Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1791969ybg; Thu, 30 Jul 2020 02:50:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPq/jAMCLXBL7IJU0s95SRqLuHIZQ0ekEsapOo+pnbeUNomYXuSm/c2rYGPGGxvgMj9n9r X-Received: by 2002:a17:906:fac1:: with SMTP id lu1mr1867190ejb.427.1596102605782; Thu, 30 Jul 2020 02:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596102605; cv=none; d=google.com; s=arc-20160816; b=Bg1thKejyyvaqM+sc5UwIBZSLQ5FJ6rWT9BmSV+3+3Rm7bQrAsfAbyZ/CRixvJ8k7g COkuJGO58bRAY8/dep9VyLe2h3qdhL9A6Tf6DIXPkPykwTe2of3uTr6z1nad0XKJlsHZ W9v55cf9qbSqw2aLXEYWEYrLp1yQdpCQGD3f9kZx5IYLo3ixNu5YBIzp+XSvoP2XX9gU kfjJqSTmj88CwG6EhI59SJcL5LlmEMkwoqsoovIquZ/+P/nPgZKBzL6pgvwAZvBDdCKo 5ghN/ifyQnH9rLl1aVFdq+Lrk9CNzPhKvO3cmJ6qMR9j9EViRKf+z8ZKyLS2LtNduZdt tjjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IyszSINmUuWIze0BnbavP6pqqJ9qAHJ6c6Qsw22nt4E=; b=eoUHM0I1O6/sf2SdEjU9/hDzOE0EM6auwP/x4wZGI153g7V1tADYoZKhyGmHfFavTY s4KP4e69lZeJmU6wgeO/uLrXO9+gAKU8zx3Z9Yj2s09j6KXCUTCaUmjoUTze/65QwIIY N1BSR4dmozTuL4BxeUUQODqUqEbj9NxYs5eGHfWoU7yhGZaBvW44zUo3rp0Wlqjnjiz0 +OajLpQzO+jbm6HmTz4PCHLjFVuPyeHBrIJbNAoRVOceBoMRxbIsIwF0T7pr5IjF1slx HeNeSCjahlhW10c1ETXhmfF+yOemQMgfexFIlt8zYilqYv/zD/MVYieNCoTT9UI3nJ1G rccw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MqczXSsw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x24si1722846ejs.198.2020.07.30.02.49.44; Thu, 30 Jul 2020 02:50:05 -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=@redhat.com header.s=mimecast20190719 header.b=MqczXSsw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729446AbgG3JrO (ORCPT + 99 others); Thu, 30 Jul 2020 05:47:14 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:55349 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728739AbgG3JrH (ORCPT ); Thu, 30 Jul 2020 05:47:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596102425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IyszSINmUuWIze0BnbavP6pqqJ9qAHJ6c6Qsw22nt4E=; b=MqczXSswaZmAtb+7fIfr+05fRUH7LK85h1vPHbwDqtulWBnkrJriQrbEHeT7KoLuHENVIU XfJp90IOpnaWGnSzIwbxkNwKp57SJy1LjubfpPhB1I7++yAd6kfLx8OpButYG1gf7vrumg qD+aG/vHU6Mea6Ozu6Yue5/xdRMxJ8o= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-365-eLspCjMBNgyxs3kURoGa3A-1; Thu, 30 Jul 2020 05:47:03 -0400 X-MC-Unique: eLspCjMBNgyxs3kURoGa3A-1 Received: by mail-wr1-f71.google.com with SMTP id j16so7757942wrw.3 for ; Thu, 30 Jul 2020 02:47:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IyszSINmUuWIze0BnbavP6pqqJ9qAHJ6c6Qsw22nt4E=; b=tcNj9aQlb+INECUl+Gxgff2z0IYCYtDRvLTPYwfdysOYbYGu+GtN/UHQ5mKcpjjO3I VJHGyMFxvWzkGhgHUivyCib0enlDO9ATFO5Iy9M01m1r4oX6/Y1JRwU4u+HPk559lnUP RobhToF61by7Ecpuo2pKowCIH7U7tfnAFzbAHId+xxNKdXKL6OcoZfk72UiUimdhttsO CCCvjThZOqTD29oxBr5E42K+VduVI+IbuhTujUOrH4ASuN8+xm+QYNr6DJfL+MBU5s/c Xd6D6xj3cSTALMlgf10IT0z4cvhPUIRF33d8IxApUu5yD8vDy0k5+iB7dekFXodmey4E iAtg== X-Gm-Message-State: AOAM531HXRgyn+6pvlkwRGRHuvkIw82J4ytZYe9baTmdR1dhdB9XJgz+ Gaoobx4uKeADSBphHXzXtJVhnIPZvAKHm1ffl2LdcAFjwpSi1xHP1eo1L8NoQU8SdOefa3ezPNI aYds8J/HfPKBWdEGeCvC3MqfV X-Received: by 2002:a1c:18e:: with SMTP id 136mr12364018wmb.93.1596102422036; Thu, 30 Jul 2020 02:47:02 -0700 (PDT) X-Received: by 2002:a1c:18e:: with SMTP id 136mr12363995wmb.93.1596102421764; Thu, 30 Jul 2020 02:47:01 -0700 (PDT) Received: from redfedo.redhat.com ([2a01:cb14:499:3d00:cd47:f651:9d80:157a]) by smtp.gmail.com with ESMTPSA id j6sm9009645wro.25.2020.07.30.02.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2020 02:47:01 -0700 (PDT) From: Julien Thierry To: linux-kernel@vger.kernel.org Cc: jpoimboe@redhat.com, peterz@infradead.org, mbenes@suse.cz, raphael.gault@arm.com, benh@kernel.crashing.org, Julien Thierry Subject: [PATCH v2 5/9] objtool: Make relocation in alternative handling arch dependent Date: Thu, 30 Jul 2020 10:46:48 +0100 Message-Id: <20200730094652.28297-6-jthierry@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200730094652.28297-1-jthierry@redhat.com> References: <20200730094652.28297-1-jthierry@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As pointed out by the comment in handle_group_alt(), support of relocation for instructions in an alternative group depends on whether arch specific kernel code handles it. So, let objtool arch specific code decide whether a relocation for the alternative section should be accepted. Reviewed-by: Miroslav Benes Signed-off-by: Julien Thierry --- tools/objtool/arch/x86/arch_special.c | 13 +++++++++++++ tools/objtool/check.c | 19 ++++++------------- tools/objtool/check.h | 6 ++++++ tools/objtool/special.h | 4 ++++ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/tools/objtool/arch/x86/arch_special.c b/tools/objtool/arch/x86/arch_special.c index 823561e4015c..34e0e162e6fd 100644 --- a/tools/objtool/arch/x86/arch_special.c +++ b/tools/objtool/arch/x86/arch_special.c @@ -35,3 +35,16 @@ void arch_handle_alternative(unsigned short feature, struct special_alt *alt) break; } } + +bool arch_support_alt_relocation(struct special_alt *special_alt, + struct instruction *insn, + struct reloc *reloc) +{ + /* + * The x86 alternatives code adjusts the offsets only when it + * encounters a branch instruction at the very beginning of the + * replacement group. + */ + return insn->offset == special_alt->new_off && + (insn->type == INSN_CALL || is_static_jump(insn)); +} diff --git a/tools/objtool/check.c b/tools/objtool/check.c index bb19e4c79e46..18ef9c64719f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -109,12 +109,6 @@ static struct instruction *prev_insn_same_sym(struct objtool_file *file, for (insn = next_insn_same_sec(file, insn); insn; \ insn = next_insn_same_sec(file, insn)) -static bool is_static_jump(struct instruction *insn) -{ - return insn->type == INSN_JUMP_CONDITIONAL || - insn->type == INSN_JUMP_UNCONDITIONAL; -} - static bool is_sibling_call(struct instruction *insn) { /* An indirect jump is either a sibling call or a jump to a table. */ @@ -866,6 +860,8 @@ static int handle_group_alt(struct objtool_file *file, alt_group = alt_group_next_index++; insn = *new_insn; sec_for_each_insn_from(file, insn) { + struct reloc *alt_reloc; + if (insn->offset >= special_alt->new_off + special_alt->new_len) break; @@ -882,14 +878,11 @@ static int handle_group_alt(struct objtool_file *file, * .altinstr_replacement section, unless the arch's * alternatives code can adjust the relative offsets * accordingly. - * - * The x86 alternatives code adjusts the offsets only when it - * encounters a branch instruction at the very beginning of the - * replacement group. */ - if ((insn->offset != special_alt->new_off || - (insn->type != INSN_CALL && !is_static_jump(insn))) && - find_reloc_by_dest_range(file->elf, insn->sec, insn->offset, insn->len)) { + alt_reloc = find_reloc_by_dest_range(file->elf, insn->sec, + insn->offset, insn->len); + if (alt_reloc && + !arch_support_alt_relocation(special_alt, insn, alt_reloc)) { WARN_FUNC("unsupported relocation in alternatives section", insn->sec, insn->offset); diff --git a/tools/objtool/check.h b/tools/objtool/check.h index 059c43bfeb18..c08ca6cd9a89 100644 --- a/tools/objtool/check.h +++ b/tools/objtool/check.h @@ -44,6 +44,12 @@ struct instruction { struct cfi_state cfi; }; +static inline bool is_static_jump(struct instruction *insn) +{ + return insn->type == INSN_JUMP_CONDITIONAL || + insn->type == INSN_JUMP_UNCONDITIONAL; +} + struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset); diff --git a/tools/objtool/special.h b/tools/objtool/special.h index 44da89afeda2..1dc1bb3e74c6 100644 --- a/tools/objtool/special.h +++ b/tools/objtool/special.h @@ -7,6 +7,7 @@ #define _SPECIAL_H #include +#include "check.h" #include "elf.h" struct special_alt { @@ -30,4 +31,7 @@ int special_get_alts(struct elf *elf, struct list_head *alts); void arch_handle_alternative(unsigned short feature, struct special_alt *alt); +bool arch_support_alt_relocation(struct special_alt *special_alt, + struct instruction *insn, + struct reloc *reloc); #endif /* _SPECIAL_H */ -- 2.21.3