2023-05-09 08:08:25

by Youling Tang

[permalink] [raw]
Subject: [PATCH] LoongArch: Add jump-label implementation

Add jump-label implementation based on the ARM64 version.

Signed-off-by: Youling Tang <[email protected]>
---
.../core/jump-labels/arch-support.txt | 2 +-
arch/loongarch/Kconfig | 2 +
arch/loongarch/configs/loongson3_defconfig | 1 +
arch/loongarch/include/asm/jump_label.h | 52 +++++++++++++++++++
arch/loongarch/kernel/Makefile | 2 +
arch/loongarch/kernel/jump_label.c | 23 ++++++++
6 files changed, 81 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/Documentation/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/configs/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=y
CONFIG_EFI_GENERIC_STUB_INITRD_CMDLINE_LOADER=y
CONFIG_EFI_CAPSULE_LOADER=m
CONFIG_EFI_TEST=m
+CONFIG_JUMP_LABEL=y
CONFIG_MODULES=y
CONFIG_MODULE_FORCE_LOAD=y
CONFIG_MODULE_UNLOAD=y
diff --git a/arch/loongarch/include/asm/jump_label.h b/arch/loongarch/include/asm/jump_label.h
new file mode 100644
index 000000000000..453a0cd3ddf0
--- /dev/null
+++ b/arch/loongarch/include/asm/jump_label.h
@@ -0,0 +1,52 @@
+/* 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 <linux/types.h>
+#include <asm/inst.h>
+
+#define JUMP_LABEL_NOP_SIZE LOONGARCH_INSN_SIZE
+
+static __always_inline bool arch_static_branch(struct static_key * const key,
+ 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 * const 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) += hw_breakpoint.o

obj-$(CONFIG_KPROBES) += kprobes.o kprobes_trampoline.o

+obj-$(CONFIG_JUMP_LABEL) += jump_label.o
+
CPPFLAGS_vmlinux.lds := $(KBUILD_CFLAGS)
diff --git a/arch/loongarch/kernel/jump_label.c b/arch/loongarch/kernel/jump_label.c
new file mode 100644
index 000000000000..c3ebaa4cf1e5
--- /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/include/asm/jump_label.h
+ */
+#include <linux/jump_label.h>
+#include <linux/kernel.h>
+#include <asm/inst.h>
+
+void arch_jump_label_transform(struct jump_entry *entry,
+ enum jump_label_type type)
+{
+ void *addr = (void *)jump_entry_code(entry);
+ u32 insn;
+
+ if (type == JUMP_LABEL_JMP)
+ insn = larch_insn_gen_b(jump_entry_code(entry), jump_entry_target(entry));
+ else
+ insn = larch_insn_gen_nop();
+
+ larch_insn_patch_text(addr, insn);
+}
--
2.37.1


2023-05-09 08:10:39

by Youling Tang

[permalink] [raw]
Subject: Re: [PATCH] LoongArch: Add jump-label implementation

On 05/09/2023 03:29 PM, Youling Tang wrote:
> Add jump-label implementation based on the ARM64 version.
>
> Signed-off-by: Youling Tang <[email protected]>
> ---
> .../core/jump-labels/arch-support.txt | 2 +-
> arch/loongarch/Kconfig | 2 +
> arch/loongarch/configs/loongson3_defconfig | 1 +
> arch/loongarch/include/asm/jump_label.h | 52 +++++++++++++++++++
> arch/loongarch/kernel/Makefile | 2 +
> arch/loongarch/kernel/jump_label.c | 23 ++++++++
> 6 files changed, 81 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/Documentation/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/configs/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=y
> CONFIG_EFI_GENERIC_STUB_INITRD_CMDLINE_LOADER=y
> CONFIG_EFI_CAPSULE_LOADER=m
> CONFIG_EFI_TEST=m
> +CONFIG_JUMP_LABEL=y
> CONFIG_MODULES=y
> CONFIG_MODULE_FORCE_LOAD=y
> CONFIG_MODULE_UNLOAD=y
> diff --git a/arch/loongarch/include/asm/jump_label.h b/arch/loongarch/include/asm/jump_label.h
> new file mode 100644
> index 000000000000..453a0cd3ddf0
> --- /dev/null
> +++ b/arch/loongarch/include/asm/jump_label.h
> @@ -0,0 +1,52 @@
> +/* 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 <linux/types.h>
> +#include <asm/inst.h>
> +
> +#define JUMP_LABEL_NOP_SIZE LOONGARCH_INSN_SIZE
> +
> +static __always_inline bool arch_static_branch(struct static_key * const key,
> + 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 * const 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) += hw_breakpoint.o
>
> obj-$(CONFIG_KPROBES) += kprobes.o kprobes_trampoline.o
>
> +obj-$(CONFIG_JUMP_LABEL) += jump_label.o
> +
> CPPFLAGS_vmlinux.lds := $(KBUILD_CFLAGS)
> diff --git a/arch/loongarch/kernel/jump_label.c b/arch/loongarch/kernel/jump_label.c
> new file mode 100644
> index 000000000000..c3ebaa4cf1e5
> --- /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/include/asm/jump_label.h
Sorry, this should be changed to,
Based on arch/arm64/kernel/jump_label.c

> + */
> +#include <linux/jump_label.h>
> +#include <linux/kernel.h>
> +#include <asm/inst.h>
> +
> +void arch_jump_label_transform(struct jump_entry *entry,
> + enum jump_label_type type)
> +{
> + void *addr = (void *)jump_entry_code(entry);
> + u32 insn;
> +
> + if (type == JUMP_LABEL_JMP)
> + insn = larch_insn_gen_b(jump_entry_code(entry), jump_entry_target(entry));
> + else
> + insn = larch_insn_gen_nop();
> +
> + larch_insn_patch_text(addr, insn);
> +}
>

2023-05-09 21:17:23

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] LoongArch: Add jump-label implementation

Hi Youling,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.4-rc1 next-20230509]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Youling-Tang/LoongArch-Add-jump-label-implementation/20230509-153154
base: linus/master
patch link: https://lore.kernel.org/r/1683617390-18015-1-git-send-email-tangyouling%40loongson.cn
patch subject: [PATCH] LoongArch: Add jump-label implementation
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20230510/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/369827734136be509a0c817517fed12548d9c41f
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Youling-Tang/LoongArch-Add-jump-label-implementation/20230509-153154
git checkout 369827734136be509a0c817517fed12548d9c41f
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch prepare

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
In file included from include/linux/cpumask.h:16,
from arch/loongarch/include/asm/processor.h:9,
from arch/loongarch/include/asm/thread_info.h:15,
from arch/loongarch/include/asm/ptrace.h:10,
from arch/loongarch/include/asm/inst.h:10,
from arch/loongarch/include/asm/jump_label.h:13,
from include/linux/jump_label.h:112,
from include/linux/dynamic_debug.h:6,
from include/linux/printk.h:564,
from include/asm-generic/bug.h:22,
from arch/loongarch/include/asm/bug.h:59,
from include/linux/bug.h:5,
from include/linux/fortify-string.h:5,
from include/linux/string.h:254,
from include/linux/uuid.h:11,
from include/linux/mod_devicetable.h:14,
from scripts/mod/devicetable-offsets.c:3:
include/linux/numa.h: In function 'phys_to_target_node':
>> include/linux/numa.h:41:9: error: implicit declaration of function 'pr_info_once' [-Werror=implicit-function-declaration]
41 | pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
| ^~~~~~~~~~~~
include/linux/cpumask.h: In function 'cpu_max_bits_warn':
>> include/linux/cpumask.h:143:9: error: implicit declaration of function 'WARN_ON_ONCE' [-Werror=implicit-function-declaration]
143 | WARN_ON_ONCE(cpu >= bits);
| ^~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:114: scripts/mod/devicetable-offsets.s] Error 1
make[2]: Target 'scripts/mod/' not remade because of errors.
make[1]: *** [Makefile:1286: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:226: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.


vim +/pr_info_once +41 include/linux/numa.h

a927bd6ba952d1 Dan Williams 2020-11-21 29
a927bd6ba952d1 Dan Williams 2020-11-21 30 #ifndef memory_add_physaddr_to_nid
a927bd6ba952d1 Dan Williams 2020-11-21 31 static inline int memory_add_physaddr_to_nid(u64 start)
a927bd6ba952d1 Dan Williams 2020-11-21 32 {
a927bd6ba952d1 Dan Williams 2020-11-21 33 pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
a927bd6ba952d1 Dan Williams 2020-11-21 34 start);
a927bd6ba952d1 Dan Williams 2020-11-21 35 return 0;
a927bd6ba952d1 Dan Williams 2020-11-21 36 }
a927bd6ba952d1 Dan Williams 2020-11-21 37 #endif
a927bd6ba952d1 Dan Williams 2020-11-21 38 #ifndef phys_to_target_node
a927bd6ba952d1 Dan Williams 2020-11-21 39 static inline int phys_to_target_node(u64 start)
a927bd6ba952d1 Dan Williams 2020-11-21 40 {
a927bd6ba952d1 Dan Williams 2020-11-21 @41 pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
a927bd6ba952d1 Dan Williams 2020-11-21 42 start);
a927bd6ba952d1 Dan Williams 2020-11-21 43 return 0;
a927bd6ba952d1 Dan Williams 2020-11-21 44 }
a927bd6ba952d1 Dan Williams 2020-11-21 45 #endif
a927bd6ba952d1 Dan Williams 2020-11-21 46 #else /* !CONFIG_NUMA */
b2ca916ce392a9 Dan Williams 2020-02-16 47 static inline int numa_map_to_online_node(int node)
b2ca916ce392a9 Dan Williams 2020-02-16 48 {
b2ca916ce392a9 Dan Williams 2020-02-16 49 return NUMA_NO_NODE;
b2ca916ce392a9 Dan Williams 2020-02-16 50 }
a927bd6ba952d1 Dan Williams 2020-11-21 51 static inline int memory_add_physaddr_to_nid(u64 start)
a927bd6ba952d1 Dan Williams 2020-11-21 52 {
a927bd6ba952d1 Dan Williams 2020-11-21 53 return 0;
a927bd6ba952d1 Dan Williams 2020-11-21 54 }
a927bd6ba952d1 Dan Williams 2020-11-21 55 static inline int phys_to_target_node(u64 start)
a927bd6ba952d1 Dan Williams 2020-11-21 56 {
a927bd6ba952d1 Dan Williams 2020-11-21 57 return 0;
a927bd6ba952d1 Dan Williams 2020-11-21 58 }
b2ca916ce392a9 Dan Williams 2020-02-16 59 #endif
b2ca916ce392a9 Dan Williams 2020-02-16 60

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests