From nobody Wed Dec 17 10:22:37 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3F9427877D for ; Sat, 8 Nov 2025 08:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589165; cv=none; b=VHFxWfN/892vtkeF6jDpk8fX3KS/4RajmRkn8Yh6Age3ZlOoc6EqC8Gg2CQZVXIH0LJ2WF+ldRR9+U8zOMh1OGBu1z0qswY690cxDEDXWWefunAUL/ueu0uuoSrxTYvhO5Fm5vtGAGSuqV0XchK0TbZXti+4al5ewvSDOFlK5I4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589165; c=relaxed/simple; bh=4xcFrZ+JqQ3sy1fsQCIhfLPeC7rXS4iJayunDgoRLEo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MqwJd8MjFIuaZWegSV28MY+zX6m7GB915UJON1NvGIRgue07C3Vv8GjX9I52b8MJM6s73tbShehenMkuofouvzElALbReCkqRKmlG10zy2zGgcaAgVdY72+0jSBz7+/vZqOv/qP2WOop2IVCqVXCgXGaoUor7Up2VoHJoOj/lD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OxjDmQay; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OxjDmQay" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-297dc3e299bso6850495ad.1 for ; Sat, 08 Nov 2025 00:06:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589162; x=1763193962; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AADfWcJgVjD9ZN7PUFLyBggrmXQYWqBtbT5qNU1VBN8=; b=OxjDmQaytpEctDItfaQik/3EVVLNzyXk7FVFlDDGII9lhI65226IshdzpNHzzQzy7/ GA+OXlOQdkaTjLAQ5ZJ6PWyyZvAslVTV/ZRI1fW+qzhiYh0JirnZ3/BA4+tjksH0MNb7 3baTqGO/6dzRm5XbCbSi0oqHOP2CCW6gvA6ci523UfRKYQiOuf4DoAgyY1lp56l4nrNZ 4oVtLM6QctOZ1dL6dwSepxDSEy4C7Cn9JcVnf6gCKSrl8uHRVaVdubSnVDZhthgKG6gJ +PoGmOWkQdp+aBMC3ussaGZZMkAUWvO0DnaCNC/CVH2B4ze6QVV+2HZmHFpf28wVfpV5 9CSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589162; x=1763193962; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=AADfWcJgVjD9ZN7PUFLyBggrmXQYWqBtbT5qNU1VBN8=; b=vwttzCiyCwOl45FFCwFMHR6JTIySB3jMst6f60J9SH59hfEt9Xh+wpRn1nZuoXtaGB CKqz7LtMRx03EkBYnNPQtJE0I2Jr61lV8iVh9WwqbVXmB536mWRI87vTB5ZqeNYT+FDR d5H/GKAcxehKJNFt/K+YMkeW2IwdKzQ+qgivjGz299UEcnOCQFyvczIkoJjl5a5QzMkj NzvMwgNyZaBKPYohHbWPfpuc0hcPFjlQtH5FR4Whu1WEH6bjmFpHYIl4TKdMTxXi2Xd0 7quXIHE/gp4pBfk2fnT01mYZTIDDw6a+xxB/wwYZjF1Q6M84LflcTgbHsSOHh98jV7xt tAwQ== X-Forwarded-Encrypted: i=1; AJvYcCUGVpHEvgK1frO/4D5bi+mptsFALBA2TRAdcC90n21pnAYiwxNMNzEbT15iKQ1ylouX3qgUjr8JuSzhL6E=@vger.kernel.org X-Gm-Message-State: AOJu0YwdMteGuhJywI3XPYGxxL3g+2imEeUDhL5Xaa+8m8Fs5u6XqlhX 5r+vHXiD0kISeJouIbh5iZah6p+V25CcI8+zaW3+YmMHTkIXjC97mEHZBlr3xg== X-Gm-Gg: ASbGncvVHWCd8TSaVLLzAyukvj4yV3+tLPhOEYd45dxsjjf9sIgeyQ9TCbRRMXgOIK9 Qkjmzhnc2qjNrEnPtJINw3fbaVtuOQ04qMO3VzWB0mNy8zHKJaf5XsxACASUdPW/T+x5Em+cr9n fwNdBKLLQgZDhB7HaWJ3ABtYAKLC8A6Itupl2AkQTuAfwEI+Nb6fXRDxrLBMfY9NgAph6luYcDZ xWzPwO5x6c2+9kMDG8YtAENEB214POutsQIZW3bwHCHIqFabiBIS/04G2buXmxxs+wUiYDDR7c/ SpHUvDnS5YH3pml6IPC/x07LiyBDwi74Haz54j0vLgmrcFLfpruZzAJ06thVN2E8r/LiM6596ub XEMgvkIXP+zu1srBx+xSpzeFpCbv1C6i4Tu+BpATnnVLpTHFvQWpqVQRU1X7okxTD34C0NGc7eP HM79NLfmWoxlYH6rhRxGT78X2e28Cu79up6QkR9SXEWX7E/A== X-Google-Smtp-Source: AGHT+IFiJr0EeMCxqF+xD/dFMEIX//Iica2/667frEt8MglvDOKULW8yWmUZ2gxdKGQQIHQbJRODxQ== X-Received: by 2002:a17:902:f791:b0:297:e267:c4c1 with SMTP id d9443c01a7336-297e5718125mr22597115ad.55.1762589161767; Sat, 08 Nov 2025 00:06:01 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29651c6f6cdsm83649695ad.71.2025.11.08.00.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:01 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 57AE911388C9; Sat, 8 Nov 2025 17:05:59 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 02/13] um: decouple MMU specific code from the common part Date: Sat, 8 Nov 2025 17:05:37 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This splits the memory, process related code with common and MMU specific parts in order to avoid ifdefs in .c file and duplication between MMU and !MMU. Signed-off-by: Hajime Tazaki --- arch/um/kernel/Makefile | 5 +- arch/um/kernel/mem-pgtable.c | 55 ++++++++++++++ arch/um/kernel/mem.c | 35 --------- arch/um/kernel/process.c | 38 ++++++++++ arch/um/kernel/skas/process.c | 37 --------- arch/um/os-Linux/Makefile | 3 +- arch/um/os-Linux/process.c | 129 ++++++++++++++++++++++++++++++++ arch/um/os-Linux/skas/process.c | 127 ------------------------------- 8 files changed, 227 insertions(+), 202 deletions(-) create mode 100644 arch/um/kernel/mem-pgtable.c diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index be60bc451b3f..76d36751973e 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -16,9 +16,10 @@ always-$(KBUILD_BUILTIN) :=3D vmlinux.lds =20 obj-y =3D config.o exec.o exitcode.o irq.o ksyms.o mem.o \ physmem.o process.o ptrace.o reboot.o sigio.o \ - signal.o sysrq.o time.o tlb.o trap.o \ - um_arch.o umid.o kmsg_dump.o capflags.o skas/ + signal.o sysrq.o time.o \ + um_arch.o umid.o kmsg_dump.o capflags.o obj-y +=3D load_file.o +obj-$(CONFIG_MMU) +=3D mem-pgtable.o tlb.o trap.o skas/ =20 obj-$(CONFIG_BLK_DEV_INITRD) +=3D initrd.o obj-$(CONFIG_GPROF) +=3D gprof_syms.o diff --git a/arch/um/kernel/mem-pgtable.c b/arch/um/kernel/mem-pgtable.c new file mode 100644 index 000000000000..549da1d3bff0 --- /dev/null +++ b/arch/um/kernel/mem-pgtable.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* Allocate and free page tables. */ + +pgd_t *pgd_alloc(struct mm_struct *mm) +{ + pgd_t *pgd =3D (pgd_t *)__get_free_page(GFP_KERNEL); + + if (pgd) { + memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t)); + memcpy(pgd + USER_PTRS_PER_PGD, + swapper_pg_dir + USER_PTRS_PER_PGD, + (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); + } + return pgd; +} + +static const pgprot_t protection_map[16] =3D { + [VM_NONE] =3D PAGE_NONE, + [VM_READ] =3D PAGE_READONLY, + [VM_WRITE] =3D PAGE_COPY, + [VM_WRITE | VM_READ] =3D PAGE_COPY, + [VM_EXEC] =3D PAGE_READONLY, + [VM_EXEC | VM_READ] =3D PAGE_READONLY, + [VM_EXEC | VM_WRITE] =3D PAGE_COPY, + [VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_COPY, + [VM_SHARED] =3D PAGE_NONE, + [VM_SHARED | VM_READ] =3D PAGE_READONLY, + [VM_SHARED | VM_WRITE] =3D PAGE_SHARED, + [VM_SHARED | VM_WRITE | VM_READ] =3D PAGE_SHARED, + [VM_SHARED | VM_EXEC] =3D PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_READ] =3D PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_WRITE] =3D PAGE_SHARED, + [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_SHARED +}; +DECLARE_VM_GET_PAGE_PROT diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 39c4a7e21c6f..f3258680bfbe 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -107,45 +106,11 @@ void free_initmem(void) { } =20 -/* Allocate and free page tables. */ - -pgd_t *pgd_alloc(struct mm_struct *mm) -{ - pgd_t *pgd =3D __pgd_alloc(mm, 0); - - if (pgd) - memcpy(pgd + USER_PTRS_PER_PGD, - swapper_pg_dir + USER_PTRS_PER_PGD, - (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); - - return pgd; -} - void *uml_kmalloc(int size, int flags) { return kmalloc(size, flags); } =20 -static const pgprot_t protection_map[16] =3D { - [VM_NONE] =3D PAGE_NONE, - [VM_READ] =3D PAGE_READONLY, - [VM_WRITE] =3D PAGE_COPY, - [VM_WRITE | VM_READ] =3D PAGE_COPY, - [VM_EXEC] =3D PAGE_READONLY, - [VM_EXEC | VM_READ] =3D PAGE_READONLY, - [VM_EXEC | VM_WRITE] =3D PAGE_COPY, - [VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_COPY, - [VM_SHARED] =3D PAGE_NONE, - [VM_SHARED | VM_READ] =3D PAGE_READONLY, - [VM_SHARED | VM_WRITE] =3D PAGE_SHARED, - [VM_SHARED | VM_WRITE | VM_READ] =3D PAGE_SHARED, - [VM_SHARED | VM_EXEC] =3D PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_READ] =3D PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_WRITE] =3D PAGE_SHARED, - [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_SHARED -}; -DECLARE_VM_GET_PAGE_PROT - void mark_rodata_ro(void) { unsigned long rodata_start =3D PFN_ALIGN(__start_rodata); diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 63b38a3f73f7..b07c1f120910 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -307,3 +308,40 @@ unsigned long __get_wchan(struct task_struct *p) =20 return 0; } + +extern void start_kernel(void); + +static int __init start_kernel_proc(void *unused) +{ + block_signals_trace(); + + start_kernel(); + return 0; +} + +char cpu_irqstacks[NR_CPUS][THREAD_SIZE] __aligned(THREAD_SIZE); + +int __init start_uml(void) +{ + stack_protections((unsigned long) &cpu_irqstacks[0]); + set_sigstack(cpu_irqstacks[0], THREAD_SIZE); + + init_new_thread_signals(); + + init_task.thread.request.thread.proc =3D start_kernel_proc; + init_task.thread.request.thread.arg =3D NULL; + return start_idle_thread(task_stack_page(&init_task), + &init_task.thread.switch_buf); +} + +static DEFINE_SPINLOCK(initial_jmpbuf_spinlock); + +void initial_jmpbuf_lock(void) +{ + spin_lock_irq(&initial_jmpbuf_spinlock); +} + +void initial_jmpbuf_unlock(void) +{ + spin_unlock_irq(&initial_jmpbuf_spinlock); +} diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c index 4a7673b0261a..d643854942bc 100644 --- a/arch/um/kernel/skas/process.c +++ b/arch/um/kernel/skas/process.c @@ -17,31 +17,6 @@ #include #include =20 -extern void start_kernel(void); - -static int __init start_kernel_proc(void *unused) -{ - block_signals_trace(); - - start_kernel(); - return 0; -} - -char cpu_irqstacks[NR_CPUS][THREAD_SIZE] __aligned(THREAD_SIZE); - -int __init start_uml(void) -{ - stack_protections((unsigned long) &cpu_irqstacks[0]); - set_sigstack(cpu_irqstacks[0], THREAD_SIZE); - - init_new_thread_signals(); - - init_task.thread.request.thread.proc =3D start_kernel_proc; - init_task.thread.request.thread.arg =3D NULL; - return start_idle_thread(task_stack_page(&init_task), - &init_task.thread.switch_buf); -} - unsigned long current_stub_stack(void) { if (current->mm =3D=3D NULL) @@ -65,15 +40,3 @@ void current_mm_sync(void) =20 um_tlb_sync(current->mm); } - -static DEFINE_SPINLOCK(initial_jmpbuf_spinlock); - -void initial_jmpbuf_lock(void) -{ - spin_lock_irq(&initial_jmpbuf_spinlock); -} - -void initial_jmpbuf_unlock(void) -{ - spin_unlock_irq(&initial_jmpbuf_spinlock); -} diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index f8d672d570d9..40e3e0eab6a0 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile @@ -8,7 +8,8 @@ KCOV_INSTRUMENT :=3D n =20 obj-y =3D elf_aux.o execvp.o file.o helper.o irq.o main.o mem.o process.o \ registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o user_syms.o util.o skas/ + umid.o user_syms.o util.o +obj-$(CONFIG_MMU) +=3D skas/ =20 CFLAGS_signal.o +=3D -Wframe-larger-than=3D4096 =20 diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 3a2a84ab9325..c50fa865d8c7 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -6,6 +6,7 @@ =20 #include #include +#include #include #include #include @@ -17,10 +18,16 @@ #include #include #include +#include #include #include #include #include +#include +#include + +int using_seccomp; +static int unscheduled_userspace_iterations; =20 void os_alarm_process(int pid) { @@ -209,3 +216,125 @@ int os_futex_wake(void *uaddr) NULL, NULL, 0)); return r < 0 ? -errno : r; } + +int is_skas_winch(int pid, int fd, void *data) +{ + return pid =3D=3D getpgrp(); +} + +void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)) +{ + (*buf)[0].JB_IP =3D (unsigned long) handler; + (*buf)[0].JB_SP =3D (unsigned long) stack + UM_THREAD_SIZE - + sizeof(void *); +} + +#define INIT_JMP_NEW_THREAD 0 +#define INIT_JMP_CALLBACK 1 +#define INIT_JMP_HALT 2 +#define INIT_JMP_REBOOT 3 + +void switch_threads(jmp_buf *me, jmp_buf *you) +{ + unscheduled_userspace_iterations =3D 0; + + if (UML_SETJMP(me) =3D=3D 0) + UML_LONGJMP(you, 1); +} + +static jmp_buf initial_jmpbuf; + +static __thread void (*cb_proc)(void *arg); +static __thread void *cb_arg; +static __thread jmp_buf *cb_back; + +int start_idle_thread(void *stack, jmp_buf *switch_buf) +{ + int n; + + set_handler(SIGWINCH); + + /* + * Can't use UML_SETJMP or UML_LONGJMP here because they save + * and restore signals, with the possible side-effect of + * trying to handle any signals which came when they were + * blocked, which can't be done on this stack. + * Signals must be blocked when jumping back here and restored + * after returning to the jumper. + */ + n =3D setjmp(initial_jmpbuf); + switch (n) { + case INIT_JMP_NEW_THREAD: + (*switch_buf)[0].JB_IP =3D (unsigned long) uml_finishsetup; + (*switch_buf)[0].JB_SP =3D (unsigned long) stack + + UM_THREAD_SIZE - sizeof(void *); + break; + case INIT_JMP_CALLBACK: + (*cb_proc)(cb_arg); + longjmp(*cb_back, 1); + break; + case INIT_JMP_HALT: + kmalloc_ok =3D 0; + return 0; + case INIT_JMP_REBOOT: + kmalloc_ok =3D 0; + return 1; + default: + printk(UM_KERN_ERR "Bad sigsetjmp return in %s - %d\n", + __func__, n); + fatal_sigsegv(); + } + longjmp(*switch_buf, 1); + + /* unreachable */ + printk(UM_KERN_ERR "impossible long jump!"); + fatal_sigsegv(); + return 0; +} + +void initial_thread_cb_skas(void (*proc)(void *), void *arg) +{ + jmp_buf here; + + cb_proc =3D proc; + cb_arg =3D arg; + cb_back =3D &here; + + initial_jmpbuf_lock(); + if (UML_SETJMP(&here) =3D=3D 0) + UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); + initial_jmpbuf_unlock(); + + cb_proc =3D NULL; + cb_arg =3D NULL; + cb_back =3D NULL; +} + +void halt_skas(void) +{ + initial_jmpbuf_lock(); + UML_LONGJMP(&initial_jmpbuf, INIT_JMP_HALT); + /* unreachable */ +} + +static bool noreboot; + +static int __init noreboot_cmd_param(char *str, int *add) +{ + *add =3D 0; + noreboot =3D true; + return 0; +} + +__uml_setup("noreboot", noreboot_cmd_param, +"noreboot\n" +" Rather than rebooting, exit always, akin to QEMU's -no-reboot option.= \n" +" This is useful if you're using CONFIG_PANIC_TIMEOUT in order to catch= \n" +" crashes in CI\n\n"); + +void reboot_skas(void) +{ + initial_jmpbuf_lock(); + UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT); + /* unreachable */ +} diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/proces= s.c index d6c22f8aa06d..01814ad82f5d 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -29,16 +28,10 @@ #include #include #include -#include #include #include #include "../internal.h" =20 -int is_skas_winch(int pid, int fd, void *data) -{ - return pid =3D=3D getpgrp(); -} - static const char *ptrace_reg_name(int idx) { #define R(n) case HOST_##n: return #n @@ -426,8 +419,6 @@ static int __init init_stub_exe_fd(void) } __initcall(init_stub_exe_fd); =20 -int using_seccomp; - /** * start_userspace() - prepare a new userspace process * @mm_id: The corresponding struct mm_id @@ -540,7 +531,6 @@ int start_userspace(struct mm_id *mm_id) return err; } =20 -static int unscheduled_userspace_iterations; extern unsigned long tt_extra_sched_jiffies; =20 void userspace(struct uml_pt_regs *regs) @@ -789,120 +779,3 @@ void userspace(struct uml_pt_regs *regs) } } } - -void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)) -{ - (*buf)[0].JB_IP =3D (unsigned long) handler; - (*buf)[0].JB_SP =3D (unsigned long) stack + UM_THREAD_SIZE - - sizeof(void *); -} - -#define INIT_JMP_NEW_THREAD 0 -#define INIT_JMP_CALLBACK 1 -#define INIT_JMP_HALT 2 -#define INIT_JMP_REBOOT 3 - -void switch_threads(jmp_buf *me, jmp_buf *you) -{ - unscheduled_userspace_iterations =3D 0; - - if (UML_SETJMP(me) =3D=3D 0) - UML_LONGJMP(you, 1); -} - -static jmp_buf initial_jmpbuf; - -static __thread void (*cb_proc)(void *arg); -static __thread void *cb_arg; -static __thread jmp_buf *cb_back; - -int start_idle_thread(void *stack, jmp_buf *switch_buf) -{ - int n; - - set_handler(SIGWINCH); - - /* - * Can't use UML_SETJMP or UML_LONGJMP here because they save - * and restore signals, with the possible side-effect of - * trying to handle any signals which came when they were - * blocked, which can't be done on this stack. - * Signals must be blocked when jumping back here and restored - * after returning to the jumper. - */ - n =3D setjmp(initial_jmpbuf); - switch (n) { - case INIT_JMP_NEW_THREAD: - (*switch_buf)[0].JB_IP =3D (unsigned long) uml_finishsetup; - (*switch_buf)[0].JB_SP =3D (unsigned long) stack + - UM_THREAD_SIZE - sizeof(void *); - break; - case INIT_JMP_CALLBACK: - (*cb_proc)(cb_arg); - longjmp(*cb_back, 1); - break; - case INIT_JMP_HALT: - kmalloc_ok =3D 0; - return 0; - case INIT_JMP_REBOOT: - kmalloc_ok =3D 0; - return 1; - default: - printk(UM_KERN_ERR "Bad sigsetjmp return in %s - %d\n", - __func__, n); - fatal_sigsegv(); - } - longjmp(*switch_buf, 1); - - /* unreachable */ - printk(UM_KERN_ERR "impossible long jump!"); - fatal_sigsegv(); - return 0; -} - -void initial_thread_cb_skas(void (*proc)(void *), void *arg) -{ - jmp_buf here; - - cb_proc =3D proc; - cb_arg =3D arg; - cb_back =3D &here; - - initial_jmpbuf_lock(); - if (UML_SETJMP(&here) =3D=3D 0) - UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); - initial_jmpbuf_unlock(); - - cb_proc =3D NULL; - cb_arg =3D NULL; - cb_back =3D NULL; -} - -void halt_skas(void) -{ - initial_jmpbuf_lock(); - UML_LONGJMP(&initial_jmpbuf, INIT_JMP_HALT); - /* unreachable */ -} - -static bool noreboot; - -static int __init noreboot_cmd_param(char *str, int *add) -{ - *add =3D 0; - noreboot =3D true; - return 0; -} - -__uml_setup("noreboot", noreboot_cmd_param, -"noreboot\n" -" Rather than rebooting, exit always, akin to QEMU's -no-reboot option.= \n" -" This is useful if you're using CONFIG_PANIC_TIMEOUT in order to catch= \n" -" crashes in CI\n\n"); - -void reboot_skas(void) -{ - initial_jmpbuf_lock(); - UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT); - /* unreachable */ -} --=20 2.43.0