From patchwork Tue Jan 7 03:42:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13928059 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 09259E77199 for ; Tue, 7 Jan 2025 03:44:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92ED16B00A7; Mon, 6 Jan 2025 22:44:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B81D6B00A8; Mon, 6 Jan 2025 22:44:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BB936B00A9; Mon, 6 Jan 2025 22:44:09 -0500 (EST) 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 4BD176B00A7 for ; Mon, 6 Jan 2025 22:44:09 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C265DAE753 for ; Tue, 7 Jan 2025 03:44:08 +0000 (UTC) X-FDA: 82979262576.15.A0E95C7 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2080.outbound.protection.outlook.com [40.107.236.80]) by imf09.hostedemail.com (Postfix) with ESMTP id 13197140006 for ; Tue, 7 Jan 2025 03:44:05 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ofGWUPxo; spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.236.80 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736221446; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GvbMUAJxfC2ngJPxfsGXWXX3r9undPrsapqykpYUxYA=; b=n/kKcBxLdu6kTeW1kxtTX3eHNTvXXjKR79uLMprsQ+lO61zpU8ZG/TAB9p1jqUw3wcNbli 0X4ceHdo8JVsOx92ct+b5tkAVaoO+Lp/0fPPANJuOYXqqauRyatePOdn9G7xqcpYrYT0Ku Z9rZarbKWy3XdwQ6cn0DKi0kRBJkXsA= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736221446; a=rsa-sha256; cv=pass; b=GFIoBtIf9CslSPCtznGJDfsIxFUcyZ6RR4d4II9jpeuUvH07dEnYQT8M/8FDK+GwApsen3 OnMcrBqlAIKIAWUqHxRUW/dIUfruepTBcHPoT6UPXoawekoGTG3w4mQ8GP85eTUc9yRACR USz6/76QnNMcmDyfbA0R8ExySLGYrzE= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ofGWUPxo; spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.236.80 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F6hDZ5R2koBnf7vYTnj8T2NJdA2CTaORRKTznw6MPHFY1oDFwn/U+uwdba6lTe+MjGJ76BdJ/sqCsJJbGJEzk6z0xMIWrcrWH0rpKxMoauqJLOXvt81lY8FH6kB9K3rE+EodacF57rGMVXrOwFo8ELUd7tD1EPUKjYeOUrzMHnXQbug9OVw2TLk2H6mOnCkXp0bBiICr2BsNgBAsTv3EQ7q4HEy5J83jJ6GobXylr2fq9FZr7QkdHPDPjE9bk5P7GHeJlSxHJi/hs4hOsT/E3UKn7+6Vsh7JClldIXhNTbc7JekdEVASikfDgo20DdER4MTNv00fDrCR7FeXlcNnVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GvbMUAJxfC2ngJPxfsGXWXX3r9undPrsapqykpYUxYA=; b=FAWe3pViAGo9DpB/qFxhhQhOJhSAkg81+24nKSlRbbMRNpsTb9srxQybB1DnPO3902cgJyPTUgFaddeo3WzccicWCHT/Alh6VA2YrvZYNc2axWFS1X4jLXLxmkdzP/swtjeowmfFbUx+scZczMcITfv9YjZ62kc1a9syGwRswq510qNdevtPNsHntwxRqtBBLKFR8M37d4TJK1CgDQee8HLU0zhGfSyEMjP1reqfaXLlcfw6Htf4UUBzo9dT8VM5+c2OLdDaGbN3VCndN0R/7f+qPyOp9/qt6mI0KNJRvXFjrrfz8vkDCDlkVfV7wJtC8Z02Al7s0TlDOmNkAHOefw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GvbMUAJxfC2ngJPxfsGXWXX3r9undPrsapqykpYUxYA=; b=ofGWUPxolyNOdDjzIP60f/v2E6nrYM38y7arRMLFRhQ1ep8sivPVWaIjZCzw91MXPKSM0eHENovs2iUF5z1FaZeJT8DrqQXSie93SkSQuunqhOaqt4e1mIcG0BcdN+2S0LoLGuUhzuCMYRDV52LB55TYCY7hnepJLCQ1OtZVz5Vyv8tUzc0JR4Tujm/GK5iQYUQBfS2JAcHUNvTu99/pWC9rDxl1GxT9DKcDksbWfw9uY0kD2DL9mw823kLnwOKwcLdp8UMtacleoln2dQcw3mhdxeNwm9WjeUw6+zzdoEL0aEiDYJGQn897wXpNEInvMMqn0xpxk9Jpmm4Gu3aCww== Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by CY5PR12MB6129.namprd12.prod.outlook.com (2603:10b6:930:27::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.15; Tue, 7 Jan 2025 03:43:53 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%6]) with mapi id 15.20.8314.015; Tue, 7 Jan 2025 03:43:53 +0000 From: Alistair Popple To: akpm@linux-foundation.org, dan.j.williams@intel.com, linux-mm@kvack.org Cc: Alistair Popple , lina@asahilina.net, zhang.lyra@gmail.com, gerald.schaefer@linux.ibm.com, vishal.l.verma@intel.com, dave.jiang@intel.com, logang@deltatee.com, bhelgaas@google.com, jack@suse.cz, jgg@ziepe.ca, catalin.marinas@arm.com, will@kernel.org, mpe@ellerman.id.au, npiggin@gmail.com, dave.hansen@linux.intel.com, ira.weiny@intel.com, willy@infradead.org, djwong@kernel.org, tytso@mit.edu, linmiaohe@huawei.com, david@redhat.com, peterx@redhat.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, jhubbard@nvidia.com, hch@lst.de, david@fromorbit.com Subject: [PATCH v5 12/25] mm/memory: Enhance insert_page_into_pte_locked() to create writable mappings Date: Tue, 7 Jan 2025 14:42:28 +1100 Message-ID: <1f41d6cb93fc3db54eb0dafb66fd6f7203249239.1736221254.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY5P282CA0198.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:249::22) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|CY5PR12MB6129:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a6f16b9-4c4f-4009-b062-08dd2ecd813e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: UdS5HtxM3+LzKh52q1mB/OyIbBsCfolhMPE7Dlq1knwsR48h+chz4vC9Rf0CfPTTNfZuAuWhUiv6OF8rrKR8k2wluKPQZiMoQs5utXOjEI8o1tq10jvLD1b3qEaBR2Ss9Z5tk0BxYgAEkZvO9Pj75Ee7sXjiUcywq9XJeVFHJ0wltQoPF6+XG0PzSFnIxSCEmRStZJab4hsPrhrRaC08zBHt8Z8r3j//eAyDBcM7QYtRS4EzpJDkpFB29VuhesdTzCbKvKxK6TUS/JGJ2G6vnV5VNwuDdOZQ3HVFxaoK0tOyF9w3t2DhP92uNOvky7il5lmoSkELnnzJ+baUkv94UbatQOi1psLJ1Fu+iV/nvrDoTSfp/m43cdrwyrU28RVF7657jrUr/Eq6udKc3S+BNMYP/FSUdZ+CphSHVsHdDPLnn2VaC+6KTz7bNBfQFh9WTQ32zANAdb3XZjOxIs+4U9U6GZwomkbbtsVbyULglcTk5LNxjCjNSjc/pS3k/69W1iSiQAzT2iVs6hs1q2wVYK3rrT4PNiJWtTFIf7F2geXyFMPVJWROtufuGIYEIPLf+Uv+3gxDJVWlVStsEbCGf4yfE88l5nXsPy1C+x7SAyKubHqqFvqGlUl5oVS4CGnF5uCEto7B0PHlq4T3pAfB+MkPc6qUlfDsAhUxENPk0vwLflD0fza1JPkgwap0is/lyJOt/a9sXUWYdgRx2SDgURZ8qGZBPt5ALQhQyN7S8hkxwg18wnIL8Uhe8l+ywimp5hz4KpNL8Dlw8a85khpPzp+fMXvVn1oBzZeSmhBBCp0rkQEznOv8nJaWygYEsO3BEYtkzFC11fLoitczX+xs/YOpNzg9rNdY97tDG9KPmDrM6NQ7yMZkO6XNhN8jqDOx+M6X+bPS8AR/vy8MDUoWMDdFz+bn4DRRlDSFfe0H0CDaz8RzaZJHFV9ngvN7j1f37gnKH0lcXqVzQXd91T0LCjxeedGvFT/uB0ULfbYNRxkIkocQVOxS7ZG0oruns5AC+p+zXPemO5qD6vGu9ALhu00gNw4ps9Hr1V3KZA+JhJWtv0JVshrbYBSf+kCTodfb4zEqldq8/iwzfabUMZVOmGBVT+raKDIbt6F0JDIUpNZ1YvbdXdwH+nTRcxIXg6tKjyaqs0xERiNdo2AZBYL5cQtS/WEhISv0wpvqROpDJrE76OEipglFE/nrsKyIjgf0NQBlq+lzqgGcyd+anuO5w6xKwLGUTR8LoCzqxUezwRpsykEgCr49NT9vokqJb1OlMQWS863Q5xsfqswlnkcWLLaCD9gImC8Vnlimp38Vb5xmY+BYqBbCrH4/d62RTCETGL1siBmUNTM1WVPml5FTrFADaUDb/nKKAZxGQQtwAMVWl49z5KZKmoof6BCqLlRS X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB7726.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JOax42wvT2jWhletQQEP9ASUilnG98s33+IvyaH4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jylw9Cx9yO3NeXjGF+/vxEMNZG7ndeTPRb2SZsnBX7UvmaMkJq8nTpvOrPu41LmAmYkL8yajAlCBygUo9qqxnTLjSudhsDYO5SQkS9pFXwwcp2++zWrcRLmFlue0fR2JMIKbPhgX2kt/xd1SGn7xIVIdf5VdqK2pfBul27THPoiTshCYjMDFnezUXBmYE3uo55PXVzQTyKsQcq6zy3ldEb2MSnvLb2ob9pupdDVWa7kMvuS8PXiTKRs+kgTv7O0eaWqs3mDO79H4vfeCCAP9LnUEuVgkpb7LhZLLXAKcXfhR11lnaXh0b4sb1cTUIuZk+MS4qP6yjsgelg9CFB6i9e4QgD+VqNFaAhnhnOKXc9IiVo1Zqv915E9p6XCBgTNHT4pdUVEasisFYdyJdDF8xWMlbMHpjPfb8RCaOv1GAKfCPhjKjAQ/yk/LtSvcNG2cJM/4fFOI4s8vUZ94Jrj+TqIF++63pLicTtE5E/ff1wz X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a6f16b9-4c4f-4009-b062-08dd2ecd813e X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 03:43:53.1365 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rSUu6GNu+qYHH0vLG0vDp4VmmD/TYvNPccBxvE0JGA5qEXsE3uLxIKQQbUq9JFkcS66r8iSEPcFvXsEauV41zg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6129 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 13197140006 X-Stat-Signature: zkkxmr79bpfz4jdqxeouj7pxtg4fxxu4 X-Rspam-User: X-HE-Tag: 1736221445-179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++jB7hsoRaZVt6+crNzxcm1atbl33EYoAa6InzrGIkX8qpI+aUygo2vL16Td0yzIMBzQtKJ4TOunaUtYYTlwdZzxRUgzlfSw2a8ShXJ7Xc40rp21z56U7gJOROsXLPWGfD99y+OvNCVG7/QGDyGID/uiHA+ZTIxU2LzjYv4lhaB35eQWlqJOPCafl9iQ7y+7/xI8we3zglxF+glphS2Krjx+RXG39m9pur0PaFgpYGyQB6X2EPihBqJP3qfRdO1CN6Nepnt04hz4FYIZiLKVygOG6dP1Wzqkd7mvykGDfANqRi6uHgsjekLbfH1Ewt3KpET0GYYLaiu4GFa9gItH3xcFqB/NiGrx9vqSfmGZk8HPrz9YMXsFU/Ba3fYfHVN5NX1X9Wbw9VKVd+pL0/CZX/Ucs= 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: List-Subscribe: List-Unsubscribe: In preparation for using insert_page() for DAX, enhance insert_page_into_pte_locked() to handle establishing writable mappings. Recall that DAX returns VM_FAULT_NOPAGE after installing a PTE which bypasses the typical set_pte_range() in finish_fault. Signed-off-by: Alistair Popple Suggested-by: Dan Williams --- Changes for v5: - Minor comment/formatting fixes suggested by David Hildenbrand Changes since v2: - New patch split out from "mm/memory: Add dax_insert_pfn" --- mm/memory.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 06bb29e..8531acb 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2126,19 +2126,40 @@ static int validate_page_before_insert(struct vm_area_struct *vma, } static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte, - unsigned long addr, struct page *page, pgprot_t prot) + unsigned long addr, struct page *page, + pgprot_t prot, bool mkwrite) { struct folio *folio = page_folio(page); + pte_t entry = ptep_get(pte); pte_t pteval; - if (!pte_none(ptep_get(pte))) - return -EBUSY; + if (!pte_none(entry)) { + if (!mkwrite) + return -EBUSY; + + /* see insert_pfn(). */ + if (pte_pfn(entry) != page_to_pfn(page)) { + WARN_ON_ONCE(!is_zero_pfn(pte_pfn(entry))); + return -EFAULT; + } + entry = maybe_mkwrite(entry, vma); + entry = pte_mkyoung(entry); + if (ptep_set_access_flags(vma, addr, pte, entry, 1)) + update_mmu_cache(vma, addr, pte); + return 0; + } + /* Ok, finally just insert the thing.. */ pteval = mk_pte(page, prot); if (unlikely(is_zero_folio(folio))) { pteval = pte_mkspecial(pteval); } else { folio_get(folio); + entry = mk_pte(page, prot); + if (mkwrite) { + entry = pte_mkyoung(entry); + entry = maybe_mkwrite(pte_mkdirty(entry), vma); + } inc_mm_counter(vma->vm_mm, mm_counter_file(folio)); folio_add_file_rmap_pte(folio, page, vma); } @@ -2147,7 +2168,7 @@ static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte, } static int insert_page(struct vm_area_struct *vma, unsigned long addr, - struct page *page, pgprot_t prot) + struct page *page, pgprot_t prot, bool mkwrite) { int retval; pte_t *pte; @@ -2160,7 +2181,7 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, pte = get_locked_pte(vma->vm_mm, addr, &ptl); if (!pte) goto out; - retval = insert_page_into_pte_locked(vma, pte, addr, page, prot); + retval = insert_page_into_pte_locked(vma, pte, addr, page, prot, mkwrite); pte_unmap_unlock(pte, ptl); out: return retval; @@ -2174,7 +2195,7 @@ static int insert_page_in_batch_locked(struct vm_area_struct *vma, pte_t *pte, err = validate_page_before_insert(vma, page); if (err) return err; - return insert_page_into_pte_locked(vma, pte, addr, page, prot); + return insert_page_into_pte_locked(vma, pte, addr, page, prot, false); } /* insert_pages() amortizes the cost of spinlock operations @@ -2310,7 +2331,7 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, BUG_ON(vma->vm_flags & VM_PFNMAP); vm_flags_set(vma, VM_MIXEDMAP); } - return insert_page(vma, addr, page, vma->vm_page_prot); + return insert_page(vma, addr, page, vma->vm_page_prot, false); } EXPORT_SYMBOL(vm_insert_page); @@ -2590,7 +2611,7 @@ static vm_fault_t __vm_insert_mixed(struct vm_area_struct *vma, * result in pfn_t_has_page() == false. */ page = pfn_to_page(pfn_t_to_pfn(pfn)); - err = insert_page(vma, addr, page, pgprot); + err = insert_page(vma, addr, page, pgprot, mkwrite); } else { return insert_pfn(vma, addr, pfn, pgprot, mkwrite); }