Re: KCSAN: data-race in generic_file_buffered_read / generic_file_buffered_read

Matthew Wilcox
2020-07-16T13:19:38Z

On Wed, Jul 15, 2020 at 11:54:54PM -0700, Eric Biggers wrote:
> > >> > Concurrent reads on the same file descriptor are allowed. Not with sys_read(),
> > >> > as that implicitly uses the file position. But it's allowed with sys_pread(),
> > >> > and also with sys_sendfile() which is the case syzbot is reporting here.
> > >>
> > >> Concurrent read()s are fine, they'll just read from the same offset.
> > >>
> > >
> > > Actually the VFS serializes concurrent read()'s on the same fd, at least for
> > > regular files.
> >
> > Hmm, where?
>
> It's serialized by file->f_pos_lock. See fdget_pos().

What if we trylock either f_lock or f_pos_lock for readahead and just
skip all the readahead code if it's already taken? I'd suggest that if
there are two readers using the same struct file, this is probably not
a workload that benefits greatly from readahead.