Skip to contentSkip to conversation

kernel-hacking: introduce CONFIG_NO_AUTO_INLINE

RFC PATCH In review Chen Linxuan 6 participants 18 messages Apr 29, 2025 – May 6, 2025

Subsystems (16)
Memory management x86 KVM Kbuild +12 more subsystems
lore
Share & tools
lore
#0 lore raw

v3 cover kernel-hacking: introduce CONFIG_NO_AUTO_INLINE

This series introduces a new kernel configuration option NO_AUTO_INLINE, which can be used to disable the automatic inlining of functions.

This will allow the function tracer to trace more functions because it only traces functions that the compiler has not inlined.

Previous discussions can be found at

This patch depends on

[PATCH] drm/i915/pxp: fix undefined reference to
`intel_pxp_gsccs_is_ready_for_sessions'

which can be found at

https://lore.kernel.org/all/[email protected]/

as well as

[RFC PATCH 5/7] RDMA/hns: initialize db in update_srq_db()

which can be found at

https://lore.kernel.org/all/FF922C77946229B6+20250411105459.90782-5-chenlinxuan@uniontech.com/

---
Changes in v3:
- Fix some modpost and objtool warnings
- Try support clang as Bart Van Assche suggested.
- Remove architecture depends as Bart Van Assche suggested.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Resend via b4 to correct Message-ID and recipients.
- Update commit message following suggestions from Jarkko Sakkinen
- Link to v1: https://lore.kernel.org/r/31F42D8141CDD2D0+20250411105142.89296-1-chenlinxuan@uniontech.com

---
Chen Linxuan (4):
rseq: add __always_inline for rseq_kernel_fields
kcov: add __always_inline for canonicalize_ip x86/xen: add __init for xen_pgd_walk lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE

Winston Wen (4):
nvme: add __always_inline for nvme_pci_npages_prp
mm: add __always_inline for page_contains_unaccepted vfio/virtio: add __always_inline for virtiovf_get_device_config_size
tpm: add __always_inline for tpm_is_hwrng_enabled

 Makefile                            | 16 ++++++++++++++++
 arch/x86/xen/mmu_pv.c               |  2 +-
 drivers/char/tpm/tpm-chip.c         |  2 +-
 drivers/nvme/host/pci.c             |  2 +-
 drivers/vfio/pci/virtio/legacy_io.c |  2 +-
 kernel/kcov.c                       |  2 +-
 kernel/rseq.c                       |  2 +-
 lib/Kconfig.debug                   | 21 +++++++++++++++++++++
 lib/Makefile                        |  3 +++
 mm/page_alloc.c                     |  2 +-
 10 files changed, 47 insertions(+), 7 deletions(-)

---
base-commit: ca91b9500108d4cf083a635c2e11c884d5dd20ea
change-id: 20250416-noautoinline-8e9b9e535452

Best regards,

Signature · 1 line
Chen Linxuan <[email protected]>
#1 lore raw

RFC PATCH v3 1/8 nvme: add __always_inline for nvme_pci_npages_prp

From: Winston Wen <[email protected]>

On x86_64 with gcc version 13.3.0, I build drivers/nvme/host/pci.c with:

  make defconfig
  ./scripts/kconfig/merge_config.sh .config <(
    echo CONFIG_BLK_DEV_NVME=m
  )
  make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once" \
    drivers/nvme/host/pci.o

Then I get a compile error:

CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC drivers/nvme/host/pci.o
In file included from <command-line>:
drivers/nvme/host/pci.c: In function 'nvme_init':
././include/linux/compiler_types.h:557:45: error: call to '__compiletime_assert_878' declared with attribute error: BUILD_BUG_ON failed: nvme_pci_npages_prp() > NVME_MAX_NR_ALLOCATIONS
557 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
././include/linux/compiler_types.h:538:25: note: in definition of macro '__compiletime_assert'

    538 |                         prefix ## suffix();                             \
        |                         ^~~~~~
  ././include/linux/compiler_types.h:557:9: note: in expansion of macro '_compiletime_assert'
    557 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
        |         ^~~~~~~~~~~~~~~~~~~
  ./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
     39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
        |                                     ^~~~~~~~~~~~~~~~~~
  ./include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     50 |         BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
        |         ^~~~~~~~~~~~~~~~
  drivers/nvme/host/pci.c:3804:9: note: in expansion of macro 'BUILD_BUG_ON'
   3804 |         BUILD_BUG_ON(nvme_pci_npages_prp() > NVME_MAX_NR_ALLOCATIONS);
        |         ^~~~~~~~~~~~

Mark nvme_pci_npages_prp() with __always_inline make it can be computed at compile time.

---
 drivers/nvme/host/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/pci.c +1 -1
index b178d52eac1b7f7286e217226b9b3686d07b7b6c..9ab070a9f0372bc6595c29a884ee9f2ffe5ae8e9 100644
@@ -390,7 +390,7 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, __le32 *dbbuf_db,
  * as it only leads to a small amount of wasted memory for the lifetime of
  * the I/O.
  */
-static int nvme_pci_npages_prp(void)
+static __always_inline int nvme_pci_npages_prp(void)
 {
 	unsigned max_bytes = (NVME_MAX_KB_SZ * 1024) + NVME_CTRL_PAGE_SIZE;
 	unsigned nprps = DIV_ROUND_UP(max_bytes, NVME_CTRL_PAGE_SIZE);
Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH v3 2/8 mm: add __always_inline for page_contains_unaccepted

In reply to Chen Linxuan

From: Winston Wen <[email protected]>

On x86_64 with gcc version 13.3.0, I compile mm/page_alloc.c with:

  make defconfig
  make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once" \
    mm/page_alloc.o

Then I get a compile error:

CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC mm/page_alloc.o
In file included from <command-line>:
mm/page_alloc.c: In function '__free_unaccepted.isra':
././include/linux/compiler_types.h:557:45: error: call to '__compiletime_assert_1013' declared with attribute error: BUILD_BUG failed
557 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
././include/linux/compiler_types.h:538:25: note: in definition of macro '__compiletime_assert'

    538 |                         prefix ## suffix();                             \
        |                         ^~~~~~
  ././include/linux/compiler_types.h:557:9: note: in expansion of macro '_compiletime_assert'
    557 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
        |         ^~~~~~~~~~~~~~~~~~~
  ./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
     39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
        |                                     ^~~~~~~~~~~~~~~~~~
  ./include/linux/build_bug.h:59:21: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
        |                     ^~~~~~~~~~~~~~~~
  mm/page_alloc.c:7301:9: note: in expansion of macro 'BUILD_BUG'
   7301 |         BUILD_BUG();
        |         ^~~~~~~~~

Marking page_contains_unaccepted with __always_inline and let dead code elimination remove reference to __free_unaccepted() here.

---
 mm/page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
index 5669baf2a6fea75c17b2be426443a6cf29051f52..433dc1936114469a323c8f3659730747965b2c3d 100644
@@ -7346,7 +7346,7 @@ static bool __free_unaccepted(struct page *page)
 
 #else
 
-static bool page_contains_unaccepted(struct page *page, unsigned int order)
+static __always_inline bool page_contains_unaccepted(struct page *page, unsigned int order)
 {
 	return false;
 }
Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH v3 3/8 vfio/virtio: add __always_inline for virtiovf_get_device_config_size

In reply to Chen Linxuan

From: Winston Wen <[email protected]>

Presume that kernel is compiled for x86_64 with gcc version 13.3.0:

  make defconfig
  ./scripts/kconfig/merge_config.sh .config <(
    echo CONFIG_VFIO=m
    echo CONFIG_VIRTIO_PCI=y
    echo CONFIG_VIRTIO_PCI_LIB_LEGACY=y
    echo CONFIG_VIRTIO_VFIO_PCI=m
    echo CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY=y
  )
  make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once" \
    drivers/vfio/pci/virtio/legacy_io.o

This results a compile error:

CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC drivers/vfio/pci/virtio/legacy_io.o
In file included from <command-line>:
drivers/vfio/pci/virtio/legacy_io.c: In function 'virtiovf_init_legacy_io':
././include/linux/compiler_types.h:557:45: error: call to '__compiletime_assert_889' declared with attribute error: BUILD_BUG_ON failed: !is_power_of_2(virtvdev->bar0_virtual_buf_size)
557 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
././include/linux/compiler_types.h:538:25: note: in definition of macro '__compiletime_assert'

    538 |                         prefix ## suffix();                             \
        |                         ^~~~~~
  ././include/linux/compiler_types.h:557:9: note: in expansion of macro '_compiletime_assert'
    557 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
        |         ^~~~~~~~~~~~~~~~~~~
  ./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
     39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
        |                                     ^~~~~~~~~~~~~~~~~~
  ./include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
     50 |         BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
        |         ^~~~~~~~~~~~~~~~
  drivers/vfio/pci/virtio/legacy_io.c:401:9: note: in expansion of macro 'BUILD_BUG_ON'
    401 |         BUILD_BUG_ON(!is_power_of_2(virtvdev->bar0_virtual_buf_size));
        |         ^~~~~~~~~~~~

BUILD_BUG_ON needs virtvdev->bar0_virtual_buf_size to be computed at compile time. So we should mark virtiovf_get_device_config_size() with __always_inline here.

---
 drivers/vfio/pci/virtio/legacy_io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/virtio/legacy_io.c +1 -1
index 832af5ba267c49a079009cfe0fa93c15ba7a490f..b6871d50b9f9e278ef3c49a9cb2baf474b8271c6 100644
@@ -350,7 +350,7 @@ int virtiovf_open_legacy_io(struct virtiovf_pci_core_device *virtvdev)
 	return virtiovf_set_notify_addr(virtvdev);
 }
 
-static int virtiovf_get_device_config_size(unsigned short device)
+static __always_inline int virtiovf_get_device_config_size(unsigned short device)
 {
 	/* Network card */
 	return offsetofend(struct virtio_net_config, status);
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH v3 4/8 tpm: add __always_inline for tpm_is_hwrng_enabled

In reply to Chen Linxuan

From: Winston Wen <[email protected]>

Presume that kernel is compiled for x86_64 with gcc version 13.3.0:

make defconfig
./scripts/kconfig/merge_config.sh .config <(
echo CONFIG_TCG_TPM=y
echo CONFIG_HW_RANDOM=m
)
make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once"

This results a link error:

ld: vmlinux.o: in function `tpm_add_hwrng':
tpm-chip.c:(.text+0x6c5924): undefined reference to `hwrng_register'
ld: vmlinux.o: in function `tpm_chip_unregister':
(.text+0x6c5bc9): undefined reference to `hwrng_unregister'
ld: vmlinux.o: in function `tpm_chip_register':
(.text+0x6c5c9b): undefined reference to `hwrng_unregister'

With CONFIG_TCG_TPM=y and CONFIG_HW_RANDOM=m,
the functions tpm_add_hwrng, tpm_chip_unregister, and tpm_chip_register are compiled into vmlinux.o
and reference the symbols hwrng_register and hwrng_unregister. These symbols, however, are compiled into rng-core.ko, which results in the linking error.

I am not sure but I think this weird linking error only arises when auto inlining is disabled because of some dead code elimination.

CONFIG_TCG_TPM=y and CONFIG_HW_RANDOM=m set CONFIG_HW_RANDOM_TPM=n. This causes the function tpm_is_hwrng_enabled to always return false, as shown below:

  static bool tpm_is_hwrng_enabled(struct tpm_chip *chip)
  {
      if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM))
          return false;
      if (tpm_is_firmware_upgrade(chip))
          return false;
      if (chip->flags & TPM_CHIP_FLAG_HWRNG_DISABLED)
          return false;
      return true;
  }

When tpm_is_hwrng_enabled is inlined, dead code elimination optimizations are applied and the reference to the hwrng_* functions will been removed.
For instance, in the tpm_chip_unregister function:

  void tpm_chip_unregister(struct tpm_chip *chip)
  {
  #ifdef CONFIG_TCG_TPM2_HMAC
      int rc;
      rc = tpm_try_get_ops(chip);
      if (!rc) {
          tpm2_end_auth_session(chip);
          tpm_put_ops(chip);
      }

#endif

      tpm_del_legacy_sysfs(chip);
      if (tpm_is_hwrng_enabled(chip))
          hwrng_unregister(&chip->hwrng);
      tpm_bios_log_teardown(chip);
      if (chip->flags & TPM_CHIP_FLAG_TPM2 && !tpm_is_firmware_upgrade(chip))
          tpm_devs_remove(chip);
      tpm_del_char_device(chip);

}

When tpm_is_hwrng_enabled is inlined and always returns false, the call to hwrng_unregister is effectively part of a if (false) block, which I guess that will be then optimized out.

However, when the -fno-inline-small-functions and -fno-inline-functions-called-once flags are used, tpm_is_hwrng_enabled is not inline.

And this optimization some how cannot occur, leading to the undefined reference errors during linking.

Adding the __always_inline attribute ensures that tpm_is_hwrng_enabled is inlined regardless of the compiler flags. This allows the dead code elimination to proceed as expected, resolving the linking issue.

---
 drivers/char/tpm/tpm-chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +1 -1
index e25daf2396d37bcaeae8a96267764df0861ad1be..48cc74d84247e258a39f2118e03aa10d0cbb066a 100644
@@ -534,7 +534,7 @@ static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
 	return tpm_get_random(chip, data, max);
 }
 
-static bool tpm_is_hwrng_enabled(struct tpm_chip *chip)
+static __always_inline bool tpm_is_hwrng_enabled(struct tpm_chip *chip)
 {
 	if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM))
 		return false;
Signature · 1 line
2.43.0
#5 lore raw

RFC PATCH v3 5/8 rseq: add __always_inline for rseq_kernel_fields

In reply to Chen Linxuan

Presume that kernel is compiled for x86_64 with gcc version 13.3.0:

make allmodconfig
make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once"

This results some objtool warnings:

vmlinux.o: warning: objtool: rseq_update_cpu_node_id+0x14c: call to rseq_kernel_fields() with UACCESS enabled vmlinux.o: warning: objtool: rseq_reset_rseq_cpu_node_id+0xef: call to rseq_kernel_fields() with UACCESS enabled

---
 kernel/rseq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rseq.c +1 -1
index b7a1ec327e8117b47e353cab92d62111dd261520..7a4b6c211359714087a753047581bc8ff0c6c76b 100644
@@ -27,7 +27,7 @@
 				  RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE)
 
 #ifdef CONFIG_DEBUG_RSEQ
-static struct rseq *rseq_kernel_fields(struct task_struct *t)
+static __always_inline struct rseq *rseq_kernel_fields(struct task_struct *t)
 {
 	return (struct rseq *) t->rseq_fields;
 }
Signature · 1 line
2.43.0
#6 lore raw

RFC PATCH v3 6/8 kcov: add __always_inline for canonicalize_ip

In reply to Chen Linxuan

Presume that kernel is compiled for x86_64 with gcc version 13.3.0:

make allmodconfig
make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once"

This results a objtool warning:

vmlinux.o: warning: objtool: __sanitizer_cov_trace_pc+0xc: call to canonicalize_ip() with UACCESS enabled

---
 kernel/kcov.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kcov.c +1 -1
index 187ba1b80bda169d2f7efead5c6076b8829522ca..a2e2d3c655406b5a1f53e4855c782727b0541935 100644
@@ -194,7 +194,7 @@ static notrace bool check_kcov_mode(enum kcov_mode needed_mode, struct task_stru
 	return mode == needed_mode;
 }
 
-static notrace unsigned long canonicalize_ip(unsigned long ip)
+static __always_inline notrace unsigned long canonicalize_ip(unsigned long ip)
 {
 #ifdef CONFIG_RANDOMIZE_BASE
 	ip -= kaslr_offset();
Signature · 1 line
2.43.0
#7 lore raw

RFC PATCH v3 7/8 x86/xen: add __init for xen_pgd_walk

In reply to Chen Linxuan

Presume that kernel is compiled for x86_64 with gcc version 13.3.0:

make allmodconfig
make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once"

This results a modpost warning:

WARNING: modpost: vmlinux: section mismatch in reference: xen_pgd_walk+0x42 (section: .text) -> xen_mark_pinned (section: .init.text)

As xen_pgd_walk is only referenced in xen_after_bootmem(void) which is also in .init.text, I add __init for xen_pgd_walk to fix this issue.

---
 arch/x86/xen/mmu_pv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/xen/mmu_pv.c +1 -1
index 38971c6dcd4b78b6b14f51bc69c4bf6b70ebd622..53650888be0a7b1dba170a5b7ba9c654244b5125 100644
@@ -696,7 +696,7 @@ static void __xen_pgd_walk(struct mm_struct *mm, pgd_t *pgd,
 	(*func)(mm, virt_to_page(pgd), PT_PGD);
 }
 
-static void xen_pgd_walk(struct mm_struct *mm,
+static void __init xen_pgd_walk(struct mm_struct *mm,
 			 void (*func)(struct mm_struct *mm, struct page *,
 				      enum pt_level),
 			 unsigned long limit)
Signature · 1 line
2.43.0
#8 lore raw

RFC PATCH v3 8/8 lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE

In reply to Chen Linxuan

Add a new kernel hacking option CONFIG_NO_AUTO_INLINE that prevents the compiler from auto-inlining functions not explicitly marked with the 'inline' keyword.

This enhancement improves function tracer capabilities as it can only trace functions that haven't been inlined by the compiler.

Previous discussions:

This patch is modified from commit 917fad29febd ("kernel hacking: add a config option to disable compiler auto-inlining") which can be founded in linux-next-history:

---
 Makefile          | 16 ++++++++++++++++
 lib/Kconfig.debug | 21 +++++++++++++++++++++
 lib/Makefile      |  3 +++
 3 files changed, 40 insertions(+)
Makefile +16 -0
index 5aa9ee52a765b7aed27f44028cdcc34a90979acb..60dec6c123543150a3332a9a819fa6933e94db4f 100644
@@ -1073,6 +1073,22 @@ endif
 # Ensure compilers do not transform certain loops into calls to wcslen()
 KBUILD_CFLAGS += -fno-builtin-wcslen
 
+ifdef CONFIG_NO_AUTO_INLINE
+# -fno-inline-functions behaves differently between gcc and clang.
+# With gcc, it prevents auto-inlining of functions but still considers functions
+# explicitly marked with "inline" for inlining. However, with clang, the flag
+# prevents inlining of all functions, including those explicitly marked with
+# inline. Clang provides the "-finline-hint-functions" option, which
+# specifically allows inlining of functions marked with "inline".
+#
+# In summary, to achieve equivalent behavior across compilers:
+# -fno-inline-functions (gcc) = -fno-inline-functions + -finline-hint-functions (clang)
+KBUILD_CFLAGS   += -fno-inline-functions \
+		   $(call cc-option, -finline-hint-functions) \
+		   $(call cc-option, -fno-inline-small-functions) \
+		   $(call cc-option, -fno-inline-functions-called-once)
+endif
+
 # change __FILE__ to the relative path to the source directory
 ifdef building_out_of_srctree
 KBUILD_CPPFLAGS += $(call cc-option,-ffile-prefix-map=$(srcroot)/=)
lib/Kconfig.debug +21 -0
index f9051ab610d54358b21d61c141b737bb345b4cee..56530f0145c885e9846dae1d2f8c6125c610d25b 100644
@@ -436,8 +436,29 @@ config GDB_SCRIPTS
 	  instance. See Documentation/process/debugging/gdb-kernel-debugging.rst
 	  for further details.
 
+
 endif # DEBUG_INFO
 
+config NO_AUTO_INLINE
+	bool "Disable compiler auto-inline optimizations (EXPERIMENTAL)"
+	default n
+	help
+	  This will prevent the compiler from optimizing the kernel by
+	  auto-inlining functions not marked with the inline keyword.
+	  With this option, only functions explicitly marked with
+	  "inline" will be inlined. This will allow the function tracer
+	  to trace more functions because it only traces functions that
+	  the compiler has not inlined.
+
+	  Note that Clang with -O2 optimization does not fully support
+	  disabling all inline-related optimizations,
+	  as Clang does not support options like
+	  -fno-inline-small-functions and -fno-inline-functions-called-once
+	  that gcc does.
+	  Some functions without the inline keyword may still be inlined.
+
+	  If unsure, select N.
+
 config FRAME_WARN
 	int "Warn for stack frames larger than"
 	range 0 8192
lib/Makefile +3 -0
index f07b24ce1b3f8db28796e461db1324d97133fdd5..2ac97f0856a12f66e6c3825af6aabafa61869262 100644
@@ -87,6 +87,9 @@ obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
 ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_KASAN),yy)
 # FIXME: Clang breaks test_bitmap_const_eval when KASAN and GCOV are enabled
 GCOV_PROFILE_test_bitmap.o := n
+# FIXME:
+# Clang breaks test_bitmap_const_eval when NO_AUTO_INLINE and KASAN are enabled
+CFLAGS_test_bitmap.o += -finline-functions
 endif
 
 obj-$(CONFIG_TEST_UUID) += test_uuid.o
Signature · 1 line
2.43.0
#9 lore raw

Re: [PATCH RFC v3 8/8] lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE

kernel test robot noticed the following build warnings:

Hi Chen,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on ca91b9500108d4cf083a635c2e11c884d5dd20ea]

url:    https://github.com/intel-lab-lkp/linux/commits/Chen-Linxuan-via-B4-Relay/nvme-add-__always_inline-for-nvme_pci_npages_prp/20250429-120709
base:   ca91b9500108d4cf083a635c2e11c884d5dd20ea
patch link:    https://lore.kernel.org/r/20250429-noautoinline-v3-8-4c49f28ea5b5%40uniontech.com
patch subject: [PATCH RFC v3 8/8] lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE

:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20250502/[email protected]/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250502/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> WARNING: modpost: vmlinux: section mismatch in reference: set_high_memory+0x0 (section: .text) -> memblock_end_of_DRAM (section: .init.text)

WARNING: modpost: vmlinux: section mismatch in reference: set_high_memory+0x4 (section: .text) -> memblock_end_of_DRAM (section: .init.text)

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#10 lore raw
In reply to Chen Linxuan
Quoted 5 lines · On Tue, Apr 29, 2025 at 12:06:04PM +0800, Chen Linxuan via B4 Relay wrote:

This series introduces a new kernel configuration option NO_AUTO_INLINE, which can be used to disable the automatic inlining of functions.

This will allow the function tracer to trace more functions because it only traces functions that the compiler has not inlined.

This still feels like a bad idea because it is extremely fragile.

#11 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · On Tue, Apr 29, 2025 at 12:06:04PM +0800, Chen Linxuan via B4 Relay wrote:

This series introduces a new kernel configuration option NO_AUTO_INLINE, which can be used to disable the automatic inlining of functions.

This will allow the function tracer to trace more functions because it only traces functions that the compiler has not inlined.

This still feels like a bad idea because it is extremely fragile.

Can you elaborate on that - does it introduce new fragility?

maintainer
#12 lore raw
Quoted 11 lines · Brendan Jackman
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · On Tue, Apr 29, 2025 at 12:06:04PM +0800, Chen Linxuan via B4 Relay wrote:

This series introduces a new kernel configuration option NO_AUTO_INLINE, which can be used to disable the automatic inlining of functions.

This will allow the function tracer to trace more functions because it only traces functions that the compiler has not inlined.

This still feels like a bad idea because it is extremely fragile.

Can you elaborate on that - does it introduce new fragility?

given it needs to sprinkle __always_inline around where it wasn't needed before, yeah.

Also, why would you want this? function tracer is already too much output. Why would you want even more?

#13 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Brendan Jackman
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · On Tue, Apr 29, 2025 at 12:06:04PM +0800, Chen Linxuan via B4 Relay wrote:

This series introduces a new kernel configuration option NO_AUTO_INLINE, which can be used to disable the automatic inlining of functions.

This will allow the function tracer to trace more functions because it only traces functions that the compiler has not inlined.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

This still feels like a bad idea because it is extremely fragile.

Can you elaborate on that - does it introduce new fragility?

given it needs to sprinkle __always_inline around where it wasn't needed before, yeah.

Right, I guess I just wouldn't have associated that with the word "fragility", but that's a reasonable complaint!

Quoted 2 lines

Also, why would you want this? function tracer is already too much output. Why would you want even more?

Yes, tracing every function is already too noisy, this would make it even more too-noisy, not sure "too noisy" -> "way too noisy" is a particularly meaningful degradation.

Whereas enlarging the pool of functions that you can _optionally target_ for tracing, or nice reliable breakpoints in GDB, and disasm that's easier to mentally map back to C, seems like a helpful improvement for test builds. Personally I sometimes spam a bunch of noinline into code I'm debugging so this seems like a way to just slap that same thing on the whole tree without dirtying the code, right?

Not that I have a strong opinion on the cost/benefit here, but the benefit seems nonzero to me.

maintainer
#14 lore raw
Quoted 6 lines · Brendan Jackman

Whereas enlarging the pool of functions that you can _optionally target_ for tracing, or nice reliable breakpoints in GDB, and disasm that's easier to mentally map back to C, seems like a helpful improvement for test builds. Personally I sometimes spam a bunch of noinline into code I'm debugging so this seems like a way to just slap that same thing on the whole tree without dirtying the code, right?

Dunno, I'm more of the printk school of debugging. Very rarely do I bother with GDB (so rare in fact that I have to look up how to even do this).

#15 lore raw
In reply to Brendan Jackman
Quoted 3 lines · Brendan Jackman

Personally I sometimes spam a bunch of noinline into code I'm debugging so this seems like a way to just slap that same thing on the whole tree without dirtying the code, right?

If this is for test builds only, has it been consider to add -fno-inline-functions as a local change in the top-level Makefile?

Bart.

#16 lore raw
Quoted 2 lines · Bart Van Assche

If this is for test builds only, has it been consider to add -fno-inline-functions as a local change in the top-level Makefile?

The issue here is that the current kernel cannot be compiled when these compiler options that reduce inlining behavior are added.

#17 lore raw
In reply to Christoph Hellwig
Quoted 9 lines · On Tue, 29 Apr 2025 14:35:04 +0200 Christoph Hellwig wrote:
Quoted 5 lines · On Tue, Apr 29, 2025 at 12:06:04PM +0800, Chen Linxuan via B4 Relay wrote:

This series introduces a new kernel configuration option NO_AUTO_INLINE, which can be used to disable the automatic inlining of functions.

This will allow the function tracer to trace more functions because it only traces functions that the compiler has not inlined.

This still feels like a bad idea because it is extremely fragile.

I'm not entirely sure if we're on the same page regarding this issue. However, I'd like to address the concerns about the fragility of NO_AUTO_INLINE.

Maintaining NO_AUTO_INLINE to function correctly is indeed challenging, and I share some reservations about whether it should exist as a Kbuild option, which is precisely why this patch series is submitted as an RFC.
I cannot even guarantee that I've addressed all existing issues in the current kernel repository with this patch series, as testing all possible compilation configurations is beyond my capabilities.

Looking at the functions where I've added __always_inline in this patch series, nearly all of them require inlining specifically because their calls need to be resolved at compile time.

The fundamental source of this fragility stems from the fact that compiler auto-inlining decisions aren't well-defined. If these functions were to change in the future for unrelated reasons - for example, if they became longer - and the compiler consequently decided not to automatically inline them, these same issues would surface regardless.