From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f201.google.com (mail-oi1-f201.google.com [209.85.167.201]) (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 BA8153B27DE for ; Mon, 15 Jun 2026 19:37:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781552249; cv=none; b=Rf8uUb3h8Lh3b0f3RtfuUBa5nMgpEIeYWJiAAlsfgUV42pcHZz4V+J+IttdKR21zT+/00rCNao2Yy7POGZ92KEuHSG3Qj60KhwO9ma2A4xlxNVdJ+9nr8Cy45Al4QTzw2nIDdHXR8kGEONlXdti1uPaduxoDTRGTn8uLeBDaYTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781552249; c=relaxed/simple; bh=gTXky8O7FJNLc0oQd7j9qOQkXqpcjpDbnvVDGWTvCJk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QTaEgXTbokI4Nizhz4hNY8NEXbs3c4hpOTCJXb5f0FqJFQMkT/T0pkO6d2Tz2bl4OYVGFYr80K38I55ePFyuPQPDrVUSUGLymI0rnUGlyfrdvbfA93oGj1cMzqXkvs02EFsMmYYWkgqWeDC1Zfn0KlnDtFpAEr33HmxqbtHs5oU= 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=ZyQ54up6; arc=none smtp.client-ip=209.85.167.201 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="ZyQ54up6" Received: by mail-oi1-f201.google.com with SMTP id 5614622812f47-4863c8d459eso3918820b6e.3 for ; Mon, 15 Jun 2026 12:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781552247; x=1782157047; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zm0iG/jXM5qQlRuaKO+1FnC/jCl1KUYIybxup6Imlys=; b=ZyQ54up6k/dMcClXJ82cw162ZS1bgEbJyzshTBi7PbJgLa30SKcpteVjvltp8S1SsK OnSWeQt1KzV3xzMDnw5sW7rHl8HY/akbBLDZymodFxNtQEli53ExPxLwyxA1doT7O50n Xy1Kld7xmgIM3ew5UYhS3GLjlY3VPul15FvfGj6ximMfArHL3rII5cIpgRaeRVkQMnpN yulE8gDPjMm4UaptoJeDcbjKey6XG4fq13/MI+PzuEC5b64AnI94HFTaYQqJKyVLs/KW 21jMTn4Xpb/EKS2pBMCEHtPR4yjYoGcDeMjAPJpmnLgrzty6ShT9cmmD7uUKpEvJ1VXw sxJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781552247; x=1782157047; h=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; bh=zm0iG/jXM5qQlRuaKO+1FnC/jCl1KUYIybxup6Imlys=; b=h95b6VDTeuhvVBHpdCwRVLiKR/bKITPDoGkKm7Rbu3qHaOZI40xXaVdTVUZHUOYKZW 48j6kTdPQSCIJp8UyjoB4j0HSOqAAdB/oLy3AWzoqIBJIPD/hlZJoOTCX2J91PxaDWJV CSf+stgLe3P/4nmFnPEcx+AOrRbavB+OP6Wxhgbg3PI+ZN2Uj5UU4YnupRb6UIpLy6Af OjtCGdWHBAGw+JMPsqxv9LP0gxjh/LIuIHvVuz2ZcYVyzBGAmFXcS1TA77GMc6KqQRHg 3G5n/vSwy+cV5IlpMT9JzO4BuXPJTv/jd6o1SVMfLjb5bqONjVByyNpwRPeQiRGUfrGF 5DSA== X-Gm-Message-State: AOJu0Yw1KWFJa1X94dvm3TudkPHDsFJa54XLkQdvjHipg6V4OoSndGbU ClPKZrZ5nk0pRhcmekEUwou7SD/yaIEQeybczpKp3MyjazCdgQ87VKGKyI3emcZiO8HxwiYGthJ kaLj/iQ== X-Received: from iogq18.prod.google.com ([2002:a6b:7112:0:b0:967:e6c0:a4e3]) (user=avagin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:4f21:b0:486:5275:8144 with SMTP id 5614622812f47-4874194d5damr8090028b6e.2.1781552246548; Mon, 15 Jun 2026 12:37:26 -0700 (PDT) Date: Mon, 15 Jun 2026 19:37:09 +0000 In-Reply-To: <20260615193716.1843340-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: <20260615193716.1843340-1-avagin@google.com> X-Mailer: git-send-email 2.54.0.1189.g8c84645362-goog Message-ID: <20260615193716.1843340-4-avagin@google.com> Subject: [PATCH 03/10] 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 , "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. 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.54.0.1189.g8c84645362-goog