Skip to contentSkip to conversation

RISC-V Pointer Masking implementatio

PATCH Superseded Alexey Baturo 2 participants 14 messages Oct 15, 2021 – Oct 17, 2021 RISC-V

v13 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v13 cover RISC-V Pointer Masking implementatio

v13:
Rebased QEMU and addressed Richard's comment.

v12:
Updated function for adjusting address with pointer masking to allocate and use temp register.

v11:
Addressed a few style issues Alistair mentioned in the previous review.

If this patch series would be accepted, I think my further attention would be to:
- Support pm for memory operations for RVV
- Add proper csr and support pm for memory operations for Hypervisor mode
- Support address wrapping on unaligned accesses as @Richard mentioned previously

Thanks!

Alexey Baturo (6):
[RISCV_PM] Add J-extension into RISC-V
[RISCV_PM] Add CSR defines for RISC-V PM extension [RISCV_PM] Support CSRs required for RISC-V PM extension except for
the h-mode
[RISCV_PM] Print new PM CSRs in QEMU logs
[RISCV_PM] Support pointer masking for RISC-V for i/c/f/d/a types of
instructions
[RISCV_PM] Allow experimental J-ext to be turned on

Anatoly Parshintsev (1):
[RISCV_PM] Implement address masking functions required for RISC-V
Pointer Masking extension

 target/riscv/cpu.c                      |  31 +++
 target/riscv/cpu.h                      |  33 +++
 target/riscv/cpu_bits.h                 |  96 ++++++++
 target/riscv/csr.c                      | 285 ++++++++++++++++++++++++
 target/riscv/insn_trans/trans_rva.c.inc |   3 +
 target/riscv/insn_trans/trans_rvd.c.inc |   2 +
 target/riscv/insn_trans/trans_rvf.c.inc |   2 +
 target/riscv/insn_trans/trans_rvi.c.inc |   2 +
 target/riscv/translate.c                |  46 ++++
 9 files changed, 500 insertions(+)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v13 1/7 Add J-extension into RISC-V

---
 target/riscv/cpu.h | 2 ++
 1 file changed, 2 insertions(+)
target/riscv/cpu.h +2 -0
index 9e55b2f5b1..3f28dc5f3a 100644
@@ -67,6 +67,7 @@
 #define RVS RV('S')
 #define RVU RV('U')
 #define RVH RV('H')
+#define RVJ RV('J')
 
 /* S extension denotes that Supervisor mode exists, however it is possible
    to have a core that support S mode but does not have an MMU and there
@@ -289,6 +290,7 @@ struct RISCVCPU {
         bool ext_s;
         bool ext_u;
         bool ext_h;
+        bool ext_j;
         bool ext_v;
         bool ext_zba;
         bool ext_zbb;
Signature · 1 line
2.30.2
#2 lore raw

PATCH v13 2/7 Add CSR defines for RISC-V PM extension

In reply to Alexey Baturo
---
 target/riscv/cpu_bits.h | 96 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)
target/riscv/cpu_bits.h +96 -0
index 999187a9ee..1a3767804a 100644
@@ -334,6 +334,38 @@
 #define CSR_MHPMCOUNTER30H  0xb9e
 #define CSR_MHPMCOUNTER31H  0xb9f
 
+/*
+ * User PointerMasking registers
+ * NB: actual CSR numbers might be changed in future
+ */
+#define CSR_UMTE            0x4c0
+#define CSR_UPMMASK         0x4c1
+#define CSR_UPMBASE         0x4c2
+
+/*
+ * Machine PointerMasking registers
+ * NB: actual CSR numbers might be changed in future
+ */
+#define CSR_MMTE            0x3c0
+#define CSR_MPMMASK         0x3c1
+#define CSR_MPMBASE         0x3c2
+
+/*
+ * Supervisor PointerMaster registers
+ * NB: actual CSR numbers might be changed in future
+ */
+#define CSR_SMTE            0x1c0
+#define CSR_SPMMASK         0x1c1
+#define CSR_SPMBASE         0x1c2
+
+/*
+ * Hypervisor PointerMaster registers
+ * NB: actual CSR numbers might be changed in future
+ */
+#define CSR_VSMTE           0x2c0
+#define CSR_VSPMMASK        0x2c1
+#define CSR_VSPMBASE        0x2c2
+
 /* mstatus CSR bits */
 #define MSTATUS_UIE         0x00000001
 #define MSTATUS_SIE         0x00000002
@@ -531,4 +563,68 @@ typedef enum RISCVException {
 #define MIE_UTIE                           (1 << IRQ_U_TIMER)
 #define MIE_SSIE                           (1 << IRQ_S_SOFT)
 #define MIE_USIE                           (1 << IRQ_U_SOFT)
+
+/* General PointerMasking CSR bits*/
+#define PM_ENABLE       0x00000001ULL
+#define PM_CURRENT      0x00000002ULL
+#define PM_INSN         0x00000004ULL
+#define PM_XS_MASK      0x00000003ULL
+
+/* PointerMasking XS bits values */
+#define PM_EXT_DISABLE  0x00000000ULL
+#define PM_EXT_INITIAL  0x00000001ULL
+#define PM_EXT_CLEAN    0x00000002ULL
+#define PM_EXT_DIRTY    0x00000003ULL
+
+/* Offsets for every pair of control bits per each priv level */
+#define XS_OFFSET    0ULL
+#define U_OFFSET     2ULL
+#define S_OFFSET     5ULL
+#define M_OFFSET     8ULL
+
+#define PM_XS_BITS   (PM_XS_MASK << XS_OFFSET)
+#define U_PM_ENABLE  (PM_ENABLE  << U_OFFSET)
+#define U_PM_CURRENT (PM_CURRENT << U_OFFSET)
+#define U_PM_INSN    (PM_INSN    << U_OFFSET)
+#define S_PM_ENABLE  (PM_ENABLE  << S_OFFSET)
+#define S_PM_CURRENT (PM_CURRENT << S_OFFSET)
+#define S_PM_INSN    (PM_INSN    << S_OFFSET)
+#define M_PM_ENABLE  (PM_ENABLE  << M_OFFSET)
+#define M_PM_CURRENT (PM_CURRENT << M_OFFSET)
+#define M_PM_INSN    (PM_INSN    << M_OFFSET)
+
+/* mmte CSR bits */
+#define MMTE_PM_XS_BITS     PM_XS_BITS
+#define MMTE_U_PM_ENABLE    U_PM_ENABLE
+#define MMTE_U_PM_CURRENT   U_PM_CURRENT
+#define MMTE_U_PM_INSN      U_PM_INSN
+#define MMTE_S_PM_ENABLE    S_PM_ENABLE
+#define MMTE_S_PM_CURRENT   S_PM_CURRENT
+#define MMTE_S_PM_INSN      S_PM_INSN
+#define MMTE_M_PM_ENABLE    M_PM_ENABLE
+#define MMTE_M_PM_CURRENT   M_PM_CURRENT
+#define MMTE_M_PM_INSN      M_PM_INSN
+#define MMTE_MASK    (MMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | MMTE_U_PM_INSN | \
+                      MMTE_S_PM_ENABLE | MMTE_S_PM_CURRENT | MMTE_S_PM_INSN | \
+                      MMTE_M_PM_ENABLE | MMTE_M_PM_CURRENT | MMTE_M_PM_INSN | \
+                      MMTE_PM_XS_BITS)
+
+/* (v)smte CSR bits */
+#define SMTE_PM_XS_BITS     PM_XS_BITS
+#define SMTE_U_PM_ENABLE    U_PM_ENABLE
+#define SMTE_U_PM_CURRENT   U_PM_CURRENT
+#define SMTE_U_PM_INSN      U_PM_INSN
+#define SMTE_S_PM_ENABLE    S_PM_ENABLE
+#define SMTE_S_PM_CURRENT   S_PM_CURRENT
+#define SMTE_S_PM_INSN      S_PM_INSN
+#define SMTE_MASK    (SMTE_U_PM_ENABLE | SMTE_U_PM_CURRENT | SMTE_U_PM_INSN | \
+                      SMTE_S_PM_ENABLE | SMTE_S_PM_CURRENT | SMTE_S_PM_INSN | \
+                      SMTE_PM_XS_BITS)
+
+/* umte CSR bits */
+#define UMTE_U_PM_ENABLE    U_PM_ENABLE
+#define UMTE_U_PM_CURRENT   U_PM_CURRENT
+#define UMTE_U_PM_INSN      U_PM_INSN
+#define UMTE_MASK     (UMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | UMTE_U_PM_INSN)
+
 #endif
Signature · 1 line
2.30.2
#3 lore raw

PATCH v13 3/7 Support CSRs required for RISC-V PM extension except for the h-mode

In reply to Alexey Baturo
---
 target/riscv/cpu.c |   2 +
 target/riscv/cpu.h |  11 ++
 target/riscv/csr.c | 285 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 298 insertions(+)
target/riscv/cpu.c +2 -0
index 1d69d1887e..75e8b8ca83 100644
@@ -365,6 +365,8 @@ static void riscv_cpu_reset(DeviceState *dev)
     env->mcause = 0;
     env->pc = env->resetvec;
     env->two_stage_lookup = false;
+    /* mmte is supposed to have pm.current hardwired to 1 */
+    env->mmte |= (PM_EXT_INITIAL | MMTE_M_PM_CURRENT);
 #endif
     cs->exception_index = RISCV_EXCP_NONE;
     env->load_res = -1;
target/riscv/cpu.h +11 -0
index 3f28dc5f3a..acb4ce9d23 100644
@@ -236,6 +236,17 @@ struct CPURISCVState {
 
     /* True if in debugger mode.  */
     bool debugger;
+
+    /*
+     * CSRs for PointerMasking extension
+     */
+    target_ulong mmte;
+    target_ulong mpmmask;
+    target_ulong mpmbase;
+    target_ulong spmmask;
+    target_ulong spmbase;
+    target_ulong upmmask;
+    target_ulong upmbase;
 #endif
 
     float_status fp_status;
target/riscv/csr.c +285 -0

303 lines not on this page · raw message

Signature · 1 line
2.30.2
#4 lore raw

Re: [PATCH v13 3/7] [RISCV_PM] Support CSRs required for RISC-V PM extension except for the h-mode

target/riscv/cpu.h struct CPURISCVState { · line 249

Quoted 11 lines · Alexey Baturo
target/riscv/cpu.h +11 -0
+
+    /*
+     * CSRs for PointerMasking extension
+     */
+    target_ulong mmte;
+    target_ulong mpmmask;
+    target_ulong mpmbase;
+    target_ulong spmmask;
+    target_ulong spmbase;
+    target_ulong upmmask;
+    target_ulong upmbase;

You need to update machine.c to migrate these.
C.f. vmstate_pmp.

r~

#5 lore raw

PATCH v13 4/7 Print new PM CSRs in QEMU logs

In reply to Alexey Baturo
---
 target/riscv/cpu.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
target/riscv/cpu.c +25 -0
index 75e8b8ca83..7f9dde70b7 100644
@@ -295,6 +295,31 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mscratch", env->mscratch);
     qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "sscratch", env->sscratch);
     qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "satp    ", env->satp);
+    if (riscv_has_ext(env, RVJ)) {
+        qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mmte    ", env->mmte);
+        switch (env->priv) {
+        case PRV_U:
+            qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "upmbase ",
+                         env->upmbase);
+            qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "upmmask ",
+                         env->upmmask);
+            break;
+        case PRV_S:
+            qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "spmbase ",
+                         env->spmbase);
+            qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "spmmask ",
+                         env->spmmask);
+            break;
+        case PRV_M:
+            qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mpmbase ",
+                         env->mpmbase);
+            qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mpmmask ",
+                         env->mpmmask);
+            break;
+        default:
+            g_assert_not_reached();
+        }
+    }
 #endif
 
     for (i = 0; i < 32; i++) {
Signature · 1 line
2.30.2
#6 lore raw

PATCH v13 5/7 Support pointer masking for RISC-V for i/c/f/d/a types of instructions

In reply to Alexey Baturo
---
 target/riscv/insn_trans/trans_rva.c.inc |  3 +++
 target/riscv/insn_trans/trans_rvd.c.inc |  2 ++
 target/riscv/insn_trans/trans_rvf.c.inc |  2 ++
 target/riscv/insn_trans/trans_rvi.c.inc |  2 ++
 target/riscv/translate.c                | 10 ++++++++++
 5 files changed, 19 insertions(+)
target/riscv/insn_trans/trans_rva.c.inc +3 -0
index 6ea07d89b0..5bdc412191 100644
@@ -25,6 +25,7 @@ static bool gen_lr(DisasContext *ctx, arg_atomic *a, MemOp mop)
     if (a->rl) {
         tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
     }
+    gen_pm_adjust_address(ctx, &src1, src1);
     tcg_gen_qemu_ld_tl(load_val, src1, ctx->mem_idx, mop);
     if (a->aq) {
         tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
@@ -44,6 +45,7 @@ static bool gen_sc(DisasContext *ctx, arg_atomic *a, MemOp mop)
     TCGLabel *l2 = gen_new_label();
 
     src1 = get_gpr(ctx, a->rs1, EXT_ZERO);
+    gen_pm_adjust_address(ctx, &src1, src1);
     tcg_gen_brcond_tl(TCG_COND_NE, load_res, src1, l1);
 
     /*
@@ -84,6 +86,7 @@ static bool gen_amo(DisasContext *ctx, arg_atomic *a,
     TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE);
     TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE);
 
+    gen_pm_adjust_address(ctx, &src1, src1);
     func(dest, src1, src2, ctx->mem_idx, mop);
 
     gen_set_gpr(ctx, a->rd, dest);
target/riscv/insn_trans/trans_rvd.c.inc +2 -0
index db9ae15755..40e73d9959 100644
@@ -31,6 +31,7 @@ static bool trans_fld(DisasContext *ctx, arg_fld *a)
         tcg_gen_addi_tl(temp, addr, a->imm);
         addr = temp;
     }
+    gen_pm_adjust_address(ctx, &addr, addr);
 
     tcg_gen_qemu_ld_i64(cpu_fpr[a->rd], addr, ctx->mem_idx, MO_TEQ);
 
@@ -51,6 +52,7 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a)
         tcg_gen_addi_tl(temp, addr, a->imm);
         addr = temp;
     }
+    gen_pm_adjust_address(ctx, &addr, addr);
 
     tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, MO_TEQ);
 
target/riscv/insn_trans/trans_rvf.c.inc +2 -0
index bddbd418d9..945dc75fdc 100644
@@ -37,6 +37,7 @@ static bool trans_flw(DisasContext *ctx, arg_flw *a)
         tcg_gen_addi_tl(temp, addr, a->imm);
         addr = temp;
     }
+    gen_pm_adjust_address(ctx, &addr, addr);
 
     dest = cpu_fpr[a->rd];
     tcg_gen_qemu_ld_i64(dest, addr, ctx->mem_idx, MO_TEUL);
@@ -59,6 +60,7 @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a)
         tcg_gen_addi_tl(temp, addr, a->imm);
         addr = temp;
     }
+    gen_pm_adjust_address(ctx, &addr, addr);
 
     tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, MO_TEUL);
 
target/riscv/insn_trans/trans_rvi.c.inc +2 -0
index 920ae0edb3..d4097b59f7 100644
@@ -146,6 +146,7 @@ static bool gen_load(DisasContext *ctx, arg_lb *a, MemOp memop)
         tcg_gen_addi_tl(temp, addr, a->imm);
         addr = temp;
     }
+    gen_pm_adjust_address(ctx, &addr, addr);
 
     tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, memop);
     gen_set_gpr(ctx, a->rd, dest);
@@ -187,6 +188,7 @@ static bool gen_store(DisasContext *ctx, arg_sb *a, MemOp memop)
         tcg_gen_addi_tl(temp, addr, a->imm);
         addr = temp;
     }
+    gen_pm_adjust_address(ctx, &addr, addr);
 
     tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop);
     return true;
target/riscv/translate.c +10 -0
index d2442f0cf5..95739b1e41 100644
@@ -118,6 +118,16 @@ static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)
     tcg_gen_ori_i64(out, in, MAKE_64BIT_MASK(32, 32));
 }
 
+/*
+ * Temp stub: generates address adjustment for PointerMasking
+ */
+static void gen_pm_adjust_address(DisasContext *s,
+                                  TCGv         *dst,
+                                  TCGv          src)
+{
+    tcg_gen_mov_tl(*dst, src);
+}
+
 /*
  * A narrow n-bit operation, where n < FLEN, checks that input operands
  * are correctly Nan-boxed, i.e., all upper FLEN - n bits are 1.
Signature · 1 line
2.30.2
#7 lore raw

Re: [PATCH v13 5/7] [RISCV_PM] Support pointer masking for RISC-V for i/c/f/d/a types of instructions

Quoted 20 lines · Alexey Baturo
---
  target/riscv/insn_trans/trans_rva.c.inc |  3 +++
  target/riscv/insn_trans/trans_rvd.c.inc |  2 ++
  target/riscv/insn_trans/trans_rvf.c.inc |  2 ++
  target/riscv/insn_trans/trans_rvi.c.inc |  2 ++
  target/riscv/translate.c                | 10 ++++++++++
  5 files changed, 19 insertions(+)
target/riscv/insn_trans/trans_rva.c.inc +1 -0
index 6ea07d89b0..5bdc412191 100644
@@ -25,6 +25,7 @@ static bool gen_lr(DisasContext *ctx, arg_atomic *a, MemOp mop)
      if (a->rl) {
          tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
      }
+    gen_pm_adjust_address(ctx, &src1, src1);

...

target/riscv/insn_trans/trans_rva.c.inc

Quoted 9 lines
target/riscv/insn_trans/trans_rva.c.inc +9 -0
+/*
+ * Temp stub: generates address adjustment for PointerMasking
+ */
+static void gen_pm_adjust_address(DisasContext *s,
+                                  TCGv         *dst,
+                                  TCGv          src)
+{
+    tcg_gen_mov_tl(*dst, src);
+}

I mentioned before that you would not be able to do this.
You are writing to the live cpu register, even if in this case it's a nop.

You could, for example, make the stub be

    *dst = src;

but that begs the question of why not use the return value, and have the stub be

    return src;

r~

#8 lore raw

Re: [PATCH v13 5/7] [RISCV_PM] Support pointer masking for RISC-V for i/c/f/d/a types of instructions

Hi,

Sorry, my bad, got it wrong.
Fixed now.

Thanks!

сб, 16 окт. 2021 г. в 02:49, Richard Henderson <[email protected]

Quoted 51 lines

:

Quoted 11 lines · Alexey Baturo
---
  target/riscv/insn_trans/trans_rva.c.inc |  3 +++
  target/riscv/insn_trans/trans_rvd.c.inc |  2 ++
  target/riscv/insn_trans/trans_rvf.c.inc |  2 ++
  target/riscv/insn_trans/trans_rvi.c.inc |  2 ++
  target/riscv/translate.c                | 10 ++++++++++
  5 files changed, 19 insertions(+)

Review

Quoted 1 line
(quoted diff) +0 -0

b/target/riscv/insn_trans/trans_rva.c.inc

target/riscv/insn_trans/trans_rva.c.inc static bool gen_lr(DisasContext *ctx, arg_atomic *a,

Quoted 4 lines

index 6ea07d89b0..5bdc412191 100644

target/riscv/insn_trans/trans_rva.c.inc +0 -0
@@ -25,6 +25,7 @@ static bool gen_lr(DisasContext *ctx, arg_atomic *a,

MemOp mop)

Quoted 4 lines
target/riscv/insn_trans/trans_rva.c.inc +1 -0
      if (a->rl) {
          tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
      }
+    gen_pm_adjust_address(ctx, &src1, src1);

...

target/riscv/insn_trans/trans_rva.c.inc

Quoted 9 lines
target/riscv/insn_trans/trans_rva.c.inc +9 -0
+/*
+ * Temp stub: generates address adjustment for PointerMasking
+ */
+static void gen_pm_adjust_address(DisasContext *s,
+                                  TCGv         *dst,
+                                  TCGv          src)
+{
+    tcg_gen_mov_tl(*dst, src);
+}

I mentioned before that you would not be able to do this.
You are writing to the live cpu register, even if in this case it's a nop.

You could, for example, make the stub be

     *dst = src;

but that begs the question of why not use the return value, and have the stub be

     return src;

r~

#9 lore raw

PATCH v13 6/7 Implement address masking functions required for RISC-V Pointer Masking extension

In reply to Alexey Baturo

From: Anatoly Parshintsev <[email protected]>

---
 target/riscv/cpu.h       | 20 ++++++++++++++
 target/riscv/translate.c | 56 +++++++++++++++++++++++++++++++++-------
 2 files changed, 66 insertions(+), 10 deletions(-)
target/riscv/cpu.h +20 -0
index acb4ce9d23..fd2335d08e 100644
@@ -407,6 +407,8 @@ FIELD(TB_FLAGS, VILL, 8, 1)
 /* Is a Hypervisor instruction load/store allowed? */
 FIELD(TB_FLAGS, HLSX, 9, 1)
 FIELD(TB_FLAGS, MSTATUS_HS_FS, 10, 2)
+/* If PointerMasking should be applied */
+FIELD(TB_FLAGS, PM_ENABLED, 10, 1)
 
 bool riscv_cpu_is_32bit(CPURISCVState *env);
 
@@ -467,6 +469,24 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
         flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_FS,
                            get_field(env->mstatus_hs, MSTATUS_FS));
     }
+    if (riscv_has_ext(env, RVJ)) {
+        int priv = cpu_mmu_index(env, false) & TB_FLAGS_PRIV_MMU_MASK;
+        bool pm_enabled = false;
+        switch (priv) {
+        case PRV_U:
+            pm_enabled = env->mmte & U_PM_ENABLE;
+            break;
+        case PRV_S:
+            pm_enabled = env->mmte & S_PM_ENABLE;
+            break;
+        case PRV_M:
+            pm_enabled = env->mmte & M_PM_ENABLE;
+            break;
+        default:
+            g_assert_not_reached();
+        }
+        flags = FIELD_DP32(flags, TB_FLAGS, PM_ENABLED, pm_enabled);
+    }
 #endif
 
     *pflags = flags;
target/riscv/translate.c +46 -10

90 lines not on this page · raw message

Signature · 1 line
2.30.2
#10 lore raw

Re: [PATCH v13 6/7] [RISCV_PM] Implement address masking functions required for RISC-V Pointer Masking extension

target/riscv/cpu.h FIELD(TB_FLAGS, VILL, 8, 1) · line 411

Quoted 3 lines · Alexey Baturo

FIELD(TB_FLAGS, MSTATUS_HS_FS, 10, 2)

target/riscv/cpu.h +2 -0
+/* If PointerMasking should be applied */
+FIELD(TB_FLAGS, PM_ENABLED, 10, 1)

Merge error.

target/riscv/cpu.h static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, · line 473

Quoted 2 lines
target/riscv/cpu.h +2 -0
+    if (riscv_has_ext(env, RVJ)) {
+        int priv = cpu_mmu_index(env, false) & TB_FLAGS_PRIV_MMU_MASK;

cpu_mmu_index has already been computed.
You want

    int priv = flags & TB_FLAGS_PRIV_MMU_MASK;
Quoted 4 lines
target/riscv/translate.c +0 -0
@@ -118,16 +125,6 @@ static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)
     tcg_gen_ori_i64(out, in, MAKE_64BIT_MASK(32, 32));
 }
 

target/riscv/translate.c static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in) · line 130

Quoted 10 lines
target/riscv/translate.c +0 -10
-/*
- * Temp stub: generates address adjustment for PointerMasking
- */
-static void gen_pm_adjust_address(DisasContext *s,
-                                  TCGv         *dst,
-                                  TCGv          src)
-{
-    tcg_gen_mov_tl(*dst, src);
-}
-

You might as well place the function correctly in the previous patch. Drop the silly alignment of parameters.

target/riscv/translate.c static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) · line 585

Quoted 2 lines
target/riscv/translate.c +2 -0
+    int priv = cpu_mmu_index(env, false) & TB_FLAGS_PRIV_MMU_MASK;
+    ctx->pm_mask = pm_mask[priv];

Using cpu_mmu_index within the translator is incorrect. You want

    priv = tb_flags & TB_FLAGS_PRIV_MMU_MASK;

r~

#11 lore raw

Re: [PATCH v13 6/7] [RISCV_PM] Implement address masking functions required for RISC-V Pointer Masking extension

Hi Richard,

Thanks for the review.

Quoted 1 line

Merge error.

fixed

Quoted 2 lines

You might as well place the function correctly in the previous patch. Drop the silly alignment of parameters.

fixed

Quoted 1 line

int priv = flags & TB_FLAGS_PRIV_MMU_MASK;

fixed

Quoted 1 line

priv = tb_flags & TB_FLAGS_PRIV_MMU_MASK;

fixed

сб, 16 окт. 2021 г. в 03:01, Richard Henderson <[email protected]

Quoted 45 lines

:

target/riscv/cpu.h FIELD(TB_FLAGS, VILL, 8, 1) · line 411

Quoted 3 lines · Alexey Baturo

FIELD(TB_FLAGS, MSTATUS_HS_FS, 10, 2)

target/riscv/cpu.h +2 -0
+/* If PointerMasking should be applied */
+FIELD(TB_FLAGS, PM_ENABLED, 10, 1)

Merge error.

target/riscv/cpu.h static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, · line 473

Quoted 2 lines
target/riscv/cpu.h +2 -0
+    if (riscv_has_ext(env, RVJ)) {
+        int priv = cpu_mmu_index(env, false) & TB_FLAGS_PRIV_MMU_MASK;

cpu_mmu_index has already been computed.
You want

     int priv = flags & TB_FLAGS_PRIV_MMU_MASK;
Quoted 4 lines
target/riscv/translate.c +0 -0
@@ -118,16 +125,6 @@ static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)
     tcg_gen_ori_i64(out, in, MAKE_64BIT_MASK(32, 32));
 }
 

target/riscv/translate.c static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in) · line 130

Quoted 10 lines
target/riscv/translate.c +0 -10
-/*
- * Temp stub: generates address adjustment for PointerMasking
- */
-static void gen_pm_adjust_address(DisasContext *s,
-                                  TCGv         *dst,
-                                  TCGv          src)
-{
-    tcg_gen_mov_tl(*dst, src);
-}
-

You might as well place the function correctly in the previous patch. Drop the silly alignment of parameters.

target/riscv/translate.c static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) · line 585

Quoted 2 lines
target/riscv/translate.c +2 -0
+    int priv = cpu_mmu_index(env, false) & TB_FLAGS_PRIV_MMU_MASK;
+    ctx->pm_mask = pm_mask[priv];

Using cpu_mmu_index within the translator is incorrect. You want

     priv = tb_flags & TB_FLAGS_PRIV_MMU_MASK;

r~

#12 lore raw

PATCH v13 7/7 Allow experimental J-ext to be turned on

In reply to Alexey Baturo
---
 target/riscv/cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
target/riscv/cpu.c +4 -0
index 7f9dde70b7..fb08c0ffb8 100644
@@ -558,6 +558,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
             }
             set_vext_version(env, vext_version);
         }
+        if (cpu->cfg.ext_j) {
+            target_misa |= RVJ;
+        }
 
         set_misa(env, target_misa);
     }
@@ -624,6 +627,7 @@ static Property riscv_cpu_properties[] = {
     DEFINE_PROP_BOOL("x-zbc", RISCVCPU, cfg.ext_zbc, false),
     DEFINE_PROP_BOOL("x-zbs", RISCVCPU, cfg.ext_zbs, false),
     DEFINE_PROP_BOOL("x-h", RISCVCPU, cfg.ext_h, false),
+    DEFINE_PROP_BOOL("x-j", RISCVCPU, cfg.ext_j, false),
     DEFINE_PROP_BOOL("x-v", RISCVCPU, cfg.ext_v, false),
     DEFINE_PROP_BOOL("Counters", RISCVCPU, cfg.ext_counters, true),
     DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true),
Signature · 1 line
2.30.2