From nobody Wed Dec 17 12:06:58 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 BC9FF14900F; Mon, 17 Mar 2025 23:03:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742252594; cv=none; b=PqIn6j17GBfMbryaWWx8rIdZB96CTolXiiXuiBhV9PRTZp/7vlTIEbrrPevsHfWdgw1jetkTC1xqedT1QhLI1GYJzAgGjZuzs2eUdrin1D6svhCdcmcpNFyLqB5NkQyeO/ESAVa9i9vhHY6xHP0/MfqxUIYMQA7xvUs82YFxAVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742252594; c=relaxed/simple; bh=V1OIXrs9CUjf000cBLJK2Je9iZkKCRv2mHPPsfho/Nc=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=Am5NbO3p+zCYi3T9YFtXtgZ9NMVB4DZg1mFYasZjYI+PL5E5iH1wUPhoPEmOM3lTeQ2RThYQLHLuLYsg7FchI6JoGSigjs9hYkk+AhyCHZ1GCo4JDLboqugt3cPqiOyUkJu6GGv7fNRL71M3ODkXVtz4bK/Jbd0+/SY9Ae9NqBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=auYfnhGk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+zLC+Hk8; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="auYfnhGk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+zLC+Hk8" Date: Mon, 17 Mar 2025 23:03:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742252587; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jeRRP/YAk4qoANrW+AA8uw4nMpTz/q7kbyeAnwmntLE=; b=auYfnhGku10DhHcBiddoy+ABDwwA7F0bjo6OSMxzOeNaUXc4gm+AxU6hM0h+DzD3/vXcah 8d+Eq2zBW0/cpy5XKkY54qfAfL7LJihMzvf8RmaDE45n47vF78ReFnh/QUjnQuTkSCZp84 5N7QBUAWtR0Zs92tD355FDosAOm3OVa5aowkdWu25N4QMhbKM5qMokXvH5Y9FTbOAsogU7 Rj2lOojvcQU5Wb+RmRXvUqYGG47Vymucvx9rx90Ftv7geiN/zFvWrD3+RMg3nC2c3z2Nhf jCOL+rpMlRmZWPNiTl44KisN4YjIKQyQngZ7bXxLB6veuXDpdSw+ZZ6CJv8kig== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742252587; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jeRRP/YAk4qoANrW+AA8uw4nMpTz/q7kbyeAnwmntLE=; b=+zLC+Hk82PXncIxkVyL3+Coq5+WRaK90ScYuzdnHuTHy35SsTAd5rbUkt5LKgBa55mCmrF KPvh12Sa7fKbu6CA== From: "tip-bot2 for Chao Gao" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fpu] x86/fpu/xstate: Fix inconsistencies in guest FPU xfeatures Cc: "Chang S. Bae" , Chao Gao , Ingo Molnar , Andy Lutomirski , "H. Peter Anvin" , Linus Torvalds , Oleg Nesterov , Dave Hansen , Juergen Gross , Stefano Stabellini , Paolo Bonzini , Vitaly Kuznetsov , Sean Christopherson , David Woodhouse , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250317140613.1761633-1-chao.gao@intel.com> References: <20250317140613.1761633-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <174225258602.14745.15224724000760257268.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/fpu branch of tip: Commit-ID: dda366083e5ff307a4a728757db874bbfe7550be Gitweb: https://git.kernel.org/tip/dda366083e5ff307a4a728757db874bbf= e7550be Author: Chao Gao AuthorDate: Mon, 17 Mar 2025 22:06:11 +08:00 Committer: Ingo Molnar CommitterDate: Mon, 17 Mar 2025 23:52:31 +01:00 x86/fpu/xstate: Fix inconsistencies in guest FPU xfeatures Guest FPUs manage vCPU FPU states. They are allocated via fpu_alloc_guest_fpstate() and are resized in fpstate_realloc() when XFD features are enabled. Since the introduction of guest FPUs, there have been inconsistencies in the kernel buffer size and xfeatures: 1. fpu_alloc_guest_fpstate() uses fpu_user_cfg since its introduction. See: 69f6ed1d14c6 ("x86/fpu: Provide infrastructure for KVM FPU cleanup") 36487e6228c4 ("x86/fpu: Prepare guest FPU for dynamically enabled FPU f= eatures") 2. __fpstate_reset() references fpu_kernel_cfg to set storage attributes. 3. fpu->guest_perm uses fpu_kernel_cfg, affecting fpstate_realloc(). A recent commit in the tip:x86/fpu tree partially addressed the inconsisten= cy between (1) and (3) by using fpu_kernel_cfg for size calculation in (1), but left fpu_guest->xfeatures and fpu_guest->perm still referencing fpu_user_cfg: https://lore.kernel.org/all/20250218141045.85201-1-stanspas@amazon.de/ 1937e18cc3cf ("x86/fpu: Fix guest FPU state buffer allocation size") The inconsistencies within fpu_alloc_guest_fpstate() and across the mentioned functions cause confusion. Fix them by using fpu_kernel_cfg consistently in fpu_alloc_guest_fpstate(), except for fields related to the UABI buffer. Referencing fpu_kernel_cfg won't impact functionalities, as: 1. fpu_guest->perm is overwritten shortly in fpu_init_guest_permissions() with fpstate->guest_perm, which already uses fpu_kernel_cfg. 2. fpu_guest->xfeatures is solely used to check if XFD features are enable= d. Including supervisor xfeatures doesn't affect the check. Fixes: 36487e6228c4 ("x86/fpu: Prepare guest FPU for dynamically enabled FP= U features") Suggested-by: Chang S. Bae Signed-off-by: Chao Gao Signed-off-by: Ingo Molnar Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Dave Hansen Cc: Juergen Gross Cc: Stefano Stabellini Cc: Paolo Bonzini Cc: Vitaly Kuznetsov Cc: Sean Christopherson Cc: David Woodhouse Link: https://lore.kernel.org/r/20250317140613.1761633-1-chao.gao@intel.com --- arch/x86/kernel/fpu/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 422c98c..1b734a9 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -239,8 +239,8 @@ bool fpu_alloc_guest_fpstate(struct fpu_guest *gfpu) fpstate->is_guest =3D true; =20 gfpu->fpstate =3D fpstate; - gfpu->xfeatures =3D fpu_user_cfg.default_features; - gfpu->perm =3D fpu_user_cfg.default_features; + gfpu->xfeatures =3D fpu_kernel_cfg.default_features; + gfpu->perm =3D fpu_kernel_cfg.default_features; =20 /* * KVM sets the FP+SSE bits in the XSAVE header when copying FPU state