David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 1 | #ifndef _ASM_X86_SWITCH_TO_H |
| 2 | #define _ASM_X86_SWITCH_TO_H |
| 3 | |
| 4 | struct task_struct; /* one of the stranger aspects of C forward declarations */ |
Brian Gerst | 0100301 | 2016-08-13 12:38:19 -0400 | [diff] [blame] | 5 | |
| 6 | struct task_struct *__switch_to_asm(struct task_struct *prev, |
| 7 | struct task_struct *next); |
| 8 | |
Andi Kleen | 35ea7903 | 2013-08-05 15:02:39 -0700 | [diff] [blame] | 9 | __visible struct task_struct *__switch_to(struct task_struct *prev, |
Brian Gerst | 0100301 | 2016-08-13 12:38:19 -0400 | [diff] [blame] | 10 | struct task_struct *next); |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 11 | |
Andy Lutomirski | e37e43a | 2016-08-11 02:35:23 -0700 | [diff] [blame] | 12 | /* This runs runs on the previous thread's stack. */ |
| 13 | static inline void prepare_switch_to(struct task_struct *prev, |
| 14 | struct task_struct *next) |
| 15 | { |
| 16 | #ifdef CONFIG_VMAP_STACK |
| 17 | /* |
| 18 | * If we switch to a stack that has a top-level paging entry |
| 19 | * that is not present in the current mm, the resulting #PF will |
| 20 | * will be promoted to a double-fault and we'll panic. Probe |
| 21 | * the new stack now so that vmalloc_fault can fix up the page |
| 22 | * tables if needed. This can only happen if we use a stack |
| 23 | * in vmap space. |
| 24 | * |
| 25 | * We assume that the stack is aligned so that it never spans |
| 26 | * more than one top-level paging entry. |
| 27 | * |
| 28 | * To minimize cache pollution, just follow the stack pointer. |
| 29 | */ |
| 30 | READ_ONCE(*(unsigned char *)next->thread.sp); |
| 31 | #endif |
| 32 | } |
| 33 | |
Brian Gerst | 616d248 | 2016-08-13 12:38:20 -0400 | [diff] [blame] | 34 | asmlinkage void ret_from_fork(void); |
| 35 | |
Brian Gerst | 7b32aea | 2016-08-13 12:38:18 -0400 | [diff] [blame] | 36 | /* data that is pointed to by thread.sp */ |
| 37 | struct inactive_task_frame { |
Peter Zijlstra | 45fe6de | 2019-02-14 10:30:52 +0100 | [diff] [blame] | 38 | unsigned long flags; |
Brian Gerst | 0100301 | 2016-08-13 12:38:19 -0400 | [diff] [blame] | 39 | #ifdef CONFIG_X86_64 |
| 40 | unsigned long r15; |
| 41 | unsigned long r14; |
| 42 | unsigned long r13; |
| 43 | unsigned long r12; |
| 44 | #else |
| 45 | unsigned long si; |
| 46 | unsigned long di; |
| 47 | #endif |
| 48 | unsigned long bx; |
Brian Gerst | 7b32aea | 2016-08-13 12:38:18 -0400 | [diff] [blame] | 49 | unsigned long bp; |
Brian Gerst | 0100301 | 2016-08-13 12:38:19 -0400 | [diff] [blame] | 50 | unsigned long ret_addr; |
Brian Gerst | 7b32aea | 2016-08-13 12:38:18 -0400 | [diff] [blame] | 51 | }; |
| 52 | |
Brian Gerst | 0100301 | 2016-08-13 12:38:19 -0400 | [diff] [blame] | 53 | struct fork_frame { |
| 54 | struct inactive_task_frame frame; |
| 55 | struct pt_regs regs; |
| 56 | }; |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 57 | |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 58 | #define switch_to(prev, next, last) \ |
| 59 | do { \ |
Andy Lutomirski | e37e43a | 2016-08-11 02:35:23 -0700 | [diff] [blame] | 60 | prepare_switch_to(prev, next); \ |
| 61 | \ |
Brian Gerst | 0100301 | 2016-08-13 12:38:19 -0400 | [diff] [blame] | 62 | ((last) = __switch_to_asm((prev), (next))); \ |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 63 | } while (0) |
| 64 | |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 65 | #endif /* _ASM_X86_SWITCH_TO_H */ |