arch___change_bit(nr, addr);
 }
 
+static inline void __instrument_read_write_bitop(long nr, volatile unsigned long *addr)
+{
+       if (IS_ENABLED(CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC)) {
+               /*
+                * We treat non-atomic read-write bitops a little more special.
+                * Given the operations here only modify a single bit, assuming
+                * non-atomicity of the writer is sufficient may be reasonable
+                * for certain usage (and follows the permissible nature of the
+                * assume-plain-writes-atomic rule):
+                * 1. report read-modify-write races -> check read;
+                * 2. do not report races with marked readers, but do report
+                *    races with unmarked readers -> check "atomic" write.
+                */
+               kcsan_check_read(addr + BIT_WORD(nr), sizeof(long));
+               /*
+                * Use generic write instrumentation, in case other sanitizers
+                * or tools are enabled alongside KCSAN.
+                */
+               instrument_write(addr + BIT_WORD(nr), sizeof(long));
+       } else {
+               instrument_read_write(addr + BIT_WORD(nr), sizeof(long));
+       }
+}
+
 /**
  * __test_and_set_bit - Set a bit and return its old value
  * @nr: Bit to set
  */
 static inline bool __test_and_set_bit(long nr, volatile unsigned long *addr)
 {
-       instrument_read_write(addr + BIT_WORD(nr), sizeof(long));
+       __instrument_read_write_bitop(nr, addr);
        return arch___test_and_set_bit(nr, addr);
 }
 
  */
 static inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr)
 {
-       instrument_read_write(addr + BIT_WORD(nr), sizeof(long));
+       __instrument_read_write_bitop(nr, addr);
        return arch___test_and_clear_bit(nr, addr);
 }
 
  */
 static inline bool __test_and_change_bit(long nr, volatile unsigned long *addr)
 {
-       instrument_read_write(addr + BIT_WORD(nr), sizeof(long));
+       __instrument_read_write_bitop(nr, addr);
        return arch___test_and_change_bit(nr, addr);
 }