On Tue, Mar 5, 2024 at 11:52 AM Gerd Hoffmann <kraxel@xxxxxxxxxx> wrote: > > Query kvm for supported guest physical address bits, in cpuid > function 80000008, eax[23:16]. Usually this is identical to host > physical address bits. With NPT or EPT being used this might be > restricted to 48 (max 4-level paging address space size) even if > the host cpu supports more physical address bits. > > When set pass this to the guest, using cpuid too. Guest firmware > can use this to figure how big the usable guest physical address > space is, so PCI bar mapping are actually reachable. > > Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxxxxx> > --- > target/i386/cpu.h | 1 + > target/i386/cpu.c | 1 + > target/i386/kvm/kvm.c | 17 +++++++++++++++++ > 3 files changed, 19 insertions(+) > > diff --git a/target/i386/cpu.h b/target/i386/cpu.h > index 952174bb6f52..d427218827f6 100644 > --- a/target/i386/cpu.h > +++ b/target/i386/cpu.h > + guest_phys_bits = kvm_get_guest_phys_bits(cs->kvm_state); > + if (guest_phys_bits && > + (cpu->guest_phys_bits == 0 || > + cpu->guest_phys_bits > guest_phys_bits)) { > + cpu->guest_phys_bits = guest_phys_bits; > + } Like Xiaoyao mentioned, the right place for this is kvm_cpu_realizefn, after host_cpu_realizefn returns. It should also be conditional on cpu->host_phys_bits. It also makes sense to: - make kvm_get_guest_phys_bits() return bits 7:0 if bits 23:16 are zero - here, set cpu->guest_phys_bits only if it is not equal to cpu->phys_bits (this undoes the previous suggestion, but I think it's cleaner) - add a property in x86_cpu_properties[] to allow configuration with TCG. Paolo > + > /* > * kvm_hyperv_expand_features() is called here for the second time in case > * KVM_CAP_SYS_HYPERV_CPUID is not supported. While we can't possibly handle > -- > 2.44.0 >