Skip to contentSkip to conversation

+ errh-use-__always_inline-on-all-error-pointer-helpers.patch added to mm-nonmm-unstable branch

PATCH Andrew Morton 4 participants 5 messages May 26 – Jun 12 Stable branch

lore
Share & tools
lore

Andrew Morton

author tree notice
#0 lore raw

The patch titled
Subject: err.h: use __always_inline on all error pointer helpers
has been added to the -mm mm-nonmm-unstable branch. Its filename is
errh-use-__always_inline-on-all-error-pointer-helpers.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/errh-use-__always_inline-on-all-error-pointer-helpers.patch

This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Arnd Bergmann <[email protected]>
Subject: err.h: use __always_inline on all error pointer helpers
Date: Tue, 26 May 2026 12:18:41 +0200

While testing randconfig builds on s390, I came across a link failure with CONFIG_DMA_SHARED_BUFFER disabled:

ERROR: modpost: "dma_buf_put" [drivers/iommu/iommufd/iommufd.ko] undefined!

The problem here is that IS_ERR() is not inlined and dead code elimination fails as a consequence.

The err.h helpers all turn into a trivial assignment of a bit mask and should never result in a function call, so force them to always be inline. This should generally result in better object code aside from avoiding the link failure above.

---

 include/linux/err.h |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/linux/err.h renamed from include/linux/err.h~errh-use-__always_inline-on-all-error-pointer-helpers +6 -6
@@ -36,7 +36,7 @@
  *
  * Return: A pointer with @error encoded within its value.
  */
-static inline void * __must_check ERR_PTR(long error)
+static __always_inline void * __must_check ERR_PTR(long error)
 {
 	return (void *) error;
 }
@@ -60,7 +60,7 @@ static inline void * __must_check ERR_PT
  * @ptr: An error pointer.
  * Return: The error code within @ptr.
  */
-static inline long __must_check PTR_ERR(__force const void *ptr)
+static __always_inline long __must_check PTR_ERR(__force const void *ptr)
 {
 	return (long) ptr;
 }
@@ -73,7 +73,7 @@ static inline long __must_check PTR_ERR(
  * @ptr: The pointer to check.
  * Return: true if @ptr is an error pointer, false otherwise.
  */
-static inline bool __must_check IS_ERR(__force const void *ptr)
+static __always_inline bool __must_check IS_ERR(__force const void *ptr)
 {
 	return IS_ERR_VALUE((unsigned long)ptr);
 }
@@ -87,7 +87,7 @@ static inline bool __must_check IS_ERR(_
  *
  * Like IS_ERR(), but also returns true for a null pointer.
  */
-static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
+static __always_inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
 {
 	return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
 }
@@ -99,7 +99,7 @@ static inline bool __must_check IS_ERR_O
  * Explicitly cast an error-valued pointer to another pointer type in such a
  * way as to make it clear that's what's going on.
  */
-static inline void * __must_check ERR_CAST(__force const void *ptr)
+static __always_inline void * __must_check ERR_CAST(__force const void *ptr)
 {
 	/* cast away the const */
 	return (void *) ptr;
@@ -122,7 +122,7 @@ static inline void * __must_check ERR_CA
  *
  * Return: The error code within @ptr if it is an error pointer; 0 otherwise.
  */
-static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
+static __always_inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
 {
 	if (IS_ERR(ptr))
 		return PTR_ERR(ptr);

_

Patches currently in -mm which might be from [email protected] are

inith-discard-exitcall-symbols-early.patch errh-use-__always_inline-on-all-error-pointer-helpers.patch

#1 lore raw
Quoted 7 lines · Andrew Morton

The patch titled
Subject: err.h: use __always_inline on all error pointer helpers
has been added to the -mm mm-nonmm-unstable branch. Its filename is
errh-use-__always_inline-on-all-error-pointer-helpers.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/errh-use-__always_inline-on-all-error-pointer-helpers.patch

Petr, shouldn't this also fix the problem with old (buggy) GCC for xtensa (IIRC) that we encountered in some tests a couple of months ago?

Quoted 91 lines

------------------------------------------------------
From: Arnd Bergmann <[email protected]>
Subject: err.h: use __always_inline on all error pointer helpers
Date: Tue, 26 May 2026 12:18:41 +0200

While testing randconfig builds on s390, I came across a link failure with CONFIG_DMA_SHARED_BUFFER disabled:

ERROR: modpost: "dma_buf_put" [drivers/iommu/iommufd/iommufd.ko] undefined!

The problem here is that IS_ERR() is not inlined and dead code elimination fails as a consequence.

The err.h helpers all turn into a trivial assignment of a bit mask and should never result in a function call, so force them to always be inline. This should generally result in better object code aside from avoiding the link failure above.

---

 include/linux/err.h |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/linux/err.h renamed from include/linux/err.h~errh-use-__always_inline-on-all-error-pointer-helpers +6 -6
@@ -36,7 +36,7 @@
  *
  * Return: A pointer with @error encoded within its value.
  */
-static inline void * __must_check ERR_PTR(long error)
+static __always_inline void * __must_check ERR_PTR(long error)
 {
 	return (void *) error;
 }
@@ -60,7 +60,7 @@ static inline void * __must_check ERR_PT
  * @ptr: An error pointer.
  * Return: The error code within @ptr.
  */
-static inline long __must_check PTR_ERR(__force const void *ptr)
+static __always_inline long __must_check PTR_ERR(__force const void *ptr)
 {
 	return (long) ptr;
 }
@@ -73,7 +73,7 @@ static inline long __must_check PTR_ERR(
  * @ptr: The pointer to check.
  * Return: true if @ptr is an error pointer, false otherwise.
  */
-static inline bool __must_check IS_ERR(__force const void *ptr)
+static __always_inline bool __must_check IS_ERR(__force const void *ptr)
 {
 	return IS_ERR_VALUE((unsigned long)ptr);
 }
@@ -87,7 +87,7 @@ static inline bool __must_check IS_ERR(_
  *
  * Like IS_ERR(), but also returns true for a null pointer.
  */
-static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
+static __always_inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
 {
 	return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
 }
@@ -99,7 +99,7 @@ static inline bool __must_check IS_ERR_O
  * Explicitly cast an error-valued pointer to another pointer type in such a
  * way as to make it clear that's what's going on.
  */
-static inline void * __must_check ERR_CAST(__force const void *ptr)
+static __always_inline void * __must_check ERR_CAST(__force const void *ptr)
 {
 	/* cast away the const */
 	return (void *) ptr;
@@ -122,7 +122,7 @@ static inline void * __must_check ERR_CA
  *
  * Return: The error code within @ptr if it is an error pointer; 0 otherwise.
  */
-static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
+static __always_inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
 {
 	if (IS_ERR(ptr))
 		return PTR_ERR(ptr);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw

Adding Tamir into Cc.

Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Andrew Morton

The patch titled
Subject: err.h: use __always_inline on all error pointer helpers
has been added to the -mm mm-nonmm-unstable branch. Its filename is
errh-use-__always_inline-on-all-error-pointer-helpers.patch

Quoted 5 lines
Quoted 2 lines

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/errh-use-__always_inline-on-all-error-pointer-helpers.patch

Petr, shouldn't this also fix the problem with old (buggy) GCC for xtensa (IIRC) that we encountered in some tests a couple of months ago?

It might here there as well. Unfortunately, I could not test it easily because it required some old GCC.

I wonder if Tamir could try to revert the commit 8901ac9d2c7eb8ed ("printf: Compile the kunit test with DISABLE_BRANCH_PROFILING") and try this patch instead.

Best Regards,
Petr

Quoted 96 lines
Quoted 91 lines

------------------------------------------------------
From: Arnd Bergmann <[email protected]>
Subject: err.h: use __always_inline on all error pointer helpers
Date: Tue, 26 May 2026 12:18:41 +0200

While testing randconfig builds on s390, I came across a link failure with CONFIG_DMA_SHARED_BUFFER disabled:

ERROR: modpost: "dma_buf_put" [drivers/iommu/iommufd/iommufd.ko] undefined!

The problem here is that IS_ERR() is not inlined and dead code elimination fails as a consequence.

The err.h helpers all turn into a trivial assignment of a bit mask and should never result in a function call, so force them to always be inline. This should generally result in better object code aside from avoiding the link failure above.

---

 include/linux/err.h |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/linux/err.h renamed from include/linux/err.h~errh-use-__always_inline-on-all-error-pointer-helpers +6 -6
@@ -36,7 +36,7 @@
  *
  * Return: A pointer with @error encoded within its value.
  */
-static inline void * __must_check ERR_PTR(long error)
+static __always_inline void * __must_check ERR_PTR(long error)
 {
 	return (void *) error;
 }
@@ -60,7 +60,7 @@ static inline void * __must_check ERR_PT
  * @ptr: An error pointer.
  * Return: The error code within @ptr.
  */
-static inline long __must_check PTR_ERR(__force const void *ptr)
+static __always_inline long __must_check PTR_ERR(__force const void *ptr)
 {
 	return (long) ptr;
 }
@@ -73,7 +73,7 @@ static inline long __must_check PTR_ERR(
  * @ptr: The pointer to check.
  * Return: true if @ptr is an error pointer, false otherwise.
  */
-static inline bool __must_check IS_ERR(__force const void *ptr)
+static __always_inline bool __must_check IS_ERR(__force const void *ptr)
 {
 	return IS_ERR_VALUE((unsigned long)ptr);
 }
@@ -87,7 +87,7 @@ static inline bool __must_check IS_ERR(_
  *
  * Like IS_ERR(), but also returns true for a null pointer.
  */
-static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
+static __always_inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
 {
 	return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
 }
@@ -99,7 +99,7 @@ static inline bool __must_check IS_ERR_O
  * Explicitly cast an error-valued pointer to another pointer type in such a
  * way as to make it clear that's what's going on.
  */
-static inline void * __must_check ERR_CAST(__force const void *ptr)
+static __always_inline void * __must_check ERR_CAST(__force const void *ptr)
 {
 	/* cast away the const */
 	return (void *) ptr;
@@ -122,7 +122,7 @@ static inline void * __must_check ERR_CA
  *
  * Return: The error code within @ptr if it is an error pointer; 0 otherwise.
  */
-static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
+static __always_inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
 {
 	if (IS_ERR(ptr))
 		return PTR_ERR(ptr);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 17 lines · Petr Mladek

Adding Tamir into Cc.

Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Andrew Morton

The patch titled
Subject: err.h: use __always_inline on all error pointer helpers
has been added to the -mm mm-nonmm-unstable branch. Its filename is
errh-use-__always_inline-on-all-error-pointer-helpers.patch

Quoted 5 lines
Quoted 2 lines

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/errh-use-__always_inline-on-all-error-pointer-helpers.patch

Petr, shouldn't this also fix the problem with old (buggy) GCC for xtensa (IIRC) that we encountered in some tests a couple of months ago?

Quoted 6 lines

It might here there as well. Unfortunately, I could not test it easily because it required some old GCC.

I wonder if Tamir could try to revert the commit 8901ac9d2c7eb8ed ("printf: Compile the kunit test with DISABLE_BRANCH_PROFILING") and try this patch instead.

Yes, confirmed.

I rebuilt xtensa-linux GCC 8.5.0 and tested printf_kunit.c with the original randconfig and branch profiling enabled, without DISABLE_BRANCH_PROFILING.

Without Arnd's patch, the original failure reproduces:

printf_kunit.c: In function 'errptr.part.2': error: call to '__compiletime_assert_313' declared with attribute error: BUILD_BUG_ON failed:
IS_ERR(PTR)

With "err.h: use __always_inline on all error pointer helpers" applied, the same compile succeeds.

So Arnd's patch fixes this case and commit 8901ac9d2c7e ("printf: Compile the kunit test with DISABLE_BRANCH_PROFILING") can be reverted once it lands.

#4 lore raw
Quoted 36 lines · Tamir Duberstein
Quoted 17 lines · Petr Mladek

Adding Tamir into Cc.

Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Andrew Morton

The patch titled
Subject: err.h: use __always_inline on all error pointer helpers
has been added to the -mm mm-nonmm-unstable branch. Its filename is
errh-use-__always_inline-on-all-error-pointer-helpers.patch

Quoted 5 lines
Quoted 2 lines

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/errh-use-__always_inline-on-all-error-pointer-helpers.patch

Petr, shouldn't this also fix the problem with old (buggy) GCC for xtensa (IIRC) that we encountered in some tests a couple of months ago?

Quoted 6 lines

It might here there as well. Unfortunately, I could not test it easily because it required some old GCC.

I wonder if Tamir could try to revert the commit 8901ac9d2c7eb8ed ("printf: Compile the kunit test with DISABLE_BRANCH_PROFILING") and try this patch instead.

Yes, confirmed.

I rebuilt xtensa-linux GCC 8.5.0 and tested printf_kunit.c with the original randconfig and branch profiling enabled, without DISABLE_BRANCH_PROFILING.

Without Arnd's patch, the original failure reproduces:

printf_kunit.c: In function 'errptr.part.2': error: call to '__compiletime_assert_313' declared with attribute error: BUILD_BUG_ON failed:
IS_ERR(PTR)

Quoted 5 lines

With "err.h: use __always_inline on all error pointer helpers" applied, the same compile succeeds.

So Arnd's patch fixes this case and commit 8901ac9d2c7e ("printf: Compile the kunit test with DISABLE_BRANCH_PROFILING") can be reverted once it lands.

Great. Thank you both for pointing it out and testing it!

It seems that it is not in the Linus' tree yet. I guess that it will appear in the 7.2 merge window, ... I set up reminder to myself.

Best Regards,
Petr