From nobody Wed Feb 11 12:08:36 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEDF4C77B7D for ; Wed, 10 May 2023 09:16:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236259AbjEJJQ5 (ORCPT ); Wed, 10 May 2023 05:16:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231486AbjEJJQx (ORCPT ); Wed, 10 May 2023 05:16:53 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A545CBF; Wed, 10 May 2023 02:16:48 -0700 (PDT) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxW+r_YFtkWk4HAA--.12277S3; Wed, 10 May 2023 17:16:47 +0800 (CST) Received: from bogon.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxKL3+YFtk7N5TAA--.18920S2; Wed, 10 May 2023 17:16:47 +0800 (CST) From: Youling Tang To: Huacai Chen Cc: Jonathan Corbet , Peter Zijlstra , Josh Poimboeuf , Jason Baron , WANG Xuerui , Zhangjin Wu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev Subject: [PATCH v2] LoongArch: Add jump-label implementation Date: Wed, 10 May 2023 17:16:46 +0800 Message-Id: <1683710206-23905-1-git-send-email-tangyouling@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf8BxKL3+YFtk7N5TAA--.18920S2 X-CM-SenderInfo: 5wdqw5prxox03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxGF1rZw4fAFW7J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IdaVFxhVjvjDU0xZFpf9x07j5o7tUUUUU= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add jump-label implementation based on the ARM64 version. Signed-off-by: Youling Tang Acked-by: Peter Zijlstra (Intel) --- Changes in v2: - Fix build errors. - fix comment. .../core/jump-labels/arch-support.txt | 2 +- arch/loongarch/Kconfig | 2 + arch/loongarch/configs/loongson3_defconfig | 1 + arch/loongarch/include/asm/jump_label.h | 51 +++++++++++++++++++ arch/loongarch/kernel/Makefile | 2 + arch/loongarch/kernel/jump_label.c | 23 +++++++++ 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 arch/loongarch/include/asm/jump_label.h create mode 100644 arch/loongarch/kernel/jump_label.c diff --git a/Documentation/features/core/jump-labels/arch-support.txt b/Doc= umentation/features/core/jump-labels/arch-support.txt index 2328eada3a49..94d9dece580f 100644 --- a/Documentation/features/core/jump-labels/arch-support.txt +++ b/Documentation/features/core/jump-labels/arch-support.txt @@ -13,7 +13,7 @@ | csky: | ok | | hexagon: | TODO | | ia64: | TODO | - | loongarch: | TODO | + | loongarch: | ok | | m68k: | TODO | | microblaze: | TODO | | mips: | ok | diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index d38b066fc931..193a959a5611 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -83,6 +83,8 @@ config LOONGARCH select GPIOLIB select HAS_IOPORT select HAVE_ARCH_AUDITSYSCALL + select HAVE_ARCH_JUMP_LABEL + select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_MMAP_RND_BITS if MMU select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOK diff --git a/arch/loongarch/configs/loongson3_defconfig b/arch/loongarch/co= nfigs/loongson3_defconfig index 6cd26dd3c134..33a0f5f742f6 100644 --- a/arch/loongarch/configs/loongson3_defconfig +++ b/arch/loongarch/configs/loongson3_defconfig @@ -63,6 +63,7 @@ CONFIG_EFI_ZBOOT=3Dy CONFIG_EFI_GENERIC_STUB_INITRD_CMDLINE_LOADER=3Dy CONFIG_EFI_CAPSULE_LOADER=3Dm CONFIG_EFI_TEST=3Dm +CONFIG_JUMP_LABEL=3Dy CONFIG_MODULES=3Dy CONFIG_MODULE_FORCE_LOAD=3Dy CONFIG_MODULE_UNLOAD=3Dy diff --git a/arch/loongarch/include/asm/jump_label.h b/arch/loongarch/inclu= de/asm/jump_label.h new file mode 100644 index 000000000000..2f9fdec256c5 --- /dev/null +++ b/arch/loongarch/include/asm/jump_label.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 Loongson Technology Corporation Limited + * + * Based on arch/arm64/include/asm/jump_label.h + */ +#ifndef __ASM_JUMP_LABEL_H +#define __ASM_JUMP_LABEL_H + +#ifndef __ASSEMBLY__ + +#include + +#define JUMP_LABEL_NOP_SIZE 4 + +static __always_inline bool arch_static_branch(struct static_key * const k= ey, + const bool branch) +{ + asm_volatile_goto( + "1: nop \n\t" + " .pushsection __jump_table, \"aw\" \n\t" + " .align 3 \n\t" + " .long 1b - ., %l[l_yes] - . \n\t" + " .quad %0 - . \n\t" + " .popsection \n\t" + : : "i"(&((char *)key)[branch]) : : l_yes); + + return false; +l_yes: + return true; +} + +static __always_inline bool arch_static_branch_jump(struct static_key * co= nst key, + const bool branch) +{ + asm_volatile_goto( + "1: b %l[l_yes] \n\t" + " .pushsection __jump_table, \"aw\" \n\t" + " .align 3 \n\t" + " .long 1b - ., %l[l_yes] - . \n\t" + " .quad %0 - . \n\t" + " .popsection \n\t" + : : "i"(&((char *)key)[branch]) : : l_yes); + + return false; +l_yes: + return true; +} + +#endif /* __ASSEMBLY__ */ +#endif /* __ASM_JUMP_LABEL_H */ diff --git a/arch/loongarch/kernel/Makefile b/arch/loongarch/kernel/Makefile index 9a72d91cd104..64ea76f60e2c 100644 --- a/arch/loongarch/kernel/Makefile +++ b/arch/loongarch/kernel/Makefile @@ -54,4 +54,6 @@ obj-$(CONFIG_HAVE_HW_BREAKPOINT) +=3D hw_breakpoint.o =20 obj-$(CONFIG_KPROBES) +=3D kprobes.o kprobes_trampoline.o =20 +obj-$(CONFIG_JUMP_LABEL) +=3D jump_label.o + CPPFLAGS_vmlinux.lds :=3D $(KBUILD_CFLAGS) diff --git a/arch/loongarch/kernel/jump_label.c b/arch/loongarch/kernel/jum= p_label.c new file mode 100644 index 000000000000..b06245955f7a --- /dev/null +++ b/arch/loongarch/kernel/jump_label.c @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Loongson Technology Corporation Limited + * + * Based on arch/arm64/kernel/jump_label.c + */ +#include +#include +#include + +void arch_jump_label_transform(struct jump_entry *entry, + enum jump_label_type type) +{ + void *addr =3D (void *)jump_entry_code(entry); + u32 insn; + + if (type =3D=3D JUMP_LABEL_JMP) + insn =3D larch_insn_gen_b(jump_entry_code(entry), jump_entry_target(entr= y)); + else + insn =3D larch_insn_gen_nop(); + + larch_insn_patch_text(addr, insn); +} --=20 2.37.1