Skip to contentSkip to conversation

iommu, debugobjects: avoid gcc-16.1 section mismatch warnings

PATCH In review Arnd Bergmann 7 participants 7 messages May 13 – May 28

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 iommu, debugobjects: avoid gcc-16.1 section mismatch warnings

From: Arnd Bergmann <[email protected]>

gcc-16 has gained some more advanced inter-procedual optimization techniques that enable it to inline the dummy_tlb_add_page() and dummy_tlb_flush() function pointers into a specialized version of __arm_v7s_unmap:

WARNING: modpost: vmlinux: section mismatch in reference: __arm_v7s_unmap+0x2cc (section: .text) -> dummy_tlb_add_page (section: .init.text)
ERROR: modpost: Section mismatches detected.

From what I can tell, the transformation is correct, as this is only called when __arm_v7s_unmap() is called from arm_v7s_do_selftests(), which is also __init. Since __arm_v7s_unmap() however is not __init, gcc cannot inline the inner function calls directly.

In debug_objects_selftest(), the same thing happens. Both the caller and the leaf function are __init, but the IPA pulls it into a non-init one:

WARNING: modpost: vmlinux: section mismatch in reference: lookup_object_or_alloc+0x7c (section: .text.lookup_object_or_alloc) -> is_static_object (section: .init.text)

Marking the affected functions as not "__init" would reliably avoid this issue but is not a good solution because it removes an otherwise correct annotation. I tried marking the functions as 'noinline', but that ended up not covering all the affected configurations.

With some more experimenting, I found that marking these functions as __attribute__((noipa)) is both logical and reliable.

In order to keep the syntax readable, add a custom macro for this in include/linux/compiler_attributes.h next to other related macros and use it to annotate both files.

---
v2: I merged both patches into one, to simplify the dependency on the new compiler_attributes.h macro.

---
 drivers/iommu/io-pgtable-arm-v7s.c  | 18 ++++++++++++------
 include/linux/compiler_attributes.h | 11 +++++++++++
 lib/debugobjects.c                  |  2 +-
 3 files changed, 24 insertions(+), 7 deletions(-)
drivers/iommu/io-pgtable-arm-v7s.c +12 -6
index 40e33257d3c2..1dbef8c55007 100644
@@ -777,21 +777,27 @@ struct io_pgtable_init_fns io_pgtable_arm_v7s_init_fns = {
 
 static struct io_pgtable_cfg *cfg_cookie __initdata;
 
-static void __init dummy_tlb_flush_all(void *cookie)
+/*
+ * __noipa prevents gcc from turning indirect iommu_flush_ops calls
+ * into direct calls from a specialized __arm_v7s_unmap() that triggers
+ * a build time section mismatch assertion.
+ */
+static __noipa void __init dummy_tlb_flush_all(void *cookie)
 {
 	WARN_ON(cookie != cfg_cookie);
 }
 
-static void __init dummy_tlb_flush(unsigned long iova, size_t size,
-				   size_t granule, void *cookie)
+static __noipa void __init dummy_tlb_flush(unsigned long iova, size_t size,
+					   size_t granule, void *cookie)
 {
 	WARN_ON(cookie != cfg_cookie);
 	WARN_ON(!(size & cfg_cookie->pgsize_bitmap));
 }
 
-static void __init dummy_tlb_add_page(struct iommu_iotlb_gather *gather,
-				      unsigned long iova, size_t granule,
-				      void *cookie)
+static __noipa void __init dummy_tlb_add_page(struct iommu_iotlb_gather *gather,
+					      unsigned long iova,
+					      size_t granule,
+					      void *cookie)
 {
 	dummy_tlb_flush(iova, granule, granule, cookie);
 }
include/linux/compiler_attributes.h +11 -0
index c16d4199bf92..836a50f5917a 100644
@@ -396,6 +396,17 @@
 # define __disable_sanitizer_instrumentation
 #endif
 
+/*
+ * Optional: not supported by clang
+ *
+ *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-noipa
+ */
+#if __has_attribute(noipa)
+# define __noipa __attribute__((noipa))
+#else
+# define __noipa
+#endif
+
 /*
  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-weak-function-attribute
  *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-weak-variable-attribute
lib/debugobjects.c +1 -1
index 12e2e42e6a31..c93b7ca3e1ab 100644
@@ -1212,7 +1212,7 @@ struct self_test {
 
 static __initconst const struct debug_obj_descr descr_type_test;
 
-static bool __init is_static_object(void *addr)
+static __noipa bool __init is_static_object(void *addr)
 {
 	struct self_test *obj = addr;
 
Signature · 1 line
2.39.5
Acked-by on v2 1/1
#1 lore raw
Quoted 7 lines · Arnd Bergmann

With some more experimenting, I found that marking these functions as __attribute__((noipa)) is both logical and reliable.

In order to keep the syntax readable, add a custom macro for this in include/linux/compiler_attributes.h next to other related macros and use it to annotate both files.

I double-checked that GCC 8.1 implemented the attribute in commit 036ea39917b0 ("attribs.c (decl_attributes): Imply noinline, noclone and no_icf attributes for noipa attribute."), which also happens to be our minimum in Linux; and that Clang indeed does not seem to support it (not even a mention of it in their repository).

If you don't mind, please add underscores (i.e. ((__noipa__))) and place it after __noinline__ to keep it sorted (the file is meant to be sorted by actual attribute name, though some entries were added that break that, but I will clean that and a couple other things up at some point).

Thanks!

Cheers,
Miguel

#2 lore raw
Quoted 10 lines · Miguel Ojeda
Quoted 7 lines · Arnd Bergmann

With some more experimenting, I found that marking these functions as __attribute__((noipa)) is both logical and reliable.

In order to keep the syntax readable, add a custom macro for this in include/linux/compiler_attributes.h next to other related macros and use it to annotate both files.

Thanks!

Quoted 5 lines

If you don't mind, please add underscores (i.e. ((__noipa__))) and place it after __noinline__ to keep it sorted (the file is meant to be sorted by actual attribute name, though some entries were added that break that, but I will clean that and a couple other things up at some point).

Ok, changed now, will wait for other comments before resending.

Arnd

#3 lore raw
In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

gcc-16 has gained some more advanced inter-procedual optimization techniques that enable it to inline the dummy_tlb_add_page() and dummy_tlb_flush() function pointers into a specialized version of __arm_v7s_unmap:

Quoted 7 lines

WARNING: modpost: vmlinux: section mismatch in reference: __arm_v7s_unmap+0x2cc (section: .text) -> dummy_tlb_add_page (section: .init.text)
ERROR: modpost: Section mismatches detected.

From what I can tell, the transformation is correct, as this is only called when __arm_v7s_unmap() is called from arm_v7s_do_selftests(), which is also __init. Since __arm_v7s_unmap() however is not __init, gcc cannot inline the inner function calls directly.

The selftests should be moved into a kunit like was done for pgtable-arm:

commit 699b059962add22b2a324645b6ae2a607fc1a93e

Author: Mostafa Saleh <[email protected]>
Date:   Mon Nov 3 12:33:50 2025 +0000

iommu/io-pgtable-arm: Move selftests to a separate file

Clean up the io-pgtable-arm library by moving the selftests out. Next the tests will be registered with kunit.

Then you won't have these section problems because the code will be in another module :)

Jason

maintainer Acked-by on v2 1/1
#4 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

---
v2: I merged both patches into one, to simplify the dependency on the new compiler_attributes.h macro.

Which you could have split into 'provide macro', fix A, fix B ..., but that's just pedantry :)

But seriously, this is way more palatable than the other hacks!

maintainer Acked-by on v2 1/1
#5 lore raw
In reply to Arnd Bergmann
Quoted 41 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

gcc-16 has gained some more advanced inter-procedual optimization techniques that enable it to inline the dummy_tlb_add_page() and dummy_tlb_flush() function pointers into a specialized version of __arm_v7s_unmap:

WARNING: modpost: vmlinux: section mismatch in reference: __arm_v7s_unmap+0x2cc (section: .text) -> dummy_tlb_add_page (section: .init.text)
ERROR: modpost: Section mismatches detected.

From what I can tell, the transformation is correct, as this is only called when __arm_v7s_unmap() is called from arm_v7s_do_selftests(), which is also __init. Since __arm_v7s_unmap() however is not __init, gcc cannot inline the inner function calls directly.

In debug_objects_selftest(), the same thing happens. Both the caller and the leaf function are __init, but the IPA pulls it into a non-init one:

WARNING: modpost: vmlinux: section mismatch in reference: lookup_object_or_alloc+0x7c (section: .text.lookup_object_or_alloc) -> is_static_object (section: .init.text)

Marking the affected functions as not "__init" would reliably avoid this issue but is not a good solution because it removes an otherwise correct annotation. I tried marking the functions as 'noinline', but that ended up not covering all the affected configurations.

With some more experimenting, I found that marking these functions as __attribute__((noipa)) is both logical and reliable.

In order to keep the syntax readable, add a custom macro for this in include/linux/compiler_attributes.h next to other related macros and use it to annotate both files.

Quoted 8 lines

---
v2: I merged both patches into one, to simplify the dependency on the new compiler_attributes.h macro.

---
 drivers/iommu/io-pgtable-arm-v7s.c  | 18 ++++++++++++------
 include/linux/compiler_attributes.h | 11 +++++++++++
 lib/debugobjects.c                  |  2 +-
 3 files changed, 24 insertions(+), 7 deletions(-)

For the io-pgtable change:

Thanks, Arnd.

Will