From patchwork Tue Sep 10 04:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797874 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2055.outbound.protection.outlook.com [40.107.236.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1ACEC19067C; Tue, 10 Sep 2024 04:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941746; cv=fail; b=P+wkXG0C2vtXTI6fLGn+hgoSGeGNJSoS3TYTclAtheaTswxhEYREVhSNQL7cdMoWi1qjos7B6yXw2XE4zIeulgzMFLFIdTJNfMl34SNsWnItIR21bAP5sziA+BQ11gve79VvzjTyu5IGLeqvq1JL8enQAM0sQk/rktS7kiKsyyU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941746; c=relaxed/simple; bh=8W044OLZm3ALC5/sg3Oqz8bwVK13cS+oWh1yt743ByE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=OYn/3QTdIEn9JMDvrBIVZ8m0J8LrZ2uQTV5czvB8cYDSFdzQD7nvFOFCwt4HAL6V+0Gbr3IcFAb8o59HJWR0w0NVXx/RQSDRlrOsaTtxlPdA3VkVaKTfkVvD/l8NvZGIlm3f3CqNOOsitMcBBe/f+fJ38TpC1q6U9ZmLZemtawY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ZPk/crcO; arc=fail smtp.client-ip=40.107.236.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ZPk/crcO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MXI1xaJfqIvkKMabg2YvEFD9cegZN5DLWoR441UhNNXEggfAWCdNCtDWo8gTOcwr44m+CnFKbE2wREg4XUaoR7lwjUKM8KI7NKUjj/7pOwGYTdeYGIxxhyWv5bdH2cpR8VmB+kS/DS/9G+HWOZv64OD3H0afFZRWGpyPRV/DGoVA4cpHIZyUojwwwdorxzshb34W0Gb7DSnNAIRIEdJqWTPcwL/N71V3RiB9GRipWMODrLi8zwZwmlXJfXfLdMUVpA6wqT56aVp2jWko3R+lOKwU1EQIVqQ6Q9HJLAljWG6MYOj3z0E84ErWs3SD/uRQ85VNS+ZT50NTP4Aybdo72g== 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=oV3RuJwb+sRS9SntpWvyzIKrNy8Tuttg1UxdDOww1Ro=; b=LWc7Dn0S4HZl5pPJOTpM8oSGiMvpw7toO0C2Pzj1IGwi4uEbTTDezhLZY7e/7flsVepnvugBKhly8HCiHyadh1SbVlw7DnsSlcf3FXTqfjEtOSbdz4SABmsK0O42YKOGb1rkBEz8oL48xzQGCBBm1my3RCz+XqEbEZH3P7NGCgUE866Ifr2Tchl2qnQ7NZZ3U0oqKfxlfgtnLyFR3Lz/vCmCtAA1ljMGe/Jwlw/FvosnnR0k/GMcl1P6GdRxhIBeucA6ZGN7OjZErLpxrnhdM6IjcMH5c/+t/ajyUQqGF1OpiCRPJIYLLVRtnPRa4PROnCRhdzUAO47ZtmdhckjkdQ== 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=oV3RuJwb+sRS9SntpWvyzIKrNy8Tuttg1UxdDOww1Ro=; b=ZPk/crcOCvT2mHOf3/9FCx7Fam/l0kGA4CPjvFozGz48KeLxkrnScEokFEpQFwoU0mCy6SSQqiZ2lVdF8T25SGJ1cie/kywHjq49PDfBlBxLgvMbRlyM5XDPqaAFUaSQbYvxIMOS9aIokksEl3+LAMJrVe/iBgIwaSCiiX1235+rC0IogacgX6U6S2L61w+1SC6vSa2Q4FnvSPdHLoz2WnZ+m9rnXruIvvvNHcBJRGISPFr5m23zdBnq1xAFrXdKHj6tTDuW/VGmLyrbF5lgbD0kSB77AJLvnbccz1c6qtAmtvE9zMoFyV+UkLEdmeTCbJN0MHYEdw/4ttnSSvzQhA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by IA0PR12MB8088.namprd12.prod.outlook.com (2603:10b6:208:409::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Tue, 10 Sep 2024 04:15:41 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%3]) with mapi id 15.20.7918.024; Tue, 10 Sep 2024 04:15:41 +0000 From: Alistair Popple To: dan.j.williams@intel.com, linux-mm@kvack.org Cc: Alistair Popple , 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 09/12] mm: Update vm_normal_page() callers to accept FS DAX pages Date: Tue, 10 Sep 2024 14:14:34 +1000 Message-ID: <64f1664980bed3da01b771afdfc4056825b61277.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-ClientProxiedBy: SY5PR01CA0005.ausprd01.prod.outlook.com (2603:10c6:10:1fa::13) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|IA0PR12MB8088:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d96d962-ecac-4a36-9c2f-08dcd14f3bbb 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: p0/XSu+j6RC4amQIub1I+NvbR/EvWujIS4R49iplf0dgWgY29I8KiQVttazJoBkrxoGLPyml53b6bJ1gqCMw0FlE77JVFw5g+qhWlK7s9OG6K9uFI8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RSR3T0kg5vThwHBk9uRnoDj0TrN4DyogtS6UYH4HPLeg4nalq4V1/p9hnjGF76ip3gSaqhPAeICgKIMTLFtMOMJMx7LbzpfmGUrd8riPT7vfa9R0Wj/3ZfPkMKhada/C2lFLb+imdLwoKTha62TGzKxvtDLcU3VyZxznCg/vTlrFfA== 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: /pHOMGGcH0XJuO5Wsr+OtYTbWqAxzCvfpUql0taa19y8j8xA43gaFKaZf+jig6m7IA+g89wyglmxqBnQJDWfvrJUnbxJSTCuTm95nlhkTDk5XpntEnPtgpBRAhoJXf9uQXsj6HZ8Jogl5pnI6pvhB0NiBjk5NXSpCu3OgUTEaYlEdVFhkJYteGmP8E8gL55Le5JhNEzRaJfhMYjgSYEKLFN7h7CCAYcp/AiYUSgtL59Nt9cX246SglUrDpTSIc/aI7rU9gOZ67NeCL3GGW3uQyKFWOk7huxyItY54ggf7/k4mRx+O0h953do6vnWbKjsLAoTAGwNkssJp9STNWyt8Z2wt8n+Q441PfzaruBttfHuzEvMiSsZPt7Qo0c2Zy2W4let81cKof+p9OJ+7xnnXMlnESgdg5I8Inu7t412PnOyfjp+BchXSoAD2Bgt1RybN+IFBoEl+ia9D68JOSxl8P0/rrXK9kQXk/Bwy813soeC+/MA+D4hkSieowEb+exoq0iWQyQMwplurYOXy1rlsLWX4jvWAx3jRs31QQr2pNE9YVGoF5ZL298JDJmdr1qG15ODoVQqVPTymc9DIMePtsRr53YuqZXk0CQtJCk7qsD+dK4QSjXSZ88/G10Lzk/2CaJIK87mo5f33PRlpp4bEMFBv2BVYLK51tQ2KNdoeED9PfDC0ZKqTGIQPcTnq9fnsqsyHpPCtO+nsp/WrnhjqP6od1NatHdYjbO7v36YUkWfIovyKVJsakK9blPhcXjBbWgy++W33bCMbSNJzaAA3uWTJe37OASyR9KJLZMopaYZLi2nJwFY3xrklQDKIIEaGgwVCPIWrntPPzJodAHdKOwrX0XMzOBNAIHBi3WxNgu/TdY+McwVE17gCOdzLKyxqP2f574B2kcsvoJC+J1bl5QPVupcNwvAUbNfBuNUt7b3OM2YTrigyFnjaIXOHCRejfPySagz/9eTdKo1NCu6EoSA3NcKQdMBNZPI4zA60LHxAV9jaNbWAvXRL/wpr1iKv4JF/clcFT3k4tpuCbT3tKBch7d9S8KKzfDIwslM+R6IpB9jnvZVQkc8Cz6A4qJ2Msm5HEpOd3sAwbxq34RNdgxu9P/f3ereyKbuae9tY574IPnawrXBjNpo7szcktxcB8bRqc8A2BmLLlR0zLCDqb+NPQz56HBdV67t9pbIAwM/io99O1EGSpI1WjgrJGQj/VuF/oSJGtK8fbXvHM/I50Hl3oKznkgMRuLveMKHfqV6h+5ufOjfzMRNVx/GGPx8VtKqn1IbtkDWQLO9ZPpRdl4IeiVUDSc/ia7WBej4+nVjXisUirGGZ7ZW9LbcbUAbHdNyM9aG31uFr703dJjBGC684kgdqtoR22K1M7Bd6MMhZdItKa8872K/D4yNmhlGE2EeDdGENxbju4v89F6FI+R2IRQ69L8KxuJfNUnFy55NKB1qnf1odz2cl782kN3JiNYleo3vI3247kWlSsT7QfyhhQjfdZh9IXisJiLfrhptVkMVwG6efpJzqvA98qcZBDGi6DY8+orzhAQyFSRd+esa5qbvBz7IVOYLLF0L6rt6nIM499dTW22cOyceY54b X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d96d962-ecac-4a36-9c2f-08dcd14f3bbb X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 04:15:41.7306 (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: V3dOcpNl6wWF+ecILF5shF8I1HGH/hLFOmqxI6ecYfW7ol7oG/75AmXfONWBAJ8yFnIrCYz7s1BGRbcYbH/GFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8088 Currently if a PTE points to a FS DAX page vm_normal_page() will return NULL as these have their own special refcounting scheme. A future change will allow FS DAX pages to be refcounted the same as any other normal page. Therefore vm_normal_page() will start returning FS DAX pages. To avoid any change in behaviour callers that don't expect FS DAX pages will need to explicitly check for this. As vm_normal_page() can already return ZONE_DEVICE pages most callers already include a check for any ZONE_DEVICE page. However some callers don't, so add explicit checks where required. Signed-off-by: Alistair Popple --- arch/x86/mm/pat/memtype.c | 4 +++- fs/proc/task_mmu.c | 16 ++++++++++++---- mm/memcontrol-v1.c | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 1fa0bf6..eb84593 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -951,6 +951,7 @@ static void free_pfn_range(u64 paddr, unsigned long size) static int follow_phys(struct vm_area_struct *vma, unsigned long *prot, resource_size_t *phys) { + struct folio *folio; pte_t *ptep, pte; spinlock_t *ptl; @@ -960,7 +961,8 @@ static int follow_phys(struct vm_area_struct *vma, unsigned long *prot, pte = ptep_get(ptep); /* Never return PFNs of anon folios in COW mappings. */ - if (vm_normal_folio(vma, vma->vm_start, pte)) { + folio = vm_normal_folio(vma, vma->vm_start, pte); + if (folio || (folio && !folio_is_device_dax(folio))) { pte_unmap_unlock(ptep, ptl); return -EINVAL; } diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 5f171ad..456b010 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -816,6 +816,8 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, if (pte_present(ptent)) { page = vm_normal_page(vma, addr, ptent); + if (page && is_device_dax_page(page)) + page = NULL; young = pte_young(ptent); dirty = pte_dirty(ptent); present = true; @@ -864,6 +866,8 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, if (pmd_present(*pmd)) { page = vm_normal_page_pmd(vma, addr, *pmd); + if (page && is_device_dax_page(page)) + page = NULL; present = true; } else if (unlikely(thp_migration_supported() && is_swap_pmd(*pmd))) { swp_entry_t entry = pmd_to_swp_entry(*pmd); @@ -1385,7 +1389,7 @@ static inline bool pte_is_pinned(struct vm_area_struct *vma, unsigned long addr, if (likely(!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))) return false; folio = vm_normal_folio(vma, addr, pte); - if (!folio) + if (!folio || folio_is_device_dax(folio)) return false; return folio_maybe_dma_pinned(folio); } @@ -1710,6 +1714,8 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, frame = pte_pfn(pte); flags |= PM_PRESENT; page = vm_normal_page(vma, addr, pte); + if (page && is_device_dax_page(page)) + page = NULL; if (pte_soft_dirty(pte)) flags |= PM_SOFT_DIRTY; if (pte_uffd_wp(pte)) @@ -2096,7 +2102,8 @@ static unsigned long pagemap_page_category(struct pagemap_scan_private *p, if (p->masks_of_interest & PAGE_IS_FILE) { page = vm_normal_page(vma, addr, pte); - if (page && !PageAnon(page)) + if (page && !PageAnon(page) && + !is_device_dax_page(page)) categories |= PAGE_IS_FILE; } @@ -2158,7 +2165,8 @@ static unsigned long pagemap_thp_category(struct pagemap_scan_private *p, if (p->masks_of_interest & PAGE_IS_FILE) { page = vm_normal_page_pmd(vma, addr, pmd); - if (page && !PageAnon(page)) + if (page && !PageAnon(page) && + !is_device_dax_page(page)) categories |= PAGE_IS_FILE; } @@ -2919,7 +2927,7 @@ static struct page *can_gather_numa_stats_pmd(pmd_t pmd, return NULL; page = vm_normal_page_pmd(vma, addr, pmd); - if (!page) + if (!page || is_device_dax_page(page)) return NULL; if (PageReserved(page)) diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index b37c0d8..e16053c 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -667,7 +667,7 @@ static struct page *mc_handle_present_pte(struct vm_area_struct *vma, { struct page *page = vm_normal_page(vma, addr, ptent); - if (!page) + if (!page || is_device_dax_page(page)) return NULL; if (PageAnon(page)) { if (!(mc.flags & MOVE_ANON))