From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BA824175A79; Sat, 14 Mar 2026 00:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773448137; cv=none; b=NWqLckybCHWJangcJjL6zIz5ExG8NGz4YJWa17+VUUzlhb6NqNL/nttx/sVD1faQGilielX6zg4THXcU8tJTIHADrxKTROuc4+rj/JawuKYJxq58b3S+cjYFHPhLBW0G8JihVobJseiQYEg+0esy4/w5nzvwWqh+gQSxz/GYU9s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773448137; c=relaxed/simple; bh=zSE9ZGweC+SFIsH032TFQbSFVYRUcYwmPoW4bQHRezM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UW91GqrJGSJftXaGGiMCy9kzgQWnZWtn7zEmplCOlCp1Jx7y+7258f39YeToeDHGuGwQ1WTraD5t6oncuE+JnW/5WK8EyO6M+MHPhX3nWwTo40UfMiMpqmZ2kQDmK2FwSgkWVnBhkqDemZBSqszFaCC1BxTMx+KiMRZIb3qlxZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oWVm/e4O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oWVm/e4O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2BB0C19421; Sat, 14 Mar 2026 00:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773448137; bh=zSE9ZGweC+SFIsH032TFQbSFVYRUcYwmPoW4bQHRezM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oWVm/e4OUxlj/A92kYR7Y/AIT1DbGO1/YYGUMfnA/Z/uWpoy8U+OO3g0PasfcD1sn 1dkin4Lmf3Mod70C/Y01YmcJKM9KZSkO2dO6hAGVwnwK97nD36PrbfDgVVGUUESddP Y86zcX1El3g7ubhIuj7U3VROlk/TtvAv+BRfc6Rx8w1dJ6sd6r+JFNQ17QHRo6uA8F JCc4Pb3SC53TsksyfFaZmu6jl9zTJ9TTBtu91xxeV/1WYuFwNtPdSOyGGYhIbtaaRf sefWI5TJq8oIxMw7ucBmA/efI7ew9xTcs9/3yYg8J+sjUgn9KwVwqXoFRKD0yVWZls qy9BslFYHmsgA== Date: Fri, 13 Mar 2026 17:28:50 -0700 From: Nathan Chancellor To: Alice Ryhl Cc: Miguel Ojeda , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Alexandre Courbot , Will Deacon , Peter Zijlstra , Mark Rutland , Nick Desaulniers , Bill Wendling , Justin Stitt , Nicolas Schier , Andrew Morton , Uladzislau Rezki , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-kbuild@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2 2/3] rust: helpers: #define __rust_helper Message-ID: <20260314002850.GB534169@ax162> References: <20260203-inline-helpers-v2-0-beb8547a03c9@google.com> <20260203-inline-helpers-v2-2-beb8547a03c9@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260203-inline-helpers-v2-2-beb8547a03c9@google.com> On Tue, Feb 03, 2026 at 11:34:09AM +0000, Alice Ryhl wrote: > From: Gary Guo > > Because of LLVM inling checks, it's generally not possible to inline a C > helper into Rust code, even with LTO: > > * LLVM doesn't want to inline functions compiled with > `-fno-delete-null-pointer-checks` with code compiled without. The C > CGUs all have this enabled and Rust CGUs don't. Inlining is okay since > this is one of the hardening features that does not change the ABI, > and we shouldn't have null pointer dereferences in these helpers. > > * LLVM doesn't want to inline functions with different list of builtins. C > side has `-fno-builtin-wcslen`; `wcslen` is not a Rust builtin, so > they should be compatible, but LLVM does not perform inlining due to > attributes mismatch. > > * clang and Rust doesn't have the exact target string. Clang generates > `+cmov,+cx8,+fxsr` but Rust doesn't enable them (in fact, Rust will > complain if `-Ctarget-feature=+cmov,+cx8,+fxsr` is used). x86-64 > always enable these features, so they are in fact the same target > string, but LLVM doesn't understand this and so inlining is inhibited. > This can be bypassed with `--ignore-tti-inline-compatible`, but this > is a hidden option. > > To fix this, we can add __always_inline on every helper, which skips > these LLVM inlining checks. For this purpose, introduce a new > __rust_helper macro that needs to be added to every helper. > > Most helpers already have __rust_helper specified, but there are a few > missing. The only consequence of this is that those specific helpers do > not get inlined. > > Signed-off-by: Gary Guo > Signed-off-by: Alice Ryhl > --- Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor > rust/helpers/helpers.c | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c > index a3c42e51f00a0990bea81ebce6e99bb397ce7533..e05c6e7e4abb7e6a4c4a3a417e35022dac1d9c58 100644 > --- a/rust/helpers/helpers.c > +++ b/rust/helpers/helpers.c > @@ -7,7 +7,36 @@ > * Sorted alphabetically. > */ > > +#include > + > +#ifdef __BINDGEN__ > +// Omit `inline` for bindgen as it ignores inline functions. > #define __rust_helper > +#else > +// The helper functions are all inline functions. > +// > +// We use `__always_inline` here to bypass LLVM inlining checks, in case the > +// helpers are inlined directly into Rust CGUs. > +// > +// The LLVM inlining checks are false positives: > +// * LLVM doesn't want to inline functions compiled with > +// `-fno-delete-null-pointer-checks` with code compiled without. > +// The C CGUs all have this enabled and Rust CGUs don't. Inlining is okay > +// since this is one of the hardening features that does not change the ABI, > +// and we shouldn't have null pointer dereferences in these helpers. > +// * LLVM doesn't want to inline functions with different list of builtins. C > +// side has `-fno-builtin-wcslen`; `wcslen` is not a Rust builtin, so they > +// should be compatible, but LLVM does not perform inlining due to attributes > +// mismatch. > +// * clang and Rust doesn't have the exact target string. Clang generates > +// `+cmov,+cx8,+fxsr` but Rust doesn't enable them (in fact, Rust will > +// complain if `-Ctarget-feature=+cmov,+cx8,+fxsr` is used). x86-64 always > +// enable these features, so they are in fact the same target string, but > +// LLVM doesn't understand this and so inlining is inhibited. This can be > +// bypassed with `--ignore-tti-inline-compatible`, but this is a hidden > +// option. > +#define __rust_helper __always_inline > +#endif > > #include "atomic.c" > #include "atomic_ext.c" > > -- > 2.53.0.rc1.225.gd81095ad13-goog >