lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250616154801.0dc94c1f@pumpkin>
Date: Mon, 16 Jun 2025 15:48:01 +0100
From: David Laight <david.laight.linux@...il.com>
To: Vincent Guittot <vincent.guittot@...aro.org>
Cc: "Li,Rongqing" <lirongqing@...du.com>, "mingo@...hat.com"
 <mingo@...hat.com>, "peterz@...radead.org" <peterz@...radead.org>,
 "juri.lelli@...hat.com" <juri.lelli@...hat.com>, "dietmar.eggemann@....com"
 <dietmar.eggemann@....com>, "rostedt@...dmis.org" <rostedt@...dmis.org>,
 "bsegall@...gle.com" <bsegall@...gle.com>, "mgorman@...e.de"
 <mgorman@...e.de>, "vschneid@...hat.com" <vschneid@...hat.com>,
 "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] sched/cputime: Fix a mostly theoretical divide by zero

On Mon, 16 Jun 2025 14:51:56 +0200
Vincent Guittot <vincent.guittot@...aro.org> wrote:

> On Mon, 16 Jun 2025 at 13:46, Li,Rongqing <lirongqing@...du.com> wrote:
> >  
> > >
> > > Sum of utime and stime can overflow to 0, when a process with many threads
> > > run over total 2^64 ns  
> 
> Theoretical is the right word; If all 2^32 possible threads belong to
> the process, we can get an overflow to 0 after ~4sec run time of each
> thread. But then how long will it take to have those 2^32 threads run
> 4sec on a system ...
> 
> It would be good to get number to show how realistic or not it could
> be to reach this value

I did wonder when re-writing mul_u64_u64_div_u64() how common this path
is and whether both stime and utime could be zero.

The current mul_u64_u64_div_u64() is particularly horrid on 32bit.
(Note that it no longer generates an approximate result.)
On 32bit x86 the worst case (lots of 1 bits in the result) is ~900 clocks,
my new version takes ~130 for pretty much all (large) values.

That is in userspace with cmov, without cmov it will be worse.
I also think the kernel has one less register to play with - %epb.

Other architectures are likely to be worse, sh[rl]d makes double
length shifts less painful - especially when combined with cmov.

See: https://www.spinics.net/lists/kernel/msg5723178.html

	David


> 
> > >
> > > Signed-off-by: Li RongQing <lirongqing@...du.com>  
> >
> >
> > Ping
> >
> > Thanks
> >
> > -Li
> >  
> > > ---
> > >  kernel/sched/cputime.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index
> > > 6dab4854..c35fc4c 100644
> > > --- a/kernel/sched/cputime.c
> > > +++ b/kernel/sched/cputime.c
> > > @@ -579,7 +579,8 @@ void cputime_adjust(struct task_cputime *curr, struct
> > > prev_cputime *prev,
> > >               goto update;
> > >       }
> > >
> > > -     stime = mul_u64_u64_div_u64(stime, rtime, stime + utime);
> > > +     if (likely(stime + utime))
> > > +             stime = mul_u64_u64_div_u64(stime, rtime, stime + utime);
> > >       /*
> > >        * Because mul_u64_u64_div_u64() can approximate on some
> > >        * achitectures; enforce the constraint that: a*b/(b+c) <= a.
> > > --
> > > 2.9.4  
> >  
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ