qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Deepak Gupta <debug@rivosinc.com>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
	pbonzini@redhat.com, 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
Subject: Re: [PATCH v3 15/20] target/riscv: shadow stack mmu index for shadow stack instructions
Date: Wed, 7 Aug 2024 14:23:45 -0700	[thread overview]
Message-ID: <ZrPl4fFyLX5N2WUs@debug.ba.rivosinc.com> (raw)
In-Reply-To: <26d37287-b4e3-42b8-818d-b96bcf128a75@linaro.org>

On Wed, Aug 07, 2024 at 12:43:31PM +1000, Richard Henderson wrote:
>On 8/7/24 10:06, Deepak Gupta wrote:
>>Shadow stack instructions shadow stack mmu index for load/stores.
>>`MMU_IDX_SS_ACCESS` at bit positon 3 is used as shadow stack index.
>>Shadow stack mmu index depend on privilege and SUM bit. If shadow stack
>>accesses happening in user mode, shadow stack mmu index = 0b1000. If
>>shaodw stack access happening in supervisor mode mmu index = 0b1001. If
>>shadow stack access happening in supervisor mode with SUM=1 then mmu
>>index = 0b1010
>>
>>Signed-off-by: Deepak Gupta <debug@rivosinc.com>
>>---
>>  target/riscv/cpu.h                            | 13 ++++++++++
>>  target/riscv/cpu_helper.c                     |  3 +++
>>  target/riscv/insn_trans/trans_rva.c.inc       |  8 ++++++
>>  target/riscv/insn_trans/trans_rvzicfiss.c.inc |  6 +++++
>>  target/riscv/internals.h                      |  1 +
>>  target/riscv/translate.c                      | 25 +++++++++++++++++++
>>  6 files changed, 56 insertions(+)
>>
>>diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
>>index 6da94c417c..3ad220a9fe 100644
>>--- a/target/riscv/cpu.h
>>+++ b/target/riscv/cpu.h
>>@@ -615,6 +615,19 @@ FIELD(TB_FLAGS, FCFI_ENABLED, 28, 1)
>>  FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 29, 1)
>>  /* zicfiss needs a TB flag so that correct TB is located based on tb flags */
>>  FIELD(TB_FLAGS, BCFI_ENABLED, 30, 1)
>>+/*
>>+ * zicfiss shadow stack is special memory on which regular stores aren't
>>+ * allowed but shadow stack stores are allowed. Shadow stack stores can
>>+ * happen as `sspush` or `ssamoswap` instructions. `sspush` implicitly
>>+ * takes shadow stack address from CSR_SSP. But `ssamoswap` takes address
>>+ * from encoded input register and it will be used by supervisor software
>>+ * to access (read/write) user shadow stack for setting up rt_frame during
>>+ * signal delivery. Supervisor software will do so by setting SUM=1. Thus
>>+ * a TB flag is needed if SUM was 1 during TB generation to correctly
>>+ * reflect memory permissions to access shadow stack user memory from
>>+ * supervisor mode.
>>+ */
>>+FIELD(TB_FLAGS, SUM, 31, 1)
>
>This is already encoded into the mmu_idx as MMUIdx_S_SUM.

This is where I need some help / suggestion and clarifications.

`riscv_env_mmu_index` is the which does mode --> mmu index translation and that's
where `MMUIdx_S_SUM` is set.

Although above function assumes following things
    -- Only loads ands stores are supposed to do read and write.
    -- Translates env/priv --> mmu index

In case of shadow stack, we need to hold following true:
Shadow stack are not writeable via regular stores but are allowed to be readable.
Shadow stack are writeable only via shadow stack instruction.
Shadow stack instructions can't operate on non-shadow stack memory.

This let me to create a new mmu index (as you saw in patches). This mmu index is only
setup by shadow stack instruction and thus has to be known at translation time
(and that's why SUM TB flag)

There is no way of telling in `riscv_env_mmu_index` about whether mmu index is requested
for regular load/store or some other instruction (in this case shadow stack instruction).
If that is available then I think I can use `riscv_env_mmu_index`.

Question:
I see that `riscv_env_mmu_index` could be called from a bunch of places in (like
`accel/tcg/ldst_common.c.inc` as well. Does it exclude loads, stores which calculate mmu
indexes during translation (like shadow stack load, stores) ?

>
>
>r~


  reply	other threads:[~2024-08-07 21:24 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07  0:06 [PATCH v3 00/20] riscv support for control flow integrity extensions Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 01/20] accel/tcg: restrict assert on icount_enabled to qemu-system Deepak Gupta
2024-08-07  0:48   ` Richard Henderson
2024-08-07 18:45     ` Deepak Gupta
2024-08-12 17:41     ` Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 02/20] target/riscv: Add zicfilp extension Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 03/20] target/riscv: Introduce elp state and enabling controls for zicfilp Deepak Gupta
2024-08-07  0:56   ` Richard Henderson
2024-08-07 18:46     ` Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 04/20] target/riscv: save and restore elp state on priv transitions Deepak Gupta
2024-08-07  1:06   ` Richard Henderson
2024-08-07 20:11     ` Deepak Gupta
2024-08-07 22:40       ` Richard Henderson
2024-08-07 22:58         ` Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 05/20] target/riscv: additional code information for sw check Deepak Gupta
2024-08-07  1:11   ` Richard Henderson
2024-08-07  0:06 ` [PATCH v3 06/20] target/riscv: tracking indirect branches (fcfi) for zicfilp Deepak Gupta
2024-08-07  1:23   ` Richard Henderson
2024-08-07 20:15     ` Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 07/20] target/riscv: zicfilp `lpad` impl and branch tracking Deepak Gupta
2024-08-07  2:01   ` Richard Henderson
2024-08-07  2:04   ` Richard Henderson
2024-08-07  0:06 ` [PATCH v3 08/20] disas/riscv: enabled `lpad` disassembly Deepak Gupta
2024-08-07  2:06   ` Richard Henderson
2024-08-07  0:06 ` [PATCH v3 09/20] target/riscv: Add zicfiss extension Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 10/20] target/riscv: introduce ssp and enabling controls for zicfiss Deepak Gupta
2024-08-07  2:11   ` Richard Henderson
2024-08-07  2:12     ` Richard Henderson
2024-08-07 20:21       ` Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 11/20] target/riscv: tb flag for shadow stack instructions Deepak Gupta
2024-08-07  2:13   ` Richard Henderson
2024-08-07  0:06 ` [PATCH v3 12/20] target/riscv: implement zicfiss instructions Deepak Gupta
2024-08-07  2:39   ` Richard Henderson
2024-08-07  2:56     ` Richard Henderson
2024-08-07 21:25       ` Deepak Gupta
2024-08-07 20:35     ` Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 13/20] target/riscv: compressed encodings for sspush and sspopchk Deepak Gupta
2024-08-07  2:40   ` Richard Henderson
2024-08-07  0:06 ` [PATCH v3 14/20] target/riscv: mmu changes for zicfiss shadow stack protection Deepak Gupta
2024-08-07  3:19   ` Richard Henderson
2024-08-09 18:55     ` Deepak Gupta
2024-08-11 22:23       ` Richard Henderson
2024-08-07  0:06 ` [PATCH v3 15/20] target/riscv: shadow stack mmu index for shadow stack instructions Deepak Gupta
2024-08-07  2:43   ` Richard Henderson
2024-08-07 21:23     ` Deepak Gupta [this message]
2024-08-07 22:57       ` Richard Henderson
2024-08-07 23:13         ` Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 16/20] disas/riscv: enable disassembly for zicfiss instructions Deepak Gupta
2024-08-07  3:24   ` Richard Henderson
2024-08-07  0:06 ` [PATCH v3 17/20] disas/riscv: enable disassembly for compressed sspush/sspopchk Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 18/20] target/riscv: add trace-hooks for each case of sw-check exception Deepak Gupta
2024-08-07  3:27   ` Richard Henderson
2024-08-07 20:52     ` Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 19/20] linux-user: permit RISC-V CFI dynamic entry in VDSO Deepak Gupta
2024-08-07  3:36   ` Richard Henderson
2024-08-07 20:53     ` Deepak Gupta
2024-08-07  0:06 ` [PATCH v3 20/20] linux-user: Add RISC-V zicfilp support " Deepak Gupta
2024-08-07  3:41   ` Richard Henderson
2024-08-07 21:00     ` 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=ZrPl4fFyLX5N2WUs@debug.ba.rivosinc.com \
    --to=debug@rivosinc.com \
    --cc=Alistair.Francis@wdc.com \
    --cc=bmeng.cn@gmail.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=laurent@vivier.eu \
    --cc=liwei1518@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=richard.henderson@linaro.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).