From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 494EDC282DD for ; Thu, 9 Jan 2020 16:04:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 15D6C2072A for ; Thu, 9 Jan 2020 16:04:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gff8ZDQx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732909AbgAIQEg (ORCPT ); Thu, 9 Jan 2020 11:04:36 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:25899 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732890AbgAIQEd (ORCPT ); Thu, 9 Jan 2020 11:04:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578585872; 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=xt5DbHzH/EVOyMc37NjjTNOfxPGZdHy+R4yzKk2QEI0=; b=gff8ZDQxdRcJyF1mUUlgIine/yt7C8A/cqPu/JG7fevme/1ORJqRK30xGb1k1B+uSsEjIf Wwo7FDxhm6wH3/ooCWTERhoMZVf5t2XT+lAIV68cR0rFvx04KOBp6n6WyJxZx4ws1LgnZu ANJ/zp11g5U0jW9Oj06wfviaQXSOnKg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-225-Qv2DOBVZMMe1MtWdYkdx1A-1; Thu, 09 Jan 2020 11:04:31 -0500 X-MC-Unique: Qv2DOBVZMMe1MtWdYkdx1A-1 Received: by mail-wm1-f70.google.com with SMTP id 18so1103904wmp.0 for ; Thu, 09 Jan 2020 08:04:30 -0800 (PST) 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=xt5DbHzH/EVOyMc37NjjTNOfxPGZdHy+R4yzKk2QEI0=; b=VYg/qfBOhn6TzbwNCYtgJcNMCDhX0ijv7WLjfXcguPUznB7VMrB/JsUIr3Bit9b5Z0 oQEdTcENmlLo0cWBva0VoNxYzNVRPDCSLfZkN/3dEZ55qR8CrNR70DNYlXwbnaXF/6+C uDsSJQ6Pz1fQ7sZeXKYiIxCE+1qHvSSGA7z4f17ASRExbtSKM2jCFmBt4wRL53yomMNw XJ5UVOrOQgBxycmV1T8pblSRuISZkU2r2dzHHNcBxkvqPEpsBPo1kzkqHVpxNwcOMWgX Jt8VIh4T2yTkLsfTKk5fH2o/QKiDtu76yP5jNG7vcAOUNcLiApIu2k8X78VBFCe9C1B8 WwNw== X-Gm-Message-State: APjAAAW9Xr2F8Yn5S+3+YOXOI4nmPx0geRDQlcAK50iU51FZLaOe3zT1 tevgfhp1PUCjE8jnijaxYKfFcMiacFVMYz1yOoKJwtrN+ZZniFay52Ua7CWxjb0lInzohFJd7Jg cj4YHEJ6LLPdPMw7DurJmuzyp X-Received: by 2002:a05:600c:294:: with SMTP id 20mr5609170wmk.97.1578585868939; Thu, 09 Jan 2020 08:04:28 -0800 (PST) X-Google-Smtp-Source: APXvYqzq/Alj0h2G/J2VQULJA01MqEGedUbxb2oF0V48iKffuNbHJbUHRhKAG5KbZl3knGLHvbjRuw== X-Received: by 2002:a05:600c:294:: with SMTP id 20mr5609151wmk.97.1578585868751; Thu, 09 Jan 2020 08:04:28 -0800 (PST) Received: from redfedo.redhat.com (host81-140-166-164.range81-140.btcentralplus.com. [81.140.166.164]) by smtp.gmail.com with ESMTPSA id b17sm8615898wrp.49.2020.01.09.08.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2020 08:04:28 -0800 (PST) From: Julien Thierry To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: jpoimboe@redhat.com, peterz@infradead.org, raphael.gault@arm.com, catalin.marinas@arm.com, will@kernel.org, Julien Thierry Subject: [RFC v5 12/57] objtool: check: Allow jumps from an alternative group to itself Date: Thu, 9 Jan 2020 16:02:15 +0000 Message-Id: <20200109160300.26150-13-jthierry@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200109160300.26150-1-jthierry@redhat.com> References: <20200109160300.26150-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 Alternatives can contain instructions that jump to another instruction in the same alternative group. This is actually a common pattern on arm64. Keep track of instructions jumping within their own alternative group and carry on validating such branches. Signed-off-by: Julien Thierry --- tools/objtool/check.c | 48 ++++++++++++++++++++++++++++++++++--------- tools/objtool/check.h | 1 + 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 8f2ff030936d..c7b3f1e2a628 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -722,6 +722,14 @@ static int handle_group_alt(struct objtool_file *file, sec_for_each_insn_from(file, insn) { if (insn->offset >= special_alt->orig_off + special_alt->orig_len) break; + /* Is insn a jump to an instruction within the alt_group */ + if (insn->jump_dest && insn->sec == insn->jump_dest->sec && + (insn->type == INSN_JUMP_CONDITIONAL || + insn->type == INSN_JUMP_UNCONDITIONAL)) { + dest_off = insn->jump_dest->offset; + insn->intra_group_jump = special_alt->orig_off <= dest_off && + dest_off < special_alt->orig_off + special_alt->orig_len; + } insn->alt_group = true; last_orig_insn = insn; @@ -1853,14 +1861,33 @@ static int validate_sibling_call(struct instruction *insn, struct insn_state *st return validate_call(insn, state); } +static int validate_branch_alt_safe(struct objtool_file *file, + struct symbol *func, + struct instruction *first, + struct insn_state state); + +static int validate_branch(struct objtool_file *file, struct symbol *func, + struct instruction *first, struct insn_state state) +{ + if (first->alt_group && list_empty(&first->alts)) { + WARN_FUNC("don't know how to handle branch to middle of alternative instruction group", + first->sec, first->offset); + return 1; + } + + return validate_branch_alt_safe(file, func, first, state); +} + /* * Follow the branch starting at the given instruction, and recursively follow * any other branches (jumps). Meanwhile, track the frame pointer state at * each instruction and validate all the rules described in * tools/objtool/Documentation/stack-validation.txt. */ -static int validate_branch(struct objtool_file *file, struct symbol *func, - struct instruction *first, struct insn_state state) +static int validate_branch_alt_safe(struct objtool_file *file, + struct symbol *func, + struct instruction *first, + struct insn_state state) { struct alternative *alt; struct instruction *insn, *next_insn; @@ -1871,12 +1898,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, insn = first; sec = insn->sec; - if (insn->alt_group && list_empty(&insn->alts)) { - WARN_FUNC("don't know how to handle branch to middle of alternative instruction group", - sec, insn->offset); - return 1; - } - while (1) { next_insn = next_insn_same_sec(file, insn); @@ -2023,8 +2044,15 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, return ret; } else if (insn->jump_dest) { - ret = validate_branch(file, func, - insn->jump_dest, state); + if (insn->intra_group_jump) + ret = validate_branch_alt_safe(file, + func, + insn->jump_dest, + state); + else + ret = validate_branch(file, func, + insn->jump_dest, + state); if (ret) { if (backtrace) BT_FUNC("(branch)", insn); diff --git a/tools/objtool/check.h b/tools/objtool/check.h index af87b55db454..d13ee02f28a4 100644 --- a/tools/objtool/check.h +++ b/tools/objtool/check.h @@ -46,6 +46,7 @@ struct instruction { struct stack_op stack_op; struct insn_state state; struct orc_entry orc; + bool intra_group_jump; }; struct objtool_file { -- 2.21.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04C73C282DD for ; Thu, 9 Jan 2020 16:06:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9AF9206ED for ; Thu, 9 Jan 2020 16:06:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MbOt5IiS"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IcXVAPng" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9AF9206ED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9f3m5C0vcOkkKHNafu8ERsungF4YtgvpRi6kYQBHoTA=; b=MbOt5IiSfcbBLb xDOXSlTJVJUVDMD8UP7wnsdSqJaySUcHM2llhJ8x3/N4u1ByLUyvDPmZDmKbiHv5W2ReoDmrS3qoF xExJwMDkN43F6Rr/FjvsNV9kbyqJnorWY0pAyiUVYYhzAMt+/GZBkKve62Vxe+E6fstMHoWxHzRH4 zti3VPMosg5M1XxFBL5XqOBABwtPMTqNJIBmb+4+257fBqEEvpvfc3ySocfJe+vlZ1hIKEuQfHD7Z I7mTHuPwmDTJ45wnHwMl2oCTkO12zs21rH21YD9TQ+KmNRBx3AmtUEQUsrkQN1rMx2at635aK3HI3 qBEy8p/2pC9VI2kogXbQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ipaKB-0007oZ-OQ; Thu, 09 Jan 2020 16:06:19 +0000 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120] helo=us-smtp-1.mimecast.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ipaIT-00058B-4B for linux-arm-kernel@lists.infradead.org; Thu, 09 Jan 2020 16:04:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578585871; h=from:from: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=FXQxfKCa95iVhzNUh/d4s107aoEQ/uGIdoZfuhqnFqc=; b=IcXVAPng4dB+tFbFODawYi3UH+k4AP0HQ2x5QT94/7ZzUk0GfjK1ahZscXu7sIbc9l9cxp ZM8JxkCCfYHKBhFxeLIi/dmso3Qd8vYnw8NRPoM8c65HyIZlUNEpdxWNscFkHjqy7vmurK 7jlSPHmHK+0gjR34aIzLjz8tBnh+FwA= 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-212-ZpcPUJn-NpObNV3EmD4eFg-1; Thu, 09 Jan 2020 11:04:30 -0500 Received: by mail-wr1-f71.google.com with SMTP id j13so3033875wrr.20 for ; Thu, 09 Jan 2020 08:04:29 -0800 (PST) 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=xt5DbHzH/EVOyMc37NjjTNOfxPGZdHy+R4yzKk2QEI0=; b=pgky8o7P/lyk/Q/+1SdnB9VpLJ0ArlMWwKuuyWdoeI8AcebU7mAJE0mWHHxz2ZeQc1 /Wllltnr1dUmivqxFezfNaWzkdJid05MgkgPd64JTUVez1hrij/wAdagVc/x7b42MJ9W nGSyxur7N2u4hciNxrFvBIQOA2Eao/pUhOQpcrvLkuOH5hVSqwirEBNxV+dcLLcTWKU/ o4uu9OS8ZewlrIBWF0iGDDwaLbwAdVoQZl2RV0lcZrfVCjO5PkgL7lVwtbRm1pcWQSQ0 nVDnVMD0O6Q8/iM8uFylxPbeqWaNvox7tOCglBCMvsMRZ7SZGybpR/QLdSMH1DEKYvrG DEHA== X-Gm-Message-State: APjAAAV5xk0T/euS3zlYHnf9mzagLnm3lUliwxWU4AOqH2+L+AMq34UC oe+1T3ya4xP7fyIgh3d8MXX5tcDupC2PTIPxCsJUHxRP5u1Lnr5xq32JRx1TkkzXQq9Yo65BvfF vgj15bpC563hCpLZiVVlcj8nRzDqqkBDJ9Xw= X-Received: by 2002:a05:600c:294:: with SMTP id 20mr5609171wmk.97.1578585868940; Thu, 09 Jan 2020 08:04:28 -0800 (PST) X-Google-Smtp-Source: APXvYqzq/Alj0h2G/J2VQULJA01MqEGedUbxb2oF0V48iKffuNbHJbUHRhKAG5KbZl3knGLHvbjRuw== X-Received: by 2002:a05:600c:294:: with SMTP id 20mr5609151wmk.97.1578585868751; Thu, 09 Jan 2020 08:04:28 -0800 (PST) Received: from redfedo.redhat.com (host81-140-166-164.range81-140.btcentralplus.com. [81.140.166.164]) by smtp.gmail.com with ESMTPSA id b17sm8615898wrp.49.2020.01.09.08.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2020 08:04:28 -0800 (PST) From: Julien Thierry To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v5 12/57] objtool: check: Allow jumps from an alternative group to itself Date: Thu, 9 Jan 2020 16:02:15 +0000 Message-Id: <20200109160300.26150-13-jthierry@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200109160300.26150-1-jthierry@redhat.com> References: <20200109160300.26150-1-jthierry@redhat.com> MIME-Version: 1.0 X-MC-Unique: ZpcPUJn-NpObNV3EmD4eFg-1 X-Mimecast-Spam-Score: 0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200109_080433_270180_B938613D X-CRM114-Status: GOOD ( 13.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julien Thierry , peterz@infradead.org, catalin.marinas@arm.com, raphael.gault@arm.com, jpoimboe@redhat.com, will@kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Alternatives can contain instructions that jump to another instruction in the same alternative group. This is actually a common pattern on arm64. Keep track of instructions jumping within their own alternative group and carry on validating such branches. Signed-off-by: Julien Thierry --- tools/objtool/check.c | 48 ++++++++++++++++++++++++++++++++++--------- tools/objtool/check.h | 1 + 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 8f2ff030936d..c7b3f1e2a628 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -722,6 +722,14 @@ static int handle_group_alt(struct objtool_file *file, sec_for_each_insn_from(file, insn) { if (insn->offset >= special_alt->orig_off + special_alt->orig_len) break; + /* Is insn a jump to an instruction within the alt_group */ + if (insn->jump_dest && insn->sec == insn->jump_dest->sec && + (insn->type == INSN_JUMP_CONDITIONAL || + insn->type == INSN_JUMP_UNCONDITIONAL)) { + dest_off = insn->jump_dest->offset; + insn->intra_group_jump = special_alt->orig_off <= dest_off && + dest_off < special_alt->orig_off + special_alt->orig_len; + } insn->alt_group = true; last_orig_insn = insn; @@ -1853,14 +1861,33 @@ static int validate_sibling_call(struct instruction *insn, struct insn_state *st return validate_call(insn, state); } +static int validate_branch_alt_safe(struct objtool_file *file, + struct symbol *func, + struct instruction *first, + struct insn_state state); + +static int validate_branch(struct objtool_file *file, struct symbol *func, + struct instruction *first, struct insn_state state) +{ + if (first->alt_group && list_empty(&first->alts)) { + WARN_FUNC("don't know how to handle branch to middle of alternative instruction group", + first->sec, first->offset); + return 1; + } + + return validate_branch_alt_safe(file, func, first, state); +} + /* * Follow the branch starting at the given instruction, and recursively follow * any other branches (jumps). Meanwhile, track the frame pointer state at * each instruction and validate all the rules described in * tools/objtool/Documentation/stack-validation.txt. */ -static int validate_branch(struct objtool_file *file, struct symbol *func, - struct instruction *first, struct insn_state state) +static int validate_branch_alt_safe(struct objtool_file *file, + struct symbol *func, + struct instruction *first, + struct insn_state state) { struct alternative *alt; struct instruction *insn, *next_insn; @@ -1871,12 +1898,6 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, insn = first; sec = insn->sec; - if (insn->alt_group && list_empty(&insn->alts)) { - WARN_FUNC("don't know how to handle branch to middle of alternative instruction group", - sec, insn->offset); - return 1; - } - while (1) { next_insn = next_insn_same_sec(file, insn); @@ -2023,8 +2044,15 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, return ret; } else if (insn->jump_dest) { - ret = validate_branch(file, func, - insn->jump_dest, state); + if (insn->intra_group_jump) + ret = validate_branch_alt_safe(file, + func, + insn->jump_dest, + state); + else + ret = validate_branch(file, func, + insn->jump_dest, + state); if (ret) { if (backtrace) BT_FUNC("(branch)", insn); diff --git a/tools/objtool/check.h b/tools/objtool/check.h index af87b55db454..d13ee02f28a4 100644 --- a/tools/objtool/check.h +++ b/tools/objtool/check.h @@ -46,6 +46,7 @@ struct instruction { struct stack_op stack_op; struct insn_state state; struct orc_entry orc; + bool intra_group_jump; }; struct objtool_file { -- 2.21.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel