Skip to content

Commit 48845a1

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 a208744 commit 48845a1

File tree

1 file changed

+82
-9
lines changed

1 file changed

+82
-9
lines changed

src/mte_tag.adoc

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,15 @@ tables is ignored.
392392
[[HYPERVISOR_LDST]]
393393
=== Memory tagging and hypervisor memory accesses
394394

395-
HLVX* instructions always generate unchecked loads. HLV*/HSV* instructions in
396-
HS and HU mode may generate checked accesses depending on effective privilege
397-
of VS or VU (as defined in privileged specification). Memory accesses generated
398-
from HLV*/HSV* instructions in HU mode may generate checked accesses when
399-
`hstatus.HU` is set.
395+
HLVX* instructions always generate unchecked loads and collect MTAG bit from
396+
VS-stage page table for code page of guest instruction in following manner
397+
398+
hstatus.MTAG_I = VS-stage_leaf_PTE(s).MTAG & VS-stage_leaf_PTE(s).X
399+
400+
If `hstatus.MTAG_I` is set, then HLV*/HSV* instructions do not generate
401+
checked accesses. If `hstatus.MTAG_I` is clear, then HLV*/HSV* instructions
402+
in HS and HU mode may generate checked accesses depending on effective privilege
403+
of VS or VU (as defined in privileged specification).
400404

401405
`xMT_MODE` (see <<MEM_TAG_EN>>) for HLV* and HSV* instructions is defined based
402406
on the effective privilege of VS or VU (as defined in privileged specification),
@@ -415,6 +419,21 @@ If HLV*/HSV* instructions result in a tag mismatch, software check exception is
415419
delivered to HS mode with tval = 4 and hstatus.GVA set. In case of tag mismatch,
416420
software check exception is always delivered synchronously.
417421

422+
[[MPRV_LDST]]
423+
=== Memory tagging on loads/stores affected by Modify Privilege bit (MPRV)
424+
425+
If execution environment is M-mode and MPRV=1, then load instruction collect
426+
MTAG bit from VS-stage page table for code page of guest instruction in
427+
following manner
428+
429+
mstatus.MTAG_I = VS-stage_leaf_PTE(s).MTAG & VS-stage_leaf_PTE(s).X
430+
431+
If MPRV=1 and `mstatus.MTAG_I` is set, then load and store instructions do not
432+
generate checked accesses. If MPRV=1 and `mstatus.MTAG_I` is clear, then load
433+
and store instructions may generate checked accesses depending on effective
434+
privilege. `xMT_MODE` is selected based on effective privilege (see
435+
<<MEM_TAG_EN>>).
436+
418437
[[MEMTAG_CSR_CTRL]]
419438
=== CSR bits for memory tagging
420439

@@ -594,6 +613,54 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
594613

595614
* Zimt instructions will revert to their behavior as defined by Zimop.
596615

616+
==== Machine Status Register (`mstatus`)
617+
618+
.Machine-mode status register (`mstatus`) for RV64
619+
[wavedrom, ,svg]
620+
....
621+
{reg: [
622+
{bits: 1, name: 'WPRI'},
623+
{bits: 1, name: 'SIE'},
624+
{bits: 1, name: 'WPRI'},
625+
{bits: 1, name: 'MIE'},
626+
{bits: 1, name: 'WPRI'},
627+
{bits: 1, name: 'SPIE'},
628+
{bits: 1, name: 'UBE'},
629+
{bits: 1, name: 'MPIE'},
630+
{bits: 1, name: 'SPP'},
631+
{bits: 2, name: 'VS[1:0]'},
632+
{bits: 2, name: 'MPP[1:0]'},
633+
{bits: 2, name: 'FS[1:0]'},
634+
{bits: 2, name: 'XS[1:0]'},
635+
{bits: 1, name: 'MPRV'},
636+
{bits: 1, name: 'SUM'},
637+
{bits: 1, name: 'MXR'},
638+
{bits: 1, name: 'TVM'},
639+
{bits: 1, name: 'TW'},
640+
{bits: 1, name: 'TSR'},
641+
{bits: 1, name: 'SPELP'},
642+
{bits: 1, name: 'SDT'},
643+
{bits: 7, name: 'WPRI'},
644+
{bits: 2, name: 'UXL[1:0]'},
645+
{bits: 2, name: 'SXL[1:0]'},
646+
{bits: 1, name: 'SBE'},
647+
{bits: 1, name: 'MBE'},
648+
{bits: 1, name: 'GVA'},
649+
{bits: 1, name: 'MPV'},
650+
{bits: 1, name: 'MTAG_I'},
651+
{bits: 1, name: 'MPELP'},
652+
{bits: 1, name: 'MDT'},
653+
{bits: 20, name: 'WPRI'},
654+
{bits: 1, name: 'SD'},
655+
], config:{lanes: 4, hspace:1024}}
656+
....
657+
658+
The Zimt extension adds `MTAG_I` bit to `mstatus`. When a trap is taken to
659+
M-mode and `mtval` is written with nonzero value, then MTAG bit for code page
660+
of qualifying instruction is deposited in `mstatus.MTAG_I`. If in M-mode and
661+
MPRV=1, load sets `mstatus.MTAG_I` to bitwise AND of VS-stage leaf page entry
662+
MTAG bit and execute permission bit.
663+
597664
==== Hypervisor Status Register (`hstatus`)
598665

599666
.Hypervisor status register (`hstatus`)
@@ -606,7 +673,8 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
606673
{bits: 1, name: 'SPV'},
607674
{bits: 1, name: 'SPVP'},
608675
{bits: 1, name: 'HU'},
609-
{bits: 2, name: 'WPRI'},
676+
{bits: 1, name: 'MTAG_I'},
677+
{bits: 1, name: 'WPRI'},
610678
{bits: 6, name: 'VGEIN'},
611679
{bits: 2, name: 'WPRI'},
612680
{bits: 1, name: 'VTVM'},
@@ -621,9 +689,14 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
621689
], config:{lanes: 4, hspace:1024}}
622690
....
623691

624-
The Zimt extension adds `VUMT_MODE` (bit 51:50) to `hstatus`. When the `HU`
625-
field is set, HLV*/HSV* may generate checked accesses in HU mode. `VUMT_MODE`
626-
selects the `xMT_MODE` if effective privilege mode is VU.
692+
The Zimt extension adds `VUMT_MODE` (bit 51:50) to `hstatus`. `VUMT_MODE`
693+
selects the `xMT_MODE` if execution environment is HU mode and effective
694+
privilege mode is VU. `hstatus.MTAG_I` bit emulates `MTAG` bit for
695+
instruction fetch from code page. When a trap is taken to HS mode and `htinst`
696+
is written with nonzero value, then VS-stage page table's MTAG bit on code page
697+
for qualifying instruction is deposited in `hstatus.MTAG_I`. Furthermore,
698+
when HSX*/HLV* instructions walks VS-stage page table to fetch instruction then
699+
`hstatus.MTAG_I` is set to AND of VS-stage leaf entries `MTAG` and `X` bits.
627700

628701
<<<
629702

0 commit comments

Comments
 (0)