@@ -38,6 +38,24 @@ use crate::mem::memory_region::MemoryRegion;
3838#[ cfg( feature = "trace_guest" ) ]
3939use crate :: sandbox:: trace:: TraceContext as SandboxTraceContext ;
4040
41+ /// On KVM x86-64 only, we have to set this in order to set the guest
42+ /// physical address width.
43+ ///
44+ /// The requirement to set this to configure the guest physical
45+ /// address width for KVM is not well documented, but see e.g. Linux
46+ /// v6.18.6 arch/x86/kvm/cpuid.c:kvm_vcpu_after_set_cpuid()
47+ /// (https://elixir.bootlin.com/linux/v6.18.6/source/arch/x86/kvm/cpuid.c#L444)
48+ /// for how it is processed.
49+ ///
50+ /// For the architectural definition and format of the system register:
51+ /// See AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and
52+ /// System Instructions
53+ /// Appendix E: Obtaining Processor Information Via the CPUID Instruction
54+ /// E.4.7: Function 8000_0008h---Processor Capacity Parameters and
55+ /// Extended Feature Identification, pp. 627--628
56+ const CPUID_FUNCTION_PROCESSOR_CAPACITY_PARAMETERS_AND_EXTENDED_FEATURE_IDENTIFICATION : u32 =
57+ 0x8000_0008 ;
58+
4159/// Return `true` if the KVM API is available, version 12, and has UserMemory capability, or `false` otherwise
4260#[ instrument( skip_all, parent = Span :: current( ) , level = "Trace" ) ]
4361pub ( crate ) fn is_hypervisor_present ( ) -> bool {
@@ -95,7 +113,9 @@ impl KvmVm {
95113 . get_supported_cpuid ( kvm_bindings:: KVM_MAX_CPUID_ENTRIES )
96114 . map_err ( |e| CreateVmError :: InitializeVm ( e. into ( ) ) ) ?;
97115 for entry in kvm_cpuid. as_mut_slice ( ) . iter_mut ( ) {
98- if entry. function == 0x8000_0008 {
116+ if entry. function
117+ == CPUID_FUNCTION_PROCESSOR_CAPACITY_PARAMETERS_AND_EXTENDED_FEATURE_IDENTIFICATION
118+ {
99119 entry. eax &= !0xff ;
100120 entry. eax |= hyperlight_common:: layout:: MAX_GPA . ilog2 ( ) + 1 ;
101121 }
0 commit comments