Skip to contentSkip to conversation

xen/mm: Remove INVALID_{MFN,GFN}_INITIALIZER

PATCH In review Andrew Cooper 4 participants 4 messages Jun 30 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/mm: Remove INVALID_{MFN,GFN}_INITIALIZER

These existed to work around a bug in older GCC when using struct-casting for variable initialisation. However, our baseline toolchain is new enough to not suffer this bug.

Removing these resolves two MISRA Rule 9.2 violations which exist in release builds of Xen only, where "= { ... }" is disallowed for simple scalar initialisation.

The BUILD_BUG_ON() in xenmem_add_to_physmap() cannot stay as it is, because INVALID_GFN is not an Integer Constant Expression. Replace it BUILD_ERROR() which is the nearest available alternative.

No functional change.

---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Oleksii Kurochko <[email protected]>

v2:
* Drop INVALID_{MFN,GFN}_INITIALIZER entirely.

For 4.22. staging-4.22 is currently blocked by this bug, following the switch from debug builds to release builds.

Passing pipeline:
https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2638483933

---
 xen/arch/arm/mmu/setup.c   |  2 +-
 xen/arch/riscv/mm.c        |  2 +-
 xen/arch/x86/efi/runtime.h |  2 +-
 xen/common/memory.c        |  4 +++-
 xen/common/page_alloc.c    |  2 +-
 xen/include/xen/mm-frame.h | 16 ++--------------
 6 files changed, 9 insertions(+), 19 deletions(-)
xen/arch/arm/mmu/setup.c +1 -1
index d042f7359703..8fb0157aff98 100644
@@ -59,7 +59,7 @@ DEFINE_BOOT_PAGE_TABLE(xen_fixmap);
 static DEFINE_PAGE_TABLES(xen_xenmap, XEN_NR_ENTRIES(2));
 
 /* Limits of the Xen heap */
-mfn_t directmap_mfn_start __read_mostly = INVALID_MFN_INITIALIZER;
+mfn_t directmap_mfn_start __read_mostly = INVALID_MFN;
 mfn_t directmap_mfn_end __read_mostly;
 vaddr_t directmap_virt_end __read_mostly;
 #ifdef CONFIG_ARM_64
xen/arch/riscv/mm.c +1 -1
index e9ce182d066c..4d3b8c220442 100644
@@ -480,7 +480,7 @@ static void __init setup_frametable_mappings(paddr_t ps, paddr_t pe)
 static void __init setup_directmap_mappings(unsigned long base_mfn,
                                             unsigned long nr_mfns)
 {
-    static mfn_t __initdata directmap_mfn_start = INVALID_MFN_INITIALIZER;
+    static mfn_t __initdata directmap_mfn_start = INVALID_MFN;
 
     mfn_t base_mfn_t = _mfn(base_mfn);
     unsigned long base_addr = mfn_to_maddr(base_mfn_t);
xen/arch/x86/efi/runtime.h +1 -1
index 88ab5651e9ce..f92d7af95e00 100644
@@ -7,7 +7,7 @@
 #include <asm/mc146818rtc.h>
 
 #ifndef COMPAT
-mfn_t __read_mostly efi_l4_mfn = INVALID_MFN_INITIALIZER;
+mfn_t __read_mostly efi_l4_mfn = INVALID_MFN;
 
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e)
 {
xen/common/memory.c +3 -1
index 3672bda0253d..2ca7723e50aa 100644
@@ -991,7 +991,9 @@ int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp,
          * guaranteeing that it won't fall in the middle of the
          * [xatp->gpfn, xatp->gpfn + xatp->size) range checked above.
          */
-        BUILD_BUG_ON(INVALID_GFN_RAW + 1);
+        if ( gfn_x(INVALID_GFN) + 1 )
+            BUILD_ERROR("bad INVALID_GFN");
+
         return -EOVERFLOW;
     }
 
xen/common/page_alloc.c +1 -1
index e01ac3e99c72..40b0f73563a5 100644
@@ -275,7 +275,7 @@ static PAGE_LIST_HEAD(page_broken_list);
  * When !CONFIG_NUMA first_valid_mfn is non-static, for use by respective
  * stubs.
  */
-STATIC_IF(CONFIG_NUMA) mfn_t first_valid_mfn = INVALID_MFN_INITIALIZER;
+STATIC_IF(CONFIG_NUMA) mfn_t first_valid_mfn = INVALID_MFN;
 
 struct bootmem_region {
     unsigned long s, e; /* MFNs @s through @e-1 inclusive are free */
xen/include/xen/mm-frame.h +2 -14
index d973aec901fa..1402c2049778 100644
@@ -6,13 +6,7 @@
 
 TYPE_SAFE(unsigned long, mfn);
 #define PRI_mfn          "05lx"
-#define INVALID_MFN_RAW  (~0UL)
-#define INVALID_MFN      _mfn(INVALID_MFN_RAW)
-/*
- * To be used for global variable initialization. This workaround a bug
- * in GCC < 5.0.
- */
-#define INVALID_MFN_INITIALIZER { INVALID_MFN_RAW }
+#define INVALID_MFN      ((mfn_t){ ~0UL })
 
 #if 0
 #define mfn_t /* Grep fodder: mfn_t, _mfn() and mfn_x() are defined above */
@@ -42,13 +36,7 @@ static inline bool mfn_eq(mfn_t x, mfn_t y)
 
 TYPE_SAFE(unsigned long, gfn);
 #define PRI_gfn          "05lx"
-#define INVALID_GFN_RAW  (~0UL)
-#define INVALID_GFN      _gfn(INVALID_GFN_RAW)
-/*
- * To be used for global variable initialization. This workaround a bug
- * in GCC < 5.0 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64856
- */
-#define INVALID_GFN_INITIALIZER { INVALID_GFN_RAW }
+#define INVALID_GFN      ((gfn_t){ ~0UL })
 
 #if 0
 #define gfn_t /* Grep fodder: gfn_t, _gfn() and gfn_x() are defined above */
Signature · 1 line
2.39.5
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Andrew Cooper

These existed to work around a bug in older GCC when using struct-casting for variable initialisation. However, our baseline toolchain is new enough to not suffer this bug.

Removing these resolves two MISRA Rule 9.2 violations which exist in release builds of Xen only, where "= { ... }" is disallowed for simple scalar initialisation.

Quoted 7 lines

The BUILD_BUG_ON() in xenmem_add_to_physmap() cannot stay as it is, because INVALID_GFN is not an Integer Constant Expression. Replace it BUILD_ERROR() which is the nearest available alternative.

No functional change.

#2 lore raw
In reply to Andrew Cooper
Quoted 29 lines · Andrew Cooper

These existed to work around a bug in older GCC when using struct-casting for variable initialisation. However, our baseline toolchain is new enough to not suffer this bug.

Removing these resolves two MISRA Rule 9.2 violations which exist in release builds of Xen only, where "= { ... }" is disallowed for simple scalar initialisation.

The BUILD_BUG_ON() in xenmem_add_to_physmap() cannot stay as it is, because INVALID_GFN is not an Integer Constant Expression. Replace it BUILD_ERROR() which is the nearest available alternative.

No functional change.

---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Oleksii Kurochko <[email protected]>

v2:
* Drop INVALID_{MFN,GFN}_INITIALIZER entirely.

Quoted 6 lines

For 4.22. staging-4.22 is currently blocked by this bug, following the switch from debug builds to release builds.

Passing pipeline:

   https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2638483933

---

~ Oleksii

Reviewed-by on v2 1/1
#3 lore raw
In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper

These existed to work around a bug in older GCC when using struct-casting for variable initialisation. However, our baseline toolchain is new enough to not suffer this bug.

Removing these resolves two MISRA Rule 9.2 violations which exist in release builds of Xen only, where "= { ... }" is disallowed for simple scalar initialisation.

Quoted 7 lines

The BUILD_BUG_ON() in xenmem_add_to_physmap() cannot stay as it is, because INVALID_GFN is not an Integer Constant Expression. Replace it BUILD_ERROR() which is the nearest available alternative.

No functional change.

~Michal