From: George Guo <dongtai.guo@linux.dev>
To: chenhuacai@kernel.org, jpoimboe@kernel.org, peterz@infradead.org,
jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com
Cc: kernel@xen0n.name, joe.lawrence@redhat.com, rostedt@goodmis.org,
ardb@kernel.org, nathan@kernel.org,
nick.desaulniers+lkml@gmail.com, yangtiezhu@loongson.cn,
jiaxun.yang@flygoat.com, xry111@xry111.site, liukexin@kylinos.cn,
loongarch@lists.linux.dev, live-patching@vger.kernel.org,
llvm@lists.linux.dev, linux-kernel@vger.kernel.org,
George Guo <guodongtai@kylinos.cn>
Subject: [PATCH 3/8] LoongArch: Add special section entry sizes for KLP support
Date: Thu, 4 Jun 2026 14:53:12 +0800 [thread overview]
Message-ID: <20260604065317.219777-4-dongtai.guo@linux.dev> (raw)
In-Reply-To: <20260604065317.219777-1-dongtai.guo@linux.dev>
From: George Guo <guodongtai@kylinos.cn>
Define entry sizes for .altinstructions, __ex_table, __bug_table, and
__jump_table sections to enable objtool to process livepatch modules
on LoongArch.
Co-developed-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: George Guo <guodongtai@kylinos.cn>
---
arch/loongarch/include/asm/alternative-asm.h | 5 +--
arch/loongarch/include/asm/alternative.h | 6 ++--
arch/loongarch/include/asm/asm-extable.h | 10 ++++--
arch/loongarch/include/asm/bug.h | 15 +++++++-
arch/loongarch/include/asm/jump_label.h | 9 ++++-
arch/loongarch/kernel/asm-offsets.c | 36 ++++++++++++++++++++
arch/loongarch/kernel/head.S | 1 +
7 files changed, 74 insertions(+), 8 deletions(-)
diff --git a/arch/loongarch/include/asm/alternative-asm.h b/arch/loongarch/include/asm/alternative-asm.h
index 7dc29bd9b2f0..d940d9d2c0e1 100644
--- a/arch/loongarch/include/asm/alternative-asm.h
+++ b/arch/loongarch/include/asm/alternative-asm.h
@@ -5,6 +5,7 @@
#ifdef __ASSEMBLER__
#include <asm/asm.h>
+#include <generated/asm-offsets.h>
/*
* Issue one struct alt_instr descriptor entry (need to put it into
@@ -33,7 +34,7 @@
.fill - (((144f-143f)-(141b-140b)) > 0) * ((144f-143f)-(141b-140b)) / 4, 4, 0x03400000
142 :
- .pushsection .altinstructions, "a"
+ .pushsection .altinstructions, "aM", @progbits, ALT_INSTR_SIZE
altinstruction_entry 140b, 143f, \feature, 142b-140b, 144f-143f
.popsection
@@ -63,7 +64,7 @@
(alt_max_short(new_len1, new_len2) - (old_len)) / 4, 4, 0x03400000
142 :
- .pushsection .altinstructions, "a"
+ .pushsection .altinstructions, "aM", @progbits, ALT_INSTR_SIZE
altinstruction_entry 140b, 143f, \feature1, 142b-140b, 144f-143f, 142b-141b
altinstruction_entry 140b, 144f, \feature2, 142b-140b, 145f-144f, 142b-141b
.popsection
diff --git a/arch/loongarch/include/asm/alternative.h b/arch/loongarch/include/asm/alternative.h
index b5bae21fb3c8..8f7712ed2f4e 100644
--- a/arch/loongarch/include/asm/alternative.h
+++ b/arch/loongarch/include/asm/alternative.h
@@ -70,7 +70,8 @@ extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
/* alternative assembly primitive: */
#define ALTERNATIVE(oldinstr, newinstr, feature) \
OLDINSTR(oldinstr, 1) \
- ".pushsection .altinstructions,\"a\"\n" \
+ ".pushsection .altinstructions, \"aM\", @progbits, " \
+ __stringify(ALT_INSTR_SIZE) "\n" \
ALTINSTR_ENTRY(feature, 1) \
".popsection\n" \
".subsection 1\n" \
@@ -79,7 +80,8 @@ extern void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
#define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2)\
OLDINSTR_2(oldinstr, 1, 2) \
- ".pushsection .altinstructions,\"a\"\n" \
+ ".pushsection .altinstructions, \"aM\", @progbits, " \
+ __stringify(ALT_INSTR_SIZE) "\n" \
ALTINSTR_ENTRY(feature1, 1) \
ALTINSTR_ENTRY(feature2, 2) \
".popsection\n" \
diff --git a/arch/loongarch/include/asm/asm-extable.h b/arch/loongarch/include/asm/asm-extable.h
index d60bdf2e6377..2d7eef7c0b39 100644
--- a/arch/loongarch/include/asm/asm-extable.h
+++ b/arch/loongarch/include/asm/asm-extable.h
@@ -7,10 +7,15 @@
#define EX_TYPE_UACCESS_ERR_ZERO 2
#define EX_TYPE_BPF 3
+#ifndef COMPILE_OFFSETS
+#include <asm/asm-offsets.h>
+#endif
+
#ifdef __ASSEMBLER__
#define __ASM_EXTABLE_RAW(insn, fixup, type, data) \
- .pushsection __ex_table, "a"; \
+ .pushsection __ex_table, "aM", @progbits, \
+ EXTABLE_SIZE; \
.balign 4; \
.long ((insn) - .); \
.long ((fixup) - .); \
@@ -29,7 +34,8 @@
#include <asm/gpr-num.h>
#define __ASM_EXTABLE_RAW(insn, fixup, type, data) \
- ".pushsection __ex_table, \"a\"\n" \
+ ".pushsection __ex_table, \"aM\", @progbits, "\
+ __stringify(EXTABLE_SIZE) "\n" \
".balign 4\n" \
".long ((" insn ") - .)\n" \
".long ((" fixup ") - .)\n" \
diff --git a/arch/loongarch/include/asm/bug.h b/arch/loongarch/include/asm/bug.h
index d090a5bec5eb..c067c858b918 100644
--- a/arch/loongarch/include/asm/bug.h
+++ b/arch/loongarch/include/asm/bug.h
@@ -22,8 +22,20 @@
#ifndef CONFIG_GENERIC_BUG
#define __BUG_ENTRY(cond_str, flags)
#else
+
+#ifdef COMPILE_OFFSETS
+#define __BUG_ENTRY(cond_str, flags) \
+ .pushsection __bug_table, "awM", @progbits, 0; \
+ .align 2; \
+ 10000: .long 10001f - .; \
+ _BUGVERBOSE_LOCATION(WARN_CONDITION_STR(cond_str) __FILE__, __LINE__) \
+ .short flags; \
+ .popsection; \
+ 10001:
+#else
+#include <generated/asm-offsets.h>
#define __BUG_ENTRY(cond_str, flags) \
- .pushsection __bug_table, "aw"; \
+ .pushsection __bug_table, "awM", @progbits, BUG_ENTRY_SIZE; \
.align 2; \
10000: .long 10001f - .; \
_BUGVERBOSE_LOCATION(WARN_CONDITION_STR(cond_str) __FILE__, __LINE__) \
@@ -31,6 +43,7 @@
.popsection; \
10001:
#endif
+#endif
#define ASM_BUG_FLAGS(cond_str, flags) \
__BUG_ENTRY(cond_str, flags) \
diff --git a/arch/loongarch/include/asm/jump_label.h b/arch/loongarch/include/asm/jump_label.h
index 7ef4ae3abf08..26ae644755ea 100644
--- a/arch/loongarch/include/asm/jump_label.h
+++ b/arch/loongarch/include/asm/jump_label.h
@@ -23,9 +23,16 @@
#define JUMP_LABEL_TYPE ".quad "
#endif
+#ifdef COMPILE_OFFSETS
+#define JUMP_ENTRY_SIZE 0
+#else
+#include <generated/asm-offsets.h>
+#endif
+
/* This macro is also expanded on the Rust side. */
#define JUMP_TABLE_ENTRY(key, label) \
- ".pushsection __jump_table, \"aw\" \n\t" \
+ ".pushsection __jump_table, \"awM\", @progbits, " \
+ __stringify(JUMP_ENTRY_SIZE) "\n\t" \
".align " __stringify(PTRLOG) " \n\t" \
".long 1b - ., " label " - . \n\t" \
JUMP_LABEL_TYPE key " - . \n\t" \
diff --git a/arch/loongarch/kernel/asm-offsets.c b/arch/loongarch/kernel/asm-offsets.c
index 2cc953f113ac..42f16e5da06d 100644
--- a/arch/loongarch/kernel/asm-offsets.c
+++ b/arch/loongarch/kernel/asm-offsets.c
@@ -18,6 +18,10 @@
#include <asm/ftrace.h>
#include <asm/sigframe.h>
#include <vdso/datapage.h>
+#include <asm/alternative.h>
+#include <asm/extable.h>
+#include <asm/bug.h>
+#include <asm/jump_label.h>
static void __used output_ptreg_defines(void)
{
@@ -323,3 +327,35 @@ static void __used output_vdso_defines(void)
DEFINE(__VDSO_PAGES, VDSO_NR_PAGES);
BLANK();
}
+
+static void __used output_extable_defines(void)
+{
+ COMMENT("LoongArch exception table entry offsets.");
+
+ DEFINE(EXTABLE_SIZE, sizeof(struct exception_table_entry));
+ BLANK();
+}
+
+static void __used output_alt_instr_defines(void)
+{
+ COMMENT("LoongArch alternative instructions offsets.");
+
+ DEFINE(ALT_INSTR_SIZE, sizeof(struct alt_instr));
+ BLANK();
+}
+
+static void __used output_bug_defines(void)
+{
+ COMMENT("LoongArch bug entry offsets.");
+
+ DEFINE(BUG_ENTRY_SIZE, sizeof(struct bug_entry));
+ BLANK();
+}
+
+static void __used output_jump_label_defines(void)
+{
+ COMMENT("LoongArch jump entry offsets.");
+
+ DEFINE(JUMP_ENTRY_SIZE, sizeof(struct jump_entry));
+ BLANK();
+}
diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S
index 4eed7bc312a8..a8a2a98e0a5c 100644
--- a/arch/loongarch/kernel/head.S
+++ b/arch/loongarch/kernel/head.S
@@ -12,6 +12,7 @@
#include <asm/regdef.h>
#include <asm/loongarch.h>
#include <asm/stackframe.h>
+#include <generated/asm-offsets.h>
#ifdef CONFIG_EFI_STUB
--
2.25.1
next prev parent reply other threads:[~2026-06-04 6:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 6:53 [PATCH 0/8] LoongArch: Add livepatch build (KLP) support George Guo
2026-06-04 6:53 ` [PATCH 1/8] " George Guo
2026-06-04 6:53 ` [PATCH 2/8] objtool/LoongArch: Add arch_adjusted_addend() for KLP support George Guo
2026-06-04 6:53 ` George Guo [this message]
2026-06-05 8:38 ` [PATCH 3/8] LoongArch: Add special section entry sizes " WangYuli
2026-06-08 10:33 ` George Guo
2026-06-04 6:53 ` [PATCH 4/8] livepatch/klp-build: disable direct-extern-access for LoongArch to fix kernel panic George Guo
2026-06-05 8:53 ` WangYuli
2026-06-04 6:53 ` [PATCH 5/8] LoongArch: fix kernel panic with -fPIC for same-compilation-unit symbol references George Guo
2026-06-05 8:10 ` Xi Ruoyao
2026-06-08 10:23 ` George Guo
2026-06-04 6:53 ` [PATCH 6/8] LoongArch: Fix EFI linking with -fdata-sections George Guo
2026-06-04 6:53 ` [PATCH 7/8] objtool/klp: Add LoongArch jump opcode bytes support George Guo
2026-06-04 6:53 ` [PATCH 8/8] klp-build: Add LoongArch syscall patching macro George Guo
2026-06-05 7:57 ` [PATCH 0/8] LoongArch: Add livepatch build (KLP) support WangYuli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260604065317.219777-4-dongtai.guo@linux.dev \
--to=dongtai.guo@linux.dev \
--cc=ardb@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=guodongtai@kylinos.cn \
--cc=jiaxun.yang@flygoat.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=liukexin@kylinos.cn \
--cc=live-patching@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=loongarch@lists.linux.dev \
--cc=mbenes@suse.cz \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=xry111@xry111.site \
--cc=yangtiezhu@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox