linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: Ralf Jung <post@ralfj.de>
Cc: "Ard Biesheuvel" <ardb@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"moderated for non-subscribers"
	<linux-arm-kernel@lists.infradead.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@lists.linux.dev, stable@vger.kernel.org,
	"Matthew Maurer" <mmaurer@google.com>,
	"Jubilee Young" <workingjubilee@gmail.com>
Subject: Re: [PATCH] arm64: rust: clean Rust 1.85.0 warning using softfloat target
Date: Thu, 13 Feb 2025 17:12:37 +0000	[thread overview]
Message-ID: <20250213171237.08e0edec@eugeo> (raw)
In-Reply-To: <9430b26a-8b2b-4ad8-b6b0-402871f2a977@ralfj.de>

On Thu, 13 Feb 2025 16:46:22 +0100
Ralf Jung <post@ralfj.de> wrote:

> Hi all,
> 
> > We have to carefully make the distinction here between codegen and ABI.
> > 
> > The arm64 C code in the kernel is built with -mgeneral-regs-only
> > because FP/SIMD registers are not preserved/restored like GPRs, and so
> > they must be used only in carefully controlled circumstances, i.e., in
> > assembler code called under kernel_neon_begin()/kernel_neon_end()
> > [modulo some exceptions related to NEON intrinsics]
> > 
> > This does not impact the ABI, which remains hard-float [this was the
> > only arm64 calling convention that existed until about a year ago].
> > Any function that takes or returns floats or doubles (or NEON
> > intrinsic types) is simply rejected by the compiler.  
> 
> That's how C works. It is not how Rust works. Rust does not reject using floats 
> ever. Instead, Rust offers softfloat targets where you can still use floats, but 
> it won't use float registers. Obviously, that needs to use a different ABI.

That's today's situation, although we do prefer to be able to turn off
floats completely (and also not have to compile parts of libcore that's
related to floats).

We mentioned this to the lang team a couple of times, and they do
acknolwedge there might be a need for it, although it's not something
that today's Rust can handle well (i.e. no feature disabling for
libcore).

We have also listed this in
https://github.com/Rust-for-Linux/linux/issues/2 and
https://github.com/Rust-for-Linux/linux/issues/514.

> As you said, aarch64 does not have an official softfloat ABI, but LLVM 
> implements a de-facto softfloat ABI if you ask it to generate functions that 
> take/return float types while disabling the relevant target features. (Maybe 
> LLVM should just refuse to generate such code, and then Rust may have ended up 
> with a different design. But now this would all be quite tricky to change.)
> 
> > Changing this to softfloat for Rust modifies this calling convention,
> > i.e., it will result in floats and doubles being accepted as function
> > parameters and return values, but there is no code in the kernel that
> > actually supports/implements that.  
> 
> As explained above, f32/f64 were already accepted as function parameters and 
> return values in Rust code before this change. So this patch does not change 
> anything here. (In fact, the ABI used for these functions should be exactly the 
> same before and after this patch.)
> 
> > Also, it should be clarified
> > whether using a softfloat ABI permits the compiler to use FP/SIMD
> > registers in codegen. We might still need -Ctarget-feature="-neon"
> > here afaict.  
> 
> Rust's softfloat targets do not use FP/SIMD registers by default. Ideally these 
> targets allow selectively using FP/SIMD registers within certain functions; for 
> aarch64, this is not properly supported by LLVM and therefore Rust.
> 
> > Ideally, we'd have a target/target-feature combo that makes this more
> > explicit: no FP/SIMD codegen at all, without affecting the ABI,
> > therefore making float/double types in function prototypes illegal.
> > AIUI, this change does something different.  
> 
> Having targets without float support would be a significant departure from past 
> language decisions in Rust -- that doesn't mean it's impossible, but it would 
> require a non-trivial effort (starting with an RFC to lay down the motivation 
> and design).
> 
> Kind regards,
> Ralf
> 
> 



  reply	other threads:[~2025-02-13 18:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-10 16:37 [PATCH] arm64: rust: clean Rust 1.85.0 warning using softfloat target Miguel Ojeda
2025-02-11 10:33 ` Will Deacon
2025-02-13 12:22   ` Miguel Ojeda
2025-02-11 11:10 ` Trevor Gross
2025-02-12  0:57   ` Matthew Maurer
2025-02-12  7:34   ` Ralf Jung
2025-02-12  9:27 ` Alice Ryhl
2025-02-13 13:59 ` Will Deacon
2025-02-13 15:32 ` Ard Biesheuvel
2025-02-13 15:46   ` Ralf Jung
2025-02-13 17:12     ` Gary Guo [this message]
2025-02-13 17:18     ` Ard Biesheuvel
2025-02-13 20:17       ` Ralf Jung

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250213171237.08e0edec@eugeo \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=ardb@kernel.org \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmaurer@google.com \
    --cc=ojeda@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=post@ralfj.de \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=will@kernel.org \
    --cc=workingjubilee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).