linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nadav Amit <namit@vmware.com>
To: Peter Xu <peterx@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linux-MM <linux-mm@kvack.org>,
	David Hildenbrand <david@redhat.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Mike Rapoport <rppt@linux.vnet.ibm.com>, Jan Kara <jack@suse.cz>
Subject: Re: [PATCH v3] userfaultfd: provide unmasked address on page-fault
Date: Thu, 3 Mar 2022 19:05:36 +0000	[thread overview]
Message-ID: <FD33CD4F-4508-4714-B1B4-62745A7B1B4B@vmware.com> (raw)
In-Reply-To: <YiB2Q0eawDInampI@xz-m1.local>



> On Mar 3, 2022, at 12:03 AM, Peter Xu <peterx@redhat.com> wrote:
> 
> On Sat, Feb 26, 2022 at 02:26:55AM +0000, Nadav Amit wrote:
>> From: Nadav Amit <namit@vmware.com>
>> 
>> Userfaultfd is supposed to provide the full address (i.e., unmasked) of
>> the faulting access back to userspace. However, that is not the case for
>> quite some time.
>> 
>> Even running "userfaultfd_demo" from the userfaultfd man page provides
>> the wrong output (and contradicts the man page). Notice that
>> "UFFD_EVENT_PAGEFAULT event" shows the masked address (7fc5e30b3000)
>> and not the first read address (0x7fc5e30b300f).
>> 
>> 	Address returned by mmap() = 0x7fc5e30b3000
>> 
>> 	fault_handler_thread():
>> 	    poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
>> 	    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fc5e30b3000
>> 		(uffdio_copy.copy returned 4096)
>> 	Read address 0x7fc5e30b300f in main(): A
>> 	Read address 0x7fc5e30b340f in main(): A
>> 	Read address 0x7fc5e30b380f in main(): A
>> 	Read address 0x7fc5e30b3c0f in main(): A
>> 
>> The exact address is useful for various reasons and specifically for
>> prefetching decisions. If it is known that the memory is populated by
>> certain objects whose size is not page-aligned, then based on the
>> faulting address, the uffd-monitor can decide whether to prefetch and
>> prefault the adjacent page.
>> 
>> This bug has been for quite some time in the kernel: since commit
>> 1a29d85eb0f1 ("mm: use vmf->address instead of of vmf->virtual_address")
>> vmf->virtual_address"), which dates back to 2016. A concern has been
>> raised that existing userspace application might rely on the old/wrong
>> behavior in which the address is masked. Therefore, it was suggested to
>> provide the masked address unless the user explicitly asks for the exact
>> address.
>> 
>> Add a new userfaultfd feature UFFD_FEATURE_EXACT_ADDRESS to direct
>> userfaultfd to provide the exact address. Add a new "real_address" field
>> to vmf to hold the unmasked address. Provide the address to userspace
>> accordingly.
>> 
>> Initialize real_address in various code-paths to be consistent with
>> address, even when it is not used, to be on the safe side.
>> 
>> Acked-by: Peter Xu <peterx@redhat.com>
>> Reviewed-by: David Hildenbrand <david@redhat.com>
>> Cc: Andrea Arcangeli <aarcange@redhat.com>
>> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
>> Cc: Jan Kara <jack@suse.cz>
>> Signed-off-by: Nadav Amit <namit@vmware.com>
> 
> Hi, Andrew,
> 
> Just a heads-up that this version has not yet been updated in -mm I think,
> while the queued one is the old version.
> 
> IOW, uffd is currently broken on latest linux-next on hugetlb.

Thanks Peter for reminding Andrew.

Andrew, please acknowledge it would be queue for the next version and
I will submit a patch to the man pages.
 



  reply	other threads:[~2022-03-03 19:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-26  2:26 Nadav Amit
2022-02-26  7:37 ` Mike Rapoport
2022-02-28  9:16 ` Jan Kara
2022-03-03  8:03 ` Peter Xu
2022-03-03 19:05   ` Nadav Amit [this message]
2022-03-03 19:51     ` Nadav Amit
2022-03-04  2:27       ` Peter Xu
2022-03-04 10:38       ` David Hildenbrand
2022-03-07 18:43         ` Nadav Amit
2022-03-04  1:54     ` Andrew Morton

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=FD33CD4F-4508-4714-B1B4-62745A7B1B4B@vmware.com \
    --to=namit@vmware.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=rppt@linux.vnet.ibm.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