Skip to content

Commit 183ec5f

Browse files
melverPeter Zijlstra
authored andcommitted
kcsan, seqlock: Fix incorrect assumption in read_seqbegin()
During testing of the preceding changes, I noticed that in some cases, current->kcsan_ctx.in_flat_atomic remained true until task exit. This is obviously wrong, because _all_ accesses for the given task will be treated as atomic, resulting in false negatives i.e. missed data races. Debugging led to fs/dcache.c, where we can see this usage of seqlock: struct dentry *d_lookup(const struct dentry *parent, const struct qstr *name) { struct dentry *dentry; unsigned seq; do { seq = read_seqbegin(&rename_lock); dentry = __d_lookup(parent, name); if (dentry) break; } while (read_seqretry(&rename_lock, seq)); [...] As can be seen, read_seqretry() is never called if dentry != NULL; consequently, current->kcsan_ctx.in_flat_atomic will never be reset to false by read_seqretry(). Give up on the wrong assumption of "assume closing read_seqretry()", and rely on the already-present annotations in read_seqcount_begin/retry(). Fixes: 88ecd15 ("seqlock, kcsan: Add annotations for KCSAN") Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 93190bc commit 183ec5f

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

include/linux/seqlock.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -810,11 +810,7 @@ static __always_inline void write_seqcount_latch_end(seqcount_latch_t *s)
810810
*/
811811
static inline unsigned read_seqbegin(const seqlock_t *sl)
812812
{
813-
unsigned ret = read_seqcount_begin(&sl->seqcount);
814-
815-
kcsan_atomic_next(0); /* non-raw usage, assume closing read_seqretry() */
816-
kcsan_flat_atomic_begin();
817-
return ret;
813+
return read_seqcount_begin(&sl->seqcount);
818814
}
819815

820816
/**
@@ -830,12 +826,6 @@ static inline unsigned read_seqbegin(const seqlock_t *sl)
830826
*/
831827
static inline unsigned read_seqretry(const seqlock_t *sl, unsigned start)
832828
{
833-
/*
834-
* Assume not nested: read_seqretry() may be called multiple times when
835-
* completing read critical section.
836-
*/
837-
kcsan_flat_atomic_end();
838-
839829
return read_seqcount_retry(&sl->seqcount, start);
840830
}
841831

0 commit comments

Comments
 (0)