From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F465C433F5 for ; Mon, 28 Feb 2022 09:16:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC30A8D0002; Mon, 28 Feb 2022 04:16:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D72F28D0001; Mon, 28 Feb 2022 04:16:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C62808D0002; Mon, 28 Feb 2022 04:16:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id B824E8D0001 for ; Mon, 28 Feb 2022 04:16:06 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5DE56181AF5F4 for ; Mon, 28 Feb 2022 09:16:06 +0000 (UTC) X-FDA: 79191631932.16.DEC59B9 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf19.hostedemail.com (Postfix) with ESMTP id A114C1A0002 for ; Mon, 28 Feb 2022 09:16:05 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id F149C2197F; Mon, 28 Feb 2022 09:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1646039763; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ERcbIDD+2M+tj1LE0zzkuItBxoJQx58CM7v8p9xOhhg=; b=eiHlQA+/Iw+Spi0IULYbJK3i2Nudjt7fGr66z9hgybL5azbIwzndCdSsBVk7YZWJFNTH0i aoEYG4fXrl7sISgQulgjqsxPM6RJtUlNVSz/cH+8cafYbXvqt/G5QQ4+8gaoNB2y/6giRN cohUXmuybicAQ2bki6Y3jaJiKevx+v8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1646039763; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ERcbIDD+2M+tj1LE0zzkuItBxoJQx58CM7v8p9xOhhg=; b=As/6bvQDNX++M9tWTqgcXZy6RAsCoOzMMxKeFN2sDg26I9DmJ+kxDMOpfz3LEXXC/ZVam/ 7Kyi5Qd9Za9kRBAw== Received: from quack3.suse.cz (unknown [10.100.224.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id BF824A3B83; Mon, 28 Feb 2022 09:16:03 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id 851F8A060A; Mon, 28 Feb 2022 10:16:00 +0100 (CET) Date: Mon, 28 Feb 2022 10:16:00 +0100 From: Jan Kara To: Nadav Amit Cc: linux-mm@kvack.org, Nadav Amit , Peter Xu , David Hildenbrand , Andrea Arcangeli , Mike Rapoport , Jan Kara Subject: Re: [PATCH v3] userfaultfd: provide unmasked address on page-fault Message-ID: <20220228091600.heba4wmmm4mmkjrk@quack3.lan> References: <20220226022655.350562-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220226022655.350562-1-namit@vmware.com> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A114C1A0002 X-Stat-Signature: 76n6du9fmpryzcgmyz4hfqoyq9479w7c Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="eiHlQA+/"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="As/6bvQD"; spf=pass (imf19.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none X-Rspam-User: X-HE-Tag: 1646039765-255421 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sat 26-02-22 02:26:55, Nadav Amit wrote: > From: Nadav Amit > > 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 > Reviewed-by: David Hildenbrand > Cc: Andrea Arcangeli > Cc: Mike Rapoport > Cc: Jan Kara > Signed-off-by: Nadav Amit > > --- > > v2->v3: > * Initialize real_address on all code paths [Jan] > > v1->v2: > * Add uffd feature to selectively enable [David, Andrea] I've just noticed one typo below. Otherwise the patch looks good to me. Feel free to add: Reviewed-by: Jan Kara > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 213cc569b192..27df0ca0a36a 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -478,7 +478,8 @@ struct vm_fault { > struct vm_area_struct *vma; /* Target VMA */ > gfp_t gfp_mask; /* gfp mask to be used for allocations */ > pgoff_t pgoff; /* Logical page offset based on vma */ > - unsigned long address; /* Faulting virtual address */ > + unsigned long address; /* Faulting virtual address - masked */ > + unsigned long real_address; /* Faulting virtual address - unmaked */ ^^ typo here Honza -- Jan Kara SUSE Labs, CR