Skip to contentSkip to conversation

kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func

PATCH Applied Jim Mattson 3 participants 4 messages Sep 25, 2019 – Sep 26, 2019

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

PATCH 1/1 kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func

Don't return -E2BIG from __do_cpuid_func when processing function 0BH or 1FH and the last interesting subleaf occupies the last allocated entry in the result array.

Cc Sean Christopherson <[email protected]>
Cc Paolo Bonzini <[email protected]>
Fixes 831bf664e9c1fc ("KVM: Refactor and simplify kvm_dev_ioctl_get_supported_cpuid")
---
 arch/x86/kvm/cpuid.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
arch/x86/kvm/cpuid.c +10 -6
index dd5985eb61b4c..a3ee9e110ba82 100644
@@ -612,16 +612,20 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
 	 */
 	case 0x1f:
 	case 0xb: {
-		int i, level_type;
+		int i;
 
-		/* read more entries until level_type is zero */
-		for (i = 1; ; ++i) {
+		/*
+		 * We filled in entry[0] for CPUID(EAX=<function>,
+		 * ECX=00H) above.  If its level type (ECX[15:8]) is
+		 * zero, then the leaf is unimplemented, and we're
+		 * done.  Otherwise, continue to populate entries
+		 * until the level type (ECX[15:8]) of the previously
+		 * added entry is zero.
+		 */
+		for (i = 1; entry[i - 1].ecx & 0xff00; ++i) {
 			if (*nent >= maxnent)
 				goto out;
 
-			level_type = entry[i - 1].ecx & 0xff00;
-			if (!level_type)
-				break;
 			do_host_cpuid(&entry[i], function, i);
 			++*nent;
 		}
Signature · 1 line
2.23.0.351.gc4317032e6-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jim Mattson

Don't return -E2BIG from __do_cpuid_func when processing function 0BH or 1FH and the last interesting subleaf occupies the last allocated entry in the result array.

Cc Sean Christopherson <[email protected]>
Cc Paolo Bonzini <[email protected]>
Fixes 831bf664e9c1fc ("KVM: Refactor and simplify kvm_dev_ioctl_get_supported_cpuid")

---

maintainer Applied
#2 lore raw
Quoted 5 lines · Sean Christopherson
Quoted 4 lines · Jim Mattson

Don't return -E2BIG from __do_cpuid_func when processing function 0BH or 1FH and the last interesting subleaf occupies the last allocated entry in the result array.

Quoted 9 lines
Quoted 6 lines
Cc Sean Christopherson <[email protected]>
Cc Paolo Bonzini <[email protected]>
Fixes 831bf664e9c1fc ("KVM: Refactor and simplify kvm_dev_ioctl_get_supported_cpuid")

---

Queued, thanks.

Paolo

maintainer Applied
#3 lore raw
In reply to Jim Mattson
Quoted 35 lines · Jim Mattson

Don't return -E2BIG from __do_cpuid_func when processing function 0BH or 1FH and the last interesting subleaf occupies the last allocated entry in the result array.

Cc Sean Christopherson <[email protected]>
Cc Paolo Bonzini <[email protected]>
Fixes 831bf664e9c1fc ("KVM: Refactor and simplify kvm_dev_ioctl_get_supported_cpuid")
---
 arch/x86/kvm/cpuid.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
arch/x86/kvm/cpuid.c +9 -3
index dd5985eb61b4c..a3ee9e110ba82 100644
@@ -612,16 +612,20 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
 	 */
 	case 0x1f:
 	case 0xb: {
-		int i, level_type;
+		int i;
 
-		/* read more entries until level_type is zero */
-		for (i = 1; ; ++i) {
+		/*
+		 * We filled in entry[0] for CPUID(EAX=<function>,
+		 * ECX=00H) above.  If its level type (ECX[15:8]) is
+		 * zero, then the leaf is unimplemented, and we're
+		 * done.  Otherwise, continue to populate entries
+		 * until the level type (ECX[15:8]) of the previously
+		 * added entry is zero.
+		 */

arch/x86/kvm/cpuid.c static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, · line 631

Quoted 10 lines
arch/x86/kvm/cpuid.c +1 -3
+		for (i = 1; entry[i - 1].ecx & 0xff00; ++i) {
 			if (*nent >= maxnent)
 				goto out;
 
-			level_type = entry[i - 1].ecx & 0xff00;
-			if (!level_type)
-				break;
 			do_host_cpuid(&entry[i], function, i);
 			++*nent;
 		}

Queued, thanks.

Paolo