From patchwork Mon Feb 28 05:34:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maninder Singh X-Patchwork-Id: 12762389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5D21C433EF for ; Mon, 28 Feb 2022 06:00:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233114AbiB1GBN (ORCPT ); Mon, 28 Feb 2022 01:01:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233094AbiB1GBL (ORCPT ); Mon, 28 Feb 2022 01:01:11 -0500 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67A2652E16 for ; Sun, 27 Feb 2022 22:00:31 -0800 (PST) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20220228060025epoutp01b61cb6d35a42c813d5c22536ddfd88ee~X3cSTRqze2997529975epoutp01U for ; Mon, 28 Feb 2022 06:00:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20220228060025epoutp01b61cb6d35a42c813d5c22536ddfd88ee~X3cSTRqze2997529975epoutp01U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1646028025; bh=8pZN1tElVEXDJhstfxtn6+EA198G1rh7eUyLBdYGKU8=; h=From:To:Cc:Subject:Date:References:From; b=ELe+8fkZdmsMF+ZXQxDrV49UatMIIuThGgH9xFd514WFGuutFaSJNl9FwfDYDWApa mJ4woWYSkvkEZUyK2m3qyolYOQl3FXWTemvGMzNQCG09Y51HBDyTjNkJXkYFtvuZGb LUIkjmeoRFAh34WnGCG8+Xry0iLUpy5qk7K5evh4= Received: from epsmges5p3new.samsung.com (unknown [182.195.42.75]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20220228060024epcas5p41dc883a6934509f392ce5f1d34e283a2~X3cRx7bEZ1434714347epcas5p4D; Mon, 28 Feb 2022 06:00:24 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 2C.91.05590.8F46C126; Mon, 28 Feb 2022 15:00:24 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20220228053457epcas5p1dac3fced39d1594f8fdfc5e64e23ac73~X3GDR45st0083200832epcas5p1R; Mon, 28 Feb 2022 05:34:57 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220228053457epsmtrp22185cfbe4fec5003ae4218c7c1ac7c8c~X3GDQ84SN1643616436epsmtrp2W; Mon, 28 Feb 2022 05:34:57 +0000 (GMT) X-AuditID: b6c32a4b-739ff700000015d6-4c-621c64f8b62b Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id F6.70.29871.10F5C126; Mon, 28 Feb 2022 14:34:57 +0900 (KST) Received: from localhost.localdomain (unknown [107.109.224.44]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220228053454epsmtip12cc27be966540d88e232d2f26568e758~X3GAq_pd12193521935epsmtip1X; Mon, 28 Feb 2022 05:34:54 +0000 (GMT) From: Maninder Singh To: mcgrof@kernel.org, pmladek@suse.com, rostedt@goodmis.org, senozhatsky@chromium.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, akpm@linux-foundation.org, wangkefeng.wang@huawei.com Cc: v.narang@samsung.com, swboyd@chromium.org, ojeda@kernel.or, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, avimalin@gmail.com, atomlin@redhat.com, Maninder Singh Subject: [PATCH 1/1] kallsyms: enhance %pS/s/b printing when KALLSYSMS is disabled Date: Mon, 28 Feb 2022 11:04:47 +0530 Message-Id: <20220228053447.1584704-1-maninder1.s@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01SfUxTVxzNfd/gnj6qi1dwoBWW1GnropC3RJk6Zp4YMowly4yLVPtsDVC7 tujEP6z4MangmixEaLEoYQmpSKEpDvmosSi0SiJVCBNhVikjI5ENiiuhi0r7MPOfm3POPb97 cn65FCr6A0+kjmoMvE6jKBQT8ditbolk45xy9aFNYVcKW+NoJNiK0isIe6+2EWcDd4dI9kl7 DcEarWGcHbPYCLa79gLG/m4eB2z17ILl7dhrnHVfDCBsR0sdwfaOjCOsx3cVsGdCz8F2hrMa /Rh32zJKcufcwwvHvVc4Nzv0CHBOexnBeasiGGfz7eX6TQXc3+5BgrvssgPO4RrEuJAzOZfe H79VyRcePc7rZJn58erR8g6gvSX78b/R54gRhD81AYqCzBY4Yc4wgXhKxHQAaHXdxwQyA6Cv dAYxgbgF8i+AEf+GKI4OWC7WL5q6AOztNBECmQWwrsmMR10EI4X29s6YawXTD+DAcCcaJSjz BEBz6DIWdS1n5HDGGkajGGPSYPlv3himmUz4S6kTE/JSYPXjMCnoCdBXHYzp6IJ+ttUaexQy XgoagyFCGMiCFT/bcQEvh5O9LlLAiTA01UUIA5cAbL7UgwmkCsDQ3UEguL6EQf91PLoblJFA R7tMkD+BlQ+aECF5KayIBBFBp2Gb7T1Og+eeNi8GJ8HQ9PRiAw52h92YsMnv4WTNDDCDFMsH hSwfFLL8n3wNoHawitfqi1S8Pl27WcOfkOoVRfpijUp6+FiRE8S+4Po9beBl4B+pByAU8ABI oeIVNImvOiSilYqTJbzu2EFdcSGv94AkChOvpB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abft7Q72op/MO6W03nzWu+af8IeNsgq34VQdui+MG 61jKBeetnrL6xbJi7XUvYv58FawqkKoWXcH4wenen0csW1fqHHtS9FKjMdpiNvsmSfc959KP /u0t+GTF0K+42aGwXKi35Dwjm8wb+6YbKp8vPRDlrK5v85zfer35kPi6I69q7UQ7+3Us229/ i13WMf1t35NbtXu//ot1OJ0Uu3Tyztr70s3y5WG9eqvesCnN36rO6+sndjs2JXmb3URuHbdO i4ss1wXnfH727PbRB4nvpgikJaQvELPYdfrfpX0bLNef6BJfoKnQfPfp0pR3gdvP6QcqsRRn JBpqMRcVJwIANEzBmRcDAAA= X-CMS-MailID: 20220228053457epcas5p1dac3fced39d1594f8fdfc5e64e23ac73 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20220228053457epcas5p1dac3fced39d1594f8fdfc5e64e23ac73 References: Precedence: bulk List-ID: with commit '82b37e632513 ("kallsyms: print module name in %ps/S case when KALLSYMS is disabled"), module name printing was enhanced. As per suggestion from Petr Mladek , covering other flavours also to print build id also. for %pB no change as it needs to know symbol name to adjust address value which can't be done without KALLSYMS. original output with KALLSYMS: [8.842129] ps function_1 [crash] [8.842735] pS function_1+0x4/0x2c [crash] [8.842890] pSb function_1+0x4/0x2c [crash b367e79021b9f3b0172f9a36d4261c1f528ca1b3] [8.843175] pB function_1+0x4/0x2c [crash] [8.843362] pBb function_1+0x4/0x2c [crash b367e79021b9f3b0172f9a36d4261c1f528ca1b3] original output without KALLSYMS: [12.487424] ps 0xffff800000eb008c [12.487598] pS 0xffff800000eb008c [12.487723] pSb 0xffff800000eb008c [12.487850] pB 0xffff800000eb008c [12.487967] pBb 0xffff800000eb008c With patched kernel without KALLSYMS: [9.205207] ps 0xffff800000eb008c [crash] [9.205564] pS 0xffff800000eb0000+0x8c [crash] [9.205757] pSb 0xffff800000eb0000+0x8c [crash b367e79021b9f3b0172f9a36d4261c1f528ca1b3] [9.206066] pB 0xffff800000eb0000+0x8c [crash] [9.206257] pBb 0xffff800000eb0000+0x8c [crash b367e79021b9f3b0172f9a36d4261c1f528ca1b3] Suggested-by: Petr Mladek Co-developed-by: Vaneet Narang Signed-off-by: Vaneet Narang Signed-off-by: Maninder Singh Reported-by: kernel test robot --- earlier discussion: https://lkml.org/lkml/2022/2/10/185 include/linux/kallsyms.h | 27 -------------- kernel/module.c | 4 +-- lib/vsprintf.c | 76 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 31 deletions(-) diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index ebfeb6099c28..5fb17dd4b6fa 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -163,33 +163,6 @@ static inline bool kallsyms_show_value(const struct cred *cred) return false; } -#ifdef CONFIG_MODULES -static inline int fill_minimal_module_info(char *sym, int size, unsigned long value) -{ - struct module *mod; - unsigned long offset; - int ret = 0; - - preempt_disable(); - mod = __module_address(value); - if (mod) { - offset = value - (unsigned long)mod->core_layout.base; - snprintf(sym, size - 1, "0x%lx+0x%lx [%s]", - (unsigned long)mod->core_layout.base, offset, mod->name); - - sym[size - 1] = '\0'; - ret = 1; - } - - preempt_enable(); - return ret; -} -#else -static inline int fill_minimal_module_info(char *sym, int size, unsigned long value) -{ - return 0; -} -#endif /*CONFIG_MODULES*/ #endif /*CONFIG_KALLSYMS*/ static inline void print_ip_sym(const char *loglvl, unsigned long ip) diff --git a/kernel/module.c b/kernel/module.c index 46a5c2ed1928..ccccb135c7fe 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1465,12 +1465,10 @@ resolve_symbol_wait(struct module *mod, return ksym; } -#ifdef CONFIG_KALLSYMS static inline bool sect_empty(const Elf_Shdr *sect) { return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0; } -#endif /* * /sys/module/foo/sections stuff @@ -2799,7 +2797,7 @@ static void add_kallsyms(struct module *mod, const struct load_info *info) } #endif /* CONFIG_KALLSYMS */ -#if IS_ENABLED(CONFIG_KALLSYMS) && IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) +#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) static void init_build_id(struct module *mod, const struct load_info *info) { const Elf_Shdr *sechdr; diff --git a/lib/vsprintf.c b/lib/vsprintf.c index cb7345ff57f3..d4a24fd29494 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -980,6 +980,80 @@ char *bdev_name(char *buf, char *end, struct block_device *bdev, } #endif +#if !defined(CONFIG_KALLSYMS) && defined(CONFIG_MODULES) +static int sprint_module_info(char *buf, char *end, unsigned long value, + const char *fmt) +{ + struct module *mod; + unsigned long offset = 1; + unsigned long base; + int ret = 0; + const char *modname; + int modbuildid = 0; + int len; +#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) + const unsigned char *buildid = NULL; +#endif + + if (is_ksym_addr(value)) + return 0; + + if (*fmt == 'B' && fmt[1] == 'b') + modbuildid = 1; + else if (*fmt == 'S' && (fmt[1] == 'b' || (fmt[1] == 'R' && fmt[2] == 'b'))) + modbuildid = 1; + else if (*fmt != 's') { + /* + * do nothing. + */ + } else + offset = 0; + + preempt_disable(); + mod = __module_address(value); + if (mod) { + ret = 1; + modname = mod->name; +#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) + if (modbuildid) + buildid = mod->build_id; +#endif + if (offset) { + base = (unsigned long)mod->core_layout.base; + offset = value - base; + } + } + + preempt_enable(); + if (!ret) + return 0; + + /* address belongs to module */ + if (offset) + len = sprintf(buf, "0x%lx+0x%lx", base, offset); + else + len = sprintf(buf, "0x%lx", value); + + len += sprintf(buf + len, " [%s", modname); +#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) + if (modbuildid && buildid) { + /* build ID should match length of sprintf */ + static_assert(sizeof(typeof_member(struct module, build_id)) == 20); + len += sprintf(buf + len, " %20phN", buildid); + } +#endif + len += sprintf(buf + len, "]"); + + return len; +} +#else +static inline int sprint_module_info(char *buf, char *end, unsigned long value, + const char *fmt) +{ + return 0; +} +#endif + static noinline_for_stack char *symbol_string(char *buf, char *end, void *ptr, struct printf_spec spec, const char *fmt) @@ -1005,7 +1079,7 @@ char *symbol_string(char *buf, char *end, void *ptr, return string_nocheck(buf, end, sym, spec); #else - if (fill_minimal_module_info(sym, KSYM_SYMBOL_LEN, value)) + if (sprint_module_info(sym, end, value, fmt)) return string_nocheck(buf, end, sym, spec); return special_hex_number(buf, end, value, sizeof(void *));