All of lore.kernel.org
 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,
	groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org,
	David Gibson <david@gibson.dropbear.id.au>,
	rth@twiddle.net
Subject: [Qemu-devel] [PULL 07/49] xics/spapr: Prevent RTAS/hypercalls emulation to be used by in-kernel XICS
Date: Tue,  2 Jul 2019 16:08:15 +1000	[thread overview]
Message-ID: <20190702060857.3926-8-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20190702060857.3926-1-david@gibson.dropbear.id.au>

From: Greg Kurz <groug@kaod.org>

The XICS-related RTAS calls and hypercalls in QEMU are not supposed to
be called when the KVM in-kernel XICS is in use.

Add some explicit checks to detect that, print an error message and report
an hardware error to the guest.

Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <156044429419.125694.507569071972451514.stgit@bahia.lab.toulouse-stg.fr.ibm.com>
[dwg: Correction to commit message]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/intc/xics_spapr.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/hw/intc/xics_spapr.c b/hw/intc/xics_spapr.c
index 5a1835e8b1..d470ab5f7a 100644
--- a/hw/intc/xics_spapr.c
+++ b/hw/intc/xics_spapr.c
@@ -41,11 +41,31 @@
  * Guest interfaces
  */
 
+static bool check_in_kernel_xics(const char *func)
+{
+    if (kvm_irqchip_in_kernel()) {
+        error_report("pseries: %s must never be called for in-kernel XICS",
+                     func);
+        return true;
+    }
+
+    return false;
+}
+
+#define CHECK_IN_KERNEL_XICS_HCALL              \
+    do {                                        \
+        if (check_in_kernel_xics(__func__)) {   \
+            return H_HARDWARE;                  \
+        }                                       \
+    } while (0)
+
 static target_ulong h_cppr(PowerPCCPU *cpu, SpaprMachineState *spapr,
                            target_ulong opcode, target_ulong *args)
 {
     target_ulong cppr = args[0];
 
+    CHECK_IN_KERNEL_XICS_HCALL;
+
     icp_set_cppr(spapr_cpu_state(cpu)->icp, cppr);
     return H_SUCCESS;
 }
@@ -56,6 +76,8 @@ static target_ulong h_ipi(PowerPCCPU *cpu, SpaprMachineState *spapr,
     target_ulong mfrr = args[1];
     ICPState *icp = xics_icp_get(XICS_FABRIC(spapr), args[0]);
 
+    CHECK_IN_KERNEL_XICS_HCALL;
+
     if (!icp) {
         return H_PARAMETER;
     }
@@ -69,6 +91,8 @@ static target_ulong h_xirr(PowerPCCPU *cpu, SpaprMachineState *spapr,
 {
     uint32_t xirr = icp_accept(spapr_cpu_state(cpu)->icp);
 
+    CHECK_IN_KERNEL_XICS_HCALL;
+
     args[0] = xirr;
     return H_SUCCESS;
 }
@@ -78,6 +102,8 @@ static target_ulong h_xirr_x(PowerPCCPU *cpu, SpaprMachineState *spapr,
 {
     uint32_t xirr = icp_accept(spapr_cpu_state(cpu)->icp);
 
+    CHECK_IN_KERNEL_XICS_HCALL;
+
     args[0] = xirr;
     args[1] = cpu_get_host_ticks();
     return H_SUCCESS;
@@ -88,6 +114,8 @@ static target_ulong h_eoi(PowerPCCPU *cpu, SpaprMachineState *spapr,
 {
     target_ulong xirr = args[0];
 
+    CHECK_IN_KERNEL_XICS_HCALL;
+
     icp_eoi(spapr_cpu_state(cpu)->icp, xirr);
     return H_SUCCESS;
 }
@@ -99,6 +127,8 @@ static target_ulong h_ipoll(PowerPCCPU *cpu, SpaprMachineState *spapr,
     uint32_t mfrr;
     uint32_t xirr;
 
+    CHECK_IN_KERNEL_XICS_HCALL;
+
     if (!icp) {
         return H_PARAMETER;
     }
@@ -111,6 +141,14 @@ static target_ulong h_ipoll(PowerPCCPU *cpu, SpaprMachineState *spapr,
     return H_SUCCESS;
 }
 
+#define CHECK_IN_KERNEL_XICS_RTAS(rets)                 \
+    do {                                                \
+        if (check_in_kernel_xics(__func__)) {           \
+            rtas_st((rets), 0, RTAS_OUT_HW_ERROR);      \
+            return;                                     \
+        }                                               \
+    } while (0)
+
 static void rtas_set_xive(PowerPCCPU *cpu, SpaprMachineState *spapr,
                           uint32_t token,
                           uint32_t nargs, target_ulong args,
@@ -119,6 +157,8 @@ static void rtas_set_xive(PowerPCCPU *cpu, SpaprMachineState *spapr,
     ICSState *ics = spapr->ics;
     uint32_t nr, srcno, server, priority;
 
+    CHECK_IN_KERNEL_XICS_RTAS(rets);
+
     if ((nargs != 3) || (nret != 1)) {
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
         return;
@@ -152,6 +192,8 @@ static void rtas_get_xive(PowerPCCPU *cpu, SpaprMachineState *spapr,
     ICSState *ics = spapr->ics;
     uint32_t nr, srcno;
 
+    CHECK_IN_KERNEL_XICS_RTAS(rets);
+
     if ((nargs != 1) || (nret != 3)) {
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
         return;
@@ -182,6 +224,8 @@ static void rtas_int_off(PowerPCCPU *cpu, SpaprMachineState *spapr,
     ICSState *ics = spapr->ics;
     uint32_t nr, srcno;
 
+    CHECK_IN_KERNEL_XICS_RTAS(rets);
+
     if ((nargs != 1) || (nret != 1)) {
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
         return;
@@ -213,6 +257,8 @@ static void rtas_int_on(PowerPCCPU *cpu, SpaprMachineState *spapr,
     ICSState *ics = spapr->ics;
     uint32_t nr, srcno;
 
+    CHECK_IN_KERNEL_XICS_RTAS(rets);
+
     if ((nargs != 1) || (nret != 1)) {
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
         return;
-- 
2.21.0



  parent reply	other threads:[~2019-07-02  6:30 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-02  6:08 [Qemu-devel] [PULL 00/49] ppc-for-4.1 queue 20190702 David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 01/49] spapr/rtas: Force big endian compile for rtas David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 02/49] docs: updates on the POWER9 XIVE interrupt controller documentation David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 03/49] ppc/pnv: fix StoreEOI activation David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 04/49] ppc/pnv: fix XSCOM MMIO base address for P9 machines with multiple chips David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 05/49] ppc/pnv: remove xscom_base field from PnvChip David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 06/49] spapr_pci: Fix potential NULL pointer dereference in spapr_dt_pci_bus() David Gibson
2019-07-02  6:08 ` David Gibson [this message]
2019-07-02  6:08 ` [Qemu-devel] [PULL 08/49] xics/spapr: Register RTAS/hypercalls once at machine init David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 09/49] xics/spapr: Detect old KVM XICS on POWER9 hosts David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 10/49] target/ppc: fix compile error in kvmppc_define_rtas_kernel_token() David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 11/49] xics: Add comment about CPU hotplug David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 12/49] target/ppc: remove getVSR()/putVSR() from fpu_helper.c David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 13/49] target/ppc: remove getVSR()/putVSR() from mem_helper.c David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 14/49] spapr_pci: Fix DRC owner in spapr_dt_pci_bus() David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 15/49] xics/spapr: Only emulated XICS should use RTAS/hypercalls emulation David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 16/49] spapr_pci: Drop useless CONFIG_KVM ifdefery David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 17/49] hw/ppc/mac_oldworld: " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 18/49] hw/ppc/mac_newworld: " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 19/49] hw/ppc/prep: " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 20/49] hw/ppc: " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 21/49] xics/spapr: Drop unused function declaration David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 22/49] xics/spapr: Rename xics_kvm_init() David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 23/49] xics/kvm: Skip rollback when KVM XICS is absent David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 24/49] xics/kvm: Always use local_err in xics_kvm_init() David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 25/49] xics/kvm: Add error propagation to ic*_set_kvm_state() functions David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 26/49] xics/kvm: Add proper rollback to xics_kvm_init() David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 27/49] ppc: Introduce kvmppc_set_reg_tb_offset() helper David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 28/49] target/ppc/machine: Add kvmppc_pvr_workaround_required() stub David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 29/49] target/ppc: remove getVSR()/putVSR() from int_helper.c David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 30/49] target/ppc: introduce separate VSX_CMP macro for xvcmp* instructions David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 31/49] target/ppc: introduce GEN_VSX_HELPER_X3 macro to fpu_helper.c David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 32/49] target/ppc: introduce separate generator and helper for xscvqpdp David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 33/49] target/ppc: introduce GEN_VSX_HELPER_X2 macro to fpu_helper.c David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 34/49] target/ppc: introduce GEN_VSX_HELPER_X2_AB " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 35/49] target/ppc: introduce GEN_VSX_HELPER_X1 " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 36/49] target/ppc: introduce GEN_VSX_HELPER_R3 " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 37/49] target/ppc: introduce GEN_VSX_HELPER_R2 " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 38/49] target/ppc: introduce GEN_VSX_HELPER_R2_AB " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 39/49] target/ppc: decode target register in VSX_VECTOR_LOAD_STORE_LENGTH at translation time David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 40/49] target/ppc: decode target register in VSX_EXTRACT_INSERT " David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 41/49] target/ppc: improve VSX_FMADD with new GEN_VSX_HELPER_VSX_MADD macro David Gibson
2019-08-28 15:50   ` [Qemu-devel] [Qemu-ppc] " Laurent Vivier
2019-08-28 17:08     ` Paul Clarke
2019-07-02  6:08 ` [Qemu-devel] [PULL 42/49] spapr_pci: Unregister listeners before destroying the IOMMU address space David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 43/49] spapr/xive: rework the mapping the KVM memory regions David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 44/49] spapr/xive: simplify spapr_irq_init_device() to remove the emulated init David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 45/49] ppc/xive: Force the Physical CAM line value to group mode David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 46/49] ppc/xive: Make the PIPR register readonly David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 47/49] ppc/pnv: Rework cache watch model of PnvXIVE David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 48/49] ppc/xive: Fix TM_PULL_POOL_CTX special operation David Gibson
2019-07-02  6:08 ` [Qemu-devel] [PULL 49/49] spapr/xive: Add proper rollback to kvmppc_xive_connect() David Gibson
2019-07-02  7:54 ` [Qemu-devel] [PULL 00/49] ppc-for-4.1 queue 20190702 no-reply
2019-07-02 19:21 ` 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=20190702060857.3926-8-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=aik@ozlabs.ru \
    --cc=clg@kaod.org \
    --cc=groug@kaod.org \
    --cc=lvivier@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=rth@twiddle.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.