target-arm: Add a few more S2 MMU input checks
v3 cover target-arm: Add a few more S2 MMU input checks
From: "Edgar E. Iglesias" <[email protected]>
This adds the inputsize > pamax check and also fixes the startlevel checks to apply to the 64bit translations.
Comments welcome!
Cheers,
Edgar
ChangeLog:
v2 -> v3:
* Document pamax arg to check_s2_startlevel
v1 -> v2:
* inputsize > pmax check only applies to AArch64
* Fix commit message typo < should be >
Edgar E. Iglesias (3):
target-arm: Apply S2 MMU startlevel table size check to AArch64
target-arm: Make pamax an argument to check_s2_startlevel
target-arm: Implement the S2 MMU inputsize > pamax check
target-arm/helper.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/3 target-arm: Apply S2 MMU startlevel table size check to AArch64
From: "Edgar E. Iglesias" <[email protected]>
The S2 starting level table size check applies to both AArch32 and AArch64. Move it to common code.
--- target-arm/helper.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
target-arm/helper.c +8 -8
@@ -6581,11 +6581,19 @@ typedef enum {static bool check_s2_startlevel (ARMCPU *cpu,bool is_aa64,int level,int inputsize,int stride) { +const int grainsize = stride +3 ; +int startsizecheck; +/* Negative levels are never allowed. */ if (level <0 ) {return false; } + startsizecheck = inputsize - ((3 - level) * stride + grainsize); +if (startsizecheck <1 || startsizecheck > stride +4 ) { +return false; + } +if (is_aa64) {unsigned int pamax =arm_pamax (cpu);
@@ -6609,20 +6617,12 @@ static bool check_s2_startlevel(ARMCPU *cpu, bool is_aa64, int level,g_assert_not_reached (); } }else { -const int grainsize = stride +3 ; -int startsizecheck; -/* AArch32 only supports 4KB pages. Assert on that. */ assert (stride ==9 );if (level ==0 ) {return false; } - - startsizecheck = inputsize - ((3 - level) * stride + grainsize); -if (startsizecheck <1 || startsizecheck > stride +4 ) { -return false; - } }return true; }
Signature · 1 line
1.9.1
Re: [PATCH v3 1/3] target-arm: Apply S2 MMU startlevel table size check to AArch64
Quoted 7 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
The S2 starting level table size check applies to both AArch32 and AArch64. Move it to common code.
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Edgar E. Iglesias <[email protected]>
thanks
-- PMM
PATCH v3 2/3 target-arm: Make pamax an argument to check_s2_startlevel
In reply to Edgar E. IglesiasFrom: "Edgar E. Iglesias" <[email protected]>
Make pamax an argument to check_s2_startlevel in preparation for future reuse.
No functional change.
--- target-arm/helper.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
target-arm/helper.c +5 -4
@@ -6575,11 +6575,13 @@ typedef enum {* @startlevel: Suggested starting level * @inputsize: Bitsize of IPAs * @stride: Page-table stride (See the ARM ARM) +* @pamax: Implementation defined bit-width of physical addresses * * Returns true if the suggested starting level is OK and false otherwise. */ static bool check_s2_startlevel (ARMCPU *cpu,bool is_aa64,int level, -int inputsize,int stride) +int inputsize,int stride, +unsigned int pamax) {const int grainsize = stride +3 ;int startsizecheck;
@@ -6595,8 +6597,6 @@ static bool check_s2_startlevel(ARMCPU *cpu, bool is_aa64, int level, }if (is_aa64) { -unsigned int pamax =arm_pamax (cpu); -switch (stride) {case 13 :/* 64KB Pages. */ if (level ==0 || (level ==1 && pamax <=42 )) {
@@ -6808,6 +6808,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,* VTCR_EL2.SL0 field (whose interpretation depends on the page size) */ int startlevel =extract32 (tcr->raw_tcr,6 ,2 ); +unsigned int pamax =arm_pamax (cpu);bool ok;if (va_size ==32 || stride ==9 ) {
@@ -6820,7 +6821,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,/* Check that the starting level is valid. */ ok =check_s2_startlevel (cpu, va_size ==64 , level, - inputsize, stride); + inputsize, stride, pamax);if (!ok) {/* AArch64 reports these as level 0 faults. * AArch32 reports these as level 1 faults.
Signature · 1 line
1.9.1
PATCH v3 3/3 target-arm: Implement the S2 MMU inputsize > pamax check
In reply to Edgar E. IglesiasFrom: "Edgar E. Iglesias" <[email protected]>
Implement the inputsize > pamax check for Stage 2 translations. We have multiple choices for how to respond to errors and choose to fault.
--- target-arm/helper.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
target-arm/helper.c +12 -4
@@ -6809,7 +6809,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,*/ int startlevel =extract32 (tcr->raw_tcr,6 ,2 );unsigned int pamax =arm_pamax (cpu); -bool ok; +bool ok = true;if (va_size ==32 || stride ==9 ) {/* AArch32 or 4KB pages */
@@ -6819,9 +6819,17 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, level =3 - startlevel; } -/* Check that the starting level is valid. */ - ok =check_s2_startlevel (cpu, va_size ==64 , level, - inputsize, stride, pamax); +if (va_size ==64 && + inputsize > pamax && + (arm_el_is_aa64 (env,1 ) || inputsize >40 )) { +/* We have multiple choices but choose to fault. */ + ok = false; + } +if (ok) { +/* Check that the starting level is valid. */ + ok =check_s2_startlevel (cpu, va_size ==64 , level, + inputsize, stride, pamax); + }if (!ok) {/* AArch64 reports these as level 0 faults. * AArch32 reports these as level 1 faults.
Signature · 1 line
1.9.1
Re: [PATCH v3 3/3] target-arm: Implement the S2 MMU inputsize > pamax check
Quoted 7 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Implement the inputsize > pamax check for Stage 2 translations. We have multiple choices for how to respond to errors and choose to fault.
Signed-off-by Edgar E. Iglesias <[email protected]>
<snip>
Too fast ;-)
I'm awaiting v4.
--
Alex Bennée
Re: [PATCH v3 3/3] target-arm: Implement the S2 MMU inputsize > pamax check
In reply to Edgar E. IglesiasQuoted 25 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Implement the inputsize > pamax check for Stage 2 translations. We have multiple choices for how to respond to errors and choose to fault.
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/helper.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)target-arm/helper.c +1
-1@@ -6809,7 +6809,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,*/ int startlevel =extract32 (tcr->raw_tcr,6 ,2 );unsigned int pamax =arm_pamax (cpu); -bool ok; +bool ok = true;if (va_size ==32 || stride ==9 ) {/* AArch32 or 4KB pages */
target-arm/helper.c static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, · line 6825
Quoted 10 lines
target-arm/helper.c +4
-3@@ -6819,9 +6819,17 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, level =3 - startlevel; } -/* Check that the starting level is valid. */ - ok =check_s2_startlevel (cpu, va_size ==64 , level, - inputsize, stride, pamax); +if (va_size ==64 && + inputsize > pamax && + (arm_el_is_aa64 (env,1 ) || inputsize >40 )) { +/* We have multiple choices but choose to fault. */
Can we say specifically "This is CONSTRAINED UNPREDICTABLE and we choose...", please?
thanks
-- PMM
Re: [PATCH v3 3/3] target-arm: Implement the S2 MMU inputsize > pamax check
Quoted 29 lines · Peter Maydell
Quoted 28 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Implement the inputsize > pamax check for Stage 2 translations. We have multiple choices for how to respond to errors and choose to fault.
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/helper.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)target-arm/helper.c +1
-1@@ -6809,7 +6809,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,*/ int startlevel =extract32 (tcr->raw_tcr,6 ,2 );unsigned int pamax =arm_pamax (cpu); -bool ok; +bool ok = true;if (va_size ==32 || stride ==9 ) {/* AArch32 or 4KB pages */ @@ -6819,9 +6819,17 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, level =3 - startlevel; }
Quoted 10 lines
target-arm/helper.c static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, · line 6825
Quoted 7 lines
target-arm/helper.c +4
-3-/* Check that the starting level is valid. */ - ok =check_s2_startlevel (cpu, va_size ==64 , level, - inputsize, stride, pamax); +if (va_size ==64 && + inputsize > pamax && + (arm_el_is_aa64 (env,1 ) || inputsize >40 )) { +/* We have multiple choices but choose to fault. */ Can we say specifically "This is CONSTRAINED UNPREDICTABLE and we choose...", please?
I'll change this for v4.
Thanks!
Edgar