Skip to content

Commit 7df9075

Browse files
committed
Merge tag 'csky-for-linus-6.0-rc1' of https://github.com/c-sky/csky-linux
Pull csky updates from Guo Ren: - Add jump-label implementation - Add qspinlock support - Enable ARCH_INLINE_READ*/WRITE*/SPIN* - Some fixups and a coding convention * tag 'csky-for-linus-6.0-rc1' of https://github.com/c-sky/csky-linux: csky: abiv1: Fixup compile error csky: cmpxchg: Coding convention for BUILD_BUG() csky: Enable ARCH_INLINE_READ*/WRITE*/SPIN* csky: Add qspinlock support csky: Add jump-label implementation csky: Move HEAD_TEXT_SECTION out of __init_begin-end csky: Correct position of _stext csky: Use the bitmap API to allocate bitmaps csky/kprobe: reclaim insn_slot on kprobe unregistration
2 parents 25e6bed + 45fef4c commit 7df9075

File tree

14 files changed

+211
-20
lines changed

14 files changed

+211
-20
lines changed

arch/csky/Kconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@ config CSKY
88
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
99
select ARCH_USE_BUILTIN_BSWAP
1010
select ARCH_USE_QUEUED_RWLOCKS
11+
select ARCH_USE_QUEUED_SPINLOCKS
12+
select ARCH_INLINE_READ_LOCK if !PREEMPTION
13+
select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION
14+
select ARCH_INLINE_READ_LOCK_IRQ if !PREEMPTION
15+
select ARCH_INLINE_READ_LOCK_IRQSAVE if !PREEMPTION
16+
select ARCH_INLINE_READ_UNLOCK if !PREEMPTION
17+
select ARCH_INLINE_READ_UNLOCK_BH if !PREEMPTION
18+
select ARCH_INLINE_READ_UNLOCK_IRQ if !PREEMPTION
19+
select ARCH_INLINE_READ_UNLOCK_IRQRESTORE if !PREEMPTION
20+
select ARCH_INLINE_WRITE_LOCK if !PREEMPTION
21+
select ARCH_INLINE_WRITE_LOCK_BH if !PREEMPTION
22+
select ARCH_INLINE_WRITE_LOCK_IRQ if !PREEMPTION
23+
select ARCH_INLINE_WRITE_LOCK_IRQSAVE if !PREEMPTION
24+
select ARCH_INLINE_WRITE_UNLOCK if !PREEMPTION
25+
select ARCH_INLINE_WRITE_UNLOCK_BH if !PREEMPTION
26+
select ARCH_INLINE_WRITE_UNLOCK_IRQ if !PREEMPTION
27+
select ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE if !PREEMPTION
28+
select ARCH_INLINE_SPIN_TRYLOCK if !PREEMPTION
29+
select ARCH_INLINE_SPIN_TRYLOCK_BH if !PREEMPTION
30+
select ARCH_INLINE_SPIN_LOCK if !PREEMPTION
31+
select ARCH_INLINE_SPIN_LOCK_BH if !PREEMPTION
32+
select ARCH_INLINE_SPIN_LOCK_IRQ if !PREEMPTION
33+
select ARCH_INLINE_SPIN_LOCK_IRQSAVE if !PREEMPTION
34+
select ARCH_INLINE_SPIN_UNLOCK if !PREEMPTION
35+
select ARCH_INLINE_SPIN_UNLOCK_BH if !PREEMPTION
36+
select ARCH_INLINE_SPIN_UNLOCK_IRQ if !PREEMPTION
37+
select ARCH_INLINE_SPIN_UNLOCK_IRQRESTORE if !PREEMPTION
1138
select ARCH_WANT_FRAME_POINTERS if !CPU_CK610 && $(cc-option,-mbacktrace)
1239
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
1340
select COMMON_CLK
@@ -40,6 +67,8 @@ config CSKY
4067
select GX6605S_TIMER if CPU_CK610
4168
select HAVE_ARCH_TRACEHOOK
4269
select HAVE_ARCH_AUDITSYSCALL
70+
select HAVE_ARCH_JUMP_LABEL if !CPU_CK610
71+
select HAVE_ARCH_JUMP_LABEL_RELATIVE
4372
select HAVE_ARCH_MMAP_RND_BITS
4473
select HAVE_ARCH_SECCOMP_FILTER
4574
select HAVE_CONTEXT_TRACKING_USER

arch/csky/abiv1/inc/abi/string.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
#define __HAVE_ARCH_MEMCPY
77
extern void *memcpy(void *, const void *, __kernel_size_t);
88

9+
#define __HAVE_ARCH_MEMMOVE
10+
extern void *memmove(void *, const void *, __kernel_size_t);
11+
12+
#define __HAVE_ARCH_MEMSET
13+
extern void *memset(void *, int, __kernel_size_t);
14+
915
#endif /* __ABI_CSKY_STRING_H */

arch/csky/include/asm/Kbuild

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ generic-y += asm-offsets.h
33
generic-y += extable.h
44
generic-y += gpio.h
55
generic-y += kvm_para.h
6-
generic-y += spinlock.h
7-
generic-y += spinlock_types.h
6+
generic-y += mcs_spinlock.h
87
generic-y += qrwlock.h
98
generic-y += qrwlock_types.h
9+
generic-y += qspinlock.h
1010
generic-y += parport.h
1111
generic-y += user.h
1212
generic-y += vmlinux.lds.h

arch/csky/include/asm/cmpxchg.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,36 @@
44
#define __ASM_CSKY_CMPXCHG_H
55

66
#ifdef CONFIG_SMP
7+
#include <linux/bug.h>
78
#include <asm/barrier.h>
89

9-
extern void __bad_xchg(void);
10-
1110
#define __xchg_relaxed(new, ptr, size) \
1211
({ \
1312
__typeof__(ptr) __ptr = (ptr); \
1413
__typeof__(new) __new = (new); \
1514
__typeof__(*(ptr)) __ret; \
1615
unsigned long tmp; \
1716
switch (size) { \
17+
case 2: { \
18+
u32 ret; \
19+
u32 shif = ((ulong)__ptr & 2) ? 16 : 0; \
20+
u32 mask = 0xffff << shif; \
21+
__ptr = (__typeof__(ptr))((ulong)__ptr & ~2); \
22+
__asm__ __volatile__ ( \
23+
"1: ldex.w %0, (%4)\n" \
24+
" and %1, %0, %2\n" \
25+
" or %1, %1, %3\n" \
26+
" stex.w %1, (%4)\n" \
27+
" bez %1, 1b\n" \
28+
: "=&r" (ret), "=&r" (tmp) \
29+
: "r" (~mask), \
30+
"r" ((u32)__new << shif), \
31+
"r" (__ptr) \
32+
: "memory"); \
33+
__ret = (__typeof__(*(ptr))) \
34+
((ret & mask) >> shif); \
35+
break; \
36+
} \
1837
case 4: \
1938
asm volatile ( \
2039
"1: ldex.w %0, (%3) \n" \
@@ -26,7 +45,7 @@ extern void __bad_xchg(void);
2645
:); \
2746
break; \
2847
default: \
29-
__bad_xchg(); \
48+
BUILD_BUG(); \
3049
} \
3150
__ret; \
3251
})
@@ -56,7 +75,7 @@ extern void __bad_xchg(void);
5675
:); \
5776
break; \
5877
default: \
59-
__bad_xchg(); \
78+
BUILD_BUG(); \
6079
} \
6180
__ret; \
6281
})
@@ -87,7 +106,7 @@ extern void __bad_xchg(void);
87106
:); \
88107
break; \
89108
default: \
90-
__bad_xchg(); \
109+
BUILD_BUG(); \
91110
} \
92111
__ret; \
93112
})
@@ -119,7 +138,7 @@ extern void __bad_xchg(void);
119138
:); \
120139
break; \
121140
default: \
122-
__bad_xchg(); \
141+
BUILD_BUG(); \
123142
} \
124143
__ret; \
125144
})

arch/csky/include/asm/jump_label.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#ifndef __ASM_CSKY_JUMP_LABEL_H
4+
#define __ASM_CSKY_JUMP_LABEL_H
5+
6+
#ifndef __ASSEMBLY__
7+
8+
#include <linux/types.h>
9+
10+
#define JUMP_LABEL_NOP_SIZE 4
11+
12+
static __always_inline bool arch_static_branch(struct static_key *key,
13+
bool branch)
14+
{
15+
asm_volatile_goto(
16+
"1: nop32 \n"
17+
" .pushsection __jump_table, \"aw\" \n"
18+
" .align 2 \n"
19+
" .long 1b - ., %l[label] - . \n"
20+
" .long %0 - . \n"
21+
" .popsection \n"
22+
: : "i"(&((char *)key)[branch]) : : label);
23+
24+
return false;
25+
label:
26+
return true;
27+
}
28+
29+
static __always_inline bool arch_static_branch_jump(struct static_key *key,
30+
bool branch)
31+
{
32+
asm_volatile_goto(
33+
"1: bsr32 %l[label] \n"
34+
" .pushsection __jump_table, \"aw\" \n"
35+
" .align 2 \n"
36+
" .long 1b - ., %l[label] - . \n"
37+
" .long %0 - . \n"
38+
" .popsection \n"
39+
: : "i"(&((char *)key)[branch]) : : label);
40+
41+
return false;
42+
label:
43+
return true;
44+
}
45+
46+
#endif /* __ASSEMBLY__ */
47+
#endif /* __ASM_CSKY_JUMP_LABEL_H */

arch/csky/include/asm/sections.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __ASM_SECTIONS_H
4+
#define __ASM_SECTIONS_H
5+
6+
#include <asm-generic/sections.h>
7+
8+
extern char _start[];
9+
10+
#endif /* __ASM_SECTIONS_H */

arch/csky/include/asm/spinlock.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __ASM_CSKY_SPINLOCK_H
4+
#define __ASM_CSKY_SPINLOCK_H
5+
6+
#include <asm/qspinlock.h>
7+
#include <asm/qrwlock.h>
8+
9+
/* See include/linux/spinlock.h */
10+
#define smp_mb__after_spinlock() smp_mb()
11+
12+
#endif /* __ASM_CSKY_SPINLOCK_H */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __ASM_CSKY_SPINLOCK_TYPES_H
4+
#define __ASM_CSKY_SPINLOCK_TYPES_H
5+
6+
#include <asm-generic/qspinlock_types.h>
7+
#include <asm-generic/qrwlock_types.h>
8+
9+
#endif /* __ASM_CSKY_SPINLOCK_TYPES_H */

arch/csky/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ obj-$(CONFIG_STACKTRACE) += stacktrace.o
1313
obj-$(CONFIG_CSKY_PMU_V1) += perf_event.o
1414
obj-$(CONFIG_PERF_EVENTS) += perf_callchain.o
1515
obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o
16+
obj-$(CONFIG_JUMP_LABEL) += jump_label.o
1617

1718
ifdef CONFIG_FUNCTION_TRACER
1819
CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)

arch/csky/kernel/jump_label.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include <linux/jump_label.h>
4+
#include <linux/kernel.h>
5+
#include <linux/memory.h>
6+
#include <linux/mutex.h>
7+
#include <linux/uaccess.h>
8+
#include <asm/cacheflush.h>
9+
10+
#define NOP32_HI 0xc400
11+
#define NOP32_LO 0x4820
12+
#define BSR_LINK 0xe000
13+
14+
void arch_jump_label_transform(struct jump_entry *entry,
15+
enum jump_label_type type)
16+
{
17+
unsigned long addr = jump_entry_code(entry);
18+
u16 insn[2];
19+
int ret = 0;
20+
21+
if (type == JUMP_LABEL_JMP) {
22+
long offset = jump_entry_target(entry) - jump_entry_code(entry);
23+
24+
if (WARN_ON(offset & 1 || offset < -67108864 || offset >= 67108864))
25+
return;
26+
27+
offset = offset >> 1;
28+
29+
insn[0] = BSR_LINK |
30+
((uint16_t)((unsigned long) offset >> 16) & 0x3ff);
31+
insn[1] = (uint16_t)((unsigned long) offset & 0xffff);
32+
} else {
33+
insn[0] = NOP32_HI;
34+
insn[1] = NOP32_LO;
35+
}
36+
37+
ret = copy_to_kernel_nofault((void *)addr, insn, 4);
38+
WARN_ON(ret);
39+
40+
flush_icache_range(addr, addr + 4);
41+
}
42+
43+
void arch_jump_label_transform_static(struct jump_entry *entry,
44+
enum jump_label_type type)
45+
{
46+
/*
47+
* We use the same instructions in the arch_static_branch and
48+
* arch_static_branch_jump inline functions, so there's no
49+
* need to patch them up here.
50+
* The core will call arch_jump_label_transform when those
51+
* instructions need to be replaced.
52+
*/
53+
arch_jump_label_transform(entry, type);
54+
}

0 commit comments

Comments
 (0)