Skip to content

Commit a208744

Browse files
authored
src/mte*: add rules supervisor access to user page and hv loads and stores (#66)
1 parent 47d1159 commit a208744

File tree

2 files changed

+89
-4
lines changed

2 files changed

+89
-4
lines changed

src/mte_tag.adoc

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,38 @@ accesses or self modifying code do not need `MTAG` bit. Thus `MTAG` bit is
383383
kept as reserved for such page table encodings.
384384
====
385385

386+
==== Tag checks on supervisor accesses to user pages
387+
388+
Supervisor accesses to user pages do not generate checked accesses and if
389+
memory tagging is enabled for user mode then MTAG bit in first stage page
390+
tables is ignored.
391+
392+
[[HYPERVISOR_LDST]]
393+
=== Memory tagging and hypervisor memory accesses
394+
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.
400+
401+
`xMT_MODE` (see <<MEM_TAG_EN>>) for HLV* and HSV* instructions is defined based
402+
on the effective privilege of VS or VU (as defined in privileged specification),
403+
execution environment privilege (HS or HU) and may generate checked memory
404+
accesses (see below).
405+
406+
- Execution environment HS/HU and effective privilege VS : `henvcfg.MT_MODE`
407+
- Execution environment HS and effective privilege VU : `senvcfg.MT_MODE`
408+
- Execution environment HU and effective privilege VU : `hstatus.VUMT_MODE`
409+
410+
If page based virtual memory is enabled for V=1, HLV*/HSV* generate checked
411+
memory accesses based on rules specified by paging bit `MTAG` in first stage
412+
page tables (see <<TAGGED_PAGE>>).
413+
414+
If HLV*/HSV* instructions result in a tag mismatch, software check exception is
415+
delivered to HS mode with tval = 4 and hstatus.GVA set. In case of tag mismatch,
416+
software check exception is always delivered synchronously.
417+
386418
[[MEMTAG_CSR_CTRL]]
387419
=== CSR bits for memory tagging
388420

@@ -398,8 +430,26 @@ can be reported asynchronously (see <<ASYNC_SW_CHECK>>).
398430
[[MEM_TAG_EN]]
399431
==== Memory tagging enable and pointer_tag_width
400432

401-
The term `xMT_MODE` is used to determine if memory tagging is enabled in
402-
current execution environment (privilege mode).
433+
The term `xMT_MODE` for effective privilege is used to determine if memory
434+
tagging is enabled on memory accesses. In some cases like hypervisor load and
435+
store instructions (HLV*/HSV*), effective privilege will be different from
436+
underlying execution environment privilege. Following table determines source
437+
for `xMT_MODE` depending on effective privilege.
438+
439+
.`xMT_MODE` source
440+
[width=100%]
441+
[%header, cols="^4,^12"]
442+
|===
443+
|`Privilege` | Memory tagging state
444+
| M | mseccfg.MT_MODE
445+
| S/HS | menvcfg.MT_MODE
446+
| U/HU | senvcfg.MT_MODE
447+
| VS | henvcfg.MT_MODE
448+
| VU | senvcfg.MT_MODE
449+
| VS(HLV*/HSV*) | henvcfg.MT_MODE
450+
| VU(HLV*/HSV* in HS) | senvcfg.MT_MODE
451+
| VU(HLV*/HSV* in HU) | hstatus.VUMT_MODE
452+
|===
403453

404454
Following table describes different encodings of `MT_MODE` and corresponding
405455
configuration
@@ -544,6 +594,37 @@ When `MT_MODE` is `0b00`, the following rules apply to VS-mode:
544594

545595
* Zimt instructions will revert to their behavior as defined by Zimop.
546596

597+
==== Hypervisor Status Register (`hstatus`)
598+
599+
.Hypervisor status register (`hstatus`)
600+
[wavedrom, ,svg]
601+
....
602+
{reg: [
603+
{bits: 5, name: 'WPRI'},
604+
{bits: 1, name: 'VSBE'},
605+
{bits: 1, name: 'GVA'},
606+
{bits: 1, name: 'SPV'},
607+
{bits: 1, name: 'SPVP'},
608+
{bits: 1, name: 'HU'},
609+
{bits: 2, name: 'WPRI'},
610+
{bits: 6, name: 'VGEIN'},
611+
{bits: 2, name: 'WPRI'},
612+
{bits: 1, name: 'VTVM'},
613+
{bits: 1, name: 'VTW'},
614+
{bits: 1, name: 'VTSR'},
615+
{bits: 9, name: 'WPRI'},
616+
{bits: 2, name: 'VSXL'},
617+
{bits: 14, name: 'WPRI'},
618+
{bits: 2, name: 'HUPMM'},
619+
{bits: 2, name: 'VUMT_MODE'},
620+
{bits: 12, name: 'WPRI'},
621+
], config:{lanes: 4, hspace:1024}}
622+
....
623+
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.
627+
547628
<<<
548629

549630
=== Appendix

src/mte_vatag.adoc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ privileged CSRs.
7676
| U | `svittu`
7777
| S / HS | `svitts`
7878
| VS | `vsvitts`
79+
| VU | `vsvittu`
7980
| M | `mvitt`
8081
|===
8182

82-
`Svatag` defines the `svittu`, `svitts` and `vsvitts` CSRs while `Smvatag`
83-
defines `mvitt`.
83+
`Svatag` defines the `svittu`, `svitts`, `vsvittu`` and `vsvitts` CSRs while
84+
`Smvatag` defines `mvitt`.
8485

8586
[[TAG_MEM_PROTECTION]]
8687
=== Protection of tag storage
@@ -114,3 +115,6 @@ are implementation defined.
114115
address space between user and supervisor with user address space spanning
115116
from zero to maxium positive address while supervisor address space spanning
116117
from minimum negative value to maximum negative value.
118+
119+
HLV* and HSV* instructions use `vsvittu` or `vsvitts` as base of the tag table
120+
depending on if `hstatus.SPVP=0` or `hstatus.SPVP=1`, respectively.

0 commit comments

Comments
 (0)