From: Ingo Molnar <mingo@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mateusz Guzik <mjguzik@gmail.com>,
linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
bp@alien8.de
Subject: Re: [PATCH v2] x86: bring back rep movsq for user access on CPUs without ERMS
Date: Sun, 3 Sep 2023 23:48:31 +0200 [thread overview]
Message-ID: <ZPT/LzkPR/jaiaDb@gmail.com> (raw)
In-Reply-To: <CAHk-=wjYOZf2wPj_=arATJ==DQQAQwh0ki=Za0RcE542rWBGFw@mail.gmail.com>
* Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Sun, 3 Sept 2023 at 13:49, Mateusz Guzik <mjguzik@gmail.com> wrote:
> >
> > "real fstat" is syscall(5, fd, &sb).
> >
> > Sapphire Rapids, will-it-scale, ops/s
> >
> > stock fstat 5088199
> > patched fstat 7625244 (+49%)
> > real fstat 8540383 (+67% / +12%)
> >
> > It dodges lockref et al, but it does not dodge SMAP which accounts for
> > the difference.
>
> Side note, since I was looking at this, I hacked up a quick way for
> architectures to do their own optimized cp_new_stat() that avoids the
> double-buffering.
>
> Sadly it *is* architecture-specific due to padding and
> architecture-specific field sizes (and thus EOVERFLOW rules), but it
> is what it is.
>
> I don't know how much it matters, but it might make a difference. And
> 'stat()' is most certainly worth optimizing for, even if glibc has
> made our life more difficult.
>
> Want to try out another entirely untested patch? Attached.
>
> Linus
> arch/x86/kernel/sys_x86_64.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> fs/stat.c | 2 +-
> include/linux/stat.h | 2 ++
> 3 files changed, 47 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
> index c783aeb37dce..fca647f61bc1 100644
> --- a/arch/x86/kernel/sys_x86_64.c
> +++ b/arch/x86/kernel/sys_x86_64.c
> @@ -22,6 +22,50 @@
> #include <asm/elf.h>
> #include <asm/ia32.h>
>
> +int cp_new_stat(struct kstat *stat, struct stat __user *ubuf)
> +{
> + typeof(ubuf->st_uid) uid;
> + typeof(ubuf->st_gid) gid;
> + typeof(ubuf->st_dev) dev = new_encode_dev(stat->dev);
> + typeof(ubuf->st_rdev) rdev = new_encode_dev(stat->rdev);
> +
> + SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
> + SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
> +
> + if (!user_write_access_begin(ubuf, sizeof(struct stat)))
> + return -EFAULT;
> +
> + unsafe_put_user(dev, &ubuf->st_dev, Efault);
> + unsafe_put_user(stat->ino, &ubuf->st_ino, Efault);
> + unsafe_put_user(stat->nlink, &ubuf->st_nlink, Efault);
> +
> + unsafe_put_user(stat->mode, &ubuf->st_mode, Efault);
> + unsafe_put_user(uid, &ubuf->st_uid, Efault);
> + unsafe_put_user(gid, &ubuf->st_gid, Efault);
> + unsafe_put_user(0, &ubuf->__pad0, Efault);
> + unsafe_put_user(rdev, &ubuf->st_rdev, Efault);
> + unsafe_put_user(stat->size, &ubuf->st_size, Efault);
> + unsafe_put_user(stat->blksize, &ubuf->st_blksize, Efault);
> + unsafe_put_user(stat->blocks, &ubuf->st_blocks, Efault);
> +
> + unsafe_put_user(stat->atime.tv_sec, &ubuf->st_atime, Efault);
> + unsafe_put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec, Efault);
> + unsafe_put_user(stat->mtime.tv_sec, &ubuf->st_mtime, Efault);
> + unsafe_put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec, Efault);
> + unsafe_put_user(stat->ctime.tv_sec, &ubuf->st_ctime, Efault);
> + unsafe_put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec, Efault);
> + unsafe_put_user(0, &ubuf->__unused[0], Efault);
> + unsafe_put_user(0, &ubuf->__unused[1], Efault);
> + unsafe_put_user(0, &ubuf->__unused[2], Efault);
/me performs happy dance at seeing proper use of vertical alignment in
bulk-assignments.
If measurements support it then this looks like a nice optimization.
Thanks,
Ingo
next prev parent reply other threads:[~2023-09-03 21:48 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 14:03 [PATCH v2] x86: bring back rep movsq for user access on CPUs without ERMS Mateusz Guzik
2023-08-30 16:50 ` Linus Torvalds
2023-08-30 20:00 ` Linus Torvalds
2023-09-01 15:20 ` Mateusz Guzik
2023-09-01 15:29 ` Linus Torvalds
2023-09-03 18:49 ` Linus Torvalds
2023-09-03 19:14 ` Linus Torvalds
2023-09-03 20:08 ` Linus Torvalds
2023-09-03 20:48 ` Mateusz Guzik
2023-09-03 20:57 ` Linus Torvalds
2023-09-03 21:06 ` Mateusz Guzik
2023-09-03 21:08 ` Linus Torvalds
2023-09-03 21:18 ` Mateusz Guzik
2023-09-03 23:28 ` Al Viro
2023-09-03 20:58 ` Mateusz Guzik
2023-09-03 21:05 ` Linus Torvalds
2023-09-03 21:48 ` Ingo Molnar [this message]
2023-09-03 22:34 ` Linus Torvalds
2023-09-03 23:15 ` Mateusz Guzik
2023-09-04 3:07 ` Linus Torvalds
2023-09-04 3:17 ` Linus Torvalds
2023-09-04 6:03 ` Mateusz Guzik
2023-09-04 17:28 ` Linus Torvalds
2023-09-05 20:41 ` Mateusz Guzik
2023-09-06 0:16 ` Linus Torvalds
2023-09-06 4:11 ` Mateusz Guzik
2023-09-01 13:33 ` David Laight
2023-09-01 15:28 ` Mateusz Guzik
2023-09-03 20:42 ` David Laight
2023-09-10 10:53 ` Mateusz Guzik
2023-09-11 10:37 ` David Laight
2023-09-12 18:48 ` Linus Torvalds
2023-09-12 19:41 ` David Laight
2023-09-12 20:48 ` Linus Torvalds
2023-09-13 8:25 ` 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=ZPT/LzkPR/jaiaDb@gmail.com \
--to=mingo@kernel.org \
--cc=bp@alien8.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox