From nobody Thu Oct 9 08:18:31 2025 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 4C71D186284; Thu, 19 Jun 2025 01:04:39 +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=1750295080; cv=none; b=bi19hxrnxCqM6Vno3Cj69I/+I4XN9E33DVScwzgB8WzugDFX6W1ZW8jIMzZNuzy5MZv9OHuUGtRWgOdiJZVHgMBSPYlViM86wq41U5/SbtnLytXJt6Is9UTnv0S8nJ5jU8RSYKRMyODkc9NzjvksthS6FkxHkOSYxpNgPCJHyXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295080; c=relaxed/simple; bh=fm+AK3tlrTe+gYqKBawZVsKJTfAyjuWAJWdKg3VZFJc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yzu+DVZlAFATL9UCVHoKw+Tt/XLrysuMvbRbDYQ4j7f7I3HYdTIqcU9yh6He0SfQM4U6XGSBkQyCv5Och9/z1kNTsJqKTa3DyS/9a9M+lwpEukIzRxNq5VC6IwnaAxDSQwUcikMxrjJCVoDn4+naa1R5noE4JCbUSIwuuMeq41U= 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=fqBZX073; 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="fqBZX073" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7426c44e014so173654b3a.3; Wed, 18 Jun 2025 18:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295078; x=1750899878; 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=AAQlIsbb3rspPlz+RCx7t45Zo7U4vMMrJR2HDEEY2UE=; b=fqBZX07303MtdYip6cMYoxX/PXbNGBBYlT7+5p9RZmKIDkEDNRKiAi3K0IsWKGWzxL NqmARN8Ye94CJG8c47xKuFLX9kQovj4jp1UCN4QAz8TNdpGGUm7I9lk0Zv36CZXWUIzo HyAfkz7aCKgPQh9TDcfmrcfmDfRgE2dpkTnPLUwj5XW4DN/ByS0PWyy/wXYQzMFZbnFN 4PSn5EdNR+9eFZbOw5KgkP6dze2++z4hxiY1Y4pbyUzsllzvmKVGGFfMQVyqg+ZBqIB/ qJXmzUryvUf+B7iOJo7KgJ6xvH9/jajrtWOEGmKOLzuoJfceZ3ZL207MWR8tJdjcyRlg FfPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295078; x=1750899878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AAQlIsbb3rspPlz+RCx7t45Zo7U4vMMrJR2HDEEY2UE=; b=qrtpkSidNBbliz0R/eWDzuGl6zHa62hj1q9S+gQ4tslMn0WHJpaa8pvaJRi/TDXFDd M/4haW/aGD3gu9JtZ+bupGUR6kIzYdnvT04GGSOlHdFR0QBqfr67DhJ1Hq68aX41Xr30 QBit9fCqj3zL5XMyBvN1uxunRZTAfuXbS6nBM1HgmraiD/iDFn2oLLLD/+NrXi4UMk5O hHpmSFY6oKqo/GA/j5lwKR2Kx6DSZ5sFb50/Q//+MNy7zEcsunX8/8ec8OJ6R3LApu1R wXe4k4EfkEVjHtod6CxEeMkk5vmrZKZL0BkPWzd6s8wsCpwqEshATsLGYXih5kDsN0Hh Ww9w== X-Forwarded-Encrypted: i=1; AJvYcCV51YmJVqyEcozu7MQS09/cfR2eAA/lOy80rwkneIvO+itEr+w1Uo6zOLAtaRX5R00wxs/V9181wdCdtnj+@vger.kernel.org, AJvYcCVlIB2U2HTG5/oHH/N8UzIIuevnHYtb/Ylfkc2htQovK8T6OUmL9tkn6HtN16DDv1yq6sncnBIkbdK4iUD6@vger.kernel.org X-Gm-Message-State: AOJu0Yx1h8XDyERTghWknYFm7gC699EAOxv0eCO5v5NPfByH9duEzizl Z0W7OSYzpVWl+CBw7IaEBj/z40OEfQ+RPpitOxPixqCjhZXzowcGLlmY X-Gm-Gg: ASbGncuNviCJlQmL1Z6zDdYdv1TJOLnZNsVgjeHciZbKN5lDrr7HZATAglz8KW+mtGC dZUhE7ixKBqKBKvn7p28Ap1/EXEcadVlPiqmyZDU7Qz6FlOepmLGT9Dv+pjbdpKS3pERbpMSs4T ZniG3N8hV09x1VHy9p9CL//WOoRugIpFElp1SnJYzfAzmJjE7TifIvQ6v2TReMaR9n2G5JcWkN2 sK58FX4/WIvYXRhkVn01lp7YmlYHYhMDJFKghlIp3OIrQALDMB+zfJ0lnJ7euRRWWnRZTwo6ay6 /t3mDhQYhZqJzI38dcE8dNkgBagRPD2gaEUR9SBVFkezpjVH5E/gkZuiDi7pyHRS7Vz1yKSwJec wHQfl9vrvFi539CtxqRVmrHzCHUQJrsHU X-Google-Smtp-Source: AGHT+IHB2DycC27BBHn6mGZ870nAohm4fuY2R4YYnJOfQvt0vJB8Xb8OYArORQprvedXyVNuZmFy3g== X-Received: by 2002:a05:6a00:21c3:b0:742:a334:466a with SMTP id d2e1a72fcca58-7489cf97ddbmr27854811b3a.12.1750295078389; Wed, 18 Jun 2025 18:04:38 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-748900829f7sm11794405b3a.87.2025.06.18.18.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:37 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 1F350ED652A; Thu, 19 Jun 2025 10:04: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, Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v9 01/13] x86/um: nommu: elf loader for fdpic Date: Thu, 19 Jun 2025 10:04:05 +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 4d0e4239f3cc..e9661846b4a3 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -17,6 +17,11 @@ typedef struct mm_context { /* Address range in need of a TLB sync */ unsigned long sync_tlb_range_from; unsigned long sync_tlb_range_to; + +#ifdef CONFIG_BINFMT_ELF_FDPIC + unsigned long exec_fdpic_loadmap; + unsigned long interp_fdpic_loadmap; +#endif } mm_context_t; =20 #endif diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptr= ace-generic.h index 4696f24d1492..4ff844bcb1cd 100644 --- a/arch/um/include/asm/ptrace-generic.h +++ b/arch/um/include/asm/ptrace-generic.h @@ -29,6 +29,12 @@ struct pt_regs { =20 #define PTRACE_OLDSETOPTIONS 21 =20 +#ifdef CONFIG_BINFMT_ELF_FDPIC +#define PTRACE_GETFDPIC 31 +#define PTRACE_GETFDPIC_EXEC 0 +#define PTRACE_GETFDPIC_INTERP 1 +#endif + struct task_struct; =20 extern long subarch_ptrace(struct task_struct *child, long request, diff --git a/arch/x86/um/asm/elf.h b/arch/x86/um/asm/elf.h index 62ed5d68a978..33f69f1eac10 100644 --- a/arch/x86/um/asm/elf.h +++ b/arch/x86/um/asm/elf.h @@ -9,6 +9,7 @@ #include =20 #define CORE_DUMP_USE_REGSET +#define ELF_FDPIC_CORE_EFLAGS 0 =20 #ifdef CONFIG_X86_32 =20 @@ -190,8 +191,11 @@ extern int arch_setup_additional_pages(struct linux_bi= nprm *bprm, =20 extern unsigned long um_vdso_addr; #define AT_SYSINFO_EHDR 33 -#define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr) - +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr); \ + NEW_AUX_ENT(AT_MINSIGSTKSZ, 0); \ +} while (0) #endif =20 typedef unsigned long elf_greg_t; diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index bd2f530e5740..419ba0282806 100644 --- a/fs/Kconfig.binfmt +++ b/fs/Kconfig.binfmt @@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY config BINFMT_ELF_FDPIC bool "Kernel support for FDPIC ELF binaries" default y if !BINFMT_ELF - depends on ARM || ((M68K || RISCV || SUPERH || XTENSA) && !MMU) + depends on ARM || ((M68K || RISCV || SUPERH || UML || XTENSA) && !MMU) select ELFCORE help ELF FDPIC binaries are based on ELF, but allow the individual load --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 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 D65582BB15 for ; Thu, 19 Jun 2025 01:04:42 +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=1750295084; cv=none; b=LcEM9BRKm8OEzFIX039H5leLjdM9fRPYktgBPj2jjs8byPo8SdqK6BRAkJN3M+CQQ6teUF3PXYPftUkiVsPX3chWXjMoE3E7YZKpMNNLKyUIFAD3z3xGvCwgyeOI9FU4bejO8YtKnIS10LZeCzbwP9h+owxviGNvLRI56GbJuck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295084; c=relaxed/simple; bh=dfL0DB/1tST3mKTIw/ve96YMtsSJZhvdkubiQPYfGI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E9EV6LsGOom46w8tM6PAqtUnyuqPiYTQJnZT61GVKjlm/iawR81lsaYdgH4K8gBE4fCTzhczD4xuEG8vBVavLIwYN3esvxSDKlDQ00u02v5v/rI0CqeOc+pi7+YEJZrxPvFQWVBYYUrk3nu/Q2PuaNo3L+Bz7tVUx6GmD5jlv/0= 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=FvE7Wh9g; 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="FvE7Wh9g" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-b31cd61b2a9so200010a12.3 for ; Wed, 18 Jun 2025 18:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295082; x=1750899882; 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=qurq9zWrKcrFnW9xOg2bS+Q7Bbhohl82OFJAmRnuxPk=; b=FvE7Wh9gOxDQmTyL8po5dPT9sTA9OOp11lEi+Uq6Oov955ocMNuoai7lrYyC43mjUe pfCzqXAOzYGQGyEXdtrPNVkK91tCvxUXh0od/MT5HzlCR8YzShkDJgQ61HM80sRp+wR8 TJ/ozgwiMNgagF7RvWbhQXPhuKxG5f8WiEK2LcaIiV1lyHlGD39vw/3VxLpfHFVieAgK R6KBiUd5eyibYsHLhj3bxa1MQPs2LxMofCi9ku2qXp76WRaAz6yMX4gOlHLPyadG5rMr MpB3z5y5E/fkkpMxpFw9zdUQGQBYnS3L97qMbOA2ueyfSkKHNOfp4XGxiLgkwtsb5fng ScZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295082; x=1750899882; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qurq9zWrKcrFnW9xOg2bS+Q7Bbhohl82OFJAmRnuxPk=; b=qtd4kr29jGt5MxM/J/G0oD46+QjTGzMAudCs9l0pe6M9NqJX6wttmcV2qIYH4CFha8 Fk8FqgNIjQ3giIGZK+Y72HCOjiwwybzuyvm+s/ClQniFXSYNJVx87oPGyGgAeWBftwyG rUY8+jTqFE327uY7d+7jMjgIA5eDNneDrU0N32xrnZVqu9l4rRoGsxs7zrqcL+gvYVpF iS9j+fue6zlSh0OmbXEH411eVUFCf7ZhkMAPQrx31KOb3UzGM9+6t4kEfviqoGdPOQW0 uIy51LP6Xhb3KkXf/HbEKhd+4R+FYtA4p4FHqA1VYHlz0W00WYpJBcGyHbYkBRJNfggx AEoA== X-Forwarded-Encrypted: i=1; AJvYcCWKa4jTRaTfPZjqrWqSco0qx3DJp5grz3L+y9ZPNVJ2qhFxjRJ04L5dPWeXLUgvYN3ijO+MfoBlYnHPRqs=@vger.kernel.org X-Gm-Message-State: AOJu0Yzc+S12nX/V39UDRisVtnZHl+IzRoUkccd/1BCk00UC+UZj5+q3 7vUDtk0lj+9lCMow6e5oEb7tx3ZUK+hgRzKCgx+DPJyUOZKI7QvQmTK3 X-Gm-Gg: ASbGncuH3yOzDEE0UvKfctjLnDGN3JbTB+MIgvJ0w88DxSfPA+RhDwZR+mKtBz8LutR I2A7qbd42pDEngmxXvxfcP53iq1WlX/YLUNu2WeHCL3XEOGYP/4ZRauUbovoipu3Ow35RaF4AXk 5BQWPgId6HNz2S99J+TcIOiANIvBEs5USbmm4nyC821xlcoCwUZW8ES19yLQQ3Lnvtt3LuS6qJp csBij0C8kfzk7UiVPKla3U6QT1LaJCQp73hUmGfvQE+7g6VgIj4k56t6Icxd6XogL/xREOkrbWc sj5Y7wqr1V6yleFviZ1c5/1qZXNd3xoC0H2arRL/42YLlJQvfzE/NLwTgf/iYXqEUXjErBP2LEB Ub8haDnWcZ1mT66I4Qnx9UlOnRSHYAyox X-Google-Smtp-Source: AGHT+IGGsTd0mGnaebBWcCkYOCEVuJRK3rXnecTPTmczQrPGvdQtHRuY0AFu7GQonB3MkwOMYxyHqA== X-Received: by 2002:a17:90b:52c6:b0:311:e8cc:424c with SMTP id 98e67ed59e1d1-313f1dee421mr28875026a91.25.1750295082061; Wed, 18 Jun 2025 18:04:42 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3158a250c4bsm841242a91.30.2025.06.18.18.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:40 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 9DB60ED652C; Thu, 19 Jun 2025 10:04: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 v9 02/13] um: decouple MMU specific code from the common part Date: Thu, 19 Jun 2025 10:04:06 +0900 Message-ID: <8f04c03682594850e0f2f5bcff98d298c318d006.1750294482.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This splits the memory, process related code with common and MMU specific parts in order to avoid ifdefs in .c file and duplication between MMU and !MMU. Signed-off-by: Hajime Tazaki --- arch/um/kernel/Makefile | 5 +- arch/um/kernel/mem-pgtable.c | 55 +++++++++++++ arch/um/kernel/mem.c | 35 --------- arch/um/kernel/process.c | 25 ++++++ arch/um/kernel/skas/process.c | 27 ------- arch/um/os-Linux/Makefile | 3 +- arch/um/os-Linux/internal.h | 5 ++ arch/um/os-Linux/process.c | 134 ++++++++++++++++++++++++++++++++ arch/um/os-Linux/skas/process.c | 132 ------------------------------- 9 files changed, 224 insertions(+), 197 deletions(-) create mode 100644 arch/um/kernel/mem-pgtable.c diff --git a/arch/um/kernel/Makefile b/arch/um/kernel/Makefile index 4669db2aa9be..b7922f937213 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -16,9 +16,10 @@ extra-y :=3D vmlinux.lds =20 obj-y =3D config.o exec.o exitcode.o irq.o ksyms.o mem.o \ physmem.o process.o ptrace.o reboot.o sigio.o \ - signal.o sysrq.o time.o tlb.o trap.o \ - um_arch.o umid.o kmsg_dump.o capflags.o skas/ + signal.o sysrq.o time.o \ + um_arch.o umid.o kmsg_dump.o capflags.o obj-y +=3D load_file.o +obj-$(CONFIG_MMU) +=3D mem-pgtable.o tlb.o trap.o skas/ =20 obj-$(CONFIG_BLK_DEV_INITRD) +=3D initrd.o obj-$(CONFIG_GPROF) +=3D gprof_syms.o diff --git a/arch/um/kernel/mem-pgtable.c b/arch/um/kernel/mem-pgtable.c new file mode 100644 index 000000000000..549da1d3bff0 --- /dev/null +++ b/arch/um/kernel/mem-pgtable.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* Allocate and free page tables. */ + +pgd_t *pgd_alloc(struct mm_struct *mm) +{ + pgd_t *pgd =3D (pgd_t *)__get_free_page(GFP_KERNEL); + + if (pgd) { + memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t)); + memcpy(pgd + USER_PTRS_PER_PGD, + swapper_pg_dir + USER_PTRS_PER_PGD, + (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); + } + return pgd; +} + +static const pgprot_t protection_map[16] =3D { + [VM_NONE] =3D PAGE_NONE, + [VM_READ] =3D PAGE_READONLY, + [VM_WRITE] =3D PAGE_COPY, + [VM_WRITE | VM_READ] =3D PAGE_COPY, + [VM_EXEC] =3D PAGE_READONLY, + [VM_EXEC | VM_READ] =3D PAGE_READONLY, + [VM_EXEC | VM_WRITE] =3D PAGE_COPY, + [VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_COPY, + [VM_SHARED] =3D PAGE_NONE, + [VM_SHARED | VM_READ] =3D PAGE_READONLY, + [VM_SHARED | VM_WRITE] =3D PAGE_SHARED, + [VM_SHARED | VM_WRITE | VM_READ] =3D PAGE_SHARED, + [VM_SHARED | VM_EXEC] =3D PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_READ] =3D PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_WRITE] =3D PAGE_SHARED, + [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_SHARED +}; +DECLARE_VM_GET_PAGE_PROT diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 76bec7de81b5..106a2f85ab5c 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -207,45 +206,11 @@ void free_initmem(void) { } =20 -/* Allocate and free page tables. */ - -pgd_t *pgd_alloc(struct mm_struct *mm) -{ - pgd_t *pgd =3D __pgd_alloc(mm, 0); - - if (pgd) - memcpy(pgd + USER_PTRS_PER_PGD, - swapper_pg_dir + USER_PTRS_PER_PGD, - (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); - - return pgd; -} - void *uml_kmalloc(int size, int flags) { return kmalloc(size, flags); } =20 -static const pgprot_t protection_map[16] =3D { - [VM_NONE] =3D PAGE_NONE, - [VM_READ] =3D PAGE_READONLY, - [VM_WRITE] =3D PAGE_COPY, - [VM_WRITE | VM_READ] =3D PAGE_COPY, - [VM_EXEC] =3D PAGE_READONLY, - [VM_EXEC | VM_READ] =3D PAGE_READONLY, - [VM_EXEC | VM_WRITE] =3D PAGE_COPY, - [VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_COPY, - [VM_SHARED] =3D PAGE_NONE, - [VM_SHARED | VM_READ] =3D PAGE_READONLY, - [VM_SHARED | VM_WRITE] =3D PAGE_SHARED, - [VM_SHARED | VM_WRITE | VM_READ] =3D PAGE_SHARED, - [VM_SHARED | VM_EXEC] =3D PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_READ] =3D PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_WRITE] =3D PAGE_SHARED, - [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] =3D PAGE_SHARED -}; -DECLARE_VM_GET_PAGE_PROT - void mark_rodata_ro(void) { unsigned long rodata_start =3D PFN_ALIGN(__start_rodata); diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 0cd6fad3d908..08959745c30d 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,8 @@ struct task_struct *cpu_tasks[NR_CPUS]; EXPORT_SYMBOL(cpu_tasks); =20 +static char cpu0_irqstack[THREAD_SIZE] __aligned(THREAD_SIZE); + void free_stack(unsigned long stack, int order) { free_pages(stack, order); @@ -295,3 +298,25 @@ unsigned long __get_wchan(struct task_struct *p) =20 return 0; } + + +static int __init start_kernel_proc(void *unused) +{ + block_signals_trace(); + + start_kernel(); + return 0; +} + +int __init start_uml(void) +{ + stack_protections((unsigned long) &cpu0_irqstack); + set_sigstack(cpu0_irqstack, THREAD_SIZE); + + init_new_thread_signals(); + + init_task.thread.request.thread.proc =3D start_kernel_proc; + init_task.thread.request.thread.arg =3D NULL; + return start_idle_thread(task_stack_page(&init_task), + &init_task.thread.switch_buf); +} diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c index 05dcdc057af9..5247121d3419 100644 --- a/arch/um/kernel/skas/process.c +++ b/arch/um/kernel/skas/process.c @@ -16,33 +16,6 @@ #include #include =20 -extern void start_kernel(void); - -static int __init start_kernel_proc(void *unused) -{ - block_signals_trace(); - - start_kernel(); - return 0; -} - -extern int userspace_pid[]; - -static char cpu0_irqstack[THREAD_SIZE] __aligned(THREAD_SIZE); - -int __init start_uml(void) -{ - stack_protections((unsigned long) &cpu0_irqstack); - set_sigstack(cpu0_irqstack, THREAD_SIZE); - - init_new_thread_signals(); - - init_task.thread.request.thread.proc =3D start_kernel_proc; - init_task.thread.request.thread.arg =3D NULL; - return start_idle_thread(task_stack_page(&init_task), - &init_task.thread.switch_buf); -} - unsigned long current_stub_stack(void) { if (current->mm =3D=3D NULL) diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index fae836713487..c048fc838068 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile @@ -8,7 +8,8 @@ KCOV_INSTRUMENT :=3D n =20 obj-y =3D execvp.o file.o helper.o irq.o main.o mem.o process.o \ registers.o sigio.o signal.o start_up.o time.o tty.o \ - umid.o user_syms.o util.o skas/ + umid.o user_syms.o util.o +obj-$(CONFIG_MMU) +=3D skas/ =20 CFLAGS_signal.o +=3D -Wframe-larger-than=3D4096 =20 diff --git a/arch/um/os-Linux/internal.h b/arch/um/os-Linux/internal.h index 5d8d3b0817a9..89cfab0d5e47 100644 --- a/arch/um/os-Linux/internal.h +++ b/arch/um/os-Linux/internal.h @@ -5,6 +5,11 @@ #include #include =20 +/* + * process.c + */ +extern int userspace_pid[]; + /* * elf_aux.c */ diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 00b49e90d05f..4eb7e137ef4b 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -6,6 +6,7 @@ =20 #include #include +#include #include #include #include @@ -15,10 +16,17 @@ #include #include #include +#include #include #include #include #include +#include +#include + +int using_seccomp; +int userspace_pid[NR_CPUS]; +int unscheduled_userspace_iterations; =20 void os_alarm_process(int pid) { @@ -189,3 +197,129 @@ void os_set_pdeathsig(void) { prctl(PR_SET_PDEATHSIG, SIGKILL); } + +int is_skas_winch(int pid, int fd, void *data) +{ + return pid =3D=3D getpgrp(); +} + +void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)) +{ + (*buf)[0].JB_IP =3D (unsigned long) handler; + (*buf)[0].JB_SP =3D (unsigned long) stack + UM_THREAD_SIZE - + sizeof(void *); +} + +#define INIT_JMP_NEW_THREAD 0 +#define INIT_JMP_CALLBACK 1 +#define INIT_JMP_HALT 2 +#define INIT_JMP_REBOOT 3 + +void switch_threads(jmp_buf *me, jmp_buf *you) +{ + unscheduled_userspace_iterations =3D 0; + + if (UML_SETJMP(me) =3D=3D 0) + UML_LONGJMP(you, 1); +} + +static jmp_buf initial_jmpbuf; + +/* XXX Make these percpu */ +static void (*cb_proc)(void *arg); +static void *cb_arg; +static jmp_buf *cb_back; + +int start_idle_thread(void *stack, jmp_buf *switch_buf) +{ + int n; + + set_handler(SIGWINCH); + + /* + * Can't use UML_SETJMP or UML_LONGJMP here because they save + * and restore signals, with the possible side-effect of + * trying to handle any signals which came when they were + * blocked, which can't be done on this stack. + * Signals must be blocked when jumping back here and restored + * after returning to the jumper. + */ + n =3D setjmp(initial_jmpbuf); + switch (n) { + case INIT_JMP_NEW_THREAD: + (*switch_buf)[0].JB_IP =3D (unsigned long) uml_finishsetup; + (*switch_buf)[0].JB_SP =3D (unsigned long) stack + + UM_THREAD_SIZE - sizeof(void *); + break; + case INIT_JMP_CALLBACK: + (*cb_proc)(cb_arg); + longjmp(*cb_back, 1); + break; + case INIT_JMP_HALT: + kmalloc_ok =3D 0; + return 0; + case INIT_JMP_REBOOT: + kmalloc_ok =3D 0; + return 1; + default: + printk(UM_KERN_ERR "Bad sigsetjmp return in %s - %d\n", + __func__, n); + fatal_sigsegv(); + } + longjmp(*switch_buf, 1); + + /* unreachable */ + printk(UM_KERN_ERR "impossible long jump!"); + fatal_sigsegv(); + return 0; +} + +void initial_thread_cb_skas(void (*proc)(void *), void *arg) +{ + jmp_buf here; + + cb_proc =3D proc; + cb_arg =3D arg; + cb_back =3D &here; + + block_signals_trace(); + if (UML_SETJMP(&here) =3D=3D 0) + UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); + unblock_signals_trace(); + + cb_proc =3D NULL; + cb_arg =3D NULL; + cb_back =3D NULL; +} + +void halt_skas(void) +{ + block_signals_trace(); + UML_LONGJMP(&initial_jmpbuf, INIT_JMP_HALT); +} + +static bool noreboot; + +static int __init noreboot_cmd_param(char *str, int *add) +{ + *add =3D 0; + noreboot =3D true; + return 0; +} + +__uml_setup("noreboot", noreboot_cmd_param, +"noreboot\n" +" Rather than rebooting, exit always, akin to QEMU's -no-reboot option.= \n" +" This is useful if you're using CONFIG_PANIC_TIMEOUT in order to catch= \n" +" crashes in CI\n"); + +void reboot_skas(void) +{ + block_signals_trace(); + UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT); +} + +void __switch_mm(struct mm_id *mm_idp) +{ + userspace_pid[0] =3D mm_idp->pid; +} diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/proces= s.c index e42ffac23e3c..808d8c205b65 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -29,16 +28,10 @@ #include #include #include -#include #include #include #include "../internal.h" =20 -int is_skas_winch(int pid, int fd, void *data) -{ - return pid =3D=3D getpgrp(); -} - static const char *ptrace_reg_name(int idx) { #define R(n) case HOST_##n: return #n @@ -433,9 +426,6 @@ static int __init init_stub_exe_fd(void) } __initcall(init_stub_exe_fd); =20 -int using_seccomp; -int userspace_pid[NR_CPUS]; - /** * start_userspace() - prepare a new userspace process * @mm_id: The corresponding struct mm_id @@ -548,7 +538,6 @@ int start_userspace(struct mm_id *mm_id) return err; } =20 -int unscheduled_userspace_iterations; extern unsigned long tt_extra_sched_jiffies; =20 void userspace(struct uml_pt_regs *regs) @@ -786,124 +775,3 @@ void userspace(struct uml_pt_regs *regs) } } } - -void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)) -{ - (*buf)[0].JB_IP =3D (unsigned long) handler; - (*buf)[0].JB_SP =3D (unsigned long) stack + UM_THREAD_SIZE - - sizeof(void *); -} - -#define INIT_JMP_NEW_THREAD 0 -#define INIT_JMP_CALLBACK 1 -#define INIT_JMP_HALT 2 -#define INIT_JMP_REBOOT 3 - -void switch_threads(jmp_buf *me, jmp_buf *you) -{ - unscheduled_userspace_iterations =3D 0; - - if (UML_SETJMP(me) =3D=3D 0) - UML_LONGJMP(you, 1); -} - -static jmp_buf initial_jmpbuf; - -/* XXX Make these percpu */ -static void (*cb_proc)(void *arg); -static void *cb_arg; -static jmp_buf *cb_back; - -int start_idle_thread(void *stack, jmp_buf *switch_buf) -{ - int n; - - set_handler(SIGWINCH); - - /* - * Can't use UML_SETJMP or UML_LONGJMP here because they save - * and restore signals, with the possible side-effect of - * trying to handle any signals which came when they were - * blocked, which can't be done on this stack. - * Signals must be blocked when jumping back here and restored - * after returning to the jumper. - */ - n =3D setjmp(initial_jmpbuf); - switch (n) { - case INIT_JMP_NEW_THREAD: - (*switch_buf)[0].JB_IP =3D (unsigned long) uml_finishsetup; - (*switch_buf)[0].JB_SP =3D (unsigned long) stack + - UM_THREAD_SIZE - sizeof(void *); - break; - case INIT_JMP_CALLBACK: - (*cb_proc)(cb_arg); - longjmp(*cb_back, 1); - break; - case INIT_JMP_HALT: - kmalloc_ok =3D 0; - return 0; - case INIT_JMP_REBOOT: - kmalloc_ok =3D 0; - return 1; - default: - printk(UM_KERN_ERR "Bad sigsetjmp return in %s - %d\n", - __func__, n); - fatal_sigsegv(); - } - longjmp(*switch_buf, 1); - - /* unreachable */ - printk(UM_KERN_ERR "impossible long jump!"); - fatal_sigsegv(); - return 0; -} - -void initial_thread_cb_skas(void (*proc)(void *), void *arg) -{ - jmp_buf here; - - cb_proc =3D proc; - cb_arg =3D arg; - cb_back =3D &here; - - block_signals_trace(); - if (UML_SETJMP(&here) =3D=3D 0) - UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); - unblock_signals_trace(); - - cb_proc =3D NULL; - cb_arg =3D NULL; - cb_back =3D NULL; -} - -void halt_skas(void) -{ - block_signals_trace(); - UML_LONGJMP(&initial_jmpbuf, INIT_JMP_HALT); -} - -static bool noreboot; - -static int __init noreboot_cmd_param(char *str, int *add) -{ - *add =3D 0; - noreboot =3D true; - return 0; -} - -__uml_setup("noreboot", noreboot_cmd_param, -"noreboot\n" -" Rather than rebooting, exit always, akin to QEMU's -no-reboot option.= \n" -" This is useful if you're using CONFIG_PANIC_TIMEOUT in order to catch= \n" -" crashes in CI\n"); - -void reboot_skas(void) -{ - block_signals_trace(); - UML_LONGJMP(&initial_jmpbuf, noreboot ? INIT_JMP_HALT : INIT_JMP_REBOOT); -} - -void __switch_mm(struct mm_id *mm_idp) -{ - userspace_pid[0] =3D mm_idp->pid; -} --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 5572A19E97C for ; Thu, 19 Jun 2025 01:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295083; cv=none; b=RZ+CZRirw2pMGg1GyzWcKsc7rCBljQ0fcEfqIJxkF0TKKxFZpnQYB9jvObMSJBqwN6qtHcqvl/dGrjBiE3nIjk5xSPfb6Nfg2kFe7f7lOoBCU9s6oe8mslkdlV/fvH1nGwY7bK2mL3OiMYAjQFgS6/UefPOS6JoZ2MGuMD2AGVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295083; c=relaxed/simple; bh=PrnDkOztux8Lftfz3cRwSL8F1uSiVMGY60W6duSht4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oWrD63ptxaxe2mL2uzJO2RGRpkmZBfBP3l0WU8T1ldXu7PW3tvON2Z45HGuUFKcaf5z4DP0++BnT4EUO7itNEmdiFchaq6GbnKpyMHpTUrZoy4M4CNBv5nAfwEe76Ae+9qUnmOvn+fyzurpGZfFEPDcfCrNobXXqrj1vu7ZSJp4= 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=UVBv1IDe; arc=none smtp.client-ip=209.85.216.44 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="UVBv1IDe" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3122a63201bso121759a91.0 for ; Wed, 18 Jun 2025 18:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295081; x=1750899881; 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=nJZY7fSdjsRmE94xDQ9kPtMR3Ats2B2OoNFvSkK6k9U=; b=UVBv1IDe1hZLpk5V4gK1O+QsHZE76EiO4YiH7TF9mR1lQxMLB0muDZSdJqipcu3w+c dnuxnotgw4GYO0nJf7qVuXzIm05jvYOTlamvWB7TSFQCUfwuLZTUMednfGnQ6HYk995E N/bhDWbrFK8O79XO8PoEtvZX0kuzE3UQwRgacM+sG1LyPEweVRNwAOf41nWWy/W6JXds mRAuLfC8xVoxJnWgfYR6bzKvXNRjN6L2wHd9ncRr21ujHaCFffnNcWo7PEvjJa+dhbXT ll0/Uc4n+IGI4JlMLFVzBmiyBKw2nefJwcMmV2HoH+u+Vo1C8X9L++7Oz7CNArdDH4V/ porQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295081; x=1750899881; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nJZY7fSdjsRmE94xDQ9kPtMR3Ats2B2OoNFvSkK6k9U=; b=TH5DTc29Q+if3lH6ka2EajPhh0cLyDUdc916jyycw4lT1D0SDUj7E4a3NKI2sgxNsL tYtBEkVifJAmwKOB7JwFSHekpL+V07Cvr8J6d6r0PnmnVjRmCGIWadJODY6PLa1VYNMk lrMovrNrYOZnrW2Ws90EJ7eJNJVrLPn8PlmF7u+w+kEz8nX6UgOlyIkm6BWzLTQH7EN5 jKDNScxKtGrJmacAgauIMbOkdTYBSh+t9H59DcuOltXKoizOWM+4/mn4EJzzCDUK4lli Y/vCaHkfoZJ5nSbf+wzMLWSNMcKdo1vL5HHa6fMMxDlM4OsnJeyc6T6lVeUhgX6IDKuQ xPDg== X-Forwarded-Encrypted: i=1; AJvYcCXAPbktBHaXzvexYvzqaPhMOT79z39+E00oCBeu6gZbO+/6Cv3L82X/SE39m02rYRcOm7kCM5CnRSh39YU=@vger.kernel.org X-Gm-Message-State: AOJu0Yxe2jEQMBkyZbv+rjnDi+LU3g2mkManoHARMwOPebjqMPmLHFzP X3nyJlDKKGNA7fMG7TKBdOHLzB9KFsaU26Ww+cjLWlKSfjv500/+Fc3C X-Gm-Gg: ASbGncsWSlyqnvHgiRLnD//jdXocPtMxNaqMl4m43Ze953z+HV+OhO9yB9DH02AzbCN UfSNxmqnhaskikFYJMSaYQa6rGuZMMgDRtgxwXbJdZASDtBi9o+32gP60iSodlShJt69GRumn3X EXqyS6rptheVgWm9FC++SX7/DSjnrm1sc6jva2EsbS/CXh2bPvk5UX09AZcVCqAJnTGLiCFQIWj BzOAxX04s1aUV/r6swqzR0JReSTNZgPsYYV5OkhraC/9r6ZX2PQKx6RtkkvDUK2CSOMpkRCtBFM dLbHUJwCCfLdlby68Q1pZZYg6I53sA9CkQfvcvupS68OeqauNkPc5BWHCxTmE3qefEAImKaVOsl 7/y/ccc2/on+Dn4gmwkYCBXiv1x5HX2B9 X-Google-Smtp-Source: AGHT+IH4uU1pGplG19mmCzAP1mwEmJG8BFCTlYV0YGKJFwD9XSBO3JUptsHATvAeeZW9CGCCDm0fGw== X-Received: by 2002:a17:90b:528f:b0:312:2bb:aa89 with SMTP id 98e67ed59e1d1-313f1d50e08mr27014989a91.20.1750295081409; Wed, 18 Jun 2025 18:04:41 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3158a318673sm821989a91.34.2025.06.18.18.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:40 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id D7147ED652E; Thu, 19 Jun 2025 10:04: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 v9 03/13] um: nommu: memory handling Date: Thu, 19 Jun 2025 10:04:07 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit adds memory operations on UML under !MMU environment. Some part of the original UML code relying on CONFIG_MMU are excluded from compilation when !CONFIG_MMU. Additionally, generic functions such as uaccess, futex, memcpy/strnlen/strncpy can be used as user- and kernel-space share the address space in !CONFIG_MMU mode. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/Makefile | 4 ++++ arch/um/include/asm/futex.h | 4 ++++ arch/um/include/asm/mmu.h | 3 +++ arch/um/include/asm/mmu_context.h | 2 ++ arch/um/include/asm/uaccess.h | 7 ++++--- arch/um/kernel/mem.c | 3 ++- arch/um/os-Linux/mem.c | 4 ++++ arch/um/os-Linux/process.c | 4 ++-- 8 files changed, 25 insertions(+), 6 deletions(-) diff --git a/arch/um/Makefile b/arch/um/Makefile index 7be0143b5ba3..5371c9a1b11e 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -46,6 +46,10 @@ ARCH_INCLUDE :=3D -I$(srctree)/$(SHARED_HEADERS) ARCH_INCLUDE +=3D -I$(srctree)/$(HOST_DIR)/um/shared KBUILD_CPPFLAGS +=3D -I$(srctree)/$(HOST_DIR)/um =20 +ifneq ($(CONFIG_MMU),y) +core-y +=3D $(ARCH_DIR)/nommu/ +endif + # -Dvmap=3Dkernel_vmap prevents anything from referencing the libpcap.o sy= mbol so # named - it's a common symbol in libpcap, so we get a binary which crashe= s. # diff --git a/arch/um/include/asm/futex.h b/arch/um/include/asm/futex.h index 780aa6bfc050..785fd6649aa2 100644 --- a/arch/um/include/asm/futex.h +++ b/arch/um/include/asm/futex.h @@ -7,8 +7,12 @@ #include =20 =20 +#ifdef CONFIG_MMU int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *= uaddr); int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 oldval, u32 newval); +#else +#include +#endif =20 #endif diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h index e9661846b4a3..9f30c69e5278 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -18,10 +18,13 @@ typedef struct mm_context { unsigned long sync_tlb_range_from; unsigned long sync_tlb_range_to; =20 +#ifndef CONFIG_MMU + unsigned long end_brk; #ifdef CONFIG_BINFMT_ELF_FDPIC unsigned long exec_fdpic_loadmap; unsigned long interp_fdpic_loadmap; #endif +#endif /* !CONFIG_MMU */ } mm_context_t; =20 #endif diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_co= ntext.h index 23dcc914d44e..033a70166066 100644 --- a/arch/um/include/asm/mmu_context.h +++ b/arch/um/include/asm/mmu_context.h @@ -36,11 +36,13 @@ static inline void switch_mm(struct mm_struct *prev, st= ruct mm_struct *next, } } =20 +#ifdef CONFIG_MMU #define init_new_context init_new_context extern int init_new_context(struct task_struct *task, struct mm_struct *mm= ); =20 #define destroy_context destroy_context extern void destroy_context(struct mm_struct *mm); +#endif =20 #include =20 diff --git a/arch/um/include/asm/uaccess.h b/arch/um/include/asm/uaccess.h index 1c6e0ae41b0c..b9677758e759 100644 --- a/arch/um/include/asm/uaccess.h +++ b/arch/um/include/asm/uaccess.h @@ -23,6 +23,7 @@ #define __addr_range_nowrap(addr, size) \ ((unsigned long) (addr) <=3D ((unsigned long) (addr) + (size))) =20 +#ifdef CONFIG_MMU extern unsigned long raw_copy_from_user(void *to, const void __user *from,= unsigned long n); extern unsigned long raw_copy_to_user(void __user *to, const void *from, u= nsigned long n); extern unsigned long __clear_user(void __user *mem, unsigned long len); @@ -34,9 +35,6 @@ static inline int __access_ok(const void __user *ptr, uns= igned long size); =20 #define INLINE_COPY_FROM_USER #define INLINE_COPY_TO_USER - -#include - static inline int __access_ok(const void __user *ptr, unsigned long size) { unsigned long addr =3D (unsigned long)ptr; @@ -70,5 +68,8 @@ do { \ barrier(); \ current->thread.segv_continue =3D NULL; \ } while (0) +#endif + +#include =20 #endif diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 106a2f85ab5c..4be1cf240d71 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -64,7 +64,8 @@ void __init arch_mm_preinit(void) * to be turned on. */ brk_end =3D (unsigned long) UML_ROUND_UP(sbrk(0)); - map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0); + map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, + !IS_ENABLED(CONFIG_MMU)); memblock_free((void *)brk_end, uml_reserved - brk_end); uml_reserved =3D brk_end; min_low_pfn =3D PFN_UP(__pa(uml_reserved)); diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index 72f302f4d197..4f5d9a94f8e2 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c @@ -213,6 +213,10 @@ int __init create_mem_file(unsigned long long len) { int err, fd; =20 + /* NOMMU kernel uses -1 as a fd for further use (e.g., mmap) */ + if (!IS_ENABLED(CONFIG_MMU)) + return -1; + fd =3D create_tmp_file(len); =20 err =3D os_set_exec_close(fd); diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 4eb7e137ef4b..8a1ab59a089f 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -99,8 +99,8 @@ int os_map_memory(void *virt, int fd, unsigned long long = off, unsigned long len, prot =3D (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | (x ? PROT_EXEC : 0); =20 - loc =3D mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED, - fd, off); + loc =3D mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED | + (!IS_ENABLED(CONFIG_MMU) ? MAP_ANONYMOUS : 0), fd, off); if (loc =3D=3D MAP_FAILED) return -errno; return 0; --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.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 7D9387405A for ; Thu, 19 Jun 2025 01:04:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295086; cv=none; b=dPtXfgd0jnosExNkimkSQ0l9y+lLcqUK6tYHtSnnz1RkxacHvlvJKdvaZByGBSzM/rlobreSKv8UTu5QQtr/Wmxf13pnvIu+SHqiZPBMjNURHVoOZeM+z8w4YFY343LlvVj93BbUlHkKchbzBtkwdYE4gfJ74lkD2kqBuBXNwZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295086; c=relaxed/simple; bh=uiSxmtJMthrLo+oH9HhdUFVGn3NpOpl/5AJlOYbiDcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p9LwL6dKImJWQrIoHfsOWEJt5P2e9zoru6wTB9wyLbMjhYy/OmTIjdJC2uDLaDIWEicv40MowM/JnoosazjHC9tBV5j0dTa26l3eQzcwhOWAR1Rvnrp3umGfhYbTRq7EaJkKFqSKw/T/83+4zT3ujNw+Qbp/1OV8NQANkGLaM48= 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=MSSLdjsu; arc=none smtp.client-ip=209.85.214.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="MSSLdjsu" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-236377f00a1so2456555ad.3 for ; Wed, 18 Jun 2025 18:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295084; x=1750899884; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V/9FDFFbTGgOECfx9E1KzmmWlTydkD+KFqPPHo/qkbE=; b=MSSLdjsuONpD8xVvFktgRvCplEU0mbjdXdyX3qMmySIa0PYPYKYpID1d5619elLiZw YC+Tx39uv2P+aAwbvLGDSG0femtvg/754GvTZobe11ubDP/WtJ7KtKdzEMjR0Uh7WxWl V11cZ1J2re6RSZV/Zctwpo5Vk96arPdBdEikhWmVPPtvNubjYq4cRxonI9a5HGD+oMYZ HyjSpvCP105v4jGFEiXcjkH7rEayVyMEptl54EMHK2+6IC9Pc1bbthXbc9JGSYullOFk nqACD9otv1TIpbO91XDw7I5PBGkuwD6L5P8UKVb8bqSklc5qzRuJN+cyQ+GsGIuvGhMf RS4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295084; x=1750899884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V/9FDFFbTGgOECfx9E1KzmmWlTydkD+KFqPPHo/qkbE=; b=FlpzEPWy6T1eteMKJBVj2klbMuK5jW1JQS3JeyzukXV++TLeys/k4lgSfREoDVL1H8 NzVJoUUGOl0Vc6iy5AtJTzp8anmgx3WVl1x37hGCxmV+/bmL8pvjnWRUWMCm8E1awuX+ 2oMvoW9huzeh9aPDeCGuK7h4zZ6HBF4dE7HR6VBvlIcmoruGwAiXxLW+YDMjWw7sAkRc 9/U/yR1q8R3pqAP7Kg7cMG7R7z21lzRoZ7Ayx+vOHezn+b9WMOiJtUi/sRm7L0VqB+QW 5eoeR6Hepat6icQ79O/Q/KSosYq3tvd7r3pMrHrm4nZXy33VPkVNIcsBz9KdSHKtda2u KqGQ== X-Forwarded-Encrypted: i=1; AJvYcCU0ClmTludnkya1TyefuKFOphMpOLNk9k8ZHiaR2ZODj//G+/Qw2bFK1KzkMIjDIKdIJMh4pPx1JopZOKs=@vger.kernel.org X-Gm-Message-State: AOJu0YyG1fjyhDL6udZFp7suXPUis9AcsHM59MsRrEYWFJtLbvUGUEud 0coBrTLE3N5JlCT8+ay3pr4nqNhPyAGTJVrk4bQ+8+1EPUVchai+g5dm X-Gm-Gg: ASbGncuT4/qFw1bHmZPe/ZDcoLemM+/9CuSKJzJwEI27Gl9oo+n8os1ItoLbZfvvso/ Wk2RO5O49IIxX6cplxj2vvASYVfTNtClaZcAAs3iy8+DGRR6oMhCRsBpExfw/4idDErJi9ANBw7 NNq0WU/alvYPZitm8T0cKW+n/djrJDaBrWgecwQpFuHSCx6sDObbUFBO7k/EZlaB51SV003bW8P ic8w/d8XjHa8L+bheCLkpu7GFSIfRxe1WFVgrsLeRdB1QlM21ZoZe7ifUQbuoiLD08ynAxPaI0D wZTl7Y7fYzYcW78eb96EXs7XZQFSz84lM/MPkZzOtocUFkU9k1DZpbaQHVhqoAUj9DSPb3Ml23Y hWUZKiQ1lI3QOtuvawZlSAK9JeDojfiWm X-Google-Smtp-Source: AGHT+IHvM6xy+FybjKS1IKrh7yVw74Mi4qPHFfz1bqRbdGlFvoJqyDnxRfmhedTPUtTIES8RLYdKIw== X-Received: by 2002:a17:902:d485:b0:234:f580:9f5 with SMTP id d9443c01a7336-2366afbad1dmr293812725ad.9.1750295083540; Wed, 18 Jun 2025 18:04:43 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2366e4d67adsm88122985ad.75.2025.06.18.18.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:40 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 1F8D3ED6530; Thu, 19 Jun 2025 10:04:37 +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 v9 04/13] x86/um: nommu: syscall handling Date: Thu, 19 Jun 2025 10:04:08 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit introduces an entry point of syscall interface for !MMU mode. It uses an entry function, __kernel_vsyscall, a kernel-wide global symbol accessible from any locations. Although it isn't in the scope of this commit, it can be also exposed via vdso image which is directly accessible from userspace. A standard library (i.e., libc) can utilize this entry point to implement syscall wrapper; we can also use this by hooking syscall for unmodified userspace applications/libraries, which will be implemented in the subsequent commit. This only supports 64-bit mode of x86 architecture. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/x86/um/Makefile | 4 ++ arch/x86/um/nommu/Makefile | 8 +++ arch/x86/um/nommu/do_syscall_64.c | 37 ++++++++++ arch/x86/um/nommu/entry_64.S | 91 +++++++++++++++++++++++++ arch/x86/um/nommu/syscalls.h | 16 +++++ arch/x86/um/shared/sysdep/syscalls_64.h | 6 ++ 6 files changed, 162 insertions(+) create mode 100644 arch/x86/um/nommu/Makefile create mode 100644 arch/x86/um/nommu/do_syscall_64.c create mode 100644 arch/x86/um/nommu/entry_64.S create mode 100644 arch/x86/um/nommu/syscalls.h diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index b42c31cd2390..227af2a987e2 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -32,6 +32,10 @@ obj-y +=3D syscalls_64.o vdso/ subarch-y =3D ../lib/csum-partial_64.o ../lib/memcpy_64.o \ ../lib/memmove_64.o ../lib/memset_64.o =20 +ifneq ($(CONFIG_MMU),y) +obj-y +=3D nommu/ +endif + endif =20 subarch-$(CONFIG_MODULES) +=3D ../kernel/module.o diff --git a/arch/x86/um/nommu/Makefile b/arch/x86/um/nommu/Makefile new file mode 100644 index 000000000000..d72c63afffa5 --- /dev/null +++ b/arch/x86/um/nommu/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +ifeq ($(CONFIG_X86_32),y) + BITS :=3D 32 +else + BITS :=3D 64 +endif + +obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_sysca= ll_64.c new file mode 100644 index 000000000000..5d0fa83e7fdc --- /dev/null +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +__visible void do_syscall_64(struct pt_regs *regs) +{ + int syscall; + + syscall =3D PT_SYSCALL_NR(regs->regs.gp); + UPT_SYSCALL_NR(®s->regs) =3D syscall; + + pr_debug("syscall(%d) (current=3D%lx) (fn=3D%lx)\n", + syscall, (unsigned long)current, + (unsigned long)sys_call_table[syscall]); + + if (likely(syscall < NR_syscalls)) { + PT_REGS_SET_SYSCALL_RETURN(regs, + EXECUTE_SYSCALL(syscall, regs)); + } + + pr_debug("syscall(%d) --> %lx\n", syscall, + regs->regs.gp[HOST_AX]); + + PT_REGS_SYSCALL_RET(regs) =3D regs->regs.gp[HOST_AX]; + + /* execve succeeded */ + if (syscall =3D=3D __NR_execve && regs->regs.gp[HOST_AX] =3D=3D 0) + userspace(¤t->thread.regs.regs); + + /* force do_signal() --> is_syscall() */ + set_thread_flag(TIF_SIGPENDING); + interrupt_end(); +} diff --git a/arch/x86/um/nommu/entry_64.S b/arch/x86/um/nommu/entry_64.S new file mode 100644 index 000000000000..e9bfc7b93c84 --- /dev/null +++ b/arch/x86/um/nommu/entry_64.S @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include + +#include +#include +#include + +#include "../entry/calling.h" + +#ifdef CONFIG_SMP +#error need to stash these variables somewhere else +#endif + +#define UM_GLOBAL_VAR(x) .data; .align 8; .globl x; x:; .long 0 + +UM_GLOBAL_VAR(current_top_of_stack) +UM_GLOBAL_VAR(current_ptregs) + +.code64 +.section .entry.text, "ax" + +.align 8 +#undef ENTRY +#define ENTRY(x) .text; .globl x; .type x,%function; x: +#undef END +#define END(x) .size x, . - x + +/* + * %rcx has the return address (we set it before entering __kernel_vsyscal= l). + * + * Registers on entry: + * rax system call number + * rcx return address + * rdi arg0 + * rsi arg1 + * rdx arg2 + * r10 arg3 + * r8 arg4 + * r9 arg5 + * + * (note: we are allowed to mess with r11: r11 is callee-clobbered + * register in C ABI) + */ +ENTRY(__kernel_vsyscall) + + movq %rsp, %r11 + + /* Point rsp to the top of the ptregs array, so we can + just fill it with a bunch of push'es. */ + movq current_ptregs, %rsp + + /* 8 bytes * 20 registers (plus 8 for the push) */ + addq $168, %rsp + + /* Construct struct pt_regs on stack */ + pushq $0 /* pt_regs->ss (index 20) */ + pushq %r11 /* pt_regs->sp */ + pushfq /* pt_regs->flags */ + pushq $0 /* pt_regs->cs */ + pushq %rcx /* pt_regs->ip */ + pushq %rax /* pt_regs->orig_ax */ + + PUSH_AND_CLEAR_REGS rax=3D$-ENOSYS + + mov %rsp, %rdi + + /* + * Switch to current top of stack, so "current->" points + * to the right task. + */ + movq current_top_of_stack, %rsp + + call do_syscall_64 + + movq current_ptregs, %rsp + + POP_REGS + + addq $8, %rsp /* skip orig_ax */ + popq %rcx /* pt_regs->ip */ + addq $8, %rsp /* skip cs */ + addq $8, %rsp /* skip flags */ + popq %rsp + + /* + * not return w/ ret but w/ jmp as the stack is already popped before + * entering __kernel_vsyscall + */ + jmp *%rcx + +END(__kernel_vsyscall) diff --git a/arch/x86/um/nommu/syscalls.h b/arch/x86/um/nommu/syscalls.h new file mode 100644 index 000000000000..a2433756b1fc --- /dev/null +++ b/arch/x86/um/nommu/syscalls.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __UM_NOMMU_SYSCALLS_H +#define __UM_NOMMU_SYSCALLS_H + + +#define task_top_of_stack(task) \ +({ \ + unsigned long __ptr =3D (unsigned long)task->stack; \ + __ptr +=3D THREAD_SIZE; \ + __ptr; \ +}) + +extern long current_top_of_stack; +extern long current_ptregs; + +#endif diff --git a/arch/x86/um/shared/sysdep/syscalls_64.h b/arch/x86/um/shared/s= ysdep/syscalls_64.h index b6b997225841..ffd80ee3b9dc 100644 --- a/arch/x86/um/shared/sysdep/syscalls_64.h +++ b/arch/x86/um/shared/sysdep/syscalls_64.h @@ -25,4 +25,10 @@ extern syscall_handler_t *sys_call_table[]; extern syscall_handler_t sys_modify_ldt; extern syscall_handler_t sys_arch_prctl; =20 +#ifndef CONFIG_MMU +extern void do_syscall_64(struct pt_regs *regs); +extern long __kernel_vsyscall(int64_t a0, int64_t a1, int64_t a2, int64_t = a3, + int64_t a4, int64_t a5, int64_t a6); +#endif + #endif --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 021041A5BB2 for ; Thu, 19 Jun 2025 01:04:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295087; cv=none; b=RkAdMZdjQebNTwxJvj7Ya5ByHZZB9Z8697wrIiAOvy+B/Cl4flfGs3mh+m+K6clV/c1rOvrWVOwefy5gn+QbFqiW5wRvhgLr1AvKYNCDYB680Qgx3eWKjcV5YxlX6kzxiDbhKnyqXLbyjccFwLGBc8gqKnpZ9Nfhbg6sROCI7Kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295087; c=relaxed/simple; bh=aI/a1cXGXvx7I7cf7SF1XPZkt49h25YOh7Q+a504gb0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cahQ9tDo1ffdBmilSHP0Z7EZERMzTJyq3qta1GGNPZGTqaFCT2ob5rXkgarmLhPIskw1Mr2vUTA22/ZvBaV62NgOa0tZ5pkKAJIXrX/WpAErb3NYqBh+aguo530H56hxgAG/XUqXHD60XZaWGr9FbPBlGyiEH2P1x9XAL6lBUJ8= 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=UgbRJBC4; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UgbRJBC4" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2366e5e4dbaso1851315ad.1 for ; Wed, 18 Jun 2025 18:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295085; x=1750899885; 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=Ji+ZU1sT1gsELuhh4VwtCDF/4tcor+mPUimFYMKA61U=; b=UgbRJBC45h7xivTiC67BO2Awlq06cP+4v7OTtiHvBKxIaLBm8eIV7q+olgzOm2zAa1 4P4ZB18XEnVK13V8eaphZJVO5HHG245CwR8yH77rNhpMBftO44FPKohugiUFJxTPxuI6 izI6pG9quOOFJgoV5+ufiM26fS0MnW+p4Z7KfFx36NaNtVhV1uvE/XMP9l+d5RLfnXK/ KenECf9rltZ0NbX2ZOlmuxXCzTOT+3OWnI0W8oL1B3QHg6dFwhxdjmUD3uVdhC3FC3F8 quycDfBJlifzK3qwxTxHVcUtDFHHFqAkTn2ZT0Po+aU1QcmgAZkmcjg84s7aezylvFRI uLmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295085; x=1750899885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ji+ZU1sT1gsELuhh4VwtCDF/4tcor+mPUimFYMKA61U=; b=Gjn75szMIo0R73ATzDbxZrKy7AWqe20I6MMeb/txcwe3cpc0IDxgJf0t8F1uQWcLBs 4/YQOwiY0GsP0EOXx6UXptT2bkSMW/Q+8gFg+mk4EE6uK9HmCCH3FtP21e8BJMocZPBK ix+i/1RYTjk1yYp5QkxXGtZfdMBzeMaSy51VKDeZw95v8TmN/0FRs2ggrGg7PS4Yndzg lpn4u7IrOAUIRHRWx3u8L8ESQF2v1oF2ZrTitrWuree7Cd+tr9WhhRKqwoWp/2y8Tp92 RzgT8kU5zvZSuUW8U+5KJ127NXhv58HiNr88dlYqJtWMEquPYAoj4wJ+NMqw9IJkX8oQ YHEA== X-Forwarded-Encrypted: i=1; AJvYcCUDxMuM38TgCda7ZnrOuledWt44vz6Toq8IYc6sRJxBMwhYeV0XF/WdfdU/YQt3svLtKUj/9sa4nz2khls=@vger.kernel.org X-Gm-Message-State: AOJu0YwD/1fIRx3gUQEBnXnpNnyqnL6L4ZJ7yOvUSXxfL93m7sbokLKl 0D3fG3TFFcETNVU9BxoSBFbAWEOGbhCKockgGZNk2NLnCYdwF6eufR// X-Gm-Gg: ASbGncscTWMLKgfoRdBSPOGvB4GjRwyxzeqIXQE3hIbuz9r8PFHeYAO/7v4oxaGJzeV nAYuHVXVpms8O30CgSoaYjrnuZq8g4D8bn8FlCvZKCJa/GljIZNyfSbsHGLsfrdphkpHHgCl5hr 2cRIee+OhFXL5MJzLtAigij2MSYjjGcNGL09lAUnF6pXarj1IkpFD2gtbnaDvDLatVhK4AF+AgP scVs5jSsWoivs73XmwHWBRD5WOkge1uWp+fj3qsaXeR68dbIWv5guEwgpH8NLWoU0yutCHxrumG dwRWWe7+YU4vRBFRCWpoCjZhJurB6Ii8blV6mzPSwB6QXVRDBFGF/54DvD7T0yHKxuPSyms/fLU iv2+dAtWDqFl0IaWsmDdoQDzvKeH0qu8E X-Google-Smtp-Source: AGHT+IHYeO1brdKDkunGQe6NWOSRQervR7OrylHVdVsGvONq6e3US8BG6tbFscc3JIS8Qm+sGe51JQ== X-Received: by 2002:a17:902:e550:b0:235:efbb:9537 with SMTP id d9443c01a7336-237cbee5016mr23428255ad.3.1750295085045; Wed, 18 Jun 2025 18:04:45 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2365decad5fsm107969565ad.211.2025.06.18.18.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:44 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 99C23ED6532; Thu, 19 Jun 2025 10:04:42 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org, Kenichi Yasukata Subject: [PATCH v9 05/13] um: nommu: seccomp syscalls hook Date: Thu, 19 Jun 2025 10:04:09 +0900 Message-ID: <9a59a67dad5b7455ff975a68ba5f5fb95a8d02a9.1750294482.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/signal.c | 16 +++++ arch/um/os-Linux/Makefile | 5 ++ arch/um/os-Linux/seccomp.c | 87 +++++++++++++++++++++++++++ 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 | 13 ++++ arch/x86/um/shared/sysdep/mcontext.h | 4 ++ 14 files changed, 167 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/signal.c create mode 100644 arch/um/os-Linux/seccomp.c create mode 100644 arch/x86/um/nommu/os-Linux/Makefile create mode 100644 arch/x86/um/nommu/os-Linux/mcontext.c diff --git a/arch/um/include/shared/kern_util.h b/arch/um/include/shared/ke= rn_util.h index 00ca3e12fd9a..ec8ba1f13c58 100644 --- a/arch/um/include/shared/kern_util.h +++ b/arch/um/include/shared/kern_util.h @@ -66,6 +66,8 @@ extern void segv_handler(int sig, struct siginfo *unused_= si, struct uml_pt_regs extern void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *= regs, void *mc); extern void fatal_sigsegv(void) __attribute__ ((noreturn)); +extern void sigsys_handler(int sig, struct siginfo *si, struct uml_pt_regs= *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 b35cc8ce333b..1251f08e26d0 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -338,4 +338,14 @@ extern void um_trace_signals_off(void); /* time-travel */ extern void deliver_time_travel_irqs(void); =20 +/* seccomp.c */ +#ifdef CONFIG_MMU +static inline int os_setup_seccomp(void) +{ + return 0; +} +#else +extern int os_setup_seccomp(void); +#endif + #endif diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index 2f5ee045bc7a..14b9dcab9907 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -431,6 +431,9 @@ void __init setup_arch(char **cmdline_p) add_bootloader_randomness(rng_seed, sizeof(rng_seed)); memzero_explicit(rng_seed, sizeof(rng_seed)); } + + /* install seccomp filter */ + os_setup_seccomp(); } =20 void __init arch_cpu_finalize_init(void) diff --git a/arch/um/nommu/Makefile b/arch/um/nommu/Makefile new file mode 100644 index 000000000000..baab7c2f57c2 --- /dev/null +++ b/arch/um/nommu/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y :=3D os-Linux/ diff --git a/arch/um/nommu/os-Linux/Makefile b/arch/um/nommu/os-Linux/Makef= ile new file mode 100644 index 000000000000..68833c576437 --- /dev/null +++ b/arch/um/nommu/os-Linux/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-y :=3D signal.o +USER_OBJS :=3D $(obj-y) + +include $(srctree)/arch/um/scripts/Makefile.rules +USER_CFLAGS+=3D-I$(srctree)/arch/um/os-Linux diff --git a/arch/um/nommu/os-Linux/signal.c b/arch/um/nommu/os-Linux/signa= l.c new file mode 100644 index 000000000000..19043b9652e2 --- /dev/null +++ b/arch/um/nommu/os-Linux/signal.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +void sigsys_handler(int sig, struct siginfo *si, + struct uml_pt_regs *regs, void *ptr) +{ + mcontext_t *mc =3D (mcontext_t *) ptr; + + /* hook syscall via SIGSYS */ + set_mc_sigsys_hook(mc); +} diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index c048fc838068..432476a4239a 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile @@ -21,4 +21,9 @@ USER_OBJS :=3D $(user-objs-y) elf_aux.o execvp.o file.o h= elper.o irq.o \ main.o mem.o process.o registers.o sigio.o signal.o start_up.o time.o \ tty.o umid.o util.o =20 +ifneq ($(CONFIG_MMU),y) +obj-y +=3D seccomp.o +USER_OBJS +=3D seccomp.o +endif + include $(srctree)/arch/um/scripts/Makefile.rules diff --git a/arch/um/os-Linux/seccomp.c b/arch/um/os-Linux/seccomp.c new file mode 100644 index 000000000000..d1cfa6e3d632 --- /dev/null +++ b/arch/um/os-Linux/seccomp.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include /* For SYS_xxx definitions */ +#include +#include +#include +#include +#include + +int __init os_setup_seccomp(void) +{ + int err; + unsigned long __userspace_start =3D uml_reserved, + __userspace_end =3D high_physmem; + + struct sock_filter filter[] =3D { + /* if (IP_high > __userspace_end) allow; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JGT + BPF_K, __userspace_end >> 32, + /*true-skip=3D*/0, /*false-skip=3D*/1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high =3D=3D __userspace_end && IP_low >=3D __userspace_end) al= low; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __userspace_end >> 32, + /*true-skip=3D*/0, /*false-skip=3D*/3), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer)), + BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, __userspace_end, + /*true-skip=3D*/0, /*false-skip=3D*/1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high < __userspace_start) allow; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, __userspace_start >> 32, + /*true-skip=3D*/1, /*false-skip=3D*/0), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high =3D=3D __userspace_start && IP_low < __userspace_start) a= llow; */ + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer) + 4), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __userspace_start >> 32, + /*true-skip=3D*/0, /*false-skip=3D*/3), + BPF_STMT(BPF_LD + BPF_W + BPF_ABS, + offsetof(struct seccomp_data, instruction_pointer)), + BPF_JUMP(BPF_JMP + BPF_JGE + BPF_K, __userspace_start, + /*true-skip=3D*/1, /*false-skip=3D*/0), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* other address; trap */ + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_TRAP), + }; + struct sock_fprog prog =3D { + .len =3D ARRAY_SIZE(filter), + .filter =3D filter, + }; + + err =3D prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); + if (err) + os_warn("PR_SET_NO_NEW_PRIVS (err=3D%d, ernro=3D%d)\n", + err, errno); + + err =3D syscall(SYS_seccomp, SECCOMP_SET_MODE_FILTER, + SECCOMP_FILTER_FLAG_TSYNC, &prog); + if (err) { + os_warn("SECCOMP_SET_MODE_FILTER (err=3D%d, ernro=3D%d)\n", + err, errno); + exit(1); + } + + set_handler(SIGSYS); + + os_info("seccomp: setup filter syscalls in the range: 0x%lx-0x%lx\n", + __userspace_start, __userspace_end); + + return 0; +} + diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c index 11f07f498270..53e276e81b37 100644 --- a/arch/um/os-Linux/signal.c +++ b/arch/um/os-Linux/signal.c @@ -20,6 +20,7 @@ #include #include #include +#include =20 void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *, void *= mc) =3D { [SIGTRAP] =3D relay_signal, @@ -30,6 +31,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) @@ -176,6 +178,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); @@ -187,6 +194,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 a827c2e01aa5..4e1f05360c49 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c @@ -238,7 +238,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 @@ -273,7 +273,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..c4ef877d5ea0 --- /dev/null +++ b/arch/x86/um/nommu/os-Linux/mcontext.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#define __FRAME_OFFSETS +#include +#include +#include +#include + +void set_mc_sigsys_hook(mcontext_t *mc) +{ + mc->gregs[REG_RCX] =3D mc->gregs[REG_RIP]; + mc->gregs[REG_RIP] =3D (unsigned long) __kernel_vsyscall; +} diff --git a/arch/x86/um/shared/sysdep/mcontext.h b/arch/x86/um/shared/sysd= ep/mcontext.h index 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 Thu Oct 9 08:18:31 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 558D81D63F0 for ; Thu, 19 Jun 2025 01:04:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295089; cv=none; b=kdnxDyMySaY8xkMp1QQQcLTocIJ6MkCZRkTov3nGmsEIwpYCdgWoVRSZpKCsyipv29AMQV/s9zJ5UFJ0/mIsFhHdSYjuYaPiScFGSUFkP7nmkmTe8kCFPNdu3NOYpCbspNykCrEQU7WoMVvvw0CURpIQkkFmv66V5sH+1ZDBFnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295089; c=relaxed/simple; bh=AdjiadfNdikwR+Cvww+/ONdcJ2psLy/wXdOHlbBBnww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T/vN46qnVuN1FAV7ECaTMiQKqO5vcXGCCa2x7mKRdMlzJu2DwjXr14SH9MmxFGcU84AE2Bwf49MuuYOJMmgDVcZJ8yyhKjQMPEpjlf90p7PA1CCR2Kp8ogU/vqRKlXtS2fDRxrmcyGM48hJLfcIj2D1nY14fH7XHoMKwzEmnXG0= 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=b0ZYGF4X; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b0ZYGF4X" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-234d3261631so2029675ad.1 for ; Wed, 18 Jun 2025 18:04:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295087; x=1750899887; 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=l1JpwCKV9cSghAwgpJmSpCtGipBuaO2tDQC5fW0CSv4=; b=b0ZYGF4XS1+bEz/0Xk/CGoQxyBpy/aPue6MiHCezZ1TLridsgi6IdOgrAZnEDzb4e+ yqeivIvHsbE7KPO1SxXl5XoxhHbsqtEaz8N2T1xX56RGqFeujBkwZSUokmYxDkuMOCfO F4T3gzDzI7JWp6gwynapcSDpQHl8zbmHPE8446xEm6LQCyKXAEeWUhSygy3xb7112lel bcLSb109NKhpwgtCfj9ATfYH3/y2GyGeF3xtyXKhOiNAqWNic463f6mKqyVUGUNoiv0v md025lTBI0nI4GKlHLwRQ5mZLUnbfugfInYndulMUgd+UJBNPHhX9Gtjx/iRE1nx1rAF ypPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295087; x=1750899887; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l1JpwCKV9cSghAwgpJmSpCtGipBuaO2tDQC5fW0CSv4=; b=UGg+cQPwHWrkrntD303+Ye2p+2kfoycf8WlHw+jxcBkk44rYKz8MiKUO169cByffsF jO4eKlaHl8dEpex6wFx1bS7w5HuQEKx+rujmTy/oHyiJ1ndF6QuByIygQsOcpyb2FI0j l9LsEogWPYfCDXdYv421j9/Qsxwdm5bLdvnnXyudReCtMX4pxI4jPLV155/BWV4LZAQb wGH4Ggp020Nf6+n5szZgpTO4yIlBxuFyGHOFyLPfPwhiOi8agMJNTaLF1ybD9hoTpE7Y t+FQCk7aU7gPGJ7bNL1PVnuZ7YLy6xf+xwO1oCaJlI4j3eXYvbJTfmiIezEOHEaYA9gj sZcA== X-Forwarded-Encrypted: i=1; AJvYcCWDD9QoN/PHwhSygGB1zTMiOuPdyU5Dc8Mwb+YnnLkoCQiyfc8cu6mJzJb4fRxd961N3VN02WOH7m99CgI=@vger.kernel.org X-Gm-Message-State: AOJu0YzYCY/QgbBBW29yR4U5r93hPWgyTgtYR6r0aZN/65mm+TwnIdXJ zOq5kHxHeGMDbE+kaQ2JO291SI2Xs6gsclIZHcPVhGlbCPiI/KQFz15lOO0PMQ== X-Gm-Gg: ASbGnctXzQwoeJAM78eUj3N4F45lZ29vYInahGGFMC9yS9jaBhtEfLKYdYaNXEbbjtB hup2b5sz5S4wjrqShPKTWm5EejqsOCeXRvVrcI5zGHeqoGol3P3YOhZ5kPu0lCgeZvscPG4RP9n V39k909kUbliQ1wolN7q6E0JE5jdTYNjoN7rykA0NVFh27eqJlj1KqJgv7LqlS6BmV+StfnUlBY ZTNDpxN4RvuuXNwxWeJ0QihbLj0ZsysHcXsw67yCDd2YJpVv+0TaiL4/jAE7FDgOcVUyDM9JjeI xGUxrhClcNOz0j0MhhSjHZrjmV6Pk3DSIs6U8extf9ufg5vSf6+VTjeqw6KYQYO3h9/dxwxWm8C Khvf0tSGC7s1U/nA2hc/S9+6goDs9IF+0 X-Google-Smtp-Source: AGHT+IHDigGDVi6Llb6rP2JHFHMbl9WEBfHRUW50U+jgVpWh5ds2qZPmAqsuS7zCc3upwEx3RuRZdg== X-Received: by 2002:a17:902:e805:b0:234:c65f:6c0c with SMTP id d9443c01a7336-2366b00ed66mr294160555ad.15.1750295087364; Wed, 18 Jun 2025 18:04:47 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2365de782bdsm108126865ad.113.2025.06.18.18.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:46 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id DD028ED6534; Thu, 19 Jun 2025 10:04:44 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 06/13] x86/um: nommu: process/thread handling Date: Thu, 19 Jun 2025 10:04:10 +0900 Message-ID: <031503649a24799bff082cf917c36550f4820181.1750294482.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since ptrace facility isn't used under !MMU of UML, there is different code path to invoke processes/threads; there are no external process used, and need to properly configure some of registers (fs segment register for TLS, etc) on every context switch, etc. Signals aren't delivered in non-ptrace syscall entry/leave so, we also need to handle pending signal by ourselves. ptrace related syscalls are not tested yet so, marked arch_has_single_step() unsupported in !MMU environment. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/asm/ptrace-generic.h | 2 +- arch/x86/um/Makefile | 3 +- arch/x86/um/nommu/Makefile | 2 +- arch/x86/um/nommu/entry_64.S | 22 ++++++++++++++ arch/x86/um/nommu/syscalls_64.c | 44 ++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 arch/x86/um/nommu/syscalls_64.c diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptr= ace-generic.h index 4ff844bcb1cd..a9778c9a59a3 100644 --- a/arch/um/include/asm/ptrace-generic.h +++ b/arch/um/include/asm/ptrace-generic.h @@ -14,7 +14,7 @@ struct pt_regs { struct uml_pt_regs regs; }; =20 -#define arch_has_single_step() (1) +#define arch_has_single_step() (IS_ENABLED(CONFIG_MMU)) =20 #define EMPTY_REGS { .regs =3D EMPTY_UML_PT_REGS } =20 diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index 227af2a987e2..53c9ebb3c41c 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -27,7 +27,8 @@ subarch-y +=3D ../kernel/sys_ia32.o =20 else =20 -obj-y +=3D syscalls_64.o vdso/ +obj-y +=3D vdso/ +obj-$(CONFIG_MMU) +=3D syscalls_64.o =20 subarch-y =3D ../lib/csum-partial_64.o ../lib/memcpy_64.o \ ../lib/memmove_64.o ../lib/memset_64.o diff --git a/arch/x86/um/nommu/Makefile b/arch/x86/um/nommu/Makefile index ebe47d4836f4..4018d9e0aba0 100644 --- a/arch/x86/um/nommu/Makefile +++ b/arch/x86/um/nommu/Makefile @@ -5,4 +5,4 @@ else BITS :=3D 64 endif =20 -obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o os-Linux/ +obj-y =3D do_syscall_$(BITS).o entry_$(BITS).o syscalls_$(BITS).o os-Linux/ diff --git a/arch/x86/um/nommu/entry_64.S b/arch/x86/um/nommu/entry_64.S index e9bfc7b93c84..950447dfa66b 100644 --- a/arch/x86/um/nommu/entry_64.S +++ b/arch/x86/um/nommu/entry_64.S @@ -89,3 +89,25 @@ ENTRY(__kernel_vsyscall) jmp *%rcx =20 END(__kernel_vsyscall) + +// void userspace(struct uml_pt_regs *regs) +ENTRY(userspace) + + /* align the stack for x86_64 ABI */ + and $-0x10, %rsp + /* Handle any immediate reschedules or signals */ + call interrupt_end + + movq current_ptregs, %rsp + + POP_REGS + + addq $8, %rsp /* skip orig_ax */ + popq %r11 /* pt_regs->ip */ + addq $8, %rsp /* skip cs */ + addq $8, %rsp /* skip flags */ + popq %rsp + + jmp *%r11 + +END(userspace) diff --git a/arch/x86/um/nommu/syscalls_64.c b/arch/x86/um/nommu/syscalls_6= 4.c new file mode 100644 index 000000000000..c78c442aed1d --- /dev/null +++ b/arch/x86/um/nommu/syscalls_64.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2003 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) + * Copyright 2003 PathScale, Inc. + * + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include /* XXX This should get the constants from libc */ +#include +#include +#include "syscalls.h" + +void arch_switch_to(struct task_struct *to) +{ + /* + * In !CONFIG_MMU, it doesn't ptrace thus, + * The FS_BASE/GS_BASE registers are saved here. + */ + current_top_of_stack =3D task_top_of_stack(to); + current_ptregs =3D (long)task_pt_regs(to); + + if ((to->thread.regs.regs.gp[FS_BASE / sizeof(unsigned long)] =3D=3D 0) || + (to->mm =3D=3D NULL)) + return; + + /* this changes the FS on every context switch */ + arch_prctl(to, ARCH_SET_FS, + (void __user *) to->thread.regs.regs.gp[FS_BASE / sizeof(unsigned lon= g)]); +} + +SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, + unsigned long, prot, unsigned long, flags, + unsigned long, fd, unsigned long, off) +{ + if (off & ~PAGE_MASK) + return -EINVAL; + + return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); +} --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9B4A18EFD4 for ; Thu, 19 Jun 2025 01:04:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295092; cv=none; b=ZvcsLyc3Xj4tnEXEjjfzqLxaoEIGMXqphHQDGsE9V290gEv+1t8JN95kMZY/JHT5zo6/rPCxnP9x7olnN//+lkChZ8OQ4AJMcl2rmway05wviJKj1k1BpUlB0PFogjpLPVpZR42nMc8+iKsLpsiLmiv/+y+SCBMZoR1eQlkt9zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295092; c=relaxed/simple; bh=O2JwOhGN7x6zkLg/VfIyxgWYO5ZxuKclp2S+k/vZwws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ys5t+1u42bovqxQUm3a9araKil0w+Zb8JeUAduhk+8tTfGosPtNy4G0GvmYoWYWTdl3UJeJtx0GmkTIbiPLQOQmAaZysyQ/Hgvobg289CWGoGoXuByEb7265ik/KhtlkmCE1BG2tzEsqTL38dPiT/P+/vunaXt1pXGLb+R+P0ZY= 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=dJe1yag6; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dJe1yag6" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-748e81d37a7so138458b3a.1 for ; Wed, 18 Jun 2025 18:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295090; x=1750899890; 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=ihdFXWNIx+H443+kP6md5Dj55CMYh0h9g6RuQVPwAiE=; b=dJe1yag6PrUnduVtlzxYq6bJtqJ9aVKa15myd8k4oYJwMvVFJ1J+Hj54xYurKDIGY4 TZt17mCn8m9imGQhQ1I2R0vPvEyWlgnbwl8j+6ii9PP1o4Edu4P+vqmGhD89gUp+7D3W ZhF400DC+2y4QMLV83gXfo4jva4OFcNiKhuOsIS6opzQpnKAD3m2ROTaJJTEqk/NwMcX vJpTWGDjMxzyYVCadVxa1Hw143/fgRYjQEmc+JI3OIWzuUvdruOwS+kFoQLgkFM4IEFE wfwWj1q6PFiPZ+6TbAd/wOp96uii8xcHMlmvkD7cks8cd7l/59hamL7ZpKqW/pDQlGM5 InBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295090; x=1750899890; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ihdFXWNIx+H443+kP6md5Dj55CMYh0h9g6RuQVPwAiE=; b=inpJOjg2KOvZGvVSa37hlPULx9W28AmO6sYrV8VewmPWtt2j7FQ1WC0DUCXy4KnzO9 ElvQ5trNTQj52KId1HQZFBRBdxULHJWAm1c515GgZmBo+PstQnMdYCTQ0L4ciW+tp9zF SWK5hdWjY0shnorV3pDmsNPBXFhAmOL+JSA7wygC7le8/ZFzDcigF8UVV62D46GP0HXZ X5Z3RMRJk8/SEZS+iqZM69PTJW37t26sdos8xX+s6G2Cu7Ojo2gsM+m4sN6ziZllTjHl G+tB1B7ElcnTOeYFUbTfImDu1bWC08QDczG2TpaxvalKHRo8/CbBD0bu6KMw2/frVFFZ AsVg== X-Forwarded-Encrypted: i=1; AJvYcCXkVCWbE0X90r+GN2HlckVYGjtT3pYd1ai1ngRR8hoKx6nl0BEzvdP0O9HXMEEqeRHS+rGP5urDS20yd4Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzL8rP8G8/c47UuGvxGlkG90oJnqNyjTC4jjWugwmm3pvgiKu1f vZanldqlXvnbWXa8qZ6bMGDXNDN0arAzTKSekfbCMy0AvzcPpo/WWu11 X-Gm-Gg: ASbGnctPR96pUmSS4prmnbwSUgKHfx3gn+Rmg5/bI0pAb4jrOTzszfqBPEjdqayAYE7 He9sq6hlWo8L+VFdIIncYrNZu9HEJtQ8MyIAHiB9k/4OEAjIJyo2tLxWnm3fCGC7ySTg/6b/Bau PZy8XdIl5pEzZv+AlvGuYbze0cG0/ejP39uVBfCVhvIoOG6ICEfkRVAMp6aSrI99tLuMggUNsSl KDUBwzFABosIgCWH1n9fiCBXvMEgKZhq475XqsfbC+R92bJ6kR+laR7kU0oee+KJSGarw08Pjt8 9YlBarMyMxjglzBrSMf9f6lzzEEAf08g0iGD6oWj5eaOG/681TNzcWfE4mKKDa6JTrWddf8QZF9 wVpYuYawCwLeQuyr7vAfp8VK1uMO2WDt6 X-Google-Smtp-Source: AGHT+IGZ4bg7vYaVF4gGWT0CG08w6lmpULaJfwfanalAIWgpjTFJYjIFTJnjoOhko+Y0PjC8ljzkjQ== X-Received: by 2002:a05:6a21:99a8:b0:1f5:535c:82dc with SMTP id adf61e73a8af0-21fbd668c44mr28761235637.42.1750295090022; Wed, 18 Jun 2025 18:04:50 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b2fe1691d7fsm11895294a12.69.2025.06.18.18.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:49 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 2EBD5ED6536; Thu, 19 Jun 2025 10:04:46 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 07/13] um: nommu: configure fs register on host syscall invocation Date: Thu, 19 Jun 2025 10:04:11 +0900 Message-ID: <2863dab9b3f9d6536b73623398a3f39e4ae70957.1750294482.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As userspace on UML/!MMU also need to configure %fs register when it is running to correctly access thread structure, host syscalls implemented in os-Linux drivers may be puzzled when they are called. Thus it has to configure %fs register via arch_prctl(SET_FS) on every host syscalls. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/shared/os.h | 6 +++ arch/um/os-Linux/process.c | 6 +++ arch/um/os-Linux/start_up.c | 21 +++++++++ arch/x86/um/nommu/do_syscall_64.c | 37 ++++++++++++++++ arch/x86/um/nommu/syscalls_64.c | 71 +++++++++++++++++++++++++++++++ 5 files changed, 141 insertions(+) diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 1251f08e26d0..7c6a8bc0447c 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 8a1ab59a089f..3a6d34ccd12b 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -16,6 +16,7 @@ #include #include #include +#include /* For SYS_xxx definitions */ #include #include #include @@ -178,6 +179,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 4e1f05360c49..55dd92bd2a0b 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 @@ -36,6 +38,8 @@ #include #include "internal.h" =20 +int host_has_fsgsbase; + static void ptrace_child(void) { int ret; @@ -459,6 +463,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; @@ -484,6 +502,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 5d0fa83e7fdc..796beb0089fc 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -2,10 +2,38 @@ =20 #include #include +#include +#include #include #include #include =20 +static int os_x86_arch_prctl(int pid, int option, unsigned long *arg2) +{ + if (!host_has_fsgsbase) + return os_arch_prctl(pid, option, arg2); + + switch (option) { + case ARCH_SET_FS: + wrfsbase(*arg2); + break; + case ARCH_SET_GS: + wrgsbase(*arg2); + break; + case ARCH_GET_FS: + *arg2 =3D rdfsbase(); + break; + case ARCH_GET_GS: + *arg2 =3D rdgsbase(); + break; + default: + pr_warn("%s: unsupported option: 0x%x", __func__, option); + break; + } + + return 0; +} + __visible void do_syscall_64(struct pt_regs *regs) { int syscall; @@ -17,6 +45,9 @@ __visible void do_syscall_64(struct pt_regs *regs) syscall, (unsigned long)current, (unsigned long)sys_call_table[syscall]); =20 + /* set fs register to the original host one */ + os_x86_arch_prctl(0, ARCH_SET_FS, (void *)host_fs); + if (likely(syscall < NR_syscalls)) { PT_REGS_SET_SYSCALL_RETURN(regs, EXECUTE_SYSCALL(syscall, regs)); @@ -34,4 +65,10 @@ __visible void do_syscall_64(struct pt_regs *regs) /* force do_signal() --> is_syscall() */ set_thread_flag(TIF_SIGPENDING); interrupt_end(); + + /* restore back fs register to userspace configured one */ + os_x86_arch_prctl(0, ARCH_SET_FS, + (void *)(current->thread.regs.regs.gp[FS_BASE + / sizeof(unsigned long)])); + } diff --git a/arch/x86/um/nommu/syscalls_64.c b/arch/x86/um/nommu/syscalls_6= 4.c index c78c442aed1d..5bb6d55b4bb5 100644 --- a/arch/x86/um/nommu/syscalls_64.c +++ b/arch/x86/um/nommu/syscalls_64.c @@ -13,8 +13,70 @@ #include /* XXX This should get the constants from libc */ #include #include +#include +#include #include "syscalls.h" =20 +/* + * The guest libc can change FS, which confuses the host libc. + * In fact, changing FS directly is not supported (check + * man arch_prctl). So, whenever we make a host syscall, + * we should be changing FS to the original FS (not the + * one set by the guest libc). This original FS is stored + * in host_fs. + */ +long long host_fs =3D -1; + +long arch_prctl(struct task_struct *task, int option, + unsigned long __user *arg2) +{ + long ret =3D -EINVAL; + unsigned long *ptr =3D arg2, tmp; + + switch (option) { + case ARCH_SET_FS: + if (host_fs =3D=3D -1) + os_arch_prctl(0, ARCH_GET_FS, (void *)&host_fs); + ret =3D 0; + break; + case ARCH_SET_GS: + ret =3D 0; + break; + case ARCH_GET_FS: + case ARCH_GET_GS: + ptr =3D &tmp; + break; + } + + ret =3D os_arch_prctl(0, option, ptr); + if (ret) + return ret; + + switch (option) { + case ARCH_SET_FS: + current->thread.regs.regs.gp[FS_BASE / sizeof(unsigned long)] =3D + (unsigned long) arg2; + break; + case ARCH_SET_GS: + current->thread.regs.regs.gp[GS_BASE / sizeof(unsigned long)] =3D + (unsigned long) arg2; + break; + case ARCH_GET_FS: + ret =3D put_user(current->thread.regs.regs.gp[FS_BASE / sizeof(unsigned = long)], arg2); + break; + case ARCH_GET_GS: + ret =3D put_user(current->thread.regs.regs.gp[GS_BASE / sizeof(unsigned = long)], arg2); + break; + } + + return ret; +} + +SYSCALL_DEFINE2(arch_prctl, int, option, unsigned long, arg2) +{ + return arch_prctl(current, option, (unsigned long __user *) arg2); +} + void arch_switch_to(struct task_struct *to) { /* @@ -42,3 +104,12 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned lon= g, len, =20 return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); } + +static int __init um_nommu_setup_hostfs(void) +{ + /* initialize the host_fs value at boottime */ + os_arch_prctl(0, ARCH_GET_FS, (void *)&host_fs); + + return 0; +} +arch_initcall(um_nommu_setup_hostfs); --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FB191FAC34 for ; Thu, 19 Jun 2025 01:04:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295093; cv=none; b=J7/ENP6ax8ERQtnS9dZYjMgg7l4W/W1k9oQFSob5bkUgrIqBRwNFd+FjcA3k20UpBEJ6UqMW1zNgytdBGwrFFlqjnx9C+l+o9UEPh0wv3JLY2j3HycTvxjoegkigMbGqvAFXOym5eJ9/E5yB6mm6ayRctb0q+OG/WWDEgSBDDZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295093; c=relaxed/simple; bh=YUEZeH1TUt8vhd5nOMxaCkzJVaWiSM7ZZlNxkfxZqDc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ms47E0PbdDte5HIJTNhUNFMDoNofjCiQR5+mfoW03+SN+QJOYTzOId5ZInWy4zh+V1RVQDYGciiGtWEfC65ZoTIkVlj0QppM/y/2gTww9PcKyKSlccbX2oLoRDaHgVxX53OKx3wdFH/h02bncwHaGqf5MBap6GWD1/EHwvt6iXw= 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=GWMv+dlb; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GWMv+dlb" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-311d5fdf1f0so153043a91.1 for ; Wed, 18 Jun 2025 18:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295092; x=1750899892; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0G7VVQnGQtrb3sGnx5GNm2Y3zP47y1QHGJfHFp/BsUc=; b=GWMv+dlbqHDc90BMa0qyhxPV1l/V164WnFnh1vB4IQrSyyRC/joyjAdeSktfNd91id rmFXV0gurkO8MjvvkUwsbbHXtW1KVdcJreTQSiZb1DZKUbJMmaTQxFQj8u1XN3qNG+Rd V8ioiWvyu2DQEAaUb5Ene+5hBJ/kaZSKDxJqciPN0wLreH4+Vn+VXAQUxgj7wIIWbkxM 23Il699pFGcri7hTKb1rLv8A0e9EuQuz4s8TrXzqt1m/WXPGGOm/d5UXCjJhi5F8RaQw EcIkkrIxjKXMk9XL7Fs0TBtuVzeR+hQwEvCLogcdUyF9QIIWZglegAob18Lo29y9A8Ij oT3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295092; x=1750899892; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0G7VVQnGQtrb3sGnx5GNm2Y3zP47y1QHGJfHFp/BsUc=; b=NVCInRDIK32zCOFbt1J54EwuJo1KRM0v0qPFhrUQ2G51QWf+var36AMY3wSvGnd3YX vYhdobHOyYDaLjz9/6TnEUmHA5U71T7UuXBZWcllW4N5F6boEFtsqPtXhaHQ++EW77jj CYL5/SgVMLH5OMg+NedS9/oAezTMDA1MOscxkB7270js4T1ev6ZAaBvkqmAkCSgWWSfQ 5/nUIE8vVskJ9U0jeiM5+EwwNDH+4/9f+SiyyQoBLZgIddPMFXiRaFK/gxAc2bmsF3UR nHyYzTF+S7Au/cWOpuQnMNdp7WxvmmJ5g4l7RPpA4lvWgeztbQ2aYAd+ttKRGX1lzM6+ r4cw== X-Forwarded-Encrypted: i=1; AJvYcCWOXPj1hSvm7HzvofLx2j1QVhNeGckkIGWNUnFZaSbyn+wNIZQfiamYB6DE2OlzI0pWgYeK9WqFEobUinc=@vger.kernel.org X-Gm-Message-State: AOJu0YwpAjDLK5rIuuwF/Y4WtUpbLdRVTDdRWa35u/7iboTjRGdj3Ong eSjMkD4nwgw7rnC2pQ60c9xje40IPXPl0qACM334GwCMaLRVKndW/++A X-Gm-Gg: ASbGncvu3GLsDQhyHHFybLkeZVY1AU2J7aaKiKfGEKvjknFRsHsUMJgqBDxoIBYu0rB 3doJA5auJVH1JNRxrc++gf71pxiPDEYRlinyTkuJ56oB73RgRptEHwVXpvPopwUPP8ohua64Ut6 EuKUfQVP3jmh8beyhNYE8N8JIQj5USGkhz+rNgdSga2raRBnl7oFdF5yF7vtyn8nZpcwuUrGpK/ 7z31CaF8WdozothEdPbZGASs96T6rwW4SDlDnzW0syWRrzrbmzf+qDCFLF++pHYmgKu+HhnClWW Prb5wuJdgH939UJ0SDCkz7hsswnJyTXo03j4DhoPioROeT7wWOWX8GGsPe06QbLm02aEXyv+hXX PLAKPN7p3G0eIEP5Zz3xmEZGLLJznPblW X-Google-Smtp-Source: AGHT+IFATU8cH8BDAswTDg8t16Qex6ZAiu2Oi4jWZUV6j/DJuzeYMglD71cpXwlvvkHyyfeb+uGavw== X-Received: by 2002:a17:90b:268a:b0:313:283e:e881 with SMTP id 98e67ed59e1d1-313f1cc5abbmr29510777a91.11.1750295091595; Wed, 18 Jun 2025 18:04:51 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3158a25617asm840600a91.33.2025.06.18.18.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:50 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 26684ED6538; Thu, 19 Jun 2025 10:04:48 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 08/13] x86/um/vdso: nommu: vdso memory update Date: Thu, 19 Jun 2025 10:04:12 +0900 Message-ID: <207204e01eab3318e475f80be9fbaece51dd13cb.1750294482.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On !MMU mode, the address of vdso is accessible from userspace. This commit implements the entry point by pointing a block of page address. This commit also add memory permission configuration of vdso page to be executable. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/x86/um/vdso/vma.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/arch/x86/um/vdso/vma.c b/arch/x86/um/vdso/vma.c index dc8dfb2abd80..1c8c39f87681 100644 --- a/arch/x86/um/vdso/vma.c +++ b/arch/x86/um/vdso/vma.c @@ -9,6 +9,7 @@ #include #include #include +#include =20 static unsigned int __read_mostly vdso_enabled =3D 1; unsigned long um_vdso_addr; @@ -21,14 +22,24 @@ static int __init init_vdso(void) { BUG_ON(vdso_end - vdso_start > PAGE_SIZE); =20 - um_vdso_addr =3D task_size - PAGE_SIZE; - um_vdso =3D alloc_page(GFP_KERNEL); if (!um_vdso) goto oom; =20 copy_page(page_address(um_vdso), vdso_start); =20 +#ifdef CONFIG_MMU + um_vdso_addr =3D task_size - PAGE_SIZE; +#else + /* this is fine with NOMMU as everything is accessible */ + um_vdso_addr =3D (unsigned long)page_address(um_vdso); + os_protect_memory((void *)um_vdso_addr, vdso_end - vdso_start, 1, 0, 1); +#endif + + pr_info("vdso_start=3D%lx um_vdso_addr=3D%lx pg_um_vdso=3D%lx", + (unsigned long)vdso_start, um_vdso_addr, + (unsigned long)page_address(um_vdso)); + return 0; =20 oom: @@ -39,6 +50,7 @@ static int __init init_vdso(void) } subsys_initcall(init_vdso); =20 +#ifdef CONFIG_MMU int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) { struct vm_area_struct *vma; @@ -63,3 +75,4 @@ int arch_setup_additional_pages(struct linux_binprm *bprm= , int uses_interp) =20 return IS_ERR(vma) ? PTR_ERR(vma) : 0; } +#endif --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF496192D68 for ; Thu, 19 Jun 2025 01:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295096; cv=none; b=aihbZ6KeuH15r4xFrpuFYMC+++/NmQr5EOZpre8uuOhUVjNVKOSr0jReuuaLgv5I2loskS8Sjg9HxA+M+VBAzvxP9OWXA16qf3yzBx6MElNTwLCvbCKOvsdCzW9A5r5H+jN6WFs0tP1G0rAU8tHkIB+R1lcCXiMiNSOfWFbhWwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295096; c=relaxed/simple; bh=jvJ95s8H53fOTEgt59zRlibOohi1Di/i1BtsAvEq9bA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lh5W8VjrCC++Nsmo/EJWfR0UIXJC8LVm+PAvfbBniuF6Yz7+lrEZByIabu6RXzfXcrtczKFSquEGkF/pTzIuBWZbWKgUtrLZv8VHmn0AWyi5DRKQ3JvXFijPqW/dlJBPih133g189f2RAKOqlJcetZXJ5gbTAqN9bB5NiOlr3Bk= 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=fYay/N8U; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fYay/N8U" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-23508d30142so4128835ad.0 for ; Wed, 18 Jun 2025 18:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295094; x=1750899894; 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=7p6fRZbGnHz0EayX66AgT73NihJkAiHm12buHgZeNJ4=; b=fYay/N8UCc/a7ft5ctBmUUCvToOKcng3jnZURG1GkXZSqlVRW7uLY2Ofp54hXqqgXo i1tcSKhPSP9qeWhjS5Pku0JKUxEAOMzrDxkKBTzfse2ftPfed6Jd4qDCNwff5+IOg8IH w9EUS518mfRlHzKSOffYEUi9eGmNqseov3vrdgg5oYcd7ob/9jAO6gW2S1hB0td/bYFa bw6bSKZ3jBPrrSK6npt9vAvf0/DuFHtgooc9Bpmn9WzHMqXc9Aa6o1MJS92btAyXdUNM q2p+91fd6TyASIwnrhd04MDJpnv0HHUiuTjTVfAJmPoTFBbh5r1yrSJ1Cp5BQSlPtECY Te2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295094; x=1750899894; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7p6fRZbGnHz0EayX66AgT73NihJkAiHm12buHgZeNJ4=; b=ou0JucbGajnGP8f9xRuWoxD/VOZ77hrEwnWMKdCnURDKmPvOR4OSLiEExPn1QvKwHN 5hPFpSm/eBwOWSQPWKdx2YhnrawxE2A80zUDTRp2qlZydcnqaDXv8p1HOjQNWG2dfU4a izxaE8fX83ljJaOXMobft6AK4QCBljJlISu7N93+EYvH9XWppwePjTF8hpRhD0FeH4mG y/zfS3/elW4t7PGNak1uAxFeaeiXyxWY4lMf8o6MVtMb/Zdy2kBbJt/W88q5/PcksJWl qj1RJuO2OfvI6BvioBl28+1f58ED5UasTH+iVH/so5cB/1OJFInCgEnsJo9frWXNdv/n dkWg== X-Forwarded-Encrypted: i=1; AJvYcCXt6d1EA7Y1/CWrZekeGM7ZnfNGYxfJSsQevm2XOnyDMeOp5NGIswUezEpMgColxhC1HixUsgmqLhRt3bA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz18X8VNHCxhWXOrpea6LKwoxCVZDbpR/ziA1oQdacKFejrxl3N v8HM79bTMcihM7nIAC4spmeFiWWAdwEIdqMytOklZ7bC/jzxTJEgG+Ig X-Gm-Gg: ASbGncuOm2smq6/hpbmljBYKXjjNg41iCTxlUEo5nXFa2CbL2uHOmd3NBDuO54Ye7Un YgGB2J6unBQZbvOX+t2ylrlb7465XtSE61w6zu0NkF3bu04KESgBZhuslo9Y7d+siIPxkKxQtqy sEJo/qsvHPyK8meaJwhaTD7KYl8bPbAzmS0JxlprywRhvWNSQ+tm+8//lM1PG3ZfnMSDIFgom8v 0/MLfkPzTftHGmm1HaHBNIt1xUDzroTngT3/pQacNapusQKMGKw7drrh3hTDp8aOjMrKOLhxvxO bjVy3taWU8owDOK4lptJxv1wsd9C40nrB9mJAeT73lUf3bVh4IZiypI1nhL2SFvHSzf5HWErQ5Z uPPra7diuB7+2EkpUtu6bYFusCRcDk/iF X-Google-Smtp-Source: AGHT+IHJ3RrMAhYNi4is4YvZZSwGpWQ3n0lTvJiFeY8PrqF28ZxH790MacJqy0mlQyulVOLvzjZUHA== X-Received: by 2002:a17:902:ccc2:b0:235:f70:fd39 with SMTP id d9443c01a7336-2366afd37d4mr354926785ad.10.1750295093805; Wed, 18 Jun 2025 18:04:53 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2365de7815esm107997435ad.118.2025.06.18.18.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:53 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 276F5ED653A; Thu, 19 Jun 2025 10:04:50 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 09/13] x86/um: nommu: signal handling Date: Thu, 19 Jun 2025 10:04:13 +0900 Message-ID: <8ae217c1b82a33c0046e0f1ccc668ed50ae28403.1750294482.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 | 13 ++ arch/um/nommu/trap.c | 194 ++++++++++++++++++++++++++ arch/x86/um/nommu/do_syscall_64.c | 6 + arch/x86/um/nommu/os-Linux/mcontext.c | 11 ++ arch/x86/um/shared/sysdep/mcontext.h | 1 + arch/x86/um/shared/sysdep/ptrace.h | 2 +- 8 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 arch/um/nommu/trap.c diff --git a/arch/um/include/shared/kern_util.h b/arch/um/include/shared/ke= rn_util.h index ec8ba1f13c58..f559943b52cb 100644 --- a/arch/um/include/shared/kern_util.h +++ b/arch/um/include/shared/kern_util.h @@ -73,4 +73,8 @@ void um_idle_sleep(void); =20 void kasan_map_memory(void *start, size_t len); =20 +#ifndef CONFIG_MMU +extern void arch_sigsegv_handler(int sig, struct siginfo *si, void *mc); +#endif + #endif diff --git a/arch/um/nommu/Makefile b/arch/um/nommu/Makefile index baab7c2f57c2..096221590cfd 100644 --- a/arch/um/nommu/Makefile +++ b/arch/um/nommu/Makefile @@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 =20 -obj-y :=3D os-Linux/ +obj-y :=3D trap.o os-Linux/ diff --git a/arch/um/nommu/os-Linux/signal.c b/arch/um/nommu/os-Linux/signa= l.c index 19043b9652e2..b2cd0470b67c 100644 --- a/arch/um/nommu/os-Linux/signal.c +++ b/arch/um/nommu/os-Linux/signal.c @@ -5,6 +5,7 @@ #include #include #include +#include =20 void sigsys_handler(int sig, struct siginfo *si, struct uml_pt_regs *regs, void *ptr) @@ -14,3 +15,15 @@ void sigsys_handler(int sig, struct siginfo *si, /* hook syscall via SIGSYS */ set_mc_sigsys_hook(mc); } + +void arch_sigsegv_handler(int sig, struct siginfo *si, void *ptr) +{ + mcontext_t *mc =3D (mcontext_t *) ptr; + + /* !MMU specific part; detection of userspace */ + if (mc->gregs[REG_RIP] > uml_reserved && + mc->gregs[REG_RIP] < high_physmem) { + /* !MMU: force handle signals after rt_sigreturn() */ + set_mc_userspace_relay_signal(mc); + } +} diff --git a/arch/um/nommu/trap.c b/arch/um/nommu/trap.c new file mode 100644 index 000000000000..2053a3b5071b --- /dev/null +++ b/arch/um/nommu/trap.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Note this is constrained to return 0, -EFAULT, -EACCES, -ENOMEM by + * segv(). + */ +int handle_page_fault(unsigned long address, unsigned long ip, + int is_write, int is_user, int *code_out) +{ + /* !MMU has no pagefault */ + return -EFAULT; +} + +static void show_segv_info(struct uml_pt_regs *regs) +{ + struct task_struct *tsk =3D current; + struct faultinfo *fi =3D UPT_FAULTINFO(regs); + + if (!unhandled_signal(tsk, SIGSEGV)) + return; + + pr_warn_ratelimited("%s%s[%d]: segfault at %lx ip %p sp %p error %x", + task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG, + tsk->comm, task_pid_nr(tsk), FAULT_ADDRESS(*fi), + (void *)UPT_IP(regs), (void *)UPT_SP(regs), + fi->error_code); +} + +static void bad_segv(struct faultinfo fi, unsigned long ip) +{ + current->thread.arch.faultinfo =3D fi; + force_sig_fault(SIGSEGV, SEGV_ACCERR, (void __user *) FAULT_ADDRESS(fi)); +} + +void fatal_sigsegv(void) +{ + force_fatal_sig(SIGSEGV); + do_signal(¤t->thread.regs); + /* + * This is to tell gcc that we're not returning - do_signal + * can, in general, return, but in this case, it's not, since + * we just got a fatal SIGSEGV queued. + */ + os_dump_core(); +} + +/** + * segv_handler() - the SIGSEGV handler + * @sig: the signal number + * @unused_si: the signal info struct; unused in this handler + * @regs: the ptrace register information + * + * The handler first extracts the faultinfo from the UML ptrace regs struc= t. + * If the userfault did not happen in an UML userspace process, bad_segv i= s called. + * Otherwise the signal did happen in a cloned userspace process, handle i= t. + */ +void segv_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *= regs, + void *mc) +{ + struct faultinfo *fi =3D UPT_FAULTINFO(regs); + + /* !MMU specific part; detection of userspace */ + /* mark is_user=3D1 when the IP is from userspace code. */ + if (UPT_IP(regs) > uml_reserved && UPT_IP(regs) < high_physmem) + regs->is_user =3D 1; + + if (UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)) { + show_segv_info(regs); + bad_segv(*fi, UPT_IP(regs)); + return; + } + segv(*fi, UPT_IP(regs), UPT_IS_USER(regs), regs, mc); + + /* !MMU specific part; detection of userspace */ + arch_sigsegv_handler(sig, unused_si, mc); +} + +/* + * We give a *copy* of the faultinfo in the regs to segv. + * This must be done, since nesting SEGVs could overwrite + * the info in the regs. A pointer to the info then would + * give us bad data! + */ +unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, + struct uml_pt_regs *regs, void *mc) +{ + int si_code; + int err; + int is_write =3D FAULT_WRITE(fi); + unsigned long address =3D FAULT_ADDRESS(fi); + + if (!is_user && regs) + current->thread.segv_regs =3D container_of(regs, struct pt_regs, regs); + + if (current->mm =3D=3D NULL) { + show_regs(container_of(regs, struct pt_regs, regs)); + panic("Segfault with no mm"); + } else if (!is_user && address > PAGE_SIZE && address < TASK_SIZE) { + show_regs(container_of(regs, struct pt_regs, regs)); + panic("Kernel tried to access user memory at addr 0x%lx, ip 0x%lx", + address, ip); + } + + if (SEGV_IS_FIXABLE(&fi)) + err =3D handle_page_fault(address, ip, is_write, is_user, + &si_code); + else { + err =3D -EFAULT; + /* + * A thread accessed NULL, we get a fault, but CR2 is invalid. + * This code is used in __do_copy_from_user() of TT mode. + * XXX tt mode is gone, so maybe this isn't needed any more + */ + address =3D 0; + } + + if (!err) + goto out; + else if (!is_user && arch_fixup(ip, regs)) + goto out; + + if (!is_user) { + show_regs(container_of(regs, struct pt_regs, regs)); + panic("Kernel mode fault at addr 0x%lx, ip 0x%lx", + address, ip); + } + + show_segv_info(regs); + + if (err =3D=3D -EACCES) { + current->thread.arch.faultinfo =3D fi; + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address); + } else { + WARN_ON_ONCE(err !=3D -EFAULT); + current->thread.arch.faultinfo =3D fi; + force_sig_fault(SIGSEGV, si_code, (void __user *) address); + } + +out: + if (regs) + current->thread.segv_regs =3D NULL; + + return 0; +} + +void relay_signal(int sig, struct siginfo *si, struct uml_pt_regs *regs, + void *mc) +{ + int code, err; + + if (!UPT_IS_USER(regs)) { + if (sig =3D=3D SIGBUS) + pr_err("Bus error - the host /dev/shm or /tmp mount likely just ran out= of space\n"); + panic("Kernel mode signal %d", sig); + } + + arch_examine_signal(sig, regs); + + /* Is the signal layout for the signal known? + * Signal data must be scrubbed to prevent information leaks. + */ + code =3D si->si_code; + err =3D si->si_errno; + if ((err =3D=3D 0) && (siginfo_layout(sig, code) =3D=3D SIL_FAULT)) { + struct faultinfo *fi =3D UPT_FAULTINFO(regs); + + current->thread.arch.faultinfo =3D *fi; + force_sig_fault(sig, code, (void __user *)FAULT_ADDRESS(*fi)); + } else { + pr_err("Attempted to relay unknown signal %d (si_code =3D %d) with errno= %d\n", + sig, code, err); + force_sig(sig); + } +} + +void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs, + void *mc) +{ + do_IRQ(WINCH_IRQ, regs); +} diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_sysca= ll_64.c index 796beb0089fc..48b3d29e2db1 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -48,6 +48,9 @@ __visible void do_syscall_64(struct pt_regs *regs) /* set fs register to the original host one */ os_x86_arch_prctl(0, ARCH_SET_FS, (void *)host_fs); =20 + /* save fp registers */ + asm volatile("fxsaveq %0" : "=3Dm"(*(struct _xstate *)regs->regs.fp)); + if (likely(syscall < NR_syscalls)) { PT_REGS_SET_SYSCALL_RETURN(regs, EXECUTE_SYSCALL(syscall, regs)); @@ -66,6 +69,9 @@ __visible void do_syscall_64(struct pt_regs *regs) set_thread_flag(TIF_SIGPENDING); interrupt_end(); =20 + /* restore fp registers */ + asm volatile("fxrstorq %0" : : "m"((current->thread.regs.regs.fp))); + /* restore back fs register to userspace configured one */ os_x86_arch_prctl(0, ARCH_SET_FS, (void *)(current->thread.regs.regs.gp[FS_BASE diff --git a/arch/x86/um/nommu/os-Linux/mcontext.c b/arch/x86/um/nommu/os-L= inux/mcontext.c index c4ef877d5ea0..955e7d9f4765 100644 --- a/arch/x86/um/nommu/os-Linux/mcontext.c +++ b/arch/x86/um/nommu/os-Linux/mcontext.c @@ -6,6 +6,17 @@ #include #include =20 +static void __userspace_relay_signal(void) +{ + /* XXX: dummy syscall */ + __asm__ volatile("call *%0" : : "r"(__kernel_vsyscall), "a"(39) :); +} + +void set_mc_userspace_relay_signal(mcontext_t *mc) +{ + mc->gregs[REG_RIP] =3D (unsigned long) __userspace_relay_signal; +} + void set_mc_sigsys_hook(mcontext_t *mc) { mc->gregs[REG_RCX] =3D mc->gregs[REG_RIP]; diff --git a/arch/x86/um/shared/sysdep/mcontext.h b/arch/x86/um/shared/sysd= ep/mcontext.h index 9a0d6087f357..479fd923ff1d 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_userspace_relay_signal(mcontext_t *mc); #endif =20 #ifdef __i386__ diff --git a/arch/x86/um/shared/sysdep/ptrace.h b/arch/x86/um/shared/sysdep= /ptrace.h index 8f7476ff6e95..7d553d9f05be 100644 --- a/arch/x86/um/shared/sysdep/ptrace.h +++ b/arch/x86/um/shared/sysdep/ptrace.h @@ -65,7 +65,7 @@ struct uml_pt_regs { int is_user; =20 /* Dynamically sized FP registers (holds an XSTATE) */ - unsigned long fp[]; + unsigned long fp[] __attribute__((aligned(16))); }; =20 #define EMPTY_UML_PT_REGS { } --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 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 1A62221883F for ; Thu, 19 Jun 2025 01:04:55 +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=1750295097; cv=none; b=V2bZ+xTVcLa94rVjvKRwNS8+cEmihSs+7Qwrsy3wGdgQORvONtJx6uGznJy6yonBrnWOYeNjt8mWCbuGOmwMo4sKfzI4fXiXQIgWXezOiJWxgWcS6hYSgjjUdZMMz/U5AqlvuaZeIvQWq/gOJtpU6XBcu6HSQSlCNpupM+C5xp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295097; c=relaxed/simple; bh=A+kgl3pP41bBhorqPw1acgSIN74xjFREHN1mNj1smKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lze/7S17z8j4r0P1GFYNmtChMmHj7IbByRFovJnhmYg+SlW7ZlF5w3lXpD8Xt/Q3Svb+DwZCZ7XvLo05TxkfajDKvIazqqfFcWVfZPOqZmqTZCCS6jEEp3ujLehv89BFoAKfeORy5wkS1UFlkX4f4eBB/SwCkFEQN3yZPliNmZ8= 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=BOqvdyht; 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="BOqvdyht" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2360ff7ac1bso1921235ad.3 for ; Wed, 18 Jun 2025 18:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295095; x=1750899895; 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=sL9evNGVpzgjwGis6FRx6Ny95Jmdu1Zd+5bgNtHIJLs=; b=BOqvdyhtob3BUZvxB9gwEgNIPCT48gWbJoumTErp36Ik9X3VULJROAMw4gBfhxp94c vE/nKR+N7tVTJ+ysc6/Mr3ddGutJLBPqABLulBDp+KzlERZKrdo0Hb/xrVf/JpXUH+HE iQZd7k5ucQuTRbzKQRe2FZT4jy58Itig8723OTIb0paOe1bZ42Vc0MR5Qxv7SE10Yttn lM8ejBQ8mM9gKr98v9zn8jgblKSm48+cyg/ofFzoPepCtmtJbBp2YkV7g9ta/hxroUwr T2KMBF6vVbeQFYdYgSUHYodZq1nbwJYc95AgMz6ssBaoAfTul6QwvTP7ED8w5hryBZST 2UiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295095; x=1750899895; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sL9evNGVpzgjwGis6FRx6Ny95Jmdu1Zd+5bgNtHIJLs=; b=U0gsJvQoghcPQVQ7g3ZjVooC5UVY4/qkrDUsA6pfPcPhlExqqOHacyq2y8N5lZEwJB YoWEr3cO2eS3GS2S5EqjDvfVRR3irh6dGShCtTIj9J0PnUJ7QkaSWkEUzp0foBAgPVtY Ggjh075K8e4m2mLyZGSExuKpbAOpuAed5IhedHSjfZ0aEmWrdHN59YWXzixHIvxaEJsO e6j3b1rImSYXzcTRUDILiQf1EUnu8X4L3omcqgJLncasSt3WkYxPnTFD875Xng96+9g+ 23zWR91eXtz44fhZIk06oQPRDASIX47P4vn/u8EY7L9ViQvXh0VJTrpldJPHOja+vXMD m3LA== X-Forwarded-Encrypted: i=1; AJvYcCVYEfVADC8Xd0jo18fQNK7iYH/Y7S6HyJLyyfjrn/fCCTwMseKFGakA/fsbE5VMbXz6ud4f0MIMonUJxY4=@vger.kernel.org X-Gm-Message-State: AOJu0YxxqgPIkT/v5iRUwOxSMpeUmQLpnNogtZCXp8JH9ogdyaGJwx4z vkGlXOvXJpbQ8e7KTDXSFo3Y4be5PCh3T0XP3D4KS+RGgMjnBXhREd6m X-Gm-Gg: ASbGnct26i6R3Op6g3GWh1abeYOFrJCK6m+vEmslgBlKk33GkLOIAq439SKgE6hC1Tw PdBpCoNIshw2E38VYQDLCbLhEqsOMwF+o53Yjb6u4QnQlG/VxTE1T7j1CW9O5guzptKyOLGkd91 beJECl+md4rr8pgQOlS4GLYmEt1ca56o61srAEhXGysB6NhLv8zqRofa0TXq3sARetJuf3WJcun PeUu8X2O99YVUgSYgD7qoGLmiZ0oloYmeCGGoJJ9EphBjupHHiZIBkBmlzu8D/y6sPktNaV4f5m P8M2Mf/iaD06rAe4wQy+ap8cIrxEPIOlXMfpi7GQBcqu3etoii7Q8qtVH3wUlQ5CQ8cYvLCJTNk 7KalB+32PJRUlZzjhlOldymhYgofr4OkS X-Google-Smtp-Source: AGHT+IFO1wmuMVt89YrBHlfn8kGYjqnEwLyl+KVA4zvbu8jubm0FHxst9cUWZDZj06afHE//hnBCAw== X-Received: by 2002:a17:902:dacf:b0:235:e76c:4353 with SMTP id d9443c01a7336-2366b16e8edmr259851315ad.51.1750295095410; Wed, 18 Jun 2025 18:04:55 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2369843f99dsm36389375ad.185.2025.06.18.18.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:54 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 7F349ED653C; Thu, 19 Jun 2025 10:04:53 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 10/13] um: nommu: a work around for MMU dependency to PCI driver Date: Thu, 19 Jun 2025 10:04:14 +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" The commit 8fe743b5eba0 ("PCI: Add CONFIG_MMU dependency") restricts the PCI base driver to depend on MMU. While nommu UML _can_ implement PCI drivers over PCI devices (e.g., virtio-pci), the current nommu UML doesn't implement it. But without PCI drivers kunit complains as config for kunit (arch_uml.config) defines the dependency to PCI drivers. This commit fixes the issue of this compile failures when building PCI drivers with nommu UML. In particular, the fix is to undefine the constant PCI_IOBASE to be able to bypass pci_unmap_iospace() call. When we will support PCI drivers for nommu UML, we will refactor this code. Signed-off-by: Hajime Tazaki --- arch/um/include/asm/dma.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/um/include/asm/dma.h b/arch/um/include/asm/dma.h index fdc53642c718..643d74555671 100644 --- a/arch/um/include/asm/dma.h +++ b/arch/um/include/asm/dma.h @@ -4,6 +4,19 @@ =20 #include =20 +/** + * now the PCI core driver depends on CONFIG_MMU in linus tree, nommu + * UML cannot build with PCI but without PCI kunit doesn't build due + * to the dependency to the CONFIG_VIRTIO_UML. + * + * This is a workaround to silence build failures on kunit, which is + * valid until nommu UML supports PCI drivers (e.g., virtio-pci) in a + * future. + */ +#ifndef CONFIG_MMU +#undef PCI_IOBASE +#endif + extern unsigned long uml_physmem; =20 #define MAX_DMA_ADDRESS (uml_physmem) --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93B2E21B192 for ; Thu, 19 Jun 2025 01:04:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295100; cv=none; b=f+FXP30inhJDHmAzka/ssY6qZ8+rWoDo9waSpTWShWdQSqMeBbYOZqwBrvlk1VbsOLuP0bdHHw9nozUofh858de6xic5kzoKt+q+cZzRI9JoO7efFOHrvFKe+n9dtxDh3CG9NOqKpe5ZOnWPZvQ48dH4+fpthHqAuZvH1+VBsJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295100; c=relaxed/simple; bh=kvY4llqgRsxBvMcZ/CXo6FHDMPIg9Hmu3RD2Lrj2HZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EhEdYjGd6WK26EIwmvDuet4Z29H+gEufjkIeo4Epysu7PRVidRmwgm6B2jqMeHyr7nt+dYxwPb0ATeu49G+Eucb7VHRP1Jj4DfQKiDrUNe67wE8A6bjJ+9FHT70C5xFkhei575Ikrw5zQ9O/8Avz5vBcrbdsjpHTFn23Mk6awTc= 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=XZ9u20cN; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XZ9u20cN" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-74801bc6dc5so178464b3a.1 for ; Wed, 18 Jun 2025 18:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295098; x=1750899898; 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=SfaLR+xtvYbSj0Yj5pLhRxT8PrYzixVb/sw/K5Eb4uM=; b=XZ9u20cN6A0dv0EM2c/8SK+qXRJENpBDmzfqwutsnFM46RoQ2JLaP/TEOFexAvPJOW fnFR5dBC6CrCKkRRAfEKwSHeqfm66g6/Q1QHkvDSRVLJncUap4XGAhgAh19U2MEqM+Fg vGpFple86xE3GZV33O7TS4crtcFBteJsZSeVIgMYSChnuDRkHMngT33e05PFs+mURobQ DK40WhW488g3WsgEAz+ekhnzwBeLOKNCZo7jgAmsLelTcR/T9e2jQFZvxqzcw1/yzA/A 8dyljQ9zGbqRLYhaWiVwx/aizs1GdwhVNB5W3c/gAaSAVJckrkXus4fkxd3ter8LSxvo N6Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295098; x=1750899898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SfaLR+xtvYbSj0Yj5pLhRxT8PrYzixVb/sw/K5Eb4uM=; b=vJ7iT+AFoM8XGaIVy6prlzZbeubw9jqrWtEcfTX9VPqwxfQxnSLLkDP0Cr6qGBW4M9 bRpJaa9ecCWXNSDLDbNCQSFGei/s/OEV4O192GFC687+9BBcVaEIlwarTGjLl5m2FsVC 43ZNyNxUpBEhQ96CF1XYcQMBes/Lz8CNThSy/ilA3BW8B4dwIw3S5se975dJm8cXGxJY gKw+QIj3xQ4TSlq00v1le6ln8AO12S5XTsC/VN7njZFDxTJBfMPSEKs03h6lGNm94XuT 9A1jOWYD+z8/cX7GvuL207NdcncjirzV8XDNmjOUJcaCmCfl4OPTBFPelcWatAG6Gy2X O1pg== X-Forwarded-Encrypted: i=1; AJvYcCWIzSSI5VXQ7yAUJTjE+3T83O8MRR41xF8fs1hOD/pX7Lbowd3ohi9FYHlYv0ksW/VhK3OPv1Xav/pnZYo=@vger.kernel.org X-Gm-Message-State: AOJu0YzhL4S3xBSQERvk2LtOEPITuOfOGzygnBzk8KL6WsejvpOYa8lM HjrwfQ1ppBMxQyfVRtVJsq+DAgN7ext/gO7gPfjm9wNo9OHBREpuhabd X-Gm-Gg: ASbGnctFCrp2inUgwaKAaA/P6k9WwT7/xNhJEIeTS+hEJ2QPnZ/BuuMA2GPqOt4DI7h nDqlGrZXOb8tv1nyWwMoVAZYPXbo0pMA8l63+9vCBsOGi9WyW870mpXBq+bV3eWn8kcao+TJI5i Aj9H+wZIyGQWYTXGVICPFsEYu9AjFi/DREVhkTUHceuSFTUDO84862qttKQI/8Y12dxsu50OhjF Td5ys2iBv+dq8kVY3fdTKxKW3G5g1eQxPVsibsUSKdOwNkndyVPNJ7YuoWSK0iFbqHCmtS75b4Q /KqSXzBnC6Axuxu1oMxKE0G7oJIITvCkCbKOJ92nJMX+40rSx9Jbk1iyP39+9xMMTIPP8EPDctB gOhbtduoO5wng0+ewCjm52AiM2mG1ClWdj7x+rQU2oV4= X-Google-Smtp-Source: AGHT+IEV6Y3cJLP4JaMcdJhSY/ETlnIE+14RVCjfX1yXRvBEOpmZSlGpLo0DZSp8M2QLOOjfCnAESw== X-Received: by 2002:a05:6a20:72a5:b0:215:d1dd:df4c with SMTP id adf61e73a8af0-220111ad18emr2803824637.6.1750295097772; Wed, 18 Jun 2025 18:04:57 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-748900d233asm11870453b3a.159.2025.06.18.18.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:57 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id D9ED2ED653E; Thu, 19 Jun 2025 10:04:55 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 11/13] um: change machine name for uname output Date: Thu, 19 Jun 2025 10:04:15 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit tries to display MMU/!MMU mode from the output of uname(2) so that users can distinguish which mode of UML is running right now. Signed-off-by: Hajime Tazaki --- arch/um/Makefile | 6 ++++++ arch/um/os-Linux/util.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/um/Makefile b/arch/um/Makefile index 5371c9a1b11e..9bc8fc149514 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -153,6 +153,12 @@ export CFLAGS_vmlinux :=3D $(LINK-y) $(LINK_WRAPS) $(L= D_FLAGS_CMDLINE) $(CC_FLAGS_ CLEAN_FILES +=3D linux x.i gmon.out MRPROPER_FILES +=3D $(HOST_DIR)/include/generated =20 +ifeq ($(CONFIG_MMU),y) +UTS_MACHINE :=3D "um" +else +UTS_MACHINE :=3D "um\(nommu\)" +endif + archclean: @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \ -o -name '*.gcov' \) -type f -print | xargs rm -f diff --git a/arch/um/os-Linux/util.c b/arch/um/os-Linux/util.c index 4193e04d7e4a..20421e9f0f77 100644 --- a/arch/um/os-Linux/util.c +++ b/arch/um/os-Linux/util.c @@ -65,7 +65,8 @@ void setup_machinename(char *machine_out) } # endif #endif - strcpy(machine_out, host.machine); + strcat(machine_out, "/"); + strcat(machine_out, host.machine); } =20 void setup_hostinfo(char *buf, int len) --=20 2.43.0 From nobody Thu Oct 9 08:18:31 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5390821D3F0 for ; Thu, 19 Jun 2025 01:05:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295103; cv=none; b=MLIMfPQbwgzw6cz/ZkoUuZXghWhds18ZeZmHwKeQwdbnZJYbwUFSaKmK2S7gxTTi6uPxJ3lKp4hoKnzb+aOiJ6vpX+7kIKKyHEvgyYM1MoTk4D9iPk9ncNU4o/PWNP/EF433tQbk0wET56QtfUECk/fkUvOc/98VAoc4hPPXvA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295103; c=relaxed/simple; bh=ZCQ+sWv+kQaZZrdKs3rCAYePM6dCyF/eP1qin3deuM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kn3xApLkqJqMgFRXOwr0MR0axi4nvJrjvWcUBdR7oHu23AiwDNmBri4jU4AC+erLqXTVwaxIkhgbxnAniINCRBs4gTLLM1KqO3Ge/NXxLe10ZOpxajMxdTuTE0mqB7+Rz5n4hlTCNvhK3kH7PhvVeLFIZBlZnDJi9ccRw/+4veM= 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=GPEBCXdu; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GPEBCXdu" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-234bfe37cccso4447165ad.0 for ; Wed, 18 Jun 2025 18:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295100; x=1750899900; 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=h4TaMBScWlO5o6sQQ8rBV8o4/7whbCNqAJF2fPQ5Lds=; b=GPEBCXduR7XRIeiZK9/e2v+VPc+cBdTorNqQ2ZRE68PgF2dUrVmCCJajIDDfETIh9Y AL6YzsUiG32TVK5g/WigRHMOmOIvE09HUHxvN/9HC80TQPiQHyfVo+BcgHgY7+FEAtXk uJuknZMMteYCHphbjNeI89V03Z+StM+sHPYKk4SkH98+HrpawLRUAfoXBuQMlx1i7QC6 zahpJRZpRa4C/geKeqQMz1K8qpGeYdapNJrlMS6kTp5ivg7NUVOSE/6bimNshSLi8x5W 660fVjZDhCwJ6NlQfAlul5gLqNQJ16lcEXQVODoSPsJtMljBhxTFR/9DlgOFzD/hAI/d bc8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295100; x=1750899900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h4TaMBScWlO5o6sQQ8rBV8o4/7whbCNqAJF2fPQ5Lds=; b=fBWbg360HUyp0bxpyTB2q4bQgl+aRClQNV5lnmeVxQsiWRPIpEYcN2pBKGKRvLKLQ/ maRCk7/cD6GHd1jlUkqMuLDz0Z+Rsd0VXvbSX8eaKcIaSaLzJ+wXg77XRwiZNKohWZYT xgqx7vDb1E7tUQlj0kbsmXZt+g4vm0xloIjX03pFH+lX0797YRvFjOaFk52xVBXUSsOv G0+MnaVWxuFIadztiDvKeJVVIwLsZSQ5eoPDFI1Yvqrl8laLab9C754rxXFJuTeugAZi pJhboo5OgqcG4seuLtIHFdAziXnchVe0DB0R7nEfrlyXdAWzMP/k46seLZVtUd0CxlXr 9g8Q== X-Forwarded-Encrypted: i=1; AJvYcCXIkw+yXM6gXOreDMmCJXrjmH4U1kUBI5G0vpFAhbCltaRybSjrRQqu97roAKw11EE3aej6otOAjkaISA0=@vger.kernel.org X-Gm-Message-State: AOJu0YwRxtdaGFbXBva7ZrMHapa015r8ycgjxl38GxexoD226YJVSwKy GnLyOQWEUFfjxeBmcNAq3Vr7CPdMBIG7gIKSpdERKVGkFlYTT5AXUnJB48zgUA== X-Gm-Gg: ASbGnctuifMtisChuptgcsJkStA3s6QyHVfW7+sCPfs3zIo0M/+VgzhKA0B/3c4+J7V CaGkfkQEQaLQ0tXKgUrpaSL7mZ3/hvZLZ/wqgdQRGNbAUN7fLTUlRrmm3EEGp5cQCxleY94r0I+ hCef2WKM5ZOTdNr+rMAaIyIIHRF3DlYxl+Oqa4fO08F+EKz2ZQ+OXUpjS++DCgN0CbEjtXKvVKz Po9MhpHCwdwpBJND+LPhB3EhStoTLL6KRfqtSKV72xC97pqQJI6AMsQsUBMQ3RwxhvykyuLOKHU lfWz30AiRRotbKRYek8fNAnRAFT36v9QWC1+uiruyJIm06x261IYG2mwTxIzdjfRi7PuDhI6ubL qr3jM08NJfVe9Wh1j2FtdR3PmIHdsBdN/ X-Google-Smtp-Source: AGHT+IHEfEf0xDbJiz2jaCicc177c2yJr3e0LtxHwGoglzOoG3x2iUoBfgOElxhGTXsOdLYdWMv4lA== X-Received: by 2002:a17:903:2ace:b0:234:9068:ed99 with SMTP id d9443c01a7336-2366b14d37amr314881505ad.24.1750295100386; Wed, 18 Jun 2025 18:05:00 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2365e0cffe6sm107190415ad.245.2025.06.18.18.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:04:59 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 6DB93ED6540; Thu, 19 Jun 2025 10:04:57 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 12/13] um: nommu: add documentation of nommu UML Date: Thu, 19 Jun 2025 10:04:16 +0900 Message-ID: <220f0cc76f3dca8e6958c107e77976f255e096e1.1750294482.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit adds an initial documentation for !MMU mode of UML. Signed-off-by: Hajime Tazaki --- Documentation/virt/uml/nommu-uml.rst | 180 +++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 181 insertions(+) create mode 100644 Documentation/virt/uml/nommu-uml.rst diff --git a/Documentation/virt/uml/nommu-uml.rst b/Documentation/virt/uml/= nommu-uml.rst new file mode 100644 index 000000000000..1a988253bef8 --- /dev/null +++ b/Documentation/virt/uml/nommu-uml.rst @@ -0,0 +1,180 @@ +.. SPDX-License-Identifier: GPL-2.0 + +UML has been built with CONFIG_MMU since day 0. The patchset +introduces the nommu mode on UML in a different angle from what Linux +Kernel Library tried. + +.. contents:: :local: + +What is it for ? +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +- Alleviate syscall hook overhead implemented with ptrace(2) +- To exercises nommu code over UML (and over KUnit) +- Less dependency to host facilities + + +How it works ? +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +To illustrate how this feature works, the below shows how syscalls are +called under nommu/UML environment. + +- boot kernel, install seccomp filter if ``syscall`` instructions are + called from userspace memory based on the address of instruction + pointer +- (userspace starts) +- calls ``vfork``/``execve`` syscalls +- ``SIGSYS`` signal raised, handler calls syscall entry point ``__kernel_v= syscall`` +- call handler function in ``sys_call_table[]`` and follow how UML syscall + works. +- return to userspace + + +What are the differences from MMU-full UML ? +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The current nommu implementation adds 3 different functions which +MMU-full UML doesn't have: + +- kernel address space can directly be accessible from userspace + - so, ``uaccess()`` always returns 1 + - generic implementation of memcpy/strcpy/futex is also used +- alternate syscall entrypoint without ptrace +- alternate syscall hook + - hook syscall by seccomp filter + +With those modifications, it allows us to use unmodified userspace +binaries with nommu UML. + + +History +=3D=3D=3D=3D=3D=3D=3D + +This feature was originally introduced by Ricardo Koller at Open +Source Summit NA 2020, then integrated with the syscall translation +functionality with the clean up to the original code. + +Building and run +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +:: + + make ARCH=3Dum x86_64_nommu_defconfig + make ARCH=3Dum + +will build UML with ``CONFIG_MMU=3Dn`` applied. + +Kunit tests can run with the following command:: + + ./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_MMU=3Dn + +To run a typical Linux distribution, we need nommu-aware userspace. +We can use a stock version of Alpine Linux with nommu-built version of +busybox and musl-libc. + + +Preparing root filesystem +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +nommu UML requires to use a specific standard library which is aware +of nommu kernel. We have tested custom-build musl-libc and busybox, +both of which have built-in support for nommu kernels. + +There are no available Linux distributions for nommu under x86_64 +architecture, so we need to prepare our own image for the root +filesystem. We use Alpine Linux as a base distribution and replace +busybox and musl-libc on top of that. The following are the step to +prepare the filesystem for the quick start:: + + container_id=3D$(docker create ghcr.io/thehajime/alpine:3.20.3-um-nom= mu) + docker start $container_id + docker wait $container_id + docker export $container_id > alpine.tar + docker rm $container_id + + mnt=3D$(mktemp -d) + dd if=3D/dev/zero of=3Dalpine.ext4 bs=3D1 count=3D0 seek=3D1G + sudo chmod og+wr "alpine.ext4" + yes 2>/dev/null | mkfs.ext4 "alpine.ext4" || true + sudo mount "alpine.ext4" $mnt + sudo tar -xf alpine.tar -C $mnt + sudo umount $mnt + +This will create a file image, ``alpine.ext4``, which contains busybox +and musl with nommu build on the Alpine Linux root filesystem. The +file can be specified to the argument ``ubd0=3D`` to the UML command line:: + + ./vmlinux ubd0=3D./alpine.ext4 rw mem=3D1024m loglevel=3D8 init=3D/sbin/= init + +We plan to upstream apk packages for busybox and musl so that we can +follow the proper procedure to set up the root filesystem. + + +Quick start with docker +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +There is a docker image that you can quickly start with a simple step:: + + docker run -it -v /dev/shm:/dev/shm --rm ghcr.io/thehajime/alpine:3.20.3= -um-nommu + +This will launch a UML instance with an pre-configured root filesystem. + +Benchmark +=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The below shows an example of performance measurement conducted with +lmbench and (self-crafted) getpid benchmark (with v6.15-rc0 uml/next +tree). + +.. csv-table:: lmbench (usec) + :header: ,native,um,um-mmu(s),um-nommu(s) + + select-10 ,0.5224,28.3882,27.2839,3.0046 + select-100 ,1.5641,30.3775,28.8091,3.8546 + select-1000 ,11.6922,38.2021,32.5367,12.2568 + syscall ,0.1635,27.8278,24.8049,2.6957 + read ,0.3063,29.0073,23.5953,2.8127 + write ,0.2531,29.6342,26.3339,2.7932 + stat ,1.8827,41.2546,34.6495,3.3199 + open/close ,3.2548,67.5806,62.4781,6.4189 + fork+sh ,1108.8000,5618.0000,3604.6667,456.0476 + fork+execve ,519.1579,2242.8000,1425.7500,138.1316 + +.. csv-table:: do_getpid bench (nsec) + :header: ,native,um,um-mmu(s),um-nommu(s) + + getpid , 162 , 27049 , 24444 , 2696 + +(um-nommu(s) is with seccomp syscall hook, um-mmu(s) is SECCOMP mode, +respectively) + +Limitations +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +generic nommu limitations +------------------------- +Since this port is a kernel of nommu architecture so, the +implementation inherits the characteristics of other nommu kernels +(riscv, arm, etc), described below. + +- vfork(2) should be used instead of fork(2) +- ELF loader only loads PIE (position independent executable) binaries +- processes share the address space among others +- mmap(2) offers a subset of functionalities (e.g., unsupported + MMAP_FIXED) + +Thus, we have limited options to userspace programs. We have tested +Alpine Linux with musl-libc, which has a support nommu kernel. + +supported architecture +---------------------- +The current implementation of nommu UML only works on x86_64 SUBARCH. +We have not tested with 32-bit environment. + + +Further readings about NOMMU UML +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D + +- NOMMU UML (original code by Ricardo Koller) + - https://static.sched.com/hosted_files/ossna2020/ec/kollerr_linux_um_nom= mu.pdf diff --git a/MAINTAINERS b/MAINTAINERS index ac8ccc837bab..822efc04bbe1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25753,6 +25753,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 Thu Oct 9 08:18:31 2025 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0383619D897 for ; Thu, 19 Jun 2025 01:05:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295105; cv=none; b=QtdukSqzJti+l1JGTUtlj6bogq/TROfmYppNqbrIAvx0UQZ43jZSW6ut4NjnbJg6w0ZInCwpaVhREVEVbRH014qUTfVCWJYaZJa2jA7uDjnTzYFVyr7x8raTp3UT5sjDM+x5IruduThSegoU9m92Ua8y2H6vHfhqw8jd+QtmdSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750295105; c=relaxed/simple; bh=MryEApqacNPUDPx//9kRjyNmysSr/3bbD7GV9l6RwME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VNpkwua28tW/TrV0PNF7w7AgcXa1J3tMjx5KZUKaqSlPAp8pNzB3ITk/TwRqxgnLylAWbMjdK2DsaH56MZwXR9ymDAYbP39oyqdDlax2fL4YNy0U8PSi6A+IcF/ldaMolAsoMZtD+pVyGKGkzDYgXViFHKysJiuCq/k4Xi18pok= 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=CjQ6kb80; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CjQ6kb80" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-235ea292956so3218965ad.1 for ; Wed, 18 Jun 2025 18:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750295103; x=1750899903; 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=4CZO2OAKV3OtJLgmf9ZQYFE78DDsp7kzC/L9szpctPA=; b=CjQ6kb80iTqsB1WNU5cewjJSMRx6sOTDmNAbpi4lTKfdw3KJvMlSHyVli4GA0c2o1k ed79ENia1roeJ6HsT3u84ipEhLAqNcDTJMW+yGGR0G1u/VIzgpp9vMbhi+H5J58tCIHC 2PloX15H39c7FFvCEPgk2OFXQOtUh4c04x43RA1ooffYbU9DCpCjshZqN49jAY/dsbP/ 11qgUixlePsEGHi2TbSlabsMWOIpBUgLgbXLeXJpbHN7MaJTp72JODmL1kj+oy9qzgPN ZMdqICdfC3MekaC/fnBoWrEdAMl4/04pLUyeioYYHyprg6mWY5xhqURRto6S2qYRMLMV AmeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750295103; x=1750899903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4CZO2OAKV3OtJLgmf9ZQYFE78DDsp7kzC/L9szpctPA=; b=E3jTuS7x6PrnHOsppwgFs8U3hoEY5cvmIT/UMdPK3SrSaB4E9+dj39xlkCGlkYWZZ1 uLa9/Z+jv+2j1hEy6lydyYHmSz3qz6WXWCKkJuozfgzLwPhJhSt2rf71tCYe6pilq5pA rtEfMzGWV46cp6ZFSYh2hZjGAFhFpXDrxa2zzl7RfXKECmx9x8mgRXt+xGe2kLX+hVFN 4hJiNrGdUr+FkUppTs7/iDpS5AvJ56j1RaPIlr/HnpimLJAUMq+suj+jA47ZNUw5TlGI ePOgKQPMyqCjBASA5CaugeQMqtkIVE0cL6WdyRud+QxSRHwp1r3gRDo76UELp6KxtmIe 8DSQ== X-Forwarded-Encrypted: i=1; AJvYcCV68ZFDkjfuBR4a239kj9juyRXshHsV+7rIXg0QZQCXBBcxMVWKCzKEP3MX2JFwagyXm+3w1OnoMRzyRmQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwCvWrt4Aj6lzdhlmsmxtaUKKCmLCuvR6RBukH8rpr83jlyoSMj 5sXXYkYsa6Sxgy9K7//fU8ybNnTEFaz/7LcGtJ4aN0CnLeP3JQD2B/773Ej3ag== X-Gm-Gg: ASbGncubP9G57cHZ4uF7h2cSWQCkx0EFhrUUdhUlWir63d8h9iO2LFt8Na/BA9+F/H2 30QKSXej8pGBKS8NBX7iXfF3U5H+7TpGZmbJb9xpKVZ1qE6S8Cs6jYBUxFyJhLU/H6LcfcbQw5M LK1VZcxhsfTMLLXG5PEo72DHNuCZFvIWV0wkZ/yEAUYl+1cDpyvST7EXRrewrVfWZO5vGflC1bV 44GAqsmniy65HORcsTLhT72UvglzHGinXXNT50nxXIRaigyvfBxNWfuA5Y1MX86pMmkYpooLuCx 6znri4ywvjPSlhzFP5k8tZDmifBvFU3Jm4oG/wgw8ktaS/gdid+AltOkVG0PId2Wwzyq8/F4Jji GcnZBjVoKbe2/SGFGvPmvG4Oef8SKg683 X-Google-Smtp-Source: AGHT+IF/lWU7GJLzDXdk1F2IZNf7VWmrNUNbM5q/vElUar5FDwrpd2kD0dJvfnbrgPtrERVIQruzoA== X-Received: by 2002:a17:903:94d:b0:234:909b:3dba with SMTP id d9443c01a7336-2366b005fb0mr274698465ad.20.1750295103301; Wed, 18 Jun 2025 18:05:03 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2365dea905fsm108088795ad.166.2025.06.18.18.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 18:05:02 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id CEC31ED6543; Thu, 19 Jun 2025 10:05:00 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 13/13] um: nommu: plug nommu code into build system Date: Thu, 19 Jun 2025 10:04:17 +0900 Message-ID: <03d0cd2581d0e143a5644df5d42fc00a550fc72a.1750294482.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add nommu kernel for um build. defconfig is also provided. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/Kconfig | 14 ++++++- arch/um/configs/x86_64_nommu_defconfig | 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 f08e8a7fac93..81a79c7a5a6f 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -31,14 +31,17 @@ config UML select ARCH_SUPPORTS_LTO_CLANG_THIN select TRACE_IRQFLAGS_SUPPORT select TTY # Needed for line.c - select HAVE_ARCH_VMAP_STACK + select HAVE_ARCH_VMAP_STACK if MMU select HAVE_RUST select ARCH_HAS_UBSAN select HAVE_ARCH_TRACEHOOK select THREAD_INFO_IN_TASK + select UACCESS_MEMCPY if !MMU + select GENERIC_STRNLEN_USER if !MMU + select GENERIC_STRNCPY_FROM_USER if !MMU =20 config MMU - bool + bool "MMU-based Paged Memory Management Support" if 64BIT default y =20 config UML_DMA_EMULATION @@ -185,8 +188,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