All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func
@ 2019-09-25 18:17 Jim Mattson
  2019-09-25 22:33 ` Sean Christopherson
  2019-09-26 10:26 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Jim Mattson @ 2019-09-25 18:17 UTC (permalink / raw)
  To: kvm; +Cc: Jim Mattson, Sean Christopherson, Paolo Bonzini, Peter Shier

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 <sean.j.christopherson@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Fixes: 831bf664e9c1fc ("KVM: Refactor and simplify kvm_dev_ioctl_get_supported_cpuid")
Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Peter Shier <pshier@google.com>
---
 arch/x86/kvm/cpuid.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index dd5985eb61b4c..a3ee9e110ba82 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -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;
 		}
-- 
2.23.0.351.gc4317032e6-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func
  2019-09-25 18:17 [PATCH] kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func Jim Mattson
@ 2019-09-25 22:33 ` Sean Christopherson
  2019-09-26 10:27   ` Paolo Bonzini
  2019-09-26 10:26 ` Paolo Bonzini
  1 sibling, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2019-09-25 22:33 UTC (permalink / raw)
  To: Jim Mattson; +Cc: kvm, Paolo Bonzini, Peter Shier

On Wed, Sep 25, 2019 at 11:17:14AM -0700, Jim Mattson wrote:
> 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 <sean.j.christopherson@intel.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Fixes: 831bf664e9c1fc ("KVM: Refactor and simplify kvm_dev_ioctl_get_supported_cpuid")
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Peter Shier <pshier@google.com>
> ---

Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func
  2019-09-25 18:17 [PATCH] kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func Jim Mattson
  2019-09-25 22:33 ` Sean Christopherson
@ 2019-09-26 10:26 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2019-09-26 10:26 UTC (permalink / raw)
  To: Jim Mattson, kvm; +Cc: Sean Christopherson, Peter Shier

On 25/09/19 20:17, Jim Mattson wrote:
> 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 <sean.j.christopherson@intel.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Fixes: 831bf664e9c1fc ("KVM: Refactor and simplify kvm_dev_ioctl_get_supported_cpuid")
> Signed-off-by: Jim Mattson <jmattson@google.com>
> Reviewed-by: Peter Shier <pshier@google.com>
> ---
>  arch/x86/kvm/cpuid.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index dd5985eb61b4c..a3ee9e110ba82 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -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;
>  		}
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func
  2019-09-25 22:33 ` Sean Christopherson
@ 2019-09-26 10:27   ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2019-09-26 10:27 UTC (permalink / raw)
  To: Sean Christopherson, Jim Mattson; +Cc: kvm, Peter Shier

On 26/09/19 00:33, Sean Christopherson wrote:
> On Wed, Sep 25, 2019 at 11:17:14AM -0700, Jim Mattson wrote:
>> 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 <sean.j.christopherson@intel.com>
>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>> Fixes: 831bf664e9c1fc ("KVM: Refactor and simplify kvm_dev_ioctl_get_supported_cpuid")
>> Signed-off-by: Jim Mattson <jmattson@google.com>
>> Reviewed-by: Peter Shier <pshier@google.com>
>> ---
> 
> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-26 10:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25 18:17 [PATCH] kvm: x86: Fix a spurious -E2BIG in __do_cpuid_func Jim Mattson
2019-09-25 22:33 ` Sean Christopherson
2019-09-26 10:27   ` Paolo Bonzini
2019-09-26 10:26 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.