From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 464DC4AE123 for ; Thu, 24 Sep 2026 21:01:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790283693; cv=none; b=fls77eQtz8+eeVaP/71Y2/JLD1tg5gehIlClx7mzYlrrzDpUtitbiElYe0avAU27pxQypXr6QdflU2G7nmDFDPcAc9x+IE61pCl84oux6PyoqaLKJswvArF7IsFx0GZYiMmSIqfJZnWBiucAoMWr9LyoUqUfv3VOB7cOYzHMx7g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790283693; c=relaxed/simple; bh=zWUFtQ0OFpf3Izpq9TTF+b80Ep7btpGUWULX6UL8HCg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hOvlPPE8xTdTPbSdR8HX/KmytpBQQJBrgQb3HUG5jn+5kJmDSDgGFCDr//hQQL41ymR8/SBcwHCCDco+YOk3PH/9LxYYik49mSoFNg7G838awTWaejorpmSLJFBwqz3xtDkuT1O6InDwmZZ7WjNfyiHt8Fn2FX6oWqpRtxyxJ8c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fAJSBdfj; arc=none smtp.client-ip=209.85.167.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fAJSBdfj" Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-4cbff1bc700so267809b6e.2 for ; Thu, 24 Sep 2026 14:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790283687; x=1790888487; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=kuB32MkZPc+XuzqWI7qs9zzr2PkaAGHh7pBlaVBsovk=; b=fAJSBdfjLmy3msSGwd6AJ0oa41KWkkZYZuctAd3/nuQIs2SdvslmujQP53kAY5rrBP 1NbgBrWhUmgAQcP6lImTK1kU7HYlNSydUKzCM5byv35RAW65Q3Hq4m03aTREqS1t4J43 mEYKIOh8l+KtY/sfcx1zGIZo11tmZ+00I5qMvrabN5lre0VcydQvZ6Rb6AVGDoBMwttt PW1jx4XIoVO5oxZ3CNfZAYMqmlFtEnY42up5xfOUEEkzgqw37sf1u01Rw3CV1eaGHOp0 C4CE2JJFLt3B/ufr+sEBEeFywYcIAoj0RKomY9j1Je61NdKgHrLUj7ziqawZgovNZdkd zJjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790283687; x=1790888487; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kuB32MkZPc+XuzqWI7qs9zzr2PkaAGHh7pBlaVBsovk=; b=tcEfPUS2uwEQYKk9DAKyD7EkDp2jyULEkNUNCJOXQTYQGdpbUubdEDD0LBb0JQ8QTf OJk4y9IT41rlNx1PWkbbJnj2bu9qJHll40Ghlkd+kOe9RMyXuaRerXZB0wVaqqrLfHUt cSP+1hL0+swJGDIiXdWd82GiG6haFP2QLf7YxkCihOvZVHVRZ3ZhjeHq4GnLHQjDvhEm ug45mfPtfO/Sy3/8M8wkPOqf4xXNwLlREHL2Jib/0UzHn5zOaZgf7jurvBqCiuWkKnWc zTyQ0igcMSJwTefkTSgiv76FGJtlQc10MXEf/OkyTCRZ1YDenvqVg2le1k93Si8GbdHN TjsQ== X-Forwarded-Encrypted: i=1; AKwUvBz9K0O1xE/lZcNYJnwhB5qGFoqmzdOqBfnoMA007PCu7ndG/h9mgNAAnR4U1fwHCe9Gm4Qr@lists.linux.dev X-Gm-Message-State: AFuF++k/R5ql9L3RFAMSoqYFFvgMGB/MyGovrY3CHkZG7/CnVcGcKxV+ 6eWLBxxFenhHQafp1kXRWWwUJ0tXzowRULafNd6kwZUiQogM+BKQWKYlNjt3OWSXDmFMy2gOH5i tX3w3zQ== X-Received: from iobbj14.prod.google.com ([2002:a05:6602:35ce:b0:9b6:e72f:c47b]) (user=avagin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:1990:b0:4b2:8e1c:5920 with SMTP id 5614622812f47-4dc57e29203mr41742b6e.9.1790283686460; Thu, 24 Sep 2026 14:01:26 -0700 (PDT) Date: Thu, 24 Sep 2026 21:01:16 +0000 In-Reply-To: <20260924210121.87032-1-avagin@google.com> Precedence: bulk X-Mailing-List: criu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260924210121.87032-1-avagin@google.com> X-Mailer: git-send-email 2.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20260924210121.87032-3-avagin@google.com> Subject: [PATCH 2/7] x86/fpu: Clean up and rename variables in signal frame handling From: Andrei Vagin To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "Chang S. Bae" Cc: linux-kernel@vger.kernel.org, criu@lists.linux.dev, Dave Hansen , x86@kernel.org, Andrei Vagin , Alexander Mikhalitsyn , "H. Peter Anvin" , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Clean up signal frame handling code by renaming several variables for clarity and consistency, and moving masking logic closer to its usage. - Rename 'fxbuf' to 'buf_fx' in check_xstate_in_sigframe() for consistency. - Rename label 'setfx' to 'err_setfx' in check_xstate_in_sigframe() to indicate it is an error path. - In __restore_fpregs_from_user(), rename 'ufeatures' to 'task_xfeatures' and 'xrestore' to 'xrestore_mask'. - Move the masking logic 'xrestore_mask &= task_xfeatures' from restore_fpregs_from_user() into __restore_fpregs_from_user(). - Rename 'xrestore' to 'xrestore_mask' in restore_fpregs_from_user() to match the name in __restore_fpregs_from_user() and __fpu_restore_sig(). - In __fpu_restore_sig(), rename 'buf' to 'buf_f' to distinguish it from 'buf_fx', and 'user_xfeatures' to 'xrestore_mask'. No functional changes. Suggested-by: Ingo Molnar Reviewed-by: Alexander Mikhalitsyn Signed-off-by: Andrei Vagin --- arch/x86/kernel/fpu/signal.c | 41 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c index 33e1284bf3e4..cd7db6dc819b 100644 --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -24,15 +24,15 @@ * Check for the presence of extended state information in the * user fpstate pointer in the sigcontext. */ -static inline bool check_xstate_in_sigframe(struct fxregs_state __user *fxbuf, +static inline bool check_xstate_in_sigframe(struct fxregs_state __user *buf_fx, struct _fpx_sw_bytes *fx_sw) { int min_xstate_size = sizeof(struct fxregs_state) + sizeof(struct xstate_header); - void __user *fpstate = fxbuf; + void __user *fpstate = buf_fx; unsigned int magic2; - if (__copy_from_user(fx_sw, &fxbuf->sw_reserved[0], sizeof(*fx_sw))) + if (__copy_from_user(fx_sw, &buf_fx->sw_reserved[0], sizeof(*fx_sw))) return false; /* Check for the first magic field and other error scenarios. */ @@ -40,7 +40,7 @@ static inline bool check_xstate_in_sigframe(struct fxregs_state __user *fxbuf, fx_sw->xstate_size < min_xstate_size || fx_sw->xstate_size > x86_task_fpu(current)->fpstate->user_size || fx_sw->xstate_size > fx_sw->extended_size) - goto setfx; + goto err_setfx; /* * Check for the presence of second magic word at the end of memory @@ -53,7 +53,7 @@ static inline bool check_xstate_in_sigframe(struct fxregs_state __user *fxbuf, if (likely(magic2 == FP_XSTATE_MAGIC2)) return true; -setfx: +err_setfx: trace_x86_fpu_xstate_check_failed(x86_task_fpu(current)); /* Set the parameters for fx only state */ @@ -240,15 +240,18 @@ bool copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size, u return true; } -static int __restore_fpregs_from_user(void __user *buf, u64 ufeatures, - u64 xrestore, bool fx_only) +static int __restore_fpregs_from_user(void __user *buf, u64 task_xfeatures, + u64 xrestore_mask, bool fx_only) { if (use_xsave()) { - u64 init_bv = ufeatures & ~xrestore; + u64 init_bv; int ret; + /* Restore enabled features only. */ + xrestore_mask &= task_xfeatures; + init_bv = task_xfeatures & ~xrestore_mask; if (likely(!fx_only)) - ret = xrstor_from_user_sigframe(buf, xrestore); + ret = xrstor_from_user_sigframe(buf, xrestore_mask); else ret = fxrstor_from_user_sigframe(buf); @@ -266,20 +269,18 @@ static int __restore_fpregs_from_user(void __user *buf, u64 ufeatures, * Attempt to restore the FPU registers directly from user memory. * Pagefaults are handled and any errors returned are fatal. */ -static bool restore_fpregs_from_user(void __user *buf, u64 xrestore, bool fx_only) +static bool restore_fpregs_from_user(void __user *buf, u64 xrestore_mask, bool fx_only) { struct fpu *fpu = x86_task_fpu(current); int ret; - /* Restore enabled features only. */ - xrestore &= fpu->fpstate->user_xfeatures; retry: fpregs_lock(); /* Ensure that XFD is up to date */ xfd_update_state(fpu->fpstate); pagefault_disable(); ret = __restore_fpregs_from_user(buf, fpu->fpstate->user_xfeatures, - xrestore, fx_only); + xrestore_mask, fx_only); pagefault_enable(); if (unlikely(ret)) { @@ -324,7 +325,7 @@ static bool restore_fpregs_from_user(void __user *buf, u64 xrestore, bool fx_onl return true; } -static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx, +static bool __fpu_restore_sig(void __user *buf_f, void __user *buf_fx, bool ia32_fxstate) { struct task_struct *tsk = current; @@ -332,7 +333,7 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx, struct user_i387_ia32_struct env; bool success, fx_only = false; union fpregs_state *fpregs; - u64 user_xfeatures = 0; + u64 xrestore_mask = 0; if (use_xsave()) { struct _fpx_sw_bytes fx_sw_user; @@ -341,14 +342,14 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx, return false; fx_only = !fx_sw_user.magic1; - user_xfeatures = fx_sw_user.xfeatures; + xrestore_mask = fx_sw_user.xfeatures; } else { - user_xfeatures = XFEATURE_MASK_FPSSE; + xrestore_mask = XFEATURE_MASK_FPSSE; } if (likely(!ia32_fxstate)) { /* Restore the FPU registers directly from user memory. */ - return restore_fpregs_from_user(buf_fx, user_xfeatures, fx_only); + return restore_fpregs_from_user(buf_fx, xrestore_mask, fx_only); } /* @@ -356,7 +357,7 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx, * to be ignored for histerical raisins. The legacy state is folded * in once the larger state has been copied. */ - if (__copy_from_user(&env, buf, sizeof(env))) + if (__copy_from_user(&env, buf_f, sizeof(env))) return false; /* @@ -420,7 +421,7 @@ static bool __fpu_restore_sig(void __user *buf, void __user *buf_fx, * * Preserve supervisor states! */ - u64 mask = user_xfeatures | xfeatures_mask_supervisor(); + u64 mask = xrestore_mask | xfeatures_mask_supervisor(); fpregs->xsave.header.xfeatures &= mask; success = !os_xrstor_safe(fpu->fpstate, -- 2.56.0.rc1.315.gc6ed9934b7-goog