From nobody Thu Oct 2 11:50:19 2025 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 51A2025A2BF for ; Thu, 18 Sep 2025 05:16:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758172588; cv=none; b=dfb18IHdzhQXcQ1VxVIQo5YlpkGPT1wyxjE17GeF34hdMp/Vi3s1sl4Q3l1y0dVwW09YGUceXB0n3NkHOKL7TOdfonQyOSzJrOmh3EzMIwm7Lx9i2g5S9bAG2wg459qlEeozBmEqSLqNXfnn3Mh0bTjrz9uIg33Lgm2POP2z6gg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758172588; c=relaxed/simple; bh=VX63Cts70ezj4r0nc0GLQLD8D46JgopVfQkzG5n55e8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k/cOI9ubai/HHKSvAE9LWMQxMjrm2/QR442e8uijZ++3RYtq+mYv7sSO7ao760ZkNyPkk7z2d5aSawXOztCwkVKszlabASIh3mBCM3p/Gqv7g/QzSStVxSwQdJ5jEIo6FrAT4zE5FxUC+iJ6GQCmEIlo3gQS7KZZKFME9EYC224= 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=TG38/xwy; arc=none smtp.client-ip=209.85.210.175 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="TG38/xwy" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-77796ad4c13so397919b3a.0 for ; Wed, 17 Sep 2025 22:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758172586; x=1758777386; 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=1F21TWOFO4Nmsr2w4QPMMTb+GqIkJhpnakmqkMS5Gtc=; b=TG38/xwyYxedwyvfwlFOXFxDpkylJk+E/320oFymMKgKU1MueulSme9o/f2dSWxWFf WkwMRAz1o9jj9d8Lul2juKUARd3s7iK6/0NHviRLKdlEyTUY4JXniu1eB7z3gBJ8u8pS SsfaETWDdOZav/m1/Y7fUaXXAzGcDS2m2d3sP7XAIwnaRcV2Lk2yBL84abeYlo4eSAVt mSYtzFoWoGjgYsANnCmFLx7HhjBGn3cxaV6G52losQSXSgvNCGIFouINenbZCfedrfWz cc+X5zf/nfT5SPSzVge0fd10KuyAT98gnLoh3Lu4Tf2Vft/bYaKsDpUzNBfdZUbaLgKG 0EFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758172586; x=1758777386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1F21TWOFO4Nmsr2w4QPMMTb+GqIkJhpnakmqkMS5Gtc=; b=UjG2qeHbSxg6B7JNUnqW+gNDadkPOt0VkLZemvsSHsE1KLUcVk6gfOLGFWVGMZbiLF seg2lY+3+ffb9zZM+DCoQOUc+0s3Z4BM8mZJgP1mNQCzSLfcHp0DOhj/Iy7iCMQmyELT GQZhNr01uVhBEg0DTU5rKN8yjluLgovYC7tp0zNWITbINsvRlWaT5nu+jONlm/+4eT8W YijwzAotQwHI+1vCzVF/Vh7t67d4xgp41rVKnCPkaZ/At4SFsyBYV8Zgd/cexjDpqXVk xwDGjxQXSsFmP6PpY4+NTRAX3uQYaXxGye4/B0vcA6pF9kdq8ZRi+bg45VJSSXJYO9uA FglA== X-Forwarded-Encrypted: i=1; AJvYcCVueZy6zTRFYXxWwuGZnp57xwwbOxeQgt+6neCjcio/zzeG1ws66AElLP+Cap4ZVNHPcTNM/8ID+yG0W2s=@vger.kernel.org X-Gm-Message-State: AOJu0YznnNrt40brYBkU2OToJN1EqdlerxfhTszFRhFRFHUclC30iJmc BQbdi/XP9rt++loA4/560ViVrKZOs8n1/Ns8TLPylyAmVSOLY3xk0eAQUrsi9A== X-Gm-Gg: ASbGncvNg6FEmPzBLAYlptRKO1iyy8um1yncjdG+stpoHkEchMx21Rgf7mPHxRLca8l 7RBvbzDwVxYsJrswYBt9+NnShKf6qWbgis6h8GFBVoDy4yBT8NiHlbbg3ITtLcmT9J8yzuPzERs 04A0BBS+8AChYCAMZre5/t5JRCE3IrN3REgjw+BHidQean8ZYd9NrObIPcdi5eVjqs1MXLXVaEr tBf9ZgZMEP9u4w171wykpj+D6Aj0fSZhxZNgK5K5llWO8yYkwXQeJy5RZvT/sbG4gt2Bwdi9Og0 iAF+MRGIfbe+AlivtxbZE09EHagUswxh2losAKydgVqLXO6A836FVPjK6k4B0BDKQrMNYizaP+/ QPLn1Lkh0fYPxfaTYPBgzM9AmQMbccyODdUk3x96qbmK8ymSbY+RT7cKS1EX3aU8KWI40F+XX0O x7QMAHse94dPERPpgw5hVE1w== X-Google-Smtp-Source: AGHT+IE9KBHsPSUbje/NyXg6zQg4Uv9zV8Hw+XsbFPAe9nlsq8Ejds5VN8WaQdSXcrL2brt8Vz97zQ== X-Received: by 2002:a05:6a20:3d05:b0:252:2bfe:b654 with SMTP id adf61e73a8af0-27aa85b493cmr6276905637.51.1758172585459; Wed, 17 Sep 2025 22:16:25 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32ea0859e20sm3576779a91.0.2025.09.17.22.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Sep 2025 22:16:24 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id A0C2C1061EE4; Thu, 18 Sep 2025 14:16:22 +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 v11 02/14] um: decouple MMU specific code from the common part Date: Thu, 18 Sep 2025 14:15:55 +0900 Message-ID: <7255e42a935a07e9a6e68ce3fbb24ab28de4cf6b.1758171893.git.thehajime@gmail.com> 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 | 25 +++++++ arch/um/kernel/skas/process.c | 25 ------- arch/um/os-Linux/Makefile | 3 +- arch/um/os-Linux/process.c | 128 ++++++++++++++++++++++++++++++++ arch/um/os-Linux/skas/process.c | 126 ------------------------------- 8 files changed, 213 insertions(+), 189 deletions(-) create mode 100644 arch/um/kernel/mem-pgtable.c diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index b8f4e9281599..11ede105f3a9 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 76bec7de81b5..106a2f85ab5c 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -207,45 +206,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 1be644de9e41..bfbfee0d401a 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,8 @@ struct task_struct *cpu_tasks[NR_CPUS]; EXPORT_SYMBOL(cpu_tasks); =20 +static char cpu0_irqstack[THREAD_SIZE] __aligned(THREAD_SIZE); + void free_stack(unsigned long stack, int order) { free_pages(stack, order); @@ -299,3 +302,25 @@ unsigned long __get_wchan(struct task_struct *p) =20 return 0; } + + +static int __init start_kernel_proc(void *unused) +{ + block_signals_trace(); + + start_kernel(); + return 0; +} + +int __init start_uml(void) +{ + stack_protections((unsigned long) &cpu0_irqstack); + set_sigstack(cpu0_irqstack, 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); +} diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c index 5881b17eb987..5247121d3419 100644 --- a/arch/um/kernel/skas/process.c +++ b/arch/um/kernel/skas/process.c @@ -16,31 +16,6 @@ #include #include =20 -extern void start_kernel(void); - -static int __init start_kernel_proc(void *unused) -{ - block_signals_trace(); - - start_kernel(); - return 0; -} - -static char cpu0_irqstack[THREAD_SIZE] __aligned(THREAD_SIZE); - -int __init start_uml(void) -{ - stack_protections((unsigned long) &cpu0_irqstack); - set_sigstack(cpu0_irqstack, 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) diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index fae836713487..c048fc838068 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 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 00b49e90d05f..d000907ec796 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 @@ -15,10 +16,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) { @@ -189,3 +196,124 @@ void os_set_pdeathsig(void) { prctl(PR_SET_PDEATHSIG, SIGKILL); } + +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; + +/* XXX Make these percpu */ +static void (*cb_proc)(void *arg); +static void *cb_arg; +static 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; + + block_signals_trace(); + if (UML_SETJMP(&here) =3D=3D 0) + UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); + unblock_signals_trace(); + + cb_proc =3D NULL; + cb_arg =3D NULL; + cb_back =3D NULL; +} + +void halt_skas(void) +{ + block_signals_trace(); + UML_LONGJMP(&initial_jmpbuf, INIT_JMP_HALT); +} + +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) +{ + block_signals_trace(); + UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT); +} diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/proces= s.c index 0bc10cd4cbed..92278107007e 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 @@ -433,8 +426,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 @@ -547,7 +538,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) @@ -786,119 +776,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; - -/* XXX Make these percpu */ -static void (*cb_proc)(void *arg); -static void *cb_arg; -static 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; - - block_signals_trace(); - if (UML_SETJMP(&here) =3D=3D 0) - UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); - unblock_signals_trace(); - - cb_proc =3D NULL; - cb_arg =3D NULL; - cb_back =3D NULL; -} - -void halt_skas(void) -{ - block_signals_trace(); - UML_LONGJMP(&initial_jmpbuf, INIT_JMP_HALT); -} - -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) -{ - block_signals_trace(); - UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT); -} --=20 2.43.0