qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: peter.maydell@linaro.org
Cc: lvivier@redhat.com, aik@ozlabs.ru, qemu-devel@nongnu.org,
	Nicholas Piggin <npiggin@gmail.com>,
	groug@kaod.org, qemu-ppc@nongnu.org,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PULL 15/42] spapr: Implement dispatch tracking for tcg
Date: Wed, 21 Aug 2019 17:25:15 +1000	[thread overview]
Message-ID: <20190821072542.23090-16-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20190821072542.23090-1-david@gibson.dropbear.id.au>

From: Nicholas Piggin <npiggin@gmail.com>

Implement cpu_exec_enter/exit on ppc which calls into new methods of
the same name in PPCVirtualHypervisorClass. These are used by spapr
to implement the splpar VPA dispatch counter initially.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Message-Id: <20190718034214.14948-2-npiggin@gmail.com>
[dwg: Removed unnecessary CONFIG_USER_ONLY checks as suggested by gkurz]
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr.c                  | 48 +++++++++++++++++++++++++++++++++
 hw/ppc/spapr_hcall.c            |  5 ----
 include/hw/ppc/spapr.h          |  7 +++++
 target/ppc/cpu.h                |  4 +++
 target/ppc/translate_init.inc.c | 27 +++++++++++++++++++
 5 files changed, 86 insertions(+), 5 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 22a45c3737..08cc7c2bd6 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -4306,6 +4306,52 @@ PowerPCCPU *spapr_find_cpu(int vcpu_id)
     return NULL;
 }
 
+static void spapr_cpu_exec_enter(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu)
+{
+    SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu);
+
+    /* These are only called by TCG, KVM maintains dispatch state */
+
+    if (spapr_cpu->vpa_addr) {
+        CPUState *cs = CPU(cpu);
+        uint32_t dispatch;
+
+        dispatch = ldl_be_phys(cs->as,
+                               spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER);
+        dispatch++;
+        if ((dispatch & 1) != 0) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "VPA: incorrect dispatch counter value for "
+                          "dispatched partition %u, correcting.\n", dispatch);
+            dispatch++;
+        }
+        stl_be_phys(cs->as,
+                    spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER, dispatch);
+    }
+}
+
+static void spapr_cpu_exec_exit(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu)
+{
+    SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu);
+
+    if (spapr_cpu->vpa_addr) {
+        CPUState *cs = CPU(cpu);
+        uint32_t dispatch;
+
+        dispatch = ldl_be_phys(cs->as,
+                               spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER);
+        dispatch++;
+        if ((dispatch & 1) != 1) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "VPA: incorrect dispatch counter value for "
+                          "preempted partition %u, correcting.\n", dispatch);
+            dispatch++;
+        }
+        stl_be_phys(cs->as,
+                    spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER, dispatch);
+    }
+}
+
 static void spapr_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -4362,6 +4408,8 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
     vhc->hpte_set_r = spapr_hpte_set_r;
     vhc->get_pate = spapr_get_pate;
     vhc->encode_hpt_for_kvm_pr = spapr_encode_hpt_for_kvm_pr;
+    vhc->cpu_exec_enter = spapr_cpu_exec_enter;
+    vhc->cpu_exec_exit = spapr_cpu_exec_exit;
     xic->ics_get = spapr_ics_get;
     xic->ics_resend = spapr_ics_resend;
     xic->icp_get = spapr_icp_get;
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 47b566882b..4c5ea17250 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -875,11 +875,6 @@ unmap_out:
 #define FLAGS_DEREGISTER_DTL       0x0000c00000000000ULL
 #define FLAGS_DEREGISTER_SLBSHADOW 0x0000e00000000000ULL
 
-#define VPA_MIN_SIZE           640
-#define VPA_SIZE_OFFSET        0x4
-#define VPA_SHARED_PROC_OFFSET 0x9
-#define VPA_SHARED_PROC_VAL    0x2
-
 static target_ulong register_vpa(PowerPCCPU *cpu, target_ulong vpa)
 {
     CPUState *cs = CPU(cpu);
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 60553d32c4..5d36eec9d0 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -525,6 +525,13 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);
 target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,
                              target_ulong *args);
 
+/* Virtual Processor Area structure constants */
+#define VPA_MIN_SIZE           640
+#define VPA_SIZE_OFFSET        0x4
+#define VPA_SHARED_PROC_OFFSET 0x9
+#define VPA_SHARED_PROC_VAL    0x2
+#define VPA_DISPATCH_COUNTER   0x100
+
 /* ibm,set-eeh-option */
 #define RTAS_EEH_DISABLE                 0
 #define RTAS_EEH_ENABLE                  1
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 630a25c246..50245a8c4d 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -1224,6 +1224,10 @@ struct PPCVirtualHypervisorClass {
     void (*hpte_set_r)(PPCVirtualHypervisor *vhyp, hwaddr ptex, uint64_t pte1);
     void (*get_pate)(PPCVirtualHypervisor *vhyp, ppc_v3_pate_t *entry);
     target_ulong (*encode_hpt_for_kvm_pr)(PPCVirtualHypervisor *vhyp);
+#ifndef CONFIG_USER_ONLY
+    void (*cpu_exec_enter)(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu);
+    void (*cpu_exec_exit)(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu);
+#endif
 };
 
 #define TYPE_PPC_VIRTUAL_HYPERVISOR "ppc-virtual-hypervisor"
diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c
index 9cd2033bb9..c9fcd87095 100644
--- a/target/ppc/translate_init.inc.c
+++ b/target/ppc/translate_init.inc.c
@@ -10469,6 +10469,28 @@ static bool ppc_cpu_is_big_endian(CPUState *cs)
 
     return !msr_le;
 }
+
+static void ppc_cpu_exec_enter(CPUState *cs)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(cs);
+
+    if (cpu->vhyp) {
+        PPCVirtualHypervisorClass *vhc =
+            PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp);
+        vhc->cpu_exec_enter(cpu->vhyp, cpu);
+    }
+}
+
+static void ppc_cpu_exec_exit(CPUState *cs)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(cs);
+
+    if (cpu->vhyp) {
+        PPCVirtualHypervisorClass *vhc =
+            PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp);
+        vhc->cpu_exec_exit(cpu->vhyp, cpu);
+    }
+}
 #endif
 
 static void ppc_cpu_instance_init(Object *obj)
@@ -10622,6 +10644,11 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
     cc->tcg_initialize = ppc_translate_init;
     cc->tlb_fill = ppc_cpu_tlb_fill;
 #endif
+#ifndef CONFIG_USER_ONLY
+    cc->cpu_exec_enter = ppc_cpu_exec_enter;
+    cc->cpu_exec_exit = ppc_cpu_exec_exit;
+#endif
+
     cc->disas_set_info = ppc_disas_set_info;
 
     dc->fw_name = "PowerPC,UNKNOWN";
-- 
2.21.0



  parent reply	other threads:[~2019-08-21  7:40 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21  7:25 [Qemu-devel] [PULL 00/42] ppc-for-4.2 queue 20190821 David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 01/42] spapr: quantify error messages regarding capability settings David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 02/42] spapr_iommu: Fix xlate trace to print translated address David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 03/42] hw: add compat machines for 4.2 David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 04/42] spapr_pci: Allow 2MiB and 16MiB IOMMU pagesizes by default David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 05/42] migration: Do not re-read the clock on pre_save in case of paused guest David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 06/42] target/ppc: Optimize emulation of lvsl and lvsr instructions David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 07/42] target/ppc: Optimize emulation of vsl and vsr instructions David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 08/42] target/ppc: move opcode decode tables to PowerPCCPU David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 09/42] target/ppc: Optimize emulation of vgbbd instruction David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 10/42] target/ppc: Optimize emulation of vclzd instruction David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 11/42] target/ppc: Optimize emulation of vclzw instruction David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 12/42] ppc: fix memory leak in spapr_caps_add_properties David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 13/42] ppc: fix memory leak in spapr_dt_drc() David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 14/42] ppc: fix leak in h_client_architecture_support David Gibson
2019-08-21  7:25 ` David Gibson [this message]
2019-08-21  7:25 ` [Qemu-devel] [PULL 16/42] spapr: Implement H_PROD David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 17/42] spapr: Implement H_CONFER David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 18/42] spapr: Implement H_JOIN David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 19/42] docs/specs: initial spec summary for Ultravisor-related hcalls David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 20/42] spapr: initial implementation for H_TPM_COMM/spapr-tpm-proxy David Gibson
2019-09-09 17:23   ` Peter Maydell
2019-09-09 17:51     ` Greg Kurz
2019-08-21  7:25 ` [Qemu-devel] [PULL 21/42] pseries: Update SLOF firmware image David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 22/42] ppc/xive: use an abstract type for XiveNotifier David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 23/42] ppc/xive: Implement TM_PULL_OS_CTX special command David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 24/42] ppc/xive: Provide backlog support David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 25/42] ppc/xive: Provide escalation support David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 26/42] ppc/xive: Provide unconditional " David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 27/42] ppc/xive: Provide silent " David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 28/42] ppc/xive: Improve 'info pic' support David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 29/42] machine: Add wakeup method to MachineClass David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 30/42] i386: use machine class ->wakeup method David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 31/42] spapr: Implement ibm,suspend-me David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 32/42] ppc: remove idle_timer logic David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 33/42] spapr/pci: Consolidate de-allocation of MSIs David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 34/42] spapr/pci: Free MSIs during reset David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 35/42] spapr/irq: Drop spapr_irq_msi_reset() David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 36/42] spapr: Implement better workaround in spapr-vty device David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 37/42] spapr/xive: Mask the EAS when allocating an IRQ David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 38/42] target/ppc: Add Directed Privileged Door-bell Exception State (DPDES) SPR David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 39/42] ppc: Add support for 'mffsl' instruction David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 40/42] ppc: conform to processor User's Manual for xscvdpspn David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 41/42] ppc: Fix emulated INFINITY and NAN conversions David Gibson
2019-08-21  7:25 ` [Qemu-devel] [PULL 42/42] ppc: Fix emulated single to double denormalized conversions David Gibson
2019-08-21  8:25 ` [Qemu-devel] [PULL 00/42] ppc-for-4.2 queue 20190821 no-reply
2019-08-21 14:18 ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190821072542.23090-16-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=aik@ozlabs.ru \
    --cc=groug@kaod.org \
    --cc=lvivier@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).