From patchwork Thu Jun 27 00:54:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13713620 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2076.outbound.protection.outlook.com [40.107.95.76]) (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 1FFE7175AE for ; Thu, 27 Jun 2024 00:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719449695; cv=fail; b=Mw2d694auY7696ENPCZxQitTUvJulUSfZpM0ggJy5yRdhzUz4IyBZEkjCWSG2LkWEhsRbZsKC4kUP1tjNDtXqw4kB8tUV9sifOtKWe/lDmi3EeBV4HstD9/Z3tbcDl3iNo6SP9PnwlRCxsRmDiM1FWq59O5uOY8oSEH9s2MHDmg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719449695; c=relaxed/simple; bh=l1kdMpo3D/x90es9Igc7Xr7Mzkbpng9uBujf0ud8HNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=kDwo2ImGc6wDrTjV30iyNwLGwkM1Cqp3nXDCkS4gKvtrDiYhEKe7aOuLulw996s20by/Ui3lf2ZsHqvezAzDytr2hLKloOtP6HDNY1jDjeOyLeuCkVmhOsg6ZynH4XW5t4kQLg39TuCvbolRop64Cx7IsAGdA/tMVzWWXMvauJM= 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=MKbrl7oA; arc=fail smtp.client-ip=40.107.95.76 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="MKbrl7oA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ise+SBxARSC6WeEfZY+AMCfhueZMC14HH/5SWS6IEv82/YZhMu/2x9KC835gKUlFzL6lkKvtiTeeZ2ppsoUMBc4emMlKbU34RMFbkWQ6pZK/e61wLeZALeSJWEXgpUlPnLYZlx7fVaar16e0ahcXeimfW0g8iyql6iSJVuhBdRhXlb5ymFuMpfh6SeFapBd45+kCYxb6HVuoYoKJAtcCLNZfDekDO1A4m8MbrjstH/55/RVwLh+pa331j39uYq0sQtnncAYfHmlvMM4iDvGN7oRJky8dl9dMtdj6Z2bThExt/s3SS7R6HXeHsrdCr7WYIh2XDfPx1iS153SlESVn1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=hPINMew12P57zfDMgYtT5iZzwuOu+WVIYwPZgbZaNX4=; b=KnMUDCktLAUYRcVcN4FK1gWkMU8+c/6BCGeDNaIXUSrHCT8zdrgTy3TTX3kQdPaLONyqyANlH47NV9GxkTOMhy309ENEbAID37lIhGbjb3irQ23QzO8hK9ibBZx902a5IBKVXa4A88iruLzq1jGLiQz7qTSqeLaoBDlrQ/T2UXI8JInxGmo4qLZrNmFhDzlBMFgEQ1FUj3Yz6yQOO0q0Z7LIQLPfseewNoRak1UOeg9K28iFcywqXqAhFlVKIIVMV+h3bYLshS5p5BNjlLu7CNi29C60fOgfxB1uwAUUAruy1Goe+DURaAtzJtac0lxIwrcqun2lGXgZfVkrvWzPwA== 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=hPINMew12P57zfDMgYtT5iZzwuOu+WVIYwPZgbZaNX4=; b=MKbrl7oAuTukBefV/i0h5Lox/fZzcnZphErp6EzXGQU4P48O1JF5tNblAbRroMtoTf1jIBYwlCEy4XwG4AOD6XUDxsAHWNayrwoVMp4xqWWmtW9F6oKepxDwg6uaoynUumpU+WQJyOacwJsfjtqjQyv/MGLxYkjpNnafqbSwK31fUgKVxlwEfIWtCutpVAJT2m93jIipE6NghjyxZRJjMcOffb2PUuvf9RkrxrC4Is1jtHZB1gqKKdJ0G9SJ6W062ewo+ghzLdYAO48dqq8maoNdzsds1ZjdQ3rzgy3RC0fr4cL7mV7fae98WVENhJsvgHjj4Yadk32g/HH8nkmPdA== 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 MW6PR12MB7071.namprd12.prod.outlook.com (2603:10b6:303:238::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.32; Thu, 27 Jun 2024 00:54:45 +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.7698.025; Thu, 27 Jun 2024 00:54:45 +0000 From: Alistair Popple To: dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, logang@deltatee.com, bhelgaas@google.com, jack@suse.cz, jgg@ziepe.ca Cc: 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-mm@kvack.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, jhubbard@nvidia.com, hch@lst.de, david@fromorbit.com, Alistair Popple Subject: [PATCH 02/13] pci/p2pdma: Don't initialise page refcount to one Date: Thu, 27 Jun 2024 10:54:17 +1000 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-ClientProxiedBy: SY8P282CA0027.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:29b::25) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|MW6PR12MB7071:EE_ X-MS-Office365-Filtering-Correlation-Id: a088fd23-3d58-498c-b9df-08dc9643bc69 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: 2rnjoSObMFwM/09/5eFhgMLvM9L+tP1OpHzVCRUD+b//b3o+zAKbBR6M8Cxsi/1zpANC4vzOcld4Y1SwplXFQyZqGVqnnNzu1TQT94314P7IjxZATsYGrBUruBKy2pgcQXerLFwu+HmZz8jwgdCd3BL5n5p+k6z37SnB90gWWPY3yRof/eGDPXKVS2+BypI0F3XCl1MVJ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CpRNDTxtg2+SPJBayHbdv/Z+parbFb4tt4gKlRSZKsiebLtnmYCsKEOmZ1YzNuyx6dbck4aFmLZSupNoWBA== 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)(366016)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dNGSkOh98qimkmddEaJLkyU01T88pufhRnad9b1L0rEZjeNZgJXMlUkh4pu0ch8AuZa3p/r+dvy35NbnSws6NbpVwdl7FwXGiwpR4ZC+4NGdvyyCSlTcHPL2fW+cuK0ZeRyqIOtdHLBloIqKe9XuW0289A7M+xEBCt3S0OjkqvG4D7aSdtmIalekRZEfq+lSWmWRz0yAiqzQWMgfv49mOPVnMYAC1BM3oV4VrlxY9Y1GdVg72AkmcXdkMItTdsuKJ+wycVw+Hz5eFADAqzXh1ekvUEFuJKPp0YGvnadXlRmoloWy8pNF0KWequOgsZ8X1D3xyADmIjaJBMNrRA2yMMiD0AE5MWLbl8Z3x8UgMk0v+00gb0q5FyX4glLGrhN3Q2Z0ZoanFBT87COJ3kXi89161ntPR9+niLzR0EFwZSLYVNCuPnQ9CYsNylEMHhJkYJz4SznBCYi4TZItUS4CQrcr+NssYaeyrunipkU5OEGZrogXK1cBOzX01gpU8rTfhr4jKhDlq9CMRCbHTjj7dVj67OawfgSefnpEqHOQBQEAxiadrnyZ4YBOo8OWL/IjUKv26Qo1cCfG9R7SPw8suV9YqGidAeVv1tz8URy1Hjn8cXbbXRzth9gnUuXmbcsB0IrhVshplwwl+Oe/Bbvq+lK6WtTARUSBUuTgEbXK+98kvTn3BohIIa1PJremGGGi0Y9wxVoqqwRV2jbjF7eUAIhs71n4H9fKRgLXRDdUcNhPdg7I3wDp5Zizvv3DmaxnLcCANzuKtdCSIUMaKjEiyruZ7+G2CELx7cGGlUfVa+tN/EIg7uLTRzO9fsvJmaPK4yIc1iOGn78xdhEYMjbzGvjiSH3A0o+Bx7/vWJbhtHox771Lqqr7KoaU6+FQOt4W8QXpTIW0KqMXhm6KVShYoX4BIragyvORWAsmKyWe9OOxyP0S+ZECu54zDbP9TOhvOm/Mosm63VOn5kxbajEdPb+uzYZXRR9keolLJuPafvWJ8ddn3IdM1+tQ0hJL4YKZp7eHkT2DumqDIB4rsuQIo0+0sYAPzmSqObTXQyKv67bASkdLe++/wFMfbK4wzwCs5e6Ql8+r3F0jfgOo8wr4gC44WVtNvHuKD4BFRaS7+vKqGcjJIidm9to143/q53bCZAUP7A3Ihj52A9UNx/OhKNfs5k8VoYmQPd3htfDhRv34QO0TkG7YcLdbh/T31SRuSjR7rz+cSbQRz2+Onpk5i12LQ5dcRGp8gKreipLyByuK2GT9vONNUKCZj1q+CAtprWyhFbfnN//g9sxrTwemlj1mOBYxP+LuJzI14nCpE/QjqYZtkHrhiEvp8fAtcA46VSQxlXCJzHgrtZ9E3L/fM2LA67hcdBHErPy/6ccAXuZWMRJFjvBAPJHbOawWAHl4FJtofKE0kwmAGaNYit1ecXwHndyFj7avsK3pvKbcIjlzb/BFJF13aD8L3O1eiJ+SLWFQodweT2l96gKBTdkb4kzODF0J+V4XZm2cng1VSscvl56QTyKSeJxAzbuu7jN2uoW3Gz0k1BhAcAOsOL52AoClBqCRj4rjK4TtnMBjNJv+MQuxVC0pVqKBDJGwdDIE X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a088fd23-3d58-498c-b9df-08dc9643bc69 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2024 00:54:45.0710 (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: kQwjgjMduH9IypZxLKV8hTKTor7kJVJeIzIw5djaLarYMfmJzrqPzmexitrN5JA/pccHPBErrEpxegO3X/nq+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB7071 The reference counts for ZONE_DEVICE private pages should be initialised by the driver when the page is actually allocated by the driver allocator, not when they are first created. This is currently the case for MEMORY_DEVICE_PRIVATE and MEMORY_DEVICE_COHERENT pages but not MEMORY_DEVICE_PCI_P2PDMA pages so fix that up. Signed-off-by: Alistair Popple --- drivers/pci/p2pdma.c | 2 ++ mm/memremap.c | 8 ++++---- mm/mm_init.c | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 4f47a13..1e9ea32 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -128,6 +128,8 @@ static int p2pmem_alloc_mmap(struct file *filp, struct kobject *kobj, goto out; } + set_page_count(virt_to_page(kaddr), 1); + /* * vm_insert_page() can sleep, so a reference is taken to mapping * such that rcu_read_unlock() can be done before inserting the diff --git a/mm/memremap.c b/mm/memremap.c index 40d4547..caccbd8 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -488,15 +488,15 @@ void free_zone_device_folio(struct folio *folio) folio->mapping = NULL; folio->page.pgmap->ops->page_free(folio_page(folio, 0)); - if (folio->page.pgmap->type != MEMORY_DEVICE_PRIVATE && - folio->page.pgmap->type != MEMORY_DEVICE_COHERENT) + if (folio->page.pgmap->type == MEMORY_DEVICE_PRIVATE || + folio->page.pgmap->type == MEMORY_DEVICE_COHERENT) + put_dev_pagemap(folio->page.pgmap); + else if (folio->page.pgmap->type != MEMORY_DEVICE_PCI_P2PDMA) /* * Reset the refcount to 1 to prepare for handing out the page * again. */ folio_set_count(folio, 1); - else - put_dev_pagemap(folio->page.pgmap); } void zone_device_page_init(struct page *page) diff --git a/mm/mm_init.c b/mm/mm_init.c index 3ec0493..b7e1599 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -6,6 +6,7 @@ * Author Mel Gorman * */ +#include "linux/memremap.h" #include #include #include @@ -1014,7 +1015,8 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, * which will set the page count to 1 when allocating the page. */ if (pgmap->type == MEMORY_DEVICE_PRIVATE || - pgmap->type == MEMORY_DEVICE_COHERENT) + pgmap->type == MEMORY_DEVICE_COHERENT || + pgmap->type == MEMORY_DEVICE_PCI_P2PDMA) set_page_count(page, 0); }