Skip to content

Commit

Permalink
kcsan: Add jiffies test to test suite
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
melver authored and paulmckrcu committed Jun 29, 2020
1 parent 7e76656 commit 56b031f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions kernel/kcsan/kcsan-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ static noinline void test_kernel_read_struct_zero_size(void)
kcsan_check_read(&test_struct.val[3], 0);
}

static noinline void test_kernel_jiffies_reader(void)
{
sink_value((long)jiffies);
}

static noinline void test_kernel_seqlock_reader(void)
{
unsigned int seq;
Expand Down Expand Up @@ -817,6 +822,23 @@ static void test_assert_exclusive_access_scoped(struct kunit *test)
KUNIT_EXPECT_TRUE(test, match_expect_inscope);
}

/*
* jiffies is special (declared to be volatile) and its accesses are typically
* not marked; this test ensures that the compiler nor KCSAN gets confused about
* jiffies's declaration on different architectures.
*/
__no_kcsan
static void test_jiffies_noreport(struct kunit *test)
{
bool match_never = false;

begin_test_checks(test_kernel_jiffies_reader, test_kernel_jiffies_reader);
do {
match_never = report_available();
} while (!end_test_checks(match_never));
KUNIT_EXPECT_FALSE(test, match_never);
}

/* Test that racing accesses in seqlock critical sections are not reported. */
__no_kcsan
static void test_seqlock_noreport(struct kunit *test)
Expand Down Expand Up @@ -867,6 +889,7 @@ static struct kunit_case kcsan_test_cases[] = {
KCSAN_KUNIT_CASE(test_assert_exclusive_bits_nochange),
KCSAN_KUNIT_CASE(test_assert_exclusive_writer_scoped),
KCSAN_KUNIT_CASE(test_assert_exclusive_access_scoped),
KCSAN_KUNIT_CASE(test_jiffies_noreport),
KCSAN_KUNIT_CASE(test_seqlock_noreport),
{},
};
Expand Down

0 comments on commit 56b031f

Please sign in to comment.