target-arm: Apply S2 MMU startlevel table size check to AArch64

The S2 starting level table size check applies to both AArch32
and AArch64. Move it to common code.

Backports commit 98d68ec289750139258d9cd9ab3f6d7dd10bb762 from qemu
This commit is contained in:
Edgar E. Iglesias 2018-02-19 01:13:22 -05:00 committed by Lioncash
parent d3e5003e53
commit bab59f6b18
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7

View File

@ -6122,11 +6122,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);
@ -6150,20 +6158,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;
}