From patchwork Tue Jul 11 20:20:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13309339 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 13DECC001B0 for ; Tue, 11 Jul 2023 20:21:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40AA78D0001; Tue, 11 Jul 2023 16:21:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BA886B007B; Tue, 11 Jul 2023 16:21:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2825B8D0001; Tue, 11 Jul 2023 16:21:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1860B6B0078 for ; Tue, 11 Jul 2023 16:21:04 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D76651203A1 for ; Tue, 11 Jul 2023 20:21:03 +0000 (UTC) X-FDA: 81000450006.03.5425139 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP id 050D34000F for ; Tue, 11 Jul 2023 20:21:01 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="ZX0x/yAQ"; spf=none (imf04.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689106862; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y6MqKlK6OxY+tonB29qlEWdduvckRCFfUllkRcgCchQ=; b=BVbe04bfUvuJpfbCr4avuEGeGln+EHFCmpnuITWqty3IfO6Hp7wgJYCgasaJh1UJF4A8eq RUjdFLloHn3amwrIPAoR91sRvgppmv5uZ0RX79+iy/20bN5er0iu/jIv01pXS8fv5jByLQ jHAzfi2RZov6VYCO86qMZU0JAfEQg7k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689106862; a=rsa-sha256; cv=none; b=mjrgYrccSrTHAKOLp8SeO6ag0Q4s67RZq7kJFIsoFLsTVnAOLRObCnxt/8ueYadP70hYTJ sVURqcvWOXVO+lusL1Z2wgQcMKOBpa4CdNPO3UVf/zOGkcnVuADzRkbzI8/WZj9R+AjNwi T002FNDRsAwowmwH+RJG8tdxA4MCK2E= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="ZX0x/yAQ"; spf=none (imf04.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=y6MqKlK6OxY+tonB29qlEWdduvckRCFfUllkRcgCchQ=; b=ZX0x/yAQj25a5I0W1lufq/qwUP oXson9J+2ubQdjXaXjjRQ+O80fML4BiNDyo6y8jRSU1mXCImAXYb7ruFGwoRefM3EqSQc1BDVRPo2 ppz+hwLnF9JLwe05Hcdxyrw3BWuVIpaMCFMjDmpKW1LoHIwy9KeZbvl1DlfsSmjuvhHINYGd8vruW wwfs5AZ3GNemhwSJxsakWnNgZpxjJnyTa/d7nKlahUEur99F9UV6GUfq7l/OxED//pTMUJ0Bk9pGb qK6l4TnIwmYQpiv/bo7yufDpeMmcqZxl85DCZrq+hr9QYvbfBAf+PWdagfdqEdA21O7KpOeUCFSP8 HfNHy3Gg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qJJqs-00G1QH-5O; Tue, 11 Jul 2023 20:20:50 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Arjun Roy , Eric Dumazet , Suren Baghdasaryan , linux-fsdevel@vger.kernel.org, Punit Agrawal Subject: [PATCH v2 6/9] mm: Move the FAULT_FLAG_VMA_LOCK check down from do_fault() Date: Tue, 11 Jul 2023 21:20:44 +0100 Message-Id: <20230711202047.3818697-7-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230711202047.3818697-1-willy@infradead.org> References: <20230711202047.3818697-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: 888yyyf5tbz6wgubfc53u336t7pedbds X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 050D34000F X-Rspam-User: X-HE-Tag: 1689106861-428889 X-HE-Meta: U2FsdGVkX1+ApfogpcE0k0Jtvc4x7jnHCZJ2Umc3Al+f0cWgx28wK5xWjOyd83WeMYY1taSmcbL96c8bYyLkyGaq9M1BlRBnn5sQzBgO2C1VcOo02K+2kVa5B3auq1B7DsUNmFZlwh30mYVyAk4Ix0ImqvDClNyp7GDIopooXCTq2EqHhmV9vFtGLHn4BT4twOkBB+9fEgXLD/Pfz61YyXoyeBFuit/deY0nQEPBe4KIoMqp71NuFdzIwiIUbhYxrL/nwWdqmd8FDDUlkdUOIoelpA68WOioHUhZTubru8EGeu0ovardQlWniuo/ozUx2f+cYawVlU2cN47IERYaUqknzcJfkTM20sg50v/rB2QQlf3hDbvcDeBm+8g0vr+yaZ5r2b7nMCJRIRjkZgpnn8PHfSqtOwmiHcHSgWlzm7/k5O38YlGDhgaqoshYVg/MKP26uYo2BkqG0TtIh+qf8VMAN2zZl6BQhhuesH1Wm4ka1zc3r9TwyvfH6B8bz5GwUr94d0HfrmHcL/wiRpY2ArePBiy9R+gVF220fPfbrRBbQ9hMt/w4nmF6TrMAC3Bbq9JVDN4I6bLFOkKidHTNniRPT27zgU4jSVmzaf6xPjGhZAG41XMEjW5Pevr4lhADQ7l3PpZRLNd+e3xjYhGSkWwk2Au3/Lk8Ocpc9VSx3EQR0YvE41e4+eHP+HW+76iZtASyZ3sDk8KG3oNyGkDNJQxPqlHuQUPZmhTUNI8dKuvBDMlhw9JtrMD4YgdQSz1dzADrWJKlYHQz+2sopb8ojyjDbEbFk5n5n0U6wpRlDHyCMRkiNMLTQSPOuAf2qUrVqh9nmHyBjwCL5VsJ+qK+5nOlMIYxAJbdL1WknO7Oyv5WD5aWDqQSuXBT9/oPJE+OIGc15vES7n009QbYSEWY/SQWqPTqW5P4Qm4jU/yTWDyJwV0fD8QolWQokjSh8ZWRfN7IiNZm/98UB0QQOld XaEShdKd dS+rW44qwFia2c+rg3kHVzBZITAY9PuUHCFqw/7AEnxYSsh2MvcWmS+PR5DBEq7ttktSNkU801rHPnNILactJ9SafcdaaxV6qL6NRuXv9W49XUh26+Z0iZvMDsIy+OudGKYkH3wyfJLmG93RZH6VhbDQvTp6m/2kFMVIqbBXm2GKSUe6YeaYfqrBE844Y2a2TnD/mN4iP5RCOUfZKqmCsyi4kME+FcJwdVwOw 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: Perform the check at the start of do_read_fault(), do_cow_fault() and do_shared_fault() instead. Should be no performance change from the last commit. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Suren Baghdasaryan --- mm/memory.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 88cf9860f17e..709bffee8aa2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4547,6 +4547,11 @@ static vm_fault_t do_read_fault(struct vm_fault *vmf) vm_fault_t ret = 0; struct folio *folio; + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + vma_end_read(vmf->vma); + return VM_FAULT_RETRY; + } + /* * Let's call ->map_pages() first and use ->fault() as fallback * if page by the offset is not ready to be mapped (cold cache or @@ -4575,6 +4580,11 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; vm_fault_t ret; + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + vma_end_read(vma); + return VM_FAULT_RETRY; + } + if (unlikely(anon_vma_prepare(vma))) return VM_FAULT_OOM; @@ -4615,6 +4625,11 @@ static vm_fault_t do_shared_fault(struct vm_fault *vmf) vm_fault_t ret, tmp; struct folio *folio; + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + vma_end_read(vma); + return VM_FAULT_RETRY; + } + ret = __do_fault(vmf); if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY))) return ret; @@ -4661,11 +4676,6 @@ static vm_fault_t do_fault(struct vm_fault *vmf) struct mm_struct *vm_mm = vma->vm_mm; vm_fault_t ret; - if (vmf->flags & FAULT_FLAG_VMA_LOCK){ - vma_end_read(vma); - return VM_FAULT_RETRY; - } - /* * The VMA was not fully populated on mmap() or missing VM_DONTEXPAND */