target/s390x/cpu_models: Make kvm_s390_apply_cpu_model() return boolean

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 <zhao1.liu@intel.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20240425031232.1586401-7-zhao1.liu@intel.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Zhao Liu 2024-04-25 11:12:31 +08:00 committed by Thomas Huth
parent c6f1baf2d5
commit 38098df346
3 changed files with 10 additions and 10 deletions

View File

@ -116,6 +116,6 @@ S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
bool kvm_s390_cpu_models_supported(void); bool kvm_s390_cpu_models_supported(void);
bool 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); bool kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp);
#endif /* TARGET_S390X_CPU_MODELS_H */ #endif /* TARGET_S390X_CPU_MODELS_H */

View File

@ -405,8 +405,7 @@ void apply_cpu_model(const S390CPUModel *model, Error **errp)
} }
if (kvm_enabled()) { if (kvm_enabled()) {
kvm_s390_apply_cpu_model(model, &err); if (!kvm_s390_apply_cpu_model(model, &err)) {
if (err) {
error_propagate(errp, err); error_propagate(errp, err);
return; return;
} }

View File

@ -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 = { struct kvm_s390_vm_cpu_processor prop = {
.fac_list = { 0 }, .fac_list = { 0 },
@ -2560,11 +2560,11 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
if (kvm_s390_cmma_available()) { if (kvm_s390_cmma_available()) {
kvm_s390_enable_cmma(); kvm_s390_enable_cmma();
} }
return; return true;
} }
if (!kvm_s390_cpu_models_supported()) { if (!kvm_s390_cpu_models_supported()) {
error_setg(errp, "KVM doesn't support CPU models"); error_setg(errp, "KVM doesn't support CPU models");
return; return false;
} }
prop.cpuid = s390_cpuid_from_cpu_model(model); prop.cpuid = s390_cpuid_from_cpu_model(model);
prop.ibc = s390_ibc_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); rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
if (rc) { if (rc) {
error_setg(errp, "KVM: Error configuring the CPU model: %d", rc); error_setg(errp, "KVM: Error configuring the CPU model: %d", rc);
return; return false;
} }
/* configure cpu features indicated e.g. via SCLP */ /* configure cpu features indicated e.g. via SCLP */
rc = configure_cpu_feat(model->features); rc = configure_cpu_feat(model->features);
if (rc) { if (rc) {
error_setg(errp, "KVM: Error configuring CPU features: %d", rc); error_setg(errp, "KVM: Error configuring CPU features: %d", rc);
return; return false;
} }
/* configure cpu subfunctions indicated via query / test bit */ /* configure cpu subfunctions indicated via query / test bit */
rc = configure_cpu_subfunc(model->features); rc = configure_cpu_subfunc(model->features);
if (rc) { if (rc) {
error_setg(errp, "KVM: Error configuring CPU subfunctions: %d", rc); error_setg(errp, "KVM: Error configuring CPU subfunctions: %d", rc);
return; return false;
} }
/* enable CMM via CMMA */ /* enable CMM via CMMA */
if (test_bit(S390_FEAT_CMM, model->features)) { 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); rc = configure_uv_feat_guest(model->features);
if (rc) { if (rc) {
error_setg(errp, "KVM: Error configuring CPU UV features %d", rc); error_setg(errp, "KVM: Error configuring CPU UV features %d", rc);
return; return false;
} }
return true;
} }
void kvm_s390_restart_interrupt(S390CPU *cpu) void kvm_s390_restart_interrupt(S390CPU *cpu)