From: Bibo Mao Date: Fri, 10 Oct 2025 03:11:07 +0000 (+0800) Subject: target/loongarch: Add bit A/D checking in TLB entry with PTW supported X-Git-Tag: v10.2.0-rc1~49^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=79ff2eee9a377f654ed0c3533a0874a0e7d6226d;p=thirdparty%2Fqemu.git target/loongarch: Add bit A/D checking in TLB entry with PTW supported With read/write access, add bit A/D checking if hardware PTW is supported. If no matched, hardware page table walk is called. And then bit A/D is updated in PTE entry and TLB entry is updated also. Signed-off-by: Bibo Mao Reviewed-by: Song Gao --- diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_helper.c index 1f3aaaa41d..01e0a27f0b 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -627,6 +627,31 @@ bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size, context.addr = address; context.tlb_index = -1; ret = get_physical_address(env, &context, access_type, mmu_idx, 0); + if (ret == TLBRET_MATCH && context.mmu_index != MMU_DA_IDX + && cpu_has_ptw(env)) { + bool need_update = true; + + if (access_type == MMU_DATA_STORE && pte_dirty(context.pte)) { + need_update = false; + } else if (access_type != MMU_DATA_STORE && pte_access(context.pte)) { + need_update = false; + + /* + * FIXME: should context.prot be set without PAGE_WRITE with + * pte_write(context.pte) && !pte_dirty(context.pte)?? + * + * Otherwise there will be no loongarch_cpu_tlb_fill() function call + * for MMU_DATA_STORE access_type in future since QEMU TLB with + * prot PAGE_WRITE is added already + */ + } + + if (need_update) { + /* Need update bit A/D in PTE entry, take PTW again */ + ret = TLBRET_NOMATCH; + } + } + if (ret != TLBRET_MATCH && cpu_has_ptw(env)) { /* Take HW PTW if TLB missed or bit P is zero */ if (ret == TLBRET_NOMATCH || ret == TLBRET_INVALID) {