From patchwork Tue Jul 30 00:54:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 13746049 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE5148C0B; Tue, 30 Jul 2024 00:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300892; cv=none; b=oIZvUcNTgujaBv/WQp+C5dvG6wkAFidLYnqvNyrcgNvBoqq4jBD4krW8R8cLIh9x96gey0+gawq0y5w2vCcEQNtd6Cy92Uve+qr2DeyRUPtu8lGCPPYxZgilPczJp/nDzlrzW8p453DhNd+E0ZSzQXMZ2844+dQy9pNf2vMLWgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300892; c=relaxed/simple; bh=pyBJdtxBPz3GxnxSNiZhE22PkJY5jWrFTCpJgLxoSPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bxIaeegNZSC9sKW7yxVLR0IrMgsenzvYPJwIaO2BIcYP1VLoPMLcADBPHG7NaJz5a2dJYjKf5ErQ1suFfIiI2yJpJgO7Z9CGPpDQxxzf5ycVlqTQBpCZqKr9Ei13u6UDPuVmavS3xxqsC0UAyxY2yYibY7C5ahSL1iJmR4ako5A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nrX492Oo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nrX492Oo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3F83C32786; Tue, 30 Jul 2024 00:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300891; bh=pyBJdtxBPz3GxnxSNiZhE22PkJY5jWrFTCpJgLxoSPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nrX492OoCnh9cqPzI2ECj3ndx2/kRnZovbDDylir8Resp4oovk1IcuXpQHtGrdn/g saNlq1qg8Cn2yptfoEMzSOBSE5nFLqBgxNibgwyt1syuBAbFNN+In/YbBIFw+2pDG9 cHp8dySv0JIqJnjCRsa1MhAaOSQGgM1Pqa7T00K5iJaGoMQhYzIz/zoK1kBf69pAoS QoZPPijded91NMv8e+wK3EgtLnpatXyC7IXTFtKkmV7eQILbM9+kwBCY7ta5EhC5wN Pf6SXXtUStxJDnoBkcJrqGP6Eagk/8gvb7DaDpbW/sAwbozaq1p811m+HzOt+4b3j5 lF1Tbm7crJZUQ== From: Song Liu To: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com, joe.lawrence@redhat.com, nathan@kernel.org, morbo@google.com, justinstitt@google.com, mcgrof@kernel.org, thunder.leizhen@huawei.com, kees@kernel.org, kernel-team@meta.com, song@kernel.org, mmaurer@google.com, samitolvanen@google.com, mhiramat@kernel.org, rostedt@goodmis.org Subject: [PATCH 1/3] kallsyms: Do not cleanup .llvm. suffix before sorting symbols Date: Mon, 29 Jul 2024 17:54:31 -0700 Message-ID: <20240730005433.3559731-2-song@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730005433.3559731-1-song@kernel.org> References: <20240730005433.3559731-1-song@kernel.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Cleaning up the symbols causes various issues afterwards. Let's sort the list based on original name and handle suffix later during the symbol lookup. Signed-off-by: Song Liu --- scripts/kallsyms.c | 31 ++----------------------------- scripts/link-vmlinux.sh | 4 ---- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 0ed873491bf5..123dab0572f8 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -5,8 +5,7 @@ * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * - * Usage: kallsyms [--all-symbols] [--absolute-percpu] - * [--lto-clang] in.map > out.S + * Usage: kallsyms [--all-symbols] [--absolute-percpu] in.map > out.S * * Table compression uses all the unused char codes on the symbols and * maps these to the most used substrings (tokens). For instance, it might @@ -62,7 +61,6 @@ static struct sym_entry **table; static unsigned int table_size, table_cnt; static int all_symbols; static int absolute_percpu; -static int lto_clang; static int token_profit[0x10000]; @@ -73,8 +71,7 @@ static unsigned char best_table_len[256]; static void usage(void) { - fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] " - "[--lto-clang] in.map > out.S\n"); + fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] in.map > out.S\n"); exit(1); } @@ -344,25 +341,6 @@ static bool symbol_absolute(const struct sym_entry *s) return s->percpu_absolute; } -static void cleanup_symbol_name(char *s) -{ - char *p; - - /* - * ASCII[.] = 2e - * ASCII[0-9] = 30,39 - * ASCII[A-Z] = 41,5a - * ASCII[_] = 5f - * ASCII[a-z] = 61,7a - * - * As above, replacing the first '.' in ".llvm." with '\0' does not - * affect the main sorting, but it helps us with subsorting. - */ - p = strstr(s, ".llvm."); - if (p) - *p = '\0'; -} - static int compare_names(const void *a, const void *b) { int ret; @@ -526,10 +504,6 @@ static void write_src(void) output_address(relative_base); printf("\n"); - if (lto_clang) - for (i = 0; i < table_cnt; i++) - cleanup_symbol_name((char *)table[i]->sym); - sort_symbols_by_name(); output_label("kallsyms_seqs_of_names"); for (i = 0; i < table_cnt; i++) @@ -807,7 +781,6 @@ int main(int argc, char **argv) static const struct option long_options[] = { {"all-symbols", no_argument, &all_symbols, 1}, {"absolute-percpu", no_argument, &absolute_percpu, 1}, - {"lto-clang", no_argument, <o_clang, 1}, {}, }; diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index f7b2503cdba9..22d0bc843986 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -156,10 +156,6 @@ kallsyms() kallsymopt="${kallsymopt} --absolute-percpu" fi - if is_enabled CONFIG_LTO_CLANG; then - kallsymopt="${kallsymopt} --lto-clang" - fi - info KSYMS "${2}.S" scripts/kallsyms ${kallsymopt} "${1}" > "${2}.S" From patchwork Tue Jul 30 00:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 13746050 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DD00C2C6; Tue, 30 Jul 2024 00:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300899; cv=none; b=V5hoXLUSW5y9a0SM3zZne3OY0OcIuDaDPkbjZc93tguvQr+8iPAmUG1bzzWa0IzWtZaWHN4on1h1PVdlpjHzUzX9/GePmwJXkvrjTDnIynNwPyUHIJk/7DHP+k34Ha3FIpgMEyzirqJarxBDPgsdGGsi2hXPCi998ceZXYwZj4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300899; c=relaxed/simple; bh=bVMhb29bKic+8kXfwnvb7g3zkaGOGr5ivu5L90mSt5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mkPEh6sHIndv9SEy81C4dA+7+2ue16K/q1ntS+1DU78ZjugaXbATBr1Fb3Ddg57q3rzw8ZPkm58at9KrgixaSyygyPd+fcxsr7UiLZ+f+708G/tMjAs1EvDcfiL69oYgpejN58Qk8Of7YfQtO4JAJ+jSwrVzq+EkjbcB80xQbzw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mWNO4laJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mWNO4laJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BCE2C32786; Tue, 30 Jul 2024 00:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300899; bh=bVMhb29bKic+8kXfwnvb7g3zkaGOGr5ivu5L90mSt5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mWNO4laJlL513lNwUaEH2u81ihF+9FlWZbHk3tAtEau4/BYLMu0AZQiM7hSKy2I15 o3B0Z8LVawdEaIMKh8NAYxPKS8QjbrrtJ9hcW2ow/Uo/I+w/m/vHBP/T6Qg0xLuzlG 4I9owC4pBoCOJOu3poii+yWNE21Av1kR6woqfDh6ms1Mei5jl8mV1CWYCm8vT7Hctz miqo+/YpGOP9vfrO7CNYWlbrlJ8SQNYweu8mmp1w8smdDxfiK/7LBv8fUpXKko5O6S s25OKJ4FBAWZD0XrLHTwWPu7c+CpGJdw3DGPA8nIi0XTnD0o4/rtVgSqk8vrdFaj40 Ci6lBkqN3vMMw== From: Song Liu To: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com, joe.lawrence@redhat.com, nathan@kernel.org, morbo@google.com, justinstitt@google.com, mcgrof@kernel.org, thunder.leizhen@huawei.com, kees@kernel.org, kernel-team@meta.com, song@kernel.org, mmaurer@google.com, samitolvanen@google.com, mhiramat@kernel.org, rostedt@goodmis.org Subject: [PATCH 2/3] kallsyms: Add APIs to match symbol without .llmv. suffix. Date: Mon, 29 Jul 2024 17:54:32 -0700 Message-ID: <20240730005433.3559731-3-song@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730005433.3559731-1-song@kernel.org> References: <20240730005433.3559731-1-song@kernel.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With CONFIG_LTO_CLANG=y, the compiler may add suffix to function names to avoid duplication. This causes confusion with users of kallsyms. On one hand, users like livepatch are required to match the symbols exactly. On the other hand, users like kprobe would like to match to original function names. Solve this by splitting kallsyms APIs. Specifically, existing APIs now should match the symbols exactly. Add two APIs that matches the full symbol, or only the part without .llvm.suffix. Specifically, the following two APIs are added: 1. kallsyms_lookup_name_or_prefix() 2. kallsyms_on_each_match_symbol_or_prefix() These APIs will be used by kprobe. Also cleanup some code and adjust kallsyms_selftests accordingly. Signed-off-by: Song Liu --- include/linux/kallsyms.h | 14 +++++++ kernel/kallsyms.c | 83 ++++++++++++++++++++++++++------------ kernel/kallsyms_selftest.c | 22 +--------- 3 files changed, 73 insertions(+), 46 deletions(-) diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index c3f075e8f60c..09b2d2099107 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -74,9 +74,12 @@ int kallsyms_on_each_symbol(int (*fn)(void *, const char *, unsigned long), void *data); int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long), const char *name, void *data); +int kallsyms_on_each_match_symbol_or_prefix(int (*fn)(void *, unsigned long), + const char *name, void *data); /* Lookup the address for a symbol. Returns 0 if not found. */ unsigned long kallsyms_lookup_name(const char *name); +unsigned long kallsyms_lookup_name_or_prefix(const char *name); extern int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize, @@ -104,6 +107,11 @@ static inline unsigned long kallsyms_lookup_name(const char *name) return 0; } +static inline unsigned long kallsyms_lookup_name_or_prefix(const char *name) +{ + return 0; +} + static inline int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize, unsigned long *offset) @@ -165,6 +173,12 @@ static inline int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long) { return -EOPNOTSUPP; } + +static inline int kallsyms_on_each_match_symbol_or_prefix(int (*fn)(void *, unsigned long), + const char *name, void *data) +{ + return -EOPNOTSUPP; +} #endif /*CONFIG_KALLSYMS*/ static inline void print_ip_sym(const char *loglvl, unsigned long ip) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index fb2c77368d18..4285dd85d814 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -164,9 +164,6 @@ static void cleanup_symbol_name(char *s) { char *res; - if (!IS_ENABLED(CONFIG_LTO_CLANG)) - return; - /* * LLVM appends various suffixes for local functions and variables that * must be promoted to global scope as part of LTO. This can break @@ -181,13 +178,13 @@ static void cleanup_symbol_name(char *s) return; } -static int compare_symbol_name(const char *name, char *namebuf) +static int compare_symbol_name(const char *name, char *namebuf, bool exact_match) { - /* The kallsyms_seqs_of_names is sorted based on names after - * cleanup_symbol_name() (see scripts/kallsyms.c) if clang lto is enabled. - * To ensure correct bisection in kallsyms_lookup_names(), do - * cleanup_symbol_name(namebuf) before comparing name and namebuf. - */ + int ret = strcmp(name, namebuf); + + if (exact_match || !ret) + return ret; + cleanup_symbol_name(namebuf); return strcmp(name, namebuf); } @@ -204,13 +201,17 @@ static unsigned int get_symbol_seq(int index) static int kallsyms_lookup_names(const char *name, unsigned int *start, - unsigned int *end) + unsigned int *end, + bool exact_match) { int ret; int low, mid, high; unsigned int seq, off; char namebuf[KSYM_NAME_LEN]; + if (!IS_ENABLED(CONFIG_LTO_CLANG)) + exact_match = true; + low = 0; high = kallsyms_num_syms - 1; @@ -219,7 +220,7 @@ static int kallsyms_lookup_names(const char *name, seq = get_symbol_seq(mid); off = get_symbol_offset(seq); kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); - ret = compare_symbol_name(name, namebuf); + ret = compare_symbol_name(name, namebuf, exact_match); if (ret > 0) low = mid + 1; else if (ret < 0) @@ -236,7 +237,7 @@ static int kallsyms_lookup_names(const char *name, seq = get_symbol_seq(low - 1); off = get_symbol_offset(seq); kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); - if (compare_symbol_name(name, namebuf)) + if (compare_symbol_name(name, namebuf, exact_match)) break; low--; } @@ -248,7 +249,7 @@ static int kallsyms_lookup_names(const char *name, seq = get_symbol_seq(high + 1); off = get_symbol_offset(seq); kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); - if (compare_symbol_name(name, namebuf)) + if (compare_symbol_name(name, namebuf, exact_match)) break; high++; } @@ -268,13 +269,35 @@ unsigned long kallsyms_lookup_name(const char *name) if (!*name) return 0; - ret = kallsyms_lookup_names(name, &i, NULL); + ret = kallsyms_lookup_names(name, &i, NULL, true); if (!ret) return kallsyms_sym_address(get_symbol_seq(i)); return module_kallsyms_lookup_name(name); } +/* + * Lookup the address for this symbol. + * + * With CONFIG_LTO_CLANG=y, if there is no exact match, also try lookup + * symbol.llvm.. + */ +unsigned long kallsyms_lookup_name_or_prefix(const char *name) +{ + unsigned long addr; + + addr = kallsyms_lookup_name(name); + + if (!addr && IS_ENABLED(CONFIG_LTO_CLANG)) { + int ret, i; + + ret = kallsyms_lookup_names(name, &i, NULL, false); + if (!ret) + addr = kallsyms_sym_address(get_symbol_seq(i)); + } + return addr; +} + /* * Iterate over all symbols in vmlinux. For symbols from modules use * module_kallsyms_on_each_symbol instead. @@ -303,7 +326,25 @@ int kallsyms_on_each_match_symbol(int (*fn)(void *, unsigned long), int ret; unsigned int i, start, end; - ret = kallsyms_lookup_names(name, &start, &end); + ret = kallsyms_lookup_names(name, &start, &end, true); + if (ret) + return 0; + + for (i = start; !ret && i <= end; i++) { + ret = fn(data, kallsyms_sym_address(get_symbol_seq(i))); + cond_resched(); + } + + return ret; +} + +int kallsyms_on_each_match_symbol_or_prefix(int (*fn)(void *, unsigned long), + const char *name, void *data) +{ + int ret; + unsigned int i, start, end; + + ret = kallsyms_lookup_names(name, &start, &end, false); if (ret) return 0; @@ -450,8 +491,6 @@ const char *kallsyms_lookup(unsigned long addr, int lookup_symbol_name(unsigned long addr, char *symname) { - int res; - symname[0] = '\0'; symname[KSYM_NAME_LEN - 1] = '\0'; @@ -462,16 +501,10 @@ int lookup_symbol_name(unsigned long addr, char *symname) /* Grab name */ kallsyms_expand_symbol(get_symbol_offset(pos), symname, KSYM_NAME_LEN); - goto found; + return 0; } /* See if it's in a module. */ - res = lookup_module_symbol_name(addr, symname); - if (res) - return res; - -found: - cleanup_symbol_name(symname); - return 0; + return lookup_module_symbol_name(addr, symname); } /* Look up a kernel symbol and return it in a text buffer. */ diff --git a/kernel/kallsyms_selftest.c b/kernel/kallsyms_selftest.c index 2f84896a7bcb..873f7c445488 100644 --- a/kernel/kallsyms_selftest.c +++ b/kernel/kallsyms_selftest.c @@ -187,31 +187,11 @@ static void test_perf_kallsyms_lookup_name(void) stat.min, stat.max, div_u64(stat.sum, stat.real_cnt)); } -static bool match_cleanup_name(const char *s, const char *name) -{ - char *p; - int len; - - if (!IS_ENABLED(CONFIG_LTO_CLANG)) - return false; - - p = strstr(s, ".llvm."); - if (!p) - return false; - - len = strlen(name); - if (p - s != len) - return false; - - return !strncmp(s, name, len); -} - static int find_symbol(void *data, const char *name, unsigned long addr) { struct test_stat *stat = (struct test_stat *)data; - if (strcmp(name, stat->name) == 0 || - (!stat->perf && match_cleanup_name(name, stat->name))) { + if (!strcmp(name, stat->name)) { stat->real_cnt++; stat->addr = addr; From patchwork Tue Jul 30 00:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 13746051 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5C98DDBC; Tue, 30 Jul 2024 00:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300906; cv=none; b=DcxxH3NV3b0D8q69cSM4abaD+LsSXDVt+OrLKlNNWNwZNxtJ+8lmCU47MCozoB7VcWB5up2N1/vWrLebwLQV97nxAltznNUrc7Zwxb0NoLQqQ/Z165/nkz08k5MuT3TtUIyIoM3T8OJjoXlwN4P7Dd2zFglFsuhvwkchYZSuZaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300906; c=relaxed/simple; bh=/OpeTm/YKTNnJ+pITyoC+SupkMdf0BnvgwwNZMCcjPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uRYMid0GvCnfpqcfTv1OUr3cREf3D6xc+O97NRz7v6LTgtiWKNTfiZJ1N091CvRc5n0i8GJxYbcSp49mSx6PWh6zdAsNzGb+yLfVW5ZP6GiuriUjWMbDnyiFrZGvmMGEbOL1DAhBHsPdARApwu+Qw77RlpPE9D+hvfBVA5ZW5kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L+n6hk3g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L+n6hk3g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 758C6C4AF0B; Tue, 30 Jul 2024 00:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300906; bh=/OpeTm/YKTNnJ+pITyoC+SupkMdf0BnvgwwNZMCcjPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L+n6hk3g1+Idcaxk+ZF6oRozb9Fp2rVfjxAM+YIfKd+msio201ZUqdd8mcOw2rU2m /Tcx6caiuE4EIcMsj173cPdzbE0ujdB+BM2ZIS14qmgfmIQrC/2TXt3MIm+u4JWWxJ RkksQTSIGZWe86rNP5Rot6ds/zFeXtxD6oGVQvv6LA/8/GZu4KgPzjpm907Y7IT7sr BORRX36pCwNvgzaSS0pYV+IU4EHuAPbR6UwnEvWL+0jHgGLG/MKzONTzShTQGZvodu 73Yu/5lyA6ifBL8gnSxlexvr8wrVQAFHHEpmA/oTcbdmltrJ5N7lnXyc04IvFQLXss LR84+50UqzaCw== From: Song Liu To: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com, joe.lawrence@redhat.com, nathan@kernel.org, morbo@google.com, justinstitt@google.com, mcgrof@kernel.org, thunder.leizhen@huawei.com, kees@kernel.org, kernel-team@meta.com, song@kernel.org, mmaurer@google.com, samitolvanen@google.com, mhiramat@kernel.org, rostedt@goodmis.org Subject: [PATCH 3/3] tracing/kprobes: Use APIs that matches symbols with .llvm. suffix Date: Mon, 29 Jul 2024 17:54:33 -0700 Message-ID: <20240730005433.3559731-4-song@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730005433.3559731-1-song@kernel.org> References: <20240730005433.3559731-1-song@kernel.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the new kallsyms APIs that matches symbols name with .llvm. suffix. This allows userspace tools to get kprobes on the expected function name, while the actual symbol has a .llvm. suffix. This only effects kernel compared with CONFIG_LTO_CLANG. Signed-off-by: Song Liu --- kernel/trace/trace_kprobe.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 61a6da808203..c319382c1a09 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -202,7 +202,8 @@ unsigned long trace_kprobe_address(struct trace_kprobe *tk) if (tk->symbol) { addr = (unsigned long) - kallsyms_lookup_name(trace_kprobe_symbol(tk)); + kallsyms_lookup_name_or_prefix(trace_kprobe_symbol(tk)); + if (addr) addr += tk->rp.kp.offset; } else { @@ -766,8 +767,13 @@ static unsigned int number_of_same_symbols(const char *mod, const char *func_nam { struct sym_count_ctx ctx = { .count = 0, .name = func_name }; - if (!mod) + if (!mod) { kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count); + if (IS_ENABLED(CONFIG_LTO_CLANG) && !ctx.count) { + kallsyms_on_each_match_symbol_or_prefix( + count_symbols, func_name, &ctx.count); + } + } module_kallsyms_on_each_symbol(mod, count_mod_symbols, &ctx);