qemu-ppc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-ppc] [PATCH 22/32] mmu-hash64: Separate VA matching from permissio


From: David Gibson
Subject: [Qemu-ppc] [PATCH 22/32] mmu-hash64: Separate VA matching from permission checking in pte64_check()
Date: Fri, 15 Feb 2013 19:01:12 +1100

pte64_check does several things.  First it checks that the given PTE
matches the requested virtual address, next it does permissions checking
and some other processing of the pte contents.

This patch separates out the first into a new pte64_match() function,
meaning we can now call the permissions checking pte64_check() function
at the end of find_pte64(), once we've found a matching PTE.

Signed-off-by: David Gibson <address@hidden>
---
 target-ppc/mmu-hash64.c |   58 +++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/target-ppc/mmu-hash64.c b/target-ppc/mmu-hash64.c
index 03c8d29..6320228 100644
--- a/target-ppc/mmu-hash64.c
+++ b/target-ppc/mmu-hash64.c
@@ -299,35 +299,35 @@ static int ppc_hash64_check_prot(int prot, int rwx)
     return ret;
 }
 
+static bool pte64_match(target_ulong pte0, target_ulong pte1,
+                        bool secondary, target_ulong ptem)
+{
+    return (pte0 & HPTE_V_VALID)
+        && (secondary == !!(pte0 & HPTE_V_SECONDARY))
+        && HPTE_V_COMPARE(pte0, ptem);
+}
+
 static int pte64_check(struct mmu_ctx_hash64 *ctx, target_ulong pte0,
-                       target_ulong pte1, int h, int rwx)
+                       target_ulong pte1, int rwx)
 {
     int access, ret, pp;
+    bool nx;
 
-    ret = -1;
-    /* Check validity and table match */
-    if ((pte0 & HPTE_V_VALID) && (h == !!(pte0 & HPTE_V_SECONDARY))) {
-        bool nx;
-
-        /* Check vsid & api */
-        pp = (pte1 & HPTE_R_PP) | ((pte1 & HPTE_R_PP0) >> 61);
-        /* No execute if either noexec or guarded bits set */
-        nx = (pte1 & HPTE_R_N) || (pte1 & HPTE_R_G);
-        if (HPTE_V_COMPARE(pte0, ctx->ptem)) {
-            /* Compute access rights */
-            access = ppc_hash64_pp_check(ctx->key, pp, nx);
-            /* Keep the matching PTE informations */
-            ctx->raddr = pte1;
-            ctx->prot = access;
-            ret = ppc_hash64_check_prot(ctx->prot, rwx);
-            if (ret == 0) {
-                /* Access granted */
-                LOG_MMU("PTE access granted !\n");
-            } else {
-                /* Access right violation */
-                LOG_MMU("PTE access rejected\n");
-            }
-        }
+    pp = (pte1 & HPTE_R_PP) | ((pte1 & HPTE_R_PP0) >> 61);
+    /* No execute if either noexec or guarded bits set */
+    nx = (pte1 & HPTE_R_N) || (pte1 & HPTE_R_G);
+    /* Compute access rights */
+    access = ppc_hash64_pp_check(ctx->key, pp, nx);
+    /* Keep the matching PTE informations */
+    ctx->raddr = pte1;
+    ctx->prot = access;
+    ret = ppc_hash64_check_prot(ctx->prot, rwx);
+    if (ret == 0) {
+        /* Access granted */
+        LOG_MMU("PTE access granted !\n");
+    } else {
+        /* Access right violation */
+        LOG_MMU("PTE access rejected\n");
     }
 
     return ret;
@@ -366,7 +366,7 @@ static int find_pte64(CPUPPCState *env, struct 
mmu_ctx_hash64 *ctx,
     hwaddr pteg_off;
     target_ulong pte0, pte1;
     int i, good = -1;
-    int ret, r;
+    int ret;
 
     ret = -1; /* No entry found */
     pteg_off = (ctx->hash[h] * HASH_PTEG_SIZE_64) & env->htab_mask;
@@ -374,18 +374,18 @@ static int find_pte64(CPUPPCState *env, struct 
mmu_ctx_hash64 *ctx,
         pte0 = ppc_hash64_load_hpte0(env, pteg_off + i*HASH_PTE_SIZE_64);
         pte1 = ppc_hash64_load_hpte1(env, pteg_off + i*HASH_PTE_SIZE_64);
 
-        r = pte64_check(ctx, pte0, pte1, h, rwx);
         LOG_MMU("Load pte from %016" HWADDR_PRIx " => " TARGET_FMT_lx " "
                 TARGET_FMT_lx " %d %d %d " TARGET_FMT_lx "\n",
                 pteg_off + (i * 16), pte0, pte1, !!(pte0 & HPTE_V_VALID),
                 h, !!(pte0 & HPTE_V_SECONDARY), ctx->ptem);
-        if (r != -1) {
-            ret = r;
+
+        if (pte64_match(pte0, pte1, h, ctx->ptem)) {
             good = i;
             break;
         }
     }
     if (good != -1) {
+        ret = pte64_check(ctx, pte0, pte1, rwx);
         LOG_MMU("found PTE at addr %08" HWADDR_PRIx " prot=%01x ret=%d\n",
                 ctx->raddr, ctx->prot, ret);
         /* Update page flags */
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]