[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v11 16/20] target/riscv: implement zicfiss instructions
From: |
Alistair Francis |
Subject: |
Re: [PATCH v11 16/20] target/riscv: implement zicfiss instructions |
Date: |
Thu, 29 Aug 2024 10:07:15 +1000 |
On Thu, Aug 29, 2024 at 10:06 AM Deepak Gupta <debug@rivosinc.com> wrote:
>
> On Thu, Aug 29, 2024 at 10:01:30AM +1000, Alistair Francis wrote:
> >On Thu, Aug 29, 2024 at 3:53 AM Deepak Gupta <debug@rivosinc.com> wrote:
> >>
> >> zicfiss has following instructions
> >> - sspopchk: pops a value from shadow stack and compares with x1/x5.
> >> If they dont match, reports a sw check exception with tval = 3.
> >> - sspush: pushes value in x1/x5 on shadow stack
> >> - ssrdp: reads current shadow stack
> >> - ssamoswap: swaps contents of shadow stack atomically
> >>
> >> sspopchk/sspush/ssrdp default to zimop if zimop implemented and SSE=0
> >>
> >> If SSE=0, ssamoswap is illegal instruction exception.
> >>
> >> This patch implements shadow stack operations for qemu-user and shadow
> >> stack is not protected.
> >>
> >> Signed-off-by: Deepak Gupta <debug@rivosinc.com>
> >> Co-developed-by: Jim Shu <jim.shu@sifive.com>
> >> Co-developed-by: Andy Chiu <andy.chiu@sifive.com>
> >> ---
> >> target/riscv/cpu_bits.h | 2 +
> >> target/riscv/insn32.decode | 21 +++++-
> >> target/riscv/insn_trans/trans_rva.c.inc | 39 ++++++++++
> >> target/riscv/insn_trans/trans_rvzicfiss.c.inc | 75 +++++++++++++++++++
> >> target/riscv/translate.c | 5 ++
> >> 5 files changed, 140 insertions(+), 2 deletions(-)
> >> create mode 100644 target/riscv/insn_trans/trans_rvzicfiss.c.inc
> >>
> >> # *** Zabhb Standard Extension ***
> >> amoswap_b 00001 . . ..... ..... 000 ..... 0101111 @atom_st
> >> diff --git a/target/riscv/insn_trans/trans_rva.c.inc
> >> b/target/riscv/insn_trans/trans_rva.c.inc
> >> index 9cf3ae8019..a2119393a6 100644
> >> --- a/target/riscv/insn_trans/trans_rva.c.inc
> >> +++ b/target/riscv/insn_trans/trans_rva.c.inc
> >> @@ -114,6 +114,25 @@ static bool trans_amoswap_w(DisasContext *ctx,
> >> arg_amoswap_w *a)
> >> return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, MO_TESL);
> >> }
> >>
> >> +static bool trans_ssamoswap_w(DisasContext *ctx, arg_amoswap_w *a)
> >> +{
> >> + REQUIRE_A_OR_ZAAMO(ctx);
> >> + if (!ctx->bcfi_enabled) {
> >> + return false;
> >> + }
> >> +
> >> + TCGv dest = dest_gpr(ctx, a->rd);
> >> + TCGv src1, src2 = get_gpr(ctx, a->rs2, EXT_NONE);
> >> +
> >> + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO);
> >> + src1 = get_address(ctx, a->rs1, 0);
> >> +
> >> + tcg_gen_atomic_xchg_tl(dest, src1, src2, SS_MMU_INDEX(ctx),
> >> + (MO_ALIGN | MO_TESL));
> >> + gen_set_gpr(ctx, a->rd, dest);
> >> + return true;
> >> +}
> >> +
> >> static bool trans_amoadd_w(DisasContext *ctx, arg_amoadd_w *a)
> >> {
> >> REQUIRE_A_OR_ZAAMO(ctx);
> >> @@ -183,6 +202,26 @@ static bool trans_amoswap_d(DisasContext *ctx,
> >> arg_amoswap_d *a)
> >> return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, MO_TEUQ);
> >> }
> >>
> >> +static bool trans_ssamoswap_d(DisasContext *ctx, arg_amoswap_w *a)
> >> +{
> >> + REQUIRE_64BIT(ctx);
> >> + REQUIRE_A_OR_ZAAMO(ctx);
> >> + if (!ctx->bcfi_enabled) {
> >> + return false;
> >> + }
> >> +
> >> + TCGv dest = dest_gpr(ctx, a->rd);
> >> + TCGv src1, src2 = get_gpr(ctx, a->rs2, EXT_NONE);
> >> +
> >> + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO);
> >> + src1 = get_address(ctx, a->rs1, 0);
> >> +
> >> + tcg_gen_atomic_xchg_tl(dest, src1, src2, SS_MMU_INDEX(ctx),
> >> + (MO_ALIGN | MO_TESQ));
> >> + gen_set_gpr(ctx, a->rd, dest);
> >> + return true;
> >> +}
> >
> >Why aren't these in the rvzicfiss file?
>
> `ssamoswap` encodings are coming from (reserved) AMO encodings (and not zimop)
> That's why kept it in trans_rva
But the instructions are defined in the rvzicfiss extension, so I feel
it makes sense to include them there
Alistair
>
> >
> >Otherwise:
> >
> >Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> >
> >Alistair
> >
> >> +
> >> static bool trans_amoadd_d(DisasContext *ctx, arg_amoadd_d *a)
> >> {
- Re: [PATCH v11 11/20] target/riscv: introduce ssp and enabling controls for zicfiss, (continued)
- [PATCH v11 02/20] target/riscv: Add zicfilp extension, Deepak Gupta, 2024/08/28
- [PATCH v11 04/20] target/riscv: save and restore elp state on priv transitions, Deepak Gupta, 2024/08/28
- [PATCH v11 07/20] target/riscv: zicfilp `lpad` impl and branch tracking, Deepak Gupta, 2024/08/28
- [PATCH v11 08/20] disas/riscv: enable `lpad` disassembly, Deepak Gupta, 2024/08/28
- [PATCH v11 10/20] target/riscv: Add zicfiss extension, Deepak Gupta, 2024/08/28
- [PATCH v11 12/20] target/riscv: tb flag for shadow stack instructions, Deepak Gupta, 2024/08/28
- [PATCH v11 16/20] target/riscv: implement zicfiss instructions, Deepak Gupta, 2024/08/28
[PATCH v11 14/20] target/riscv: AMO operations always raise store/AMO fault, Deepak Gupta, 2024/08/28
[PATCH v11 17/20] target/riscv: compressed encodings for sspush and sspopchk, Deepak Gupta, 2024/08/28
[PATCH v11 13/20] target/riscv: mmu changes for zicfiss shadow stack protection, Deepak Gupta, 2024/08/28