All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Julien Grall <julien.grall@arm.com>,
	sstabellini@kernel.org, Julien Grall <julien.grall@linaro.org>
Subject: [PATCH 14/15] xen/arm: guest_walk_tables: Switch the return to bool
Date: Mon, 16 Jul 2018 18:27:11 +0100	[thread overview]
Message-ID: <20180716172712.20294-15-julien.grall@arm.com> (raw)
In-Reply-To: <20180716172712.20294-1-julien.grall@arm.com>

At the moment, guest_walk_tables can either return 0, -EFAULT, -EINVAL.
The use of the last 2 are not clearly defined and used inconsistently in
the code. The current only caller does not care about the return
value and the value of it seems very limited (no way to differentiate
between the 15ish error paths).

So switch to bool to simplify the return and make the developper life a
bit easier.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/arch/arm/guest_walk.c        | 50 ++++++++++++++++++++--------------------
 xen/arch/arm/mem_access.c        |  2 +-
 xen/include/asm-arm/guest_walk.h |  8 +++----
 3 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c
index 4a1b4cf2c8..7db7a7321b 100644
--- a/xen/arch/arm/guest_walk.c
+++ b/xen/arch/arm/guest_walk.c
@@ -28,9 +28,9 @@
  * page table on a different vCPU, the following registers would need to be
  * loaded: TCR_EL1, TTBR0_EL1, TTBR1_EL1, and SCTLR_EL1.
  */
-static int guest_walk_sd(const struct vcpu *v,
-                         vaddr_t gva, paddr_t *ipa,
-                         unsigned int *perms)
+static bool guest_walk_sd(const struct vcpu *v,
+                          vaddr_t gva, paddr_t *ipa,
+                          unsigned int *perms)
 {
     int ret;
     bool disabled = true;
@@ -79,7 +79,7 @@ static int guest_walk_sd(const struct vcpu *v,
     }
 
     if ( disabled )
-        return -EFAULT;
+        return false;
 
     /*
      * The address of the L1 descriptor for the initial lookup has the
@@ -97,12 +97,12 @@ static int guest_walk_sd(const struct vcpu *v,
     /* Access the guest's memory to read only one PTE. */
     ret = access_guest_memory_by_ipa(d, paddr, &pte, sizeof(short_desc_t), false);
     if ( ret )
-        return -EINVAL;
+        return false;
 
     switch ( pte.walk.dt )
     {
     case L1DESC_INVALID:
-        return -EFAULT;
+        return false;
 
     case L1DESC_PAGE_TABLE:
         /*
@@ -122,10 +122,10 @@ static int guest_walk_sd(const struct vcpu *v,
         /* Access the guest's memory to read only one PTE. */
         ret = access_guest_memory_by_ipa(d, paddr, &pte, sizeof(short_desc_t), false);
         if ( ret )
-            return -EINVAL;
+            return false;
 
         if ( pte.walk.dt == L2DESC_INVALID )
-            return -EFAULT;
+            return false;
 
         if ( pte.pg.page ) /* Small page. */
         {
@@ -175,7 +175,7 @@ static int guest_walk_sd(const struct vcpu *v,
             *perms |= GV2M_EXEC;
     }
 
-    return 0;
+    return true;
 }
 
 /*
@@ -355,9 +355,9 @@ static bool check_base_size(unsigned int output_size, uint64_t base)
  * page table on a different vCPU, the following registers would need to be
  * loaded: TCR_EL1, TTBR0_EL1, TTBR1_EL1, and SCTLR_EL1.
  */
-static int guest_walk_ld(const struct vcpu *v,
-                         vaddr_t gva, paddr_t *ipa,
-                         unsigned int *perms)
+static bool guest_walk_ld(const struct vcpu *v,
+                          vaddr_t gva, paddr_t *ipa,
+                          unsigned int *perms)
 {
     int ret;
     bool disabled = true;
@@ -442,7 +442,7 @@ static int guest_walk_ld(const struct vcpu *v,
          */
         if ( (input_size > TCR_EL1_IPS_48_BIT_VAL) ||
              (input_size < TCR_EL1_IPS_MIN_VAL) )
-            return -EFAULT;
+            return false;
     }
     else
     {
@@ -487,7 +487,7 @@ static int guest_walk_ld(const struct vcpu *v,
     }
 
     if ( disabled )
-        return -EFAULT;
+        return false;
 
     /*
      * The starting level is the number of strides (grainsizes[gran] - 3)
@@ -498,12 +498,12 @@ static int guest_walk_ld(const struct vcpu *v,
     /* Get the IPA output_size. */
     ret = get_ipa_output_size(d, tcr, &output_size);
     if ( ret )
-        return -EFAULT;
+        return false;
 
     /* Make sure the base address does not exceed its configured size. */
     ret = check_base_size(output_size, ttbr);
     if ( !ret )
-        return -EFAULT;
+        return false;
 
     /*
      * Compute the base address of the first level translation table that is
@@ -523,12 +523,12 @@ static int guest_walk_ld(const struct vcpu *v,
         /* Access the guest's memory to read only one PTE. */
         ret = access_guest_memory_by_ipa(d, paddr, &pte, sizeof(lpae_t), false);
         if ( ret )
-            return -EFAULT;
+            return false;
 
         /* Make sure the base address does not exceed its configured size. */
         ret = check_base_size(output_size, pfn_to_paddr(pte.walk.base));
         if ( !ret )
-            return -EFAULT;
+            return false;
 
         /*
          * If page granularity is 64K, make sure the address is aligned
@@ -537,7 +537,7 @@ static int guest_walk_ld(const struct vcpu *v,
         if ( (output_size < TCR_EL1_IPS_52_BIT_VAL) &&
              (gran == GRANULE_SIZE_INDEX_64K) &&
              (pte.walk.base & 0xf) )
-            return -EFAULT;
+            return false;
 
         /*
          * Break if one of the following conditions is true:
@@ -567,7 +567,7 @@ static int guest_walk_ld(const struct vcpu *v,
      * maps a memory block at level 3 (PTE<1:0> == 01).
      */
     if ( !lpae_is_valid(pte) || !lpae_is_mapping(pte, level) )
-        return -EFAULT;
+        return false;
 
     /* Make sure that the lower bits of the PTE's base address are zero. */
     mask = GENMASK_ULL(47, grainsizes[gran]);
@@ -583,11 +583,11 @@ static int guest_walk_ld(const struct vcpu *v,
     if ( !pte.pt.xn && !xn_table )
         *perms |= GV2M_EXEC;
 
-    return 0;
+    return true;
 }
 
-int guest_walk_tables(const struct vcpu *v, vaddr_t gva,
-                      paddr_t *ipa, unsigned int *perms)
+bool guest_walk_tables(const struct vcpu *v, vaddr_t gva,
+                       paddr_t *ipa, unsigned int *perms)
 {
     uint32_t sctlr = READ_SYSREG(SCTLR_EL1);
     register_t tcr = READ_SYSREG(TCR_EL1);
@@ -595,7 +595,7 @@ int guest_walk_tables(const struct vcpu *v, vaddr_t gva,
 
     /* We assume that the domain is running on the currently active domain. */
     if ( v != current )
-        return -EFAULT;
+        return false;
 
     /* Allow perms to be NULL. */
     perms = perms ?: &_perms;
@@ -619,7 +619,7 @@ int guest_walk_tables(const struct vcpu *v, vaddr_t gva,
         /* Memory can be accessed without any restrictions. */
         *perms = GV2M_READ|GV2M_WRITE|GV2M_EXEC;
 
-        return 0;
+        return true;
     }
 
     if ( is_32bit_domain(v->domain) && !(tcr & TTBCR_EAE) )
diff --git a/xen/arch/arm/mem_access.c b/xen/arch/arm/mem_access.c
index ae2686ffa2..57ec7872bb 100644
--- a/xen/arch/arm/mem_access.c
+++ b/xen/arch/arm/mem_access.c
@@ -125,7 +125,7 @@ p2m_mem_access_check_and_get_page(vaddr_t gva, unsigned long flag,
          * The software gva to ipa translation can still fail, e.g., if the gva
          * is not mapped.
          */
-        if ( guest_walk_tables(v, gva, &ipa, &perms) < 0 )
+        if ( !guest_walk_tables(v, gva, &ipa, &perms) )
             return NULL;
 
         /*
diff --git a/xen/include/asm-arm/guest_walk.h b/xen/include/asm-arm/guest_walk.h
index 4ed8476e08..8768ac9894 100644
--- a/xen/include/asm-arm/guest_walk.h
+++ b/xen/include/asm-arm/guest_walk.h
@@ -2,10 +2,10 @@
 #define _XEN_GUEST_WALK_H
 
 /* Walk the guest's page tables in software. */
-int guest_walk_tables(const struct vcpu *v,
-                      vaddr_t gva,
-                      paddr_t *ipa,
-                      unsigned int *perms);
+bool guest_walk_tables(const struct vcpu *v,
+                       vaddr_t gva,
+                       paddr_t *ipa,
+                       unsigned int *perms);
 
 #endif /* _XEN_GUEST_WALK_H */
 
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-07-16 17:27 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16 17:26 [PATCH 00/15] xen/arm: Bunch of clean-up/improvement Julien Grall
2018-07-16 17:26 ` [PATCH 01/15] xen/arm: cpregs: Allow HSR_CPREG* to receive more than 1 parameter Julien Grall
2018-08-14 21:47   ` Stefano Stabellini
2018-07-16 17:26 ` [PATCH 02/15] xen/arm: cpregs: Fix typo in the documentation of TTBCR Julien Grall
2018-08-14 20:39   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 03/15] xen/arm: Introduce helpers to clear/flags flags in HCR_EL2 Julien Grall
2018-08-14 20:46   ` Stefano Stabellini
2018-08-14 21:23     ` Julien Grall
2018-08-14 21:49       ` Stefano Stabellini
2018-08-14 22:53         ` Julien Grall
2018-08-14 23:03           ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 04/15] xen/arm: p2m: Reduce the locking section in get_page_from_gva Julien Grall
2018-08-14 20:49   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 05/15] xen/arm: p2m: Limit call to mem access code use " Julien Grall
2018-07-17  9:54   ` Razvan Cojocaru
2018-08-14 20:59   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 06/15] xen/arm: Rework lpae_mapping Julien Grall
2018-08-14 21:04   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 07/15] xen/arm: Rework lpae_table Julien Grall
2018-08-14 21:07   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 08/15] xen/arm: Rename lpae_valid to lpae_is_valid Julien Grall
2018-08-14 21:09   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 09/15] xen/arm: guest_walk: Use lpae_is_mapping to simplify the code Julien Grall
2018-08-14 21:14   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 10/15] xen/arm: Introduce helpers to get/set an MFN from/to an LPAE entry Julien Grall
2018-08-14 21:25   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 11/15] xen/arm: Allow lpae_is_{table, mapping} helpers to work on invalid entry Julien Grall
2018-08-14 21:33   ` Stefano Stabellini
2018-08-14 22:51     ` Julien Grall
2018-08-15 19:13       ` Stefano Stabellini
2018-08-16  8:51         ` Julien Grall
2018-07-16 17:27 ` [PATCH 12/15] xen/arm: p2m: Rename ret to mfn in p2m_lookup Julien Grall
2018-08-14 21:35   ` Stefano Stabellini
2018-07-16 17:27 ` [PATCH 13/15] xen/arm: p2m: Introduce a new variable removing_mapping in __p2m_set_entry Julien Grall
2018-08-14 21:37   ` Stefano Stabellini
2018-07-16 17:27 ` Julien Grall [this message]
2018-08-14 21:41   ` [PATCH 14/15] xen/arm: guest_walk_tables: Switch the return to bool Stefano Stabellini
2018-07-16 17:27 ` [PATCH 15/15] xen/arm: traps: Move the implementation of GUEST_BUG_ON in traps.h Julien Grall
2018-08-14 21:43   ` Stefano Stabellini
2018-08-16  8:54     ` Julien Grall
2018-08-16 18:17       ` Stefano Stabellini
2018-08-20  9:17         ` Julien Grall
2018-08-20 22:02           ` Stefano Stabellini
2018-07-23 17:12 ` [PATCH 00/15] xen/arm: Bunch of clean-up/improvement Julien Grall
2018-08-22 15:45 ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180716172712.20294-15-julien.grall@arm.com \
    --to=julien.grall@arm.com \
    --cc=julien.grall@linaro.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.