From: Mauricio Faria de Oliveira <mfo@canonical.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: Minchan Kim <minchan@kernel.org>,
"Huang, Ying" <ying.huang@intel.com>,
Yu Zhao <yuzhao@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Yang Shi <shy828301@gmail.com>,
Miaohe Lin <linmiaohe@huawei.com>,
linux-mm@kvack.org, linux-block@vger.kernel.org,
axboe@kernel.dk, John Hubbard <jhubbard@nvidia.com>
Subject: Re: [PATCH v3] mm: fix race between MADV_FREE reclaim and blkdev direct IO read
Date: Wed, 2 Feb 2022 13:29:25 -0300 [thread overview]
Message-ID: <CAO9xwp3RwkNxWC+FRTcX6Mzi+Ehgbgsmm0qyru_Mb=AMONyexg@mail.gmail.com> (raw)
In-Reply-To: <YfqPJLTIx18DCGii@infradead.org>
On Wed, Feb 2, 2022 at 11:03 AM Christoph Hellwig <hch@infradead.org> wrote:
>
> 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?
In general, since this particular problem is specific to MADV_FREE,
it seemed about right to go for a more contained/particular solution
(than changes with broader impact/risk to things that aren't broken).
This isn't to say either approach shouldn't be pursued, but just that
the larger changes aren't strictly needed to actually fix _this_ issue
(and might complicate landing the fix into the stable/distro kernels.)
Now, specifically on the 2 suggestions you mentioned, I'm not very
familiar with other implementations, thus I can't speak to that, sorry.
However, on the 1st suggestion (set pages dirty early), John noted
[1] there might be issues with that and advised not going there.
>
> > Reproducer:
> > ==========
> >
> > @ test.c (simplified, but works)
>
> Can you add this to blktests or some other regularly run regression
> test suite?
Sure.
The test also needs the kernel-side change (to trigger memory reclaim),
which can probably be wired for blktests with a fault-injection capability.
Does that sound good? Maybe there's a better way to do it.
>
> > + smp_rmb();
> > +
> > + /*
> > + * The only page refs must be from the isolation
> > + * plus one or more rmap's (dropped by discard:).
>
> Overly long line.
Hmm, checkpatch.pl didn't complain about it. Ah, it checks for 100 chars.
Ok; v4.
>
> > + */
> > + if ((ref_count == 1 + map_count) &&
>
> No need for the inner braces.
>
Ok; v4.
I'll wait a bit in case more changes are needed, and send v4 w/ the above.
Thanks!
[1] https://lore.kernel.org/linux-mm/7094dbd6-de0c-9909-e657-e358e14dc6c3@nvidia.com/
--
Mauricio Faria de Oliveira
next prev parent reply other threads:[~2022-02-02 16:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-31 23:02 Mauricio Faria de Oliveira
2022-01-31 23:43 ` Andrew Morton
2022-02-01 2:23 ` Mauricio Faria de Oliveira
2022-02-02 14:03 ` Christoph Hellwig
2022-02-02 16:29 ` Mauricio Faria de Oliveira [this message]
2022-02-02 19:56 ` Yu Zhao
2022-02-02 21:27 ` Mauricio Faria de Oliveira
2022-02-02 21:53 ` Yu Zhao
2022-02-03 22:17 ` Mauricio Faria de Oliveira
2022-02-04 5:56 ` Yu Zhao
2022-02-04 7:03 ` John Hubbard
2022-02-04 18:59 ` Mauricio Faria de Oliveira
2022-02-04 18:58 ` Mauricio Faria de Oliveira
2022-02-16 6:48 ` Huang, Ying
2022-02-16 21:58 ` Yu Zhao
2022-02-16 22:00 ` Yu Zhao
2022-02-17 6:08 ` Huang, Ying
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAO9xwp3RwkNxWC+FRTcX6Mzi+Ehgbgsmm0qyru_Mb=AMONyexg@mail.gmail.com' \
--to=mfo@canonical.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=jhubbard@nvidia.com \
--cc=linmiaohe@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=shy828301@gmail.com \
--cc=ying.huang@intel.com \
--cc=yuzhao@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox