Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp254303pxf; Wed, 24 Mar 2021 04:29:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuhwsjBFgfj1AQSMXShAikM8rIRFR7CHshM1wfD440uOQL+L3Vpi6bk1fdQi3yqvkLMcAq X-Received: by 2002:a17:906:3385:: with SMTP id v5mr3124180eja.539.1616585389167; Wed, 24 Mar 2021 04:29:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616585389; cv=none; d=google.com; s=arc-20160816; b=zLU1M/Ni5wA1liqlWg9MS5sKdOTx2vv5v4vwCVMwKOgsnhNlufnkyG6bUQRoCO6VVR t3FtHrWzGQzxRko11n4ynZxwchk8ZooMkoYAMu+IUqLgXpXT6QIA7CpG+Pj+yzoaPaGN UkD5x/uZ9x5FGT9468oVYtQrsan81weTCaWhf7X1dswJURMItJsLArrtZtroZdZMBGKN YEsXNpgt0G1UBURUGLVqGdxjgi/AyZ15cm99o41f7Zpxu77Xe5vTESAzCFXyrRxwcT/N UlA9NKmgvp1YSxnV5wW9ea2H783IuPhNXbtfWCFfBVOF4E8cTaZDblgV+Wt/pr7xxK6u EkAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Ui3KK3mzwqbV9eLNTYNhSvBlcu0bQi8tP4Sx/vLrsFM=; b=NxOynW2hHUwA3jy+lPW68//eVwi1M106vdzof3bWNsUwfdfjohI6daIlVfVxEuEwOF trKRbKckw8AMiNAgRAeEd4lkERa5SF37G5xZpDl1dgGtL1l4vxXhuj5UYDyniNNWQZRm lFA3qQ4R4KgSIeTP15RtZUw7RBqVkPwmGtsUkeBmRh0J4WITpPvkrYcPDtJkPoFucYBt 4NG7jdtOmn8+kpwXAyEx3MhGhA0HrsngAoeuRIT7F4WX1hNNIfxpCpWpxordNuoHiFDd aAoksd/XyA6VuK5ep97B+UrDsSyZO03uGeu2HZY/7Cw5peuSZ0aslM7k1NjPfkk75xL7 enlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=RW6zzpKK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i6si1505797edu.313.2021.03.24.04.29.26; Wed, 24 Mar 2021 04:29:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=RW6zzpKK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235356AbhCXJ5U (ORCPT + 99 others); Wed, 24 Mar 2021 05:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235338AbhCXJ5Q (ORCPT ); Wed, 24 Mar 2021 05:57:16 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A6ECC0613DE for ; Wed, 24 Mar 2021 02:57:16 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id u5so31812519ejn.8 for ; Wed, 24 Mar 2021 02:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Ui3KK3mzwqbV9eLNTYNhSvBlcu0bQi8tP4Sx/vLrsFM=; b=RW6zzpKKOYU4TonZHWyHu86rXkdv9zk1Kn+dfUmAdQHSnL8x7WIErObnzx9/rde0cl R+mxfCOCbfNcgLEiAGTKpJyJgLqMS6bNhmImpdWBezU4dPQpX08sZi9eQdcsYiiyIJ2U Im+zCCfJX8PghtZ0tLRFjRwUsEypOLYW/flzA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Ui3KK3mzwqbV9eLNTYNhSvBlcu0bQi8tP4Sx/vLrsFM=; b=Bl9OGLYmwR8Gq4AHwTLNcPQ8X8HuAP8Lc3yjqFZ8kRErqoo2XSD1Avb+huTiJRM85Y Si2SpRtoEnOYJRFE20XM/w0+1w3qlamAi53NYfjX4Cp5WTORzRk9uGw71SiZfCIyQ5DL W/9yszw11rpRW89T7WZ0mt8fwpoy8cmSt0gQqVT/YbUoqDpLKthbonNqB7VX+dSkRDxJ KLRNRV/MeMESoBpdCA41TF14UWx7rmRC4Gv4P7/+O7KPCoMCaHtHBWq4uBE1s4Y6ORwl 9wLDRbsaGTUphlAtu+DLMGKnORmG8p1wjnoAioNFmfSnTVeQvlEFLPVqvv55fLQMnGi8 b8xg== X-Gm-Message-State: AOAM533nlYabqbaUNKC5LioST/yKJGlReK3gkZtiiGx3ZkrwS5d7JbmD AXSFXQVZCEgAzAzAyQD+DLcHxA== X-Received: by 2002:a17:906:2710:: with SMTP id z16mr2752772ejc.176.1616579834782; Wed, 24 Mar 2021 02:57:14 -0700 (PDT) Received: from [192.168.1.149] ([80.208.71.248]) by smtp.gmail.com with ESMTPSA id hd37sm645541ejc.114.2021.03.24.02.57.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Mar 2021 02:57:14 -0700 (PDT) Subject: Re: [PATCH v2 04/12] module: Add printk format to add module build ID to stacktraces To: Stephen Boyd , Andrew Morton Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Alexei Starovoitov , Jessica Yu , Evan Green , Hsin-Yi Wang , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , linux-doc@vger.kernel.org, Matthew Wilcox References: <20210324020443.1815557-1-swboyd@chromium.org> <20210324020443.1815557-5-swboyd@chromium.org> From: Rasmus Villemoes Message-ID: <6dfb8ca2-20f3-e58a-ad6b-db6a6472afe0@rasmusvillemoes.dk> Date: Wed, 24 Mar 2021 10:57:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210324020443.1815557-5-swboyd@chromium.org> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/03/2021 03.04, Stephen Boyd wrote: > @@ -2778,6 +2793,10 @@ static inline void layout_symtab(struct module *mod, struct load_info *info) > static void add_kallsyms(struct module *mod, const struct load_info *info) > { > } > + > +static void init_build_id(struct module *mod, const struct load_info *info) > +{ > +} > #endif /* CONFIG_KALLSYMS */ > > static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigned int num) > @@ -4004,6 +4023,7 @@ static int load_module(struct load_info *info, const char __user *uargs, > goto free_arch_cleanup; > } > > + init_build_id(mod, info); > dynamic_debug_setup(mod, info->debug, info->num_debug); > > /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */ > @@ -4235,7 +4255,7 @@ void * __weak dereference_module_function_descriptor(struct module *mod, > const char *module_address_lookup(unsigned long addr, > unsigned long *size, > unsigned long *offset, > - char **modname, > + char **modname, unsigned char **modbuildid, It's an existing defect with modname, but surely this should take a "const unsigned char **modbuildid", no? > char *namebuf) > { > const char *ret = NULL; > @@ -4246,6 +4266,8 @@ const char *module_address_lookup(unsigned long addr, > if (mod) { > if (modname) > *modname = mod->name; > + if (modbuildid) > + *modbuildid = mod->build_id; > > ret = find_kallsyms_symbol(mod, addr, size, offset); > } > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index 41ddc353ebb8..9cd62e84e4aa 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -961,13 +961,15 @@ char *symbol_string(char *buf, char *end, void *ptr, > char sym[KSYM_SYMBOL_LEN]; > #endif > > - if (fmt[1] == 'R') > + if (fmt[1] == 'R' || fmt[1] == 'r') > ptr = __builtin_extract_return_addr(ptr); > value = (unsigned long)ptr; > > #ifdef CONFIG_KALLSYMS > if (*fmt == 'B') > sprint_backtrace(sym, value); > + else if (*fmt == 'S' && (fmt[1] == 'b' || fmt[1] == 'r')) > + sprint_symbol_stacktrace(sym, value); > else if (*fmt != 's') > sprint_symbol(sym, value); > else > @@ -2129,6 +2131,8 @@ early_param("no_hash_pointers", no_hash_pointers_enable); > * - 'S' For symbolic direct pointers (or function descriptors) with offset > * - 's' For symbolic direct pointers (or function descriptors) without offset > * - '[Ss]R' as above with __builtin_extract_return_addr() translation > + * - '[Ss]r' as above with __builtin_extract_return_addr() translation and module build ID > + * - '[Ss]b' as above with module build ID (for use in backtraces) The code doesn't quite match the comment. The lowercase s is not handled (i.e., there's no way to say "without offset, with build ID"). You don't have to fix the code to support that right now, the whole kallsyms vsprintf code needs to be reworked inside-out anyway (having vsnprint call sprint_symbol* which builds the output using snprintf() calls makes me cringe), so please just replace [Ss] by S to make the comment match the code - I notice that you did only document the S variant in printk-formats.rst. Is there any reason you didn't just make b an optional flag that could be specified with or without R? I suppose the parsing is more difficult with several orthogonal flags (see escaped_string()), but it's a little easier to understand. Dunno, it's not like we're gonna think of 10 other things that could be printed for a symbol, so perhaps it's fine. Rasmus