From patchwork Fri Jan 10 06:00:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13933698 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 91E97E7719C for ; Fri, 10 Jan 2025 06:02:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3090D6B00A6; Fri, 10 Jan 2025 01:02:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B6FD6B00A7; Fri, 10 Jan 2025 01:02:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E3746B00A8; Fri, 10 Jan 2025 01:02:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D759A6B00A6 for ; Fri, 10 Jan 2025 01:02:30 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8230B120814 for ; Fri, 10 Jan 2025 06:02:30 +0000 (UTC) X-FDA: 82990497660.08.67CE88F Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2083.outbound.protection.outlook.com [40.107.100.83]) by imf03.hostedemail.com (Postfix) with ESMTP id C295C20004 for ; Fri, 10 Jan 2025 06:02:27 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=e2BPexFf; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf03.hostedemail.com: domain of apopple@nvidia.com designates 40.107.100.83 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736488947; 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=LHF9yIYFSBkDrWWm5Q2w+o+FZwVZ6F3GbxhCIiJOiz4=; b=y/sZROy+bI/oj4M0OKtk8NKwkI2nE2Sw/Nkxsi78/N8k4IXB5ygBZy6xuJKWlGyUoakXAe LEOCk4NhQr7WNyRnUCRnValOlZbidAyZdlBl+oBODH4L3rLb4vu3FIw2bMRO4o/Nq/ihA2 cSDQc529ksCIfwZzkoKZhlWvRCDDvWU= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736488947; a=rsa-sha256; cv=pass; b=3tFcJqtZXFWwgnaEDMMGO0gwNFxu1Juq/0JR3XlyyWwpoP43CVGTmPGWkxrM9zptLq2zj6 OBkGf0ao52L1uPdAs1mA5lLM9WQTTNQvN2xPykXN5hmtgJqNxCC+YlsTDv3gn8J3yXEwWW assWSuht5B150+3EG9SclGX1t+ge3oY= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=e2BPexFf; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf03.hostedemail.com: domain of apopple@nvidia.com designates 40.107.100.83 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PgTiNY4A4r8/QYaaTU537MTOz61mXhVza+OZzKGaBwmz2KzYQiOwLhdfgaYyYeLSTVSSRWX/JNcpmCD00+oM+Azkecp5UXJ8VQoCHNT6dZuXmpr+718v76JdACukmflLCoRWfQcqY+SPvO/sE3VdhgH/ypxkDS8ocmSjeQR2YqtsUaojohrjFGWd0ujP7Spb/JUwgmv7BeK+mnsqmJck23fDaiU9VzniVMrv6cuJ9Q+En9yGH5q+42Y0xGg9wo8d47TJFaFU+gl9D3sPzUYi74WNZwlIP1gKCBXcJgmimY2VDMXat411AffrcsA6TTnqYg6kz7Zy/0GNWyx6FYy4NQ== 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=LHF9yIYFSBkDrWWm5Q2w+o+FZwVZ6F3GbxhCIiJOiz4=; b=EEBO+7eJ7IfYr5/NReg1i8fv6fN1JxDvcZkU3jQsGYXC859I8VtcC0CoGX+otmOjx0uzZ6AVI1e9s9Mg5lUxyrKt1D+igzIUm0s4BCvGMOxM7RcCOBmTao1vg22ziEdo4+FEVp9cnp61vTI8iEfJugDa0iFjepu5mPKN5BlfYcHsoEkLNYwI6KlDsCNu/y2wp7VlCEpdiukOLe4qX2rGlVhOqOJydTscdZJG0skvlDSHcYgLXlfMIBt+utOg6LKGbXvfZ+DH6t8vBij2SI17HtPsr8Np11CFejSl8OyxHN5dcObqo9KZJYkrKVhwiSRcuO9xjia5weG4j6S7kGUYOA== 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=LHF9yIYFSBkDrWWm5Q2w+o+FZwVZ6F3GbxhCIiJOiz4=; b=e2BPexFfr2jHS751+WiMeuPHWRSUso2/Bre8nXGv1uTBnstnBGk3sUDeK1d9oWM34mhUEeKS10AEBMX5LA5bK4k0b82cAthWRriWM02SsiNDuzOjwk3sP+z094a06OBUcYlyulDVe+38TGxgcoThiIcl6z5W5oQrvZCKhwt3JWqxog6zHXtW9aambqGOlPqa2NAeqCHPdYNG0Ch4gr9/Kbc7YwNZKZDhe3oVQSZv0vulnERyc1TeMGW7PGtmYXLCtAynU50DRwkM1hlL/BxqbayFXqLSsJGf+Sej0UhmoPLQ3ZOc4cVsKTzjfq5I9AAMaZAktm6YuEZYSWVP6jo9dg== Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by BY5PR12MB4132.namprd12.prod.outlook.com (2603:10b6:a03:209::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.10; Fri, 10 Jan 2025 06:02:25 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%7]) with mapi id 15.20.8335.011; Fri, 10 Jan 2025 06:02:25 +0000 From: Alistair Popple To: akpm@linux-foundation.org, dan.j.williams@intel.com, linux-mm@kvack.org Cc: alison.schofield@intel.com, 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, chenhuacai@kernel.org, kernel@xen0n.name, loongarch@lists.linux.dev Subject: [PATCH v6 13/26] mm/memory: Add vmf_insert_page_mkwrite() Date: Fri, 10 Jan 2025 17:00:41 +1100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY5P282CA0021.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:202::7) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4132:EE_ X-MS-Office365-Filtering-Correlation-Id: ac49c2d0-d595-420d-7e8c-08dd313c5b0a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: 0te9+hLgdyBwA6pTyT2iowxccsDjHTVRSkxEopDiv0PtqRAMkSMmvdX0iIjiyg8I0wAHmp6igTwErACFA5JmS7UqfZfX+0UqsOTqmRcOWDIvAEc5nmKIAeUsofzC/akWR+yb2BncQTxwqQ6SIZai7dsikxWv7VHYAQDX9cNwRC4G2wmfII0SCZPEiNoxuGoSGzv4MCHTZQND+xQQSQ6wyHMewhUDevSiEjisjNuBwazSEpB+UzvZG5ULZZtv0D+P3M2TuFWNuIzgJNaE9mHLDeGz1Bf98WuTQ8So/R0yJMvVGDfdNBuIfNo8GK6orYz7miLyM/3HpfJf2b+EUDQMRinfldATO7VlUtexkPiFWnw0guQGRq96yJA/VCCk/D6YGGmsXAnJNciqnZLIQVjeOcSz4Fm39UxJ16V/ENKVrUFlHuHPpO1afmKXiJ3MuxEQTl/ZS7PDaXoofc3ETBEvwG+DD7yd2kXgWnTF4ko7bOwzFd2e1toOJ75p5mAxOs2Eq/t0vQ8JwXzMfaTAY22u1fZUze6Ln0pgz9UGz1byCZM/BingFhn3lPNkyuk/az5qPN2beTF+vvWO5s1/o8yHouW2FgXbg+tTSTGjx52rM5r+n41Bv1CZfUzbttbx77M6pYz6pCxIR5AM/V5lNybqOoQ5T9+VLG25tPRgp/y6zOuDDQ2JxsFgQEOS/TkUynhheinveHD9rw6c+RiumQY0IzIxJKUt2itGLvSF1gviEsFGAumqx+d2/QJNiYp/Re0kymZBDZGOtYktxu8yWFJJPeXI2BFYxRJggIkEEozDEDyl31r5QR8NFhDznohcCP2W/ZiV7K317c9gA0VhEXYm3hrmitwVQijYuRFisCQHJrMCV2JfsPA5gGFRAe1LHEg6FfdFZ2cPXI8/P8nS2p9RmuOh9EoRjk1//wWIKpQJsypJkZe+xh3j8zHxDFYQ+ymrTXtK35z/PqmP7RQ5OgUkhvxlt5hhpA6vhNe1/+u3Axu98oYWkTICY0hWKiRWl/eBBdi94kD9x+sKeoYWvQ6i+MdfqLxf5FYyqFc+dczrJGf8D6xTCswysijWHyI6Arfcu7Agdf1FmlJcEQZppZ71ix/Wib3fRzvOTtsdE2UoJZXEDe9Pnje8qRql5NW/1xkXFnWMb0Z/h7mGD5oD3w4pCK9PltkwjGgAMAqGjKsn+fgT9sizcmq8N/8MSJrEmI0yAnT2edVsvRKruXJfsniXnipPo9Rd5C071MSHy6kdknSmrN8fbhxZHQWJI9Mh4XbCdZBA1CpfBZcpRiZI1oPZ9J0xlGkM0VSIIvhYl9RuRxItcQbHNpwFHhBp077TU9Lkc6ziEPyhQbO3t2e7975USjU2ND2GaUKvKIlVqUR04P/6MRW6eU8ELDZdWQ8vmeUt 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)(1800799024)(376014)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QMfm7iNyFYvsOZWsAror1s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1qhYpDVgXQI/bpct+q9DLXca5+cAYYHiTzdzm6yqhQPaILNJsibXdcL+2xc1ojPfwubRkRWROo39giw1dmpmQ2RbEIEHq4ufAksZwlg5Q+isrrQKLcvQau9DmovkqpG2DvIdOWCRnrXQE0wvxYiCRcyXQUhxFMLDf+miwdA8+waDYWTh6JiUJpl/TWU54Kl2hq06VWBBpj+brl9spf20FPY7YhTwvCNsjELaaAk0Cmm9NKn6DcPqYP4TWrRerWqgosUFoUFx9wKmJkjRAw+EZw/+Dc/r80nQwThom4TbiaDXPNzvUacFbSfh81WQcAg0aEFsPobvzr+upF6qcbP9gF+yznxaA2VKP0JQ0lNXgsf3QYyTJ1yRILh7LYNc3wo5QtofWZVPJNwhP+wkFRJ/gipbk13mnDcrjemgOMWyjfzujfX7RDjSNAjZXMBCir63leH4ym1n0Hiy1WwIHl2fmzhMhufCBXyMGEGykwg2caGhS2B9Nw4 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac49c2d0-d595-420d-7e8c-08dd313c5b0a X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2025 06:02:25.4570 (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: A3uQKPEKD+WyHnU5uJGaPFxPIRsJG3rEya2gJhqV7ZCn+My3OT42JAyceFujF8LmlIffUZgIOyXFHN95etSgBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4132 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C295C20004 X-Stat-Signature: 94r9dk8bjhptyesax5d1b3aj15c59jst X-Rspam-User: X-HE-Tag: 1736488947-247188 X-HE-Meta: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MwY9dEb1gigfnSOHqM+FGlmq3eMhFQroAwpjpLAFZCj+9fCCQj5SeEEmW+0EInr8LzHRptcDwzy0xIBjQS3G9PpZjP0gyWTHyst70KO6ZjPFEnC+9JDWdeNLll/lbZJIIS0Gl7AGNJcZ5xA/L1NIN+m8b3hIMghv3AuljX9s1OVBkFLbIOY18Xf2PN8cXBScpWlNpqvqaCi5hvFutshFqa7b2xGy0QTXv/Wr6WsWFuxQs0NvqYXVHvKxMY7UlEH7VGSyloJ7jf+1V9MA/Jt85OpEkamJK5g90SGnvRYt9V2G9yb0TSvW2V5N5wYmIFSW3YUxXqtsmCNT4UM+RP1U3OPvVu4Uoh7TQZ7dPG5EyJyQqmFcjvCY2FERyBnTUwB49xVta5SXBwa7q7YjyMHdXXd0D91kAtGfn3aCWGjB8fKB7FFF7+I9I6mS7GfvT4XSmLwyE7+jh6WD+HhamnjE 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: Currently to map a DAX page the DAX driver calls vmf_insert_pfn. This creates a special devmap PTE entry for the pfn but does not take a reference on the underlying struct page for the mapping. This is because DAX page refcounts are treated specially, as indicated by the presence of a devmap entry. To allow DAX page refcounts to be managed the same as normal page refcounts introduce vmf_insert_page_mkwrite(). This will take a reference on the underlying page much the same as vmf_insert_page, except it also permits upgrading an existing mapping to be writable if requested/possible. Signed-off-by: Alistair Popple --- Updates from v2: - Rename function to make not DAX specific - Split the insert_page_into_pte_locked() change into a separate patch. Updates from v1: - Re-arrange code in insert_page_into_pte_locked() based on comments from Jan Kara. - Call mkdrity/mkyoung for the mkwrite case, also suggested by Jan. --- include/linux/mm.h | 2 ++ mm/memory.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index e790298..f267b06 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3620,6 +3620,8 @@ int vm_map_pages(struct vm_area_struct *vma, struct page **pages, unsigned long num); int vm_map_pages_zero(struct vm_area_struct *vma, struct page **pages, unsigned long num); +vm_fault_t vmf_insert_page_mkwrite(struct vm_fault *vmf, struct page *page, + bool write); vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn); vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr, diff --git a/mm/memory.c b/mm/memory.c index 8531acb..c60b819 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2624,6 +2624,42 @@ static vm_fault_t __vm_insert_mixed(struct vm_area_struct *vma, return VM_FAULT_NOPAGE; } +vm_fault_t vmf_insert_page_mkwrite(struct vm_fault *vmf, struct page *page, + bool write) +{ + struct vm_area_struct *vma = vmf->vma; + pgprot_t pgprot = vma->vm_page_prot; + unsigned long pfn = page_to_pfn(page); + unsigned long addr = vmf->address; + int err; + + if (addr < vma->vm_start || addr >= vma->vm_end) + return VM_FAULT_SIGBUS; + + track_pfn_insert(vma, &pgprot, pfn_to_pfn_t(pfn)); + + if (!pfn_modify_allowed(pfn, pgprot)) + return VM_FAULT_SIGBUS; + + /* + * We refcount the page normally so make sure pfn_valid is true. + */ + if (!pfn_valid(pfn)) + return VM_FAULT_SIGBUS; + + if (WARN_ON(is_zero_pfn(pfn) && write)) + return VM_FAULT_SIGBUS; + + err = insert_page(vma, addr, page, pgprot, write); + if (err == -ENOMEM) + return VM_FAULT_OOM; + if (err < 0 && err != -EBUSY) + return VM_FAULT_SIGBUS; + + return VM_FAULT_NOPAGE; +} +EXPORT_SYMBOL_GPL(vmf_insert_page_mkwrite); + vm_fault_t vmf_insert_mixed(struct vm_area_struct *vma, unsigned long addr, pfn_t pfn) {