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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 3CD27C433E0 for ; Wed, 3 Mar 2021 23:56:26 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 B1C6A64F4B for ; Wed, 3 Mar 2021 23:56:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1C6A64F4B 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+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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GEZGzggGwyvgEfjEZO2pEZX9NQ9K+uYRd20cOYyqyeY=; b=K3CxYLzH2a34u+i6GCpNjlZOd 0DkWUUrvX7SqkrfVyi8bY+LTu83KxUNXsFFpcvNfJ3TZPiNoh561C0dKCxPmZb2V9rTlRB7MGGZDT IZcRSA7y/b7a8mdHcZpGBN6WWa3XH8AgWHvvWZM00fMBE7MOAHNT/x23l4I7Ip4F2ey5m1r/VxCxD 583xkhK1IVgfO72jPjtBvbKgb5X+MTSVsWvL6yB3L+c5jZ4MM1xmfUR/XCJCKC7I9xZxuUDCQEaao TgdIYhWR3Dbttu/xE50KQNxIBRBYGmBXxGIWmtHfIL8LSXZ+oVkqj8ZODgX1FI0LIJwpN5GWLz4tD nWVVm23Pw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHbGt-00722b-Km; Wed, 03 Mar 2021 23:51:15 +0000 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHV0V-005jtB-LN for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 17:10:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614791393; 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=wWFc5LkINmQGNoqDpICyJHLZ4ydJLXuT0gd8wTx9egU=; b=HPaB6r7dl6RRb3AKdc+lLZnZxN1pxRDueJzfXuElsenymHtnYFm7HeeXCd5R8jRNkUIkLj 8gS2VfJIhJiryzB9pftBDJmTr7ke3V/NsrMQvYfKhEvmb/oFl4rLVOIzlbAxrL0Of5bCRP 4shy3Ti7eimgrRZ7Z0sqDT9KfPd5oPM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-sF7qP_DOOr2arrOGZtj0sQ-1; Wed, 03 Mar 2021 12:09:52 -0500 X-MC-Unique: sF7qP_DOOr2arrOGZtj0sQ-1 Received: by mail-wm1-f72.google.com with SMTP id m17so2070817wml.3 for ; Wed, 03 Mar 2021 09:09:52 -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=wWFc5LkINmQGNoqDpICyJHLZ4ydJLXuT0gd8wTx9egU=; b=DeTd8ykcTbOv6WRt09tKij4LD9hXliLdPYoEzbvFXBS9puGzx0Mv9MI8+3PPy9TH8i IbT9qFTLfuWDqsjo0IdvHNgPi44C04smYNW/ShGev6z8yr4gWyrN1tMlKcycUJUUwT/p Qpt/o8jEG7/ZcTOH2Am1vNod+aIoZQ7XD4x8RXF/33dImLqf157+Ewuj+a6kL9ydJf4J hDHRl1kWA30OotBJLkA2XcVaGHNTFQbY5+rGQdlmtB624iy40YK+oI9kxA/DVncqos+/ bemURmVYOGKszoSHImzIqDd/W4xTc6hEVYFgWDjacyxd730K6j/YVqXtRHRYKkV3Dj6P 2WDg== X-Gm-Message-State: AOAM532MX17lBdmB24Co6luT4+5gYvm3mg7sGRZFS6g64BWjS9XN3awC sClCZC/3SPf2h+y0w5SY/+xmQz7sQ1AfL229WX2LeuSq3akCY/A3h73ildFrJJUUOZPBTqjhIz5 xzcRaV3n83MmzO5qGcWy9pd6MzNUmsk2JCzg= X-Received: by 2002:adf:f841:: with SMTP id d1mr27888715wrq.36.1614791391363; Wed, 03 Mar 2021 09:09:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDCUZUG8mSoLXRPqSl8I/V8alKK6lYNpH2msZdC3D2Z/G3uqkfDbJx/aOBofOeSHgeyAmuew== X-Received: by 2002:adf:f841:: with SMTP id d1mr27888704wrq.36.1614791391241; Wed, 03 Mar 2021 09:09:51 -0800 (PST) Received: from redfedo.redhat.com ([2a01:cb14:499:3d00:cd47:f651:9d80:157a]) by smtp.gmail.com with ESMTPSA id r7sm33066226wre.25.2021.03.03.09.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 09:09:50 -0800 (PST) From: Julien Thierry To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, ardb@kernel.org, masahiroy@kernel.org, jpoimboe@redhat.com, peterz@infradead.org, ycote@redhat.com, Julien Thierry Subject: [RFC PATCH v2 09/13] objtool: arm64: Decode LDR instructions Date: Wed, 3 Mar 2021 18:09:28 +0100 Message-Id: <20210303170932.1838634-10-jthierry@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210303170932.1838634-1-jthierry@redhat.com> References: <20210303170932.1838634-1-jthierry@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jthierry@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Load literal instructions can generate constants inside code sections. Record the locations of the constants in order to be able to remove their corresponding "struct instruction". Signed-off-by: Julien Thierry --- tools/objtool/arch/arm64/decode.c | 86 ++++++++++++++++++++++++++++ tools/objtool/arch/x86/decode.c | 5 ++ tools/objtool/check.c | 3 + tools/objtool/include/objtool/arch.h | 3 + 4 files changed, 97 insertions(+) diff --git a/tools/objtool/arch/arm64/decode.c b/tools/objtool/arch/arm64/decode.c index 4e086d2251f5..b4631d79f13f 100644 --- a/tools/objtool/arch/arm64/decode.c +++ b/tools/objtool/arch/arm64/decode.c @@ -30,6 +30,73 @@ static unsigned long sign_extend(unsigned long x, int nbits) return ((~0UL + (sign_bit ^ 1)) << nbits) | x; } +struct insn_loc { + const struct section *sec; + unsigned long offset; + struct hlist_node hnode; + bool ignorable; +}; + +DEFINE_HASHTABLE(invalid_insns, 16); + +static int record_invalid_insn(const struct section *sec, + unsigned long offset, + bool ignore) +{ + struct insn_loc *loc; + struct hlist_head *l; + + l = &invalid_insns[hash_min(offset, HASH_BITS(invalid_insns))]; + if (!hlist_empty(l)) { + loc = hlist_entry(l->first, struct insn_loc, hnode); + loc->ignorable |= ignore; + return 0; + } + + loc = malloc(sizeof(*loc)); + if (!loc) { + WARN("malloc failed"); + return -1; + } + + loc->sec = sec; + loc->offset = offset; + loc->ignorable = ignore; + + hash_add(invalid_insns, &loc->hnode, loc->offset); + + return 0; +} + +int arch_post_process_instructions(struct objtool_file *file) +{ + struct hlist_node *tmp; + struct insn_loc *loc; + unsigned int bkt; + int res = 0; + + hash_for_each_safe(invalid_insns, bkt, tmp, loc, hnode) { + struct instruction *insn; + + insn = find_insn(file, (struct section *) loc->sec, loc->offset); + if (insn) { + if (loc->ignorable) { + list_del(&insn->list); + hash_del(&insn->hash); + free(insn); + } else { + WARN_FUNC("can't decode instruction", insn->sec, insn->offset); + return -1; + } + } + + hash_del(&loc->hnode); + free(loc); + } + + return res; +} + bool arch_callee_saved_reg(unsigned char reg) { switch (reg) { @@ -389,6 +456,25 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec, if (ret <= 0) return ret; + if (aarch64_insn_is_ldr_lit(insn)) { + long pc_offset; + + pc_offset = insn & GENMASK(23, 5); + /* Sign extend and multiply by 4 */ + pc_offset = (pc_offset << (64 - 23)); + pc_offset = ((pc_offset >> (64 - 23)) >> 5) << 2; + + if (record_invalid_insn(sec, offset + pc_offset, true)) + return -1; + + /* 64-bit literal */ + if (insn & BIT(30)) { + if (record_invalid_insn(sec, + offset + pc_offset + 4, + true)) + return -1; + } + } *type = INSN_OTHER; break; } diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c index 431bafb881d4..54f57bfd6f8f 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -619,6 +619,11 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec, return 0; } +int arch_post_process_instructions(struct objtool_file *file) +{ + return 0; +} + void arch_initial_func_cfi_state(struct cfi_init_state *state) { int i; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index a0f762a15ad5..7750f6342855 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -325,6 +325,9 @@ static int decode_instructions(struct objtool_file *file) if (stats) printf("nr_insns: %lu\n", nr_insns); + if (arch_post_process_instructions(file)) + return -1; + return 0; err: diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/objtool/arch.h index ff21f387712d..6c61fc96ff00 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -65,6 +65,7 @@ struct stack_op { struct list_head list; }; +struct objtool_file; struct instruction; void arch_initial_func_cfi_state(struct cfi_init_state *state); @@ -75,6 +76,8 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec, unsigned long *immediate, struct list_head *ops_list); +int arch_post_process_instructions(struct objtool_file *file); + bool arch_callee_saved_reg(unsigned char reg); unsigned long arch_jump_destination(struct instruction *insn); -- 2.25.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel