From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) (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 B75E3318B9C for ; Mon, 17 Aug 2026 04:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786940462; cv=none; b=IlR5Ki/Wc477yRZLakLJnRlZ/75JYOHyyWGPpIY3zYUO+RmLKun4RGYbrJperIKDRlrW97PKK2hepWNphQ3atYAPuek/473llKMKmUKQNgDh0eoRIotpIf/qaezUYi5ZSRvS22YazjOVKJF0PdDW/JQ9DL+i42SvEASDDl2LBnA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786940462; c=relaxed/simple; bh=Fj6O5O0OVGQEOAg5m3ZLYJrkJ3m5QZuJ2i4wisOSKW4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CJVBDDSLIzYduBPqRUyXEugYrsfrtYlzGw2dUS8OUXZGg/sMBUpRgP4XG+xNNR/8Ye8DJ4nnGCSY2I6p5YI9c2kch+CF1C6MEMRUT75BK7PeI0UgyPRT3ova4McEonJ74697W9HAapcahzwkhwnNL5enp7eShMkvcnjUssVdijc= 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=XD6qZi0b; arc=none smtp.client-ip=209.85.210.69 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="XD6qZi0b" Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-7e7624e584dso4542188a34.2 for ; Sun, 16 Aug 2026 21:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786940460; x=1787545260; 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=sTjo6aZvyLBA/rbDobhpOJiS9o4YY4gm2eDitpUg4DA=; b=XD6qZi0bOteIdmu1p4phxfl/6tCUODfvqv9PNyUWKBkO6sy3jLptqj39iQ83H539Wd 42YnfTIYdJWk5b+/6ieYR1eDM+34hNEHlmfuaocaNyvT8ljjUQ//F5WhB0cM6ANCDW8K tCRHEk7o5hnab15TA2l6dTZbrDJ60pVBD1ZaDrGVkqTOyOEPw30oKUtHcGGNHvUlnQid HRiVPSSh8xmknEfgQFmZqlpdb28CjOesXr7mjtr7SfNgh3cMCVqEkW/9KLtULWdwbPZg MUYtDpIOJOWG8PxtOQMIgkcEgcslAsFGWWVxj/r4pRGcTfSZ/9opG3FkOX8FQi+fhY+Z OG2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786940460; x=1787545260; 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=sTjo6aZvyLBA/rbDobhpOJiS9o4YY4gm2eDitpUg4DA=; b=K95C2elkFM0wRavlevwSmb7UERCUkl2TTXR6jmM/N9sjGU13mJW2U2hmAeXisw1dQI AceIcdBh/JcC/utTRlFsj1Xh3ln+bfw3rUFB2Z0DOPSIBoOD2uX95mW00O0tglwGQmPC ZyOF2TSGRKhs/SNyRAplvJ9sEmxPbCjjWQT3ffbCS+UybI42zdnTMOTGjNPFwgwafO/O 2/eNml4O7kO1EYr0gdhb4OyklGfjUTMNxgkEqKhyW1RSU+GN6YVQEYV7e7UpoJ+hChjg YBWTtjJRrI43U3jBmQ5jXVmPV6hczaFU4NGwDq+syXBOCa4Dl24FPcuST6FEbEggCVj0 hN6w== X-Forwarded-Encrypted: i=1; AHgh+Rpj/AylPVWlOv/wQ8mIoalw+XuBNJ0uJSIbbuFcxQLM1ISp/CPs5/3ccv4Lt1VMSDHbwA2L@lists.linux.dev X-Gm-Message-State: AOJu0Yziwk4KqR5noSh3LuZt5r3obcULt9y/B4LYzpzDHtmOwp7OI+eu lRfdj7UMKmX7ETTj1SzKw9CEyGdypuAXJ5cU/Qf6NaGRSiesf/5/L+3z3w2bWNTs6QKMV+93/Yb Eef9+Vw== X-Received: from ilkj13.prod.google.com ([2002:a05:6e02:eed:b0:509:30bc:8271]) (user=avagin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:c93:b0:6b1:64f:cd88 with SMTP id 006d021491bc7-6b106501ebcmr7175117eaf.6.1786940458922; Sun, 16 Aug 2026 21:20:58 -0700 (PDT) Date: Mon, 17 Aug 2026 04:20:43 +0000 In-Reply-To: <20260817042048.1579415-1-avagin@google.com> Precedence: bulk X-Mailing-List: criu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260817042048.1579415-1-avagin@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260817042048.1579415-4-avagin@google.com> Subject: [PATCH 3/8] x86/fpu: Split __fpu_restore_sig to extract compat path 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" Content-Type: text/plain; charset="UTF-8" Split __fpu_restore_sig to move the restore part for the legacy/compat FPU state (when buf_f is present) to a separate helper function. The legacy 32-bit FP frame duplicates the FP state portion of the FX/XSAVE frame. For backward compatibility, the legacy FP frame is treated as the source of truth, and its state is folded into the FX/XSAVE state before restoring the registers. Reviewed-by: Alexander Mikhalitsyn Signed-off-by: Andrei Vagin --- arch/x86/kernel/fpu/signal.c | 50 +++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c index 42c3d78bd849..6a14b528ac7f 100644 --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -264,6 +264,9 @@ static int __restore_fpregs_from_user(void __user *buf, u64 task_xfeatures, } } +static bool restore_fpregs_from_user_compat(void __user *buf_f, void __user *buf_fx, + u64 xrestore_mask, bool fx_only); + /* * Attempt to restore the FPU registers directly from user memory. * Pagefaults are handled and any errors returned are fatal. @@ -324,14 +327,9 @@ static bool restore_fpregs_from_user(void __user *buf, u64 xrestore_mask, bool f return true; } -static bool __fpu_restore_sig(void __user *buf_f, void __user *buf_fx, - bool ia32_fxstate) +static bool __fpu_restore_sig(void __user *buf_f, void __user *buf_fx) { - struct task_struct *tsk = current; - struct fpu *fpu = x86_task_fpu(tsk); - struct user_i387_ia32_struct env; - bool success, fx_only = false; - union fpregs_state *fpregs; + bool fx_only = false; u64 xrestore_mask = 0; if (use_xsave()) { @@ -346,11 +344,33 @@ static bool __fpu_restore_sig(void __user *buf_f, void __user *buf_fx, xrestore_mask = XFEATURE_MASK_FPSSE; } - if (likely(!ia32_fxstate)) { + if (likely(!buf_f)) { /* Restore the FPU registers directly from user memory. */ return restore_fpregs_from_user(buf_fx, xrestore_mask, fx_only); } + return restore_fpregs_from_user_compat(buf_f, buf_fx, xrestore_mask, fx_only); +} + +#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION) +/* + * Restore FPU state from a signal frame when a legacy 32-bit FP frame + * (buf_f) is present. + * + * The legacy FP frame duplicates the FP state portion of the FX/XSAVE + * frame (buf_fx). For backward compatibility, the legacy FP frame is + * treated as the source of truth, and its state is folded into the + * FX/XSAVE state before restoring the registers. + */ +static bool restore_fpregs_from_user_compat(void __user *buf_f, void __user *buf_fx, + u64 xrestore_mask, bool fx_only) +{ + struct task_struct *tsk = current; + struct fpu *fpu = x86_task_fpu(tsk); + struct user_i387_ia32_struct env; + union fpregs_state *fpregs; + bool success; + /* * Copy the legacy state because the FP portion of the FX frame has * to be ignored for histerical raisins. The legacy state is folded @@ -435,6 +455,13 @@ static bool __fpu_restore_sig(void __user *buf_f, void __user *buf_fx, fpregs_unlock(); return success; } +#else +static bool restore_fpregs_from_user_compat(void __user *buf_f, void __user *buf_fx, + u64 xrestore_mask, bool fx_only) +{ + return false; +} +#endif static inline unsigned int xstate_sigframe_size(struct fpstate *fpstate) { @@ -449,8 +476,7 @@ static inline unsigned int xstate_sigframe_size(struct fpstate *fpstate) bool fpu__restore_sig(void __user *buf, int ia32_frame) { struct fpu *fpu = x86_task_fpu(current); - void __user *buf_fx = buf; - bool ia32_fxstate = false; + void __user *buf_fx = buf, *buf_f = NULL; bool success = false; unsigned int size; @@ -471,7 +497,7 @@ bool fpu__restore_sig(void __user *buf, int ia32_frame) if (ia32_frame && use_fxsr()) { buf_fx = buf + sizeof(struct fregs_state); size += sizeof(struct fregs_state); - ia32_fxstate = true; + buf_f = buf; } if (!access_ok(buf, size)) @@ -482,7 +508,7 @@ bool fpu__restore_sig(void __user *buf, int ia32_frame) sizeof(struct user_i387_ia32_struct), NULL, buf); } else { - success = __fpu_restore_sig(buf, buf_fx, ia32_fxstate); + success = __fpu_restore_sig(buf_f, buf_fx); } out: -- 2.55.0.691.gc56d675ccc-goog