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 5ACB2287244; Mon, 22 Sep 2025 10:29:38 +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=1758536980; cv=fail; b=S5x2W4Z7D92uLhdo9J07Lq79dF8sRM2econxiwPE243HROqsC4c190gA1SJ33pb0CavYVX/8JDOn7dPaAvy6+VIWjGEe4fQNNUTKEALWC76qtYuNxuD9/Be0de1JOYa47U7KbnE9hKoce+e7fV2vRMJV8DfdxVVPZcBBno0PGt0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758536980; c=relaxed/simple; bh=snj2T7DUgIakhWfBQtBVY1LuxUG43jZgOl6RXdmbgTo=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=BM9a3NYOZv5hvVKF9GAOg6jQyrDLN8UCAk1m8YwU0VBTAUN/MxwhJUs/EG9E3QnHUYvZD2uEpk0cV/YlVsgTDtkX5KdB0r3+K34osfshoZ5aHNhI2FlqMqBfHyiSk/WpiliOL+UrVjEL7Puts3uiSuBZPADuBwwaxJd0QkmyKGg= 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=seRAZPIT; 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="seRAZPIT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=X27NqyVVfyz1U8pV2J+5+THgWnI4PvNw/YYd78NAUr1ucx6ulP3ZoMHmE6tYJ2SWxEJHkevnes3NGPAa1625JleCwuZUITFpJR867jIJfOE6sIMf0dFHYOfXoXuVQwaOxxHp37PalZpzh/W83I9fTFoa/TvOW4ZhiM4fE0OiJFHUqYJ+t24L6f5jtt12wjyC5p88L9+ydUgSa65U8av6EidSvdHvpThCmK5Lb1gW+q4x9DwfkZz42gZIvsE1jv2BEhM0shxLSJP6eNvIW7XazqoNBHueaIpYrSkH05e1HxRsPmFKVr9NdrHzA/8tQuX8y4o50uNakRIIemJJ+xJRvg== 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=hKslol1RbonCZ567DY57tFdiqVdBO76b2L+7hn33wws=; b=pnnh9ASw4CsYGrlhYA+FdMMLI8nbY6bjXKwMMp7nPTLMEQ9iEGl6ic6G+U8CFZsbMB3oPeG1AcFtWgbmRWHvuzIvclmmCvidXS9pAkq7nXqPQxjarbhyVdaO1CbIAx9L45RiSP+PzCcJn0DbfOgKXYfOh8T2vklwTeJXAGwKZWNo2mqTxQMFz+eUsjFJKoIk/IeLImq1Rv17IagrNC1ovnqzNAXEAlXxVWfTuRDp6mJ2OxZXt4omb4VZw4bGLKoPhlgmioU5LFO59cwKpJweq1XbgVIUSpt7SXCTpgqagQyFLeLPJHMVnQVm2t83Zza6MDkMPMjpHU/zOKcQniskxg== 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=hKslol1RbonCZ567DY57tFdiqVdBO76b2L+7hn33wws=; b=seRAZPIToGFTi7Ac0YTpZeLVWOhY3qulwwn+HKYnQU+hioPjotfHZWdYqUrrSCULJxIw3n4JwuJYj9qomYp1FF4GTBCQY0pfl2GOwWqdrefQ+DPElxk55keR7INYiASQY2fvDhpEUk/XrAXHXZi/qVDVpJgNeSEtbDPCAUJaR1Y= 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 LO4P265MB6400.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2d4::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9137.20; Mon, 22 Sep 2025 10:29:29 +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.9137.018; Mon, 22 Sep 2025 10:29:28 +0000 Date: Mon, 22 Sep 2025 11:29:22 +0100 From: Gary Guo To: "Benno Lossin" Cc: "Joel Fernandes" , , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , =?UTF-8?B?QmrDtnJu?= Roy Baron , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , , "Alistair Popple" , "Timur Tabi" , Subject: Re: [PATCH] rust: print: Fix issue with rust_build_error Message-ID: <20250922112922.0f57fbf3@eugeo> In-Reply-To: References: <20250920161958.2079105-1-joelagnelf@nvidia.com> <20250921004517.GA2101443@joelbox2> X-Mailer: Claws Mail 4.3.1 (GTK 3.24.49; x86_64-pc-linux-gnu) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0553.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:33b::7) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|LO4P265MB6400:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e55f665-af19-4c80-3e02-08ddf9c2e7fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|7416014|376014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?yOnc7e8pYNkBVeh3AcWYQbdkwmcjMahbL94XnA5ifg0bbEdmgzjzMKkMdt+H?= =?us-ascii?Q?mi2mpPz5tzW7iO1KzH1hrIiN0EVgp/lBbnKm36OxBbtJAb9ftRyTLdHin3MF?= =?us-ascii?Q?/HwhD+NFPr47Fgr3Iua0UnpH1WgbYVDgA4YxKvbte1tAngP+6siCgQnb5qhi?= =?us-ascii?Q?tA5yhC25CM0t3CA8eTCamvxRb5AZvem1j2LKk1rKRIhzvSGrI/kP0bVtq9Mq?= =?us-ascii?Q?skzxRS5fKH6+w0YA8/y4yD86QfBXfd8qIw+t3sUZp1zuH+5EjLbh0szxoIZW?= =?us-ascii?Q?3I+UNxKD2dpQbZVHlrCv9PpHXqHAhGUCAIPFzMuiNNhvlE5xTM0N76Bh9FS6?= =?us-ascii?Q?r1SLEwo14qmePOIc19FGfuU62pbGz8Uq78hX1Toi4dq0ki/0ZbNRmWY0I2tC?= =?us-ascii?Q?EIS74ta2XPEd+TNv1B8GpnJDDmljs/rDHs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us-ascii?Q?m4PnOpu+FHGgDP0P1zELYkjxPVmQneNl6P1WFgePA//STvkUHLfJCBowOlD4?= =?us-ascii?Q?oxkuhmU0DPzNMxUNfdWkEyqKuHZaVLKAy9G0h/AXAm7+ZjNV8T3BAN8pxbTf?= =?us-ascii?Q?6fJVdoOULTo=3D?= 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)(366016)(1800799024)(7416014)(376014)(7053199007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jmIgfihXLnMG+N308FNefmNgbs5YVzwgTKXcKI9X9i9CcDxXVNVgy2+z4VUZ?= =?us-ascii?Q?GFjIfdwdCZdrf5SSKvzxSx90nd/+OllvKiRenC0hj3tPo5SbAJK7wYt39VPF?= =?us-ascii?Q?WVOX8PHGROIlixYhCtGeqn1XIg2VbhEhpBbT3dtHoZgaDEptYjJwg9EptFJP?= =?us-ascii?Q?RT2FzE0T+JHM62zpYTOL7JzN9jJ3NOczBGvxFr74DHI0gkqD4IBZmpOnaQn0?= =?us-ascii?Q?lEHPv30rjV5gY3lHq4nUufvtq9H7nMHrLrAo5ZFBZ+u05QukaBB6V5bgekxN?= =?us-ascii?Q?Tq6dx1JOsma9j7QUIou98WrLV+X0pHVZSXL7iGDVEhVXvaK8608RWp/Vhyhv?= =?us-ascii?Q?FSdSq8Z/CXGvwc1E75+2PdRiEjzHlG+g7xt8ucgGKo7Km7TVFqpWDoWBXY6U?= =?us-ascii?Q?DvAxof/cIQTUH8EXcR8kGyc7axpssXAKQUVCdkeV8Irif961rsp/jMnR5WMt?= =?us-ascii?Q?PdhZ3qqp+HamawfauR+tVQUJJniM6QeP9qTx/nJva+JBeUxU9UBPT/Pa4KCk?= =?us-ascii?Q?P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judjiH?= =?us-ascii?Q?R4qz0IUMcIAJ1+iIixnPtHsPzhiNfTs6H5qAKttwrkUPqCH14MkXx7dGSkNu?= =?us-ascii?Q?I3gWswc01xKsD3oLCDAcOZH4g/1CEB3mHBUoRIgrO9OJdzUeQiG5QHL220tc?= =?us-ascii?Q?Ald+dFlY5ViXjFKTGH1gvcRcrUOSyZ/iERPmdDmn?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 3e55f665-af19-4c80-3e02-08ddf9c2e7fe X-MS-Exchange-CrossTenant-AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2025 10:29:28.3448 (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: 7xiN3EOWINLwA9hV/2xA41hSjbfSjJ29sgAaznoU8R4TMPBPJhhm6sEQzdTbcbmmM6JEvLQKRJPaCuGoa4uCEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO4P265MB6400 On Sun, 21 Sep 2025 09:12:45 +0200 "Benno Lossin" wrote: > On Sun Sep 21, 2025 at 2:45 AM CEST, Joel Fernandes wrote: > > On Sat, Sep 20, 2025 at 10:09:30PM +0200, Benno Lossin wrote: > >> On Sat Sep 20, 2025 at 6:19 PM CEST, Joel Fernandes wrote: > >> > When printing just before calling io.write32(), modpost fails due to > >> > build_assert's missing rust_build_error symbol. The issue is that, the > >> > printk arguments are passed as reference in bindings code, thus Rust > >> > cannot trust its value and fails to optimize away the build_assert. > >> > > >> > The issue can be reproduced with the following simple snippet: > >> > let offset = 0; > >> > pr_err!("{}", offset); > >> > io.write32(base, offset); > >> > >> I took a long time to understand this and I think I got it now, but > >> maybe I'm still wrong: passing `offset` to `printk` via a reference > >> results in the compiler thinking that the value of `offset` might be > >> changed (even though its a shared reference I assume). For this reason > >> the `build_assert!` used by `io.write32` cannot be optimized away. > > > > Yes, that's correct and that's my understanding. I in fact also dumped the IR > > and see that the compiler is trying to reload the pointer to the offset. I > > feel this is a compiler bug, and for immutable variables, the compiler should > > not be reloading them even if they are passed to external code? Because if > > external code is modifying immutable variables, that is buggy anyway. > > It would be great if you could add all of the extra info that you looked > at into the commit message here. So all of the code to reproduce the > issue, the IR you looked at... > > >> > Fix it by just using a closure to call printk. Rust captures the > >> > arguments into the closure's arguments thus breaking the dependency. > >> > This can be fixed by simply creating a variable alias for each variable > >> > however the closure is a simple and concise fix. > >> > >> I don't think this is the fix we want to have. > > > > Yeah its ugly, though a small workaround. IMO ideally the fix should be in > > the compiler. I want to send a proposal for this in fact. I looked at the MIR > > and I believe with my limited understanding, that the MIR should be issuing a > > copy before making a pointer of the immutable variable if pointers to > > immutable variables are being passed to external functions. > > ... and definitely the MIR. > > > If I were to send a proposal to the Rust language to start a discussion > > leading to a potential RFC stage, would you mind guiding me on doing so? > > I agree that this should be fixed in the compiler if we aren't missing > some attribute on one of our functions. > > Note that this probably doesn't require an RFC, since it's not a big > feature and I imagine that there isn't much controversy about it. We can > mention this in our sync meeting on Wednesday with the Rust folks & see > what they have to say about it. After that we probably want to open an > issue about it, I'll let you know. > > >> In fact it already > >> doesn't compile all of the existing code: > > > > Oh gosh, I should have run doctests. I just did a normal build. Let me see > > if I can fix this closure issue. > > We might just want to live with this until we get the compiler fixed. Or > is there a different workaround like this: > > let offset = 0; > let offset_pr = offset; > pr_err!("{}", offset_pr); > io.write32(base, offset); I suggested to Joel during Kangrejos that just pr_err!("{}", {offset}); should work, as it would create a new copy. Best, Gary