From nobody Wed Dec 17 08:44:15 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 1AAF125A630 for ; Sat, 8 Nov 2025 08:05:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589158; cv=none; b=sAmHKfQg0oWPpS0hpbpJclPyFR9h3iP5SPrP56SIjm4DFI/0MUFVAuEpaIJ6LRGtH0Gq/ijMyLi1mFXBfb8U0RwfLB8TgrQVB9eccp62KufjqbpHK75u5SpFROspz5rkAfzUIwW8ocZ5MGb5Xs1Q92f31FuyBX2gdb5rKqKXiZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589158; c=relaxed/simple; bh=CvYzjfP7rw4yGGJRdX8B4balTna1wcyExbLjMjY+2gM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fxrib6CwtcN99mbDIHRrMoDa+R5drr99mnU3L45Pp8okc2RhZ/ZmQ+lH7vxFIhGSvXqhc8Lf2HCugsFkQxpN8y+aejKb18K+z7sO3tOPxy99NKToz2HmbrHGsO6mPw7sQC3rUkilHCyZvqDauJaoYm8eF9bibpS3FSTHGmaM8rM= 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=gqTs+69F; arc=none smtp.client-ip=209.85.214.171 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="gqTs+69F" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-294fe7c2e69so16024105ad.0 for ; Sat, 08 Nov 2025 00:05:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589156; x=1763193956; 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=hjmnnaJ+dU4QzslBxUrlmdhSXDXCpeTGjd28jp/dBEQ=; b=gqTs+69FF3kfegUNdsmb18tTgXgdmSAcwoBmMo2qY9VZ15WHGKOa4bNugon5P4NFtV In69Hm9lejo6f6eP+dUFGpx5UufFPKv5ynI8vdiSqtwoCDF4OxoGvLUe883EYB5b5w/A pPk3EzsZg3LhYKhqh6k5fQJ0PaRPIy0kwerWgVO3Cna3vXQ/L5vWJhzaujkFXZVk9LgC WbSDJOWbM77DmUYySQLqEzF+hONP2fIZfGnbmeTxUonIL8636xLQwaM5BRQasFnbMUUb N6AgSHss9MziDejNG1b0xXcnMu+twLJMyQiAPg5ePA2td6N9WiY4A4VVoKMQZ0ijoMYT JonQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589156; x=1763193956; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hjmnnaJ+dU4QzslBxUrlmdhSXDXCpeTGjd28jp/dBEQ=; b=CiFRbGX5y6A0s0RWPRWYrnmdBc8WCUGS4GdCkYXyIeQSWLSkNwIawo3F7Z7VYKM6M0 dDwXYjbfeEq9wTCH2xdnDxfKTHDqXAjW9DEFVZ7buUTn9YHw7dpk6DSj07o+hHqHkIgx ANx2sChjZO2UTznAo7wF2v1kxPFEGfJfraMDEH/84eJIL/231aO5N8MMIBkTV6vC8So3 hgZaG31l2WIWijp4uf/TOCBVUTiulCZzIxRCOUNbRGEoditD4vSojGbu/0J0r5GLmgf2 cFE0AWu49egukkiWG7C2+4CVaGE2CtkJhqd+FPLq3PZLgHxo392gsU2hozYyDAJ95Hw5 PWOg== X-Forwarded-Encrypted: i=1; AJvYcCUqXFGqQmaRWIWaTRJ5UfuTqyj/CeL3dF/w3QizCyLK7m0VRLxc+sHWepop0OWEIdFKHBf3Q51yKYFtKuU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7nGtbZar7UA7oRZpWL8stLzwCAnhZ3iDpWYVh49RPIxYY5Y4k 11eVFSSIttNhhluOTSvydFzVTsj7pexYaMlsmuZ5WaXBk9WXB+S367fy5Sdy48IH X-Gm-Gg: ASbGnctH+cbgSAHHM+6jLT0hA998hBo0DtxGouGKU8v1HUn1Aji/wk6ZTWbVKf6SEQN fZR9vAAE9UTvaTgzqOdTgwMIvlPBu66qNuRjiIq8yzOYvzQxEe5RyCGArwh7NTQaXPbD5RXdeqk rrY8WAy2SFcsT2DKL03cIwI6iCWmAR3fMIkaBLPshZPlm64gAfSlvszE2TL5l6ecwGF6BAt6zWa +eXAYltP0WNXz9JqJGmnsD6ltqqRODCXte587aGaeFsVs9z/c/FEOQ8zQifKEbudqZDKzWUan0P w8VTL7129xFQhZPAhlb2PpQvGmbAXRdiYMJN0MtI9P63xGI21Gibgxt88e6S0o/Y1mWfyCGdSg9 KfwXFQLfCCUHjIdmMy2/HneNjAUpDOrQzibSsO6viGR2dmymKg6xDMftdMD00lSobyeL0ARDmZw xCC+eUjGSXLxElRE9cjrxgqnwGomXZrM1bnQfgBCGxcFVdAaEbtl8qxvlgExcKamO83XE= X-Google-Smtp-Source: AGHT+IFNIgTTAZ2Vl2vkAxBvJV+q8EYjnppJ5K0pIHpzL9Ue02aCEVYgWqO6SIqSBUirhrY7QzbLaw== X-Received: by 2002:a17:903:ac6:b0:295:269d:87cf with SMTP id d9443c01a7336-297e5619d74mr21459175ad.5.1762589156346; Sat, 08 Nov 2025 00:05:56 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2965096b801sm83340945ad.7.2025.11.08.00.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:05:55 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 0019311388C7; Sat, 8 Nov 2025 17:05:53 +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 v13 01/13] x86/um: nommu: elf loader for fdpic Date: Sat, 8 Nov 2025 17:05:36 +0900 Message-ID: <59210140957e95ab0df73125bfdb035913a468b1.1762588860.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 07d48738b402..82a919132aff 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -21,6 +21,11 @@ typedef struct mm_context { spinlock_t sync_tlb_lock; 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 #define INIT_MM_CONTEXT(mm) \ diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptr= ace-generic.h index 86d74f9d33cf..62e9916078ec 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 22d0111b543b..388fe669886c 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 @@ -158,8 +159,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 1949e25c7741..0a92bebd5f75 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 Wed Dec 17 08:44:15 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3F9427877D for ; Sat, 8 Nov 2025 08:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589165; cv=none; b=VHFxWfN/892vtkeF6jDpk8fX3KS/4RajmRkn8Yh6Age3ZlOoc6EqC8Gg2CQZVXIH0LJ2WF+ldRR9+U8zOMh1OGBu1z0qswY690cxDEDXWWefunAUL/ueu0uuoSrxTYvhO5Fm5vtGAGSuqV0XchK0TbZXti+4al5ewvSDOFlK5I4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589165; c=relaxed/simple; bh=4xcFrZ+JqQ3sy1fsQCIhfLPeC7rXS4iJayunDgoRLEo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MqwJd8MjFIuaZWegSV28MY+zX6m7GB915UJON1NvGIRgue07C3Vv8GjX9I52b8MJM6s73tbShehenMkuofouvzElALbReCkqRKmlG10zy2zGgcaAgVdY72+0jSBz7+/vZqOv/qP2WOop2IVCqVXCgXGaoUor7Up2VoHJoOj/lD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OxjDmQay; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OxjDmQay" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-297dc3e299bso6850495ad.1 for ; Sat, 08 Nov 2025 00:06:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589162; x=1763193962; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AADfWcJgVjD9ZN7PUFLyBggrmXQYWqBtbT5qNU1VBN8=; b=OxjDmQaytpEctDItfaQik/3EVVLNzyXk7FVFlDDGII9lhI65226IshdzpNHzzQzy7/ GA+OXlOQdkaTjLAQ5ZJ6PWyyZvAslVTV/ZRI1fW+qzhiYh0JirnZ3/BA4+tjksH0MNb7 3baTqGO/6dzRm5XbCbSi0oqHOP2CCW6gvA6ci523UfRKYQiOuf4DoAgyY1lp56l4nrNZ 4oVtLM6QctOZ1dL6dwSepxDSEy4C7Cn9JcVnf6gCKSrl8uHRVaVdubSnVDZhthgKG6gJ +PoGmOWkQdp+aBMC3ussaGZZMkAUWvO0DnaCNC/CVH2B4ze6QVV+2HZmHFpf28wVfpV5 9CSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589162; x=1763193962; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=AADfWcJgVjD9ZN7PUFLyBggrmXQYWqBtbT5qNU1VBN8=; b=vwttzCiyCwOl45FFCwFMHR6JTIySB3jMst6f60J9SH59hfEt9Xh+wpRn1nZuoXtaGB CKqz7LtMRx03EkBYnNPQtJE0I2Jr61lV8iVh9WwqbVXmB536mWRI87vTB5ZqeNYT+FDR d5H/GKAcxehKJNFt/K+YMkeW2IwdKzQ+qgivjGz299UEcnOCQFyvczIkoJjl5a5QzMkj NzvMwgNyZaBKPYohHbWPfpuc0hcPFjlQtH5FR4Whu1WEH6bjmFpHYIl4TKdMTxXi2Xd0 7quXIHE/gp4pBfk2fnT01mYZTIDDw6a+xxB/wwYZjF1Q6M84LflcTgbHsSOHh98jV7xt tAwQ== X-Forwarded-Encrypted: i=1; AJvYcCUGVpHEvgK1frO/4D5bi+mptsFALBA2TRAdcC90n21pnAYiwxNMNzEbT15iKQ1ylouX3qgUjr8JuSzhL6E=@vger.kernel.org X-Gm-Message-State: AOJu0YwdMteGuhJywI3XPYGxxL3g+2imEeUDhL5Xaa+8m8Fs5u6XqlhX 5r+vHXiD0kISeJouIbh5iZah6p+V25CcI8+zaW3+YmMHTkIXjC97mEHZBlr3xg== X-Gm-Gg: ASbGncvVHWCd8TSaVLLzAyukvj4yV3+tLPhOEYd45dxsjjf9sIgeyQ9TCbRRMXgOIK9 Qkjmzhnc2qjNrEnPtJINw3fbaVtuOQ04qMO3VzWB0mNy8zHKJaf5XsxACASUdPW/T+x5Em+cr9n fwNdBKLLQgZDhB7HaWJ3ABtYAKLC8A6Itupl2AkQTuAfwEI+Nb6fXRDxrLBMfY9NgAph6luYcDZ xWzPwO5x6c2+9kMDG8YtAENEB214POutsQIZW3bwHCHIqFabiBIS/04G2buXmxxs+wUiYDDR7c/ SpHUvDnS5YH3pml6IPC/x07LiyBDwi74Haz54j0vLgmrcFLfpruZzAJ06thVN2E8r/LiM6596ub XEMgvkIXP+zu1srBx+xSpzeFpCbv1C6i4Tu+BpATnnVLpTHFvQWpqVQRU1X7okxTD34C0NGc7eP HM79NLfmWoxlYH6rhRxGT78X2e28Cu79up6QkR9SXEWX7E/A== X-Google-Smtp-Source: AGHT+IFiJr0EeMCxqF+xD/dFMEIX//Iica2/667frEt8MglvDOKULW8yWmUZ2gxdKGQQIHQbJRODxQ== X-Received: by 2002:a17:902:f791:b0:297:e267:c4c1 with SMTP id d9443c01a7336-297e5718125mr22597115ad.55.1762589161767; Sat, 08 Nov 2025 00:06:01 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29651c6f6cdsm83649695ad.71.2025.11.08.00.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:01 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 57AE911388C9; Sat, 8 Nov 2025 17:05:59 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 02/13] um: decouple MMU specific code from the common part Date: Sat, 8 Nov 2025 17:05:37 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This splits the memory, process related code with common and MMU specific parts in order to avoid ifdefs in .c file and duplication between MMU and !MMU. Signed-off-by: Hajime Tazaki --- arch/um/kernel/Makefile | 5 +- arch/um/kernel/mem-pgtable.c | 55 ++++++++++++++ arch/um/kernel/mem.c | 35 --------- arch/um/kernel/process.c | 38 ++++++++++ arch/um/kernel/skas/process.c | 37 --------- arch/um/os-Linux/Makefile | 3 +- arch/um/os-Linux/process.c | 129 ++++++++++++++++++++++++++++++++ arch/um/os-Linux/skas/process.c | 127 ------------------------------- 8 files changed, 227 insertions(+), 202 deletions(-) create mode 100644 arch/um/kernel/mem-pgtable.c diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index be60bc451b3f..76d36751973e 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -16,9 +16,10 @@ always-$(KBUILD_BUILTIN) :=3D vmlinux.lds =20 obj-y =3D config.o exec.o exitcode.o irq.o ksyms.o mem.o \ physmem.o process.o ptrace.o reboot.o sigio.o \ - signal.o sysrq.o time.o tlb.o trap.o \ - um_arch.o umid.o kmsg_dump.o capflags.o skas/ + signal.o sysrq.o time.o \ + um_arch.o umid.o kmsg_dump.o capflags.o obj-y +=3D load_file.o +obj-$(CONFIG_MMU) +=3D mem-pgtable.o tlb.o trap.o skas/ =20 obj-$(CONFIG_BLK_DEV_INITRD) +=3D initrd.o obj-$(CONFIG_GPROF) +=3D gprof_syms.o diff --git a/arch/um/kernel/mem-pgtable.c b/arch/um/kernel/mem-pgtable.c new file mode 100644 index 000000000000..549da1d3bff0 --- /dev/null +++ b/arch/um/kernel/mem-pgtable.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* Allocate and free page tables. */ + +pgd_t *pgd_alloc(struct mm_struct *mm) +{ + pgd_t *pgd =3D (pgd_t *)__get_free_page(GFP_KERNEL); + + if (pgd) { + memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t)); + memcpy(pgd + USER_PTRS_PER_PGD, + swapper_pg_dir + USER_PTRS_PER_PGD, + (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); + } + return pgd; +} + +static const pgprot_t protection_map[16] =3D { + [VM_NONE] =3D PAGE_NONE, + [VM_READ] =3D PAGE_READONLY, + [VM_WRITE] =3D PAGE_COPY, + [VM_WRITE | VM_READ] =3D PAGE_COPY, + [VM_EXEC] =3D PAGE_READONLY, + [VM_EXEC | VM_READ] =3D PAGE_READONLY, + [VM_EXEC | VM_WRITE] =3D PAGE_COPY, + [VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_COPY, + [VM_SHARED] =3D PAGE_NONE, + [VM_SHARED | VM_READ] =3D PAGE_READONLY, + [VM_SHARED | VM_WRITE] =3D PAGE_SHARED, + [VM_SHARED | VM_WRITE | VM_READ] =3D PAGE_SHARED, + [VM_SHARED | VM_EXEC] =3D PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_READ] =3D PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_WRITE] =3D PAGE_SHARED, + [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_SHARED +}; +DECLARE_VM_GET_PAGE_PROT diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 39c4a7e21c6f..f3258680bfbe 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -107,45 +106,11 @@ void free_initmem(void) { } =20 -/* Allocate and free page tables. */ - -pgd_t *pgd_alloc(struct mm_struct *mm) -{ - pgd_t *pgd =3D __pgd_alloc(mm, 0); - - if (pgd) - memcpy(pgd + USER_PTRS_PER_PGD, - swapper_pg_dir + USER_PTRS_PER_PGD, - (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); - - return pgd; -} - void *uml_kmalloc(int size, int flags) { return kmalloc(size, flags); } =20 -static const pgprot_t protection_map[16] =3D { - [VM_NONE] =3D PAGE_NONE, - [VM_READ] =3D PAGE_READONLY, - [VM_WRITE] =3D PAGE_COPY, - [VM_WRITE | VM_READ] =3D PAGE_COPY, - [VM_EXEC] =3D PAGE_READONLY, - [VM_EXEC | VM_READ] =3D PAGE_READONLY, - [VM_EXEC | VM_WRITE] =3D PAGE_COPY, - [VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_COPY, - [VM_SHARED] =3D PAGE_NONE, - [VM_SHARED | VM_READ] =3D PAGE_READONLY, - [VM_SHARED | VM_WRITE] =3D PAGE_SHARED, - [VM_SHARED | VM_WRITE | VM_READ] =3D PAGE_SHARED, - [VM_SHARED | VM_EXEC] =3D PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_READ] =3D PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_WRITE] =3D PAGE_SHARED, - [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_SHARED -}; -DECLARE_VM_GET_PAGE_PROT - void mark_rodata_ro(void) { unsigned long rodata_start =3D PFN_ALIGN(__start_rodata); diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 63b38a3f73f7..b07c1f120910 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -307,3 +308,40 @@ unsigned long __get_wchan(struct task_struct *p) =20 return 0; } + +extern void start_kernel(void); + +static int __init start_kernel_proc(void *unused) +{ + block_signals_trace(); + + start_kernel(); + return 0; +} + +char cpu_irqstacks[NR_CPUS][THREAD_SIZE] __aligned(THREAD_SIZE); + +int __init start_uml(void) +{ + stack_protections((unsigned long) &cpu_irqstacks[0]); + set_sigstack(cpu_irqstacks[0], THREAD_SIZE); + + init_new_thread_signals(); + + init_task.thread.request.thread.proc =3D start_kernel_proc; + init_task.thread.request.thread.arg =3D NULL; + return start_idle_thread(task_stack_page(&init_task), + &init_task.thread.switch_buf); +} + +static DEFINE_SPINLOCK(initial_jmpbuf_spinlock); + +void initial_jmpbuf_lock(void) +{ + spin_lock_irq(&initial_jmpbuf_spinlock); +} + +void initial_jmpbuf_unlock(void) +{ + spin_unlock_irq(&initial_jmpbuf_spinlock); +} diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c index 4a7673b0261a..d643854942bc 100644 --- a/arch/um/kernel/skas/process.c +++ b/arch/um/kernel/skas/process.c @@ -17,31 +17,6 @@ #include #include =20 -extern void start_kernel(void); - -static int __init start_kernel_proc(void *unused) -{ - block_signals_trace(); - - start_kernel(); - return 0; -} - -char cpu_irqstacks[NR_CPUS][THREAD_SIZE] __aligned(THREAD_SIZE); - -int __init start_uml(void) -{ - stack_protections((unsigned long) &cpu_irqstacks[0]); - set_sigstack(cpu_irqstacks[0], THREAD_SIZE); - - init_new_thread_signals(); - - init_task.thread.request.thread.proc =3D start_kernel_proc; - init_task.thread.request.thread.arg =3D NULL; - return start_idle_thread(task_stack_page(&init_task), - &init_task.thread.switch_buf); -} - unsigned long current_stub_stack(void) { if (current->mm =3D=3D NULL) @@ -65,15 +40,3 @@ void current_mm_sync(void) =20 um_tlb_sync(current->mm); } - -static DEFINE_SPINLOCK(initial_jmpbuf_spinlock); - -void initial_jmpbuf_lock(void) -{ - spin_lock_irq(&initial_jmpbuf_spinlock); -} - -void initial_jmpbuf_unlock(void) -{ - spin_unlock_irq(&initial_jmpbuf_spinlock); -} diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index f8d672d570d9..40e3e0eab6a0 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile @@ -8,7 +8,8 @@ KCOV_INSTRUMENT :=3D n =20 obj-y =3D elf_aux.o execvp.o file.o helper.o irq.o main.o mem.o process.o \ registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o user_syms.o util.o skas/ + umid.o user_syms.o util.o +obj-$(CONFIG_MMU) +=3D skas/ =20 CFLAGS_signal.o +=3D -Wframe-larger-than=3D4096 =20 diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 3a2a84ab9325..c50fa865d8c7 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -6,6 +6,7 @@ =20 #include #include +#include #include #include #include @@ -17,10 +18,16 @@ #include #include #include +#include #include #include #include #include +#include +#include + +int using_seccomp; +static int unscheduled_userspace_iterations; =20 void os_alarm_process(int pid) { @@ -209,3 +216,125 @@ int os_futex_wake(void *uaddr) NULL, NULL, 0)); return r < 0 ? -errno : r; } + +int is_skas_winch(int pid, int fd, void *data) +{ + return pid =3D=3D getpgrp(); +} + +void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)) +{ + (*buf)[0].JB_IP =3D (unsigned long) handler; + (*buf)[0].JB_SP =3D (unsigned long) stack + UM_THREAD_SIZE - + sizeof(void *); +} + +#define INIT_JMP_NEW_THREAD 0 +#define INIT_JMP_CALLBACK 1 +#define INIT_JMP_HALT 2 +#define INIT_JMP_REBOOT 3 + +void switch_threads(jmp_buf *me, jmp_buf *you) +{ + unscheduled_userspace_iterations =3D 0; + + if (UML_SETJMP(me) =3D=3D 0) + UML_LONGJMP(you, 1); +} + +static jmp_buf initial_jmpbuf; + +static __thread void (*cb_proc)(void *arg); +static __thread void *cb_arg; +static __thread jmp_buf *cb_back; + +int start_idle_thread(void *stack, jmp_buf *switch_buf) +{ + int n; + + set_handler(SIGWINCH); + + /* + * Can't use UML_SETJMP or UML_LONGJMP here because they save + * and restore signals, with the possible side-effect of + * trying to handle any signals which came when they were + * blocked, which can't be done on this stack. + * Signals must be blocked when jumping back here and restored + * after returning to the jumper. + */ + n =3D setjmp(initial_jmpbuf); + switch (n) { + case INIT_JMP_NEW_THREAD: + (*switch_buf)[0].JB_IP =3D (unsigned long) uml_finishsetup; + (*switch_buf)[0].JB_SP =3D (unsigned long) stack + + UM_THREAD_SIZE - sizeof(void *); + break; + case INIT_JMP_CALLBACK: + (*cb_proc)(cb_arg); + longjmp(*cb_back, 1); + break; + case INIT_JMP_HALT: + kmalloc_ok =3D 0; + return 0; + case INIT_JMP_REBOOT: + kmalloc_ok =3D 0; + return 1; + default: + printk(UM_KERN_ERR "Bad sigsetjmp return in %s - %d\n", + __func__, n); + fatal_sigsegv(); + } + longjmp(*switch_buf, 1); + + /* unreachable */ + printk(UM_KERN_ERR "impossible long jump!"); + fatal_sigsegv(); + return 0; +} + +void initial_thread_cb_skas(void (*proc)(void *), void *arg) +{ + jmp_buf here; + + cb_proc =3D proc; + cb_arg =3D arg; + cb_back =3D &here; + + initial_jmpbuf_lock(); + if (UML_SETJMP(&here) =3D=3D 0) + UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); + initial_jmpbuf_unlock(); + + cb_proc =3D NULL; + cb_arg =3D NULL; + cb_back =3D NULL; +} + +void halt_skas(void) +{ + initial_jmpbuf_lock(); + UML_LONGJMP(&initial_jmpbuf, INIT_JMP_HALT); + /* unreachable */ +} + +static bool noreboot; + +static int __init noreboot_cmd_param(char *str, int *add) +{ + *add =3D 0; + noreboot =3D true; + return 0; +} + +__uml_setup("noreboot", noreboot_cmd_param, +"noreboot\n" +" Rather than rebooting, exit always, akin to QEMU's -no-reboot option.= \n" +" This is useful if you're using CONFIG_PANIC_TIMEOUT in order to catch= \n" +" crashes in CI\n\n"); + +void reboot_skas(void) +{ + initial_jmpbuf_lock(); + UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT); + /* unreachable */ +} diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/proces= s.c index d6c22f8aa06d..01814ad82f5d 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -29,16 +28,10 @@ #include #include #include -#include #include #include #include "../internal.h" =20 -int is_skas_winch(int pid, int fd, void *data) -{ - return pid =3D=3D getpgrp(); -} - static const char *ptrace_reg_name(int idx) { #define R(n) case HOST_##n: return #n @@ -426,8 +419,6 @@ static int __init init_stub_exe_fd(void) } __initcall(init_stub_exe_fd); =20 -int using_seccomp; - /** * start_userspace() - prepare a new userspace process * @mm_id: The corresponding struct mm_id @@ -540,7 +531,6 @@ int start_userspace(struct mm_id *mm_id) return err; } =20 -static int unscheduled_userspace_iterations; extern unsigned long tt_extra_sched_jiffies; =20 void userspace(struct uml_pt_regs *regs) @@ -789,120 +779,3 @@ void userspace(struct uml_pt_regs *regs) } } } - -void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)) -{ - (*buf)[0].JB_IP =3D (unsigned long) handler; - (*buf)[0].JB_SP =3D (unsigned long) stack + UM_THREAD_SIZE - - sizeof(void *); -} - -#define INIT_JMP_NEW_THREAD 0 -#define INIT_JMP_CALLBACK 1 -#define INIT_JMP_HALT 2 -#define INIT_JMP_REBOOT 3 - -void switch_threads(jmp_buf *me, jmp_buf *you) -{ - unscheduled_userspace_iterations =3D 0; - - if (UML_SETJMP(me) =3D=3D 0) - UML_LONGJMP(you, 1); -} - -static jmp_buf initial_jmpbuf; - -static __thread void (*cb_proc)(void *arg); -static __thread void *cb_arg; -static __thread jmp_buf *cb_back; - -int start_idle_thread(void *stack, jmp_buf *switch_buf) -{ - int n; - - set_handler(SIGWINCH); - - /* - * Can't use UML_SETJMP or UML_LONGJMP here because they save - * and restore signals, with the possible side-effect of - * trying to handle any signals which came when they were - * blocked, which can't be done on this stack. - * Signals must be blocked when jumping back here and restored - * after returning to the jumper. - */ - n =3D setjmp(initial_jmpbuf); - switch (n) { - case INIT_JMP_NEW_THREAD: - (*switch_buf)[0].JB_IP =3D (unsigned long) uml_finishsetup; - (*switch_buf)[0].JB_SP =3D (unsigned long) stack + - UM_THREAD_SIZE - sizeof(void *); - break; - case INIT_JMP_CALLBACK: - (*cb_proc)(cb_arg); - longjmp(*cb_back, 1); - break; - case INIT_JMP_HALT: - kmalloc_ok =3D 0; - return 0; - case INIT_JMP_REBOOT: - kmalloc_ok =3D 0; - return 1; - default: - printk(UM_KERN_ERR "Bad sigsetjmp return in %s - %d\n", - __func__, n); - fatal_sigsegv(); - } - longjmp(*switch_buf, 1); - - /* unreachable */ - printk(UM_KERN_ERR "impossible long jump!"); - fatal_sigsegv(); - return 0; -} - -void initial_thread_cb_skas(void (*proc)(void *), void *arg) -{ - jmp_buf here; - - cb_proc =3D proc; - cb_arg =3D arg; - cb_back =3D &here; - - initial_jmpbuf_lock(); - if (UML_SETJMP(&here) =3D=3D 0) - UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); - initial_jmpbuf_unlock(); - - cb_proc =3D NULL; - cb_arg =3D NULL; - cb_back =3D NULL; -} - -void halt_skas(void) -{ - initial_jmpbuf_lock(); - UML_LONGJMP(&initial_jmpbuf, INIT_JMP_HALT); - /* unreachable */ -} - -static bool noreboot; - -static int __init noreboot_cmd_param(char *str, int *add) -{ - *add =3D 0; - noreboot =3D true; - return 0; -} - -__uml_setup("noreboot", noreboot_cmd_param, -"noreboot\n" -" Rather than rebooting, exit always, akin to QEMU's -no-reboot option.= \n" -" This is useful if you're using CONFIG_PANIC_TIMEOUT in order to catch= \n" -" crashes in CI\n\n"); - -void reboot_skas(void) -{ - initial_jmpbuf_lock(); - UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT); - /* unreachable */ -} --=20 2.43.0 From nobody Wed Dec 17 08:44:15 2025 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.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 67ACD295DAC for ; Sat, 8 Nov 2025 08:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589166; cv=none; b=uc2apndQkvxMMhANpHo5n0kWaMkL0H4YstxudTi3iBP4Y4SwvhWo9EdB5zdXACbnRMZlEH/m21OubAcb4vQphN3tZ6DOYw2HhkUkgslW8VlfB1bg+PmjLvpux5mAts6Au+zQX35wmhaJsIMN6XmfXKE1/b7xdIE7dgS6uXnMeDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589166; c=relaxed/simple; bh=bSDEYAueziQBf3WylfgbNGKPCbRnWhpRBSBYqNqX8LM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MVW6edOd/v5J60jKvXLkrrOcGApiYflzclJ20CCew+MJO/BUF22aqQzwgPN7+bYaYmQ+ZdLL6KOym+HP7c3teZLovI7Wgu4GtAdX4FbhlXzn0Y77j55/A/TAU2QycHRdUaMIdkn+XaTLnTu5vICqVTcxqjftIpoODN3zThy2vCQ= 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=mWZ+Irao; arc=none smtp.client-ip=209.85.210.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="mWZ+Irao" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-793021f348fso1076553b3a.1 for ; Sat, 08 Nov 2025 00:06:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589164; x=1763193964; 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=Lm2scelwojVCxczz2ObXlffF/4mE69mJL29qxONKAeE=; b=mWZ+Iraonb0pS4o3FsRd/DTtF4uGjgEJJQo3kKwyYtYtv+T9K2Sn4lX7GTc9aKIJHR 683YA+dN6UU8wz/TyE2Df4oheQB8QxVdj0qLfzRYXaVTHpQHcAuzDHBNDEZqLl9cuki2 8ffKraX0T3/yWRC/tlC6rJ/8CiBH93DGqy2+rC4hEOMcN6qgttwaqaLynFU0zvWk8yEF lB/IrmjYMkXQ0qxffTDih+MhGczprNnY/OCb9zbiYlkLaby11OqFvxnjsyHhG1+nBfI7 5QauInuSQDTtFW4akeFYHtghwHFmPTqxzLwwY1ok0aqwWczQAc3rzYf33Yt172IUifwa hYgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589164; x=1763193964; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Lm2scelwojVCxczz2ObXlffF/4mE69mJL29qxONKAeE=; b=eWK3u2qWcn2N8v9jWy55p9qarIPLaX/pl06OjWYw5BPFrlrN5j0CqmsHXqgFz7U67R skI21aecYk3peRfJafOhxW0BY91oAE5MQGx5G0CMFHRPzrx3DKeEqhbBv/nomxVNP5xY vuovHexdmcqdMPFlER6gJPctgmbFYbgP9VEPXoGPmxk57bUe0eDvcnqwabTVy84lZnN8 7IQND1PtgIUlRlCamoaIPBufk2qTnMVyr+PCtX03TbZeLYveVLMPHpo0GrAQbjqHib+R 13sxhtTPpnGJAuEFZl9xEocfKsDJRSpUJ7ABCEekKyo9wj86KKj+MBdKPYZk5PctyjHz ZXuQ== X-Forwarded-Encrypted: i=1; AJvYcCVXWYANOcB4Wp6OmXPhcEjpWy1+3qO/HqYbYyvCnvZDeSFSHGTVOc46oWpDFy6acN97vX2OebuPbIPCEXw=@vger.kernel.org X-Gm-Message-State: AOJu0YwQWdMZqwXVYH4v4is73JsB92cdXndCOU7fsFGPBQ3DItsHLEGy zFdjJAty/8f43U37Oy3gsmN5+xsYeeiueAqGy3innstI8hVkQbG4Kq+X X-Gm-Gg: ASbGncsVSQABfydT9uSd0RocWLhpFhFLarE97q+MpH+J4pXTKeZzwqRcYYH65kNYbGa lIGdG5ZzLXdYQ1D8UqZ15iPypNjBK33TYoweAgm4uJhmbMXKviiv5/P//OoPhvHPkul3NNlIiuK b+6rY4iiHOvO0bbEIvcsw3fDxoS79mg13YxgQ/PJsHg3dtMZL9BX5XbbOSiFqBvOOpigLsqGKZI /V4e0ISVLren20lw0aIx6LQBIEKiBw6whbV1dnmkYFW3lya2BQAyaxiivddB4DS3nbaQdFzFfXK cOJD1/esRQAkrVUMQriZFiHCrt89Ghl/Ka9CiJ/W0ShSvGFcXYDdv/Bl9fYXb8rYYw3FTowXtCk 7mnbXohQTjv2EIJcgjFlKj0elgC1nFi4DQBG4mQAfrwuh08gcHgNX4xyfWdzyxgj5kPUQO71eYY UsjQXn6Qvdp+azVBV/chTVCxAAMATXLU6ZegnMSqkmzo5isA== X-Google-Smtp-Source: AGHT+IGu/het2cVRieRqiXorkhj+THkOqiM2xkhG3vmOKrA/bzZOZb+7OfPVwqzTvt7adsqHGGOymQ== X-Received: by 2002:a05:6a20:729d:b0:334:8a8e:6576 with SMTP id adf61e73a8af0-353a314c69fmr2474816637.29.1762589163524; Sat, 08 Nov 2025 00:06:03 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b0c9ff8538sm5219197b3a.28.2025.11.08.00.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:02 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 95CE511388CB; Sat, 8 Nov 2025 17:06:01 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 03/13] um: nommu: memory handling Date: Sat, 8 Nov 2025 17:05:38 +0900 Message-ID: <28512370a78b53783655667300bc4464fd338029.1762588860.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 7be0143b5ba3..5371c9a1b11e 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 82a919132aff..c0b9ce3215c4 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -22,10 +22,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 #define INIT_MM_CONTEXT(mm) \ diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_co= ntext.h index c727e56ba116..528b217da285 100644 --- a/arch/um/include/asm/mmu_context.h +++ b/arch/um/include/asm/mmu_context.h @@ -18,11 +18,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 0df9ea4abda8..031b357800b7 100644 --- a/arch/um/include/asm/uaccess.h +++ b/arch/um/include/asm/uaccess.h @@ -18,6 +18,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); @@ -29,9 +30,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; @@ -63,5 +61,8 @@ do { \ barrier(); \ 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 f3258680bfbe..e599b637c5fb 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -71,7 +71,8 @@ void __init arch_mm_preinit(void) * to be turned on. */ brk_end =3D PAGE_ALIGN((unsigned long) 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 c50fa865d8c7..ddb5258d7720 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -100,8 +100,8 @@ int os_map_memory(void *virt, int fd, unsigned long lon= g 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 Wed Dec 17 08:44:15 2025 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.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 44C372E3AEA for ; Sat, 8 Nov 2025 08:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589170; cv=none; b=ORnqlJzGll/ireq1Am/i0xR701BfOrT3jVTscJY1H9jMV7o6aCzWFHrvnrCG8oXu+IgS+EQRK6he7N9znrTUjQOblB92ySEcYHXLwKRdLnOtFlRg2+O5f9xQ2Esl+uhaks9XCJWS+WTA26OoTbF7CDhdByHWSxwrVW7fSJhhYKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589170; c=relaxed/simple; bh=ohZr8TN+3EzzLa/zdEUa/3GcfCV2x/KsAaalXoHEw/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BN/2GFVoxG7HMgC7VEBwCgaXq7xKtQbWYGowKjJo7FnhVCrQ5kaeL4u3H5KxrXRFih39Nk93l4rWVPcMmwgz7WCptv6sFvi5JTnrv1yra7JGyhQZd7P+/+8Y4S8wQ9TPQgFxKyDNJwA+jUxLC76NyPjAvfcyr9yLFLEAtkVU3Gc= 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=WmessiOE; arc=none smtp.client-ip=209.85.214.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="WmessiOE" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-297d4a56f97so8516945ad.1 for ; Sat, 08 Nov 2025 00:06:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589166; x=1763193966; 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=fo64Q14KD7RJjz3s47AhqXDA7DbhSnhy3sX7mHpz33g=; b=WmessiOEmshltWF7TU4b2eIVvyvkZoKDT350Q2VzycdeGiaWDQW8urPCZgXZYA4nlC P365C5mTrOwC9JfuXWfpM/Vf3dgAY84RYoESyNirHdmziNwwKSt6SEpbYxWdJj182mt8 BE3kthX6SeJeUnw3Tk+PIL+liKIYZW3Q+vfGuKplMzGVVztlLN4tuajqXLZpRTsX5qJe 5d/AZ6GyMk5w1zOPs3EnC5Mdt65IKqGYSaVNSK0xp81RdoiCqYI9IpZEymsKSOU/mQ9n B9ss3DkOxfy2xOIu94h3+xFYpuQn78PcDO8b+sw3hayr6Bcgn2Z6IxdB/IhZSd8chce+ MDVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589166; x=1763193966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fo64Q14KD7RJjz3s47AhqXDA7DbhSnhy3sX7mHpz33g=; b=cKOkQ+rnCVMnZ2LaQnO62jl5b8k3qlNBoGlHyc37As7Rtt/n2cTKiwUrG0TQ08EpMT MA2q8tKIg4ZnZ1qj3JkEKknIOYR8L7538Mc8xxvT371NeBxeRWkLrJo3dNwPeltjI9bD e55tgjsfcZshIk7fL6ttC/YP2Ll1KvlSlZlo/nS49NzpeEoCeRGuSZZAmIIhi0C8qQCO kIhp+kh+9wO+aBqRviHj7UvzGCVEU3dgTgvKTv7o80YGm03eILWXuhffHO7AlEp3Lr2D pyKNoiemMgzv47e5zfeXVM34NW4xFLF9wnYzRgO/BvMeLADAAYzbv1gFX3dD+Bpf8GZb gyDw== X-Forwarded-Encrypted: i=1; AJvYcCUiaSEqrbSXwkMXTLrNVtsSg31ZJGCXWRGmipiaxooXhPwFqNPDxDuuhE+Eqd/UNH6I4sKCSiD5g271s04=@vger.kernel.org X-Gm-Message-State: AOJu0YzkRft9NgjcyIA2J/h+eOMxRK07iPlhlS0iUpAi0tkF4JoSdYHr yjKrsdodrZpjqzZOD9jux8L9Shcqhlhes+5Duh+1A1qyOQPfN+ebjhq4 X-Gm-Gg: ASbGnctEgP3O4owZ3VVzxBCm/hosL3oPYa/xokuykZFi0bF+wonYCH9cm6A4PLH+B77 /njDvE1G8FMKA6mzMthhmIi+iplxqw/Wpg8nVMD9GcHkNfhGcEMZEfml+1ChqgT3aI/uaB5ij7F ptzGUtlp5UQHcd4NpMPjKnCTjej+Ibk4D3sS3bN6ZUwBrSHAV9cXh1I+LMCfRbDEVfHh3/c5wZs aQHmNo3H6ONiPzE9pcr0LWyfz9BU5WedWcN9nIaF4Uy/hPratrbzEvNVGOpRIyguGXYIMIhNdPn HCnf9NSkqfISAeB6pdYUC5+5qdIJorbqGw5gS7M9LDQQQKNdL9CEK6EnXX8OPLJ8uifJnrMS7NO gwuUjASlCvae5We4hSgq775PRw//4AEyR7rioeAydIKjEJ/yyQftL1msmroL4yoGT/yLuwQHDTx 9B3ck11e2CsXx8FIl6kPDcIwM3mpbDFO/8VQT7dUtLVJn3rg== X-Google-Smtp-Source: AGHT+IEuRYykMljnZYhL+TbH5FurVSKavUEug22jUuvZ3baInb7oeHFpVuOBsBNWV5IN8PKWIaLSRw== X-Received: by 2002:a17:903:1b2e:b0:26c:e270:6dad with SMTP id d9443c01a7336-297e57151ecmr21195745ad.60.1762589166317; Sat, 08 Nov 2025 00:06:06 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29651cc6595sm81710455ad.98.2025.11.08.00.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:05 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id B755E11388CD; Sat, 8 Nov 2025 17:06:03 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 04/13] x86/um: nommu: syscall handling Date: Sat, 8 Nov 2025 17:05:39 +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 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/asm/syscall.h | 6 ++ arch/x86/um/nommu/Makefile | 8 +++ arch/x86/um/nommu/do_syscall_64.c | 32 +++++++++ arch/x86/um/nommu/entry_64.S | 112 ++++++++++++++++++++++++++++++ arch/x86/um/nommu/syscalls.h | 16 +++++ 6 files changed, 178 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 f9ea75bf43ac..39693807755a 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -31,6 +31,10 @@ obj-y +=3D mem_64.o 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/asm/syscall.h b/arch/x86/um/asm/syscall.h index d6208d0fad51..bb4f6f011667 100644 --- a/arch/x86/um/asm/syscall.h +++ b/arch/x86/um/asm/syscall.h @@ -20,4 +20,10 @@ static inline int syscall_get_arch(struct task_struct *t= ask) #endif } =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 /* __UM_ASM_SYSCALL_H */ 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..292d7c578622 --- /dev/null +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -0,0 +1,32 @@ +// 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; + + if (likely(syscall < NR_syscalls)) { + unsigned long ret; + + ret =3D (*sys_call_table[syscall])(UPT_SYSCALL_ARG1(®s->regs), + UPT_SYSCALL_ARG2(®s->regs), + UPT_SYSCALL_ARG3(®s->regs), + UPT_SYSCALL_ARG4(®s->regs), + UPT_SYSCALL_ARG5(®s->regs), + UPT_SYSCALL_ARG6(®s->regs)); + PT_REGS_SET_SYSCALL_RETURN(regs, ret); + } + + PT_REGS_SYSCALL_RET(regs) =3D regs->regs.gp[HOST_AX]; + + /* handle tasks and signals at the end */ + 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..485c578aae64 --- /dev/null +++ b/arch/x86/um/nommu/entry_64.S @@ -0,0 +1,112 @@ +/* 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 + + jmp userspace + +END(__kernel_vsyscall) + +/* + * common userspace returning routine + * + * all procedures like syscalls, signal handlers, umh processes, will gate + * this routine to properly configure registers/stacks. + * + * void userspace(struct uml_pt_regs *regs) + */ +ENTRY(userspace) + + /* clear direction flag to meet ABI */ + cld + /* 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 %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(userspace) 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 --=20 2.43.0 From nobody Wed Dec 17 08:44:15 2025 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 216C72E541E for ; Sat, 8 Nov 2025 08:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589171; cv=none; b=txXA9cx3+Jrs83q0fR4sZcKmqTvR/BolfkKCkCd3SpZMiGkewW5y7QoqMwVE+aqKLsz5xnuj8/Cz5BfU+qX7xmK9niXO2skvmmYFyv7aUcc/DMFIorQlA34MPpmSfVK6nDEzLoehLiQoLI/6hWblaKD3t1+cYWbCWeQJqoSbKXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589171; c=relaxed/simple; bh=ApZCova8kpoHyvQowYMCMZfo2gH0ldio/mRio3HyRRc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b3CcRDBPN+IfcUZFwMfakuHa19snior+EtsmYgS1j1Rjb6/pCcWCvX0bJ7Y1PKq0Ahkz10G2ucG68S6ZmuWx3/SN6zbDm7sAy35UGqXMsD38BjcB++K8MkFDA+FU1N7jQBexbwE8rgL2OH/NvMKID/UOFoo1F2YsC7rsNJEdiTI= 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=fceT9Z9m; arc=none smtp.client-ip=209.85.216.48 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="fceT9Z9m" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-340c1c05feeso1286972a91.1 for ; Sat, 08 Nov 2025 00:06:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589168; x=1763193968; 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=SLnEdv1Aj+O6ghd8EMKGqBIoQpaMRjL7FrHMTz+k/js=; b=fceT9Z9mKj7WGEAFt4dogThUg+pb9CxiZvHWssA7DqMYb8k5MnvleELaW5PYfgoq8N geyw14kT0Y3h5ZSgoXqDIolqBjySl1cCi73qHAn/Hkqw9P4rjqwpkJZmmgLaFd53DsNH W4A2Dy4S6sorTTJkJ6SXooWiDeRkllZubNq31SbSX2zYgnOZ6cZ9erc5xmNfFFkFlN/V BnnAsif2rV4D+nyip/OUrgYOcQoSmLr4cfhnAvNUES5gJ513PDH18D5rUttqL+cBgPkB PuzT4h9CsVibFHJbOzMLFLXdXt5APi1R+EZheLyRWCx4Bcre3mI/Bcz1F1eXug81k28w gC0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589168; x=1763193968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SLnEdv1Aj+O6ghd8EMKGqBIoQpaMRjL7FrHMTz+k/js=; b=Kd5nMVzfoVz4/fhk9NluVb7OI5v1ov6R+A1WTVu5Zxa5MAGsIWfQdoDhMJx7a2Dwf4 ij30lt+wUvi2isCsnIUPspPduG8v44+LmslGii2SR3TNtcV+LxAFK2iDXx11YHY/uvDt l9kGd78T5lDcAvJRGLP4eurVrc3yH/8nhGbXtBa8vWucOq2ai2bk1NWtFY0YPf7sVLl0 wc3ZClTgl9IiHwuKWGYwh+RSIEIAuYS48Ng5D4LZFehEN97Y+t5drn1ub73ioViXuf+U fMAueqCUBh6qosqIqvAcvvQSq88ATmNVHeUa5UbjI4Die3Je04pPZ1TyEc++kM9Iria1 Hz0Q== X-Forwarded-Encrypted: i=1; AJvYcCVFgKlThSozVVgEszFlt3dnwKChF+yd7NMCBd+XxktUOlP2ax0NulyeTKTsM60Bg8SMNLkw19cO/58ZJwY=@vger.kernel.org X-Gm-Message-State: AOJu0YxCjvxtVIBBIL1HEwUCFo0K4JZhgntkKjBKawxmIOPEVNzDKWk9 kj3hoLYnZDmyLn/ib5h3wU8JSAAZoTqfDqTpoX4evlkqeFHwUnHhLsJxfKLaudNb X-Gm-Gg: ASbGncvPwRxfsiRp877aHjxLBNUqZDIqWq3uck20ZFU9IzD0DbhD1jeq2OCBPcJgKha uxc4PjU2MFyv0nxjeC1nKU99czvDcHXT8t6tueIU4MtrNT4L6T+SQcVOSfiEO+ienv/WXmWlEqp nNjU/lnpmQHYP88I2JlwaQqKVNQFim8GL8XIBZneFpQSERVF29SVVzUkHTaMJhnU/23q8YqzELc N+6R4FS/uAu2fCu9YmAXOU/qM+awZqKMNYHHp0i28UY7LFFoYAX9CfbJz6tMBz6e2VrTNdvx5R/ lDBBN0GAFqhDNWJMPZ8fi+iH/vpJGi50EML4xk10HHXKxkK+14Sk74j7iL7Lttwg8RRsxKm0bVH pq48ppfY9dfrF/OnWYrqFs0msE1N4F6yOuq3MDltpelazcRWcNMGZY8zArHbrlH7H6ubpJ+/18r Al661wwKUOVuo/Ve6Zv3jUzit3hsh77uky3WJH4bil2mhPrA== X-Google-Smtp-Source: AGHT+IF/0KZ5RiX7F5gJWW1n/1VeDv21BdI+XAZBghbXnkRhZxzi65ZsXJm5TsGevPqoLSCwHlvJAA== X-Received: by 2002:a17:90b:3f0b:b0:32e:a5ae:d00 with SMTP id 98e67ed59e1d1-3436cb9833fmr2369527a91.13.1762589168273; Sat, 08 Nov 2025 00:06:08 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-341a69b33c7sm11409199a91.18.2025.11.08.00.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:07 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id D220D11388CF; Sat, 8 Nov 2025 17:06:05 +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 v13 05/13] um: nommu: seccomp syscalls hook Date: Sat, 8 Nov 2025 17:05:40 +0900 Message-ID: <9e3438cf6d6c26a708c428267375b102b434d5d6.1762588860.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. It also renames existing static function, sigsys_handler(), in start_up.c to avoid name conflicts between them. 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/seccomp.c | 87 +++++++++++++++++++++++++++ arch/um/nommu/os-Linux/signal.c | 16 +++++ arch/um/os-Linux/signal.c | 8 +++ arch/um/os-Linux/start_up.c | 4 +- arch/x86/um/nommu/Makefile | 2 +- arch/x86/um/nommu/os-Linux/Makefile | 6 ++ arch/x86/um/nommu/os-Linux/mcontext.c | 15 +++++ arch/x86/um/shared/sysdep/mcontext.h | 4 ++ 13 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 arch/um/nommu/Makefile create mode 100644 arch/um/nommu/os-Linux/Makefile create mode 100644 arch/um/nommu/os-Linux/seccomp.c create mode 100644 arch/um/nommu/os-Linux/signal.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 38321188c04c..7798f16a4677 100644 --- a/arch/um/include/shared/kern_util.h +++ b/arch/um/include/shared/kern_util.h @@ -63,6 +63,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= *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 b26e94292fc1..5451f9b1f41e 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -356,4 +356,14 @@ static inline void os_local_ipi_enable(void) { } static inline void os_local_ipi_disable(void) { } #endif /* CONFIG_SMP */ =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 e2b24e1ecfa6..27c13423d9aa 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -423,6 +423,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..805e26ccf63b --- /dev/null +++ b/arch/um/nommu/os-Linux/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y :=3D seccomp.o 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/seccomp.c b/arch/um/nommu/os-Linux/secc= omp.c new file mode 100644 index 000000000000..d1cfa6e3d632 --- /dev/null +++ b/arch/um/nommu/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/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/signal.c b/arch/um/os-Linux/signal.c index 327fb3c52fc7..2f6795cd884c 100644 --- a/arch/um/os-Linux/signal.c +++ b/arch/um/os-Linux/signal.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "internal.h" =20 void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *, void *= mc) =3D { @@ -31,6 +32,7 @@ void (*sig_info[NSIG])(int, struct siginfo *, struct uml_= pt_regs *, void *mc) =3D [SIGSEGV] =3D segv_handler, [SIGIO] =3D sigio_handler, [SIGCHLD] =3D sigchld_handler, + [SIGSYS] =3D sigsys_handler, }; =20 static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc) @@ -182,6 +184,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); @@ -193,6 +200,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/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index 054ac03bbf5e..33e039d2c1bf 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c @@ -239,7 +239,7 @@ extern unsigned long *exec_fp_regs; =20 __initdata static struct stub_data *seccomp_test_stub_data; =20 -static void __init sigsys_handler(int sig, siginfo_t *info, void *p) +static void __init _sigsys_handler(int sig, siginfo_t *info, void *p) { ucontext_t *uc =3D p; =20 @@ -274,7 +274,7 @@ static int __init seccomp_helper(void *data) sizeof(seccomp_test_stub_data->sigstack)); =20 sa.sa_flags =3D SA_ONSTACK | SA_NODEFER | SA_SIGINFO; - sa.sa_sigaction =3D (void *) sigsys_handler; + sa.sa_sigaction =3D (void *) _sigsys_handler; sa.sa_restorer =3D NULL; if (sigaction(SIGSYS, &sa, NULL) < 0) exit(2); 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..b62a6195096f --- /dev/null +++ b/arch/x86/um/nommu/os-Linux/mcontext.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#define __FRAME_OFFSETS +#include +#include +#include + +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); + +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 6fe490cc5b98..9a0d6087f357 100644 --- a/arch/x86/um/shared/sysdep/mcontext.h +++ b/arch/x86/um/shared/sysdep/mcontext.h @@ -17,6 +17,10 @@ extern int get_stub_state(struct uml_pt_regs *regs, stru= ct stub_data *data, extern int set_stub_state(struct uml_pt_regs *regs, struct stub_data *data, int single_stepping); =20 +#ifndef CONFIG_MMU +extern void set_mc_sigsys_hook(mcontext_t *mc); +#endif + #ifdef __i386__ =20 #define GET_FAULTINFO_FROM_MC(fi, mc) \ --=20 2.43.0 From nobody Wed Dec 17 08:44:15 2025 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 670412E0405 for ; Sat, 8 Nov 2025 08:06:11 +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=1762589173; cv=none; b=YukbC3Ms0pNVF8FPBiNeDWk5RgqWH3N19CeXKZK+gF6WpwPD6o2Fk3nS0rtbYTwG4Nx29U9NOQPez/sOZuRaYyAHwTZBkT/bydFwx8iSbF4QTE4lLr6pysBFOXXviI66j51NmU/JI7fstFGoTEZZ85gY+UmGW9F1ZSYcEe9CzB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589173; c=relaxed/simple; bh=Xdgd9SzJQKPXpSd3h/YCws/19jIBtbhoHsT1rlMAAwM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sre4r5xzB2akwCJz7aD9F1MIJHEo5lBBPIdcHjvh6K4cyT6772BnSP/oqofdad/oJa/nYJ6pjK9ijqRZXqcPrYXp06bdRLqkYzCR77yzPv+jzZ56hekddMPy9AvlWP8ImxW2DpZOb76Ndfsg8Iem93FMLd2fgkebVL6FpAu8KA0= 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=JuPNK7jZ; 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="JuPNK7jZ" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7a4c202a30aso1235949b3a.2 for ; Sat, 08 Nov 2025 00:06:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589171; x=1763193971; 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=LBx1RAda5jRhU5+5MRbhR+8InixhRX8igq/pYh2YNko=; b=JuPNK7jZms4KducFyrcQsOxujdoJETgt1mQyx/kEGxmvVKhF3GKxKOqjwPLlZCqUhc wE3KXwya6lgT53sMVmVF1sY3PgULSFdrr78Pao5VCYnZHdKYPYB7GUFbGpdOtkyQqJhm XGmJ6YHXAbSCY/7/P5UgxrH+0vOTKJNG8fzdhds5PYSZkSNyRMeBXYS04fCcYAtPxQ6x 6Bmotiw41RlKYt58jRzHzsZwF1t0QA/+ma1OD5tr6eMPKXgaolj1suCtvqlyun3iq3Ur i5RFd6ng07nkE3SBJ3nMzA956XafI2OcRk0195BwPa9Mo31713LQvd3Mk0KCRSdIWf2M 2URg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589171; x=1763193971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LBx1RAda5jRhU5+5MRbhR+8InixhRX8igq/pYh2YNko=; b=Y8LlKr5rKC7D5mdylr4rtgtWvpgGsX24vKtox+1ckSuev4JRl12QKZfhOjDdWsjYA7 vMbXinWyxBbnLjsjZ53dvB4BpnE/hzlANAMfPlbinIja5F532pGjgVVEEJoyuNFz3G+H 03umAwo+yphx2nnVjVV5bkNoXMv8OCaiAVLSXY9+8HnCJdsIGxZAZdmAyJhWx+xc/Ys5 pAtOx0V6qmyJHHBi0b8zbhJ/RFFi+tTPaWkxnKROw6+MuDp8vIrNSoTJx5fDRs0L9wUG YXQY6Ow72wI8GrJvUwt+3xbtDwL3/Ea8/VpPc4jnais0AfCxCd7ZNsH5n22lfSICHfPm PVQw== X-Forwarded-Encrypted: i=1; AJvYcCXQLK6mK6jXSDCXRW5eMMTdFKirRTRT8nMxA4yZvAJRQ72JEdM6nSFzpcbPZXq7Qvzj1mRIgR4yofo4evc=@vger.kernel.org X-Gm-Message-State: AOJu0YxLcTpkb+ceEImFKAzNOw4q5DTdpa2+p5B5vLh0CDU3+g35JWMp Qvzl1SsZpu3iJSt1cb2gVcDYGPLGXtUKxuOibmwh57bnCGoOQ+8J1xqp X-Gm-Gg: ASbGncvgWzH7+R1nDICf06D/yJCpwNEksps6v9yWLKsKY66OfHK36Hu86eW6sbDo/ma 6QxsRn0ZNQTIERubOGBEig8KW5diXWpcJLVHKTKhHL4kAD5KC6/bSWqWqR+0anRhLCVM6/S9OeX Z00zjF+79wJVGB/Z5rIyRJpDfY4Zqots1NawVNdBzpmD3XrpSXAgjuZVX9M9VZgrIf5gmsyhFmT gp3q2lrKjIbCCLaKjNKU0qLk3t+7nMmfa+Fb03xCmSFUujGjsZpbbgPbTOwoy0HpUxmfwBqCA/R Of4+8//eERoLa3E7KOlAKjyJyeUYuQSUf1VC7f41hf78TPbet1QBASMcAS7YzdiF1GzTPcPvF+G LoihCWOYCpo14J+Ck6cmGEgdmv/Gsn4F4jCnGMTR6sGaT7JQMGmv2YlX1IhciW2P7Fd3/yM2BDg mOmYe1eUyyeT3+AOyZXt6axNi8hyEdlYsj+s1atfdjta/GhdawtX+/P+d3 X-Google-Smtp-Source: AGHT+IHzchLXWxzzDz1WxC3Dk4RM7G0kck5BQurVJPuk/UCkNNlsjtfs2t5XKr3BUU+NgfTwVrdmVA== X-Received: by 2002:a05:6a21:6d83:b0:34e:7bef:e81d with SMTP id adf61e73a8af0-353a13a4dd7mr2538481637.8.1762589170593; Sat, 08 Nov 2025 00:06:10 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ba8ffe3616fsm7280302a12.19.2025.11.08.00.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:09 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id EE07211388D1; Sat, 8 Nov 2025 17:06:07 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 06/13] x86/um: nommu: process/thread handling Date: Sat, 8 Nov 2025 17:05:41 +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" 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/x86/um/Makefile | 3 +- arch/x86/um/nommu/Makefile | 2 +- arch/x86/um/nommu/entry_64.S | 2 ++ arch/x86/um/nommu/syscalls.h | 2 ++ arch/x86/um/nommu/syscalls_64.c | 50 ++++++++++++++++++++++++++++ 6 files changed, 58 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 62e9916078ec..5aa38fe6b2fb 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/x86/um/Makefile b/arch/x86/um/Makefile index 39693807755a..98dc57afff83 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -26,7 +26,8 @@ subarch-y +=3D ../kernel/sys_ia32.o =20 else =20 -obj-y +=3D mem_64.o syscalls_64.o vdso/ +obj-y +=3D mem_64.o 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 485c578aae64..a58922fc81e5 100644 --- a/arch/x86/um/nommu/entry_64.S +++ b/arch/x86/um/nommu/entry_64.S @@ -86,6 +86,8 @@ END(__kernel_vsyscall) */ ENTRY(userspace) =20 + /* set stack and pt_regs to the current task */ + call arch_set_stack_to_current /* clear direction flag to meet ABI */ cld /* align the stack for x86_64 ABI */ diff --git a/arch/x86/um/nommu/syscalls.h b/arch/x86/um/nommu/syscalls.h index a2433756b1fc..ce16bf8abd59 100644 --- a/arch/x86/um/nommu/syscalls.h +++ b/arch/x86/um/nommu/syscalls.h @@ -13,4 +13,6 @@ extern long current_top_of_stack; extern long current_ptregs; =20 +void arch_set_stack_to_current(void); + #endif 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..d56027ebc651 --- /dev/null +++ b/arch/x86/um/nommu/syscalls_64.c @@ -0,0 +1,50 @@ +// 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_set_stack_to_current(void) +{ + current_top_of_stack =3D task_top_of_stack(current); + current_ptregs =3D (long)task_pt_regs(current); +} + +void arch_switch_to(struct task_struct *to) +{ + /* + * In !CONFIG_MMU, it doesn't ptrace thus, + * The FS_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 Wed Dec 17 08:44:15 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 0C654288C22 for ; Sat, 8 Nov 2025 08:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589175; cv=none; b=usq86QaCtcc7qvn3wpzpHrqHy4/0FDmB/cKkm8tU81+w1KlDUGh8m7u4mBpDL2wX3wBYC1F8N8VPgv1wXiAS6xFsOf4p/KgVfV6tkw2HS18Tn2xJpnvpHKsBej//4pcpcyBK96soFtDRBCJL9tm8x2RB+nGfJdSiPBOFdSeiBRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589175; c=relaxed/simple; bh=w/P0WV8/06U9fcziuDHn0Wwv3zpkumouszCtz0x7ivA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iGHAou4zc15hV4dRPf4PVtUUzCU979Vs2Y6mqpG/CzKRP6rv8yzPfBiRqWcc+1ohTyuCaD8nOOdhsRolFE3fiLOlj0UD/SWmqdXt0NR3gwQvjASnAYnVhQWWwcYxOqgYWhmD/mX2kaJ7582oTcbo/xFvtRkRORtxyttn/TZv+aE= 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=Czr+DYGU; arc=none smtp.client-ip=209.85.214.176 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="Czr+DYGU" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-294df925292so16314305ad.1 for ; Sat, 08 Nov 2025 00:06:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589173; x=1763193973; 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=SVM2G4FP/w8QD00uu0HK9wDNN1nmcST3P93SXeGJtYY=; b=Czr+DYGUtgCkR3/FHGIUfpRL8Vz2eH6QCIIi3OvCVhReh0ULCvHAZw833RSUJbgZ8j ll73ZvVNAjm0LErOtz0uadEM3j3NUMyJ7qtSGGnpCghbagwOK6FYsUztfUshfJwdhrm9 TM0C3hWHDa6oUwIQdTLxXm/z2kqzoYJMVRSGFUS98nbfvqFtATtaF9L2PrJdGN8+pvSu XS5D6EtKv5dDyJwCKJNABtVipCXgfYAw9QKMsj1WBMl/2V4eSMAM8RkmRiBzIwl9hLjI htC8HHzVbpntx/m/V+7Jgn88Qn4zTtEZvcGckiFsVfkc4U0ppExADhLNObWDj/jNBQNQ cT6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589173; x=1763193973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SVM2G4FP/w8QD00uu0HK9wDNN1nmcST3P93SXeGJtYY=; b=pErXONA57w460vaR6nNlpe+c/cMkrYiLZsz3pADXFtcZCOotCyMm6gGiJbPfss4ulc HrkIMAVrxV88BBplfQUA2wUiDhEmioHb0xTg30UPKhcvZqSMv6qS3/A+ya8LwVRIAkb8 ygkpZZl1uhWkxq8PuUZIwVTNyFXkRuqOHuvaWufLPJczks0a3oyQ1dCn7pxzyYmYs5k5 AbcBP2im+MBPh7AchXUuD28m//2ZzHQJ85KIxG2mNChHhFLuUDibgB9jIktBH5U/Nz75 jJCDV54JUz2ob9iKOSQ6UdLGmnHeQKjbCIkyjDlAXWiQU2au9yOx6wk01sxeVq8ZJbCE YFkQ== X-Forwarded-Encrypted: i=1; AJvYcCW0f2H/9YjWHumJ78sODJsaSFYyS2LFVcANnLT/TkuMrJtzagOmfmMcybLslnEANrZyftmu6sc7uN60Phg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5RsB4oNHGhL4yR1dIdJ8fEXHjWBgp6D9JbPzFENUKtR/Hcpge FfhpQ5qQl1WCdmZWzCx/X7tdfz12j+uSgSbnWsx9Ym6I5HSwGeF3SEAW X-Gm-Gg: ASbGncvcY6H753C1RNPvVaIWhkVcq5swifTTCo24zAaJ8E1f1qMQ1BROcekTeeKyhUK UyHUxUFCarQSQ1CgikQhtpI6scFnIwd/G8QpR0i9srrz6cnc/yi+xVkcw/aKASRZD4B6wi2B4YK xuipoSD/KdHjOy6bLupZJdV8cPB3R7f7NwuLPqvrTzVR+WymppU3QoVDn9I6mPKkjkhZCWGTc4A pvmd215qrg0mkvM7dGdRnI1IKbJMnYKqYUO0wnpJ1CAdQx6OBwRMB8ZaDOkT6n/5jZb+mlu/nyR SL62jV6BQu+DnFGiFyyWcWnGIjkOCw28TY4Ak74IBq/iKMCP03MHmdOJGfuTMTnxVXixfyXvE2B VLIZbZlia6hqaOPSiG9Wddpi3lPsIAp/Il7iQv6z8emh+nsRsWWC7EUPWxYy7qjhPuFYdIzIJhT rpPThyDFzLLXS0whAvVKAInjjGFS6rF5VI2PuZEgSX42XXtC+WE78zbdD1 X-Google-Smtp-Source: AGHT+IGcrMW5bAkx8lKAGWdpQHmJ3n1S/JnVjYsLNXBmw+OKie6VvCjaORE4fhcWJKknP0Cu7jRe/w== X-Received: by 2002:a17:902:e947:b0:267:a5df:9b07 with SMTP id d9443c01a7336-297e53e7303mr23827725ad.12.1762589173061; Sat, 08 Nov 2025 00:06:13 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29651ccc19asm81307265ad.104.2025.11.08.00.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:12 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 8272C11388D3; Sat, 8 Nov 2025 17:06:10 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 07/13] um: nommu: configure fs register on host syscall invocation Date: Sat, 8 Nov 2025 17:05:42 +0900 Message-ID: <5b4fab636ab8cbd1db025a0561fe9993990fc869.1762588860.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 | 21 +++++++++ arch/x86/um/nommu/do_syscall_64.c | 37 ++++++++++++++++ arch/x86/um/nommu/syscalls_64.c | 71 +++++++++++++++++++++++++++++++ 5 files changed, 141 insertions(+) diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 5451f9b1f41e..0ac87507e05e 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -189,6 +189,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 ddb5258d7720..dacf63ac33c8 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -18,6 +18,7 @@ #include #include #include +#include /* For SYS_xxx definitions */ #include #include #include @@ -179,6 +180,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 33e039d2c1bf..c0afe5d8b559 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -37,6 +39,8 @@ #include #include "internal.h" =20 +int host_has_fsgsbase; + static void ptrace_child(void) { int ret; @@ -460,6 +464,20 @@ __uml_setup("seccomp=3D", uml_seccomp_config, " This is insecure and should only be used with a trusted userspace\n\n" ); =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"); + } +} + void __init os_early_checks(void) { int pid; @@ -488,6 +506,9 @@ void __init os_early_checks(void) using_seccomp =3D 0; check_ptrace(); =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 292d7c578622..9bc630995df9 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; @@ -13,6 +41,9 @@ __visible void do_syscall_64(struct pt_regs *regs) syscall =3D PT_SYSCALL_NR(regs->regs.gp); UPT_SYSCALL_NR(®s->regs) =3D 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)) { unsigned long ret; =20 @@ -29,4 +60,10 @@ __visible void do_syscall_64(struct pt_regs *regs) =20 /* handle tasks and signals at the end */ 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 d56027ebc651..19d23686fc5b 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_set_stack_to_current(void) { current_top_of_stack =3D task_top_of_stack(current); @@ -48,3 +110,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 Wed Dec 17 08:44:15 2025 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 D07362E7F03 for ; Sat, 8 Nov 2025 08:06:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589177; cv=none; b=kJOAQLz+xlW2xNqvtldsK/n7b5rRGft590aD2B+cmB83pppNAh/iLtpCYjbjPKqo/TtJLUgCP+hSj0AghXubJPNuJyWxmYe+VhABqJSKjiO1hxX6SjfR/Srq/2wt2SLDjwSQEVqdYUKvhaI+FkJl7Z7O0y4F5mNbWfK3G/fo3w8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589177; c=relaxed/simple; bh=xTw1fZj9TABghspblzMyZh7aJYlpz7LOhXxI2BNDWxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TP8rmFwl3ad/BPORs7okKip3UU0Mt1RgG0bPDyQQSYU1StN/S/xa66XdRXMP5JgOoafr4JXCMvt9aRvz8zqjjdnmeqmcJwup8Jcnj3GM2UDQVCWxG0AQe1ub046+hg2VZNkC2jPWeeDJsbXSZSG3Wt6Ci5C6Wci6WbVW15F0j68= 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=EbT7lvjz; arc=none smtp.client-ip=209.85.210.182 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="EbT7lvjz" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-7af6a6f20easo1249143b3a.0 for ; Sat, 08 Nov 2025 00:06:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589175; x=1763193975; 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=KXlvIxBTzUi2fvQwFF5f1ABJZvc5EYR8EZzXkNvyLME=; b=EbT7lvjzKGBHqo1JeOk9kDmxmgdHxlF0uNv3qjutwAXpW1lf/yEZpISX1uYKUfvsim aX9J0OsVtFzzgnA9YtNb9r493TBeUtLMIBUwVZKmBRXjEITSbB06Bu9uoVQGs7ThOMNZ akoMTe0/CitClDLTPhkv/qDq2olDFNXUq7JQzR1pH8zT+8kyNpbol1raJNNG0FboztBp 2fDDPlXlorf5uwaAsueYahrxp+Abc84fEzawvzSP4JR9S1rcShGl4+aOeDbxvnHZjB8R GZfo/zX5Vq7xDXOOurEbWwtOuK4nbTHXdsFGbBpHatee4szE/EvQB/IzHAUuY8thKD/g Iyuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589175; x=1763193975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=KXlvIxBTzUi2fvQwFF5f1ABJZvc5EYR8EZzXkNvyLME=; b=VZwfgaDEWglhmKh4nxf5lyPPXJ35P3VzaKDhQnHleelm+D5103PAB3llGFrYotlbWs vya9yooXDKx3fF7xAsICmfE1XLRq3ASjvtSfxXcMM2Vsg91S90GPm8iRYGt8ShDYx5sN 7/3LwacmlFsEb4tx9ieIb8V1/NKstMiOOAge744+K+ptLDiGuRYNHZZcUu6xXeKOFH/6 okp7Jt9Ed8IDGMKMii6IwUFp4HTWZKJz6xg6nBbxvnr0yQfk5mtukYPjwhA1TrxXqJXS 5sz2cObU/o1NIYD0wqlQlWomDrjC0tnd2wY+AYZ3rHWp2jjl0qrS4zzQQQQs3tF24Y85 1Vpg== X-Forwarded-Encrypted: i=1; AJvYcCWXcQpBEwoEzj/tRmIz2YQl5ty11t2pxu3aUVar+8FQtv9X9SDwQNQcCAsntvlRojm965naNJ/U5XZjk+w=@vger.kernel.org X-Gm-Message-State: AOJu0YyXH5pa9F2vSD7RFR64K9AzayWXvSPJAGtOIPc2VNJ39A11mePr yKeww36Q1k34UmpkrTlQVJM81UE+pwjWRFvLT965CGxbVBQRn/XovO58 X-Gm-Gg: ASbGncviiEqgf7FujkUti3R6PsyDijgupVFa1nkvPiegKrJVk86qMCY0do9/D2Gj7UX 14cc57YaDeOanU/QWIQkHVR7xh5cwcv6PBgj8MO9nW0yA+sTl5DxqmoYsGA2NFqX/3q3YHI7wD3 2sFK2jK5Swuv7fKoD+huCuMgS5UAISgkRsp2wK6O5frePfLhx1C0a9Qo4TpCD/UE0AprHV7SBId XernF5GgnqecmDHDgdYYUYnBgoydMKTWydUYdoMYuC8rUtGBA8c6C5ecOG248xOJDUDV5FA0q6W N/V0pUy82uxGuqMusfxHLaoIq1e8nU06vh2VzbdBlUX6I62B9hsew2i8GhFsBqJTF1OYk3sczWC xtbAA3xFfMU5+J+dDHBx991GDqq/MyRTyW4T0TZmVla4WZXAtLHy43nWjGHrgXS99WZM1iUkFkO kk/RBQoXOkDBk7w8pHjANySNqGv7cFfeeq/+5GdheJezb+Lw== X-Google-Smtp-Source: AGHT+IGD48yU+7r6eJf4t73UQMq9PCzXek9Pp9f1XAQMtlPt+4CKZ0imYX/Cbn2ZTgd9N+RvP0eTWA== X-Received: by 2002:a05:6a00:4605:b0:7aa:81fc:a83a with SMTP id d2e1a72fcca58-7b225acd5b0mr2845940b3a.6.1762589175204; Sat, 08 Nov 2025 00:06:15 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b0c9632e22sm5333782b3a.8.2025.11.08.00.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:14 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id BE10811388D5; Sat, 8 Nov 2025 17:06:12 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 08/13] x86/um/vdso: nommu: vdso memory update Date: Sat, 8 Nov 2025 17:05:43 +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" 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 51a2b9f2eca9..0799b3fe7521 100644 --- a/arch/x86/um/vdso/vma.c +++ b/arch/x86/um/vdso/vma.c @@ -9,6 +9,7 @@ #include #include #include +#include =20 unsigned long um_vdso_addr; static struct page *um_vdso; @@ -20,18 +21,29 @@ 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) panic("Cannot allocate vdso\n"); =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; } 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; @@ -53,3 +65,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 Wed Dec 17 08:44:15 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 448002E1EEE for ; Sat, 8 Nov 2025 08:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589180; cv=none; b=CIXnwdMEuSo0nk0fEgXclbUBdYpQJFn6JvyHHGwfkShpQtIjqEQGvSv0nAiyZq6lJQASCeCQRS4olNvduFeDXMj+4I15nEvJfR12eOHuOU6Mz9jeVKkkt1zPIIYk9RsCkk7ATVcFAF+V1V9k8YXVrKhrT4oeWlpgNgqa/7S4b6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589180; c=relaxed/simple; bh=Q1RsL2/EtjIgu5QYIPwEJ1zosyelA3KCSVkAQjDY+RA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I9fxg/vM+m+5O5nK1hDGIF6WQ2WsLUQf9eVbb+RFAtfeUYylsINYyEnChMcUSVlhSom5NtK9XYagFu8ukE0Wj/inPIuNWEDgC/stkpIjU27QLg8HdhEXm1RfUqFu4F2TT8RwOEXolhZp2MRgLKi0zJfSNJ7vgUd7W7jLxkaoKG8= 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=SGKGPkMX; arc=none smtp.client-ip=209.85.210.170 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="SGKGPkMX" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7b22ffa2a88so283129b3a.1 for ; Sat, 08 Nov 2025 00:06:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589177; x=1763193977; 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=sZpI4L1Kh98JdhM/QsHv9mwFGGWJGOR2fxfWgHIsbW8=; b=SGKGPkMXwZDm7JCcBQyqbjg05yRCY/k2OLab9JtFp1Ww+jZLYBIALXpzaralP2/fhS Evj5/kD4Ugawr0y06JDCshyV/bWH9YB2jFaEY5ASOfteec+gwzBD6OOqLVGddpnmw/LW vIW5yHWZ2irDzK+Murj5X4fxidu+6R7u42tgaV0FKLAAZ0nNw9Z/nclBC1fAESRFF2p7 gffTCWxzXbX+63ocGYCGLpUK+Z+kVBOUpgMMu++P023YimYCuvrJ6fSwl2y3hfNuAuiw WBR9D02Z9iRukX1rkgTjsg9Tdk/tm3JwJByP4dvT34ZP8uDH7hoZKgqIioK1IuYod0JJ 7OUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589177; x=1763193977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=sZpI4L1Kh98JdhM/QsHv9mwFGGWJGOR2fxfWgHIsbW8=; b=YUskaAzbG4FsudddV8W135+CEn8SlgAyoz4EM9lWBmF/fKpt7XCB3kwEVzRXV2tdAB VsQdvuivddama1xF3X664XyIHBjdmf7AFwqPoc5+vEQEX1s95uIB4dNlz6amwangbK/R RIli8sryYZ7YZ8E/JpsYDc4l0H70aVocnsiQ+qTn/HFoxywUG7//CnXyYHZbvtS7lNuE lCrB4lAk2CQJXZ4pyfqIbaW7Yu66Kt11uoDgX/F5T94ul4xh6cbcewd5cl62H3c2jPjJ wuretQ0Hc7HbFogxrQE+K0WCLGrtLtO4DXeHsEkA3Y7WC8mcLKI61abqQbRvXu70A9gy LZlA== X-Forwarded-Encrypted: i=1; AJvYcCU5w+cGpWM722KS7nAJQbLdJvcE4qXNR2JgUxydYp9aIebMv0r50c3QLgw/WqAfO6v58p/RX56GO01h7Mc=@vger.kernel.org X-Gm-Message-State: AOJu0Ywt49ja77eo9HKyoOyN/8XOu1NGt96uvspfjW4W6ae6jXLWyMpQ rOIYjZ68/FPNgOEdGokDj8SbA4lsTOf3w40SF4JzAdAggM7MZADI6lzV X-Gm-Gg: ASbGnctR/ywAZOdbA7pcsJhwp0Wc9wrQTJywJyG/4VI4lLVHk9hn61qJPUfexvqBoVK zO2nc5WBrQPN6w1GO+2fyPwXsltE2izAnbkPB/F9mf0tklt0QOjmS1jkguX3K/7DFrIVu/j8Fh8 7v0c13rZn2W7zJBzxAL3ZbDf/V5j1dG00Lc+XE2yAl0XOF6roC2Qy1Nq4zIa//qhOiqot3J8U3K 5bvbeWrbsvYhTUqZHfu9dMBJEhZNWeYLLkV6Y/LDiZ9w3VMCB+J5ACvlZc+RwAHQRf2EzXW/FcG 5NCp/garBd1V8JhZns3ODXK/N/HjFALq1pJ2b03Stax7eDMHro3KRNYHOTNVVNu7XSamY53Gt5y r5trb0mv6BvIxhMGN67v7ervIJ+iZM4NhL91U+yh+wR/MWpaWSnC9W7t4HooBwsceBHAb3vz+c0 Mh6B9MNnJm9qZYUBzlFJfaGnIyPhQQJxzfIrkxJWAJqVnmuKPatH7iGL/Q X-Google-Smtp-Source: AGHT+IEtQahKb/xhxpS9blrirl5D/G2IB7a8vh9pAl760xoGpH+7uMEuvrcbi80xszZ6UIWdzZ2HYQ== X-Received: by 2002:a05:6a20:9144:b0:350:fa56:3f45 with SMTP id adf61e73a8af0-353a335664dmr2653669637.35.1762589177334; Sat, 08 Nov 2025 00:06:17 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ba9024e6e17sm7053523a12.34.2025.11.08.00.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:16 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id EB81211388D7; Sat, 8 Nov 2025 17:06:14 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 09/13] x86/um: nommu: signal handling Date: Sat, 8 Nov 2025 17:05:44 +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 | 8 + arch/um/nommu/trap.c | 201 ++++++++++++++++++++++++++ arch/um/os-Linux/signal.c | 3 +- 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 +- 9 files changed, 235 insertions(+), 3 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 7798f16a4677..46c8d6336ca1 100644 --- a/arch/um/include/shared/kern_util.h +++ b/arch/um/include/shared/kern_util.h @@ -70,4 +70,8 @@ void um_idle_sleep(void); =20 void kasan_map_memory(void *start, size_t len); =20 +#ifndef CONFIG_MMU +extern void nommu_relay_signal(void *ptr); +#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..6febb178dcda 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,10 @@ void sigsys_handler(int sig, struct siginfo *si, /* hook syscall via SIGSYS */ set_mc_sigsys_hook(mc); } + +void nommu_relay_signal(void *ptr) +{ + mcontext_t *mc =3D (mcontext_t *) ptr; + + set_mc_relay_signal(mc); +} diff --git a/arch/um/nommu/trap.c b/arch/um/nommu/trap.c new file mode 100644 index 000000000000..430297517455 --- /dev/null +++ b/arch/um/nommu/trap.c @@ -0,0 +1,201 @@ +// 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 */ + relay_signal(sig, unused_si, regs, 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; + + /* !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)) { + 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); + } + /* if is_user=3D=3D1, set return to userspace sig handler to relay signal= */ + nommu_relay_signal(mc); + + 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/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c index 2f6795cd884c..28754f56c42b 100644 --- a/arch/um/os-Linux/signal.c +++ b/arch/um/os-Linux/signal.c @@ -41,9 +41,10 @@ static void sig_handler_common(int sig, struct siginfo *= si, mcontext_t *mc) int save_errno =3D errno; =20 r.is_user =3D 0; + if (mc) + get_regs_from_mc(&r, mc); if (sig =3D=3D SIGSEGV) { /* For segfaults, we want the data from the sigcontext. */ - get_regs_from_mc(&r, mc); GET_FAULTINFO_FROM_MC(r.faultinfo, mc); } =20 diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_sysca= ll_64.c index 9bc630995df9..cf5a347ee9b1 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -44,6 +44,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)) { unsigned long ret; =20 @@ -61,6 +64,9 @@ __visible void do_syscall_64(struct pt_regs *regs) /* handle tasks and signals at the end */ 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 b62a6195096f..afa20f1e235a 100644 --- a/arch/x86/um/nommu/os-Linux/mcontext.c +++ b/arch/x86/um/nommu/os-Linux/mcontext.c @@ -4,10 +4,21 @@ #include #include #include +#include +#include "../syscalls.h" =20 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); =20 +void set_mc_relay_signal(mcontext_t *mc) +{ + /* configure stack and userspace returning routine as + * instruction pointer + */ + mc->gregs[REG_RSP] =3D (unsigned long) current_top_of_stack; + mc->gregs[REG_RIP] =3D (unsigned long) userspace; +} + 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 9a0d6087f357..82a5f38b350f 100644 --- a/arch/x86/um/shared/sysdep/mcontext.h +++ b/arch/x86/um/shared/sysdep/mcontext.h @@ -19,6 +19,7 @@ extern int set_stub_state(struct uml_pt_regs *regs, struc= t stub_data *data, =20 #ifndef CONFIG_MMU extern void set_mc_sigsys_hook(mcontext_t *mc); +extern void set_mc_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 572ea2d79131..6ed6bb1ca50e 100644 --- a/arch/x86/um/shared/sysdep/ptrace.h +++ b/arch/x86/um/shared/sysdep/ptrace.h @@ -53,7 +53,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 Wed Dec 17 08:44:15 2025 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 68EC72E92D6 for ; Sat, 8 Nov 2025 08:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589181; cv=none; b=LZEsC93bQdWPjiSpgcNwrn8Xt+rwC3i/WIwZ7kojoGDssbtbEcK1WbzLVFUu2MsWJZ4Zx6dLK1AJGhom8p8LfvAa3aS088b75P3xVo7f07Maz/xVYowK//4dEcS/bMhZ5HgILgOCGeoqD+ksW//2M3CW/sTGtp1eESfIOnOvC1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589181; c=relaxed/simple; bh=cP8tVJMzsmQcslbRgyEI/3kjgKDzqbQZXJLwSVZ1W2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SRYDCidj7u+DMJBqFeR7hXzwfxixokxys7fdK0Ro3uq/B62ji9utFPDu7WJKNScPpsW9iHFMbqlZCRIzZeNL+OTqF4Z3QYDCYbO6ZX/ZK0i0Q6ohao5Q51q3kzlpM2bN+9plWFlCXaGTs9BeIVEg9gzfgswr10oN5sxO4bgL8yY= 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=EjbkXCjv; arc=none smtp.client-ip=209.85.210.182 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="EjbkXCjv" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-794e300e20dso983041b3a.1 for ; Sat, 08 Nov 2025 00:06:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589179; x=1763193979; 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=9nqBnkNS4GHBgTUiwDcxL24xHY+Q8FfpyTOYW+ItBnc=; b=EjbkXCjv35/8ivMZecbKaYJ325YZOnBX6ODeRI7DcdjwPt9vwg1sydQhSaWu1SgvRf 6xJ5jU3L4iMXg+Mt93z1pa4OzCO1eEp0QHWhWNcFXzRO4fbM22uC70b+2tPz2we/ZRp9 XGftNxOM3NExBQ3/r07OOk6asvJNOIBCj/asHdKuRdNwrx2emBPThfkqzAF0ExkEdYuZ JZr+2e7Vch6S2t//eapm2XrExT1Xibv3EaToGercfVt3nl3ytUDR5KInrE/mJE9nEyJJ DzC3w0YN7QS4yr7YfeqEN3uYi8IkVATqTlfDB2crdUcGzusuYyO7zg7AolaWqqxQ7lkT BcQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589179; x=1763193979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9nqBnkNS4GHBgTUiwDcxL24xHY+Q8FfpyTOYW+ItBnc=; b=uXYhkDtwpWV+yWcbXoukwAEIGvBfeyjgYIdwNh2LCY5LWTkT3lA9hSBg7NLAlbj84j lqozIYPRyDggdxnTFalVCF0Bbccgc0Cg2rNEsHYba9TpjRCsLf1mREjdMriVHhT1luYl aVnflw6cEa7K2H3s9Ma2Tr08v0uAEl3ordNLjntE3CoOpXorEqXLKfhqCVg8EYVprP+O ySLGRYBJoQaLkdKAn1wFQR40BKy2gYqf4a1fSyBinKnLDqDv4w2HrEXSmn2VVgo2rD7U 7yE0nJpwQzEObEuJd6pwqVl53+9rZLTslYTPxzBS041X2sb/df3iCUtOifH+oyQSO8JX v8uQ== X-Forwarded-Encrypted: i=1; AJvYcCWJk2uK4W85k4DSFjqrNX29QqN0NTuhycQYBFW5d5Cw1XPDUOodkGNTaPYMWXMD+Lo3/ukWyQxm0lj468s=@vger.kernel.org X-Gm-Message-State: AOJu0Yz05rnGhtSzd5wrCze8dVT2O/v8VRoUjgeBmjofXXNzJXLnSNWw AULVOPMRdX7sJwpfFuIbkN7tgYzfu4PnnnOamZH6lnJscKIHK521rs7O X-Gm-Gg: ASbGncuZfZ2uG1DSZ+dMS51cL2xXujmD9AK7nybhtexsNscupAFFUr4FttRVsWfENhl ldOiOKs5gCOxzkIZa9eLA1/r6QivKCmxFw51f/BdXPhRkNsW21JwKPiMLJv30+axSHqW3STMVt+ hA7NxW5q4/DTXx+CU554NQp8jodrjDG+C2hf6m2Ttb8CxLc2/impBrCiq2EXa2nPz2BVU8DC71j Td+4BuXLDnFZT6tNh6ZhprXF3t4FiNQ3sdOxoJNNyT/ZdIY7XFxuBc0skirpWHYBxIkPuaSjkNt lsnj41e9sWxTqY2MRUNt6j95t8U40R7CNYLbghntJuqPFncGku75leIX4kBlC55mKed1KDNpJ3S paOHnH/6r/SRpOUgdKPB6knlmchu4CnJyiPTsCxe/+is+362TuDoYDLkG551tJsliwPmkPVwyjz 8Ws8tvKH+lVVP5V/KOOy2vBR/zdeI8VtvuLOaErbQ0uiy9OoRnZmglxhP4 X-Google-Smtp-Source: AGHT+IEeLxoMDyJQgdBR8WYJmHiLhZ7pAXN7oI3a/DfOUHZJDQcbCb7YzFoFxJg3hJbK1bLn0MBfQg== X-Received: by 2002:a05:6a20:a10a:b0:351:e1bc:e8cc with SMTP id adf61e73a8af0-352b5c009d0mr6591481637.5.1762589179593; Sat, 08 Nov 2025 00:06:19 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ba8f8c880c5sm7230587a12.6.2025.11.08.00.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:18 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 346A711388D9; Sat, 8 Nov 2025 17:06:17 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 10/13] um: change machine name for uname output Date: Sat, 8 Nov 2025 17:05:45 +0900 Message-ID: <7cfc1ecdcb8fe15edd92d3b1539994e28f3b6d5a.1762588860.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 5371c9a1b11e..9bc8fc149514 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -153,6 +153,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 e3ad71a0d13c..5fb26f5dfcb6 100644 --- a/arch/um/os-Linux/util.c +++ b/arch/um/os-Linux/util.c @@ -64,7 +64,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 Wed Dec 17 08:44:15 2025 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 BF6F72E9ECA for ; Sat, 8 Nov 2025 08:06:21 +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=1762589184; cv=none; b=uEuehD1LnVnUVDipDbVWuZtwEBSclsaBnuLBLMh7QYzLKQ4+5Klhzgd1tAFhH/Uy9Hq6rWQsfTb5RpyJjiHBOaCwtD/fDWfD0rpYNaluNagYFHyjEZxMcQb2DMx79KGSmqd3bXbwqVvtplMyprxNRQYBLb1CDhhx60mc/ljAFJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589184; c=relaxed/simple; bh=pb+afI/6/X6X9fMm8RSxMg3KNjvn7Kd3MLf/HKmZNFA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=thkJzP70wzElzGB9O1LS/a0KdTrlXh8+70C3lYr6BwhAe403K3PjXp8l+xPx970COYt0+Ugw0mcujXxjXVewbam1rxa3U58h//arMvmc6OuzqAh3rOL5wRdJwErFvtTtry+swumXxWuia0dJV98JG1KtGQW5FRiNzYPqaxWWHAc= 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=Oqvp9T0H; 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="Oqvp9T0H" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7afd7789ccdso1458378b3a.2 for ; Sat, 08 Nov 2025 00:06:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589181; x=1763193981; 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=uu/tPbxU9/ARLStujrsMBWUmhOTcbpkoe1nFm3w3B10=; b=Oqvp9T0HSi4Lx5lq1wOnUdKfO/ouZUnBjhsC/c2dHImhqu3wl8NXtFClbwszW76oOS vtGq1o/pQ0uQaVtVFl4ncrt7ePIqFuCw+ACmplOxEJ74seCta/udpTaZcpjg0VZWP8Lh lfyOkFEVQtuNitSA1Lkfhb7p/ExEM5MR3Cyi6aOtlgwdFUFMHF2Q0ObZWPxq6yoIHwH+ Hp4RVhHT7gPd0W3hkEOQTMfzNHO1k+lrZloKv0+pVi1rAN3lVWdusfudDXERc/PEZUVt 96Se8y0LqCxBhehIChd7NGUYim6QcuOQTmSsz4i7qMFBPlGIriGQDNbTILMjvd27B6mg fQcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589181; x=1763193981; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uu/tPbxU9/ARLStujrsMBWUmhOTcbpkoe1nFm3w3B10=; b=i4lgMZnlAL+/f3H0ebyLEhuxrZQxu6sllKrPFwbZtVJyW5WmLRJZHJRsHuNfmfReCT RW+kFsZTtDbMGTXNUXy3GWtc3v14baI6imofaBNkZADVnZGRCpPkbvAk/Fr80zEcXsOx QOkCWeT14TyXmeySHlfXSihijhGoOHY/irvpF9s6H9uYWm2sLMgiYkf4Fm2TNuzTGvkq rIS7zV2EUcTWu8oQevXePKRZDaoPKYOuxoWr8aK4ACiqvaBD87a2dwYv8oVRLoIWCMIA DgwdEsBEjJ4fSedK3k3RhaFAizGLbQ/TuPfPzatGS0oHHCNEgXMqTeMGSE1IXYvNmz0Z A9rQ== X-Forwarded-Encrypted: i=1; AJvYcCUDN+ilYOIPdxFwGSgdsNvRnfW+af7VM8MF54tXBWgdrd0uau0Ta4LDGndcq7Xjp7izZ3/w3L4wrPXp92s=@vger.kernel.org X-Gm-Message-State: AOJu0Yzx3XAhjlyjO8ckTi/k6fabZJ0LG1/4On/gAysuquPJX/Z4eBdi l5Oh7TssAAmIsFiudw5tTfUOGc2lYZfNSQaSTlyUC1w99wYLCXnJK6ca X-Gm-Gg: ASbGncuQ0/L29AZr0iPFX26JBBDNRnC2QV84s/0JOD3zKjhlNcgdhp8Ku0xUS0XOL9v mR8m2/tp2Wn69kfzchHO10uIP7Sij8RDRSqt36VcXXvM3D+5LS8nkJGAg8DUBvl3jBRiBibBpdj 2wzm3Ww9y9s64rnVmvF7yHeNLXzA7XLRdikMX4Bz5AxD+i2op4geYHG+ev0OP7n4ToM5UBJKhyN frOhCNE3vumDW1AEEE+fp9VeeKjA5muq+jSIKCm/3tiydCAztJ1NqNeJoC9uJyRxba+I7wNdbp2 /X7EfJEJR2VGTZ74XKHKi7wKhlpcLTxRB/dPRut3lRTdaOj65nUfy4+yAFek3BVj5Myd5d7u2qy t7e8pr6EHD6ypXR3cqBDduY4aGzowoVFvTBTnm53weGMRlNhlnQObl9bfgBKLtGM6R/ChFBXWb1 OyY3VEwBrH+mxA/Qn5vbTud+qVQKdnjs3+wkLmeWnW2gCWjHIEualg9X69 X-Google-Smtp-Source: AGHT+IF7mUz86StpMhyTBEmSmjCP/Jl1AFr+f+bpRD/SCMI1b/IQXHVDAjmvzlL0XUw1PqOX/qeczw== X-Received: by 2002:a05:6a00:2ea2:b0:7aa:2cc6:8c38 with SMTP id d2e1a72fcca58-7b225acbff2mr3066155b3a.2.1762589181042; Sat, 08 Nov 2025 00:06:21 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b0ccc59eb6sm5189098b3a.67.2025.11.08.00.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:20 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 3163611388DB; Sat, 8 Nov 2025 17:06:19 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 11/13] um: nommu: disable SMP on nommu UML Date: Sat, 8 Nov 2025 17:05:46 +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" CONFIG_SMP doesn't work with nommu UML since fs register handling of host does conflict with thread local storage (more specifically, the variable signals_enabled). Thus this commit disables the CONFIG option and the TLS variables. Signed-off-by: Hajime Tazaki --- arch/um/os-Linux/internal.h | 8 ++++++++ arch/x86/um/Kconfig | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/um/os-Linux/internal.h b/arch/um/os-Linux/internal.h index bac9fcc8c14c..25cb5cc931c1 100644 --- a/arch/um/os-Linux/internal.h +++ b/arch/um/os-Linux/internal.h @@ -6,6 +6,14 @@ #include #include =20 +/* NOMMU doesn't work with thread-local storage used in CONFIG_SMP, + * due to the dependency on host_fs variable switch upon user/kernel + * context so, disable TLS until NOMMU supports SMP. + */ +#ifndef CONFIG_MMU +#define __thread +#endif + /* * elf_aux.c */ diff --git a/arch/x86/um/Kconfig b/arch/x86/um/Kconfig index bdd7c8e39b01..f12e2e4e0a12 100644 --- a/arch/x86/um/Kconfig +++ b/arch/x86/um/Kconfig @@ -12,7 +12,7 @@ config UML_X86 select ARCH_USE_QUEUED_SPINLOCKS select DCACHE_WORD_ACCESS select HAVE_EFFICIENT_UNALIGNED_ACCESS - select UML_SUBARCH_SUPPORTS_SMP if X86_CX8 + select UML_SUBARCH_SUPPORTS_SMP if X86_CX8 && MMU =20 config 64BIT bool "64-bit kernel" if "$(SUBARCH)" =3D "x86" --=20 2.43.0 From nobody Wed Dec 17 08:44:15 2025 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 57A6B2EA731 for ; Sat, 8 Nov 2025 08:06:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589186; cv=none; b=bXzc5K6H8VMBHK/D4OBYozGstCyvLSvw53yS+5yE3eDKxG12Sp6na5GONwN9GmI4sN+PKlMz2QtT9DBWShaTS00eIA1eN6Tk1gNUD+Ldz3LIv6GOAJ9dW652opJ89bmADjJ/0bUZXaRht+BmZjTT6CxaD/PR0A2e2FsxRicSCWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589186; c=relaxed/simple; bh=zibfGPnHjDDfR56CnEZcgy7KJBvoyjyLYqaq7S1mZJA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eJCf5KVrLQ9q2EjWaFQPf+Cy2gDPcwyO3zrdbmEewKt1gZnSKY4EEDNGQZ6VFKCjwsFlczrOlWGWb81PxjaNcQnWo6F9Ij6mEBeKWyKkkScvbEzx0V/RHwH+iNZXHTcnhOftQ2snZqQd3laruJqaJIkN+P2KgGi4+ITqPwzxmGg= 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=Hv4IQfGQ; arc=none smtp.client-ip=209.85.210.169 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="Hv4IQfGQ" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-7aa2170adf9so1225617b3a.0 for ; Sat, 08 Nov 2025 00:06:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589183; x=1763193983; 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=8dqdH+bbha0oqzf1JSsYMP+tOcPwBytuRd4+x0yMEJ4=; b=Hv4IQfGQM3uF8887B+vgAqRIGEQB/DzQGGjm6kb11+Zz3ePtJXaZwoOmzvTUpyycfP 3sOFC+m63csV6aHJkaoCGn1lCCDWXH4JDlZJQ5nsM2ep6Byz94CqU65Ivbxc2xmPnR8K QbJ1z5V4VKS+DjwLcrVlQHBO4LwTFq99kx8skQUc9EpuJ4oXzj1EVesE7gnLKYxGIOsv 6K45PK+bTMyGLxmBjH0YZQcyKYB3WVwzEPNH0/wO3dQ3t1fS//+ezSVILtcrG6N20646 6n6MwoSLME07p3nuAtwhIE27QUOUIWyMTVoojLemO/nH1YMvKsycxUODoI0PTXWJzPmI x+Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589183; x=1763193983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8dqdH+bbha0oqzf1JSsYMP+tOcPwBytuRd4+x0yMEJ4=; b=iEvndzPupeIBw/RYdnseDDBCRU1p1rQ6p1EkE2/xVwQv2SK+feZhlP3DW9AzZjyZVn CzT4mIuGmPziTyvb6awwfUF6mDKb6fHQIc7qRYNdGcDLChOf25HAw6MlawJLw4/K1CVM O68EUA5FOkqdn24oji4S53C5iAqphmQ+EapSE6l7uEHYnlMGk/LTTH4hAEHSF/bExi8p xs3DD193BPJEdRXJk0cf+PSPRfhsRSrvC5sOJ7w0r4udF+dW6nV5/GhTLcoJI7IdezXB IaFT8kKKXiq1YyOoXAED5HlC/f4kNO6gBN//AOC16540tldNo3RSpLGXv6ui6/BkJrFB A/gA== X-Forwarded-Encrypted: i=1; AJvYcCVM9i1+JDmMkLrcCpEvM8Ba5aBPE/CWdV5sr+O6O/gNq+cYAHbSvk22PPM+lDArj3VzEccLuj9uly4zol0=@vger.kernel.org X-Gm-Message-State: AOJu0YzdK4ZgzEGLOaK/qWYh/xlxRAtOH/nuOe62OtFbPrSbQa9ll1Tn NMATXlKJOopA+iwlRE0lr+enjjw0gB8IJP23LKFsR8Pa96dgLCR81+6y X-Gm-Gg: ASbGnctcKj70F7sEUG0lAGCheRIuxKoPHvnLxLyObqex6UP9JkUyY2xYBW7fwdNB6kx 2gCJJRSvoVHC9HYn4VxBXsFipfr/n5h8AOFQMGacFF2Cub5H1hJ0YaLysoodKG01HM7TodcjG2v 9AieY0vDRgFv9iWmrbM9fjvOxvOYFCmNilLQq2Wd0q/tKdE0zoNUcJAcU/JxY1RJbbN4tyONzgl dszeYn/zPYB1pQXWqpLxYk31dig8GapVRMiDRyJwjWOw5CYo1CHm6P4iA4Ql9gRnvQRlMw0S5sp UkOELZw4uAXmLHN4Fl6yN2fwCFw9ASy1fTuQsyyPEWDqugtqpf3Kj+wVOnDmhut2FC42b4pW7h/ b1vCAo+12fQQ5NvBWtuJninSMNWwsqcfl3hhJ15wYatdPjBHPjV5alGd27Cn51yJRWg7F7BvbKp vwtTXM4KFIb7MyGM00RkXb581A0Yj79+jPNSPyjM4fr/8cnFewYAWnLbkq X-Google-Smtp-Source: AGHT+IHPdEthRdTRwy4DjlAb9ugJodv/2lyawe799MFKgVDlI5BF9aTI1fKrT19wzsFKSQnRdicvzA== X-Received: by 2002:a05:6a00:2d8b:b0:7ab:2fd6:5d42 with SMTP id d2e1a72fcca58-7b22668fd88mr2351669b3a.16.1762589183437; Sat, 08 Nov 2025 00:06:23 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b0c9ff74bfsm5237995b3a.27.2025.11.08.00.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:22 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 2C76011388DD; Sat, 8 Nov 2025 17:06:21 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 12/13] um: nommu: add documentation of nommu UML Date: Sat, 8 Nov 2025 17:05:47 +0900 Message-ID: <16940d31af89a3127acf29d23e10dcb9b7b9f4e3.1762588860.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 | 180 +++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 181 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..f049bbc697d1 --- /dev/null +++ b/Documentation/virt/uml/nommu-uml.rst @@ -0,0 +1,180 @@ +.. 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.17-rc5 uml/next +tree). + +.. csv-table:: lmbench (usec) + :header: ,native,um,um-mmu(s),um-nommu(s) + + select-10 ,0.5319,36.1214,24.2795,2.9174 + select-100 ,1.6019,34.6049,28.8865,3.8080 + select-1000 ,12.2588,43.6838,48.7438,12.7872 + syscall ,0.1644,35.0321,53.2119,2.5981 + read ,0.3055,31.5509,45.8538,2.7068 + write ,0.2512,31.3609,29.2636,2.6948 + stat ,1.8894,43.8477,49.6121,3.1908 + open/close ,3.2973,77.5123,68.9431,6.2575 + fork+sh ,1110.3000,7359.5000,4618.6667,439.4615 + fork+execve ,510.8182,2834.0000,2461.1667,139.7848 + +.. csv-table:: do_getpid bench (nsec) + :header: ,native,um,um-mmu(s),um-nommu(s) + + getpid , 161 , 34477 , 26242 , 2599 + +(um-nommu(s) is with seccomp syscall hook, um-mmu(s) is SECCOMP mode, +respectively) + +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 3da2c26a796b..2f227f56d04e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26764,6 +26764,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 Wed Dec 17 08:44:15 2025 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 E93D92E7F03 for ; Sat, 8 Nov 2025 08:06:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589187; cv=none; b=OvPU8YIeyivnHHv2a68x11Cq7G9lzJay0epFaCT+jEDmMN0+/guT6fDS54/ALR4UUONgV10x2wpMkMjvpVnrzELFYVrvkK79aGEW6ch6D8YDTsarF9fxuHxISapfOX6F+RYfRuiWSj0WZYY54MSBi7vUcfMJgfJfAHokTvWKhJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762589187; c=relaxed/simple; bh=vFTFIe6I8r5QCp5mBI9sujzCZER4Rq/NgROeYBJU/sw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WEg6iqhkc5hnYzI7LqR3oRVtt+NzAyzNEWGjws+1GEMwe1M1TMamdMpLuKP/5crohimgXLp57ZOXJouXGTKrfUnDPXNItDJ4hXYtfo5z7Hv+F2IBJoPqzQooSLa9YUEODR5i2/FQBF8POvjQAisEbWPVDdzkzfbAWl3zo5gy+Bk= 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=e0hDgUl1; arc=none smtp.client-ip=209.85.216.48 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="e0hDgUl1" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-341d07c020fso1919402a91.2 for ; Sat, 08 Nov 2025 00:06:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762589185; x=1763193985; 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=Ph9zR1fvONGEfCwcooy4q6QCBsuZBG7EiBPZ3ZJSBIk=; b=e0hDgUl1DMC/HP02yS/mIp5QGVGGxFk2LYfieOlVQ4Ycok/D0d3VccOlhQfp6xve4s CS7vFa85kRnS6vdpkKNuAgS/b5XlM+SOA1PEfyxJAmOpAM2Zz9l0jeRNhYbHDKPhxc8Z UHmFi8s27u3zkduPhXSbZ8pm56fPDL0U3C62w2aJepQs8czK4lqXdgNXnzXPOY9yGL1v lndOvBLARPq2xg5feBqBECfKRADdvxY7oYbPC6ngOA/nfaQhz53a1okNxE2Jta/twMyO klyYCWgGu0EITC4Bi11hiEi1zphcwKi+a5JRlJY5IjdRbnm7eKqJSXWWA+rdhmcdXO7c 9hig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762589185; x=1763193985; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Ph9zR1fvONGEfCwcooy4q6QCBsuZBG7EiBPZ3ZJSBIk=; b=IF/rATaQZMUKp5+BQztTdG/wy19Lkb8LqXsBDi78N8mmvXFK7w/nz63h0/Eqb90Uhx 4K/o6Gj5KUX3wvi6sO15qEvbMOUciDZFpAwkrF+1H76h1mjh4h63NEIW5vcIEQfZOFy4 eonyHTRBuAKKbxL45qYSxW8CEbdUR4vtHu3m1UnO0pou/hlpEtNyGyNU9OrFwdFBcjah /ZqqvvKoZkXswBaWrRvrvXi/4lopc4T0qDjhHYxQES9rBSonGNg8EkczfminmifQu+LE 3lOe6ZJiKYkNQkpZh55p9J91OALtEGJUd1jrufEd36PS6BNBtuiwLjRAV3gVWZgwTtjN LEtw== X-Forwarded-Encrypted: i=1; AJvYcCUQ/rBQo2CZ+AYXO+y3+dgvzBNxi4rPyrMsE2pO5rChdeWYFZxWXeJc10ekZMVi6b2ZLctXp8fwjmcOh7w=@vger.kernel.org X-Gm-Message-State: AOJu0YzYwvuuidNq357D12BHEf6gm5gGO/oY1lPU4dK42QCtxR1g4kGW n51MgxRKi2k2f8kjdAMr5N4NaEKc/xQEod0PGVKG3FrEU7Fdb/ChYAOV X-Gm-Gg: ASbGncuisXhSc7WxG2qPtJAz9lp/RzHuIA0zPWDHTetWxAoVJEo0IQYkKcYd0MLTHXk L/Uk/fspHQSX2cVjARI+elLoJsHHtcPWaEKsqJbIHad9hEgCuP62UVALGxJ0qK0sqkgjh6fKM7A yu0Q4dnzUcegOqcMkYufhDdvLMs/qwR4LwFVbHTuG2e2P65I9/4oXBVmlmCtXpVKSoFqdhNQrSW A4+Ky4Pzi8+34n4yHNQjMiDzjXKvtTcy+Osx3szFTBW0Moe1aUmaO6Q5y/cvzcgFa2JWwu7BqIb xLlm8qv9ihrCaSX/iftqjXxdOCk1E38UrcLFwtjQcA1KjoVW4Ux0m8CGVc7xoICfE9QdwZDt6Rn zszIA/rfjEwcBv2FudHU2RmbKcvOzt5dWz1juCwDr8fBgQPojs0SRU9TGKUpQuE5pHQqNLybAHm kSzA81opAAV/gJ0WgT/ZsT/XB9srIoPluDnbZf/RmChn3mvQBEZuhAfYY8kCwegXHK+YM= X-Google-Smtp-Source: AGHT+IGJfdh18b/VLG+FNXOhiB/u0ohyfs/EsEy0a88QiPDZTbxqJDMvN0IIjQCopB9ZzCCa4OleMg== X-Received: by 2002:a17:902:ecc5:b0:295:565b:c691 with SMTP id d9443c01a7336-297e5629152mr26786625ad.17.1762589185138; Sat, 08 Nov 2025 00:06:25 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2965096b8ffsm81262075ad.21.2025.11.08.00.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Nov 2025 00:06:24 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 52B3311388DF; Sat, 8 Nov 2025 17:06:23 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v13 13/13] um: nommu: plug nommu code into build system Date: Sat, 8 Nov 2025 17:05:48 +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" 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 | 54 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 arch/um/configs/x86_64_nommu_defconfig diff --git a/arch/um/Kconfig b/arch/um/Kconfig index 097c6a6265ef..4907fd2db512 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -34,16 +34,19 @@ 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 HAVE_SYSCALL_TRACEPOINTS select THREAD_INFO_IN_TASK select SPARSE_IRQ + 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 @@ -225,8 +228,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..02cb87091c9f --- /dev/null +++ b/arch/um/configs/x86_64_nommu_defconfig @@ -0,0 +1,54 @@ +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_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_EXT4_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