KVM: arm64: Fix masks in stage2_pte_cacheable()
Will Deacon
maintainerPATCH 1/1 KVM: arm64: Fix masks in stage2_pte_cacheable()
stage2_pte_cacheable() tries to figure out whether the mapping installed in its 'pte' parameter is cacheable or not. Unfortunately, it fails miserably because it extracts the memory attributes from the entry using FIELD_GET(), which returns the attributes shifted down to bit 0, but then compares this with the unshifted value generated by the PAGE_S2_MEMATTR() macro.
A direct consequence of this bug is that cache maintenance is silently skipped, which in turn causes 32-bit guests to crash early on when their set/way maintenance is trapped but not emulated correctly.
Fix the broken masks by avoiding the use of FIELD_GET() altogether.
---
Applies on top of the other pgtable fix I previously sent here:
https://lore.kernel.org/r/[email protected]
arch/arm64/kvm/hyp/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/hyp/pgtable.c +1 -1
@@ -635,7 +635,7 @@ static void stage2_flush_dcache(void *addr, u64 size)static bool stage2_pte_cacheable (kvm_pte_t pte) { -u64 memattr =FIELD_GET (KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR , pte); +u64 memattr = pte &KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR ;return memattr ==PAGE_S2_MEMATTR (NORMAL ); }
Signature · 6 lines
2.29.1.341.ge80a0c044ae-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 8 lines · Will Deacon
stage2_pte_cacheable()tries to figure out whether the mapping installed in its 'pte' parameter is cacheable or not. Unfortunately, it fails miserably because it extracts the memory attributes from the entry usingFIELD_GET(), which returns the attributes shifted down to bit 0, but then compares this with the unshifted value generated by thePAGE_S2_MEMATTR()macro.[...]
Applied to next, thanks!
[1/1] KVM: arm64: Fix masks in stage2_pte_cacheable()
commit: e2fc6a9f686d037cbd9b08b9fb657685b4a722d3
Cheers,
M.
Signature · 7 lines
Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm