* [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE
@ 2025-04-29 4:06 Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 1/8] nvme: add __always_inline for nvme_pci_npages_prp Chen Linxuan via B4 Relay
` (8 more replies)
0 siblings, 9 replies; 17+ messages in thread
From: Chen Linxuan via B4 Relay @ 2025-04-29 4:06 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Chen Linxuan, Changbin Du
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
Link: https://lore.kernel.org/all/20181028130945.23581-3-changbin.du@gmail.com/
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/20250415090616.2649889-1-jani.nikula@intel.com/
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/
Signed-off-by: Chen Linxuan <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/20250416-noautoinline-v2-0-e69a2717530f@uniontech.com
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,
--
Chen Linxuan <chenlinxuan@uniontech.com>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH RFC v3 1/8] nvme: add __always_inline for nvme_pci_npages_prp
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
@ 2025-04-29 4:06 ` Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 2/8] mm: add __always_inline for page_contains_unaccepted Chen Linxuan via B4 Relay
` (7 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Chen Linxuan via B4 Relay @ 2025-04-29 4:06 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Chen Linxuan, Changbin Du
From: Winston Wen <wentao@uniontech.com>
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.
Co-developed-by: Chen Linxuan <chenlinxuan@uniontech.com>
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
Signed-off-by: Winston Wen <wentao@uniontech.com>
---
drivers/nvme/host/pci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index b178d52eac1b7f7286e217226b9b3686d07b7b6c..9ab070a9f0372bc6595c29a884ee9f2ffe5ae8e9 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH RFC v3 2/8] mm: add __always_inline for page_contains_unaccepted
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 1/8] nvme: add __always_inline for nvme_pci_npages_prp Chen Linxuan via B4 Relay
@ 2025-04-29 4:06 ` Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 3/8] vfio/virtio: add __always_inline for virtiovf_get_device_config_size Chen Linxuan via B4 Relay
` (6 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Chen Linxuan via B4 Relay @ 2025-04-29 4:06 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Chen Linxuan, Changbin Du
From: Winston Wen <wentao@uniontech.com>
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.
Co-developed-by: Chen Linxuan <chenlinxuan@uniontech.com>
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
Signed-off-by: Winston Wen <wentao@uniontech.com>
---
mm/page_alloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 5669baf2a6fea75c17b2be426443a6cf29051f52..433dc1936114469a323c8f3659730747965b2c3d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH RFC v3 3/8] vfio/virtio: add __always_inline for virtiovf_get_device_config_size
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 1/8] nvme: add __always_inline for nvme_pci_npages_prp Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 2/8] mm: add __always_inline for page_contains_unaccepted Chen Linxuan via B4 Relay
@ 2025-04-29 4:06 ` Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 4/8] tpm: add __always_inline for tpm_is_hwrng_enabled Chen Linxuan via B4 Relay
` (5 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Chen Linxuan via B4 Relay @ 2025-04-29 4:06 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Chen Linxuan, Changbin Du
From: Winston Wen <wentao@uniontech.com>
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.
Co-developed-by: Chen Linxuan <chenlinxuan@uniontech.com>
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
Signed-off-by: Winston Wen <wentao@uniontech.com>
---
drivers/vfio/pci/virtio/legacy_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/vfio/pci/virtio/legacy_io.c b/drivers/vfio/pci/virtio/legacy_io.c
index 832af5ba267c49a079009cfe0fa93c15ba7a490f..b6871d50b9f9e278ef3c49a9cb2baf474b8271c6 100644
--- a/drivers/vfio/pci/virtio/legacy_io.c
+++ b/drivers/vfio/pci/virtio/legacy_io.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH RFC v3 4/8] tpm: add __always_inline for tpm_is_hwrng_enabled
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
` (2 preceding siblings ...)
2025-04-29 4:06 ` [PATCH RFC v3 3/8] vfio/virtio: add __always_inline for virtiovf_get_device_config_size Chen Linxuan via B4 Relay
@ 2025-04-29 4:06 ` Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 5/8] rseq: add __always_inline for rseq_kernel_fields Chen Linxuan via B4 Relay
` (4 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Chen Linxuan via B4 Relay @ 2025-04-29 4:06 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Chen Linxuan, Changbin Du
From: Winston Wen <wentao@uniontech.com>
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.
Co-developed-by: Chen Linxuan <chenlinxuan@uniontech.com>
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
Signed-off-by: Winston Wen <wentao@uniontech.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
---
drivers/char/tpm/tpm-chip.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index e25daf2396d37bcaeae8a96267764df0861ad1be..48cc74d84247e258a39f2118e03aa10d0cbb066a 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH RFC v3 5/8] rseq: add __always_inline for rseq_kernel_fields
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
` (3 preceding siblings ...)
2025-04-29 4:06 ` [PATCH RFC v3 4/8] tpm: add __always_inline for tpm_is_hwrng_enabled Chen Linxuan via B4 Relay
@ 2025-04-29 4:06 ` Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 6/8] kcov: add __always_inline for canonicalize_ip Chen Linxuan via B4 Relay
` (3 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Chen Linxuan via B4 Relay @ 2025-04-29 4:06 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Chen Linxuan, Changbin Du
From: Chen Linxuan <chenlinxuan@uniontech.com>
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
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
---
kernel/rseq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/rseq.c b/kernel/rseq.c
index b7a1ec327e8117b47e353cab92d62111dd261520..7a4b6c211359714087a753047581bc8ff0c6c76b 100644
--- a/kernel/rseq.c
+++ b/kernel/rseq.c
@@ -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;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH RFC v3 6/8] kcov: add __always_inline for canonicalize_ip
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
` (4 preceding siblings ...)
2025-04-29 4:06 ` [PATCH RFC v3 5/8] rseq: add __always_inline for rseq_kernel_fields Chen Linxuan via B4 Relay
@ 2025-04-29 4:06 ` Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 7/8] x86/xen: add __init for xen_pgd_walk Chen Linxuan via B4 Relay
` (2 subsequent siblings)
8 siblings, 0 replies; 17+ messages in thread
From: Chen Linxuan via B4 Relay @ 2025-04-29 4:06 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Chen Linxuan, Changbin Du
From: Chen Linxuan <chenlinxuan@uniontech.com>
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
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
---
kernel/kcov.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/kcov.c b/kernel/kcov.c
index 187ba1b80bda169d2f7efead5c6076b8829522ca..a2e2d3c655406b5a1f53e4855c782727b0541935 100644
--- a/kernel/kcov.c
+++ b/kernel/kcov.c
@@ -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();
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH RFC v3 7/8] x86/xen: add __init for xen_pgd_walk
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
` (5 preceding siblings ...)
2025-04-29 4:06 ` [PATCH RFC v3 6/8] kcov: add __always_inline for canonicalize_ip Chen Linxuan via B4 Relay
@ 2025-04-29 4:06 ` Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 8/8] lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
2025-04-29 12:35 ` [PATCH RFC v3 0/8] kernel-hacking: " Christoph Hellwig
8 siblings, 0 replies; 17+ messages in thread
From: Chen Linxuan via B4 Relay @ 2025-04-29 4:06 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Chen Linxuan, Changbin Du
From: Chen Linxuan <chenlinxuan@uniontech.com>
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.
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
---
arch/x86/xen/mmu_pv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index 38971c6dcd4b78b6b14f51bc69c4bf6b70ebd622..53650888be0a7b1dba170a5b7ba9c654244b5125 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH RFC v3 8/8] lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
` (6 preceding siblings ...)
2025-04-29 4:06 ` [PATCH RFC v3 7/8] x86/xen: add __init for xen_pgd_walk Chen Linxuan via B4 Relay
@ 2025-04-29 4:06 ` Chen Linxuan via B4 Relay
2025-04-29 12:35 ` [PATCH RFC v3 0/8] kernel-hacking: " Christoph Hellwig
8 siblings, 0 replies; 17+ messages in thread
From: Chen Linxuan via B4 Relay @ 2025-04-29 4:06 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin
Cc: linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Chen Linxuan, Changbin Du
From: Chen Linxuan <chenlinxuan@uniontech.com>
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:
Link: https://lore.kernel.org/all/20181028130945.23581-3-changbin.du@gmail.com/
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:
Link: https://web.git.kernel.org/pub/scm/linux/kernel/git/next/linux-next-history.git/commit/?id=917fad29febd
Cc: Changbin Du <changbin.du@gmail.com>
Co-developed-by: Winston Wen <wentao@uniontech.com>
Signed-off-by: Winston Wen <wentao@uniontech.com>
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
---
Makefile | 16 ++++++++++++++++
lib/Kconfig.debug | 21 +++++++++++++++++++++
lib/Makefile | 3 +++
3 files changed, 40 insertions(+)
diff --git a/Makefile b/Makefile
index 5aa9ee52a765b7aed27f44028cdcc34a90979acb..60dec6c123543150a3332a9a819fa6933e94db4f 100644
--- a/Makefile
+++ b/Makefile
@@ -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)/=)
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index f9051ab610d54358b21d61c141b737bb345b4cee..56530f0145c885e9846dae1d2f8c6125c610d25b 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -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
diff --git a/lib/Makefile b/lib/Makefile
index f07b24ce1b3f8db28796e461db1324d97133fdd5..2ac97f0856a12f66e6c3825af6aabafa61869262 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
` (7 preceding siblings ...)
2025-04-29 4:06 ` [PATCH RFC v3 8/8] lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
@ 2025-04-29 12:35 ` Christoph Hellwig
2025-05-01 14:19 ` Brendan Jackman
2025-05-06 2:30 ` Chen Linxuan
8 siblings, 2 replies; 17+ messages in thread
From: Christoph Hellwig @ 2025-04-29 12:35 UTC (permalink / raw)
To: chenlinxuan
Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Andrew Morton, Yishai Hadas, Jason Gunthorpe, Shameer Kolothum,
Kevin Tian, Alex Williamson, Peter Huewe, Jarkko Sakkinen,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Nick Desaulniers, Bill Wendling, Justin Stitt, Vlastimil Babka,
Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Peter Zijlstra,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, linux-nvme,
linux-kernel, linux-mm, kvm, virtualization, linux-integrity,
linux-kbuild, llvm, Winston Wen, kasan-dev, xen-devel,
Changbin Du, Linus Torvalds
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.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE
2025-04-29 12:35 ` [PATCH RFC v3 0/8] kernel-hacking: " Christoph Hellwig
@ 2025-05-01 14:19 ` Brendan Jackman
2025-05-01 15:02 ` Peter Zijlstra
2025-05-06 2:30 ` Chen Linxuan
1 sibling, 1 reply; 17+ messages in thread
From: Brendan Jackman @ 2025-05-01 14:19 UTC (permalink / raw)
To: Christoph Hellwig, chenlinxuan
Cc: Keith Busch, Jens Axboe, Sagi Grimberg, Andrew Morton,
Yishai Hadas, Jason Gunthorpe, Shameer Kolothum, Kevin Tian,
Alex Williamson, Peter Huewe, Jarkko Sakkinen, Masahiro Yamada,
Nathan Chancellor, Nicolas Schier, Nick Desaulniers,
Bill Wendling, Justin Stitt, Vlastimil Babka, Suren Baghdasaryan,
Michal Hocko, Johannes Weiner, Zi Yan, Mathieu Desnoyers,
Peter Zijlstra, Paul E. McKenney, Boqun Feng, Dmitry Vyukov,
Andrey Konovalov, Juergen Gross, Boris Ostrovsky, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
linux-nvme, linux-kernel, linux-mm, kvm, virtualization,
linux-integrity, linux-kbuild, llvm, Winston Wen, kasan-dev,
xen-devel, Changbin Du, Linus Torvalds
On Tue Apr 29, 2025 at 12:35 PM UTC, Christoph Hellwig wrote:
> 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?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE
2025-05-01 14:19 ` Brendan Jackman
@ 2025-05-01 15:02 ` Peter Zijlstra
2025-05-01 15:22 ` Brendan Jackman
0 siblings, 1 reply; 17+ messages in thread
From: Peter Zijlstra @ 2025-05-01 15:02 UTC (permalink / raw)
To: Brendan Jackman
Cc: Christoph Hellwig, chenlinxuan, Keith Busch, Jens Axboe,
Sagi Grimberg, Andrew Morton, Yishai Hadas, Jason Gunthorpe,
Shameer Kolothum, Kevin Tian, Alex Williamson, Peter Huewe,
Jarkko Sakkinen, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Nick Desaulniers, Bill Wendling, Justin Stitt,
Vlastimil Babka, Suren Baghdasaryan, Michal Hocko,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Paul E. McKenney,
Boqun Feng, Dmitry Vyukov, Andrey Konovalov, Juergen Gross,
Boris Ostrovsky, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, linux-nvme, linux-kernel,
linux-mm, kvm, virtualization, linux-integrity, linux-kbuild,
llvm, Winston Wen, kasan-dev, xen-devel, Changbin Du,
Linus Torvalds
On Thu, May 01, 2025 at 02:19:47PM +0000, Brendan Jackman wrote:
> On Tue Apr 29, 2025 at 12:35 PM UTC, Christoph Hellwig wrote:
> > 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?
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE
2025-05-01 15:02 ` Peter Zijlstra
@ 2025-05-01 15:22 ` Brendan Jackman
2025-05-01 15:50 ` Peter Zijlstra
2025-05-03 19:13 ` Bart Van Assche
0 siblings, 2 replies; 17+ messages in thread
From: Brendan Jackman @ 2025-05-01 15:22 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Christoph Hellwig, chenlinxuan, Keith Busch, Jens Axboe,
Sagi Grimberg, Andrew Morton, Yishai Hadas, Jason Gunthorpe,
Shameer Kolothum, Kevin Tian, Alex Williamson, Peter Huewe,
Jarkko Sakkinen, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Nick Desaulniers, Bill Wendling, Justin Stitt,
Vlastimil Babka, Suren Baghdasaryan, Michal Hocko,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Paul E. McKenney,
Boqun Feng, Dmitry Vyukov, Andrey Konovalov, Juergen Gross,
Boris Ostrovsky, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, linux-nvme, linux-kernel,
linux-mm, kvm, virtualization, linux-integrity, linux-kbuild,
llvm, Winston Wen, kasan-dev, xen-devel, Changbin Du,
Linus Torvalds
On Thu May 1, 2025 at 3:02 PM UTC, Peter Zijlstra wrote:
> On Thu, May 01, 2025 at 02:19:47PM +0000, Brendan Jackman wrote:
>> On Tue Apr 29, 2025 at 12:35 PM UTC, Christoph Hellwig wrote:
>> > 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.
Right, I guess I just wouldn't have associated that with the word
"fragility", but that's a reasonable complaint!
> 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.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE
2025-05-01 15:22 ` Brendan Jackman
@ 2025-05-01 15:50 ` Peter Zijlstra
2025-05-03 19:13 ` Bart Van Assche
1 sibling, 0 replies; 17+ messages in thread
From: Peter Zijlstra @ 2025-05-01 15:50 UTC (permalink / raw)
To: Brendan Jackman
Cc: Christoph Hellwig, chenlinxuan, Keith Busch, Jens Axboe,
Sagi Grimberg, Andrew Morton, Yishai Hadas, Jason Gunthorpe,
Shameer Kolothum, Kevin Tian, Alex Williamson, Peter Huewe,
Jarkko Sakkinen, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Nick Desaulniers, Bill Wendling, Justin Stitt,
Vlastimil Babka, Suren Baghdasaryan, Michal Hocko,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Paul E. McKenney,
Boqun Feng, Dmitry Vyukov, Andrey Konovalov, Juergen Gross,
Boris Ostrovsky, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, linux-nvme, linux-kernel,
linux-mm, kvm, virtualization, linux-integrity, linux-kbuild,
llvm, Winston Wen, kasan-dev, xen-devel, Changbin Du,
Linus Torvalds
On Thu, May 01, 2025 at 03:22:55PM +0000, Brendan Jackman wrote:
> 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).
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE
2025-05-01 15:22 ` Brendan Jackman
2025-05-01 15:50 ` Peter Zijlstra
@ 2025-05-03 19:13 ` Bart Van Assche
2025-05-06 2:40 ` Chen Linxuan
1 sibling, 1 reply; 17+ messages in thread
From: Bart Van Assche @ 2025-05-03 19:13 UTC (permalink / raw)
To: Brendan Jackman, Peter Zijlstra
Cc: Christoph Hellwig, chenlinxuan, Keith Busch, Jens Axboe,
Sagi Grimberg, Andrew Morton, Yishai Hadas, Jason Gunthorpe,
Shameer Kolothum, Kevin Tian, Alex Williamson, Peter Huewe,
Jarkko Sakkinen, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, Nick Desaulniers, Bill Wendling, Justin Stitt,
Vlastimil Babka, Suren Baghdasaryan, Michal Hocko,
Johannes Weiner, Zi Yan, Mathieu Desnoyers, Paul E. McKenney,
Boqun Feng, Dmitry Vyukov, Andrey Konovalov, Juergen Gross,
Boris Ostrovsky, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, linux-nvme, linux-kernel,
linux-mm, kvm, virtualization, linux-integrity, linux-kbuild,
llvm, Winston Wen, kasan-dev, xen-devel, Changbin Du,
Linus Torvalds
On 5/1/25 8:22 AM, Brendan Jackman wrote:
> 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.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE
2025-04-29 12:35 ` [PATCH RFC v3 0/8] kernel-hacking: " Christoph Hellwig
2025-05-01 14:19 ` Brendan Jackman
@ 2025-05-06 2:30 ` Chen Linxuan
1 sibling, 0 replies; 17+ messages in thread
From: Chen Linxuan @ 2025-05-06 2:30 UTC (permalink / raw)
To: hch
Cc: akpm, alex.williamson, andreyknvl, axboe, boqun.feng,
boris.ostrovsky, bp, changbin.du, chenlinxuan, dave.hansen,
dvyukov, hannes, hpa, jackmanb, jarkko, jgg, jgross, justinstitt,
kasan-dev, kbusch, kevin.tian, kvm, linux-integrity, linux-kbuild,
linux-kernel, linux-mm, linux-nvme, llvm, masahiroy,
mathieu.desnoyers, mhocko, mingo, morbo, nathan,
nick.desaulniers+lkml, nicolas.schier, paulmck, peterhuewe,
peterz, sagi, shameerali.kolothum.thodi, surenb, tglx, torvalds,
vbabka, virtualization, wentao, x86, xen-devel, yishaih, ziy
On Tue, 29 Apr 2025 14:35:04 +0200 Christoph Hellwig wrote:
> 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.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE
2025-05-03 19:13 ` Bart Van Assche
@ 2025-05-06 2:40 ` Chen Linxuan
0 siblings, 0 replies; 17+ messages in thread
From: Chen Linxuan @ 2025-05-06 2:40 UTC (permalink / raw)
To: Bart Van Assche
Cc: Brendan Jackman, Peter Zijlstra, Christoph Hellwig, chenlinxuan,
Keith Busch, Jens Axboe, Sagi Grimberg, Andrew Morton,
Yishai Hadas, Jason Gunthorpe, Shameer Kolothum, Kevin Tian,
Alex Williamson, Peter Huewe, Jarkko Sakkinen, Masahiro Yamada,
Nathan Chancellor, Nicolas Schier, Nick Desaulniers,
Bill Wendling, Justin Stitt, Vlastimil Babka, Suren Baghdasaryan,
Michal Hocko, Johannes Weiner, Zi Yan, Mathieu Desnoyers,
Paul E. McKenney, Boqun Feng, Dmitry Vyukov, Andrey Konovalov,
Juergen Gross, Boris Ostrovsky, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, linux-nvme,
linux-kernel, linux-mm, kvm, virtualization, linux-integrity,
linux-kbuild, llvm, Winston Wen, kasan-dev, xen-devel,
Changbin Du, Linus Torvalds
On Sun, May 4, 2025 at 3:14 AM Bart Van Assche <bvanassche@acm.org> wrote:
> 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.
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2025-05-06 2:41 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-29 4:06 [PATCH RFC v3 0/8] kernel-hacking: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 1/8] nvme: add __always_inline for nvme_pci_npages_prp Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 2/8] mm: add __always_inline for page_contains_unaccepted Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 3/8] vfio/virtio: add __always_inline for virtiovf_get_device_config_size Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 4/8] tpm: add __always_inline for tpm_is_hwrng_enabled Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 5/8] rseq: add __always_inline for rseq_kernel_fields Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 6/8] kcov: add __always_inline for canonicalize_ip Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 7/8] x86/xen: add __init for xen_pgd_walk Chen Linxuan via B4 Relay
2025-04-29 4:06 ` [PATCH RFC v3 8/8] lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE Chen Linxuan via B4 Relay
2025-04-29 12:35 ` [PATCH RFC v3 0/8] kernel-hacking: " Christoph Hellwig
2025-05-01 14:19 ` Brendan Jackman
2025-05-01 15:02 ` Peter Zijlstra
2025-05-01 15:22 ` Brendan Jackman
2025-05-01 15:50 ` Peter Zijlstra
2025-05-03 19:13 ` Bart Van Assche
2025-05-06 2:40 ` Chen Linxuan
2025-05-06 2:30 ` Chen Linxuan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).