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
4949 struct sym_entry {
5050 unsigned long long addr;
5151 unsigned int len;
52+ unsigned int seq;
5253 unsigned int start_pos;
5354 unsigned int percpu_absolute;
5455 unsigned char sym[];
@@ -77,6 +78,7 @@ static unsigned int table_size, table_cnt; · 22 unmodified lines
7778 static int all_symbols;
7879 static int absolute_percpu;
7980 static int base_relative;
81+static int lto_clang;
8082
8183 static int token_profit[0x10000];
8284
@@ -88,7 +90,7 @@ static unsigned char best_table_len[256]; · 5 unmodified lines
8890 static void usage(void)
8991 {
9092 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");
9294 exit(1);
9395 }
9496
@@ -410,6 +412,65 @@ static int symbol_absolute(const struct sym_entry *s) · 315 unmodified lines
410412 return s->percpu_absolute;
411413 }
412414
415+static char * s_name(char *buf)
416+{
417+ /* Skip the symbol type */
418+ return buf + 1;
419+}
420+
421+static 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+
443+static 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+
469+static void sort_symbols_by_name(void)
470+{
471+ qsort(table, table_cnt, sizeof(table[0]), compare_names);
472+}
473+
413474 static void write_src(void)
414475 {
415476 unsigned int i, k, off;
@@ -495,6 +556,7 @@ static void write_src(void) · 79 unmodified lines
495556 for (i = 0; i < table_cnt; i++) {
496557 if ((i & 0xFF) == 0)
497558 markers[i >> 8] = off;
559+ table[i]->seq = i;
498560
499561 /* There cannot be any symbol of length zero. */
500562 if (table[i]->len == 0) {
@@ -535,6 +597,15 @@ static void write_src(void) · 34 unmodified lines
535597
536598 free(markers);
537599
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+
538609 output_label("kallsyms_token_table");
539610 off = 0;
540611 for (i = 0; i < 256; i++) {
@@ -573,7 +644,7 @@ static void forget_symbol(const unsigned char *symbol, int len) · 32 unmodified lines
573644 }
574645
575646 /* do the initial token count */
576−static void build_initial_tok_table(void)
647+static void build_initial_token_table(void)
577648 {
578649 unsigned int i;
579650
@@ -698,7 +769,7 @@ static void insert_real_symbols_in_table(void) · 118 unmodified lines
698769
699770 static void optimize_token_table(void)
700771 {
701− build_initial_tok_table();
772+ build_initial_token_table();
702773
703774 insert_real_symbols_in_table();
704775
@@ -818,6 +889,7 @@ int main(int argc, char **argv) · 113 unmodified lines
818889 {"all-symbols", no_argument, &all_symbols, 1},
819890 {"absolute-percpu", no_argument, &absolute_percpu, 1},
820891 {"base-relative", no_argument, &base_relative, 1},
892+ {"lto-clang", no_argument, &lto_clang, 1},
821893 {},
822894 };
823895
scripts/link-vmlinux.sh+4−0
@@ -156,6 +156,10 @@ kallsyms() · 155 unmodified lines
156156 kallsymopt="${kallsymopt} --base-relative"
157157 fi
158158
159+ if is_enabled CONFIG_LTO_CLANG; then
160+ kallsymopt="${kallsymopt} --lto-clang"
161+ fi
162+
159163 info KSYMS ${2}
160164 scripts/kallsyms ${kallsymopt} ${1} > ${2}
161165 }