From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.48.22 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796076912; b=eTbMbu+KIIbl6mJIHbkbWO3TmdsqtgCA1tz8jBKeQh6Vgdu2Yp0UUjX+8QTicsEcTOgD frpmjNFQLm17piE1qxyPoNkasHf+PsbM0EKp/muS9EKC2zlR6WX8KufHlI8xnFfNPpPfB sP6/v4EQPwcMrQh4HD0bLYoqyf1jQMfQFYoK8A8xy4dfWqYHxwblQjKyjEGc+YMijLjx2 MMnnQFBEPNqZaKV2i/Q6hdmwIqrNOVMKxGfqOkpjguKQX2WI7uByGfeGJUA+N5fU/2n2S nI6GnHeKJNPC6uwQZmdc3wFYc2YrhZrXn4k8RMcDiWDbr8fD4eI1XvOqnZo61nKOdog== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796076912; h=DMARC-Filter:DKIM-Signature:Received:Received:From:To:Cc:Subject: Date:X-Mailer:Message-ID:In-Reply-To:References:Content-Type: Content-Transfer-Encoding:X-MS-Reactions:X-ClientProxiedBy: MIME-Version:X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=NE4JYIKvCaI9xhCtlkl0ebIWRqXBTbL2BXpjijhP6N8=; b=DWu3R6lAV6hyyNQJeUNiMNID+nUFXfjz6w00FTPYfjUunBvNFPvgW69UAxJ7Ckk2OzQT CuLCMofeG1MxPEagehskj8JHsGlXBh24Npt2Wv2U0DNFFzNQubq7Z2UO+ks8i1fm7O8Zg lI3Qc8aF5fmhRlo98GcB+pyyyGiT/IKHm+miy5Od5XmaT1AlLWhVJSYFRsU5LMOlug9bS Hgf8gTxh8xBOEPqSZPXvx7k7OtkeA1kosQRuCSc/y2ZlWsf2ggqhzGRL3kOleXPdwfW/a HW1p+MgTRqheCKuJ8bXmMzmJwfqIHI2tig4ymSXN1e7yyZY257BB8WSItBlRRSktubQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=tqnCIyU+; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.48.22 Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012022.outbound.protection.outlook.com [52.101.48.22]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92167606A31A; Mon, 30 Nov 2026 22:15:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 92167606A31A 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, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=tqnCIyU+ ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sL2vJOSJ1MXEQ7sd/wqocpORez3b58qF69X5IFfYv/Tjfwg45TsUZZ7nk0zxCQZn86iwtbiYnksOZlzoyvW6A2+eOVhonnbpymz6GmuEo2RRv+Yqum51dVkXceAAmqDsk75jbgHOzd7+IfJuQtZrznK+uCGlxf0SXV+UmgQGtECAhvId8AXHAIKlGD+2LeHyC0NsNCo+tQHMGopuBCjWEKXbg3kps+9EUXU9VDLvQFC8gdp3f20n11iom2U91AO+8tBPRgTudlECCnxPKFLUHV+q+t9UFXB8qfIiVgXqM78DMsx4C6I0tAHFjpBYRlglc6eRW8Fs67lnvXo0ljBHuw== 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=NE4JYIKvCaI9xhCtlkl0ebIWRqXBTbL2BXpjijhP6N8=; b=hpHPySXqQmQUqSvO+iuW0kCWFzYsv1TeDLj6yE5NdErnDM43hqkOh89ONlW52MBOW8TzT5NRFn/UVnUiIjhVPFLU3JxlB1g/3H/oGvKRftDKhVAHdfWnK57mIuPV7WdDPX70PXjnV5Aj2G2EKfgAVRSw55EwqdGvZtMqtxJ7gBOWtCiaZMO0xePKz5Gpa5Pso94CptDEUA75JncGVnzG8gEOYxsxaAKgdtNDjhgg+1edFLE1eDugj4Goza8Qn+6oeeh8mqYD93XD845DavY7hEXCN2TMo2+fnAWIdTAba6rmoHesWNoAUfUapvvzYZt/E7a4Za46QhkCwtJCYWSPJQ== 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=NE4JYIKvCaI9xhCtlkl0ebIWRqXBTbL2BXpjijhP6N8=; b=tqnCIyU+t9AZYP1tJbpRG8Hon0QZbZadsXtqjs2B+pYWwx9/J9+YMwkOa0oiw6q0KPaT962GRcI1LHIay6RborNwfsckVoa7WJ7LVbzqNVse97Q/FDzcoggCrOWLZs7hSSzbbzMrmBLui+enYVMdUDfu7EoxdjPrUmoHjmKf97SzTxYt1g51UyFDFIwoaFeurfw7CEvszxqIK4P50qZk+qOqiYc3O4UBBopyd7hTe7e8D35BMLA8MfQ46LSRw19mkndGQthwacqSwdeIoyxkEpml2BRaxu1JoulKfELh+fc4MHE+uX4at+Sv+2doU9/8jcjPMOY8EuoUhMmdd9OSgg== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from IA0PR12MB8374.namprd12.prod.outlook.com (2603:10b6:208:40e::7) by IA4PR12MB9785.namprd12.prod.outlook.com (2603:10b6:208:55b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Mon, 30 Nov 2026 22:15:07 +0000 Received: from IA0PR12MB8374.namprd12.prod.outlook.com ([fe80::d85f:4c87:ae84:3f16]) by IA0PR12MB8374.namprd12.prod.outlook.com ([fe80::d85f:4c87:ae84:3f16%6]) with mapi id 15.21.0662.012; Mon, 30 Nov 2026 22:15:07 +0000 From: Zi Yan To: Andreas Hindborg , Matthew Wilcox , David Hildenbrand Cc: Andrew Morton , Vlastimil Babka , Lorenzo Stoakes , "Liam R. Howlett" , Uladzislau Rezki , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Mike Rapoport , Joshua Hahn , Rakie Kim , Gregory Price , Ying Huang , Danilo Krummrich , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= , Greg Kroah-Hartman , =?utf-8?b?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Christian Brauner , Carlos Llamas , Igor B , Vitaly Wool , linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v22 0/6] rust: page: add page kinds Date: Mon, 30 Nov 2026 17:15:04 -0500 X-Mailer: MailMate (3.0r7038) Message-ID: <513DF0BA-DC37-4A90-ADD7-9FCCCFC00623@nvidia.com> In-Reply-To: <874id3vqd4.fsf@t14s.mail-host-address-is-not-set> References: <20261118-page-ownable-v22-0-d63ff73f4075@kernel.org> <37B6D4A8-288E-40E8-9214-EDABBFE49C39@nvidia.com> <871p8iue5y.fsf@t14s.mail-host-address-is-not-set> <3C3421E5-5B7D-42B8-ABD2-185375693D7A@nvidia.com> <87se0vu2ul.fsf@t14s.mail-host-address-is-not-set> <874id3vqd4.fsf@t14s.mail-host-address-is-not-set> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-MS-Reactions: disallow X-ClientProxiedBy: MN0PR05CA0027.namprd05.prod.outlook.com (2603:10b6:208:52c::24) To IA0PR12MB8374.namprd12.prod.outlook.com (2603:10b6:208:40e::7) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA0PR12MB8374:EE_|IA4PR12MB9785:EE_ X-MS-Office365-Filtering-Correlation-Id: f304de68-b0f7-4a4d-c256-08df4f2f642a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016|23010399003|11063799006|5023799004|4143699003|6133799003|261009223027099003|22082099003|18002099003|10067099003|56012099006|261102123227099003|261026121527099003|261026130827099003|261026140227099003|261021135927099003|261021121427099003|261021130227099003|261028144727099003|261021123027099003|261022075727099003|261022113327099003|261022115727099003|261022105027099003; X-Microsoft-Antispam-Message-Info: ezK/Qije/xl4YYwRE+jR3FztenmM/k+MAQNyY4m38Zhbpzb5viyhmF4rcIKltAGAN6DYVweZ4Pyfh5iV0w3S4JDw3avOI3nPBcz+JJhGokT1AGpkxufyAqFMSmMtxkmuv3g+GfVgrlLozVgxh9EoipSzxcpV+VrF6OG68tV4n1EXTGfh54l7getzlTh5ntLQbDK4ZbvvRcu3TuBz00s8kbOzZbUJMVettWtbcQhxaNnbFjx3vZUJqKKw0LbQJrnYjEXXxHTvvJC+0WxmsG+vTE02/J9NKH0r6J/hqwqWDwkjppH3XNSTJFsdLF0Hc6FIYFfpZOunval6sHazFORKBzy4o8Rvr/VMP4mQ1oQO8vHUoP1GWB9LrJIu9cdK8h6ZajkDBpiWGLJivUiB3NbdPbgt3wKKHJupPF66B/MFJ2+05C/TJzaFxHZahLIiqERUyWY3IWEp90XPUGSfZYe00npzvrUWY0n/VRIVFyr4/xFRS35vcBXwxRxSY/BGsycYxDLfKdY6l1f9ChX2f/C+iMa1ylIJwGv9p0y7I+95oYV/VBJW3DdH5+K6AVYhCRuNqwfC4LJtIHyrbXOAtOz4ks2idgwet1RXSO2DdzqXatZC06dbO/7u3DHQU3mS/Bmj+hOFSNfLSgzQFO3kAt0xs/AnqbtQNAz2Ukyx3ZZdh9c= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:IA0PR12MB8374.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016)(23010399003)(11063799006)(5023799004)(4143699003)(6133799003)(261009223027099003)(22082099003)(18002099003)(10067099003)(56012099006)(261102123227099003)(261026121527099003)(261026130827099003)(261026140227099003)(261021135927099003)(261021121427099003)(261021130227099003)(261028144727099003)(261021123027099003)(261022075727099003)(261022113327099003)(261022115727099003)(261022105027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?V0VhUUQ2ZkluSlpwS2NQNEdCL3FVU1pOZDJOK05wYWQ3d3dJTGN4N0Y1Tk84?= =?utf-8?B?TjlaeW5laHNpSHdlcGdFV01Xc2NBeU5yTEUrOWlLbWJtUU5pZ0JBZ2hnSC9a?= =?utf-8?B?K2hSN0dFK1ZYaVFSS0JpTnNJQ2dBdDN4WEc1cE94NjFwNXZ5RmhDUVlFZmFr?= =?utf-8?B?RG50aGJmdGdZVnRFVS9rR0tBSFdRdHNVU0J5Q29iQm1YdzdnaWxNc0dWakUz?= =?utf-8?B?dEhJYmc3NElvalNEUTR1RldwT29VL0VPOEMzbTYxMVJHaTJRcmVqbTNxbks2?= =?utf-8?B?cTN4V1BLNGhLS2phbTdxRFc2OFNiYkt3b243WjZsOUpaZGFpaCtvQ05PK09C?= =?utf-8?B?M2hGQ2xxcXUvVUl0NVJ6WjNCQ0xoVnRiYmM5Y2FRMzZnZzg0WEhQQUVZdTh1?= =?utf-8?B?TldvdjNyMllzSFBFWERScUtKWWR2SEQ4cWh0TzVPSWo1UlBGN05WaTNvQTVy?= =?utf-8?B?UGkzWkx4bXhSdTVNWVBjQjVBZWdob1d5ZGtZVnAySUw2S0JlQ1ZxNFdlKzgx?= =?utf-8?B?bHBkWm1MSnhGWjZibW1WMElwNWJ0d3FsMTZIZTNOZlMzUG8xWFpkM2pVcXhW?= =?utf-8?B?bjlZalEybzlMR0t3NDZaR1p1QTkwNWRiVzN0Y0loZ2RWSCsyckF3bzBtbk9K?= =?utf-8?B?OWM1NXUxaG95dmlMbXVxWmpzcm1qNDZ0SVZuWmpsWjczTzMrL09MK3lyR3hU?= =?utf-8?B?cUlGVnJIMEZBdnRSZVpJMzVic2x2emVhQ0ZzQThSZlpmNUpySUY2enFOY0Za?= =?utf-8?B?YVhpM3BQWFZ4YXNWNmNrOGJuaEp3WkNJZjhXL1ZvRTBGcFBuVDNQdzdJSUs5?= =?utf-8?B?aXBVVm0vSTRydWJGcVlWS083V0o2QkVPdW1nMHFzRWtOaENvVmZpQk5ObVY4?= =?utf-8?B?UFBQTTN1SDg2ek1zQm4zNWQyamV5WVBHanowQ1pIaFBRMnp2dnpTMEVmb1JJ?= =?utf-8?B?ZGF0MndoREQ3aHFJbkJOZEcvOUFWcE9tNHhkRG5kcndxb01ieVlma1FNS2lQ?= =?utf-8?B?aTRraG9qUk9PYys2OFdUZU1RdnRKbXpIWkxYRUc0L2xyTFBGMkdnWEpIekht?= =?utf-8?B?ZjNXdTVQWHZzQmhzNXlnaVpJNEk4OHpsOVBrODhyclo2TWRDdDVmWVpPdHF0?= =?utf-8?B?Y2o1aVZDWnE1bjZaVDNyKzl3cmJMcVA3MjM1OExoL3N2Z1JMcC9uRHQvSGhI?= =?utf-8?B?Nk1zL281Z2wraDdrOVhzSWZHN1ZWWHVkSGRRSkNLUXk3V0xqQWUrMk9obXBw?= =?utf-8?B?Z1JWMTNub0ZCUnZHa2xEMytKb0VGVGpNMC9FMW0rZzNIN1RNa3grQ3k3YWg2?= =?utf-8?B?L1N5R2tiSkdEcEpyb2ZTTzRrakFUdmkxZWxFc003akNwNXV1K3EwOWw0RXo3?= =?utf-8?B?bHpjMzREd0xpei81TTNLVW03ZXdyU2QrVUsrc3RmWVQvUTl2Tmk5TXJJT3gr?= =?utf-8?B?UGhEYmY2c05saC8za2hNbnhJaGQyT0ZJTjM0TlNUWjROdTZ6TldveWQ1OGdl?= =?utf-8?B?RURaRTZHUndDUVFKeUQ4NU84WlJldC9mSC93WGh1L1FQMTdvQzI0ZFlyQ3Vn?= =?utf-8?B?V21kcjN0UTFGMDVoaStIengwci9rNmZLdzRxeDFEQi8xUHEvZnRmOTZsTXRV?= =?utf-8?B?bUxLL1J0L1RwQTUvWWpINFBtb3pQdEVFY0liRkJlK2p2Y0RrdzFpeWdlandX?= =?utf-8?B?THZwdFlnYjI2UmpaU0FBS1E5QlZoNjU2b3B6OG04UWV3L2N4TlJrSDE0eUc0?= =?utf-8?B?RnM4aDJPV21sa1J5OGpHYkZQRFo2cXdJekRpc3dpVEpPZkduVHd1VDBDaExB?= =?utf-8?B?c1ArY3BEZTI1Q2ZGdi9RZ1A0MFVLRUxCM0JQNzBjSzFqaU44bXhsUkhwOU1t?= =?utf-8?B?WFNSa3Y5c3ZxenF6WkZCazlEZXpaQVZWWWxHSit2eVVadUM2YVp0Q0dtdDBW?= =?utf-8?B?RmpxdmpWMXlhRlRrYlB4d0EzQVV4VUE4NTc3WjN0K3FycVlLaDRpQ3RmRHN4?= =?utf-8?B?dlRtQ2ZKRW0zRXpyVktrUDJFWE1VUGNiUzNocEI1Y3hnODZybFltMk9kVnho?= =?utf-8?B?UXQvVzR2L2NjQWVCTHdCR1BJdytMOElldzl6NzVOdzNzU25ldjUvUnA0dUxi?= =?utf-8?B?MXpaZGZrVE1KYkFYaG9SQklqRTdBWC9HVGFvTWt5MFh5OVhvQklZaHVNSVRZ?= =?utf-8?B?RFkxV3ZLeTZSQWRaNGprR0d1ZnVEaVFSSFU4THNKaXRNeGE0K0JFcHYzbk9T?= =?utf-8?B?bS9hZ3U2NEdmeFFOR29mc0xUWGtXd1c4Yk85eVhTM21YNFFZbU11dlNRYjg2?= =?utf-8?Q?KQqcBckZKXFBlVlemf?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f304de68-b0f7-4a4d-c256-08df4f2f642a X-MS-Exchange-CrossTenant-AuthSource: IA0PR12MB8374.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 22:15:07.3662 (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: q3Q/DEpbOvuywuQXR0+a2tZxGH6miXh/PzB6X0Y+KvbM0DFBwnL0hs6f0srqVIIn X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR12MB9785 On 26 Nov 2026, at 5:28, Andreas Hindborg wrote: > Zi Yan writes: > >> On 20 Nov 2026, at 7:03, Andreas Hindborg wrote: >> >>> Zi Yan writes: >>> >>>> On 18 Nov 2026, at 14:34, Andreas Hindborg wrote: >>>> >>>>> Zi Yan writes: >>>>> >>>>>> On 18 Nov 2026, at 11:18, Andreas Hindborg wrote: >>>>>> >>>>>>> Note: The page patches were part of the `Ownable` series [1] until = v21. >>>>>>> This series continues the version numbering of that series, and it = depends >>>>>>> on v22 of that series for `Ownable`, `Owned` and the split of `RefC= ounted` >>>>>>> and `AlwaysRefCounted`. >>>>>>> >>>>>>> Not all pages can be treated the same way. A page allocated with >>>>>>> `alloc_pages()` is managed by the page reference count, and kernel = C code >>>>>>> routinely takes its own references to such a page. A page owned by = the >>>>>>> slab allocator must not have references taken to it, but it can sti= ll >>>>>>> show up in places such as a bio vector. A frozen page has a referen= ce >>>>>>> count of zero and is exclusively owned by the party that allocated = it. >>>>>>> >>>>>>> A single `Page` type cannot describe all of these. This series make= s >>>>>>> `Page` generic over a sealed `PageKind` that describes what is know= n about >>>>>>> the page: >>>>>>> >>>>>>> - `Page` is the base kind. Nothing is known about the page >>>>>>> beyond the validity of the `struct page`. >>>>>>> - `Page` is the default kind. The page is managed by t= he >>>>>>> page reference count, and `Page` implements >>>>>>> `AlwaysRefCounted`. >>>>>>> - `Page` is a uniquely owned frozen page whose data are= a >>>>>>> follows standard Rust aliasing rules, so the data is available a= s >>>>>>> `&[u8]` and `&mut [u8]`. It is handled through >>>>>>> `Owned>` and is the first in-tree user of `Owned= `. >>>>>>> - `Page` is a frozen page whose allocation is uniquely own= ed. >>>>>>> Unlike for `Page`, nothing is known about who accesse= s the >>>>>>> data of the page, so the data is only available through the unsa= fe >>>>>>> raw accessors. >>>>>> >>>>>> Why do we need to allocate Page when we can allocate Page? >>>>>> To me, Page is an observed page state from a non-owner point >>>>>> of view. >>>>> >>>>> I'm not sure we need it, which is why I added this note: >>>>> >>>>> This currently has no users, but I add it here for completeness. Let= 's >>>>> discuss if we should keep it or not. >>>>> >>>>> The difference between the `Page` and `Page` is th= at >>>>> `Page` has stronger invariants. Namely that the (physical) >>>>> memory region of the page does not incur data races, and that the pag= e >>>>> not in highmem. From a Rust point of view, this allows us to obtain a >>>>> reference to the page contents without jumping through any hoops. >>>> >>>> But access to memory region of the page is associated with page table >>>> mapping or IOMMU mapping (for device, and I assume devices are accessi= ng >>>> data via virtual addresses instead of physical addresses to avoid furt= her >>>> complication). It seems that you are trying to use page refcount =3D= =3D 0 >>>> to infer that no page table mapping exists for the page. But how about >>>> kernel direct map? >>> >>> `Page` has the invariant that it must not be in highmem, and >>> as such is always accessible in the kernel virtual address space. As fa= r >>> as I understand, this means we do not need `kmap_local` before accessin= g >>> the contents. >>> >>>> Anyone with struct page can use kmap_local*() >>>> to get kernel direct map and access the page content. kmap_local*() >>>> does not reject frozen pages. >>> >>> `Page` is a unique handle. Nobody can get a hold of the >>> underlying `struct page` to perform mapping operations on the page. >>> >> >> Right, but if kernel direct map exists, how can you claim >> =E2=80=9Cthe (physical) memory region of the page does not incur data ra= ces=E2=80=9D? >> At least, =E2=80=9Cassuming no one is accessing the region via kernel di= rect >> map=E2=80=9D could be added. > > I think I see the disconnect. Let me see if I can explain. > > In Rust, when you allocate memory that is not reference counted, you get > a handle to it. In safe Rust, you are the only one with that handle. The > type system makes sure that you can only write through this handle if > you did not share it with anyone. All this is ensured statically, and > the handle compiles down to a pointer at runtime. `Page` is > such a handle. Assuming absence of unsafe Rust and C code, the allocated > memory is race free. > > In the kernel of course we have C code and any thread in the kernel can > access any piece of memory mapped into the address space, including all > physical memory via the direct map (assuming no highmem). But that is > not how we generally write software. If we want to access the contents > of a frozen `struct page`, we will get the pointer to it from somewhere, > probably an allocator. Probably we will call `alloc_frozen_pages()`. And > assuming the allocator is correct, it will not hand out the same page > twice, at least not until it is freed first. > > So the page backing `Page` comes from `alloc_frozen_pages`, > and since this function will not hand out pages that are already in use, > we can claim that the page contents is free of data races. If this is > not the case, there is a bug in the kernel. Pages handed out by > `alloc_frozen_pages` should not be in use. > > And because of the type system, users of `Page` can only > write the page contents if the compiler can assert that the handle is > unique. This is called an exclusive reference, or a mutable reference, > in Rust. > > They `Page` type makes sure that the page cannot be used in a > way that would cause the page contents to incur data races. It cannot be > inserted into a vma, for instance. > > So the guarantee comes from ownership of the allocation, not from mm > preventing direct map access. Thank you for the explanation. It matches my understanding. These Page types would only concerns about Rust side, assuming C code respects the exclusive ownership. My point is that this assumption should be written in the comment for clarification, so in the future when a bug appears, one will check C code directly. Or this assumption is implicit since Rust type system guarantees the correctness of Rust code? > >> >>>> >>>>> >>>>> I do not have a user for a frozen page without these invariants, but = I >>>>> would assume there are use cases? >>>> >>>> For the above reason, everything is Page? >>> >>> Pages that are part of user space process vmas are not frozen? We see >>> these in system calls for IO. >> >> Sorry I was too vague. I mean Page and Page should >> be Page given that kernel direct map exists. Strictly speaking, >> Page should be pages allocated without kernel direct mapping. > > It is OK for the pages to be direct mapped. In fact I think they _have_ > to be, otherwise we would not be able to access their content. OK. Should this be documented clearly in the comment? > >> >>> >>>> >>>>> >>>>>> In core-mm, a page is frozen, when its refcount =3D=3D 0. The code l= ooking >>>>>> at the page knows the page is exclusively owned by others. If the co= de >>>>>> allocates a frozen page, it will not check its refcount, because >>>>>> the code knows it has the exclusive ownership of the page. To reflec= t >>>>>> this, the code calling alloc_frozen_pages() should just get >>>>>> Page >>>>> >>>>> Is it always the case that users of frozen pages will use them in suc= h a >>>>> way that they can guarantee no races to the page contents (physical >>>>> memory)? They cannot be mapped for DMA access or anything like that - >>>>> that always requires a refcount? >>>> >>>> See kmap_local*() case above. >>> >>> Right. Both `Page` and `Page` are guaranteed to be >>> the only reference the underlying `struct page`, and so nobody can do >>> mapping operations from under us. The difference of the two is that >>> `Page` provides guarantees about placement out of highmem an= d >>> no races on the page contents. >>> >> >> Sorry for being pedantic, but IMHO =E2=80=9Cno races on the page content= =E2=80=9D is >> too strong. LLM tells me, let me know if it is wrong, that DMA map >> code does not check page refcount and currently gives a dma_addr_t >> for slab and kmalloc pages, which are frozen. This means a Page >> can be mapped via dma map C code. What is the plan to prevent that? > > `Page` cannot be mapped for dma with safe Rust code. We use > the Rust type system to ensure this. We use different types to express > different capabilities. > > (Future) Rust DMA mapping APIs may not take `Page` or > `Page` as arguments. Does this imply that Rust code does not and will not hand this page to C code? The claim should be restricted to Safe Rust. Especially for =E2=80=9CA Page ... Thus, the exclusive ownership of the page is upheld by the kernel, and not only by the Rust type system.=E2=80=9D, core-mm does not uphold the exclusive ownership of the page, since a frozen page just means no one else can take a reference on the page. > >> >>>> >>>>> >>>>>> and if the code encounters a Page and finds it has no refcount= , >>>>>> it should convert it to Page or there should be a method >>>>>> that accepts PFN and return Page if the page of the PFN has = no >>>>>> refcount, for PFN walkers. >>>>> >>>>> We can add conversion functions, that makes sense. >>>>> >>>>>> >>>>>> =E2=80=9Cthe data=E2=80=9D mentioned in Page and Page is struct page >>>>>> data or the data in the physical frame pointed by Page<...>? If it >>>>>> is the former, is it better to use metadata? >>>>> >>>>> I'm referring to the actual physical memory region that the struct pa= ge >>>>> describes. >>>>> >>>>>> >>>>>> I am new to Rust, so feel free to correct me. Thanks. :) >>>>>> >>>>> >>>>> I'm new to mm, I really appreciate your eyes on this. >>>> >>>> Do you mind describing the high level workflow around Page in Rust? >>>> From my point of view, exclusive page content access is more related >>>> to page table (including IOMMU page table) than struct page itself. >>>> struct page ownership is more about the metadata stored in struct >>>> page for physical memory maintenance. >>> >>> Just as in C code, there are many workflows around `Page`. Three main >>> ones I have seen in Rust code are: >>> >>> - Pages that are part of io buffers during a syscall. The pages are >>> mapped in at least one user space process and the kernel may want to >>> read or write from/to them. These would be `Page`. >> >> Is RefCounted too broad for this? A refcounted page might or might not >> be mapped and a mapped page might not might not be mapped into userspace= . >> Is UserMapped more descriptive? > > I think for the invariants we put on `Page` it does not > matter whether the page is mapped or not. The fact that it _may_ be > mapped is enough. If we need to figure out whether a page is mapped or > not in order to give access to particular functionality, we can add > another type for that. This pattern is some times referred to as > typestates. Got it. > >> >> FYI, I am working on adding PG_folio to distinguish user rmappable >> folios from general mapped pages. In terms of pages mapped into >> userspace process, they can be either rmappable or vm_insert*() >> into userspace. > > For now we do not have any infrastructure for handling folios in Rust. > We only handle order 0 regular pages. But I imagine we will need it > eventually. > >> >>> >>> - Pages that hit the block device driver API via the block layer. These >>> can be anything, so we model them as `Page`. >> >> Even they can be frozen without a refcount? > > Yes. Quick robot overview on v7.4-rc2 (I did not verify all of it): > > Kernel buffers from kmalloc() live on frozen pages (refcount 0). The > block layer turns such a buffer into a bio_vec with plain > virt_to_page() and never takes a page reference, so the frozen page > ends up in bi_io_vec unchanged. > > 1. Where frozen pages come from > > SLUB allocates the backing pages for all slabs as frozen pages: > > - Normal slabs: mm/slub.c:3379-3384, allocate_slab() =E2=86=92 > alloc_frozen_pages() / __alloc_frozen_pages(). > - Large kmalloc (bigger than KMALLOC_MAX_CACHE_SIZE): > mm/slub.c:5474-5477 calls alloc_frozen_pages_noprof() and then > __SetPageLargeKmalloc(page). > > So every kmalloc()'d buffer sits on a page whose _refcount is 0, > whether it comes from a slab or the large-kmalloc path. The pages are > freed again with free_frozen_pages(). There is a caveat here, __SetPageLargeKmalloc(page). It sets a page type to the frozen page. It helps one check page ownership. > >> >>> >>> - Pages used for backing storage like in the null block driver. These >>> are modeled as `Page`. >> >> null_alloc_page() uses alloc_pages() and gets refcount =3D=3D 1 pages. >> unless you mean struct nullb_page. > > Yes, the C null block driver uses reference counted pages. The Rust null > block driver implementation will use frozen pages. Matthew suggested > this approach. This worries me, because 1. willy, David, and I have been talking about a new page type for device allocated memory to separate it from rmappable folio (anon or pagecache folios) and this using frozen pages is different; 2. it introduces a new long-live frozen page (exclude zone device memory), = whereas existing frozen pages without a page type are either transient or marked by PG_hwpoison. The transient ones are a) PCP pages, b) compaction=E2=80=99s cc->freepages[], c) temporarily isolated free pages. I am not sure core-mm has code properly handles this new long-live frozen page. At least, page_is_unmovable() used by memory offline needs to handle this kind of frozen page, since it assumes frozen and untyped pages are free or about to be freed and can lead offline_pages() looping on them. See commit 213268869301f ("mm: page_isolation: do not take slab pages for free") for more context. David and willy, what is your take on this? Either we assign a page type to Page or still uses refcounted pages. Best Regards, Yan, Zi