Skip to contentSkip to conversation

xen/arm CONFIG_PHYS_ADDR_T_32=y fixes

PATCH In review Michal Orzel 3 participants 6 messages Jan 28, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover xen/arm CONFIG_PHYS_ADDR_T_32=y fixes

This series contains build fixes when CONFIG_PHYS_ADDR_T_32=y.

@Oleksii:
This is a release blocker.

Michal Orzel (2):
device-tree: bootfdt: Fix build issue when CONFIG_PHYS_ADDR_T_32=y xen/arm: Fix build issue when CONFIG_PHYS_ADDR_T_32=y

 xen/arch/arm/include/asm/mm.h    | 2 +-
 xen/common/device-tree/bootfdt.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 device-tree: bootfdt: Fix build issue when CONFIG_PHYS_ADDR_T_32=y

On Arm32, when CONFIG_PHYS_ADDR_T_32 is set, a build failure is observed:
common/device-tree/bootfdt.c: In function 'build_assertions':
./include/xen/macros.h:47:31: error: static assertion failed: "!(alignof(struct membanks) != 8)"
47 | #define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })

      |                               ^~~~~~~~~~~~~~

common/device-tree/bootfdt.c:31:5: note: in expansion of macro 'BUILD_BUG_ON'
31 | BUILD_BUG_ON(alignof(struct membanks) != 8);

When CONFIG_PHYS_ADDR_T_32 is set, paddr_t is defined as unsigned long, therefore the struct membanks alignment is 4B and not 8B. The check is there to ensure the struct membanks and struct membank, which is a member of the former, are equally aligned. Therefore modify the check to compare alignments obtained via alignof not to rely on hardcoded values.

Fixes 2209c1e35b47 ("xen/arm: Introduce a generic way to access memory bank structures")

---
Changes in v2:
- modify the check to test against alignment of struct membank

---
 xen/common/device-tree/bootfdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/device-tree/bootfdt.c +2 -2
index 47386d4fffea..529c91e603ab 100644
@@ -27,8 +27,8 @@ static void __init __maybe_unused build_assertions(void)
      */
     BUILD_BUG_ON((offsetof(struct membanks, bank) !=
                  offsetof(struct meminfo, bank)));
-    /* Ensure "struct membanks" is 8-byte aligned */
-    BUILD_BUG_ON(alignof(struct membanks) != 8);
+    /* Ensure "struct membanks" and "struct membank" are equally aligned */
+    BUILD_BUG_ON(alignof(struct membanks) != alignof(struct membank));
 }
 
 static bool __init device_tree_node_is_available(const void *fdt, int node)
Signature · 1 line
2.25.1
Tested-by on v2 1/2
#2 lore raw

Re: [for-4.20][PATCH v2 1/2] device-tree: bootfdt: Fix build issue when CONFIG_PHYS_ADDR_T_32=y

Hi Michal, Julien,

Quoted 32 lines · Michal Orzel

On Arm32, when CONFIG_PHYS_ADDR_T_32 is set, a build failure is observed:
common/device-tree/bootfdt.c: In function 'build_assertions':
./include/xen/macros.h:47:31: error: static assertion failed: "!(alignof(struct membanks) != 8)"
47 | #define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })

     |                               ^~~~~~~~~~~~~~

common/device-tree/bootfdt.c:31:5: note: in expansion of macro 'BUILD_BUG_ON'
31 | BUILD_BUG_ON(alignof(struct membanks) != 8);

When CONFIG_PHYS_ADDR_T_32 is set, paddr_t is defined as unsigned long, therefore the struct membanks alignment is 4B and not 8B. The check is there to ensure the struct membanks and struct membank, which is a member of the former, are equally aligned. Therefore modify the check to compare alignments obtained via alignof not to rely on hardcoded values.

Fixes 2209c1e35b47 ("xen/arm: Introduce a generic way to access memory bank structures")

---
Changes in v2:
- modify the check to test against alignment of struct membank
---
xen/common/device-tree/bootfdt.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/device-tree/bootfdt.c +0 -0
index 47386d4fffea..529c91e603ab 100644

xen/common/device-tree/bootfdt.c static void __init __maybe_unused build_assertions(void) · line 31

Quoted 7 lines
xen/common/device-tree/bootfdt.c +2 -2
@@ -27,8 +27,8 @@ static void __init __maybe_unused build_assertions(void)
     */
    BUILD_BUG_ON((offsetof(struct membanks, bank) !=
                 offsetof(struct meminfo, bank)));
-    /* Ensure "struct membanks" is 8-byte aligned */
-    BUILD_BUG_ON(alignof(struct membanks) != 8);
+    /* Ensure "struct membanks" and "struct membank" are equally aligned */
+    BUILD_BUG_ON(alignof(struct membanks) != alignof(struct membank));

Apologies for not catching the issue for your v1, probably I didn't understand very well the test itself, why are we checking that the structure have the same alignment?
I see we check the offset of (struct membanks).bank against (struct meminfo|struct shared_meminfo).bank, isn't that enough?
For sure I’m missing something...

Anyway I tested this:

Quoted 7 lines
xen/common/device-tree/bootfdt.c +0 -0
 }
 
 static bool __init device_tree_node_is_available(const void *fdt, int node)
Signature · 1 line
2.25.1
#3 lore raw

Re: [for-4.20][PATCH v2 1/2] device-tree: bootfdt: Fix build issue when CONFIG_PHYS_ADDR_T_32=y

Quoted 41 lines · Luca Fancellu

Hi Michal, Julien,

Quoted 37 lines · Michal Orzel

On Arm32, when CONFIG_PHYS_ADDR_T_32 is set, a build failure is observed:
common/device-tree/bootfdt.c: In function 'build_assertions':
./include/xen/macros.h:47:31: error: static assertion failed: "!(alignof(struct membanks) != 8)"
47 | #define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })

     |                               ^~~~~~~~~~~~~~

common/device-tree/bootfdt.c:31:5: note: in expansion of macro 'BUILD_BUG_ON'
31 | BUILD_BUG_ON(alignof(struct membanks) != 8);

When CONFIG_PHYS_ADDR_T_32 is set, paddr_t is defined as unsigned long, therefore the struct membanks alignment is 4B and not 8B. The check is there to ensure the struct membanks and struct membank, which is a member of the former, are equally aligned. Therefore modify the check to compare alignments obtained via alignof not to rely on hardcoded values.

Fixes 2209c1e35b47 ("xen/arm: Introduce a generic way to access memory bank structures")

---
Changes in v2:
- modify the check to test against alignment of struct membank
---
xen/common/device-tree/bootfdt.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/device-tree/bootfdt.c +0 -2
index 47386d4fffea..529c91e603ab 100644
@@ -27,8 +27,8 @@ static void __init __maybe_unused build_assertions(void)
     */
    BUILD_BUG_ON((offsetof(struct membanks, bank) !=
                 offsetof(struct meminfo, bank)));
-    /* Ensure "struct membanks" is 8-byte aligned */
-    BUILD_BUG_ON(alignof(struct membanks) != 8);
Quoted 8 lines

xen/common/device-tree/bootfdt.c static void __init __maybe_unused build_assertions(void) · line 31

Quoted 2 lines
xen/common/device-tree/bootfdt.c +2 -0
+    /* Ensure "struct membanks" and "struct membank" are equally aligned */
+    BUILD_BUG_ON(alignof(struct membanks) != alignof(struct membank));

Apologies for not catching the issue for your v1, probably I didn't understand very well the test itself, why are we checking that the structure have the same alignment?
I see we check the offset of (struct membanks).bank against (struct meminfo|struct shared_meminfo).bank, isn't that enough?
For sure I’m missing something...

In my understanding it's to prevent issues when casting between these structures. It's not that FAM (flexible array member) requires the same alignment but if you consider casting this member to a type with a stricter alignment requirement you may encounter alignment issues.

Quoted 5 lines

Anyway I tested this:

~Michal

Reviewed-by on v2 1/2
#4 lore raw

Re: [for-4.20][PATCH v2 1/2] device-tree: bootfdt: Fix build issue when CONFIG_PHYS_ADDR_T_32=y

In reply to Michal Orzel
Quoted 18 lines · Michal Orzel

On Arm32, when CONFIG_PHYS_ADDR_T_32 is set, a build failure is observed:
common/device-tree/bootfdt.c: In function 'build_assertions':
./include/xen/macros.h:47:31: error: static assertion failed:
"!(alignof(struct membanks) != 8)"
47 | #define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond
")"); })

      |                               ^~~~~~~~~~~~~~

common/device-tree/bootfdt.c:31:5: note: in expansion of macro 'BUILD_BUG_ON'
31 | BUILD_BUG_ON(alignof(struct membanks) != 8);

When CONFIG_PHYS_ADDR_T_32 is set, paddr_t is defined as unsigned long, therefore the struct membanks alignment is 4B and not 8B. The check is there to ensure the struct membanks and struct membank, which is a member of the former, are equally aligned. Therefore modify the check to compare alignments obtained via alignof not to rely on hardcoded values.

Quoted 4 lines
Fixes 2209c1e35b47 ("xen/arm: Introduce a generic way to access memory

bank structures")

Cheers,

Quoted 29 lines

---
Changes in v2:
- modify the check to test against alignment of struct membank

---
 xen/common/device-tree/bootfdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/device-tree/bootfdt.c +2 -2
index 47386d4fffea..529c91e603ab 100644
@@ -27,8 +27,8 @@ static void __init __maybe_unused build_assertions(void)
      */
     BUILD_BUG_ON((offsetof(struct membanks, bank) !=
                  offsetof(struct meminfo, bank)));
-    /* Ensure "struct membanks" is 8-byte aligned */
-    BUILD_BUG_ON(alignof(struct membanks) != 8);
+    /* Ensure "struct membanks" and "struct membank" are equally aligned
 */
+    BUILD_BUG_ON(alignof(struct membanks) != alignof(struct membank));
 }
 

static bool __init device_tree_node_is_available(const void *fdt, int
node)
--
2.25.1

#5 lore raw

PATCH v2 2/2 xen/arm: Fix build issue when CONFIG_PHYS_ADDR_T_32=y

In reply to Michal Orzel

On Arm32, when CONFIG_PHYS_ADDR_T_32 is set, a build failure is observed:
arch/arm/platforms/vexpress.c: In function 'vexpress_smp_init':
arch/arm/platforms/vexpress.c:102:12: error: format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'long long unsigned int' [-Werror=format=]
102 | printk("Set SYS_FLAGS to %"PRIpaddr" (%p)\n",

When CONFIG_PHYS_ADDR_T_32 is set, paddr_t is defined as unsigned long. Commit 96f35de69e59 dropped __virt_to_maddr() which used paddr_t as a return type. Without a cast, the expression type is unsigned long long which causes the issue. Fix it.

Fixes 96f35de69e59 ("x86+Arm: drop (rename) __virt_to_maddr() / __maddr_to_virt()")

---
Changes in v2:
- none

---
 xen/arch/arm/include/asm/mm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/include/asm/mm.h +1 -1
index f91ff088f6b1..a0d8e5afe977 100644
@@ -263,7 +263,7 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 
 #define virt_to_maddr(va) ({                                        \
     vaddr_t va_ = (vaddr_t)(va);                                    \
-    (va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK); \
+    (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \
 })
 
 #ifdef CONFIG_ARM_32
Signature · 1 line
2.25.1