History

Merge tag 'modules-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux

Pull modules updates from Luis Chamberlain: "Tux gets for xmas an improvement to the average lookup performance of kallsyms_lookup_name() by 715x thanks to the work by Zhen Lei, which upgraded our old implementation from being O(n) to O(log(n)), while also retaining the old implementation support on /proc/kallsyms. The only penalty was increasing the memory footprint by 3 * kallsyms_num_syms. Folks who want to improve this further now also have a dedicated selftest facility through KALLSYMS_SELFTEST. Stephen Boyd added zstd in-kernel decompression support, but the only users of this would be folks using the load-pin LSM because otherwise we do module decompression in userspace. The only other thing with mentioning is a minor boot time optimization by Rasmus Villemoes which deferes param_sysfs_init() to late init. The rest is cleanups and minor fixes" * tag 'modules-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux: livepatch: Call klp_match_callback() in klp_find_callback() to avoid code duplication module/decompress: Support zstd in-kernel decompression kallsyms: Remove unneeded semicolon kallsyms: Add self-test facility livepatch: Use kallsyms_on_each_match_symbol() to improve performance kallsyms: Add helper kallsyms_on_each_match_symbol() kallsyms: Reduce the memory occupied by kallsyms_seqs_of_names[] kallsyms: Correctly sequence symbols when CONFIG_LTO_CLANG=y kallsyms: Improve the performance of kallsyms_lookup_name() scripts/kallsyms: rename build_initial_tok_table() module: Fix NULL vs IS_ERR checking for module_get_next_page kernel/params.c: defer most of param_sysfs_init() to late_initcall time module: Remove unused macros module_addr_min/max module: remove redundant module_sysfs_initialized variable

Linus Torvalds committed 3 years ago

Commit 3ba2c3f2 parents 0015edd 4f1354d16 files · +840 −43Browse files

Showing the changes to scripts (2 of 16 files). Show all

Unified · Split

2 files
  1. scripts/kallsyms.c +75 −3
  2. scripts/link-vmlinux.sh +4 −0
scripts/kallsyms.c+75−3
@@ -49,6 +49,7 @@ _Static_assert( · 48 unmodified lines
49struct sym_entry {49struct sym_entry {
50 unsigned long long addr;50 unsigned long long addr;
51 unsigned int len;51 unsigned int len;
52 unsigned int seq;
52 unsigned int start_pos;53 unsigned int start_pos;
53 unsigned int percpu_absolute;54 unsigned int percpu_absolute;
54 unsigned char sym[];55 unsigned char sym[];
@@ -77,6 +78,7 @@ static unsigned int table_size, table_cnt; · 22 unmodified lines
77static int all_symbols;78static int all_symbols;
78static int absolute_percpu;79static int absolute_percpu;
79static int base_relative;80static int base_relative;
81static int lto_clang;
80 82
81static int token_profit[0x10000];83static int token_profit[0x10000];
82 84
@@ -88,7 +90,7 @@ static unsigned char best_table_len[256]; · 5 unmodified lines
88static void usage(void)90static void usage(void)
89{91{
90 fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] "92 fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] "
91 "[--base-relative] in.map > out.S\n");93 "[--base-relative] [--lto-clang] in.map > out.S\n");
92 exit(1);94 exit(1);
93}95}
94 96
@@ -410,6 +412,65 @@ static int symbol_absolute(const struct sym_entry *s) · 315 unmodified lines
410 return s->percpu_absolute;412 return s->percpu_absolute;
411}413}
412 414
415static char * s_name(char *buf)
416{
417 /* Skip the symbol type */
418 return buf + 1;
419}
420
421static void cleanup_symbol_name(char *s)
422{
423 char *p;
424
425 if (!lto_clang)
426 return;
427
428 /*
429 * ASCII[.] = 2e
430 * ASCII[0-9] = 30,39
431 * ASCII[A-Z] = 41,5a
432 * ASCII[_] = 5f
433 * ASCII[a-z] = 61,7a
434 *
435 * As above, replacing '.' with '\0' does not affect the main sorting,
436 * but it helps us with subsorting.
437 */
438 p = strchr(s, '.');
439 if (p)
440 *p = '\0';
441}
442
443static int compare_names(const void *a, const void *b)
444{
445 int ret;
446 char sa_namebuf[KSYM_NAME_LEN];
447 char sb_namebuf[KSYM_NAME_LEN];
448 const struct sym_entry *sa = *(const struct sym_entry **)a;
449 const struct sym_entry *sb = *(const struct sym_entry **)b;
450
451 expand_symbol(sa->sym, sa->len, sa_namebuf);
452 expand_symbol(sb->sym, sb->len, sb_namebuf);
453 cleanup_symbol_name(s_name(sa_namebuf));
454 cleanup_symbol_name(s_name(sb_namebuf));
455 ret = strcmp(s_name(sa_namebuf), s_name(sb_namebuf));
456 if (!ret) {
457 if (sa->addr > sb->addr)
458 return 1;
459 else if (sa->addr < sb->addr)
460 return -1;
461
462 /* keep old order */
463 return (int)(sa->seq - sb->seq);
464 }
465
466 return ret;
467}
468
469static void sort_symbols_by_name(void)
470{
471 qsort(table, table_cnt, sizeof(table[0]), compare_names);
472}
473
413static void write_src(void)474static void write_src(void)
414{475{
415 unsigned int i, k, off;476 unsigned int i, k, off;
@@ -495,6 +556,7 @@ static void write_src(void) · 79 unmodified lines
495 for (i = 0; i < table_cnt; i++) {556 for (i = 0; i < table_cnt; i++) {
496 if ((i & 0xFF) == 0)557 if ((i & 0xFF) == 0)
497 markers[i >> 8] = off;558 markers[i >> 8] = off;
559 table[i]->seq = i;
498 560
499 /* There cannot be any symbol of length zero. */561 /* There cannot be any symbol of length zero. */
500 if (table[i]->len == 0) {562 if (table[i]->len == 0) {
@@ -535,6 +597,15 @@ static void write_src(void) · 34 unmodified lines
535 597
536 free(markers);598 free(markers);
537 599
600 sort_symbols_by_name();
601 output_label("kallsyms_seqs_of_names");
602 for (i = 0; i < table_cnt; i++)
603 printf("\t.byte 0x%02x, 0x%02x, 0x%02x\n",
604 (unsigned char)(table[i]->seq >> 16),
605 (unsigned char)(table[i]->seq >> 8),
606 (unsigned char)(table[i]->seq >> 0));
607 printf("\n");
608
538 output_label("kallsyms_token_table");609 output_label("kallsyms_token_table");
539 off = 0;610 off = 0;
540 for (i = 0; i < 256; i++) {611 for (i = 0; i < 256; i++) {
@@ -573,7 +644,7 @@ static void forget_symbol(const unsigned char *symbol, int len) · 32 unmodified lines
573}644}
574 645
575/* do the initial token count */646/* do the initial token count */
576static void build_initial_tok_table(void)647static void build_initial_token_table(void)
577{648{
578 unsigned int i;649 unsigned int i;
579 650
@@ -698,7 +769,7 @@ static void insert_real_symbols_in_table(void) · 118 unmodified lines
698 769
699static void optimize_token_table(void)770static void optimize_token_table(void)
700{771{
701 build_initial_tok_table();772 build_initial_token_table();
702 773
703 insert_real_symbols_in_table();774 insert_real_symbols_in_table();
704 775
@@ -818,6 +889,7 @@ int main(int argc, char **argv) · 113 unmodified lines
818 {"all-symbols", no_argument, &all_symbols, 1},889 {"all-symbols", no_argument, &all_symbols, 1},
819 {"absolute-percpu", no_argument, &absolute_percpu, 1},890 {"absolute-percpu", no_argument, &absolute_percpu, 1},
820 {"base-relative", no_argument, &base_relative, 1},891 {"base-relative", no_argument, &base_relative, 1},
892 {"lto-clang", no_argument, &lto_clang, 1},
821 {},893 {},
822 };894 };
823 895
scripts/link-vmlinux.sh+4−0
@@ -156,6 +156,10 @@ kallsyms() · 155 unmodified lines
156 kallsymopt="${kallsymopt} --base-relative"156 kallsymopt="${kallsymopt} --base-relative"
157 fi157 fi
158 158
159 if is_enabled CONFIG_LTO_CLANG; then
160 kallsymopt="${kallsymopt} --lto-clang"
161 fi
162
159 info KSYMS ${2}163 info KSYMS ${2}
160 scripts/kallsyms ${kallsymopt} ${1} > ${2}164 scripts/kallsyms ${kallsymopt} ${1} > ${2}
161}165}