From patchwork Tue Jun 27 04:23:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13293982 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 18EA4EB64D9 for ; Tue, 27 Jun 2023 04:23:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CFB48D0007; Tue, 27 Jun 2023 00:23:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 759CF8D0001; Tue, 27 Jun 2023 00:23:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55DA68D0007; Tue, 27 Jun 2023 00:23:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 473288D0001 for ; Tue, 27 Jun 2023 00:23:34 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 19C691405BA for ; Tue, 27 Jun 2023 04:23:34 +0000 (UTC) X-FDA: 80947233948.01.52ED914 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf11.hostedemail.com (Postfix) with ESMTP id 4A0BF40008 for ; Tue, 27 Jun 2023 04:23:32 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=ugW+SG7Y; spf=pass (imf11.hostedemail.com: domain of 3Q2SaZAYKCKASURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Q2SaZAYKCKASURENBGOOGLE.COMLINUX-MMKVACK.ORG@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=1687839812; 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=kbyeBW7WIJNXjK7iu35fAbN/5yTuDJs52xpJl7xU1IY=; b=vD8kem979exbJomXU6LoFhWkW8Uz9XjEIRWqEjjNjgFiWBLAZ4w0+PcvnaByqD6fY/f/7B ehNAKY5mhTh56YZvqgVlziusVCyaznP0qE89YtUwnuk6a7wH6nRcnpeMcgOzz2nFXuaPpA RLuI5Rja1BOY1ofSocEanAcwsw95ivM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687839812; a=rsa-sha256; cv=none; b=ta9i4o7Lnnxs8w/+ZnLfbVKxUE/XLym53t5GQAtHr/tngjx2IcZrZ+eew91dCV0Mjj21rP JUGo2dUQ0/PgDjanOFDhSAa1Ux3lFxwrLqo1MwUtPZDcbAdbrAwr0h87i/YvnHlhdg7cXO byxF+ctAgKDHERiVuTD4MUF7RgPZKE0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=ugW+SG7Y; spf=pass (imf11.hostedemail.com: domain of 3Q2SaZAYKCKASURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Q2SaZAYKCKASURENBGOOGLE.COMLINUX-MMKVACK.ORG@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-57003dac4a8so105903097b3.1 for ; Mon, 26 Jun 2023 21:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687839811; x=1690431811; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kbyeBW7WIJNXjK7iu35fAbN/5yTuDJs52xpJl7xU1IY=; b=ugW+SG7YngNovW466Ob1qbMUa7QCgvQN2HYZdw69vEb2gnilYAyfBBDC9eIv0kJn5R K+Nth6CovXEzufoeufA2bBetWvrGzXQiUD8VhdoqNnFL16vRdxwfeZTWoLlNANAXPsaE 4it7n5SCFHwAzJ+itDODzIf22wtA7wDa/2u16CAUMCgAj1Ez2yBmApbjIHS34bZr0QAs 6CcMERtjjQw5qzSYxGAWzCQbLbu0UfN+0PYZKiPIpB8IIqWC1ndKoEhlLxsLL9cLvsPv v4BzBjfVXuH+PyuaE6GmW6rTE2x5EJClKScB3InhL/RUrH4gPNiYW0KVLBDn77KNMcAS 0haQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687839811; x=1690431811; 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=kbyeBW7WIJNXjK7iu35fAbN/5yTuDJs52xpJl7xU1IY=; b=d6qnswB9FiwybZRW3WbOeYsR1ADyRR/WppbgxCEXtD61oQxvU9OtTOnyiEf8YvMzVC g+HQeWp1nQtYa8v0gVw2jTV0e4APeany6dSwvNBpENdJs8+1yRFRNWOPI17k2ek16UO+ qbiggJiDm2b7VpZCivAxg5cnnFJiJa/8yfYaVQGsXNU828IqyfDqOUon0WZNIExU3Q7I yD674te9FDIR387uQdDlNSWs0l2MsI5g4nUr191fcDGfjLeU3vFzSm+HP6J6Znc47r48 e+kYuUu8tmjlCaO4xBronea1Y5hcsYJI5WT8S4MHRgefCPGuEIdZ1mGwX3/Dp5m/qPBs 3geQ== X-Gm-Message-State: AC+VfDyMm5qDagDrCCyVF/D+p5QEvSzIGWHdiYSvfKoPhAwBvo87dsqJ GvOz0/LrMusrR0j8+b74ENOPy3Vu6kA= X-Google-Smtp-Source: ACHHUZ5PHgbnMPnEsTLa+W0vChTT29tB4jfEbEI5BqOjiRDx9zMqo94H5raeRb2+zfsUTcjeQvPxANoMY/M= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:5075:f38d:ce2f:eb1b]) (user=surenb job=sendgmr) by 2002:a25:ac92:0:b0:bc4:78ac:920f with SMTP id x18-20020a25ac92000000b00bc478ac920fmr13716099ybi.0.1687839811426; Mon, 26 Jun 2023 21:23:31 -0700 (PDT) Date: Mon, 26 Jun 2023 21:23:16 -0700 In-Reply-To: <20230627042321.1763765-1-surenb@google.com> Mime-Version: 1.0 References: <20230627042321.1763765-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230627042321.1763765-4-surenb@google.com> Subject: [PATCH v3 3/8] mm: drop per-VMA lock in handle_mm_fault if retrying or when finished 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-Queue-Id: 4A0BF40008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: osuopdwzysdy4goutndhiizhxtagauhe X-HE-Tag: 1687839812-754379 X-HE-Meta: U2FsdGVkX19pIl7EHWojHtfustl3QnUgrqX28PuAyzBx4L+QQy5xBRP83qtd7AqikPubGYcqy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hRHmPwpjkf39kD893RM9vmf9byWFIfKKcw7O692Rdo8+kiFj2vCLcqEYMkIQnmIGFZZCtzmuKXpRej3pvx8i9Whl1kP+FlCEtFXJo19EGsjopoeTuLVYKmcAycRjwBEhiRnTs/Qv3BCEt8gv9uuxoskfBU6cWmzI3QU2L7O1hZhXd5ELwxis9hv2aW57mm4ull4XkudK81+geCtTT7a8f0H+Urmysw/bsylMcmg7cvUf2MAl/EYNGmtBAk0DRWUa2sSSEui09rJNxWv5UFt2sbfZ00tYjvtNdPfYsUK6aLrg7E1arn6xxw5Ohowv02dxgA8RKxtGLBxriGi/H0S42Nzpm7AVBegdiTC5EYVa1bEHrTXOB1IaKBWbbr9YF84fo4H0nZC8RphAHF+1fQxTvYds+Eq2k9yO9gEWI2cSFoZRqtnOrI8Jgy1A4S1Ouh48AGS1swfy376ZngpcGA0VA/hQxx4ym7u3VY6tbVOoYLtqs7DAxfc4aIEg== 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 before returning from handle_mm_fault when page fault should be retried or is completed. 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 | 12 +++++++++++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 6045a5117ac1..89f84e9ea1ff 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -601,7 +601,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..9011ad63c41b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5086,7 +5086,17 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, } } - return handle_pte_fault(&vmf); + ret = handle_pte_fault(&vmf); + if (ret & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)) { + /* + * In case of VM_FAULT_RETRY or VM_FAULT_COMPLETED we might + * be still holding per-VMA lock to keep the vma stable as long + * as possible. Drop it before returning. + */ + if (vmf.flags & FAULT_FLAG_VMA_LOCK) + vma_end_read(vma); + } + return ret; } /**