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: <333d84d215c44589840e18cec9108fb0@AcuMS.aculab.com>
Date: Sun, 10 Mar 2024 19:21:32 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Alexey Dobriyan' <adobriyan@...il.com>, Greg Kroah-Hartman
	<gregkh@...uxfoundation.org>
CC: "Rafael J. Wysocki" <rafael@...nel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>
Subject: RE: [PATCH] sysfs: make sysfs_emit() return ssize_t

From: Alexey Dobriyan
> Sent: 08 March 2024 06:26
> 
> On Thu, Mar 07, 2024 at 10:04:41PM +0000, Greg Kroah-Hartman wrote:
> > On Mon, Feb 05, 2024 at 01:11:36PM +0300, Alexey Dobriyan wrote:
> > > sysfs_emit() is most often found in functions returning ssize_t
> > > not int:
> > >
> > > 	static ssize_t oops_count_show(...)
> > > 	{
> > > 		return sysfs_emit(page, ...);
> > > 	}
> > >
> > > This pattern results in sign-extension instruction between
> > > sysfs_emit() return value (int) and caller return value (which is
> > > ssize_t).
> >
> > Is that a problem?
> 
> Small problem, but, yes.
> 
> If sysfs_emit() returns "int", then every user compiles to
> 
> 	call	sysfs_emit
> 	movsx	rax, eax
> 	ret
> 
> Given than sysfs_emit() is the official way to print in sysfs,
> there are lots of users and there will be more users in the future
> as it grows.
> 
> This trailing "movsx" instruction is duplicated every time.

Actually you are missing a tail call...
But no one will notice the extra execution time, it will
be masked by the cost of the formatting.
So it is a small amount of I-cache.

In reality the best fix is not to use ssize_t for something
where the domain of the value is much smaller.
In this case it is probably unsigned as well.

Efficient calling conventions for 64bit code probably require
all non-negative types be passed/returned as 'unsigned long' and
then copied to an 'unsigned int' to get better code generation.
Signed values are much more difficult though.
But unless you are trying to get that last extra clock there
are likely to be much lower hanging fruit.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ