mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: 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>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] x86/fpu: Use vmemdup_user() in xstateregs_set()
Date: Mon, 31 Aug 2026 11:57:55 +0200	[thread overview]
Message-ID: <apVQI4em8hdBZPAl@linux.dev> (raw)
In-Reply-To: <20260805140346.149561-2-thorsten.blum@linux.dev>

On Wed, Aug 05, 2026 at 04:03:45PM +0200, Thorsten Blum 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.
> 
> Performance should be similar, and xstateregs_set() is not a hot path.
> Page alignment should not matter because the buffer is only used as a
> memcpy() source in copy_uabi_from_kernel_to_xstate().
> 
> The allocation behavior differs because vmemdup_user() uses GFP_USER,
> which adds __GFP_HARDWALL and may affect cpuset allocations.
> 
> tools/testing/selftests/x86/avx_64 passed on an Alder Lake CPU.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> Changes in v2:
> - Add performance analysis and selftest result to the changelog (Ingo)
> - v1: https://lore.kernel.org/r/20260720195534.70111-3-thorsten.blum@linux.dev/
> ---
>  arch/x86/kernel/fpu/regset.c | 17 ++++++-----------
>  1 file changed, 6 insertions(+), 11 deletions(-)

Hi Ingo,

Could you please give this another look now that I've added the
performance analysis to the changelog? Is there anything else missing?

Thanks,
Thorsten

> diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset.c
> index 0986c2200adc..8dc9de732c78 100644
> --- a/arch/x86/kernel/fpu/regset.c
> +++ b/arch/x86/kernel/fpu/regset.c
> @@ -3,7 +3,8 @@
>   * FPU register's regset abstraction, for ptrace, core dumps, etc.
>   */
>  #include <linux/sched/task_stack.h>
> -#include <linux/vmalloc.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
>  
>  #include <asm/fpu/api.h>
>  #include <asm/fpu/signal.h>
> @@ -157,21 +158,15 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
>  		return -EFAULT;
>  
>  	if (!kbuf) {
> -		tmpbuf = vmalloc(count);
> -		if (!tmpbuf)
> -			return -ENOMEM;
> -
> -		if (copy_from_user(tmpbuf, ubuf, count)) {
> -			ret = -EFAULT;
> -			goto out;
> -		}
> +		tmpbuf = vmemdup_user(ubuf, count);
> +		if (IS_ERR(tmpbuf))
> +			return PTR_ERR(tmpbuf);
>  	}
>  
>  	fpu_force_restore(fpu);
>  	ret = copy_uabi_from_kernel_to_xstate(fpu->fpstate, kbuf ?: tmpbuf, &target->thread.pkru);
>  
> -out:
> -	vfree(tmpbuf);
> +	kvfree(tmpbuf);
>  	return ret;
>  }
>  

      reply	other threads:[~2026-08-31  9:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 14:03 Thorsten Blum
2026-08-31  9:57 ` Thorsten Blum [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=apVQI4em8hdBZPAl@linux.dev \
    --to=thorsten.blum@linux.dev \
    --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=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

all inboxes | Powered by JetHome®