diff mbox series

[PULL,13/13] target/loongarch: Clear PAGE_READ when PTE.NR is set

Message ID 20261105065345.966691-14-maobibo@loongson.cn
State New
Headers show
Series [PULL,01/13] bios-tables-test-allowed-diff.h: Allow LoongArch DSDT.* | expand

Commit Message

Bibo Mao Nov. 5, 2026, 6:53 a.m. UTC
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: qemu-stable@nongnu.org
Fixes: 7392cb1c7b24 ("target/loongarch: Add common function loongarch_check_pte()")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Reviewed-by: Xianglai Li <lixianglai@loongson.cn>
---
 target/loongarch/cpu_helper.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

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;