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] [day] [month] [year] [list]
Message-ID: <20241119080853.58cbca4f@gandalf.local.home>
Date: Tue, 19 Nov 2024 08:08:53 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@...il.com>,
 mingo@...hat.com, juri.lelli@...hat.com, vincent.guittot@...aro.org,
 linux-kernel@...r.kernel.org, dietmar.eggemann@....com, bsegall@...gle.com,
 mgorman@...e.de, vschneid@...hat.com
Subject: Re: [PATCH sched-next] sched/cputime: Fix unused value issue

On Tue, 19 Nov 2024 09:36:50 +0100
Peter Zijlstra <peterz@...radead.org> wrote:

> > The above adds more branches than just having:
> > 
> > 	if (stime == 0)
> > 		goto update;
> > 
> > 	if (utime == 0) {
> > 		stime = rtime;
> > 		goto update;
> > 	}
> > 
> > (or's "||" are branches)
> > 
> > And the latter is much easier to read!
> > 
> > Just fix the issue. Don't try to be clever about it.  
> 
> There is nothing to fix. Yes there is an unused assignment, but the
> compiler is free to elide it (and it does).

This has nothing to do with the compiler optimizing it.

> 
> Keep the code as is, it is simple and straight-forward.

I disagree from a stability and understandability point of view. Why is
utime assigned? Here's the full context:

	if (stime == 0) {
		utime = rtime;  <<<---- Assigns utime
		goto update;    <<<---- Jumps to "update"
	}

	if (utime == 0) {
		stime = rtime;
		goto update;
	}

	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.
	 */
	if (unlikely(stime > rtime))
		stime = rtime;

update:                           <<<---- Jumped here
	/*
	 * Make sure stime doesn't go backwards; this preserves monotonicity
	 * for utime because rtime is monotonic.
	 *
	 *  utime_i+1 = rtime_i+1 - stime_i
	 *            = rtime_i+1 - (rtime_i - utime_i)
	 *            = (rtime_i+1 - rtime_i) + utime_i
	 *            >= utime_i
	 */
	if (stime < prev->stime)
		stime = prev->stime;
	utime = rtime - stime;   <<<---- reassigns utime

So the first assignment of "utime" is meaningless, or there's a bug here
that utime incorrectly had its value overwritten. If the first assignment
is meaningless, it leaves others still wondering if there is actually a bug
here, because they are wondering "why was utime assigned?".

-- Steve



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ