Skip to contentSkip to conversation

kvm: work around supported cpuid ioctl() brokenness

PATCH In review Mark McLoughlin 2 participants 3 messages May 12, 2009 – May 19, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: work around supported cpuid ioctl() brokenness

KVM_GET_SUPPORTED_CPUID has been known to fail to return -E2BIG when it runs out of entries. Detect this by always trying again with a bigger table if the ioctl() fills the table.

---
 target-i386/kvm.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
target-i386/kvm.c +2 -0
index fe67eed..d2e1651 100644
@@ -45,6 +45,8 @@ static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max)
     cpuid = (struct kvm_cpuid2 *)qemu_mallocz(size);
     cpuid->nent = max;
     r = kvm_ioctl(s, KVM_GET_SUPPORTED_CPUID, cpuid);
+    if (r == 0 && cpuid->nent >= max)
+        r = -E2BIG;
     if (r < 0) {
         if (r == -E2BIG) {
             qemu_free(cpuid);
Signature · 1 line
1.6.0.6
#1 lore raw
Quoted 5 lines · Mark McLoughlin

KVM_GET_SUPPORTED_CPUID has been known to fail to return -E2BIG when it runs out of entries. Detect this by always trying again with a bigger table if the ioctl() fills the table.

Looks good, except for

target-i386/kvm.c static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max) · line 49

Quoted 6 lines
     cpuid = (struct kvm_cpuid2 *)qemu_mallocz(size);
     cpuid->nent = max;
     r = kvm_ioctl(s, KVM_GET_SUPPORTED_CPUID, cpuid);
target-i386/kvm.c +2 -0
+    if (r == 0 && cpuid->nent >= max)
+        r = -E2BIG;

Missing braces.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#2 lore raw

PATCH v2 1/1 kvm: work around supported cpuid ioctl() brokenness

KVM_GET_SUPPORTED_CPUID has been known to fail to return -E2BIG when it runs out of entries. Detect this by always trying again with a bigger table if the ioctl() fills the table.

---
 target-i386/kvm.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
target-i386/kvm.c +3 -0
index fe67eed..7cdcf31 100644
@@ -45,6 +45,9 @@ static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max)
     cpuid = (struct kvm_cpuid2 *)qemu_mallocz(size);
     cpuid->nent = max;
     r = kvm_ioctl(s, KVM_GET_SUPPORTED_CPUID, cpuid);
+    if (r == 0 && cpuid->nent >= max) {
+        r = -E2BIG;
+    }
     if (r < 0) {
         if (r == -E2BIG) {
             qemu_free(cpuid);
Signature · 1 line
1.6.0.6