Messages in this thread | | | Date | Tue, 14 May 2024 06:12:53 -0700 | From | Boqun Feng <> | Subject | Re: [PATCH 2/2] rust: time: Use wrapping_sub() for Ktime::sub() |
| |
On Mon, May 13, 2024 at 05:04:43PM +0200, Miguel Ojeda wrote: > On Thu, May 9, 2024 at 2:14 PM Thomas Gleixner <tglx@linutronix.de> wrote: > > > > In principle ktime_sub() should not overflow for regular use cases. > > > > If the binder example overflows the substraction, then something is > > seriously wrong. Though in that case as it's only for debug purposes > > panicing would be totally counter productive. A warning might be > > appropriate though. > > Thanks for the clarification Thomas. > > Alice and I pinged about this in the RustNL Unconf, i.e. about having > a way to customize what happens on integer overflow (and, in general, > other panics too), which I had in: > > https://github.com/Rust-for-Linux/linux/issues/354 > > e.g. like UBSan that allows a "report and continue" option. > > We chatted with Mara and Amanieu, who were receptive. In particular, > Mara posted right away: > > https://github.com/rust-lang/rfcs/pull/3632 > > as a possible first step to eventually have that ability, mentioning > Rust for Linux as a user. > > If we get the ability to customize those, then this could simply be a > normal arithmetic operation, i.e. like any other. That is, considered > to be a bug if it overflows. >
That is nice to have, thank you guys!
> Meanwhile, one alternative is going with Boqun's approach, but I would > just use the standard operator (i.e. what we do elsewhere) and try to > get the customization happen as soon as possible since we will need it > for everything else (plus we avoid to make the code uglier with > changes that we will need to revert anyway; and it also allows us to > easily test any new customization feature from the compiler/library). >
However, I must point out that it needs more than a customized panic handler to work: we also need to change the code generation (or adding a different flag similar to -Coverflow-checks), because the current code generation is Rust panic when overflow happens, which means the subsequent code is unreachable.
Regards, Boqun
> Cheers, > Miguel
| |