Skip to content

Commit 932562a

Browse files
author
Kent Overstreet
committed
rseq: Split out rseq.h from sched.h
We're trying to get sched.h down to more or less just types only, not code - rseq can live in its own header. This helps us kill the dependency on preempt.h in sched.h. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent c968b99 commit 932562a

File tree

10 files changed

+140
-124
lines changed

10 files changed

+140
-124
lines changed

arch/arm64/kernel/ptrace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/hw_breakpoint.h>
2929
#include <linux/regset.h>
3030
#include <linux/elf.h>
31+
#include <linux/rseq.h>
3132

3233
#include <asm/compat.h>
3334
#include <asm/cpufeature.h>

arch/powerpc/kernel/interrupt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/context_tracking.h>
44
#include <linux/err.h>
55
#include <linux/compat.h>
6+
#include <linux/rseq.h>
67
#include <linux/sched/debug.h> /* for show_regs */
78

89
#include <asm/kup.h>

arch/s390/kernel/signal.c

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

1313
#include <linux/sched.h>
1414
#include <linux/sched/task_stack.h>
15+
#include <linux/rseq.h>
1516
#include <linux/mm.h>
1617
#include <linux/smp.h>
1718
#include <linux/kernel.h>

arch/x86/kernel/signal.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/context_tracking.h>
2828
#include <linux/entry-common.h>
2929
#include <linux/syscalls.h>
30+
#include <linux/rseq.h>
3031

3132
#include <asm/processor.h>
3233
#include <asm/ucontext.h>

fs/exec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include <linux/coredump.h>
6767
#include <linux/time_namespace.h>
6868
#include <linux/user_events.h>
69+
#include <linux/rseq.h>
6970

7071
#include <linux/uaccess.h>
7172
#include <asm/mmu_context.h>

include/linux/resume_user_mode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/sched.h>
77
#include <linux/task_work.h>
88
#include <linux/memcontrol.h>
9+
#include <linux/rseq.h>
910
#include <linux/blk-cgroup.h>
1011

1112
/**

include/linux/rseq.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2+
#ifndef _LINUX_RSEQ_H
3+
#define _LINUX_RSEQ_H
4+
5+
#ifdef CONFIG_RSEQ
6+
7+
#include <linux/preempt.h>
8+
#include <linux/sched.h>
9+
10+
/*
11+
* Map the event mask on the user-space ABI enum rseq_cs_flags
12+
* for direct mask checks.
13+
*/
14+
enum rseq_event_mask_bits {
15+
RSEQ_EVENT_PREEMPT_BIT = RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT,
16+
RSEQ_EVENT_SIGNAL_BIT = RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT,
17+
RSEQ_EVENT_MIGRATE_BIT = RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT,
18+
};
19+
20+
enum rseq_event_mask {
21+
RSEQ_EVENT_PREEMPT = (1U << RSEQ_EVENT_PREEMPT_BIT),
22+
RSEQ_EVENT_SIGNAL = (1U << RSEQ_EVENT_SIGNAL_BIT),
23+
RSEQ_EVENT_MIGRATE = (1U << RSEQ_EVENT_MIGRATE_BIT),
24+
};
25+
26+
static inline void rseq_set_notify_resume(struct task_struct *t)
27+
{
28+
if (t->rseq)
29+
set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
30+
}
31+
32+
void __rseq_handle_notify_resume(struct ksignal *sig, struct pt_regs *regs);
33+
34+
static inline void rseq_handle_notify_resume(struct ksignal *ksig,
35+
struct pt_regs *regs)
36+
{
37+
if (current->rseq)
38+
__rseq_handle_notify_resume(ksig, regs);
39+
}
40+
41+
static inline void rseq_signal_deliver(struct ksignal *ksig,
42+
struct pt_regs *regs)
43+
{
44+
preempt_disable();
45+
__set_bit(RSEQ_EVENT_SIGNAL_BIT, &current->rseq_event_mask);
46+
preempt_enable();
47+
rseq_handle_notify_resume(ksig, regs);
48+
}
49+
50+
/* rseq_preempt() requires preemption to be disabled. */
51+
static inline void rseq_preempt(struct task_struct *t)
52+
{
53+
__set_bit(RSEQ_EVENT_PREEMPT_BIT, &t->rseq_event_mask);
54+
rseq_set_notify_resume(t);
55+
}
56+
57+
/* rseq_migrate() requires preemption to be disabled. */
58+
static inline void rseq_migrate(struct task_struct *t)
59+
{
60+
__set_bit(RSEQ_EVENT_MIGRATE_BIT, &t->rseq_event_mask);
61+
rseq_set_notify_resume(t);
62+
}
63+
64+
/*
65+
* If parent process has a registered restartable sequences area, the
66+
* child inherits. Unregister rseq for a clone with CLONE_VM set.
67+
*/
68+
static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags)
69+
{
70+
if (clone_flags & CLONE_VM) {
71+
t->rseq = NULL;
72+
t->rseq_len = 0;
73+
t->rseq_sig = 0;
74+
t->rseq_event_mask = 0;
75+
} else {
76+
t->rseq = current->rseq;
77+
t->rseq_len = current->rseq_len;
78+
t->rseq_sig = current->rseq_sig;
79+
t->rseq_event_mask = current->rseq_event_mask;
80+
}
81+
}
82+
83+
static inline void rseq_execve(struct task_struct *t)
84+
{
85+
t->rseq = NULL;
86+
t->rseq_len = 0;
87+
t->rseq_sig = 0;
88+
t->rseq_event_mask = 0;
89+
}
90+
91+
#else
92+
93+
static inline void rseq_set_notify_resume(struct task_struct *t)
94+
{
95+
}
96+
static inline void rseq_handle_notify_resume(struct ksignal *ksig,
97+
struct pt_regs *regs)
98+
{
99+
}
100+
static inline void rseq_signal_deliver(struct ksignal *ksig,
101+
struct pt_regs *regs)
102+
{
103+
}
104+
static inline void rseq_preempt(struct task_struct *t)
105+
{
106+
}
107+
static inline void rseq_migrate(struct task_struct *t)
108+
{
109+
}
110+
static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags)
111+
{
112+
}
113+
static inline void rseq_execve(struct task_struct *t)
114+
{
115+
}
116+
117+
#endif
118+
119+
#ifdef CONFIG_DEBUG_RSEQ
120+
121+
void rseq_syscall(struct pt_regs *regs);
122+
123+
#else
124+
125+
static inline void rseq_syscall(struct pt_regs *regs)
126+
{
127+
}
128+
129+
#endif
130+
131+
#endif /* _LINUX_RSEQ_H */

include/linux/sched.h

Lines changed: 1 addition & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include <linux/task_io_accounting.h>
3636
#include <linux/posix-timers_types.h>
3737
#include <linux/restart_block.h>
38-
#include <linux/rseq.h>
38+
#include <uapi/linux/rseq.h>
3939
#include <linux/seqlock_types.h>
4040
#include <linux/kcsan.h>
4141
#include <linux/rv.h>
@@ -2181,129 +2181,6 @@ static inline bool owner_on_cpu(struct task_struct *owner)
21812181
unsigned long sched_cpu_util(int cpu);
21822182
#endif /* CONFIG_SMP */
21832183

2184-
#ifdef CONFIG_RSEQ
2185-
2186-
/*
2187-
* Map the event mask on the user-space ABI enum rseq_cs_flags
2188-
* for direct mask checks.
2189-
*/
2190-
enum rseq_event_mask_bits {
2191-
RSEQ_EVENT_PREEMPT_BIT = RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT,
2192-
RSEQ_EVENT_SIGNAL_BIT = RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT,
2193-
RSEQ_EVENT_MIGRATE_BIT = RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT,
2194-
};
2195-
2196-
enum rseq_event_mask {
2197-
RSEQ_EVENT_PREEMPT = (1U << RSEQ_EVENT_PREEMPT_BIT),
2198-
RSEQ_EVENT_SIGNAL = (1U << RSEQ_EVENT_SIGNAL_BIT),
2199-
RSEQ_EVENT_MIGRATE = (1U << RSEQ_EVENT_MIGRATE_BIT),
2200-
};
2201-
2202-
static inline void rseq_set_notify_resume(struct task_struct *t)
2203-
{
2204-
if (t->rseq)
2205-
set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
2206-
}
2207-
2208-
void __rseq_handle_notify_resume(struct ksignal *sig, struct pt_regs *regs);
2209-
2210-
static inline void rseq_handle_notify_resume(struct ksignal *ksig,
2211-
struct pt_regs *regs)
2212-
{
2213-
if (current->rseq)
2214-
__rseq_handle_notify_resume(ksig, regs);
2215-
}
2216-
2217-
static inline void rseq_signal_deliver(struct ksignal *ksig,
2218-
struct pt_regs *regs)
2219-
{
2220-
preempt_disable();
2221-
__set_bit(RSEQ_EVENT_SIGNAL_BIT, &current->rseq_event_mask);
2222-
preempt_enable();
2223-
rseq_handle_notify_resume(ksig, regs);
2224-
}
2225-
2226-
/* rseq_preempt() requires preemption to be disabled. */
2227-
static inline void rseq_preempt(struct task_struct *t)
2228-
{
2229-
__set_bit(RSEQ_EVENT_PREEMPT_BIT, &t->rseq_event_mask);
2230-
rseq_set_notify_resume(t);
2231-
}
2232-
2233-
/* rseq_migrate() requires preemption to be disabled. */
2234-
static inline void rseq_migrate(struct task_struct *t)
2235-
{
2236-
__set_bit(RSEQ_EVENT_MIGRATE_BIT, &t->rseq_event_mask);
2237-
rseq_set_notify_resume(t);
2238-
}
2239-
2240-
/*
2241-
* If parent process has a registered restartable sequences area, the
2242-
* child inherits. Unregister rseq for a clone with CLONE_VM set.
2243-
*/
2244-
static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags)
2245-
{
2246-
if (clone_flags & CLONE_VM) {
2247-
t->rseq = NULL;
2248-
t->rseq_len = 0;
2249-
t->rseq_sig = 0;
2250-
t->rseq_event_mask = 0;
2251-
} else {
2252-
t->rseq = current->rseq;
2253-
t->rseq_len = current->rseq_len;
2254-
t->rseq_sig = current->rseq_sig;
2255-
t->rseq_event_mask = current->rseq_event_mask;
2256-
}
2257-
}
2258-
2259-
static inline void rseq_execve(struct task_struct *t)
2260-
{
2261-
t->rseq = NULL;
2262-
t->rseq_len = 0;
2263-
t->rseq_sig = 0;
2264-
t->rseq_event_mask = 0;
2265-
}
2266-
2267-
#else
2268-
2269-
static inline void rseq_set_notify_resume(struct task_struct *t)
2270-
{
2271-
}
2272-
static inline void rseq_handle_notify_resume(struct ksignal *ksig,
2273-
struct pt_regs *regs)
2274-
{
2275-
}
2276-
static inline void rseq_signal_deliver(struct ksignal *ksig,
2277-
struct pt_regs *regs)
2278-
{
2279-
}
2280-
static inline void rseq_preempt(struct task_struct *t)
2281-
{
2282-
}
2283-
static inline void rseq_migrate(struct task_struct *t)
2284-
{
2285-
}
2286-
static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags)
2287-
{
2288-
}
2289-
static inline void rseq_execve(struct task_struct *t)
2290-
{
2291-
}
2292-
2293-
#endif
2294-
2295-
#ifdef CONFIG_DEBUG_RSEQ
2296-
2297-
void rseq_syscall(struct pt_regs *regs);
2298-
2299-
#else
2300-
2301-
static inline void rseq_syscall(struct pt_regs *regs)
2302-
{
2303-
}
2304-
2305-
#endif
2306-
23072184
#ifdef CONFIG_SCHED_CORE
23082185
extern void sched_core_free(struct task_struct *tsk);
23092186
extern void sched_core_fork(struct task_struct *p);

kernel/fork.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#include <linux/stackprotector.h>
101101
#include <linux/user_events.h>
102102
#include <linux/iommu.h>
103+
#include <linux/rseq.h>
103104

104105
#include <asm/pgalloc.h>
105106
#include <linux/uaccess.h>

kernel/sched/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/profile.h>
5858
#include <linux/psi.h>
5959
#include <linux/rcuwait_api.h>
60+
#include <linux/rseq.h>
6061
#include <linux/sched/wake_q.h>
6162
#include <linux/scs.h>
6263
#include <linux/slab.h>

0 commit comments

Comments
 (0)