From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFA611DE4E1 for ; Wed, 15 Jan 2025 22:50:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981436; cv=none; b=Um/REMHhlR4Y7kkX0lS6q8K53La8FsczWXT80tU5ndy093OefSXaxvpfj38pmqDiJrV7t+iTI765U5Wiw+AhcA4UNSPYg+MZR9uF99F0/WydyANL+B3CLyActP0wEoYba9j+Pd5Tdionh9bHKfP82UTNNVLGqxuAzR6c0e97V5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981436; c=relaxed/simple; bh=n5PKzA7GDiJ+vIl39yQ9EFUuhqglOyZ5+cDQqSVGCYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nuP5H8yLoobAR0aSAKqTDER/aGEl9LPmpt2my1p6chosUE0LRgB+y4vNSFofqGXzFEzeMPuqRztOZfGxi/e3sbYDVVj66H8Z86UfOsYYJK+AjxEUVypb7/IF1YZjg9mprpjafc8AUZtx6hBVDSCU+9Q+ovDd4ISnPzsuT8oZH0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcD37V4z9sRr; Wed, 15 Jan 2025 23:42:52 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RuBQKud5YVsR; Wed, 15 Jan 2025 23:42:52 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcD2Npxz9sRk; Wed, 15 Jan 2025 23:42:52 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3DCAA8B77A; Wed, 15 Jan 2025 23:42:52 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id AEhSP7Uv2wGL; Wed, 15 Jan 2025 23:42:52 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 15DC18B774; Wed, 15 Jan 2025 23:42:49 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 01/15] objtool: Fix generic annotation infrastructure cross build Date: Wed, 15 Jan 2025 23:42:41 +0100 Message-ID: <0ac0217b174efcefe772822089e9b64ff8c65da3.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980963; l=1213; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=n5PKzA7GDiJ+vIl39yQ9EFUuhqglOyZ5+cDQqSVGCYs=; b=9nUpCHBH2MuF6kXRB8OESgj5pUg/Vwv9wBjo8aA5eEAfC5w5ABcr8HV2k0ZEnp+s+LP7Gxt50 WQWIL/XE0cwCPiSVvzpusLaUHSL+qQXRPwvYEDKhMfdGh7WefoesJgX X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Cross build for powerpc/32 on x86_64 leads to: CC init/main.o init/main.o: warning: objtool: early_randomize_kstack_offset+0xf0: Unknown = annotation type: 134217728 init/main.o: warning: objtool: start_kernel+0x4a8: Unknown annotation type:= 134217728 init/main.o: warning: objtool: do_one_initcall+0x178: Unknown annotation ty= pe: 134217728 Fix byte order. Fixes: 2116b349e29a ("objtool: Generic annotation infrastructure") Signed-off-by: Christophe Leroy --- v5: New in v5 --- tools/objtool/check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e92c5564d9ca..129c4e2245ae 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2272,7 +2272,7 @@ static int read_annotate(struct objtool_file *file, } =20 for_each_reloc(sec->rsec, reloc) { - type =3D *(u32 *)(sec->data->d_buf + (reloc_idx(reloc) * sec->sh.sh_ents= ize) + 4); + type =3D bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + (reloc_i= dx(reloc) * sec->sh.sh_entsize) + 4)); =20 offset =3D reloc->sym->offset + reloc_addend(reloc); insn =3D find_insn(file, reloc->sym->sec, offset); --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7ABE21DE2BB for ; Wed, 15 Jan 2025 22:51:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981470; cv=none; b=pm4SZqTU0aoGgrfNFxaKHNivZqFMw1Aa5/GjIBsFJkyZPZXGWjbCAplGjp2QpxVBj21a+owOAol09enCN7VGEvMZxnT/NNyuHpWwoNxrIXUZLMx9tUzHwkg+1WnOBbsYK4Z8JVHtjaMLCeBrU0zVW9wmWwmdQalfPdjSDR8N4Rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981470; c=relaxed/simple; bh=s34YeKjlQMgJ0BPjun7wq17Hk3TXlOThHycw1E0DOE4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i99MLwuLVOZWW7DLmfsMRNljbt+jz+vhhjEOoOXfh62jp3gq97GEoo0bazJIc6tkE/B1xSq6CDbSRG+wG1IV7na/LwHjjNFtmCi2kQdwVHoZE71M42DgbtrROz56uvV18fEwo/p384HWsNTWaaVuuV/rK0gklqc+wli58nMK0pE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcH0Tmjz9sRy; Wed, 15 Jan 2025 23:42:55 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Lk43c_pRbiud; Wed, 15 Jan 2025 23:42:54 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcG6jFkz9sRs; Wed, 15 Jan 2025 23:42:54 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D0BB48B77A; Wed, 15 Jan 2025 23:42:54 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id v0ej-sZ1G8Ss; Wed, 15 Jan 2025 23:42:54 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 97C768B774; Wed, 15 Jan 2025 23:42:52 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 02/15] objtool: Move back misplaced comment Date: Wed, 15 Jan 2025 23:42:42 +0100 Message-ID: <2700fb1284bc4f72bc835911a4ec914083ab88c7.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980963; l=1950; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=s34YeKjlQMgJ0BPjun7wq17Hk3TXlOThHycw1E0DOE4=; b=FjZMuTKO1BBEU/WNDtvmcSAP87mwnWMHPfelMSZxYWv7DX6+kEpMCzJSD2yYB5uE0Ar+DqUkH CJPdTNqKIY9CRZbyQyxefgC7e5KtjsPtOfvWnYr2wWKft32htJZaqT6 X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A comment was introduced by commit 113d4bc90483 ("objtool: Fix clang switch table edge case") and wrongly moved by commit d871f7b5a6a2 ("objtool: Refactor jump table code to support other architectures") without the piece of code added with the comment in the original commit. Fixes: d871f7b5a6a2 ("objtool: Refactor jump table code to support other ar= chitectures") Signed-off-by: Christophe Leroy --- tools/objtool/arch/x86/special.c | 5 ----- tools/objtool/check.c | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 9c1c9df09aaa..76c7933bcb19 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -142,11 +142,6 @@ struct reloc *arch_find_switch_table(struct objtool_fi= le *file, strcmp(table_sec->name, C_JUMP_TABLE_SECTION)) return NULL; =20 - /* - * Each table entry has a rela associated with it. The rela - * should reference text in the same function as the original - * instruction. - */ rodata_reloc =3D find_reloc_by_dest(file->elf, table_sec, table_offset); if (!rodata_reloc) return NULL; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 129c4e2245ae..58d9b1a750e3 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2036,6 +2036,12 @@ static void find_jump_table(struct objtool_file *fil= e, struct symbol *func, table_reloc =3D arch_find_switch_table(file, insn, &table_size); if (!table_reloc) continue; + + /* + * Each table entry has a rela associated with it. The rela + * should reference text in the same function as the original + * instruction. + */ dest_insn =3D find_insn(file, table_reloc->sym->sec, reloc_addend(table_= reloc)); if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != =3D func) continue; --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A7F81DC9AB for ; Wed, 15 Jan 2025 22:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981405; cv=none; b=VnLtNUAg/4R3QXTfcAFUytP8WyR/osVOVyPRRIy7527ZhiEiEmZ7Ug0KxYQh+KSy/d2d2SldD3+b1Knijx4JJ+YGRuwCpJilAL4SCTNH/H9CtEuwHAjgGid/Bakcq8Oim2cEiDAbWWmZ+er8rjcWruunyrhlQVsS91WwADRLrAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981405; c=relaxed/simple; bh=aQ3xTILH+GfwiY+a8f3LvBKwTjOvpcWTTyPoV8IF2/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M8aQNQJ0NytBSLBhJVfX+v7mPNJWj2LRy8B1sKS9qAYX5+RIduHXBIRq37iVsSfh7N6iRr4NBDEV2S/ouLUEt+/AbIFq4/ai+cIB64CGIYRfmIbkcBRX2LrIhwltVC1ys4n4VFRf1diWdk4Yhg98Y5u2suC+ELa2Bs2cXWsobjw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcK41Ryz9sS8; Wed, 15 Jan 2025 23:42:57 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cY6dlER2MY5v; Wed, 15 Jan 2025 23:42:57 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcK3GlMz9sS7; Wed, 15 Jan 2025 23:42:57 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5BFE68B77A; Wed, 15 Jan 2025 23:42:57 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 3e-6oFIGtkBR; Wed, 15 Jan 2025 23:42:57 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 04B5A8B774; Wed, 15 Jan 2025 23:42:54 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 03/15] objtool: Allow an architecture to disable objtool on ASM files Date: Wed, 15 Jan 2025 23:42:43 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980963; l=1401; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=aQ3xTILH+GfwiY+a8f3LvBKwTjOvpcWTTyPoV8IF2/4=; b=4dGCDIhqCl+/VTvnT0rbYhLt7E29M1UaD3mJ5uLo607oESZPPwq/A0BJNYeJC8ZDV7ofnxa/j ClJ5K0+2XcxDfTIUKR35ErQGeeZo9TtJOcH8aYqVlJEmhZZvmHIhcED X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Supporting objtool on ASM files requires quite an effort. Features like UACCESS validation don't require ASM files validation. In order to allow architectures to enable objtool validation without spending unnecessary effort on cleaning up ASM files, provide an option to disable objtool validation on ASM files. Suggested-by: Naveen N Rao Signed-off-by: Christophe Leroy --- arch/Kconfig | 5 +++++ scripts/Makefile.lib | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 6682b2a53e34..137ef643e865 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1305,6 +1305,11 @@ config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT config HAVE_OBJTOOL bool =20 +config ARCH_OBJTOOL_SKIP_ASM + bool + help + Architecture doesn't support objtool on ASM files + config HAVE_JUMP_LABEL_HACK bool =20 diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 7395200538da..3c5e6de76b11 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -325,7 +325,11 @@ define rule_cc_o_c endef =20 quiet_cmd_as_o_S =3D AS $(quiet_modtag) $@ +ifndef CONFIG_ARCH_OBJTOOL_SKIP_ASM cmd_as_o_S =3D $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool) +else + cmd_as_o_S =3D $(CC) $(a_flags) -c -o $@ $< +endif =20 define rule_as_o_S $(call cmd_and_fixdep,as_o_S) --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F132A1DD9AB for ; Wed, 15 Jan 2025 22:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981410; cv=none; b=mYShEj+HaHysCapmQa4N9GRilc7vbD9yXt/xjui6QgMtiYGfKix4eadEgK3EYgVjC3rbC2qugiXlmPerWpC+LtMeFOCNZ3zVmGMgmrPu9QvMsh7dplL4zbMH8dwW9T8gMlF0e5/dgyR8MZHHnQnzV/J6d1abxxbURIiPwrUpH8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981410; c=relaxed/simple; bh=AtXgcZWCVAZG0ZZoJAL+afYs9xez+Wa0PGBF3/snVyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gawFDq119AiTg3oS7zADKeLajL+fZY+q5R2CiTx0Lfpf6du7tB2SCS61I9Le2vIXoHqWBfs61n2GRhIFKqWi51lymxG4/0kJbhZbtt9jDTzDtQIDneI3ISbZ1n3KglJN705h5NCf9OCCwOmHNYJctE/5qiLodxdveeRld0gXYOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcN15h3z9sSH; Wed, 15 Jan 2025 23:43:00 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PVQMaZJXyjmg; Wed, 15 Jan 2025 23:43:00 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcN0CBlz9sSC; Wed, 15 Jan 2025 23:43:00 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E884F8B77A; Wed, 15 Jan 2025 23:42:59 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id Yuwf72boS7Cs; Wed, 15 Jan 2025 23:42:59 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7D9BA8B774; Wed, 15 Jan 2025 23:42:57 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 04/15] objtool: Fix JUMP_ENTRY_SIZE for bi-arch like powerpc Date: Wed, 15 Jan 2025 23:42:44 +0100 Message-ID: <908df81a11d6d48353a096256f2acdc1833f1cec.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980963; l=3047; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=AtXgcZWCVAZG0ZZoJAL+afYs9xez+Wa0PGBF3/snVyw=; b=uFyZIHlQUiQ6PHRcVu0ANbt9OkrkHoVXRQu5q7KeplRbinQ0BEFg6fJwnxZNzWZt8ZPNnVXvU 8F8ARmg4IRNBHbCiTjUe3qAJW26UH3ogb/rWzzIfr8VlON8Z0x3X9fq X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" struct jump_entry { s32 code; s32 target; long key; }; It means that the size of the third argument depends on whether we are building a 32 bits or 64 bits kernel. Therefore JUMP_ENTRY_SIZE must depend on elf_class_addrsize(elf). To allow that, entries[] table must be initialised at runtime. This is easily done by moving it into its only user which is special_get_alts(). Signed-off-by: Christophe Leroy Acked-by: Peter Zijlstra (Intel) --- .../arch/powerpc/include/arch/special.h | 2 +- tools/objtool/special.c | 55 +++++++++---------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/tools/objtool/arch/powerpc/include/arch/special.h b/tools/objt= ool/arch/powerpc/include/arch/special.h index ffef9ada7133..b17802dcf436 100644 --- a/tools/objtool/arch/powerpc/include/arch/special.h +++ b/tools/objtool/arch/powerpc/include/arch/special.h @@ -6,7 +6,7 @@ #define EX_ORIG_OFFSET 0 #define EX_NEW_OFFSET 4 =20 -#define JUMP_ENTRY_SIZE 16 +#define JUMP_ENTRY_SIZE (8 + elf_addr_size(elf)) /* 12 on PPC32, 16 on PPC= 64 */ #define JUMP_ORIG_OFFSET 0 #define JUMP_NEW_OFFSET 4 #define JUMP_KEY_OFFSET 8 diff --git a/tools/objtool/special.c b/tools/objtool/special.c index 097a69db82a0..7780ed8a084a 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -26,34 +26,6 @@ struct special_entry { unsigned char key; /* jump_label key */ }; =20 -static const struct special_entry entries[] =3D { - { - .sec =3D ".altinstructions", - .group =3D true, - .size =3D ALT_ENTRY_SIZE, - .orig =3D ALT_ORIG_OFFSET, - .orig_len =3D ALT_ORIG_LEN_OFFSET, - .new =3D ALT_NEW_OFFSET, - .new_len =3D ALT_NEW_LEN_OFFSET, - .feature =3D ALT_FEATURE_OFFSET, - }, - { - .sec =3D "__jump_table", - .jump_or_nop =3D true, - .size =3D JUMP_ENTRY_SIZE, - .orig =3D JUMP_ORIG_OFFSET, - .new =3D JUMP_NEW_OFFSET, - .key =3D JUMP_KEY_OFFSET, - }, - { - .sec =3D "__ex_table", - .size =3D EX_ENTRY_SIZE, - .orig =3D EX_ORIG_OFFSET, - .new =3D EX_NEW_OFFSET, - }, - {}, -}; - void __weak arch_handle_alternative(unsigned short feature, struct special= _alt *alt) { } @@ -144,6 +116,33 @@ int special_get_alts(struct elf *elf, struct list_head= *alts) unsigned int nr_entries; struct special_alt *alt; int idx, ret; + const struct special_entry entries[] =3D { + { + .sec =3D ".altinstructions", + .group =3D true, + .size =3D ALT_ENTRY_SIZE, + .orig =3D ALT_ORIG_OFFSET, + .orig_len =3D ALT_ORIG_LEN_OFFSET, + .new =3D ALT_NEW_OFFSET, + .new_len =3D ALT_NEW_LEN_OFFSET, + .feature =3D ALT_FEATURE_OFFSET, + }, + { + .sec =3D "__jump_table", + .jump_or_nop =3D true, + .size =3D JUMP_ENTRY_SIZE, + .orig =3D JUMP_ORIG_OFFSET, + .new =3D JUMP_NEW_OFFSET, + .key =3D JUMP_KEY_OFFSET, + }, + { + .sec =3D "__ex_table", + .size =3D EX_ENTRY_SIZE, + .orig =3D EX_ORIG_OFFSET, + .new =3D EX_NEW_OFFSET, + }, + {}, + }; =20 INIT_LIST_HEAD(alts); =20 --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 023711DDA33 for ; Wed, 15 Jan 2025 22:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981414; cv=none; b=nz+/pLRAqS6WWyhXkFHvKLUHXm8AWtjYCU2RVkt0tKzsQWLVuYUVrl2WItilCSJ0pEX2OQGqzUqbIfMekDl8ptfEV13Q8NNcbHRufwoBBct7zICNsDWM751g4qvdemuQCk0FyRjPjZk/87zoYQXhLTdz0YjNQ3N134prQQIIqZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981414; c=relaxed/simple; bh=fxh6MSeYgn++RudIjNcYn69iUXicHtRIQBFpkzWYb8Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i12paTVY8zybcHTy2J/+R+fTok7yhcN0Kor47V2MwFRj5yIMM2tiMThpOZ6PQFH8aQAq2Go93txiwrmDSfXCx0xEdgIcb2HJzy5jx8Ijc0QQpwNIv1eKF99IyB352u3EAqy7swSrZuOP0llAH5vhF8El93pl0OS4ONjKAP4pIL0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcR1LrKz9sSL; Wed, 15 Jan 2025 23:43:03 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rb_q4sKRoTO4; Wed, 15 Jan 2025 23:43:03 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcR09klz9sSK; Wed, 15 Jan 2025 23:43:03 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E8F908B77A; Wed, 15 Jan 2025 23:43:02 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id xP54RDpKO_cp; Wed, 15 Jan 2025 23:43:02 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 432CA8B774; Wed, 15 Jan 2025 23:42:59 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 05/15] objtool: Add INSN_RETURN_CONDITIONAL Date: Wed, 15 Jan 2025 23:42:45 +0100 Message-ID: <537e5d8f181b1f1c2b8918f1aefa1dba3f972c03.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980963; l=3391; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=fxh6MSeYgn++RudIjNcYn69iUXicHtRIQBFpkzWYb8Q=; b=jvHbYKz3q4JJ4G7AnJq6DHGhOgfwQATdZWWKk0hsbDSMM1eyb1Nf9zLMZ1MbrPVgf8PziSN3Y BbpOYDdYJWRDwizo/BZDBd4QZXTIkm0xt/xnp+eiOBqTTm/uvR2awTA X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Most functions have an unconditional return at the end, like this one: 00000000 : 0: 81 22 04 d0 lwz r9,1232(r2) 4: 38 60 00 00 li r3,0 8: 2c 09 00 00 cmpwi r9,0 c: 4d 82 00 20 beqlr <=3D=3D Conditional return 10: 80 69 00 a0 lwz r3,160(r9) 14: 54 63 00 36 clrrwi r3,r3,4 18: 68 63 04 00 xori r3,r3,1024 1c: 7c 63 00 34 cntlzw r3,r3 20: 54 63 d9 7e srwi r3,r3,5 24: 4e 80 00 20 blr <=3D=3D Unconditional return But other functions like this other one below only have conditional returns: 00000028 : 28: 81 25 00 00 lwz r9,0(r5) 2c: 2c 08 00 00 cmpwi r8,0 30: 7d 29 30 78 andc r9,r9,r6 34: 7d 27 3b 78 or r7,r9,r7 38: 54 84 65 3a rlwinm r4,r4,12,20,29 3c: 81 23 00 18 lwz r9,24(r3) 40: 41 82 00 58 beq 98 44: 7d 29 20 2e lwzx r9,r9,r4 48: 55 29 07 3a rlwinm r9,r9,0,28,29 4c: 2c 09 00 0c cmpwi r9,12 50: 41 82 00 08 beq 58 54: 39 00 00 80 li r8,128 58: 2c 08 00 01 cmpwi r8,1 5c: 90 e5 00 00 stw r7,0(r5) 60: 4d a2 00 20 beqlr+ <=3D=3D Conditional return 64: 7c e9 3b 78 mr r9,r7 68: 39 40 00 00 li r10,0 6c: 39 4a 00 04 addi r10,r10,4 70: 7c 0a 40 00 cmpw r10,r8 74: 91 25 00 04 stw r9,4(r5) 78: 91 25 00 08 stw r9,8(r5) 7c: 38 a5 00 10 addi r5,r5,16 80: 91 25 ff fc stw r9,-4(r5) 84: 4c 80 00 20 bgelr <=3D=3D Conditional return 88: 55 49 60 26 slwi r9,r10,12 8c: 7d 29 3a 14 add r9,r9,r7 90: 91 25 00 00 stw r9,0(r5) 94: 4b ff ff d8 b 6c 98: 39 00 00 04 li r8,4 9c: 4b ff ff bc b 58 If conditional returns are decoded as INSN_OTHER, objtool considers that the second function never returns. If conditional returns are decoded as INSN_RETURN, objtool considers that code after that conditional return is dead. To overcome this situation, introduce INSN_RETURN_CONDITIONAL which is taken as a confirmation that a function is not noreturn but still sees following code as reachable. Signed-off-by: Christophe Leroy Acked-by: Peter Zijlstra (Intel) --- tools/objtool/check.c | 2 +- tools/objtool/include/objtool/arch.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 58d9b1a750e3..10979d68103d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -279,7 +279,7 @@ static bool __dead_end_function(struct objtool_file *fi= le, struct symbol *func, func_for_each_insn(file, func, insn) { empty =3D false; =20 - if (insn->type =3D=3D INSN_RETURN) + if (insn->type =3D=3D INSN_RETURN || insn->type =3D=3D INSN_RETURN_CONDI= TIONAL) return false; } =20 diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index d63b46a19f39..900601e2f22b 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -19,6 +19,7 @@ enum insn_type { INSN_CALL, INSN_CALL_DYNAMIC, INSN_RETURN, + INSN_RETURN_CONDITIONAL, INSN_CONTEXT_SWITCH, INSN_BUG, INSN_NOP, --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FBD61DED49 for ; Wed, 15 Jan 2025 22:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981457; cv=none; b=PbZnAlmVo2Z7FEIOjWMDqvO643NyQ1cHo0lpRVGPC8I69WILQGASDl7wi7ulPpPrP22riPJDXQbDinmm44Z/LD+ATTTfuV+OjMK3GBwQB3XPEJSaURqs1TlJVtJNUbLK5Gdf3DdWhk0y68PGqY9MarFq7KR1KyFNY+I0yaoh1wA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981457; c=relaxed/simple; bh=fqttkCOH/DPr21Jy9pk9KHcyBNc9VVe/REU9Zsv+9Qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RNe/LCHDvuHR6Ajm+UcdrVZOiZB770vlbAX+c9uEL25l6acAoqdfCikq1PlYQyu+yAndCL+QWogsYnLYg8s2sH+uDmYDvAD4m/YfuTqtsL535eNsuu3DrMigzsQdU6enqZVvSd5VpQXTstEv47IBEF6PWjRXOde3MMnqc/giNXQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcT5fpGz9sSR; Wed, 15 Jan 2025 23:43:05 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CGI684IZnpuz; Wed, 15 Jan 2025 23:43:05 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcT4rZ8z9sSN; Wed, 15 Jan 2025 23:43:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 965228B77A; Wed, 15 Jan 2025 23:43:05 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id jnXJZo8I46BV; Wed, 15 Jan 2025 23:43:05 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 09BDD8B774; Wed, 15 Jan 2025 23:43:02 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 06/15] objtool: Add support for relative switch tables Date: Wed, 15 Jan 2025 23:42:46 +0100 Message-ID: <3b380e5e0cf3e54304d52c45a551fb7a6c9627bb.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980963; l=3463; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=fqttkCOH/DPr21Jy9pk9KHcyBNc9VVe/REU9Zsv+9Qk=; b=LSTIL6frG7RFbeahKwa9DSgA5iHcfOsT5UT1LBv1jKoVYMhtlqEAlpQ79RgFph57SAcqPHakA HQg/1M/i9PRCRCSSTD6yf4l8b8Mja8Pyf0Hr5TyVJZwDlTzgvcxU+7c X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On powerpc, switch tables are relative, than means the address of the table is added to the value of the entry in order to get the pointed address: (r10 is the table address, r4 the index in the table) lis r10,0 <=3D=3D Load r10 with upper part of .rodata address R_PPC_ADDR16_HA .rodata addi r10,r10,0 <=3D=3D Add lower part of .rodata address R_PPC_ADDR16_LO .rodata lwzx r8,r10,r4 <=3D=3D Read table entry at r10 + r4 into r8 add r10,r8,r10 <=3D=3D Add table address to read value mtctr r10 <=3D=3D Save calculated address in CTR bctr <=3D=3D Branch to address in CTR RELOCATION RECORDS FOR [.rodata]: OFFSET TYPE VALUE 00000000 R_PPC_REL32 .text+0x0000054c 00000004 R_PPC_REL32 .text+0x000003d0 ... But for c_jump_tables it is not the case, they contain the pointed address directly: lis r28,0 <=3D=3D Load r28 with upper .rodata..c_jump_table R_PPC_ADDR16_HA .rodata..c_jump_table addi r28,r28,0 <=3D=3D Add lower part of .rodata..c_jump_table R_PPC_ADDR16_LO .rodata..c_jump_table lwzx r10,r28,r10 <=3D=3D Read table entry at r10 + r28 into r10 mtctr r10 <=3D=3D Save read value in CTR bctr <=3D=3D Branch to address in CTR RELOCATION RECORDS FOR [.rodata..c_jump_table]: OFFSET TYPE VALUE 00000000 R_PPC_ADDR32 .text+0x00000dc8 00000004 R_PPC_ADDR32 .text+0x00000dc8 ... Add support to objtool for relative tables, based on the relocation type which is R_PPC_REL32 for switch tables and R_PPC_ADDR32 for C jump tables. Do the comparison using R_ABS32 and R_ABS64 which are architecture agnostic. And use correct size for 'long' instead of hard coding a size of '8'. Signed-off-by: Christophe Leroy --- tools/objtool/check.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 10979d68103d..4495e7823b29 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1950,7 +1950,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, struct symbol *pfunc =3D insn_func(insn)->pfunc; struct reloc *table =3D insn_jump_table(insn); struct instruction *dest_insn; - unsigned int prev_offset =3D 0; + unsigned int offset, prev_offset =3D 0; struct reloc *reloc =3D table; struct alternative *alt; =20 @@ -1967,7 +1967,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, break; =20 /* Make sure the table entries are consecutive: */ - if (prev_offset && reloc_offset(reloc) !=3D prev_offset + 8) + if (prev_offset && reloc_offset(reloc) !=3D prev_offset + elf_addr_size(= file->elf)) break; =20 /* Detect function pointers from contiguous objects: */ @@ -1975,7 +1975,12 @@ static int add_jump_table(struct objtool_file *file,= struct instruction *insn, reloc_addend(reloc) =3D=3D pfunc->offset) break; =20 - dest_insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); + if (reloc_type(reloc) =3D=3D R_ABS32 || reloc_type(reloc) =3D=3D R_ABS64) + offset =3D reloc_addend(reloc); + else + offset =3D reloc_addend(reloc) + reloc_offset(table) - reloc_offset(rel= oc); + + dest_insn =3D find_insn(file, reloc->sym->sec, offset); if (!dest_insn) break; =20 --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16F831DE2DF for ; Wed, 15 Jan 2025 22:50:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981423; cv=none; b=fVxDErhcAYRPXWW5vr2bsTD8l6wApKKY4QsR2cfskATAVbwfUTN+HCxypF0NrDIrUsNnLmetqaCrEismC5Wsibf8lNNInKt3cGH61sZcNOHs2xO+RJujKiL9N0Dg5ZAziM+C4f61oWEcyPoDUZzkyuuniHDRPmhBM/ZVxCw9hmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981423; c=relaxed/simple; bh=Y/lU/ClBPP266lfq5TBMJ0Mc7FqwzIGQ/ba4ZqZNO8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UpXFl4kkgSKjgjTWcpF1x6XDYZsaZjSP+XsiDHnMCNtLHNQPse/LzpXezAcDoar2L+ZIhoVkM1JY5IPL8nRT9/WIRd+9QVS9ufPKjzIKoL/RjMlqstKTabT60N+/pi+nRO9rsutaBmlkHD4Rq1rd7sixeoMgkZcnIxw/+MxdY8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcX29s1z9sST; Wed, 15 Jan 2025 23:43:08 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FwAN_bvuo6ta; Wed, 15 Jan 2025 23:43:08 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcX1QY9z9sSS; Wed, 15 Jan 2025 23:43:08 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 1FE798B77A; Wed, 15 Jan 2025 23:43:08 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id MyG2dnFOf3Vo; Wed, 15 Jan 2025 23:43:08 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B1A9B8B774; Wed, 15 Jan 2025 23:43:05 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 07/15] objtool: Merge mark_func_jump_tables() and add_func_jump_tables() Date: Wed, 15 Jan 2025 23:42:47 +0100 Message-ID: <98a12e927d23a817a11b2ad9cdf209f64be53567.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980963; l=1841; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=Y/lU/ClBPP266lfq5TBMJ0Mc7FqwzIGQ/ba4ZqZNO8o=; b=ihN06500jJgWzVltSkCjOOw0Dd4+kOXr7vMofNesf4gxw29RG1Dve/n4b9Uq1ABgP/9Hcf40A hlXu1vJuIUlDCYzDGUJfz3m6xFv9AAZZI5W6raZIDtyeCgjot3kjjjB X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Those two functions loop over the instructions of a function. Merge the two loops in order to ease enhancement of table end in a following patch. Signed-off-by: Christophe Leroy --- tools/objtool/check.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 4495e7823b29..613d169eb6b8 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2061,10 +2061,11 @@ static void find_jump_table(struct objtool_file *fi= le, struct symbol *func, * First pass: Mark the head of each jump table so that in the next pass, * we know when a given jump table ends and the next one starts. */ -static void mark_func_jump_tables(struct objtool_file *file, - struct symbol *func) +static int mark_add_func_jump_tables(struct objtool_file *file, + struct symbol *func) { - struct instruction *insn, *last =3D NULL; + struct instruction *insn, *last =3D NULL, *insn_t1 =3D NULL, *insn_t2; + int ret =3D 0; =20 func_for_each_insn(file, func, insn) { if (!last) @@ -2088,16 +2089,7 @@ static void mark_func_jump_tables(struct objtool_fil= e *file, continue; =20 find_jump_table(file, func, insn); - } -} =20 -static int add_func_jump_tables(struct objtool_file *file, - struct symbol *func) -{ - struct instruction *insn, *insn_t1 =3D NULL, *insn_t2; - int ret =3D 0; - - func_for_each_insn(file, func, insn) { if (!insn_jump_table(insn)) continue; =20 @@ -2138,8 +2130,7 @@ static int add_jump_table_alts(struct objtool_file *f= ile) if (func->type !=3D STT_FUNC) continue; =20 - mark_func_jump_tables(file, func); - ret =3D add_func_jump_tables(file, func); + ret =3D mark_add_func_jump_tables(file, func); if (ret) return ret; } --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA3991DDC3F for ; Wed, 15 Jan 2025 22:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981466; cv=none; b=US0mixGy7uENyaVNvXYwkJBi0ZeZPJKHXxe4hTZfe2cLYgO6Msd/4c+ggDWkKLoRksJ3RrFRIsCwoZCY25e57wMhOImT1CR1x5MO9tuTo07BzkpmK+LiRdFINhTkhwoynuDJb+5vRPlSnI2yrlGfQcnN3Azrwveel9VteCDoohY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981466; c=relaxed/simple; bh=U81L49Nw0AgeWOM9sdxxGuzlO2Zt+79EWQdKerlwdC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gfFS9ukENfiCD88cWOngN/X4DuOTLylRjCY7ld2yvvyFwUmUGcZYB5PjXh+MSQokEGDBECwt1vlGI3cH3TgyPO6sQ/YW8VPBBOU+mqtF69bkkM2JueAkhr1oaG8fiSQgrR4ojeMBpWLXAQz9hGcIFFeb/Wm+uruJA0RqErKjxsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcZ6D8Cz9sSW; Wed, 15 Jan 2025 23:43:10 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IXAcOl9CibBJ; Wed, 15 Jan 2025 23:43:10 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcZ5DQSz9sSV; Wed, 15 Jan 2025 23:43:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9F8058B77A; Wed, 15 Jan 2025 23:43:10 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id aK_2SN5iBKqh; Wed, 15 Jan 2025 23:43:10 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 461A68B774; Wed, 15 Jan 2025 23:43:08 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 08/15] objtool: Track general purpose register used for switch table base Date: Wed, 15 Jan 2025 23:42:48 +0100 Message-ID: <36ab728d242109aeb3fe5464123a2da672f406d6.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980963; l=5395; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=U81L49Nw0AgeWOM9sdxxGuzlO2Zt+79EWQdKerlwdC8=; b=/3AoT0IbBunpN8fIeZAmfBT1tDugFsaMy4vciiR2Ev7oz0U4eNfGYGo6t94PhVVi+ekkjoRdX oZPEEnQZ95iBlA6yAatcKE7QMTV7e2XcrslIHcfUSzy7jcqVJbmAahm X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A function can contain nested switch tables using different registers as base address. In order to avoid failure in tracking those switch tables, the register containing the base address needs to be taken into account. To do so, add a 5 bits field in struct instruction that will hold the ID of the register containing the base address of the switch table and take that register into account during the backward search in order to not stop the walk when encountering a jump related to another switch table. On architectures not handling it, the ID stays nul and has no impact on the search. To enable that, also provide to arch_find_switch_table() the dynamic instruction related to a table search. Also allow prev_insn_same_sec() to be used outside check.c so that architectures can backward walk through instruction to find out which register is used as base address for a switch table. Signed-off-by: Christophe Leroy --- tools/objtool/arch/powerpc/special.c | 3 ++- tools/objtool/arch/x86/special.c | 3 ++- tools/objtool/check.c | 9 +++++---- tools/objtool/include/objtool/check.h | 6 ++++-- tools/objtool/include/objtool/special.h | 3 ++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powe= rpc/special.c index 51610689abf7..0b3a766c4842 100644 --- a/tools/objtool/arch/powerpc/special.c +++ b/tools/objtool/arch/powerpc/special.c @@ -14,7 +14,8 @@ bool arch_support_alt_relocation(struct special_alt *spec= ial_alt, =20 struct reloc *arch_find_switch_table(struct objtool_file *file, struct instruction *insn, - unsigned long *table_size) + unsigned long *table_size, + struct instruction *orig_insn) { exit(-1); } diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 76c7933bcb19..b0147923a70c 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -110,7 +110,8 @@ bool arch_support_alt_relocation(struct special_alt *sp= ecial_alt, */ struct reloc *arch_find_switch_table(struct objtool_file *file, struct instruction *insn, - unsigned long *table_size) + unsigned long *table_size, + struct instruction *orig_insn) { struct reloc *text_reloc, *rodata_reloc; struct section *table_sec; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 613d169eb6b8..72b977f81dd6 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -81,8 +81,8 @@ static struct instruction *next_insn_same_func(struct obj= tool_file *file, return find_insn(file, func->cfunc->sec, func->cfunc->offset); } =20 -static struct instruction *prev_insn_same_sec(struct objtool_file *file, - struct instruction *insn) +struct instruction *prev_insn_same_sec(struct objtool_file *file, + struct instruction *insn) { if (insn->idx =3D=3D 0) { if (insn->prev_len) @@ -2028,7 +2028,8 @@ static void find_jump_table(struct objtool_file *file= , struct symbol *func, insn && insn_func(insn) && insn_func(insn)->pfunc =3D=3D func; insn =3D insn->first_jump_src ?: prev_insn_same_sym(file, insn)) { =20 - if (insn !=3D orig_insn && insn->type =3D=3D INSN_JUMP_DYNAMIC) + if (insn !=3D orig_insn && insn->type =3D=3D INSN_JUMP_DYNAMIC && + insn->gpr =3D=3D orig_insn->gpr) break; =20 /* allow small jumps within the range */ @@ -2038,7 +2039,7 @@ static void find_jump_table(struct objtool_file *file= , struct symbol *func, insn->jump_dest->offset > orig_insn->offset)) break; =20 - table_reloc =3D arch_find_switch_table(file, insn, &table_size); + table_reloc =3D arch_find_switch_table(file, insn, &table_size, orig_ins= n); if (!table_reloc) continue; =20 diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index e1cd13cd28a3..8b68f840dddb 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -63,8 +63,9 @@ struct instruction { noendbr : 1, unret : 1, visited : 4, - no_reloc : 1; - /* 10 bit hole */ + no_reloc : 1, + gpr : 5; + /* 5 bit hole */ =20 struct alt_group *alt_group; struct instruction *jump_dest; @@ -118,6 +119,7 @@ struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset); =20 struct instruction *next_insn_same_sec(struct objtool_file *file, struct i= nstruction *insn); +struct instruction *prev_insn_same_sec(struct objtool_file *file, struct i= nstruction *insn); =20 #define sec_for_each_insn(file, _sec, insn) \ for (insn =3D find_insn(file, _sec, 0); \ diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/includ= e/objtool/special.h index e7ee7ffccefd..aca1f7762f5d 100644 --- a/tools/objtool/include/objtool/special.h +++ b/tools/objtool/include/objtool/special.h @@ -39,5 +39,6 @@ bool arch_support_alt_relocation(struct special_alt *spec= ial_alt, struct reloc *reloc); struct reloc *arch_find_switch_table(struct objtool_file *file, struct instruction *insn, - unsigned long *table_size); + unsigned long *table_size, + struct instruction *orig_insn); #endif /* _SPECIAL_H */ --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3EE11DDC01 for ; Wed, 15 Jan 2025 22:50:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981440; cv=none; b=IXU12z/M0Sa0g0goHDZzSaQPmjst+tNp32FRIHH5uqMlJXBOlowophtXpBqJW0wJTqVMEiVzw48JxI48ccCu5AzEs8GVnOth5xpZSWyxYbd2SKA2ftFPgX5DAMAI3w2N1vMHHHLoJ9oOjJ9t/uj7ZZw8QeJGhkWjPrAw100mJpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981440; c=relaxed/simple; bh=5NdIHm7DD4bTebG2kf3cj71x6eBUoq5xTfa2EU+XO1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CMFEsTFQ5Ko6uVVLfJKGM/YOdWp/aZdzhB8dPCcAcV2OHbkpWByHcLOm6Uw4/LnMEChn6K9apIE9Ul7V0It9ELB5wfNO9+kvN+IpwZOd3OQuZvxVg+tss90E3fB9kajf86DU+/HgGZdLGAS9WkyBg67sGIwhdXoi0cF0+p3Wju8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcd2pn8z9sSY; Wed, 15 Jan 2025 23:43:13 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xdYktiID7W5v; Wed, 15 Jan 2025 23:43:13 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcd1v6Vz9sSX; Wed, 15 Jan 2025 23:43:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2F7B08B77A; Wed, 15 Jan 2025 23:43:13 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id Kex8_2sVL1dd; Wed, 15 Jan 2025 23:43:13 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id BAC938B774; Wed, 15 Jan 2025 23:43:10 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 09/15] objtool: Find end of switch table directly Date: Wed, 15 Jan 2025 23:42:49 +0100 Message-ID: <3e31a9910c471ad9c17b76a96cc910e7a8aa2a10.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980964; l=3780; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=5NdIHm7DD4bTebG2kf3cj71x6eBUoq5xTfa2EU+XO1s=; b=BcAyjkvv2GQlZ+Fyl9KJ+tQwNqAdeIWlAHl9O6Ty4zCgkXVj/S8xZQe1aKUxm5oF0FDMbJc7W JOP1Tx9G/avATVxQ3jZE7d6jRzv5jFdeUmD+Jmkmbse21bYHCv8HrCo X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" At the time being, the end of a switch table can only be known once the start of the following switch table has ben located. This is a problem when switch tables are nested because until the first switch table is properly added, the second one cannot be located as a the backward walk will abut on the dynamic switch of the previous one. So perform a first forward walk in the code in order to locate all possible relocations to switch tables and build a local table with those relocations. Later on once one switch table is found, go through this local table to know where next switch table starts. Signed-off-by: Christophe Leroy --- tools/objtool/check.c | 63 ++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 72b977f81dd6..0ad2bdd92232 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2058,14 +2058,30 @@ static void find_jump_table(struct objtool_file *fi= le, struct symbol *func, } } =20 +static struct reloc *find_next_table(struct instruction *insn, + struct reloc **table, unsigned int size) +{ + unsigned long offset =3D reloc_offset(insn_jump_table(insn)); + int i; + struct reloc *reloc =3D NULL; + + for (i =3D 0; i < size; i++) { + if (reloc_offset(table[i]) > offset && + (!reloc || reloc_offset(table[i]) < reloc_offset(reloc))) + reloc =3D table[i]; + } + return reloc; +} + /* * First pass: Mark the head of each jump table so that in the next pass, * we know when a given jump table ends and the next one starts. */ static int mark_add_func_jump_tables(struct objtool_file *file, - struct symbol *func) + struct symbol *func, + struct reloc **table, unsigned int size) { - struct instruction *insn, *last =3D NULL, *insn_t1 =3D NULL, *insn_t2; + struct instruction *insn, *last =3D NULL; int ret =3D 0; =20 func_for_each_insn(file, func, insn) { @@ -2094,23 +2110,11 @@ static int mark_add_func_jump_tables(struct objtool= _file *file, if (!insn_jump_table(insn)) continue; =20 - if (!insn_t1) { - insn_t1 =3D insn; - continue; - } - - insn_t2 =3D insn; - - ret =3D add_jump_table(file, insn_t1, insn_jump_table(insn_t2)); + ret =3D add_jump_table(file, insn, find_next_table(insn, table, size)); if (ret) return ret; - - insn_t1 =3D insn_t2; } =20 - if (insn_t1) - ret =3D add_jump_table(file, insn_t1, NULL); - return ret; } =20 @@ -2123,15 +2127,42 @@ static int add_jump_table_alts(struct objtool_file = *file) { struct symbol *func; int ret; + struct instruction *insn; + unsigned int size =3D 0, i =3D 0; + struct reloc **table =3D NULL; =20 if (!file->rodata) return 0; =20 + for_each_insn(file, insn) { + struct instruction *dest_insn; + struct reloc *reloc; + unsigned long table_size; + + func =3D insn_func(insn) ? insn_func(insn)->pfunc : NULL; + reloc =3D arch_find_switch_table(file, insn, &table_size, NULL); + /* + * Each table entry has a rela associated with it. The rela + * should reference text in the same function as the original + * instruction. + */ + if (!reloc) + continue; + dest_insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); + if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != =3D func) + continue; + if (i =3D=3D size) { + size +=3D 1024; + table =3D realloc(table, size * sizeof(*table)); + } + table[i++] =3D reloc; + } + for_each_sym(file, func) { if (func->type !=3D STT_FUNC) continue; =20 - ret =3D mark_add_func_jump_tables(file, func); + ret =3D mark_add_func_jump_tables(file, func, table, i); if (ret) return ret; } --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A6641DD520 for ; Wed, 15 Jan 2025 22:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981444; cv=none; b=VIxpFCv655X8StwQSdVtCKncXrwtrhARVvYIHhtQwn+2dUeWkBl4JZnFBq7xU4LOfr22h2UhxhO+u48fE4BzdKTrxDDx6LK3qj1/612ZOnuPKNYbPmzz8GxTLG+dlbG2+xv0BcrEplt/kJ0W/onGTCVVHO55onQj1mPfIPd01so= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981444; c=relaxed/simple; bh=JuwlSgEwF/YR6LrF/3dyTUkenLYF1P/hJhBSM22DTYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HCIXWi7AdfeSvihgWNWOcm2/nxJvG/1yU/tHZ8YiMw2IXQ0smLK3DsmB32SklaeSyr+dtJgMgSgEQVRak1OxaKoBA2Sa4kl+Akvz3L/Q9nCpYt8p1t/6WFudK6ZvnwB77izq9+akUMEUjqKGF+hxPCIl4CTky3C2JbgUnSTMRLA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcg4pRZz9sSc; Wed, 15 Jan 2025 23:43:15 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XdwoUHxHyRny; Wed, 15 Jan 2025 23:43:15 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcg43nvz9sSZ; Wed, 15 Jan 2025 23:43:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 75C5F8B77A; Wed, 15 Jan 2025 23:43:15 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 3fVrbZ-f6jS4; Wed, 15 Jan 2025 23:43:15 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 498838B774; Wed, 15 Jan 2025 23:43:13 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 10/15] objtool: When looking for switch tables also follow conditional and dynamic jumps Date: Wed, 15 Jan 2025 23:42:50 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980964; l=1637; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=JuwlSgEwF/YR6LrF/3dyTUkenLYF1P/hJhBSM22DTYs=; b=6n79kSoRqJEkcLY6Y1MpivBmSAT/lzEzZyAMGNN3v6mvPqEx/uoTD+ysqCfWtDqZDQCsWhr20 HH+SYrmEjHED2JmmWjRWWspBKF4dphfKId01AsZ6iKYLf6WU0zSih5j X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When walking backward to find the base address of a switch table, also take into account conditionnal branches and dynamic jumps from a previous switch table. To avoid mis-routing, break when stumbling on a function return. Signed-off-by: Christophe Leroy --- tools/objtool/check.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 0ad2bdd92232..87b81d8e01c0 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1998,6 +1998,8 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, alt->next =3D insn->alts; insn->alts =3D alt; prev_offset =3D reloc_offset(reloc); + if (!dest_insn->first_jump_src) + dest_insn->first_jump_src =3D insn; } =20 if (!prev_offset) { @@ -2032,6 +2034,9 @@ static void find_jump_table(struct objtool_file *file= , struct symbol *func, insn->gpr =3D=3D orig_insn->gpr) break; =20 + if (insn->type =3D=3D INSN_RETURN) + break; + /* allow small jumps within the range */ if (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL && insn->jump_dest && @@ -2093,8 +2098,7 @@ static int mark_add_func_jump_tables(struct objtool_f= ile *file, * that find_jump_table() can back-track using those and * avoid some potentially confusing code. */ - if (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL && insn->jump_dest && - insn->offset > last->offset && + if (is_static_jump(insn) && insn->jump_dest && insn->jump_dest->offset > insn->offset && !insn->jump_dest->first_jump_src) { =20 --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DE211DED49 for ; Wed, 15 Jan 2025 22:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981452; cv=none; b=qNLFq8a3/ZZsaQt1QD4cqy5GGiYqRC4MUvPN4a245iFh5J23A6qOCtRNO96DwIJAGDz7PtUT8mCJG/tHuiml3OwrPxtq3iWjjJ7V9shzDGDrqFW0lw5ufA5qvxlWKsM0kjBUYhFAP5k/QUqC3AWhaDOfDRrEjuYY5zms/FyGnmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981452; c=relaxed/simple; bh=ZbF92lKn/a2BcO+/Rt9A3tjdZfwn64sAKLypVaGo9hw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cKIkOb/Y5xKaJ9xVg2XjQWa6+e2VJVftcgu/pNgUP81wZwDt5bjlxW3duJ5p/rZBB6kSf/UvTweOL8YTEvzWUxRJ6sYy8Ng6iEao5f/X8AVY9STtOkSI1K8YUua/ZiuyGQ/LZwa2SOACBD7EXqljCrpSWWpyByTjpi/42IERY6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLck6gxXz9sSf; Wed, 15 Jan 2025 23:43:18 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Dr5Ps3RQ53L0; Wed, 15 Jan 2025 23:43:18 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLck5yY5z9sSd; Wed, 15 Jan 2025 23:43:18 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id BCD238B77A; Wed, 15 Jan 2025 23:43:18 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id o-cH9_aqzb1D; Wed, 15 Jan 2025 23:43:18 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A04948B774; Wed, 15 Jan 2025 23:43:15 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 11/15] objtool: .rodata.cst{2/4/8/16} are not switch tables Date: Wed, 15 Jan 2025 23:42:51 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980964; l=775; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=ZbF92lKn/a2BcO+/Rt9A3tjdZfwn64sAKLypVaGo9hw=; b=HVqgwXZ3/EXy0sYgLk6n8xkh8j2Gln6sKIw9R/abzTvIv6inqVrwnFsumz+MkEEFrqio6tXGN 941QxuIDnGhBaJaHHI9M6hFbpY2HnvgcT9nhxdDO96zQyP/U1c+Ixib X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Exclude sections named .rodata.cst2 .rodata.cst4 .rodata.cst8 .rodata.cst16 as they won't contain switch tables. Signed-off-by: Christophe Leroy --- tools/objtool/check.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 87b81d8e01c0..91436f4b3622 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2506,7 +2506,8 @@ static void mark_rodata(struct objtool_file *file) */ for_each_sec(file, sec) { if (!strncmp(sec->name, ".rodata", 7) && - !strstr(sec->name, ".str1.")) { + !strstr(sec->name, ".str1.") && + !strstr(sec->name, ".cst")) { sec->rodata =3D true; found =3D true; } --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9681B1DE3B3 for ; Wed, 15 Jan 2025 22:50:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981428; cv=none; b=SNO1HGjP2uRgKT6Vld4hPlR1FDotuulRCenG5sPGcHzIZHf/op9jSJOz2nc0M81b/+A5iANaUYIrJsTWG94uVkz8cu11ttcrKanQ927o/7BRiRdXTsuYyogyxlcXmLpgr96jTa5nsC0BPD/9/DlHAAtjWP/+4O7IzeM+w1Bto+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981428; c=relaxed/simple; bh=jUmgRhfOUOKcm47vVLJz0Uk+vweVINDmw47p9P553do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J90MH2O0GA2OkkZdLmxxKqjSIsq3Oy24dLaDSlX7R98AMDLWkuOuTDa4KCu5/nN6FMLa1g4xdvR/xIn7IiNKqGd+DFOGLrPoF3ku9xDzHiuI6hiPkWOkZye93u4xKMAz5VzbQg5+3ob7Ce8VsylT5Zl7zMfMaZWhzv1UufTltsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcn297Rz9sSh; Wed, 15 Jan 2025 23:43:21 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fuPRgmlINGTC; Wed, 15 Jan 2025 23:43:21 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcn13D6z9sSg; Wed, 15 Jan 2025 23:43:21 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 13A798B77A; Wed, 15 Jan 2025 23:43:21 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id TTrr0vm5x28f; Wed, 15 Jan 2025 23:43:20 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E1CBB8B774; Wed, 15 Jan 2025 23:43:18 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 12/15] objtool: Add support for more complex UACCESS control Date: Wed, 15 Jan 2025 23:42:52 +0100 Message-ID: <64a6921ec7bc78c4b25561cf13e8147f26e884a6.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980964; l=3081; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=jUmgRhfOUOKcm47vVLJz0Uk+vweVINDmw47p9P553do=; b=PvDeZ1WUGIKvE/gRmmck4Oiaz1dQxNwL0Klut/cRBsip4QjA8Cuhi0vktmLlI0qxgq4GTnG0y eXtRWgLdHSeApvZuNEn1PuyKh8XD4VLq3y6BPOz72m6IFeg10tqv7oo X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On x86, UACCESS is controlled by two instructions: STAC and CLAC. STAC instruction enables UACCESS while CLAC disables UACCESS. This is simple enough for objtool to locate UACCESS enable and disable. But on powerpc it is a bit more complex, the same instruction is used for enabling and disabling UACCESS, and the same instruction can be used for many other things. It would be too complex to use exclusively instruction decoding. To help objtool, annotate such instructions, on the same principle as reachable/unreachable instructions. And add ANNOTATE_UACCESS_BEGIN and ANNOTATE_UACCESS_END macros to be used in inline assembly code to annotate UACCESS enable and UACCESS disable instructions. Signed-off-by: Christophe Leroy --- v5: Use generic annotation infrastructure --- include/linux/objtool.h | 3 +++ include/linux/objtool_types.h | 2 ++ tools/include/linux/objtool_types.h | 2 ++ tools/objtool/check.c | 8 ++++++++ 4 files changed, 15 insertions(+) diff --git a/include/linux/objtool.h b/include/linux/objtool.h index c722a921165b..7efd731da2a2 100644 --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -183,6 +183,9 @@ */ #define ANNOTATE_REACHABLE(label) __ASM_ANNOTATE(label, ANNOTYPE_REACHABLE) =20 +#define ANNOTATE_UACCESS_BEGIN ASM_ANNOTATE(ANNOTYPE_UACCESS_BEGIN) +#define ANNOTATE_UACCESS_END ASM_ANNOTATE(ANNOTYPE_UACCESS_END) + #else #define ANNOTATE_NOENDBR ANNOTATE type=3DANNOTYPE_NOENDBR #define ANNOTATE_RETPOLINE_SAFE ANNOTATE type=3DANNOTYPE_RETPOLINE_SAFE diff --git a/include/linux/objtool_types.h b/include/linux/objtool_types.h index df5d9fa84dba..28da3d989e65 100644 --- a/include/linux/objtool_types.h +++ b/include/linux/objtool_types.h @@ -65,5 +65,7 @@ struct unwind_hint { #define ANNOTYPE_IGNORE_ALTS 6 #define ANNOTYPE_INTRA_FUNCTION_CALL 7 #define ANNOTYPE_REACHABLE 8 +#define ANNOTYPE_UACCESS_BEGIN 9 +#define ANNOTYPE_UACCESS_END 10 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ diff --git a/tools/include/linux/objtool_types.h b/tools/include/linux/objt= ool_types.h index df5d9fa84dba..28da3d989e65 100644 --- a/tools/include/linux/objtool_types.h +++ b/tools/include/linux/objtool_types.h @@ -65,5 +65,7 @@ struct unwind_hint { #define ANNOTYPE_IGNORE_ALTS 6 #define ANNOTYPE_INTRA_FUNCTION_CALL 7 #define ANNOTYPE_REACHABLE 8 +#define ANNOTYPE_UACCESS_BEGIN 9 +#define ANNOTYPE_UACCESS_END 10 =20 #endif /* _LINUX_OBJTOOL_TYPES_H */ diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 91436f4b3622..54625f09d831 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2422,6 +2422,14 @@ static int __annotate_late(struct objtool_file *file= , int type, struct instructi insn->dead_end =3D false; break; =20 + case ANNOTYPE_UACCESS_BEGIN: + insn->type =3D INSN_STAC; + break; + + case ANNOTYPE_UACCESS_END: + insn->type =3D INSN_CLAC; + break; + default: WARN_INSN(insn, "Unknown annotation type: %d", type); break; --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05FDA1DE2DF for ; Wed, 15 Jan 2025 22:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981419; cv=none; b=fkddolDpmhRpx4UPzfDfjLyURG7PM7hx9KzjJGt7ue+/5kNCla1k9y1VJ8bxXsB96oaAVzBEu7a1wvLjAjzj9UCVPYOhTHI9pECVPJrCvyDiqLiKQx0bJlN5k94lgYNRfgMF7+kGfdgJSW9vkanV0g5ejXjX6JQxVKsJTLZT3CY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981419; c=relaxed/simple; bh=LnrGt2KAlzy5sv5GWt/HSpRIYrEvSi7R0lyIHIdGvlI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C3S1V06IkeWUXj4vTXzQzRLP+FmDjaCrSpHyyKY4NP5tFTVnU0xigy3YlLqwtpZ1dIfLJRWa0vT2NJabEvhstQ5SAW1ArLClawGu17Dpgjqd7rPr7rbmF+kUtxfFgHQwgdOihIaQ4wHKd/cQUGA3JjIKIf7CEzupOmUSp28N7p0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcr118tz9sSm; Wed, 15 Jan 2025 23:43:24 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id guOiPyj1LLke; Wed, 15 Jan 2025 23:43:24 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcr05Rjz9sSj; Wed, 15 Jan 2025 23:43:24 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E4AA08B77A; Wed, 15 Jan 2025 23:43:23 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id oIHFxUtQG8ax; Wed, 15 Jan 2025 23:43:23 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2FB5C8B774; Wed, 15 Jan 2025 23:43:21 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 13/15] objtool: Prepare noreturns.h for more architectures Date: Wed, 15 Jan 2025 23:42:53 +0100 Message-ID: <12729c2b5f944bc2a6938bc3e3b33e5e703a2258.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980964; l=2918; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=LnrGt2KAlzy5sv5GWt/HSpRIYrEvSi7R0lyIHIdGvlI=; b=PeX1SnrfDYVTrlFpXawBVcEdOvOavZBDC0xyS4VRtYab4BdU1TZGD+horiBPuQPyfgaWnPDJa xuwd87ltRpGCBryhJqTYieShBxw3TtH7bQRKClX7gpFt8WmrctQ4c2V X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" noreturns.h is a mix of x86 specific functions and more generic core functions. In preparation of inclusion of powerpc, split x86 functions out of noreturns.h into arch/noreturns.h Signed-off-by: Christophe Leroy --- .../objtool/arch/x86/include/arch/noreturns.h | 20 +++++++++++++++++++ tools/objtool/noreturns.h | 14 ++----------- 2 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 tools/objtool/arch/x86/include/arch/noreturns.h diff --git a/tools/objtool/arch/x86/include/arch/noreturns.h b/tools/objtoo= l/arch/x86/include/arch/noreturns.h new file mode 100644 index 000000000000..a4262aff3917 --- /dev/null +++ b/tools/objtool/arch/x86/include/arch/noreturns.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * This is a (sorted!) list of all known __noreturn functions in arch/x86. + * It's needed for objtool to properly reverse-engineer the control flow g= raph. + * + * Yes, this is unfortunate. A better solution is in the works. + */ +NORETURN(cpu_bringup_and_idle) +NORETURN(ex_handler_msr_mce) +NORETURN(hlt_play_dead) +NORETURN(hv_ghcb_terminate) +NORETURN(machine_real_restart) +NORETURN(rewind_stack_and_make_dead) +NORETURN(sev_es_terminate) +NORETURN(snp_abort) +NORETURN(x86_64_start_kernel) +NORETURN(x86_64_start_reservations) +NORETURN(xen_cpu_bringup_again) +NORETURN(xen_start_kernel) diff --git a/tools/objtool/noreturns.h b/tools/objtool/noreturns.h index f37614cc2c1b..dfee1c91a70d 100644 --- a/tools/objtool/noreturns.h +++ b/tools/objtool/noreturns.h @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ =20 +#include + /* * This is a (sorted!) list of all known __noreturn functions in the kerne= l. * It's needed for objtool to properly reverse-engineer the control flow g= raph. @@ -19,33 +21,21 @@ NORETURN(__x64_sys_exit_group) NORETURN(arch_cpu_idle_dead) NORETURN(bch2_trans_in_restart_error) NORETURN(bch2_trans_restart_error) -NORETURN(cpu_bringup_and_idle) NORETURN(cpu_startup_entry) NORETURN(do_exit) NORETURN(do_group_exit) NORETURN(do_task_dead) -NORETURN(ex_handler_msr_mce) -NORETURN(hlt_play_dead) -NORETURN(hv_ghcb_terminate) NORETURN(kthread_complete_and_exit) NORETURN(kthread_exit) NORETURN(kunit_try_catch_throw) -NORETURN(machine_real_restart) NORETURN(make_task_dead) NORETURN(mpt_halt_firmware) NORETURN(nmi_panic_self_stop) NORETURN(panic) NORETURN(panic_smp_self_stop) NORETURN(rest_init) -NORETURN(rewind_stack_and_make_dead) NORETURN(rust_begin_unwind) NORETURN(rust_helper_BUG) -NORETURN(sev_es_terminate) -NORETURN(snp_abort) NORETURN(start_kernel) NORETURN(stop_this_cpu) NORETURN(usercopy_abort) -NORETURN(x86_64_start_kernel) -NORETURN(x86_64_start_reservations) -NORETURN(xen_cpu_bringup_again) -NORETURN(xen_start_kernel) --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D48B41DD520 for ; Wed, 15 Jan 2025 22:50:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981448; cv=none; b=QfjaF3yX/BwJy2ymiI7OtVwZTp1HRRC2GbO48RUxlut6/FOftH/AQ1T3bO/znbWZNWxA6zIy/1iUI7hG2B46SGAH18zZCdLiLgIZfcMjLK0U1v3uvNH67GJqbOvNMvIdpeuPTPeSEja4ptU106hQlygy0adrSIR5zA2VqNlUTqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981448; c=relaxed/simple; bh=buhY3GoC0LGY1HUaDu1bTWqVjA42DPm4i5qlmE4s1Nc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=adbtjY9RysR0YI6zSkFlWPq+J680lh3BDQULjqQFXXvxY4WDa7n8ubA2RpDkXmMC41eSRo2HzW6ZYmQZ/8PlTSw56Zu++MyyI4W0alygYSMqey7xcjTxgMZWY5g6PqGz84lNeL6UAS0+lAPg4ekNKtICYFj28dMb1tBMgo/tZ4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLct50S8z9sSq; Wed, 15 Jan 2025 23:43:26 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kzmB7gqQMCTP; Wed, 15 Jan 2025 23:43:26 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLct3ptxz9sSn; Wed, 15 Jan 2025 23:43:26 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6F3AF8B77A; Wed, 15 Jan 2025 23:43:26 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id xL4HBP5zkE8F; Wed, 15 Jan 2025 23:43:26 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 08F088B774; Wed, 15 Jan 2025 23:43:23 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 14/15] powerpc/bug: Annotate reachable after warning trap Date: Wed, 15 Jan 2025 23:42:54 +0100 Message-ID: <25e776852c18471a78dca172c6253e16e8d28c51.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980964; l=2325; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=buhY3GoC0LGY1HUaDu1bTWqVjA42DPm4i5qlmE4s1Nc=; b=Zzx0LN7CaVkiZJDwdxeV+ibCLDFY96znMCMxLBDAlvwLJ2kQLdeuupSEGG4ZBBiXYwNYUUDFV Q5UGbSOaXY1D8KkUN/X3yxxwGstc0o5rsND8gM0oXshr0I9HPzvQNOo X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit is copied from commit bfb1a7c91fb7 ("x86/bug: Merge annotate_reachable() into _BUG_FLAGS() asm") 'twi 31,0,0' is a BUG instruction, which is by default a dead end. But the same instruction is used for WARNINGs and the execution resumes with the following instruction. Mark it reachable so that objtool knows that it is not a dead end in that case. Also change the unreachable() annotation by __builtin_unreachable() since objtool already knows that a BUG instruction is a dead end. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/bug.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h index 1db485aacbd9..c41e9f903b5b 100644 --- a/arch/powerpc/include/asm/bug.h +++ b/arch/powerpc/include/asm/bug.h @@ -4,6 +4,7 @@ #ifdef __KERNEL__ =20 #include +#include =20 #ifdef CONFIG_BUG =20 @@ -51,10 +52,11 @@ ".previous\n" #endif =20 -#define BUG_ENTRY(insn, flags, ...) \ +#define BUG_ENTRY(insn, flags, extra, ...) \ __asm__ __volatile__( \ "1: " insn "\n" \ _EMIT_BUG_ENTRY \ + extra \ : : "i" (__FILE__), "i" (__LINE__), \ "i" (flags), \ "i" (sizeof(struct bug_entry)), \ @@ -67,12 +69,12 @@ */ =20 #define BUG() do { \ - BUG_ENTRY("twi 31, 0, 0", 0); \ - unreachable(); \ + BUG_ENTRY("twi 31, 0, 0", 0, ""); \ + __builtin_unreachable(); \ } while (0) #define HAVE_ARCH_BUG =20 -#define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (f= lags)) +#define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (f= lags), ANNOTATE_REACHABLE(1b)) =20 #ifdef CONFIG_PPC64 #define BUG_ON(x) do { \ @@ -80,7 +82,7 @@ if (x) \ BUG(); \ } else { \ - BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \ + BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "", "r" ((__force long)(x))); \ } \ } while (0) =20 @@ -92,7 +94,7 @@ } else { \ BUG_ENTRY(PPC_TLNEI " %4, 0", \ BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN), \ - "r" (__ret_warn_on)); \ + "", "r" (__ret_warn_on)); \ } \ unlikely(__ret_warn_on); \ }) --=20 2.47.0 From nobody Wed Feb 5 12:56:27 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D8261DDC3C for ; Wed, 15 Jan 2025 22:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981462; cv=none; b=kBsuFQNuz4FLg/kXJx9CcQ78+DZaHXSRkQu64DQwMzrGZuAMBQgR/4IU8SrMDU+rdH+vr2wnNiulGXegTrBZmoUs3tuMewu2uOe4zcvoBcTWse5LvXCTsnfuHBfsvMFjqck7d/r6eZtOqsDHO4W65Z1G5qxHNBwkM2UBA69xuvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981462; c=relaxed/simple; bh=TtQFZRV8HkQ6RWtta5Z+u17f88zSx0PTdtTwQ2K2ffc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hXE5Er9GjPdcLi5OCLT1stcP0pj6NCyYijFTiDuruKMrDUYnv7OUfyEitfuCbv1t2TzOd7+nQdjv+KESTSHemuFI9Lre0gx82gvU4QHvw4PZ2jgmFaVoGv51VUnh46lSmH3cQ4lt7Rpoi5pvaHGVPW33Z7UH4s1Nf1dbCY+e+Yg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcx5mB1z9sSr; Wed, 15 Jan 2025 23:43:29 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0nPmvMzRZDJk; Wed, 15 Jan 2025 23:43:29 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcx4gsJz9sSp; Wed, 15 Jan 2025 23:43:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8F3E98B77A; Wed, 15 Jan 2025 23:43:29 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id AGpYmkgwMLrx; Wed, 15 Jan 2025 23:43:29 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 989968B774; Wed, 15 Jan 2025 23:43:26 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 15/15] powerpc: Implement UACCESS validation on PPC32 Date: Wed, 15 Jan 2025 23:42:55 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980964; l=16785; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=TtQFZRV8HkQ6RWtta5Z+u17f88zSx0PTdtTwQ2K2ffc=; b=xGhi/efhy8EpXiPihSXGVzdUrdp/NzdOWxAGGlLvY4/eHbugSOc106PEocxE5flA/iG0NzLLX Tc1mBH8nmk4BXGKTbTI/00VfG6dkfxVhxIwGpd3VxxpsaN/prSAB87w X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to implement UACCESS validation, objtool support for powerpc needs to be enhanced to decode more instructions. It also requires implementation of switch tables finding. On PPC32 it is similar to x86, switch tables are anonymous in .rodata, the difference is that the value is relative to its index in the table. Another big different is that several switch tables can be nested so the register containing the table base address also needs to be tracked and taken into account. Don't activate it for Clang for now because its switch tables are different from GCC switch tables. Then comes the UACCESS enabling/disabling instructions. On booke and 8xx it is done with a mtspr instruction. For 8xx that's in SPRN_MD_AP, for booke that's in SPRN_PID. Annotate those instructions. No work has been done for ASM files, they are not used for UACCESS so for the moment just tell objtool to ignore ASM files. For relocatable code, the .got2 relocation preceding each global function needs to be marked as ignored because some versions of GCC do this: 120: 00 00 00 00 .long 0x0 120: R_PPC_REL32 .got2+0x7ff0 00000124 : 124: 94 21 ff f0 stwu r1,-16(r1) 128: 7c 08 02 a6 mflr r0 12c: 42 9f 00 05 bcl 20,4*cr7+so,130 130: 39 00 00 00 li r8,0 134: 39 20 00 08 li r9,8 138: 93 c1 00 08 stw r30,8(r1) 13c: 7f c8 02 a6 mflr r30 140: 90 01 00 14 stw r0,20(r1) 144: 80 1e ff f0 lwz r0,-16(r30) 148: 7f c0 f2 14 add r30,r0,r30 14c: 81 5e 80 00 lwz r10,-32768(r30) 150: 80 fe 80 04 lwz r7,-32764(r30) Also declare longjmp() and start_secondary_resume() as global noreturn functions, and declare __copy_tofrom_user() and __arch_clear_user() as UACCESS safe. Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 2 + arch/powerpc/include/asm/book3s/32/kup.h | 2 + arch/powerpc/include/asm/nohash/32/kup-8xx.h | 4 +- arch/powerpc/include/asm/nohash/kup-booke.h | 4 +- arch/powerpc/kexec/core_32.c | 4 +- arch/powerpc/mm/nohash/kup.c | 2 + tools/objtool/arch/powerpc/decode.c | 150 +++++++++++++++++- .../arch/powerpc/include/arch/noreturns.h | 11 ++ .../arch/powerpc/include/arch/special.h | 9 ++ tools/objtool/arch/powerpc/special.c | 37 ++++- tools/objtool/check.c | 6 +- 11 files changed, 216 insertions(+), 15 deletions(-) create mode 100644 tools/objtool/arch/powerpc/include/arch/noreturns.h diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index a0ce777f9706..525ab52b79fb 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -162,6 +162,7 @@ config PPC select ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE if PPC_RADIX_MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO + select ARCH_OBJTOOL_SKIP_ASM select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT select ARCH_SPLIT_ARG64 if PPC32 @@ -267,6 +268,7 @@ config PPC select HAVE_OPTPROBES select HAVE_OBJTOOL if ARCH_USING_PATCHABLE_FUNCTION_ENTRY || MPROFILE_= KERNEL || PPC32 select HAVE_OBJTOOL_MCOUNT if HAVE_OBJTOOL + select HAVE_UACCESS_VALIDATION if HAVE_OBJTOOL && PPC_KUAP && PPC32 && C= C_IS_GCC select HAVE_PERF_EVENTS select HAVE_PERF_EVENTS_NMI if PPC64 select HAVE_PERF_REGS diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/includ= e/asm/book3s/32/kup.h index 4e14a5427a63..9e158b1dd3a6 100644 --- a/arch/powerpc/include/asm/book3s/32/kup.h +++ b/arch/powerpc/include/asm/book3s/32/kup.h @@ -34,6 +34,7 @@ static __always_inline void uaccess_begin_32s(unsigned lo= ng addr) asm volatile(ASM_MMU_FTR_IFSET( "mfsrin %0, %1;" "rlwinm %0, %0, 0, %2;" + ANNOTATE_UACCESS_BEGIN "mtsrin %0, %1;" "isync", "", %3) : "=3D&r"(tmp) @@ -48,6 +49,7 @@ static __always_inline void uaccess_end_32s(unsigned long= addr) asm volatile(ASM_MMU_FTR_IFSET( "mfsrin %0, %1;" "oris %0, %0, %2;" + ANNOTATE_UACCESS_END "mtsrin %0, %1;" "isync", "", %3) : "=3D&r"(tmp) diff --git a/arch/powerpc/include/asm/nohash/32/kup-8xx.h b/arch/powerpc/in= clude/asm/nohash/32/kup-8xx.h index 46bc5925e5fd..8f3a859fe0a1 100644 --- a/arch/powerpc/include/asm/nohash/32/kup-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/kup-8xx.h @@ -39,13 +39,13 @@ static __always_inline unsigned long __kuap_get_and_ass= ert_locked(void) =20 static __always_inline void uaccess_begin_8xx(unsigned long val) { - asm(ASM_MMU_FTR_IFSET("mtspr %0, %1", "", %2) : : + asm(ANNOTATE_UACCESS_BEGIN ASM_MMU_FTR_IFSET("mtspr %0, %1", "", %2) : : "i"(SPRN_MD_AP), "r"(val), "i"(MMU_FTR_KUAP) : "memory"); } =20 static __always_inline void uaccess_end_8xx(void) { - asm(ASM_MMU_FTR_IFSET("mtspr %0, %1", "", %2) : : + asm(ANNOTATE_UACCESS_END ASM_MMU_FTR_IFSET("mtspr %0, %1", "", %2) : : "i"(SPRN_MD_AP), "r"(MD_APG_KUAP), "i"(MMU_FTR_KUAP) : "memory"); } =20 diff --git a/arch/powerpc/include/asm/nohash/kup-booke.h b/arch/powerpc/inc= lude/asm/nohash/kup-booke.h index 0c7c3258134c..b12d87e457fa 100644 --- a/arch/powerpc/include/asm/nohash/kup-booke.h +++ b/arch/powerpc/include/asm/nohash/kup-booke.h @@ -63,13 +63,13 @@ static __always_inline unsigned long __kuap_get_and_ass= ert_locked(void) =20 static __always_inline void uaccess_begin_booke(unsigned long val) { - asm(ASM_MMU_FTR_IFSET("mtspr %0, %1; isync", "", %2) : : + asm(ANNOTATE_UACCESS_BEGIN ASM_MMU_FTR_IFSET("mtspr %0, %1; isync", "", %= 2) : : "i"(SPRN_PID), "r"(val), "i"(MMU_FTR_KUAP) : "memory"); } =20 static __always_inline void uaccess_end_booke(void) { - asm(ASM_MMU_FTR_IFSET("mtspr %0, %1; isync", "", %2) : : + asm(ANNOTATE_UACCESS_END ASM_MMU_FTR_IFSET("mtspr %0, %1; isync", "", %2)= : : "i"(SPRN_PID), "r"(0), "i"(MMU_FTR_KUAP) : "memory"); } =20 diff --git a/arch/powerpc/kexec/core_32.c b/arch/powerpc/kexec/core_32.c index c95f96850c9e..6e955f32e7c3 100644 --- a/arch/powerpc/kexec/core_32.c +++ b/arch/powerpc/kexec/core_32.c @@ -17,7 +17,7 @@ typedef void (*relocate_new_kernel_t)( unsigned long indirection_page, unsigned long reboot_code_buffer, - unsigned long start_address) __noreturn; + unsigned long start_address); =20 /* * This is a generic machine_kexec function suitable at least for @@ -61,6 +61,8 @@ void default_machine_kexec(struct kimage *image) /* now call it */ rnk =3D (relocate_new_kernel_t) reboot_code_buffer; (*rnk)(page_list, reboot_code_buffer_phys, image->start); + + unreachable(); /* For objtool */ } =20 int machine_kexec_prepare(struct kimage *image) diff --git a/arch/powerpc/mm/nohash/kup.c b/arch/powerpc/mm/nohash/kup.c index c20c4f357fbf..ea1ae6cb3c3b 100644 --- a/arch/powerpc/mm/nohash/kup.c +++ b/arch/powerpc/mm/nohash/kup.c @@ -22,6 +22,8 @@ void setup_kuap(bool disabled) =20 pr_info("Activating Kernel Userspace Access Protection\n"); =20 + /* Performed a paired allow/prevent to silence objtool warning */ + allow_user_access(NULL, NULL, 0, KUAP_READ_WRITE); prevent_user_access(KUAP_READ_WRITE); } #endif diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/power= pc/decode.c index 53b55690f320..6c7244199678 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -8,6 +8,7 @@ #include #include #include +#include =20 int arch_ftrace_match(char *name) { @@ -39,28 +40,158 @@ const char *arch_ret_insn(int len) exit(-1); } =20 +/* + * Try to find the register used as base for a table jump. + * If not found return r1 which is the stack so can't be valid + * + * For relative jump tables we expect the following sequence + * lwzx rx, reg1, reg2 or lwz rx, 0(reg) + * add ry, rx, rbase or add ry, rbase, rx + * mtctr ry + * bctr + * + * For absolute jump tables we expect the following sequence + * lwzx rx, rbase, rindex + * mtctr rx + * bctr + * + * Those sequences might be nested with other code, but we expect + * it within the last 16 instructions. + */ +static unsigned int arch_decode_jumptable_base(struct objtool_file *file, + const struct section *sec, + struct instruction *jump_insn) +{ + int i; + unsigned int td =3D ~0, ta =3D ~0, tb =3D ~0; + struct instruction *insn; + + for (insn =3D jump_insn, i =3D 0; + insn && i < 16; + insn =3D prev_insn_same_sec(file, insn), i++) { + u32 ins =3D read_instruction(file, sec, insn->offset); + unsigned int ra =3D (ins >> 16) & 0x1f; + unsigned int rb =3D (ins >> 11) & 0x1f; + unsigned int rd =3D (ins >> 21) & 0x1f; + + if (td =3D=3D ~0 && ta =3D=3D ~0) { + if ((ins & 0xfc1ffffe) =3D=3D 0x7c0903a6) /* mtctr rd */ + td =3D rd; + continue; + } + /* lwzx td, ra, rb */ + if (td !=3D ~0 && (ins & 0xfc0007fe) =3D=3D 0x7c00002e && rd =3D=3D td) + return ra; + + /* lwzx ta, ra, rb or lwzx tb, ra, rb */ + if (ta !=3D ~0 && (ins & 0xfc0007fe) =3D=3D 0x7c00002e && (rd =3D=3D ta = || rd =3D=3D tb)) + return rd =3D=3D ta ? tb : ta; + + /* lwz ta, 0(ra) or lwz tb, 0(ra) */ + if (ta !=3D ~0 && (ins & 0xfc00ffff) =3D=3D 0x80000000 && (rd =3D=3D ta = || rd =3D=3D tb)) + return rd =3D=3D ta ? tb : ta; + + /* add td, ta, tb */ + if (ta =3D=3D ~0 && (ins & 0xfc0007ff) =3D=3D 0x7c000214 && rd =3D=3D td= ) { + ta =3D ra; + tb =3D rb; + td =3D ~0; + } + } + return 1; +} + int arch_decode_instruction(struct objtool_file *file, const struct sectio= n *sec, unsigned long offset, unsigned int maxlen, struct instruction *insn) { - unsigned int opcode; + unsigned int opcode, xop; + unsigned int rs, ra, rb, bo, bi, to, uimm, simm, lk, aa; enum insn_type typ; unsigned long imm; - u32 ins; + u32 ins =3D read_instruction(file, sec, offset); + + if (!ins && file->elf->ehdr.e_flags & EF_PPC_RELOCATABLE_LIB) { + struct reloc *reloc; + + reloc =3D find_reloc_by_dest_range(file->elf, insn->sec, insn->offset, 4= ); + + if (reloc && reloc_type(reloc) =3D=3D R_PPC_REL32 && + !strncmp(reloc->sym->sec->name, ".got2", 5)) { + insn->type =3D INSN_OTHER; + insn->ignore =3D true; + insn->len =3D 4; + + return 0; + } + } =20 - ins =3D bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset)); opcode =3D ins >> 26; - typ =3D INSN_OTHER; - imm =3D 0; + xop =3D (ins >> 1) & 0x3ff; + rs =3D bo =3D to =3D (ins >> 21) & 0x1f; + ra =3D bi =3D (ins >> 16) & 0x1f; + rb =3D (ins >> 11) & 0x1f; + uimm =3D simm =3D (ins >> 0) & 0xffff; + aa =3D ins & 2; + lk =3D ins & 1; =20 switch (opcode) { + case 3: + if (to =3D=3D 31 && ra =3D=3D 0 && simm =3D=3D 0) /* twi 31, r0, 0 */ + typ =3D INSN_BUG; + else + typ =3D INSN_OTHER; + break; + case 16: /* bc[l][a] */ + if (lk) /* bcl[a] */ + typ =3D INSN_OTHER; + else /* bc[a] */ + typ =3D INSN_JUMP_CONDITIONAL; + + imm =3D ins & 0xfffc; + if (imm & 0x8000) + imm -=3D 0x10000; + insn->immediate =3D imm | aa; + break; case 18: /* b[l][a] */ - if ((ins & 3) =3D=3D 1) /* bl */ + if (lk) /* bl[a] */ typ =3D INSN_CALL; + else /* b[a] */ + typ =3D INSN_JUMP_UNCONDITIONAL; =20 imm =3D ins & 0x3fffffc; if (imm & 0x2000000) imm -=3D 0x4000000; + insn->immediate =3D imm | aa; + break; + case 19: + if (xop =3D=3D 16 && bo =3D=3D 20 && bi =3D=3D 0) /* blr */ + typ =3D INSN_RETURN; + else if (xop =3D=3D 16) /* bclr */ + typ =3D INSN_RETURN_CONDITIONAL; + else if (xop =3D=3D 50) /* rfi */ + typ =3D INSN_JUMP_DYNAMIC; + else if (xop =3D=3D 528 && bo =3D=3D 20 && bi =3D=3D 0 && !lk) /* bctr */ + typ =3D INSN_JUMP_DYNAMIC; + else if (xop =3D=3D 528 && bo =3D=3D 20 && bi =3D=3D 0 && lk) /* bctrl */ + typ =3D INSN_CALL_DYNAMIC; + else + typ =3D INSN_OTHER; + break; + case 24: + if (rs =3D=3D 0 && ra =3D=3D 0 && uimm =3D=3D 0) + typ =3D INSN_NOP; + else + typ =3D INSN_OTHER; + break; + case 31: + if (xop =3D=3D 4 && to =3D=3D 31 && ra =3D=3D 0 && rb =3D=3D 0) /* trap = */ + typ =3D INSN_BUG; + else + typ =3D INSN_OTHER; + break; + default: + typ =3D INSN_OTHER; break; } =20 @@ -70,13 +201,18 @@ int arch_decode_instruction(struct objtool_file *file,= const struct section *sec insn->len =3D 4; =20 insn->type =3D typ; - insn->immediate =3D imm; + + if (typ =3D=3D INSN_JUMP_DYNAMIC) + insn->gpr =3D arch_decode_jumptable_base(file, sec, insn); =20 return 0; } =20 unsigned long arch_jump_destination(struct instruction *insn) { + if (insn->immediate & 2) + return insn->immediate & ~2; + return insn->offset + insn->immediate; } =20 diff --git a/tools/objtool/arch/powerpc/include/arch/noreturns.h b/tools/ob= jtool/arch/powerpc/include/arch/noreturns.h new file mode 100644 index 000000000000..664f17d39026 --- /dev/null +++ b/tools/objtool/arch/powerpc/include/arch/noreturns.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * This is a (sorted!) list of all known __noreturn functions in arch/powe= rpc. + * It's needed for objtool to properly reverse-engineer the control flow g= raph. + * + * Yes, this is unfortunate. A better solution is in the works. + */ +NORETURN(longjmp) +NORETURN(start_secondary_resume) +NORETURN(unrecoverable_exception) diff --git a/tools/objtool/arch/powerpc/include/arch/special.h b/tools/objt= ool/arch/powerpc/include/arch/special.h index b17802dcf436..6c3f29ef4895 100644 --- a/tools/objtool/arch/powerpc/include/arch/special.h +++ b/tools/objtool/arch/powerpc/include/arch/special.h @@ -2,6 +2,9 @@ #ifndef _PPC_ARCH_SPECIAL_H #define _PPC_ARCH_SPECIAL_H =20 +#include +#include + #define EX_ENTRY_SIZE 8 #define EX_ORIG_OFFSET 0 #define EX_NEW_OFFSET 4 @@ -18,4 +21,10 @@ #define ALT_ORIG_LEN_OFFSET 10 #define ALT_NEW_LEN_OFFSET 11 =20 +static inline u32 read_instruction(struct objtool_file *file, const struct= section *sec, + unsigned long offset) +{ + return bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset)); +} + #endif /* _PPC_ARCH_SPECIAL_H */ diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powe= rpc/special.c index 0b3a766c4842..0001ee53ff59 100644 --- a/tools/objtool/arch/powerpc/special.c +++ b/tools/objtool/arch/powerpc/special.c @@ -3,7 +3,8 @@ #include #include #include - +#include +#include =20 bool arch_support_alt_relocation(struct special_alt *special_alt, struct instruction *insn, @@ -17,5 +18,37 @@ struct reloc *arch_find_switch_table(struct objtool_file= *file, unsigned long *table_size, struct instruction *orig_insn) { - exit(-1); + struct reloc *text_reloc; + struct section *table_sec; + unsigned long table_offset; + u32 ins; + + /* look for a relocation which references .rodata */ + text_reloc =3D find_reloc_by_dest_range(file->elf, insn->sec, + insn->offset, insn->len); + if (!text_reloc || reloc_type(text_reloc) !=3D R_PPC_ADDR16_LO || + text_reloc->sym->type !=3D STT_SECTION || !text_reloc->sym->sec->roda= ta) + return NULL; + + ins =3D read_instruction(file, insn->sec, insn->offset); + if (orig_insn && ((ins >> 21) & 0x1f) !=3D orig_insn->gpr) + return NULL; + + table_offset =3D reloc_addend(text_reloc); + table_sec =3D text_reloc->sym->sec; + + /* + * Make sure the .rodata address isn't associated with a + * symbol. GCC jump tables are anonymous data. + * + * Also support C jump tables which are in the same format as + * switch jump tables. For objtool to recognize them, they + * need to be placed in the C_JUMP_TABLE_SECTION section. They + * have symbols associated with them. + */ + if (find_symbol_containing(table_sec, table_offset) && + strcmp(table_sec->name, C_JUMP_TABLE_SECTION)) + return NULL; + + return find_reloc_by_dest(file->elf, table_sec, table_offset); } diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 54625f09d831..736923b9d01f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1189,13 +1189,17 @@ static const char *uaccess_safe_builtin[] =3D { "stackleak_track_stack", /* misc */ "csum_partial_copy_generic", + "ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */ + /* misc x86 */ "copy_mc_fragile", "copy_mc_fragile_handle_tail", "copy_mc_enhanced_fast_string", - "ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */ "rep_stos_alternative", "rep_movs_alternative", "__copy_user_nocache", + /* misc powerpc */ + "__copy_tofrom_user", + "__arch_clear_user", NULL }; =20 --=20 2.47.0