-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to understand the PMA and the PBMT? #1687
Comments
Normally, the answer is yes, they are necessary. Without this PMA, the processor would not know whether a physical-memory access (without PBMT, I mean) could be allocated in cache. (Obviously, implementations without caches don't need this PMA.)
It's hard to know how to answer this question since it is so broad, but one important consideration is that PBMT can only make the attributes stronger; it can't make them weaker. So the PMAs should err on the side of weak. For example, you might define the PMAs for all of main memory to be cacheable, so that PBMT can override subsets of main memory to be NC/IO.
PMA is a must, because not all accesses use the page tables. Those untranslated accesses need attributes, too. |
|
How to define the pma attr when V=1 and pbmte=0 when the V=1, hgatp.mode !=bare, vsatp.mode !=bare, pbmte=0
When two-stage address translation is enabled within the H extension, the page-based memory types are also applied in two stages. First, if hgatp.MODE is not equal to zero, non-zero G-stage PTE PBMT bits override the attributes in the PMA to produce an intermediate set of attributes. Otherwise, the PMAs serve as the intermediate attributes. Second, if vsatp.MODE is not equal to zero, non-zero VS-stage PTE PBMT bits override the intermediate attributes to produce the final set of attributes used by |
When PBMTE=0 (i.e Svpbmt is disabled and must appear - per the spec - as if it is not implemented), the memory attributes for memory accesses are determined simply (and solely) by the PMAs. And in two-stage address translation, if Svpbmt is not enabled/implemented for a given stage, then the behavior is the same as if you read the spec paragraph about two-stage translation with MODE=0 (i.e. Svpbmt not enabled/implemented has the same effect as Bare mode translation - in both cases actual address translation using page tables is not in effect and hence there is no PTE PBMT field to take into account). |
Hi gfavor, Thank you very much for your kind reply.
|
On Sun, Oct 27, 2024 at 8:55 AM rock-ifly ***@***.***> wrote:
And in two-stage address translation, if Svpbmt is not enabled/implemented
for a given stage, then the behavior is the same as if you read the spec
paragraph about two-stage translation with MODE=0 (i.e. Svpbmt not
enabled/implemented has the same effect as *Bare mode translation* - in
both cases actual address translation using page tables is not in effect
and hence there is no PTE PBMT field to take into account).
---->Q1: I am not clear on this spot. what does the bare mode mean, Q1a or
Q1b?
Q1a) vsatp.mode=Bare in VS-stage translation, or just Q1b) the
pbmt_pte_VS=0( mean Bare?) ? If the answer is Q1a, why?
As defined in the Priv spec, *atp.MODE = 0 = "Bare". This applies for all
three *atp CSRs.
---->Q2: when V=1(virutualizeion is running), if menvcfg.pbmte=0,
menvcfg.pbmte=1, but per the spec, henvcfg.pbmte is read-only zero. Does it
mean Q2a or Q2B?
Q2a)if menvcfg.pbmte=0, then henvcfg.pbmte=0, and all the pbmt_pte_S/VS/G
are no longer used,?
Q2b) or the menvcfg.pbmte=0 just make pbmt_pte_G no longer used, and the
henvcfg.pbmte=1 make pbmt_pte_VS still be used as usual?
See the definitions of menvcfg.PBMTE and henvcfg.PBMTE in the Priv spec -
they fully define the effects that each bit has (including answering your
question). Note that Q2b directly violates the spec for menvcfg.PBMTE.
Message ID: ***@***.***>
… |
Hi gfavor, Thank you very much! Do you mean Thanks again! |
when V=1, are there 4 types of translation as following?
|
Re-read the spec, it seems that PMA is a more general memAttr configuration, NOT for every page. To specify the memAttr for every single page, PBMT field is introduced. That's to say, PMA is general and configured for a large part of the memory, NOT page by page, while the PBMT is used for every single page since it is in the payload of every leafpte.
|
Also: PMA operates even if translation is disabled,
There is effectively a PMA for each attribute, each of which can
have multiple regions of arbitrary size
The PBMT bit in page table entry overrides the corresponding PMA
attributes (or leaves them unchanged)
…On Sun, Oct 27, 2024 at 8:32 PM rock-ifly ***@***.***> wrote:
Re-read the spec, it seems that PMA is a more general memAttr
configuration, NOT for every page. To specify the memAttr for every single
page, PBMT field is introduced. That's to say, PMA is general and
configured for a large part of the memory, NOT page by page, while the PBMT
is used for every single page since it is in the payload of every leafpte.
1. From a perspective, PBMT is kind of MAIR registers for the ARM
architecture. Both the PBMT and AttrIndex(index for MAIR codes) are set
page by page.
2. For a more general usage, PBMT fields are commonly used in the
translation to get more varieties of the memAttr.
—
Reply to this email directly, view it on GitHub
<#1687 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHPXVJWIPDCJNZDJPVS3UZDZ5WV3RAVCNFSM6AAAAABQCUB44OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBQGQ3TQOBWHA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Hi Allen, Thank you for your helpful reply. So we just take PMA as a basic configration for the memory space, and use PBMT to describe the PMA attrs per page, and PBMT give a more choice configure the PMA_effective for the page. I am puzzled by RV spec about two-stage translation, and doubt why PBMTE=0 means corresponding Xatp.MODE=Bare.
|
I am puzzled by RV spec about two-stage translation, and doubt why PBMTE=0
means corresponding Xatp.MODE=Bare.
PBMTE=0 corresponds to *atp.MODE=Bare in that there is no leaf PTE PBMT
field to provide any selective override of the PMA attributes. If that is
a confusing reference, then it may be better to simply think in terms of
PBMTE=0 meaning that there is no override of attributes by the associated
translation table. In that sense the effect is the same as if PBMTE=1 and
PBMT=0 from the associated translation table leaf PTE.
Message ID: ***@***.***>
… |
Hi gfavor, Thanks for your reply. Let's make it clear,
It is clear that pbmt works during two stage translation.
Q1) what does "otherwise" mean? Is memAttr_intermediate = G-stage PTE PBMT, override the PMA under the conditionA((hgatp.MODE !=0) & (pbmt_pte_G !=0)), the "otherwise" is ~conditionA, that 's ~conditionA = ((hgatp.MODE=Bare) | (pbmt_pte_G = 0))? So the pmbte=0 means use the original PMA.
Q2) what does "otherwise" mean? Is memAttr_final = VS-stage PTE PBMT, override the memAttr_intermediate under the conditionB((vsatp.MODE !=0) & (pbmt_pte_VS !=0)), the "otherwise" is ~conditionB, that 's ~conditionB = ((vsatp.MODE=Bare) | (pbmt_pte_VS = 0))? So the henvcfg.pmbte=0 means use the memAttr_intermediate. Q3) it seems that G-stage have more power to determine the final memAttr. Why can't the GuestOS PMA have more power than G-stage PMA? It seems the right way that GuestOS have more power to control the final memAttr, is it right? |
First, if hgatp.MODE is not equal to zero, non-zero G-stage PTE PBMT bits
override the attributes in the PMA to produce an intermediate set of
attributes. *Otherwise*, the PMAs serve as the intermediate attributes.
Q1) what does "otherwise" mean?
This means that if the preceding condition is not true, then the following
statement (that the PMAs serve as the intermediate attributes) applies.
Q3) it seems that G-stage have more power to determine the final memAttr.
Why can't the GuestOS PMA have more power than G-stage PMA? It seems the
right way that GuestOS have more power to control the final memAttr, is it
right?
A VM should see the effective memory attributes based on the actual PMAs as
then modified by the hypervisor through G-stage page tables. In other
words, the hypervisor determines the memory attributes that a guest sees
(and can then further modify via its VS-stage page tables).
|
So can we get the following rules
|
That is pretty much correct. Just note that PMAs provide a set of memory attributes - some of which are modified by a non-zero PBMT and some are not. Svpbmt specifies the attributes that definitely are modified and then says:
|
I try to understand the logic, since i found the override logic give more power for G-stage(Hypervisor), GuestOS
|
Yes, Svpbmt didn't pursue an ARM-like model. But RISC-V and ARM are different in an important regard: 1) ARM doesn't have PMAs and only/always determines memory types from page tables - even in its equivalent of M-mode. In this regard, RISC-V is more like x86 - which has its equivalent of region-based "PMAs" and does not use a strict model of only "strenghthening" a memory type. The details in all this are not so obvious, but were considered at the time of developing this extension. Simply comparing with what ARM did is misleading because of the different underlying architectural situation of having region-based PMAs. |
OK, I need more time to think about it. Thank you very much for your kindly and helpful reply. |
Hi gfavor, I am puzzled with the specific condition when V=1, vsatp.mode=Sv39, pbmt_pte_VS=2b00, hgatp.mode=Bare,
Is there something wrong? Since hgatp.mode=Bare, why not just use GuestOS default PMA (PMA_VS-stage) as the memAttr_final? Thank you. |
PBMT=0 is described as "None", meaning that there are no "requested memory attributes" or, in other words, there is no override of any of the memory attributes. It is not saying that the attributes comes directly from the PMAs. |
Q1 - First,
So when Pbmt=0 means no override of any memory attributes. Can GuestOS have its own PMA_VS_stage? Can we use the PMA_VS_stage as the final memAttr when hgatp.mode=Bare? Q2 - Second, we find that linux for RISCV has assigned pte.memAttr=Cacheable when pbmt=2b00. Can we take the cacheable as the final cacheablity when pbmt_pte_vs=2b00, under the condition vstatp.mode=Sv39, pbmt_pte_vs=2b00, hgatp.mode=Bare(flat translation)?
Q3 - what does your PMAs mean? system predefined PMA(PMA_original), like the SoC system predetermined, or the GuestOS default PMA(PMA_VS_stage), like very system has its own default PMA? Thank you. |
"PMAs" are defined in chapter/section "3.6. Physical Memory Attributes" of the Priv spec. There are no other "PMAs" in he RISC-V architecture that belong to any specific privilege level or translation mode or stage of translation. There are just the one and only preceding PMAs. Single and two-stage translation can modify (aka override) selected physical memory attributes through use of the Svpbmt extension. Regarding Q2, if the PMAs for an address specify the Cacheable attribute and there is no override of that by a leaf PTE, then - as defined by the Svpbmt extension - the final effective attribute is Cacheable. (And this is orthogonal to the translation MODE(s) in effect for translating that address.) |
What is the relationship between the PMA and the PBMT?
4)Can we just use the PBMT field as PMA field in the pte, without implementation an common PMA? That is PBMT=0 means Cacheable, PBMT=1 means NC( non-Cacheable), PBMT=2 means IO(nGnRnE).PBMT=3 means page fault. Or the PMA is a MUST, and the PBMT is a suppplement. What is the ordinary/common means for the PMA and the PBMT?
The text was updated successfully, but these errors were encountered: