From nobody Tue Dec 16 12:42:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1843E298CBE; Fri, 9 May 2025 20:18:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746821896; cv=none; b=ZN1egAaihfyLsc3zioLx8wlJ/15zm9KsXAREGXX2L6U4ftK2uIhdIExcxGtoSe++ZpWlnZjDnxMyPuPIIFby2yxKVCTHjSXKiws07gHfk7CmEPDsGJ/cYMfOxmLEzlUSiCBp8FAx+duuv41eV4e2x2AHCCge+kDfhksdTV09tbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746821896; c=relaxed/simple; bh=WrGEyNHSSw7Wx3DQ3criX7+p62Pve6p0318/Ksge9cQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jzKGUPZDP94oTjbzP97cYt18MyQJZiJQuHjFhFG1Fayr+N1yFj5PVLsA8koHe2hQtR6AbSgu7LPU3R7XDQWmpDgargSj3EHuOGKN1WJ8IyV8J6DOpuqHzacGElFteKbGBluRJMhhqbBHqnfhqpyO0DjKGZRdAPmu3YOQaNf7HFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tx+VTOuN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tx+VTOuN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F3EFC4CEEF; Fri, 9 May 2025 20:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746821896; bh=WrGEyNHSSw7Wx3DQ3criX7+p62Pve6p0318/Ksge9cQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tx+VTOuNeOAdNveLRr8D1TBDpGlVVTpewtqyC5XNZaf65xWLv9JRKOVIQrQwl2BnS kZt7OsU+avOREH80V0YaZFvgP5suwYeruN5UtG9oJDRzTWEtpeBkSExPmirmza81yt KQMQSpYcIGLggP0DOAOTyuMltPXcUI0Vu7jih6D3C1LFafvON+dMy5TPGoN9i+iI1q 4f9yS1wCDLWqv14zB/2+ZEpNgm0wZa8VUbZMNCY3AugEX2L7TK8pnOvUYWKVAjR/PK 01rbpGbAcJpuzJblDPaQZjNE27p7ZTIxwYOZC6APKV7hAqqS20VhYAYRXSk1oFtgjG 941II6UNRIcSQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Petr Mladek , Miroslav Benes , Joe Lawrence , live-patching@vger.kernel.org, Song Liu , laokz , Jiri Kosina , Marcos Paulo de Souza , Weinan Liu , Fazla Mehrab , Chen Zhongjin , Puranjay Mohan Subject: [PATCH v2 44/62] x86/jump_label: Define ELF section entry size for jump table Date: Fri, 9 May 2025 13:17:08 -0700 Message-ID: X-Mailer: git-send-email 2.49.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for the objtool klp diff subcommand, define the entry size for the __jump_table section in its ELF header. This will allow tooling to extract individual entries. Signed-off-by: Josh Poimboeuf --- arch/x86/include/asm/jump_label.h | 32 +++++++++++++++++-------------- include/linux/jump_label.h | 20 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_= label.h index cd21554b3675..6081c33e1566 100644 --- a/arch/x86/include/asm/jump_label.h +++ b/arch/x86/include/asm/jump_label.h @@ -12,29 +12,31 @@ #include #include =20 -#define JUMP_TABLE_ENTRY(key, label) \ - ".pushsection __jump_table, \"a\"\n\t" \ - _ASM_ALIGN "\n\t" \ - ".long 1b - . \n\t" \ - ".long " label " - . \n\t" \ - _ASM_PTR " " key " - . \n\t" \ +#define JUMP_TABLE_ENTRY(key, label, size) \ + ".pushsection __jump_table, \"aM\", @progbits, " size "\n\t" \ + _ASM_ALIGN "\n\t" \ + ".long 1b - . \n\t" \ + ".long " label " - . \n\t" \ + _ASM_PTR " " key " - . \n\t" \ ".popsection \n\t" =20 /* This macro is also expanded on the Rust side. */ #ifdef CONFIG_HAVE_JUMP_LABEL_HACK -#define ARCH_STATIC_BRANCH_ASM(key, label) \ +#define ARCH_STATIC_BRANCH_ASM(key, label, size) \ "1: jmp " label " # objtool NOPs this \n\t" \ - JUMP_TABLE_ENTRY(key " + 2", label) + JUMP_TABLE_ENTRY(key " + 2", label, size) #else /* !CONFIG_HAVE_JUMP_LABEL_HACK */ -#define ARCH_STATIC_BRANCH_ASM(key, label) \ +#define ARCH_STATIC_BRANCH_ASM(key, label, size) \ "1: .byte " __stringify(BYTES_NOP5) "\n\t" \ - JUMP_TABLE_ENTRY(key, label) + JUMP_TABLE_ENTRY(key, label, size) #endif /* CONFIG_HAVE_JUMP_LABEL_HACK */ =20 static __always_inline bool arch_static_branch(struct static_key * const k= ey, const bool branch) { - asm goto(ARCH_STATIC_BRANCH_ASM("%c0 + %c1", "%l[l_yes]") - : : "i" (key), "i" (branch) : : l_yes); + asm goto(ARCH_STATIC_BRANCH_ASM("%c[key] + %c[branch]", "%l[l_yes]", "%c[= size]") + : : [key] "i" (key), [branch] "i" (branch), + [size] "i" (sizeof(struct jump_entry)) + : : l_yes); =20 return false; l_yes: @@ -45,8 +47,10 @@ static __always_inline bool arch_static_branch_jump(stru= ct static_key * const ke { asm goto("1:" "jmp %l[l_yes]\n\t" - JUMP_TABLE_ENTRY("%c0 + %c1", "%l[l_yes]") - : : "i" (key), "i" (branch) : : l_yes); + JUMP_TABLE_ENTRY("%c[key] + %c[branch]", "%l[l_yes]", "%c[size]") + : : [key] "i" (key), [branch] "i" (branch), + [size] "i" (sizeof(struct jump_entry)) + : : l_yes); =20 return false; l_yes: diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h index fdb79dd1ebd8..9ff1ecc8e7a8 100644 --- a/include/linux/jump_label.h +++ b/include/linux/jump_label.h @@ -110,16 +110,20 @@ struct static_key { #endif /* __ASSEMBLY__ */ =20 #ifdef CONFIG_JUMP_LABEL -#include - -#ifndef __ASSEMBLY__ -#ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE =20 +#if defined(CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE) && !defined(__ASSEMBLY__) +/* Must be defined before including */ struct jump_entry { s32 code; s32 target; long key; // key may be far away from the core kernel under KASLR }; +#endif + +#include + +#ifndef __ASSEMBLY__ +#ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE =20 static inline unsigned long jump_entry_code(const struct jump_entry *entry) { @@ -138,7 +142,7 @@ static inline struct static_key *jump_entry_key(const s= truct jump_entry *entry) return (struct static_key *)((unsigned long)&entry->key + offset); } =20 -#else +#else /* !CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE */ =20 static inline unsigned long jump_entry_code(const struct jump_entry *entry) { @@ -155,7 +159,7 @@ static inline struct static_key *jump_entry_key(const s= truct jump_entry *entry) return (struct static_key *)((unsigned long)entry->key & ~3UL); } =20 -#endif +#endif /* !CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE */ =20 static inline bool jump_entry_is_branch(const struct jump_entry *entry) { @@ -184,8 +188,8 @@ static inline int jump_entry_size(struct jump_entry *en= try) #endif } =20 -#endif -#endif +#endif /* !__ASSEMBLY__ */ +#endif /* CONFIG_JUMP_LABEL */ =20 #ifndef __ASSEMBLY__ =20 --=20 2.49.0