From patchwork Tue Sep 10 04:14:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797866 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: 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-cxl@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: N691mV30cr5XvSOYTZoHp7GOUkaNqYT2MHhBHrOYzgj/3b+/pZo+CbLkpH2cdiRcw/UCnlRv68SVYV/EenIi5cdiL7IcjVw9YNxdULQ7KUK0VC6tem1Y1emTKrvLAB8tdDwIMAJv1ShwGCZQFKPrmNuzjq30JGXfeIs2oC+nCqJTRwxQtm23741tAMS7bjgnluNjmwdxHB+vv3DzRm2PK2MSssBIIVFMlEJDiB5IO24EZdvT8Ry48VranA2cbjLkggDRTfwWF8SjA4sWeHDUr26HlANbUM1ttN6ZA8O791706xtyl880H5LY7olt58/DuOSEX78CYTYZlZg6REGYb2MGO20WPE/ZIjB/ZU2kRsuCfxb1da+3WY1f7NYTCfajQeQek+wWVIolmtnhIbvQcNvZnwEpMVbLRP+Ok6WemDLIqnSujFeme7ywBpkgNzk09EBclgTFiAOrQBSNZ4x83qcHjW8iQ4Uu9VeYrI8khwmsidnKNqO290CZLbCDcx2zUKtYBmAhGoKMLxN0ts1X6uebCmvi7Z8A06sOkePHCn4nN/GY8Cb9mB3/kEDtFaMZjRDQUbtUrrkF9B6zAJwSzZG7zKlcAsZI9gzJ0++pv72tMsdFNcDVQ33W06vRqwHKWTtofQ6M61J9TRWORJa2bOHtVkZm87XAGrGACXY8NXdspZiSkoS88OCAJZUQv8w8xx6YN2AAe8K63/ze5QPLVoPpNsUaaXkZqSkmHOrRgLQHrjPji/1KfuxDsmsPeoGgdSNF++hhMfHBRXRC0xp2jVpGhXbgVTf9RoPY1ONbgI6k1XHJ91wDzAtIdUUgCahotoltHfh9l8XZAtTrs8NRuOWqTuGysM8Tere/FGDV6Z4uszwWwX2Uwxa6F+WVskLpu9hcI9NH95/3y6pPNJk/GVNFvQKOWqhgXkrJXuJtfy9CwwzqDlpzTqjCIeH3714Vm04aF9n5GPSugSGrnM57oKf8XDeDnamAemvu6vYeCQruWNHU9IjfGV0AOpxa1XTJqQ9fcsK8c8K7w0FqHciL7saDezhV3t1UDHo4e8TkjFe7KfPCuSrKgGuC37/jY4+5QFA5fTIQOpUUm5wF9S1RNHZFXkb8yhLXDBBzjtJe26ARKj5bwHUFbEyzA6IpKSjoe5r8KDujmzgpYNOqVS1vXmglDF7nRxfrMEFLMqyzUHeiM/cJFLYaBoEJezyd79ucLJLswDag4E77jn1ZwkWcrji5KzxiLSFOjLNBPoO2EGMtRJSeeM91/OuHvXd6SRKsyLEpHt8Nx1V4cdIl9uX18O6lIhZCman+YEXCFPJer2KaVSvMHWxC+1yDWVOR5Uw1Y2UGkycwFvVBtIuZ5TH4SA== 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: iPLav8Pmg9cmH7rrfcIvbv7YDogC3zthIrBQyT3eVcVGlJkRDzDLPsFy41KwVWGDhZid8mbHYKZolIliprSqVo7fSFfhipS9k6+Q9scrRi8+9+e6YkCR+V0tdA5hatrDfk264sTpNeQz8Kpt7F8vImKsuly+z8ExKhZfvMiA5KZKD6tIYg8k7DlnCl6na4VXFtU7IdyJl1pRCrgVBWdns7AhoBSVY7+w3b4t5e0T3+bp1X7He44NC0prVv+BuUx0gaAcIlIgZyaVt55R6tZMwTwByk/iFnYs04VYY6T+mMW/F2OCD0Dlj/8kzdN+OHQK7EdhOvYV8oyVKuIV9oxAO5kkYokgV/JIr7qzqs4n7mzgwog3fP15Hip/I5edLFoMK2A3IqixsyxCfs4s8F+Q+P4YtCdqdbswh02JmI0ijcZnb2QH4paPHYDkfqpkLUfYQvSVYxTsUnUecdGfl3QanQef5/QYRcInCbpJAspwM/y9TW6pzToxOGVGGtOc/Gz6SiA8auUdtQjfoocToa6SoRJ+N/W+RDp4v4ucECma7NqrNTW+m/kCOvnExs5NzC0QbE8SaXWKc+9OnvhxsZpfB1bNSTuXfxANB5eeRBwe94bVwUs7eoC5HouwloUi7cV5x4vfuO/bhClhfVHPpHulmY2W1JFghLg/dobKG4tIMyTwz04kxePyWbuFhFwlBPXguEq7P8h4DHfjHMdgtfaVzr4X7tql87HvurkhHhCM7jZCoAj/Msr/JlfJuRvV+/wErxfbxU07FXXQUYWNUEDuk39XIWjmw/q4cOo9hFLZ7ZOezUd3+Mh7JiljZwFDo6WBNgKeqdJXwg9459SID/vFQSiZpw6E3K7HNKyF9nnQ3cra8bIFNS5dPZUSuSjeMrinWm0/GV8OeqDcCdcIDY9qm+EyanFhGUmODftcCcF56P1t0GI/IAlLtVY7ik34qlQDnINGzn7yaIYycmtjmToB9IFxyTMfPddWZ5tHeE9IPDwAGLKyqItBXa24xlMMRLmgId0vQ0njPkQziiqIDFx+J5k/XBsp+jQvnapaehxddUyAqQ821ufY1B5hyf2bhpWsiVfzkccMf6qG4UOzE/C/D9dS+gjr0oEyEbnQRNCLvRm+JJmzDu0l6rPJMxzaT942j1l0zGhHsCuzn7ghurl2tqY0vYGZdSrvZJkGqksBeqBo/YaGLFCe+MyBd0xsrSV3ZCCVTBFlfKKIuktMq3anmn2jJNSK8eVr+iPPwwuA4xE/wgf0AAVncKfqXMOwfS47NqCzxDiY3eSI6Glrz/sxe6eF+w9k71hJQSItgwPHg5JC3FfszV8ulYOkq7RTuWqMe6X75KpHEBEiBkmDgoOvvJm5E5Lh0smxRjeR1KWdTkSwPXU7yhTjG5k5R8voWLuKCA5J0Xm/MdO3MzJy56MYrVSA/fqk2BcNYEj/6IHGVJHFQjPvxQKLWqA0nn2y3zsseXEyVMBkz4LPHDRMzE35X9oG89qpTiCC5+ZCbB6gurppWEnBw0aXGBp64g9eSg2MEFlSeMcQuLWAQFxOwgRnOu+qSPRSP5Dzzg3IsxTPgP4DCS8vz3VFt0hhfBK0tfxc 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 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, unsigned long addr, break; } - if (!(flags & FOLL_PCI_P2PDMA) && is_pci_p2pdma_page(page)) { - gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); - break; - } - folio = try_grab_folio_fast(page, 1, flags); if (!folio) { gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); From patchwork Tue Sep 10 04:14:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797867 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: 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-cxl@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: SZ5J+werEmfKSvNgJ6LyyRiVC5fbAc/dNJFT9HAaxLR2TZTeJktuJgd/FRCDjg0jLD+Km/UdvcgQoYEZV7+3aLDKVDS2RC0DAYMVhaqj1Qwog/bqcodFZLUYhEauw/Bfi/nTTMDvcHWVmtw8QhIkki4vx2PvQp7OKRdWv0PY5N92tHZqv0fzcosYdVq85tj4hC14ZRO8fTVXrwPJRAz6sMMXtJpTbAs72dOFjwWGZn2I9yLrUyHNh6kzkf7/OJS/uF7im/N0xcC0y6oILO/sN3cfXg5C5brJLXmA6b/M9p7D0N2MEjQx03lWneh1XaOuBRI+NKxmF52ukbgysFxPqwLZoSJZ+hrDFUokP+COxKnVcGcceJO9MsDuDsuqMmA2EIWhXm7UbAYNsC3GisF1HEAl+TO8x6Xru1VIfF9Lwgo0+J6NGd5OHF4XEAk7F8GMWBLVUePI+UwqADwqeZ+GCSBMuotQP6H+1xSM+3XjG89BXGFadw9m2QhlugRT8CrbGAd1Fcro2CbqKBq5nzxpAEGmMivV4dBq8TWWCboL0/DW2JWk+mM+UinHdjA/G3HKqyCtLC0M+KSi9d6ktHpWSlwwJ06UEAk6fsAjUA8gsRUUEO4MVV7R/A0R/l79bu/JPRxwW9NBat8uW80qnhTXh5eCb3NdXNqq64ZBbEwddex/U9u3N7rlDCe8hASydjT5zjcjvmHfl5a1ljA3P50T+TfPjsIa33lW1rIB2M3RRhnAFo6+4FepkAapejeNpmRPOU1fHG1/laSZTONh2hCMb3AwHuyAEF6WoXRK+OedjOmYDjqfCFW/aa506Bp1uVjK7SlqwQHgZftGsRbo/TvdawljtM+sh6Do8Hksb1IDQLwKbtJfG8Ml0f8prgRcwQ+PIeC+HecldqLcLQNK5br0AJEx5BbkjKj1xviqgcFN9ZiXlmGF5Jj0aDDi/kgeSybdgCFWF9q/ABXMgCqMmp6/EiKIclK2n0FcKb4DngH7Elu9ZsKtiuBH+rLC2czcIosPcleTlq7S24zayD3V/Jib70TzD4D+bTQSDxfrtcs6VdVpwVSXNlVstUHmFi68qZzGxWheT0599MDUrmqM2xcvqPk90i22uDMFV8LWnscobxsPrrK4/CcfHLAMblERL893d0/C8zzHYqV0meRxo0upFk88dZ/N7NJwuVHFTjEu1LTMilkTQsT5w2OK86ACxOCC/8HgGKQ94n4r+tl2co+IrScaNkAnTC0xkMPNAyEYE4aSJrW29k3Qyvml4B6UVmLyyS8PqjJ4Q5iM2jOt21f15vaut8mJJXvThVzhV+A70rc1ICyS/6JZR0vIS1drrFeIRiPPIG2wMKU+uOimx2G9/A== 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: 4VdBz8HHLtOxcBhLhCMFL7nMgDg1l0ig+7XmVXiX1CoQqesWh6hvrOo+OKF49KMkxhpp5M7RVvmwoEEvHHe6vWcXvR20u9YrO6Rno9Y+6dbWi3MMS03a8ux28VSjce8GmJAdVnSRbes8cE9n8G7hyrVjUHsro4GvDzZhxX9ntUJnXB53QmTnQPWL8zpxfAXhN08D8Ehc4rF7+8furD6TZTSkhn3oESgct6tXK91qqr0JlI0vPLqa4ZucAm1oCwzxHB37PLtS0lGgTVj/lMeOExX/R/J8s2C4FBGQMx+CQuHJksrydkNi3ku8bqObwnNeD1DmvvIP/73XSasfEzyz27m61wmYoSW2AfNefN7rMl6xgA5Ny5Y+coxWtHuBxLAfLAQVuertr2e6zLV97Zk6Dp8vM3hYKsbCgSd3ot3wvAI6Cw/2RW3hhgT+/GiXfEYI/5U+Dvgqp0cvz2q9xngUsE0CJfhi+X6S6i57dXihqT+HaclKzki1usmlP4rbnAHa6a5zoB+AC1lgTjks80Q8XGeWIKy6Y/HYPORkFTkFlZLVtKhZAQYgx1D5nMC0XkfZGFZRjULFAgd069p5e8i/dzlM+T+URvDUL0FnbrgHPjYFQD63F0/LXy/xIOe/ZTRkTJWWQ9MnSNJ/LVr0xsAyE5cD4nuvWwu8PPRe811wkKnCYnzv5SBo7m91l7MkVaMmxkpVEl6/17fX7semlmqYvfhc9AYbise9aZC86+Q/SCpzNSbh5Y5MpA1+m1w3+16kzkeIju4vgiwHKutM/IzuONQzxxsZd+mvGRoTiBiE3ji8XPjKFeLuC4oRZzmEPWQszTQveBFhz8k4S/jfSJEL6hniFpuemF6cUVIPHbup4gBmd69tZoeLM94dTM36R8fG1Okw3GRRFYoBgtZJDE/yqW0ln+o1F5qEF5ioY2LH+mVES0fhqkM1FF1y+gY1nSigoKcoy1OySP2cTgZJT9+FB1OJiTWCHmWC+dmy0b+8qFvISNUMCILXyjO2a4ljiyqY0/iRnu7LLejNtc5Ej0F4Crfus+VZz7L89oUeAeeQKREg+mbqpNxJY+qD5PWzw2R48LVzYmReFw00X+3R+OHSAUxibr0DbJm7kl9IG7TReJckS9vTRwSRJe9YwfBRJybuAy/Dz5WKUCHr2yTLj1f78x5fSpM5uuxOaYKXBOYF6ObqbvPDObYTw4KfqZdR9KvHT9U97PuwaO7/QWZk0uWjZ9iGxhAt3Msi23bPwLpN7euTous82iZ+ThW2a1dH5wHPOIHUUOZUmNiR8EKEULejkbhsa7SPi2jRDk74N6k3/Tfi7xWZIIY2LdvIdPxbAebXmc8HZC6m5A7ohcOPDATpRC+Zo3VbT0QhNmdU2s6ohfpw0oPytkhU3GI9H2MZ/HPKEadkbbUVHWk5t8tlOMDimnE7VPZW3G/vD6eZgPQiEkE6gHly0t3hpQ70MmJhJRktof2U6Yu5SRuhvx1EAT8Rs8fS0xCnL68Ku7l8sg8PFejh4U1Nw+mAKvvP1OhI6oSFwhwhPwKuR9yxK2402vxrAKDnwPnMlNq/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 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, } /* + * 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 = NULL; folio->page.pgmap->ops->page_free(folio_page(folio, 0)); - if (folio->page.pgmap->type != MEMORY_DEVICE_PRIVATE && - folio->page.pgmap->type != MEMORY_DEVICE_COHERENT) + 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; + } } 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 page *page, unsigned long pfn, } /* - * 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 == MEMORY_DEVICE_PRIVATE || - pgmap->type == 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; + } } /* From patchwork Tue Sep 10 04:14:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797868 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: 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-cxl@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: iqrbVvURPQEAKv3k9135doCKU+t/lEH0CJVPgHV21AOQ3++/eXpr3/QSqvEKiDeC8sGe1xrf9efOOjAaOc+rJg274pfGqHRI95A/0HuG3F1bJ9haAMVWT77IGMDDUTPTHES7mIQBy8fxHDSAxFk8dTxLkZo1O1Y4KdQQE30+CbiYP2HaQwyJscC77gugvNQKDYIwbJMwey+qbcdg/VNfuymnDaflbF+UeymRBVdDCNgogIJFIE0tkhNNMmM59LrlMin6EdVwGX6fPwAh4CGBU3bNDBvexTUP/DiZn1xBr3qcuS1Lv94gt5scgDuuggPpz0yvNPbAKHtk33Xy1VFpgqxRuhFvcsZ9DI6jCTn4q775A3EqvStJCoo02YQbHqMaQG1DUtX85JWq2Slxaz5nIT6aH9ZFVBJJN05SySHt4NRTZJITeVAnMr8VPvM5LK4BlyZIlh54+7UmL5SEzhTnlmnyYhXV1SSJ7ZG3I8mEAdfPO3FxR/9bq9t5aXgxmpzKClh7XSDwiZK9tRExFJ6GUVq9x17KayuzZBORIS918adysDiajM5uKIELRDbhgWMByVhfz3G5GpThr4KVJDc0mtGEOe5mMpiu9MrPbtsXKl8Nn6CuNmU8BeDQ+z5hzTYbMBpJftyHJJ23/6SfTH15DIyMnrir/9r3OZp3sfXAMlnfCxnsTTbLOqR+ge8a9Us9ObOtAl+rh345DRVLS2p95eeEssMIYrCtIouDdXl+ZS5rKdI+MTPHhbKc7HVO4+VCdqN1L96Fk8lWvzz9qaIYzpoyE/Eo419ycjI9uSioQG9o1T0RcJL2eOjyho+nVYHqgkvQk3dUm1kRsL+KP62Ld5y8exIMBlTToBviO6d7hhKYJTnNXqq2bM6eKXWKX7bERleDi4IZWmc7bhdhQ9n37+GI8zpSNPZHKPmxZFKJRYbu/8eHbpPW7uQAOReP5miSFTwe7QppDCUQvTx1PByWozgJ+X+2qhXjDAoaLg8NEVY4qCYjLB/mNYgd6vr8s8+Wcpcxa+OWFh1IV5BJPO7NQHxQScq9CeW0hKDvfdUrxOg/QBi3EmCecfYQetSpfPcNSTsrh64b3mYeydwDU1k1UHvn4S2Wu70PCG7quBjgvohPvZAjRYix96T74EuiFbm9iXchDf3eJct+EzhC9JZ0RUxbafYfW3r1drGOMdGgkPcsEpPT2F0AHgDLfvICPfJerDZpBLU+kmGIK9vjtLGBM8B+jfEGRNsM7wI1nk/rEQ8a0tEmWbHkO6HuY2XpdJbuYfaQArD3/xu0XIZ3C0ubGR3oQNAKFWJVGidZm90+dVyh4tsID/7sS9+dRT0djCbCqLAuMiogEkbCcUO9XUuQeg== 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: qobh2u4tGTkyr9iETtnsUD2llXgvH6z/LiXINDUYu2dlFluk//wfK0kv3AIVGn9G4eWyyz05KEM4kCxX3woauWbHLzI36htYslHeRY+CRyGclrzZPYUqYo6u308NNa7jZi5v2A+579LaSd5eRoqTDCbyCUgyd8CmI9zLMXR+yumkMelvSS52FRc1KmixMGbrEtG6XGMQC+fgYhtunDwH9Fjgdx3bz0KXml3/DWErjutYduk6YaaiOCjcH2X/QEj5wiiu639+F0Lm73DT1aHikCMbKWCP900atDBMYTV9tKIIx7as9V6koY9facu6IVUYGGZSe098EOeusmoaiJ7XwMQAg0HLljAV7dAfSo73EFaK4WkroQuYIUde/ytqax5bLz8/urmAWSh/jJ1pjJyTTKzikDw+9XNd4u3r4cnZhfONYYJBDs21Pd1uUi3lNXAYpcoXLgv6wH19YCdmodAXvb2xye4OOJaFRb8YtjvgZcebq1MroEqrvpNPKh7smBGjK+6e9B/yzNjlZD5cONYLzPHIRbxvQ7DdcGZXicD91F7bsk21oOmwgIXFWNoDLY5iXepVP6brEI/DCmHxdSKri5bmVNIEvR3HacZ4Vu7dGf/DZ1az9NeYXSHGOGrmkxzkGeNoF2Kkp9PTY+TohW1I0nG9mKwEUpM3GGqiwXykjuFjPt9e4qf847VEcqd9lf/4XaSpHGKVQV7XTJ15Q9+LOkDgkVtpXY6VAalwK8oU76PJ4K44EBOkc0zZ4whXQs4LZ4s4heYsaVAuQzfwewpVO6VQLRgumrqoOtzLYAYY0yP84TkrGgFyJhohIwuH3Z6NzM8WBJb+XhzIfX1OEKVk9MOhW8dxOAtMYxtefN1DoqZsv8BdThA+Xy6CMjPt/BSppmjHqFeKhoCmswSCxWACvPrWuUnHKYSMMuyxau0t5UhtBTLxT0jBqpgypJ8W028hSp25aCLQzTvXaeh01z+GCuXrQzAX9XL+OVYMpBQIn7kcSUYltXVXuQQq+KGVllMMcXJp4fqKkPc/gNRZpNtAl72mRYE5MMq2y1V8upgFujQuT+tRrZEaJkIn8oP88+pltMwV9qMdfBshjBl1mQrVTj2ZUYGYM1BN+kMP3vNCm7XT38GZjl9TI0Ynt/j36bW0xGCC/ccMsLmO+Vu3d5MR7c2Gk2nQtgkww8S3ljWsLRnPyYvW2sBviJ1hyldJVAGctjR10DL//Gc8JlXrjP/NNcA466lGo4w0PADWrHlk6wpYB/XD4BLctGLHiYoW/LOo6g5a6x9fvJokEtdXMJp1FUJyIq7xzoE0AbfKpy2r0S7CG77fUPbxQtEVKUSlVgo97H4ch2DlJO2/ivRnL/rnn9iS/ZYRRDjIIl6q+GvCIlpE102m/xhmXUNwOLh7MSxNl68M2WpggnYEq7tbbjePvZzz7lVeT+2GZdc+U6Lam9jYgXsHy9qJMQnecsE0A2FI4AjV1bQDGgCk9GiMMqRBNF242iVGD1skVmRpN7WELdPcXHC0bD+Vxczq1HHNrSzB2iNhPDh7fzlSNYLazHLCRxe14ycv05eLdK8/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 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; - error = ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, - TASK_INTERRUPTIBLE, 0, 0, - ext4_wait_dax_page(inode)); + error = dax_wait_page_idle(page, ext4_wait_dax_page, inode); } while (error == 0); 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; *retry = true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, - 0, 0, fuse_wait_dax_page(inode)); + return dax_wait_page_idle(page, fuse_wait_dax_page, inode); } /* dmap_end == 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; *retry = true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, - 0, 0, xfs_wait_dax_page(inode)); + return dax_wait_page_idle(page, xfs_wait_dax_page, inode); } 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, loff_t len, bool *did_zero, int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, const struct iomap_ops *ops); +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) == 1, + TASK_INTERRUPTIBLE, 0, 0, cb(inode)); +} + #if IS_ENABLED(CONFIG_DAX) int dax_read_lock(void); void dax_read_unlock(int id); From patchwork Tue Sep 10 04:14:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797869 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: 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-cxl@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: uoFnlTqPCRafGcsU3FqgEABbN5Uqrf8Hfyolk3n1xFlonzTwRyH92Eey9N+DTObprvKP92pl/ghpUQ5o87Cac3jdXgOwTdk68spF2ijf6J53ftF40kr/DaHnDLozH+O6dlujMj+eyADjXw25Y6GeYnRzxMDXQLHc2iWyhzrPBJ2iTAa/hc+iuSoKj9HWl6Zy6fZ8ZMD63oNkzgXL6NXA2afKIiPB+Qqw+p05e4RFcIpfUw5p0gY9zOImbYTgxS2t98ScXHOT+50pPDIOZidYa0JXR3rfOMUOfSjCi2eBtmpQWZKfbGs5R5Up4Ehhhb06qCXTPcPKtj9TpUfOG1aLTi6XrmlWIi5Euu0NurN+OtecMfRhOuIjtT9jqgSOZ7ufXkt3VR0/iIOK13TWMsRwE9goifOmGGATAyfobOMgyJI6pBawpOLiqR/5eYueXNQpENCONyigDqsVebw4274rZKMBDwntuQVNoypXm4Z1iEi6c8fmY+XZuE9tlqK3iKfIb6rgh3tf5FXxeQcEPL3Dg+/+DHIAJ6OG6WbQn2q6cKKfrO3knwJ+v088CCNGnuB1H4jUrlGZSmUjyYciDLCR3AnmAG3TCmPEP/TGopTQKmCpnls2NJvDuBsmC6qYoYr9JpemTsjuCPgQWiYH/4UHZJERQynh8IRTfGihrlzBNmhwfH0w/3JkUrc8hCIsw/YLXGmncxkAT2HSqlSFexw3QSBGZcfDbptYE/xRmSz3kAwJX+SRAdUvhDQf45/PE1N3Aei4Ic5li+Ypwj+91UMDH4+DO7AOLoOILZ0ghiEbbXspV42Bzz9VdQI4mdwQnibz1v/kcGE3r2hghrQm12se6h/v8f/WAxOA5S/2+FHaTt/TZyI1T7HoK0baqHx3qOmv1l87rpORvCm5Bv9J1YLY8P3ULXggi54BXboZpMfBtHgmkjTIThy+2iQ0vc/OylHGIO+zNAk79DQxuZXOwumUdgA1OD8eY4/2dUouhr8us/VaVV/dbL/jjIvIUqRkIuLW3Acn6F4gHv5RYp4lYobXLZGmJih1arTYhLOLUY3C4EGrUFkXJUGTFY0F+usyM1BY/aJbueT6YFJp8D/pO/8xKK35g8ei2y2caxGSpqAIHFNj2CVFISMiMuZPfhZ2pdCTrHOGkgmkLrqXFCPHAVx/sJCEVpTwIYqUm3ldHnBcNLFsCXI4aGsEBN2s92ep+GJyk5surKLK3hVKlapjwBUK9iURgnY8FZSeybxli1J9ZTpy8Han/PNK8wRoYj/3GRrLkvEAeLiOMCb0euVnbo21kR7TT+MghiU1CQWfRtsW70+jIXVAWkXfpnDcxOlaYmhlaKFrlQIlxKDCDmYZDDUCxA== 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: kBXV69qqtHhZalRdv1aKk3DNGZAlbMYSXVxcu3EYI/s5XkjBxgTzTnWzSmkkxfdKQ1l85w7aO4brH7Ppoxk3iRpsvA2orPpQ5hjhGIEzsXUvXtiPrELcYBcuKkm04Fv0MuxoEXlPWbtpOWiWVPCcJ5D7G5BwD4PftvCwDg6sG68RqAHPO2EgqajPgMS2IjDeSMdDlYV8snBWD+9yIsOMf3yi0zEk+A222ejepWhn6cKlfNlAjWUeO8RXy/lXWzuaIFKmyrXcF8JET7wCf7xVvNDPHpgsIaLo1xSFvsAYZGH9A20toO6i4oCrKp4M5aWc6fi+IMxqWJhLL/hYSXQm/eLID301KOA4Mixg7pp/IjDJHMQ0hMV5oC98DgzpwT/exZdEajeimwGU9AcIVjOSq1VAZL3RImOrrxCtca2ymWxOS7KeV6sXWcCqPAXC90712qf/ZrTh8DzcnnWxrCKShHc/Ov+nK2LigDp01Fekh8Mr4gCLZ04idufFOqyN/CeCmnEYxFaRwYoT0vS4lfpsGe0LJA4+7YiECDIcOAjlXjLTrKs49NGzXDF6du+2PO+aUywG4JfFikULD5ojnYo8jXMK4a54rmwv/gQBZUaIYNUlnAiIJ5ED2G1xV9bUgwJMJR+1gdpAfbfJDq/aL3vYSb9o4q/uRwx5GB1NeOLMkZSI9fl7Prtl4fLvU7JGmXYrxldQs3HOqd0HAeI0lcKXuO56vdxqXrNfhSWLw0c+j9YtcJeySewibVCWTtAInaHxB5dot+OzXiTmDofXU6TplMEBZPTCQnvsWEXvKshEiffakujvlZAtbR2XhHszZTuC/ksZ6aGqc4u0qnuyiVO8cSm2R74hAe+7qJRPxuiM4QUDKoKnjHL/Gk5SfZAAbx024HNAy2E2/736TqdSIv/wsLaTkeYB+IxWWTdrAFDDvUUJKentZ2Eh5s0J0qqAKoh/VVco4TSbm/oqApdVZo9QEObnvAR0kfUkP/vEVFpVPfyoPFufaKDTAqTwGiFFJDaLIOrURijdFJMNWVbesIHrshCLr6UPU3CL7RDquO8/ZZ/BF8lo6/E2ZsQkqJnfqHI27MslELd2/9lw2ZBKAARUNcVpr65jtkR0P0PzGiSTPaxP8AfiXZ1dZerOpgyTCnWHbUrqPvm7Mq+PfzK3D/fg5uhA9QaCyLSbQiUNU+V9EsS/4cq0oZgIPYROp4gCS7A9V9a/9GwilRPvcWECYVADcIJVENa5M/Zue2NpZAd4ChM/y/8RjO8K8ROaUYiVBzo7i1FeTjdpOgs/ctKpmW90NpvwluPlHPi2lPpV1A/h3uH1qNN3KXv0yXTVIJpJ8n6eefT59y1sumeUkZScKO9Yi4lEwEVj3PRzyUnYHpxhN3U8QkWik6C2Noz3R2JVjYpQADAqSQ4gK3KIeZXQRYNh/jpIq0bsqahn/NJ5kJqPKMimkbN9C1SVeNAbyTLbJVtVgoMElTjsCoG9vScEhCBXkWrBss/tJCQMtw11rFis82ygqJnfZPnz8l+J5FPT8UJFdCgLv3r3YsVJIpK1u9I2R3TxI6NJeQYV1XWlSIZsDDVUJR+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 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/nouveau/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 { 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); } 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 = { static void p2pdma_page_free(struct page *page) { - struct pci_p2pdma_pagemap *pgmap = to_p2p_pgmap(page->pgmap); + struct pci_p2pdma_pagemap *pgmap = to_p2p_pgmap(page_dev_pagemap(page)); /* safe to dereference while a reference is held to the percpu ref */ struct pci_p2pdma *p2pdma = 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 != sg_page(sg)->pgmap) { - state->pgmap = sg_page(sg)->pgmap; + if (state->pgmap != page_dev_pagemap(sg_page(sg))) { + state->pgmap = page_dev_pagemap(sg_page(sg)); state->map = pci_p2pdma_map_type(state->pgmap, dev); state->bus_off = 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 == MEMORY_DEVICE_PRIVATE; + page_dev_pagemap(page)->type == MEMORY_DEVICE_PRIVATE; } static inline bool folio_is_device_private(const struct folio *folio) @@ -173,13 +173,13 @@ static inline bool is_pci_p2pdma_page(const struct page *page) { return IS_ENABLED(CONFIG_PCI_P2PDMA) && is_zone_device_page(page) && - page->pgmap->type == MEMORY_DEVICE_PCI_P2PDMA; + page_dev_pagemap(page)->type == MEMORY_DEVICE_PCI_P2PDMA; } static inline bool is_device_coherent_page(const struct page *page) { return is_zone_device_page(page) && - page->pgmap->type == MEMORY_DEVICE_COHERENT; + page_dev_pagemap(page)->type == MEMORY_DEVICE_COHERENT; } 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; /* - * 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) == ZONE_DEVICE; } +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 == b->pgmap; + return page_dev_pagemap(a) == page_dev_pagemap(b); } 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, struct file *filp) 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); } 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, unsigned long addr, * just report the PFN. */ if (is_device_private_entry(entry) && - pfn_swap_entry_to_page(entry)->pgmap->owner == + page_dev_pagemap(pfn_swap_entry_to_page(entry))->owner == range->dev_private_owner) { cpu_flags = 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 = pfn_swap_entry_to_page(entry); ret = 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 = vmf->page->pgmap->ops->migrate_to_ram(vmf); + pgmap = page_dev_pagemap(vmf->page); + ret = pgmap->ops->migrate_to_ram(vmf); put_page(vmf->page); } else if (is_hwpoison_entry(entry)) { ret = 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); 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; mem_cgroup_uncharge(folio); @@ -486,12 +486,12 @@ void free_zone_device_folio(struct folio *folio) * to clear folio->mapping. */ folio->mapping = NULL; - folio->page.pgmap->ops->page_free(folio_page(folio, 0)); + folio->pgmap->ops->page_free(folio_page(folio, 0)); - 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; 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 != MEMORY_DEVICE_FS_DAX) + if (folio->pgmap->type != MEMORY_DEVICE_FS_DAX) return false; /* 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(); for (; addr < end; addr += PAGE_SIZE, ptep++) { + struct dev_pagemap *pgmap; unsigned long mpfn = 0, pfn; struct folio *folio; struct page *page; @@ -133,9 +134,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, goto next; page = pfn_swap_entry_to_page(entry); + pgmap = page_dev_pagemap(page); if (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_PRIVATE) || - page->pgmap->owner != migrate->pgmap_owner) + pgmap->owner != migrate->pgmap_owner) goto next; mpfn = migrate_pfn(page_to_pfn(page)) | @@ -151,12 +153,13 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, goto next; } page = vm_normal_page(migrate->vma, addr, pte); + pgmap = 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 != migrate->pgmap_owner)) + pgmap->owner != migrate->pgmap_owner)) goto next; mpfn = migrate_pfn(pfn) | MIGRATE_PFN_MIGRATE; mpfn |= 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 = pgmap; + page_folio(page)->pgmap = pgmap; page->zone_device_data = NULL; /* From patchwork Tue Sep 10 04:14:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797870 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: 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-cxl@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: OYHtU7a8jLIt/MuBG+b8ChbB5Htn+KST2CrbhqYChwiM4iKd2w4r6a1cx+ZOVdT4jchb8Xa06XqPhf7gdEjEFyMZRpkPARGsEE/EZ0oItIGQVhSWjGBvYpJSGvLTBzcW+HMto4B8hdGo0P9gP6M+4cOxhftkRRcfxUAOUKVi2n9JEqtgMESYhrkjH90eOJOxcMIV53y+MPqVddgL0EO+f7Zo/mSN/mBXHC7lxXrqSXTvkeabmzNieQWoXoo5Xv1Uej7ucJaRzJMJpJvZ5EPNhDm0WhC20BZ5vQH3+Rz20hv1F7GK+Q4y5ku38V5uZFNWORn8k/OP+qeP5+3rYR6HgIwdCcjM2GVwM730+wCRBh76YwbBn0JDjsLzCDxhVvUILwsafolEQPQkrpz+ZBWRVNwKtdYVth2Jp4U8xJQHXwZAintWYT5w7ah8mBCiDWMtq3lnvMO86sjCzubC/fwrJQcAl/xY2O81n6VrlCad3oDkzubZ5WxWC1tcIV2ehxnz691gi+dCc1lVAXZFgke91d1xSIkdAeHxXI0+mx86UN9LBg+t3b6zP/FlClhSl9W/GdUay9BVjISfETsw3/nffIeFwPr9sOJEWm9UC5wrq8CTxnHEEB9qAR0UxH3+Ge9EX1YT3ZrMaqUgswelEuxIg9mgm3YEypX/csVUv6wUJZq51B+3ixhrrA3gvyWdY2dj5PYzqyGLJl7h1xYwaXl82RWKLqCXNHL7uMWZ7XtR7EmWEnpdUroCDV4xsCYUp0meizINycAdK8str+UQl1MZ0+M7fMKKOhW46bRIpRCVWOeOOUvCvc3eMPawn6r517CqvgveszOs5Ak4fq0xYoiuQcGQ7tl4CoGZknRBXAe+NvGanz6fROXRJHTETy46xvICDY4wWDJNJ6g5XI2KPsB9I3AlanHYuZWtZW26VOFxPVUD71p/+8LdzXKcW+GbAbwDonQrNKGkedPtDPLH9u4AED3PA5vzjDcRSZcxRlhBnl/7vcjTguwKKO7i1tum4T29zmvYD2ZGPmWCn9rE9Owu/A4LYXLCgUnZO990BxQFWYcztAaRC5llLjeacmbg0vKftkbA2LrMX0RgK2Nw5h6O1dWfk0cxVpxOFTlkSEtvagQ4loS+n5WJFChSEChYkGTa6ALDqNUKg1jvrtSFV6H2KXZQLY+ZdVEYNHCUsdOyGYHEFcIvzSe6ddNykGPEEAFYaZ2BIyngaZLVSvG80zUHT6llwMw+cW1RjVgmrqnmRISlLU3Om9VHw9qBcfKXVujQSql5BmEFfebKhjgAtNgcP3JXIYAp0CkTOq9ADoQiDA2+G9O4sbNH0hUqBmPaR3dP2sMVQjiUPGikbufvXpQEzQ== 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: 4fm1AMGUfi0XUs52JZf0rz+bge8SUQRMukaoO6sIPARxe4n5otAObBKpyu3W1n7WGCKXebBq4Ky8M2tw40dTrJGGqEtpOaIbdirmJh6XWMd1HxjZNeNP/8DghHjc19eRMiKCU9ghM2snmuSkeoFDD6vXqrt7UmpYdEUD8NvYgxkHwAWoOPy5t/NZpi25GcVAtimDAx5gcES0ibzRyI4dEdc7aXKGoM6WhmYQIV8NFKMxCULpIBgVUiN77UfGcVSsofsPvuoxRhvlOzTUIACAfn2Gfk3W5rE1uZHB+0I2zFlGA5LUsQyxYI857LjGlpNMv13fyMF6tLHN/MvcrctRbO8nsSleDu50EmopoPXbAyoccCLeX5P1Ng1vyLzIws68oF9MKR5alWXi/VafbI4CqxpZufG4o9dgn5I4hC8bXKo9/fOAoTFEN/l8tVUbZap0c4/obrDaEW8GhFh12LyiCVysczneHbDG4dKcs/CQTQ9HC5H5oF1/OVYWcx0wiKvDibDE2BGef9h9Pzv4USGKLy63VSd2bWhwx+lB3PI/kCAqxiCF03IQZY1rhyCMGLnGC2TyZkQX5oYMqKN+wG3p+kWL4bWW0DhX+yEAvlBd6taXhgSgU/rnh+op55XcZ/xbqdAuyxK5fbonB7nnn2awPGBOHHZpTaKbcM9Fg93YhOZB/MW7SLNfzERbNqWW+PDvEuIqOC1oa2YCkdHwu6gNSYff5yObgIKp3SMjRAt4SVtbD6RbTSAQU+xF17SBsd8nslmjjLGDexDBnG75oUYNZ9BBKsDzdlZn0DuEn1g5a23v8I+Fe26RCnu6wqitw09Iq8bcKPWZFifv3CPku+gVGmawV6n+vbQ4cZXeITRlWvPudqsjcAj5i08wrioZzCqnTB6owi1NY/mBeivSkAg6N6CtPF3lkV5oygoTJwrBt4gLnje+7XFBJ6bCuOCm865gBwq5u9Xrk1DNul0QtknjD3p8h6oGKT+HaQtnmMiosR33MbntLMOUJ4wgKF5EWfdgkrnc7uxd/ZOrRg0bRjBnmVyMLSi8oobJqadcSMVxwhHIZh5ZFEEMwA7zX8fmMuyk/vs5ToqbcWA1pqITAz1xrxaudX0jgzSzr5kcBfc/eHKutpNqvFCf7NY65Bd8Y3benNwUC94FZThYtjkhUVnpVLDXBVPYsAMLoGa6avYzo9teJu3GBTuHTaKZB1kcv/RS8SdgUckZILeLKzsgcXl7txynyQNuUDktfX5npD/zUBehX6n6hNsW9EVAIxr1LamlEF/Q4D2W1BL+4K9yP6bFRXusno1A1zcvm2B3cUptwwsoI6lD2GBsTmq3KB6Z37cH8K/AI9uXcxRq7TazLN5s9+JS7osha67dg13COSAddanHsxMI7IfoYfYYQOuXznxposOk5mwxrJQOpDfQErf3Ll/UHkc945brK33qUDs55BLoZTGvinpXPmvAnlokvgPj020XkvWLVCeSyTsDNoHuQslv1MjvEoDM2+xSiQxs9RRaJlvFa7+AcFeWFYcqOAMz42EG9VZEcjSgAgv3R7JY/Yr0TBeayITiJBylzzs+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 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 Signed-off-by: Dan Williams --- 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 page **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 addr, 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_area_struct *vma, } 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 = page_folio(page); + pte_t entry = ptep_get(pte); pte_t pteval; - 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) != page_to_pfn(page)) { + WARN_ON_ONCE(!is_zero_pfn(pte_pfn(entry))); + return -EFAULT; + } + entry = maybe_mkwrite(entry, vma); + entry = 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 = mk_pte(page, prot); if (unlikely(is_zero_folio(folio))) { pteval = pte_mkspecial(pteval); } else { folio_get(folio); + entry = mk_pte(page, prot); + if (mkwrite) { + entry = pte_mkyoung(entry); + entry = 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, } 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, unsigned long addr, pte = get_locked_pte(vma->vm_mm, addr, &ptl); if (!pte) goto out; - retval = insert_page_into_pte_locked(vma, pte, addr, page, prot); + retval = 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 = 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); } /* insert_pages() amortizes the cost of spinlock operations @@ -2223,7 +2252,7 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned 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); @@ -2503,7 +2532,7 @@ static vm_fault_t __vm_insert_mixed(struct vm_area_struct *vma, * result in pfn_t_has_page() == false. */ page = pfn_to_page(pfn_t_to_pfn(pfn)); - err = insert_page(vma, addr, page, pgprot); + err = 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_struct *vma, return VM_FAULT_NOPAGE; } +vm_fault_t dax_insert_pfn(struct vm_fault *vmf, pfn_t pfn_t, bool write) +{ + struct vm_area_struct *vma = vmf->vma; + pgprot_t pgprot = vma->vm_page_prot; + unsigned long pfn = pfn_t_to_pfn(pfn_t); + struct page *page = pfn_to_page(pfn); + unsigned long addr = vmf->address; + int err; + + if (addr < vma->vm_start || addr >= 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 = insert_page(vma, addr, page, pgprot, write); + if (err == -ENOMEM) + return VM_FAULT_OOM; + if (err < 0 && err != -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) { From patchwork Tue Sep 10 04:14:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797871 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: 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-cxl@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: 8FLTFF1tbGPHDHObo9x3BBrfgQo0kcQ7btnVJnhqjc7/m3A5yePlGwc2rEZ9aHYERs61AZrby39RJWG93aZIxXbP0YQvFpXC9ecx+1Bsw/y+GJDEQc16ryp3Yvvo61j01Qvg4hjIZmEt3Xb0Tqaf1zw4WQ6j216vHEfawUbB1PEU9U9iONKVPzj/0DRjOVCoWVKD2fzlrxgsDjSOMVay77Eec2SmSiG78s5+W0nMXzRXGv6kVC4/DwBY6b/q9yXhXpRRM5cKZHZe9gfTXiKgbFFV0EQEIYR4C7dp/di60lWSFtYgYDO/6xI9xwJzIyYDgUkPayMWCDvYq3gWOLaitGyH8g52dwiMPLfqstQQZ9d52r+XiLLFmvO+HYoWBOcR+TG/h6SMOkkNwuK3FJoHHnQM3xsftPkJ8A5MSCZLQaEwCBHKYChxnFVtlyh4e3xj+BGWOcXtpeXBwy023eo+yh6O9s/fLq243vGj7H0Of85nfcQB1crzyl0QjoKRjucXMBqKSrNHKjGqcPCEUM/8yLO7jtWoXbRpnz2q5iSSRO11Ew4mmrwzPoxpHqwhX/kCiYNRuwfsvlvI8eBXLrW/nNGKkqPTy/iKkbLDJyulfuFQHnIcGezzSnxsaQ1nkqI23k0Ek6t19kw8fs14y1m45yomrUH5ju8ROCsZU832JDevfe/MLLfIzUj5JciVPTYHBFb1ABGkqFg/5X4CQXFgtXpwNPIjqfa6am8pJo5H0amUEPCIThrSxC+al1SVm5Lk0Msy7ugWo8P5u1s+Yur7xRbo0wfyRVT8BWdox/Iyp9qHcPxfjVWVCM+loaud1jA1W2+NW3IfiLBEphrBjuld/qiyzN74PDRWHiD0SSAnNEfF8gh8BLZ//3sJky4de3IWrQVgIHly0mAB7bIbI2jX5Mr9JvK9pKTZByVhP2FGarIGeabtHrgI0OX3GBpkP323GZrTyYQED+FasdwD8VEW12cB89yed6v7Fe5Mjn77ppp8yWDasxkV0xFGJzM5+H3D0dZQgZKcIQK27vX+RxVLkuVuHPZLdGj2joIAqSoa+l0bWMeJPoSenO/U29xgBmb4JKpRRatVi8mp9AxjnTkWejZRctvDkWpwaA3v3DpWVWi9SVg8ivQrF2DiuyLrE98XO8uR3GobuEZaMiuqZjODaNz3i7v0gBk3f6o0eeCxRpiQ5VzlWIaaI9o65a7VQo1h+Oiw2lz7+OPHuqbordZPfGhBNSfAJq4OpAg1DGpHdSA4OzgR/cXIWhFCqr/5beOUiSW/0lpyKPxysgRw38AofSrQA0slxVaWzLTnXn8mhESa05EaIGUcNAtVdx7ODjaoV8JWOXQB/WrsRxrhgnerog== 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: O6fAvEy50brguwa6iwu+iZg/Q160isc+uCr2WwThmEWKZ3ThvzTyqK7JuDdCh43H8Jcw9tgeldm/NZO7xHtBG/jJaMqqHZFb88OqhscuGQACw7zfBFLIrznLE0uvBYbe6OC5csAGfyeBdJ8UMXWFVDn8mNfvkAlQEEyTJOcBqU0dA20iP8C1/mJ8iaU8hGGZ3DJWVm9wbNG6XFTieYCe+lA20/T3tULHdEM8/fDoK1W4dYIToLF/+UYPrnVJcmPRK4wKGZEayE/9AkpvRfhdS+GzGjBfKqFX+kRSF21J+R1ona5/OMZWqjJAih0KfrKiSIGgGzQxuyMF8ln2MIJRy7pfJ2itZf2g/xhntSVZSsqP8aN/N+0X3A4JVsJ8Bw7T7h0luCZGQAPCMjrqU6iFCtY3vjkTGn0C+2L6YR2jnsF7w6OWhb8FJwjMgq7S08ymIqf3moqKSCle9/L8ffAVLX90kKnP57WKF+KX3UoTnUYWniHxVWLzPTP5vIpF/qaT66tA9lz/a+vtlA2jkUm3Lo5rpaivJ3ebpJ5fWBkHNWZQsx4D+mSwWO3a/DpBrgmlu8KGfNwYlXbzYejwtqskn19ImdgrNBMN4Gh0PkzYgrmtOnwKDOXjDTffJ5gEhbztwSqQw2AOh9I+VD3ZNxCG7tISzTMxFAQDdxMNP8qEQ5/ClltPwfuUwm+faL+uDp5cDfumwhQD3W9SBx0imuUQ1QDpul7RbzLvhdklNLLNyD5mmMd/I5tHorqdZQvz3Vuoi/uOtSZB3A/TOp1RoweBonN+IHAsMO4pVsii1ELp4v3TO1GxuGvQe/bDQqjzwUquKbbHK4cfeO5OI4hwOmuka0GngdcXxfGO5caGN7Hrc3XxszPuKsOIXjVNS9tWVt35Z/CBw/bC0bfTMuFMdo8JeAMAcBb6p88DMkzoY1OKO81uox6QmqN5HaSr2YA8jxJoQYzUF0x9vNxHHJTsdZgW4c6f33tr8qtZZy+gyx0hbRva3YWOu2d+p05sAdfKTeN9M6KYzPtqKDXxPsKkeHxx2jkXCdce0svRKSeFpmerNRw263/3hGnQ5UoslvxzDGB18PtGaJqBYIfDs+lTVjhJ8ef5vQSGmBY8DchtEY70OljKO5N2If/tJPKMQhBuytB8hdPtVgdvgu+S6YjsQegbayN77foeLz4Y4OgAuACzNZME/Wq/LUAA8p6QI4w/GXm+mRdkrk3Gu1YbNjBPGL0qciLcJQT6Um2x1kC/IxPyEcdKbaoOQzRDDwAXv2JQEXH/KaPTk60LsXYVUvCB+hxzcjXsSTKC+HGUMQb7aVJnrWxiIaRAtcU+gyvV5sIZMTCqmkMlp1ZZ1sjwZZcJXK5pLORP58jL0Ojf3sedBfaBprF8GyUArO80WYI7znKjP5T962KlI+7tUA+uAYNnomou/j7//eo4ljRgHapf69fDLEijAoJCZ9G+0N+Cxh5aYvD8af650rGflL0TutmV2sOB5jJr7+IMpSZaKuKimdSbu+AfEJU4GoZt0jUrSGr/91XRafqOj3QwymtB/R/vZOYHmnegAeOR7gP1OWBvVZXqJA+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 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_area_struct *vma, 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); 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) +#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(struct 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 *vma, unsigned long addr, struct mm_struct *mm = vma->vm_mm; pgprot_t prot = vma->vm_page_prot; pud_t entry; - spinlock_t *ptl; - ptl = pud_lock(mm, pud); if (!pud_none(*pud)) { if (write) { if (pud_pfn(*pud) != pfn_t_to_pfn(pfn)) { WARN_ON_ONCE(!is_huge_zero_pud(*pud)); - goto out_unlock; + return; } entry = pud_mkyoung(*pud); entry = 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; } entry = 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); } /** @@ -1382,6 +1377,7 @@ vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, bool write) unsigned long addr = vmf->address & PUD_MASK; struct vm_area_struct *vma = vmf->vma; pgprot_t pgprot = vma->vm_page_prot; + spinlock_t *ptl; /* * 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) track_pfn_insert(vma, &pgprot, pfn); + ptl = 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 = vmf->vma; + unsigned long addr = vmf->address & PUD_MASK; + pud_t *pud = vmf->pud; + pgprot_t prot = vma->vm_page_prot; + struct mm_struct *mm = vma->vm_mm; + spinlock_t *ptl; + struct folio *folio; + struct page *page; + + if (addr < vma->vm_start || addr >= vma->vm_end) + return VM_FAULT_SIGBUS; + + track_pfn_insert(vma, &prot, pfn); + + ptl = pud_lock(mm, pud); + if (pud_none(*vmf->pud)) { + page = pfn_t_to_page(pfn); + folio = 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 */ 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_area_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 = NULL; @@ -2435,12 +2474,24 @@ int zap_huge_pud(struct mmu_gather *tlb, struct vm_area_struct *vma, orig_pud = 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 = NULL; + struct folio *folio; + + /* No support for anonymous PUD pages or migration yet */ + BUG_ON(vma_is_anonymous(vma) || !pud_present(orig_pud)); + + page = pud_page(orig_pud); + folio = 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_area_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_struct *vma, pud_t *pud, count_vm_event(THP_SPLIT_PUD); - pudp_huge_clear_flush(vma, haddr, pud); + old_pud = pudp_huge_clear_flush(vma, haddr, pud); + if (is_huge_zero_pud(old_pud)) + return; + + if (vma_is_dax(vma)) { + struct page *page = pud_page(old_pud); + struct folio *folio = 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); + } } 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 = atomic_inc_and_test(&folio->_entire_mapcount); if (first) { nr = atomic_add_return_relaxed(ENTIRELY_MAPPED, mapped); @@ -1330,6 +1331,13 @@ static __always_inline void __folio_add_anon_rmap(struct 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 = 0; i < nr_pages; i++) { @@ -1522,6 +1530,26 @@ void folio_add_file_rmap_pmd(struct folio *folio, struct page *page, #endif } +/** + * 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(struct folio *folio, partially_mapped = nr && atomic_read(mapped); break; case RMAP_LEVEL_PMD: + case RMAP_LEVEL_PUD: atomic_dec(&folio->_large_mapcount); last = atomic_add_negative(-1, &folio->_entire_mapcount); if (last) { @@ -1630,6 +1659,26 @@ void folio_remove_rmap_pmd(struct folio *folio, struct page *page, #endif } +/** + * folio_remove_rmap_pud - remove a PUD mapping from a page range of a folio + * @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 */ From patchwork Tue Sep 10 04:14:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797872 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: 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-cxl@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: qSRf7qDFt8xvMAXNJwCg0p+jjeHoeQN8+Js4UWbPFYDXKXNrSvDaWQXKf8pOvAGzAFFnJytfOReYi2v+pBJkT3dM+mnSeWe224nTftm0RjFa2MuFPNEiVzLVlqkEKbBcmr0cbGnR+hEjT2ZaJdQ67ZFi2l/F9wiKPd1apFHc50r8/2LZuvZpRxbLMq67a3bhqAdYaMXF4zef1izCU5Q4/++ObUH/vZ/+WVJhHtcbsYSuUDAcH2W91IUIp58pDmZh0AuUBVNlYs/0Ijizp0eu8BLXBHgnivBwHcEfpjDmC6G0I47vUpxgr+kSCugxmWdiGp9PYEdgkvAQWp6hJuKm5GAwRrqBJpLQGhXwb9UyAnGjXWEzALGhfm5cdIod7JKeXTqsOViV4Nxnw5h0hYsslEGbzkJmkmpEpA7plm4WESNCmuSti2vda9As+B4v+lYWfEgg9qieb7l7z5ji47z63XsRLy3lSegOZLpkavNiBJRg7GuJiAPQvqcbOv/4y8nFiatRRBDtt4IAk6l3JVCr7HEEIXayDiqaevCOUKYywfmTFddWujjK7W7uUfOCDSQeUO26rQafaPpL6bPOK2LAKLWPeWK5PIazAvm2oQ8pNJi/mQOtojHDCbdL+32rp6SC4GBHUAkHzsDAfl15VIQAz2aySUc7BlAmwh6V8d35nRPwNV2ZR/sNRMOl18jSZU3XjDg7xb/7j2pjMEYSw/3o7vfg3eEv5ojb8CE4DbZewpUj8KW/q5ZByHraiIh2wb7eagTCXAF7aMIC/iBXv0C7ARrs4g0BZYHT+YU8SH/mVgw1ka0FzPJTo4PbrKWQT0cGA3c9mAxzynyMrv41HwPOV3zS76vY5VuCKl57BWNppjN7y/Z9QGpQ5vH5eHxWPhpkiXUyi2MkqpUmMGxiMf5KSEutv2qu088u6RRLMZW10a9qiYW7xx0Yv32yoAsBLoFemy7GO5ob54B8QmK2Ahi9+/3guF3202Z/mZ51ZA4DAkoKr39jS4BKXo9mCWKs4zMxK2yFifQUK9hFJrYEmBLN9/9HU7DnFMm9sYmExGa7QOWToYy5WRI5lEhfvowjaHlvFM3NvF4RFa0D46MoJFThud0x1qDgKE8OZCLXWqWjQql1sXzgD2mI30AZZUyNknn7qhN2wTM33sCrtXeBecfRg+fsV+nxh1t3Iw/IuiV90LykxnCFTfXJwnaVcClx4b6DQvygG7HV6Vc9Vj+y+zA2vShjtf7B4JO3Z38clIVs79BY/dT0l4kxg5jjIiEvPn62+PDjPm/i5JtMMfNqmZ8QBRZbGYEZO0KaNnEaYFAKGfpff+/2NSiTh6+VxNAYap5hBAjpUH24wMSuqVOG+5M3xg== 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: sFRNX1Sl7EXocfye4Hj2Apxs/vv4ZJvWgo/yDRCnT7968OusMCDwmNborBC+BuO+69sM6rMkx2cwMkhBeth29XOTZhdn9VVT+oPYhMnRRX1qYZcERUC3AkLdvFgXzOI7AXTsHuCPV56B39SEVwqk4ALecNiJdoSFv+tECTAOOwCDEWT57momtFGhtWxxBPmlBwY+F5cjmz2IBbCWSPnsSaa5iB1IygY4JCaGmeOYrA8p1JSCf6LWMjZkn1vRCObvOOTZ1eXDy+ZtxSol1hFOBzXK2z7zTpVNj7HoXq9XBr7vDmhPCp5xqJW+IZdVwpeNmbbFsjq7nodhxuIMY9/E5SmhR9fejB+wEJIgFOrhO2yk7/EAme9NZxbbPDESxmyms+6ABHOBi+w/lV5yrDQwZqiTn1obTrykHP7yBXZGpn86Lmsm7ltM87mdUpYJ4dGPPS9V4zvCMP0YPKIvR6ZDhyQVu5sOyKoaujxNcQGvw1YhDWnO5Xmkn08MNMvtKaS20cIeWfODvCjR0RAdgOlGxkZXSdopyNwWG8IKJBq7+xx4GAibq1Rl/vGJAhX5HYFG5eqaAL3y9LY6hm5YiDexW7cLcyaHZxM5uMqxuxEqAnlpsyxzPCn+YE3DWi+iL29KgeQX26+yaN0Dw/PYjbs7ihqcLl430pvURMIuVpNB9ZVg1jzh9gCX/SnMyIbJY8GldXWKboWBDCgg+8vQ8j8pIzVRBj86Xye3H7D6yMJ10xLjY+gyACc42rm0l70GSZbKnvcAfXHJqVgZMhQRFHdylrE0LiNpRvimVO/07Y86z3jCtNr1au+LjD4NtTYq+viOS0bWScvgXvaU8URfUW3i26aZSeIwQCLo8thqgcUI1FuogLGnxEFmrSiDcvGhWUk00/GDvr+kMxN6qMGLnA/wcJhPe22+TY1kq0zsHPAtgWCR3iKOJ3SA+BUIcbHyt/Dmz2UjI90s8nmwOUpTHtqDp4Sxk+6tWOCabS0ersx9MGRDVfd+9OuZ68vmH5eW5tXSQQ1pKbMISSsmrtZsmbzDBRtz5EkuMAMOJXSuRdq0I/zqxZRrjM5FZ0tQAgQ0w1nItuVm3kvTvqmBOLThax5qXQI1MePTl25TArSR4hcvTutOc6HyU7mCpLKVbJCV5P17eyBN6scjtMZfkmupsWxxt4qKA/wd7KuKIi/sjBSZeo43dJrzMeTkLbxltbcJGt8sPKhCqM8pEXsRfjW1ljwvJu7suS3dAdCnrBpzbKQjwP01T4fuBV/vVpNZoRHlTuodbwGkLclpROT5P2UYubowf2R13JMIUxi/LdgQ4pdGUFZpekwZeF2qfiB8IXwOAxyc54DxT+tYwPyCbg+s1poJKGou84jNpJb2f3lpmOEn1lftNnpg4uzmlICiTS3RSZfSPPQr2LhMJzYE1TCQ8QPHBhLWIECm6Sc785prsgnpjKcvXP1LwcJHvQmm3/VZoSteCY5Md8ustIVolIYefGmOS1s1TvLiubZ1tDqFD6mQ6oOx/VNEnwjebGYzUO5dV1k87eGnGv6oPvZQYqkY3vKTyOuY8hRAe66fwiI/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 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_area_struct *vma, 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); 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 *vma, unsigned long addr, { struct mm_struct *mm = vma->vm_mm; pmd_t entry; - spinlock_t *ptl; - ptl = pmd_lock(mm, pmd); if (!pmd_none(*pmd)) { if (write) { if (pmd_pfn(*pmd) != pfn_t_to_pfn(pfn)) { WARN_ON_ONCE(!is_huge_zero_pmd(*pmd)); - goto out_unlock; + return; } entry = pmd_mkyoung(*pmd); entry = 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); } - goto out_unlock; + return; } entry = pmd_mkhuge(pfn_t_pmd(pfn, prot)); @@ -1271,11 +1269,6 @@ static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr, 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); } /** @@ -1294,6 +1287,7 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write) struct vm_area_struct *vma = vmf->vma; pgprot_t pgprot = vma->vm_page_prot; pgtable_t pgtable = NULL; + spinlock_t *ptl; /* * 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) } track_pfn_insert(vma, &pgprot, pfn); - + ptl = 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); +vm_fault_t dax_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write) +{ + struct vm_area_struct *vma = vmf->vma; + unsigned long addr = vmf->address & PMD_MASK; + struct mm_struct *mm = vma->vm_mm; + spinlock_t *ptl; + pgtable_t pgtable = NULL; + struct folio *folio; + struct page *page; + + if (addr < vma->vm_start || addr >= vma->vm_end) + return VM_FAULT_SIGBUS; + + if (arch_needs_pgtable_deposit()) { + pgtable = pte_alloc_one(vma->vm_mm); + if (!pgtable) + return VM_FAULT_OOM; + } + + track_pfn_insert(vma, &vma->vm_page_prot, pfn); + + ptl = pmd_lock(mm, vmf->pmd); + if (pmd_none(*vmf->pmd)) { + page = pfn_t_to_page(pfn); + folio = 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) { From patchwork Tue Sep 10 04:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797873 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: 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-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|IA0PR12MB8088:EE_ X-MS-Office365-Filtering-Correlation-Id: 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: N+IfuPAs7XaJc3M9yDU4ghwimT9Ez+RziZdYS1X3rruWJD4fMmspjCzE1uSUQr4fBQ4dVyFm1RsBHjsVBHRNFlTXdwFRkoldYQGdybvNVo+iDqO14q0nphPUwwcnXqRTjYIsgdr1zlSWOjCn9NRu/km9Ng0KuFVaPVnXuYS4xv+3vNSTLGAnddF5eH2Hdg0qcNWoPOLKDjz2H3pDO3+IU586Ku2fJDJS0/StNJsG1y8U1eEX53svdDpFXQ5Kj5DIMKa9MnWzLYZegzg1hjy3/nj62BYMvHtIIKTBWWKiIxnjcZxowChsLSOUlQDzmx0+E7uJwrX4Bvn+mxs0lRkzRA2p3L7YzgiOHE6//g4E3PSf2/nVf/ZeFmKDSdoctm3akAu6WoC2GZoUqzftJx4e4A8ULZJlgYrNoGTQRvaVxV7SXmHmQRHmUEC9khEFdkYSku+++muyShMfBRYDCEQBH6PBG3RgRl0RoFfJhOZfS32GWaAPWEuIVbzYPH3WLWIhdtov9NiEkE9IqtsvLSW9NvtPjrYSZQUccQVZbTHanfjmMbZH9Erfo5ZArnyqGmtzQanpxquQtpeM17SUU1X6nxecModG/2Nfh1mzm0M8x9UcsApV+AoFzJDq/VTm+Ugn0L91UA2HpuhdYGtofY0hEsGhl8s1U7oaoL9IosofhNodm60cNLAQRqQ/IC++yXWm+Tz+anhqXyU/yubCujEDeEUGe4Peg77GomhRaryzTi5ID43t4AVIAVE8upYOWgQYXfaazTyTPewRabwoxfI7q75HRK82B4lLAs/6ZxrGJYcrq/wn5Bz0FC02w3clztW4czPJboVUvAWfcrQAzfHyFINCkMh7Ypkagmwt9wl6zwBWNjdD8sam6+WpZsK7qYDZz0LorwyXycTjtru0k+TMlRA66Sa6IJ5YZQdkDeRebjOZt4WQGK2lahXUzOWyRK9iPpVxg76OSiKDFUBV4KeUdRKXk1CeBbzdNwYzXgd9owAw4Vat7QF474ojoiR5dwvqalPZ5oAcFIYEk4YjwlmHXG473ZsfuCyM7Rm4OzxCICA+8zR/UTrAFeOBv326iwG9dQWJKoR0QvUCygu/5GTD+VzDZA/RwVWxq1QACdQeD/irKyroqXvRAiAHhhImO23T6FSHiddV7bdN5omJrFoldaziiqcE+JpPgpwVuxDDSzPOrNrr3NCG3SKBkQZdA617tUBdFiazZnDy1kj+lvVqWM0ywLSRdwy1SKsoBQatjbN95/SAvsxDP7lVOocVKKQSr5nDEnPr687ix2a/sUjGXtNwIYdEXmRKwFbvbEn/H9BU4OpzPLwasj5OrHsPiVQxC2AA79eCo8qitcZ5ooKQcQ== 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: z5lgFlHP7AzaYSp3mkzVPbqYuTtAeWoEg1C+f0xOkrXprZR2ZkBCc28IqRn3ORx9CgB53vzROsRRMtgtC9bOfvfS90Tx3rWALkBm/g8KrozgWe1aIjhECrLZPgdxrAt29U3J0GVap5yzyEzcZcqqd43B4FuNzNgUyWNvqJBVIzhqBX1lYv4x8Hpnps7jTVnpukr2hisq8M37qauC/GHK1iDxXcjT08W35a8jZD0acWWIKbL+6TTqliv96vLIOHnmfWxJMyZT/4qNTVC+PyMYuaSS7MhaYds6YthfivGeP7YKd55HM7NT0glcxd3g0ODW2++LYAJLUxmZnXEnNdmsN2jEMMad13HJU3A++TLEdbMVhydYFvjxiP6GgN/JQAla9TAPkSaih1x7/50wXXX5fToB4DlBr9F9mt1/kU09dSUvbrZqUb1qJC1FvAabUhgcQIe2inaQYX8RB1kpDoAmgoOnsgBKAbx1jhlaGYZ65ZK7Qosa4Fw7I+jetlzko+pyOUqL5IQ4JrAB6Rg7cXPGaYB7it7HZ/qfMRKdXYUo8M5uzYGi0BAZ9bhLMVqfK5EkZoPN9YKz7mPCmKiypcOQKKsDuERRasrT7PXpfQlz+RhcIo9JejwrIi2hyyOhgETyrxA7/fYwEZ2mgTo4YLTF1e8ULhdoes77tyXFIH9hjkfv4lJnneBaeYUSqihWUiwT9fMLeAVVSZgVJ5hg9u5bePDOcZ0J0QziFx1gBZ0i50fvoDOfTgTzWi3Tk3cjSg4g02sPitgum/67XoBXjCh+oYYliZiE42Ua0VSeJYrAu7iPSk4jnZnzCffFtE66/pnxQkaEpFsOkQr6xahDuS3FjLXXulKcRfbnK1Q4DlvQhANwjNqAsVhHgHTdroYUUITTaWbGNFIyxGpzOgMdxZzLvM7fVFfTipRYSHYKeGBgUdPMUZ/yPP+PiIsipDtUiEdHbNJ54tTmpi4CQMHoG1hLCjjrBfX/B8rd3cZW8X/T2W6HXa8gWyuQ4FU+iC5uHR/tMn1tQ0nF8JLtrh6J17Slb2oFg9K+Xcf8sKnLu7G6CVFHDf4d6mcmduVMYIOHG3MobcCVuCHq9JXX3v28OVBCDHjRnPbTuEZL8JA97uXeT6KDeJkUCnHThP1N3ZVdyEJOYWEkgsRDoO09+bYtCZELWQinb26QLYqm+1mqufiyXq9KpRqIMYBm4G92Kbmhi8bogdWLePblI4Y0SRb0hmyKx4+61AC0S49nkeFY8iqWW/fAiTpVkQSAqNYzY8aG3GoFWaxkXVXeHKzDDxcgeSjzLYiWFKk78yCIGIW9oBmrMPBlQqjhCKm3pumDCUUO7mNH+P4AYY82n9MfH7Gi+kLNlJXdqhC2PIKGVwgdnU3mzpHBEMW7bwFaSPt4fwDKZseUBT277HO/ejjRjZk8Th24+SZF8jRtf9eJVqYMCm1d61dzM2FOtsGt4OQedwG0RsKJzKQfjtt0V6mU2W1cJAmoTu3hOQCmIF8NsCzwYxPoPGq8awIHfpA2VgKFCGRvWzgz1LP7S9MsGOsuzfoSogrmxKAt9x65Cd8c9QSUXfEYE2UIPo9gGIXZk6qhJDc2z7mU 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 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 struct folio *folio) return is_device_coherent_page(&folio->page); } +static inline bool is_device_dax_page(const struct page *page) +{ + return is_zone_device_page(page) && + page_dev_pagemap(page)->type == 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; + /* 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); From patchwork Tue Sep 10 04:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797874 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2055.outbound.protection.outlook.com [40.107.236.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1ACEC19067C; Tue, 10 Sep 2024 04:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941746; cv=fail; b=P+wkXG0C2vtXTI6fLGn+hgoSGeGNJSoS3TYTclAtheaTswxhEYREVhSNQL7cdMoWi1qjos7B6yXw2XE4zIeulgzMFLFIdTJNfMl34SNsWnItIR21bAP5sziA+BQ11gve79VvzjTyu5IGLeqvq1JL8enQAM0sQk/rktS7kiKsyyU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725941746; c=relaxed/simple; bh=8W044OLZm3ALC5/sg3Oqz8bwVK13cS+oWh1yt743ByE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=OYn/3QTdIEn9JMDvrBIVZ8m0J8LrZ2uQTV5czvB8cYDSFdzQD7nvFOFCwt4HAL6V+0Gbr3IcFAb8o59HJWR0w0NVXx/RQSDRlrOsaTtxlPdA3VkVaKTfkVvD/l8NvZGIlm3f3CqNOOsitMcBBe/f+fJ38TpC1q6U9ZmLZemtawY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ZPk/crcO; arc=fail smtp.client-ip=40.107.236.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ZPk/crcO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MXI1xaJfqIvkKMabg2YvEFD9cegZN5DLWoR441UhNNXEggfAWCdNCtDWo8gTOcwr44m+CnFKbE2wREg4XUaoR7lwjUKM8KI7NKUjj/7pOwGYTdeYGIxxhyWv5bdH2cpR8VmB+kS/DS/9G+HWOZv64OD3H0afFZRWGpyPRV/DGoVA4cpHIZyUojwwwdorxzshb34W0Gb7DSnNAIRIEdJqWTPcwL/N71V3RiB9GRipWMODrLi8zwZwmlXJfXfLdMUVpA6wqT56aVp2jWko3R+lOKwU1EQIVqQ6Q9HJLAljWG6MYOj3z0E84ErWs3SD/uRQ85VNS+ZT50NTP4Aybdo72g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oV3RuJwb+sRS9SntpWvyzIKrNy8Tuttg1UxdDOww1Ro=; b=LWc7Dn0S4HZl5pPJOTpM8oSGiMvpw7toO0C2Pzj1IGwi4uEbTTDezhLZY7e/7flsVepnvugBKhly8HCiHyadh1SbVlw7DnsSlcf3FXTqfjEtOSbdz4SABmsK0O42YKOGb1rkBEz8oL48xzQGCBBm1my3RCz+XqEbEZH3P7NGCgUE866Ifr2Tchl2qnQ7NZZ3U0oqKfxlfgtnLyFR3Lz/vCmCtAA1ljMGe/Jwlw/FvosnnR0k/GMcl1P6GdRxhIBeucA6ZGN7OjZErLpxrnhdM6IjcMH5c/+t/ajyUQqGF1OpiCRPJIYLLVRtnPRa4PROnCRhdzUAO47ZtmdhckjkdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oV3RuJwb+sRS9SntpWvyzIKrNy8Tuttg1UxdDOww1Ro=; b=ZPk/crcOCvT2mHOf3/9FCx7Fam/l0kGA4CPjvFozGz48KeLxkrnScEokFEpQFwoU0mCy6SSQqiZ2lVdF8T25SGJ1cie/kywHjq49PDfBlBxLgvMbRlyM5XDPqaAFUaSQbYvxIMOS9aIokksEl3+LAMJrVe/iBgIwaSCiiX1235+rC0IogacgX6U6S2L61w+1SC6vSa2Q4FnvSPdHLoz2WnZ+m9rnXruIvvvNHcBJRGISPFr5m23zdBnq1xAFrXdKHj6tTDuW/VGmLyrbF5lgbD0kSB77AJLvnbccz1c6qtAmtvE9zMoFyV+UkLEdmeTCbJN0MHYEdw/4ttnSSvzQhA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by IA0PR12MB8088.namprd12.prod.outlook.com (2603:10b6:208:409::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Tue, 10 Sep 2024 04:15:41 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%3]) with mapi id 15.20.7918.024; Tue, 10 Sep 2024 04:15:41 +0000 From: Alistair Popple To: dan.j.williams@intel.com, linux-mm@kvack.org Cc: Alistair Popple , vishal.l.verma@intel.com, dave.jiang@intel.com, logang@deltatee.com, bhelgaas@google.com, jack@suse.cz, jgg@ziepe.ca, catalin.marinas@arm.com, will@kernel.org, mpe@ellerman.id.au, npiggin@gmail.com, dave.hansen@linux.intel.com, ira.weiny@intel.com, willy@infradead.org, djwong@kernel.org, tytso@mit.edu, linmiaohe@huawei.com, david@redhat.com, peterx@redhat.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, jhubbard@nvidia.com, hch@lst.de, david@fromorbit.com Subject: [PATCH 09/12] mm: Update vm_normal_page() callers to accept FS DAX pages Date: Tue, 10 Sep 2024 14:14:34 +1000 Message-ID: <64f1664980bed3da01b771afdfc4056825b61277.1725941415.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-ClientProxiedBy: SY5PR01CA0005.ausprd01.prod.outlook.com (2603:10c6:10:1fa::13) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|IA0PR12MB8088:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d96d962-ecac-4a36-9c2f-08dcd14f3bbb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: p0/XSu+j6RC4amQIub1I+NvbR/EvWujIS4R49iplf0dgWgY29I8KiQVttazJoBkrxoGLPyml53b6bJ1gqCMw0FlE77JVFw5g+qhWlK7s9OG6K9uFI8ZX8DMvj9BeFt4rsj9Xj2VJPpfqVtwSuzHWhee4WPsWnbTePWI65dqs5NyHTcDOMXxVuTLmCUZfVyD+Q9s4n+dRb7ZenPhZe3aB/wuNu91ORvUJPhZ0qocJ2pdBE5LGfmvdSeSim/xN7lRJ3Q3vJ5rfa8S+hdH6LgZ2lEAtgVz+CrrOBRVnMbdz9U01drvYAztD95VSgzbXHvDemyXKY7nYr25dm6SpM+4KEw7BhvRisHrp0ne5aqtRgoS4pLAzzT+2Pf6lG12osuhiqyfVijzNUYrOmvbPAD5V8P3cTU2QFjn5pW1Q/rda3eU8+F4MRYTzRVMrIRtFGMbtmz7gS6tyGuYeXa5ViA4nqFgemLkb0FACLtK3N7nNiLSwG4/jMm0VnfN5jolL/wJ6vB9qTSeb/85zct/QHpEctigmFZLNllzvclZCu01w5ghKGowjgmQIQlV2lAW0iSSBoRdfGlkBlA+jkTirf0s/b/P/pK8SKLdYMUsmyXlcv7z5YT7gT2l/osdBnMQlmNgpgj5YkvaTLtqag9xrtM9eOEgnqK4JV04vo/cpN5yDiNUzirRHm/3ba8h4HcXC580QYclgNDEGKlO6HcqjFMCmHzcLKoDLCqIfhLZTxQ2FE05W43j5JnflqteswDo9dOT0eZX1j8WLXAedYAPyleQrCp92BCehpoEq9kFKpy7r64c0k56CuhQm2fP8uF+4t+j976aH0sO/UPrUMDXZq+bPqqkqKXzh/OryjL4VfpsAO2c99nRFNRytdtcJ6gZK8iY6uQy0R62NXaviR5RdhCFEsuVtY9TzDYvohbHgG0BzoswvMF6zjwc/VP5/TyuXd/4QYZffBN2G+oO+9JOdXDwCPNB+oKzM8YGYRrgbM/230dkZMSZ/FA07JkQrheLVOXGiMzwtwBb/uvHV3lRU0fHbBYRm+Z65vMg5oNuRJthLWWOA2XPFaakAbNh/W21J538v/I0S4LuM1mWBhBeGuZI1bIBWwex5WOjGzP4t52Q1qNNdnqCM0e2xy0cewCoqNxR8VOuDwNm7LlIY6uiEqqZ5/0Nh8cOwn0t27SojAdQkRSR3T0kg5vThwHBk9uRnoDj0TrN4DyogtS6UYH4HPLeg4nalq4V1/p9hnjGF76ip3gSaqhPAeICgKIMTLFtMOMJMx7LbzpfmGUrd8riPT7vfa9R0Wj/3ZfPkMKhada/C2lFLb+imdLwoKTha62TGzKxvtDLcU3VyZxznCg/vTlrFfA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB7726.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /pHOMGGcH0XJuO5Wsr+OtYTbWqAxzCvfpUql0taa19y8j8xA43gaFKaZf+jig6m7IA+g89wyglmxqBnQJDWfvrJUnbxJSTCuTm95nlhkTDk5XpntEnPtgpBRAhoJXf9uQXsj6HZ8Jogl5pnI6pvhB0NiBjk5NXSpCu3OgUTEaYlEdVFhkJYteGmP8E8gL55Le5JhNEzRaJfhMYjgSYEKLFN7h7CCAYcp/AiYUSgtL59Nt9cX246SglUrDpTSIc/aI7rU9gOZ67NeCL3GGW3uQyKFWOk7huxyItY54ggf7/k4mRx+O0h953do6vnWbKjsLAoTAGwNkssJp9STNWyt8Z2wt8n+Q441PfzaruBttfHuzEvMiSsZPt7Qo0c2Zy2W4let81cKof+p9OJ+7xnnXMlnESgdg5I8Inu7t412PnOyfjp+BchXSoAD2Bgt1RybN+IFBoEl+ia9D68JOSxl8P0/rrXK9kQXk/Bwy813soeC+/MA+D4hkSieowEb+exoq0iWQyQMwplurYOXy1rlsLWX4jvWAx3jRs31QQr2pNE9YVGoF5ZL298JDJmdr1qG15ODoVQqVPTymc9DIMePtsRr53YuqZXk0CQtJCk7qsD+dK4QSjXSZ88/G10Lzk/2CaJIK87mo5f33PRlpp4bEMFBv2BVYLK51tQ2KNdoeED9PfDC0ZKqTGIQPcTnq9fnsqsyHpPCtO+nsp/WrnhjqP6od1NatHdYjbO7v36YUkWfIovyKVJsakK9blPhcXjBbWgy++W33bCMbSNJzaAA3uWTJe37OASyR9KJLZMopaYZLi2nJwFY3xrklQDKIIEaGgwVCPIWrntPPzJodAHdKOwrX0XMzOBNAIHBi3WxNgu/TdY+McwVE17gCOdzLKyxqP2f574B2kcsvoJC+J1bl5QPVupcNwvAUbNfBuNUt7b3OM2YTrigyFnjaIXOHCRejfPySagz/9eTdKo1NCu6EoSA3NcKQdMBNZPI4zA60LHxAV9jaNbWAvXRL/wpr1iKv4JF/clcFT3k4tpuCbT3tKBch7d9S8KKzfDIwslM+R6IpB9jnvZVQkc8Cz6A4qJ2Msm5HEpOd3sAwbxq34RNdgxu9P/f3ereyKbuae9tY574IPnawrXBjNpo7szcktxcB8bRqc8A2BmLLlR0zLCDqb+NPQz56HBdV67t9pbIAwM/io99O1EGSpI1WjgrJGQj/VuF/oSJGtK8fbXvHM/I50Hl3oKznkgMRuLveMKHfqV6h+5ufOjfzMRNVx/GGPx8VtKqn1IbtkDWQLO9ZPpRdl4IeiVUDSc/ia7WBej4+nVjXisUirGGZ7ZW9LbcbUAbHdNyM9aG31uFr703dJjBGC684kgdqtoR22K1M7Bd6MMhZdItKa8872K/D4yNmhlGE2EeDdGENxbju4v89F6FI+R2IRQ69L8KxuJfNUnFy55NKB1qnf1odz2cl782kN3JiNYleo3vI3247kWlSsT7QfyhhQjfdZh9IXisJiLfrhptVkMVwG6efpJzqvA98qcZBDGi6DY8+orzhAQyFSRd+esa5qbvBz7IVOYLLF0L6rt6nIM499dTW22cOyceY54b X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d96d962-ecac-4a36-9c2f-08dcd14f3bbb X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 04:15:41.7306 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: V3dOcpNl6wWF+ecILF5shF8I1HGH/hLFOmqxI6ecYfW7ol7oG/75AmXfONWBAJ8yFnIrCYz7s1BGRbcYbH/GFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8088 Currently if a PTE points to a FS DAX page vm_normal_page() will return NULL as these have their own special refcounting scheme. A future change will allow FS DAX pages to be refcounted the same as any other normal page. Therefore vm_normal_page() will start returning FS DAX pages. To avoid any change in behaviour callers that don't expect FS DAX pages will need to explicitly check for this. As vm_normal_page() can already return ZONE_DEVICE pages most callers already include a check for any ZONE_DEVICE page. However some callers don't, so add explicit checks where required. Signed-off-by: Alistair Popple --- arch/x86/mm/pat/memtype.c | 4 +++- fs/proc/task_mmu.c | 16 ++++++++++++---- mm/memcontrol-v1.c | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 1fa0bf6..eb84593 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -951,6 +951,7 @@ static void free_pfn_range(u64 paddr, unsigned long size) static int follow_phys(struct vm_area_struct *vma, unsigned long *prot, resource_size_t *phys) { + struct folio *folio; pte_t *ptep, pte; spinlock_t *ptl; @@ -960,7 +961,8 @@ static int follow_phys(struct vm_area_struct *vma, unsigned long *prot, pte = ptep_get(ptep); /* Never return PFNs of anon folios in COW mappings. */ - if (vm_normal_folio(vma, vma->vm_start, pte)) { + folio = vm_normal_folio(vma, vma->vm_start, pte); + if (folio || (folio && !folio_is_device_dax(folio))) { pte_unmap_unlock(ptep, ptl); return -EINVAL; } diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 5f171ad..456b010 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -816,6 +816,8 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, if (pte_present(ptent)) { page = vm_normal_page(vma, addr, ptent); + if (page && is_device_dax_page(page)) + page = NULL; young = pte_young(ptent); dirty = pte_dirty(ptent); present = true; @@ -864,6 +866,8 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, if (pmd_present(*pmd)) { page = vm_normal_page_pmd(vma, addr, *pmd); + if (page && is_device_dax_page(page)) + page = NULL; present = true; } else if (unlikely(thp_migration_supported() && is_swap_pmd(*pmd))) { swp_entry_t entry = pmd_to_swp_entry(*pmd); @@ -1385,7 +1389,7 @@ static inline bool pte_is_pinned(struct vm_area_struct *vma, unsigned long addr, if (likely(!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))) return false; folio = vm_normal_folio(vma, addr, pte); - if (!folio) + if (!folio || folio_is_device_dax(folio)) return false; return folio_maybe_dma_pinned(folio); } @@ -1710,6 +1714,8 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, frame = pte_pfn(pte); flags |= PM_PRESENT; page = vm_normal_page(vma, addr, pte); + if (page && is_device_dax_page(page)) + page = NULL; if (pte_soft_dirty(pte)) flags |= PM_SOFT_DIRTY; if (pte_uffd_wp(pte)) @@ -2096,7 +2102,8 @@ static unsigned long pagemap_page_category(struct pagemap_scan_private *p, if (p->masks_of_interest & PAGE_IS_FILE) { page = vm_normal_page(vma, addr, pte); - if (page && !PageAnon(page)) + if (page && !PageAnon(page) && + !is_device_dax_page(page)) categories |= PAGE_IS_FILE; } @@ -2158,7 +2165,8 @@ static unsigned long pagemap_thp_category(struct pagemap_scan_private *p, if (p->masks_of_interest & PAGE_IS_FILE) { page = vm_normal_page_pmd(vma, addr, pmd); - if (page && !PageAnon(page)) + if (page && !PageAnon(page) && + !is_device_dax_page(page)) categories |= PAGE_IS_FILE; } @@ -2919,7 +2927,7 @@ static struct page *can_gather_numa_stats_pmd(pmd_t pmd, return NULL; page = vm_normal_page_pmd(vma, addr, pmd); - if (!page) + if (!page || is_device_dax_page(page)) return NULL; if (PageReserved(page)) diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index b37c0d8..e16053c 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -667,7 +667,7 @@ static struct page *mc_handle_present_pte(struct vm_area_struct *vma, { struct page *page = vm_normal_page(vma, addr, ptent); - if (!page) + if (!page || is_device_dax_page(page)) return NULL; if (PageAnon(page)) { if (!(mc.flags & MOVE_ANON)) From patchwork Tue Sep 10 04:14:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797875 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: 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-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|IA0PR12MB8088:EE_ X-MS-Office365-Filtering-Correlation-Id: 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: 8CiSMj5pK0SlWAHNC/J6vVfa0y5qcwlpZXjSI2KG7wipzNiQGIXjTu/Bc72usrwLLmrG+2Zl4CxNuYcr6gfHTuyqj67f+aDweFhsUh+b33g2VU9hz56jOBjTCD2mZjVZGMen4PyRG0C3BslGLOTP+1aM3L+hEdoIEBCe9kwpYU3WZ3t8nlFwmRGpkl/7kZok20S0Kh1KxH1kF/Z8WpB8U6YXSwyvAnM19dkpE1i0ilPDA7/BsaXaVIaLIRjGuBuc+oDNKp7m1fa4KCKXH0gnRjJElV+INv6aARqAeRFLKp72LHjs0+Tvhw6De4eH4+hInqSr9FwEPqsHDFMJJz5c89urz2gGErK9x8n181zNNtSqoaYow03W+J/xPlSWCiBNcGZIK9qq5+mBnsxzGRFsxVDVQLxpi/kP64tkui2w/sA6yzvCHqrl0tka72gSXQ5lnGZ9Gu1Wsy8NiSDFyIw5IDAPcgiAfrXnWp5KQk7H+CVGY56OQru5zx5iDAg5lFMu9emmyGzkUGZI+R6Ct80jauOeifu2oz97S7wwHUllFgGaiK61kMouRawJNUCnNYOjLVSx2H7ZDoD74rn1OGdQyftJhNcdMahah/bO6P4PkjkDfZeM5Zuve9Sln8wqEBjl9jjy5Rk3etjv4INgwb7KU2TA/fJTAyyuNlRvbOFVlI8M7vnnBmFa+yB1S4dAQXgcuaFIxDegfR3VWU+gJ3cwgYV1MhsxNISF1MBvDweWfzCXOMtM6pty8g/4tx6bK4yC65rS4xpbdz37mrJ3AdkWSMLMp5csn/zZ+jq91dTOHa9wS5yNTPNV63OC1tBVIcnR8ab6QqBTl0ZX4orKlpwzOqLFcCUqVchmFaSRwn1QuJZeb33K39AYYzEXFxk2CyE8PRtmktXQfRohm8RoAvtl7Uec8a5tIzQH+auVlV0KAkiHfEqrSZcNh65VP631b/zO1wTZ6Hp2Yf+v1E0lcAIhVpcs5WRPqBbEQiCd4NMer9O9kdi1nAQqmDVXczEBulGY8hEjbUz8nQ3utwmJTYcloy6u0Vd1nyo2BHNciQ7wOR0skyaBvRr5MZG0moiJQG1Yb/TnMb4dWtuRm5gIGv1fTIpPU9yS/tYEwuG9AAeF2QKv0RVtqGAOLRV2SuZnFhEkFsNmfK7L/Mb+tyWMxpKIsdRFVE1EFQM29jfh8P8fvQtuTNXD5uMerCItrdqKphBIgEV1IvpQcLvD+A/YvAZ4F8MUVeQHcerm/8XOYA3mmWPZu/fQXbpnASHfh9vS343u4kW3s0IccrMa18Evby798a6Bhzm7dmsdt5ywf/TPFMWl6kYGxWC3zbceL+B0CEMHJ9FPpkn6wy5ICk5SwBDbtg== 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: /t/M9I4z9PudY7sqaVCuj6nygIGp3Q1ilyeC2fjQoAl1zDORGXtBB0o1hhYPdWFqCPuxE/Nzaeh+cUWs+udDBdRuPHY7SutFPEuhTCAPMkK1YphqmF2tnBWmYC0vYkWgXWja9iOKj+iTIaqrN9Zllml93iP+V5krtrk7b33wnR6AtXXNw9Mob8mZQuK7r/Z1RyQ+r/B5NStaz/cMG4JPt9oXbQDfc/LEMjNx5MaKJUHVSCcXtukQSQCKI43hczMQ/mLRffxGmQ3lzNGNK60e+UbjX+QHnvV4GPzYCHeOOrySEcClswk+Et6ir0QwH8Ibijj19QH3qBERMJPqQlZIJLcyPrUOYjtpm6zRmSfcZ4L6hGQckyMzVNxMzeQz8sSx9tPKKh5nR+lCTTbYN83nFQMJeRP13x2fNQZ2M04HALyfeYo4p1JftuYJJdO1jhBn9XK8Ndq+GORfbB1Yi5khgETh+jQNTXrVU52o3ll17t6p7JWzu6jd6jOMqJw7K4D5QrMpF/iciEWUQkyGy0IRgsnvDuvYHHpaCzOQoY5HYhkTK2nbu9aiDOiTqQUxKBrbvZMhd0YswDt87gWqXHzvZ0xPo1v3dxwY2mvdPZ2/clt9A3EXskY3REffZzadAAMlAri6N+Rzd58jGAXGfthFs0JPeNkVDcZ8c1fTc+pBKuIgHuZjSxxwkdvNRp4uJBWfHDFfnunDkCy12kuB3br/TacNMEC8tsIw56tX6QdMBitVKwIjb4L+PdMUaf/DvaziCyrWp5WEQMVjinmvwGE1PFpW59yOKxGLAB+2Xs9KjA/KSzHeA/TJkpQoibhYtDWeAZo9jyBBv3Iaf1u6A8fMaYnodyf5A/DKvk+MCfSGD1etedr9H2sdNtIiZ6Zg8+ZZV/UcFJfszhFYeecN8+9BjOv7w9S1GOPSJD7qCzcNJHOnKOjto71BmQNY/Ynb83feB4NHD5eJWfTNPH+AN/zEkJcCwyPFZCcFMMKdeU8dUisU636uqWVM0mVh58SvTm+LYj8exoi5QOCzZGs8AVSqgtXdJWY6C/qcb9iJhRnHVfBSltJhYe7QC92rmYBJQwEdoZTIERQddoFlLtphv/RJupDWqOUdXGGUXol8ZZ3q6Y0wnqjQkhg9ECm8bA8kT7+NGohVy5rj9Hynx+sp4lMEEAV/4ntYc8uD2yG+CB3fuO7kzkzFm37X1HrmXAOICkXmxG0hXHDdyjVWPzmHqmo4lcNI72FGxUJSO+3XC0qEoPcd7uGJWS2afrT2UB9LBDoDiXRamLWi/lAsA/aEONL1CMha+UuyaXARTrBMoNrLEbpCi0KT+BPgDIT1/8wEvVYDZn8khxZm4FUSobhcInwYGD20EELcbj9Nu3EJiqYEGfJto5GSwKkLEjCFGuQEP2F1NIPjCYRSaEaNtl0C204N/N+JouDQJOUs7+QUnfVFBCreP8L//TlZDx2K3761NR/dQ8FTR2nsSsG+pjkxT6cOBmCk0nQ9yhKCtRFxbpv+ExbqDd357QQR8O1xnsigg6q65ivL4SUCmPVK2PUzOtEro/84GctPM6gXlx/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 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; } - pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); + pfn = phys_to_pfn_t(phys, 0); dax_set_mapping(vmf, pfn, fault_size); - return vmf_insert_mixed(vmf->vma, vmf->address, pfn); + return dax_insert_pfn(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); } 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; } - pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); + pfn = phys_to_pfn_t(phys, 0); dax_set_mapping(vmf, pfn, fault_size); - return vmf_insert_pfn_pmd(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); + return dax_insert_pfn_pmd(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); } #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; } - pfn = phys_to_pfn_t(phys, PFN_DEV|PFN_MAP); + pfn = phys_to_pfn_t(phys, 0); dax_set_mapping(vmf, pfn, fault_size); - return vmf_insert_pfn_pud(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE); + return 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; 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, pmem->disk = disk; pmem->pgmap.owner = pmem; - pmem->pfn_flags = PFN_DEV; + pmem->pfn_flags = 0; if (is_nd_pfn(dev)) { pmem->pgmap.type = MEMORY_DEVICE_FS_DAX; pmem->pgmap.ops = &fsdax_pagemap_ops; @@ -522,7 +522,6 @@ static int pmem_attach_disk(struct device *dev, pmem->data_offset = le64_to_cpu(pfn_sb->dataoff); pmem->pfn_pad = resource_size(res) - range_len(&pmem->pgmap.range); - pmem->pfn_flags |= PFN_MAP; bb_range = pmem->pgmap.range; bb_range.start += 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 = MEMORY_DEVICE_FS_DAX; pmem->pgmap.ops = &fsdax_pagemap_ops; addr = devm_memremap_pages(dev, &pmem->pgmap); - pmem->pfn_flags |= PFN_MAP; bb_range = pmem->pgmap.range; } else { addr = 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; } +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 = dax_to_pfn(entry); \ - pfn < dax_end_pfn(entry); pfn++) + pfn < dax_end_pfn(entry); pfn++) -static inline bool dax_page_is_shared(struct page *page) +static void dax_device_folio_init(struct folio *folio, int order) { - return page->mapping == PAGE_MAPPING_DAX_SHARED; -} + int orig_order = folio_order(folio); + int i; -/* - * 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 != PAGE_MAPPING_DAX_SHARED) { - /* - * Reset the index if the page was already mapped - * regularly before. - */ - if (page->mapping) - page->share = 1; - page->mapping = PAGE_MAPPING_DAX_SHARED; - } - page->share++; -} + if (orig_order != order) { + struct dev_pagemap *pgmap = page_dev_pagemap(&folio->page); -static inline unsigned long dax_page_share_put(struct page *page) -{ - return --page->share; -} + for (i = 0; i < (1UL << orig_order); i++) { + struct page *page = folio_page(folio, i); -/* - * 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->mapping - * 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 = dax_entry_size(entry), pfn, index; - int i = 0; + ClearPageHead(page); + clear_compound_head(page); - if (IS_ENABLED(CONFIG_FS_DAX_LIMITED)) - return; - - index = linear_page_index(vma, address & ~(size - 1)); - for_each_mapped_pfn(entry, pfn) { - struct page *page = pfn_to_page(pfn); + /* + * Reset pgmap which was over-written by + * prep_compound_page(). + */ + page_folio(page)->pgmap = pgmap; - if (shared) { - dax_page_share_get(page); - } else { - WARN_ON_ONCE(page->mapping); - page->mapping = mapping; - page->index = index + i++; + /* Make sure this isn't set to TAIL_MAPPING */ + page->mapping = NULL; } } + + if (order > 0) { + prep_compound_page(&folio->page, order); + if (order > 1) + INIT_LIST_HEAD(&folio->_deferred_list); + } } -static void dax_disassociate_entry(void *entry, struct address_space *mapping, - bool trunc) +static void dax_associate_new_entry(void *entry, struct address_space *mapping, + pgoff_t index) { - unsigned long pfn; + unsigned long order = dax_entry_order(entry); + struct folio *folio = dax_to_folio(entry); - if (IS_ENABLED(CONFIG_FS_DAX_LIMITED)) + if (!dax_entry_size(entry)) return; - for_each_mapped_pfn(entry, pfn) { - struct page *page = 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 != mapping); - page->mapping = NULL; - page->index = 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 = mapping; + folio->index = index; } 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 = pfn_to_page(pfn); - 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); } - dax_disassociate_entry(entry, mapping, false); xas_store(xas, NULL); /* undo the PMD join */ dax_wake_entry(xas, entry, WAKE_ALL); mapping->nrpages -= PG_PMD_NR; @@ -743,7 +720,7 @@ struct page *dax_layout_busy_page(struct address_space *mapping) EXPORT_SYMBOL_GPL(dax_layout_busy_page); 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 = 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 -= 1UL << dax_entry_order(entry); ret = 1; @@ -894,9 +870,11 @@ static void *dax_insert_entry(struct xa_state *xas, struct vm_fault *vmf, if (shared || dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) { void *old; - 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 = 0; out_check_addr: @@ -1189,11 +1165,14 @@ static vm_fault_t dax_load_hole(struct xa_state *xas, struct vm_fault *vmf, struct inode *inode = iter->inode; unsigned long vaddr = vmf->address; pfn_t pfn = pfn_to_pfn_t(my_zero_pfn(vaddr)); + struct page *page = pfn_t_to_page(pfn); vm_fault_t ret; *entry = dax_insert_entry(xas, vmf, iter, *entry, pfn, DAX_ZERO_PAGE); - ret = vmf_insert_mixed(vmf->vma, vaddr, pfn); + page_ref_inc(page); + ret = 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; - zero_folio = mm_get_huge_zero_folio(vmf->vma->vm_mm); + if (arch_needs_pgtable_deposit()) { + pgtable = pte_alloc_one(vma->vm_mm); + if (!pgtable) + return VM_FAULT_OOM; + } + zero_folio = mm_get_huge_zero_folio(vmf->vma->vm_mm); if (unlikely(!zero_folio)) goto fallback; @@ -1221,29 +1205,23 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, *entry = dax_insert_entry(xas, vmf, iter, *entry, pfn, DAX_PMD | DAX_ZERO_PAGE); - if (arch_needs_pgtable_deposit()) { - pgtable = pte_alloc_one(vma->vm_mm); - if (!pgtable) - return VM_FAULT_OOM; - } - ptl = 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; - if (pgtable) { - pgtable_trans_huge_deposit(vma->vm_mm, vmf->pmd, pgtable); - mm_inc_nr_ptes(vma->vm_mm); - } - pmd_entry = mk_pmd(&zero_folio->page, vmf->vma->vm_page_prot); + pmd_entry = mk_pmd(&zero_folio->page, vma->vm_page_prot); pmd_entry = 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; +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 *vmf, loff_t pos = (loff_t)xas->xa_index << PAGE_SHIFT; bool write = iter->flags & IOMAP_WRITE; unsigned long entry_flags = pmd ? DAX_PMD : 0; - int err = 0; + int ret, err = 0; pfn_t pfn; void *kaddr; + struct page *page; 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 *vmf, if (dax_fault_is_synchronous(iter, vmf->vma)) return dax_fault_synchronous_pfnp(pfnp, pfn); - /* insert PMD pfn */ + page = pfn_t_to_page(pfn); + page_ref_inc(page); + if (pmd) - return vmf_insert_pfn_pmd(vmf, pfn, write); + ret = dax_insert_pfn_pmd(vmf, pfn, write); + else + ret = dax_insert_pfn(vmf, pfn, write); - /* 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; } 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 pfn, unsigned int order) XA_STATE_ORDER(xas, &mapping->i_pages, vmf->pgoff, order); void *entry; vm_fault_t ret; + struct page *page; xas_lock_irq(&xas); entry = 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 = pfn_t_to_page(pfn); + page_ref_inc(page); if (order == 0) - ret = vmf_insert_mixed_mkwrite(vmf->vma, vmf->address, pfn); + ret = dax_insert_pfn(vmf, pfn, true); #ifdef CONFIG_FS_DAX_PMD else if (order == PMD_ORDER) - ret = vmf_insert_pfn_pmd(vmf, pfn, FAULT_FLAG_WRITE); + ret = dax_insert_pfn_pmd(vmf, pfn, FAULT_FLAG_WRITE); #endif else ret = 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 = fs->window_kaddr + offset; if (pfn) - *pfn = phys_to_pfn_t(fs->window_phys_addr + offset, - PFN_DEV | PFN_MAP); + *pfn = phys_to_pfn_t(fs->window_phys_addr + offset, 0); return nr_pages > max_nr_pages ? max_nr_pages : nr_pages; } 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) == 1, + int ret; + + ret = ___wait_var_event(page, !page_ref_count(page), TASK_INTERRUPTIBLE, 0, 0, cb(inode)); + + return ret; } #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 *vma); struct mmu_gather; struct inode; +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. */ -#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 <= 127u) @@ -1527,12 +1510,6 @@ static inline void put_page(struct page *page) { struct folio *folio = page_folio(page); - /* - * 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); } 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) -/* - * 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) != 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 *page, int refs) * belongs to this folio. */ if (unlikely(page_folio(page) != folio)) { - if (!put_devmap_managed_folio_refs(folio, refs)) - folio_put_refs(folio, refs); + folio_put_refs(folio, refs); goto retry; } @@ -111,8 +110,7 @@ static void gup_put_folio(struct folio *folio, int refs, unsigned int flags) refs *= GUP_PIN_COUNTING_BIAS; } - if (!put_devmap_managed_folio_refs(folio, refs)) - folio_put_refs(folio, refs); + folio_put_refs(folio, refs); } /** @@ -543,8 +541,7 @@ static struct folio *try_grab_folio_fast(struct page *page, 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; } 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_area_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; entry = pmd_to_swp_entry(old_pmd); folio = pfn_swap_entry_folio(entry); + } else if (is_huge_zero_pmd(old_pmd)) { + return; } else { page = pmd_page(old_pmd); folio = 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); } -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 = pud_offset(p4d, address); if (!pud_present(*pud)) return 0; - if (pud_devmap(*pud)) + if (pud_trans_huge(*pud)) return PUD_SHIFT; pmd = pmd_offset(pud, address); if (!pmd_present(*pmd)) return 0; - if (pmd_devmap(*pmd)) + if (pmd_trans_huge(*pmd)) return PMD_SHIFT; pte = pte_offset_map(pmd, address); if (!pte) return 0; ptent = ptep_get(pte); - if (pte_present(ptent) && pte_devmap(ptent)) + if (pte_present(ptent)) ret = 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 = NULL; return wp_pfn_shared(vmf); + } return wp_page_shared(vmf, folio); } 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); void free_zone_device_folio(struct folio *folio) { - if (WARN_ON_ONCE(!folio->pgmap->ops || - !folio->pgmap->ops->page_free)) + struct dev_pagemap *pgmap = folio->pgmap; + + if (WARN_ON_ONCE(!pgmap->ops)) + return; + + if (WARN_ON_ONCE(pgmap->type != MEMORY_DEVICE_FS_DAX && + !pgmap->ops->page_free)) return; mem_cgroup_uncharge(folio); @@ -486,24 +491,29 @@ void free_zone_device_folio(struct folio *folio) * to clear folio->mapping. */ folio->mapping = NULL; - folio->pgmap->ops->page_free(folio_page(folio, 0)); - 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; - 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; + 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 != 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) == 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 addr, unsigned long start = addr; ptl = pmd_trans_huge_lock(pmd, vma); + if (vma_is_dax(vma)) + ptl = 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 page *page, unsigned long pfn, } /* - * 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; - 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, unsigned int *refs) unlock_page_lruvec_irqrestore(lruvec, flags); lruvec = 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; From patchwork Tue Sep 10 04:14:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797876 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: 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-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|IA0PR12MB8088:EE_ X-MS-Office365-Filtering-Correlation-Id: 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: VF0zDR0YEdCFVbNXgyjvP3kMvy9g84qrOROG1Uwg/KgY1Jy3t/YPMevP5xAArNOWVH+GrCw4LBCWivomXMqMBJgWuxBbQv/ll749oCrwB8mxq/MwtRhpXt799UoBvX8kj7sFr1Ke0dLTmH/EkE55jYsa8dUbKsG3mGhQP7r7ucGVlAVZNn+HyMOod1emICZz7YPOjhJ8hKSwad4t6oxaa51lVoyl7rnDIjmDN/Aw0gxSxpflagk5rZuaskoGLMPG5DbJ6bKiQXdTadFrbGJuq3XItP4D2f7gF93s5+o3hyjSeLL/RyRFotEaKB8vBvGbCkXpkYfB+i0ODTDxWwlAWBaBxOg66/wgDRM3dbL4JDFSsKTARe7tgCKpd7cHyjKblIycQMNPH8GYDs72wgPpqelSD/B30/pmRJElEYSnUzWS/KPsoRIoTkilsTX3GT8QnXowo1JKLr1wxqnUawtYQcIeBUs5Nz/9EH0TjhS8Gx5hZbYc+/CQD99W73ivmOd3vR1IuiwRaQeztvri4FlFNwjYElCtcN2CokXFKoYQki5vYGPEdEPTTd9draZiE0S01EX6WuyUP+fVS/RPI64k1SiILRK21NrQGqy6sOVe2ca3CBEgDb+1j0aPxdDCc+EQRaXouzeTR+vrhQxJLNycWjaFvzerROmPXZkRQbOB4F3LFvXzNp/ZEEnqiz9o4eM6q/4Suded3/WohR3dhW/d5NDGh8Y4pv4mKY8ClDI6Je8xV4cYanUTVqOIhlk/XVyKHh4ZDfVKHCmk/gBIoqwjC1mQQV9pS32e9+VBoT8F3jP+rWdQbQy52svRIQrQSGSnGMu3CoDNds2RxeXGmSbkbqgkxhHDiKrp2YTYp5uGLTiXbcVaHUF0FhYCzjYb4bPaNm26UjXFJQSaSmJDbJNFIPD2kVO9SaChiguPdjH+ZJRL3GoGhGpR5/SozaovMv9qBh2DzJFNW90/tU+AksyLt18SWXxNr1BnOGWgcTKmaat+HdpG9AsQR/3p+rN6DQScmihyaqCw3k7DdeHxo7I9LXl7Z1QAO0a+9n4DCokX5xmEJiyFGeKBYPmRWw6CP+cY8pHUQuis6jTCDMkMV7IMqq0JdLVT+1c6Nil+Q0d+HSvUUdyLsw/4uuMPRTwdt3kFGeBOfXaerwe0Gz0ITNY1ICQ5Dc6UcI88kBiCy1s/Ejs83Bm1/9gis9pcpIJYNUYQWdogmxNd1Lus0XVh0I1IfilzIW2HOtfNWKL4zGelreMyIdhK/P3lvdjbR1yX4qTlcIM/w7HgKQXjYuQjNcO6+Vp2b8IVYyJ+KPqd7yCxYO0fZL7mbMVJFyVI4v0NBnvoXrjmr5bGvWIR7fUBOnDPyA== 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: 1torIMmdGwQwI/aeXvznobaTj8cDtQlLq3tundyFA67thyuzDgrmw9Z3VrG3fmAvqpI5+nEDUjKEKNEJB6F3xXm84qaZ10riTODnAIimhvdWvrmMjV/cf4G39Xk/PlGFErSxzTRKhrkIDSbxmBUNC6Cb/mCd4DlzRiLXNDa2kgsmmXlzDEoTM8uNfuaA/tNMAIbZQ1YWnEPS/+7QVpWg8TAiewnX6vRb/puJWw+bTSUn1JYfTbFG+4riwrxMJCGIJbhN2ikS/vxDzg6dgXwS6TQepSrTRwSue7Vd8AiRBpaFOrlJ0Ct7EXfVfw12PoU4GakSFpVLJ7djpI1f0vNrUzoO8SQnXWbi6IcXlwpFuzjcT09OSpx+cFqwBdZTI9dog94/r7EMCIlZGssxXIwL6LFkSpZQBnswq6drFi6EVf9RR/JqlH9w0LgpskxGMJFU5liijBZeOnT4m5SahpaBuVul2Lrl6f8RCgGD/nkCu5eZQkccvzTvbj23BCDhfoqr3BCP4qoPrVBNEUdaAx2rog9tpjfcHw5xRga+JNYJ5M7Fwd/QuXHnIpjuRpqgBEl0V8XIo5YTG5SICVCB/NQlC9GtRaFyFcyStU7T1smtDfSCvfSpSETqmHvI5LXZ38KzNiEegAJrV/GClLGhYBTq+KYHAWZouZ34xKT4usfHBfrbV45Q2inER0yKX5L6NQsbc7WAFBZyw0/PZFqKtfnsyj5zxFsxlZwgAMVo5j0ySouX5pvPxy8idZtbhRE4VSTAE9WhBqRonTkZRv2n4kC8fpRhyE9XOHOTFbYG3+gC7+zhrdlOSSH5gU8wYLgDpTn1yS+8UH2XCwgU3/goudQ6sKyQzZZkVADl3/vJiIztjYA/t3VgKE/Qpn/Pfoc/bCYVpNQXZrJDCMw22K1PRwOBfGlHJZ3qcCOkHCRHd1AqS/hGaWwXhxQTzIuyp7W2r5iHaGHA9n91NowOmVK69nTObKnwFkRvVsagOtZNGaCL/1IoLCCispQ8v8PgrbkAJxQBLTsP9C4cP0HCt67SlUssHcvVcppUt0mPCheOjULmtJhsU7IUj7DcyFkeVKJqbkiDkYYoFj0usk+nn0D7sD1Iq+qwD3cQhuRlewhBrAevATeZlGhjPrS3aTEDFrCIWxkywmTZ+8U9xOFuu8JoEbjaCOJOtPeiCBTCXuenhm2skRMGZEfPY19Sc3EO53SW11xlVP8kEgPJjrH/DYOGldMidglfHYfUsO61TTExH7Y6tH2xnVPuYzz1hP4KhJITzcnYU4yZtO44P1M7Y+DQ6IVwBW73FmyXSRPxPAi79ineXDquPcIJ0EfS6Ffi3q3XQyQEgjtIe9JI8eJ4aMCHTiZlR0pDsyjgy8+n5qutCyU9cLLgRbvvvHkOL7xRLWeZtxW0LGTy4MU+mCA0hHjBv/hCwxTsvKn/aO18GeORrE9U9RDtZjy81Z3PGSrurtjvnG8J51zkM6bjdsmTJE5UOLUfDEOEwq0u6QKWdMKh2QW+1d5kuZBLd2RqEx7zOoxqGC0J3ddFUOhkdtWZSEV8biyizqY651kRkjufqHyt9kfhcXeTGVZVnkWR7k4ATZeZDHuR 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 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/book3s64/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_struct *mm, unsigned long addr unsigned long old; #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 @@ -227,7 +227,6 @@ pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long addres VM_BUG_ON(address & ~HPAGE_PMD_MASK); VM_BUG_ON(pmd_trans_huge(*pmdp)); - VM_BUG_ON(pmd_devmap(*pmdp)); pmd = *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, unsigned 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 = !pmd_same(*(pmdp), entry); @@ -70,7 +70,6 @@ int pudp_set_access_flags(struct vm_area_struct *vma, unsigned long address, { int changed; #ifdef CONFIG_DEBUG_VM - WARN_ON(!pud_devmap(*pudp)); assert_spin_locked(pud_lockptr(vma->vm_mm, pudp)); #endif changed = !pud_same(*(pudp), entry); @@ -193,7 +192,7 @@ pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *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 = 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_struct *vma, pud_t pud; 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 = 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/book3s64/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_struct *mm, unsigned long add unsigned long old; #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 @@ -1441,7 +1441,7 @@ unsigned long radix__pud_hugepage_update(struct mm_struct *mm, unsigned long add unsigned long old; #ifdef CONFIG_DEBUG_VM - WARN_ON(!pud_devmap(*pudp)); + WARN_ON(!pud_trans_huge(*pudp)); assert_spin_locked(pud_lockptr(mm, pudp)); #endif @@ -1459,7 +1459,6 @@ pmd_t radix__pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long addre 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 - if (pmd_trans_huge(pmd) || pmd_devmap(pmd)) { + if (pmd_trans_huge(pmd)) { if (is_thp) *is_thp = true; ret_pte = (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 = 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 = 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 userfaultfd_ctx *ctx, goto out; ret = false; - if (!pmd_present(_pmd) || pmd_devmap(_pmd)) + if (!pmd_present(_pmd) || vma_is_dax(vmf->vma)) goto out; 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 = (__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 = (__pud); \ - if (pud_trans_huge(*____pud) \ - || pud_devmap(*____pud)) \ + if (pud_trans_huge(*____pud)) \ __split_huge_pud(__vma, __pud, __address); \ } while (0) @@ -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 *pmd, 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 = READ_ONCE(*pud); - 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_struct *vma, return NULL; pfn += (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 = get_dev_pagemap(pfn, ctx->pgmap); - if (!ctx->pgmap) - return ERR_PTR(-EFAULT); - } - page = pfn_to_page(pfn); - 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); ret = try_grab_folio(page_folio(page), 1, flags); @@ -839,8 +817,7 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, page = vm_normal_page(vma, address, pte); /* - * 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_struct *vma, goto out; } - 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 = get_dev_pagemap(pte_pfn(pte), *pgmap); - if (*pgmap) - page = 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 = ERR_PTR(-EFAULT); @@ -941,14 +907,6 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, return no_page_table(vma, flags, address); if (!pmd_present(pmdval)) return no_page_table(vma, flags, address); - if (pmd_devmap(pmdval)) { - ptl = pmd_lock(mm, pmd); - page = 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); @@ -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 = NULL; - int nr_start = *nr, ret = 0; + int ret = 0; pte_t *ptep, *ptem; ptem = ptep = 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; - if (pte_devmap(pte)) { - if (unlikely(flags & FOLL_LONGTERM)) - goto pte_unmap; - - pgmap = 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; 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 */ -#if defined(CONFIG_ARCH_HAS_PTE_DEVMAP) && defined(CONFIG_TRANSPARENT_HUGEPAGE) -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 = *nr; - struct dev_pagemap *pgmap = NULL; - - do { - struct folio *folio; - struct page *page = pfn_to_page(pfn); - - pgmap = get_dev_pagemap(pfn, pgmap); - if (unlikely(!pgmap)) { - gup_fast_undo_dev_pagemap(nr, nr_start, flags, pages); - break; - } - - folio = 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] = page; - (*nr)++; - pfn++; - } while (addr += PAGE_SIZE, addr != end); - - put_dev_pagemap(pgmap); - return addr == 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 = *nr; - - fault_pfn = 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) != 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 = *nr; - - fault_pfn = 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) != 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; - 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 = pmd_page(orig); refs = record_subpages(page, PMD_SIZE, addr, end, pages + *nr); @@ -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; - 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 = pud_page(orig); refs = record_subpages(page, PUD_SIZE, addr, end, pages + *nr); @@ -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; - BUILD_BUG_ON(pgd_devmap(orig)); - page = pgd_page(orig); refs = record_subpages(page, PGDIR_SIZE, addr, end, pages + *nr); 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, unsigned 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); } - 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 = pmdp_get_lockless(pmdp); - if (!pmd_devmap(pmd) && !pmd_trans_huge(pmd)) + if (!pmd_trans_huge(pmd)) goto again; 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); } - 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, } entry = pmd_mkhuge(pfn_t_pmd(pfn, prot)); - if (pfn_t_devmap(pfn)) - entry = pmd_mkdevmap(entry); if (write) { entry = pmd_mkyoung(pmd_mkdirty(entry)); entry = maybe_pmd_mkwrite(entry, vma); @@ -1294,8 +1292,6 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, pfn_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)) == (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, } entry = pud_mkhuge(pfn_t_pud(pfn, prot)); - if (pfn_t_devmap(pfn)) - entry = pud_mkdevmap(entry); if (write) { entry = pud_mkyoung(pud_mkdirty(entry)); entry = maybe_pud_mkwrite(entry, vma); @@ -1421,8 +1415,6 @@ vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, pfn_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)) == (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); } -struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long addr, - pmd_t *pmd, int flags, struct dev_pagemap **pgmap) -{ - unsigned long pfn = pmd_pfn(*pmd); - struct mm_struct *mm = 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 += (addr & ~PMD_MASK) >> PAGE_SHIFT; - *pgmap = get_dev_pagemap(pfn, *pgmap); - if (!*pgmap) - return ERR_PTR(-EFAULT); - page = pfn_to_page(pfn); - ret = try_grab_folio(page_folio(page), 1, flags); - if (ret) - page = 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, ret = -EAGAIN; pud = *src_pud; - if (unlikely(!pud_trans_huge(pud) && !pud_devmap(pud))) + if (unlikely(!pud_trans_huge(pud))) goto out_unlock; /* @@ -2473,8 +2425,7 @@ spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma) { spinlock_t *ptl; ptl = 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; ptl = 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_struct *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)); count_vm_event(THP_SPLIT_PUD); @@ -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 = 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); @@ -2648,8 +2599,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *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)); count_vm_event(THP_SPLIT_PMD); @@ -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 != 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 = pmdp_get_lockless(pmd); /* 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 = ACTION_CONTINUE; } @@ -152,7 +152,7 @@ static int wp_clean_pud_entry(pud_t *pud, unsigned long addr, unsigned long end, pud_t pudval = READ_ONCE(*pud); /* 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 = 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; 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, } } - 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 = pmd_offset(src_pud, addr); do { next = 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 != HPAGE_PMD_SIZE, src_vma); err = 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 = pud_offset(src_p4d, addr); do { next = pud_addr_end(addr, end); - if (pud_trans_huge(*src_pud) || pud_devmap(*src_pud)) { + if (pud_trans_huge(*src_pud)) { int err; VM_BUG_ON_VMA(next-addr != HPAGE_PUD_SIZE, src_vma); @@ -1710,7 +1697,7 @@ static inline unsigned long zap_pmd_range(struct mmu_gather *tlb, pmd = pmd_offset(pud, addr); do { next = 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 != 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 = pud_offset(p4d, addr); do { next = pud_addr_end(addr, end); - if (pud_trans_huge(*pud) || pud_devmap(*pud)) { + if (pud_trans_huge(*pud)) { if (next - addr != 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, } /* Ok, finally just insert the thing.. */ - if (pfn_t_devmap(pfn)) - entry = pte_mkdevmap(pfn_t_pte(pfn, prot)); - else - entry = pte_mkspecial(pfn_t_pte(pfn, prot)); + entry = pte_mkspecial(pfn_t_pte(pfn, prot)); if (mkwrite) { entry = pte_mkyoung(entry); @@ -2489,8 +2473,6 @@ static bool vm_mixed_ok(struct vm_area_struct *vma, pfn_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_struct *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; /* @@ -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; - WARN_ON_ONCE(pfn_t_devmap(pfn_t)); - if (WARN_ON(is_zero_pfn(pfn) && write)) return VM_FAULT_SIGBUS; @@ -5678,7 +5657,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, pud_t orig_pud = *vmf.pud; barrier(); - if (pud_trans_huge(orig_pud) || pud_devmap(orig_pud)) { + if (pud_trans_huge(orig_pud)) { /* * TODO once we support anonymous PUDs: NUMA case and @@ -5719,7 +5698,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *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); 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 = 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; _pmd = 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 != 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 *vma, new_pud = 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 == 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 *vma, 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 == 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 = pmdp_get_lockless(pvmw->pmd); - 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 = pmd_lock(mm, pvmw->pmd); pmde = *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 = pudp; fw->pud = pud; - 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 = pud_page(pud); + + if (is_device_dax_page(page)) { + spin_unlock(ptl); + goto not_found; + } + goto found; } 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 = 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; 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 = 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 = 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, unsigned long dst_start, ptl = 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 = -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; - if (WARN_ON_ONCE(pte_devmap(pte) || pte_special(pte))) + if (WARN_ON_ONCE(pte_special(pte))) return -1; 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; - if (WARN_ON_ONCE(pmd_devmap(pmd))) - return -1; - if (WARN_ON_ONCE(!pfn_valid(pfn))) return -1; From patchwork Tue Sep 10 04:14:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13797877 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: 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-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|IA0PR12MB8088:EE_ X-MS-Office365-Filtering-Correlation-Id: 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: ZqPB41i3tzHAG1VS1zvrugREewOLjXViHvSBJKybH87fMG0KwqMdPNdjOpB8in/Vgl/9ImRr601MH+nGEnKL0a9XP+I/Dyq9Pp/cN2xhGuNFSp4cjHsVfYCvcJ4tLGmoyiq1/Biy64byebisD04x5AFd0gQn+CgKglbObcAjmWYlYYjuY6OgQI+WrcUbJIML0H+p0h6TvEgZOLs37JME0e1MnGeKvtuGWTiX5Mn16nJMoYQCS7Thj1CGgJcm6CMFQUNkcQxYnfl9V7CjXo32pnNv8jTHMK9YZ77heIfLbB6foa1V2rXcnclq5YMTd5UANTmP+RVEJQ90y9UFc0r5ZKAIA0tuikbaRwN7dxPU05BD2mAZoUXtyGXAO3s4dQk2CJbW1anjP686T1R3AWDPUZKwYHowAOJz3ILBl2qDP1VouWEGV9GKW18FQajlCLn5kWQ64OHEd+mgGWwlnpLi3grqIjRznc3BbG0zEPvQUn6wb5UaK6VF8vdaJ5kQRSMEd2rj2ZRgisri81cIBhuSmynxzd3E2Nknl0gwKZF0LrI6LqeaeWdYYOpV7K2lYKqjH2b/UNdnLRCly2wQ4I6BX2MomkQWRI3/MUFTy60Ih2UhTFz2SyfVf7V+uFTi3V1y8NkASlM1AjavZEiWOdpMj7emK1RVIh67WQ8wz6Otni1eS1jYC5To2fpxd0kKGDAtLm0eUFgWKVFEetsfb0N6ZGhoQSSqDzQK7BmxXx2GJ0QnxcWssen/xWtzyWe7XGVaM+0OoJLLJdmsRUsAJwXTiAqCy7FcS6LNKq4RvggqDhCML2ES78wIX1GIEWMtjnxbKhXNuHoioeCUvX7EFpLRmQJ9awLMQyrvyt78QrfEd4Ho46fCtt0KTOjEE/qZl19yiZwCqkFKAmUgeGJsetafmR6Uf/Z5kSjAeiB7iuDGkCyz+cjoNUWwYXLms4LRUTnJV81rqLOidp/vjRG9elFL8PGF/0QhabXrkgisWr3lZfSNWuZg3f6roLPFMfPSSQNtOh3tA/BEGQhQ6rufJ22m36ikM3tVblGLnSlvDmuXJDNSR6Gi1qIGsCxV4c2BGW1svlvpUBbHTsR4YdbWRvtUqCRz/SRZYDOJMdQZSdLDFznNeFZd+ZQ1eRhmpTY8w//ImiN1JaVewwG7pMZP0Q75IsrqyRtWWhfJedhJkQXZ9mv+Dxl5xiPunDOCqvKIn9D0YKMEiaS3h6muDrV4vwu/p2P1Pj2VJbt38ZQxSqwe74eTweP5eGISHN2m324MVnSdN7bFByMutJ8NP5xnaxYbgopdOx/uhlD8RJoSiQtyYYXM1yNhgiDl8OaG5sThJLWUXw7DhFMUQIbK69TXPzd+1w== 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: lreiPlExgUqJova0xZzIYi/s1jgXyKsl70n1XU74JC2x1zwA4XVK2PLZofnVb87EWpZebQb+9sBitZvKhAbt6ACE6iX77X2NQ8phjCe4R55+RaECVNrQiDSDDeWNjLRrMavDnR6I77RoFB8vmmK4WEg17QYiFgrSFjC54AbIceoOLCnB23PRjYkMQyYciZKz/fHkvyGcvZfKiFei77UoxRduKFFJ00TdFJh3W2266qFwLWnic4/icHo0kkxSiDntIPE35NoL7ZGHHXDG0hf/fGH6Q2TnDMIW1sLMQtoFF0qLrozhwuI+bLnn7cnjdiBeaHjSWA5Ly2U3E7qnnZZ9nygr9HGZzU2gKSlNBPJq7HEUdfEYvKFpDlr3Gu2d0Fpxf54UtUc8ZrLmDvPIXv8Vsla6Eha79lwtK/7nL4F3EDTIS4J+syvPXjA5kAL9zCI4Gv7Oc0srKnStKt70Zbm5ZCg2rwJ/dGMLxGO2YIqYEMafP65ueG62rz46f5ScsDJynrv1KEG1teDPaNkbso+/VdMIF6Z2O5XU25OxWD4FejcSP0ZtUFolJtvRYNp9WGZkHTYSzAy3877W7xbR6FOSE6OVDGXarlITXksWkG3nmTptZmqsWkJZ9vHSMCNmOtWFaCdFMYjz2CAWQe+8yHujybb3uWWTZVXekNhUBhe8zQ7bbOL/3ZKjlYn8e3s7y374GZX5Zah1QhimA7tqPcQh064n2DU/CzwCJFiCqnoo7fXE29srKxWj6XbztMeCPaR6EiMchPiXivf6ewAIX8emsVC4q8W2drGibMg61Z+hMfYuvrv3B9DIUVr03DT6X5BqZwmexd18yty8gzcrF3YBwQavzpnHq1t2pu0Sk+VSg7UJqp6i3qwx10xA6GnYz/JKk1rnK+mOqx9/OerqrGf/oz2g39SdjpzKxWlkTHvgaTsS49avEaF12ODT/JwOO2lHiptLX/qSZuSca6UKABWMkrmxLYKMD2t9iv6uzPjyAqqAIgNDV0gsbOCc92ne1EWxu559fFxqbewmdTnnhBgDRymM16fkisPEpFg7xsokgCwh56SW/pCRx7Tr25W0+QmScD4fyEnv9c4CmsyMwfMM1DanbNWmxamDlN3dhG48zWzww0WqVhWla+UlGanFqvhoFooqj+OwxggmQhXubZdXhCXKHkNp4D7Hn++gEbIP5t17jdbFv1FNh/ZmGw99t6v1lYxtsPgIEIjMvKPh3IlWpzuu4ajH8E9RMPRVtHbEMj5xi61sdz1OuHBNt7d9sBaJMmtRI82XMuezaTDHx5uL1Cr08ULg4XvljM+QmHbf+0qT1TCZUWVJPF099W4rhLr9f5IQgwNkbWqTolFSA1flXpTkDpuVGfdjSZfdfefyC66qv3/xUvWF2m4KXW5ZCmINSvwEdOOqQ6yS6HqiajZyv1v79kN3wsF0pNUOpfuS2qqnUP7+pVlXKAYUUfKdZcH+NQB/KNYbswimaK0gQwUjbNMGhnLULLvOkBdLzlZyHlrcnqIa8OTVfI1W3e0mNiQdHYrtzddKXayi38k7Jz0gEde/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 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/arch_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) /* * PTE_PRESENT_INVALID=1 & PTE_VALID=0 indicates that the pte's fields should be diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.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 phys) #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) == \ PTE_ATTRINDX(MT_NORMAL_TAGGED)) @@ -269,11 +268,6 @@ static inline pmd_t pmd_mkcont(pmd_t pmd) return __pmd(pmd_val(pmd) | PMD_SECT_CONT); } -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) #define pmd_mkhuge(pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT)) -#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_area_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 #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_BOOK3S_64 select ARCH_HAS_SET_MEMORY diff --git a/arch/powerpc/include/asm/book3s/64/hash-4k.h b/arch/powerpc/include/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_struct *mm, extern int hash__has_transparent_hugepage(void); #endif -static inline pmd_t hash__pmd_mkdevmap(pmd_t pmd) -{ - BUG(); - return pmd; -} - #endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */ diff --git a/arch/powerpc/include/asm/book3s/64/hash-64k.h b/arch/powerpc/include/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)) == + return !!((pmd_val(pmd) & (_PAGE_PTE | H_PAGE_THP_HUGE)) == (_PAGE_PTE | H_PAGE_THP_HUGE)); } @@ -281,11 +281,6 @@ extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *mm, extern int hash__has_transparent_hugepage(void); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -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__ */ #endif /* _ASM_POWERPC_BOOK3S_64_HASH_64K_H */ diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/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 @@ #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 */ /* * 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) /* * 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; } -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 software - * use in page directory entries (ie. non-ptes). - */ -static inline int pte_devmap(pte_t pte) -{ - __be64 mask = cpu_to_be64(_PAGE_DEVMAP | _PAGE_PTE); - - return (pte_raw(pte) & mask) == 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); - -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 */ diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/include/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) static inline int radix__pmd_trans_huge(pmd_t pmd) { - return (pmd_val(pmd) & (_PAGE_PTE | _PAGE_DEVMAP)) == _PAGE_PTE; + return (pmd_val(pmd) & _PAGE_PTE) == _PAGE_PTE; } static inline pmd_t radix__pmd_mkhuge(pmd_t pmd) @@ -274,7 +274,7 @@ static inline pmd_t radix__pmd_mkhuge(pmd_t pmd) static inline int radix__pud_trans_huge(pud_t pud) { - return (pud_val(pud) & (_PAGE_PTE | _PAGE_DEVMAP)) == _PAGE_PTE; + return (pud_val(pud) & _PAGE_PTE) == _PAGE_PTE; } static inline pud_t radix__pud_mkhuge(pud_t pud) @@ -315,16 +315,6 @@ static inline int radix__has_transparent_pud_hugepage(void) } #endif -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) } #ifdef CONFIG_TRANSPARENT_HUGEPAGE -/* NOTE: when predicate huge page, consider also pmd_devmap, or use pmd_leaf */ static inline int pmd_trans_huge(pmd_t pmd) { - return (pmd_val(pmd) & (_PAGE_PSE|_PAGE_DEVMAP)) == _PAGE_PSE; + return (pmd_val(pmd) & _PAGE_PSE) == _PAGE_PSE; } #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD static inline int pud_trans_huge(pud_t pud) { - return (pud_val(pud) & (_PAGE_PSE|_PAGE_DEVMAP)) == _PAGE_PSE; + return (pud_val(pud) & _PAGE_PSE) == _PAGE_PSE; } #endif @@ -299,29 +298,6 @@ static inline int has_transparent_hugepage(void) return boot_cpu_has(X86_FEATURE_PSE); } -#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 */ 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); } -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 = 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); } -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); } -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); } -#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP -static inline int pte_devmap(pte_t a) -{ - return (pte_flags(a) & _PAGE_DEVMAP) == _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/pgtable_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 #ifdef CONFIG_X86_64 #define _PAGE_BIT_SAVED_DIRTY _PAGE_BIT_SOFTW5 /* Saved Dirty bit */ @@ -117,11 +116,9 @@ #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 @@ -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_LARGE) 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 -#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 addr, 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 -#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP -static inline bool pfn_t_devmap(pfn_t pfn) -{ - const u64 flags = PFN_DEV|PFN_MAP; - - return (pfn.val & flags) == 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 */ -#if !defined(CONFIG_ARCH_HAS_PTE_DEVMAP) || !defined(CONFIG_TRANSPARENT_HUGEPAGE) -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. -config ARCH_HAS_PTE_DEVMAP - bool - config ARCH_HAS_ZONE_DMA_SET bool @@ -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 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_debug_args *args) vaddr &= HPAGE_PUD_MASK; pud = 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 = 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_debug_args *args) WARN_ON(!pud_none(pud)); #endif /* __PAGETABLE_PMD_FOLDED */ pud = pfn_pud(args->pud_pfn, args->page_prot); - pud = pud_mkdevmap(pud); pud = pud_wrprotect(pud); pud = pud_mkclean(pud); set_pud_at(args->mm, vaddr, args->pudp, pud); @@ -384,7 +377,6 @@ static void __init pud_advanced_tests(struct pgtable_debug_args *args) #endif /* __PAGETABLE_PMD_FOLDED */ pud = pfn_pud(args->pud_pfn, args->page_prot); - pud = pud_mkdevmap(pud); pud = 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_debug_args *args) static void __init pmd_protnone_tests(struct pgtable_debug_args *args) { } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ -#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP -static void __init pte_devmap_tests(struct pgtable_debug_args *args) -{ - pte_t pte = 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 = 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 = 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 = 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); - 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; } -#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) {