From patchwork Tue Dec 17 05:13:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13911031 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 2A642E7716A for ; Tue, 17 Dec 2024 05:15:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D02166B00A4; Tue, 17 Dec 2024 00:15:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB2CB6B00A5; Tue, 17 Dec 2024 00:15:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A693F6B00A6; Tue, 17 Dec 2024 00:15:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 86BC16B00A4 for ; Tue, 17 Dec 2024 00:15:37 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 50216AE96A for ; Tue, 17 Dec 2024 05:15:37 +0000 (UTC) X-FDA: 82903286886.01.E08C7C9 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2057.outbound.protection.outlook.com [40.107.237.57]) by imf27.hostedemail.com (Postfix) with ESMTP id 1867740011 for ; Tue, 17 Dec 2024 05:15:00 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=pxrbt5la; spf=pass (imf27.hostedemail.com: domain of apopple@nvidia.com designates 40.107.237.57 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=1734412520; 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=+RK8HcctKWrWGjHAxyN8k6xlAbP24zFsv0TFbZlW19A=; b=nYBRI6vdJDjehD0c9e6UwbYjU9vd6MeR2YGGRdKp4gT0oqH1EG39UveIZ9JZx4HFU8lIV0 CF8116YgYQXqr4nJtwFMHvsSEB1kTE59tzoBiFfQAbptJQL9ZxaMSb9hnE/EmPUSW7TtgZ Dj4tqpOz3xz1ieDoqeFSF8IMAxEMMf8= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1734412520; a=rsa-sha256; cv=pass; b=hvzZXaJL5TaqZpqd9BvJl7L6qFusi80Zmjl4y1kOwlLn9usGfyMTC92fhgMDeZi9eEm31h fVMHLRAyp05t3y5uA53YUUnHMNfe9+ZKeFrGVDryMZWPy5XtoxK1p26Ctxi1fBnUZOoECg Mr7aXNolQsSctH/c0u9tgr5UYOC1jmE= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=pxrbt5la; spf=pass (imf27.hostedemail.com: domain of apopple@nvidia.com designates 40.107.237.57 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=qF57srFH519e7P7RO2dcihHdh2eL/xzvm+2xqN3hIX3cH0nq4qIA2t36hnjBJRCN5sDJbcX9qdW9d/L8+Pfm3hz96U4wtE4/ZL/IIr8JY1f+or2vsIhiRJXgAmWh05fBt3TlYpexGnk2+5E8kmnqhZ5bA78Zs+eTthMWxVlw5keq02O9p5v6Y8aq+95pgGQ3MgXYkwx3xkNdx/SzrEcupPPREwPw/ZDp//ZByI/zM32TrSqLydRhHSWTygGKWi1PKS/d6RLXXPUB26olk79bE1dHdAHYTFnXnRZfY588Dglg2Wswtm0fx2WBLs9np1jGocOpRCPB6gBOHRZCsl8XLw== 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=+RK8HcctKWrWGjHAxyN8k6xlAbP24zFsv0TFbZlW19A=; b=opXrj7SbXd/MoF4o2gSLxss0S9/bWUkozbovykOXmWCzVBUeW7O35zUjU03tBV1/0UkKbSVxDZq6ndXiHakx8j8yNcwZZbZtj5gx1C8UjUagMshsJR/6SRH0nAaN/kvWj/UEmZ5ScrmjA5kwoQnLcgPI8qfiaXZLNagHJt7T0tkD9y6gtBcOWlbhXwp6khfEY4SB+02M2fQG0vRlDZ8eJdNAxbx2zo5Bl9wtXA7h0k3HL+Zgk7iRLmNRPxW8TqAn8IfFTplpGfpM0+c7vV2ZdfYYdcI5OA3p/lcQgcjSaEXt0vwbHE312ha8mTJ5IknbvLQF8cTZ8KxWKELbXGJ6YQ== 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=+RK8HcctKWrWGjHAxyN8k6xlAbP24zFsv0TFbZlW19A=; b=pxrbt5laaiD4HOnHxQi8mKJNCZkAbiIdFKK/H7B9luGn+IDh+k2ZqzwNLevYX+lvqw6fqVlutYdjLqi5PFVubkLT8sGBD128pHtQ9ZOC3Vq5qM8hENP3FgAj2CLS9eDLuN7RqZUOH1aSsBrOr9pce4XqWRkR6Wmhe48DtNtyI2orqWv+nohYbaT06upxujl/xBIKPd04l+Ri7PRAEH6wEfEvJCeVozqNa2+JeNBgmd9uqP8wTpd5eY7RTHX3oX/DDZ+lprEFnpsu0x+556oMTRcbpqizlu0gtU9xY6m0A7dUXxKSWuQvKnABOYIDMbzvP/zFt/UuC9trHUoIlHYpvg== Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by DM6PR12MB4388.namprd12.prod.outlook.com (2603:10b6:5:2a9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Tue, 17 Dec 2024 05:15:32 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%4]) with mapi id 15.20.8251.015; Tue, 17 Dec 2024 05:15:32 +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 v4 22/25] device/dax: Properly refcount device dax pages when mapping Date: Tue, 17 Dec 2024 16:13:05 +1100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY5P300CA0022.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:1ff::12) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|DM6PR12MB4388:EE_ X-MS-Office365-Filtering-Correlation-Id: f81d557f-2c0f-49ee-8a3e-08dd1e59d483 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: zq3vf2bInKE36eN0X/iCid4SIT2hITWwMoWuLPtxLWILIM04N4dIfrSPcDS114GHgBtpICnF8GNjXjt2yrxg4Ak2UR0t2bH95wLGtBCRw0I8Y8DuTgddQJOmFiYLK/uWtQUaAIgAyFFy1h1WCgmFQB2YcJnEv2pHuZuPv6UDiuiP70cFzYU7gpFUrGz1mgPtCuz/T6EPp7M3F+TpYevd1iedH94Au+WHscuN8JjANO5LERDFAUItBFHBImYF5Ow8hmbEASnNfDX7sfnu/l/PoluvHIN73UUMiFa72VWBdKsUW8SSG63KoU6jXmxNxr7FKZJ+bGB5DKTC8yTlqSy/vzdBlpVprRJaFFHIKvR9mKO3EdVzRne3RG5fmGyMvsvMx5oSfBWgTBFWaK13xp9dLXIwyNF1ZaXAMu/A6ZgEGWcX53XJWUcPU2JeLTlyhlX/bbjQ/NeqS/52oQboN4Ew14zUpcDbzU5thuRhYyhSkwqejVjY3Tixi0zyNL1Sg/Oyw+vXgq9Xo7UUVXhaU9LPwngukuCtGGhSgd6YRTBeM424CIozjCewMu5T9Egn1+DCNTK7RrU4fXaYdGZd8M1rsyT2SFKv6+LJOh7RZBsqVOSygv1MvkNSlKTne9eCkAnacdKnyvbtS8xk6mQ6vMRsAvHzx9URPAhWTQvQkbaESV6LKov7B9Ju26CCNoUqq5Mtgp+fUvxTsFj+QbPLjBzYGGg19r2MXbLwX7e4dhWE8x+RtS2kvlSNL5pvP96dwoWk/5rfw/7mheo2LytN2guuBQRZhrDICvOSq8gQPYEqDqyhpcz0cFXP8J8XsgFX0qmDt8LDWTzWMj/jC+W6O0PLoToCwnaZOxYXWxeIJPzVCOLaaRkY7TSoJwGQ7ptApt02ma995fSnNzZSV6U6WZj+DnqUprFIA3080TxwrqHlCtNT1/FJW+dP4F1XgTEVOY+yxtuIbr9ImKZAjvZspBB7nXTS+tMqb8dTMIwR9uZfrrIQ2R/u0dD2B5witZW2IQybBD//2Gm3FKYCkeIAnOzvKYvaTnj0Tz/65abpz/4PQ83YrY4hoOaprcvNbLE5Gh2nALzCBofkicl62zGeCOGy+t2fsAvQDI042bA4JxYm/em89/m67w7ulrXXaWccBFYwqmXCxrisVTbBO0t6+LsPK7n3TuotuZ1dFf3VJRAgBZBzKn5ZHw+Mi6ca+bAeOCwIIQn/enZa2Z/DLl1wk2q61kuyfBTKMlGQAWoZMbq8zJKrrezMLIEn6IKd2SOMH9G2yoJBsxO7ytCKnHjm/gk+xAQVSkgcQLtoiKgMfgcrbe42V0wUCv3RDkOXoa0DJ6uYOIyqbkXhV6mHGF6MzxkBIH1XsEQJpvWFYMOBwaWBrFTZSp/DobPJ+ysk2ndSOjJo 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LX9GV4FQNB08hEnE728R9r9FmMdM5tA6IFDivr6aQnrqZOv2BlQTjou++q04hEukp98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zaMLxRWHGnwOLlQ4Fe3blwYJZaU5uhGpIhPqIkC4s8Ow1OCtvNuMdu68qM2R4sAglwgWoLvNfJs97k4EmVZNkCRABiq5FNV8l2s00Xht1Pe3DbrQQUV+tOuiAQO8cUa0g/GsktGm5k6N/bYGKoMdCQfmLNEIEBfrOrpaJxCgPHg1XEAE91ec63nvwr0G8g+YVvb2UgOwm+54a3ra/CbodJHZOkCA51dAGMJG+Za54Tf4k5Y/GuQ41ztI7mCv9kriWbi++kKhig4fYaT6QsrCs1MFzuanVYw7+UIDrsXuozjD5D5fbpDfSkvXbI5NcoTP+4bKbqoUBkFwTTyTQTb/rsD/cH0lnYLPGIWrulbd+6be2AKiyRrL1Dd5xIe6vyYBOCpLSMmdG1ERglcXx1sK8AtcgeuW6E3J8K1BxLHBA0OSqi99oqftrJiZT6VX2cfTk1iSqpkO X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f81d557f-2c0f-49ee-8a3e-08dd1e59d483 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 05:15:32.5649 (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: AsFC4umf4Px8cqi6FppADGLNXIEVP5M+7IoaVKLfevtAv3PjrDn9U7axRgZeeaAEgBbP66jCjvlqiA41LrAXzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4388 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1867740011 X-Stat-Signature: dqb6e7e5wfka7msq9mpxqdrg7yrauha6 X-Rspam-User: X-HE-Tag: 1734412500-241 X-HE-Meta: U2FsdGVkX19UPDlDPNg5FAmRmu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Xs+onzZyb0MuqyZuIyDGr6jtp67s9TcAEiw4Kul/pQsy5KQyx9R7fPs+YlDXf6fFwkuTFu1WJLeHvYByZz30iSVwXl7ZkWv4epCJ9nphcAuVh38oUItU1PjAo2ooYMF5K6j/+4m44R26WxPiCko51xJ6E0hpgjxi1aANF72neLxD0aG+oSKR6Tmq+/G1yAEZjKtfEkq+B80VLAdlk40CA/wqbR3BVi6XXQAE7HeU/qmDkhc51tqhGldRgtkT8YX9yFD/XDQQU5vracr8Cp249ICFxGZp/yuZJGSQcFQIKWWJQ7Z 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: Device DAX pages are currently not reference counted when mapped, instead relying on the devmap PTE bit to ensure mapping code will not get/put references. This requires special handling in various page table walkers, particularly GUP, to manage references on the underlying pgmap to ensure the pages remain valid. However there is no reason these pages can't be refcounted properly at map time. Doning so eliminates the need for the devmap PTE bit, freeing up a precious PTE bit. It also simplifies GUP as it no longer needs to manage the special pgmap references and can instead just treat the pages normally as defined by vm_normal_page(). Signed-off-by: Alistair Popple --- drivers/dax/device.c | 15 +++++++++------ mm/memremap.c | 13 ++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 6d74e62..fd22dbf 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -126,11 +126,12 @@ static vm_fault_t __dev_dax_pte_fault(struct dev_dax *dev_dax, return VM_FAULT_SIGBUS; } - pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); + pfn = phys_to_pfn_t(phys, 0); dax_set_mapping(vmf, pfn, fault_size); - return vmf_insert_mixed(vmf->vma, vmf->address, pfn); + return vmf_insert_page_mkwrite(vmf, pfn_t_to_page(pfn), + vmf->flags & FAULT_FLAG_WRITE); } static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax, @@ -169,11 +170,12 @@ static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax, return VM_FAULT_SIGBUS; } - pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); + pfn = phys_to_pfn_t(phys, 0); dax_set_mapping(vmf, pfn, fault_size); - return vmf_insert_pfn_pmd(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); + return vmf_insert_folio_pmd(vmf, page_folio(pfn_t_to_page(pfn)), + vmf->flags & FAULT_FLAG_WRITE); } #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD @@ -214,11 +216,12 @@ static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, return VM_FAULT_SIGBUS; } - pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); + pfn = phys_to_pfn_t(phys, 0); dax_set_mapping(vmf, pfn, fault_size); - return vmf_insert_pfn_pud(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); + return vmf_insert_folio_pud(vmf, page_folio(pfn_t_to_page(pfn)), + vmf->flags & FAULT_FLAG_WRITE); } #else static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, diff --git a/mm/memremap.c b/mm/memremap.c index 9a8879b..532a52a 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -460,11 +460,10 @@ void free_zone_device_folio(struct folio *folio) { struct dev_pagemap *pgmap = folio->pgmap; - if (WARN_ON_ONCE(!pgmap->ops)) - return; - - if (WARN_ON_ONCE(pgmap->type != MEMORY_DEVICE_FS_DAX && - !pgmap->ops->page_free)) + if (WARN_ON_ONCE((!pgmap->ops && + pgmap->type != MEMORY_DEVICE_GENERIC) || + (pgmap->ops && !pgmap->ops->page_free && + pgmap->type != MEMORY_DEVICE_FS_DAX))) return; mem_cgroup_uncharge(folio); @@ -494,7 +493,8 @@ void free_zone_device_folio(struct folio *folio) * zero which indicating the page has been removed from the file * system mapping. */ - if (pgmap->type != MEMORY_DEVICE_FS_DAX) + if (pgmap->type != MEMORY_DEVICE_FS_DAX && + pgmap->type != MEMORY_DEVICE_GENERIC) folio->mapping = NULL; switch (pgmap->type) { @@ -509,7 +509,6 @@ void free_zone_device_folio(struct folio *folio) * Reset the refcount to 1 to prepare for handing out the page * again. */ - pgmap->ops->page_free(folio_page(folio, 0)); folio_set_count(folio, 1); break;