From: Dan Williams <dan.j.williams@intel.com>
To: john.hubbard@gmail.com
Cc: Matthew Wilcox <willy@infradead.org>,
Michal Hocko <mhocko@kernel.org>,
Christopher Lameter <cl@linux.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Jan Kara <jack@suse.cz>,
Linux MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-rdma <linux-rdma@vger.kernel.org>,
John Hubbard <jhubbard@nvidia.com>,
Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH 2/2] mm: set PG_dma_pinned on get_user_pages*()
Date: Sun, 17 Jun 2018 12:53:04 -0700 [thread overview]
Message-ID: <CAPcyv4i=eky-QrPcLUEqjsASuRUrFEWqf79hWe0mU8xtz6Jk-w@mail.gmail.com> (raw)
In-Reply-To: <20180617012510.20139-3-jhubbard@nvidia.com>
On Sat, Jun 16, 2018 at 6:25 PM, <john.hubbard@gmail.com> wrote:
> From: John Hubbard <jhubbard@nvidia.com>
>
> This fixes a few problems that come up when using devices (NICs, GPUs,
> for example) that want to have direct access to a chunk of system (CPU)
> memory, so that they can DMA to/from that memory. Problems [1] come up
> if that memory is backed by persistence storage; for example, an ext4
> file system. I've been working on several customer bugs that are hitting
> this, and this patchset fixes those bugs.
>
> The bugs happen via:
>
> 1) get_user_pages() on some ext4-backed pages
> 2) device does DMA for a while to/from those pages
>
> a) Somewhere in here, some of the pages get disconnected from the
> file system, via try_to_unmap() and eventually drop_buffers()
>
> 3) device is all done, device driver calls set_page_dirty_lock(), then
> put_page()
>
> And then at some point, we see a this BUG():
>
> kernel BUG at /build/linux-fQ94TU/linux-4.4.0/fs/ext4/inode.c:1899!
> backtrace:
> ext4_writepage
> __writepage
> write_cache_pages
> ext4_writepages
> do_writepages
> __writeback_single_inode
> writeback_sb_inodes
> __writeback_inodes_wb
> wb_writeback
> wb_workfn
> process_one_work
> worker_thread
> kthread
> ret_from_fork
>
> ...which is due to the file system asserting that there are still buffer
> heads attached:
>
> ({ \
> BUG_ON(!PagePrivate(page)); \
> ((struct buffer_head *)page_private(page)); \
> })
>
> How to fix this:
> ----------------
> Introduce a new page flag: PG_dma_pinned, and set this flag on
> all pages that are returned by the get_user_pages*() family of
> functions. Leave it set nearly forever: until the page is freed.
>
> Then, check this flag before attempting to unmap pages. This will
> cause a very early return from try_to_unmap_one(), and will avoid
> doing things such as, notably, removing page buffers via drop_buffers().
>
> This uses a new struct page flag, but only on 64-bit systems.
>
> Obviously, this is heavy-handed, but given the long, broken history of
> get_user_pages in combination with file-backed memory, and given the
> problems with alternative designs, it's a reasonable fix for now: small,
> simple, and easy to revert if and when a more comprehensive design solution
> is chosen.
>
> Some alternatives, and why they were not taken:
>
> 1. It would be better, if possible, to clear PG_dma_pinned, once all
> get_user_pages callers returned the page (via something more specific than
> put_page), but that would significantly change the usage for get_user_pages
> callers. That's too intrusive for such a widely used and old API, so let's
> leave it alone.
>
> Also, such a design would require a new counter that would be associated
> with each page. There's no room in struct page, so it would require
> separate tracking, which is not acceptable for general page management.
>
> 2. There are other more complicated approaches[2], but these depend on
> trying to solve very specific call paths that, in the end, are just
> downstream effects of the root cause. And so these did not actually fix the
> customer bugs that I was working on.
>
> References:
>
> [1] https://lwn.net/Articles/753027/ : "The trouble with get_user_pages()"
>
> [2] https://marc.info/?l=linux-mm&m=<20180521143830.GA25109@bombadil.infradead.org>
> (Matthew Wilcox listed two ideas here)
>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
[..]
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 6db729dc4c50..37576f0a4645 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1360,6 +1360,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
> flags & TTU_SPLIT_FREEZE, page);
> }
>
> + if (PageDmaPinned(page))
> + return false;
> /*
> * We have to assume the worse case ie pmd for invalidation. Note that
> * the page can not be free in this function as call of try_to_unmap()
We have a similiar problem with DAX and the conclusion we came to is
that it is not acceptable for userspace to arbitrarily block kernel
actions. The conclusion there was: 'wait' if the DMA is transient, and
'revoke' if the DMA is long lived, or otherwise 'block' long-lived DMA
if a revocation mechanism is not available.
next prev parent reply other threads:[~2018-06-17 19:53 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-17 1:25 [PATCH 0/2] mm: gup: don't unmap or drop filesystem buffers john.hubbard
2018-06-17 1:25 ` [PATCH 1/2] consolidate get_user_pages error handling john.hubbard
2018-06-17 1:25 ` [PATCH 2/2] mm: set PG_dma_pinned on get_user_pages*() john.hubbard
2018-06-17 19:53 ` Dan Williams [this message]
2018-06-17 20:04 ` Jason Gunthorpe
2018-06-17 20:10 ` Dan Williams
2018-06-17 20:28 ` John Hubbard
2018-06-18 8:12 ` Christoph Hellwig
2018-06-18 17:50 ` John Hubbard
2018-06-18 17:56 ` Dan Williams
2018-06-18 18:14 ` John Hubbard
2018-06-18 19:21 ` Dan Williams
2018-06-18 19:31 ` Jason Gunthorpe
2018-06-18 20:04 ` Dan Williams
2018-06-18 21:36 ` John Hubbard
2018-06-19 8:29 ` Jan Kara
2018-06-19 9:02 ` Matthew Wilcox
2018-06-19 10:41 ` Jan Kara
2018-06-19 18:11 ` John Hubbard
2018-06-20 1:24 ` Dan Williams
2018-06-20 1:34 ` John Hubbard
2018-06-20 1:57 ` Dan Williams
2018-06-20 2:03 ` John Hubbard
2018-06-20 12:08 ` Jan Kara
2018-06-20 22:55 ` John Hubbard
2018-06-21 16:30 ` Jan Kara
2018-06-25 15:21 ` Jan Kara
2018-06-25 19:03 ` John Hubbard
2018-06-26 7:52 ` Jan Kara
2018-06-26 6:31 ` John Hubbard
2018-06-26 11:48 ` Jan Kara
2018-06-26 13:47 ` Michal Hocko
2018-06-26 16:48 ` Jan Kara
2018-06-27 11:32 ` Michal Hocko
2018-06-27 11:53 ` Jan Kara
2018-06-27 11:59 ` Michal Hocko
2018-06-27 12:42 ` Jan Kara
2018-06-27 14:57 ` Jason Gunthorpe
2018-06-27 17:02 ` Jan Kara
2018-06-28 2:42 ` John Hubbard
2018-06-28 9:17 ` Jan Kara
2018-07-02 5:52 ` Leon Romanovsky
2018-07-02 6:10 ` John Hubbard
2018-07-02 6:34 ` Leon Romanovsky
2018-07-02 6:41 ` John Hubbard
2018-07-02 10:36 ` Michal Hocko
2018-07-02 7:02 ` Jan Kara
2018-07-02 14:48 ` Michal Hocko
2018-07-02 6:58 ` Jan Kara
2018-06-18 8:11 ` Christoph Hellwig
2018-06-19 6:15 ` Leon Romanovsky
2018-06-17 22:19 ` John Hubbard
2018-06-18 7:56 ` Christoph Hellwig
2018-06-18 17:44 ` John Hubbard
2018-06-17 21:54 ` [PATCH 0/2] mm: gup: don't unmap or drop filesystem buffers Christopher Lameter
2018-06-17 22:23 ` John Hubbard
2018-06-18 8:10 ` Christoph Hellwig
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='CAPcyv4i=eky-QrPcLUEqjsASuRUrFEWqf79hWe0mU8xtz6Jk-w@mail.gmail.com' \
--to=dan.j.williams@intel.com \
--cc=cl@linux.com \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=john.hubbard@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mhocko@kernel.org \
--cc=willy@infradead.org \
/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