From nobody Thu Oct 9 00:37:51 2025 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73FDB218596; Sun, 22 Jun 2025 21:33:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628007; cv=none; b=ZYrn9A4uYVIfd/v8qgCtt8Eo7pw7KctFj7GQlJN6jLdiVrP0EcnEYA1YcbVrH3IJfA0bJMsBYh4c01ghhI8WKPOKHh8nCVsWgt4EfftTrSpBxHS/Kno0w0odbVxAdqvAoJwrL0aEYf1Ls7QhM/epNQdY4Ji/71By5xROgodevk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628007; c=relaxed/simple; bh=fm+AK3tlrTe+gYqKBawZVsKJTfAyjuWAJWdKg3VZFJc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sxAYmvHdRSq76jTUxngVTZmKrihy5+XlVSD9qYEaMYInvz1JRlO/5zUkWQSWIEt1W1G5336SvSH7Z4ls80qV8BRXYAgUQBYmHLmXsKNSdW2IuMbx+wu6ydQn99XDko3y1C1wGMU6/1h1EZgBoGnQ85p2+nBd0HUJaA2J7XqDEgg= 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=jisSHjhP; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jisSHjhP" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-23602481460so30259185ad.0; Sun, 22 Jun 2025 14:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628006; x=1751232806; 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=jisSHjhPBZKH94qCgVft8NrvEpm9pRsHMmHaIxYqwCpzbFvwQbESV5vdCqSK52PX2o DEjuiWcAzwbpLdcmENsG8E2y952IAcPzOA3TckS0m7Gi/C0JoRQxipHC5JieThYVjSSs nrMDGyLMGgdd2qm4zZSm7VfVUS+xEWP3cGIR20lkSnGp2MFc0gEOi0QzTEMTm8Y9wnwx zqnluQSTXJIjuEvXEDcIuy75z48MXZhusk+lfGNbmlvfzfDNzM0XNO+rN1aadGTWowYO 4rp1/+2qCXf/DIrOdbxeGb7vS16HMYu3fXO2Dhm15chsj1m05h5w5+P4MA4fMuvLK4cx hhng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628006; x=1751232806; 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=Y74bElSnY7p/emPE4MHn2rk9/AAxycrQ/46jBMzQZDo76b6+f72lHq48c1PMmC0EY7 p1/f2GDgLPAImtI1ZGqFwQPfk3s+bsHUgTHbNqzQhsI2j6aqhkTEgY2gCqGdywPjmOwr 7v/TAGDWGCcvP4ULD38FyVC5KBDIZmP3uddv8TjzfaAGWdDEQOEp0eN5ajhM/GJcat7i IjnpsBUJqarMUyWpg0+Zo7buJfysgp2r0gHvS/2FHCgKg9kdpOTdinTa2y/gQQFhxMXg NVphJq6YBxJvmZG0V9FmK6DLTWUt49KOb7JBK9XLOqWK+OyWjKsjaln/jSlByObImmKt 4TuQ== X-Forwarded-Encrypted: i=1; AJvYcCXfvMvNQEwwrTAW/wsWkaSjGxI+i5dAehS8UPvvzhZxLl8g6u8PZsEyRUrj1coTLhifKgg1A36jRxzlQUkL@vger.kernel.org, AJvYcCXmfrYIWi526Bnvy6ec9ltB6TuilxhlId6G8ft88/6LLLraE0aWrZ0ay3f3dKywlTrmy3QB1o7/1sPzk+aX@vger.kernel.org X-Gm-Message-State: AOJu0Yx/xc6EJxXAhs0u68wl0+4EcSDbm30wkrqtNQIUxk87jaZdivGU eXwIb7D0jbztWgC2KCp+xn3x+bWSaKD+HGxedfVmNMiUY6dhE/WYo91X X-Gm-Gg: ASbGnctNtjMg/h95Oq+jX7o+CYQ2zVC/Pq/6qSpd2SjKZAF5G79qUiUNR1eDYQ9fynv yyApDjisfa5YQBVE4JL0bHPEWvqkXyRKMuu9SrNDpELFdk7ATrHSpuUm/kbm/qlWDFTjLgV4h2e qeYsa4N/t330JmTunOLYxClZfsXYz4+GG9liA8SRh9aDzNApiD/7vz78Feb4m9S1gO09u58D8Ud NDmbIxSwuTNztsXwoyXsVFYZIsHkSCpx3YBw+4k7vjD7LY3oXNa9GxDquHtk+vaMFuW8Z4W2tjI VpdTb3R6ttL1ihwQKDYMizUoNyfTX0nRS+Ny4nwnmBWOXXUhdfRQXQ0AIoY+Qc0LUj6d4GWbZRS vuqn8v14WdQ2RVQ9mQ+T/CWZorWeChtYZ X-Google-Smtp-Source: AGHT+IE/OyFdRvoMZNChjYSNeiwAt0sGgB2Kp3DYDGisjy/68Lf7lJEd62sOTC8wwxO80U6hLupeeg== X-Received: by 2002:a17:902:ec85:b0:234:f825:b2c3 with SMTP id d9443c01a7336-237d983d1e7mr177001775ad.17.1750628005666; Sun, 22 Jun 2025 14:33:25 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d83d5c97sm67821005ad.70.2025.06.22.14.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:24 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 2359AEF1EA6; Mon, 23 Jun 2025 06:33:16 +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 v10 01/13] x86/um: nommu: elf loader for fdpic Date: Mon, 23 Jun 2025 06:32:59 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As UML supports CONFIG_MMU=3Dn case, it has to use an alternate ELF loader, FDPIC ELF loader. In this commit, we added necessary definitions in the arch, as UML has not been used so far. It also updates Kconfig file to use BINFMT_ELF_FDPIC under !MMU environment. Cc: Eric Biederman Cc: Kees Cook Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: linux-mm@kvack.org Cc: linux-fsdevel@vger.kernel.org Acked-by: Kees Cook Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/asm/mmu.h | 5 +++++ arch/um/include/asm/ptrace-generic.h | 6 ++++++ arch/x86/um/asm/elf.h | 8 ++++++-- fs/Kconfig.binfmt | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h index 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 00:37:51 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1749219E8C for ; Sun, 22 Jun 2025 21:33:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628009; cv=none; b=rl3LyVvmRdT6PhPMQiCsnD11RKggbPpS0j0Xua41meF08kx24u+TMlA1VIYHgO4Dnz9lL+Co3xC8I/mixbDnswA61SNZ/x+SxKr6hFDMOXrGM8o/vSQQleJJfqsi2MpuEtlY3vEISNkjJ7vD9poSrvvgEb+nG/+kWXYEvazzRe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628009; c=relaxed/simple; bh=dfL0DB/1tST3mKTIw/ve96YMtsSJZhvdkubiQPYfGI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qvJdfyJiM97TRFf/HWLe6HjbMnRkperlQa/FZiLSOwxmTbUK2w50xhHC8XbQmNx1L30HO/YUCCsrs19aK//AL9SrSbKtDAiBkQOsM8xovxx4pFCS49vagHUyr0XrxGs4WRmIm1ZTxSeY1IHFeDEfLUzgkPClS3TVPDEGO56cwYw= 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=VGwRG/DZ; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VGwRG/DZ" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-311e2cc157bso2696482a91.2 for ; Sun, 22 Jun 2025 14:33:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628007; x=1751232807; 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=VGwRG/DZZ+OHbmKr8Uh/ZydTgVhvubK92i9iPBzDnG73FYwmSgWkp1bTg7zoLfPB9v TqfPuo3obwXRXMLcdK+COEtiocAa8xBULY62gAqcwVAWblsuP7H40nVoMvFoLdGYlHWH cKIQirF3silaEDe8LjPtQ4MmCnvCuWP2sG2kTUcVv075nUSg+QRygfz6Qq9DZbCsF5y0 IVrvQwqWO+TEz/JRxcVqHEg+nA+NC0U21+lOIKfwDR9sXSVcwLGOP99CFsnvV3foEw21 RlBCMXxtM7+7tS2Ew7EOuSEwMolwgPSL5Ez5h8a0g1rWrs3gTt63F4Yp2gKg/YgA5uOo b3nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628007; x=1751232807; 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=OsJb1a7WysBwD5hs5kpkDdQkhKa4igC3doIqZd61y2sRylNAVoyaZk81raPsHiIOBx YbEMYJ2+fP3bmQbS3FNNfqa5n2lcxHx7ZN1zSgJNswAO0FLQ3/geLINYRj9aIxUtbBDt p5utON1Zj2g/j1QvdHjRUEpi+MoQCTcT2tnWodUrnqF9bCwktDCN99+F6f3K4j7Ddw9Y FtYcjxy6aT8wp8rpcgqlfoaqLx5ARcqzv9xCIT5Ur1pN/ZcdkyIXKLmOFjAh4BKptjdV TC6Jh0YdPc08w/ckClUhuV6CvdIBBdUWSOJ7Z/lkfVJdDhMW8JQhElc5ITMZb32U7Evl MidA== X-Forwarded-Encrypted: i=1; AJvYcCWib8y37Jvf6xo4b6pCCR6iAqeeLvKSXNEPsDvpptOne7rPzVbZHFxdKZ/M8EWZpMo0BsRWvRH8X3TeCOc=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9HgtFcI283oQaoUvWL4apBzCQaPM9rPTavVWCdIHoDNToURYO Tj+Vsu0I4bMKB9R/2Y31kh7yxFblPkXQAOQOzMg2mj09+RygEE8ncPWs X-Gm-Gg: ASbGncsZqy1qHgtXHqZ0aRQY0s9JA77Usd1STgUF72KkM8TvPqXOsiWVVeE3NQ/2+TA SKwbQAP68tc1MxvlrfU5dcct/OhG6Y5AySmlIx5uk+71W2QeJAkv5DaMUHE/Vrem8UTcDUVmGW2 vDRRG6uP8r1DVHgRw5fC8dUkVYdO2iA+DH3KmO2yZstIxMrvYJrQWLiITMWtzlP0ipfLr6PRagr UBe+UPPPBZ67RcsS6pRMXOnAoEpUSlCaZA/FACZwvfqatOWcN9pG0+Hbc0N4hibdS6hkcB11ubE owouKVHiGS8xUhglg0Vrw60MQcZp/laErhQQFnItq361ubdGBRpSn+NzZxsE1OV49gqNca4m20M VueakgovEhcJPYwGMJCcITy8/9X3MF3em7Usn5sI5evY= X-Google-Smtp-Source: AGHT+IEfcaO7nL1r0VRRYA5nD7uwrl/g9hgdqGLugVfFAlzFAOu6uJN+cwNKGC609OdzFHp9MVQ6dA== X-Received: by 2002:a17:90b:3908:b0:311:f99e:7f4e with SMTP id 98e67ed59e1d1-3159d8c5ef7mr15865845a91.16.1750628006954; Sun, 22 Jun 2025 14:33:26 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3158a318733sm8909505a91.38.2025.06.22.14.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:24 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 51E20EF1EA8; Mon, 23 Jun 2025 06:33:18 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v10 02/13] um: decouple MMU specific code from the common part Date: Mon, 23 Jun 2025 06:33:00 +0900 Message-ID: <8f04c03682594850e0f2f5bcff98d298c318d006.1750594487.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 00:37:51 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 DD27D21FF58 for ; Sun, 22 Jun 2025 21:33:29 +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=1750628011; cv=none; b=HoG/GoD/g2b3dveGDfchupjWCa0lmo84N8h8FLsAMm06RHgFOVVqM7PWRI9U2Zt90bggOhqLShzoc25pzBUUC1ucvM2RUFa2ZhTqTg/kiz92cKKek7i1E0pXAiWlYYn8G0jx9JBGVgBgo0cZ8TSfwb2aplsgvElEKOFM/DaLj34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628011; c=relaxed/simple; bh=PrnDkOztux8Lftfz3cRwSL8F1uSiVMGY60W6duSht4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bwsd+sMP3Bj6MDVQXWpIOeldSmSMPzPGM94XzNDCTN/3ckAjksed3V8qC/jMzxQpJKAk1SihAo1lJnVEQe6XeNSZ0wQBJl2UwWC0n0y7ZyOWicsNd56u0OP9PAh18Vj3FauDysYooqMnBWBzEr1rPcBo4sAvtcrnUZTIiYqhHQ8= 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=gDTdasgd; 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="gDTdasgd" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2363616a1a6so26989705ad.3 for ; Sun, 22 Jun 2025 14:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628009; x=1751232809; 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=gDTdasgdSjU2QFfORV6yg/WXwbdXv4+6oSR5QwMcNBfE4HQUV1zrKrL7PX0dUWjcQm OpcfO0seZ3FjdGBX8okXnglhK1NO9kEkKoii6gawcPCfnqFK6noqW2u+kNwKHRBmMYsW rwxARiaIF6exnx0+6JcoyVDiQX269wUdrtqVj94BCdzhh7cvXdIh6W8A4rGe6/HxJIw7 pmg8t6uHD395CIvJ6qp2GS36qoJezscl76V/48kg+ja6h5w+8qXBAKHkHQvio0TcPVQc l3bnu0Vvq1n5iUb+V9SFGo/QWH6m9g/OGk0x6Hdf5S8X7Rj01fwZ9c+uihzdO8F0mL4J udLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628009; x=1751232809; 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=bScMaU9MK2zBt95nMJ3KXcaNw7At7rjhhsc85RX60HFyDNx7TLTzfG4JwZahIcY8AL KfTdr6RBEZmD/fjaGoQ/7k/TpKGsJRSvVCnehQxHAK6Wx2YLKpQ4kyzHyKPgBG6hX/Zh WNfLFjEN32uIIQ4sfV/jWHBXldf5GyJeT2z9kmZXaK1Fg9tJnHNBU7tJYrXafFhVIgDh 1BUSbULNslybqY2c5xmLwKwe4rVyt/UEioHAVCteBDq+tiQDgR9CRfT0a1KyT7955dDj c4Z8EG+zwEeZq08JttjwQctjrPdMtpgbXHs3Gwki2C7Z1up1gobhiAcWExmqh2IpHyuW gU4g== X-Forwarded-Encrypted: i=1; AJvYcCX+pZYXbDcWaQGiyuQ9Yo71JfuF7ni9e6QWUEgGmk23A4jxo0BH+c69ICH+DBE020+olUZC/ddSWr4En7g=@vger.kernel.org X-Gm-Message-State: AOJu0YwwOOzF3I+qIIajFYoca67uGlZtvaceqNWVVnaG1310osvgDUXo lilXr5pN0U5bBLj4BcucIFHcih7L7rQeMAHSaF9z7yWvLrfcy0SuVO1O X-Gm-Gg: ASbGncu66qD4860zTUgpnSQJXhD15spMq9F3P2ENQ6lkCHGyowPcDxqp4fbWHxSl0+t MNzwRzQ7DNdUGzcEKwhxE+VzJeJgx7DtbqQ0jq/vCjjd2qx9wAHlftCMyYJXq30OohQuLvmVy66 FT1VYDVj3SJ7hKPcqZKVVANWwoKhz+ApKCh+G1QyJHbH9nws1qCU21Xi7D5KhrSV7nD9DaznGxk 3lUhjLwDDT2QJeVOVSLgmdBaFijzs9hL0FAijBkYbEgV54aRB/c6MbtBExtIy4+ZvrvAwpRT1N3 u83gqOfbcBubxbPsHiD522lBWh95SQaS0UW034YjCeWuGXe9B0ExhKty2YB1P9ok0SGjQn4L/ZX tHOkDr+XAmNmXngLGdziEUupwZ+AdmGBx X-Google-Smtp-Source: AGHT+IE+C6TqiI6itKxfIEkY9onlcQ1YuOUVxXsgpsSghi9Pc7uabtrgYH9aXbzxZQRAffufgmsfkQ== X-Received: by 2002:a17:902:ce8c:b0:235:880:cf8a with SMTP id d9443c01a7336-237d97fbc21mr155530705ad.15.1750628009187; Sun, 22 Jun 2025 14:33:29 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d8393227sm67844035ad.24.2025.06.22.14.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:27 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id D0078EF1EAA; Mon, 23 Jun 2025 06:33:21 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v10 03/13] um: nommu: memory handling Date: Mon, 23 Jun 2025 06:33:01 +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 00:37:51 2025 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DDE81EF38E for ; Sun, 22 Jun 2025 21:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628013; cv=none; b=B6xVYg+iNap4u6UIWMKE99yahjJFCRTtmKsCraQCduXXVJIjWGR4Jvxiimra2OLwHvjIug0KVFQqHJS8sbqPp8+Q5F+H1TqWBE4eA/Gyxt83T6b53Y8kzFLypEnFRzE+6fs53pd+Zl4KTZRxmhehFin1majAIkZUn17odG4FHxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628013; c=relaxed/simple; bh=NtZJ+r2oFr+SH7wwZMO5qJK4wxp6UgcrPaIyCGQHA7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mnsb2aK3Pz/8+5koy/uQ6t0nDD28NdxjfV/G5QkVmXI8SIQ/IUvPuC/MzDA4OVb2BVfDqWUlg3CDaak8yD2znD5sKU3zytC2fNgSIg73pna0z+wAUxDcb7fFfLgEJXSKYBCfhb8JEuxXHkjG2ov4iBVmu9k8wiZqEQUyqpiAe/k= 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=YjSeh21o; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YjSeh21o" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-74801bc6dc5so2693912b3a.1 for ; Sun, 22 Jun 2025 14:33:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628011; x=1751232811; 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=5RAxhnmhedCbVcYMwch2f12BZ7LCLjFr4NInIHPP8YI=; b=YjSeh21ofc+wqPz4/DaycKfzULK/BxCLFK/J3Mgjn392cgJL3W9CWETDXgnjPQfh9t 0ustbxE0nuLFp3lbsujDLg+7vwQ+OYd5n1AInQ+7oAB8QyuUs3Fmp/y1qK0zYj0fkl7K 5BsTWlkPlB/sGa4LpjOFMNjsBXLBiRITveF/5+/F3TiEdZn8lqip0V4bg8+u7xl86yKv +vndvh7EnqeYtvr0wpZQ+Y18lwKUyuh4iVtkwmN1t/PtyXOgejW4xK8wp+3qAsjLNNEH m6Z13OJlFtRUsswZyA1zVdrb3RiWb+PqSJRzTbHKo/wAQ6Q9SinJh1NKc79ph7OR0H34 CHew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628011; x=1751232811; 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=5RAxhnmhedCbVcYMwch2f12BZ7LCLjFr4NInIHPP8YI=; b=aLWjbHTSi2HSRBbIPod+wqK+p1nMaoRhUWQEUxP429YxtRQiGQZVMjbLksuqkriHlM O0buvxJO735ln2iffWx2fw8xzvXNBtyPKtgNGEYTF7VxRr1o6by9cgl+PhsnbLhVfdeD TyrtGkQ5EAY7a0Qq1T08Ear8lv5EwcR1wmzB/mcKowd7Muv4pGEy3B7Jvj6mNSdOINYz 7rVKkdLnyLBo6JG7OizndnLBgGraWvfEq5PpnhQPJlb/o/bhF7UU6ew6Xmh7m/f0yfMf ys1Vrqpz7GhdxNbEMo1uXftY6VPnUbv7u2/Fr4eVxp5BfSDlaKsQTOkcjcykcz4CtT8Z Z40Q== X-Forwarded-Encrypted: i=1; AJvYcCWnpEfprfquZE50Eb5yRXTIHkurTL+gkxeuq/1YSZb2APowQ+or1JOvlacKRP3VwWYT3bkl29PGmPk5F40=@vger.kernel.org X-Gm-Message-State: AOJu0Yy34ZwCcg5/B1gWrhJJOUY90XzLRBvGPKo/38kTKlMDO9LqVLvW O/ApuLyoduz3ZYJpZMevbwfI06C/Waz3CPpCdZsAuNCfcH+lMzIDSlfh X-Gm-Gg: ASbGncu+zfUNviG2PYwkYd/u4XRTw+IDoB+wuWW9PgKh8HXvEQ8b6NRVfoinWFU+99e 3v6b2oFXt89ZmTVKOw1KK6rKyVNSK1keuQZopfIGWqfJ0TjfJxn/xaVn45pyPSrpq5nhqwG9/zM /1aPLtsK3eS412p93nE2qPWpdnAnSaoreZU+QAvIdfjMKNocd3lCi6/ArQd+vqBf8/5WfRmY9Mj IJOY3/5geEBFPtc2Cqz9Tk0s7jCHh52Ak0SvfPT2IbKO9JMM/hAJ74ZZWmFbt3R1P7z16+ERKGL MUUK7HldAE8013avtCS+Sm7Ggzi68j9dJvkplwG6SPnixbdVQ5IwRZPdrvAM1gK/l4ktgwlX5o7 EhmVeE+oItpkPOQH2CF2Ao54WDrLvxIhL X-Google-Smtp-Source: AGHT+IFUHlTqUevwTXQzSa064MISHkFpoSR4ppWu4XfsTFKtBWOzpZZHg8+BGawYS5MSiaj7gUKlUA== X-Received: by 2002:a05:6a00:2e03:b0:748:a0b9:f873 with SMTP id d2e1a72fcca58-7490f548544mr13040845b3a.9.1750628011304; Sun, 22 Jun 2025 14:33:31 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7490a621cd4sm6859224b3a.105.2025.06.22.14.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:29 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id A38BEEF1EAC; Mon, 23 Jun 2025 06:33:23 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v10 04/13] x86/um: nommu: syscall handling Date: Mon, 23 Jun 2025 06:33:02 +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 | 25 +++++++ 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, 150 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..6b08daab6afe --- /dev/null +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +__visible void do_syscall_64(struct pt_regs *regs) +{ + int syscall; + + syscall =3D PT_SYSCALL_NR(regs->regs.gp); + UPT_SYSCALL_NR(®s->regs) =3D syscall; + + if (likely(syscall < NR_syscalls)) { + PT_REGS_SET_SYSCALL_RETURN(regs, + EXECUTE_SYSCALL(syscall, regs)); + } + + PT_REGS_SYSCALL_RET(regs) =3D regs->regs.gp[HOST_AX]; + + /* handle tasks and signals at the end */ + interrupt_end(); +} diff --git a/arch/x86/um/nommu/entry_64.S b/arch/x86/um/nommu/entry_64.S new file mode 100644 index 000000000000..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 00:37:51 2025 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E637A22173D for ; Sun, 22 Jun 2025 21:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628015; cv=none; b=gw9wFru7JXjDpIle86Drmo8eweVsOh/5SGUuBMCfSHuyqlQUKdRgRdqXrcKG97JweT9RYH3RE7mlcQJ9jqQ4EgBa6WD1lQuNZBSGVdfuAWdN5pPRYVhC90ni0ipravwvTyZdVD5ASuIIatBu0F4duLu/F/VDivMO1hDhpgByLLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628015; c=relaxed/simple; bh=aI/a1cXGXvx7I7cf7SF1XPZkt49h25YOh7Q+a504gb0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uo8YdlGjMpcKtQhvDiqpMGMo80XBJ4i9DLRrIgwF25Fgo4hWVz9JNB8mE/vdTlR7jtN391IN8m7XtGNZpYmOA6klwOXHfkMwYSIzUWKHbYXlGT7F3p8JfklP7kfs5m5LU0Vh6sFrVyP7tTtt57smrKXw8kjaP5pPv5Q1XgqRwmA= 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=S63V2Xaq; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S63V2Xaq" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-b26f7d2c1f1so3770108a12.0 for ; Sun, 22 Jun 2025 14:33:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628013; x=1751232813; 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=S63V2XaqyFDSFAMPPpnypIqflxCdU9p6bnnuA6CRN8HDRDBdnFYveNcTucwz1hFfy/ xMgfYOHpAvCWmCPPbOU7VF5gowGwkF3vUvRxZmd4Bwhz8uT7tcyn6t5N5QkZdVsBRCg3 ySsN66eEOyUnQcWf1sgoI12PUDw23b1zYRITd2YP7LpW/KiDmKFXJ4Uc2uo19b1z8SET 6eXj/OX+uKVc2qYK+e6oMwH7V97cjMoIqPfJHIBpwjJOqweW3XI+FKtiKXlpkKhK1v0A MOdcpJtRgb564tj65e4yvmRg0jbARmK+fRf+qxYbo38kjW7Ia5FKyXiH+7b80Vnxa56z WPVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628013; x=1751232813; 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=TihaewXc1LIuctw5pfza34yjmLd+kxSia9M2B6yaFOQ96B4yab3c9LHycvNQZKcBqu h6eMQZrehlldjQJ/iOCEWz0OzaptudFhfjXbBv+c+dUKfo+VqP1W++HID65rQdixAlEI FgcXXAJUMytbdvhWE3pugbaZ2G24gPqMIBp5ttAT7amKgEfoDhz99MRmecO/tE0enGLw eUqgLKjy6Oi1DVlVG04ayIPcvNrGG7oLotN/WiAkJr5Y8UreziCk+pgnuqpGBaDbSDGp R33W11ZrBKMqD8wFilRjYS5A/V+XOxLpFAYf1L1MxlnB6F3Aph2VFarYDvgWzweWp4Fo Ub7g== X-Forwarded-Encrypted: i=1; AJvYcCW/crvWKy+iX9lzuT+koKzItyfOv3Kljp1sAEVJ2nYemQqeJMX/h6p8bQVn4tLXhx/hl32M/CdyKzf4pfQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxJtEfAUMyuGCHwMc6E17mrI30absQfANAmUN8Ss8iJqYqIJnDG raqdGjK27w3TKjREwn1xOj46U7AdmFFYMRcPxboSeZeaY758FGxsgjWi8Qp3VyPR X-Gm-Gg: ASbGncseYB6itAqwE7kHEIKFJlA64CNOHvnfmeIgx21KiRKtXw2plP5aHrnyORfr0ut KjsduJDRRahk0tvDsqKIa7J5E2VuVx2Gxs8MMvKFBguHSqXl/usr57DLSr/AOhjmDODB3F/w965 kgfT85TjDivIdkuKrK6UriWg9C27Uurd3xzP1xhMSIyRbtpOr/R9QPais+DWbt+wt6fkg9ilvOb 0iVbROzRrfVBirpj9rlddnGiwKKR8yIGDe8R836WYTkrf/4j0i0B1Yg9z0rqJbEBURXvensi6Tm dtH8PH2m086jts1OZxWP5W+unFbCglBa/OU1H0J25hGnsXlB2gTyxmUEWxE3szQIK+8sxTmw1vg 4m9aD9BAkCv2X0UiORaAm2BPIe9uyXw7d46k58+4BFBE= X-Google-Smtp-Source: AGHT+IFbEBE8CMyqNQgxh9RS5r85e6jK5u/i2lRl89cnRuxl2sdCixMZiDZ7sQv5QTe6fqbBixPh7Q== X-Received: by 2002:a17:902:d50e:b0:235:27b6:a891 with SMTP id d9443c01a7336-237d9a74664mr159618605ad.28.1750628013005; Sun, 22 Jun 2025 14:33:33 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d873b5b2sm66979335ad.245.2025.06.22.14.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:29 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 147DEEF1EAE; Mon, 23 Jun 2025 06:33:25 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org, Kenichi Yasukata Subject: [PATCH v10 05/13] um: nommu: seccomp syscalls hook Date: Mon, 23 Jun 2025 06:33:03 +0900 Message-ID: <558fd49fe5272087f766e632cd5d3bd1ec3a2b9a.1750594487.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 00:37:51 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 90E45221DB9 for ; Sun, 22 Jun 2025 21:33:34 +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=1750628016; cv=none; b=sBna7cNlhNH2vO0z02JSbWebaHJxHQ/9FI9RkxGNmVZdT9//aNsiCU/nfWeNfs4Wjl/HkZgiFfkya94ku+1OI7qbg6WOdnq4KoZ6Dk6++8ijyHiJ9wwe40szKqm1BhVi3GxA9uzyeKPrhTuKcsOGtZ/eY4B7jRfDkunQr11WR0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628016; c=relaxed/simple; bh=yMx3RnJmWQF39D3YDn4nS0qlnS46T4/ZbrLmkWs9msA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GiOADQ6vsZq4F+5ea4ZeSi1m/AEByxpUXGsas2M+4Kcq1NI1ebkcdetRsuc8rNpZw6Tf3GffQMKJ7d54OOLOoQa/LMcjE4rjYmM4FlvxLqdD+UzIHQ/Pm8vXRAXhoa/QqLZUCgePahAh6cv57jM8/mnoscqXTYP8l5osllOij7Q= 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=EW7td+an; 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="EW7td+an" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-234bfe37cccso45271745ad.0 for ; Sun, 22 Jun 2025 14:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628014; x=1751232814; 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=MWmA09AalrKCKqNdOimE9etFAWoYaJVH+yPCouYXbe4=; b=EW7td+anAoFktFdhJGPriv9B6dB4f4U5ERGE4xy+YZWTsHmUv483vAugT1oRjNnGfj ktoImR2iGgsKfG0Bbe5uvlO305UTHEhRQn6f6shJ+HUEMupzh7A5p9oRyGE/30j1rtdK Y3glXJKainGvakPjk0aHMHkmQzJu8TwuFDZWlx7TyZJ2kBcZeucn/Wb3Lwnlz1Sxle3Q adox0/lMEIrbfGBT9rAhIUx9/bQCYJH0uZihUW6dDee3iEdAA0Q8oOH5xmBPsu4NgoyI aaKyG9u1b/AV6pz90kKe7Hv/L01mLbK2buVqzGihkMdMGkpdLEfiZPD1+uv+fQ97oqni s+gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628014; x=1751232814; 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=MWmA09AalrKCKqNdOimE9etFAWoYaJVH+yPCouYXbe4=; b=uyxZRrFMOvg63RFGgglBvcOb8H2lSZPcDSUDnyU7waCXnRCbnymldj8XfPMt5nHBfi Qcs74LsahZCEPK+gGM2SpUYTfqsNY54cgb+bZvc0f309vB0P/5NRD4i8JFMDBiWE/Y/k cM0qoOeYTu0ePx0uQscbJKCexjJ2VgWvRX0lrpe/XeiZEDU5j0hL+RutPKG2+fzsKbPD VQgjxfo+qrQ7l6a40NGrSZaABDG+v9H9G+L+8TpaffzXfhia5fN/pLGm2NR4tRoaOYmG EYcwNBygb/n4qwupLnBl3dGz4OyA2KT0u+DAXn7WbWQunH5cPN+1gk5yzgy+yzf/p3/r 8MMg== X-Forwarded-Encrypted: i=1; AJvYcCWbQzs0navIBikJ0aJ3qVEjVZUvMWAvdanUIqcdNAYojsvH534Yp6jdsHAD/C6dPwxJ05TDV0YUo0OxUNc=@vger.kernel.org X-Gm-Message-State: AOJu0YwQqpfC102hX12bWLMZcCHxzVclti1wRxsF5RnFjg8nzXm2zPH7 GWieb5OFRQpWU27T8QytM1RsJzowLLVq4zpK9S6l1Dx3Ybr0DZX6vRlK X-Gm-Gg: ASbGncuAy88yLN5kCwFk9PGxbeJsN+JdDDSRSbxNmpv3GBRGade+ms5hMETE0Q0o2fj UPpnVDvHs8SmHkvgpbuGCEOjiIJrLWQN2uya6H8AAfwXDkOMAr8fL5wYgg0dmHhWz6xipgOiw8+ xLy1oSQ7aaWBwmIOl+aFt48VfODvvpIiR84dlgRTEXd2qxj/o6TB04T5k2xokMQ3hZ6ySp7+3OA KH8Ka0ix5ijty84vHRxzN8ShqIVfBktgtPG5vkFrb4+FGQoPeF6PnNQzVyP4zoYjF/roCo0qbKx yB9ouLwhg8YA+M7UMu/pd+x08D5SGHj4FC14QYV8ZTgc0jHW00lcM4Sl1CNWYdahG0Yl8GmGMcA Cakwznc0mu/cC4XF0kgz1OgDRgJFSXcYO77aPL8iz1M0= X-Google-Smtp-Source: AGHT+IFahGSpnoHBpn2Cds8cB3SpBCFDv0BojRPvfSRb4pA+F4Lk4gBS9gdDKoH1fQRiUwr1fYoqQg== X-Received: by 2002:a17:903:1aa7:b0:234:8a4a:adad with SMTP id d9443c01a7336-237d98f9968mr163441015ad.26.1750628013744; Sun, 22 Jun 2025 14:33:33 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d83936e1sm67971125ad.5.2025.06.22.14.33.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:29 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 5F881EF1EB0; Mon, 23 Jun 2025 06:33:27 +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 v10 06/13] x86/um: nommu: process/thread handling Date: Mon, 23 Jun 2025 06:33:04 +0900 Message-ID: <92ad19005df45ac15452be94c9cb522c87c8ee1c.1750594487.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..e88e93e9d80a --- /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 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 00:37:51 2025 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.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 0008B221FBF for ; Sun, 22 Jun 2025 21:33:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628017; cv=none; b=fdih8qKyYwjZh98xJHyw5LrCwhLhCHqKP7i+SpJ83Pc2pyLarPKcuWdOa68S1VYZPtU/Z2QqXuFDOfjF8ep5V+ZgmYFyKpT5njrCJBcttLOB/F9HXfU/gNBYLJPHdnOYzHUgkCW3df8oNCkAFdIci4BzR+tai7ShQtCyXXf1vl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628017; c=relaxed/simple; bh=9K2NpIEVnoAe2alCNOBN1YxBV6/oELFvayApQuoodpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P5dXcrOBNANsHHsfxgTHNlKQPYSwX6o43dtvW4WfZVMaM9rXScvu9T/iDBn0z6BXZDsGK4aamk+iKlduipN9MqE0D8xbDxSNsdx1UiYjhi/bUAytJIt78TRmm7ANFObpvytHm4HA+fRz8ar772PwL2vkN9RRGHHUsHOwDWFtOs0= 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=H1Lbw/Lj; arc=none smtp.client-ip=209.85.214.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="H1Lbw/Lj" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-23508d30142so48292085ad.0 for ; Sun, 22 Jun 2025 14:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628015; x=1751232815; 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=imZ2VRtA0KRhDqFvVOmvCgQSiKBob6JpuoHz1j3Ovlw=; b=H1Lbw/LjKpNKvj6OMkBjam83hpR8W3IRRL92EImHzgqt7Q5NKYAR9my3IaeKwiwS8+ xTNNeu+7cTKhCEkk7MkEk7dXpGlmJO6cSWz5sDWlDcfKdgVBdbvcMeeWCdzStNT1nEb2 OwnoSVcXJmYs5Qb9+fBxNHvKkTyESBeIlm89Kid8B1smHlCFI+iFoj2fJFMDXb1H1BKE ldaEc+blZdnst2KkzVGfcrORmRE8Qwr4dY4GOYhNxQQHNsgnBnxEauo9sSBLVJ8rXfSf VxR2zrLoDvTkomURA0a5eIc99EHYra7kAEmkFpHNAkstV/fNcH20+/qX/x2tfemJYD98 Cf7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628015; x=1751232815; 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=imZ2VRtA0KRhDqFvVOmvCgQSiKBob6JpuoHz1j3Ovlw=; b=dZ3pzEHZrz32RYGgcO0qf7SckaonyQZXLHG1OTUOg1DjgF28TfcM8vfS53KZJDlX3Z MYYO2yJRpWEssFXU6XIZ8vOy1/TfDYQIBaVy/RzjKTngu/Gx7D9HvCpwzwy80YqPha3S f7dhnZsUk4foSdbquMolq66PSWIruHWNr8lc7vVcKY9fqvAz5p6q8JCcSfweMX5LLu23 s2Ja3o2UdRIvrPMMSY6vqQIcSHRMpx4rHq6DmawTtvjdYLmkt0Gd3eQa3p0P28Zko5eG sbFM9bVjvyTVfkz4+dq7FKzJh3J5OO46bSJqH/QaSDaifrpFhQ5m8mH7Axx9945+BNe2 j5xg== X-Forwarded-Encrypted: i=1; AJvYcCUAzsdpbn8zn7fxCuwL/h2KfhOC4B7pueVKrusyna/hj+PW2EMcG1JCRYrUntPXLqRlwIJ141IdD+5WLv0=@vger.kernel.org X-Gm-Message-State: AOJu0YzR03q5odnuK3nGQ3X1Tqt/ebntJyfU0Dz9akYlFf5/nvxXgiBq PXfdMJXcm7K1k6lEsvc0O9SbwlloaWwo8f5wgJckIw/p6rCqfXrPUgSy X-Gm-Gg: ASbGnctgDKX8xbdU2UCEa1hALqHonNn+5+PmJ1H9Wh7ikTNrMQaWzhRCfSQNf2vbyNT OwjmiML75KXHNXyhMMv/L2Yrn0jZ96GqTpY1D46CpFvmoQarOSWwe/7m1nx8Gh0FKYX9549C7Jo ryB10Qq+QhXzMzgRbVUhNz6TtAiBUn/5UQ7HfKS5NaNNO/tNdWoCA1x7pGcHrYew3z6baqn9kij qvGxCOMAdldJCLJ7suXA7o4wLOxF+5rjTdpXaCFzMqRG319n6EcpfxZSzkPnFKCitQNypu06WHr jYE7dRZmCHqN0+/VO+04KrDQCsvByujN98WNId2dHd/T6Sn7IKlTgXJ+yIQvUhuAqAzy1JgqRuH 5tdWKtR9VFJFYyxvZrwq1WDKMEVZbrGKk X-Google-Smtp-Source: AGHT+IHUJSJk6kFL23Nwi5JQiUdKibcLCw4cz/mxoOvNKkEO/EWyf7iBCMF7YwsmUB2xpRLlmwLjtA== X-Received: by 2002:a17:903:4b2b:b0:234:a139:11f0 with SMTP id d9443c01a7336-237d980d949mr156889965ad.7.1750628015092; Sun, 22 Jun 2025 14:33:35 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d8673d1asm67144255ad.172.2025.06.22.14.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:33 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 92951EF1EB2; Mon, 23 Jun 2025 06:33:30 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v10 07/13] um: nommu: configure fs register on host syscall invocation Date: Mon, 23 Jun 2025 06:33:05 +0900 Message-ID: <30ea8e4c251b15349f370302b98ceb70f4572180.1750594487.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 6b08daab6afe..74d5bcc4508d 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -2,10 +2,38 @@ =20 #include #include +#include +#include #include #include #include =20 +static int os_x86_arch_prctl(int pid, int option, unsigned long *arg2) +{ + if (!host_has_fsgsbase) + return os_arch_prctl(pid, option, arg2); + + switch (option) { + case ARCH_SET_FS: + wrfsbase(*arg2); + break; + case ARCH_SET_GS: + wrgsbase(*arg2); + break; + case ARCH_GET_FS: + *arg2 =3D rdfsbase(); + break; + case ARCH_GET_GS: + *arg2 =3D rdgsbase(); + break; + default: + pr_warn("%s: unsupported option: 0x%x", __func__, option); + break; + } + + return 0; +} + __visible void do_syscall_64(struct pt_regs *regs) { int syscall; @@ -13,6 +41,9 @@ __visible void do_syscall_64(struct pt_regs *regs) syscall =3D PT_SYSCALL_NR(regs->regs.gp); UPT_SYSCALL_NR(®s->regs) =3D syscall; =20 + /* set fs register to the original host one */ + os_x86_arch_prctl(0, ARCH_SET_FS, (void *)host_fs); + if (likely(syscall < NR_syscalls)) { PT_REGS_SET_SYSCALL_RETURN(regs, EXECUTE_SYSCALL(syscall, regs)); @@ -22,4 +53,10 @@ __visible void do_syscall_64(struct pt_regs *regs) =20 /* handle tasks and signals at the end */ interrupt_end(); + + /* restore back fs register to userspace configured one */ + os_x86_arch_prctl(0, ARCH_SET_FS, + (void *)(current->thread.regs.regs.gp[FS_BASE + / sizeof(unsigned long)])); + } diff --git a/arch/x86/um/nommu/syscalls_64.c b/arch/x86/um/nommu/syscalls_6= 4.c index e88e93e9d80a..f213251c5e35 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 00:37:51 2025 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07E602222CA for ; Sun, 22 Jun 2025 21:33:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628018; cv=none; b=CPk7BCF+LTVpveCbayWhwvQ5OOELdlFlVZx9WTdZUDrWhOxW7BZr/e74uCL8j/GclOS43XZeToam1dfLrzyKYd+kSK7Q+5lYULTGuqNfIz7qF1fhHlG7CN91mLVaeDQ7DlTftPKu4fwV5dR5Tobeh+NQHb/xLXxlrWKLZB38/IU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628018; c=relaxed/simple; bh=YUEZeH1TUt8vhd5nOMxaCkzJVaWiSM7ZZlNxkfxZqDc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hq4hJh6YBfpSYSUAW/Q7MB92UFmX/oFGFljoiKtFk++S8vNtNhUdPYnla1/0AhACu0iapXUkjlf8v4KZI28mYa9qlX58dKjgGATgYbqUN1FmX/E+CaobFT5aLFzuOs2wiiIg9V9yewqk4xDmuJYf1P1GQngJFxHwOwFBxBKZ4Mk= 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=hSiNF3p2; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hSiNF3p2" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-748feca4a61so1820805b3a.3 for ; Sun, 22 Jun 2025 14:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628016; x=1751232816; 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=hSiNF3p2fzghwqtCVgMG98e69P2gbeBJCsWESQhtkXNm21ewsb5ty1UTw6Q7/80xbg n+KLV3VFqeWEgj/6Raef72bKmO4tfBWGy7XCLFxXU2rB6UWMxKyVneXi9grk9udPTPx0 hZYL/p7+hc3RuXy5HkBMDEwddSlvYD2wG4oO1mi+7MIP9TaoYMiV0STfDYUhGclHnXQr EoeIZ5urg99SyM+zCQb4hXulOnDMZDq8NLFUXS8v33zozlkDiwCMcwyuX2O0Qe/Uesrb WieQWPIBwTA+pNW6GDocsqB5hkj4allGuEVGGvGbRvOZBbu4HSJwW9Q7FvnVRQAzwx5c lCnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628016; x=1751232816; 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=U8RrFpMbNMAxzvAWJeJUzLStIu4s7GwL8swITFzp6HB90evCW9eUmxtjGt9Rc71cxe H/EdllLpGJnstQGNEWQCmvkZBflv4LxBP1xoL1xiou3fCI+PUClLswO84pwv4/SuTGXz y58n0pbuVMJRjCBpLxekDJ1SyARY/QcO1FGP1GaCWq09t7F8LY6ZwU4peJWf1TzsRbiQ T2gSqlr/MM8UiMBMVcNcYnbZfda1cqm0q7UGjCNc4uncs1ohVST8k8QG9h5EYxQRvixv 66930Qtx+gnfQaVr8nDwBctd1xLh3Jtnp0NMB9m4mvf6LIkFx+RJ4H5M4vMuq1U35qUM 1cyA== X-Forwarded-Encrypted: i=1; AJvYcCVGjmMe3157xE3VqQFbKNvfGxA9Q4M4U0wiRFpa+a4c3RFiBg2y55M++CNkoF/KE7aliCUKutKZJfRqurQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0DyyyGaEHlQNDyXjJ+1FGxlDQkOKSGzROwnCtHoxDLw2mshUo psdpmP+1V7911YGThxIXyyvt4A6CHJlBzxL+KSupHEUi0SOV4RshS7HQOcg2BA== X-Gm-Gg: ASbGnctRV5tQW5xM4b/3epTPTEor3samling/XnJNmM83KPNOISCNotJnLYAKw3kzdb 98ExfbKRRfgDYCF7K8+YeTMpYiLYcTtV44+yQ/IdO8MyCpdwsOwVBmjVfMJzO5HWfrwWtlOm+Se L1dLMwrN+4uwRKdSD4uTOF71KzrCSWW7tXQrL3jynCeUHngCEThZkLiP/IKya684DdAJBjO2h2j ju0JrFRUuq0TL8018VSUqvHsWcZjzk5GV6EspL5HKKideRZ7R1sytZzb5wmHO4qj7NSyGzoY4hK qAUkj45cMSz718qYMoukeYCQNTp6+njSkHekhGRMPXylOAym0Bm7SRpN3WorwBEBULXsC7hVBiS tKtp8tKrooos5gkUec37OWR0aKnmpAZpn X-Google-Smtp-Source: AGHT+IHrrJwTveE1DrjrmwA8iNFWeSED2zb/Yvu8dxfkj2CbC/FxRJjNGr3E1Hy0RND7HchK71ZUmA== X-Received: by 2002:a05:6a20:431d:b0:215:e818:9fe3 with SMTP id adf61e73a8af0-22026eb0730mr15937527637.27.1750628016251; Sun, 22 Jun 2025 14:33:36 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f1241f20sm6274763a12.45.2025.06.22.14.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:35 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id DEBEDEF1EB4; Mon, 23 Jun 2025 06:33:32 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v10 08/13] x86/um/vdso: nommu: vdso memory update Date: Mon, 23 Jun 2025 06:33:06 +0900 Message-ID: <0b7d3061a6053731b9499d6a1e373314ef9f12d0.1750594487.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 00:37:51 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 666B322257B for ; Sun, 22 Jun 2025 21:33:38 +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=1750628020; cv=none; b=ASOo9FDGTh4BOlAKC2gfI6c7O+9q+lrPAE6My5gZUU3jbTj3YQLAFJMPJ++dhlB2IdDmDC2hP8L6iFIYYIag2dVPb8AzIwiKqjqJ3Cl936M/3J6bwsBwOsQ/+tTKDaPuzZ3WABpWo8E3x+S+S/LI2bwOsSFVWrA8pL//ektrmXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628020; c=relaxed/simple; bh=TrKy+gOi1lzDFf8Ad5jdyEt9NWNAoFFccmw+VIWUBUg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e7XkHwzkdIjN4aSbo6PX5tWQXjoIPo+0KTtZ8dIHmgJHNu+t9m7XFLOWxRkoUaolGtIaONX/5Q/u9YJj8G6RuLXujXMEECCKtD4T2bsgZGaTsH240YxtdX3Bhj14ACB0KJ1uM30RDhZ4S8+nVQhioL/P/m59XO3xIF6eIuWwZkc= 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=gf29CMvh; 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="gf29CMvh" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-742c3d06de3so4130472b3a.0 for ; Sun, 22 Jun 2025 14:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628017; x=1751232817; 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=HWYis9XY/qzyLWLxXYbKTNJnR2A9tZ/PpUFIrifE6jQ=; b=gf29CMvhQ3DHp2kJZRrP9jmnqdt754ERs+gcqwIoNFi1FkDCr9ZK42aHXU9gY4111Q 8Z1hQ4tI+3DH2sakkGtHHwA8DzryNLVcWoN2iSx5wHqDWKEL0XTQL05rz7jwLoujGvaK ggVgTxv12ER61W8UndBp9GNDe/MrdOlwHVSKFVZ9Hfp4wtfTLyyLcagbqllRiisZIuH+ V60KwWPo0jnrOrQMLQI2jn8YktB9+7EmMyH/QrbuEXPxLkm41zc6rpwmOb0aG6NsMnks AOFQNAP7vkabj7tjd/R0vodcQlzav5vDJA+k669oig9qm0Y1Q5UL0b5qellp88xRHqaK lUHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628017; x=1751232817; 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=HWYis9XY/qzyLWLxXYbKTNJnR2A9tZ/PpUFIrifE6jQ=; b=w2ARgzbYYScq1ZX8IJHb80BZes/AWSaAj7/9Q+H218jO2koZtjOfnVziAIlZ109PlU ZUUU80XAdRNrUzTiqZE0nKu9cbpru0OTvhujb8jsKc4IXZpvxk1YcGYNtBoZIlQJBUNL UW0D6Bmmwaq22J40V8rbH0dQWdw5Aaaw7r7JmQ2DhO3svVSKcKBSyVaO6+ZdD/6sfWGs esAUmpERNvld1SnqXh5gSHEYnHwMjXNeRCph8oPde7Y6uyBwxdlvOQeCssVYPq1IONqb Xl2PPu3BLZ5aAA/T/Dp0gI+RbWvCxtRWrvD0eHvOyyqOeT6E//J7wfBODFdSvinL+qMx qY2Q== X-Forwarded-Encrypted: i=1; AJvYcCWnFUR9SdMDF2vWvTEdISLTvhXZce5P0wMIu5ceiFeUlK2IMEyIwJOA2T6dPbcn9bKYq9tGeauB1DNAa5U=@vger.kernel.org X-Gm-Message-State: AOJu0YwZbyEFKDHvFzhb7iHhQeAkwBsm/wmnngQWe0uI33eXdRae4ZFc gMvdG2Sj9st9IfsBPaCFKFYpfxKDr4Z2bCeOd7AVJkMQhK8frJYXvOB8 X-Gm-Gg: ASbGncvbE2ebZVUSNZWXc517XmRBk68acY3OdGNYpCEANoMGUSZ6Rz9P/PA0UPpey6J DJVwAqNc9dd+0CMITVuBpRYT/wgbCjzGFCPRGepR4A4kXC1Bbzfgt/oF8JRiX/dT5/CyxQh9LA2 tjRPyj3JGvQN4Qlx7TQ+Xz0CAND2QZ3aBnTWzNN9dcFbpGaAUOaep8/DENITHxxtcVYMaF8id92 8u9oGZmEmCuBGRGXLC+OekdBF9AM1RbUYMqwi1dS6kaBg1bv64/pVSqQ6wdjQ6B/ZDr8RuUSosv /idmzGSzdc5WYyd9SJkhJz5TfkivKIfdkMw3IGeDhWTRMLmrpdlVwljfj2KeZxGTi3QbQXTB5cy kiMOX43Q3uCPWyNS6q9e/PUxM5GwV1v90 X-Google-Smtp-Source: AGHT+IGq0uPvfQN/by2MTlJphZLjSS2FAmQmME8fkve20GVLlwC4kH6GbiBFeD62y0KfiugCRlcrhw== X-Received: by 2002:a05:6a20:918b:b0:1f5:9330:29fe with SMTP id adf61e73a8af0-22026e6ddb2mr15546602637.17.1750628017530; Sun, 22 Jun 2025 14:33:37 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7490a6891a4sm6764586b3a.147.2025.06.22.14.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:36 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id BB6B1EF1EB6; Mon, 23 Jun 2025 06:33:34 +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 v10 09/13] x86/um: nommu: signal handling Date: Mon, 23 Jun 2025 06:33:07 +0900 Message-ID: <548dcef198b79a4f8eb166481e39abe6e13ed2e3.1750594487.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 74d5bcc4508d..d77e69e097c1 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -44,6 +44,9 @@ __visible void do_syscall_64(struct pt_regs *regs) /* set fs register to the original host one */ os_x86_arch_prctl(0, ARCH_SET_FS, (void *)host_fs); =20 + /* save fp registers */ + asm volatile("fxsaveq %0" : "=3Dm"(*(struct _xstate *)regs->regs.fp)); + if (likely(syscall < NR_syscalls)) { PT_REGS_SET_SYSCALL_RETURN(regs, EXECUTE_SYSCALL(syscall, regs)); @@ -54,6 +57,9 @@ __visible void do_syscall_64(struct pt_regs *regs) /* handle tasks and signals at the end */ interrupt_end(); =20 + /* restore fp registers */ + asm volatile("fxrstorq %0" : : "m"((current->thread.regs.regs.fp))); + /* restore back fs register to userspace configured one */ os_x86_arch_prctl(0, ARCH_SET_FS, (void *)(current->thread.regs.regs.gp[FS_BASE diff --git a/arch/x86/um/nommu/os-Linux/mcontext.c b/arch/x86/um/nommu/os-L= inux/mcontext.c index 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 00:37:51 2025 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F41CD223714 for ; Sun, 22 Jun 2025 21:33:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628021; cv=none; b=IWRpI014SOFMZ2cbBmhkRNmJADjZ13/HOIGkvjynOv14DA5ovK6z8HUKFmHgFMzHOKnp9gpiRJDDsDuc14zDuX4J24da9MxM0gUmdHOFNEVjfyAfvQwo7VxF5qvuQa7+iChKvijZqcX8GlR2stLNSIB6Njgj9jZH/JGuErKHbE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628021; c=relaxed/simple; bh=A+kgl3pP41bBhorqPw1acgSIN74xjFREHN1mNj1smKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GHACaWq2qwOaDzCVaGN9U1b54mParFAemihsXQhI/Xuaw8qEKbaAknvekSl/+qyWzi5lBZT5GAnqHRpfdJpgt0oUresrQ1NpCBNUvva8avk7oFcX9pf28+x+ckZy6QTKcsRyBp28+/JVmX0qVpV/7Ysf9+6KtPTvAPr55GNPfj8= 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=JilzLc1W; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JilzLc1W" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-73972a54919so2704332b3a.3 for ; Sun, 22 Jun 2025 14:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628019; x=1751232819; 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=JilzLc1WGX7ntYoHlbH3LVerlsvB564y5ADXapLhkLwjhyYb6WMQtb+VsODGc9enwm HZyEeunRgdRQafjPJ1pdjGEbFe8xZGht6XHbg8odAFLdl5Ttbu/GXg7MNKC7hZHad98g cTDkBu9uceGMED9yqZrZXqKEvirssjYjQg9nPDhq49/20Qwdnngi72S0bw2VOwSq6Obh Y6LYOwsEbWuTU2FTpzQR1pRKuzheLfQA0DmYuj6V0ikuMXgdcsFeJfuTrkQ3U01gmHGS a7hMhdlVa1pOY4nO1G7kfxqLyweECFoSrVdhal6Cm5Fo+IZsEj01dbD+8uVyUYHhj1La 8rYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628019; x=1751232819; 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=p6azmWEhlSKI7r8r6Q/j9BOFDaPsQc9IIvBQeNZWQj+5LMZQqx6T8p24w2T3bx761m JokroOoGxKiq8R1TcvSCrImg2oUkRz8A6/rOHGtT+kS76tWD4ez+otGI68ch/UaROszp EDQnd2ecpEtjivSfg5ONZyA/WGenKTEGmk3eMlL3kILocRWEumcUBBvJqywdjCqcZbse LBDkEGfvUiM5JEsFKeI+dm8NHqbXrOY/iZSX1K+iBbiSYrFxlwUr3XJ+Wp/O8U4obXQC LXaeBZaPyRRCtiSUH59DYv+aFiSkSSRMRCPCnGA2PKT4LM73zk2yxIpNFpRr6su5vqwd AAKw== X-Forwarded-Encrypted: i=1; AJvYcCWqfZyL3tIS+4CAXuqBBUxbFswWVQUVj6dSciVClur7FNkfkh7PMyLe4d1cdjoaQUld3d9S1cAkn4OcuXw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywv1jF7wzjKRi+n/rFGIt43H241jrnOu1gk6DMn5e7M4cMBVgEe wIFN8afOi+xbkSXH7gZUZ+HgwGmP9hJ62iQy+1jdWjpEYYFNbcja9pf7 X-Gm-Gg: ASbGncvIxev5EcD1FQBPLWu6IrrXMloWUitvrdgnDTT1VXYFtj7M7PjIFx9htnkxBGU tgE99ORQZBiGLZgYODS/EsK7Yu4EJCz3+SXh+EVxxkYCkxSAAK0PjLpCR67EQXEUgzKNk3Tj3Nq xh5jga47CSmibqEAB7m3Wr6lqDC65MUbgvMXg1jstYw9zSIPZS/EaZNGkcZsqzln18qc7kOkX5L vDNA9djKohMxcj0jExhDiO237UFhFjyGKgvGtwQXbPgkhifTpwkAYUGfxaNuPp9HKJJWTUt29uF snTYeWMBp7PixDW++W4mpbA7kJNqR/qN2I47oplgQQPybPnNGqSYtz4kUvN+eFATtpC37JBxd6z vm0rXasisbqtUKktSnwMkyCPg6fLCGE2G X-Google-Smtp-Source: AGHT+IHnCoh0OAe4axWmL20FoXf5VObbkWOWaaYc43C4lAvRwQcH0SlNZZ/I60fw+XEGmY114DRcGQ== X-Received: by 2002:a05:6a00:238c:b0:746:2a0b:3dc8 with SMTP id d2e1a72fcca58-7490dac586emr14075135b3a.17.1750628019333; Sun, 22 Jun 2025 14:33:39 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7490a6c8c80sm6802898b3a.177.2025.06.22.14.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:38 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id A45F3EF1EB8; Mon, 23 Jun 2025 06:33:36 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v10 10/13] um: nommu: a work around for MMU dependency to PCI driver Date: Mon, 23 Jun 2025 06:33: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" 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 00:37:51 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 C37FE21B9E5 for ; Sun, 22 Jun 2025 21:33:42 +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=1750628024; cv=none; b=VQn6rACVCaBFCvitp5Zc8r8SP/axceJ3H9/BwtPbsHogMuGaHfFCmEOEy9cCvWAGy4nM0up5bpG7mzLHMUnxoI0TpAxIAIh9MmyzRj5a8DAom8pZGC6AptxSKStao+yFIw1Bde6bWoFIcMjWKDd/szSgB1EibnbHlbOrueT3Eqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628024; c=relaxed/simple; bh=kvY4llqgRsxBvMcZ/CXo6FHDMPIg9Hmu3RD2Lrj2HZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Elp/G9vXs7hK89cUf83/zyN3/CfIA+1WrN/HuonGp4gViLMCQ2jfdOF09up1njA6zhlTu3epAA7o3KKKxXs0jcq4pekurmIqpZqP2tMMsp2WTADrjOc63V8YJOl7/CUM7xAnN+M7CUE1cViC0eljpTNjvv1RTeQ4+S0gJTk0VV4= 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=NEFy63Ox; 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="NEFy63Ox" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2360ff7ac1bso23572925ad.3 for ; Sun, 22 Jun 2025 14:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628022; x=1751232822; 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=NEFy63Ox7cJimbNq08CkoIAWsWlLyYxxmlgx1BP/kbwV24ZownW8YdXy2Lqcm6itgH hiMQkLmegJ7LGwH4p+Myj3xoqYXZTE5rJ7v+cCgL1jvEYV//wzZ72dhGwHx5EfkzAd64 4Z7mBC1qJcO7TtTNcUO1EY70Fih25P9qKTL5aEur0dlUlYi2FHU8rldGqK3LfMqcrQek 6p7rPHwbAjAfMt0Be3NZvRuGw3aGegpcerFsSDGdY1HLTiKJB7viuY6Nx1AFgWPHRQ6O 8ps4eipGckoO+fgrnsSZoTktyGS9Vjj2umK123nYo4GpqpcH84+g1E58j3EWf+xHCEFo eC7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628022; x=1751232822; 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=d0rQcYpCkx5g6L82l0cnVNkTynZ02o5D51pYf5e3GPKeVxTCcvkaToGSjSPUjMD1Y3 IgxFJbsCSx20xGVljI74bZqVM7WY6qZi7nB1jU496Eju9wIFQcbNW0nmReYO3fHFJswP 6ymGn9etOT1uTwssriM0CX8nZJVb4twaAYXb2hn3m85rmvxk8QS2eq3pw+byb7dx8UEh GBwlK16HatJ6Y9L4PoJfj0cPsQZrnMPXm64yDq3pmQLpKLENcYgpTyL2zqFQNQz0F2Yw Aql/6QIfxgZddIrq/d7Mcf22tgUXa7WHuRgxpQ7oR99RXs/4cYGeDEL6+yH5Oo1wvGhx gxWA== X-Forwarded-Encrypted: i=1; AJvYcCWd+9SSR/itT0le5mz+X8U81aTS2rkAfVtYCeLuaA4YeERducWSapW8b2OjnEHSIvqn3NC0doUrhn3B69Q=@vger.kernel.org X-Gm-Message-State: AOJu0YwkP89P7WmBC+DlwLhyXykPHxtLTymyOQAsc1qVcy3xylRqq5hV szQNDDocxxK+WtQEN05W0RcsYOrSQe2eMtTKmM9vkzpNXLhXkcoquV5o X-Gm-Gg: ASbGnctNPpZsJFgXEHzu9x2x9GlynDgW7n4iGs1onerM0MVQPVIoH/Q8fFHlcHT6CtP 66pcZBMgIEO6sxSh2es60oHccXR202fEFp7csmQggXcL+p7mEZbFcX5SERGMfa+EQUNtmCp2gI9 3PSkuqt8QB0F3cYAMNwyNIXKRoSrxo7Al81hl+pjwLgUqFatjdKiQ5ZBOy0LIJ40Ouaoj0SResM x1+q8bxkcNXxsKLvUq0zUnARym0Yp0YiP7aDM+fGNh2yau1mmc6rZlFuX9x8D03295Rfn/zvEbT zUUT0rcvoUGwSRK16PLBqMUeUl+Il5HE6IIRBvWvkSrMcvzs/mtwd9triyo+HWc82ecZbJ758bc N+LWegIpj7sO9qCPzRYRf0bGI6l3s8VMS X-Google-Smtp-Source: AGHT+IE2X/a6jjB1EnFZZyhowFHSJjm1zCMXjlA1XnMsjL3oMDjBlwH6AM3zKhRsmJ9nHB3vT4YZVg== X-Received: by 2002:a17:902:e889:b0:235:f51f:c9e4 with SMTP id d9443c01a7336-237d980b75bmr163794955ad.12.1750628021956; Sun, 22 Jun 2025 14:33:41 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d83cf981sm68073275ad.59.2025.06.22.14.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:41 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 5EFA2EF1EBA; Mon, 23 Jun 2025 06:33:38 +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 v10 11/13] um: change machine name for uname output Date: Mon, 23 Jun 2025 06:33:09 +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 00:37:51 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 4B5F2225785 for ; Sun, 22 Jun 2025 21:33:45 +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=1750628027; cv=none; b=dvdllrqQXCgTN0s+Amc0ChFHjjHZdkH7BFpoafbkQjYrmh3IhHb6DCeGWFutue0olr6ljGTn63Sj1/lRuXF6CfD7HQAn/AqyDLWWFi0uttpQAeSs+TgWxFzIx73Ydkx4FmbNrm5e9ps3LIs+8dkOqIHtQrXMWC6t1rE24wl5sDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628027; c=relaxed/simple; bh=ZCQ+sWv+kQaZZrdKs3rCAYePM6dCyF/eP1qin3deuM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MQTMAP78w7NYfhjaVJWRj+eJAZ6+x4wxnhwE3wYTSTQ5a1F1eedddBhL1Cr3cUQJWPBVGiPPtD/yBgkS/twJ+2ubwgJRIPxSIhvvQ4vp2Mlv9lSQPZZ4KhETES9a/BNwad844GMLTYL+OI0xmqmlwDaL8UzuJei6kxqjNkfV3Gg= 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=C/FY/529; 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="C/FY/529" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2366e5e4dbaso28060535ad.1 for ; Sun, 22 Jun 2025 14:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628024; x=1751232824; 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=C/FY/529uo6fJFymmIfiuAZG7a8JiXV5VJIFtPHGK/TaRQjWhnnEhytwUK69GT1FVb FV/37N6iJgFOrYt/0Yez8EOT1+XjCMXITJxZF4cdMHD5as9p+FeZtspkwwK0+ttcj2Gk ZFKfFhhDUmZqQG46FYdfWXxvhVbPw85i1f8WBU0oQ7v0r4FeSVqSAX95gEh4uMM+NrXu r9lA98vnSv0qfrk2qcRmLtIMfEWM+GGCDnT5TlOFqhOUdnUfKe6oAO72hSz27mferfkK ne7WV3UL2fa92AfHudK8O4vrOugBpTn88meH7haSed88DHHBmyP0z8b7zrXXT5NCp8+1 S3lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628024; x=1751232824; 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=Z55wbL9QxYBEN/Zn6FAj0XeGasfl20cBVVGu3BGAlDqZUdh4VOhn1UWSJa+q7X8x9t mkHVyBuccUT12il1J7wF5fbxHA1vKYhX3TZPsqHRTzCY86pAgh4xZA09mh1ivyTL9Tkq BRkqWjr0bmvWQxubgh5yp29YWbILhEQY8yTY6uPpXuLbtMuTD94uHVb38jqX6b+S4whW HbPLNTaVzICoWZ7LewLAjTxQYzfbhU2vPXwKO035YldBD1fwFSPX/63VK+4GCAvwBhOK F6raGtJhaT5HnGEgytSh61tOK5zmpXCXJkD9Lr0CBKTvQQ76WyELgwEK4znptlyrXFqW g+Qg== X-Forwarded-Encrypted: i=1; AJvYcCW1sSy6P40JHW24V5xY8KJJeJF4UskyFhx6Ooko0ujTqZXMQh9dF7owVx8xHeSMelDanyh1E0Qw6Dn335Q=@vger.kernel.org X-Gm-Message-State: AOJu0YzFaBGbZ1XpU8xpK0Gg+6e4qXbU0Lg/nypIp7V9Xh5zVT1rzQX0 uBXeX2MdZtBL7cSp3xodcRHycpPBANoetkd+zeHFcm5JEK0f56Ro5pjeUu3I1Q== X-Gm-Gg: ASbGnctI/ir1V989711FpA99rezKH/pnNylAixGksPoCzZ0t/YRAZ4ebz12WbBCMDB3 SDB6KdZFw6HE8Zp3ztRRA8E95qn68egEo74PZV8QvORwSfrn9twGTG44DT0li9Wm2M8OfLEEyPA KGSvrucAp/zbhF4uYNez7dp8Kw6348V3dbiGH2+Fhgb/vBsSsBg5RuVW7EswAVo1GIiTncOcRWs /GlcozaVFUrmyqmT0cYhkb/666EpOB/le6oRYh31yXBIa1hTf79bYnGdjNedlMr0cUEKYvMJ53h LJqB/exJwj1xuOb/yPzXhLNN6DK+/LDYFwilSr6x9IcObVrQ59NRqCebVN1gJzEEgoZhnRvegcB MTqaaE1iF0szaejP8vnxXlxPhJWba0X3k X-Google-Smtp-Source: AGHT+IFIxUQ0/YD9Herz6BdBG99RUQWTSP01WOOdLGUJBk0F001Qhh8PYbENqSOqfVF9ZR/sOn/VmQ== X-Received: by 2002:a17:902:edc6:b0:237:e3bc:7691 with SMTP id d9443c01a7336-237e3bc76bbmr88766475ad.13.1750628024337; Sun, 22 Jun 2025 14:33:44 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d83955a3sm66601295ad.36.2025.06.22.14.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:43 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id C1671EF1EBC; Mon, 23 Jun 2025 06:33:41 +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 v10 12/13] um: nommu: add documentation of nommu UML Date: Mon, 23 Jun 2025 06:33:10 +0900 Message-ID: <8da6d6a802e2bd4573594aedda3d1f827d86517a.1750594487.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 00:37:51 2025 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D5FB21CC40 for ; Sun, 22 Jun 2025 21:33:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628029; cv=none; b=ur+C2m81ysaXoT4cORkyfr6F3zd+j0SaeQcZ6XdEIdqyc2YHJoAfiZXttBal4KEtm2jxWPNEr+PJpB6FgA2AmaeuvxuAKnuwIcGgdn9GNcFhCE0zYOH5gGFnH1SWF2ow8ZF1wuBl9qNmRMHXvVCCIs07sRG2vN7eSp8tSj0KT7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750628029; c=relaxed/simple; bh=MryEApqacNPUDPx//9kRjyNmysSr/3bbD7GV9l6RwME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qJxQiADOt0t2Fr/6oc/+PJTvTZkvDQXmHp31Vy0UHY7lZOL8pF4yAisTVkLlA63AJqKC5BPRLgcuK10leSPWk0nGFs2YNpkjd4Fol8LZyq0VVgM8nXrGAVBpYJKuJYvqI7hQRLAizw8dhmleSHdThFjEZiGZiDE5LPnhIDu1n/I= 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=AkayZplr; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AkayZplr" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-236192f8770so23921785ad.0 for ; Sun, 22 Jun 2025 14:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750628027; x=1751232827; 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=AkayZplrElO0Azrs+uCy56R0njFWNekTZwHyZ6O8q0J1fN8N5M4T4c8G81Ww5I1PON QkQBgJT4kvdR4nt8GqPrLhN70d6ASTbpWwveFM3C8dDcQIvoOTd8Ql35BA58EgCDhD/n EZX81MpWl/RoYJNwDNSVN6rSXErhvfVpnVePWX/KBTKR9CR/LTVfz7n3N44Tm84k+g03 dspJUFywH0biMmwzrEZDggdAsj7zMjislC5erA4h36Vr2SDt7QIKJRcQqKXOlzq/Rwwr vytzTgyDcZ1tVLM9/ueblEJshs8pY6mybdXDUXjpMabFDY5QHnr02+melSs66QRh2sqm W1Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750628027; x=1751232827; 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=MtKPyqdHetAxMMOgaU6ChVQswEz1dLOhTMHyU3zXSPx01L/xQPQYMMeAMYxw3atedc 3Bhg4YUHTfyLVapJ2aI+SXK+mHdz2N6vYnveWz24BeRuWZil0XsAstQ3lreCQbxigc1v G6U4TXzH8jr4LHsyuAGFchSR73YxNlowMx9ESGC/ondDNPZ9xl++4dpIPAYcPf2yiPBl zEmZMst7VBuiJlIIuVrBuCcplkOYYAmU/HkcffU4vkGQ4RSQ7RY9zF705WxufPgnUdOc 0ZAwAj/chYUUBmAK/8nIa/hi/0kFeG31gTbDe3YffflChBLMIMD9mlRINBg5RBJq40QO p0CQ== X-Forwarded-Encrypted: i=1; AJvYcCXUNdFslSVKMMQ7Cvqf67rKMoDqRLZByMnAGFnK+0HEcF3+bRyavbISGb+BPn/N8AmahZwbqBMq6uagGXc=@vger.kernel.org X-Gm-Message-State: AOJu0YwJk8o6+Z4gtOfXSoMhP9gzS8RYNUNeNNOoMV8bydCzEmp8NEYX pr4LnzhnxWVxHiXN1fsQCEt9sVB2bDT3wJzvguPPdkGd83DJhpJ8lKjpms6roA== X-Gm-Gg: ASbGnctR3dZ083eRRyeUv6SdBfFKS+nmtgV3jM2TIeieXEcN7Y2H5op3zfqBKoZ7zdy ld4I4aOUJqJgQRrdW8vGzMm1Vk9JBg0TlywuGEv/zHem62uFc6K+poI9MSM0kouYETD7UYyiGbm 4V1BI+bHIKJTJcOLr4MnL2FwOry4Zasr+IsXoyR6Dl38YMSHVJi8orVo9a5TSZX0gWIHZvwNXOl xNsEPl5r31Hnuu/G3WWvfJR6EybNNSgey6eooP3pQ04tVpgDvdmq04PC380gV1KLTCuXz1VAhiU WX1OZThpM0L0jS4LBNlcjDiUEaqjSw2v4P5XVAi8osYsZY6MY4N6A2CjfRwNGOIbbv4nV0eDU7z jwzQSvu+grd9OIHCEEcCh4KakwuqsptAI X-Google-Smtp-Source: AGHT+IHxp56Xls+moSgffTIGwer9X/frbYltlT1Wotdht1GfPvk8Ri0YMlmgTa9DA+cKj0epHgkh4Q== X-Received: by 2002:a17:902:f64a:b0:236:8b70:191b with SMTP id d9443c01a7336-237dad62920mr129643705ad.0.1750628026800; Sun, 22 Jun 2025 14:33:46 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-237d83d1390sm66931345ad.68.2025.06.22.14.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jun 2025 14:33:46 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id E3DE1EF1EBE; Mon, 23 Jun 2025 06:33: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 v10 13/13] um: nommu: plug nommu code into build system Date: Mon, 23 Jun 2025 06:33:11 +0900 Message-ID: <2b8eb79a28dd4cca358236347847679c7a968f04.1750594487.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