Skip to contentSkip to conversation

s390x/cpu_models: Misc cleanup on returned error code and local @err variables

PATCH In review Zhao Liu 3 participants 20 messages Apr 19, 2024 – Apr 22, 2024

lore
Share & tools
lore

Zhao Liu

author
#0 lore raw

cover s390x/cpu_models: Misc cleanup on returned error code and local @err variables

From: Zhao Liu <[email protected]>

Hi list,

This series is the followup of Thomas' suggestion in previous ERRP_GUARD() cleanup[1]. And based on Thomas' thoughts, I tried to clean up as many of the other related places (in s390x/cpu_models.c).

[1]: https://lore.kernel.org/qemu-devel/[email protected]/

Regards,
Zhao
---
Zhao Liu (6):
target/s390x/cpu_model: Make check_compatibility() return boolean target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model() target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return
boolean
target/s390x/cpu_models: Drop local @err in get_max_cpu_model() target/s390x/cpu_models: Make kvm_s390_apply_cpu_model() return
boolean
target/s390x/cpu_models_sysemu: Drop local @err in apply_cpu_model()

 target/s390x/cpu_models.c        | 25 ++++++++++---------------
 target/s390x/cpu_models.h        | 10 ++++++----
 target/s390x/cpu_models_sysemu.c |  5 +----
 target/s390x/kvm/kvm.c           | 28 +++++++++++++++-------------
 4 files changed, 32 insertions(+), 36 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/6 target/s390x/cpu_model: Make check_compatibility() return boolean

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

With returned boolean, there's no need to check @err.

---
 target/s390x/cpu_models.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
target/s390x/cpu_models.c +7 -7
index 8ed3bb6a27b3..8cb47d905fb4 100644
@@ -510,7 +510,7 @@ static void check_compat_model_failed(Error **errp,
     return;
 }
 
-static void check_compatibility(const S390CPUModel *max_model,
+static bool check_compatibility(const S390CPUModel *max_model,
                                 const S390CPUModel *model, Error **errp)
 {
     ERRP_GUARD();
@@ -518,11 +518,11 @@ static void check_compatibility(const S390CPUModel *max_model,
 
     if (model->def->gen > max_model->def->gen) {
         check_compat_model_failed(errp, max_model, "Selected CPU generation is too new");
-        return;
+        return false;
     } else if (model->def->gen == max_model->def->gen &&
                model->def->ec_ga > max_model->def->ec_ga) {
         check_compat_model_failed(errp, max_model, "Selected CPU GA level is too new");
-        return;
+        return false;
     }
 
 #ifndef CONFIG_USER_ONLY
@@ -530,14 +530,14 @@ static void check_compatibility(const S390CPUModel *max_model,
         error_setg(errp, "The unpack facility is not compatible with "
                    "the --only-migratable option. You must remove either "
                    "the 'unpack' facility or the --only-migratable option");
-        return;
+        return false;
     }
 #endif
 
     /* detect the missing features to properly report them */
     bitmap_andnot(missing, model->features, max_model->features, S390_FEAT_MAX);
     if (bitmap_empty(missing, S390_FEAT_MAX)) {
-        return;
+        return true;
     }
 
     error_setg(errp, " ");
@@ -546,6 +546,7 @@ static void check_compatibility(const S390CPUModel *max_model,
                   "available in the current configuration: ");
     error_append_hint(errp,
                       "Consider a different accelerator, QEMU, or kernel version\n");
+    return false;
 }
 
 S390CPUModel *get_max_cpu_model(Error **errp)
@@ -605,8 +606,7 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)
     cpu->model->cpu_ver = max_model->cpu_ver;
 
     check_consistency(cpu->model);
-    check_compatibility(max_model, cpu->model, &err);
-    if (err) {
+    if (!check_compatibility(max_model, cpu->model, &err)) {
         error_propagate(errp, err);
         return;
     }
Signature · 1 line
2.34.1
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] target/s390x/cpu_model: Make check_compatibility() return boolean

Quoted 5 lines · Zhao Liu

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

Quoted 7 lines

With returned boolean, there's no need to check @err.

---
  target/s390x/cpu_models.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
author
#3 lore raw

PATCH 2/6 target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model()

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

Use @errp to fetech error information directly and drop the local virable @err.

---
 target/s390x/cpu_models.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
target/s390x/cpu_models.c +1 -3
index 8cb47d905fb4..052540a866ac 100644
@@ -577,7 +577,6 @@ S390CPUModel *get_max_cpu_model(Error **errp)
 void s390_realize_cpu_model(CPUState *cs, Error **errp)
 {
     ERRP_GUARD();
-    Error *err = NULL;
     S390CPUClass *xcc = S390_CPU_GET_CLASS(cs);
     S390CPU *cpu = S390_CPU(cs);
     const S390CPUModel *max_model;
@@ -606,8 +605,7 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)
     cpu->model->cpu_ver = max_model->cpu_ver;
 
     check_consistency(cpu->model);
-    if (!check_compatibility(max_model, cpu->model, &err)) {
-        error_propagate(errp, err);
+    if (!check_compatibility(max_model, cpu->model, errp)) {
         return;
     }
 
Signature · 1 line
2.34.1
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model()

Quoted 3 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Use @errp to fetech error information directly and drop the local

s/fetech/fetch/

Quoted 1 line

virable @err.

s/virable/variable/

Quoted 5 lines
---
  target/s390x/cpu_models.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

With the typos fixed:

author
#5 lore raw

Re: [PATCH 2/6] target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model()

Quoted 16 lines · Thomas Huth

Date: Fri, 19 Apr 2024 09:39:53 +0200
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH 2/6] target/s390x/cpu_model: Drop local @err in
s390_realize_cpu_model()

Quoted 3 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Use @errp to fetech error information directly and drop the local

s/fetech/fetch/

Quoted 1 line

virable @err.

s/virable/variable/

Quoted 9 lines
Quoted 5 lines
---
  target/s390x/cpu_models.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

With the typos fixed:

Thanks! --codespell check also missed them. Will fix!

Regards,
Zhao

author
#6 lore raw

PATCH 3/6 target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

So make kvm_s390_get_host_cpu_model() return boolean and check the returned boolean in get_max_cpu_model() instead of accessing @err.

Additionally, since now get_max_cpu_model() returns directly if kvm_s390_get_host_cpu_model() fills @err, so make kvm_s390_get_host_cpu_model() return true by default for the non-KVM case in target/s390x/cpu_models.h.

---
 target/s390x/cpu_models.c |  9 ++++-----
 target/s390x/cpu_models.h |  5 +++--
 target/s390x/kvm/kvm.c    | 13 +++++++------
 3 files changed, 14 insertions(+), 13 deletions(-)
target/s390x/cpu_models.c +4 -5
index 052540a866ac..a0e4acb707d7 100644
@@ -560,16 +560,15 @@ S390CPUModel *get_max_cpu_model(Error **errp)
     }
 
     if (kvm_enabled()) {
-        kvm_s390_get_host_cpu_model(&max_model, &err);
+        if (!kvm_s390_get_host_cpu_model(&max_model, &err)) {
+            error_propagate(errp, err);
+            return NULL;
+        }
     } else {
         max_model.def = s390_find_cpu_def(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
                                           QEMU_MAX_CPU_EC_GA, NULL);
         bitmap_copy(max_model.features, qemu_max_cpu_feat, S390_FEAT_MAX);
     }
-    if (err) {
-        error_propagate(errp, err);
-        return NULL;
-    }
     cached = true;
     return &max_model;
 }
target/s390x/cpu_models.h +3 -2
index d7b89129891a..5041c1e10fed 100644
@@ -116,12 +116,13 @@ S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
 
 #ifdef CONFIG_KVM
 bool kvm_s390_cpu_models_supported(void);
-void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp);
+bool kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp);
 void kvm_s390_apply_cpu_model(const S390CPUModel *model,  Error **errp);
 #else
-static inline void kvm_s390_get_host_cpu_model(S390CPUModel *model,
+static inline bool kvm_s390_get_host_cpu_model(S390CPUModel *model,
                                                Error **errp)
 {
+    return true;
 }
 static inline void kvm_s390_apply_cpu_model(const S390CPUModel *model,
                                             Error **errp)
target/s390x/kvm/kvm.c +7 -6
index 4ce809c5d46b..57937b4ddbef 100644
@@ -2375,7 +2375,7 @@ bool kvm_s390_cpu_models_supported(void)
                              KVM_S390_VM_CPU_MACHINE_SUBFUNC);
 }
 
-void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
+bool kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
 {
     struct kvm_s390_vm_cpu_machine prop = {};
     struct kvm_device_attr attr = {
@@ -2390,14 +2390,14 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
 
     if (!kvm_s390_cpu_models_supported()) {
         error_setg(errp, "KVM doesn't support CPU models");
-        return;
+        return false;
     }
 
     /* query the basic cpu model properties */
     rc = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
     if (rc) {
         error_setg(errp, "KVM: Error querying host CPU model: %d", rc);
-        return;
+        return false;
     }
 
     cpu_type = cpuid_type(prop.cpuid);
@@ -2420,13 +2420,13 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
     rc = query_cpu_feat(model->features);
     if (rc) {
         error_setg(errp, "KVM: Error querying CPU features: %d", rc);
-        return;
+        return false;
     }
     /* get supported cpu subfunctions indicated via query / test bit */
     rc = query_cpu_subfunc(model->features);
     if (rc) {
         error_setg(errp, "KVM: Error querying CPU subfunctions: %d", rc);
-        return;
+        return false;
     }
 
     /* PTFF subfunctions might be indicated although kernel support missing */
@@ -2482,7 +2482,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
     }
     if (!model->def) {
         error_setg(errp, "KVM: host CPU model could not be identified");
-        return;
+        return false;
     }
     /* for now, we can only provide the AP feature with HW support */
     if (ap_available()) {
@@ -2506,6 +2506,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
     /* strip of features that are not part of the maximum model */
     bitmap_and(model->features, model->features, model->def->full_feat,
                S390_FEAT_MAX);
+    return true;
 }
 
 static int configure_uv_feat_guest(const S390FeatBitmap features)
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean

Quoted 25 lines · Zhao Liu

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

So make kvm_s390_get_host_cpu_model() return boolean and check the returned boolean in get_max_cpu_model() instead of accessing @err.

Additionally, since now get_max_cpu_model() returns directly if kvm_s390_get_host_cpu_model() fills @err, so make kvm_s390_get_host_cpu_model() return true by default for the non-KVM case in target/s390x/cpu_models.h.

---
  target/s390x/cpu_models.c |  9 ++++-----
  target/s390x/cpu_models.h |  5 +++--
  target/s390x/kvm/kvm.c    | 13 +++++++------
  3 files changed, 14 insertions(+), 13 deletions(-)
target/s390x/cpu_models.c +0 -0
index 052540a866ac..a0e4acb707d7 100644

target/s390x/cpu_models.c S390CPUModel *get_max_cpu_model(Error **errp) · line 562

Quoted 3 lines
target/s390x/cpu_models.c +0 -0
@@ -560,16 +560,15 @@ S390CPUModel *get_max_cpu_model(Error **errp)
      }
 
      if (kvm_enabled()) {

Nitpicking, we could move @err declaration here:

          Error *err = NULL;
Quoted 17 lines
target/s390x/cpu_models.c +4 -5
-        kvm_s390_get_host_cpu_model(&max_model, &err);
+        if (!kvm_s390_get_host_cpu_model(&max_model, &err)) {
+            error_propagate(errp, err);
+            return NULL;
+        }
      } else {
          max_model.def = s390_find_cpu_def(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
                                            QEMU_MAX_CPU_EC_GA, NULL);
          bitmap_copy(max_model.features, qemu_max_cpu_feat, S390_FEAT_MAX);
      }
-    if (err) {
-        error_propagate(errp, err);
-        return NULL;
-    }
      cached = true;
      return &max_model;
  }
author
#8 lore raw

Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean

Quoted 11 lines

target/s390x/cpu_models.c S390CPUModel *get_max_cpu_model(Error **errp) · line 561

Quoted 7 lines
target/s390x/cpu_models.c +0 -0
index 052540a866ac..a0e4acb707d7 100644
@@ -560,16 +560,15 @@ S390CPUModel *get_max_cpu_model(Error **errp)
      }
      if (kvm_enabled()) {

Nitpicking, we could move @err declaration here:

          Error *err = NULL;

Yeah! Next patch removes this variable completely, so I think it's OK not to move. ;-)

Thanks,
Zhao

Quoted 18 lines
Quoted 17 lines
target/s390x/cpu_models.c +4 -5
-        kvm_s390_get_host_cpu_model(&max_model, &err);
+        if (!kvm_s390_get_host_cpu_model(&max_model, &err)) {
+            error_propagate(errp, err);
+            return NULL;
+        }
      } else {
          max_model.def = s390_find_cpu_def(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
                                            QEMU_MAX_CPU_EC_GA, NULL);
          bitmap_copy(max_model.features, qemu_max_cpu_feat, S390_FEAT_MAX);
      }
-    if (err) {
-        error_propagate(errp, err);
-        return NULL;
-    }
      cached = true;
      return &max_model;
  }
#9 lore raw

Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean

In reply to Zhao Liu
Quoted 5 lines · Zhao Liu

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

Quoted 7 lines

So make kvm_s390_get_host_cpu_model() return boolean and check the returned boolean in get_max_cpu_model() instead of accessing @err.

Additionally, since now get_max_cpu_model() returns directly if kvm_s390_get_host_cpu_model() fills @err, so make kvm_s390_get_host_cpu_model() return true by default for the non-KVM case in target/s390x/cpu_models.h.

You could also argue the other way round that there should be something in *model if it returns "true" ... anyway, the stub should never be executed, so it likely doesn't matter too much, but I'd still prefer if we'd rather return "false" in the non-KVM stub instead.

Quoted 7 lines

index d7b89129891a..5041c1e10fed 100644

target/s390x/cpu_models.h +0 -0
@@ -116,12 +116,13 @@ S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
 
  #ifdef CONFIG_KVM
  bool kvm_s390_cpu_models_supported(void);

target/s390x/cpu_models.h S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga, · line 126

Quoted 10 lines
target/s390x/cpu_models.h +3 -2
-void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp);
+bool kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp);
  void kvm_s390_apply_cpu_model(const S390CPUModel *model,  Error **errp);
  #else
-static inline void kvm_s390_get_host_cpu_model(S390CPUModel *model,
+static inline bool kvm_s390_get_host_cpu_model(S390CPUModel *model,
                                                 Error **errp)
  {
+    return true;
  }

Thomas

author
#10 lore raw

Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean

Hi Thomas,

Quoted 19 lines · Thomas Huth

Date: Fri, 19 Apr 2024 09:50:46 +0200
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH 3/6] target/s390x/cpu_models: Make
kvm_s390_get_host_cpu_model() return boolean

Quoted 5 lines · Zhao Liu

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

Quoted 7 lines

So make kvm_s390_get_host_cpu_model() return boolean and check the returned boolean in get_max_cpu_model() instead of accessing @err.

Additionally, since now get_max_cpu_model() returns directly if kvm_s390_get_host_cpu_model() fills @err, so make kvm_s390_get_host_cpu_model() return true by default for the non-KVM case in target/s390x/cpu_models.h.

Quoted 4 lines

You could also argue the other way round that there should be something in *model if it returns "true" ... anyway, the stub should never be executed, so it likely doesn't matter too much, but I'd still prefer if we'd rather return "false" in the non-KVM stub instead.

I see, since this interface in wrapped in kvm_enabled() condition, so the non-kvm sutb wouldn't be called.

Thanks! Will change to return false.

Regards,
Zhao

#11 lore raw

Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean

Quoted 27 lines · Zhao Liu

Hi Thomas,

Quoted 19 lines · Thomas Huth

Date: Fri, 19 Apr 2024 09:50:46 +0200
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH 3/6] target/s390x/cpu_models: Make
kvm_s390_get_host_cpu_model() return boolean

Quoted 5 lines · Zhao Liu

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

Quoted 7 lines

So make kvm_s390_get_host_cpu_model() return boolean and check the returned boolean in get_max_cpu_model() instead of accessing @err.

Additionally, since now get_max_cpu_model() returns directly if kvm_s390_get_host_cpu_model() fills @err, so make kvm_s390_get_host_cpu_model() return true by default for the non-KVM case in target/s390x/cpu_models.h.

Quoted 4 lines

You could also argue the other way round that there should be something in *model if it returns "true" ... anyway, the stub should never be executed, so it likely doesn't matter too much, but I'd still prefer if we'd rather return "false" in the non-KVM stub instead.

Quoted 4 lines

I see, since this interface in wrapped in kvm_enabled() condition, so the non-kvm sutb wouldn't be called.

Thanks! Will change to return false.

Or try to rebase your series on this untested patch:
https://lore.kernel.org/qemu-devel/[email protected]/

author
#12 lore raw

Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean

Quoted 33 lines · Philippe Mathieu-Daudé

Date: Fri, 19 Apr 2024 11:08:22 +0200
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH 3/6] target/s390x/cpu_models: Make
kvm_s390_get_host_cpu_model() return boolean

Quoted 27 lines · Zhao Liu

Hi Thomas,

Quoted 23 lines · Thomas Huth

Date: Fri, 19 Apr 2024 09:50:46 +0200
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH 3/6] target/s390x/cpu_models: Make
kvm_s390_get_host_cpu_model() return boolean

Quoted 5 lines · Zhao Liu

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

Quoted 7 lines

So make kvm_s390_get_host_cpu_model() return boolean and check the returned boolean in get_max_cpu_model() instead of accessing @err.

Additionally, since now get_max_cpu_model() returns directly if kvm_s390_get_host_cpu_model() fills @err, so make kvm_s390_get_host_cpu_model() return true by default for the non-KVM case in target/s390x/cpu_models.h.

You could also argue the other way round that there should be something in *model if it returns "true" ... anyway, the stub should never be executed, so it likely doesn't matter too much, but I'd still prefer if we'd rather return "false" in the non-KVM stub instead.

Quoted 8 lines
Quoted 4 lines

I see, since this interface in wrapped in kvm_enabled() condition, so the non-kvm sutb wouldn't be called.

Thanks! Will change to return false.

Or try to rebase your series on this untested patch:
https://lore.kernel.org/qemu-devel/[email protected]/

Good, pls let me pick this patch into my v2.

author
#13 lore raw

PATCH 4/6 target/s390x/cpu_models: Drop local @err in get_max_cpu_model()

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

Use @errp to fetech error information directly and drop the local virable @err.

---
 target/s390x/cpu_models.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
target/s390x/cpu_models.c +1 -3
index a0e4acb707d7..aae452cfd3fc 100644
@@ -551,7 +551,6 @@ static bool check_compatibility(const S390CPUModel *max_model,
 
 S390CPUModel *get_max_cpu_model(Error **errp)
 {
-    Error *err = NULL;
     static S390CPUModel max_model;
     static bool cached;
 
@@ -560,8 +559,7 @@ S390CPUModel *get_max_cpu_model(Error **errp)
     }
 
     if (kvm_enabled()) {
-        if (!kvm_s390_get_host_cpu_model(&max_model, &err)) {
-            error_propagate(errp, err);
+        if (!kvm_s390_get_host_cpu_model(&max_model, errp)) {
             return NULL;
         }
     } else {
Signature · 1 line
2.34.1
Reviewed-by on v1 4/6
#14 lore raw

Re: [PATCH 4/6] target/s390x/cpu_models: Drop local @err in get_max_cpu_model()

Quoted 4 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Use @errp to fetech error information directly and drop the local virable @err.

Copy-n-paste of the same typos as in patch 2 ;-)

Quoted 18 lines
---
  target/s390x/cpu_models.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
target/s390x/cpu_models.c +0 -1
index a0e4acb707d7..aae452cfd3fc 100644
@@ -551,7 +551,6 @@ static bool check_compatibility(const S390CPUModel *max_model,
 
  S390CPUModel *get_max_cpu_model(Error **errp)
  {
-    Error *err = NULL;
      static S390CPUModel max_model;
      static bool cached;
 

target/s390x/cpu_models.c S390CPUModel *get_max_cpu_model(Error **errp) · line 565

Quoted 9 lines
target/s390x/cpu_models.c +1 -2
@@ -560,8 +559,7 @@ S390CPUModel *get_max_cpu_model(Error **errp)
      }
 
      if (kvm_enabled()) {
-        if (!kvm_s390_get_host_cpu_model(&max_model, &err)) {
-            error_propagate(errp, err);
+        if (!kvm_s390_get_host_cpu_model(&max_model, errp)) {
              return NULL;
          }
      } else {

With the typos fixed:

author
#15 lore raw

PATCH 5/6 target/s390x/cpu_models: Make kvm_s390_apply_cpu_model() return boolean

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

So make kvm_s390_apply_cpu_model() return boolean and check the returned boolean in apply_cpu_model() instead of accessing @err.

---
 target/s390x/cpu_models.h        |  5 +++--
 target/s390x/cpu_models_sysemu.c |  3 +--
 target/s390x/kvm/kvm.c           | 15 ++++++++-------
 3 files changed, 12 insertions(+), 11 deletions(-)
target/s390x/cpu_models.h +3 -2
index 5041c1e10fed..1be94294319d 100644
@@ -117,16 +117,17 @@ S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
 #ifdef CONFIG_KVM
 bool kvm_s390_cpu_models_supported(void);
 bool kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp);
-void kvm_s390_apply_cpu_model(const S390CPUModel *model,  Error **errp);
+bool kvm_s390_apply_cpu_model(const S390CPUModel *model,  Error **errp);
 #else
 static inline bool kvm_s390_get_host_cpu_model(S390CPUModel *model,
                                                Error **errp)
 {
     return true;
 }
-static inline void kvm_s390_apply_cpu_model(const S390CPUModel *model,
+static inline bool kvm_s390_apply_cpu_model(const S390CPUModel *model,
                                             Error **errp)
 {
+    return true;
 }
 static inline bool kvm_s390_cpu_models_supported(void)
 {
target/s390x/cpu_models_sysemu.c +1 -2
index 2d99218069cb..bf855c659d5e 100644
@@ -405,8 +405,7 @@ void apply_cpu_model(const S390CPUModel *model, Error **errp)
     }
 
     if (kvm_enabled()) {
-        kvm_s390_apply_cpu_model(model, &err);
-        if (err) {
+        if (!kvm_s390_apply_cpu_model(model, &err)) {
             error_propagate(errp, err);
             return;
         }
target/s390x/kvm/kvm.c +8 -7
index 57937b4ddbef..6334fb84141b 100644
@@ -2543,7 +2543,7 @@ static void kvm_s390_configure_apie(bool interpret)
     }
 }
 
-void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
+bool kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
 {
     struct kvm_s390_vm_cpu_processor prop  = {
         .fac_list = { 0 },
@@ -2560,11 +2560,11 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
         if (kvm_s390_cmma_available()) {
             kvm_s390_enable_cmma();
         }
-        return;
+        return true;
     }
     if (!kvm_s390_cpu_models_supported()) {
         error_setg(errp, "KVM doesn't support CPU models");
-        return;
+        return false;
     }
     prop.cpuid = s390_cpuid_from_cpu_model(model);
     prop.ibc = s390_ibc_from_cpu_model(model);
@@ -2574,19 +2574,19 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
     rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
     if (rc) {
         error_setg(errp, "KVM: Error configuring the CPU model: %d", rc);
-        return;
+        return false;
     }
     /* configure cpu features indicated e.g. via SCLP */
     rc = configure_cpu_feat(model->features);
     if (rc) {
         error_setg(errp, "KVM: Error configuring CPU features: %d", rc);
-        return;
+        return false;
     }
     /* configure cpu subfunctions indicated via query / test bit */
     rc = configure_cpu_subfunc(model->features);
     if (rc) {
         error_setg(errp, "KVM: Error configuring CPU subfunctions: %d", rc);
-        return;
+        return false;
     }
     /* enable CMM via CMMA */
     if (test_bit(S390_FEAT_CMM, model->features)) {
@@ -2601,8 +2601,9 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
     rc = configure_uv_feat_guest(model->features);
     if (rc) {
         error_setg(errp, "KVM: Error configuring CPU UV features %d", rc);
-        return;
+        return false;
     }
+    return true;
 }
 
 void kvm_s390_restart_interrupt(S390CPU *cpu)
Signature · 1 line
2.34.1
Reviewed-by on v1 5/6
#16 lore raw

Re: [PATCH 5/6] target/s390x/cpu_models: Make kvm_s390_apply_cpu_model() return boolean

Quoted 8 lines · Zhao Liu

From: Zhao Liu <[email protected]>

As error.h suggested, the best practice for callee is to return something to indicate success / failure.

So make kvm_s390_apply_cpu_model() return boolean and check the returned boolean in apply_cpu_model() instead of accessing @err.

Quoted 6 lines
---
  target/s390x/cpu_models.h        |  5 +++--
  target/s390x/cpu_models_sysemu.c |  3 +--
  target/s390x/kvm/kvm.c           | 15 ++++++++-------
  3 files changed, 12 insertions(+), 11 deletions(-)
author
#17 lore raw

PATCH 6/6 target/s390x/cpu_models_sysemu: Drop local @err in apply_cpu_model()

In reply to Zhao Liu

From: Zhao Liu <[email protected]>

Use @errp to fetech error information directly and drop the local virable @err.

---
 target/s390x/cpu_models_sysemu.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
target/s390x/cpu_models_sysemu.c +1 -3
index bf855c659d5e..15be729c3d48 100644
@@ -389,7 +389,6 @@ CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *infoa,
 
 void apply_cpu_model(const S390CPUModel *model, Error **errp)
 {
-    Error *err = NULL;
     static S390CPUModel applied_model;
     static bool applied;
 
@@ -405,8 +404,7 @@ void apply_cpu_model(const S390CPUModel *model, Error **errp)
     }
 
     if (kvm_enabled()) {
-        if (!kvm_s390_apply_cpu_model(model, &err)) {
-            error_propagate(errp, err);
+        if (!kvm_s390_apply_cpu_model(model, errp)) {
             return;
         }
     }
Signature · 1 line
2.34.1
Reviewed-by on v1 6/6
#18 lore raw

Re: [PATCH 6/6] target/s390x/cpu_models_sysemu: Drop local @err in apply_cpu_model()

Quoted 4 lines · Zhao Liu

From: Zhao Liu <[email protected]>

Use @errp to fetech error information directly and drop the local virable @err.

With the typos fixed:

Reviewed-by on the v1 series
#19 lore raw
In reply to Zhao Liu
Quoted 5 lines · Zhao Liu

From: Zhao Liu <[email protected]>

---
Zhao Liu (6):

Quoted 8 lines
   target/s390x/cpu_model: Make check_compatibility() return boolean
   target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model()
   target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return
     boolean
   target/s390x/cpu_models: Drop local @err in get_max_cpu_model()
   target/s390x/cpu_models: Make kvm_s390_apply_cpu_model() return
     boolean
   target/s390x/cpu_models_sysemu: Drop local @err in apply_cpu_model()

Series: