Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5313822rwb; Wed, 9 Aug 2023 02:01:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgKHCI3mvhD64LuiOd3+lVTpteapWalI2MMqPgmOFTbEknm0NfWG3pG6SSz0n1RkESqSvB X-Received: by 2002:a17:90a:a511:b0:261:2a59:dc38 with SMTP id a17-20020a17090aa51100b002612a59dc38mr1630570pjq.25.1691571708785; Wed, 09 Aug 2023 02:01:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691571708; cv=none; d=google.com; s=arc-20160816; b=gCc3+0N98PqK5+dK74IBbgld611zjLcm8qkHizytmSYqZI02XWSpg5PTAqRKmi0Knh qrBUu11474pXGouiGm0V0Wjgk/zcvYldz+0Chx3/R4K5JdHZnvRsLqd78CPwj7tY9ErQ rsSX6DyTR4fkulqpycNtc2xr/Q7Cd84Vbt+2MNWjHb0SJK/7J1b6x5AizPWxr1AFDlmc V5CzuErgt8BWsR4HsPXkPRXGEE6yLhhueRnJNEBx/5dXdAx0LoYE+2d2PRcihISkCuZj 3cXKBtUzPNcO9kdJ4kz3Er5KnERoZCBh7TakCj0wi2PAQDtyga24Tf9o1cTGbloz5PAc NGmA== 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=9++fJwb0WIVH7sC2LRJApi6BbZiu3wA5bopP2QtPAEU=; fh=o45i9bBrOE/GuAHaEwxsN59PvrZuIOmhioZFWcmA1tw=; b=oYwhR+c7pSkZYDomC7zPipUFp4c1fA8KBzrLUd9dcJBkWBOOxJzVEbB5Lo3+5d4JGz ckcJ2bGa6sUt+evi0P4cI6sW2h17V0W8b46KMsd5zGlLpwxhBGbmx/kvRFi6MqcQbSZ8 uXnEGIBuPIegos8JgYbhl8r5ZcBJCcBC9iYSgZDbV+SUdvyuAzEDbUuk7UsptemRWFUR 9UblM0wnLvIqRkCndC8ALp2Wc8ZbIPT9J3zHQVjak4LvU6NqAFkpd0N7Uop2ECmY3NBr 0SnvDPus5LjHaqLgoAjIZBPaS1TDflDqVmK7121MN+D4AHjFyDuqOtLXSZuBUsX1JVOd SZ5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=WJcEUOMG; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a17-20020a17090ad81100b0025bcf85bda2si987597pjv.7.2023.08.09.02.01.37; Wed, 09 Aug 2023 02:01:48 -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=casper.20170209 header.b=WJcEUOMG; 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 S231758AbjHIH1h (ORCPT + 99 others); Wed, 9 Aug 2023 03:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231661AbjHIH1C (ORCPT ); Wed, 9 Aug 2023 03:27:02 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E0A91BFE for ; Wed, 9 Aug 2023 00:27:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=9++fJwb0WIVH7sC2LRJApi6BbZiu3wA5bopP2QtPAEU=; b=WJcEUOMG4dlOgFQoGg/sVYODAg 8AizDoGFIfPhu69yxS8yJyLe6DvjzfjmguH3gKllCNKZ4Kcd3/SlvJn7uX90RvtFfbPeq9HkaiXnU rf7chfchoN9Bes6G+vz+IS2zUNjdKv1rK3xLUkx+6Zu/WfJ2To45py0yDxsQ0stHXrCQg0nSNvkWU osSrAsckSHWWaYZ5gKHeaNkbEMxjI8xgB/QyBUW+40/5lNvdirqOYQQsz0g8xMRN/iV8vCrT6kAj8 N02ywy1EbFxWn5zY4D7fn8kMOSFeI9Sglar+34/MleBPUCyCKpGWjvjTQLuaO0HNmmiFO/KRPI7eV sO7cqVMg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qTdag-004olY-C9; Wed, 09 Aug 2023 07:26:46 +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)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A576B302DFC; Wed, 9 Aug 2023 09:26:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 90948201D9950; Wed, 9 Aug 2023 09:26:44 +0200 (CEST) Message-ID: <20230809072201.326960605@infradead.org> User-Agent: quilt/0.66 Date: Wed, 09 Aug 2023 09:12:31 +0200 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, David.Kaplan@amd.com, Andrew.Cooper3@citrix.com, jpoimboe@kernel.org, gregkh@linuxfoundation.org Subject: [RFC][PATCH 13/17] objtool/x86: Add arch_is_offset_insn() References: <20230809071218.000335006@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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,URIBL_BLOCKED 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 Add a little wrappery to identify the magic symbols that are actually inside another instruction -- yay for variable length instruction encoding. Signed-off-by: Peter Zijlstra (Intel) --- tools/objtool/arch/x86/decode.c | 6 ++++++ tools/objtool/check.c | 13 ++++++++++--- tools/objtool/include/objtool/arch.h | 1 + tools/objtool/include/objtool/elf.h | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -826,3 +826,9 @@ bool arch_is_rethunk(struct symbol *sym) { return !strcmp(sym->name, "__x86_return_thunk"); } + +bool arch_is_offset_insn(struct symbol *sym) +{ + return !strcmp(sym->name, "zen_return_thunk") || + !strcmp(sym->name, "srso_safe_ret"); +} --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -459,8 +459,7 @@ static int decode_instructions(struct ob * Both zen_return_thunk() and srso_safe_ret() are embedded inside * another instruction and objtool doesn't grok that. Skip validating them. */ - if (!strcmp(func->name, "zen_return_thunk") || - !strcmp(func->name, "srso_safe_ret") || func->alias != func) + if (func->offset_insn || func->alias != func) continue; if (!find_insn(file, sec, func->offset)) { @@ -1303,6 +1302,11 @@ __weak bool arch_is_rethunk(struct symbo return false; } +__weak bool arch_is_offset_insn(struct symbol *sym) +{ + return false; +} + static struct reloc *insn_reloc(struct objtool_file *file, struct instruction *insn) { struct reloc *reloc; @@ -1588,7 +1592,7 @@ static int add_jump_destinations(struct * middle of another instruction. Objtool only * knows about the outer instruction. */ - if (sym && !strcmp(sym->name, "zen_return_thunk")) { + if (sym && sym->offset_insn) { add_return_call(file, insn, false); continue; } @@ -2507,6 +2511,9 @@ static int classify_symbols(struct objto if (arch_is_rethunk(func)) func->return_thunk = true; + if (arch_is_offset_insn(func)) + func->offset_insn = true; + if (arch_ftrace_match(func->name)) func->fentry = true; --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -90,6 +90,7 @@ int arch_decode_hint_reg(u8 sp_reg, int bool arch_is_retpoline(struct symbol *sym); bool arch_is_rethunk(struct symbol *sym); +bool arch_is_offset_insn(struct symbol *sym); int arch_rewrite_retpolines(struct objtool_file *file); --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -66,6 +66,7 @@ struct symbol { u8 fentry : 1; u8 profiling_func : 1; u8 warned : 1; + u8 offset_insn : 1; struct list_head pv_target; struct reloc *relocs; };