Skip to content

Add gentag exclusion-mask CSRs - #102

Merged
Adam 'pi3' Zabrocki (Adam-pi3) merged 2 commits into
riscv:mainfrom
Adam-pi3:main
Jun 26, 2026
Merged

Add gentag exclusion-mask CSRs#102
Adam 'pi3' Zabrocki (Adam-pi3) merged 2 commits into
riscv:mainfrom
Adam-pi3:main

Conversation

@Adam-pi3

Copy link
Copy Markdown
Collaborator

Add pairs of CSRs to hold a 128-bit tag generation exclusion mask for gentag. The mask controls which pointer tag values gentag may generate, allowing software to exclude special values such as zero for untagged pointers.

Define mask semantics for 4-bit and 7-bit pointer tags, clarify that the mask affects only gentag, and leave CSR addresses to be allocated.

This commit addresses #92.

Add pairs of CSRs to hold a 128-bit tag generation exclusion mask for
gentag. The mask controls which pointer tag values gentag may generate,
allowing software to exclude special values such as zero for untagged
pointers.

Define mask semantics for 4-bit and 7-bit pointer tags, clarify that the
mask affects only gentag, and leave CSR addresses to be allocated.

This commit addresses riscv#92.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a final point on my side, we also need to address the fact that the addition
of these CSRs create a data syntactic dependency in the memory model between
gentag and the *tagexclude CSRs. Specifically, the dependency as the
*tagexclude as sources and the destination operand of gentag as the
destination.

Comment thread src/mte_tag.adoc Outdated
@Adam-pi3

Adam 'pi3' Zabrocki (Adam-pi3) commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

As a final point on my side, we also need to address the fact that the addition of these CSRs create a data syntactic dependency in the memory model between gentag and the *tagexclude CSRs. Specifically, the dependency as the *tagexclude as sources and the destination operand of gentag as the destination.

I can add the following sentence:

For the purposes of syntactic dependencies in the memory model, `gentag` has the
active tag generation exclusion mask CSRs as source operands and `rd` as its
destination operand.

Comment thread src/mte_tag.adoc Outdated

When `pointer_tag_width = 7` is supported by the implementation, bits `[127:0]`
are writable, subject to the requirement that the read-back value leaves at
least one tag value permitted for every supported `pointer_tag_width`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"requirement that the read-back value leaves at
least one tag value permitted for every supported pointer_tag_width"

isn't that requirement also needed for tag_width = 4?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my actual comment: this shouldn't be in the same sentence as "When pointer_tag_width = 7"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lfiolhais

Copy link
Copy Markdown
Contributor

As a final point on my side, we also need to address the fact that the addition of these CSRs create a data syntactic dependency in the memory model between gentag and the *tagexclude CSRs. Specifically, the dependency as the *tagexclude as sources and the destination operand of gentag as the destination.

I can add the following sentence:

For the purposes of syntactic dependencies in the memory model, `gentag` has the
active tag generation exclusion mask CSRs as source operands and `rd` as its
destination operand.

LGTM 👍

Clarify that gentag depends on the active exclusion-mask CSRs for memory-model
syntactic dependencies.

Also specify that the exclusion-mask CSRs are legalized on write, that changing
pointer_tag_width does not modify the mask, and that at least one tag value in
the mandatory 4-bit tag range must remain permitted.
@lfiolhais

Copy link
Copy Markdown
Contributor

Thanks for the PR Adam 'pi3' Zabrocki (@Adam-pi3). All of my concerns were addressed. Apologies for the sparse replies. I'm at the EU Sumit and don't have much time to look at my laptop.

@radimkrcmar

Copy link
Copy Markdown
Contributor

I didn't notice this PR before the meeting, sorry.

When adding new architectural state, we also have to provide protection against side channel usage on software that doesn't context-switch it. A bit in *stateen CSRs seems ideal.

Comment thread src/mte_tag.adoc
| `henvmtagexclude1:henvmtagexclude0`

| VU
| `senvmtagexclude1:senvmtagexclude0`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity -- are there performance reasons against providing a single CSR pair for all privilege levels?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. For the `stateen point, I understand your later comment that this is already covered by the existing new state added for Svatag, so I did not add a separate stateen bit in this PR.

On the single-CSR-pair question: I don't think the main reason for separate CSR pairs is performance. The intent was to mirror the existing per-execution- environment MT_MODE structure and allow M, S/HS, U/HU, and VS/VU contexts to have independent gentag exclusion policies. A single global pair would be simpler architecturally, but it would couple host/guest/kernel/user/M-mode policy and could require extra save/restore when switching between domains that want different excluded tags.

@Adam-pi3
Adam 'pi3' Zabrocki (Adam-pi3) merged commit c0e7902 into riscv:main Jun 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants