From: Deepak Gupta <debug@rivosinc.com>
To: Alistair Francis <alistair23@gmail.com>
Cc: qemu-riscv@nongnu.org, qemu-devel@nongnu.org, palmer@dabbelt.com,
Alistair.Francis@wdc.com, laurent@vivier.eu, bmeng.cn@gmail.com,
liwei1518@gmail.com, dbarboza@ventanamicro.com,
zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com,
andy.chiu@sifive.com, kito.cheng@sifive.com
Subject: Re: [PATCH v11 16/20] target/riscv: implement zicfiss instructions
Date: Wed, 28 Aug 2024 17:15:53 -0700 [thread overview]
Message-ID: <Zs+9uSmWV7HY3PTQ@debug.ba.rivosinc.com> (raw)
In-Reply-To: <CAKmqyKPEeWry0yGurH+3o=0N55nG+41-bDeVChwQdKX++zt0Xw@mail.gmail.com>
On Thu, Aug 29, 2024 at 10:07:15AM +1000, Alistair Francis wrote:
>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
Ok noted.
I'll wait for a day or two. If there are not objections from anyone else, I'll move
them to rvzicfiss.
>
>Alistair
>
>>
>> >
>> >Otherwise:
>> >
>> >Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>> >
>> >Alistair
>> >
>> >> +
>> >> static bool trans_amoadd_d(DisasContext *ctx, arg_amoadd_d *a)
>> >> {
next prev parent reply other threads:[~2024-08-29 0:17 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-28 17:47 [PATCH v11 00/20] riscv support for control flow integrity extensions Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 01/20] target/riscv: expose *envcfg csr and priv to qemu-user as well Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 02/20] target/riscv: Add zicfilp extension Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 03/20] target/riscv: Introduce elp state and enabling controls for zicfilp Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 04/20] target/riscv: save and restore elp state on priv transitions Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 05/20] target/riscv: additional code information for sw check Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 06/20] target/riscv: tracking indirect branches (fcfi) for zicfilp Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 07/20] target/riscv: zicfilp `lpad` impl and branch tracking Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 08/20] disas/riscv: enable `lpad` disassembly Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 09/20] target/riscv: Expose zicfilp extension as a cpu property Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 10/20] target/riscv: Add zicfiss extension Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 11/20] target/riscv: introduce ssp and enabling controls for zicfiss Deepak Gupta
2024-08-28 23:16 ` Alistair Francis
2024-08-28 17:47 ` [PATCH v11 12/20] target/riscv: tb flag for shadow stack instructions Deepak Gupta
2024-08-29 1:34 ` Richard Henderson
2024-08-28 17:47 ` [PATCH v11 13/20] target/riscv: mmu changes for zicfiss shadow stack protection Deepak Gupta
2024-08-28 23:29 ` Alistair Francis
2024-08-28 23:45 ` Deepak Gupta
2024-08-29 0:03 ` Alistair Francis
2024-08-29 0:17 ` Deepak Gupta
2024-08-28 17:47 ` [PATCH v11 14/20] target/riscv: AMO operations always raise store/AMO fault Deepak Gupta
2024-08-28 23:33 ` Alistair Francis
2024-08-28 17:47 ` [PATCH v11 15/20] target/riscv: update `decode_save_opc` to store extra word2 Deepak Gupta
2024-08-28 23:36 ` Alistair Francis
2024-08-28 17:47 ` [PATCH v11 16/20] target/riscv: implement zicfiss instructions Deepak Gupta
2024-08-29 0:01 ` Alistair Francis
2024-08-29 0:06 ` Deepak Gupta
2024-08-29 0:07 ` Alistair Francis
2024-08-29 0:15 ` Deepak Gupta [this message]
2024-08-28 17:47 ` [PATCH v11 17/20] target/riscv: compressed encodings for sspush and sspopchk Deepak Gupta
2024-08-29 0:03 ` Alistair Francis
2024-08-28 17:47 ` [PATCH v11 18/20] disas/riscv: enable disassembly for zicfiss instructions Deepak Gupta
2024-08-29 0:04 ` Alistair Francis
2024-08-28 17:47 ` [PATCH v11 19/20] disas/riscv: enable disassembly for compressed sspush/sspopchk Deepak Gupta
2024-08-29 0:06 ` Alistair Francis
2024-08-28 17:47 ` [PATCH v11 20/20] target/riscv: Expose zicfiss extension as a cpu property Deepak Gupta
2024-08-29 0:06 ` Alistair Francis
2024-08-28 17:50 ` [PATCH v11 00/20] riscv support for control flow integrity extensions Deepak Gupta
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=Zs+9uSmWV7HY3PTQ@debug.ba.rivosinc.com \
--to=debug@rivosinc.com \
--cc=Alistair.Francis@wdc.com \
--cc=alistair23@gmail.com \
--cc=andy.chiu@sifive.com \
--cc=bmeng.cn@gmail.com \
--cc=dbarboza@ventanamicro.com \
--cc=jim.shu@sifive.com \
--cc=kito.cheng@sifive.com \
--cc=laurent@vivier.eu \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).