[PATCH] i386/kvm: correct the meaning of '0xffffffff' value for hv-spinlocks

Vitaly Kuznetsov posted 1 patch 5 years, 6 months ago
Test docker-mingw@fedora passed
Test checkpatch passed
Test FreeBSD passed
Test asan passed
Test docker-quick@centos7 passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20200515114847.74523-1-vkuznets@redhat.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <rth@twiddle.net>, Eduardo Habkost <ehabkost@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
docs/hyperv.txt   | 2 +-
target/i386/cpu.c | 2 +-
target/i386/cpu.h | 4 ++--
target/i386/kvm.c | 4 ++--
4 files changed, 6 insertions(+), 6 deletions(-)
[PATCH] i386/kvm: correct the meaning of '0xffffffff' value for hv-spinlocks
Posted by Vitaly Kuznetsov 5 years, 6 months ago
Hyper-V TLFS prior to version 6.0 had a mistake in it: special value
'0xffffffff' for CPUID 0x40000004.EBX was called 'never to retry', this
looked weird (like why it's not '0' which supposedly have the same effect?)
but nobody raised the question. In TLFS version 6.0 the mistake was
corrected to 'never notify' which sounds logical. Fix QEMU accordingly.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 docs/hyperv.txt   | 2 +-
 target/i386/cpu.c | 2 +-
 target/i386/cpu.h | 4 ++--
 target/i386/kvm.c | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/docs/hyperv.txt b/docs/hyperv.txt
index 6518b716a958..5df00da54fc4 100644
--- a/docs/hyperv.txt
+++ b/docs/hyperv.txt
@@ -49,7 +49,7 @@ more efficiently. In particular, this enlightenment allows paravirtualized
 ======================
 Enables paravirtualized spinlocks. The parameter indicates how many times
 spinlock acquisition should be attempted before indicating the situation to the
-hypervisor. A special value 0xffffffff indicates "never to retry".
+hypervisor. A special value 0xffffffff indicates "never notify".
 
 3.4. hv-vpindex
 ================
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 7a4a8e3847f0..5bb9a8017523 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7133,7 +7133,7 @@ static Property x86_cpu_properties[] = {
     DEFINE_PROP_BOOL("pmu", X86CPU, enable_pmu, false),
 
     DEFINE_PROP_UINT32("hv-spinlocks", X86CPU, hyperv_spinlock_attempts,
-                       HYPERV_SPINLOCK_NEVER_RETRY),
+                       HYPERV_SPINLOCK_NEVER_NOTIFY),
     DEFINE_PROP_BIT64("hv-relaxed", X86CPU, hyperv_features,
                       HYPERV_FEAT_RELAXED, 0),
     DEFINE_PROP_BIT64("hv-vapic", X86CPU, hyperv_features,
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 408392dbf6f4..80253d1c373b 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -980,8 +980,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
 #define HYPERV_FEAT_IPI                 13
 #define HYPERV_FEAT_STIMER_DIRECT       14
 
-#ifndef HYPERV_SPINLOCK_NEVER_RETRY
-#define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
+#ifndef HYPERV_SPINLOCK_NEVER_NOTIFY
+#define HYPERV_SPINLOCK_NEVER_NOTIFY             0xFFFFFFFF
 #endif
 
 #define EXCP00_DIVZ	0
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 34f838728dd6..28e9c73cc2a5 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -731,7 +731,7 @@ static bool hyperv_enabled(X86CPU *cpu)
 {
     CPUState *cs = CPU(cpu);
     return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 &&
-        ((cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY) ||
+        ((cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_NOTIFY) ||
          cpu->hyperv_features || cpu->hyperv_passthrough);
 }
 
@@ -1201,7 +1201,7 @@ static int hyperv_handle_properties(CPUState *cs,
             env->features[FEAT_HV_RECOMM_EAX] = c->eax;
 
             /* hv-spinlocks may have been overriden */
-            if (cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY) {
+            if (cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_NOTIFY) {
                 c->ebx = cpu->hyperv_spinlock_attempts;
             }
         }
-- 
2.25.4


Re: [PATCH] i386/kvm: correct the meaning of '0xffffffff' value for hv-spinlocks
Posted by Eduardo Habkost 5 years, 3 months ago
On Fri, May 15, 2020 at 01:48:47PM +0200, Vitaly Kuznetsov wrote:
> Hyper-V TLFS prior to version 6.0 had a mistake in it: special value
> '0xffffffff' for CPUID 0x40000004.EBX was called 'never to retry', this
> looked weird (like why it's not '0' which supposedly have the same effect?)
> but nobody raised the question. In TLFS version 6.0 the mistake was
> corrected to 'never notify' which sounds logical. Fix QEMU accordingly.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>

I've just found this buried in my inbox, sorry for missing it!

Queued for 5.2.

> ---
>  docs/hyperv.txt   | 2 +-
>  target/i386/cpu.c | 2 +-
>  target/i386/cpu.h | 4 ++--
>  target/i386/kvm.c | 4 ++--
>  4 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/docs/hyperv.txt b/docs/hyperv.txt
> index 6518b716a958..5df00da54fc4 100644
> --- a/docs/hyperv.txt
> +++ b/docs/hyperv.txt
> @@ -49,7 +49,7 @@ more efficiently. In particular, this enlightenment allows paravirtualized
>  ======================
>  Enables paravirtualized spinlocks. The parameter indicates how many times
>  spinlock acquisition should be attempted before indicating the situation to the
> -hypervisor. A special value 0xffffffff indicates "never to retry".
> +hypervisor. A special value 0xffffffff indicates "never notify".
>  
>  3.4. hv-vpindex
>  ================
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 7a4a8e3847f0..5bb9a8017523 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -7133,7 +7133,7 @@ static Property x86_cpu_properties[] = {
>      DEFINE_PROP_BOOL("pmu", X86CPU, enable_pmu, false),
>  
>      DEFINE_PROP_UINT32("hv-spinlocks", X86CPU, hyperv_spinlock_attempts,
> -                       HYPERV_SPINLOCK_NEVER_RETRY),
> +                       HYPERV_SPINLOCK_NEVER_NOTIFY),
>      DEFINE_PROP_BIT64("hv-relaxed", X86CPU, hyperv_features,
>                        HYPERV_FEAT_RELAXED, 0),
>      DEFINE_PROP_BIT64("hv-vapic", X86CPU, hyperv_features,
> diff --git a/target/i386/cpu.h b/target/i386/cpu.h
> index 408392dbf6f4..80253d1c373b 100644
> --- a/target/i386/cpu.h
> +++ b/target/i386/cpu.h
> @@ -980,8 +980,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
>  #define HYPERV_FEAT_IPI                 13
>  #define HYPERV_FEAT_STIMER_DIRECT       14
>  
> -#ifndef HYPERV_SPINLOCK_NEVER_RETRY
> -#define HYPERV_SPINLOCK_NEVER_RETRY             0xFFFFFFFF
> +#ifndef HYPERV_SPINLOCK_NEVER_NOTIFY
> +#define HYPERV_SPINLOCK_NEVER_NOTIFY             0xFFFFFFFF
>  #endif
>  
>  #define EXCP00_DIVZ	0
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 34f838728dd6..28e9c73cc2a5 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -731,7 +731,7 @@ static bool hyperv_enabled(X86CPU *cpu)
>  {
>      CPUState *cs = CPU(cpu);
>      return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 &&
> -        ((cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY) ||
> +        ((cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_NOTIFY) ||
>           cpu->hyperv_features || cpu->hyperv_passthrough);
>  }
>  
> @@ -1201,7 +1201,7 @@ static int hyperv_handle_properties(CPUState *cs,
>              env->features[FEAT_HV_RECOMM_EAX] = c->eax;
>  
>              /* hv-spinlocks may have been overriden */
> -            if (cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY) {
> +            if (cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_NOTIFY) {
>                  c->ebx = cpu->hyperv_spinlock_attempts;
>              }
>          }
> -- 
> 2.25.4
> 

-- 
Eduardo


Re: [PATCH] i386/kvm: correct the meaning of '0xffffffff' value for hv-spinlocks
Posted by Vitaly Kuznetsov 5 years, 3 months ago
Eduardo Habkost <ehabkost@redhat.com> writes:

> On Fri, May 15, 2020 at 01:48:47PM +0200, Vitaly Kuznetsov wrote:
>> Hyper-V TLFS prior to version 6.0 had a mistake in it: special value
>> '0xffffffff' for CPUID 0x40000004.EBX was called 'never to retry', this
>> looked weird (like why it's not '0' which supposedly have the same effect?)
>> but nobody raised the question. In TLFS version 6.0 the mistake was
>> corrected to 'never notify' which sounds logical. Fix QEMU accordingly.
>> 
>> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>
> I've just found this buried in my inbox, sorry for missing it!

Better late than never! (And, to be honest, I completely forgot about it
as well :-)

>
> Queued for 5.2.
>

Thanks!

-- 
Vitaly