Received: from eggs.gnu.org ([209.51.188.92]:33622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hFtpX-0004Cg-8x for qemu-devel@nongnu.org; Mon, 15 Apr 2019 01:06:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hFtpV-0006VD-SV for qemu-devel@nongnu.org; Mon, 15 Apr 2019 01:06:55 -0400 Date: Mon, 15 Apr 2019 15:06:43 +1000 From: Nicholas Piggin References: <20190412093603.18232-1-npiggin@gmail.com> <20190415041359.GE32705@umbus.fritz.box> In-Reply-To: <20190415041359.GE32705@umbus.fritz.box> MIME-Version: 1.0 Message-Id: <1555302690.7m52mtdllv.astroid@bobo.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] spapr: add splpar hcalls H_JOIN, H_PROD, H_CONFER List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: Benjamin Herrenschmidt , =?iso-8859-1?q?C=E9dric?= Le Goater , qemu-devel@nongnu.org, qemu-ppc@nongnu.org David Gibson's on April 15, 2019 2:13 pm: > On Fri, Apr 12, 2019 at 07:36:03PM +1000, Nicholas Piggin wrote: >> These implementations have a few deficiencies that are noted, but are >> good enough for Linux to use. >>=20 >> Signed-off-by: Nicholas Piggin >> --- >>=20 >> Cleaned up checkpatch warnings, sorry I didn't realise that exists. >>=20 >> hw/ppc/spapr_hcall.c | 88 ++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 88 insertions(+) >>=20 >> diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c >> index 8a736797b9..e985bb694d 100644 >> --- a/hw/ppc/spapr_hcall.c >> +++ b/hw/ppc/spapr_hcall.c >> @@ -1065,6 +1065,90 @@ static target_ulong h_cede(PowerPCCPU *cpu, Spapr= MachineState *spapr, >> return H_SUCCESS; >> } >> =20 >> +static target_ulong h_join(PowerPCCPU *cpu, SpaprMachineState *spapr, >> + target_ulong opcode, target_ulong *args) >> +{ >> + CPUPPCState *env =3D &cpu->env; >> + CPUState *cs =3D CPU(cpu); >> + >> + if (env->msr & (1ULL << MSR_EE)) { >> + return H_BAD_MODE; >> + } >> + >> + /* >> + * This should check for single-threaded mode. In practice, Linux >> + * does not try to H_JOIN all CPUs. >> + */ >> + >> + cs->halted =3D 1; >> + cs->exception_index =3D EXCP_HALTED; >> + cs->exit_request =3D 1; >> + >> + return H_SUCCESS; >> +} >> + >> +static target_ulong h_confer(PowerPCCPU *cpu, SpaprMachineState *spapr, >> + target_ulong opcode, target_ulong *args) >> +{ >> + target_long target =3D args[0]; >> + CPUState *cs =3D CPU(cpu); >> + >> + /* >> + * This does not do a targeted yield or confer, but check the param= eter >> + * anyway. -1 means confer to all/any other CPUs. >> + */ >> + if (target !=3D -1 && !CPU(spapr_find_cpu(target))) { >> + return H_PARAMETER; >> + } >> + >> + /* >> + * H_CONFER with target =3D=3D this is not exactly the same as H_JO= IN >> + * according to PAPR (e.g., MSR[EE] check and single threaded check >> + * is not done in this case), but unlikely to matter. >> + */ >> + if (cpu =3D=3D spapr_find_cpu(target)) { >> + return h_join(cpu, spapr, opcode, args); >> + } >> + >> + /* >> + * This does not implement the dispatch sequence check that PAPR ca= lls for, >> + * but PAPR also specifies a stronger implementation where the targ= et must >> + * be run (or EE, or H_PROD) before H_CONFER returns. Without such = a hard >> + * scheduling requirement implemented, there is no correctness reas= on to >> + * implement the dispatch sequence check. >> + */ >> + cs->exception_index =3D EXCP_YIELD; >> + cpu_loop_exit(cs); >> + >> + return H_SUCCESS; >> +} >> + >> +/* >> + * H_PROD and H_CONFER are specified to only modify GPR r3, which is no= t >> + * achievable running under KVM, >=20 > Uh.. why not? sc 1 handler kills ctr and cr0, but I misread the spec, they are not specified to modify _only_ GPR r3, but rather the only GPR modified is r3. cr0 and ctr still in the kill set. >> although KVM already implements H_CONFER >> + * this way. >=20 > And this seems to contradict the above. I just meat it already is implemented with those clobbers, but as above that's not a problem. I'll take the comment out. >> + */ >> +static target_ulong h_prod(PowerPCCPU *cpu, SpaprMachineState *spapr, >> + target_ulong opcode, target_ulong *args) >> +{ >> + target_long target =3D args[0]; >> + CPUState *cs; >> + >> + /* >> + * Should set the prod flag in the VPA. >=20 > So.. why doesn't it? It needs to be cleared at all vCPU dispatch points to SPEC, not just when calling H_CEDE as Ben's patch had. I think complexity would be significant for questionable benefit. Like the dispatch sequence, it seems like the test is trying to cover some race condition for the client but does not really do it well (and for Linux not necessary). prod bit is cleared after vCPU returns from preemption, so it can=20 clear at any time and you can't rely on it, unless you look at=20 dispatch sequence numbers to decipher if it was reset or not. KVM does implement something like the prodded flag as Ben's patch did but that's not to spec AFAIKS. >=20 >> + */ >> + >> + cs =3D CPU(spapr_find_cpu(target)); >> + if (!cs) { >> + return H_PARAMETER; >> + } >> + >> + cs->halted =3D 0; >> + qemu_cpu_kick(cs); >> + >> + return H_SUCCESS; >> +} >> + >> static target_ulong h_rtas(PowerPCCPU *cpu, SpaprMachineState *spapr, >> target_ulong opcode, target_ulong *args) >> { >> @@ -1860,6 +1944,10 @@ static void hypercall_register_types(void) >> /* hcall-splpar */ >> spapr_register_hypercall(H_REGISTER_VPA, h_register_vpa); >> spapr_register_hypercall(H_CEDE, h_cede); >> + spapr_register_hypercall(H_CONFER, h_confer); >> + spapr_register_hypercall(H_JOIN, h_join); >=20 > I don't see any sign that H_JOIN is implemented in KVM, although > H_CONFER and H_PROD certainly are. H_JOIN is not. >> + spapr_register_hypercall(H_PROD, h_prod); >> + >> spapr_register_hypercall(H_SIGNAL_SYS_RESET, h_signal_sys_reset); >> =20 >> /* processor register resource access h-calls */ >=20 > Don't we also need to add something to hypertas-calls to advertise the > availability of these calls to the guest? hcall-splpar is for H_CONFER and H_PROD, H_JOIN also wants hcall-join actually, good point. I could split the patch up and add H_CONFER and H_PROD first. Thanks, Nick =