target-arm: Add a few more S2 MMU input checks
v2 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
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 | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 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
PATCH v2 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target-arm/helper.c +4 -4
@@ -6579,7 +6579,8 @@ typedef enum {* 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 +6596,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 +6807,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 +6820,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
Re: [PATCH v2 2/3] target-arm: Make pamax an argument to check_s2_startlevel
Quoted 17 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Make pamax an argument to
check_s2_startlevelin preparation for future reuse.No functional change.
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target-arm/helper.c +0
-0
target-arm/helper.c typedef enum { · line 6584
Quoted 7 lines
target-arm/helper.c +2
-1@@ -6579,7 +6579,8 @@ typedef enum {* 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) {
If you fix the docstring above you can have my:
Quoted 20 lines
target-arm/helper.c +1
-2const int grainsize = stride +3 ;int startsizecheck;@@ -6595,8 +6596,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 +6807,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 ) {
target-arm/helper.c static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, · line 6826
Quoted 8 lines
target-arm/helper.c +1
-1@@ -6820,7 +6820,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.
--
Alex Bennée
Re: [PATCH v2 2/3] target-arm: Make pamax an argument to check_s2_startlevel
Quoted 30 lines · Alex Bennée
Quoted 17 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Make pamax an argument to
check_s2_startlevelin preparation for future reuse.No functional change.
Signed-off-by Edgar E. Iglesias <[email protected]>--- target-arm/helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target-arm/helper.c +0
-0target-arm/helper.c typedef enum { · line 6584
Quoted 7 lines
target-arm/helper.c +2
-1@@ -6579,7 +6579,8 @@ typedef enum {* 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) {If you fix the docstring above you can have my:
Quoted 1 line
Reviewed-by Alex Bennée <[email protected]>
I've fixed the comment for v3.
Thanks,
Edgar
Quoted 34 lines
Quoted 22 lines
target-arm/helper.c +1
-2const int grainsize = stride +3 ;int startsizecheck;@@ -6595,8 +6596,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 +6807,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 ) {target-arm/helper.c static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, · line 6826
Quoted 8 lines
target-arm/helper.c +1
-1@@ -6820,7 +6820,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. --
Alex Bennée
PATCH v2 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
@@ -6808,7 +6808,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 */
@@ -6818,9 +6818,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 v2 3/3] target-arm: Implement the S2 MMU inputsize > pamax check
Quoted 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@@ -6808,7 +6808,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 6823
Quoted 9 lines
target-arm/helper.c +3
-3@@ -6818,9 +6818,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 )) {
If va_size == 64 doesn't that imply arm_el_is_aa64(env, 1)? Looking further up the function it seems that is what sets va_size in the first place. I think that makes the inputsize > 40 check redundant.
target-arm/helper.c static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, · line 6834
Quoted 11 lines
target-arm/helper.c +8
-0+/* 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.
I'm not a fan of the ok = true / ok = false / ok = check_s2_start_level() / if (!ok) ping-pong here as it is hard to follow. I'm not sure how you could make it cleaner to follow though. Maybe something like:
/* For stage 2 translations the starting level is specified by the
* 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 is_aarch64_regime = (va_size == 64);
bool ok;
if (va_size == 32 || stride == 9) {
/* AArch32 or 4KB pages */
level = 2 - startlevel;
} else {
/* 16KB or 64KB pages */
level = 3 - startlevel;
}
if (is_aarch64_regime &&
inputsize > pamax) {
/* We have multiple choices but choose to fault. */
ok = false;
} else {
/* Check that the starting level is valid. */
ok = check_s2_startlevel(cpu, is_aarch64_regime, level,
inputsize, stride, pamax);
}
if (!ok) {
/* AArch64 reports these as level 0 faults.
* AArch32 reports these as level 1 faults.
*/
level = is_aarch64_regime ? 0 : 1;
fault_type = translation_fault;
goto do_fault;
}But I'm wondering if it just makes more sense to push the:
is_aarch64_regime && inputsize > pamax
Check into check_s2_startlevel? Then you could just have a simple call which succeeds or falls through to a fault?
/* Check that the starting level is valid. */
if (!check_s2_startlevel(cpu, is_aarch64_regime, level,
inputsize, stride, pamax) ){
/* AArch64 reports these as level 0 faults.
* AArch32 reports these as level 1 faults.
*/
level = is_aarch64_regime ? 0 : 1;
fault_type = translation_fault;
goto do_fault;
}--
Alex Bennée
Re: [PATCH v2 3/3] target-arm: Implement the S2 MMU inputsize > pamax check
Quoted 31 lines · Alex Bennée
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@@ -6808,7 +6808,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 */ @@ -6818,9 +6818,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 6823
Quoted 6 lines
target-arm/helper.c +3
-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 )) {If
va_size== 64 doesn't that implyarm_el_is_aa64(env, 1)? Looking further up the function it seems that is what setsva_sizein the first place. I think that makes the inputsize > 40 check redundant.
va_size == 64 is true if the EL corresponding to the translation _regime_ is in 64 bit mode (in this case EL2).
EL1 may very well be in 32bit mode.
Quoted 52 lines
target-arm/helper.c static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, · line 6834
Quoted 12 lines
target-arm/helper.c +8
-0+/* 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. I'm not a fan of the ok = true / ok = false / ok =
check_s2_start_level()/ if (!ok) ping-pong here as it is hard to follow. I'm not sure how you could make it cleaner to follow though. Maybe something like:/* For stage 2 translations the starting level is specified by the * 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 is_aarch64_regime = (va_size == 64); bool ok; if (va_size == 32 || stride == 9) { /* AArch32 or 4KB pages */ level = 2 - startlevel; } else { /* 16KB or 64KB pages */ level = 3 - startlevel; } if (is_aarch64_regime && inputsize > pamax) { /* We have multiple choices but choose to fault. */ ok = false; } else { /* Check that the starting level is valid. */ ok = check_s2_startlevel(cpu, is_aarch64_regime, level, inputsize, stride, pamax); } if (!ok) { /* AArch64 reports these as level 0 faults. * AArch32 reports these as level 1 faults. */ level = is_aarch64_regime ? 0 : 1; fault_type = translation_fault; goto do_fault; }
Quoted 6 lines
But I'm wondering if it just makes more sense to push the:
is_aarch64_regime && inputsize > pamaxCheck into
check_s2_startlevel? Then you could just have a simple call which succeeds or falls through to a fault?
Yeah, I guess we could rename check_s2_startlevel to something more generic and move all the checks there. I don't feel very strongly about either way...
Thanks,
Edgar
Quoted 14 lines
/* Check that the starting level is valid. */ if (!check_s2_startlevel(cpu, is_aarch64_regime, level, inputsize, stride, pamax) ){ /* AArch64 reports these as level 0 faults. * AArch32 reports these as level 1 faults. */ level = is_aarch64_regime ? 0 : 1; fault_type = translation_fault; goto do_fault; }--
Alex Bennée
Re: [PATCH v2 3/3] target-arm: Implement the S2 MMU inputsize > pamax check
Quoted 43 lines · Edgar E. Iglesias
Quoted 31 lines · Alex Bennée
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@@ -6808,7 +6808,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 */ @@ -6818,9 +6818,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 6823
Quoted 6 lines
target-arm/helper.c +3
-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 )) {If
va_size== 64 doesn't that implyarm_el_is_aa64(env, 1)? Looking further up the function it seems that is what setsva_sizein the first place. I think that makes the inputsize > 40 check redundant.
Quoted 4 lines
va_size== 64 is true if the EL corresponding to the translation _regime_ is in 64 bit mode (in this case EL2).EL1 may very well be in 32bit mode.
Ahh yes, I missed that on the first reading. I think it might be clearer when reading the code to have the:
bool is_aarch64_regime = (va_size == 64);
And use that to make it clear. And then comment on later check that it's incompatible with EL1 being aarch32.
Quoted 55 lines
Quoted 55 lines
target-arm/helper.c static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, · line 6834
Quoted 13 lines
target-arm/helper.c +8
-0+/* 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. I'm not a fan of the ok = true / ok = false / ok =
check_s2_start_level()/ if (!ok) ping-pong here as it is hard to follow. I'm not sure how you could make it cleaner to follow though. Maybe something like:/* For stage 2 translations the starting level is specified by the * 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 is_aarch64_regime = (va_size == 64); bool ok; if (va_size == 32 || stride == 9) { /* AArch32 or 4KB pages */ level = 2 - startlevel; } else { /* 16KB or 64KB pages */ level = 3 - startlevel; } if (is_aarch64_regime && inputsize > pamax) { /* We have multiple choices but choose to fault. */ ok = false; } else { /* Check that the starting level is valid. */ ok = check_s2_startlevel(cpu, is_aarch64_regime, level, inputsize, stride, pamax); } if (!ok) { /* AArch64 reports these as level 0 faults. * AArch32 reports these as level 1 faults. */ level = is_aarch64_regime ? 0 : 1; fault_type = translation_fault; goto do_fault; }But I'm wondering if it just makes more sense to push the:
Quoted 7 lines
Quoted 4 lines
is_aarch64_regime && inputsize > pamaxCheck into
check_s2_startlevel? Then you could just have a simple call which succeeds or falls through to a fault?Yeah, I guess we could rename
check_s2_startlevelto something more generic and move all the checks there. I don't feel very strongly about either way...
I think it would be cleaner to follow. get_phys_addr_lpae is already a bit of a monster so the less conditions to keep track of while reading it the better IMHO.
Quoted 19 lines
Thanks,
EdgarQuoted 14 lines
/* Check that the starting level is valid. */ if (!check_s2_startlevel(cpu, is_aarch64_regime, level, inputsize, stride, pamax) ){ /* AArch64 reports these as level 0 faults. * AArch32 reports these as level 1 faults. */ level = is_aarch64_regime ? 0 : 1; fault_type = translation_fault; goto do_fault; }--
Alex Bennée
--
Alex Bennée
Re: [PATCH v2 3/3] target-arm: Implement the S2 MMU inputsize > pamax check
Quoted 119 lines · Alex Bennée
Quoted 43 lines · Edgar E. Iglesias
Quoted 31 lines · Alex Bennée
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@@ -6808,7 +6808,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 */ @@ -6818,9 +6818,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 6823
Quoted 6 lines
target-arm/helper.c +3
-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 )) {If
va_size== 64 doesn't that implyarm_el_is_aa64(env, 1)? Looking further up the function it seems that is what setsva_sizein the first place. I think that makes the inputsize > 40 check redundant.Quoted 4 lines
va_size== 64 is true if the EL corresponding to the translation _regime_ is in 64 bit mode (in this case EL2).EL1 may very well be in 32bit mode.
Ahh yes, I missed that on the first reading. I think it might be clearer when reading the code to have the:
bool is_aarch64_regime = (va_size == 64);And use that to make it clear. And then comment on later check that it's incompatible with EL1 being aarch32.
Quoted 60 lines
Quoted 59 lines
target-arm/helper.c static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, · line 6834
Quoted 13 lines
target-arm/helper.c +8
-0+/* 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. I'm not a fan of the ok = true / ok = false / ok =
check_s2_start_level()/ if (!ok) ping-pong here as it is hard to follow. I'm not sure how you could make it cleaner to follow though. Maybe something like:/* For stage 2 translations the starting level is specified by the * 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 is_aarch64_regime = (va_size == 64); bool ok; if (va_size == 32 || stride == 9) { /* AArch32 or 4KB pages */ level = 2 - startlevel; } else { /* 16KB or 64KB pages */ level = 3 - startlevel; } if (is_aarch64_regime && inputsize > pamax) { /* We have multiple choices but choose to fault. */ ok = false; } else { /* Check that the starting level is valid. */ ok = check_s2_startlevel(cpu, is_aarch64_regime, level, inputsize, stride, pamax); } if (!ok) { /* AArch64 reports these as level 0 faults. * AArch32 reports these as level 1 faults. */ level = is_aarch64_regime ? 0 : 1; fault_type = translation_fault; goto do_fault; }But I'm wondering if it just makes more sense to push the:
is_aarch64_regime && inputsize > pamaxCheck into
check_s2_startlevel? Then you could just have a simple call which succeeds or falls through to a fault?
Quoted 6 lines
Quoted 2 lines
Yeah, I guess we could rename
check_s2_startlevelto something more generic and move all the checks there. I don't feel very strongly about either way...I think it would be cleaner to follow.
get_phys_addr_lpaeis already a bit of a monster so the less conditions to keep track of while reading it the better IMHO.
OK, I'll have a look at that for v4.
Thanks!
Edgar
Quoted 24 lines
Quoted 20 lines
Thanks,
EdgarQuoted 14 lines
/* Check that the starting level is valid. */ if (!check_s2_startlevel(cpu, is_aarch64_regime, level, inputsize, stride, pamax) ){ /* AArch64 reports these as level 0 faults. * AArch32 reports these as level 1 faults. */ level = is_aarch64_regime ? 0 : 1; fault_type = translation_fault; goto do_fault; }--
Alex Bennée--
Alex Bennée