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: <20250722230341.5a1cc5e5@pumpkin>
Date: Tue, 22 Jul 2025 23:03:41 +0100
From: David Laight <david.laight.linux@...il.com>
To: Oleg Nesterov <oleg@...hat.com>
Cc: Ingo Molnar <mingo@...hat.com>, Peter Zijlstra <peterz@...radead.org>,
 Thomas Gleixner <tglx@...utronix.de>, Borislav Petkov <bp@...en8.de>, Dave
 Hansen <dave.hansen@...ux.intel.com>, "H. Peter Anvin" <hpa@...or.com>,
 "Li,Rongqing" <lirongqing@...du.com>, Steven Rostedt <rostedt@...dmis.org>,
 linux-kernel@...r.kernel.org, x86@...nel.org
Subject: Re: [PATCH] x86/math64: handle #DE in mul_u64_u64_div_u64()

On Tue, 22 Jul 2025 15:21:48 +0200
Oleg Nesterov <oleg@...hat.com> wrote:

> On 07/22, David Laight wrote:
> >
> > On Tue, 22 Jul 2025 12:50:35 +0200
> > Oleg Nesterov <oleg@...hat.com> wrote:
> >  
> > > 	static inline u64 mul_u64_u64_div_u64(u64 a, u64 mul, u64 div)
> > > 	{
> > > 		char ok = 0;
> > > 		u64 q;
> > >
> > > 		asm ("mulq %3; 1: divq %4; movb $1,%1; 2:\n"
> > > 			_ASM_EXTABLE(1b, 2b)
> > > 			: "=a" (q), "+r" (ok)  
> >
> > That needs to be "+q" (ok)  
> 
> Thanks... I will never understand the asm constraints.

I'm not sure I understand all of them.
But the previous version wouldn't compile.

> 
> > > 		if (ok)
> > > 			return q;
> > > 		BUG_ON(!div);
> > > 		WARN_ON_ONCE(1);  
> >
> > I know there are are a lot of WARN_ON_ONCE(1) out there,
> > but maybe WARN_ON_ONCE("muldiv overflow") would be better?
> > (The linker will merge the strings).  
> 
> OK. If you are fine with this version I'll send V2.
> 
> 	/*
> 	 * Returns ULONG_MAX when the result doesn't fit u64.
> 	 */
> 	static inline u64 mul_u64_u64_div_u64(u64 a, u64 mul, u64 div)
> 	{
> 		char ok = 0;
> 		u64 q;
> 
> 		asm ("mulq %3; 1: divq %4; movb $1,%1; 2:\n"
> 			_ASM_EXTABLE(1b, 2b)
> 			: "=a" (q), "+q" (ok)
> 			: "a" (a), "rm" (mul), "rm" (div)
> 			: "rdx");
> 
> 		if (ok)
> 			return q;
> 		BUG_ON(!div);
> 		WARN_ONCE(1, "muldiv overflow.\n");

I wonder what WARN_ON_ONCE("muldiv overflow") outputs?

Actually, without the BUG or WARN you want:
	u64 fail = ~(u64)0;
then
	incq $1 ... "+r" (fail)
and finally
	return q | fail;
to remove the conditional branches from the normal path
(apart from one the caller might do)

	David

> 		return ~(u64)0;
> 	}
> 
> Oleg.
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ