@@ -380,11 +380,20 @@ 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 and collect MTAG bit from
384+ VS-stage page table for code page of guest instruction in following manner
385+
386+ hstatus.MTAG_I = VS-stage_leaf_PTE(s).MTAG & VS-stage_leaf_PTE(s).X
387+
388+ If `vsatp.MODE == BARE`, then collected value of `hstatus.MTAG_I` will be 0.
389+
390+ HLV*/HSV* instructions generate unchecked memory accesses if VS-stage leaf
391+ PTE entry's execute permission bit is set.
392+
393+ If `hstatus.MTAG_I` is set, then HLV*/HSV* instructions do not generate
394+ checked accesses. If `hstatus.MTAG_I` is clear, then HLV*/HSV* instructions
395+ in HS and HU mode may generate checked accesses depending on effective privilege
396+ of VS or VU (as defined in privileged specification).
388397
389398`xMT_MODE` (see <<MEM_TAG_EN>>) for HLV* and HSV* instructions is defined based
390399on the effective privilege of VS or VU (as defined in privileged specification),
@@ -403,6 +412,23 @@ If HLV*/HSV* instructions result in a tag mismatch, software check exception is
403412delivered to HS mode with tval = 4 and hstatus.GVA set. In case of tag mismatch,
404413software check exception is always delivered synchronously.
405414
415+ [[MPRV_LDST]]
416+ === Memory tagging on loads/stores affected by Modify Privilege bit (MPRV)
417+
418+ If MPRV and MXR both are set, then load instruction collect MTAG bit from first
419+ stage page table for code page of guest instruction in following manner
420+
421+ mstatus.MTAG_I = first-stage_leaf_PTE(s).MTAG & first-stage_leaf_PTE(s).X
422+
423+ If `satp.MODE == BARE`, then collected value of `mstatus.MTAG_I` will be 0.
424+
425+ If MRPV=1 and first-stage page table leaf entry PTE (for effective mode S/U/VU/VS
426+ /HS/HU) has execute permission bit set then load generate unchecked accesses. If
427+ MPRV=1 and `mstatus.MTAG_I` is set, then load and store instructions generate
428+ unchecked accesses. If MPRV=1 and `mstatus.MTAG_I` is clear, then load and store
429+ instructions may generate checked accesses depending on effective privilege.
430+ `xMT_MODE` is selected based on effective privilege (see <<MEM_TAG_EN>>).
431+
406432[[MEMTAG_CSR_CTRL]]
407433=== CSR bits for memory tagging
408434
@@ -574,6 +600,52 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
574600
575601* Zimt instructions will revert to their behavior as defined by Zimop.
576602
603+ ==== Machine Status Register (`mstatus`)
604+
605+ .Machine-mode status register (`mstatus`) for RV64
606+ [wavedrom, ,svg]
607+ ....
608+ {reg: [
609+ {bits: 1, name: 'WPRI'},
610+ {bits: 1, name: 'SIE'},
611+ {bits: 1, name: 'WPRI'},
612+ {bits: 1, name: 'MIE'},
613+ {bits: 1, name: 'WPRI'},
614+ {bits: 1, name: 'SPIE'},
615+ {bits: 1, name: 'UBE'},
616+ {bits: 1, name: 'MPIE'},
617+ {bits: 1, name: 'SPP'},
618+ {bits: 2, name: 'VS[1:0]'},
619+ {bits: 2, name: 'MPP[1:0]'},
620+ {bits: 2, name: 'FS[1:0]'},
621+ {bits: 2, name: 'XS[1:0]'},
622+ {bits: 1, name: 'MPRV'},
623+ {bits: 1, name: 'SUM'},
624+ {bits: 1, name: 'MXR'},
625+ {bits: 1, name: 'TVM'},
626+ {bits: 1, name: 'TW'},
627+ {bits: 1, name: 'TSR'},
628+ {bits: 1, name: 'SPELP'},
629+ {bits: 1, name: 'SDT'},
630+ {bits: 7, name: 'WPRI'},
631+ {bits: 2, name: 'UXL[1:0]'},
632+ {bits: 2, name: 'SXL[1:0]'},
633+ {bits: 1, name: 'SBE'},
634+ {bits: 1, name: 'MBE'},
635+ {bits: 1, name: 'GVA'},
636+ {bits: 1, name: 'MPV'},
637+ {bits: 1, name: 'MTAG_I'},
638+ {bits: 1, name: 'MPELP'},
639+ {bits: 1, name: 'MDT'},
640+ {bits: 20, name: 'WPRI'},
641+ {bits: 1, name: 'SD'},
642+ ], config:{lanes: 4, hspace:1024}}
643+ ....
644+
645+ The Zimt extension adds `MTAG_I` bit to `mstatus`. When a trap is taken to
646+ M-mode and `mtval` is written with nonzero value, then MTAG bit for code page
647+ of trapping instruction is deposited in `mstatus.MTAG_I`.
648+
577649==== Hypervisor Status Register (`hstatus`)
578650
579651.Hypervisor status register (`hstatus`)
@@ -586,7 +658,8 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
586658 {bits: 1, name: 'SPV'},
587659 {bits: 1, name: 'SPVP'},
588660 {bits: 1, name: 'HU'},
589- {bits: 2, name: 'WPRI'},
661+ {bits: 1, name: 'MTAG_I'},
662+ {bits: 1, name: 'WPRI'},
590663 {bits: 6, name: 'VGEIN'},
591664 {bits: 2, name: 'WPRI'},
592665 {bits: 1, name: 'VTVM'},
@@ -601,9 +674,12 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
601674], config:{lanes: 4, hspace:1024}}
602675....
603676
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.
677+ The Zimt extension adds `VUMT_MODE` (bit 51:50) to `hstatus`. `VUMT_MODE`
678+ selects the `xMT_MODE` if execution environment is HU mode and effective
679+ privilege mode is VU. `hstatus.MTAG_I` bit emulates `MTAG` bit for
680+ instruction fetch from code page. When a trap is taken to HS mode and `htinst`
681+ is written with nonzero value, then VS-stage page table's MTAG bit on code page
682+ for trapping instruction is deposited in `hstatus.MTAG_I`.
607683
608684<<<
609685
0 commit comments