You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(19) |
Nov
(18) |
Dec
(34) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(14) |
Feb
(14) |
Mar
(3) |
Apr
(10) |
May
(10) |
Jun
(17) |
Jul
(15) |
Aug
(24) |
Sep
(24) |
Oct
(11) |
Nov
(13) |
Dec
(15) |
| 2008 |
Jan
(10) |
Feb
(46) |
Mar
(20) |
Apr
(42) |
May
(44) |
Jun
(22) |
Jul
(59) |
Aug
(8) |
Sep
(15) |
Oct
(52) |
Nov
(30) |
Dec
(38) |
| 2009 |
Jan
(27) |
Feb
(27) |
Mar
(47) |
Apr
(85) |
May
(74) |
Jun
(41) |
Jul
(70) |
Aug
(64) |
Sep
(97) |
Oct
(147) |
Nov
(67) |
Dec
(48) |
| 2010 |
Jan
(68) |
Feb
(33) |
Mar
(53) |
Apr
(98) |
May
(55) |
Jun
(71) |
Jul
(99) |
Aug
(132) |
Sep
(291) |
Oct
(220) |
Nov
(344) |
Dec
(300) |
| 2011 |
Jan
(57) |
Feb
(25) |
Mar
(59) |
Apr
(104) |
May
(60) |
Jun
(155) |
Jul
(143) |
Aug
(43) |
Sep
(53) |
Oct
(20) |
Nov
(35) |
Dec
(103) |
| 2012 |
Jan
(62) |
Feb
(43) |
Mar
(29) |
Apr
(80) |
May
(75) |
Jun
(61) |
Jul
(52) |
Aug
(58) |
Sep
(33) |
Oct
(32) |
Nov
(69) |
Dec
(37) |
| 2013 |
Jan
(77) |
Feb
(28) |
Mar
(52) |
Apr
(18) |
May
(37) |
Jun
(21) |
Jul
(22) |
Aug
(55) |
Sep
(29) |
Oct
(74) |
Nov
(50) |
Dec
(44) |
| 2014 |
Jan
(77) |
Feb
(62) |
Mar
(81) |
Apr
(99) |
May
(59) |
Jun
(95) |
Jul
(55) |
Aug
(34) |
Sep
(78) |
Oct
(33) |
Nov
(48) |
Dec
(51) |
| 2015 |
Jan
(56) |
Feb
(120) |
Mar
(37) |
Apr
(15) |
May
(22) |
Jun
(196) |
Jul
(54) |
Aug
(33) |
Sep
(32) |
Oct
(42) |
Nov
(149) |
Dec
(61) |
| 2016 |
Jan
(15) |
Feb
(26) |
Mar
(37) |
Apr
(27) |
May
(14) |
Jun
(11) |
Jul
(13) |
Aug
(64) |
Sep
(2) |
Oct
(36) |
Nov
(18) |
Dec
(46) |
| 2017 |
Jan
(6) |
Feb
(1) |
Mar
(2) |
Apr
(50) |
May
(42) |
Jun
(11) |
Jul
(4) |
Aug
(12) |
Sep
(11) |
Oct
(21) |
Nov
(15) |
Dec
(42) |
| 2018 |
Jan
(33) |
Feb
(27) |
Mar
(20) |
Apr
(5) |
May
(4) |
Jun
(1) |
Jul
(42) |
Aug
(29) |
Sep
(11) |
Oct
(40) |
Nov
(312) |
Dec
(18) |
| 2019 |
Jan
(44) |
Feb
(98) |
Mar
(125) |
Apr
(160) |
May
(123) |
Jun
(33) |
Jul
(56) |
Aug
(81) |
Sep
(24) |
Oct
(23) |
Nov
(52) |
Dec
(86) |
| 2020 |
Jan
(6) |
Feb
(17) |
Mar
(62) |
Apr
(21) |
May
(118) |
Jun
(42) |
Jul
(52) |
Aug
(62) |
Sep
(20) |
Oct
(5) |
Nov
(23) |
Dec
(111) |
| 2021 |
Jan
(31) |
Feb
(8) |
Mar
(26) |
Apr
(13) |
May
(54) |
Jun
(31) |
Jul
(17) |
Aug
(10) |
Sep
(83) |
Oct
(8) |
Nov
(21) |
Dec
(33) |
| 2022 |
Jan
(67) |
Feb
(11) |
Mar
(4) |
Apr
(46) |
May
(12) |
Jun
(17) |
Jul
(19) |
Aug
(7) |
Sep
(53) |
Oct
(14) |
Nov
(29) |
Dec
(22) |
| 2023 |
Jan
(20) |
Feb
(4) |
Mar
(37) |
Apr
(25) |
May
(15) |
Jun
(20) |
Jul
(38) |
Aug
(1) |
Sep
(1) |
Oct
(34) |
Nov
|
Dec
(8) |
| 2024 |
Jan
(15) |
Feb
(10) |
Mar
|
Apr
(4) |
May
(23) |
Jun
|
Jul
(8) |
Aug
(2) |
Sep
(18) |
Oct
(1) |
Nov
(18) |
Dec
(15) |
| 2025 |
Jan
(5) |
Feb
(1) |
Mar
(7) |
Apr
(4) |
May
(18) |
Jun
(7) |
Jul
|
Aug
(17) |
Sep
(13) |
Oct
(15) |
Nov
(5) |
Dec
(46) |
| 2026 |
Jan
(2) |
Feb
(6) |
Mar
(9) |
Apr
(28) |
May
(10) |
Jun
(6) |
Jul
|
Aug
(55) |
Sep
(2) |
Oct
(130) |
Nov
(9) |
Dec
|
|
From: SCST G. <lna...@ya...> - 2026-11-13 17:55:27
|
Commit: 9574953 GitHub URL: https://github.com/SCST-project/scst/commit/957495351973200710bb4c1574151ac5ef045a24 Author: Gleb Chesnokov Date: 2026-11-13T20:52:25+03:00 Log Message: ----------- kunit: Cover blockio transport errors and completion ordering Exercise real data and flush BIO completion callbacks using a private unregistered disk and task-scoped backend stubs. Check ENOLINK sense for reads, writes with FUA, synchronous and asynchronous flushes, discard and VERIFY, with literal expectations for the unchanged error mappings. Capture the response at command completion and cover inline and deferred BIOs, reversed completion order, mixed errors, prior DIF sense, allocation failures, IMMED and VERIFY short reads and miscompares. Check that ENOLINK preserves prior sense for synchronous and asynchronous flushes and discard. Hold a test reference to the first BIO to verify that allocation-failure unwinding drops its production reference, and release both references on a detected leak during fixture cleanup. Keep the existing flush suite unchanged and document that this coverage does not establish initiator failover or device lifecycle behavior. Modified Paths: -------------- doc/KUNIT.md | 6 + .../kunit/vdisk/suites/scst_vdisk_blockio_test.c | 678 +++++++++++++++ scst/src/kunit/objects.mk | 1 + 3 files changed, 685 insertions(+) =================================================================== diff --git a/doc/KUNIT.md b/doc/KUNIT.md index 6403da9..bcd16c3 100644 --- a/doc/KUNIT.md +++ b/doc/KUNIT.md @@ -72,6 +72,12 @@ files. Base labels come directly from suite registrations: | `isert-scst.ko` | `ISER` | | `qla2x00tgt.ko` | `QLA` | +`VDISK` includes `scst-VDISK-blockio`, which checks backend transport-error sense, +unchanged error mappings, BIO completion ordering, flush, discard and VERIFY. +It uses a private unregistered disk and stubs backend calls; it does not submit +I/O to a real device. Initiator failover and ALUA/backend lifecycle behavior +require separate integration tests. + `ISER` selects `scst-ISER-cq`, which tests CQ poll errors, batch sizes and completion ordering inside `isert-scst.ko` using private RDMA fixtures. No RDMA device is needed. Detecting out-of-bounds pointer formation on a diff --git a/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_blockio_test.c b/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_blockio_test.c new file mode 100644 index 0000000..9471039 --- /dev/null +++ b/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_blockio_test.c @@ -0,0 +1,678 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include "../scst_vdisk_fixture.h" + +#define BLOCKIO_TEST_DATA_LEN 1024 + +struct blockio_fixture { + struct scst_cmd cmd; + struct scst_device dev; + struct scst_session sess; + struct scst_vdisk_dev vdev; + struct vdisk_cmd_params params; + struct gendisk *disk; + struct bio_set bioset; + bool bioset_ready; + struct scatterlist sg[2]; + u8 sense[SCST_SENSE_BUFFERSIZE]; + struct vdisk_test_response response; + struct bio *pending[2]; + struct bio *held_bio; + blk_status_t status[2]; + blk_opf_t flags[2]; + sector_t sector[2]; + unsigned int bytes[2]; + unsigned int allocations; + unsigned int fail_alloc_at; + unsigned int submissions; + unsigned int completions; + unsigned int flushes; + unsigned int discards; + int backend_error; + ssize_t read_result; + bool single_vec; + bool inline_io; +}; + +static void blockio_done(struct scst_cmd *cmd, int state, enum scst_exec_context context) +{ + struct blockio_fixture *f = container_of(cmd, struct blockio_fixture, cmd); + struct kunit *test = kunit_get_current_test(); + + KUNIT_EXPECT_TRUE(test, cmd->completed); + KUNIT_EXPECT_EQ(test, state, SCST_CMD_STATE_DEFAULT); + if (!f->completions++) + vdisk_test_save_response(&f->response, cmd); +} + +static struct bio *blockio_alloc(int nr_vecs, gfp_t gfp_mask, struct bio_set *bs) +{ + struct kunit *test = kunit_get_current_test(); + struct blockio_fixture *f = test->priv; + struct bio *bio; + + KUNIT_EXPECT_PTR_EQ(test, bs, &f->bioset); + if (++f->allocations == f->fail_alloc_at) + return NULL; + /* Force one BIO per SG entry without relying on BIO_MAX_VECS or page size. */ + bio = bio_alloc_bioset(NULL, f->single_vec ? 1 : nr_vecs, 0, gfp_mask, bs); + if (bio && f->fail_alloc_at && !f->held_bio) { + /* Keep the first BIO alive to check its reference after allocation failure. */ + bio_get(bio); + f->held_bio = bio; + } + return bio; +} + +static void blockio_submit(struct bio *bio) +{ + struct kunit *test = kunit_get_current_test(); + struct blockio_fixture *f = test->priv; + unsigned int n = f->submissions++; + + KUNIT_EXPECT_PTR_EQ(test, bio->bi_bdev, f->disk->part0); + if (n >= ARRAY_SIZE(f->pending)) { + KUNIT_FAIL(test, "unexpected extra BIO"); + bio->bi_status = BLK_STS_IOERR; + bio_endio(bio); + return; + } + f->flags[n] = bio->bi_opf; + f->sector[n] = bio->bi_iter.bi_sector; + f->bytes[n] = bio->bi_iter.bi_size; + if (bio_op(bio) == REQ_OP_READ && bio->bi_iter.bi_size) + zero_fill_bio(bio); + if (f->inline_io) { + /* The submitter reference must keep the command alive until it returns. */ + KUNIT_EXPECT_EQ(test, f->completions, 0U); + bio->bi_status = f->status[n]; + bio_endio(bio); + } else { + f->pending[n] = bio; + } +} + +static void blockio_complete(struct kunit *test, unsigned int n, blk_status_t status) +{ + struct blockio_fixture *f = test->priv; + struct bio *bio; + + KUNIT_ASSERT_LT(test, n, (unsigned int)ARRAY_SIZE(f->pending)); + bio = f->pending[n]; + KUNIT_ASSERT_NOT_NULL(test, bio); + f->pending[n] = NULL; + bio->bi_status = status; + bio_endio(bio); +} + +static int blockio_flush(struct block_device *bdev, gfp_t gfp_mask) +{ + struct kunit *test = kunit_get_current_test(); + struct blockio_fixture *f = test->priv; + + KUNIT_EXPECT_PTR_EQ(test, bdev, f->disk->part0); + f->flushes++; + return f->backend_error; +} + +static int blockio_discard(struct block_device *bdev, sector_t start, sector_t sectors, + gfp_t gfp_mask) +{ + struct kunit *test = kunit_get_current_test(); + struct blockio_fixture *f = test->priv; + + KUNIT_EXPECT_PTR_EQ(test, bdev, f->disk->part0); + KUNIT_EXPECT_EQ(test, start, (sector_t)8); + KUNIT_EXPECT_EQ(test, sectors, (sector_t)2); + f->discards++; + return f->backend_error; +} + +static ssize_t blockio_read_result(struct scst_vdisk_dev *vdev, void *buf, size_t len, + loff_t *loff) +{ + struct kunit *test = kunit_get_current_test(); + struct blockio_fixture *f = test->priv; + + KUNIT_EXPECT_PTR_EQ(test, vdev, &f->vdev); + KUNIT_EXPECT_EQ(test, len, (size_t)BLOCKIO_TEST_DATA_LEN); + return f->read_result; +} + +static int blockio_init(struct kunit *test) +{ + struct queue_limits limits = { .logical_block_size = 512 }; + struct blockio_fixture *f; + unsigned int i; + int ret; + + f = kunit_kzalloc(test, sizeof(*f), GFP_KERNEL); + if (!f) + return -ENOMEM; + test->priv = f; + sg_init_table(f->sg, ARRAY_SIZE(f->sg)); + for (i = 0; i < ARRAY_SIZE(f->sg); i++) { + void *data = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL); + + if (!data) + return -ENOMEM; + /* Distinct pages with short segments cannot merge into one bvec. */ + sg_set_buf(&f->sg[i], data, BLOCKIO_TEST_DATA_LEN / 2); + } + /* Private, unregistered disk: every backend entry point is stubbed below. */ + f->disk = blk_alloc_disk(&limits, NUMA_NO_NODE); + if (IS_ERR(f->disk)) { + ret = PTR_ERR(f->disk); + f->disk = NULL; + return ret; + } + ret = bioset_init(&f->bioset, 4, 0, BIOSET_NEED_BVECS); + if (ret) { + put_disk(f->disk); + f->disk = NULL; + return ret; + } + f->bioset_ready = true; + f->vdev.bdev_desc.bdev = f->disk->part0; + f->vdev.vdisk_bioset = &f->bioset; + f->vdev.blockio = true; + f->vdev.thin_provisioned = true; + f->vdev.nblocks = 4096; + f->vdev.file_size = f->vdev.nblocks << 9; + f->vdev.dev = &f->dev; + f->dev.dh_priv = &f->vdev; + f->dev.block_size = 512; + f->dev.block_shift = 9; + f->cmd.dev = &f->dev; + f->cmd.sess = &f->sess; + f->cmd.cdb = f->cmd.cdb_buf; + f->cmd.cmd_gfp_mask = GFP_KERNEL; + f->cmd.lba = 8; + f->cmd.data_len = BLOCKIO_TEST_DATA_LEN; + f->cmd.bufflen = BLOCKIO_TEST_DATA_LEN; + f->cmd.resp_data_len = BLOCKIO_TEST_DATA_LEN; + f->cmd.sg = f->sg; + f->cmd.sg_cnt = ARRAY_SIZE(f->sg); + f->cmd.sense = f->sense; + f->cmd.sense_buflen = sizeof(f->sense); + f->cmd.scst_cmd_done = blockio_done; + kref_init(&f->cmd.cmd_ref); + f->sess.initiator_name = "kunit"; + f->sess.init_phase = SCST_SESS_IPH_READY; + atomic_set(&f->sess.sess_cmd_count, 1); + f->params.cmd = &f->cmd; + f->params.loff = 8 << 9; + kunit_activate_static_stub(test, vdisk_alloc_bio, blockio_alloc); + kunit_activate_static_stub(test, vdisk_submit_bio, blockio_submit); + kunit_activate_static_stub(test, vdisk_submit_flush_bio, blockio_submit); + kunit_activate_static_stub(test, vdisk_issue_flush, blockio_flush); + kunit_activate_static_stub(test, vdisk_issue_discard, blockio_discard); + return 0; +} + +/* KUnit's suite exit callback requires a mutable struct kunit pointer. */ +/* cppcheck-suppress constParameterCallback symbolName=test */ +static void blockio_exit(struct kunit *test) +{ + struct blockio_fixture *f = test->priv; + unsigned int i; + + if (!f) + return; + /* Drain real end-I/O callbacks even after an assertion aborts the test. */ + for (i = 0; i < ARRAY_SIZE(f->pending); i++) { + struct bio *bio = f->pending[i]; + + if (!bio) + continue; + f->pending[i] = NULL; + bio->bi_status = BLK_STS_IOERR; + bio_endio(bio); + } + if (f->held_bio) { + /* Recover a leaked production reference before dropping the test reference. */ + if (atomic_read(&f->held_bio->__bi_cnt) == 2) + bio_put(f->held_bio); + bio_put(f->held_bio); + } + if (f->bioset_ready) + bioset_exit(&f->bioset); + if (f->disk) + put_disk(f->disk); +} + +struct blockio_error_case { + const char *name; + blk_status_t status; + int error; + u8 read_key, read_asc; + u8 write_key, write_asc, write_ascq; + u8 other_key, other_asc; +}; + +/* Literal protocol expectations also pin the mappings outside ENOLINK. */ +static const struct blockio_error_case blockio_errors[] = { + { "success", BLK_STS_OK, 0 }, + { "transport", BLK_STS_TRANSPORT, -ENOLINK, + NOT_READY, 0x08, NOT_READY, 0x08, 0, NOT_READY, 0x08 }, + { "io_error", BLK_STS_IOERR, -EIO, + MEDIUM_ERROR, 0x11, MEDIUM_ERROR, 0x03, 0, MEDIUM_ERROR, 0x03 }, + { "offline", BLK_STS_OFFLINE, -ENODEV, + MEDIUM_ERROR, 0x11, MEDIUM_ERROR, 0x03, 0, MEDIUM_ERROR, 0x03 }, + { "medium", BLK_STS_MEDIUM, -ENODATA, + MEDIUM_ERROR, 0x11, MEDIUM_ERROR, 0x03, 0, MEDIUM_ERROR, 0x03 }, + { "protection", BLK_STS_PROTECTION, -EILSEQ, + MEDIUM_ERROR, 0x11, MEDIUM_ERROR, 0x03, 0, MEDIUM_ERROR, 0x03 }, + { "space", BLK_STS_NOSPC, -ENOSPC, + MEDIUM_ERROR, 0x11, DATA_PROTECT, 0x27, 0x07, MEDIUM_ERROR, 0x03 }, + { "target", BLK_STS_TARGET, -EREMOTEIO, + MEDIUM_ERROR, 0x11, MEDIUM_ERROR, 0x03, 0, MEDIUM_ERROR, 0x03 }, + { "unsupported", BLK_STS_NOTSUPP, -EOPNOTSUPP, + MEDIUM_ERROR, 0x11, MEDIUM_ERROR, 0x03, 0, MEDIUM_ERROR, 0x03 }, + { "resource", BLK_STS_RESOURCE, -ENOMEM, + MEDIUM_ERROR, 0x11, MEDIUM_ERROR, 0x03, 0, MEDIUM_ERROR, 0x03 }, + { "again", BLK_STS_AGAIN, -EAGAIN, + MEDIUM_ERROR, 0x11, MEDIUM_ERROR, 0x03, 0, MEDIUM_ERROR, 0x03 }, +}; + +static void blockio_error_desc(const struct blockio_error_case *p, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name); +} + +KUNIT_ARRAY_PARAM(blockio_error, blockio_errors, blockio_error_desc); + +static void blockio_expect_result(struct kunit *test, int error, u8 key, u8 asc, u8 ascq, + int good_len) +{ + struct blockio_fixture *f = test->priv; + struct vdisk_test_response response = {}; + + vdisk_test_save_response(&response, &f->cmd); + if (error) { + vdisk_test_expect_sense(test, &response, key, asc, ascq); + if (f->completions) + vdisk_test_expect_sense(test, &f->response, key, asc, ascq); + } else { + vdisk_test_expect_response(test, &response, SAM_STAT_GOOD, good_len); + if (f->completions) + vdisk_test_expect_response(test, &f->response, SAM_STAT_GOOD, good_len); + } +} + +static void blockio_rw_test(struct kunit *test, bool write, bool inline_io) +{ + const struct blockio_error_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + unsigned int i; + + f->single_vec = true; + f->inline_io = inline_io; + f->status[0] = p->status; + f->cmd.data_direction = write ? SCST_DATA_WRITE : SCST_DATA_READ; + blockio_exec_rw(&f->params, write, write); + KUNIT_ASSERT_EQ(test, f->submissions, 2U); + for (i = 0; i < 2; i++) { + KUNIT_EXPECT_TRUE(test, (f->flags[i] & REQ_OP_MASK) == + (write ? REQ_OP_WRITE : REQ_OP_READ)); + KUNIT_EXPECT_EQ(test, !!(f->flags[i] & REQ_FUA), write); + KUNIT_EXPECT_EQ(test, f->sector[i], (sector_t)(8 + i)); + KUNIT_EXPECT_EQ(test, f->bytes[i], BLOCKIO_TEST_DATA_LEN / 2); + } + if (!inline_io) { + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_complete(test, 0, p->status); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_complete(test, 1, BLK_STS_OK); + } + KUNIT_EXPECT_EQ(test, f->completions, 1U); + blockio_expect_result(test, p->error, write ? p->write_key : p->read_key, + write ? p->write_asc : p->read_asc, write ? p->write_ascq : 0, + BLOCKIO_TEST_DATA_LEN); + KUNIT_EXPECT_EQ(test, !!f->cmd.deferred_dif_read_check, !write && !p->error); +} + +static void blockio_read_test(struct kunit *test) +{ + blockio_rw_test(test, false, false); +} + +static void blockio_write_fua_test(struct kunit *test) +{ + blockio_rw_test(test, true, false); +} + +static void blockio_inline_test(struct kunit *test) +{ + blockio_rw_test(test, true, true); +} + +static void blockio_flush_sync_test(struct kunit *test) +{ + const struct blockio_error_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + + f->backend_error = p->error; + f->cmd.resp_data_len = 0; + KUNIT_EXPECT_EQ(test, vdisk_blockio_flush(f->disk->part0, GFP_KERNEL, false, + &f->cmd, false), p->error); + KUNIT_EXPECT_EQ(test, f->flushes, 1U); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_expect_result(test, p->error, p->other_key, p->other_asc, 0, 0); +} + +static void blockio_flush_async_test(struct kunit *test) +{ + const struct blockio_error_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + + f->cmd.resp_data_len = 0; + KUNIT_EXPECT_EQ(test, vdisk_synchronize_cache(&f->params), RUNNING_ASYNC); + KUNIT_ASSERT_EQ(test, f->submissions, 1U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_complete(test, 0, p->status); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + blockio_expect_result(test, p->error, p->other_key, p->other_asc, 0, 0); +} + +static void blockio_flush_immed_test(struct kunit *test) +{ + const struct blockio_error_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + + f->cmd.cdb[1] = 2; + f->cmd.resp_data_len = 0; + KUNIT_EXPECT_EQ(test, vdisk_synchronize_cache(&f->params), RUNNING_ASYNC); + KUNIT_ASSERT_EQ(test, f->submissions, 1U); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + KUNIT_EXPECT_EQ(test, kref_read(&f->cmd.cmd_ref), 1U); + KUNIT_ASSERT_NOT_NULL(test, f->pending[0]); + KUNIT_EXPECT_PTR_EQ(test, f->pending[0]->bi_private, NULL); + blockio_complete(test, 0, p->status); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + blockio_expect_result(test, 0, 0, 0, 0, 0); +} + +static void blockio_discard_test(struct kunit *test) +{ + const struct blockio_error_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + + f->backend_error = p->error; + f->cmd.resp_data_len = 0; + KUNIT_EXPECT_EQ(test, vdisk_unmap_range(&f->cmd, &f->vdev, 8, 2), p->error ? -EIO : 0); + KUNIT_EXPECT_EQ(test, f->discards, 1U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_expect_result(test, p->error, p->other_key, p->other_asc, 0, 0); +} + +static void blockio_flush_sync_prior_sense_test(struct kunit *test) +{ + struct blockio_fixture *f = test->priv; + + KUNIT_ASSERT_EQ(test, scst_set_cmd_error(&f->cmd, ABORTED_COMMAND, 0x10, 0x02), 0); + f->backend_error = -ENOLINK; + KUNIT_EXPECT_EQ(test, vdisk_blockio_flush(f->disk->part0, GFP_KERNEL, false, + &f->cmd, false), -ENOLINK); + KUNIT_EXPECT_EQ(test, f->flushes, 1U); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_expect_result(test, -ENOLINK, ABORTED_COMMAND, 0x10, 0x02, 0); +} + +static void blockio_flush_async_prior_sense_test(struct kunit *test) +{ + struct blockio_fixture *f = test->priv; + + f->cmd.resp_data_len = 0; + KUNIT_EXPECT_EQ(test, vdisk_synchronize_cache(&f->params), RUNNING_ASYNC); + KUNIT_ASSERT_EQ(test, f->submissions, 1U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + KUNIT_ASSERT_EQ(test, scst_set_cmd_error(&f->cmd, ABORTED_COMMAND, 0x10, 0x02), 0); + blockio_complete(test, 0, BLK_STS_TRANSPORT); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + blockio_expect_result(test, -ENOLINK, ABORTED_COMMAND, 0x10, 0x02, 0); +} + +static void blockio_discard_prior_sense_test(struct kunit *test) +{ + struct blockio_fixture *f = test->priv; + + KUNIT_ASSERT_EQ(test, scst_set_cmd_error(&f->cmd, ABORTED_COMMAND, 0x10, 0x02), 0); + f->backend_error = -ENOLINK; + KUNIT_EXPECT_EQ(test, vdisk_unmap_range(&f->cmd, &f->vdev, 8, 2), -EIO); + KUNIT_EXPECT_EQ(test, f->discards, 1U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_expect_result(test, -ENOLINK, ABORTED_COMMAND, 0x10, 0x02, 0); +} + +static void blockio_verify_test(struct kunit *test) +{ + const struct blockio_error_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + + f->inline_io = true; + f->status[0] = p->status; + f->cmd.data_direction = SCST_DATA_NONE; + f->cmd.resp_data_len = 0; + KUNIT_EXPECT_EQ(test, vdev_exec_verify(&f->params), CMD_SUCCEEDED); + KUNIT_EXPECT_EQ(test, f->flushes, 1U); + KUNIT_EXPECT_EQ(test, f->submissions, 1U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + KUNIT_EXPECT_TRUE(test, (f->flags[0] & REQ_OP_MASK) == REQ_OP_READ); + KUNIT_EXPECT_TRUE(test, f->flags[0] & REQ_SYNC); + if (p->error == -EAGAIN) + KUNIT_EXPECT_EQ(test, f->cmd.status, (u8)SAM_STAT_BUSY); + else + blockio_expect_result(test, p->error, p->read_key, p->read_asc, 0, 0); +} + +static void blockio_verify_flush_test(struct kunit *test) +{ + struct blockio_fixture *f = test->priv; + + /* A regression that continues into the read must fail without waiting. */ + f->inline_io = true; + f->backend_error = -ENOLINK; + f->cmd.data_direction = SCST_DATA_NONE; + KUNIT_EXPECT_EQ(test, vdev_exec_verify(&f->params), CMD_SUCCEEDED); + KUNIT_EXPECT_EQ(test, f->flushes, 1U); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_expect_result(test, -ENOLINK, NOT_READY, 0x08, 0, 0); +} + +struct blockio_verify_case { + const char *name; + bool fileio; + ssize_t result; +}; + +static const struct blockio_verify_case blockio_verify_cases[] = { + { "fileio_enolink", true, -ENOLINK }, + { "short_block_read", false, BLOCKIO_TEST_DATA_LEN - 1 }, + { "zero_block_read", false, 0 }, +}; + +static void blockio_verify_desc(const struct blockio_verify_case *p, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name); +} + +KUNIT_ARRAY_PARAM(blockio_verify, blockio_verify_cases, blockio_verify_desc); + +static void blockio_verify_fallback_test(struct kunit *test) +{ + const struct blockio_verify_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + + f->vdev.blockio = !p->fileio; + f->vdev.nv_cache = true; + f->read_result = p->result; + f->cmd.data_direction = SCST_DATA_NONE; + kunit_activate_static_stub(test, vdev_read_sync, blockio_read_result); + KUNIT_EXPECT_EQ(test, vdev_exec_verify(&f->params), CMD_SUCCEEDED); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_expect_result(test, -EIO, MEDIUM_ERROR, 0x11, 0, 0); +} + +struct blockio_compare_case { + const char *name; + blk_status_t status; + bool mismatch; + unsigned int reads; + u8 key, asc; +}; + +static const struct blockio_compare_case blockio_compare_cases[] = { + { "matching_data", BLK_STS_OK, false, 2, 0, 0 }, + { "miscompare", BLK_STS_OK, true, 1, MISCOMPARE, 0x1d }, + { "transport_before_compare", BLK_STS_TRANSPORT, true, 1, NOT_READY, 0x08 }, + { "medium_before_compare", BLK_STS_MEDIUM, true, 1, MEDIUM_ERROR, 0x11 }, +}; + +static void blockio_compare_desc(const struct blockio_compare_case *p, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name); +} + +KUNIT_ARRAY_PARAM(blockio_compare, blockio_compare_cases, blockio_compare_desc); + +static void blockio_compare_test(struct kunit *test) +{ + const struct blockio_compare_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + + f->inline_io = true; + f->status[0] = p->status; + f->cmd.data_direction = SCST_DATA_WRITE; + f->cmd.resp_data_len = 0; + if (p->mismatch) + memset(sg_virt(f->sg), 0xa5, f->sg[0].length); + KUNIT_EXPECT_EQ(test, vdev_exec_verify(&f->params), CMD_SUCCEEDED); + KUNIT_EXPECT_EQ(test, f->flushes, 1U); + KUNIT_EXPECT_EQ(test, f->submissions, p->reads); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_expect_result(test, p->key ? -EIO : 0, p->key, p->asc, 0, 0); +} + +struct blockio_order_case { + const char *name; + blk_status_t first, second; + bool write; + bool reverse; + bool prior_dif; + u8 key, asc, ascq; +}; + +static const struct blockio_order_case blockio_order_cases[] = { + { "success_then_transport", BLK_STS_OK, BLK_STS_TRANSPORT, + false, true, false, NOT_READY, 0x08, 0 }, + { "transport_then_medium", BLK_STS_TRANSPORT, BLK_STS_MEDIUM, + false, false, false, NOT_READY, 0x08, 0 }, + { "medium_then_transport", BLK_STS_MEDIUM, BLK_STS_TRANSPORT, + false, true, false, MEDIUM_ERROR, 0x11, 0 }, + { "transport_then_nospc", BLK_STS_TRANSPORT, BLK_STS_NOSPC, + true, true, false, NOT_READY, 0x08, 0 }, + { "nospc_then_transport", BLK_STS_NOSPC, BLK_STS_TRANSPORT, + true, false, false, DATA_PROTECT, 0x27, 0x07 }, + { "prior_dif_error", BLK_STS_TRANSPORT, BLK_STS_TRANSPORT, + true, true, true, ABORTED_COMMAND, 0x10, 0x02 }, +}; + +static void blockio_order_desc(const struct blockio_order_case *p, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name); +} + +KUNIT_ARRAY_PARAM(blockio_order, blockio_order_cases, blockio_order_desc); + +static void blockio_order_test(struct kunit *test) +{ + const struct blockio_order_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + + f->single_vec = true; + f->cmd.data_direction = p->write ? SCST_DATA_WRITE : SCST_DATA_READ; + blockio_exec_rw(&f->params, p->write, false); + KUNIT_ASSERT_EQ(test, f->submissions, 2U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + if (p->prior_dif) + scst_set_cmd_error(&f->cmd, + SCST_LOAD_SENSE(scst_logical_block_app_tag_check_failed)); + blockio_complete(test, p->reverse ? 1 : 0, p->first); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + blockio_complete(test, p->reverse ? 0 : 1, p->second); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + blockio_expect_result(test, -EIO, p->key, p->asc, p->ascq, 0); +} + +struct blockio_alloc_case { + const char *name; + unsigned int fail_at; + unsigned int commands; + u8 status; +}; + +static const struct blockio_alloc_case blockio_alloc_cases[] = { + { "first_bio_busy", 1, 1, SAM_STAT_BUSY }, + { "second_bio_busy", 2, 1, SAM_STAT_BUSY }, + { "second_bio_task_set_full", 2, 2, SAM_STAT_TASK_SET_FULL }, +}; + +static void blockio_alloc_desc(const struct blockio_alloc_case *p, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name); +} + +KUNIT_ARRAY_PARAM(blockio_alloc, blockio_alloc_cases, blockio_alloc_desc); + +static void blockio_alloc_test(struct kunit *test) +{ + const struct blockio_alloc_case *p = test->param_value; + struct blockio_fixture *f = test->priv; + + f->single_vec = true; + f->fail_alloc_at = p->fail_at; + f->cmd.data_direction = SCST_DATA_READ; + atomic_set(&f->sess.sess_cmd_count, p->commands); + blockio_exec_rw(&f->params, false, false); + KUNIT_EXPECT_EQ(test, f->allocations, p->fail_at); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + vdisk_test_expect_response(test, &f->response, p->status, 0); + if (p->fail_at > 1) { + KUNIT_ASSERT_NOT_NULL(test, f->held_bio); + /* Only our reference may remain after blockio_exec_rw() unwinds. */ + KUNIT_EXPECT_EQ(test, atomic_read(&f->held_bio->__bi_cnt), 1); + } else { + KUNIT_EXPECT_PTR_EQ(test, f->held_bio, NULL); + } +} + +static struct kunit_case blockio_cases[] = { + KUNIT_CASE_PARAM(blockio_read_test, blockio_error_gen_params), + KUNIT_CASE_PARAM(blockio_write_fua_test, blockio_error_gen_params), + KUNIT_CASE_PARAM(blockio_inline_test, blockio_error_gen_params), + KUNIT_CASE_PARAM(blockio_flush_sync_test, blockio_error_gen_params), + KUNIT_CASE_PARAM(blockio_flush_async_test, blockio_error_gen_params), + KUNIT_CASE_PARAM(blockio_flush_immed_test, blockio_error_gen_params), + KUNIT_CASE_PARAM(blockio_discard_test, blockio_error_gen_params), + KUNIT_CASE(blockio_flush_sync_prior_sense_test), + KUNIT_CASE(blockio_flush_async_prior_sense_test), + KUNIT_CASE(blockio_discard_prior_sense_test), + KUNIT_CASE_PARAM(blockio_verify_test, blockio_error_gen_params), + KUNIT_CASE(blockio_verify_flush_test), + KUNIT_CASE_PARAM(blockio_verify_fallback_test, blockio_verify_gen_params), + KUNIT_CASE_PARAM(blockio_compare_test, blockio_compare_gen_params), + KUNIT_CASE_PARAM(blockio_order_test, blockio_order_gen_params), + KUNIT_CASE_PARAM(blockio_alloc_test, blockio_alloc_gen_params), + {} +}; + +scst_kunit_suite(blockio_suite, "VDISK", "-blockio", + .init = blockio_init, + .exit = blockio_exit, + .test_cases = blockio_cases, +); diff --git a/scst/src/kunit/objects.mk b/scst/src/kunit/objects.mk index 20a2cec..8c76c78 100644 --- a/scst/src/kunit/objects.mk +++ b/scst/src/kunit/objects.mk @@ -37,6 +37,7 @@ scst-kunit-scst_user := \ scst-kunit-scst_vdisk := \ kunit/vdisk/scst_vdisk_fixture.o \ + kunit/vdisk/suites/scst_vdisk_blockio_test.o \ kunit/vdisk/suites/scst_vdisk_capacity_test.o \ kunit/vdisk/suites/scst_vdisk_flush_test.o \ kunit/vdisk/suites/scst_vdisk_io_test.o \ |
|
From: SCST G. <lna...@ya...> - 2026-11-13 17:55:23
|
Commit: 24a9366 GitHub URL: https://github.com/SCST-project/scst/commit/24a9366dd5d70c53ac22458a0f352f8f234ca440 Author: Gleb Chesnokov Date: 2026-11-13T20:52:25+03:00 Log Message: ----------- kunit: Cover vdisk flush failures and command completion Exercise the real block flush callbacks and command handlers using private block-layer state. Replace backend execution and flush BIO allocation through the flush wrappers. Stub VERIFY's existing read helper so the tests can check that a failed flush prevents verification without accessing storage. Keep its data length independent of PAGE_SIZE. Cover synchronous and asynchronous flush errors, START STOP, VERIFY, SYNCHRONIZE CACHE with and without IMMED, allocation failures, BUSY versus TASK SET FULL, commandless requests and preservation of prior sense. Check early allocation and DIF failures through SYNCHRONIZE CACHE, including DIF memory pressure and IMMED completion ordering and references. Capture status, sense and response length in the first completion callback so an error set after completion cannot satisfy the assertions. Keep the existing write-error sense for backend flush failures; this series does not introduce backend-error classification. Modified Paths: -------------- scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.c | 40 +- scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.h | 13 + .../kunit/vdisk/suites/scst_vdisk_flush_test.c | 391 +++++++++++++++ .../kunit/vdisk/suites/scst_vdisk_sync_test.c | 68 +++ scst/src/dev_handlers/scst_vdisk_main.c | 28 +- scst/src/dev_handlers/scst_vdisk_test.h | 8 + scst/src/kunit/objects.mk | 1 + 7 files changed, 539 insertions(+), 10 deletions(-) =================================================================== diff --git a/scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.c b/scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.c index ea47081..cec7e97 100644 --- a/scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.c +++ b/scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.c @@ -121,13 +121,47 @@ static int vdisk_test_no_dif(struct scst_cmd *cmd) return 0; } +void vdisk_test_save_response(struct vdisk_test_response *response, const struct scst_cmd *cmd) +{ + size_t len = min_t(size_t, cmd->sense_valid_len, sizeof(response->sense)); + + response->status = cmd->status; + response->resp_data_len = cmd->resp_data_len; + response->sense_valid_len = cmd->sense_valid_len; + if (cmd->sense) + memcpy(response->sense, cmd->sense, min_t(size_t, len, cmd->sense_buflen)); +} + +void vdisk_test_expect_response(struct kunit *test, const struct vdisk_test_response *response, + u8 status, int resp_data_len) +{ + KUNIT_EXPECT_EQ(test, response->status, status); + KUNIT_EXPECT_EQ(test, response->resp_data_len, resp_data_len); + if (status != SAM_STAT_CHECK_CONDITION) + KUNIT_EXPECT_EQ(test, response->sense_valid_len, 0); +} + +void vdisk_test_expect_sense(struct kunit *test, const struct vdisk_test_response *response, + u8 key, u8 asc, u8 ascq) +{ + vdisk_test_expect_response(test, response, SAM_STAT_CHECK_CONDITION, 0); + KUNIT_ASSERT_GE(test, response->sense_valid_len, 14); + KUNIT_EXPECT_EQ(test, response->sense[0] & 0x7f, 0x70); + KUNIT_EXPECT_EQ(test, response->sense[2] & 0xf, key); + KUNIT_EXPECT_EQ(test, response->sense[12], asc); + KUNIT_EXPECT_EQ(test, response->sense[13], ascq); +} + static void vdisk_test_done(struct scst_cmd *cmd, int state, enum scst_exec_context context) { struct vdisk_test_fixture *f = container_of(cmd, struct vdisk_test_fixture, cmd); - f->completions++; - f->completion_state = state; - f->completed_before_callback = cmd->completed; + /* Preserve the response observed by the first completion callback. */ + if (!f->completions++) { + f->completion_state = state; + f->completed_before_callback = cmd->completed; + vdisk_test_save_response(&f->response, cmd); + } } int vdisk_test_init(struct kunit *test) diff --git a/scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.h b/scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.h index 1f7b5d1..995e058 100644 --- a/scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.h +++ b/scst/src/dev_handlers/kunit/vdisk/scst_vdisk_fixture.h @@ -8,6 +8,13 @@ struct vdisk_test_fixture; +struct vdisk_test_response { + u8 status; + int resp_data_len; + unsigned short sense_valid_len; + u8 sense[SCST_SENSE_BUFFERSIZE]; +}; + struct vdisk_test_file { struct file file; struct inode inode; @@ -52,6 +59,7 @@ struct vdisk_test_fixture { unsigned int completions; int completion_state; bool completed_before_callback; + struct vdisk_test_response response; struct vdisk_test_flush flushes[2]; unsigned int flush_count; unsigned int block_flush_count; @@ -61,6 +69,11 @@ struct vdisk_test_fixture { int vdisk_test_init(struct kunit *test); void vdisk_test_exit(struct kunit *test); +void vdisk_test_save_response(struct vdisk_test_response *response, const struct scst_cmd *cmd); +void vdisk_test_expect_response(struct kunit *test, const struct vdisk_test_response *response, + u8 status, int resp_data_len); +void vdisk_test_expect_sense(struct kunit *test, const struct vdisk_test_response *response, + u8 key, u8 asc, u8 ascq); void vdisk_test_expect_flush(struct kunit *test, unsigned int n, struct file *file, loff_t start, loff_t end); diff --git a/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_flush_test.c b/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_flush_test.c new file mode 100644 index 0000000..615facf --- /dev/null +++ b/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_flush_test.c @@ -0,0 +1,391 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include "../scst_vdisk_fixture.h" + +/* Keep VERIFY within one read independently of the kernel's page size. */ +#define FLUSH_TEST_DATA_LEN 4096 + +struct flush_fixture { + struct scst_cmd cmd; + struct scst_device dev; + struct scst_session sess; + struct scst_vdisk_dev vdev; + struct vdisk_cmd_params params; + struct gendisk *disk; + u8 sense[SCST_SENSE_BUFFERSIZE]; + struct bio *pending; + blk_status_t bio_status; + unsigned int submissions; + unsigned int completions; + struct vdisk_test_response response; + unsigned int sync_flushes; + unsigned int reads; + int sync_flush_error; + bool defer; +}; + +static void flush_done(struct scst_cmd *cmd, int state, enum scst_exec_context context) +{ + struct flush_fixture *f = container_of(cmd, struct flush_fixture, cmd); + struct kunit *test = kunit_get_current_test(); + + KUNIT_EXPECT_TRUE(test, cmd->completed); + KUNIT_EXPECT_EQ(test, state, SCST_CMD_STATE_DEFAULT); + if (!f->completions++) + vdisk_test_save_response(&f->response, cmd); +} + +static void flush_submit(struct bio *bio) +{ + struct kunit *test = kunit_get_current_test(); + struct flush_fixture *f = test->priv; + + KUNIT_EXPECT_PTR_EQ(test, bio->bi_bdev, f->disk->part0); + if (f->submissions++) { + KUNIT_FAIL(test, "unexpected extra flush BIO"); + bio->bi_status = BLK_STS_IOERR; + bio_endio(bio); + return; + } + /* Replace backend execution while retaining the actual end-I/O callback. */ + if (f->defer) { + f->pending = bio; + return; + } + bio->bi_status = f->bio_status; + bio_endio(bio); +} + +static int flush_issue(struct block_device *bdev, gfp_t gfp_mask) +{ + struct kunit *test = kunit_get_current_test(); + struct flush_fixture *f = test->priv; + + KUNIT_EXPECT_PTR_EQ(test, bdev, f->disk->part0); + f->sync_flushes++; + return f->sync_flush_error; +} + +static ssize_t flush_read(struct scst_vdisk_dev *vdev, void *buf, size_t len, loff_t *loff) +{ + struct kunit *test = kunit_get_current_test(); + struct flush_fixture *f = test->priv; + + KUNIT_EXPECT_PTR_EQ(test, vdev, &f->vdev); + KUNIT_EXPECT_EQ(test, f->sync_flushes, 1U); + KUNIT_EXPECT_EQ(test, f->sync_flush_error, 0); + KUNIT_EXPECT_EQ(test, len, (size_t)FLUSH_TEST_DATA_LEN); + f->reads++; + memset(buf, 0, len); + *loff += len; + return len; +} + +static struct bio *flush_alloc_fail(gfp_t gfp_mask) +{ + return NULL; +} + +static int flush_init(struct kunit *test) +{ + struct queue_limits limits = { .logical_block_size = 512 }; + struct flush_fixture *f; + + f = kunit_kzalloc(test, sizeof(*f), GFP_KERNEL); + if (!f) + return -ENOMEM; + test->priv = f; + /* Allocate private block-layer state without registering or opening a disk. */ + f->disk = blk_alloc_disk(&limits, NUMA_NO_NODE); + if (IS_ERR(f->disk)) { + int ret = PTR_ERR(f->disk); + + f->disk = NULL; + return ret; + } + f->vdev.bdev_desc.bdev = f->disk->part0; + f->vdev.blockio = true; + f->vdev.file_size = 4096 << 9; + f->vdev.dev = &f->dev; + f->dev.dh_priv = &f->vdev; + f->dev.block_size = 512; + f->dev.block_shift = 9; + f->cmd.dev = &f->dev; + f->cmd.sess = &f->sess; + f->cmd.cdb = f->cmd.cdb_buf; + f->cmd.cmd_gfp_mask = GFP_KERNEL; + f->cmd.data_len = FLUSH_TEST_DATA_LEN; + f->cmd.resp_data_len = FLUSH_TEST_DATA_LEN; + f->cmd.sense = f->sense; + f->cmd.sense_buflen = sizeof(f->sense); + f->cmd.scst_cmd_done = flush_done; + kref_init(&f->cmd.cmd_ref); + f->sess.initiator_name = "kunit"; + f->sess.init_phase = SCST_SESS_IPH_READY; + atomic_set(&f->sess.sess_cmd_count, 1); + f->params.cmd = &f->cmd; + kunit_activate_static_stub(test, vdisk_submit_flush_bio, flush_submit); + kunit_activate_static_stub(test, vdisk_issue_flush, flush_issue); + kunit_activate_static_stub(test, vdev_read_sync, flush_read); + return 0; +} + +/* KUnit's suite exit callback requires a mutable struct kunit pointer. */ +/* cppcheck-suppress constParameterCallback symbolName=test */ +static void flush_exit(struct kunit *test) +{ + struct flush_fixture *f = test->priv; + struct bio *bio; + + if (!f) + return; + /* A failed assertion must not leave a deferred flush BIO behind. */ + bio = f->pending; + if (bio) { + f->pending = NULL; + bio->bi_status = BLK_STS_IOERR; + bio_endio(bio); + } + if (f->disk) + put_disk(f->disk); +} + +struct flush_error_case { + const char *name; + blk_status_t status; + int error; +}; + +static const struct flush_error_case flush_errors[] = { + { "success", BLK_STS_OK, 0 }, + { "io_error", BLK_STS_IOERR, -EIO }, +}; + +static void flush_error_desc(const struct flush_error_case *p, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name); +} + +KUNIT_ARRAY_PARAM(flush_error, flush_errors, flush_error_desc); + +static void flush_expect_sense(struct kunit *test, u8 key, u8 asc, u8 ascq) +{ + struct flush_fixture *f = test->priv; + + KUNIT_EXPECT_EQ(test, f->cmd.status, (u8)SAM_STAT_CHECK_CONDITION); + KUNIT_EXPECT_EQ(test, f->sense[2] & 0xf, key); + KUNIT_EXPECT_EQ(test, f->sense[12], asc); + KUNIT_EXPECT_EQ(test, f->sense[13], ascq); + KUNIT_EXPECT_EQ(test, f->cmd.resp_data_len, 0); + if (f->completions) + vdisk_test_expect_sense(test, &f->response, key, asc, ascq); +} + +static void flush_async_test(struct kunit *test) +{ + const struct flush_error_case *p = test->param_value; + struct flush_fixture *f = test->priv; + + f->bio_status = p->status; + KUNIT_EXPECT_EQ(test, vdisk_blockio_flush(f->disk->part0, GFP_KERNEL, true, + &f->cmd, true), 0); + KUNIT_EXPECT_EQ(test, f->submissions, 1U); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + if (p->error) { + flush_expect_sense(test, MEDIUM_ERROR, 0x03, 0); + } else { + KUNIT_EXPECT_EQ(test, f->cmd.status, (u8)SAM_STAT_GOOD); + vdisk_test_expect_response(test, &f->response, SAM_STAT_GOOD, + FLUSH_TEST_DATA_LEN); + } +} + +static void flush_sync_test(struct kunit *test) +{ + const struct flush_error_case *p = test->param_value; + struct flush_fixture *f = test->priv; + + f->sync_flush_error = p->error; + /* Disabling logging must not suppress the SCSI error. */ + KUNIT_EXPECT_EQ(test, vdisk_blockio_flush(f->disk->part0, GFP_KERNEL, false, + &f->cmd, false), p->error); + KUNIT_EXPECT_EQ(test, f->sync_flushes, 1U); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + if (p->error) + flush_expect_sense(test, MEDIUM_ERROR, 0x03, 0); + else + KUNIT_EXPECT_EQ(test, f->cmd.status, (u8)SAM_STAT_GOOD); +} + +static void flush_verify_test(struct kunit *test) +{ + const struct flush_error_case *p = test->param_value; + struct flush_fixture *f = test->priv; + + f->sync_flush_error = p->error; + f->cmd.data_direction = SCST_DATA_NONE; + KUNIT_EXPECT_EQ(test, vdev_exec_verify(&f->params), CMD_SUCCEEDED); + KUNIT_EXPECT_EQ(test, f->sync_flushes, 1U); + KUNIT_EXPECT_EQ(test, f->reads, p->error ? 0U : 1U); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + if (p->error) + flush_expect_sense(test, MEDIUM_ERROR, 0x03, 0); + else + KUNIT_EXPECT_EQ(test, f->cmd.status, (u8)SAM_STAT_GOOD); +} + +static void flush_start_stop_test(struct kunit *test) +{ + const struct flush_error_case *p = test->param_value; + struct flush_fixture *f = test->priv; + + f->sync_flush_error = p->error; + KUNIT_EXPECT_EQ(test, vdisk_exec_start_stop(&f->params), CMD_SUCCEEDED); + KUNIT_EXPECT_EQ(test, f->sync_flushes, 1U); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + KUNIT_EXPECT_EQ(test, f->completions, 0U); + if (p->error) + flush_expect_sense(test, MEDIUM_ERROR, 0x03, 0); + else + KUNIT_EXPECT_EQ(test, f->cmd.status, (u8)SAM_STAT_GOOD); +} + +static void flush_synchronize_test(struct kunit *test, bool immed) +{ + const struct flush_error_case *p = test->param_value; + struct flush_fixture *f = test->priv; + struct bio *bio; + + f->defer = true; + f->cmd.cdb[1] = immed ? 2 : 0; + f->cmd.resp_data_len = 0; + KUNIT_EXPECT_EQ(test, vdisk_synchronize_cache(&f->params), RUNNING_ASYNC); + KUNIT_EXPECT_EQ(test, f->completions, immed ? 1U : 0U); + KUNIT_EXPECT_EQ(test, kref_read(&f->cmd.cmd_ref), 1U); + KUNIT_ASSERT_EQ(test, f->submissions, 1U); + bio = f->pending; + KUNIT_ASSERT_NOT_NULL(test, bio); + KUNIT_EXPECT_PTR_EQ(test, bio->bi_private, immed ? NULL : &f->cmd); + f->pending = NULL; + bio->bi_status = p->status; + bio_endio(bio); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + if (p->error && !immed) { + flush_expect_sense(test, MEDIUM_ERROR, 0x03, 0); + } else { + KUNIT_EXPECT_EQ(test, f->cmd.status, (u8)SAM_STAT_GOOD); + vdisk_test_expect_response(test, &f->response, SAM_STAT_GOOD, 0); + } +} + +static void flush_synchronize_wait_test(struct kunit *test) +{ + flush_synchronize_test(test, false); +} + +static void flush_synchronize_immed_test(struct kunit *test) +{ + flush_synchronize_test(test, true); +} + +struct flush_alloc_case { + const char *name; + unsigned int commands; + bool no_cmd; + bool prior_error; + u8 status; +}; + +static const struct flush_alloc_case flush_alloc_cases[] = { + { "busy", 1, false, false, SAM_STAT_BUSY }, + { "task_set_full", 2, false, false, SAM_STAT_TASK_SET_FULL }, + { "commandless", 1, true, false, SAM_STAT_GOOD }, + { "prior_dif_error", 1, false, true, SAM_STAT_CHECK_CONDITION }, +}; + +static void flush_alloc_desc(const struct flush_alloc_case *p, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name); +} + +KUNIT_ARRAY_PARAM(flush_alloc, flush_alloc_cases, flush_alloc_desc); + +static void flush_alloc_test(struct kunit *test) +{ + const struct flush_alloc_case *p = test->param_value; + struct flush_fixture *f = test->priv; + + kunit_activate_static_stub(test, vdisk_alloc_flush_bio, flush_alloc_fail); + atomic_set(&f->sess.sess_cmd_count, p->commands); + if (p->prior_error) + scst_set_cmd_error(&f->cmd, + SCST_LOAD_SENSE(scst_logical_block_app_tag_check_failed)); + KUNIT_EXPECT_EQ(test, vdisk_blockio_flush(f->disk->part0, GFP_KERNEL, true, + p->no_cmd ? NULL : &f->cmd, true), -ENOMEM); + KUNIT_EXPECT_EQ(test, f->completions, p->no_cmd ? 0U : 1U); + KUNIT_EXPECT_EQ(test, f->cmd.status, p->status); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + if (!p->no_cmd) + vdisk_test_expect_response(test, &f->response, p->status, 0); + if (p->prior_error) + flush_expect_sense(test, ABORTED_COMMAND, 0x10, 0x02); +} + +struct flush_synchronize_alloc_case { + const char *name; + unsigned int commands; + bool immed; + u8 status; +}; + +static const struct flush_synchronize_alloc_case flush_synchronize_alloc_cases[] = { + { "busy", 1, false, SAM_STAT_BUSY }, + { "task_set_full", 2, false, SAM_STAT_TASK_SET_FULL }, + { "immed", 1, true, SAM_STAT_GOOD }, +}; + +static void flush_synchronize_alloc_desc(const struct flush_synchronize_alloc_case *p, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name); +} + +KUNIT_ARRAY_PARAM(flush_synchronize_alloc, flush_synchronize_alloc_cases, + flush_synchronize_alloc_desc); + +static void flush_synchronize_alloc_test(struct kunit *test) +{ + const struct flush_synchronize_alloc_case *p = test->param_value; + struct flush_fixture *f = test->priv; + + kunit_activate_static_stub(test, vdisk_alloc_flush_bio, flush_alloc_fail); + atomic_set(&f->sess.sess_cmd_count, p->commands); + f->cmd.cdb[1] = p->immed ? 2 : 0; + f->cmd.resp_data_len = 0; + KUNIT_EXPECT_EQ(test, vdisk_synchronize_cache(&f->params), RUNNING_ASYNC); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + KUNIT_EXPECT_EQ(test, f->cmd.status, p->status); + vdisk_test_expect_response(test, &f->response, p->status, 0); + KUNIT_EXPECT_EQ(test, f->submissions, 0U); + KUNIT_EXPECT_EQ(test, f->sync_flushes, 0U); + KUNIT_EXPECT_PTR_EQ(test, f->pending, NULL); + KUNIT_EXPECT_EQ(test, kref_read(&f->cmd.cmd_ref), 1U); +} + +static struct kunit_case flush_cases[] = { + KUNIT_CASE_PARAM(flush_async_test, flush_error_gen_params), + KUNIT_CASE_PARAM(flush_sync_test, flush_error_gen_params), + KUNIT_CASE_PARAM(flush_verify_test, flush_error_gen_params), + KUNIT_CASE_PARAM(flush_start_stop_test, flush_error_gen_params), + KUNIT_CASE_PARAM(flush_synchronize_wait_test, flush_error_gen_params), + KUNIT_CASE_PARAM(flush_synchronize_immed_test, flush_error_gen_params), + KUNIT_CASE_PARAM(flush_alloc_test, flush_alloc_gen_params), + KUNIT_CASE_PARAM(flush_synchronize_alloc_test, flush_synchronize_alloc_gen_params), + {} +}; + +scst_kunit_suite(flush_suite, "VDISK", "-flush", + .init = flush_init, + .exit = flush_exit, + .test_cases = flush_cases, +); diff --git a/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_sync_test.c b/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_sync_test.c index d079e32..da2136b 100644 --- a/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_sync_test.c +++ b/scst/src/dev_handlers/kunit/vdisk/suites/scst_vdisk_sync_test.c @@ -108,6 +108,10 @@ static const struct vdisk_flush_case vdisk_flush_cases[] = { .blocks = 1 }, { .name = "dif_error_skips_block_flush", .blockio = true, .dif_shift = 9, .dif_error = -EIO, .files = 1, .error = -EIO }, + { .name = "async_dif_error_completes", .async = true, .blockio = true, .dif_shift = 9, + .dif_error = -EIO, .files = 1, .error = -EIO }, + { .name = "commandless_dif_error", .async = true, .no_cmd = true, + .blockio = true, .dif_shift = 9, .dif_error = -EIO, .files = 1, .error = -EIO }, }; static void vdisk_flush_desc(const struct vdisk_flush_case *p, char *desc) @@ -146,6 +150,11 @@ static void vdisk_flush_test(struct kunit *test) if (p->async && !p->no_cmd) { KUNIT_EXPECT_EQ(test, f->completion_state, SCST_CMD_STATE_DEFAULT); KUNIT_EXPECT_TRUE(test, f->completed_before_callback); + if (p->error) + vdisk_test_expect_sense(test, &f->response, MEDIUM_ERROR, 0x03, 0); + else + vdisk_test_expect_response(test, &f->response, SAM_STAT_GOOD, + sizeof(f->written)); } KUNIT_EXPECT_EQ(test, !!f->cmd.completed, (p->async || p->error) && !p->no_cmd); KUNIT_EXPECT_EQ(test, f->cmd.status, @@ -160,6 +169,64 @@ static void vdisk_flush_test(struct kunit *test) } } +struct vdisk_sync_dif_error_case { + const char *name; + int error; + unsigned int commands; + bool immed; + u8 status; +}; + +static const struct vdisk_sync_dif_error_case vdisk_sync_dif_errors[] = { + { "io_error", -EIO, 1, false, SAM_STAT_CHECK_CONDITION }, + { "busy", -ENOMEM, 1, false, SAM_STAT_BUSY }, + { "task_set_full", -ENOMEM, 2, false, SAM_STAT_TASK_SET_FULL }, + { "immed_io_error", -EIO, 1, true, SAM_STAT_GOOD }, + { "immed_memory_pressure", -ENOMEM, 1, true, SAM_STAT_GOOD }, +}; + +static void vdisk_sync_dif_error_desc(const struct vdisk_sync_dif_error_case *p, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s", p->name); +} + +KUNIT_ARRAY_PARAM(vdisk_sync_dif_error, vdisk_sync_dif_errors, vdisk_sync_dif_error_desc); + +static void vdisk_sync_dif_error_test(struct kunit *test) +{ + const struct vdisk_sync_dif_error_case *p = test->param_value; + struct vdisk_test_fixture *f = test->priv; + + f->vdev.blockio = true; + f->vdev.bdev_desc.bdev = &f->bdev; + f->vdev.dif_fd = &f->dif.file; + f->dif.sync_result = p->error; + atomic_set(&f->sess.sess_cmd_count, p->commands); + f->cmd.cdb[0] = SYNCHRONIZE_CACHE; + f->cmd.cdb[1] = p->immed ? 2 : 0; + f->cmd.data_direction = SCST_DATA_NONE; + f->cmd.data_len = 4096; + f->cmd.bufflen = 0; + f->cmd.resp_data_len = 0; + + KUNIT_EXPECT_EQ(test, vdisk_synchronize_cache(&f->params), RUNNING_ASYNC); + KUNIT_EXPECT_EQ(test, f->completions, 1U); + KUNIT_EXPECT_EQ(test, f->completion_state, SCST_CMD_STATE_DEFAULT); + KUNIT_EXPECT_TRUE(test, f->completed_before_callback); + KUNIT_EXPECT_EQ(test, f->cmd.status, p->status); + KUNIT_EXPECT_EQ(test, f->cmd.resp_data_len, 0); + vdisk_test_expect_response(test, &f->response, p->status, 0); + if (p->status == SAM_STAT_CHECK_CONDITION) + vdisk_test_expect_sense(test, &f->response, MEDIUM_ERROR, 0x03, 0); + KUNIT_EXPECT_EQ(test, f->flush_count, 1U); + KUNIT_EXPECT_EQ(test, f->block_flush_count, 0U); + vdisk_test_expect_flush(test, 0, &f->dif.file, 128, 191); + /* IMMED must complete before syncing DIF and retain the command meanwhile. */ + KUNIT_EXPECT_EQ(test, f->flushes[0].completions, p->immed ? 1U : 0U); + KUNIT_EXPECT_EQ(test, f->flushes[0].cmd_refs, p->immed ? 2 : 1); + KUNIT_EXPECT_EQ(test, kref_read(&f->cmd.cmd_ref), 1U); +} + struct vdisk_backend_case { const char *name; bool closed; @@ -232,6 +299,7 @@ static void vdisk_backend_test(struct kunit *test) static struct kunit_case vdisk_sync_cases[] = { KUNIT_CASE_PARAM(vdisk_range_test, vdisk_range_gen_params), KUNIT_CASE_PARAM(vdisk_flush_test, vdisk_flush_gen_params), + KUNIT_CASE_PARAM(vdisk_sync_dif_error_test, vdisk_sync_dif_error_gen_params), KUNIT_CASE_PARAM(vdisk_backend_test, vdisk_backend_gen_params), {} }; diff --git a/scst/src/dev_handlers/scst_vdisk_main.c b/scst/src/dev_handlers/scst_vdisk_main.c index 63b74b8..dfed54d 100644 --- a/scst/src/dev_handlers/scst_vdisk_main.c +++ b/scst/src/dev_handlers/scst_vdisk_main.c @@ -276,13 +276,19 @@ out_put: TRACE_EXIT(); } -static struct bio *vdisk_alloc_flush_bio(gfp_t gfp_mask) +SCST_KUNIT_VISIBLE +struct bio *vdisk_alloc_flush_bio(gfp_t gfp_mask) { + SCST_KUNIT_REDIRECT(vdisk_alloc_flush_bio, gfp_mask); + return bio_alloc(/*bdev=*/NULL, 0, /*opf=*/0, gfp_mask); } -static void vdisk_submit_flush_bio(struct bio *bio) +SCST_KUNIT_VISIBLE +void vdisk_submit_flush_bio(struct bio *bio) { + SCST_KUNIT_REDIRECT(vdisk_submit_flush_bio, bio); + #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || \ (defined(CONFIG_SUSE_KERNEL) && \ LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) @@ -303,8 +309,11 @@ static void vdisk_submit_flush_bio(struct bio *bio) #endif } -static int vdisk_issue_flush(struct block_device *bdev, gfp_t gfp_mask) +SCST_KUNIT_VISIBLE +int vdisk_issue_flush(struct block_device *bdev, gfp_t gfp_mask) { + SCST_KUNIT_REDIRECT(vdisk_issue_flush, bdev, gfp_mask); + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0) && \ (!defined(RHEL_MAJOR) || RHEL_MAJOR - 0 < 8 || \ RHEL_MAJOR - 0 == 8 && RHEL_MINOR - 0 < 4) @@ -1599,7 +1608,8 @@ enum compl_status_e vdisk_synchronize_cache(struct vdisk_cmd_params *p) return res; } -static enum compl_status_e vdisk_exec_start_stop(struct vdisk_cmd_params *p) +SCST_KUNIT_VISIBLE +enum compl_status_e vdisk_exec_start_stop(struct vdisk_cmd_params *p) { struct scst_cmd *cmd = p->cmd; struct scst_device *dev = cmd->dev; @@ -2931,9 +2941,12 @@ out: } /* Note: Updates *@loff if reading succeeded except for NULLIO devices. */ -static ssize_t vdev_read_sync(struct scst_vdisk_dev *virt_dev, void *buf, - size_t len, loff_t *loff) +SCST_KUNIT_VISIBLE +ssize_t vdev_read_sync(struct scst_vdisk_dev *virt_dev, void *buf, + size_t len, loff_t *loff) { + SCST_KUNIT_REDIRECT(vdev_read_sync, virt_dev, buf, len, loff); + if (virt_dev->nullio) { return len; } else if (virt_dev->blockio) { @@ -6282,7 +6295,8 @@ out: return res; } -static enum compl_status_e vdev_exec_verify(struct vdisk_cmd_params *p) +SCST_KUNIT_VISIBLE +enum compl_status_e vdev_exec_verify(struct vdisk_cmd_params *p) { return vdev_verify(p->cmd, p->loff); } diff --git a/scst/src/dev_handlers/scst_vdisk_test.h b/scst/src/dev_handlers/scst_vdisk_test.h index 7447b35..5c4d5d5 100644 --- a/scst/src/dev_handlers/scst_vdisk_test.h +++ b/scst/src/dev_handlers/scst_vdisk_test.h @@ -7,6 +7,14 @@ #ifdef SCST_KUNIT_ENABLED struct vdisk_cmd_params; +struct scst_vdisk_dev; + +struct bio *vdisk_alloc_flush_bio(gfp_t gfp_mask); +void vdisk_submit_flush_bio(struct bio *bio); +int vdisk_issue_flush(struct block_device *bdev, gfp_t gfp_mask); +ssize_t vdev_read_sync(struct scst_vdisk_dev *virt_dev, void *buf, size_t len, loff_t *loff); +enum compl_status_e vdev_exec_verify(struct vdisk_cmd_params *p); +enum compl_status_e vdisk_exec_start_stop(struct vdisk_cmd_params *p); int vdisk_blockio_flush(struct block_device *bdev, gfp_t gfp_mask, bool report_error, struct scst_cmd *cmd, bool async); diff --git a/scst/src/kunit/objects.mk b/scst/src/kunit/objects.mk index efc30db..20a2cec 100644 --- a/scst/src/kunit/objects.mk +++ b/scst/src/kunit/objects.mk @@ -38,6 +38,7 @@ scst-kunit-scst_user := \ scst-kunit-scst_vdisk := \ kunit/vdisk/scst_vdisk_fixture.o \ kunit/vdisk/suites/scst_vdisk_capacity_test.o \ + kunit/vdisk/suites/scst_vdisk_flush_test.o \ kunit/vdisk/suites/scst_vdisk_io_test.o \ kunit/vdisk/suites/scst_vdisk_protocol_test.o \ kunit/vdisk/suites/scst_vdisk_sync_test.o \ |
|
From: SCST G. <lna...@ya...> - 2026-11-13 17:55:23
|
Commit: eb49aff GitHub URL: https://github.com/SCST-project/scst/commit/eb49aff4c7de2c95e1c992c8a8dd873c669b2259 Author: Gleb Chesnokov Date: 2026-11-13T20:52:25+03:00 Log Message: ----------- scst_vdisk: Preserve block backend transport errors Report ENOLINK as NOT READY / LOGICAL UNIT COMMUNICATION FAILURE for block reads, writes, flushes and discards. Use the read mapping for backend failures during VERIFY as well. This preserves an explicit transport failure instead of turning it into an operation-specific medium error. Keep separate helpers for each operation and retain all other error mappings, including the WRITE-only ENOSPC response. Do not infer path loss from EIO or ENODEV, change ALUA or backend lifecycle, or alter command completion and first-error handling. Modified Paths: -------------- scst/src/dev_handlers/scst_vdisk_main.c | 91 +++++++++++---- 1 file changed, 71 insertions(+), 20 deletions(-) =================================================================== diff --git a/scst/src/dev_handlers/scst_vdisk_main.c b/scst/src/dev_handlers/scst_vdisk_main.c index dfed54d..e056037 100644 --- a/scst/src/dev_handlers/scst_vdisk_main.c +++ b/scst/src/dev_handlers/scst_vdisk_main.c @@ -239,6 +239,70 @@ static struct file *vdev_open_fd(const struct scst_vdisk_dev *virt_dev, const ch return fd; } +/* + * ENOLINK identifies a backend transport failure, not a medium error or an + * ALUA state change. Keep the existing per-operation sense for other errors. + */ +static void vdisk_blockio_set_read_error(struct scst_cmd *cmd, int error) +{ + switch (error) { + case -ENOLINK: + /* LOGICAL UNIT COMMUNICATION FAILURE */ + scst_set_cmd_error(cmd, NOT_READY, 0x08, 0); + break; + default: + scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_read_error)); + break; + } +} + +static void vdisk_blockio_set_write_error(struct scst_cmd *cmd, int error) +{ + switch (error) { + case -ENOLINK: + /* LOGICAL UNIT COMMUNICATION FAILURE */ + scst_set_cmd_error(cmd, NOT_READY, 0x08, 0); + break; + case -ENOSPC: { + const struct scst_vdisk_dev *virt_dev = cmd->dev->dh_priv; + + WARN_ON(!virt_dev->thin_provisioned); + scst_set_cmd_error(cmd, + SCST_LOAD_SENSE(scst_space_allocation_failed_write_protect)); + break; + } + default: + scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_write_error)); + break; + } +} + +static void vdisk_blockio_set_flush_error(struct scst_cmd *cmd, int error) +{ + switch (error) { + case -ENOLINK: + /* LOGICAL UNIT COMMUNICATION FAILURE */ + scst_set_cmd_error(cmd, NOT_READY, 0x08, 0); + break; + default: + scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_write_error)); + break; + } +} + +static void vdisk_blockio_set_discard_error(struct scst_cmd *cmd, int error) +{ + switch (error) { + case -ENOLINK: + /* LOGICAL UNIT COMMUNICATION FAILURE */ + scst_set_cmd_error(cmd, NOT_READY, 0x08, 0); + break; + default: + scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_write_error)); + break; + } +} + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) static void vdev_flush_end_io(struct bio *bio, int error) #else @@ -261,7 +325,7 @@ static void vdev_flush_end_io(struct bio *bio) PRINT_ERROR("FLUSH bio failed: %d (cmd %p)", error, cmd); if (cmd) - scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_write_error)); + vdisk_blockio_set_flush_error(cmd, error); } if (!cmd) @@ -367,7 +431,7 @@ out_rep: /* Allocation failed before any flush BIO was submitted. */ scst_set_busy(cmd); else - scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_write_error)); + vdisk_blockio_set_flush_error(cmd, res); } if (async && cmd) { @@ -1811,7 +1875,7 @@ static int vdisk_unmap_range(struct scst_cmd *cmd, struct scst_vdisk_dev *virt_d if (unlikely(err != 0)) { PRINT_ERROR("blkdev_issue_discard() for LBA %lld, blocks %lld failed: %d", (unsigned long long)start_lba, blocks, err); - scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_write_error)); + vdisk_blockio_set_discard_error(cmd, err); res = -EIO; goto out; } @@ -3017,6 +3081,8 @@ static enum compl_status_e vdev_verify(struct scst_cmd *cmd, loff_t loff) (unsigned long long)err, len_mem); if (err == -EAGAIN) scst_set_busy(cmd); + else if (virt_dev->blockio && err < 0) + vdisk_blockio_set_read_error(cmd, err); else scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_read_error)); if (compare) @@ -5757,24 +5823,9 @@ static void blockio_endio(struct bio *bio) #else if (op_is_write(bio_op(bio))) { #endif - if (error == -ENOSPC) { - const struct scst_vdisk_dev *virt_dev = - blockio_work->cmd->dev->dh_priv; - - WARN_ON(!virt_dev->thin_provisioned); - scst_set_cmd_error(blockio_work->cmd, - /* - * checkpatch-suppress LONG_LINE ; Keep the - * complete symbolic sense name. - */ - SCST_LOAD_SENSE(scst_space_allocation_failed_write_protect)); - } else { - scst_set_cmd_error(blockio_work->cmd, - SCST_LOAD_SENSE(scst_sense_write_error)); - } + vdisk_blockio_set_write_error(blockio_work->cmd, error); } else { - scst_set_cmd_error(blockio_work->cmd, - SCST_LOAD_SENSE(scst_sense_read_error)); + vdisk_blockio_set_read_error(blockio_work->cmd, error); } spin_unlock_irqrestore(&vdev_err_lock, flags); |
|
From: SCST G. <lna...@ya...> - 2026-11-13 17:55:15
|
Commit: f12a6ee GitHub URL: https://github.com/SCST-project/scst/commit/f12a6ee21dfd99afbb8c24419dd2d40f17dfb305 Author: Gleb Chesnokov Date: 2026-11-13T20:52:25+03:00 Log Message: ----------- scst_vdisk: Isolate block I/O calls for fault injection Wrap data BIO allocation and submission and block discard issuance so task-scoped KUnit stubs can supply backend failures while exercising the real completion paths. Share the data BIO wrappers with synchronous VERIFY reads and preserve the existing kernel compatibility branches. Make blockio_exec_rw() and vdisk_unmap_range() visible only in KUnit builds. Keep these private test interfaces separate from test coverage; normal builds retain static functions and no redirects. Modified Paths: -------------- scst/src/dev_handlers/scst_vdisk_main.c | 63 ++++++++++----- scst/src/dev_handlers/scst_vdisk_test.h | 7 ++ 2 files changed, 48 insertions(+), 22 deletions(-) =================================================================== diff --git a/scst/src/dev_handlers/scst_vdisk_main.c b/scst/src/dev_handlers/scst_vdisk_main.c index e056037..d546778 100644 --- a/scst/src/dev_handlers/scst_vdisk_main.c +++ b/scst/src/dev_handlers/scst_vdisk_main.c @@ -1844,8 +1844,18 @@ static int vdisk_unmap_file_range(struct scst_cmd *cmd, struct scst_vdisk_dev *v return res; } -static int vdisk_unmap_range(struct scst_cmd *cmd, struct scst_vdisk_dev *virt_dev, - u64 start_lba, u64 blocks) +SCST_KUNIT_VISIBLE +int vdisk_issue_discard(struct block_device *bdev, sector_t start, sector_t sectors, + gfp_t gfp_mask) +{ + SCST_KUNIT_REDIRECT(vdisk_issue_discard, bdev, start, sectors, gfp_mask); + + return blkdev_issue_discard(bdev, start, sectors, gfp_mask); +} + +SCST_KUNIT_VISIBLE +int vdisk_unmap_range(struct scst_cmd *cmd, struct scst_vdisk_dev *virt_dev, + u64 start_lba, u64 blocks) { int res, err; @@ -1871,7 +1881,7 @@ static int vdisk_unmap_range(struct scst_cmd *cmd, struct scst_vdisk_dev *virt_d sector_t nr_sects = blocks << (cmd->dev->block_shift - 9); gfp_t gfp = cmd->cmd_gfp_mask; - err = blkdev_issue_discard(bdev, start_sector, nr_sects, gfp); + err = vdisk_issue_discard(bdev, start_sector, nr_sects, gfp); if (unlikely(err != 0)) { PRINT_ERROR("blkdev_issue_discard() for LBA %lld, blocks %lld failed: %d", (unsigned long long)start_lba, blocks, err); @@ -2916,6 +2926,28 @@ static void blockio_end_sync_io(struct bio *bio) complete(&s->c); } +SCST_KUNIT_VISIBLE +struct bio *vdisk_alloc_bio(int nr_vecs, gfp_t gfp_mask, struct bio_set *bs) +{ + SCST_KUNIT_REDIRECT(vdisk_alloc_bio, nr_vecs, gfp_mask, bs); + + return bio_alloc_bioset(/*bdev=*/NULL, nr_vecs, /*opf=*/0, gfp_mask, bs); +} + +SCST_KUNIT_VISIBLE +void vdisk_submit_bio(struct bio *bio) +{ + SCST_KUNIT_REDIRECT(vdisk_submit_bio, bio); + +#if (!defined(CONFIG_SUSE_KERNEL) && \ + LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0)) || \ + LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) + submit_bio(bio->bi_rw, bio); +#else + submit_bio(bio); +#endif +} + /* * blockio_read_sync() - read up to @len bytes from a block I/O device * @@ -2948,8 +2980,7 @@ static ssize_t blockio_read_sync(struct scst_vdisk_dev *virt_dev, void *buf, max_nr_vecs = min(bio_get_nr_vecs(bdev), BIO_MAX_VECS); #endif - bio = bio_alloc_bioset(/*bdev=*/NULL, max_nr_vecs, /*opf=*/0, - GFP_KERNEL, virt_dev->vdisk_bioset); + bio = vdisk_alloc_bio(max_nr_vecs, GFP_KERNEL, virt_dev->vdisk_bioset); if (!bio) goto out; @@ -2983,13 +3014,7 @@ static ssize_t blockio_read_sync(struct scst_vdisk_dev *virt_dev, void *buf, } } } -#if (!defined(CONFIG_SUSE_KERNEL) && \ - LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0)) || \ - LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) - submit_bio(bio->bi_rw, bio); -#else - submit_bio(bio); -#endif + vdisk_submit_bio(bio); wait_for_completion(&s.c); ret = (unsigned long)s.error; if (likely(ret == 0)) { @@ -5973,7 +5998,8 @@ static void vdisk_blk_add_dif(struct bio *bio, gfp_t gfp_mask, const struct scst } #endif /* defined(CONFIG_BLK_DEV_INTEGRITY) */ -static void blockio_exec_rw(struct vdisk_cmd_params *p, bool write, bool fua) +SCST_KUNIT_VISIBLE +void blockio_exec_rw(struct vdisk_cmd_params *p, bool write, bool fua) { struct scst_cmd *cmd = p->cmd; u64 lba_start = scst_cmd_get_lba(cmd); @@ -6069,8 +6095,7 @@ static void blockio_exec_rw(struct vdisk_cmd_params *p, bool write, bool fua) int rc; if (need_new_bio) { - bio = bio_alloc_bioset(/*bdev=*/NULL, max_nr_vecs, /*opf=*/0, - gfp_mask, bs); + bio = vdisk_alloc_bio(max_nr_vecs, gfp_mask, bs); if (!bio) { PRINT_ERROR("Failed to create bio for data segment %d (cmd %p)", cmd->get_sg_buf_entry_num, cmd); @@ -6163,13 +6188,7 @@ static void blockio_exec_rw(struct vdisk_cmd_params *p, bool write, bool fua) hbio = hbio->bi_next; bio->bi_next = NULL; -#if (!defined(CONFIG_SUSE_KERNEL) && \ - LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0)) || \ - LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) - submit_bio(bio->bi_rw, bio); -#else - submit_bio(bio); -#endif + vdisk_submit_bio(bio); } blk_finish_plug(&plug); diff --git a/scst/src/dev_handlers/scst_vdisk_test.h b/scst/src/dev_handlers/scst_vdisk_test.h index 5c4d5d5..090058b 100644 --- a/scst/src/dev_handlers/scst_vdisk_test.h +++ b/scst/src/dev_handlers/scst_vdisk_test.h @@ -9,6 +9,13 @@ struct vdisk_cmd_params; struct scst_vdisk_dev; +struct bio *vdisk_alloc_bio(int nr_vecs, gfp_t gfp_mask, struct bio_set *bs); +void vdisk_submit_bio(struct bio *bio); +void blockio_exec_rw(struct vdisk_cmd_params *p, bool write, bool fua); +int vdisk_issue_discard(struct block_device *bdev, sector_t start, sector_t sectors, + gfp_t gfp_mask); +int vdisk_unmap_range(struct scst_cmd *cmd, struct scst_vdisk_dev *virt_dev, + u64 start_lba, u64 blocks); struct bio *vdisk_alloc_flush_bio(gfp_t gfp_mask); void vdisk_submit_flush_bio(struct bio *bio); int vdisk_issue_flush(struct block_device *bdev, gfp_t gfp_mask); |
|
From: SCST G. <lna...@ya...> - 2026-11-13 17:54:32
|
Commit: 0a4ef91 GitHub URL: https://github.com/SCST-project/scst/commit/0a4ef919ae6a3d8065b893d3e9b8b923023c5937 Author: Gleb Chesnokov Date: 2026-11-13T20:52:25+03:00 Log Message: ----------- scst_vdisk: Isolate block flush calls for fault injection Flush command tests need to replace backend execution and reproduce BIO allocation failures without submitting I/O to a real device. Extract private wrappers for flush BIO allocation, flush BIO submission and synchronous block flush. Keep the existing kernel compatibility branches, request flags and ordering unchanged. Leave read, write and discard submission paths alone. This patch only prepares the flush operations for testing. KUnit visibility and static stubs are added separately. Modified Paths: -------------- scst/src/dev_handlers/scst_vdisk_main.c | 75 +++++++++------ 1 file changed, 45 insertions(+), 30 deletions(-) =================================================================== diff --git a/scst/src/dev_handlers/scst_vdisk_main.c b/scst/src/dev_handlers/scst_vdisk_main.c index 773b14c..63b74b8 100644 --- a/scst/src/dev_handlers/scst_vdisk_main.c +++ b/scst/src/dev_handlers/scst_vdisk_main.c @@ -276,6 +276,48 @@ out_put: TRACE_EXIT(); } +static struct bio *vdisk_alloc_flush_bio(gfp_t gfp_mask) +{ + return bio_alloc(/*bdev=*/NULL, 0, /*opf=*/0, gfp_mask); +} + +static void vdisk_submit_flush_bio(struct bio *bio) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || \ + (defined(CONFIG_SUSE_KERNEL) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) + /* + * For the introduction of REQ_PREFLUSH, see also commit + * 28a8f0d317bf ("block, drivers, fs: rename REQ_FLUSH to + * REQ_PREFLUSH") # v4.8. + */ + bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH; + submit_bio(bio); +#else + /* + * For the introduction of WRITE_FLUSH, see also commit + * 4fed947cb311 ("block: implement REQ_FLUSH/FUA based + * interface for FLUSH/FUA requests") # v2.6.37. + */ + submit_bio(WRITE_FLUSH, bio); +#endif +} + +static int vdisk_issue_flush(struct block_device *bdev, gfp_t gfp_mask) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0) && \ + (!defined(RHEL_MAJOR) || RHEL_MAJOR - 0 < 8 || \ + RHEL_MAJOR - 0 == 8 && RHEL_MINOR - 0 < 4) + return blkdev_issue_flush(bdev, gfp_mask, NULL); +#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0) && \ + (!defined(RHEL_MAJOR) || RHEL_MAJOR - 0 < 8 || \ + RHEL_MAJOR - 0 == 8 && RHEL_MINOR - 0 < 6) + return blkdev_issue_flush(bdev, gfp_mask); +#else + return blkdev_issue_flush(bdev); +#endif +} + SCST_KUNIT_VISIBLE int vdisk_blockio_flush(struct block_device *bdev, gfp_t gfp_mask, bool report_error, struct scst_cmd *cmd, bool async) @@ -289,7 +331,7 @@ int vdisk_blockio_flush(struct block_device *bdev, gfp_t gfp_mask, bool report_e if (async) { struct bio *bio; - bio = bio_alloc(/*bdev=*/NULL, 0, /*opf=*/0, gfp_mask); + bio = vdisk_alloc_flush_bio(gfp_mask); if (!bio) { res = -ENOMEM; goto out_rep; @@ -300,37 +342,10 @@ int vdisk_blockio_flush(struct block_device *bdev, gfp_t gfp_mask, bool report_e bio_set_dev(bio, bdev); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || \ - (defined(CONFIG_SUSE_KERNEL) && \ - LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) - /* - * For the introduction of REQ_PREFLUSH, see also commit - * 28a8f0d317bf ("block, drivers, fs: rename REQ_FLUSH to - * REQ_PREFLUSH") # v4.8. - */ - bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH; - submit_bio(bio); -#else - /* - * For the introduction of WRITE_FLUSH, see also commit - * 4fed947cb311 ("block: implement REQ_FLUSH/FUA based - * interface for FLUSH/FUA requests") # v2.6.37. - */ - submit_bio(WRITE_FLUSH, bio); -#endif + vdisk_submit_flush_bio(bio); goto out; } else { -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR - 0 < 8 || \ - RHEL_MAJOR - 0 == 8 && RHEL_MINOR - 0 < 4) - res = blkdev_issue_flush(bdev, gfp_mask, NULL); -#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR - 0 < 8 || \ - RHEL_MAJOR - 0 == 8 && RHEL_MINOR - 0 < 6) - res = blkdev_issue_flush(bdev, gfp_mask); -#else - res = blkdev_issue_flush(bdev); -#endif + res = vdisk_issue_flush(bdev, gfp_mask); } out_rep: |
|
From: SCST G. <lna...@ya...> - 2026-11-13 17:54:20
|
Commit: bb7ec66 GitHub URL: https://github.com/SCST-project/scst/commit/bb7ec66f765f8aca88eaffdb98efa6e39bb2114c Author: Gleb Chesnokov Date: 2026-11-13T20:52:25+03:00 Log Message: ----------- scst_vdisk: Report flush failures and complete commands once A failed synchronous block flush leaves the command successful, and an asynchronous flush allocation failure completes it with GOOD. A DIF file flush error before asynchronous block submission leaves the command without a completion callback. Set the existing write-error sense for synchronous block flush failures. Report resource pressure when no flush BIO could be allocated. Complete an asynchronous command after an early DIF flush failure; retain synchronous completion ownership and IMMED behavior. Modified Paths: -------------- scst/src/dev_handlers/scst_vdisk_main.c | 17 ++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) =================================================================== diff --git a/scst/src/dev_handlers/scst_vdisk_main.c b/scst/src/dev_handlers/scst_vdisk_main.c index 1531b0c..773b14c 100644 --- a/scst/src/dev_handlers/scst_vdisk_main.c +++ b/scst/src/dev_handlers/scst_vdisk_main.c @@ -338,6 +338,14 @@ out_rep: PRINT_ERROR("%s() failed: %d", async ? "bio_alloc" : "blkdev_issue_flush", res); + if (res && cmd) { + if (async) + /* Allocation failed before any flush BIO was submitted. */ + scst_set_busy(cmd); + else + scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_write_error)); + } + if (async && cmd) { cmd->completed = 1; cmd->scst_cmd_done(cmd, SCST_CMD_STATE_DEFAULT, scst_estimate_context()); @@ -1445,8 +1453,15 @@ static int vdisk_fsync_blockio(loff_t loff, loff_t len, struct scst_device *dev, loff = (loff >> dev->block_shift) << SCST_DIF_TAG_SHIFT; len = (len >> dev->block_shift) << SCST_DIF_TAG_SHIFT; res = __vdisk_fsync_fileio(loff, len, dev, cmd, virt_dev->dif_fd); - if (unlikely(res != 0)) + if (unlikely(res != 0)) { + /* No flush BIO will be submitted to complete this command. */ + if (async && cmd) { + cmd->completed = 1; + cmd->scst_cmd_done(cmd, SCST_CMD_STATE_DEFAULT, + scst_estimate_context()); + } goto out; + } } res = vdisk_blockio_flush(virt_dev->bdev_desc.bdev, gfp_flags, true, cmd, async); |
|
From: SCST G. <lna...@ya...> - 2026-11-13 17:53:08
|
Commit: c390a34 GitHub URL: https://github.com/SCST-project/scst/commit/c390a34bc0001091299dde4ee4f3815164fc9702 Author: Gleb Chesnokov Date: 2026-11-13T20:52:25+03:00 Log Message: ----------- scripts: Isolate analyzer dependencies in CI Every native analyzer currently prepares Sparse, Smatch and kernel headers. A failed fetch can prevent unrelated analysis and common fixtures from running even when their own dependencies are available. Use separate Docker targets for each analyzer and the common fixtures. Keep the prepared kernel and build toolchain for Sparse, Smatch and Cppcheck. Give Coccinelle only spatch, cpp and the rules extracted from the same pinned kernel package. Install Smatch with its matching data and retain its frontend and asset installation fixes. Fetch Sparse and Smatch from the current bvanassche/sparse and error27/smatch master branches on GitHub without version pins. Refresh the selected analyzer's source layer on each CI run and rerun while allowing package and kernel layers to remain cached. Record the fetched commits. Follow current analyzer versions by default and pin only for a demonstrated compatibility problem. Run Checkpatch separately. Resolve the current torvalds/linux master on GitHub on each CI invocation, outside image caching, and fetch the script, spelling and const-struct data, and diagnostic documentation from that revision. Record the resolved SHA and file hashes without adding a pin. Publish the tool directory only after every download succeeds. Make up to three source fetch attempts with backoff and HTTP low-speed limits. Retain the final failure status and provenance. Bound Checkpatch reference resolution and retry its asset downloads too. Partition analyzer tests into common fixtures and native tool groups. Run each native group with its analyzer; keep the default all selection and incomplete-run checks. Add fixtures for dependency isolation, group selection and Checkpatch acquisition failures. Modified Paths: -------------- .github/workflows/analyzers.yml | 52 +++++- Makefile | 3 +- doc/CI.md | 10 +- scripts/README.md | 77 ++++++-- scripts/analyzer_run.py | 22 ++- scripts/analyzer_tests.py | 69 +++++--- scripts/ci/analyzers.Dockerfile | 50 +++++- scripts/ci/analyzers.env | 4 - scripts/ci/fetch-checkpatch | 52 ++++++ scripts/ci/install-analyzers | 137 ++++++++++----- scripts/ci/run-analyzer.py | 35 +++- scripts/coccinelle/coccicheck.py | 13 +- scripts/coccinelle/test_rules.py | 7 +- scripts/tests/test_analyzer_ci.py | 58 +++++- scripts/tests/test_analyzer_run.py | 33 ++++ scripts/tests/test_analyzer_tests.py | 81 ++++++++- scripts/tests/test_coccicheck.py | 11 +- scripts/tests/test_fetch_checkpatch.py | 123 +++++++++++++ 18 files changed, 694 insertions(+), 143 deletions(-) =================================================================== diff --git a/.github/workflows/analyzers.yml b/.github/workflows/analyzers.yml index 8a7848f..5e66656 100644 --- a/.github/workflows/analyzers.yml +++ b/.github/workflows/analyzers.yml @@ -45,6 +45,35 @@ jobs: retention-days: 7 path: .cache/lint/ + checkpatch: + name: checkpatch + runs-on: ubuntu-24.04 + timeout-minutes: 15 + continue-on-error: ${{ github.event_name == 'push' }} + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - name: Fetch Checkpatch and data from current Linux master + run: | + bash scripts/ci/fetch-checkpatch "$RUNNER_TEMP/checkpatch" \ + 2>&1 | tee "$RUNNER_TEMP/checkpatch-fetch.log" + echo "CHECKPATCH_PATH=$RUNNER_TEMP/checkpatch/scripts" >> "$GITHUB_ENV" + - name: Test Checkpatch integration + run: make analyzer-tests ANALYZER_TEST_GROUP=checkpatch + - name: Run make checkpatch + run: python3 -B scripts/ci/run-analyzer.py checkpatch + - name: Save complete analyzer evidence + if: always() + uses: actions/upload-artifact@v7 + with: + name: checkpatch-evidence + retention-days: 7 + path: | + ${{ runner.temp }}/checkpatch-fetch.log + ${{ runner.temp }}/checkpatch/ + .cache/lint/ + native: name: ${{ matrix.analyzer == 'analyzer-tests' && 'Analyzer tests' || matrix.analyzer }} runs-on: ubuntu-24.04 @@ -57,7 +86,6 @@ jobs: - analyzer-tests - sparse - smatch - - checkpatch - coccicheck - cppcheck steps: @@ -65,25 +93,31 @@ jobs: with: persist-credentials: false - name: Prepare analyzer environment + env: + DOCKER_BUILDKIT: "1" + ANALYZER: ${{ matrix.analyzer }} run: | - docker build -f scripts/ci/analyzers.Dockerfile -t scst-analyzers:local . \ + build_args=() + if [[ "$ANALYZER" == sparse || "$ANALYZER" == smatch ]]; then + build_args+=(--build-arg "ANALYZER_REFRESH=$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT") + fi + docker build -f scripts/ci/analyzers.Dockerfile --target "$ANALYZER" \ + "${build_args[@]}" -t scst-analyzers:local . \ 2>&1 | tee "$RUNNER_TEMP/analyzer-image.log" - name: Run make ${{ matrix.analyzer }} env: ANALYZER: ${{ matrix.analyzer }} run: | - source scripts/ci/kernel.env docker run --rm --init --network=none --cap-drop=ALL \ --security-opt=no-new-privileges --user "$(id -u):$(id -g)" \ --env HOME=/tmp --env GITHUB_ACTIONS=true \ --env GITHUB_STEP_SUMMARY=/scst/.cache/analyzer-summary \ - --env "KDIR=/usr/src/kernels/$KERNEL_BUILD.x86_64" \ --mount "type=bind,src=$PWD,dst=/scst" scst-analyzers:local \ - sh -c 'if [ "$1" = analyzer-tests ]; then - exec make analyzer-tests - else - exec python3 -B scripts/ci/run-analyzer.py "$1" - fi' -- "$ANALYZER" + sh -ec 'case "$1" in + analyzer-tests) exec make analyzer-tests ANALYZER_TEST_GROUP=common ;; + coccicheck|cppcheck) make analyzer-tests ANALYZER_TEST_GROUP="$1" ;; + esac + exec python3 -B scripts/ci/run-analyzer.py "$1"' -- "$ANALYZER" - name: Publish summary if: always() run: | diff --git a/Makefile b/Makefile index f612022..66623c3 100644 --- a/Makefile +++ b/Makefile @@ -330,9 +330,10 @@ lint-test: PYTHONDONTWRITEBYTECODE=1 $(PYTHON) -m unittest discover -s scripts/tests -v .PHONY: analyzer-tests +ANALYZER_TEST_GROUP ?= all analyzer-tests: export SCST_LINT_KDIR := $(KDIR) analyzer-tests: - +@$(PYTHON) -B scripts/analyzer_tests.py + +@$(PYTHON) -B scripts/analyzer_tests.py --group "$(ANALYZER_TEST_GROUP)" .PHONY: all-lint all-lint: sparse smatch coccicheck cppcheck checkpatch scs_lint diff --git a/doc/CI.md b/doc/CI.md index cd45c79..d3d98f6 100644 --- a/doc/CI.md +++ b/doc/CI.md @@ -51,8 +51,14 @@ kernel diagnostics and incomplete reports fail the run. Package artifacts are attached to the Packages workflow; upstream master builds also update the `master-rpm` prerelease snapshot. -Analyzer jobs fail on remaining findings and print them in job logs; container -jobs also retain reports as artifacts. The +Analyzer jobs fail on remaining findings, print them in job logs and retain +reports as artifacts. Each job prepares its own dependencies. Checkpatch uses +current Linux `master` from GitHub, including its dictionaries and documentation; +Sparse and Smatch use current `master` from `bvanassche/sparse` and +`error27/smatch` on GitHub without version pins. Each CI run and rerun refreshes +the selected analyzer's source layer and records the fetched commit. +Common tooling fixtures run separately, and native +model probes run with their corresponding analyzer. The [analyzer guide](../scripts/README.md#analyzer-ci) covers reproduction and the distinction between findings and incomplete analysis. diff --git a/scripts/README.md b/scripts/README.md index 6012f69..2055fb7 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -187,33 +187,52 @@ Exceptions match exact paths, messages and functions where applicable. There are no free-form ignore patterns; inspect reasons with `make analyzer-policy ANALYZER=smatch`. -Install Sparse and Smatch with matching `smatch_data`. Use `SMATCH_DATA_DIR` -if Smatch cannot find its installed data. The selected kernel must accept -the checker; recent kernels may require a newer frontend. +Install the selected checker; Smatch also needs matching `smatch_data`. +Smatch builds its own frontend and does not need standalone Sparse. +Use `SMATCH_DATA_DIR` if Smatch cannot find its installed data. The selected +kernel must accept the checker; recent kernels may require a newer frontend. Build the CI tool environment with: ```sh -docker build -f scripts/ci/analyzers.Dockerfile -t scst-analyzers:local . +DOCKER_BUILDKIT=1 docker build -f scripts/ci/analyzers.Dockerfile \ + --build-arg ANALYZER_REFRESH="$(date +%s%N)" \ + --target sparse -t scst-analyzers:local . ``` -Tool revisions are in [ci/analyzers.env](ci/analyzers.env); kernel headers -and checksums are in `ci/kernel.env` and `ci/kernel.SHA256SUMS`. The image +Select `sparse`, `smatch`, `cppcheck`, `coccicheck` or `analyzer-tests` as the +target. BuildKit builds only the selected stage and its dependencies. +Sparse and Smatch follow the current `master` branches of +[bvanassche/sparse](https://github.com/bvanassche/sparse) and +[error27/smatch](https://github.com/error27/smatch), without version pins. +CI changes `ANALYZER_REFRESH` on each run and rerun to refresh the selected +source layer without invalidating its package or kernel layers. The local +command above does the same for `sparse` or `smatch`; omit this build argument +for other targets. Analyzer versions follow upstream or distribution updates +by default; pin an analyzer only to address a demonstrated compatibility problem. +Source fetches make up to three attempts with bounded low-speed waits and +backoff; exhausted failures still fail image preparation. Kernel headers and +checksums are in `ci/kernel.env` and `ci/kernel.SHA256SUMS`. The Smatch stage includes the [Smatch frontend fix](sparse_smatch/patches/typeof-address-space.patch) needed for current kernel RCU headers and an [installation fix](sparse_smatch/patches/install-assets.patch) separating data and manual-page targets. Distribution tool packages follow Fedora updates; -the whole environment is not version-locked. Tool provenance is recorded under +the whole environment is not version-locked. Tool provenance, including the +requested reference and actual fetched commit, is recorded under `/usr/local/share/scst-ci/` inside the image. ## Coccinelle ```sh make coccicheck KDIR=/path/to/kernel/build +# Or supply just the rules, without a prepared kernel: +make coccicheck COCCI_RULES_PATH=/path/to/scripts/coccinelle ``` -Install `spatch` with Python support and kernel sources containing -`scripts/coccinelle/`. Rules declaring `report` mode run on the shared source +Install `spatch` with Python support, the C preprocessor `cpp` used by iterator +models, and kernel rules from `scripts/coccinelle/`. +`COCCI_RULES_PATH` takes precedence over the kernel path. Rules declaring +`report` mode run on the shared source scope, including userspace and KUnit files; other rules are listed as skipped. No build is needed. The wrapper extends installed parser hints with SCST contracts and current source definitions, without pinned macro hashes. @@ -360,11 +379,31 @@ The [workflow](../.github/workflows/analyzers.yml) runs on PRs targeting `master pushes to `master` and manual dispatch. Updating a PR cancels its older run. Separate jobs run `make sparse`, `make smatch`, `make checkpatch`, `make coccicheck` and `make cppcheck`, including KUnit sources. -`Analyzer tests` runs `make analyzer-tests` in the same container, alongside -the analyzer jobs. It checks script fixtures and native model probes without -building or executing SCST. A parallel `SCST code style` job runs `make scs_lint` -without a kernel build. CI prints active findings, coverage and visible advice; complete inventories -and native streams remain in `.cache/lint/`. The container jobs retain these +Each job prepares only its own analyzer and assets: + +| Job | Environment and downloaded inputs | +| --- | --- | +| Sparse | Build toolchain, prepared kernel RPM, current `bvanassche/sparse` master from GitHub. | +| Smatch | Build toolchain, prepared kernel RPM, current `error27/smatch` master and its data; no standalone Sparse. | +| Cppcheck | Build toolchain, prepared kernel RPM, distribution Cppcheck; no Sparse or Smatch. | +| Coccinelle | Distribution Coccinelle, the `cpp` preprocessor and rules extracted from the same pinned kernel RPM; no kernel build toolchain or other analyzers. | +| Checkpatch | Runner Python, Git and Perl; Checkpatch files from current Linux `master` on GitHub. | +| Analyzer tests | Common script fixtures, Git, Make and a C compiler; no native analyzers or kernel download. | +| SCST code style | Python, uv and the style driver's dependencies; no kernel or other analyzers. | + +Checkpatch acquisition runs outside Docker caching on every CI invocation. +`ci/fetch-checkpatch` resolves `torvalds/linux` `master` once, then downloads +`scripts/checkpatch.pl`, `scripts/spelling.txt`, `scripts/const_structs.checkpatch` +and `Documentation/dev-tools/checkpatch.rst` from that revision. No commit is +pinned in the repository; the resolved SHA and file hashes record the inputs +used by that run. Downloads retry transient failures, and an incomplete set +fails preparation. The fetch log and complete tool snapshot are artifacts. + +`Analyzer tests` runs the `common` group. Native Checkpatch, Cppcheck and +Coccinelle probes run before analysis in their respective jobs, using the same +tools and assets as that analysis. These fixtures do not build or execute SCST. +CI prints active findings, coverage and visible advice; complete inventories +and native streams remain in `.cache/lint/`. All analyzer jobs retain these reports for seven days. PR and manual runs fail on findings remaining after policy exceptions or @@ -383,12 +422,20 @@ Python standard library. Run its fixtures from the repository root: ```sh make lint-test # PYTHON defaults to python3 make analyzer-tests KDIR=/path/to/current/kernel/build +# Run one dependency group: +make analyzer-tests ANALYZER_TEST_GROUP=common +make analyzer-tests ANALYZER_TEST_GROUP=checkpatch CHECKPATCH_PATH=/path/to/scripts ``` The fixtures use temporary repositories, files and child processes. They do not build SCST, load modules or access live devices. -`analyzer-tests` additionally requires the CI analyzer tools and kernel scripts. +`analyzer-tests` defaults to `ANALYZER_TEST_GROUP=all`, preserving the complete +suite selection. The `common`, `checkpatch`, `cppcheck` and `coccicheck` groups +partition that selection; each requires only its own tools and assets. +Native groups require Checkpatch and its data, Cppcheck and a C compiler, or +Coccinelle with `cpp` and kernel rules, respectively. `CHECKPATCH_PATH` and +`COCCI_RULES_PATH` may supply assets independently of `KDIR`. Real Checkpatch, Cppcheck and Coccinelle check small C inputs: valid examples must pass, and deliberate bugs must retain their expected diagnostics through the production models. Each suite runs in a separate process; missing tools, diff --git a/scripts/analyzer_run.py b/scripts/analyzer_run.py index 8f4d217..c60c52b 100644 --- a/scripts/analyzer_run.py +++ b/scripts/analyzer_run.py @@ -17,6 +17,7 @@ from analyzer_policy import inline_inventory, integration, load_policy, source_p from analyzer_report import LABELS, markdown_block, render from lint_common import Interrupted, entrypoint, print_phase, report_lock, report_section, run from style.checkpatch import checker_path +from coccinelle.coccicheck import rules_path ROOT = Path(__file__).resolve().parents[1] DRIVERS = {"sparse": "sparse_smatch/smp.py", "smatch": "sparse_smatch/smp.py", @@ -49,21 +50,25 @@ def metadata(tool, environment): binary = checker_path() if tool == "checkpatch" else Path(shutil.which(name) or name) version = probe([str(binary), "--version"]) provenance = Path("/usr/local/share/scst-ci") / (tool + "-source.txt") + if tool == "checkpatch" and binary.with_name("checkpatch-source.txt").is_file(): + provenance = binary.with_name("checkpatch-source.txt") kernel = Path(environment.get("SCST_LINT_KDIR") or environment.get("KDIR") or f"/lib/modules/{environment.get('KVER') or os.uname().release}/build") + kbuild = tool in {"sparse", "smatch", "cppcheck"} + support_tools = (("make", "gcc", "ld", "pahole", "python3") if kbuild else + ("cpp", "python3") if tool == "coccicheck" else ()) result = { "commit": probe(["git", "-C", str(ROOT), "rev-parse", "HEAD"]), "branch": probe(["git", "-C", str(ROOT), "branch", "--show-current"]), "worktree": probe(["git", "-C", str(ROOT), "status", "--porcelain"]), - "kernel": str(kernel.resolve()) if tool != "scs_lint" else None, - "kernel_config_sha256": digest(kernel / ".config") if tool != "scs_lint" else None, + "kernel": str(kernel.resolve()) if kbuild else None, + "kernel_config_sha256": digest(kernel / ".config") if kbuild else None, "tool": str(binary), "tool_sha256": digest(binary), "version": version, "source_provenance": provenance.read_text() if provenance.exists() else "unavailable", "configuration": build_configuration(environment) if tool in {"sparse", "smatch", "cppcheck"} else {}, "environment_tools": {name: probe([name, "--version"]) - for name in ("make", "gcc", "ld", "pahole", "python3") - if tool in {"sparse", "smatch", "cppcheck", "coccicheck"}}, + for name in support_tools}, } if not provenance.exists() and binary.is_file() and shutil.which("rpm"): package = probe(["rpm", "-qf", str(binary.resolve())]) @@ -72,6 +77,12 @@ def metadata(tool, environment): if tool == "checkpatch": result["data_sha256"] = {name: digest(binary.with_name(name)) for name in ("spelling.txt", "const_structs.checkpatch")} + result["data_sha256"]["Documentation/dev-tools/checkpatch.rst"] = digest( + binary.parent.parent / "Documentation/dev-tools/checkpatch.rst") + if tool == "coccicheck": + result["rules"] = str(rules_path(environment)) + source = Path("/usr/local/share/scst-ci/coccinelle-rules-source.txt") + result["rules_source_provenance"] = source.read_text() if source.is_file() else "unavailable" if tool == "scs_lint": driver = ROOT / "scripts/scs_lint/scs_lint.py" result.update(driver=str(driver), driver_sha256=digest(driver), @@ -156,6 +167,9 @@ def print_metadata(tool, data, policy): print(f" Commit: {value(data['commit'])}\n Branch: {branch}; worktree: {worktree}") if data['kernel']: print(f" Kernel build tree: {data['kernel']}") + if data.get("rules"): + print(f" Coccinelle rules: {data['rules']}") + print(f" Rules source: {data['rules_source_provenance'].strip()}") print(f"\nTool: {data.get('driver', data['tool'])}") version = value(data["version"]) if tool == "checkpatch": diff --git a/scripts/analyzer_tests.py b/scripts/analyzer_tests.py index 257d3bb..b17e609 100644 --- a/scripts/analyzer_tests.py +++ b/scripts/analyzer_tests.py @@ -17,9 +17,12 @@ import unittest sys.dont_write_bytecode = True from compile_commands import write_json from lint_common import entrypoint, run +from coccinelle.coccicheck import rules_path ROOT = Path(__file__).resolve().parents[1] -SUITE_DIRS = {"tests", "style", "sparse_smatch", "cppcheck", "coccinelle"} +GROUP_DIRS = {"common": {"tests", "sparse_smatch"}, "checkpatch": {"style"}, + "cppcheck": {"cppcheck"}, "coccicheck": {"coccinelle"}} +SUITE_DIRS = set().union(*GROUP_DIRS.values()) # Temporary, explicit exceptions for the upstream Coccinelle variadic bug. # Match both the test identity and reason; unrelated skips still fail CI. KNOWN_SKIPS = { @@ -34,11 +37,12 @@ KNOWN_SKIPS = { } -def suites(root): +def suites(root, group="all"): + directories = SUITE_DIRS if group == "all" else GROUP_DIRS[group] names = subprocess.check_output( ["git", "-C", str(root), "ls-files", "-z", "scripts"], text=True).split("\0") return sorted(name for name in names if len(Path(name).parts) == 3 - and Path(name).parts[1] in SUITE_DIRS and Path(name).match("test_*.py")) + and Path(name).parts[1] in directories and Path(name).match("test_*.py")) def passed(row, status, suite=None): @@ -96,48 +100,61 @@ def run_suite(path, output): return int(row["state"] != "passed") -def environment(): +def environment(group="all"): # Test fixtures own their build/report overrides and temporary repositories. kernel = Path(os.environ.get("SCST_LINT_KDIR") or os.environ.get("KDIR") or f"/lib/modules/{os.environ.get('KVER') or os.uname().release}/build").resolve() env = {key: value for key, value in os.environ.items() if not key.startswith(("CI_", "GITHUB_", "LINT_", "SCST_LINT_", "GIT_")) and key not in {"MAKEFLAGS", "MFLAGS", "MAKELEVEL", "MAKEOVERRIDES", "GNUMAKEFLAGS", - "CPPCHECK_PROJECT", "CPPCHECK_USERSPACE_PROJECT", "CHECKPATCH_PATH"}} - env.update(PYTHONDONTWRITEBYTECODE="1", KDIR=str(kernel), SCST_LINT_KDIR=str(kernel), - CHECKPATCH_PATH=str(kernel / "scripts")) + "CPPCHECK_PROJECT", "CPPCHECK_USERSPACE_PROJECT", "CHECKPATCH_PATH", + "COCCI_RULES_PATH", "KDIR", "KVER", "KUNIT_TEST", "KUNIT_LABEL"}} + env["PYTHONDONTWRITEBYTECODE"] = "1" + if group in {"all", "checkpatch"}: + env["CHECKPATCH_PATH"] = str(Path(os.environ.get("CHECKPATCH_PATH") or + kernel / "scripts").resolve()) + if group in {"all", "coccicheck"}: + env["COCCI_RULES_PATH"] = str(rules_path()) return env -def prerequisites(env): - missing = [tool for tool in ("git", "make", "cc", "cpp", "perl", "cppcheck", "spatch") - if not shutil.which(tool)] - kernel = Path(env["KDIR"]) - for name in ("scripts/checkpatch.pl", "scripts/spelling.txt", "scripts/const_structs.checkpatch", - "scripts/coccinelle/api/stream_open.cocci", - "scripts/coccinelle/misc/add_namespace.cocci"): - if not (kernel / name).is_file(): - missing.append(str(kernel / name)) +def prerequisites(env, group="all"): + tools = {"common": {"git", "make", "cc", "cpp"}, "checkpatch": {"git", "perl", "diff"}, + "cppcheck": {"cppcheck", "cc"}, "coccicheck": {"spatch", "cpp"}} + selected = set().union(*tools.values()) if group == "all" else tools[group] + missing = [tool for tool in sorted(selected) if not shutil.which(tool, path=env.get("PATH"))] + files = [] + if group in {"all", "checkpatch"}: + directory = Path(env["CHECKPATCH_PATH"]) + files += [directory / name for name in + ("checkpatch.pl", "spelling.txt", "const_structs.checkpatch")] + if group in {"all", "coccicheck"}: + directory = Path(env["COCCI_RULES_PATH"]) + files += [directory / name for name in ("api/stream_open.cocci", "misc/add_namespace.cocci")] + missing += [str(path) for path in files if not path.is_file()] if missing: raise ValueError("Missing analyzer-test prerequisites: " + ", ".join(missing)) -def execute(root): +def execute(root, group="all"): reports = root / ".cache/lint" reports.mkdir(parents=True, exist_ok=True) directory = Path(tempfile.mkdtemp(prefix="analyzer-tests-", dir=reports)) manifest = directory / "tests.json" - report = dict(state="started", suites=[], failures=[]) + report = dict(state="started", group=group, suites=[], failures=[]) write_json(manifest, report) started = time.monotonic() - print(f"Analyzer tests: Python {sys.version.split()[0]}; reports: {directory}", flush=True) + print(f"Analyzer tests ({group}): Python {sys.version.split()[0]}; reports: {directory}", flush=True) try: - selected = suites(root) + selected = suites(root, group) if not selected: raise ValueError("No tracked analyzer test suites found") - env = environment() - prerequisites(env) - print(f"Kernel tools: {env['KDIR']}; {len(selected)} test suites", flush=True) + env = environment(group) + prerequisites(env, group) + print(f"Selected group: {group}; {len(selected)} test suites", flush=True) + for name in ("CHECKPATCH_PATH", "COCCI_RULES_PATH"): + if name in env: + print(f" {name}={env[name]}", flush=True) for name in selected: stem = name.replace("/", "_").removesuffix(".py") log, result_file = directory / (stem + ".log"), directory / (stem + ".json") @@ -180,7 +197,7 @@ def execute(root): report["state"] = "incomplete" report["seconds"] = round(time.monotonic() - started, 1) write_json(manifest, report) - summary = (f"Analyzer tests: {report['state'].upper()}; " + summary = (f"Analyzer tests ({group}): {report['state'].upper()}; " f"{sum(row.get('tests', 0) for row in report['suites'])} tests; " f"{sum(row.get('skipped', 0) for row in report['suites'])} skipped; " f"{report['seconds']}s\nReports: {directory}\n") @@ -195,12 +212,14 @@ def execute(root): def main(): parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--group", choices=("all", *GROUP_DIRS), default="all", + help="run common fixtures or one analyzer's native probes (default: all)") parser.add_argument("--suite", type=Path, help=argparse.SUPPRESS) parser.add_argument("--result", type=Path, help=argparse.SUPPRESS) args = parser.parse_args() if bool(args.suite) != bool(args.result): parser.error("--suite and --result must be supplied together") - return run_suite(args.suite, args.result) if args.suite else execute(ROOT) + return run_suite(args.suite, args.result) if args.suite else execute(ROOT, args.group) if __name__ == "__main__": diff --git a/scripts/ci/analyzers.Dockerfile b/scripts/ci/analyzers.Dockerfile index 9b75078..90ac34d 100644 --- a/scripts/ci/analyzers.Dockerfile +++ b/scripts/ci/analyzers.Dockerfile @@ -1,14 +1,48 @@ # SPDX-License-Identifier: GPL-2.0-only -FROM fedora:44@sha256:43b29f65a41eb9c35e1cd5323e3bdf3b655c2357a9f4f1ff2f9c2798e5045d80 +FROM fedora:44@sha256:43b29f65a41eb9c35e1cd5323e3bdf3b655c2357a9f4f1ff2f9c2798e5045d80 AS base RUN dnf install -y --setopt=install_weak_deps=False \ - gcc make git python3 perl elfutils-libelf-devel openssl openssl-devel \ - sqlite-devel flex bison pkgconf-pkg-config diffutils findutils \ - curl-minimal xz tar gzip dwarves coccinelle cppcheck && dnf clean all + make git python3 diffutils findutils && dnf clean all +WORKDIR /scst +ENV PYTHONDONTWRITEBYTECODE=1 + +COPY scripts/ci/install-analyzers /opt/scst-ci/ +# Extract the pinned package once; consumers copy only the assets they use. +FROM base AS kernel-files +RUN dnf install -y --setopt=install_weak_deps=False curl-minimal rpm cpio && dnf clean all COPY scripts/ci/kernel.env scripts/ci/kernel.SHA256SUMS /opt/scst-ci/ -COPY scripts/ci/analyzers.env scripts/ci/install-analyzers /opt/scst-ci/ +RUN bash /opt/scst-ci/install-analyzers kernel + +FROM base AS kernel-build +COPY --from=kernel-files /opt/kernel-devel.rpm /tmp/kernel-devel.rpm +RUN dnf install -y --setopt=install_weak_deps=False \ + gcc perl elfutils-libelf-devel openssl openssl-devel flex bison \ + pkgconf-pkg-config dwarves /tmp/kernel-devel.rpm && \ + ln -s /usr/src/kernels/* /opt/kernel && \ + rm /tmp/kernel-devel.rpm && dnf clean all +ENV KDIR=/opt/kernel + +FROM kernel-build AS sparse +# A fresh build argument invalidates only this stage's source/build layer. +ARG ANALYZER_REFRESH +RUN bash /opt/scst-ci/install-analyzers sparse + +FROM kernel-build AS smatch +RUN dnf install -y --setopt=install_weak_deps=False sqlite-devel && dnf clean all COPY scripts/sparse_smatch/patches/typeof-address-space.patch \ scripts/sparse_smatch/patches/install-assets.patch /opt/scst-ci/ -RUN bash /opt/scst-ci/install-analyzers -WORKDIR /scst -ENV PYTHONDONTWRITEBYTECODE=1 +# Refresh Smatch sources without invalidating its package or kernel layers. +ARG ANALYZER_REFRESH +RUN bash /opt/scst-ci/install-analyzers smatch + +FROM kernel-build AS cppcheck +RUN dnf install -y --setopt=install_weak_deps=False cppcheck && dnf clean all + +FROM base AS coccicheck +RUN dnf install -y --setopt=install_weak_deps=False coccinelle cpp && dnf clean all +COPY --from=kernel-files /opt/kernel/scripts/coccinelle /opt/coccinelle +COPY --from=kernel-files /usr/local/share/scst-ci/coccinelle-rules-source.txt /usr/local/share/scst-ci/ +ENV COCCI_RULES_PATH=/opt/coccinelle + +FROM base AS analyzer-tests +RUN dnf install -y --setopt=install_weak_deps=False gcc && dnf clean all diff --git a/scripts/ci/analyzers.env b/scripts/ci/analyzers.env deleted file mode 100644 index 0f24838..0000000 --- a/scripts/ci/analyzers.env +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Update the revisions, frontend patch and recorded provenance together. -SPARSE_REVISION=37156835e3d725b6d750f000be33ba3814bb2310 -SMATCH_REVISION=5189e3fb018b783a26dcb45c02c114c1d1aad290 diff --git a/scripts/ci/fetch-checkpatch b/scripts/ci/fetch-checkpatch new file mode 100644 index 0000000..b1b95e0 --- /dev/null +++ b/scripts/ci/fetch-checkpatch @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0-only +# Fetch a consistent snapshot of the current Linux master, without a stored pin. +set -euo pipefail + +if (( $# != 1 )) || [[ -e $1 || -L $1 ]]; then + printf 'Usage: %s NEW_DESTINATION\n' "$0" >&2 + exit 2 +fi +destination=$1 +repository=https://github.com/torvalds/linux.git +ref=refs/heads/master +staging=$(mktemp -d "${destination}.XXXXXX") +trap 'rm -rf "$staging"' EXIT + +for attempt in 1 2 3; do + if remote_head=$(timeout 60 git -c http.lowSpeedLimit=1024 -c http.lowSpeedTime=30 \ + ls-remote --exit-code "$repository" "$ref"); then + break + else + status=$? + fi + printf 'Resolving Linux master failed (attempt %d/3, exit %d)\n' "$attempt" "$status" >&2 + if (( attempt == 3 )); then + exit "$status" + fi + sleep "$((attempt * 10))" +done +read -r revision resolved_ref <<< "$remote_head" +if [[ ! $revision =~ ^[0-9a-f]{40}$ || $resolved_ref != "$ref" || $remote_head == *$'\n'* ]]; then + printf 'Invalid Linux master reference: %s\n' "$remote_head" >&2 + exit 1 +fi +printf 'Fetching Checkpatch from %s %s (%s)\n' "$repository" "$ref" "$revision" + +files=(scripts/checkpatch.pl scripts/spelling.txt scripts/const_structs.checkpatch + Documentation/dev-tools/checkpatch.rst) +for file in "${files[@]}"; do + mkdir -p "$staging/$(dirname "$file")" + curl --fail --location --retry 3 --retry-all-errors \ + --connect-timeout 15 --max-time 120 \ + "https://raw.githubusercontent.com/torvalds/linux/$revision/$file" \ + --output "$staging/$file" + test -s "$staging/$file" +done +chmod 755 "$staging/scripts/checkpatch.pl" +( + printf 'Repository: %s\nRef: %s\nCommit: %s\n' "$repository" "$ref" "$revision" + cd "$staging" + sha256sum "${files[@]}" +) > "$staging/scripts/checkpatch-source.txt" +mv -T "$staging" "$destination" diff --git a/scripts/ci/install-analyzers b/scripts/ci/install-analyzers index d39d9ef..d3d9ca2 100644 --- a/scripts/ci/install-analyzers +++ b/scripts/ci/install-analyzers @@ -1,60 +1,105 @@ #!/usr/bin/env bash # SPDX-License-Identifier: GPL-2.0-only -# Run only while building the dedicated analyzer container. +# Run only while building the selected analyzer container stage. set -euo pipefail HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -# shellcheck source=analyzers.env -source "$HERE/analyzers.env" -# shellcheck source=kernel.env -source "$HERE/kernel.env" -install -d /usr/local/share/scst-ci -package="kernel-devel-$KERNEL_BUILD.x86_64.rpm" -( - cd /tmp - curl --fail --location --retry 3 \ - "https://kojipkgs.fedoraproject.org/packages/kernel/${KERNEL_BUILD%-*}/${KERNEL_BUILD#*-}/x86_64/$package" \ - --output "$package" - awk -v package="$package" '$2 == package {print; found=1} END {if (!found) exit 1}' \ - "$HERE/kernel.SHA256SUMS" | sha256sum --check - dnf install -y --setopt=install_weak_deps=False "./$package" - test -s "/usr/src/kernels/$KERNEL_BUILD.x86_64/Module.symvers" - rm "$package" -) -dnf clean all +extract_kernel() +{ + # shellcheck source=kernel.env + source "$HERE/kernel.env" + local package="kernel-devel-$KERNEL_BUILD.x86_64.rpm" + local repository="https://kojipkgs.fedoraproject.org/packages/kernel" + local url="$repository/${KERNEL_BUILD%-*}/${KERNEL_BUILD#*-}/x86_64/$package" + + ( + cd /tmp + curl --fail --location --retry 3 --retry-all-errors \ + --connect-timeout 15 --max-time 300 "$url" --output "$package" + awk -v package="$package" '$2 == package {print; found=1} END {if (!found) exit 1}' \ + "$HERE/kernel.SHA256SUMS" | sha256sum --check + mkdir kernel-package + cd kernel-package + rpm2cpio "../$package" | cpio --extract --make-directories --quiet + mv "usr/src/kernels/$KERNEL_BUILD.x86_64" /opt/kernel + test -s /opt/kernel/Module.symvers + test -d /opt/kernel/scripts/coccinelle + printf 'Package: %s\nURL: %s\n' "$package" "$url" \ + > /usr/local/share/scst-ci/coccinelle-rules-source.txt + sha256sum "../$package" >> /usr/local/share/scst-ci/coccinelle-rules-source.txt + cd /tmp + # Build stages install the RPM with its declared dependencies. The + # Coccinelle stage needs only the extracted rules, not those packages. + mv "$package" /opt/kernel-devel.rpm + rm -rf kernel-package + ) +} fetch_source() { - local name=$1 repository=$2 revision=$3 + local name=$1 repository=$2 reference=$3 + local attempt status delay revision + git init "/opt/$name" git -C "/opt/$name" remote add origin "$repository" - git -C "/opt/$name" fetch --depth 1 origin "$revision" + for attempt in 1 2 3; do + printf 'Fetching %s reference %s (attempt %d/3)\n' "$name" "$reference" "$attempt" >&2 + if git -C "/opt/$name" -c http.lowSpeedLimit=1024 -c http.lowSpeedTime=30 \ + fetch --depth 1 origin "$reference"; then + break + else + status=$? + fi + printf 'Fetch of %s failed (attempt %d/3, exit %d)\n' \ + "$name" "$attempt" "$status" >&2 + if (( attempt == 3 )); then + return "$status" + fi + delay=$((attempt * 10)) + printf 'Retrying %s fetch in %d seconds\n' "$name" "$delay" >&2 + sleep "$delay" + done git -C "/opt/$name" checkout --detach FETCH_HEAD - test "$(git -C "/opt/$name" rev-parse HEAD)" = "$revision" - printf 'Repository: %s\nCommit: %s\n' "$repository" "$revision" \ + revision=$(git -C "/opt/$name" rev-parse HEAD) + # Branches follow their fetched tip; pinned commits must still match exactly. + if [[ "$reference" != refs/heads/* ]]; then + test "$revision" = "$reference" + fi + printf 'Repository: %s\nReference: %s\nCommit: %s\n' "$repository" "$reference" "$revision" \ > "/usr/local/share/scst-ci/$name-source.txt" } -fetch_source sparse https://git.kernel.org/pub/scm/devel/sparse/sparse.git "$SPARSE_REVISION" -CFLAGS='-O2 -g -std=gnu99' make -C /opt/sparse -j"$(nproc)" sparse -install /opt/sparse/sparse /usr/local/bin/sparse - -fetch_source smatch https://github.com/error27/smatch.git "$SMATCH_REVISION" -for patch in "$HERE/typeof-address-space.patch" "$HERE/install-assets.patch"; do - git -C /opt/smatch apply --check "$patch" - git -C /opt/smatch apply "$patch" - sha256sum "$patch" >> /usr/local/share/scst-ci/smatch-source.txt -done -CFLAGS='-O2 -g -std=gnu99' make -C /opt/smatch -j"$(nproc)" PREFIX=/usr/local smatch -# Do not replace standalone Sparse with Smatch's bundled frontend. -make -C /opt/smatch PREFIX=/usr/local INST_PROGRAMS=smatch install-bin install-assets -test -s /usr/local/share/smatch/smatch_data/kernel.unreachable.turn_off -for tool in sparse smatch; do - "$tool" --version >> "/usr/local/share/scst-ci/$tool-source.txt" - sha256sum "$(command -v "$tool")" >> "/usr/local/share/scst-ci/$tool-source.txt" -done -# Record all installed Smatch model contents, without adding project models. -(cd /usr/local/share/smatch/smatch_data && - find . -type f -print0 | sort -z | xargs -0 sha256sum) \ - > /usr/local/share/scst-ci/smatch-data.sha256 -rm -rf /opt/sparse /opt/smatch +install -d /usr/local/share/scst-ci +case "${1:-}" in + kernel) + extract_kernel + exit 0 + ;; + sparse) + fetch_source sparse https://github.com/bvanassche/sparse.git refs/heads/master + CFLAGS='-O2 -g -std=gnu99' make -C /opt/sparse -j"$(nproc)" sparse + install /opt/sparse/sparse /usr/local/bin/sparse + ;; + smatch) + fetch_source smatch https://github.com/error27/smatch.git refs/heads/master + for patch in "$HERE/typeof-address-space.patch" "$HERE/install-assets.patch"; do + git -C /opt/smatch apply --check "$patch" + git -C /opt/smatch apply "$patch" + sha256sum "$patch" >> /usr/local/share/scst-ci/smatch-source.txt + done + CFLAGS='-O2 -g -std=gnu99' make -C /opt/smatch -j"$(nproc)" PREFIX=/usr/local smatch + # Smatch builds its own frontend; do not install its standalone Sparse. + make -C /opt/smatch PREFIX=/usr/local INST_PROGRAMS=smatch install-bin install-assets + test -s /usr/local/share/smatch/smatch_data/kernel.unreachable.turn_off + (cd /usr/local/share/smatch/smatch_data && + find . -type f -print0 | sort -z | xargs -0 sha256sum) \ + > /usr/local/share/scst-ci/smatch-data.sha256 + ;; + *) + printf 'Usage: %s {kernel|sparse|smatch}\n' "$0" >&2 + exit 2 + ;; +esac +"$1" --version >> "/usr/local/share/scst-ci/$1-source.txt" +sha256sum "$(command -v "$1")" >> "/usr/local/share/scst-ci/$1-source.txt" +rm -rf "/opt/$1" diff --git a/scripts/ci/run-analyzer.py b/scripts/ci/run-analyzer.py index 2d78c3e..fc25e13 100644 --- a/scripts/ci/run-analyzer.py +++ b/scripts/ci/run-analyzer.py @@ -18,6 +18,7 @@ from analyzer_policy import source_policy # noqa: E402 from analyzer_report import markdown_block # noqa: E402 from lint_common import entrypoint, report_lock, run # noqa: E402 from style.checkpatch import checker_path # noqa: E402 +from coccinelle.coccicheck import rules_path # noqa: E402 TOOLS = {"sparse": "sparse", "smatch": "smatch", "coccicheck": "spatch", "cppcheck": "cppcheck", "checkpatch": "checkpatch.pl"} @@ -97,10 +98,12 @@ def main(): def analyze(tool, lock_fd): - kernel = Path(os.environ.get("SCST_LINT_KDIR") or os.environ.get("KDIR", "")) - config_path = kernel / ".config" - config = config_path.read_text() if config_path.is_file() else "" - if tool != "checkpatch": + kernel = None + config = "" + if tool in {"sparse", "smatch", "cppcheck"}: + kernel = Path(os.environ.get("SCST_LINT_KDIR") or os.environ.get("KDIR", "")).resolve() + config_path = kernel / ".config" + config = config_path.read_text() if config_path.is_file() else "" if not (kernel / "Module.symvers").is_file(): raise ValueError("Set KDIR to a prepared kernel build tree with Module.symvers") if not any(line in {"CONFIG_KUNIT=y", "CONFIG_KUNIT=m"} for line in config.splitlines()): @@ -114,16 +117,31 @@ def analyze(tool, lock_fd): # Keep the existing preparation gate; the common Make frontend owns # metadata and the human-readable report for both local and CI runs. subprocess.check_output([executable, "--version"], text=True) - (directory / "kernel.config").write_text(config) + if kernel is not None: + (directory / "kernel.config").write_text(config) models = provenance.with_name("smatch-data.sha256") if tool == "smatch" and models.exists(): shutil.copyfile(models, directory / "smatch-data.sha256") identity = str(uuid.uuid4()) - env = dict(os.environ, KDIR=str(kernel.resolve()), SCST_LINT_KDIR=str(kernel.resolve()), - KUNIT_TEST="y", KUNIT_LABEL="ALL", LINT_DEFER_REPORTS="1", + env = dict(os.environ, LINT_DEFER_REPORTS="1", CPPCHECK_PROJECT="", CPPCHECK_USERSPACE_PROJECT="", SCST_LINT_RUN_ID=identity, SCST_LINT_CI_WRAPPER="1", LINT_REPORT_LOCK_TOOL=tool, LINT_REPORT_LOCK_FD=str(lock_fd)) + command = ["make", "-j2", tool] + if kernel is not None: + env.update(KDIR=str(kernel), SCST_LINT_KDIR=str(kernel), KUNIT_TEST="y", KUNIT_LABEL="ALL") + command += [f"KDIR={kernel}", "KUNIT_TEST=y", "KUNIT_LABEL=ALL", "WERROR=n"] + else: + # Resolve source assets before removing irrelevant build overrides. + if tool == "checkpatch": + env["CHECKPATCH_PATH"] = str(Path(executable).parent) + else: + rules = rules_path() + if not any(rules.rglob("*.cocci")): + raise ValueError(f"no kernel Coccinelle rules in {rules}") + env["COCCI_RULES_PATH"] = str(rules) + for name in ("KDIR", "SCST_LINT_KDIR", "KVER", "KUNIT_TEST", "KUNIT_LABEL"): + env.pop(name, None) report = {} frontend = {} try: @@ -131,8 +149,7 @@ def analyze(tool, lock_fd): # report distinguishes them; neither a failed make nor a report alone # is sufficient to classify the run as completed source findings. # The frontend in turn gives the driver time to stop native children. - result = run(["make", "-j2", tool, f"KDIR={kernel.resolve()}", - "KUNIT_TEST=y", "KUNIT_LABEL=ALL", "WERROR=n"], cwd=ROOT, env=env, + result = run(command, cwd=ROOT, env=env, pass_fds=(lock_fd,), cancel_timeout=20) finally: path = directory / f"{tool}.json" diff --git a/scripts/coccinelle/coccicheck.py b/scripts/coccinelle/coccicheck.py index 8447ff9..e247abe 100644 --- a/scripts/coccinelle/coccicheck.py +++ b/scripts/coccinelle/coccicheck.py @@ -41,6 +41,15 @@ COMPLETE = "SCST_COCCI_COMPLETE" FINDING = "SCST_COCCI_FINDING" +def rules_path(environment=None): + env = os.environ if environment is None else environment + if env.get("COCCI_RULES_PATH"): + return Path(env["COCCI_RULES_PATH"]).resolve() + kernel = Path(env.get("SCST_LINT_KDIR") or env.get("KDIR") or + f"/lib/modules/{env.get('KVER') or os.uname().release}/build") + return (kernel / "scripts/coccinelle").resolve() + + def metadata(text, name): match = re.search(r"^//[^\S\n]*" + name + r":[^\S\n]*(.*)$", text, re.MULTILINE) return match[1] if match else "" @@ -180,9 +189,7 @@ def main(): spatch = shutil.which("spatch") if not spatch: raise ValueError("spatch is not installed") - kernel = Path(os.environ.get("SCST_LINT_KDIR") or os.environ.get("KDIR") or - f"/lib/modules/{os.uname().release}/build") - directory = kernel / "scripts/coccinelle" + directory = rules_path() paths = sorted(directory.rglob("*.cocci")) if not paths: raise ValueError(f"no kernel Coccinelle rules in {directory}") diff --git a/scripts/coccinelle/test_rules.py b/scripts/coccinelle/test_rules.py index c52753e..e51a90a 100644 --- a/scripts/coccinelle/test_rules.py +++ b/scripts/coccinelle/test_rules.py @@ -1,6 +1,5 @@ """Exercise private kernel rule adaptations with native positive and negative matches.""" -import os from pathlib import Path import shutil import subprocess @@ -9,7 +8,7 @@ import tempfile import unittest sys.path.insert(0, str(Path(__file__).resolve().parents[1])) -from coccinelle.coccicheck import coverage, instrument_rule, rule_options +from coccinelle.coccicheck import coverage, instrument_rule, rule_options, rules_path from coccinelle.compat import adapt from coccinelle.model import prepare @@ -18,9 +17,7 @@ class NativeRuleTests(unittest.TestCase): def check(self, name, source, expected): spatch = shutil.which("spatch") self.assertTrue(spatch, "spatch is required") - kernel = Path(os.environ.get("SCST_LINT_KDIR") or os.environ.get("KDIR") or - f"/lib/modules/{os.uname().release}/build") - original = kernel / "scripts/coccinelle" / name + original = rules_path() / name before = original.read_bytes() text, _ = adapt(original, before.decode()) with tempfile.TemporaryDirectory(prefix="scst-cocci-rule-") as temporary: diff --git a/scripts/tests/test_analyzer_ci.py b/scripts/tests/test_analyzer_ci.py index 0e68059..526086e 100644 --- a/scripts/tests/test_analyzer_ci.py +++ b/scripts/tests/test_analyzer_ci.py @@ -29,7 +29,7 @@ class AnalyzerCiTests(unittest.TestCase): "sparse smatch coccicheck cppcheck checkpatch:\n" f"\t@FIXTURE_TOOL=$@ {shlex.quote(sys.executable)} -B scripts/analyzer_run.py $@\n" "\t@exit $(FIXTURE_MAKE_TAIL_EXIT)\n") - for name in ("git", "sparse", "smatch", "spatch", "cppcheck"): + for name in ("git", "sparse", "smatch", "spatch", "cppcheck", "cpp"): path = self.bin / name path.write_text(f"#!{sys.executable}\nprint('fixture-version')\n") path.chmod(0o755) @@ -43,6 +43,9 @@ class AnalyzerCiTests(unittest.TestCase): checker.chmod(0o755) for name in ("spelling.txt", "const_structs.checkpatch"): checker.with_name(name).touch() + rules = kernel / "scripts/coccinelle" + rules.mkdir() + (rules / "fixture.cocci").write_text("// fixture rule\n") self.env = dict(os.environ, KDIR=str(kernel), SCST_LINT_KDIR=str(kernel), PATH=str(self.bin), MAKEFLAGS="", MFLAGS="", MAKEOVERRIDES="", GNUMAKEFLAGS="", FIXTURE_STATUS="0", FIXTURE_MAKE_TAIL_EXIT="0", @@ -50,21 +53,26 @@ class AnalyzerCiTests(unittest.TestCase): FIXTURE_OUTCOME="clean", FIXTURE_COVERAGE="full") self.env.pop("GITHUB_STEP_SUMMARY", None) self.env.pop("CHECKPATCH_PATH", None) + self.env.pop("COCCI_RULES_PATH", None) driver = self.root / "scripts/sparse_smatch/smp.py" driver.write_text('''import json, os, sys from pathlib import Path root = Path(__file__).resolve().parents[2] sys.path.insert(0, str(root / 'scripts')) from lint_common import report_lock -assert os.environ['KUNIT_TEST'] == 'y' -assert os.environ['KUNIT_LABEL'] == 'ALL' +tool = os.environ['FIXTURE_TOOL'] +if tool in ('sparse', 'smatch', 'cppcheck'): + assert os.environ['KUNIT_TEST'] == 'y' + assert os.environ['KUNIT_LABEL'] == 'ALL' +else: + assert not any(name in os.environ for name in + ('KDIR', 'SCST_LINT_KDIR', 'KVER', 'KUNIT_TEST', 'KUNIT_LABEL')) assert os.environ['LINT_DEFER_REPORTS'] == '1' assert os.environ['CPPCHECK_PROJECT'] == '' assert os.environ['CPPCHECK_USERSPACE_PROJECT'] == '' status = int(os.environ['FIXTURE_STATUS']) directory = root / '.cache/lint' directory.mkdir(parents=True, exist_ok=True) -tool = os.environ['FIXTURE_TOOL'] with report_lock(root, tool) as lock_fd: assert lock_fd == int(os.environ['LINT_REPORT_LOCK_FD']) if os.environ.get('FIXTURE_NO_REPORT'): @@ -193,16 +201,50 @@ sys.exit(status) result = self.run_ci("checkpatch") self.assertEqual(result.returncode, 2, result.stdout + result.stderr) - def test_checkpatch_needs_tool_data_but_not_a_prepared_kunit_kernel(self): - (self.root / "kernel/.config").unlink() - (self.root / "kernel/Module.symvers").unlink() + def test_checkpatch_needs_only_its_own_tool_and_data(self): + assets = self.root / "checkpatch" + (self.root / "kernel/scripts").rename(assets) + shutil.rmtree(self.root / "kernel") + self.env["CHECKPATCH_PATH"] = str(assets) + for name in ("sparse", "smatch", "cppcheck", "spatch"): + (self.bin / name).unlink() result = self.run_ci("checkpatch") self.assertEqual(result.returncode, 0, result.stdout + result.stderr) - (self.root / "kernel/scripts/spelling.txt").unlink() + self.assertFalse((self.root / ".cache/lint/kernel.config").exists()) + (assets / "spelling.txt").unlink() result = self.run_ci("checkpatch") self.assertEqual(result.returncode, 2, result.stdout + result.stderr) self.assertIn("missing Checkpatch tool/data", result.stderr) + def test_coccicheck_needs_no_prepared_kernel_or_other_analyzers(self): + rules = self.root / "rules" + (self.root / "kernel/scripts/coccinelle").rename(rules) + shutil.rmtree(self.root / "kernel") + self.env["COCCI_RULES_PATH"] = str(rules) + for name in ("sparse", "smatch", "cppcheck"): + (self.bin / name).unlink() + result = self.run_ci("coccicheck") + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertFalse((self.root / ".cache/lint/kernel.config").exists()) + (rules / "fixture.cocci").unlink() + result = self.run_ci("coccicheck") + self.assertEqual(result.returncode, 2, result.stdout + result.stderr) + self.assertIn("no kernel Coccinelle rules", result.stderr) + + def test_build_analyzers_need_only_the_selected_checker(self): + for tool in ("sparse", "smatch", "cppcheck"): + with self.subTest(tool=tool): + for name in ("sparse", "smatch", "cppcheck", "spatch"): + (self.bin / name).chmod(0o755 if name == tool else 0o644) + result = self.run_ci(tool) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + (self.root / "kernel/Module.symvers").unlink() + for tool in ("sparse", "smatch", "cppcheck"): + with self.subTest(tool=tool): + result = self.run_ci(tool) + self.assertEqual(result.returncode, 2, result.stdout + result.stderr) + self.assertIn("prepared kernel build tree", result.stderr) + def test_make_failure_without_a_new_report_cannot_reuse_previous_results(self): self.assertEqual(self.run_ci().returncode, 0) self.env["FIXTURE_NO_REPORT"] = "1" diff --git a/scripts/tests/test_analyzer_run.py b/scripts/tests/test_analyzer_run.py index e6b6e42..16fbba2 100644 --- a/scripts/tests/test_analyzer_run.py +++ b/scripts/tests/test_analyzer_run.py @@ -202,6 +202,39 @@ sys.exit(0) class MetadataTests(unittest.TestCase): + def test_source_analyzers_do_not_probe_build_dependencies(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + binary = root / "scripts/checkpatch.pl" + binary.parent.mkdir() + binary.write_text("fixture checker\n") + for name in ("spelling.txt", "const_structs.checkpatch", "checkpatch-source.txt"): + binary.with_name(name).write_text(name + "\n") + doc = root / "Documentation/dev-tools/checkpatch.rst" + doc.parent.mkdir(parents=True) + doc.write_text("fixture documentation\n") + for tool in ("checkpatch", "coccicheck"): + with self.subTest(tool=tool), \ + patch.object(analyzer_run, "checker_path", return_value=binary), \ + patch.object(analyzer_run.shutil, "which", return_value=None), \ + patch.object(analyzer_run, "probe", return_value=dict(status=0, output="")) as probe: + data = analyzer_run.metadata(tool, {"KDIR": "/absent/kernel", + "COCCI_RULES_PATH": str(root / "rules")}) + self.assertIsNone(data["kernel"]) + self.assertIsNone(data["kernel_config_sha256"]) + support = ["cpp", "python3"] if tool == "coccicheck" else [] + self.assertEqual(list(data["environment_tools"]), support) + self.assertFalse(data["configuration"]) + self.assertEqual([call.args[0][0] for call in probe.call_args_list], + [str(binary) if tool == "checkpatch" else "spatch", + "git", "git", "git", *support]) + if tool == "checkpatch": + self.assertEqual(data["source_provenance"], "checkpatch-source.txt\n") + self.assertEqual(data["data_sha256"]["Documentation/dev-tools/checkpatch.rst"], + analyzer_run.digest(doc)) + else: + self.assertEqual(data["rules"], str(root / "rules")) + def test_build_defaults_and_overrides_are_described(self): defaults = analyzer_run.build_configuration({}) self.assertIn('newer QLogic tree', defaults['QLA_32GBIT']) diff --git a/scripts/tests/test_analyzer_tests.py b/scripts/tests/test_analyzer_tests.py index c069631..f906c6a 100644 --- a/scripts/tests/test_analyzer_tests.py +++ b/scripts/tests/test_analyzer_tests.py @@ -133,12 +133,73 @@ class AnalyzerTestsTests(unittest.TestCase): self.assertEqual(driver.suites(Path("/repo")), [ "scripts/coccinelle/test_rules.py", "scripts/cppcheck/test_models.py", "scripts/style/test_native.py", "scripts/tests/test_a.py"]) + selected = [] + for group, expected in ( + ("common", ["scripts/tests/test_a.py"]), + ("checkpatch", ["scripts/style/test_native.py"]), + ("cppcheck", ["scripts/cppcheck/test_models.py"]), + ("coccicheck", ["scripts/coccinelle/test_rules.py"])): + with self.subTest(group=group): + actual = driver.suites(Path("/repo"), group) + self.assertEqual(actual, expected) + selected.extend(actual) + self.assertEqual(sorted(selected), driver.suites(Path("/repo"))) + + def test_empty_selected_group_is_incomplete(self): + with tempfile.TemporaryDirectory() as temporary, \ + patch.object(driver.subprocess, "check_output", return_value="scripts/tests/test_a.py\0"), \ + patch.dict(os.environ, GITHUB_STEP_SUMMARY=""), \ + contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()): + root = Path(temporary) + self.assertEqual(driver.execute(root, "checkpatch"), 1) + report = json.loads(next((root / ".cache/lint").glob( + "analyzer-tests-*/tests.json")).read_text()) + self.assertEqual(report["group"], "checkpatch") + self.assertEqual(report["state"], "incomplete") + self.assertIn("No tracked analyzer test suites found", report["failures"]) def test_missing_tools_fail_instead_of_skipping_native_tests(self): with tempfile.TemporaryDirectory() as temporary, \ patch.object(driver.shutil, "which", return_value=None): with self.assertRaisesRegex(ValueError, "Missing analyzer-test prerequisites:.*cppcheck"): - driver.prerequisites({"KDIR": temporary}) + driver.prerequisites({"CHECKPATCH_PATH": temporary, "COCCI_RULES_PATH": temporary}) + + def test_each_group_requires_only_its_tools_and_assets(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + for group, available, files in ( + ("common", {"git", "make", "cc", "cpp"}, ()), + ("checkpatch", {"git", "perl", "diff"}, + ("checkpatch.pl", "spelling.txt", "const_structs.checkpatch")), + ("cppcheck", {"cppcheck", "cc"}, ()), + ("coccicheck", {"spatch", "cpp"}, + ("api/stream_open.cocci", "misc/add_namespace.cocci"))): + with self.subTest(group=group): + assets = root / group + for name in files: + path = assets / name + path.parent.mkdir(parents=True, exist_ok=True) + path.touch() + env = dict(PATH="/selected/bin", CHECKPATCH_PATH=str(assets), + COCCI_RULES_PATH=str(assets)) + + def which(name, *, path): + self.assertEqual(path, env["PATH"]) + return "/selected/bin/" + name if name in available else None + + with patch.object(driver.shutil, "which", side_effect=which): + driver.prerequisites(env, group) + for absent in sorted(available): + with patch.object(driver.shutil, "which", side_effect=lambda name, **kw: + None if name == absent else "/selected/bin/" + name): + with self.assertRaisesRegex(ValueError, absent): + driver.prerequisites(env, group) + for name in files: + (assets / name).unlink() + with patch.object(driver.shutil, "which", side_effect=which), \ + self.assertRaisesRegex(ValueError, name): + driver.prerequisites(env, group) + (assets / name).touch() def test_environment_isolates_make_git_and_outer_reports(self): with patch.dict(os.environ, {"KDIR": "/selected/kernel", "GITHUB_ACTIONS": "true", @@ -146,12 +207,26 @@ class AnalyzerTestsTests(unittest.TestCase): "SCST_LINT_RUN_ID": "outer", "LINT_DEFER_REPORTS": "1", "CPPCHECK_PROJECT": "/stale/commands.json"}, clear=True): env = driver.environment() - self.assertEqual(env["SCST_LINT_KDIR"], "/selected/kernel") self.assertEqual(env["CHECKPATCH_PATH"], "/selected/kernel/scripts") + self.assertEqual(env["COCCI_RULES_PATH"], "/selected/kernel/scripts/coccinelle") for name in ("GITHUB_ACTIONS", "MAKEFLAGS", "GIT_DIR", "SCST_LINT_RUN_ID", - "LINT_DEFER_REPORTS", "CPPCHECK_PROJECT"): + "LINT_DEFER_REPORTS", "CPPCHECK_PROJECT", "KDIR", "SCST_LINT_KDIR"): self.assertNotIn(name, env) + def test_only_selected_source_assets_are_inherited(self): + with patch.dict(os.environ, {"KDIR": "/unused/kernel", "KUNIT_TEST": "y", + "KUNIT_LABEL": "ALL", "CHECKPATCH_PATH": "/selected/checkpatch", + "COCCI_RULES_PATH": "/selected/rules"}, clear=True): + for group in driver.GROUP_DIRS: + ... [truncated message content] |
|
From: SCST G. <lna...@ya...> - 2026-11-11 08:04:14
|
Commit: 7c40d1e GitHub URL: https://github.com/SCST-project/scst/commit/7c40d1e74ea51f148e7b3e8ce59a02676a3edd82 Author: Gleb Chesnokov Date: 2026-11-11T11:02:29+03:00 Log Message: ----------- scripts: Fix compatibility preparation for old kernels Old x86 purgatory Makefiles reset KBUILD_CFLAGS and drop the kernel's C dialect. GCC 15 and newer then reject old bool/false declarations under C23, breaking regression builds such as Linux 4.9.337. Preserve the inherited -std= flag when purgatory replaces its flags. Check compatibility patches before applying them and skip patches whose reverse dry-run succeeds. Fail on unexpected mismatches without leaving partially applied hunks or reject files. Handle independently backported PIE and DTC changes separately, and skip compatibility fixes for source files that are no longer present. Add fixtures for repeated preparation, patch conflicts and C dialect preservation. Validated with 42 Python tests and a Linux 4.9.337 regression build using GCC 16.2.1 without CC or HOSTCC overrides. Modified Paths: -------------- scripts/README.md | 4 + scripts/kernel/kernel-functions | 141 +++++++------ scripts/kernel/test_kernel_functions.py | 155 +++++++++++++++ 3 files changed, 238 insertions(+), 62 deletions(-) =================================================================== diff --git a/scripts/README.md b/scripts/README.md index 6d2fb81..6012f69 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -31,6 +31,10 @@ builds. Static analyzers have separate Make targets and CI jobs. The maintained kernel matrix is `ABT_KERNELS` in `nightly/conf/nightly.conf`; the CI subset is selected through `kernel/kernel-matrix` and `.github/kernel-matrix.conf`. +Run `python3 -m unittest discover -s scripts/kernel -p 'test_*.py'` to check +kernel preparation using temporary patch and Makefile fixtures, without +downloading or compiling a kernel. + `kernel/qla2xxx.py` tracks upstream QLogic commits, compares committed Linux and SCST driver trees, audits residual differences with an optional kernel profile, and exports mail patches with SCST paths. It uses diff --git a/scripts/kernel/kernel-functions b/scripts/kernel/kernel-functions index 9c1c9fb..bcc0c6f 100644 --- a/scripts/kernel/kernel-functions +++ b/scripts/kernel/kernel-functions @@ -166,10 +166,53 @@ function extract_kernel_tree { rmdir "${tmpdir}" } +# Apply a compatibility patch from stdin, or skip it if already applied. +# Check the whole patch first so a failed hunk cannot leave partial changes. +function apply_kernel_compat_patch { + local patchfile rc + + patchfile="$(mktemp)" || return $? + if ! cat >"${patchfile}"; then + rm -f "${patchfile}" + return 1 + fi + + if patch -p1 -f -s --dry-run <"${patchfile}" >/dev/null 2>&1; then + patch -p1 -f -s <"${patchfile}" + rc=$? + elif patch -p1 -f -s -R --dry-run <"${patchfile}" >/dev/null 2>&1; then + rc=0 + else + echo "Error: kernel compatibility patch neither applies nor is already applied." >&2 + patch -p1 -f --dry-run <"${patchfile}" >&2 + rc=1 + fi + rm -f "${patchfile}" + return "${rc}" +} + +function preserve_purgatory_c_standard { + local makefile=arch/x86/purgatory/Makefile + + [ -f "${makefile}" ] || return 0 + # Old purgatory Makefiles discard the parent's -std= along with tracing + # flags. GCC 15 defaults to C23, which rejects old kernel bool/false + # declarations. Keep the kernel's chosen dialect, not the other flags. + # Leave Makefiles that already select or inherit a dialect unchanged. + # shellcheck disable=SC2016 # These are Make variables, not shell variables. + sed -i '/^KBUILD_CFLAGS[[:blank:]]*:=/ { + /-std=/! { + /\$(KBUILD_CFLAGS)/! s/:=/:= $(filter -std=%,$(KBUILD_CFLAGS))/ + } + }' "${makefile}" +} + # Patch a kernel tree where $1 is the kernel version. function patch_kernel { check_kernel_version "$1" || return $? + preserve_purgatory_c_standard || return $? + case "$1" in *^*) # RHEL-compatible distro or UEK. @@ -180,8 +223,9 @@ function patch_kernel { # support for gcc 5") # v3.18. See also commit cb984d101b30 # ("compiler-gcc: integrate the various compiler-gcc[345].h # files") # v4.2. - if kernel_version_lt "$1" 4.2; then - patch -f -s -p1 <<'EOF' + # Stable kernels may already have the consolidated compiler-gcc.h. + if kernel_version_lt "$1" 4.2 && [ -f include/linux/compiler-gcc4.h ]; then + apply_kernel_compat_patch <<'EOF' || return $? diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 02ae99e8e6d3..47e12c19c965 100644 --- a/include/linux/compiler-gcc.h @@ -198,7 +242,7 @@ index 02ae99e8e6d3..47e12c19c965 100644 EOF # See also commit 733ed6e43756 ("compiler-gcc{3,4}.h: Use # GCC_VERSION macro") # v3.9. - patch -f -s -p1 <<'EOF' + apply_kernel_compat_patch <<'EOF' || return $? diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index 769e19864632..2ec6c7a11502 100644 --- a/include/linux/compiler-gcc4.h @@ -224,7 +268,7 @@ EOF if [ "${1#3.13}" != "$1" ]; then if [ "$1" = "3.13" ] || [ "${1#3.13.}" -lt 6 ]; then - patch -f -s -p1 <<'EOF' + apply_kernel_compat_patch <<'EOF' || return $? From 7b4ec8dd7d4ac467e9eee4d49f2c9574d773efbb Mon Sep 17 00:00:00 2001 From: Johannes Berg <joh...@in...> Date: Thu, 16 Jan 2014 10:18:48 +1030 @@ -265,7 +309,7 @@ EOF fi if [ "${1#4.15}" != "$1" ]; then - patch -f -s -p1 <<'EOF' + apply_kernel_compat_patch <<'EOF' || return $? From ad343a98e74e85aa91d844310e797f96fee6983b Mon Sep 17 00:00:00 2001 From: Sergey Senozhatsky <ser...@gm...> Date: Tue, 6 Feb 2018 15:37:52 -0800 @@ -307,7 +351,7 @@ index 5ba754d17952..9997a8805a82 100644 setenv("LESS", "FRSX", 0); } EOF - patch -f -s -p1 <<'EOF' + apply_kernel_compat_patch <<'EOF' || return $? From 854e55ad289ef8888e7991f0ada85d5846f5afb9 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf <jpo...@re...> Date: Thu, 15 Mar 2018 22:11:54 -0500 @@ -356,7 +400,7 @@ EOF fi if kernel_version_lt "$1" 4.8; then - patch -f -s -p1 <<'EOF' + apply_kernel_compat_patch <<'EOF' || return $? From c6a385539175ebc603da53aafb7753d39089f32e Mon Sep 17 00:00:00 2001 From: Borislav Petkov <bp...@su...> Date: Mon, 14 Nov 2016 19:41:31 +0100 @@ -408,8 +452,12 @@ index 0ed6ce300543..c324b43712f0 100644 -fno-strict-aliasing -fno-common \ -Werror-implicit-function-declaration \ -Wno-format-security \ -@@ -387,7 +388,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ - +EOF + # Stable backports may already contain only the assembler-flags hunk. + apply_kernel_compat_patch <<'EOF' || return $? +--- a/Makefile ++++ b/Makefile +@@ -388,6 +389,6 @@ KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := -KBUILD_AFLAGS := -D__ASSEMBLY__ @@ -422,7 +470,7 @@ EOF case "$1" in 4.18.0-*) # CentOS 8.x - patch -f -s -p1 <<'EOF' + apply_kernel_compat_patch <<'EOF' || return $? From a6e60d84989fa0e91db7f236eda40453b0e44afa Mon Sep 17 00:00:00 2001 From: Miguel Ojeda <mig...@gm...> Date: Sat, 19 Jan 2019 20:59:34 +0100 @@ -502,7 +550,7 @@ index 8fa38d3e7538..f5bc4c046461 100644 EOF ;; 3.*) - patch -f -s -p1 <<'EOF' + apply_kernel_compat_patch <<'EOF' || return $? --- linux-3.10.0-1127.el7/include/linux/init.h.orig 2020-05-09 20:55:48.638956513 -0700 +++ linux-3.10.0-1127.el7/include/linux/init.h 2020-05-09 20:56:46.947612445 -0700 @@ -309,13 +309,15 @@ @@ -528,7 +576,7 @@ EOF esac if kernel_version_lt "$1" 3.18; then - patch -f -s -p1 <<'EOF' + apply_kernel_compat_patch <<'EOF' || return $? From eeeda4cd06e828b331b15741a204ff9f5874d28d Mon Sep 17 00:00:00 2001 From: Ben Hutchings <be...@de...> Date: Wed, 24 Sep 2014 13:30:12 +0100 @@ -570,48 +618,14 @@ EOF # See also commit e33a814e772c ("scripts/dtc: Remove redundant YYLOC global # declaration") # v5.6~10^2. if kernel_version_lt "$1" 5.6; then - patch -p1 -f -s <<'EOF' -From e33a814e772cdc36436c8c188d8c42d019fda639 Mon Sep 17 00:00:00 2001 -From: Dirk Mueller <dmu...@su...> -Date: Tue, 14 Jan 2020 18:53:41 +0100 -Subject: [PATCH] scripts/dtc: Remove redundant YYLOC global declaration - -gcc 10 will default to -fno-common, which causes this error at link -time: - - (.text+0x0): multiple definition of `yylloc'; dtc-lexer.lex.o (symbol from plugin):(.text+0x0): first defined here - -This is because both dtc-lexer as well as dtc-parser define the same -global symbol yyloc. Before with -fcommon those were merged into one -defintion. The proper solution would be to mark this as "extern", -however that leads to: - - dtc-lexer.l:26:16: error: redundant redeclaration of 'yylloc' [-Werror=redundant-decls] - 26 | extern YYLTYPE yylloc; - | ^~~~~~ -In file included from dtc-lexer.l:24: -dtc-parser.tab.h:127:16: note: previous declaration of 'yylloc' was here - 127 | extern YYLTYPE yylloc; - | ^~~~~~ -cc1: all warnings being treated as errors - -which means the declaration is completely redundant and can just be -dropped. - -Signed-off-by: Dirk Mueller <dmu...@su...> -Signed-off-by: David Gibson <da...@gi...> -[robh: cherry-pick from upstream] -Cc: st...@vg... -Signed-off-by: Rob Herring <ro...@ke...> ---- - scripts/dtc/dtc-lexer.l | 1 - - 1 file changed, 1 deletion(-) - -diff --git a/scripts/dtc/dtc-lexer.l b/scripts/dtc/dtc-lexer.l -index 5c6c3fd557d7..b3b7270300de 100644 ---- a/scripts/dtc/dtc-lexer.l -+++ b/scripts/dtc/dtc-lexer.l -@@ -23,7 +23,6 @@ LINECOMMENT "//".*\n + local lexer + for lexer in scripts/dtc/dtc-lexer.l scripts/dtc/dtc-lexer.lex.c_shipped; do + [ -f "${lexer}" ] || continue + if grep -q '^extern bool treesource_error;' "${lexer}"; then + apply_kernel_compat_patch <<EOF || return $? +--- a/${lexer} ++++ b/${lexer} +@@ -23,7 +23,6 @@ #include "srcpos.h" #include "dtc-parser.tab.h" @@ -619,25 +633,28 @@ index 5c6c3fd557d7..b3b7270300de 100644 extern bool treesource_error; /* CAUTION: this will stop working if we ever use yyless() or yyunput() */ -diff --git a/scripts/dtc/dtc-lexer.lex.c_shipped b/scripts/dtc/dtc-lexer.lex.c_shipped -index 5c6c3fd557d7..b3b7270300de 100644 ---- a/scripts/dtc/dtc-lexer.lex.c_shipped -+++ b/scripts/dtc/dtc-lexer.lex.c_shipped -@@ -23,7 +23,6 @@ LINECOMMENT "//".*\n +EOF + else + apply_kernel_compat_patch <<EOF || return $? +--- a/${lexer} ++++ b/${lexer} +@@ -39,7 +39,6 @@ #include "srcpos.h" #include "dtc-parser.tab.h" -YYLTYPE yylloc; - extern bool treesource_error; /* CAUTION: this will stop working if we ever use yyless() or yyunput() */ + #define YY_USER_ACTION \\ EOF + fi + done fi # See also commit 52a9dab6d892 ("libsubcmd: Fix use-after-free for # realloc(..., 0)") # v5.17 - if kernel_version_lt "$1" 5.17; then - patch -p1 -f -s <<'EOF' + if kernel_version_lt "$1" 5.17 && [ -f tools/lib/subcmd/subcmd-util.h ]; then + apply_kernel_compat_patch <<'EOF' || return $? From 52a9dab6d892763b2a8334a568bd4e2c1a6fde66 Mon Sep 17 00:00:00 2001 From: Kees Cook <kee...@ch...> Date: Sun, 13 Feb 2022 10:24:43 -0800 diff --git a/scripts/kernel/test_kernel_functions.py b/scripts/kernel/test_kernel_functions.py new file mode 100644 index 0000000..213bafb --- /dev/null +++ b/scripts/kernel/test_kernel_functions.py @@ -0,0 +1,155 @@ +# SPDX-License-Identifier: GPL-2.0-only +"""Exercise kernel preparation with real patch/make and temporary fixtures.""" + +from pathlib import Path +import subprocess +import tempfile +import unittest + + +HELPERS = Path(__file__).resolve().with_name("kernel-functions") +PATCH = """--- a/example ++++ b/example +@@ -1,3 +1,3 @@ + before +-old ++new + after +""" +LEXER = """#include "srcpos.h" +#include "dtc-parser.tab.h" + +YYLTYPE yylloc; +extern bool treesource_error; + +/* CAUTION: this will stop working if we ever use yyless() or yyunput() */ +""" +SUBCMD = """static inline void *xrealloc(void *ptr, size_t size) +{ + void *ret = realloc(ptr, size); + if (!ret && !size) + ret = realloc(ptr, 1); + if (!ret) { + ret = realloc(ptr, size); + if (!ret && !size) + ret = realloc(ptr, 1); + if (!ret) + die("Out of memory, realloc failed"); + } + return ret; +} +""" +SUBCMD_FIXED = """static inline void *xrealloc(void *ptr, size_t size) +{ + void *ret = realloc(ptr, size); + if (!ret) + die("Out of memory, realloc failed"); + return ret; +} +""" + + +class KernelPreparationTests(unittest.TestCase): + def setUp(self): + temporary = tempfile.TemporaryDirectory(prefix="scst kernel preparation ") + self.addCleanup(temporary.cleanup) + self.root = Path(temporary.name) + + def write(self, name, contents): + path = self.root / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(contents) + return path + + def run_helper(self, command, patch=None): + return subprocess.run( + ["bash", "-c", 'source "$1" || exit; ' + command, "test", str(HELPERS)], + cwd=self.root, input=patch, text=True, capture_output=True, timeout=30, + ) + + def assert_success(self, result): + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(list(self.root.rglob("*.rej")), []) + + def test_apply_and_skip_already_applied_patch(self): + path = self.write("example", "before\nold\nafter\n") + for _ in range(2): + self.assert_success(self.run_helper("apply_kernel_compat_patch", PATCH)) + self.assertEqual(path.read_text(), "before\nnew\nafter\n") + + def test_conflicting_patch_does_not_partially_modify_files(self): + first = self.write("example", "before\nold\nafter\n") + second = self.write("conflict", "unrelated\n") + patch = PATCH + PATCH.replace("example", "conflict") + result = self.run_helper("apply_kernel_compat_patch", patch) + self.assertNotEqual(result.returncode, 0) + self.assertIn("neither applies nor is already applied", result.stderr) + self.assertEqual(first.read_text(), "before\nold\nafter\n") + self.assertEqual(second.read_text(), "unrelated\n") + self.assertEqual(list(self.root.rglob("*.rej")), []) + + def test_missing_patch_target_is_an_error(self): + result = self.run_helper("apply_kernel_compat_patch", PATCH) + self.assertNotEqual(result.returncode, 0) + self.assertFalse((self.root / "example").exists()) + + def test_stable_backports_and_partial_dtc_backport(self): + lexer = self.write("scripts/dtc/dtc-lexer.l", LEXER.replace("YYLTYPE yylloc;\n", "")) + shipped = self.write("scripts/dtc/dtc-lexer.lex.c_shipped", LEXER) + subcmd = self.write("tools/lib/subcmd/subcmd-util.h", SUBCMD_FIXED) + for _ in range(2): + self.assert_success(self.run_helper("patch_kernel 4.9.337")) + self.assertEqual(lexer.read_text(), LEXER.replace("YYLTYPE yylloc;\n", "")) + self.assertEqual(shipped.read_text(), lexer.read_text()) + self.assertEqual(subcmd.read_text(), SUBCMD_FIXED) + + def test_apply_missing_backports_without_shipped_lexer(self): + lexer = self.write("scripts/dtc/dtc-lexer.l", LEXER) + subcmd = self.write("tools/lib/subcmd/subcmd-util.h", SUBCMD) + self.assert_success(self.run_helper("patch_kernel 4.9")) + self.assertNotIn("YYLTYPE yylloc;", lexer.read_text()) + self.assertEqual(subcmd.read_text(), SUBCMD_FIXED) + + def test_absent_optional_sources_are_skipped(self): + self.assert_success(self.run_helper("patch_kernel 4.9")) + + def test_old_lexer_without_treesource_error(self): + original = LEXER.replace("extern bool treesource_error;\n", "") + lexer = self.write("scripts/dtc/dtc-lexer.l", original) + for _ in range(2): + self.assert_success(self.run_helper("patch_kernel 4.9")) + self.assertEqual(lexer.read_text(), original.replace("YYLTYPE yylloc;\n", "")) + + def test_patch_kernel_propagates_patch_failure(self): + self.write("scripts/dtc/dtc-lexer.l", "unexpected source\n") + subcmd = self.write("tools/lib/subcmd/subcmd-util.h", SUBCMD) + result = self.run_helper("patch_kernel 4.9") + self.assertNotEqual(result.returncode, 0) + self.assertEqual(subcmd.read_text(), SUBCMD) + + def test_purgatory_preserves_dialect_without_tracing_flags(self): + path = self.write("arch/x86/purgatory/Makefile", "KBUILD_CFLAGS := -Os -ffreestanding\n") + for _ in range(2): + self.assert_success(self.run_helper("preserve_purgatory_c_standard")) + self.assertEqual(path.read_text().count("$(filter -std=%,$(KBUILD_CFLAGS))"), 1) + for dialect in ("gnu89", "gnu11", "gnu17"): + with self.subTest(dialect=dialect): + self.write("Makefile", f"KBUILD_CFLAGS := -std={dialect} -pg -fstack-protector\n" + "include arch/x86/purgatory/Makefile\n" + "all:\n\t@echo $(KBUILD_CFLAGS)\n") + result = subprocess.run(["make", "-s"], cwd=self.root, capture_output=True, + text=True, timeout=30) + self.assert_success(result) + self.assertEqual(result.stdout.strip(), f"-std={dialect} -Os -ffreestanding") + + def test_modern_and_explicit_purgatory_flags_are_unchanged(self): + for flags in ("$(filter-out -pg,$(KBUILD_CFLAGS))", "-std=gnu11 -Os"): + with self.subTest(flags=flags): + original = "KBUILD_CFLAGS := " + flags + "\n" + path = self.write("arch/x86/purgatory/Makefile", original) + self.assert_success(self.run_helper("preserve_purgatory_c_standard")) + self.assertEqual(path.read_text(), original) + + +if __name__ == "__main__": + unittest.main() |
|
From: SCST G. <lna...@ya...> - 2026-11-11 08:03:18
|
Commit: 8529747 GitHub URL: https://github.com/SCST-project/scst/commit/8529747323e7859eb9d247883f09bb86d0e24304 Author: Gleb Chesnokov Date: 2026-11-11T11:02:29+03:00 Log Message: ----------- scst: Fix path resolution from kernel threads Linux 7.3 starts kernel threads with their root and pwd in nullfs. Consequently, SCST sysfs workers and other kernel threads can fail to open existing backing devices or metadata files with ENOENT. Add common file-open and path-lookup wrappers and protect the existing block-device opener with scoped_with_init_fs(). Use the userspace init FS context only for kernel threads and restore it when the operation returns, including on errors. Preserve the context of userspace callers. Route all direct file opens and path lookups through these helpers, including virtual disks, persistent reservations, mode pages and DLM. Use tsk_is_kthread() and scoped_with_init_fs() on Linux 7.3 and later. Keep the existing behavior and block-device APIs on older kernels. Model scoped_with_init_fs() for Cppcheck and Coccinelle and register the exact fs_struct.h include for Cppcheck. Keep scoped bodies and early returns visible, with native model regression coverage. Modified Paths: -------------- scripts/coccinelle/macros.h | 5 + scripts/coccinelle/test_models.py | 11 +++ scripts/cppcheck/kernel.h | 6 ++ scripts/cppcheck/test_models.py | 10 ++ scripts/policy/cppcheck.json | 13 +++ scst/include/scst.h | 4 + scst/src/dev_handlers/scst_disk.c | 4 +- scst/src/dev_handlers/scst_vdisk_main.c | 6 +- scst/src/scst_dlm.c | 4 +- scst/src/scst_lib.c | 74 +++++++++++++-- scst/src/scst_pres.c | 6 +- 11 files changed, 123 insertions(+), 20 deletions(-) =================================================================== diff --git a/scripts/coccinelle/macros.h b/scripts/coccinelle/macros.h index f103964..8138a57 100644 --- a/scripts/coccinelle/macros.h +++ b/scripts/coccinelle/macros.h @@ -21,6 +21,11 @@ /* checkpatch-suppress MACRO_ARG_UNUSED ; Coccinelle iterator parser token. */ #define for_each_possible_cpu(cpu) YACFE_ITERATOR +/* FS scope: retain the following statement, including an early return. + * Kernel FS context switching and cleanup are outside this parser model. + */ +#define scoped_with_init_fs() YACFE_ITERATOR + /* String-valued fragments, including hashes from generated headers. */ #define SCST_VERSION_NAME YACFE_STRING #define SCST_VERSION_STRING_SUFFIX YACFE_STRING diff --git a/scripts/coccinelle/test_models.py b/scripts/coccinelle/test_models.py index a621e09..b23937f 100644 --- a/scripts/coccinelle/test_models.py +++ b/scripts/coccinelle/test_models.py @@ -61,6 +61,17 @@ class NativeModelTests(unittest.TestCase): self.check(source) self.check(source.replace("probe();", "other();"), expected=0) + def test_init_fs_scope_retains_body_and_early_return(self): + for body in ("{ probe(); }", "return probe();"): + source = ("int fixture(int kthread) { if (kthread) { " + "scoped_with_init_fs() " + body + " } return fallback(); }\n") + with self.subTest(body=body): + self.check(source) + self.check(source.replace("probe()", "other()"), expected=0) + self.check(source, pattern="return@p fallback(...);") + self.check(source, pattern="return@p probe(...);", + expected=int(body.startswith("return"))) + def test_current_sysfs_macro_retains_generated_function(self): source = 'ISCSI_SESS_BOOL_PARAM_ATTR(initial_r2t, "InitialR2T");\n' self.check(source, pattern="iscsi_get_bool_value@p(...)") diff --git a/scripts/cppcheck/kernel.h b/scripts/cppcheck/kernel.h index 5927ce2..b52789d 100644 --- a/scripts/cppcheck/kernel.h +++ b/scripts/cppcheck/kernel.h @@ -38,6 +38,12 @@ #define __acquires(x) #define __acquire(x) #define __release(x) +/* linux/fs_struct.h executes the scoped body once, including early returns. + * FS context switching and cleanup are outside this syntax model. + */ +#define scoped_with_init_fs() \ + for (int scst_cppcheck_init_fs_once = 1; scst_cppcheck_init_fs_once; \ + scst_cppcheck_init_fs_once = 0) /* checkpatch-suppress-macro MACRO_ARG_UNUSED ; Lockdep metadata is outside this model. */ #define __cond_lock(x, y) (y) /* linux/bitops.h ultimately supplies the unsigned-long BIT expression. */ diff --git a/scripts/cppcheck/test_models.py b/scripts/cppcheck/test_models.py index 7b96645..83d93bc 100644 --- a/scripts/cppcheck/test_models.py +++ b/scripts/cppcheck/test_models.py @@ -142,6 +142,16 @@ void fixture(struct scatterlist *head) self.check(source, "arrayIndexOutOfBounds") self.check(source.replace("values[3]", "values[1]")) + def test_init_fs_scope_body_and_early_return_remain_visible(self): + for body in ("{ values[3] = 1; }", "return values[3];"): + source = "int fixture(void) { int values[2] = { 0 }; " \ + "scoped_with_init_fs() " + body + " return 0; }" + with self.subTest(body=body): + self.check(source, "arrayIndexOutOfBounds") + self.check(source.replace("values[3]", "values[1]")) + self.check("int fixture(void) { int value; " + "scoped_with_init_fs() { value = 1; } return value; }") + def test_trace_assignment_body_remains_visible(self): source = """ struct payload { int value; }; diff --git a/scripts/policy/cppcheck.json b/scripts/policy/cppcheck.json index adf93b4..f6c36e8 100644 --- a/scripts/policy/cppcheck.json +++ b/scripts/policy/cppcheck.json @@ -166,6 +166,19 @@ ], "reason": "Analyze project code with selected compiler configuration and native API models; the bodies of these exact system headers are outside coverage." }, + { + "profiles": [ + "kernel" + ], + "source_roots": [ + "scst" + ], + "dependency_headers": [], + "headers": [ + "linux/fs_struct.h" + ], + "reason": "scoped_with_init_fs() is modeled in scripts/cppcheck/kernel.h to retain the scoped body and early returns; kernel FS context switching and cleanup are outside coverage." + }, { "profiles": [ "userspace" diff --git a/scst/include/scst.h b/scst/include/scst.h index a6788e7..3135b83 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -5989,6 +5989,10 @@ int scst_scsi_exec_async(struct scst_cmd *cmd, void *data, int scst_get_file_mode(const char *path); bool scst_parent_dir_exists(const char *path); +/* Path lookups use userspace init's FS context when called from a kthread. */ +struct file *scst_filp_open(const char *filename, int flags, umode_t mode); +int scst_kern_path(const char *name, unsigned int flags, struct path *path); + struct scst_bdev_descriptor { struct block_device *bdev; void *priv; diff --git a/scst/src/dev_handlers/scst_disk.c b/scst/src/dev_handlers/scst_disk.c index 1c16284..f92092a 100644 --- a/scst/src/dev_handlers/scst_disk.c +++ b/scst/src/dev_handlers/scst_disk.c @@ -270,7 +270,7 @@ static void disk_write_pr_dump(struct scst_device *dev) ssize_t written; loff_t pos = 0; - f = filp_open(priv->pr_dump_path, O_WRONLY | O_CREAT | O_TRUNC, 0600); + f = scst_filp_open(priv->pr_dump_path, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (IS_ERR(f)) { /* * Keep numeric error output on supported kernels without the %pe formatter. @@ -292,7 +292,7 @@ static void disk_write_pr_dump(struct scst_device *dev) PRINT_ERROR("%s: short write to PR dump file %s: %zd/%zd", dev->virt_name, priv->pr_dump_path, written, priv->pr_dump_len); - rc = kern_path(priv->pr_dump_path, 0, &fpath); + rc = scst_kern_path(priv->pr_dump_path, 0, &fpath); if (!rc) scst_vfs_unlink_and_put(&fpath); else diff --git a/scst/src/dev_handlers/scst_vdisk_main.c b/scst/src/dev_handlers/scst_vdisk_main.c index 7c9223d..1531b0c 100644 --- a/scst/src/dev_handlers/scst_vdisk_main.c +++ b/scst/src/dev_handlers/scst_vdisk_main.c @@ -226,7 +226,7 @@ static struct file *vdev_open_fd(const struct scst_vdisk_dev *virt_dev, const ch open_flags |= O_DSYNC; TRACE_DBG("Opening file %s, flags 0x%x", name, open_flags); - fd = filp_open(name, O_LARGEFILE | open_flags, 0600); + fd = scst_filp_open(name, O_LARGEFILE | open_flags, 0600); if (IS_ERR(fd)) { if (PTR_ERR(fd) == -EMEDIUMTYPE) TRACE(TRACE_MINOR, "Unable to open %s with EMEDIUMTYPE, DRBD passive?", @@ -436,7 +436,7 @@ static int vdisk_check_tp_support(struct scst_vdisk_dev *virt_dev) res = scst_open_bdev_by_path(virt_dev->filename, BLK_OPEN_READ, NULL, NULL, &bdev_desc); } else { - fd = filp_open(virt_dev->filename, O_LARGEFILE, 0600); + fd = scst_filp_open(virt_dev->filename, O_LARGEFILE, 0600); res = PTR_ERR_OR_ZERO(fd); } if (res) { @@ -10011,7 +10011,7 @@ static void __init vdev_check_mode_pages_path(void) TRACE_ENTRY(); - res = kern_path(VDEV_MODE_PAGES_DIR, 0, &path); + res = scst_kern_path(VDEV_MODE_PAGES_DIR, 0, &path); if (res == 0) path_put(&path); if (res != 0) { diff --git a/scst/src/scst_dlm.c b/scst/src/scst_dlm.c index 4889bae..e682010 100644 --- a/scst/src/scst_dlm.c +++ b/scst/src/scst_dlm.c @@ -653,7 +653,7 @@ static int scst_read_file(const char *path, char *buf, int buf_len) loff_t pos; int ret; - f = filp_open(path, 0, 0400); + f = scst_filp_open(path, 0, 0400); if (IS_ERR(f)) { ret = PTR_ERR(f); goto out; @@ -765,7 +765,7 @@ int scst_dlm_read_nodeids(char **entries) if (!*entries) return -ENOMEM; - comms = filp_open(scst_dlm_comms_dir, 0, 0400); + comms = scst_filp_open(scst_dlm_comms_dir, 0, 0400); if (IS_ERR(comms)) return PTR_ERR(comms); #ifndef HAVE_ITERATE_DIR diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 721ccff..bda3615 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -22,6 +22,7 @@ #include <linux/init.h> #include <linux/kernel.h> #include <linux/errno.h> +#include <linux/fs_struct.h> #include <linux/list.h> #include <linux/spinlock.h> #include <linux/slab.h> @@ -6253,9 +6254,45 @@ static void scst_complete_request_sense(struct scst_cmd *req_cmd) TRACE_EXIT(); } -int scst_open_bdev_by_path(const char *path, blk_mode_t mode, void *holder, - const struct blk_holder_ops *hops, - struct scst_bdev_descriptor *bdev_desc) +/* + * Borrow userspace init's FS context only for path resolution in kthreads. + * Callers running in a userspace task retain their own context. + */ +struct file *scst_filp_open(const char *filename, int flags, umode_t mode) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 3, 0) + /* + * See also commit 67c54d1d730a ("fs: add scoped_with_init_fs()") # v7.3. + * See also commit 32750c77e811 ("fs: start all kthreads in nullfs") # v7.3. + */ + if (tsk_is_kthread(current)) { + scoped_with_init_fs() + return filp_open(filename, flags, mode); + } +#endif + return filp_open(filename, flags, mode); +} +EXPORT_SYMBOL(scst_filp_open); + +int scst_kern_path(const char *name, unsigned int flags, struct path *path) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 3, 0) + /* + * See also commit 67c54d1d730a ("fs: add scoped_with_init_fs()") # v7.3. + * See also commit 32750c77e811 ("fs: start all kthreads in nullfs") # v7.3. + */ + if (tsk_is_kthread(current)) { + scoped_with_init_fs() + return kern_path(name, flags, path); + } +#endif + return kern_path(name, flags, path); +} +EXPORT_SYMBOL(scst_kern_path); + +static int __scst_open_bdev_by_path(const char *path, blk_mode_t mode, void *holder, + const struct blk_holder_ops *hops, + struct scst_bdev_descriptor *bdev_desc) { #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 9, 0) && \ (!defined(RHEL_RELEASE_CODE) || \ @@ -6281,6 +6318,23 @@ int scst_open_bdev_by_path(const char *path, blk_mode_t mode, void *holder, return 0; } + +int scst_open_bdev_by_path(const char *path, blk_mode_t mode, void *holder, + const struct blk_holder_ops *hops, + struct scst_bdev_descriptor *bdev_desc) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 3, 0) + /* + * See also commit 67c54d1d730a ("fs: add scoped_with_init_fs()") # v7.3. + * See also commit 32750c77e811 ("fs: start all kthreads in nullfs") # v7.3. + */ + if (tsk_is_kthread(current)) { + scoped_with_init_fs() + return __scst_open_bdev_by_path(path, mode, holder, hops, bdev_desc); + } +#endif + return __scst_open_bdev_by_path(path, mode, holder, hops, bdev_desc); +} EXPORT_SYMBOL(scst_open_bdev_by_path); void scst_release_bdev(struct scst_bdev_descriptor *bdev_desc) @@ -6327,7 +6381,7 @@ loff_t scst_file_size(const char *path, umode_t *mode) struct inode *inode; loff_t res; - filp = filp_open(path, O_LARGEFILE | O_RDONLY, 0600); + filp = scst_filp_open(path, O_LARGEFILE | O_RDONLY, 0600); if (IS_ERR(filp)) return PTR_ERR(filp); inode = file_inode(filp); @@ -15635,14 +15689,14 @@ int scst_copy_file(const char *src, const char *dest) goto out; } - file_src = filp_open(src, O_RDONLY, 0); + file_src = scst_filp_open(src, O_RDONLY, 0); if (IS_ERR(file_src)) { res = PTR_ERR(file_src); TRACE_DBG("Unable to open file '%s' - error %d", src, res); goto out_free; } - file_dest = filp_open(dest, O_WRONLY | O_CREAT | O_TRUNC, 0644); + file_dest = scst_filp_open(dest, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (IS_ERR(file_dest)) { res = PTR_ERR(file_dest); TRACE_DBG("Unable to open backup file '%s' - error %d", dest, @@ -15698,7 +15752,7 @@ int scst_remove_file(const char *name) TRACE_ENTRY(); - res = kern_path(name, 0, &path); + res = scst_kern_path(name, 0, &path); if (!res) scst_vfs_unlink_and_put(&path); else @@ -15724,7 +15778,7 @@ int scst_write_file_transactional(const char *name, const char *name1, if (res != 0 && (res != -ENOENT)) goto out; - file = filp_open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644); + file = scst_filp_open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (IS_ERR(file)) { res = PTR_ERR(file); PRINT_ERROR("Unable to (re)create file '%s' - error %d", @@ -15803,7 +15857,7 @@ static int __scst_read_file_transactional(const char *file_name, const char *sig goto out; } - file = filp_open(file_name, O_RDONLY, 0); + file = scst_filp_open(file_name, O_RDONLY, 0); if (IS_ERR(file)) { res = PTR_ERR(file); TRACE_DBG("Unable to open file '%s' - error %d", file_name, res); @@ -15874,7 +15928,7 @@ int scst_get_file_mode(const char *path) struct file *file; int res; - file = filp_open(path, O_RDONLY, 0400); + file = scst_filp_open(path, O_RDONLY, 0400); if (IS_ERR(file)) { res = PTR_ERR(file); goto out; diff --git a/scst/src/scst_pres.c b/scst/src/scst_pres.c index be741c3..3fbd7a7 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -640,7 +640,7 @@ static int scst_pr_do_load_device_file(struct scst_device *dev, const char *file goto out; } - file = filp_open(file_name, O_RDONLY, 0); + file = scst_filp_open(file_name, O_RDONLY, 0); if (IS_ERR(file)) { res = PTR_ERR(file); TRACE_PR("Unable to open file '%s' - error %d", file_name, res); @@ -844,7 +844,7 @@ void scst_pr_sync_device_file(struct scst_device *dev) scst_copy_file(dev->pr_file_name, dev->pr_file_name1); - file = filp_open(dev->pr_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644); + file = scst_filp_open(dev->pr_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (IS_ERR(file)) { res = PTR_ERR(file); PRINT_ERROR("Unable to (re)create PR file '%s' - error %d", @@ -970,7 +970,7 @@ write_error_close: struct path path; int rc; - rc = kern_path(dev->pr_file_name, 0, &path); + rc = scst_kern_path(dev->pr_file_name, 0, &path); if (!rc) scst_vfs_unlink_and_put(&path); else |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:26:37
|
Commit: 61c1326 GitHub URL: https://github.com/SCST-project/scst/commit/61c1326c9efae52176d294dadfca8f664cae3d3e Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- scripts: Validate source-bound Checkpatch exceptions Whole-file Checkpatch needs reviewed exceptions without hiding native failures. Validate per-file completion, totals, stderr and exit status before applying source comments. An unreadable second file must fail even if all findings from the first file are exempt. Support exact rule IDs, bounded regions, macros, named identifiers and single-rule file scopes with reasons. Allow standalone comments to wrap without expanding their scope. Bind PREFER_FALLTHROUGH and TYPO_SPELLING to comments; retain neighboring locations and other diagnostic types. Limit COMPLEX_MACRO ranges to single-line object-like sense tuples with known keys and byte-valued ASC/ASCQ. Reject expressions, function-like macros, directives, unrelated code and literals instead of broadening the exception. Keep ordinary macro exceptions attached to one definition. Add completion, location-binding and malformed-declaration fixtures, including block boundaries and attempted sense-structure bypasses. Recognize CONSTANT_COMPARISON only in complete #if/#elif predicates comparing the configured version macros and literal constructors. Parse Boolean groups, defined guards, vendor - 0 and paired >> 8 forms. Splice physical lines before recognizing comments and literals. Mixed or unknown expressions and ordinary C comparisons remain checked. Recognize LONG_LINE_STRING only for the exact configured logging names and paths when a literal format argument ends the line. Keep checks on other arguments, unrelated calls and ordinary strings. Validate native source quotations before either exception and retain all raw findings. Add structural, continuation, false-match and malformed-policy fixtures. Remove the legacy Checkpatch wrappers and their separate PR workflow. Make checkpatch and the analyzer workflow provide the source checks; Conform and review own commit-message conventions. Accept native totals without the checks field when strict mode is disabled; Checkpatch omits that field rather than emitting zero. Preserve severity accounting and per-file completion checks. Add native clean, WARNING and CHECK probes in both modes, including the strict-only AVOID_BUG severity in --file mode. Require an unreadable second input to remain incomplete in every case. Keep the global exclusions in the same policy change: AVOID_BUG for established invariant assertions, LINUX_VERSION_CODE for supported upstream/vendor compatibility, and commit-submission metadata checks which do not apply to source analysis. Do not disable other source rules. Use the shared report lock around analysis and evidence publication. Modified Paths: -------------- .agents/skills/scst-qla2xxx-update/SKILL.md | 2 +- .github/workflows/checkpatch_pull.yml | 31 -- CONTRIBUTING.md | 18 +- doc/CI.md | 1 - scripts/README.md | 72 ++- scripts/analyzer_policy.py | 97 +++- scripts/analyzer_setup.py | 4 + scripts/checkpatch | 27 - scripts/checkpatch_commits | 21 - scripts/checkpatch_diff | 13 - scripts/checkpatch_scan | 6 - scripts/ci/run-analyzer.py | 8 +- scripts/policy/checkpatch.json | 81 ++- scripts/style/__init__.py | 1 + scripts/style/checkpatch.py | 56 +- scripts/style/exceptions.py | 374 ++++++++++++++ scripts/style/layouts.py | 152 ++++++ scripts/style/test_native.py | 62 +++ scripts/tests/test_analyzer_ci.py | 10 + scripts/tests/test_analyzer_policy.py | 35 +- scripts/tests/test_checkpatch.py | 31 ++ scripts/tests/test_checkpatch_exceptions.py | 395 +++++++++++++++ scripts/tests/test_checkpatch_layouts.py | 120 +++++ 23 files changed, 1469 insertions(+), 148 deletions(-) =================================================================== diff --git a/.agents/skills/scst-qla2xxx-update/SKILL.md b/.agents/skills/scst-qla2xxx-update/SKILL.md index 7afd2d1..53eac8f 100644 --- a/.agents/skills/scst-qla2xxx-update/SKILL.md +++ b/.agents/skills/scst-qla2xxx-update/SKILL.md @@ -100,7 +100,7 @@ python3 scripts/kernel/qla2xxx.py export --linux <linux-repo> \ substantial defaults, capability and control-flow differences separately from mechanical backports; token equality is not semantic proof. - Run the tool tests if its behavior changed, plus the repository's required - diff, per-commit checkpatch and message checks. Inspect imported diagnostics + diff, `make checkpatch` and commit-message checks. Inspect imported diagnostics individually; do not rewrite upstream patches merely to hide existing warnings or extend ignore lists. - Compile core and both newer QLogic modules against the target kernel, using diff --git a/.github/workflows/checkpatch_pull.yml b/.github/workflows/checkpatch_pull.yml deleted file mode 100644 index 5d7c5e0..0000000 --- a/.github/workflows/checkpatch_pull.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Checkpatch upon pull request - -on: - pull_request: - branches: - - master - -concurrency: - group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -jobs: - checkpatch: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@main - with: - ref: ${{github.event.pull_request.head.sha}} - fetch-depth: 0 - - - name: Download checkpatch.pl - run: | - curl -fsSL --retry 5 https://raw.githubusercontent.com/torvalds/linux/master/scripts/checkpatch.pl -o checkpatch.pl - curl -fsSL --retry 5 https://raw.githubusercontent.com/torvalds/linux/master/scripts/spelling.txt -o spelling.txt - curl -fsSL --retry 5 https://raw.githubusercontent.com/torvalds/linux/master/scripts/const_structs.checkpatch -o const_structs.checkpatch - chmod +x checkpatch.pl - - - name: Run checkpatch.pl - run: | - CHECKPATCH_PATH=. ./scripts/checkpatch_commits ${{github.event.pull_request.base.sha}} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d9605c..a390719 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,14 +9,14 @@ rules below describe SCST-specific additions and exceptions. - Preserve the naming and diagnostic conventions of the component being changed, including its existing `TRACE_*` and `PRINT_*` macros. The shared definitions are in `scst/include/scst_debug.h`. -- Use the repository's `scripts/checkpatch` wrapper. Its ignore list records - the diagnostics disabled for SCST; do not copy that list into another - configuration. A disabled diagnostic is not a general style exemption. +- Use `make checkpatch`. Its global exceptions are recorded with reasons in + `scripts/policy/checkpatch.json`; local exceptions belong beside the source. + A disabled diagnostic is not a general style exemption. ## Commit messages -`Signed-off-by:` is optional in SCST. This matches the `MISSING_SIGN_OFF` and -`NO_AUTHOR_SIGN_OFF` exclusions in `scripts/checkpatch`. +`Signed-off-by:` is optional in SCST. Commit messages are checked separately +from source style, using Conform and review. Use a prefix from the registry below in the kernel-style subject: @@ -80,8 +80,8 @@ for the patch. No Git hooks are installed. | Change | Required local checks | | --- | --- | | Any change | `git diff --check <base>`. | -| Prepared commits | `scripts/checkpatch_commits <base>` and Conform as described below; review prefixes against the registry above. | -| Uncommitted C changes | `scripts/checkpatch_diff <base>`; rerun per-commit checks after preparing the series. | +| Prepared commits | Conform as described below; review prefixes against the registry above. | +| C sources or headers | `make checkpatch`; this checks the complete maintained source scope. | | Shell scripts or sourced shell files | Syntax checks and ShellCheck as described below. | | Python files | `python3 -m py_compile <changed-files>`. | | Go files | `gofmt -l <changed-files>` must produce no output; follow component guidance. | @@ -123,8 +123,8 @@ conform enforce --commit-msg-file <message-file> ``` Checkpatch requires a kernel `scripts/` directory containing `checkpatch.pl` -and its companion data files. The wrapper defaults to the running kernel's -build tree; set `CHECKPATCH_PATH` to use another prepared directory. Record +and its companion data files. Set `KDIR` to select a kernel build tree or +`CHECKPATCH_PATH` to use another prepared scripts directory. Record the kernel/tool version with the result when it affects diagnostics. ### Analyzer tooling diff --git a/doc/CI.md b/doc/CI.md index 1c56695..55eb0b0 100644 --- a/doc/CI.md +++ b/doc/CI.md @@ -5,7 +5,6 @@ Workflows live in [`.github/workflows`](../.github/workflows). PR checks target | Workflow | Purpose | Events | | --- | --- | --- | -| [PR Checkpatch](../.github/workflows/checkpatch_pull.yml) | Individual patch and commit style | PR | | [CI](../.github/workflows/ci.yml) | Clang build and DEB packaging | PR, push, manual | | [Packages](../.github/workflows/rpm.yml) | Ubuntu DEBs, RPMs and a published package snapshot | Push to master only | | [Regression](../.github/workflows/run_regression_tests.yaml) | Module and patched-kernel builds across the kernel matrix | PR, push | diff --git a/scripts/README.md b/scripts/README.md index 17aefc8..405d932 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -15,15 +15,10 @@ direct callers of a relocated script must use its new directory below. | `sparse_smatch/` | Native Kbuild analyzers (`make sparse`, `make smatch`) and CHECK records. | | `coccinelle/` | Kernel semantic-patch report rules (`make coccicheck`). | | `cppcheck/` | Native analysis using captured compiler commands (`make cppcheck`). | -| `style/` | Whole-file Checkpatch analysis (`make checkpatch`, `scripts/checkpatch_scan`). | +| `style/` | Whole-file Checkpatch analysis (`make checkpatch`). | | `scs_lint/` | SCST code style rules (`make scs_lint`); see [SCS](../doc/scs.md). | | `tests/` | Isolated regression fixtures for the shared analyzer helpers (`make lint-test`). | -The `checkpatch`, `checkpatch_commits` and `checkpatch_diff` helpers retain -their existing patch/commit policy, including the ignored types in `checkpatch`. -The kernel regression runner also retains its separate checkpatch filtering. -`checkpatch_scan` now delegates to the unfiltered whole-file analyzer below. - Use Make targets from the repository root unless a component workflow says otherwise. Direct scripts retain their working-directory conventions: `generate-kernel-patch` and `update-version` use the SCST root, while archive @@ -73,8 +68,7 @@ requires the current per-module Kbuild layout. `lint_scope.py` reads [policy/common.json](policy/common.json) for full and explicit-file selection. The loader rejects invalid or missing policy; -there are no environment-based extra exclusions. Existing checkpatch wrappers -and the kernel regression runner still use their own selection and filtering. +there are no environment-based extra exclusions. Inspect the shared policy and eligible tracked files without running analyzers: @@ -234,19 +228,67 @@ the summary links to captured commands, native XML and checker coverage. ```sh make checkpatch KDIR=/path/to/kernel/build +make checkpatch CHECKPATCH_PATH=/path/to/kernel/scripts ``` The target checks whole C files and headers selected by the common policy, -including userspace and KUnit. Diff mode selects whole changed files. It needs -the kernel's `checkpatch.pl`, `spelling.txt` and `const_structs.checkpatch`, +including userspace and KUnit. It needs the kernel's `checkpatch.pl`, +`spelling.txt` and `const_structs.checkpatch`, but no compilation or KUnit-enabled kernel. `CHECKPATCH_PATH` overrides `KDIR`. -Native `--strict` checks run without ignored types or project exceptions; -local `.checkpatch.conf` files are not loaded. Source files are never rewritten. +Native `--strict` checks use the global exceptions in +[policy/checkpatch.json](policy/checkpatch.json): invariant assertions, +kernel-version checks and commit-submission metadata. Commit messages have +separate Conform checks. Local `.checkpatch.conf` files are not loaded. +Policy also recognizes complete `#if`/`#elif` expressions comparing the listed +version macros, and format-only long lines in the listed logging calls. +Version predicates allow `defined` guards, Boolean grouping, vendor `- 0` +forms and matching `>> 8` series comparisons. Unknown expressions remain checked. +Logging exceptions require a literal format argument ending the line; other +arguments, unrelated calls and ordinary long strings remain checked. +Other exceptions use source comments. All exceptions apply only after native +coverage and totals are checked; raw diagnostics and policy reasons remain visible. +Source files are never rewritten. Findings return 1; missing per-file completion, inconsistent totals, stderr or tool failures return 2. Make maps both failures to 2. Complete output and -coverage are in `.cache/lint/checkpatch.{log,json}`. `scripts/checkpatch_scan` -uses the same policy and exit codes; legacy patch/commit helpers remain separate. +coverage are in `.cache/lint/checkpatch.{log,json}`. + +A reviewed interface spelling can use +`checkpatch-suppress-symbol CAMELCASE symbolName=Name ; reason` in a standalone +C comment before a use or declaration of that exact identifier. This exception +applies to that name across selected files, avoiding Checkpatch's first-use +ordering dependency. Other names and diagnostic categories remain checked; +removing or renaming the annotated identifier invalidates the declaration. + +`COMPLEX_MACRO` begin/end blocks accept only object-like sense-key, ASC, ASCQ +definitions, one per line, with byte-valued ASC/ASCQ. Comments are allowed; +unrelated code or expressions invalidate the block. Other macro exceptions +must remain attached to individual definitions. + +## Source exceptions and provenance + +Use a standalone comment immediately before the relevant construct: + +```c +/* checkpatch-suppress CONST_STRUCT ; Older kernels require a mutable registration object. */ +/* cppcheck-suppress constParameterCallback symbolName=cmd ; Keep the callback ABI. */ +/* coccinelle-suppress rule_name ; Explain the reviewed exception. */ +``` + +The parsers also support bounded `-begin`/`-end` blocks, `-macro` and `-file` +where the tool supports them; every declaration requires a reason. File +exceptions affect one named diagnostic, not all findings. The current +Checkpatch file exceptions cover portable ABI integer types and unchanged +legacy license headers. Cppcheck and Coccinelle have no file-wide exceptions. +Checkpatch comment diagnostics attach to the next comment; other line +exceptions attach to the next code line. A longer rationale can precede +the marker, which then refers to it with `See the contract above.`. Checkpatch +markers and reasons may also wrap across a standalone `/* ... */` comment. + +SCST contracts and reviewed exceptions come from the frozen historical branch +at `ee5e4173fff7`. Changed historical contexts require a fresh review before +reattaching an exception. +Use the policy inventory above for the complete current list and reasons. ## SCST code style @@ -274,7 +316,7 @@ build. The container jobs retain reports from `.cache/lint/` for seven days. CI fails on findings remaining after policy exceptions, just like local Make targets. The native-analyzer runner returns 1 for completed analysis with findings and 2 for build/tool failures, incomplete analysis or missing KUnit -coverage. PRs retain the separate patch/commit Checkpatch workflow. +coverage. ## Dependencies and tooling tests diff --git a/scripts/analyzer_policy.py b/scripts/analyzer_policy.py index 6eb974c..f187993 100644 --- a/scripts/analyzer_policy.py +++ b/scripts/analyzer_policy.py @@ -1,7 +1,9 @@ """Inspect the shared analyzer input policy without invoking an analyzer.""" import argparse +import hashlib import json +import re import subprocess import sys from functools import lru_cache @@ -26,6 +28,18 @@ KBUILD_SCHEMA = { BASIC_SCHEMA = {"version": int, "notes": [str]} POLICIES = ("common", "sparse", "smatch", "coccicheck", "cppcheck", "checkpatch", "scs_lint") BASIC_POLICIES = ("coccicheck", "cppcheck", "checkpatch", "scs_lint") +ANALYZER_SCHEMAS = { + "checkpatch": {**BASIC_SCHEMA, "strict": bool, "max_line_length": int, + "disabled_checks": [{"id": str, "reason": str}], + "version_comparisons": { + "code_macros": [{"name": str, "constructor": str, "arguments": int}], + "integer_macros": [str], "reason": str}, + "logging_calls": [{"file_glob": str, "names": [str], "reason": str}], + "macro_body_layouts": [{"file_glob": str, "macro": str, + "first_entry_pattern": str, "reason": str}], + "line_layouts": [{"rule": str, "file_glob": str, + "source_pattern": str, "reason": str}]}, +} def relative_path(value: str, location: str): @@ -66,12 +80,39 @@ def read_policy(path: Path, name="common") -> dict: if name not in POLICIES: raise ValueError(f"unknown policy: {name}") policy = json.loads(path.read_text(encoding="utf-8"), object_pairs_hook=unique_object) - schema = BASIC_SCHEMA if name in BASIC_POLICIES else ( + schema = ANALYZER_SCHEMAS.get(name, BASIC_SCHEMA) if name in BASIC_POLICIES else ( SCHEMA if name == "common" else KBUILD_SCHEMA) validate(policy, schema, str(path)) if policy["version"] != 1: raise ValueError(f"{path}: unsupported policy version") if name in BASIC_POLICIES: + if name == "checkpatch": + ids = [entry["id"] for entry in policy["disabled_checks"]] + if len(ids) != len(set(ids)) or any(not re.fullmatch(r"[A-Z][A-Z0-9_]*", x) for x in ids): + raise ValueError(f"{path}: diagnostic IDs must be exact and unique") + if policy["max_line_length"] <= 0: + raise ValueError(f"{path}: invalid line length") + versions = policy["version_comparisons"] + macros = [item["name"] for item in versions["code_macros"]] + versions["integer_macros"] + if (len(macros) != len(set(macros)) or + any(not re.fullmatch(r"[A-Z_][A-Z0-9_]*", macro) for macro in macros)): + raise ValueError(f"{path}: version macro names must be exact and unique") + for item in versions["code_macros"]: + if (not re.fullmatch(r"[A-Z_][A-Z0-9_]*", item["constructor"]) or + not 1 <= item["arguments"] <= 3): + raise ValueError(f"{path}: invalid version constructor") + for item in policy["logging_calls"]: + relative_path(item["file_glob"], str(path)) + names = item["names"] + if (not names or len(names) != len(set(names)) or + any(not re.fullmatch(r"[A-Za-z_]\w*", name) for name in names)): + raise ValueError(f"{path}: logging call names must be exact and unique") + for entry in policy["macro_body_layouts"] + policy["line_layouts"]: + relative_path(entry["file_glob"], str(path)) + re.compile(entry.get("source_pattern", entry.get("first_entry_pattern"))) + if any(entry["rule"] not in {"LONG_LINE", "LONG_LINE_COMMENT", "LONG_LINE_STRING"} + for entry in policy["line_layouts"]): + raise ValueError(f"{path}: unsupported layout rule") return policy if name != "common": for key, fields in (("exclude_directories", ("path",)), @@ -129,6 +170,28 @@ def source_policy(name="common") -> dict: load_policy(name)["exclude_directories"]} +def load(name): + """Combine diagnostic policy with the separately maintained source scope.""" + return {**load_policy(name), **source_policy(name)} + + +def inline_inventory(root, name): + if name == "checkpatch": + from style.exceptions import inventory + else: + return [] + return inventory(root, load(name)) + + +def integration(root, name): + if name not in {"coccicheck", "cppcheck"}: + return [] + from analyzer_setup import MODELS + + return [dict(item, sha256=hashlib.sha256((root / item["path"]).read_bytes()).hexdigest()) + for item in MODELS.get(name, ())] + + def text_report(result: dict, action: str) -> str: lines = [f"Policy: {result['policy']} ({result['policy_file']})"] if action == "validate": @@ -154,8 +217,31 @@ def text_report(result: dict, action: str) -> str: lines.append("Environment overrides for input exclusions: none.") lines.extend(policy["notes"]) if result["policy"] in BASIC_POLICIES: - lines.append("Additional input exclusions and diagnostic exceptions: none.") - lines.extend(result["configured_policy"]["notes"]) + lines.append("Additional input exclusions: none.") + entries = result.get("inline_exceptions", []) + lines.append(f"Inline exception declarations: {len(entries)} (not hit counts).") + lines.extend(f" {e['file']}:{e['line']}-{e['end_line']} [{e['rule']}] " + f"{e['scope']}: {e['reason']}" for e in entries) + for model in result.get("models", []): + lines.append(f"Model {model['path']} ({model['sha256']}): {model['reason']}") + configured = result["configured_policy"] + if result["policy"] == "checkpatch": + lines.append("Globally disabled Checkpatch IDs: " + + (", ".join(x["id"] for x in configured["disabled_checks"]) or "none")) + versions = configured["version_comparisons"] + for item in versions["code_macros"]: + lines.append(f" Version comparison: {item['name']} / {item['constructor']}" + f" ({item['arguments']} literal arguments)") + lines.append(" Integer version macros: " + ", ".join(versions["integer_macros"])) + lines.append(" In #if/#elif expressions only: " + versions["reason"]) + for item in configured["logging_calls"]: + lines.append(f" Logging strings: {item['file_glob']} / " + + ", ".join(item["names"]) + ": " + item["reason"]) + for item in configured["macro_body_layouts"] + configured["line_layouts"]: + label = item.get("rule", "PARENTHESIS_ALIGNMENT") + expression = item.get("source_pattern", item.get("first_entry_pattern")) + lines.append(f" Layout [{label}] {item['file_glob']} / {expression}: {item['reason']}") + lines.extend(configured["notes"]) elif result["policy"] != "common": native = result["configured_policy"] lines.append("Source warning exceptions (exact file, function and message):") @@ -181,14 +267,19 @@ def main() -> int: try: policy = load_policy(args.policy) scope = source_policy(args.policy) + root = Path(__file__).resolve().parent.parent + entries = inline_inventory(root, args.policy) result = {"policy": args.policy, "policy_file": f"scripts/policy/{args.policy}.json"} if args.action == "validate": + integration(root, args.policy) result["valid"] = True else: result["coverage"] = "Shared input selection only; no analyzer has run." if args.action == "show": result["configured_policy"] = policy result["effective_source_policy"] = scope + result["inline_exceptions"] = entries + result["models"] = integration(root, args.policy) else: from lint_scope import tracked_sources diff --git a/scripts/analyzer_setup.py b/scripts/analyzer_setup.py new file mode 100644 index 0000000..b1bc554 --- /dev/null +++ b/scripts/analyzer_setup.py @@ -0,0 +1,4 @@ +"""Integration models are separate from source scope and diagnostic exceptions.""" + +MODELS = { +} diff --git a/scripts/checkpatch b/scripts/checkpatch deleted file mode 100755 index 64cff7c..0000000 --- a/scripts/checkpatch +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -scriptpath="${CHECKPATCH_PATH:-/lib/modules/$(uname -r)/build/scripts}" - -ignore=( - MISSING_SIGN_OFF - EMAIL_SUBJECT - UNKNOWN_COMMIT_ID - NO_AUTHOR_SIGN_OFF - COMMIT_LOG_USE_LINK - BAD_REPORTED_BY_LINK - FILE_PATH_CHANGES - SPDX_LICENSE_TAG - LINUX_VERSION_CODE - CONSTANT_COMPARISON - NEW_TYPEDEFS - AVOID_BUG - COMPLEX_MACRO - MACRO_ARG_REUSE - IF_0 - LONG_LINE_STRING -) -ignore_str="${ignore[*]}" - -"${scriptpath}/checkpatch.pl" --no-tree --show-types --strict --ignore="${ignore_str// /,}" "$@" diff --git a/scripts/checkpatch_commits b/scripts/checkpatch_commits deleted file mode 100755 index 0aa0cc1..0000000 --- a/scripts/checkpatch_commits +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -rootdir="$(readlink -f "$(dirname "$0")/..")" -scriptsdir="${rootdir}/scripts" -base_commit="${1:-master}" - -commits=$(cd "${rootdir}" && git log --pretty=format:"%h" "${base_commit}"..HEAD) -err=0 - -for commit in ${commits}; do - echo "Running checkpatch for commit ${commit}" - echo -e "========================================\n" - - (cd "${rootdir}" && - git format-patch -1 --stdout "${commit}" | "${scriptsdir}/checkpatch" -) || err=1 - echo -e "\n" -done - -exit "${err}" diff --git a/scripts/checkpatch_diff b/scripts/checkpatch_diff deleted file mode 100755 index 8ab3af4..0000000 --- a/scripts/checkpatch_diff +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -rootdir="$(readlink -f "$(dirname "$0")/..")" -scriptsdir="${rootdir}/scripts" -base_commit="${1:-master}" - -err=0 - -(cd "${rootdir}" && git diff "${base_commit}" | "${scriptsdir}/checkpatch" -) || err=1 - -exit "${err}" diff --git a/scripts/checkpatch_scan b/scripts/checkpatch_scan deleted file mode 100755 index 33f4327..0000000 --- a/scripts/checkpatch_scan +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -scriptsdir="$(cd "$(dirname "$0")" && pwd)" -exec "${PYTHON:-python3}" -B "$scriptsdir/style/checkpatch.py" "$@" diff --git a/scripts/ci/run-analyzer.py b/scripts/ci/run-analyzer.py index 30a23a1..56c7824 100644 --- a/scripts/ci/run-analyzer.py +++ b/scripts/ci/run-analyzer.py @@ -28,8 +28,12 @@ def complete_native_report(report): if tool == "checkpatch": checked = report.get("checked_files") completed = report.get("completed_files") - return (report.get("complete") is True and not report.get("failures") and - report.get("native_status") == report.get("exit_code") and + remaining, ignored = report.get("remaining"), report.get("ignored", 0) + findings = report.get("findings", remaining) + return (all(type(value) is int and value >= 0 for value in (remaining, ignored, findings)) and + findings == remaining + ignored and + report.get("complete") is True and not report.get("failures") and + report.get("native_status") == int(bool(findings)) and isinstance(checked, list) and bool(checked) and checked == report.get("selected_files") and isinstance(completed, list) and diff --git a/scripts/policy/checkpatch.json b/scripts/policy/checkpatch.json index 54b768b..f008d96 100644 --- a/scripts/policy/checkpatch.json +++ b/scripts/policy/checkpatch.json @@ -3,7 +3,82 @@ "notes": [ "Check whole C files and headers with native Checkpatch --strict.", "Include userspace and KUnit sources through the common input policy.", - "No diagnostic exceptions, ignored types or local Checkpatch configuration.", - "Legacy patch and commit helpers retain their separate existing policy." - ] + "Commit messages are checked separately by Conform and review." + ], + "strict": true, + "max_line_length": 100, + "disabled_checks": [ + { + "id": "AVOID_BUG", + "reason": "Existing invariant assertions require a separate recovery-path audit before replacement." + }, + { + "id": "LINUX_VERSION_CODE", + "reason": "The out-of-tree compatibility layer supports multiple upstream and distribution kernels." + }, + { + "id": "MISSING_SIGN_OFF", + "reason": "Conform and review check commit messages; source analysis does not enforce kernel patch-submission metadata." + }, + { + "id": "COMMIT_MESSAGE", + "reason": "Conform and review check commit messages; source analysis does not enforce kernel patch-submission metadata." + }, + { + "id": "EMAIL_SUBJECT", + "reason": "Conform and review check commit messages; source analysis does not enforce kernel patch-submission metadata." + }, + { + "id": "UNKNOWN_COMMIT_ID", + "reason": "Conform and review check commit messages; source analysis does not enforce kernel patch-submission metadata." + }, + { + "id": "NO_AUTHOR_SIGN_OFF", + "reason": "Conform and review check commit messages; source analysis does not enforce kernel patch-submission metadata." + }, + { + "id": "COMMIT_LOG_USE_LINK", + "reason": "Conform and review check commit messages; source analysis does not enforce kernel patch-submission metadata." + }, + { + "id": "BAD_REPORTED_BY_LINK", + "reason": "Conform and review check commit messages; source analysis does not enforce kernel patch-submission metadata." + }, + { + "id": "FILE_PATH_CHANGES", + "reason": "Conform and review check commit messages; source analysis does not enforce kernel patch-submission metadata." + } + ], + "version_comparisons": { + "code_macros": [ + {"name": "LINUX_VERSION_CODE", "constructor": "KERNEL_VERSION", "arguments": 3}, + {"name": "RHEL_RELEASE_CODE", "constructor": "RHEL_RELEASE_VERSION", "arguments": 2} + ], + "integer_macros": ["RHEL_MAJOR", "RHEL_MINOR", "UTS_UBUNTU_RELEASE_ABI"], + "reason": "Kernel compatibility predicates compare known version constants in complete #if/#elif expressions; retain version-code-before-threshold ordering." + }, + "logging_calls": [ + { + "file_glob": "*", + "names": ["PRINT_ERROR", "PRINT_WARNING", "PRINT_WARNING_ONCE", "PRINT_INFO", "PRINT_CRIT_ERROR", "TRACE_MGMT_DBG", "TRACE_DBG", "TRACE_MEM", "TRACE_PR", "TRACE_CONN_CLOSE_DBG", "TRACE_WRITE", "TRACE_BLOCK", "TRACE_RETRY", "TRACE_SN"], + "reason": "Keep a complete diagnostic literal searchable, as for native kernel logging; only a format argument ending the line is exempt." + }, + { + "file_glob": "iscsi-scst/usr/*", + "names": ["log_error"], + "reason": "Keep the daemon's complete diagnostic literal searchable; other arguments and ordinary long lines remain checked." + }, + { + "file_glob": "usr/*", + "names": ["printf"], + "reason": "Keep a complete userspace diagnostic literal searchable; only a format argument ending the line is exempt." + }, + { + "file_glob": "fcst/*", + "names": ["FT_ERR"], + "reason": "Keep the FC target's complete diagnostic literal searchable; other arguments and ordinary long lines remain checked." + } + ], + "macro_body_layouts": [], + "line_layouts": [] } diff --git a/scripts/style/__init__.py b/scripts/style/__init__.py new file mode 100644 index 0000000..eef5fd6 --- /dev/null +++ b/scripts/style/__init__.py @@ -0,0 +1 @@ +"""SCST analyzer integration.""" diff --git a/scripts/style/checkpatch.py b/scripts/style/checkpatch.py index 843deb3..0684823 100644 --- a/scripts/style/checkpatch.py +++ b/scripts/style/checkpatch.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 -"""Check whole SCST C files with native Checkpatch and no diagnostic filters.""" +"""Check whole SCST C files with native Checkpatch and source-bound exceptions.""" import argparse from collections import Counter -import fcntl import json import os from pathlib import Path @@ -15,10 +14,13 @@ import tempfile sys.dont_write_bytecode = True ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT / "scripts")) -from lint_common import copy_output, entrypoint, log_path, run, show_log # noqa: E402 -from lint_scope import select_sources # noqa: E402 +from analyzer_report import show_result # noqa: E402 +from lint_common import copy_output, entrypoint, log_path, report_lock, run, show_log # noqa: E402 +from lint_scope import select_sources, tracked_sources # noqa: E402 +from analyzer_policy import load_policy # noqa: E402 +from style.exceptions import apply_exceptions, source_exceptions # noqa: E402 -TOTAL = re.compile(r"total: (\d+) errors, (\d+) warnings, (\d+) checks, \d+ lines checked") +TOTAL = re.compile(r"total: (\d+) errors, (\d+) warnings, (?:(\d+) checks, )?\d+ lines checked") COMPLETE = re.compile(r"(.+) has (?:style problems, please review|" r"no obvious style problems and is ready for submission)\.") DIAGNOSTIC = re.compile(r"^(ERROR|WARNING|CHECK):([^:\n]+): ?(.*)$", re.MULTILINE) @@ -37,7 +39,7 @@ def checker_path(): def native_report(text, stderr, status, selected): """Require matching native totals and completion for every requested file.""" diagnostics = Counter(match[1] for match in DIAGNOSTIC.finditer(text)) - totals = [tuple(map(int, match.groups())) for line in text.splitlines() + totals = [tuple(int(value or 0) for value in match.groups()) for line in text.splitlines() if (match := TOTAL.fullmatch(line))] completed = Counter(str(Path(match[1]).resolve()) for line in text.splitlines() if (match := COMPLETE.fullmatch(line))) @@ -76,8 +78,23 @@ def check(tool, selected, log): stderr = directory / "stderr" env = dict(os.environ, CHECKPATCH_CONFIG_DIR=str(directory), GIT_DIR=git_dir, GIT_WORK_TREE=str(ROOT)) + policy = load_policy("checkpatch") command = [str(tool), "--no-tree", "--root=" + str(ROOT), "--strict", "--show-types", - "--color=never", "--no-fix", "--no-fix-inplace", "--file", *map(str, selected)] + "--color=never", "--no-fix", "--no-fix-inplace", + "--max-line-length=" + str(policy["max_line_length"]), + "--file", *map(str, selected)] + if not policy["strict"]: + command.remove("--strict") + if policy["disabled_checks"]: + command.append("--ignore=" + ",".join(x["id"] for x in policy["disabled_checks"])) + sources = {p.relative_to(ROOT).as_posix(): p.read_text(errors="surrogateescape") + for p in selected} + symbol_sources = {p.relative_to(ROOT).as_posix(): p.read_text(errors="surrogateescape") + for p in tracked_sources(ROOT, "checkpatch")} + symbol_sources.update(sources) + entries = [e for name, source in symbol_sources.items() + for e in source_exceptions(source, name) + if name in sources or e.get("symbol")] try: with stdout.open("wb") as output, stderr.open("wb") as errors: result = run(command, cwd=directory, env=env, stdout=output, stderr=errors, @@ -87,17 +104,27 @@ def check(tool, selected, log): for path in (stdout, stderr): if path.exists(): copy_output(path, stream) - return native_report(stdout.read_text(errors="replace"), stderr.read_text(errors="replace"), - result.returncode, selected) + native = stdout.read_bytes() + record = native_report(native.decode(errors="replace"), stderr.read_text(errors="replace"), + result.returncode, selected) + filtered, exempt, _ = apply_exceptions(native, ROOT, sources, policy, + symbol_sources=symbol_sources) + display = log.with_suffix(".selected.log") + display.write_bytes(filtered + stderr.read_bytes()) + # Tool failures and missing per-file totals remain blocking even when + # every ordinary finding has an applicable source exception. + record.update(findings=record["remaining"], ignored=sum(exempt.values()), + remaining=record["remaining"] - sum(exempt.values()), + exception_counts=dict(exempt), inline_exceptions=entries, + selected_log=str(display)) + return record def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("files", nargs="*", type=Path) args = parser.parse_args() - with log_path(ROOT, "checkpatch.lock", truncate=False).open("a") as lock: - # Serialize this report without blocking independent Kbuild analyzers. - fcntl.flock(lock, fcntl.LOCK_EX) + with report_lock(ROOT, "checkpatch"): log = log_path(ROOT, "checkpatch.log") report = log.with_suffix(".json") summary = {"tool": "checkpatch", "run_id": os.environ.get("SCST_LINT_RUN_ID"), @@ -122,10 +149,13 @@ def main(): summary.update(outcome="findings" if status else "clean", exit_code=status) print(f"Checkpatch: {len(selected)} files, {summary['remaining']} diagnostic(s).") return status + except BaseException as error: + summary.setdefault("failures", []).append(str(error) or type(error).__name__) + raise finally: report.write_text(json.dumps(summary, indent=2) + "\n") if os.environ.get("LINT_DEFER_REPORTS") != "1": - copy_output(log) + show_result(summary, log) show_log(log) diff --git a/scripts/style/exceptions.py b/scripts/style/exceptions.py new file mode 100644 index 0000000..7a782ba --- /dev/null +++ b/scripts/style/exceptions.py @@ -0,0 +1,374 @@ +"""Rule-specific comments attached to Checkpatch source locations.""" + +import fnmatch +import re +from collections import Counter +from pathlib import Path + +from style.layouts import source_layouts + +DIAGNOSTIC = re.compile(r"^(ERROR|WARNING|CHECK)\b", re.MULTILINE) +TOTAL = re.compile(r"^total: (\d+) errors, (\d+) warnings, (?:(\d+) checks, )?" + r"\d+ lines checked$", re.MULTILINE) +SOURCE_DIAGNOSTIC = re.compile( + r"^(ERROR|WARNING|CHECK):([A-Z][A-Z0-9_]*): [^\n]*\n" + r"#\d+: FILE: ([^\n]+):(\d+):\n((?: [^\n]*\n)*(?:\+[^\n]*\n)+)", re.MULTILINE) +# These rules print the previous line before the location being diagnosed. +PREVIOUS_CONTEXT = {"PARENTHESIS_ALIGNMENT", "LINE_SPACING"} +# These diagnostics can refer to comments rather than the next C token. +COMMENT_RULES = {"PREFER_FALLTHROUGH", "TYPO_SPELLING"} +TOKEN = re.compile(r'"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|' + r'/\*.*?(?:\*/|\Z)|//(?:\\\n|[^\n])*', re.DOTALL) +MARKER = re.compile(r"/\*[ \t]*CHECKPATCH:[ \t]+ignore(-file|-block)?[ \t]+" + r"([A-Z][A-Z0-9_]*)" + r"[ \t]+--[ \t]+([^\n]+?)[ \t]*\*/") +SUPPRESSION = re.compile(r"/\* checkpatch-suppress(-begin|-end|-file|-macro|-symbol)? " + r"([A-Z][A-Z0-9_]*)(?: symbolName=([A-Za-z_]\w*))?" + r"(?: ; ([^\n]*?))? \*/") +DEFINE = re.compile(r"[ \t]*#[ \t]*define[ \t]+([A-Za-z_][A-Za-z_0-9]*)\b") +AGGREGATE = re.compile(r"(typedef\s+)?(struct|union|enum)(?:\s+([A-Za-z_]\w*))?") +ARRAY = re.compile(r"(?:[A-Za-z_]\w*\s+|\*\s*)+([A-Za-z_]\w*)\s*" + r"(?:\[[^\[\]{};]*\]\s*)+=\s*") +ATTRIBUTES = r"(?:__[A-Za-z_]\w*(?:\([^;{}]*\))?\s*)*" +SENSE_KEYS = frozenset({ + "NO_SENSE", "RECOVERED_ERROR", "NOT_READY", "MEDIUM_ERROR", "HARDWARE_ERROR", + "ILLEGAL_REQUEST", "UNIT_ATTENTION", "DATA_PROTECT", "BLANK_CHECK", + "COPY_ABORTED", "ABORTED_COMMAND", "VOLUME_OVERFLOW", "MISCOMPARE", "COMPLETED", +}) +SENSE_BYTE = r"(0[xX][0-9a-fA-F]+|0|[1-9][0-9]*)" +SENSE_TUPLE = re.compile(r"\s*#\s*define\s+[A-Za-z_]\w*\s+([A-Z_]+)\s*,\s*" + + SENSE_BYTE + r"\s*,\s*" + SENSE_BYTE + r"\s*") + + +def validate_sense_block(source, entry, end_line, name): + """Accept only object-like sense-key/ASC/ASCQ definitions in this range.""" + # Keep string/character literals visible: masking them could turn an + # invalid replacement such as '"text" 0' into an apparently valid byte. + text = TOKEN.sub(lambda m: re.sub(r"[^\n]", " ", m[0]) + if m[0].startswith(("/*", "//")) else m[0], source) + start = entry["comment_end_line"] + definitions = 0 + for line, value in enumerate(text.split("\n")[start:end_line - 1], start + 1): + if not value.strip(): + continue + match = SENSE_TUPLE.fullmatch(value) + if (not match or match[1] not in SENSE_KEYS or + any(int(byte, 16 if byte.lower().startswith("0x") else 10) > 255 + for byte in match.groups()[1:])): + raise ValueError(f"{name}:{line}: COMPLEX_MACRO block requires " + "single-line object-like sense-key, ASC, ASCQ definitions") + definitions += 1 + if not definitions: + raise ValueError(f"{name}:{entry['comment_line']}: empty sense-code block") + + +def block_end(code, start, name): + """Bound a named aggregate or array initializer, never a function body.""" + text = "\n".join(code[start:]) + opening = text.find("{") + prefix = text[:opening].strip() if opening >= 0 else "" + aggregate = AGGREGATE.fullmatch(prefix) + array = ARRAY.fullmatch(prefix) + if not (array or (aggregate and (aggregate[1] or aggregate[3]))): + raise ValueError(f"{name}:{start + 1}: ignore-block requires a named " + "struct/union/enum definition or array initializer") + target = f"{aggregate[2]} {aggregate[3]}" if aggregate else array[1] + stack = [] + pairs = {")": "(", "]": "[", "}": "{"} + for offset in range(opening, len(text)): + char = text[offset] + if char in {"\0", "#"}: + raise ValueError(f"{name}:{start + 1}: incomplete or preprocessed annotated block; " + "use a smaller exception or complete source context") + if char in "([{": + stack.append(char) + elif char in ")]}": + if not stack or stack.pop() != pairs[char]: + break + if not stack: + suffix = (r"([A-Za-z_]\w*)\s*;" + if aggregate and aggregate[1] else ";") + tail = re.match(r"\s*" + ATTRIBUTES + suffix, text[offset + 1:]) + if not tail: + break + if aggregate and aggregate[1]: + target = f"typedef {tail[1]}" + end = offset + 1 + tail.end() + # A line-based diagnostic must not include a second declaration. + if text[end:].split("\n", 1)[0].strip(): + break + return start + text[:end].count("\n") + 1, target + raise ValueError(f"{name}:{start + 1}: incomplete or unsupported annotated block") + + +def source_exceptions(source, name): + """Reject malformed markers; strings and unrelated comments are not markers.""" + lines = source.split("\n") + tokens = list(TOKEN.finditer(source)) + comments = {source.count("\n", 0, token.start()): token + for token in tokens if token[0].startswith(("/*", "//"))} + code = TOKEN.sub(lambda m: re.sub(r"[^\n]", " ", m[0]), source).split("\n") + result, opened = [], {} + for token_index, token in enumerate(tokens): + if not token[0].startswith(("/*", "//")) or not any( + marker in token[0] for marker in ("CHECKPATCH:", "checkpatch-suppress")): + continue + line = source.count("\n", 0, token.start()) + 1 + comment_end = line + token[0].count("\n") + native_style = "checkpatch-suppress" in token[0] + # Wrapped comments keep reasons readable even beside deeply indented + # arguments. The complete comment must still occupy its own lines. + text = "/* " + " ".join(re.sub(r"^\s*\* ?", "", row).strip() + for row in token[0][2:-2].splitlines()).strip() + " */" + marker = (SUPPRESSION if native_style else MARKER).fullmatch(text) + if (not token[0].startswith("/*") or not token[0].endswith("*/") or not marker + or "\n".join(lines[line - 1:comment_end]).strip() != token[0] + or (line > 1 and lines[line - 2].rstrip().endswith("\\"))): + raise ValueError(f"{name}:{line}: expected a standalone " + "checkpatch-suppress[-begin|-end|-file|-macro] RULE ; reason comment") + if native_style: + suffix, rule, symbol, reason = marker.groups() + else: + suffix, rule, reason = marker.groups() + symbol = None + if (suffix == "-symbol") != bool(symbol) or (symbol and rule != "CAMELCASE"): + raise ValueError(f"{name}:{line}: symbol exceptions require CAMELCASE and symbolName") + if suffix == "-end": + if rule not in opened: + raise ValueError(f"{name}:{line}: unmatched suppression end") + entry = opened.pop(rule) + if line <= entry["line"] or any("\0" in row for row in + code[entry["line"] - 1:line - 1]): + raise ValueError(f"{name}:{line}: empty or incomplete suppression block") + if rule == "COMPLEX_MACRO": + validate_sense_block(source, entry, line, name) + entry.update(end_line=line - 1, end_comment_line=line) + continue + if not reason or not reason.strip(): + raise ValueError(f"{name}:{line}: suppression requires a reason after ';'") + annotation_start = line + if reason.strip() == "See the contract above.": + previous = tokens[token_index - 1] if token_index else None + if (previous is None or not previous[0].startswith("/*") or + source[previous.end():token.start()].strip() or + "checkpatch-suppress" in previous[0]): + raise ValueError(f"{name}:{line}: missing exception rationale") + reason = " ".join(re.sub(r"^\s*\* ?", "", row).strip() + for row in previous[0][2:-2].splitlines()).strip() + annotation_start = source.count("\n", 0, previous.start()) + 1 + scope = {None: "line", "-file": "file", "-block": "block", + "-begin": "block", "-macro": "macro", "-symbol": "symbol"}[suffix] + if scope == "file": + if any(row.strip() for row in code[:line - 1]): + raise ValueError(f"{name}:{line}: ignore-file must be in the file header " + "before code or preprocessor directives") + result.append({"file": name, "comment_line": line, "line": 1, + "end_line": len(lines) - int(lines[-1] in {"", "\0"}), + "scope": scope, "target": name, "rule": rule, + "reason": reason.strip(), "source": "whole file"}) + continue + target = comment_end + # Consecutive markers may explain different rules for the same construct. + comment = None + while target < len(lines) and (not code[target].strip() if native_style else + MARKER.fullmatch(lines[target].strip())): + candidate = comments.get(target) + if (native_style and scope == "line" and rule in COMMENT_RULES and candidate + and "checkpatch-suppress" not in candidate[0]): + comment = candidate + break + target += 1 + if target >= len(code) or (not code[target].strip() and comment is None) or code[target] == "\0": + raise ValueError(f"{name}:{line}: Checkpatch comment must precede source code") + macro = DEFINE.match(code[target]) if scope == "macro" or ( + not native_style and scope == "line") else None + if scope == "macro" and not macro: + raise ValueError(f"{name}:{line}: macro suppression must precede #define") + if rule == "COMPLEX_MACRO" and not macro and suffix != "-begin": + raise ValueError(f"{name}:{line}: COMPLEX_MACRO comment must precede #define") + end = target + 1 + (comment[0].count("\n") if comment else 0) + label = f"{name}:{target + 1}" + if suffix == "-block": + end, label = block_end(code, target, name) + while macro and lines[end - 1].rstrip().endswith("\\"): + end += 1 + if (end > len(lines) or lines[end - 1] == "\0" + or (end == len(lines) and not lines[end - 1])): + raise ValueError(f"{name}:{line}: incomplete annotated macro") + entry = {"file": name, "comment_line": line, "line": target + 1, + "end_line": end, "scope": "macro" if macro else scope, + "target": macro[1] if macro else label, + "rule": rule, "reason": reason.strip(), + "source": lines[target].strip()} + entry["comment_end_line"] = comment_end + if symbol: + if not re.search(r"\b" + re.escape(symbol) + r"\b", code[target]): + raise ValueError(f"{name}:{line}: annotated source does not use {symbol}") + entry["symbol"] = symbol + if rule == "PREFER_FALLTHROUGH": + # Native Checkpatch also diagnoses the rule name and its rationale. + # Account for this rule only, on the verified annotation lines. + entry["annotation_start"] = annotation_start + if macro: + entry["macro"] = macro[1] + if suffix == "-begin": + if rule in opened: + raise ValueError(f"{name}:{line}: duplicate open suppression block") + opened[rule] = entry + result.append(entry) + if opened: + entry = next(iter(opened.values())) + raise ValueError(f"{name}:{entry['comment_line']}: unterminated suppression block") + return result + + +def inventory(root, policy): + """Inspect tracked source comments, including files outside effective scope.""" + from lint_scope import git_names, in_scope + + if (root / ".git").exists(): + names = git_names(root, "ls-files", "--cached", "-z", "--", + *(":(top,literal)" + path for path in policy["source_roots"])) + else: + names = [path.relative_to(root).as_posix() for directory in policy["source_roots"] + for path in (root / directory).rglob("*") if path.is_file()] + result = [] + for name in sorted(set(names)): + path = root / name + if path.suffix not in policy["source_suffixes"] or not path.is_file(): + continue + for entry in source_exceptions(path.read_text(errors="surrogateescape"), name): + entry["selected_by_policy"] = in_scope(path, root, "checkpatch", policy=policy) + result.append(entry) + return result + + +def layout_reason(rule, name, quoted, policy): + """Apply only reviewed table forms, after source-context verification.""" + if rule == "PARENTHESIS_ALIGNMENT" and len(quoted) == 2: + opening = re.fullmatch(r"([ \t]*)([A-Za-z_]\w*)\([^\n]*,", quoted[0]) + indentation = re.match(r"[ \t]*", quoted[1])[0] + if not opening or len(indentation.expandtabs(8)) != len(opening[1].expandtabs(8)) + 8: + return None + for item in policy["macro_body_layouts"]: + if (item["macro"] == opening[2] and fnmatch.fnmatchcase(name, item["file_glob"]) + and re.fullmatch(item["first_entry_pattern"], quoted[1].lstrip())): + return item["reason"] + if rule in {"LONG_LINE", "LONG_LINE_COMMENT", "LONG_LINE_STRING"} and len(quoted) == 1: + if len(quoted[0].expandtabs(8)) <= policy["max_line_length"]: + return None + normalized = re.sub(r"[ \t]+", " ", quoted[0].strip()) + for item in policy["line_layouts"]: + if (rule == item["rule"] and fnmatch.fnmatchcase(name, item["file_glob"]) + and re.fullmatch(item["source_pattern"], normalized)): + return item["reason"] + return None + + +def effective_totals(text): + """Replace native conclusions with per-input totals after policy application.""" + lines = [] + counts = Counter() + exempt = 0 + boilerplate = { + "NOTE: For some of the reported defects, checkpatch may be able to", + " mechanically convert to the typical style using --fix or --fix-inplace.", + } + for line in text.splitlines(keepends=True): + value = line.rstrip("\n") + if TOTAL.fullmatch(value): + lines.append(line.replace("total: ", "total (before exemptions): ", 1)) + lines.append(f"total (after policy): {counts['ERROR']} errors, " + f"{counts['WARNING']} warnings, {counts['CHECK']} checks; " + f"{exempt} exempt diagnostics\n") + counts.clear() + exempt = 0 + elif value in boilerplate or re.fullmatch( + r".+ has (?:style problems, please review|no obvious style problems " + r"and is ready for submission)\.", value): + continue + else: + match = re.match(r"^(ERROR|WARNING|CHECK):", value) + if match: + counts[match[1]] += 1 + exempt += value.startswith("EXEMPT:") + lines.append(line) + return "".join(lines) + + +def apply_exceptions(report, root, sources, policy=None, *, symbol_sources=None): + """Annotate exact locations; certify success only with complete accounting.""" + if policy is None: + from analyzer_policy import load + + policy = load("checkpatch") + text = report.decode("utf-8", errors="surrogateescape") + exempt = Counter() + entries = {name: source_exceptions(source, name) for name, source in sources.items()} + symbols = [entry for name, source in (symbol_sources or sources).items() + for entry in source_exceptions(source, name) if entry.get("symbol")] + layouts = {} + + def annotate(match): + path = Path(match[3]) + if path.is_absolute(): + try: + path = path.relative_to(root) + except ValueError: + return match[0] + name = path.as_posix() + if name not in entries: + try: + name = Path(match[3]).resolve().relative_to(root).as_posix() + except ValueError: + return match[0] + line = int(match[4]) + quoted = [row[1:] for row in match[5].splitlines()] + start = line - len(quoted) if match[2] in PREVIOUS_CONTEXT else line - 1 + if name not in sources or start < 0: + return match[0] + if sources[name].split("\n")[start:start + len(quoted)] != quoted: + return match[0] + for entry in entries.get(name, []): + annotation = (match[2] == "PREFER_FALLTHROUGH" and + entry.get("annotation_start", entry["comment_line"]) <= line <= + entry.get("comment_end_line", entry["comment_line"])) + if (entry.get("symbol") or entry["rule"] != match[2] or + not (annotation or entry["line"] <= line <= entry["end_line"])): + continue + exempt[entry["rule"]] += 1 + target = f"{entry['scope']} {entry['target']}" + return ("EXEMPT" + match[0][len(match[1]):] + + f" Reason ({target}): {entry['reason']}\n") + # Match the reviewed identifier, independently of the first-use location + # chosen by Checkpatch's per-process CamelCase cache. + word = re.match(r"(?:ERROR|WARNING|CHECK):CAMELCASE: Avoid CamelCase: <([A-Za-z_]\w*)>\n", + match[0]) + if word and re.search(r"\b" + re.escape(word[1]) + r"\b", "\n".join(quoted)): + for entry in symbols: + if entry["symbol"] == word[1]: + exempt["CAMELCASE"] += 1 + return ("EXEMPT" + match[0][len(match[1]):] + + f" Reason (symbol {word[1]}, {entry['file']}:{entry['line']}): " + f"{entry['reason']}\n") + if name not in layouts: + layouts[name] = source_layouts(sources[name], name, policy) + reason = layouts[name].get((match[2], line)) or layout_reason(match[2], name, quoted, policy) + if reason: + exempt[match[2]] += 1 + return ("EXEMPT" + match[0][len(match[1]):] + + f" Reason (policy layout): {reason}\n") + return match[0] + + selected = SOURCE_DIAGNOSTIC.sub(annotate, text) + selected = effective_totals(selected) + counts = Counter(DIAGNOSTIC.findall(text)) + totals = Counter() + summaries = TOTAL.findall(text) + for errors, warnings, checks in summaries: + totals.update(ERROR=int(errors), WARNING=int(warnings), CHECK=int(checks or 0)) + # Missing/malformed summaries, unknown diagnostics and partial reports cannot + # turn a failing tool invocation into success. Stderr is checked by the caller. + accounted = bool(exempt and summaries and counts == +totals + and sum(counts.values()) == sum(exempt.values())) + return selected.encode("utf-8", errors="surrogateescape"), exempt, accounted diff --git a/scripts/style/layouts.py b/scripts/style/layouts.py new file mode 100644 index 0000000..59cf287 --- /dev/null +++ b/scripts/style/layouts.py @@ -0,0 +1,152 @@ +"""Recognize reviewed source forms, never arbitrary diagnostic text.""" + +import fnmatch +import re + +TOKEN = re.compile(r'"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|' + r'/\*.*?(?:\*/|\Z)|//(?:\\\n|[^\n])*', re.DOTALL) +PP_TOKEN = re.compile(r"\s*(defined\b|[A-Za-z_]\w*|0[xX][0-9a-fA-F]+|[0-9]+|" + r"&&|\|\||==|!=|<=|>=|>>|[()!,<>-])") +INTEGER = re.compile(r"(?:0[xX][0-9a-fA-F]+|0|[1-9][0-9]*)") +STRING = r'"(?:\\[^\n]|[^"\\\n])*"' +LOG_CALL = re.compile(r"([ \t]*)([A-Za-z_]\w*)\([ \t]*(" + STRING + + r"(?:[ \t]*" + STRING + r")*)[ \t]*(?:,|\);)[ \t]*") + + +def version_expression(text, policy): + """Allow known version comparisons, defined() guards and Boolean grouping.""" + tokens = [] + while text.strip(): + match = PP_TOKEN.match(text) + if not match: + return False + tokens.append(match[1]) + text = text[match.end():] + codes = {item["name"]: item for item in policy["code_macros"]} + integers = set(policy["integer_macros"]) + position = comparisons = 0 + + def take(expected=None): + nonlocal position + if position == len(tokens) or (expected is not None and tokens[position] != expected): + raise ValueError("unexpected version-expression token") + value = tokens[position] + position += 1 + return value + + def accept(value): + if position < len(tokens) and tokens[position] == value: + take() + return True + return False + + def integer(): + if not INTEGER.fullmatch(take()): + raise ValueError("expected an integer litera... [truncated message content] |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:26:02
|
Commit: f5983f8 GitHub URL: https://github.com/SCST-project/scst/commit/f5983f85b528a247dc4ccccfe7762c94d7d4d34f Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- scripts: Remove Checkpatch from kernel regression CI The analyzer workflow checks source style independently of kernel compatibility builds. Stop running each downloaded kernel's Checkpatch on the generated SCST patch, and remove its separate diagnostic summary and filters. Patch generation, application and compilation stay intact. Remove the obsolete -nc option from the regression runner, kernel matrix parser, regression workflow and nightly entries. Preserve every kernel version and all remaining build options. Update the regression workflow documentation and kernel-update instructions in the same patch. Modified Paths: -------------- .agents/skills/scst-kernel-update/SKILL.md | 5 +- .github/workflows/run_regression_tests.yaml | 2 +- CONTRIBUTING.md | 2 +- nightly/conf/nightly.conf | 198 +++++++-------- scripts/README.md | 8 +- scripts/kernel/kernel-matrix | 1 - scripts/kernel/run-regression-tests | 50 ---- 7 files changed, 107 insertions(+), 159 deletions(-) =================================================================== diff --git a/.agents/skills/scst-kernel-update/SKILL.md b/.agents/skills/scst-kernel-update/SKILL.md index d44e093..0da30ae 100644 --- a/.agents/skills/scst-kernel-update/SKILL.md +++ b/.agents/skills/scst-kernel-update/SKILL.md @@ -79,9 +79,8 @@ requests suffice; do not download large packages just to check availability. ## Apply and validate - Update each existing series to its newest confirmed published version. - Keep options (`-nc`, `-ns`, etc.) and ordering. When advancing the upstream - head, preserve the repository's convention: the new head has full nightly - checks and the previous head becomes a normal `-nc` entry. + Keep the supported options (`-4`, `-f`, `-u`, `-p`) and ordering. Static + analyzers run separately from kernel compatibility builds. - Add a new upstream series when the request covers that release. Newly discovered distribution minors, OL majors, and UEK generations are reported separately; adding them requires a separate support change. diff --git a/.github/workflows/run_regression_tests.yaml b/.github/workflows/run_regression_tests.yaml index d0fe70f..5e4a5b6 100644 --- a/.github/workflows/run_regression_tests.yaml +++ b/.github/workflows/run_regression_tests.yaml @@ -57,7 +57,7 @@ jobs: workdir="/tmp/scst-${version}" out="output.txt" - ./scripts/kernel/run-regression-tests -l -q -d "${workdir}" "${version}-nc" | tee "${out}" + ./scripts/kernel/run-regression-tests -l -q -d "${workdir}" "${version}" | tee "${out}" if ! grep -q "Compiling the patched kernel" "${out}"; then echo "::error title=Regression tests::run-regression-tests failed" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 343e87d..9d9605c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -153,7 +153,7 @@ in `.github/workflows/ci.yml` and `.github/workflows/coverity.yml`. in the [scripts guide](scripts/README.md#sparse-and-smatch). `scripts/kernel/run-regression-tests` checks kernel compatibility through -compilation and checkpatch. It downloads or prepares kernel trees and is +compilation. It downloads or prepares kernel trees and is separate from the analyzer targets above. The nightly support matrix is `ABT_KERNELS` in `nightly/conf/nightly.conf`; CI exercises a subset in `.github/workflows/run_regression_tests.yaml`. diff --git a/nightly/conf/nightly.conf b/nightly/conf/nightly.conf index 535e4e8..c95f914 100644 --- a/nightly/conf/nightly.conf +++ b/nightly/conf/nightly.conf @@ -4,103 +4,103 @@ ABT_DETAILS="x86_64" ABT_JOBS=5 ABT_KERNELS=" \ 7.3 \ -7.2.11-nc \ -7.1.13-nc \ -7.0.14-nc \ -6.19.14-nc \ -6.18.57-nc \ -6.17.13-nc \ -6.16.12-nc \ -6.15.11-nc \ -6.14.11-nc \ -6.13.12-nc \ -6.12.113-nc \ -6.11.11-nc \ -6.10.14-nc \ -6.9.12-nc \ -6.8.12-nc \ -6.7.12-nc \ -6.6.159-nc \ -6.5.13-nc \ -6.4.16-nc \ -6.3.13-nc \ -6.2.16-nc \ -6.1.190-nc \ -6.0.19-nc \ -5.19.17-nc \ -5.18.19-nc \ -5.17.15-nc \ -5.16.20-nc \ -5.15.223-nc \ -5.14.21-nc \ -5.13.19-nc \ -5.12.19-nc \ -5.11.22-nc \ -5.10.272-nc \ -5.9.16-nc \ -5.8.18-nc \ -5.7.19-nc \ -5.6.19-nc \ -5.5.19-nc \ -5.4.302-nc \ -5.3.18-nc \ -5.2.21-nc \ -5.1.21-nc \ -5.0.21-nc \ -4.20.17-nc \ -4.19.325-nc \ -4.18.20-nc \ -4.17.19-nc \ -4.16.18-nc \ -4.15.18-nc \ -4.14.336-nc \ -4.13.16-nc \ -4.12.14-nc \ -4.11.12-nc \ -4.10.17-nc \ -4.9.337-nc \ -4.8.17-nc \ -4.7.10-nc \ -4.6.7-nc \ -4.5.7-nc \ -4.4.302-nc \ -4.3.6-nc \ -4.2.8-nc \ -4.1.52-nc \ -4.0.9-nc \ -3.19.8-nc \ -3.18.140-nc \ -6.12.0-211.66.1.el10_2^Rocky^10.2-nc \ -6.12.0-124.56.1.el10_1^Rocky^10.1-nc \ -5.14.0-687.58.1.el9_8^Rocky^9.8-nc \ -5.14.0-611.55.1.el9_7^Rocky^9.7-nc \ -4.18.0-553.174.1.el8_10^Rocky^8.10-nc \ -6.12.0-55.43.1.el10_0^AlmaLinux^10.0-nc \ -5.14.0-570.62.1.el9_6^AlmaLinux^9.6-nc \ -5.14.0-503.40.1.el9_5^AlmaLinux^9.5-nc \ -5.14.0-427.42.1.el9_4^AlmaLinux^9.4-nc \ -5.14.0-362.24.2.el9_3^AlmaLinux^9.3-nc \ -5.14.0-284.30.1.el9_2^AlmaLinux^9.2-nc \ -5.14.0-162.23.1.el9_1^AlmaLinux^9.1-nc \ -5.14.0-70.30.1.el9_0^AlmaLinux^9.0-nc \ -4.18.0-513.24.1.el8_9^AlmaLinux^8.9-nc \ -4.18.0-477.27.2.el8_8^AlmaLinux^8.8-nc \ -4.18.0-425.19.2.el8_7^AlmaLinux^8.7-nc \ -4.18.0-372.32.1.el8_6^AlmaLinux^8.6-nc \ -4.18.0-348.23.1.el8_5^AlmaLinux^8.5-nc \ -4.18.0-305.25.1.el8_4^AlmaLinux^8.4-nc \ -4.18.0-240.22.1.el8_3^AlmaLinux^8.3-nc \ -4.18.0-193.28.1.el8_2^CentOS^8.2.2004-nc \ -4.18.0-147.8.1.el8_1^CentOS^8.1.1911-nc \ -4.18.0-80.11.2.el8_0^CentOS^8.0.1905-nc \ -3.10.0-1160.118.1.el7^CentOS^7.9.2009-nc \ -3.10.0-1127.19.1.el7^CentOS^7.8.2003-nc \ -3.10.0-1062.18.1.el7^CentOS^7.7.1908-nc \ -3.10.0-957.27.2.el7^CentOS^7.6.1810-nc \ -3.10.0-862.14.4.el7^CentOS^7.5.1804-nc \ -6.12.0-207.111.5.4.el10uek^UEK^10-nc \ -5.15.0-325.221.6.4.el9uek^UEK^9-nc \ -5.4.17-2136.360.3.1.el8uek^UEK^8-nc \ -4.14.35-2047.543.3.1.el7uek^UEK^7-nc \ -4.1.12-124.93.1.el7uek^UEK^7-nc \ +7.2.11 \ +7.1.13 \ +7.0.14 \ +6.19.14 \ +6.18.57 \ +6.17.13 \ +6.16.12 \ +6.15.11 \ +6.14.11 \ +6.13.12 \ +6.12.113 \ +6.11.11 \ +6.10.14 \ +6.9.12 \ +6.8.12 \ +6.7.12 \ +6.6.159 \ +6.5.13 \ +6.4.16 \ +6.3.13 \ +6.2.16 \ +6.1.190 \ +6.0.19 \ +5.19.17 \ +5.18.19 \ +5.17.15 \ +5.16.20 \ +5.15.223 \ +5.14.21 \ +5.13.19 \ +5.12.19 \ +5.11.22 \ +5.10.272 \ +5.9.16 \ +5.8.18 \ +5.7.19 \ +5.6.19 \ +5.5.19 \ +5.4.302 \ +5.3.18 \ +5.2.21 \ +5.1.21 \ +5.0.21 \ +4.20.17 \ +4.19.325 \ +4.18.20 \ +4.17.19 \ +4.16.18 \ +4.15.18 \ +4.14.336 \ +4.13.16 \ +4.12.14 \ +4.11.12 \ +4.10.17 \ +4.9.337 \ +4.8.17 \ +4.7.10 \ +4.6.7 \ +4.5.7 \ +4.4.302 \ +4.3.6 \ +4.2.8 \ +4.1.52 \ +4.0.9 \ +3.19.8 \ +3.18.140 \ +6.12.0-211.66.1.el10_2^Rocky^10.2 \ +6.12.0-124.56.1.el10_1^Rocky^10.1 \ +5.14.0-687.58.1.el9_8^Rocky^9.8 \ +5.14.0-611.55.1.el9_7^Rocky^9.7 \ +4.18.0-553.174.1.el8_10^Rocky^8.10 \ +6.12.0-55.43.1.el10_0^AlmaLinux^10.0 \ +5.14.0-570.62.1.el9_6^AlmaLinux^9.6 \ +5.14.0-503.40.1.el9_5^AlmaLinux^9.5 \ +5.14.0-427.42.1.el9_4^AlmaLinux^9.4 \ +5.14.0-362.24.2.el9_3^AlmaLinux^9.3 \ +5.14.0-284.30.1.el9_2^AlmaLinux^9.2 \ +5.14.0-162.23.1.el9_1^AlmaLinux^9.1 \ +5.14.0-70.30.1.el9_0^AlmaLinux^9.0 \ +4.18.0-513.24.1.el8_9^AlmaLinux^8.9 \ +4.18.0-477.27.2.el8_8^AlmaLinux^8.8 \ +4.18.0-425.19.2.el8_7^AlmaLinux^8.7 \ +4.18.0-372.32.1.el8_6^AlmaLinux^8.6 \ +4.18.0-348.23.1.el8_5^AlmaLinux^8.5 \ +4.18.0-305.25.1.el8_4^AlmaLinux^8.4 \ +4.18.0-240.22.1.el8_3^AlmaLinux^8.3 \ +4.18.0-193.28.1.el8_2^CentOS^8.2.2004 \ +4.18.0-147.8.1.el8_1^CentOS^8.1.1911 \ +4.18.0-80.11.2.el8_0^CentOS^8.0.1905 \ +3.10.0-1160.118.1.el7^CentOS^7.9.2009 \ +3.10.0-1127.19.1.el7^CentOS^7.8.2003 \ +3.10.0-1062.18.1.el7^CentOS^7.7.1908 \ +3.10.0-957.27.2.el7^CentOS^7.6.1810 \ +3.10.0-862.14.4.el7^CentOS^7.5.1804 \ +6.12.0-207.111.5.4.el10uek^UEK^10 \ +5.15.0-325.221.6.4.el9uek^UEK^9 \ +5.4.17-2136.360.3.1.el8uek^UEK^8 \ +4.14.35-2047.543.3.1.el7uek^UEK^7 \ +4.1.12-124.93.1.el7uek^UEK^7 \ " diff --git a/scripts/README.md b/scripts/README.md index ba5ee58..17aefc8 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -31,10 +31,10 @@ generation and source inventory use the requested or current source directory. Module Makefiles invoke `sign-modules` from the directory containing modules. Consult each script's argument handling before invoking it. -`kernel/run-regression-tests` prepares kernel trees and runs compilation and -checkpatch according to its options. The maintained kernel -matrix is `ABT_KERNELS` in `nightly/conf/nightly.conf`; the CI subset is selected -through `kernel/kernel-matrix` and `.github/kernel-matrix.conf`. +`kernel/run-regression-tests` prepares kernel trees and runs compatibility +builds. Static analyzers have separate Make targets and CI jobs. The maintained +kernel matrix is `ABT_KERNELS` in `nightly/conf/nightly.conf`; the CI subset is +selected through `kernel/kernel-matrix` and `.github/kernel-matrix.conf`. `kernel/qla2xxx.py` tracks upstream QLogic commits, compares committed Linux and SCST driver trees, audits residual differences with an optional kernel diff --git a/scripts/kernel/kernel-matrix b/scripts/kernel/kernel-matrix index 31c2b03..8907559 100644 --- a/scripts/kernel/kernel-matrix +++ b/scripts/kernel/kernel-matrix @@ -27,7 +27,6 @@ strip_kernel_options() { while true; do case "${stripped_kernel}" in - *-nc) stripped_kernel="${stripped_kernel%-nc}" ;; *-4) stripped_kernel="${stripped_kernel%-4}" ;; *-f) stripped_kernel="${stripped_kernel%-f}" ;; *-u) stripped_kernel="${stripped_kernel%-u}" ;; diff --git a/scripts/kernel/run-regression-tests b/scripts/kernel/run-regression-tests index b2251df..ec20021 100755 --- a/scripts/kernel/run-regression-tests +++ b/scripts/kernel/run-regression-tests @@ -34,7 +34,6 @@ # download it. # - Convert the SCST source code into a kernel patch. # - Extract the kernel sources. -# - Run checkpatch on the SCST kernel patch. # - Apply the SCST kernel patch to the kernel tree. # - Run 'make allmodconfig'. # - Run 'make headers_check'. @@ -246,50 +245,6 @@ function generate_kernel_patch { "${scriptsdir}"/generate-kernel-patch "${driver_options[@]}" -p "${outputdir}/${patchdir}" "$2" "$1" } -# Run checkpatch on the generated kernel patch. Assumes that there is a -# vanilla kernel tree present in directory "${outputdir}/linux-$1", and leaves -# this kernel tree clean. -function run_checkpatch { - local kver plevel errors warnings - local outputfile="${outputdir}/checkpatch-$1-output.txt" - local patchfile="${outputdir}/scst-$1-kernel.patch" - - kver="$(kernel_version "$1")" - plevel="$(patchlevel "$1")" - if [ -e "${outputdir}/linux-$1/scripts/checkpatch.pl" ]; then - if [ "${multiple_patches}" = "false" ]; then - echo "Running checkpatch on the SCST kernel patch ..." - ( cd "${outputdir}/linux-$1" \ - && scripts/checkpatch.pl --no-tree --no-signoff --strict - < "${patchfile}" &> "${outputfile}") - else - echo "Running checkpatch on the SCST kernel patches ..." - rm -f "${outputfile}" - ( cd "${outputdir}/linux-$1" \ - && for p in "${outputdir}/${patchdir}"/* - do - echo "==== $p" >>"${outputfile}" - scripts/checkpatch.pl --no-tree --no-signoff --strict - < "$p" >> "${outputfile}" 2>&1 - done - ) - fi - - errors=$(grep -c '^ERROR' "${outputfile}") - warnings=$(grep -c '^WARNING' "${outputfile}") - checks=$(grep -c '^CHECK' "${outputfile}") - - echo "${errors} errors / ${warnings} warnings / ${checks} checks." - - grep -E '^WARNING|^ERROR|^CHECK' "${outputfile}" | - sort | - grep -v 'WARNING: missing space after return type' | - sed 's/^CHECK: Avoid CamelCase:.*/CHECK: Avoid CamelCase/' | - uniq -c - else - echo "Skipping checkpatch step for kernel $1." - fi - return 0 -} - function patch_and_configure_kernel { local kver kver="$(kernel_version "$1")" @@ -595,7 +550,6 @@ do full_check="false" generate_kernel_patch_options="" - run_checkpatch="true" ipv6="true" while true; do kv_without_opt="${kv%-?}" @@ -606,7 +560,6 @@ do case "${kopt}" in '-4') ipv6="false";; '-f') full_check="true";; - '-nc') run_checkpatch="false";; '-u') generate_kernel_patch_options="-u";; '-p') multiple_patches="true";; *) break;; @@ -625,9 +578,6 @@ do continue fi k="${k/^*}" - if [ "${run_checkpatch}" = "true" ]; then - run_checkpatch "$k" - fi patch_and_configure_kernel "$k" || continue case "$k" in 3.10.0-*) |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:25:43
|
Commit: cf0976c GitHub URL: https://github.com/SCST-project/scst/commit/cf0976c628ab3bda5c80308c9e0a3d56b32ddaa4 Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- build: Export configured kernel and userspace compiler commands Provide make compile-commands as a shared compilation database for tools and editors. Read actual Kbuild compiler commands from .cmd files and check them against fresh capture records, rather than passing Sparse-specific CHECKFLAGS to a C compiler. Record userspace recipes through the same compile_c expansion used for normal objects, without rebuilding executables. Keep the collector out of ordinary CLI prerequisites so builds need no Python tooling. Retain original commands and build evidence, require complete capture, and publish the database atomically under the shared build lock. The export includes configured sources outside analyzer policy; consumers apply their own scope. Add isolated collector and Make recipe fixtures. Target analysis at the current CI kernel instead of supporting legacy Kbuild layouts. Reject CHECK records whose cwd is the kernel build tree before reading its unrelated modules.order. Keep module-build support independent of this analyzer requirement and cover the rejection with an isolated inventory fixture. Modified Paths: -------------- .gitignore | 2 + Makefile | 16 +- iscsi-scst/usr/Makefile | 9 +- scripts/README.md | 5 + scripts/compile_commands.mk | 9 + scripts/compile_commands.py | 191 +++++++++++++++ scripts/tests/test_compile_commands.py | 131 ++++++++++ usr/events/Makefile | 9 +- usr/fileio/Makefile | 9 +- usr/stpgd/Makefile | 9 +- 10 files changed, 385 insertions(+), 5 deletions(-) =================================================================== diff --git a/.gitignore b/.gitignore index a5e0ae9..2856bd1 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,5 @@ srpt/conftest/*/result-*.txt TAGS usr/fileio/fileio_tgt usr/stpgd/stpgd + +/compile_commands.json diff --git a/Makefile b/Makefile index b9f8470..eb408ba 100644 --- a/Makefile +++ b/Makefile @@ -171,6 +171,8 @@ help: ' sparse, smatch analyze configured modules through Kbuild' \ ' coccicheck run kernel Coccinelle report rules' \ ' cppcheck analyze fresh kernel and userspace build contexts' \ + ' compile-commands export configured compiler commands for tools/editors' \ + ' COMPILE_COMMANDS=path database output (default: compile_commands.json)' \ ' checkpatch check C source/header style, including KUnit' \ ' scs_lint check SCST code style rules (doc/scs.md)' \ ' lint-test test shared analyzer tooling (no modules)' \ @@ -293,7 +295,19 @@ scs_lint: scs-lint-test: @uv run --no-project scripts/scs_lint/test_scs_lint.py -.PHONY: cppcheck lint-userspace +.PHONY: compile-commands compile-commands-cli cppcheck lint-userspace +COMPILE_COMMANDS ?= $(CURDIR)/compile_commands.json +compile-commands: export SCST_LINT_KDIR := $(KDIR) +compile-commands: + +@$(PYTHON) -B scripts/compile_commands.py --output "$(COMPILE_COMMANDS)" + +compile-commands-cli: + +$(MAKE) -C scst/src ../include/scst_itf_ver.h + +$(MAKE) -C iscsi-scst/usr compile-commands + +$(MAKE) -C usr/fileio compile-commands + +$(MAKE) -C usr/stpgd compile-commands + +$(MAKE) -C usr/events compile-commands + cppcheck: export SCST_LINT_KDIR := $(KDIR) cppcheck: export SCST_LINT_CC := $(CC) cppcheck: diff --git a/iscsi-scst/usr/Makefile b/iscsi-scst/usr/Makefile index a7084dd..34f6e46 100644 --- a/iscsi-scst/usr/Makefile +++ b/iscsi-scst/usr/Makefile @@ -56,8 +56,10 @@ ifeq (.depend_adm,$(wildcard .depend_adm)) -include .depend_adm endif +compile_c = $(CC) -c -o $(2) $(CFLAGS) $(1) + %.o: %.c Makefile - $(CC) -c -o $(@) $(CFLAGS) $(<) + $(call compile_c,$<,$@) .depend_d: $(CC) -M $(CFLAGS) $(SRCS_D) >$(@) @@ -70,3 +72,8 @@ clean: extraclean: clean rm -f *.orig *.rej + +COMMAND_SOURCES := $(sort $(SRCS_D) $(SRCS_ADM)) +ifneq ($(filter compile-commands,$(MAKECMDGOALS)),) +include ../../scripts/compile_commands.mk +endif diff --git a/scripts/README.md b/scripts/README.md index 31a6b4b..ba5ee58 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -66,6 +66,11 @@ committing; sourced libraries, POSIX shell scripts, and callers outside ## Shared analyzer source scope +Kernel-based analysis targets the current kernel selected in +[`ci/kernel.env`](ci/kernel.env). Older kernels remain supported for SCST builds, +but are outside analyzer compatibility support. Compilation database export +requires the current per-module Kbuild layout. + `lint_scope.py` reads [policy/common.json](policy/common.json) for full and explicit-file selection. The loader rejects invalid or missing policy; there are no environment-based extra exclusions. Existing checkpatch wrappers diff --git a/scripts/compile_commands.mk b/scripts/compile_commands.mk new file mode 100644 index 0000000..1461ac0 --- /dev/null +++ b/scripts/compile_commands.mk @@ -0,0 +1,9 @@ +# Record the same compile_c recipe used for objects, without compiling CLI code. +PYTHON ?= python3 +.PHONY: compile-commands $(COMMAND_SOURCES:.c=.compile-command) +compile-commands: $(COMMAND_SOURCES:.c=.compile-command) + +$(COMMAND_SOURCES:.c=.compile-command): %.compile-command: %.c + @test -n "$(COMPILE_COMMANDS_DIR)" || { echo "Use make compile-commands at the repository root" >&2; exit 1; } + @$(PYTHON) ../../scripts/compile_commands.py record "$(COMPILE_COMMANDS_DIR)" -- \ + $(call compile_c,$<,$(<:.c=.o)) diff --git a/scripts/compile_commands.py b/scripts/compile_commands.py new file mode 100644 index 0000000..7a405c3 --- /dev/null +++ b/scripts/compile_commands.py @@ -0,0 +1,191 @@ +#!/usr/bin/env python3 +"""Export real compiler commands for SCST and Cppcheck.""" + +import argparse +from collections import Counter +import json +import os +from pathlib import Path +import shlex +import subprocess +import sys +import tempfile + +sys.dont_write_bytecode = True +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "scripts")) +from lint_common import entrypoint, run, show_log # noqa: E402 +from lint_kbuild import build_lock, collect as collect_checks, unchecked_invocations # noqa: E402 + + +def write_json(path, value): + path.parent.mkdir(parents=True, exist_ok=True) + with tempfile.NamedTemporaryFile(mode="w", dir=path.parent, delete=False) as stream: + temporary = Path(stream.name) + json.dump(value, stream, indent=2) + stream.write("\n") + temporary.replace(path) + + +def source_files(arguments, profile, root): + if profile == "kernel": + candidates = arguments[-1:] + elif "-c" in arguments: + candidates = [arg for arg in arguments if arg.endswith(".c") and not arg.startswith("-")] + else: + return [] + return [path for arg in candidates if (path := Path(arg).resolve()).is_file() + and path.is_relative_to(root) and not path.name.endswith(".mod.c")] + + +def record(directory, arguments, profile): + for source in source_files(arguments, profile, ROOT): + with tempfile.NamedTemporaryFile(dir=directory, suffix=".json", delete=False) as stream: + path = Path(stream.name) + entry = {"directory": str(Path.cwd()), "file": str(source), + "arguments": arguments, "state": "started", "returncode": 2} + write_json(path, entry) + entry.update(state="complete", returncode=0) + write_json(path, entry) + + +def load_records(directory): + records = [json.loads(path.read_text()) for path in sorted(directory.glob("*.json"))] + if not records: + raise ValueError(f"No compilation records: {directory}") + for row in records: + if (row.get("state") != "complete" or row.get("returncode") != 0 or + not Path(row["directory"]).is_absolute() or not Path(row["file"]).is_absolute() or + not row.get("arguments")): + raise ValueError(f"Unfinished or invalid compilation record in {directory}") + return records + + +def read_database(path, root): + entries = json.loads(path.read_text()) + if not isinstance(entries, list) or not entries: + raise ValueError(f"Empty or invalid compilation database: {path}") + result = [] + for entry in entries: + directory = Path(entry["directory"]) + source = (directory / entry["file"]).resolve() + if (not directory.is_absolute() or not source.is_file() or + not source.is_relative_to(root) or source.suffix != ".c" or + source.name.endswith(".mod.c")): + raise ValueError(f"Invalid compiler input in {path}: {source}") + args = entry.get("arguments") or shlex.split(entry.get("command", "")) + if not args: + raise ValueError(f"Missing compiler command in {path}: {source}") + result.append({"directory": str(directory), "file": str(source), "arguments": args}) + return result + + +def module_database(root, checks, directory, log): + """Use Kbuild's own .cmd reader, retaining each CHECK's actual compiler cwd.""" + kernel = Path(os.environ.get("SCST_LINT_KDIR") or os.environ.get("KDIR") or + f"/lib/modules/{os.environ.get('KVER') or os.uname().release}/build").resolve() + generator = kernel / "scripts/clang-tools/gen_compile_commands.py" + if not generator.is_file(): + raise ValueError(f"Kernel compilation database generator not found: {generator}") + entries = [] + for index, cwd in enumerate(sorted({row["directory"] for row in checks})): + if Path(cwd).resolve() == kernel: + raise ValueError("Legacy external-module Kbuild layout is unsupported; use the current " + "analysis kernel selected in scripts/ci/kernel.env") + output = directory / f"kernel-{index}.json" + # Match Kbuild's compile_commands.json target: modules.order and .mod + # enumerate current objects, excluding stale .cmd files from old configs. + order = Path(cwd) / "modules.order" + if not order.is_file(): + raise ValueError(f"Kbuild module inventory not found: {order}") + command = [sys.executable, str(generator), "-d", cwd, "-o", str(output), str(order)] + invocation = directory / f"kernel-{index}.invocation.json" + evidence = {"command": command, "directory": cwd, "state": "started", "status": None} + write_json(invocation, evidence) + with log.open("ab") as stream: + status = run(command, cwd=cwd, stdout=stream, stderr=subprocess.STDOUT).returncode + write_json(invocation, dict(evidence, state="complete", status=status)) + if status: + raise ValueError(f"Kbuild compiler database export failed: {log}") + entries.extend(read_database(output, root)) + expected, actual = Counter(row["file"] for row in checks), Counter(row["file"] for row in entries) + if actual != expected: + raise ValueError(f"Incomplete compiler database: missing={list((expected - actual).elements())} " + f"unexpected={list((actual - expected).elements())}") + return entries + + +def collect(root, output, *, log=None, context=None, locked=False): + """Publish one database only after fresh kernel and CLI inventories complete.""" + if not locked: + with build_lock(root): + return collect(root, output, log=log, context=context, locked=True) + output = output.resolve() + cache = root / ".cache/lint/compile-commands" + cache.mkdir(parents=True, exist_ok=True) + directory = Path(tempfile.mkdtemp(prefix="run-", dir=cache)) + checks, cli = directory / "checks", directory / "cli" + checks.mkdir() + cli.mkdir() + log = log or directory / "build.log" + manifest = directory / "context.json" + result = {"state": "started", "directory": str(directory), "kernel_make_status": None, + "userspace_make_status": None, "inputs": [], "failures": [], "log": str(log)} + write_json(manifest, result) + if context: + write_json(context, result) + show_log(log, "Compilation database build log") + try: + checker = [sys.executable, str(Path(__file__).resolve()), + "record-check", str(checks)] + result["kernel_make_status"], _ = collect_checks( + root, "compile-commands", checks, log, checker=checker, checkflags="") + if result["kernel_make_status"]: + raise ValueError(f"Compilation database build failed: {log}") + records = load_records(checks) + sources = {root / os.fsdecode(name) for name in subprocess.check_output( + ["git", "-C", str(root), "ls-files", "-z", "--", "*.c"]).split(b"\0") if name} + missing = unchecked_invocations(root, "common", log, records, source_inputs=sources) + if missing: + raise ValueError(f"Unrecorded Kbuild CHECK invocations: {missing}") + entries = module_database(root, records, directory, log) + command = ["make", "--no-silent", "-C", str(root), "compile-commands-cli", + "COMPILE_COMMANDS_DIR=" + str(cli)] + with log.open("ab") as stream: + result["userspace_make_status"] = run(command, stdout=stream, stderr=subprocess.STDOUT, + progress="CLI compiler command export").returncode + if result["userspace_make_status"]: + raise ValueError(f"CLI compiler command export failed: {log}") + entries += [{key: row[key] for key in ("directory", "file", "arguments")} + for row in load_records(cli)] + entries.sort(key=lambda row: (row["file"], row["directory"])) + write_json(output, entries) + result.update(state="complete", total_commands=len(entries), + inputs=sorted({row["file"] for row in entries})) + print(f"Compilation database: {len(entries)} C commands; {output}", flush=True) + return result + except BaseException as error: + result.update(state="failed", failures=[str(error) or type(error).__name__]) + raise + finally: + write_json(manifest, result) + if context: + write_json(context, result) + + +def main(): + if len(sys.argv) > 1 and sys.argv[1] in {"record", "record-check"}: + arguments = sys.argv[3:] + if arguments[:1] == ["--"]: + arguments = arguments[1:] + record(Path(sys.argv[2]), arguments, "kernel" if sys.argv[1] == "record-check" else "userspace") + return 0 + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--output", type=Path, default=ROOT / "compile_commands.json") + args = parser.parse_args() + collect(ROOT, args.output) + return 0 + + +if __name__ == "__main__": + sys.exit(entrypoint(main)) diff --git a/scripts/tests/test_compile_commands.py b/scripts/tests/test_compile_commands.py new file mode 100644 index 0000000..b1cad07 --- /dev/null +++ b/scripts/tests/test_compile_commands.py @@ -0,0 +1,131 @@ +"""Shared database completeness and CLI recipe fixtures; no SCST compilation.""" + +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest +from unittest.mock import patch + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +import compile_commands as commands + + +class CompileCommandsTests(unittest.TestCase): + def setUp(self): + temporary = tempfile.TemporaryDirectory() + self.addCleanup(temporary.cleanup) + self.root = Path(temporary.name) + self.source = self.root / "scst/sample.c" + self.source.parent.mkdir() + self.source.write_text("int value;\n") + self.entry = {"directory": str(self.source.parent), "file": str(self.source), + "arguments": ["gcc", "-c", "sample.c", "-o", "sample.o"]} + self.database = self.root / "compile_commands.json" + + def test_database_rejects_invalid_sources_and_keeps_distinct_commands(self): + commands.write_json(self.database, [self.entry, dict(self.entry, arguments=[ + "gcc", "-DSECOND=1", "-c", "sample.c"])]) + self.assertEqual(len(commands.read_database(self.database, self.root)), 2) + for entry in (dict(self.entry, directory="scst"), + dict(self.entry, file="missing.c"), + dict(self.entry, arguments=[]), + dict(self.entry, file=__file__)): + with self.subTest(entry=entry): + commands.write_json(self.database, [entry]) + with self.assertRaises(ValueError): + commands.read_database(self.database, self.root) + + def test_unfinished_record_is_not_a_successful_export(self): + directory = self.root / "records" + directory.mkdir() + for state, status in (("started", 2), ("complete", 1)): + commands.write_json(directory / "record.json", + dict(self.entry, state=state, returncode=status)) + with self.assertRaisesRegex(ValueError, "Unfinished"): + commands.load_records(directory) + commands.write_json(directory / "record.json", + dict(self.entry, state="complete", returncode=0)) + self.assertEqual(len(commands.load_records(directory)), 1) + + def test_failed_build_preserves_published_database_and_records_failure(self): + self.database.write_text("previous complete database\n") + with patch.object(commands, "collect_checks", return_value=(2, [])): + with self.assertRaisesRegex(ValueError, "build failed"): + commands.collect(self.root, self.database) + self.assertEqual(self.database.read_text(), "previous complete database\n") + manifest = next((self.root / ".cache/lint/compile-commands").glob("run-*/context.json")) + result = json.loads(manifest.read_text()) + self.assertEqual(result["state"], "failed") + self.assertEqual(result["kernel_make_status"], 2) + self.assertTrue(result["failures"]) + + def test_native_database_must_match_check_inventory(self): + kernel = self.root / "kernel" + generator = kernel / "scripts/clang-tools/gen_compile_commands.py" + generator.parent.mkdir(parents=True) + generator.touch() + log = self.root / "build.log" + log.touch() + (self.source.parent / "modules.order").touch() + def generate(command, **kwargs): + output = Path(command[command.index("-o") + 1]) + commands.write_json(output, [self.entry]) + return subprocess.CompletedProcess(command, 0) + with patch.dict(os.environ, {"SCST_LINT_KDIR": str(kernel)}), \ + patch.object(commands, "run", side_effect=generate): + self.assertEqual(commands.module_database( + self.root, [self.entry], self.root, log), [self.entry]) + with self.assertRaisesRegex(ValueError, "Incomplete compiler database"): + commands.module_database(self.root, [self.entry, self.entry], self.root, log) + + def test_legacy_kernel_cwd_cannot_select_an_unrelated_module_inventory(self): + kernel = self.root / "kernel" + generator = kernel / "scripts/clang-tools/gen_compile_commands.py" + generator.parent.mkdir(parents=True) + generator.touch() + (kernel / "modules.order").touch() + with patch.dict(os.environ, {"SCST_LINT_KDIR": str(kernel)}), \ + patch.object(commands, "run") as run: + with self.assertRaisesRegex(ValueError, "Legacy external-module Kbuild layout"): + commands.module_database(self.root, [dict(self.entry, directory=str(kernel))], + self.root, self.root / "build.log") + run.assert_not_called() + + def test_cli_export_uses_real_recipe_without_invoking_compiler(self): + repository = Path(__file__).resolve().parents[2] + scripts = self.root / "scripts" + scripts.mkdir() + for name in ("compile_commands.py", "compile_commands.mk"): + shutil.copy2(repository / "scripts" / name, scripts / name) + component = self.root / "usr/fileio" + component.mkdir(parents=True) + shutil.copy2(repository / "usr/fileio/Makefile", component / "Makefile") + (component / "sample.c").touch() + records = self.root / "records" + records.mkdir() + result = subprocess.run(["make", "--no-print-directory", "-C", str(component), + "compile-commands", "SRCS_F=sample.c", "CC=compiler-must-not-run", + "LOCAL_CFLAGS=-DTEST_CONTEXT=1", "COMPILE_COMMANDS_DIR=" + str(records)], + env=dict(os.environ, PYTHONPATH=str(repository / "scripts"), PYTHONDONTWRITEBYTECODE="1"), + capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + entry, = commands.load_records(records) + self.assertEqual(entry["arguments"][0], "compiler-must-not-run") + self.assertIn("-DTEST_CONTEXT=1", entry["arguments"]) + self.assertEqual(entry["file"], str(component / "sample.c")) + self.assertFalse((component / "sample.o").exists()) + + def test_cli_cleanup_does_not_require_packaged_export_tooling(self): + repository = Path(__file__).resolve().parents[2] + for name in ("iscsi-scst/usr", "usr/fileio", "usr/stpgd", "usr/events"): + with self.subTest(component=name): + component = self.root / name + component.mkdir(parents=True, exist_ok=True) + shutil.copy2(repository / name / "Makefile", component / "Makefile") + result = subprocess.run(["make", "--no-print-directory", "-C", str(component), + "clean"], capture_output=True, text=True) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) diff --git a/usr/events/Makefile b/usr/events/Makefile index bb296ce..c03e2b3 100644 --- a/usr/events/Makefile +++ b/usr/events/Makefile @@ -52,8 +52,10 @@ endif #-include .depend_c #endif +compile_c = $(CC) -c -o $(2) $(CFLAGS) $(1) + %.o: %.c Makefile - $(CC) -c -o $(@) $(CFLAGS) $(<) + $(call compile_c,$<,$@) .depend_f: $(CC) -M $(CFLAGS) $(SRCS_F) >$(@) @@ -87,3 +89,8 @@ release-archive: ../../scripts/release/generate-release-archive events "$$(sed -n 's/^#define[[:blank:]]VERSION_STR[[:blank:]]*\"\([^\"]*\)\".*/\1/p' ../include/version.h)" .PHONY: all install uninstall clean extraclean 2release 2debug 2perf + +COMMAND_SOURCES := $(SRCS_F) +ifneq ($(filter compile-commands,$(MAKECMDGOALS)),) +include ../../scripts/compile_commands.mk +endif diff --git a/usr/fileio/Makefile b/usr/fileio/Makefile index 7fe2e49..215b56c 100644 --- a/usr/fileio/Makefile +++ b/usr/fileio/Makefile @@ -74,8 +74,10 @@ endif #-include .depend_c #endif +compile_c = $(CC) -c -o $(2) $(CFLAGS) $(1) + %.o: %.c Makefile - $(CC) -c -o $(@) $(CFLAGS) $(<) + $(call compile_c,$<,$@) .depend_f: $(CC) -M $(CFLAGS) $(SRCS_F) >$(@) @@ -109,3 +111,8 @@ release-archive: ../../scripts/release/generate-release-archive fileio_tgt "$$(sed -n 's/^#define[[:blank:]]VERSION_STR[[:blank:]]*\"\([^\"]*\)\".*/\1/p' ../include/version.h)" .PHONY: all install uninstall clean extraclean 2release 2debug 2perf + +COMMAND_SOURCES := $(SRCS_F) +ifneq ($(filter compile-commands,$(MAKECMDGOALS)),) +include ../../scripts/compile_commands.mk +endif diff --git a/usr/stpgd/Makefile b/usr/stpgd/Makefile index 206e55b..8e275fa 100644 --- a/usr/stpgd/Makefile +++ b/usr/stpgd/Makefile @@ -54,8 +54,10 @@ endif #-include .depend_c #endif +compile_c = $(CC) -c -o $(2) $(CFLAGS) $(1) + %.o: %.c Makefile - $(CC) -c -o $(@) $(CFLAGS) $(<) + $(call compile_c,$<,$@) .depend_f: $(CC) -M $(CFLAGS) $(SRCS_F) >$(@) @@ -91,3 +93,8 @@ release-archive: ../../scripts/release/generate-release-archive stpgd "$$(sed -n 's/^#define[[:blank:]]VERSION_STR[[:blank:]]*\"\([^\"]*\)\".*/\1/p' ../include/version.h)" .PHONY: all install uninstall clean extraclean 2release 2debug 2perf + +COMMAND_SOURCES := $(SRCS_F) +ifneq ($(filter compile-commands,$(MAKECMDGOALS)),) +include ../../scripts/compile_commands.mk +endif |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:24:43
|
Commit: 3acf6ab GitHub URL: https://github.com/SCST-project/scst/commit/3acf6ab456e81c87ece1bf5ed76cdac0a1d6121e Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- scripts: Preserve checker execution records and partial diagnostics Kbuild can discard a checker's exit status, and an interrupted checker can lose buffered output. Publish a started record before execution, stream native output to a retained log, then atomically publish the completed record. Require every announced CHECK to have a completed result before reporting clean analysis. Resolve relative CHECK paths against active make directories before falling back to suffixes. This avoids confusing duplicate basenames such as config.c while keeping ambiguous or missing invocations fatal. Allow capture clients to clear checker-only CHECKFLAGS explicitly. Give the shared process-group runner bounded deadlines and preserve partial output on timeout or interruption. Add a result renderer that separates active diagnostics, notes, reviewed exceptions, coverage and build messages. A pahole version notice is evidence, not a checker failure. Native records remain authoritative for exit status. Cover interrupted adapters, duplicate and missing CHECK invocations, process-group termination, output retention and report classification with isolated fixtures. Sparse and Smatch exception policy is unchanged. Serialize report replacement with a per-tool lock, separate from the Kbuild lock. Validate inherited lock descriptors and preserve Make jobserver descriptors. Keep the lock until rendering and publication finish, so another invocation cannot replace the evidence underneath it. Allow outer callers to extend cancellation grace while native process groups retain their two-second deadline. Render native exit statuses, checker activity, source findings, coverage limitations and build diagnostics separately. Group repeated inventories without changing the retained logs. Label progress as total elapsed time; per-rule durations remain distinct. Cover locks, inherited descriptors, termination escalation and report rendering with isolated fixtures. Modified Paths: -------------- scripts/analyzer_report.py | 277 +++++++++++++++ scripts/lint_common.py | 100 +++++- scripts/lint_kbuild.py | 33 +- scripts/sparse_smatch/check.py | 24 +- scripts/sparse_smatch/records.py | 9 + scripts/sparse_smatch/smp.py | 20 +- scripts/tests/test_analyzer_report.py | 257 +++++++++++++ scripts/tests/test_kbuild_driver.py | 31 +- scripts/tests/test_lint_common.py | 151 +++++++- scripts/tests/test_lint_kbuild.py | 64 +++- 10 files changed, 912 insertions(+), 54 deletions(-) =================================================================== diff --git a/scripts/analyzer_report.py b/scripts/analyzer_report.py new file mode 100644 index 0000000..1b7a60a --- /dev/null +++ b/scripts/analyzer_report.py @@ -0,0 +1,277 @@ +"""Readable Make and CI evidence; classification belongs to native analyzer drivers. + +Raw streams and machine reports remain authoritative and are never rewritten. +""" + +from collections import Counter +from functools import partial +from pathlib import Path +import json +import re + +from lint_common import report_section +from sparse_smatch.check import DIAGNOSTIC + + +def show_result(report, log): + text = render(report, log) + Path(log).with_suffix(".summary.log").write_text(text) + print(text, end="", flush=True) + +def build_diagnostics(path, *, failed=False, exclude_lines=()): + """Retain build/environment diagnostics with their nearby source context.""" + if not Path(path).is_file(): + return [] + lines = Path(path).read_text(errors="replace").splitlines() + blocks = Counter() + diagnostic = re.compile(r"\b(?:warning|error|fatal error):|undefined reference|" + r"undefined symbol|\*\*\*|Skipping BTF generation", re.IGNORECASE) + for index, line in enumerate(lines): + if line not in exclude_lines and diagnostic.search(line): + block = [line] + for following in range(index + 1, min(index + 5, len(lines))): + text = lines[following] + if (not text.startswith(" ") or diagnostic.search(text) or + re.match(r"\s+(?:CC|CHECK|LD|BTF|MODPOST|GEN)\s", text)): + break + block.append(text) + blocks[tuple(block)] += 1 + result = [] + for block, count in blocks.items(): + result.extend(block) + if count > 1: + result.append(f" Repeated {count} times; all occurrences are in the full log.") + if failed and not any(re.search(r"error:|undefined|\*\*\*", line, re.IGNORECASE) + for line in result): + result.extend(["Build failure context:", *lines[-24:]]) + return result + +LABELS = {"sparse": "Sparse", "smatch": "Smatch", "cppcheck": "Cppcheck", + "checkpatch": "Checkpatch", "coccicheck": "Coccinelle", "scs_lint": "SCS"} +SEVERITIES = ("fatal error", "error", "warning", "style", "performance", "portability", + "check", "information", "finding") + + +def group_lines(groups): + return [f"{count:7} {severity}: [{rule}]" for (severity, rule), count in sorted( + groups.items(), key=lambda item: (SEVERITIES.index(item[0][0]) + if item[0][0] in SEVERITIES else len(SEVERITIES), + -item[1], item[0][1]))] + + +def markdown_block(text): + """Keep diagnostic text literal, including embedded Markdown and HTML.""" + fence = "`" * max(3, 1 + max((len(run) for run in re.findall(r"`+", text)), default=0)) + return f"{fence}text\n{text.rstrip()}\n{fence}\n" + + +def section(title, lines, *, collapsed=False, markdown=False): + if not markdown: + return report_section(title, lines, collapsed=collapsed) + body = lines if isinstance(lines, str) else "\n".join(lines) + if collapsed: + return f"\n<details><summary>{title}</summary>\n\n{markdown_block(body)}\n</details>\n" + return f"\n**{title}**\n\n{markdown_block(body)}" + + +def render(report, log, *, include_reports=True, status=None, markdown=False): + """Format native decisions; grouping never determines the exit status.""" + tool = report["tool"] + status = report.get("exit_code", 2) if status is None else status + outcome = report.get("outcome", "incomplete") + badge = "FAIL" if status else "SKIP" if outcome == "skipped" else "PASS" + lines = [f"{LABELS[tool]}: {badge}; analysis {outcome} (exit {status})", + f"Findings: {report.get('remaining', 'unknown')} (blocking)"] + failures = list(report.get("failures", [])) + active, notices, groups, coverage, details = [], Counter(), Counter(), [], [] + macro_limits, limit_reasons, rule_details, tool_notices = Counter(), set(), [], [] + checker_details = {} + part = partial(section, markdown=markdown) + native_lines = set() + checked = report.get("checked_files", []) + units = tool in {"sparse", "smatch", "cppcheck"} + kind = "translation units (.c)" if units else "source files (.c and .h)" + coverage.append(f"Checked {kind}: {len(checked)}; " + f"including {sum('/kunit/' in path for path in checked)} KUnit " + f"{'translation units' if units else 'files'}") + if outcome == "skipped": + coverage.append("No eligible inputs; no analysis performed.") + if tool == "cppcheck": + for row in report.get("profiles", []): + coverage.append(f"{row['profile']}: complete={row['complete']}, " + f"native exit={row['native_status']}, " + f"units={row['translation_units']}") + if row.get("native_status_reason"): + coverage.append(f" Native exit explanation: {row['native_status_reason']}") + inventory = row.get("checker_inventory", {}) + inactive = [checker for checker in inventory.get("checkers", []) if not checker["active"]] + if inactive: + coverage.append(f" {row['profile']}: {len(inactive)} checkers not reported active:") + reasons = Counter(checker["reason"] for checker in inactive) + coverage.extend(f" {count} x {reason}" for reason, count in reasons.items()) + entries = [f"Cppcheck {inventory['version']}; native No entries:"] + for checker in inactive: + requirement = (f"; native require:{checker['requirements']}" + if checker["requirements"] else "") + entries.append(f"{checker['name']}: {checker['reason']}{requirement}") + checker_details.setdefault(tuple(entries), []).append(row["profile"]) + failures.extend(row.get("failures", [])) + for diagnostic in row.get("diagnostics", []): + if diagnostic.get("excluded"): + notices["outside source scope", diagnostic["excluded"]] += 1 + continue + if diagnostic.get("advisory"): + if diagnostic["id"] == "checkersReport": + coverage.append(f" {row['profile']}: {diagnostic['msg']}") + continue + notices[diagnostic["id"], diagnostic["advisory"]] += 1 + continue + groups[diagnostic["severity"], diagnostic["id"]] += 1 + locations = diagnostic.get("locations", []) or [{}] + for location in locations: + active.append(f"{location.get('file', 'native')}:{location.get('line', '0')}: " + f"{diagnostic['severity']}: {diagnostic['msg']} " + f"[{diagnostic['id']}]") + if location.get("info"): + active.append(" " + location["info"]) + details.append("Native suppression hit counts: unavailable; suppressed messages are not emitted.") + elif tool == "coccicheck": + rules = report.get("rules", []) + skipped = report.get("skipped_rules", []) + coverage.append(f"Semantic rules: {len(rules)} run; {len(skipped)} skipped without report mode") + for path in skipped: + coverage.append(f"Skipped rule: {path} (no report mode)") + for row in rules: + name = Path(row["rule"]).name + duration = (f", duration={row['duration_seconds']:.1f}s" + if "duration_seconds" in row else "") + rule_details.append(f"{name}: complete={row['complete']}, " + f"native exit={row['native_status']}, " + f"inputs={len(row['handled'])}{duration}") + failures.extend(f"{row['rule']}: {value}" for value in row.get("failures", [])) + for item in row.get("diagnostics", []): + if item.get("exception"): + notices["source exception", name] += 1 + else: + groups["finding", name] += 1 + active.append(item["native"]) + for item in row.get("coverage_limits", []): + macro_limits[item['file'], item['line'], item['name'], item['message']] += 1 + limit_reasons.add(item['reason']) + for item in row.get("tool_warnings", []): + tool_notices.append(f"{name}: {item['message']} — {item['reason']}") + definitions = {(file, line) for file, line, _, _ in macro_limits} + coverage.append(f"Non-blocking macro definition errors: {sum(macro_limits.values())} " + f"occurrences; {len(definitions)} definitions") + coverage.append("Limits: macro bodies and _Generic associations are not exhaustively " + "analyzed; no synthetic macro contexts are checked.") + elif tool == "checkpatch": + selected = Path(report.get("selected_log", log)) + if selected.is_file(): + text = selected.read_text(errors="replace") + active.extend(re.findall(r"^(?:ERROR|WARNING|CHECK):[^\n]+(?:\n(?!\n)[^\n]+)*", + text, re.MULTILINE)) + groups.update((match[1].lower(), match[2] or "unclassified") for match in re.finditer( + r"^(ERROR|WARNING|CHECK):(?:([A-Z][A-Z0-9_]*):)?", text, re.MULTILINE)) + coverage.append(f"Native completion: {report.get('complete', False)}; " + f"file reports: {len(report.get('completed_files', []))}; " + f"native exit={report.get('native_status', 'not completed')}") + if report.get("native_status") == 1: + coverage.append(f"Native exit explanation: Checkpatch reported findings; " + f"{report.get('ignored', 0)} exempted, " + f"{report.get('remaining', 0)} active.") + details.extend(f"{count:7} [{rule}]" for rule, count in sorted( + report.get("exception_counts", {}).items())) + elif tool == "scs_lint": + for item in report.get("diagnostics", []): + active.append(item["native"]) + groups["error", item["rule"]] += 1 + coverage.extend(["Rules: SCS.1", report.get("parser_runtime", "Parser runtime: unavailable")]) + else: + directory = report.get("records_directory") + if directory: + for path in sorted(Path(directory).glob("*.json")): + row = json.loads(path.read_text()) + ignored = {item["diagnostic"] for item in row["ignored"]} + for item in row["ignored"]: + notices["matched exception", item["reason"]] += 1 + native = Path(row.get("log", path.with_suffix(".log"))) + if native.is_file(): + active_context = False + for line in native.read_text(errors="replace").splitlines(): + native_lines.add(line) + if line in ignored: + active_context = False + continue + if match := DIAGNOSTIC.match(line.encode()): + active_context = True + severity = match["severity"].decode().lower() + if severity == "warn": + severity = "warning" + groups[severity, tool] += 1 + active.append(line) + elif active_context and line.startswith((" ", "\t")): + active.append(line) + elif line.strip(): + active_context = False + # Retain include-stack notes and other native output, + # but do not present them as blocking source findings. + notices["tool message", line] += 1 + if row.get("state") != "complete" or row["returncode"]: + failures.append(f"Incomplete CHECK: {path}; native exit={row['returncode']}") + coverage.append(f"Kbuild exit={report.get('make_status', 'not completed')}; " + f"translation units={report.get('translation_units', 0)}") + if not active: + active = ["No diagnostic text captured; inspect the full log." + if report.get("remaining") else "None."] + lines.extend(group_lines(groups)) + if markdown: + lines = [markdown_block("\n".join(lines))] + lines.append(part("Active diagnostics", active)) + if failures: + lines.append(part("Analysis failures", failures)) + lines.append(part("Coverage and completion", coverage)) + for entries, profiles in checker_details.items(): + lines.append(part(f"Checker inventory: {', '.join(profiles)}", [ + "Counts describe registered checker execution, not file coverage or suppression hits.", + "Native require: lists prerequisites, not the exact reason a checker was inactive.", + "Explanations do not change native activity flags or analysis status.", + *entries], collapsed=True)) + if tool_notices: + lines.append(part("Tool notices", tool_notices)) + if tool in {"sparse", "smatch", "cppcheck"}: + environment = build_diagnostics(report.get("build_log", log), + failed=outcome == "incomplete", exclude_lines=native_lines) + if environment: + btf = [line for line in environment if line.startswith("Skipping BTF generation")] + other = [line for line in environment if not line.startswith("Skipping BTF generation")] + if btf: + lines.append(f"BTF generation skipped for {len(btf)} modules; " + "build messages are separate from analyzer findings.") + lines.append(part("BTF details", btf, collapsed=True)) + if other: + lines.append(part("Build/environment messages", + ["Separate from analyzer findings:", *other])) + lines.append(f"Inline exception declarations: {len(report.get('inline_exceptions', []))} " + "(not suppression hits)") + if "ignored" in report: + lines.append(f"Matched exceptions: {report['ignored']}") + if notices: + details.extend(f"{count} x {identifier}: {reason}" + for (identifier, reason), count in notices.items()) + if details: + lines.append(part("Exception and model details", details, collapsed=True)) + if rule_details: + lines.append(part("Per-rule completion", rule_details, collapsed=True)) + if macro_limits: + lines.append(part("Macro coverage limitations", [ + *sorted(limit_reasons), + *(f"{file}:{line}: {message} [{name}] ({count} occurrences)" + for (file, line, name, message), count in sorted(macro_limits.items())), + "Original error excerpts remain in the native logs and machine report."], collapsed=True)) + if include_reports: + paths = [f"Full native log: {log}", f"Machine report: {Path(log).with_suffix('.json')}"] + if report.get("records_directory"): + paths.append(f"Per-invocation evidence: {report['records_directory']}") + lines.append(part("Reports", paths)) + return "\n".join(lines) + "\n" diff --git a/scripts/lint_common.py b/scripts/lint_common.py index 7d08c01..f144a99 100644 --- a/scripts/lint_common.py +++ b/scripts/lint_common.py @@ -2,6 +2,7 @@ import contextlib from concurrent.futures import ThreadPoolExecutor, TimeoutError as FutureTimeout +import fcntl import os import re import shlex @@ -13,12 +14,37 @@ import sys import time from pathlib import Path -PROGRESS_INTERVAL = 5 +PROGRESS_INTERVAL = 30 SPINNER_INTERVAL = 0.1 SPINNER_FRAMES = "|/-\\" VERBOSE = os.environ.get("V", "0") not in {"", "0"} +def report_section(title, lines, *, collapsed=False): + """Format report sections with optional folding in GitHub Actions.""" + body = lines if isinstance(lines, str) else "\n".join(lines) + if collapsed and os.environ.get("GITHUB_ACTIONS") == "true" and not VERBOSE: + return f"\n::group::{title}\n{body.rstrip()}\n::endgroup::\n" + return f"\n--- {title} ---\n{body.rstrip()}\n" + + +def print_phase(tool, phase): + print(f"\n{'=' * 72}\n{phase} | {tool}\n{'=' * 72}\n", flush=True) + + +def parser_runtime(): + from importlib.metadata import PackageNotFoundError, version + + packages = [] + for name in ("tree-sitter", "tree-sitter-c"): + try: + release = version(name) + except PackageNotFoundError: + release = "unknown" + packages.append(f"{name} {release}") + return f"Parser runtime: Python {sys.version.split()[0]}; " + "; ".join(packages) + + def show_log(path, label="Full log"): print(f" {label}: {Path(path).resolve()}", file=sys.stderr, flush=True) @@ -26,10 +52,11 @@ def show_log(path, label="Full log"): class Progress: """Animate only a quiet child; redirected output gets periodic plain lines.""" - def __init__(self, label, *, quiet=True): + def __init__(self, label, *, quiet=True, stream=None): self.label = label + self.stream = sys.stderr if stream is None else stream self.started = time.monotonic() - self.animated = (bool(label) and quiet and sys.stderr.isatty() + self.animated = (bool(label) and quiet and self.stream.isatty() and os.environ.get("TERM") != "dumb") self.interval = SPINNER_INTERVAL if self.animated else PROGRESS_INTERVAL self.frame = 0 @@ -37,27 +64,28 @@ class Progress: def update(self): elapsed = int(time.monotonic() - self.started) + label = self.label() if callable(self.label) else self.label if self.animated: - elapsed -= elapsed % PROGRESS_INTERVAL frame = SPINNER_FRAMES[self.frame % len(SPINNER_FRAMES)] - text = f" {frame} {self.label} {elapsed // 60:02}:{elapsed % 60:02}" + text = f" {frame} {label} {elapsed // 60:02}:{elapsed % 60:02} total" width = shutil.get_terminal_size().columns - print("\r\033[2K" + text[:max(1, width - 1)], end="", file=sys.stderr, flush=True) + print("\r\033[2K" + text[:max(1, width - 1)], end="", file=self.stream, flush=True) self.frame += 1 else: - print(f" {self.label}: running ({elapsed}s elapsed)", file=sys.stderr, flush=True) + print(f" {label}: running ({elapsed}s total elapsed)", file=self.stream, flush=True) self.visible = True def clear(self): if self.animated and self.visible: - print("\r\033[2K", end="", file=sys.stderr, flush=True) + print("\r\033[2K", end="", file=self.stream, flush=True) def finish(self, status): self.clear() if self.visible: elapsed = int(time.monotonic() - self.started) - print(f" {self.label}: finished ({elapsed}s, exit {status})", - file=sys.stderr, flush=True) + label = self.label() if callable(self.label) else self.label + print(f" {label}: finished ({elapsed}s total elapsed, exit {status})", + file=self.stream, flush=True) def jobserver_fds(env): @@ -80,16 +108,39 @@ def start(command, *, env=None, **kwargs): environment = os.environ if env is None else env if VERBOSE: print(" $ " + shlex.join(map(str, command)), file=sys.stderr, flush=True) + descriptors = set(kwargs.pop("pass_fds", ())) | set(jobserver_fds(environment)) return subprocess.Popen(command, env=environment, start_new_session=True, - pass_fds=jobserver_fds(environment), **kwargs) + pass_fds=tuple(sorted(descriptors)), **kwargs) -def stop(process): +@contextlib.contextmanager +def report_lock(root, tool): + """Serialize direct and Make runs until the parent finishes its report.""" + path = root / ".cache/lint" / f"{tool}.report.lock" + path.parent.mkdir(parents=True, exist_ok=True) + if os.environ.get("LINT_REPORT_LOCK_TOOL") == tool: + # Reuse the parent's open file description. Opening the same lock + # again would deadlock; an environment flag alone is not ownership. + try: + descriptor = int(os.environ.get("LINT_REPORT_LOCK_FD", "")) + if descriptor < 3 or not os.path.samestat(os.fstat(descriptor), path.stat()): + raise ValueError("Wrong report lock descriptor") + fcntl.flock(descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB) + except (OSError, ValueError) as error: + raise ValueError("Invalid inherited analyzer report lock") from error + yield descriptor + else: + with path.open("a") as stream: + fcntl.flock(stream, fcntl.LOCK_EX) + yield stream.fileno() + + +def stop(process, *, timeout=2): """Stop the owned process group, including children of an exited driver.""" with contextlib.suppress(ProcessLookupError): os.killpg(process.pid, signal.SIGTERM) try: - process.wait(timeout=2) + process.wait(timeout=timeout) except subprocess.TimeoutExpired: pass with contextlib.suppress(ProcessLookupError): @@ -101,12 +152,14 @@ def exit_status(returncode): return returncode if returncode >= 0 else 128 - returncode -def run(command, *, input=None, check=False, progress=None, **kwargs): +def run(command, *, input=None, check=False, progress=None, progress_stream=None, + timeout=None, cancel_timeout=2, **kwargs): if input is not None: kwargs["stdin"] = subprocess.PIPE process = start(command, **kwargs) + deadline = time.monotonic() + timeout if timeout is not None else None indicator = Progress(progress, quiet=kwargs.get("stdout") is not None - and kwargs.get("stderr") is not None) + and kwargs.get("stderr") is not None, stream=progress_stream) # Python 3.12 can stop writing pending stdin after a communicate timeout. # Keep one I/O operation running while the main thread updates progress. with ThreadPoolExecutor(max_workers=1) as executor: @@ -115,16 +168,22 @@ def run(command, *, input=None, check=False, progress=None, **kwargs): indicator.update() communication = executor.submit(process.communicate, input) while True: + remaining = deadline - time.monotonic() if deadline is not None else None + if remaining is not None and remaining <= 0: + raise subprocess.TimeoutExpired(command, timeout) + wait = indicator.interval if progress else remaining + if remaining is not None and wait is not None: + wait = min(wait, remaining) try: - stdout, stderr = communication.result( - timeout=indicator.interval if progress else None) + stdout, stderr = communication.result(timeout=wait) break except FutureTimeout: - indicator.update() + if progress: + indicator.update() except BaseException: indicator.clear() # Close the process group's pipes before joining the I/O worker. - stop(process) + stop(process, timeout=cancel_timeout) raise result = subprocess.CompletedProcess(command, exit_status(process.returncode), stdout, stderr) indicator.finish(result.returncode) @@ -168,6 +227,9 @@ def entrypoint(main): return 128 + error.signum except KeyboardInterrupt: return 130 + except subprocess.TimeoutExpired as error: + print(f"Command timed out after {error.timeout}s: {error.cmd}", file=sys.stderr) + return 2 except subprocess.CalledProcessError as error: print(f"Command failed ({error.returncode}): {error.cmd}", file=sys.stderr) return error.returncode diff --git a/scripts/lint_kbuild.py b/scripts/lint_kbuild.py index cea2cd5..838043c 100644 --- a/scripts/lint_kbuild.py +++ b/scripts/lint_kbuild.py @@ -54,13 +54,15 @@ def validate_checker(root, tool, log): raise ValueError(f"{tool} is incompatible with {probe}; module build was not started") -def collect(root, tool, directory, log, *, checker=None): +def collect(root, tool, directory, log, *, checker=None, checkflags=None): """Retain CHECK exits even when the enclosing Kbuild discards them.""" env = dict(os.environ, SCST_LINT_RECORDS=str(directory)) checker = shlex.join(checker or [sys.executable, str(root / "scripts/sparse_smatch/check.py"), tool]) command = ["make", "--no-silent", "-k", "-C", str(root), "lint-kbuild", "C=2", "V=0", "CHECK=" + checker] + if checkflags is not None: + command.append("CHECKFLAGS=" + checkflags) with log.open("ab") as output: result = run(command, env=env, stdout=output, stderr=subprocess.STDOUT, progress=f"{tool.capitalize()} Kbuild") @@ -68,21 +70,40 @@ def collect(root, tool, directory, log, *, checker=None): return result.returncode, records -def unchecked_invocations(root, tool, log, records): +def unchecked_invocations(root, tool, log, records, *, source_inputs=None): """Detect a CHECK whose adapter never managed to leave a record.""" checked = Counter(Path(row["file"]) for row in records) - sources = set(tracked_sources(root, tool)) | set(checked) + sources = set(tracked_sources(root, tool) if source_inputs is None else source_inputs) | set(checked) announced = Counter() + directories = Counter() for line in log.read_text(errors="replace").splitlines(): + directory = re.fullmatch(r"make(?:\[\d+\])?: (Entering|Leaving) directory ['`](.+)'", line) + if directory: + action, name = directory.groups() + key = Path(name).resolve() + if action == "Entering": + directories[key] += 1 + elif directories[key]: + directories[key] -= 1 + continue match = re.fullmatch(r"\s+CHECK\s+(?:\[M\]\s+)?(.+\.c)\s*", line) if not match: continue path = Path(match[1]) if path.is_absolute(): - candidates = {path.resolve()} if in_scope(path, root, tool) else set() + eligible = (in_scope(path, root, tool) if source_inputs is None + else path.resolve() in sources) + candidates = {path.resolve()} if eligible else set() else: - candidates = {source for source in sources - if source.as_posix().endswith("/" + path.as_posix())} + # Newer Kbuild prints paths relative to the module directory. + # Do not confuse them with equally named userspace files, or use + # successful records alone: that would hide a missing invocation. + candidates = {(directory / path).resolve() + for directory, active in directories.items() if active + and (directory / path).resolve() in sources} + if not candidates: + candidates = {source for source in sources + if source.as_posix().endswith("/" + path.as_posix())} if len(candidates) > 1: raise ValueError(f"ambiguous Kbuild CHECK path: {path}") announced.update(candidates) diff --git a/scripts/sparse_smatch/check.py b/scripts/sparse_smatch/check.py index 0ba0728..aa7d6f3 100644 --- a/scripts/sparse_smatch/check.py +++ b/scripts/sparse_smatch/check.py @@ -14,6 +14,7 @@ ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT / "scripts")) from lint_scope import in_scope # noqa: E402 from analyzer_policy import load_policy # noqa: E402 +from sparse_smatch.records import write_record from sparse_smatch.native import checker_command # noqa: E402 DIAGNOSTIC = re.compile( @@ -87,7 +88,7 @@ def main(): source = source.resolve() record = {"directory": str(Path.cwd()), "file": str(source), "arguments": ["cc", *arguments], "returncode": 2, - "findings": 0, "ignored": [], "errors": 0} + "findings": 0, "ignored": [], "errors": 0, "state": "started"} # Kbuild can discard CHECK's exit status. Leave a failed record even if # spawning the tool fails or this adapter is interrupted before completion. with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False, @@ -96,25 +97,26 @@ def main(): record_path = Path(output.name) command = [*checker_command(tool), *arguments[:-1], "-fmax-warnings=unlimited", arguments[-1]] record["checker_arguments"] = command - record_path.write_text(json.dumps(record)) - result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - # Parallel Kbuild output may interleave; preserve each native stream too. native_log = record_path.with_suffix(".log") - native_log.write_bytes(result.stdout) - sys.stdout.buffer.write(result.stdout) - diagnostics = [match for line in result.stdout.splitlines() + record["log"] = str(native_log) + write_record(record_path, record) + # Stream before waiting: a killed checker must leave its partial evidence. + with native_log.open("wb") as output: + result = subprocess.run(command, stdout=output, stderr=subprocess.STDOUT) + output = native_log.read_bytes() + sys.stdout.buffer.write(output) + diagnostics = [match for line in output.splitlines() if (match := DIAGNOSTIC.match(line))] headers = {rule["header"]: kernel_header(arguments, rule["header"]) for rule in policy["kernel_exceptions"]} - record.update(returncode=result.returncode, log=str(native_log), findings=len(diagnostics), + record.update(returncode=result.returncode, state="complete", findings=len(diagnostics), ignored=[entry for item in diagnostics if (entry := ignored_warning(tool, item.string, headers))], errors=sum(b"error" in item["severity"].lower() and not item["function"] - for item in diagnostics) + bool(TRUNCATED.search(result.stdout))) + for item in diagnostics) + bool(TRUNCATED.search(output))) # Smatch's "file:line function() error:" is a source finding; frontend # "file:line:column: error:" means parsing failed, even with a zero exit. - with record_path.open("w") as output: - json.dump(record, output) + write_record(record_path, record) return result.returncode if result.returncode >= 0 else 128 - result.returncode diff --git a/scripts/sparse_smatch/records.py b/scripts/sparse_smatch/records.py new file mode 100644 index 0000000..9b39d8c --- /dev/null +++ b/scripts/sparse_smatch/records.py @@ -0,0 +1,9 @@ +"""Atomically publish checker state.""" + +import json + + +def write_record(path, record): + temporary = path.with_suffix(".tmp") + temporary.write_text(json.dumps(record, indent=2) + "\n") + temporary.replace(path) diff --git a/scripts/sparse_smatch/smp.py b/scripts/sparse_smatch/smp.py index a8e28e9..863447b 100644 --- a/scripts/sparse_smatch/smp.py +++ b/scripts/sparse_smatch/smp.py @@ -11,7 +11,8 @@ import tempfile sys.dont_write_bytecode = True ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT / "scripts")) -from lint_common import copy_output, entrypoint, log_path, show_log # noqa: E402 +from analyzer_report import show_result # noqa: E402 +from lint_common import copy_output, entrypoint, log_path, report_lock, show_log # noqa: E402 from lint_kbuild import build_lock, collect, unchecked_invocations, validate_checker # noqa: E402 from lint_scope import select_sources # noqa: E402 @@ -21,7 +22,7 @@ def main(): parser.add_argument("tool", choices=("sparse", "smatch")) parser.add_argument("files", nargs="*", type=Path) args = parser.parse_args() - with build_lock(ROOT): + with report_lock(ROOT, args.tool), build_lock(ROOT): log = log_path(ROOT, args.tool + ".log") report = log.with_suffix(".json") summary = {"tool": args.tool, "outcome": "incomplete", "exit_code": 2, @@ -58,12 +59,14 @@ def main(): if missing: print("Selected sources absent from this build configuration:\n" + "\n".join(missing), file=sys.stderr) - adapter_failed = any(line.startswith(b"SCST checker failed:") - for line in log.read_bytes().splitlines()) + adapter_failures = [line for line in log.read_text(errors="replace").splitlines() + if line.startswith("SCST checker failed:")] + if adapter_failures: + summary.setdefault("failures", []).extend(adapter_failures) if unrecorded: print("Kbuild CHECK steps without records:\n" + "\n".join(unrecorded), file=sys.stderr) - if (status or not records or errors or missing or unrecorded or adapter_failed or - any(row["returncode"] for row in records)): + if (status or not records or errors or missing or unrecorded or adapter_failures or + any(row["returncode"] or row.get("state") != "complete" for row in records)): print(f"{args.tool}: incomplete analysis (make={status}, " f"checker invocations={len(records)}, errors={errors}).", file=sys.stderr) return 2 @@ -72,10 +75,13 @@ def main(): print(f"{args.tool}: {len(records)} translation units, {findings} diagnostic(s), " f"{ignored} ignored, {remaining} remaining.") return result + except BaseException as error: + summary.setdefault("failures", []).append(str(error) or type(error).__name__) + raise finally: report.write_text(json.dumps(summary, indent=2) + "\n") if os.environ.get("LINT_DEFER_REPORTS") != "1": - copy_output(log) + show_result(summary, log) show_log(log) diff --git a/scripts/tests/test_analyzer_report.py b/scripts/tests/test_analyzer_report.py new file mode 100644 index 0000000..6f1aca1 --- /dev/null +++ b/scripts/tests/test_analyzer_report.py @@ -0,0 +1,257 @@ +"""Reporting must retain evidence without participating in outcome classification.""" + +from pathlib import Path +import json +import sys +import tempfile +import unittest +from unittest.mock import patch + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from analyzer_report import build_diagnostics, markdown_block, render + + +class AnalyzerReportTests(unittest.TestCase): + def test_pahole_notices_retain_context_and_do_not_change_outcome(self): + with tempfile.TemporaryDirectory() as temporary: + log = Path(temporary) / "smatch.log" + notice = ("warning: pahole version differs\n" + " The kernel was built with: 130\n You are using: 132\n") + log.write_text(notice + " CHECK module.c\n" + notice) + report = dict(tool="smatch", outcome="clean", exit_code=0, remaining=0, + ignored=0, make_status=0, checked_files=["module.c"], translation_units=1) + text = render(report, log) + self.assertIn("Smatch: PASS; analysis clean (exit 0)", text) + self.assertIn("The kernel was built with: 130", text) + self.assertIn("Repeated 2 times", text) + self.assertNotIn(" CHECK module.c", text) + self.assertEqual(report["exit_code"], 0) + self.assertEqual(log.read_text().count("warning: pahole"), 2) + + def test_failed_build_without_a_standard_error_retains_its_tail(self): + with tempfile.TemporaryDirectory() as temporary: + log = Path(temporary) / "cppcheck.log" + log.write_text("Package libnl-3.0 was not found in the pkg-config search path.\n") + self.assertIn("libnl-3.0", "\n".join(build_diagnostics(log, failed=True))) + + def test_advice_is_visible_and_distinct_from_active_diagnostics(self): + with tempfile.TemporaryDirectory() as temporary: + log = Path(temporary) / "cppcheck.log" + log.touch() + report = dict(tool="cppcheck", outcome="findings", exit_code=1, remaining=1, + checked_files=["scst/file.c"], inline_exceptions=[{}, {}], profiles=[{ + "profile": "kernel", "complete": True, "native_status": 3, + "translation_units": 1, "failures": [], "diagnostics": [ + {"id": "nullPointer", "severity": "error", "msg": "Null pointer", + "locations": [{"file": "scst/file.c", "line": "10"}]}, + {"id": "unmatchedSuppression", "advisory": "Validated declaration."}, + ]}]) + text = render(report, log) + self.assertIn("Inline exception declarations: 2 (not suppression hits)", text) + self.assertIn("scst/file.c:10: error: Null pointer [nullPointer]", text) + self.assertIn("1 x unmatchedSuppression: Validated declaration.", text) + self.assertIn("complete=True, native exit=3", text) + + + def test_cppcheck_counts_findings_once_and_keeps_each_location(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'cppcheck.log' + log.touch() + report = dict(tool='cppcheck', outcome='findings', exit_code=1, remaining=1, + profiles=[dict(profile='kernel', complete=True, native_status=3, + translation_units=1, diagnostics=[dict( + id='nullPointer', severity='error', msg='Null pointer', + locations=[dict(file='first.c', line=1), + dict(file='second.c', line=2, info='Called here')])])]) + text = render(report, log) + self.assertIn('1 error: [nullPointer]', text) + self.assertIn('first.c:1:', text) + self.assertIn('second.c:2:', text) + self.assertIn('Called here', text) + + def test_cppcheck_xml_is_not_a_build_message(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'cppcheck.log' + log.write_text('<error verbose="Warning: native advice"/>') + build = Path(tmp) / 'build.log' + build.write_text('warning: pahole version differs\n compiler context\n') + report = dict(tool='cppcheck', outcome='clean', exit_code=0, remaining=0, + build_log=str(build), profiles=[]) + text = render(report, log) + self.assertIn('pahole version differs', text) + self.assertIn('compiler context', text) + self.assertNotIn('<error', text) + + def test_checker_notes_and_exceptions_are_separate_from_findings(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + native = root / 'check.log' + note = 'source.c: note: in included file:\n' + ignored = 'header.h:2:3: warning: reviewed layout' + finding = 'source.c:7 fn() warn: retained finding' + native.write_text(note + ignored + '\n' + finding + '\n') + (root / 'check.json').write_text(json.dumps(dict( + state='complete', returncode=0, log=str(native), + ignored=[dict(diagnostic=ignored, reason='Exact reviewed header.')] + ))) + report = dict(tool='smatch', outcome='findings', exit_code=1, remaining=1, + records_directory=str(root), ignored=1) + text = render(report, native) + active = text.split('--- Active diagnostics ---')[1].split('--- Coverage')[0] + self.assertIn(finding, active) + self.assertNotIn('in included file', active) + self.assertNotIn(ignored, active) + self.assertNotIn('Build/environment messages', text) + self.assertIn('1 x tool message: source.c: note:', text) + self.assertIn('Exact reviewed header.', text) + + def test_checkpatch_groups_categories_without_dropping_context(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'checkpatch.log' + log.write_text('WARNING:AVOID_BUG: Do not crash\n#2: FILE: source.c:2:\n' + '+BUG();\n\nCHECK:LINE_SPACING: Blank line\n#4: FILE: source.c:4:\n' + '+return;\n\n') + report = dict(tool='checkpatch', outcome='findings', exit_code=1, remaining=2) + text = render(report, log) + self.assertIn('1 warning: [AVOID_BUG]', text) + self.assertIn('1 check: [LINE_SPACING]', text) + self.assertIn('+BUG();', text) + self.assertIn('source.c:4:', text) + + def test_coccinelle_rule_coverage_and_skips_remain_visible(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'coccicheck.log' + log.touch() + report = dict(tool='coccicheck', outcome='clean', exit_code=0, remaining=0, + rules=[dict(rule='rules/alloc.cocci', complete=True, native_status=0, + handled=['source.c'])], skipped_rules=['rules/patch-only.cocci']) + text = render(report, log) + self.assertIn('Semantic rules: 1 run; 1 skipped without report mode', text) + self.assertIn('patch-only.cocci (no report mode)', text) + self.assertIn('alloc.cocci: complete=True', text) + + def test_native_exit_explanations_and_checker_counts_are_visible(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'native.log' + log.touch() + report = dict(tool='cppcheck', outcome='clean', exit_code=0, remaining=0, + checked_files=['scst/src/kunit/test.c'], profiles=[dict( + profile='kernel', complete=True, native_status=3, translation_units=1, + native_status_reason='validated unmatched inline declarations', + diagnostics=[dict(id='checkersReport', severity='information', + advisory='Native checker inventory', + msg='Active checkers: 108/164')])]) + text = render(report, log) + self.assertIn('Checked translation units (.c): 1; including 1 KUnit translation units', text) + self.assertIn('Native exit explanation: validated unmatched inline declarations', text) + self.assertIn('kernel: Active checkers: 108/164', text) + self.assertNotIn('x checkersReport', text) + report = dict(tool='checkpatch', outcome='clean', exit_code=0, remaining=0, + native_status=1, ignored=12, checked_files=['scst/src/kunit/test.h']) + text = render(report, log) + self.assertIn('12 exempted, 0 active', text) + self.assertIn('Checked source files (.c and .h): 1; including 1 KUnit files', text) + + def test_cppcheck_inventory_explains_no_entries_without_promoting_them_to_active(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'native.log' + log.touch() + inventory = dict(version='2.22.0', checkers=[ + dict(name='CheckNullPointer::nullPointer', active=True, requirements=''), + dict(name='CheckIO::checkCoutCerrMisusage', active=False, requirements='c', + reason='C++-specific checks (inputs are C)'), + dict(name='CheckUnusedFunctions::check', active=False, requirements='unusedFunction', + reason='Build-directory unusedFunction pass is not registered in this inventory'), + dict(name='CheckOther::newCheck', active=False, requirements='warning', + reason='Reason not established from the native inventory'), + ]) + profiles = [dict(profile=name, complete=True, native_status=0, translation_units=1, + checker_inventory=inventory, diagnostics=[dict( + id='checkersReport', advisory='Native checker inventory', + msg='Active checkers: 1/4')]) for name in ('kernel', 'userspace')] + report = dict(tool='cppcheck', outcome='clean', exit_code=0, remaining=0, profiles=profiles) + before = json.dumps(report) + for markdown in (False, True): + with self.subTest(markdown=markdown), patch.dict('os.environ', GITHUB_ACTIONS='true'), \ + patch('lint_common.VERBOSE', False): + text = render(report, log, markdown=markdown) + heading = ('<details><summary>Checker inventory: kernel, userspace</summary>' + if markdown else '::group::Checker inventory: kernel, userspace') + self.assertIn(heading, text) + self.assertEqual(text.count('Active checkers: 1/4'), 2) + self.assertIn('3 checkers not reported active', text) + self.assertIn('1 x C++-specific checks (inputs are C)', text) + self.assertIn('1 x Reason not established', text) + self.assertEqual(text.count('CheckIO::checkCoutCerrMisusage:'), 1) + self.assertIn('native require:c', text) + self.assertIn('not registered in this inventory', text) + self.assertIn('Cppcheck: PASS; analysis clean (exit 0)', text) + self.assertEqual(json.dumps(report), before) + + def test_btf_messages_are_folded_without_hiding_build_warnings(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'build.log' + raw = ('Skipping BTF generation for first.ko due to unavailability of vmlinux\n' + 'Skipping BTF generation for second.ko due to unavailability of vmlinux\n' + 'warning: compiler versions differ\n compiler details\n') + log.write_text(raw) + report = dict(tool='sparse', outcome='clean', exit_code=0, remaining=0) + with patch.dict('os.environ', {'GITHUB_ACTIONS': 'true'}), \ + patch('lint_common.VERBOSE', False): + text = render(report, log) + self.assertIn('BTF generation skipped for 2 modules', text) + self.assertIn('::group::BTF details', text) + self.assertIn('second.ko', text) + self.assertIn('--- Build/environment messages ---', text) + self.assertIn('compiler details', text) + self.assertEqual(log.read_text(), raw) + + def test_coccinelle_notices_and_macro_coverage_limits_remain_distinct(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'native.log' + log.touch() + report = dict(tool='coccicheck', outcome='clean', exit_code=0, remaining=0, + rules=[dict(rule='do_div.cocci', complete=True, native_status=0, + handled=['source.c'], duration_seconds=3.5, + tool_warnings=[dict(message='<string>:33: SyntaxWarning: notice', + reason='Upstream compatibility')], + coverage_limits=[dict(file='source.h', line=2, name='MACRO', + message='parse error', + reason='A standalone definition is not checked.')])]) + for github in ('', 'true'): + for verbose in (False, True): + with (self.subTest(github=github, verbose=verbose), + patch.dict('os.environ', {'GITHUB_ACTIONS': github}), + patch('lint_common.VERBOSE', verbose)): + text = render(report, log) + folded = github == 'true' and not verbose + heading = ('::group::Macro coverage limitations' if folded else + '--- Macro coverage limitations ---') + self.assertIn(heading, text) + self.assertEqual('::group::' in text, folded) + self.assertIn('do_div.cocci: <string>:33: SyntaxWarning: notice', text) + self.assertIn('duration=3.5s', text) + self.assertIn('1 occurrences; 1 definitions', text) + self.assertIn('no synthetic macro contexts are checked', text) + self.assertIn('source.h:2: parse error [MACRO] (1 occurrences)', text) + self.assertIn('A standalone definition is not checked.', text) + self.assertNotIn('Macro context coverage', text) + + def test_markdown_keeps_diagnostics_literal_and_has_no_workflow_commands(self): + with tempfile.TemporaryDirectory() as tmp: + log = Path(tmp) / 'native.log' + log.touch() + message = 'source.c:2:1: error: SCS.1: ``` </details> **text**' + report = dict(tool='scs_lint', outcome='findings', exit_code=1, remaining=1, + checked_files=['source.c'], diagnostics=[dict(native=message, rule='SCS.1')]) + with patch.dict('os.environ', {'GITHUB_ACTIONS': 'true'}): + text = render(report, log, markdown=True) + self.assertIn('**Active diagnostics**', text) + self.assertIn('````text\n' + message + '\n````', text) + self.assertNotIn('::group::', text) + self.assertIn('SCS: FAIL', text) + self.assertTrue(markdown_block('plain').startswith('```text\n')) + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/tests/test_kbuild_driver.py b/scripts/tests/test_kbuild_driver.py index a010ff6..dd288de 100644 --- a/scripts/tests/test_kbuild_driver.py +++ b/scripts/tests/test_kbuild_driver.py @@ -117,13 +117,38 @@ subprocess.run([*shlex.split(checker), str(root / 'scst/second.c')], cwd=root) """) result = self.analyze() self.assertEqual(result.returncode, 2, result.stderr) - self.assertIn(b"SCST checker failed", result.stderr) + self.assertIn(b"SCST checker failed", result.stdout + result.stderr) self.assertIn(b"checker invocations=2", result.stderr) + def test_interrupted_adapter_retains_partial_native_output(self): + import json + + self.program("sparse", """ +import os, signal, sys +print('scst/source.c:1:2: warning: partial native finding', flush=True) +os.kill(os.getppid(), signal.SIGTERM) +""") + result = self.analyze() + self.assertEqual(result.returncode, 2, result.stderr) + summary = json.loads((self.root / ".cache/lint/sparse.json").read_text()) + records = list(Path(summary["records_directory"]).glob("*.json")) + self.assertEqual(len(records), 1) + record = json.loads(records[0].read_text()) + self.assertEqual(record["state"], "started") + self.assertNotEqual(record["returncode"], 0) + self.assertIn("partial native finding", Path(record["log"]).read_text()) + def test_missing_tool_fails(self): (self.bin / "sparse").unlink() self.assertNotEqual(self.analyze().returncode, 0) + def test_legacy_diff_environment_does_not_skip_analysis(self): + self.env["DIFFBR"] = "missing-reference" + self.env["TEST_DIAGNOSTIC"] = "scst/source.c:1:2: warning: retained finding" + result = self.analyze() + self.assertEqual(result.returncode, 1, result.stderr) + self.assertIn(b"retained finding", result.stdout) + def test_explicit_input_missing_from_build_is_not_a_clean_result(self): source = self.source.with_name("disabled.c") source.write_text("int disabled;\n") @@ -141,8 +166,8 @@ print('scst/source.c:2 example() error: source defect') result = subprocess.run([sys.executable, str(self.root / "scripts/sparse_smatch/smp.py"), "smatch"], env=self.env, cwd=self.root, capture_output=True) self.assertEqual(result.returncode, 1, result.stderr) - self.assertIn(b"retained smatch finding", result.stderr) - self.assertIn(b"source defect", result.stderr) + self.assertIn(b"retained smatch finding", result.stdout + result.stderr) + self.assertIn(b"source defect", result.stdout + result.stderr) self.assertIn(b"2 diagnostic(s)", result.stdout) def test_generated_metadata_is_not_counted_as_checked(self): diff --git a/scripts/tests/test_lint_common.py b/scripts/tests/test_lint_common.py index 4b91e52..34fc42c 100644 --- a/scripts/tests/test_lint_common.py +++ b/scripts/tests/test_lint_common.py @@ -18,7 +18,7 @@ from unittest.mock import patch sys.dont_write_bytecode = True SCRIPTS = Path(__file__).resolve().parents[1] sys.path.insert(0, str(SCRIPTS)) -from lint_common import Progress, copy_output, jobserver_fds, log_path, run # noqa: E402 +from lint_common import Progress, copy_output, jobserver_fds, log_path, report_lock, run # noqa: E402 class LogTest(unittest.TestCase): @@ -157,14 +157,27 @@ sys.exit(entrypoint(main)) process.communicate(timeout=5) os.close(master) - def test_plain_progress_updates_every_five_seconds(self): + def test_plain_progress_updates_every_thirty_seconds(self): stream = io.StringIO() with contextlib.redirect_stderr(stream), \ - patch("lint_common.time.monotonic", side_effect=(10, 15)): + patch("lint_common.time.monotonic", side_effect=(10, 40)): progress = Progress("Fixture") - self.assertEqual(progress.interval, 5) + self.assertEqual(progress.interval, 30) progress.update() - self.assertEqual(stream.getvalue(), " Fixture: running (5s elapsed)\n") + self.assertEqual(stream.getvalue(), " Fixture: running (30s total elapsed)\n") + + def test_progress_label_tracks_the_current_rule_on_the_selected_stream(self): + stream = io.StringIO() + rule = 'first.cocci' + with patch('lint_common.time.monotonic', side_effect=(10, 40, 70, 75)): + progress = Progress(lambda: rule, stream=stream) + progress.update() + rule = 'second.cocci' + progress.update() + progress.finish(0) + self.assertIn('first.cocci: running (30s total elapsed)', stream.getvalue()) + self.assertIn('second.cocci: running (60s total elapsed)', stream.getvalue()) + self.assertIn('second.cocci: finished (65s total elapsed, exit 0)', stream.getvalue()) def test_dumb_terminal_does_not_receive_escape_sequences(self): stream = io.StringIO() @@ -185,7 +198,7 @@ sys.exit(entrypoint(main)) with self.assertRaises(KeyboardInterrupt): run(["fixture"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, progress="Fixture") - stop.assert_called_once_with(start.return_value) + stop.assert_called_once_with(start.return_value, timeout=2) self.assertTrue(stream.getvalue().endswith("\r\033[2K")) def test_inherited_pipe_jobserver_survives_python_driver(self): @@ -278,5 +291,131 @@ if stopping: process.communicate(timeout=5) +class TimeoutTests(unittest.TestCase): + def test_outer_driver_waits_for_native_sigkill_and_cleanup(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + native = root / 'native.py' + native.write_text(""" +import os, signal, sys, time +from pathlib import Path +signal.signal(signal.SIGTERM, signal.SIG_IGN) +Path(sys.argv[1], 'native.pid').write_text(str(os.getpid())) +Path(sys.argv[1], 'native-ready').touch() +while True: + time.sleep(1) +""") + driver = root / 'driver.py' + driver.write_text(""" +import os, subprocess, sys +from pathlib import Path +sys.path.insert(0, sys.argv[... [truncated message content] |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:24:26
|
Commit: edf42a0 GitHub URL: https://github.com/SCST-project/scst/commit/edf42a074282633e7aa174093049454026e24db0 Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- scripts: Keep analyzer targets on the full configured source scope A source diff cannot establish that a module's unchanged consumers and headers remain clean. Make the analyzer targets always check their full configured scope. Retain explicit-file selection for focused investigation. Remove DIFFBR, --base and the shared Git diff/pathspec helpers. Keep policy validation, symlink checks and missing-input failures. Update CLI and selector fixtures and document the supported interface. Capture Git stderr and preserve it in source-selection errors, so SCS negative fixtures can assert the failure without leaking an expected "fatal: not a git repository" into a successful CI test log. The SCS layout rule and explicit-file interface remain unchanged. Modified Paths: -------------- Makefile | 1 - doc/scs.md | 7 +- scripts/README.md | 31 +++---- scripts/ci/run-analyzer.py | 4 +- scripts/coccinelle/coccicheck.py | 3 +- scripts/cppcheck/cppcheck.py | 5 +- scripts/lint_scope.py | 46 +++------- scripts/scs_lint/scs_lint.py | 3 +- scripts/scs_lint/test_scs_lint.py | 29 ++++--- scripts/sparse_smatch/smp.py | 5 +- scripts/style/checkpatch.py | 3 +- scripts/tests/test_analyzer_ci.py | 1 - scripts/tests/test_analyzer_policy.py | 15 +--- scripts/tests/test_kbuild_driver.py | 5 +- scripts/tests/test_lint_scope.py | 66 +++++++-------- 15 files changed, 88 insertions(+), 136 deletions(-) =================================================================== diff --git a/Makefile b/Makefile index b7699e5..b9f8470 100644 --- a/Makefile +++ b/Makefile @@ -173,7 +173,6 @@ help: ' cppcheck analyze fresh kernel and userspace build contexts' \ ' checkpatch check C source/header style, including KUnit' \ ' scs_lint check SCST code style rules (doc/scs.md)' \ - ' DIFFBR=commit compare with one commit; select relevant inputs' \ ' lint-test test shared analyzer tooling (no modules)' \ ' all make all' \ ' clean clean files' \ diff --git a/doc/scs.md b/doc/scs.md index 27448f1..46942b6 100644 --- a/doc/scs.md +++ b/doc/scs.md @@ -18,13 +18,12 @@ void scst_example(struct scst_cmd *cmd) } ``` -This follows engine's OCS.7.5 layout rule. It does not change visibility, -inlining, linkage or the behavior of KUnit helpers. +This layout does not change visibility, inlining, linkage or the behavior of +KUnit helpers. `scs_lint` checks all preprocessor branches in the selected project C sources and headers. Comments, string literals and preprocessor directives (including macro definitions) are outside this rule. There are no per-file waivers. -Run `make scs_lint` for all tracked project sources, -`make scs_lint DIFFBR=<base>` for changed files, or +Run `make scs_lint` for all tracked project sources or `scripts/scs_lint/run_scs_lint.sh path/to/file.c` for explicit files. diff --git a/scripts/README.md b/scripts/README.md index 6c4f0d1..31a6b4b 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -66,8 +66,8 @@ committing; sourced libraries, POSIX shell scripts, and callers outside ## Shared analyzer source scope -`lint_scope.py` reads [policy/common.json](policy/common.json) for full, diff -and explicit-file selection. The loader rejects invalid or missing policy; +`lint_scope.py` reads [policy/common.json](policy/common.json) for full and +explicit-file selection. The loader rejects invalid or missing policy; there are no environment-based extra exclusions. Existing checkpatch wrappers and the kernel regression runner still use their own selection and filtering. @@ -104,14 +104,9 @@ sources does not enable them in a build; that needs the build configuration. Full selection reads existing working-tree files listed in the Git index, including staged new files. Missing and untracked files are omitted. -Diff selection compares a base with the working tree, including staged and -unstaged changes. It selects whole current files, checks rename destinations, -and skips deleted and untracked files. The base must resolve to one commit; -options, ranges, tree objects and unknown revisions are rejected. - Explicit files may be untracked, but must exist and be within the same scope. -They cannot be combined with a diff base. Both a path and its resolved symlink -destination must be in scope. Results are sorted and deduplicated. +Both a path and its resolved symlink destination must be in scope. +Results are sorted and deduplicated. An empty selection means there are no eligible inputs, not a completed scan. ## Shared process and log helpers @@ -139,7 +134,6 @@ descriptor releases the lock, including on exceptions. ```sh make -j8 sparse KDIR=/path/to/kernel/build KUNIT_TEST=y make -j8 smatch KDIR=/path/to/kernel/build KUNIT_TEST=y -make smatch DIFFBR=master KUNIT_TEST=y python3 -B scripts/sparse_smatch/smp.py sparse scst/src/scst_lib.c ``` @@ -148,9 +142,8 @@ installing or loading them. The scope above applies, excluding userspace; the upstream QLogic base is built only as a dependency. `KUNIT_TEST=y` includes KUnit suites and requires a kernel with KUnit support. -Diff mode compares one commit with the working tree. A changed module source -or header triggers full configured analysis; an unrelated diff skips it. -An explicitly selected or changed C file absent from the build is an error. +Both targets analyze the full configured build. An explicitly selected C file +absent from the build is an error. Source findings and incomplete analysis fail the targets. The Python driver returns 0 for clean runs or empty selections, 1 for findings and 2 for @@ -196,13 +189,12 @@ needed for current kernel RCU headers. Tool provenance is recorded under ```sh make coccicheck KDIR=/path/to/kernel/build -make coccicheck KDIR=/path/to/kernel/build DIFFBR=master ``` Install `spatch` with Python support and kernel sources containing `scripts/coccinelle/`. Rules declaring `report` mode run on the shared source scope, including userspace and KUnit files; other rules are listed as skipped. -Diff mode checks whole changed C files and headers. No build is needed. +The selected C files and headers are checked in full. No build is needed. The wrapper adds only report counters and completion markers to temporary rule copies. It uses no SCST macro models or diagnostic exceptions. Parser @@ -215,7 +207,6 @@ Full output and per-rule coverage are in `.cache/lint/coccicheck.{log,json}`. ```sh make -j8 cppcheck KDIR=/path/to/kernel/build KUNIT_TEST=y -make -j8 cppcheck KDIR=/path/to/kernel/build KUNIT_TEST=y DIFFBR=master ``` The target requires Cppcheck with `--check-level` and `--checkers-report` @@ -225,8 +216,8 @@ example) to collect their compiler commands. It then runs kernel and userspace analysis separately with all native checks enabled. Nothing is installed or loaded. KUnit coverage follows `KUNIT_TEST` and the kernel configuration. -A relevant diff triggers the full configured analysis, including header -consumers. Explicit or changed C files absent from the build cause a failure. +The target runs the full configured analysis, including header consumers. +Explicit C files absent from the build cause a failure. Real includes and definitions are preserved; no project models, header substitutions, inline suppressions or diagnostic exceptions are enabled. Native parser failures and missing includes remain visible as incomplete @@ -238,7 +229,6 @@ the summary links to captured commands, native XML and checker coverage. ```sh make checkpatch KDIR=/path/to/kernel/build -make checkpatch DIFFBR=master CHECKPATCH_PATH=/path/to/kernel/scripts ``` The target checks whole C files and headers selected by the common policy, @@ -260,8 +250,7 @@ KUnit visibility annotations belong on their own line. It uses the common source policy and checks every preprocessor branch, including KUnit sources. There are no additional exclusions or diagnostic exceptions. -Use `make scs_lint DIFFBR=<commit>` for changed files or -`scripts/scs_lint/run_scs_lint.sh path/to/file.c` for explicit inputs. +Use `scripts/scs_lint/run_scs_lint.sh path/to/file.c` for explicit inputs. The wrapper needs `uv` and Python 3.11+; uv supplies the pinned Tree-sitter dependencies. No kernel build is needed. Reports are saved in `.cache/lint/scs_lint.{log,json}`. Findings return 1; incomplete analysis diff --git a/scripts/ci/run-analyzer.py b/scripts/ci/run-analyzer.py index 0363481..30a23a1 100644 --- a/scripts/ci/run-analyzer.py +++ b/scripts/ci/run-analyzer.py @@ -132,7 +132,7 @@ def main(): print(policy, flush=True) identity = str(uuid.uuid4()) env = dict(os.environ, KDIR=str(kernel.resolve()), SCST_LINT_KDIR=str(kernel.resolve()), - KUNIT_TEST="y", KUNIT_LABEL="ALL", DIFFBR="", LINT_DEFER_REPORTS="1", + KUNIT_TEST="y", KUNIT_LABEL="ALL", LINT_DEFER_REPORTS="1", SCST_LINT_RUN_ID=identity) report = {} try: @@ -140,7 +140,7 @@ def main(): # report distinguishes them; neither a failed make nor a report alone # is sufficient to classify the run as completed source findings. result = run(["make", "-j2", args.tool, f"KDIR={kernel.resolve()}", - "KUNIT_TEST=y", "KUNIT_LABEL=ALL", "DIFFBR=", "WERROR=n"], cwd=ROOT, env=env) + "KUNIT_TEST=y", "KUNIT_LABEL=ALL", "WERROR=n"], cwd=ROOT, env=env) finally: path = directory / f"{args.tool}.json" if path.exists(): diff --git a/scripts/coccinelle/coccicheck.py b/scripts/coccinelle/coccicheck.py index 78a2d66..0a7868d 100644 --- a/scripts/coccinelle/coccicheck.py +++ b/scripts/coccinelle/coccicheck.py @@ -90,7 +90,6 @@ def coverage(output, selected, native_status): def main(): parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--base", default=os.environ.get("DIFFBR") or None) parser.add_argument("files", nargs="*", type=Path) args = parser.parse_args() # Also serialize log replacement by concurrent invocations in this worktree. @@ -103,7 +102,7 @@ def main(): report.write_text(json.dumps(summary, indent=2) + "\n") show_log(log) try: - selected = select_sources(ROOT, args.files, args.base, "coccicheck") + selected = select_sources(ROOT, args.files, "coccicheck") summary["selected_files"] = [p.relative_to(ROOT).as_posix() for p in selected] if not selected: print("No eligible Coccinelle inputs; analysis skipped.") diff --git a/scripts/cppcheck/cppcheck.py b/scripts/cppcheck/cppcheck.py index e9befa2..e30a4e1 100644 --- a/scripts/cppcheck/cppcheck.py +++ b/scripts/cppcheck/cppcheck.py @@ -139,7 +139,6 @@ def analyze(profile, records, directory, log): def main(): parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--base", default=os.environ.get("DIFFBR") or None) parser.add_argument("files", nargs="*", type=Path) args = parser.parse_args() with build_lock(ROOT): @@ -151,7 +150,7 @@ def main(): report.write_text(json.dumps(summary, indent=2) + "\n") show_log(log) try: - selected = select_sources(ROOT, args.files, args.base, "cppcheck") + selected = select_sources(ROOT, args.files, "cppcheck") summary["selected_files"] = [p.relative_to(ROOT).as_posix() for p in selected] if not selected: print("No eligible Cppcheck inputs; analysis skipped.") @@ -178,7 +177,7 @@ def main(): records = kernel + userspace captured = {Path(row["file"]) for row in records} missing = ([str(path) for path in selected if path.suffix == ".c" and path not in captured] - if args.files or args.base else []) + if args.files else []) summary.update(kernel_make_status=kernel_status, userspace_make_status=user_status, unchecked_files=missing, unrecorded_checks=missing_checks) if (kernel_status or user_status or not kernel or not userspace or missing or diff --git a/scripts/lint_scope.py b/scripts/lint_scope.py index 59c9643..6ca99c1 100644 --- a/scripts/lint_scope.py +++ b/scripts/lint_scope.py @@ -7,8 +7,8 @@ from pathlib import Path from analyzer_policy import source_policy -def in_scope(path: Path, root: Path, tool="common") -> bool: - policy = source_policy(tool) +def in_scope(path: Path, root: Path, tool="common", *, policy=None) -> bool: + policy = source_policy(tool) if policy is None else policy try: # Neither an alias nor its destination may widen the source scope. names = (Path(os.path.abspath(path)).relative_to(Path(os.path.abspath(root))).as_posix(), @@ -23,22 +23,13 @@ def in_scope(path: Path, root: Path, tool="common") -> bool: for name in names) -def glob_literal(value: str) -> str: - """Quote literal policy paths for Git's glob pathspecs.""" - return "".join({"[": "[[]", "*": "[*]", "?": "[?]"}.get(char, char) for char in value) - - -def git_pathspecs(tool="common") -> list[str]: - policy = source_policy(tool) - return [*(f":(top,glob){glob_literal(directory)}/**/*{suffix}" - for directory in policy["source_roots"] for suffix in policy["source_suffixes"]), - *(f":(top,exclude,glob)**/*{rule['suffix']}" for rule in policy["exclude_suffixes"]), - *(f":(top,exclude,glob){glob_literal(rule['path'])}/**" - for rule in policy["exclude_directories"])] - - def git_names(root: Path, *arguments: str) -> list[str]: - output = subprocess.check_output(["git", "-C", str(root), *arguments]) + try: + output = subprocess.check_output(["git", "-C", str(root), *arguments], + stderr=subprocess.PIPE) + except subprocess.CalledProcessError as error: + detail = error.stderr.decode(errors="replace").strip() + raise ValueError(f"Git source selection failed: {detail or error}") from error return [os.fsdecode(name) for name in output.split(b"\0") if name] @@ -49,27 +40,10 @@ def tracked_sources(root: Path, tool="common") -> list[Path]: if in_scope(root / name, root, tool) and (root / name).is_file()}) -def resolve_base(root: Path, base: str) -> str: - """Require one commit before passing a user-supplied base to Git diff.""" - return subprocess.check_output( - ["git", "-C", str(root), "rev-parse", "--verify", "--end-of-options", - f"{base}^{{commit}}"], text=True).strip() - - -def changed_sources(root: Path, base: str, tool="common") -> list[Path]: - revision = resolve_base(root, base) - names = git_names(root, "diff", "--no-renames", "--name-only", "-z", - "--diff-filter=d", revision, "--", *git_pathspecs(tool)) - return sorted({root / name for name in names - if in_scope(root / name, root, tool) and (root / name).is_file()}) - - -def select_sources(root: Path, files: list[Path], base: str | None, tool="common") -> list[Path]: - if files and base: - raise ValueError("select files or a Git base, not both") +def select_sources(root: Path, files: list[Path], tool="common") -> list[Path]: if files: for path in files: if not path.is_file() or not in_scope(path, root, tool): raise ValueError(f"not a project C source/header: {path}") return sorted({path.resolve() for path in files}) - return changed_sources(root, base, tool) if base else tracked_sources(root, tool) + return tracked_sources(root, tool) diff --git a/scripts/scs_lint/scs_lint.py b/scripts/scs_lint/scs_lint.py index 88ae8ad..4b362bf 100644 --- a/scripts/scs_lint/scs_lint.py +++ b/scripts/scs_lint/scs_lint.py @@ -84,7 +84,6 @@ def main(argv: list[str] | None = None) -> int: ap = argparse.ArgumentParser(description=__doc__) ap.add_argument("files", nargs="*", type=Path, metavar="FILE", help="C source/header files; default: tracked project C sources and headers") - ap.add_argument("--base", default=os.environ.get("DIFFBR") or None) args = ap.parse_args(argv) with log_path(REPOSITORY, "scs_lint.lock", truncate=False).open("a") as lock: @@ -94,7 +93,7 @@ def main(argv: list[str] | None = None) -> int: "remaining": 0, "selected_files": [], "checked_files": []} show_log(log) try: - paths = select_sources(REPOSITORY, args.files, args.base, "scs_lint") + paths = select_sources(REPOSITORY, args.files, "scs_lint") report["selected_files"] = [path.relative_to(REPOSITORY).as_posix() for path in paths] parser = ts.Parser(ts.Language(tree_sitter_c.language())) with log.open("a") as output: diff --git a/scripts/scs_lint/test_scs_lint.py b/scripts/scs_lint/test_scs_lint.py index cf6b4f0..4c9eeb8 100644 --- a/scripts/scs_lint/test_scs_lint.py +++ b/scripts/scs_lint/test_scs_lint.py @@ -103,9 +103,6 @@ class CommandTest(unittest.TestCase): self.temporary = tempfile.TemporaryDirectory(prefix="scs-lint-test-") self.addCleanup(self.temporary.cleanup) self.root = Path(self.temporary.name) - environment = mock.patch.dict("os.environ", {"DIFFBR": ""}) - environment.start() - self.addCleanup(environment.stop) def source(self, name, text): path = self.root / name @@ -113,12 +110,12 @@ class CommandTest(unittest.TestCase): path.write_text(text) return path - def run_lint(self, files, base=None): + def run_lint(self, files): out = io.StringIO() err = io.StringIO() with (contextlib.redirect_stdout(out), contextlib.redirect_stderr(err), mock.patch("scs_lint.REPOSITORY", self.root)): - status = main([str(path) for path in files] + (["--base", base] if base else [])) + status = main([str(path) for path in files]) return status, out.getvalue(), err.getvalue() def report(self): @@ -158,7 +155,7 @@ class CommandTest(unittest.TestCase): self.assertIn("0 file(s) checked", err) self.assertEqual(self.report()["outcome"], "skipped") - def test_changed_files_only_and_no_source_changes_skip(self): + def test_default_checks_all_sources_despite_legacy_diff_environment(self): subprocess.run(["git", "init", "-q", str(self.root)], check=True) changed = self.source("scst/changed.c", "SCST_KUNIT_VISIBLE\nvoid good(void);\n") unchanged = self.source("scst/unchanged.h", "SCST_KUNIT_VISIBLE void bad(void);\n") @@ -166,13 +163,20 @@ class CommandTest(unittest.TestCase): subprocess.run(["git", "-C", str(self.root), "-c", "user.name=Fixture", "-c", "use...@ex...", "commit", "-qm", "Fixture"], check=True) - self.assertEqual(self.run_lint([], base="HEAD")[0], 0) - self.assertEqual(self.report()["outcome"], "skipped") changed.write_text("SCST_KUNIT_VISIBLE void changed(void);\n") - status, out, _ = self.run_lint([], base="HEAD") + with mock.patch.dict("os.environ", {"DIFFBR": "HEAD"}): + status, out, _ = self.run_lint([]) self.assertEqual(status, 1) - self.assertNotIn(str(unchanged), out) - self.assertEqual(self.report()["checked_files"], ["scst/changed.c"]) + self.assertIn(str(unchanged), out) + self.assertIn(str(changed), out) + self.assertEqual(self.report()["checked_files"], ["scst/changed.c", "scst/unchanged.h"]) + + def test_rejects_removed_base_option(self): + error = io.StringIO() + with contextlib.redirect_stderr(error), self.assertRaises(SystemExit) as exited: + main(["--base", "HEAD"]) + self.assertEqual(exited.exception.code, 2) + self.assertIn("unrecognized arguments: --base", error.getvalue()) def test_unreadable_file_preserves_earlier_findings_but_fails_analysis(self): first = self.source("scst/a.c", "SCST_KUNIT_VISIBLE void bad(void);\n") @@ -209,7 +213,8 @@ class CommandTest(unittest.TestCase): self.root = self.root / "missing" status, out, err = self.run_lint([]) self.assertEqual((status, out), (2, "")) - self.assertIn("scs_lint:", err) + self.assertIn("scs_lint: Git source selection failed:", err) + self.assertIn("not a git repository", err) if __name__ == "__main__": diff --git a/scripts/sparse_smatch/smp.py b/scripts/sparse_smatch/smp.py index 96614b5..a8e28e9 100644 --- a/scripts/sparse_smatch/smp.py +++ b/scripts/sparse_smatch/smp.py @@ -19,7 +19,6 @@ from lint_scope import select_sources # noqa: E402 def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("tool", choices=("sparse", "smatch")) - parser.add_argument("--base", default=os.environ.get("DIFFBR") or None) parser.add_argument("files", nargs="*", type=Path) args = parser.parse_args() with build_lock(ROOT): @@ -33,7 +32,7 @@ def main(): report.write_text(json.dumps(summary, indent=2) + "\n") show_log(log) try: - selected = select_sources(ROOT, args.files, args.base, args.tool) + selected = select_sources(ROOT, args.files, args.tool) summary["selected_files"] = [p.relative_to(ROOT).as_posix() for p in selected] if not selected: print("No module C files selected; no analysis requested.") @@ -47,7 +46,7 @@ def main(): checked = {Path(row["file"]) for row in records} summary["checked_files"] = sorted(path.relative_to(ROOT).as_posix() for path in checked) missing = ([str(path) for path in selected if path.suffix == ".c" and path not in checked] - if args.files or args.base else []) + if args.files else []) unrecorded = unchecked_invocations(ROOT, args.tool, log, records) errors = sum(row["errors"] for row in records) findings = sum(row["findings"] for row in records) diff --git a/scripts/style/checkpatch.py b/scripts/style/checkpatch.py index 4b97578..843deb3 100644 --- a/scripts/style/checkpatch.py +++ b/scripts/style/checkpatch.py @@ -93,7 +93,6 @@ def check(tool, selected, log): def main(): parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--base", default=os.environ.get("DIFFBR") or None) parser.add_argument("files", nargs="*", type=Path) args = parser.parse_args() with log_path(ROOT, "checkpatch.lock", truncate=False).open("a") as lock: @@ -107,7 +106,7 @@ def main(): report.write_text(json.dumps(summary, indent=2) + "\n") show_log(log) try: - selected = select_sources(ROOT, args.files, args.base, "checkpatch") + selected = select_sources(ROOT, args.files, "checkpatch") summary["selected_files"] = [path.relative_to(ROOT).as_posix() for path in selected] if not selected: print("No eligible Checkpatch inputs; analysis skipped.") diff --git a/scripts/tests/test_analyzer_ci.py b/scripts/tests/test_analyzer_ci.py index a36907c..4c123f7 100644 --- a/scripts/tests/test_analyzer_ci.py +++ b/scripts/tests/test_analyzer_ci.py @@ -55,7 +55,6 @@ from pathlib import Path root = Path(__file__).resolve().parents[2] assert os.environ['KUNIT_TEST'] == 'y' assert os.environ['KUNIT_LABEL'] == 'ALL' -assert os.environ['DIFFBR'] == '' assert os.environ['LINT_DEFER_REPORTS'] == '1' status = int(os.environ['FIXTURE_STATUS']) directory = root / '.cache/lint' diff --git a/scripts/tests/test_analyzer_policy.py b/scripts/tests/test_analyzer_policy.py index 2614ec5..746779a 100644 --- a/scripts/tests/test_analyzer_policy.py +++ b/scripts/tests/test_analyzer_policy.py @@ -14,7 +14,7 @@ from unittest.mock import patch sys.dont_write_bytecode = True sys.path.insert(0, str(Path(__file__).resolve().parents[1])) import analyzer_policy -from lint_scope import changed_sources, git_names, git_pathspecs, in_scope +from lint_scope import in_scope from lint_scope import select_sources, tracked_sources @@ -92,7 +92,7 @@ class PolicyTests(unittest.TestCase): def test_policy_errors_do_not_become_empty_selections(self): self.activate({**self.policy, "version": 2}) for select in (lambda: in_scope(self.root / "outside.c", self.root), - lambda: tracked_sources(self.root), git_pathspecs): + lambda: tracked_sources(self.root), lambda: select_sources(self.root, [])): with self.assertRaisesRegex(ValueError, "unsupported policy version"): select() @@ -115,18 +115,11 @@ class PolicyTests(unittest.TestCase): with patch.dict(os.environ, {"IGNORE_DIRS": policy["source_roots"][0], "IGNORE_PATTERNS": ".*"}): self.assertEqual(tracked_sources(self.root), expected) - self.assertEqual(select_sources(self.root, expected, None), expected) - names = git_names(self.root, "ls-files", "--cached", "-z", "--", *git_pathspecs()) - self.assertEqual(sorted(self.root / name for name in names), expected) + self.assertEqual(select_sources(self.root, expected), expected) for path in excluded: self.assertFalse(in_scope(path, self.root)) with self.assertRaises(ValueError): - select_sources(self.root, [path], None) - self.git("-c", "user.name=Test", "-c", "use...@ex...", - "-c", "commit.gpgsign=false", "commit", "-qm", "base") - for path in [*expected, *excluded]: - path.write_text("int changed(void);\n", encoding="utf-8") - self.assertEqual(changed_sources(self.root, "HEAD"), expected) + select_sources(self.root, [path]) def test_native_exceptions_require_exact_fields_and_unique_keys(self): path = analyzer_policy.POLICY_PATH.with_name("smatch.json") diff --git a/scripts/tests/test_kbuild_driver.py b/scripts/tests/test_kbuild_driver.py index db178d8..a010ff6 100644 --- a/scripts/tests/test_kbuild_driver.py +++ b/scripts/tests/test_kbuild_driver.py @@ -50,7 +50,7 @@ if not os.environ.get('TEST_NO_CHECK'): str(root / 'scst/source.c')], cwd=root) sys.exit(int(os.environ.get('TEST_BUILD_EXIT', '0'))) """) - self.env = dict(os.environ, PATH=str(self.bin), DIFFBR="", MAKEFLAGS="", + self.env = dict(os.environ, PATH=str(self.bin), MAKEFLAGS="", PYTHONDONTWRITEBYTECODE="1", SCST_LINT_KDIR=str(self.kernel), SMATCH_DATA_DIR=str(data)) self.env.pop("LINT_DEFER_REPORTS", None) @@ -120,8 +120,7 @@ subprocess.run([*shlex.split(checker), str(root / 'scst/second.c')], cwd=root) self.assertIn(b"SCST checker failed", result.stderr) self.assertIn(b"checker invocations=2", result.stderr) - def test_missing_tool_and_invalid_base_fail(self): - self.assertNotEqual(self.analyze("--base", "missing").returncode, 0) + def test_missing_tool_fails(self): (self.bin / "sparse").unlink() self.assertNotEqual(self.analyze().returncode, 0) diff --git a/scripts/tests/test_lint_scope.py b/scripts/tests/test_lint_scope.py index 46beec7..7962f54 100644 --- a/scripts/tests/test_lint_scope.py +++ b/scripts/tests/test_lint_scope.py @@ -1,4 +1,4 @@ -"""Exercise source selection against Git, including paths and renames.""" +"""Exercise tracked and explicit source selection against Git.""" import os from pathlib import Path @@ -6,10 +6,11 @@ import subprocess import sys import tempfile import unittest +from unittest.mock import patch sys.dont_write_bytecode = True sys.path.insert(0, str(Path(__file__).resolve().parents[1])) -from lint_scope import changed_sources, git_pathspecs, in_scope, select_sources, tracked_sources +from lint_scope import in_scope, select_sources, tracked_sources class ScopeTests(unittest.TestCase): @@ -29,7 +30,7 @@ class ScopeTests(unittest.TestCase): self.git("add", "-f", "--", name) return path - def test_full_and_patch_scope_agree(self): + def test_tracked_and_explicit_scope_agree(self): kept = ("scst/src/core.c", "scst/src/kunit/test.c", "iscsi-scst/usr/user.c", "qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.c", "qla2x00t-32gbit/qla2x00-target/scst_qla2xxx.h", "srpt/src/driver.c", @@ -43,16 +44,11 @@ class ScopeTests(unittest.TestCase): for name in (*kept, *excluded): self.assertEqual(in_scope(self.source(name), self.root), name in kept) self.assertEqual(set(tracked_sources(self.root)), {self.root / n for n in kept}) - names = self.git("diff", "--cached", "--name-only", "-z", "--", *git_pathspecs()) - self.assertEqual({os.fsdecode(n) for n in names.split(b"\0") if n}, set(kept)) + self.assertEqual(set(select_sources(self.root, [self.root / n for n in kept])), + {self.root / n for n in kept}) for name in excluded: with self.subTest(name=name), self.assertRaises(ValueError): - select_sources(self.root, [self.root / name], None) - self.git("-c", "user.name=Test", "-c", "use...@ex...", - "-c", "commit.gpgsign=false", "commit", "-qm", "base") - for name in (*kept, *excluded): - (self.root / name).write_text("int changed(void);\n") - self.assertEqual(set(changed_sources(self.root, "HEAD")), {self.root / n for n in kept}) + select_sources(self.root, [self.root / name]) def test_alias_cannot_reinclude_qlogic_sources(self): kept = self.source("scst/kept.c") @@ -63,7 +59,7 @@ class ScopeTests(unittest.TestCase): alias.symlink_to(target) self.assertFalse(in_scope(alias, self.root)) with self.assertRaises(ValueError): - select_sources(self.root, [alias], None) + select_sources(self.root, [alias]) def test_deleted_untracked_and_escaping_links(self): kept = self.source("scst/kept.c") @@ -76,30 +72,34 @@ class ScopeTests(unittest.TestCase): new = self.root / "scst/new.c" new.write_text("int fresh;\n") self.assertEqual(tracked_sources(self.root), [kept]) - self.assertEqual(select_sources(self.root, [new], None), [new]) + self.assertEqual(select_sources(self.root, [new]), [new]) with self.assertRaises(ValueError): - select_sources(self.root, [alias], None) - - def test_diff_checks_new_name_and_rejects_bad_base(self): - self.source("scst/before.c") - self.git("-c", "user.name=Test", "-c", "use...@ex...", - "-c", "commit.gpgsign=false", "commit", "-qm", "base") - self.git("mv", "scst/before.c", "scst/after.c") - self.assertEqual(changed_sources(self.root, "HEAD"), [self.root / "scst/after.c"]) - with self.assertRaises(subprocess.CalledProcessError): - changed_sources(self.root, "missing-reference") + select_sources(self.root, [alias]) - def test_diff_requires_one_commit_even_when_the_worktree_is_clean(self): + def test_default_selection_ignores_legacy_diff_environment(self): source = self.source("scst/core.c") - self.git("-c", "user.name=Test", "-c", "use...@ex...", - "-c", "commit.gpgsign=false", "commit", "-qm", "base") - for base in ("--quiet", "--exit-code", "--cached", "HEAD..HEAD", "HEAD^{tree}"): - with self.subTest(base=base), self.assertRaises(subprocess.CalledProcessError): - changed_sources(self.root, base) - self.git("tag", "baseline") - self.assertEqual(changed_sources(self.root, "baseline"), []) - source.write_text("int changed(void);\n") - self.assertEqual(changed_sources(self.root, "baseline"), [source]) + with patch.dict(os.environ, {"DIFFBR": "missing-reference"}): + self.assertEqual(select_sources(self.root, []), [source]) + + def test_git_failure_preserves_diagnostics_in_the_callers_error(self): + empty = self.root / "not-a-repository" + empty.mkdir() + with patch.dict(os.environ, {"GIT_CEILING_DIRECTORIES": str(self.root)}): + with self.assertRaisesRegex(ValueError, "Git source selection failed:.*not a git repository"): + tracked_sources(empty) + + def test_analyzer_commands_reject_removed_base_option(self): + scripts = Path(__file__).resolve().parents[1] + for command in (("sparse_smatch/smp.py", "sparse"), + ("sparse_smatch/smp.py", "smatch"), + ("style/checkpatch.py",), ("cppcheck/cppcheck.py",), + ("coccinelle/coccicheck.py",)): + with self.subTest(command=command): + result = subprocess.run( + [sys.executable, "-B", str(scripts / command[0]), *command[1:], + "--base", "HEAD"], cwd=self.root, capture_output=True, text=True) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("unrecognized arguments: --base", result.stderr) if __name__ == "__main__": |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:24:06
|
Commit: bca83ce GitHub URL: https://github.com/SCST-project/scst/commit/bca83cec1d4240a573d29d08f20cab3607f60658 Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- .github/workflows: Run PR checks regardless of changed paths The shared path policy skips Clang, kernel regression, KUnit and Ginkgo when a pull request changes only inputs classified as unrelated to a check. Run these checks for every pull request to master so coverage no longer depends on maintaining that classification. Remove the selector, its TOML policy and dedicated tests, together with the workflow conditions and full-history checkouts used for selection. Keep VM supervisor checks and the kernel matrix dependency, and update the CI guide to describe unconditional PR coverage. Preserve the event-specific Ginkgo label sets and the 30-minute PR job limit. Push and manual triggers retain their existing behavior. Modified Paths: -------------- .github/ci-checks.toml | 104 ---- .github/workflows/ci.yml | 15 +- .github/workflows/ginkgo.yml | 17 +- .github/workflows/kunit.yml | 18 +- .github/workflows/run_regression_tests.yaml | 17 - doc/CI.md | 14 +- scripts/ci/select_checks.py | 163 ------ scripts/ci/test_select_checks.py | 425 --------------- 8 files changed, 7 insertions(+), 766 deletions(-) =================================================================== diff --git a/.github/ci-checks.toml b/.github/ci-checks.toml deleted file mode 100644 index a640271..0000000 --- a/.github/ci-checks.toml +++ /dev/null @@ -1,104 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# PR selection only; push and manual runs always run their checks. -# Paths are literal repository-relative names, not globs. Prefixes end in '/'. -# Skip rules take precedence, then exact paths, then non-overlapping prefixes. -# Unlisted paths, this config and the selector itself always run every check. -# Validate with: python3 scripts/ci/select_checks.py --validate-config - -[skip] -basenames = ["AGENTS.md"] -paths = [ - # Do not exempt all documentation: some files are package/kernel inputs. - "CONTRIBUTING.md", - "INSTALL.md", - "README.md", - "README.clang", - "README.cross-compilation", - "README.module-signing", - "README.performance", - "doc/CI.md", - "doc/KUNIT.md", - "scripts/README.md", - "scripts/kunit/upstream/README.md", - "tests/ginkgo/README.md", - # Independent source checks. - "scripts/checkpatch", - "scripts/checkpatch_commits", - "scripts/checkpatch_diff", - "scripts/checkpatch_scan", - "scripts/source/list-double-blank-lines", - "scripts/source/run-shellcheck", - # Release-only inputs are exercised by Packages on master. - ".github/workflows/rpm.yml", - "scripts/release/build-rpm-artifacts", - "scripts/release/generate-release-archive", - "scripts/release/prepare-package-release", - "scripts/release/update-version", -] - -[[rules]] -# VM inputs shared by both suites. -paths = [ - "scripts/ci/Dockerfile", - "scripts/ci/build-guest", - "scripts/ci/build-image", - "scripts/ci/guest", - "scripts/ci/kernel.SHA256SUMS", - "scripts/ci/kernel.env", - "scripts/ci/scst-ci.service", - "scripts/ci/scst-ci.target", - "scripts/ci/test_vm.py", - "scripts/ci/vm.py", -] -checks = ["ginkgo", "kunit"] - -[[rules]] -paths = [ - ".github/workflows/ginkgo.yml", - # Only the scst_user Ginkgo jobs boot these kernels. - "scripts/ci/kernel-5.8.SHA256SUMS", - "scripts/ci/kernel-5.8.env", - "scripts/ci/kernel-5.9.SHA256SUMS", - "scripts/ci/kernel-5.9.env", -] -checks = ["ginkgo"] - -[[rules]] -paths = [".github/workflows/kunit.yml"] -checks = ["kunit"] - -[[rules]] -paths = [".github/workflows/ci.yml"] -checks = ["clang"] - -[[rules]] -paths = [".github/workflows/run_regression_tests.yaml"] -checks = ["regression"] - -[[rules]] -# KUnit tooling tests execute kernel patch generation and regression helpers. -paths = [ - "scripts/kernel/generate-kernel-patch", - "scripts/kernel/run-regression-tests", - "scripts/kernel/kernel-functions", - "scripts/kernel/filter-trace-entry-exit", - "scripts/kernel/specialize-patch", -] -checks = ["kunit", "regression"] - -[[rules]] -paths = ["doc/scst_pg.sgml", "doc/scst_user_spec.sgml", "doc/fig1.png", "doc/fig2.png"] -checks = ["kunit", "clang", "regression"] - -[[rules]] -prefixes = ["tests/ginkgo/"] -checks = ["ginkgo"] - -[[rules]] -# Both VM suites import kernel_diagnostics from the KUnit runner. -prefixes = ["scripts/kunit/"] -checks = ["ginkgo", "kunit"] - -[[rules]] -prefixes = ["debian/"] -checks = ["clang"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a3557d..3f9ff01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,28 +30,15 @@ jobs: - uses: actions/checkout@main with: persist-credentials: false - fetch-depth: 0 - - name: Check CI selection - run: python3 -m unittest discover -s scripts/ci -p 'test_select_checks.py' - - name: Select Clang build - id: changes - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - python3 scripts/ci/select_checks.py --check clang --event "$GITHUB_EVENT_NAME" \ - --base "$BASE_SHA" --head "$HEAD_SHA" - name: Install build-essential - if: steps.changes.outputs.run == 'true' run: | sudo apt-get update sudo apt-get install -y build-essential debhelper devscripts dpkg-dev quilt - name: Install multilib run: | sudo apt-get install -y gcc-multilib g++-multilib - if: steps.changes.outputs.run == 'true' && matrix.arch == 'x86' + if: matrix.arch == 'x86' - name: Build - if: steps.changes.outputs.run == 'true' env: 'CC': ${{ matrix.compiler }} CFLAGS: ${{ matrix.arch == 'x86' && '-m32' || '' }} diff --git a/.github/workflows/ginkgo.yml b/.github/workflows/ginkgo.yml index d0a9afb..2f98f97 100644 --- a/.github/workflows/ginkgo.yml +++ b/.github/workflows/ginkgo.yml @@ -27,29 +27,14 @@ jobs: - uses: actions/checkout@v7 with: persist-credentials: false - # Compare the whole PR against its merge base, including fork PRs. - fetch-depth: 0 - - name: Check CI selection - run: python3 -m unittest discover -s scripts/ci -p 'test_select_checks.py' - - name: Select Ginkgo checks - id: changes - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - python3 scripts/ci/select_checks.py --check ginkgo --event "$GITHUB_EVENT_NAME" \ - --base "$BASE_SHA" --head "$HEAD_SHA" - name: Install build and VM tools - if: steps.changes.outputs.run == 'true' run: | sudo apt-get update sudo apt-get install -y qemu-system-x86 qemu-utils openssh-client e2fsprogs fakeroot - name: Build SCST image and check Ginkgo framework - if: steps.changes.outputs.run == 'true' timeout-minutes: ${{ github.event_name == 'pull_request' && 10 || 40 }} run: bash scripts/ci/build-image ginkgo "$RUNNER_TEMP/ginkgo-image" - name: Run local and iSCSI tests against the compiled SCST - if: steps.changes.outputs.run == 'true' env: GINKGO_LABEL: ${{ github.event_name == 'pull_request' && 'ci-pr' || github.event_name == 'push' && 'ci-push' || '' }} VM_TIMEOUT: ${{ github.event_name == 'pull_request' && '1080' || '10000' }} @@ -57,7 +42,7 @@ jobs: python3 scripts/ci/vm.py ginkgo "$RUNNER_TEMP/ginkgo-image" \ "$RUNNER_TEMP/ginkgo-results" --timeout "$VM_TIMEOUT" --ginkgo-label "$GINKGO_LABEL" - name: Save build logs, reports and serial consoles - if: always() && steps.changes.outputs.run == 'true' + if: always() uses: actions/upload-artifact@v7 with: name: ginkgo-results diff --git a/.github/workflows/kunit.yml b/.github/workflows/kunit.yml index 7438cac..1240f21 100644 --- a/.github/workflows/kunit.yml +++ b/.github/workflows/kunit.yml @@ -27,38 +27,24 @@ jobs: - uses: actions/checkout@v7 with: persist-credentials: false - # Compare the whole PR against its merge base, including fork PRs. - fetch-depth: 0 - - name: Check VM supervisor and CI selection + - name: Check VM supervisor run: python3 -m unittest discover -s scripts/ci -p 'test_*.py' - - name: Select KUnit checks - id: changes - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - python3 scripts/ci/select_checks.py --check kunit --event "$GITHUB_EVENT_NAME" \ - --base "$BASE_SHA" --head "$HEAD_SHA" - name: Install VM tools - if: steps.changes.outputs.run == 'true' run: | sudo apt-get update sudo apt-get install -y qemu-system-x86 qemu-utils e2fsprogs fakeroot - name: Build kernel-matched image and KUnit modules - if: steps.changes.outputs.run == 'true' run: bash scripts/ci/build-image kunit "$RUNNER_TEMP/kunit-image" - name: Exercise VM success, panic and timeout handling - if: steps.changes.outputs.run == 'true' run: | python3 scripts/ci/vm.py self-test "$RUNNER_TEMP/kunit-image" \ "$RUNNER_TEMP/kunit-supervisor" --timeout 180 --accel tcg - name: Run KUnit - if: steps.changes.outputs.run == 'true' run: | python3 scripts/ci/vm.py kunit "$RUNNER_TEMP/kunit-image" \ "$RUNNER_TEMP/kunit-results" --timeout 1200 - name: Save build and runtime evidence - if: always() && steps.changes.outputs.run == 'true' + if: always() uses: actions/upload-artifact@v7 with: name: kunit-results diff --git a/.github/workflows/run_regression_tests.yaml b/.github/workflows/run_regression_tests.yaml index 7200f29..d0fe70f 100644 --- a/.github/workflows/run_regression_tests.yaml +++ b/.github/workflows/run_regression_tests.yaml @@ -20,29 +20,14 @@ jobs: name: Prepare kernel matrix runs-on: ubuntu-latest outputs: - run: ${{ steps.changes.outputs.run }} regression: ${{ steps.matrix.outputs.regression }} steps: - name: Checkout code uses: actions/checkout@main with: persist-credentials: false - fetch-depth: 0 - - - name: Check CI selection - run: python3 -m unittest discover -s scripts/ci -p 'test_select_checks.py' - - - name: Select kernel regression checks - id: changes - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - python3 scripts/ci/select_checks.py --check regression --event "$GITHUB_EVENT_NAME" \ - --base "$BASE_SHA" --head "$HEAD_SHA" - name: Resolve kernel matrix - if: steps.changes.outputs.run == 'true' id: matrix shell: bash run: | @@ -52,8 +37,6 @@ jobs: regression_tests: name: ${{ matrix.version }} needs: prepare_matrix - # Job conditions are evaluated before expanding the matrix. - if: needs.prepare_matrix.outputs.run == 'true' runs-on: ubuntu-latest strategy: fail-fast: false diff --git a/doc/CI.md b/doc/CI.md index 8a53a6b..1c56695 100644 --- a/doc/CI.md +++ b/doc/CI.md @@ -15,16 +15,9 @@ Workflows live in [`.github/workflows`](../.github/workflows). PR checks target | [Coverity](../.github/workflows/coverity.yml) | Static analysis | Push, upstream repository only | | [Mailing list](../.github/workflows/mail_notification.yml) | Commit notifications | Push, upstream repository only | -On PRs, [select_checks.py](../scripts/ci/select_checks.py) selects Clang, kernel -regression, KUnit and Ginkgo using [ci-checks.toml](../.github/ci-checks.toml). -Edit that config to change path rules; it is validated before selection. -Unknown paths and changes to the config or selector run every check. -Known unrelated changes skip expensive work; regression selection happens -before creating its matrix jobs. Some documentation is a package or kernel-patch -input and still needs validation. PR Checkpatch always runs. Packages runs only -after a push to master; the separate Clang build still checks DEB packaging on -PRs. Push and manual runs retain their full checks. Selection errors fail the -workflow; skip reasons appear in the job summary. +Clang, kernel regression, KUnit and Ginkgo run on every PR regardless of which +files changed. Packages runs only after a push to master; the separate Clang +build checks DEB packaging on PRs. Ginkgo uses `ci-pr` for PRs, `ci-push` for master, and all tests for manual runs. The PR job targets 15–20 minutes including image preparation and has a hard @@ -105,6 +98,5 @@ crashes a guest. CI tooling checks without builds or VM access: ```sh -python3 scripts/ci/select_checks.py --validate-config python3 -m unittest discover -s scripts/ci -p 'test_*.py' ``` diff --git a/scripts/ci/select_checks.py b/scripts/ci/select_checks.py deleted file mode 100644 index 1791139..0000000 --- a/scripts/ci/select_checks.py +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0-only -"""Decide whether changed paths require a CI check; filter pull requests only.""" - -import argparse -import os -from pathlib import Path, PurePosixPath -import subprocess -import sys -import tomllib - - -CHECKS = ('ginkgo', 'kunit', 'clang', 'regression') -ROOT = Path(__file__).resolve().parents[2] -CONFIG_PATH = ROOT / '.github/ci-checks.toml' -CONTROL_PATHS = {CONFIG_PATH.relative_to(ROOT).as_posix(), - Path(__file__).resolve().relative_to(ROOT).as_posix()} - - -def string_list(value, name): - if not isinstance(value, list) or any(not isinstance(item, str) or not item - for item in value): - raise ValueError(f'{name} must be an array of nonempty strings') - if len(value) != len(set(value)): - raise ValueError(f'{name} contains duplicate entries') - return value - - -def validate_paths(values, kind, name): - for value in string_list(values, name): - path = value[:-1] if kind == 'prefixes' and value.endswith('/') else value - if (not path or any(part in ('', '.', '..') for part in path.split('/')) - or any(char in value for char in '\\*?[]\x00\r\n') - or value != value.strip() - or (kind == 'prefixes' and not value.endswith('/')) - or (kind == 'basenames' and '/' in value)): - raise ValueError(f'{name}: invalid literal {kind} entry {value!r}') - - -def validate_config(config): - if set(config) != {'skip', 'rules'}: - raise ValueError('Config must contain exactly skip and rules') - skip = config['skip'] - if not isinstance(skip, dict) or set(skip) != {'paths', 'basenames'}: - raise ValueError('skip must contain exactly paths and basenames') - for kind, values in skip.items(): - validate_paths(values, kind, f'skip.{kind}') - if not isinstance(config['rules'], list): - raise ValueError('rules must be an array of tables') - seen_paths = set(skip['paths']) - seen_prefixes = set() - for index, rule in enumerate(config['rules'], 1): - name = f'rules[{index}]' - if (not isinstance(rule, dict) - or set(rule) not in ({'paths', 'checks'}, {'prefixes', 'checks'})): - raise ValueError(f'{name} must contain checks and either paths or prefixes') - checks = string_list(rule['checks'], f'{name}.checks') - if not checks or set(checks) - set(CHECKS): - raise ValueError(f'{name}.checks must select from {", ".join(CHECKS)}') - kind = 'paths' if 'paths' in rule else 'prefixes' - validate_paths(rule[kind], kind, f'{name}.{kind}') - if not rule[kind]: - raise ValueError(f'{name}.{kind} must not be empty') - for value in rule[kind]: - if kind == 'paths': - if value in seen_paths: - raise ValueError(f'{name}: duplicate path {value!r}') - seen_paths.add(value) - else: - if any(value.startswith(other) or other.startswith(value) - for other in seen_prefixes): - raise ValueError(f'{name}: overlapping prefix {value!r}') - seen_prefixes.add(value) - - -def load_config(path=CONFIG_PATH): - with path.open('rb') as stream: - config = tomllib.load(stream) - validate_config(config) - return config - - -def can_skip(check, path, config): - # Changes to the selection mechanism must exercise every check, regardless - # of the policy being edited in the same PR. - if path in CONTROL_PATHS: - return False - skip = config['skip'] - if PurePosixPath(path).name in skip['basenames'] or path in skip['paths']: - return True - for rule in config['rules']: - if path in rule.get('paths', []): - return check not in rule['checks'] - for rule in config['rules']: - if any(path.startswith(prefix) for prefix in rule.get('prefixes', [])): - return check not in rule['checks'] - # New code, shared build inputs and unclassified paths run every check. - return False - - -def changed_paths(base, head): - # Resolve refs before constructing a revision range; reject missing commits. - commits = [subprocess.check_output( - ['git', 'rev-parse', '--verify', '--end-of-options', f'{ref}^{{commit}}'], - text=True).strip() for ref in (base, head)] - output = subprocess.check_output([ - 'git', 'diff', '--no-ext-diff', '--no-renames', '--name-only', '-z', - f'{commits[0]}...{commits[1]}', '--', - ]) - # No rename detection: both the deleted and added path must be skip-safe. - return [os.fsdecode(path) for path in output.split(b'\0') if path] - - -def select_run(check, event, base, head, config): - if event != 'pull_request': - return True, f'{check}: required for push and manual runs.' - if not base or not head: - raise ValueError('Pull-request selection requires base and head commits') - paths = changed_paths(base, head) - if not paths: - return True, f'{check}: required because the PR diff is empty.' - for path in paths: - print(f'Changed path: {path!r}') - if any(not can_skip(check, path, config) for path in paths): - return True, f'{check}: required by relevant or unclassified changes.' - return False, f'{check}: skipped because all changed paths are known unrelated inputs.' - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('--validate-config', action='store_true', - help='validate the CI path policy without selecting a check') - parser.add_argument('--check', choices=CHECKS) - parser.add_argument('--event', - choices=('pull_request', 'push', 'workflow_dispatch')) - parser.add_argument('--base', default='') - parser.add_argument('--head', default='') - args = parser.parse_args() - if not args.validate_config and (not args.check or not args.event): - parser.error('--check and --event are required unless using --validate-config') - try: - config = load_config() - if args.validate_config: - print('CI path config is valid.') - return 0 - required, reason = select_run(args.check, args.event, args.base, args.head, config) - except (OSError, ValueError, subprocess.CalledProcessError) as error: - print(f'Cannot determine CI selection: {error}', file=sys.stderr) - return 1 - print(reason) - result = f'run={str(required).lower()}\n' - print(result, end='') - if os.environ.get('GITHUB_OUTPUT'): - with Path(os.environ['GITHUB_OUTPUT']).open('a') as stream: - stream.write(result) - if os.environ.get('GITHUB_STEP_SUMMARY'): - with Path(os.environ['GITHUB_STEP_SUMMARY']).open('a') as stream: - stream.write(reason + '\n') - return 0 - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/scripts/ci/test_select_checks.py b/scripts/ci/test_select_checks.py deleted file mode 100644 index f56e61b..0000000 --- a/scripts/ci/test_select_checks.py +++ /dev/null @@ -1,425 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -"""Exercise PR selection with real Git histories; no VM or SCST access.""" - -from copy import deepcopy -import os -from pathlib import Path -import subprocess -import sys -import tempfile -import unittest -from unittest.mock import patch - -import select_checks - - -class PathPolicyTests(unittest.TestCase): - def setUp(self): - self.config = select_checks.load_config() - - def test_known_guides_and_independent_tools_skip_all_builds(self): - paths = ('README.md', 'README.clang', 'tests/ginkgo/README.md', - 'scst/AGENTS.md', 'doc/CI.md', 'doc/KUNIT.md', - 'CONTRIBUTING.md', 'INSTALL.md', 'scripts/README.md', - 'scripts/checkpatch', 'scripts/checkpatch_commits', - 'scripts/checkpatch_diff', 'scripts/checkpatch_scan', - 'scripts/source/list-double-blank-lines', - 'scripts/source/run-shellcheck') - for check in select_checks.CHECKS: - for path in paths: - with self.subTest(check=check, path=path): - self.assertTrue(select_checks.can_skip(check, path, self.config)) - - def test_shared_build_inputs_and_unknown_paths_run_all_checks(self): - paths = ('scst/src/scst_lib.c', 'iscsi-scst/kernel/iscsi.c', - 'scst_local/scst_local.c', 'usr/fileio/fileio.c', - 'scstadmin/scstadmin', 'scst/src/kunit/select.mk', - 'Makefile', 'scst/Makefile', 'doc/Makefile', '.dockerignore', - '.github/kernel-matrix.conf', '.github/ci-checks.toml', - 'scripts/kernel/kernel-matrix', - 'scripts/kernel/sign-modules', 'scripts/source/list-source-files', - 'scripts/source/clean-source-tree', 'scripts/ci/select_checks.py', - f'scripts/ci/{Path(__file__).name}', 'scripts/ci/new-helper.py', - 'scripts/checkpatch_new', 'scripts/source/new-helper', - 'doc/new-helper.py', 'scst/README.c', 'new-component/config.json') - for check in select_checks.CHECKS: - for path in paths: - with self.subTest(check=check, path=path): - self.assertFalse(select_checks.can_skip(check, path, self.config)) - - def test_known_inputs_select_their_consumers(self): - cases = { - 'tests/ginkgo/suite/suite_test.go': {'ginkgo'}, - 'tests/ginkgo/internal/testrun/labels.json': {'ginkgo'}, - 'scripts/kunit/run.py': {'ginkgo', 'kunit'}, - 'scripts/kunit/inventory.py': {'ginkgo', 'kunit'}, - 'scripts/ci/kernel.env': {'ginkgo', 'kunit'}, - 'scripts/ci/vm.py': {'ginkgo', 'kunit'}, - 'scripts/ci/build-guest': {'ginkgo', 'kunit'}, - 'scripts/kernel/generate-kernel-patch': {'kunit', 'regression'}, - 'scripts/kernel/run-regression-tests': {'kunit', 'regression'}, - 'debian/rules': {'clang'}, - 'scripts/release/build-rpm-artifacts': set(), - 'scripts/release/generate-release-archive': set(), - 'scripts/release/prepare-package-release': set(), - 'scripts/release/update-version': set(), - '.github/workflows/ci.yml': {'clang'}, - '.github/workflows/rpm.yml': set(), - '.github/workflows/kunit.yml': {'kunit'}, - '.github/workflows/ginkgo.yml': {'ginkgo'}, - '.github/workflows/run_regression_tests.yaml': {'regression'}, - 'doc/scst_pg.sgml': {'kunit', 'clang', 'regression'}, - } - for path, expected in cases.items(): - with self.subTest(path=path): - self.assertEqual({check for check in select_checks.CHECKS - if not select_checks.can_skip(check, path, self.config)}, expected) - - def test_packaged_and_kernel_exported_documentation_is_not_a_blanket_exemption(self): - paths = ('scstadmin/scstadmin.sysfs/scst-1.0.0/README', - 'iscsi-scst/doc/manpages/iscsi-scstd.8', - 'fcst/README', 'scst/README_in-tree') - for check in select_checks.CHECKS: - for path in paths: - with self.subTest(check=check, path=path): - self.assertFalse(select_checks.can_skip(check, path, self.config)) - - def test_push_and_manual_runs_do_not_consult_paths(self): - with patch('select_checks.changed_paths') as changed: - for check in select_checks.CHECKS: - for event in ('push', 'workflow_dispatch'): - self.assertTrue(select_checks.select_run(check, event, '', '', self.config)[0]) - changed.assert_not_called() - - -class ConfigTests(unittest.TestCase): - def setUp(self): - self.config = {'skip': {'paths': [], 'basenames': []}, 'rules': []} - - def test_unknown_or_missing_fields_are_rejected(self): - cases = [ - {}, {'skip': self.config['skip']}, - dict(self.config, typo=[]), dict(self.config, skip=[]), - dict(self.config, skip={'paths': []}), - dict(self.config, skip={'paths': [], 'basenames': [], 'typo': []}), - dict(self.config, rules={}), dict(self.config, rules=[[]]), - ] - for config in cases: - with self.subTest(config=config), self.assertRaises(ValueError): - select_checks.validate_config(config) - for rule in ({'paths': ['doc/file']}, - {'paths': ['doc/file'], 'checks': ['ginkgo'], 'typo': []}, - {'paths': ['doc/file'], 'prefixes': ['doc/'], 'checks': ['ginkgo']}): - with self.subTest(rule=rule), self.assertRaises(ValueError): - select_checks.validate_config(dict(self.config, rules=[rule])) - - def test_check_names_and_types_are_validated(self): - for checks in ([], ['unknown'], ['ginkgo', 'ginkgo'], 'ginkgo', [True], [1], ['']): - self.config['rules'] = [{'paths': ['file'], 'checks': checks}] - with self.subTest(checks=checks), self.assertRaisesRegex(ValueError, 'checks'): - select_checks.validate_config(self.config) - - def test_selectors_must_be_literal_relative_paths(self): - bad = ['', '/absolute', '../outside', './relative', 'a/../b', 'a//b', - 'a\\b', 'a\nb', 'a\rb', 'a\0b', 'a*', 'a?', 'a[bc]', 'a ', ' a'] - for kind in ('paths', 'prefixes'): - values = bad + (['trailing/'] if kind == 'paths' else ['missing-slash']) - for value in values: - self.config['rules'] = [{kind: [value], 'checks': ['ginkgo']}] - with self.subTest(kind=kind, value=value), self.assertRaises(ValueError): - select_checks.validate_config(self.config) - for values in ([], 'file', [False], ['file/', 'file/']): - self.config['rules'] = [{kind: values, 'checks': ['ginkgo']}] - with self.subTest(kind=kind, values=values), self.assertRaises(ValueError): - select_checks.validate_config(self.config) - self.config['rules'] = [] - for values in (['doc/README'], ['.'], ['..'], ['*'], [''], ['AGENTS.md', 'AGENTS.md']): - self.config['skip']['basenames'] = values - with self.subTest(basenames=values), self.assertRaises(ValueError): - select_checks.validate_config(self.config) - - def test_duplicate_paths_and_overlapping_prefixes_are_rejected(self): - for kind, first, second in (('paths', 'file', 'file'), - ('prefixes', 'scripts/', 'scripts/'), - ('prefixes', 'scripts/', 'scripts/kunit/'), - ('prefixes', 'scripts/kunit/', 'scripts/')): - self.config['rules'] = [{kind: [first], 'checks': ['ginkgo']}, - {kind: [second], 'checks': ['kunit']}] - with self.subTest(kind=kind, first=first), self.assertRaises(ValueError): - select_checks.validate_config(self.config) - self.config['skip']['paths'] = ['file'] - self.config['rules'] = [{'paths': ['file'], 'checks': ['ginkgo']}] - with self.assertRaisesRegex(ValueError, 'duplicate path'): - select_checks.validate_config(self.config) - - def test_exact_paths_override_prefixes_regardless_of_rule_order(self): - rules = [{'prefixes': ['tests/'], 'checks': ['ginkgo']}, - {'paths': ['tests/tool.py'], 'checks': ['kunit']}] - for ordered in (rules, list(reversed(rules))): - self.config['rules'] = ordered - select_checks.validate_config(self.config) - self.assertTrue(select_checks.can_skip('ginkgo', 'tests/tool.py', self.config)) - self.assertFalse(select_checks.can_skip('kunit', 'tests/tool.py', self.config)) - self.assertFalse(select_checks.can_skip('ginkgo', 'tests/new.py', self.config)) - self.assertFalse(select_checks.can_skip('ginkgo', 'tests-other/new.py', self.config)) - self.config['skip'] = {'paths': ['tests/tool.py'], 'basenames': ['AGENTS.md']} - self.config['rules'] = rules[:1] - select_checks.validate_config(self.config) - for path in ('tests/tool.py', 'tests/AGENTS.md'): - self.assertTrue(select_checks.can_skip('ginkgo', path, self.config)) - - def test_control_files_cannot_be_exempted_by_config(self): - for path in select_checks.CONTROL_PATHS: - for kind in ('skip', 'paths', 'prefixes'): - config = deepcopy(self.config) - if kind == 'skip': - config['skip']['paths'] = [path] - else: - value = path if kind == 'paths' else path.rsplit('/', 1)[0] + '/' - config['rules'] = [{kind: [value], 'checks': ['ginkgo']}] - select_checks.validate_config(config) - for check in select_checks.CHECKS: - with self.subTest(path=path, kind=kind, check=check): - self.assertFalse(select_checks.can_skip(check, path, config)) - - -class ConfigCLITests(unittest.TestCase): - def setUp(self): - temporary = tempfile.TemporaryDirectory() - self.addCleanup(temporary.cleanup) - self.root = Path(temporary.name) - self.script = self.root / 'repo/scripts/ci/select_checks.py' - self.script.parent.mkdir(parents=True) - self.script.write_text(Path(select_checks.__file__).read_text()) - self.config = self.root / 'repo/.github/ci-checks.toml' - self.config.parent.mkdir(parents=True) - self.config.write_text(select_checks.CONFIG_PATH.read_text()) - self.output = self.root / 'output' - self.summary = self.root / 'summary' - - def run_cli(self, *args): - return subprocess.run([sys.executable, str(self.script), *args], cwd=self.root, - env=dict(os.environ, GITHUB_OUTPUT=str(self.output), - GITHUB_STEP_SUMMARY=str(self.summary)), - capture_output=True, text=True, check=False) - - def test_validation_resolves_config_from_script_and_emits_no_selection(self): - result = self.run_cli('--validate-config') - self.assertEqual(result.returncode, 0, result.stderr) - self.assertIn('config is valid', result.stdout) - self.assertFalse(self.output.exists()) - self.assertFalse(self.summary.exists()) - - def test_invalid_or_missing_config_fails_before_selection_for_every_event(self): - for content in (None, '[broken', 'skip = {}\nrules = []', - '[skip]\npaths = []\nbasenames = []\n' - '[[rules]]\npaths = ["file"]\nchecks = ["typo"]'): - if content is None: - self.config.unlink() - else: - self.config.write_text(content) - cases = [('--validate-config',)] + [ - ('--check', 'ginkgo', '--event', event) - for event in ('pull_request', 'push', 'workflow_dispatch')] - for args in cases: - with self.subTest(content=content, args=args): - result = self.run_cli(*args) - self.assertNotEqual(result.returncode, 0) - self.assertIn('Cannot determine CI selection:', result.stderr) - self.assertNotIn('Traceback', result.stderr) - self.assertFalse(self.output.exists()) - self.assertFalse(self.summary.exists()) - - def test_selection_still_requires_check_and_event(self): - for args in ((), ('--check', 'ginkgo'), ('--event', 'push')): - with self.subTest(args=args): - result = self.run_cli(*args) - self.assertNotEqual(result.returncode, 0) - self.assertFalse(self.output.exists()) - - -class GitSelectionTests(unittest.TestCase): - def setUp(self): - temporary = tempfile.TemporaryDirectory() - self.addCleanup(temporary.cleanup) - self.root = Path(temporary.name) - self.repo = self.root / 'repo' - self.repo.mkdir() - self.output = self.root / 'output' - self.summary = self.root / 'summary' - self.git('init', '-q', '--initial-branch=main') - self.write('scst/core.c', 'core\n') - self.write('doc/CI.md', 'documentation\n') - self.base = self.commit() - - def git(self, *args): - return subprocess.check_output([ - 'git', '-c', 'user.name=CI test', '-c', 'use...@ex...', - '-c', 'commit.gpgsign=false', '-c', 'core.hooksPath=/dev/null', *args, - ], cwd=self.repo, text=True).strip() - - def write(self, name, text): - path = self.repo / name - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(text) - - def commit(self): - self.git('add', '-A') - self.git('commit', '-qm', 'Test change') - return self.git('rev-parse', 'HEAD') - - def select(self, *, check='ginkgo', base=None, head='HEAD', event='pull_request'): - self.output.unlink(missing_ok=True) - self.summary.unlink(missing_ok=True) - return subprocess.run([ - sys.executable, str(Path(select_checks.__file__).resolve()), - '--check', check, '--event', event, - '--base', self.base if base is None else base, - '--head', head, - ], cwd=self.repo, env=dict(os.environ, GITHUB_OUTPUT=str(self.output), - GITHUB_STEP_SUMMARY=str(self.summary)), - capture_output=True, text=True, check=False) - - def assert_selection(self, expected, **kwargs): - result = self.select(**kwargs) - self.assertEqual(result.returncode, 0, result.stderr) - self.assertEqual(self.output.read_text(), f'run={str(expected).lower()}\n') - self.assertIn(kwargs.get('check', 'ginkgo') + ':', self.summary.read_text()) - - def test_docs_and_checkpatch_only(self): - self.write('doc/CI.md', 'updated documentation\n') - self.write('scripts/checkpatch', '#!/bin/bash\n') - self.commit() - for check in select_checks.CHECKS: - with self.subTest(check=check): - self.assert_selection(False, check=check) - - def test_earlier_code_change_is_not_hidden_by_latest_docs_commit(self): - self.write('scst/core.c', 'changed core\n') - self.commit() - self.write('doc/CI.md', 'updated documentation\n') - self.commit() - self.assert_selection(True) - - def test_kunit_tooling_change_is_not_exempted_with_documentation(self): - self.write('doc/CI.md', 'updated documentation\n') - self.write('scripts/kunit/run.py', '# changed KUnit runner\n') - self.commit() - self.assert_selection(True) - - def test_changes_on_base_branch_are_excluded_from_pr_diff(self): - self.git('checkout', '-qb', 'topic') - self.write('doc/CI.md', 'updated documentation\n') - head = self.commit() - self.git('checkout', '-q', 'main') - self.write('scst/core.c', 'upstream core change\n') - base = self.commit() - self.assert_selection(False, base=base, head=head) - - def test_source_renamed_to_documentation_still_requires_checks(self): - self.git('mv', 'scst/core.c', 'doc/core.md') - self.commit() - self.assert_selection(True) - - def test_documentation_renamed_to_source_requires_checks(self): - self.git('mv', 'doc/CI.md', 'scst/new.c') - self.commit() - self.assert_selection(True) - - def test_documentation_rename_can_skip(self): - self.git('mv', 'doc/CI.md', 'doc/KUNIT.md') - self.commit() - self.assert_selection(False) - - def test_deletions_are_classified(self): - self.git('rm', '-q', 'doc/CI.md') - self.commit() - self.assert_selection(False) - self.git('rm', '-q', 'scst/core.c') - self.commit() - self.assert_selection(True) - - def test_changed_file_list_is_not_truncated(self): - for index in range(350): - self.write(f'guides/{index}/AGENTS.md', 'instructions\n') - self.write('scst/core.c', 'changed core\n') - self.commit() - self.assert_selection(True) - - def test_paths_with_newlines_are_not_split_into_exempt_names(self): - self.write('doc/CI.md\nREADME.md', 'unknown input\n') - self.commit() - self.assert_selection(True) - - def test_empty_diff_runs_conservatively(self): - for check in select_checks.CHECKS: - self.assert_selection(True, check=check) - - def test_config_change_runs_every_check(self): - self.write('.github/ci-checks.toml', select_checks.CONFIG_PATH.read_text()) - self.commit() - for check in select_checks.CHECKS: - self.assert_selection(True, check=check) - - def test_push_and_manual_events_run_even_for_docs_only(self): - self.write('doc/CI.md', 'updated documentation\n') - self.commit() - for check in select_checks.CHECKS: - for event in ('push', 'workflow_dispatch'): - with self.subTest(check=check, event=event): - self.assert_selection(True, check=check, event=event, base='', head='') - - def test_debian_only_change_selects_only_clang(self): - self.write('debian/rules', '# packaging change\n') - self.commit() - for check in select_checks.CHECKS: - with self.subTest(check=check): - self.assert_selection(check == 'clang', check=check) - - def test_release_only_change_skips_pr_checks_but_keeps_master_runs(self): - self.write('.github/workflows/rpm.yml', '# master-only workflow\n') - self.write('scripts/release/build-rpm-artifacts', '# RPM build\n') - self.commit() - for check in select_checks.CHECKS: - with self.subTest(check=check): - self.assert_selection(False, check=check) - self.assert_selection(True, check=check, event='push', base='', head='') - - def test_cross_component_rename_requires_both_consumers(self): - self.write('tests/ginkgo/example.go', '// test\n') - self.base = self.commit() - (self.repo / 'debian').mkdir() - self.git('mv', 'tests/ginkgo/example.go', 'debian/example.go') - self.commit() - for check in select_checks.CHECKS: - with self.subTest(check=check): - self.assert_selection(check in ('ginkgo', 'clang'), check=check) - - def test_invalid_check_fails_without_skip_output(self): - result = self.select(check='unknown') - self.assertNotEqual(result.returncode, 0) - self.assertFalse(self.output.exists()) - - def test_missing_or_invalid_revisions_fail_without_skip_output(self): - for base, head in (('', 'HEAD'), (self.base, ''), - ('missing-ref', 'HEAD'), (self.base, 'missing-ref')): - with self.subTest(base=base, head=head): - result = self.select(base=base, head=head) - self.assertNotEqual(result.returncode, 0) - self.assertIn('Cannot determine CI selection', result.stderr) - self.assertFalse(self.output.exists()) - self.assertFalse(self.summary.exists()) - - def test_missing_merge_base_fails_without_skip_output(self): - self.git('checkout', '-q', '--orphan', 'unrelated') - self.write('doc/other.md', 'unrelated history\n') - self.commit() - result = self.select() - self.assertNotEqual(result.returncode, 0) - self.assertIn('Cannot determine CI selection', result.stderr) - self.assertFalse(self.output.exists()) - self.assertFalse(self.summary.exists()) - - -if __name__ == '__main__': - unittest.main() |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:23:47
|
Commit: 9279e75 GitHub URL: https://github.com/SCST-project/scst/commit/9279e7532d23f8a097d6d2afae4903e833478983 Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- scst_user: Advance the cache-flush address only when needed Cppcheck reports unreadVariable in dev_user_flush_dcache(): Variable 'start' is assigned a value that is never used. Only ARCH_HAS_FLUSH_ANON_PAGE needs the advancing virtual address. Move its increment into that branch, after the mapping lookup and anonymous page flush. Keep the initial zero-address check, data-cache flush, page iteration, and buffer-length accounting on every architecture. Modified Paths: -------------- scst/src/dev_handlers/scst_user_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) =================================================================== diff --git a/scst/src/dev_handlers/scst_user_main.c b/scst/src/dev_handlers/scst_user_main.c index d9d797a..adadf3f 100644 --- a/scst/src/dev_handlers/scst_user_main.c +++ b/scst/src/dev_handlers/scst_user_main.c @@ -776,10 +776,10 @@ static void dev_user_flush_dcache(struct scst_user_cmd *ucmd) vma = find_vma(current->mm, start); if (vma) flush_anon_page(vma, page, start); + start += PAGE_SIZE; } #endif flush_dcache_page(page); - start += PAGE_SIZE; bufflen -= PAGE_SIZE; } |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:23:41
|
Commit: 682849f GitHub URL: https://github.com/SCST-project/scst/commit/682849f8321141813a490604e3d4a4696ae0b810 Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- scst_lib: Remove impossible CDB field-decoder error branches Cppcheck reports knownConditionTrueFalse at ten READ/WRITE CDB wrappers: Condition 'res!=0' is always false The shared helpers only extract LBA and length fields and have no failure path. Make the three helpers used solely for field extraction return void and remove the callers' impossible error branches. Keep the int result of get_cdb_info_lba_4_len_2 because it also implements the opcode-table callback. Keep READ/WRITE(6)'s zero-length-to-256 conversion, DIF action selection, corrupted-tag injection, and every return from the fallible protection parsers unchanged. Resolve all ten diagnostics without exceptions. Modified Paths: -------------- scst/src/scst_lib.c | 111 +++++---------- 1 file changed, 34 insertions(+), 77 deletions(-) =================================================================== diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 8788bad..f4f5f3b 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -11781,8 +11781,8 @@ static int get_cdb_info_len_1(struct scst_cmd *cmd, return 0; } -static inline int get_cdb_info_lba_3_len_1_256(struct scst_cmd *cmd, - const struct scst_sdbops *sdbops) +static inline void get_cdb_info_lba_3_len_1_256(struct scst_cmd *cmd, + const struct scst_sdbops *sdbops) { cmd->lba = (cmd->cdb[sdbops->info_lba_off] & 0x1F) << 16; cmd->lba |= get_unaligned_be16(cmd->cdb + sdbops->info_lba_off + 1); @@ -11799,45 +11799,34 @@ static inline int get_cdb_info_lba_3_len_1_256(struct scst_cmd *cmd, */ cmd->bufflen = (u8)(cmd->cdb[sdbops->info_len_off] - 1) + 1; cmd->data_len = cmd->bufflen; - return 0; } static int get_cdb_info_lba_3_len_1_256_read(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_3_len_1_256(cmd, sdbops); + const struct scst_device *dev = cmd->dev; - if (res != 0) { - goto out; - } else { - const struct scst_device *dev = cmd->dev; + get_cdb_info_lba_3_len_1_256(cmd, sdbops); - if (dev->dev_dif_mode != SCST_DIF_MODE_NONE && !dev->dpicz) - cmd->cmd_dif_actions = dev->dev_dif_rd_prot0_actions | - SCST_DIF_CHECK_GUARD_TAG | dev->dif_app_chk | - SCST_DIF_CHECK_REF_TAG; - } -out: - return res; + if (dev->dev_dif_mode != SCST_DIF_MODE_NONE && !dev->dpicz) + cmd->cmd_dif_actions = dev->dev_dif_rd_prot0_actions | + SCST_DIF_CHECK_GUARD_TAG | dev->dif_app_chk | + SCST_DIF_CHECK_REF_TAG; + return 0; } static int get_cdb_info_lba_3_len_1_256_write(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_3_len_1_256(cmd, sdbops); + const struct scst_device *dev = cmd->dev; - if (res != 0) { - goto out; - } else { - const struct scst_device *dev = cmd->dev; + get_cdb_info_lba_3_len_1_256(cmd, sdbops); - if (dev->dev_dif_mode != SCST_DIF_MODE_NONE) - cmd->cmd_dif_actions = dev->dev_dif_wr_prot0_actions | - SCST_DIF_CHECK_GUARD_TAG | dev->dif_app_chk | - SCST_DIF_CHECK_REF_TAG; - } -out: - return res; + if (dev->dev_dif_mode != SCST_DIF_MODE_NONE) + cmd->cmd_dif_actions = dev->dev_dif_wr_prot0_actions | + SCST_DIF_CHECK_GUARD_TAG | dev->dif_app_chk | + SCST_DIF_CHECK_REF_TAG; + return 0; } static int get_cdb_info_len_2(struct scst_cmd *cmd, @@ -11931,10 +11920,7 @@ static int get_cdb_info_lba_4_len_2(struct scst_cmd *cmd, static int get_cdb_info_read_10(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_4_len_2(cmd, sdbops); - - if (res != 0) - return res; + get_cdb_info_lba_4_len_2(cmd, sdbops); #ifdef CONFIG_SCST_DIF_INJECT_CORRUPTED_TAGS EXTRACHECKS_BUG_ON(cmd->cdb[0] != READ_10); @@ -11946,61 +11932,44 @@ static int get_cdb_info_read_10(struct scst_cmd *cmd, static int get_cdb_info_lba_4_len_2_wrprotect(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_4_len_2(cmd, sdbops); - - if (res != 0) - return res; - else - return scst_parse_wrprotect(cmd); + get_cdb_info_lba_4_len_2(cmd, sdbops); + return scst_parse_wrprotect(cmd); } -static inline int get_cdb_info_lba_4_len_4(struct scst_cmd *cmd, - const struct scst_sdbops *sdbops) +static inline void get_cdb_info_lba_4_len_4(struct scst_cmd *cmd, + const struct scst_sdbops *sdbops) { cmd->lba = get_unaligned_be32(cmd->cdb + sdbops->info_lba_off); cmd->bufflen = get_unaligned_be32(cmd->cdb + sdbops->info_len_off); cmd->data_len = cmd->bufflen; - return 0; } static int get_cdb_info_lba_4_len_4_rdprotect(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_4_len_4(cmd, sdbops); - - if (res != 0) - return res; - else - return scst_parse_rdprotect(cmd); + get_cdb_info_lba_4_len_4(cmd, sdbops); + return scst_parse_rdprotect(cmd); } static int get_cdb_info_lba_4_len_4_wrprotect(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_4_len_4(cmd, sdbops); - - if (res != 0) - return res; - else - return scst_parse_wrprotect(cmd); + get_cdb_info_lba_4_len_4(cmd, sdbops); + return scst_parse_wrprotect(cmd); } -static inline int get_cdb_info_lba_8_len_4(struct scst_cmd *cmd, - const struct scst_sdbops *sdbops) +static inline void get_cdb_info_lba_8_len_4(struct scst_cmd *cmd, + const struct scst_sdbops *sdbops) { cmd->lba = get_unaligned_be64(cmd->cdb + sdbops->info_lba_off); cmd->bufflen = get_unaligned_be32(cmd->cdb + sdbops->info_len_off); cmd->data_len = cmd->bufflen; - return 0; } static int get_cdb_info_read_16(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_8_len_4(cmd, sdbops); - - if (res != 0) - return res; + get_cdb_info_lba_8_len_4(cmd, sdbops); #ifdef CONFIG_SCST_DIF_INJECT_CORRUPTED_TAGS EXTRACHECKS_BUG_ON(cmd->cdb[0] != READ_16); @@ -12012,34 +11981,22 @@ static int get_cdb_info_read_16(struct scst_cmd *cmd, static int get_cdb_info_lba_8_len_4_wrprotect(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_8_len_4(cmd, sdbops); - - if (res != 0) - return res; - else - return scst_parse_wrprotect(cmd); + get_cdb_info_lba_8_len_4(cmd, sdbops); + return scst_parse_wrprotect(cmd); } static int get_cdb_info_lba_8_len_4_wrprotect32(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_8_len_4(cmd, sdbops); - - if (res != 0) - return res; - else - return scst_parse_wrprotect32(cmd); + get_cdb_info_lba_8_len_4(cmd, sdbops); + return scst_parse_wrprotect32(cmd); } static int get_cdb_info_lba_8_len_4_rdprotect32(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - int res = get_cdb_info_lba_8_len_4(cmd, sdbops); - - if (res != 0) - return res; - else - return scst_parse_rdprotect32(cmd); + get_cdb_info_lba_8_len_4(cmd, sdbops); + return scst_parse_rdprotect32(cmd); } static int get_cdb_info_write_same(struct scst_cmd *cmd, |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:23:06
|
Commit: 490277d GitHub URL: https://github.com/SCST-project/scst/commit/490277d70a960e49f8fe7e0e423035cb19f8c46f Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- iscsi-scst: Initialize session attribute names as strings Checkpatch --strict reports CAMELCASE for the nine iSCSI parameter names passed to ISCSI_SESS_*_PARAM_ATTR(), including: CHECK:CAMELCASE: Avoid CamelCase: <InitialR2T> CHECK:CAMELCASE: Avoid CamelCase: <MaxRecvDataSegmentLength> CHECK:CAMELCASE: Avoid CamelCase: <HeaderDigest> These names form the existing sysfs interface and must retain their protocol spelling. Pass them as string literals and initialize the kobj_attribute directly instead of asking __ATTR() to stringify tokens. Keep every attribute name, mode 0444, show function and NULL store callback unchanged. Rename the macro parameter to param so it cannot substitute the .name designator in the initializer. Generated private symbols and session parameter accesses keep their existing spelling. This resolves the style reports without changing public structure fields or introducing aliases or diagnostic exceptions. Modified Paths: -------------- iscsi-scst/kernel/session.c | 59 +++++++++------ 1 file changed, 34 insertions(+), 25 deletions(-) =================================================================== diff --git a/iscsi-scst/kernel/session.c b/iscsi-scst/kernel/session.c index 3dafea4..dcff0a2 100644 --- a/iscsi-scst/kernel/session.c +++ b/iscsi-scst/kernel/session.c @@ -379,8 +379,8 @@ void iscsi_sess_force_close(struct iscsi_session *sess) TRACE_EXIT(); } -#define ISCSI_SESS_BOOL_PARAM_ATTR(name, exported_name) \ -static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \ +#define ISCSI_SESS_BOOL_PARAM_ATTR(param, exported_name) \ +static ssize_t iscsi_sess_show_##param(struct kobject *kobj, \ struct kobj_attribute *attr, char *buf) \ { \ struct scst_session *scst_sess; \ @@ -390,14 +390,17 @@ static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \ sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess); \ \ return sysfs_emit(buf, "%s\n", \ - iscsi_get_bool_value(sess->sess_params.name)); \ + iscsi_get_bool_value(sess->sess_params.param)); \ } \ \ -static struct kobj_attribute iscsi_sess_attr_##name = \ - __ATTR(exported_name, 0444, iscsi_sess_show_##name, NULL) +static struct kobj_attribute iscsi_sess_attr_##param = { \ + .attr = { .name = exported_name, .mode = 0444 }, \ + .show = iscsi_sess_show_##param, \ + .store = NULL, \ +} -#define ISCSI_SESS_INT_PARAM_ATTR(name, exported_name) \ -static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \ +#define ISCSI_SESS_INT_PARAM_ATTR(param, exported_name) \ +static ssize_t iscsi_sess_show_##param(struct kobject *kobj, \ struct kobj_attribute *attr, char *buf) \ { \ struct scst_session *scst_sess; \ @@ -407,14 +410,17 @@ static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \ sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess); \ \ return sysfs_emit(buf, "%d\n", \ - sess->sess_params.name); \ + sess->sess_params.param); \ } \ \ -static struct kobj_attribute iscsi_sess_attr_##name = \ - __ATTR(exported_name, 0444, iscsi_sess_show_##name, NULL) +static struct kobj_attribute iscsi_sess_attr_##param = { \ + .attr = { .name = exported_name, .mode = 0444 }, \ + .show = iscsi_sess_show_##param, \ + .store = NULL, \ +} -#define ISCSI_SESS_DIGEST_PARAM_ATTR(name, exported_name) \ -static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \ +#define ISCSI_SESS_DIGEST_PARAM_ATTR(param, exported_name) \ +static ssize_t iscsi_sess_show_##param(struct kobject *kobj, \ struct kobj_attribute *attr, char *buf) \ { \ struct scst_session *scst_sess; \ @@ -425,21 +431,24 @@ static ssize_t iscsi_sess_show_##name(struct kobject *kobj, \ sess = (struct iscsi_session *)scst_sess_get_tgt_priv(scst_sess); \ \ return sysfs_emit(buf, "%s\n", \ - iscsi_get_digest_name(sess->sess_params.name, digest_name)); \ + iscsi_get_digest_name(sess->sess_params.param, digest_name)); \ } \ \ -static struct kobj_attribute iscsi_sess_attr_##name = \ - __ATTR(exported_name, 0444, iscsi_sess_show_##name, NULL) - -ISCSI_SESS_BOOL_PARAM_ATTR(initial_r2t, InitialR2T); -ISCSI_SESS_BOOL_PARAM_ATTR(immediate_data, ImmediateData); -ISCSI_SESS_INT_PARAM_ATTR(max_recv_data_length, MaxRecvDataSegmentLength); -ISCSI_SESS_INT_PARAM_ATTR(max_xmit_data_length, MaxXmitDataSegmentLength); -ISCSI_SESS_INT_PARAM_ATTR(max_burst_length, MaxBurstLength); -ISCSI_SESS_INT_PARAM_ATTR(first_burst_length, FirstBurstLength); -ISCSI_SESS_INT_PARAM_ATTR(max_outstanding_r2t, MaxOutstandingR2T); -ISCSI_SESS_DIGEST_PARAM_ATTR(header_digest, HeaderDigest); -ISCSI_SESS_DIGEST_PARAM_ATTR(data_digest, DataDigest); +static struct kobj_attribute iscsi_sess_attr_##param = { \ + .attr = { .name = exported_name, .mode = 0444 }, \ + .show = iscsi_sess_show_##param, \ + .store = NULL, \ +} + +ISCSI_SESS_BOOL_PARAM_ATTR(initial_r2t, "InitialR2T"); +ISCSI_SESS_BOOL_PARAM_ATTR(immediate_data, "ImmediateData"); +ISCSI_SESS_INT_PARAM_ATTR(max_recv_data_length, "MaxRecvDataSegmentLength"); +ISCSI_SESS_INT_PARAM_ATTR(max_xmit_data_length, "MaxXmitDataSegmentLength"); +ISCSI_SESS_INT_PARAM_ATTR(max_burst_length, "MaxBurstLength"); +ISCSI_SESS_INT_PARAM_ATTR(first_burst_length, "FirstBurstLength"); +ISCSI_SESS_INT_PARAM_ATTR(max_outstanding_r2t, "MaxOutstandingR2T"); +ISCSI_SESS_DIGEST_PARAM_ATTR(header_digest, "HeaderDigest"); +ISCSI_SESS_DIGEST_PARAM_ATTR(data_digest, "DataDigest"); static ssize_t iscsi_sess_sid_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:21:51
|
Commit: d18b876 GitHub URL: https://github.com/SCST-project/scst/commit/d18b876c792d49081ff5bcf3fc49aa21370fc083 Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- iscsi-scstd: Separate parameter lookup assignments from conditions Checkpatch reports eight instances of: ERROR:ASSIGN_IN_IF: do not use assignment in if condition These occur in config_parse_main(), text_scan_login() and the get/set attribute event handlers. Each conditional stores the successful lookup index while falling back from target keys to session keys and user keys. Assign the index before each condition. Finish a handled configuration or login key with continue, and send successful attribute responses through the common done path. Only attempt the next lookup after the previous branch failed to match; do not eagerly evaluate every key table. Preserve target/global eligibility checks, unknown-key handling, parsing errors, response generation and buffer cleanup. This is a control-flow cleanup, not a fix for a demonstrated parameter lookup bug. Resolve all eight diagnostics without exceptions. Modified Paths: -------------- iscsi-scst/usr/config.c | 34 ++++++++++----- iscsi-scst/usr/event.c | 25 +++++++++-- iscsi-scst/usr/iscsid.c | 12 ++--- 3 files changed, 51 insertions(+), 20 deletions(-) =================================================================== diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index 3379d18..7e665fb 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -981,9 +981,13 @@ int config_parse_main(const char *data, u32 cookie) res = target_create(p, &target); if (res != 0) goto out; - } else if (!strcasecmp(p, "Alias") && target) { - ; - } else if ((idx = params_index_by_name(p, target_keys)) >= 0 && (target)) { + continue; + } + if (!strcasecmp(p, "Alias") && target) + continue; + + idx = params_index_by_name(p, target_keys); + if (idx >= 0 && target) { char *str = config_sep_string(&q); n = config_sep_string(&q); @@ -1009,7 +1013,11 @@ int config_parse_main(const char *data, u32 cookie) continue; } target->target_params[idx] = val; - } else if ((idx = params_index_by_name(p, session_keys)) >= 0 && (target)) { + continue; + } + + idx = params_index_by_name(p, session_keys); + if (idx >= 0 && target) { char *str = config_sep_string(&q); n = config_sep_string(&q); @@ -1035,8 +1043,11 @@ int config_parse_main(const char *data, u32 cookie) continue; } target->session_params[idx] = val; - } else if ((idx = params_index_by_name_numwild(p, user_keys)) >= 0 && - ((target) || global_section)) { + continue; + } + + idx = params_index_by_name_numwild(p, user_keys); + if (idx >= 0 && (target || global_section)) { char *name; const char *pass; @@ -1052,11 +1063,12 @@ int config_parse_main(const char *data, u32 cookie) res = __config_account_add(target, idx, name, pass, p, !target, 0); - if (res < 0) - continue; - } else if (global_section && - (!strcasecmp(p, ISCSI_ISNS_SERVER_ATTR_NAME) || - !strcasecmp(p, ISCSI_ISNS_ACCESS_CONTROL_ATTR_NAME))) { + continue; + } + + if (global_section && + (!strcasecmp(p, ISCSI_ISNS_SERVER_ATTR_NAME) || + !strcasecmp(p, ISCSI_ISNS_ACCESS_CONTROL_ATTR_NAME))) { continue; } else { log_error("Unknown or unexpected param: %s\n", p); diff --git a/iscsi-scst/usr/event.c b/iscsi-scst/usr/event.c index b6d4dc9..6317c6a 100644 --- a/iscsi-scst/usr/event.c +++ b/iscsi-scst/usr/event.c @@ -537,7 +537,11 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event) if (target->target_params[idx] != target_keys[idx].local_def) add_key_mark(res_str, sizeof(res_str), 1); - } else if ((idx = params_index_by_name(pp, session_keys)) >= 0) { + goto done; + } + + idx = params_index_by_name(pp, session_keys); + if (idx >= 0) { if (!target) { log_error("Target expected for attr %s", pp); res = -EINVAL; @@ -549,7 +553,11 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event) if (target->session_params[idx] != session_keys[idx].local_def) add_key_mark(res_str, sizeof(res_str), 1); - } else if ((idx = params_index_by_name_numwild(pp, user_keys)) >= 0) { + goto done; + } + + idx = params_index_by_name_numwild(pp, user_keys); + if (idx >= 0) { const struct iscsi_attr *user; user = account_lookup_by_sysfs_name(target, idx, pp); @@ -682,6 +690,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event) goto out_free; } +done: send_mgmt_cmd_res(event->tid, event->cookie, E_GET_ATTR_VALUE, 0, res_str); out_free: @@ -906,7 +915,11 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event) kernel_params_set(event->tid, session->sid.id64, key_target, 1 << idx, params); } - } else if ((idx = params_index_by_name(pp, session_keys)) >= 0) { + goto done; + } + + idx = params_index_by_name(pp, session_keys); + if (idx >= 0) { if (!target) { log_error("Target expected for attr %s", pp); res = -EINVAL; @@ -937,7 +950,11 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event) } target->session_params[idx] = val; - } else if ((idx = params_index_by_name_numwild(pp, user_keys)) >= 0) { + goto done; + } + + idx = params_index_by_name_numwild(pp, user_keys); + if (idx >= 0) { const struct iscsi_attr *user; user = account_lookup_by_sysfs_name(target, idx, pp); diff --git a/iscsi-scst/usr/iscsid.c b/iscsi-scst/usr/iscsid.c index fd55be5..3181ab4 100644 --- a/iscsi-scst/usr/iscsid.c +++ b/iscsi-scst/usr/iscsid.c @@ -353,11 +353,13 @@ static void text_scan_login(struct connection *conn) datasize = conn->req.datasize; while ((key = next_key(&data, &datasize, &value))) { - if (!(params_index_by_name(key, login_keys) < 0)) { - ; - } else if (!strcmp(key, "AuthMethod")) { - ; - } else if ((idx = params_index_by_name(key, session_keys)) >= 0) { + if (params_index_by_name(key, login_keys) >= 0) + continue; + if (!strcmp(key, "AuthMethod")) + continue; + + idx = params_index_by_name(key, session_keys); + if (idx >= 0) { unsigned int val; char buf[32]; |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:21:33
|
Commit: 93f5263 GitHub URL: https://github.com/SCST-project/scst/commit/93f5263c10de0b7be2cef2c6f7a5e8616de3eca7 Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- iscsi-scstd: Replace digest arithmetic macros with inline functions Checkpatch reports MACRO_ARG_REUSE in the private MD5 and SHA1 Boolean transforms and in MD5STEP, for example: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'z' - possible side-effects? CHECK:MACRO_ARG_REUSE: Macro argument reuse 'w' - possible side-effects? CHECK:MACRO_ARG_REUSE: Macro argument reuse 's' - possible side-effects? The current callers pass plain local state, so this is not a demonstrated digest bug. Replace the transforms with typed u32 inline functions and make each MD5 step return the updated word instead of mutating a macro argument. Pass the Boolean result by value, without a function pointer. Preserve all 64 MD5 round operands, constants, input indices and rotations, including truncation to 32 bits before rotation. Preserve the SHA1 round expressions and schedule. Resolve all seven native diagnostics without exceptions; leave compatibility and control-flow macros alone. Modified Paths: -------------- iscsi-scst/usr/md5.c | 168 ++++++++------- iscsi-scst/usr/sha1.c | 25 ++- 2 files changed, 110 insertions(+), 83 deletions(-) =================================================================== diff --git a/iscsi-scst/usr/md5.c b/iscsi-scst/usr/md5.c index a03b12c..f122226 100644 --- a/iscsi-scst/usr/md5.c +++ b/iscsi-scst/usr/md5.c @@ -17,16 +17,32 @@ #include "md5.h" -/* MD5 Transforms */ -#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) ((x) ^ (y) ^ (z)) -#define F4(x, y, z) ((y) ^ ((x) | ~(z))) +/* MD5 transforms */ +static inline u32 md5_f1(u32 x, u32 y, u32 z) +{ + return z ^ (x & (y ^ z)); +} -/* Macro for applying transforms */ -#define MD5STEP(f, w, x, y, z, i, k, s) \ - ((w) += f(x, y, z) + (i) + (k), \ - (w) = ((w) << (s) | (w) >> (32 - (s))) + (x)) +static inline u32 md5_f2(u32 x, u32 y, u32 z) +{ + return md5_f1(z, x, y); +} + +static inline u32 md5_f3(u32 x, u32 y, u32 z) +{ + return x ^ y ^ z; +} + +static inline u32 md5_f4(u32 x, u32 y, u32 z) +{ + return y ^ (x | ~z); +} + +static inline u32 md5_step(u32 w, u32 f, u32 x, u32 i, u32 k, unsigned int s) +{ + w += f + i + k; + return ((w << s) | (w >> (32 - s))) + x; +} static void __md5_transform(u32 hash[MD5_DIGEST_WORDS], const u32 in[MD5_BLOCK_WORDS]) @@ -38,73 +54,73 @@ static void __md5_transform(u32 hash[MD5_DIGEST_WORDS], c = hash[2]; d = hash[3]; - MD5STEP(F1, a, b, c, d, in[0], 0xD76AA478UL, 7); - MD5STEP(F1, d, a, b, c, in[1], 0xE8C7B756UL, 12); - MD5STEP(F1, c, d, a, b, in[2], 0x242070DBUL, 17); - MD5STEP(F1, b, c, d, a, in[3], 0xC1BDCEEEUL, 22); - MD5STEP(F1, a, b, c, d, in[4], 0xF57C0FAFUL, 7); - MD5STEP(F1, d, a, b, c, in[5], 0x4787C62AUL, 12); - MD5STEP(F1, c, d, a, b, in[6], 0xA8304613UL, 17); - MD5STEP(F1, b, c, d, a, in[7], 0xFD469501UL, 22); - MD5STEP(F1, a, b, c, d, in[8], 0x698098D8UL, 7); - MD5STEP(F1, d, a, b, c, in[9], 0x8B44F7AFUL, 12); - MD5STEP(F1, c, d, a, b, in[10], 0xFFFF5BB1UL, 17); - MD5STEP(F1, b, c, d, a, in[11], 0x895CD7BEUL, 22); - MD5STEP(F1, a, b, c, d, in[12], 0x6B901122UL, 7); - MD5STEP(F1, d, a, b, c, in[13], 0xFD987193UL, 12); - MD5STEP(F1, c, d, a, b, in[14], 0xA679438EUL, 17); - MD5STEP(F1, b, c, d, a, in[15], 0x49B40821UL, 22); - - MD5STEP(F2, a, b, c, d, in[1], 0xF61E2562UL, 5); - MD5STEP(F2, d, a, b, c, in[6], 0xC040B340UL, 9); - MD5STEP(F2, c, d, a, b, in[11], 0x265E5A51UL, 14); - MD5STEP(F2, b, c, d, a, in[0], 0xE9B6C7AAUL, 20); - MD5STEP(F2, a, b, c, d, in[5], 0xD62F105DUL, 5); - MD5STEP(F2, d, a, b, c, in[10], 0x02441453UL, 9); - MD5STEP(F2, c, d, a, b, in[15], 0xD8A1E681UL, 14); - MD5STEP(F2, b, c, d, a, in[4], 0xE7D3FBC8UL, 20); - MD5STEP(F2, a, b, c, d, in[9], 0x21E1CDE6UL, 5); - MD5STEP(F2, d, a, b, c, in[14], 0xC33707D6UL, 9); - MD5STEP(F2, c, d, a, b, in[3], 0xF4D50D87UL, 14); - MD5STEP(F2, b, c, d, a, in[8], 0x455A14EDUL, 20); - MD5STEP(F2, a, b, c, d, in[13], 0xA9E3E905UL, 5); - MD5STEP(F2, d, a, b, c, in[2], 0xFCEFA3F8UL, 9); - MD5STEP(F2, c, d, a, b, in[7], 0x676F02D9UL, 14); - MD5STEP(F2, b, c, d, a, in[12], 0x8D2A4C8AUL, 20); - - MD5STEP(F3, a, b, c, d, in[5], 0xFFFA3942UL, 4); - MD5STEP(F3, d, a, b, c, in[8], 0x8771F681UL, 11); - MD5STEP(F3, c, d, a, b, in[11], 0x6D9D6122UL, 16); - MD5STEP(F3, b, c, d, a, in[14], 0xFDE5380CUL, 23); - MD5STEP(F3, a, b, c, d, in[1], 0xA4BEEA44UL, 4); - MD5STEP(F3, d, a, b, c, in[4], 0x4BDECFA9UL, 11); - MD5STEP(F3, c, d, a, b, in[7], 0xF6BB4B60UL, 16); - MD5STEP(F3, b, c, d, a, in[10], 0xBEBFBC70UL, 23); - MD5STEP(F3, a, b, c, d, in[13], 0x289B7EC6UL, 4); - MD5STEP(F3, d, a, b, c, in[0], 0xEAA127FAUL, 11); - MD5STEP(F3, c, d, a, b, in[3], 0xD4EF3085UL, 16); - MD5STEP(F3, b, c, d, a, in[6], 0x04881D05UL, 23); - MD5STEP(F3, a, b, c, d, in[9], 0xD9D4D039UL, 4); - MD5STEP(F3, d, a, b, c, in[12], 0xE6DB99E5UL, 11); - MD5STEP(F3, c, d, a, b, in[15], 0x1FA27CF8UL, 16); - MD5STEP(F3, b, c, d, a, in[2], 0xC4AC5665UL, 23); - - MD5STEP(F4, a, b, c, d, in[0], 0xF4292244UL, 6); - MD5STEP(F4, d, a, b, c, in[7], 0x432AFF97UL, 10); - MD5STEP(F4, c, d, a, b, in[14], 0xAB9423A7UL, 15); - MD5STEP(F4, b, c, d, a, in[5], 0xFC93A039UL, 21); - MD5STEP(F4, a, b, c, d, in[12], 0x655B59C3UL, 6); - MD5STEP(F4, d, a, b, c, in[3], 0x8F0CCC92UL, 10); - MD5STEP(F4, c, d, a, b, in[10], 0xFFEFF47DUL, 15); - MD5STEP(F4, b, c, d, a, in[1], 0x85845DD1UL, 21); - MD5STEP(F4, a, b, c, d, in[8], 0x6FA87E4FUL, 6); - MD5STEP(F4, d, a, b, c, in[15], 0xFE2CE6E0UL, 10); - MD5STEP(F4, c, d, a, b, in[6], 0xA3014314UL, 15); - MD5STEP(F4, b, c, d, a, in[13], 0x4E0811A1UL, 21); - MD5STEP(F4, a, b, c, d, in[4], 0xF7537E82UL, 6); - MD5STEP(F4, d, a, b, c, in[11], 0xBD3AF235UL, 10); - MD5STEP(F4, c, d, a, b, in[2], 0x2AD7D2BBUL, 15); - MD5STEP(F4, b, c, d, a, in[9], 0xEB86D391UL, 21); + a = md5_step(a, md5_f1(b, c, d), b, in[0], 0xD76AA478UL, 7); + d = md5_step(d, md5_f1(a, b, c), a, in[1], 0xE8C7B756UL, 12); + c = md5_step(c, md5_f1(d, a, b), d, in[2], 0x242070DBUL, 17); + b = md5_step(b, md5_f1(c, d, a), c, in[3], 0xC1BDCEEEUL, 22); + a = md5_step(a, md5_f1(b, c, d), b, in[4], 0xF57C0FAFUL, 7); + d = md5_step(d, md5_f1(a, b, c), a, in[5], 0x4787C62AUL, 12); + c = md5_step(c, md5_f1(d, a, b), d, in[6], 0xA8304613UL, 17); + b = md5_step(b, md5_f1(c, d, a), c, in[7], 0xFD469501UL, 22); + a = md5_step(a, md5_f1(b, c, d), b, in[8], 0x698098D8UL, 7); + d = md5_step(d, md5_f1(a, b, c), a, in[9], 0x8B44F7AFUL, 12); + c = md5_step(c, md5_f1(d, a, b), d, in[10], 0xFFFF5BB1UL, 17); + b = md5_step(b, md5_f1(c, d, a), c, in[11], 0x895CD7BEUL, 22); + a = md5_step(a, md5_f1(b, c, d), b, in[12], 0x6B901122UL, 7); + d = md5_step(d, md5_f1(a, b, c), a, in[13], 0xFD987193UL, 12); + c = md5_step(c, md5_f1(d, a, b), d, in[14], 0xA679438EUL, 17); + b = md5_step(b, md5_f1(c, d, a), c, in[15], 0x49B40821UL, 22); + + a = md5_step(a, md5_f2(b, c, d), b, in[1], 0xF61E2562UL, 5); + d = md5_step(d, md5_f2(a, b, c), a, in[6], 0xC040B340UL, 9); + c = md5_step(c, md5_f2(d, a, b), d, in[11], 0x265E5A51UL, 14); + b = md5_step(b, md5_f2(c, d, a), c, in[0], 0xE9B6C7AAUL, 20); + a = md5_step(a, md5_f2(b, c, d), b, in[5], 0xD62F105DUL, 5); + d = md5_step(d, md5_f2(a, b, c), a, in[10], 0x02441453UL, 9); + c = md5_step(c, md5_f2(d, a, b), d, in[15], 0xD8A1E681UL, 14); + b = md5_step(b, md5_f2(c, d, a), c, in[4], 0xE7D3FBC8UL, 20); + a = md5_step(a, md5_f2(b, c, d), b, in[9], 0x21E1CDE6UL, 5); + d = md5_step(d, md5_f2(a, b, c), a, in[14], 0xC33707D6UL, 9); + c = md5_step(c, md5_f2(d, a, b), d, in[3], 0xF4D50D87UL, 14); + b = md5_step(b, md5_f2(c, d, a), c, in[8], 0x455A14EDUL, 20); + a = md5_step(a, md5_f2(b, c, d), b, in[13], 0xA9E3E905UL, 5); + d = md5_step(d, md5_f2(a, b, c), a, in[2], 0xFCEFA3F8UL, 9); + c = md5_step(c, md5_f2(d, a, b), d, in[7], 0x676F02D9UL, 14); + b = md5_step(b, md5_f2(c, d, a), c, in[12], 0x8D2A4C8AUL, 20); + + a = md5_step(a, md5_f3(b, c, d), b, in[5], 0xFFFA3942UL, 4); + d = md5_step(d, md5_f3(a, b, c), a, in[8], 0x8771F681UL, 11); + c = md5_step(c, md5_f3(d, a, b), d, in[11], 0x6D9D6122UL, 16); + b = md5_step(b, md5_f3(c, d, a), c, in[14], 0xFDE5380CUL, 23); + a = md5_step(a, md5_f3(b, c, d), b, in[1], 0xA4BEEA44UL, 4); + d = md5_step(d, md5_f3(a, b, c), a, in[4], 0x4BDECFA9UL, 11); + c = md5_step(c, md5_f3(d, a, b), d, in[7], 0xF6BB4B60UL, 16); + b = md5_step(b, md5_f3(c, d, a), c, in[10], 0xBEBFBC70UL, 23); + a = md5_step(a, md5_f3(b, c, d), b, in[13], 0x289B7EC6UL, 4); + d = md5_step(d, md5_f3(a, b, c), a, in[0], 0xEAA127FAUL, 11); + c = md5_step(c, md5_f3(d, a, b), d, in[3], 0xD4EF3085UL, 16); + b = md5_step(b, md5_f3(c, d, a), c, in[6], 0x04881D05UL, 23); + a = md5_step(a, md5_f3(b, c, d), b, in[9], 0xD9D4D039UL, 4); + d = md5_step(d, md5_f3(a, b, c), a, in[12], 0xE6DB99E5UL, 11); + c = md5_step(c, md5_f3(d, a, b), d, in[15], 0x1FA27CF8UL, 16); + b = md5_step(b, md5_f3(c, d, a), c, in[2], 0xC4AC5665UL, 23); + + a = md5_step(a, md5_f4(b, c, d), b, in[0], 0xF4292244UL, 6); + d = md5_step(d, md5_f4(a, b, c), a, in[7], 0x432AFF97UL, 10); + c = md5_step(c, md5_f4(d, a, b), d, in[14], 0xAB9423A7UL, 15); + b = md5_step(b, md5_f4(c, d, a), c, in[5], 0xFC93A039UL, 21); + a = md5_step(a, md5_f4(b, c, d), b, in[12], 0x655B59C3UL, 6); + d = md5_step(d, md5_f4(a, b, c), a, in[3], 0x8F0CCC92UL, 10); + c = md5_step(c, md5_f4(d, a, b), d, in[10], 0xFFEFF47DUL, 15); + b = md5_step(b, md5_f4(c, d, a), c, in[1], 0x85845DD1UL, 21); + a = md5_step(a, md5_f4(b, c, d), b, in[8], 0x6FA87E4FUL, 6); + d = md5_step(d, md5_f4(a, b, c), a, in[15], 0xFE2CE6E0UL, 10); + c = md5_step(c, md5_f4(d, a, b), d, in[6], 0xA3014314UL, 15); + b = md5_step(b, md5_f4(c, d, a), c, in[13], 0x4E0811A1UL, 21); + a = md5_step(a, md5_f4(b, c, d), b, in[4], 0xF7537E82UL, 6); + d = md5_step(d, md5_f4(a, b, c), a, in[11], 0xBD3AF235UL, 10); + c = md5_step(c, md5_f4(d, a, b), d, in[2], 0x2AD7D2BBUL, 15); + b = md5_step(b, md5_f4(c, d, a), c, in[9], 0xEB86D391UL, 21); hash[0] += a; hash[1] += b; diff --git a/iscsi-scst/usr/sha1.c b/iscsi-scst/usr/sha1.c index 4231653..9231818 100644 --- a/iscsi-scst/usr/sha1.c +++ b/iscsi-scst/usr/sha1.c @@ -18,9 +18,20 @@ #include "sha1.h" /* SHA1 transforms */ -#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) /* x ? y : z */ -#define F2(x, y, z) ((x) ^ (y) ^ (z)) /* XOR */ -#define F3(x, y, z) (((x) & (y)) + ((z) & ((x) ^ (y)))) /* majority */ +static inline u32 sha1_f1(u32 x, u32 y, u32 z) +{ + return z ^ (x & (y ^ z)); +} + +static inline u32 sha1_f2(u32 x, u32 y, u32 z) +{ + return x ^ y ^ z; +} + +static inline u32 sha1_f3(u32 x, u32 y, u32 z) +{ + return (x & y) + (z & (x ^ y)); +} /* SHA1 per-round constants */ #define K1 0x5A827999UL /* Rounds 0-19: sqrt(2) * 2^30 */ @@ -53,22 +64,22 @@ static void __sha1_transform(u32 hash[SHA1_DIGEST_WORDS], e = hash[4]; for (i = 0; i < 20; i++) { - t = F1(b, c, d) + K1 + rol32(a, 5) + e + W[i]; + t = sha1_f1(b, c, d) + K1 + rol32(a, 5) + e + W[i]; e = d; d = c; c = rol32(b, 30); b = a; a = t; } for (; i < 40; i++) { - t = F2(b, c, d) + K2 + rol32(a, 5) + e + W[i]; + t = sha1_f2(b, c, d) + K2 + rol32(a, 5) + e + W[i]; e = d; d = c; c = rol32(b, 30); b = a; a = t; } for (; i < 60; i++) { - t = F3(b, c, d) + K3 + rol32(a, 5) + e + W[i]; + t = sha1_f3(b, c, d) + K3 + rol32(a, 5) + e + W[i]; e = d; d = c; c = rol32(b, 30); b = a; a = t; } for (; i < 80; i++) { - t = F2(b, c, d) + K4 + rol32(a, 5) + e + W[i]; + t = sha1_f2(b, c, d) + K4 + rol32(a, 5) + e + W[i]; e = d; d = c; c = rol32(b, 30); b = a; a = t; } |
|
From: SCST G. <lna...@ya...> - 2026-10-26 11:17:50
|
Commit: 8349605 GitHub URL: https://github.com/SCST-project/scst/commit/8349605ff06b1ea9ccc042a110e48da5d2729636 Author: Gleb Chesnokov Date: 2026-10-26T14:17:21+03:00 Log Message: ----------- scst: Shorten statements and trace argument lines Checkpatch --strict reports LONG_LINE in deeply nested DIF action calls, conditional help strings and diagnostics containing PRI macros, and LONG_LINE_STRING in trace calls whose flags share the format line: CHECK:LONG_LINE: line length of 103 exceeds 100 columns CHECK:LONG_LINE_STRING: line length of 110 exceeds 100 columns Select the DIF action in a single setter argument instead of duplicating that setter in both branches. Preserve the mode test, PASS versus PASS_CHECK selection and update of the existing action flags. Wrap conditional alternatives, existing PRI concatenation boundaries and trace arguments without splitting diagnostic strings or changing argument order. Resolve 15 LONG_LINE and 23 LONG_LINE_STRING reports without adding exceptions. Retain layouts whose further shortening would require interface or deeper control-flow changes. Also fix PARENTHESIS_ALIGNMENT in dev_user_ext_cdb_get() and its private declaration, and remove an extra blank line. Quote and shorten the three HIGHMEM preprocessor warnings. This fixes Checkpatch CAMELCASE reports for <Consider> and <See> and the accompanying LINE_CONTINUATIONS reports without suppressing those diagnostic types. Preserve the existing conditions and the distinction between HIGHMEM being supported by the core and unsupported by the other two modules. Modified Paths: -------------- iscsi-scst/kernel/iscsi.c | 3 +- iscsi-scst/usr/iscsid.c | 4 +- scst/src/dev_handlers/scst_user_main.c | 7 +- scst/src/dev_handlers/scst_user_test.h | 2 +- scst/src/scst_lib.c | 114 ++++++++------- scst/src/scst_main.c | 5 +- scst/src/scst_sysfs.c | 6 +- scst_local/scst_local.c | 5 +- srpt/src/ib_srpt.c | 8 +- usr/fileio/common.c | 12 +- usr/fileio/fileio.c | 3 +- 11 files changed, 90 insertions(+), 79 deletions(-) =================================================================== diff --git a/iscsi-scst/kernel/iscsi.c b/iscsi-scst/kernel/iscsi.c index 4e18a7d..e08f046 100644 --- a/iscsi-scst/kernel/iscsi.c +++ b/iscsi-scst/kernel/iscsi.c @@ -1779,7 +1779,8 @@ static int nop_out_start(struct iscsi_cmnd *cmnd) sg = scst_alloc_sg(size, GFP_KERNEL, &cmnd->sg_cnt); if (!sg) { - TRACE(TRACE_OUT_OF_MEM, "Allocation of buffer for %d Nop-Out payload failed", + TRACE(TRACE_OUT_OF_MEM, + "Allocation of buffer for %d Nop-Out payload failed", size); err = -ISCSI_REASON_OUT_OF_RESOURCES; goto out; diff --git a/iscsi-scst/usr/iscsid.c b/iscsi-scst/usr/iscsid.c index 161cc80..fd55be5 100644 --- a/iscsi-scst/usr/iscsid.c +++ b/iscsi-scst/usr/iscsid.c @@ -288,7 +288,9 @@ static int login_check_reinstatement(struct connection *conn) if (session) { if (req->sid.id.tsih == 0) { /* Kernel will do session reinstatement */ - log_debug(1, "Session sid %#" PRIx64 " reinstatement detected (tid %d, initiator %s)", + log_debug(1, + "Session sid %#" PRIx64 + " reinstatement detected (tid %d, initiator %s)", req->sid.id64, conn->tid, conn->initiator); res = ISCSI_SESS_REINSTATEMENT; diff --git a/scst/src/dev_handlers/scst_user_main.c b/scst/src/dev_handlers/scst_user_main.c index 51cdb9f..d9d797a 100644 --- a/scst/src/dev_handlers/scst_user_main.c +++ b/scst/src/dev_handlers/scst_user_main.c @@ -45,10 +45,7 @@ static void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, unsigned lo #ifndef INSIDE_KERNEL_TREE #if defined(CONFIG_HIGHMEM4G) || defined(CONFIG_HIGHMEM64G) -#warning HIGHMEM kernel configurations are not supported by this module, \ -because nowadays it is not worth the effort. Consider changing \ -VMSPLIT option or use a 64 - bit configuration instead. See README file \ -for details. +#warning "HIGHMEM is unsupported; change VMSPLIT or use a 64-bit kernel. See README." #endif #endif @@ -1944,7 +1941,7 @@ const u8 *dev_user_ext_cdb(const struct scst_cmd *cmd) */ SCST_KUNIT_VISIBLE struct scst_cmd *dev_user_ext_cdb_get(struct scst_user_dev *dev, unsigned int cmd_h, - struct scst_user_cmd **user_cmd) + struct scst_user_cmd **user_cmd) { struct scst_user_cmd *ucmd; struct scst_cmd *cmd; diff --git a/scst/src/dev_handlers/scst_user_test.h b/scst/src/dev_handlers/scst_user_test.h index 8e8ce41..f5f9d8f 100644 --- a/scst/src/dev_handlers/scst_user_test.h +++ b/scst/src/dev_handlers/scst_user_test.h @@ -9,7 +9,7 @@ bool ucmd_get_check(struct scst_user_cmd *ucmd); const u8 *dev_user_ext_cdb(const struct scst_cmd *cmd); struct scst_cmd *dev_user_ext_cdb_get(struct scst_user_dev *dev, unsigned int cmd_h, - struct scst_user_cmd **user_cmd); + struct scst_user_cmd **user_cmd); void dev_user_unjam_cmd(struct scst_user_cmd *ucmd, int busy, unsigned long *flags); void dev_user_flush_pool(struct sgv_pool *pool); int dev_user_process_cleanup(struct scst_user_dev *dev); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 7b4eb53..8788bad 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -1763,7 +1763,8 @@ int scst_set_cmd_error_status(struct scst_cmd *cmd, int status) TRACE_ENTRY(); if (status == SAM_STAT_RESERVATION_CONFLICT) { - TRACE(TRACE_SCSI | TRACE_MINOR, "Reservation conflict (dev %s, initiator %s, tgt_id %d)", + TRACE(TRACE_SCSI | TRACE_MINOR, + "Reservation conflict (dev %s, initiator %s, tgt_id %d)", cmd->dev ? cmd->dev->virt_name : NULL, cmd->sess->initiator_name, cmd->tgt->rel_tgt_id); } @@ -2520,12 +2521,14 @@ void scst_set_busy(struct scst_cmd *cmd) if (c <= 1 || cmd->sess->init_phase != SCST_SESS_IPH_READY) { scst_set_cmd_error_status(cmd, SAM_STAT_BUSY); - TRACE(TRACE_FLOW_CONTROL, "Sending BUSY status to initiator %s (cmds count %d, queue_type %x, sess->init_phase %d)", + TRACE(TRACE_FLOW_CONTROL, + "Sending BUSY status to initiator %s (cmds count %d, queue_type %x, sess->init_phase %d)", cmd->sess->initiator_name, c, cmd->queue_type, cmd->sess->init_phase); } else { scst_set_cmd_error_status(cmd, SAM_STAT_TASK_SET_FULL); - TRACE(TRACE_FLOW_CONTROL, "Sending QUEUE_FULL status to initiator %s (cmds count %d, queue_type %x, sess->init_phase %d)", + TRACE(TRACE_FLOW_CONTROL, + "Sending QUEUE_FULL status to initiator %s (cmds count %d, queue_type %x, sess->init_phase %d)", cmd->sess->initiator_name, c, cmd->queue_type, cmd->sess->init_phase); } @@ -3255,7 +3258,8 @@ int scst_get_cmd_abnormal_done_state(struct scst_cmd *cmd) * Little hack to trace completion of commands, which are * going to bypass normal tracing on SCST_CMD_STATE_PRE_DEV_DONE */ - TRACE(TRACE_SCSI, "cmd %p, status %x, msg_status %x, host_status %x, driver_status %x, resp_data_len %d", + TRACE(TRACE_SCSI, + "cmd %p, status %x, msg_status %x, host_status %x, driver_status %x, resp_data_len %d", cmd, cmd->status, cmd->msg_status, cmd->host_status, cmd->driver_status, cmd->resp_data_len); @@ -3643,7 +3647,8 @@ out: */ void scst_restore_sg_buff(struct scst_cmd *cmd) { - TRACE_DBG_FLAG(TRACE_DEBUG | TRACE_MEMORY, "cmd %p, sg %p, DATA: orig_sg_entry %p, orig_entry_offs %d, orig_entry_len %d, orig_sg_cnt %d, DIF: orig_sg_entry %p, orig_entry_offs %d, orig_entry_len %d, orig_sg_cnt %d", + TRACE_DBG_FLAG(TRACE_DEBUG | TRACE_MEMORY, + "cmd %p, sg %p, DATA: orig_sg_entry %p, orig_entry_offs %d, orig_entry_len %d, orig_sg_cnt %d, DIF: orig_sg_entry %p, orig_entry_offs %d, orig_entry_len %d, orig_sg_cnt %d", cmd, cmd->sg, cmd->orig_sg.orig_sg_entry, cmd->orig_sg.orig_entry_offs, cmd->orig_sg.orig_entry_len, cmd->orig_sg.orig_sg_cnt, @@ -3757,7 +3762,8 @@ int scst_cmd_get_expected_transfer_len_data(struct scst_cmd *cmd) res = (u64)cmd->expected_transfer_len_full << cmd->dev->block_shift; rem = do_div(res, cmd->dev->block_size + (1 << SCST_DIF_TAG_SHIFT)); if (unlikely(rem != 0)) - TRACE(TRACE_MINOR, "Reminder %d for expected transfer len data! (cmd %p, op %s, expected len full %d)", + TRACE(TRACE_MINOR, + "Reminder %d for expected transfer len data! (cmd %p, op %s, expected len full %d)", rem, cmd, scst_get_opcode_name(cmd), cmd->expected_transfer_len_full); @@ -3783,7 +3789,8 @@ int scst_cmd_get_expected_transfer_len_dif(struct scst_cmd *cmd) res = (u64)cmd->expected_transfer_len_full << SCST_DIF_TAG_SHIFT; rem = do_div(res, cmd->dev->block_size + (1 << SCST_DIF_TAG_SHIFT)); if (unlikely(rem != 0)) - TRACE(TRACE_MINOR, "Reminder %d for expected transfer len dif! (cmd %p, op %s, expected len full %d)", + TRACE(TRACE_MINOR, + "Reminder %d for expected transfer len dif! (cmd %p, op %s, expected len full %d)", rem, cmd, scst_get_opcode_name(cmd), cmd->expected_transfer_len_full); @@ -6162,7 +6169,8 @@ static void scst_complete_request_sense(struct scst_cmd *req_cmd) if (scsi_status_is_good(req_cmd->status) && len > 0 && scst_sense_valid(buf)) { - TRACE(TRACE_SCSI | TRACE_MGMT_DEBUG, "REQUEST SENSE %p returned valid sense (orig cmd %s)", + TRACE(TRACE_SCSI | TRACE_MGMT_DEBUG, + "REQUEST SENSE %p returned valid sense (orig cmd %s)", req_cmd, orig_cmd->op_name); PRINT_BUFF_FLAG(TRACE_SCSI | TRACE_MGMT_DEBUG, "Sense", buf, len); if (scst_no_sense(buf)) @@ -9666,7 +9674,8 @@ static void scst_check_fail_ref_tag(struct scst_cmd *cmd) if (((cmd->dev->dev_dif_mode & SCST_DIF_MODE_TGT) == 0) && (checks & SCST_DIF_CHECK_REF_TAG)) { - TRACE(TRACE_SCSI | TRACE_MINOR, "No tgt dif_mode, failing cmd %p with ref tag check failed", + TRACE(TRACE_SCSI | TRACE_MINOR, + "No tgt dif_mode, failing cmd %p with ref tag check failed", cmd); scst_dif_acc_ref_check_failed_scst(cmd); scst_set_cmd_error(cmd, @@ -9680,7 +9689,8 @@ static void scst_check_fail_guard_tag(struct scst_cmd *cmd) if (((cmd->dev->dev_dif_mode & SCST_DIF_MODE_TGT) == 0) && (checks & SCST_DIF_CHECK_GUARD_TAG)) { - TRACE(TRACE_SCSI | TRACE_MINOR, "No tgt dif_mode, failing cmd %p with guard tag check failed", + TRACE(TRACE_SCSI | TRACE_MINOR, + "No tgt dif_mode, failing cmd %p with guard tag check failed", cmd); scst_dif_acc_guard_check_failed_scst(cmd); scst_set_cmd_error(cmd, @@ -10502,14 +10512,12 @@ static int scst_init_dif_actions(struct scst_device *dev) SCST_DIF_ACTION_STRIP); scst_set_scst_dif_action(&dev->dev_dif_rd_prot0_actions, SCST_DIF_ACTION_PASS_CHECK); - if (dev->dev_dif_mode & SCST_DIF_MODE_DEV_CHECK) { - /* STORE might be set as well */ - scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, - SCST_DIF_ACTION_PASS_CHECK); - } else { - scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, - SCST_DIF_ACTION_PASS); - } + /* STORE might be set as well */ + scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, + (dev->dev_dif_mode & + SCST_DIF_MODE_DEV_CHECK) ? + SCST_DIF_ACTION_PASS_CHECK : + SCST_DIF_ACTION_PASS); } scst_set_tgt_dif_action(&dev->dev_dif_wr_actions, @@ -10600,14 +10608,12 @@ static int scst_init_dif_actions(struct scst_device *dev) SCST_DIF_ACTION_STRIP); scst_set_scst_dif_action(&dev->dev_dif_rd_prot0_actions, SCST_DIF_ACTION_PASS); - if (dev->dev_dif_mode & SCST_DIF_MODE_DEV_CHECK) { - /* STORE might be set as well */ - scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, - SCST_DIF_ACTION_PASS_CHECK); - } else { - scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, - SCST_DIF_ACTION_PASS); - } + /* STORE might be set as well */ + scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, + (dev->dev_dif_mode & + SCST_DIF_MODE_DEV_CHECK) ? + SCST_DIF_ACTION_PASS_CHECK : + SCST_DIF_ACTION_PASS); } scst_set_tgt_dif_action(&dev->dev_dif_wr_actions, @@ -10706,14 +10712,12 @@ static int scst_init_dif_actions(struct scst_device *dev) } else { scst_set_scst_dif_action(&dev->dev_dif_rd_prot0_actions, SCST_DIF_ACTION_STRIP); - if (dev->dev_dif_mode & SCST_DIF_MODE_DEV_CHECK) { - /* STORE might be set as well */ - scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, - SCST_DIF_ACTION_PASS_CHECK); - } else { - scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, - SCST_DIF_ACTION_PASS); - } + /* STORE might be set as well */ + scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, + (dev->dev_dif_mode & + SCST_DIF_MODE_DEV_CHECK) ? + SCST_DIF_ACTION_PASS_CHECK : + SCST_DIF_ACTION_PASS); } scst_set_tgt_dif_action(&dev->dev_dif_wr_actions, @@ -10795,14 +10799,12 @@ static int scst_init_dif_actions(struct scst_device *dev) } else { scst_set_scst_dif_action(&dev->dev_dif_rd_prot0_actions, SCST_DIF_ACTION_PASS); - if (dev->dev_dif_mode & SCST_DIF_MODE_DEV_CHECK) { - /* STORE might be set as well */ - scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, - SCST_DIF_ACTION_PASS_CHECK); - } else { - scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, - SCST_DIF_ACTION_PASS); - } + /* STORE might be set as well */ + scst_set_dev_dif_action(&dev->dev_dif_rd_prot0_actions, + (dev->dev_dif_mode & + SCST_DIF_MODE_DEV_CHECK) ? + SCST_DIF_ACTION_PASS_CHECK : + SCST_DIF_ACTION_PASS); } scst_set_tgt_dif_action(&dev->dev_dif_wr_actions, @@ -11061,7 +11063,8 @@ static int scst_parse_rdprotect(struct scst_cmd *cmd) } if (unlikely(dev->dev_dif_type == 2 && rdprotect != 0)) { - TRACE(TRACE_SCSI | TRACE_MINOR, "Non-32-byte CDBs with non-zero rdprotect (%d) are not allowed in DIF type 2 (dev %s, cmd %p, op %s)", + TRACE(TRACE_SCSI | TRACE_MINOR, + "Non-32-byte CDBs with non-zero rdprotect (%d) are not allowed in DIF type 2 (dev %s, cmd %p, op %s)", rdprotect, dev->virt_name, cmd, scst_get_opcode_name(cmd)); scst_set_cmd_error(cmd, @@ -11127,7 +11130,8 @@ static int scst_parse_rdprotect32(struct scst_cmd *cmd) TRACE_ENTRY(); if (unlikely(dev->dev_dif_type != 2)) { - TRACE(TRACE_SCSI | TRACE_MINOR, "32-byte CDBs are not allowed in DIF type %d (dev %s, cmd %p, op %s)", + TRACE(TRACE_SCSI | TRACE_MINOR, + "32-byte CDBs are not allowed in DIF type %d (dev %s, cmd %p, op %s)", dev->dev_dif_type, dev->virt_name, cmd, scst_get_opcode_name(cmd)); scst_set_cmd_error(cmd, @@ -11234,7 +11238,8 @@ static int scst_parse_wrprotect(struct scst_cmd *cmd) } if (unlikely(dev->dev_dif_type == 2 && wrprotect != 0)) { - TRACE(TRACE_SCSI | TRACE_MINOR, "Non-32-byte CDBs with non-zero wrprotect (%d) are not allowed in DIF type 2 (dev %s, cmd %p, op %s)", + TRACE(TRACE_SCSI | TRACE_MINOR, + "Non-32-byte CDBs with non-zero wrprotect (%d) are not allowed in DIF type 2 (dev %s, cmd %p, op %s)", wrprotect, dev->virt_name, cmd, scst_get_opcode_name(cmd)); scst_set_cmd_error(cmd, @@ -11263,7 +11268,8 @@ static int scst_parse_wrprotect32(struct scst_cmd *cmd) TRACE_ENTRY(); if (unlikely(dev->dev_dif_type != 2)) { - TRACE(TRACE_SCSI | TRACE_MINOR, "32-byte CDBs are not allowed in DIF type %d (dev %s, cmd %p, op %s)", + TRACE(TRACE_SCSI | TRACE_MINOR, + "32-byte CDBs are not allowed in DIF type %d (dev %s, cmd %p, op %s)", dev->dev_dif_type, dev->virt_name, cmd, scst_get_opcode_name(cmd)); scst_set_cmd_error(cmd, @@ -11320,7 +11326,8 @@ static int __scst_parse_vrprotect(struct scst_cmd *cmd, int vrprotect_offs) cmd->cmd_dif_actions = SCST_DIF_CHECK_GUARD_TAG; break; default: - TRACE(TRACE_SCSI | TRACE_MINOR, "Invalid VRPROTECT value %x (dev %s, cmd %p)", + TRACE(TRACE_SCSI | TRACE_MINOR, + "Invalid VRPROTECT value %x (dev %s, cmd %p)", vrprotect, dev->virt_name, cmd); scst_set_invalid_field_in_cdb(cmd, vrprotect_offs, 5 | SCST_INVAL_FIELD_BIT_OFFS_VALID); @@ -11347,7 +11354,8 @@ static int __scst_parse_vrprotect(struct scst_cmd *cmd, int vrprotect_offs) cmd->cmd_dif_actions = 0; break; default: - TRACE(TRACE_SCSI | TRACE_MINOR, "Invalid VRPROTECT value %x (dev %s, cmd %p)", + TRACE(TRACE_SCSI | TRACE_MINOR, + "Invalid VRPROTECT value %x (dev %s, cmd %p)", vrprotect, dev->virt_name, cmd); scst_set_invalid_field_in_cdb(cmd, vrprotect_offs, 5 | SCST_INVAL_FIELD_BIT_OFFS_VALID); @@ -11395,7 +11403,8 @@ static int scst_parse_vrprotect(struct scst_cmd *cmd) } if (unlikely(dev->dev_dif_type == 2 && vrprotect != 0)) { - TRACE(TRACE_SCSI | TRACE_MINOR, "Non-32-byte CDBs with non-zero vrprotect (%d) are not allowed in DIF type 2 (dev %s, cmd %p, op %s)", + TRACE(TRACE_SCSI | TRACE_MINOR, + "Non-32-byte CDBs with non-zero vrprotect (%d) are not allowed in DIF type 2 (dev %s, cmd %p, op %s)", vrprotect, dev->virt_name, cmd, scst_get_opcode_name(cmd)); scst_set_cmd_error(cmd, @@ -11423,7 +11432,8 @@ static int scst_parse_vrprotect32(struct scst_cmd *cmd) TRACE_ENTRY(); if (unlikely(dev->dev_dif_type != 2)) { - TRACE(TRACE_SCSI | TRACE_MINOR, "32-byte CDBs are not allowed in DIF type %d (dev %s, cmd %p, op %s)", + TRACE(TRACE_SCSI | TRACE_MINOR, + "32-byte CDBs are not allowed in DIF type %d (dev %s, cmd %p, op %s)", dev->dev_dif_type, dev->virt_name, cmd, scst_get_opcode_name(cmd)); scst_set_cmd_error(cmd, @@ -13504,7 +13514,8 @@ static void scst_alloc_set_UA(struct scst_tgt_dev *tgt_dev, UA_entry->global_UA = (flags & SCST_SET_UA_FLAG_GLOBAL) != 0; - TRACE(TRACE_MGMT_DEBUG | TRACE_SCSI, "Queuing new %sUA %p (%x:%x:%x, d_sense %d) to tgt_dev %p (dev %s, initiator %s)", + TRACE(TRACE_MGMT_DEBUG | TRACE_SCSI, + "Queuing new %sUA %p (%x:%x:%x, d_sense %d) to tgt_dev %p (dev %s, initiator %s)", UA_entry->global_UA ? "global " : "", UA_entry, sense[2], sense[12], sense[13], tgt_dev->dev->d_sense, tgt_dev, tgt_dev->dev->virt_name, tgt_dev->sess->initiator_name); @@ -14156,7 +14167,6 @@ out: TRACE_EXIT(); } - /* dev_lock supposed to be locked and BHs off */ static void scst_abort_cmds_tgt_dev(struct scst_tgt_dev *tgt_dev, struct scst_cmd *exclude_cmd) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 9025d76..9be0b29 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -46,10 +46,7 @@ #define DEFAULT_SYMBOL_NAMESPACE SCST_NAMESPACE #if defined(CONFIG_HIGHMEM4G) || defined(CONFIG_HIGHMEM64G) -#warning HIGHMEM kernel configurations are fully supported, but not \ -recommended for performance reasons. Consider changing VMSPLIT \ -option or use a 64 - bit configuration instead. See README file for \ -details. +#warning "HIGHMEM is supported; for better performance, change VMSPLIT or use 64-bit. See README." #endif /* diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 0f86347..6bbf047 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -860,7 +860,8 @@ static ssize_t scst_tgtt_mgmt_show(struct kobject *kobj, struct kobj_attribute * " echo \"del_attribute <attribute> <value>\" >mgmt\n" : "", tgtt->tgt_optional_attributes ? " echo \"add_target_attribute target_name <attribute> <value>\" >mgmt\n" - " echo \"del_target_attribute target_name <attribute> <value>\" >mgmt\n" : "", + " echo \"del_target_attribute target_name <attribute> <value>\" >mgmt\n" + : "", tgtt->mgmt_cmd_help ? tgtt->mgmt_cmd_help : "", tgtt->mgmt_cmd_help ? "\n" : "", tgtt->add_target_parameters ? @@ -5923,7 +5924,8 @@ static ssize_t scst_devt_mgmt_show(struct kobject *kobj, struct kobj_attribute * " echo \"del_attribute <attribute> <value>\" >mgmt\n" : "", devt->dev_optional_attributes ? " echo \"add_device_attribute device_name <attribute> <value>\" >mgmt\n" - " echo \"del_device_attribute device_name <attribute> <value>\" >mgmt\n" : "", + " echo \"del_device_attribute device_name <attribute> <value>\" >mgmt\n" + : "", devt->mgmt_cmd_help ? devt->mgmt_cmd_help : "", devt->mgmt_cmd_help ? "\n" : "", p ?: "", diff --git a/scst_local/scst_local.c b/scst_local/scst_local.c index cb5fa55..fd3ab08 100644 --- a/scst_local/scst_local.c +++ b/scst_local/scst_local.c @@ -48,10 +48,7 @@ static inline u32 blk_mq_unique_tag(struct request *rq) #ifndef INSIDE_KERNEL_TREE #if defined(CONFIG_HIGHMEM4G) || defined(CONFIG_HIGHMEM64G) -#warning HIGHMEM kernel configurations are not supported by this module, \ -because nowadays it is not worth the effort. Consider changing \ -VMSPLIT option or use a 64 - bit configuration instead. See SCST core \ -README file for details. +#warning "HIGHMEM is unsupported; change VMSPLIT or use a 64-bit kernel. See SCST core README." #endif #endif diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 2037408..d9605a2 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -2071,10 +2071,10 @@ static void srpt_process_send_completion(struct ib_cq *cq, pr_info("RDMA t %d for idx %u failed with status %d.%s\n", opcode, index, wc->status, wc->status == IB_WC_RETRY_EXC_ERR ? - " If this has not been triggered by a cable pull, please consider to increase the subnet timeout parameter on the IB switch." : - wc->status == IB_WC_WR_FLUSH_ERR ? - " If this has not been triggered by a cable pull, please check the involved IB HCA's and cables." : - ""); + " If this has not been triggered by a cable pull, please consider to increase the subnet timeout parameter on the IB switch." + : wc->status == IB_WC_WR_FLUSH_ERR ? + " If this has not been triggered by a cable pull, please check the involved IB HCA's and cables." + : ""); srpt_handle_rdma_err_comp(ch, ch->ioctx_ring[index], opcode, srpt_xmt_rsp_context); } else if (opcode == SRPT_RDMA_ZEROLENGTH_WRITE) { diff --git a/usr/fileio/common.c b/usr/fileio/common.c index eaafabd..7491715 100644 --- a/usr/fileio/common.c +++ b/usr/fileio/common.c @@ -295,7 +295,8 @@ static int do_exec(struct vdisk_cmd *vcmd) ", data_len %" PRId64, vcmd->cmd->cmd_h, cmd->pbuf, lba_start, (uint64_t)loff, data_len); if (loff < 0 || data_len < 0 || ((loff + data_len) > dev->file_size)) { - PRINT_INFO("Access beyond the end of the device (%" PRId64 " of %" PRId64 ", len %" PRId64 ")", + PRINT_INFO("Access beyond the end of the device (%" PRId64 " of %" PRId64 + ", len %" PRId64 ")", (uint64_t)loff, (uint64_t)dev->file_size, data_len); set_cmd_error(vcmd, SCST_LOAD_SENSE(scst_sense_block_out_range_error)); @@ -381,7 +382,8 @@ static int do_exec(struct vdisk_cmd *vcmd) if (data_len == 0) data_len = dev->file_size - ((loff_t)lba_start << dev->block_shift); - TRACE(TRACE_ORDER, "SYNCHRONIZE_CACHE: loff=%" PRId64 ", data_len=%" PRId64 ", immed=%d", + TRACE(TRACE_ORDER, + "SYNCHRONIZE_CACHE: loff=%" PRId64 ", data_len=%" PRId64 ", immed=%d", (uint64_t)loff, data_len, immed); /* ToDo: execute immediate synchronization in the background. */ exec_fsync(vcmd); @@ -458,7 +460,8 @@ static int do_alloc_mem(struct vdisk_cmd *vcmd) TRACE_ENTRY(); - TRACE_MEM("Alloc mem (cmd %d, sess_h %" PRIx64 ", cdb_len %d, alloc_len %d, queue_type %d, data_direction %d)", + TRACE_MEM("Alloc mem (cmd %d, sess_h %" PRIx64 + ", cdb_len %d, alloc_len %d, queue_type %d, data_direction %d)", cmd->cmd_h, cmd->alloc_cmd.sess_h, cmd->alloc_cmd.cdb_len, cmd->alloc_cmd.alloc_len, cmd->alloc_cmd.queue_type, cmd->alloc_cmd.data_direction); @@ -656,7 +659,8 @@ static int do_sess(struct vdisk_cmd *vcmd) tgt_dev->sess_h = cmd->sess.sess_h; - PRINT_INFO("Session from initiator %s (target %s) attached (LUN %" PRIx64 ", threads_num %d, rd_only %d, sess_h %" PRIx64 ")", + PRINT_INFO("Session from initiator %s (target %s) attached (LUN %" PRIx64 + ", threads_num %d, rd_only %d, sess_h %" PRIx64 ")", cmd->sess.initiator_name, cmd->sess.target_name, cmd->sess.lun, cmd->sess.threads_num, cmd->sess.rd_only, diff --git a/usr/fileio/fileio.c b/usr/fileio/fileio.c index 95ed9c2..01afd95 100644 --- a/usr/fileio/fileio.c +++ b/usr/fileio/fileio.c @@ -354,7 +354,8 @@ static int start(int argc, char **argv) close(fd); PRINT_INFO("%s", " "); - PRINT_INFO("Virtual device \"%s\", path \"%s\", size %" PRId64 "MB, block size %d, nblocks %" PRId64 ", options:", + PRINT_INFO("Virtual device \"%s\", path \"%s\", size %" PRId64 + "MB, block size %d, nblocks %" PRId64 ", options:", devs[i].name, devs[i].file_name, (uint64_t)devs[i].file_size / 1024 / 1024, devs[i].block_size, (uint64_t)devs[i].nblocks); |
|
From: SCST G. <lna...@ya...> - 2026-10-22 16:07:10
|
Commit: d3a2105 GitHub URL: https://github.com/SCST-project/scst/commit/d3a21054ddfa1df2e12c29d6305285de67711cc4 Author: Gleb Chesnokov Date: 2026-10-22T19:04:12+03:00 Log Message: ----------- scst_lib: Fix comparison unmapping on older vendor kernels The scatterlist comparison refactor made saddr and daddr const, but the native kunmap_local() implementations in supported older vendor kernels forward their argument to __kunmap_local(void *addr). With WERROR=y, package builds fail on Oracle Linux 9 UEK 5.15.0-325.221.6.4.el9uek.x86_64 and Rocky Linux 8.10 4.18.0-553.174.1.el8_10.x86_64 with four instances of: error: passing argument 1 of '__kunmap_local' discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers] Keep the mapping addresses as u8 *, matching the mutable pointer returned by kmap_local_page(). This fixes both normal and mismatch unmapping paths. The comparison remains read-only, and scst_miscompare_offset() retains its const-qualified inputs. No mapping lifetime or comparison behavior changes. Fixes: 32af569f3802 ("scst_lib: Separate byte comparison from scatterlist traversal") Modified Paths: -------------- scst/src/scst_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) =================================================================== diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 2e2f014..c791e02 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -9156,7 +9156,7 @@ int sg_cmp_elem(struct scatterlist **pdst_sg, size_t *pdst_len, struct scatterlist *dst_sg; size_t src_len, dst_len, src_offs, dst_offs; struct page *src_page, *dst_page; - const u8 *saddr, *daddr; + u8 *saddr, *daddr; *cmp_res = true; |
|
From: SCST G. <lna...@ya...> - 2026-10-22 14:59:11
|
Commit: da55c81 GitHub URL: https://github.com/SCST-project/scst/commit/da55c8106867fa49b989845b6488f58ff4cc12f6 Author: Gleb Chesnokov Date: 2026-10-22T17:58:45+03:00 Log Message: ----------- scst/include/backport.h: Fix secs_to_jiffies availability checks Package builds report: backport.h:896: error: "secs_to_jiffies" redefined [-Werror] This affects Rocky 6.12.0-211.66.1.el10_2, Ubuntu 6.8.0-147-generic and Oracle UEK 5.15.0-325.221.6.4.el9uek. Their jiffies.h already provides the helper, but our fallback only excluded upstream 6.13 and UEK 6.12. Adding outer parentheses made the duplicate definitions differ and exposed the incomplete availability check. Retain the parenthesized fallback and use the native helper on stable 5.15.217, 6.1.178, 6.6.145 and 6.12.97 or later in each stable line, the supported RHEL 8.10, 9.7 and 10.1 kernels, and Ubuntu 6.8 ABI 147 or later. Keep RHEL 10.0 separate from RHEL 9.7, and do not apply the Ubuntu generic ABI range to the separately numbered cloud flavours. UEK 7 does not expose a numeric update version. Use FMODE_FSNOTIFY_HSM from linux/fs.h to distinguish the updates that also introduced secs_to_jiffies: 5.15.0-325.217.3 and 5.15.0-324.217.5.1. The marker is absent in the preceding releases inspected for each UEK branch. For RHEL 8.10, use the release version in line with the supported kernel matrix, which lists 4.18.0-553.174.1. Older 8.10 updates that precede the helper backport are outside that matrix. Keep the existing UEK 6.12 exclusion. Do not test whether secs_to_jiffies itself is defined or replace a native definition. Fixes: dc8110b5c328 ("scst: Evaluate cache and compatibility macro operands once") Modified Paths: -------------- scst/include/backport.h | 34 +++++++++++++-- 1 file changed, 30 insertions(+), 4 deletions(-) =================================================================== diff --git a/scst/include/backport.h b/scst/include/backport.h index 16857c2..3b1f848 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -46,6 +46,7 @@ #include <linux/debugfs.h> #include <linux/dmapool.h> #include <linux/eventpoll.h> +#include <linux/fs.h> #include <linux/highmem.h> #include <linux/iocontext.h> #include <linux/jiffies.h> @@ -887,12 +888,37 @@ static inline long pin_user_pages_backport(unsigned long start, #define time_is_before_jiffies64(a) time_after64(get_jiffies_64(), a) #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 13, 0) && \ - (!defined(UEK_KABI_RENAME) || \ - LINUX_VERSION_CODE < KERNEL_VERSION(6, 12, 0)) /* * See also commit b35108a51cf7 ("jiffies: Define secs_to_jiffies()") # v6.13. - */ + * See also commit 5dc96cd93818 # v6.12.97. + * See also commit a48236b8889e # v6.6.145. + * See also commit 9e107c549965 # v6.1.178. + * See also commit 10d4df898c9c # v5.15.217. + * See also commit 841654961528 # RHEL 10.1. + * See also commit 929d63667813 # RHEL 9.7. + * See also commit 8ab7dbdc77d7 # UEK-5.15.0-325.217.3. + * UEK 7 gained this helper together with FMODE_FSNOTIFY_HSM. Use that + * marker to retain the fallback on older UEK updates. + */ +#if !(LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 97) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 145) && \ + LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0)) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 178) && \ + LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 217) && \ + LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)) || \ + (defined(RHEL_MAJOR) && \ + ((RHEL_MAJOR - 0 == 8 && RHEL_MINOR - 0 >= 10) || \ + (RHEL_MAJOR - 0 == 9 && RHEL_MINOR - 0 >= 7) || \ + (RHEL_MAJOR - 0 == 10 && RHEL_MINOR - 0 >= 1))) || \ + (defined(UEK_KABI_RENAME) && \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0) || \ + (LINUX_VERSION_CODE == KERNEL_VERSION(5, 15, 0) && \ + defined(FMODE_FSNOTIFY_HSM)))) || \ + (defined(UTS_UBUNTU_RELEASE_ABI) && \ + LINUX_VERSION_CODE >> 8 == KERNEL_VERSION(6, 8, 0) >> 8 && \ + UTS_UBUNTU_RELEASE_ABI - 0 >= 147 && \ + UTS_UBUNTU_RELEASE_ABI - 0 < 999)) #define secs_to_jiffies(_secs) ((unsigned long)((_secs) * HZ)) #endif |
|
From: SCST G. <lna...@ya...> - 2026-10-21 16:52:16
|
Commit: 60ff16e GitHub URL: https://github.com/SCST-project/scst/commit/60ff16ef4feb15419c288627ab7fd2893e21f7b1 Author: Gleb Chesnokov Date: 2026-10-21T19:48:40+03:00 Log Message: ----------- scst/include/backport.h: Allow resurrection with active references Found by manual code inspection, not by an analyzer or a runtime test. When scst_suspend_activity() times out with commands still active, __scst_resume_activity() revives the command and management counters. The old wrapper calls percpu_ref_reinit(), whose zero-count requirement is enforced by this kernel assertion: WARN_ON_ONCE(!percpu_ref_is_zero(ref)); Upstream 3.18-4.19 and the retained EL7/UEK4/UEK5 implementations preserve the per-CPU allocation and use long counters, but reinit still rejects this legitimate nonzero resurrection. Restore the initial reference additively, retain outstanding references, and restore per-CPU operation with the kernel's bias, counter clearing and release-store ordering. Keep explicitly forced atomic mode unchanged. SCST serializes kill and resurrection with scst_suspend_mutex and keeps both counters alive even when their release callbacks run. Require the same external serialization for mode changes and exit. Concurrent gets and puts remain allowed. Kill confirmation can wake the caller before confirm_switch is cleared. Drain a pending switch callback with rcu_barrier_sched() before reusing the counters. The kernel switch waitqueue is private, and older kernels do not export percpu_ref_switch_to_percpu(). This conditional barrier can also wait for unrelated RCU callbacks; it is skipped once the switch has completed. Native resurrection on 4.20+ and EL8+ remains unchanged. Add scst-LIB-percpu-ref to scst.ko with private, real kernel counters. Keep the backport helper available to KUnit on modern kernels, using their counter layout and unified RCU API. Cover immediate resurrection with active refs, resurrection after draining, forced atomic mode, and repeated suspend cancellations with commands completing while dead. Also fix the fake Kbuild cleaner used by the Python tooling tests. CI reported test_cleanup_without_packaged_tooling failing with "find: cannot delete .../isert-scst.ko: No such file or directory". iSCSI cleans kernel/ and kernel/isert-scst/ concurrently, so one fixture find can remove an artifact after the other has enumerated it. Use -ignore_readdir_race to tolerate only vanished files, matching Kbuild's idempotent rm -f behavior. Keep other find errors and the injected FAIL_CLEAN failure fatal; retain parallel cleanup and artifact checks. Tests, builds and VM validation were not run, as requested. Modified Paths: -------------- scripts/kunit/test_clean.py | 5 +- scst/include/backport.h | 63 ++++- scst/src/kunit/lib/suites/scst_kunit_percpu_ref.c | 215 +++++++++++++++ scst/src/kunit/objects.mk | 1 + 4 files changed, 279 insertions(+), 5 deletions(-) =================================================================== diff --git a/scripts/kunit/test_clean.py b/scripts/kunit/test_clean.py index cdc60b6..d43a8d7 100644 --- a/scripts/kunit/test_clean.py +++ b/scripts/kunit/test_clean.py @@ -35,10 +35,13 @@ class CleanTests(unittest.TestCase): (target / 'visited.o').touch() kernel = root / 'kernel' kernel.mkdir() + # iSCSI cleans kernel/ and kernel/isert-scst/ concurrently. Like + # Kbuild's rm -f, tolerate artifacts already removed by a peer. (kernel / 'Makefile').write_text( 'clean:\n' '\t@test "$(FAIL_CLEAN)" != y\n' - '\t@find "$(M)" -type f \\( -name "*.o" -o -name "*.ko" \\) -delete\n') + '\t@find "$(M)" -ignore_readdir_race -type f ' + '\\( -name "*.o" -o -name "*.ko" \\) -delete\n') artifacts = ['scst/src/scst.ko', 'scst/src/kunit/lib/suites/test.o', 'scst/src/dev_handlers/scst_vdisk.ko', 'scst/src/dev_handlers/kunit/vdisk/suites/test.o', diff --git a/scst/include/backport.h b/scst/include/backport.h index b9a96d9..15418a1 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -53,6 +53,7 @@ #endif #include <linux/percpu-refcount.h> #include <linux/preempt.h> +#include <linux/rcupdate.h> #include <linux/scatterlist.h> /* struct scatterlist */ #include <linux/shrinker.h> #include <linux/slab.h> /* kmalloc() */ @@ -1325,18 +1326,72 @@ typedef unsigned long percpu_count_t; #define READ_REF_COUNT(ref) atomic_long_read(&(ref)->data->count) #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 8) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) && \ + (!defined(RHEL_MAJOR) || RHEL_MAJOR - 0 < 8)) || \ + defined(SCST_KUNIT_ENABLED) /* * See also commit 18c9a6bbe064 ("percpu-refcount: Introduce * percpu_ref_resurrect()") # v4.20. + * + * The caller must serialize kill, resurrection, mode switches and exit, and + * keep ref alive even if its release callback runs. This helper may sleep. + * SCST holds scst_suspend_mutex and uses persistent command counters. Gets + * and puts may run concurrently. + * + * Keep this implementation available to KUnit on newer kernels so the tests + * exercise the backport with real kernel counters and RCU callbacks. */ -static inline void percpu_ref_resurrect(struct percpu_ref *ref) +static inline void scst_percpu_ref_resurrect_backport(struct percpu_ref *ref) { - percpu_ref_reinit(ref); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0) + struct percpu_ref_data *data = ref->data; +#else + struct percpu_ref *data = ref; +#endif + unsigned long __percpu *percpu_count; + unsigned long ptr; + int cpu; + + /* + * The kill confirmation can wake the caller before confirm_switch is + * cleared. The kernel's switch waitqueue is private, and older kernels + * do not export switch_to_percpu(). Drain a pending callback before + * reusing the per-CPU counters. The supported pre-4.20 implementations, + * including EL7 and UEK4/UEK5, use call_rcu_sched(). + */ + if (READ_ONCE(data->confirm_switch)) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) + rcu_barrier_sched(); +#else + rcu_barrier(); +#endif + } + + ptr = READ_ONCE(ref->percpu_count_ptr); + percpu_count = (unsigned long __percpu *)(ptr & ~__PERCPU_REF_ATOMIC_DEAD); + if (WARN_ON_ONCE((ptr & __PERCPU_REF_ATOMIC_DEAD) != __PERCPU_REF_ATOMIC_DEAD || + !percpu_count)) + return; + + /* Restore the initial reference without discarding outstanding refs. */ + atomic_long_inc(&data->count); + if (!data->force_atomic) { + atomic_long_add(1UL << (BITS_PER_LONG - 1), &data->count); + for_each_possible_cpu(cpu) + *per_cpu_ptr(percpu_count, cpu) = 0; + ptr &= ~__PERCPU_REF_ATOMIC; + } + + /* Publish initialized counters before allowing new live acquisitions. */ + smp_store_release(&ref->percpu_count_ptr, ptr & ~__PERCPU_REF_DEAD); } #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) && \ + (!defined(RHEL_MAJOR) || RHEL_MAJOR - 0 < 8) +#define percpu_ref_resurrect scst_percpu_ref_resurrect_backport +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) && !defined(RHEL_MAJOR) /* * See also commit 4c907baf36d8 ("percpu_ref: implement percpu_ref_is_dying()") diff --git a/scst/src/kunit/lib/suites/scst_kunit_percpu_ref.c b/scst/src/kunit/lib/suites/scst_kunit_percpu_ref.c new file mode 100644 index 0000000..94932c9 --- /dev/null +++ b/scst/src/kunit/lib/suites/scst_kunit_percpu_ref.c @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include "../../scst_kunit.h" + +#ifdef INSIDE_KERNEL_TREE +#include <scst/scst.h> +#else +#include "scst.h" +#endif + +struct percpu_ref_fixture { + struct percpu_ref ref; + atomic_t releases; + atomic_t confirmations; + unsigned int held; + bool initialized; + bool dead; +}; + +static void percpu_test_release(struct percpu_ref *ref) +{ + struct percpu_ref_fixture *f = container_of(ref, struct percpu_ref_fixture, ref); + + /* Like the SCST command counters, the fixture outlives zero references. */ + atomic_inc(&f->releases); +} + +static void percpu_test_confirm(struct percpu_ref *ref) +{ + struct percpu_ref_fixture *f = container_of(ref, struct percpu_ref_fixture, ref); + + atomic_inc(&f->confirmations); +} + +static int percpu_test_init(struct kunit *test) +{ + struct percpu_ref_fixture *f; + + f = kunit_kzalloc(test, sizeof(*f), GFP_KERNEL); + if (!f) + return -ENOMEM; + atomic_set(&f->releases, 0); + atomic_set(&f->confirmations, 0); + test->priv = f; + return 0; +} + +static int percpu_test_start(struct kunit *test, unsigned int flags) +{ + struct percpu_ref_fixture *f = test->priv; + int ret; + + ret = percpu_ref_init(&f->ref, percpu_test_release, + flags | PERCPU_REF_ALLOW_REINIT, GFP_KERNEL); + if (!ret) + f->initialized = true; + return ret; +} + +static void percpu_test_get(struct percpu_ref_fixture *f) +{ + percpu_ref_get(&f->ref); + f->held++; +} + +static void percpu_test_put(struct percpu_ref_fixture *f) +{ + f->held--; + percpu_ref_put(&f->ref); +} + +static void percpu_test_kill(struct percpu_ref_fixture *f) +{ + f->dead = true; + percpu_ref_kill_and_confirm(&f->ref, percpu_test_confirm); +} + +static void percpu_test_resurrect(struct percpu_ref_fixture *f) +{ + /* Exercise the backport even when the running kernel has resurrect(). */ + scst_percpu_ref_resurrect_backport(&f->ref); + f->dead = percpu_ref_is_dying(&f->ref); +} + +static void percpu_test_exit(struct kunit *test) +{ + struct percpu_ref_fixture *f = test->priv; + + if (!f || !f->initialized) + return; + if (!f->dead) + percpu_test_kill(f); + /* KUnit runs on kernels using the unified RCU callback API. */ + rcu_barrier(); + while (f->held) + percpu_test_put(f); + percpu_ref_exit(&f->ref); +} + +static void percpu_resurrect_preserves_active_refs(struct kunit *test) +{ + struct percpu_ref_fixture *f = test->priv; + unsigned long allocation; + bool acquired; + + KUNIT_ASSERT_EQ(test, percpu_test_start(test, 0), 0); + allocation = f->ref.percpu_count_ptr & ~__PERCPU_REF_ATOMIC_DEAD; + percpu_test_get(f); + percpu_test_get(f); + percpu_test_get(f); + percpu_test_kill(f); + acquired = percpu_ref_tryget_live(&f->ref); + KUNIT_EXPECT_FALSE(test, acquired); + if (acquired) + percpu_ref_put(&f->ref); + + /* Do not drain RCU first: the backport must wait for a pending switch. */ + percpu_test_resurrect(f); + KUNIT_ASSERT_FALSE(test, f->dead); + KUNIT_EXPECT_EQ(test, atomic_read(&f->confirmations), 1); + KUNIT_EXPECT_EQ(test, atomic_read(&f->releases), 0); + KUNIT_EXPECT_EQ(test, f->ref.percpu_count_ptr, allocation); + acquired = percpu_ref_tryget_live(&f->ref); + KUNIT_EXPECT_TRUE(test, acquired); + if (acquired) + percpu_ref_put(&f->ref); + + /* Regather the counters to detect lost refs or stale per-CPU values. */ + percpu_test_kill(f); + rcu_barrier(); + KUNIT_EXPECT_EQ(test, READ_REF_COUNT(&f->ref), 3L); + KUNIT_EXPECT_EQ(test, atomic_read(&f->releases), 0); + while (f->held) + percpu_test_put(f); + KUNIT_EXPECT_TRUE(test, percpu_ref_is_zero(&f->ref)); + KUNIT_EXPECT_EQ(test, atomic_read(&f->releases), 1); +} + +static void percpu_resurrect_after_drain(struct kunit *test) +{ + struct percpu_ref_fixture *f = test->priv; + unsigned int cycle; + + KUNIT_ASSERT_EQ(test, percpu_test_start(test, 0), 0); + for (cycle = 0; cycle < 3; cycle++) { + percpu_test_kill(f); + rcu_barrier(); + KUNIT_EXPECT_TRUE(test, percpu_ref_is_zero(&f->ref)); + KUNIT_EXPECT_EQ(test, atomic_read(&f->releases), (int)cycle + 1); + percpu_test_resurrect(f); + KUNIT_ASSERT_FALSE(test, f->dead); + KUNIT_EXPECT_FALSE(test, percpu_ref_is_zero(&f->ref)); + } +} + +static void percpu_resurrect_keeps_atomic_mode(struct kunit *test) +{ + struct percpu_ref_fixture *f = test->priv; + + KUNIT_ASSERT_EQ(test, percpu_test_start(test, PERCPU_REF_INIT_ATOMIC), 0); + percpu_test_get(f); + percpu_test_get(f); + percpu_test_kill(f); + percpu_test_resurrect(f); + KUNIT_ASSERT_FALSE(test, f->dead); + KUNIT_EXPECT_TRUE(test, f->ref.percpu_count_ptr & __PERCPU_REF_ATOMIC); + KUNIT_EXPECT_EQ(test, READ_REF_COUNT(&f->ref), 3L); + KUNIT_EXPECT_EQ(test, atomic_read(&f->releases), 0); + percpu_test_kill(f); + rcu_barrier(); + KUNIT_EXPECT_EQ(test, READ_REF_COUNT(&f->ref), 2L); + while (f->held) + percpu_test_put(f); + KUNIT_EXPECT_EQ(test, atomic_read(&f->releases), 1); +} + +static void percpu_resurrect_repeated_cancellations(struct kunit *test) +{ + struct percpu_ref_fixture *f = test->priv; + unsigned int cycle; + + KUNIT_ASSERT_EQ(test, percpu_test_start(test, 0), 0); + percpu_test_get(f); + percpu_test_get(f); + for (cycle = 0; cycle < 5; cycle++) { + percpu_test_kill(f); + rcu_barrier(); + KUNIT_EXPECT_EQ(test, READ_REF_COUNT(&f->ref), 2L); + /* One command completes while suspended; the other survives resume. */ + percpu_test_put(f); + percpu_test_resurrect(f); + KUNIT_ASSERT_FALSE(test, f->dead); + KUNIT_EXPECT_EQ(test, atomic_read(&f->releases), 0); + percpu_test_get(f); + } + percpu_test_kill(f); + rcu_barrier(); + KUNIT_EXPECT_EQ(test, READ_REF_COUNT(&f->ref), 2L); + while (f->held) + percpu_test_put(f); + KUNIT_EXPECT_EQ(test, atomic_read(&f->releases), 1); +} + +static struct kunit_case percpu_ref_cases[] = { + KUNIT_CASE(percpu_resurrect_preserves_active_refs), + KUNIT_CASE(percpu_resurrect_after_drain), + KUNIT_CASE(percpu_resurrect_keeps_atomic_mode), + KUNIT_CASE(percpu_resurrect_repeated_cancellations), + {} +}; + +scst_kunit_suite(percpu_ref_suite, "LIB", "-percpu-ref", + .init = percpu_test_init, + .exit = percpu_test_exit, + .test_cases = percpu_ref_cases, +); diff --git a/scst/src/kunit/objects.mk b/scst/src/kunit/objects.mk index ceef218..efc30db 100644 --- a/scst/src/kunit/objects.mk +++ b/scst/src/kunit/objects.mk @@ -11,6 +11,7 @@ scst-kunit-scst := \ kunit/event/suites/scst_kunit_event_delivery.o \ kunit/lib/suites/scst_kunit_capacity.o \ kunit/lib/suites/scst_kunit_lib.o \ + kunit/lib/suites/scst_kunit_percpu_ref.o \ kunit/lib/suites/scst_kunit_sgv.o \ kunit/lib/suites/scst_kunit_write_same.o \ kunit/lifecycle/suites/scst_kunit_lifecycle.o \ |
|
From: SCST G. <lna...@ya...> - 2026-10-21 16:49:20
|
Commit: d8720d6 GitHub URL: https://github.com/SCST-project/scst/commit/d8720d6662ac00cabc22916df805422835d1a126 Author: Gleb Chesnokov Date: 2026-10-21T19:48:40+03:00 Log Message: ----------- scst/include/backport.h: Remove obsolete pre-3.18 helpers The minimum upstream kernel is now 3.18, while the retained EL7 kernels already provide the newer percpu_ref layout and API. Remove the 32-bit percpu counters, the two-argument init adapter, the pre-3.17 reinit and exit helpers, and the stand-alone atomic fallback. Include the native percpu-refcount header for every supported kernel. Also remove upstream-only PTR_RET, ktime_before, kvfree, __ATTR_RW and 32Gb FC speed fallbacks, plus the obsolete 3.16 strscpy version test. These paths were already excluded for EL7. Retain old-version branches that EL7 still uses, including shrinker, RCU-head and SCSI adapters. This removes unreachable compatibility code; it does not claim an analyzer-warning fix. The supported-kernel resurrection wrapper still uses reinit and is corrected separately. Modified Paths: -------------- scst/include/backport.h | 290 +-------------- 1 file changed, 3 insertions(+), 287 deletions(-) =================================================================== diff --git a/scst/include/backport.h b/scst/include/backport.h index 98ba43e..b9a96d9 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -51,10 +51,7 @@ #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0) #include <linux/overflow.h> #endif -#if defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7 || \ - LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) #include <linux/percpu-refcount.h> -#endif #include <linux/preempt.h> #include <linux/scatterlist.h> /* struct scatterlist */ #include <linux/shrinker.h> @@ -106,15 +103,6 @@ static __always_inline unsigned long long rdtsc(void) #define tsc_khz 1000 #endif -/* <linux/err.h> */ - -/* - * See also commit 6e8b8726ad50 ("PTR_RET is now PTR_ERR_OR_ZERO") # v3.12 - */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0) && !defined(RHEL_RELEASE_CODE) -#define PTR_ERR_OR_ZERO(p) PTR_RET(p) -#endif - /* <linux/bio.h> */ #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0) && \ @@ -915,22 +903,6 @@ static inline void kobj_ns_drop_backport(enum kobj_ns_type type, void *ns) #define kref_read(kref) (atomic_read(&(kref)->refcount)) #endif -/* <linux/ktime.h> */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) && !defined(RHEL_MAJOR) -/** - * ktime_before - Compare if a ktime_t value is smaller than another one. - * @cmp1: comparable1 - * @cmp2: comparable2 - * - * Return: true if cmp1 happened before cmp2. - */ -static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2) -{ - return ktime_compare(cmp1, cmp2) < 0; -} -#endif - /* <linux/list.h> */ #ifndef __list_for_each @@ -1093,23 +1065,6 @@ static inline void *kvcalloc(size_t n, size_t size, gfp_t flags) } #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0) && \ - !(LINUX_VERSION_CODE >> 8 == KERNEL_VERSION(3, 12, 0) >> 8 && \ - LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 41)) && \ - !defined(RHEL_MAJOR) -/* - * See also commit 39f1f78d53b9 ("nick kvfree() from apparmor") # v3.15. - * See also commit fb6a2a8ebe27 ("nick kvfree() from apparmor") # v3.12.41. - */ -static inline void kvfree(void *addr) -{ - if (is_vmalloc_addr(addr)) - vfree(addr); - else - kfree(addr); -} -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) && \ (LINUX_VERSION_CODE >> 8 != KERNEL_VERSION(5, 15, 0) >> 8 || \ LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 54)) && \ @@ -1363,257 +1318,35 @@ static __always_inline size_t __must_check size_add(size_t addend1, size_t adden #define PERCPU_REF_ALLOW_REINIT 0 #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) -#define PERCPU_COUNT_BIAS (1U << 31) -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) && !defined(RHEL_MAJOR) -typedef unsigned int percpu_count_t; -#define READ_REF_COUNT(ref) atomic_read(&(ref)->count) -#else typedef unsigned long percpu_count_t; #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) #define READ_REF_COUNT(ref) atomic_long_read(&(ref)->count) #else #define READ_REF_COUNT(ref) atomic_long_read(&(ref)->data->count) #endif -#endif - -/* - * For kernel versions that have <linux/percpu-refcount.h>, backport the - * functionality that is missing from that header file. - */ -#if (defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7) || \ - LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) && \ (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 8) - /* * See also commit 18c9a6bbe064 ("percpu-refcount: Introduce * percpu_ref_resurrect()") # v4.20. */ static inline void percpu_ref_resurrect(struct percpu_ref *ref) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) || \ - (defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7) percpu_ref_reinit(ref); -#else - unsigned __percpu *pcpu_count = (unsigned __percpu *) - ((uintptr_t)ref->pcpu_count & ~PCPU_REF_DEAD); - int cpu; - - BUG_ON(!pcpu_count); - //WARN_ON(!percpu_ref_is_zero(ref)); - - atomic_set(&ref->count, 1 + PERCPU_COUNT_BIAS); - - /* - * Restore per-cpu operation. The barrier guarantees that the zeroing - * is visible to all percpu accesses which can see the following - * PCPU_REF_DEAD clearing. - */ - for_each_possible_cpu(cpu) - *per_cpu_ptr(pcpu_count, cpu) = 0; - - ref->pcpu_count = (unsigned __percpu *) - ((uintptr_t)ref->pcpu_count & ~PCPU_REF_DEAD); - smp_mb(); -#endif } +#endif -#if !(defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7) -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) && !defined(RHEL_MAJOR) /* * See also commit 4c907baf36d8 ("percpu_ref: implement percpu_ref_is_dying()") * # v4.0. */ static inline bool percpu_ref_is_dying(struct percpu_ref *ref) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) - return (uintptr_t)ref->pcpu_count & PCPU_REF_DEAD; -#else - return ref->pcpu_count_ptr & PCPU_REF_DEAD; -#endif -} -#elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) -static inline bool percpu_ref_is_dying(struct percpu_ref *ref) { return ref->percpu_count_ptr & __PERCPU_REF_DEAD; } #endif -#endif /* !(defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7) */ - -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 20, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) && \ - !(defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7) -/* - * See also commit 2aad2a86f668 ("percpu_ref: add PERCPU_REF_INIT_* flags") - * # v3.18. - */ -static inline int __must_check percpu_ref_init_backport(struct percpu_ref *ref, - percpu_ref_func_t *release, unsigned int flags, - gfp_t gfp) -{ - WARN_ON_ONCE(flags != 0); - WARN_ON_ONCE(gfp != GFP_KERNEL); - return percpu_ref_init(ref, release); -} -#define percpu_ref_init percpu_ref_init_backport - -/* - * See also commit 9e804d1f58da ("percpu_ref: rename things to prepare for - * decoupling percpu/atomic mode switch") # v3.18. - */ -static inline bool __ref_is_percpu(struct percpu_ref *ref, - percpu_count_t __percpu **percpu_countp) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) - uintptr_t pcpu_ptr = (uintptr_t)ACCESS_ONCE(ref->pcpu_count); - - if (unlikely(pcpu_ptr & PCPU_REF_DEAD)) - return false; - - *percpu_countp = (percpu_count_t __percpu *)pcpu_ptr; - return true; -#else - return __pcpu_ref_alive(ref, percpu_countp); -#endif -} -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) && \ - !(defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7) -/* - * See also commit 2d7227828e14 ("percpu-refcount: implement percpu_ref_reinit() - * and percpu_ref_is_zero()") # v3.17. - */ -static inline bool percpu_ref_is_zero(struct percpu_ref *ref) -{ - return !atomic_read(&ref->count); -} -/* - * See also commit 9a1049da9bd2 ("percpu-refcount: require percpu_ref to be - * exited explicitly") # v3.17. - */ -static inline void percpu_ref_exit(struct percpu_ref *ref) -{ -} -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) && \ - !(defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7) -static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) -{ - percpu_count_t __percpu *percpu_count; - bool ret = false; - - rcu_read_lock(); - - if (__ref_is_percpu(ref, &percpu_count)) { - this_cpu_inc(*percpu_count); - ret = true; - } else if (!percpu_ref_is_dying(ref)) { - ret = atomic_long_inc_not_zero(&ref->count); - } - - rcu_read_unlock(); - - return ret; -} -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) */ - -#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) && \ - (!defined(RHEL_MAJOR) || \ - RHEL_MAJOR -0 == 7 && RHEL_MINOR -0 < 5) - -struct percpu_ref; -typedef void (percpu_ref_func_t)(struct percpu_ref *); - -struct percpu_ref { - atomic_t count; - percpu_ref_func_t *release; - bool dead; -}; - -static inline int __must_check percpu_ref_init(struct percpu_ref *ref, - percpu_ref_func_t *release, unsigned int flags, - gfp_t gfp) -{ - WARN_ON_ONCE(flags != 0); - atomic_set(&ref->count, 1); - ref->release = release; - ref->dead = false; - return 0; -} - -static inline void percpu_ref_exit(struct percpu_ref *ref) -{ -} - -static inline void percpu_ref_get(struct percpu_ref *ref) -{ - atomic_inc(&ref->count); -} - -static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) -{ - bool ret = false; - - rcu_read_lock(); - if (!ref->dead) - ret = atomic_inc_not_zero(&ref->count); - rcu_read_unlock(); - - return ret; -} - -static inline void percpu_ref_put(struct percpu_ref *ref) -{ - if (unlikely(atomic_dec_and_test(&ref->count))) - ref->release(ref); -} - -static inline void -percpu_ref_kill_and_confirm(struct percpu_ref *ref, percpu_ref_func_t *confirm_kill) -{ - WARN_ON_ONCE(ref->dead); - ref->dead = true; - if (confirm_kill) - confirm_kill(ref); - percpu_ref_put(ref); -} - -static inline void percpu_ref_kill(struct percpu_ref *ref) -{ - percpu_ref_kill_and_confirm(ref, NULL); -} - -static inline void percpu_ref_resurrect(struct percpu_ref *ref) -{ - WARN_ON_ONCE(!ref->dead); - ref->dead = false; - percpu_ref_get(ref); -} - -static inline bool __ref_is_percpu(struct percpu_ref *ref, - unsigned __percpu **percpu_countp) -{ - *percpu_countp = NULL; - return !ref->dead; -} - -static inline bool percpu_ref_is_dying(struct percpu_ref *ref) -{ - return ref->dead; -} - -static inline bool percpu_ref_is_zero(struct percpu_ref *ref) -{ - return !atomic_read(&ref->count); -} -#endif /* Only use this function for debugging purposes. Not upstream. */ static inline unsigned long percpu_ref_read(struct percpu_ref *ref) @@ -1937,14 +1670,12 @@ static inline void *memdup_user_nul(const void __user *src, size_t len) #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) && \ - (LINUX_VERSION_CODE >> 8 != KERNEL_VERSION(3, 16, 0) >> 8 || \ - LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 60)) && \ (LINUX_VERSION_CODE >> 8 != KERNEL_VERSION(3, 18, 0) >> 8 || \ LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 64)) && \ (!defined(RHEL_RELEASE_CODE) || \ RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(7, 7)) /* - * See also commit 30035e45753b ("string: provide strscpy()") # v4.3, v3.16.60, v3.18.64. + * See also commit 30035e45753b ("string: provide strscpy()") # v4.3, v3.18.64. */ static inline ssize_t strscpy(char *dest, const char *src, size_t count) { @@ -1980,11 +1711,6 @@ static inline ssize_t strscpy(char *dest, const char *src, size_t count) /* <linux/sysfs.h> */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) && !defined(RHEL_MAJOR) -/* See also commit b9b3259746d7 ("sysfs.h: add __ATTR_RW() macro") # v3.11. */ -#define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) && \ (LINUX_VERSION_CODE >> 8 != KERNEL_VERSION(4, 9, 0) >> 8 || \ LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 260)) && \ @@ -2514,16 +2240,6 @@ static inline void *bsg_job_sense(struct bsg_job *job) /* <scsi/scsi_transport_fc.h> */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0) && !defined(RHEL_MAJOR) -/* - * See also commit 624f28be8109 ("[SCSI] scsi_transport_fc: Add 32Gbps speed - * definition.") # v3.15. - */ -enum { - FC_PORTSPEED_32GBIT = 0x40 -}; -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0) && \ !defined(FC_PORTSPEED_64GBIT) /* |