Bug fixes related to secure 2 stage translation
cover Bug fixes related to secure 2 stage translation
Idan Horowitz (3):
target/arm: Check VSTCR.SW when assigning the stage 2 output PA space target/arm: Take VSTCR.SW, VTCR.NSW into account in final stage 2 walk target/arm: Determine final stage 2 output PA space based on original
IPA
target/arm/helper.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/3 target/arm: Check VSTCR.SW when assigning the stage 2 output PA space
As per the AArch64.SS2OutputPASpace() psuedo-code in the ARMv8 ARM when the PA space of the IPA is non secure, the output PA space is secure if and only if all of the bits VTCR.<NSW, NSA>, VSTCR.<SW, SA> are not set.
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -12697,7 +12697,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, }else { attrs->secure = !((env->cp15.vtcr_el2.raw_tcr & (VTCR_NSA |VTCR_NSW )) - || (env->cp15.vstcr_el2.raw_tcr &VSTCR_SA )); + || (env->cp15.vstcr_el2.raw_tcr & (VSTCR_SA |VSTCR_SW ))); } }return 0 ;
Signature · 1 line
2.35.1
Re: [PATCH 1/3] target/arm: Check VSTCR.SW when assigning the stage 2 output PA space
Quoted 17 lines · Le sunnuntaina 27. maaliskuuta 2022, 12.34.26 EEST Idan Horowitz a écrit :
As per the
AArch64.SS2OutputPASpace()psuedo-code in the ARMv8 ARM when the PA space of the IPA is non secure, the output PA space is secure if and only if all of the bits VTCR.<NSW, NSA>, VSTCR.<SW, SA> are not set.Signed-off-by Idan Horowitz <[email protected]>--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/helper.c +0
-0@@ -12697,7 +12697,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, } else { attrs->secure = !((env->cp15.vtcr_el2.raw_tcr & (VTCR_NSA |
Quoted 3 lines
VTCR_NSW)) - || (env->cp15.vstcr_el2.raw_tcr&VSTCR_SA)); + || (env->cp15.vstcr_el2.raw_tcr&
(VSTCR_SA|VSTCR_SW))); }
The VTCR_EL2 specification says that the NSA bit "behaves as 1 for all purposes other than reading back the value of the bit when one of the following is true (...)
* The value of VTCR_EL2.NSW is 1.
* The value of VSTCR_EL2.SA is 1."
Sorry but I don't see any reason to check the SW bit here.
Signature · 2 lines
Реми Дёни-Курмон http://www.remlab.net/
Re: [PATCH 1/3] target/arm: Check VSTCR.SW when assigning the stage 2 output PA space
Quoted 28 lines · Rémi Denis-Courmont
Quoted 17 lines · Le sunnuntaina 27. maaliskuuta 2022, 12.34.26 EEST Idan Horowitz a écrit :
As per the
AArch64.SS2OutputPASpace()psuedo-code in the ARMv8 ARM when the PA space of the IPA is non secure, the output PA space is secure if and only if all of the bits VTCR.<NSW, NSA>, VSTCR.<SW, SA> are not set.Signed-off-by Idan Horowitz <[email protected]>--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/arm/helper.c +0
-0@@ -12697,7 +12697,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, } else { attrs->secure = !((env->cp15.vtcr_el2.raw_tcr & (VTCR_NSA |Quoted 3 lines
VTCR_NSW)) - || (env->cp15.vstcr_el2.raw_tcr&VSTCR_SA)); + || (env->cp15.vstcr_el2.raw_tcr&
(VSTCR_SA|VSTCR_SW))); }The
VTCR_EL2specification says that the NSA bit "behaves as 1 for all purposes other than reading back the value of the bit when one of the following is true (...)
* The value of VTCR_EL2.NSW is 1.
* The value of VSTCR_EL2.SA is 1."
Quoted 1 line
Sorry but I don't see any reason to check the SW bit here.
Because the description of SA says that it behaves as 1 if SW is 1.
r~
Re: [PATCH 1/3] target/arm: Check VSTCR.SW when assigning the stage 2 output PA space
In reply to Idan HorowitzQuoted 8 lines · Idan Horowitz
As per the
AArch64.SS2OutputPASpace()psuedo-code in the ARMv8 ARM when the PA space of the IPA is non secure, the output PA space is secure if and only if all of the bits VTCR.<NSW, NSA>, VSTCR.<SW, SA> are not set.Signed-off-by Idan Horowitz<[email protected]>--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
PATCH 2/3 target/arm: Take VSTCR.SW, VTCR.NSW into account in final stage 2 walk
In reply to Idan HorowitzAs per the AArch64.SS2InitialTTWState() psuedo-code in the ARMv8 ARM the initial PA space used for stage 2 table walks is assigned based on the SW and NSW bits of the VSTCR and VTCR registers.
This was already implemented for the recursive stage 2 page table walks in S1_ptw_translate(), but was missing for the final stage 2 walk.
--- target/arm/helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
target/arm/helper.c +10 -0
@@ -12657,6 +12657,16 @@ bool get_phys_addr(CPUARMState *env, target_ulong address,return ret; } +if (arm_is_secure_below_el3 (env)) { +if (attrs->secure) { + attrs->secure = !(env->cp15.vstcr_el2.raw_tcr &VSTCR_SW ); + }else { + attrs->secure = !(env->cp15.vtcr_el2.raw_tcr &VTCR_NSW ); + } + }else { +assert (!attrs->secure); + } + s2_mmu_idx = attrs->secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; is_el0 = mmu_idx == ARMMMUIdx_E10_0 || mmu_idx == ARMMMUIdx_SE10_0;
Signature · 1 line
2.35.1
Re: [PATCH 2/3] target/arm: Take VSTCR.SW, VTCR.NSW into account in final stage 2 walk
Quoted 10 lines · Idan Horowitz
As per the
AArch64.SS2InitialTTWState()psuedo-code in the ARMv8 ARM the initial PA space used for stage 2 table walks is assigned based on the SW and NSW bits of the VSTCR and VTCR registers.
This was already implemented for the recursive stage 2 page table walks inS1_ptw_translate(), but was missing for the final stage 2 walk.Signed-off-by Idan Horowitz<[email protected]>--- target/arm/helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
r~
PATCH 3/3 target/arm: Determine final stage 2 output PA space based on original IPA
In reply to Idan HorowitzAs per the AArch64.S2Walk() psuedo-code in the ARMv8 ARM, the final decision as to the output address's PA space based on the SA/SW/NSA/NSA bits needs to take the input IPA's PA space into account, and not the PA space of the result of the stage 2 walk itself.
--- target/arm/helper.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
target/arm/helper.c +5 -3
@@ -12644,6 +12644,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address,hwaddr ipa;int s2_prot;int ret; +bool ipa_secure;ARMCacheAttrs cacheattrs2 = {};ARMMMUIdx s2_mmu_idx;bool is_el0;
@@ -12657,14 +12658,15 @@ bool get_phys_addr(CPUARMState *env, target_ulong address,return ret; } + ipa_secure = attrs->secure;if (arm_is_secure_below_el3 (env)) { -if (attrs->secure) { +if (ipa_secure) { attrs->secure = !(env->cp15.vstcr_el2.raw_tcr &VSTCR_SW ); }else { attrs->secure = !(env->cp15.vtcr_el2.raw_tcr &VTCR_NSW ); } }else { -assert (!attrs->secure); +assert (!ipa_secure); } s2_mmu_idx = attrs->secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2;
@@ -12701,7 +12703,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address,/* Check if IPA translates to secure or non-secure PA space. */ if (arm_is_secure_below_el3 (env)) { -if (attrs->secure) { +if (ipa_secure) { attrs->secure = !(env->cp15.vstcr_el2.raw_tcr & (VSTCR_SA |VSTCR_SW )); }else {
Signature · 1 line
2.35.1
Re: [PATCH 3/3] target/arm: Determine final stage 2 output PA space based on original IPA
Quoted 6 lines · Idan Horowitz
As per the
AArch64.S2Walk()psuedo-code in the ARMv8 ARM, the final decision as to the output address's PA space based on the SA/SW/NSA/NSA bits needs to take the input IPA's PA space into account, and not the PA space of the result of the stage 2 walk itself.Signed-off-by Idan Horowitz <[email protected]>
I believe I follow: because the walk uses walkstate.address.paddress.paspace, the ipa input parameter is unchanged, and it is ipa that is passed to AArch64.S2NextWalkStateLast() to form the output address.
r~
Re: [PATCH 3/3] target/arm: Determine final stage 2 output PA space based on original IPA
Quoted 5 lines · Richard Henderson
I believe I follow: because the walk uses walkstate.address.paddress.paspace, the ipa input parameter is unchanged, and it is ipa that is passed to
AArch64.S2NextWalkStateLast()to form the output address.
Indeed, I initially found the issue when a test case passed on arm IP but raised a data abort in QEMU.
Since fixing this issue solved the inconsistency, I believe this is the intended behaviour and not a spec bug.
Quoted 2 lines
r~
Idan Horowitz
Re: [PATCH 3/3] target/arm: Determine final stage 2 output PA space based on original IPA
In reply to Richard HendersonQuoted 7 lines · Richard Henderson
Quoted 5 lines · Idan Horowitz
As per the
AArch64.S2Walk()psuedo-code in the ARMv8 ARM, the final decision as to the output address's PA space based on the SA/SW/NSA/NSA bits needs to take the input IPA's PA space into account, and not the PA space of the result of the stage 2 walk itself.
Quoted 5 lines
Quoted 1 line
Signed-off-by Idan Horowitz <[email protected]>I believe I follow: because the walk uses walkstate.address.paddress.paspace, the ipa input parameter is unchanged, and it is ipa that is passed to
AArch64.S2NextWalkStateLast()to form the output address.
Textually, this is described on page D5-4802 of DDI 0487H.a; the security of the output address of the memory access isn't affected by the security of the output address of the translation table walk.
-- PMM
Peter Maydell
AppliedQuoted 8 lines · Idan Horowitz
Idan Horowitz (3):
target/arm: Check VSTCR.SW when assigning the stage 2 output PA space target/arm: Take VSTCR.SW, VTCR.NSW into account in final stage 2 walk target/arm: Determine final stage 2 output PA space based on original
IPA
Applied to target-arm.next, thanks. (I fixed a couple of typos in the patch 3 commit message.)
-- PMM