[Qemu-devel] [PATCH v2] i386/kvm: Fix build with -m32

Max Reitz posted 1 patch 4 years, 10 months ago
Test s390x passed
Test asan passed
Test docker-mingw@fedora passed
Test FreeBSD passed
Test checkpatch passed
Test docker-clang@ubuntu passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20190624193913.28343-1-mreitz@redhat.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>, Richard Henderson <rth@twiddle.net>, Marcelo Tosatti <mtosatti@redhat.com>
target/i386/kvm.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
[Qemu-devel] [PATCH v2] i386/kvm: Fix build with -m32
Posted by Max Reitz 4 years, 10 months ago
find_next_bit() takes a pointer of type "const unsigned long *", but the
first argument passed here is a "uint64_t *".  These types are
incompatible when compiling qemu with -m32.

Just use ctz64() instead.

Fixes: c686193072a47032d83cb4e131dc49ae30f9e5d
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 target/i386/kvm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index e4b4f5756a..31490bf8b5 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1043,14 +1043,15 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid,
     CPUX86State *env = &cpu->env;
     uint32_t r, fw, bits;
     uint64_t deps;
-    int i, dep_feat = 0;
+    int i, dep_feat;
 
     if (!hyperv_feat_enabled(cpu, feature) && !cpu->hyperv_passthrough) {
         return 0;
     }
 
     deps = kvm_hyperv_properties[feature].dependencies;
-    while ((dep_feat = find_next_bit(&deps, 64, dep_feat)) < 64) {
+    while (deps) {
+        dep_feat = ctz64(deps);
         if (!(hyperv_feat_enabled(cpu, dep_feat))) {
                 fprintf(stderr,
                         "Hyper-V %s requires Hyper-V %s\n",
@@ -1058,7 +1059,7 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid,
                         kvm_hyperv_properties[dep_feat].desc);
                 return 1;
         }
-        dep_feat++;
+        deps &= ~(1ull << dep_feat);
     }
 
     for (i = 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i++) {
-- 
2.21.0


Re: [Qemu-devel] [PATCH v2] i386/kvm: Fix build with -m32
Posted by Philippe Mathieu-Daudé 4 years, 10 months ago
On 6/24/19 9:39 PM, Max Reitz wrote:
> find_next_bit() takes a pointer of type "const unsigned long *", but the
> first argument passed here is a "uint64_t *".  These types are
> incompatible when compiling qemu with -m32.
> 
> Just use ctz64() instead.
> 
> Fixes: c686193072a47032d83cb4e131dc49ae30f9e5d
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  target/i386/kvm.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index e4b4f5756a..31490bf8b5 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -1043,14 +1043,15 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid,
>      CPUX86State *env = &cpu->env;
>      uint32_t r, fw, bits;
>      uint64_t deps;
> -    int i, dep_feat = 0;
> +    int i, dep_feat;
>  
>      if (!hyperv_feat_enabled(cpu, feature) && !cpu->hyperv_passthrough) {
>          return 0;
>      }
>  
>      deps = kvm_hyperv_properties[feature].dependencies;
> -    while ((dep_feat = find_next_bit(&deps, 64, dep_feat)) < 64) {
> +    while (deps) {
> +        dep_feat = ctz64(deps);
>          if (!(hyperv_feat_enabled(cpu, dep_feat))) {
>                  fprintf(stderr,
>                          "Hyper-V %s requires Hyper-V %s\n",
> @@ -1058,7 +1059,7 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid,
>                          kvm_hyperv_properties[dep_feat].desc);
>                  return 1;
>          }
> -        dep_feat++;
> +        deps &= ~(1ull << dep_feat);

Easier than using deposit64(), OK.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

>      }
>  
>      for (i = 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i++) {
> 

Re: [Qemu-devel] [PATCH v2] i386/kvm: Fix build with -m32
Posted by Eduardo Habkost 4 years, 10 months ago
On Mon, Jun 24, 2019 at 09:39:13PM +0200, Max Reitz wrote:
> find_next_bit() takes a pointer of type "const unsigned long *", but the
> first argument passed here is a "uint64_t *".  These types are
> incompatible when compiling qemu with -m32.
> 
> Just use ctz64() instead.
> 
> Fixes: c686193072a47032d83cb4e131dc49ae30f9e5d
> Signed-off-by: Max Reitz <mreitz@redhat.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

> ---
>  target/i386/kvm.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index e4b4f5756a..31490bf8b5 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -1043,14 +1043,15 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid,
>      CPUX86State *env = &cpu->env;
>      uint32_t r, fw, bits;
>      uint64_t deps;
> -    int i, dep_feat = 0;
> +    int i, dep_feat;
>  
>      if (!hyperv_feat_enabled(cpu, feature) && !cpu->hyperv_passthrough) {
>          return 0;
>      }
>  
>      deps = kvm_hyperv_properties[feature].dependencies;
> -    while ((dep_feat = find_next_bit(&deps, 64, dep_feat)) < 64) {
> +    while (deps) {
> +        dep_feat = ctz64(deps);
>          if (!(hyperv_feat_enabled(cpu, dep_feat))) {
>                  fprintf(stderr,
>                          "Hyper-V %s requires Hyper-V %s\n",
> @@ -1058,7 +1059,7 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid,
>                          kvm_hyperv_properties[dep_feat].desc);
>                  return 1;
>          }
> -        dep_feat++;
> +        deps &= ~(1ull << dep_feat);
>      }
>  
>      for (i = 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i++) {
> -- 
> 2.21.0
> 

-- 
Eduardo