[14/17] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function
diff mbox series

Message ID 20200322161418.31606-15-julien@xen.org
State New
Headers show
Series
  • Bunch of typesafe conversion
Related show

Commit Message

Julien Grall March 22, 2020, 4:14 p.m. UTC
From: Julien Grall <julien.grall@arm.com>

set_gpfn_from_mfn() is currently implement in a 2 part macros. The
second macro is only called within the first macro, so they can be
folded together.

Furthermore, this is now converted to a static inline making the code
more readable and safer.

Signed-off-by: Julien Grall <julien.grall@arm.com>

---

    This was originally sent as part of "xen/arm: Properly disable M2P
    on Arm" [1].

    Changes since the original version:
        - Remove the paragraph in the comment about dom_* as we don't
          need to move them anymore.
        - Constify 'd' as it is never modified within the function

    [1] <20190603160350.29806-1-julien.grall@arm.com>
---
 xen/include/asm-x86/mm.h | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

Comments

Jan Beulich March 27, 2020, 12:44 p.m. UTC | #1
On 22.03.2020 17:14, julien@xen.org wrote:
> From: Julien Grall <julien.grall@arm.com>
> 
> set_gpfn_from_mfn() is currently implement in a 2 part macros. The
> second macro is only called within the first macro, so they can be
> folded together.
> 
> Furthermore, this is now converted to a static inline making the code
> more readable and safer.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>

Patch
diff mbox series

diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 83058fb8d1..53f2ed7c7d 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -493,24 +493,25 @@  extern paddr_t mem_hotplug;
 #define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
 
 #define compat_machine_to_phys_mapping ((unsigned int *)RDWR_COMPAT_MPT_VIRT_START)
-#define _set_gpfn_from_mfn(mfn, pfn) ({                        \
-    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); \
-    unsigned long entry = (d && (d == dom_cow)) ?              \
-        SHARED_M2P_ENTRY : (pfn);                              \
-    ((void)((mfn) >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 || \
-            (compat_machine_to_phys_mapping[(mfn)] = (unsigned int)(entry))), \
-     machine_to_phys_mapping[(mfn)] = (entry));                \
-    })
 
 /*
  * Disable some users of set_gpfn_from_mfn() (e.g., free_heap_pages()) until
  * the machine_to_phys_mapping is actually set up.
  */
 extern bool machine_to_phys_mapping_valid;
-#define set_gpfn_from_mfn(mfn, pfn) do {        \
-    if ( machine_to_phys_mapping_valid )        \
-        _set_gpfn_from_mfn(mfn, pfn);           \
-} while (0)
+
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+{
+    const struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;
+
+    if ( !machine_to_phys_mapping_valid )
+        return;
+
+    if ( mfn < (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
+        compat_machine_to_phys_mapping[mfn] = entry;
+    machine_to_phys_mapping[mfn] = entry;
+}
 
 extern struct rangeset *mmio_ro_ranges;