target/arm: Use signed quantity to represent VMSAv8-64 translation level
PATCH 1/1 target/arm: Use signed quantity to represent VMSAv8-64 translation level
The LPA2 extension implements 52-bit virtual addressing for 4k and 16k translation granules, and for the former, this means an additional level of translation is needed. This means we start counting at -1 instead of 0 when doing a walk, and so 'level' is now a signed quantity, and should be typed as such. So turn it from uint32_t into int32_t.
--- target/arm/ptw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/ptw.c +1 -1
@@ -1172,7 +1172,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw,ARMCPU *cpu =env_archcpu (env);ARMMMUIdx mmu_idx = ptw->in_mmu_idx;bool is_secure = ptw->in_secure; -uint32_t level; +int32_t level;ARMVAParameters param;uint64_t ttbr;hwaddr descaddr, indexmask, indexmask_grainsize;
Signature · 1 line
2.35.1
Quoted 7 lines · Ard Biesheuvel
The LPA2 extension implements 52-bit virtual addressing for 4k and 16k translation granules, and for the former, this means an additional level of translation is needed. This means we start counting at -1 instead of 0 when doing a walk, and so 'level' is now a signed quantity, and should be typed as such. So turn it from
uint32_tintoint32_t.
Does this cause any visible wrong behaviour, or is it just a cleanup thing ?
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 7 lines · Ard Biesheuvel
The LPA2 extension implements 52-bit virtual addressing for 4k and 16k translation granules, and for the former, this means an additional level of translation is needed. This means we start counting at -1 instead of 0 when doing a walk, and so 'level' is now a signed quantity, and should be typed as such. So turn it from
uint32_tintoint32_t.
Quoted 3 lines
Does this cause any visible wrong behaviour, or is it just a cleanup thing ?
No, 5 level paging is completely broken because of this, given that the 'level < 3' tests give the wrong result for (uint32_t)-1
Quoted 12 lines · Ard Biesheuvel
Quoted 10 lines · Peter Maydell
Quoted 7 lines · Ard Biesheuvel
The LPA2 extension implements 52-bit virtual addressing for 4k and 16k translation granules, and for the former, this means an additional level of translation is needed. This means we start counting at -1 instead of 0 when doing a walk, and so 'level' is now a signed quantity, and should be typed as such. So turn it from
uint32_tintoint32_t.
Quoted 6 lines
Quoted 3 lines
Does this cause any visible wrong behaviour, or is it just a cleanup thing ?
No, 5 level paging is completely broken because of this, given that the 'level < 3' tests give the wrong result for (uint32_t)-1
Right, thanks. This seems like a bug worth fixing for 7.2.
We should make 'uint32_t startlevel' also an int32_t for consistency, I think, given that it is also sometimes negative, though in that case it doesn't get used in any comparisons so it's not going to cause wrong behaviour.
thanks
-- PMM
Quoted 14 lines · Peter Maydell
Quoted 12 lines · Ard Biesheuvel
Quoted 10 lines · Peter Maydell
Quoted 7 lines · Ard Biesheuvel
The LPA2 extension implements 52-bit virtual addressing for 4k and 16k translation granules, and for the former, this means an additional level of translation is needed. This means we start counting at -1 instead of 0 when doing a walk, and so 'level' is now a signed quantity, and should be typed as such. So turn it from
uint32_tintoint32_t.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Does this cause any visible wrong behaviour, or is it just a cleanup thing ?
No, 5 level paging is completely broken because of this, given that the 'level < 3' tests give the wrong result for (uint32_t)-1
Right, thanks. This seems like a bug worth fixing for 7.2.
Indeed. And the other patch I sent is needed too if you want to run with LPA2
'target/arm: Limit LPA2 effective output address when TCR.DS == 0'
In case it is useful, I have a WIP kernel branch here which can be built with 52-bit virtual addressing for 4k or 16k pages.
https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=arm64-4k-lpa2
Quoted 5 lines
We should make '
uint32_tstartlevel' also anint32_tfor consistency, I think, given that it is also sometimes negative, though in that case it doesn't get used in any comparisons so it's not going to cause wrong behaviour.
Indeed. I'll send a v2 and fold that in.