From patchwork Wed Jun 28 17:25:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13296086 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 79676EB64DA for ; Wed, 28 Jun 2023 17:25:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B7648D0006; Wed, 28 Jun 2023 13:25:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 468FA8D0001; Wed, 28 Jun 2023 13:25:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3090E8D0006; Wed, 28 Jun 2023 13:25:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 214358D0001 for ; Wed, 28 Jun 2023 13:25:42 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E78581A029A for ; Wed, 28 Jun 2023 17:25:41 +0000 (UTC) X-FDA: 80952833682.05.4622624 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf06.hostedemail.com (Postfix) with ESMTP id 1F9B2180017 for ; Wed, 28 Jun 2023 17:25:39 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="f/qWBsZG"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3E22cZAYKCIo685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3E22cZAYKCIo685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687973140; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Etjd7yIk6y8wpf6gNh6t/+qVgTHbYuzl98QGtof+wLo=; b=wLjuWEUu9l4j6hA8b08DbiHWys1zBw9WIA0R/RnbWHPOBnjfwCcV6J4RNjHa2FMHfz1UWK G+I2lVVfHUFSp+QMBHA1IHFo/EO49hCBfZArAE9RwMGSLSYPz+Z6iViTXQxcJGH7cBx+Sf HonU5HsvXe08dZcl0Y9z/aD6HMsvBME= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="f/qWBsZG"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3E22cZAYKCIo685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3E22cZAYKCIo685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687973140; a=rsa-sha256; cv=none; b=jQ1x0wgD8KCBFqOXEsGYdtiYuwhK9dJFmC/bkR9B/Yltjp5JBHgh7/kL0cokjyfCsIKDiF KThcJ01EPOLvngi11Pu2FRCw0ws+d8HX/X+jVSPC/15aPpLEStQSL5OJlPV4WRVzGbfMlV 5XI4ppuXxfS8etVx9V77CnPnp9G6KVU= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-c22664c3df7so194659276.1 for ; Wed, 28 Jun 2023 10:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687973139; x=1690565139; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Etjd7yIk6y8wpf6gNh6t/+qVgTHbYuzl98QGtof+wLo=; b=f/qWBsZGlwZ5P3Q7P10m/N0F147acALs/pNCcM/R0Pth04XyJd0edvT4fGoeFanU7i nprMaYJ57ZehrPFrJEWv3ay7af2qJ50IjmH60upDZ9HdpmFC8tlgMQahwdbr6hPxrcaH iOO6oMrTdA91rUvBSlj3mK5n37r8vBp1nCpkzIfw6tcfelQj9RfuyeoCq4XRyPGgxE2q dQMo/1n5ck9TGwQyYB/muJ7ImteNS4kZ9vd0EFUXwjlDgrqn/G4AIMcN3x+wt+TV2nOX SE48ZlUM2T4t9Cw7Ds2yMNxtlnhpPB6+PXqMHtIIOsUUg96SvUV200B4lfaag6Y6fl1F QOjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687973139; x=1690565139; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Etjd7yIk6y8wpf6gNh6t/+qVgTHbYuzl98QGtof+wLo=; b=Ym9hkLqvpa/K2qNParK/Vihx9CqLSJNB0IJ89q23j3I7sPyqtB7PB22/c6y4yB4/z8 7vhDjCQwi+TVU0GK7h3zVUprwibcOXwlZHzHe+VDaxf/BIyqtJtXrDEpI/rt7LLT97c2 SiexaLA7PwwZ+FTilrLKH6ZgVddx86TWrHD4e3zhqlkGbls6zv9pln/ILD32nJxmhqzC SBwD+O2pcHNr0sfKCJ6jcks2tgLF+uHzKU+VRFK3eV9iDNRAXwc9y9lffc8W35kHqWCT gH9b2D2G1ToctF5pEtSREoTwPIT1f+I8dTt82FHzLrqxe0boE7dwmGdyUXMCqElROsLt B9ow== X-Gm-Message-State: ABy/qLaOzH8pl7tPqlsEzoVlkaN9t3iRZEz6FzhtF7J5UVIo4GR0+ORp PcmcGFl49yX2+x6I+KYl7VxsJR09miU= X-Google-Smtp-Source: APBJJlGsLGXNMWvz9SGYOgX+1/1dEWX9HTUaDi0WsEVrC4gPxKfPFDmgxWjZwZruzhN/4I0d7h/V6yPZrxg= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:eea3:e898:7d7a:1125]) (user=surenb job=sendgmr) by 2002:a25:f501:0:b0:ba8:1646:c15d with SMTP id a1-20020a25f501000000b00ba81646c15dmr21941ybe.1.1687973139195; Wed, 28 Jun 2023 10:25:39 -0700 (PDT) Date: Wed, 28 Jun 2023 10:25:26 -0700 In-Reply-To: <20230628172529.744839-1-surenb@google.com> Mime-Version: 1.0 References: <20230628172529.744839-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230628172529.744839-4-surenb@google.com> Subject: [PATCH v5 3/6] mm: drop per-VMA lock when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, peterx@redhat.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1F9B2180017 X-Stat-Signature: 9w7x4cz4auiedee1um57fchxzk88gj5n X-Rspam-User: X-HE-Tag: 1687973139-979411 X-HE-Meta: U2FsdGVkX18CJ4y8kOCWCVZ2SoTYhI/ECiRglNGeF+LYuiva6ufM5e8blmxU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xD2Ig0c9ImuJoEYrWTMZaIlVi7sA7MNUotse06GQ5pHbWtjouU1crYTBA+eT76bzy7iME77qKwlQyMJFmbHOXrccER/mjukFwL7NibEVzI/CNOABLSNPMDYALiDmWh6Km03u4wQiwRILRRVOWDGRHzfSEQ1BUvrAJ2md1x3obDTDZMFalC5aT5McL2mA35IjI3PJVjOX++5BsK0DA0cCBWG8/VpRezpXursQh33PDRG726cuqU3RpxLFNy7rhkqXAQV+y3g0MAptFV5ol6vLPY2zQUZbBcEliIKqni46eHaTUfj3R97pqTh+GOhr1FHQdnIs05+HCdzHsOvQ83DVhYKn9Eul/s/izShcoPe6mESaIiHEPpoYlW+WvSkCUCT7M21pc1mlEaf8Z2Rrou4a9uH7RPrCXKb4GrMrxQlQ7WoovTDONPk5xaROTPHNHjemKCCBMvmQ3EYBmVsr+i49zUp71sKRHogfGBVTEDAbBevCujMYciAvv6dE4m52feOfaRWMuDqGB9NLk5Y/PnqCKrvz5k63ncf5RCkuFUCd2OTG0g== 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: handle_mm_fault returning VM_FAULT_RETRY or VM_FAULT_COMPLETED means mmap_lock has been released. However with per-VMA locks behavior is different and the caller should still release it. To make the rules consistent for the caller, drop the per-VMA lock when returning VM_FAULT_RETRY or VM_FAULT_COMPLETED. Currently the only path returning VM_FAULT_RETRY under per-VMA locks is do_swap_page and no path returns VM_FAULT_COMPLETED for now. Signed-off-by: Suren Baghdasaryan Acked-by: Peter Xu --- arch/arm64/mm/fault.c | 3 ++- arch/powerpc/mm/fault.c | 3 ++- arch/s390/mm/fault.c | 3 ++- arch/x86/mm/fault.c | 3 ++- mm/memory.c | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index c85b6d70b222..9c06c53a9ff3 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -612,7 +612,8 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, goto lock_mmap; } fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs); - vma_end_read(vma); + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + vma_end_read(vma); if (!(fault & VM_FAULT_RETRY)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 531177a4ee08..4697c5dca31c 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -494,7 +494,8 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - vma_end_read(vma); + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + vma_end_read(vma); if (!(fault & VM_FAULT_RETRY)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c index b65144c392b0..cccefe41038b 100644 --- a/arch/s390/mm/fault.c +++ b/arch/s390/mm/fault.c @@ -418,7 +418,8 @@ static inline vm_fault_t do_exception(struct pt_regs *regs, int access) goto lock_mmap; } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - vma_end_read(vma); + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + vma_end_read(vma); if (!(fault & VM_FAULT_RETRY)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); goto out; diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index e4399983c50c..d69c85c1c04e 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1347,7 +1347,8 @@ void do_user_addr_fault(struct pt_regs *regs, goto lock_mmap; } fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - vma_end_read(vma); + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) + vma_end_read(vma); if (!(fault & VM_FAULT_RETRY)) { count_vm_vma_lock_event(VMA_LOCK_SUCCESS); diff --git a/mm/memory.c b/mm/memory.c index f69fbc251198..f14d45957b83 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3713,6 +3713,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (vmf->flags & FAULT_FLAG_VMA_LOCK) { ret = VM_FAULT_RETRY; + vma_end_read(vma); goto out; }