diff mbox series

spapr: add splpar hcalls H_JOIN, H_PROD, H_CONFER

Message ID 20190412054214.707-1-npiggin@gmail.com (mailing list archive)
State New, archived
Headers show
Series spapr: add splpar hcalls H_JOIN, H_PROD, H_CONFER | expand

Commit Message

Nicholas Piggin April 12, 2019, 5:42 a.m. UTC
These implementations have a few deficiencies that are noted, but are
good enough for Linux to use.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>

---
This has been tested with TCG with some Linux hacks to use H_JOIN/H_PROD
for suspend and CPU unplug (plus an implementation of ibm,suspend-me to
do the suspend). Not sure if KVM might need some more work to support
H_JOIN properly, but right now Linux only uses it on PowerVM.


 hw/ppc/spapr_hcall.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

Comments

no-reply@patchew.org April 12, 2019, 5:46 a.m. UTC | #1
Patchew URL: https://patchew.org/QEMU/20190412054214.707-1-npiggin@gmail.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190412054214.707-1-npiggin@gmail.com
Subject: [Qemu-devel] [PATCH] spapr: add splpar hcalls H_JOIN, H_PROD, H_CONFER
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]            patchew/1554822037-329838-1-git-send-email-imammedo@redhat.com -> patchew/1554822037-329838-1-git-send-email-imammedo@redhat.com
 t [tag update]            patchew/20190411161013.4514-1-clg@kaod.org -> patchew/20190411161013.4514-1-clg@kaod.org
 * [new tag]               patchew/20190412054214.707-1-npiggin@gmail.com -> patchew/20190412054214.707-1-npiggin@gmail.com
Switched to a new branch 'test'
2f73cb0a80 spapr: add splpar hcalls H_JOIN, H_PROD, H_CONFER

=== OUTPUT BEGIN ===
ERROR: braces {} are necessary for all arms of this statement
#28: FILE: hw/ppc/spapr_hcall.c:1074:
+    if (env->msr & (1ULL << MSR_EE))
[...]

ERROR: braces {} are necessary for all arms of this statement
#53: FILE: hw/ppc/spapr_hcall.c:1099:
+    if (target != -1 && !CPU(spapr_find_cpu(target)))
[...]

ERROR: braces {} are necessary for all arms of this statement
#61: FILE: hw/ppc/spapr_hcall.c:1107:
+    if (cpu == spapr_find_cpu(target))
[...]

ERROR: braces {} are necessary for all arms of this statement
#93: FILE: hw/ppc/spapr_hcall.c:1139:
+    if (!cs)
[...]

total: 4 errors, 0 warnings, 96 lines checked

Commit 2f73cb0a80a1 (spapr: add splpar hcalls H_JOIN, H_PROD, H_CONFER) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20190412054214.707-1-npiggin@gmail.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
diff mbox series

Patch

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 8a736797b9..6829cadcd3 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -1065,6 +1065,86 @@  static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr,
     return H_SUCCESS;
 }
 
+static target_ulong h_join(PowerPCCPU *cpu, SpaprMachineState *spapr,
+                           target_ulong opcode, target_ulong *args)
+{
+    CPUPPCState *env = &cpu->env;
+    CPUState *cs = 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 = 1;
+    cs->exception_index = EXCP_HALTED;
+    cs->exit_request = 1;
+
+    return H_SUCCESS;
+}
+
+static target_ulong h_confer(PowerPCCPU *cpu, SpaprMachineState *spapr,
+                           target_ulong opcode, target_ulong *args)
+{
+    target_long target = args[0];
+    CPUState *cs = CPU(cpu);
+
+    /*
+     * This does not do a targeted yield or confer, but check the parameter
+     * anyway. -1 means confer to all/any other CPUs.
+     */
+    if (target != -1 && !CPU(spapr_find_cpu(target)))
+        return H_PARAMETER;
+
+    /*
+     * H_CONFER with target == this is not exactly the same as H_JOIN
+     * according to PAPR (e.g., MSR[EE] check and single threaded check
+     * is not done in this case), but unlikely to matter.
+     */
+    if (cpu == spapr_find_cpu(target))
+        return h_join(cpu, spapr, opcode, args);
+
+    /*
+     * This does not implement the dispatch sequence check that PAPR calls for,
+     * but PAPR also specifies a stronger implementation where the target must
+     * be run (or EE, or H_PROD) before H_CONFER returns. Without such a hard
+     * scheduling requirement implemented, there is no correctness reason to
+     * implement the dispatch sequence check.
+     */
+    cs->exception_index = EXCP_YIELD;
+    cpu_loop_exit(cs);
+
+    return H_SUCCESS;
+}
+
+/*
+ * H_PROD and H_CONFER are specified to only modify GPR r3, which is not
+ * achievable running under KVM, although KVM already implements H_CONFER
+ * this way.
+ */
+static target_ulong h_prod(PowerPCCPU *cpu, SpaprMachineState *spapr,
+                           target_ulong opcode, target_ulong *args)
+{
+    target_long target = args[0];
+    CPUState *cs;
+
+    /*
+     * This does not maintain a prod flag for the vCPU that PAPR asks for.
+     */
+
+    cs = CPU(spapr_find_cpu(target));
+    if (!cs)
+        return H_PARAMETER;
+
+    cs->halted = 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 +1940,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);
+    spapr_register_hypercall(H_PROD, h_prod);
+
     spapr_register_hypercall(H_SIGNAL_SYS_RESET, h_signal_sys_reset);
 
     /* processor register resource access h-calls */