Skip to content

Commit f705de1

Browse files
committed
KVM: x86: Initialize allow_smaller_maxphyaddr earlier in setup
Initialize allow_smaller_maxphyaddr during hardware setup as soon as KVM knows whether or not TDP will be utilized. To avoid having to teach KVM's emulator all about CET, KVM's upcoming CET virtualization support will be mutually exclusive with allow_smaller_maxphyaddr, i.e. will disable SHSTK and IBT if allow_smaller_maxphyaddr is enabled. In general, allow_smaller_maxphyaddr should be initialized as soon as possible since it's globally visible while its only input is whether or not EPT/NPT is enabled. I.e. there's effectively zero risk of setting allow_smaller_maxphyaddr too early, and substantial risk of setting it too late. Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Link: https://lore.kernel.org/r/20250922184743.1745778-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 1f6f68f commit f705de1

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5370,6 +5370,21 @@ static __init int svm_hardware_setup(void)
53705370
get_npt_level(), PG_LEVEL_1G);
53715371
pr_info("Nested Paging %s\n", str_enabled_disabled(npt_enabled));
53725372

5373+
/*
5374+
* It seems that on AMD processors PTE's accessed bit is
5375+
* being set by the CPU hardware before the NPF vmexit.
5376+
* This is not expected behaviour and our tests fail because
5377+
* of it.
5378+
* A workaround here is to disable support for
5379+
* GUEST_MAXPHYADDR < HOST_MAXPHYADDR if NPT is enabled.
5380+
* In this case userspace can know if there is support using
5381+
* KVM_CAP_SMALLER_MAXPHYADDR extension and decide how to handle
5382+
* it
5383+
* If future AMD CPU models change the behaviour described above,
5384+
* this variable can be changed accordingly
5385+
*/
5386+
allow_smaller_maxphyaddr = !npt_enabled;
5387+
53735388
/* Setup shadow_me_value and shadow_me_mask */
53745389
kvm_mmu_set_me_spte_mask(sme_me_mask, sme_me_mask);
53755390

@@ -5449,21 +5464,6 @@ static __init int svm_hardware_setup(void)
54495464

54505465
svm_set_cpu_caps();
54515466

5452-
/*
5453-
* It seems that on AMD processors PTE's accessed bit is
5454-
* being set by the CPU hardware before the NPF vmexit.
5455-
* This is not expected behaviour and our tests fail because
5456-
* of it.
5457-
* A workaround here is to disable support for
5458-
* GUEST_MAXPHYADDR < HOST_MAXPHYADDR if NPT is enabled.
5459-
* In this case userspace can know if there is support using
5460-
* KVM_CAP_SMALLER_MAXPHYADDR extension and decide how to handle
5461-
* it
5462-
* If future AMD CPU models change the behaviour described above,
5463-
* this variable can be changed accordingly
5464-
*/
5465-
allow_smaller_maxphyaddr = !npt_enabled;
5466-
54675467
kvm_caps.inapplicable_quirks &= ~KVM_X86_QUIRK_CD_NW_CLEARED;
54685468
return 0;
54695469

arch/x86/kvm/vmx/vmx.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8436,6 +8436,14 @@ __init int vmx_hardware_setup(void)
84368436
return -EOPNOTSUPP;
84378437
}
84388438

8439+
/*
8440+
* Shadow paging doesn't have a (further) performance penalty
8441+
* from GUEST_MAXPHYADDR < HOST_MAXPHYADDR so enable it
8442+
* by default
8443+
*/
8444+
if (!enable_ept)
8445+
allow_smaller_maxphyaddr = true;
8446+
84398447
if (!cpu_has_vmx_ept_ad_bits() || !enable_ept)
84408448
enable_ept_ad_bits = 0;
84418449

@@ -8665,14 +8673,6 @@ int __init vmx_init(void)
86658673

86668674
vmx_check_vmcs12_offsets();
86678675

8668-
/*
8669-
* Shadow paging doesn't have a (further) performance penalty
8670-
* from GUEST_MAXPHYADDR < HOST_MAXPHYADDR so enable it
8671-
* by default
8672-
*/
8673-
if (!enable_ept)
8674-
allow_smaller_maxphyaddr = true;
8675-
86768676
return 0;
86778677

86788678
err_l1d_flush:

0 commit comments

Comments
 (0)