From nobody Mon Jun 8 10:56:50 2026 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (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 DFBCA3DC84E for ; Thu, 4 Jun 2026 06:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556074; cv=none; b=ai/l5Yx3lhAP8FUg4zx9jEIQMMMJCN8FV7Ne3RL66bcaaugQSh/KjOiMrYoyCM6PCycvhPro7QyJ7xuf/1+C0edyDu7yMP7c4TytX4rLeznihwG8RA3WJTICmN49erb391C06ujVWAiN/VPNCPYHg8u7vY8y+oYtgeBoldQNC1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556074; c=relaxed/simple; bh=CEIAnlvL0rhnO6ZzKUdVEs7J/+earQCHbO4otn4jgzY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b8MWkp/ZyM9V1Iybfa2123LK3d3e9DSE4Lm4PrL46+F1Acbgd8W0wzff6eNLu1GgTa+dEvd4VVuweeP9jONm02tjlC5YVDhNeDtf3KxFreT0juwPCgTAadey9SfY+gjcdIE4hR/cxTd5iTFHVVUvWohLtXZaLqBpBCEqtKqjofE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=i0TTT6EX; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="i0TTT6EX" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780556070; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BZal1eUFT5zCvAjnUL3zj5MffVR6wFyaxSxRBYF+dwo=; b=i0TTT6EXqtPFUHsFVCn/SBtfpu0yFK3pTonWomD5VpGQSe8iUE8ITtZJkePGIHI8w3YgCh O+I2moKQ1Ma9gBTfgpLg1jMZj0LFm/AOGLY+dNi6et8p2zC0dDZSzcEpAN+4amxlghO1I9 SRezudzNIz6C3Cu85aPphlOVWAgHUDU= From: George Guo 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 Subject: [PATCH 1/8] LoongArch: Add livepatch build (KLP) support Date: Thu, 4 Jun 2026 14:53:10 +0800 Message-Id: <20260604065317.219777-2-dongtai.guo@linux.dev> In-Reply-To: <20260604065317.219777-1-dongtai.guo@linux.dev> References: <20260604065317.219777-1-dongtai.guo@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: George Guo This allows automated livepatch module generation using objtool. Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- arch/loongarch/Kconfig | 1 + tools/objtool/Makefile | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 3b042dbb2c41..1dbf51ba9d6a 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -159,6 +159,7 @@ config LOONGARCH select HAVE_IOREMAP_PROT select HAVE_IRQ_EXIT_ON_IRQ_STACK select HAVE_IRQ_TIME_ACCOUNTING + select HAVE_KLP_BUILD select HAVE_KPROBES select HAVE_KPROBES_ON_FTRACE select HAVE_KRETPROBES diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 94aabeee9736..83d645675ed9 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -8,7 +8,8 @@ ifeq ($(SRCARCH),x86) endif =20 ifeq ($(SRCARCH),loongarch) - BUILD_ORC :=3D y + BUILD_ORC :=3D y + ARCH_HAS_KLP :=3D y endif =20 ifeq ($(SRCARCH),arm64) --=20 2.25.1 From nobody Mon Jun 8 10:56:50 2026 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 949A93DB623 for ; Thu, 4 Jun 2026 06:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556111; cv=none; b=SMO5buOe69EnnnuMg6ZbY2fwPMkCmTiypmZO2BwAtl9NskxxEHNIWGoQnQLQyIGJOUdNqKXH19JWRlgleVa/nlst/1Uc6Lp9iS4/dMo2KdYeGfOs8TmKKVH+myiXgIsResF0X41eEzOR8iaSNGb8c196Rt7r4rEj+6lslVWpaDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556111; c=relaxed/simple; bh=oLaUr+FB9VSsAuBRiSWaPzIJPJ7H5RqIcSuL90V25FQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FAiUXfLI/J+5ptwVOafJ5nED+Agn2IfeRjcAXZBld/MmVt1+9q2yuDGveF6ZEnwTFCn5j/lFI5pjbiypuxFAmQ/+YMdXdwmczvAGiRYbrEdNcAHsApwDP33asP/wAE9xXl2SaIvuJBTI/FCYWFir5AOzBbShYXHVqinDE2KHs28= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tdnOfxvD; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tdnOfxvD" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780556106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=svJYdefjY/nnU0nlx6aQgjbpTVvVYZOsKKX0wUiaSj0=; b=tdnOfxvDgxTn6fQkXk2LW/QfycMkY+owjw4QTRPOcWLfnrvl3pox0zq+UNndIX99OR/tj8 Acw4eyINDBioJiju8gexjls2B0K2kgKKuZYEuhMT4AlkdB/+Gpa38tJPi2gA7syUN0WVnw BbAgK2RyqU8WkrIP7+DmoYoBj/Pk+Zs= From: George Guo 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 Subject: [PATCH 2/8] objtool/LoongArch: Add arch_adjusted_addend() for KLP support Date: Thu, 4 Jun 2026 14:53:11 +0800 Message-Id: <20260604065317.219777-3-dongtai.guo@linux.dev> In-Reply-To: <20260604065317.219777-1-dongtai.guo@linux.dev> References: <20260604065317.219777-1-dongtai.guo@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: George Guo Implement arch_adjusted_addend() to return the relocation addend value. Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- tools/objtool/arch/loongarch/decode.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 6cd288150f49..674e4efd138f 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -34,6 +34,11 @@ s64 arch_insn_adjusted_addend(struct instruction *insn, = struct reloc *reloc) return reloc_addend(reloc); } =20 +u64 arch_adjusted_addend(struct reloc *reloc) +{ + return reloc_addend(reloc); +} + bool arch_pc_relative_reloc(struct reloc *reloc) { return false; --=20 2.25.1 From nobody Mon Jun 8 10:56:50 2026 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 508C53DBD77 for ; Thu, 4 Jun 2026 06:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556135; cv=none; b=E50TXf1Jd1dqUP9Qg57frBFu2OCRf+GgXo6rvLdtQxtq9UJbPEWBiqCNuErgh5dDxmoKgy4ZmVTQJ8SOBKEigmUUqBJXUT39hP3dNj6OAwp904esURu1HrbHZ1BSwq9Btbp35sClkvp2iU3xcl5nFQwg9Xme4Qt0Oucn6uKxrj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556135; c=relaxed/simple; bh=ozODrf/YskxLh7GSBLFEFLirMysqauyIzAVNs8EwW8I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VyHvEHbIoEIzOg/oyeWRL9Z84/EEbJ1ARG/iBoBBVHoJz/N6Nyi8N+JXyHMmM2PAbFS4Yk/SXhrfhdjRHT8tNMU+fq3Faxd4v5IIyL/8fpc5enzM5ygNtTnYBLLL/UYGrrvuUuWP3yAWfPalnvatrcl2arxIjnO5pJwA2nXcbiE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cZ9pXfqE; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cZ9pXfqE" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780556128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y1V5SfkWutaG7THsFK665QVbmO8aunuz7f9TfyLp1sw=; b=cZ9pXfqE4JYoDJLEIGugeeA/Eh1KhhaZQIvYH66+snmuHRc34iQRj0oKsVuymiZoAPbR2M HSj5JBY709iBVA8lftRq4Tl3rOfbO/uDsTEVC9D5TPi3LF4D0dcewIuUN4lGLh4VgV5oKb kP3f4zHJMRNp0ktwM6GVrUGFjjQjtV4= From: George Guo 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 Subject: [PATCH 3/8] LoongArch: Add special section entry sizes for KLP support Date: Thu, 4 Jun 2026 14:53:12 +0800 Message-Id: <20260604065317.219777-4-dongtai.guo@linux.dev> In-Reply-To: <20260604065317.219777-1-dongtai.guo@linux.dev> References: <20260604065317.219777-1-dongtai.guo@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: George Guo 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 Signed-off-by: Kexin Liu Signed-off-by: George Guo --- 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__ =20 #include +#include =20 /* * 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 : =20 - .pushsection .altinstructions, "a" + .pushsection .altinstructions, "aM", @progbits, ALT_INSTR_SIZE altinstruction_entry 140b, 143f, \feature, 142b-140b, 144f-143f .popsection =20 @@ -63,7 +64,7 @@ (alt_max_short(new_len1, new_len2) - (old_len)) / 4, 4, 0x03400000 142 : =20 - .pushsection .altinstructions, "a" + .pushsection .altinstructions, "aM", @progbits, ALT_INSTR_SIZE altinstruction_entry 140b, 143f, \feature1, 142b-140b, 144f-143f, 142b-14= 1b altinstruction_entry 140b, 144f, \feature2, 142b-140b, 145f-144f, 142b-14= 1b .popsection diff --git a/arch/loongarch/include/asm/alternative.h b/arch/loongarch/incl= ude/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, s= truct 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, s= truct alt_instr *end); =20 #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/incl= ude/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 =20 +#ifndef COMPILE_OFFSETS +#include +#endif + #ifdef __ASSEMBLER__ =20 #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 =20 #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 #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 =20 #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/inclu= de/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 =20 +#ifdef COMPILE_OFFSETS +#define JUMP_ENTRY_SIZE 0 +#else +#include +#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/as= m-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 #include #include +#include +#include +#include +#include =20 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 #include #include +#include =20 #ifdef CONFIG_EFI_STUB =20 --=20 2.25.1 From nobody Mon Jun 8 10:56:50 2026 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (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 2D35D385D63 for ; Thu, 4 Jun 2026 06:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556163; cv=none; b=Lrk4J9HC1dP5VKvYJgeGWDbOcTest8moXi9r2yTIHoCrGdVXio2Xmm7h68g5JGVJGgatIoqiDx/YsbyK2Lr/KvGEdbeqtSlQPX3TG0CxZBCORtaoAEdcVIcSP6qyQfTrU2DYVmNuKGXZostt0/YVHXFmY50Z8lxmRNH9tWudltI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556163; c=relaxed/simple; bh=u1iDBVc2w/8vztJQrTnvoSQW8h/eE2UgCzY5Oc9d34c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TEWXRuvHFZwQ9pOj1EJLndZpr4FnmRKbZAk/f/b2Of/KssGMYVJx91a9yMjEEgX0Xcz9qVCwhkUuX9JxmJrn330gAXvMq//IcFvq6f3wRJPj4oWJ+9Y/+rn5icX7dF7IFtUqVQ4AeyzTIOXXlerjFwi0fHQCpUR0wenvoL9ZcxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ctkvIpS3; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ctkvIpS3" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780556160; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=npSVQzrI/XnrvzPC4XtktJ2Mr3iT0r1KkLt6HOzTG1o=; b=ctkvIpS3BVWrT2AHdJySXGoxvdLf5e+qSEylduVmVDE5YJVLosqtUhWc6Zxgnnk7UkTPUF 8Dloeogh/Ndt9gCDE3jDdRBhyZhZYLCHBa7AgtDY2eJbJ5FnTp4p20Zdyaethg6Ec+hNQw eDhSTVK0I6ViWR26M62X0g33Q04tLqU= From: George Guo 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 Subject: [PATCH 4/8] livepatch/klp-build: disable direct-extern-access for LoongArch to fix kernel panic Date: Thu, 4 Jun 2026 14:53:13 +0800 Message-Id: <20260604065317.219777-5-dongtai.guo@linux.dev> In-Reply-To: <20260604065317.219777-1-dongtai.guo@linux.dev> References: <20260604065317.219777-1-dongtai.guo@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: George Guo On LoongArch systems, livepatch modules containing references to EXTERNAL global variables trigger kernel panics when the core kernel is built with the -mdirect-extern-access optimization. Root cause: The -mdirect-extern-access optimization replaces GOT-based external symbol access with direct addressing for improved performance. However, this breaks the kernel module loading mechanism, which relies on GOT entries for proper relocation of EXTERNAL symbol references. Direct access to global variables from livepatch modules causes invalid memory accesses and kernel panics. Solution: For LoongArch klp builds, conditionally disable direct-extern-access by adding: - -mno-direct-extern-access for GCC builds - -fno-direct-access-external-data for Clang builds See also commit 38b10b269d04 ("LoongArch: Tweak CFLAGS for Clang compatibility"), which added -mdirect-extern-access to the kernel as a nice-to-have optimization that reduces GOT accesses. Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- scripts/livepatch/klp-build | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index e83973567c87..529437d75346 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -542,6 +542,17 @@ fix_patches() { =20 clean_kernel() { local cmd=3D() + local ARCH_KBUILD_CFLAGS_KERNEL=3D"" + + if [[ -v CONFIG_LOONGARCH && "$CONFIG_LOONGARCH" =3D=3D "y" ]]; then + if [[ -n "$CONFIG_CC_IS_CLANG" ]]; then + ARCH_KBUILD_CFLAGS_KERNEL=3D"-fno-direct-access-external-data" + else + ARCH_KBUILD_CFLAGS_KERNEL=3D"-mno-direct-extern-access" + fi + + status "LoongArch detected: adding $ARCH_KBUILD_CFLAGS_KERNEL to KBUILD_= CFLAGS_KERNEL" + fi =20 cmd=3D("make") cmd+=3D("--silent") @@ -582,6 +593,7 @@ build_kernel() { fi cmd+=3D("-j$JOBS") cmd+=3D("KCFLAGS=3D-ffunction-sections -fdata-sections") + cmd+=3D("KBUILD_CFLAGS_KERNEL=3D$ARCH_KBUILD_CFLAGS_KERNEL") cmd+=3D("vmlinux") cmd+=3D("modules") =20 --=20 2.25.1 From nobody Mon Jun 8 10:56:50 2026 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 583283DA7FD for ; Thu, 4 Jun 2026 06:56:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556182; cv=none; b=tolcGPhcRZVWSLRqOD80JRiBtde+yCZzjYx3DyC/lYsBNXPgZk7KMc9NHZhAp9fm8FwcGyB+1D4CslXTlCHumTlo8NHAq2+g/IqDhy5sEkREOKAu2ND9x1cjGzcJKAtQqJY9BvwEEqkvUG9kifxs3wueAnvl2x9ksVrnpwk+oIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556182; c=relaxed/simple; bh=XpoFR3JPzQXTMZQiHIvD3lfABbsedj0sRsdZarmYqIE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=imRt7QrouuiapaeOKaQ7JVnLizW1vAgAN08Rre3mCexARz+DkFHmHHiByiGHuRa3wsrzHNLEiJCth/amwRLhNn8dR5JPBdm1yuI0+5gYnrI9ffzd5gBVN3HrJsExCFvQgajb1tV0dFanxH9IGhHdhW9Dg+3YfopUHw9EAuLeaNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=EWZwYByV; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="EWZwYByV" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780556177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lUaBjWh3I/w17j3E4iJEmAnEhQBvyWwQtpl5kUTTn+8=; b=EWZwYByVU7d16ZXu2gAI/jM9FAlDGr3F/INboyuc+u0Op7en0cyq+T5idhjqO78SGl50Nb x6gc7Ecu0Y+55pqC+xs+h+UwggWMehp/Y01ok+yqr1atQp0l2Vt1lLULezqLRClxu226qA k8NW0zV0JPNkIhQlJjEwZ6imlYOPyI8= From: George Guo 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 Subject: [PATCH 5/8] LoongArch: fix kernel panic with -fPIC for same-compilation-unit symbol references Date: Thu, 4 Jun 2026 14:53:14 +0800 Message-Id: <20260604065317.219777-6-dongtai.guo@linux.dev> In-Reply-To: <20260604065317.219777-1-dongtai.guo@linux.dev> References: <20260604065317.219777-1-dongtai.guo@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: George Guo Add architecture-specific -fPIC compiler flag for LoongArch64 to prevent kernel panics when applying livepatches containing references to symbols defined in the same compilation unit. Root cause: In the KLP workflow, when a function is livepatched, it's extracted from the original object file and compiled into a separate kernel module. When the patched function references symbols defined in the same compilation unit (like 'uts_sem' in kernel/sys.c), these references break if not compiled as position-independent code. On LoongArch64, without -fPIC, references to same-compilation-unit symbols use absolute addressing that assumes fixed memory locations. When the function is relocated into the livepatch module, these absolute addresses become invalid, causing kernel panics. Example failure case: - SYSCALL_DEFINE1(newuname) references the same-compilation-unit symbol 'uts_sem' - When kpatch extracts this function into a module, the reference to 'uts_sem' must be properly relocated - Without -fPIC, the absolute address reference causes invalid memory access and kernel panic Solution: Force -fPIC compilation for all LoongArch64 KLP builds. This ensures that references to same-compilation-unit symbols use position-independent addressing, allowing proper relocation by the kernel module loader and preventing kernel panics in livepatch scenarios. Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- scripts/livepatch/klp-build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 529437d75346..83a43e0df3b9 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -543,8 +543,10 @@ fix_patches() { clean_kernel() { local cmd=3D() local ARCH_KBUILD_CFLAGS_KERNEL=3D"" + local ARCH_KCFLAGS=3D"" =20 if [[ -v CONFIG_LOONGARCH && "$CONFIG_LOONGARCH" =3D=3D "y" ]]; then + ARCH_KCFLAGS=3D"-fPIC" if [[ -n "$CONFIG_CC_IS_CLANG" ]]; then ARCH_KBUILD_CFLAGS_KERNEL=3D"-fno-direct-access-external-data" else @@ -592,7 +594,7 @@ build_kernel() { cmd+=3D("-s") fi cmd+=3D("-j$JOBS") - cmd+=3D("KCFLAGS=3D-ffunction-sections -fdata-sections") + cmd+=3D("KCFLAGS=3D-ffunction-sections -fdata-sections $ARCH_KCFLAGS") cmd+=3D("KBUILD_CFLAGS_KERNEL=3D$ARCH_KBUILD_CFLAGS_KERNEL") cmd+=3D("vmlinux") cmd+=3D("modules") --=20 2.25.1 From nobody Mon Jun 8 10:56:50 2026 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 371143DDDA0 for ; Thu, 4 Jun 2026 06:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556187; cv=none; b=pgtJs9fZEGIgTdyGhO+KjhpB9tMBFA/IF9OLo8DYyTCSC4+N3TEh3hV4Ki5AkoPiNduFDv67blkx+RlZGATmUL8vDKHzLKuCZceeZkSK2/fK161ZcCZpRSlsH86vWrMeAKJBsr0Op2koJ56FH0ZZBddcsr2e1kMh3e2Rpki98rM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556187; c=relaxed/simple; bh=OvI7222dt3pd1EshIbEJENw5/OnwTK2o+TJyWMgUtYI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wn6D/XpbKx6FSt6iNfa2qi4bc1vE/fj2eBbMFjIrQIdoAh3u2DTg4NpCnuPtXSaebVTWUrklSHdXTBfWKx1eRxaO+6S7tuVLBx6Z5B2QsEpZQl8lA17Sf0eBHldx8i5D+r1nz2gTuh2fWZx2N2bYv2Xipl2cvn7ySAVgc0vlNl8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=KP/JsfvE; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="KP/JsfvE" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780556183; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D3PtV/wdUNwaqt62doo9rdFl9ViQ6FDPrsmGB6jLREY=; b=KP/JsfvErPsC/GaQoq0oBJFFlGFUsWlRzRKkTnmuR5hV7TVEGWr9uupbl3Ijm9Z7MnHOMq 3RK3uEGRtQ2GzNdA2qpeicDfI7WYXz5sGh6ouPY912yH/VCBtl/+LB3LtcbCi4S1O/nCth 9XegMIDH9VYUsecTA7sRf+/gRqrvQEE= From: George Guo 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 Subject: [PATCH 6/8] LoongArch: Fix EFI linking with -fdata-sections Date: Thu, 4 Jun 2026 14:53:15 +0800 Message-Id: <20260604065317.219777-7-dongtai.guo@linux.dev> In-Reply-To: <20260604065317.219777-1-dongtai.guo@linux.dev> References: <20260604065317.219777-1-dongtai.guo@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: George Guo When building with func-fdata-sections, the .init.bss section gets split up into a bunch of .init.bss. sections. Make sure they get linked into .init.data. Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- arch/loongarch/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/loongarch/kernel/vmlinux.lds.S b/arch/loongarch/kernel/vm= linux.lds.S index 840d944c2f73..dc5fa017db94 100644 --- a/arch/loongarch/kernel/vmlinux.lds.S +++ b/arch/loongarch/kernel/vmlinux.lds.S @@ -96,7 +96,7 @@ SECTIONS #endif =20 .init.bss : { - *(.init.bss) + *(.init.bss .init.bss.*) } . =3D ALIGN(PECOFF_SEGMENT_ALIGN); __initdata_end =3D .; --=20 2.25.1 From nobody Mon Jun 8 10:56:50 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 851823DBD6F for ; Thu, 4 Jun 2026 06:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556210; cv=none; b=sEa3wKNIcfRbwQgqrvcuoiFRjqOrD+yU4YOeFN3h9LUqTjFOwswcZWugSP2YrAs/16m/0E1zpVEZzXllFhntzOXHPIOTBgR/G/pbVnAKgSlK1s3LfTz+qMOPcMCCJeU2iRiEOboyexNTyOTs4i7mX1AaBjfYNBp9kDL4XDqwVXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556210; c=relaxed/simple; bh=cDfZSz3ivvl1QfWZ9jvAA+VablcjicxvJ0V6T4B9iOk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WN+Fd00sG6Iw4vj2KAKmKBuBXUzmKJNIuwnup399WoaV8ZsreakGUcmSVxAnP5mEfxbm/UNqRgwvA/qT9nJpOpmpKMrgRu2YX3RmKHgdUxr2twn8yfmi61bNEtDmPU+U+WHFsmVhPO9EcCdeLABkEAfNK18XAuXp33XFYtc5mI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=qw/LD98X; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qw/LD98X" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780556206; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WjOt6p1vyAYaMNIqwKJQkplVc88EqcFx+7171iEr4bE=; b=qw/LD98Xc9AvH7ZbB0k5aNJcUKoq562Ef7c2MoKZ7WPcJT4lwIT8IutXQEnzYfooS9VRKR 7PdhHGKhC7m7QtjytaG5LctnehDHX1W0Ib24e6ZCjvwNpXeDtXQC0GzVDlF7l7oTMpsoS+ cEtx131EP2eT2xE3p45kBwyL/vK0Fn0= From: George Guo 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 Subject: [PATCH 7/8] objtool/klp: Add LoongArch jump opcode bytes support Date: Thu, 4 Jun 2026 14:53:16 +0800 Message-Id: <20260604065317.219777-8-dongtai.guo@linux.dev> In-Reply-To: <20260604065317.219777-1-dongtai.guo@linux.dev> References: <20260604065317.219777-1-dongtai.guo@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: George Guo Implement arch_jump_opcode_bytes() for LoongArch so that klp checksums for jump/call instructions with non-relocated destination offsets are position-independent, mirroring the x86 and arm64 implementations. Mask out the embedded branch offset while preserving the opcode and the register operands, which differ per instruction format: - B/BL (reg0i26): no regs -> 0xfc000000 - BEQZ/BNEZ/BCEQZ/BCNEZ (reg1i21): keep rj/cj -> 0xfc0003e0 - JIRL/BEQ/BNE/.../BGEU (reg2i16): keep rj/rd -> 0xfc0003ff Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- tools/objtool/arch/loongarch/decode.c | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 674e4efd138f..12facd0cc8d1 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -432,6 +432,47 @@ unsigned long arch_jump_table_sym_offset(struct reloc = *reloc, struct reloc *tabl } } =20 +size_t arch_jump_opcode_bytes(struct objtool_file *file, struct instructio= n *insn, + unsigned char *buf) +{ + union loongarch_instruction *code; + u32 insn_word; + + insn_word =3D le32toh(*(u32 *)(insn->sec->data->d_buf + insn->offset)); + code =3D (union loongarch_instruction *)&insn_word; + + switch (code->reg0i26_format.opcode) { + case b_op: + case bl_op: + /* reg0i26: 26-bit offset, no register operands */ + insn_word &=3D 0xfc000000; + break; + case beqz_op: + case bnez_op: + case bceqz_op: /* =3D=3D bcnez_op */ + /* reg1i21: keep opcode + rj/cj at bits[9:5] */ + insn_word &=3D 0xfc0003e0; + break; + case jirl_op: + case beq_op: + case bne_op: + case blt_op: + case bge_op: + case bltu_op: + case bgeu_op: + /* reg2i16: keep opcode + rj/rd at bits[9:0] */ + insn_word &=3D 0xfc0003ff; + break; + default: + break; + } + + insn_word =3D htole32(insn_word); + memcpy(buf, &insn_word, sizeof(insn_word)); + + return LOONGARCH_INSN_SIZE; +} + #ifdef DISAS =20 int arch_disas_info_init(struct disassemble_info *dinfo) --=20 2.25.1 From nobody Mon Jun 8 10:56:50 2026 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 D08863D9045 for ; Thu, 4 Jun 2026 06:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556228; cv=none; b=S76eNX2THX7v0k9JzLxD+bKcm62DThpIa8C5AKX/Pb8v/hdKO2HK+C0YJusCEAcLZ+5YoZJVjSfrcQJ73EJv52xsSMTqAgpIn3stcsxKTeGvra0D13h3yeTK3D0+HbesvTXFKAaGLDnb/WtR0Fic5ri6nnQ9oaf+GDNr8+hdN3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556228; c=relaxed/simple; bh=dydZVhth1y6JE7+fyLmn2w7NHqI4W6Xits7j2exGHig=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hK9ZWZHrKQ0ye6ypdE2wOaWs9fIbvmZAsUquTU5TbYoI7CTmg15tQQRNszYXW5rIkqGhE6vKgIxcjJMP0gxnIj00bYRHCRfmjTiXYc/lr+2YugV4j7m6ldv4HwUCES0sD91dexI1zGNl1yOCpgw2gLnSYaE+KF7U4VLOAi9eZxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FcbXErjt; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FcbXErjt" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780556224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2K4imcceEzYpUOx6xUchhbO3GzKewULjWdUSxLezYq8=; b=FcbXErjtlTY6PwY7b3DmaGm946iCHHqA4xODP3txeKerfajc18mAzBEd9Nd86++L5m+r/y RvxO+5n1yjYTpd/M4hPs7P5GSklG+evgZW74n4dl7PktQBKl5+Wti4zqEVchk6dDjMWjFQ HSzjQISY/riGUyA58zySejFTRHTMHQA= From: George Guo 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 Subject: [PATCH 8/8] klp-build: Add LoongArch syscall patching macro Date: Thu, 4 Jun 2026 14:53:17 +0800 Message-Id: <20260604065317.219777-9-dongtai.guo@linux.dev> In-Reply-To: <20260604065317.219777-1-dongtai.guo@linux.dev> References: <20260604065317.219777-1-dongtai.guo@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: George Guo Add LoongArch support for KLP_SYSCALL_DEFINEx(), mirroring the generic __SYSCALL_DEFINEx() pattern from include/linux/syscalls.h. Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- include/linux/livepatch_helpers.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/livepatch_helpers.h b/include/linux/livepatch_he= lpers.h index 4b647b83865f..a8aad067177b 100644 --- a/include/linux/livepatch_helpers.h +++ b/include/linux/livepatch_helpers.h @@ -91,6 +91,28 @@ } \ static inline long __klp_do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) =20 +#elif defined(CONFIG_LOONGARCH) + +#define __KLP_SYSCALL_DEFINEx(x, name, ...) \ + __diag_push(); \ + __diag_ignore(GCC, 8, "-Wattribute-alias", \ + "Type aliasing is used to sanitize syscall arguments");\ + asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \ + __attribute__((alias(__stringify(__se_sys##name)))); \ + ALLOW_ERROR_INJECTION(sys##name, ERRNO); \ + static inline long __klp_do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ + asmlinkage long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ + asmlinkage long __attribute__((optimize("-fno-optimize-sibling-calls")))\ + __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ + { \ + long ret =3D __klp_do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__));\ + __MAP(x,__SC_TEST,__VA_ARGS__); \ + __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \ + return ret; \ + } \ + __diag_pop(); \ + static inline long __klp_do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) + #endif =20 #endif /* _LINUX_LIVEPATCH_HELPERS_H */ --=20 2.25.1