Skip to content

Commit 6032aca

Browse files
jmberg-intelrichardweinberger
authored andcommitted
um: make stub data pages size tweakable
There's a lot of code here that hard-codes that the data is a single page, and right now that seems to be sufficient, but to make it easier to change this in the future, add a new STUB_DATA_PAGES constant and use it throughout the code. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent fc54a4f commit 6032aca

8 files changed

Lines changed: 27 additions & 21 deletions

File tree

arch/um/include/shared/as-layout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#define STUB_START stub_start
2424
#define STUB_CODE STUB_START
2525
#define STUB_DATA (STUB_CODE + UM_KERN_PAGE_SIZE)
26-
#define STUB_END (STUB_DATA + UM_KERN_PAGE_SIZE)
26+
#define STUB_DATA_PAGES 1 /* must be a power of two */
27+
#define STUB_END (STUB_DATA + STUB_DATA_PAGES * UM_KERN_PAGE_SIZE)
2728

2829
#ifndef __ASSEMBLY__
2930

arch/um/kernel/skas/clone.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
void __attribute__ ((__section__ (".__syscall_stub")))
2525
stub_clone_handler(void)
2626
{
27-
struct stub_data *data = get_stub_page();
27+
struct stub_data *data = get_stub_data();
2828
long err;
2929

3030
err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
31-
(unsigned long)data + UM_KERN_PAGE_SIZE / 2);
31+
(unsigned long)data +
32+
STUB_DATA_PAGES * UM_KERN_PAGE_SIZE / 2);
3233
if (err) {
3334
data->parent_err = err;
3435
goto done;

arch/um/kernel/skas/mmu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
2121
unsigned long stack = 0;
2222
int ret = -ENOMEM;
2323

24-
stack = get_zeroed_page(GFP_KERNEL);
24+
stack = __get_free_pages(GFP_KERNEL | __GFP_ZERO, ilog2(STUB_DATA_PAGES));
2525
if (stack == 0)
2626
goto out;
2727

@@ -52,7 +52,7 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
5252

5353
out_free:
5454
if (to_mm->id.stack != 0)
55-
free_page(to_mm->id.stack);
55+
free_pages(to_mm->id.stack, ilog2(STUB_DATA_PAGES));
5656
out:
5757
return ret;
5858
}
@@ -74,6 +74,6 @@ void destroy_context(struct mm_struct *mm)
7474
}
7575
os_kill_ptraced_process(mmu->id.u.pid, 1);
7676

77-
free_page(mmu->id.stack);
77+
free_pages(mmu->id.stack, ilog2(STUB_DATA_PAGES));
7878
free_ldt(mmu);
7979
}

arch/um/kernel/um_arch.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,13 @@ int __init linux_main(int argc, char **argv)
326326
add_arg(DEFAULT_COMMAND_LINE_CONSOLE);
327327

328328
host_task_size = os_get_top_address();
329-
/* reserve two pages for the stubs */
330-
host_task_size -= 2 * PAGE_SIZE;
331-
stub_start = host_task_size;
329+
/* reserve a few pages for the stubs (taking care of data alignment) */
330+
/* align the data portion */
331+
BUILD_BUG_ON(!is_power_of_2(STUB_DATA_PAGES));
332+
stub_start = (host_task_size - 1) & ~(STUB_DATA_PAGES * PAGE_SIZE - 1);
333+
/* another page for the code portion */
334+
stub_start -= PAGE_SIZE;
335+
host_task_size = stub_start;
332336

333337
/*
334338
* TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps

arch/um/os-Linux/skas/process.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static int userspace_tramp(void *stack)
262262
if (stack != NULL) {
263263
fd = phys_mapping(uml_to_phys(stack), &offset);
264264
addr = mmap((void *) STUB_DATA,
265-
UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
265+
STUB_DATA_PAGES * UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
266266
MAP_FIXED | MAP_SHARED, fd, offset);
267267
if (addr == MAP_FAILED) {
268268
printk(UM_KERN_ERR "mapping segfault stack at 0x%lx failed, errno = %d\n",
@@ -277,7 +277,7 @@ static int userspace_tramp(void *stack)
277277
(unsigned long) stub_segv_handler -
278278
(unsigned long) __syscall_stub_start;
279279

280-
set_sigstack((void *) STUB_DATA, UM_KERN_PAGE_SIZE);
280+
set_sigstack((void *) STUB_DATA, STUB_DATA_PAGES * UM_KERN_PAGE_SIZE);
281281
sigemptyset(&sa.sa_mask);
282282
sa.sa_flags = SA_ONSTACK | SA_NODEFER | SA_SIGINFO;
283283
sa.sa_sigaction = (void *) v;
@@ -515,7 +515,7 @@ static int __init init_thread_regs(void)
515515
thread_regs[REGS_IP_INDEX] = STUB_CODE +
516516
(unsigned long) stub_clone_handler -
517517
(unsigned long) __syscall_stub_start;
518-
thread_regs[REGS_SP_INDEX] = STUB_DATA + UM_KERN_PAGE_SIZE -
518+
thread_regs[REGS_SP_INDEX] = STUB_DATA + STUB_DATA_PAGES * UM_KERN_PAGE_SIZE -
519519
sizeof(void *);
520520
#ifdef __SIGNAL_FRAMESIZE
521521
thread_regs[REGS_SP_INDEX] -= __SIGNAL_FRAMESIZE;

arch/x86/um/shared/sysdep/stub_32.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,27 @@ static inline void remap_stack_and_trap(void)
8989
"addl %4,%%ebx ; movl %%eax, (%%ebx) ;"
9090
"int $3"
9191
: :
92-
"g" (~(UM_KERN_PAGE_SIZE - 1)),
92+
"g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)),
9393
"g" (STUB_MMAP_NR),
9494
"g" (UML_STUB_FIELD_FD),
9595
"g" (UML_STUB_FIELD_OFFSET),
9696
"g" (UML_STUB_FIELD_CHILD_ERR),
97-
"c" (UM_KERN_PAGE_SIZE),
97+
"c" (STUB_DATA_PAGES * UM_KERN_PAGE_SIZE),
9898
"d" (PROT_READ | PROT_WRITE),
9999
"S" (MAP_FIXED | MAP_SHARED)
100100
:
101101
"memory");
102102
}
103103

104-
static __always_inline void *get_stub_page(void)
104+
static __always_inline void *get_stub_data(void)
105105
{
106106
unsigned long ret;
107107

108108
asm volatile (
109109
"movl %%esp,%0 ;"
110110
"andl %1,%0"
111111
: "=a" (ret)
112-
: "g" (~(UM_KERN_PAGE_SIZE - 1)));
112+
: "g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)));
113113

114114
return (void *)ret;
115115
}

arch/x86/um/shared/sysdep/stub_64.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,26 @@ static inline void remap_stack_and_trap(void)
9898
"int3"
9999
: :
100100
"g" (STUB_MMAP_NR),
101-
"g" (~(UM_KERN_PAGE_SIZE - 1)),
101+
"g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)),
102102
"g" (MAP_FIXED | MAP_SHARED),
103103
"g" (UML_STUB_FIELD_FD),
104104
"g" (UML_STUB_FIELD_OFFSET),
105105
"g" (UML_STUB_FIELD_CHILD_ERR),
106-
"S" (UM_KERN_PAGE_SIZE),
106+
"S" (STUB_DATA_PAGES * UM_KERN_PAGE_SIZE),
107107
"d" (PROT_READ | PROT_WRITE)
108108
:
109109
__syscall_clobber, "r10", "r8", "r9");
110110
}
111111

112-
static __always_inline void *get_stub_page(void)
112+
static __always_inline void *get_stub_data(void)
113113
{
114114
unsigned long ret;
115115

116116
asm volatile (
117117
"movq %%rsp,%0 ;"
118118
"andq %1,%0"
119119
: "=a" (ret)
120-
: "g" (~(UM_KERN_PAGE_SIZE - 1)));
120+
: "g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)));
121121

122122
return (void *)ret;
123123
}

arch/x86/um/stub_segv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
void __attribute__ ((__section__ (".__syscall_stub")))
1212
stub_segv_handler(int sig, siginfo_t *info, void *p)
1313
{
14-
struct faultinfo *f = get_stub_page();
14+
struct faultinfo *f = get_stub_data();
1515
ucontext_t *uc = p;
1616

1717
GET_FAULTINFO_FROM_MC(*f, &uc->uc_mcontext);

0 commit comments

Comments
 (0)