mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kallsyms: copy constants from __KERNEL__ to user, drop the inclusion
@ 2026-10-08 23:19 Jim Cromie via B4 Relay
  2026-10-09 18:54 ` Nicolas Schier
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Cromie via B4 Relay @ 2026-10-08 23:19 UTC (permalink / raw)
  To: Nathan Chancellor, Denis Benato, Andrew Morton, linux-kbuild,
	nsc, thomas.weissschuh, chewi, abelvesa, linux-kernel, Kees Cook
  Cc: Jim Cromie

From: Jim Cromie <jim.cromie@gmail.com>

commit 4fafd1165b33 replaced hardcoded values which determine marker
array size, with new values that accelerate symbol-name lookups.
These symbols are needed in user-space to generate the lookup tables,
and in kernel to read the generated table.

To avoid 2-defns problem, they were added to a kernel header (with
ifdef guards) and included by scripts/kallsyms.c.  But that creates
packaging problems elsewhere, so just add the 2nd defns, with an
explicit comment about the user-kernel coupling.

Fixes: 4fafd1165b33 ("kallsyms: increase marker density to 16:1 to accelerate lookups")

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 kernel/kallsyms_internal.h | 12 +++++-------
 scripts/kallsyms.c         |  9 ++++++++-
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/kernel/kallsyms_internal.h b/kernel/kallsyms_internal.h
index 6a781e4cc77f..8311cce21128 100644
--- a/kernel/kallsyms_internal.h
+++ b/kernel/kallsyms_internal.h
@@ -2,18 +2,17 @@
 #ifndef LINUX_KALLSYMS_INTERNAL_H_
 #define LINUX_KALLSYMS_INTERNAL_H_
 
+#include <linux/types.h>
+
 /*
- * Provide compile-constants for scripts/kallsyms.c
- * so it can build the corresponding kallsyms_marker[] table.
- * and wrap the rest in __KERNEL__
+ * These constants determine the size of the kallsyms_markers array
+ * written by scripts/kallsyms.c during the build.  The symbol values
+ * must be kept in sync.
  */
 #define KALLSYMS_MARKER_SHIFT 4
 #define KALLSYMS_MARKER_SIZE  (1U << KALLSYMS_MARKER_SHIFT)
 #define KALLSYMS_MARKER_MASK  (KALLSYMS_MARKER_SIZE - 1U)
 
-#ifdef __KERNEL__
-#include <linux/types.h>
-
 extern const int kallsyms_offsets[];
 extern const u8 kallsyms_names[];
 
@@ -24,6 +23,5 @@ extern const u16 kallsyms_token_index[];
 
 extern const unsigned int kallsyms_markers[];
 extern const u8 kallsyms_seqs_of_names[];
-#endif /* __KERNEL__ */
 
 #endif // LINUX_KALLSYMS_INTERNAL_H_
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index be42a9111350..d142f040ad92 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -29,7 +29,14 @@
 
 #include <xalloc.h>
 
-#include "../kernel/kallsyms_internal.h"
+/*
+ * These constants determine the size of the marker array filled here,
+ * and they're duplicated in kernel/kallsyms.c, where they're used in
+ * get_symbol_offset().  They must be kept in agreement.
+ */
+#define KALLSYMS_MARKER_SHIFT 4
+#define KALLSYMS_MARKER_SIZE  (1U << KALLSYMS_MARKER_SHIFT)
+#define KALLSYMS_MARKER_MASK  (KALLSYMS_MARKER_SIZE - 1U)
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
 

---
base-commit: b9c9b9eb732aefcd02bbc211b2570a2315a889da
change-id: 20261008-fix-kallsyms-18e5a7fd0e19

Best regards,
-- 
Jim Cromie <jim.cromie@gmail.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kallsyms: copy constants from __KERNEL__ to user, drop the inclusion
  2026-10-08 23:19 [PATCH] kallsyms: copy constants from __KERNEL__ to user, drop the inclusion Jim Cromie via B4 Relay
@ 2026-10-09 18:54 ` Nicolas Schier
  2026-10-10 23:34   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Schier @ 2026-10-09 18:54 UTC (permalink / raw)
  To: Jim Cromie
  Cc: Nathan Chancellor, Denis Benato, Andrew Morton, linux-kbuild,
	nsc, thomas.weissschuh, chewi, abelvesa, linux-kernel, Kees Cook

> commit 4fafd1165b33 replaced hardcoded values which determine marker
> array size, with new values that accelerate symbol-name lookups.
> These symbols are needed in user-space to generate the lookup tables,
> and in kernel to read the generated table.
> 
> To avoid 2-defns problem, they were added to a kernel header (with
> ifdef guards) and included by scripts/kallsyms.c.  But that creates
> packaging problems elsewhere, so just add the 2nd defns, with an
> explicit comment about the user-kernel coupling.
> 
> Fixes: 4fafd1165b33 ("kallsyms: increase marker density to 16:1 to accelerate lookups")
> 
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---

FTR: Please keep trailers in a single trailer block, otherwise that will
probably break some common tooling (cp. e.g. git-interpret-trailers).

Is the commit ID correct?  In mm-nonmm-unstable I find
e2c2904abf71d0144f37844fde7dffe8b814a44f instead.

>  kernel/kallsyms_internal.h | 12 +++++-------
>  scripts/kallsyms.c         |  9 ++++++++-
>  2 files changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/kallsyms_internal.h b/kernel/kallsyms_internal.h
> index 6a781e4cc77f..8311cce21128 100644
> --- a/kernel/kallsyms_internal.h
> +++ b/kernel/kallsyms_internal.h
> @@ -2,18 +2,17 @@
>  #ifndef LINUX_KALLSYMS_INTERNAL_H_
>  #define LINUX_KALLSYMS_INTERNAL_H_
>  
> +#include <linux/types.h>
> +
>  /*
> - * Provide compile-constants for scripts/kallsyms.c
> - * so it can build the corresponding kallsyms_marker[] table.
> - * and wrap the rest in __KERNEL__
> + * These constants determine the size of the kallsyms_markers array
> + * written by scripts/kallsyms.c during the build.  The symbol values
> + * must be kept in sync.
>   */
>  #define KALLSYMS_MARKER_SHIFT 4
>  #define KALLSYMS_MARKER_SIZE  (1U << KALLSYMS_MARKER_SHIFT)
>  #define KALLSYMS_MARKER_MASK  (KALLSYMS_MARKER_SIZE - 1U)

Keeping these values in sync between kernel and kallsyms/user-space
might be simple by shifting these to some Kconfig symbols.  But that
could be done in a follow-up commit as well.

Nevertheless: fixes the report and prevent usage of in-tree header in
user-space tool; thanks!

Tested-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kallsyms: copy constants from __KERNEL__ to user, drop the inclusion
  2026-10-09 18:54 ` Nicolas Schier
@ 2026-10-10 23:34   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-10-10 23:34 UTC (permalink / raw)
  To: Nicolas Schier
  Cc: Jim Cromie, Nathan Chancellor, Denis Benato, linux-kbuild,
	thomas.weissschuh, chewi, abelvesa, linux-kernel, Kees Cook

On Fri, 09 Oct 2026 20:54:42 +0200 Nicolas Schier <nsc@kernel.org> wrote:

> > commit 4fafd1165b33 replaced hardcoded values which determine marker
> > array size, with new values that accelerate symbol-name lookups.
> > These symbols are needed in user-space to generate the lookup tables,
> > and in kernel to read the generated table.
> > 
> > To avoid 2-defns problem, they were added to a kernel header (with
> > ifdef guards) and included by scripts/kallsyms.c.  But that creates
> > packaging problems elsewhere, so just add the 2nd defns, with an
> > explicit comment about the user-kernel coupling.
> > 
> > Fixes: 4fafd1165b33 ("kallsyms: increase marker density to 16:1 to accelerate lookups")
> > 
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > ---

Thanks, I added this as a to-be-squashed-later fix against "kallsyms:
increase marker density to 16:1 to accelerate lookups".

btw, I have recorded some question marks about this series:

https://lore.kernel.org/20260929221330.72cd1de4@pumpkin
https://lore.kernel.org/20260930132109.260597-1-david.laight.linux@gmail.com
https://lore.kernel.org/20260930101307.4477e264@pumpkin

and I'd like to get those crossed off before proceeding.

> FTR: Please keep trailers in a single trailer block, otherwise that will
> probably break some common tooling (cp. e.g. git-interpret-trailers).
> 
> Is the commit ID correct?  In mm-nonmm-unstable I find
> e2c2904abf71d0144f37844fde7dffe8b814a44f instead.

mm-unstable is "unstable".  It rebases more than once per day so lookup
by hash doesn't work.

	git log --oneline | grep "kallsyms increase marker density to 16:1 to accelerate lookups"

works for me.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-10 23:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-08 23:19 [PATCH] kallsyms: copy constants from __KERNEL__ to user, drop the inclusion Jim Cromie via B4 Relay
2026-10-09 18:54 ` Nicolas Schier
2026-10-10 23:34   ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®