The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] x86/fpu: Use vmemdup_user() in xstateregs_set()
Date: Tue, 4 Aug 2026 19:42:03 +0200	[thread overview]
Message-ID: <anIka22z_eGD65Tf@gmail.com> (raw)
In-Reply-To: <anG7EZ6rj5UrdVPx@linux.dev>


* Thorsten Blum <thorsten.blum@linux.dev> wrote:

> On Sun, Aug 02, 2026 at 03:20:59PM +0200, Ingo Molnar wrote:
> > * Thorsten Blum <thorsten.blum@linux.dev> wrote:
> > > > Replace the open-coded vmalloc() and copy_from_user() with
> > > > vmemdup_user() to simplify xstateregs_set().
> > > > 
> > > > vmemdup_user() returns an ERR_PTR() on failure, preserving the existing
> > > > -ENOMEM and -EFAULT error codes. Since vmemdup_user() is backed by
> > > > kvmalloc(), use kvfree() to free the buffer instead.
> > > > 
> > > > Return early on error and drop the obsolete out label.
> > 
> > > I've resent this cleanup a few times and haven't received feedback. Is
> > > this still something you would consider, or would you prefer that I drop
> > > it? It's intended to be a mechanical cleanup with no functional changes.
> > > 
> > > Happy to rerun the relevant x86 XSAVE selftests if it helps.
> > 
> > So the changelog is silent on any potential side-effects of this change.
> > vmalloc will return page-aligned addresses. kmalloc won't. Will this
> > have any effects on performance?
> > 
> > Are there other examples of vmalloc() -> kvmalloc() conversions in
> > the tree, is it a recommended and well-tested technique to simplify
> > the code?
> > 
> > A very quick git log investigation does not seem to be showing
> > any such recent conversion examples:
> > 
> >   starship:~/tip> git log -E --grep='kvmalloc' --since=one-year-ago | grep -w vmalloc
> > 
> > I'm not opposed to it in principle, I just think the 'analysis'
> > side of the patch description is basically non-existent.
> 
> Performance should be similar, and it's not a hot path.
> 
> Page alignment shouldn't matter because the buffer is only used as a
> memcpy() source in copy_uabi_from_kernel_to_xstate().
> 
> The main difference is that vmemdup_user() uses GFP_USER, which adds
> __GFP_HARDWALL and may change cpuset allocations.
> 
> The avx_64 selftests also pass on my Alder Lake CPU:
> 
>   [RUN]   AVX registers: check context switches, 10 iterations, 5 threads.
>   [OK]    No incorrect case was found.
>   [RUN]   AVX registers: inject xstate via ptrace().
>   [OK]    'xfeatures' in SW reserved area was correctly written
>   [OK]    xstate was correctly updated.
>   [RUN]   AVX registers: load xstate and raise SIGUSR1
>   [OK]    'magic1' is valid
>   [OK]    'xfeatures' in SW reserved area is valid
>   [OK]    'xfeatures' in XSAVE header is valid
>   [OK]    xstate delivery was successful
>   [OK]    'magic2' is valid
>   [RUN]   AVX registers: load new xstate from sighandler and check it after sigreturn
>   [OK]    xstate was restored correctly
>   # The kernel does not support feature number: 5
>   # The kernel does not support feature number: 6
>   # The kernel does not support feature number: 7

With this analysis included in the changelog I suppose it's
a worthwile simplification.

Thanks,

	Ingo


      reply	other threads:[~2026-08-04 17:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 19:55 [PATCH RESEND] x86/fpu: Use vmemdup_user() in xstateregs_set() Thorsten Blum
2026-08-02 12:47 ` Thorsten Blum
2026-08-02 13:20   ` Ingo Molnar
2026-08-04 10:12     ` Thorsten Blum
2026-08-04 17:42       ` Ingo Molnar [this message]

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=anIka22z_eGD65Tf@gmail.com \
    --to=mingo@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=thorsten.blum@linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox