From: Christian Schrefl <chrisi.schrefl@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>, Andrew Lunn <andrew@lunn.ch>,
Miguel Ojeda <ojeda@kernel.org>
Cc: "Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"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>,
"Jonathan Corbet" <corbet@lwn.net>,
"Russell King" <linux@armlinux.org.uk>,
"Rudraksha Gupta" <guptarud@gmail.com>,
"Ard Biesheuvel" <ardb@kernel.org>,
"Geert Stappers" <stappers@stappers.nl>,
"Jamie Cunliffe" <Jamie.Cunliffe@arm.com>,
"Sven Van Asbroeck" <thesven73@gmail.com>,
rust-for-linux@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3] arm: rust: Enable Rust support for ARMv7
Date: Sat, 1 Feb 2025 00:42:19 +0100 [thread overview]
Message-ID: <defddc25-eb8b-420a-b64c-6ce57ebb3f6b@gmail.com> (raw)
In-Reply-To: <e14cfb34-308f-4797-afe7-4e7e2d470fe3@app.fastmail.com>
On 31.01.25 8:37 PM, Arnd Bergmann wrote:
> On Fri, Jan 31, 2025, at 19:58, Christian Schrefl wrote:
>> On 31.01.25 5:05 PM, Andrew Lunn wrote:
>>>> To fix this Rust would have to provide a way to build the core
>>>> library without float support. I don't know if there is a plan
>>>> already to allow this.
>>>
>>> Floating point is banned within the kernel, except for in very narrow
>>> conditions, because the floating point registers are lazy saved on
>>> context switch. If the kernel uses the floating point registers, you
>>> can break user space in bad ways.
>>>
>>> I expect this has been discussed, since it is well known kernel
>>> restriction. Maybe go see what happened to that discussion within RfL?
>>
>> After checking again, it seems the float intrinsics are actually not
>> needed anymore at least for my config.
>
> Ah, nice! If this is true for all architectures using the current
> rust compiler, it would be great to remove the FP stubs entirely
> and have link errors instead of panicking, to make it consistent
> with C.
After a quick test it seems that (most?) intrinsics are not needed
anymore on x86, but not sure if that's valid for all supported rust
versions and config options.
>
>> Only `__aeabi_uldivmod` is still
>> required for `parse_u64_into` since [0] allows disabling float formatting.
>>
>> Link error without the `__aeabi_uldivmod` symbol defined:
>>
>> ld.lld: error: undefined symbol: __aeabi_uldivmod
>>>>> referenced by num.rs:580 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:580)
>>>>> rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a
>>>>> referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589)
>>>>> rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a
>>>>> referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589)
>>>>> rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a
>>>>> referenced 34 more times
>>>>> did you mean: __aeabi_uidivmod
>>>>> defined in: vmlinux.a(arch/arm/lib/lib1funcs.o)
>>
>> Not sure if we should just implement `__aeabi_uldivmod`, keep the
>> panicking intrinsic for it or somehow fix it in upstream Rust?
>
> The 64-bit division is particularly easy to introduce by accident
> on 32-bit architectures, so ending up in a panic here is clearly
> a problem. From the message above it appears that there is only
> a single calling function (parse_u64_into()) in the rust library,
> so I wonder if it might be sufficient to split that out into
> another object file that then doesn't need to get linked into
> the kernel, or for the kernel to override it with an implementation
> that does not rely on __aeabi_uldivmod() but calls __do_div64()
> instead.
I don't think that we can split it into a different object
file or do some weird redirect in Rust itself.
> Since parse_u64_into seems to be a parsing function that is
> expected to be slow, it should be acceptable to call __do_div64()
> here, while we still prevent calling __aeabi_uldivmod() from
> kernel source code.
`parse_u64_into` seems to be used by Formatting for u128
and i128 so it would be fine to disable these with a flag.
However `__aeabi_uldivmod` is used by some other parts of
core as well, like logarithm calculation for 64 and 128
bit integers, not sure what else uses is. I would guess
its fine for these to be slow.
Can someone help me figure out how to get ld.lld to print
every usage instead of just the first three?
Not sure how easy it would be to disable these but it
would probably require some effort and would probably
be pretty hacky, so not sure if Rust would accept these.
>
> Note that on earlier ARMv7 (Cortex-A8, A9), even a 32-bit
> division is implemented through an expensive software loop.
> Later cores (Cortex-A7, A15, A17) have native 32-bit division
> instructions but still no 64-bit ones.
I would assume that a software implementation is fine.
Cheers
Christian
next prev parent reply other threads:[~2025-01-31 23:42 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-23 22:40 [PATCH v3] arm: rust: Enable Rust support for ARMv7 Christian Schrefl
2025-01-30 23:10 ` Christian Schrefl
2025-01-31 7:40 ` Arnd Bergmann
2025-01-31 15:34 ` Christian Schrefl
2025-01-31 16:05 ` Andrew Lunn
2025-01-31 18:58 ` Christian Schrefl
2025-01-31 19:37 ` Arnd Bergmann
2025-01-31 23:42 ` Christian Schrefl [this message]
2025-02-01 0:58 ` Christian Schrefl
2025-02-02 16:57 ` Christian Schrefl
2025-02-01 0:03 ` Christian Schrefl
2025-02-05 13:12 ` Miguel Ojeda
2025-02-05 13:14 ` Alice Ryhl
2025-04-06 14:59 ` Miguel Ojeda
2025-01-31 19:18 ` Arnd Bergmann
2025-03-21 7:24 ` Linus Walleij
2025-04-05 20:05 ` Christian Schrefl
2025-04-06 14:08 ` Manish Shakya
2025-04-06 14:57 ` Miguel Ojeda
2025-04-06 21:17 ` Benno Lossin
2025-04-06 21:31 ` Miguel Ojeda
2025-04-13 21:10 ` Christian Schrefl
2025-04-13 21:31 ` Christian Schrefl
2025-04-06 21:48 ` Manish Shakya
-- strict thread matches above, loose matches on Subject: below --
2025-04-07 16:04 Benno Lossin
2025-04-07 17:35 ` Miguel Ojeda
2025-04-07 23:03 ` Manish Shakya
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=defddc25-eb8b-420a-b64c-6ce57ebb3f6b@gmail.com \
--to=chrisi.schrefl@gmail.com \
--cc=Jamie.Cunliffe@arm.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=andrew@lunn.ch \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=corbet@lwn.net \
--cc=gary@garyguo.net \
--cc=guptarud@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=stappers@stappers.nl \
--cc=thesven73@gmail.com \
--cc=tmgross@umich.edu \
/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