[POC][PATCH 54/83] um: store stacks as pointers

From: Al Viro
Date: Mon Dec 21 2015 - 18:58:04 EST


From: Al Viro <viro@xxxxxxxxxxxxxxxxxx>

Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
---
arch/um/drivers/chan_user.c | 6 +++---
arch/um/drivers/chan_user.h | 2 +-
arch/um/drivers/line.c | 8 ++++----
arch/um/drivers/ubd.h | 2 +-
arch/um/drivers/ubd_kern.c | 2 +-
arch/um/drivers/ubd_user.c | 4 ++--
arch/um/include/shared/kern_util.h | 4 ++--
arch/um/include/shared/os.h | 6 +++---
arch/um/include/shared/skas/mm_id.h | 2 +-
arch/um/include/shared/skas/skas.h | 2 +-
arch/um/kernel/process.c | 11 ++++-------
arch/um/kernel/skas/mmu.c | 17 ++++++++---------
arch/um/kernel/skas/process.c | 4 ++--
arch/um/os-Linux/aio.c | 2 +-
arch/um/os-Linux/helper.c | 14 +++++++-------
arch/um/os-Linux/sigio.c | 2 +-
arch/um/os-Linux/skas/process.c | 19 +++++++++----------
17 files changed, 51 insertions(+), 56 deletions(-)

diff --git a/arch/um/drivers/chan_user.c b/arch/um/drivers/chan_user.c
index 3fd7c3e..bbda889 100644
--- a/arch/um/drivers/chan_user.c
+++ b/arch/um/drivers/chan_user.c
@@ -217,7 +217,7 @@ static int winch_thread(void *arg)
}

static int winch_tramp(int fd, struct tty_port *port, int *fd_out,
- unsigned long *stack_out)
+ void **stack_out)
{
struct winch_data data;
int fds[2], n, err;
@@ -273,7 +273,7 @@ static int winch_tramp(int fd, struct tty_port *port, int *fd_out,

void register_winch(int fd, struct tty_port *port)
{
- unsigned long stack;
+ void *stack;
int pid, thread, count, thread_fd = -1;
char c = 1;

@@ -282,7 +282,7 @@ void register_winch(int fd, struct tty_port *port)

pid = tcgetpgrp(fd);
if (is_skas_winch(pid, fd, port)) {
- register_winch_irq(-1, fd, -1, port, 0);
+ register_winch_irq(-1, fd, -1, port, NULL);
return;
}

diff --git a/arch/um/drivers/chan_user.h b/arch/um/drivers/chan_user.h
index 03f1b56..9cc900b 100644
--- a/arch/um/drivers/chan_user.h
+++ b/arch/um/drivers/chan_user.h
@@ -41,7 +41,7 @@ extern void generic_free(void *data);
struct tty_port;
extern void register_winch(int fd, struct tty_port *port);
extern void register_winch_irq(int fd, int tty_fd, int pid,
- struct tty_port *port, unsigned long stack);
+ struct tty_port *port, void *stack);

#define __channel_help(fn, prefix) \
__uml_help(fn, prefix "[0-9]*=<channel description>\n" \
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index 6208702..ae8a5b1 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -598,7 +598,7 @@ struct winch {
int tty_fd;
int pid;
struct tty_port *port;
- unsigned long stack;
+ void *stack;
struct work_struct work;
};

@@ -609,7 +609,7 @@ static void __free_winch(struct work_struct *work)

if (winch->pid != -1)
os_kill_process(winch->pid, 1);
- if (winch->stack != 0)
+ if (winch->stack)
free_stack(winch->stack, 0);
kfree(winch);
}
@@ -672,7 +672,7 @@ static irqreturn_t winch_interrupt(int irq, void *data)
}

void register_winch_irq(int fd, int tty_fd, int pid, struct tty_port *port,
- unsigned long stack)
+ void *stack)
{
struct winch *winch;

@@ -707,7 +707,7 @@ void register_winch_irq(int fd, int tty_fd, int pid, struct tty_port *port,
cleanup:
os_kill_process(pid, 1);
os_close_file(fd);
- if (stack != 0)
+ if (stack)
free_stack(stack, 0);
}

diff --git a/arch/um/drivers/ubd.h b/arch/um/drivers/ubd.h
index 3b48cd2..5507e2c 100644
--- a/arch/um/drivers/ubd.h
+++ b/arch/um/drivers/ubd.h
@@ -7,7 +7,7 @@
#ifndef __UM_UBD_USER_H
#define __UM_UBD_USER_H

-extern int start_io_thread(unsigned long sp, int *fds_out);
+extern int start_io_thread(void *sp, int *fds_out);
extern int io_thread(void *arg);
extern int kernel_fd;

diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index e8ab93c..e88fe7c 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -1082,7 +1082,7 @@ static int __init ubd_init(void)
late_initcall(ubd_init);

static int __init ubd_driver_init(void){
- unsigned long stack;
+ void *stack;
int err;

/* Set by CONFIG_BLK_DEV_UBD_SYNC or ubd=sync.*/
diff --git a/arch/um/drivers/ubd_user.c b/arch/um/drivers/ubd_user.c
index e376f9b..47791d4 100644
--- a/arch/um/drivers/ubd_user.c
+++ b/arch/um/drivers/ubd_user.c
@@ -21,7 +21,7 @@
#include "ubd.h"
#include <os.h>

-int start_io_thread(unsigned long sp, int *fd_out)
+int start_io_thread(void *sp, int *fd_out)
{
int pid, fds[2], err;

@@ -40,7 +40,7 @@ int start_io_thread(unsigned long sp, int *fd_out)
goto out_close;
}

- pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM, NULL);
+ pid = clone(io_thread, sp, CLONE_FILES | CLONE_VM, NULL);
if(pid < 0){
err = -errno;
printk("start_io_thread - clone failed : errno = %d\n", errno);
diff --git a/arch/um/include/shared/kern_util.h b/arch/um/include/shared/kern_util.h
index 35ab97e..886e362 100644
--- a/arch/um/include/shared/kern_util.h
+++ b/arch/um/include/shared/kern_util.h
@@ -19,8 +19,8 @@ extern int kmalloc_ok;
#define UML_ROUND_UP(addr) \
((((unsigned long) addr) + PAGE_SIZE - 1) & PAGE_MASK)

-extern unsigned long alloc_stack(int order, int atomic);
-extern void free_stack(unsigned long stack, int order);
+extern void *alloc_stack(int order, int atomic);
+extern void free_stack(void *stack, int order);

struct pt_regs;
extern void do_signal(struct pt_regs *regs);
diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
index 868e6c3..fc47885 100644
--- a/arch/um/include/shared/os.h
+++ b/arch/um/include/shared/os.h
@@ -210,7 +210,7 @@ extern int execvp_noalloc(char *buf, const char *file, char *const argv[]);
/* helper.c */
extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv);
extern int run_helper_thread(int (*proc)(void *), void *arg,
- unsigned int flags, unsigned long *stack_out);
+ unsigned int flags, void **stack_out);
extern int helper_wait(int pid);


@@ -270,8 +270,8 @@ extern int protect(struct mm_id * mm_idp, unsigned long addr,

/* skas/process.c */
extern int is_skas_winch(int pid, int fd, void *data);
-extern int start_userspace(unsigned long stub_stack);
-extern int copy_context_skas0(unsigned long stack, int pid);
+extern int start_userspace(void *stub_stack);
+extern int copy_context_skas0(void *stack, int pid);
extern void userspace(struct uml_pt_regs *regs);
extern int map_stub_pages(int fd, unsigned long code, unsigned long data,
unsigned long stack);
diff --git a/arch/um/include/shared/skas/mm_id.h b/arch/um/include/shared/skas/mm_id.h
index 48dd098..b75c535 100644
--- a/arch/um/include/shared/skas/mm_id.h
+++ b/arch/um/include/shared/skas/mm_id.h
@@ -11,7 +11,7 @@ struct mm_id {
int mm_fd;
int pid;
} u;
- unsigned long stack;
+ void *stack;
};

#endif
diff --git a/arch/um/include/shared/skas/skas.h b/arch/um/include/shared/skas/skas.h
index 911f3c4..689d0c6 100644
--- a/arch/um/include/shared/skas/skas.h
+++ b/arch/um/include/shared/skas/skas.h
@@ -14,6 +14,6 @@ extern int user_thread(unsigned long stack, int flags);
extern void new_thread_handler(void);
extern void handle_syscall(struct uml_pt_regs *regs);
extern long execute_syscall_skas(void *r);
-extern unsigned long current_stub_stack(void);
+extern void *current_stub_stack(void);

#endif
diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
index b77685b..69c8d56 100644
--- a/arch/um/kernel/process.c
+++ b/arch/um/kernel/process.c
@@ -55,21 +55,18 @@ int pid_to_processor_id(int pid)
return -1;
}

-void free_stack(unsigned long stack, int order)
+void free_stack(void *stack, int order)
{
- free_pages((void *)stack, order);
+ free_pages(stack, order);
}

-unsigned long alloc_stack(int order, int atomic)
+void *alloc_stack(int order, int atomic)
{
- unsigned long page;
gfp_t flags = GFP_KERNEL;

if (atomic)
flags = GFP_ATOMIC;
- page = __get_free_pages(flags, order);
-
- return page;
+ return (void *)__get_free_pages(flags, order);
}

static inline void set_current(struct task_struct *task)
diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c
index 6898b23..a0e5758 100644
--- a/arch/um/kernel/skas/mmu.c
+++ b/arch/um/kernel/skas/mmu.c
@@ -15,7 +15,7 @@
#include <skas.h>

static int init_stub_pte(struct mm_struct *mm, unsigned long proc,
- unsigned long kernel)
+ void *kernel)
{
pgd_t *pgd;
pud_t *pud;
@@ -51,11 +51,11 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
{
struct mm_context *from_mm = NULL;
struct mm_context *to_mm = &mm->context;
- unsigned long stack = 0;
+ void *stack;
int ret = -ENOMEM;

- stack = (unsigned long)get_zeroed_page(GFP_KERNEL);
- if (stack == 0)
+ stack = get_zeroed_page(GFP_KERNEL);
+ if (!stack)
goto out;

to_mm->id.stack = stack;
@@ -84,8 +84,8 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
return 0;

out_free:
- if (to_mm->id.stack != 0)
- free_page((void *)to_mm->id.stack);
+ if (to_mm->id.stack)
+ free_page(to_mm->id.stack);
out:
return ret;
}
@@ -94,8 +94,7 @@ void uml_setup_stubs(struct mm_struct *mm)
{
int err, ret;

- ret = init_stub_pte(mm, STUB_CODE,
- (unsigned long) __syscall_stub_start);
+ ret = init_stub_pte(mm, STUB_CODE, __syscall_stub_start);
if (ret)
goto out;

@@ -153,6 +152,6 @@ void destroy_context(struct mm_struct *mm)
}
os_kill_ptraced_process(mmu->id.u.pid, 1);

- free_page((void *)mmu->id.stack);
+ free_page(mmu->id.stack);
free_ldt(mmu);
}
diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c
index 527fa58..1a2d485 100644
--- a/arch/um/kernel/skas/process.c
+++ b/arch/um/kernel/skas/process.c
@@ -43,10 +43,10 @@ int __init start_uml(void)
&init_task.thread.switch_buf);
}

-unsigned long current_stub_stack(void)
+void *current_stub_stack(void)
{
if (current->mm == NULL)
- return 0;
+ return NULL;

return current->mm->context.id.stack;
}
diff --git a/arch/um/os-Linux/aio.c b/arch/um/os-Linux/aio.c
index 014eb35..e029471 100644
--- a/arch/um/os-Linux/aio.c
+++ b/arch/um/os-Linux/aio.c
@@ -164,7 +164,7 @@ static int do_not_aio(struct aio_thread_req *req)
static int aio_req_fd_r = -1;
static int aio_req_fd_w = -1;
static int aio_pid = -1;
-static unsigned long aio_stack;
+static void *aio_stack;

static int not_aio_thread(void *arg)
{
diff --git a/arch/um/os-Linux/helper.c b/arch/um/os-Linux/helper.c
index 3f02d42..8653db7 100644
--- a/arch/um/os-Linux/helper.c
+++ b/arch/um/os-Linux/helper.c
@@ -42,11 +42,11 @@ static int helper_child(void *arg)
int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
{
struct helper_data data;
- unsigned long stack, sp;
+ void *stack, *sp;
int pid, fds[2], ret, n;

stack = alloc_stack(0, __cant_sleep());
- if (stack == 0)
+ if (!stack)
return -ENOMEM;

ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
@@ -71,7 +71,7 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
data.fd = fds[1];
data.buf = __cant_sleep() ? uml_kmalloc(PATH_MAX, UM_GFP_ATOMIC) :
uml_kmalloc(PATH_MAX, UM_GFP_KERNEL);
- pid = clone(helper_child, (void *) sp, CLONE_VM, &data);
+ pid = clone(helper_child, sp, CLONE_VM, &data);
if (pid < 0) {
ret = -errno;
printk(UM_KERN_ERR "run_helper : clone failed, errno = %d\n",
@@ -111,17 +111,17 @@ out_free:
}

int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags,
- unsigned long *stack_out)
+ void **stack_out)
{
- unsigned long stack, sp;
+ void *stack, *sp;
int pid, status, err;

stack = alloc_stack(0, __cant_sleep());
- if (stack == 0)
+ if (!stack)
return -ENOMEM;

sp = stack + UM_KERN_PAGE_SIZE - sizeof(void *);
- pid = clone(proc, (void *) sp, flags, arg);
+ pid = clone(proc, sp, flags, arg);
if (pid < 0) {
err = -errno;
printk(UM_KERN_ERR "run_helper_thread : clone failed, "
diff --git a/arch/um/os-Linux/sigio.c b/arch/um/os-Linux/sigio.c
index 46e762f..a5f8fa5 100644
--- a/arch/um/os-Linux/sigio.c
+++ b/arch/um/os-Linux/sigio.c
@@ -22,7 +22,7 @@
* exitcall.
*/
static int write_sigio_pid = -1;
-static unsigned long write_sigio_stack;
+static void *write_sigio_stack;

/*
* These arrays are initialized before the sigio thread is started, and
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index b856c66..ec32886 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -85,7 +85,7 @@ bad_wait:
fatal_sigsegv();
}

-extern unsigned long current_stub_stack(void);
+extern void *current_stub_stack(void);

static void get_skas_faultinfo(int pid, struct faultinfo *fi)
{
@@ -110,7 +110,7 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi)
* faultinfo is prepared by the stub-segv-handler at start of
* the stub stack page. We just have to copy it.
*/
- memcpy(fi, (void *)current_stub_stack(), sizeof(*fi));
+ memcpy(fi, current_stub_stack(), sizeof(*fi));

err = put_fp_registers(pid, fpregs);
if (err < 0) {
@@ -245,10 +245,9 @@ static int userspace_tramp(void *stack)
#define NR_CPUS 1
int userspace_pid[NR_CPUS];

-int start_userspace(unsigned long stub_stack)
+int start_userspace(void *stub_stack)
{
- void *stack;
- unsigned long sp;
+ void *stack, *sp;
int pid, status, n, flags, err;

stack = mmap(NULL, UM_KERN_PAGE_SIZE,
@@ -261,11 +260,11 @@ int start_userspace(unsigned long stub_stack)
return err;
}

- sp = (unsigned long) stack + UM_KERN_PAGE_SIZE - sizeof(void *);
+ sp = stack + UM_KERN_PAGE_SIZE - sizeof(void *);

flags = CLONE_FILES | SIGCHLD;

- pid = clone(userspace_tramp, (void *) sp, flags, (void *) stub_stack);
+ pid = clone(userspace_tramp, sp, flags, stub_stack);
if (pid < 0) {
err = -errno;
printk(UM_KERN_ERR "start_userspace : clone failed, "
@@ -439,14 +438,14 @@ static int __init init_thread_regs(void)

__initcall(init_thread_regs);

-int copy_context_skas0(unsigned long new_stack, int pid)
+int copy_context_skas0(void *new_stack, int pid)
{
int err;
- unsigned long current_stack = current_stub_stack();
+ void *current_stack = current_stub_stack();
struct stub_data *data = (struct stub_data *) current_stack;
struct stub_data *child_data = (struct stub_data *) new_stack;
unsigned long long new_offset;
- int new_fd = phys_mapping(to_phys((void *)new_stack), &new_offset);
+ int new_fd = phys_mapping(to_phys(new_stack), &new_offset);

/*
* prepare offset and fd of child's stack as argument for parent's
--
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/