KVM : selftests: arm64: Explicitly set the page attrs to Inner-Shareable
v2 cover KVM : selftests: arm64: Explicitly set the page attrs to Inner-Shareable
The series fixes a conflict in memory attributes in some implementations,
such as Neoverse-N3, that causes a data abort in guest EL1 with FSC 0x35 (IMPLEMENTATION DEFINED fault (Unsupported Exclusive or Atomic access)).
Patch-1 is a cleanup patch that replaces numbers (and comments) to using proper macros for hardware configuration, such as registers and page-table entries.
Patch-2 fixes the actual bug and sets the page attrs to Inner-Shareable by default for the VMs created in the selftests. More details are presented in the commit text.
v1: https://lore.kernel.org/all/[email protected]/
v1 -> v2: Addressed Oliver's comments (thank you)
- Moved the TCR_* macros from tools' sysreg.h to selftests' local processor.h in patch-1.
- Adjsted the citations to describe the issue more appropriately in patch-2.
Raghavendra Rao Ananta (2):
KVM: selftests: arm64: Introduce and use hardware-definition macros
KVM: selftests: arm64: Explicitly set the page attrs to
Inner-Shareable
.../selftests/kvm/arm64/page_fault_test.c | 2 +- .../selftests/kvm/include/arm64/processor.h | 67 +++++++++++++++++-- .../selftests/kvm/lib/arm64/processor.c | 60 ++++++++++------- 3 files changed, 96 insertions(+), 33 deletions(-)
base-commit: 38fec10eb60d687e30c8c6b5420d86e8149f7557
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
PATCH v2 1/2 KVM: selftests: arm64: Introduce and use hardware-definition macros
The kvm selftest library for arm64 currently configures the hardware fields, such as shift and mask in the page-table entries and registers, directly with numbers. While it add comments at places, it's better to rewrite them with appropriate macros to improve the readability and reduce the risk of errors. Hence, introduce macros to define the hardware fields and use them in the arm64 processor library.
Most of the definitions are primary copied from the Linux's header, arch/arm64/include/asm/pgtable-hwdef.h.
No functional change intended.
--- .../selftests/kvm/arm64/page_fault_test.c | 2 +- .../selftests/kvm/include/arm64/processor.h | 66 +++++++++++++++++-- .../selftests/kvm/lib/arm64/processor.c | 57 ++++++++-------- 3 files changed, 92 insertions(+), 33 deletions(-)
tools/testing/selftests/kvm/arm64/page_fault_test.c +1 -1
@@ -199,7 +199,7 @@ static bool guest_set_ha(void)if (hadbs ==0 )return false; - tcr =read_sysreg (tcr_el1) |TCR_EL1_HA ; + tcr =read_sysreg (tcr_el1) |TCR_HA ;write_sysreg (tcr, tcr_el1);isb ();
tools/testing/selftests/kvm/include/arm64/processor.h +60 -6
78 lines not on this page · raw message
tools/testing/selftests/kvm/lib/arm64/processor.c +31 -26
143 lines not on this page · raw message
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
PATCH v2 2/2 KVM: selftests: arm64: Explicitly set the page attrs to Inner-Shareable
In reply to Raghavendra Rao AnantaAtomic instructions such as 'ldset' over (global) variables in the guest is observed to cause an EL1 data abort with FSC 0x35 (IMPLEMENTATION DEFINED fault (Unsupported Exclusive or Atomic access)). The observation was particularly apparent on Neoverse-N3.
According to ARM ARM DDI0487L.a B2.2.6 (Possible implementation restrictions on using atomic instructions), atomic instructions are architecturally guaranteed for Inner Shareable and Outer Shareable attributes. For Non-Shareable attribute, the atomic instructions are not atomic and issuing such an instruction can lead to the FSC mentioned in this case (among other things).
Moreover, according to DDI0487L.a C3.2.6 (Single-copy atomic 64-byte load/store), it is implementation defined that a data abort with the mentioned FSC is reported for the first stage of translation that provides an inappropriate memory type. It's likely that Neoverse-N3 chose to implement these two and why we see an FSC of 0x35 in EL1 upon executing atomic instructions.
ARM64 KVM selftests sets no shareable attributes, which makes them Non-Shareable by default. Hence, explicitly set them as Inner-Shareable to fix this issue.
--- tools/testing/selftests/kvm/include/arm64/processor.h | 1 + tools/testing/selftests/kvm/lib/arm64/processor.c | 3 +++ 2 files changed, 4 insertions(+)
tools/testing/selftests/kvm/include/arm64/processor.h +1 -0
@@ -113,6 +113,7 @@#define PMD_TYPE_TABLE BIT(1)#define PTE_TYPE_PAGE BIT(1) +#define PTE_SHARED (UL(3) << 8)/* SH[1:0], inner shareable */ #define PTE_AF BIT(10)#define PTE_ADDR_MASK (page_shift) GENMASK(47, (page_shift))
tools/testing/selftests/kvm/lib/arm64/processor.c +3 -0
@@ -172,6 +172,9 @@ static void _virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, } pg_attr =PTE_AF |PTE_ATTRINDX (attr_idx) |PTE_TYPE_PAGE |PTE_VALID ; +if (!use_lpa2_pte_format (vm)) + pg_attr |=PTE_SHARED ; + *ptep =addr_pte (vm, paddr, pg_attr); }
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Re: [PATCH v2 2/2] KVM: selftests: arm64: Explicitly set the page attrs to Inner-Shareable
.
Quoted 13 lines · Raghavendra Rao Ananta
Atomic instructions such as 'ldset' over (global) variables in the guest is observed to cause an EL1 data abort with FSC
0x35(IMPLEMENTATION DEFINED fault (Unsupported Exclusive or Atomic access)). The observation was particularly apparent on Neoverse-N3.According to ARM ARM DDI0487L.a B2.2.6 (Possible implementation restrictions on using atomic instructions), atomic instructions are architecturally guaranteed for Inner Shareable and Outer Shareable attributes. For Non-Shareable attribute, the atomic instructions are not atomic and issuing such an instruction can lead to the FSC mentioned in this case (among other things).
Quoted 6 lines
Moreover, according to DDI0487L.a C3.2.6 (Single-copy atomic 64-byte load/store), it is implementation defined that a data abort with the mentioned FSC is reported for the first stage of translation that provides an inappropriate memory type. It's likely that Neoverse-N3 chose to implement these two and why we see an FSC of
0x35in EL1 upon executing atomic instructions.
nit: It's likely that Neoverse-N3 chose to implement this option (the first option) instead of reporting at the final enabled stage of translation
I have minor question here: The DDI0487L C3.2.6 (Single-copy atomic 64-byte load/store) mentioned
"""
When the instructions access a memory type that is not one of the following, a data abort for unsupported Exclusive or atomic access is generated:
• Normal Inner Non-cacheable, Outer Non-cacheable. """
So, the above is the "Normal Inner Non-cacheable", but in our case we have "Normal and non-shareable" in stage-1 mapping, right? I know it is very close, but it seems the situation is still only "one bit" away in my understanding...
Quoted 41 lines
ARM64 KVM selftests sets no shareable attributes, which makes them Non-Shareable by default. Hence, explicitly set them as Inner-Shareable to fix this issue.
Suggested-by Oliver Upton <[email protected]>Signed-off-by Raghavendra Rao Ananta <[email protected]>--- tools/testing/selftests/kvm/include/arm64/processor.h | 1 + tools/testing/selftests/kvm/lib/arm64/processor.c | 3 +++ 2 files changed, 4 insertions(+)tools/testing/selftests/kvm/include/arm64/processor.h +1
-0@@ -113,6 +113,7 @@#define PMD_TYPE_TABLE BIT(1)#define PTE_TYPE_PAGE BIT(1) +#define PTE_SHARED (UL(3) << 8)/* SH[1:0], inner shareable */ #define PTE_AF BIT(10)#define PTE_ADDR_MASK (page_shift) GENMASK(47, (page_shift))tools/testing/selftests/kvm/lib/arm64/processor.c +3
-1@@ -172,6 +172,9 @@ static void _virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, } pg_attr =PTE_AF |PTE_ATTRINDX (attr_idx) |PTE_TYPE_PAGE |PTE_VALID ; +if (!use_lpa2_pte_format (vm)) + pg_attr |=PTE_SHARED ; + *ptep =addr_pte (vm, paddr, pg_attr); } --2.49.0.504.g3bcea36a83-goog
Re: [PATCH v2 2/2] KVM: selftests: arm64: Explicitly set the page attrs to Inner-Shareable
Quoted 15 lines · Mingwei Zhang
Quoted 13 lines · Raghavendra Rao Ananta
Atomic instructions such as 'ldset' over (global) variables in the guest is observed to cause an EL1 data abort with FSC
0x35(IMPLEMENTATION DEFINED fault (Unsupported Exclusive or Atomic access)). The observation was particularly apparent on Neoverse-N3.According to ARM ARM DDI0487L.a B2.2.6 (Possible implementation restrictions on using atomic instructions), atomic instructions are architecturally guaranteed for Inner Shareable and Outer Shareable attributes. For Non-Shareable attribute, the atomic instructions are not atomic and issuing such an instruction can lead to the FSC mentioned in this case (among other things).
Quoted 6 lines
Quoted 6 lines
Moreover, according to DDI0487L.a C3.2.6 (Single-copy atomic 64-byte load/store), it is implementation defined that a data abort with the mentioned FSC is reported for the first stage of translation that provides an inappropriate memory type. It's likely that Neoverse-N3 chose to implement these two and why we see an FSC of
0x35in EL1 upon executing atomic instructions.
Ok, can we please drop this second reference?
This is talking about something else (FEAT_LS64) that happens to share the same FSC as an unsupported atomic instruction. I mentioned this to you internally as an illustration of how different implementations may behave when determining if the attributes support a particular access, but it isn't actually relevant to this change.
Quoted 3 lines
nit: It's likely that Neoverse-N3 chose to implement this option (the first option) instead of reporting at the final enabled stage of translation
I would much rather we rely on the language that describes what the architecture guarantees rather than speculate as to how Neoverse-N3 behaves.
Mentioning that the breakage was observed on Neoverse-N3 is still useful to add to the changelog.
Quoted 8 lines
I have minor question here: The DDI0487L C3.2.6 (Single-copy atomic 64-byte load/store) mentioned
"""
When the instructions access a memory type that is not one of the following, a data abort for unsupported Exclusive or atomic access is generated:
Quoted 7 lines
• Normal Inner Non-cacheable, Outer Non-cacheable. """
So, the above is the "Normal Inner Non-cacheable", but in our case we have "Normal and non-shareable" in stage-1 mapping, right? I know it is very close, but it seems the situation is still only "one bit" away in my understanding...
This citation relates to FEAT_LS64. If you look at B2.2.6 instead, it reads:
"""
The memory types for which it is architecturally guaranteed that the atomic instructions will be atomic are:
- Inner Shareable, Inner Write-Back, Outer Write-Back Normal memory with Read allocation hints and Write allocation hints and not transient.
- Outer Shareable, Inner Write-Back, Outer Write-Back Normal memory with Read allocation hints and Write allocation hints and not transient.
"""
and
"""
If the atomic insturctions are not atomic in regard to other agents that access memory, then performing an atomic instruction to such a location can have one or more of the following effects:
[...]
- The instruction generates an IMPLEMENTATION DEFINED fault reported using the Data Abort Fault status code of ESR_ELx.DFSC = 110101
"""
The memory type used by KVM selftests is *Non-Shareable*, which is not one of the memory types guaranteed by the architecture to work.
Thanks,
Oliver
Re: [PATCH v2 2/2] KVM: selftests: arm64: Explicitly set the page attrs to Inner-Shareable
Quoted 66 lines · Oliver Upton
Quoted 15 lines · Mingwei Zhang
Quoted 13 lines · Raghavendra Rao Ananta
Atomic instructions such as 'ldset' over (global) variables in the guest is observed to cause an EL1 data abort with FSC
0x35(IMPLEMENTATION DEFINED fault (Unsupported Exclusive or Atomic access)). The observation was particularly apparent on Neoverse-N3.According to ARM ARM DDI0487L.a B2.2.6 (Possible implementation restrictions on using atomic instructions), atomic instructions are architecturally guaranteed for Inner Shareable and Outer Shareable attributes. For Non-Shareable attribute, the atomic instructions are not atomic and issuing such an instruction can lead to the FSC mentioned in this case (among other things).
Quoted 6 lines
Quoted 6 lines
Moreover, according to DDI0487L.a C3.2.6 (Single-copy atomic 64-byte load/store), it is implementation defined that a data abort with the mentioned FSC is reported for the first stage of translation that provides an inappropriate memory type. It's likely that Neoverse-N3 chose to implement these two and why we see an FSC of
0x35in EL1 upon executing atomic instructions.Ok, can we please drop this second reference?
This is talking about something else (
FEAT_LS64) that happens to share the same FSC as an unsupported atomic instruction. I mentioned this to you internally as an illustration of how different implementations may behave when determining if the attributes support a particular access, but it isn't actually relevant to this change.Quoted 3 lines
nit: It's likely that Neoverse-N3 chose to implement this option (the first option) instead of reporting at the final enabled stage of translation
I would much rather we rely on the language that describes what the architecture guarantees rather than speculate as to how Neoverse-N3 behaves.
Mentioning that the breakage was observed on Neoverse-N3 is still useful to add to the changelog.
Quoted 8 lines
I have minor question here: The DDI0487L C3.2.6 (Single-copy atomic 64-byte load/store) mentioned
"""
When the instructions access a memory type that is not one of the following, a data abort for unsupported Exclusive or atomic access is generated:Quoted 7 lines
• Normal Inner Non-cacheable, Outer Non-cacheable. """
So, the above is the "Normal Inner Non-cacheable", but in our case we have "Normal and non-shareable" in stage-1 mapping, right? I know it is very close, but it seems the situation is still only "one bit" away in my understanding...
This citation relates to
FEAT_LS64. If you look at B2.2.6 instead, it reads:"""
The memory types for which it is architecturally guaranteed that the atomic instructions will be atomic are:
Quoted 8 lines
- Inner Shareable, Inner Write-Back, Outer Write-Back Normal memory with Read allocation hints and Write allocation hints and not transient.
- Outer Shareable, Inner Write-Back, Outer Write-Back Normal memory with Read allocation hints and Write allocation hints and not transient.
"""
Agree that the above should be the right place to cite. C3.2.6 seems to discuss atomic instruction with memory attributes bits(which points to MAIR_EL1 and MAIR_EL2?). In this case, it is more related to shareability bits instead.
Quoted 19 lines
and
"""
If the atomic insturctions are not atomic in regard to other agents that access memory, then performing an atomic instruction to such a location can have one or more of the following effects:[...]
- The instruction generates an IMPLEMENTATION DEFINED fault reported using the Data Abort Fault status code of ESR_ELx.DFSC = 110101
"""The memory type used by KVM selftests is *Non-Shareable*, which is not one of the memory types guaranteed by the architecture to work.
Thanks,
Oliver
Marc Zyngier
maintainerRe: [PATCH v2 2/2] KVM: selftests: arm64: Explicitly set the page attrs to Inner-Shareable
Quoted 77 lines · Mingwei Zhang
Quoted 66 lines · Oliver Upton
Quoted 15 lines · Mingwei Zhang
Quoted 13 lines · Raghavendra Rao Ananta
Atomic instructions such as 'ldset' over (global) variables in the guest is observed to cause an EL1 data abort with FSC
0x35(IMPLEMENTATION DEFINED fault (Unsupported Exclusive or Atomic access)). The observation was particularly apparent on Neoverse-N3.According to ARM ARM DDI0487L.a B2.2.6 (Possible implementation restrictions on using atomic instructions), atomic instructions are architecturally guaranteed for Inner Shareable and Outer Shareable attributes. For Non-Shareable attribute, the atomic instructions are not atomic and issuing such an instruction can lead to the FSC mentioned in this case (among other things).
Quoted 6 lines
Quoted 6 lines
Moreover, according to DDI0487L.a C3.2.6 (Single-copy atomic 64-byte load/store), it is implementation defined that a data abort with the mentioned FSC is reported for the first stage of translation that provides an inappropriate memory type. It's likely that Neoverse-N3 chose to implement these two and why we see an FSC of
0x35in EL1 upon executing atomic instructions.Ok, can we please drop this second reference?
This is talking about something else (
FEAT_LS64) that happens to share the same FSC as an unsupported atomic instruction. I mentioned this to you internally as an illustration of how different implementations may behave when determining if the attributes support a particular access, but it isn't actually relevant to this change.Quoted 3 lines
nit: It's likely that Neoverse-N3 chose to implement this option (the first option) instead of reporting at the final enabled stage of translation
I would much rather we rely on the language that describes what the architecture guarantees rather than speculate as to how Neoverse-N3 behaves.
Mentioning that the breakage was observed on Neoverse-N3 is still useful to add to the changelog.
Quoted 8 lines
I have minor question here: The DDI0487L C3.2.6 (Single-copy atomic 64-byte load/store) mentioned
"""
When the instructions access a memory type that is not one of the following, a data abort for unsupported Exclusive or atomic access is generated:Quoted 7 lines
• Normal Inner Non-cacheable, Outer Non-cacheable. """
So, the above is the "Normal Inner Non-cacheable", but in our case we have "Normal and non-shareable" in stage-1 mapping, right? I know it is very close, but it seems the situation is still only "one bit" away in my understanding...
This citation relates to
FEAT_LS64. If you look at B2.2.6 instead, it reads:"""
The memory types for which it is architecturally guaranteed that the atomic instructions will be atomic are:Quoted 8 lines
- Inner Shareable, Inner Write-Back, Outer Write-Back Normal memory with Read allocation hints and Write allocation hints and not transient.
- Outer Shareable, Inner Write-Back, Outer Write-Back Normal memory with Read allocation hints and Write allocation hints and not transient.
"""
Quoted 4 lines
Agree that the above should be the right place to cite. C3.2.6 seems to discuss atomic instruction with memory attributes
bits(which points to MAIR_EL1 and MAIR_EL2?). In this case, it is more related to shareability bits instead.
Not sure what you mean by this reference to MAIR.
These constraints apply to any memory access, including those that are *not* the direct effect of an instruction. For example, an atomic page table update generated by the HW (AF or DB update) is only guaranteed to succeed if the PTW is itself configured to use ISH+WB or OSH+WB, and could otherwise result in any of the ill effects described in B2.2.6.
M.
Signature · 1 line
Jazz isn't dead. It just smells funny.
Oliver Upton
AppliedQuoted 11 lines · Raghavendra Rao Ananta
The series fixes a conflict in memory attributes in some implementations,
such as Neoverse-N3, that causes a data abort in guest EL1 with FSC0x35(IMPLEMENTATION DEFINED fault (Unsupported Exclusive or Atomic access)).Patch-1 is a cleanup patch that replaces numbers (and comments) to using proper macros for hardware configuration, such as registers and page-table entries.
[...]
I cleaned up the changelog on patch 2 per the discussion + added a note about the interaction with LPA2.
Applied to fixes, thanks!
[1/2] KVM: selftests: arm64: Introduce and use hardware-definition macros
https://git.kernel.org/kvmarm/kvmarm/c/d8d78398e550 [2/2] KVM: selftests: arm64: Explicitly set the page attrs to Inner-Shareable https://git.kernel.org/kvmarm/kvmarm/c/c8631ea59b65
--
Best,
Oliver