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

2024-04-19 Thread Thomas Huth

On 19/04/2024 08.57, Zhao Liu wrote:

From: Zhao Liu 

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.

Signed-off-by: Zhao Liu 
---
  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(-)


Reviewed-by: Thomas Huth 




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

2024-04-19 Thread Zhao Liu
From: Zhao Liu 

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.

Signed-off-by: Zhao Liu 
---
 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(-)

diff --git a/target/s390x/cpu_models.h b/target/s390x/cpu_models.h
index 5041c1e10fed..1be94294319d 100644
--- a/target/s390x/cpu_models.h
+++ b/target/s390x/cpu_models.h
@@ -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)
 {
diff --git a/target/s390x/cpu_models_sysemu.c b/target/s390x/cpu_models_sysemu.c
index 2d99218069cb..bf855c659d5e 100644
--- a/target/s390x/cpu_models_sysemu.c
+++ b/target/s390x/cpu_models_sysemu.c
@@ -405,8 +405,7 @@ void apply_cpu_model(const S390CPUModel *model, Error 
**errp)
 }
 
 if (kvm_enabled()) {
-kvm_s390_apply_cpu_model(model, );
-if (err) {
+if (!kvm_s390_apply_cpu_model(model, )) {
 error_propagate(errp, err);
 return;
 }
diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c
index 57937b4ddbef..6334fb84141b 100644
--- a/target/s390x/kvm/kvm.c
+++ b/target/s390x/kvm/kvm.c
@@ -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, );
 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)
-- 
2.34.1