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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Thu, 2 May 2013 15:10:33 +0200
From:	Peter Zijlstra <peterz@...radead.org>
To:	mingo@...nel.org, hpa@...or.com, linux-kernel@...r.kernel.org,
	dave@...1.net, fweisbec@...il.com, tglx@...utronix.de,
	sgruszka@...hat.com
Cc:	linux-tip-commits@...r.kernel.org
Subject: Re: [tip:sched/urgent] sched: Avoid cputime scaling overflow

> +	for (;;) {
> +		/* Make sure "rtime" is the bigger of stime/rtime */
> +		if (stime > rtime) {
> +			u64 tmp = rtime; rtime = stime; stime = tmp;

I keep forgetting to mention we have swap(rtime, stime); that does the above.

> +		}
> +
> +		/* Make sure 'total' fits in 32 bits */
> +		if (total >> 32)
> +			goto drop_precision;
> +
> +		/* Does rtime (and thus stime) fit in 32 bits? */
> +		if (!(rtime >> 32))
> +			break;
> +
> +		/* Can we just balance rtime/stime rather than dropping bits? */
> +		if (stime >> 31)
> +			goto drop_precision;
> +
> +		/* We can grow stime and shrink rtime and try to make them both fit */
> +		stime <<= 1;
> +		rtime >>= 1;
> +		continue;
> +
> +drop_precision:
> +		/* We drop from rtime, it has more bits than stime */
> +		rtime >>= 1;
> +		total >>= 1;
>  	}
>  
> +	/*
> +	 * Make sure gcc understands that this is a 32x32->64 multiply,
> +	 * followed by a 64/32->64 divide.
> +	 */
> +	scaled = div_u64((u64) (u32) stime * (u64) (u32) rtime, (u32)total);
>  	return (__force cputime_t) scaled;
>  }
>  
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ