From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from LO0P265CU003.outbound.protection.outlook.com (mail-uksouthazon11022075.outbound.protection.outlook.com [52.101.96.75]) (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 4CF9A72623; Mon, 8 Dec 2025 13:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.96.75 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765201782; cv=fail; b=MJsRr9SNF7RJsdIZk855dD7ngUZVq60QJs3dfLsgA4XgL9IkcYTKuwpLtT24zDNrHPmZCYHQin26ZuTsXEBReAdLlne6H54wK+A50S27ncFxIqTKl+kXTPfn0TyrsC9EZOHDF6qhSPdID3dv/ZoZVCD7XsZAc5Jo1cx0Ir1HXSY= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765201782; c=relaxed/simple; bh=+ChtnHYhXYmQB9Ju1VhVp30Sn0BUl6WxavEiugo9H0s=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ScFl9rZINnHgTdQRmpU8K+vKEAfVTNaqsj6L9V+egQilYQGd+knGIp1DsaSLaxsnNs5xcT2WCjs+3+6kiE1WlkXtKf50QqKRTBgP0IGAtSEs15SWyWYJZsx5hJ+Gd5+ohoYXviWImtcflmbqEe3wP9XtJDJa2bkHIqAmyrp72JI= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b=ZN52kC3a; arc=fail smtp.client-ip=52.101.96.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b="ZN52kC3a" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Xxncm8BYAopKMNAkCZFY8R8rz5nKUPR4AamMEFyWmgdPouKKPJ6jFWZmXiJgfTRjEOaS37GMDv7hVbY/zAu17sTDcWwR2e7CKYRDkGfs2WEshDyeuvwEtFZ3rs1H8BnZRlxKApIs+idZTMns63XTxLYxQE7lN3aten7nPAXU/c4mt46Mp3Hkxw0eNAL70E0FLRRGI4h0aSlsDWnwS3rDhZBodtnEznTe1V4lASPgtD5M7QKwQ1Gfz5Pkgq+LhKKBHhj5y3JzqhMYWoCZ9o+sp0pO23VUAIDANYsVIssy1A9jomuDdpe8Tj/AOfAdshUl33f+WsiasVi5rnmuTusV7Q== 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=CKwz8FOUzDI5BdFxJBDXzI4Noa1klj/zs27vC4Yz8l8=; b=dX7KsGwueAVd3eqosqUN1LwZ+XmhTAK25ajPpuMj7y7ZoesPC3FJxrxmxQQXuX75j/9lqZqJIu6VGmnqQpVhyvDmdcB2Fowct01CTMw1aGZrH3osO5AgWZIMFojwYAa14iRu3BZxDrheKXbNuNlneiCZJzp3Sk2MmpiDUd86F5M4t/1hRW2YVS7vp2xEgDdBRZ0PnwW1/SkAMmFPQbPNxSxsvnLWbn+9fushCKwUBNcrIGuCMbCloy73mB0YL7eK3COJf34z1xC8tDJ9MhYrYYzeOGrbwKIhESic27tKI3GCG5kp969Lu2kkeP2q81+piEKVqr9xWcJqGtIxHh/muw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CKwz8FOUzDI5BdFxJBDXzI4Noa1klj/zs27vC4Yz8l8=; b=ZN52kC3aqbK1IA67np0SO78txYuWjZwbOMey/9lExwsQdSr1Nrkp7XlE++2df+2rnq93dzi28f8M41K7uj1NE44avUoZ/n4zdWFei2kuD5d6UleGrN6WEiHGpx/cKmmmsQvINdYxBfGnIhDHUQYj+Rmx6jx1tZJcaPcdX+mvcPM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) by LO0P265MB5989.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:28c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9388.14; Mon, 8 Dec 2025 13:49:35 +0000 Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1818:a2bf:38a7:a1e7]) by LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1818:a2bf:38a7:a1e7%6]) with mapi id 15.20.9388.013; Mon, 8 Dec 2025 13:49:35 +0000 Date: Mon, 8 Dec 2025 13:49:33 +0000 From: Gary Guo To: Alexandre Courbot Cc: Danilo Krummrich , Alice Ryhl , Daniel Almeida , Miguel Ojeda , Alex Gaynor , Boqun Feng , =?UTF-8?B?QmrDtnJu?= Roy Baron , Benno Lossin , Andreas Hindborg , Trevor Gross , "Rafael J. Wysocki" , Viresh Kumar , Will Deacon , Peter Zijlstra , Mark Rutland , , , , Subject: Re: [PATCH v3 0/7] rust: build_assert: document and fix use with function arguments Message-ID: <20251208134933.24372874.gary@garyguo.net> In-Reply-To: <20251208-io-build-assert-v3-0-98aded02c1ea@nvidia.com> References: <20251208-io-build-assert-v3-0-98aded02c1ea@nvidia.com> X-Mailer: Claws Mail 4.3.1 (GTK 3.24.51; x86_64-pc-linux-gnu) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0503.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13b::10) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|LO0P265MB5989:EE_ X-MS-Office365-Filtering-Correlation-Id: 355851fb-546b-44ed-a1dd-08de36609fab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|10070799003|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?LJKHQVchRhLjIytNT0YJDvCTzuiHpLU2rIHiopxHwEUQ/Ful8CxCsxhuGZ44?= =?us-ascii?Q?3eaBAT7GuMrVBMbGyenBoJA6I/N+SUp1G4Q8coWJp2qSmAgx46QHcUNGr4qL?= =?us-ascii?Q?pLLT3Q8YkHbjYAnKoX4juxvLtPQ9RTAJrT7vheIwrAh/CQIU9rYiXg09K0Jc?= =?us-ascii?Q?/3KYEuO6eaXKyhVAgrqi1XksQfWJ9HvSlF6T9JhHIvc9dAGNaMw05L4W64T6?= =?us-ascii?Q?8QV4AHYrP7CmsOxl0Ti3dO2Kp+tmssZeoUOvSUOPTGJoN8Drgp/unCzSRWuW?= =?us-ascii?Q?bIhL2Prytma6lBCaBydDfoLrVMrN8Tm3YYnU6Rr55d19ce5B8PHggLt5rRl2?= =?us-ascii?Q?Q3RU5Kk5M8/7wgBY0BtxAbqTP9PhVYhk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Q?xJ+bBGUyuKkywN4ReZJ0npa3ZkacMg3lThj8hEB0Kci8zD++M5B/g/IhJmWU?= =?us-ascii?Q?+MRsOLqcI+rJOk4DONk4m8ww/K3z1ai8nf5s3SpEuMKp1vWXN9Rkplvyu5Yz?= =?us-ascii?Q?mbH2tmtvnfMXazS6nWrIhNef9aTflmUhkNKoNkp1Mocq0AJoML6iAyespmQh?= =?us-ascii?Q?8W7Sa2lEBIR/5dn/F/88+cXFbmr2+Wdp?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(10070799003)(1800799024)(7053199007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?VZQSyljaEQbPOMdykgOjlUMnbC3SkaP24/RiDtERVt4fQyu5qgz+zPrHl7P0?= =?us-ascii?Q?RAnuC1rJTt3lSbgDJvejvDJZmfMkACBiA3NaZU5BY5MRpqOoM2bSViZmryJR?= =?us-ascii?Q?mjNSru7eOrK7lhjbpvjR/lIp1XgercnqJ4QNH3RHlMJ8wX33NwchwrDC2ME/?= =?us-ascii?Q?hNBnJ3OprWUJD4rhHbAhLh5GQbVSqtD3lVxcf7uQBka9e6ti7Iu+QHZTTMeZ?= =?us-ascii?Q?qflf9DNe9TUAQH01jUqkq5ma2tmn03bkPUZ6uU9qNtl6yywxtTcJM6sd4eov?= =?us-ascii?Q?7w6k5Mlh8+SBzEMpX00rBYR2XcvuSYvxmUEkJIubH7NZFB7s3TPkLza/POl7?= =?us-ascii?Q?2s/j4ep6Nsbm/kFgsws8GITrdSXmqsJFPm8EXlvYoFr8/uAI/xzz78UkpC3Q?= =?us-ascii?Q?ae0KnyZ9SCcUkXjXkQlVsp00mMW0xZ81dxJCVp24NEeopR4nq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DHD3Q+0LJynti0+8rZmgUPNDH9vFCqGvXhDO?= =?us-ascii?Q?1UBg3pTQth2bD9TCBCx2OileuFYzSxT/8TfXgZekfpE2dDzsWgkz5s/irD4L?= =?us-ascii?Q?zL1orfmLTsQLJgPoleQ7HnNouoGEXUcPaZzofAI4pdc90iiedmlYWEnlH2p2?= =?us-ascii?Q?rwCt4+HL4tK+uj0sMSU8eWQM61t6EQTYX4ThMoT6iaU+6JAJZPHfcrSsnVtI?= =?us-ascii?Q?kElk7cZxdbXO4eO2+PqXW4l5Tl1Sc8UAIIm6TrYZ?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 355851fb-546b-44ed-a1dd-08de36609fab X-MS-Exchange-CrossTenant-AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2025 13:49:35.7885 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QfqDTyqTn3Umijw58xyBj3VDHdoO1N4BhdIWcJHmRNWNAB+vCEwJ8VxNnYgLOByy4KB9rM4YhYy3aQ4hQEQ6Dg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO0P265MB5989 On Mon, 08 Dec 2025 11:46:58 +0900 Alexandre Courbot wrote: > `build_assert` relies on the compiler to optimize out its error path, > lest build fails with the dreaded error: > > ERROR: modpost: "rust_build_error" [path/to/module.ko] undefined! > > It has been observed that very trivial code performing I/O accesses > (sometimes even using an immediate value) would seemingly randomly fail > with this error whenever `CLIPPY=1` was set. The same behavior was also > observed until different, very similar conditions [1][2]. > > The cause, as pointed out by Gary Guo [3], appears to be that the > failing function is eventually using `build_assert` with its argument, > but is only annotated with `#[inline]`. This gives the compiler freedom > to not inline the function, which it notably did when Clippy was active, > triggering the error. That's an interesting observation, so `#[inline]` is fine without clippy but `#[inline(always)]` is needed when Clippy is used? I know Clippy would affect codegen but this might be a first concrete example that it actually creates (non-perf) issues that I've countered in practice. > > The fix is to annotate functions passing their argument to > `build_assert` with `#[inline(always)]`, telling the compiler to be as > aggressive as possible with their inlining. This is also the correct > behavior as inlining is mandatory for correct behavior in these cases. Yeah, I suppose when you draw parallelism with C `BUILD_BUG` macro, there are a few users of that in other macros, which are kinda force-inlined. > > This series fixes all possible points of failure in the kernel crate, > and adds documentation to `build_assert` explaining how to properly > inline functions for which this behavior may arise. > > [1] https://lore.kernel.org/all/DEEUYUOAEZU3.1J1HM2YQ10EX1@nvidia.com/ > [2] https://lore.kernel.org/all/A1A280D4-836E-4D75-863E-30B1C276C80C@collabora.com/ > [3] https://lore.kernel.org/all/20251121143008.2f5acc33.gary@garyguo.net/ > > Signed-off-by: Alexandre Courbot > --- > Changes in v3: > - Add "Fixes:" tags. > - CC stable on fixup patches. > - Link to v2: https://patch.msgid.link/20251128-io-build-assert-v2-0-a9ea9ce7d45d@nvidia.com > > Changes in v2: > - Turn into a series and address other similar cases in the kernel crate. > - Link to v1: https://patch.msgid.link/20251127-io-build-assert-v1-1-04237f2e5850@nvidia.com > > --- > Alexandre Courbot (7): > rust: build_assert: add instructions for use with function arguments > rust: io: always inline functions using build_assert with arguments > rust: cpufreq: always inline functions using build_assert with arguments > rust: bits: always inline functions using build_assert with arguments > rust: sync: refcount: always inline functions using build_assert with arguments > rust: irq: always inline functions using build_assert with arguments > rust: num: bounded: add missing comment for always inlined function > > rust/kernel/bits.rs | 6 ++++-- > rust/kernel/build_assert.rs | 7 ++++++- > rust/kernel/cpufreq.rs | 2 ++ > rust/kernel/io.rs | 9 ++++++--- > rust/kernel/io/resource.rs | 2 ++ > rust/kernel/irq/flags.rs | 2 ++ > rust/kernel/num/bounded.rs | 1 + > rust/kernel/sync/refcount.rs | 3 ++- > 8 files changed, 25 insertions(+), 7 deletions(-) > --- > base-commit: ba65a4e7120a616d9c592750d9147f6dcafedffa > change-id: 20251127-io-build-assert-3579a5bfb81c > > Best regards,