Skip to content

Commit f7e9077

Browse files
btw616jmberg-intel
authored andcommitted
um: Stop tracking stub's PID via userspace_pid[]
The PID of the stub process can be obtained from current_mm_id(). There is no need to track it via userspace_pid[]. Stop doing that to simplify the code. Signed-off-by: Tiwei Bie <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent b3fb0eb commit f7e9077

File tree

7 files changed

+8
-26
lines changed

7 files changed

+8
-26
lines changed

arch/um/include/asm/mmu_context.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,16 @@
1616
#define activate_mm activate_mm
1717
static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
1818
{
19-
/*
20-
* This is called by fs/exec.c and sys_unshare()
21-
* when the new ->mm is used for the first time.
22-
*/
23-
__switch_mm(&new->context.id);
2419
}
2520

2621
static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
2722
struct task_struct *tsk)
2823
{
2924
unsigned cpu = smp_processor_id();
3025

31-
if(prev != next){
26+
if (prev != next) {
3227
cpumask_clear_cpu(cpu, mm_cpumask(prev));
3328
cpumask_set_cpu(cpu, mm_cpumask(next));
34-
if(next != &init_mm)
35-
__switch_mm(&next->context.id);
3629
}
3730
}
3831

arch/um/include/shared/skas/mm_id.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ struct mm_id {
1919
int syscall_fd_map[STUB_MAX_FDS];
2020
};
2121

22-
void __switch_mm(struct mm_id *mm_idp);
23-
2422
void notify_mm_kill(int pid);
2523

2624
#endif

arch/um/include/shared/skas/skas.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <sysdep/ptrace.h>
1010

1111
extern int using_seccomp;
12-
extern int userspace_pid[];
1312

1413
extern void new_thread_handler(void);
1514
extern void handle_syscall(struct uml_pt_regs *regs);

arch/um/kernel/exec.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ void flush_thread(void)
2626

2727
get_safe_registers(current_pt_regs()->regs.gp,
2828
current_pt_regs()->regs.fp);
29-
30-
__switch_mm(&current->mm->context.id);
3129
}
3230

3331
void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)

arch/um/kernel/skas/process.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ static int __init start_kernel_proc(void *unused)
2626
return 0;
2727
}
2828

29-
extern int userspace_pid[];
30-
3129
static char cpu0_irqstack[THREAD_SIZE] __aligned(THREAD_SIZE);
3230

3331
int __init start_uml(void)

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ static int __init init_stub_exe_fd(void)
434434
__initcall(init_stub_exe_fd);
435435

436436
int using_seccomp;
437-
int userspace_pid[NR_CPUS];
438437

439438
/**
440439
* start_userspace() - prepare a new userspace process
@@ -553,7 +552,7 @@ extern unsigned long tt_extra_sched_jiffies;
553552

554553
void userspace(struct uml_pt_regs *regs)
555554
{
556-
int err, status, op, pid = userspace_pid[0];
555+
int err, status, op;
557556
siginfo_t si_ptrace;
558557
siginfo_t *si;
559558
int sig;
@@ -562,6 +561,8 @@ void userspace(struct uml_pt_regs *regs)
562561
interrupt_end();
563562

564563
while (1) {
564+
struct mm_id *mm_id = current_mm_id();
565+
565566
/*
566567
* When we are in time-travel mode, userspace can theoretically
567568
* do a *lot* of work without being scheduled. The problem with
@@ -590,7 +591,6 @@ void userspace(struct uml_pt_regs *regs)
590591
current_mm_sync();
591592

592593
if (using_seccomp) {
593-
struct mm_id *mm_id = current_mm_id();
594594
struct stub_data *proc_data = (void *) mm_id->stack;
595595

596596
err = set_stub_state(regs, proc_data, singlestepping());
@@ -644,8 +644,10 @@ void userspace(struct uml_pt_regs *regs)
644644
GET_FAULTINFO_FROM_MC(regs->faultinfo, mcontext);
645645
}
646646
} else {
647+
int pid = mm_id->pid;
648+
647649
/* Flush out any pending syscalls */
648-
err = syscall_stub_flush(current_mm_id());
650+
err = syscall_stub_flush(mm_id);
649651
if (err) {
650652
if (err == -ENOMEM)
651653
report_enomem();
@@ -776,7 +778,6 @@ void userspace(struct uml_pt_regs *regs)
776778
__func__, sig);
777779
fatal_sigsegv();
778780
}
779-
pid = userspace_pid[0];
780781
interrupt_end();
781782

782783
/* Avoid -ERESTARTSYS handling in host */
@@ -901,8 +902,3 @@ void reboot_skas(void)
901902
block_signals_trace();
902903
UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT);
903904
}
904-
905-
void __switch_mm(struct mm_id *mm_idp)
906-
{
907-
userspace_pid[0] = mm_idp->pid;
908-
}

arch/x86/um/tls_32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ int arch_switch_tls(struct task_struct *to)
186186
/*
187187
* We have no need whatsoever to switch TLS for kernel threads; beyond
188188
* that, that would also result in us calling os_set_thread_area with
189-
* userspace_pid[cpu] == 0, which gives an error.
189+
* task->mm == NULL, which would cause a crash.
190190
*/
191191
if (likely(to->mm))
192192
return load_TLS(O_FORCE, to);

0 commit comments

Comments
 (0)