All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, danielhb413@gmail.com,
	peter.maydell@linaro.org,
	Nicholas Miehlbradt <nicholas@linux.ibm.com>
Subject: [PULL 15/15] target/ppc: Check DEXCR on hash{st, chk} instructions
Date: Tue, 20 Dec 2022 10:52:51 -0300	[thread overview]
Message-ID: <20221220135251.155176-16-danielhb413@gmail.com> (raw)
In-Reply-To: <20221220135251.155176-1-danielhb413@gmail.com>

From: Nicholas Miehlbradt <nicholas@linux.ibm.com>

Adds checks to the hashst and hashchk instructions to only execute if
enabled by the relevant aspect in the DEXCR and HDEXCR.

This behaviour is guarded behind TARGET_PPC64 since Power10 is
currently the only implementation which has the DEXCR.

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Nicholas Miehlbradt <nicholas@linux.ibm.com>
Message-Id: <20221220042330.2387944-3-nicholas@linux.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 target/ppc/excp_helper.c | 58 +++++++++++++++++++++++++++++-----------
 1 file changed, 43 insertions(+), 15 deletions(-)

diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index 94adcb766b..add4d54ae7 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -2902,29 +2902,57 @@ static uint64_t hash_digest(uint64_t ra, uint64_t rb, uint64_t key)
     return stage1_h ^ stage1_l;
 }
 
+static void do_hash(CPUPPCState *env, target_ulong ea, target_ulong ra,
+                    target_ulong rb, uint64_t key, bool store)
+{
+    uint64_t calculated_hash = hash_digest(ra, rb, key), loaded_hash;
+
+    if (store) {
+        cpu_stq_data_ra(env, ea, calculated_hash, GETPC());
+    } else {
+        loaded_hash = cpu_ldq_data_ra(env, ea, GETPC());
+        if (loaded_hash != calculated_hash) {
+            raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
+                POWERPC_EXCP_TRAP, GETPC());
+        }
+    }
+}
+
 #include "qemu/guest-random.h"
 
-#define HELPER_HASH(op, key, store)                                           \
+#ifdef TARGET_PPC64
+#define HELPER_HASH(op, key, store, dexcr_aspect)                             \
 void helper_##op(CPUPPCState *env, target_ulong ea, target_ulong ra,          \
                  target_ulong rb)                                             \
 {                                                                             \
-    uint64_t calculated_hash = hash_digest(ra, rb, key), loaded_hash;         \
-                                                                              \
-    if (store) {                                                              \
-        cpu_stq_data_ra(env, ea, calculated_hash, GETPC());                   \
-    } else {                                                                  \
-        loaded_hash = cpu_ldq_data_ra(env, ea, GETPC());                      \
-        if (loaded_hash != calculated_hash) {                                 \
-            raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,                 \
-                POWERPC_EXCP_TRAP, GETPC());                                  \
-        }                                                                     \
+    if (env->msr & R_MSR_PR_MASK) {                                           \
+        if (!(env->spr[SPR_DEXCR] & R_DEXCR_PRO_##dexcr_aspect##_MASK ||      \
+            env->spr[SPR_HDEXCR] & R_HDEXCR_ENF_##dexcr_aspect##_MASK))       \
+            return;                                                           \
+    } else if (!(env->msr & R_MSR_HV_MASK)) {                                 \
+        if (!(env->spr[SPR_DEXCR] & R_DEXCR_PNH_##dexcr_aspect##_MASK ||      \
+            env->spr[SPR_HDEXCR] & R_HDEXCR_ENF_##dexcr_aspect##_MASK))       \
+            return;                                                           \
+    } else if (!(env->msr & R_MSR_S_MASK)) {                                  \
+        if (!(env->spr[SPR_HDEXCR] & R_HDEXCR_HNU_##dexcr_aspect##_MASK))     \
+            return;                                                           \
     }                                                                         \
+                                                                              \
+    do_hash(env, ea, ra, rb, key, store);                                     \
+}
+#else
+#define HELPER_HASH(op, key, store, dexcr_aspect)                             \
+void helper_##op(CPUPPCState *env, target_ulong ea, target_ulong ra,          \
+                 target_ulong rb)                                             \
+{                                                                             \
+    do_hash(env, ea, ra, rb, key, store);                                     \
 }
+#endif /* TARGET_PPC64 */
 
-HELPER_HASH(HASHST, env->spr[SPR_HASHKEYR], true)
-HELPER_HASH(HASHCHK, env->spr[SPR_HASHKEYR], false)
-HELPER_HASH(HASHSTP, env->spr[SPR_HASHPKEYR], true)
-HELPER_HASH(HASHCHKP, env->spr[SPR_HASHPKEYR], false)
+HELPER_HASH(HASHST, env->spr[SPR_HASHKEYR], true, NPHIE)
+HELPER_HASH(HASHCHK, env->spr[SPR_HASHKEYR], false, NPHIE)
+HELPER_HASH(HASHSTP, env->spr[SPR_HASHPKEYR], true, PHIE)
+HELPER_HASH(HASHCHKP, env->spr[SPR_HASHPKEYR], false, PHIE)
 #endif /* CONFIG_TCG */
 
 #if !defined(CONFIG_USER_ONLY)
-- 
2.38.1



  parent reply	other threads:[~2022-12-20 13:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-20 13:52 [PULL 00/15] ppc queue Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 01/15] MAINTAINERS: downgrade PPC KVM/TCG CPUs and pSeries to 'Odd Fixes' Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 02/15] hw/sd/sdhci: MMIO region is implemented in 32-bit accesses Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 03/15] hw/sd/sdhci: Support big endian SD host controller interfaces Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 04/15] hw/ppc/e500: Add Freescale eSDHC to e500plat Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 05/15] target/ppc/kvm: Add missing "cpu.h" and "exec/hwaddr.h" Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 06/15] hw/ppc/vof: Do not include the full "cpu.h" Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 07/15] hw/ppc/spapr: Reduce "vof.h" inclusion Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 08/15] target/ppc/mmu_common: Log which effective address had no TLB entry found Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 09/15] target/ppc/mmu_common: Fix table layout of "info tlb" HMP command Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 10/15] hw/ppc/virtex_ml507: Prefer local over global variable Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 11/15] hw/ppc/e500: Prefer local variable over qdev_get_machine() Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 12/15] hw/ppc/e500: Resolve variable shadowing Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 13/15] hw/ppc/e500: Move comment to more appropriate place Daniel Henrique Barboza
2022-12-20 13:52 ` [PULL 14/15] target/ppc: Implement the DEXCR and HDEXCR Daniel Henrique Barboza
2022-12-20 13:52 ` Daniel Henrique Barboza [this message]
2022-12-20 21:34 ` [PULL 00/15] ppc queue Peter Maydell
2022-12-20 22:13   ` Philippe Mathieu-Daudé
2022-12-21 10:25     ` Daniel Henrique Barboza

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=20221220135251.155176-16-danielhb413@gmail.com \
    --to=danielhb413@gmail.com \
    --cc=nicholas@linux.ibm.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 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.