From patchwork Fri Oct 28 19:40:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1023466wru; Fri, 28 Oct 2022 13:15:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7+H3V94r4g+BH2Kjv276wkHVBsfRYhH0Z9RCJdBnLuSw4R6e3YzI++SaF2X+0QujAEiB9a X-Received: by 2002:a63:6b49:0:b0:46a:fcba:308f with SMTP id g70-20020a636b49000000b0046afcba308fmr1124767pgc.8.1666988143733; Fri, 28 Oct 2022 13:15:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666988143; cv=none; d=google.com; s=arc-20160816; b=BIBY+23Zm/2OYeaEDFDoIptP0LUvzrZHqQTqCeAd60DD7SYy/WN26d97T7i1CQEdSc gb9VC9Hpebbev9Qntqas//qIzo/S9XQBtdAlGZwxsnC28GXRkoiJ2pDu/gwB14Un138o JMzpdkareg4TCPYBsxkKgfjAJHU0G9U1LgjxL2Yzp0sPYue7Fdon/AY9K5iCIxlDlcuN wSH+zPbYszWwfn7FgO00TCr4kIgML8D/Vm70+jJwl2ph/nQp6/ckxV5d9+vz8PWRXd7v V8gQ0oIcdmw31/qE4H/hjF7UWxRO1sRFBHVVZvL2jFNH2a4D3KAb4qE0gYKKoz2jg61S VGrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=w2TcGA3omIeq3yxp81jgH+z11BiFQX/+KG2uxbRcnKg=; b=T/jHptytIFJ9u1VGAh+KrpOaK09gQ+WZRTPr3G711fz2p3jBCNX++GOLPZ64gopN4q uLpUpCz4ef7tjnvmodLh1Cnmt+DpCFBWo+VCtbMwkWC7cqtPPvYYRQnUnosWT2m+I65r k6HfU59wGW00OaLKsCLXrEs4LjlpZ8xjcrDtIULukvrRbZn2wOOP3Fweqt7Ge++g8q8V /SeqbWuYEWeohtVQBUZn8pyosohiseagQ+3n54p5IRyjsF/G11H2WxXao3GjQGwpsMnN +YgczEvioKf0dz85agifmoVG1KKHsL5xTY70HMqxpqEhdZHqMU3uAUCyi13OcLiOhXiR obXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=ks+sTiRY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z17-20020a631911000000b00434ac3b9915si6371936pgl.790.2022.10.28.13.15.30; Fri, 28 Oct 2022 13:15:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=ks+sTiRY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbiJ1TsX (ORCPT + 99 others); Fri, 28 Oct 2022 15:48:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230142AbiJ1TsS (ORCPT ); Fri, 28 Oct 2022 15:48:18 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11C6A24419D for ; Fri, 28 Oct 2022 12:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=w2TcGA3omIeq3yxp81jgH+z11BiFQX/+KG2uxbRcnKg=; b=ks+sTiRY6cSm9Wr/5Ajk0dRWgD 8FOEc3MhC69/nxeFJfF4MsM5p2kWKC0wMsBYpMgeuLjF4ynIO07RIqoFH10m/rbeHWi7aAjPcH4XL BL93ujKDf988/1YnHhVgktI3/a9FCh3gG44Sp2dT6uAXcGTfGB0X7JnbFnwtbMPXUnVHzi5hmXtjd iqLtkIK/EC2vzuPd3jlzDWNKIXLHwAqwxyGEx4o2T/I6hFbLiWgvf7q6KMMYp/eW0aF5Bvx+PJjO3 +eUjCJW1JFrIw8bbpdV88/LkK9ictwhcmKs/wwt4bIH9/j4C3Pkv0L8PFQlX6SMutqrEXhwsr7+3+ j/QVtvRQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooVKR-007ARB-1D; Fri, 28 Oct 2022 19:47:43 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B57CC300322; Fri, 28 Oct 2022 21:47:41 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 980AB2C6B7F85; Fri, 28 Oct 2022 21:47:41 +0200 (CEST) Message-ID: <20221028194453.330970755@infradead.org> User-Agent: quilt/0.66 Date: Fri, 28 Oct 2022 21:40:23 +0200 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, djwong@kernel.org, yujie.liu@intel.com, tglx@linutronix.de, jpoimboe@kernel.org, joao.moreira@intel.com, samitolvanen@google.com Subject: [PATCH 1/5] kallsyms: Revert "Take callthunks into account" References: <20221028194022.388521751@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747963760040765245?= X-GMAIL-MSGID: =?utf-8?q?1747963760040765245?= This is a full revert of commit: f1389181622a ("kallsyms: Take callthunks into account") The commit assumes a number of things that are not quite right. Notably it assumes every symbol has PADDING_BYTES in front of it that are not claimed by another symbol. This is not true; even when compiled with: -fpatchable-function-entry=${PADDING_BYTES},${PADDING_BYTES} Notably things like .cold subfunctions do not need to adhere to this change in ABI. It it also not true when build with CFI_CLANG, which claims these PADDING_BYTES in the __cfi_##name symbol. Once the prefix bytes are not consistent and or otherwise claimed the approach this patch takes goes out the window and kallsym resolution will report invalid symbol names. Therefore revert this to make room for another approach. Reported-by: Reported-by: kernel test robot Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/202210241614.2ae4c1f5-yujie.liu@intel.com --- kernel/kallsyms.c | 45 +++++---------------------------------------- 1 file changed, 5 insertions(+), 40 deletions(-) --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -293,12 +293,6 @@ static unsigned long get_symbol_pos(unsi return low; } -#ifdef CONFIG_FUNCTION_PADDING_BYTES -#define PADDING_BYTES CONFIG_FUNCTION_PADDING_BYTES -#else -#define PADDING_BYTES 0 -#endif - /* * Lookup an address but don't bother to find any names. */ @@ -306,25 +300,13 @@ int kallsyms_lookup_size_offset(unsigned unsigned long *offset) { char namebuf[KSYM_NAME_LEN]; - int ret; - - addr += PADDING_BYTES; if (is_ksym_addr(addr)) { get_symbol_pos(addr, symbolsize, offset); - ret = 1; - goto found; + return 1; } - - ret = !!module_address_lookup(addr, symbolsize, offset, NULL, NULL, namebuf); - if (!ret) { - ret = !!__bpf_address_lookup(addr, symbolsize, - offset, namebuf); - } -found: - if (ret && offset) - *offset -= PADDING_BYTES; - return ret; + return !!module_address_lookup(addr, symbolsize, offset, NULL, NULL, namebuf) || + !!__bpf_address_lookup(addr, symbolsize, offset, namebuf); } static const char *kallsyms_lookup_buildid(unsigned long addr, @@ -337,8 +319,6 @@ static const char *kallsyms_lookup_build namebuf[KSYM_NAME_LEN - 1] = 0; namebuf[0] = 0; - addr += PADDING_BYTES; - if (is_ksym_addr(addr)) { unsigned long pos; @@ -368,8 +348,6 @@ static const char *kallsyms_lookup_build found: cleanup_symbol_name(namebuf); - if (ret && offset) - *offset -= PADDING_BYTES; return ret; } @@ -396,8 +374,6 @@ int lookup_symbol_name(unsigned long add symname[0] = '\0'; symname[KSYM_NAME_LEN - 1] = '\0'; - addr += PADDING_BYTES; - if (is_ksym_addr(addr)) { unsigned long pos; @@ -425,8 +401,6 @@ int lookup_symbol_attrs(unsigned long ad name[0] = '\0'; name[KSYM_NAME_LEN - 1] = '\0'; - addr += PADDING_BYTES; - if (is_ksym_addr(addr)) { unsigned long pos; @@ -443,8 +417,6 @@ int lookup_symbol_attrs(unsigned long ad return res; found: - if (offset) - *offset -= PADDING_BYTES; cleanup_symbol_name(name); return 0; } @@ -470,15 +442,8 @@ static int __sprint_symbol(char *buffer, len = strlen(buffer); offset -= symbol_offset; - if (add_offset) { - char s = '+'; - - if ((long)offset < 0) { - s = '-'; - offset = 0UL - offset; - } - len += sprintf(buffer + len, "%c%#lx/%#lx", s, offset, size); - } + if (add_offset) + len += sprintf(buffer + len, "+%#lx/%#lx", offset, size); if (modname) { len += sprintf(buffer + len, " [%s", modname);