Skip to content

Commit edab7f8

Browse files
authored
src/mte_tag: HLV/HSV/MPRV support for opt-out based on PTE.MTAG for codepage (#82)
Guest might have set PTE.MTAG for code page and thus wouldn't be expecting tag checks even if data pointer had PTE.MTAG set. On an exit to hypervisor, hypervisor emulating this load/store must do emulation similarly and thus HLVX* is updated to collect to MTAG bit in hstatus. MTAG_I and use that during HLV/HSV. Similar mechanisms when in M-mode and MPRV=1. Signed-off-by: Deepak Gupta <debug@rivosinc.com>
1 parent e322ef8 commit edab7f8

File tree

1 file changed

+78
-11
lines changed

1 file changed

+78
-11
lines changed

src/mte_tag.adoc

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,12 @@ tables is ignored.
380380
[[HYPERVISOR_LDST]]
381381
=== Memory tagging and hypervisor memory accesses
382382

383-
HLVX* instructions always generate unchecked loads. HLV*/HSV* instructions in
384-
HS and HU mode may generate checked accesses depending on effective privilege
385-
of VS or VU (as defined in privileged specification). Memory accesses generated
386-
from HLV*/HSV* instructions in HU mode may generate checked accesses when
387-
`hstatus.HU` is set.
383+
HLVX* instructions always generate unchecked loads.
384+
385+
If `hstatus.MTAG_I` is set, then HLV*/HSV* instructions do not generate
386+
checked accesses. If `hstatus.MTAG_I` is clear, then HLV*/HSV* instructions
387+
in HS and HU mode may generate checked accesses depending on effective privilege
388+
of VS or VU (as defined in privileged specification).
388389

389390
`xMT_MODE` (see <<MEM_TAG_EN>>) for HLV* and HSV* instructions is defined based
390391
on the effective privilege of VS or VU (as defined in privileged specification),
@@ -400,8 +401,24 @@ memory accesses based on rules specified by paging bit `MTAG` in first stage
400401
page tables (see <<TAGGED_PAGE>>).
401402

402403
If HLV*/HSV* instructions result in a tag mismatch, software check exception is
403-
delivered to HS mode with tval = 4 and hstatus.GVA set. In case of tag mismatch,
404-
software check exception is always delivered synchronously.
404+
delivered to HS mode with tval = 4 and hstatus.GVA set.
405+
406+
[[MPRV_LDST]]
407+
=== Memory tagging on loads/stores affected by Modify Privilege bit (MPRV)
408+
409+
If MPRV=1 and `mstatus.MTAG_I` is set, then load and store instructions
410+
generate unchecked accesses. If MPRV=1 and `mstatus.MTAG_I` is clear, then
411+
load and store instructions may generate checked accesses depending on
412+
effective privilege. `xMT_MODE` is selected based on effective privilege (see
413+
<<MEM_TAG_EN>>).
414+
415+
If page based virtual memory is enabled for effective privilege and memory
416+
tagging is enabled for effective privilege, then checked accesses are generated
417+
based on rules specified by paging bit `MTAG` in first stage page tables (see
418+
<<TAGGED_PAGE>>).
419+
420+
In case of a tag mismatch, software check exception is delivered to M mode with
421+
tval = 4.
405422

406423
[[MEMTAG_CSR_CTRL]]
407424
=== CSR bits for memory tagging
@@ -574,6 +591,52 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
574591

575592
* Zimt instructions will revert to their behavior as defined by Zimop.
576593

594+
==== Machine Status Register (`mstatus`)
595+
596+
.Machine-mode status register (`mstatus`) for RV64
597+
[wavedrom, ,svg]
598+
....
599+
{reg: [
600+
{bits: 1, name: 'WPRI'},
601+
{bits: 1, name: 'SIE'},
602+
{bits: 1, name: 'WPRI'},
603+
{bits: 1, name: 'MIE'},
604+
{bits: 1, name: 'WPRI'},
605+
{bits: 1, name: 'SPIE'},
606+
{bits: 1, name: 'UBE'},
607+
{bits: 1, name: 'MPIE'},
608+
{bits: 1, name: 'SPP'},
609+
{bits: 2, name: 'VS[1:0]'},
610+
{bits: 2, name: 'MPP[1:0]'},
611+
{bits: 2, name: 'FS[1:0]'},
612+
{bits: 2, name: 'XS[1:0]'},
613+
{bits: 1, name: 'MPRV'},
614+
{bits: 1, name: 'SUM'},
615+
{bits: 1, name: 'MXR'},
616+
{bits: 1, name: 'TVM'},
617+
{bits: 1, name: 'TW'},
618+
{bits: 1, name: 'TSR'},
619+
{bits: 1, name: 'SPELP'},
620+
{bits: 1, name: 'SDT'},
621+
{bits: 7, name: 'WPRI'},
622+
{bits: 2, name: 'UXL[1:0]'},
623+
{bits: 2, name: 'SXL[1:0]'},
624+
{bits: 1, name: 'SBE'},
625+
{bits: 1, name: 'MBE'},
626+
{bits: 1, name: 'GVA'},
627+
{bits: 1, name: 'MPV'},
628+
{bits: 1, name: 'MTAG_I'},
629+
{bits: 1, name: 'MPELP'},
630+
{bits: 1, name: 'MDT'},
631+
{bits: 20, name: 'WPRI'},
632+
{bits: 1, name: 'SD'},
633+
], config:{lanes: 4, hspace:1024}}
634+
....
635+
636+
The Zimt extension adds `MTAG_I` bit to `mstatus`. When a trap is taken to
637+
M-mode and `mtinst` is written with nonzero value, then MTAG bit for code page
638+
of trapping instruction is deposited in `mstatus.MTAG_I`.
639+
577640
==== Hypervisor Status Register (`hstatus`)
578641

579642
.Hypervisor status register (`hstatus`)
@@ -586,7 +649,8 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
586649
{bits: 1, name: 'SPV'},
587650
{bits: 1, name: 'SPVP'},
588651
{bits: 1, name: 'HU'},
589-
{bits: 2, name: 'WPRI'},
652+
{bits: 1, name: 'MTAG_I'},
653+
{bits: 1, name: 'WPRI'},
590654
{bits: 6, name: 'VGEIN'},
591655
{bits: 2, name: 'WPRI'},
592656
{bits: 1, name: 'VTVM'},
@@ -601,9 +665,12 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
601665
], config:{lanes: 4, hspace:1024}}
602666
....
603667

604-
The Zimt extension adds `VUMT_MODE` (bit 51:50) to `hstatus`. When the `HU`
605-
field is set, HLV*/HSV* may generate checked accesses in HU mode. `VUMT_MODE`
606-
selects the `xMT_MODE` if effective privilege mode is VU.
668+
The Zimt extension adds `VUMT_MODE` (bit 51:50) to `hstatus`. `VUMT_MODE`
669+
selects the `xMT_MODE` if execution environment is HU mode and effective
670+
privilege mode is VU. `hstatus.MTAG_I` bit emulates `MTAG` bit for
671+
instruction fetch from code page. When a trap is taken to HS mode and `htinst`
672+
is written with nonzero value, then VS-stage page table's MTAG bit on code page
673+
for trapping instruction is deposited in `hstatus.MTAG_I`.
607674

608675
<<<
609676

0 commit comments

Comments
 (0)