From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 6A1641DDC0B; Wed, 30 Apr 2025 04:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987259; cv=none; b=FTgi2xiytNWNKmq1u8aCsSDYBS8tmZaU4MGWz20dqDAqs0+8vqW8vpJBEtNyRgBXGUSlnHNSrikXE5GF8XBpvhkX38jPsqEviR4bXJIINymstLu2CPmVCvDzwgYN3zmI9al9a4hCWzT2YtOBuWhzt7W/yS2FR2NVh8BHiEQLmkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987259; c=relaxed/simple; bh=Xn2RaNaReEp4HS2lM2B2ydz2zvsDs19KOeICSn68auQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hIAowwA+y875W3mMoTeVldVF0drFja49vkSbT8gnXKeEAW3huXNkxS+/Wk/42Xncemutko7/9TlGBu3IKnwou00kspJqX8+VyfBABrEV9nCmAd0SS6QBpmvsqYEjWIKKzIL7mf8wq7ggOkkmcp0lmaGN7t02hH3O5HxNH9RPtrE= 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=TD8lCl8+; arc=none smtp.client-ip=209.85.210.177 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="TD8lCl8+" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-736b350a22cso5935730b3a.1; Tue, 29 Apr 2025 21:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987256; x=1746592056; 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=ukyNfs65nuvgTdhSkdJYZ2Y9345NLuFCWN/gVQv/aLg=; b=TD8lCl8+4G0M0WrTETIkaFHmAy7rEYq3lHZh2OQkn56OD5IwcFi1OHdpDOV/rNabRG 2BqLGz6hPsiTIrYFhyv1RNkkneRCouJRYn+Cf+O5ZpGOolQaLRRysZnzMGyv8Bp5rsTo 4Nsx7KE399i1n6vyTSHUJ1N8XeIMtf7rqCDlK0BiS7FG5DytFMx81Xs9ZJnS4Ffe2xix dcTzFyGJ8AQbg8NguVw3urySkJopvZ+m3qoALOUg3vpOtOQ9c1//kds/CC3uuG2BsUEk oTqmWY2l8N0gDe4YMLvpV20PTv38nsN6aiAESJqequeFbzO6268/hVBoTHGBmykE8mBM VFNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987256; x=1746592056; 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=ukyNfs65nuvgTdhSkdJYZ2Y9345NLuFCWN/gVQv/aLg=; b=T+ebLpiyAdPQTWaMjVCc+l0u35GDxROJg5GZGIDsj0sLQXrsncKVNAe2CT2DWGXKYa z/ASZizTXfCKCFYh8PQ0GenlovshhciPXB64Zii0w0DUZMuTi8lx5HqbYULIEU3TEMaa XT493hdtUvcQ4407s0zKqx7Csz8IFQIJFrdyt61adl1npWVnhkYIc0W94xiu9jwv0Y3D +jgtEhgv7Xo6I05+H/3teeWWMWyJCepcyija4nB6iojirPQ3GDlFRyGH3doPMLN6OAeZ w/2dH3Bc9jlGBKbWN7LnA0ohmGckfLuBODozyLqt7+7XAgQkNuwOQLJgY42lre80S68V 0uLQ== X-Forwarded-Encrypted: i=1; AJvYcCUUur8/CfQ4/zfl+tyDSSTD9KkP6jyBAsrfNC9qS18iA1b65e1FdyevgsW/zQR4u7gtXMxgXIpWiRYbhrA5@vger.kernel.org, AJvYcCXgYpwquD9TGplZK/WD9qA9piQ/UJW8zQFJXYZaqBFmvbnzANzXMXtUSrY01UaXTLzQLY8ztCpQSSPM685H@vger.kernel.org X-Gm-Message-State: AOJu0YwBeKR2R6GIXVmz+no9FiAeYxnJg/f7z1TTtwjBiTuW0APu0J9h 0hSN1tYFhMOdAf9q90oWHI7RxnDFgsi3AwJeic0HKGNiJEuJfSC56afMhZFomD4= X-Gm-Gg: ASbGncu8GTt6SZc0WyFzPgHb0qvf1+gHDy3qQQszrKxyvC/mc0iDE3xP1FzkMPno9V3 Ua/0NIq4v0/9plZ0Je81yoM/TG6/U+22rK/ArVtLIwMPjyhWZo111hmxcFczUKeS8USzle8OpYE XgrOas1ht5QdJdm1kgdxginn7xkdejskIDARRgbRGyQXGhYZ4/Qf9SQw4wCpjQylV6IyDn/188a dWHsChVMvg70QE41RMcghp1om2SAhPFoLS6Y3Tby/MuddaJknrlQO90oW/kkEMyM4vEDsGdawZz p9d4u88yu8N1cvriMfSi50jKNKef8Yu9NBfjm8JjgH78iE5N+bBwEXP8Gl/c/zUP33uRbZQ6EtD Rc7YWzCu0JbM= X-Google-Smtp-Source: AGHT+IHaI2hva/XO5UNyBlcemnxgGJqm96jqA3suKBcAYtlVKSOpmAkCAY78xziMTfLiN3rWee/VXA== X-Received: by 2002:a05:6a00:2e24:b0:736:39d4:ccf6 with SMTP id d2e1a72fcca58-74038989daemr2827463b3a.8.1745987256524; Tue, 29 Apr 2025 21:27:36 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-740398f9ac3sm621129b3a.23.2025.04.29.21.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:35 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id DC01FE94814; Wed, 30 Apr 2025 13:27:33 +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, Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v8 01/12] x86/um: nommu: elf loader for fdpic Date: Wed, 30 Apr 2025 13:27:07 +0900 Message-ID: <1f0ec32dbc49f8784995a29a2e87063507eb9838.1745980082.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" As UML supports CONFIG_MMU=3Dn case, it has to use an alternate ELF loader, FDPIC ELF loader. In this commit, we added necessary definitions in the arch, as UML has not been used so far. It also updates Kconfig file to use BINFMT_ELF_FDPIC under !MMU environment. Cc: Eric Biederman Cc: Kees Cook Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: linux-mm@kvack.org Cc: linux-fsdevel@vger.kernel.org Acked-by: Kees Cook Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/asm/mmu.h | 5 +++++ arch/um/include/asm/ptrace-generic.h | 6 ++++++ arch/x86/um/asm/elf.h | 8 ++++++-- fs/Kconfig.binfmt | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h index a3eaca41ff61..01422b761aa0 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -14,6 +14,11 @@ typedef struct mm_context { /* Address range in need of a TLB sync */ unsigned long sync_tlb_range_from; unsigned long sync_tlb_range_to; + +#ifdef CONFIG_BINFMT_ELF_FDPIC + unsigned long exec_fdpic_loadmap; + unsigned long interp_fdpic_loadmap; +#endif } mm_context_t; =20 #endif diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptr= ace-generic.h index 4696f24d1492..4ff844bcb1cd 100644 --- a/arch/um/include/asm/ptrace-generic.h +++ b/arch/um/include/asm/ptrace-generic.h @@ -29,6 +29,12 @@ struct pt_regs { =20 #define PTRACE_OLDSETOPTIONS 21 =20 +#ifdef CONFIG_BINFMT_ELF_FDPIC +#define PTRACE_GETFDPIC 31 +#define PTRACE_GETFDPIC_EXEC 0 +#define PTRACE_GETFDPIC_INTERP 1 +#endif + struct task_struct; =20 extern long subarch_ptrace(struct task_struct *child, long request, diff --git a/arch/x86/um/asm/elf.h b/arch/x86/um/asm/elf.h index 62ed5d68a978..33f69f1eac10 100644 --- a/arch/x86/um/asm/elf.h +++ b/arch/x86/um/asm/elf.h @@ -9,6 +9,7 @@ #include =20 #define CORE_DUMP_USE_REGSET +#define ELF_FDPIC_CORE_EFLAGS 0 =20 #ifdef CONFIG_X86_32 =20 @@ -190,8 +191,11 @@ extern int arch_setup_additional_pages(struct linux_bi= nprm *bprm, =20 extern unsigned long um_vdso_addr; #define AT_SYSINFO_EHDR 33 -#define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr) - +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr); \ + NEW_AUX_ENT(AT_MINSIGSTKSZ, 0); \ +} while (0) #endif =20 typedef unsigned long elf_greg_t; diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index bd2f530e5740..419ba0282806 100644 --- a/fs/Kconfig.binfmt +++ b/fs/Kconfig.binfmt @@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY config BINFMT_ELF_FDPIC bool "Kernel support for FDPIC ELF binaries" default y if !BINFMT_ELF - depends on ARM || ((M68K || RISCV || SUPERH || XTENSA) && !MMU) + depends on ARM || ((M68K || RISCV || SUPERH || UML || XTENSA) && !MMU) select ELFCORE help ELF FDPIC binaries are based on ELF, but allow the individual load --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 4BF9F1DE8B4 for ; Wed, 30 Apr 2025 04:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987262; cv=none; b=WvaRS8izl4pSsT4vQ0r4qaDotRUgEs+xjXfwZPwdAFh2X1c+tYz3ebfbCc7vM3d0D/TcPRAYCTTZpJ5JRBDXp3EarZlkXu8X4o8C4o5lFLfPoIw0zyaD0n+zA15bBeJRyD84O6rIZOSrTheThe6E0gJTWhgRSp5qd3AfRUhnU+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987262; c=relaxed/simple; bh=14ZwErdFw/tkVVG22Dt416W3KY7eTBOFbpsU/xBx3Ek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dWB51QJVdih+0X6Or264Cv8xMQ/h1BgQn1iALhrfiPm6Gv5t1XhOq2Xw6EC1kOJ52PZgndvF/X9UyxTMYtYqWfxZ8LErOgRua6omP9ULwxYbg5jwb9UpFa62eatNJEdFrcoXNkePJSogLZAMMmmPmoulF647njye5TgP9whvBiA= 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=CVe0jmU3; arc=none smtp.client-ip=209.85.214.180 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="CVe0jmU3" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-22423adf751so68759005ad.2 for ; Tue, 29 Apr 2025 21:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987260; x=1746592060; 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=XxkcTNzm3D6nL0kwz3FotmEhOp0HbpyTDMavm76nXag=; b=CVe0jmU3NH21at/3cJucOV/NkL7sQ4xlxXbaAWggs2QGD05U0tBGrMsskKQbNRejsH maNBBhZYCijZAY+GXwqpOJNCFaxbtaUgqCAh9ej7A9ZgrMI4EBCR75UIcxA2Nde48KRW uwYxZHRv/67qwre0en9gMlcl56iCmAIRlRlQAQME3acO9X/HFTUpa/DPATVcPHTE/d4a wxhSG0ydW6k/WYCbNwwqKCM4FcKLGCbwLyYuCva5Lejzo+VTZWPT93Vnt9HBzkafnxC1 BK9u+EGgf714085k4oEOb89Q2KMi4e7aqVYnPGpS5ZhKTwwenShGUuSCp/xu7we0nTco 8QhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987260; x=1746592060; 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=XxkcTNzm3D6nL0kwz3FotmEhOp0HbpyTDMavm76nXag=; b=RHTYuxqQtmotZVW2/NKRnqBB5ZgLwzEaHiJhoYJUYt4z3Zr96qfEkrgs1pNKYZrNWF 9fFzREOroIaoB5jjSKs2N7nFhYD4WPV4KpSG7yOG3ppIasmYLnUOhM+0LmpJXKIoINDL 03JrxBuz56bSUSkJI4dC4oNsYOYppXrvVFK0XqcjCdkn/xaySTy0xejVo39osXnSm8UI 3ROyE8o638nnn3Cnj5Dx+QXQdnXdVE5hvfPZzt+/2EdKs00BBbDU3Ure5UoUMjl9omOh r+DbSfKd3IP6fBu+aK5y4kdX7PMJxsqPmJcGITNlLUFFJoDf1crppa1zatz3Tgnz6ca3 Ir9g== X-Forwarded-Encrypted: i=1; AJvYcCV22srTFHkLlQtQ6KobKc1pIr+Apcd5sr3PALEq0lNMr6SENzRwnFwdsqhFeY+zE8TawI1EPfCKIzFMPok=@vger.kernel.org X-Gm-Message-State: AOJu0YzyihWs+fVzb5FiGLpfRf7bccvSMl1mJhidhcFrcR4miciUMNXE YahHuhYZRx34FdpjtlvyXbN05w8Qvo9aL3IdKvZzVXnG+juGwMAo X-Gm-Gg: ASbGncvfw9JkL040hEmzUaNVPqltN32NWWJ7xMlrfNziQPSgco6y6SXwBrLUAyjgqpH 8XRVooYrwIWeY6zuzdpmJUNVf8c3+xgOxZPAsdSkCMCEils6LjRsyi4RhUe5ilw+MKSQt7uZoi0 +x4fmhWJClVC9KxC8iofDjaioJU8kHnHUXIv9hCtA7LoC4/wWhdKBf2cQMoSLlVypMcNgFPWoex g6+RGOMHn1D81NHN4vvUwrFlFCpcZ+JzUrcNkCnNAqxvw24Ab8Wd7e4JBBwFU8JDDG0vD+W3FDe BjQHvrD+3U5U3HPXW/a3IXdQRMJePab3LxnGcMXg+eB/LUUWFfWNdOQkGLzCbZ39xqcq85NOiJc CTA3P3XbFsgFvJwhqVgxyZA== X-Google-Smtp-Source: AGHT+IHgdjbusCjYmIH+ACOzIzDAu13eai9H3Z92dIgixBY5dCjEqln5XxlFGM+akjniyzUkMjrgLw== X-Received: by 2002:a17:902:c950:b0:224:c47:cbd with SMTP id d9443c01a7336-22df32b7e5dmr29296215ad.0.1745987259538; Tue, 29 Apr 2025 21:27:39 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db4dbd20dsm112320725ad.79.2025.04.29.21.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:38 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 9C164E94816; Wed, 30 Apr 2025 13:27:36 +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 v8 02/12] um: decouple MMU specific code from the common part Date: Wed, 30 Apr 2025 13:27:08 +0900 Message-ID: <7663e05099b914d3b978a521b2d3f67791a3abe9.1745980082.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 | 27 ------- arch/um/os-Linux/Makefile | 3 +- arch/um/os-Linux/internal.h | 5 ++ arch/um/os-Linux/process.c | 133 ++++++++++++++++++++++++++++++++ arch/um/os-Linux/skas/process.c | 132 ------------------------------- 9 files changed, 223 insertions(+), 197 deletions(-) create mode 100644 arch/um/kernel/mem-pgtable.c diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index 4df1cd0d2017..827a7438509d 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -16,9 +16,10 @@ extra-y :=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 61b5a5ede01c..cbe8b9d03d8c 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -206,45 +205,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 0cd6fad3d908..08959745c30d 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); @@ -295,3 +298,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 05dcdc057af9..5247121d3419 100644 --- a/arch/um/kernel/skas/process.c +++ b/arch/um/kernel/skas/process.c @@ -16,33 +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; -} - -extern int userspace_pid[]; - -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 049dfa5bc9c6..331564888400 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 drivers/ skas/ + umid.o user_syms.o util.o drivers/ +obj-$(CONFIG_MMU) +=3D skas/ =20 CFLAGS_signal.o +=3D -Wframe-larger-than=3D4096 =20 diff --git a/arch/um/os-Linux/internal.h b/arch/um/os-Linux/internal.h index 317fca190c2b..bcbf64ce8cd1 100644 --- a/arch/um/os-Linux/internal.h +++ b/arch/um/os-Linux/internal.h @@ -2,6 +2,11 @@ #ifndef __UM_OS_LINUX_INTERNAL_H #define __UM_OS_LINUX_INTERNAL_H =20 +/* + * process.c + */ +extern int userspace_pid[]; + /* * elf_aux.c */ diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 184566edeee9..2331e32c4898 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,9 +16,15 @@ #include #include #include +#include #include #include #include +#include +#include + +int userspace_pid[NR_CPUS]; +int unscheduled_userspace_iterations; =20 void os_alarm_process(int pid) { @@ -158,3 +165,129 @@ 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"); + +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] =3D mm_idp->pid; +} diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/proces= s.c index ae2aea062f06..40136102fc11 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -5,7 +5,6 @@ */ =20 #include -#include #include #include #include @@ -16,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -25,15 +23,9 @@ #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 @@ -315,8 +307,6 @@ static int __init init_stub_exe_fd(void) } __initcall(init_stub_exe_fd); =20 -int userspace_pid[NR_CPUS]; - /** * start_userspace() - prepare a new userspace process * @stub_stack: pointer to the stub stack. @@ -398,7 +388,6 @@ int start_userspace(unsigned long stub_stack) return err; } =20 -int unscheduled_userspace_iterations; extern unsigned long tt_extra_sched_jiffies; =20 void userspace(struct uml_pt_regs *regs) @@ -560,124 +549,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"); - -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] =3D mm_idp->pid; -} --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 D78241DFE22 for ; Wed, 30 Apr 2025 04:27:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987268; cv=none; b=psEGbj2Ce4EExc9ELaFjdb9oYO3KB6LAAkBNeMAsJJYq0AX5HVdy42lh4vW6O+fleRsUyEQcgBDKlydVGNn3VQZeiRJuDJ8j3/pm8ZgUeBzpzfEqF/vQNrSYs2vzsSJbOPOvoNtc7NTETF/nlPMSVgcbsTSApHVqz3+2lF/zJPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987268; c=relaxed/simple; bh=97Z7HY04S7W0oRfvQvmeek+Uhxqh6sKGJFbTY+DAs+k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PMuW5OF2PyU7IP0HU6pKC9vbQ+lquQA3tJeaOlz48yMsIt7sngOFkwbjqpKoFDvVuX1v1JRCikt7piKOYb3w8UmO0DZeM2aY/3b1kqK5WlFK1qP2GPaZo9XdpejZe5PDa0FihlQtcLk1BPNuNa5o2wfgXR5L+uwpHQev26vHzYY= 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=Gm2D2MRg; arc=none smtp.client-ip=209.85.210.179 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="Gm2D2MRg" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-736a72220edso6882837b3a.3 for ; Tue, 29 Apr 2025 21:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987265; x=1746592065; 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=OCuYr2KP3wBxDodLMaPRY+onEFYkqYFG8HFmFD5AH3Q=; b=Gm2D2MRgmDKixiUEtEClRCC3c4g+A1Ov4iTsUUJrbep0GVLVOCYj2fyXu2UhNACDQm PK7UioXI8x32++6jcjfopaxBlEiwjR8xH2bN9ijuo1R87W96Zf+0aWsOzAJ3MnzmuAyu B5LUI0OiZQu/G+UV6CMfpKA8WLA/O4yrmO6eyua0P30VGPSNIusEC+6nQssCa6XTti1k FqMNEkK/aiq+OkWxlYCiTThkDPjLsZ0rMpNXB5RvqKEPx/NUfF5LUnXpd5yCk2d+sBDf LRb7EyiyAQvVzJSM1U8CERhiylSQkFWS8IYbHwUfbvDr+dZrdrQlt0hiWw86Ayfup+/x 0PCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987265; x=1746592065; 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=OCuYr2KP3wBxDodLMaPRY+onEFYkqYFG8HFmFD5AH3Q=; b=O1vepf55aZJY6Hac1b8tfH3A8YsMIIsnSCw5KWsEd3N7k1uFNFboM98m+WlX/UJ5ze 77rlvUhh2buup8IA7B5n1nCsv0Fu732oAlXr7yELC0w5AUJeSzh/2GNzEHpAmL4z6Loo Hfj6e85YFr3zH8GZnM8wED0fvH9GB7vRLiW77qVKfcQVXmxJCEIA3Lly2AhSxcsJDsKN hSswlpd+MJo2FIAsrWLk1Od2Fb+CzPZeub4g4Fv5/ndXnoIUGL/0xnTDE8ecGAk1Oj6b QL5kJmSQ0LU5KgcJt+KDaidm1WezA7doYCKzLQRD54mDbK8MwDaAYLEPdGnkUtAVFsV4 4UMA== X-Forwarded-Encrypted: i=1; AJvYcCUDSODdxLApuMeg8KCrY7z0bfBe0hGvGHqwDrFhWL0DCG/1wl+Po8EtKcfBz0PIrQDYvr+cIXzeBabVU6M=@vger.kernel.org X-Gm-Message-State: AOJu0YyIu5JS4MS9VmYK6Pw9tPaqeXUhumOdt/AKevfDIMnNn5+AmzhK ViDDM8bCE9OhxpSHLP0Z5Uqqpv+vfAltf3GTjosZrWirHW+exFlP X-Gm-Gg: ASbGncupJ9fCFNUWGSyC1bkYb005r0/bFgxb2iPdRYuRK5790c4Pmx4AoV+akhg7MZQ S8yzW3TbwRlTpv4i6b9Ko/aHlrF/OTm6R25KEzojA3n5xD3J7m1AoYA3tV/XYLpPR1dz/5/2Ba6 CAbeP20L8G0e9LKp+TOBkk8viy0IB6eWmRy69sTj+RqUqvq30vOW2P/edFwjsm9F4BGG5CKABaP dxemjTIb2km4C5Y6hzIxewtdThVsaar+9n8fGrwWqQiOYkzQ+GIWy2NzxEUXsZhTgXMnk0hWbdm N24fq3OJg8P9WxZchg95IEjQ/F6jVsawz3Zwmol3eH7gS9rmpc3cZFUgIgFSE9x62Bqcuw9XyB5 Efp3PG5h/YnU= X-Google-Smtp-Source: AGHT+IH0FbwVRr3MAmvHuDKfwKvFcYAl32DVyoxymDr2Jear3LyL+Hz5Wp7hXom+GZQca10gjxHCUA== X-Received: by 2002:a05:6a00:130e:b0:736:6043:69f9 with SMTP id d2e1a72fcca58-74038a85c28mr2474451b3a.19.1745987264935; Tue, 29 Apr 2025 21:27:44 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74039a62bfdsm628293b3a.142.2025.04.29.21.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:44 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 2BA51E94818; Wed, 30 Apr 2025 13:27:42 +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 v8 03/12] um: nommu: memory handling Date: Wed, 30 Apr 2025 13:27:09 +0900 Message-ID: <2598e5207a53e4ec1f2077b5c5a9f03fc3782506.1745980082.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 commit adds memory operations on UML under !MMU environment. Some part of the original UML code relying on CONFIG_MMU are excluded from compilation when !CONFIG_MMU. Additionally, generic functions such as uaccess, futex, memcpy/strnlen/strncpy can be used as user- and kernel-space share the address space in !CONFIG_MMU mode. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/Makefile | 4 ++++ arch/um/include/asm/futex.h | 4 ++++ arch/um/include/asm/mmu.h | 3 +++ arch/um/include/asm/mmu_context.h | 2 ++ arch/um/include/asm/uaccess.h | 7 ++++--- arch/um/kernel/mem.c | 3 ++- arch/um/os-Linux/mem.c | 4 ++++ arch/um/os-Linux/process.c | 4 ++-- 8 files changed, 25 insertions(+), 6 deletions(-) diff --git a/arch/um/Makefile b/arch/um/Makefile index 1d36a613aad8..fcf4bb915a31 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -46,6 +46,10 @@ ARCH_INCLUDE :=3D -I$(srctree)/$(SHARED_HEADERS) ARCH_INCLUDE +=3D -I$(srctree)/$(HOST_DIR)/um/shared KBUILD_CPPFLAGS +=3D -I$(srctree)/$(HOST_DIR)/um =20 +ifneq ($(CONFIG_MMU),y) +core-y +=3D $(ARCH_DIR)/nommu/ +endif + # -Dvmap=3Dkernel_vmap prevents anything from referencing the libpcap.o sy= mbol so # named - it's a common symbol in libpcap, so we get a binary which crashe= s. # diff --git a/arch/um/include/asm/futex.h b/arch/um/include/asm/futex.h index 780aa6bfc050..785fd6649aa2 100644 --- a/arch/um/include/asm/futex.h +++ b/arch/um/include/asm/futex.h @@ -7,8 +7,12 @@ #include =20 =20 +#ifdef CONFIG_MMU int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *= uaddr); int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 oldval, u32 newval); +#else +#include +#endif =20 #endif diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h index 01422b761aa0..d4087f9499e2 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -15,10 +15,13 @@ typedef struct mm_context { unsigned long sync_tlb_range_from; unsigned long sync_tlb_range_to; =20 +#ifndef CONFIG_MMU + unsigned long end_brk; #ifdef CONFIG_BINFMT_ELF_FDPIC unsigned long exec_fdpic_loadmap; unsigned long interp_fdpic_loadmap; #endif +#endif /* !CONFIG_MMU */ } mm_context_t; =20 #endif diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_co= ntext.h index 23dcc914d44e..033a70166066 100644 --- a/arch/um/include/asm/mmu_context.h +++ b/arch/um/include/asm/mmu_context.h @@ -36,11 +36,13 @@ static inline void switch_mm(struct mm_struct *prev, st= ruct mm_struct *next, } } =20 +#ifdef CONFIG_MMU #define init_new_context init_new_context extern int init_new_context(struct task_struct *task, struct mm_struct *mm= ); =20 #define destroy_context destroy_context extern void destroy_context(struct mm_struct *mm); +#endif =20 #include =20 diff --git a/arch/um/include/asm/uaccess.h b/arch/um/include/asm/uaccess.h index 3a08f9029a3f..eb9b7d577062 100644 --- a/arch/um/include/asm/uaccess.h +++ b/arch/um/include/asm/uaccess.h @@ -23,6 +23,7 @@ #define __addr_range_nowrap(addr, size) \ ((unsigned long) (addr) <=3D ((unsigned long) (addr) + (size))) =20 +#ifdef CONFIG_MMU extern unsigned long raw_copy_from_user(void *to, const void __user *from,= unsigned long n); extern unsigned long raw_copy_to_user(void __user *to, const void *from, u= nsigned long n); extern unsigned long __clear_user(void __user *mem, unsigned long len); @@ -34,9 +35,6 @@ static inline int __access_ok(const void __user *ptr, uns= igned long size); =20 #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER - -#include - static inline int __access_ok(const void __user *ptr, unsigned long size) { unsigned long addr =3D (unsigned long)ptr; @@ -68,5 +66,8 @@ do { \ put_unaligned(*((type *)src), (type *)(dst)); \ current->thread.segv_continue =3D NULL; \ } while (0) +#endif + +#include =20 #endif diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index cbe8b9d03d8c..1e18384381e2 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -64,7 +64,8 @@ void __init mem_init(void) * to be turned on. */ brk_end =3D (unsigned long) UML_ROUND_UP(sbrk(0)); - map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0); + map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, + !IS_ENABLED(CONFIG_MMU)); memblock_free((void *)brk_end, uml_reserved - brk_end); uml_reserved =3D brk_end; min_low_pfn =3D PFN_UP(__pa(uml_reserved)); diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index 72f302f4d197..4f5d9a94f8e2 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c @@ -213,6 +213,10 @@ int __init create_mem_file(unsigned long long len) { int err, fd; =20 + /* NOMMU kernel uses -1 as a fd for further use (e.g., mmap) */ + if (!IS_ENABLED(CONFIG_MMU)) + return -1; + fd =3D create_tmp_file(len); =20 err =3D os_set_exec_close(fd); diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 2331e32c4898..8a615875d1a1 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -70,8 +70,8 @@ int os_map_memory(void *virt, int fd, unsigned long long = off, unsigned long len, prot =3D (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | (x ? PROT_EXEC : 0); =20 - loc =3D mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED, - fd, off); + loc =3D mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED | + (!IS_ENABLED(CONFIG_MMU) ? MAP_ANONYMOUS : 0), fd, off); if (loc =3D=3D MAP_FAILED) return -errno; return 0; --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 256D81DF977 for ; Wed, 30 Apr 2025 04:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987269; cv=none; b=OJMLnNTIbnZuR0qpOXvxeNmbjjdNEA8w+XvdZIj4qfj8ZM7h+zU2qHbAw06ol6DvIDLEYhvRqE9tTri5ekc1ReCCDIX6TrGAN8mv/+zi5uU25NYKK4zw38Hx/YWrQG5a1PN5B+7AkkDG2g/TTnLYkgOLLpwYIamRbnM2ghNl0wU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987269; c=relaxed/simple; bh=uiSxmtJMthrLo+oH9HhdUFVGn3NpOpl/5AJlOYbiDcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c8+fFs0mlKwu9rxhnSJkdtd+M6tBf9S3SMNgP19HkyXAUAXbkBGdd+T2EakKEgRs21jhi3RdUXIygFiyktXjTpfX+4Qj0j/jWZqsibMIHU/g9WZU/JcMqzLw97fgGCK6zS80OHUYvHYC9nHFK8vHrDNCYvEB9d5VjY6SJ0lHq9M= 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=AT9pOPJ8; arc=none smtp.client-ip=209.85.214.181 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="AT9pOPJ8" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-22c33677183so71767915ad.2 for ; Tue, 29 Apr 2025 21:27:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987267; x=1746592067; 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=V/9FDFFbTGgOECfx9E1KzmmWlTydkD+KFqPPHo/qkbE=; b=AT9pOPJ8lYMREO3oTv17/8luTqR8p/0zk7r7AmsjHVf77JJJwKOFkZCWyRBeZHuxAb ty1uyb7qy4qJOJ7K0JK5WcBEQCKeG1PbMuychwrp+72V3EcAmpF1uO55uPh0k6gHJply KnutKiqYCIfRo4d5RT/5bvVxwgunbNUMAAXDWbPLrWnWwD7lUFNHjXJca/1fPhBctQoq NyezMdkj70SuwhDkMRrlhtqAtqv9BHu4UvXopfE/UHfgNWRT4Q6/pxR2sbIOlpiSDECe hgEZz5yVF15ROHuJnSs97ud+Y/N1fEHJEmIV/1vhILSUjpp++c/uGOgO5//tZhe6he/2 8UCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987267; x=1746592067; 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=V/9FDFFbTGgOECfx9E1KzmmWlTydkD+KFqPPHo/qkbE=; b=kqKiTZHgeeXR797bg3JaZpj476XO/hyOKjnBjsAHG9xzd6Ky0IUiS8kr5LNShBZJIX CTPCzWtMkFFFHG0Una6Zg2HjV14ByUS8fuf98uxKubr7gpI0jzPRJumxr07gxnN04ewa vMhCGnbyo6zBzJSsJ1T/d0v4fvgVEOAOQXmW0m4QY0/oOekwPKc02byy8yzEixE6DcoG 5Rgdd1tO5UXGwKl3/sFG+ocJEX4m0W8xcRjlnurmbEYIV4r6sYdsy9NGZGaIHa7owOQt ZengN0s4+dd99UnNcw3NkG2SlhusNqdUC2XUE9WUP31rY75e6xLf5fmQfUCWiI8+WWoE mjXg== X-Forwarded-Encrypted: i=1; AJvYcCWRI/GehMafXjq4jyRZZpGIFYbZo9eguY5CRDML21h1DIwGBgWKe4Fcv7vIJXXJu2oqEUotgVZbhnBgQLM=@vger.kernel.org X-Gm-Message-State: AOJu0YxRqYuac9dd5L5gk6DZugDXuz1mF5jySwQv/J9x79l8ywFTJW/K tHQHJXsGUoyXrBmLfVQQaqu7zyEhfL2zixMQ3ZMxfbtWPLEJIZOk X-Gm-Gg: ASbGncvAoXsro34k+qqHaq9McRyNclnukaNhBIq9Tc+PoZAYsQ6u6HbaD30wTOtOKyB /AtIRWp1Nv/VfqGSChGogAQgWiV0aAfBcw5tjQ3pVXZjQdVvf28hsIykmgsmtYQMzln2FCdhWls QS2zsc94aoxJyfadeWTasPxmttgqeXFvG1UXxPQFamoV5XnXUrpkMLzjAt3LJNw11DJaUTCDdM9 4X9Uk0frQGHfl8PLdWdNO+0Jz7msVJ5mdZXHgVbOOvpIuwuy34PmGetcxY/kADbSJC6MLExuyYH rDFctdwy2Bmy4NcrXghDmOgRbRN7obALFtx0nflZDNdvZa3XOwH8XavNRJiINdYRb1Xbaht5SeR wCWnrP/bn1Rs= X-Google-Smtp-Source: AGHT+IE1t3dxTA3D4yK2A7FdFXYVRfds1pPjBfcX/u2XIDgYkr+Ssgsi8tcGY9rf7mYw6fzn16NtDA== X-Received: by 2002:a17:903:1946:b0:21f:5cd8:c67 with SMTP id d9443c01a7336-22df57d2db9mr17805125ad.31.1745987267296; Tue, 29 Apr 2025 21:27:47 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db50e766bsm112325805ad.149.2025.04.29.21.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:46 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id C0907E9481A; Wed, 30 Apr 2025 13:27:44 +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 v8 04/12] x86/um: nommu: syscall handling Date: Wed, 30 Apr 2025 13:27:10 +0900 Message-ID: <3ba48d392c14777c9a1723b61b7d743ec3a4c14b.1745980082.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 commit introduces an entry point of syscall interface for !MMU mode. It uses an entry function, __kernel_vsyscall, a kernel-wide global symbol accessible from any locations. Although it isn't in the scope of this commit, it can be also exposed via vdso image which is directly accessible from userspace. A standard library (i.e., libc) can utilize this entry point to implement syscall wrapper; we can also use this by hooking syscall for unmodified userspace applications/libraries, which will be implemented in the subsequent commit. This only supports 64-bit mode of x86 architecture. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/x86/um/Makefile | 4 ++ arch/x86/um/nommu/Makefile | 8 +++ arch/x86/um/nommu/do_syscall_64.c | 37 ++++++++++ arch/x86/um/nommu/entry_64.S | 91 +++++++++++++++++++++++++ arch/x86/um/nommu/syscalls.h | 16 +++++ arch/x86/um/shared/sysdep/syscalls_64.h | 6 ++ 6 files changed, 162 insertions(+) create mode 100644 arch/x86/um/nommu/Makefile create mode 100644 arch/x86/um/nommu/do_syscall_64.c create mode 100644 arch/x86/um/nommu/entry_64.S create mode 100644 arch/x86/um/nommu/syscalls.h diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index b42c31cd2390..227af2a987e2 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -32,6 +32,10 @@ obj-y +=3D syscalls_64.o vdso/ subarch-y =3D ../lib/csum-partial_64.o ../lib/memcpy_64.o \ ../lib/memmove_64.o ../lib/memset_64.o =20 +ifneq ($(CONFIG_MMU),y) +obj-y +=3D nommu/ +endif + endif =20 subarch-$(CONFIG_MODULES) +=3D ../kernel/module.o diff --git a/arch/x86/um/nommu/Makefile b/arch/x86/um/nommu/Makefile new file mode 100644 index 000000000000..d72c63afffa5 --- /dev/null +++ b/arch/x86/um/nommu/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +ifeq ($(CONFIG_X86_32),y) + BITS :=3D 32 +else + BITS :=3D 64 +endif + +obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_sysca= ll_64.c new file mode 100644 index 000000000000..5d0fa83e7fdc --- /dev/null +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +__visible void do_syscall_64(struct pt_regs *regs) +{ + int syscall; + + syscall =3D PT_SYSCALL_NR(regs->regs.gp); + UPT_SYSCALL_NR(®s->regs) =3D syscall; + + pr_debug("syscall(%d) (current=3D%lx) (fn=3D%lx)\n", + syscall, (unsigned long)current, + (unsigned long)sys_call_table[syscall]); + + if (likely(syscall < NR_syscalls)) { + PT_REGS_SET_SYSCALL_RETURN(regs, + EXECUTE_SYSCALL(syscall, regs)); + } + + pr_debug("syscall(%d) --> %lx\n", syscall, + regs->regs.gp[HOST_AX]); + + PT_REGS_SYSCALL_RET(regs) =3D regs->regs.gp[HOST_AX]; + + /* execve succeeded */ + if (syscall =3D=3D __NR_execve && regs->regs.gp[HOST_AX] =3D=3D 0) + userspace(¤t->thread.regs.regs); + + /* force do_signal() --> is_syscall() */ + set_thread_flag(TIF_SIGPENDING); + interrupt_end(); +} diff --git a/arch/x86/um/nommu/entry_64.S b/arch/x86/um/nommu/entry_64.S new file mode 100644 index 000000000000..e9bfc7b93c84 --- /dev/null +++ b/arch/x86/um/nommu/entry_64.S @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include + +#include +#include +#include + +#include "../entry/calling.h" + +#ifdef CONFIG_SMP +#error need to stash these variables somewhere else +#endif + +#define UM_GLOBAL_VAR(x) .data; .align 8; .globl x; x:; .long 0 + +UM_GLOBAL_VAR(current_top_of_stack) +UM_GLOBAL_VAR(current_ptregs) + +.code64 +.section .entry.text, "ax" + +.align 8 +#undef ENTRY +#define ENTRY(x) .text; .globl x; .type x,%function; x: +#undef END +#define END(x) .size x, . - x + +/* + * %rcx has the return address (we set it before entering __kernel_vsyscal= l). + * + * Registers on entry: + * rax system call number + * rcx return address + * rdi arg0 + * rsi arg1 + * rdx arg2 + * r10 arg3 + * r8 arg4 + * r9 arg5 + * + * (note: we are allowed to mess with r11: r11 is callee-clobbered + * register in C ABI) + */ +ENTRY(__kernel_vsyscall) + + movq %rsp, %r11 + + /* Point rsp to the top of the ptregs array, so we can + just fill it with a bunch of push'es. */ + movq current_ptregs, %rsp + + /* 8 bytes * 20 registers (plus 8 for the push) */ + addq $168, %rsp + + /* Construct struct pt_regs on stack */ + pushq $0 /* pt_regs->ss (index 20) */ + pushq %r11 /* pt_regs->sp */ + pushfq /* pt_regs->flags */ + pushq $0 /* pt_regs->cs */ + pushq %rcx /* pt_regs->ip */ + pushq %rax /* pt_regs->orig_ax */ + + PUSH_AND_CLEAR_REGS rax=3D$-ENOSYS + + mov %rsp, %rdi + + /* + * Switch to current top of stack, so "current->" points + * to the right task. + */ + movq current_top_of_stack, %rsp + + call do_syscall_64 + + movq current_ptregs, %rsp + + POP_REGS + + addq $8, %rsp /* skip orig_ax */ + popq %rcx /* pt_regs->ip */ + addq $8, %rsp /* skip cs */ + addq $8, %rsp /* skip flags */ + popq %rsp + + /* + * not return w/ ret but w/ jmp as the stack is already popped before + * entering __kernel_vsyscall + */ + jmp *%rcx + +END(__kernel_vsyscall) diff --git a/arch/x86/um/nommu/syscalls.h b/arch/x86/um/nommu/syscalls.h new file mode 100644 index 000000000000..a2433756b1fc --- /dev/null +++ b/arch/x86/um/nommu/syscalls.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_SYSCALLS_H +#define __UM_NOMMU_SYSCALLS_H + + +#define task_top_of_stack(task) \ +({ \ + unsigned long __ptr =3D (unsigned long)task->stack; \ + __ptr +=3D THREAD_SIZE; \ + __ptr; \ +}) + +extern long current_top_of_stack; +extern long current_ptregs; + +#endif diff --git a/arch/x86/um/shared/sysdep/syscalls_64.h b/arch/x86/um/shared/s= ysdep/syscalls_64.h index b6b997225841..ffd80ee3b9dc 100644 --- a/arch/x86/um/shared/sysdep/syscalls_64.h +++ b/arch/x86/um/shared/sysdep/syscalls_64.h @@ -25,4 +25,10 @@ extern syscall_handler_t *sys_call_table[]; extern syscall_handler_t sys_modify_ldt; extern syscall_handler_t sys_arch_prctl; =20 +#ifndef CONFIG_MMU +extern void do_syscall_64(struct pt_regs *regs); +extern long __kernel_vsyscall(int64_t a0, int64_t a1, int64_t a2, int64_t = a3, + int64_t a4, int64_t a5, int64_t a6); +#endif + #endif --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 C67BE1E1C09 for ; Wed, 30 Apr 2025 04:27:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987272; cv=none; b=hckqUub8AYFF8PbikSCXjLz0cOXldTh81yn2tURNfodAJ5SMslr3zFcH6rftQrGb4EDVJz++YGrLiXUuW1N8rlhNA3YtWDG8YTr+b9GFl985NoYZxPAjw8istalE6PcMXy3KmVsHmBrfHJDHIYzwZA4mjO7IqxZC49isRJ0KU5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987272; c=relaxed/simple; bh=9QLQzR2LZqRiGtzgc/CnL0hE02EicK9KVjH9YleUWoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ppd/M7ULnIGNW+dUORNmFFPnp7CJ9W9T+w/C+Sk2HNa9GmJdqZefNTdcrBWQyhEh3Epv1XbaJlSOqOYd5WA67EOLSfmV/EgnwzrP5pY0YLVQoml/vR9+R20c4eLMxw6z5EqaZz77wMMzlwlPRKtOCDmdCwPk2qbgRGl278DyjK8= 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=PguT0xP/; arc=none smtp.client-ip=209.85.214.173 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="PguT0xP/" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2241053582dso102570085ad.1 for ; Tue, 29 Apr 2025 21:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987270; x=1746592070; 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=+Rda5w8ftnYQQ6W3q5FgOQJiq+Hj9EhDJE6pWtJC4Ow=; b=PguT0xP/YdQPkyo8MNDll/uHYZWKEDWopJS016hvHmIFcg46/rwaw8ar9ZrLeUP1mN YccaPwas3xlRG9Bbi0VKTx9HXkzelNHkmMmS4hNaIXaeSAwNd8dqJYJZZy0ZzWrcpqav z/trWt2qZwiYFSAgGz6vUJLYiyiqIUR+8MkDDDd0VKf9myD7iniUV9N2GafLh/xveWdP vnC6/rPnrXfHNsMemeDDke0hNOCHS/ncmib+lVb216AbXMHGNDPpoXJmcfb7BqQ1/ncF NRAJtesaFEXcT2Y44bW9boMu3DYg2hqPvy3ogCoQLkgkGuk+GyekFc/pVsWR4cUFFM6d yZWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987270; x=1746592070; 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=+Rda5w8ftnYQQ6W3q5FgOQJiq+Hj9EhDJE6pWtJC4Ow=; b=qbckiz3jduD5twjE8uEvwAXmT5dh9akIz04RDZ6cPZ0bY27mKbzeULlH7kHvdxCxgu YPzRHW39BRsW2El9Me2fV2PlcZx2kG534W/25DBf08JPUSAhQvwU2ykzalYlLz5k/fmd OOuP8UONLdm9b1XwgdO9B4F2RkHV4jf6OORrR/GkieKDczmvwmn4VUFOGnRWk6j3RHnb hHQFTuh0c+dIDKPumZNXV0Gmhta08aBQ6jAgq/fBynGcMyP/ATMYdltbx0qURA4C7ktk 65zTlmN0em99X5Mx90TyN8M4RXlZQjPUbTtYQekk2DL9PTR7Si6kd3DqOXx05tMifpbL bzBg== X-Forwarded-Encrypted: i=1; AJvYcCXuqKVenEN2pPCrpMuf1oz7JK6MK8rveRO36jpRoMuZNotQXuR2uO6lWwXrQHJ+hjuzdPAfTRO9icmm7wg=@vger.kernel.org X-Gm-Message-State: AOJu0YxGwafPfSPVWvzwuCJrR3SE001wBONd6gabhPFYISoZp5+Yx+bz bLUNw0+eSem+o2nn5eAnH9NbWYfYtqXTgpo0wVYVTm3u3AtczsJ2 X-Gm-Gg: ASbGncsm0vJLU1Q6jrxYDjLu5PICXiiKjazEoSGo2VPc4bYnk6veFufemsgAzTKWxty m4ZWSUnCIwrYL8wJ4CfOAVFUap4Rn4eE/iIgiYJNe8+rS3xxctz9E5X3y/W8m3tnw/rwwiAWcgW 6V3SsbY+pnbXAtP4sRB2xMjaoGNRYcfzYo4Xww7mgQCjSgsGiq2leEkkz7IouZXkI0+7xxBO0MP 8SMOHD05s1Il8bDYII1ph6vLZ0GJNq+ZThj1+y3NlbLPVYsGrT7vs3TlZiuSXxjB2OvpYodlK3j Le+eQelV3CvUPQXhs0jmgNu1svTxRK1ejwlOvZP4TGnffnr5Yb6qNsNQ/nUqUEbW6LJtuuR266z mm222by27uqY= X-Google-Smtp-Source: AGHT+IFM9+qSbHZo6PrAllTRnzE6ZKUFkumQZ/B0AYyUyUFgvdPZvBGr40PMIlqIRsils5Ezf29wWA== X-Received: by 2002:a17:902:e84b:b0:223:5c33:56a8 with SMTP id d9443c01a7336-22df581e52cmr18188695ad.35.1745987269925; Tue, 29 Apr 2025 21:27:49 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db50e7c1bsm112367585ad.107.2025.04.29.21.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:49 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 6F158E9481C; Wed, 30 Apr 2025 13:27:47 +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, Kenichi Yasukata Subject: [PATCH v8 05/12] um: nommu: seccomp syscalls hook Date: Wed, 30 Apr 2025 13:27:11 +0900 Message-ID: <1a00eb90cbfa24befe9bdd5416a8fb837881deae.1745980082.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 commit adds syscall hook with seccomp. Using seccomp raises SIGSYS to UML process, which is captured in the (UML) kernel, then jumps to the syscall entry point, __kernel_vsyscall, to hook the original syscall instructions. The SIGSYS signal is raised upon the execution from uml_reserved and high_physmem, which locates userspace memory. Signed-off-by: Hajime Tazaki Signed-off-by: Kenichi Yasukata --- arch/um/include/shared/kern_util.h | 2 + arch/um/include/shared/os.h | 10 +++ arch/um/kernel/um_arch.c | 3 + arch/um/nommu/Makefile | 3 + arch/um/nommu/os-Linux/Makefile | 7 +++ arch/um/nommu/os-Linux/signal.c | 16 +++++ arch/um/os-Linux/Makefile | 5 ++ arch/um/os-Linux/seccomp.c | 87 +++++++++++++++++++++++++++ arch/um/os-Linux/signal.c | 8 +++ arch/x86/um/nommu/Makefile | 2 +- arch/x86/um/nommu/os-Linux/Makefile | 6 ++ arch/x86/um/nommu/os-Linux/mcontext.c | 13 ++++ arch/x86/um/shared/sysdep/mcontext.h | 3 + 13 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 arch/um/nommu/Makefile create mode 100644 arch/um/nommu/os-Linux/Makefile create mode 100644 arch/um/nommu/os-Linux/signal.c create mode 100644 arch/um/os-Linux/seccomp.c create mode 100644 arch/x86/um/nommu/os-Linux/Makefile create mode 100644 arch/x86/um/nommu/os-Linux/mcontext.c diff --git a/arch/um/include/shared/kern_util.h b/arch/um/include/shared/ke= rn_util.h index 00ca3e12fd9a..2c8c18bd5860 100644 --- a/arch/um/include/shared/kern_util.h +++ b/arch/um/include/shared/kern_util.h @@ -66,6 +66,8 @@ extern void segv_handler(int sig, struct siginfo *unused_= si, struct uml_pt_regs extern void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *= regs, void *mc); extern void fatal_sigsegv(void) __attribute__ ((noreturn)); +extern void sigsys_handler(int sig, struct siginfo *si, struct uml_pt_regs= *, + void *mc); =20 void um_idle_sleep(void); =20 diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 152a60080d5b..7f6703869dde 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -338,4 +338,14 @@ extern void um_trace_signals_off(void); /* time-travel */ extern void deliver_time_travel_irqs(void); =20 +/* seccomp.c */ +#ifdef CONFIG_MMU +static inline int os_setup_seccomp(void) +{ + return 0; +} +#else +extern int os_setup_seccomp(void); +#endif + #endif diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index 7f050783885a..2b591e929eca 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -433,6 +433,9 @@ void __init setup_arch(char **cmdline_p) add_bootloader_randomness(rng_seed, sizeof(rng_seed)); memzero_explicit(rng_seed, sizeof(rng_seed)); } + + /* install seccomp filter */ + os_setup_seccomp(); } =20 void __init arch_cpu_finalize_init(void) diff --git a/arch/um/nommu/Makefile b/arch/um/nommu/Makefile new file mode 100644 index 000000000000..baab7c2f57c2 --- /dev/null +++ b/arch/um/nommu/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y :=3D os-Linux/ diff --git a/arch/um/nommu/os-Linux/Makefile b/arch/um/nommu/os-Linux/Makef= ile new file mode 100644 index 000000000000..68833c576437 --- /dev/null +++ b/arch/um/nommu/os-Linux/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y :=3D signal.o +USER_OBJS :=3D $(obj-y) + +include $(srctree)/arch/um/scripts/Makefile.rules +USER_CFLAGS+=3D-I$(srctree)/arch/um/os-Linux diff --git a/arch/um/nommu/os-Linux/signal.c b/arch/um/nommu/os-Linux/signa= l.c new file mode 100644 index 000000000000..19043b9652e2 --- /dev/null +++ b/arch/um/nommu/os-Linux/signal.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +void sigsys_handler(int sig, struct siginfo *si, + struct uml_pt_regs *regs, void *ptr) +{ + mcontext_t *mc =3D (mcontext_t *) ptr; + + /* hook syscall via SIGSYS */ + set_mc_sigsys_hook(mc); +} diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index 331564888400..6bfdfec8cbcc 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile @@ -21,4 +21,9 @@ USER_OBJS :=3D $(user-objs-y) elf_aux.o execvp.o file.o h= elper.o irq.o \ main.o mem.o process.o registers.o sigio.o signal.o start_up.o time.o \ tty.o umid.o util.o =20 +ifneq ($(CONFIG_MMU),y) +obj-y +=3D seccomp.o +USER_OBJS +=3D seccomp.o +endif + include $(srctree)/arch/um/scripts/Makefile.rules diff --git a/arch/um/os-Linux/seccomp.c b/arch/um/os-Linux/seccomp.c new file mode 100644 index 000000000000..d1cfa6e3d632 --- /dev/null +++ b/arch/um/os-Linux/seccomp.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include /* For SYS_xxx definitions */ +#include +#include +#include +#include +#include + +int __init os_setup_seccomp(void) +{ + int err; + unsigned long __userspace_start =3D uml_reserved, + __userspace_end =3D high_physmem; + + struct sock_filter filter[] =3D { + /* if (IP_high > __userspace_end) allow; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JGT + BPF_K, __userspace_end >> 32, + /*true-skip=3D*/0, /*false-skip=3D*/1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high =3D=3D __userspace_end && IP_low >=3D __userspace_end) al= low; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __userspace_end >> 32, + /*true-skip=3D*/0, /*false-skip=3D*/3), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer)), + BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, __userspace_end, + /*true-skip=3D*/0, /*false-skip=3D*/1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high < __userspace_start) allow; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, __userspace_start >> 32, + /*true-skip=3D*/1, /*false-skip=3D*/0), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high =3D=3D __userspace_start && IP_low < __userspace_start) a= llow; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __userspace_start >> 32, + /*true-skip=3D*/0, /*false-skip=3D*/3), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer)), + BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, __userspace_start, + /*true-skip=3D*/1, /*false-skip=3D*/0), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* other address; trap */ + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_TRAP), + }; + struct sock_fprog prog =3D { + .len =3D ARRAY_SIZE(filter), + .filter =3D filter, + }; + + err =3D prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); + if (err) + os_warn("PR_SET_NO_NEW_PRIVS (err=3D%d, ernro=3D%d)\n", + err, errno); + + err =3D syscall(SYS_seccomp, SECCOMP_SET_MODE_FILTER, + SECCOMP_FILTER_FLAG_TSYNC, &prog); + if (err) { + os_warn("SECCOMP_SET_MODE_FILTER (err=3D%d, ernro=3D%d)\n", + err, errno); + exit(1); + } + + set_handler(SIGSYS); + + os_info("seccomp: setup filter syscalls in the range: 0x%lx-0x%lx\n", + __userspace_start, __userspace_end); + + return 0; +} + diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c index e71e5b4878d1..9adc729c20bd 100644 --- a/arch/um/os-Linux/signal.c +++ b/arch/um/os-Linux/signal.c @@ -20,6 +20,7 @@ #include #include #include +#include =20 void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *, void *= mc) =3D { [SIGTRAP] =3D relay_signal, @@ -29,6 +30,7 @@ void (*sig_info[NSIG])(int, struct siginfo *, struct uml_= pt_regs *, void *mc) =3D [SIGBUS] =3D relay_signal, [SIGSEGV] =3D segv_handler, [SIGIO] =3D sigio_handler, + [SIGSYS] =3D sigsys_handler, }; =20 static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc) @@ -167,6 +169,11 @@ static void sigusr1_handler(int sig, struct siginfo *u= nused_si, mcontext_t *mc) uml_pm_wake(); } =20 +__weak void sigsys_handler(int sig, struct siginfo *unused_si, + struct uml_pt_regs *regs, void *mc) +{ +} + void register_pm_wake_signal(void) { set_handler(SIGUSR1); @@ -178,6 +185,7 @@ static void (*handlers[_NSIG])(int sig, struct siginfo = *si, mcontext_t *mc) =3D { [SIGILL] =3D sig_handler, [SIGFPE] =3D sig_handler, [SIGTRAP] =3D sig_handler, + [SIGSYS] =3D sig_handler, =20 [SIGIO] =3D sig_handler, [SIGWINCH] =3D sig_handler, diff --git a/arch/x86/um/nommu/Makefile b/arch/x86/um/nommu/Makefile index d72c63afffa5..ebe47d4836f4 100644 --- a/arch/x86/um/nommu/Makefile +++ b/arch/x86/um/nommu/Makefile @@ -5,4 +5,4 @@ else BITS :=3D 64 endif =20 -obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o +obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o os-Linux/ diff --git a/arch/x86/um/nommu/os-Linux/Makefile b/arch/x86/um/nommu/os-Lin= ux/Makefile new file mode 100644 index 000000000000..4571e403a6ff --- /dev/null +++ b/arch/x86/um/nommu/os-Linux/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y =3D mcontext.o +USER_OBJS :=3D mcontext.o + +include $(srctree)/arch/um/scripts/Makefile.rules diff --git a/arch/x86/um/nommu/os-Linux/mcontext.c b/arch/x86/um/nommu/os-L= inux/mcontext.c new file mode 100644 index 000000000000..c4ef877d5ea0 --- /dev/null +++ b/arch/x86/um/nommu/os-Linux/mcontext.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#define __FRAME_OFFSETS +#include +#include +#include +#include + +void set_mc_sigsys_hook(mcontext_t *mc) +{ + mc->gregs[REG_RCX] =3D mc->gregs[REG_RIP]; + mc->gregs[REG_RIP] =3D (unsigned long) __kernel_vsyscall; +} diff --git a/arch/x86/um/shared/sysdep/mcontext.h b/arch/x86/um/shared/sysd= ep/mcontext.h index b724c54da316..15e9ff287021 100644 --- a/arch/x86/um/shared/sysdep/mcontext.h +++ b/arch/x86/um/shared/sysdep/mcontext.h @@ -7,6 +7,9 @@ #define __SYS_SIGCONTEXT_X86_H =20 extern void get_regs_from_mc(struct uml_pt_regs *, mcontext_t *); +#ifndef CONFIG_MMU +extern void set_mc_sigsys_hook(mcontext_t *mc); +#endif =20 #ifdef __i386__ =20 --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 78ED21E2613 for ; Wed, 30 Apr 2025 04:27:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987274; cv=none; b=nJPibI8rZTFK4pPWIB7hhg+vBQ2iNM3vitrHeiw1OEpDfI6O6eCNGpq94b9LRUwv2Bcy+I3xU1rpup5fzT9zWiXeJZ1mDf/Q9B1cENBWfwddpK4ppiKpf7YYhqG3VfyEmbadpnGshLTvkkOIJx3qv5E3Gd7LIfun/8RFZ/V8lqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987274; c=relaxed/simple; bh=pRI1lMDDqWLaTBC/3kskcvEDE+HR1dGRP/QuNgv527s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LNsL0lZJGZ4qApUUHyyumfFxvr5uy1q7Zbgr4G7zNq5nA/Q694auUwyz3iIw81A7R0JY1QtLaYSOxeMQ2GwjYOLAoE1QrOtTYsH7ZAP5CHDTlUsXAPu86JrNMY2muQx4Nisun0LfqNJlczVOW0JJ19BGsjz/m8uwVMjHa7DylsM= 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=gHUDrrxI; arc=none smtp.client-ip=209.85.214.180 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="gHUDrrxI" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-22409077c06so109264305ad.1 for ; Tue, 29 Apr 2025 21:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987272; x=1746592072; 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=Q5NKRA2Vd8iUo2TNfSXqtZxbhUvo/xKWVJfwrs+7skI=; b=gHUDrrxIV2x9A5WckWMH0ENTEh/MamDOXC1yhzlEzXw+IWPRmT3lZEkrlgmaVQp9L6 x1MXZm9MukquuyP8+ui2RK+ZOlq/7ECxqenT+D1r4uxpAnjby5gQ0e6XjFqiIobwl3gj +QmtQxsjvsQQc5GJ0bqYKFEMUuPsU/2etovLnGhCzqT6Wo98azqs0XblV1lp1LdPBzOM QP8+U+9Vo6su456L5kiEdt6bDdKppgm6WzgN/i0KOcdE99vQ/xxI4imIPyMmBouGbzIB Hom4CA3MWVgvQXq7Po4bQKCw4TqrX8W2tOFF0QKlex0D37Bx1ArdycON6nFLKDN3SQhK CvFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987272; x=1746592072; 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=Q5NKRA2Vd8iUo2TNfSXqtZxbhUvo/xKWVJfwrs+7skI=; b=nYgFFTIsobPguxQlzmlA3fO1hf6LxHiGlGCkNUQahzEnnkM6Fog1nLyeEB2nXZvm1E pFYVQx2rGhsFYDQTVFBKUvno/aRJmC8IvFVcZJpDgf9Yi8GNGmaXcOQ4C7UwUQbQakKv QP4gdmzsmCX5rmz3qPD87iAB9PlXxVg6sXfTCVcHKpWvjY2B+nSR/5XDmmMdzKQb8COK bKYte7B/2poSqKSmNzpYsrFxMnNgbc0C8RYa/GJMjB05u32uUxQWGbylQMUFXCzMOA+l 4NJwmXAV2t/YE92WEn6aneuDtCgDQKgkT14XT7W113l0pZp9b9o6iVKniVYFTb6PUx+s AZCw== X-Forwarded-Encrypted: i=1; AJvYcCWuT4SmrHMtaO5OXIbITCHgZwsmTIcfq9i0QVz/F08FrGzz3ZKL9COxZj4IS/W6yk4ipHF12zmpCf2K+Yk=@vger.kernel.org X-Gm-Message-State: AOJu0YzUWZSeSsli0JN+NmUAmXjFupnb2oB5t535oHn+fUTilGwhnXA4 F+nJSPn69VDPUYNfhOEmR1jU/a/NSPr3dYKJT3Ywvisl6u7laJj3 X-Gm-Gg: ASbGnctjjqjphbHIg2QrI3DCQzjeDGzIDlN9M4MFh7JedGa3Kyb3q/jDlWpoXR1kJk3 pbeZYRX5Si05cWa7rW0xp3p5mVshIfZbCumduIdweZwY4EpVsiw3WWaWgqa4ablu2caIVj+z7C7 hU1C+JgXSf85rAxvDmuDe4POw9Vzlne+Enbtom9h1gkplfJxrq8EYAw5/P4tzjj9JkFDU1IAFMH DtDaxiYhc/vfV8uPG++91SCCGKDIZrbaT9RDmlVsPuD45IMQyAlWsx7uHIsBTYK8ajnMf8JaSf7 di+LikxbdUgOb+gMEatOQkvnTVq9dm5GJ1NL4UZ79b+F/zgBKu80dMPBWDoou0tQvc7d/7Xl1p/ lAasjBTALZV4= X-Google-Smtp-Source: AGHT+IGOxIjchaID2CDqMQJI7v4ig2oBAAKA/o5gORT6xH9R/bvvse4aK4O3R8Prfqt9cmDnq/3Z6A== X-Received: by 2002:a17:903:298e:b0:224:1c1:4ac1 with SMTP id d9443c01a7336-22df358f9c2mr28149925ad.47.1745987271755; Tue, 29 Apr 2025 21:27:51 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db50e7a33sm112187705ad.146.2025.04.29.21.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:51 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id C7F08E9481E; Wed, 30 Apr 2025 13:27:49 +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 v8 06/12] x86/um: nommu: process/thread handling Date: Wed, 30 Apr 2025 13:27:12 +0900 Message-ID: <71d4afcd72f3ea4a513c012c8bc6db04419f57e9.1745980082.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" Since ptrace facility isn't used under !MMU of UML, there is different code path to invoke processes/threads; there are no external process used, and need to properly configure some of registers (fs segment register for TLS, etc) on every context switch, etc. Signals aren't delivered in non-ptrace syscall entry/leave so, we also need to handle pending signal by ourselves. ptrace related syscalls are not tested yet so, marked arch_has_single_step() unsupported in !MMU environment. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/asm/ptrace-generic.h | 2 +- arch/um/os-Linux/process.c | 6 ++++ arch/x86/um/Makefile | 3 +- arch/x86/um/nommu/Makefile | 2 +- arch/x86/um/nommu/entry_64.S | 22 ++++++++++++++ arch/x86/um/nommu/syscalls_64.c | 44 ++++++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 arch/x86/um/nommu/syscalls_64.c diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptr= ace-generic.h index 4ff844bcb1cd..a9778c9a59a3 100644 --- a/arch/um/include/asm/ptrace-generic.h +++ b/arch/um/include/asm/ptrace-generic.h @@ -14,7 +14,7 @@ struct pt_regs { struct uml_pt_regs regs; }; =20 -#define arch_has_single_step() (1) +#define arch_has_single_step() (IS_ENABLED(CONFIG_MMU)) =20 #define EMPTY_REGS { .regs =3D EMPTY_UML_PT_REGS } =20 diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 8a615875d1a1..3ac01881e905 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -28,6 +28,9 @@ int unscheduled_userspace_iterations; =20 void os_alarm_process(int pid) { + if (pid <=3D 0) + return; + kill(pid, SIGALRM); } =20 @@ -45,6 +48,9 @@ void os_kill_process(int pid, int reap_child) =20 void os_kill_ptraced_process(int pid, int reap_child) { + if (pid <=3D 0) + return; + kill(pid, SIGKILL); ptrace(PTRACE_KILL, pid); ptrace(PTRACE_CONT, pid); diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index 227af2a987e2..53c9ebb3c41c 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -27,7 +27,8 @@ subarch-y +=3D ../kernel/sys_ia32.o =20 else =20 -obj-y +=3D syscalls_64.o vdso/ +obj-y +=3D vdso/ +obj-$(CONFIG_MMU) +=3D syscalls_64.o =20 subarch-y =3D ../lib/csum-partial_64.o ../lib/memcpy_64.o \ ../lib/memmove_64.o ../lib/memset_64.o diff --git a/arch/x86/um/nommu/Makefile b/arch/x86/um/nommu/Makefile index ebe47d4836f4..4018d9e0aba0 100644 --- a/arch/x86/um/nommu/Makefile +++ b/arch/x86/um/nommu/Makefile @@ -5,4 +5,4 @@ else BITS :=3D 64 endif =20 -obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o os-Linux/ +obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o syscalls_$(BITS).o os-Linux/ diff --git a/arch/x86/um/nommu/entry_64.S b/arch/x86/um/nommu/entry_64.S index e9bfc7b93c84..950447dfa66b 100644 --- a/arch/x86/um/nommu/entry_64.S +++ b/arch/x86/um/nommu/entry_64.S @@ -89,3 +89,25 @@ ENTRY(__kernel_vsyscall) jmp *%rcx =20 END(__kernel_vsyscall) + +// void userspace(struct uml_pt_regs *regs) +ENTRY(userspace) + + /* align the stack for x86_64 ABI */ + and $-0x10, %rsp + /* Handle any immediate reschedules or signals */ + call interrupt_end + + movq current_ptregs, %rsp + + POP_REGS + + addq $8, %rsp /* skip orig_ax */ + popq %r11 /* pt_regs->ip */ + addq $8, %rsp /* skip cs */ + addq $8, %rsp /* skip flags */ + popq %rsp + + jmp *%r11 + +END(userspace) diff --git a/arch/x86/um/nommu/syscalls_64.c b/arch/x86/um/nommu/syscalls_6= 4.c new file mode 100644 index 000000000000..c78c442aed1d --- /dev/null +++ b/arch/x86/um/nommu/syscalls_64.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2003 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) + * Copyright 2003 PathScale, Inc. + * + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include /* XXX This should get the constants from libc */ +#include +#include +#include "syscalls.h" + +void arch_switch_to(struct task_struct *to) +{ + /* + * In !CONFIG_MMU, it doesn't ptrace thus, + * The FS_BASE/GS_BASE registers are saved here. + */ + current_top_of_stack =3D task_top_of_stack(to); + current_ptregs =3D (long)task_pt_regs(to); + + if ((to->thread.regs.regs.gp[FS_BASE / sizeof(unsigned long)] =3D=3D 0) || + (to->mm =3D=3D NULL)) + return; + + /* this changes the FS on every context switch */ + arch_prctl(to, ARCH_SET_FS, + (void __user *) to->thread.regs.regs.gp[FS_BASE / sizeof(unsigned lon= g)]); +} + +SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, + unsigned long, prot, unsigned long, flags, + unsigned long, fd, unsigned long, off) +{ + if (off & ~PAGE_MASK) + return -EINVAL; + + return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); +} --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 32C3F33EC for ; Wed, 30 Apr 2025 04:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987768; cv=none; b=Y8KJpr220sxdP1xYCOY5EKZA1yt4Z+ztB8OMtDP2z/juE017ZADt4BmZ74gT8NRc1YK9O4wubfxP7WzIFJ/1fk3XfZNtiYlgCb7QClpcRigu42ZE7fsY2mS9rd8+Twhh+iRvAVXis5YMAInpoEtx4UzfpxL0ZuDKlFAA28FVQNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987768; c=relaxed/simple; bh=khQbOphnaTF3Rbt52w+eeGcF1LQO4WOApscpm1Ts69I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XQxSvMJqEjSdBl5KWcDDtOt9x67qOzudvAV89+sOErVD22V6aDCtmzYuAY/Ho0zA3bEk0B03+wVKPdQcTCl/qlOjFx+WOfEaPEz5bKDBxdGV8RjoS9PfF703nXmYo7h5LZzu012QU3jfRgISlEmnEab5sVsC0dPtXGauIzhkhdU= 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=BL3N+bEa; arc=none smtp.client-ip=209.85.219.54 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="BL3N+bEa" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6ecf99dd567so99784276d6.0 for ; Tue, 29 Apr 2025 21:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987765; x=1746592565; 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=RhZelJwiTUJ/UkMrQlTULCdNhOyleWw7wnwmeZqJPjo=; b=BL3N+bEaGvfZ/pb9AMiBGlwTTaazthGNUEKZP9634MzsVhmNrymnaA5hYQh2iQwAag iHGu07hCHuSnpezDZAGNfNgjDIPkZxR8rEnCNTNlobbBQQsfuFADEwTsevCc7O3Uo1hx t3hBbYunQFlaPKPsuE7HOhlkQ5djDBXRIeP0tGtRUhFfvvmTay4nf4es4yxfiTn53yOS /AUfM8Ds5/uvRM1g2eQ8XDXdq18syXkK99oUfHxtSfJ3vJenyZ6JTnEeVWozRVfezbUL dCQX5TeZYZBTKqJDYkp09mMieaLguUWcFQQcgSvI+I3tWRiw1VlDTLX7kjpxGNxp/UwY ffUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987765; x=1746592565; 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=RhZelJwiTUJ/UkMrQlTULCdNhOyleWw7wnwmeZqJPjo=; b=CI3j6h9+hYMFmdx55C+BrOPbck3tjfv36XQdY59LXx7yg0Q9U2OAQXldRbnhRB+5tg rok0yS3CUxaiJgM+mdkCO5mNmuB6Fv21b+QgHnvN+V9SvEkDRF8CgO0ukNnR848GK+eU 67BTvIDGoasE0sUDtn46XTILjgp0uhQ3i7X7akWOM7HzVu6VH+IufE82vlFMyDl5Pit1 sjpwoJKLW07Fe3BLltKCO/4HehGsZhmaFiTwPkhO9rVSP4B5NL4wdhX8n+3xBxZRVk7w o4bkLjEElSGmdyzoEPuDrvAEKeqRFgIhIdMT6r5AGNQlksZNOGPuTlxnvz0biRHGsRdh AtkQ== X-Forwarded-Encrypted: i=1; AJvYcCVPcjwQz8pcRKQOoaoahT1LIiFTTuuL5QlGLD5+c53VEAdEB483fVqQhVkk3EwSlAEWmKGhzUFRglVo62s=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7XrhpCLF+dF+jVEvPx+Cwpne5U05VDmQ/nlN7U3qiidws1/jO TWPbrD5/zRcD0wMOOnKqis4OSjETJnrunRbWmVt9itzJTDiveQNDP7La6v/h X-Gm-Gg: ASbGncurwVb7X2sEylRNGfcz+U+N/ITVJC77a53CHENssWWDsy0/0v7ru5F40rZWg8I 7kdcydzkDg2Jj1lz39B+u4VDMLEuIK9WD9b7h0Dz8f29v96JVu+kDXB6aPDT5V0PbOUbhqCjIUK Z2q6Jp/bHtxYD3hgKS4PCRK5aRXeHAVuxOIfbpFRAseWQ2QJF9sqYjxwjhI3wB7+xjlNZW7qG0m 4+b3/ofPN7AbsoiKBRZHkQvi7e5Kepluw7+ufqH2RoZesCubsYiyeFgJDtYndHXy8yXoqPDfgxf CLDPLTQZR+w67kz7lkrMDy2Ps43ylGsyWwusZzoW19Mtk53cwqprg/UA5IakwgYrsXzC1WcfsnX zQU2jAJAIIiE= X-Google-Smtp-Source: AGHT+IF7i/I3IdOLHAQ2T3n6rN/DkuQz7/uZDc2c33Jl4R9I8AWjlNgT7XTdUlU6shCJ7XEQ1alnEg== X-Received: by 2002:a17:90b:6d0:b0:2fe:b9be:216 with SMTP id 98e67ed59e1d1-30a3336ba48mr2266861a91.31.1745987275453; Tue, 29 Apr 2025 21:27:55 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a349e3c2csm566258a91.2.2025.04.29.21.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:54 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id CFEAFE94820; Wed, 30 Apr 2025 13:27:52 +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 v8 07/12] um: nommu: configure fs register on host syscall invocation Date: Wed, 30 Apr 2025 13:27:13 +0900 Message-ID: <3b21fc4fab514b550076b10e571a371dfee54a0d.1745980082.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" As userspace on UML/!MMU also need to configure %fs register when it is running to correctly access thread structure, host syscalls implemented in os-Linux drivers may be puzzled when they are called. Thus it has to configure %fs register via arch_prctl(SET_FS) on every host syscalls. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/shared/os.h | 6 +++ arch/um/os-Linux/process.c | 6 +++ arch/um/os-Linux/start_up.c | 20 +++++++++ arch/x86/um/nommu/do_syscall_64.c | 37 ++++++++++++++++ arch/x86/um/nommu/syscalls_64.c | 71 +++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+) diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 7f6703869dde..2e972ca55213 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -190,6 +190,7 @@ extern void check_host_supports_tls(int *supports_tls, = int *tls_min); extern void get_host_cpu_features( void (*flags_helper_func)(char *line), void (*cache_helper_func)(char *line)); +extern int host_has_fsgsbase; =20 /* mem.c */ extern int create_mem_file(unsigned long long len); @@ -213,6 +214,11 @@ extern int os_protect_memory(void *addr, unsigned long= len, extern int os_unmap_memory(void *addr, int len); extern int os_drop_memory(void *addr, int length); extern int can_drop_memory(void); +extern int os_arch_prctl(int pid, int option, unsigned long *arg); +#ifndef CONFIG_MMU +extern long long host_fs; +#endif + =20 void os_set_pdeathsig(void); =20 diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 3ac01881e905..7806b51e38b3 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -16,6 +16,7 @@ #include #include #include +#include /* For SYS_xxx definitions */ #include #include #include @@ -155,6 +156,11 @@ int __init can_drop_memory(void) return ok; } =20 +int os_arch_prctl(int pid, int option, unsigned long *arg2) +{ + return syscall(SYS_arch_prctl, option, arg2); +} + void init_new_thread_signals(void) { set_handler(SIGSEGV); diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index 93fc82c01aba..dbab091892b3 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -28,6 +30,8 @@ #include #include "internal.h" =20 +int host_has_fsgsbase; + static void ptrace_child(void) { int ret; @@ -278,6 +282,19 @@ void __init get_host_cpu_features( } } =20 +static void __init check_fsgsbase(void) +{ + unsigned long auxv =3D getauxval(AT_HWCAP2); + + os_info("Checking FSGSBASE instructions..."); + if (auxv & HWCAP2_FSGSBASE) { + host_has_fsgsbase =3D 1; + os_info("OK\n"); + } else { + host_has_fsgsbase =3D 0; + os_info("disabled\n"); + } +} =20 void __init os_early_checks(void) { @@ -293,6 +310,9 @@ void __init os_early_checks(void) */ check_tmpexec(); =20 + /* probe fsgsbase instruction */ + check_fsgsbase(); + pid =3D start_ptraced_child(); if (init_pid_registers(pid)) fatal("Failed to initialize default registers"); diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_sysca= ll_64.c index 5d0fa83e7fdc..796beb0089fc 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -2,10 +2,38 @@ =20 #include #include +#include +#include #include #include #include =20 +static int os_x86_arch_prctl(int pid, int option, unsigned long *arg2) +{ + if (!host_has_fsgsbase) + return os_arch_prctl(pid, option, arg2); + + switch (option) { + case ARCH_SET_FS: + wrfsbase(*arg2); + break; + case ARCH_SET_GS: + wrgsbase(*arg2); + break; + case ARCH_GET_FS: + *arg2 =3D rdfsbase(); + break; + case ARCH_GET_GS: + *arg2 =3D rdgsbase(); + break; + default: + pr_warn("%s: unsupported option: 0x%x", __func__, option); + break; + } + + return 0; +} + __visible void do_syscall_64(struct pt_regs *regs) { int syscall; @@ -17,6 +45,9 @@ __visible void do_syscall_64(struct pt_regs *regs) syscall, (unsigned long)current, (unsigned long)sys_call_table[syscall]); =20 + /* set fs register to the original host one */ + os_x86_arch_prctl(0, ARCH_SET_FS, (void *)host_fs); + if (likely(syscall < NR_syscalls)) { PT_REGS_SET_SYSCALL_RETURN(regs, EXECUTE_SYSCALL(syscall, regs)); @@ -34,4 +65,10 @@ __visible void do_syscall_64(struct pt_regs *regs) /* force do_signal() --> is_syscall() */ set_thread_flag(TIF_SIGPENDING); interrupt_end(); + + /* restore back fs register to userspace configured one */ + os_x86_arch_prctl(0, ARCH_SET_FS, + (void *)(current->thread.regs.regs.gp[FS_BASE + / sizeof(unsigned long)])); + } diff --git a/arch/x86/um/nommu/syscalls_64.c b/arch/x86/um/nommu/syscalls_6= 4.c index c78c442aed1d..5bb6d55b4bb5 100644 --- a/arch/x86/um/nommu/syscalls_64.c +++ b/arch/x86/um/nommu/syscalls_64.c @@ -13,8 +13,70 @@ #include /* XXX This should get the constants from libc */ #include #include +#include +#include #include "syscalls.h" =20 +/* + * The guest libc can change FS, which confuses the host libc. + * In fact, changing FS directly is not supported (check + * man arch_prctl). So, whenever we make a host syscall, + * we should be changing FS to the original FS (not the + * one set by the guest libc). This original FS is stored + * in host_fs. + */ +long long host_fs =3D -1; + +long arch_prctl(struct task_struct *task, int option, + unsigned long __user *arg2) +{ + long ret =3D -EINVAL; + unsigned long *ptr =3D arg2, tmp; + + switch (option) { + case ARCH_SET_FS: + if (host_fs =3D=3D -1) + os_arch_prctl(0, ARCH_GET_FS, (void *)&host_fs); + ret =3D 0; + break; + case ARCH_SET_GS: + ret =3D 0; + break; + case ARCH_GET_FS: + case ARCH_GET_GS: + ptr =3D &tmp; + break; + } + + ret =3D os_arch_prctl(0, option, ptr); + if (ret) + return ret; + + switch (option) { + case ARCH_SET_FS: + current->thread.regs.regs.gp[FS_BASE / sizeof(unsigned long)] =3D + (unsigned long) arg2; + break; + case ARCH_SET_GS: + current->thread.regs.regs.gp[GS_BASE / sizeof(unsigned long)] =3D + (unsigned long) arg2; + break; + case ARCH_GET_FS: + ret =3D put_user(current->thread.regs.regs.gp[FS_BASE / sizeof(unsigned = long)], arg2); + break; + case ARCH_GET_GS: + ret =3D put_user(current->thread.regs.regs.gp[GS_BASE / sizeof(unsigned = long)], arg2); + break; + } + + return ret; +} + +SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2) +{ + return arch_prctl(current, option, (unsigned long __user *) arg2); +} + void arch_switch_to(struct task_struct *to) { /* @@ -42,3 +104,12 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned lon= g, len, =20 return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); } + +static int __init um_nommu_setup_hostfs(void) +{ + /* initialize the host_fs value at boottime */ + os_arch_prctl(0, ARCH_GET_FS, (void *)&host_fs); + + return 0; +} +arch_initcall(um_nommu_setup_hostfs); --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 2F6361DE8A5 for ; Wed, 30 Apr 2025 04:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987281; cv=none; b=J6cdt2a05WNhtfwqotKCVMQTE9s67KNJ/H/D3VxuizxWOBmnJcQsY/dXt9SQrd7zL0A5O4gkEG02A18SVe/GgdCpeXBGcU1IEb7hWTHVzordh9y2nnxIMBcXpJi/PqQIoOuMIywpb+otREIVZrbs4PCZXd7qqIjhlt7+Zxw3TG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987281; c=relaxed/simple; bh=YUEZeH1TUt8vhd5nOMxaCkzJVaWiSM7ZZlNxkfxZqDc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YcAYPOvU/XW4Na8qrBG30yX7YTrsmmvUv7cI22Pb/5xfLcrpKn5XnEecrJfcOXyImPNZN2+E2KHi1GHPhX4Yy8/1mvuJcfx9qcIzIzZki2ZQUE4PrDU5tyfZCNVFiIuPLSBxwoafRh3oPYhXuQZS551BuOygw+SwAN+Y9dUmzfI= 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=hk5QfAJf; arc=none smtp.client-ip=209.85.215.173 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="hk5QfAJf" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-af908bb32fdso539654a12.1 for ; Tue, 29 Apr 2025 21:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987277; x=1746592077; 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=0G7VVQnGQtrb3sGnx5GNm2Y3zP47y1QHGJfHFp/BsUc=; b=hk5QfAJfwJDlCTf9KIVQWjWKRAPkbvLDvdT/CUoxpOOkZ5cBViAZTjDozxRvY7ahQI iN8ZqJh3coyStUmzBZo9yhI+OztBGKaKNf7Ymzcelk+aMtPFPRt1mQ4kEZ8TZ6OHmBsu +s6RuHGXalvMjCJgOZ0Tsb4fVFSwtxar67L66nDXwGBZrWux0zOtHJHzuTiy1xxkr9wV aTlZtkB/8vo7MKSX+4Hv4BxinU4AB5Mik6vjvUjGxKDjA5tKZWH18grInK7Ghhms15a2 FK3sxsN/RjOuOJLJtJItHUJRaYK6DuE6N7iOV5R8Xd0RUJkghFryq8uhcOidx0kG4bxC MV/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987277; x=1746592077; 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=0G7VVQnGQtrb3sGnx5GNm2Y3zP47y1QHGJfHFp/BsUc=; b=wpeHU/fUo6wJYicYVA647T5LihDwnItWPpFDWjEkO/2MEZbBqvXa8D7wZC38dmjE4P cP5seThi2XUPk8z5bYrcuqefg1AgLzzIrSNRy4B4DvROOMlcLWZ/O/dYVJnWc5SZqR9c JabQVs+y3CAhgxt+9ho9iC33b6oIMzjM5sn1MyKU7gSKWAUmB430BDiTaXLbmkE9jHkH Lo23PDfKgE4hLw+HkF77nxEtPsUPlgbb587gi68M4+tXlx97oTYgJq1tOZn9PH45cP/f 0/esBoCqBqkzWGf5mb2K/pV34W0ONZyPsoZCoFcK6DxH6j5IuS2kPC2ObgOHi0ATU5+a mYkw== X-Forwarded-Encrypted: i=1; AJvYcCVhmW01GQfA6BoOpgPdy5kKHrf2Q+aiFL5NDXOlopIdRDvF9RrmV33fkHrgSlpMCy0iCLmSEeWA/qbDAEc=@vger.kernel.org X-Gm-Message-State: AOJu0YwSXCnI3srlm7JhgWI9hFP3EZgHXM1sKSlCmu4rLfhljN3HgFtQ 4Lg+M8LmAYKZb6EriVBg+/NydXpy5pR7ozrRlbVs59AKz8ApX/PjS1VdqFee X-Gm-Gg: ASbGncsV8P7pxTYPatjLLr2lK7/7h78TXk12y/6CeOyMq8FbTYZX9meAPk+iKhaB/kP DelK4xpBS+uxWsjeX3jzAsJq57u6p1oJyj7izKuMdVwET1BRq3sp4YaysMM9S17mhz41HkQk/gM lQgg/3Cy8/wisNOpjACG9QyONkri4ug22m6SHeEKPBG+bWcRimnMGRDDHLhU6SXpdtEEqCCPyz2 Lq1BAiudDnqaVTUtV/9p3QanGP7UaYLs6rHUJoPbRM+8w8NvubB4DmsZbXfjFH/sVxWs+DcvFcF i5V7uh6QALmLA0iQn3RpyU6tDErVC+5NFqfJLx5dMUkzO8v/24ZaCIurfKXCqkMPkhEd34YlMQv +WttDqCgNyEo= X-Google-Smtp-Source: AGHT+IECA9Apxbc6D2JhVwEUhYdUmhJiBYci0GxbrvHA3yJvjLnYDlridKGWIXBUNgsmhrFM8ye3SQ== X-Received: by 2002:a05:6a20:6f0a:b0:1e1:a449:ff71 with SMTP id adf61e73a8af0-20a8e173f9cmr2155932637.1.1745987277300; Tue, 29 Apr 2025 21:27:57 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74039a5bde6sm609398b3a.127.2025.04.29.21.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:56 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 52572E94822; Wed, 30 Apr 2025 13:27:55 +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 v8 08/12] x86/um/vdso: nommu: vdso memory update Date: Wed, 30 Apr 2025 13:27:14 +0900 Message-ID: <1670b88c2196a5fb2a6eed90c7a8714f03c040a7.1745980082.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" On !MMU mode, the address of vdso is accessible from userspace. This commit implements the entry point by pointing a block of page address. This commit also add memory permission configuration of vdso page to be executable. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/x86/um/vdso/vma.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/x86/um/vdso/vma.c b/arch/x86/um/vdso/vma.c index dc8dfb2abd80..1c8c39f87681 100644 --- a/arch/x86/um/vdso/vma.c +++ b/arch/x86/um/vdso/vma.c @@ -9,6 +9,7 @@ #include #include #include +#include =20 static unsigned int __read_mostly vdso_enabled =3D 1; unsigned long um_vdso_addr; @@ -21,14 +22,24 @@ static int __init init_vdso(void) { BUG_ON(vdso_end - vdso_start > PAGE_SIZE); =20 - um_vdso_addr =3D task_size - PAGE_SIZE; - um_vdso =3D alloc_page(GFP_KERNEL); if (!um_vdso) goto oom; =20 copy_page(page_address(um_vdso), vdso_start); =20 +#ifdef CONFIG_MMU + um_vdso_addr =3D task_size - PAGE_SIZE; +#else + /* this is fine with NOMMU as everything is accessible */ + um_vdso_addr =3D (unsigned long)page_address(um_vdso); + os_protect_memory((void *)um_vdso_addr, vdso_end - vdso_start, 1, 0, 1); +#endif + + pr_info("vdso_start=3D%lx um_vdso_addr=3D%lx pg_um_vdso=3D%lx", + (unsigned long)vdso_start, um_vdso_addr, + (unsigned long)page_address(um_vdso)); + return 0; =20 oom: @@ -39,6 +50,7 @@ static int __init init_vdso(void) } subsys_initcall(init_vdso); =20 +#ifdef CONFIG_MMU int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) { struct vm_area_struct *vma; @@ -63,3 +75,4 @@ int arch_setup_additional_pages(struct linux_binprm *bprm= , int uses_interp) =20 return IS_ERR(vma) ? PTR_ERR(vma) : 0; } +#endif --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 EB25F1DED63 for ; Wed, 30 Apr 2025 04:28:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987282; cv=none; b=oUyaR7rspZ8imQ+w8/Ig0DG85F0pPQFdLtGqO5+7fWAzVHMNkjQKPP/+ZuLECqd24jDxp1e/+5LD3TNY5Mbtomh85qsVvbCMO2iu9vb6Qt2/gOypHvDghYJP5d0pMPkdpJW3CxsGcLcd05pJ/DJKay34ddjMxiYzN5M50qH9aHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987282; c=relaxed/simple; bh=tvWwcvdelH2ZCwaXkDs3RnjvaPgYvNWnZZNy0rariak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ou9CzPegc3vKpt0MlpzFA9pjFsRnrnwgxlvXeuLRr3SI58vk1v9R62Xngvsum08bfexGNRrSewBEQYvwLYRZlqWsax64UITTQnNEbtyLOujuEBvDq0QUEyVMTnE3EhEWNk3jI2IgWsus/wFpaphkMyB0RM08uqO8JybHg2sEkHw= 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=akLGP+LQ; arc=none smtp.client-ip=209.85.210.174 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="akLGP+LQ" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-73972a54919so5776414b3a.3 for ; Tue, 29 Apr 2025 21:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987280; x=1746592080; 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=mp6eKKbWpiSHyJXYBVOlGqFhgugHf5gGjyOnElsYIQ8=; b=akLGP+LQ0exlj7HT2y9S7bN69kEpqDizlIjo5yrJAm9Sf7aPBD+bTpFpfxSsjcT9hQ DSkBcgcZ1dTAyUnVXAkdLyBCVwagO6Qlv7QKU6LVE6wlEZZ+mSfQEcFJPbyjdHn21vEK W17H/MVPW6nmKKFbg1cViw6junG6fz27P84W3bPeNblwkockf+zTfos+zzocTyGqQfOB 0ZcKGqb0KXPNYQPfn63j1MwLQQdLUjQreX6nQH90AH5oC39M0oHC/gsup6rP3VFW9aoR wYicSczv3RIzUrx+srXk4lTu3R+cl4W14ueHRlYthAFaMO/W37iF9XkjrxFfWNkEGosE j25g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987280; x=1746592080; 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=mp6eKKbWpiSHyJXYBVOlGqFhgugHf5gGjyOnElsYIQ8=; b=tTeKxO9JUW1QRuW6TXotQUkFZhmdtM/ZlSLj04LkSod7OOfvTW91lJcB4N8AOAT6qR ea9FaKYRsGvl56BnJAR4fXoWyYur+LZEKdvayCmYrhoyekjyKQ6LeFBlFD9mY3pxLpaq HCMOrQH1On3O2PIn/UfwjtNNzvQOQE4z7Ur6ChcrWB6YCLQHcpr31QDY26weTX8GcOEu UAOypX/tvMy1LKEPgFyhtJxSJbHlAaHqzgUXMxd4ZV5+X3JbQdvDrEZZN98zW10hSXih RVyrRw5xI0YnDgIMd2vEpk2FmORUJHeOw6tgOwCbBXmt9G7EfWz1cuHqIg/gX+O8g+Ro +3tQ== X-Forwarded-Encrypted: i=1; AJvYcCXHWh9DrH4oheuY74iXTBxk7LdY1XcbjuLNkw2CE2NE/aIUa2ANxDP5nXLdn5ytsFKSCSGCYJSKyc+0Ewo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8M/yW54Av6A7xKOWKuYwXfBeW7nPxRBYEKGMPXoWD8/AaA6lF SCkHk9vYmkcI6iPtDARU55OqYu8cZwGMIODiTyEhrB3BuMiKQEUB X-Gm-Gg: ASbGnctm9Ejj881J8L0XleBqEYYJLmsWGTTbVJakd3NaX0nXBvVVejlfDiNwTsRH5Rs 9qjLE2oiX55ZYanSs3g9+6a8uyuUQ/EjrkLYW2zyd+BOyTYvOuj8A/7Mx/aqsSMSAeGvBvwLc/F NZ4Pq5NLAPJmLkwYX/YargVoSrrmwTmHY74XFuk4fmTD0hTkTTNYphRsRiTizpbNPncuFIjPRbx uRaN/6hqO1fB/sjRyhxb5so+uLUvWSpKBdmLiOqcrWc35+DT0huO6Mo0mI6vLgwX5w1Ru5gz0TG JoZyQ6ZwYZSLR2w+pVGljmN/U8LhE3E786AXMh4rX1n9se2yj6NeA8yPbdRGJp1g0QUGfzcijtx cTBb5dG1IAAQ= X-Google-Smtp-Source: AGHT+IFs9TraF1kR6FW5u1Q5u6Tmlb0LDMb+CsM3q0Udn9dfC/0UdzNr3zkLiVA4e0ssPjXNHc5cNA== X-Received: by 2002:a05:6a20:d046:b0:1f5:8220:7452 with SMTP id adf61e73a8af0-20a87d4eb30mr2154035637.24.1745987280011; Tue, 29 Apr 2025 21:28:00 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b1b7efab4a5sm6348034a12.19.2025.04.29.21.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:59 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 98529E94824; Wed, 30 Apr 2025 13:27:57 +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 v8 09/12] x86/um: nommu: signal handling Date: Wed, 30 Apr 2025 13:27:15 +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 commit updates the behavior of signal handling under !MMU environment. It adds the alignment code for signal frame as the frame is used in userspace as-is. floating point register is carefully handling upon entry/leave of syscall routine so that signal handlers can read/write the contents of the register. It also adds the follow up routine for SIGSEGV as a signal delivery runs in the same stack frame while we have to avoid endless SIGSEGV. Signed-off-by: Hajime Tazaki --- arch/um/include/shared/kern_util.h | 4 + arch/um/nommu/Makefile | 2 +- arch/um/nommu/os-Linux/signal.c | 13 ++ arch/um/nommu/trap.c | 194 ++++++++++++++++++++++++++ arch/x86/um/nommu/do_syscall_64.c | 6 + arch/x86/um/nommu/os-Linux/mcontext.c | 11 ++ arch/x86/um/shared/sysdep/mcontext.h | 1 + arch/x86/um/shared/sysdep/ptrace.h | 2 +- 8 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 arch/um/nommu/trap.c diff --git a/arch/um/include/shared/kern_util.h b/arch/um/include/shared/ke= rn_util.h index 2c8c18bd5860..85a4f154423b 100644 --- a/arch/um/include/shared/kern_util.h +++ b/arch/um/include/shared/kern_util.h @@ -73,4 +73,8 @@ void um_idle_sleep(void); =20 void kasan_map_memory(void *start, size_t len); =20 +#ifndef CONFIG_MMU +extern void arch_sigsegv_handler(int sig, struct siginfo *si, void *mc); +#endif + #endif diff --git a/arch/um/nommu/Makefile b/arch/um/nommu/Makefile index baab7c2f57c2..096221590cfd 100644 --- a/arch/um/nommu/Makefile +++ b/arch/um/nommu/Makefile @@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 =20 -obj-y :=3D os-Linux/ +obj-y :=3D trap.o os-Linux/ diff --git a/arch/um/nommu/os-Linux/signal.c b/arch/um/nommu/os-Linux/signa= l.c index 19043b9652e2..b2cd0470b67c 100644 --- a/arch/um/nommu/os-Linux/signal.c +++ b/arch/um/nommu/os-Linux/signal.c @@ -5,6 +5,7 @@ #include #include #include +#include =20 void sigsys_handler(int sig, struct siginfo *si, struct uml_pt_regs *regs, void *ptr) @@ -14,3 +15,15 @@ void sigsys_handler(int sig, struct siginfo *si, /* hook syscall via SIGSYS */ set_mc_sigsys_hook(mc); } + +void arch_sigsegv_handler(int sig, struct siginfo *si, void *ptr) +{ + mcontext_t *mc =3D (mcontext_t *) ptr; + + /* !MMU specific part; detection of userspace */ + if (mc->gregs[REG_RIP] > uml_reserved && + mc->gregs[REG_RIP] < high_physmem) { + /* !MMU: force handle signals after rt_sigreturn() */ + set_mc_userspace_relay_signal(mc); + } +} diff --git a/arch/um/nommu/trap.c b/arch/um/nommu/trap.c new file mode 100644 index 000000000000..2053a3b5071b --- /dev/null +++ b/arch/um/nommu/trap.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Note this is constrained to return 0, -EFAULT, -EACCES, -ENOMEM by + * segv(). + */ +int handle_page_fault(unsigned long address, unsigned long ip, + int is_write, int is_user, int *code_out) +{ + /* !MMU has no pagefault */ + return -EFAULT; +} + +static void show_segv_info(struct uml_pt_regs *regs) +{ + struct task_struct *tsk =3D current; + struct faultinfo *fi =3D UPT_FAULTINFO(regs); + + if (!unhandled_signal(tsk, SIGSEGV)) + return; + + pr_warn_ratelimited("%s%s[%d]: segfault at %lx ip %p sp %p error %x", + task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG, + tsk->comm, task_pid_nr(tsk), FAULT_ADDRESS(*fi), + (void *)UPT_IP(regs), (void *)UPT_SP(regs), + fi->error_code); +} + +static void bad_segv(struct faultinfo fi, unsigned long ip) +{ + current->thread.arch.faultinfo =3D fi; + force_sig_fault(SIGSEGV, SEGV_ACCERR, (void __user *) FAULT_ADDRESS(fi)); +} + +void fatal_sigsegv(void) +{ + force_fatal_sig(SIGSEGV); + do_signal(¤t->thread.regs); + /* + * This is to tell gcc that we're not returning - do_signal + * can, in general, return, but in this case, it's not, since + * we just got a fatal SIGSEGV queued. + */ + os_dump_core(); +} + +/** + * segv_handler() - the SIGSEGV handler + * @sig: the signal number + * @unused_si: the signal info struct; unused in this handler + * @regs: the ptrace register information + * + * The handler first extracts the faultinfo from the UML ptrace regs struc= t. + * If the userfault did not happen in an UML userspace process, bad_segv i= s called. + * Otherwise the signal did happen in a cloned userspace process, handle i= t. + */ +void segv_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *= regs, + void *mc) +{ + struct faultinfo *fi =3D UPT_FAULTINFO(regs); + + /* !MMU specific part; detection of userspace */ + /* mark is_user=3D1 when the IP is from userspace code. */ + if (UPT_IP(regs) > uml_reserved && UPT_IP(regs) < high_physmem) + regs->is_user =3D 1; + + if (UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)) { + show_segv_info(regs); + bad_segv(*fi, UPT_IP(regs)); + return; + } + segv(*fi, UPT_IP(regs), UPT_IS_USER(regs), regs, mc); + + /* !MMU specific part; detection of userspace */ + arch_sigsegv_handler(sig, unused_si, mc); +} + +/* + * We give a *copy* of the faultinfo in the regs to segv. + * This must be done, since nesting SEGVs could overwrite + * the info in the regs. A pointer to the info then would + * give us bad data! + */ +unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, + struct uml_pt_regs *regs, void *mc) +{ + int si_code; + int err; + int is_write =3D FAULT_WRITE(fi); + unsigned long address =3D FAULT_ADDRESS(fi); + + if (!is_user && regs) + current->thread.segv_regs =3D container_of(regs, struct pt_regs, regs); + + if (current->mm =3D=3D NULL) { + show_regs(container_of(regs, struct pt_regs, regs)); + panic("Segfault with no mm"); + } else if (!is_user && address > PAGE_SIZE && address < TASK_SIZE) { + show_regs(container_of(regs, struct pt_regs, regs)); + panic("Kernel tried to access user memory at addr 0x%lx, ip 0x%lx", + address, ip); + } + + if (SEGV_IS_FIXABLE(&fi)) + err =3D handle_page_fault(address, ip, is_write, is_user, + &si_code); + else { + err =3D -EFAULT; + /* + * A thread accessed NULL, we get a fault, but CR2 is invalid. + * This code is used in __do_copy_from_user() of TT mode. + * XXX tt mode is gone, so maybe this isn't needed any more + */ + address =3D 0; + } + + if (!err) + goto out; + else if (!is_user && arch_fixup(ip, regs)) + goto out; + + if (!is_user) { + show_regs(container_of(regs, struct pt_regs, regs)); + panic("Kernel mode fault at addr 0x%lx, ip 0x%lx", + address, ip); + } + + show_segv_info(regs); + + if (err =3D=3D -EACCES) { + current->thread.arch.faultinfo =3D fi; + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address); + } else { + WARN_ON_ONCE(err !=3D -EFAULT); + current->thread.arch.faultinfo =3D fi; + force_sig_fault(SIGSEGV, si_code, (void __user *) address); + } + +out: + if (regs) + current->thread.segv_regs =3D NULL; + + return 0; +} + +void relay_signal(int sig, struct siginfo *si, struct uml_pt_regs *regs, + void *mc) +{ + int code, err; + + if (!UPT_IS_USER(regs)) { + if (sig =3D=3D SIGBUS) + pr_err("Bus error - the host /dev/shm or /tmp mount likely just ran out= of space\n"); + panic("Kernel mode signal %d", sig); + } + + arch_examine_signal(sig, regs); + + /* Is the signal layout for the signal known? + * Signal data must be scrubbed to prevent information leaks. + */ + code =3D si->si_code; + err =3D si->si_errno; + if ((err =3D=3D 0) && (siginfo_layout(sig, code) =3D=3D SIL_FAULT)) { + struct faultinfo *fi =3D UPT_FAULTINFO(regs); + + current->thread.arch.faultinfo =3D *fi; + force_sig_fault(sig, code, (void __user *)FAULT_ADDRESS(*fi)); + } else { + pr_err("Attempted to relay unknown signal %d (si_code =3D %d) with errno= %d\n", + sig, code, err); + force_sig(sig); + } +} + +void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs, + void *mc) +{ + do_IRQ(WINCH_IRQ, regs); +} diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_sysca= ll_64.c index 796beb0089fc..48b3d29e2db1 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -48,6 +48,9 @@ __visible void do_syscall_64(struct pt_regs *regs) /* set fs register to the original host one */ os_x86_arch_prctl(0, ARCH_SET_FS, (void *)host_fs); =20 + /* save fp registers */ + asm volatile("fxsaveq %0" : "=3Dm"(*(struct _xstate *)regs->regs.fp)); + if (likely(syscall < NR_syscalls)) { PT_REGS_SET_SYSCALL_RETURN(regs, EXECUTE_SYSCALL(syscall, regs)); @@ -66,6 +69,9 @@ __visible void do_syscall_64(struct pt_regs *regs) set_thread_flag(TIF_SIGPENDING); interrupt_end(); =20 + /* restore fp registers */ + asm volatile("fxrstorq %0" : : "m"((current->thread.regs.regs.fp))); + /* restore back fs register to userspace configured one */ os_x86_arch_prctl(0, ARCH_SET_FS, (void *)(current->thread.regs.regs.gp[FS_BASE diff --git a/arch/x86/um/nommu/os-Linux/mcontext.c b/arch/x86/um/nommu/os-L= inux/mcontext.c index c4ef877d5ea0..955e7d9f4765 100644 --- a/arch/x86/um/nommu/os-Linux/mcontext.c +++ b/arch/x86/um/nommu/os-Linux/mcontext.c @@ -6,6 +6,17 @@ #include #include =20 +static void __userspace_relay_signal(void) +{ + /* XXX: dummy syscall */ + __asm__ volatile("call *%0" : : "r"(__kernel_vsyscall), "a"(39) :); +} + +void set_mc_userspace_relay_signal(mcontext_t *mc) +{ + mc->gregs[REG_RIP] =3D (unsigned long) __userspace_relay_signal; +} + void set_mc_sigsys_hook(mcontext_t *mc) { mc->gregs[REG_RCX] =3D mc->gregs[REG_RIP]; diff --git a/arch/x86/um/shared/sysdep/mcontext.h b/arch/x86/um/shared/sysd= ep/mcontext.h index 15e9ff287021..0efe5ddf95af 100644 --- a/arch/x86/um/shared/sysdep/mcontext.h +++ b/arch/x86/um/shared/sysdep/mcontext.h @@ -9,6 +9,7 @@ extern void get_regs_from_mc(struct uml_pt_regs *, mcontext_t *); #ifndef CONFIG_MMU extern void set_mc_sigsys_hook(mcontext_t *mc); +extern void set_mc_userspace_relay_signal(mcontext_t *mc); #endif =20 #ifdef __i386__ diff --git a/arch/x86/um/shared/sysdep/ptrace.h b/arch/x86/um/shared/sysdep= /ptrace.h index 8f7476ff6e95..7d553d9f05be 100644 --- a/arch/x86/um/shared/sysdep/ptrace.h +++ b/arch/x86/um/shared/sysdep/ptrace.h @@ -65,7 +65,7 @@ struct uml_pt_regs { int is_user; =20 /* Dynamically sized FP registers (holds an XSTATE) */ - unsigned long fp[]; + unsigned long fp[] __attribute__((aligned(16))); }; =20 #define EMPTY_UML_PT_REGS { } --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 C5D311E570B for ; Wed, 30 Apr 2025 04:28:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987285; cv=none; b=e1S3DiE9fa94QkwEmb3Nq9Et9b+/oXtfxP0vMD4I6BhHAOtb9FXYWKtaXIMiXdj31kSeanMrMqAw1RfIELDGEUdBuEOJUGlTNK0lCybmeY0yeikwyq4RkXyUty8emLgP2FEa+53Et8joQg0Av7hff0mRzgyWADvz24ymrqxxhQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987285; c=relaxed/simple; bh=wSkPm5yBeW+wrBDAjRTe5/DIUE2FvkpgHBkUEbYzM04=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t09/YNAEI99OIJh2IRflYIG2NCCb9fJgqhVjIB10f6jpp7ZCX1OzWCr4OnaAhO21E0HfC4ltx8dfuMTUpbHPtLqYsCD5ftstOX9l3UNt+AkHiyQKwavw0dfKsrqylNcNR66zQi5jRkFpq5Iq87M/BCdxzw+sx9jTxFdypMTdYck= 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=SQMp708r; arc=none smtp.client-ip=209.85.214.172 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="SQMp708r" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-227d6b530d8so75754785ad.3 for ; Tue, 29 Apr 2025 21:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987283; x=1746592083; 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=B/ZhA8POgOa1pDP88Eiedzl7Qg41tN4Rus19EAaNMog=; b=SQMp708rvwPa3n4JpHgRPPe3RYFVYYE3ysUUuHewqVDyo4Y3HgNf2ws/mTQk3Tcf84 woRLVnJ7HCfjn3ltKCb+Xyk/a2LJR/tVaExSFLsiYD+oMmJFQIXJnjAcWYZ4GIjrcVTR 5QSY17zBiDjI5obWhOyEOwt7jRLrqVvVZvZhN7kKEnvmmqwPIGjKr0lQviQXnTwtpJ6i c+kEfcfg7PZcAyQAXkvFp9c+a6oX21ID2kjFm/TgwGJNKdurTj8ABp3RKRajIrN/7XfD aQMv5+WeatsLZkn5CkGaKpC/xGIcN8slcDyRZ+pBZzuhiqT3X+w9Y94c5NPfBYueggG5 XWGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987283; x=1746592083; 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=B/ZhA8POgOa1pDP88Eiedzl7Qg41tN4Rus19EAaNMog=; b=lJH8RF2jUPJM7sMG+ktB8bxiDUepXL30ndnS3r3MXnlSFPHNq81yQWOmNtTZBKUTNe rXvVAVvc2f9/j5U6GrNktAyDyUEU9fIUuqnPVecZSgV0fmMQdTI7BzNiOTM8Zl9jsGNj jIBEoSABDiTvDwsTBQ8b3TBNhd0fwi1TUma6/zKeKvtuD1uX/BqiLooUS9R1fLM0m5TL 1j7igzQjZB95hwMuM9a4Ia1iAcDMQAGKPv2hW8s1og4KWebcGAseevQ45KURSBAJS5mW qga0f1xECLlsxwcvQ+/q48I/bnd0qwOQY6gHax3r6zAfwZN+B+GVGj/wO1PZU0wvEM6y OXVA== X-Forwarded-Encrypted: i=1; AJvYcCVQKHbMWSUnjMA1B4KCATqwj5+aFq6HdpzZo4Di31Kz3iMjgdjSLllZfUIlysURN/jNsiA/hTctxCm4vUg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/ZBlKT3N54nbvcDoXpBS3i/hjCXPam6MYD2OdDmGdpF42dt4I gkp+WBVsXMvcAhV0LsvXP3ARL1ye9dnUYTX2jKLL52yXGD+UXorC X-Gm-Gg: ASbGncvNZLb8sQOcUbJi7tehJk65m3dLveakOlnvRN68EHFogLp4Yi+nUXY0JKNIaiI FtCIU0n2AbAYP/JtmDOb9R8t/zxOwTdc8KSg68LAYxCjkp/pmCyr/iobT8VPilqW5pjYkkTUr15 c+31oWU+j0lYz4wsOGHnJaR7+BWua0DsovuE1V2EWxuzCDCPAIjVt6JsGwrRhTK1ABjZxsKIcy2 hupMwXxzlI8x/n+qGq1AWNEW0LW5tL0mKWnRNIUcHwmU2pGfjCJ4vWWXImIQm3sfSLe/8SghtwV yHCZNZToJSQPB4Uqf0YiSYgYZdl5aQMZjvLtM8RaqY/r6WZKaY28QaUS+MljdIF5zdx7wsr5N6S RmQrKIDaqHocT263wYAFLMw== X-Google-Smtp-Source: AGHT+IHLnJV1jRxDa8YUV/nZ0brQ2Gx6YopooEOeWXq2tdOwSnZ7t3052ntTYHbm7mId/W8e0+yiSA== X-Received: by 2002:a17:902:d58b:b0:224:26fd:82e5 with SMTP id d9443c01a7336-22df35caa68mr29021325ad.48.1745987282966; Tue, 29 Apr 2025 21:28:02 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db51062casm111526675ad.208.2025.04.29.21.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:28:02 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 33EA2E94826; Wed, 30 Apr 2025 13:28:00 +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 v8 10/12] um: change machine name for uname output Date: Wed, 30 Apr 2025 13:27:16 +0900 Message-ID: <64d60cf0ac06f49a4ff7f79df4c60e364d11464f.1745980082.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 commit tries to display MMU/!MMU mode from the output of uname(2) so that users can distinguish which mode of UML is running right now. Signed-off-by: Hajime Tazaki --- arch/um/Makefile | 6 ++++++ arch/um/os-Linux/util.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/um/Makefile b/arch/um/Makefile index fcf4bb915a31..722a3bd03f24 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -155,6 +155,12 @@ export CFLAGS_vmlinux :=3D $(LINK-y) $(LINK_WRAPS) $(L= D_FLAGS_CMDLINE) $(CC_FLAGS_ CLEAN_FILES +=3D linux x.i gmon.out MRPROPER_FILES +=3D $(HOST_DIR)/include/generated =20 +ifeq ($(CONFIG_MMU),y) +UTS_MACHINE :=3D "um" +else +UTS_MACHINE :=3D "um\(nommu\)" +endif + archclean: @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \ -o -name '*.gcov' \) -type f -print | xargs rm -f diff --git a/arch/um/os-Linux/util.c b/arch/um/os-Linux/util.c index 4193e04d7e4a..20421e9f0f77 100644 --- a/arch/um/os-Linux/util.c +++ b/arch/um/os-Linux/util.c @@ -65,7 +65,8 @@ void setup_machinename(char *machine_out) } # endif #endif - strcpy(machine_out, host.machine); + strcat(machine_out, "/"); + strcat(machine_out, host.machine); } =20 void setup_hostinfo(char *buf, int len) --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 0F7B31E5B90 for ; Wed, 30 Apr 2025 04:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987287; cv=none; b=h498WGSPm0QSyxLv7WxWn6uUWqROQ8pPZtk/9p0uw0ks23wGfIdSgQvNfCjREHj1y/z0MveMwji+Qhf6Lq30lyq3DqWC9v7dMIXl27q6dYnRtF9Q67+x+Mt+VKurqLmArGti7V5rbdnVYoqJh4wlkgLXWHGFOIqRrHexHZnQ+p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987287; c=relaxed/simple; bh=beQjAzIY4tbRs0TEUdmxjkrngcffOTKEdMuKtlPYk+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dj+c4RbGdsG0QCWmTutnLbSZFo99oS6ioDCtfXD/nGPTJbCFb/Iq5kXHGgjS2HVMO6jIXkRz7azrmMt5Proilx/GbItk7Zt2X6wXa9QCnpmanvBW+r6bfvFgCobidWI7RUYXEJyz+YMHcIogJKmhXMgQgxv/sdFF9D/kcT4qFyk= 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=V4d6/OYF; arc=none smtp.client-ip=209.85.210.180 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="V4d6/OYF" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-73712952e1cso7192555b3a.1 for ; Tue, 29 Apr 2025 21:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987285; x=1746592085; 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=hHaVuq4Zwe9gLJutKzuA+VGXPhun5t5NN63IcV8lR68=; b=V4d6/OYFo9bvk4TUTx5oU8Cl4Vcx3fAdVAM6Mtomk/ctThNDLrG+M926EcJ0QR5AVO 0ovG3x2xBtbERnYo9ZHX8pOZdOb7zzfawwwaXfLses6URlkSXqKXn9EeK6bFiD66LNCC LOegteog3JM7ub+xh7zJshJsOIMSkMWvAi8ofeCbY3I43S56KQfjRDCuXDp06ltDQQ++ 9fMBpusBA56ssbL8BC5z8k6WScRvrYJFVr5BBumF01kuLWbuALP9TupnbvokGTOL5wlN 8TpLK60VhwdbqL4KQWmTJgHeHgNfUWsvaY/uazV5mvqRjsHxW+XM6GYjTaw8hxlJ4Rnn m7bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987285; x=1746592085; 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=hHaVuq4Zwe9gLJutKzuA+VGXPhun5t5NN63IcV8lR68=; b=Ayy+bpBWB0ncUXhNxn6u+6t23zUAqH/HDrLpO90kbFIpMzzxwqhvJRkj2lu7QnvMw9 TwxHq9NLA58LWTI6Z0SFub0L4kdTeH0Jcg/Yx/Ek89SeEgTxzRHA3VMy9iKwJUKOuyLK r2R/ogSHRM1KoGd4FbAI8jEo0lpWKjr8PvPz37gx6xlqXurEyMLohu4qckLf4zxIXt9O Tmu8Uc2I0aXHUxL8eeTjdTIeZRoQMsajK4LQydannx5RUczDXk3+TcBFGIjBaCGdh6E3 DaN0oeWgKtZsGvJFKcZcORDAXqUy5VjGQl80D9u0DMO5QN9g6pMp90TiEMI7L/kG6nYq Dihw== X-Forwarded-Encrypted: i=1; AJvYcCUI2jgtwuhvmsxQkt21WD1qisa8Au1Yva8HJAfJNpxH+HDfaYdkctMHd7mb9XonRNMqiNKM7ofbiggKdR0=@vger.kernel.org X-Gm-Message-State: AOJu0YywDbDVKL9wMoQBvuoiX13yrSjv9khKWiO93NA5+lIcUUG90iI7 saND+P9iIvHc1O7LUpqz6b1KNrF8k6RE81d1zC0a0g+X7PeoxHwG X-Gm-Gg: ASbGncsoAwyA2GsMnvTOUmI94P4jXhtmpja0hSJ7tpho0j1k/QsjjBZszNCd/14ps1Y rkF8GBZI8fcpzk+4DBdB/aQO6EwHKPJ+FwSjzLFpgE5pe5pTzHN75lQqAc2tmYC539snvxjgQXi C8LcMMxFTibXOvAeTIcdixoWgFE9FVG2iG19Uc5wi4tXrPLKMTyt2LGAcldvyMpbjU8d47nia8f 0HHkkwSh7m8d50vW5kthHXmDqrROZqK9riD6AD7ad+FTrcUZJ11Uq3m3KyUONMp0SwiATig2fyG Wkmo2lWBIIRIW/ZAYVYFoqeW1Om4JLhyc4a+rX/EdunrUdDniFUUUDGh5yGRTf0VVR5y2U9TTuY kOtVPKZj0W4U= X-Google-Smtp-Source: AGHT+IFcLglsLp35fpVY5aAm/RiBDEo8ho6SSo1+56LkhDY+q9Ov9DaIySaSK81WgYdSZ4+KxLTB2A== X-Received: by 2002:a05:6a00:22d4:b0:736:8c0f:7758 with SMTP id d2e1a72fcca58-7403a784350mr1721050b3a.10.1745987285190; Tue, 29 Apr 2025 21:28:05 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-740399230e6sm648218b3a.68.2025.04.29.21.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:28:04 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 798A2E94828; Wed, 30 Apr 2025 13:28:02 +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 v8 11/12] um: nommu: add documentation of nommu UML Date: Wed, 30 Apr 2025 13:27:17 +0900 Message-ID: <254209f7e93f7fcdbc16853cad9f0a0ab34c8032.1745980082.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 commit adds an initial documentation for !MMU mode of UML. Signed-off-by: Hajime Tazaki --- Documentation/virt/uml/nommu-uml.rst | 177 +++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 178 insertions(+) create mode 100644 Documentation/virt/uml/nommu-uml.rst diff --git a/Documentation/virt/uml/nommu-uml.rst b/Documentation/virt/uml/= nommu-uml.rst new file mode 100644 index 000000000000..2034ba4d397a --- /dev/null +++ b/Documentation/virt/uml/nommu-uml.rst @@ -0,0 +1,177 @@ +.. SPDX-License-Identifier: GPL-2.0 + +UML has been built with CONFIG_MMU since day 0. The patchset +introduces the nommu mode on UML in a different angle from what Linux +Kernel Library tried. + +.. contents:: :local: + +What is it for ? +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +- Alleviate syscall hook overhead implemented with ptrace(2) +- To exercises nommu code over UML (and over KUnit) +- Less dependency to host facilities + + +How it works ? +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +To illustrate how this feature works, the below shows how syscalls are +called under nommu/UML environment. + +- boot kernel, install seccomp filter if ``syscall`` instructions are + called from userspace memory based on the address of instruction + pointer +- (userspace starts) +- calls ``vfork``/``execve`` syscalls +- ``SIGSYS`` signal raised, handler calls syscall entry point ``__kernel_v= syscall`` +- call handler function in ``sys_call_table[]`` and follow how UML syscall + works. +- return to userspace + + +What are the differences from MMU-full UML ? +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The current nommu implementation adds 3 different functions which +MMU-full UML doesn't have: + +- kernel address space can directly be accessible from userspace + - so, ``uaccess()`` always returns 1 + - generic implementation of memcpy/strcpy/futex is also used +- alternate syscall entrypoint without ptrace +- alternate syscall hook + - hook syscall by seccomp filter + +With those modifications, it allows us to use unmodified userspace +binaries with nommu UML. + + +History +=3D=3D=3D=3D=3D=3D=3D + +This feature was originally introduced by Ricardo Koller at Open +Source Summit NA 2020, then integrated with the syscall translation +functionality with the clean up to the original code. + +Building and run +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +:: + + make ARCH=3Dum x86_64_nommu_defconfig + make ARCH=3Dum + +will build UML with ``CONFIG_MMU=3Dn`` applied. + +Kunit tests can run with the following command:: + + ./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_MMU=3Dn + +To run a typical Linux distribution, we need nommu-aware userspace. +We can use a stock version of Alpine Linux with nommu-built version of +busybox and musl-libc. + + +Preparing root filesystem +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +nommu UML requires to use a specific standard library which is aware +of nommu kernel. We have tested custom-build musl-libc and busybox, +both of which have built-in support for nommu kernels. + +There are no available Linux distributions for nommu under x86_64 +architecture, so we need to prepare our own image for the root +filesystem. We use Alpine Linux as a base distribution and replace +busybox and musl-libc on top of that. The following are the step to +prepare the filesystem for the quick start:: + + container_id=3D$(docker create ghcr.io/thehajime/alpine:3.20.3-um-nom= mu) + docker start $container_id + docker wait $container_id + docker export $container_id > alpine.tar + docker rm $container_id + + mnt=3D$(mktemp -d) + dd if=3D/dev/zero of=3Dalpine.ext4 bs=3D1 count=3D0 seek=3D1G + sudo chmod og+wr "alpine.ext4" + yes 2>/dev/null | mkfs.ext4 "alpine.ext4" || true + sudo mount "alpine.ext4" $mnt + sudo tar -xf alpine.tar -C $mnt + sudo umount $mnt + +This will create a file image, ``alpine.ext4``, which contains busybox +and musl with nommu build on the Alpine Linux root filesystem. The +file can be specified to the argument ``ubd0=3D`` to the UML command line:: + + ./vmlinux ubd0=3D./alpine.ext4 rw mem=3D1024m loglevel=3D8 init=3D/sbin/= init + +We plan to upstream apk packages for busybox and musl so that we can +follow the proper procedure to set up the root filesystem. + + +Quick start with docker +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +There is a docker image that you can quickly start with a simple step:: + + docker run -it -v /dev/shm:/dev/shm --rm ghcr.io/thehajime/alpine:3.20.3= -um-nommu + +This will launch a UML instance with an pre-configured root filesystem. + +Benchmark +=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The below shows an example of performance measurement conducted with +lmbench and (self-crafted) getpid benchmark (with v6.13-rc5 uml/next +tree). + +.. csv-table:: lmbench (usec) + :header: ,native,um,um-nommu(s) + + select-10 ,0.5569,27.0149,2.9772 + select-100 ,2.3964,26.9242,3.8947 + select-1000 ,20.8101,39.6842,12.8161 + syscall ,0.1735,25.7706,2.6997 + read ,0.3488,25.7922,2.7923 + write ,0.2861,26.5560,2.7961 + stat ,1.9171,36.2893,3.2678 + open/close ,3.8475,62.2847,6.3909 + fork+sh ,1159.0000,5230.3333,409.1786 + fork+execve ,535.3000,2075.8333,135.4074 + +.. csv-table:: do_getpid bench (nsec) + :header: ,native,um,um-nommu(s) + + getpid, 172 , 24979 , 2691 + +Limitations +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +generic nommu limitations +------------------------- +Since this port is a kernel of nommu architecture so, the +implementation inherits the characteristics of other nommu kernels +(riscv, arm, etc), described below. + +- vfork(2) should be used instead of fork(2) +- ELF loader only loads PIE (position independent executable) binaries +- processes share the address space among others +- mmap(2) offers a subset of functionalities (e.g., unsupported + MMAP_FIXED) + +Thus, we have limited options to userspace programs. We have tested +Alpine Linux with musl-libc, which has a support nommu kernel. + +supported architecture +---------------------- +The current implementation of nommu UML only works on x86_64 SUBARCH. +We have not tested with 32-bit environment. + + +Further readings about NOMMU UML +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D + +- NOMMU UML (original code by Ricardo Koller) + - https://static.sched.com/hosted_files/ossna2020/ec/kollerr_linux_um_nom= mu.pdf diff --git a/MAINTAINERS b/MAINTAINERS index 8e0736dc2ee0..6738c3fc1256 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -24743,6 +24743,7 @@ USER-MODE LINUX (UML) M: Richard Weinberger M: Anton Ivanov M: Johannes Berg +M: Hajime Tazaki L: linux-um@lists.infradead.org S: Maintained W: http://user-mode-linux.sourceforge.net --=20 2.43.0 From nobody Sat Feb 7 15:04:53 2026 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 5974B1E833F for ; Wed, 30 Apr 2025 04:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987289; cv=none; b=V/GyrXMPREQD4fiAPoLUHVZCQ71PclLuHCvHoouv7GfLfVmwJWAeVLjM1rUJn4gJkfU5dLZ/lt3uzY3TI7e5G9GT22LUMWZZZpYplHyWq5a1yrUHmS6pCtWUmBygtxKrFob6DddhY2e6IzfejC2IdHIe0unYcef83gHlymtoQ7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745987289; c=relaxed/simple; bh=TFsHqaEhkzm+GjAye4kPSKIxJy2XQj4yPdb8QFBTIBU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KcoCYqvvBRXF9HTQXrumpL6VpiScoSmAvZZWKiSI3HmdS4a07SBjQ770x3sQS1UBpPrRQxJ7sSJNWadcv69BLbi8jf7XPQE9Ckhgpuxabv4WOlAEVl2osFS5TqHjpMyZKjZiOzDpJBKeemB+5DjisJID5CrMvTYiAPVCVNOodUs= 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=aFktP8UC; arc=none smtp.client-ip=209.85.216.43 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="aFktP8UC" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-301cda78d48so8421284a91.0 for ; Tue, 29 Apr 2025 21:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987287; x=1746592087; 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=rT31LZBxKQU6eu4tlFml+AuOML692n2PMZhnY9YLrtA=; b=aFktP8UCBIqmAH21iyCI8IRCqivbcAqxKJO+r3i7S4Du6LnejmzMH4AIdUI5aBFmBX pZ9D5FtSskf9KMRhGDgSi310UYxgCiqz62l5Y4Ad3unSih3YZEkjpz8lV2GSjPighQH0 LG6781dDIOUo984qsOhumiahg66KDBNGq/kv5Or1xuuZlxhrtLqRARwYlei3DQYVkb8t LkjDoMFE3/YXS4gbloecjaL2wQVDaeh54v+ODb0Ldu9Zxjr0bqe1vC0DXrzVMfAGZE5M JSMm0Lk55AlINbwQ4esvOXDivDmZHoG/wuCQgvvhSkz8ele7JayNCC//am8Mm+BCdype oYbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987287; x=1746592087; 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=rT31LZBxKQU6eu4tlFml+AuOML692n2PMZhnY9YLrtA=; b=JMrDg6dYaVSDVBRuQ+fipX8/9i1tsqt6FHcT+NNQ7Dw4ltB4kPjOcf06HLLFR4L7rg zz2cjmuxV045TWHM4KVaqQm/c3kP0bLAjXe4gEEbn6rWQXHtPArYNvEoz5MCMnFakubn YmG5m/vA6EXxzmmJJyyI5IqouMKXMfonloHiN6EGIQWerNyd7I3+e0reDX7mP/zsKzlY 85BIZLH2gvJYaFwXWxCl8xVkmwHdgBstVVZhw3ix1HJcy55ABn/kMSgODTNq/p9SBy6e MTosT/C8OBxRC6lgcTVHVkm2Bvqoh2l6HcJxrcWFTvxGNEQSgwr9CBq97GhBOPSITN5a U6kA== X-Forwarded-Encrypted: i=1; AJvYcCVfNICAY9Wr0ke++Ze9yoiEn2rMd8cZFI2NhexuqnN7Re4RI6Atc6j+pZNu5L7AgFvLMYeGbVCoSWVxD3Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+JKDsbJ7YHm+VnqKR1givQcmCSI/QS+AifcpOqmCEEU1F5+lg ytzjt72pcLCeHEoz9HQalsEhR2OJDwaEAFiPwcNvnEQ2Psajgm7q X-Gm-Gg: ASbGnctnFKDPubmc438C38ilJ3Eh6DzFe6p/HcJDQj2NmmRb2/rwoWjhD/PRYZjeq3P qVcjK7dyCHTVXIRwDZB69VdKzoOyMgMRcDuJOK31akoVp+YFDABI+seVU1GUITMd2+5FsfMCwcP IaisdCveD5re2L2pGM3rwkqABbTEeGE3n0VRkI/JVf9TphsiE3AIs86MtYSuFGfdnK7uYph709A kANtfrbAQhd7Qd37bncuXtcowNpibGNX57XrnFAHVVCNiU8E+lQSrLjRRbqWyMyef26OOmAcKXx MdMv+eX0DauRXqdBzsrI0qFdkvP4SA6F9y5r1nuAX/MLSllg11EobyOYvv1CFeyT7X+p4TusmX1 UJSjl7A6Vv8k= X-Google-Smtp-Source: AGHT+IHs8ctUZrSNL4gP9gYydAnVaHBNQJH8vTsp9SOtrT3bTdbngoqV9WtXcIXTZkQTZdyv3JUqTQ== X-Received: by 2002:a17:90b:1f8e:b0:2f4:432d:250d with SMTP id 98e67ed59e1d1-30a33302091mr2229467a91.21.1745987287552; Tue, 29 Apr 2025 21:28:07 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a34a1113csm493273a91.22.2025.04.29.21.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:28:06 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id EFAB9E9482A; Wed, 30 Apr 2025 13:28:04 +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 v8 12/12] um: nommu: plug nommu code into build system Date: Wed, 30 Apr 2025 13:27:18 +0900 Message-ID: <5a59722b1cab960187461701df76d6f4d3f1249f.1745980082.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" Add nommu kernel for um build. defconfig is also provided. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/Kconfig | 14 +++++- arch/um/configs/x86_64_nommu_defconfig | 64 ++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 arch/um/configs/x86_64_nommu_defconfig diff --git a/arch/um/Kconfig b/arch/um/Kconfig index 79509c7f39de..84b2ee7129ae 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -31,14 +31,17 @@ config UML select ARCH_SUPPORTS_LTO_CLANG_THIN select TRACE_IRQFLAGS_SUPPORT select TTY # Needed for line.c - select HAVE_ARCH_VMAP_STACK + select HAVE_ARCH_VMAP_STACK if MMU select HAVE_RUST select ARCH_HAS_UBSAN select HAVE_ARCH_TRACEHOOK select THREAD_INFO_IN_TASK + select UACCESS_MEMCPY if !MMU + select GENERIC_STRNLEN_USER if !MMU + select GENERIC_STRNCPY_FROM_USER if !MMU =20 config MMU - bool + bool "MMU-based Paged Memory Management Support" if 64BIT default y =20 config UML_DMA_EMULATION @@ -191,8 +194,15 @@ config MAGIC_SYSRQ The keys are documented in . = Don't say Y unless you really know what this hack does. =20 +config ARCH_FORCE_MAX_ORDER + int "Order of maximal physically contiguous allocations" if EXPERT + default "10" if MMU + default "16" if !MMU + config KERNEL_STACK_ORDER int "Kernel stack size order" + default 3 if !MMU + range 3 10 if !MMU default 2 if 64BIT range 2 10 if 64BIT default 1 if !64BIT diff --git a/arch/um/configs/x86_64_nommu_defconfig b/arch/um/configs/x86_6= 4_nommu_defconfig new file mode 100644 index 000000000000..c2e0fb546987 --- /dev/null +++ b/arch/um/configs/x86_64_nommu_defconfig @@ -0,0 +1,64 @@ +CONFIG_SYSVIPC=3Dy +CONFIG_POSIX_MQUEUE=3Dy +CONFIG_NO_HZ=3Dy +CONFIG_HIGH_RES_TIMERS=3Dy +CONFIG_BSD_PROCESS_ACCT=3Dy +CONFIG_IKCONFIG=3Dy +CONFIG_IKCONFIG_PROC=3Dy +CONFIG_LOG_BUF_SHIFT=3D14 +CONFIG_CGROUPS=3Dy +CONFIG_BLK_CGROUP=3Dy +CONFIG_CGROUP_SCHED=3Dy +CONFIG_CGROUP_DEVICE=3Dy +CONFIG_CGROUP_CPUACCT=3Dy +# CONFIG_PID_NS is not set +CONFIG_CC_OPTIMIZE_FOR_SIZE=3Dy +# CONFIG_MMU is not set +CONFIG_HOSTFS=3Dy +CONFIG_MAGIC_SYSRQ=3Dy +CONFIG_SSL=3Dy +CONFIG_NULL_CHAN=3Dy +CONFIG_PORT_CHAN=3Dy +CONFIG_PTY_CHAN=3Dy +CONFIG_TTY_CHAN=3Dy +CONFIG_CON_CHAN=3D"pts" +CONFIG_SSL_CHAN=3D"pts" +CONFIG_UML_SOUND=3Dm +CONFIG_UML_NET=3Dy +CONFIG_UML_NET_ETHERTAP=3Dy +CONFIG_UML_NET_TUNTAP=3Dy +CONFIG_UML_NET_SLIP=3Dy +CONFIG_UML_NET_DAEMON=3Dy +CONFIG_UML_NET_MCAST=3Dy +CONFIG_UML_NET_SLIRP=3Dy +CONFIG_MODULES=3Dy +CONFIG_MODULE_UNLOAD=3Dy +CONFIG_IOSCHED_BFQ=3Dm +CONFIG_BINFMT_MISC=3Dm +CONFIG_NET=3Dy +CONFIG_PACKET=3Dy +CONFIG_UNIX=3Dy +CONFIG_INET=3Dy +CONFIG_DEVTMPFS=3Dy +CONFIG_DEVTMPFS_MOUNT=3Dy +CONFIG_BLK_DEV_UBD=3Dy +CONFIG_BLK_DEV_LOOP=3Dm +CONFIG_BLK_DEV_NBD=3Dm +CONFIG_DUMMY=3Dm +CONFIG_TUN=3Dm +CONFIG_PPP=3Dm +CONFIG_SLIP=3Dm +CONFIG_LEGACY_PTY_COUNT=3D32 +CONFIG_UML_RANDOM=3Dy +CONFIG_SOUND=3Dm +CONFIG_EXT4_FS=3Dy +CONFIG_REISERFS_FS=3Dy +CONFIG_QUOTA=3Dy +CONFIG_AUTOFS_FS=3Dm +CONFIG_ISO9660_FS=3Dm +CONFIG_JOLIET=3Dy +CONFIG_NLS=3Dy +CONFIG_DEBUG_KERNEL=3Dy +CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=3Dy +CONFIG_FRAME_WARN=3D1024 +CONFIG_IPV6=3Dy --=20 2.43.0