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 3EE54C433F5 for ; Tue, 22 Feb 2022 05:02:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 623F38D0002; Tue, 22 Feb 2022 00:02:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D44E8D0001; Tue, 22 Feb 2022 00:02:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49C498D0002; Tue, 22 Feb 2022 00:02:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id 3C1E68D0001 for ; Tue, 22 Feb 2022 00:02:47 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E5376181CA77C for ; Tue, 22 Feb 2022 05:02:46 +0000 (UTC) X-FDA: 79169220732.17.144046A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 5D9B01A0005 for ; Tue, 22 Feb 2022 05:02:46 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 520AF615D8; Tue, 22 Feb 2022 05:02:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 618CBC340E8; Tue, 22 Feb 2022 05:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1645506164; bh=lkRKfkaBIFfgKQpXE1yIOdEisow84GsiMsHX/tvabxk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LBlGhQdDxxtHUIw7JlPDkXnCbu7ZdKi0jWLjOPnHltNJlxxdKtLas/l/sg/GQlkYh gXTJV36B+BfFbdwsdddNSYovrAYrb04dbQp3OVyHkRx0H6v8cHhddHWa1TTMg6QzOl RhAGFHRwx3SSH7P4oyEtjcgQwXTsIt9xqje6AcDs= Date: Mon, 21 Feb 2022 21:02:43 -0800 From: Andrew Morton To: Nadav Amit Cc: linux-mm@kvack.org, Nadav Amit , David Hildenbrand , Andrea Arcangeli , Mike Rapoport , Peter Xu , Jan Kara Subject: Re: [PATCH v2] userfaultfd: provide unmasked address on page-fault Message-Id: <20220221210243.142b8e6b2c0fd41087eb51b5@linux-foundation.org> In-Reply-To: <20220218041003.3508-1-namit@vmware.com> References: <20220218041003.3508-1-namit@vmware.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 5D9B01A0005 X-Stat-Signature: p4bts5urx766c4fbgnzhzjoch8tec6ut Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=LBlGhQdD; dmarc=none; spf=pass (imf19.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1645506166-734596 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 Fri, 18 Feb 2022 04:10:03 +0000 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). Well damn. > 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. Is a manpage update planned?