From patchwork Fri Apr 14 14:47:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 83464 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp377992rwl; Fri, 14 Apr 2023 07:55:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YcjGeJ4sEV27ZGed00I5iDprccbvob8hwtmX571Laz/QT2EPTagqqhV0sn/+1YEX1UVZF5 X-Received: by 2002:a05:6a00:2292:b0:637:f1ae:d3e with SMTP id f18-20020a056a00229200b00637f1ae0d3emr9959594pfe.25.1681484104837; Fri, 14 Apr 2023 07:55:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681484104; cv=none; d=google.com; s=arc-20160816; b=J+ocL3s2VRp+KUvQobjMMvaFZSjDq6nOKUUtRr7/8Mzav8Wm4i1u/TIqeWwsQbTup/ 26s62qoV4XvFs0QBKwQtgj3Dr2Rrckq981x6Vbo8F1MYv0+fcxCqcT4TSkRCKiV1wIBW H9+ZLjHYDIPZBLopWebUOF+MEcXxWrswxG2ROSvQLUB030UNo8bmnSgxehkbSJLpL/Wb snFZLD+BsJdWVP0Jv27v1okGLp0Lr8cTVaSxBPXkKd0ADRCv+7NQFXkPJakey9XrH8AE lkNFMaKBPA78XkkfOOn+cMmc8YU+Udvh7H4VsdS9yOlNqhU+F54U24+X8NAMxqVzr0rq bzSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=H3vxGja9f4eMtuDashMJ8NhHcbldqcXJTbhqo15/T+8=; b=c0aVDpBlp0K9/uCXuZJacE0Zzk4l9k8LGn9GEXAvfN6/g/e1Zlh3Q8pviHa29QPp4C j31fyPSMM4tcXe4S3wo9thXrHwTUsUEFEd6omrDjQILCIR9AxqB+zwuTszHCe+JsSBMj fcq6lSpeJi4WQ4KT4pDhaDTuULs63GTlr8NrUrA8aoiPwJ0FdCc+p+qe/G7dh4wsPzFR 5jnlxd5GRuDVahs8eESv2SQzC4e7feSJ2Pnu9jv+dQZ1i8KrUhygIjiIdJxXscBuWT3h vwPW0i+i6wJcLHl3nj+SLb1xUBXYA3jTDTPtoIS6yVae7SmV+Y8AbjKOdbZq3WaQJu5u CKHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pQmFMCW+; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x21-20020aa79575000000b0062ae6345c6fsi4188918pfq.394.2023.04.14.07.54.51; Fri, 14 Apr 2023 07:55:04 -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=@linutronix.de header.s=2020 header.b=pQmFMCW+; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231259AbjDNOsJ (ORCPT + 99 others); Fri, 14 Apr 2023 10:48:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231192AbjDNOr7 (ORCPT ); Fri, 14 Apr 2023 10:47:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B191BB748; Fri, 14 Apr 2023 07:47:56 -0700 (PDT) Date: Fri, 14 Apr 2023 14:47:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1681483675; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H3vxGja9f4eMtuDashMJ8NhHcbldqcXJTbhqo15/T+8=; b=pQmFMCW+fVb4CzW7MNISY8cnbvg+hlJxK6GXEup1UA5X7E7IOshW4pOd9TM9yUjolLi79M 9Z9igxXiBp18cz/O0bLIu4/TvMBVZ/Kzu41/1MGxAuVm49HdaudoRQC/pr47KydcgS4Wy7 mDlBA/bX9RB3fNz+wvrsogC71AfLHpSeeNPQNvV6uwG9aIwq8Q75l9Rq6SWmhKWj92fleg 2uV8JTXLxKwHEPUhbmOjiE84CT+ctbJyvSYZfbRklr2fdn9I0YOWfVmqQ3tkJgyCWmKIjH KDKjFMemrcpzuopD/dJO6WoV7OgBB77KoVMiOhgegNbWRpD2j3ychoWsOee1Sw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1681483675; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H3vxGja9f4eMtuDashMJ8NhHcbldqcXJTbhqo15/T+8=; b=WdnytkO5Fqwuigmbl8RFl9dEv7URIUaDwPEOLmjmybR6vCFOlsbqcmvzDWKtZ+/va1t3Q1 MtWfGd48/ytiWIDA== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Separate prefix code from stack validation code Cc: Josh Poimboeuf , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: MIME-Version: 1.0 Message-ID: <168148367491.404.14493212462771615260.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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_PASS,T_SCC_BODY_TEXT_LINE 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?1763004198102288719?= X-GMAIL-MSGID: =?utf-8?q?1763163876797086254?= The following commit has been merged into the objtool/core branch of tip: Commit-ID: bd456a1bedd20cebd37493f8cb0291294a7356ea Gitweb: https://git.kernel.org/tip/bd456a1bedd20cebd37493f8cb0291294a7356ea Author: Josh Poimboeuf AuthorDate: Wed, 12 Apr 2023 13:26:13 -07:00 Committer: Peter Zijlstra CommitterDate: Fri, 14 Apr 2023 16:08:29 +02:00 objtool: Separate prefix code from stack validation code Simplify the prefix code by moving it after validate_reachable_instructions(). Signed-off-by: Josh Poimboeuf Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/d7f31ac2de462d0cd7b1db01b7ecb525c057c8f6.1681331135.git.jpoimboe@kernel.org --- tools/objtool/check.c | 88 +++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 1cf2e28..8ee4d51 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4114,54 +4114,61 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructio return false; } -static int add_prefix_symbol(struct objtool_file *file, struct symbol *func, - struct instruction *insn) +static int add_prefix_symbol(struct objtool_file *file, struct symbol *func) { - if (!opts.prefix) - return 0; + struct instruction *insn, *prev; - for (;;) { - struct instruction *prev = prev_insn_same_sec(file, insn); - u64 offset; + insn = find_insn(file, func->sec, func->offset); + if (!insn) + return -1; - if (!prev) - break; + for (prev = prev_insn_same_sec(file, insn); + prev; + prev = prev_insn_same_sec(file, prev)) { + u64 offset; if (prev->type != INSN_NOP) - break; + return -1; offset = func->offset - prev->offset; - if (offset >= opts.prefix) { - if (offset == opts.prefix) { - /* - * Since the sec->symbol_list is ordered by - * offset (see elf_add_symbol()) the added - * symbol will not be seen by the iteration in - * validate_section(). - * - * Hence the lack of list_for_each_entry_safe() - * there. - * - * The direct concequence is that prefix symbols - * don't get visited (because pointless), except - * for the logic in ignore_unreachable_insn() - * that needs the terminating insn to be visited - * otherwise it will report the hole. - * - * Hence mark the first instruction of the - * prefix symbol as visisted. - */ - prev->visited |= VISITED_BRANCH; - elf_create_prefix_symbol(file->elf, func, opts.prefix); - } - break; - } - insn = prev; + + if (offset > opts.prefix) + return -1; + + if (offset < opts.prefix) + continue; + + elf_create_prefix_symbol(file->elf, func, opts.prefix); + break; } + if (!prev) + return -1; + return 0; } +static int add_prefix_symbols(struct objtool_file *file) +{ + struct section *sec; + struct symbol *func; + int warnings = 0; + + for_each_sec(file, sec) { + if (!(sec->sh.sh_flags & SHF_EXECINSTR)) + continue; + + sec_for_each_sym(sec, func) { + if (func->type != STT_FUNC) + continue; + + add_prefix_symbol(file, func); + } + } + + return warnings; +} + static int validate_symbol(struct objtool_file *file, struct section *sec, struct symbol *sym, struct insn_state *state) { @@ -4180,8 +4187,6 @@ static int validate_symbol(struct objtool_file *file, struct section *sec, if (!insn || insn->ignore || insn->visited) return 0; - add_prefix_symbol(file, sym, insn); - state->uaccess = sym->uaccess_safe; ret = validate_branch(file, insn_func(insn), insn, *state); @@ -4621,6 +4626,13 @@ int check(struct objtool_file *file) warnings += ret; } + if (opts.prefix) { + ret = add_prefix_symbols(file); + if (ret < 0) + return ret; + warnings += ret; + } + if (opts.ibt) { ret = create_ibt_endbr_seal_sections(file); if (ret < 0)