mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Alexey Dobriyan' <adobriyan@gmail.com>
Cc: 'Matt Fleming' <matt@codeblueprint.co.uk>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Grimm, Jon" <Jon.Grimm@amd.com>,
	"Kumar, Venkataramanan" <Venkataramanan.Kumar@amd.com>,
	Jan Kara <jack@suse.cz>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: RE: [PATCH] x86/asm/64: Align start of __clear_user() loop to 16-bytes
Date: Thu, 18 Jun 2020 16:39:35 +0000	[thread overview]
Message-ID: <20b0166e11f44bf491062838090b93be@AcuMS.aculab.com> (raw)
In-Reply-To: <20200618131655.GA24607@localhost.localdomain>

From: Alexey Dobriyan 
> Sent: 18 June 2020 14:17
...
> > > diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
> > > index fff28c6f73a2..b0dfac3d3df7 100644
> > > --- a/arch/x86/lib/usercopy_64.c
> > > +++ b/arch/x86/lib/usercopy_64.c
> > > @@ -24,6 +24,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
> > >  	asm volatile(
> > >  		"	testq  %[size8],%[size8]\n"
> > >  		"	jz     4f\n"
> > > +		"	.align 16\n"
> > >  		"0:	movq $0,(%[dst])\n"
> > >  		"	addq   $8,%[dst]\n"
> > >  		"	decl %%ecx ; jnz   0b\n"
> >
> > You can do better that that loop.
> > Change 'dst' to point to the end of the buffer, negate the count
> > and divide by 8 and you get:
> > 		"0:	movq $0,($[dst],%%ecx,8)\n"
> > 		"	add $1,%%ecx"
> > 		"	jnz 0b\n"
> > which might run at one iteration per clock especially on cpu that pair
> > the add and jnz into a single uop.
> > (You need to use add not inc.)
> 
> /dev/zero should probably use REP STOSB etc just like everything else.

Almost certainly it shouldn't, and neither should anything else.
Potentially it could use whatever memset() is patched to.
That MIGHT be 'rep stos' on some cpu variants, but in general
it is slow.

	David

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

  reply	other threads:[~2020-06-18 16:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-18 10:20 Matt Fleming
2020-06-18 10:48 ` David Laight
2020-06-18 13:16   ` Alexey Dobriyan
2020-06-18 16:39     ` David Laight [this message]
2020-06-18 21:01       ` Alexey Dobriyan
2020-06-19 16:40 ` [tip: x86/urgent] " tip-bot2 for Matt Fleming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20b0166e11f44bf491062838090b93be@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=Jon.Grimm@amd.com \
    --cc=Venkataramanan.Kumar@amd.com \
    --cc=adobriyan@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®