diff mbox series

[7/7] target/ppc: Fix VRMA to not check virtual page class key protection

Message ID 20240806131318.275109-8-npiggin@gmail.com
State New
Headers show
Series various ppc fixes | expand

Commit Message

Nicholas Piggin Aug. 6, 2024, 1:13 p.m. UTC
Hash virtual real mode addressing is defined by the architecture
to not perform virtual page class key protection checks.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 target/ppc/mmu-hash64.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

BALATON Zoltan Aug. 6, 2024, 6:44 p.m. UTC | #1
On Tue, 6 Aug 2024, Nicholas Piggin wrote:
> Hash virtual real mode addressing is defined by the architecture
> to not perform virtual page class key protection checks.
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> target/ppc/mmu-hash64.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
> index 5e1983e334..c8c2f8910a 100644
> --- a/target/ppc/mmu-hash64.c
> +++ b/target/ppc/mmu-hash64.c
> @@ -993,6 +993,7 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
>     int exec_prot, pp_prot, amr_prot, prot;
>     int need_prot;
>     hwaddr raddr;
> +    bool vrma = false;
>
>     /*
>      * Note on LPCR usage: 970 uses HID4, but our special variant of
> @@ -1022,6 +1023,7 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
>             }
>         } else if (ppc_hash64_use_vrma(env)) {
>             /* Emulated VRMA mode */
> +            vrma = true;
>             slb = &vrma_slbe;
>             if (build_vrma_slbe(cpu, slb) != 0) {
>                 /* Invalid VRMA setup, machine check */
> @@ -1136,7 +1138,12 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
>
>     exec_prot = ppc_hash64_pte_noexec_guard(cpu, pte);
>     pp_prot = ppc_hash64_pte_prot(mmu_idx, slb, pte);
> -    amr_prot = ppc_hash64_amr_prot(cpu, pte);
> +    if (vrma) {
> +        /* VRMA does not check keys */
> +        amr_prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;

This can be shortened as PAGE_RWX which I think is simpler but does not 
have to be, only if you want. With that you could also shorten the if to a 
ternary operator as

amr_prot = vrma ? PAGE_RWX : ppc_hash64_amr_prot(cpu, pte);

and save some lines.

Regards,
BALATON Zoltan

> +    } else {
> +        amr_prot = ppc_hash64_amr_prot(cpu, pte);
> +    }
>     prot = exec_prot & pp_prot & amr_prot;
>
>     need_prot = check_prot_access_type(PAGE_RWX, access_type);
>
diff mbox series

Patch

diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index 5e1983e334..c8c2f8910a 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -993,6 +993,7 @@  bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
     int exec_prot, pp_prot, amr_prot, prot;
     int need_prot;
     hwaddr raddr;
+    bool vrma = false;
 
     /*
      * Note on LPCR usage: 970 uses HID4, but our special variant of
@@ -1022,6 +1023,7 @@  bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
             }
         } else if (ppc_hash64_use_vrma(env)) {
             /* Emulated VRMA mode */
+            vrma = true;
             slb = &vrma_slbe;
             if (build_vrma_slbe(cpu, slb) != 0) {
                 /* Invalid VRMA setup, machine check */
@@ -1136,7 +1138,12 @@  bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
 
     exec_prot = ppc_hash64_pte_noexec_guard(cpu, pte);
     pp_prot = ppc_hash64_pte_prot(mmu_idx, slb, pte);
-    amr_prot = ppc_hash64_amr_prot(cpu, pte);
+    if (vrma) {
+        /* VRMA does not check keys */
+        amr_prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
+    } else {
+        amr_prot = ppc_hash64_amr_prot(cpu, pte);
+    }
     prot = exec_prot & pp_prot & amr_prot;
 
     need_prot = check_prot_access_type(PAGE_RWX, access_type);