Skip to content

src/mte_tag: tighten the first stage page table conditions for MTAG#79

Merged
deepak0414 merged 1 commit intoriscv:mainfrom
deepak0414:mtag_page_bit_clarification
Nov 11, 2025
Merged

src/mte_tag: tighten the first stage page table conditions for MTAG#79
deepak0414 merged 1 commit intoriscv:mainfrom
deepak0414:mtag_page_bit_clarification

Conversation

@deepak0414
Copy link
Collaborator

Quite often loader or other piece of code might read code pages. If a code page is set as MTAG=1, then those loads (to code page) will look for tags. This change clarifies in specification that loads/stores to pages marked as executable always generate unchecked memory accesses.

Setting MTAG for XWR=111 and XWR=010 was disallowed. Instead of raising page fault, raise access-fault exception to signify fatality.

@deepak0414 deepak0414 requested a review from fmayer October 30, 2025 04:39
@deepak0414
Copy link
Collaborator Author

It came to my attention that there was a bug on normal (non-MPRV, non-HLV/HSV)
load/store side as well. A load to code page shouldn't lead to checked accesses.
@fmayer , I assume that should be fine. Let me know if it isn't.

@radimkrcmar, if you could spend few minutes on this as well. That would be appreciated.

@radimkrcmar
Copy link

@radimkrcmar, if you could spend few minutes on this as well. That would be appreciated.

I am a bit out of water here as I don't understand why XWR is reserved, as XR seems practically the same, so any decision about how it should interact with tagging seems arbitrary to me.

@deepak0414
Copy link
Collaborator Author

@radimkrcmar, if you could spend few minutes on this as well. That would be appreciated.

I am a bit out of water here as I don't understand why XWR is reserved, as XR seems practically the same, so any decision about how it should interact with tagging seems arbitrary to me.

MTAG = 1 with XWR because it creates a situation where code can be self modifying or code is operating on data which is on same page. As per the rules tag checks should elided. However any such situation wanting tag checks or elision doesn't make sense. So totally avoiding that encoding to be possible and keeping it reserved.

@deepak0414
Copy link
Collaborator Author

deepak0414 commented Nov 2, 2025

@radimkrcmar, if you could spend few minutes on this as well. That would be appreciated.

I am a bit out of water here as I don't understand why XWR is reserved, as XR seems practically the same, so any decision about how it should interact with tagging seems arbitrary to me.

MTAG = 1 with XWR because it creates a situation where code can be self modifying or code is operating on data which is on same page. As per the rules tag checks should elided. However any such situation wanting tag checks or elision doesn't make sense. So totally avoiding that encoding to be possible and keeping it reserved.

Aah
I think I got your point. In case of XWR, it's probably better to ignore MTAG like in case of XR with MTAG.
Basically all loads to a page with X=1 will generate unchecked mem accesses. And thus avoid special casing. Kind of make sense. Let me think on that for a bit.

@deepak0414 deepak0414 force-pushed the mtag_page_bit_clarification branch from e41f634 to 8f9c7f7 Compare November 3, 2025 18:04
@deepak0414
Copy link
Collaborator Author

@radimkrcmar, if you could spend few minutes on this as well. That would be appreciated.

I am a bit out of water here as I don't understand why XWR is reserved, as XR seems practically the same, so any decision about how it should interact with tagging seems arbitrary to me.

MTAG = 1 with XWR because it creates a situation where code can be self modifying or code is operating on data which is on same page. As per the rules tag checks should elided. However any such situation wanting tag checks or elision doesn't make sense. So totally avoiding that encoding to be possible and keeping it reserved.

Aah I think I got your point. In case of XWR, it's probably better to ignore MTAG like in case of XR with MTAG. Basically all loads to a page with X=1 will generate unchecked mem accesses. And thus avoid special casing. Kind of make sense. Let me think on that for a bit.

Did an update on PR.

@deepak0414
Copy link
Collaborator Author

@fmayer says that its easier to say simply that checked accesses come executable page with mtag=0 towards a data page with mtag = 1.
Revise PR and try to simplify rules.

Quite often loader or other piece of code might read code pages. If a code
page is set as MTAG=1, then those loads (to code page) will look for tags.
This change clarifies in specification that loads/stores to pages marked
as executable always generate unchecked memory accesses.

If if memory tagging is not enabled for execution environment then `MTAG`
bit is ignored. This allows for setting up tagging and enabling/disabling
on sampling basis (without asking OS to clear to the bit when tagging is
disabled)

Signed-off-by: Deepak Gupta <debug@rivosinc.com>
@deepak0414 deepak0414 force-pushed the mtag_page_bit_clarification branch from 8f9c7f7 to 15d5106 Compare November 5, 2025 06:00
@deepak0414
Copy link
Collaborator Author

Can anyone take a look, approve or drop a comment?

@deepak0414 deepak0414 merged commit e322ef8 into riscv:main Nov 11, 2025
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.

2 participants