[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZkIeW_NgXFYsAx5M@boqun-archlinux>
Date: Mon, 13 May 2024 07:06:19 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: Miguel Ojeda <ojeda@...nel.org>, John Stultz <jstultz@...gle.com>,
Stephen Boyd <sboyd@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Gary Guo <gary@...yguo.net>, bjorn3_gh@...tonmail.com,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...sung.com>,
Alice Ryhl <aliceryhl@...gle.com>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, Kees Cook <keescook@...omium.org>
Subject: Re: [PATCH 2/2] rust: time: Use wrapping_sub() for Ktime::sub()
On Thu, May 09, 2024 at 02:14:16PM +0200, Thomas Gleixner wrote:
> On Tue, Apr 23 2024 at 14:11, Boqun Feng wrote:
> > On Thu, Apr 11, 2024 at 04:08:01PM -0700, Boqun Feng wrote:
> >> Currently since Rust code is compiled with "-Coverflow-checks=y", so a
> >> normal substraction may be compiled as an overflow checking and panic
> >> if overflow happens:
> >>
> >> subq %rsi, %rdi
> >> jo .LBB0_2
> >> movq %rdi, %rax
> >> retq
> >> .LBB0_2:
> >> pushq %rax
> >> leaq str.0(%rip), %rdi
> >> leaq .L__unnamed_1(%rip), %rdx
> >> movl $33, %esi
> >> callq *core::panicking::panic::h59297120e85ea178@...PCREL(%rip)
> >>
> >> although overflow detection is nice to have, however this makes
> >> `Ktime::sub()` behave differently than `ktime_sub()`, moreover it's not
> >> clear that the overflow checking is helpful, since for example, the
> >> current binder usage[1] doesn't have the checking.
> >
> > Ping. Thomas, John and Stepthen. Could you take a look at this, and the
> > discussion between Miguel and me? The key question is the behavior when
> > ktime_sub() hits a overflow, I think. Thanks!
>
> 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! Looks to me, a reasonable implementation would be calling
`overflowing_sub`[1] and print a warning if overflow happens:
<in the implementation of Sub trait of Ktime>
let (ret, overflow) = self.inner.overflowing_sub(other.inner);
if overflow {
pr_err!("Overflow on Ktime: {} - {}\n", self.inner, other.inner);
}
return ret;
I will use this as a new version for more reviews.
[1]: https://doc.rust-lang.org/std/primitive.i64.html#method.overflowing_sub
Regards,
Boqun
> Thanks,
>
> tglx
>
>
Powered by blists - more mailing lists