From patchwork Wed Jun 28 07:17:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13295273 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 7BBE2EB64D7 for ; Wed, 28 Jun 2023 07:18:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDA228D0007; Wed, 28 Jun 2023 03:18:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B62E18D0001; Wed, 28 Jun 2023 03:18:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DC6F8D0007; Wed, 28 Jun 2023 03:18:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 906ED8D0001 for ; Wed, 28 Jun 2023 03:18:14 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4A35EAF87E for ; Wed, 28 Jun 2023 07:18:14 +0000 (UTC) X-FDA: 80951302908.26.1011289 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf14.hostedemail.com (Postfix) with ESMTP id 7F7C8100003 for ; Wed, 28 Jun 2023 07:18:12 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=SLs76mkj; spf=pass (imf14.hostedemail.com: domain of 3s96bZAYKCAw463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3s96bZAYKCAw463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687936692; a=rsa-sha256; cv=none; b=tVOwZqcGMNN2rHdayTVgF5eMEbC+JHqs3b1sjGwzUBckSKyp28MvAhig60Bha6ZkVkG0Zz ENhN1GZ809THQE75rRlAGScwXzkEuF+geK/DYJSHPR1XFRuYdZQi6hiqh8KZeI3nnWKb0V giCcbyQP9aKXOOBpX/vqDltOBWUE4Ww= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=SLs76mkj; spf=pass (imf14.hostedemail.com: domain of 3s96bZAYKCAw463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3s96bZAYKCAw463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687936692; 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=vpZ4UoIowr79k29KU4+AhJbPBUsrrQbVzV/sKUpKyik=; b=N+1aaB68G4RpoPsE8kYvtE7PvWgnaIujgmO3joolgL5ADukmoDneJLGpcvcOA6lI3Zp5DC 73j3sWVwks98fvuRBuwRGPh93x01Pf6I4aobA5dnyDCIM9XCce7vm4QtDcwHgbmixn7wZB WN3abvNKxsWU9KqcY0NL+CnVfYEMQ6g= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-c18ebcb4358so1335830276.1 for ; Wed, 28 Jun 2023 00:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687936691; x=1690528691; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vpZ4UoIowr79k29KU4+AhJbPBUsrrQbVzV/sKUpKyik=; b=SLs76mkjZS/IPWUFDrWe+WabTw/6PoyKoxnKx5c2+HkFLi1gsV2ZJRy/kBPEq4QB87 XXCvupAyakoRvJUqAGoahV38l60daziRCxaQH0YkZQJeum0l7cxZ9swxwKvx8AmgY0tI cjEEnGBFaiCx1/bU/pacXNB3McOE+Jk0Hg+xOlefDx0TtzXaRptU/gJksUoFQPPsoJXj izcVNfG+LPXBLJiFXsBGAKDDPYYmNba9jLKhu2cVp2Dpd1Gvc5i43PJyyrItFsO+BVJP czQYZMZ9+UVoJRF+70p5nESx05q4a/7PZSGqtMaNV3Jb+jUrhGMXtqVQ/GrAP+Eu7+7/ 6nSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687936691; x=1690528691; 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=vpZ4UoIowr79k29KU4+AhJbPBUsrrQbVzV/sKUpKyik=; b=OfKq88lvPHfdmX0+Cjqlwnpd5xOdQ38RYNTe/MFxMJoeFmcG9cOl0dQfRr3kUZGSok UGLGMFDcsB8gIVG9m4suo/Zw66NV+VVgEQzEGM+11zYirO3Hl/x+2lcAxSz7S8ZpZf9N E6PmDYzPeJN80xXz/LW3va14zVkVnHnxHDj5LGbKERW/Q3OFLlO+6rE1WVTQtKMzJyJr fTJiM2SsmpImCP5N5va/ut8tbQn9zzWwh1owAYM4wqXL4TPMQ8pT11XdNhylLI0w3SDe pV/cVh7jgTPWTly0yqgv1/U6nqjCwShFQ2fhKhOZn/irVZB8FCqhkUnQFby01ht/Br+o GeIQ== X-Gm-Message-State: ABy/qLY0xofliEMUM12Gs0gN/mbYze03nZMPRWRMFaQfysbbctc0iVSX ArIvUhwj6hZpdSZnOUJjrT+nWCbKIWw= X-Google-Smtp-Source: APBJJlFgJ2jRK81tWxhk4XDKf3t6TTIa6oT5N32m+JJJWdx/Y3G1ED6lRjtvxsVjVQo+TveZPkRF5dvhPUU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6664:8bd3:57fd:c83a]) (user=surenb job=sendgmr) by 2002:a05:6902:1105:b0:bc3:cdb7:4ec8 with SMTP id o5-20020a056902110500b00bc3cdb74ec8mr7690ybu.6.1687936691637; Wed, 28 Jun 2023 00:18:11 -0700 (PDT) Date: Wed, 28 Jun 2023 00:17:57 -0700 In-Reply-To: <20230628071800.544800-1-surenb@google.com> Mime-Version: 1.0 References: <20230628071800.544800-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230628071800.544800-4-surenb@google.com> Subject: [PATCH v4 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: rspam08 X-Rspamd-Queue-Id: 7F7C8100003 X-Stat-Signature: wxm7c3zr3sf1mnijtb5uncbj5h5aoj9x X-Rspam-User: X-HE-Tag: 1687936692-578327 X-HE-Meta: U2FsdGVkX1+U4D21o+cJkpAS02oqZIJ9i03bMyJeQGTpKQFajQU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VgUQP3iRc9NC8GJZCTwVZCIrLZffCsq9khx3+eKAUbRV3ucXL24lDoPQ/lkDGw+/XjNmWDJiI1ozxy3mpvjz0XAqd7iabnxS0tQXJWlUup+LKAgB3oHKVTNe1KnS+tfxE4HtA5r7F3DMk6TFR+zwJc+1Nwr+A7Gwn2yoybbdcqs+p/WpgUrRkBadVbaebLeokH7d3inMhN43TAPGqvV8TFuhYsPOgw4V2AzYQNQixME/99qyiQjUGucBuPjRmq2X9ae13CQWwGk0FzDMD1MVFy3/01GbgNqYQWB7KbCZsKEyrCcnxiDCFJX6IgQ3c2vx1B4L0Lvs6hkvosCT3NG7v7pxRg5w40mLL7wxbGWQsbQotJxvGsJM52Cyn1XzVoRm5jcBH3pdUvQOc2lCXUqg0MnQSJ9c3lBmzUfmlNRRlOXuwHeuyvrz7ADL1BxCUCsdAtUBXw4+VmsdyHVDlb9+F7urNMp4yY4JPeYF/J+It6y7QxhCqHnYlaV49ak84wqbkq8hRvpGEA== 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; }