From nobody Sat Feb 7 17:55:41 2026 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4090229D260 for ; Wed, 4 Feb 2026 02:28:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172101; cv=none; b=k7KTrQqq/GjNbaTjWbVOv8AeA/d5ocIa/8kS+Z5lzPiFwOrk/TjCE/Nx4CYECL8aL1bx1gdDh0WZvnOmFegiyVeLd65rmNkB0yoz8oxtT1TykWIMrKhLyhAnLf5hRjqbLQ+K4HpbO/uf2GbmoHfjVp4qgrbFDJiLw+lEtN5vXys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172101; c=relaxed/simple; bh=CvYzjfP7rw4yGGJRdX8B4balTna1wcyExbLjMjY+2gM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dKv005y7Am/y9dJ+wV163L1vs0bTxDlDO79IZYe61dxaAX7eZVtuxCfGW7o2/mH6+MDpSVcSHsoVLpNis+bZ3lrEvkvfmLTjzDP11HWptitlLkCZqozn8DR0xdhcSIBx7q5N8Eb8edSKw+sfxVGf+scZHsyVSiJSBINJcScv2Gw= 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=NPev4Nj6; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NPev4Nj6" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-82318702afbso5213471b3a.1 for ; Tue, 03 Feb 2026 18:28:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172099; x=1770776899; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hjmnnaJ+dU4QzslBxUrlmdhSXDXCpeTGjd28jp/dBEQ=; b=NPev4Nj6MZv8TtZc5TUkucKKyaCeCQFsQeDygiaMV3DK5IAeeRLiU0dxtGdpj5xcH4 FN+KIgKdn5EflUydJEQft++zWabJhZEIQAk6hvvkjlfyIBTO8oV2Le6VA9+skcivWo+n 020qaMgi3VlPbfuQOQUg3ElgP78KM2bA1RIpka7vVlVGk+ynlQCY/dE5LQZfLC9NlFiH 90S1Ybquy2LRunlQZANJs4Sufrvsstfico932Ta2S5gCno6quztZSon7KZnCOMvqqSol PHvIVOkL+3QYplbeRudvvr+zFGsthi9a52ELD4j1quPiaMEgQhAW3BiBSolzW5WcV7kx s5Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172099; x=1770776899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hjmnnaJ+dU4QzslBxUrlmdhSXDXCpeTGjd28jp/dBEQ=; b=P+mjeiC6MvcNIFQuyKd0ynEOwa9yzewuMwsx1Ec6oJvrRTCpqlImQDc0F7UqAFswdI FT4/Nc/d4/yrwrIlXZQNkxG1red9R84v0CAHQwBvhBDjMwto0cacDF6Rk2AHcN/PJ9Hq Qc/ifC/gSdH5n/VHYAeuwU968/k0GwhKnPAn3IuQO0GmCWpT6BXiebTN8KgtnoijRlTg OT8FHqix0X9fHDLQtH1JBNB0xDR9B9EhPsFE+I9t5yE7+1VWK40jg1dkekrw2DZHuxQn QC7c1G2cC0MRlewA42LE273iFleYg0IaM9aVRK7XEzmexhzDfO7aDhBRlZYar8LOjQBT k30g== X-Forwarded-Encrypted: i=1; AJvYcCUHTPO7gE/GW80roFmS9YElEz40AlbzC8ANDDqd81xG8R0IszjJU83MzFsU6fE909g8/qsQKDuI2DbXwOk=@vger.kernel.org X-Gm-Message-State: AOJu0YzeqG336REEcWMmkSwExZ6XIHU87JL9kwCCwn1U+kiA2i1NxaxE qYSLLcYSi4kBiAZyiGVQy2cMB9jL4viic37nEXRmA1NhUpXtmhIToQCV X-Gm-Gg: AZuq6aK1RVPGSEW3QMkGRZt6jFrBzVr+8awIK09Tv3YWABryUvICVF7poHqPRXTnXvj trRsONsuGBHn6gTNEbvVVM8p/0SxqsoGCjivOmzvacZndVJQ10jSz1Zv77VrFSmtmTzOwbke9T5 LMGkvCj+nvfGtXZgTxN2y37owbwbOEJSJfN+neGjFtfAXyRq89ntXuOUUcNlz3gLG58/tkpxMXT nnzwE90AT7hXMB5brRayBukFpe+IBzcsYiQdCDJyVs9dwt/FjVJ0GjYx+XnDb3VYoIT2qHgPGe3 pq6+/d78a9E4e+qlVeF10NmcHfv/ooXp8cxAAsyzBiKvM697iHXCC7RWnQT5lQc6Ngm5BVznPSo 0Pqk95aZ0DRHu3gukjNz20xO96Z93yzIy265E6SF/ox13qS+1wdVrdImkKye5HWEQ+arHLtrWxj TYUMBdvcJhPGZBLkwEyNz6qPzAUBoxJMjeMDVnhhkviayE+fxeVNBzymYUo4sxw6ADUs5hBp93I mSTwB8MLwA2sZzp X-Received: by 2002:a05:6a20:a122:b0:370:73c1:6a87 with SMTP id adf61e73a8af0-393724cde89mr1471194637.58.1770172099431; Tue, 03 Feb 2026 18:28:19 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a93397c472sm6721415ad.89.2026.02.03.18.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:18 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 421DD1200C31; Wed, 4 Feb 2026 11:28:17 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org, Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v14 01/13] x86/um: nommu: elf loader for fdpic Date: Wed, 4 Feb 2026 11:27:59 +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 22d0111b543b..388fe669886c 100644 --- a/arch/x86/um/asm/elf.h +++ b/arch/x86/um/asm/elf.h @@ -9,6 +9,7 @@ #include =20 #define CORE_DUMP_USE_REGSET +#define ELF_FDPIC_CORE_EFLAGS 0 =20 #ifdef CONFIG_X86_32 =20 @@ -158,8 +159,11 @@ extern int arch_setup_additional_pages(struct linux_bi= nprm *bprm, =20 extern unsigned long um_vdso_addr; #define AT_SYSINFO_EHDR 33 -#define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr) - +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr); \ + NEW_AUX_ENT(AT_MINSIGSTKSZ, 0); \ +} while (0) #endif =20 typedef unsigned long elf_greg_t; diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index 1949e25c7741..0a92bebd5f75 100644 --- a/fs/Kconfig.binfmt +++ b/fs/Kconfig.binfmt @@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY config BINFMT_ELF_FDPIC bool "Kernel support for FDPIC ELF binaries" default y if !BINFMT_ELF - depends on ARM || ((M68K || RISCV || SUPERH || XTENSA) && !MMU) + depends on ARM || ((M68K || RISCV || SUPERH || UML || XTENSA) && !MMU) select ELFCORE help ELF FDPIC binaries are based on ELF, but allow the individual load --=20 2.43.0 From nobody Sat Feb 7 17:55:41 2026 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C26DD2BF002 for ; Wed, 4 Feb 2026 02:28:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172103; cv=none; b=pol4dPwdqhsHRfWEwPBM6QprBbYLJUtBsaAF35XOkdl7sgvM4YDkFKTMOW2M4hDBbvOsxAXiaMDW5Of3MDRDsYJUNdbive7upnnllKTrOc0OM5c2OWugoJWI4x/ZdOwS0x69Ttk8YZh0ufT8GXEdYCXWgVvMBR696SOTsHpxX4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172103; c=relaxed/simple; bh=ZiBjYTpVGhtkj5Ak/GnH8XcMsvP0AYgN0WurqAcjoHI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ez5RMOxgLUP005v9YfOdwIjBIe2YBEcWM/5waHnDCBrsbO2pWqlxAeAz6cHTZonW0rURl8FCeFZmJh4/gJjwKNNASmRG4ZKL3Ve9807pPkMLpH4oGYnZsFE3Ue55ZP3wX4rl+VZRdnYEW6lwWJvldm7JZnF02QoOUGyeyYqjIJY= 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=A/HgOm0I; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A/HgOm0I" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-82318b640beso3543781b3a.0 for ; Tue, 03 Feb 2026 18:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172101; x=1770776901; 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=KNOvTdYobj6+1S0fsqiY4Qax5jbv4IaGWEMEORei1Pk=; b=A/HgOm0IdV3HYRkP+0eZnQHw9VGY61VyT6O2p0VadodfHhBNLWkcXXtULSOd0ZRPy5 /eQLPYGYjwdpcYBrmagLQ8jFiRws2HU/puDUkLJwMxtvMlb4Qjcv6IVDyZSeliFQdhvI Yeps8G4XHX8ikcdMgXDO+JHa8Bq12E6JN9gzYmmEwikvKWUi4bbjzkTYv1Z9bEHqEL0U Rrgnuwg6/Cmc9ppvyW4HqTsy36tRbxW++NxiBlzA3W9a6lxlAOvuBT6ZdsbiPp7CKdpr KJSXWA/CmOZ/Zul7XkT8urFpaJHl+dXQWRNB6JBphAZjs+WiwCvhkr8VgAoTfpW/2aVq O0jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172101; x=1770776901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=KNOvTdYobj6+1S0fsqiY4Qax5jbv4IaGWEMEORei1Pk=; b=E5hCyU47NORMKhlDbeRP0Bo4bHcYLStnBb5q46rqtbOCSaHgFGFt0pX2Y/aZ8BamhQ gYkXhKsO85Y5vVjc+ZqGw0dgrnrNQJUqrwIVHp4GMy8VYCNMb4Jw/Rv1PCO2tsBggGqP hdVj1E56DSNqZ0t/fH8E8wqoQ5B+ToR8AQ55G56pP7ycZ9XVSlKxwuyFxjaMYCeR2oxI Fn7tkZgT1qij5zr5FnlgXQpe1Rszj0FKfSNggTTss+CUNyi3CJ9IH2cM/mOq8RwH1K2+ 8FD7zrvl9qFQBnVg2fPlTTaDKFk6vLZMSKE96J5kMIqj4EocA/0qhyeohpJIUIXrHHr7 ecWw== X-Forwarded-Encrypted: i=1; AJvYcCU6GsqFVKr1SP/A9gv5qR2JwLBfeuJbtLlyE7wBfnjMx/YgAhQ4HMr+ZO6hS1ecCCee4i/yr6lgkgvB1To=@vger.kernel.org X-Gm-Message-State: AOJu0YwS1yDzkKlMoHOQif+QrhPS9FDoaaOd1jkF0Jyx+++KYSmdfXeI T7NPU88PCpNtAIyr969dTX7ye4EqDnIztMsspw8fl85unITlRvZP8gRv X-Gm-Gg: AZuq6aLIGTVuHQub6phfzkXf64oIv0eQ8im73tYwTCNe8oSSli5Yg2JZqdr+8rC6vwi ktZIgOaRKR2j12+6it8uvvXSpWhDn3Ihdn4SPZWLB+rSOjR63zGTar8qCbJiZAIUI+2gCxs4wYy UAqa/g5RdWTc0mwGp/FMYOzsbKACvVNmw0Z2hnIjBldM+FOJSOcJcG4H8qbbolEScTaXMsEOjMs B9I9m32NBHFxe5UhgpGyCfZKJ4s8cy0ZYVHMbdtry1zjGM9IKvgUaGMBaYDjn90vA3paaweacT6 YSstnp/yWKDtM5QsOcXUMwSbq/Zm9JxGcRrHe0nkKvo9hEejkexAESM3vbmRg8aUntOfEWS+RSH 1a5gYJkxGTR7r4ZRC2LEBJDRZYJony+HOYLRLOptbTE3W72JVRG3jPwkoMfGPl2uV8u80DBh7iM eImsCiKFP5knUqtM9sKgKa7fASXdpWMJ9vjPIbQU4PTycTXCtNFKu10TNoKT6VoX4Ys+qIMGOpS eMI5QGOgEkT6CC1v6oRpjTRpcI= X-Received: by 2002:a05:6a00:3c84:b0:81f:9bed:ae9d with SMTP id d2e1a72fcca58-8241c6e2f4fmr1458678b3a.46.1770172101033; Tue, 03 Feb 2026 18:28:21 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8241d47a418sm660116b3a.53.2026.02.03.18.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:19 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 87CA61200C33; Wed, 4 Feb 2026 11:28:18 +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 v14 02/13] um: decouple MMU specific code from the common part Date: Wed, 4 Feb 2026 11:28:00 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This splits the memory, process related code with common and MMU specific parts in order to avoid ifdefs in .c file and duplication between MMU and !MMU. Signed-off-by: Hajime Tazaki --- arch/um/kernel/Makefile | 5 +- arch/um/kernel/mem-pgtable.c | 55 ++++++++++++++ arch/um/kernel/mem.c | 35 --------- arch/um/kernel/process.c | 38 ++++++++++ arch/um/kernel/skas/process.c | 37 --------- arch/um/os-Linux/Makefile | 3 +- arch/um/os-Linux/process.c | 129 ++++++++++++++++++++++++++++++++ arch/um/os-Linux/skas/process.c | 128 +------------------------------ 8 files changed, 228 insertions(+), 202 deletions(-) create mode 100644 arch/um/kernel/mem-pgtable.c diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index be60bc451b3f..76d36751973e 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -16,9 +16,10 @@ always-$(KBUILD_BUILTIN) :=3D vmlinux.lds =20 obj-y =3D config.o exec.o exitcode.o irq.o ksyms.o mem.o \ physmem.o process.o ptrace.o reboot.o sigio.o \ - signal.o sysrq.o time.o tlb.o trap.o \ - um_arch.o umid.o kmsg_dump.o capflags.o skas/ + signal.o sysrq.o time.o \ + um_arch.o umid.o kmsg_dump.o capflags.o obj-y +=3D load_file.o +obj-$(CONFIG_MMU) +=3D mem-pgtable.o tlb.o trap.o skas/ =20 obj-$(CONFIG_BLK_DEV_INITRD) +=3D initrd.o obj-$(CONFIG_GPROF) +=3D gprof_syms.o diff --git a/arch/um/kernel/mem-pgtable.c b/arch/um/kernel/mem-pgtable.c new file mode 100644 index 000000000000..549da1d3bff0 --- /dev/null +++ b/arch/um/kernel/mem-pgtable.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* Allocate and free page tables. */ + +pgd_t *pgd_alloc(struct mm_struct *mm) +{ + pgd_t *pgd =3D (pgd_t *)__get_free_page(GFP_KERNEL); + + if (pgd) { + memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t)); + memcpy(pgd + USER_PTRS_PER_PGD, + swapper_pg_dir + USER_PTRS_PER_PGD, + (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); + } + return pgd; +} + +static const pgprot_t protection_map[16] =3D { + [VM_NONE] =3D PAGE_NONE, + [VM_READ] =3D PAGE_READONLY, + [VM_WRITE] =3D PAGE_COPY, + [VM_WRITE | VM_READ] =3D PAGE_COPY, + [VM_EXEC] =3D PAGE_READONLY, + [VM_EXEC | VM_READ] =3D PAGE_READONLY, + [VM_EXEC | VM_WRITE] =3D PAGE_COPY, + [VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_COPY, + [VM_SHARED] =3D PAGE_NONE, + [VM_SHARED | VM_READ] =3D PAGE_READONLY, + [VM_SHARED | VM_WRITE] =3D PAGE_SHARED, + [VM_SHARED | VM_WRITE | VM_READ] =3D PAGE_SHARED, + [VM_SHARED | VM_EXEC] =3D PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_READ] =3D PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_WRITE] =3D PAGE_SHARED, + [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_SHARED +}; +DECLARE_VM_GET_PAGE_PROT diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 39c4a7e21c6f..f3258680bfbe 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -107,45 +106,11 @@ void free_initmem(void) { } =20 -/* Allocate and free page tables. */ - -pgd_t *pgd_alloc(struct mm_struct *mm) -{ - pgd_t *pgd =3D __pgd_alloc(mm, 0); - - if (pgd) - memcpy(pgd + USER_PTRS_PER_PGD, - swapper_pg_dir + USER_PTRS_PER_PGD, - (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); - - return pgd; -} - void *uml_kmalloc(int size, int flags) { return kmalloc(size, flags); } =20 -static const pgprot_t protection_map[16] =3D { - [VM_NONE] =3D PAGE_NONE, - [VM_READ] =3D PAGE_READONLY, - [VM_WRITE] =3D PAGE_COPY, - [VM_WRITE | VM_READ] =3D PAGE_COPY, - [VM_EXEC] =3D PAGE_READONLY, - [VM_EXEC | VM_READ] =3D PAGE_READONLY, - [VM_EXEC | VM_WRITE] =3D PAGE_COPY, - [VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_COPY, - [VM_SHARED] =3D PAGE_NONE, - [VM_SHARED | VM_READ] =3D PAGE_READONLY, - [VM_SHARED | VM_WRITE] =3D PAGE_SHARED, - [VM_SHARED | VM_WRITE | VM_READ] =3D PAGE_SHARED, - [VM_SHARED | VM_EXEC] =3D PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_READ] =3D PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_WRITE] =3D PAGE_SHARED, - [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_SHARED -}; -DECLARE_VM_GET_PAGE_PROT - void mark_rodata_ro(void) { unsigned long rodata_start =3D PFN_ALIGN(__start_rodata); diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 63b38a3f73f7..b07c1f120910 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -307,3 +308,40 @@ unsigned long __get_wchan(struct task_struct *p) =20 return 0; } + +extern void start_kernel(void); + +static int __init start_kernel_proc(void *unused) +{ + block_signals_trace(); + + start_kernel(); + return 0; +} + +char cpu_irqstacks[NR_CPUS][THREAD_SIZE] __aligned(THREAD_SIZE); + +int __init start_uml(void) +{ + stack_protections((unsigned long) &cpu_irqstacks[0]); + set_sigstack(cpu_irqstacks[0], THREAD_SIZE); + + init_new_thread_signals(); + + init_task.thread.request.thread.proc =3D start_kernel_proc; + init_task.thread.request.thread.arg =3D NULL; + return start_idle_thread(task_stack_page(&init_task), + &init_task.thread.switch_buf); +} + +static DEFINE_SPINLOCK(initial_jmpbuf_spinlock); + +void initial_jmpbuf_lock(void) +{ + spin_lock_irq(&initial_jmpbuf_spinlock); +} + +void initial_jmpbuf_unlock(void) +{ + spin_unlock_irq(&initial_jmpbuf_spinlock); +} diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c index 4a7673b0261a..d643854942bc 100644 --- a/arch/um/kernel/skas/process.c +++ b/arch/um/kernel/skas/process.c @@ -17,31 +17,6 @@ #include #include =20 -extern void start_kernel(void); - -static int __init start_kernel_proc(void *unused) -{ - block_signals_trace(); - - start_kernel(); - return 0; -} - -char cpu_irqstacks[NR_CPUS][THREAD_SIZE] __aligned(THREAD_SIZE); - -int __init start_uml(void) -{ - stack_protections((unsigned long) &cpu_irqstacks[0]); - set_sigstack(cpu_irqstacks[0], THREAD_SIZE); - - init_new_thread_signals(); - - init_task.thread.request.thread.proc =3D start_kernel_proc; - init_task.thread.request.thread.arg =3D NULL; - return start_idle_thread(task_stack_page(&init_task), - &init_task.thread.switch_buf); -} - unsigned long current_stub_stack(void) { if (current->mm =3D=3D NULL) @@ -65,15 +40,3 @@ void current_mm_sync(void) =20 um_tlb_sync(current->mm); } - -static DEFINE_SPINLOCK(initial_jmpbuf_spinlock); - -void initial_jmpbuf_lock(void) -{ - spin_lock_irq(&initial_jmpbuf_spinlock); -} - -void initial_jmpbuf_unlock(void) -{ - spin_unlock_irq(&initial_jmpbuf_spinlock); -} diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index f8d672d570d9..40e3e0eab6a0 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile @@ -8,7 +8,8 @@ KCOV_INSTRUMENT :=3D n =20 obj-y =3D elf_aux.o execvp.o file.o helper.o irq.o main.o mem.o process.o \ registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o user_syms.o util.o skas/ + umid.o user_syms.o util.o +obj-$(CONFIG_MMU) +=3D skas/ =20 CFLAGS_signal.o +=3D -Wframe-larger-than=3D4096 =20 diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 3a2a84ab9325..734d143417c8 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; +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..0ebde3d488d6 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,7 @@ int start_userspace(struct mm_id *mm_id) return err; } =20 -static int unscheduled_userspace_iterations; +extern int unscheduled_userspace_iterations; extern unsigned long tt_extra_sched_jiffies; =20 void userspace(struct uml_pt_regs *regs) @@ -789,120 +780,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 Sat Feb 7 17:55:41 2026 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.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 27BF52BD58A for ; Wed, 4 Feb 2026 02:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172104; cv=none; b=oxKmxkIC0Hv3GmEAcnnB1UaVvcBOsMOjn1PXsMZgnFZRKkC4Igum5KsZ0WexLBAfe94u8hKVhHCY+0+dlBMBbmDFUgoOUK+1MUDTdkoQzy/3zpGFDXa+8kVNUJcY1XIZ9nOoNDIYS3x3wS2Ot36jLvZ08sp42XY8o4z/ukm0g4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172104; c=relaxed/simple; bh=KfGMoBBWybwaW+3F0FqWr9sLd6uCZg9z5s+yh61+F2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E6HxzRcdLPSnN782P/nb9gtP7W1aAQyz+DDSqg4fE84qtf3rUA7pymeK0wTd+05v34pgLYvFkhu+jlnHqHFbw++bXXxrWzT4E1U/jx/3mP2sJ/62JPx+7O2Ztu5bHEkZK1sNZUDE6jyGHK20nq+yZ/7WXXmMwFDGHdDYP5Cnx8Y= 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=cJ8U+Mmm; arc=none smtp.client-ip=209.85.215.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="cJ8U+Mmm" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-c2af7d09533so4140807a12.1 for ; Tue, 03 Feb 2026 18:28:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172102; x=1770776902; 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=0L/5/J5t1GFM1WwQS1/l29QmS+JzOLR4lODWUcBj0lQ=; b=cJ8U+Mmm2z2xa4oBsgUQXo0AICXeCJZgJyVEl3OXLrXsQuURwe6DjmBC0/yQYv2U9J 3BglImZjCvFBtPQSwW9LtAjIgFIxuwZOZ7YgTHWqbQo2RvZAQTefjxrXev6oQXgNyH7w cusxaIhTqMQ6lAjywPIsPTUzPYs/rkq4yRmWYxYcOjayUZPZ2TpFe+/xCDO+Q0YBzIwL FnYoUT8XexAzi76OpUnnLaujG8ZUeoN3athRJDm2C6uCrH7FcDF2E+lfLLa0ZXXa2PcO iMBhP3N+muMzUTmdAqU9t3rEegGyr7Zh1duF8ZBMt2Xi5fhZQAp8jfyeKI5YW8BLWhOC CrCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172102; x=1770776902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0L/5/J5t1GFM1WwQS1/l29QmS+JzOLR4lODWUcBj0lQ=; b=jdGpARy4gjRejmx7wkxX3cSVTYwCQPLSBI9nwgoyao8xA3HankgLwRr5MiyCt8I6+B GwTKV+TVPnABWftsqdlUCyp6wN2hdegZVjO15YgrAzzp5xsx8ZwajyJfq2dAe7puZXcE hXPt0jK7X71wH9t1Jw56K/owL0jIv5icaQR1wlegH36gBwsRU0vFlDQiRLrCoYt3qbMG zDSnyfk195I2JaUfYnlOYMHmiRMtedUNMy9v4GhklpdncFilbn0Y8E7SsavGQfOLmuF6 ramg3LfJCkJ/ixxaRxvI1qwdBOwlGweNU+xUIVlinlAolSimgFccoHMmrdbnz5oDBF2D BU4g== X-Forwarded-Encrypted: i=1; AJvYcCWdQqloBB9O6HWYQBMl5jLyr3VQLSnP5R+YOtJVN8LpEFicHzT0YwBMMM7wDvWyx1F6JtInM2+DyXUXiqg=@vger.kernel.org X-Gm-Message-State: AOJu0YysPbBD3np3nNl2xsjdHc1PKr6hg0Pjy42yYQdWHzQQDal9Cu7f zVEDRcurVExgGOVjQD26Oj3QV4MwWYSxRLNiXyO428WRSlW4nU07iUdn X-Gm-Gg: AZuq6aJYUYSt8oWdjZMj4LtyXVGOtTX/O3RG72E+XW2YPrAp+pVnLW/CWUnAJN0dLVI gwi968mYijh+yYzqSjX/ncRTzkaVN/Y7A+HHJJ69Xml7LJpbopyhJHKFGAxL8HE6HI5Wk9SFJV/ kv8sa6GOfrwv06BkEn5GI7iStJivLcldn+Mz6FxJp7rH/M5Vvx+l7xhonotCcCrbe/nJyEH+VLS o9LY7Xn7iOIKCoC8dMc+pr5VKOlkzqyMSuIyuAN6sdRMKDK3C/Y4Lsoe8L2PxlW6+2zb6O1/VEf SjOjqMy/Z63qe8zPq0riserHzSXEjOuNmyGdjHW5r8JoBpxPU9/VkstH7MxZEn04gwHA2aV6tzp ncJ5+ZN68LtWsh3HDUbA4zZhBkkGo7GQRPTnjubd7cDNgFmi0dWX05ZQezskKfSlpYY9ZwOvuHl gIwp1PKIGV/3XZQWXDXXgbU6BYxQJJmuzv+DoBmhfyfstk4ivm7wahznZSW69qcm3MI9VZGzXHi pa9Smzu1AGSwx8j X-Received: by 2002:a05:6a20:2452:b0:253:1e04:4e8 with SMTP id adf61e73a8af0-3937249cfe5mr1451449637.56.1770172102389; Tue, 03 Feb 2026 18:28:22 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a93397ef6fsm6992595ad.95.2026.02.03.18.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:21 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id DDC2C1200C35; Wed, 4 Feb 2026 11:28:19 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v14 03/13] um: nommu: memory handling Date: Wed, 4 Feb 2026 11:28:01 +0900 Message-ID: <0e06cec4e7b715cd3c0a3fa8bec7e00c4e4c27ec.1770170302.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit adds memory operations on UML under !MMU environment. Some part of the original UML code relying on CONFIG_MMU are excluded from compilation when !CONFIG_MMU. Additionally, generic functions such as uaccess, futex, memcpy/strnlen/strncpy can be used as user- and kernel-space share the address space in !CONFIG_MMU mode. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/Makefile | 4 ++++ arch/um/include/asm/futex.h | 4 ++++ arch/um/include/asm/mmu.h | 3 +++ arch/um/include/asm/mmu_context.h | 2 ++ arch/um/include/asm/uaccess.h | 7 ++++--- arch/um/kernel/mem.c | 3 ++- arch/um/os-Linux/mem.c | 4 ++++ arch/um/os-Linux/process.c | 4 ++-- 8 files changed, 25 insertions(+), 6 deletions(-) diff --git a/arch/um/Makefile b/arch/um/Makefile index 721b652ffb65..5e9bf2a8aa6d 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 + # -Dstrrchr=3Dkernel_strrchr (as well as the various in6addr symbols) prev= ents # anything from referencing # libc symbols with the same name, which can cause a linker error. diff --git a/arch/um/include/asm/futex.h b/arch/um/include/asm/futex.h index 780aa6bfc050..785fd6649aa2 100644 --- a/arch/um/include/asm/futex.h +++ b/arch/um/include/asm/futex.h @@ -7,8 +7,12 @@ #include =20 =20 +#ifdef CONFIG_MMU int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *= uaddr); int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 oldval, u32 newval); +#else +#include +#endif =20 #endif diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h index 82a919132aff..c0b9ce3215c4 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -22,10 +22,13 @@ typedef struct mm_context { unsigned long sync_tlb_range_from; unsigned long sync_tlb_range_to; =20 +#ifndef CONFIG_MMU + unsigned long end_brk; #ifdef CONFIG_BINFMT_ELF_FDPIC unsigned long exec_fdpic_loadmap; unsigned long interp_fdpic_loadmap; #endif +#endif /* !CONFIG_MMU */ } mm_context_t; =20 #define INIT_MM_CONTEXT(mm) \ diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_co= ntext.h index c727e56ba116..528b217da285 100644 --- a/arch/um/include/asm/mmu_context.h +++ b/arch/um/include/asm/mmu_context.h @@ -18,11 +18,13 @@ static inline void switch_mm(struct mm_struct *prev, st= ruct mm_struct *next, { } =20 +#ifdef CONFIG_MMU #define init_new_context init_new_context extern int init_new_context(struct task_struct *task, struct mm_struct *mm= ); =20 #define destroy_context destroy_context extern void destroy_context(struct mm_struct *mm); +#endif =20 #include =20 diff --git a/arch/um/include/asm/uaccess.h b/arch/um/include/asm/uaccess.h index 0df9ea4abda8..031b357800b7 100644 --- a/arch/um/include/asm/uaccess.h +++ b/arch/um/include/asm/uaccess.h @@ -18,6 +18,7 @@ #define __addr_range_nowrap(addr, size) \ ((unsigned long) (addr) <=3D ((unsigned long) (addr) + (size))) =20 +#ifdef CONFIG_MMU extern unsigned long raw_copy_from_user(void *to, const void __user *from,= unsigned long n); extern unsigned long raw_copy_to_user(void __user *to, const void *from, u= nsigned long n); extern unsigned long __clear_user(void __user *mem, unsigned long len); @@ -29,9 +30,6 @@ static inline int __access_ok(const void __user *ptr, uns= igned long size); =20 #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER - -#include - static inline int __access_ok(const void __user *ptr, unsigned long size) { unsigned long addr =3D (unsigned long)ptr; @@ -63,5 +61,8 @@ do { \ barrier(); \ current->thread.segv_continue =3D NULL; \ } while (0) +#endif + +#include =20 #endif diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index f3258680bfbe..e599b637c5fb 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -71,7 +71,8 @@ void __init arch_mm_preinit(void) * to be turned on. */ brk_end =3D PAGE_ALIGN((unsigned long) sbrk(0)); - map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0); + map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, + !IS_ENABLED(CONFIG_MMU)); memblock_free((void *)brk_end, uml_reserved - brk_end); uml_reserved =3D brk_end; min_low_pfn =3D PFN_UP(__pa(uml_reserved)); diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index 72f302f4d197..4f5d9a94f8e2 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c @@ -213,6 +213,10 @@ int __init create_mem_file(unsigned long long len) { int err, fd; =20 + /* NOMMU kernel uses -1 as a fd for further use (e.g., mmap) */ + if (!IS_ENABLED(CONFIG_MMU)) + return -1; + fd =3D create_tmp_file(len); =20 err =3D os_set_exec_close(fd); diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 734d143417c8..b338a89ecf1e 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 Sat Feb 7 17:55:41 2026 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.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 DC8312C21EB for ; Wed, 4 Feb 2026 02:28:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172106; cv=none; b=iI7znrG5BXoYU2AT1JoyyUyP6lLH/EhxsEyKFjvz664wzLhvRzEOVc9Uh5gHEJfc/po8RKohAR18VcB7/r5j8A3lu1E49iUErUQS6kch81ZwgnBSKH8EjvDvyCOp09qFq4GtMpaej0uaKMaaE3sEKmMo+QxrYRoQZoGb0rWfOOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172106; c=relaxed/simple; bh=ohZr8TN+3EzzLa/zdEUa/3GcfCV2x/KsAaalXoHEw/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rKXm5BntwDDg9uNRfIpwR26R5+/AXK57zUXPMPrVVvvmxx1uJIESZYsn/rTf7wpAmyMSZuzR1GavLv/7OffblylrmQzYEzHIAiFfVH7T+qG5po3Kd8q25nG7BzedEV+zfOYRcxlQCmhmir0cswAXNg0h0ncDlbxPLxC9WZdOduI= 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=JuG9pt+7; arc=none smtp.client-ip=209.85.215.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="JuG9pt+7" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-c633984fbeeso157102a12.0 for ; Tue, 03 Feb 2026 18:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172104; x=1770776904; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fo64Q14KD7RJjz3s47AhqXDA7DbhSnhy3sX7mHpz33g=; b=JuG9pt+7JIcztBlhXxsNiw+Q40BVAnQD1m60C2UED5yU+I4vkdw6xSqwxBuG5ljeGD 2KEUwwf+ER7nmkq2pg+xxQV7eIT3JzalmJHy/7HSEsWoEsKjPazpxfnixqFtgNfyeYp8 QcaKp/p5UD9OlIwoLMH8XfpSTi/ur6XfZmUZHNZn7b1wi09lHceNP3R5y4dPEEpqFoGQ KmZW6anYWjmVO/Wb0CNgpHMIYE/vRlJI0+Krn2rILkIWx0PAs9Lp1PZrcR53kz1IPqvF kxuph0Dv3YSno9x+iyXpS9LXMZnyceuXkF+6QolGApLd0M3KY+K7ujMMRU0Hzklmn5AY kQ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172104; x=1770776904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fo64Q14KD7RJjz3s47AhqXDA7DbhSnhy3sX7mHpz33g=; b=SoCzksXL1haHsV766M2+At6En1DLSKPNTYokG4zupWa0075r+SKFBQ9p7OlGmrvHpA UQITGtAGL8CMyN/l/l2V90c1VxHPm5BWXplgP5ntgIY/IAvAXHvel+l1WaYBJYknEWVx Px2a9vpIu71I0hYtcmdIHcbo7La1AIzTy0bPqZ8Cb4yhtjjbobFEjSmqTwqUfRm6Eyg6 3HTmAOqZifUu0ACd5h/soJ6/2FNomOn6we8kjvkcA0/mXN9ZoZP+FX+Q0+2bLgi6lgzV bxyzvmgKV90g/Eq1y0L6bUyb1iZHLQvm0iAeLg82fGwqIiEf7NjoXPso0GpP2qfARv0n hQhw== X-Forwarded-Encrypted: i=1; AJvYcCW0S0t0PH/bI+XH2VwewG6PiRCBl4RG/Ae4YgF7RDF/cR71NKSKeY5V4Ezu6IOXGfNJp1r0JogCU2V+e8k=@vger.kernel.org X-Gm-Message-State: AOJu0YwjgIiGwK0fVJ//Je41V+NC+d1m7fSjzqQwqujT/kUNZaxzhiKE BIKnahXYmIFGjn2bAfGDLo4A2zg3x0Wn9AGloxTIuDG9YQA9aj7iwyXT X-Gm-Gg: AZuq6aIzHIIf6nyeDgX4PpASPP/RJWwWFU+pLS+jHOE1Rzfy4Kji9gnazMAOf2abJ56 yV8sLBbv4PAy8/RlMdx86pi2CPA9Qed0e451dHHTY4Bl8aVzB1BHXdfHWhKNKyg29e5XWu1RJlO T6Vl6SMjIZl/swmqlsG2CNLOSSfiq4OsibWaDWuWCQXZTntonffklA3XI3dr6tqtm6T80paoeBB 3B14NYSrehcWMQ0LBJ4AASTqxQxvg67YZmK8pZS+hjovv+hRq1eE7aksiaF9hnyyRbOiav6wgv/ DOsQ4LLtORdndifzgelXdFg5MqcDSD00nsWwSl5thoRa8eIkKPm0AhuwPrbTdUaage3Fz1icRXx b0PpoW/uDfaGQoLy2BaKF43RtUCQS0dzCIJcA+8l7tEl1r5rkf4E+LTNE2e7DsreQOXb5oT1lsI He4X/YYsjpfv+tBoAFmvo4l2I8DF1ykcMq9QhcLBHyKI+smZ9CxtksvCNuN4bgB30QKJZprmWTP MfOVQhwEjxSxu+6 X-Received: by 2002:a17:90b:1c8d:b0:354:57eb:c826 with SMTP id 98e67ed59e1d1-35486bacb31mr1186796a91.2.1770172104122; Tue, 03 Feb 2026 18:28:24 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3548630dfa2sm900607a91.14.2026.02.03.18.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:22 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 705C11200C37; Wed, 4 Feb 2026 11:28:21 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v14 04/13] x86/um: nommu: syscall handling Date: Wed, 4 Feb 2026 11:28:02 +0900 Message-ID: <3208da96a38b9109acd031dd4fec54afd2721deb.1770170302.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit introduces an entry point of syscall interface for !MMU mode. It uses an entry function, __kernel_vsyscall, a kernel-wide global symbol accessible from any locations. Although it isn't in the scope of this commit, it can be also exposed via vdso image which is directly accessible from userspace. A standard library (i.e., libc) can utilize this entry point to implement syscall wrapper; we can also use this by hooking syscall for unmodified userspace applications/libraries, which will be implemented in the subsequent commit. This only supports 64-bit mode of x86 architecture. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/x86/um/Makefile | 4 ++ arch/x86/um/asm/syscall.h | 6 ++ arch/x86/um/nommu/Makefile | 8 +++ arch/x86/um/nommu/do_syscall_64.c | 32 +++++++++ arch/x86/um/nommu/entry_64.S | 112 ++++++++++++++++++++++++++++++ arch/x86/um/nommu/syscalls.h | 16 +++++ 6 files changed, 178 insertions(+) create mode 100644 arch/x86/um/nommu/Makefile create mode 100644 arch/x86/um/nommu/do_syscall_64.c create mode 100644 arch/x86/um/nommu/entry_64.S create mode 100644 arch/x86/um/nommu/syscalls.h diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index f9ea75bf43ac..39693807755a 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -31,6 +31,10 @@ obj-y +=3D mem_64.o syscalls_64.o vdso/ subarch-y =3D ../lib/csum-partial_64.o ../lib/memcpy_64.o \ ../lib/memmove_64.o ../lib/memset_64.o =20 +ifneq ($(CONFIG_MMU),y) +obj-y +=3D nommu/ +endif + endif =20 subarch-$(CONFIG_MODULES) +=3D ../kernel/module.o diff --git a/arch/x86/um/asm/syscall.h b/arch/x86/um/asm/syscall.h index d6208d0fad51..bb4f6f011667 100644 --- a/arch/x86/um/asm/syscall.h +++ b/arch/x86/um/asm/syscall.h @@ -20,4 +20,10 @@ static inline int syscall_get_arch(struct task_struct *t= ask) #endif } =20 +#ifndef CONFIG_MMU +extern void do_syscall_64(struct pt_regs *regs); +extern long __kernel_vsyscall(int64_t a0, int64_t a1, int64_t a2, int64_t = a3, + int64_t a4, int64_t a5, int64_t a6); +#endif + #endif /* __UM_ASM_SYSCALL_H */ diff --git a/arch/x86/um/nommu/Makefile b/arch/x86/um/nommu/Makefile new file mode 100644 index 000000000000..d72c63afffa5 --- /dev/null +++ b/arch/x86/um/nommu/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +ifeq ($(CONFIG_X86_32),y) + BITS :=3D 32 +else + BITS :=3D 64 +endif + +obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_sysca= ll_64.c new file mode 100644 index 000000000000..292d7c578622 --- /dev/null +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +__visible void do_syscall_64(struct pt_regs *regs) +{ + int syscall; + + syscall =3D PT_SYSCALL_NR(regs->regs.gp); + UPT_SYSCALL_NR(®s->regs) =3D syscall; + + if (likely(syscall < NR_syscalls)) { + unsigned long ret; + + ret =3D (*sys_call_table[syscall])(UPT_SYSCALL_ARG1(®s->regs), + UPT_SYSCALL_ARG2(®s->regs), + UPT_SYSCALL_ARG3(®s->regs), + UPT_SYSCALL_ARG4(®s->regs), + UPT_SYSCALL_ARG5(®s->regs), + UPT_SYSCALL_ARG6(®s->regs)); + PT_REGS_SET_SYSCALL_RETURN(regs, ret); + } + + PT_REGS_SYSCALL_RET(regs) =3D regs->regs.gp[HOST_AX]; + + /* handle tasks and signals at the end */ + interrupt_end(); +} diff --git a/arch/x86/um/nommu/entry_64.S b/arch/x86/um/nommu/entry_64.S new file mode 100644 index 000000000000..485c578aae64 --- /dev/null +++ b/arch/x86/um/nommu/entry_64.S @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include + +#include +#include +#include + +#include "../entry/calling.h" + +#ifdef CONFIG_SMP +#error need to stash these variables somewhere else +#endif + +#define UM_GLOBAL_VAR(x) .data; .align 8; .globl x; x:; .long 0 + +UM_GLOBAL_VAR(current_top_of_stack) +UM_GLOBAL_VAR(current_ptregs) + +.code64 +.section .entry.text, "ax" + +.align 8 +#undef ENTRY +#define ENTRY(x) .text; .globl x; .type x,%function; x: +#undef END +#define END(x) .size x, . - x + +/* + * %rcx has the return address (we set it before entering __kernel_vsyscal= l). + * + * Registers on entry: + * rax system call number + * rcx return address + * rdi arg0 + * rsi arg1 + * rdx arg2 + * r10 arg3 + * r8 arg4 + * r9 arg5 + * + * (note: we are allowed to mess with r11: r11 is callee-clobbered + * register in C ABI) + */ +ENTRY(__kernel_vsyscall) + + movq %rsp, %r11 + + /* Point rsp to the top of the ptregs array, so we can + just fill it with a bunch of push'es. */ + movq current_ptregs, %rsp + + /* 8 bytes * 20 registers (plus 8 for the push) */ + addq $168, %rsp + + /* Construct struct pt_regs on stack */ + pushq $0 /* pt_regs->ss (index 20) */ + pushq %r11 /* pt_regs->sp */ + pushfq /* pt_regs->flags */ + pushq $0 /* pt_regs->cs */ + pushq %rcx /* pt_regs->ip */ + pushq %rax /* pt_regs->orig_ax */ + + PUSH_AND_CLEAR_REGS rax=3D$-ENOSYS + + mov %rsp, %rdi + + /* + * Switch to current top of stack, so "current->" points + * to the right task. + */ + movq current_top_of_stack, %rsp + + call do_syscall_64 + + jmp userspace + +END(__kernel_vsyscall) + +/* + * common userspace returning routine + * + * all procedures like syscalls, signal handlers, umh processes, will gate + * this routine to properly configure registers/stacks. + * + * void userspace(struct uml_pt_regs *regs) + */ +ENTRY(userspace) + + /* clear direction flag to meet ABI */ + cld + /* align the stack for x86_64 ABI */ + and $-0x10, %rsp + /* Handle any immediate reschedules or signals */ + call interrupt_end + + movq current_ptregs, %rsp + + POP_REGS + + addq $8, %rsp /* skip orig_ax */ + popq %rcx /* pt_regs->ip */ + addq $8, %rsp /* skip cs */ + addq $8, %rsp /* skip flags */ + popq %rsp + + /* + * not return w/ ret but w/ jmp as the stack is already popped before + * entering __kernel_vsyscall + */ + jmp *%rcx + +END(userspace) diff --git a/arch/x86/um/nommu/syscalls.h b/arch/x86/um/nommu/syscalls.h new file mode 100644 index 000000000000..a2433756b1fc --- /dev/null +++ b/arch/x86/um/nommu/syscalls.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_SYSCALLS_H +#define __UM_NOMMU_SYSCALLS_H + + +#define task_top_of_stack(task) \ +({ \ + unsigned long __ptr =3D (unsigned long)task->stack; \ + __ptr +=3D THREAD_SIZE; \ + __ptr; \ +}) + +extern long current_top_of_stack; +extern long current_ptregs; + +#endif --=20 2.43.0 From nobody Sat Feb 7 17:55:41 2026 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 7EBAF2C0303 for ; Wed, 4 Feb 2026 02:28:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172108; cv=none; b=OTRabLygTzuRYXMAezNq8vFt5MpHXbWm8UW1PCYnfCpLLRiampdhGgDPf5UXG6pPz21OO6ke3hNlVTTSZXtpXY4AZTH1yvnHejU8njU6z4LVxB9rsQ09KNSzG2h1j8PR/JQEgDg7dvLh7PHUBbwPtLYQa20NSxx0s1Gm+9kHOUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172108; c=relaxed/simple; bh=SFRj99H60SuVf2pzFy78XNsf70dEa3gjFhK5ewhjtEA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ikKaKEpVrsuqiOh8XfPWQ8AbkafYrJYp7I7NZDoMwxcnT4kMTjAOm6kMOrfyqDP4lz0hPMEj9SLy1Q9zctEeq+9tkiqyfUGsc9xEI3QGyswJwmoRuNrGgj7MZxdUt8u9r7ptG/NYvfdFzR5SmWg0j6unPO9fO4qczLFejRl+3Wg= 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=nUvlhoRn; arc=none smtp.client-ip=209.85.216.51 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="nUvlhoRn" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-352c5bd2769so3745333a91.1 for ; Tue, 03 Feb 2026 18:28:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172106; x=1770776906; 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=4GzNDSqk/5OQvqJXVrFISSObJmCqqMejYVMMF81vnhg=; b=nUvlhoRnSCCg9eOwE3pbSfEYmNd1C1gXVoZ3l/VSMD8mJcI1Xvus0nPZi+eyZKu2np 2/Znc0x3Sfz5E1N983HsixYr4hRXXTCjJvgoTUX4ghSVY6YVQr+Diix+9phwexkk0Fiv e/P2Avxifh5vDB7YjgDMTs/F6Mir35kUM+fMR1p378FOwQCvTQFU55hFNTt+LV2gSkRa gcQyBpDdTypsl+M3Pj3v+i8SRTIkwF3g3iXT3o5xLSysXXgzemNl1qKQilLlArbtN9Y/ xQCjqb/c0jnMWYA4jdR/6JDmPrNYE2TnduNbVTJLBPOYlswAq7Ymx874nwtLbHKzet1V BSPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172106; x=1770776906; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4GzNDSqk/5OQvqJXVrFISSObJmCqqMejYVMMF81vnhg=; b=YOYQgCO79iSvMpMQ7tW6DpeW/LA14osKDkm4QH7mQL/7Mlt8gmplj20zO67RPAr0eS nGaUGeljSwRwXDWEQ97F9+KM+wbU8t94UqH3LWN+xizs1lgkSF6368roJCiBBKIKpgfs 7O68P7Qy8COjMUUcZl57IzXZnPVUy0WzwIojcIh4CNdIH0Qe4kVt/XJLaRrfNkGHdg2c s5oF+sBf2OWFwGbE8K5StBbv79uEya4mejeE/CXqfWRw/LQs4iSrxU0ZXE0+zm4v7z9e YkllGAS/BQU+3REM78fcSl2DhCK4o9M0zNWPZnhWnlKKANy0Kck0CCJuXUiyqvS4djP4 MTJQ== X-Forwarded-Encrypted: i=1; AJvYcCXuUKFoXC5XDQmNkbvP1O/krwIsftA98MFVnj7lDYOndhG/jJDIEUaNgUlgP68wkGA5BCCWu3eNPAnc+Bg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+N9z0J+AMH4TXuQzjLfD24f1+iYdtffdlTzzEMUmPGp8TphD2 YjFLCOuVwi2/QiK5HgM6vQWzGbFT1NJ7XIuh0cInSCB07ml1lsPJaLqe X-Gm-Gg: AZuq6aJGxNurYDtKv53gi2zKT+AvSuMA4Fq7/FmicndPxGLF0YML+jsNUxf2X0UD2D9 KUd1nl+Wo/xX1jLz5uImN2SUupBCEXW94uMOd5ekHx7F3Qx9zy9rqz8olXwg8F0WQg7ZU2wafpu fhWkjjSq8bJHw/UJr8v7cR/SiLCU0FkGmMYYNEhrcTvg3h+t8nmTTO099CEC7qfVTlBFwYP9nba rs8AOOGlxcU5Xm5eC8YMmptAFW+Houf1UToChaKjTHSQ2plAKghAQeLKXKMokSlpOULS2J5vpr+ 4O6Z8K626eXfW8Al/rSiVE5PKV2NZvd9pTpR3jDugxJjzrMHGPa3zf8C8Db/LxW1EZwrO4tJyV+ HNN2ePuoJDYQtYc8CKU4nlvufoEZlUY0eNAhRu5nD/Mk/3PGjQJ17GYO6uXOvpSo1vv1ZZTPN+U OkfbF3wmVHmOwiCxrnvc5Sh0AghM2zmWDYWbrB0L623aflXbdMNTv5Kh33KQ1OL4ooGn8e2UChd Rlnl3vd/xKEktMR X-Received: by 2002:a17:90a:ec8f:b0:340:bde5:c9e8 with SMTP id 98e67ed59e1d1-3548719372cmr1207738a91.22.1770172105906; Tue, 03 Feb 2026 18:28:25 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6c82e343e4sm632227a12.4.2026.02.03.18.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:24 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id CB1DE1200C39; Wed, 4 Feb 2026 11:28:22 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org, Kenichi Yasukata Subject: [PATCH v14 05/13] um: nommu: seccomp syscalls hook Date: Wed, 4 Feb 2026 11:28:03 +0900 Message-ID: <053f2b46e47093a4347ee83d4afe79985715d24a.1770170302.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit adds syscall hook with seccomp. Using seccomp raises SIGSYS to UML process, which is captured in the (UML) kernel, then jumps to the syscall entry point, __kernel_vsyscall, to hook the original syscall instructions. The SIGSYS signal is raised upon the execution from uml_reserved and high_physmem, which locates userspace memory. It also renames existing static function, sigsys_handler(), in start_up.c to avoid name conflicts between them. Signed-off-by: Hajime Tazaki Signed-off-by: Kenichi Yasukata --- arch/um/include/shared/kern_util.h | 2 + arch/um/include/shared/os.h | 10 +++ arch/um/kernel/um_arch.c | 3 + arch/um/nommu/Makefile | 3 + arch/um/nommu/os-Linux/Makefile | 7 +++ arch/um/nommu/os-Linux/seccomp.c | 87 +++++++++++++++++++++++++++ arch/um/nommu/os-Linux/signal.c | 16 +++++ arch/um/os-Linux/signal.c | 8 +++ arch/um/os-Linux/start_up.c | 4 +- arch/x86/um/nommu/Makefile | 2 +- arch/x86/um/nommu/os-Linux/Makefile | 6 ++ arch/x86/um/nommu/os-Linux/mcontext.c | 15 +++++ arch/x86/um/shared/sysdep/mcontext.h | 4 ++ 13 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 arch/um/nommu/Makefile create mode 100644 arch/um/nommu/os-Linux/Makefile create mode 100644 arch/um/nommu/os-Linux/seccomp.c create mode 100644 arch/um/nommu/os-Linux/signal.c create mode 100644 arch/x86/um/nommu/os-Linux/Makefile create mode 100644 arch/x86/um/nommu/os-Linux/mcontext.c diff --git a/arch/um/include/shared/kern_util.h b/arch/um/include/shared/ke= rn_util.h index 38321188c04c..7798f16a4677 100644 --- a/arch/um/include/shared/kern_util.h +++ b/arch/um/include/shared/kern_util.h @@ -63,6 +63,8 @@ extern void segv_handler(int sig, struct siginfo *unused_= si, struct uml_pt_regs extern void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *= regs, void *mc); extern void fatal_sigsegv(void) __attribute__ ((noreturn)); +extern void sigsys_handler(int sig, struct siginfo *si, struct uml_pt_regs= *regs, + void *mc); =20 void um_idle_sleep(void); =20 diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index b26e94292fc1..5451f9b1f41e 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -356,4 +356,14 @@ static inline void os_local_ipi_enable(void) { } static inline void os_local_ipi_disable(void) { } #endif /* CONFIG_SMP */ =20 +/* seccomp.c */ +#ifdef CONFIG_MMU +static inline int os_setup_seccomp(void) +{ + return 0; +} +#else +extern int os_setup_seccomp(void); +#endif + #endif diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index e2b24e1ecfa6..27c13423d9aa 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -423,6 +423,9 @@ void __init setup_arch(char **cmdline_p) add_bootloader_randomness(rng_seed, sizeof(rng_seed)); memzero_explicit(rng_seed, sizeof(rng_seed)); } + + /* install seccomp filter */ + os_setup_seccomp(); } =20 void __init arch_cpu_finalize_init(void) diff --git a/arch/um/nommu/Makefile b/arch/um/nommu/Makefile new file mode 100644 index 000000000000..baab7c2f57c2 --- /dev/null +++ b/arch/um/nommu/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y :=3D os-Linux/ diff --git a/arch/um/nommu/os-Linux/Makefile b/arch/um/nommu/os-Linux/Makef= ile new file mode 100644 index 000000000000..805e26ccf63b --- /dev/null +++ b/arch/um/nommu/os-Linux/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y :=3D seccomp.o signal.o +USER_OBJS :=3D $(obj-y) + +include $(srctree)/arch/um/scripts/Makefile.rules +USER_CFLAGS+=3D-I$(srctree)/arch/um/os-Linux diff --git a/arch/um/nommu/os-Linux/seccomp.c b/arch/um/nommu/os-Linux/secc= omp.c new file mode 100644 index 000000000000..d1cfa6e3d632 --- /dev/null +++ b/arch/um/nommu/os-Linux/seccomp.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include /* For SYS_xxx definitions */ +#include +#include +#include +#include +#include + +int __init os_setup_seccomp(void) +{ + int err; + unsigned long __userspace_start =3D uml_reserved, + __userspace_end =3D high_physmem; + + struct sock_filter filter[] =3D { + /* if (IP_high > __userspace_end) allow; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JGT + BPF_K, __userspace_end >> 32, + /*true-skip=3D*/0, /*false-skip=3D*/1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high =3D=3D __userspace_end && IP_low >=3D __userspace_end) al= low; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __userspace_end >> 32, + /*true-skip=3D*/0, /*false-skip=3D*/3), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer)), + BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, __userspace_end, + /*true-skip=3D*/0, /*false-skip=3D*/1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high < __userspace_start) allow; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, __userspace_start >> 32, + /*true-skip=3D*/1, /*false-skip=3D*/0), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high =3D=3D __userspace_start && IP_low < __userspace_start) a= llow; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __userspace_start >> 32, + /*true-skip=3D*/0, /*false-skip=3D*/3), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer)), + BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, __userspace_start, + /*true-skip=3D*/1, /*false-skip=3D*/0), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* other address; trap */ + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_TRAP), + }; + struct sock_fprog prog =3D { + .len =3D ARRAY_SIZE(filter), + .filter =3D filter, + }; + + err =3D prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); + if (err) + os_warn("PR_SET_NO_NEW_PRIVS (err=3D%d, ernro=3D%d)\n", + err, errno); + + err =3D syscall(SYS_seccomp, SECCOMP_SET_MODE_FILTER, + SECCOMP_FILTER_FLAG_TSYNC, &prog); + if (err) { + os_warn("SECCOMP_SET_MODE_FILTER (err=3D%d, ernro=3D%d)\n", + err, errno); + exit(1); + } + + set_handler(SIGSYS); + + os_info("seccomp: setup filter syscalls in the range: 0x%lx-0x%lx\n", + __userspace_start, __userspace_end); + + return 0; +} + diff --git a/arch/um/nommu/os-Linux/signal.c b/arch/um/nommu/os-Linux/signa= l.c new file mode 100644 index 000000000000..19043b9652e2 --- /dev/null +++ b/arch/um/nommu/os-Linux/signal.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +void sigsys_handler(int sig, struct siginfo *si, + struct uml_pt_regs *regs, void *ptr) +{ + mcontext_t *mc =3D (mcontext_t *) ptr; + + /* hook syscall via SIGSYS */ + set_mc_sigsys_hook(mc); +} diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c index 6c993bc8c78e..6538c2d8694c 100644 --- a/arch/um/os-Linux/signal.c +++ b/arch/um/os-Linux/signal.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "internal.h" =20 void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *, void *= mc) =3D { @@ -32,6 +33,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) @@ -180,6 +182,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); @@ -191,6 +198,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 Sat Feb 7 17:55:41 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 346322BDC05 for ; Wed, 4 Feb 2026 02:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172117; cv=none; b=fQVGh41r3Oucb27Rv7cx/y9KoNZjbqkAHAnXSlPK4ZiStinHB4blULb6NzjChyy6m/fRQglChmrhQjmvjmrBnAqUTQD8i57YxyNLLHDSvXs7sYBjepkC4KT7zD3XEyHwEyX0dSYMsXGfnpQemB1YF7Qn9awKL/5lnzdcMBub0G0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172117; c=relaxed/simple; bh=eK7W1+4srvp6F74qzJFzXiz4md/zD2rIs58+CYifDHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NVopEyiCewATfhFXV6CtusN/u3zeXVfE+XHKArbn+dIdGA6CuJk8n4fOLMUHeue71F8JT/Vvm0ed0NOecZ+MGPMW3qFF0xdas539gn4O0fxVr8cdmM3ifpYzVL7aJp4nKO6A4iq6q/DLHYmOVHpcfPIrsngJYnud4PlqVTi937c= 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=RjlDfCHv; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RjlDfCHv" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-81f4dfa82edso3377652b3a.0 for ; Tue, 03 Feb 2026 18:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172107; x=1770776907; 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=RjNnT/qNufze77W5gRyvHPSLcanY/U9dlqiEm3iR1Nk=; b=RjlDfCHvxnF2IcHkjwVLi42vVSMcfNP4f5yYx3jBJBfX2gghUwpmMojeymfkOMFnxS numYfC0i1whmlHKRAj0z9R3WTORleZYtEwhJmQfH6lsye9FXDnJpQkJSBsOb/MFGyUsj eJYkwTtxYK0hHiRLxHAQGoi0/d8CBVAiEA3YaYpoCiaERDVYgyDMJAhrE5XlowwEjHUc w3J4pDAjJVdwrqvep8jCwRKT7Qfsa3vCAz4mF1ZbtwNHeHxLK7x8gBNsdESVlwYU9zHS M67wk7Z6PolXOOy3DCrLku64918tChP5HWawAEawdri983n+X2uDUu+lHwo9l6If5y+x Z5kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172107; x=1770776907; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RjNnT/qNufze77W5gRyvHPSLcanY/U9dlqiEm3iR1Nk=; b=naYHxufZtJu5Vbt9zrwMleTzZz/k/pkeqegKY3kCZh+wNZ53oYndl7jIlTU1kOHT9j lpvWfMLPoY7pvN+F3vGq6UBiT1ws9T1TSyYER1LKjPLlxFQqFHUZZGk+8GiuHHp2exAK WP5lm0SHOQvaXVrUv89YXV1pn6r4xvEbCZK+PEZX839JC/HQh7aEMDSakFLW7b9tCthD 8C7TECpTkcK/xssJLgWYWquBkBupCljInlWMVXv1xGVW6Zx6IGz7pG0loFvIhUer4XEp mnxSukQevld5BsIEui1TeC42eUvoBHOQUFN56oOa9v4gyI6ekhmfC5d+Not0K2E/1KLd 5Nuw== X-Forwarded-Encrypted: i=1; AJvYcCWY7hCDZSaCXRYnR+yhQFF1qTENIhzAKINDWRFMdrR8OaJyhq1qb9//1fwE7Cu+Sj5YilrI432l17KzrSw=@vger.kernel.org X-Gm-Message-State: AOJu0YwfrVuMmh6896QBKY1KujBYRQZk6Ugqlz32ywCHjRHfx/ri3+85 J5UWmqSy08bN7Lsts/VpVJZmfC8FmHgt4i98RkO5qYk+fVk6YNvyuJUh X-Gm-Gg: AZuq6aIabpu0u8wlEYgZw7vy7Ae9bC+5iJmsSfZC4sbaoHD6OqYLiwHCQf8yroscWzS sbiqQPRnVuV9iQMftgs58KCEwFqOMyBgfChxY8oZU3lVMointYIwOUnJC9eTk2/X1QwOKHUUHln 4DjvD32seSW68y4JeMKgzTXM3P5d9JrXB+vMpi1JGwirbv3voy+9PDuyI4DY9sEJ+vGbZRgu54F vLY7HZhqa5Zd5MLjCIu+rvBea+3VQZRnKZgU6tHDcXwZWV9mIZ9lVrOh+wdEGs307qi7L5BvQf1 7oSdEaSA1ssjeLdFPGjyVjd13QJEZWZGylKVa98+jw1bu7ZehK1bvbz2ACO/A0JwRYqNs0VdpUl mcjpEOxASL53lO0z4JiXO7Q310HlBP6esP4ZK588Rspp7JJbMUUCxPk4mBJ8cE4PiPc1m6U1k4q /p+SOxQ5zuIqHXKDNfn3yJrJQpi3/CUkYyQ+3wAN10ymykfmCQUnWfyrs9A85LLWH1iw57oOSbW HPI6jAFL3YdibJI X-Received: by 2002:a05:6a00:2d10:b0:81f:be3c:8a24 with SMTP id d2e1a72fcca58-8241c5e9c88mr1483790b3a.36.1770172107592; Tue, 03 Feb 2026 18:28:27 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8241d4a5c28sm707551b3a.62.2026.02.03.18.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:26 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 0A3F21200C3B; Wed, 4 Feb 2026 11:28:24 +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 v14 06/13] x86/um: nommu: process/thread handling Date: Wed, 4 Feb 2026 11:28:04 +0900 Message-ID: <4a58e2e3f5a18c5bae50dd41dc0dc8ae901085ee.1770170302.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/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 | 40 ++++++++++++++++++++++++++++ arch/x86/um/syscalls_64.c | 2 +- 6 files changed, 47 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/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..3b1610280110 --- /dev/null +++ b/arch/x86/um/nommu/syscalls_64.c @@ -0,0 +1,40 @@ +// 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)]); +} diff --git a/arch/x86/um/syscalls_64.c b/arch/x86/um/syscalls_64.c index 6a00a28c9cca..9684850603a2 100644 --- a/arch/x86/um/syscalls_64.c +++ b/arch/x86/um/syscalls_64.c @@ -45,7 +45,7 @@ SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, a= rg2) return arch_prctl(current, option, (unsigned long __user *) arg2); } =20 -void arch_switch_to(struct task_struct *to) +__weak void arch_switch_to(struct task_struct *to) { /* * Nothing needs to be done on x86_64. --=20 2.43.0 From nobody Sat Feb 7 17:55:41 2026 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 D14D32C0F79 for ; Wed, 4 Feb 2026 02:28:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172111; cv=none; b=r4pfUVIyB+vKhDlTnjXH1nRp1Mz5Vlo2hlg/P5V4gpSjtYw6oikr1efiw5OLqEDV+fQND6ticRYHki7MH0KpSGSYVcOf/hD+DeNEH8TLpAnfOhN0+4ttDc9V5dMftKu34CUc2K+eTiCsFKnSIqofRSe6kFpTsEmahI/lw6hKwiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172111; c=relaxed/simple; bh=Smx444R1K3eGvehQLSYSKsoNfFVfI8EFubuS5ARqwWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lr2y6fac7VEzdFPQDwkLCnz0z6N3mS5kB/GUP6yuaLGzo+k9jXbFkKex6lJgOMmEwRYoPR61UbuTuikcG/fU+rGha2cbaeeNdDzx9949tQwxp+33A7rZPQYipnhYZ30N1qT6uB0+gUaDLtHngEPCZTGu4XC8u8ZtSvbsyzKVGLU= 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=dLyLRS7o; arc=none smtp.client-ip=209.85.216.41 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="dLyLRS7o" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-34abc7da414so3885730a91.0 for ; Tue, 03 Feb 2026 18:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172109; x=1770776909; 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=EozC+O+V6UtpPMZ43xTGpDpBr5Y3IUusGEEQ6C8VmaE=; b=dLyLRS7oLvYYFUg5gaaUTYGOyP15fBlio5JcfRy7w4JC7VlYwJGLqw+rpFRz8MTiwn 09u9N9Dtlt07sd+FFomHNIgBpqDM4YEIlVwNMcebub+b8+7WZR82CGjuZgnsMudr/AVu YWoroJzC2SjDD/hTJl59z0TUgLwReCGaxGn7dQIcZuGVgjV17sf7ulLRmpW+8YwqQT7Z R7x5vzqyR9pkctHyDpUUzs2zEsBAUwiBjV5X5vKRGYPZd6SQzJeH1FNP6Ucl/9Z9DOgX CHT7XJCQCLZ9Be4hx9Ms270320XC+FnBhv7O00aPdzLzelQPEAuLNZslMU+6KADlIYW0 9r9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172109; x=1770776909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=EozC+O+V6UtpPMZ43xTGpDpBr5Y3IUusGEEQ6C8VmaE=; b=hV8gKhLAjX7oJWdVZqfBgTOZPPSqdJnX9luSvhVTQKNBbfmXFlgqIc5CKy6IXAzre2 Q2dgJzcqLpV7ed5Db4M676Z3ftZl593rAOEBwJTQsof82Y5pBec1BzC/OA1L6meV3dqc nWf14Q+SEf1w/GYLz1Bwo2IxfUJTA7BsYec6cyAb0Xqpu0vEYXALOqsR8gSvtVt6Zvem Tb5TsMiqIHLSaYgmXYUtws3KpweKxvQTsE/DWub4cUxdxdJzV234t0ivwj+CR4IZFgXu MnbmzQT8CbV9ReJVMRbEPVxk23MJbVi/4m1MJQkggteu3qJLJbwRw78tttCacnbcn7Z1 t0CQ== X-Forwarded-Encrypted: i=1; AJvYcCU+L+yHoYu2iD1wwG+NMtp4xH64GJVnDdUwBjy5f1WApDHZtn/cyikBJHeY+qHqaecRSu6HKpxfGTjgGz0=@vger.kernel.org X-Gm-Message-State: AOJu0Yzt0mvPBSKrpDekKULGHjXq1uIRiTYtIrwLT/HobP4UM22cns0c /1vjcFam7PLFLxspNBUmDbczOioSwcc5BC0SZSIMfGf1Ph911d70EOVO X-Gm-Gg: AZuq6aL7oA5UXhqfboPlNIhsFjBty9Ut1UvdI3gmK1pHUKPUQtb8SE0Y7nGcEZGuv7a ItrVqXCQQ1nVefHRB8EA92HIsNr6jicvAhC7mYHMXDGGGqQd96pSpT6PE4MbjISOIo0MES94QNh XsOjFS/o5I1/0CL/iVqC8qNnJilrGxVYl2G2saIy61XtbqS/PSLSEdp45gWyX9/5zXXTBLCAVRP jRux9q/x+Mq3noJy0MBQks+r++DA5b2CT4ErZGtDcf0pzrv4Wc2yZ6luK8ce7mijlUjy3skFueT cCK0j7C0vv1QBaTpTHRKM8tt/KMRa3ENq3GIYZwQ4/TQC6TDZCeFPaBPZMFfOmCH0OhH0rkeJEj LBLkh90GTBnD7Ea4nFwH1kNNLSKNalcymS2tvbnyBIgHMBCTmJHr6kXagNMhf/VEiZdqlKYom9X mJ7TIee2VjhPkDIP9PkN+9nckps5cO8j9ouk4HjzrDRYghJXLTdbwgVDEkQbdyupXBx10VFilRb wLiZT9wKhQVsxE4 X-Received: by 2002:a17:90b:3884:b0:340:4abf:391d with SMTP id 98e67ed59e1d1-35487125d82mr1194529a91.16.1770172109005; Tue, 03 Feb 2026 18:28:29 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35485da24a4sm874683a91.1.2026.02.03.18.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:26 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 52A6A1200C3D; Wed, 4 Feb 2026 11:28:25 +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 v14 07/13] um: nommu: configure fs register on host syscall invocation Date: Wed, 4 Feb 2026 11:28:05 +0900 Message-ID: <6cbe7389d6f8250a22afe2213c90a6ceaf721a97.1770170302.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 | 11 +++++++ arch/x86/um/nommu/syscalls.h | 1 + arch/x86/um/nommu/syscalls_64.c | 48 ++++++++++++++++++++++++++++++- 6 files changed, 92 insertions(+), 1 deletion(-) 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 b338a89ecf1e..4f30a389c530 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..c08ae4e0edec 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -4,7 +4,9 @@ #include #include #include +#include #include +#include "syscalls.h" =20 __visible void do_syscall_64(struct pt_regs *regs) { @@ -13,6 +15,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 +34,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.h b/arch/x86/um/nommu/syscalls.h index ce16bf8abd59..4b9e3c85cf3a 100644 --- a/arch/x86/um/nommu/syscalls.h +++ b/arch/x86/um/nommu/syscalls.h @@ -13,6 +13,7 @@ extern long current_top_of_stack; extern long current_ptregs; =20 +int os_x86_arch_prctl(int pid, int option, unsigned long *arg2); void arch_set_stack_to_current(void); =20 #endif diff --git a/arch/x86/um/nommu/syscalls_64.c b/arch/x86/um/nommu/syscalls_6= 4.c index 3b1610280110..25fb11a8b7a4 100644 --- a/arch/x86/um/nommu/syscalls_64.c +++ b/arch/x86/um/nommu/syscalls_64.c @@ -10,11 +10,48 @@ #include #include #include +#include #include /* XXX This should get the constants from libc */ #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; + +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; +} + void arch_set_stack_to_current(void) { current_top_of_stack =3D task_top_of_stack(current); @@ -35,6 +72,15 @@ void arch_switch_to(struct task_struct *to) return; =20 /* this changes the FS on every context switch */ - arch_prctl(to, ARCH_SET_FS, + os_x86_arch_prctl(0, ARCH_SET_FS, (void __user *) to->thread.regs.regs.gp[FS_BASE / sizeof(unsigned lon= g)]); } + +static int __init um_nommu_setup_hostfs(void) +{ + /* initialize the host_fs value at boottime */ + os_x86_arch_prctl(0, ARCH_GET_FS, (void *)&host_fs); + + return 0; +} +arch_initcall(um_nommu_setup_hostfs); --=20 2.43.0 From nobody Sat Feb 7 17:55:41 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.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 EB9652C08D4 for ; Wed, 4 Feb 2026 02:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172115; cv=none; b=FEg7EsqHRranZmbOZ1PJvYOay5y/B3O8IQSlqik89Xnm1A+2TUqlDU9w5z5olDq3XsKpfua3FlrjtEAN2BQ9jlkvT2wYtDXmDUq22EZZojT3ClFALwe7dNQNT0Qo80FeaSyYXgJ3gf9epp6pHlGB2h+LHiL8tkQjPzi5P5w9Rmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172115; c=relaxed/simple; bh=xTw1fZj9TABghspblzMyZh7aJYlpz7LOhXxI2BNDWxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R2i/kkiab+ik4jXp0aQnJGWT6xC3QMDg6cPkhpUNtm29vj89vupBHusd5gHUM5SqNO2l9uWQhsJN5UUmCN2fleyVViHs1HyeeZ7AFmfZMRyMRxfGADZER2Q8LR+EyPYcrEMFqsCysU6sH/fY1F2nesGO6I9IUtLZn4apsmHNNMw= 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=Z+NL9Q7E; arc=none smtp.client-ip=209.85.210.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="Z+NL9Q7E" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-8230f2140beso232174b3a.1 for ; Tue, 03 Feb 2026 18:28:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172110; x=1770776910; 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=Z+NL9Q7E+WkRkJZ6U8X/0fgNhjOBdVguWMzpYqPrBLJnOs65ZlpIcg0yeXM+RUJsaT woGBt02r2ExazMHXu48QjCUMhFG1kTAzyyIWFZr3sKToE7jUIQpEY69UrxAPPumzRc4R 08UwODeCwE+AjnZmKNQW2enOVK63BNj3hFn86MyaD6t+tZBn5Wi2nQIYooXnWP3HzRT+ 8oEFuDNRh9m/bUda9aZ7n3l6HPCaL/Y99hNclFHuAMBoyBk/bKeV42D6+s8s22RzmO4E Ks5Qn53SG8MzbomfioxVzKXRWKvDwj7DMlFcwZ7ZlwYx13WKkYXmSt0wag/gaRWwiMda DJVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172110; x=1770776910; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=KXlvIxBTzUi2fvQwFF5f1ABJZvc5EYR8EZzXkNvyLME=; b=IOLgbV1U6I7Fu7P5prQbIOQlmLlArdgSiXkbactmRmFPSAN4jrLWx3Igr+WZWbtbiu 6R+0Ybn6XGUqgTRgX/hVBjvAX1KRx3fFKPivKEafCLg6gsyRoY8w2fr9w2t5TNzw0+xA IclWTEZrdcXm9tAT+P7Unpk9kt6GEmqRPwiM/HDbbEi1LraH+1aY5z9nhyVvQpwNWbAz YkGLNp1Bj/ShwCYUgoDhPeMzf/rlWc6b0ljilYG3RKAj8LmJ+JzKSGTvWt1LZMZ04iCU Yg9BvMeH6OYBprIEvHS8I3gEGTVH+x70YWlC54Kef3QnDYIId46/ia0pc6dnsqEpFuRI pgOg== X-Forwarded-Encrypted: i=1; AJvYcCW3St1lDOk4doymkym1Yrrum+y166fSE82T6f/bnAZfCWGNV5TIl5Rixrx4bJj4s3NKdoHMeWpfiPvU0Pk=@vger.kernel.org X-Gm-Message-State: AOJu0YwqX0E/dqgEroVIEzV4tqIjnPn9D1QW1vUm0XMzCnMauyWUaLnM qmLB2A4CKw4cNL7lpJlrfzeZeDEJPlW2pf6N2ljoqQ5DsRcB6jKf3zFt X-Gm-Gg: AZuq6aL9TCWey2q3VfTph7hJqzuQBeq6GPD3gAiXaCxcFvGe5GV+c+MUGrvgcQX2guQ H5Z+6epoFTIHb1Pipv2j+hZqkRutoiPg8M/HDG7SVRXhq5i0HggmvncNMMI27B9c8B3fdX2Qr6R vjJuasNHUFJii0GnyRichYZL568lKGh2K6mxwepGvUMHAN2X2OMGodp1hsbSpmXqImjSJsjkIXa wnF7P60m8JkvfWsZLaV7AY1Qmu1lgMRr3dji8v5lQ+qs5VdK/B/+gdO0ipHzKOS+JreM/QW91Ts k+GUMY67m46ECU0JFMwwxsEIHd0VDFri9mSqcIfrJTDL3jbmyMvSoOOKGUWIgnSCGqK4+2xYCt4 YBdJ8tC1mf2brjsWDkqYqz6t7oF7HNsb2qiscTY/XYG945mx1DUdoakvm/8BRM+K7VtBBlJprsW pKx0+keYE/JKdUNgL48okOtOelxBJPytYtDnAweJcaCFM5AZuLtlEWOu2/cNi9zs2GBpMk1v0Fl wcGd3PXzmo609JL X-Received: by 2002:a05:6a00:1d9c:b0:81f:32cc:b1fc with SMTP id d2e1a72fcca58-82404255f03mr4635844b3a.3.1770172110336; Tue, 03 Feb 2026 18:28:30 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6c8321cb78sm565404a12.8.2026.02.03.18.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:29 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id BC0351200C3F; Wed, 4 Feb 2026 11:28:26 +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 v14 08/13] x86/um/vdso: nommu: vdso memory update Date: Wed, 4 Feb 2026 11:28:06 +0900 Message-ID: <1779dfb80f0e6fc25c001062a1e00cb661531c23.1770170302.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 Sat Feb 7 17:55:41 2026 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA5822C0323 for ; Wed, 4 Feb 2026 02:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172115; cv=none; b=CFWOOPQPsSM8OQnrtOi6wzp5vGvEKnQEyc1n/bNWAAkb8i+wSgcDdYrzkcTJJpBU5g4kihiM2B4oQK+5fR//rgZbTctE19bVJ3AhslcmWXhvlXTb7oUWqeLsTb7LORXr5Q+gTxzdeE9wxHh6/wxwfDaAhH+p+K2SO5KilNkr+vg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172115; c=relaxed/simple; bh=ZB/u+SUVd2GDaqS1LGta8W/EdA6v+Ag2CP2pVx8RWh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T/HRdpqFRn/Nrl/K85Sl8ONuXIxyS7EgogaNIJMMeMXs5xAeljrg+NfcUiW6sfsJb7SroRqtetMFhqEWEf4TYVnrBLmrIowkF9bDarEHWrAkElpuVidsxBWJoT0PUKaaKqCZInT1Mo9Wm4/lkg76TD1H+LWv3yE4v/0UzJsAnII= 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=ILHS9Tao; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ILHS9Tao" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-823f9f81da5so1359609b3a.1 for ; Tue, 03 Feb 2026 18:28:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172112; x=1770776912; 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=Aq3uuAS8q1FS3IzZLV8ekSAwWgIlL8t7l7cW/84Jw10=; b=ILHS9TaoOh1FYay3lBxAbRFbx5ElMZcOWAGpKb/cmigxRVav4N3i2MqRIDtjwFcGZW I9/+ruaP4ZKEJyUQkVtkmkfUQ9OY5RETDH5PUecbQZpSf5+Rz7AcK422lFi5N+1tUJaK sh5dZb3r5c9vnUSvfbkEmHC2V7RZq1B/aE1TxDhFfAVUtZIhkCjCJjbSq2Db5zoBvxM0 31eu8Mnt3CJcEG5Q90FXN+BhvKuibpuYyTtHZTQACP+qMftx7U6/7Kk8gdLTdxcbr+MI 1IfDjFXK0gh7ivXHV2DxR9dxcwjSlgmU6mgv68n98/IgK332BGJ1qUXY51ENbbvTKiYY nQbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172112; x=1770776912; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Aq3uuAS8q1FS3IzZLV8ekSAwWgIlL8t7l7cW/84Jw10=; b=hKEQQlda/TAQw88P9rdCpycoIVgCi21vFWk0q1jkYmvfzhHMSC4pDWvzgYB2l1rQzi TX/paZ4ui/f4HTz4XHif42Vo7i+ZVfiok2LcIIcCriZGyjy70SClAoKDgfyZe5piiVDA FAo4QbhtN+BKalTWZF6roHB8J4HhvsCagfDHIis2HZsdXX7J/2IggGnaZc8vcDBBDQPB tloownoMQBLbHRXPDZmEHbB8N1Hy+wKt9NbbYWvIsTM4veOb3XCZ+UjUlI0ZXpLDeoFS E1WZOU9BgQKBSck7PlZq37ghLnZAvCyvMqKfI/FN5hFZCMUAjyLUXs+WzWaHlHT0PNhj gAkg== X-Forwarded-Encrypted: i=1; AJvYcCX3MQSEcrqt+AY4SiTv64QRQBbvn9VDzfJl3V3+yHksVM/G3jRaRf6jXcKvPqQOi2QlE7mpgx8wOhosSCY=@vger.kernel.org X-Gm-Message-State: AOJu0YyIwNJIBkYNuxyWJdqpC0UGGdjvh8Y8OW645Fgxrngp+cH+gu/u ZzEyJxY2xZEdRQGhhZsY24b+EWJGzunhpFwrdRqMyIeVicU/M+SUgmFX X-Gm-Gg: AZuq6aJ6fTe/2FesP4Lkvz2U+2OoO39EeoWp74VYLl0Bb4WEUALT97uAxUEKMsvDoGL PaXAY+BDawU0nyndyhsyxqwyJ7xvH66go4o5JrEvkhNhqf/3d2uz9jjuaOO2YgTO5EO/5eijF/I 2hlT9ROWS55eHC+Kcj3ZriRLf+zn0n1Ym/zlTbUfwkmQmt/MpBxeqbZFXC+UK+TjgsypvpxnEbG WLu3BbkzusKTsTeqGYxBXu76rhKDHlmRykgHCQxdHjKmsQQsJ7wUFhz1QrnVHdCBHSDql/AQZAl b9BspXu4a+aCVU025kUAkqaBksxM0PIz70b66Ej38eDruWjDaeNJM40Cg6BpMZCI922aVDMmC04 ZIn3ZiWdyhpnwo/KVjq6hpQZaXfQvIL2+oGmeecMTH7VVRCrG2WZG1sKivV7hZebvZL3+TgU5s5 xe6sncafSBCRVfP8bN91lbCNdGk/aX/+tDBivnfygfLBgfRa2BUprwNMB4Vb9HWPYKf2RlFBDm7 sEqWBrf4Nx0gbnI X-Received: by 2002:a05:6a20:12d0:b0:350:b8e:f9a9 with SMTP id adf61e73a8af0-393723ce739mr1442395637.42.1770172111899; Tue, 03 Feb 2026 18:28:31 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6c8515f36esm600016a12.29.2026.02.03.18.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:30 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 0C9201200C41; Wed, 4 Feb 2026 11:28:29 +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 v14 09/13] x86/um: nommu: signal handling Date: Wed, 4 Feb 2026 11:28:07 +0900 Message-ID: <5e1c488a92193d64dec254880ef7f919667e6f93.1770170302.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 6538c2d8694c..52a525b0e478 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) struct uml_pt_regs r; =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 c08ae4e0edec..7756c30f183c 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -18,6 +18,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 @@ -35,6 +38,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 Sat Feb 7 17:55:41 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29C9E2BDC2C for ; Wed, 4 Feb 2026 02:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172117; cv=none; b=mBbepBmEXHq0R79OpXCTE1UCEOdScV1e6afaci2AqmDxLUzufkUa/ySGvTnoEPW8bLkk7a0EzbwOIMH5avvUbg+lalQ2nw0mr9vy+ub+XgfaMRGocV7Ukrs34SGi6g90mrbc6wTpuahhT9fYejkAtYmGp3W6MpZTBbEQqgm3tHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172117; c=relaxed/simple; bh=ev1/Z1OG/YiuH2q2zg5vvaRdpn7B8WQiRvGRmc9zHfw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SY5gHzXwMhlx7geFxXStVNKOPktzp2nyw5mkHQZdlpXb/2swBh3z1t9cnQLs9t1U7j3AFFeduBf2HhcGZe9TJ63mHbgsj0QdmbAHbRrMQt1/g2wv5cJXP2rDzFMz+mgFXUmVMOzWoFt7dgNWsaEpNm4bafmOz+EcbDl/+9JjezQ= 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=MqW+nN14; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MqW+nN14" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2a79998d35aso2231345ad.0 for ; Tue, 03 Feb 2026 18:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172113; x=1770776913; 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=MnR/gEo9MGuCBEtorpEkbpSgfKcb44tNNZClRV3Eflw=; b=MqW+nN14yKeMDTX2HS1PnrBW6UFyHoPLq1v+N6Z5bFMt8BHDUshM0C05Fe7ojwZVls Tbrg5cnY8F+0b9jS7jviOvfIwwsbKVJ3TBb7baKxAmB6VzcNJTT2swkVUyz2uMovOM9Q 3VA+dgsgb8ouPxCEYa59/Vk5DEoXWsXHgcfcQczBltXMthbgXxy+AEndFPjaS/dGg7hq j9ZAcg4wK3DX1kPDWBjQD3+yEmm/vC3go3ROAvUMajsFveDI5SSnbF29AC/usuzpgi7G T8MTgUnM3NKPI7hvG5jWVKtajiWqQp3cwGCaM8hmHXHqqGvNwndoCLIt4R+bbhCC4h+n JNMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172113; x=1770776913; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MnR/gEo9MGuCBEtorpEkbpSgfKcb44tNNZClRV3Eflw=; b=ACn+9fYoAUOeBtbv72aZv/lIbzi/IPjBv0aX+9xI8e3enPklFwKte5kNMQK+HOJUqL OM+PV1mIwrd/T2hnutoB7Z+G9x0FAfLU19lGexMRQJkr6ggoMPigtpmRLJ2q75BpCafG cf8qnNJh6rnqQKivO85Bqxc7pWXVD1YDk0bbu9lzdpAyPU07hHdf8lNj0sI/HWGAZcdx I5xPzC6rT37Co9+ONVHO9LIoAT/rO4ryrQ5SvlJhruvx+ExNfAcUga4mI5HdpLJQu2sP vKHcuYqwxbop28FSZa4YbRwm4C+THZG4718MLKAKijLSvVSsJ8RS90wDiiu4crqOZgCy s9nw== X-Forwarded-Encrypted: i=1; AJvYcCVtHiWeBzvHcn+8u4xbIHVsFxEcC2oeZo/ttp5pW9mimb6oea78+D+ebrk3fLTDhNEpJbDG1LIvK5ZiqKI=@vger.kernel.org X-Gm-Message-State: AOJu0YxEWFPJPdyuuW9LfIE/pbIf3iD0C+/MokQTqd0AL2xsMLRdGXBX fN2oEKYpXOF374qny3aflrIOgxaRFYbG3pbEyenZgY4zbbhAQbtyN0AH X-Gm-Gg: AZuq6aLHmEUM82ZO1Ngh+HSbyYq9qi2SB6sT9yOAdD+ZhMLBWge6GONcE71uNCfmrJm Xl95tPlC1DuSvcY/bt7i/2jaSKOk7UlGcGMI68Jl4rP4YE6mgUbYz3qJYiF+e5DLfuFzibjSkpW j6DToSIOpnYhdD/DkODoEgH2/xLa+URPZuGV7Rxu89Pco6NVBEVNRxC50KtE7E3e5DFhXylXd2w 0T756PYXUG8WellVvzOdvNcfs0Aq/dhZkVwRAxKK41YMMXw42EkxOF4EZ+g56i9LfGjH5AaqTOR Xt0kcBl6uCOt1jCEBZWPBHqrEHPULGtK87OEJqPL0AaSOcBcGxmfvJwK4KqJmBpyXsLyqLqoa8D x04PteMULEyyYeq4zIIQGg+BlOg3aZRFnidLf+JH8+hNn8qegNRio4LHFqR+mSIT8atNnEUAvas LVHQ4HBUVFSIyhrG137IqZDfE3vTozkxOtp1a5FayAbjbZW9yf8ENVDD4vAJEBUg4Qy5g5aA8mr fjqcr0Bda2RGkx2 X-Received: by 2002:a17:902:d546:b0:2a7:6cd5:b48 with SMTP id d9443c01a7336-2a933e68d37mr16320995ad.29.1770172113431; Tue, 03 Feb 2026 18:28:33 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a93394e387sm6829065ad.48.2026.02.03.18.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:32 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id BB5B31200C43; Wed, 4 Feb 2026 11:28:30 +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 v14 10/13] um: change machine name for uname output Date: Wed, 4 Feb 2026 11:28:08 +0900 Message-ID: <62314a61fd98febda7aafaa746f00eb0b16d1180.1770170302.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit tries to display MMU/!MMU mode from the output of uname(2) so that users can distinguish which mode of UML is running right now. Signed-off-by: Hajime Tazaki --- arch/um/Makefile | 6 ++++++ arch/um/os-Linux/util.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/um/Makefile b/arch/um/Makefile index 5e9bf2a8aa6d..3393e0262888 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -151,6 +151,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 Sat Feb 7 17:55:41 2026 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68C902BEC4E for ; Wed, 4 Feb 2026 02:28:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172116; cv=none; b=Fc6YgMfvcPVBj9nLTFN9/GYs+g0Wgkf4QS/u+QnXAlA3GdZEHpA5Lahn7tSvq9Ew+nt4crAyPymWFIOnX1g6nQdqhK4xvh7NBFtDWx/wOjDeC0V+tOij9+pdP6dhqDmtKQstXtBhaSn6nx2qOxEQoBxY1oKnhGRQEEoJMF8n5XY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172116; c=relaxed/simple; bh=pb+afI/6/X6X9fMm8RSxMg3KNjvn7Kd3MLf/HKmZNFA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jw50LAFnojBHXI86fEvZXnX8d0at5rOFZXAEHMIFeAbB2i6MQk+JII3YCxSBtTKmvl5Uf36Fi5jIofdfkuhf+sPJV0gX0QArw2bDNIAHrhAYrsNE3pdvyo8sUQaLeJYD1muKSGKez00yrKvpHxgRUc7wJZzTvWo76b42gUpSA5Q= 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=HyVeEp2O; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HyVeEp2O" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-c626bd75628so2343087a12.3 for ; Tue, 03 Feb 2026 18:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172115; x=1770776915; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uu/tPbxU9/ARLStujrsMBWUmhOTcbpkoe1nFm3w3B10=; b=HyVeEp2Og+8IQPAifhG5d9c/yuGZ+nGAXVqXfGYzXNQZHP10jiN1Vk8Xl0e3FjcBRf TrwHt0f20i9hlhtcyDSmlWY8VQUyYdVXkD4d8tTIYqPSB1T28wJgxrQfLy3YRc1BDEyH LSKQ7ia8ih4e2jbqeYvhNekQJMYiyRIxURxfma1gdx1uwLKxUNtosnwX3JzspC1cXa4d 7YTXssjeVr8FU34+iDgPkNSo4rd/66ZB4UKqz4nxLKFqHhhN/HqnJgAHuWnmsJkxSh+Q /ow7TG5z1AGlxhym8R0dMWDy9/yJQkudIopvNnzgIW18jaLUkYE/zDumpEBpEHeq+EPk kBqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172115; x=1770776915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uu/tPbxU9/ARLStujrsMBWUmhOTcbpkoe1nFm3w3B10=; b=vy4ZLonqDSYSraM3PadKG1kmGzXs5G3Gkp8ayqVkU09lpaBwqVPSb1wnuPnuZ3MciQ eBVAvg9aXX7IcLFx6KjiWmsMKVHKi6XPybndM2JFhcapcFbw6IVU25XEOeR09jrHmRQ0 OQopYlojpCXX9jKI+O/pGnvfjZEHfYL3R3mzrmeuo2eu41lKw6rS6TO5YvevMB0UKs4D UI4L5VXnJCdKhVWgr0VkSaoxt06Cm3RduNtrzaUnjW7IPB1P/kJCsLi5WR/5xN6yrgy8 tw/Pzz5DPMQoObJswuOH8Ih8ERyuPAeprBNBKsJfYF5DKicN1UaM5JcMHO9AZVo54KdL LJ9A== X-Forwarded-Encrypted: i=1; AJvYcCW0kta9BT9hGxI6vx60jAeHi8ZXIym0VxhXi+tJuuWzNdIXTisanfL5rVAbxo8w9prsCYRKMpcsgKBzehg=@vger.kernel.org X-Gm-Message-State: AOJu0YwSv5w9EzQd0sIM6d7ltcc1nIOTDL9OkF9GxMBy8P9xmvqF893n 9oABqa+y8jchaX89uU4V5QesRNyn8jdmHKPLekrqfVNaY5jZuSyFTFO4HzDZukot X-Gm-Gg: AZuq6aIEsviTUaZLJ1rWN9t7Ii8rAGzQCXE9sbvIQqrXDgISPDqB1qKyfW4p9mNqMRP EuwAsl8oUTadV6m1u0LhbEsZoggrWzo1HsvK4LXORmKsOZ8y+ZkGtUZWsetgxd3nx1cfAqqa1cl svHQS11gW1EDq9FqrZLQY68BYZIsRBIFrxmrRXCyXj+pK0G5xHxEXD2dQGPsvq/6QgIB/wwwhmv cHNvSXYQH75Q48QkDOBdtYHneFZ7IxmNAvvyMaVU4M/7b23QsWoc0dX7ZJLPkD57J/76duJJph8 Zq7NuiRIKvaxG+6P53e6/QIBaIh4KVvESeOWuuAvSwV+ZIximncietf6wPpYdssBcQpei5wgVJO di9PgV8+0Q0oFtcr91OVo5d0XuiUzMXiZlzADYGMBh3vBl4OMgVOKNPEqONl39PfiQDmRstoOTY CDTgSiZeFsVAPml6961sNpg6gGL44609fBKWEWTJGSSS+IK46a9Q1d9KkGgirAJo+DjA57mIja9 JyUAla/kg4JwZ81 X-Received: by 2002:a05:6a21:2d43:b0:342:d58b:561c with SMTP id adf61e73a8af0-393721081a1mr1490301637.27.1770172114792; Tue, 03 Feb 2026 18:28:34 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-354860be66esm848846a91.2.2026.02.03.18.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:33 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 523EE1200C45; Wed, 4 Feb 2026 11:28:32 +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 v14 11/13] um: nommu: disable SMP on nommu UML Date: Wed, 4 Feb 2026 11:28:09 +0900 Message-ID: <3b9e3e4b85c9bdbc4e1fdd123c8270652a88e1e9.1770170302.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 bdd7c8e39b01..f12e2e4e0a12 100644 --- a/arch/x86/um/Kconfig +++ b/arch/x86/um/Kconfig @@ -12,7 +12,7 @@ config UML_X86 select ARCH_USE_QUEUED_SPINLOCKS select DCACHE_WORD_ACCESS select HAVE_EFFICIENT_UNALIGNED_ACCESS - select UML_SUBARCH_SUPPORTS_SMP if X86_CX8 + select UML_SUBARCH_SUPPORTS_SMP if X86_CX8 && MMU =20 config 64BIT bool "64-bit kernel" if "$(SUBARCH)" =3D "x86" --=20 2.43.0 From nobody Sat Feb 7 17:55:41 2026 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 DD9F72BFC85 for ; Wed, 4 Feb 2026 02:28:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172126; cv=none; b=u8kxM2LrPghe7DI0HfKUOPrFkp+vZ5jsSuHJw5FA5wHyikILNfbbkKaRvZp9sKdSbqCGOrUVCu2OTByIKhvVCeFXKeuxUBGV2cHsuWQLS+dq2Tjj1ql5Jh+wVy0QPipeEGaVhXZnnpN5jC3FMsU+vaL7XGIMfpC5zki5u9wVPyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172126; c=relaxed/simple; bh=4EOBn6D9NOchkWdntR2OzGY3J6Nkq9fmc4qX1hahIuc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lY176CG5wcfFLGWd0wb7XneILlBExDD3EdeutdnNFXiXbKzYx+xwsBtxVORDUojf3m7eBEiiMobz0ehdZ+kqpvB0JYSn/GCI7mUuvYPEt4djKEu8Af7eItwJUy3+Uzg78wpgXDHfbd/Sv7P5OKBZAk7hwsMYrZE0OArSFpBRIJE= 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=GsFfRnx9; arc=none smtp.client-ip=209.85.210.196 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="GsFfRnx9" Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-82311f4070cso274201b3a.0 for ; Tue, 03 Feb 2026 18:28:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172116; x=1770776916; 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=6ipAR8Fz6rCIEqHC+jf7avJINpUheKc7NzcjSyRooHM=; b=GsFfRnx9P6ucJCKaM1DYw8pp+XsvslW8+utpWM5aeDw3WTVuuQaA3BjILIoXRHjByZ 7NeyFI3ljJPbHgoi4REpkebux5a0yw76U4Blk+Jk/M6SLTjDbI9U9rgoN2mksKiJsGDp bTzAGG7nnOKp1ag9uQ7gQYcBQBtDROZY9WGYst6AIEsdcgZMjA38RVYS16n56VPxbOex hJmUcRajEhZxumuKz12F3Ns6wbVi0/yLtQdi6kbB/pJxl6GX52ia0W9qcP3q+7zYnXZy 2edB7NUc8oVMp2J1EfvehXyPyTovL/fa5+KAIRvm3ziHCMR7ie1Sp49ujpBWC6pLD1fw 0NFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172116; x=1770776916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6ipAR8Fz6rCIEqHC+jf7avJINpUheKc7NzcjSyRooHM=; b=S6tD3smYs4MR2XSMYfxhShqUlqV7d47oFByTsEF/LU1cxxeCkrRniCR30G0KEFqA++ ZvHrmnzyOf9EEraZAUby+D0Fhq5Oh1d/Sf7Ro1XDwGKcn3vgH9B5t/aSVLQNQEalIZ9J yJFtUxJ4muWwN93srQ9hQ7YnUSDyo3CyUk363Kpj1Uk6gi38ZCtmmaFYGt+FlxsyKKBS vDuLWIHTqNXrSBxc+ANMBbDkgIrXpEKMCxzWpkiiG23gPBTDtbdxfWgzOiFjg/csd4OB AKZ9k84n0IQrS0ayr7wni+/as0xcyPd+m09WWDGmcKdRWI+FjkcXL8qKpSlvMiNgXGHG NmzQ== X-Forwarded-Encrypted: i=1; AJvYcCXwRcL1xzE/dYxolnqVXZl3eZrbmFzMVDEoZsnqXUupQUZsvrGp6tg5Yp/hZjdlI2BD3vBKX7hYyFfOOgo=@vger.kernel.org X-Gm-Message-State: AOJu0YwjUoQzPwkmVXSTf6S2bdAS3gyw6TNtAC/Bb8qlIrkhGZNnUyzK yuwTKEow0mdsbXlEFCPakTWGOvZSRS9MsFk/9SwkiH2TaaU6R2wA1l6j X-Gm-Gg: AZuq6aJesHn08TmzF+qZ2mFWazn2nlOEfTPx2tahm1ok9bmUbFc3tW9NRfnF9+6Q3z3 bGA0D1OA3MdnbIR+Ha0ld1DWnksLCu8Uy7vjeu3H7SHj0tfjAD9bewoYwR/92uhMnAnc6hdRgrC 3S1ZBW5KaATTkWoU/vt+Q7lDDHhJd9YW/3VGaonxXkeCE+kyXIvd/eCW96zF4u0UA6gRSB7cimU AEwyYaUPDQWjBaIqgguEkJX327OABVjROjvowMkmmLlZO9gjBjdYXaoahrzaTFOhx06loQ1e9D4 8+UWydP+d+42hyMXBL/bBDnA0yVMIGzRqGfuuVRlUwxwNxpGHZYgOHOHsgvtUQ0YIz02oGGAM5l XwWbVScE6/RqposkRZ25O0Cmd+kDqxCBNCRLdK1H6fcf4W/ke33cEIsrQ2N3isRVlwf7NhDOZ1Y V/6Y5bq5N2gOf/hHCzo1y+nJPyfSEQMgzrIovKB5VTp+m6mJ06ek+3O7QbYIxwdfWlQiv9HKDf5 IZzYNMIwoORsoBn X-Received: by 2002:a05:6a00:3927:b0:81f:be27:8d16 with SMTP id d2e1a72fcca58-8241c676169mr1501741b3a.21.1770172116190; Tue, 03 Feb 2026 18:28:36 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8241d47b875sm682709b3a.55.2026.02.03.18.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:34 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id D1AE91200C47; Wed, 4 Feb 2026 11:28:33 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v14 12/13] um: nommu: add documentation of nommu UML Date: Wed, 4 Feb 2026 11:28:10 +0900 Message-ID: <950680efa307cd1512ffb029c6d04abb0eed4deb.1770170302.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 | 181 +++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 182 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..b359af1155bb --- /dev/null +++ b/Documentation/virt/uml/nommu-uml.rst @@ -0,0 +1,181 @@ +.. 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 in order to +cover broader code to be executed over UML. + +.. contents:: :local: + +What is it for ? +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +- To exercises nommu code over UML (and over KUnit) +- Reduce syscall latency triggered with the interactions of multiple + processes + + +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 +- alternate syscall hook with a different 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 --kconf= ig_add CONFIG_KUNIT_UML_PCI=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, which are available as additional packages. + + +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 the 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, 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 + MAP_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 +- introduction at FOSDEM 2026 + - https://fosdem.org/2026/schedule/event/HWLQDV-nommu-uml-thehajime/ diff --git a/MAINTAINERS b/MAINTAINERS index 0d044a58cbfe..00912c1a70c5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -27195,6 +27195,7 @@ USER-MODE LINUX (UML) M: Richard Weinberger M: Anton Ivanov M: Johannes Berg +M: Hajime Tazaki L: linux-um@lists.infradead.org S: Maintained W: http://user-mode-linux.sourceforge.net --=20 2.43.0 From nobody Sat Feb 7 17:55:41 2026 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CCE22BF002 for ; Wed, 4 Feb 2026 02:28:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172120; cv=none; b=GypV7P8LQUVA1+3kBuyqdXuJrarZsFUPFvfAblRo5BOAv0S/yqln4iBe+5E294WU69dfRbz/L/+T5JkciPOTVDaknq7dzGFdFbeAxZTQkNJJSL3Hk9PE4oGxGGqcQaDZRqNG5NpHaTVJEhMJ5vab5b66SlwJ78+x7S2W7P40iSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770172120; c=relaxed/simple; bh=+BGv4SK9AOCNPAjOsOp+OXfxp/FZgDlsFpvDq+PDm6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f1hUdSy2CViFocYa1ki7mKM4xvMbrdV99NOn6SBNgWjqPZts6gPT7xvX+8hv6YYiITah5ITV125KsrAF4NurbGirg3ovserHrGTmokOmkGXyv4kI7ylaI4pv1Q/bQj672VngTBgV6kWsShke/OiFruGJusGFHovkJbWhpMfGVW0= 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=dQTpB9wK; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dQTpB9wK" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-8230f8f27cfso3347546b3a.0 for ; Tue, 03 Feb 2026 18:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770172118; x=1770776918; 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=St31LvF0IHppIozPj48TTmhG2uWfbbDiPNVwz27B6eo=; b=dQTpB9wKg4xvjK21NGZUepjj+LwHajexmPh/dUVsg8Eon9otC7i4nO2DTeG043Zrv5 xNarVEBkgzm+ChIOvd9tnRgSF8T2NwSqlAfc56r+BzWhirEumauZsB325gaiAvpYDFCy pG+OgEe+d/qfDLYkm1dMSwqe1nB8oEbr/35OjEodndokEQSoFziX5dsYuAK2KSYvnhvk DWL9zDqYGMhB+DxCT0JrOP5mRm+vEMi6wqRAlgH7ERaEsC2QKZGtZj2jEo+tehZrYI9E B5VT/K6NVjYu8JNjDoW7jh64K3g/jgQLnUmz/90qrBkRgG3KV4OvrLJCeWWU9wJnAmds 3o2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770172118; x=1770776918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=St31LvF0IHppIozPj48TTmhG2uWfbbDiPNVwz27B6eo=; b=BvjSswCaqJrGgfSeILprAI46mXzXcvlzkdROIhl31ahCvpTzSi88FU6OlcDpQHfSLX 3Lt1Bx+W4iCrv1XI+kV0SsdGUPvWYcJT1a8tqOk3qEWyQU94tJAADrqO+8QRTdSJkNES FAoo3E65W/bab2QJpxI8AbDp0vCTI5C9YX3Tq7kuhE/7OOjpl3KleFDGhjJjgL1Bj9KV qy3osU3Vm+QqC45sXk+ISwaFpC6FWS7aw+X/1qZEM4oWcpTIgrMqWouGc+q3phj9p6e3 XWd17rS3Ye0miA4uZYTMBJlVDOpcB+4wokkg8SfS2D1RtspqW+aM1Mzrox8Gj97SyjOs dxlQ== X-Forwarded-Encrypted: i=1; AJvYcCWUyG22pXPXQ/OWQiBCRaQry8jh4iibT+34afFVPeICwO7giRUIeUwG2UaCkQGfJBVLrMzGlmNDIzcAqH8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8PieWMyuaTj0qhI/b2TtUhCpqW6s7EQnn4FbDoZXZjA6qfm1t x+dYx82na/nXqNHBfbGmkjEWaMnn77Xa+oRJkCKSD658n5u2wRgZwxTr X-Gm-Gg: AZuq6aKC2SFvwXQsrbB3y0p5J4iasxexhqmN44jzA7LMmXIWi28qAIjSEA9DaZk1sJW SCE9ygcDogTtZeF7d0AxkHFL0hNS3+GB0p4lRB8kIqKxQ2nmtCY0Ef1HBh8oCuoeKgbnPTSTgqX Vm5LlbUB56jMTaMRvgs3gku7Xi/+A89rrMu9Pu0zHErRlpmKgh0T4ptlT8AzOTJHWHZMAKVM3dt FPyYhhz4FKd3fb7Twg2RlSG4STOhZ51TUtIW1sY+p1rilHkj9aPXl6OlSBAth61DoW1zXi/qy1a jh3lpJ9UzVlFFUnJ4WspWGMcpXnpxbBDZgc4FYMH2r4HJiTvL/zU9wr+RI2SM/E+pG7P/JC2Ucd Kyx7AWnoHL/4PCrIG9LZHpC2U+lYA82heG94+5EzoBzSSMW+ZuDUMua+TS7XXatL8QxdXnWlPaP aZG7Ed2dWTUxeIts3D67o8iHE8nYXS4kh71hexURSZRDgaPmhIzAbzUCqrhwtI/MXISGkngzzXG L3Dmh3lrZnsLvmnn/MHBqNwoY0= X-Received: by 2002:a05:6a00:4b4a:b0:81f:3d13:e07b with SMTP id d2e1a72fcca58-8241c5efb68mr1330656b3a.43.1770172117824; Tue, 03 Feb 2026 18:28:37 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8241d478975sm628857b3a.52.2026.02.03.18.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 18:28:36 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 8BE061200C49; Wed, 4 Feb 2026 11:28:35 +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 v14 13/13] um: nommu: plug nommu code into build system Date: Wed, 4 Feb 2026 11:28:11 +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 8415d39b0d43..1c90e3efef2e 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -35,16 +35,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 @@ -226,8 +229,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