From nobody Fri Feb 13 00:14:48 2026 Received: from zxbjcas.zhaoxin.com (zxbjcas.zhaoxin.com [124.127.214.139]) (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 CF90422083 for ; Thu, 2 Jan 2025 08:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.127.214.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735807489; cv=none; b=DrHVNBxpLvR9MmaSV6wN1W7j41eNZ1cWRlW5VeLYReOgQSnrCPUHHvIARUWJcTAGx8A5oEweUGJ01MAtHYYyhm+SEenCTfQ5OuJJ3it8jifbxkohD+APS6X3AyZwgPWMyxDmknMu5XnA7+tJT9bMz751VeUUQHgcztaOnqpFc6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735807489; c=relaxed/simple; bh=FpugUMg2Ib9aLIGt/r+jmsV3iJ4L5caVA21NIhl8PS4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=IvRVx07D4xNUM2ZgrpTwRZghvOASYqINLobBVCfaCS5e00REAA836rfCAY34LYSylFKPMe8/oAp5idFm53q/6RaPWbfM2BvpM8bNVQXnAZUeOi9HngpEI+ZTobBKFgJeQrLmQfzIXCpwkz71xuqqUbRgenahys/iePDXHpXvSr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com; spf=pass smtp.mailfrom=zhaoxin.com; arc=none smtp.client-ip=124.127.214.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com Received: from zxbjcas.zhaoxin.com (localhost [127.0.0.2] (may be forged)) by zxbjcas.zhaoxin.com with ESMTP id 5028Oh8s081033 for ; Thu, 2 Jan 2025 16:24:43 +0800 (GMT-8) (envelope-from TonyWWang-oc@zhaoxin.com) Received: from zxbjmbx1.zhaoxin.com (zxbjmbx1.zhaoxin.com [10.29.252.163]) by zxbjcas.zhaoxin.com with ESMTP id 5028NBAa080445; Thu, 2 Jan 2025 16:23:11 +0800 (GMT-8) (envelope-from TonyWWang-oc@zhaoxin.com) Received: from ZXSHMBX1.zhaoxin.com (10.28.252.163) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 2 Jan 2025 16:23:10 +0800 Received: from ZXSHMBX1.zhaoxin.com (10.28.252.163) by ZXSHMBX1.zhaoxin.com (10.28.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 2 Jan 2025 16:23:10 +0800 Received: from ZXSHMBX1.zhaoxin.com ([fe80::1f6:1739:ec6a:3d64]) by ZXSHMBX1.zhaoxin.com ([fe80::1f6:1739:ec6a:3d64%7]) with mapi id 15.01.2507.039; Thu, 2 Jan 2025 16:23:10 +0800 Received: from tony.zhaoxin.com (10.32.65.152) by ZXBJMBX03.zhaoxin.com (10.29.252.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 2 Jan 2025 15:54:02 +0800 From: Tony W Wang-oc To: , , , , , , , , , , CC: , , , Lyle Li Subject: [PATCH] x86/fpu: Fix the os panic issue caused by the XGETBV instruction Date: Thu, 2 Jan 2025 15:54:19 +0800 Message-ID: <20250102075419.2559-1-TonyWWang-oc@zhaoxin.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To ZXBJMBX03.zhaoxin.com (10.29.252.7) X-Moderation-Data: 1/2/2025 4:23:09 PM X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: zxbjcas.zhaoxin.com 5028Oh8s081033 Content-Type: text/plain; charset="utf-8" From: Lyle Li The callers of the xfeatures_in_use function must ensure that the current processor has the X86_FEATURE_XGETBV1 feature. However, in some places where xfeatures_in_use is called, there is no check to see if the processor supports this feature, leading to the execution of the XGETBV XCR1 instruction on processors that do not support this feature, triggering a #GP exception, and ultimately causing an OS panic. To fix this issue, a check for the X86_FEATURE_XGETBV1 feature has been added before calling xfeatures_in_use. Fixes: ae6012d72fa6 ("x86/pkeys: Ensure updated PKRU value is XRSTOR'd")=20 Fixes: 30d02551ba4f ("x86/fpu: Optimize out sigframe xfeatures when in init= state") Signed-off-by: Lyle Li Signed-off-by: Tony W Wang-oc --- arch/x86/kernel/fpu/xstate.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h index aa16f1a1b..4d966c6c7 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -80,6 +80,9 @@ static inline int update_pkru_in_sigframe(struct xregs_st= ate __user *buf, u64 ma if (unlikely(!cpu_feature_enabled(X86_FEATURE_OSPKE))) return 0; =20 + if (!cpu_feature_enabled(X86_FEATURE_XGETBV1)) + return 0; + /* Mark PKRU as in-use so that it is restored correctly. */ xstate_bv =3D (mask & xfeatures_in_use()) | XFEATURE_MASK_PKRU; =20 @@ -292,7 +295,7 @@ static inline int xsave_to_user_sigframe(struct xregs_s= tate __user *buf, u32 pkr int err; =20 /* Optimize away writing unnecessary xfeatures: */ - if (fpu_state_size_dynamic()) + if (cpu_feature_enabled(X86_FEATURE_XGETBV1) && fpu_state_size_dynamic()) mask &=3D xfeatures_need_sigframe_write(); =20 lmask =3D mask; --=20 2.25.1