From patchwork Fri Jan 10 06:00:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13933707 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 EDBCEE7719C for ; Fri, 10 Jan 2025 06:03:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C4946B00B7; Fri, 10 Jan 2025 01:03:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 74B1C6B00B8; Fri, 10 Jan 2025 01:03:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5770E6B00B9; Fri, 10 Jan 2025 01:03:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F10FE6B00B7 for ; Fri, 10 Jan 2025 01:03:18 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A833C140849 for ; Fri, 10 Jan 2025 06:03:18 +0000 (UTC) X-FDA: 82990499676.16.8A30270 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2073.outbound.protection.outlook.com [40.107.93.73]) by imf14.hostedemail.com (Postfix) with ESMTP id DC685100004 for ; Fri, 10 Jan 2025 06:03:15 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=IsiidAmI; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf14.hostedemail.com: domain of apopple@nvidia.com designates 40.107.93.73 as permitted sender) smtp.mailfrom=apopple@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=1736488996; 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=JBogux3Y6BlCUGp+uxoPLeKDN/2vWcnHxTSJAO2S6BhuJtStLhdA1WBKiJq1KhTWRjEnNN GeMy9ztC7lHNCJZ1tVeXBddDtr6MnMpBnCgkl2URmMXAM/EY+mnE1jtmuf0hS02aczGDEs fD7gBjwdNz7aPlTJpTkSakf20T+kejY= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736488996; a=rsa-sha256; cv=pass; b=h57ycwPK7VYdUQa1muYs+txXOFhRvEmUJbhySN3bjghf5rG/NUQKaP2/LxAizht7Gm6Mvc E+xXwAZFqigPYTXtut6mqKXxzLJfzboeAoyjjOYM75U+gxyI0boMZit66lnXjJaWR9qbQ3 5cmtquMY5kwKQ2TpdLU6CWcY6vYkFHE= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=IsiidAmI; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf14.hostedemail.com: domain of apopple@nvidia.com designates 40.107.93.73 as permitted sender) smtp.mailfrom=apopple@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=y18xpba6TdheYus1n6dVkhfLhglU0ONgqQfrNnYlwvcM1iWEj/cniKfFpTad7flRpDLUcq30Hsd59CTgLt4Vmse5OupzAK6cs5etd1ZhaIksgmSp56HkjitDP32ucuH5kNpCE2FLtSb/rFYSzGT8TJmqEAcOsXxL9F4UbKZj6/qIk/JPc2aqVL73Pw3t6IlmGtujxAwb9CIpTxRMyjevTT9fRGFXSg3g5NWK8MgzGdQIEkr2p6BgfHk1gY11yBQ7ACof4x/SyVIfTQ3TBU7aOnXH0wZsAM2qvSNUWYat5D2pQK8NUIZjwlN4O14kg9e9M5VmOMszUmlJrx05IEQGNg== 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=S8yLkD4vtMpOnXI+X3yg0lUvkaf1LGofKeKGauEzPB0QXGqP2QWt2j6/xUz0VnRzyyDFsIiNZROx20/CrZMbCao6bdHlqgAJ0d1ZjaDJT84t8t+qjCQwc6+ZIeQzxDlgpguFc80Hg4Y1ZxYvLdmOwIvpdBaIt3tX/AH78hQcXjxa3svWIwRPzaK88KO5BSfutof4Zo70z8pPQnYJFv2E9CKjJrj33lioZSWCjHsKI5WWEbikhkrSBRbyMTlNdEPJcPGdn22FxB+Xyv5IMVHnvAB3UT2v+P+UAFl3nr0oq7WyRJd0MhPWbOKnwJV9Sq5j4SgP4GIDi/xTrVLmNoWLUw== 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=IsiidAmIzGlV9snO1GXLGjypuf+oqJWB+BFtbvIArPqbaAqT2fLwHfVKq2Ig1dQbobsRTHmjdriH8IUp+rGczqP7e8fn7LahIN0xQ9x+TECGNCh4rw8uJrklRs0K2mkf8FrXdi/kd7tJBY/kgUSV3RPLIGJavVXxMUDhCVZP+TNaaL2+Pf75L74h8RD/cGCkgVr84YubI0PQyHWL7Zb3am+aTUvUcHbsU2DKxiLi3HAjFojkzOzCoIiTSnFOHYxDrVvJt3fCX8qUX7uG1RfOACiUBiPtBvmz33Bwg+EajglLyjda9egrJ7JCezhzgfKxJhQ0/s3jIrmZ/gpX55Olfg== Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by SA0PR12MB7002.namprd12.prod.outlook.com (2603:10b6:806:2c0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.13; Fri, 10 Jan 2025 06:03:13 +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:03:13 +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 22/26] device/dax: Properly refcount device dax pages when mapping Date: Fri, 10 Jan 2025 17:00:50 +1100 Message-ID: <7d5416ad49341207e5f3c48d5b9c4b7af5fd9ac6.1736488799.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY5PR01CA0122.ausprd01.prod.outlook.com (2603:10c6:10:246::19) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|SA0PR12MB7002:EE_ X-MS-Office365-Filtering-Correlation-Id: 22c062fe-c9b2-4741-fd88-08dd313c779f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: lycuOy11TiPN5jqDOEDgW2ZLjC+j/tz4q9oO/CHDpcFPf6x9+hlr96QvPDR7Hgpk/iHAtL7ndH8QlaZJIJSALkGVkJ8wkOKRtjWrHwqepusu54Q7blblvHF8ZGG7itogeynSdcbvP4yM+CfM2bfDiq3/9+ZRY6GZDY+hoZHIr8QWX+liiL4aI/OrtZ2rTM80JmixMjgohYEUNrOV3ueifkEAadMxEFcmuHoWMkv/H7+uhgcr6dET8aiz/x2325P/PUct4tKBSXdT1AOONlrHwZuxYk6Z2j1QvIPhNjpmLnS6kHGtaLoA0mQF0UpyfbsKwJpSCdTTC04OfbAbz5gNx5UAmb1k+1eJRl/uN/QJWzB0mxFpBKPcnz6lpAfltFIBUBeq7/b3ZLULO0b3BrLmUuH/kxc7ROx0w2Vc2/LWVHsUYs1jHxv2LtVWyDHd27bgrN5QVdnwDIG94tPN8758xeDmMMx/dPSZAIFpXXQDxNdHxc1n/tIwKLXRiM5Npdw+Llzd4FbBIXQ1MscEeVvdBhHU/AxDuC24hDNzCKLInASK06jcClGzeXlH/VWcta8GtXFPsTkArmRU13XX3TMVPRq+dZ2PHw1Ss0eVUJeeDZWGm4iV4sZx808CYh1zP4AFRtN/7mVZHBJwNrihCVl0TTVT5BQm5vnCXSNBGpYfEygrgD47ZxiG/fzgEZSdd1XBHAzGwiVOF9KTfrIL91us0UIT4CbGFnhGvUbEMly5v9VMAxCQubabV+sFzDnNKGtTFCPXvN/7SOBWoP5aHcDJ1Hkf+UHvV8lrgqfPrE1jBzLAMVWZaUM++IDe4jiqxfi2REK7n7ttMiOmSYfa9PnCaO0hRqHG4PPZjYGpouwnkMbyjHji1XC8Lqi+XxaBwZSJaAX9F37lkZeVfFSeXegmm6AGOsVDZpcy9Yufjnlqr8XUHuvOTTmk+XWBlR0Hg/EONaUWa++BUfqLlqaskOxJn+aizQzNDlVQUUVcLojCiWY9kpf3BToTBXZA3kBI5SvJTtwl4Rc5GLc8B6vQ0K8RC+eJyAyreUl+y26VoH+v5qpmJhRCObJYDp7QLIOPURo2JK+OIE73koW6Y/DyrvFUo0S/fih/9JYVTJHTluGwr+3TSFxUZ4YWThrS1SROGB2E5ULetKa90xrugeIMhPqd3Viqu2O+L/ZYOWQtaCFSYOB0+GV54Ce2V/jx5kGdli+Pa4j3ddehKdp/BgnRfWn/5BSFYFG6axg1E7ZRa0oXBU9LwucqaiZ8T4sbL1eSxh92ZCOJ+XWUzwd5OMl2UrYxti/eu9Vt7vj3tMSvDBaqxnHWBpPIOd45qWVnJTxZghhs5ZbgJMLUeMdWINZ2wLUce1pG/4NbI0xhR/a/mYqAe2hBuY+9LS3zxyDwDBzcQ5gD 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)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-Mess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BOIet9b/2rmVZVx8g093Vn07D4aC4chMZdR0Sj22a3hVQmnkGk8OWiZ5WPtZ1CY5neJvf8nbt6c9kRa3AjXwFp63b9bf5ollqzPmeVcHdo+8LBKWwYSvkG+ADIKy78c71L7P2yaC+JUFgUhUGYb7kqYlgyRdqUCqq7qZdxYyar0gJmZtaqf/Y+4qsGVs9WmF0Yp+DyKowmeACHjrJX68h5Dss9B7So/ld0tREXdb2hTzxLDo8+ijsYUNNXl9XqamYPikNwA2QOrAoMAUS2itnd1n+vJcAtM3aWTrtyi/j12PseGgu6KsTc/NFLgQmurrbnKvs5G5GetVOIFWhb+3LkIGGvxxlAOUmxUtlM1rIcLqEEpeFVamNQe5hd9idr53y/GmPjYE53OA4GRl9JkjYDE18XBn6/d0rCxM4XcmGi2up48ylEmBwuigLzFVc+h/vwWez7Gopd3qkyPtnfN9AKv2iVrWJSXB3OXCIBfkEZUy+7swWp5L979a9frHNNhPG1dWjSE5aio6QA73y1fgdyfsTJnBbaE3nXES7+t4EgxfOlRkguhK0A9eZT2a2I8 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22c062fe-c9b2-4741-fd88-08dd313c779f 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:03:13.2648 (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: 0RiJRIlixOpBkFWjby829rdmbUos9luBd8n9Gw3H6jW166Tlw9sazfjJVClIaR8CDWRrB8h/K/1IIilgvRqhaA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7002 X-Stat-Signature: pp3zehe7w1mawj6i4bfpy3ju4egg3ynh X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NhdVqneJYpK1eq1y9nZFt7Z9v9pqOvCtV8K+UTwWuT8FHWzKoJMS3ZbjhVqAqW2TxfHw1h6wpA3nti506s0B7J5m6L6mbz/NiOTD9YsfsW/PeVLLoequ2tIECW4uMkHsi4cibQqC01K21S/mi4eQS+JoOZJKBPOm8NdqCqytaQLoTv+D5dtrxHfmX0yFLfiKoMaEoJuKE9CSFhjO3IP6FOupKMBMFt50TTp1XlKPZ9J0z6ds/5fGYJ/NPmfvb46VpkF5sB7oEpTZRuq2D0R+Pe+ktFj98umt1ImJLJ0Lhn5MioQVS3xDA0hurDaEf1LdWBKXuuV82GRP/Xf5ZeJ3NDfb4H+Up0aDMVj7uNypqh4ezIywRhcyZgjUltk0g5Z9U5ue8wDSOE698pv/oMTRFxklDXhB4L/I7mtA5zx4VRRhtN31OaA3PoyADRtBkPJ5YnAnAshY6OE2cC4VGPg/Pa7IWPPmT2gO5r1U= 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;