On LoongArch the NR bit in a PTE indicates that the page is not readable, i.e. it is write-only. When translating a PTE to QEMU protection bits, clear PAGE_READ if PTE.NR is set instead of always exposing PAGE_READ.
This avoids incorrectly marking a write-only page as readable. Cc: [email protected] Fixes: 7392cb1c7b24 ("target/loongarch: Add common function loongarch_check_pte()") Signed-off-by: Bibo Mao <[email protected]> Reviewed-by: Xianglai Li <[email protected]> --- target/loongarch/cpu_helper.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/target/loongarch/cpu_helper.c b/target/loongarch/cpu_helper.c index 271b4adc17..6b98fff691 100644 --- a/target/loongarch/cpu_helper.c +++ b/target/loongarch/cpu_helper.c @@ -101,7 +101,10 @@ TLBRet loongarch_check_pte(CPULoongArchState *env, MMUContext *context, context->physical = (tlb_ppn << R_TLBENTRY_64_PPN_SHIFT) | (context->addr & MAKE_64BIT_MASK(0, tlb_ps)); - context->prot = PAGE_READ; + context->prot = 0; + if (!tlb_nr) { + context->prot |= PAGE_READ; + } context->mmu_index = tlb_plv; if (tlb_d) { context->prot |= PAGE_WRITE; -- 2.54.0
