Skip to content

Commit 69a8ee2

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 <[email protected]>
1 parent 38325f1 commit 69a8ee2

File tree

1 file changed

+85
-9
lines changed

1 file changed

+85
-9
lines changed

src/mte_tag.adoc

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,20 @@ 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+
If `vsatp.MODE == BARE`, then collected value of `hstatus.MTAG_I` will be 0.
388+
389+
HLV*/HSV* instructions generate unchecked memory accesses if VS-stage leaf
390+
PTE entry's execute permission bit is set.
391+
392+
If `hstatus.MTAG_I` is set, then HLV*/HSV* instructions do not generate
393+
checked accesses. If `hstatus.MTAG_I` is clear, then HLV*/HSV* instructions
394+
in HS and HU mode may generate checked accesses depending on effective privilege
395+
of VS or VU (as defined in privileged specification).
387396

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

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

@@ -573,6 +599,52 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
573599

574600
* Zimt instructions will revert to their behavior as defined by Zimop.
575601

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

607683
<<<
608684

0 commit comments

Comments
 (0)