Re: [PATCH] target: riscv: Add Svrsw60t59b extension support

2025-06-06 Thread Deepak Gupta
On Thu, Jun 5, 2025 at 7:21 AM Alexandre Ghiti wrote: > > The Svrsw60t59b extension allows to free the PTE reserved bits 60 and 59 > for software to use. > > Signed-off-by: Alexandre Ghiti > --- Reviewed-by: Deepak Gupta

Re: [PATCH RFC] target: riscv: Add Svrsw60b59b extension support

2025-04-22 Thread Deepak Gupta
On Fri, Mar 14, 2025 at 11:48:33AM +0100, Alexandre Ghiti wrote: The Svrsw60b59b extension allows to free the PTE reserved bits 60 and 59 for software to use. Apart from what you already caught. Extension is dependnet on Sv39. So it should be validated somewhere. Perhaps in `riscv_cpu_validate_

Re: [PATCH v2 2/2] target/riscv: fixes a bug against `ssamoswap` behavior in M-mode

2025-03-15 Thread Deepak Gupta
On Thu, Mar 6, 2025 at 6:05 PM Alistair Francis wrote: > > On Thu, Mar 6, 2025 at 4:47 PM Deepak Gupta wrote: > > > > Commit f06bfe3dc38c ("target/riscv: implement zicfiss instructions") adds > > `ssamoswap` instruction. `ssamoswap` takes the code-point from e

[PATCH v2 1/2] target/riscv: fix access permission checks for CSR_SSP

2025-03-06 Thread Deepak Gupta
ssp) CSR access contr" in the priv spec. Fixes: 8205bc127a83 ("target/riscv: introduce ssp and enabling controls for zicfiss". Thanks to Adam Zabrocki for bringing this to attention. Reported-by: Adam Zabrocki Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target

[PATCH v2 2/2] target/riscv: fixes a bug against `ssamoswap` behavior in M-mode

2025-03-05 Thread Deepak Gupta
ment zicfiss instructions") Reported-by: Ved Shanbhogue Signed-off-by: Deepak Gupta --- target/riscv/insn_trans/trans_rvzicfiss.c.inc | 17 + 1 file changed, 17 insertions(+) diff --git a/target/riscv/insn_trans/trans_rvzicfiss.c.inc b/target/riscv/insn_trans/trans_rvzicfiss.c.in

Re: [PATCH 1/2] target/riscv: fix access permission checks for CSR_SSP

2025-03-05 Thread Deepak Gupta
On Thu, Mar 06, 2025 at 04:20:56PM +1000, Alistair Francis wrote: On Thu, Mar 6, 2025 at 4:12 PM Deepak Gupta wrote: On Thu, Mar 06, 2025 at 03:20:55PM +1000, Alistair Francis wrote: >On Tue, Feb 18, 2025 at 12:56 PM Deepak Gupta wrote: >> >> Commit:8205bc1 ("target/risc

Re: [PATCH 2/2] target/riscv: fixes a bug against `ssamoswap` behavior in M-mode

2025-03-05 Thread Deepak Gupta
On Thu, Mar 06, 2025 at 04:22:52PM +1000, Alistair Francis wrote: On Thu, Mar 6, 2025 at 4:13 PM Deepak Gupta wrote: On Thu, Mar 06, 2025 at 03:29:00PM +1000, Alistair Francis wrote: >On Tue, Feb 18, 2025 at 12:57 PM Deepak Gupta wrote: >> >> Commit f06bfe3dc38c ("tar

Re: [PATCH 2/2] target/riscv: fixes a bug against `ssamoswap` behavior in M-mode

2025-03-05 Thread Deepak Gupta
On Thu, Mar 06, 2025 at 03:29:00PM +1000, Alistair Francis wrote: On Tue, Feb 18, 2025 at 12:57 PM Deepak Gupta wrote: Commit f06bfe3dc38c ("target/riscv: implement zicfiss instructions") adds `ssamoswap` instruction. `ssamoswap` takes the code-point from existing reserved encoding

Re: [PATCH 1/2] target/riscv: fix access permission checks for CSR_SSP

2025-03-05 Thread Deepak Gupta
On Thu, Mar 06, 2025 at 03:20:55PM +1000, Alistair Francis wrote: On Tue, Feb 18, 2025 at 12:56 PM Deepak Gupta wrote: Commit:8205bc1 ("target/riscv: introduce ssp and enabling controls for zicfiss") introduced CSR_SSP but it mis-interpreted the spec on access to CSR_SSP in M-mode

[PATCH 1/2] target/riscv: fix access permission checks for CSR_SSP

2025-02-17 Thread Deepak Gupta
er" of `zicfiss` specification. Thanks to Adam Zabrocki for bringing this to attention. Fixes: 8205bc127a83 ("target/riscv: introduce ssp and enabling controls for zicfiss" Reported-by: Adam Zabrocki Signed-off-by: Deepak Gupta --- target/riscv/csr.c | 5 + 1 file changed, 5 inse

[PATCH 2/2] target/riscv: fixes a bug against `ssamoswap` behavior in M-mode

2025-02-17 Thread Deepak Gupta
ion 2.7 of zicfiss specification). This patch corrects that behavior for `ssamoswap`. Fixes: f06bfe3dc38c ("target/riscv: implement zicfiss instructions") Reported-by: Ved Shanbhogue Signed-off-by: Deepak Gupta --- target/riscv/insn_trans/trans_rvzicfiss.c.inc | 13 +++-- 1 file ch

[PATCH v16 13/20] target/riscv: mmu changes for zicfiss shadow stack protection

2024-10-08 Thread Deepak Gupta
ff-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson --- target/riscv/cpu_helper.c | 64 ++- target/riscv/internals.h | 3 ++ 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/

[PATCH v16 12/20] target/riscv: tb flag for shadow stack instructions

2024-10-08 Thread Deepak Gupta
enabled or not. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h| 2 ++ target/riscv/cpu_helper.c | 4 target/riscv/translate.c | 3 +++ 3 files changed, 9 insertions

[PATCH v16 16/20] target/riscv: implement zicfiss instructions

2024-10-08 Thread Deepak Gupta
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 Co-developed-by: Jim Shu Co

[PATCH v16 01/20] target/riscv: expose *envcfg csr and priv to qemu-user as well

2024-10-08 Thread Deepak Gupta
need arises then `henvcfg` could be exposed as well. Relevant discussion: https://lore.kernel.org/all/cakmqykotvwpfep2mstqvdumjerkh+bqcckeq4hanydfpdwk...@mail.gmail.com/ Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Fr

[PATCH v16 02/20] target/riscv: Add zicfilp extension

2024-10-08 Thread Deepak Gupta
: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 5 + 3 files changed, 7 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index

[PATCH v16 17/20] target/riscv: compressed encodings for sspush and sspopchk

2024-10-08 Thread Deepak Gupta
sspush/sspopchk have compressed encodings carved out of zcmops. compressed sspush is designated as c.mop.1 while compressed sspopchk is designated as c.mop.5. Note that c.sspush x1 exists while c.sspush x5 doesn't. Similarly c.sspopchk x5 exists while c.sspopchk x1 doesn't. Signed-off-

[PATCH v16 09/20] target/riscv: Expose zicfilp extension as a cpu property

2024-10-08 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 05f727222e..135559fc95 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1469,6 +1469,7 @@ const

[PATCH v16 19/20] disas/riscv: enable disassembly for compressed sspush/sspopchk

2024-10-08 Thread Deepak Gupta
sspush and sspopchk have equivalent compressed encoding taken from zcmop. cmop.1 is sspush x1 while cmop.5 is sspopchk x5. Due to unusual encoding for both rs1 and rs2 from space bitfield, this required a new codec. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 19

[PATCH v16 18/20] disas/riscv: enable disassembly for zicfiss instructions

2024-10-08 Thread Deepak Gupta
Enable disassembly for sspush, sspopchk, ssrdp & ssamoswap. Disasembly is only enabled if zimop and zicfiss ext is set to true. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 40 +++- disas/riscv.h | 1 + 2 files changed

[PATCH v16 08/20] disas/riscv: enable `lpad` disassembly

2024-10-08 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- disas/riscv.c | 18 +- disas/riscv.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas

[PATCH v16 10/20] target/riscv: Add zicfiss extension

2024-10-08 Thread Deepak Gupta
zicfiss [1] riscv cpu extension enables backward control flow integrity. This patch sets up space for zicfiss extension in cpuconfig. And imple- ments dependency on A, zicsr, zimop and zcmop extensions. [1] - https://github.com/riscv/riscv-cfi Signed-off-by: Deepak Gupta Co-developed-by: Jim

[PATCH v16 06/20] target/riscv: tracking indirect branches (fcfi) for zicfilp

2024-10-08 Thread Deepak Gupta
`lpad` gets translated, fcfi_lp_expected flag in DisasContext can be cleared. Else it'll fault. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/

[PATCH v16 03/20] target/riscv: Introduce elp state and enabling controls for zicfilp

2024-10-08 Thread Deepak Gupta
te back to NO_LP_EXPECTED. On reset, elp is set to NO_LP_EXPECTED. zicfilp is enabled via bit2 in *envcfg CSRs. Enabling control for M-mode is in mseccfg CSR at bit position 10. On trap, elp state is saved away in *status. Adds elp to the migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: J

[PATCH v16 07/20] target/riscv: zicfilp `lpad` impl and branch tracking

2024-10-08 Thread Deepak Gupta
`lpad`. If they don't match, cpu raises a sw check exception with tval = 2. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu_user.h | 1 + target/riscv/i

[PATCH v16 14/20] target/riscv: AMO operations always raise store/AMO fault

2024-10-08 Thread Deepak Gupta
This patch adds one more word for tcg compile which can be obtained during unwind time to determine fault type for original operation (example AMO). Depending on that, fault can be promoted to store/AMO fault. Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard

[PATCH v16 15/20] target/riscv: update `decode_save_opc` to store extra word2

2024-10-08 Thread Deepak Gupta
/qemu/-/issues/594 Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/insn_trans/trans_privileged.c.inc | 8 target/riscv/insn_trans/trans_rva.c.inc| 4 ++-- target/riscv/insn_trans/trans_rvd.c.inc| 4

[PATCH v16 00/20] riscv support for control flow integrity extensions

2024-10-08 Thread Deepak Gupta
es assert condition in accel/tcg v2: - added missed file (in v1) for shadow stack instructions implementation. Deepak Gupta (20): target/riscv: expose *envcfg csr and priv to qemu-user as well target/riscv: Add zicfilp extension target/riscv: Introduce elp state and enabling controls fo

[PATCH v16 20/20] target/riscv: Expose zicfiss extension as a cpu property

2024-10-08 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index ac5ad6fa9d..0751d08d85 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1473,6 +1473,7 @@ const

[PATCH v16 04/20] target/riscv: save and restore elp state on priv transitions

2024-10-08 Thread Deepak Gupta
on *envcfg (for U, VU, S, VU, HS) or mseccfg csr (for M). Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson --- target/riscv/cpu.h| 1 + target/riscv/cpu_helper.c | 54 +++ target/riscv

[PATCH v16 11/20] target/riscv: introduce ssp and enabling controls for zicfiss

2024-10-08 Thread Deepak Gupta
t. Adds ssp to migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.c| 2 ++ target/riscv/cpu.h| 3 +++ target/riscv/cpu_bits.h | 6 +

[PATCH v16 05/20] target/riscv: additional code information for sw check

2024-10-08 Thread Deepak Gupta
`. Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h| 2 ++ target/riscv/cpu_helper.c | 3 +++ target/riscv/csr.c| 1 + 3 files changed, 6 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index

Re: [PATCH v15 14/21] target/riscv: disallow probe accesses to shadow stack

2024-10-03 Thread Deepak Gupta
On Thu, Oct 03, 2024 at 11:33:35AM -0700, Deepak Gupta wrote: `check_zicbom_access` (`cbo.clean/flush/inval`) may probe shadow stack memory and must always raise store/AMO access fault because it has store semantics. For non-shadow stack memory even though `cbo.clean/flush/inval` have store

[PATCH v15 20/21] disas/riscv: enable disassembly for compressed sspush/sspopchk

2024-10-03 Thread Deepak Gupta
sspush and sspopchk have equivalent compressed encoding taken from zcmop. cmop.1 is sspush x1 while cmop.5 is sspopchk x5. Due to unusual encoding for both rs1 and rs2 from space bitfield, this required a new codec. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 19

[PATCH v15 21/21] target/riscv: Expose zicfiss extension as a cpu property

2024-10-03 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index ac5ad6fa9d..0751d08d85 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1473,6 +1473,7 @@ const

[PATCH v15 10/21] target/riscv: Add zicfiss extension

2024-10-03 Thread Deepak Gupta
zicfiss [1] riscv cpu extension enables backward control flow integrity. This patch sets up space for zicfiss extension in cpuconfig. And imple- ments dependency on A, zicsr, zimop and zcmop extensions. [1] - https://github.com/riscv/riscv-cfi Signed-off-by: Deepak Gupta Co-developed-by: Jim

[PATCH v15 12/21] target/riscv: tb flag for shadow stack instructions

2024-10-03 Thread Deepak Gupta
enabled or not. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h| 2 ++ target/riscv/cpu_helper.c | 4 target/riscv/translate.c | 3 +++ 3 files changed, 9 insertions

[PATCH v15 00/21] riscv support for control flow integrity extensions

2024-10-03 Thread Deepak Gupta
- Style changes. - fixes assert condition in accel/tcg v2: - added missed file (in v1) for shadow stack instructions implementation. Deepak Gupta (21): target/riscv: expose *envcfg csr and priv to qemu-user as well target/riscv: Add zicfilp extension target/riscv: Introduce elp stat

[PATCH v15 09/21] target/riscv: Expose zicfilp extension as a cpu property

2024-10-03 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 05f727222e..135559fc95 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1469,6 +1469,7 @@ const

[PATCH v15 14/21] target/riscv: disallow probe accesses to shadow stack

2024-10-03 Thread Deepak Gupta
well. Signed-off-by: Deepak Gupta --- target/riscv/cpu_helper.c | 22 +- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 5580f5f3f3..ab46f694b5 100644 --- a/target/riscv/cpu_helper.c +++ b/target/

[PATCH v15 05/21] target/riscv: additional code information for sw check

2024-10-03 Thread Deepak Gupta
`. Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h| 2 ++ target/riscv/cpu_helper.c | 3 +++ target/riscv/csr.c| 1 + 3 files changed, 6 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index

[PATCH v15 18/21] target/riscv: compressed encodings for sspush and sspopchk

2024-10-03 Thread Deepak Gupta
sspush/sspopchk have compressed encodings carved out of zcmops. compressed sspush is designated as c.mop.1 while compressed sspopchk is designated as c.mop.5. Note that c.sspush x1 exists while c.sspush x5 doesn't. Similarly c.sspopchk x5 exists while c.sspopchk x1 doesn't. Signed-off-

[PATCH v15 07/21] target/riscv: zicfilp `lpad` impl and branch tracking

2024-10-03 Thread Deepak Gupta
`lpad`. If they don't match, cpu raises a sw check exception with tval = 2. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu_user.h | 1 + target/riscv/i

[PATCH v15 16/21] target/riscv: update `decode_save_opc` to store extra word2

2024-10-03 Thread Deepak Gupta
/qemu/-/issues/594 Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/insn_trans/trans_privileged.c.inc | 8 target/riscv/insn_trans/trans_rva.c.inc| 4 ++-- target/riscv/insn_trans/trans_rvd.c.inc| 4

[PATCH v15 06/21] target/riscv: tracking indirect branches (fcfi) for zicfilp

2024-10-03 Thread Deepak Gupta
`lpad` gets translated, fcfi_lp_expected flag in DisasContext can be cleared. Else it'll fault. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/

[PATCH v15 15/21] target/riscv: AMO operations always raise store/AMO fault

2024-10-03 Thread Deepak Gupta
This patch adds one more word for tcg compile which can be obtained during unwind time to determine fault type for original operation (example AMO). Depending on that, fault can be promoted to store/AMO fault. Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard

[PATCH v15 11/21] target/riscv: introduce ssp and enabling controls for zicfiss

2024-10-03 Thread Deepak Gupta
t. Adds ssp to migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.c| 2 ++ target/riscv/cpu.h| 3 +++ target/riscv/cpu_bits.h | 6 +

[PATCH v15 13/21] target/riscv: mmu changes for zicfiss shadow stack protection

2024-10-03 Thread Deepak Gupta
accesses to RO memory leads to store page fault. To implement special nature of shadow stack memory where only selected stores (shadow stack stores from sspush) have to be allowed while rest of regular stores disallowed, new MMU TLB index is created for shadow stack. Signed-off-by: Deepak Gupta

[PATCH v15 17/21] target/riscv: implement zicfiss instructions

2024-10-03 Thread Deepak Gupta
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 Co-developed-by: Jim Shu Co

[PATCH v15 02/21] target/riscv: Add zicfilp extension

2024-10-03 Thread Deepak Gupta
: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 5 + 3 files changed, 7 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index

[PATCH v15 19/21] disas/riscv: enable disassembly for zicfiss instructions

2024-10-03 Thread Deepak Gupta
Enable disassembly for sspush, sspopchk, ssrdp & ssamoswap. Disasembly is only enabled if zimop and zicfiss ext is set to true. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 40 +++- disas/riscv.h | 1 + 2 files changed

[PATCH v15 01/21] target/riscv: expose *envcfg csr and priv to qemu-user as well

2024-10-03 Thread Deepak Gupta
need arises then `henvcfg` could be exposed as well. Relevant discussion: https://lore.kernel.org/all/cakmqykotvwpfep2mstqvdumjerkh+bqcckeq4hanydfpdwk...@mail.gmail.com/ Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Fr

[PATCH v15 08/21] disas/riscv: enable `lpad` disassembly

2024-10-03 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- disas/riscv.c | 18 +- disas/riscv.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas

[PATCH v15 03/21] target/riscv: Introduce elp state and enabling controls for zicfilp

2024-10-03 Thread Deepak Gupta
te back to NO_LP_EXPECTED. On reset, elp is set to NO_LP_EXPECTED. zicfilp is enabled via bit2 in *envcfg CSRs. Enabling control for M-mode is in mseccfg CSR at bit position 10. On trap, elp state is saved away in *status. Adds elp to the migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: J

[PATCH v15 04/21] target/riscv: save and restore elp state on priv transitions

2024-10-03 Thread Deepak Gupta
on *envcfg (for U, VU, S, VU, HS) or mseccfg csr (for M). Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson --- target/riscv/cpu.h| 1 + target/riscv/cpu_helper.c | 54 +++ target/riscv

[PATCH v14 09/20] target/riscv: Expose zicfilp extension as a cpu property

2024-09-12 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index a0490e29f9..b4b578003f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1495,6 +1495,7 @@ const

[PATCH v14 18/20] disas/riscv: enable disassembly for zicfiss instructions

2024-09-12 Thread Deepak Gupta
Enable disassembly for sspush, sspopchk, ssrdp & ssamoswap. Disasembly is only enabled if zimop and zicfiss ext is set to true. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 40 +++- disas/riscv.h | 1 + 2 files changed

[PATCH v14 17/20] target/riscv: compressed encodings for sspush and sspopchk

2024-09-12 Thread Deepak Gupta
sspush/sspopchk have compressed encodings carved out of zcmops. compressed sspush is designated as c.mop.1 while compressed sspopchk is designated as c.mop.5. Note that c.sspush x1 exists while c.sspush x5 doesn't. Similarly c.sspopchk x5 exists while c.sspopchk x1 doesn't. Signed-off-

[PATCH v14 11/20] target/riscv: introduce ssp and enabling controls for zicfiss

2024-09-12 Thread Deepak Gupta
t. Adds ssp to migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.c| 2 ++ target/riscv/cpu.h| 3 +++ target/riscv/cpu_bits.h | 6 +

[PATCH v14 01/20] target/riscv: expose *envcfg csr and priv to qemu-user as well

2024-09-12 Thread Deepak Gupta
need arises then `henvcfg` could be exposed as well. Relevant discussion: https://lore.kernel.org/all/cakmqykotvwpfep2mstqvdumjerkh+bqcckeq4hanydfpdwk...@mail.gmail.com/ Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Fr

[PATCH v14 07/20] target/riscv: zicfilp `lpad` impl and branch tracking

2024-09-12 Thread Deepak Gupta
`lpad`. If they don't match, cpu raises a sw check exception with tval = 2. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu_user.h | 1 + target/riscv/i

[PATCH v14 05/20] target/riscv: additional code information for sw check

2024-09-12 Thread Deepak Gupta
`. Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h| 2 ++ target/riscv/cpu_helper.c | 3 +++ target/riscv/csr.c| 1 + 3 files changed, 6 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index

[PATCH v14 20/20] target/riscv: Expose zicfiss extension as a cpu property

2024-09-12 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4172774087..3e72df6ef8 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1499,6 +1499,7 @@ const

[PATCH v14 13/20] target/riscv: mmu changes for zicfiss shadow stack protection

2024-09-12 Thread Deepak Gupta
accesses to RO memory leads to store page fault. To implement special nature of shadow stack memory where only selected stores (shadow stack stores from sspush) have to be allowed while rest of regular stores disallowed, new MMU TLB index is created for shadow stack. Signed-off-by: Deepak Gupta

[PATCH v14 06/20] target/riscv: tracking indirect branches (fcfi) for zicfilp

2024-09-12 Thread Deepak Gupta
`lpad` gets translated, fcfi_lp_expected flag in DisasContext can be cleared. Else it'll fault. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/

[PATCH v14 03/20] target/riscv: Introduce elp state and enabling controls for zicfilp

2024-09-12 Thread Deepak Gupta
te back to NO_LP_EXPECTED. On reset, elp is set to NO_LP_EXPECTED. zicfilp is enabled via bit2 in *envcfg CSRs. Enabling control for M-mode is in mseccfg CSR at bit position 10. On trap, elp state is saved away in *status. Adds elp to the migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: J

[PATCH v14 04/20] target/riscv: save and restore elp state on priv transitions

2024-09-12 Thread Deepak Gupta
on *envcfg (for U, VU, S, VU, HS) or mseccfg csr (for M). Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson --- target/riscv/cpu.h| 1 + target/riscv/cpu_helper.c | 54 +++ target/riscv

[PATCH v14 15/20] target/riscv: update `decode_save_opc` to store extra word2

2024-09-12 Thread Deepak Gupta
/qemu/-/issues/594 Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/insn_trans/trans_privileged.c.inc | 8 target/riscv/insn_trans/trans_rva.c.inc| 4 ++-- target/riscv/insn_trans/trans_rvd.c.inc| 4

[PATCH v14 19/20] disas/riscv: enable disassembly for compressed sspush/sspopchk

2024-09-12 Thread Deepak Gupta
sspush and sspopchk have equivalent compressed encoding taken from zcmop. cmop.1 is sspush x1 while cmop.5 is sspopchk x5. Due to unusual encoding for both rs1 and rs2 from space bitfield, this required a new codec. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 19

[PATCH v14 10/20] target/riscv: Add zicfiss extension

2024-09-12 Thread Deepak Gupta
zicfiss [1] riscv cpu extension enables backward control flow integrity. This patch sets up space for zicfiss extension in cpuconfig. And imple- ments dependency on A, zicsr, zimop and zcmop extensions. [1] - https://github.com/riscv/riscv-cfi Signed-off-by: Deepak Gupta Co-developed-by: Jim

[PATCH v14 08/20] disas/riscv: enable `lpad` disassembly

2024-09-12 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- disas/riscv.c | 18 +- disas/riscv.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas

[PATCH v14 14/20] target/riscv: AMO operations always raise store/AMO fault

2024-09-12 Thread Deepak Gupta
This patch adds one more word for tcg compile which can be obtained during unwind time to determine fault type for original operation (example AMO). Depending on that, fault can be promoted to store/AMO fault. Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard

[PATCH v14 16/20] target/riscv: implement zicfiss instructions

2024-09-12 Thread Deepak Gupta
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 Co-developed-by: Jim Shu Co

[PATCH v14 12/20] target/riscv: tb flag for shadow stack instructions

2024-09-12 Thread Deepak Gupta
enabled or not. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h| 2 ++ target/riscv/cpu_helper.c | 4 target/riscv/translate.c | 3 +++ 3 files changed, 9 insertions

[PATCH v14 00/20] riscv support for control flow integrity extensions

2024-09-12 Thread Deepak Gupta
- fixes assert condition in accel/tcg v2: - added missed file (in v1) for shadow stack instructions implementation. Deepak Gupta (20): target/riscv: expose *envcfg csr and priv to qemu-user as well target/riscv: Add zicfilp extension target/riscv: Introduce elp state and enabling contr

[PATCH v14 02/20] target/riscv: Add zicfilp extension

2024-09-12 Thread Deepak Gupta
: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 5 + 3 files changed, 7 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index

[PATCH v13 00/20] riscv support for control flow integrity extensions

2024-08-30 Thread Deepak Gupta
ons to not require helper. - tcg helpers only for cfi violation cases so that trace hooks can be placed. - Style changes. - fixes assert condition in accel/tcg v2: - added missed file (in v1) for shadow stack instructions implementation. Deepak Gupta (20): target/riscv:

[PATCH v13 07/20] target/riscv: zicfilp `lpad` impl and branch tracking

2024-08-30 Thread Deepak Gupta
`lpad`. If they don't match, cpu raises a sw check exception with tval = 2. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu_user.h | 1 + target/riscv/i

[PATCH v13 05/20] target/riscv: additional code information for sw check

2024-08-30 Thread Deepak Gupta
`. Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h| 2 ++ target/riscv/cpu_helper.c | 3 +++ target/riscv/csr.c| 1 + 3 files changed, 6 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index

[PATCH v13 02/20] target/riscv: Add zicfilp extension

2024-08-30 Thread Deepak Gupta
: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 5 + 3 files changed, 7 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index

[PATCH v13 19/20] disas/riscv: enable disassembly for compressed sspush/sspopchk

2024-08-30 Thread Deepak Gupta
sspush and sspopchk have equivalent compressed encoding taken from zcmop. cmop.1 is sspush x1 while cmop.5 is sspopchk x5. Due to unusual encoding for both rs1 and rs2 from space bitfield, this required a new codec. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 19

[PATCH v13 08/20] disas/riscv: enable `lpad` disassembly

2024-08-30 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- disas/riscv.c | 18 +- disas/riscv.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas

[PATCH v13 16/20] target/riscv: implement zicfiss instructions

2024-08-30 Thread Deepak Gupta
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 Co-developed-by: Jim Shu Co

[PATCH v13 06/20] target/riscv: tracking indirect branches (fcfi) for zicfilp

2024-08-30 Thread Deepak Gupta
`lpad` gets translated, fcfi_lp_expected flag in DisasContext can be cleared. Else it'll fault. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/

[PATCH v13 20/20] target/riscv: Expose zicfiss extension as a cpu property

2024-08-30 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index c5ebcefeb5..2592465e24 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1485,6 +1485,7 @@ const

[PATCH v13 10/20] target/riscv: Add zicfiss extension

2024-08-30 Thread Deepak Gupta
zicfiss [1] riscv cpu extension enables backward control flow integrity. This patch sets up space for zicfiss extension in cpuconfig. And imple- ments dependency on A, zicsr, zimop and zcmop extensions. [1] - https://github.com/riscv/riscv-cfi Signed-off-by: Deepak Gupta Co-developed-by: Jim

[PATCH v13 03/20] target/riscv: Introduce elp state and enabling controls for zicfilp

2024-08-30 Thread Deepak Gupta
te back to NO_LP_EXPECTED. On reset, elp is set to NO_LP_EXPECTED. zicfilp is enabled via bit2 in *envcfg CSRs. Enabling control for M-mode is in mseccfg CSR at bit position 10. On trap, elp state is saved away in *status. Adds elp to the migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: J

[PATCH v13 12/20] target/riscv: tb flag for shadow stack instructions

2024-08-30 Thread Deepak Gupta
enabled or not. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h| 2 ++ target/riscv/cpu_helper.c | 4 target/riscv/translate.c | 3 +++ 3 files changed, 9 insertions

[PATCH v13 18/20] disas/riscv: enable disassembly for zicfiss instructions

2024-08-30 Thread Deepak Gupta
Enable disassembly for sspush, sspopchk, ssrdp & ssamoswap. Disasembly is only enabled if zimop and zicfiss ext is set to true. Signed-off-by: Deepak Gupta Acked-by: Alistair Francis --- disas/riscv.c | 40 +++- disas/riscv.h | 1 + 2 files changed

[PATCH v13 11/20] target/riscv: introduce ssp and enabling controls for zicfiss

2024-08-30 Thread Deepak Gupta
t. Adds ssp to migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.c| 2 ++ target/riscv/cpu.h| 3 +++ target/riscv/cpu_bits.h | 6 +

[PATCH v13 14/20] target/riscv: AMO operations always raise store/AMO fault

2024-08-30 Thread Deepak Gupta
This patch adds one more word for tcg compile which can be obtained during unwind time to determine fault type for original operation (example AMO). Depending on that, fault can be promoted to store/AMO fault. Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard

[PATCH v13 09/20] target/riscv: Expose zicfilp extension as a cpu property

2024-08-30 Thread Deepak Gupta
Signed-off-by: Deepak Gupta Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 55754cb374..c9aeffee4e 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1481,6 +1481,7 @@ const

[PATCH v13 01/20] target/riscv: expose *envcfg csr and priv to qemu-user as well

2024-08-30 Thread Deepak Gupta
need arises then `henvcfg` could be exposed as well. Relevant discussion: https://lore.kernel.org/all/cakmqykotvwpfep2mstqvdumjerkh+bqcckeq4hanydfpdwk...@mail.gmail.com/ Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Fr

[PATCH v13 04/20] target/riscv: save and restore elp state on priv transitions

2024-08-30 Thread Deepak Gupta
on *envcfg (for U, VU, S, VU, HS) or mseccfg csr (for M). Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson --- target/riscv/cpu.h| 1 + target/riscv/cpu_helper.c | 54 +++ target/riscv

[PATCH v13 13/20] target/riscv: mmu changes for zicfiss shadow stack protection

2024-08-30 Thread Deepak Gupta
accesses to RO memory leads to store page fault. To implement special nature of shadow stack memory where only selected stores (shadow stack stores from sspush) have to be allowed while rest of regular stores disallowed, new MMU TLB index is created for shadow stack. Signed-off-by: Deepak Gupta

[PATCH v13 15/20] target/riscv: update `decode_save_opc` to store extra word2

2024-08-30 Thread Deepak Gupta
/qemu/-/issues/594 Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/insn_trans/trans_privileged.c.inc | 8 target/riscv/insn_trans/trans_rva.c.inc| 4 ++-- target/riscv/insn_trans/trans_rvd.c.inc| 4

[PATCH v13 17/20] target/riscv: compressed encodings for sspush and sspopchk

2024-08-30 Thread Deepak Gupta
sspush/sspopchk have compressed encodings carved out of zcmops. compressed sspush is designated as c.mop.1 while compressed sspopchk is designated as c.mop.5. Note that c.sspush x1 exists while c.sspush x5 doesn't. Similarly c.sspopchk x5 exists while c.sspopchk x1 doesn't. Signed-off-

Re: [PATCH v12 11/20] target/riscv: introduce ssp and enabling controls for zicfiss

2024-08-30 Thread Deepak Gupta
On Thu, Aug 29, 2024 at 10:56:41PM -0700, Deepak Gupta wrote: On Fri, Aug 30, 2024 at 03:20:04PM +1000, Richard Henderson wrote: On 8/30/24 09:34, Deepak Gupta wrote: +bool cpu_get_bcfien(CPURISCVState *env) It occurs to me that a better name would be "cpu_get_sspen". The backw

Re: [PATCH v12 11/20] target/riscv: introduce ssp and enabling controls for zicfiss

2024-08-29 Thread Deepak Gupta
On Fri, Aug 30, 2024 at 03:20:04PM +1000, Richard Henderson wrote: On 8/30/24 09:34, Deepak Gupta wrote: +bool cpu_get_bcfien(CPURISCVState *env) It occurs to me that a better name would be "cpu_get_sspen". The backward cfi is merely a consequence of the shadow stack. Want me

[PATCH v12 16/20] target/riscv: implement zicfiss instructions

2024-08-29 Thread Deepak Gupta
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 Co-developed-by: Jim Shu Co

  1   2   3   4   5   >