Skip to content

Commit 56b031f

Browse files
melverpaulmckrcu
authored andcommitted
kcsan: Add jiffies test to test suite
Add a test that KCSAN nor the compiler gets confused about accesses to jiffies on different architectures. Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 7e76656 commit 56b031f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

kernel/kcsan/kcsan-test.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ static noinline void test_kernel_read_struct_zero_size(void)
366366
kcsan_check_read(&test_struct.val[3], 0);
367367
}
368368

369+
static noinline void test_kernel_jiffies_reader(void)
370+
{
371+
sink_value((long)jiffies);
372+
}
373+
369374
static noinline void test_kernel_seqlock_reader(void)
370375
{
371376
unsigned int seq;
@@ -817,6 +822,23 @@ static void test_assert_exclusive_access_scoped(struct kunit *test)
817822
KUNIT_EXPECT_TRUE(test, match_expect_inscope);
818823
}
819824

825+
/*
826+
* jiffies is special (declared to be volatile) and its accesses are typically
827+
* not marked; this test ensures that the compiler nor KCSAN gets confused about
828+
* jiffies's declaration on different architectures.
829+
*/
830+
__no_kcsan
831+
static void test_jiffies_noreport(struct kunit *test)
832+
{
833+
bool match_never = false;
834+
835+
begin_test_checks(test_kernel_jiffies_reader, test_kernel_jiffies_reader);
836+
do {
837+
match_never = report_available();
838+
} while (!end_test_checks(match_never));
839+
KUNIT_EXPECT_FALSE(test, match_never);
840+
}
841+
820842
/* Test that racing accesses in seqlock critical sections are not reported. */
821843
__no_kcsan
822844
static void test_seqlock_noreport(struct kunit *test)
@@ -867,6 +889,7 @@ static struct kunit_case kcsan_test_cases[] = {
867889
KCSAN_KUNIT_CASE(test_assert_exclusive_bits_nochange),
868890
KCSAN_KUNIT_CASE(test_assert_exclusive_writer_scoped),
869891
KCSAN_KUNIT_CASE(test_assert_exclusive_access_scoped),
892+
KCSAN_KUNIT_CASE(test_jiffies_noreport),
870893
KCSAN_KUNIT_CASE(test_seqlock_noreport),
871894
{},
872895
};

0 commit comments

Comments
 (0)