From nobody Sat Oct 4 15:55:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36C522BF009 for ; Thu, 14 Aug 2025 10:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166541; cv=none; b=sqLuz0G/+Z2nlc63/kb+qzM+J10Vz92V39/fA74rzLELfYw3xMoehpGYB0k/KCKDWvlcBMpqL52t4v09bUIt9wuUxsllE3ij6HgM34q/Z8zQGFGPkZCf4Td3l41PvG+Ylfpq3hKcQRV/HNDSnCdTHixb4MQU/SNozHXchh/3S6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166541; c=relaxed/simple; bh=lDGy6jHs+vuuTEUpjz4ACNHrl6wiJe/Q7+nM7ZD2nQ4=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=qY5WYtsG4laWU+l3Cec+lDdlT8HnwQpDDHcDs0dNNFnc6IhbDEFPaTpSGj7qBGz1fPjkNy74akfV8PtFoYE2+KGQa5hJg+owEBwxjBCTC8BGwVBNgon1Qpw6QeYSJ/5QZucgzsRMouMSr0u6zJeHdwMmgfY4Rhg0dOyXRg9nckU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Fk0cNVCH; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Fk0cNVCH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755166536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=mi40gkloI3WzbXMRLyBw5TNSNsrPISTg/pT33snPr9k=; b=Fk0cNVCH/hw8V9htqqZWaYGR/63o4i3Teh0xcJXx5npwHBiShRPmGnk/jPS9giTlokAk2a uD8bSrDX/eOaExzVdZJSKUuNBFPxNfjF+6cYhnx3K30qSM65FEa/0KKjUWMt+Kn4DS7vub M6dpWSq3WhwjFGw2e0m175anMbg/nJI= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-533-DOt6xThKOJSRkApuNgzTkQ-1; Thu, 14 Aug 2025 06:15:35 -0400 X-MC-Unique: DOt6xThKOJSRkApuNgzTkQ-1 X-Mimecast-MFC-AGG-ID: DOt6xThKOJSRkApuNgzTkQ_1755166533 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EA57619775A5; Thu, 14 Aug 2025 10:15:32 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.62]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 4E669300019F; Thu, 14 Aug 2025 10:15:28 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 14 Aug 2025 12:14:17 +0200 (CEST) Date: Thu, 14 Aug 2025 12:14:11 +0200 From: Oleg Nesterov To: Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Jens Axboe , Peter Zijlstra , Rick Edgecombe , Sohil Mehta , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH 1/6] x86/fpu: change copy_xstate_to_uabi_buf() to accept fpstate + pkru instead of task_struct Message-ID: <20250814101411.GA17341@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250814101340.GA17288@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Preparation for the next change. Signed-off-by: Oleg Nesterov --- arch/x86/kernel/fpu/regset.c | 10 ++++++---- arch/x86/kernel/fpu/xstate.c | 12 ++++++------ arch/x86/kernel/fpu/xstate.h | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset.c index 0986c2200adc..d280d415b171 100644 --- a/arch/x86/kernel/fpu/regset.c +++ b/arch/x86/kernel/fpu/regset.c @@ -83,7 +83,7 @@ int xfpregs_get(struct task_struct *target, const struct = user_regset *regset, sizeof(fpu->fpstate->regs.fxsave)); } =20 - copy_xstate_to_uabi_buf(to, target, XSTATE_COPY_FX); + copy_xstate_to_uabi_buf(to, fpu->fpstate, target->thread.pkru, XSTATE_COP= Y_FX); return 0; } =20 @@ -130,12 +130,14 @@ int xfpregs_set(struct task_struct *target, const str= uct user_regset *regset, int xstateregs_get(struct task_struct *target, const struct user_regset *r= egset, struct membuf to) { + struct fpu *fpu =3D x86_task_fpu(target); + if (!cpu_feature_enabled(X86_FEATURE_XSAVE)) return -ENODEV; =20 - sync_fpstate(x86_task_fpu(target)); + sync_fpstate(fpu); =20 - copy_xstate_to_uabi_buf(to, target, XSTATE_COPY_XSAVE); + copy_xstate_to_uabi_buf(to, fpu->fpstate, target->thread.pkru, XSTATE_COP= Y_XSAVE); return 0; } =20 @@ -419,7 +421,7 @@ int fpregs_get(struct task_struct *target, const struct= user_regset *regset, struct membuf mb =3D { .p =3D &fxsave, .left =3D sizeof(fxsave) }; =20 /* Handle init state optimized xstate correctly */ - copy_xstate_to_uabi_buf(mb, target, XSTATE_COPY_FP); + copy_xstate_to_uabi_buf(mb, fpu->fpstate, target->thread.pkru, XSTATE_CO= PY_FP); fx =3D &fxsave; } else { fx =3D &fpu->fpstate->regs.fxsave; diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 12ed75c1b567..2bd5974d5f0e 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1256,7 +1256,8 @@ void __copy_xstate_to_uabi_buf(struct membuf to, stru= ct fpstate *fpstate, /** * copy_xstate_to_uabi_buf - Copy kernel saved xstate to a UABI buffer * @to: membuf descriptor - * @tsk: The task from which to copy the saved xstate + * @fpstate: The fpstate buffer from which to copy + * @pkru_val: The PKRU value to store in the PKRU component * @copy_mode: The requested copy mode * * Converts from kernel XSAVE or XSAVES compacted format to UABI conforming @@ -1265,12 +1266,11 @@ void __copy_xstate_to_uabi_buf(struct membuf to, st= ruct fpstate *fpstate, * * It supports partial copy but @to.pos always starts from zero. */ -void copy_xstate_to_uabi_buf(struct membuf to, struct task_struct *tsk, - enum xstate_copy_mode copy_mode) +void copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate, + u32 pkru_val, enum xstate_copy_mode copy_mode) { - __copy_xstate_to_uabi_buf(to, x86_task_fpu(tsk)->fpstate, - x86_task_fpu(tsk)->fpstate->user_xfeatures, - tsk->thread.pkru, copy_mode); + __copy_xstate_to_uabi_buf(to, fpstate, fpstate->user_xfeatures, + pkru_val, copy_mode); } =20 static int copy_from_buffer(void *dst, unsigned int offset, unsigned int s= ize, diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h index 52ce19289989..9d76ded84cdd 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -46,8 +46,8 @@ struct membuf; extern void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fp= state, u64 xfeatures, u32 pkru_val, enum xstate_copy_mode copy_mode); -extern void copy_xstate_to_uabi_buf(struct membuf to, struct task_struct *= tsk, - enum xstate_copy_mode mode); +extern void copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpst= ate, + u32 pkru_val, enum xstate_copy_mode copy_mode); extern int copy_uabi_from_kernel_to_xstate(struct fpstate *fpstate, const = void *kbuf, u32 *pkru); extern int copy_sigframe_from_user_to_xstate(struct task_struct *tsk, cons= t void __user *ubuf); =20 --=20 2.25.1.362.g51ebf55 From nobody Sat Oct 4 15:55:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CC7D2F39CF for ; Thu, 14 Aug 2025 10:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166549; cv=none; b=si05ZP1hUni04bEEEKe9boAe5KC4P+sWYJPXpreNLRhRsquX1QNUqrgwLVA/QDGZqW2/vHMa71tCk3kyywVs+AxiYlq7SVrd3iV1HRNsJjpksM/ICY2p56c2g+38wp7/s3sv5Iynqi8+PjKHhx7GtDgT+Oqgb17itw/jV0FhTbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166549; c=relaxed/simple; bh=3rig9o0mKKdZLmjoLPG8hkOvBttTRwc/0hPS8s3NewQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=aMyhEHmSFyq5OoSlrm8jt6Y/Bm2J2y8rMTit75XC76PKnx2jG7Ev/y9ImzAq25GDksA3ma8FpF/6Jkc1ET22wdvbR2BIIFfKFknoTn/greDIy9Ewce8Z6pqHvW8cCTq3oU8iRTQWKL405mn5TZrwBlAAWhETOF80PptnchYixJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dR7cdcTe; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dR7cdcTe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755166546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=oIM+QpfetU8Xpz9SmqBoW9/2mND86Ux35Wm3WP2cxcY=; b=dR7cdcTeuvZZ6ath6+GEyiO1Q8bXrVzD2pdcGnYgU/qpJG0xpOTLaqxbB4tZe7ngSZUHmZ 1DtdsAMjkRj1Fvt4q79VNuLkH6RGd4CvcJRbBySmi+F9yJxJcE3HOimHCcZSPG7KtfVM4G agU5iLX/QWYb31cGK+uyNdd2hHMTrtY= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-61-GXEuGU2QOcCvFWNzSOkkuQ-1; Thu, 14 Aug 2025 06:15:41 -0400 X-MC-Unique: GXEuGU2QOcCvFWNzSOkkuQ-1 X-Mimecast-MFC-AGG-ID: GXEuGU2QOcCvFWNzSOkkuQ_1755166539 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1975D1955BE4; Thu, 14 Aug 2025 10:15:39 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.62]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id AD07E1800447; Thu, 14 Aug 2025 10:15:35 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 14 Aug 2025 12:14:23 +0200 (CEST) Date: Thu, 14 Aug 2025 12:14:18 +0200 From: Oleg Nesterov To: Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Jens Axboe , Peter Zijlstra , Rick Edgecombe , Sohil Mehta , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH 2/6] x86/fpu: regset: introduce get_fpstate() helper Message-ID: <20250814101418.GA17349@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250814101340.GA17288@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After the previous change the regset get() functions do not really need "struct fpu *", they can use "struct fpstate *" returned by the new helper which also does sync_fpstate(). Signed-off-by: Oleg Nesterov --- arch/x86/kernel/fpu/regset.c | 42 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset.c index d280d415b171..f5a803774e1c 100644 --- a/arch/x86/kernel/fpu/regset.c +++ b/arch/x86/kernel/fpu/regset.c @@ -49,6 +49,13 @@ static void sync_fpstate(struct fpu *fpu) fpu_sync_fpstate(fpu); } =20 +static struct fpstate *get_fpstate(struct task_struct *task) +{ + struct fpu *fpu =3D x86_task_fpu(task); + sync_fpstate(fpu); + return fpu->fpstate; +} + /* * Invalidate cached FPU registers before modifying the stopped target * task's fpstate. @@ -71,19 +78,19 @@ static void fpu_force_restore(struct fpu *fpu) int xfpregs_get(struct task_struct *target, const struct user_regset *regs= et, struct membuf to) { - struct fpu *fpu =3D x86_task_fpu(target); + struct fpstate *fpstate; =20 if (!cpu_feature_enabled(X86_FEATURE_FXSR)) return -ENODEV; =20 - sync_fpstate(fpu); + fpstate =3D get_fpstate(target); =20 if (!use_xsave()) { - return membuf_write(&to, &fpu->fpstate->regs.fxsave, - sizeof(fpu->fpstate->regs.fxsave)); + return membuf_write(&to, &fpstate->regs.fxsave, + sizeof(fpstate->regs.fxsave)); } =20 - copy_xstate_to_uabi_buf(to, fpu->fpstate, target->thread.pkru, XSTATE_COP= Y_FX); + copy_xstate_to_uabi_buf(to, fpstate, target->thread.pkru, XSTATE_COPY_FX); return 0; } =20 @@ -130,14 +137,13 @@ int xfpregs_set(struct task_struct *target, const str= uct user_regset *regset, int xstateregs_get(struct task_struct *target, const struct user_regset *r= egset, struct membuf to) { - struct fpu *fpu =3D x86_task_fpu(target); + struct fpstate *fpstate; =20 if (!cpu_feature_enabled(X86_FEATURE_XSAVE)) return -ENODEV; =20 - sync_fpstate(fpu); - - copy_xstate_to_uabi_buf(to, fpu->fpstate, target->thread.pkru, XSTATE_COP= Y_XSAVE); + fpstate =3D get_fpstate(target); + copy_xstate_to_uabi_buf(to, fpstate, target->thread.pkru, XSTATE_COPY_XSA= VE); return 0; } =20 @@ -189,15 +195,15 @@ int ssp_active(struct task_struct *target, const stru= ct user_regset *regset) int ssp_get(struct task_struct *target, const struct user_regset *regset, struct membuf to) { - struct fpu *fpu =3D x86_task_fpu(target); + struct fpstate *fpstate; struct cet_user_state *cetregs; =20 if (!cpu_feature_enabled(X86_FEATURE_USER_SHSTK) || !ssp_active(target, regset)) return -ENODEV; =20 - sync_fpstate(fpu); - cetregs =3D get_xsave_addr(&fpu->fpstate->regs.xsave, XFEATURE_CET_USER); + fpstate =3D get_fpstate(target); + cetregs =3D get_xsave_addr(&fpstate->regs.xsave, XFEATURE_CET_USER); if (WARN_ON(!cetregs)) { /* * This shouldn't ever be NULL because shadow stack was @@ -403,17 +409,17 @@ void convert_to_fxsr(struct fxregs_state *fxsave, int fpregs_get(struct task_struct *target, const struct user_regset *regse= t, struct membuf to) { - struct fpu *fpu =3D x86_task_fpu(target); + struct fpstate *fpstate; struct user_i387_ia32_struct env; struct fxregs_state fxsave, *fx; =20 - sync_fpstate(fpu); - if (!cpu_feature_enabled(X86_FEATURE_FPU)) return fpregs_soft_get(target, regset, to); =20 + fpstate =3D get_fpstate(target); + if (!cpu_feature_enabled(X86_FEATURE_FXSR)) { - return membuf_write(&to, &fpu->fpstate->regs.fsave, + return membuf_write(&to, &fpstate->regs.fsave, sizeof(struct fregs_state)); } =20 @@ -421,10 +427,10 @@ int fpregs_get(struct task_struct *target, const stru= ct user_regset *regset, struct membuf mb =3D { .p =3D &fxsave, .left =3D sizeof(fxsave) }; =20 /* Handle init state optimized xstate correctly */ - copy_xstate_to_uabi_buf(mb, fpu->fpstate, target->thread.pkru, XSTATE_CO= PY_FP); + copy_xstate_to_uabi_buf(mb, fpstate, target->thread.pkru, XSTATE_COPY_FP= ); fx =3D &fxsave; } else { - fx =3D &fpu->fpstate->regs.fxsave; + fx =3D &fpstate->regs.fxsave; } =20 __convert_from_fxsr(&env, target, fx); --=20 2.25.1.362.g51ebf55 From nobody Sat Oct 4 15:55:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDDB02FD1A9 for ; Thu, 14 Aug 2025 10:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166553; cv=none; b=Y0viLsvuQSR3xLnGUrGSmJiHXkvZJ9UBsJvrZachWM3magLjFW13J65NS6nz7no3Qskr4hhcTMKi2rVeeDmK3k/OZdZ8dPztc7xrsoHIu9ML9z5CBaT1hFYqRnmrI/trHkjbqqBGe7BD1g69gsikLEVUQKXcqpA/qJqN11Gju6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166553; c=relaxed/simple; bh=cRBDZ0V4M7USIfEXDXK1MhDoXCarJ9SLFjiHd+H031I=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=uFDw5fOh7V1d4dwIWJ5lMutD1C73K9t1SXWZQ30CB5pk5t13wdKhiWWX566lRP6GfCSE1Z9ew9YRgxMZsw80GBYB5DirSQ1U20JJI9Vz9t8nGz2NZ3VW+HY96acakgXBmePeK1R6nhiAYbvx3fpsVYe2GJ1BRzqCZm2F0lO8bKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Re+8Un1u; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Re+8Un1u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755166550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=I9OqGrWe4bFx0j7k4ZODRtHJTXRM3rkKeIqs4AxHQOM=; b=Re+8Un1uavvoxM03r7GSt7LpX+/we2HZIsFnFznKvLewGoJ0WNK7lKme5rV4myoxg/nJ+4 lPysfAZR4IAbQpSsCBPvhyyTxGCNXcFz1BrUkBrhKxif5yDyGlV3DVtJxID8BJlFVGNvUg ZbXxzOKEAUjRQzG0BLD9B6qct6YnVSw= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-39-DoHpBq0pPJau2EwjgYIjQw-1; Thu, 14 Aug 2025 06:15:46 -0400 X-MC-Unique: DoHpBq0pPJau2EwjgYIjQw-1 X-Mimecast-MFC-AGG-ID: DoHpBq0pPJau2EwjgYIjQw_1755166544 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 194C918003FC; Thu, 14 Aug 2025 10:15:44 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.62]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id A45C81800297; Thu, 14 Aug 2025 10:15:40 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 14 Aug 2025 12:14:28 +0200 (CEST) Date: Thu, 14 Aug 2025 12:14:24 +0200 From: Oleg Nesterov To: Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Jens Axboe , Peter Zijlstra , Rick Edgecombe , Sohil Mehta , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH 3/6] x86/fpu: fold sync_fpstate() into get_fpstate() Message-ID: <20250814101424.GA17352@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250814101340.GA17288@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After the previous change sync_fpstate() has no other callers. Signed-off-by: Oleg Nesterov --- arch/x86/kernel/fpu/regset.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset.c index f5a803774e1c..ecbabdc15ec1 100644 --- a/arch/x86/kernel/fpu/regset.c +++ b/arch/x86/kernel/fpu/regset.c @@ -43,16 +43,12 @@ int regset_xregset_fpregs_active(struct task_struct *ta= rget, const struct user_r * - ptrace to dump fpstate of a stopped task, in which case the registe= rs * have already been saved to fpstate on context switch. */ -static void sync_fpstate(struct fpu *fpu) -{ - if (fpu =3D=3D x86_task_fpu(current)) - fpu_sync_fpstate(fpu); -} - static struct fpstate *get_fpstate(struct task_struct *task) { struct fpu *fpu =3D x86_task_fpu(task); - sync_fpstate(fpu); + + if (task =3D=3D current) + fpu_sync_fpstate(fpu); return fpu->fpstate; } =20 --=20 2.25.1.362.g51ebf55 From nobody Sat Oct 4 15:55:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24D24301475 for ; Thu, 14 Aug 2025 10:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166559; cv=none; b=PZYH5OsmZC5WcNWkCToNRAKr70FIoJEFZjn7MlZrulImtdUgj5/TrpLQ6048FKv61wr/2/X8VIogUTOUSdF1CDF794JPc5PmMBaRp5rgMNYKVyjYVLUd+9Ng0bOd6wYFqNkw40AzabLRrjT6sCL+K3fMsUbsf+SNPmXCvPwOFL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166559; c=relaxed/simple; bh=ikwK1L1Zqv+UgFsFXEmpO+tfpHaf2zCZIQITeI8jLNs=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=d5oR+0daOTjKEEnxsjmycFQDOUEd0K/ddQBDLSv3pFg/RK/fRMC4Av38syExT1yuQ6OeaO30CvsBYLHvEgDHg7lBrVHboFBdJvD6hnPXcWXeuOH2DeIMyWOtKoOwFRgv2uvDFRQ/284bdVZwgcbSbHbZUEL0ncErx7EqnKVlJ80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fHh9ybAI; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fHh9ybAI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755166557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=cc8JTYkYXyLOfAFP05hC+s4ahvBhm0jxKwqiDB0jMOc=; b=fHh9ybAIGo9NfQ3D4ka8wV95/DTAZYqb5imuIJ1gla5ZMbEAb88TPkKmiqOCclKdCSLcjA AC6wpDE445MfbMkfR62Fh9clBCfpvU88a+bIGIhTPY9euFhV22z9VY+JqVUTwLbYatS4Rg 9QsHc5508AN/CrxztjrS2pcXqGSZz24= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-388-FS5_zYP6OA-_seZQdQ0AFA-1; Thu, 14 Aug 2025 06:15:51 -0400 X-MC-Unique: FS5_zYP6OA-_seZQdQ0AFA-1 X-Mimecast-MFC-AGG-ID: FS5_zYP6OA-_seZQdQ0AFA_1755166550 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 091BD1882805; Thu, 14 Aug 2025 10:15:50 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.62]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 02A051955E89; Thu, 14 Aug 2025 10:15:45 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 14 Aug 2025 12:14:34 +0200 (CEST) Date: Thu, 14 Aug 2025 12:14:29 +0200 From: Oleg Nesterov To: Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Jens Axboe , Peter Zijlstra , Rick Edgecombe , Sohil Mehta , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH 4/6] x86/shstk: add "task_struct *tsk" argument to reset_thread_features() Message-ID: <20250814101429.GA17356@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250814101340.GA17288@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Preparation for the next change. Signed-off-by: Oleg Nesterov --- arch/x86/include/asm/shstk.h | 4 ++-- arch/x86/kernel/process_64.c | 2 +- arch/x86/kernel/shstk.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/shstk.h b/arch/x86/include/asm/shstk.h index ba6f2fe43848..92d449cc352a 100644 --- a/arch/x86/include/asm/shstk.h +++ b/arch/x86/include/asm/shstk.h @@ -15,7 +15,7 @@ struct thread_shstk { }; =20 long shstk_prctl(struct task_struct *task, int option, unsigned long arg2); -void reset_thread_features(void); +void reset_thread_features(struct task_struct *task); unsigned long shstk_alloc_thread_stack(struct task_struct *p, unsigned lon= g clone_flags, unsigned long stack_size); void shstk_free(struct task_struct *p); @@ -26,7 +26,7 @@ bool shstk_is_enabled(void); #else static inline long shstk_prctl(struct task_struct *task, int option, unsigned long arg2) { return -EINVAL; } -static inline void reset_thread_features(void) {} +static inline void reset_thread_features(struct task_struct *task) {} static inline unsigned long shstk_alloc_thread_stack(struct task_struct *p, unsigned long clone_flags, unsigned long stack_size) { return 0; } diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 52a5c03c353c..543425ea8d44 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -540,7 +540,7 @@ start_thread_common(struct pt_regs *regs, unsigned long= new_ip, load_gs_index(__USER_DS); } =20 - reset_thread_features(); + reset_thread_features(current); =20 loadsegment(fs, 0); loadsegment(es, _ds); diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c index 2ddf23387c7e..e6d3b1371b11 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -184,11 +184,11 @@ static int shstk_setup(void) return 0; } =20 -void reset_thread_features(void) +void reset_thread_features(struct task_struct *tsk) { - memset(¤t->thread.shstk, 0, sizeof(struct thread_shstk)); - current->thread.features =3D 0; - current->thread.features_locked =3D 0; + memset(&tsk->thread.shstk, 0, sizeof(struct thread_shstk)); + tsk->thread.features =3D 0; + tsk->thread.features_locked =3D 0; } =20 unsigned long shstk_alloc_thread_stack(struct task_struct *tsk, unsigned l= ong clone_flags, --=20 2.25.1.362.g51ebf55 From nobody Sat Oct 4 15:55:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33F192EBBA7 for ; Thu, 14 Aug 2025 10:16:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166567; cv=none; b=RBUYDBKh0UCWqFZEJYNe4Sqqj2xdmJ+tVVO+TEq0p4RIqIoMoz/pDhDNa1LZFG2On+mZvk4HCRCd5iZhZNk2SqYKJ+HnQPiA/Ze2JDky0RtrbqF0Jq8lXMSSeMXGMRjoXVwmn9C8q7QFkiL41w3pxjd7r35yup5taaLv5vNqIlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166567; c=relaxed/simple; bh=K9wUwnjWFxdOJ7Wm33r78Qn4RUe2Lz37lf3pYpYOLXM=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=EzH3qmKo00GaeFCUMy/OCxqFIgSGbqxiZbgb2+sC4THD2DVnuxm7yP0uSpLGMGyiiurkLTeyFIl6Bo0cm9jgoOV6tlPIPkqlK9QUl8NHk3tfq5E8AYjXaWUGwPK9iijojErSkVDW6NWhLWABpMMc0H+jAS82hA6DQNC9Ylhdl4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZVXFvV0u; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZVXFvV0u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755166565; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=DVY1QUCNIwldEWKREIgkBawz/WH7nI6qPUesGk16egQ=; b=ZVXFvV0u5s8eEVPk8CX4BuHOhhy0b/tzj8C3/aVgBw7/X4nbnq1IHJnLKwVVaAUwe15YGF RbeCGtUz5EC3a+HCv3wyz+dtYUJQnhLrlA4FqmaambGebWS+mY+DhkEgz/anV3bPbUTKBx CZDxvMM0Kr0z/+SHfUHTGV4QMF464GM= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-26-JBqeZ61SNCqTASO1AyXFcw-1; Thu, 14 Aug 2025 06:16:01 -0400 X-MC-Unique: JBqeZ61SNCqTASO1AyXFcw-1 X-Mimecast-MFC-AGG-ID: JBqeZ61SNCqTASO1AyXFcw_1755166560 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9BDEF18824F2; Thu, 14 Aug 2025 10:15:59 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.62]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 0B1911800446; Thu, 14 Aug 2025 10:15:51 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 14 Aug 2025 12:14:43 +0200 (CEST) Date: Thu, 14 Aug 2025 12:14:35 +0200 From: Oleg Nesterov To: Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Jens Axboe , Peter Zijlstra , Rick Edgecombe , Sohil Mehta , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH 5/6] x86/shstk: don't create the shadow stack for PF_USER_WORKERs Message-ID: <20250814101435.GA17362@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250814101340.GA17288@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If a features_enabled(ARCH_SHSTK_SHSTK) userspace thread creates a PF_USER_WORKER thread, shstk_alloc_thread_stack() allocates the shadow stack for no reason, the new (kernel) thread will never return to usermode. Plus the current code doesn't even look correct, in this case fpu_clone() won't call update_fpu_shstk(). Add the new "bool minimal =3D !!args->fn" argument (which matches that of fpu_clone()) to shstk_alloc_thread_stack() and change it to do reset_thread_features(tsk) if "minimal" is true. With this patch ssp_get() -> ssp_active(target) should never return true if target->flags & PF_USER_WORKER. Signed-off-by: Oleg Nesterov --- arch/x86/include/asm/shstk.h | 4 ++-- arch/x86/kernel/process.c | 2 +- arch/x86/kernel/shstk.c | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/shstk.h b/arch/x86/include/asm/shstk.h index 92d449cc352a..dfb2aeebc25f 100644 --- a/arch/x86/include/asm/shstk.h +++ b/arch/x86/include/asm/shstk.h @@ -17,7 +17,7 @@ struct thread_shstk { long shstk_prctl(struct task_struct *task, int option, unsigned long arg2); void reset_thread_features(struct task_struct *task); unsigned long shstk_alloc_thread_stack(struct task_struct *p, unsigned lon= g clone_flags, - unsigned long stack_size); + bool minimal, unsigned long stack_size); void shstk_free(struct task_struct *p); int setup_signal_shadow_stack(struct ksignal *ksig); int restore_signal_shadow_stack(void); @@ -28,7 +28,7 @@ static inline long shstk_prctl(struct task_struct *task, = int option, unsigned long arg2) { return -EINVAL; } static inline void reset_thread_features(struct task_struct *task) {} static inline unsigned long shstk_alloc_thread_stack(struct task_struct *p, - unsigned long clone_flags, + unsigned long clone_flags, bool minimal, unsigned long stack_size) { return 0; } static inline void shstk_free(struct task_struct *p) {} static inline int setup_signal_shadow_stack(struct ksignal *ksig) { return= 0; } diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 1b7960cf6eb0..e932e0e53972 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -209,7 +209,7 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) * is disabled, new_ssp will remain 0, and fpu_clone() will know not to * update it. */ - new_ssp =3D shstk_alloc_thread_stack(p, clone_flags, args->stack_size); + new_ssp =3D shstk_alloc_thread_stack(p, clone_flags, args->fn, args->stac= k_size); if (IS_ERR_VALUE(new_ssp)) return PTR_ERR((void *)new_ssp); =20 diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c index e6d3b1371b11..3da22c6f5874 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -192,11 +192,20 @@ void reset_thread_features(struct task_struct *tsk) } =20 unsigned long shstk_alloc_thread_stack(struct task_struct *tsk, unsigned l= ong clone_flags, - unsigned long stack_size) + bool minimal, unsigned long stack_size) { struct thread_shstk *shstk =3D &tsk->thread.shstk; unsigned long addr, size; =20 + /* + * Kernel threads cloned from userspace thread never return to + * usermode. + */ + if (minimal) { + reset_thread_features(tsk); + return 0; + } + /* * If shadow stack is not enabled on the new thread, skip any * switch to a new shadow stack. --=20 2.25.1.362.g51ebf55 From nobody Sat Oct 4 15:55:21 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0298A2FABED for ; Thu, 14 Aug 2025 10:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166573; cv=none; b=MiELMdSacTaEYjrtUny6bdCveDcR0b7e72/t9aKrJLSruRZvFpV28Va8fuwSkAiEV7YGtEPUxOtpTc+tbcG7ICVe63dHDSJWdsEwrNI7XE9yV9HZ7h8+9thjV+dQuz14hWOOwZrfj6Xx5eUJCWlYULaACNhomaqPckzlK6jI6S4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755166573; c=relaxed/simple; bh=Eh+zMIqztYIY2ggEJbUI5AiR3H04ggRlpFk382BjQDA=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=AOvq8pGjam2zqRs2X/evBSkTbPm/SFLVGYXzNKpIv79LvHdAZkc7EhuUffw9g9jUwzTxQMmNQQrIcnMCs4MvY6/2gO5Kybl6dA8I9sV3IGft4/9tfw0NWjPDwvndONNsy2JQvt4efwwbB4kyfcz6pmbfvOkDu0C/1RdwPsnoNAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PmtdiWJf; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PmtdiWJf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755166571; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=sNdAklJ4NfQziNX1nrwBgXGN4LI63ON8uM/hjWZghWw=; b=PmtdiWJfHbm1JLuCvHxnn5Cglp8yJQj04RP7umSu26jGqcyiv6Ekd2PPOzkcVWinio6kWg 2pnHMelMk1GBJ2jhdHpj91u0os0r5mvAa0p7c7NvRiz6s4E1VuASnBFG0hZyyWcB6tiVyV WT0usLQFOQTWjg5M9Gn+262Hcflogjc= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-FT_HeovZMUK15syjokGoow-1; Thu, 14 Aug 2025 06:16:07 -0400 X-MC-Unique: FT_HeovZMUK15syjokGoow-1 X-Mimecast-MFC-AGG-ID: FT_HeovZMUK15syjokGoow_1755166566 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D5C9319373D8; Thu, 14 Aug 2025 10:16:05 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.62]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id A2D471955E89; Thu, 14 Aug 2025 10:16:01 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 14 Aug 2025 12:14:50 +0200 (CEST) Date: Thu, 14 Aug 2025 12:14:44 +0200 From: Oleg Nesterov To: Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Jens Axboe , Peter Zijlstra , Rick Edgecombe , Sohil Mehta , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH 6/6] x86/fpu: change get_fpstate() to return &init_fpstate if PF_USER_WORKER Message-ID: <20250814101444.GA17366@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250814101340.GA17288@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" PF_USER_WORKERs must never use FPU, this is what kernel_fpu_begin/etc assume. The .regset_get() functions can safely use init_fpstate if target->flags & PF_USER_WORKER. Signed-off-by: Oleg Nesterov --- arch/x86/kernel/fpu/regset.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset.c index ecbabdc15ec1..dfd12d109f00 100644 --- a/arch/x86/kernel/fpu/regset.c +++ b/arch/x86/kernel/fpu/regset.c @@ -45,8 +45,12 @@ int regset_xregset_fpregs_active(struct task_struct *tar= get, const struct user_r */ static struct fpstate *get_fpstate(struct task_struct *task) { - struct fpu *fpu =3D x86_task_fpu(task); + struct fpu *fpu; =20 + if (unlikely(task->flags & PF_USER_WORKER)) + return &init_fpstate; + + fpu =3D x86_task_fpu(task); if (task =3D=3D current) fpu_sync_fpstate(fpu); return fpu->fpstate; --=20 2.25.1.362.g51ebf55