From nobody Wed Feb 11 03:42:09 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B8B32264CC for ; Sun, 2 Nov 2025 09:49:52 +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=1762076994; cv=none; b=VIQ/utcM/U5oTh5cwRETZ85LV9A3kXPCSbu0vDhmXvjNXZL8/GUK6XjVjv9cFxSn3eLzC1+4BdqTmJjv0CcCFaPSjepNE14wxxVyQi/efbqJUWy6s2bjrWt2KNI6djuUfxAfXQMedvtsMZ+Wq48+9QlLilxG1vFQvwkPZ8IaRiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762076994; c=relaxed/simple; bh=vzlHvi1hpehuDtzoLI80fmGg0yF2KnaOx/kv6IzWt0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sRF6oxg3cEfbEdvwmNq34WJBoWzSglOR+4FejQ6aVxfREc2lpP9DiOLTbKFeAEAp8Xi2UgIobus2Ek/kX3uDAFbOyUNO4Xw468/eKe0VsQQGzCoZ9LLSs4rKXumGJFS9W3xwpuYrKqtxRTel0dckUPLTTnXJR32gyj23ny0VPqw= 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=cs4UtvcD; 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="cs4UtvcD" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7a435a3fc57so3308587b3a.1 for ; Sun, 02 Nov 2025 01:49:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762076992; x=1762681792; 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=7GAo7QPFRSMtQ+F+v51lXmGXWMCiRMzi5C8xvTtplUQ=; b=cs4UtvcDGXTvL6TbJgVEIK56EgbSZ8sB+rNtGI6/iKvRuGqIH33Bhl6XOD1cyL0kc4 FL+EFAGGx6zs19kz+G5X9X3nTVb2BVC3XD0oeoMeMBICYBpVB21R1DDTzmW5OEa2P793 NFBAWz87Z3OTE2VDYDkQp4cR4VUrJhXFaALegcYv60R6sEPPNTC9z6gxnbmGhlZe5VGp 1yJFAoZ0kTZtJ8ApMGOFSD1nR3LQ5eAj64ecm8bMAHrWsWHjvduDz+GkADcR7kyqog1A 00PQ73zo8HMUT80gdTT6bVXssDXq8GxaYl5vJfrImCL3nVtHsAzmTFxZ5cJbaNyBUh68 xLcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762076992; x=1762681792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7GAo7QPFRSMtQ+F+v51lXmGXWMCiRMzi5C8xvTtplUQ=; b=Yo0LiOHuLYJL5T5kDFHIAyw1qpHTIhigUjDV3KLvb9fgj+KonclcpfvXNFHFsjr+ZJ mBOFBxOvzdCuUCX/ibDu6hO1jH7ZTzkN1R2XkicNzGEiHFSL8xP2hPy2AKWQLjQQtr1j vZtAOv/UC5zZnSXY0eLWYnIUlV8YDadDlK3aqkc0eJ5ScOyIP9QM8txLOIQrS/vGYxaM q5K6pPrQU5n6UXDdgjhs8bIc/3WagJc+iVO4qiOqcpAtlIds938oVc0gfNsfnIBft4Ng DAYMkyHue73SCujlDVx6+FMxJhG65d66bqXBPd3+eNasHPC7Rpyk1VeVw+e/h1NMe7Sp RQig== X-Forwarded-Encrypted: i=1; AJvYcCUPLX8xNS/kez0deT/AULvtdIr8WlR9kKATUFp3Kin4NUbYsZyOg3I5v/4E71mNzG8+58MYfFD9AtsVb9U=@vger.kernel.org X-Gm-Message-State: AOJu0YzChAh1Zx3x0onJA1zNrcqWMFiKrZZfMNhrwM3pNfbr4v37ao2l rAVzI9Tf+xJVuB9V8enWUYuNbJdnrMOjjO23v5+X0T7cRy7TnDF9b0mU X-Gm-Gg: ASbGnctow+NnXi8afKo2GPTlkFlhkhzw1F7PmL0ZCCQRHX9Kb/sFn0+7zJuDkKcloUZ IpwsvgxMMuvNf4Lq0T40Srk55UySu3Ja0wXvOAvzDYrEMyOx/l1WKXw4p/kmtDaXP+LtSrSNabS G5yMOwk3fSC+BvAizneHZcLXcGu3bReCA7ZhNzhL7TqSXIZVA9rYwtqlzf3uJFYXyMB8/wYbrLw u81LeWvfiRg0PuBXYosQlNbmAuMCZP/3BIpb/hsRwS9hqcV7ZXGcqHHYYiInQN0SDhtSY/BXXH5 ouo+fVuzlY8kKoCsb4hqFiZgFEm6rWKb/DC9De9UMTD367KPVfxiFTC+V0xnhYH8AtVpQtQ0Rru PC3Rbxf9XZ3uxDl+WEs3evJrZB5jryZLX5mxAhKAim7qZQnyofoDP+sBF6rhDIqODAb3oIjfy3e ah4adnGF4G9c5RzV70W9G6iV3sOEyYs2L1U4twfHJK5bs7gw== X-Google-Smtp-Source: AGHT+IFjPZCZPoz2w60NDnASz0MjN7TYV8NIqgCnj6gVUAWRi7VL8ewmGqOYXuj4ykHVff4Lv7oBqw== X-Received: by 2002:a05:6a00:1793:b0:7aa:d434:69d6 with SMTP id d2e1a72fcca58-7aad443af35mr506394b3a.10.1762076991691; Sun, 02 Nov 2025 01:49:51 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7a9bad978c4sm2738154b3a.13.2025.11.02.01.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:49:50 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 0072711237FF; Sun, 2 Nov 2025 18:49:42 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org, Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v12 01/13] x86/um: nommu: elf loader for fdpic Date: Sun, 2 Nov 2025 18:49:26 +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" 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 62ed5d68a978..33f69f1eac10 100644 --- a/arch/x86/um/asm/elf.h +++ b/arch/x86/um/asm/elf.h @@ -9,6 +9,7 @@ #include =20 #define CORE_DUMP_USE_REGSET +#define ELF_FDPIC_CORE_EFLAGS 0 =20 #ifdef CONFIG_X86_32 =20 @@ -190,8 +191,11 @@ extern int arch_setup_additional_pages(struct linux_bi= nprm *bprm, =20 extern unsigned long um_vdso_addr; #define AT_SYSINFO_EHDR 33 -#define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr) - +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr); \ + NEW_AUX_ENT(AT_MINSIGSTKSZ, 0); \ +} while (0) #endif =20 typedef unsigned long elf_greg_t; diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index 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 Feb 11 03:42:09 2026 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.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 43883247DE1 for ; Sun, 2 Nov 2025 09:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762076995; cv=none; b=c4f2YMM4K6ZFZu/OBbOE1I6Yz60sj+zUun1X3NolWG7uJRaOVVQ+9+fFQAVZXmdowN3AfrwhDl5Zxpf7dHGiMSDNa4AcC1Uu6uIyQJH9fyrPvJZrAyvI3lhDBTCL6/GvW5DHaIu4U2Egb6K+EMeSE7QlIu+GGR6XpaJeDxWaKFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762076995; c=relaxed/simple; bh=3h4KHxjf6Nj7gUR5Fq6oVdei/yT1yZ6RSKyCcwa/FeE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o03nrJGQMDmzPnVMdWfb1kvKN/kMn+aP1AKUvd2QTErh9LHVRqXmzks9rAOJqdGSBAZU4wAOv2TQ5rBLkWdR9Z9k931Y2AossawgUqk/jnvKMb8uUElLWCqzcye99dR7w7IaLphaJ436keWjOLSWV4snQV/x++VVsDrFcBiPZBg= 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=aWylnObL; arc=none smtp.client-ip=209.85.215.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="aWylnObL" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-b996c8db896so527842a12.3 for ; Sun, 02 Nov 2025 01:49:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762076992; x=1762681792; 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=w5g26G/COfPvrLkIRmt5b7hYWmBBdOf28rjYEzX22+c=; b=aWylnObLe0J5Rg9jWgmSzl0gmcxh+LiYpo5hZl9cvF0xoAfGo8sZeP863hU8HOegD1 FwP5SqN5JAP8KIRNLPvUind/nOTC9bhf/8RRYl6RsaF+hR1uUVJvuAgEPxFSxMzozQWH 5HGonzRs8roT7hmOMg1I56P3cpqIiC1EPd0RaC81Kqd1stHQ1KUZOQVVQ8Tp44m5GvEI p3UShq264QqaSOZ57Vt5ERiG4N+JnbfjghbeSVoiagiXyPMXG1OALGtYpplD4BpHhlaq OJrnU9nwURkt/0FXbYTRXHl8iBvMVVnu6RyVQpWbi/P4CUG2dRjaQ2OIHinJ7ocr28dr ZPPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762076992; x=1762681792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w5g26G/COfPvrLkIRmt5b7hYWmBBdOf28rjYEzX22+c=; b=ks05GBwyfkzq1wGZshd/4wnDWW7pKzEisdz7VBTjFrbns4eet++PqA3nsBpVV1+vMG pWeLrjcJb6GFTt1DprCTygZ1bqUcBQjHexN2xCEygTSXv3nuUv9eSHfDtkc7k+OE5d2X vJtUO2oNedv3X/hKKNWtCVJArfAuMh4Z5V7bULEHL0Co+0Oxhjewrh5jFgLhliLw5Fu7 Ccgpwu/o+RutH0kYSv86RWN6dyE0vDMbxuOi/vSWJL8ajq5i7os6ldeX44G3YS/jiwQf ehKQXDwzuJrhYcj3KZZgPLBMrCMa62kEUT8C+YD+R07Xwnnk0UVp8mVSxo3LN47kyo+a lVjg== X-Forwarded-Encrypted: i=1; AJvYcCU3f2POiQBmsKFh6hmh++heS+cgQ6EL3eQqRm0o5qdV0BhPhnCcl/lJewpFICCS9C90s3qGHmKQNwNgjZo=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0u4FiHvYkEDklf5VQfKEsMP9XCjkURoiNhdE/yj1qYHs9fy+T ZxRJ53z3bl5vvyJIszHhDlKfVcHKtlU5628LgcRAgZDoqC44x/HfW4Lm X-Gm-Gg: ASbGncvf50winwrurDJfA/tkDD3hLK/op+NMK7Nce4zrL4/m9W0jyVAHYWyFgQSXTur 101U20s8F6pZ0XHkS1vSAfi61zHRmLjH4HNXAH+jEktSoK9hk5qrLuiESSw9v/S6u2YuBJ/tahV JLJuTBCIclI/Nt4h1VyXwkq3M1MWCtGXVRLkZelph8U6BzJlpJHmDKa0jbp8LfZ3EDRN2NoxWzm UjOtk9a0FH50Mx0Cny1snDjRtnJZaw+4z9Rd5OR7xGrxXuuzDH6e/hii1Ro4IvNHgpJA510OdfQ EspH/U8HEFYjiu0hIQFtwUbPwPXgU84ZxdeOs6QEJjt8Bvf6/phN9G5SRNuvqr2d/wb9MukO4qA oBChS7dhK4S2pyCtJPS/hEUGSWGwsY9GEf3zOZqjVSZOjHdiLId3jxmhfb2LauPT3A5th2RPYpU HP5eQ0415c1sChhxW9uYMHN/RPqnqPX1PmRJnVjnobhFTEuw== X-Google-Smtp-Source: AGHT+IE4ZJuOJv/lZZjeLKVBUjHez5Y01sXUDedOJUP9w8GA2DbzhYNRv1LwyZd82LKqaI0ufh3+IQ== X-Received: by 2002:a17:902:d2d0:b0:295:49ab:3593 with SMTP id d9443c01a7336-29549ab53edmr87061675ad.29.1762076992361; Sun, 02 Nov 2025 01:49:52 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29554cba950sm50950775ad.97.2025.11.02.01.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:49:50 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id AAAAD1123801; Sun, 2 Nov 2025 18:49:44 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v12 02/13] um: decouple MMU specific code from the common part Date: Sun, 2 Nov 2025 18:49:27 +0900 Message-ID: <08489faaad68a17037e1f24b2a39d8fc3b021c61.1762075876.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This splits the memory, process related code with common and MMU specific parts in order to avoid ifdefs in .c file and duplication between MMU and !MMU. Signed-off-by: Hajime Tazaki --- arch/um/kernel/Makefile | 5 +- arch/um/kernel/mem-pgtable.c | 55 ++++++++++++++ arch/um/kernel/mem.c | 35 --------- arch/um/kernel/process.c | 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 dc938715ec9d..52cd906e3896 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -214,45 +213,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 70c73c22f715..051679d78aae 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile @@ -8,7 +8,8 @@ KCOV_INSTRUMENT :=3D n =20 obj-y =3D execvp.o file.o helper.o irq.o main.o mem.o process.o \ registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o user_syms.o util.o skas/ + umid.o user_syms.o util.o +obj-$(CONFIG_MMU) +=3D skas/ =20 CFLAGS_signal.o +=3D -Wframe-larger-than=3D4096 =20 diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 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 Feb 11 03:42:09 2026 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 D50AF26B973 for ; Sun, 2 Nov 2025 09:49:56 +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=1762076998; cv=none; b=Z2KLxgZOIdvuFEeIhlOr6I8z8n6TV0KAIx3eXLQg6uOff61DhM9chKlmw7d+UdYshatdAb772Ridol9+enMoV99zCe/fFP/ru7FrLhVUYmnsFr1wHLM4d8PpttMcBAqEg3yBMyTa6B0rnqs72tydhgizxyWPI/8ULoi5u01HZC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762076998; c=relaxed/simple; bh=MDKNy8GA7hh89rDwV6Uik8zdzD4tw3Zr+4cOFbUqcB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ftZI6yI5w/lD5XszdHvItyEmtYIjko7OvBLfpTwjaWwPN4WEIaY8BqDL2+OPdFba+ZKme4pl0ljbBziBRqIhciEA6oe5R79aafdomruSzDrS9Mhs82BFz/l9PyB1ajwaodKrZ55oUPAGylE16IaSduGEsEku3YBjsGZaXoZAZrs= 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=i7VOkR+U; 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="i7VOkR+U" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-340cccf6956so485954a91.0 for ; Sun, 02 Nov 2025 01:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762076996; x=1762681796; 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=dLVWDe27CxuFua8732sg2A25U9KjI/ik4lvuwLmfhJ4=; b=i7VOkR+U9EPaOtnmOSQucCPkRHZirLMvJzC+hb9jbVR63QAyIeKYmbLlt/F5htTv3g JIiAfTg/QGfBkQQzUYGTF+Ft6VtRAjbIdE61J4DqBYljwTR/nTqm4nncpAO6CZFtxxE8 05nmTKXrLtF4WBnaWZtiYPZqlzgrw3DrJdrXAk3oQT0oVSMXPeEmGger0gLq2NqxHloy Ch73y5LWlpj7V5NP8spYeLAn4qoStEm3TY9DU91Og8ac3F+M7m7va0cZrJg0DCBy4vav tR0jSmAFh8BTvm8kjQKRjeF7bD+HlH5fTFALJutktomF2UZG8xqVf03JoZJ0BltDLRxB mOMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762076996; x=1762681796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dLVWDe27CxuFua8732sg2A25U9KjI/ik4lvuwLmfhJ4=; b=iHiWHOEUui6qXKREpTnC0QZujl+CeID/XmkC5NyCVI1rWeqClXiBAP6It6M/o0I1h7 vdiuYx045bRwUlIFOzrzn9uDnx23u5Q5vi3qUr2C0SrkGl5Af94UmmlENHja9Yq/qt82 Q8eENL9wHnRt23i/NlGwNRlIS7FfZPe5b38USWVGUrCzg/3ctqiozCQXw3MwkowTZwrI zbRPcIgJAMSNjIsOqS6pCjBEhpiidQUc54l5OL9Ft8nVl3GQbShpyKVGGQQr8SjiihMX tPx/gBz8xr1hzGODYdcQTnvB2O/fSjRs7vqUFWAnFgaqIsDuKyTNh9GAm2P4hffLNhWG WyFQ== X-Forwarded-Encrypted: i=1; AJvYcCUaBp0uWaIyxKcmNog16ROLNc+tt/uSpghouPDy8wiFtaGsetjf5O6r0JR5QsCfU8KOlfWI4BEoaqniyqc=@vger.kernel.org X-Gm-Message-State: AOJu0YwYV21+38LVLfjDOVETXIa5/9THCU5MeZtBq7qAZCv6bJnf/UTO V9IZuPjdVr2Y04YjnCwQ3G9Eukx6ZX+VtVpgWz8Lx6Kc/eKUFyZ25kM8 X-Gm-Gg: ASbGncuhF3MNgZlBaxrOJDo1q7kfM7i5FQnkHJ18d1VUZuELN636eeoOpKW3hXiywU3 K/L45oqXaXCap13lS6veMh2WCz/dTlTWBWNKNZx1Eu2Pssmncxfs86t2d0xvuA+sAJIM3o1qJSg DIERBx1J61FS3efAEjIoeiMKf8dDbd6BzdQR4cb9zUEKCy4/zDzE69SBXenGv8QJ9oxOnvVHMAT E01URPLm63KkTDT/azHDE8IuZ8XoP4N2OiAtxWEsz0dfTx51xyRNPYLO9xUTI5XZAkHVu/UMIRR BoscsToO3g4Jye33IRbXlKgnACbBxNgOGn1OFpwPdnkvT/5loV8XgiSI86nJykAxlAKt9sBbvt0 +qfT4Qhmu9RS4Cre67dp6hnKr0Rub41wVKPdIizu7X7YKjoJSrJOE6sqoTp9eP0uAWWCJhKQ8cO 5QT9HEe3atDfAUfG+p+AnGGtnzDTcpjzmhtbCNGgjn9vusZ6kZGNPMHcnZ X-Google-Smtp-Source: AGHT+IGzGeGnGZ1p4XL3AbmXtABYfDo2QjDzgeG3Xh1EPclKdLYIizv0aT8x/i0qH9w4Wj7HzH+eoQ== X-Received: by 2002:a17:90b:548e:b0:340:bfcd:6af3 with SMTP id 98e67ed59e1d1-340bfcd73e0mr5203014a91.33.1762076996088; Sun, 02 Nov 2025 01:49:56 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b9b8f2b5403sm812590a12.17.2025.11.02.01.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:49:54 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 7CB341123803; Sun, 2 Nov 2025 18:49:46 +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 v12 03/13] um: nommu: memory handling Date: Sun, 2 Nov 2025 18:49:28 +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 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 1c6e0ae41b0c..b9677758e759 100644 --- a/arch/um/include/asm/uaccess.h +++ b/arch/um/include/asm/uaccess.h @@ -23,6 +23,7 @@ #define __addr_range_nowrap(addr, size) \ ((unsigned long) (addr) <=3D ((unsigned long) (addr) + (size))) =20 +#ifdef CONFIG_MMU extern unsigned long raw_copy_from_user(void *to, const void __user *from,= unsigned long n); extern unsigned long raw_copy_to_user(void __user *to, const void *from, u= nsigned long n); extern unsigned long __clear_user(void __user *mem, unsigned long len); @@ -34,9 +35,6 @@ static inline int __access_ok(const void __user *ptr, uns= igned long size); =20 #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER - -#include - static inline int __access_ok(const void __user *ptr, unsigned long size) { unsigned long addr =3D (unsigned long)ptr; @@ -70,5 +68,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 52cd906e3896..1b9e7c62412d 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 Feb 11 03:42:09 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.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 8792B26AAAB for ; Sun, 2 Nov 2025 09:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762076997; cv=none; b=Bc6kezb9nLVHU5xeguz2MZzC6k/hYEfFW9oZz+8zyKGeo3PC2jFVxjNuaf9X637AU+xDO/hPJVX11ap/uUjYjAGFIgnt+Xo5bDoLTNAgiB6MM9YuPLcebG4W2Qe4GETqtIIZnlAmIVtJ0rUhs1AsP5TyPF86IBSXYQo1VWlhorA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762076997; c=relaxed/simple; bh=Z6qZSB5ccwxVgYVj98AksF/DlcdpqcgoKyj9hpY/Brg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hHsVq+CHujVbIbvH0ch2NDb2Zzz4as+eHYZgEIJS0LgZ93nrcUoWMUqqGYr8RRUzdvg6xgqo9y/ScUZ7qVQd3EOuYFvaUDJr88C8ar6ipPpJBZceCUV/TEErx7NB4zTlFivT7mCE/uzrYsyHNJl8cFikrnYn/MrSdcOup+N64GM= 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=T38cZKoa; arc=none smtp.client-ip=209.85.214.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="T38cZKoa" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-28a5b8b12a1so36785905ad.0 for ; Sun, 02 Nov 2025 01:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762076995; x=1762681795; 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=MNruZWOB1A9W2xPWfDeeJw/PtthshopimV+lzxEm4to=; b=T38cZKoaemDfKrpH0+ta8blcm0wfz0MwYgy//cVHMw7zLWylvMBY7WxOj8XkIKUlL7 MmDqBbh2ncRe23s5NviKIK4S73nLiWfcEXVRk0fium8ryTboCDeNfTz1R1bu3CQmE5a7 MC3BLp6tEBC4ihNtruEUR4C+wbUduaIJUAEovvHlJ5ZtGOS1XFpsHHK9IskskR5B4PKp l8VG+jKZ+01LG/EDERupUdOjaNZ1LnarfxBFJk6a4qsF9vHE6LMNTGIUTjgcDq+EB0qo Pcn/O0HsZV76cuAKRjzk4g7UPcgKCM36PV1B6RnsFr1wsnHc+eJ2fRDEXwnhXNj8F2Lr inqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762076995; x=1762681795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MNruZWOB1A9W2xPWfDeeJw/PtthshopimV+lzxEm4to=; b=kKa5axVuNNKBidV/5NHtrEba7aa0E656OO/9wKJ+6hSDU5+Gv1MzGn7Yp/nCu8GEWq eLNK4Rg2BH916VsJWtg7ZjDDogavE2Ecu1klktjoSWBKhR4xBAKvf2QYY1b7xgK+Mn0R G6kl1MJfVG4ypIp9yTx/xoOQLJVsCBAoyorxowZxnYJsNfZ2FnbeGQ47pk0tB7JtNwQU 1KoglOG4sF9zyikRG29Hb1FvtqsRL5l56aJ2cw5KrqWUDM7tg6yxhmGT+Be0RtOm74SK lbrNVEORly6vttmyOqFsJZ3bY6cjDNmPCG9hxRcL/RUDLG1vM/M6QbwKCkHFtKj7mTjL lksQ== X-Forwarded-Encrypted: i=1; AJvYcCWjBdvR5I9S33upwdKCRXBt5d4dmRsDC68mFwrviZiashK5NZ6hjF9vPK+tsfy5dwNZn3Y5QJhfN/VCvMw=@vger.kernel.org X-Gm-Message-State: AOJu0YwwuvmvdE1yjaNnzpGujPSZsKwOvAmi0ZjIuJ3FEKbCs7h5PCVi Xd1CFV6duR8TOkFwB5bK4eSzeMJl0j95nUJPIsPz4VevfOp+7DqmCmkA X-Gm-Gg: ASbGncsUw2nRoQ4ZcKxyN/G2/tv5w2Nphp+RNvNoKrVLCBI1OY2com7eHy4fhcOAfXo rDWkSZZ4etnrZ32sP2vCa9MAK+PvnOGcwUojo6oRMAEjerZJLkGbAbG1ViBM5ZEi2u318CDjYDi xm6Q4Ew2IakdrojdbbiGWIcED0x3z7LLNBZX1FO+DRjac+St3TRn/RsbOMtJ5ThH+UUE80eooPJ H65EPtTKHuh6Np/2+I8/fRgsT4Xf0wIokRA6lKhF+mpD8Gw2mH7qBc8BCuksr3a0SRY2Q3yB1Xs ma00WFX7gVRFGt4WBBrupht43Imwpjz2bOMYDGUjVqpe4OBcU+tnVitdogjo1IYX5sSMYQzHo6t /lmYtHrmhHW2ySPgKZkU+jdoLODZaRNuQPrhWY9vTOJgWt1UMoBcnVcQ8c5f7Dghp7o0A5M8v7R gdg9yPbqDmidoFO7M8cJrKaDqcN+tuY20+QIRE2mc3cC/HAakK35xwQHML X-Google-Smtp-Source: AGHT+IFkoW2S8Nm2549TybzP/Qjnm/HVrzvPiD3jHPwRPqbA7kzapN9ZpSAsI/ISg985qkSCINlgQQ== X-Received: by 2002:a17:902:f68f:b0:261:6d61:f28d with SMTP id d9443c01a7336-2951a4aa201mr116295275ad.50.1762076994796; Sun, 02 Nov 2025 01:49:54 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29564fb531asm38273845ad.14.2025.11.02.01.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:49:54 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 0686F1123805; Sun, 2 Nov 2025 18:49:48 +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 v12 04/13] x86/um: nommu: syscall handling Date: Sun, 2 Nov 2025 18:49:29 +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 b42c31cd2390..227af2a987e2 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -32,6 +32,10 @@ obj-y +=3D syscalls_64.o vdso/ subarch-y =3D ../lib/csum-partial_64.o ../lib/memcpy_64.o \ ../lib/memmove_64.o ../lib/memset_64.o =20 +ifneq ($(CONFIG_MMU),y) +obj-y +=3D nommu/ +endif + endif =20 subarch-$(CONFIG_MODULES) +=3D ../kernel/module.o diff --git a/arch/x86/um/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 Feb 11 03:42:09 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.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 E53AA26ED23 for ; Sun, 2 Nov 2025 09:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077000; cv=none; b=LWcqd0HLBNr7fSXfWtZMyY9yT4UwxrPBM9LZANo/M5dQq3rnrfH9gjHVoPPDXyOLbSJODV8TPvMmGpUU7/Z/hmPqW05ETarAw4p+jtnUBMZ3pWy5i2dclnZAr27gunKSypdVqON0e/BcjMIUTgY7T9aOPY2ZcGV5O9guLX5xpZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077000; c=relaxed/simple; bh=ApZCova8kpoHyvQowYMCMZfo2gH0ldio/mRio3HyRRc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mi0+R958vjENgX7fxcVlpnXA4/n8RDXsgBvBjuvwhRqLVgroWRrAwuHhMx+e5MqrnPtAAx1iOf1PSnHVGYXsERHl05FJBnAETaRaGGA0n7rD8SUGp1MlDmgc4cqX3N9wg3UfZIX9lXKhXj1y/PysNGTAtBNsjO/Wak/JkohDi2A= 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=e4/ligWk; arc=none smtp.client-ip=209.85.210.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="e4/ligWk" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-7a4176547bfso3315725b3a.2 for ; Sun, 02 Nov 2025 01:49:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762076998; x=1762681798; 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=e4/ligWkuRxeYc48um+cdOz640wEML+oJ0C2ETSxjZrioM5UyrGSE3qZ2tq5yEm0QG LCmlg3RZWAKc6bGZ85YLVqxJ6v9GchTORWPb9g8uPkW6Kmr29w93ffq0IEYWYBQ5d1lH FEYYFCOnqENzdneAEk1K8OYa7qQbtbhnJjcjnArfhFOgwUHWn8riHdriBNNkUHwjA85u yACJTeZU0bg5sCW7DVz+eBU0wChmUxvTNlxMHANH93cxn12pzDmP5VSfOWFBYY91LqOH tma9nP8j4i3AP/NEPz19uSTAsoh1DYucKdOFQs8YTS/7MkKQx479PikXbtFM6DDME0r0 kjGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762076998; x=1762681798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SLnEdv1Aj+O6ghd8EMKGqBIoQpaMRjL7FrHMTz+k/js=; b=HxloBt4Q+Xy9vlnTLmqHd2LwDxz3d4O273OO1A2k1T5WTs12+664/zZC/EsnrXJl4C odBR1donNemlEgmeXELe1pplABVeWX2soh74Kjn8Z3ZxN5XMY3hnhJznGj0CeI34Jck0 nAiB+RHFLKiOe4L3kRKJpmrndyQ6NDGSfBqGcINbdZn+cKzE5JB+bjqrTx0kKM9LgsOD lb3yw+5RNEmPy18U9sqo2cKaWACqPkYkX2S8GrnVmr2Th+MeQKVn29/al5iQHnwKBtD5 MIVLayVTDYnCgoldTj9kEPnfyqoLBxl54pgdLp1OZIdjVg1y8pniVtKtQzMj/fc6bkH4 46LQ== X-Forwarded-Encrypted: i=1; AJvYcCWsTy+RIg03lysNJnKSF33o8a/3FQ0WuD/G9Bbcpy87cW670EtdgR0YkIyZKpJeVbqsVk7BleVR414yrWA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzlmrr2ToGZcY6gMM4ZyxWxJV4Hr6+dKls8jOhphJMVrDY4ltDA 2SjePQL60D3YuI8qIuw7OgC3EsEIiGpVTqjQk4c0O9F0CDgb64oP7R6i X-Gm-Gg: ASbGnctL2xRq5qGiBSk+qCL2aKAOl2CUOdor1z0dVx6RRYNx5tWgXtzeCq8rOZKLUY0 ZH2rkJGcynBc1eewVsmeB/YgJXn5qKwSBwHBZrXFxADvPt/Enb/VQfo68+ovr7AZ38o2KPwvFzC 0LGBBEXHXDjqUy3BXpazsuXlOpiCKKOHgXqQt+z241LoUDXFAWCGkkwajuNsYBD1FVUGJ4Etdqn wiM8Bycm1qkml3kNuJlmM8pxaITDxeh4Q+2L40HoQ3jn9XQQtKa5K+LWOAKfZi39qX/q7SZ+x8E XNLVl+ucLYuLZdujLGXHy7LVt+cTKFriM6s5RV3fGPth6sojBT5LBly2fVmlmtMKl3kJe4Jhqf6 HqmaMZiMO+XoCN7o2CxaPcTkY0HT5GD1K5TFVEDFbBoX1Xtdn868Bu6K4H0O1sh58xgB5WU3Msq fzbAJfjPeuYwf6Kn3OK9pjYN22+KHG1fC/3eGzg6qAKc242+++RGiBROJC X-Google-Smtp-Source: AGHT+IGEB1oC5W8bqUi5NVnEQR/tZnvPiWF/2wnwqLC4TMuxSvT8HcXunME5KnODXeltaFD1eULcDg== X-Received: by 2002:a05:6a00:6b95:20b0:781:16de:cc0c with SMTP id d2e1a72fcca58-7a778fdf49dmr9112560b3a.19.1762076998081; Sun, 02 Nov 2025 01:49:58 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7a7d8a76f00sm7452492b3a.12.2025.11.02.01.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:49:56 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 6AB251123807; Sun, 2 Nov 2025 18:49:49 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org, Kenichi Yasukata Subject: [PATCH v12 05/13] um: nommu: seccomp syscalls hook Date: Sun, 2 Nov 2025 18:49:30 +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 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 Feb 11 03:42:09 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35D0426E6F4 for ; Sun, 2 Nov 2025 09:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762076999; cv=none; b=Urrh7AFWpIQxfbRyUSAbdn8ZNPFExNRJTn+5tXIOuH7WRnDDeiRUgQ0E22ZnOmtRPJ+q5ep3FZzjGwczNtcnLp5ENsPBbROpfLieAFeIsp1R8Ov4k2dDSPfwY0WU2EGOFQC/s+sty3cKTtXLN3ARXQD3g5Cos6YQAy17OKYbJeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762076999; c=relaxed/simple; bh=asugRdDdRMBxIe1EMSyil3lIrPO4TUilJEIW10zlNcg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lcwyBVWsb6CVcrArZVSDsxeraacQrA9kmjvTo4RRqYosySD4tDwLVC/j6EAubkOoCbeK5nYzBXzEET55psgw1IjDc6GMxwuQxbJsrx77M/Y518pHEwv9wwEFaKv+US4Bvmh94uw3+uubgNsHZvQJDywg8rcrl4hAVixIQUSdX8I= 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=CUMQz3Tn; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CUMQz3Tn" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-294fc62d7f4so30459075ad.2 for ; Sun, 02 Nov 2025 01:49:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762076997; x=1762681797; 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=gGE/jcU6KuNdO8mMPcpFhWHkaPMHY5y6/wQ8dXBnUzI=; b=CUMQz3TnpHD2C/qWZjQAjOlzwxS8xCrb3ZOfyrH5zeCKtoaVcncF3eZLqDb3P97IgY My+k8+VG630AjmZ1VWOKac4PB/oLF+pEHp4rakCel2ZUo4npzLDF8T+XWsiIVjg4oKZH F/4jUL1xz5zuJY7kN28JjVgfNKjV6qeUmb4EifzidvuRcJYr6ZCPQcIplmOuUKOVPmWe wp2I9gNQJCBcAFYwk8Z+gbnhnLxKzMnXN6sMilQ9A1QT7W8ekXVDR9jTYElxQklYgjYH 9Y5EiZXD469PzxtMOa/a2XoFOUraYY04vz4bTS2M57IsXiXY/mUhPYpJldX4t/h3YJQI hMGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762076997; x=1762681797; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gGE/jcU6KuNdO8mMPcpFhWHkaPMHY5y6/wQ8dXBnUzI=; b=lCLewaI4gD+pHeukAzeRCeBeb4kF6bQnD3x/j+ZAYsEYYPY84OiGz3yi4PyLNTTXFY i/yr14A17aJq9kBy5IobrXemtWJWX/6TYHU7LwMz4WYShvu78Az7EdGd5O9nbP7I8dU7 1AlJrvlhqOhVcUV5fjvp/oco3VLKXXWlT7z8t04lPj8dt6qRibpC3fOctYBxEuw2SL3y NLS7c+tcodCs1ErRWNDYwEPadv10VAnAiuk4fSwSEfeMyNhLpZeyCy3ItxMgo9QRT0Or QqmAJQsLCU2xc3gRsnNusuZQzT6rqsk62esJXkaWA29uRqLV00STcisezMfZw7b6/Box vxGA== X-Forwarded-Encrypted: i=1; AJvYcCUcDfiWsuiku6dMYgzK3aBkt0KDqP2dbTpKLHG5QOLwBlDG1kTW63KYzmAnlPpAsJ34xfUT/bJ6tv5Vsvk=@vger.kernel.org X-Gm-Message-State: AOJu0YwZJHS1G9st4ddLnTDTALXPb/v56ZNlx6ZmOcg+9XVdbwzpX7mX Vb95xQ6mothBE4lkrGO2vEhAA8Tqs0WWLwhcz+o/WznhlnoHnNTjl6gUTOwTYA== X-Gm-Gg: ASbGncsn4WaNCt0VwkVBc82ZQ172hiiWjaCvyBxFR4nHB562ofsWrlHrCUE7snB/A5F c0XTlKiO2+mhTWpKKmeCzI3yzuxlCUD3Jff5lmoJFjQNlv7+0sVLIDOYSU7U2lNYqufaw2wVdIC HyLbOV+JgFhZ9xn4TfZV0Ag+K2LQ0dZS3z+yUwhpmTk1KXVzCRiLz1/+Gn/2aN0jt1FvcgvmkZg oJ3tjrUfn8Y8VUGat/QtTkVkh5u2J1mj3H19wzK5Z+koe7HK1MN10B5XGy+Tam0ZOEdAndrVvGt n+/7aRB0yfk4hGiX+12uAQwT0mSXRrEviQQRz1ICu4BQ8wKRInMrLdMk2dH4o2nRa41LDINES3J XgptD4RVhDyhqjU9TGHkA6M7GlDskAdvwbhfkFhm0HlDEwNDlLewYh1xkxydClXwUdr1v5YnsOy 8Hv1t0ZTJbC+VKt9gvd+2On0kdM68894Xy50vnE9aLBIDV6w== X-Google-Smtp-Source: AGHT+IGReh0qFD9/25L9otnnAJhTMLHIgLD9016XRnct0oN/9kvWpTVLUAzzoVVdm/CxflS7aR3gmA== X-Received: by 2002:a17:902:ecd2:b0:295:3e80:9aa4 with SMTP id d9443c01a7336-2953e809f54mr75897205ad.22.1762076997472; Sun, 02 Nov 2025 01:49:57 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2952810a664sm79134845ad.52.2025.11.02.01.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:49:56 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id D365B1123809; Sun, 2 Nov 2025 18:49:50 +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 v12 06/13] x86/um: nommu: process/thread handling Date: Sun, 2 Nov 2025 18:49:31 +0900 Message-ID: <94b1c9a65af9d22e3f21d28bc0fad2f94e1e86cb.1762075876.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since ptrace facility isn't used under !MMU of UML, there is different code path to invoke processes/threads; there are no external process used, and need to properly configure some of registers (fs segment register for TLS, etc) on every context switch, etc. Signals aren't delivered in non-ptrace syscall entry/leave so, we also need to handle pending signal by ourselves. ptrace related syscalls are not tested yet so, marked arch_has_single_step() unsupported in !MMU environment. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/asm/ptrace-generic.h | 2 +- arch/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 227af2a987e2..53c9ebb3c41c 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -27,7 +27,8 @@ subarch-y +=3D ../kernel/sys_ia32.o =20 else =20 -obj-y +=3D syscalls_64.o vdso/ +obj-y +=3D vdso/ +obj-$(CONFIG_MMU) +=3D syscalls_64.o =20 subarch-y =3D ../lib/csum-partial_64.o ../lib/memcpy_64.o \ ../lib/memmove_64.o ../lib/memset_64.o diff --git a/arch/x86/um/nommu/Makefile b/arch/x86/um/nommu/Makefile index ebe47d4836f4..4018d9e0aba0 100644 --- a/arch/x86/um/nommu/Makefile +++ b/arch/x86/um/nommu/Makefile @@ -5,4 +5,4 @@ else BITS :=3D 64 endif =20 -obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o os-Linux/ +obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o syscalls_$(BITS).o os-Linux/ diff --git a/arch/x86/um/nommu/entry_64.S b/arch/x86/um/nommu/entry_64.S index 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 Feb 11 03:42:09 2026 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 4A88B26F28A for ; Sun, 2 Nov 2025 09:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077002; cv=none; b=YL8c0LigAmXqwQtoDtH/juJVWxC/sqnq/nyIBU7p6BohAbS3zzSdiQHtQWFvGle0R/WApD00/gUwZBtYLPdVkBKNfuZpHEW0cyxd6hX3KSKuwbUrnZ9Rnu5+RI1GnCuVTQOqeGPRdBw8uuq/cZc9VO6TfYbiLt8hjmh3a6svIR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077002; c=relaxed/simple; bh=w/P0WV8/06U9fcziuDHn0Wwv3zpkumouszCtz0x7ivA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EBWJKyxEb9t74shU2F4svONTaD8+4yh78BdrVjqLdbNZW2hrV+p4VJmQI/k2S/hIEFtY+9rnodCt3jH8oIdg9SyZoqt6zFN7tgd34sgBwGCfaqc68wSxQJxLFQQFAE7IYVpEBJnbVUTAnhLhQKVtlhSYWpJ2f6Ej/eaIpVTxjSI= 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=Lua6H8m6; arc=none smtp.client-ip=209.85.216.49 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="Lua6H8m6" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-3407f385dd0so1882238a91.1 for ; Sun, 02 Nov 2025 01:50:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762076999; x=1762681799; 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=Lua6H8m6HWuex0+2+eso9rajpR1ykoco35u7xJRNmTgV/mOB5DlcNJxMrsOhbJ+B7Y KelMvCRO+R7c5tgNFiC6PLNpTS6s/RKdZi80ezRI/7+RMKXTBjOM4Wgkp+VA8ovJ28G8 8nkT/Do+n0eMH9Ly8kFY2jTnrPFAq8r/FzdF4ZA0C+WKTxjo3DaHmctn9iXJ/AoMhKBO FFboW3R/DhSp05upKAHjoNhpE821zYeaTDiMpBCnHfLuMo2V+sdsZra5sMWY8g2miUmr ThogYKpNJegvsj1HG2utIU1ZsS+ClnUKUwZADQB5X2A64Q6ZJa3zbrHJIT42sc5zjay0 DAnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762076999; x=1762681799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SVM2G4FP/w8QD00uu0HK9wDNN1nmcST3P93SXeGJtYY=; b=WKIOOxy25C8aGLm4N8TAcwF6tpJ/HMKgd0GpbfbrEDbdh7q6pfr7SCrQHKLdfJ6rzK X6mt0WTBWNtBIGTLRHWyp468PN02Kgkggwr3H+U1PI/HKFceTRZEy30c/InwtTGLflv9 cKKd3Io5ARlxCCRiQ3j/bUI9juX/vWa9MCSo9oZWvVH22/YVHBfrgtmvN/koAKAyCeKK gQdmAYctP3Ko8H8VLwsJ/uhkasDq5La5DTFzhUo2dTBZszIYe7AfsDc3lsaSKzmzAj0i 6hjzHhDzXCFot8WgQ4Z9GWtoqwgTqMrO5mggaDIHsMGHHT+plADcYkCBcZittElG25lj Uz0g== X-Forwarded-Encrypted: i=1; AJvYcCXNhFbLmGBJeSJ0A6rvBckEOTsiH3lOxU8cLFCbMR9YUBQ7PJLDiheFuhouUktB0GsC9cz8jK0sAyK+arA=@vger.kernel.org X-Gm-Message-State: AOJu0YyTEnIjPAHKbzQBZLIAZqwV/TujoJCDkebgxwjBTWxpxeDsQLTc RKKS9IsZjVO88ouRoEUWG1nTE2ulfwiWCOwom9gP7axHUHkun/tUcOI5 X-Gm-Gg: ASbGnctRlYfWykMr9ZLsTtw9GF6LeWcLpvDv7xgtGsfm+ZHxwH7FVAQyjEOrYMb3Jml LybGW+8Xb2BhOjvDajqyddDaRn3yAD+QjT2e37MSSEvsF0wTOv3hhRoI+RToDgk+QOZfPNtCqdB RXd0p0iVvgCv4WS4VmY6wi2EwGdEPAXhGvTi2vbWQ3KsdkykjQjxEp2dZV6oJsfftYeLMG5PeZ9 leQQXFuqYPDuIjBnQ37ISHdyteXoedQQFC9vD1Q332ACUQrOa4BWcsSaihRyZDPsUhD7nX9iU/N cLvRfZnn9LUemIXF8vg9iRwjvrckiznLBMvq75e1xlXOLH02uLHfRiBF0i47q8GrVcgIwhkDmCU 20K36vY/FCMnSALUB2xlQDSjXD/s0R9cDA8Obk9jftnJK+J72yf1DMyPwSP13Cd1WCwDixZdT5u jwRJbIyfAamKCSfGc1+UVHKfPCQczGDDYUoGEVrn7wQmnToUu4AMXZ1yv6 X-Google-Smtp-Source: AGHT+IEGAiub3al+B+1jEkCyOgGZofHqkuwFGRsJXjVCnAfatIVXeTAFwQSvpFLTzPP2lopemXTUgw== X-Received: by 2002:a17:90b:2ccb:b0:340:f7d6:dc70 with SMTP id 98e67ed59e1d1-340f7d6e39fmr2375548a91.13.1762076999483; Sun, 02 Nov 2025 01:49:59 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-340d1a4a587sm3387074a91.3.2025.11.02.01.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:49:56 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 5DC30112380B; Sun, 2 Nov 2025 18:49:52 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v12 07/13] um: nommu: configure fs register on host syscall invocation Date: Sun, 2 Nov 2025 18:49:32 +0900 Message-ID: <86fc0b173ac530454a0f0e33f5100e0b60e37730.1762075876.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 Feb 11 03:42:09 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 A3D6A26F47D for ; Sun, 2 Nov 2025 09:50:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077003; cv=none; b=hZojA08f+G40S9FA2u2UcaICN2dYdA2OxUeinw3NbP7vEkqG4bzGkw7ds3wn1MhXQ9D2g/fcT5uLJctDmNr1A10HziIkV7mA80FaqkkCt7a9W6N/Ad8WOtiVo+l4HopyTEXiYBO01GoXU5HAoiI3jzADz6Kj6v8zgrbHtZGgCO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077003; c=relaxed/simple; bh=xTw1fZj9TABghspblzMyZh7aJYlpz7LOhXxI2BNDWxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gd/r+hA/vKqQNE7Jqcs2mV5N863StxKDFObOKY/ojxZKjRzp6W+ByUEhjigbpJvEhV386a73+FGfomPUiG0zCpsFnxfQ9VpOrMg4fE+VS7QkBu67Hi0KqmCxTXa2mzQYmX6BqLKr8ywwRrvgYHeLs1Wv61UI9K1Y2WWjKqWZ/5w= 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=R34IH01p; arc=none smtp.client-ip=209.85.216.53 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="R34IH01p" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-33b5a3e8ae2so3807586a91.1 for ; Sun, 02 Nov 2025 01:50:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762077001; x=1762681801; 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=R34IH01pQ2mVcxKuC0WakEvhR1IP+HeIaVoSnrkZfebuZV1NkPBKc2ntL5u4dPmSzw un9DmkQVXSQJXuYNey3vQd3AI1cnDw2bm5nWiXcwSUv+YGLNTq8gUJSC3RAOjmhDgsIB NSf8bak/vKjx9mU3CIn3es4DJpp+zDYOtPG2DyFC4Bwy+Eh2D5TFcIHorAU4CEh3FD+l yOPmDoBrVolRsY4tpmFrrSyUjOjS301gxmIS8JtompwKp4DjyfofuR9rl674DlEGYYJs Jzj8oB/td02JORJFeAk5hF1ABQ1Lu344Wr6IfpS6SgBQthRoVkrEIvafpHf3NxeFndhB dabA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762077001; x=1762681801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KXlvIxBTzUi2fvQwFF5f1ABJZvc5EYR8EZzXkNvyLME=; b=mQaYRvW3aVpvZdsogtqfqhhSwdmWwvtbkXdOzLf3pAA7z23AWMbAses5QZ1gkvGaqL 8Q0qFp6ydgdwdQL8YlMF/SjoqaviKqPL5oyZ+vBwpkyVb+ugo11l7K73oR9PYMXhk4zY FumTO3nAnoNoBbhzzbj2xLszaAFdjtM6nKYb+oq4tuJU/Qlg7tePcZa/3qoKkE12a9We PDm7CjREdD+Nykv8HLKbYk4zQbVs4PpdUGXvtCRlTylwPv+CK5BJ037ZooZaJ1k0g5N+ oCoR+e+gB28Q5nOzDKc6/Xp63HlLJrfHkNb1nzZH/uZCm//G6siqsieKZY30bKGYOfuw gbXw== X-Forwarded-Encrypted: i=1; AJvYcCUCjtTY2NZQhlrOD90Anz0xMZ5Czc3PPDIVs0ucVp6o8SXoBZVOn1Us3d8U1+IXDziA37r0kjqg+llpWro=@vger.kernel.org X-Gm-Message-State: AOJu0YwNygxf4dlPPFISup+9gvSWchT2/+LKbKaberDkxA9RpmO2WoKd o+6FyiJc1+XzTnOy7FeuYfq+xI6rRz7hFDa0nxDSYjCrsGFTgSzi4kMV X-Gm-Gg: ASbGncsbhQXh/4t2eHZl5Xgf/zASDanNZD7aCifYzURVv5SJ06z0D7bd+LH42dtykWS HahzGOvL2+oe5q9leJAyzVus0wmeAheeG9XzP3Im8vatGUWCmo/cTgWef8hyyndOwM/kB7UP5su pGvdCTtd/sce4/oc2M0Z0j3RgAr+ftntA4tex7hkn420dolTfMaDyPt3gA6kQaoxarWMjr0U1Io YzHssqVycbsOkHeltXgIqHwsRl3fDpOHbI8yvJP+jTA0jkzZxENPPJ6gM57AA0T+JN/3iGI0BxI 8HNpmNsVXAOIVPcZQvIpQET2O+OR21Pss25P4qIbhPKeV0qmBt/ZoptuXpiHd7s0YVHY7t7EdEg IPwv1ljxZpuk1F8hGskcIXpaaohtyR4ds6c0fiewhaNLULxn4ATJDGAEuIIOQAQZlYa+K8+a6ks qo+BaLKi5LbnTpY5pxIx1oivUjnBk1751y9FW7SmlBHSOLhQ== X-Google-Smtp-Source: AGHT+IF6VpzjPS9k/xuod2eADBDKoo5bQTtUF+qS4DJNZKzsKjProRzGMXg47Us7ItLnPnxUlti0ag== X-Received: by 2002:a17:902:d505:b0:290:b10f:9aec with SMTP id d9443c01a7336-294ed2c61c2mr141344925ad.26.1762077000826; Sun, 02 Nov 2025 01:50:00 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-295269bd6f4sm79732315ad.101.2025.11.02.01.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:49:56 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id B530F112380D; Sun, 2 Nov 2025 18:49: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 Subject: [PATCH v12 08/13] x86/um/vdso: nommu: vdso memory update Date: Sun, 2 Nov 2025 18:49:33 +0900 Message-ID: <8036933c8c46dbf1ec32b8b57ecebc94c2cdb2ca.1762075876.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On !MMU mode, the address of vdso is accessible from userspace. This commit implements the entry point by pointing a block of page address. This commit also add memory permission configuration of vdso page to be executable. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/x86/um/vdso/vma.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/x86/um/vdso/vma.c b/arch/x86/um/vdso/vma.c index 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 Feb 11 03:42:09 2026 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.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 253EC270551 for ; Sun, 2 Nov 2025 09:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077005; cv=none; b=SS95V/rZ7OPjxe2bQ7uQu++2ky02d+/80WNHtTU++uuoVFsTMN8s5ffCZSEUAOC4rGWpd2RsBxuQh6qjuin4kWYiG/4W8zxNnq5PVw96McLOy/1QDOhLzPgIAFoOCgDjqyaVqfpVvSAlQVTgMdS8tk7tY8TJZLEN7Jy7zEdfW8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077005; c=relaxed/simple; bh=Q1RsL2/EtjIgu5QYIPwEJ1zosyelA3KCSVkAQjDY+RA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cXNyLoB5qDAIpb46k19YXBSHOxXv9tKjBCxYzNW4MUxaKkV7P88qJCrRn1exrgWD4Jso4B513eHdtSXHLEG98+0Ia4BapHrEJBcD6qnoMFHU80WShhh5hiZ7vcA9RMG54dKgR9CQneVX1QUTIssMKlUpshbb/uIIoNdwrjiWfVc= 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=Fl9gbhWU; arc=none smtp.client-ip=209.85.215.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="Fl9gbhWU" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-b9a5b5b47bfso192401a12.1 for ; Sun, 02 Nov 2025 01:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762077002; x=1762681802; 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=Fl9gbhWU4bYCCFThPOgBZQ91jRbfpdA1UL0AYp9JyE1/x93s+dwRTqsLhf21/rFKdE 5SIvbQVc9snHxGz+V1hTCK5NVV3vuYVeb3P4r3VIuSM4PONKMh/KFWCreEOOsLhGhX3e 1YRYgqLetZlqcmHqJ3wtSq8HQpoq++nbC9zgsAFtVmxYG3SL7NQcl0vXPGPvlaCBjFeX w/u2eVsJznA3RPVrcnilNT6/8OJdnfUq5G1kX4XucRfzSLqAQgAsIwLgkFzy4rsY1lP1 FjGAA+e4Piq9RSZ4xIbz3l9/sTSL90biBDlkwkto6aAhU9aILsCiQI0/lwDb4Qgvh+Qw osGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762077002; x=1762681802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sZpI4L1Kh98JdhM/QsHv9mwFGGWJGOR2fxfWgHIsbW8=; b=q5FxxuD18Ztlhmoehk8Tub2HZ6Ppc5b2KIDe2aycAMMoucuFllzSEj3Z0IP2uc31hL 0L4ZwgLYfIftYzS5q+pk4uZ/KvUQNQZUyR4+8p+KypsYSOudqv44+7ArrIG7I5WrlcIB c5jpvveQN0KlBdEK8ahZLWOV7L/ZhQcXuKZme8pfOVOdRjSda18Lv0BzILr/TOuo5IQA NkoLiYDjEO4Yg2ma0YZ917YNQwCfxFS0C1V7/JnWnyFiKsKlcfnZkZwq7N0D6RSYMwW6 t/2nBEovJCDnHciCtZE7oSMRkDW4bdeC3+rUub6of+KsaiNk7j7FzlHXlG02D6YlIEDh eFRw== X-Forwarded-Encrypted: i=1; AJvYcCX1jIzXWoc8dqLcdB8e7lIOJuU+1wzIHCgRgZPT092CzXs0XJzSd3SDSWKjGM9DJbyfhuepjPWcXVpk6jU=@vger.kernel.org X-Gm-Message-State: AOJu0YyP3ilqYU4nLH9ixjKwkD9NPKT7aWEUqHlOlwhPajmfYzTRwyeh ibqOPgJwMeE5RtHR5/JIlkRpkca0Y3p9YP6ZggwkxsdUb5smiI38Nbjd X-Gm-Gg: ASbGnct/icFZNJCQN4L7SvZXfIL0yq7Xlv/tJ6Ex0FDrUlKLMsp1MwtUYxvnYdg/HmS 1M0E5H0XofYfJK0V31RCV74C1ZsCPZ6G3q+nxjHElwvfqziMz+aFkmpAsysGbXL3WQjvk8MaoCn HO/cCg66xVLEBV2BrFDi89LgIc3czAFmX63r0zvKoPDM/t+v4FbZ61f7nbtvjd4fsDwTqg8NI5r NKX9w5CctWbIfuyRKZ6R4BefSyf3pX780AyCl0Q4ALHr1nswtutDChu7+tlw6chGxqhpqj/53Fm T9LT+y5xOrDqANNhgnTg0rDGk9JUJ1+Er58/oMxbCq3b27YzDEcIrvfAQrXFEq/jBUKkEZTSten XgJ9ulAh9n+Giy3gVAWFgMhsoaoP46ZSl8E+SHxq8d7BO4Bd1JLEyPdgQh6/TxP5MRo6ar2DLsE CAbWyTTdjzzMO3xxEUUSbsPazsnoAYToxTf+kvsIKAWYD3rA== X-Google-Smtp-Source: AGHT+IEbHt8HzruA82vaWyVMP115xJROv7lZ5AWsz7H0jSQB1/KL43tJCy4khao1owqwLyjejtW9ng== X-Received: by 2002:a17:902:ce8b:b0:295:560a:e499 with SMTP id d9443c01a7336-295560ae620mr65873175ad.5.1762077002176; Sun, 02 Nov 2025 01:50:02 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-295586482c6sm45045515ad.22.2025.11.02.01.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:50:00 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 0AE49112380F; Sun, 2 Nov 2025 18:49:55 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v12 09/13] x86/um: nommu: signal handling Date: Sun, 2 Nov 2025 18:49:34 +0900 Message-ID: <32debc0728ce22cd4db50cdf1cd4e8db430ad402.1762075876.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 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 Feb 11 03:42:09 2026 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 B8E1A270EC3 for ; Sun, 2 Nov 2025 09:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077005; cv=none; b=ks5iROqpdWxzYSCixuxQbEssIsqEQ0JdVHcoInNzh415KlzVk6V9OzfIs2NIJ3INFwlE8+plZndp2w2eI8IefktNig54l5kIlTxiBO5JJuoOjSnAdSWirzdcEI3tt8tQbv4V2dLaVSjJfseDV4Vi81jPP2H5JaPfg7ujVQKleRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077005; c=relaxed/simple; bh=cP8tVJMzsmQcslbRgyEI/3kjgKDzqbQZXJLwSVZ1W2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O5uSXYukAROSDPHLNvzQAagtD49Ee8JV6tOJ14L5X/gCVmRY4ljvukIQmLOcXo4zn3cqkNnQ6THUU82TjZ13ds9KzNViJ/UU4Myhp8o8iEtfyYUCuViVO4PBg6bCCaa4u4EPMTlPCxhT2NCa2b0P0DygZIEdsrHr3qNdo60jD6s= 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=YGMj69tT; arc=none smtp.client-ip=209.85.216.52 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="YGMj69tT" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-339e71ccf48so4076357a91.3 for ; Sun, 02 Nov 2025 01:50:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762077003; x=1762681803; 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=YGMj69tTvSRTNY/wUYMs7Y+6gJz2ePklYCJwELy4wvZjZk7oQtB1qOp2tjnxg+c3+a W6NNr8xQkUJ1vsitqLqlneMVbeCH3EFCdMTOK2+tD0pDXn5WD6xX7SsPF/mzW+2Y/7D8 9523bauD+gMz9+1sTZO4GEmkPlmEBp8MWt6SH/Wo48+/3w4C7+PeOISC9gDj7HHvl4PJ bbD0W0VF+i8pfZ0NikEEryUG7wq+4LX7ZnX3OB9lvcCyIPXFU/GI+9Md+SmzBAuxFFb9 YLGe0Ytu7tiPWoEQWSph96e1EvuoJCPO3tTl/XRG8ibZF0RDBJevWT3lw4du+i+8fT3H /k5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762077003; x=1762681803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9nqBnkNS4GHBgTUiwDcxL24xHY+Q8FfpyTOYW+ItBnc=; b=WLycF/wqECQcfz2S4QLPEUgFSDpo7Gsec+rtjh3B1Sr38Zn8o9yjOfkJWfA4QFeCa6 X5yfoVnYGZF5riy4KDOB/BbucDtTEPgym/TbT8DV4Llr70LYlscpUVHkj9X5ATfxybaH EA72kdPus0l9xNpc5a27dPyPdtZw1E5EX6ur+j26C6SI7YnN0dHl0QSViNsUBTcNt81Y IeB0luyXTLWQ4/3EwnqiqCGb9rHeYFalmsBXtUF5RwGNq4XjciuktJ88AncgUYs1C/wI eqX4ILpxzYNnQoR4JQFRnBa1CGrT4iak541x8KSx11SUtw04pkLkHVx/aCvvKdB9BVma /Xgw== X-Forwarded-Encrypted: i=1; AJvYcCXz69b0TyPieIjAWE0t7LnKycH/ffWnaSMq1117UJZQEycPPalN2i1VQqPslBr2Dpq0xy5uXisY7ZvBXus=@vger.kernel.org X-Gm-Message-State: AOJu0YxKUQTBKM5vM+S7SNxZS5pIQmasb9ClEqrM6pNHdruIAzVPiSgJ DUEd18pfPNPVwU/oiR7dTO/G9gi97FNsSY877JWT/2qwziR3CRbV35qf X-Gm-Gg: ASbGncseAj1nPxL5b8nbpangMQWG2/h4CbC+E5pvMW7uw1Bvvg2VAiC4qqkHeOuqRqI qk2i7zcrTM+SsXEN6ujflN+ksqfVgltVv3nEy7keRRpssXr0JhLxvr5cwFmWtGfe426MyVVVTBe Ut8e/dp+S5FS1gkt+4+THRsCAyFwwuaGCtsO0p3fSGAODq5vG7israjn5LFIUGd+Zs/nZbKWB4T DXGNVxCc+2l6XtUQMgfkWLjuZWYWeI57iPe6jGDmzeM+pKgEihrWAJ6wRCvsyb/Zgb4Ku7uQR3B 9WxX43E7vNIWvXoiNfv824zSOj6f8hvFIcqswlAtxrGDiI6FS/JGX53WqNqb+MniH3TnN9Y0dVO 1zOfDUXbmWnG0GPNOX4ThTP3o8aL6xv8xGLhDRlAvIPSeIlhgY4PsMShDOloy/Xrc9JAWELIeCS 2GvSsJy/BmpCRq7i4bz2SsZtUpnXJaS311e8IiKIBAYGrcgA== X-Google-Smtp-Source: AGHT+IHuXrm2fcu4utkxWrFy+W8BUf2g500DhuJfUTiIskvkxoz07jb3DhqnxeSGx4/0+emeuA/vkQ== X-Received: by 2002:a17:90b:3e44:b0:341:194:5e7a with SMTP id 98e67ed59e1d1-3410194623fmr1787362a91.29.1762077002893; Sun, 02 Nov 2025 01:50:02 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-340999f9943sm6854469a91.1.2025.11.02.01.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:50:00 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 971AB1123811; Sun, 2 Nov 2025 18:49:56 +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 v12 10/13] um: change machine name for uname output Date: Sun, 2 Nov 2025 18:49:35 +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 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 Feb 11 03:42:09 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E089A271A94 for ; Sun, 2 Nov 2025 09:50:04 +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=1762077006; cv=none; b=DO2giuOZPOggtv193PrODKl+mVzoitDcQ33Z2Z7q2nDatH/MkGFVmq2x1V/1MnYR1kN6YQ8aI7a1hVqDAEFNXAPw6+9Lsa3mjjt1TLQDl2/kcLz7tCUGrCMApwaMP8DEdKZFsM9Ho0CCPfR70sQpn8yJWA7SvvMWx5zJNtTNmF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077006; c=relaxed/simple; bh=gv2QVhcMmEMjQ2DKMNqWKgsW+lI0oArue4IoB/hcybY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QSM3qxddCCfniM7GTNFaq5W8ZtwaXWXxCIOQ7qRs+tuRhhfSGz7zcq3U0UevojA0fvYubUm7KeiI7lBc9o4cItV2F7G8vGjFXrlHg8JmwtiUdgJxTJ2DWbLh6hvdfYU12wesniYI+BptvfdNfcJcqHPFLLxhhAmnsXFDQkaKioY= 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=ax8l2UFJ; 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="ax8l2UFJ" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7aa2170adf9so230009b3a.0 for ; Sun, 02 Nov 2025 01:50:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762077004; x=1762681804; 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=YfBGkCpdCJbbx8ptfVRSSTZ4TOwzXcv5IKpsCTLcAdg=; b=ax8l2UFJvrgYhg7U7SAAPIRWqyLebUTDcWlCKDwRe21hlxZoL4QQz1hlnu6b6skgnN PXqgLl7j+XWkq3Rp5H7hO05phzXB1+gyeVXbBA6yJQSghKNp2hpaMIR8MaWVxGUwD4mP s6XnQunVlX02knSTIo++liojFqdcHBK1PJWVGAN1izu1FEdTvDYtkcYnRSVPgJeTmG9Z CAjW5wyf6TiJOfxPxDUstBYDeCIvJ3zqbx9IOye8iFyGAMf4ZVgotjacdX/5NSY0sMfK SkUhmE6lhg67Gip8egyHa8U/lElk4JXk5/fjcEM1piu8wFABrnb3Ok9eusCvm2g0pwTp rD5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762077004; x=1762681804; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YfBGkCpdCJbbx8ptfVRSSTZ4TOwzXcv5IKpsCTLcAdg=; b=HjZGva+0OkQaYf+a+vtsdEyup5/rul+HGy0XU1ZA3pFmFqCAzlivvCy3VecV1VUjQD 9RpmIvsr6PG3QEE3MuMPrnylh2n8uah8sgOcKjtvOMVnxWMBywyEOLOLVVd8SefQkqDM uuWd6usDiKuqNTVgRhJQfdRbLAM2hVKzVzQAfcP5eghu3HUBnKl+IKOK1OpoHc2lgY6J pGBzlkX6/MHYyuCAEB0u/qdDMYcXwCZAYOYbgBMuuT/8XFuB4X8mAyF8HGl8dB5WeVN5 /FwQviX/X4/fWJHSeOzB8u/QDmuSu04UBhawg0nBmrpld51TjQLb9Fcz7hJ10Foc2NSs 0zVA== X-Forwarded-Encrypted: i=1; AJvYcCU/DgmIXL7NVArFX70mAXNZzY1YIjdssHk8IAPm0ATKzv8/f8NUD9pTgrR8iOzG2tlpoOBd7BcH/mTWvJo=@vger.kernel.org X-Gm-Message-State: AOJu0YxpicXeCfVgsYsaEZLg7vOvinPRv1IHA35pTaogLcDpOdOpDGXJ SPWy0pIU7jej5FczdVRnw7vL84WufZAmo8m2uIS3aG9FllUAKqFWU3Q4OZNRqQ== X-Gm-Gg: ASbGncvOH4ZggBfpZBdODwdMJx62u0HzJEDLyf93QhQvvzx13UrDVpmjc2HkCsf+RtM j5T8c9PiP34Kj09AA2sjPEwz6IzzqgacmB1qm51iInvNbHOZHzXBNQ/LNDKAhZAj3C5VbznxlnC Ypo2U8PN/WUETRsWFR5GLObqCWMF3+rJrQVD60riS//QzsD1aRpsPmYzFiQ94Rao5qu4NBaMbvh 5V+4mqo7A/WVIghg1ODZJcp9jg23vaVa3sgWw00E97xhmYXifwSv1feuhWiHjQRpPEKPfIk3IW+ 7oiq0Ubzs5m/7PwVL6B+hV8Mb7b1wR5BnI2yB/cxvBjuRrVJ2xmXCGbLlX4lAmEs1Yepj+H6A8v MItnRZTnNhsSK1K3VQw6+QCWUySkDL6Gqz7PH7O2lvsjgyntlbLEHZboIXO1cplx05+jALnSP60 SHscRqfPVn8Vru9Q17ypkA2ghnwQiotnPLNEkHu9UPBTIAEiVs7x2Vgl2b X-Google-Smtp-Source: AGHT+IEDhV7V1q+X2A4WeUCbo0ZHZo62KKRfx9fdau0q/StwiLJYD/4G+s6ryRCgEgHJrpTQR06FxQ== X-Received: by 2002:a05:6a00:2d1d:b0:7aa:8397:7754 with SMTP id d2e1a72fcca58-7aa83978122mr1186234b3a.2.1762077004150; Sun, 02 Nov 2025 01:50:04 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7aa76782f1esm1243225b3a.67.2025.11.02.01.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:50:00 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id E59851123813; Sun, 2 Nov 2025 18:49:57 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v12 11/13] um: nommu: disable SMP on nommu UML Date: Sun, 2 Nov 2025 18:49:36 +0900 Message-ID: <54839396f81bc2755728a53912bd8fcb19b889a1.1762075876.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" 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 c52fb5cb8d21..2bc18ecad783 100644 --- a/arch/x86/um/Kconfig +++ b/arch/x86/um/Kconfig @@ -13,7 +13,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 Feb 11 03:42:09 2026 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.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 B44AB2737F2 for ; Sun, 2 Nov 2025 09:50:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077007; cv=none; b=CySBvNTnoiY3bIDqEJtJuY9pLnRv+9fYa6kDo1IRcYOmtdEv1QWxY7hQzGh+JNgreIKzdigmVeRf+kknS58HVDt2lVRloYFOB7ImKQCO+JFXXu0cvbRSNftwBqaakC8NGWzTUyLVwKO3SgeSNG5Vw8OQKGOarxBEbZJOeeLJgts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077007; c=relaxed/simple; bh=zibfGPnHjDDfR56CnEZcgy7KJBvoyjyLYqaq7S1mZJA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lZTNSUtc0jqhBSzpAd3zNO71h0uSx+SEUINbYE6o3KiEnOVe3oXRR87lFY4JM3cTaBGq/JkSS17Sl9K0GMF5HfykXHZUbmTa4ZdpKFHV/bpNr07sfbNaZ3C1MnyKMTJaCn36wdEEuYqwnLjzb3NvIWkvpq8lA/ZEBxi1Jf95jbQ= 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=UX2g4X27; arc=none smtp.client-ip=209.85.214.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="UX2g4X27" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-290aaff555eso32065425ad.2 for ; Sun, 02 Nov 2025 01:50:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762077005; x=1762681805; 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=UX2g4X27uPUyRnPXQaYADAYy6ozRCiooL0IFQZ+vKzJbl96MCml1T45PrBlNYAmxHT omJDTyaAOEPwAX2F6Qn7lIRUo77y6QVmGHbfDOHvW3LXzehZeXXcF2kJXOdfTyQIRulh GhAv36N2YMo8sSABJkpIO20WSC0Q1KcaVzqs6ai5jDqHz7V4M2G9Ezq58MrlxgRfNHYn KyGgLiZXw+9Lq64IFx/qo1jIztSVZdXrHdfsJfgUzFmZqaLSOfQj2+O5IGBHvTpkdhXM wzYxFp9jW83B52cEjLNhZvHLJxHwsI5p7DM4MPjR/siIFLkWGuXSBdYRdRUHe1xqzjD6 8MQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762077005; x=1762681805; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8dqdH+bbha0oqzf1JSsYMP+tOcPwBytuRd4+x0yMEJ4=; b=L+TP9iCm2+rfFCtz7o8FLBJD3wIZ8LEO4zIG7JkyXOxVW6qfvw+qYK1XE+0JI/b9GX 1Juqu1e9I4bsfQeSBWhk+A6KxQr4huBuxhQ7XNxomiUrqkfRRZ+zVuYaidLtrM10qlzJ NrwLyReCJDXTLaLA2K3qHatH/fdytATV6Y+9cd1DRAING1kw7hJUaY0TityC72AEG3Jb ScMvgmB0S0+B6gqfjo71AUGATWZh+LYBpL2X/fJUx9e9B7Y/UsxMAwEZ9pvl2wLmXBh0 PbOSAUkIQNMRfMjwO9SEYq/gvfDO+9T/qtb107jVFGCN07VpYUry/FMA7nwURP21AKLi LxlQ== X-Forwarded-Encrypted: i=1; AJvYcCX2NOJKqXktgnBiFFSBJ7YwlEWy950tgPPQHSMZqmuODfOn+ggeu8hGYDw42dcEpu+JBcQE0vzrUDk19GY=@vger.kernel.org X-Gm-Message-State: AOJu0YyLC1tefLkty8Vgwrt/7TqtsVgWWJlOEQn2y72pm4RHZcA8lhPi 0U0mdS7TMUIsSby5FtonfFeTtBrEf5lMhGZe5LQRwcF0f0tQotM8/iEj X-Gm-Gg: ASbGncuqPem0jSvDMaJ5iPub36cq2E8mzn3TQ+AgNGOSaNNBTHC09c435ytq3exc5js sc7paFF/I+nSFVmDXJHdW6FKwiE7OCquVLizLNOaXTtpufM5nmscc/4Jp2JTfA5AdsPV8dJzxvZ cvHEQc0ZS8PT4r4T1K1qYmYcUwg7uIfIAZTm2yrVWghkE8e3BlL9YViHDvc6t5GOoZUo04VMoQ1 O3ooO6eTn/Tg3CFH/Vxn2W0S5pqsNxku/yHSN+g9F2e96zuAqtsSt7DR9Ug8t4a6GIVb2VjLCAg ohzBNkovEE1w0LtlN9fZYa09FHA6fSZVuWllkU2n9sLVua3wqYobgnLGqNxowBf0vVSjqCPVUaq omRFL+dFlFJ0smNO12bJAmNjqBQQ1QhAFp7FISEGmNZHrk6jxN/TN4tvHY4a9iZ+86eMSoFyRZu Fjlt9pZHzwX1tbpULEfMr9JMS+V8hgXDK56wlES+hEZqwvsc693+DbHcU+ X-Google-Smtp-Source: AGHT+IFTT8mUkp6R0uskWG/57yRDg57gYJx+nISTWHd5GAVvqwpyvi2KaA37qjTacNm8b/KIx1pAaw== X-Received: by 2002:a17:902:daca:b0:27d:6f37:7b66 with SMTP id d9443c01a7336-2951a486898mr125305485ad.47.1762077004804; Sun, 02 Nov 2025 01:50:04 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29526871b31sm82851965ad.8.2025.11.02.01.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:50:01 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 5B4291123815; Sun, 2 Nov 2025 18:49: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 v12 12/13] um: nommu: add documentation of nommu UML Date: Sun, 2 Nov 2025 18:49:37 +0900 Message-ID: <5a831d893431c15a1bc2833cedc5a45cdfa44cb9.1762075876.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 Feb 11 03:42:09 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C55BA2741C0 for ; Sun, 2 Nov 2025 09:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077008; cv=none; b=FuR0u7eV0cjgmS2aNhgLSPHIIBRrO7xyHIRAQrAE2OG99HpJAUA4++7HNq5CSFoaLcqsZC5/ViYoa+BtK2Nxe65vpChJNxDViinHzxEZ+kaobmfM2tlmd/d2bTpknT/oE8hguHhXrtPYsAY/tvJs8P8iIHf5DWxNhwxO1Uy02h0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762077008; c=relaxed/simple; bh=vFTFIe6I8r5QCp5mBI9sujzCZER4Rq/NgROeYBJU/sw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t8GvbNv6CuNl57ScUcq5d0CUGZrySZejHQD/uYbpMNHknpF585jRPRQcVy17haZhSEBW+4djbwjXt2EnczzjVOyPDYTg478PmwI0nVxrPtL894dnhPEYzAXqfUQ6n4JyafjWQVJ9FJzuLctBAxjYngtEcjuTn2RPgdio881Y5lg= 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=AZLPDNZ6; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AZLPDNZ6" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-29555415c5fso14400865ad.1 for ; Sun, 02 Nov 2025 01:50:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762077006; x=1762681806; 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=AZLPDNZ6Sb4iLrTPxDBK0BKNxnGdm1+TdPurFqznSQ00qnW0MFkEqFrW9ZuAUhIKMa 9xZ9ya20Yxb/72hKquoXTCBVvdfMqxPN6Q7Tou9FqTFV8I5pD1VTKFcsETjtUbsJ/Koz oR4nxXzjjcmb9cZuTxKfsGZu0dc+P3lAoExr5c8gH3/ZYU9SD0DuR2rbZWgrwbRyT0wg cino+t/XvXdUNYwxITLIudH4jN8odWAbs8X1pOVGmqFWcvH2HvgYkuq+ELKDgqg1Edbr pbRySwANTRKzu7fUs2XdNYKwj37UrUBv4Ys7cVKI6K4qc4orVoWge4n0rtLZp20PmYMU q4Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762077006; x=1762681806; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ph9zR1fvONGEfCwcooy4q6QCBsuZBG7EiBPZ3ZJSBIk=; b=Q/pUPp8eNb4Aw5P8S4j1AAZ5d6f9cCJBXyzU+VZuZMICjuAa0WH1ZBMDqhzLWVVr1d FBjJ9oDaE65qx0sOr5MF9WQLn2u1F7lHbmkPM5ag8wX3cjpIinH0O0G2yRYWrhF+kHQh mStJWPTWQ3MMhJrwjYWunL17fCvwko4xGaqMDKqGuCRMn8epXuwP2NPiX0+ARnlj1SxM +KliLvDO9U9L5UO5m6tXXD32SrU/xW/9LAclp78x6c0XUZJyUruBYcoqaUL1ZRXhH8zs 5GhaA14BbVsq+Ple5JZeyokHTfS+OIv3FpUIdT0RdueWvA/OhV16kz+HvHer8WfvbGRd mA4g== X-Forwarded-Encrypted: i=1; AJvYcCWO5a2Gbw5Hi5LBxLb13Cx2RIjECjOr1nXPNRXRpLnd755OujZ3umVrjKZ0VBMWXFkfjPUpEvONRPW1zDA=@vger.kernel.org X-Gm-Message-State: AOJu0YwFWiQSEK637BEdjCctzxj9OAh9LpzBZzjdz4mLNNSBOh6i59rH urKZlGrzpSTzg5cNu5jgqo/Xs8tp25TCLuRolfrht8VfNT/4p/Eb7t7z X-Gm-Gg: ASbGncsQM8XxkaS06fiwMvObc28IDXoCZz2p1jv1xBOILtGJHQ8r+EalGtcdV1mDWej B2wbQfXPSOmvim8DC42Bf7AtQndDMIF4QV8Pyrs2W7qdO2D8uAG4MW7iISy7DmNuaNGPkCjYOf6 LNpfJQNJ7WceH1KEIoCc8BMWNKI3nJuVkFDFFDOIyBbRmAPLt9wF6wJlORaBUus/ViQ9m0+avou TsPPw/qZqx6+I3EaaM8X2hqMcDOvmg0gHgRzzSUjHSV1IzXIM4m9TVLaPKCwZSzEGcvp63cmDjU DLXzceXBFCm+2lYxEbiZEMwuTLgFIQ3wooJd5+AulwJ+IVgIJ5uq/SZ5uVJBgEQsMFsAdvm7zjD Ks8rGxD8X0cTOhzCYSXRyunDdGSvFT8ocsQVsinVuhp+O9hixZdLnkLO0Db/gvKcuRtxHes4Pcn pa5W8Z4skSw6UHZf9/2I6dXTsO8vnq03fWYQaVLHnxQdChWBwWyPYssOpHN08RdsAu+wQ= X-Google-Smtp-Source: AGHT+IHUuWG7Ov5kBT/yNTPJH3xuxkjK4iSTaaCg1YaGK1t1FQzTnk7AwddqLgQ2HelyS4KrdoJ2gA== X-Received: by 2002:a17:903:2285:b0:290:2a14:2ed5 with SMTP id d9443c01a7336-2951a390655mr107666405ad.4.1762077006004; Sun, 02 Nov 2025 01:50:06 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2958dd23059sm18342285ad.47.2025.11.02.01.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Nov 2025 01:50:04 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id B73931123817; Sun, 2 Nov 2025 18:50:00 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v12 13/13] um: nommu: plug nommu code into build system Date: Sun, 2 Nov 2025 18:49:38 +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