Skip to content

Commit b96e650

Browse files
Mohammed Gamalbonzini
authored andcommitted
KVM: x86: VMX: Make smaller physical guest address space support user-configurable
This patch exposes allow_smaller_maxphyaddr to the user as a module parameter. Since smaller physical address spaces are only supported on VMX, the parameter is only exposed in the kvm_intel module. For now disable support by default, and let the user decide if they want to enable it. Modifications to VMX page fault and EPT violation handling will depend on whether that parameter is enabled. Signed-off-by: Mohammed Gamal <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 32251b0 commit b96e650

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ static bool __read_mostly enable_preemption_timer = 1;
129129
module_param_named(preemption_timer, enable_preemption_timer, bool, S_IRUGO);
130130
#endif
131131

132+
extern bool __read_mostly allow_smaller_maxphyaddr;
133+
module_param(allow_smaller_maxphyaddr, bool, S_IRUGO);
134+
132135
#define KVM_VM_CR0_ALWAYS_OFF (X86_CR0_NW | X86_CR0_CD)
133136
#define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST X86_CR0_NE
134137
#define KVM_VM_CR0_ALWAYS_ON \
@@ -4803,6 +4806,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
48034806
* EPT will cause page fault only if we need to
48044807
* detect illegal GPAs.
48054808
*/
4809+
WARN_ON_ONCE(!allow_smaller_maxphyaddr);
48064810
kvm_fixup_and_inject_pf_error(vcpu, cr2, error_code);
48074811
return 1;
48084812
} else
@@ -5331,7 +5335,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
53315335
* would also use advanced VM-exit information for EPT violations to
53325336
* reconstruct the page fault error code.
53335337
*/
5334-
if (unlikely(kvm_mmu_is_illegal_gpa(vcpu, gpa)))
5338+
if (unlikely(allow_smaller_maxphyaddr && kvm_mmu_is_illegal_gpa(vcpu, gpa)))
53355339
return kvm_emulate_instruction(vcpu, 0);
53365340

53375341
return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0);
@@ -8305,11 +8309,12 @@ static int __init vmx_init(void)
83058309
vmx_check_vmcs12_offsets();
83068310

83078311
/*
8308-
* Intel processors don't have problems with
8309-
* GUEST_MAXPHYADDR < HOST_MAXPHYADDR so enable
8310-
* it for VMX by default
8312+
* Shadow paging doesn't have a (further) performance penalty
8313+
* from GUEST_MAXPHYADDR < HOST_MAXPHYADDR so enable it
8314+
* by default
83118315
*/
8312-
allow_smaller_maxphyaddr = true;
8316+
if (!enable_ept)
8317+
allow_smaller_maxphyaddr = true;
83138318

83148319
return 0;
83158320
}

arch/x86/kvm/vmx/vmx.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,10 @@ static inline bool vmx_has_waitpkg(struct vcpu_vmx *vmx)
552552

553553
static inline bool vmx_need_pf_intercept(struct kvm_vcpu *vcpu)
554554
{
555-
return !enable_ept || cpuid_maxphyaddr(vcpu) < boot_cpu_data.x86_phys_bits;
555+
if (!enable_ept)
556+
return true;
557+
558+
return allow_smaller_maxphyaddr && cpuid_maxphyaddr(vcpu) < boot_cpu_data.x86_phys_bits;
556559
}
557560

558561
void dump_vmcs(void);

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static struct kvm_shared_msrs __percpu *shared_msrs;
188188
u64 __read_mostly host_efer;
189189
EXPORT_SYMBOL_GPL(host_efer);
190190

191-
bool __read_mostly allow_smaller_maxphyaddr;
191+
bool __read_mostly allow_smaller_maxphyaddr = 0;
192192
EXPORT_SYMBOL_GPL(allow_smaller_maxphyaddr);
193193

194194
static u64 __read_mostly host_xss;

0 commit comments

Comments
 (0)