Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18914759rwd; Wed, 28 Jun 2023 02:24:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ZUed/yia9ZoiYmgH0QHuhWvWNDAWMqaWrGi5grSH5FtufJ/EjT0TsoGOUz4+M0+qHxZ78 X-Received: by 2002:a05:6a21:9016:b0:110:9210:f6ac with SMTP id tq22-20020a056a21901600b001109210f6acmr22162465pzb.37.1687944252187; Wed, 28 Jun 2023 02:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687944252; cv=none; d=google.com; s=arc-20160816; b=t0wAN0WMuh0YyQTac80Ar13TMqY8pXBaSYU+UR6J5Dgn1pEjCWsbkG6aVx9BjEW7sV cgouEu8p2vC5J3A+GZsvvs0vHHdByA8EeBcOvnHB4ZQMjFVsSinhh7WNFNspByTr7/mi UM0PPEpFVHB+zVHi3vXNQKTJoGpz7eTpJPMtcAaZrCR9aSkHso+p26VOvUVRiH8skalu slxccL542L7gmKpVxhTdslHqhibqeTErZGGS3qXhAjG4GG/6fMPVS0RIfMlH6FWLH1Yy 6bdtfjw/soMk9AKwpRU+joNbpVTCrWPvoJkatW7WSfOBCEexHlgYBohlu+F9w0ecsESg WDbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=vpZ4UoIowr79k29KU4+AhJbPBUsrrQbVzV/sKUpKyik=; fh=RMSYO7NH5mgRq+Q9Sd8uvtKjjFjspH3ZqZT6M3GUwas=; b=iDuLG2I32lzheVXAFqmGSmeuMMd/yii/ClSfQJyB9jfaA9rlgjFhjXyJLeW4CtUykk mqCcDR14fun58ZwB//U3q/nFCSicVAGtD6Yz75LNAaYEJ5g8LKx8dKtFeKzEgDY55VvJ SaLIShLW6PhmIAaTotkMUBRfSbIwz/QsfjCSfvajLeGZB8nlxUHnEAxRlOoZw1Yd8Mlb TmbZ63M00qhZ89naqjb74H/M/EJ4LUKJRcWzjPaYtkwVLZz4B485WcNOPQQvXllj18VR P3GxhGcMIzl5L+AqErqDIdRCVwPDsmTe9ssL8nvwR1o7I8FmWo+w20klqno83cNgBbh3 PO4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="Y/BmyWEp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k5-20020a170902d58500b001b801044467si6191261plh.3.2023.06.28.02.23.52; Wed, 28 Jun 2023 02:24:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="Y/BmyWEp"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231186AbjF1Igr (ORCPT + 99 others); Wed, 28 Jun 2023 04:36:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234156AbjF1Ict (ORCPT ); Wed, 28 Jun 2023 04:32:49 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2EF719A6 for ; Wed, 28 Jun 2023 01:25:08 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-c118efd0c36so1463786276.0 for ; Wed, 28 Jun 2023 01:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687940708; x=1690532708; 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=Y/BmyWEpuUjChZT5QdMMP23e5pjfNPIZ030KUHXF3YPb34eOidF7lQwnrjyKF0VLru yCn1PKNYo9pyiiY+Fa7ii3YrTr/SVuMiXElIIztvzuFRH0vPTurvtANRAe3kmh5rzI8F nIi7cfvOCTDDkhzjaYgm4FXGtm1xvw7xnZNVEcZktnj+cx4AjS3jm/BNAaupd+A5sUZG TZwxtrT9Srz/yiCUYSHbU2wo2cll9XFfJhkMH0PFV5H2igsfhdEgD2xUaxvXw05t8Ywf NArOOkAjaoXb9Tv/FvLZZI3pIsEkSvdO+G3PQF210WwBo0qYEHRZFiIr+sQLSt4NWVVa /XXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687940708; x=1690532708; 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=Y+3iDgkHitDv5lso9vrjUh/v5PfDeqQZV9R1+3VCmpjACelYEKvfE9hgngaRn3N4Lr jSuHwFwMrb6pHuuFfyPgctCO+cmUHFEPPlLQbLNBDF1G04jOG7/2AS+Ue6HaCQ+e/xed d0J2rQVGlkZ94SNaJ2IQ+z3sVCbKnyVwYVJtVvB1WJ5WqPAmVXh6OL5B/o44HKDBCucF 0ip+3gZwd58N4rZWlb8WtiYepRO2J5sAw1pgjnDE0MrhQ/XhBN6xKGzBdZzFbSWm6ZSk B7DiH6rKwZUBaIRs13lwGaWFrIrYRitO67jwMtbcF1WU0Equ3wO6+4bLrKxCTHenGpYA 4qzw== X-Gm-Message-State: ABy/qLZD6j967UXlrASFi8TwprD/8WHwzq+xWTUODR1T8x6PBXKsw9rU OWK22kLVY3kTjVq5xojOMnyr49AAZLc= 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; } -- 2.41.0.162.gfafddb0af9-goog