mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>, Jann Horn <jannh@google.com>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Tal Zussman <tz2294@columbia.edu>,
	stable@vger.kernel.org
Subject: Re: [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs
Date: Fri, 13 Nov 2026 20:15:34 +0100	[thread overview]
Message-ID: <0d6e29f8-54fc-427a-a979-1a8c6f4e3f06@kernel.org> (raw)
In-Reply-To: <avcNcL6svEOTg_3r@gremlin>

On 11/13/26 14:59, Lorenzo Stoakes (ARM) wrote:
> On Fri, Nov 13, 2026 at 12:59:00AM +0100, David Hildenbrand (Arm) wrote:
>> On 11/12/26 18:38, Lorenzo Stoakes (ARM) wrote:
>>> In order to establish guard regions, guard markers are installed in the
>>> page tables of a mapped VMA.
>>>
>>> However, problems arise when one tries to combine this with registering a
>>> VMA for userfaultfd, as such operations may themselves need to install page
>>> table markers such as uffd-wp.
>>
>> How does this interact with UFFDIO_POISON markers that can outlive even
>> userfaultfd registration?
> 
> The zap clears poison markers, as is standard. It's really horrible this logic.
> 
> So the code path for zap used by the guard install (via zap_vma_range()) is:
> 
> zap_vma_range()
>   -> zap_vma_range_batched() with NULL zap_details
>     -> __zap_vma_range()
>       -> zap_p4d_range()
>         ...
>         -> zap_pte_range()
>           -> do_zap_pte_range()
>             -> zap_nonpresent_ptes()
> 
> And zap_details is NULL.
> > In zap_non_present_ptes():
> 
> 	...
> 	} else if (softleaf_is_uffd_wp_marker(entry)) {
> 		if (... !zap_drop_markers(details))
> 			return 1;
> 	} else if (softleaf_is_guard_marker(entry)) {
> 		...
> 		if (!zap_drop_markers(details))
> 			return 1;
> 	} else if (softleaf_is_hwpoison(entry) ||
> 		   softleaf_is_poison_marker(entry)) {
> 		if (!should_zap_cows(details))
> 			return 1;
> 	} ...
> 
> And zap_drop_markers() checks zap_details && zap_details->flags &
> ZAP_FLAG_DROP_MARKER.

Right, my intuition tells me to just nuke that thing by setting
ZAP_FLAG_DROP_MARKER.

MADV_GUARD, is just like munmap() another form of "zap it all and protect it".
>>> This is especially problematic because guard region installation causes the
>>> regions to be zapped first, meaning that the removal of userfaultfd-tracked
>>> ranges will not be logged in this case.
>>
>> Again, similar to trying to uffd-wp-protect'ing a hwpoison marker (which will be
>> ignored), and then zapping that.
>>
>> Isn't guard marker installation/removal just another form of zapping?
> 
> I mean users being weird could decide to use it for that rather than
> MADV_DONTNEED, but zapping is a side effect really.
> 
> Really the idea is that you might have users who, for whatever reason,
> faulted in some range, and now want to make that a guard range, so for
> convenience we zap it for them :)

I think not just convenience. There was this problem with faultaround / THP
placement IIRC ...

I'd just zap everything that's there. That's literally what the user asked for.

> 
>>
>> So to me this all sounds like "if user space does something stupid, it's user
>> space's fault".
> 
> Unfortunately, as per Tal's series, there's more to it than that (linked in
> Closes: tags).
> 
> You can get an infinite syscall restart (ugh) if you do this on a shmem
> range (Tal's 9/12) so it's a kernel bug that _has_ to be fixed.
> 
> The other bits are just about a user losing track of uffd stuff if they
> guard/unguard, as you say.
> 
> But every other zap code path does the uffd remove event stuff, so this is
> still an exception.
> 
> If you support uffd, you have to add a whole bunch of horrifying, awful,
> terrible open-coded uffd crap, e.g. the userfaultfd_remove() etc. And you
> have to drop the bloody lock and reacquire it too and make sure all that
> works correctly (...!)
> 
> Anyway there's basically 3 options here:
> 
> 1. do something like what Tal's series does - add a TON of complexity for a
>    use case that nobody uses to get behaviour on something nobody sane
>    should care about (i.e. uffd/guard/unguard/expect uffd correctness).
> 
> 2. Zap with ZAP_FLAG_DROP_MARKER, and silently lose uffd-wp state but
>   'support' uffd. It does fix the 9/12 bug but then subtly breaks uffd.

Right, that's what I would do.

MADV_GUARD_INSTALL zaps everything.

It already zaps swap entries, migration entries, hwpoison entries ... so just
zap everything.

[...]

> 
> If you're really concerned though, we could go with option 2, which will
> just make UFFD behave differently for guard regions.
> 

Not really concerned, it's just the most consistent one for me. Zap everything.
The user asks for it, like he would ask with munmap().

> (I regret, obviously, ever allowing this for uffd ranges. And we _all_
>  regret that uffd was _ever_ allowed to be merged in this state...)
Yeah ...

-- 
Cheers,

David

  reply	other threads:[~2026-11-13 19:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 17:38 Lorenzo Stoakes (ARM)
2026-11-12 20:59 ` Liam R. Howlett
2026-11-12 23:59 ` David Hildenbrand (Arm)
2026-11-13 13:59   ` Lorenzo Stoakes (ARM)
2026-11-13 19:15     ` David Hildenbrand (Arm) [this message]
2026-11-13 19:22       ` Lorenzo Stoakes (ARM)
2026-11-13  8:58 ` Vlastimil Babka (SUSE)

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=0d6e29f8-54fc-427a-a979-1a8c6f4e3f06@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=jannh@google.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=tz2294@columbia.edu \
    --cc=vbabka@kernel.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

all inboxes | Powered by JetHome®