From nobody Fri Jul 24 21:29:03 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 57D2042AFAF for ; Fri, 24 Jul 2026 11:42:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893360; cv=none; b=b3x5LWxAx4CP+8GHkLkqMfzj+gyY2rYKTje/8/XZlXgr8XoxqZlAAAakntQQco6Og90pjWsGKHaTfUMJEtWGMfukZwa6+6Ka+xIef/NdqBbSQ10w4cpSaVQ/vVnWgbSN1NIOdWYYbQmin+vt1eRh3VGicFVDqS2Op+akqPvX+PU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893360; c=relaxed/simple; bh=g4aWsJHOiDyicVy+6atNZeWvyTiklyF5B/Q9s60sTEQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=enawmTi1B8zVUc5ETlOBcKxv8XdTS4gTKSZ/SlRAHcphZCL9dpiAjCgzizmaw61a15ZyZak/ktMqEydHg9rQ3TharBuv1QbVLv025gtczFI+RmSdM7D1zQBqkYZRAOzjHQNztWBkCaVozt6/SMOap+8fGXC379PLMn6S3jEalSc= 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=D8ya6kBZ; arc=none smtp.client-ip=91.218.175.185 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="D8ya6kBZ" 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=1784893337; 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=YodUDurSBZ0t3mGqHGWa1pwdwgkEMO0YVH20Jc2peyc=; b=D8ya6kBZ5iyWBDJ2Hqd7Fx+WaE3Z+8K0AI2YXDn8UoAxZLLJF0pWcRfguyRzuwNdkjIRje /vH+Eh4utMDPEi0cHUFDQb70zHyRcrrgFv98Jil21rEtjRr0ru0y9KMcGiNP0/VfRqkGFm S2uyuSJlwtbrA211tHGHFR1N5rU/KIs= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, WangYuli Subject: [PATCH v4 01/14] objtool/LoongArch: Add arch_adjusted_addend() for KLP support Date: Fri, 24 Jul 2026 19:41:14 +0800 Message-ID: <20260724114128.31451-2-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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: WangYuli Signed-off-by: WangYuli 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.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.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 4B9CE41DDE3 for ; Fri, 24 Jul 2026 11:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893357; cv=none; b=TkaNkqknIKmtEGUJ/BZVdMdugGb6kg/pyC/KSi5MUP3YXF3rwP/yxNYu2psjHDAPFpz+mlYj4p4o1Q1j1LPMDiJSQSeSQsJ2E+uWxHG9k1Vdk+skNvCaP7wZpsB2iFA1YYG/K8UyRCHcrBQJ/TM2/1wsvQyHlUoI+aJlIhCklLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893357; c=relaxed/simple; bh=xb9mu0XWlZz+CCoPcNZQlw5KDRg+JU1R2U/pL8b7sw4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lRUmBlDb74pq/K4DkdqW/aF8lkO7brQh94D5OXtDW4MADFin02B2T03jFqxsIh2xrrtGKZ/Noou5NkGThhokkB1uGarnAkH/dWZ5keEnNAFNfuO/4f1hsOkZgq7LUCpwp4PUViL7Z91iHnRcHU4Yh3JkK4tL1qN/5VyiFoqg7lk= 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=bpyhbRtc; arc=none smtp.client-ip=95.215.58.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="bpyhbRtc" 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=1784893344; 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=hhuH9g52jHNSJEe8w/a0EnKpZBvqwu0muqKI08e0rGY=; b=bpyhbRtcwoLRaIqiefamkx97gaXfL94XlWfbN22XgoqVxetK7SFWuqcxkKX0TDbJXhDqWx DBSuTMGYzmzYekaRmw49nq5cwvhtnT6NehsMU2LZTjUcwS3bRpf1gx1Xol95HCu248yHX5 lkIzmpXEaaVguwe5sl7N4BsQX8H/mEA= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 02/14] LoongArch: Mark special sections for KLP support Date: Fri, 24 Jul 2026 19:41:15 +0800 Message-ID: <20260724114128.31451-3-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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 objtool needs to split the kernel's special sections into per-entry symbols when generating livepatch modules. Mark them so it can: - .altinstructions and __ex_table are read-only, so set an explicit entry size via SHF_MERGE (ALT_INSTR_SIZE / EXTABLE_SIZE). - __bug_table and __jump_table are writable. SHF_MERGE cannot be combined with SHF_WRITE (Clang rejects it), so annotate each entry with ANNOTATE_DATA_SPECIAL instead, mirroring x86/arm64. Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- arch/loongarch/include/asm/alternative-asm.h | 10 ++++++++-- arch/loongarch/include/asm/alternative.h | 11 +++++++++-- arch/loongarch/include/asm/asm-extable.h | 10 ++++++++-- arch/loongarch/include/asm/bug.h | 1 + arch/loongarch/include/asm/jump_label.h | 2 ++ arch/loongarch/kernel/asm-offsets.c | 18 ++++++++++++++++++ 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/arch/loongarch/include/asm/alternative-asm.h b/arch/loongarch/= include/asm/alternative-asm.h index 7dc29bd9b2f0..92122a258a8e 100644 --- a/arch/loongarch/include/asm/alternative-asm.h +++ b/arch/loongarch/include/asm/alternative-asm.h @@ -5,6 +5,8 @@ #ifdef __ASSEMBLER__ =20 #include +#include +#include =20 /* * Issue one struct alt_instr descriptor entry (need to put it into @@ -33,14 +35,16 @@ .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 .subsection 1 + ANNOTATE_DATA_SPECIAL 143 : \newinstr 144 : + ANNOTATE_DATA_SPECIAL_END .previous .endm =20 @@ -63,17 +67,19 @@ (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 =20 .subsection 1 + ANNOTATE_DATA_SPECIAL 143 : \newinstr1 144 : \newinstr2 145 : + ANNOTATE_DATA_SPECIAL_END .previous .endm =20 diff --git a/arch/loongarch/include/asm/alternative.h b/arch/loongarch/incl= ude/asm/alternative.h index b5bae21fb3c8..1d3ac2f667d1 100644 --- a/arch/loongarch/include/asm/alternative.h +++ b/arch/loongarch/include/asm/alternative.h @@ -7,6 +7,7 @@ #include #include #include +#include #include =20 struct alt_instr { @@ -70,22 +71,28 @@ 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" \ + ANNOTATE_DATA_SPECIAL "\n" \ ALTINSTR_REPLACEMENT(newinstr, feature, 1) \ + ANNOTATE_DATA_SPECIAL_END "\n" \ ".previous\n" =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" \ ".subsection 1\n" \ + ANNOTATE_DATA_SPECIAL "\n" \ ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \ ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \ + ANNOTATE_DATA_SPECIAL_END "\n" \ ".previous\n" =20 /* 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..14e3acbaad8d 100644 --- a/arch/loongarch/include/asm/bug.h +++ b/arch/loongarch/include/asm/bug.h @@ -25,6 +25,7 @@ #define __BUG_ENTRY(cond_str, flags) \ .pushsection __bug_table, "aw"; \ .align 2; \ + __ANNOTATE_DATA_SPECIAL; \ 10000: .long 10001f - .; \ _BUGVERBOSE_LOCATION(WARN_CONDITION_STR(cond_str) __FILE__, __LINE__) \ .short flags; \ diff --git a/arch/loongarch/include/asm/jump_label.h b/arch/loongarch/inclu= de/asm/jump_label.h index 7ef4ae3abf08..d20f0fa24b6b 100644 --- a/arch/loongarch/include/asm/jump_label.h +++ b/arch/loongarch/include/asm/jump_label.h @@ -12,6 +12,7 @@ #include #include #include +#include =20 #define HAVE_JUMP_LABEL_BATCH =20 @@ -27,6 +28,7 @@ #define JUMP_TABLE_ENTRY(key, label) \ ".pushsection __jump_table, \"aw\" \n\t" \ ".align " __stringify(PTRLOG) " \n\t" \ + ANNOTATE_DATA_SPECIAL "\n\t" \ ".long 1b - ., " label " - . \n\t" \ JUMP_LABEL_TYPE key " - . \n\t" \ ".popsection \n\t" diff --git a/arch/loongarch/kernel/asm-offsets.c b/arch/loongarch/kernel/as= m-offsets.c index 2cc953f113ac..a611cbe557ed 100644 --- a/arch/loongarch/kernel/asm-offsets.c +++ b/arch/loongarch/kernel/asm-offsets.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include =20 static void __used output_ptreg_defines(void) { @@ -323,3 +325,19 @@ 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(); +} --=20 2.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 2EBF73DAAAC for ; Fri, 24 Jul 2026 11:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893381; cv=none; b=B2/M5aKkWls+6Wv0qaRSjV7HDrW6f2kBH9kAGpwHyMlSLVQRKqAsbWlB9tu/+0NIeJdpSCHEX0qyjzX0B0bwlu8A2sMbjjYLD5bnL1bTWhjVu4kT2M79XCCPatLtxeeaC4xGbaRIBCqXxO36y8feaZJgAV6mzELlJeQ0j59FYlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893381; c=relaxed/simple; bh=Gv4lC9BvcinQAa/Ch0YFAmnZsxbAsTD/Je/O7YwLvcY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NXSNkViXzJzawEn9CL29cTWcuxxfMNV4Mt0Cqy1g5HhZtXwgi63Gy4d9Dis71STWVoPh+cwROmc83gkituwBH+asxLkf/XHt+vpVgo2h5UlC/CghlXCizlvn5LOq0oaEjVNu9rV277b6d9nBLbX620MR5s24d+1RPii6rEUSeWc= 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=Tb9Yg+Ft; arc=none smtp.client-ip=91.218.175.185 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="Tb9Yg+Ft" 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=1784893362; 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=Dg8mnRfhKOXtjhnJODwnJEoqXKaAueIbRF1/0IO5Wm4=; b=Tb9Yg+Ftj7cpUt+/LJTOq4vkeyVaDsyy39Td8jYEqol4PGaNk+9u4G8yrB0+YgTROOWeET 5ctg1fwY4lYaj4N2CWiqAMW1wPClBvgqpWzHvIGw1btjCPI8BORwmsaHG62VvyLyHq/5NP sfkabW+6WZbkBkNwbLRkOsUh5AZp/ZY= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 03/14] livepatch/klp-build: use -fPIC and drop direct-extern-access on LoongArch Date: Fri, 24 Jul 2026 19:41:16 +0800 Message-ID: <20260724114128.31451-4-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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, the klp relocation machinery redirects a livepatch's reference to a core-kernel symbol through a GOT entry. klp-build extracts the patched function into a separate module while the referenced symbol stays in the core kernel, so the reference must be GOT-indirect for that redirect to work. Two default compiler behaviours defeat this and make a loaded livepatch module fault. The first is a same-unit global (the syscall test patches sys_newuname() in kernel/sys.c, which reads 'uts_sem', a rw_semaphore defined in the same file). With CONFIG_RELOCATABLE=3Dy the kernel is built -fPIE. For a global defined in the same unit, -fPIE emits a direct PC-relative reference (R_LARCH_PCALA_*) and skips the GOT, while -fPIC routes it through the GOT (R_LARCH_GOT_PC_*). Once klp-build moves the patched function into the livepatch module, the direct reference has no GOT slot to redirect and faults. The second is an extern global. -mdirect-extern-access replaces GOT-based external symbol access with direct addressing. A livepatch reference to such a symbol then has no GOT slot to fix up, and the wrong address faults the kernel. This optimization was added by commit 38b10b269d04 ("LoongArch: Tweak CFLAGS for Clang compatibility") as a nice-to-have that reduces GOT accesses. For LoongArch KLP builds, keep both forms GOT-indirect: - Add -fPIC via KCFLAGS. -fPIE is not enough; it optimizes away the very GOT indirection KLP relies on. - Disable direct-extern-access: -mno-direct-extern-access for GCC, -fno-direct-access-external-data for Clang. Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- scripts/livepatch/klp-build | 43 ++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index e83973567c87..27463def08f8 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -278,6 +278,13 @@ validate_config() { [[ -x "$OBJTOOL" ]] && "$OBJTOOL" klp 2>&1 | command grep -q "not impleme= nted" && \ die "objtool not built with KLP support; install xxhash-devel/libxxhash-= dev (version >=3D 0.8) and recompile" =20 + if [[ -v CONFIG_LOONGARCH ]]; then + [[ -v CONFIG_AS_HAS_EXPLICIT_RELOCS ]] || \ + die "LoongArch klp-build requires CONFIG_AS_HAS_EXPLICIT_RELOCS=3Dy" + [[ -v CONFIG_RELOCATABLE ]] || \ + die "LoongArch klp-build requires CONFIG_RELOCATABLE=3Dy" + fi + return 0 } =20 @@ -556,6 +563,31 @@ build_kernel() { local log=3D"$TMP_DIR/build.log" local cmd=3D() =20 + local ARCH_KBUILD_CFLAGS_KERNEL=3D"" + local ARCH_KCFLAGS=3D"" + + # For KLP, LoongArch symbol references must stay GOT-indirect so the klp + # relocation machinery can redirect a cross-object reference through a + # GOT entry. Two default behaviours defeat that (CONFIG_RELOCATABLE and + # CONFIG_AS_HAS_EXPLICIT_RELOCS are checked in validate_config()): + # + # - -fPIE (added under CONFIG_RELOCATABLE) emits a direct PC-relative + # reference for a same-unit global and skips the GOT; -fPIC routes it + # through the GOT. Add -fPIC via KCFLAGS. + # - -mdirect-extern-access replaces GOT access for an extern global with + # direct addressing. Disable it. + if [[ -v CONFIG_LOONGARCH ]]; then + ARCH_KCFLAGS=3D"-fPIC" + + if [[ "${CONFIG_CC_IS_CLANG:-}" =3D=3D "y" ]]; 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 + cmd=3D("make") =20 # When a patch to a kernel module references a newly created unexported @@ -581,7 +613,16 @@ 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:+ $A= RCH_KCFLAGS}") + # -fPIC is added for KLP via KCFLAGS above; the arch adds -fPIE via + # KBUILD_CFLAGS_KERNEL, which kbuild places after KCFLAGS on the + # built-in compile line. -fPIC/-fPIE is last-one-wins, so -fPIE would + # win. Setting KBUILD_CFLAGS_KERNEL on the command line replaces the + # arch value (not append), which drops -fPIE and lets -fPIC win. Only + # do this when an arch needs it (LoongArch). + if [[ -n "$ARCH_KBUILD_CFLAGS_KERNEL" ]]; then + cmd+=3D("KBUILD_CFLAGS_KERNEL=3D$ARCH_KBUILD_CFLAGS_KERNEL") + fi cmd+=3D("vmlinux") cmd+=3D("modules") =20 --=20 2.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (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 0A274364022 for ; Fri, 24 Jul 2026 11:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893393; cv=none; b=CnO8TJC5MPv52u5AY5fNTO1cggmZTXt4pzfWfg2BYB2tbGeRUbGmRIN7CHUhg8mJYIxKy8fL+Kw/SBUD/qQzrH67ixa65sZALp1+520NqJKACftuoAQCu1m9slqxnRXgKuIEO8q2dqP+6PV4jXux9od2xYGru7ZGtO+W2R8Xx00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893393; c=relaxed/simple; bh=Bb78+cO275HEQbSq6ijCG4Le87X/mYGTAx1uSh3BzgU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N6pcgfXtOD9YXVTtn3FNoJu4hK4AdZHPBsJ/99HFCwbJr+HRE3yMcELkmLrqj1aGgKMYmBLCj64roZKa7d6WnRGbH5tOYZnOqnDBPjG+1TaH/DRP+EZcVCYcrQXKmTRboKVoQ/r2qq43zTNAEo/rSVEW0v2H4VV3R7SRkbimpmA= 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=Yuy2Gvuh; arc=none smtp.client-ip=95.215.58.188 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="Yuy2Gvuh" 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=1784893383; 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=HOw/Zcv6a4N4ORviF7azimVASXV/RZlA1Vn92xRQ/yk=; b=Yuy2GvuhW6oJDgSuWJcmZomaFQ/EBi5Lhovflvk4eSVRFchbZuOE9s4JaP6WtHf1o7we9b A3xNOqDUUDZX6hFBlBO/08wpKcz9Y1Fq4Ivctwpu7rlmRTa48lFXgbRu9ZIHdnVDP0yQZZ ex5Tq/dr2bTz2aw3eLxj9as1fQnkMwo= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 04/14] LoongArch: Fix EFI linking with -fdata-sections Date: Fri, 24 Jul 2026 19:41:17 +0800 Message-ID: <20260724114128.31451-5-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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 -fdata-sections, the .init.bss section gets split up into a bunch of .init.bss. sections. Make sure they get linked into .init.bss. 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..570f936df34e 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.*) /* from the EFI stub */ } . =3D ALIGN(PECOFF_SEGMENT_ALIGN); __initdata_end =3D .; --=20 2.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.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 642E342BC20 for ; Fri, 24 Jul 2026 11:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893418; cv=none; b=Hx9mTq1krh9VyfSdhYQHrC6oAWRoPamsgLhLzFM2SVW5kiX0g4I3g+WDME/7ABrCkYOXqSxLZIcCgznODWofsHQBM+tTjSRgou5cJzvkyV6SXZsja93uNzwBr1wYiY61E15iMyp3zclZfdQKtex8OAJw22rJES8PDjxpAdswJY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893418; c=relaxed/simple; bh=vWZ2f6qLJn8k5AwIqGBaX6o9NuboH8z04KTf0fV6LSE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gEpzl/KtYEAqbDNHkAFW+6VXeJdSUAqM+OiiJaxMPDFy+gERheXFRkKwxWK8boED822/HLWASyQ9ZW1Y+wu3QNedlbO9shfH473UOUklHep56iP+bYOBsulN9L7KJeu9ebxDJ7YHt+/5HTdpFJ8J60nrgjOh1pBDVJslAQhRVFo= 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=Bs6JK7id; arc=none smtp.client-ip=95.215.58.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="Bs6JK7id" 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=1784893407; 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=w7joukHFcR2YlJrUdrRU9RAszNALKTouzih+0IOutSo=; b=Bs6JK7idysRnF8e91HbePH1q0OK90zj1NUS7gTmNtysWgYFCAyBJwxHFKuSVS3tbNEBIGp oiqsYRsSiaw44OfTlCSt1tjUfeHGuuspplGGYusyv3TnF4k8cW7dqc0ssudbJaNjB3ZbXt dBp+Gy5ULPpGDqDcxcDecx61TN5dZp0= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 05/14] objtool/klp: Add LoongArch jump opcode bytes support Date: Fri, 24 Jul 2026 19:41:18 +0800 Message-ID: <20260724114128.31451-6-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 1E2F642EEA3 for ; Fri, 24 Jul 2026 11:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893431; cv=none; b=q/cJzM1ftUOSYqb9XxMwscN8ZjWWYS65COYievMv+KYVzSJ6hEsuVinlKh9ElWQyNa6U2WhnpQrMDkWBWpUD8PFcNQE47I6Pee/9Zh0oPd8PSAkR0s0uYwqzHNbPqSLyRQeD9heQ3UXPmu6IDyy2R3Jc/k637YXsppoCbz5NMxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893431; c=relaxed/simple; bh=nR2NGgnoSO2e2cqedVwvp+9ffYat37por2Pc3FEwQSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C068rfq59auJnrSION9N9bGhEGXLKxTYW8pEKg6LwmDIzp1VLFsmjlwYAFz3JE+yDMB1hohkkHZULM+MFyHPwt5DPCJ/dkc3BkfeDrYCKXvnacLpGiz/GhZrJqtThrLAWF2hb9i5edNdnEzxl/57eG2QPZB1rrmVhPNXcLPw9CU= 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=Y7ogIpGT; arc=none smtp.client-ip=95.215.58.186 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="Y7ogIpGT" 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=1784893420; 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=QVqsYNxvxH4gglTruj2hqXBkW0j7nkdtxj7CnZ4x+PU=; b=Y7ogIpGTEYdzlwPARvlTWQZ9aVJkfPYE6qzq0Q8X/P1ZLOIQGZ18QHjEOu9jG7utHLfIWt ii1HE8gkwUM9vv000pvLTDajoSkIivC38aWQYNTIaUNk1WbWsadZU57zNvwDt3mhXG0zJc 7k0gY+gVQeYvUCkeTxznVK3v2d+MdTU= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 06/14] klp-build: Add LoongArch syscall patching macro Date: Fri, 24 Jul 2026 19:41:19 +0800 Message-ID: <20260724114128.31451-7-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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..d79e692e382d 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.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (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 5A32D42377D for ; Fri, 24 Jul 2026 11:43:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893447; cv=none; b=Q9pe9U7rx9Y246we285j47IugZ3DseCzSn8Tj9S1/FFM9GDRrzNAeVCDRcL03YvIJlEg8uFJUL7Yf1Ngiqx+V6HojWSmQjbcux5arKtUm5Q4VdkkQo5FR8zTOvbq4234Z1nqz16HsZmIa2m3Jo17PA7RDN6yCfB/mH3kJHfxSJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893447; c=relaxed/simple; bh=GtT94Ry+uUJBjxiUnKxrkDDhoiOOj9v515CL6k/baIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qCwlaDnMYdVIWrHwsWyDhe0LQM7u20hhH1AbQHlUu/59sZcheYkiWyXSgXeQ0qZg6nI2AREJ8TNhy6bGkVeBbPcm+bBep+u7BmvW/77cEobvGrt82A4P9Uzap4tJy+HArRO6X+kUjXWoYkgZB9hvpnI0rBJ5iuueG4edrYsatxs= 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=eThdGdhl; arc=none smtp.client-ip=95.215.58.174 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="eThdGdhl" 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=1784893436; 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=nT4tadmZ1lw5h3g23O3yyAlZUdiECqqGkhthTyxcnTI=; b=eThdGdhlIpYmh+EG7kdm8aiZNy/xv+/gm8U0VAJLzR5FlTeRBDaHq9wz6S7vauxKOizzyH v10/TgtCOktYNO7SeXr1s0NdLGCpATXtpfZu1WRbadxU6v5L2RyqWkapCj2XELB/Sw/f5Q mNWZHx6xZqfdoWjFam4q9q0LffPm6yA= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, WangYuli Subject: [PATCH v4 07/14] LoongArch: Add livepatch build (KLP) support Date: Fri, 24 Jul 2026 19:41:20 +0800 Message-ID: <20260724114128.31451-8-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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: WangYuli Signed-off-by: WangYuli 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.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 4C9F2429CE6 for ; Fri, 24 Jul 2026 11:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893453; cv=none; b=hcU4bZwaY/qP6x2du+ekxtaV2ueh2qwl6g/hIJlAqLEirmArdzJcCzTCK4garKZqVIvfO69Zu1gxkkj/p8qfWS3n3ozhMTuLvjglkw/ry8Mvcox5eDJ6GgQSTKcsTuUiYExrNY1zVZXl24Ycb+BWoQ6h00kHziu+QM45aZC/BUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893453; c=relaxed/simple; bh=slM7L03r6D2OjaW+kBk0O9AeKJGNMLiGB01zwBQGGbc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZK5gPd6CjSs6jtyI1DOt0JRtYbxo6qwtOzaPDXse91aE6GQrETgRLkXrN/k4+vslZSZ5utzmBRKRPqavY+cEGcwm2XngnBWR2bZTWZ1zkR7i0aBf7jU/L5KlC3YFPFGZrzHmS7oT4M2xEerb4QTLv4Adzokj1avs5FPc+XPnptw= 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=o8O8t7cH; arc=none smtp.client-ip=95.215.58.186 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="o8O8t7cH" 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=1784893443; 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=6K7yvO3rVvrbt7FhGRcAwJSEYj6FUU71+bm2uI+UzLw=; b=o8O8t7cHGKxUHuoLeHx6f4lX3uv1xEOGhdDQjMdKfnZcSHPNQQJO75g/KfFNt3YIh4PVZ2 BcjVIXQZa+K3qhM8tu5c5q3OSLpTLDzpjDMLse7wpDss+cXzglYk2TPgRHbO/qIvSXXcfI SrZn3ABwq4/RjtohaA3Yg0QZA0ibHPg= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 08/14] LoongArch: Select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY Date: Fri, 24 Jul 2026 19:41:21 +0800 Message-ID: <20260724114128.31451-9-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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 arch/loongarch/Makefile uses -fpatchable-function-entry=3D2 when CONFIG_DYNAMIC_FTRACE is set, but nothing selects FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY, so kbuild falls back to FTRACE_MCOUNT_USE_RECORDMCOUNT and runs recordmcount on every object. The pass is useless here: there are no _mcount calls to find, and the real ftrace sites come from the __patchable_function_entries section anyway. It is not just wasted time. recordmcount needs a non-weak symbol in each text section, to use as the base of the __mcount_loc relocations it writes (see find_secsym_ndx()). GAS emits a section symbol for every section, so GCC objects always have one. Clang's integrated assembler drops unreferenced section symbols, so a clang object must use the function's own symbol -- but find_secsym_ndx() skips weak symbols. So with -ffunction-sections (which klp-build uses), a __weak function like sched_clock is alone in its section with no usable symbol, and recordmcount fails: Cannot find symbol for section 5: .text.sched_clock. kernel/sched/build_utility.o: failed Select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY like arm64 and riscv do, which disables the recordmcount pass altogether. Reported-by: Joe Lawrence Suggested-by: Joe Lawrence Signed-off-by: George Guo --- arch/loongarch/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 1dbf51ba9d6a..a1549003c871 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -88,6 +88,7 @@ config LOONGARCH select CPU_PM select EDAC_SUPPORT select EFI + select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY if DYNAMIC_FTRACE select GENERIC_ATOMIC64 if 32BIT select GENERIC_CLOCKEVENTS select GENERIC_CMOS_UPDATE --=20 2.53.0 From nobody Fri Jul 24 21:29:03 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 7EE4D42BC20 for ; Fri, 24 Jul 2026 11:44:18 +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=1784893463; cv=none; b=LfX5wX0/zVoadM/kOkwfeLMYGsOdjH3zYmXLpIXvVP8yJj5GVY6xUkMxjHbgekKVus3a8K55JEKsweoSVN7dj1KZqC0sbRWGrVY414Fe+Mittd2VZOqL4+xaATYsMphruG01NGpGYjlIy6hEzyc1znfIZW04lyXwpwiljGAmG2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893463; c=relaxed/simple; bh=awtKp8GoTpZLRWN4FwmOYGzyrNm8WEnDX2kSQMbAf3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MsuP5tI127tJR9C18EK0fKQJt77rEd2uKOnGrnlBLpBxSin7e8UxMrCu+dmaOXQRZWaiNd7PCt3P7zCcpqSINRz3sXvpbzr0OUqkATk7oIKBFL9KeDOMqd1HwvqnHn7AuuqhjWWzx071d0QYX/C+2JIp+zS7lPgf1K5GDI/56BA= 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=bR5xhC9B; 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="bR5xhC9B" 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=1784893453; 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=kOBS5OEfLhdRCerIgpAYs/smL6UyfBzQi4+mASVl25M=; b=bR5xhC9Bgyt/yKBqDd/C/Wrn9LBAv2aJQootVDKCjJqxRtpe3W5wUTs/AOmBWAbdBooqyv u7aOPiUEHwXVpF2RxV+CRK/AgkJwGx0l1ljlsrvx4DXHCI14bDY0E229eR5ZugHyIcEVTK /nqOlf2WKj2CJeyuCR0CiF/07YIHbGc= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 09/14] objtool/klp: Convert local label references Date: Fri, 24 Jul 2026 19:41:22 +0800 Message-ID: <20260724114128.31451-10-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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 Some toolchains reference an object through a local assembler label (.L*) rather than a section symbol plus offset. The assembler keeps the label because a "section + constant offset" reference would go stale under linker relaxation, while a symbol reference can be recomputed afterwards. Such labels are assembler-local, absent from kallsyms, and are never cloned into the livepatch object. Two toolchains hit this: - GCC/GAS on LoongArch references special section entries (__ex_table, __bug_table, __jump_table, .altinstructions) through local text labels instead of a section symbol. - Clang emits a switch jump table through a local label (.LJTI*) in a SHF_MERGE|SHF_STRINGS .rodata section, where the table shares the section with the livepatch's klp_func name strings. convert_reloc_secsym_to_sym() only handled the section symbol form and returned early for a label reference, so the label was never converted and the reference resolved incorrectly, with no error at build or load time: - GCC: should_keep_special_sym() cannot correlate the entry with an included function and silently drops it, so the livepatch module is missing the patched function's __ex_table / __bug_table / __jump_table entries. - Clang: the jump table is not cloned, and its base label resolves into the name strings that occupy the same offset; the switch's indirect jump then lands on a wild address and the patched function oopses at runtime. Redirect a local label reference off the label, mirroring the section symbol case: - In a text section, to the containing function symbol. A label with no containing function symbol (e.g. hand-written asm in a plain .text section) can't be correlated; skip it rather than failing, since such entries belong to unchanged code and are dropped anyway. - In a non-text section (e.g. the .rodata jump table), to the section symbol plus the full offset. Reported-by: Joe Lawrence Suggested-by: Joe Lawrence Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- tools/objtool/klp-diff.c | 49 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index b9624bd9439b..3e573b73fe6b 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1423,8 +1423,55 @@ static int convert_reloc_secsym_to_sym(struct elf *e= lf, struct reloc *reloc) if (!strcmp(reloc->sec->name, ".rela__patchable_function_entries")) return convert_pfe_reloc(elf, reloc); =20 - if (!is_sec_sym(sym)) + if (!is_sec_sym(sym)) { + /* + * Most toolchains reference special-section entries via the + * section symbol plus an offset. GCC/GAS on LoongArch instead + * references a local text label (.L*): LoongArch linker + * relaxation is the reason GAS keeps the label rather than + * reducing it to a section symbol reference. Such a label is + * never cloned into the livepatch object, so the entry would be + * silently dropped. Redirect the relocation to the containing + * function, mirroring the section-symbol case below. + */ + if (is_local_label(sym)) { + unsigned long offset =3D sym->offset + reloc_addend(reloc); + + if (is_text_sec(sec)) { + sym =3D find_symbol_containing_inclusive(sec, offset); + if (!sym) { + /* + * A local label with no containing function + * symbol (e.g. hand-written asm in a plain .text + * section). It can't be correlated to a function, + * so skip it rather than failing the build; such + * entries belong to unchanged code and are dropped + * anyway. + */ + return 1; + } + + reloc->sym =3D sym; + set_reloc_sym(elf, reloc, sym->idx); + set_reloc_addend(elf, reloc, offset - sym->offset); + } else { + /* + * A local label in a non-text section, e.g. Clang's + * .LJTI* switch jump table in .rodata. It isn't + * cloned into the livepatch either, so redirect the + * reloc to the section symbol plus the full offset, + * mirroring the section-symbol case below. + */ + if (!sec->sym && !elf_create_section_symbol(elf, sec)) + return -1; + reloc->sym =3D sec->sym; + set_reloc_sym(elf, reloc, sec->sym->idx); + set_reloc_addend(elf, reloc, offset); + } + } + return 0; + } =20 sym =3D find_symbol_containing_inclusive(sec, arch_adjusted_addend(reloc)= ); if (!sym) { --=20 2.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 4AA5C2F8E9C for ; Fri, 24 Jul 2026 11:44:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893488; cv=none; b=GVrWJLMHNJgTdYPUTtUdlHE6ICPyRQ3MOp3Q3fcm/32UHCUvYyMumeZL5IygmATthnTqLovEc+2EbbdY/2TpwbmVAHVvDEIFpp7AXFe4wDxg4SVguX5WDSl5pWZWfV89vjOmelCBha7ZkfTraFaWSEK7/rNt1AuNcE+HTkeUV98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893488; c=relaxed/simple; bh=CaFOpuuLUh9zgCRxgo2wwmY+NQu80AqfooJ+NmN19x4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IZcHOQ4ljFcDX45XeFhglbv0PObwmvjvV7OiiYJkB40ED3uYuv4gSUT+uwj3Wk7PX87lYM4VqVaKQiPQooCb/fCziTstQ7PBRXvd5zHb6nh3goQjpjlSJqsnqj+U/O0skBUbZEajrxgFRfHK3xcIJMKwxffDnIqMeW+PX8HRpZo= 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=qEae7tMi; arc=none smtp.client-ip=91.218.175.179 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="qEae7tMi" 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=1784893484; 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=IvQulOLnt6zPtOVaClrSdA4fxpkNIXdPTLy0qFfUDyc=; b=qEae7tMimh/BGqp58tT+Ftc7+Bgw99QaK1z2c1Cn2Fx+mB8nI4aWqjER/jw4s55utvEP// 8SBuUDaYBT53nbAOjCCXCBgKyUt8id2PRsALAfax6v+DjitDeDRHL0wysj5XC7YvA1ZSCm A+fMK2f+oXBPTJjtTRAvoCzKZqqk45M= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 10/14] objtool/klp: Fix ANNOTATE_DATA_SPECIAL parsing for local label references Date: Fri, 24 Jul 2026 19:41:23 +0800 Message-ID: <20260724114128.31451-11-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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 create_fake_symbols() takes each annotated entry's offset from the annotate relocation's addend alone. That works only when the relocation points at the special section's section symbol. GCC/GAS on LoongArch points it at the entry's local label instead, with a zero addend: every entry then gets offset 0, the "distance to the next annotation" size becomes 0, and the fallback sets the size to the rest of the section. So every fake symbol starts at offset 0 and covers the whole special section. If any entry in the section belongs to a patched function, should_keep_special_sym() keeps such a symbol, and the output module gets the entire __bug_table (thousands of entries and klp relocations) instead of just the patched function's entries. Compute the offset as sym->offset + addend, which handles both the section symbol form (sym->offset =3D=3D 0) and the local label form (addend =3D=3D 0). Reported-by: Joe Lawrence Signed-off-by: George Guo --- tools/objtool/klp-diff.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 3e573b73fe6b..a952e680e8a6 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1877,7 +1877,12 @@ static int create_fake_symbols(struct elf *elf) if (annotype(elf, sec, reloc) !=3D ANNOTYPE_DATA_SPECIAL) continue; =20 - offset =3D reloc_addend(reloc); + /* + * The annotated location may be referenced via the section + * symbol plus addend, or via a local label (GCC/GAS on + * LoongArch): sym->offset + addend covers both forms. + */ + offset =3D reloc->sym->offset + reloc_addend(reloc); =20 size =3D 0; next_reloc =3D reloc; @@ -1889,7 +1894,7 @@ static int create_fake_symbols(struct elf *elf) next_reloc->sym->sec !=3D reloc->sym->sec) continue; =20 - size =3D reloc_addend(next_reloc) - offset; + size =3D (next_reloc->sym->offset + reloc_addend(next_reloc)) - offset; break; } =20 --=20 2.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (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 84284378D8E; Fri, 24 Jul 2026 11:45:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893533; cv=none; b=kGR1lPYviAqNpUFmIuUD+qCyDWtv12pxTocXUdYHw0SzL2x9vD6XDj6MHw8QzU/NuyRCIwy46wfhqBApbzHxYw/XZuZOybZMM0ovCZhUvc933SYffqXRxiyNCoDFqED7xg9XPISBXz2VfBldvK/4DI5LoAwmMoK3Cdpf8e3mcRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893533; c=relaxed/simple; bh=1zECCi6Ex7mHqMuO1WEpHBQ0n6CgHagqiye0NBchq9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FjhXHRmze8PInM1fq0hXLPKdFuki+lYzByjsBJo9Wz+1XuH6Q4NyMYp9BBTVYfj2cKowTUOMpmjg8d8OnTVuidr2AJGTs/0nmZY3qokxFAOoi0GD3X2sYoaWVWd3jZE8yt2lQ4PYgOpqrh2h4e0DKWegKiKjHySPKl+Amj2jNmY= 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=t5R7uASp; arc=none smtp.client-ip=95.215.58.174 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="t5R7uASp" 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=1784893529; 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=3K5wGN9XWFfzaBYR/egLQZSf83uwFZjqG2cXWqC5y/I=; b=t5R7uASpLGLvqdCNP++RUKeR4X0OuB+dPFuO7S5FkEycdTKYyvqSVQgzOSniOeTOL0ixeC pJOp0TF8s1eDLyoqcxGpM6oMyTCYdHqzUTkMPuRi442b6bw7U21J1/ODqhVaSbBVp3Te7w hEDzbYDicN3HpEoDFAJ5fsRuq2gP9As= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 11/14] objtool/klp: Fold LoongArch paired ADD/SUB relocations into PCREL Date: Fri, 24 Jul 2026 19:41:24 +0800 Message-ID: <20260724114128.31451-12-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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, the "key - ." field of a __jump_table entry can come out as two relocations at the same offset, R_LARCH_ADD64 plus R_LARCH_SUB64. clang's integrated assembler emits this pair when the key symbol is not defined in the same translation unit (for example __tracepoint_netif_rx); GAS, and clang for locally-defined keys, produce a single R_LARCH_64_PCREL instead, which is why GCC builds do not hit this. objtool's elf_create_reloc() allows only one relocation per offset, so cloning such an entry fails with: vmlinux.o: error: objtool: __jump_table_23683+0x8: duplicate reloc When the SUB half points at the relocation's own position (the "sym - ." pattern), the pair means the same thing as one PC-relative relocation. Add arch_normalize_paired_reloc() which rewrites the ADD half to R_LARCH_32_PCREL/R_LARCH_64_PCREL and skips the SUB half. The LoongArch module loader supports both forms. Reported-by: Joe Lawrence Signed-off-by: George Guo --- tools/objtool/arch/loongarch/decode.c | 62 +++++++++++++++++++ .../objtool/arch/loongarch/include/arch/elf.h | 18 ++++++ tools/objtool/klp-diff.c | 13 ++++ 3 files changed, 93 insertions(+) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 12facd0cc8d1..273398ea4486 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -39,6 +39,68 @@ u64 arch_adjusted_addend(struct reloc *reloc) return reloc_addend(reloc); } =20 +/* + * A cross-section difference like the "key - ." field of a __jump_table + * entry may come out as a paired R_LARCH_ADD plus R_LARCH_SUB relocation + * at the same offset: clang's integrated assembler does this when the + * symbol is not defined in the same translation unit (GAS, and clang for + * locally-defined symbols, emit a single PCREL instead). objtool allows + * only one relocation per offset, so the pair breaks cloning. + * + * When the SUB half points at the reloc's own position ("sym - ."), the + * pair means the same as a single PC-relative relocation, which the + * module loader also supports: rewrite the ADD half to R_LARCH_*_PCREL + * and tell the caller to skip the SUB half. + * + * Return 1 to skip the reloc, 0 to proceed, -1 on error. + */ +int arch_normalize_paired_reloc(struct elf *elf, struct reloc *reloc) +{ + struct section *rsec =3D reloc->sec; + unsigned int sub_type, pcrel_type; + struct reloc *sub, *add; + + switch (reloc_type(reloc)) { + case R_LARCH_ADD32: + sub_type =3D R_LARCH_SUB32; + pcrel_type =3D R_LARCH_32_PCREL; + break; + case R_LARCH_ADD64: + sub_type =3D R_LARCH_SUB64; + pcrel_type =3D R_LARCH_64_PCREL; + break; + case R_LARCH_SUB32: + case R_LARCH_SUB64: + /* + * Skip only if the paired ADD (the preceding reloc) has + * been rewritten to PCREL; otherwise leave the pair + * intact so a failed conversion stays loud. + */ + add =3D reloc_idx(reloc) ? reloc - 1 : NULL; + if (add && reloc_offset(add) =3D=3D reloc_offset(reloc) && + (reloc_type(add) =3D=3D R_LARCH_32_PCREL || + reloc_type(add) =3D=3D R_LARCH_64_PCREL)) + return 1; + return 0; + default: + return 0; + } + + /* The paired SUB reloc immediately follows the ADD */ + sub =3D rsec_next_reloc(rsec, reloc); + if (!sub || reloc_offset(sub) !=3D reloc_offset(reloc) || + reloc_type(sub) !=3D sub_type) + return 0; + + /* Only a "sym - ." difference is PC-relative */ + if (sub->sym->sec !=3D rsec->base || + sub->sym->offset + reloc_addend(sub) !=3D reloc_offset(sub)) + return 0; + + set_reloc_type(elf, reloc, pcrel_type); + return 0; +} + bool arch_pc_relative_reloc(struct reloc *reloc) { return false; diff --git a/tools/objtool/arch/loongarch/include/arch/elf.h b/tools/objtoo= l/arch/loongarch/include/arch/elf.h index ec79062c9554..0103f27fccfc 100644 --- a/tools/objtool/arch/loongarch/include/arch/elf.h +++ b/tools/objtool/arch/loongarch/include/arch/elf.h @@ -15,6 +15,18 @@ #ifndef R_LARCH_64 #define R_LARCH_64 2 #endif +#ifndef R_LARCH_ADD32 +#define R_LARCH_ADD32 50 +#endif +#ifndef R_LARCH_ADD64 +#define R_LARCH_ADD64 51 +#endif +#ifndef R_LARCH_SUB32 +#define R_LARCH_SUB32 55 +#endif +#ifndef R_LARCH_SUB64 +#define R_LARCH_SUB64 56 +#endif #ifndef R_LARCH_32_PCREL #define R_LARCH_32_PCREL 99 #endif @@ -34,4 +46,10 @@ #define R_TEXT32 R_LARCH_32_PCREL #define R_TEXT64 R_LARCH_32_PCREL =20 +#define ARCH_HAS_PAIRED_RELOCS 1 + +struct elf; +struct reloc; +int arch_normalize_paired_reloc(struct elf *elf, struct reloc *reloc); + #endif /* _OBJTOOL_ARCH_ELF_H */ diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index a952e680e8a6..92cf0fc3ff2f 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1518,6 +1518,13 @@ static bool is_uncorrelated_section(struct section *= sec) strstarts(sec->name, ".data..Lanon."); /* Clang */ } =20 +#ifndef ARCH_HAS_PAIRED_RELOCS +static inline int arch_normalize_paired_reloc(struct elf *elf, struct relo= c *reloc) +{ + return 0; +} +#endif + /* * Convert a relocation symbol reference to the needed format: either a se= ction * symbol or the underlying symbol itself. Return -1 error, 0 success, 1 = skip. @@ -1525,10 +1532,16 @@ static bool is_uncorrelated_section(struct section = *sec) static int convert_reloc_sym(struct elf *elf, struct reloc *reloc) { struct section *sec =3D reloc->sym->sec; + int ret; =20 if (reloc_type(reloc) =3D=3D R_NONE) return 1; =20 + /* Fold paired ADD/SUB relocs (LoongArch) into a single PCREL */ + ret =3D arch_normalize_paired_reloc(elf, reloc); + if (ret) + return ret; + if (is_uncorrelated_section(sec)) return convert_reloc_sym_to_secsym(elf, reloc); =20 --=20 2.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 4148C341ABB for ; Fri, 24 Jul 2026 11:45:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893540; cv=none; b=BCS5xd0HdFcyBOPPsVZkpabBNltqN2p3dMMg5jCvI2FJs/fmedoT1zQyia3YgByNuWGm1QW+nAiGsIoYbl8qHZTex+MbWFJp66PLQdESuTm2ncmYLS9u6lz1grlkYFygO0t9c7k5zlyY9IDglx6WjEoyKtcMcaJMpd8RzqDKC/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893540; c=relaxed/simple; bh=+EwcJGyjyyjcMkO5A9AdRmuju22Ek3rMbdBo+iANy7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oBBWEuWwHzCgNme7oluB1JRMEqtgmk/aK/uUt8UthmuhK25ikJ0wTKwsVq7KU4HEt8LXT7LuqZ7bbG01GsXDUqHgtoULc1y072BT+Hg+8YBBQ7ElmRHF1gg86JW7c42MANmlaaXoLb9BAt0KF6hcfqIPOrEr+bRjMAV93Hrts9w= 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=r9MfNsHR; arc=none smtp.client-ip=91.218.175.185 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="r9MfNsHR" 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=1784893536; 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=18qWUBFyGokEbNhqKGAmxikEqxfS9peDgddO3aKzKXI=; b=r9MfNsHRhsBDq6cWq1zcTg9PYKqeMeK1ZHXHQis0l1F7aVefvkXlyphPGW4VGon19odeLH WTSubANUtPohjXeAxDNhIzXNpeNGSUn+9BbRbjvas+J0YhsKDmDnAP1t2ZE4TOntL0Khz5 GsEQ0XurjW8QgSz3s9yBSUBpMW+d1vM= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 12/14] objtool/LoongArch: Enable inline alternative cloning for KLP Date: Fri, 24 Jul 2026 19:41:25 +0800 Message-ID: <20260724114128.31451-13-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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 An ALTERNATIVE() emits its replacement instructions into a .subsection 1 placed after the patched function. When objtool clones the function into a livepatch module, clone_inline_alternatives() clones that replacement block too, but only for architectures that define ARCH_HAS_INLINE_ALTS. LoongArch uses the same .subsection layout as arm64, and its alternative macros now mark the replacement with ANNOTATE_DATA_SPECIAL (see "LoongArch: Mark special sections for KLP support"). Define ARCH_HAS_INLINE_ALTS so the replacement is cloned; otherwise a livepatch for a function containing an ALTERNATIVE() fails to build with "can't find new instruction". Reproduced by building a livepatch for a function containing an ALTERNATIVE() (the base-vmlinux test). Link: https://lore.kernel.org/all/ak7QBSm3mmDlB-4u@redhat.com Reported-by: Joe Lawrence Signed-off-by: George Guo --- tools/objtool/arch/loongarch/include/arch/elf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/objtool/arch/loongarch/include/arch/elf.h b/tools/objtoo= l/arch/loongarch/include/arch/elf.h index 0103f27fccfc..e2843679f24e 100644 --- a/tools/objtool/arch/loongarch/include/arch/elf.h +++ b/tools/objtool/arch/loongarch/include/arch/elf.h @@ -46,6 +46,7 @@ #define R_TEXT32 R_LARCH_32_PCREL #define R_TEXT64 R_LARCH_32_PCREL =20 +#define ARCH_HAS_INLINE_ALTS 1 #define ARCH_HAS_PAIRED_RELOCS 1 =20 struct elf; --=20 2.53.0 From nobody Fri Jul 24 21:29:03 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 AA154346E75 for ; Fri, 24 Jul 2026 11:45:43 +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=1784893545; cv=none; b=jUtGEIeTTvBQx9Lo4cHyXADSWvQHxwANILW2UGrOpHOPsllowTvVCfdOGzNaQBaCBeAeVLOEZaxxy+EKJSnPay7xgUUYLc+DkF/luVm1IVaRreIZ3sRj6u4h3zFknocXTg5rHS552OmI+t47HzwoGb5HMmwiLloejTJAB7wxvlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893545; c=relaxed/simple; bh=16rzf+qzWNXObKuK83MOC2na7VFzAB9eGdvs8zN80YM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fttL++urweF2adOivD0ySm5G8oLQEwG5vYHUCv6ZX6x2PhlADz8xbZnQLwkgebViY46RmeEm9L2z5ZdfClIlukYZgDpoQk+ISl0s3O7iyJUDziBVfafoeSYHXUeLGWZFWuLBEUVg8fw6p3NnpuPqMcqpUlMNWwk3AmVE/9+xeVo= 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=eEMnYHAy; 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="eEMnYHAy" 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=1784893541; 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=wgzBqynfoZaxFoS1KfD08vyQRws3QN+VgwIwrElk/Ts=; b=eEMnYHAyZAMi3vx73G3SFKcesdVsn0xu9Wfqj3DwfvCGeXAKvIrmiEapK5YLQLi0myYaRu mYDZKkstdpWgumyWdlOpvw2gF5Z9ab6PdmHzElEyWN3IWrvnBVZ3KV9I+Y4gxdY0hEa8gy 3594ymNp0/DY6uVRHppxMhkyF/k2+68= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 13/14] objtool/klp: Keep LoongArch tablejump annotation table entries Date: Fri, 24 Jul 2026 19:41:26 +0800 Message-ID: <20260724114128.31451-14-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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 With -mannotate-tablejump, LoongArch compilers emit a .discard.tablejump_annotate section. Each entry is a pair of 8-byte words: the address of a jump instruction and the address of its jump table. objtool reads these pairs to find switch jump tables when decoding. klp-diff creates one fake symbol per 8-byte word and clones a word only if should_keep_special_sym() accepts it. The default rule keeps a word only if it references a function that was cloned into the output module. The instruction-side word references the function and is kept. The table-side word references the jump table via its .rodata section symbol, which is not a function symbol, so it is dropped. The cloned annotate section then holds only instruction-side words, compacted together. The pairing is destroyed. Parsing the malformed section crashes objtool on the patch module and no .ko is produced: Building patch module: livepatch-shadow-newpid.ko livepatch-shadow-newpid.o: error: SIGSEGV: objtool crash! Keep all .discard.tablejump_annotate words whose referenced symbol has been cloned. Reproduced with the shadow-newpid test, which patches proc_pid_status(). That function contains two switch jump tables. Before, klp-diff clones only the instruction-side words: DEBUG: vmlinux.o: _discard_tablejump_annotate_57441 [+DATA] DEBUG: vmlinux.o: .discard.tablejump_annotate+0x0: proc_pid_statu= s+0xc70 [FUNC GLOBAL] DEBUG: vmlinux.o: _discard_tablejump_annotate_57443 [+DATA] DEBUG: vmlinux.o: .discard.tablejump_annotate+0x8: proc_pid_statu= s+0xd2c [FUNC GLOBAL] After, the full pairs are kept, including the .rodata table words: DEBUG: vmlinux.o: _discard_tablejump_annotate_57441 [+DATA] DEBUG: vmlinux.o: .discard.tablejump_annotate+0x0: proc_pid_statu= s+0xc70 [FUNC GLOBAL] DEBUG: vmlinux.o: _discard_tablejump_annotate_57442 [+DATA] DEBUG: vmlinux.o: .discard.tablejump_annotate+0x8: .rodata.proc_p= id_status+0x0 [SECTION] DEBUG: vmlinux.o: _discard_tablejump_annotate_57443 [+DATA] DEBUG: vmlinux.o: .discard.tablejump_annotate+0x10: proc_pid_stat= us+0xd2c [FUNC GLOBAL] DEBUG: vmlinux.o: _discard_tablejump_annotate_57444 [+DATA] DEBUG: vmlinux.o: .discard.tablejump_annotate+0x18: .rodata.proc_= pid_status+0x80 [SECTION] and the patch module builds. Co-developed-by: Kexin Liu Signed-off-by: Kexin Liu Signed-off-by: George Guo --- tools/objtool/klp-diff.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index 92cf0fc3ff2f..f151ffc71184 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1956,6 +1956,7 @@ static int create_fake_symbols(struct elf *elf) static bool should_keep_special_sym(struct elf *elf, struct symbol *sym) { bool annotate_insn =3D !strcmp(sym->sec->name, ".discard.annotate_insn"); + bool tablejump_annotate =3D !strcmp(sym->sec->name, ".discard.tablejump_a= nnotate"); struct reloc *reloc; =20 if (is_sec_sym(sym) || !sym->sec->rsec) @@ -1968,6 +1969,16 @@ static bool should_keep_special_sym(struct elf *elf,= struct symbol *sym) if (!reloc->sym->clone || is_undef_sym(reloc->sym->clone)) continue; =20 + /* + * .discard.tablejump_annotate (LoongArch -mannotate-tablejump) + * holds pairs of words: a jump instruction and its jump table. + * The table word references the table via its .rodata section + * symbol, which the is_func_sym() rule below would drop, + * breaking the pairing. Keep both words of each entry. + */ + if (tablejump_annotate) + return true; + /* * Keep special section references to cloned functions. * In some cases annotate_insn can also reference cloned alt --=20 2.53.0 From nobody Fri Jul 24 21:29:03 2026 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 7F6883DEAC6 for ; Fri, 24 Jul 2026 11:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893552; cv=none; b=tuAHRiKTbKUv1cCp1reEbWooNifVpjbkztHVjWswuSEV+JoBAffCNqIFiBpn+LPEPIgGYBRfMO/E3qemE7BSAs60Zep85Tl5xv7WYjMT46almsvOWmTXX07kVL9yNibPOCX1BGHQz3dy9d3YT/+9hOnJq/p643wi8vz2X/T7bDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784893552; c=relaxed/simple; bh=bMdIMN3HQu5vLCUuxN14UQxRrmpE/mPqNXKEvoYv2tA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C4ZHoKtF2ppgfMXkSKp3UvMePi9wcBEkPSDCSFwYqJTn/a4AxZEcPe/7ESoqd5yvV3GJEOgMOx8417azmITmYlqukZBuXiUz4NZflTsaewyrjZoR97A4XK+aojY5GsKAc+Bh6VlAiaL4XuSFvkwHXrpGvdpg1nhRZW7MCdYITU0= 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=ak7Lvi6Z; arc=none smtp.client-ip=91.218.175.189 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="ak7Lvi6Z" 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=1784893546; 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=LIo2KtyLunyD7pJOq9hd/zxxpBKhcVHigJ3J1NZnnHA=; b=ak7Lvi6ZviCnhDVhkWQJVAhooQLajLD1k22QrQZy/zbqs+vgEc0THLZgOWgwNZyL8ciR3Q gyJSbMhYMAVzGH2mFuGXiA7+KBq3eIHJBPx1dJeiz6sR3YiGUpfPh+yQjL0kQmA9e0cal4 2HEWi5X3eZhP005mtgIC2SpCRmUJJw0= 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, wangrui@loongson.cn, liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io, loongarch@lists.linux.dev, live-patching@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 14/14] objtool/klp: Rewrite PC-relative data references to GOT on LoongArch Date: Fri, 24 Jul 2026 19:41:27 +0800 Message-ID: <20260724114128.31451-15-dongtai.guo@linux.dev> In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev> References: <20260724114128.31451-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 A livepatch module is mapped far more than the +-2GB reachable by a pcalau12i/addi.d pair, so a klp relocation that resolves to a symbol in vmlinux cannot be reached PC-relatively: the relocation overflows and the patched function computes a wild pointer. Far calls are already handled by the module loader, which redirects them through a PLT stub, but there is no such indirection for data, whose address is materialized inline. Compilers emit the direct PC-relative form for any symbol they consider local. In particular file-local 'static' data is never interposable, so -fPIC does not route it through the GOT. This is correct for vmlinux and for ordinary modules; it only breaks once klp-diff extracts the function into the far livepatch module while its data stays behind. It is not Clang-specific: GCC emits the same PC-relative form. Add an arch hook, arch_klp_convert_reloc_to_got(), invoked when a klp relocation is created, and implement it for LoongArch: rewrite the reference to its GOT-indirect equivalent, which loads the full 64-bit address from a GOT slot the module loader fills in: pcalau12i rd, %pc_hi20(sym) -> pcalau12i rd, %got_pc_hi20(sym) addi.d rd, rj, %pc_lo12(sym) -> ld.d rd, rj, %got_pc_lo12(sym) The loader already sizes the module GOT from every SHT_RELA section that targets executable code, including .klp.rela.*, so the slot is reserved at load time and filled when the patch is enabled. Only an adjacent, register-consistent pcalau12i/addi.d pair that materializes an address can be converted. A PCALA_LO12 on any other instruction is a load or store that reads the symbol directly; going through the GOT there needs an extra instruction to dereference the slot, and the function cannot grow without shifting every offset, relocation and ORC entry. A pcalau12i shared by several addi.d with different addends would likewise need one GOT slot per addend, which a single GOT_PC_HI20 cannot express. Reject both rather than emit a livepatch that is quietly broken. The LoongArch decoder in tools/ lacks the reg1i20 instruction format used to identify pcalau12i; add it to the tools/ copy of asm/inst.h. Reproduced by a livepatch for proc_pid_status() (the shadow-newpid test), which reads the file-local task_state_array[]. Signed-off-by: George Guo --- tools/arch/loongarch/include/asm/inst.h | 11 ++ tools/objtool/arch/loongarch/decode.c | 104 ++++++++++++++++++ .../objtool/arch/loongarch/include/arch/elf.h | 16 +++ tools/objtool/klp-diff.c | 23 +++- 4 files changed, 152 insertions(+), 2 deletions(-) diff --git a/tools/arch/loongarch/include/asm/inst.h b/tools/arch/loongarch= /include/asm/inst.h index d68fad63c8b7..0d4caa6522f1 100644 --- a/tools/arch/loongarch/include/asm/inst.h +++ b/tools/arch/loongarch/include/asm/inst.h @@ -25,6 +25,10 @@ enum reg1i21_op { bcnez_op =3D 0x12, /* bits[9:8] =3D 0x01 */ }; =20 +enum reg1i20_op { + pcalau12i_op =3D 0x0d, +}; + enum reg2_op { ertn_op =3D 0x1920e, }; @@ -66,6 +70,12 @@ struct reg0i26_format { unsigned int opcode : 6; }; =20 +struct reg1i20_format { + unsigned int rd : 5; + unsigned int immediate : 20; + unsigned int opcode : 7; +}; + struct reg1i21_format { unsigned int immediate_h : 5; unsigned int rj : 5; @@ -111,6 +121,7 @@ union loongarch_instruction { unsigned int word; struct reg0i15_format reg0i15_format; struct reg0i26_format reg0i26_format; + struct reg1i20_format reg1i20_format; struct reg1i21_format reg1i21_format; struct reg2_format reg2_format; struct reg2i12_format reg2i12_format; diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 273398ea4486..99765b13058c 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -101,6 +101,110 @@ int arch_normalize_paired_reloc(struct elf *elf, stru= ct reloc *reloc) return 0; } =20 +static bool klp_read_insn(struct section *sec, unsigned long offset, + union loongarch_instruction *insn) +{ + if (offset + sizeof(*insn) > sec_size(sec)) + return false; + + memcpy(insn, sec->data->d_buf + offset, sizeof(*insn)); + return true; +} + +/* + * A livepatch module is mapped far more than the +-2GB reachable by + * pcalau12i/addi.d, so a klp reloc which resolves to a symbol in vmlinux = cannot + * be reached PC-relatively: the relocation overflows and the patched func= tion + * computes a wild pointer. Far calls are already handled by the module l= oader, + * which redirects them through a PLT stub, but there is no such indirecti= on for + * data: the address is materialized inline. + * + * Compilers emit the direct PC-relative form for any symbol they consider= local + * (in particular file-local 'static' data, which is never interposable, so + * -fPIC does not route it through the GOT). This is correct for vmlinux = and + * for ordinary modules; it only breaks once klp-diff extracts the functio= n into + * a far away livepatch module while its data stays behind. + * + * Convert the reference to its GOT-indirect equivalent, which loads the f= ull + * 64-bit address from a GOT slot the module loader fills in and so works = at any + * distance: + * + * pcalau12i rd, %pc_hi20(sym) -> pcalau12i rd, %got_pc_hi20(sym) + * addi.d rd, rj, %pc_lo12(sym) -> ld.d rd, rj, %got_pc_lo12(sym) + * + * Only an adjacent pcalau12i/addi.d pair which materializes an address ca= n be + * converted, and only that exact shape is accepted: + * + * - A PCALA_LO12 on anything but addi.d is a load or store reading the s= ymbol + * directly. Going through the GOT would need an extra instruction to + * dereference the slot, and the function cannot grow without shifting = every + * offset, relocation and ORC entry. + * + * - The pair must be adjacent and register-consistent. If one pcalau12i= is + * shared by several addi.d with different addends, each needs its own = GOT + * slot, but the single GOT_PC_HI20 only spans one page: the result wou= ld be + * correct only if those slots happened to share a page. Requiring + * adjacency rejects that (the second addi.d is not preceded by a pcala= u12i), + * as well as a pair the compiler scheduled apart. + * + * Bail out on anything else instead of emitting a livepatch which is quie= tly + * broken. + */ +int arch_klp_convert_reloc_to_got(struct elf *elf, struct section *sec, + unsigned long offset, unsigned int *type) +{ + union loongarch_instruction hi, lo; + unsigned long hi_offset, lo_offset; + + switch (*type) { + case R_LARCH_PCALA_HI20: + hi_offset =3D offset; + lo_offset =3D offset + LOONGARCH_INSN_SIZE; + break; + + case R_LARCH_PCALA_LO12: + if (offset < LOONGARCH_INSN_SIZE) { + ERROR("%s+0x%lx: PCALA_LO12 with no preceding instruction", + sec->name, offset); + return -1; + } + hi_offset =3D offset - LOONGARCH_INSN_SIZE; + lo_offset =3D offset; + break; + + default: + return 0; + } + + if (!klp_read_insn(sec, hi_offset, &hi) || + !klp_read_insn(sec, lo_offset, &lo)) { + ERROR("%s+0x%lx: PCALA pair runs past end of section", + sec->name, offset); + return -1; + } + + if (hi.reg1i20_format.opcode !=3D pcalau12i_op || + lo.reg2i12_format.opcode !=3D addid_op || + lo.reg2i12_format.rj !=3D hi.reg1i20_format.rd) { + ERROR("%s+0x%lx: cannot make klp reference GOT-indirect: expected an adj= acent pcalau12i/addi.d pair, found 0x%08x/0x%08x", + sec->name, offset, hi.word, lo.word); + return -1; + } + + if (*type =3D=3D R_LARCH_PCALA_HI20) { + *type =3D R_LARCH_GOT_PC_HI20; + return 0; + } + + /* addi.d rd, rj, %pc_lo12(sym) -> ld.d rd, rj, %got_pc_lo12(sym) */ + lo.reg2i12_format.opcode =3D ldd_op; + if (elf_write_insn(elf, sec, lo_offset, sizeof(lo), (const char *)&lo)) + return -1; + + *type =3D R_LARCH_GOT_PC_LO12; + return 0; +} + bool arch_pc_relative_reloc(struct reloc *reloc) { return false; diff --git a/tools/objtool/arch/loongarch/include/arch/elf.h b/tools/objtoo= l/arch/loongarch/include/arch/elf.h index e2843679f24e..7a97cf69dc86 100644 --- a/tools/objtool/arch/loongarch/include/arch/elf.h +++ b/tools/objtool/arch/loongarch/include/arch/elf.h @@ -27,6 +27,18 @@ #ifndef R_LARCH_SUB64 #define R_LARCH_SUB64 56 #endif +#ifndef R_LARCH_PCALA_HI20 +#define R_LARCH_PCALA_HI20 71 +#endif +#ifndef R_LARCH_PCALA_LO12 +#define R_LARCH_PCALA_LO12 72 +#endif +#ifndef R_LARCH_GOT_PC_HI20 +#define R_LARCH_GOT_PC_HI20 75 +#endif +#ifndef R_LARCH_GOT_PC_LO12 +#define R_LARCH_GOT_PC_LO12 76 +#endif #ifndef R_LARCH_32_PCREL #define R_LARCH_32_PCREL 99 #endif @@ -48,9 +60,13 @@ =20 #define ARCH_HAS_INLINE_ALTS 1 #define ARCH_HAS_PAIRED_RELOCS 1 +#define ARCH_HAS_KLP_GOT_RELOCS 1 =20 struct elf; struct reloc; +struct section; int arch_normalize_paired_reloc(struct elf *elf, struct reloc *reloc); +int arch_klp_convert_reloc_to_got(struct elf *elf, struct section *sec, + unsigned long offset, unsigned int *type); =20 #endif /* _OBJTOOL_ARCH_ELF_H */ diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index f151ffc71184..1538f8f92f1f 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1525,6 +1525,14 @@ static inline int arch_normalize_paired_reloc(struct= elf *elf, struct reloc *rel } #endif =20 +#ifndef ARCH_HAS_KLP_GOT_RELOCS +static inline int arch_klp_convert_reloc_to_got(struct elf *elf, struct se= ction *sec, + unsigned long offset, unsigned int *type) +{ + return 0; +} +#endif + /* * Convert a relocation symbol reference to the needed format: either a se= ction * symbol or the underlying symbol itself. Return -1 error, 0 success, 1 = skip. @@ -1565,12 +1573,23 @@ static int clone_reloc_klp(struct elfs *e, struct r= eloc *patched_reloc, char sym_name[SYM_NAME_LEN]; struct klp_reloc klp_reloc; unsigned long sympos; + unsigned int type; =20 if (!patched_sym->twin) { ERROR("unexpected klp reloc for new symbol %s", patched_sym->name); return -1; } =20 + /* + * This reference resolves to a symbol which stays in the patched + * object, arbitrarily far from the livepatch module. Give the arch a + * chance to convert a PC-relative reference into an indirect one which + * can reach it (LoongArch: PCALA -> GOT). + */ + type =3D reloc_type(patched_reloc); + if (arch_klp_convert_reloc_to_got(e->out, sec, offset, &type)) + return -1; + /* * Keep the original reloc intact for now to avoid breaking objtool run * which relies on proper relocations for many of its features. This @@ -1591,7 +1610,7 @@ static int clone_reloc_klp(struct elfs *e, struct rel= oc *patched_reloc, sym->clone =3D patched_sym; } =20 - if (!elf_create_reloc(e->out, sec, offset, sym, addend, reloc_type(patche= d_reloc))) + if (!elf_create_reloc(e->out, sec, offset, sym, addend, type)) return -1; =20 /* @@ -1648,7 +1667,7 @@ static int clone_reloc_klp(struct elfs *e, struct rel= oc *patched_reloc, klp_reloc_off =3D sec_size(klp_relocs); memset(&klp_reloc, 0, sizeof(klp_reloc)); =20 - klp_reloc.type =3D reloc_type(patched_reloc); + klp_reloc.type =3D type; if (!elf_add_data(e->out, klp_relocs, &klp_reloc, sizeof(klp_reloc), true= )) return -1; =20 --=20 2.53.0