mirror of https://gitee.com/openkylin/qemu.git
ppc: Add a return value to ppc_set_compat() and ppc_set_compat_all()
As recommended in "qapi/error.h", indicate success / failure with a return value. Since ppc_set_compat() is called from a VMState handler, let's make it an int so that it propagates any negative errno returned by kvmppc_set_compat(). Do the same for ppc_set_compat_all() for consistency, even if it isn't called in a context where a negative errno is required on failure. This will allow to simplify error handling in the callers. Signed-off-by: Greg Kurz <groug@kaod.org> Message-Id: <20200914123505.612812-3-groug@kaod.org> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
9c4d1497e8
commit
2c82e8df4d
|
@ -158,7 +158,7 @@ bool ppc_type_check_compat(const char *cputype, uint32_t compat_pvr,
|
||||||
return pcc_compat(pcc, compat_pvr, min_compat_pvr, max_compat_pvr);
|
return pcc_compat(pcc, compat_pvr, min_compat_pvr, max_compat_pvr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp)
|
int ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp)
|
||||||
{
|
{
|
||||||
const CompatInfo *compat = compat_by_pvr(compat_pvr);
|
const CompatInfo *compat = compat_by_pvr(compat_pvr);
|
||||||
CPUPPCState *env = &cpu->env;
|
CPUPPCState *env = &cpu->env;
|
||||||
|
@ -169,11 +169,11 @@ void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp)
|
||||||
pcr = 0;
|
pcr = 0;
|
||||||
} else if (!compat) {
|
} else if (!compat) {
|
||||||
error_setg(errp, "Unknown compatibility PVR 0x%08"PRIx32, compat_pvr);
|
error_setg(errp, "Unknown compatibility PVR 0x%08"PRIx32, compat_pvr);
|
||||||
return;
|
return -EINVAL;
|
||||||
} else if (!ppc_check_compat(cpu, compat_pvr, 0, 0)) {
|
} else if (!ppc_check_compat(cpu, compat_pvr, 0, 0)) {
|
||||||
error_setg(errp, "Compatibility PVR 0x%08"PRIx32" not valid for CPU",
|
error_setg(errp, "Compatibility PVR 0x%08"PRIx32" not valid for CPU",
|
||||||
compat_pvr);
|
compat_pvr);
|
||||||
return;
|
return -EINVAL;
|
||||||
} else {
|
} else {
|
||||||
pcr = compat->pcr;
|
pcr = compat->pcr;
|
||||||
}
|
}
|
||||||
|
@ -185,17 +185,19 @@ void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp)
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_setg_errno(errp, -ret,
|
error_setg_errno(errp, -ret,
|
||||||
"Unable to set CPU compatibility mode in KVM");
|
"Unable to set CPU compatibility mode in KVM");
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cpu->compat_pvr = compat_pvr;
|
cpu->compat_pvr = compat_pvr;
|
||||||
env->spr[SPR_PCR] = pcr & pcc->pcr_mask;
|
env->spr[SPR_PCR] = pcr & pcc->pcr_mask;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t compat_pvr;
|
uint32_t compat_pvr;
|
||||||
Error *err;
|
Error **errp;
|
||||||
|
int ret;
|
||||||
} SetCompatState;
|
} SetCompatState;
|
||||||
|
|
||||||
static void do_set_compat(CPUState *cs, run_on_cpu_data arg)
|
static void do_set_compat(CPUState *cs, run_on_cpu_data arg)
|
||||||
|
@ -203,26 +205,28 @@ static void do_set_compat(CPUState *cs, run_on_cpu_data arg)
|
||||||
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
||||||
SetCompatState *s = arg.host_ptr;
|
SetCompatState *s = arg.host_ptr;
|
||||||
|
|
||||||
ppc_set_compat(cpu, s->compat_pvr, &s->err);
|
s->ret = ppc_set_compat(cpu, s->compat_pvr, s->errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ppc_set_compat_all(uint32_t compat_pvr, Error **errp)
|
int ppc_set_compat_all(uint32_t compat_pvr, Error **errp)
|
||||||
{
|
{
|
||||||
CPUState *cs;
|
CPUState *cs;
|
||||||
|
|
||||||
CPU_FOREACH(cs) {
|
CPU_FOREACH(cs) {
|
||||||
SetCompatState s = {
|
SetCompatState s = {
|
||||||
.compat_pvr = compat_pvr,
|
.compat_pvr = compat_pvr,
|
||||||
.err = NULL,
|
.errp = errp,
|
||||||
|
.ret = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
run_on_cpu(cs, do_set_compat, RUN_ON_CPU_HOST_PTR(&s));
|
run_on_cpu(cs, do_set_compat, RUN_ON_CPU_HOST_PTR(&s));
|
||||||
|
|
||||||
if (s.err) {
|
if (s.ret < 0) {
|
||||||
error_propagate(errp, s.err);
|
return s.ret;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ppc_compat_max_vthreads(PowerPCCPU *cpu)
|
int ppc_compat_max_vthreads(PowerPCCPU *cpu)
|
||||||
|
|
|
@ -1352,10 +1352,10 @@ bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat_pvr,
|
||||||
bool ppc_type_check_compat(const char *cputype, uint32_t compat_pvr,
|
bool ppc_type_check_compat(const char *cputype, uint32_t compat_pvr,
|
||||||
uint32_t min_compat_pvr, uint32_t max_compat_pvr);
|
uint32_t min_compat_pvr, uint32_t max_compat_pvr);
|
||||||
|
|
||||||
void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp);
|
int ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp);
|
||||||
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
#if !defined(CONFIG_USER_ONLY)
|
||||||
void ppc_set_compat_all(uint32_t compat_pvr, Error **errp);
|
int ppc_set_compat_all(uint32_t compat_pvr, Error **errp);
|
||||||
#endif
|
#endif
|
||||||
int ppc_compat_max_vthreads(PowerPCCPU *cpu);
|
int ppc_compat_max_vthreads(PowerPCCPU *cpu);
|
||||||
void ppc_compat_add_property(Object *obj, const char *name,
|
void ppc_compat_add_property(Object *obj, const char *name,
|
||||||
|
|
Loading…
Reference in New Issue