Skip to content

Commit a386aaa

Browse files
committed
src/mte_tag: HLV/HSV/MPRV support for opt-out based on PTE.MTAG for codepage
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 38325f1 commit a386aaa

File tree

1 file changed

+88
-9
lines changed

1 file changed

+88
-9
lines changed

src/mte_tag.adoc

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,18 @@ tables is ignored.
379379
[[HYPERVISOR_LDST]]
380380
=== Memory tagging and hypervisor memory accesses
381381

382-
HLVX* instructions always generate unchecked loads. HLV*/HSV* instructions in
383-
HS and HU mode may generate checked accesses depending on effective privilege
384-
of VS or VU (as defined in privileged specification). Memory accesses generated
385-
from HLV*/HSV* instructions in HU mode may generate checked accesses when
386-
`hstatus.HU` is set.
382+
HLVX* instructions always generate unchecked loads and collect MTAG bit from
383+
VS-stage page table for code page of guest instruction in following manner
384+
385+
hstatus.MTAG_I = VS-stage_leaf_PTE(s).MTAG & VS-stage_leaf_PTE(s).X
386+
387+
HLV*/HSV* instructions generate unchecked memory accesses if VS-stage leaf
388+
PTE entry's execute permission bit is set.
389+
390+
If `hstatus.MTAG_I` is set, then HLV*/HSV* instructions do not generate
391+
checked accesses. If `hstatus.MTAG_I` is clear, then HLV*/HSV* instructions
392+
in HS and HU mode may generate checked accesses depending on effective privilege
393+
of VS or VU (as defined in privileged specification).
387394

388395
`xMT_MODE` (see <<MEM_TAG_EN>>) for HLV* and HSV* instructions is defined based
389396
on the effective privilege of VS or VU (as defined in privileged specification),
@@ -402,6 +409,23 @@ If HLV*/HSV* instructions result in a tag mismatch, software check exception is
402409
delivered to HS mode with tval = 4 and hstatus.GVA set. In case of tag mismatch,
403410
software check exception is always delivered synchronously.
404411

412+
[[MPRV_LDST]]
413+
=== Memory tagging on loads/stores affected by Modify Privilege bit (MPRV)
414+
415+
If execution environment is M-mode, MPRV and MXR both are set, and memory
416+
tagging is enabled for effective privilege then load instruction collect MTAG
417+
bit from first stage page table for code page of guest instruction in following
418+
manner
419+
420+
mstatus.MTAG_I = first-stage_leaf_PTE(s).MTAG & first-stage_leaf_PTE(s).X
421+
422+
If MRPV=1 and first-stage page table leaf entry PTE (for effective mode S/U/VU/VS
423+
/HS/HU) has execute permission bit set then load generate unchecked accesses. If
424+
MPRV=1 and `mstatus.MTAG_I` is set, then load and store instructions generate
425+
unchecked accesses. If MPRV=1 and `mstatus.MTAG_I` is clear, then load and store
426+
instructions may generate checked accesses depending on effective privilege.
427+
`xMT_MODE` is selected based on effective privilege (see <<MEM_TAG_EN>>).
428+
405429
[[MEMTAG_CSR_CTRL]]
406430
=== CSR bits for memory tagging
407431

@@ -573,6 +597,54 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
573597

574598
* Zimt instructions will revert to their behavior as defined by Zimop.
575599

600+
==== Machine Status Register (`mstatus`)
601+
602+
.Machine-mode status register (`mstatus`) for RV64
603+
[wavedrom, ,svg]
604+
....
605+
{reg: [
606+
{bits: 1, name: 'WPRI'},
607+
{bits: 1, name: 'SIE'},
608+
{bits: 1, name: 'WPRI'},
609+
{bits: 1, name: 'MIE'},
610+
{bits: 1, name: 'WPRI'},
611+
{bits: 1, name: 'SPIE'},
612+
{bits: 1, name: 'UBE'},
613+
{bits: 1, name: 'MPIE'},
614+
{bits: 1, name: 'SPP'},
615+
{bits: 2, name: 'VS[1:0]'},
616+
{bits: 2, name: 'MPP[1:0]'},
617+
{bits: 2, name: 'FS[1:0]'},
618+
{bits: 2, name: 'XS[1:0]'},
619+
{bits: 1, name: 'MPRV'},
620+
{bits: 1, name: 'SUM'},
621+
{bits: 1, name: 'MXR'},
622+
{bits: 1, name: 'TVM'},
623+
{bits: 1, name: 'TW'},
624+
{bits: 1, name: 'TSR'},
625+
{bits: 1, name: 'SPELP'},
626+
{bits: 1, name: 'SDT'},
627+
{bits: 7, name: 'WPRI'},
628+
{bits: 2, name: 'UXL[1:0]'},
629+
{bits: 2, name: 'SXL[1:0]'},
630+
{bits: 1, name: 'SBE'},
631+
{bits: 1, name: 'MBE'},
632+
{bits: 1, name: 'GVA'},
633+
{bits: 1, name: 'MPV'},
634+
{bits: 1, name: 'MTAG_I'},
635+
{bits: 1, name: 'MPELP'},
636+
{bits: 1, name: 'MDT'},
637+
{bits: 20, name: 'WPRI'},
638+
{bits: 1, name: 'SD'},
639+
], config:{lanes: 4, hspace:1024}}
640+
....
641+
642+
The Zimt extension adds `MTAG_I` bit to `mstatus`. When a trap is taken to
643+
M-mode and `mtval` is written with nonzero value, then MTAG bit for code page
644+
of qualifying instruction is deposited in `mstatus.MTAG_I`. If in M-mode, MPRV
645+
and MXR both are set, load sets `mstatus.MTAG_I` to bitwise AND of first-stage
646+
leaf page entry MTAG bit and execute permission bit.
647+
576648
==== Hypervisor Status Register (`hstatus`)
577649

578650
.Hypervisor status register (`hstatus`)
@@ -585,7 +657,8 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
585657
{bits: 1, name: 'SPV'},
586658
{bits: 1, name: 'SPVP'},
587659
{bits: 1, name: 'HU'},
588-
{bits: 2, name: 'WPRI'},
660+
{bits: 1, name: 'MTAG_I'},
661+
{bits: 1, name: 'WPRI'},
589662
{bits: 6, name: 'VGEIN'},
590663
{bits: 2, name: 'WPRI'},
591664
{bits: 1, name: 'VTVM'},
@@ -600,9 +673,15 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
600673
], config:{lanes: 4, hspace:1024}}
601674
....
602675

603-
The Zimt extension adds `VUMT_MODE` (bit 51:50) to `hstatus`. When the `HU`
604-
field is set, HLV*/HSV* may generate checked accesses in HU mode. `VUMT_MODE`
605-
selects the `xMT_MODE` if effective privilege mode is VU.
676+
The Zimt extension adds `VUMT_MODE` (bit 51:50) to `hstatus`. `VUMT_MODE`
677+
selects the `xMT_MODE` if execution environment is HU mode and effective
678+
privilege mode is VU. `hstatus.MTAG_I` bit emulates `MTAG` bit for
679+
instruction fetch from code page. When a trap is taken to HS mode and `htinst`
680+
is written with nonzero value, then VS-stage page table's MTAG bit on code page
681+
for qualifying instruction is deposited in `hstatus.MTAG_I`. Furthermore, when
682+
HLVX* instructions walks VS-stage page table to fetch instruction then
683+
`hstatus.MTAG_I` is set to bitwise AND of VS-stage leaf entry's `MTAG` and
684+
execute permission bits.
606685

607686
<<<
608687

0 commit comments

Comments
 (0)