Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1406632pxk; Fri, 4 Sep 2020 08:37:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyZd/92Fs+nv8ElxmA9HDNlUATN89dHiCfUWTJlUPru3LUZgvNNfjIn/EQZMrr1gmMObAn X-Received: by 2002:a17:906:8508:: with SMTP id i8mr1927477ejx.390.1599233864018; Fri, 04 Sep 2020 08:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599233864; cv=none; d=google.com; s=arc-20160816; b=uXwsrSypeY13qODVp3of6fvBiV/v5cTkLckog8Bf8GixVEr/0E5+17pozx5evxLFaC fwDKo+1sXYjB1UWrP8apCovOn9x4585lfLEq5gSy3OAzIFPKDOdFTP1LNn4kxrLqspjg vVFxNfcSeaMBMLXavDhgE5cVGK+uQtzgyNboZtXLTLnDBq0dXUc+43UxxnCoGWg/OQyw boRdBI6Pu7lWCkxnFCQhS5AouQgrwLuOD89lB+0ct3rSwoBJwuEvJJD6fKWDz/pNdXkv fo4VxxPn4BUeSkOgQk7Px29HmavQSqowKWc/SERDuA0bF/qdNYVSMFLCCnx8GxJox12R TtJg== 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=hrVz+KLbKI6BdLhyF2fMlzFox3txKG0LPn3niHgImoA=; b=QB1IyqOlGX5mG9bCkOgkL3SOnyAiNGn62lslVL4gHirLacscT27hmBTY/7NYkCXOeo XwNIePjt+xlS66EdgJs5irQupZgQhHDbSwE0tlt87xL8YUbMGLG7AXfxSYSQpcLpM4pr dQ2qTYr2nJKPbRcjqq/TyUO0acCCajbZsjq7kLZVRmDUsUbF02L3caSlfooaUuSb1lWR lyGH7Tnvf1EDV44oDPM6r5aqaJzuU7dKQ4aLAY0SLBqWFVuK3kBX7fPlIQEazR79U8Rl jHmbK7+25JH+Z4jLJ7ir53C+sjfiWKuftPwrxXrz3Q0VocAOhSpHO0DV7X7+ZXvAUa8P rFHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SOnJXWOP; 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 p8si3915437edw.437.2020.09.04.08.37.20; Fri, 04 Sep 2020 08:37:44 -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=SOnJXWOP; 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 S1726537AbgIDPdS (ORCPT + 99 others); Fri, 4 Sep 2020 11:33:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30226 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726213AbgIDPdR (ORCPT ); Fri, 4 Sep 2020 11:33:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599233595; 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=hrVz+KLbKI6BdLhyF2fMlzFox3txKG0LPn3niHgImoA=; b=SOnJXWOP8N0dwJ/vSXD9lUPYhuDwaegBdZM9+9sC/L1PTYAhBH4S8D/KCq2mILxsyKSgKb 064VHJueFnRu6IeQKwUXmRkvsew22tGnVQE4FdKh+MSyprBWLcIezynDDjiyzAYhpEzSAq 5xW7+cyzv93xL12m94fObCHSxx+rak4= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-30-eGmBl3RBPDqy_6U0FYXZ_g-1; Fri, 04 Sep 2020 11:33:13 -0400 X-MC-Unique: eGmBl3RBPDqy_6U0FYXZ_g-1 Received: by mail-ed1-f71.google.com with SMTP id y15so2858725ede.14 for ; Fri, 04 Sep 2020 08:33:13 -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=hrVz+KLbKI6BdLhyF2fMlzFox3txKG0LPn3niHgImoA=; b=fmQdSDCDaiSv9wAkOa0bHfo8ZhETCDnKdk1sWjrLHAqlrKevvKRB3YhHHbbLSCcSDB aiuXnUsWi21dxEU+XF7eFUrUVR+kDPsYWVe27e+j/rk7Y/3GaxLohXbvMdUkGTkYfybg iYDP8cXiuqxcM7YnpJHBorkCI7EKwPgB9zzRKfc+bYLGqBad0uvi/Jt79+mDPYZWPalM qFd6aEHPinFWkAJdSWhsbm+amXciTILcUN31SLe+FXBSTF39pMYcUCz01DUaKcLWnOhf SQ3yRxSVyqQW2vMRv5ceSPYRvQg5dPTzLeG4asBXR36Wv/SpT0o0qjlDrbmFJVfyviT+ hYCQ== X-Gm-Message-State: AOAM5326U6E6uJNAb4yNoJUMEwyCkk06ix2QSDq+/37EToDf6XsWO9pD JlarhM1HjxdeUG4HFXqAH+aRr3rjCZi9dh7HoFCxFaVZ5AXlcU9iSIAjQ5XpIOFv8iF1AmRMpGv 5jh2xH2eTofOUHsEYJANilzue X-Received: by 2002:a05:6402:17b5:: with SMTP id j21mr8895146edy.276.1599233592376; Fri, 04 Sep 2020 08:33:12 -0700 (PDT) X-Received: by 2002:a05:6402:17b5:: with SMTP id j21mr8895118edy.276.1599233592050; Fri, 04 Sep 2020 08:33:12 -0700 (PDT) Received: from redfedo.redhat.com ([2a01:cb14:499:3d00:cd47:f651:9d80:157a]) by smtp.gmail.com with ESMTPSA id o6sm6374294edh.40.2020.09.04.08.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 08:33:11 -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 v3 05/10] objtool: Make relocation in alternative handling arch dependent Date: Fri, 4 Sep 2020 16:30:23 +0100 Message-Id: <20200904153028.32676-6-jthierry@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200904153028.32676-1-jthierry@redhat.com> References: <20200904153028.32676-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/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/special.c b/tools/objtool/arch/x86/special.c index 823561e4015c..34e0e162e6fd 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/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 6156bd9a687c..8217a9a9a838 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 0abdf8efdbc0..58374255934b 100644 --- a/tools/objtool/check.h +++ b/tools/objtool/check.h @@ -47,6 +47,12 @@ struct instruction { #endif }; +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