linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: David Rientjes <rientjes@google.com>,
	kernel test robot <oliver.sang@intel.com>,
	Hyeonggon Yoo <42.hyeyoo@gmail.com>,
	oe-lkp@lists.linux.dev, lkp@intel.com,
	Mike Rapoport <rppt@linux.ibm.com>,
	Christoph Lameter <cl@linux.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: A better dump_page()
Date: Thu, 5 Jan 2023 15:35:55 +0000	[thread overview]
Message-ID: <Y7buW4unbGBI9mx4@casper.infradead.org> (raw)
In-Reply-To: <a1d98577-6037-4712-7573-a8a3daa486e6@suse.cz>

On Thu, Jan 05, 2023 at 04:19:06PM +0100, Vlastimil Babka wrote:
> On 1/4/23 00:29, Matthew Wilcox wrote:
> > On Tue, Jan 03, 2023 at 03:07:12PM -0800, David Rientjes wrote:
> >> On Tue, 3 Jan 2023, Matthew Wilcox wrote:
> >> 
> >> > On Tue, Jan 03, 2023 at 11:42:11AM +0100, Vlastimil Babka wrote:
> >> > > Separately we should also make the __dump_page() more resilient.
> >> > 
> >> > Right.  It's not ideal when one of our best debugging tools obfuscates
> >> > the problem we're trying to debug.  I've seen probems like this before,
> >> > and the problem is that somebody calls dump_page() on a page that they
> >> > don't own a refcount on.  That lets the page mutate under us in some
> >> > fairly awkward ways (as you've seen here, it seems to be part of several
> >> > different compound allocations at various points during the dump
> >> > process).
> >> > 
> >> > One possibility I thought about was taking our own refcount on the
> >> > page at the start of dump_page().  That would kill off the possibility
> >> > of ever passing in a const struct page, and it would confuse people.
> >> > Also, what if somebody passes in a pointer to something that's not a
> >> > struct page?  Then we've (tried to) modify memory that's not a refcount.
> >> > 
> >> > I think the best we can do is to snapshot the struct page and the folio
> >> > it appears to belong to at the start of dump_page().  It'll take a
> >> > little care (for example, folio_pfn() must be passed the original
> >> > folio, and not the snapshot), but I think it's doable.
> >> > 
> >> 
> >> By snapshot do you mean memcpy() of the metadata to the stack?  I assume 
> >> this still leaves the opportunity for the underlying mutation of the page 
> >> but makes the window more narrow.
> > 
> > Right.  We'd need to memcpy() both the page and the folio, so around 192
> > bytes.  It doesn't make it consistent since it could be mutated during
> > the memcpy(), but it will be consistent throughout the execution of the
> > function, so we won't get calls like folio_entire_mapcount() aborting
> > due to the folio having become a tail page halfway through.
> 
> I'm afraid this problem can still happen if the snapshot is inconsistent in
> the first place and you e.g. snapshot the tail page as tail page, and the
> supposed folio head page as not head page.

Oh, there would have to be an explicit check that the head page pointed
to is actually a head page, and further that it really is the head page
of this page.  But the advantage is that we can check that we have a
consistent snapshot _once_ rather than in every helper that we use in
this function.

The question is what to do if we have an inconsistent snapshot.
The answer we usually use (eg in filemap, gup, etc) is to try again until
we get a consistent answer.  But I think that's the wrong answer here; if
we get an inconsistent snapshot, we should give up.  Whatever information
might have been gleaned from the head page is now gone, because we don't
have the original head page any more.  So we should just dump the page
as a non-compound page.

> The local copying still makes a lot of sense though, as anything checked on
> the copy that determines its further evaluation can be trusted to remain
> consistent without complicated piecemeal READ_ONCE()'s etc. And as you
> mentioned it will allow us to proceed with constification, where the
> possibility of dump_page() through VM_BUG_ON_PAGE() is IIRC a big blocker
> for constifying the various flags checking helpers etc.

Yes, that's a nice side-benefit ;-)


  reply	other threads:[~2023-01-05 15:36 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-31 15:26 [linus:master] [mm, slub] 0af8489b02: kernel_BUG_at_include/linux/mm.h kernel test robot
2023-01-01  5:30 ` Hyeonggon Yoo
2023-01-01  6:50 ` Hyeonggon Yoo
2023-01-01  7:37   ` supervisor write access in kernel mode in __pv_queued_spin_unlock_slowpath Hyeonggon Yoo
2023-01-01 11:08     ` Maxim Levitsky
2023-01-02 11:17       ` Hyeonggon Yoo
2023-01-03 10:42 ` [linus:master] [mm, slub] 0af8489b02: kernel_BUG_at_include/linux/mm.h Vlastimil Babka
2023-01-03 13:46   ` Oliver Sang
2023-01-03 14:36     ` Vlastimil Babka
2023-01-04  9:04     ` Hyeonggon Yoo
2023-01-05  1:46       ` Oliver Sang
2023-01-05 13:59         ` Hyeonggon Yoo
2023-01-05 14:47         ` Hyeonggon Yoo
2023-01-09 14:16           ` Oliver Sang
2023-01-06 10:13         ` Vlastimil Babka
2023-01-09 14:01           ` Oliver Sang
2023-01-09 14:04             ` Oliver Sang
2023-01-10 13:53             ` Oliver Sang
2023-01-10 14:09               ` Vlastimil Babka
2023-01-11  2:26                 ` Feng Tang
2023-01-11 10:52                   ` Vlastimil Babka
2023-01-12  7:47                 ` Oliver Sang
2023-01-12  7:56                   ` Vlastimil Babka
2023-01-17  7:19                     ` Oliver Sang
2023-01-12  8:49                   ` Vlastimil Babka
2023-01-03 15:31   ` A better dump_page() Matthew Wilcox
2023-01-03 23:07     ` David Rientjes
2023-01-03 23:29       ` Matthew Wilcox
2023-01-05 15:19         ` Vlastimil Babka
2023-01-05 15:35           ` Matthew Wilcox [this message]
2023-01-06 17:28 ` [linus:master] [mm, slub] 0af8489b02: kernel_BUG_at_include/linux/mm.h Hyeonggon Yoo
2023-01-11  9:44 ` BUG: unable to handle page fault for address: f6ffe000 Hyeonggon Yoo

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=Y7buW4unbGBI9mx4@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=42.hyeyoo@gmail.com \
    --cc=cl@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=oe-lkp@lists.linux.dev \
    --cc=oliver.sang@intel.com \
    --cc=rientjes@google.com \
    --cc=rppt@linux.ibm.com \
    --cc=vbabka@suse.cz \
    /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