From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (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 7E92131715F for ; Mon, 17 Aug 2026 04:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786940462; cv=none; b=fOilSBhF24E5GdcURn4fsrMW7QKi8XPPF79bjrU4WHmfQOOmEPojRSB4+uwoz8bbo6uB9eDHNvDFBuap7WKgNiKSP9Hhh68SI58zswUvlyh7W0iQnuwagpLFKQbDMoQZZeHFwXmBbDpH6FmbfIuE/Wt5P0bogX6W/M86gqfVstc= 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=uaVhoYqv; arc=none smtp.client-ip=209.85.210.71 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="uaVhoYqv" Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-7e9f6f0240eso3859435a34.3 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=1786940459; x=1787545259; darn=vger.kernel.org; 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=uaVhoYqvd9ddvX0lqMeWA+ucTJkN5FMXqG7hYkp6tyB5po5TcIXprvs8FeBXBs+xXn 9hj51DYrCWnq0rZDx0wFsFZC1NkKZNR7wNWddOaq0pM97HvW9/2eLTOM3ROJNmixe6C/ b96fM7XKZdeRA71RSkNK8I2ivCn0ANFLMQV2nNHePiubZEaFllzZGurnfnh2yoWar+9n HFYZfqO+lil4yRSzr8L4JFvPM+G/12IXpKBdHSG2JocLKarGPI3SrNdmroUbma83jsND +1nRsWzS4v1hE3fwUxFd8/HoJV+j0B7szjYkjGCRkXqn5ZIYp5NT6JsB+gL+dMvzwT3d 2IGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786940459; x=1787545259; 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=cQ6PzH7smxcF9SDBJR/yxnhlSxEsPux2irLPWvtleoEPkuQGrMlLiZU+GN1csFO2zn aEdOSwN4oFlvnVcyPpUmKA4C63nFJQ+05XTh/zhllfW8HhfdjlNptdz5HantzUo4XD7g vFE7dIy8+MadxatZrHwSVAxBHc4yUg3iL+rt4oqKWMi7pxG++8HoKVXh9zSAeyjLbuO8 /7KfqnTkqrnJMTfwKhdJRucnG/xYTLLG6j5tM8P5hych6knYU3BGAmM87bLjWGA234Rl dkdGOoiQxeXCtpoX69EX7YclHtspUkCdE6S9IKkXosoJQGc1mQ2NJv4IQyzTMkY+nrxl JHgA== X-Gm-Message-State: AOJu0YzN8unLPoHF/Q5M9JiMNdD7G8iYU+8P4ANr9fRMKuq/e0i9OWxj rOZKazl02z+7bTTDWj2GYmJ7MOJMsnZX6XGpEI7GvjClhg1c3xOSPO4i7okYyeh2Cv0zh02UZhx NFPz4lA== 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: linux-kernel@vger.kernel.org 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