From nobody Fri Oct 3 15:32:58 2025 Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (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 7FC212E7648; Fri, 29 Aug 2025 15:33:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756481590; cv=none; b=ZBs+HFDb6ew7Ztzn0ovbF1JEpM3i+Kir+j8GQvTEzpMrSaVLW93Xh26U2OEiUTM8mhutBtlrO1l03dbcAiBqHjKkIqIs7imq6wxddsWHJIbqAvfRdQh5uW9+TzjFxVnEOcMzpA6lY2LwV7waH/220xyh2Ak4Q6Xn46Auzp8N12w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756481590; c=relaxed/simple; bh=be0yaU2VSauTKW0ejwoPeGB9TJqXp74audZRWQgzWmw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K0wCgnE2TL+CfSzgmYo4NjjhapYt/97auEyQiaHxp+cvRcHAhco+LkWT+sjWG/3IElXgBgv2M5CFjZaeozeDKcHvhsLdDMwM9ljoE0zkoEnO+PZwGw7b/OpE+x7Y6LyyWg41YS7S7Y39Ixy1acy2Tb2ilT2fxc1gmWV8TKjHzKA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=eeAoHq/L; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="eeAoHq/L" Received: from terminus.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3:0:0:0:136]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 57TFVo4G2871953 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 29 Aug 2025 08:32:21 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 57TFVo4G2871953 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025082201; t=1756481541; bh=E8FWVS3F21e0+iQvPdDtHltgySljBipLyJm5DeDRHrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eeAoHq/LfNkyV0eOhyF+onTUSd3APy4MGQRyGO8tZhIgvicy9AOSKvspmfUU4ULwx q6n+1M+i+SaMZJnUa0g28PtKUzP2wT0hmx31sexeiw6Ib6kMpY43Mb4uiBbwH4lHgY E8UKZIqLhB5aAsWaapZsrcpIic26YH/osZ2PYxNrqfsJf+7y0KrIN8mbR84jhjzNoK bH56FPkxD38UTtlt+DrOqysh4ezk/+M5mbOMdd5ytYRvgjcA1NI2pUKMXTTk/LNBG+ GGs2cCr09dY/GuJtB4OF4w6sOQdCzCgozUS2Us1SDLE+gkcF5CpEJ4jgYKyQE0aDiN DgLRSKHZOlc4Q== From: "Xin Li (Intel)" To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, xin@zytor.com, luto@kernel.org, peterz@infradead.org, andrew.cooper3@citrix.com, chao.gao@intel.com, hch@infradead.org Subject: [PATCH v7 10/21] KVM: x86: Add a helper to detect if FRED is enabled for a vCPU Date: Fri, 29 Aug 2025 08:31:38 -0700 Message-ID: <20250829153149.2871901-11-xin@zytor.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250829153149.2871901-1-xin@zytor.com> References: <20250829153149.2871901-1-xin@zytor.com> 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 Content-Type: text/plain; charset="utf-8" From: Xin Li Signed-off-by: Xin Li [ Sean: removed the "kvm_" prefix from the function name ] Signed-off-by: Sean Christopherson Signed-off-by: Xin Li (Intel) Tested-by: Shan Kang Tested-by: Xuelian Guo --- Change in v5: * Add TB from Xuelian Guo. --- arch/x86/kvm/kvm_cache_regs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h index 36a8786db291..31b446b6cbd7 100644 --- a/arch/x86/kvm/kvm_cache_regs.h +++ b/arch/x86/kvm/kvm_cache_regs.h @@ -204,6 +204,21 @@ static __always_inline bool kvm_is_cr4_bit_set(struct = kvm_vcpu *vcpu, return !!kvm_read_cr4_bits(vcpu, cr4_bit); } =20 +/* + * It's enough to check just CR4.FRED (X86_CR4_FRED) to tell if + * a vCPU is running with FRED enabled, because: + * 1) CR4.FRED can be set to 1 only _after_ IA32_EFER.LMA =3D 1. + * 2) To leave IA-32e mode, CR4.FRED must be cleared first. + */ +static inline bool is_fred_enabled(struct kvm_vcpu *vcpu) +{ +#ifdef CONFIG_X86_64 + return kvm_is_cr4_bit_set(vcpu, X86_CR4_FRED); +#else + return false; +#endif +} + static inline ulong kvm_read_cr3(struct kvm_vcpu *vcpu) { if (!kvm_register_is_available(vcpu, VCPU_EXREG_CR3)) --=20 2.51.0