Re: [PATCH -RFC 0/2] mm/ext4: avoid data corruption when extending DIO write race with buffered read

From: Matthew Wilcox
Date: Mon Dec 11 2023 - 23:45:05 EST


On Wed, Dec 06, 2023 at 08:37:57PM +0100, Jan Kara wrote:
> Within the same page buffered reads and writes should be consistent because
> they are synchronized by the page lock. However once reads and writes
> involve multiple pages, there is no serialization so you can get contents
> of some pages before write and some pages after being written. However this
> doesn't seem to be your particular case here. I just wanted to point out
> that in general even buffered reads vs writes are not fully consistent.

Buffered reads don't take the page/folio lock. We only use the folio
lock to avoid reading stale data from the page cache while we're
fetching the data from storage. Once the uptodate flag is set on the
folio, we never take the folio lock for reads.