]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - arch/x86/include/asm/switch_to.h
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-focal-kernel.git] / arch / x86 / include / asm / switch_to.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
f05e798a
DH
2#ifndef _ASM_X86_SWITCH_TO_H
3#define _ASM_X86_SWITCH_TO_H
4
5struct task_struct; /* one of the stranger aspects of C forward declarations */
0100301b
BG
6
7struct task_struct *__switch_to_asm(struct task_struct *prev,
8 struct task_struct *next);
9
35ea7903 10__visible struct task_struct *__switch_to(struct task_struct *prev,
0100301b 11 struct task_struct *next);
f05e798a
DH
12struct tss_struct;
13void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
14 struct tss_struct *tss);
15
e37e43a4
AL
16/* This runs runs on the previous thread's stack. */
17static inline void prepare_switch_to(struct task_struct *prev,
18 struct task_struct *next)
19{
20#ifdef CONFIG_VMAP_STACK
21 /*
22 * If we switch to a stack that has a top-level paging entry
23 * that is not present in the current mm, the resulting #PF will
24 * will be promoted to a double-fault and we'll panic. Probe
25 * the new stack now so that vmalloc_fault can fix up the page
26 * tables if needed. This can only happen if we use a stack
27 * in vmap space.
28 *
29 * We assume that the stack is aligned so that it never spans
30 * more than one top-level paging entry.
31 *
32 * To minimize cache pollution, just follow the stack pointer.
33 */
34 READ_ONCE(*(unsigned char *)next->thread.sp);
35#endif
36}
37
616d2483
BG
38asmlinkage void ret_from_fork(void);
39
2c96b2fe
JP
40/*
41 * This is the structure pointed to by thread.sp for an inactive task. The
42 * order of the fields must match the code in __switch_to_asm().
43 */
7b32aead 44struct inactive_task_frame {
0100301b
BG
45#ifdef CONFIG_X86_64
46 unsigned long r15;
47 unsigned long r14;
48 unsigned long r13;
49 unsigned long r12;
50#else
51 unsigned long si;
52 unsigned long di;
53#endif
54 unsigned long bx;
2c96b2fe
JP
55
56 /*
57 * These two fields must be together. They form a stack frame header,
58 * needed by get_frame_pointer().
59 */
7b32aead 60 unsigned long bp;
0100301b 61 unsigned long ret_addr;
7b32aead
BG
62};
63
0100301b
BG
64struct fork_frame {
65 struct inactive_task_frame frame;
66 struct pt_regs regs;
67};
f05e798a 68
f05e798a
DH
69#define switch_to(prev, next, last) \
70do { \
e37e43a4
AL
71 prepare_switch_to(prev, next); \
72 \
0100301b 73 ((last) = __switch_to_asm((prev), (next))); \
f05e798a
DH
74} while (0)
75
f05e798a 76#endif /* _ASM_X86_SWITCH_TO_H */