[PATCH] target/loongarch: Clear PAGE_READ when PTE.NR is set

Bibo Mao posted 1 patch 3 weeks, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261030080516.229527-1-maobibo@loongson.cn
Maintainers: Song Gao <17746591750@163.com>, Bibo Mao <maobibo@loongson.cn>, Xianglai Li <lixianglai@loongson.cn>
target/loongarch/cpu_helper.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] target/loongarch: Clear PAGE_READ when PTE.NR is set
Posted by Bibo Mao 3 weeks, 2 days ago
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>
---
 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;

base-commit: 73294d096cc591e122fde9e63db4739de6d84f2b
-- 
2.54.0
Re: [PATCH] target/loongarch: Clear PAGE_READ when PTE.NR is set
Posted by lixianglai 2 weeks, 3 days ago
Reviewed-by:  Xianglai Li <lixianglai@loongson.cn>


> 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>
> ---
>   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;
>
> base-commit: 73294d096cc591e122fde9e63db4739de6d84f2b