From patchwork Wed Sep 27 05:25:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13399938 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 E6C6CE80A89 for ; Wed, 27 Sep 2023 05:25:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 844E28D007F; Wed, 27 Sep 2023 01:25:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F4B08D0002; Wed, 27 Sep 2023 01:25:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6701F8D007F; Wed, 27 Sep 2023 01:25:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4A1B28D0002 for ; Wed, 27 Sep 2023 01:25:28 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1E3061A0FD1 for ; Wed, 27 Sep 2023 05:25:28 +0000 (UTC) X-FDA: 81281239536.24.208F604 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP id 7702CC0018 for ; Wed, 27 Sep 2023 05:25:26 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=C555FVAk; spf=none (imf10.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=1695792326; 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=THwc4fnOhp9odGE13p2PG8xoZR7MkxHpU6yd8j7wazU=; b=LFEsgkY3WikamGDqNGs8pbx8NYAcBRBT1ti5mXCyo+7le+QuyGIOFkaz323lSXyauO/36k A6aC2ZFLqQNT0oOSHxS1OS9M9ewVwdhai30T76x6uKEDqeuZjPKmXTnDXRYb3OTzys90+O u6gQa2GnplSANkL7RiZGQMwYTT7WZZ0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695792326; a=rsa-sha256; cv=none; b=7QPMgUbxOa4fE7boZkrXdv2E7W9B/jbvaVjslg60sA34XaNgenFUPKAHQsxTdkE5t5bODX yhwRDYIWS3uwGRjG49sydHuHQddeMx6wa3dajUT09M9TXUPHX8ndv1Hta8IYsE/pnSBcHr ByLXprgOwdD0RmHdBTkmYzBXmxaKu3Y= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=C555FVAk; spf=none (imf10.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=THwc4fnOhp9odGE13p2PG8xoZR7MkxHpU6yd8j7wazU=; b=C555FVAkORYddRC9Hc7wFKafyK o8Vtg/i1YL3DlOC99+hT1ecHohXzAkHV/WOHgk7/aRLWCaTRadWJ9rrHwT7XrxHAcLrLszEwCk088 soRFEeMiMtXt54wu6QwzHDW/8s1DhVKYBqDnTYysJo1G5ypoPK7c7mHKTEdXS+kuhfyZb5Oj+71/U YIwhg1V2zYT04GwRwGZ/lGPJJphhfedt3ai0qx0se7N6kjVjqz+Qvdrj57q8kAXZZ392RYnxYaua9 Pk+wOZe+i4k8RQCIHkV8H9aekSkeSKHZ2v3WTdlvTwfKk3VRyQgmfGDyRwrhd2/Pc2rJ1KQK4ZfO2 l29bpzfQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qlN2o-00Byx0-Uk; Wed, 27 Sep 2023 05:25:06 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Suren Baghdasaryan Subject: [PATCH 6/6] mm: Handle write faults to RO pages under the VMA lock Date: Wed, 27 Sep 2023 06:25:04 +0100 Message-Id: <20230927052505.2855872-7-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230927052505.2855872-1-willy@infradead.org> References: <20230927052505.2855872-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7702CC0018 X-Rspam-User: X-Stat-Signature: booud15w49ccqwquik7jz5ntzjjkgt6o X-Rspamd-Server: rspam03 X-HE-Tag: 1695792326-492187 X-HE-Meta: U2FsdGVkX186HfcKJyEDKeSSqCIVRRXam0YO9Mg+l3L0FwcoqZ5dHvI/050dvcgCcHl5585mYVAHq0J9RMXlAmoxoLoNSEDFJu4mwMXazZ1e6ynSOPZsQAeCfIOjEY/KVWdqvGDAGhpUzrZtsAb7cPQzy6brRJjMv1coAEbpSjetkAnUbmdqijPkGqci1Z94ZoiIfZIjNcEDnb2eawAVCxSwJu2o+vH2gwFivJvEube5Q7XFNCeJIj08Dsco47Mewe2Xz6zJjseEy4cJHdcM2R9mzhLIeDX7FH+Y1vY7g0Xj5BvZDGYN/IphahEnApYuEevXxsBWn5C3Pvd87t090o7KOjeUl6Bg2rQRZn07PUoAcZaNTLG5kOKgBIl2XyOYsu/cp5YFSNrWG45W81dFV41WFZfi3sj5/rsVzhXlXinDrQdyUh7PRgiW6OcyA94huC+trpgneIWRHVrro3xHyJWgVXB05uLlwM18N9iw15pRrPB7eiDvXpYL/WThx+5LwFVVzCwuOcjbPGme9nPpFIQkUvuN837txfr66uUWPA6UZ52KgId5gWsdF6a8Ce+fLtOl5Le/N43c91IWAIEPyJISLNK8dGABTu3TCdkkkDfWN2TABJuVg9W2JFQTdVKaDM7aiE9M5vNpOWlhGag+2W0jVhsWPti4M5VrIgugi8jDX4jM5NU3gmCFMBKoXlJueAAGrLg3rl+HC1i+qbo1spMrpIW13V2HibjblV1lBUuCzQEFMGDTsfKIUSl950xxfnspoOmc1cS0mvaGQMErZjTM2bh3xR3wbB82cJOq0Q2MpTZTA1vY7vA8REiWbNKbIXE5flSPR46JR14ftkajNwDdyL2Hvb1SIZWgo9pQZBR7EBVdOmWgPQ07fnh5gyuR8fGZFW1lcpBMGAK9fipT21Y3mdIy05LeDbW364PrtfFpJYSbDJTb5NoFfQqNUX4JxROV9gErxa1kHxVef+2 1nOWbg7M twRwvdAbPKrg5HEuDHgFqgQtt460ucBIn2sCtAGHBIAJPdPQix5gp8y5HfAPd/Dz4qILOANUMluOXiuhwoHU9Jjx5qL70PzQX6naMuCi/XcOnOnpU/CC9n1md5wKIrH4SWoiTTwZfwI+vwM84HqWiZiuGEHJvY9DRQQTO2huRU/q77vxIReyuiYuSNA== 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) --- mm/memory.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 5f92126dc527..45ffa0a527ca 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_maybe_unlock_vma(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_maybe_unlock_vma(vmf); + if (tmp) { folio_put(folio); - vma_end_read(vmf->vma); - return VM_FAULT_RETRY; + return tmp; } tmp = do_page_mkwrite(vmf, folio);