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, qemu-devel@nongnu.org, groug@kaod.org,
	qemu-ppc@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
	"Suraj Jitindar Singh" <sjitindarsingh@gmail.com>,
	"David Gibson" <david@gibson.dropbear.id.au>
Subject: [PULL 08/34] target/ppc: add support for Hypervisor Facility Unavailable Exception
Date: Fri, 31 Jan 2020 17:08:58 +1100	[thread overview]
Message-ID: <20200131060924.147449-9-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20200131060924.147449-1-david@gibson.dropbear.id.au>

From: Cédric Le Goater <clg@kaod.org>

The privileged message send and clear instructions (msgsndp & msgclrp)
are privileged, but will generate a hypervisor facility unavailable
exception if not enabled in the HFSCR and executed in privileged
non-hypervisor state.

Add checks when accessing the DPDES register and when using the
msgsndp and msgclrp isntructions.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
Message-Id: <20200120104935.24449-3-clg@kaod.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 target/ppc/cpu.h         |  6 ++++++
 target/ppc/excp_helper.c | 13 +++++++++++++
 target/ppc/misc_helper.c | 27 +++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 8ebeaba649..96aeea1934 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -397,6 +397,10 @@ typedef struct ppc_v3_pate_t {
 #define PSSCR_ESL         PPC_BIT(42) /* Enable State Loss */
 #define PSSCR_EC          PPC_BIT(43) /* Exit Criterion */
 
+/* HFSCR bits */
+#define HFSCR_MSGP     PPC_BIT(53) /* Privileged Message Send Facilities */
+#define HFSCR_IC_MSGP  0xA
+
 #define msr_sf   ((env->msr >> MSR_SF)   & 1)
 #define msr_isf  ((env->msr >> MSR_ISF)  & 1)
 #define msr_shv  ((env->msr >> MSR_SHV)  & 1)
@@ -1329,6 +1333,8 @@ void cpu_ppc_set_vhyp(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp);
 #endif
 
 void store_fpscr(CPUPPCState *env, uint64_t arg, uint32_t mask);
+void helper_hfscr_facility_check(CPUPPCState *env, uint32_t bit,
+                                 const char *caller, uint32_t cause);
 
 static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn)
 {
diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index 1b07c3ed56..027f54c0ed 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -471,6 +471,15 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
     case POWERPC_EXCP_FU:         /* Facility unavailable exception          */
 #ifdef TARGET_PPC64
         env->spr[SPR_FSCR] |= ((target_ulong)env->error_code << 56);
+#endif
+        break;
+    case POWERPC_EXCP_HV_FU:     /* Hypervisor Facility Unavailable Exception */
+#ifdef TARGET_PPC64
+        env->spr[SPR_HFSCR] |= ((target_ulong)env->error_code << FSCR_IC_POS);
+        srr0 = SPR_HSRR0;
+        srr1 = SPR_HSRR1;
+        new_msr |= (target_ulong)MSR_HVB;
+        new_msr |= env->msr & ((target_ulong)1 << MSR_RI);
 #endif
         break;
     case POWERPC_EXCP_PIT:       /* Programmable interval timer interrupt    */
@@ -1277,6 +1286,8 @@ void helper_book3s_msgsnd(target_ulong rb)
 #if defined(TARGET_PPC64)
 void helper_book3s_msgclrp(CPUPPCState *env, target_ulong rb)
 {
+    helper_hfscr_facility_check(env, HFSCR_MSGP, "msgclrp", HFSCR_IC_MSGP);
+
     if (!dbell_type_server(rb)) {
         return;
     }
@@ -1292,6 +1303,8 @@ void helper_book3s_msgsndp(CPUPPCState *env, target_ulong rb)
 {
     int pir = env->spr_cb[SPR_PIR].default_value;
 
+    helper_hfscr_facility_check(env, HFSCR_MSGP, "msgsndp", HFSCR_IC_MSGP);
+
     if (!dbell_type_server(rb)) {
         return;
     }
diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c
index 0c5919ff08..55b68d1246 100644
--- a/target/ppc/misc_helper.c
+++ b/target/ppc/misc_helper.c
@@ -41,6 +41,18 @@ void helper_store_dump_spr(CPUPPCState *env, uint32_t sprn)
 }
 
 #ifdef TARGET_PPC64
+static void raise_hv_fu_exception(CPUPPCState *env, uint32_t bit,
+                                  const char *caller, uint32_t cause,
+                                  uintptr_t raddr)
+{
+    qemu_log_mask(CPU_LOG_INT, "HV Facility %d is unavailable (%s)\n",
+                  bit, caller);
+
+    env->spr[SPR_HFSCR] &= ~((target_ulong)FSCR_IC_MASK << FSCR_IC_POS);
+
+    raise_exception_err_ra(env, POWERPC_EXCP_HV_FU, cause, raddr);
+}
+
 static void raise_fu_exception(CPUPPCState *env, uint32_t bit,
                                uint32_t sprn, uint32_t cause,
                                uintptr_t raddr)
@@ -55,6 +67,17 @@ static void raise_fu_exception(CPUPPCState *env, uint32_t bit,
 }
 #endif
 
+void helper_hfscr_facility_check(CPUPPCState *env, uint32_t bit,
+                                 const char *caller, uint32_t cause)
+{
+#ifdef TARGET_PPC64
+    if ((env->msr_mask & MSR_HVB) && !msr_hv &&
+                                     !(env->spr[SPR_HFSCR] & (1UL << bit))) {
+        raise_hv_fu_exception(env, bit, caller, cause, GETPC());
+    }
+#endif
+}
+
 void helper_fscr_facility_check(CPUPPCState *env, uint32_t bit,
                                 uint32_t sprn, uint32_t cause)
 {
@@ -114,6 +137,8 @@ target_ulong helper_load_dpdes(CPUPPCState *env)
 {
     target_ulong dpdes = 0;
 
+    helper_hfscr_facility_check(env, HFSCR_MSGP, "load DPDES", HFSCR_IC_MSGP);
+
     /* TODO: TCG supports only one thread */
     if (env->pending_interrupts & (1 << PPC_INTERRUPT_DOORBELL)) {
         dpdes = 1;
@@ -127,6 +152,8 @@ void helper_store_dpdes(CPUPPCState *env, target_ulong val)
     PowerPCCPU *cpu = env_archcpu(env);
     CPUState *cs = CPU(cpu);
 
+    helper_hfscr_facility_check(env, HFSCR_MSGP, "store DPDES", HFSCR_IC_MSGP);
+
     /* TODO: TCG supports only one thread */
     if (val & ~0x1) {
         qemu_log_mask(LOG_GUEST_ERROR, "Invalid DPDES register value "
-- 
2.24.1



  parent reply	other threads:[~2020-01-31  6:14 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31  6:08 [PULL 00/34] ppc-for-5.0 queue 20200131 David Gibson
2020-01-31  6:08 ` [PULL 01/34] ppc/pnv: use QEMU unit definition MiB David Gibson
2020-01-31  6:08 ` [PULL 02/34] ppc/pnv: improve error logging when a PNOR update fails David Gibson
2020-01-31  6:08 ` [PULL 03/34] ppc:virtex_ml507: remove unused arguments David Gibson
2020-01-31  6:08 ` [PULL 04/34] hw/ppc/prep: Remove the deprecated "prep" machine and the OpenHackware BIOS David Gibson
2020-01-31  6:08 ` [PULL 05/34] target/ppc: Clarify the meaning of return values in kvm_handle_debug David Gibson
2020-01-31  6:08 ` [PULL 06/34] spapr: Fail CAS if option vector table cannot be parsed David Gibson
2020-01-31  6:08 ` [PULL 07/34] target/ppc: Add privileged message send facilities David Gibson
2020-01-31  6:08 ` David Gibson [this message]
2020-01-31  6:08 ` [PULL 09/34] spapr: Don't allow multiple active vCPUs at CAS David Gibson
2020-01-31  6:09 ` [PULL 10/34] ppc/pnv: Add support for HRMOR on Radix host David Gibson
2020-01-31  6:09 ` [PULL 11/34] ppc/pnv: remove useless "core-pir" property alias David Gibson
2020-01-31  6:09 ` [PULL 12/34] ppc/pnv: Add support for "hostboot" mode David Gibson
2020-01-31  6:09 ` [PULL 13/34] tpm: Move tpm_tis_show_buffer to tpm_util.c David Gibson
2020-01-31  6:09 ` [PULL 14/34] spapr: Implement get_dt_compatible() callback David Gibson
2020-01-31  6:09 ` [PULL 15/34] tpm_spapr: Support TPM for ppc64 using CRQ based interface David Gibson
2020-01-31  6:09 ` [PULL 16/34] tpm_spapr: Support suspend and resume David Gibson
2020-01-31  6:09 ` [PULL 17/34] hw/ppc/Kconfig: Enable TPM_SPAPR as part of PSERIES config David Gibson
2020-01-31  6:09 ` [PULL 18/34] docs/specs/tpm: reST-ify TPM documentation David Gibson
2020-01-31  6:09 ` [PULL 19/34] ppc/pnv: Add models for POWER9 PHB4 PCIe Host bridge David Gibson
2020-01-31  6:09 ` [PULL 20/34] ppc/pnv: Add models for POWER8 PHB3 " David Gibson
2020-01-31  6:09 ` [PULL 21/34] ppc/pnv: change the PowerNV machine devices to be non user creatable David Gibson
2020-01-31  6:09 ` [PULL 22/34] spapr: Enable DD2.3 accelerated count cache flush in pseries-5.0 machine David Gibson
2020-01-31  6:09 ` [PULL 23/34] target/ppc/cpu.h: Put macro parameter in parentheses David Gibson
2020-01-31  6:09 ` [PULL 24/34] Wrapper function to wait on condition for the main loop mutex David Gibson
2020-01-31  6:09 ` [PULL 25/34] ppc: spapr: Introduce FWNMI capability David Gibson
2020-01-31  6:09 ` [PULL 26/34] target/ppc: Handle NMI guest exit David Gibson
2020-01-31  6:09 ` [PULL 27/34] target/ppc: Build rtas error log upon an MCE David Gibson
2020-01-31  6:09 ` [PULL 28/34] ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls David Gibson
2020-01-31  6:09 ` [PULL 29/34] migration: Include migration support for machine check handling David Gibson
2020-01-31  6:09 ` [PULL 30/34] ppc: spapr: Activate the FWNMI functionality David Gibson
2020-01-31  6:09 ` [PULL 31/34] target/ppc: Use probe_access for LSW, STSW David Gibson
2020-01-31  6:09 ` [PULL 32/34] target/ppc: Use probe_access for LMW, STMW David Gibson
2020-01-31  6:09 ` [PULL 33/34] target/ppc: Remove redundant mask in DCBZ David Gibson
2020-01-31  6:09 ` [PULL 34/34] target/ppc: Use probe_write for DCBZ David Gibson
2020-01-31 16:42 ` [PULL 00/34] ppc-for-5.0 queue 20200131 Peter Maydell
2020-02-02  8:43   ` David Gibson
2020-02-02 10:33     ` Greg Kurz

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=20200131060924.147449-9-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --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=sjitindarsingh@gmail.com \
    /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.