Skip to content

Commit 999c83e

Browse files
Christoph HellwigAl Viro
authored andcommitted
x86: move PAGE_OFFSET, TASK_SIZE & friends to page_{32,64}_types.h
At least for 64-bit this moves them closer to some of the defines they are based on, and it prepares for using the TASK_SIZE_MAX definition from assembly. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent c6f7c75 commit 999c83e

3 files changed

Lines changed: 49 additions & 49 deletions

File tree

arch/x86/include/asm/page_32_types.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@
4141
#define __VIRTUAL_MASK_SHIFT 32
4242
#endif /* CONFIG_X86_PAE */
4343

44+
/*
45+
* User space process size: 3GB (default).
46+
*/
47+
#define IA32_PAGE_OFFSET PAGE_OFFSET
48+
#define TASK_SIZE PAGE_OFFSET
49+
#define TASK_SIZE_LOW TASK_SIZE
50+
#define TASK_SIZE_MAX TASK_SIZE
51+
#define DEFAULT_MAP_WINDOW TASK_SIZE
52+
#define STACK_TOP TASK_SIZE
53+
#define STACK_TOP_MAX STACK_TOP
54+
4455
/*
4556
* Kernel image size is limited to 512 MB (see in arch/x86/kernel/head_32.S)
4657
*/

arch/x86/include/asm/page_64_types.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,44 @@
5858
#define __VIRTUAL_MASK_SHIFT 47
5959
#endif
6060

61+
/*
62+
* User space process size. This is the first address outside the user range.
63+
* There are a few constraints that determine this:
64+
*
65+
* On Intel CPUs, if a SYSCALL instruction is at the highest canonical
66+
* address, then that syscall will enter the kernel with a
67+
* non-canonical return address, and SYSRET will explode dangerously.
68+
* We avoid this particular problem by preventing anything executable
69+
* from being mapped at the maximum canonical address.
70+
*
71+
* On AMD CPUs in the Ryzen family, there's a nasty bug in which the
72+
* CPUs malfunction if they execute code from the highest canonical page.
73+
* They'll speculate right off the end of the canonical space, and
74+
* bad things happen. This is worked around in the same way as the
75+
* Intel problem.
76+
*
77+
* With page table isolation enabled, we map the LDT in ... [stay tuned]
78+
*/
79+
#define TASK_SIZE_MAX ((1UL << __VIRTUAL_MASK_SHIFT) - PAGE_SIZE)
80+
81+
#define DEFAULT_MAP_WINDOW ((1UL << 47) - PAGE_SIZE)
82+
83+
/* This decides where the kernel will search for a free chunk of vm
84+
* space during mmap's.
85+
*/
86+
#define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
87+
0xc0000000 : 0xFFFFe000)
88+
89+
#define TASK_SIZE_LOW (test_thread_flag(TIF_ADDR32) ? \
90+
IA32_PAGE_OFFSET : DEFAULT_MAP_WINDOW)
91+
#define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
92+
IA32_PAGE_OFFSET : TASK_SIZE_MAX)
93+
#define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_ADDR32)) ? \
94+
IA32_PAGE_OFFSET : TASK_SIZE_MAX)
95+
96+
#define STACK_TOP TASK_SIZE_LOW
97+
#define STACK_TOP_MAX TASK_SIZE_MAX
98+
6199
/*
62100
* Maximum kernel image size is limited to 1 GiB, due to the fixmap living
63101
* in the next 1 GiB (see level2_kernel_pgt in arch/x86/kernel/head_64.S).

arch/x86/include/asm/processor.h

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -782,17 +782,6 @@ static inline void spin_lock_prefetch(const void *x)
782782
})
783783

784784
#ifdef CONFIG_X86_32
785-
/*
786-
* User space process size: 3GB (default).
787-
*/
788-
#define IA32_PAGE_OFFSET PAGE_OFFSET
789-
#define TASK_SIZE PAGE_OFFSET
790-
#define TASK_SIZE_LOW TASK_SIZE
791-
#define TASK_SIZE_MAX TASK_SIZE
792-
#define DEFAULT_MAP_WINDOW TASK_SIZE
793-
#define STACK_TOP TASK_SIZE
794-
#define STACK_TOP_MAX STACK_TOP
795-
796785
#define INIT_THREAD { \
797786
.sp0 = TOP_OF_INIT_STACK, \
798787
.sysenter_cs = __KERNEL_CS, \
@@ -802,44 +791,6 @@ static inline void spin_lock_prefetch(const void *x)
802791
#define KSTK_ESP(task) (task_pt_regs(task)->sp)
803792

804793
#else
805-
/*
806-
* User space process size. This is the first address outside the user range.
807-
* There are a few constraints that determine this:
808-
*
809-
* On Intel CPUs, if a SYSCALL instruction is at the highest canonical
810-
* address, then that syscall will enter the kernel with a
811-
* non-canonical return address, and SYSRET will explode dangerously.
812-
* We avoid this particular problem by preventing anything executable
813-
* from being mapped at the maximum canonical address.
814-
*
815-
* On AMD CPUs in the Ryzen family, there's a nasty bug in which the
816-
* CPUs malfunction if they execute code from the highest canonical page.
817-
* They'll speculate right off the end of the canonical space, and
818-
* bad things happen. This is worked around in the same way as the
819-
* Intel problem.
820-
*
821-
* With page table isolation enabled, we map the LDT in ... [stay tuned]
822-
*/
823-
#define TASK_SIZE_MAX ((1UL << __VIRTUAL_MASK_SHIFT) - PAGE_SIZE)
824-
825-
#define DEFAULT_MAP_WINDOW ((1UL << 47) - PAGE_SIZE)
826-
827-
/* This decides where the kernel will search for a free chunk of vm
828-
* space during mmap's.
829-
*/
830-
#define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
831-
0xc0000000 : 0xFFFFe000)
832-
833-
#define TASK_SIZE_LOW (test_thread_flag(TIF_ADDR32) ? \
834-
IA32_PAGE_OFFSET : DEFAULT_MAP_WINDOW)
835-
#define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
836-
IA32_PAGE_OFFSET : TASK_SIZE_MAX)
837-
#define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_ADDR32)) ? \
838-
IA32_PAGE_OFFSET : TASK_SIZE_MAX)
839-
840-
#define STACK_TOP TASK_SIZE_LOW
841-
#define STACK_TOP_MAX TASK_SIZE_MAX
842-
843794
#define INIT_THREAD { \
844795
.addr_limit = KERNEL_DS, \
845796
}

0 commit comments

Comments
 (0)