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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E458C433ED for ; Wed, 7 Apr 2021 01:45:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2F5C961396 for ; Wed, 7 Apr 2021 01:45:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F5C961396 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=lespinasse.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 425DB8E0010; Tue, 6 Apr 2021 21:45:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 899276B0085; Tue, 6 Apr 2021 21:45:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7EA76B0083; Tue, 6 Apr 2021 21:45:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id B088C8D0008 for ; Tue, 6 Apr 2021 21:45:08 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7194A82499A8 for ; Wed, 7 Apr 2021 01:45:08 +0000 (UTC) X-FDA: 78003877896.17.C8C6250 Received: from server.lespinasse.org (server.lespinasse.org [63.205.204.226]) by imf04.hostedemail.com (Postfix) with ESMTP id D6399132 for ; Wed, 7 Apr 2021 01:45:06 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-ed; t=1617759903; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=AZPl31a+Qwjg2yKK4/58wswJf9/r+P5+G7HgfFwgwPw=; b=myO1JlTLVwjj24PaAXDauPLhrNYZf5SriBcRFoxRq6uYNze2pldTo0iqgg/1h9Tk22dkA lmYyTY+Bn1u8AvOCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lespinasse.org; i=@lespinasse.org; q=dns/txt; s=srv-11-rsa; t=1617759903; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=AZPl31a+Qwjg2yKK4/58wswJf9/r+P5+G7HgfFwgwPw=; b=LpXTrEgOQVv1SNRQC0QiFxqtt5r3kW1xS0lKV129jQ3pGExTQLhVAfhaY4ophF2qd9GPM uGdaUjRHHgg/cP2jS10ipaOcP2chwNgqYP7lIJCCkO1TYdBA2Uj42Nzr3HGPQ98ywqLCNZU wzKEZVBj0iYDunZ850zmNvpx0p69hMJ3GQMHiSQzgUYmUNKFhKheqm4Cc2AIAHsKRBoODwU PpvRQPAzz4QgLLQvr5iXXjiYa4nZOwdnPUo77vKtDVwue3bzaanPHOHhoPE9n9Zmktm4Iez 1rE0/jqbi44fDIfdauryJOpQyygXVN/sHP49P9/8OIvq80NkuOX3/i4FFtlA== Received: from zeus.lespinasse.org (zeus.lespinasse.org [IPv6:fd00::150:0]) by server.lespinasse.org (Postfix) with ESMTPS id 301ED16046E; Tue, 6 Apr 2021 18:45:03 -0700 (PDT) Received: by zeus.lespinasse.org (Postfix, from userid 1000) id 1F68A19F320; Tue, 6 Apr 2021 18:45:03 -0700 (PDT) From: Michel Lespinasse To: Linux-MM Cc: Laurent Dufour , Peter Zijlstra , Michal Hocko , Matthew Wilcox , Rik van Riel , Paul McKenney , Andrew Morton , Suren Baghdasaryan , Joel Fernandes , Rom Lemarchand , Linux-Kernel , Michel Lespinasse Subject: [RFC PATCH 27/37] mm: implement speculative handling in do_fault_around() Date: Tue, 6 Apr 2021 18:44:52 -0700 Message-Id: <20210407014502.24091-28-michel@lespinasse.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210407014502.24091-1-michel@lespinasse.org> References: <20210407014502.24091-1-michel@lespinasse.org> MIME-Version: 1.0 X-Stat-Signature: cuc33mzb8ei68n9qbiohbxu4pt63b8ye X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D6399132 Received-SPF: none (lespinasse.org>: No applicable sender policy available) receiver=imf04; identity=mailfrom; envelope-from=""; helo=server.lespinasse.org; client-ip=63.205.204.226 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617759906-333205 Content-Transfer-Encoding: quoted-printable 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: Call the vm_ops->map_pages method within an rcu read locked section. In the speculative case, verify the mmap sequence lock at the start of the section. A match guarantees that the original vma is still valid at that time, and that the associated vma->vm_file stays valid while the vm_ops->map_pages() method is running. Do not test vmf->pmd in the speculative case - we only speculate when a page table already exists, and and this saves us from having to handle synchronization around the vmf->pmd read. Change xfs_filemap_map_pages() account for the fact that it can not block anymore, as it is now running within an rcu read lock. Signed-off-by: Michel Lespinasse --- fs/xfs/xfs_file.c | 3 +++ mm/memory.c | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index a007ca0711d9..b360732b20ae 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1387,6 +1387,9 @@ xfs_filemap_map_pages( struct inode *inode =3D file_inode(vmf->vma->vm_file); vm_fault_t ret; =20 + if (!xfs_ilock_nowait(XFS_I(inode), XFS_MMAPLOCK_SHARED)) + return (vmf->flags & FAULT_FLAG_SPECULATIVE) ? + VM_FAULT_RETRY : 0; xfs_ilock(XFS_I(inode), XFS_MMAPLOCK_SHARED); ret =3D filemap_map_pages(vmf, start_pgoff, end_pgoff); xfs_iunlock(XFS_I(inode), XFS_MMAPLOCK_SHARED); diff --git a/mm/memory.c b/mm/memory.c index 13e2aaf900e5..a20e13d84145 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4012,6 +4012,7 @@ static vm_fault_t do_fault_around(struct vm_fault *= vmf) pgoff_t start_pgoff =3D vmf->pgoff; pgoff_t end_pgoff; int off; + vm_fault_t ret; =20 nr_pages =3D READ_ONCE(fault_around_bytes) >> PAGE_SHIFT; mask =3D ~(nr_pages * PAGE_SIZE - 1) & PAGE_MASK; @@ -4030,14 +4031,31 @@ static vm_fault_t do_fault_around(struct vm_fault= *vmf) end_pgoff =3D min3(end_pgoff, vma_pages(vmf->vma) + vmf->vma->vm_pgoff = - 1, start_pgoff + nr_pages - 1); =20 - if (pmd_none(*vmf->pmd)) { + if (!(vmf->flags & FAULT_FLAG_SPECULATIVE) && + pmd_none(*vmf->pmd)) { vmf->prealloc_pte =3D pte_alloc_one(vmf->vma->vm_mm); if (!vmf->prealloc_pte) return VM_FAULT_OOM; smp_wmb(); /* See comment in __pte_alloc() */ } =20 - return vmf->vma->vm_ops->map_pages(vmf, start_pgoff, end_pgoff); + rcu_read_lock(); +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT + if (vmf->flags & FAULT_FLAG_SPECULATIVE) { + if (!mmap_seq_read_check(vmf->vma->vm_mm, vmf->seq)) { + rcu_read_unlock(); + return VM_FAULT_RETRY; + } + /* + * the mmap sequence check verified that vmf->vma was still + * current at that point in time. + * The rcu read lock ensures vmf->vma->vm_file stays valid. + */ + } +#endif + ret =3D vmf->vma->vm_ops->map_pages(vmf, start_pgoff, end_pgoff); + rcu_read_unlock(); + return ret; } =20 static vm_fault_t do_read_fault(struct vm_fault *vmf) --=20 2.20.1