Re: [PATCH v3] mm: fix race between MADV_FREE reclaim and blkdev direct IO read

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jan 31, 2022 at 08:02:55PM -0300, Mauricio Faria de Oliveira wrote:
> Well, blkdev_direct_IO() gets references for all pages, and on READ
> operations it only sets them dirty _later_.
> 
> So, if MADV_FREE'd pages (i.e., not dirty) are used as buffers for
> direct IO read from block devices, and page reclaim happens during
> __blkdev_direct_IO[_simple]() exactly AFTER bio_iov_iter_get_pages()
> returns, but BEFORE the pages are set dirty, the situation happens.
> 
> The direct IO read eventually completes. Now, when userspace reads
> the buffers, the PTE is no longer there and the page fault handler
> do_anonymous_page() services that with the zero-page, NOT the data!

So why not just set the pages dirty early like the other direct I/O
implementations?  Or if this is fine with the patch should we remove
the early dirtying elsewhere?

> Reproducer:
> ==========
> 
> @ test.c (simplified, but works)

Can you add this to blktests or some other regularly run regression
test suite?

> +				smp_rmb();
> +
> +				/*
> +				 * The only page refs must be from the isolation
> +				 * plus one or more rmap's (dropped by discard:).

Overly long line.

> +				 */
> +				if ((ref_count == 1 + map_count) &&

No need for the inner braces.




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux