Skip to contentSkip to conversation

kernel-hacking: introduce CONFIG_NO_AUTO_INLINE

RFC PATCH Applied Chen Linxuan 4 participants 15 messages Apr 11, 2025 – Apr 15, 2025 1 message not in the archive

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

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 here:

Chen Linxuan (2):
drm/i915/pxp: fix undefined reference to
`intel_pxp_gsccs_is_ready_for_sessions'
RDMA/hns: initialize db in update_srq_db()

Winston Wen (5):
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 lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE

 Makefile                                   |  6 ++++++
 drivers/char/tpm/tpm-chip.c                |  2 +-
 drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h |  8 ++++++--
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c |  2 +-
 drivers/nvme/host/pci.c                    |  2 +-
 drivers/vfio/pci/virtio/legacy_io.c        |  2 +-
 lib/Kconfig.debug                          | 15 +++++++++++++++
 mm/page_alloc.c                            |  2 +-
 8 files changed, 32 insertions(+), 7 deletions(-)
Signature · 1 line
2.48.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

RFC PATCH 2/7 mm: add __always_inline for page_contains_unaccepted

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();
        |         ^~~~~~~~~
---
 mm/page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
index fd6b865cb1ab..7c0934c818dd 100644
@@ -7286,7 +7286,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.48.1
#3 lore raw

RFC PATCH 3/7 vfio/virtio: add __always_inline for virtiovf_get_device_config_size

In reply to a message not in the archive

From: Winston Wen <[email protected]>

On x86_64 with gcc version 13.3.0, I compile
drivers/vfio/pci/virtio/legacy_io.c with:

  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

Then I get 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));
        |         ^~~~~~~~~~~~
---
 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 832af5ba267c..b6871d50b9f9 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.48.1
#4 lore raw

RFC PATCH 4/7 drm/i915/pxp: fix undefined reference to `intel_pxp_gsccs_is_ready_for_sessions'

In reply to a message not in the archive

On x86_64 with gcc version 13.3.0, I compile kernel with:

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

Then I get a linker error:

ld: vmlinux.o: in function `pxp_fw_dependencies_completed':
kintel_pxp.c:(.text+0x95728f): undefined reference to `intel_pxp_gsccs_is_ready_for_sessions'

---
 drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h +6 -2
index 9aae779c4da3..4969d3de2bac 100644
@@ -23,6 +23,7 @@ int intel_pxp_gsccs_init(struct intel_pxp *pxp);
 
 int intel_pxp_gsccs_create_session(struct intel_pxp *pxp, int arb_session_id);
 void intel_pxp_gsccs_end_arb_fw_session(struct intel_pxp *pxp, u32 arb_session_id);
+bool intel_pxp_gsccs_is_ready_for_sessions(struct intel_pxp *pxp);
 
 #else
 static inline void intel_pxp_gsccs_fini(struct intel_pxp *pxp)
@@ -34,8 +35,11 @@ static inline int intel_pxp_gsccs_init(struct intel_pxp *pxp)
 	return 0;
 }
 
-#endif
+static inline bool intel_pxp_gsccs_is_ready_for_sessions(struct intel_pxp *pxp)
+{
+	return false;
+}
 
-bool intel_pxp_gsccs_is_ready_for_sessions(struct intel_pxp *pxp);
+#endif
 
 #endif /*__INTEL_PXP_GSCCS_H__ */
Signature · 1 line
2.48.1
maintainer Reviewed-by on v1 4/7
#5 lore raw

Re: [RFC PATCH 4/7] drm/i915/pxp: fix undefined reference to `intel_pxp_gsccs_is_ready_for_sessions'

Quoted 7 lines · Chen Linxuan

On x86_64 with gcc version 13.3.0, I compile kernel with:

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

The change looks good, but I'm guessing the real explanation is that you have CONFIG_DRM_I915_PXP=n and that appears to be broken.

Fixes 99afb7cc8c44 ("drm/i915/pxp: Add ARB session creation and cleanup")

But how do you want this merged?

BR,
Jani.

Quoted 37 lines

Then I get a linker error:

ld: vmlinux.o: in function `pxp_fw_dependencies_completed':
kintel_pxp.c:(.text+0x95728f): undefined reference to `intel_pxp_gsccs_is_ready_for_sessions'

---
 drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h +6 -2
index 9aae779c4da3..4969d3de2bac 100644
@@ -23,6 +23,7 @@ int intel_pxp_gsccs_init(struct intel_pxp *pxp);
 
 int intel_pxp_gsccs_create_session(struct intel_pxp *pxp, int arb_session_id);
 void intel_pxp_gsccs_end_arb_fw_session(struct intel_pxp *pxp, u32 arb_session_id);
+bool intel_pxp_gsccs_is_ready_for_sessions(struct intel_pxp *pxp);
 
 #else
 static inline void intel_pxp_gsccs_fini(struct intel_pxp *pxp)
@@ -34,8 +35,11 @@ static inline int intel_pxp_gsccs_init(struct intel_pxp *pxp)
 	return 0;
 }
 
-#endif
+static inline bool intel_pxp_gsccs_is_ready_for_sessions(struct intel_pxp *pxp)
+{
+	return false;
+}
 
-bool intel_pxp_gsccs_is_ready_for_sessions(struct intel_pxp *pxp);
+#endif
 
 #endif /*__INTEL_PXP_GSCCS_H__ */
Signature · 1 line
Jani Nikula, Intel
#6 lore raw

Re: [RFC PATCH 4/7] drm/i915/pxp: fix undefined reference to `intel_pxp_gsccs_is_ready_for_sessions'

Quoted 10 lines · Jani Nikula <[email protected]> 于2025年4月15日周二 15:59写道:
Quoted 7 lines · Chen Linxuan

On x86_64 with gcc version 13.3.0, I compile kernel with:

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

Quoted 8 lines

The change looks good, but I'm guessing the real explanation is that you have CONFIG_DRM_I915_PXP=n and that appears to be broken.

Fixes 99afb7cc8c44 ("drm/i915/pxp: Add ARB session creation and cleanup")

But how do you want this merged?

As patch 5 has been merged into rdma-next, I think it's OK to merge this single patch into your tree.

Quoted 46 lines

BR,
Jani.

Quoted 27 lines

Then I get a linker error:

ld: vmlinux.o: in function `pxp_fw_dependencies_completed':
kintel_pxp.c:(.text+0x95728f): undefined reference to `intel_pxp_gsccs_is_ready_for_sessions'

---
 drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h +1 -0
index 9aae779c4da3..4969d3de2bac 100644
@@ -23,6 +23,7 @@ int intel_pxp_gsccs_init(struct intel_pxp *pxp);
 
 int intel_pxp_gsccs_create_session(struct intel_pxp *pxp, int arb_session_id);
 void intel_pxp_gsccs_end_arb_fw_session(struct intel_pxp *pxp, u32 arb_session_id);
+bool intel_pxp_gsccs_is_ready_for_sessions(struct intel_pxp *pxp);
 
 #else
 static inline void intel_pxp_gsccs_fini(struct intel_pxp *pxp)
@@ -34,8 +35,11 @@ static inline int intel_pxp_gsccs_init(struct intel_pxp *pxp)
      return 0;
 }
 

drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h static inline int intel_pxp_gsccs_init(struct intel_pxp *pxp) · line 45

Quoted 10 lines
drivers/gpu/drm/i915/pxp/intel_pxp_gsccs.h +5 -2
-#endif
+static inline bool intel_pxp_gsccs_is_ready_for_sessions(struct intel_pxp *pxp)
+{
+     return false;
+}
 
-bool intel_pxp_gsccs_is_ready_for_sessions(struct intel_pxp *pxp);
+#endif
 
 #endif /*__INTEL_PXP_GSCCS_H__ */

--
Jani Nikula, Intel

maintainer
#7 lore raw

Re: [RFC PATCH 4/7] drm/i915/pxp: fix undefined reference to `intel_pxp_gsccs_is_ready_for_sessions'

Quoted 14 lines · Chen Linxuan
Quoted 13 lines · Jani Nikula <[email protected]> 于2025年4月15日周二 15:59写道:
Quoted 7 lines · Chen Linxuan

On x86_64 with gcc version 13.3.0, I compile kernel with:

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

The change looks good, but I'm guessing the real explanation is that you have CONFIG_DRM_I915_PXP=n and that appears to be broken.

Quoted 8 lines
Quoted 5 lines
Fixes 99afb7cc8c44 ("drm/i915/pxp: Add ARB session creation and cleanup")

But how do you want this merged?

As patch 5 has been merged into rdma-next, I think it's OK to merge this single patch into your tree.

Thanks. I amended the commit message a little, and resent this to intel-gfx [1], and will merge it via drm-intel-next.

BR,
Jani.

[1] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Jani Nikula, Intel
#8 lore raw

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

In reply to a message not in the archive

On x86_64 with gcc version 13.3.0, I compile
drivers/infiniband/hw/hns/hns_roce_hw_v2.c with:

  make defconfig
  ./scripts/kconfig/merge_config.sh .config <(
    echo CONFIG_COMPILE_TEST=y
    echo CONFIG_HNS3=m
    echo CONFIG_INFINIBAND=m
    echo CONFIG_INFINIBAND_HNS_HIP08=m
  )
  make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once" \
    drivers/infiniband/hw/hns/hns_roce_hw_v2.o

Then I get a compile error:

CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC [M] drivers/infiniband/hw/hns/hns_roce_hw_v2.o
In file included from drivers/infiniband/hw/hns/hns_roce_hw_v2.c:47:
drivers/infiniband/hw/hns/hns_roce_hw_v2.c: In function 'update_srq_db':
drivers/infiniband/hw/hns/hns_roce_common.h:74:17: error: 'db' is used uninitialized [-Werror=uninitialized]

     74 |                 *((__le32 *)_ptr + (field_h) / 32) &=                          \
        |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  drivers/infiniband/hw/hns/hns_roce_common.h:90:17: note: in expansion of macro '_hr_reg_clear'
     90 |                 _hr_reg_clear(ptr, field_type, field_h, field_l);              \
        |                 ^~~~~~~~~~~~~
  drivers/infiniband/hw/hns/hns_roce_common.h:95:39: note: in expansion of macro '_hr_reg_write'
     95 | #define hr_reg_write(ptr, field, val) _hr_reg_write(ptr, field, val)
        |                                       ^~~~~~~~~~~~~
  drivers/infiniband/hw/hns/hns_roce_hw_v2.c:948:9: note: in expansion of macro 'hr_reg_write'
    948 |         hr_reg_write(&db, DB_TAG, srq->srqn);
        |         ^~~~~~~~~~~~
  drivers/infiniband/hw/hns/hns_roce_hw_v2.c:946:31: note: 'db' declared here
    946 |         struct hns_roce_v2_db db;
        |                               ^~

cc1: all warnings being treated as errors

---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +1 -1
index 160e8927d364..7d6c0cfa1ded 100644
@@ -943,7 +943,7 @@ static void fill_wqe_idx(struct hns_roce_srq *srq, unsigned int wqe_idx)
 static void update_srq_db(struct hns_roce_srq *srq)
 {
 	struct hns_roce_dev *hr_dev = to_hr_dev(srq->ibsrq.device);
-	struct hns_roce_v2_db db;
+	struct hns_roce_v2_db db = { 0 };
 
 	hr_reg_write(&db, DB_TAG, srq->srqn);
 	hr_reg_write(&db, DB_CMD, HNS_ROCE_V2_SRQ_DB);
Signature · 1 line
2.48.1
#9 lore raw

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

Quoted 36 lines · Chen Linxuan

On x86_64 with gcc version 13.3.0, I compile
drivers/infiniband/hw/hns/hns_roce_hw_v2.c with:

  make defconfig
  ./scripts/kconfig/merge_config.sh .config <(
    echo CONFIG_COMPILE_TEST=y
    echo CONFIG_HNS3=m
    echo CONFIG_INFINIBAND=m
    echo CONFIG_INFINIBAND_HNS_HIP08=m
  )
  make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once" \
    drivers/infiniband/hw/hns/hns_roce_hw_v2.o

Then I get a compile error:

CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC [M] drivers/infiniband/hw/hns/hns_roce_hw_v2.o
In file included from drivers/infiniband/hw/hns/hns_roce_hw_v2.c:47:
drivers/infiniband/hw/hns/hns_roce_hw_v2.c: In function 'update_srq_db':
drivers/infiniband/hw/hns/hns_roce_common.h:74:17: error: 'db' is used uninitialized [-Werror=uninitialized]

     74 |                 *((__le32 *)_ptr + (field_h) / 32) &=                          \
        |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  drivers/infiniband/hw/hns/hns_roce_common.h:90:17: note: in expansion of macro '_hr_reg_clear'
     90 |                 _hr_reg_clear(ptr, field_type, field_h, field_l);              \
        |                 ^~~~~~~~~~~~~
  drivers/infiniband/hw/hns/hns_roce_common.h:95:39: note: in expansion of macro '_hr_reg_write'
     95 | #define hr_reg_write(ptr, field, val) _hr_reg_write(ptr, field, val)
        |                                       ^~~~~~~~~~~~~
  drivers/infiniband/hw/hns/hns_roce_hw_v2.c:948:9: note: in expansion of macro 'hr_reg_write'
    948 |         hr_reg_write(&db, DB_TAG, srq->srqn);
        |         ^~~~~~~~~~~~
  drivers/infiniband/hw/hns/hns_roce_hw_v2.c:946:31: note: 'db' declared here
    946 |         struct hns_roce_v2_db db;
        |                               ^~
Quoted 8 lines

cc1: all warnings being treated as errors

---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to rdma-next.

Thanks

#10 lore raw

RFC PATCH 6/7 tpm: add __always_inline for tpm_is_hwrng_enabled

In reply to a message not in the archive

From: Winston Wen <[email protected]>

On x86_64 with gcc version 13.3.0, I compile kernel with:

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"

Then I get 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'

---
 drivers/char/tpm/tpm-chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +1 -1
index e25daf2396d3..48cc74d84247 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.48.1
maintainer
#11 lore raw

Re: [RFC PATCH 6/7] tpm: add __always_inline for tpm_is_hwrng_enabled

Quoted 3 lines · Chen Linxuan

From: Winston Wen <[email protected]>

On x86_64 with gcc version 13.3.0, I compile kernel with:

Use passive:

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

Quoted 9 lines

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"

Then I get a link error:

"This results a link error:"

Quoted 7 lines

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'

The resolution is lacking i.e., why adding __always_inline addresses the linking problem.

Quoted 24 lines
---
 drivers/char/tpm/tpm-chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +1 -1
index e25daf2396d3..48cc74d84247 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.48.1

BR, Jarkko

#12 lore raw

Re: [RFC PATCH 6/7] tpm: add __always_inline for tpm_is_hwrng_enabled

Quoted 18 lines · Jarkko Sakkinen <[email protected]> 于2025年4月12日周六 08:47写道:
Quoted 3 lines · Chen Linxuan

From: Winston Wen <[email protected]>

On x86_64 with gcc version 13.3.0, I compile kernel with:

Use passive:

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

Quoted 8 lines

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"

Quoted 4 lines
Quoted 1 line

Then I get a link error:

"This results a link error:"

I will update commit message when I send v2.

Quoted 10 lines
Quoted 7 lines

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'

The resolution is lacking i.e., why adding __always_inline addresses the linking problem.

Regarding your comment about the resolution,
here’s a detailed explanation of
why adding the __always_inline attribute addresses the linking issue:

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:

```c
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:

```c
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.

There might be better ways to fix this.
But it is directly caused by adding -fno-inline-small-functions and -fno-inline-functions-called-once flags,
I think add __always_inline is good enough.

Quoted 29 lines
Quoted 23 lines
---
 drivers/char/tpm/tpm-chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +1 -2
index e25daf2396d3..48cc74d84247 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;
--
Quoted 2 lines

2.48.1

BR, Jarkko

#13 lore raw

RFC PATCH 7/7 lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE

In reply to a message not in the archive

From: Winston Wen <[email protected]>

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 917fad29febd ("kernel hacking: add a config option to disable compiler auto-inlining") which can be founded in linux-next-history:

Unlike the original implementation, this patch:

1. Make it depends on CC_IS_GCC,
as Clang 18.1.3 break test_bitmap_const_eval() in lib/test_bitmap.c

2. Make it depends on X86_64,
as I haven't test other architectures

3. Removes unnecessary cc-option checks per 7d73c3e9c514 ("Makefile:
remove stale cc-option checks").

4. Update help information.

---
 Makefile          |  6 ++++++
 lib/Kconfig.debug | 15 +++++++++++++++
 2 files changed, 21 insertions(+)
Makefile +6 -0
index f42418556507..0a9bf33ce75f 100644
@@ -1071,6 +1071,12 @@ endif
 # Ensure compilers do not transform certain loops into calls to wcslen()
 KBUILD_CFLAGS += -fno-builtin-wcslen
 
+ifdef CONFIG_NO_AUTO_INLINE
+KBUILD_CFLAGS   += -fno-inline-functions \
+		   -fno-inline-small-functions \
+		   -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 +15 -0
index 9fe4d8dfe578..2ebb4802886a 100644
@@ -436,8 +436,23 @@ 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
+	depends on CC_IS_GCC && (X86 || LOONGARCH)
+	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.
+
+	  If unsure, select N.
+
 config FRAME_WARN
 	int "Warn for stack frames larger than"
 	range 0 8192
Signature · 1 line
2.48.1
#14 lore raw

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

Quoted 18 lines · Chen Linxuan <[email protected]> 于2025年4月11日周五 18:56写道:

From: Winston Wen <[email protected]>

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 917fad29febd ("kernel hacking: add a config option to disable compiler auto-inlining") which can be founded in linux-next-history:

Quoted 7 lines

Unlike the original implementation, this patch:

1. Make it depends on CC_IS_GCC,
as Clang 18.1.3 break test_bitmap_const_eval() in lib/test_bitmap.c

2. Make it depends on X86_64,
as I haven't test other architectures

LOONGARCH has been tested, too.

Quoted 65 lines

3. Removes unnecessary cc-option checks per 7d73c3e9c514 ("Makefile:
remove stale cc-option checks").

4. Update help information.

---
 Makefile          |  6 ++++++
 lib/Kconfig.debug | 15 +++++++++++++++
 2 files changed, 21 insertions(+)
Makefile +6 -0
index f42418556507..0a9bf33ce75f 100644
@@ -1071,6 +1071,12 @@ endif
 # Ensure compilers do not transform certain loops into calls to wcslen()
 KBUILD_CFLAGS += -fno-builtin-wcslen
 
+ifdef CONFIG_NO_AUTO_INLINE
+KBUILD_CFLAGS   += -fno-inline-functions \
+                  -fno-inline-small-functions \
+                  -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 +15 -1
index 9fe4d8dfe578..2ebb4802886a 100644
@@ -436,8 +436,23 @@ 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
+       depends on CC_IS_GCC && (X86 || LOONGARCH)
+       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.
+
+         If unsure, select N.
+
 config FRAME_WARN
        int "Warn for stack frames larger than"
        range 0 8192
--

2.48.1

#15 lore raw

RFC PATCH 1/7 nvme: add __always_inline for nvme_pci_npages_prp

In reply to Chen Linxuan

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);
        |         ^~~~~~~~~~~~
---
 drivers/nvme/host/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/pci.c +1 -1
index b178d52eac1b..9ab070a9f037 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.48.1