arm/ptw: Handle atomic updates of page tables entries in MMIO during PTW.
PATCH v3 1/1 arm/ptw: Handle atomic updates of page tables entries in MMIO during PTW.
Seen testing of CXL emulation on arm64 (currently out of tree).
CXL interleave occurs at subpage granularity so is emulated using an IO Memory Region. The memory is general purpose and as such may contain page tables. FEAT_HADFS using atomic accesses from the page table walkers to update accessed and dirty bits.
Note that disabling kernel support this ARM 8.1 feature avoids this issue as the PTW no longer does an atomic update of the page table entries, but that is a nasty workaround beyond its use in root causing this issue.
---
v3: Thanks Richard and Peter for reviewing.
Much simpler error handle + use of BQL_LOCK_GUARD() (Richard) Dropped RFC and updated description as seems this is converging!
--- target/arm/ptw.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
target/arm/ptw.c +29 -2
@@ -711,8 +711,35 @@ static uint64_t arm_casq_ptw(CPUARMState *env, uint64_t old_val,void *host = ptw->out_host;if (unlikely (!host)) { - fi->type = ARMFault_UnsuppAtomicUpdate; -return 0 ; +/* Page table in MMIO Memory Region */ +CPUState *cs =env_cpu (env); +MemTxAttrs attrs = { + .space = ptw->out_space, + .secure =arm_space_is_secure (ptw->out_space), + }; +AddressSpace *as =arm_addressspace (cs, attrs); +MemTxResult result =MEMTX_OK ; +BQL_LOCK_GUARD (); + + cur_val = (ptw->out_be + ?address_space_ldq_be (as, ptw->out_phys, attrs, &result) + :address_space_ldq_le (as, ptw->out_phys, attrs, &result)); +if (result ==MEMTX_OK && cur_val == old_val) { +if (ptw->out_be) { +address_space_stq_be (as, ptw->out_phys, new_val, attrs, + &result); + }else { +address_space_stq_le (as, ptw->out_phys, new_val, attrs, + &result); + } + } +if (unlikely (result !=MEMTX_OK )) { + fi->type = ARMFault_SyncExternalOnWalk; + fi->ea =arm_extabort_type (result); +return old_val; + } + +return cur_val; }/*
Signature · 1 line
2.39.2
Quoted 7 lines · Jonathan Cameron
Seen testing of CXL emulation on arm64 (currently out of tree).
CXL interleave occurs at subpage granularity so is emulated using an IO Memory Region. The memory is general purpose and as such may contain page tables.
FEAT_HADFSusing atomic accesses from the page table walkers to update accessed and dirty bits.
Quoted 6 lines
Note that disabling kernel support this ARM 8.1 feature avoids this issue as the PTW no longer does an atomic update of the page table entries, but that is a nasty workaround beyond its use in root causing this issue.
Signed-off-by Jonathan Cameron<[email protected]>---
r~
Peter Maydell
AppliedQuoted 8 lines · Jonathan Cameron
Seen testing of CXL emulation on arm64 (currently out of tree).
CXL interleave occurs at subpage granularity so is emulated using an IO Memory Region. The memory is general purpose and as such may contain page tables.
FEAT_HADFSusing atomic accesses from the page table walkers to update accessed and dirty bits.
Quoted 6 lines
Note that disabling kernel support this ARM 8.1 feature avoids this issue as the PTW no longer does an atomic update of the page table entries, but that is a nasty workaround beyond its use in root causing this issue.
Signed-off-by Jonathan Cameron <[email protected]>---
Applied to target-arm.next, thanks.
-- PMM