From patchwork Fri Oct 6 19:53:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13411938 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 6E7CCE94107 for ; Fri, 6 Oct 2023 19:53:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07BD680011; Fri, 6 Oct 2023 15:53:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 02B6880008; Fri, 6 Oct 2023 15:53:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5BC980011; Fri, 6 Oct 2023 15:53:30 -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 D96E980008 for ; Fri, 6 Oct 2023 15:53:30 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B25631CA4D9 for ; Fri, 6 Oct 2023 19:53:30 +0000 (UTC) X-FDA: 81316086180.03.A3D0786 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id 1F256A001F for ; Fri, 6 Oct 2023 19:53:28 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=QVcBvqic; spf=none (imf15.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=1696622009; 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=7oiMnjIM4hSkmqR8ZCJCtaNuaV9dY5uCykUhLQHJ5E0=; b=VYLJQkAObk35EnRHP/tz1gGamwuccyIFVfpZnF0dHfLvF70X4RWxMgP1ywRnRj3y2WrUkJ n/t0S548dKRtKqNBKiibkCl6TERVq/y2axV1VhxFM/0MEiJHMOuhb6E4XgWq8U9Y/uT6uk 4JyWkhhIJdZnlhoeGGjgZNkd4G7ew1M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696622009; a=rsa-sha256; cv=none; b=B25agC9mj1ZEp3BQdzMys969pd6AaHlaN5j4sEddaAkRpHE7rXHRwj+WWdfIppPqb/1l0h qw0q1GfuRv4wfwQTkQQXG4OGbLeO18SzSqfKOWY4g4tIlm1jspsv82//7s+jqp2U1+OLHU 7GSY9OmzpsoBpRZBlLekL2FjXg9NA90= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=QVcBvqic; spf=none (imf15.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=7oiMnjIM4hSkmqR8ZCJCtaNuaV9dY5uCykUhLQHJ5E0=; b=QVcBvqicFZyjYIraMPx3PklnEs dhlC6U2v9hVGbzTBNfv3ToBcyaQEaPBbJDz2y5wWxjAcGWdxDjODyn9qFTwPtFXEkBkMuxPqs1cQ+ i3I34tIp/qFDGliRowh2H5uZx8JLHfG6g3s4OHxVXPF4+nhPerhazD3LAROmh6JXKTwH/K9fDyZ00 HgVz+l7bvQgVFk8na2jjWsflWNKoR3BfUSn/eD2iQeTC70Uyq4WomaWVFvQ2N3n4tO6rRiTg8EtrC 3WRRXNlR3YHQaXzIISoAFftQ8BJ/ooDxmnJieU095v3BQMBk2+HdI3T54tjGUncozkclAFKt5yC9Q V+z7xxvw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qoqsy-00H9Gq-VH; Fri, 06 Oct 2023 19:53:21 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Suren Baghdasaryan Subject: [PATCH v2 6/6] mm: Handle write faults to RO pages under the VMA lock Date: Fri, 6 Oct 2023 20:53:18 +0100 Message-Id: <20231006195318.4087158-7-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20231006195318.4087158-1-willy@infradead.org> References: <20231006195318.4087158-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: 7xiw9gx3odyhy4hgtcjz5d8k7y3q5px3 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1F256A001F X-Rspam-User: X-HE-Tag: 1696622008-48554 X-HE-Meta: U2FsdGVkX1/+dWC9vc8h6E6XAslT9mnGrbf3ZS1KgBpnudjlvt6SMa1i6RW/i4V6kvXsD/CKzz3bY5p8ZDmDjCeZhrDPqIQNpRAisPzWa2lCQ4ETlLQVlBQxhpBtF84ecHUO8b8Lh3okLPYpuJmr12hsqTEjMbabWt+OpbQ7m0L5wgufgIUYp4Pvhk+gvDfuKXNIXRYJv+GhfQKq+96xyGY/BXqJNUCn+MGQWttev8a9doseKJUhz1C0Nf00ER+t/L3GeC1ljd0tYpPRpxOjsfKgibbwdhdtW+PrIYpPYUf3UbwSAOWOg39/tD5gkcqjZeSwCo/1z9W9R39xESXopTubZmd2EcQ5wm5jdMMrmqwh5Mng//L65oxToOqI7PoZ4AF66Ost/3mZMk5kpZ0syTuujVUmkz/AidY0KJQo5Pa8HYSK8H7yqiU411iZ61RxWZR5reVE4lGMnjLSW/i53jyGP3Jz6HROpl15kFiUkwRsGCt1uQcnlvxeSLf/iHRnmCrjBwU795YLEmv/BWtxMPkasdDpCnm1McAKNxSzwLWS0fPlX7HGasV1WFNx+6rBrzP1yJCf0hLxLoIbh13CPbgejyvUIndtGhQkDs1lZm9bISvMrLZCPUyK4qWzA7pN19xtUWG2GFJnpZPbND2m7mOYE49ANjfH6bn/MuiXFUFldOmwzq34ctsHr18WCVpQYaFm5gvCCw5Sk+Rfu85p3Ub7JanbttPxADrPDW6E4bmki/Xw1U7QBI6SkvRDiTBHldQ2z1rqeL9IrD4Fxo6z7y9xz6eGggyoOfyUKUk1U8WoM94wkQyBUicBBwkxs+1UO5cHzoe1Wez0qwBrCuBKDJP9pgXxfYxoOXA2eZfKnKzvr/qHh2licqILIOwKpzeCGXAheJexYvBZFpMdglYjZQmj77e8cmOzITaX5hQpRhdzPq3TpNKodSZPgoq7Pc5AmgF6FThrIPxfJEomEMK +xQkSBsm spoBdMuBCt6Dxc1pwroYGC6nYw121xy6rw3nbEAPg90mAWE89HRyfDHZKGecT8gZROYJTxJObgGvXP31UjTBgesCK4AtwssXnBBxMWo3VW/urj7Bsec3BJRL0pUhIyL00ll6ZGunfkfzOfrEh7ki40YUDwgzEDKj9mHTKew/tf8VGLE4Jd4hef1emMw== 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: I think this is a pretty rare occurrence, but for consistency handle faults with the VMA lock held the same way that we handle other faults with the VMA lock held. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Suren Baghdasaryan --- mm/memory.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index e615afd28db2..3d1bc622e344 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3301,10 +3301,9 @@ static vm_fault_t wp_pfn_shared(struct vm_fault *vmf) vm_fault_t ret; pte_unmap_unlock(vmf->pte, vmf->ptl); - if (vmf->flags & FAULT_FLAG_VMA_LOCK) { - vma_end_read(vmf->vma); - return VM_FAULT_RETRY; - } + ret = vmf_can_call_fault(vmf); + if (ret) + return ret; vmf->flags |= FAULT_FLAG_MKWRITE; ret = vma->vm_ops->pfn_mkwrite(vmf); @@ -3328,10 +3327,10 @@ static vm_fault_t wp_page_shared(struct vm_fault *vmf, struct folio *folio) vm_fault_t tmp; pte_unmap_unlock(vmf->pte, vmf->ptl); - if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + tmp = vmf_can_call_fault(vmf); + if (tmp) { folio_put(folio); - vma_end_read(vmf->vma); - return VM_FAULT_RETRY; + return tmp; } tmp = do_page_mkwrite(vmf, folio);