[PATCH] LoongArch: Add klp-build support for live patching

WangYuli posted 1 patch 2 weeks, 2 days ago
arch/loongarch/Kconfig                | 1 +
tools/objtool/Makefile                | 3 ++-
tools/objtool/arch/loongarch/decode.c | 5 +++++
3 files changed, 8 insertions(+), 1 deletion(-)
[PATCH] LoongArch: Add klp-build support for live patching
Posted by WangYuli 2 weeks, 2 days ago
From: WangYuli <wangyl5933@chinaunicom.cn>

Add klp-build support for the LoongArch architecture, enabling
automated live patch module generation using objtool.

Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
---
 arch/loongarch/Kconfig                | 1 +
 tools/objtool/Makefile                | 3 ++-
 tools/objtool/arch/loongarch/decode.c | 5 +++++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index 1a0a5f9def33..7b5f2a329908 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -159,6 +159,7 @@ config LOONGARCH
 	select HAVE_KPROBES
 	select HAVE_KPROBES_ON_FTRACE
 	select HAVE_KRETPROBES
+	select HAVE_KLP_BUILD
 	select HAVE_LIVEPATCH
 	select HAVE_MOD_ARCH_SPECIFIC
 	select HAVE_NMI
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index ad6e1ec706ce..cead37c25a69 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -8,7 +8,8 @@ ifeq ($(SRCARCH),x86)
 endif
 
 ifeq ($(SRCARCH),loongarch)
-	BUILD_ORC	   := y
+	BUILD_ORC    := y
+	ARCH_HAS_KLP := y
 endif
 
 ifeq ($(ARCH_HAS_KLP),y)
diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loongarch/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);
 }
 
+u64 arch_adjusted_addend(struct reloc *reloc)
+{
+	return reloc_addend(reloc);
+}
+
 bool arch_pc_relative_reloc(struct reloc *reloc)
 {
 	return false;
-- 
2.51.0
Re: [PATCH] LoongArch: Add klp-build support for live patching
Posted by Huacai Chen 2 weeks, 2 days ago
Hi, Yuli,

On Wed, Dec 3, 2025 at 5:11 PM WangYuli <wangyuli@aosc.io> wrote:
>
> From: WangYuli <wangyl5933@chinaunicom.cn>
>
> Add klp-build support for the LoongArch architecture, enabling
> automated live patch module generation using objtool.
Have you verified the functions?

Huacai

>
> Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
> ---
>  arch/loongarch/Kconfig                | 1 +
>  tools/objtool/Makefile                | 3 ++-
>  tools/objtool/arch/loongarch/decode.c | 5 +++++
>  3 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
> index 1a0a5f9def33..7b5f2a329908 100644
> --- a/arch/loongarch/Kconfig
> +++ b/arch/loongarch/Kconfig
> @@ -159,6 +159,7 @@ config LOONGARCH
>         select HAVE_KPROBES
>         select HAVE_KPROBES_ON_FTRACE
>         select HAVE_KRETPROBES
> +       select HAVE_KLP_BUILD
>         select HAVE_LIVEPATCH
>         select HAVE_MOD_ARCH_SPECIFIC
>         select HAVE_NMI
> diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
> index ad6e1ec706ce..cead37c25a69 100644
> --- a/tools/objtool/Makefile
> +++ b/tools/objtool/Makefile
> @@ -8,7 +8,8 @@ ifeq ($(SRCARCH),x86)
>  endif
>
>  ifeq ($(SRCARCH),loongarch)
> -       BUILD_ORC          := y
> +       BUILD_ORC    := y
> +       ARCH_HAS_KLP := y
>  endif
>
>  ifeq ($(ARCH_HAS_KLP),y)
> diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loongarch/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);
>  }
>
> +u64 arch_adjusted_addend(struct reloc *reloc)
> +{
> +       return reloc_addend(reloc);
> +}
> +
>  bool arch_pc_relative_reloc(struct reloc *reloc)
>  {
>         return false;
> --
> 2.51.0
>