From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Yosry Ahmed <yosry@kernel.org>,
Sean Christopherson <seanjc@google.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 7.2.y 9/9] KVM: x86: Disallow EFER.LME and EFER.LMA if long mode is not supported
Date: Fri, 11 Sep 2026 06:41:23 -0400 [thread overview]
Message-ID: <20260911104123.189614-9-sashal@kernel.org> (raw)
In-Reply-To: <20260911104123.189614-1-sashal@kernel.org>
From: Yosry Ahmed <yosry@kernel.org>
[ Upstream commit e62392bf39ebfdf60d1d082799397fe1cbf8dfc5 ]
Remove EFER.LME and EFER.LMA from EFER reserved bits only if long mode
is actually supported. KVM does check long-mode support before allowing
the bits for guest writes and userspace writes through KVM_SET_SREGS*
(in __kvm_valid_efer()), but userspace writes through KVM_SET_MSRS only
check reserved bits.
In practice, this doesn't really matter. The true motiviation is getting
rid of the #ifdeffery when initializing efer_reserved_bits.
Cc: stable@vger.kernel.org
Signed-off-by: Yosry Ahmed <yosry@kernel.org>
Link: https://patch.msgid.link/20260713181020.2735367-3-yosry@kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/x86/kvm/msrs.c | 10 +---------
arch/x86/kvm/x86.c | 3 +++
2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kvm/msrs.c b/arch/x86/kvm/msrs.c
index 07f2a22d2607d..19981ac780eed 100644
--- a/arch/x86/kvm/msrs.c
+++ b/arch/x86/kvm/msrs.c
@@ -19,16 +19,8 @@ bool __read_mostly report_ignored_msrs = true;
module_param(report_ignored_msrs, bool, 0644);
EXPORT_SYMBOL_FOR_KVM_INTERNAL(report_ignored_msrs);
-/* EFER defaults:
- * - enable syscall per default because its emulated by KVM
- * - enable LME and LMA per default on 64 bit KVM
- */
-#ifdef CONFIG_X86_64
-static
-u64 __read_mostly efer_reserved_bits = ~((u64)(EFER_SCE | EFER_LME | EFER_LMA));
-#else
+/* Enable syscall by default because its emulated by KVM */
static u64 __read_mostly efer_reserved_bits = ~((u64)EFER_SCE);
-#endif
#define MAX_IO_MSRS 256
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a0e74a4e40d06..3b29427526785 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7328,6 +7328,9 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_setup_xss_caps);
static void kvm_setup_efer_caps(void)
{
+ if (kvm_cpu_cap_has(X86_FEATURE_LM))
+ kvm_enable_efer_bits(EFER_LME | EFER_LMA);
+
if (kvm_cpu_cap_has(X86_FEATURE_NX))
kvm_enable_efer_bits(EFER_NX);
--
2.53.0
next prev parent reply other threads:[~2026-09-11 10:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 10:32 FAILED: patch "[PATCH] KVM: x86: Disallow EFER.LME and EFER.LMA if long mode is not" failed to apply to 7.2-stable tree gregkh
2026-09-11 10:41 ` [PATCH 7.2.y 1/9] KVM: x86: Rename __{g,s}et_sregs2() => kvm_vcpu_ioctl_x86_{g,s}et_sregs2() Sasha Levin
2026-09-11 10:41 ` [PATCH 7.2.y 2/9] KVM: x86: Move kvm_caps and kvm_host_values to asm/kvm_host.h Sasha Levin
2026-09-11 10:41 ` [PATCH 7.2.y 3/9] KVM: x86: Swap the include order between x86.h and mmu.h Sasha Levin
2026-09-11 10:41 ` [PATCH 7.2.y 4/9] KVM: x86: Move eager_page_split to mmu.{c,h} Sasha Levin
2026-09-11 10:41 ` [PATCH 7.2.y 5/9] KVM: x86: Move kvm_{load,put}_guest_fpu() to fpu.h Sasha Levin
2026-09-11 10:41 ` [PATCH 7.2.y 6/9] KVM: x86: Extract get/set MSR (list) ioctl logic to helpers Sasha Levin
2026-09-11 10:41 ` [PATCH 7.2.y 7/9] KVM: x86: Expose several TSC helpers via x86.h for use by MSR code Sasha Levin
2026-09-11 10:41 ` [PATCH 7.2.y 8/9] KVM: x86: Move the bulk of MSR specific code from x86.c to msrs.{c,h} Sasha Levin
2026-09-11 10:41 ` Sasha Levin [this message]
2026-09-11 12:26 ` [PATCH 7.2.y 1/9] KVM: x86: Rename __{g,s}et_sregs2() => kvm_vcpu_ioctl_x86_{g,s}et_sregs2() Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260911104123.189614-9-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=seanjc@google.com \
--cc=stable@vger.kernel.org \
--cc=yosry@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox