[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 1/6] better kvm detection
|
From: |
Gerd Hoffmann |
|
Subject: |
[PATCH v3 1/6] better kvm detection |
|
Date: |
Fri, 5 May 2023 09:11:12 +0200 |
In case kvm emulates features of another hypervisor (for example hyperv)
two VMM CPUID blocks will be present, one for the emulated hypervisor
and one for kvm itself.
This patch makes seabios loop over the VMM CPUID blocks to make sure it
will properly detect kvm when multiple blocks are present.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
src/fw/paravirt.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c
index fba4e52db684..c880cb10a1bc 100644
--- a/src/fw/paravirt.c
+++ b/src/fw/paravirt.c
@@ -56,20 +56,31 @@ inline int qemu_cfg_dma_enabled(void)
static void kvm_detect(void)
{
+ unsigned int i, kvmbase = 0, max = 0;
unsigned int eax, ebx, ecx, edx;
char signature[13];
- cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
- memcpy(signature + 0, &ebx, 4);
- memcpy(signature + 4, &ecx, 4);
- memcpy(signature + 8, &edx, 4);
- signature[12] = 0;
+ for (i = KVM_CPUID_SIGNATURE;; i += 0x100) {
+ eax = 0;
+ cpuid(i, &eax, &ebx, &ecx, &edx);
+ if (eax < i)
+ break;
+ memcpy(signature + 0, &ebx, 4);
+ memcpy(signature + 4, &ecx, 4);
+ memcpy(signature + 8, &edx, 4);
+ signature[12] = 0;
+ dprintf(1, "cpuid 0x%x: eax %x, signature '%s'\n", i, eax, signature);
+ if (strcmp(signature, "KVMKVMKVM") == 0) {
+ kvmbase = i;
+ max = eax;
+ }
+ }
- if (strcmp(signature, "KVMKVMKVM") == 0) {
+ if (kvmbase) {
dprintf(1, "Running on KVM\n");
PlatformRunningOn |= PF_KVM;
- if (eax >= KVM_CPUID_SIGNATURE + 0x10) {
- cpuid(KVM_CPUID_SIGNATURE + 0x10, &eax, &ebx, &ecx, &edx);
+ if (max >= kvmbase + 0x10) {
+ cpuid(kvmbase + 0x10, &eax, &ebx, &ecx, &edx);
dprintf(1, "kvm: have invtsc, freq %u kHz\n", eax);
tsctimer_setfreq(eax, "invtsc");
}
--
2.40.1
- [PATCH v3 0/6] misc tweaks for kvm and the 64bit pci window, Gerd Hoffmann, 2023/05/05
- [PATCH v3 4/6] be less conservative with the 64bit pci io window, Gerd Hoffmann, 2023/05/05
- [PATCH v3 2/6] detect physical address space size, Gerd Hoffmann, 2023/05/05
- [PATCH v3 1/6] better kvm detection,
Gerd Hoffmann <=
- [PATCH v3 6/6] check for e820 conflict, Gerd Hoffmann, 2023/05/05
- [PATCH v3 3/6] move 64bit pci window to end of address space, Gerd Hoffmann, 2023/05/05
- [PATCH v3 5/6] qemu: log reservations in fw_cfg e820 table, Gerd Hoffmann, 2023/05/05
- Re: [SeaBIOS] [PATCH v3 0/6] misc tweaks for kvm and the 64bit pci window, Kevin O'Connor, 2023/05/09