linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/3] kallsyms: Rust requirements
@ 2022-05-05 19:16 Miguel Ojeda
  2022-05-05 19:16 ` [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512 Miguel Ojeda
  0 siblings, 1 reply; 5+ messages in thread
From: Miguel Ojeda @ 2022-05-05 19:16 UTC (permalink / raw)
  To: Adrian Hunter, Alexander Shishkin, Alexei Starovoitov, Andi Kleen,
	Andrew Morton, Arnaldo Carvalho de Melo, Changbin Du,
	Christophe Leroy, David Vernet, Gustavo A. R. Silva, Ingo Molnar,
	Jiri Kosina, Jiri Olsa, Josh Poimboeuf, Kees Cook, Kefeng Wang,
	linux-kernel, linux-perf-users, live-patching, Masahiro Yamada,
	Miroslav Benes, Nathan Chancellor, Nick Desaulniers,
	Peter Zijlstra, Petr Mladek, Sergey Senozhatsky, Stephen Boyd
  Cc: rust-for-linux, Miguel Ojeda

These are the kallsyms patches we carry on the Rust patch series as
prerequisites. We were requested to submit them independently, so
here they are!

  - The first one is an improvement that may be applied even without
    the big symbol support.

  - The second adds support for "big" symbols without actually
    increasing the limit.

  - The third performs the actual increase.

Thanks!

Boqun Feng (1):
  kallsyms: avoid hardcoding the buffer size

Miguel Ojeda (2):
  kallsyms: support "big" kernel symbols
  kallsyms: increase maximum kernel symbol length to 512

 include/linux/kallsyms.h            |  2 +-
 kernel/kallsyms.c                   | 26 +++++++++++++---
 kernel/livepatch/core.c             |  4 +--
 scripts/kallsyms.c                  | 47 ++++++++++++++++++++++++-----
 tools/include/linux/kallsyms.h      |  2 +-
 tools/lib/perf/include/perf/event.h |  2 +-
 tools/lib/symbol/kallsyms.h         |  2 +-
 7 files changed, 68 insertions(+), 17 deletions(-)


base-commit: 672c0c5173427e6b3e2a9bbb7be51ceeec78093a
-- 
2.35.3


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

* [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512
  2022-05-05 19:16 [PATCH v1 0/3] kallsyms: Rust requirements Miguel Ojeda
@ 2022-05-05 19:16 ` Miguel Ojeda
  2022-05-05 23:48   ` Kees Cook
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Miguel Ojeda @ 2022-05-05 19:16 UTC (permalink / raw)
  To: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek,
	Joe Lawrence, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Andrew Morton, Sergey Senozhatsky,
	Kefeng Wang, Helge Deller, Stephen Boyd, Christophe Leroy,
	Masahiro Yamada, Nick Desaulniers, Changbin Du, Nathan Chancellor,
	Gustavo A. R. Silva, Andi Kleen, Kees Cook, Adrian Hunter,
	linux-kernel, live-patching, linux-perf-users
  Cc: rust-for-linux, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Gary Guo, Boqun Feng

Rust symbols can become quite long due to namespacing introduced
by modules, types, traits, generics, etc. For instance,
the following code:

    pub mod my_module {
        pub struct MyType;
        pub struct MyGenericType<T>(T);

        pub trait MyTrait {
            fn my_method() -> u32;
        }

        impl MyTrait for MyGenericType<MyType> {
            fn my_method() -> u32 {
                42
            }
        }
    }

generates a symbol of length 96 when using the upcoming v0 mangling scheme:

    _RNvXNtCshGpAVYOtgW1_7example9my_moduleINtB2_13MyGenericTypeNtB2_6MyTypeENtB2_7MyTrait9my_method

At the moment, Rust symbols may reach up to 300 in length.
Setting 512 as the maximum seems like a reasonable choice to
keep some headroom.

Co-developed-by: Alex Gaynor <alex.gaynor@gmail.com>
Signed-off-by: Alex Gaynor <alex.gaynor@gmail.com>
Co-developed-by: Wedson Almeida Filho <wedsonaf@google.com>
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
Co-developed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Gary Guo <gary@garyguo.net>
Co-developed-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 include/linux/kallsyms.h            | 2 +-
 kernel/livepatch/core.c             | 4 ++--
 scripts/kallsyms.c                  | 4 ++--
 tools/include/linux/kallsyms.h      | 2 +-
 tools/lib/perf/include/perf/event.h | 2 +-
 tools/lib/symbol/kallsyms.h         | 2 +-
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index ce1bd2fbf23e..e5ad6e31697d 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -15,7 +15,7 @@
 
 #include <asm/sections.h>
 
-#define KSYM_NAME_LEN 128
+#define KSYM_NAME_LEN 512
 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s %s]") + \
 			(KSYM_NAME_LEN - 1) + \
 			2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + \
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index bc475e62279d..ec06ce59d728 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -213,7 +213,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab,
 	 * we use the smallest/strictest upper bound possible (56, based on
 	 * the current definition of MODULE_NAME_LEN) to prevent overflows.
 	 */
-	BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 128);
+	BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 512);
 
 	relas = (Elf_Rela *) relasec->sh_addr;
 	/* For each rela in this klp relocation section */
@@ -227,7 +227,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab,
 
 		/* Format: .klp.sym.sym_objname.sym_name,sympos */
 		cnt = sscanf(strtab + sym->st_name,
-			     ".klp.sym.%55[^.].%127[^,],%lu",
+			     ".klp.sym.%55[^.].%511[^,],%lu",
 			     sym_objname, sym_name, &sympos);
 		if (cnt != 3) {
 			pr_err("symbol %s has an incorrectly formatted name\n",
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index c4e85eec2b4b..f9d07f9eb709 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -30,10 +30,10 @@
 #define _stringify_1(x)	#x
 #define _stringify(x)	_stringify_1(x)
 
-#define KSYM_NAME_LEN		128
+#define KSYM_NAME_LEN		512
 
 /* A substantially bigger size than the current maximum. */
-#define KSYM_NAME_LEN_BUFFER	512
+#define KSYM_NAME_LEN_BUFFER	2048
 _Static_assert(
 	KSYM_NAME_LEN_BUFFER == KSYM_NAME_LEN * 4,
 	"Please keep KSYM_NAME_LEN_BUFFER in sync with KSYM_NAME_LEN"
diff --git a/tools/include/linux/kallsyms.h b/tools/include/linux/kallsyms.h
index efb6c3f5f2a9..5a37ccbec54f 100644
--- a/tools/include/linux/kallsyms.h
+++ b/tools/include/linux/kallsyms.h
@@ -6,7 +6,7 @@
 #include <stdio.h>
 #include <unistd.h>
 
-#define KSYM_NAME_LEN 128
+#define KSYM_NAME_LEN 512
 
 struct module;
 
diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h
index e7758707cadd..116a80c31675 100644
--- a/tools/lib/perf/include/perf/event.h
+++ b/tools/lib/perf/include/perf/event.h
@@ -95,7 +95,7 @@ struct perf_record_throttle {
 };
 
 #ifndef KSYM_NAME_LEN
-#define KSYM_NAME_LEN 256
+#define KSYM_NAME_LEN 512
 #endif
 
 struct perf_record_ksymbol {
diff --git a/tools/lib/symbol/kallsyms.h b/tools/lib/symbol/kallsyms.h
index 72ab9870454b..542f9b059c3b 100644
--- a/tools/lib/symbol/kallsyms.h
+++ b/tools/lib/symbol/kallsyms.h
@@ -7,7 +7,7 @@
 #include <linux/types.h>
 
 #ifndef KSYM_NAME_LEN
-#define KSYM_NAME_LEN 256
+#define KSYM_NAME_LEN 512
 #endif
 
 static inline u8 kallsyms2elf_binding(char type)
-- 
2.35.3


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

* Re: [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512
  2022-05-05 19:16 ` [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512 Miguel Ojeda
@ 2022-05-05 23:48   ` Kees Cook
  2022-05-06  8:34   ` Petr Mladek
  2022-05-06  9:45   ` Geert Stappers
  2 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2022-05-05 23:48 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Petr Mladek,
	Joe Lawrence, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Andrew Morton, Sergey Senozhatsky,
	Kefeng Wang, Helge Deller, Stephen Boyd, Christophe Leroy,
	Masahiro Yamada, Nick Desaulniers, Changbin Du, Nathan Chancellor,
	Gustavo A. R. Silva, Andi Kleen, Adrian Hunter, linux-kernel,
	live-patching, linux-perf-users, rust-for-linux, Alex Gaynor,
	Wedson Almeida Filho, Gary Guo, Boqun Feng

On Thu, May 05, 2022 at 09:16:45PM +0200, Miguel Ojeda wrote:
> Rust symbols can become quite long due to namespacing introduced
> by modules, types, traits, generics, etc. For instance,
> the following code:
> 
>     pub mod my_module {
>         pub struct MyType;
>         pub struct MyGenericType<T>(T);
> 
>         pub trait MyTrait {
>             fn my_method() -> u32;
>         }
> 
>         impl MyTrait for MyGenericType<MyType> {
>             fn my_method() -> u32 {
>                 42
>             }
>         }
>     }
> 
> generates a symbol of length 96 when using the upcoming v0 mangling scheme:
> 
>     _RNvXNtCshGpAVYOtgW1_7example9my_moduleINtB2_13MyGenericTypeNtB2_6MyTypeENtB2_7MyTrait9my_method
> 
> At the moment, Rust symbols may reach up to 300 in length.
> Setting 512 as the maximum seems like a reasonable choice to
> keep some headroom.
> 
> Co-developed-by: Alex Gaynor <alex.gaynor@gmail.com>
> Signed-off-by: Alex Gaynor <alex.gaynor@gmail.com>
> Co-developed-by: Wedson Almeida Filho <wedsonaf@google.com>
> Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
> Co-developed-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Gary Guo <gary@garyguo.net>
> Co-developed-by: Boqun Feng <boqun.feng@gmail.com>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

I look forward to aiming my demangler at /proc/kallsyms. ;)

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

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

* Re: [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512
  2022-05-05 19:16 ` [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512 Miguel Ojeda
  2022-05-05 23:48   ` Kees Cook
@ 2022-05-06  8:34   ` Petr Mladek
  2022-05-06  9:45   ` Geert Stappers
  2 siblings, 0 replies; 5+ messages in thread
From: Petr Mladek @ 2022-05-06  8:34 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Josh Poimboeuf, Jiri Kosina, Miroslav Benes, Joe Lawrence,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Andrew Morton, Sergey Senozhatsky, Kefeng Wang, Helge Deller,
	Stephen Boyd, Christophe Leroy, Masahiro Yamada, Nick Desaulniers,
	Changbin Du, Nathan Chancellor, Gustavo A. R. Silva, Andi Kleen,
	Kees Cook, Adrian Hunter, linux-kernel, live-patching,
	linux-perf-users, rust-for-linux, Alex Gaynor,
	Wedson Almeida Filho, Gary Guo, Boqun Feng

On Thu 2022-05-05 21:16:45, Miguel Ojeda wrote:
> Rust symbols can become quite long due to namespacing introduced
> by modules, types, traits, generics, etc. For instance,
> the following code:
> 
>     pub mod my_module {
>         pub struct MyType;
>         pub struct MyGenericType<T>(T);
> 
>         pub trait MyTrait {
>             fn my_method() -> u32;
>         }
> 
>         impl MyTrait for MyGenericType<MyType> {
>             fn my_method() -> u32 {
>                 42
>             }
>         }
>     }
> 
> generates a symbol of length 96 when using the upcoming v0 mangling scheme:
> 
>     _RNvXNtCshGpAVYOtgW1_7example9my_moduleINtB2_13MyGenericTypeNtB2_6MyTypeENtB2_7MyTrait9my_method
> 
> At the moment, Rust symbols may reach up to 300 in length.
> Setting 512 as the maximum seems like a reasonable choice to
> keep some headroom.
> 
> Co-developed-by: Alex Gaynor <alex.gaynor@gmail.com>
> Signed-off-by: Alex Gaynor <alex.gaynor@gmail.com>
> Co-developed-by: Wedson Almeida Filho <wedsonaf@google.com>
> Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
> Co-developed-by: Gary Guo <gary@garyguo.net>
> Signed-off-by: Gary Guo <gary@garyguo.net>
> Co-developed-by: Boqun Feng <boqun.feng@gmail.com>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

I was primary interested into the livepatching code.
But the entire patch looks good:

Reviewed-by: Petr Mladek <pmladek@suse.com>

I just hope that it will not cause stack overflows
somewhere.

Best Regards,
Petr

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

* Re: [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512
  2022-05-05 19:16 ` [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512 Miguel Ojeda
  2022-05-05 23:48   ` Kees Cook
  2022-05-06  8:34   ` Petr Mladek
@ 2022-05-06  9:45   ` Geert Stappers
  2 siblings, 0 replies; 5+ messages in thread
From: Geert Stappers @ 2022-05-06  9:45 UTC (permalink / raw)
  To: Miguel Ojeda, Josh Poimboeuf, Jiri Kosina, Miroslav Benes,
	Petr Mladek, Joe Lawrence, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Andrew Morton, Sergey Senozhatsky,
	Kefeng Wang, Helge Deller, Stephen Boyd, Christophe Leroy,
	Masahiro Yamada, Nick Desaulniers, Changbin Du, Nathan Chancellor,
	Gustavo A. R. Silva, Andi Kleen, Kees Cook, Adrian Hunter,
	linux-kernel, live-patching, linux-perf-users, rust-for-linux,
	Alex Gaynor, Wedson Almeida Filho, Gary Guo, Boqun Feng

On Thu, May 05, 2022 at 09:16:45PM +0200, Miguel Ojeda wrote:
> 
> generates a symbol of length 96 when using the upcoming v0 mangling scheme:
> 
>     _RNvXNtCshGpAVYOtgW1_7example9my_moduleINtB2_13MyGenericTypeNtB2_6MyTypeENtB2_7MyTrait9my_method
> 
> At the moment, Rust symbols may reach up to 300 in length.
> Setting 512 as the maximum seems like a reasonable choice to
> keep some headroom.
> 
> diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
> index ce1bd2fbf23e..e5ad6e31697d 100644
> --- a/include/linux/kallsyms.h
> +++ b/include/linux/kallsyms.h
> @@ -15,7 +15,7 @@
>  
>  #include <asm/sections.h>
>  
> -#define KSYM_NAME_LEN 128
> +#define KSYM_NAME_LEN 512

multiplication factor is four


> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> @@ -213,7 +213,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab,
>  	 * we use the smallest/strictest upper bound possible (56, based on
>  	 * the current definition of MODULE_NAME_LEN) to prevent overflows.
>  	 */
> -	BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 128);
> +	BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 512);

factor four


> @@ -227,7 +227,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab,
>  
>  		/* Format: .klp.sym.sym_objname.sym_name,sympos */
>  		cnt = sscanf(strtab + sym->st_name,
> -			     ".klp.sym.%55[^.].%127[^,],%lu",
> +			     ".klp.sym.%55[^.].%511[^,],%lu",

4 * ( 127 + 1 )  =  511 + 1


> --- a/scripts/kallsyms.c
> +++ b/scripts/kallsyms.c
> @@ -30,10 +30,10 @@
>  #define _stringify_1(x)	#x
>  #define _stringify(x)	_stringify_1(x)
>  
> -#define KSYM_NAME_LEN		128
> +#define KSYM_NAME_LEN		512

factor four


> --- a/tools/include/linux/kallsyms.h
> +++ b/tools/include/linux/kallsyms.h
> @@ -6,7 +6,7 @@
>  #include <stdio.h>
>  #include <unistd.h>
>  
> -#define KSYM_NAME_LEN 128
> +#define KSYM_NAME_LEN 512

factor four


> --- a/tools/lib/perf/include/perf/event.h
> +++ b/tools/lib/perf/include/perf/event.h
> @@ -95,7 +95,7 @@ struct perf_record_throttle {
>  };
>  
>  #ifndef KSYM_NAME_LEN
> -#define KSYM_NAME_LEN 256
> +#define KSYM_NAME_LEN 512

Here is the multiplication factor  two.


> --- a/tools/lib/symbol/kallsyms.h
> +++ b/tools/lib/symbol/kallsyms.h
> @@ -7,7 +7,7 @@
>  #include <linux/types.h>
>  
>  #ifndef KSYM_NAME_LEN
> -#define KSYM_NAME_LEN 256
> +#define KSYM_NAME_LEN 512

Another  "factor two"



It feels good to unify all the KSYM_NAME_LEN to 512.

Thing that feels less good is doubling 256 versus quadrupling 128.

I felt the need to report that.


Feel free to ignore this remark.



Groeten
Geert Stappers
-- 
Silence is hard to parse

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

end of thread, other threads:[~2022-05-06  9:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-05 19:16 [PATCH v1 0/3] kallsyms: Rust requirements Miguel Ojeda
2022-05-05 19:16 ` [PATCH v1 3/3] kallsyms: increase maximum kernel symbol length to 512 Miguel Ojeda
2022-05-05 23:48   ` Kees Cook
2022-05-06  8:34   ` Petr Mladek
2022-05-06  9:45   ` Geert Stappers

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).