Skip to content

Commit b473a38

Browse files
melverpaulmckrcu
authored andcommitted
kcsan: Only test clear_bit_unlock_is_negative_byte if arch defines it
Some architectures do not define clear_bit_unlock_is_negative_byte(). Only test it when it is actually defined (similar to other usage, such as in lib/test_kasan.c). Link: https://lkml.kernel.org/r/202112050757.x67rHnFU-lkp@intel.com Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent e3d2b72 commit b473a38

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

kernel/kcsan/kcsan_test.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ static void test_barrier_nothreads(struct kunit *test)
598598
KCSAN_EXPECT_READ_BARRIER(test_and_change_bit(0, &test_var), true);
599599
KCSAN_EXPECT_READ_BARRIER(clear_bit_unlock(0, &test_var), true);
600600
KCSAN_EXPECT_READ_BARRIER(__clear_bit_unlock(0, &test_var), true);
601-
KCSAN_EXPECT_READ_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var), true);
602601
KCSAN_EXPECT_READ_BARRIER(arch_spin_lock(&arch_spinlock), false);
603602
KCSAN_EXPECT_READ_BARRIER(arch_spin_unlock(&arch_spinlock), true);
604603
KCSAN_EXPECT_READ_BARRIER(spin_lock(&test_spinlock), false);
@@ -644,7 +643,6 @@ static void test_barrier_nothreads(struct kunit *test)
644643
KCSAN_EXPECT_WRITE_BARRIER(test_and_change_bit(0, &test_var), true);
645644
KCSAN_EXPECT_WRITE_BARRIER(clear_bit_unlock(0, &test_var), true);
646645
KCSAN_EXPECT_WRITE_BARRIER(__clear_bit_unlock(0, &test_var), true);
647-
KCSAN_EXPECT_WRITE_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var), true);
648646
KCSAN_EXPECT_WRITE_BARRIER(arch_spin_lock(&arch_spinlock), false);
649647
KCSAN_EXPECT_WRITE_BARRIER(arch_spin_unlock(&arch_spinlock), true);
650648
KCSAN_EXPECT_WRITE_BARRIER(spin_lock(&test_spinlock), false);
@@ -690,14 +688,18 @@ static void test_barrier_nothreads(struct kunit *test)
690688
KCSAN_EXPECT_RW_BARRIER(test_and_change_bit(0, &test_var), true);
691689
KCSAN_EXPECT_RW_BARRIER(clear_bit_unlock(0, &test_var), true);
692690
KCSAN_EXPECT_RW_BARRIER(__clear_bit_unlock(0, &test_var), true);
693-
KCSAN_EXPECT_RW_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var), true);
694691
KCSAN_EXPECT_RW_BARRIER(arch_spin_lock(&arch_spinlock), false);
695692
KCSAN_EXPECT_RW_BARRIER(arch_spin_unlock(&arch_spinlock), true);
696693
KCSAN_EXPECT_RW_BARRIER(spin_lock(&test_spinlock), false);
697694
KCSAN_EXPECT_RW_BARRIER(spin_unlock(&test_spinlock), true);
698695
KCSAN_EXPECT_RW_BARRIER(mutex_lock(&test_mutex), false);
699696
KCSAN_EXPECT_RW_BARRIER(mutex_unlock(&test_mutex), true);
700697

698+
#ifdef clear_bit_unlock_is_negative_byte
699+
KCSAN_EXPECT_READ_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var), true);
700+
KCSAN_EXPECT_WRITE_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var), true);
701+
KCSAN_EXPECT_RW_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var), true);
702+
#endif
701703
kcsan_nestable_atomic_end();
702704
}
703705

kernel/kcsan/selftest.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ static bool __init test_barrier(void)
169169
KCSAN_CHECK_READ_BARRIER(test_and_change_bit(0, &test_var));
170170
KCSAN_CHECK_READ_BARRIER(clear_bit_unlock(0, &test_var));
171171
KCSAN_CHECK_READ_BARRIER(__clear_bit_unlock(0, &test_var));
172-
KCSAN_CHECK_READ_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var));
173172
arch_spin_lock(&arch_spinlock);
174173
KCSAN_CHECK_READ_BARRIER(arch_spin_unlock(&arch_spinlock));
175174
spin_lock(&test_spinlock);
@@ -199,7 +198,6 @@ static bool __init test_barrier(void)
199198
KCSAN_CHECK_WRITE_BARRIER(test_and_change_bit(0, &test_var));
200199
KCSAN_CHECK_WRITE_BARRIER(clear_bit_unlock(0, &test_var));
201200
KCSAN_CHECK_WRITE_BARRIER(__clear_bit_unlock(0, &test_var));
202-
KCSAN_CHECK_WRITE_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var));
203201
arch_spin_lock(&arch_spinlock);
204202
KCSAN_CHECK_WRITE_BARRIER(arch_spin_unlock(&arch_spinlock));
205203
spin_lock(&test_spinlock);
@@ -232,12 +230,16 @@ static bool __init test_barrier(void)
232230
KCSAN_CHECK_RW_BARRIER(test_and_change_bit(0, &test_var));
233231
KCSAN_CHECK_RW_BARRIER(clear_bit_unlock(0, &test_var));
234232
KCSAN_CHECK_RW_BARRIER(__clear_bit_unlock(0, &test_var));
235-
KCSAN_CHECK_RW_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var));
236233
arch_spin_lock(&arch_spinlock);
237234
KCSAN_CHECK_RW_BARRIER(arch_spin_unlock(&arch_spinlock));
238235
spin_lock(&test_spinlock);
239236
KCSAN_CHECK_RW_BARRIER(spin_unlock(&test_spinlock));
240237

238+
#ifdef clear_bit_unlock_is_negative_byte
239+
KCSAN_CHECK_RW_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var));
240+
KCSAN_CHECK_READ_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var));
241+
KCSAN_CHECK_WRITE_BARRIER(clear_bit_unlock_is_negative_byte(0, &test_var));
242+
#endif
241243
kcsan_nestable_atomic_end();
242244

243245
return ret;

0 commit comments

Comments
 (0)