target/arm: Remove loop from get_phys_addr_lpae
The unconditional loop was used both to iterate over levels and to control parsing of attributes. Use an explicit goto in both cases. While this appears less clean for iterating over levels, we will need to jump back into the middle of this loop for atomic updates, which is even uglier. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20221024051851.3074715-8-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
f0a398a249
commit
fe4ddc151b
192
target/arm/ptw.c
192
target/arm/ptw.c
|
@ -1061,6 +1061,8 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw,
|
|||
uint64_t descaddrmask;
|
||||
bool aarch64 = arm_el_is_aa64(env, el);
|
||||
bool guarded = false;
|
||||
uint64_t descriptor;
|
||||
bool nstable;
|
||||
|
||||
/* TODO: This code does not support shareability levels. */
|
||||
if (aarch64) {
|
||||
|
@ -1253,106 +1255,104 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw,
|
|||
* bits at each step.
|
||||
*/
|
||||
tableattrs = is_secure ? 0 : (1 << 4);
|
||||
for (;;) {
|
||||
uint64_t descriptor;
|
||||
bool nstable;
|
||||
|
||||
descaddr |= (address >> (stride * (4 - level))) & indexmask;
|
||||
descaddr &= ~7ULL;
|
||||
nstable = extract32(tableattrs, 4, 1);
|
||||
if (!nstable) {
|
||||
/*
|
||||
* Stage2_S -> Stage2 or Phys_S -> Phys_NS
|
||||
* Assert that the non-secure idx are even, and relative order.
|
||||
*/
|
||||
QEMU_BUILD_BUG_ON((ARMMMUIdx_Phys_NS & 1) != 0);
|
||||
QEMU_BUILD_BUG_ON((ARMMMUIdx_Stage2 & 1) != 0);
|
||||
QEMU_BUILD_BUG_ON(ARMMMUIdx_Phys_NS + 1 != ARMMMUIdx_Phys_S);
|
||||
QEMU_BUILD_BUG_ON(ARMMMUIdx_Stage2 + 1 != ARMMMUIdx_Stage2_S);
|
||||
ptw->in_ptw_idx &= ~1;
|
||||
ptw->in_secure = false;
|
||||
}
|
||||
if (!S1_ptw_translate(env, ptw, descaddr, fi)) {
|
||||
goto do_fault;
|
||||
}
|
||||
descriptor = arm_ldq_ptw(env, ptw, fi);
|
||||
if (fi->type != ARMFault_None) {
|
||||
goto do_fault;
|
||||
}
|
||||
|
||||
if (!(descriptor & 1) ||
|
||||
(!(descriptor & 2) && (level == 3))) {
|
||||
/* Invalid, or the Reserved level 3 encoding */
|
||||
goto do_fault;
|
||||
}
|
||||
|
||||
descaddr = descriptor & descaddrmask;
|
||||
|
||||
next_level:
|
||||
descaddr |= (address >> (stride * (4 - level))) & indexmask;
|
||||
descaddr &= ~7ULL;
|
||||
nstable = extract32(tableattrs, 4, 1);
|
||||
if (!nstable) {
|
||||
/*
|
||||
* For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [15:12]
|
||||
* of descriptor. For FEAT_LPA2 and effective DS, bits [51:50] of
|
||||
* descaddr are in [9:8]. Otherwise, if descaddr is out of range,
|
||||
* raise AddressSizeFault.
|
||||
* Stage2_S -> Stage2 or Phys_S -> Phys_NS
|
||||
* Assert that the non-secure idx are even, and relative order.
|
||||
*/
|
||||
if (outputsize > 48) {
|
||||
if (param.ds) {
|
||||
descaddr |= extract64(descriptor, 8, 2) << 50;
|
||||
} else {
|
||||
descaddr |= extract64(descriptor, 12, 4) << 48;
|
||||
}
|
||||
} else if (descaddr >> outputsize) {
|
||||
fault_type = ARMFault_AddressSize;
|
||||
goto do_fault;
|
||||
}
|
||||
|
||||
if ((descriptor & 2) && (level < 3)) {
|
||||
/*
|
||||
* Table entry. The top five bits are attributes which may
|
||||
* propagate down through lower levels of the table (and
|
||||
* which are all arranged so that 0 means "no effect", so
|
||||
* we can gather them up by ORing in the bits at each level).
|
||||
*/
|
||||
tableattrs |= extract64(descriptor, 59, 5);
|
||||
level++;
|
||||
indexmask = indexmask_grainsize;
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* Block entry at level 1 or 2, or page entry at level 3.
|
||||
* These are basically the same thing, although the number
|
||||
* of bits we pull in from the vaddr varies. Note that although
|
||||
* descaddrmask masks enough of the low bits of the descriptor
|
||||
* to give a correct page or table address, the address field
|
||||
* in a block descriptor is smaller; so we need to explicitly
|
||||
* clear the lower bits here before ORing in the low vaddr bits.
|
||||
*/
|
||||
page_size = (1ULL << ((stride * (4 - level)) + 3));
|
||||
descaddr &= ~(hwaddr)(page_size - 1);
|
||||
descaddr |= (address & (page_size - 1));
|
||||
/* Extract attributes from the descriptor */
|
||||
attrs = extract64(descriptor, 2, 10)
|
||||
| (extract64(descriptor, 52, 12) << 10);
|
||||
|
||||
if (regime_is_stage2(mmu_idx)) {
|
||||
/* Stage 2 table descriptors do not include any attribute fields */
|
||||
break;
|
||||
}
|
||||
/* Merge in attributes from table descriptors */
|
||||
attrs |= nstable << 3; /* NS */
|
||||
guarded = extract64(descriptor, 50, 1); /* GP */
|
||||
if (param.hpd) {
|
||||
/* HPD disables all the table attributes except NSTable. */
|
||||
break;
|
||||
}
|
||||
attrs |= extract32(tableattrs, 0, 2) << 11; /* XN, PXN */
|
||||
/*
|
||||
* The sense of AP[1] vs APTable[0] is reversed, as APTable[0] == 1
|
||||
* means "force PL1 access only", which means forcing AP[1] to 0.
|
||||
*/
|
||||
attrs &= ~(extract32(tableattrs, 2, 1) << 4); /* !APT[0] => AP[1] */
|
||||
attrs |= extract32(tableattrs, 3, 1) << 5; /* APT[1] => AP[2] */
|
||||
break;
|
||||
QEMU_BUILD_BUG_ON((ARMMMUIdx_Phys_NS & 1) != 0);
|
||||
QEMU_BUILD_BUG_ON((ARMMMUIdx_Stage2 & 1) != 0);
|
||||
QEMU_BUILD_BUG_ON(ARMMMUIdx_Phys_NS + 1 != ARMMMUIdx_Phys_S);
|
||||
QEMU_BUILD_BUG_ON(ARMMMUIdx_Stage2 + 1 != ARMMMUIdx_Stage2_S);
|
||||
ptw->in_ptw_idx &= ~1;
|
||||
ptw->in_secure = false;
|
||||
}
|
||||
if (!S1_ptw_translate(env, ptw, descaddr, fi)) {
|
||||
goto do_fault;
|
||||
}
|
||||
descriptor = arm_ldq_ptw(env, ptw, fi);
|
||||
if (fi->type != ARMFault_None) {
|
||||
goto do_fault;
|
||||
}
|
||||
|
||||
if (!(descriptor & 1) || (!(descriptor & 2) && (level == 3))) {
|
||||
/* Invalid, or the Reserved level 3 encoding */
|
||||
goto do_fault;
|
||||
}
|
||||
|
||||
descaddr = descriptor & descaddrmask;
|
||||
|
||||
/*
|
||||
* For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [15:12]
|
||||
* of descriptor. For FEAT_LPA2 and effective DS, bits [51:50] of
|
||||
* descaddr are in [9:8]. Otherwise, if descaddr is out of range,
|
||||
* raise AddressSizeFault.
|
||||
*/
|
||||
if (outputsize > 48) {
|
||||
if (param.ds) {
|
||||
descaddr |= extract64(descriptor, 8, 2) << 50;
|
||||
} else {
|
||||
descaddr |= extract64(descriptor, 12, 4) << 48;
|
||||
}
|
||||
} else if (descaddr >> outputsize) {
|
||||
fault_type = ARMFault_AddressSize;
|
||||
goto do_fault;
|
||||
}
|
||||
|
||||
if ((descriptor & 2) && (level < 3)) {
|
||||
/*
|
||||
* Table entry. The top five bits are attributes which may
|
||||
* propagate down through lower levels of the table (and
|
||||
* which are all arranged so that 0 means "no effect", so
|
||||
* we can gather them up by ORing in the bits at each level).
|
||||
*/
|
||||
tableattrs |= extract64(descriptor, 59, 5);
|
||||
level++;
|
||||
indexmask = indexmask_grainsize;
|
||||
goto next_level;
|
||||
}
|
||||
|
||||
/*
|
||||
* Block entry at level 1 or 2, or page entry at level 3.
|
||||
* These are basically the same thing, although the number
|
||||
* of bits we pull in from the vaddr varies. Note that although
|
||||
* descaddrmask masks enough of the low bits of the descriptor
|
||||
* to give a correct page or table address, the address field
|
||||
* in a block descriptor is smaller; so we need to explicitly
|
||||
* clear the lower bits here before ORing in the low vaddr bits.
|
||||
*/
|
||||
page_size = (1ULL << ((stride * (4 - level)) + 3));
|
||||
descaddr &= ~(hwaddr)(page_size - 1);
|
||||
descaddr |= (address & (page_size - 1));
|
||||
/* Extract attributes from the descriptor */
|
||||
attrs = extract64(descriptor, 2, 10)
|
||||
| (extract64(descriptor, 52, 12) << 10);
|
||||
|
||||
if (regime_is_stage2(mmu_idx)) {
|
||||
/* Stage 2 table descriptors do not include any attribute fields */
|
||||
goto skip_attrs;
|
||||
}
|
||||
/* Merge in attributes from table descriptors */
|
||||
attrs |= nstable << 3; /* NS */
|
||||
guarded = extract64(descriptor, 50, 1); /* GP */
|
||||
if (param.hpd) {
|
||||
/* HPD disables all the table attributes except NSTable. */
|
||||
goto skip_attrs;
|
||||
}
|
||||
attrs |= extract32(tableattrs, 0, 2) << 11; /* XN, PXN */
|
||||
/*
|
||||
* The sense of AP[1] vs APTable[0] is reversed, as APTable[0] == 1
|
||||
* means "force PL1 access only", which means forcing AP[1] to 0.
|
||||
*/
|
||||
attrs &= ~(extract32(tableattrs, 2, 1) << 4); /* !APT[0] => AP[1] */
|
||||
attrs |= extract32(tableattrs, 3, 1) << 5; /* APT[1] => AP[2] */
|
||||
skip_attrs:
|
||||
|
||||
/*
|
||||
* Here descaddr is the final physical address, and attributes
|
||||
* are all in attrs.
|
||||
|
|
Loading…
Reference in New Issue