]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
um: Stop tracking stub's PID via userspace_pid[]
authorTiwei Bie <tiwei.btw@antgroup.com>
Fri, 11 Jul 2025 06:50:21 +0000 (14:50 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Sun, 13 Jul 2025 17:42:49 +0000 (19:42 +0200)
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 <tiwei.btw@antgroup.com>
Link: https://patch.msgid.link/20250711065021.2535362-4-tiwei.bie@linux.dev
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
arch/um/include/asm/mmu_context.h
arch/um/include/shared/skas/mm_id.h
arch/um/include/shared/skas/skas.h
arch/um/kernel/exec.c
arch/um/kernel/skas/process.c
arch/um/os-Linux/skas/process.c
arch/x86/um/tls_32.c

index 23dcc914d44e8cd492ed692ce1ab92cdad0ddb25..0bbb24868557160bede936603a884f2961507543 100644 (file)
 #define activate_mm activate_mm
 static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
 {
-       /*
-        * This is called by fs/exec.c and sys_unshare()
-        * when the new ->mm is used for the first time.
-        */
-       __switch_mm(&new->context.id);
 }
 
 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 
@@ -28,11 +23,9 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
 {
        unsigned cpu = smp_processor_id();
 
-       if(prev != next){
+       if (prev != next) {
                cpumask_clear_cpu(cpu, mm_cpumask(prev));
                cpumask_set_cpu(cpu, mm_cpumask(next));
-               if(next != &init_mm)
-                       __switch_mm(&next->context.id);
        }
 }
 
index 89df9a55fbea633dd613acbb02b3e59bd01bae8a..4f977ef5dda554699f3147b395652199c9397b3d 100644 (file)
@@ -19,8 +19,6 @@ struct mm_id {
        int syscall_fd_map[STUB_MAX_FDS];
 };
 
-void __switch_mm(struct mm_id *mm_idp);
-
 void notify_mm_kill(int pid);
 
 #endif
index 7d1de4cab551b053183cc1386023c19b8e7d227b..807514e105382b958b27e3bb8ecaaa13afab7a1f 100644 (file)
@@ -9,7 +9,6 @@
 #include <sysdep/ptrace.h>
 
 extern int using_seccomp;
-extern int userspace_pid[];
 
 extern void new_thread_handler(void);
 extern void handle_syscall(struct uml_pt_regs *regs);
index cb8b5cd9285c1c9a673ffc499f69a7016d94a6f9..13812fa97eeea1a8f52646be3b4375fa8cb0ceac 100644 (file)
@@ -26,8 +26,6 @@ void flush_thread(void)
 
        get_safe_registers(current_pt_regs()->regs.gp,
                           current_pt_regs()->regs.fp);
-
-       __switch_mm(&current->mm->context.id);
 }
 
 void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
index 05dcdc057af9481a41c2e1168b3f7d96f5e9da86..5881b17eb9874256cef33ca69643aa0f737e4cab 100644 (file)
@@ -26,8 +26,6 @@ static int __init start_kernel_proc(void *unused)
        return 0;
 }
 
-extern int userspace_pid[];
-
 static char cpu0_irqstack[THREAD_SIZE] __aligned(THREAD_SIZE);
 
 int __init start_uml(void)
index 861ac00a07de5754a287779ad03793255fc19d51..78f48fa9db8bc978f1547c276782577307592606 100644 (file)
@@ -434,7 +434,6 @@ static int __init init_stub_exe_fd(void)
 __initcall(init_stub_exe_fd);
 
 int using_seccomp;
-int userspace_pid[NR_CPUS];
 
 /**
  * start_userspace() - prepare a new userspace process
@@ -553,7 +552,7 @@ extern unsigned long tt_extra_sched_jiffies;
 
 void userspace(struct uml_pt_regs *regs)
 {
-       int err, status, op, pid = userspace_pid[0];
+       int err, status, op;
        siginfo_t si_ptrace;
        siginfo_t *si;
        int sig;
@@ -562,6 +561,8 @@ void userspace(struct uml_pt_regs *regs)
        interrupt_end();
 
        while (1) {
+               struct mm_id *mm_id = current_mm_id();
+
                /*
                 * When we are in time-travel mode, userspace can theoretically
                 * do a *lot* of work without being scheduled. The problem with
@@ -590,7 +591,6 @@ void userspace(struct uml_pt_regs *regs)
                current_mm_sync();
 
                if (using_seccomp) {
-                       struct mm_id *mm_id = current_mm_id();
                        struct stub_data *proc_data = (void *) mm_id->stack;
 
                        err = set_stub_state(regs, proc_data, singlestepping());
@@ -644,8 +644,10 @@ void userspace(struct uml_pt_regs *regs)
                                GET_FAULTINFO_FROM_MC(regs->faultinfo, mcontext);
                        }
                } else {
+                       int pid = mm_id->pid;
+
                        /* Flush out any pending syscalls */
-                       err = syscall_stub_flush(current_mm_id());
+                       err = syscall_stub_flush(mm_id);
                        if (err) {
                                if (err == -ENOMEM)
                                        report_enomem();
@@ -776,7 +778,6 @@ void userspace(struct uml_pt_regs *regs)
                                       __func__, sig);
                                fatal_sigsegv();
                        }
-                       pid = userspace_pid[0];
                        interrupt_end();
 
                        /* Avoid -ERESTARTSYS handling in host */
@@ -901,8 +902,3 @@ void reboot_skas(void)
        block_signals_trace();
        UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT);
 }
-
-void __switch_mm(struct mm_id *mm_idp)
-{
-       userspace_pid[0] = mm_idp->pid;
-}
index cb3f17627d165e8eaf2d2b144e3895c4efbc30da..1909c2e640b287368233374a4c19d6f41732339e 100644 (file)
@@ -186,7 +186,7 @@ int arch_switch_tls(struct task_struct *to)
        /*
         * We have no need whatsoever to switch TLS for kernel threads; beyond
         * that, that would also result in us calling os_set_thread_area with
-        * userspace_pid[cpu] == 0, which gives an error.
+        * task->mm == NULL, which would cause a crash.
         */
        if (likely(to->mm))
                return load_TLS(O_FORCE, to);