From nobody Sat Nov 30 10:49:42 2024 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2060.outbound.protection.outlook.com [40.107.243.60]) (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 8C33D171671; Tue, 10 Sep 2024 04:15:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941703; cv=fail; b=CRidpi5+gf3Eg7JEjXZj/4fI5YA8s/DZFTsnrLxm7vUc+2LNq9QP345LB+yGZfMlOhRti6NO9vXIywOAIAkxN4whHxjI3J9upup7Lp/1+ynModsDG/fw7uYJSsUq1AdeEm2IPzQi3RClJd6EpEOXILA+jJqdTGteDA6ktVuIaLs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941703; c=relaxed/simple; bh=2Mq2sCRCjDKlrt0F8DN7YL3yaumqrdvH+VwCU4xgnOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=nNh67tvrsQwiLGqzIROus8jGgQDKbjkpPRyIzpLxCKs3L/QvA2bbFs0UZJNZijngyk8bK+vR+I04aIf8IjI0JbBPb9Zb34vDv/Jdd4vgD9bLqiKyEtQ4nm699HHBMwq269L12wdksvIE/zFFPsPtwaRp8MTuYYR5TW3jYOGaYpw= 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=oGVL3Kqb; arc=fail smtp.client-ip=40.107.243.60 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="oGVL3Kqb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fuushkQwVp05ZUC4gx8qBrAfQcAIY2nnbm+YwJX+qCHjWucVD+PsYRki7T5+sDqRYtZT2pHmZfMsjETMPp85TuB7nZrGKH//RZSuUmTdHwCXGRaEq3aqPjlRwFCRJiPmc+x+rcpkiEYbez4knyaSzb2+i4qXydEIbImNDI6YE7dkBgTC4a+X867mAqdVbVHO4Spp+rYCcHMgQlpWvO3bP+5jGu1ahWpZrAB8B0CSIHpSfEYNPQcDTS+lD1LsOn+1DeoNwTAZfeTqiqkC0uDJSIzLuOKz2nc9tic1NRWJueMkDlxVE8cp4vuonKoG7CDpp3NXtA4ALcJETr9opj3/wA== 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=zDZIA7b0Q/wBPCoHsWPFK3DDgXsBN4K7sD82TYiK/gQ=; b=YYqo6yl5YRXnWhAJFNQMW1fBl0zmFcOXYiKhPKOmyR971J9ywiJO9Euao1+S6cUZ9g8nJbrej9HDK+oVMQkUNnUFNVI2oTfxtZ01xdccv7v36ufs2mNJADPIXLr2lUQj8lhIXzYvDZdQxURy7Lr0Y3IuTo8U0bCZ6x1eniBtRdhM3GqhO51zCD1etI6WUZUc4c6SKZgzy0yAq452u5xBU8foDOdCw58wt6xhNCuQ31+i/flcjicO0U1RRYtYMEsepvr9HaEuDaLYQzJkmoMa7fMCTxkqrnBQhGkRlOUxXcVwNW4C3/csjyjunM3Ip03KWeWEIjXjRMfgA89A5a72Nw== 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=zDZIA7b0Q/wBPCoHsWPFK3DDgXsBN4K7sD82TYiK/gQ=; b=oGVL3KqbHRBzkHqAagqE2MDwSCwPp9ojvkwOzdxRFdPoBnxE5p33/RnAxEsLe1HdkVraPG4q7Pe0GlfwgH6ouvCYRdaIh4tUEcFGEsaLH9Mm4HepFkHqp4m4uxi/4uaZJkrhGk584wRSnR9uwi4GYKL1BkvjY60N6KEBw5gmfWd+bG6LOez3roNcMqo726eervczdgRcD8eaLUzWBUB2IoAqaGrgBYF1/Dr0586ZDfYtTaYAi/iMnsDqF1HDO8IEib8PzigBQg/3Zbgv5PPC4Fh85ujAZqB0wsUZp1BrpkbjVTyXjEQUTjJrt/TYkL521kpmQkFOExd8yBiAz+v/pA== 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 BY5PR12MB4148.namprd12.prod.outlook.com (2603:10b6:a03:208::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.20; Tue, 10 Sep 2024 04:14:58 +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:14:58 +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, Jason Gunthorpe Subject: [PATCH 01/12] mm/gup.c: Remove redundant check for PCI P2PDMA page Date: Tue, 10 Sep 2024 14:14:26 +1000 Message-ID: <2ebba7a606ef78084d6c8869dc18580c56de810f.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SY6PR01CA0052.ausprd01.prod.outlook.com (2603:10c6:10:e9::21) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4148:EE_ X-MS-Office365-Filtering-Correlation-Id: fe089c1d-9434-4029-bdbb-08dcd14f21f0 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: =?us-ascii?Q?N691mV30cr5XvSOYTZoHp7GOUkaNqYT2MHhBHrOYzgj/3b+/pZo+CbLkpH2c?= =?us-ascii?Q?diRcw/UCnlRv68SVYV/EenIi5cdiL7IcjVw9YNxdULQ7KUK0VC6tem1Y1emT?= =?us-ascii?Q?KrvLAB8tdDwIMAJv1ShwGCZQFKPrmNuzjq30JGXfeIs2oC+nCqJTRwxQtm23?= =?us-ascii?Q?741tAMS7bjgnluNjmwdxHB+vv3DzRm2PK2MSssBIIVFMlEJDiB5IO24EZdvT?= =?us-ascii?Q?8Ry48VranA2cbjLkggDRTfwWF8SjA4sWeHDUr26HlANbUM1ttN6ZA8O79170?= =?us-ascii?Q?6xtyl880H5LY7olt58/DuOSEX78CYTYZlZg6REGYb2MGO20WPE/ZIjB/ZU2k?= =?us-ascii?Q?RsuCfxb1da+3WY1f7NYTCfajQeQek+wWVIolmtnhIbvQcNvZnwEpMVbLRP+O?= =?us-ascii?Q?k6WemDLIqnSujFeme7ywBpkgNzk09EBclgTFiAOrQBSNZ4x83qcHjW8iQ4Uu?= =?us-ascii?Q?9VeYrI8khwmsidnKNqO290CZLbCDcx2zUKtYBmAhGoKMLxN0ts1X6uebCmvi?= =?us-ascii?Q?7Z8A06sOkePHCn4nN/GY8Cb9mB3/kEDtFaMZjRDQUbtUrrkF9B6zAJwSzZG7?= =?us-ascii?Q?zKlcAsZI9gzJ0++pv72tMsdFNcDVQ33W06vRqwHKWTtofQ6M61J9TRWORJa2?= =?us-ascii?Q?bOHtVkZm87XAGrGACXY8NXdspZiSkoS88OCAJZUQv8w8xx6YN2AAe8K63/ze?= =?us-ascii?Q?5QPLVoPpNsUaaXkZqSkmHOrRgLQHrjPji/1KfuxDsmsPeoGgdSNF++hhMfHB?= =?us-ascii?Q?RXRC0xp2jVpGhXbgVTf9RoPY1ONbgI6k1XHJ91wDzAtIdUUgCahotoltHfh9?= =?us-ascii?Q?l8XZAtTrs8NRuOWqTuGysM8Tere/FGDV6Z4uszwWwX2Uwxa6F+WVskLpu9hc?= =?us-ascii?Q?I9NH95/3y6pPNJk/GVNFvQKOWqhgXkrJXuJtfy9CwwzqDlpzTqjCIeH3714V?= =?us-ascii?Q?m04aF9n5GPSugSGrnM57oKf8XDeDnamAemvu6vYeCQruWNHU9IjfGV0AOpxa?= =?us-ascii?Q?1XTJqQ9fcsK8c8K7w0FqHciL7saDezhV3t1UDHo4e8TkjFe7KfPCuSrKgGuC?= =?us-ascii?Q?37/jY4+5QFA5fTIQOpUUm5wF9S1RNHZFXkb8yhLXDBBzjtJe26ARKj5bwHUF?= =?us-ascii?Q?bEyzA6IpKSjoe5r8KDujmzgpYNOqVS1vXmglDF7nRxfrMEFLMqyzUHeiM/cJ?= =?us-ascii?Q?FLYaBoEJezyd79ucLJLswDag4E77jn1ZwkWcrji5KzxiLSFOjLNBPoO2EGMt?= =?us-ascii?Q?RJSeeM91/OuHvXd6SRKsyLEpHt8Nx1V4cdIl9uX18O6lIhZCman+YEXCFPJe?= =?us-ascii?Q?r2KaVSvMHWxC+1yDWVOR5Uw1Y2UGkycwFvVBtIuZ5TH4SA=3D=3D?= 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: =?us-ascii?Q?iPLav8Pmg9cmH7rrfcIvbv7YDogC3zthIrBQyT3eVcVGlJkRDzDLPsFy41Kw?= =?us-ascii?Q?VWGDhZid8mbHYKZolIliprSqVo7fSFfhipS9k6+Q9scrRi8+9+e6YkCR+V0t?= =?us-ascii?Q?dA5hatrDfk264sTpNeQz8Kpt7F8vImKsuly+z8ExKhZfvMiA5KZKD6tIYg8k?= =?us-ascii?Q?7DlnCl6na4VXFtU7IdyJl1pRCrgVBWdns7AhoBSVY7+w3b4t5e0T3+bp1X7H?= =?us-ascii?Q?e44NC0prVv+BuUx0gaAcIlIgZyaVt55R6tZMwTwByk/iFnYs04VYY6T+mMW/?= =?us-ascii?Q?F2OCD0Dlj/8kzdN+OHQK7EdhOvYV8oyVKuIV9oxAO5kkYokgV/JIr7qzqs4n?= =?us-ascii?Q?7mzgwog3fP15Hip/I5edLFoMK2A3IqixsyxCfs4s8F+Q+P4YtCdqdbswh02J?= =?us-ascii?Q?mI0ijcZnb2QH4paPHYDkfqpkLUfYQvSVYxTsUnUecdGfl3QanQef5/QYRcIn?= =?us-ascii?Q?CbpJAspwM/y9TW6pzToxOGVGGtOc/Gz6SiA8auUdtQjfoocToa6SoRJ+N/W+?= =?us-ascii?Q?RDp4v4ucECma7NqrNTW+m/kCOvnExs5NzC0QbE8SaXWKc+9OnvhxsZpfB1bN?= =?us-ascii?Q?STuXfxANB5eeRBwe94bVwUs7eoC5HouwloUi7cV5x4vfuO/bhClhfVHPpHul?= =?us-ascii?Q?mY2W1JFghLg/dobKG4tIMyTwz04kxePyWbuFhFwlBPXguEq7P8h4DHfjHMdg?= =?us-ascii?Q?tfaVzr4X7tql87HvurkhHhCM7jZCoAj/Msr/JlfJuRvV+/wErxfbxU07FXXQ?= =?us-ascii?Q?UYWNUEDuk39XIWjmw/q4cOo9hFLZ7ZOezUd3+Mh7JiljZwFDo6WBNgKeqdJX?= =?us-ascii?Q?wg9459SID/vFQSiZpw6E3K7HNKyF9nnQ3cra8bIFNS5dPZUSuSjeMrinWm0/?= =?us-ascii?Q?GV8OeqDcCdcIDY9qm+EyanFhGUmODftcCcF56P1t0GI/IAlLtVY7ik34qlQD?= =?us-ascii?Q?nINGzn7yaIYycmtjmToB9IFxyTMfPddWZ5tHeE9IPDwAGLKyqItBXa24xlMM?= =?us-ascii?Q?RLmgId0vQ0njPkQziiqIDFx+J5k/XBsp+jQvnapaehxddUyAqQ821ufY1B5h?= =?us-ascii?Q?yf2bhpWsiVfzkccMf6qG4UOzE/C/D9dS+gjr0oEyEbnQRNCLvRm+JJmzDu0l?= =?us-ascii?Q?6rPJMxzaT942j1l0zGhHsCuzn7ghurl2tqY0vYGZdSrvZJkGqksBeqBo/YaG?= =?us-ascii?Q?LFCe+MyBd0xsrSV3ZCCVTBFlfKKIuktMq3anmn2jJNSK8eVr+iPPwwuA4xE/?= =?us-ascii?Q?wgf0AAVncKfqXMOwfS47NqCzxDiY3eSI6Glrz/sxe6eF+w9k71hJQSItgwPH?= =?us-ascii?Q?g5JC3FfszV8ulYOkq7RTuWqMe6X75KpHEBEiBkmDgoOvvJm5E5Lh0smxRjeR?= =?us-ascii?Q?1KWdTkSwPXU7yhTjG5k5R8voWLuKCA5J0Xm/MdO3MzJy56MYrVSA/fqk2BcN?= =?us-ascii?Q?YEj/6IHGVJHFQjPvxQKLWqA0nn2y3zsseXEyVMBkz4LPHDRMzE35X9oG89qp?= =?us-ascii?Q?TiCC5+ZCbB6gurppWEnBw0aXGBp64g9eSg2MEFlSeMcQuLWAQFxOwgRnOu+q?= =?us-ascii?Q?SPRSP5Dzzg3IsxTPgP4DCS8vz3VFt0hhfBK0tfxc?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe089c1d-9434-4029-bdbb-08dcd14f21f0 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:14:58.3094 (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: loSBcQCmmp0Q5iqu6vRQ+5oaZmLPN0iHid/T1Xax2S7M7u9o2eR9Rf3+c93OJjDjfYHBA791sy3gRPGMNCX95Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4148 Content-Type: text/plain; charset="utf-8" PCI P2PDMA pages are not mapped with pXX_devmap PTEs therefore the check in __gup_device_huge() is redundant. Remove it Signed-off-by: Alistair Popple Reviewed-by: Jason Gunthorpe Acked-by: David Hildenbrand Reviewed-by: Dan Wiliams --- mm/gup.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index d19884e..5d2fc9a 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2954,11 +2954,6 @@ static int gup_fast_devmap_leaf(unsigned long pfn, u= nsigned long addr, break; } =20 - if (!(flags & FOLL_PCI_P2PDMA) && is_pci_p2pdma_page(page)) { - gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); - break; - } - folio =3D try_grab_folio_fast(page, 1, flags); if (!folio) { gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2068.outbound.protection.outlook.com [40.107.244.68]) (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 302511CF8B; Tue, 10 Sep 2024 04:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941707; cv=fail; b=PTj/3XTErePlaSCQCxH20vREfEHZj01YHEZhHvnkjpRcNKH0l11RSYa+wQEXvYDin7hY2JvyGw7VUPUoOhkO0lMrhnC8gclN8cqdNCTGi0rRMn6Ug3kUEKsPgKojlszMjnGb7Yew3yUbyHg3aPaf9aIMGnsyZhDvgE4InjpFZ0Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941707; c=relaxed/simple; bh=1L188h5KNYXplwSFYcPgGWpL+VSrYrlpu4RDCuSQ8Wk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=TalZWc8RDAvKkE20YbP4dxbi5T9PjkkEtwthi8q8rc+mAz1E6TqseXA6HhA/dglfOeFAvpmpJvqkwjQHXBmoDkwIplZ0ntwjSOvC0/z7oqby40ljqWMNehH93c76jQh7ELBYY0rD+9sDy2MVjWT1n1/m17A7Hsc9TsN3Dc/wfkE= 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=Ku25m3X1; arc=fail smtp.client-ip=40.107.244.68 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="Ku25m3X1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ArSmaWpHAulgDCZjUdNPuelA/ds21d9j4hfrtzjVXK+O2KN319rltk1qCiysCSIzkJdXv1XxhYXY0AxT6VlGqssmhw173wnUs/3hq3Ojk7WLft8Thqyc4oJSVqV4JPrmphcXUQ1hduslvedMw6zt8snxlhaXweTivCTF9DNm+1T9FqlRtX0ZjSyC77nAMKtCmNwDS/OKkg4awe3LgJROC0CE+PxW1jcjL+6fj64qdlfD6vwYupGO6Cg27WbskzmWJit9kzgRq5LNjXJeGqbvDZjKtVAUlwc5TTO4wiFM4K3YNoTzrea8P8ff4H+kplAQevs+RZtUlCcOH1Ixz2C9nQ== 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=z7bMoyH61WQOj/0djBXDddV4SIhrpx8WF80k0zij8WY=; b=fBuALuApHA8JN6fbNLpT23LLv0C7P6HfnDHVh+zLajtsZb1BafYgcW/DxqUjifSzviLIvRKoINAQ+oChk3UgufjBAieGRsIdlZ4ll64uPmua2xvf5lE4XmU7nzQ4HPC7iqdRe6tYSaWzzfBRMubHMwc55BWu+cTImCoGfoGFsITvg5awYZ/7a07NZ2Aypwdau0Re8DxijPUSJN2jzh7/Lkg3ycTbXEBHO9pcqy8YM57NWGZ1TEoULnkvG4qLx9NvCaj5YoEgaXJH1JFPBY3+j7hxr9mu79Uqou9dju2CepL8y+HXLqMREX4CnpC8Und67S+flgvz2TxBTsxsLNerXg== 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=z7bMoyH61WQOj/0djBXDddV4SIhrpx8WF80k0zij8WY=; b=Ku25m3X1x8jKR7c7d+vvrZw4VQX5zTwItTSW3kl54eFZilW8v2UQCxttZOwy76HExDW0PWu+zPoQXw/6VTWuYOvv+zpnP3PBNOU8NdR9UcqsQQPwUh7JXW2wHFD4kI08XyJ20yctA3loR5w1SekHUTc+PMKmz47nPo9gJvBYJXb7EY49HTK4NBopb8oeIC9UmjN0leBMYPbzd/PnOK2QCXsz0SvKKo2yCuDV1hGfO7CO8W7wQN5xzZTStFbtOUtkGcXAUBtLyxLgFJkLXJvDrAw2bbFp9ojMHpjjzLDd7VfRqi79XsqYOk7R4m3cpmzBHRcQcIesGKkLjo42TkbayQ== 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 BY5PR12MB4148.namprd12.prod.outlook.com (2603:10b6:a03:208::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.20; Tue, 10 Sep 2024 04:15:03 +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:03 +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 02/12] pci/p2pdma: Don't initialise page refcount to one Date: Tue, 10 Sep 2024 14:14:27 +1000 Message-ID: <4f8326d9d9e81f1cb893c2bd6f17878b138cf93d.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SY5P282CA0191.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:249::14) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4148:EE_ X-MS-Office365-Filtering-Correlation-Id: 17208fe1-2f79-4791-0afc-08dcd14f24d7 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: =?us-ascii?Q?SZ5J+werEmfKSvNgJ6LyyRiVC5fbAc/dNJFT9HAaxLR2TZTeJktuJgd/FRCD?= =?us-ascii?Q?jg0jLD+Km/UdvcgQoYEZV7+3aLDKVDS2RC0DAYMVhaqj1Qwog/bqcodFZLUY?= =?us-ascii?Q?hEauw/Bfi/nTTMDvcHWVmtw8QhIkki4vx2PvQp7OKRdWv0PY5N92tHZqv0fz?= =?us-ascii?Q?cosYdVq85tj4hC14ZRO8fTVXrwPJRAz6sMMXtJpTbAs72dOFjwWGZn2I9yLr?= =?us-ascii?Q?UyHNh6kzkf7/OJS/uF7im/N0xcC0y6oILO/sN3cfXg5C5brJLXmA6b/M9p7D?= =?us-ascii?Q?0N2MEjQx03lWneh1XaOuBRI+NKxmF52ukbgysFxPqwLZoSJZ+hrDFUokP+CO?= =?us-ascii?Q?xKnVcGcceJO9MsDuDsuqMmA2EIWhXm7UbAYNsC3GisF1HEAl+TO8x6Xru1VI?= =?us-ascii?Q?fF9Lwgo0+J6NGd5OHF4XEAk7F8GMWBLVUePI+UwqADwqeZ+GCSBMuotQP6H+?= =?us-ascii?Q?1xSM+3XjG89BXGFadw9m2QhlugRT8CrbGAd1Fcro2CbqKBq5nzxpAEGmMivV?= =?us-ascii?Q?4dBq8TWWCboL0/DW2JWk+mM+UinHdjA/G3HKqyCtLC0M+KSi9d6ktHpWSlww?= =?us-ascii?Q?J06UEAk6fsAjUA8gsRUUEO4MVV7R/A0R/l79bu/JPRxwW9NBat8uW80qnhTX?= =?us-ascii?Q?h5eCb3NdXNqq64ZBbEwddex/U9u3N7rlDCe8hASydjT5zjcjvmHfl5a1ljA3?= =?us-ascii?Q?P50T+TfPjsIa33lW1rIB2M3RRhnAFo6+4FepkAapejeNpmRPOU1fHG1/laSZ?= =?us-ascii?Q?TONh2hCMb3AwHuyAEF6WoXRK+OedjOmYDjqfCFW/aa506Bp1uVjK7SlqwQHg?= =?us-ascii?Q?ZftGsRbo/TvdawljtM+sh6Do8Hksb1IDQLwKbtJfG8Ml0f8prgRcwQ+PIeC+?= =?us-ascii?Q?HecldqLcLQNK5br0AJEx5BbkjKj1xviqgcFN9ZiXlmGF5Jj0aDDi/kgeSybd?= =?us-ascii?Q?gCFWF9q/ABXMgCqMmp6/EiKIclK2n0FcKb4DngH7Elu9ZsKtiuBH+rLC2czc?= =?us-ascii?Q?IosPcleTlq7S24zayD3V/Jib70TzD4D+bTQSDxfrtcs6VdVpwVSXNlVstUHm?= =?us-ascii?Q?Fi68qZzGxWheT0599MDUrmqM2xcvqPk90i22uDMFV8LWnscobxsPrrK4/Ccf?= =?us-ascii?Q?HLAMblERL893d0/C8zzHYqV0meRxo0upFk88dZ/N7NJwuVHFTjEu1LTMilkT?= =?us-ascii?Q?QsT5w2OK86ACxOCC/8HgGKQ94n4r+tl2co+IrScaNkAnTC0xkMPNAyEYE4aS?= =?us-ascii?Q?JrW29k3Qyvml4B6UVmLyyS8PqjJ4Q5iM2jOt21f15vaut8mJJXvThVzhV+A7?= =?us-ascii?Q?0rc1ICyS/6JZR0vIS1drrFeIRiPPIG2wMKU+uOimx2G9/A=3D=3D?= 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: =?us-ascii?Q?4VdBz8HHLtOxcBhLhCMFL7nMgDg1l0ig+7XmVXiX1CoQqesWh6hvrOo+OKF4?= =?us-ascii?Q?9KMkxhpp5M7RVvmwoEEvHHe6vWcXvR20u9YrO6Rno9Y+6dbWi3MMS03a8ux2?= =?us-ascii?Q?8VSjce8GmJAdVnSRbes8cE9n8G7hyrVjUHsro4GvDzZhxX9ntUJnXB53QmTn?= =?us-ascii?Q?QPWL8zpxfAXhN08D8Ehc4rF7+8furD6TZTSkhn3oESgct6tXK91qqr0JlI0v?= =?us-ascii?Q?PLqa4ZucAm1oCwzxHB37PLtS0lGgTVj/lMeOExX/R/J8s2C4FBGQMx+CQuHJ?= =?us-ascii?Q?ksrydkNi3ku8bqObwnNeD1DmvvIP/73XSasfEzyz27m61wmYoSW2AfNefN7r?= =?us-ascii?Q?Ml6xgA5Ny5Y+coxWtHuBxLAfLAQVuertr2e6zLV97Zk6Dp8vM3hYKsbCgSd3?= =?us-ascii?Q?ot3wvAI6Cw/2RW3hhgT+/GiXfEYI/5U+Dvgqp0cvz2q9xngUsE0CJfhi+X6S?= =?us-ascii?Q?6i57dXihqT+HaclKzki1usmlP4rbnAHa6a5zoB+AC1lgTjks80Q8XGeWIKy6?= =?us-ascii?Q?Y/HYPORkFTkFlZLVtKhZAQYgx1D5nMC0XkfZGFZRjULFAgd069p5e8i/dzlM?= =?us-ascii?Q?+T+URvDUL0FnbrgHPjYFQD63F0/LXy/xIOe/ZTRkTJWWQ9MnSNJ/LVr0xsAy?= =?us-ascii?Q?E5cD4nuvWwu8PPRe811wkKnCYnzv5SBo7m91l7MkVaMmxkpVEl6/17fX7sem?= =?us-ascii?Q?lmqYvfhc9AYbise9aZC86+Q/SCpzNSbh5Y5MpA1+m1w3+16kzkeIju4vgiwH?= =?us-ascii?Q?KutM/IzuONQzxxsZd+mvGRoTiBiE3ji8XPjKFeLuC4oRZzmEPWQszTQveBFh?= =?us-ascii?Q?z8k4S/jfSJEL6hniFpuemF6cUVIPHbup4gBmd69tZoeLM94dTM36R8fG1Okw?= =?us-ascii?Q?3GRRFYoBgtZJDE/yqW0ln+o1F5qEF5ioY2LH+mVES0fhqkM1FF1y+gY1nSig?= =?us-ascii?Q?oKcoy1OySP2cTgZJT9+FB1OJiTWCHmWC+dmy0b+8qFvISNUMCILXyjO2a4lj?= =?us-ascii?Q?iyqY0/iRnu7LLejNtc5Ej0F4Crfus+VZz7L89oUeAeeQKREg+mbqpNxJY+qD?= =?us-ascii?Q?5PWzw2R48LVzYmReFw00X+3R+OHSAUxibr0DbJm7kl9IG7TReJckS9vTRwSR?= =?us-ascii?Q?Je9YwfBRJybuAy/Dz5WKUCHr2yTLj1f78x5fSpM5uuxOaYKXBOYF6ObqbvPD?= =?us-ascii?Q?ObYTw4KfqZdR9KvHT9U97PuwaO7/QWZk0uWjZ9iGxhAt3Msi23bPwLpN7euT?= =?us-ascii?Q?ous82iZ+ThW2a1dH5wHPOIHUUOZUmNiR8EKEULejkbhsa7SPi2jRDk74N6k3?= =?us-ascii?Q?/Tfi7xWZIIY2LdvIdPxbAebXmc8HZC6m5A7ohcOPDATpRC+Zo3VbT0QhNmdU?= =?us-ascii?Q?2s6ohfpw0oPytkhU3GI9H2MZ/HPKEadkbbUVHWk5t8tlOMDimnE7VPZW3G/v?= =?us-ascii?Q?D6eZgPQiEkE6gHly0t3hpQ70MmJhJRktof2U6Yu5SRuhvx1EAT8Rs8fS0xCn?= =?us-ascii?Q?L68Ku7l8sg8PFejh4U1Nw+mAKvvP1OhI6oSFwhwhPwKuR9yxK2402vxrAKDn?= =?us-ascii?Q?wPnMlNq/sl6DOVIDvQ8+4FvbcXmg5aqEtRYLy3xo?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17208fe1-2f79-4791-0afc-08dcd14f24d7 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:03.3332 (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: WL4uVIxk5MMr8lGNbXOSY/6us43cqffRpqpEHjyyGsILF1fV93oCnnD8kPim7Jy2NxuC0tgmjoVI+tqYDrQd3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4148 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Dan Williams --- drivers/pci/p2pdma.c | 6 ++++++ mm/memremap.c | 17 +++++++++++++---- mm/mm_init.c | 22 ++++++++++++++++++---- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 4f47a13..210b9f4 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -129,6 +129,12 @@ static int p2pmem_alloc_mmap(struct file *filp, struct= kobject *kobj, } =20 /* + * Initialise the refcount for the freshly allocated page. As we have + * just allocated the page no one else should be using it. + */ + 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 * pages diff --git a/mm/memremap.c b/mm/memremap.c index 40d4547..07bbe0e 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -488,15 +488,24 @@ void free_zone_device_folio(struct folio *folio) folio->mapping =3D NULL; folio->page.pgmap->ops->page_free(folio_page(folio, 0)); =20 - if (folio->page.pgmap->type !=3D MEMORY_DEVICE_PRIVATE && - folio->page.pgmap->type !=3D MEMORY_DEVICE_COHERENT) + switch (folio->page.pgmap->type) { + case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_COHERENT: + put_dev_pagemap(folio->page.pgmap); + break; + + case MEMORY_DEVICE_FS_DAX: + case MEMORY_DEVICE_GENERIC: /* * 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); + break; + + case MEMORY_DEVICE_PCI_P2PDMA: + break; + } } =20 void zone_device_page_init(struct page *page) diff --git a/mm/mm_init.c b/mm/mm_init.c index 4ba5607..0489820 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1015,12 +1015,26 @@ static void __ref __init_zone_device_page(struct pa= ge *page, unsigned long pfn, } =20 /* - * ZONE_DEVICE pages are released directly to the driver page allocator - * which will set the page count to 1 when allocating the page. + * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC and + * MEMORY_TYPE_FS_DAX pages are released directly to the driver page + * allocator which will set the page count to 1 when allocating the + * page. + * + * MEMORY_TYPE_GENERIC and MEMORY_TYPE_FS_DAX pages automatically have + * their refcount reset to one whenever they are freed (ie. after + * their refcount drops to 0). */ - if (pgmap->type =3D=3D MEMORY_DEVICE_PRIVATE || - pgmap->type =3D=3D MEMORY_DEVICE_COHERENT) + switch (pgmap->type) { + case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_COHERENT: + case MEMORY_DEVICE_PCI_P2PDMA: set_page_count(page, 0); + break; + + case MEMORY_DEVICE_FS_DAX: + case MEMORY_DEVICE_GENERIC: + break; + } } =20 /* --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2089.outbound.protection.outlook.com [40.107.220.89]) (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 4E132168C20; Tue, 10 Sep 2024 04:15:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941713; cv=fail; b=Daawfk1wi3RQzvWg2q8B4WFbKiepgKfyNopPp9na98ZRN6OEv3tJxwSayOHjwnOsd+ctfiwcM59NzispbtX5Fk/OnGEb2zGoJgzB6OTfX5XoDxD1ZP8NY5bJF8ZWqJcCjPJyw9m6dIXtJTbGuF00GODXbYrr3lpuQhrn49h51Qw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941713; c=relaxed/simple; bh=zW/EczAAHj8VYW5kjAxCsQDWDGQ/+6AhzihVni2zQf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=lLQZ9JrLkjofOLKS+/hslhJdY9MuzSNpeK4Dt4n3E/Q7SkRq8KH1z2sxQWlqVaoSAvf07F+jFux/iYfbRffiN3CkgLOej23Wq0FiIzuCOPNi5wvfVhkQ+kYRW0UiD4mWPWKLp03r6wpKSdsNGH9vcwmxYKcMdP4r+t+3QZYyKUM= 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=ZxE+uGPn; arc=fail smtp.client-ip=40.107.220.89 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="ZxE+uGPn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t2SozdAz0QW77S4Bhen0zVnlZiEc0HshNK1GWuqMEiYPUoRt1pYfO1buoRti9bMy1Mt2ACk6p26eJm9ovnB33Sr4cRrZIBKewtcVIbkW7AxRBOzVj8B8lcimsq0nJSquvnk30zEf7eQ+4OSzw6se+khh6SiwAo/nZTfevxElHwEVHiPO5E+XzM+1R/KQFAMrlAowGJPqDd9Cxkr5daAyQclsIfW7f38kb08zSgoWs/fu7X41abFsVh+/qpiHvP8Rl0nXZpVCSK82cyD8MYYM4ZY0bSl55TKqU7U4R5+7YWudPXyMBjPqNzWI+xMghpfq6qgmPaTq2EFXfV6iaAY/SA== 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=DcVLiuWZMyEaidTz8honbOf5KmaLeUplBoucWssgGrM=; b=QH4FkoYmzX9F3/OmPMSfLp5aJZVueAyJjoMsPcbGP7xb3w6GmPJdK7JWOHZ3hY+Jr/Xbw6HX56YXw2i7YZCN5zqm933Om+cBtJC73TnWYrHV78GdOqQlwHM2O16uVVTcONpvpGpgjgjK9Grn5mInE4S+LSN7fUjW26GYf9a563j2RqEl5CKFN+Qd0D+FBFDQa/E5wG55Wup8byTYd7dZZ00kpTr11v8ExpD2MPsucpOIzRxTZeFrDej04d2uDEiVzwv46z505ikkQvR3QRVq4g9GFhxy5NJbqTmKjYhOav3KxLjQl2GDoKyWy9ZZ0aNq1Fq4xH+Lr41rtys0x+NKfQ== 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=DcVLiuWZMyEaidTz8honbOf5KmaLeUplBoucWssgGrM=; b=ZxE+uGPniGIgT2BiDLKyfJcnXdqtBsRz2bLD8IzpIPtqgV4/5hcCPhVbvMR6AmfX0IZiHDSVmcfx89opEcc/7I8C+tUObMm/7YmFwls5CkM8HeVnW5iBaLI095T8BaQgDK5muSsDahrJWDmG7azWT537paZpARkjnvJVNeqha4Cwbec2XJ7At/H3TWEZAO/UemappX351N4dqzgDBd75tXby72MzOwgPvlBbiBXRfyEF8e4Qrs4KxTruzXWPs0OUGr/R9s+NSveq350yYVaRJC0sN2Lej4fldEDYZyaD6fdJOrFK3VuuKZmY23RT4D726tLbSqTydKNYiHKX+1/dfw== 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 BY5PR12MB4148.namprd12.prod.outlook.com (2603:10b6:a03:208::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.20; Tue, 10 Sep 2024 04:15:08 +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:08 +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 03/12] fs/dax: Refactor wait for dax idle page Date: Tue, 10 Sep 2024 14:14:28 +1000 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SY5P282CA0134.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:209::19) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4148:EE_ X-MS-Office365-Filtering-Correlation-Id: 74cb772a-8d46-480e-5af6-08dcd14f27e9 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: =?us-ascii?Q?iqrbVvURPQEAKv3k9135doCKU+t/lEH0CJVPgHV21AOQ3++/eXpr3/QSqvEK?= =?us-ascii?Q?iDeC8sGe1xrf9efOOjAaOc+rJg274pfGqHRI95A/0HuG3F1bJ9haAMVWT77I?= =?us-ascii?Q?GMDDUTPTHES7mIQBy8fxHDSAxFk8dTxLkZo1O1Y4KdQQE30+CbiYP2HaQwyJ?= =?us-ascii?Q?scC77gugvNQKDYIwbJMwey+qbcdg/VNfuymnDaflbF+UeymRBVdDCNgogIJF?= =?us-ascii?Q?IE0tkhNNMmM59LrlMin6EdVwGX6fPwAh4CGBU3bNDBvexTUP/DiZn1xBr3qc?= =?us-ascii?Q?uS1Lv94gt5scgDuuggPpz0yvNPbAKHtk33Xy1VFpgqxRuhFvcsZ9DI6jCTn4?= =?us-ascii?Q?q775A3EqvStJCoo02YQbHqMaQG1DUtX85JWq2Slxaz5nIT6aH9ZFVBJJN05S?= =?us-ascii?Q?ySHt4NRTZJITeVAnMr8VPvM5LK4BlyZIlh54+7UmL5SEzhTnlmnyYhXV1SSJ?= =?us-ascii?Q?7ZG3I8mEAdfPO3FxR/9bq9t5aXgxmpzKClh7XSDwiZK9tRExFJ6GUVq9x17K?= =?us-ascii?Q?ayuzZBORIS918adysDiajM5uKIELRDbhgWMByVhfz3G5GpThr4KVJDc0mtGE?= =?us-ascii?Q?Oe5mMpiu9MrPbtsXKl8Nn6CuNmU8BeDQ+z5hzTYbMBpJftyHJJ23/6SfTH15?= =?us-ascii?Q?DIyMnrir/9r3OZp3sfXAMlnfCxnsTTbLOqR+ge8a9Us9ObOtAl+rh345DRVL?= =?us-ascii?Q?S2p95eeEssMIYrCtIouDdXl+ZS5rKdI+MTPHhbKc7HVO4+VCdqN1L96Fk8lW?= =?us-ascii?Q?vzz9qaIYzpoyE/Eo419ycjI9uSioQG9o1T0RcJL2eOjyho+nVYHqgkvQk3dU?= =?us-ascii?Q?m1kRsL+KP62Ld5y8exIMBlTToBviO6d7hhKYJTnNXqq2bM6eKXWKX7bERleD?= =?us-ascii?Q?i4IZWmc7bhdhQ9n37+GI8zpSNPZHKPmxZFKJRYbu/8eHbpPW7uQAOReP5miS?= =?us-ascii?Q?FTwe7QppDCUQvTx1PByWozgJ+X+2qhXjDAoaLg8NEVY4qCYjLB/mNYgd6vr8?= =?us-ascii?Q?s8+Wcpcxa+OWFh1IV5BJPO7NQHxQScq9CeW0hKDvfdUrxOg/QBi3EmCecfYQ?= =?us-ascii?Q?etSpfPcNSTsrh64b3mYeydwDU1k1UHvn4S2Wu70PCG7quBjgvohPvZAjRYix?= =?us-ascii?Q?96T74EuiFbm9iXchDf3eJct+EzhC9JZ0RUxbafYfW3r1drGOMdGgkPcsEpPT?= =?us-ascii?Q?2F0AHgDLfvICPfJerDZpBLU+kmGIK9vjtLGBM8B+jfEGRNsM7wI1nk/rEQ8a?= =?us-ascii?Q?0tEmWbHkO6HuY2XpdJbuYfaQArD3/xu0XIZ3C0ubGR3oQNAKFWJVGidZm90+?= =?us-ascii?Q?dVyh4tsID/7sS9+dRT0djCbCqLAuMiogEkbCcUO9XUuQeg=3D=3D?= 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: =?us-ascii?Q?qobh2u4tGTkyr9iETtnsUD2llXgvH6z/LiXINDUYu2dlFluk//wfK0kv3AIV?= =?us-ascii?Q?Gn9G4eWyyz05KEM4kCxX3woauWbHLzI36htYslHeRY+CRyGclrzZPYUqYo6u?= =?us-ascii?Q?308NNa7jZi5v2A+579LaSd5eRoqTDCbyCUgyd8CmI9zLMXR+yumkMelvSS52?= =?us-ascii?Q?FRc1KmixMGbrEtG6XGMQC+fgYhtunDwH9Fjgdx3bz0KXml3/DWErjutYduk6?= =?us-ascii?Q?YaaiOCjcH2X/QEj5wiiu639+F0Lm73DT1aHikCMbKWCP900atDBMYTV9tKII?= =?us-ascii?Q?x7as9V6koY9facu6IVUYGGZSe098EOeusmoaiJ7XwMQAg0HLljAV7dAfSo73?= =?us-ascii?Q?EFaK4WkroQuYIUde/ytqax5bLz8/urmAWSh/jJ1pjJyTTKzikDw+9XNd4u3r?= =?us-ascii?Q?4cnZhfONYYJBDs21Pd1uUi3lNXAYpcoXLgv6wH19YCdmodAXvb2xye4OOJaF?= =?us-ascii?Q?Rb8YtjvgZcebq1MroEqrvpNPKh7smBGjK+6e9B/yzNjlZD5cONYLzPHIRbxv?= =?us-ascii?Q?Q7DdcGZXicD91F7bsk21oOmwgIXFWNoDLY5iXepVP6brEI/DCmHxdSKri5bm?= =?us-ascii?Q?VNIEvR3HacZ4Vu7dGf/DZ1az9NeYXSHGOGrmkxzkGeNoF2Kkp9PTY+TohW1I?= =?us-ascii?Q?0nG9mKwEUpM3GGqiwXykjuFjPt9e4qf847VEcqd9lf/4XaSpHGKVQV7XTJ15?= =?us-ascii?Q?Q9+LOkDgkVtpXY6VAalwK8oU76PJ4K44EBOkc0zZ4whXQs4LZ4s4heYsaVAu?= =?us-ascii?Q?QzfwewpVO6VQLRgumrqoOtzLYAYY0yP84TkrGgFyJhohIwuH3Z6NzM8WBJb+?= =?us-ascii?Q?XhzIfX1OEKVk9MOhW8dxOAtMYxtefN1DoqZsv8BdThA+Xy6CMjPt/BSppmjH?= =?us-ascii?Q?qFeKhoCmswSCxWACvPrWuUnHKYSMMuyxau0t5UhtBTLxT0jBqpgypJ8W028h?= =?us-ascii?Q?Sp25aCLQzTvXaeh01z+GCuXrQzAX9XL+OVYMpBQIn7kcSUYltXVXuQQq+KGV?= =?us-ascii?Q?llMMcXJp4fqKkPc/gNRZpNtAl72mRYE5MMq2y1V8upgFujQuT+tRrZEaJkIn?= =?us-ascii?Q?8oP88+pltMwV9qMdfBshjBl1mQrVTj2ZUYGYM1BN+kMP3vNCm7XT38GZjl9T?= =?us-ascii?Q?I0Ynt/j36bW0xGCC/ccMsLmO+Vu3d5MR7c2Gk2nQtgkww8S3ljWsLRnPyYvW?= =?us-ascii?Q?2sBviJ1hyldJVAGctjR10DL//Gc8JlXrjP/NNcA466lGo4w0PADWrHlk6wpY?= =?us-ascii?Q?B/XD4BLctGLHiYoW/LOo6g5a6x9fvJokEtdXMJp1FUJyIq7xzoE0AbfKpy2r?= =?us-ascii?Q?0S7CG77fUPbxQtEVKUSlVgo97H4ch2DlJO2/ivRnL/rnn9iS/ZYRRDjIIl6q?= =?us-ascii?Q?+GvCIlpE102m/xhmXUNwOLh7MSxNl68M2WpggnYEq7tbbjePvZzz7lVeT+2G?= =?us-ascii?Q?Zdc+U6Lam9jYgXsHy9qJMQnecsE0A2FI4AjV1bQDGgCk9GiMMqRBNF242iVG?= =?us-ascii?Q?D1skVmRpN7WELdPcXHC0bD+Vxczq1HHNrSzB2iNhPDh7fzlSNYLazHLCRxe1?= =?us-ascii?Q?4ycv05eLdK8/qUJk1jTVoklKGl/qF7HUl8rSpn7I?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74cb772a-8d46-480e-5af6-08dcd14f27e9 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:08.4801 (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: uO/UtzO3M9SgVZdkYJBej9eFJooqbZV8U6tFNLamjzPW6rAMXhDCSNufl4gCixR+lykbb6TqLLmW9TcXabCd5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4148 Content-Type: text/plain; charset="utf-8" A FS DAX page is considered idle when its refcount drops to one. This is currently open-coded in all file systems supporting FS DAX. Move the idle detection to a common function to make future changes easier. Signed-off-by: Alistair Popple Reviewed-by: Jan Kara Reviewed-by: Christoph Hellwig Reviewed-by: Dan Williams --- fs/ext4/inode.c | 5 +---- fs/fuse/dax.c | 4 +--- fs/xfs/xfs_inode.c | 4 +--- include/linux/dax.h | 8 ++++++++ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 941c1c0..367832a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3923,10 +3923,7 @@ int ext4_break_layouts(struct inode *inode) if (!page) return 0; =20 - error =3D ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) =3D=3D 1, - TASK_INTERRUPTIBLE, 0, 0, - ext4_wait_dax_page(inode)); + error =3D dax_wait_page_idle(page, ext4_wait_dax_page, inode); } while (error =3D=3D 0); =20 return error; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index 12ef91d..da50595 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -676,9 +676,7 @@ static int __fuse_dax_break_layouts(struct inode *inode= , bool *retry, return 0; =20 *retry =3D true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) =3D=3D 1, TASK_INTERRUPTIBLE, - 0, 0, fuse_wait_dax_page(inode)); + return dax_wait_page_idle(page, fuse_wait_dax_page, inode); } =20 /* dmap_end =3D=3D 0 leads to unmapping of whole file */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 7dc6f32..7e27ba1 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -3071,9 +3071,7 @@ xfs_break_dax_layouts( return 0; =20 *retry =3D true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) =3D=3D 1, TASK_INTERRUPTIBLE, - 0, 0, xfs_wait_dax_page(inode)); + return dax_wait_page_idle(page, xfs_wait_dax_page, inode); } =20 int diff --git a/include/linux/dax.h b/include/linux/dax.h index 9d3e332..773dfc4 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -213,6 +213,14 @@ int dax_zero_range(struct inode *inode, loff_t pos, lo= ff_t len, bool *did_zero, int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, const struct iomap_ops *ops); =20 +static inline int dax_wait_page_idle(struct page *page, + void (cb)(struct inode *), + struct inode *inode) +{ + return ___wait_var_event(page, page_ref_count(page) =3D=3D 1, + TASK_INTERRUPTIBLE, 0, 0, cb(inode)); +} + #if IS_ENABLED(CONFIG_DAX) int dax_read_lock(void); void dax_read_unlock(int id); --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2084.outbound.protection.outlook.com [40.107.236.84]) (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 7AF9C18C32E; Tue, 10 Sep 2024 04:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941719; cv=fail; b=aszw6tUQt0+6LFWgpQ0kR9MPu3+F6/r0r/bQS9Ph5Q1NHTtPVnbrnoYf5ScGX++HGG85pyWG6409fve0/+9iXqAAmOkYG3oQLAhMcipf8LsExRKpLLc3uXWGllnOWGiPjjUuIcLpATiDCp+TfZgyjDMff6NZOd3AfIdTVWVx6XE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941719; c=relaxed/simple; bh=63HHAE7U8KheeCI16daaZ8HaV/4dWktvA5XX4WpBirg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=mq8r2iAUWOsoqhozk9VG8vSefGl9oKNZOdTpUVhT0wKln3M/sPIuqcW1jlmDHEonB/zTCNzKSbgzluoeKVC2JwPYq9O4ohZY675WQ6k5R/FTEL22qWsAcH8/iO7T0DQZrGB0wIwe39SKfIHXGoLRmsHIhJ3UYUhpHG1ajhYti1Q= 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=PMc6RK/5; arc=fail smtp.client-ip=40.107.236.84 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="PMc6RK/5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j0s5HjgiXJovpJ1+1cWjpMmFdiawikYgZCOBGVFXQyYXeHzFFDGVJ1RsVzU8x4WBqz9s4XHCxFoUdg0VwzKkyeoj4Whg1HodxYI17xsR6lmzAz3vUQ8+aEZ8ran2BjnLbPVYdFAllbGUmUPCzv9hJs/4RgObCUIgDnUJaW6E6SJjEng1qitXjYkijpWniZqievDOMWCz1HJxhgAxXyDPs8bzQOUMuLg5Yuj7db8gx1DCtPo+QzCAL0/fgrSHB9ZTxScSZl5vRMdbShFtJKSrIqPGdy/4lWQPpmtYkhakcdFiVhZ6ktPonmUwFrQ+zUbugXz0BmKj2q5cq26VEnprEQ== 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=VEsOjpdhx2gPdJTwDK+5GbbARYUEApLZebd7uxMRR9Q=; b=m5zKAEoIS2KWAcYnY3N+Pdp3astcqtr4Xfh4Y5fdCErztd+cbyFEsNKNdSu9fEPkUC2coxC2EpGQj9N9XMLrsKhE9TNY8L8pzPlZbsJ09lR21M2YSerLcqRYmwc9mZ94K6MpxnunA0hVYcUDmMyCrVLMN8vFdO4JDAZU7+btT1tNNJplcsCrXOJyvfRRi4OSTR1QWJxafnTP5NMTe8vlosuKUVIxu2LP3kogzzpJMLaqk3W6DAlNLVuIdTyO0/CbH/T7VL0cDB+UGtmbrPPveTVIu98FJCvkVYBswO5E5PMf0hpe83ynfVUcypm5mN3latHRkJB7SmHarEb/To7mcg== 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=VEsOjpdhx2gPdJTwDK+5GbbARYUEApLZebd7uxMRR9Q=; b=PMc6RK/5gmiewEjbZkjkJ+e8yjpTAIx5yvv+7RvBbejaQWXzq+BPEPcUhppMLZ1uQ5bsCu5wYn1aBG9bcm1r5jR804qWOCPWYdMf9jp+4vp0Cg/X1HNBUzYLynSZ2dRPJRavH4gjTNluKpHkPIek0OpLfKycbN3ODDvN4c8ecLeq41/2dvi/I4H5CK57FLHR2bYJkVFtTOX6H6URZX0PvfdpJxCS5CJ6qCk8iY84SYdKzhQiufazBaEeFebgEGkz4hyyEx2uAiJkUyw7aDgdBbmJKx3AWRLpU0hdqxoRLisdAv23GjEGE3fxi6S3Rj2kYJh0FRqGI8cdq5gdvbjzEA== 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 BY5PR12MB4148.namprd12.prod.outlook.com (2603:10b6:a03:208::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.20; Tue, 10 Sep 2024 04:15: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%3]) with mapi id 15.20.7918.024; Tue, 10 Sep 2024 04:15:13 +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, Jason Gunthorpe Subject: [PATCH 04/12] mm: Allow compound zone device pages Date: Tue, 10 Sep 2024 14:14:29 +1000 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SY5PR01CA0015.ausprd01.prod.outlook.com (2603:10c6:10:1fa::18) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4148:EE_ X-MS-Office365-Filtering-Correlation-Id: 5cb2e5a1-eb85-4f45-ea92-08dcd14f2b0f 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: =?us-ascii?Q?uoFnlTqPCRafGcsU3FqgEABbN5Uqrf8Hfyolk3n1xFlonzTwRyH92Eey9N+D?= =?us-ascii?Q?TObprvKP92pl/ghpUQ5o87Cac3jdXgOwTdk68spF2ijf6J53ftF40kr/DaHn?= =?us-ascii?Q?DLozH+O6dlujMj+eyADjXw25Y6GeYnRzxMDXQLHc2iWyhzrPBJ2iTAa/hc+i?= =?us-ascii?Q?uSoKj9HWl6Zy6fZ8ZMD63oNkzgXL6NXA2afKIiPB+Qqw+p05e4RFcIpfUw5p?= =?us-ascii?Q?0gY9zOImbYTgxS2t98ScXHOT+50pPDIOZidYa0JXR3rfOMUOfSjCi2eBtmpQ?= =?us-ascii?Q?WZKfbGs5R5Up4Ehhhb06qCXTPcPKtj9TpUfOG1aLTi6XrmlWIi5Euu0NurN+?= =?us-ascii?Q?OtecMfRhOuIjtT9jqgSOZ7ufXkt3VR0/iIOK13TWMsRwE9goifOmGGATAyfo?= =?us-ascii?Q?bOMgyJI6pBawpOLiqR/5eYueXNQpENCONyigDqsVebw4274rZKMBDwntuQVN?= =?us-ascii?Q?oypXm4Z1iEi6c8fmY+XZuE9tlqK3iKfIb6rgh3tf5FXxeQcEPL3Dg+/+DHIA?= =?us-ascii?Q?J6OG6WbQn2q6cKKfrO3knwJ+v088CCNGnuB1H4jUrlGZSmUjyYciDLCR3Anm?= =?us-ascii?Q?AG3TCmPEP/TGopTQKmCpnls2NJvDuBsmC6qYoYr9JpemTsjuCPgQWiYH/4UH?= =?us-ascii?Q?ZJERQynh8IRTfGihrlzBNmhwfH0w/3JkUrc8hCIsw/YLXGmncxkAT2HSqlSF?= =?us-ascii?Q?exw3QSBGZcfDbptYE/xRmSz3kAwJX+SRAdUvhDQf45/PE1N3Aei4Ic5li+Yp?= =?us-ascii?Q?wj+91UMDH4+DO7AOLoOILZ0ghiEbbXspV42Bzz9VdQI4mdwQnibz1v/kcGE3?= =?us-ascii?Q?r2hghrQm12se6h/v8f/WAxOA5S/2+FHaTt/TZyI1T7HoK0baqHx3qOmv1l87?= =?us-ascii?Q?rpORvCm5Bv9J1YLY8P3ULXggi54BXboZpMfBtHgmkjTIThy+2iQ0vc/OylHG?= =?us-ascii?Q?IO+zNAk79DQxuZXOwumUdgA1OD8eY4/2dUouhr8us/VaVV/dbL/jjIvIUqRk?= =?us-ascii?Q?IuLW3Acn6F4gHv5RYp4lYobXLZGmJih1arTYhLOLUY3C4EGrUFkXJUGTFY0F?= =?us-ascii?Q?+usyM1BY/aJbueT6YFJp8D/pO/8xKK35g8ei2y2caxGSpqAIHFNj2CVFISMi?= =?us-ascii?Q?MuZPfhZ2pdCTrHOGkgmkLrqXFCPHAVx/sJCEVpTwIYqUm3ldHnBcNLFsCXI4?= =?us-ascii?Q?aGsEBN2s92ep+GJyk5surKLK3hVKlapjwBUK9iURgnY8FZSeybxli1J9ZTpy?= =?us-ascii?Q?8Han/PNK8wRoYj/3GRrLkvEAeLiOMCb0euVnbo21kR7TT+MghiU1CQWfRtsW?= =?us-ascii?Q?70+jIXVAWkXfpnDcxOlaYmhlaKFrlQIlxKDCDmYZDDUCxA=3D=3D?= 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: =?us-ascii?Q?kBXV69qqtHhZalRdv1aKk3DNGZAlbMYSXVxcu3EYI/s5XkjBxgTzTnWzSmkk?= =?us-ascii?Q?xfdKQ1l85w7aO4brH7Ppoxk3iRpsvA2orPpQ5hjhGIEzsXUvXtiPrELcYBcu?= =?us-ascii?Q?Kkm04Fv0MuxoEXlPWbtpOWiWVPCcJ5D7G5BwD4PftvCwDg6sG68RqAHPO2Eg?= =?us-ascii?Q?qajPgMS2IjDeSMdDlYV8snBWD+9yIsOMf3yi0zEk+A222ejepWhn6cKlfNlA?= =?us-ascii?Q?jWUeO8RXy/lXWzuaIFKmyrXcF8JET7wCf7xVvNDPHpgsIaLo1xSFvsAYZGH9?= =?us-ascii?Q?A20toO6i4oCrKp4M5aWc6fi+IMxqWJhLL/hYSXQm/eLID301KOA4Mixg7pp/?= =?us-ascii?Q?IjDJHMQ0hMV5oC98DgzpwT/exZdEajeimwGU9AcIVjOSq1VAZL3RImOrrxCt?= =?us-ascii?Q?ca2ymWxOS7KeV6sXWcCqPAXC90712qf/ZrTh8DzcnnWxrCKShHc/Ov+nK2Li?= =?us-ascii?Q?gDp01Fekh8Mr4gCLZ04idufFOqyN/CeCmnEYxFaRwYoT0vS4lfpsGe0LJA4+?= =?us-ascii?Q?7YiECDIcOAjlXjLTrKs49NGzXDF6du+2PO+aUywG4JfFikULD5ojnYo8jXMK?= =?us-ascii?Q?4a54rmwv/gQBZUaIYNUlnAiIJ5ED2G1xV9bUgwJMJR+1gdpAfbfJDq/aL3vY?= =?us-ascii?Q?Sb9o4q/uRwx5GB1NeOLMkZSI9fl7Prtl4fLvU7JGmXYrxldQs3HOqd0HAeI0?= =?us-ascii?Q?lcKXuO56vdxqXrNfhSWLw0c+j9YtcJeySewibVCWTtAInaHxB5dot+OzXiTm?= =?us-ascii?Q?DofXU6TplMEBZPTCQnvsWEXvKshEiffakujvlZAtbR2XhHszZTuC/ksZ6aGq?= =?us-ascii?Q?c4u0qnuyiVO8cSm2R74hAe+7qJRPxuiM4QUDKoKnjHL/Gk5SfZAAbx024HNA?= =?us-ascii?Q?y2E2/736TqdSIv/wsLaTkeYB+IxWWTdrAFDDvUUJKentZ2Eh5s0J0qqAKoh/?= =?us-ascii?Q?VVco4TSbm/oqApdVZo9QEObnvAR0kfUkP/vEVFpVPfyoPFufaKDTAqTwGiFF?= =?us-ascii?Q?JDaLIOrURijdFJMNWVbesIHrshCLr6UPU3CL7RDquO8/ZZ/BF8lo6/E2ZsQk?= =?us-ascii?Q?qJnfqHI27MslELd2/9lw2ZBKAARUNcVpr65jtkR0P0PzGiSTPaxP8AfiXZ1d?= =?us-ascii?Q?ZerOpgyTCnWHbUrqPvm7Mq+PfzK3D/fg5uhA9QaCyLSbQiUNU+V9EsS/4cq0?= =?us-ascii?Q?oZgIPYROp4gCS7A9V9a/9GwilRPvcWECYVADcIJVENa5M/Zue2NpZAd4ChM/?= =?us-ascii?Q?y/8RjO8K8ROaUYiVBzo7i1FeTjdpOgs/ctKpmW90NpvwluPlHPi2lPpV1A/h?= =?us-ascii?Q?3uH1qNN3KXv0yXTVIJpJ8n6eefT59y1sumeUkZScKO9Yi4lEwEVj3PRzyUnY?= =?us-ascii?Q?HpxhN3U8QkWik6C2Noz3R2JVjYpQADAqSQ4gK3KIeZXQRYNh/jpIq0bsqahn?= =?us-ascii?Q?/NJ5kJqPKMimkbN9C1SVeNAbyTLbJVtVgoMElTjsCoG9vScEhCBXkWrBss/t?= =?us-ascii?Q?JCQMtw11rFis82ygqJnfZPnz8l+J5FPT8UJFdCgLv3r3YsVJIpK1u9I2R3Tx?= =?us-ascii?Q?I6NJeQYV1XWlSIZsDDVUJR+h96zkFMQowdPMPbA7?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5cb2e5a1-eb85-4f45-ea92-08dcd14f2b0f 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:13.7800 (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: f1YbV/7E42pYhfdOYr5F1P8DEub/9wB/qqBJ7dBRqesOKLMmcUgYz5BhPeEM77ajDKMUINJd/lM2KIE/aRGJ2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4148 Content-Type: text/plain; charset="utf-8" Zone device pages are used to represent various type of device memory managed by device drivers. Currently compound zone device pages are not supported. This is because MEMORY_DEVICE_FS_DAX pages are the only user of higher order zone device pages and have their own page reference counting. A future change will unify FS DAX reference counting with normal page reference counting rules and remove the special FS DAX reference counting. Supporting that requires compound zone device pages. Supporting compound zone device pages requires compound_head() to distinguish between head and tail pages whilst still preserving the special struct page fields that are specific to zone device pages. A tail page is distinguished by having bit zero being set in page->compound_head, with the remaining bits pointing to the head page. For zone device pages page->compound_head is shared with page->pgmap. The page->pgmap field is common to all pages within a memory section. Therefore pgmap is the same for both head and tail pages and can be moved into the folio and we can use the standard scheme to find compound_head from a tail page. Signed-off-by: Alistair Popple Reviewed-by: Jason Gunthorpe Reviewed-by: Dan Williams --- Changes since v1: - Move pgmap to the folio as suggested by Matthew Wilcox --- drivers/gpu/drm/nouveau/nouveau_dmem.c | 3 ++- drivers/pci/p2pdma.c | 6 +++--- include/linux/memremap.h | 6 +++--- include/linux/migrate.h | 4 ++-- include/linux/mm_types.h | 9 +++++++-- include/linux/mmzone.h | 8 +++++++- lib/test_hmm.c | 3 ++- mm/hmm.c | 2 +- mm/memory.c | 4 +++- mm/memremap.c | 14 +++++++------- mm/migrate_device.c | 7 +++++-- mm/mm_init.c | 2 +- 12 files changed, 43 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouve= au/nouveau_dmem.c index 6fb65b0..58d308c 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -88,7 +88,8 @@ struct nouveau_dmem { =20 static struct nouveau_dmem_chunk *nouveau_page_to_chunk(struct page *page) { - return container_of(page->pgmap, struct nouveau_dmem_chunk, pagemap); + return container_of(page_dev_pagemap(page), struct nouveau_dmem_chunk, + pagemap); } =20 static struct nouveau_drm *page_to_drm(struct page *page) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 210b9f4..a58f2c1 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -199,7 +199,7 @@ static const struct attribute_group p2pmem_group =3D { =20 static void p2pdma_page_free(struct page *page) { - struct pci_p2pdma_pagemap *pgmap =3D to_p2p_pgmap(page->pgmap); + struct pci_p2pdma_pagemap *pgmap =3D to_p2p_pgmap(page_dev_pagemap(page)); /* safe to dereference while a reference is held to the percpu ref */ struct pci_p2pdma *p2pdma =3D rcu_dereference_protected(pgmap->provider->p2pdma, 1); @@ -1022,8 +1022,8 @@ enum pci_p2pdma_map_type pci_p2pdma_map_segment(struct pci_p2pdma_map_state *state, struct device *= dev, struct scatterlist *sg) { - if (state->pgmap !=3D sg_page(sg)->pgmap) { - state->pgmap =3D sg_page(sg)->pgmap; + if (state->pgmap !=3D page_dev_pagemap(sg_page(sg))) { + state->pgmap =3D page_dev_pagemap(sg_page(sg)); state->map =3D pci_p2pdma_map_type(state->pgmap, dev); state->bus_off =3D to_p2p_pgmap(state->pgmap)->bus_offset; } diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 3f7143a..14273e6 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -161,7 +161,7 @@ static inline bool is_device_private_page(const struct = page *page) { return IS_ENABLED(CONFIG_DEVICE_PRIVATE) && is_zone_device_page(page) && - page->pgmap->type =3D=3D MEMORY_DEVICE_PRIVATE; + page_dev_pagemap(page)->type =3D=3D MEMORY_DEVICE_PRIVATE; } =20 static inline bool folio_is_device_private(const struct folio *folio) @@ -173,13 +173,13 @@ static inline bool is_pci_p2pdma_page(const struct pa= ge *page) { return IS_ENABLED(CONFIG_PCI_P2PDMA) && is_zone_device_page(page) && - page->pgmap->type =3D=3D MEMORY_DEVICE_PCI_P2PDMA; + page_dev_pagemap(page)->type =3D=3D MEMORY_DEVICE_PCI_P2PDMA; } =20 static inline bool is_device_coherent_page(const struct page *page) { return is_zone_device_page(page) && - page->pgmap->type =3D=3D MEMORY_DEVICE_COHERENT; + page_dev_pagemap(page)->type =3D=3D MEMORY_DEVICE_COHERENT; } =20 static inline bool folio_is_device_coherent(const struct folio *folio) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 002e49b..9a85a82 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -207,8 +207,8 @@ struct migrate_vma { unsigned long end; =20 /* - * Set to the owner value also stored in page->pgmap->owner for - * migrating out of device private memory. The flags also need to + * Set to the owner value also stored in page_dev_pagemap(page)->owner + * for migrating out of device private memory. The flags also need to * be set to MIGRATE_VMA_SELECT_DEVICE_PRIVATE. * The caller should always set this field when using mmu notifier * callbacks to avoid device MMU invalidations for device private diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 6e3bdf8..c2f1d53 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -129,8 +129,11 @@ struct page { unsigned long compound_head; /* Bit zero is set */ }; struct { /* ZONE_DEVICE pages */ - /** @pgmap: Points to the hosting device page map. */ - struct dev_pagemap *pgmap; + /* + * The first word is used for compound_head or folio + * pgmap + */ + void *_unused; void *zone_device_data; /* * ZONE_DEVICE private pages are counted as being @@ -299,6 +302,7 @@ typedef struct { * @_refcount: Do not access this member directly. Use folio_ref_count() * to find how many references there are to this folio. * @memcg_data: Memory Control Group data. + * @pgmap: Metadata for ZONE_DEVICE mappings * @virtual: Virtual address in the kernel direct map. * @_last_cpupid: IDs of last CPU and last process that accessed the folio. * @_entire_mapcount: Do not use directly, call folio_entire_mapcount(). @@ -337,6 +341,7 @@ struct folio { /* private: */ }; /* public: */ + struct dev_pagemap *pgmap; }; struct address_space *mapping; pgoff_t index; diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 17506e4..e191434 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1134,6 +1134,12 @@ static inline bool is_zone_device_page(const struct = page *page) return page_zonenum(page) =3D=3D ZONE_DEVICE; } =20 +static inline struct dev_pagemap *page_dev_pagemap(const struct page *page) +{ + WARN_ON(!is_zone_device_page(page)); + return page_folio(page)->pgmap; +} + /* * Consecutive zone device pages should not be merged into the same sgl * or bvec segment with other types of pages or if they belong to different @@ -1149,7 +1155,7 @@ static inline bool zone_device_pages_have_same_pgmap(= const struct page *a, return false; if (!is_zone_device_page(a)) return true; - return a->pgmap =3D=3D b->pgmap; + return page_dev_pagemap(a) =3D=3D page_dev_pagemap(b); } =20 extern void memmap_init_zone_device(struct zone *, unsigned long, diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 056f2e4..b072ca9 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -195,7 +195,8 @@ static int dmirror_fops_release(struct inode *inode, st= ruct file *filp) =20 static struct dmirror_chunk *dmirror_page_to_chunk(struct page *page) { - return container_of(page->pgmap, struct dmirror_chunk, pagemap); + return container_of(page_dev_pagemap(page), struct dmirror_chunk, + pagemap); } =20 static struct dmirror_device *dmirror_page_to_device(struct page *page) diff --git a/mm/hmm.c b/mm/hmm.c index 7e0229a..a11807c 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -248,7 +248,7 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, uns= igned long addr, * just report the PFN. */ if (is_device_private_entry(entry) && - pfn_swap_entry_to_page(entry)->pgmap->owner =3D=3D + page_dev_pagemap(pfn_swap_entry_to_page(entry))->owner =3D=3D range->dev_private_owner) { cpu_flags =3D HMM_PFN_VALID; if (is_writable_device_private_entry(entry)) diff --git a/mm/memory.c b/mm/memory.c index c31ea30..d2785fb 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4024,6 +4024,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) vmf->page =3D pfn_swap_entry_to_page(entry); ret =3D remove_device_exclusive_entry(vmf); } else if (is_device_private_entry(entry)) { + struct dev_pagemap *pgmap; if (vmf->flags & FAULT_FLAG_VMA_LOCK) { /* * migrate_to_ram is not yet ready to operate @@ -4048,7 +4049,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) */ get_page(vmf->page); pte_unmap_unlock(vmf->pte, vmf->ptl); - ret =3D vmf->page->pgmap->ops->migrate_to_ram(vmf); + pgmap =3D page_dev_pagemap(vmf->page); + ret =3D pgmap->ops->migrate_to_ram(vmf); put_page(vmf->page); } else if (is_hwpoison_entry(entry)) { ret =3D VM_FAULT_HWPOISON; diff --git a/mm/memremap.c b/mm/memremap.c index 07bbe0e..e885bc9 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -458,8 +458,8 @@ EXPORT_SYMBOL_GPL(get_dev_pagemap); =20 void free_zone_device_folio(struct folio *folio) { - if (WARN_ON_ONCE(!folio->page.pgmap->ops || - !folio->page.pgmap->ops->page_free)) + if (WARN_ON_ONCE(!folio->pgmap->ops || + !folio->pgmap->ops->page_free)) return; =20 mem_cgroup_uncharge(folio); @@ -486,12 +486,12 @@ void free_zone_device_folio(struct folio *folio) * to clear folio->mapping. */ folio->mapping =3D NULL; - folio->page.pgmap->ops->page_free(folio_page(folio, 0)); + folio->pgmap->ops->page_free(folio_page(folio, 0)); =20 - switch (folio->page.pgmap->type) { + switch (folio->pgmap->type) { case MEMORY_DEVICE_PRIVATE: case MEMORY_DEVICE_COHERENT: - put_dev_pagemap(folio->page.pgmap); + put_dev_pagemap(folio->pgmap); break; =20 case MEMORY_DEVICE_FS_DAX: @@ -514,7 +514,7 @@ void zone_device_page_init(struct page *page) * Drivers shouldn't be allocating pages after calling * memunmap_pages(). */ - WARN_ON_ONCE(!percpu_ref_tryget_live(&page->pgmap->ref)); + WARN_ON_ONCE(!percpu_ref_tryget_live(&page_dev_pagemap(page)->ref)); set_page_count(page, 1); lock_page(page); } @@ -523,7 +523,7 @@ EXPORT_SYMBOL_GPL(zone_device_page_init); #ifdef CONFIG_FS_DAX bool __put_devmap_managed_folio_refs(struct folio *folio, int refs) { - if (folio->page.pgmap->type !=3D MEMORY_DEVICE_FS_DAX) + if (folio->pgmap->type !=3D MEMORY_DEVICE_FS_DAX) return false; =20 /* diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 6d66dc1..9d30107 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -106,6 +106,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, arch_enter_lazy_mmu_mode(); =20 for (; addr < end; addr +=3D PAGE_SIZE, ptep++) { + struct dev_pagemap *pgmap; unsigned long mpfn =3D 0, pfn; struct folio *folio; struct page *page; @@ -133,9 +134,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, goto next; =20 page =3D pfn_swap_entry_to_page(entry); + pgmap =3D page_dev_pagemap(page); if (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_PRIVATE) || - page->pgmap->owner !=3D migrate->pgmap_owner) + pgmap->owner !=3D migrate->pgmap_owner) goto next; =20 mpfn =3D migrate_pfn(page_to_pfn(page)) | @@ -151,12 +153,13 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, goto next; } page =3D vm_normal_page(migrate->vma, addr, pte); + pgmap =3D page_dev_pagemap(page); if (page && !is_zone_device_page(page) && !(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) goto next; else if (page && is_device_coherent_page(page) && (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_COHERENT) || - page->pgmap->owner !=3D migrate->pgmap_owner)) + pgmap->owner !=3D migrate->pgmap_owner)) goto next; mpfn =3D migrate_pfn(pfn) | MIGRATE_PFN_MIGRATE; mpfn |=3D pte_write(pte) ? MIGRATE_PFN_WRITE : 0; diff --git a/mm/mm_init.c b/mm/mm_init.c index 0489820..3d0611e 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -996,7 +996,7 @@ static void __ref __init_zone_device_page(struct page *= page, unsigned long pfn, * and zone_device_data. It is a bug if a ZONE_DEVICE page is * ever freed or placed on a driver-private list. */ - page->pgmap =3D pgmap; + page_folio(page)->pgmap =3D pgmap; page->zone_device_data =3D NULL; =20 /* --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2073.outbound.protection.outlook.com [40.107.220.73]) (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 18CDC18D649; Tue, 10 Sep 2024 04:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941724; cv=fail; b=GA71KC5PVaPGDXY7jOLHc7uLcS8Ht7MM3g81r1Frpv0SHL3wOvN/YhwsPSdNi+FNJSBYpJujpL3dHhsh07scghtr2OyrRNvmwBXginrbSWY5LCyMc+JQ3DEd+2+op6NejTuRINieEQOfCgRS4G4mOZkLm9es/5frHG8B+FRuXzI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941724; c=relaxed/simple; bh=P8hj8duirPqMbwv4st4UqVI974aAMGWoSxucp+HHAyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=KnCOEBepaUdrZrQKnb7r5WLnd8P1TphpmTSRRRhfemNasCGbM66Dd9DjC7rscI00UGIAH13KUbm/Gv9GLPMDV8WIWusTjqpvCCTWMh4NysLFxBPci16dbr4IuzJfZ88mQvwbPMES5QRwHq8Oi8WW0xFPnC7MObQ38CtskSGiTwc= 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=lr7jpi/6; arc=fail smtp.client-ip=40.107.220.73 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="lr7jpi/6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tVemABZIZThPaR09NY40UZOvIqHoiesl5ZNh0FBob/FonkyBWycrHaU5ipwh2JTWluOOsHkKOHPvBuL3gjPkY7oo+y9RISSeg0LOgtpqIeLhyIB8BrOr5026xt56HUAI51vOTd1aNAgJMo7VMCTp1+w4JOO2jeEaEp7/mbxd1tPK7W2UPOCm3N3w8cYE05eC66Gh3DNAGQobxvJSVjY8HXKn1inJZrwEEb8EIKMQGKvcVLBwiufsHU2DPS841wgEqDQmto2aT4c9XGF7cNzHO3Rb2NTf5QmjC9uVd8Ugm3PVtKbohfHJnq9l9OhkyB1WGKcwGGZTeFSPi8yC3OKsvQ== 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=44/c89HYmWXuc2I8zGYG6pChU962eRsHc5iIPIY/3LY=; b=c+mq6fuamCE/tHlRkMn1FouhTffZ9kNN9cQui2slEOCe+lSqSIZdYZxY2To6iTxChranpxUDvSX9J3aPmWTmw0iuSD7fqmsDxaPH3LPu0mlrc5Kf4RjrYibaahedbi3iOTBhI7ALXGwqySOJyePXaEP5ubS1DgzlFYH6sCIeLOqcTBToKwicq8p0gqw/PF4ajLhEI/r7wlFA5huYwxo6B+C2hYVyQIw4/T3rKltfQruhKfgO9FWdNl7e/YJkuhxUQQ0cWY/oEswIcW3pNN/HRnQOEejvIyXMvcjyTbBybj5XvGGduApmuEnbxZ7kWiZH69Uea9NmdIm+1xEipxKx4Q== 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=44/c89HYmWXuc2I8zGYG6pChU962eRsHc5iIPIY/3LY=; b=lr7jpi/6v5w1PCtw63AaJp9L3qhf1QIVAzexT9KUftGE2lWKBTtsxh2ZiraW9u76im6zz2Clr4yS5xXMfAi9CfubXbkinstM+fmOnvOIzGOYn5YaMJBuy+AulXq/qbqXT6kW5dPqlrtAXsRxPAPEFTtMc/2nqh2bhLARF01zK1rqd2o7wLF1V/yPJ6+QoG7xqL2kUx8HO6FYBA9PUnstl1QirOy207mZrNklyb0D6d2e0LZnWZIW3U2GMlXs0me0XeBOZVURMIk+WkcwnTKQZ8+88knOoeMngqF1SFjbvZe+oeSeUVEs3pd6aimLs41aAw4Ak/Edhs8V/ltifhdMkA== 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 BY5PR12MB4148.namprd12.prod.outlook.com (2603:10b6:a03:208::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.20; Tue, 10 Sep 2024 04:15:19 +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:19 +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 05/12] mm/memory: Add dax_insert_pfn Date: Tue, 10 Sep 2024 14:14:30 +1000 Message-ID: <110d5b177d793ab17ea5d1210606cb7dd0f82493.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SY8P282CA0001.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:29b::35) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4148:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a32106e-d821-48f2-d5a0-08dcd14f2e4b 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: =?us-ascii?Q?OYHtU7a8jLIt/MuBG+b8ChbB5Htn+KST2CrbhqYChwiM4iKd2w4r6a1cx+ZO?= =?us-ascii?Q?VdT4jchb8Xa06XqPhf7gdEjEFyMZRpkPARGsEE/EZ0oItIGQVhSWjGBvYpJS?= =?us-ascii?Q?GvLTBzcW+HMto4B8hdGo0P9gP6M+4cOxhftkRRcfxUAOUKVi2n9JEqtgMESY?= =?us-ascii?Q?hrkjH90eOJOxcMIV53y+MPqVddgL0EO+f7Zo/mSN/mBXHC7lxXrqSXTvkeab?= =?us-ascii?Q?mzNieQWoXoo5Xv1Uej7ucJaRzJMJpJvZ5EPNhDm0WhC20BZ5vQH3+Rz20hv1?= =?us-ascii?Q?F7GK+Q4y5ku38V5uZFNWORn8k/OP+qeP5+3rYR6HgIwdCcjM2GVwM730+wCR?= =?us-ascii?Q?Bh76YwbBn0JDjsLzCDxhVvUILwsafolEQPQkrpz+ZBWRVNwKtdYVth2Jp4U8?= =?us-ascii?Q?xJQHXwZAintWYT5w7ah8mBCiDWMtq3lnvMO86sjCzubC/fwrJQcAl/xY2O81?= =?us-ascii?Q?n6VrlCad3oDkzubZ5WxWC1tcIV2ehxnz691gi+dCc1lVAXZFgke91d1xSIkd?= =?us-ascii?Q?AeHxXI0+mx86UN9LBg+t3b6zP/FlClhSl9W/GdUay9BVjISfETsw3/nffIeF?= =?us-ascii?Q?wPr9sOJEWm9UC5wrq8CTxnHEEB9qAR0UxH3+Ge9EX1YT3ZrMaqUgswelEuxI?= =?us-ascii?Q?g9mgm3YEypX/csVUv6wUJZq51B+3ixhrrA3gvyWdY2dj5PYzqyGLJl7h1xYw?= =?us-ascii?Q?aXl82RWKLqCXNHL7uMWZ7XtR7EmWEnpdUroCDV4xsCYUp0meizINycAdK8st?= =?us-ascii?Q?r+UQl1MZ0+M7fMKKOhW46bRIpRCVWOeOOUvCvc3eMPawn6r517CqvgveszOs?= =?us-ascii?Q?5Ak4fq0xYoiuQcGQ7tl4CoGZknRBXAe+NvGanz6fROXRJHTETy46xvICDY4w?= =?us-ascii?Q?WDJNJ6g5XI2KPsB9I3AlanHYuZWtZW26VOFxPVUD71p/+8LdzXKcW+GbAbwD?= =?us-ascii?Q?onQrNKGkedPtDPLH9u4AED3PA5vzjDcRSZcxRlhBnl/7vcjTguwKKO7i1tum?= =?us-ascii?Q?4T29zmvYD2ZGPmWCn9rE9Owu/A4LYXLCgUnZO990BxQFWYcztAaRC5llLjea?= =?us-ascii?Q?cmbg0vKftkbA2LrMX0RgK2Nw5h6O1dWfk0cxVpxOFTlkSEtvagQ4loS+n5WJ?= =?us-ascii?Q?FChSEChYkGTa6ALDqNUKg1jvrtSFV6H2KXZQLY+ZdVEYNHCUsdOyGYHEFcIv?= =?us-ascii?Q?zSe6ddNykGPEEAFYaZ2BIyngaZLVSvG80zUHT6llwMw+cW1RjVgmrqnmRISl?= =?us-ascii?Q?LU3Om9VHw9qBcfKXVujQSql5BmEFfebKhjgAtNgcP3JXIYAp0CkTOq9ADoQi?= =?us-ascii?Q?DA2+G9O4sbNH0hUqBmPaR3dP2sMVQjiUPGikbufvXpQEzQ=3D=3D?= 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: =?us-ascii?Q?4fm1AMGUfi0XUs52JZf0rz+bge8SUQRMukaoO6sIPARxe4n5otAObBKpyu3W?= =?us-ascii?Q?1n7WGCKXebBq4Ky8M2tw40dTrJGGqEtpOaIbdirmJh6XWMd1HxjZNeNP/8Dg?= =?us-ascii?Q?hHjc19eRMiKCU9ghM2snmuSkeoFDD6vXqrt7UmpYdEUD8NvYgxkHwAWoOPy5?= =?us-ascii?Q?t/NZpi25GcVAtimDAx5gcES0ibzRyI4dEdc7aXKGoM6WhmYQIV8NFKMxCULp?= =?us-ascii?Q?IBgVUiN77UfGcVSsofsPvuoxRhvlOzTUIACAfn2Gfk3W5rE1uZHB+0I2zFlG?= =?us-ascii?Q?A5LUsQyxYI857LjGlpNMv13fyMF6tLHN/MvcrctRbO8nsSleDu50EmopoPXb?= =?us-ascii?Q?AyoccCLeX5P1Ng1vyLzIws68oF9MKR5alWXi/VafbI4CqxpZufG4o9dgn5I4?= =?us-ascii?Q?hC8bXKo9/fOAoTFEN/l8tVUbZap0c4/obrDaEW8GhFh12LyiCVysczneHbDG?= =?us-ascii?Q?4dKcs/CQTQ9HC5H5oF1/OVYWcx0wiKvDibDE2BGef9h9Pzv4USGKLy63VSd2?= =?us-ascii?Q?bWhwx+lB3PI/kCAqxiCF03IQZY1rhyCMGLnGC2TyZkQX5oYMqKN+wG3p+kWL?= =?us-ascii?Q?4bWW0DhX+yEAvlBd6taXhgSgU/rnh+op55XcZ/xbqdAuyxK5fbonB7nnn2aw?= =?us-ascii?Q?PGBOHHZpTaKbcM9Fg93YhOZB/MW7SLNfzERbNqWW+PDvEuIqOC1oa2YCkdHw?= =?us-ascii?Q?u6gNSYff5yObgIKp3SMjRAt4SVtbD6RbTSAQU+xF17SBsd8nslmjjLGDexDB?= =?us-ascii?Q?nG75oUYNZ9BBKsDzdlZn0DuEn1g5a23v8I+Fe26RCnu6wqitw09Iq8bcKPWZ?= =?us-ascii?Q?Fifv3CPku+gVGmawV6n+vbQ4cZXeITRlWvPudqsjcAj5i08wrioZzCqnTB6o?= =?us-ascii?Q?wi1NY/mBeivSkAg6N6CtPF3lkV5oygoTJwrBt4gLnje+7XFBJ6bCuOCm865g?= =?us-ascii?Q?Bwq5u9Xrk1DNul0QtknjD3p8h6oGKT+HaQtnmMiosR33MbntLMOUJ4wgKF5E?= =?us-ascii?Q?Wfdgkrnc7uxd/ZOrRg0bRjBnmVyMLSi8oobJqadcSMVxwhHIZh5ZFEEMwA7z?= =?us-ascii?Q?X8fmMuyk/vs5ToqbcWA1pqITAz1xrxaudX0jgzSzr5kcBfc/eHKutpNqvFCf?= =?us-ascii?Q?7NY65Bd8Y3benNwUC94FZThYtjkhUVnpVLDXBVPYsAMLoGa6avYzo9teJu3G?= =?us-ascii?Q?BTuHTaKZB1kcv/RS8SdgUckZILeLKzsgcXl7txynyQNuUDktfX5npD/zUBeh?= =?us-ascii?Q?X6n6hNsW9EVAIxr1LamlEF/Q4D2W1BL+4K9yP6bFRXusno1A1zcvm2B3cUpt?= =?us-ascii?Q?wwsoI6lD2GBsTmq3KB6Z37cH8K/AI9uXcxRq7TazLN5s9+JS7osha67dg13C?= =?us-ascii?Q?OSAddanHsxMI7IfoYfYYQOuXznxposOk5mwxrJQOpDfQErf3Ll/UHkc945br?= =?us-ascii?Q?K33qUDs55BLoZTGvinpXPmvAnlokvgPj020XkvWLVCeSyTsDNoHuQslv1Mjv?= =?us-ascii?Q?EoDM2+xSiQxs9RRaJlvFa7+AcFeWFYcqOAMz42EG9VZEcjSgAgv3R7JY/Yr0?= =?us-ascii?Q?TBeayITiJBylzzs+msSazDtTJivcCjbucF3PsU6v?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a32106e-d821-48f2-d5a0-08dcd14f2e4b 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:19.2031 (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: vrD+oo8TgBdRf5WfNZocgy7YpSi09mpOuFvt+6m/W4jpWAksLIQ49wwxXSOW4YqO+Kh9BVzpdCHqpFjQ8xteYw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4148 Content-Type: text/plain; charset="utf-8" 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 dax_insert_pfn. 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 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 | 1 +- mm/memory.c | 83 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index b0ff06d..ae6d713 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3463,6 +3463,7 @@ int vm_map_pages(struct vm_area_struct *vma, struct p= age **pages, unsigned long num); int vm_map_pages_zero(struct vm_area_struct *vma, struct page **pages, unsigned long num); +vm_fault_t dax_insert_pfn(struct vm_fault *vmf, pfn_t pfn_t, 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 a= ddr, diff --git a/mm/memory.c b/mm/memory.c index d2785fb..368e15d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2039,19 +2039,47 @@ static int validate_page_before_insert(struct vm_ar= ea_struct *vma, } =20 static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *= pte, - unsigned long addr, struct page *page, pgprot_t prot) + unsigned long addr, struct page *page, + pgprot_t prot, bool mkwrite) { struct folio *folio =3D page_folio(page); + pte_t entry =3D ptep_get(pte); pte_t pteval; =20 - if (!pte_none(ptep_get(pte))) - return -EBUSY; + if (!pte_none(entry)) { + if (!mkwrite) + return -EBUSY; + + /* + * For read faults on private mappings the PFN passed in may not + * match the PFN we have mapped if the mapped PFN is a writeable + * COW page. In the mkwrite case we are creating a writable PTE + * for a shared mapping and we expect the PFNs to match. If they + * don't match, we are likely racing with block allocation and + * mapping invalidation so just skip the update. + */ + if (pte_pfn(entry) !=3D page_to_pfn(page)) { + WARN_ON_ONCE(!is_zero_pfn(pte_pfn(entry))); + return -EFAULT; + } + entry =3D maybe_mkwrite(entry, vma); + entry =3D pte_mkyoung(entry); + if (ptep_set_access_flags(vma, addr, pte, entry, 1)) + update_mmu_cache(vma, addr, pte); + return 0; + } + /* Ok, finally just insert the thing.. */ pteval =3D mk_pte(page, prot); if (unlikely(is_zero_folio(folio))) { pteval =3D pte_mkspecial(pteval); } else { folio_get(folio); + entry =3D mk_pte(page, prot); + if (mkwrite) { + entry =3D pte_mkyoung(entry); + entry =3D maybe_mkwrite(pte_mkdirty(entry), vma); + } inc_mm_counter(vma->vm_mm, mm_counter_file(folio)); folio_add_file_rmap_pte(folio, page, vma); } @@ -2060,7 +2088,7 @@ static int insert_page_into_pte_locked(struct vm_area= _struct *vma, pte_t *pte, } =20 static int insert_page(struct vm_area_struct *vma, unsigned long addr, - struct page *page, pgprot_t prot) + struct page *page, pgprot_t prot, bool mkwrite) { int retval; pte_t *pte; @@ -2073,7 +2101,8 @@ static int insert_page(struct vm_area_struct *vma, un= signed long addr, pte =3D get_locked_pte(vma->vm_mm, addr, &ptl); if (!pte) goto out; - retval =3D insert_page_into_pte_locked(vma, pte, addr, page, prot); + retval =3D insert_page_into_pte_locked(vma, pte, addr, page, prot, + mkwrite); pte_unmap_unlock(pte, ptl); out: return retval; @@ -2087,7 +2116,7 @@ static int insert_page_in_batch_locked(struct vm_area= _struct *vma, pte_t *pte, err =3D validate_page_before_insert(vma, page); if (err) return err; - return insert_page_into_pte_locked(vma, pte, addr, page, prot); + return insert_page_into_pte_locked(vma, pte, addr, page, prot, false); } =20 /* insert_pages() amortizes the cost of spinlock operations @@ -2223,7 +2252,7 @@ int vm_insert_page(struct vm_area_struct *vma, unsign= ed long addr, BUG_ON(vma->vm_flags & VM_PFNMAP); vm_flags_set(vma, VM_MIXEDMAP); } - return insert_page(vma, addr, page, vma->vm_page_prot); + return insert_page(vma, addr, page, vma->vm_page_prot, false); } EXPORT_SYMBOL(vm_insert_page); =20 @@ -2503,7 +2532,7 @@ static vm_fault_t __vm_insert_mixed(struct vm_area_st= ruct *vma, * result in pfn_t_has_page() =3D=3D false. */ page =3D pfn_to_page(pfn_t_to_pfn(pfn)); - err =3D insert_page(vma, addr, page, pgprot); + err =3D insert_page(vma, addr, page, pgprot, mkwrite); } else { return insert_pfn(vma, addr, pfn, pgprot, mkwrite); } @@ -2516,6 +2545,44 @@ static vm_fault_t __vm_insert_mixed(struct vm_area_s= truct *vma, return VM_FAULT_NOPAGE; } =20 +vm_fault_t dax_insert_pfn(struct vm_fault *vmf, pfn_t pfn_t, bool write) +{ + struct vm_area_struct *vma =3D vmf->vma; + pgprot_t pgprot =3D vma->vm_page_prot; + unsigned long pfn =3D pfn_t_to_pfn(pfn_t); + struct page *page =3D pfn_to_page(pfn); + unsigned long addr =3D vmf->address; + int err; + + if (addr < vma->vm_start || addr >=3D vma->vm_end) + return VM_FAULT_SIGBUS; + + track_pfn_insert(vma, &pgprot, pfn_t); + + if (!pfn_modify_allowed(pfn, pgprot)) + return VM_FAULT_SIGBUS; + + /* + * We refcount the page normally so make sure pfn_valid is true. + */ + if (!pfn_t_valid(pfn_t)) + return VM_FAULT_SIGBUS; + + WARN_ON_ONCE(pfn_t_devmap(pfn_t)); + + if (WARN_ON(is_zero_pfn(pfn) && write)) + return VM_FAULT_SIGBUS; + + err =3D insert_page(vma, addr, page, pgprot, write); + if (err =3D=3D -ENOMEM) + return VM_FAULT_OOM; + if (err < 0 && err !=3D -EBUSY) + return VM_FAULT_SIGBUS; + + return VM_FAULT_NOPAGE; +} +EXPORT_SYMBOL_GPL(dax_insert_pfn); + vm_fault_t vmf_insert_mixed(struct vm_area_struct *vma, unsigned long addr, pfn_t pfn) { --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2080.outbound.protection.outlook.com [40.107.236.80]) (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 E40E918EFF1; Tue, 10 Sep 2024 04:15:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941730; cv=fail; b=tHlMoi7w/u7/g+Z/fJ0R5cBNc4I2X44AgVSV2KsEaTz7P8WRnASfSDMGDyTQtETwCiu6far5HaqNySF7fQ2mJaGD+rDsaBwInlCQjS8ku2hcmX3m9GsI3aQNkGnQQjiqW/FDQZhImsnpal5vVtNc0BsLD9KxrF82znbLw08PlIs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941730; c=relaxed/simple; bh=ppN7AeQ535KjELJTEfxCfPobSJA90d14ZG8egdvqiEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ScDFU+8AMmJZuxvc67KpbgyglRWck8aJE+dujpHIT7EJa1ggkQmqtewMSITFJuERG1FFn2zWnhDOpPmqYTcJGJh5KZWzPgJLwTrqGX3zXgu8dLXnFzCWggHgG6N2NntURz2CQyK2jbrZPZwq5KncylKT93i8A5B2GW2jLX71Irs= 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=c+tZEiAz; arc=fail smtp.client-ip=40.107.236.80 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="c+tZEiAz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L+ZOssOVvz/rCwzeZHQ+U+uSHxq+lSEhcTcLXlFeBMgB5xmln6jLVmvk6gN8Sxu3fGljVMU9SgNATYMKe4xGYBTkNXAVLbPdQ2HYbhNRYovMRSliIkqlbKGbXvqSrmR8TWY/nUrert8KhMQPXZS7BnPJ3UeIhIVeJP7CX/QyM+uDqcTUnkvSNYEW9qK/Neoa4Q57Kr0Zg9Iy3hcLCiJIndZNTcgA2kY1nr2ZKZXzQVR1GjBDKcQ9wWu9H0/ytcP+KyzARpwUYuRXSQaejqM45P/I7kbjDcFBcJcpainAx2hZJEwgaLnD2hIrHjpCz118yCHqiRNgd9CGNoO3h0zAig== 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=3Bud1BOoIKrruKCTNC42zk12SQVHnS3DekPle0TBxIs=; b=uaRpCH7eE19YvM7Ok/2mao0rNEaVjvkDFnn8dqhyjdxlXiLd02pn7nqi6Q3/+RSx6LzQdcGtqKekmtrBG5fsK/n5QsG8+/SzCu2xu5w4U+oiJGfT2KepU6fU4HwWOdFcOrL7xscoR4MDNKlCJbWPZzvaLE0dGzob+BPPdySgQmdevr23knGoPBPaOEaN3yttmQ7Oo7gNOoh/5P7HpGmmHi6fUieOuYx7OnJun9sS72rQsN8RYL/WZ3Bd6A+zHBhal/TlwxpY7b7hz2jpqyjQTyDMzAOY2hzDlqD2IJyAsPSr+5f6BheqmdbLRHPx4yLKnX1FvsHOLx+kKS8MV1XhkQ== 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=3Bud1BOoIKrruKCTNC42zk12SQVHnS3DekPle0TBxIs=; b=c+tZEiAzjiLklX/B6fYH1x9f72oqj7xzPw8IYgdctTqzMSGm1me1F6er+CtYrn7Nd3KM+a3v5duYav2DaR4Re+jvD4Z6jsWKgeLRJPcVoiEWjDvWrlY+32ZafUBrCbKElkZBFD8YE1R2Qz4oX7IaEXQq8igDfW1122avvfxZINr1da1LvLXXLlmlQz9qX3zefPsjJdnV12KoIO+w8F8S5sI/jj5DFR8OrDgehgl/8HwBVSTZhF1kWHHJbHG3L+ycwN5Edp4WMA/RLm2cEKCt/vf+HYHNiEe5jpPLcOVzrCQz/SWOzcabfBb091rARlyfD7zOzxiYEexXldFZiKUvaw== 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 BY5PR12MB4148.namprd12.prod.outlook.com (2603:10b6:a03:208::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.20; Tue, 10 Sep 2024 04:15:24 +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:24 +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 06/12] huge_memory: Allow mappings of PUD sized pages Date: Tue, 10 Sep 2024 14:14:31 +1000 Message-ID: <3ce22c7c8f00cb62e68efa5be24137173a97d23c.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SYAPR01CA0038.ausprd01.prod.outlook.com (2603:10c6:1:1::26) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4148:EE_ X-MS-Office365-Filtering-Correlation-Id: e252b8ee-a36a-4332-0db6-08dcd14f3189 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: =?us-ascii?Q?8FLTFF1tbGPHDHObo9x3BBrfgQo0kcQ7btnVJnhqjc7/m3A5yePlGwc2rEZ9?= =?us-ascii?Q?aHYERs61AZrby39RJWG93aZIxXbP0YQvFpXC9ecx+1Bsw/y+GJDEQc16ryp3?= =?us-ascii?Q?Yvvo61j01Qvg4hjIZmEt3Xb0Tqaf1zw4WQ6j216vHEfawUbB1PEU9U9iONKV?= =?us-ascii?Q?Pzj/0DRjOVCoWVKD2fzlrxgsDjSOMVay77Eec2SmSiG78s5+W0nMXzRXGv6k?= =?us-ascii?Q?VC4/DwBY6b/q9yXhXpRRM5cKZHZe9gfTXiKgbFFV0EQEIYR4C7dp/di60lWS?= =?us-ascii?Q?FtYgYDO/6xI9xwJzIyYDgUkPayMWCDvYq3gWOLaitGyH8g52dwiMPLfqstQQ?= =?us-ascii?Q?Z9d52r+XiLLFmvO+HYoWBOcR+TG/h6SMOkkNwuK3FJoHHnQM3xsftPkJ8A5M?= =?us-ascii?Q?SCZLQaEwCBHKYChxnFVtlyh4e3xj+BGWOcXtpeXBwy023eo+yh6O9s/fLq24?= =?us-ascii?Q?3vGj7H0Of85nfcQB1crzyl0QjoKRjucXMBqKSrNHKjGqcPCEUM/8yLO7jtWo?= =?us-ascii?Q?XbRpnz2q5iSSRO11Ew4mmrwzPoxpHqwhX/kCiYNRuwfsvlvI8eBXLrW/nNGK?= =?us-ascii?Q?kqPTy/iKkbLDJyulfuFQHnIcGezzSnxsaQ1nkqI23k0Ek6t19kw8fs14y1m4?= =?us-ascii?Q?5yomrUH5ju8ROCsZU832JDevfe/MLLfIzUj5JciVPTYHBFb1ABGkqFg/5X4C?= =?us-ascii?Q?QXFgtXpwNPIjqfa6am8pJo5H0amUEPCIThrSxC+al1SVm5Lk0Msy7ugWo8P5?= =?us-ascii?Q?u1s+Yur7xRbo0wfyRVT8BWdox/Iyp9qHcPxfjVWVCM+loaud1jA1W2+NW3If?= =?us-ascii?Q?iLBEphrBjuld/qiyzN74PDRWHiD0SSAnNEfF8gh8BLZ//3sJky4de3IWrQVg?= =?us-ascii?Q?IHly0mAB7bIbI2jX5Mr9JvK9pKTZByVhP2FGarIGeabtHrgI0OX3GBpkP323?= =?us-ascii?Q?GZrTyYQED+FasdwD8VEW12cB89yed6v7Fe5Mjn77ppp8yWDasxkV0xFGJzM5?= =?us-ascii?Q?+H3D0dZQgZKcIQK27vX+RxVLkuVuHPZLdGj2joIAqSoa+l0bWMeJPoSenO/U?= =?us-ascii?Q?29xgBmb4JKpRRatVi8mp9AxjnTkWejZRctvDkWpwaA3v3DpWVWi9SVg8ivQr?= =?us-ascii?Q?F2DiuyLrE98XO8uR3GobuEZaMiuqZjODaNz3i7v0gBk3f6o0eeCxRpiQ5Vzl?= =?us-ascii?Q?WIaaI9o65a7VQo1h+Oiw2lz7+OPHuqbordZPfGhBNSfAJq4OpAg1DGpHdSA4?= =?us-ascii?Q?OzgR/cXIWhFCqr/5beOUiSW/0lpyKPxysgRw38AofSrQA0slxVaWzLTnXn8m?= =?us-ascii?Q?hESa05EaIGUcNAtVdx7ODjaoV8JWOXQB/WrsRxrhgnerog=3D=3D?= 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: =?us-ascii?Q?O6fAvEy50brguwa6iwu+iZg/Q160isc+uCr2WwThmEWKZ3ThvzTyqK7JuDdC?= =?us-ascii?Q?h43H8Jcw9tgeldm/NZO7xHtBG/jJaMqqHZFb88OqhscuGQACw7zfBFLIrznL?= =?us-ascii?Q?E0uvBYbe6OC5csAGfyeBdJ8UMXWFVDn8mNfvkAlQEEyTJOcBqU0dA20iP8C1?= =?us-ascii?Q?/mJ8iaU8hGGZ3DJWVm9wbNG6XFTieYCe+lA20/T3tULHdEM8/fDoK1W4dYIT?= =?us-ascii?Q?oLF/+UYPrnVJcmPRK4wKGZEayE/9AkpvRfhdS+GzGjBfKqFX+kRSF21J+R1o?= =?us-ascii?Q?na5/OMZWqjJAih0KfrKiSIGgGzQxuyMF8ln2MIJRy7pfJ2itZf2g/xhntSVZ?= =?us-ascii?Q?SsqP8aN/N+0X3A4JVsJ8Bw7T7h0luCZGQAPCMjrqU6iFCtY3vjkTGn0C+2L6?= =?us-ascii?Q?YR2jnsF7w6OWhb8FJwjMgq7S08ymIqf3moqKSCle9/L8ffAVLX90kKnP57WK?= =?us-ascii?Q?F+KX3UoTnUYWniHxVWLzPTP5vIpF/qaT66tA9lz/a+vtlA2jkUm3Lo5rpaiv?= =?us-ascii?Q?J3ebpJ5fWBkHNWZQsx4D+mSwWO3a/DpBrgmlu8KGfNwYlXbzYejwtqskn19I?= =?us-ascii?Q?mdgrNBMN4Gh0PkzYgrmtOnwKDOXjDTffJ5gEhbztwSqQw2AOh9I+VD3ZNxCG?= =?us-ascii?Q?7tISzTMxFAQDdxMNP8qEQ5/ClltPwfuUwm+faL+uDp5cDfumwhQD3W9SBx0i?= =?us-ascii?Q?muUQ1QDpul7RbzLvhdklNLLNyD5mmMd/I5tHorqdZQvz3Vuoi/uOtSZB3A/T?= =?us-ascii?Q?Op1RoweBonN+IHAsMO4pVsii1ELp4v3TO1GxuGvQe/bDQqjzwUquKbbHK4cf?= =?us-ascii?Q?eO5OI4hwOmuka0GngdcXxfGO5caGN7Hrc3XxszPuKsOIXjVNS9tWVt35Z/CB?= =?us-ascii?Q?w/bC0bfTMuFMdo8JeAMAcBb6p88DMkzoY1OKO81uox6QmqN5HaSr2YA8jxJo?= =?us-ascii?Q?QYzUF0x9vNxHHJTsdZgW4c6f33tr8qtZZy+gyx0hbRva3YWOu2d+p05sAdfK?= =?us-ascii?Q?TeN9M6KYzPtqKDXxPsKkeHxx2jkXCdce0svRKSeFpmerNRw263/3hGnQ5Uos?= =?us-ascii?Q?lvxzDGB18PtGaJqBYIfDs+lTVjhJ8ef5vQSGmBY8DchtEY70OljKO5N2If/t?= =?us-ascii?Q?JPKMQhBuytB8hdPtVgdvgu+S6YjsQegbayN77foeLz4Y4OgAuACzNZME/Wq/?= =?us-ascii?Q?LUAA8p6QI4w/GXm+mRdkrk3Gu1YbNjBPGL0qciLcJQT6Um2x1kC/IxPyEcdK?= =?us-ascii?Q?baoOQzRDDwAXv2JQEXH/KaPTk60LsXYVUvCB+hxzcjXsSTKC+HGUMQb7aVJn?= =?us-ascii?Q?rWxiIaRAtcU+gyvV5sIZMTCqmkMlp1ZZ1sjwZZcJXK5pLORP58jL0Ojf3sed?= =?us-ascii?Q?BfaBprF8GyUArO80WYI7znKjP5T962KlI+7tUA+uAYNnomou/j7//eo4ljRg?= =?us-ascii?Q?Hapf69fDLEijAoJCZ9G+0N+Cxh5aYvD8af650rGflL0TutmV2sOB5jJr7+IM?= =?us-ascii?Q?pSZaKuKimdSbu+AfEJU4GoZt0jUrSGr/91XRafqOj3QwymtB/R/vZOYHmneg?= =?us-ascii?Q?AeOR7gP1OWBvVZXqJA+EHmVtqeiAeORikr3s827p?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e252b8ee-a36a-4332-0db6-08dcd14f3189 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:24.6607 (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: 49ZJzoWF5ufNXqH4Cm0oPh90Eols0q5j5pF+TRPU7EQHNP4NqLmT5ez1M2NT5gSSsCLAd+aKKzzwbhaisvSJ6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4148 Content-Type: text/plain; charset="utf-8" Currently DAX folio/page reference counts are managed differently to normal pages. To allow these to be managed the same as normal pages introduce dax_insert_pfn_pud. This will map the entire PUD-sized folio and take references as it would for a normally mapped page. This is distinct from the current mechanism, vmf_insert_pfn_pud, which simply inserts a special devmap PUD entry into the page table without holding a reference to the page for the mapping. Signed-off-by: Alistair Popple --- include/linux/huge_mm.h | 4 ++- include/linux/rmap.h | 15 +++++++- mm/huge_memory.c | 93 ++++++++++++++++++++++++++++++++++++------ mm/rmap.c | 49 ++++++++++++++++++++++- 4 files changed, 149 insertions(+), 12 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 6370026..d3a1872 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -40,6 +40,7 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_are= a_struct *vma, =20 vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write); vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, bool write); +vm_fault_t dax_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, bool write); =20 enum transparent_hugepage_flag { TRANSPARENT_HUGEPAGE_UNSUPPORTED, @@ -114,6 +115,9 @@ extern struct kobj_attribute thpsize_shmem_enabled_attr; #define HPAGE_PUD_MASK (~(HPAGE_PUD_SIZE - 1)) #define HPAGE_PUD_SIZE ((1UL) << HPAGE_PUD_SHIFT) =20 +#define HPAGE_PUD_ORDER (HPAGE_PUD_SHIFT-PAGE_SHIFT) +#define HPAGE_PUD_NR (1<_large_mapcount); break; case RMAP_LEVEL_PMD: + case RMAP_LEVEL_PUD: atomic_inc(&folio->_entire_mapcount); atomic_inc(&folio->_large_mapcount); break; @@ -437,6 +451,7 @@ static __always_inline int __folio_try_dup_anon_rmap(st= ruct folio *folio, atomic_add(orig_nr_pages, &folio->_large_mapcount); break; case RMAP_LEVEL_PMD: + case RMAP_LEVEL_PUD: if (PageAnonExclusive(page)) { if (unlikely(maybe_pinned)) return -EBUSY; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c4b45ad..e8985a4 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1336,21 +1336,19 @@ static void insert_pfn_pud(struct vm_area_struct *v= ma, unsigned long addr, struct mm_struct *mm =3D vma->vm_mm; pgprot_t prot =3D vma->vm_page_prot; pud_t entry; - spinlock_t *ptl; =20 - ptl =3D pud_lock(mm, pud); if (!pud_none(*pud)) { if (write) { if (pud_pfn(*pud) !=3D pfn_t_to_pfn(pfn)) { WARN_ON_ONCE(!is_huge_zero_pud(*pud)); - goto out_unlock; + return; } entry =3D pud_mkyoung(*pud); entry =3D maybe_pud_mkwrite(pud_mkdirty(entry), vma); if (pudp_set_access_flags(vma, addr, pud, entry, 1)) update_mmu_cache_pud(vma, addr, pud); } - goto out_unlock; + return; } =20 entry =3D pud_mkhuge(pfn_t_pud(pfn, prot)); @@ -1362,9 +1360,6 @@ static void insert_pfn_pud(struct vm_area_struct *vma= , unsigned long addr, } set_pud_at(mm, addr, pud, entry); update_mmu_cache_pud(vma, addr, pud); - -out_unlock: - spin_unlock(ptl); } =20 /** @@ -1382,6 +1377,7 @@ vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, p= fn_t pfn, bool write) unsigned long addr =3D vmf->address & PUD_MASK; struct vm_area_struct *vma =3D vmf->vma; pgprot_t pgprot =3D vma->vm_page_prot; + spinlock_t *ptl; =20 /* * If we had pud_special, we could avoid all these restrictions, @@ -1399,10 +1395,52 @@ vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf,= pfn_t pfn, bool write) =20 track_pfn_insert(vma, &pgprot, pfn); =20 + ptl =3D pud_lock(vma->vm_mm, vmf->pud); insert_pfn_pud(vma, addr, vmf->pud, pfn, write); + spin_unlock(ptl); + return VM_FAULT_NOPAGE; } EXPORT_SYMBOL_GPL(vmf_insert_pfn_pud); + +/** + * dax_insert_pfn_pud - insert a pud size pfn backed by a normal page + * @vmf: Structure describing the fault + * @pfn: pfn of the page to insert + * @write: whether it's a write fault + * + * Return: vm_fault_t value. + */ +vm_fault_t dax_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, bool write) +{ + struct vm_area_struct *vma =3D vmf->vma; + unsigned long addr =3D vmf->address & PUD_MASK; + pud_t *pud =3D vmf->pud; + pgprot_t prot =3D vma->vm_page_prot; + struct mm_struct *mm =3D vma->vm_mm; + spinlock_t *ptl; + struct folio *folio; + struct page *page; + + if (addr < vma->vm_start || addr >=3D vma->vm_end) + return VM_FAULT_SIGBUS; + + track_pfn_insert(vma, &prot, pfn); + + ptl =3D pud_lock(mm, pud); + if (pud_none(*vmf->pud)) { + page =3D pfn_t_to_page(pfn); + folio =3D page_folio(page); + folio_get(folio); + folio_add_file_rmap_pud(folio, page, vma); + add_mm_counter(mm, mm_counter_file(folio), HPAGE_PUD_NR); + } + insert_pfn_pud(vma, addr, vmf->pud, pfn, write); + spin_unlock(ptl); + + return VM_FAULT_NOPAGE; +} +EXPORT_SYMBOL_GPL(dax_insert_pfn_pud); #endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ =20 void touch_pmd(struct vm_area_struct *vma, unsigned long addr, @@ -1947,7 +1985,8 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_ar= ea_struct *vma, zap_deposited_table(tlb->mm, pmd); spin_unlock(ptl); } else if (is_huge_zero_pmd(orig_pmd)) { - zap_deposited_table(tlb->mm, pmd); + if (!vma_is_dax(vma) || arch_needs_pgtable_deposit()) + zap_deposited_table(tlb->mm, pmd); spin_unlock(ptl); } else { struct folio *folio =3D NULL; @@ -2435,12 +2474,24 @@ int zap_huge_pud(struct mmu_gather *tlb, struct vm_= area_struct *vma, orig_pud =3D pudp_huge_get_and_clear_full(vma, addr, pud, tlb->fullmm); arch_check_zapped_pud(vma, orig_pud); tlb_remove_pud_tlb_entry(tlb, pud, addr); - if (vma_is_special_huge(vma)) { + if (!vma_is_dax(vma) && vma_is_special_huge(vma)) { spin_unlock(ptl); /* No zero page support yet */ } else { - /* No support for anonymous PUD pages yet */ - BUG(); + struct page *page =3D NULL; + struct folio *folio; + + /* No support for anonymous PUD pages or migration yet */ + BUG_ON(vma_is_anonymous(vma) || !pud_present(orig_pud)); + + page =3D pud_page(orig_pud); + folio =3D page_folio(page); + folio_remove_rmap_pud(folio, page, vma); + VM_BUG_ON_PAGE(!PageHead(page), page); + add_mm_counter(tlb->mm, mm_counter_file(folio), -HPAGE_PUD_NR); + + spin_unlock(ptl); + tlb_remove_page_size(tlb, page, HPAGE_PUD_SIZE); } return 1; } @@ -2448,6 +2499,8 @@ int zap_huge_pud(struct mmu_gather *tlb, struct vm_ar= ea_struct *vma, static void __split_huge_pud_locked(struct vm_area_struct *vma, pud_t *pud, unsigned long haddr) { + pud_t old_pud; + VM_BUG_ON(haddr & ~HPAGE_PUD_MASK); VM_BUG_ON_VMA(vma->vm_start > haddr, vma); VM_BUG_ON_VMA(vma->vm_end < haddr + HPAGE_PUD_SIZE, vma); @@ -2455,7 +2508,23 @@ static void __split_huge_pud_locked(struct vm_area_s= truct *vma, pud_t *pud, =20 count_vm_event(THP_SPLIT_PUD); =20 - pudp_huge_clear_flush(vma, haddr, pud); + old_pud =3D pudp_huge_clear_flush(vma, haddr, pud); + if (is_huge_zero_pud(old_pud)) + return; + + if (vma_is_dax(vma)) { + struct page *page =3D pud_page(old_pud); + struct folio *folio =3D page_folio(page); + + if (!folio_test_dirty(folio) && pud_dirty(old_pud)) + folio_mark_dirty(folio); + if (!folio_test_referenced(folio) && pud_young(old_pud)) + folio_set_referenced(folio); + folio_remove_rmap_pud(folio, page, vma); + folio_put(folio); + add_mm_counter(vma->vm_mm, mm_counter_file(folio), + -HPAGE_PUD_NR); + } } =20 void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud, diff --git a/mm/rmap.c b/mm/rmap.c index 1103a53..274641c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1180,6 +1180,7 @@ static __always_inline unsigned int __folio_add_rmap(= struct folio *folio, atomic_add(orig_nr_pages, &folio->_large_mapcount); break; case RMAP_LEVEL_PMD: + case RMAP_LEVEL_PUD: first =3D atomic_inc_and_test(&folio->_entire_mapcount); if (first) { nr =3D atomic_add_return_relaxed(ENTIRELY_MAPPED, mapped); @@ -1330,6 +1331,13 @@ static __always_inline void __folio_add_anon_rmap(st= ruct folio *folio, case RMAP_LEVEL_PMD: SetPageAnonExclusive(page); break; + case RMAP_LEVEL_PUD: + /* + * Keep the compiler happy, we don't support anonymous + * PUD mappings. + */ + WARN_ON_ONCE(1); + break; } } for (i =3D 0; i < nr_pages; i++) { @@ -1522,6 +1530,26 @@ void folio_add_file_rmap_pmd(struct folio *folio, st= ruct page *page, #endif } =20 +/** + * folio_add_file_rmap_pud - add a PUD mapping to a page range of a folio + * @folio: The folio to add the mapping to + * @page: The first page to add + * @vma: The vm area in which the mapping is added + * + * The page range of the folio is defined by [page, page + HPAGE_PUD_NR) + * + * The caller needs to hold the page table lock. + */ +void folio_add_file_rmap_pud(struct folio *folio, struct page *page, + struct vm_area_struct *vma) +{ +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD + __folio_add_file_rmap(folio, page, HPAGE_PUD_NR, vma, RMAP_LEVEL_PUD); +#else + WARN_ON_ONCE(true); +#endif +} + static __always_inline void __folio_remove_rmap(struct folio *folio, struct page *page, int nr_pages, struct vm_area_struct *vma, enum rmap_level level) @@ -1551,6 +1579,7 @@ static __always_inline void __folio_remove_rmap(struc= t folio *folio, partially_mapped =3D nr && atomic_read(mapped); break; case RMAP_LEVEL_PMD: + case RMAP_LEVEL_PUD: atomic_dec(&folio->_large_mapcount); last =3D atomic_add_negative(-1, &folio->_entire_mapcount); if (last) { @@ -1630,6 +1659,26 @@ void folio_remove_rmap_pmd(struct folio *folio, stru= ct page *page, #endif } =20 +/** + * folio_remove_rmap_pud - remove a PUD mapping from a page range of a fol= io + * @folio: The folio to remove the mapping from + * @page: The first page to remove + * @vma: The vm area from which the mapping is removed + * + * The page range of the folio is defined by [page, page + HPAGE_PUD_NR) + * + * The caller needs to hold the page table lock. + */ +void folio_remove_rmap_pud(struct folio *folio, struct page *page, + struct vm_area_struct *vma) +{ +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD + __folio_remove_rmap(folio, page, HPAGE_PUD_NR, vma, RMAP_LEVEL_PUD); +#else + WARN_ON_ONCE(true); +#endif +} + /* * @arg: enum ttu_flags will be passed to this argument */ --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2073.outbound.protection.outlook.com [40.107.244.73]) (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 B1298190046; Tue, 10 Sep 2024 04:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941735; cv=fail; b=LrSnx5lwW2DasKPfs7gnqAuupdynByvyRu5fxJTWTgQe7g1iGbRzdR1vzjDUrrOv8v9NqsyPXIZWEt1W3ukOp/pBNzqEbZKcQehylxT0qPClvTRdDb7FTNtUimcBCqscOpYcIdH62h7G+2gxtrfZCrxysWDweX59ri7PhMukdcs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941735; c=relaxed/simple; bh=p0r7xPVvMVqZHyjPXqe3z5FreSJZ/CBWsj9olNpyk1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=IcxKhj2RFZva1mrzXZurBvguum7OFFhyf/28O0YjxP7BvUzk6tRmxdffLU44XoM1QgUv74ex6GdLH7YRSnqoBzTwjX9Kg78lb1Q8NlLJHUJUMRDjWjQWQNgBpFEXIjfgAKhmGSuJLhXrtSW/81I9KWC+ZguUbJHcRAthcgI39Ck= 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=RFFG+r3Q; arc=fail smtp.client-ip=40.107.244.73 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="RFFG+r3Q" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u9TGGWrJRRAxIUWc0H03/Qy89CiicDsvu8TH5ylhM2nAsQhdSq0shaRdGEa1RbNTHDtCOUT6Ui3SRDYkLRX7chT4PD1xWecND9WtA7aH2DMJbHjO15MR2m/3zAFtGEQ8fF1ieP0uC2Cg+MdwYfVq/7CUUY0jNYkxddp4SXrOPJ7y2eZIB0uUzC93PYiImgVUTS/0l7UF3FqdqHug0YRLcgzmarsmQJ6ohFby9xw/BBpi8BLxk4igIruT67yLnqheESxnEnrld+Lfk97QzMzPDPj0asrlUb0xP6fhXv+I266FuUEDXe84t8za+gMSthovYeWsduNrmPRse6RBxNMtlg== 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=ItcM8EpGZKlhlFXvZ10jl4KAPka0zJ1t+4ANNPAc2z8=; b=haOQQGR3DNshxoUVfQ+PWw1jsQl3eFhYCg1rl1RFqTcXkRaf2fi7WxoadTSBE/uGnMyG5QwUIjrGMs77dkjWMheXfntIae7ccgWOJRs3K983tc4K8GroDwHBJRC8CBpKDKgf+9XdUYjVDdDiOG6992bD9QamMGZC03ITI7JNMcAolOyf9roqLBWAD827xp4JlDxig6p8UQqsqVB9W7PuXEMn2uLG99juV2Q/9NWW8GLZqBPGdwEX/2SPQ+34KR5reZhNNq7GYBdpBEuXat9oqZXlAyadQrY6XfxoXhWcVQKz/JsBrLj2x1hU/X26V5bMLmB7/aDaoqtCJdrYdekgHg== 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=ItcM8EpGZKlhlFXvZ10jl4KAPka0zJ1t+4ANNPAc2z8=; b=RFFG+r3QyVbxX0P0Acghf98y1J6eymXn6eiwPD7EhtP+8Oo1/4nZHL3lMD2K5HnoNUKS5Wnhsizbj/sPW1kfFLYOfQktCozwQQRDiXrObbgQdmkcGw9hQXFvEXjlgpmHbE08CSZqiUndVzoicehQD+EjByEOXZUZHgB/4RqyPW5D2dvBD23VltzD0HY4LjmAaeDA1auF+KLZEBW8LBj/dynuYjZRdeWpqChAqPeZI7du757SXM7NHGUJnvp7FDJG/XOxlwiZ/ecveY1fr5mbJomVOq/4S1qJZykTVxK8AVCkfUaCH0B+8+frA0L1Xz6dzOQu0kTiq2ImO3BpK7FZYg== 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 BY5PR12MB4148.namprd12.prod.outlook.com (2603:10b6:a03:208::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.20; Tue, 10 Sep 2024 04:15:30 +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:30 +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 07/12] huge_memory: Allow mappings of PMD sized pages Date: Tue, 10 Sep 2024 14:14:32 +1000 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SYAPR01CA0046.ausprd01.prod.outlook.com (2603:10c6:1:1::34) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4148:EE_ X-MS-Office365-Filtering-Correlation-Id: b139175d-3b9e-4e2c-ea1c-08dcd14f3503 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: =?us-ascii?Q?qSRf7qDFt8xvMAXNJwCg0p+jjeHoeQN8+Js4UWbPFYDXKXNrSvDaWQXKf8pO?= =?us-ascii?Q?vAGzAFFnJytfOReYi2v+pBJkT3dM+mnSeWe224nTftm0RjFa2MuFPNEiVzLV?= =?us-ascii?Q?lqkEKbBcmr0cbGnR+hEjT2ZaJdQ67ZFi2l/F9wiKPd1apFHc50r8/2LZuvZp?= =?us-ascii?Q?RxbLMq67a3bhqAdYaMXF4zef1izCU5Q4/++ObUH/vZ/+WVJhHtcbsYSuUDAc?= =?us-ascii?Q?H2W91IUIp58pDmZh0AuUBVNlYs/0Ijizp0eu8BLXBHgnivBwHcEfpjDmC6G0?= =?us-ascii?Q?I47vUpxgr+kSCugxmWdiGp9PYEdgkvAQWp6hJuKm5GAwRrqBJpLQGhXwb9Uy?= =?us-ascii?Q?AnGjXWEzALGhfm5cdIod7JKeXTqsOViV4Nxnw5h0hYsslEGbzkJmkmpEpA7p?= =?us-ascii?Q?lm4WESNCmuSti2vda9As+B4v+lYWfEgg9qieb7l7z5ji47z63XsRLy3lSegO?= =?us-ascii?Q?ZLpkavNiBJRg7GuJiAPQvqcbOv/4y8nFiatRRBDtt4IAk6l3JVCr7HEEIXay?= =?us-ascii?Q?DiqaevCOUKYywfmTFddWujjK7W7uUfOCDSQeUO26rQafaPpL6bPOK2LAKLWP?= =?us-ascii?Q?eWK5PIazAvm2oQ8pNJi/mQOtojHDCbdL+32rp6SC4GBHUAkHzsDAfl15VIQA?= =?us-ascii?Q?z2aySUc7BlAmwh6V8d35nRPwNV2ZR/sNRMOl18jSZU3XjDg7xb/7j2pjMEYS?= =?us-ascii?Q?w/3o7vfg3eEv5ojb8CE4DbZewpUj8KW/q5ZByHraiIh2wb7eagTCXAF7aMIC?= =?us-ascii?Q?/iBXv0C7ARrs4g0BZYHT+YU8SH/mVgw1ka0FzPJTo4PbrKWQT0cGA3c9mAxz?= =?us-ascii?Q?ynyMrv41HwPOV3zS76vY5VuCKl57BWNppjN7y/Z9QGpQ5vH5eHxWPhpkiXUy?= =?us-ascii?Q?i2MkqpUmMGxiMf5KSEutv2qu088u6RRLMZW10a9qiYW7xx0Yv32yoAsBLoFe?= =?us-ascii?Q?my7GO5ob54B8QmK2Ahi9+/3guF3202Z/mZ51ZA4DAkoKr39jS4BKXo9mCWKs?= =?us-ascii?Q?4zMxK2yFifQUK9hFJrYEmBLN9/9HU7DnFMm9sYmExGa7QOWToYy5WRI5lEhf?= =?us-ascii?Q?vowjaHlvFM3NvF4RFa0D46MoJFThud0x1qDgKE8OZCLXWqWjQql1sXzgD2mI?= =?us-ascii?Q?30AZZUyNknn7qhN2wTM33sCrtXeBecfRg+fsV+nxh1t3Iw/IuiV90LykxnCF?= =?us-ascii?Q?TfXJwnaVcClx4b6DQvygG7HV6Vc9Vj+y+zA2vShjtf7B4JO3Z38clIVs79BY?= =?us-ascii?Q?/dT0l4kxg5jjIiEvPn62+PDjPm/i5JtMMfNqmZ8QBRZbGYEZO0KaNnEaYFAK?= =?us-ascii?Q?Gfpff+/2NSiTh6+VxNAYap5hBAjpUH24wMSuqVOG+5M3xg=3D=3D?= 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: =?us-ascii?Q?sFRNX1Sl7EXocfye4Hj2Apxs/vv4ZJvWgo/yDRCnT7968OusMCDwmNborBC+?= =?us-ascii?Q?BuO+69sM6rMkx2cwMkhBeth29XOTZhdn9VVT+oPYhMnRRX1qYZcERUC3AkLd?= =?us-ascii?Q?vFgXzOI7AXTsHuCPV56B39SEVwqk4ALecNiJdoSFv+tECTAOOwCDEWT57mom?= =?us-ascii?Q?tFGhtWxxBPmlBwY+F5cjmz2IBbCWSPnsSaa5iB1IygY4JCaGmeOYrA8p1JSC?= =?us-ascii?Q?f6LWMjZkn1vRCObvOOTZ1eXDy+ZtxSol1hFOBzXK2z7zTpVNj7HoXq9XBr7v?= =?us-ascii?Q?DmhPCp5xqJW+IZdVwpeNmbbFsjq7nodhxuIMY9/E5SmhR9fejB+wEJIgFOrh?= =?us-ascii?Q?O2yk7/EAme9NZxbbPDESxmyms+6ABHOBi+w/lV5yrDQwZqiTn1obTrykHP7y?= =?us-ascii?Q?BXZGpn86Lmsm7ltM87mdUpYJ4dGPPS9V4zvCMP0YPKIvR6ZDhyQVu5sOyKoa?= =?us-ascii?Q?ujxNcQGvw1YhDWnO5Xmkn08MNMvtKaS20cIeWfODvCjR0RAdgOlGxkZXSdop?= =?us-ascii?Q?yNwWG8IKJBq7+xx4GAibq1Rl/vGJAhX5HYFG5eqaAL3y9LY6hm5YiDexW7cL?= =?us-ascii?Q?cyaHZxM5uMqxuxEqAnlpsyxzPCn+YE3DWi+iL29KgeQX26+yaN0Dw/PYjbs7?= =?us-ascii?Q?ihqcLl430pvURMIuVpNB9ZVg1jzh9gCX/SnMyIbJY8GldXWKboWBDCgg+8vQ?= =?us-ascii?Q?8j8pIzVRBj86Xye3H7D6yMJ10xLjY+gyACc42rm0l70GSZbKnvcAfXHJqVgZ?= =?us-ascii?Q?MhQRFHdylrE0LiNpRvimVO/07Y86z3jCtNr1au+LjD4NtTYq+viOS0bWScvg?= =?us-ascii?Q?XvaU8URfUW3i26aZSeIwQCLo8thqgcUI1FuogLGnxEFmrSiDcvGhWUk00/GD?= =?us-ascii?Q?vr+kMxN6qMGLnA/wcJhPe22+TY1kq0zsHPAtgWCR3iKOJ3SA+BUIcbHyt/Dm?= =?us-ascii?Q?z2UjI90s8nmwOUpTHtqDp4Sxk+6tWOCabS0ersx9MGRDVfd+9OuZ68vmH5eW?= =?us-ascii?Q?5tXSQQ1pKbMISSsmrtZsmbzDBRtz5EkuMAMOJXSuRdq0I/zqxZRrjM5FZ0tQ?= =?us-ascii?Q?AgQ0w1nItuVm3kvTvqmBOLThax5qXQI1MePTl25TArSR4hcvTutOc6HyU7mC?= =?us-ascii?Q?pLKVbJCV5P17eyBN6scjtMZfkmupsWxxt4qKA/wd7KuKIi/sjBSZeo43dJrz?= =?us-ascii?Q?MeTkLbxltbcJGt8sPKhCqM8pEXsRfjW1ljwvJu7suS3dAdCnrBpzbKQjwP01?= =?us-ascii?Q?T4fuBV/vVpNZoRHlTuodbwGkLclpROT5P2UYubowf2R13JMIUxi/LdgQ4pdG?= =?us-ascii?Q?UFZpekwZeF2qfiB8IXwOAxyc54DxT+tYwPyCbg+s1poJKGou84jNpJb2f3lp?= =?us-ascii?Q?mOEn1lftNnpg4uzmlICiTS3RSZfSPPQr2LhMJzYE1TCQ8QPHBhLWIECm6Sc7?= =?us-ascii?Q?85prsgnpjKcvXP1LwcJHvQmm3/VZoSteCY5Md8ustIVolIYefGmOS1s1TvLi?= =?us-ascii?Q?ubZ1tDqFD6mQ6oOx/VNEnwjebGYzUO5dV1k87eGnGv6oPvZQYqkY3vKTyOuY?= =?us-ascii?Q?8hRAe66fwiI/WFht8B2LsSBg5YO2edNyHsEawsTs?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b139175d-3b9e-4e2c-ea1c-08dcd14f3503 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:30.4787 (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: hHC8+DlOYjhRod5vWNyyQZeQ67SvJaANrbVN7lz0epJCBkXqP+OcCtofVooBYis+/gswvAOOkb0QI6v/j0Y6Bw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4148 Content-Type: text/plain; charset="utf-8" Currently DAX folio/page reference counts are managed differently to normal pages. To allow these to be managed the same as normal pages introduce dax_insert_pfn_pmd. This will map the entire PMD-sized folio and take references as it would for a normally mapped page. This is distinct from the current mechanism, vmf_insert_pfn_pmd, which simply inserts a special devmap PMD entry into the page table without holding a reference to the page for the mapping. Signed-off-by: Alistair Popple --- include/linux/huge_mm.h | 1 +- mm/huge_memory.c | 57 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index d3a1872..eaf3f78 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -40,6 +40,7 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_are= a_struct *vma, =20 vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write); vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, bool write); +vm_fault_t dax_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write); vm_fault_t dax_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, bool write); =20 enum transparent_hugepage_flag { diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e8985a4..790041e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1237,14 +1237,12 @@ static void insert_pfn_pmd(struct vm_area_struct *v= ma, unsigned long addr, { struct mm_struct *mm =3D vma->vm_mm; pmd_t entry; - spinlock_t *ptl; =20 - ptl =3D pmd_lock(mm, pmd); if (!pmd_none(*pmd)) { if (write) { if (pmd_pfn(*pmd) !=3D pfn_t_to_pfn(pfn)) { WARN_ON_ONCE(!is_huge_zero_pmd(*pmd)); - goto out_unlock; + return; } entry =3D pmd_mkyoung(*pmd); entry =3D maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); @@ -1252,7 +1250,7 @@ static void insert_pfn_pmd(struct vm_area_struct *vma= , unsigned long addr, update_mmu_cache_pmd(vma, addr, pmd); } =20 - goto out_unlock; + return; } =20 entry =3D pmd_mkhuge(pfn_t_pmd(pfn, prot)); @@ -1271,11 +1269,6 @@ static void insert_pfn_pmd(struct vm_area_struct *vm= a, unsigned long addr, =20 set_pmd_at(mm, addr, pmd, entry); update_mmu_cache_pmd(vma, addr, pmd); - -out_unlock: - spin_unlock(ptl); - if (pgtable) - pte_free(mm, pgtable); } =20 /** @@ -1294,6 +1287,7 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, p= fn_t pfn, bool write) struct vm_area_struct *vma =3D vmf->vma; pgprot_t pgprot =3D vma->vm_page_prot; pgtable_t pgtable =3D NULL; + spinlock_t *ptl; =20 /* * If we had pmd_special, we could avoid all these restrictions, @@ -1316,12 +1310,55 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf,= pfn_t pfn, bool write) } =20 track_pfn_insert(vma, &pgprot, pfn); - + ptl =3D pmd_lock(vma->vm_mm, vmf->pmd); insert_pfn_pmd(vma, addr, vmf->pmd, pfn, pgprot, write, pgtable); + spin_unlock(ptl); + if (pgtable) + pte_free(vma->vm_mm, pgtable); + return VM_FAULT_NOPAGE; } EXPORT_SYMBOL_GPL(vmf_insert_pfn_pmd); =20 +vm_fault_t dax_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write) +{ + struct vm_area_struct *vma =3D vmf->vma; + unsigned long addr =3D vmf->address & PMD_MASK; + struct mm_struct *mm =3D vma->vm_mm; + spinlock_t *ptl; + pgtable_t pgtable =3D NULL; + struct folio *folio; + struct page *page; + + if (addr < vma->vm_start || addr >=3D vma->vm_end) + return VM_FAULT_SIGBUS; + + if (arch_needs_pgtable_deposit()) { + pgtable =3D pte_alloc_one(vma->vm_mm); + if (!pgtable) + return VM_FAULT_OOM; + } + + track_pfn_insert(vma, &vma->vm_page_prot, pfn); + + ptl =3D pmd_lock(mm, vmf->pmd); + if (pmd_none(*vmf->pmd)) { + page =3D pfn_t_to_page(pfn); + folio =3D page_folio(page); + folio_get(folio); + folio_add_file_rmap_pmd(folio, page, vma); + add_mm_counter(mm, mm_counter_file(folio), HPAGE_PMD_NR); + } + insert_pfn_pmd(vma, addr, vmf->pmd, pfn, vma->vm_page_prot, + write, pgtable); + spin_unlock(ptl); + if (pgtable) + pte_free(mm, pgtable); + + return VM_FAULT_NOPAGE; +} +EXPORT_SYMBOL_GPL(dax_insert_pfn_pmd); + #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD static pud_t maybe_pud_mkwrite(pud_t pud, struct vm_area_struct *vma) { --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2072.outbound.protection.outlook.com [40.107.93.72]) (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 41E37190674; Tue, 10 Sep 2024 04:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941740; cv=fail; b=WmbF0gS2fBUyN+ukvw2WzQN85pfjVYqcjX8CsWJdx2/SzTQTUKXHIH+0BHMR26bQKI+qrROjO9Mq08h6FB5UaW1Ml6scwSFCrRdfGzP0MfSI7bOZ4Ps7AGEjw4RAJiegBW2IQdhrAIRZzAv4Vi8tGEWO6aW2Enguc8BwXN6lYYs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941740; c=relaxed/simple; bh=Rml4FOtNZ4oTMo+4SWtnuHmUqWSdD0HggTagsoup7w0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ZYSMZxaTSJFrp7r/6OkMdONENI2x6BJl/qaFPOBrQXNDtqhvKPPDtRjGjFcmA3jR22xYZh9f5Jv0AYecA1Ir59ItiLx4MVo3hzhyFySRBaRLT0kz0vTxX0qBuMdFMb9sEEmyiZgstPdGzYKYFTktQPTHhYzCEX4QzYoGrFj7Jgk= 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=hS2ezw8+; arc=fail smtp.client-ip=40.107.93.72 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="hS2ezw8+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rZBaqegP2yi+3HEsP5rP6SWphwz0NgmuPRKqrcTPzQlqnnh3rxwQmvb84jqzI1SbjPS4kUO/QlRQsJ6MLHWt0LxgW+7OX3skfETvioHYu+PZ5fJEEO2IOPHQXIOTVBKkYy2ZkWzyfj3B73HaaFwuVizL9VP999w11iCLDUWfoAXw4diIdttmgedwKCeICTkkGUmcy5hU1fDI0qWwrh3maYP+UuOUbTXnlhH59h1fK5PSbRt1WGsyxR8K0BQBMsYtxecvwy7GNRAW6RnEMJ7x0HX2+we9n/F0U/mfzite7Jo3tG0EfG6NcTnjyhEDwkXh9xn5p2cwCT+q3Wn8yG/YjQ== 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=mmVmguBDaPXZcKaagi7Z+K991/nm44PK190JdcuA+tg=; b=Zu69LGT0mUtrJOIupd5Kd12sG2ToT+DA0LEDol/NJkfmUXQAhi77jG2aW+tCXhT/ueYA0NKSSE8NUMrMvZirmpgdjI5ofx5T+FQpqyUcxCDYBHedhdvRgQcIhDq54+rGnBoZ/di9UqqAEWkNyNt4t+1FTZQgfGQZd3in1q6KAy8SRzrtkZhyZhxEB2BS24hZftW+Qmu4ByymLIFNguUqhwexIVTGRnl0Nn4RLpTqIxySai0uAbrLyHnEDDzWq5PCHNOVqPp5b93iuD4Ny7uQcyIHb9t/qRXdiNt0Kz+Rs3UnBJqdKtcpIA5Fyrfz6VyIxn8QOmsyvP2aRsfaz2VL3g== 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=mmVmguBDaPXZcKaagi7Z+K991/nm44PK190JdcuA+tg=; b=hS2ezw8+I+MLJ2F3SgAVUJQTBaY8y53MZtqrZeZxcX2nQo91JgDlnFL86r2bv/BSZz2Uwl3hhaAvoA0BDzXVkErE/Vw8Lsozm92KvTHu3byfQBs621gdxv3yBLCXfwPp41dspzVRXac1XfJjVuFbfQmNf9nooGYtIqdSmZqnMBx3b2+xXobjxNCfspvjdPMflapjdL3HASWIn0g32EKbpwvVU8UwJhIqUSVUrAlsAUv0C1pTtXVAuzbu5hp8bPSRNxZJkZ7BB+/PyN9lgFUPkyEMRvhHod1R9/P+SXZSKfZiNMMUMFT+ELQ/eZldE/0U6RLNXucHlTK8XP2/D+GqrA== 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:36 +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:36 +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 08/12] gup: Don't allow FOLL_LONGTERM pinning of FS DAX pages Date: Tue, 10 Sep 2024 14:14:33 +1000 Message-ID: <78b49fc7e0302be282b4fcbd3f71fa4ae38e2d5f.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SY5P282CA0110.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:20b::15) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@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: 2d92a199-4c00-4b0d-b7c4-08dcd14f385b 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: =?us-ascii?Q?N+IfuPAs7XaJc3M9yDU4ghwimT9Ez+RziZdYS1X3rruWJD4fMmspjCzE1uSU?= =?us-ascii?Q?Qr4fBQ4dVyFm1RsBHjsVBHRNFlTXdwFRkoldYQGdybvNVo+iDqO14q0nphPU?= =?us-ascii?Q?wwcnXqRTjYIsgdr1zlSWOjCn9NRu/km9Ng0KuFVaPVnXuYS4xv+3vNSTLGAn?= =?us-ascii?Q?ddF5eH2Hdg0qcNWoPOLKDjz2H3pDO3+IU586Ku2fJDJS0/StNJsG1y8U1eEX?= =?us-ascii?Q?53svdDpFXQ5Kj5DIMKa9MnWzLYZegzg1hjy3/nj62BYMvHtIIKTBWWKiIxnj?= =?us-ascii?Q?cZxowChsLSOUlQDzmx0+E7uJwrX4Bvn+mxs0lRkzRA2p3L7YzgiOHE6//g4E?= =?us-ascii?Q?3PSf2/nVf/ZeFmKDSdoctm3akAu6WoC2GZoUqzftJx4e4A8ULZJlgYrNoGTQ?= =?us-ascii?Q?RvaVxV7SXmHmQRHmUEC9khEFdkYSku+++muyShMfBRYDCEQBH6PBG3RgRl0R?= =?us-ascii?Q?oFfJhOZfS32GWaAPWEuIVbzYPH3WLWIhdtov9NiEkE9IqtsvLSW9NvtPjrYS?= =?us-ascii?Q?ZQUccQVZbTHanfjmMbZH9Erfo5ZArnyqGmtzQanpxquQtpeM17SUU1X6nxec?= =?us-ascii?Q?ModG/2Nfh1mzm0M8x9UcsApV+AoFzJDq/VTm+Ugn0L91UA2HpuhdYGtofY0h?= =?us-ascii?Q?EsGhl8s1U7oaoL9IosofhNodm60cNLAQRqQ/IC++yXWm+Tz+anhqXyU/yubC?= =?us-ascii?Q?ujEDeEUGe4Peg77GomhRaryzTi5ID43t4AVIAVE8upYOWgQYXfaazTyTPewR?= =?us-ascii?Q?abwoxfI7q75HRK82B4lLAs/6ZxrGJYcrq/wn5Bz0FC02w3clztW4czPJboVU?= =?us-ascii?Q?vAWfcrQAzfHyFINCkMh7Ypkagmwt9wl6zwBWNjdD8sam6+WpZsK7qYDZz0Lo?= =?us-ascii?Q?rwyXycTjtru0k+TMlRA66Sa6IJ5YZQdkDeRebjOZt4WQGK2lahXUzOWyRK9i?= =?us-ascii?Q?PpVxg76OSiKDFUBV4KeUdRKXk1CeBbzdNwYzXgd9owAw4Vat7QF474ojoiR5?= =?us-ascii?Q?dwvqalPZ5oAcFIYEk4YjwlmHXG473ZsfuCyM7Rm4OzxCICA+8zR/UTrAFeOB?= =?us-ascii?Q?v326iwG9dQWJKoR0QvUCygu/5GTD+VzDZA/RwVWxq1QACdQeD/irKyroqXvR?= =?us-ascii?Q?AiAHhhImO23T6FSHiddV7bdN5omJrFoldaziiqcE+JpPgpwVuxDDSzPOrNrr?= =?us-ascii?Q?3NCG3SKBkQZdA617tUBdFiazZnDy1kj+lvVqWM0ywLSRdwy1SKsoBQatjbN9?= =?us-ascii?Q?5/SAvsxDP7lVOocVKKQSr5nDEnPr687ix2a/sUjGXtNwIYdEXmRKwFbvbEn/?= =?us-ascii?Q?H9BU4OpzPLwasj5OrHsPiVQxC2AA79eCo8qitcZ5ooKQcQ=3D=3D?= 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: =?us-ascii?Q?z5lgFlHP7AzaYSp3mkzVPbqYuTtAeWoEg1C+f0xOkrXprZR2ZkBCc28IqRn3?= =?us-ascii?Q?ORx9CgB53vzROsRRMtgtC9bOfvfS90Tx3rWALkBm/g8KrozgWe1aIjhECrLZ?= =?us-ascii?Q?PgdxrAt29U3J0GVap5yzyEzcZcqqd43B4FuNzNgUyWNvqJBVIzhqBX1lYv4x?= =?us-ascii?Q?8Hpnps7jTVnpukr2hisq8M37qauC/GHK1iDxXcjT08W35a8jZD0acWWIKbL+?= =?us-ascii?Q?6TTqliv96vLIOHnmfWxJMyZT/4qNTVC+PyMYuaSS7MhaYds6YthfivGeP7YK?= =?us-ascii?Q?d55HM7NT0glcxd3g0ODW2++LYAJLUxmZnXEnNdmsN2jEMMad13HJU3A++TLE?= =?us-ascii?Q?dbMVhydYFvjxiP6GgN/JQAla9TAPkSaih1x7/50wXXX5fToB4DlBr9F9mt1/?= =?us-ascii?Q?kU09dSUvbrZqUb1qJC1FvAabUhgcQIe2inaQYX8RB1kpDoAmgoOnsgBKAbx1?= =?us-ascii?Q?jhlaGYZ65ZK7Qosa4Fw7I+jetlzko+pyOUqL5IQ4JrAB6Rg7cXPGaYB7it7H?= =?us-ascii?Q?Z/qfMRKdXYUo8M5uzYGi0BAZ9bhLMVqfK5EkZoPN9YKz7mPCmKiypcOQKKsD?= =?us-ascii?Q?uERRasrT7PXpfQlz+RhcIo9JejwrIi2hyyOhgETyrxA7/fYwEZ2mgTo4YLTF?= =?us-ascii?Q?1e8ULhdoes77tyXFIH9hjkfv4lJnneBaeYUSqihWUiwT9fMLeAVVSZgVJ5hg?= =?us-ascii?Q?9u5bePDOcZ0J0QziFx1gBZ0i50fvoDOfTgTzWi3Tk3cjSg4g02sPitgum/67?= =?us-ascii?Q?XoBXjCh+oYYliZiE42Ua0VSeJYrAu7iPSk4jnZnzCffFtE66/pnxQkaEpFsO?= =?us-ascii?Q?kQr6xahDuS3FjLXXulKcRfbnK1Q4DlvQhANwjNqAsVhHgHTdroYUUITTaWbG?= =?us-ascii?Q?NFIyxGpzOgMdxZzLvM7fVFfTipRYSHYKeGBgUdPMUZ/yPP+PiIsipDtUiEdH?= =?us-ascii?Q?bNJ54tTmpi4CQMHoG1hLCjjrBfX/B8rd3cZW8X/T2W6HXa8gWyuQ4FU+iC5u?= =?us-ascii?Q?HR/tMn1tQ0nF8JLtrh6J17Slb2oFg9K+Xcf8sKnLu7G6CVFHDf4d6mcmduVM?= =?us-ascii?Q?YIOHG3MobcCVuCHq9JXX3v28OVBCDHjRnPbTuEZL8JA97uXeT6KDeJkUCnHT?= =?us-ascii?Q?hP1N3ZVdyEJOYWEkgsRDoO09+bYtCZELWQinb26QLYqm+1mqufiyXq9KpRqI?= =?us-ascii?Q?MYBm4G92Kbmhi8bogdWLePblI4Y0SRb0hmyKx4+61AC0S49nkeFY8iqWW/fA?= =?us-ascii?Q?iTpVkQSAqNYzY8aG3GoFWaxkXVXeHKzDDxcgeSjzLYiWFKk78yCIGIW9oBmr?= =?us-ascii?Q?MPBlQqjhCKm3pumDCUUO7mNH+P4AYY82n9MfH7Gi+kLNlJXdqhC2PIKGVwgd?= =?us-ascii?Q?nU3mzpHBEMW7bwFaSPt4fwDKZseUBT277HO/ejjRjZk8Th24+SZF8jRtf9eJ?= =?us-ascii?Q?VqYMCm1d61dzM2FOtsGt4OQedwG0RsKJzKQfjtt0V6mU2W1cJAmoTu3hOQCm?= =?us-ascii?Q?IF8NsCzwYxPoPGq8awIHfpA2VgKFCGRvWzgz1LP7S9MsGOsuzfoSogrmxKAt?= =?us-ascii?Q?9x65Cd8c9QSUXfEYE2UIPo9gGIXZk6qhJDc2z7mU?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d92a199-4c00-4b0d-b7c4-08dcd14f385b 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:35.9036 (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: tCSFupX6de5G6UEizforjsXwcCeAwCCJKj9mo9MljSe1339BjRIwjChs0P15VJepMRxtgE5Zl6tg8OZDyndtOA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8088 Content-Type: text/plain; charset="utf-8" Longterm pinning of FS DAX pages should already be disallowed by various pXX_devmap checks. However a future change will cause these checks to be invalid for FS DAX pages so make folio_is_longterm_pinnable() return false for FS DAX pages. Signed-off-by: Alistair Popple --- include/linux/memremap.h | 11 +++++++++++ include/linux/mm.h | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 14273e6..6a1406a 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -187,6 +187,17 @@ static inline bool folio_is_device_coherent(const stru= ct folio *folio) return is_device_coherent_page(&folio->page); } =20 +static inline bool is_device_dax_page(const struct page *page) +{ + return is_zone_device_page(page) && + page_dev_pagemap(page)->type =3D=3D MEMORY_DEVICE_FS_DAX; +} + +static inline bool folio_is_device_dax(const struct folio *folio) +{ + return is_device_dax_page(&folio->page); +} + #ifdef CONFIG_ZONE_DEVICE void zone_device_page_init(struct page *page); void *memremap_pages(struct dev_pagemap *pgmap, int nid); diff --git a/include/linux/mm.h b/include/linux/mm.h index ae6d713..935e493 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1989,6 +1989,10 @@ static inline bool folio_is_longterm_pinnable(struct= folio *folio) if (folio_is_device_coherent(folio)) return false; =20 + /* DAX must also always allow eviction. */ + if (folio_is_device_dax(folio)) + return false; + /* Otherwise, non-movable zone folios can be pinned. */ return !folio_is_zone_movable(folio); =20 --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 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: Content-Transfer-Encoding: quoted-printable 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-kernel@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: =?us-ascii?Q?p0/XSu+j6RC4amQIub1I+NvbR/EvWujIS4R49iplf0dgWgY29I8KiQVttazJ?= =?us-ascii?Q?oBkrxoGLPyml53b6bJ1gqCMw0FlE77JVFw5g+qhWlK7s9OG6K9uFI8ZX8DMv?= =?us-ascii?Q?j9BeFt4rsj9Xj2VJPpfqVtwSuzHWhee4WPsWnbTePWI65dqs5NyHTcDOMXxV?= =?us-ascii?Q?uTLmCUZfVyD+Q9s4n+dRb7ZenPhZe3aB/wuNu91ORvUJPhZ0qocJ2pdBE5LG?= =?us-ascii?Q?fmvdSeSim/xN7lRJ3Q3vJ5rfa8S+hdH6LgZ2lEAtgVz+CrrOBRVnMbdz9U01?= =?us-ascii?Q?drvYAztD95VSgzbXHvDemyXKY7nYr25dm6SpM+4KEw7BhvRisHrp0ne5aqtR?= =?us-ascii?Q?goS4pLAzzT+2Pf6lG12osuhiqyfVijzNUYrOmvbPAD5V8P3cTU2QFjn5pW1Q?= =?us-ascii?Q?/rda3eU8+F4MRYTzRVMrIRtFGMbtmz7gS6tyGuYeXa5ViA4nqFgemLkb0FAC?= =?us-ascii?Q?LtK3N7nNiLSwG4/jMm0VnfN5jolL/wJ6vB9qTSeb/85zct/QHpEctigmFZLN?= =?us-ascii?Q?llzvclZCu01w5ghKGowjgmQIQlV2lAW0iSSBoRdfGlkBlA+jkTirf0s/b/P/?= =?us-ascii?Q?pK8SKLdYMUsmyXlcv7z5YT7gT2l/osdBnMQlmNgpgj5YkvaTLtqag9xrtM9e?= =?us-ascii?Q?OEgnqK4JV04vo/cpN5yDiNUzirRHm/3ba8h4HcXC580QYclgNDEGKlO6Hcqj?= =?us-ascii?Q?FMCmHzcLKoDLCqIfhLZTxQ2FE05W43j5JnflqteswDo9dOT0eZX1j8WLXAed?= =?us-ascii?Q?YAPyleQrCp92BCehpoEq9kFKpy7r64c0k56CuhQm2fP8uF+4t+j976aH0sO/?= =?us-ascii?Q?UPrUMDXZq+bPqqkqKXzh/OryjL4VfpsAO2c99nRFNRytdtcJ6gZK8iY6uQy0?= =?us-ascii?Q?R62NXaviR5RdhCFEsuVtY9TzDYvohbHgG0BzoswvMF6zjwc/VP5/TyuXd/4Q?= =?us-ascii?Q?YZffBN2G+oO+9JOdXDwCPNB+oKzM8YGYRrgbM/230dkZMSZ/FA07JkQrheLV?= =?us-ascii?Q?OXGiMzwtwBb/uvHV3lRU0fHbBYRm+Z65vMg5oNuRJthLWWOA2XPFaakAbNh/?= =?us-ascii?Q?W21J538v/I0S4LuM1mWBhBeGuZI1bIBWwex5WOjGzP4t52Q1qNNdnqCM0e2x?= =?us-ascii?Q?y0cewCoqNxR8VOuDwNm7LlIY6uiEqqZ5/0Nh8cOwn0t27SojAdQkRSR3T0kg?= =?us-ascii?Q?5vThwHBk9uRnoDj0TrN4DyogtS6UYH4HPLeg4nalq4V1/p9hnjGF76ip3gSa?= =?us-ascii?Q?qhPAeICgKIMTLFtMOMJMx7LbzpfmGUrd8riPT7vfa9R0Wj/3ZfPkMKhada/C?= =?us-ascii?Q?2lFLb+imdLwoKTha62TGzKxvtDLcU3VyZxznCg/vTlrFfA=3D=3D?= 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: =?us-ascii?Q?/pHOMGGcH0XJuO5Wsr+OtYTbWqAxzCvfpUql0taa19y8j8xA43gaFKaZf+ji?= =?us-ascii?Q?g6m7IA+g89wyglmxqBnQJDWfvrJUnbxJSTCuTm95nlhkTDk5XpntEnPtgpBR?= =?us-ascii?Q?AhoJXf9uQXsj6HZ8Jogl5pnI6pvhB0NiBjk5NXSpCu3OgUTEaYlEdVFhkJYt?= =?us-ascii?Q?eGmP8E8gL55Le5JhNEzRaJfhMYjgSYEKLFN7h7CCAYcp/AiYUSgtL59Nt9cX?= =?us-ascii?Q?246SglUrDpTSIc/aI7rU9gOZ67NeCL3GGW3uQyKFWOk7huxyItY54ggf7/k4?= =?us-ascii?Q?mRx+O0h953do6vnWbKjsLAoTAGwNkssJp9STNWyt8Z2wt8n+Q441PfzaruBt?= =?us-ascii?Q?tfHuzEvMiSsZPt7Qo0c2Zy2W4let81cKof+p9OJ+7xnnXMlnESgdg5I8Inu7?= =?us-ascii?Q?t412PnOyfjp+BchXSoAD2Bgt1RybN+IFBoEl+ia9D68JOSxl8P0/rrXK9kQX?= =?us-ascii?Q?k/Bwy813soeC+/MA+D4hkSieowEb+exoq0iWQyQMwplurYOXy1rlsLWX4jvW?= =?us-ascii?Q?Ax3jRs31QQr2pNE9YVGoF5ZL298JDJmdr1qG15ODoVQqVPTymc9DIMePtsRr?= =?us-ascii?Q?53YuqZXk0CQtJCk7qsD+dK4QSjXSZ88/G10Lzk/2CaJIK87mo5f33PRlpp4b?= =?us-ascii?Q?EMFBv2BVYLK51tQ2KNdoeED9PfDC0ZKqTGIQPcTnq9fnsqsyHpPCtO+nsp/W?= =?us-ascii?Q?rnhjqP6od1NatHdYjbO7v36YUkWfIovyKVJsakK9blPhcXjBbWgy++W33bCM?= =?us-ascii?Q?bSNJzaAA3uWTJe37OASyR9KJLZMopaYZLi2nJwFY3xrklQDKIIEaGgwVCPIW?= =?us-ascii?Q?rntPPzJodAHdKOwrX0XMzOBNAIHBi3WxNgu/TdY+McwVE17gCOdzLKyxqP2f?= =?us-ascii?Q?574B2kcsvoJC+J1bl5QPVupcNwvAUbNfBuNUt7b3OM2YTrigyFnjaIXOHCRe?= =?us-ascii?Q?jfPySagz/9eTdKo1NCu6EoSA3NcKQdMBNZPI4zA60LHxAV9jaNbWAvXRL/wp?= =?us-ascii?Q?r1iKv4JF/clcFT3k4tpuCbT3tKBch7d9S8KKzfDIwslM+R6IpB9jnvZVQkc8?= =?us-ascii?Q?Cz6A4qJ2Msm5HEpOd3sAwbxq34RNdgxu9P/f3ereyKbuae9tY574IPnawrXB?= =?us-ascii?Q?jNpo7szcktxcB8bRqc8A2BmLLlR0zLCDqb+NPQz56HBdV67t9pbIAwM/io99?= =?us-ascii?Q?O1EGSpI1WjgrJGQj/VuF/oSJGtK8fbXvHM/I50Hl3oKznkgMRuLveMKHfqV6?= =?us-ascii?Q?h+5ufOjfzMRNVx/GGPx8VtKqn1IbtkDWQLO9ZPpRdl4IeiVUDSc/ia7WBej4?= =?us-ascii?Q?+nVjXisUirGGZ7ZW9LbcbUAbHdNyM9aG31uFr703dJjBGC684kgdqtoR22K1?= =?us-ascii?Q?M7Bd6MMhZdItKa8872K/D4yNmhlGE2EeDdGENxbju4v89F6FI+R2IRQ69L8K?= =?us-ascii?Q?xuJfNUnFy55NKB1qnf1odz2cl782kN3JiNYleo3vI3247kWlSsT7QfyhhQjf?= =?us-ascii?Q?dZh9IXisJiLfrhptVkMVwG6efpJzqvA98qcZBDGi6DY8+orzhAQyFSRd+esa?= =?us-ascii?Q?5qbvBz7IVOYLLF0L6rt6nIM499dTW22cOyceY54b?= 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 Content-Type: text/plain; charset="utf-8" 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 siz= e) 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; =20 @@ -960,7 +961,8 @@ static int follow_phys(struct vm_area_struct *vma, unsi= gned long *prot, pte =3D ptep_get(ptep); =20 /* Never return PFNs of anon folios in COW mappings. */ - if (vm_normal_folio(vma, vma->vm_start, pte)) { + folio =3D 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 a= ddr, =20 if (pte_present(ptent)) { page =3D vm_normal_page(vma, addr, ptent); + if (page && is_device_dax_page(page)) + page =3D NULL; young =3D pte_young(ptent); dirty =3D pte_dirty(ptent); present =3D true; @@ -864,6 +866,8 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long a= ddr, =20 if (pmd_present(*pmd)) { page =3D vm_normal_page_pmd(vma, addr, *pmd); + if (page && is_device_dax_page(page)) + page =3D NULL; present =3D true; } else if (unlikely(thp_migration_supported() && is_swap_pmd(*pmd))) { swp_entry_t entry =3D pmd_to_swp_entry(*pmd); @@ -1385,7 +1389,7 @@ static inline bool pte_is_pinned(struct vm_area_struc= t *vma, unsigned long addr, if (likely(!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))) return false; folio =3D 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 pa= gemapread *pm, frame =3D pte_pfn(pte); flags |=3D PM_PRESENT; page =3D vm_normal_page(vma, addr, pte); + if (page && is_device_dax_page(page)) + page =3D NULL; if (pte_soft_dirty(pte)) flags |=3D PM_SOFT_DIRTY; if (pte_uffd_wp(pte)) @@ -2096,7 +2102,8 @@ static unsigned long pagemap_page_category(struct pag= emap_scan_private *p, =20 if (p->masks_of_interest & PAGE_IS_FILE) { page =3D vm_normal_page(vma, addr, pte); - if (page && !PageAnon(page)) + if (page && !PageAnon(page) && + !is_device_dax_page(page)) categories |=3D PAGE_IS_FILE; } =20 @@ -2158,7 +2165,8 @@ static unsigned long pagemap_thp_category(struct page= map_scan_private *p, =20 if (p->masks_of_interest & PAGE_IS_FILE) { page =3D vm_normal_page_pmd(vma, addr, pmd); - if (page && !PageAnon(page)) + if (page && !PageAnon(page) && + !is_device_dax_page(page)) categories |=3D PAGE_IS_FILE; } =20 @@ -2919,7 +2927,7 @@ static struct page *can_gather_numa_stats_pmd(pmd_t p= md, return NULL; =20 page =3D vm_normal_page_pmd(vma, addr, pmd); - if (!page) + if (!page || is_device_dax_page(page)) return NULL; =20 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_are= a_struct *vma, { struct page *page =3D vm_normal_page(vma, addr, ptent); =20 - if (!page) + if (!page || is_device_dax_page(page)) return NULL; if (PageAnon(page)) { if (!(mc.flags & MOVE_ANON)) --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2085.outbound.protection.outlook.com [40.107.220.85]) (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 CE58A191F9A; Tue, 10 Sep 2024 04:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941753; cv=fail; b=IqQUqTx8h7KeRU7tH/ZcE2sa+3+5x5JO/2OH/nCTQDbowF4lQnHQRGMTXAHZn0f1K+UoncfpklnI5Uncy7wA719JoRQ8LaeVyliI7JS1FaajICgNL+JjKvTIKk6waLwNAbO2U4nvfnK56Uc5fKz+KFUasbMHzksONQT8gAMbNvw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941753; c=relaxed/simple; bh=qQZJ7LjvsCObk463rIVzaoMAPIn/bx4qdokv2exctIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=bFO2Y+DcJ7y33IQOeqNA7FNmCOupN4uOCV2Fe2m3RzIKWCY1fR15igpsHRL/0/xUZIF2tQWyMMwe7Tq3lA4Fl2Wr8zTpW3mMyrMxgTcqscpAtV3sTuszRjFSnZJCzc//cxg5B9r29K4M7r4i9n+ayy2U/9wmb6O4E+vjymoJp4s= 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=VAe7+ilB; arc=fail smtp.client-ip=40.107.220.85 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="VAe7+ilB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bv1eMEtDlfpwxRmVVRQL/F4b6ik99OVq7gcdga8i1NwbY7/pqnBlROLHwIstTfKkE9mZdKXWZVj6WZwWHiSSOcEFyDcn0QRjjt7BFYo7t/oG9DwSt11JABEam8YUV7PSW5eD/SekKKEK5DT4wFyrCByqTHetANGFi0ju0F0GKiAWwh/gY5MVK+79EXQr+zM701cl02FujeVStqMjiqg8yZyhZfPKspQlQ/55uhGCJgpl8x5JTG/luozw6FjyKX0qNSDD8VIP7kBJc42LLdka8ULruWgaKZj8AE9ePcJp3W8XTn/VuC42s4fY981PGi/z9QnUNL5FPn48oJX+5E6+PQ== 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=KxsaXxCobkebjzMmd7orGk+KwMiRdngzL78EWeSmELI=; b=Roqfms1SJmml2uoGOVR5j4x3kzRsilNcWvKcayddOyCS1c+xOgrut4Q20IEZCLICReAf99ArxyH+aiDrqkO3JTUOjT5Rrw6GNbMQomipCRCCi57zfiwf6C7PnapuD9KrgWlhr5KIgrQ+rQWIK88+3U4B24o0xQSvK6zl+oIG9AMFl8e8y4JwFRlsLpNKvrwmlLmw291KuBwYkdZnZ/KAtoNFf9W2sdFmB0WvioWt/f2Q5yeaPltMi7K4hrtrlR2rFlWNiZseFmHDsVY2d4lZqBO78FTzRJ1rQkHaAVnEy9k25M154vNwf4darjFLsMpodG1iSrwNXBXSODsr1ABHLg== 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=KxsaXxCobkebjzMmd7orGk+KwMiRdngzL78EWeSmELI=; b=VAe7+ilB6z7OvL2rlBsSW39Ih+m5CO1Hw8rsqyk7nI/yvyPGpOckJi8cOhdtkHagC0bPr/GrqCMqQ4dowNFHVofITf4Fp9VpXkQUFI1XhsnBDqpgpSsJ20X6dXJR+hwFcc66pfgulKk4MXqCJT4ce7P53gReScb7vI6A8+tNbUfK5Pc6A250QO0NTN4hO/E51xxIT6x6bhLlJsfq4s4ZKo/iz5n+uWwIpWy11p+2OF33Pga+Ifif8LX5fwb3Yiom2QbXzaG1o/IaWu3m5k0IikOZkUVEWDYLWhvuqsyoi9LL6KJq0pvyelrfrWPjry8IGBrtqlsnAdhgN1vH5yw2jg== 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:47 +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:47 +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 10/12] fs/dax: Properly refcount fs dax pages Date: Tue, 10 Sep 2024 14:14:35 +1000 Message-ID: <9f4ef8eaba4c80230904da893018ce615b5c24b2.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SY6PR01CA0082.ausprd01.prod.outlook.com (2603:10c6:10:110::15) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@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: 611e0f79-913b-4c28-42a0-08dcd14f3ee7 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: =?us-ascii?Q?8CiSMj5pK0SlWAHNC/J6vVfa0y5qcwlpZXjSI2KG7wipzNiQGIXjTu/Bc72u?= =?us-ascii?Q?srwLLmrG+2Zl4CxNuYcr6gfHTuyqj67f+aDweFhsUh+b33g2VU9hz56jOBjT?= =?us-ascii?Q?CD2mZjVZGMen4PyRG0C3BslGLOTP+1aM3L+hEdoIEBCe9kwpYU3WZ3t8nlFw?= =?us-ascii?Q?mRGpkl/7kZok20S0Kh1KxH1kF/Z8WpB8U6YXSwyvAnM19dkpE1i0ilPDA7/B?= =?us-ascii?Q?saXaVIaLIRjGuBuc+oDNKp7m1fa4KCKXH0gnRjJElV+INv6aARqAeRFLKp72?= =?us-ascii?Q?LHjs0+Tvhw6De4eH4+hInqSr9FwEPqsHDFMJJz5c89urz2gGErK9x8n181zN?= =?us-ascii?Q?NtSqoaYow03W+J/xPlSWCiBNcGZIK9qq5+mBnsxzGRFsxVDVQLxpi/kP64tk?= =?us-ascii?Q?ui2w/sA6yzvCHqrl0tka72gSXQ5lnGZ9Gu1Wsy8NiSDFyIw5IDAPcgiAfrXn?= =?us-ascii?Q?Wp5KQk7H+CVGY56OQru5zx5iDAg5lFMu9emmyGzkUGZI+R6Ct80jauOeifu2?= =?us-ascii?Q?oz97S7wwHUllFgGaiK61kMouRawJNUCnNYOjLVSx2H7ZDoD74rn1OGdQyftJ?= =?us-ascii?Q?hNcdMahah/bO6P4PkjkDfZeM5Zuve9Sln8wqEBjl9jjy5Rk3etjv4INgwb7K?= =?us-ascii?Q?U2TA/fJTAyyuNlRvbOFVlI8M7vnnBmFa+yB1S4dAQXgcuaFIxDegfR3VWU+g?= =?us-ascii?Q?J3cwgYV1MhsxNISF1MBvDweWfzCXOMtM6pty8g/4tx6bK4yC65rS4xpbdz37?= =?us-ascii?Q?mrJ3AdkWSMLMp5csn/zZ+jq91dTOHa9wS5yNTPNV63OC1tBVIcnR8ab6QqBT?= =?us-ascii?Q?l0ZX4orKlpwzOqLFcCUqVchmFaSRwn1QuJZeb33K39AYYzEXFxk2CyE8PRtm?= =?us-ascii?Q?ktXQfRohm8RoAvtl7Uec8a5tIzQH+auVlV0KAkiHfEqrSZcNh65VP631b/zO?= =?us-ascii?Q?1wTZ6Hp2Yf+v1E0lcAIhVpcs5WRPqBbEQiCd4NMer9O9kdi1nAQqmDVXczEB?= =?us-ascii?Q?ulGY8hEjbUz8nQ3utwmJTYcloy6u0Vd1nyo2BHNciQ7wOR0skyaBvRr5MZG0?= =?us-ascii?Q?moiJQG1Yb/TnMb4dWtuRm5gIGv1fTIpPU9yS/tYEwuG9AAeF2QKv0RVtqGAO?= =?us-ascii?Q?LRV2SuZnFhEkFsNmfK7L/Mb+tyWMxpKIsdRFVE1EFQM29jfh8P8fvQtuTNXD?= =?us-ascii?Q?5uMerCItrdqKphBIgEV1IvpQcLvD+A/YvAZ4F8MUVeQHcerm/8XOYA3mmWPZ?= =?us-ascii?Q?u/fQXbpnASHfh9vS343u4kW3s0IccrMa18Evby798a6Bhzm7dmsdt5ywf/TP?= =?us-ascii?Q?FMWl6kYGxWC3zbceL+B0CEMHJ9FPpkn6wy5ICk5SwBDbtg=3D=3D?= 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: =?us-ascii?Q?/t/M9I4z9PudY7sqaVCuj6nygIGp3Q1ilyeC2fjQoAl1zDORGXtBB0o1hhYP?= =?us-ascii?Q?dWFqCPuxE/Nzaeh+cUWs+udDBdRuPHY7SutFPEuhTCAPMkK1YphqmF2tnBWm?= =?us-ascii?Q?YC0vYkWgXWja9iOKj+iTIaqrN9Zllml93iP+V5krtrk7b33wnR6AtXXNw9Mo?= =?us-ascii?Q?b8mZQuK7r/Z1RyQ+r/B5NStaz/cMG4JPt9oXbQDfc/LEMjNx5MaKJUHVSCcX?= =?us-ascii?Q?tukQSQCKI43hczMQ/mLRffxGmQ3lzNGNK60e+UbjX+QHnvV4GPzYCHeOOryS?= =?us-ascii?Q?EcClswk+Et6ir0QwH8Ibijj19QH3qBERMJPqQlZIJLcyPrUOYjtpm6zRmSfc?= =?us-ascii?Q?Z4L6hGQckyMzVNxMzeQz8sSx9tPKKh5nR+lCTTbYN83nFQMJeRP13x2fNQZ2?= =?us-ascii?Q?M04HALyfeYo4p1JftuYJJdO1jhBn9XK8Ndq+GORfbB1Yi5khgETh+jQNTXrV?= =?us-ascii?Q?U52o3ll17t6p7JWzu6jd6jOMqJw7K4D5QrMpF/iciEWUQkyGy0IRgsnvDuvY?= =?us-ascii?Q?HHpaCzOQoY5HYhkTK2nbu9aiDOiTqQUxKBrbvZMhd0YswDt87gWqXHzvZ0xP?= =?us-ascii?Q?o1v3dxwY2mvdPZ2/clt9A3EXskY3REffZzadAAMlAri6N+Rzd58jGAXGfthF?= =?us-ascii?Q?s0JPeNkVDcZ8c1fTc+pBKuIgHuZjSxxwkdvNRp4uJBWfHDFfnunDkCy12kuB?= =?us-ascii?Q?3br/TacNMEC8tsIw56tX6QdMBitVKwIjb4L+PdMUaf/DvaziCyrWp5WEQMVj?= =?us-ascii?Q?inmvwGE1PFpW59yOKxGLAB+2Xs9KjA/KSzHeA/TJkpQoibhYtDWeAZo9jyBB?= =?us-ascii?Q?v3Iaf1u6A8fMaYnodyf5A/DKvk+MCfSGD1etedr9H2sdNtIiZ6Zg8+ZZV/Uc?= =?us-ascii?Q?FJfszhFYeecN8+9BjOv7w9S1GOPSJD7qCzcNJHOnKOjto71BmQNY/Ynb83fe?= =?us-ascii?Q?B4NHD5eJWfTNPH+AN/zEkJcCwyPFZCcFMMKdeU8dUisU636uqWVM0mVh58Sv?= =?us-ascii?Q?Tm+LYj8exoi5QOCzZGs8AVSqgtXdJWY6C/qcb9iJhRnHVfBSltJhYe7QC92r?= =?us-ascii?Q?mYBJQwEdoZTIERQddoFlLtphv/RJupDWqOUdXGGUXol8ZZ3q6Y0wnqjQkhg9?= =?us-ascii?Q?ECm8bA8kT7+NGohVy5rj9Hynx+sp4lMEEAV/4ntYc8uD2yG+CB3fuO7kzkzF?= =?us-ascii?Q?m37X1HrmXAOICkXmxG0hXHDdyjVWPzmHqmo4lcNI72FGxUJSO+3XC0qEoPcd?= =?us-ascii?Q?7uGJWS2afrT2UB9LBDoDiXRamLWi/lAsA/aEONL1CMha+UuyaXARTrBMoNrL?= =?us-ascii?Q?EbpCi0KT+BPgDIT1/8wEvVYDZn8khxZm4FUSobhcInwYGD20EELcbj9Nu3EJ?= =?us-ascii?Q?iqYEGfJto5GSwKkLEjCFGuQEP2F1NIPjCYRSaEaNtl0C204N/N+JouDQJOUs?= =?us-ascii?Q?7+QUnfVFBCreP8L//TlZDx2K3761NR/dQ8FTR2nsSsG+pjkxT6cOBmCk0nQ9?= =?us-ascii?Q?yhKCtRFxbpv+ExbqDd357QQR8O1xnsigg6q65ivL4SUCmPVK2PUzOtEro/84?= =?us-ascii?Q?GctPM6gXlx/BHHkC0enH0Kw04H5DkRrMpx7jXbln?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 611e0f79-913b-4c28-42a0-08dcd14f3ee7 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:47.1060 (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: 6bHQ1HixT7YqhUYTDrJoaNgIXlbYoZbYsb5xx78mgcESH7YlQWps2gKTqDItZGBMoW+7JWKGk6NXYZZG7ek2nQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8088 Content-Type: text/plain; charset="utf-8" Currently fs dax pages are considered free when the refcount drops to one and their refcounts are not increased when mapped via PTEs or decreased when unmapped. This requires special logic in mm paths to detect that these pages should not be properly refcounted, and to detect when the refcount drops to one instead of zero. On the other hand get_user_pages(), etc. will properly refcount fs dax pages by taking a reference and dropping it when the page is unpinned. Tracking this special behaviour requires extra PTE bits (eg. pte_devmap) and introduces rules that are potentially confusing and specific to FS DAX pages. To fix this, and to possibly allow removal of the special PTE bits in future, convert the fs dax page refcounts to be zero based and instead take a reference on the page each time it is mapped as is currently the case for normal pages. This may also allow a future clean-up to remove the pgmap refcounting that is currently done in mm/gup.c. Signed-off-by: Alistair Popple --- drivers/dax/device.c | 12 +- drivers/dax/super.c | 2 +- drivers/nvdimm/pmem.c | 4 +- fs/dax.c | 192 ++++++++++++++++++-------------------- fs/fuse/virtio_fs.c | 3 +- include/linux/dax.h | 6 +- include/linux/mm.h | 27 +----- include/linux/page-flags.h | 6 +- mm/gup.c | 9 +-- mm/huge_memory.c | 6 +- mm/internal.h | 2 +- mm/memory-failure.c | 6 +- mm/memory.c | 6 +- mm/memremap.c | 40 +++----- mm/mlock.c | 2 +- mm/mm_init.c | 9 +-- mm/swap.c | 2 +- 17 files changed, 143 insertions(+), 191 deletions(-) diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 9c1a729..4d3ddd1 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -126,11 +126,11 @@ static vm_fault_t __dev_dax_pte_fault(struct dev_dax = *dev_dax, return VM_FAULT_SIGBUS; } =20 - pfn =3D phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); + pfn =3D phys_to_pfn_t(phys, 0); =20 dax_set_mapping(vmf, pfn, fault_size); =20 - return vmf_insert_mixed(vmf->vma, vmf->address, pfn); + return dax_insert_pfn(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); } =20 static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax, @@ -169,11 +169,11 @@ static vm_fault_t __dev_dax_pmd_fault(struct dev_dax = *dev_dax, return VM_FAULT_SIGBUS; } =20 - pfn =3D phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); + pfn =3D phys_to_pfn_t(phys, 0); =20 dax_set_mapping(vmf, pfn, fault_size); =20 - return vmf_insert_pfn_pmd(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); + return dax_insert_pfn_pmd(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); } =20 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD @@ -214,11 +214,11 @@ static vm_fault_t __dev_dax_pud_fault(struct dev_dax = *dev_dax, return VM_FAULT_SIGBUS; } =20 - pfn =3D phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); + pfn =3D phys_to_pfn_t(phys, 0); =20 dax_set_mapping(vmf, pfn, fault_size); =20 - return vmf_insert_pfn_pud(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); + return dax_insert_pfn_pud(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); } #else static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, diff --git a/drivers/dax/super.c b/drivers/dax/super.c index e16d1d4..57a94a6 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -257,7 +257,7 @@ EXPORT_SYMBOL_GPL(dax_holder_notify_failure); void arch_wb_cache_pmem(void *addr, size_t size); void dax_flush(struct dax_device *dax_dev, void *addr, size_t size) { - if (unlikely(!dax_write_cache_enabled(dax_dev))) + if (unlikely(dax_dev && !dax_write_cache_enabled(dax_dev))) return; =20 arch_wb_cache_pmem(addr, size); diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 210fb77..451cd0f 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -513,7 +513,7 @@ static int pmem_attach_disk(struct device *dev, =20 pmem->disk =3D disk; pmem->pgmap.owner =3D pmem; - pmem->pfn_flags =3D PFN_DEV; + pmem->pfn_flags =3D 0; if (is_nd_pfn(dev)) { pmem->pgmap.type =3D MEMORY_DEVICE_FS_DAX; pmem->pgmap.ops =3D &fsdax_pagemap_ops; @@ -522,7 +522,6 @@ static int pmem_attach_disk(struct device *dev, pmem->data_offset =3D le64_to_cpu(pfn_sb->dataoff); pmem->pfn_pad =3D resource_size(res) - range_len(&pmem->pgmap.range); - pmem->pfn_flags |=3D PFN_MAP; bb_range =3D pmem->pgmap.range; bb_range.start +=3D pmem->data_offset; } else if (pmem_should_map_pages(dev)) { @@ -532,7 +531,6 @@ static int pmem_attach_disk(struct device *dev, pmem->pgmap.type =3D MEMORY_DEVICE_FS_DAX; pmem->pgmap.ops =3D &fsdax_pagemap_ops; addr =3D devm_memremap_pages(dev, &pmem->pgmap); - pmem->pfn_flags |=3D PFN_MAP; bb_range =3D pmem->pgmap.range; } else { addr =3D devm_memremap(dev, pmem->phys_addr, diff --git a/fs/dax.c b/fs/dax.c index becb4a6..05f7b88 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -71,6 +71,11 @@ static unsigned long dax_to_pfn(void *entry) return xa_to_value(entry) >> DAX_SHIFT; } =20 +static struct folio *dax_to_folio(void *entry) +{ + return page_folio(pfn_to_page(dax_to_pfn(entry))); +} + static void *dax_make_entry(pfn_t pfn, unsigned long flags) { return xa_mk_value(flags | (pfn_t_to_pfn(pfn) << DAX_SHIFT)); @@ -318,85 +323,58 @@ static unsigned long dax_end_pfn(void *entry) */ #define for_each_mapped_pfn(entry, pfn) \ for (pfn =3D dax_to_pfn(entry); \ - pfn < dax_end_pfn(entry); pfn++) + pfn < dax_end_pfn(entry); pfn++) =20 -static inline bool dax_page_is_shared(struct page *page) +static void dax_device_folio_init(struct folio *folio, int order) { - return page->mapping =3D=3D PAGE_MAPPING_DAX_SHARED; -} + int orig_order =3D folio_order(folio); + int i; =20 -/* - * Set the page->mapping with PAGE_MAPPING_DAX_SHARED flag, increase the - * refcount. - */ -static inline void dax_page_share_get(struct page *page) -{ - if (page->mapping !=3D PAGE_MAPPING_DAX_SHARED) { - /* - * Reset the index if the page was already mapped - * regularly before. - */ - if (page->mapping) - page->share =3D 1; - page->mapping =3D PAGE_MAPPING_DAX_SHARED; - } - page->share++; -} + if (orig_order !=3D order) { + struct dev_pagemap *pgmap =3D page_dev_pagemap(&folio->page); =20 -static inline unsigned long dax_page_share_put(struct page *page) -{ - return --page->share; -} + for (i =3D 0; i < (1UL << orig_order); i++) { + struct page *page =3D folio_page(folio, i); =20 -/* - * When it is called in dax_insert_entry(), the shared flag will indicate = that - * whether this entry is shared by multiple files. If so, set the page->m= apping - * PAGE_MAPPING_DAX_SHARED, and use page->share as refcount. - */ -static void dax_associate_entry(void *entry, struct address_space *mapping, - struct vm_area_struct *vma, unsigned long address, bool shared) -{ - unsigned long size =3D dax_entry_size(entry), pfn, index; - int i =3D 0; + ClearPageHead(page); + clear_compound_head(page); =20 - if (IS_ENABLED(CONFIG_FS_DAX_LIMITED)) - return; - - index =3D linear_page_index(vma, address & ~(size - 1)); - for_each_mapped_pfn(entry, pfn) { - struct page *page =3D pfn_to_page(pfn); + /* + * Reset pgmap which was over-written by + * prep_compound_page(). + */ + page_folio(page)->pgmap =3D pgmap; =20 - if (shared) { - dax_page_share_get(page); - } else { - WARN_ON_ONCE(page->mapping); - page->mapping =3D mapping; - page->index =3D index + i++; + /* Make sure this isn't set to TAIL_MAPPING */ + page->mapping =3D NULL; } } + + if (order > 0) { + prep_compound_page(&folio->page, order); + if (order > 1) + INIT_LIST_HEAD(&folio->_deferred_list); + } } =20 -static void dax_disassociate_entry(void *entry, struct address_space *mapp= ing, - bool trunc) +static void dax_associate_new_entry(void *entry, struct address_space *map= ping, + pgoff_t index) { - unsigned long pfn; + unsigned long order =3D dax_entry_order(entry); + struct folio *folio =3D dax_to_folio(entry); =20 - if (IS_ENABLED(CONFIG_FS_DAX_LIMITED)) + if (!dax_entry_size(entry)) return; =20 - for_each_mapped_pfn(entry, pfn) { - struct page *page =3D pfn_to_page(pfn); - - WARN_ON_ONCE(trunc && page_ref_count(page) > 1); - if (dax_page_is_shared(page)) { - /* keep the shared flag if this page is still shared */ - if (dax_page_share_put(page) > 0) - continue; - } else - WARN_ON_ONCE(page->mapping && page->mapping !=3D mapping); - page->mapping =3D NULL; - page->index =3D 0; - } + /* + * We don't hold a reference for the DAX pagecache entry for the + * page. But we need to initialise the folio so we can hand it + * out. Nothing else should have a reference either. + */ + WARN_ON_ONCE(folio_ref_count(folio)); + dax_device_folio_init(folio, order); + folio->mapping =3D mapping; + folio->index =3D index; } =20 static struct page *dax_busy_page(void *entry) @@ -406,7 +384,7 @@ static struct page *dax_busy_page(void *entry) for_each_mapped_pfn(entry, pfn) { struct page *page =3D pfn_to_page(pfn); =20 - if (page_ref_count(page) > 1) + if (page_ref_count(page)) return page; } return NULL; @@ -620,7 +598,6 @@ static void *grab_mapping_entry(struct xa_state *xas, xas_lock_irq(xas); } =20 - dax_disassociate_entry(entry, mapping, false); xas_store(xas, NULL); /* undo the PMD join */ dax_wake_entry(xas, entry, WAKE_ALL); mapping->nrpages -=3D PG_PMD_NR; @@ -743,7 +720,7 @@ struct page *dax_layout_busy_page(struct address_space = *mapping) EXPORT_SYMBOL_GPL(dax_layout_busy_page); =20 static int __dax_invalidate_entry(struct address_space *mapping, - pgoff_t index, bool trunc) + pgoff_t index, bool trunc) { XA_STATE(xas, &mapping->i_pages, index); int ret =3D 0; @@ -757,7 +734,6 @@ static int __dax_invalidate_entry(struct address_space = *mapping, (xas_get_mark(&xas, PAGECACHE_TAG_DIRTY) || xas_get_mark(&xas, PAGECACHE_TAG_TOWRITE))) goto out; - dax_disassociate_entry(entry, mapping, trunc); xas_store(&xas, NULL); mapping->nrpages -=3D 1UL << dax_entry_order(entry); ret =3D 1; @@ -894,9 +870,11 @@ static void *dax_insert_entry(struct xa_state *xas, st= ruct vm_fault *vmf, if (shared || dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) { void *old; =20 - dax_disassociate_entry(entry, mapping, false); - dax_associate_entry(new_entry, mapping, vmf->vma, vmf->address, - shared); + if (!shared) { + dax_associate_new_entry(new_entry, mapping, + linear_page_index(vmf->vma, vmf->address)); + } + /* * Only swap our new entry into the page cache if the current * entry is a zero page or an empty entry. If a normal PTE or @@ -1084,9 +1062,7 @@ static int dax_iomap_direct_access(const struct iomap= *iomap, loff_t pos, goto out; if (pfn_t_to_pfn(*pfnp) & (PHYS_PFN(size)-1)) goto out; - /* For larger pages we need devmap */ - if (length > 1 && !pfn_t_devmap(*pfnp)) - goto out; + rc =3D 0; =20 out_check_addr: @@ -1189,11 +1165,14 @@ static vm_fault_t dax_load_hole(struct xa_state *xa= s, struct vm_fault *vmf, struct inode *inode =3D iter->inode; unsigned long vaddr =3D vmf->address; pfn_t pfn =3D pfn_to_pfn_t(my_zero_pfn(vaddr)); + struct page *page =3D pfn_t_to_page(pfn); vm_fault_t ret; =20 *entry =3D dax_insert_entry(xas, vmf, iter, *entry, pfn, DAX_ZERO_PAGE); =20 - ret =3D vmf_insert_mixed(vmf->vma, vaddr, pfn); + page_ref_inc(page); + ret =3D dax_insert_pfn(vmf, pfn, false); + put_page(page); trace_dax_load_hole(inode, vmf, ret); return ret; } @@ -1212,8 +1191,13 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state = *xas, struct vm_fault *vmf, pmd_t pmd_entry; pfn_t pfn; =20 - zero_folio =3D mm_get_huge_zero_folio(vmf->vma->vm_mm); + if (arch_needs_pgtable_deposit()) { + pgtable =3D pte_alloc_one(vma->vm_mm); + if (!pgtable) + return VM_FAULT_OOM; + } =20 + zero_folio =3D mm_get_huge_zero_folio(vmf->vma->vm_mm); if (unlikely(!zero_folio)) goto fallback; =20 @@ -1221,29 +1205,23 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state= *xas, struct vm_fault *vmf, *entry =3D dax_insert_entry(xas, vmf, iter, *entry, pfn, DAX_PMD | DAX_ZERO_PAGE); =20 - if (arch_needs_pgtable_deposit()) { - pgtable =3D pte_alloc_one(vma->vm_mm); - if (!pgtable) - return VM_FAULT_OOM; - } - ptl =3D pmd_lock(vmf->vma->vm_mm, vmf->pmd); - if (!pmd_none(*(vmf->pmd))) { - spin_unlock(ptl); - goto fallback; - } + if (!pmd_none(*vmf->pmd)) + goto fallback_unlock; =20 - if (pgtable) { - pgtable_trans_huge_deposit(vma->vm_mm, vmf->pmd, pgtable); - mm_inc_nr_ptes(vma->vm_mm); - } - pmd_entry =3D mk_pmd(&zero_folio->page, vmf->vma->vm_page_prot); + pmd_entry =3D mk_pmd(&zero_folio->page, vma->vm_page_prot); pmd_entry =3D pmd_mkhuge(pmd_entry); - set_pmd_at(vmf->vma->vm_mm, pmd_addr, vmf->pmd, pmd_entry); + if (pgtable) + pgtable_trans_huge_deposit(vma->vm_mm, vmf->pmd, pgtable); + set_pmd_at(vma->vm_mm, pmd_addr, vmf->pmd, pmd_entry); spin_unlock(ptl); trace_dax_pmd_load_hole(inode, vmf, zero_folio, *entry); return VM_FAULT_NOPAGE; =20 +fallback_unlock: + spin_unlock(ptl); + mm_put_huge_zero_folio(vma->vm_mm); + fallback: if (pgtable) pte_free(vma->vm_mm, pgtable); @@ -1649,9 +1627,10 @@ static vm_fault_t dax_fault_iter(struct vm_fault *vm= f, loff_t pos =3D (loff_t)xas->xa_index << PAGE_SHIFT; bool write =3D iter->flags & IOMAP_WRITE; unsigned long entry_flags =3D pmd ? DAX_PMD : 0; - int err =3D 0; + int ret, err =3D 0; pfn_t pfn; void *kaddr; + struct page *page; =20 if (!pmd && vmf->cow_page) return dax_fault_cow_page(vmf, iter); @@ -1684,14 +1663,21 @@ static vm_fault_t dax_fault_iter(struct vm_fault *v= mf, if (dax_fault_is_synchronous(iter, vmf->vma)) return dax_fault_synchronous_pfnp(pfnp, pfn); =20 - /* insert PMD pfn */ + page =3D pfn_t_to_page(pfn); + page_ref_inc(page); + if (pmd) - return vmf_insert_pfn_pmd(vmf, pfn, write); + ret =3D dax_insert_pfn_pmd(vmf, pfn, write); + else + ret =3D dax_insert_pfn(vmf, pfn, write); =20 - /* insert PTE pfn */ - if (write) - return vmf_insert_mixed_mkwrite(vmf->vma, vmf->address, pfn); - return vmf_insert_mixed(vmf->vma, vmf->address, pfn); + /* + * Insert PMD/PTE will have a reference on the page when mapping it so + * drop ours. + */ + put_page(page); + + return ret; } =20 static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, @@ -1932,6 +1918,7 @@ dax_insert_pfn_mkwrite(struct vm_fault *vmf, pfn_t pf= n, unsigned int order) XA_STATE_ORDER(xas, &mapping->i_pages, vmf->pgoff, order); void *entry; vm_fault_t ret; + struct page *page; =20 xas_lock_irq(&xas); entry =3D get_unlocked_entry(&xas, order); @@ -1947,14 +1934,17 @@ dax_insert_pfn_mkwrite(struct vm_fault *vmf, pfn_t = pfn, unsigned int order) xas_set_mark(&xas, PAGECACHE_TAG_DIRTY); dax_lock_entry(&xas, entry); xas_unlock_irq(&xas); + page =3D pfn_t_to_page(pfn); + page_ref_inc(page); if (order =3D=3D 0) - ret =3D vmf_insert_mixed_mkwrite(vmf->vma, vmf->address, pfn); + ret =3D dax_insert_pfn(vmf, pfn, true); #ifdef CONFIG_FS_DAX_PMD else if (order =3D=3D PMD_ORDER) - ret =3D vmf_insert_pfn_pmd(vmf, pfn, FAULT_FLAG_WRITE); + ret =3D dax_insert_pfn_pmd(vmf, pfn, FAULT_FLAG_WRITE); #endif else ret =3D VM_FAULT_FALLBACK; + put_page(page); dax_unlock_entry(&xas, entry); trace_dax_insert_pfn_mkwrite(mapping->host, vmf, ret); return ret; diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index dd52601..f79a94d 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -875,8 +875,7 @@ static long virtio_fs_direct_access(struct dax_device *= dax_dev, pgoff_t pgoff, if (kaddr) *kaddr =3D fs->window_kaddr + offset; if (pfn) - *pfn =3D phys_to_pfn_t(fs->window_phys_addr + offset, - PFN_DEV | PFN_MAP); + *pfn =3D phys_to_pfn_t(fs->window_phys_addr + offset, 0); return nr_pages > max_nr_pages ? max_nr_pages : nr_pages; } =20 diff --git a/include/linux/dax.h b/include/linux/dax.h index 773dfc4..0f6f355 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -217,8 +217,12 @@ static inline int dax_wait_page_idle(struct page *page, void (cb)(struct inode *), struct inode *inode) { - return ___wait_var_event(page, page_ref_count(page) =3D=3D 1, + int ret; + + ret =3D ___wait_var_event(page, !page_ref_count(page), TASK_INTERRUPTIBLE, 0, 0, cb(inode)); + + return ret; } =20 #if IS_ENABLED(CONFIG_DAX) diff --git a/include/linux/mm.h b/include/linux/mm.h index 935e493..592b992 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1071,6 +1071,8 @@ int vma_is_stack_for_current(struct vm_area_struct *v= ma); struct mmu_gather; struct inode; =20 +extern void prep_compound_page(struct page *page, unsigned int order); + /* * compound_order() can be called without holding a reference, which means * that niceties like page_folio() don't work. These callers should be @@ -1394,25 +1396,6 @@ vm_fault_t finish_fault(struct vm_fault *vmf); * back into memory. */ =20 -#if defined(CONFIG_ZONE_DEVICE) && defined(CONFIG_FS_DAX) -DECLARE_STATIC_KEY_FALSE(devmap_managed_key); - -bool __put_devmap_managed_folio_refs(struct folio *folio, int refs); -static inline bool put_devmap_managed_folio_refs(struct folio *folio, int = refs) -{ - if (!static_branch_unlikely(&devmap_managed_key)) - return false; - if (!folio_is_zone_device(folio)) - return false; - return __put_devmap_managed_folio_refs(folio, refs); -} -#else /* CONFIG_ZONE_DEVICE && CONFIG_FS_DAX */ -static inline bool put_devmap_managed_folio_refs(struct folio *folio, int = refs) -{ - return false; -} -#endif /* CONFIG_ZONE_DEVICE && CONFIG_FS_DAX */ - /* 127: arbitrary random number, small enough to assemble well */ #define folio_ref_zero_or_close_to_overflow(folio) \ ((unsigned int) folio_ref_count(folio) + 127u <=3D 127u) @@ -1527,12 +1510,6 @@ static inline void put_page(struct page *page) { struct folio *folio =3D page_folio(page); =20 - /* - * For some devmap managed pages we need to catch refcount transition - * from 2 to 1: - */ - if (put_devmap_managed_folio_refs(folio, 1)) - return; folio_put(folio); } =20 diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 2175ebc..0326a41 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -667,12 +667,6 @@ PAGEFLAG_FALSE(VmemmapSelfHosted, vmemmap_self_hosted) #define PAGE_MAPPING_KSM (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) #define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) =20 -/* - * Different with flags above, this flag is used only for fsdax mode. It - * indicates that this page->mapping is now under reflink case. - */ -#define PAGE_MAPPING_DAX_SHARED ((void *)0x1) - static __always_inline bool folio_mapping_flags(const struct folio *folio) { return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) !=3D 0; diff --git a/mm/gup.c b/mm/gup.c index 5d2fc9a..798c92b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -91,8 +91,7 @@ static inline struct folio *try_get_folio(struct page *pa= ge, int refs) * belongs to this folio. */ if (unlikely(page_folio(page) !=3D folio)) { - if (!put_devmap_managed_folio_refs(folio, refs)) - folio_put_refs(folio, refs); + folio_put_refs(folio, refs); goto retry; } =20 @@ -111,8 +110,7 @@ static void gup_put_folio(struct folio *folio, int refs= , unsigned int flags) refs *=3D GUP_PIN_COUNTING_BIAS; } =20 - if (!put_devmap_managed_folio_refs(folio, refs)) - folio_put_refs(folio, refs); + folio_put_refs(folio, refs); } =20 /** @@ -543,8 +541,7 @@ static struct folio *try_grab_folio_fast(struct page *p= age, int refs, */ if (unlikely((flags & FOLL_LONGTERM) && !folio_is_longterm_pinnable(folio))) { - if (!put_devmap_managed_folio_refs(folio, refs)) - folio_put_refs(folio, refs); + folio_put_refs(folio, refs); return NULL; } =20 diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 790041e..ab2cd4e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2017,7 +2017,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_ar= ea_struct *vma, tlb->fullmm); arch_check_zapped_pmd(vma, orig_pmd); tlb_remove_pmd_tlb_entry(tlb, pmd, addr); - if (vma_is_special_huge(vma)) { + if (!vma_is_dax(vma) && vma_is_special_huge(vma)) { if (arch_needs_pgtable_deposit()) zap_deposited_table(tlb->mm, pmd); spin_unlock(ptl); @@ -2661,13 +2661,15 @@ static void __split_huge_pmd_locked(struct vm_area_= struct *vma, pmd_t *pmd, */ if (arch_needs_pgtable_deposit()) zap_deposited_table(mm, pmd); - if (vma_is_special_huge(vma)) + if (!vma_is_dax(vma) && vma_is_special_huge(vma)) return; if (unlikely(is_pmd_migration_entry(old_pmd))) { swp_entry_t entry; =20 entry =3D pmd_to_swp_entry(old_pmd); folio =3D pfn_swap_entry_folio(entry); + } else if (is_huge_zero_pmd(old_pmd)) { + return; } else { page =3D pmd_page(old_pmd); folio =3D page_folio(page); diff --git a/mm/internal.h b/mm/internal.h index b00ea45..08123c2 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -680,8 +680,6 @@ static inline void prep_compound_tail(struct page *head= , int tail_idx) set_page_private(p, 0); } =20 -extern void prep_compound_page(struct page *page, unsigned int order); - extern void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flags); extern bool free_pages_prepare(struct page *page, unsigned int order); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 96ce31e..80dd2a7 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -419,18 +419,18 @@ static unsigned long dev_pagemap_mapping_shift(struct= vm_area_struct *vma, pud =3D pud_offset(p4d, address); if (!pud_present(*pud)) return 0; - if (pud_devmap(*pud)) + if (pud_trans_huge(*pud)) return PUD_SHIFT; pmd =3D pmd_offset(pud, address); if (!pmd_present(*pmd)) return 0; - if (pmd_devmap(*pmd)) + if (pmd_trans_huge(*pmd)) return PMD_SHIFT; pte =3D pte_offset_map(pmd, address); if (!pte) return 0; ptent =3D ptep_get(pte); - if (pte_present(ptent) && pte_devmap(ptent)) + if (pte_present(ptent)) ret =3D PAGE_SHIFT; pte_unmap(pte); return ret; diff --git a/mm/memory.c b/mm/memory.c index 368e15d..cc692d6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3752,13 +3752,15 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { /* * VM_MIXEDMAP !pfn_valid() case, or VM_SOFTDIRTY clear on a - * VM_PFNMAP VMA. + * VM_PFNMAP VMA. FS DAX also wants ops->pfn_mkwrite called. * * We should not cow pages in a shared writeable mapping. * Just mark the pages writable and/or call ops->pfn_mkwrite. */ - if (!vmf->page) + if (!vmf->page || is_device_dax_page(vmf->page)) { + vmf->page =3D NULL; return wp_pfn_shared(vmf); + } return wp_page_shared(vmf, folio); } =20 diff --git a/mm/memremap.c b/mm/memremap.c index e885bc9..89c0c3b 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -458,8 +458,13 @@ EXPORT_SYMBOL_GPL(get_dev_pagemap); =20 void free_zone_device_folio(struct folio *folio) { - if (WARN_ON_ONCE(!folio->pgmap->ops || - !folio->pgmap->ops->page_free)) + struct dev_pagemap *pgmap =3D folio->pgmap; + + if (WARN_ON_ONCE(!pgmap->ops)) + return; + + if (WARN_ON_ONCE(pgmap->type !=3D MEMORY_DEVICE_FS_DAX && + !pgmap->ops->page_free)) return; =20 mem_cgroup_uncharge(folio); @@ -486,24 +491,29 @@ void free_zone_device_folio(struct folio *folio) * to clear folio->mapping. */ folio->mapping =3D NULL; - folio->pgmap->ops->page_free(folio_page(folio, 0)); =20 - switch (folio->pgmap->type) { + switch (pgmap->type) { case MEMORY_DEVICE_PRIVATE: case MEMORY_DEVICE_COHERENT: - put_dev_pagemap(folio->pgmap); + pgmap->ops->page_free(folio_page(folio, 0)); + put_dev_pagemap(pgmap); break; =20 - case MEMORY_DEVICE_FS_DAX: case MEMORY_DEVICE_GENERIC: /* * 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; =20 + case MEMORY_DEVICE_FS_DAX: + wake_up_var(&folio->page); + break; + case MEMORY_DEVICE_PCI_P2PDMA: + pgmap->ops->page_free(folio_page(folio, 0)); break; } } @@ -519,21 +529,3 @@ void zone_device_page_init(struct page *page) lock_page(page); } EXPORT_SYMBOL_GPL(zone_device_page_init); - -#ifdef CONFIG_FS_DAX -bool __put_devmap_managed_folio_refs(struct folio *folio, int refs) -{ - if (folio->pgmap->type !=3D MEMORY_DEVICE_FS_DAX) - return false; - - /* - * fsdax page refcounts are 1-based, rather than 0-based: if - * refcount is 1, then the page is free and the refcount is - * stable because nobody holds a reference on the page. - */ - if (folio_ref_sub_return(folio, refs) =3D=3D 1) - wake_up_var(&folio->_refcount); - return true; -} -EXPORT_SYMBOL(__put_devmap_managed_folio_refs); -#endif /* CONFIG_FS_DAX */ diff --git a/mm/mlock.c b/mm/mlock.c index e3e3dc2..5352b00 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -362,6 +362,8 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long ad= dr, unsigned long start =3D addr; =20 ptl =3D pmd_trans_huge_lock(pmd, vma); + if (vma_is_dax(vma)) + ptl =3D NULL; if (ptl) { if (!pmd_present(*pmd)) goto out; diff --git a/mm/mm_init.c b/mm/mm_init.c index 3d0611e..3c32190 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1015,23 +1015,22 @@ static void __ref __init_zone_device_page(struct pa= ge *page, unsigned long pfn, } =20 /* - * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC and - * MEMORY_TYPE_FS_DAX pages are released directly to the driver page - * allocator which will set the page count to 1 when allocating the - * page. + * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC are released + * directly to the driver page allocator which will set the page count + * to 1 when allocating the page. * * MEMORY_TYPE_GENERIC and MEMORY_TYPE_FS_DAX pages automatically have * their refcount reset to one whenever they are freed (ie. after * their refcount drops to 0). */ switch (pgmap->type) { + case MEMORY_DEVICE_FS_DAX: case MEMORY_DEVICE_PRIVATE: case MEMORY_DEVICE_COHERENT: case MEMORY_DEVICE_PCI_P2PDMA: set_page_count(page, 0); break; =20 - case MEMORY_DEVICE_FS_DAX: case MEMORY_DEVICE_GENERIC: break; } diff --git a/mm/swap.c b/mm/swap.c index 6b83898..0b90b61 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -969,8 +969,6 @@ void folios_put_refs(struct folio_batch *folios, unsign= ed int *refs) unlock_page_lruvec_irqrestore(lruvec, flags); lruvec =3D NULL; } - if (put_devmap_managed_folio_refs(folio, nr_refs)) - continue; if (folio_ref_sub_and_test(folio, nr_refs)) free_zone_device_folio(folio); continue; --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2055.outbound.protection.outlook.com [40.107.220.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 F1E26192B78; Tue, 10 Sep 2024 04:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941759; cv=fail; b=CCiOx05aDoHGZvLSUiIyBIHbfGMBvPavY8VTDQIo794yYJLPCu/A5DuShd8r16Gpi9rTJMAbMN1iq4OBvcjHILO1lC5p60ovgpkDjw9iq12jZ6a79bYiHLkc+0j/+r0QAyplTnYyS2conNXsymUDiW4lpvcbyBZVrRhzGj1kBew= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941759; c=relaxed/simple; bh=WKFYnXPWNZud51IeK/OxKlmgYFXbqt/aIVclzBUQahg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=PmRDqfODHy2BufzpMn0AnWSq4vbpZHZsb7cgqrZch4ngzdivu8dyzO0Xft8JcK7dSI+8HGYARCT7jbBNfLxasJ+Z3VhObL0K5w6mMQScolCx5n5xtFBImFwY2++FTy+tcvWTw6DmQOFNdW85T/fTLF4xT2VrBvGkmYd4qRSTUrk= 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=GOtW36z8; arc=fail smtp.client-ip=40.107.220.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="GOtW36z8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KtAHmdw0KRAyuxXMvAg583wC3SDEf1q/ZoxzuEKv3BIfqQa2cdt997bkQzBPW+PSDalL4KYuYVaEn0u/5qCT2/SzMfdxf56YCjQ6nTzkfGYaT6dsFXqrgUn0LK59pmbuPVcxJ6Qqu8twoLK8G/NifPUH2NaoNi63rCalNCOmIU3jeWvAh6cB4fF/P3JUiJt9Fc2/4fJyXbf6y/yI2tMokEDn+SCWH2BbkaFOXHVUAnTvphC7s4VCRL231CyRBA+pCrlzJftYQgV7xueIlAKf2xmQTqhrffYlhDxaJq2t/xEpLVGduMHFdB+OOKoe13Tde64lOX0XPJIVB8w+LGVmbg== 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=gzpSbsBEbbJRrYOQfHMEsEmFzj1kc67TtymrJmZwhR0=; b=qRFSuTZZn/RfE/QYaHh4qUToUd3RwokI4ad5enx8AehYhyPw8hCE/OMQLHKKrHK8/yU0MexU6LJwTv+1GvB/ZiU+DFyh8hSV6vx8C+JzTjgWHeOvgfZPFidnX5INAptUWJxkaMmppX8u93Lf2pVPBBWUG93NSxYPSFxtYnimieYcvekqZ8cq4zHLGgWzuWskQ5Yv0fSFGDkwqEar7d9EcKYZ0WL58izrXB7Gu9XC0g3cZs66hRsijHQNregsaK1hheT3uQWsQNe0lt5JxqSi3C6emHaYg5ZndvDjvRBeSXQx1u1QzxyLWrqsP0v8tqWZqeeoGaBi35Gx8VGHgtN52w== 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=gzpSbsBEbbJRrYOQfHMEsEmFzj1kc67TtymrJmZwhR0=; b=GOtW36z8bvOjjwLLMd1//9RNLCQwjQFcj0Ju2Hm0xKZmhoqQ09GiGygyfwBRNOSetNCHvLH4YGRnRm30ZBgk7tH2S7QGg4M0CLCtiQPvBPxmtVJaD4kb5tbsxz3Hjwjq0P1mOHMOF7Q/2U9GHsiMxhB1JI2AUW1CKiPf3bXXmZp2q0baoNKBTwBkk9WQdtndFY3JqkJ+SpTa+lkthXFa1Aq7cVAtdic5wyasVKD0kH+hDjY+q1ataGkN0yO+Hl5Mx0Yjw1xYsHEZ3b0PYVJOk2SKb18bAXXvodNhp4HMuapPyzwLWeVphkK+akVXmfOpdwzuq5+odnwFXhGHEBpQlA== 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:53 +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:53 +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 11/12] mm: Remove pXX_devmap callers Date: Tue, 10 Sep 2024 14:14:36 +1000 Message-ID: <4511465a4f8429f45e2ac70d2e65dc5e1df1eb47.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SY5P282CA0001.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:208::15) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@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: 9eaf4d6f-a978-4cb2-3c49-08dcd14f426f 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: =?us-ascii?Q?VF0zDR0YEdCFVbNXgyjvP3kMvy9g84qrOROG1Uwg/KgY1Jy3t/YPMevP5xAA?= =?us-ascii?Q?rNOWVH+GrCw4LBCWivomXMqMBJgWuxBbQv/ll749oCrwB8mxq/MwtRhpXt79?= =?us-ascii?Q?9UoBvX8kj7sFr1Ke0dLTmH/EkE55jYsa8dUbKsG3mGhQP7r7ucGVlAVZNn+H?= =?us-ascii?Q?yMOod1emICZz7YPOjhJ8hKSwad4t6oxaa51lVoyl7rnDIjmDN/Aw0gxSxpfl?= =?us-ascii?Q?agk5rZuaskoGLMPG5DbJ6bKiQXdTadFrbGJuq3XItP4D2f7gF93s5+o3hyjS?= =?us-ascii?Q?eLL/RyRFotEaKB8vBvGbCkXpkYfB+i0ODTDxWwlAWBaBxOg66/wgDRM3dbL4?= =?us-ascii?Q?JDFSsKTARe7tgCKpd7cHyjKblIycQMNPH8GYDs72wgPpqelSD/B30/pmRJEl?= =?us-ascii?Q?EYSnUzWS/KPsoRIoTkilsTX3GT8QnXowo1JKLr1wxqnUawtYQcIeBUs5Nz/9?= =?us-ascii?Q?EH0TjhS8Gx5hZbYc+/CQD99W73ivmOd3vR1IuiwRaQeztvri4FlFNwjYElCt?= =?us-ascii?Q?cN2CokXFKoYQki5vYGPEdEPTTd9draZiE0S01EX6WuyUP+fVS/RPI64k1SiI?= =?us-ascii?Q?LRK21NrQGqy6sOVe2ca3CBEgDb+1j0aPxdDCc+EQRaXouzeTR+vrhQxJLNyc?= =?us-ascii?Q?WjaFvzerROmPXZkRQbOB4F3LFvXzNp/ZEEnqiz9o4eM6q/4Suded3/WohR3d?= =?us-ascii?Q?hW/d5NDGh8Y4pv4mKY8ClDI6Je8xV4cYanUTVqOIhlk/XVyKHh4ZDfVKHCmk?= =?us-ascii?Q?/gBIoqwjC1mQQV9pS32e9+VBoT8F3jP+rWdQbQy52svRIQrQSGSnGMu3CoDN?= =?us-ascii?Q?ds2RxeXGmSbkbqgkxhHDiKrp2YTYp5uGLTiXbcVaHUF0FhYCzjYb4bPaNm26?= =?us-ascii?Q?UjXFJQSaSmJDbJNFIPD2kVO9SaChiguPdjH+ZJRL3GoGhGpR5/SozaovMv9q?= =?us-ascii?Q?Bh2DzJFNW90/tU+AksyLt18SWXxNr1BnOGWgcTKmaat+HdpG9AsQR/3p+rN6?= =?us-ascii?Q?DQScmihyaqCw3k7DdeHxo7I9LXl7Z1QAO0a+9n4DCokX5xmEJiyFGeKBYPmR?= =?us-ascii?Q?Ww6CP+cY8pHUQuis6jTCDMkMV7IMqq0JdLVT+1c6Nil+Q0d+HSvUUdyLsw/4?= =?us-ascii?Q?uuMPRTwdt3kFGeBOfXaerwe0Gz0ITNY1ICQ5Dc6UcI88kBiCy1s/Ejs83Bm1?= =?us-ascii?Q?/9gis9pcpIJYNUYQWdogmxNd1Lus0XVh0I1IfilzIW2HOtfNWKL4zGelreMy?= =?us-ascii?Q?IdhK/P3lvdjbR1yX4qTlcIM/w7HgKQXjYuQjNcO6+Vp2b8IVYyJ+KPqd7yCx?= =?us-ascii?Q?YO0fZL7mbMVJFyVI4v0NBnvoXrjmr5bGvWIR7fUBOnDPyA=3D=3D?= 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: =?us-ascii?Q?1torIMmdGwQwI/aeXvznobaTj8cDtQlLq3tundyFA67thyuzDgrmw9Z3VrG3?= =?us-ascii?Q?fmAvqpI5+nEDUjKEKNEJB6F3xXm84qaZ10riTODnAIimhvdWvrmMjV/cf4G3?= =?us-ascii?Q?9Xk/PlGFErSxzTRKhrkIDSbxmBUNC6Cb/mCd4DlzRiLXNDa2kgsmmXlzDEoT?= =?us-ascii?Q?M8uNfuaA/tNMAIbZQ1YWnEPS/+7QVpWg8TAiewnX6vRb/puJWw+bTSUn1JYf?= =?us-ascii?Q?TbFG+4riwrxMJCGIJbhN2ikS/vxDzg6dgXwS6TQepSrTRwSue7Vd8AiRBpaF?= =?us-ascii?Q?OrlJ0Ct7EXfVfw12PoU4GakSFpVLJ7djpI1f0vNrUzoO8SQnXWbi6IcXlwpF?= =?us-ascii?Q?uzjcT09OSpx+cFqwBdZTI9dog94/r7EMCIlZGssxXIwL6LFkSpZQBnswq6dr?= =?us-ascii?Q?Fi6EVf9RR/JqlH9w0LgpskxGMJFU5liijBZeOnT4m5SahpaBuVul2Lrl6f8R?= =?us-ascii?Q?CgGD/nkCu5eZQkccvzTvbj23BCDhfoqr3BCP4qoPrVBNEUdaAx2rog9tpjfc?= =?us-ascii?Q?Hw5xRga+JNYJ5M7Fwd/QuXHnIpjuRpqgBEl0V8XIo5YTG5SICVCB/NQlC9Gt?= =?us-ascii?Q?RaFyFcyStU7T1smtDfSCvfSpSETqmHvI5LXZ38KzNiEegAJrV/GClLGhYBTq?= =?us-ascii?Q?+KYHAWZouZ34xKT4usfHBfrbV45Q2inER0yKX5L6NQsbc7WAFBZyw0/PZFqK?= =?us-ascii?Q?tfnsyj5zxFsxlZwgAMVo5j0ySouX5pvPxy8idZtbhRE4VSTAE9WhBqRonTkZ?= =?us-ascii?Q?Rv2n4kC8fpRhyE9XOHOTFbYG3+gC7+zhrdlOSSH5gU8wYLgDpTn1yS+8UH2X?= =?us-ascii?Q?CwgU3/goudQ6sKyQzZZkVADl3/vJiIztjYA/t3VgKE/Qpn/Pfoc/bCYVpNQX?= =?us-ascii?Q?ZrJDCMw22K1PRwOBfGlHJZ3qcCOkHCRHd1AqS/hGaWwXhxQTzIuyp7W2r5iH?= =?us-ascii?Q?aGHA9n91NowOmVK69nTObKnwFkRvVsagOtZNGaCL/1IoLCCispQ8v8PgrbkA?= =?us-ascii?Q?JxQBLTsP9C4cP0HCt67SlUssHcvVcppUt0mPCheOjULmtJhsU7IUj7DcyFke?= =?us-ascii?Q?VKJqbkiDkYYoFj0usk+nn0D7sD1Iq+qwD3cQhuRlewhBrAevATeZlGhjPrS3?= =?us-ascii?Q?aTEDFrCIWxkywmTZ+8U9xOFuu8JoEbjaCOJOtPeiCBTCXuenhm2skRMGZEfP?= =?us-ascii?Q?Y19Sc3EO53SW11xlVP8kEgPJjrH/DYOGldMidglfHYfUsO61TTExH7Y6tH2x?= =?us-ascii?Q?nVPuYzz1hP4KhJITzcnYU4yZtO44P1M7Y+DQ6IVwBW73FmyXSRPxPAi79ine?= =?us-ascii?Q?XDquPcIJ0EfS6Ffi3q3XQyQEgjtIe9JI8eJ4aMCHTiZlR0pDsyjgy8+n5qut?= =?us-ascii?Q?CyU9cLLgRbvvvHkOL7xRLWeZtxW0LGTy4MU+mCA0hHjBv/hCwxTsvKn/aO18?= =?us-ascii?Q?GeORrE9U9RDtZjy81Z3PGSrurtjvnG8J51zkM6bjdsmTJE5UOLUfDEOEwq0u?= =?us-ascii?Q?6QKWdMKh2QW+1d5kuZBLd2RqEx7zOoxqGC0J3ddFUOhkdtWZSEV8biyizqY6?= =?us-ascii?Q?51kRkjufqHyt9kfhcXeTGVZVnkWR7k4ATZeZDHuR?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9eaf4d6f-a978-4cb2-3c49-08dcd14f426f 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:52.9804 (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: sMIv1JfrOnBtH318CFAitYFgOa/sAW5vGDJ/EcuOKX/b01+dwfqf+dJ3zXRxsO4VMwBk/Z+ig6ut6CQcnkgPuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8088 Content-Type: text/plain; charset="utf-8" The devmap PTE special bit was used to detect mappings of FS DAX pages. This tracking was required to ensure the generic mm did not manipulate the page reference counts as FS DAX implemented it's own reference counting scheme. Now that FS DAX pages have their references counted the same way as normal pages this tracking is no longer needed and can be removed. Almost all existing uses of pmd_devmap() are paired with a check of pmd_trans_huge(). As pmd_trans_huge() now returns true for FS DAX pages dropping the check in these cases doesn't change anything. However care needs to be taken because pmd_trans_huge() also checks that a page is not an FS DAX page. This is dealt with either by checking !vma_is_dax() or relying on the fact that the page pointer was obtained from a page list. This is possible because zone device pages cannot appear in any page list due to sharing page->lru with page->pgmap. Signed-off-by: Alistair Popple --- arch/powerpc/mm/book3s64/hash_pgtable.c | 3 +- arch/powerpc/mm/book3s64/pgtable.c | 8 +- arch/powerpc/mm/book3s64/radix_pgtable.c | 5 +- arch/powerpc/mm/pgtable.c | 2 +- fs/dax.c | 5 +- fs/userfaultfd.c | 2 +- include/linux/huge_mm.h | 10 +- include/linux/pgtable.h | 2 +- mm/gup.c | 163 +------------------------ mm/hmm.c | 7 +- mm/huge_memory.c | 65 +--------- mm/khugepaged.c | 2 +- mm/mapping_dirty_helpers.c | 4 +- mm/memory.c | 37 +---- mm/migrate_device.c | 2 +- mm/mprotect.c | 2 +- mm/mremap.c | 5 +- mm/page_vma_mapped.c | 5 +- mm/pagewalk.c | 8 +- mm/pgtable-generic.c | 7 +- mm/userfaultfd.c | 2 +- mm/vmscan.c | 5 +- 22 files changed, 59 insertions(+), 292 deletions(-) diff --git a/arch/powerpc/mm/book3s64/hash_pgtable.c b/arch/powerpc/mm/book= 3s64/hash_pgtable.c index 988948d..82d3117 100644 --- a/arch/powerpc/mm/book3s64/hash_pgtable.c +++ b/arch/powerpc/mm/book3s64/hash_pgtable.c @@ -195,7 +195,7 @@ unsigned long hash__pmd_hugepage_update(struct mm_struc= t *mm, unsigned long addr unsigned long old; =20 #ifdef CONFIG_DEBUG_VM - WARN_ON(!hash__pmd_trans_huge(*pmdp) && !pmd_devmap(*pmdp)); + WARN_ON(!hash__pmd_trans_huge(*pmdp)); assert_spin_locked(pmd_lockptr(mm, pmdp)); #endif =20 @@ -227,7 +227,6 @@ pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *= vma, unsigned long addres =20 VM_BUG_ON(address & ~HPAGE_PMD_MASK); VM_BUG_ON(pmd_trans_huge(*pmdp)); - VM_BUG_ON(pmd_devmap(*pmdp)); =20 pmd =3D *pmdp; pmd_clear(pmdp); diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/= pgtable.c index 5a4a753..4537a29 100644 --- a/arch/powerpc/mm/book3s64/pgtable.c +++ b/arch/powerpc/mm/book3s64/pgtable.c @@ -50,7 +50,7 @@ int pmdp_set_access_flags(struct vm_area_struct *vma, uns= igned long address, { int changed; #ifdef CONFIG_DEBUG_VM - WARN_ON(!pmd_trans_huge(*pmdp) && !pmd_devmap(*pmdp)); + WARN_ON(!pmd_trans_huge(*pmdp)); assert_spin_locked(pmd_lockptr(vma->vm_mm, pmdp)); #endif changed =3D !pmd_same(*(pmdp), entry); @@ -70,7 +70,6 @@ int pudp_set_access_flags(struct vm_area_struct *vma, uns= igned long address, { int changed; #ifdef CONFIG_DEBUG_VM - WARN_ON(!pud_devmap(*pudp)); assert_spin_locked(pud_lockptr(vma->vm_mm, pudp)); #endif changed =3D !pud_same(*(pudp), entry); @@ -193,7 +192,7 @@ pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struc= t *vma, pmd_t pmd; VM_BUG_ON(addr & ~HPAGE_PMD_MASK); VM_BUG_ON((pmd_present(*pmdp) && !pmd_trans_huge(*pmdp) && - !pmd_devmap(*pmdp)) || !pmd_present(*pmdp)); + || !pmd_present(*pmdp)); pmd =3D pmdp_huge_get_and_clear(vma->vm_mm, addr, pmdp); /* * if it not a fullmm flush, then we can possibly end up converting @@ -211,8 +210,7 @@ pud_t pudp_huge_get_and_clear_full(struct vm_area_struc= t *vma, pud_t pud; =20 VM_BUG_ON(addr & ~HPAGE_PMD_MASK); - VM_BUG_ON((pud_present(*pudp) && !pud_devmap(*pudp)) || - !pud_present(*pudp)); + VM_BUG_ON(!pud_present(*pudp)); pud =3D pudp_huge_get_and_clear(vma->vm_mm, addr, pudp); /* * if it not a fullmm flush, then we can possibly end up converting diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/boo= k3s64/radix_pgtable.c index b0d9270..78907b6 100644 --- a/arch/powerpc/mm/book3s64/radix_pgtable.c +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c @@ -1424,7 +1424,7 @@ unsigned long radix__pmd_hugepage_update(struct mm_st= ruct *mm, unsigned long add unsigned long old; =20 #ifdef CONFIG_DEBUG_VM - WARN_ON(!radix__pmd_trans_huge(*pmdp) && !pmd_devmap(*pmdp)); + WARN_ON(!radix__pmd_trans_huge(*pmdp)); assert_spin_locked(pmd_lockptr(mm, pmdp)); #endif =20 @@ -1441,7 +1441,7 @@ unsigned long radix__pud_hugepage_update(struct mm_st= ruct *mm, unsigned long add unsigned long old; =20 #ifdef CONFIG_DEBUG_VM - WARN_ON(!pud_devmap(*pudp)); + WARN_ON(!pud_trans_huge(*pudp)); assert_spin_locked(pud_lockptr(mm, pudp)); #endif =20 @@ -1459,7 +1459,6 @@ pmd_t radix__pmdp_collapse_flush(struct vm_area_struc= t *vma, unsigned long addre =20 VM_BUG_ON(address & ~HPAGE_PMD_MASK); VM_BUG_ON(radix__pmd_trans_huge(*pmdp)); - VM_BUG_ON(pmd_devmap(*pmdp)); /* * khugepaged calls this for normal pmd */ diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index 7316396..c8cba4d 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c @@ -509,7 +509,7 @@ pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long ea, return NULL; #endif =20 - if (pmd_trans_huge(pmd) || pmd_devmap(pmd)) { + if (pmd_trans_huge(pmd)) { if (is_thp) *is_thp =3D true; ret_pte =3D (pte_t *)pmdp; diff --git a/fs/dax.c b/fs/dax.c index 05f7b88..6933ff3 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1721,7 +1721,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault= *vmf, pfn_t *pfnp, * the PTE we need to set up. If so just return and the fault will be * retried. */ - if (pmd_trans_huge(*vmf->pmd) || pmd_devmap(*vmf->pmd)) { + if (pmd_trans_huge(*vmf->pmd)) { ret =3D VM_FAULT_NOPAGE; goto unlock_entry; } @@ -1842,8 +1842,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault= *vmf, pfn_t *pfnp, * the PMD we need to set up. If so just return and the fault will be * retried. */ - if (!pmd_none(*vmf->pmd) && !pmd_trans_huge(*vmf->pmd) && - !pmd_devmap(*vmf->pmd)) { + if (!pmd_none(*vmf->pmd) && !pmd_trans_huge(*vmf->pmd)) { ret =3D 0; goto unlock_entry; } diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 68cdd89..1c90913 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -304,7 +304,7 @@ static inline bool userfaultfd_must_wait(struct userfau= ltfd_ctx *ctx, goto out; =20 ret =3D false; - if (!pmd_present(_pmd) || pmd_devmap(_pmd)) + if (!pmd_present(_pmd) || vma_is_dax(vmf->vma)) goto out; =20 if (pmd_trans_huge(_pmd)) { diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index eaf3f78..79a24ac 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -334,8 +334,7 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t= *pmd, #define split_huge_pmd(__vma, __pmd, __address) \ do { \ pmd_t *____pmd =3D (__pmd); \ - if (is_swap_pmd(*____pmd) || pmd_trans_huge(*____pmd) \ - || pmd_devmap(*____pmd)) \ + if (is_swap_pmd(*____pmd) || pmd_trans_huge(*____pmd)) \ __split_huge_pmd(__vma, __pmd, __address, \ false, NULL); \ } while (0) @@ -361,8 +360,7 @@ change_huge_pud(struct mmu_gather *tlb, struct vm_area_= struct *vma, #define split_huge_pud(__vma, __pud, __address) \ do { \ pud_t *____pud =3D (__pud); \ - if (pud_trans_huge(*____pud) \ - || pud_devmap(*____pud)) \ + if (pud_trans_huge(*____pud)) \ __split_huge_pud(__vma, __pud, __address); \ } while (0) =20 @@ -385,7 +383,7 @@ static inline int is_swap_pmd(pmd_t pmd) static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma) { - if (is_swap_pmd(*pmd) || pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) + if (is_swap_pmd(*pmd) || pmd_trans_huge(*pmd)) return __pmd_trans_huge_lock(pmd, vma); else return NULL; @@ -393,7 +391,7 @@ static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pm= d, static inline spinlock_t *pud_trans_huge_lock(pud_t *pud, struct vm_area_struct *vma) { - if (pud_trans_huge(*pud) || pud_devmap(*pud)) + if (pud_trans_huge(*pud)) return __pud_trans_huge_lock(pud, vma); else return NULL; diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 780f3b4..a68e279 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1645,7 +1645,7 @@ static inline int pud_trans_unstable(pud_t *pud) defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) pud_t pudval =3D READ_ONCE(*pud); =20 - if (pud_none(pudval) || pud_trans_huge(pudval) || pud_devmap(pudval)) + if (pud_none(pudval) || pud_trans_huge(pudval)) return 1; if (unlikely(pud_bad(pudval))) { pud_clear_bad(pud); diff --git a/mm/gup.c b/mm/gup.c index 798c92b..74b0234 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -616,31 +616,9 @@ static struct page *follow_huge_pud(struct vm_area_str= uct *vma, return NULL; =20 pfn +=3D (addr & ~PUD_MASK) >> PAGE_SHIFT; - - if (IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) && - pud_devmap(pud)) { - /* - * device mapped pages can only be returned if the caller - * will manage the page reference count. - * - * At least one of FOLL_GET | FOLL_PIN must be set, so - * assert that here: - */ - if (!(flags & (FOLL_GET | FOLL_PIN))) - return ERR_PTR(-EEXIST); - - if (flags & FOLL_TOUCH) - touch_pud(vma, addr, pudp, flags & FOLL_WRITE); - - ctx->pgmap =3D get_dev_pagemap(pfn, ctx->pgmap); - if (!ctx->pgmap) - return ERR_PTR(-EFAULT); - } - page =3D pfn_to_page(pfn); =20 - if (!pud_devmap(pud) && !pud_write(pud) && - gup_must_unshare(vma, flags, page)) + if (!pud_write(pud) && gup_must_unshare(vma, flags, page)) return ERR_PTR(-EMLINK); =20 ret =3D try_grab_folio(page_folio(page), 1, flags); @@ -839,8 +817,7 @@ static struct page *follow_page_pte(struct vm_area_stru= ct *vma, page =3D vm_normal_page(vma, address, pte); =20 /* - * We only care about anon pages in can_follow_write_pte() and don't - * have to worry about pte_devmap() because they are never anon. + * We only care about anon pages in can_follow_write_pte(). */ if ((flags & FOLL_WRITE) && !can_follow_write_pte(pte, page, vma, flags)) { @@ -848,18 +825,7 @@ static struct page *follow_page_pte(struct vm_area_str= uct *vma, goto out; } =20 - if (!page && pte_devmap(pte) && (flags & (FOLL_GET | FOLL_PIN))) { - /* - * Only return device mapping pages in the FOLL_GET or FOLL_PIN - * case since they are only valid while holding the pgmap - * reference. - */ - *pgmap =3D get_dev_pagemap(pte_pfn(pte), *pgmap); - if (*pgmap) - page =3D pte_page(pte); - else - goto no_page; - } else if (unlikely(!page)) { + if (unlikely(!page)) { if (flags & FOLL_DUMP) { /* Avoid special (like zero) pages in core dumps */ page =3D ERR_PTR(-EFAULT); @@ -941,14 +907,6 @@ static struct page *follow_pmd_mask(struct vm_area_str= uct *vma, return no_page_table(vma, flags, address); if (!pmd_present(pmdval)) return no_page_table(vma, flags, address); - if (pmd_devmap(pmdval)) { - ptl =3D pmd_lock(mm, pmd); - page =3D follow_devmap_pmd(vma, address, pmd, flags, &ctx->pgmap); - spin_unlock(ptl); - if (page) - return page; - return no_page_table(vma, flags, address); - } if (likely(!pmd_leaf(pmdval))) return follow_page_pte(vma, address, pmd, flags, &ctx->pgmap); =20 @@ -2830,7 +2788,7 @@ static int gup_fast_pte_range(pmd_t pmd, pmd_t *pmdp,= unsigned long addr, int *nr) { struct dev_pagemap *pgmap =3D NULL; - int nr_start =3D *nr, ret =3D 0; + int ret =3D 0; pte_t *ptep, *ptem; =20 ptem =3D ptep =3D pte_offset_map(&pmd, addr); @@ -2854,16 +2812,7 @@ static int gup_fast_pte_range(pmd_t pmd, pmd_t *pmdp= , unsigned long addr, if (!pte_access_permitted(pte, flags & FOLL_WRITE)) goto pte_unmap; =20 - if (pte_devmap(pte)) { - if (unlikely(flags & FOLL_LONGTERM)) - goto pte_unmap; - - pgmap =3D get_dev_pagemap(pte_pfn(pte), pgmap); - if (unlikely(!pgmap)) { - gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); - goto pte_unmap; - } - } else if (pte_special(pte)) + if (pte_special(pte)) goto pte_unmap; =20 VM_BUG_ON(!pfn_valid(pte_pfn(pte))); @@ -2934,91 +2883,6 @@ static int gup_fast_pte_range(pmd_t pmd, pmd_t *pmdp= , unsigned long addr, } #endif /* CONFIG_ARCH_HAS_PTE_SPECIAL */ =20 -#if defined(CONFIG_ARCH_HAS_PTE_DEVMAP) && defined(CONFIG_TRANSPARENT_HUGE= PAGE) -static int gup_fast_devmap_leaf(unsigned long pfn, unsigned long addr, - unsigned long end, unsigned int flags, struct page **pages, int *nr) -{ - int nr_start =3D *nr; - struct dev_pagemap *pgmap =3D NULL; - - do { - struct folio *folio; - struct page *page =3D pfn_to_page(pfn); - - pgmap =3D get_dev_pagemap(pfn, pgmap); - if (unlikely(!pgmap)) { - gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); - break; - } - - folio =3D try_grab_folio_fast(page, 1, flags); - if (!folio) { - gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); - break; - } - folio_set_referenced(folio); - pages[*nr] =3D page; - (*nr)++; - pfn++; - } while (addr +=3D PAGE_SIZE, addr !=3D end); - - put_dev_pagemap(pgmap); - return addr =3D=3D end; -} - -static int gup_fast_devmap_pmd_leaf(pmd_t orig, pmd_t *pmdp, unsigned long= addr, - unsigned long end, unsigned int flags, struct page **pages, - int *nr) -{ - unsigned long fault_pfn; - int nr_start =3D *nr; - - fault_pfn =3D pmd_pfn(orig) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); - if (!gup_fast_devmap_leaf(fault_pfn, addr, end, flags, pages, nr)) - return 0; - - if (unlikely(pmd_val(orig) !=3D pmd_val(*pmdp))) { - gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); - return 0; - } - return 1; -} - -static int gup_fast_devmap_pud_leaf(pud_t orig, pud_t *pudp, unsigned long= addr, - unsigned long end, unsigned int flags, struct page **pages, - int *nr) -{ - unsigned long fault_pfn; - int nr_start =3D *nr; - - fault_pfn =3D pud_pfn(orig) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); - if (!gup_fast_devmap_leaf(fault_pfn, addr, end, flags, pages, nr)) - return 0; - - if (unlikely(pud_val(orig) !=3D pud_val(*pudp))) { - gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); - return 0; - } - return 1; -} -#else -static int gup_fast_devmap_pmd_leaf(pmd_t orig, pmd_t *pmdp, unsigned long= addr, - unsigned long end, unsigned int flags, struct page **pages, - int *nr) -{ - BUILD_BUG(); - return 0; -} - -static int gup_fast_devmap_pud_leaf(pud_t pud, pud_t *pudp, unsigned long = addr, - unsigned long end, unsigned int flags, struct page **pages, - int *nr) -{ - BUILD_BUG(); - return 0; -} -#endif - static int gup_fast_pmd_leaf(pmd_t orig, pmd_t *pmdp, unsigned long addr, unsigned long end, unsigned int flags, struct page **pages, int *nr) @@ -3030,13 +2894,6 @@ static int gup_fast_pmd_leaf(pmd_t orig, pmd_t *pmdp= , unsigned long addr, if (!pmd_access_permitted(orig, flags & FOLL_WRITE)) return 0; =20 - if (pmd_devmap(orig)) { - if (unlikely(flags & FOLL_LONGTERM)) - return 0; - return gup_fast_devmap_pmd_leaf(orig, pmdp, addr, end, flags, - pages, nr); - } - page =3D pmd_page(orig); refs =3D record_subpages(page, PMD_SIZE, addr, end, pages + *nr); =20 @@ -3074,13 +2931,7 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp= , unsigned long addr, if (!pud_access_permitted(orig, flags & FOLL_WRITE)) return 0; =20 - if (pud_devmap(orig)) { - if (unlikely(flags & FOLL_LONGTERM)) - return 0; - return gup_fast_devmap_pud_leaf(orig, pudp, addr, end, flags, - pages, nr); - } - + // TODO: FOLL_LONGTERM? page =3D pud_page(orig); refs =3D record_subpages(page, PUD_SIZE, addr, end, pages + *nr); =20 @@ -3119,8 +2970,6 @@ static int gup_fast_pgd_leaf(pgd_t orig, pgd_t *pgdp,= unsigned long addr, if (!pgd_access_permitted(orig, flags & FOLL_WRITE)) return 0; =20 - BUILD_BUG_ON(pgd_devmap(orig)); - page =3D pgd_page(orig); refs =3D record_subpages(page, PGDIR_SIZE, addr, end, pages + *nr); =20 diff --git a/mm/hmm.c b/mm/hmm.c index a11807c..1b85ed6 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -298,7 +298,6 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, uns= igned long addr, * fall through and treat it like a normal page. */ if (!vm_normal_page(walk->vma, addr, pte) && - !pte_devmap(pte) && !is_zero_pfn(pte_pfn(pte))) { if (hmm_pte_need_fault(hmm_vma_walk, pfn_req_flags, 0)) { pte_unmap(ptep); @@ -351,7 +350,7 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, return hmm_pfns_fill(start, end, range, HMM_PFN_ERROR); } =20 - if (pmd_devmap(pmd) || pmd_trans_huge(pmd)) { + if (pmd_trans_huge(pmd)) { /* * No need to take pmd_lock here, even if some other thread * is splitting the huge pmd we will get that event through @@ -362,7 +361,7 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, * values. */ pmd =3D pmdp_get_lockless(pmdp); - if (!pmd_devmap(pmd) && !pmd_trans_huge(pmd)) + if (!pmd_trans_huge(pmd)) goto again; =20 return hmm_vma_handle_pmd(walk, addr, end, hmm_pfns, pmd); @@ -429,7 +428,7 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned long = start, unsigned long end, return hmm_vma_walk_hole(start, end, -1, walk); } =20 - if (pud_leaf(pud) && pud_devmap(pud)) { + if (pud_leaf(pud) && vma_is_dax(walk->vma)) { unsigned long i, npages, pfn; unsigned int required_fault; unsigned long *hmm_pfns; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ab2cd4e..7c39950 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1254,8 +1254,6 @@ static void insert_pfn_pmd(struct vm_area_struct *vma= , unsigned long addr, } =20 entry =3D pmd_mkhuge(pfn_t_pmd(pfn, prot)); - if (pfn_t_devmap(pfn)) - entry =3D pmd_mkdevmap(entry); if (write) { entry =3D pmd_mkyoung(pmd_mkdirty(entry)); entry =3D maybe_pmd_mkwrite(entry, vma); @@ -1294,8 +1292,6 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, p= fn_t pfn, bool write) * but we need to be consistent with PTEs and architectures that * can't support a 'special' bit. */ - BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) && - !pfn_t_devmap(pfn)); BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) =3D=3D (VM_PFNMAP|VM_MIXEDMAP)); BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags)); @@ -1389,8 +1385,6 @@ static void insert_pfn_pud(struct vm_area_struct *vma= , unsigned long addr, } =20 entry =3D pud_mkhuge(pfn_t_pud(pfn, prot)); - if (pfn_t_devmap(pfn)) - entry =3D pud_mkdevmap(entry); if (write) { entry =3D pud_mkyoung(pud_mkdirty(entry)); entry =3D maybe_pud_mkwrite(entry, vma); @@ -1421,8 +1415,6 @@ vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, p= fn_t pfn, bool write) * but we need to be consistent with PTEs and architectures that * can't support a 'special' bit. */ - BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) && - !pfn_t_devmap(pfn)); BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) =3D=3D (VM_PFNMAP|VM_MIXEDMAP)); BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags)); @@ -1493,46 +1485,6 @@ void touch_pmd(struct vm_area_struct *vma, unsigned = long addr, update_mmu_cache_pmd(vma, addr, pmd); } =20 -struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long a= ddr, - pmd_t *pmd, int flags, struct dev_pagemap **pgmap) -{ - unsigned long pfn =3D pmd_pfn(*pmd); - struct mm_struct *mm =3D vma->vm_mm; - struct page *page; - int ret; - - assert_spin_locked(pmd_lockptr(mm, pmd)); - - if (flags & FOLL_WRITE && !pmd_write(*pmd)) - return NULL; - - if (pmd_present(*pmd) && pmd_devmap(*pmd)) - /* pass */; - else - return NULL; - - if (flags & FOLL_TOUCH) - touch_pmd(vma, addr, pmd, flags & FOLL_WRITE); - - /* - * device mapped pages can only be returned if the - * caller will manage the page reference count. - */ - if (!(flags & (FOLL_GET | FOLL_PIN))) - return ERR_PTR(-EEXIST); - - pfn +=3D (addr & ~PMD_MASK) >> PAGE_SHIFT; - *pgmap =3D get_dev_pagemap(pfn, *pgmap); - if (!*pgmap) - return ERR_PTR(-EFAULT); - page =3D pfn_to_page(pfn); - ret =3D try_grab_folio(page_folio(page), 1, flags); - if (ret) - page =3D ERR_PTR(ret); - - return page; -} - int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, pmd_t *dst_pmd, pmd_t *src_pmd, unsigned long addr, struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) @@ -1664,7 +1616,7 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm= _struct *src_mm, =20 ret =3D -EAGAIN; pud =3D *src_pud; - if (unlikely(!pud_trans_huge(pud) && !pud_devmap(pud))) + if (unlikely(!pud_trans_huge(pud))) goto out_unlock; =20 /* @@ -2473,8 +2425,7 @@ spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, struct = vm_area_struct *vma) { spinlock_t *ptl; ptl =3D pmd_lock(vma->vm_mm, pmd); - if (likely(is_swap_pmd(*pmd) || pmd_trans_huge(*pmd) || - pmd_devmap(*pmd))) + if (likely(is_swap_pmd(*pmd) || pmd_trans_huge(*pmd))) return ptl; spin_unlock(ptl); return NULL; @@ -2491,7 +2442,7 @@ spinlock_t *__pud_trans_huge_lock(pud_t *pud, struct = vm_area_struct *vma) spinlock_t *ptl; =20 ptl =3D pud_lock(vma->vm_mm, pud); - if (likely(pud_trans_huge(*pud) || pud_devmap(*pud))) + if (likely(pud_trans_huge(*pud))) return ptl; spin_unlock(ptl); return NULL; @@ -2541,7 +2492,7 @@ static void __split_huge_pud_locked(struct vm_area_st= ruct *vma, pud_t *pud, VM_BUG_ON(haddr & ~HPAGE_PUD_MASK); VM_BUG_ON_VMA(vma->vm_start > haddr, vma); VM_BUG_ON_VMA(vma->vm_end < haddr + HPAGE_PUD_SIZE, vma); - VM_BUG_ON(!pud_trans_huge(*pud) && !pud_devmap(*pud)); + VM_BUG_ON(!pud_trans_huge(*pud)); =20 count_vm_event(THP_SPLIT_PUD); =20 @@ -2575,7 +2526,7 @@ void __split_huge_pud(struct vm_area_struct *vma, pud= _t *pud, (address & HPAGE_PUD_MASK) + HPAGE_PUD_SIZE); mmu_notifier_invalidate_range_start(&range); ptl =3D pud_lock(vma->vm_mm, pud); - if (unlikely(!pud_trans_huge(*pud) && !pud_devmap(*pud))) + if (unlikely(!pud_trans_huge(*pud))) goto out; __split_huge_pud_locked(vma, pud, range.start); =20 @@ -2648,8 +2599,7 @@ static void __split_huge_pmd_locked(struct vm_area_st= ruct *vma, pmd_t *pmd, VM_BUG_ON(haddr & ~HPAGE_PMD_MASK); VM_BUG_ON_VMA(vma->vm_start > haddr, vma); VM_BUG_ON_VMA(vma->vm_end < haddr + HPAGE_PMD_SIZE, vma); - VM_BUG_ON(!is_pmd_migration_entry(*pmd) && !pmd_trans_huge(*pmd) - && !pmd_devmap(*pmd)); + VM_BUG_ON(!is_pmd_migration_entry(*pmd) && !pmd_trans_huge(*pmd)); =20 count_vm_event(THP_SPLIT_PMD); =20 @@ -2866,8 +2816,7 @@ void split_huge_pmd_locked(struct vm_area_struct *vma= , unsigned long address, * require a folio to check the PMD against. Otherwise, there * is a risk of replacing the wrong folio. */ - if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd) || - is_pmd_migration_entry(*pmd)) { + if (pmd_trans_huge(*pmd) || is_pmd_migration_entry(*pmd)) { if (folio && folio !=3D pmd_folio(*pmd)) return; __split_huge_pmd_locked(vma, pmd, address, freeze); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 4a83c40..4e3ed2f 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -961,8 +961,6 @@ static int find_pmd_or_thp_or_none(struct mm_struct *mm, return SCAN_PMD_NULL; if (pmd_trans_huge(pmde)) return SCAN_PMD_MAPPED; - if (pmd_devmap(pmde)) - return SCAN_PMD_NULL; if (pmd_bad(pmde)) return SCAN_PMD_NULL; return SCAN_SUCCEED; diff --git a/mm/mapping_dirty_helpers.c b/mm/mapping_dirty_helpers.c index 2f8829b..208b428 100644 --- a/mm/mapping_dirty_helpers.c +++ b/mm/mapping_dirty_helpers.c @@ -129,7 +129,7 @@ static int wp_clean_pmd_entry(pmd_t *pmd, unsigned long= addr, unsigned long end, pmd_t pmdval =3D pmdp_get_lockless(pmd); =20 /* Do not split a huge pmd, present or migrated */ - if (pmd_trans_huge(pmdval) || pmd_devmap(pmdval)) { + if (pmd_trans_huge(pmdval)) { WARN_ON(pmd_write(pmdval) || pmd_dirty(pmdval)); walk->action =3D ACTION_CONTINUE; } @@ -152,7 +152,7 @@ static int wp_clean_pud_entry(pud_t *pud, unsigned long= addr, unsigned long end, pud_t pudval =3D READ_ONCE(*pud); =20 /* Do not split a huge pud */ - if (pud_trans_huge(pudval) || pud_devmap(pudval)) { + if (pud_trans_huge(pudval)) { WARN_ON(pud_write(pudval) || pud_dirty(pudval)); walk->action =3D ACTION_CONTINUE; } diff --git a/mm/memory.c b/mm/memory.c index cc692d6..0008735 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -604,16 +604,6 @@ struct page *vm_normal_page(struct vm_area_struct *vma= , unsigned long addr, return NULL; if (is_zero_pfn(pfn)) return NULL; - if (pte_devmap(pte)) - /* - * NOTE: New users of ZONE_DEVICE will not set pte_devmap() - * and will have refcounts incremented on their struct pages - * when they are inserted into PTEs, thus they are safe to - * return here. Legacy ZONE_DEVICE pages that set pte_devmap() - * do not have refcounts. Example of legacy ZONE_DEVICE is - * MEMORY_DEVICE_FS_DAX type in pmem or virtio_fs drivers. - */ - return NULL; =20 print_bad_pte(vma, addr, pte, NULL); return NULL; @@ -692,8 +682,6 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *= vma, unsigned long addr, } } =20 - if (pmd_devmap(pmd)) - return NULL; if (is_huge_zero_pmd(pmd)) return NULL; if (unlikely(pfn > highest_memmap_pfn)) @@ -1235,8 +1223,7 @@ copy_pmd_range(struct vm_area_struct *dst_vma, struct= vm_area_struct *src_vma, src_pmd =3D pmd_offset(src_pud, addr); do { next =3D pmd_addr_end(addr, end); - if (is_swap_pmd(*src_pmd) || pmd_trans_huge(*src_pmd) - || pmd_devmap(*src_pmd)) { + if (is_swap_pmd(*src_pmd) || pmd_trans_huge(*src_pmd)) { int err; VM_BUG_ON_VMA(next-addr !=3D HPAGE_PMD_SIZE, src_vma); err =3D copy_huge_pmd(dst_mm, src_mm, dst_pmd, src_pmd, @@ -1272,7 +1259,7 @@ copy_pud_range(struct vm_area_struct *dst_vma, struct= vm_area_struct *src_vma, src_pud =3D pud_offset(src_p4d, addr); do { next =3D pud_addr_end(addr, end); - if (pud_trans_huge(*src_pud) || pud_devmap(*src_pud)) { + if (pud_trans_huge(*src_pud)) { int err; =20 VM_BUG_ON_VMA(next-addr !=3D HPAGE_PUD_SIZE, src_vma); @@ -1710,7 +1697,7 @@ static inline unsigned long zap_pmd_range(struct mmu_= gather *tlb, pmd =3D pmd_offset(pud, addr); do { next =3D pmd_addr_end(addr, end); - if (is_swap_pmd(*pmd) || pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) { + if (is_swap_pmd(*pmd) || pmd_trans_huge(*pmd)) { if (next - addr !=3D HPAGE_PMD_SIZE) __split_huge_pmd(vma, pmd, addr, false, NULL); else if (zap_huge_pmd(tlb, vma, pmd, addr)) { @@ -1752,7 +1739,7 @@ static inline unsigned long zap_pud_range(struct mmu_= gather *tlb, pud =3D pud_offset(p4d, addr); do { next =3D pud_addr_end(addr, end); - if (pud_trans_huge(*pud) || pud_devmap(*pud)) { + if (pud_trans_huge(*pud)) { if (next - addr !=3D HPAGE_PUD_SIZE) { mmap_assert_locked(tlb->mm); split_huge_pud(vma, pud, addr); @@ -2375,10 +2362,7 @@ static vm_fault_t insert_pfn(struct vm_area_struct *= vma, unsigned long addr, } =20 /* Ok, finally just insert the thing.. */ - if (pfn_t_devmap(pfn)) - entry =3D pte_mkdevmap(pfn_t_pte(pfn, prot)); - else - entry =3D pte_mkspecial(pfn_t_pte(pfn, prot)); + entry =3D pte_mkspecial(pfn_t_pte(pfn, prot)); =20 if (mkwrite) { entry =3D pte_mkyoung(entry); @@ -2489,8 +2473,6 @@ static bool vm_mixed_ok(struct vm_area_struct *vma, p= fn_t pfn, bool mkwrite) /* these checks mirror the abort conditions in vm_normal_page */ if (vma->vm_flags & VM_MIXEDMAP) return true; - if (pfn_t_devmap(pfn)) - return true; if (pfn_t_special(pfn)) return true; if (is_zero_pfn(pfn_t_to_pfn(pfn))) @@ -2522,8 +2504,7 @@ static vm_fault_t __vm_insert_mixed(struct vm_area_st= ruct *vma, * than insert_pfn). If a zero_pfn were inserted into a VM_MIXEDMAP * without pte special, it would there be refcounted as a normal page. */ - if (!IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL) && - !pfn_t_devmap(pfn) && pfn_t_valid(pfn)) { + if (!IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL) && pfn_t_valid(pfn)) { struct page *page; =20 /* @@ -2568,8 +2549,6 @@ vm_fault_t dax_insert_pfn(struct vm_fault *vmf, pfn_t= pfn_t, bool write) if (!pfn_t_valid(pfn_t)) return VM_FAULT_SIGBUS; =20 - WARN_ON_ONCE(pfn_t_devmap(pfn_t)); - if (WARN_ON(is_zero_pfn(pfn) && write)) return VM_FAULT_SIGBUS; =20 @@ -5678,7 +5657,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_st= ruct *vma, pud_t orig_pud =3D *vmf.pud; =20 barrier(); - if (pud_trans_huge(orig_pud) || pud_devmap(orig_pud)) { + if (pud_trans_huge(orig_pud)) { =20 /* * TODO once we support anonymous PUDs: NUMA case and @@ -5719,7 +5698,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_st= ruct *vma, pmd_migration_entry_wait(mm, vmf.pmd); return 0; } - if (pmd_trans_huge(vmf.orig_pmd) || pmd_devmap(vmf.orig_pmd)) { + if (pmd_trans_huge(vmf.orig_pmd)) { if (pmd_protnone(vmf.orig_pmd) && vma_is_accessible(vma)) return do_huge_pmd_numa_page(&vmf); =20 diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 9d30107..f8c4baf 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -599,7 +599,7 @@ static void migrate_vma_insert_page(struct migrate_vma = *migrate, pmdp =3D pmd_alloc(mm, pudp, addr); if (!pmdp) goto abort; - if (pmd_trans_huge(*pmdp) || pmd_devmap(*pmdp)) + if (pmd_trans_huge(*pmdp)) goto abort; if (pte_alloc(mm, pmdp)) goto abort; diff --git a/mm/mprotect.c b/mm/mprotect.c index 0c5d6d0..e6b721d 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -382,7 +382,7 @@ static inline long change_pmd_range(struct mmu_gather *= tlb, goto next; =20 _pmd =3D pmdp_get_lockless(pmd); - if (is_swap_pmd(_pmd) || pmd_trans_huge(_pmd) || pmd_devmap(_pmd)) { + if (is_swap_pmd(_pmd) || pmd_trans_huge(_pmd)) { if ((next - addr !=3D HPAGE_PMD_SIZE) || pgtable_split_needed(vma, cp_flags)) { __split_huge_pmd(vma, pmd, addr, false, NULL); diff --git a/mm/mremap.c b/mm/mremap.c index 24712f8..a0f111c 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -587,7 +587,7 @@ unsigned long move_page_tables(struct vm_area_struct *v= ma, new_pud =3D alloc_new_pud(vma->vm_mm, vma, new_addr); if (!new_pud) break; - if (pud_trans_huge(*old_pud) || pud_devmap(*old_pud)) { + if (pud_trans_huge(*old_pud)) { if (extent =3D=3D HPAGE_PUD_SIZE) { move_pgt_entry(HPAGE_PUD, vma, old_addr, new_addr, old_pud, new_pud, need_rmap_locks); @@ -609,8 +609,7 @@ unsigned long move_page_tables(struct vm_area_struct *v= ma, if (!new_pmd) break; again: - if (is_swap_pmd(*old_pmd) || pmd_trans_huge(*old_pmd) || - pmd_devmap(*old_pmd)) { + if (is_swap_pmd(*old_pmd) || pmd_trans_huge(*old_pmd)) { if (extent =3D=3D HPAGE_PMD_SIZE && move_pgt_entry(HPAGE_PMD, vma, old_addr, new_addr, old_pmd, new_pmd, need_rmap_locks)) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index ae5cc42..77da636 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -235,8 +235,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *= pvmw) */ pmde =3D pmdp_get_lockless(pvmw->pmd); =20 - if (pmd_trans_huge(pmde) || is_pmd_migration_entry(pmde) || - (pmd_present(pmde) && pmd_devmap(pmde))) { + if (pmd_trans_huge(pmde) || is_pmd_migration_entry(pmde)) { pvmw->ptl =3D pmd_lock(mm, pvmw->pmd); pmde =3D *pvmw->pmd; if (!pmd_present(pmde)) { @@ -251,7 +250,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *= pvmw) return not_found(pvmw); return true; } - if (likely(pmd_trans_huge(pmde) || pmd_devmap(pmde))) { + if (likely(pmd_trans_huge(pmde))) { if (pvmw->flags & PVMW_MIGRATION) return not_found(pvmw); if (!check_pmd(pmd_pfn(pmde), pvmw)) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index cd79fb3..09a3ee4 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -753,7 +753,7 @@ struct folio *folio_walk_start(struct folio_walk *fw, fw->pudp =3D pudp; fw->pud =3D pud; =20 - if (!pud_present(pud) || pud_devmap(pud)) { + if (!pud_present(pud)) { spin_unlock(ptl); goto not_found; } else if (!pud_leaf(pud)) { @@ -765,6 +765,12 @@ struct folio *folio_walk_start(struct folio_walk *fw, * support PUD mappings in VM_PFNMAP|VM_MIXEDMAP VMAs. */ page =3D pud_page(pud); + + if (is_device_dax_page(page)) { + spin_unlock(ptl); + goto not_found; + } + goto found; } =20 diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c index a78a4ad..093c435 100644 --- a/mm/pgtable-generic.c +++ b/mm/pgtable-generic.c @@ -139,8 +139,7 @@ pmd_t pmdp_huge_clear_flush(struct vm_area_struct *vma,= unsigned long address, { pmd_t pmd; VM_BUG_ON(address & ~HPAGE_PMD_MASK); - VM_BUG_ON(pmd_present(*pmdp) && !pmd_trans_huge(*pmdp) && - !pmd_devmap(*pmdp)); + VM_BUG_ON(pmd_present(*pmdp) && !pmd_trans_huge(*pmdp)); pmd =3D pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp); flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE); return pmd; @@ -153,7 +152,7 @@ pud_t pudp_huge_clear_flush(struct vm_area_struct *vma,= unsigned long address, pud_t pud; =20 VM_BUG_ON(address & ~HPAGE_PUD_MASK); - VM_BUG_ON(!pud_trans_huge(*pudp) && !pud_devmap(*pudp)); + VM_BUG_ON(!pud_trans_huge(*pudp)); pud =3D pudp_huge_get_and_clear(vma->vm_mm, address, pudp); flush_pud_tlb_range(vma, address, address + HPAGE_PUD_SIZE); return pud; @@ -293,7 +292,7 @@ pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr,= pmd_t *pmdvalp) *pmdvalp =3D pmdval; if (unlikely(pmd_none(pmdval) || is_pmd_migration_entry(pmdval))) goto nomap; - if (unlikely(pmd_trans_huge(pmdval) || pmd_devmap(pmdval))) + if (unlikely(pmd_trans_huge(pmdval))) goto nomap; if (unlikely(pmd_bad(pmdval))) { pmd_clear_bad(pmd); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 966e6c8..1ac83b3 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1679,7 +1679,7 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsig= ned long dst_start, =20 ptl =3D pmd_trans_huge_lock(src_pmd, src_vma); if (ptl) { - if (pmd_devmap(*src_pmd)) { + if (vma_is_dax(src_vma)) { spin_unlock(ptl); err =3D -ENOENT; break; diff --git a/mm/vmscan.c b/mm/vmscan.c index 1b1fad0..c4d261b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3322,7 +3322,7 @@ static unsigned long get_pte_pfn(pte_t pte, struct vm= _area_struct *vma, unsigned if (!pte_present(pte) || is_zero_pfn(pfn)) return -1; =20 - if (WARN_ON_ONCE(pte_devmap(pte) || pte_special(pte))) + if (WARN_ON_ONCE(pte_special(pte))) return -1; =20 if (WARN_ON_ONCE(!pfn_valid(pfn))) @@ -3340,9 +3340,6 @@ static unsigned long get_pmd_pfn(pmd_t pmd, struct vm= _area_struct *vma, unsigned if (!pmd_present(pmd) || is_huge_zero_pmd(pmd)) return -1; =20 - if (WARN_ON_ONCE(pmd_devmap(pmd))) - return -1; - if (WARN_ON_ONCE(!pfn_valid(pfn))) return -1; =20 --=20 git-series 0.9.1 From nobody Sat Nov 30 10:49:42 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2054.outbound.protection.outlook.com [40.107.220.54]) (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 AE90B193067; Tue, 10 Sep 2024 04:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941765; cv=fail; b=G5ZvNHduxEcdc0jla5+KxtFpIy14q+oo2CQ7wQijJqymZHnMmGD1/7gwjGUGVYiMQkAbprz23PCExkExaYn4RJRuLuCLVcDyr+pI1ByJ4wWX8TptNceqYXKhjzGZUB/dHUvEa3SoyYHJlTOzKQGheHzCyIzwlr4/y+xOBz9lVyA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941765; c=relaxed/simple; bh=ZDDnLD68UvQOGvV/UwP8zyczYFoRYm0bptMwhNPWKUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=oDihmNNhG0smhISfZRR0mb31PqQS9B2bH0Sgpi0XMZCnw1HOHsF8tu5MFF0f3rBu1OfRt0YurZ1xmhWSQhBU8KF4NQfcbq83HpRMI6Yunrp9gRNmSEOdtJX+qXBHqH13Ho2ijol3WtF4V7yX0qEE+UQpIvxQTf0tjFJwlIjFwJ4= 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=DA1HHclP; arc=fail smtp.client-ip=40.107.220.54 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="DA1HHclP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DVPlP/smIwUuv9UXKLFPUb0G3UF6TAIy72mf53Rop3f0LbG42Tw9nkrnuJreP0NinQeFes95+CFkfZG8q0H0A8T6ZOXOUEakbCyf+8XjfMY01khN9FD4UQBm9943WRfqPWpWNOu1bBO7xXH1ZjTXMn0BuO5ZrRGgFAxf5F5jzMlmR9ej1ApGdGrdiLsk4sxodKbOq36sMW+Mj7r61fpm0VegIsskanDBKzEGI1t9+GwYcBQajQ2ZPh0WnSIUXwgJZg+crpupnNXsMitAQF+TYQi/IXwoXbfARMO1sHI7A/e+OdZQomdchgaRXClszmFEHz8L+JdvcVkIoI9mMLmTDQ== 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=7SMUkeTzWk6c4iE6rjNyhyHm9o2LzNrSa+O2Uo2gc7Q=; b=B8K2Z95oCsh20vq0vGXSxBGGVo0YKcVfRJZVM2jVBq+MG/ScJdJlCGgHhgP/PeOCfJ/mbUBSrFouftvwbg+BRsNuVezpPr50XD+2YMpvzxlFLMrfg1lw2hQOcr9gePPrGb+O6Y0po+954t9H5jSG0kZck2vKDQgomYNpzqsUCxvMr/mrXxBoDGK59hW4mJbOq7WSYaI4FLJQ/pFPWOZ3JNgxherrPf5tl5shFyWk8EK0LJ+gc5tZJUlgiZJDSxODUOVGyPdw2LLRjZmAUef6pfGYoA8y/wK2kK9z2e51MLPqFbHe9biTk9flqzt9iJIH+2pRYiSk49pj8sjOL103EQ== 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=7SMUkeTzWk6c4iE6rjNyhyHm9o2LzNrSa+O2Uo2gc7Q=; b=DA1HHclPwFsrSPUFMtTjTkwPwvv9CRuB121jfKFCgFRUt4wVIN0kMwWdBg7lJdyknF9NOiGJ7S8dNjUQvhExdvud7yv6EompwbcX7PlBlo04aTbEoY5/5stgMIbGFTvzVA/oMqx1w5mHNXoANX9NKfROQ3FMnu82kbyeT7aPE+72IvxmJ+72iZv1gcPnS5mde4nhz+qcrNrApDIoB0fWqSTIILtZo4dyrWKicZKuhq5MQVcBq9HQ+eKIO4dXoLq+M2bkT7bsCHTs7WoeHfKKrktZ7XBYfyoqXY0iuuVTWkvOD6X5+kWYsF3nGhFXBWgtx9JiEJyOcHODFZFkVxIiUA== 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:59 +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:59 +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 12/12] mm: Remove devmap related functions and page table bits Date: Tue, 10 Sep 2024 14:14:37 +1000 Message-ID: <39b1a78aa16ebe5db1c4b723e44fbdd217d302ac.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SYCPR01CA0034.ausprd01.prod.outlook.com (2603:10c6:10:e::22) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-kernel@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: 8c6ad695-bef9-41df-3a9a-08dcd14f45fb 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: =?us-ascii?Q?ZqPB41i3tzHAG1VS1zvrugREewOLjXViHvSBJKybH87fMG0KwqMdPNdjOpB8?= =?us-ascii?Q?in/Vgl/9ImRr601MH+nGEnKL0a9XP+I/Dyq9Pp/cN2xhGuNFSp4cjHsVfYCv?= =?us-ascii?Q?cJ4tLGmoyiq1/Biy64byebisD04x5AFd0gQn+CgKglbObcAjmWYlYYjuY6Og?= =?us-ascii?Q?QI+WrcUbJIML0H+p0h6TvEgZOLs37JME0e1MnGeKvtuGWTiX5Mn16nJMoYQC?= =?us-ascii?Q?S7Thj1CGgJcm6CMFQUNkcQxYnfl9V7CjXo32pnNv8jTHMK9YZ77heIfLbB6f?= =?us-ascii?Q?oa1V2rXcnclq5YMTd5UANTmP+RVEJQ90y9UFc0r5ZKAIA0tuikbaRwN7dxPU?= =?us-ascii?Q?05BD2mAZoUXtyGXAO3s4dQk2CJbW1anjP686T1R3AWDPUZKwYHowAOJz3ILB?= =?us-ascii?Q?l2qDP1VouWEGV9GKW18FQajlCLn5kWQ64OHEd+mgGWwlnpLi3grqIjRznc3B?= =?us-ascii?Q?bG0zEPvQUn6wb5UaK6VF8vdaJ5kQRSMEd2rj2ZRgisri81cIBhuSmynxzd3E?= =?us-ascii?Q?2Nknl0gwKZF0LrI6LqeaeWdYYOpV7K2lYKqjH2b/UNdnLRCly2wQ4I6BX2Mo?= =?us-ascii?Q?mkQWRI3/MUFTy60Ih2UhTFz2SyfVf7V+uFTi3V1y8NkASlM1AjavZEiWOdpM?= =?us-ascii?Q?j7emK1RVIh67WQ8wz6Otni1eS1jYC5To2fpxd0kKGDAtLm0eUFgWKVFEetsf?= =?us-ascii?Q?b0N6ZGhoQSSqDzQK7BmxXx2GJ0QnxcWssen/xWtzyWe7XGVaM+0OoJLLJdms?= =?us-ascii?Q?RUsAJwXTiAqCy7FcS6LNKq4RvggqDhCML2ES78wIX1GIEWMtjnxbKhXNuHoi?= =?us-ascii?Q?oeCUvX7EFpLRmQJ9awLMQyrvyt78QrfEd4Ho46fCtt0KTOjEE/qZl19yiZwC?= =?us-ascii?Q?qkFKAmUgeGJsetafmR6Uf/Z5kSjAeiB7iuDGkCyz+cjoNUWwYXLms4LRUTnJ?= =?us-ascii?Q?V81rqLOidp/vjRG9elFL8PGF/0QhabXrkgisWr3lZfSNWuZg3f6roLPFMfPS?= =?us-ascii?Q?SQNtOh3tA/BEGQhQ6rufJ22m36ikM3tVblGLnSlvDmuXJDNSR6Gi1qIGsCxV?= =?us-ascii?Q?4c2BGW1svlvpUBbHTsR4YdbWRvtUqCRz/SRZYDOJMdQZSdLDFznNeFZd+ZQ1?= =?us-ascii?Q?eRhmpTY8w//ImiN1JaVewwG7pMZP0Q75IsrqyRtWWhfJedhJkQXZ9mv+Dxl5?= =?us-ascii?Q?xiPunDOCqvKIn9D0YKMEiaS3h6muDrV4vwu/p2P1Pj2VJbt38ZQxSqwe74eT?= =?us-ascii?Q?weP5eGISHN2m324MVnSdN7bFByMutJ8NP5xnaxYbgopdOx/uhlD8RJoSiQty?= =?us-ascii?Q?YYXM1yNhgiDl8OaG5sThJLWUXw7DhFMUQIbK69TXPzd+1w=3D=3D?= 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: =?us-ascii?Q?lreiPlExgUqJova0xZzIYi/s1jgXyKsl70n1XU74JC2x1zwA4XVK2PLZofnV?= =?us-ascii?Q?b87EWpZebQb+9sBitZvKhAbt6ACE6iX77X2NQ8phjCe4R55+RaECVNrQiDSD?= =?us-ascii?Q?DeWNjLRrMavDnR6I77RoFB8vmmK4WEg17QYiFgrSFjC54AbIceoOLCnB23PR?= =?us-ascii?Q?jYkMQyYciZKz/fHkvyGcvZfKiFei77UoxRduKFFJ00TdFJh3W2266qFwLWni?= =?us-ascii?Q?c4/icHo0kkxSiDntIPE35NoL7ZGHHXDG0hf/fGH6Q2TnDMIW1sLMQtoFF0qL?= =?us-ascii?Q?rozhwuI+bLnn7cnjdiBeaHjSWA5Ly2U3E7qnnZZ9nygr9HGZzU2gKSlNBPJq?= =?us-ascii?Q?7HEUdfEYvKFpDlr3Gu2d0Fpxf54UtUc8ZrLmDvPIXv8Vsla6Eha79lwtK/7n?= =?us-ascii?Q?L4F3EDTIS4J+syvPXjA5kAL9zCI4Gv7Oc0srKnStKt70Zbm5ZCg2rwJ/dGML?= =?us-ascii?Q?xGO2YIqYEMafP65ueG62rz46f5ScsDJynrv1KEG1teDPaNkbso+/VdMIF6Z2?= =?us-ascii?Q?O5XU25OxWD4FejcSP0ZtUFolJtvRYNp9WGZkHTYSzAy3877W7xbR6FOSE6OV?= =?us-ascii?Q?DGXarlITXksWkG3nmTptZmqsWkJZ9vHSMCNmOtWFaCdFMYjz2CAWQe+8yHuj?= =?us-ascii?Q?ybb3uWWTZVXekNhUBhe8zQ7bbOL/3ZKjlYn8e3s7y374GZX5Zah1QhimA7tq?= =?us-ascii?Q?PcQh064n2DU/CzwCJFiCqnoo7fXE29srKxWj6XbztMeCPaR6EiMchPiXivf6?= =?us-ascii?Q?ewAIX8emsVC4q8W2drGibMg61Z+hMfYuvrv3B9DIUVr03DT6X5BqZwmexd18?= =?us-ascii?Q?yty8gzcrF3YBwQavzpnHq1t2pu0Sk+VSg7UJqp6i3qwx10xA6GnYz/JKk1rn?= =?us-ascii?Q?K+mOqx9/OerqrGf/oz2g39SdjpzKxWlkTHvgaTsS49avEaF12ODT/JwOO2lH?= =?us-ascii?Q?iptLX/qSZuSca6UKABWMkrmxLYKMD2t9iv6uzPjyAqqAIgNDV0gsbOCc92ne?= =?us-ascii?Q?1EWxu559fFxqbewmdTnnhBgDRymM16fkisPEpFg7xsokgCwh56SW/pCRx7Tr?= =?us-ascii?Q?25W0+QmScD4fyEnv9c4CmsyMwfMM1DanbNWmxamDlN3dhG48zWzww0WqVhWl?= =?us-ascii?Q?a+UlGanFqvhoFooqj+OwxggmQhXubZdXhCXKHkNp4D7Hn++gEbIP5t17jdbF?= =?us-ascii?Q?v1FNh/ZmGw99t6v1lYxtsPgIEIjMvKPh3IlWpzuu4ajH8E9RMPRVtHbEMj5x?= =?us-ascii?Q?i61sdz1OuHBNt7d9sBaJMmtRI82XMuezaTDHx5uL1Cr08ULg4XvljM+QmHbf?= =?us-ascii?Q?+0qT1TCZUWVJPF099W4rhLr9f5IQgwNkbWqTolFSA1flXpTkDpuVGfdjSZfd?= =?us-ascii?Q?fefyC66qv3/xUvWF2m4KXW5ZCmINSvwEdOOqQ6yS6HqiajZyv1v79kN3wsF0?= =?us-ascii?Q?pNUOpfuS2qqnUP7+pVlXKAYUUfKdZcH+NQB/KNYbswimaK0gQwUjbNMGhnLU?= =?us-ascii?Q?LLvOkBdLzlZyHlrcnqIa8OTVfI1W3e0mNiQdHYrtzddKXayi38k7Jz0gEde/?= =?us-ascii?Q?zsAO9wCXqs0Nxd3X4gUvg6ZRJFnWzYpvBSRWkIgS?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c6ad695-bef9-41df-3a9a-08dcd14f45fb 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:58.9614 (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: Ws2Z61tZ3nhpzS8/N3UNVdkSF8cKfUXf11B86GsH2q9YGzH48sh/uZSgBQiIPywyGeeA/UCWWnNh1XiRKd0fLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8088 Content-Type: text/plain; charset="utf-8" Now that DAX and all other reference counts to ZONE_DEVICE pages are managed normally there is no need for the special devmap PTE/PMD/PUD page table bits. So drop all references to these, freeing up a software defined page table bit on architectures supporting it. Signed-off-by: Alistair Popple Acked-by: Will Deacon # arm64 --- Documentation/mm/arch_pgtable_helpers.rst | 6 +-- arch/arm64/Kconfig | 1 +- arch/arm64/include/asm/pgtable-prot.h | 1 +- arch/arm64/include/asm/pgtable.h | 24 +-------- arch/powerpc/Kconfig | 1 +- arch/powerpc/include/asm/book3s/64/hash-4k.h | 6 +-- arch/powerpc/include/asm/book3s/64/hash-64k.h | 7 +-- arch/powerpc/include/asm/book3s/64/pgtable.h | 52 +------------------ arch/powerpc/include/asm/book3s/64/radix.h | 14 +----- arch/x86/Kconfig | 1 +- arch/x86/include/asm/pgtable.h | 50 +----------------- arch/x86/include/asm/pgtable_types.h | 5 +-- include/linux/mm.h | 7 +-- include/linux/pfn_t.h | 20 +------- include/linux/pgtable.h | 19 +------ mm/Kconfig | 4 +- mm/debug_vm_pgtable.c | 59 +-------------------- mm/hmm.c | 3 +- 18 files changed, 11 insertions(+), 269 deletions(-) diff --git a/Documentation/mm/arch_pgtable_helpers.rst b/Documentation/mm/a= rch_pgtable_helpers.rst index af24516..c88c7fa 100644 --- a/Documentation/mm/arch_pgtable_helpers.rst +++ b/Documentation/mm/arch_pgtable_helpers.rst @@ -30,8 +30,6 @@ PTE Page Table Helpers +---------------------------+---------------------------------------------= -----+ | pte_protnone | Tests a PROT_NONE PTE = | +---------------------------+---------------------------------------------= -----+ -| pte_devmap | Tests a ZONE_DEVICE mapped PTE = | -+---------------------------+---------------------------------------------= -----+ | pte_soft_dirty | Tests a soft dirty PTE = | +---------------------------+---------------------------------------------= -----+ | pte_swp_soft_dirty | Tests a soft dirty swapped PTE = | @@ -104,8 +102,6 @@ PMD Page Table Helpers +---------------------------+---------------------------------------------= -----+ | pmd_protnone | Tests a PROT_NONE PMD = | +---------------------------+---------------------------------------------= -----+ -| pmd_devmap | Tests a ZONE_DEVICE mapped PMD = | -+---------------------------+---------------------------------------------= -----+ | pmd_soft_dirty | Tests a soft dirty PMD = | +---------------------------+---------------------------------------------= -----+ | pmd_swp_soft_dirty | Tests a soft dirty swapped PMD = | @@ -177,8 +173,6 @@ PUD Page Table Helpers +---------------------------+---------------------------------------------= -----+ | pud_write | Tests a writable PUD = | +---------------------------+---------------------------------------------= -----+ -| pud_devmap | Tests a ZONE_DEVICE mapped PUD = | -+---------------------------+---------------------------------------------= -----+ | pud_mkyoung | Creates a young PUD = | +---------------------------+---------------------------------------------= -----+ | pud_mkold | Creates an old PUD = | diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 6494848..b6d9c29 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -36,7 +36,6 @@ config ARM64 select ARCH_HAS_MEMBARRIER_SYNC_CORE select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE - select ARCH_HAS_PTE_DEVMAP select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_HW_PTE_YOUNG select ARCH_HAS_SETUP_DMA_OPS diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm= /pgtable-prot.h index b11cfb9..043b102 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -17,7 +17,6 @@ #define PTE_SWP_EXCLUSIVE (_AT(pteval_t, 1) << 2) /* only for swp ptes */ #define PTE_DIRTY (_AT(pteval_t, 1) << 55) #define PTE_SPECIAL (_AT(pteval_t, 1) << 56) -#define PTE_DEVMAP (_AT(pteval_t, 1) << 57) =20 /* * PTE_PRESENT_INVALID=3D1 & PTE_VALID=3D0 indicates that the pte's fields= should be diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index 7a4f560..d21b6c9 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -107,7 +107,6 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t ph= ys) #define pte_user(pte) (!!(pte_val(pte) & PTE_USER)) #define pte_user_exec(pte) (!(pte_val(pte) & PTE_UXN)) #define pte_cont(pte) (!!(pte_val(pte) & PTE_CONT)) -#define pte_devmap(pte) (!!(pte_val(pte) & PTE_DEVMAP)) #define pte_tagged(pte) ((pte_val(pte) & PTE_ATTRINDX_MASK) =3D=3D \ PTE_ATTRINDX(MT_NORMAL_TAGGED)) =20 @@ -269,11 +268,6 @@ static inline pmd_t pmd_mkcont(pmd_t pmd) return __pmd(pmd_val(pmd) | PMD_SECT_CONT); } =20 -static inline pte_t pte_mkdevmap(pte_t pte) -{ - return set_pte_bit(pte, __pgprot(PTE_DEVMAP | PTE_SPECIAL)); -} - #ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP static inline int pte_uffd_wp(pte_t pte) { @@ -569,14 +563,6 @@ static inline int pmd_trans_huge(pmd_t pmd) =20 #define pmd_mkhuge(pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT)) =20 -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -#define pmd_devmap(pmd) pte_devmap(pmd_pte(pmd)) -#endif -static inline pmd_t pmd_mkdevmap(pmd_t pmd) -{ - return pte_pmd(set_pte_bit(pmd_pte(pmd), __pgprot(PTE_DEVMAP))); -} - #define __pmd_to_phys(pmd) __pte_to_phys(pmd_pte(pmd)) #define __phys_to_pmd_val(phys) __phys_to_pte_val(phys) #define pmd_pfn(pmd) ((__pmd_to_phys(pmd) & PMD_MASK) >> PAGE_SHIFT) @@ -1136,16 +1122,6 @@ static inline int pmdp_set_access_flags(struct vm_ar= ea_struct *vma, return __ptep_set_access_flags(vma, address, (pte_t *)pmdp, pmd_pte(entry), dirty); } - -static inline int pud_devmap(pud_t pud) -{ - return 0; -} - -static inline int pgd_devmap(pgd_t pgd) -{ - return 0; -} #endif =20 #ifdef CONFIG_PAGE_TABLE_CHECK diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index d7b09b0..8094e48 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -144,7 +144,6 @@ config PPC select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE select ARCH_HAS_PHYS_TO_DMA select ARCH_HAS_PMEM_API - select ARCH_HAS_PTE_DEVMAP if PPC_BOOK3S_64 select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE && PPC_BOOK= 3S_64 select ARCH_HAS_SET_MEMORY diff --git a/arch/powerpc/include/asm/book3s/64/hash-4k.h b/arch/powerpc/in= clude/asm/book3s/64/hash-4k.h index c654c37..d23244b 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-4k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-4k.h @@ -140,12 +140,6 @@ extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_s= truct *mm, extern int hash__has_transparent_hugepage(void); #endif =20 -static inline pmd_t hash__pmd_mkdevmap(pmd_t pmd) -{ - BUG(); - return pmd; -} - #endif /* !__ASSEMBLY__ */ =20 #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */ diff --git a/arch/powerpc/include/asm/book3s/64/hash-64k.h b/arch/powerpc/i= nclude/asm/book3s/64/hash-64k.h index 0bf6fd0..0fb5b7d 100644 --- a/arch/powerpc/include/asm/book3s/64/hash-64k.h +++ b/arch/powerpc/include/asm/book3s/64/hash-64k.h @@ -259,7 +259,7 @@ static inline void mark_hpte_slot_valid(unsigned char *= hpte_slot_array, */ static inline int hash__pmd_trans_huge(pmd_t pmd) { - return !!((pmd_val(pmd) & (_PAGE_PTE | H_PAGE_THP_HUGE | _PAGE_DEVMAP)) = =3D=3D + return !!((pmd_val(pmd) & (_PAGE_PTE | H_PAGE_THP_HUGE)) =3D=3D (_PAGE_PTE | H_PAGE_THP_HUGE)); } =20 @@ -281,11 +281,6 @@ extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_s= truct *mm, extern int hash__has_transparent_hugepage(void); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 -static inline pmd_t hash__pmd_mkdevmap(pmd_t pmd) -{ - return __pmd(pmd_val(pmd) | (_PAGE_PTE | H_PAGE_THP_HUGE | _PAGE_DEVMAP)); -} - #endif /* __ASSEMBLY__ */ =20 #endif /* _ASM_POWERPC_BOOK3S_64_HASH_64K_H */ diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/in= clude/asm/book3s/64/pgtable.h index 5da92ba..9bf54b5 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -88,7 +88,6 @@ =20 #define _PAGE_SOFT_DIRTY _RPAGE_SW3 /* software: software dirty tracking */ #define _PAGE_SPECIAL _RPAGE_SW2 /* software: special page */ -#define _PAGE_DEVMAP _RPAGE_SW1 /* software: ZONE_DEVICE page */ =20 /* * Drivers request for cache inhibited pte mapping using _PAGE_NO_CACHE @@ -109,7 +108,7 @@ */ #define _HPAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \ _PAGE_ACCESSED | H_PAGE_THP_HUGE | _PAGE_PTE | \ - _PAGE_SOFT_DIRTY | _PAGE_DEVMAP) + _PAGE_SOFT_DIRTY) /* * user access blocked by key */ @@ -123,7 +122,7 @@ */ #define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \ _PAGE_ACCESSED | _PAGE_SPECIAL | _PAGE_PTE | \ - _PAGE_SOFT_DIRTY | _PAGE_DEVMAP) + _PAGE_SOFT_DIRTY) =20 /* * We define 2 sets of base prot bits, one for basic pages (ie, @@ -635,24 +634,6 @@ static inline pte_t pte_mkhuge(pte_t pte) return pte; } =20 -static inline pte_t pte_mkdevmap(pte_t pte) -{ - return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_SPECIAL | _PAGE_DEVMAP)= ); -} - -/* - * This is potentially called with a pmd as the argument, in which case it= 's not - * safe to check _PAGE_DEVMAP unless we also confirm that _PAGE_PTE is set. - * That's because the bit we use for _PAGE_DEVMAP is not reserved for soft= ware - * use in page directory entries (ie. non-ptes). - */ -static inline int pte_devmap(pte_t pte) -{ - __be64 mask =3D cpu_to_be64(_PAGE_DEVMAP | _PAGE_PTE); - - return (pte_raw(pte) & mask) =3D=3D mask; -} - static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) { /* FIXME!! check whether this need to be a conditional */ @@ -1406,35 +1387,6 @@ static inline bool arch_needs_pgtable_deposit(void) } extern void serialize_against_pte_lookup(struct mm_struct *mm); =20 - -static inline pmd_t pmd_mkdevmap(pmd_t pmd) -{ - if (radix_enabled()) - return radix__pmd_mkdevmap(pmd); - return hash__pmd_mkdevmap(pmd); -} - -static inline pud_t pud_mkdevmap(pud_t pud) -{ - if (radix_enabled()) - return radix__pud_mkdevmap(pud); - BUG(); - return pud; -} - -static inline int pmd_devmap(pmd_t pmd) -{ - return pte_devmap(pmd_pte(pmd)); -} - -static inline int pud_devmap(pud_t pud) -{ - return pte_devmap(pud_pte(pud)); -} - -static inline int pgd_devmap(pgd_t pgd) -{ - return 0; } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/incl= ude/asm/book3s/64/radix.h index 8f55ff7..df23a82 100644 --- a/arch/powerpc/include/asm/book3s/64/radix.h +++ b/arch/powerpc/include/asm/book3s/64/radix.h @@ -264,7 +264,7 @@ static inline int radix__p4d_bad(p4d_t p4d) =20 static inline int radix__pmd_trans_huge(pmd_t pmd) { - return (pmd_val(pmd) & (_PAGE_PTE | _PAGE_DEVMAP)) =3D=3D _PAGE_PTE; + return (pmd_val(pmd) & _PAGE_PTE) =3D=3D _PAGE_PTE; } =20 static inline pmd_t radix__pmd_mkhuge(pmd_t pmd) @@ -274,7 +274,7 @@ static inline pmd_t radix__pmd_mkhuge(pmd_t pmd) =20 static inline int radix__pud_trans_huge(pud_t pud) { - return (pud_val(pud) & (_PAGE_PTE | _PAGE_DEVMAP)) =3D=3D _PAGE_PTE; + return (pud_val(pud) & _PAGE_PTE) =3D=3D _PAGE_PTE; } =20 static inline pud_t radix__pud_mkhuge(pud_t pud) @@ -315,16 +315,6 @@ static inline int radix__has_transparent_pud_hugepage(= void) } #endif =20 -static inline pmd_t radix__pmd_mkdevmap(pmd_t pmd) -{ - return __pmd(pmd_val(pmd) | (_PAGE_PTE | _PAGE_DEVMAP)); -} - -static inline pud_t radix__pud_mkdevmap(pud_t pud) -{ - return __pud(pud_val(pud) | (_PAGE_PTE | _PAGE_DEVMAP)); -} - struct vmem_altmap; struct dev_pagemap; extern int __meminit radix__vmemmap_create_mapping(unsigned long start, diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index b74b9ee..9177fe3 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -91,7 +91,6 @@ config X86 select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE select ARCH_HAS_PMEM_API if X86_64 - select ARCH_HAS_PTE_DEVMAP if X86_64 select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_HW_PTE_YOUNG select ARCH_HAS_NONLEAF_PMD_YOUNG if PGTABLE_LEVELS > 2 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 8d12bfa..b576a14 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -280,16 +280,15 @@ static inline bool pmd_leaf(pmd_t pte) } =20 #ifdef CONFIG_TRANSPARENT_HUGEPAGE -/* NOTE: when predicate huge page, consider also pmd_devmap, or use pmd_le= af */ static inline int pmd_trans_huge(pmd_t pmd) { - return (pmd_val(pmd) & (_PAGE_PSE|_PAGE_DEVMAP)) =3D=3D _PAGE_PSE; + return (pmd_val(pmd) & _PAGE_PSE) =3D=3D _PAGE_PSE; } =20 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD static inline int pud_trans_huge(pud_t pud) { - return (pud_val(pud) & (_PAGE_PSE|_PAGE_DEVMAP)) =3D=3D _PAGE_PSE; + return (pud_val(pud) & _PAGE_PSE) =3D=3D _PAGE_PSE; } #endif =20 @@ -299,29 +298,6 @@ static inline int has_transparent_hugepage(void) return boot_cpu_has(X86_FEATURE_PSE); } =20 -#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP -static inline int pmd_devmap(pmd_t pmd) -{ - return !!(pmd_val(pmd) & _PAGE_DEVMAP); -} - -#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static inline int pud_devmap(pud_t pud) -{ - return !!(pud_val(pud) & _PAGE_DEVMAP); -} -#else -static inline int pud_devmap(pud_t pud) -{ - return 0; -} -#endif - -static inline int pgd_devmap(pgd_t pgd) -{ - return 0; -} -#endif #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 static inline pte_t pte_set_flags(pte_t pte, pteval_t set) @@ -482,11 +458,6 @@ static inline pte_t pte_mkspecial(pte_t pte) return pte_set_flags(pte, _PAGE_SPECIAL); } =20 -static inline pte_t pte_mkdevmap(pte_t pte) -{ - return pte_set_flags(pte, _PAGE_SPECIAL|_PAGE_DEVMAP); -} - static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set) { pmdval_t v =3D native_pmd_val(pmd); @@ -572,11 +543,6 @@ static inline pmd_t pmd_mkwrite_shstk(pmd_t pmd) return pmd_set_flags(pmd, _PAGE_DIRTY); } =20 -static inline pmd_t pmd_mkdevmap(pmd_t pmd) -{ - return pmd_set_flags(pmd, _PAGE_DEVMAP); -} - static inline pmd_t pmd_mkhuge(pmd_t pmd) { return pmd_set_flags(pmd, _PAGE_PSE); @@ -656,11 +622,6 @@ static inline pud_t pud_mkdirty(pud_t pud) return pud_mksaveddirty(pud); } =20 -static inline pud_t pud_mkdevmap(pud_t pud) -{ - return pud_set_flags(pud, _PAGE_DEVMAP); -} - static inline pud_t pud_mkhuge(pud_t pud) { return pud_set_flags(pud, _PAGE_PSE); @@ -988,13 +949,6 @@ static inline int pte_present(pte_t a) return pte_flags(a) & (_PAGE_PRESENT | _PAGE_PROTNONE); } =20 -#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP -static inline int pte_devmap(pte_t a) -{ - return (pte_flags(a) & _PAGE_DEVMAP) =3D=3D _PAGE_DEVMAP; -} -#endif - #define pte_accessible pte_accessible static inline bool pte_accessible(struct mm_struct *mm, pte_t a) { diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pg= table_types.h index 2f32113..37c250f 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -33,7 +33,6 @@ #define _PAGE_BIT_CPA_TEST _PAGE_BIT_SOFTW1 #define _PAGE_BIT_UFFD_WP _PAGE_BIT_SOFTW2 /* userfaultfd wrprotected */ #define _PAGE_BIT_SOFT_DIRTY _PAGE_BIT_SOFTW3 /* software dirty tracking */ -#define _PAGE_BIT_DEVMAP _PAGE_BIT_SOFTW4 =20 #ifdef CONFIG_X86_64 #define _PAGE_BIT_SAVED_DIRTY _PAGE_BIT_SOFTW5 /* Saved Dirty bit */ @@ -117,11 +116,9 @@ =20 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE) #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX) -#define _PAGE_DEVMAP (_AT(u64, 1) << _PAGE_BIT_DEVMAP) #define _PAGE_SOFTW4 (_AT(pteval_t, 1) << _PAGE_BIT_SOFTW4) #else #define _PAGE_NX (_AT(pteval_t, 0)) -#define _PAGE_DEVMAP (_AT(pteval_t, 0)) #define _PAGE_SOFTW4 (_AT(pteval_t, 0)) #endif =20 @@ -148,7 +145,7 @@ #define _COMMON_PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \ _PAGE_SPECIAL | _PAGE_ACCESSED | \ _PAGE_DIRTY_BITS | _PAGE_SOFT_DIRTY | \ - _PAGE_DEVMAP | _PAGE_CC | _PAGE_UFFD_WP) + _PAGE_CC | _PAGE_UFFD_WP) #define _PAGE_CHG_MASK (_COMMON_PAGE_CHG_MASK | _PAGE_PAT) #define _HPAGE_CHG_MASK (_COMMON_PAGE_CHG_MASK | _PAGE_PSE | _PAGE_PAT_LAR= GE) =20 diff --git a/include/linux/mm.h b/include/linux/mm.h index 592b992..5976276 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2624,13 +2624,6 @@ static inline pte_t pte_mkspecial(pte_t pte) } #endif =20 -#ifndef CONFIG_ARCH_HAS_PTE_DEVMAP -static inline int pte_devmap(pte_t pte) -{ - return 0; -} -#endif - extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl); static inline pte_t *get_locked_pte(struct mm_struct *mm, unsigned long ad= dr, diff --git a/include/linux/pfn_t.h b/include/linux/pfn_t.h index 2d91482..0100ad8 100644 --- a/include/linux/pfn_t.h +++ b/include/linux/pfn_t.h @@ -97,26 +97,6 @@ static inline pud_t pfn_t_pud(pfn_t pfn, pgprot_t pgprot) #endif #endif =20 -#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP -static inline bool pfn_t_devmap(pfn_t pfn) -{ - const u64 flags =3D PFN_DEV|PFN_MAP; - - return (pfn.val & flags) =3D=3D flags; -} -#else -static inline bool pfn_t_devmap(pfn_t pfn) -{ - return false; -} -pte_t pte_mkdevmap(pte_t pte); -pmd_t pmd_mkdevmap(pmd_t pmd); -#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ - defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) -pud_t pud_mkdevmap(pud_t pud); -#endif -#endif /* CONFIG_ARCH_HAS_PTE_DEVMAP */ - #ifdef CONFIG_ARCH_HAS_PTE_SPECIAL static inline bool pfn_t_special(pfn_t pfn) { diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index a68e279..f3a95e3 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1616,21 +1616,6 @@ static inline int pud_write(pud_t pud) } #endif /* pud_write */ =20 -#if !defined(CONFIG_ARCH_HAS_PTE_DEVMAP) || !defined(CONFIG_TRANSPARENT_HU= GEPAGE) -static inline int pmd_devmap(pmd_t pmd) -{ - return 0; -} -static inline int pud_devmap(pud_t pud) -{ - return 0; -} -static inline int pgd_devmap(pgd_t pgd) -{ - return 0; -} -#endif - #if !defined(CONFIG_TRANSPARENT_HUGEPAGE) || \ !defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) static inline int pud_trans_huge(pud_t pud) @@ -1885,8 +1870,8 @@ typedef unsigned int pgtbl_mod_mask; * - It should contain a huge PFN, which points to a huge page larger than * PAGE_SIZE of the platform. The PFN format isn't important here. * - * - It should cover all kinds of huge mappings (e.g., pXd_trans_huge(), - * pXd_devmap(), or hugetlb mappings). + * - It should cover all kinds of huge mappings (i.e. pXd_trans_huge() + * or hugetlb mappings). */ #ifndef pgd_leaf #define pgd_leaf(x) false diff --git a/mm/Kconfig b/mm/Kconfig index 8078a4b..58402d7 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1017,9 +1017,6 @@ config ARCH_HAS_CURRENT_STACK_POINTER register alias named "current_stack_pointer", this config can be selected. =20 -config ARCH_HAS_PTE_DEVMAP - bool - config ARCH_HAS_ZONE_DMA_SET bool =20 @@ -1037,7 +1034,6 @@ config ZONE_DEVICE depends on MEMORY_HOTPLUG depends on MEMORY_HOTREMOVE depends on SPARSEMEM_VMEMMAP - depends on ARCH_HAS_PTE_DEVMAP select XARRAY_MULTI =20 help diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index e4969fb..1262148 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -348,12 +348,6 @@ static void __init pud_advanced_tests(struct pgtable_d= ebug_args *args) vaddr &=3D HPAGE_PUD_MASK; =20 pud =3D pfn_pud(args->pud_pfn, args->page_prot); - /* - * Some architectures have debug checks to make sure - * huge pud mapping are only found with devmap entries - * For now test with only devmap entries. - */ - pud =3D pud_mkdevmap(pud); set_pud_at(args->mm, vaddr, args->pudp, pud); flush_dcache_page(page); pudp_set_wrprotect(args->mm, vaddr, args->pudp); @@ -366,7 +360,6 @@ static void __init pud_advanced_tests(struct pgtable_de= bug_args *args) WARN_ON(!pud_none(pud)); #endif /* __PAGETABLE_PMD_FOLDED */ pud =3D pfn_pud(args->pud_pfn, args->page_prot); - pud =3D pud_mkdevmap(pud); pud =3D pud_wrprotect(pud); pud =3D pud_mkclean(pud); set_pud_at(args->mm, vaddr, args->pudp, pud); @@ -384,7 +377,6 @@ static void __init pud_advanced_tests(struct pgtable_de= bug_args *args) #endif /* __PAGETABLE_PMD_FOLDED */ =20 pud =3D pfn_pud(args->pud_pfn, args->page_prot); - pud =3D pud_mkdevmap(pud); pud =3D pud_mkyoung(pud); set_pud_at(args->mm, vaddr, args->pudp, pud); flush_dcache_page(page); @@ -693,53 +685,6 @@ static void __init pmd_protnone_tests(struct pgtable_d= ebug_args *args) static void __init pmd_protnone_tests(struct pgtable_debug_args *args) { } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ =20 -#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP -static void __init pte_devmap_tests(struct pgtable_debug_args *args) -{ - pte_t pte =3D pfn_pte(args->fixed_pte_pfn, args->page_prot); - - pr_debug("Validating PTE devmap\n"); - WARN_ON(!pte_devmap(pte_mkdevmap(pte))); -} - -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -static void __init pmd_devmap_tests(struct pgtable_debug_args *args) -{ - pmd_t pmd; - - if (!has_transparent_hugepage()) - return; - - pr_debug("Validating PMD devmap\n"); - pmd =3D pfn_pmd(args->fixed_pmd_pfn, args->page_prot); - WARN_ON(!pmd_devmap(pmd_mkdevmap(pmd))); -} - -#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static void __init pud_devmap_tests(struct pgtable_debug_args *args) -{ - pud_t pud; - - if (!has_transparent_pud_hugepage()) - return; - - pr_debug("Validating PUD devmap\n"); - pud =3D pfn_pud(args->fixed_pud_pfn, args->page_prot); - WARN_ON(!pud_devmap(pud_mkdevmap(pud))); -} -#else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -static void __init pud_devmap_tests(struct pgtable_debug_args *args) { } -#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -#else /* CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_devmap_tests(struct pgtable_debug_args *args) { } -static void __init pud_devmap_tests(struct pgtable_debug_args *args) { } -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -#else -static void __init pte_devmap_tests(struct pgtable_debug_args *args) { } -static void __init pmd_devmap_tests(struct pgtable_debug_args *args) { } -static void __init pud_devmap_tests(struct pgtable_debug_args *args) { } -#endif /* CONFIG_ARCH_HAS_PTE_DEVMAP */ - static void __init pte_soft_dirty_tests(struct pgtable_debug_args *args) { pte_t pte =3D pfn_pte(args->fixed_pte_pfn, args->page_prot); @@ -1341,10 +1286,6 @@ static int __init debug_vm_pgtable(void) pte_protnone_tests(&args); pmd_protnone_tests(&args); =20 - pte_devmap_tests(&args); - pmd_devmap_tests(&args); - pud_devmap_tests(&args); - pte_soft_dirty_tests(&args); pmd_soft_dirty_tests(&args); pte_swap_soft_dirty_tests(&args); diff --git a/mm/hmm.c b/mm/hmm.c index 1b85ed6..4fca141 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -395,8 +395,7 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, return 0; } =20 -#if defined(CONFIG_ARCH_HAS_PTE_DEVMAP) && \ - defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) +#if defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) static inline unsigned long pud_to_hmm_pfn_flags(struct hmm_range *range, pud_t pud) { --=20 git-series 0.9.1