These are needed for the __jump_table in modules using
static keys/jump-labels with the layout from
HAVE_ARCH_JUMP_LABEL_RELATIVE on 64bit kernels.
Signed-off-by: Emil Renner Berthing <[email protected]>
---
Tested on the HiFive Unleashed board.
This patch is new in v2. It fixes an error loading modules
containing static keys found by Björn Töpel.
arch/riscv/kernel/module.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
index 7191342c54da..104fba889cf7 100644
--- a/arch/riscv/kernel/module.c
+++ b/arch/riscv/kernel/module.c
@@ -263,6 +263,13 @@ static int apply_r_riscv_add32_rela(struct module *me, u32 *location,
return 0;
}
+static int apply_r_riscv_add64_rela(struct module *me, u32 *location,
+ Elf_Addr v)
+{
+ *(u64 *)location += (u64)v;
+ return 0;
+}
+
static int apply_r_riscv_sub32_rela(struct module *me, u32 *location,
Elf_Addr v)
{
@@ -270,6 +277,13 @@ static int apply_r_riscv_sub32_rela(struct module *me, u32 *location,
return 0;
}
+static int apply_r_riscv_sub64_rela(struct module *me, u32 *location,
+ Elf_Addr v)
+{
+ *(u64 *)location -= (u64)v;
+ return 0;
+}
+
static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
Elf_Addr v) = {
[R_RISCV_32] = apply_r_riscv_32_rela,
@@ -290,7 +304,9 @@ static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
[R_RISCV_RELAX] = apply_r_riscv_relax_rela,
[R_RISCV_ALIGN] = apply_r_riscv_align_rela,
[R_RISCV_ADD32] = apply_r_riscv_add32_rela,
+ [R_RISCV_ADD64] = apply_r_riscv_add64_rela,
[R_RISCV_SUB32] = apply_r_riscv_sub32_rela,
+ [R_RISCV_SUB64] = apply_r_riscv_sub64_rela,
};
int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
--
2.27.0
Add jump-label implementation based on the ARM64 version
and add CONFIG_JUMP_LABEL=y to the defconfigs.
Signed-off-by: Emil Renner Berthing <[email protected]>
Reviewed-by: Björn Töpel <[email protected]>
---
Tested on the HiFive Unleashed board.
Changes since v1:
- WARN and give up gracefully if the jump offset cannot be
represented in a JAL instruction.
- Add missing braces.
- Add CONFIG_JUMP_LABEL=y to defconfigs.
All suggested by Björn Töpel.
Changes since RFC:
- Use RISCV_PTR and RISCV_LGPTR macros to match struct jump_table
also in 32bit kernels.
- Remove unneeded branch ? 1 : 0, thanks Björn
- Fix \n\n instead of \n\t mistake
.../core/jump-labels/arch-support.txt | 2 +-
arch/riscv/Kconfig | 2 +
arch/riscv/configs/defconfig | 1 +
arch/riscv/configs/nommu_k210_defconfig | 1 +
arch/riscv/configs/nommu_virt_defconfig | 1 +
arch/riscv/configs/rv32_defconfig | 1 +
arch/riscv/include/asm/jump_label.h | 59 +++++++++++++++++++
arch/riscv/kernel/Makefile | 2 +
arch/riscv/kernel/jump_label.c | 49 +++++++++++++++
9 files changed, 117 insertions(+), 1 deletion(-)
create mode 100644 arch/riscv/include/asm/jump_label.h
create mode 100644 arch/riscv/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 632a1c7aefa2..760243d18ed7 100644
--- a/Documentation/features/core/jump-labels/arch-support.txt
+++ b/Documentation/features/core/jump-labels/arch-support.txt
@@ -23,7 +23,7 @@
| openrisc: | TODO |
| parisc: | ok |
| powerpc: | ok |
- | riscv: | TODO |
+ | riscv: | ok |
| s390: | ok |
| sh: | TODO |
| sparc: | ok |
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index fd639937e251..d2f5c53fdc19 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -46,6 +46,8 @@ config RISCV
select GENERIC_TIME_VSYSCALL if MMU && 64BIT
select HANDLE_DOMAIN_IRQ
select HAVE_ARCH_AUDITSYSCALL
+ select HAVE_ARCH_JUMP_LABEL
+ select HAVE_ARCH_JUMP_LABEL_RELATIVE
select HAVE_ARCH_KASAN if MMU && 64BIT
select HAVE_ARCH_KGDB
select HAVE_ARCH_KGDB_QXFER_PKT
diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig
index 4da4886246a4..d58c93efb603 100644
--- a/arch/riscv/configs/defconfig
+++ b/arch/riscv/configs/defconfig
@@ -17,6 +17,7 @@ CONFIG_BPF_SYSCALL=y
CONFIG_SOC_SIFIVE=y
CONFIG_SOC_VIRT=y
CONFIG_SMP=y
+CONFIG_JUMP_LABEL=y
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_NET=y
diff --git a/arch/riscv/configs/nommu_k210_defconfig b/arch/riscv/configs/nommu_k210_defconfig
index b48138e329ea..cd1df62b13c7 100644
--- a/arch/riscv/configs/nommu_k210_defconfig
+++ b/arch/riscv/configs/nommu_k210_defconfig
@@ -33,6 +33,7 @@ CONFIG_SMP=y
CONFIG_NR_CPUS=2
CONFIG_CMDLINE="earlycon console=ttySIF0"
CONFIG_CMDLINE_FORCE=y
+CONFIG_JUMP_LABEL=y
# CONFIG_BLOCK is not set
CONFIG_BINFMT_FLAT=y
# CONFIG_COREDUMP is not set
diff --git a/arch/riscv/configs/nommu_virt_defconfig b/arch/riscv/configs/nommu_virt_defconfig
index cf74e179bf90..f27596e9663e 100644
--- a/arch/riscv/configs/nommu_virt_defconfig
+++ b/arch/riscv/configs/nommu_virt_defconfig
@@ -30,6 +30,7 @@ CONFIG_MAXPHYSMEM_2GB=y
CONFIG_SMP=y
CONFIG_CMDLINE="root=/dev/vda rw earlycon=uart8250,mmio,0x10000000,115200n8 console=ttyS0"
CONFIG_CMDLINE_FORCE=y
+CONFIG_JUMP_LABEL=y
# CONFIG_BLK_DEV_BSG is not set
CONFIG_PARTITION_ADVANCED=y
# CONFIG_MSDOS_PARTITION is not set
diff --git a/arch/riscv/configs/rv32_defconfig b/arch/riscv/configs/rv32_defconfig
index 05bbf5240569..3a55f0e00d6c 100644
--- a/arch/riscv/configs/rv32_defconfig
+++ b/arch/riscv/configs/rv32_defconfig
@@ -17,6 +17,7 @@ CONFIG_BPF_SYSCALL=y
CONFIG_SOC_VIRT=y
CONFIG_ARCH_RV32I=y
CONFIG_SMP=y
+CONFIG_JUMP_LABEL=y
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_NET=y
diff --git a/arch/riscv/include/asm/jump_label.h b/arch/riscv/include/asm/jump_label.h
new file mode 100644
index 000000000000..d5fb342bfccf
--- /dev/null
+++ b/arch/riscv/include/asm/jump_label.h
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2020 Emil Renner Berthing
+ *
+ * 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>
+
+#define JUMP_LABEL_NOP_SIZE 4
+
+static __always_inline bool arch_static_branch(struct static_key *key,
+ bool branch)
+{
+ asm_volatile_goto(
+ " .option push \n\t"
+ " .option norelax \n\t"
+ " .option norvc \n\t"
+ "1: nop \n\t"
+ " .option pop \n\t"
+ " .pushsection __jump_table, \"aw\" \n\t"
+ " .align " RISCV_LGPTR " \n\t"
+ " .long 1b - ., %l[label] - . \n\t"
+ " " RISCV_PTR " %0 - . \n\t"
+ " .popsection \n\t"
+ : : "i"(&((char *)key)[branch]) : : label);
+
+ return false;
+label:
+ return true;
+}
+
+static __always_inline bool arch_static_branch_jump(struct static_key *key,
+ bool branch)
+{
+ asm_volatile_goto(
+ " .option push \n\t"
+ " .option norelax \n\t"
+ " .option norvc \n\t"
+ "1: jal zero, %l[label] \n\t"
+ " .option pop \n\t"
+ " .pushsection __jump_table, \"aw\" \n\t"
+ " .align " RISCV_LGPTR " \n\t"
+ " .long 1b - ., %l[label] - . \n\t"
+ " " RISCV_PTR " %0 - . \n\t"
+ " .popsection \n\t"
+ : : "i"(&((char *)key)[branch]) : : label);
+
+ return false;
+label:
+ return true;
+}
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ASM_JUMP_LABEL_H */
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index b355cf485671..a5287ab9f7f2 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -53,4 +53,6 @@ endif
obj-$(CONFIG_HOTPLUG_CPU) += cpu-hotplug.o
obj-$(CONFIG_KGDB) += kgdb.o
+obj-$(CONFIG_JUMP_LABEL) += jump_label.o
+
clean:
diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c
new file mode 100644
index 000000000000..1bab1abc1aa5
--- /dev/null
+++ b/arch/riscv/kernel/jump_label.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020 Emil Renner Berthing
+ *
+ * Based on arch/arm64/kernel/jump_label.c
+ */
+#include <linux/kernel.h>
+#include <linux/jump_label.h>
+#include <asm/bug.h>
+#include <asm/patch.h>
+
+#define RISCV_INSN_NOP 0x00000013U
+#define RISCV_INSN_JAL 0x0000006fU
+
+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) {
+ long offset = jump_entry_target(entry) - jump_entry_code(entry);
+
+ if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288))
+ return;
+
+ insn = RISCV_INSN_JAL |
+ (((u32)offset & GENMASK(19, 12)) << (12 - 12)) |
+ (((u32)offset & GENMASK(11, 11)) << (20 - 11)) |
+ (((u32)offset & GENMASK(10, 1)) << (21 - 1)) |
+ (((u32)offset & GENMASK(20, 20)) << (31 - 20));
+ } else {
+ insn = RISCV_INSN_NOP;
+ }
+
+ patch_text_nosync(addr, &insn, sizeof(insn));
+}
+
+void arch_jump_label_transform_static(struct jump_entry *entry,
+ enum jump_label_type type)
+{
+ /*
+ * We use the same instructions in the arch_static_branch and
+ * arch_static_branch_jump inline functions, so there's no
+ * need to patch them up here.
+ * The core will call arch_jump_label_transform when those
+ * instructions need to be replaced.
+ */
+}
--
2.27.0
On Wed, 8 Jul 2020 at 23:10, Emil Renner Berthing <[email protected]> wrote:
>
> These are needed for the __jump_table in modules using
> static keys/jump-labels with the layout from
> HAVE_ARCH_JUMP_LABEL_RELATIVE on 64bit kernels.
>
> Signed-off-by: Emil Renner Berthing <[email protected]>
Reviewed-by: Björn Töpel <[email protected]>
Tested-by: Björn Töpel <[email protected]>
> ---
>
> Tested on the HiFive Unleashed board.
>
> This patch is new in v2. It fixes an error loading modules
> containing static keys found by Björn Töpel.
>
> arch/riscv/kernel/module.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
> index 7191342c54da..104fba889cf7 100644
> --- a/arch/riscv/kernel/module.c
> +++ b/arch/riscv/kernel/module.c
> @@ -263,6 +263,13 @@ static int apply_r_riscv_add32_rela(struct module *me, u32 *location,
> return 0;
> }
>
> +static int apply_r_riscv_add64_rela(struct module *me, u32 *location,
> + Elf_Addr v)
> +{
> + *(u64 *)location += (u64)v;
> + return 0;
> +}
> +
> static int apply_r_riscv_sub32_rela(struct module *me, u32 *location,
> Elf_Addr v)
> {
> @@ -270,6 +277,13 @@ static int apply_r_riscv_sub32_rela(struct module *me, u32 *location,
> return 0;
> }
>
> +static int apply_r_riscv_sub64_rela(struct module *me, u32 *location,
> + Elf_Addr v)
> +{
> + *(u64 *)location -= (u64)v;
> + return 0;
> +}
> +
> static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
> Elf_Addr v) = {
> [R_RISCV_32] = apply_r_riscv_32_rela,
> @@ -290,7 +304,9 @@ static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
> [R_RISCV_RELAX] = apply_r_riscv_relax_rela,
> [R_RISCV_ALIGN] = apply_r_riscv_align_rela,
> [R_RISCV_ADD32] = apply_r_riscv_add32_rela,
> + [R_RISCV_ADD64] = apply_r_riscv_add64_rela,
> [R_RISCV_SUB32] = apply_r_riscv_sub32_rela,
> + [R_RISCV_SUB64] = apply_r_riscv_sub64_rela,
> };
>
> int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
> --
> 2.27.0
>
On Wed, 8 Jul 2020 at 23:10, Emil Renner Berthing <[email protected]> wrote:
>
> Add jump-label implementation based on the ARM64 version
> and add CONFIG_JUMP_LABEL=y to the defconfigs.
>
> Signed-off-by: Emil Renner Berthing <[email protected]>
> Reviewed-by: Björn Töpel <[email protected]>
Tested-by: Björn Töpel <[email protected]>
> ---
>
> Tested on the HiFive Unleashed board.
>
> Changes since v1:
> - WARN and give up gracefully if the jump offset cannot be
> represented in a JAL instruction.
> - Add missing braces.
> - Add CONFIG_JUMP_LABEL=y to defconfigs.
>
> All suggested by Björn Töpel.
>
> Changes since RFC:
> - Use RISCV_PTR and RISCV_LGPTR macros to match struct jump_table
> also in 32bit kernels.
> - Remove unneeded branch ? 1 : 0, thanks Björn
> - Fix \n\n instead of \n\t mistake
>
> .../core/jump-labels/arch-support.txt | 2 +-
> arch/riscv/Kconfig | 2 +
> arch/riscv/configs/defconfig | 1 +
> arch/riscv/configs/nommu_k210_defconfig | 1 +
> arch/riscv/configs/nommu_virt_defconfig | 1 +
> arch/riscv/configs/rv32_defconfig | 1 +
> arch/riscv/include/asm/jump_label.h | 59 +++++++++++++++++++
> arch/riscv/kernel/Makefile | 2 +
> arch/riscv/kernel/jump_label.c | 49 +++++++++++++++
> 9 files changed, 117 insertions(+), 1 deletion(-)
> create mode 100644 arch/riscv/include/asm/jump_label.h
> create mode 100644 arch/riscv/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 632a1c7aefa2..760243d18ed7 100644
> --- a/Documentation/features/core/jump-labels/arch-support.txt
> +++ b/Documentation/features/core/jump-labels/arch-support.txt
> @@ -23,7 +23,7 @@
> | openrisc: | TODO |
> | parisc: | ok |
> | powerpc: | ok |
> - | riscv: | TODO |
> + | riscv: | ok |
> | s390: | ok |
> | sh: | TODO |
> | sparc: | ok |
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index fd639937e251..d2f5c53fdc19 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -46,6 +46,8 @@ config RISCV
> select GENERIC_TIME_VSYSCALL if MMU && 64BIT
> select HANDLE_DOMAIN_IRQ
> select HAVE_ARCH_AUDITSYSCALL
> + select HAVE_ARCH_JUMP_LABEL
> + select HAVE_ARCH_JUMP_LABEL_RELATIVE
> select HAVE_ARCH_KASAN if MMU && 64BIT
> select HAVE_ARCH_KGDB
> select HAVE_ARCH_KGDB_QXFER_PKT
> diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig
> index 4da4886246a4..d58c93efb603 100644
> --- a/arch/riscv/configs/defconfig
> +++ b/arch/riscv/configs/defconfig
> @@ -17,6 +17,7 @@ CONFIG_BPF_SYSCALL=y
> CONFIG_SOC_SIFIVE=y
> CONFIG_SOC_VIRT=y
> CONFIG_SMP=y
> +CONFIG_JUMP_LABEL=y
> CONFIG_MODULES=y
> CONFIG_MODULE_UNLOAD=y
> CONFIG_NET=y
> diff --git a/arch/riscv/configs/nommu_k210_defconfig b/arch/riscv/configs/nommu_k210_defconfig
> index b48138e329ea..cd1df62b13c7 100644
> --- a/arch/riscv/configs/nommu_k210_defconfig
> +++ b/arch/riscv/configs/nommu_k210_defconfig
> @@ -33,6 +33,7 @@ CONFIG_SMP=y
> CONFIG_NR_CPUS=2
> CONFIG_CMDLINE="earlycon console=ttySIF0"
> CONFIG_CMDLINE_FORCE=y
> +CONFIG_JUMP_LABEL=y
> # CONFIG_BLOCK is not set
> CONFIG_BINFMT_FLAT=y
> # CONFIG_COREDUMP is not set
> diff --git a/arch/riscv/configs/nommu_virt_defconfig b/arch/riscv/configs/nommu_virt_defconfig
> index cf74e179bf90..f27596e9663e 100644
> --- a/arch/riscv/configs/nommu_virt_defconfig
> +++ b/arch/riscv/configs/nommu_virt_defconfig
> @@ -30,6 +30,7 @@ CONFIG_MAXPHYSMEM_2GB=y
> CONFIG_SMP=y
> CONFIG_CMDLINE="root=/dev/vda rw earlycon=uart8250,mmio,0x10000000,115200n8 console=ttyS0"
> CONFIG_CMDLINE_FORCE=y
> +CONFIG_JUMP_LABEL=y
> # CONFIG_BLK_DEV_BSG is not set
> CONFIG_PARTITION_ADVANCED=y
> # CONFIG_MSDOS_PARTITION is not set
> diff --git a/arch/riscv/configs/rv32_defconfig b/arch/riscv/configs/rv32_defconfig
> index 05bbf5240569..3a55f0e00d6c 100644
> --- a/arch/riscv/configs/rv32_defconfig
> +++ b/arch/riscv/configs/rv32_defconfig
> @@ -17,6 +17,7 @@ CONFIG_BPF_SYSCALL=y
> CONFIG_SOC_VIRT=y
> CONFIG_ARCH_RV32I=y
> CONFIG_SMP=y
> +CONFIG_JUMP_LABEL=y
> CONFIG_MODULES=y
> CONFIG_MODULE_UNLOAD=y
> CONFIG_NET=y
> diff --git a/arch/riscv/include/asm/jump_label.h b/arch/riscv/include/asm/jump_label.h
> new file mode 100644
> index 000000000000..d5fb342bfccf
> --- /dev/null
> +++ b/arch/riscv/include/asm/jump_label.h
> @@ -0,0 +1,59 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (C) 2020 Emil Renner Berthing
> + *
> + * 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>
> +
> +#define JUMP_LABEL_NOP_SIZE 4
> +
> +static __always_inline bool arch_static_branch(struct static_key *key,
> + bool branch)
> +{
> + asm_volatile_goto(
> + " .option push \n\t"
> + " .option norelax \n\t"
> + " .option norvc \n\t"
> + "1: nop \n\t"
> + " .option pop \n\t"
> + " .pushsection __jump_table, \"aw\" \n\t"
> + " .align " RISCV_LGPTR " \n\t"
> + " .long 1b - ., %l[label] - . \n\t"
> + " " RISCV_PTR " %0 - . \n\t"
> + " .popsection \n\t"
> + : : "i"(&((char *)key)[branch]) : : label);
> +
> + return false;
> +label:
> + return true;
> +}
> +
> +static __always_inline bool arch_static_branch_jump(struct static_key *key,
> + bool branch)
> +{
> + asm_volatile_goto(
> + " .option push \n\t"
> + " .option norelax \n\t"
> + " .option norvc \n\t"
> + "1: jal zero, %l[label] \n\t"
> + " .option pop \n\t"
> + " .pushsection __jump_table, \"aw\" \n\t"
> + " .align " RISCV_LGPTR " \n\t"
> + " .long 1b - ., %l[label] - . \n\t"
> + " " RISCV_PTR " %0 - . \n\t"
> + " .popsection \n\t"
> + : : "i"(&((char *)key)[branch]) : : label);
> +
> + return false;
> +label:
> + return true;
> +}
> +
> +#endif /* __ASSEMBLY__ */
> +#endif /* __ASM_JUMP_LABEL_H */
> diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
> index b355cf485671..a5287ab9f7f2 100644
> --- a/arch/riscv/kernel/Makefile
> +++ b/arch/riscv/kernel/Makefile
> @@ -53,4 +53,6 @@ endif
> obj-$(CONFIG_HOTPLUG_CPU) += cpu-hotplug.o
> obj-$(CONFIG_KGDB) += kgdb.o
>
> +obj-$(CONFIG_JUMP_LABEL) += jump_label.o
> +
> clean:
> diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c
> new file mode 100644
> index 000000000000..1bab1abc1aa5
> --- /dev/null
> +++ b/arch/riscv/kernel/jump_label.c
> @@ -0,0 +1,49 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2020 Emil Renner Berthing
> + *
> + * Based on arch/arm64/kernel/jump_label.c
> + */
> +#include <linux/kernel.h>
> +#include <linux/jump_label.h>
> +#include <asm/bug.h>
> +#include <asm/patch.h>
> +
> +#define RISCV_INSN_NOP 0x00000013U
> +#define RISCV_INSN_JAL 0x0000006fU
> +
> +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) {
> + long offset = jump_entry_target(entry) - jump_entry_code(entry);
> +
> + if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288))
> + return;
> +
> + insn = RISCV_INSN_JAL |
> + (((u32)offset & GENMASK(19, 12)) << (12 - 12)) |
> + (((u32)offset & GENMASK(11, 11)) << (20 - 11)) |
> + (((u32)offset & GENMASK(10, 1)) << (21 - 1)) |
> + (((u32)offset & GENMASK(20, 20)) << (31 - 20));
> + } else {
> + insn = RISCV_INSN_NOP;
> + }
> +
> + patch_text_nosync(addr, &insn, sizeof(insn));
> +}
> +
> +void arch_jump_label_transform_static(struct jump_entry *entry,
> + enum jump_label_type type)
> +{
> + /*
> + * We use the same instructions in the arch_static_branch and
> + * arch_static_branch_jump inline functions, so there's no
> + * need to patch them up here.
> + * The core will call arch_jump_label_transform when those
> + * instructions need to be replaced.
> + */
> +}
> --
> 2.27.0
>
Hi Emil,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.8-rc5 next-20200713]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Emil-Renner-Berthing/riscv-Support-R_RISCV_ADD64-and-R_RISCV_SUB64-relocs/20200709-051310
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git dcde237b9b0eb1d19306e6f48c0a4e058907619f
config: riscv-allyesconfig (attached as .config)
compiler: riscv64-linux-gcc (GCC) 9.3.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
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All errors (new ones prefixed by >>):
In file included from include/linux/compiler_types.h:68,
from <command-line>:
arch/riscv/include/asm/jump_label.h: In function 'arch_static_branch':
>> arch/riscv/include/asm/jump_label.h:26:15: error: expected ':' before 'RISCV_LGPTR'
26 | " .align " RISCV_LGPTR " \n\t"
| ^~~~~~~~~~~
include/linux/compiler-gcc.h:121:47: note: in definition of macro 'asm_volatile_goto'
121 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
| ^
In file included from include/linux/jump_label.h:117,
from include/linux/dynamic_debug.h:6,
from include/linux/printk.h:404,
from kernel/module_signature.c:10:
arch/riscv/include/asm/jump_label.h:33:1: warning: label 'label' defined but not used [-Wunused-label]
33 | label:
| ^~~~~
In file included from include/linux/compiler_types.h:68,
from <command-line>:
arch/riscv/include/asm/jump_label.h: In function 'arch_static_branch_jump':
arch/riscv/include/asm/jump_label.h:47:15: error: expected ':' before 'RISCV_LGPTR'
47 | " .align " RISCV_LGPTR " \n\t"
| ^~~~~~~~~~~
include/linux/compiler-gcc.h:121:47: note: in definition of macro 'asm_volatile_goto'
121 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
| ^
In file included from include/linux/jump_label.h:117,
from include/linux/dynamic_debug.h:6,
from include/linux/printk.h:404,
from kernel/module_signature.c:10:
arch/riscv/include/asm/jump_label.h:54:1: warning: label 'label' defined but not used [-Wunused-label]
54 | label:
| ^~~~~
--
In file included from include/linux/compiler_types.h:68,
from <command-line>:
arch/riscv/include/asm/jump_label.h: In function 'arch_static_branch':
>> arch/riscv/include/asm/jump_label.h:26:15: error: expected ':' before 'RISCV_LGPTR'
26 | " .align " RISCV_LGPTR " \n\t"
| ^~~~~~~~~~~
include/linux/compiler-gcc.h:121:47: note: in definition of macro 'asm_volatile_goto'
121 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
| ^
In file included from include/linux/jump_label.h:117,
from include/linux/dynamic_debug.h:6,
from include/linux/printk.h:404,
from include/drm/drm_print.h:30,
from drivers/gpu/drm/tidss/tidss_irq.c:7:
arch/riscv/include/asm/jump_label.h:33:1: warning: label 'label' defined but not used [-Wunused-label]
33 | label:
| ^~~~~
In file included from include/linux/compiler_types.h:68,
from <command-line>:
arch/riscv/include/asm/jump_label.h: In function 'arch_static_branch_jump':
arch/riscv/include/asm/jump_label.h:47:15: error: expected ':' before 'RISCV_LGPTR'
47 | " .align " RISCV_LGPTR " \n\t"
| ^~~~~~~~~~~
include/linux/compiler-gcc.h:121:47: note: in definition of macro 'asm_volatile_goto'
121 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
| ^
In file included from include/linux/jump_label.h:117,
from include/linux/dynamic_debug.h:6,
from include/linux/printk.h:404,
from include/drm/drm_print.h:30,
from drivers/gpu/drm/tidss/tidss_irq.c:7:
arch/riscv/include/asm/jump_label.h:54:1: warning: label 'label' defined but not used [-Wunused-label]
54 | label:
| ^~~~~
In file included from arch/riscv/include/asm/kgdb.h:109,
from include/linux/kgdb.h:20,
from include/linux/fb.h:5,
from include/drm/drm_crtc.h:31,
from drivers/gpu/drm/tidss/tidss_crtc.h:13,
from drivers/gpu/drm/tidss/tidss_irq.c:9:
At top level:
arch/riscv/include/asm/gdb_xml.h:23:19: warning: 'riscv_gdb_stub_cpuxml' defined but not used [-Wunused-const-variable=]
23 | static const char riscv_gdb_stub_cpuxml[2048] =
| ^~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/gdb_xml.h:16:19: warning: 'riscv_gdb_stub_target_desc' defined but not used [-Wunused-const-variable=]
16 | static const char riscv_gdb_stub_target_desc[256] =
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/gdb_xml.h:13:19: warning: 'gdb_xfer_read_cpuxml' defined but not used [-Wunused-const-variable=]
13 | static const char gdb_xfer_read_cpuxml[39] =
| ^~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/gdb_xml.h:10:19: warning: 'gdb_xfer_read_target' defined but not used [-Wunused-const-variable=]
10 | static const char gdb_xfer_read_target[31] = "qXfer:features:read:target.xml:";
| ^~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/gdb_xml.h:7:19: warning: 'riscv_gdb_stub_feature' defined but not used [-Wunused-const-variable=]
7 | static const char riscv_gdb_stub_feature[64] =
| ^~~~~~~~~~~~~~~~~~~~~~
vim +26 arch/riscv/include/asm/jump_label.h
15
16 static __always_inline bool arch_static_branch(struct static_key *key,
17 bool branch)
18 {
19 asm_volatile_goto(
20 " .option push \n\t"
21 " .option norelax \n\t"
22 " .option norvc \n\t"
23 "1: nop \n\t"
24 " .option pop \n\t"
25 " .pushsection __jump_table, \"aw\" \n\t"
> 26 " .align " RISCV_LGPTR " \n\t"
27 " .long 1b - ., %l[label] - . \n\t"
28 " " RISCV_PTR " %0 - . \n\t"
29 " .popsection \n\t"
30 : : "i"(&((char *)key)[branch]) : : label);
31
32 return false;
33 label:
34 return true;
35 }
36
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]