Skip to contentSkip to conversation

KVM: Don't fail KVM_GET_SUPPORTED_CPUID if nent is just right

PATCH In review Sasha Levin 2 participants 4 messages Nov 24, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM: Don't fail KVM_GET_SUPPORTED_CPUID if nent is just right

If we pass just enough entries to KVM_GET_SUPPORTED_CPUID, we would still fail with -E2BIG due to wrong comparisons.

Cc Avi Kivity <[email protected]>
Cc Marcelo Tosatti <[email protected]>
---
 arch/x86/kvm/x86.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +1 -1
index 9eff4af..83fef71 100644
@@ -2710,7 +2710,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
 		     cpuid->nent);
 
 	r = -E2BIG;
-	if (nent >= cpuid->nent)
+	if (nent > cpuid->nent)
 		goto out_free;
 
 	r = -EFAULT;
Signature · 1 line
1.7.8.rc3
#1 lore raw
Quoted 15 lines · Sasha Levin

If we pass just enough entries to KVM_GET_SUPPORTED_CPUID, we would still fail with -E2BIG due to wrong comparisons.

Cc Avi Kivity <[email protected]>
Cc Marcelo Tosatti <[email protected]>
---
 arch/x86/kvm/x86.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +0 -0
index 9eff4af..83fef71 100644

arch/x86/kvm/x86.c static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, · line 2716

Quoted 8 lines
arch/x86/kvm/x86.c +1 -1
@@ -2710,7 +2710,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
 		     cpuid->nent);
 
 	r = -E2BIG;
-	if (nent >= cpuid->nent)
+	if (nent > cpuid->nent)
 		goto out_free;
 
 

This is just a landmine for the next entry to be added there; surely whoever adds it will forget to correct the > back to >=.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 18 lines · Avi Kivity
Quoted 17 lines · Sasha Levin

If we pass just enough entries to KVM_GET_SUPPORTED_CPUID, we would still fail with -E2BIG due to wrong comparisons.

Cc Avi Kivity <[email protected]>
Cc Marcelo Tosatti <[email protected]>
---
 arch/x86/kvm/x86.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +0 -0
index 9eff4af..83fef71 100644
@@ -2710,7 +2710,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
 		     cpuid->nent);
 
Quoted 10 lines

arch/x86/kvm/x86.c static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,

Quoted 6 lines
arch/x86/kvm/x86.c +1 -1
 	r = -E2BIG;
-	if (nent >= cpuid->nent)
+	if (nent > cpuid->nent)
 		goto out_free;
 
 

This is just a landmine for the next entry to be added there; surely whoever adds it will forget to correct the > back to >=.

Slapping a big warning before that should do the trick? Or maybe add something similar to 'final_nent = nent - 1;'?

Signature · 1 line
Sasha.
#3 lore raw
Quoted 30 lines · Sasha Levin
Quoted 18 lines · Avi Kivity
Quoted 17 lines · Sasha Levin

If we pass just enough entries to KVM_GET_SUPPORTED_CPUID, we would still fail with -E2BIG due to wrong comparisons.

Cc Avi Kivity <[email protected]>
Cc Marcelo Tosatti <[email protected]>
---
 arch/x86/kvm/x86.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +0 -0
index 9eff4af..83fef71 100644
@@ -2710,7 +2710,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
 		     cpuid->nent);
 
Quoted 10 lines

arch/x86/kvm/x86.c static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,

Quoted 6 lines
arch/x86/kvm/x86.c +1 -1
 	r = -E2BIG;
-	if (nent >= cpuid->nent)
+	if (nent > cpuid->nent)
 		goto out_free;
 
 

This is just a landmine for the next entry to be added there; surely whoever adds it will forget to correct the > back to >=.

Quoted 2 lines

Slapping a big warning before that should do the trick? Or maybe add something similar to 'final_nent = nent - 1;'?

Refactor the whole thing so all the repetitive code goes away. Maybe make it table driven.

But after my cpuid.c patch please, I'd hate to redo it.

Signature · 1 line
error compiling committee.c: too many arguments to function