All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Herton R. Krzesinski" <herton@redhat.com>,
	x86@kernel.org, tglx@linutronix.de, mingo@redhat.com,
	bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
	linux-kernel@vger.kernel.org, olichtne@redhat.com,
	atomasov@redhat.com, aokuliar@redhat.com
Subject: Re: [PATCH] x86: add back the alignment of the destination to 8 bytes in copy_user_generic()
Date: Mon, 17 Mar 2025 13:16:23 +0000	[thread overview]
Message-ID: <20250317131623.2cc15ada@pumpkin> (raw)
In-Reply-To: <CAHk-=wj2MhDH_zjnyrUhYUf3ZqokC-jKSeRp9G6GnhwFU9z+Hg@mail.gmail.com>

On Fri, 14 Mar 2025 09:06:13 -1000
Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Fri, 14 Mar 2025 at 07:53, Herton R. Krzesinski <herton@redhat.com> wrote:
> >
> > --- a/arch/x86/include/asm/uaccess_64.h
> > +++ b/arch/x86/include/asm/uaccess_64.h
> > @@ -130,7 +130,7 @@ copy_user_generic(void *to, const void *from, unsigned long len)
> >                 "2:\n"
> >                 _ASM_EXTABLE_UA(1b, 2b)
> >                 :"+c" (len), "+D" (to), "+S" (from), ASM_CALL_CONSTRAINT
> > -               : : "memory", "rax");
> > +               : : "memory", "rax", "rdx", "r8");  
> 
> Please don't penalize the caller with the extra clobbers.
> 
> Maybe it doesn't matter - these functions are marked always_inline,
> but they aren't inlined in very many places and maybe those places
> have registers to spare - but let's not penalize the FSRM case anyway.
> 
> And we do call it "rep_movs_alternative", so let's keep it close to
> "rep movs" semantics (yes, we already clobber %rax, but let's not make
> it worse).
> 
> As to the actual change to rep_movs - that should be done differently
> too. In particular, I doubt it makes any sense to try to align the
> destination for small writes or for the ERMS case when we use 'rep
> movsb', so I think this should all go into just the ".Llarge_movsq"
> case.

The Intel cpu (sandy bridge onwards) execute 'rep mosvb' twice as
fast if the destination is 32 byte aligned.
Potentially this is worth optimising for - but the cost of the extra
code may exceed the benefit.

> .. and then the patch can be further optimized to just do the first -
> possibly unaligned - destination word unconditionally, and then
> updating the addresses and counts to make the rest be aligned.

You can also something similar for any trailing bytes.
If you are feeling 'brave' copy the last 8 bytes first.

	David

  parent reply	other threads:[~2025-03-17 13:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14 17:53 Performance issues in copy_user_generic() in x86_64 Herton R. Krzesinski
2025-03-14 17:53 ` [PATCH] x86: add back the alignment of the destination to 8 bytes in copy_user_generic() Herton R. Krzesinski
2025-03-14 19:06   ` Linus Torvalds
2025-03-14 20:33     ` Herton Krzesinski
2025-03-16 10:58       ` Ingo Molnar
2025-03-16 11:09         ` Ingo Molnar
2025-03-17 13:18           ` Herton Krzesinski
2025-03-18 21:59           ` David Laight
2025-03-18 22:50             ` Herton Krzesinski
2025-03-19 13:07               ` David Laight
2025-03-17 13:16     ` David Laight [this message]
2025-03-17 21:29       ` Linus Torvalds
2025-03-17 22:32         ` David Laight

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=20250317131623.2cc15ada@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=aokuliar@redhat.com \
    --cc=atomasov@redhat.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=herton@redhat.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=olichtne@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.