Skip to content

Commit 742adaa

Browse files
committed
Pull OpenRISC updates from Stafford Horne: "I picked up one series from Chen Miao, our Google Summer of Code contributor, which adds OpenRISC support for static keys" * tag 'for-linus' of https://github.com/openrisc/linux: openrisc: Add jump label support openrisc: Regenerate defconfigs. openrisc: Add R_OR1K_32_PCREL relocation type module support openrisc: Add text patching API support
2 parents 21fbefc + 8c30b00 commit 742adaa

File tree

15 files changed

+255
-16
lines changed

15 files changed

+255
-16
lines changed

Documentation/features/core/jump-labels/arch-support.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
| microblaze: | TODO |
1818
| mips: | ok |
1919
| nios2: | TODO |
20-
| openrisc: | TODO |
20+
| openrisc: | ok |
2121
| parisc: | ok |
2222
| powerpc: | ok |
2323
| riscv: | ok |

arch/openrisc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ config OPENRISC
2424
select GENERIC_PCI_IOMAP
2525
select GENERIC_IOREMAP
2626
select GENERIC_CPU_DEVICES
27+
select HAVE_ARCH_JUMP_LABEL
28+
select HAVE_ARCH_JUMP_LABEL_RELATIVE
2729
select HAVE_PCI
2830
select HAVE_UID16
2931
select HAVE_PAGE_SIZE_8KB

arch/openrisc/configs/or1ksim_defconfig

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@ CONFIG_LOG_BUF_SHIFT=14
33
CONFIG_BLK_DEV_INITRD=y
44
# CONFIG_RD_GZIP is not set
55
CONFIG_EXPERT=y
6-
# CONFIG_KALLSYMS is not set
76
# CONFIG_EPOLL is not set
87
# CONFIG_TIMERFD is not set
98
# CONFIG_EVENTFD is not set
109
# CONFIG_AIO is not set
11-
# CONFIG_VM_EVENT_COUNTERS is not set
12-
# CONFIG_COMPAT_BRK is not set
13-
CONFIG_SLUB=y
14-
CONFIG_SLUB_TINY=y
15-
CONFIG_MODULES=y
16-
# CONFIG_BLOCK is not set
10+
# CONFIG_KALLSYMS is not set
1711
CONFIG_BUILTIN_DTB_NAME="or1ksim"
1812
CONFIG_HZ_100=y
13+
CONFIG_JUMP_LABEL=y
14+
CONFIG_MODULES=y
15+
# CONFIG_BLOCK is not set
16+
CONFIG_SLUB_TINY=y
17+
# CONFIG_COMPAT_BRK is not set
18+
# CONFIG_VM_EVENT_COUNTERS is not set
1919
CONFIG_NET=y
2020
CONFIG_PACKET=y
2121
CONFIG_UNIX=y
2222
CONFIG_INET=y
23-
# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
24-
# CONFIG_INET_XFRM_MODE_TUNNEL is not set
25-
# CONFIG_INET_XFRM_MODE_BEET is not set
2623
# CONFIG_INET_DIAG is not set
2724
CONFIG_TCP_CONG_ADVANCED=y
2825
# CONFIG_TCP_CONG_BIC is not set
@@ -35,7 +32,6 @@ CONFIG_DEVTMPFS=y
3532
CONFIG_DEVTMPFS_MOUNT=y
3633
# CONFIG_PREVENT_FIRMWARE_BUILD is not set
3734
# CONFIG_FW_LOADER is not set
38-
CONFIG_PROC_DEVICETREE=y
3935
CONFIG_NETDEVICES=y
4036
CONFIG_ETHOC=y
4137
CONFIG_MICREL_PHY=y
@@ -53,4 +49,3 @@ CONFIG_SERIAL_OF_PLATFORM=y
5349
# CONFIG_DNOTIFY is not set
5450
CONFIG_TMPFS=y
5551
CONFIG_NFS_FS=y
56-
# CONFIG_ENABLE_MUST_CHECK is not set

arch/openrisc/configs/virt_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CONFIG_NR_CPUS=8
1212
CONFIG_SMP=y
1313
CONFIG_HZ_100=y
1414
# CONFIG_OPENRISC_NO_SPR_SR_DSX is not set
15+
CONFIG_JUMP_LABEL=y
1516
# CONFIG_COMPAT_BRK is not set
1617
CONFIG_NET=y
1718
CONFIG_PACKET=y
@@ -55,7 +56,6 @@ CONFIG_DRM=y
5556
# CONFIG_DRM_FBDEV_EMULATION is not set
5657
CONFIG_DRM_VIRTIO_GPU=y
5758
CONFIG_FB=y
58-
CONFIG_FIRMWARE_EDID=y
5959
CONFIG_FRAMEBUFFER_CONSOLE=y
6060
CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
6161
CONFIG_LOGO=y

arch/openrisc/include/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ generic-y += spinlock.h
99
generic-y += qrwlock_types.h
1010
generic-y += qrwlock.h
1111
generic-y += user.h
12-
generic-y += text-patching.h

arch/openrisc/include/asm/fixmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
enum fixed_addresses {
3030
FIX_EARLYCON_MEM_BASE,
31+
FIX_TEXT_POKE0,
3132
__end_of_fixed_addresses
3233
};
3334

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2025 Chen Miao
4+
*/
5+
6+
#ifndef __ASM_OPENRISC_INSN_DEF_H
7+
#define __ASM_OPENRISC_INSN_DEF_H
8+
9+
/* or1k instructions are always 32 bits. */
10+
#define OPENRISC_INSN_SIZE 4
11+
12+
/* or1k nop instruction code */
13+
#define OPENRISC_INSN_NOP 0x15000000U
14+
15+
#endif /* __ASM_OPENRISC_INSN_DEF_H */
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2025 Chen Miao
4+
*
5+
* Based on arch/arm/include/asm/jump_label.h
6+
*/
7+
#ifndef __ASM_OPENRISC_JUMP_LABEL_H
8+
#define __ASM_OPENRISC_JUMP_LABEL_H
9+
10+
#ifndef __ASSEMBLER__
11+
12+
#include <linux/types.h>
13+
#include <asm/insn-def.h>
14+
15+
#define HAVE_JUMP_LABEL_BATCH
16+
17+
#define JUMP_LABEL_NOP_SIZE OPENRISC_INSN_SIZE
18+
19+
/**
20+
* JUMP_TABLE_ENTRY - Create a jump table entry
21+
* @key: Jump key identifier (typically a symbol address)
22+
* @label: Target label address
23+
*
24+
* This macro creates a jump table entry in the dedicated kernel section (__jump_table).
25+
* Each entry contains the following information:
26+
* Offset from current instruction to jump instruction (1b - .)
27+
* Offset from current instruction to target label (label - .)
28+
* Offset from current instruction to key identifier (key - .)
29+
*/
30+
#define JUMP_TABLE_ENTRY(key, label) \
31+
".pushsection __jump_table, \"aw\" \n\t" \
32+
".align 4 \n\t" \
33+
".long 1b - ., " label " - . \n\t" \
34+
".long " key " - . \n\t" \
35+
".popsection \n\t"
36+
37+
#define ARCH_STATIC_BRANCH_ASM(key, label) \
38+
".align 4 \n\t" \
39+
"1: l.nop \n\t" \
40+
" l.nop \n\t" \
41+
JUMP_TABLE_ENTRY(key, label)
42+
43+
static __always_inline bool arch_static_branch(struct static_key *const key,
44+
const bool branch)
45+
{
46+
asm goto (ARCH_STATIC_BRANCH_ASM("%0", "%l[l_yes]")
47+
::"i"(&((char *)key)[branch])::l_yes);
48+
49+
return false;
50+
l_yes:
51+
return true;
52+
}
53+
54+
#define ARCH_STATIC_BRANCH_JUMP_ASM(key, label) \
55+
".align 4 \n\t" \
56+
"1: l.j " label " \n\t" \
57+
" l.nop \n\t" \
58+
JUMP_TABLE_ENTRY(key, label)
59+
60+
static __always_inline bool
61+
arch_static_branch_jump(struct static_key *const key, const bool branch)
62+
{
63+
asm goto (ARCH_STATIC_BRANCH_JUMP_ASM("%0", "%l[l_yes]")
64+
::"i"(&((char *)key)[branch])::l_yes);
65+
66+
return false;
67+
l_yes:
68+
return true;
69+
}
70+
71+
#endif /* __ASSEMBLER__ */
72+
#endif /* __ASM_OPENRISC_JUMP_LABEL_H */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2025 Chen Miao
4+
*/
5+
6+
#ifndef _ASM_OPENRISC_PATCHING_H
7+
#define _ASM_OPENRISC_PATCHING_H
8+
9+
#include <linux/types.h>
10+
11+
int patch_insn_write(void *addr, u32 insn);
12+
13+
#endif /* _ASM_OPENRISC_PATCHING_H */

arch/openrisc/kernel/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ obj-y := head.o setup.o or32_ksyms.o process.o dma.o \
99
traps.o time.o irq.o entry.o ptrace.o signal.o \
1010
sys_call_table.o unwinder.o cacheinfo.o
1111

12+
obj-$(CONFIG_JUMP_LABEL) += jump_label.o
1213
obj-$(CONFIG_SMP) += smp.o sync-timer.o
1314
obj-$(CONFIG_STACKTRACE) += stacktrace.o
1415
obj-$(CONFIG_MODULES) += module.o
1516
obj-$(CONFIG_OF) += prom.o
17+
obj-y += patching.o
1618

1719
clean:

0 commit comments

Comments
 (0)