From patchwork Wed Apr 30 04:27:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=4bG+pdd0; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=D7+PHkkb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMN4hwHz1ySm for ; Wed, 30 Apr 2025 14:28:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ukyNfs65nuvgTdhSkdJYZ2Y9345NLuFCWN/gVQv/aLg=; b=4bG+pdd0/GNv53Z22VvWGDUlQS 3YCFj02peh9gOgApdPkyNF3Lc2391vg5US4FHt0IJBdc/bM6GSlwQyV/83liaQTjpU4QTmqJ1EvA1 O62+6c108RlKAAdPs6c3gx6sGe7vqRQyN0fZ4NBktznIeLTOkQPcyKhKOZDRNV15FNPjZUWO1zMVP i9lCMtWX8rk+/L2dy6HYBcP3F5LUHhQBW3cOUgZcztUah9EBBRCvA2a2bj7+z2eKB77C8LdSkshlX qBxTBM22pYGgRWdh06ETr+jL9B3eNa+ph5J83VOzpjv2v2Stx4R+7zXV9d9FM3mdxRddLqYXwa1G4 a2ZbOH/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4A-0000000Bffe-35S8; Wed, 30 Apr 2025 04:29:02 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z2n-0000000BfPJ-2fXx for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:27:40 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-736b0c68092so5936327b3a.0 for ; Tue, 29 Apr 2025 21:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987256; x=1746592056; darn=lists.infradead.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=ukyNfs65nuvgTdhSkdJYZ2Y9345NLuFCWN/gVQv/aLg=; b=D7+PHkkb84R3MR52zjefn3hEbZ2e1eAWN9Va9VP8dahnupE9ut8HyMKK+3jLn16GYe gssuZqdZpkGvnBsB+ktlZQcZYPZRKggtJLYX7fDlW5YXThc69MHJnzGpgw08SfU+/pNt mCwubGkwSUIsnBleKovqFH35KW72Fz2RLTB9voo6Bk7Wd/IEtqEZLPpfaMiYUPaULwJZ O9ct+aeSEut7cNNK1CqVDrwApmzZVf3jhNHTG7r6IVEu5bnzymBEE7kku17uutqXwdMv fODSy22MClCWlJ5ZV8jg4o0maonZ6cUo6YD71s2jhVltD4FGFlaIvHGDRMaETQgmXmSX FkdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987256; x=1746592056; 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=ukyNfs65nuvgTdhSkdJYZ2Y9345NLuFCWN/gVQv/aLg=; b=WR3aJDqeob1Jfds8e8bEERlLNMcMImiJbYwnIh7j51h9HOU+lDwLbgAKtopiNB2o4w 9AI7RF3XSFkALDMQHMoceIn40iAj8hQEbgCz8GlGexNr9Ogwwd6zcqWDaLZ/2hrHx6kJ HbGZMrgaxN2AdfrHESR8eIVwdP97IZ7B0/19IPL9NXZQsBRLCOlRuBeTPDxfVahGdy9K 8/I3+yp+LUTjWBSmnE5j99EUZineqPItvlSvWRFCqpgBgUGdgEqIXpQsQwrF/pDG58NF eH8h3dEEwthzNr0wpO7B6CaUNRbtkX7hBRGzm2ffCVzIP0dxvq7YV1ILFnw3DAHOaOQV fGHA== X-Gm-Message-State: AOJu0YyG7kVI/4B6UeK9daeTSPwWFeE7hIKnpJx539bkosyvHc2t6WCt YyeMuAFZuUlSLA7VCJ40LyrtW2MRY1oJPPulKLg6csYHalB5g+9P X-Gm-Gg: ASbGncsWpzOiDIu1A7e0wf5TuMVpYOwP14iqbV0cFOtibP+HDgZp356MQS/TpX0iK/f 22jCssRA4wNHnH0Bir6cQcDHOl7mppp5E8Qgv8WNcDpmtAHn0SJId7zHS3b4Wla7h9LImoVU4MV GAkfwVD9LIN4yHtpsb4D83lztAhSNJcoCjVGp2q6ERu2/9q2z47KyKQAY3azcHLTksIM0xpCYtz Mvnr+tm+6vqu9kQZXWl9KRqs6WJQKS6gaJ/B9t3iEFa86aa5nZVY8BmyGYZyEAcNdQw310ji4PB 9+MeRBzDZB5zH5RCGtbkb8uTFH+vJN38kkMc1Uagw5otPMYK/Gfbcw2zqEf8nyGSfvFgnwGriuO GQdNWyTzTaW0= X-Google-Smtp-Source: AGHT+IHaI2hva/XO5UNyBlcemnxgGJqm96jqA3suKBcAYtlVKSOpmAkCAY78xziMTfLiN3rWee/VXA== X-Received: by 2002:a05:6a00:2e24:b0:736:39d4:ccf6 with SMTP id d2e1a72fcca58-74038989daemr2827463b3a.8.1745987256524; Tue, 29 Apr 2025 21:27:36 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-740398f9ac3sm621129b3a.23.2025.04.29.21.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:35 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id DC01FE94814; Wed, 30 Apr 2025 13:27:33 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org, Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v8 01/12] x86/um: nommu: elf loader for fdpic Date: Wed, 30 Apr 2025 13:27:07 +0900 Message-ID: <1f0ec32dbc49f8784995a29a2e87063507eb9838.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250429_212737_673177_6CE53BFE X-CRM114-Status: GOOD ( 16.84 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: As UML supports CONFIG_MMU=n 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 [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42a listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org As UML supports CONFIG_MMU=n 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 a3eaca41ff61..01422b761aa0 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -14,6 +14,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; #endif diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptrace-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 { #define PTRACE_OLDSETOPTIONS 21 +#ifdef CONFIG_BINFMT_ELF_FDPIC +#define PTRACE_GETFDPIC 31 +#define PTRACE_GETFDPIC_EXEC 0 +#define PTRACE_GETFDPIC_INTERP 1 +#endif + struct task_struct; 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 #define CORE_DUMP_USE_REGSET +#define ELF_FDPIC_CORE_EFLAGS 0 #ifdef CONFIG_X86_32 @@ -190,8 +191,11 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, 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 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 From patchwork Wed Apr 30 04:27:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Jfr61skh; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=lo4S9wPp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMN5Bslz1yVR for ; Wed, 30 Apr 2025 14:28:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XxkcTNzm3D6nL0kwz3FotmEhOp0HbpyTDMavm76nXag=; b=Jfr61skhVuwyTFu5Hkpe1xu2Ni yNUtjMAcSX28syriAL7BoVdIU8P6o7XZj9/LZPop1Ubl9K8h4xemY6l5aUWHwBsDM/u7BBICpcH3C knxF1UxY+kFAKMWLEuOg8tRxRi9LZ+VaQqrhgu75t1Iy4+/G+SNbMJv7drbUI2Mtkf1GA9FPRbvki 6L/QCOpYKkZcIoep7RNE+tDa4366f8nS9Wb9R4RlhKRv3dkk7gFReqxNEpDS8MwvPxt9d74hyKma0 9aq2b5oM2OJhQ7Vlzhmq9ppEsbKK3FuvruBwTHAE6S0z8Sr7810uslY0F54uSiRH/6Td0vLVhQMOb nZYt6I4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4B-0000000Bffk-07Af; Wed, 30 Apr 2025 04:29:03 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z2q-0000000BfPd-2j2I for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:27:42 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-227d6b530d8so75747535ad.3 for ; Tue, 29 Apr 2025 21:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987260; x=1746592060; darn=lists.infradead.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=XxkcTNzm3D6nL0kwz3FotmEhOp0HbpyTDMavm76nXag=; b=lo4S9wPpNawHdsZKdqB2DyOlIWPJM8baVJxnzeRN455rsGpkB/JzWopfV/kcaaJ1R4 YMZifyvJ7c/Iay1/awIf4BhBRF2Wy4HjHx0tG7/ZDzYtV385Ls+CqNu2F0IdawKNZmcV e1xP5i8iJyFkGGIxKW9emSLiAA5CKRwrOD5ONPd8Clr+PAU4ZYAvto/B3Y6CdWKSL8Id 0ldilPt2zsa1MY0xQrTMe2QKJk/xnxTpJYIhYTarYVTqWW/bBvsiEQFnvSmRHg2ZgJSH 5bXUKJsEtwVXhRBKHjNmIFbAOTTNHluRtA0ibicxkZs4lMTjwm9fKHu+sq5wHStzBHlC xJsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987260; x=1746592060; 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=XxkcTNzm3D6nL0kwz3FotmEhOp0HbpyTDMavm76nXag=; b=NQAQun0/YRUuVlIYOrGvjXDao/kWY7B2UYvybJUpiIZxJpScqA9Cp0ba4b0bzwMi+W TOP2vK2zJUkP75UYqaJzSemAyzECocWiOMZERluaIUrpqsSiYeT9WIN0X6oKGOmEHl/Y pShwQaemW3VMMcTtg5Us2EL3tTvyPTJPGSRc1ELxw7azAZJdK4PE9zqc+PLQjElANmlw CLgtno1J4fCo/H8iOfbyHSdJjSWoJh4pjt7rOQnvryI2XNMnaMuGl73S1KYI5DKwXsp+ XlMUF0ej3Z5lCTXaA2NlOMYcpvCD/sgBrda2msQqjB1AvZWpP00U4UqoTkn8Y8IHRhKJ xMWw== X-Gm-Message-State: AOJu0Yy24yNzasWV4Hc4ajjqhkHqR3tTJXemJ3CSQRX1ROoHnjTu7fOL 9EdPs3LyKYA5qnWTbH0vHHoRsbuXUGwEf1N6ZQ2dZ2onMMNSy3o1 X-Gm-Gg: ASbGncsFTes5A46qFwe9h8p5ctwovkuqdzGfdzQtBCjgbd02xhmWr+SUBTwRfzK6MBn Benszur2HTK5mE2aTXuYNxfz5jxGRoSUHP7VOr0IAh7tQS9vQOh/qWASHIdUHlTrWpbnkzKritj yqnFGfCmr/SKgr23NGa1gmUolDORaaiZe3fPkQlCOpUzlhdhKCRU4QSXfiP+xcmHBXxJHRElz6B WsWXDXbVq3VrfUR+gLIKAWAiHw0/526h/KZZwB1WMejAhKC6yhSxQ3DcBAJGt8ze3+X6wDJ6JpK X3QnXSZ6HArFKCtz/9sWlXszIoNSDXCiAPE+mWgbiG8K5aGzdC7Mhol7QV6bxl3AnduPwJTSk5k tLSBcYAvPkCJ+E6JXrgALWQ== X-Google-Smtp-Source: AGHT+IHgdjbusCjYmIH+ACOzIzDAu13eai9H3Z92dIgixBY5dCjEqln5XxlFGM+akjniyzUkMjrgLw== X-Received: by 2002:a17:902:c950:b0:224:c47:cbd with SMTP id d9443c01a7336-22df32b7e5dmr29296215ad.0.1745987259538; Tue, 29 Apr 2025 21:27:39 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db4dbd20dsm112320725ad.79.2025.04.29.21.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:38 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 9C164E94816; Wed, 30 Apr 2025 13:27: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 v8 02/12] um: decouple MMU specific code from the common part Date: Wed, 30 Apr 2025 13:27:08 +0900 Message-ID: <7663e05099b914d3b978a521b2d3f67791a3abe9.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250429_212740_701258_F12CB0D5 X-CRM114-Status: GOOD ( 24.48 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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/kerne [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:632 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 | 133 ++++++++++++++++++++++++++++++++ arch/um/os-Linux/skas/process.c | 132 ------------------------------- 9 files changed, 223 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 4df1cd0d2017..827a7438509d 100644 --- a/arch/um/kernel/Makefile +++ b/arch/um/kernel/Makefile @@ -16,9 +16,10 @@ extra-y := vmlinux.lds obj-y = 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 += load_file.o +obj-$(CONFIG_MMU) += mem-pgtable.o tlb.o trap.o skas/ obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o obj-$(CONFIG_GPROF) += 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 = (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] = { + [VM_NONE] = PAGE_NONE, + [VM_READ] = PAGE_READONLY, + [VM_WRITE] = PAGE_COPY, + [VM_WRITE | VM_READ] = PAGE_COPY, + [VM_EXEC] = PAGE_READONLY, + [VM_EXEC | VM_READ] = PAGE_READONLY, + [VM_EXEC | VM_WRITE] = PAGE_COPY, + [VM_EXEC | VM_WRITE | VM_READ] = PAGE_COPY, + [VM_SHARED] = PAGE_NONE, + [VM_SHARED | VM_READ] = PAGE_READONLY, + [VM_SHARED | VM_WRITE] = PAGE_SHARED, + [VM_SHARED | VM_WRITE | VM_READ] = PAGE_SHARED, + [VM_SHARED | VM_EXEC] = PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_READ] = PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_WRITE] = PAGE_SHARED, + [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = PAGE_SHARED +}; +DECLARE_VM_GET_PAGE_PROT diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 61b5a5ede01c..cbe8b9d03d8c 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -206,45 +205,11 @@ void free_initmem(void) { } -/* Allocate and free page tables. */ - -pgd_t *pgd_alloc(struct mm_struct *mm) -{ - pgd_t *pgd = __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); } -static const pgprot_t protection_map[16] = { - [VM_NONE] = PAGE_NONE, - [VM_READ] = PAGE_READONLY, - [VM_WRITE] = PAGE_COPY, - [VM_WRITE | VM_READ] = PAGE_COPY, - [VM_EXEC] = PAGE_READONLY, - [VM_EXEC | VM_READ] = PAGE_READONLY, - [VM_EXEC | VM_WRITE] = PAGE_COPY, - [VM_EXEC | VM_WRITE | VM_READ] = PAGE_COPY, - [VM_SHARED] = PAGE_NONE, - [VM_SHARED | VM_READ] = PAGE_READONLY, - [VM_SHARED | VM_WRITE] = PAGE_SHARED, - [VM_SHARED | VM_WRITE | VM_READ] = PAGE_SHARED, - [VM_SHARED | VM_EXEC] = PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_READ] = PAGE_READONLY, - [VM_SHARED | VM_EXEC | VM_WRITE] = PAGE_SHARED, - [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = PAGE_SHARED -}; -DECLARE_VM_GET_PAGE_PROT - void mark_rodata_ro(void) { unsigned long rodata_start = 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); +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) 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 = start_kernel_proc; + init_task.thread.request.thread.arg = 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 -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 = start_kernel_proc; - init_task.thread.request.thread.arg = NULL; - return start_idle_thread(task_stack_page(&init_task), - &init_task.thread.switch_buf); -} - unsigned long current_stub_stack(void) { if (current->mm == NULL) diff --git a/arch/um/os-Linux/Makefile b/arch/um/os-Linux/Makefile index 049dfa5bc9c6..331564888400 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile @@ -8,7 +8,8 @@ KCOV_INSTRUMENT := n obj-y = 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 drivers/ skas/ + umid.o user_syms.o util.o drivers/ +obj-$(CONFIG_MMU) += skas/ CFLAGS_signal.o += -Wframe-larger-than=4096 diff --git a/arch/um/os-Linux/internal.h b/arch/um/os-Linux/internal.h index 317fca190c2b..bcbf64ce8cd1 100644 --- a/arch/um/os-Linux/internal.h +++ b/arch/um/os-Linux/internal.h @@ -2,6 +2,11 @@ #ifndef __UM_OS_LINUX_INTERNAL_H #define __UM_OS_LINUX_INTERNAL_H +/* + * 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 184566edeee9..2331e32c4898 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -15,9 +16,15 @@ #include #include #include +#include #include #include #include +#include +#include + +int userspace_pid[NR_CPUS]; +int unscheduled_userspace_iterations; void os_alarm_process(int pid) { @@ -158,3 +165,129 @@ void os_set_pdeathsig(void) { prctl(PR_SET_PDEATHSIG, SIGKILL); } + +int is_skas_winch(int pid, int fd, void *data) +{ + return pid == getpgrp(); +} + +void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)) +{ + (*buf)[0].JB_IP = (unsigned long) handler; + (*buf)[0].JB_SP = (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 = 0; + + if (UML_SETJMP(me) == 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 = setjmp(initial_jmpbuf); + switch (n) { + case INIT_JMP_NEW_THREAD: + (*switch_buf)[0].JB_IP = (unsigned long) uml_finishsetup; + (*switch_buf)[0].JB_SP = (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 = 0; + return 0; + case INIT_JMP_REBOOT: + kmalloc_ok = 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 = proc; + cb_arg = arg; + cb_back = &here; + + block_signals_trace(); + if (UML_SETJMP(&here) == 0) + UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); + unblock_signals_trace(); + + cb_proc = NULL; + cb_arg = NULL; + cb_back = 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 = 0; + noreboot = 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] = mm_idp->pid; +} diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c index ae2aea062f06..40136102fc11 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -5,7 +5,6 @@ */ #include -#include #include #include #include @@ -16,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -25,15 +23,9 @@ #include #include #include -#include #include #include "../internal.h" -int is_skas_winch(int pid, int fd, void *data) -{ - return pid == getpgrp(); -} - static const char *ptrace_reg_name(int idx) { #define R(n) case HOST_##n: return #n @@ -315,8 +307,6 @@ static int __init init_stub_exe_fd(void) } __initcall(init_stub_exe_fd); -int userspace_pid[NR_CPUS]; - /** * start_userspace() - prepare a new userspace process * @stub_stack: pointer to the stub stack. @@ -398,7 +388,6 @@ int start_userspace(unsigned long stub_stack) return err; } -int unscheduled_userspace_iterations; extern unsigned long tt_extra_sched_jiffies; void userspace(struct uml_pt_regs *regs) @@ -560,124 +549,3 @@ void userspace(struct uml_pt_regs *regs) } } } - -void new_thread(void *stack, jmp_buf *buf, void (*handler)(void)) -{ - (*buf)[0].JB_IP = (unsigned long) handler; - (*buf)[0].JB_SP = (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 = 0; - - if (UML_SETJMP(me) == 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 = setjmp(initial_jmpbuf); - switch (n) { - case INIT_JMP_NEW_THREAD: - (*switch_buf)[0].JB_IP = (unsigned long) uml_finishsetup; - (*switch_buf)[0].JB_SP = (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 = 0; - return 0; - case INIT_JMP_REBOOT: - kmalloc_ok = 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 = proc; - cb_arg = arg; - cb_back = &here; - - block_signals_trace(); - if (UML_SETJMP(&here) == 0) - UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK); - unblock_signals_trace(); - - cb_proc = NULL; - cb_arg = NULL; - cb_back = 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 = 0; - noreboot = 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] = mm_idp->pid; -} From patchwork Wed Apr 30 04:27:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=TBv85Z1h; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=c2sI6Hbb; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Y17HiTd1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMP02DFz1yWr for ; Wed, 30 Apr 2025 14:28:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OCuYr2KP3wBxDodLMaPRY+onEFYkqYFG8HFmFD5AH3Q=; b=TBv85Z1h7PyiGfFXoQdaNfZWny tjaCXgL8JIGzkCxrq5ZbYkQUmf4psd6lKL5JyqAVfrR6lFiF80YuI7npEuVgN1YHjG7nmQg4+5Nzd 1IkHg2uxpLy2oBL44an6JssDOvyTUNefOpNOid/YjBE8hW9Uwput0FxSfP2OUZ74m1ReX0/y5qbW4 a5nss2jaqgL9mBpaUbOI2fUMbEVJzXdK4hy51Ctj919EMiqyMH9nuUwqWQ+uuFXvoN0lpoLzRyImU htYipdAOtBuzonHm1F1Qcjvp8h7rnAj+wmXL5kPywEjB01j/Mvogl85tzLC8c7pYaUr4gd2jYF9Ld 1twgGV4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4C-0000000BfhA-0TxX; Wed, 30 Apr 2025 04:29:04 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z36-0000000BfSg-1FcH for linux-um@bombadil.infradead.org; Wed, 30 Apr 2025 04:27:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=OCuYr2KP3wBxDodLMaPRY+onEFYkqYFG8HFmFD5AH3Q=; b=c2sI6HbbAOLQDZDJEDgFXoKSVc PMA6j8B9+OvRp0z8XAAxL+btJiPYMVYVRQPv/49MqgeW8OPYkq9MQdiRZX+ByCQ5S3mejFBu3Xwof JM2sEyOkx9RKjjXMId41a+TMJ/e+7ipB4MZ52g907q5j3TCPY3PPEnagqqVtSRJAFX5X0qCx0SgJM B1Lm72X+r8mUcoHGNytRaQo0FDVeLBwCNzxMWsCY5NRZh9ZuBugjqdXJNnObtVmNFNaJMA3Q9QL6x e4suTUvgkWKLb6MfpkNEGJz+rdR1tPzR2NHDUIa6BOtYmrGhxZ4o2zo9wULcszGeo1KWAwkp44vxf uE1vykVA==; Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by desiato.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u9z2y-0000000DgC2-2BOd for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:27:50 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-7396f13b750so7548930b3a.1 for ; Tue, 29 Apr 2025 21:27:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987265; x=1746592065; darn=lists.infradead.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=OCuYr2KP3wBxDodLMaPRY+onEFYkqYFG8HFmFD5AH3Q=; b=Y17HiTd1g9y2gtvBk9/Mwn29rcAcDxzTOrw7vrtN909Va4yE13UlzUWuFYjlSDm1zo wg0ydRKIF1FunMOnlbNvsfBnsiTh0qCHh9RZT73/Mf0KFqQv2p8sokdbGHTVz7dhIowW VJNLkvYYtdqD72sguP8tTDmogU1cd6HSLpEHpwybH1jezCU6g1EYorSEdXgqObGuVkzJ 41xOeVBUJ6tZoZf96/ohXstHQtrzy1iPpbfRyf08SJRSN4hGiDx9KVjgu+wWIvKYV9zm f69kQ8qus3Eblnvv4u+/eYzaFOPWeFSmuZi/Ac1aA/LaSaHg2UccAwJW/Txdat6hiMMK 6jGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987265; x=1746592065; 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=OCuYr2KP3wBxDodLMaPRY+onEFYkqYFG8HFmFD5AH3Q=; b=ITt1ElGyxso2Bdv9xwEdQ5fPn/EcjMa/bc6RVEgKNoz/ue8ZrsqHfzHOV8IOFnSBiA hHI3IJ8oLVCZTI2Wj/X7MI/89i1wrM33EFnNELdSjMzJqF+GRHPBCHjgmJDy9KPsvSky XDH3VnDu50zhX4X2ggaYZofQbuQta130521DEBWSoRTb4vgOPKWWNP4ZzftsVgP5OfIX JareT8OQ2nrOjY86TqibwZKzIoj86F4D7TlttoLJ30htK/qDCS0gr0u7W7Xd6P3jDFWj zMdlHt3i72HqDAul6Uf9vZFIJpEkCLBrNmsfoQf9ckUsUjnuL+StqCNXSpYvfm26lwqp UnXg== X-Gm-Message-State: AOJu0YyYGQdHS/267L5gk1/dfcctj+pW0kVujIAylqSne+jGD5R+Es+c 1gaEsvSWZ50n1MAPE5unq/qi7v+bhPKWiwDc5ZEV0mwJ4inPDGyC X-Gm-Gg: ASbGnctQDQeykwyxxCg9KJj1JGmG3/V/QPgDsyt3PFEGTPIANCgvIJHCBTqqN8s3Y5/ JY7L6ovJnyOL3AIN+OBK+5VbUIWjP4CzLDoyPgcczAf+XAqlB4f9X1cTW9CyxmW+9B/f0Q+rAKK M9H7EWZx3/SwAtoqi5F5Nps2LYSf9/LwyqkQ/E0F1mBVfMUiYdW7oGi/qgN28SZJVh8S/F4+bZc VZU+5qYQ9MzBEZZrDi4TYDyqNxq0lmALGwYD3wz1jl6r7ZHrVBWRhJJrJHECkapQUo6ep7M6Lf5 jDTtlovoZMSV9/sLh7h0oRB5DRuC1OyRyHu+rfGr0peLP4katnJXmP8R4r4bnkBrwkP0h89XBrf UjBmLEPiX82o= X-Google-Smtp-Source: AGHT+IH0FbwVRr3MAmvHuDKfwKvFcYAl32DVyoxymDr2Jear3LyL+Hz5Wp7hXom+GZQca10gjxHCUA== X-Received: by 2002:a05:6a00:130e:b0:736:6043:69f9 with SMTP id d2e1a72fcca58-74038a85c28mr2474451b3a.19.1745987264935; Tue, 29 Apr 2025 21:27:44 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74039a62bfdsm628293b3a.142.2025.04.29.21.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:44 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 2BA51E94818; Wed, 30 Apr 2025 13:27:42 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v8 03/12] um: nommu: memory handling Date: Wed, 30 Apr 2025 13:27:09 +0900 Message-ID: <2598e5207a53e4ec1f2077b5c5a9f03fc3782506.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250430_052748_801870_41EC7A81 X-CRM114-Status: GOOD ( 16.62 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 u [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:430 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 1d36a613aad8..fcf4bb915a31 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -46,6 +46,10 @@ ARCH_INCLUDE := -I$(srctree)/$(SHARED_HEADERS) ARCH_INCLUDE += -I$(srctree)/$(HOST_DIR)/um/shared KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um +ifneq ($(CONFIG_MMU),y) +core-y += $(ARCH_DIR)/nommu/ +endif + # -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so # named - it's a common symbol in libpcap, so we get a binary which crashes. # 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 +#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 #endif diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h index 01422b761aa0..d4087f9499e2 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -15,10 +15,13 @@ typedef struct mm_context { unsigned long sync_tlb_range_from; unsigned long sync_tlb_range_to; +#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; #endif diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_context.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, struct mm_struct *next, } } +#ifdef CONFIG_MMU #define init_new_context init_new_context extern int init_new_context(struct task_struct *task, struct mm_struct *mm); #define destroy_context destroy_context extern void destroy_context(struct mm_struct *mm); +#endif #include diff --git a/arch/um/include/asm/uaccess.h b/arch/um/include/asm/uaccess.h index 3a08f9029a3f..eb9b7d577062 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) <= ((unsigned long) (addr) + (size))) +#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, unsigned 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, unsigned long size); #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 = (unsigned long)ptr; @@ -68,5 +66,8 @@ do { \ put_unaligned(*((type *)src), (type *)(dst)); \ current->thread.segv_continue = NULL; \ } while (0) +#endif + +#include #endif diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index cbe8b9d03d8c..1e18384381e2 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -64,7 +64,8 @@ void __init mem_init(void) * to be turned on. */ brk_end = (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 = brk_end; min_low_pfn = 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; + /* NOMMU kernel uses -1 as a fd for further use (e.g., mmap) */ + if (!IS_ENABLED(CONFIG_MMU)) + return -1; + fd = create_tmp_file(len); err = os_set_exec_close(fd); diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 2331e32c4898..8a615875d1a1 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -70,8 +70,8 @@ int os_map_memory(void *virt, int fd, unsigned long long off, unsigned long len, prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | (x ? PROT_EXEC : 0); - loc = mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED, - fd, off); + loc = mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED | + (!IS_ENABLED(CONFIG_MMU) ? MAP_ANONYMOUS : 0), fd, off); if (loc == MAP_FAILED) return -errno; return 0; From patchwork Wed Apr 30 04:27:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079245 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=XgyAgzXH; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=fs0Uue6R; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TpTGt3T8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMQ4yW5z1yMf for ; Wed, 30 Apr 2025 14:28:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=V/9FDFFbTGgOECfx9E1KzmmWlTydkD+KFqPPHo/qkbE=; b=XgyAgzXHGh6TnEESrgmXMPBpRt UoGBqR4gD8l9o+Wsabz5/r0eMID4XGRbHjdLMwhK/BR3Gq0fWDZx1q6eja5rv/LM9fuwPdn1h97pJ 2k8j2RSBvgXy42KsE2qUqXwsItrY4qgJOIKJRiqZGoBkT4J2iy1itxDtphcYihstkhF2GXkesjg1d iKQ9I6tGfQAV9Ms20lAhAhi3LmUZWGVuAbZ+RuAOQ7lpQcYCZ6BjZmSUgWsR32xUCjCcJ1kcGTz3m YaAPqrhuDEQXn3uryB4dZsLbkLoe8g9lI9A2xDqSOVjG1bgm3MRk7AxfnUWSuBFiwI0KZ5JJNdcaK 5WwokwyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4D-0000000BfkU-3nit; Wed, 30 Apr 2025 04:29:05 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z3N-0000000BfWo-3jJ1 for linux-um@bombadil.infradead.org; Wed, 30 Apr 2025 04:28:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=V/9FDFFbTGgOECfx9E1KzmmWlTydkD+KFqPPHo/qkbE=; b=fs0Uue6Rq625beM4yqvMxmbnx8 Vmq2QLO4Z8QXMCD9DgP3+exILlfEqMAxRtghwwiix8bv28YW1Nym3NR+I0mTyqGWtPqMWpDqnb+AF mig1fL1H0TJFsGae9SvQS3oBQ8KK2Lnt8tTWp6J2Ulkpjy7/h8iDrbu2zf9KA/u7Yd2hXCm7od0Sw 6z/3muXBtBDMaUKkDROYerKpw+gi8tB0KbnK2IqqEMRLeefu3JqdNVvsCnYRYOGAybpxLM4adnqXd E/1tZnObJQpuS27kYmDpAe6Z8Fdj1/FEH2CyvGFI+XPJ6kLw6+umLgAhMO2sVaieezoe2ebs6ohoQ k692E+uQ==; Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by desiato.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u9z31-0000000DgC6-0Ply for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:28:10 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2279915e06eso77945425ad.1 for ; Tue, 29 Apr 2025 21:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987267; x=1746592067; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V/9FDFFbTGgOECfx9E1KzmmWlTydkD+KFqPPHo/qkbE=; b=TpTGt3T8U32+fTk1tfdG3ytAisv4h9ptH3A78pAfHChQtHt9V6dCjjSZoXDQxYVTI4 auKTFwcOmLsJdao+Cz3DdqWZsX9P343O0vyi75zhjutwqGIk6HMcgZotNVzU4xlrToLA aye1z+YNPSZWA5vS0vZYwyMqjWQzQrQ+XaWPE9J3nv24FOutj9PqSlh7fVURZxP6mYYY oWFi/S/vnQopOhzjumUjuOfOpGsyGnboJCWhvwPLSFco7sodOyq6zWJBBKmCFRZsPCF5 h0Q/FP5HafHOtAyMX85fuyyKI5y7RyJpcCGHJt1LqY3j16jauJGkDbf3Dx0wgVqHn6Vz dB+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987267; x=1746592067; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V/9FDFFbTGgOECfx9E1KzmmWlTydkD+KFqPPHo/qkbE=; b=L1d3bq1mCCNaBNMWuVAsMWWeo7M1bPGu4GtbV3TQOCd48ktBybYjmhkGPeIHtSpZC3 VQ/YYvEiICnZ0JtyOFGXgbzKBMR0aZM8UHETBVrN3Kq5LbLTb75xEBfO5Zq4kSEMbCMA 3B2z0dAUYJjF5m8IXXyF5OVSEH3cDUFkPqXgnUksLznl5eeL8Gh3l0n5wDYDq1Ux75Ey dvilHUoOWjiR4Y+Lmhu4Ex7cJJvwUfZJlBBDK8giVhnCfXu87jAaeHGxJAIxeHUCAzY8 sjhehITFXeF8Qh55oRJBFTAuNJ6tCXDpjX3asljKvOyZ7MD/FQfzoBBs9GpIp3AyrjY+ r1yA== X-Gm-Message-State: AOJu0Yw732fN0pbEPnLmstwiO0PqBY4O5JOp9lfuS1Xg2ku3O8NCFPUN peysQNotwklaIL9NgqcDTzQIG4NewJVqc7Um1QqFHv0+ELOMVPK1ElM59x8a X-Gm-Gg: ASbGncsSR6QhcD1jIXvdvoYo/TN5JaIPn7n+zUvcx0rohySpWw/Smq0020+1IHf7fj1 vbFb6DJKw9V2cmjM4+HqTU8PAFuqm+yoO8LeolDpg7M3ZcaCA0tUwGaMYrA9T/+rxh6Pk+6jfJY Fp7rJljURXJ8o0uExPQYk4yHWb+rfSvEd6SYkmLkAPb/i+xU4u/4Q0C0NXrBW0FWDeNdXsZ8Tj3 EL/eyDlJ1Shqz043S6AvG1ZUK0P8+LetwXMSrR2QpYW9zeAn+dSnGJp40X8e+0RE5PVFb1oRrz2 Lvv6z6nSzItoxA7yoxOiL73RIX1u2hkLi0f7gphfZ/QMsc/mjeBvlMcmwPDztdeLke/fIP2NWDQ heLFVjgwg6n8= X-Google-Smtp-Source: AGHT+IE1t3dxTA3D4yK2A7FdFXYVRfds1pPjBfcX/u2XIDgYkr+Ssgsi8tcGY9rf7mYw6fzn16NtDA== X-Received: by 2002:a17:903:1946:b0:21f:5cd8:c67 with SMTP id d9443c01a7336-22df57d2db9mr17805125ad.31.1745987267296; Tue, 29 Apr 2025 21:27:47 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db50e766bsm112325805ad.149.2025.04.29.21.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:46 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id C0907E9481A; Wed, 30 Apr 2025 13:27: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 v8 04/12] x86/um: nommu: syscall handling Date: Wed, 30 Apr 2025 13:27:10 +0900 Message-ID: <3ba48d392c14777c9a1723b61b7d743ec3a4c14b.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250430_052754_479725_264D4797 X-CRM114-Status: GOOD ( 21.90 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 implem [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62e listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This commit introduces an entry point of syscall interface for !MMU mode. It uses an entry function, __kernel_vsyscall, a kernel-wide global symbol accessible from any locations. Although it isn't in the scope of this commit, it can be also exposed via vdso image which is directly accessible from userspace. A standard library (i.e., libc) can utilize this entry point to implement syscall wrapper; we can also use this by hooking syscall for unmodified userspace applications/libraries, which will be implemented in the subsequent commit. This only supports 64-bit mode of x86 architecture. Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/x86/um/Makefile | 4 ++ arch/x86/um/nommu/Makefile | 8 +++ arch/x86/um/nommu/do_syscall_64.c | 37 ++++++++++ arch/x86/um/nommu/entry_64.S | 91 +++++++++++++++++++++++++ arch/x86/um/nommu/syscalls.h | 16 +++++ arch/x86/um/shared/sysdep/syscalls_64.h | 6 ++ 6 files changed, 162 insertions(+) create mode 100644 arch/x86/um/nommu/Makefile create mode 100644 arch/x86/um/nommu/do_syscall_64.c create mode 100644 arch/x86/um/nommu/entry_64.S create mode 100644 arch/x86/um/nommu/syscalls.h diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index b42c31cd2390..227af2a987e2 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -32,6 +32,10 @@ obj-y += syscalls_64.o vdso/ subarch-y = ../lib/csum-partial_64.o ../lib/memcpy_64.o \ ../lib/memmove_64.o ../lib/memset_64.o +ifneq ($(CONFIG_MMU),y) +obj-y += nommu/ +endif + endif subarch-$(CONFIG_MODULES) += ../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 := 32 +else + BITS := 64 +endif + +obj-y = do_syscall_$(BITS).o entry_$(BITS).o diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_syscall_64.c new file mode 100644 index 000000000000..5d0fa83e7fdc --- /dev/null +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +__visible void do_syscall_64(struct pt_regs *regs) +{ + int syscall; + + syscall = PT_SYSCALL_NR(regs->regs.gp); + UPT_SYSCALL_NR(®s->regs) = syscall; + + pr_debug("syscall(%d) (current=%lx) (fn=%lx)\n", + syscall, (unsigned long)current, + (unsigned long)sys_call_table[syscall]); + + if (likely(syscall < NR_syscalls)) { + PT_REGS_SET_SYSCALL_RETURN(regs, + EXECUTE_SYSCALL(syscall, regs)); + } + + pr_debug("syscall(%d) --> %lx\n", syscall, + regs->regs.gp[HOST_AX]); + + PT_REGS_SYSCALL_RET(regs) = regs->regs.gp[HOST_AX]; + + /* execve succeeded */ + if (syscall == __NR_execve && regs->regs.gp[HOST_AX] == 0) + userspace(¤t->thread.regs.regs); + + /* force do_signal() --> is_syscall() */ + set_thread_flag(TIF_SIGPENDING); + interrupt_end(); +} diff --git a/arch/x86/um/nommu/entry_64.S b/arch/x86/um/nommu/entry_64.S new file mode 100644 index 000000000000..e9bfc7b93c84 --- /dev/null +++ b/arch/x86/um/nommu/entry_64.S @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include + +#include +#include +#include + +#include "../entry/calling.h" + +#ifdef CONFIG_SMP +#error need to stash these variables somewhere else +#endif + +#define UM_GLOBAL_VAR(x) .data; .align 8; .globl x; x:; .long 0 + +UM_GLOBAL_VAR(current_top_of_stack) +UM_GLOBAL_VAR(current_ptregs) + +.code64 +.section .entry.text, "ax" + +.align 8 +#undef ENTRY +#define ENTRY(x) .text; .globl x; .type x,%function; x: +#undef END +#define END(x) .size x, . - x + +/* + * %rcx has the return address (we set it before entering __kernel_vsyscall). + * + * 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=$-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 = (unsigned long)task->stack; \ + __ptr += 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/sysdep/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; +#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 From patchwork Wed Apr 30 04:27:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079235 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=w6aSZJaV; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LOt1UQQ2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMN5mRCz1yWn for ; Wed, 30 Apr 2025 14:28:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+Rda5w8ftnYQQ6W3q5FgOQJiq+Hj9EhDJE6pWtJC4Ow=; b=w6aSZJaVfoHghLxd2s3U5VmowQ x5opkOT2Dn4AvuMHpKtSfIzqwuVCJuSaGGokDpvtP4bqpQozKXD2norhwkiE7L6/q87+7IG95vKrt svymFzSrvp8usL9yt1tDj0LUJBANqZbVXwOMMQHrHm4v7sKHnwyKXUU8WN4JRM69fDuU+t/2rkRJf gqPwsjNYTZRJnqDdLwFC8sMVpp39VtT9RfRFrph/seY9hTtJNskhZGksh3OG4+qC3PaQ7bcG0NDjl jDdAu276G6Sj9mVOuh8P2Adevm6zF84gtA0VFL9nZajwLUcGsYNQqGZ0gffRrhNNWQYw7Oc7DwjrV vvFpQThg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4B-0000000Bffs-1Nvh; Wed, 30 Apr 2025 04:29:03 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z31-0000000BfRP-06cu for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:27:52 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2295d78b45cso96735725ad.0 for ; Tue, 29 Apr 2025 21:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987270; x=1746592070; darn=lists.infradead.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=+Rda5w8ftnYQQ6W3q5FgOQJiq+Hj9EhDJE6pWtJC4Ow=; b=LOt1UQQ2he+Wp0H63f0jw9WotOxBuze9EB8F5SGx0Rka9A6yKskGpVvWR3fL6b5/kg DXAoLMdPQPhTO5vC7nNP31gxuHdu7LyANxmMkjy1KCV4mgOwvpeYXT1t6xrqQsb4RUWg RBbPYD0ZbTLZYFzoqGHYLi5ogoyA80Q/lpjIaa8yG5edTcHKpQQBJyY850TsLNgB0FW0 ylEvjEUP5wivOMuYbyZ7shOsHSxDdfP9MuoDawEsyH3pOiXGs306DyHAQKjodsjtJreL XupLsVwKODSief0yCMp5xYS3okY8Kg7+h+Czdxlqnw9GO4W4JO1pRVGsg2ibSsLqOkgv 98xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987270; x=1746592070; 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=+Rda5w8ftnYQQ6W3q5FgOQJiq+Hj9EhDJE6pWtJC4Ow=; b=YuPsUF1BSyKcCZsKO/bgg51hKKLNuap3bVQxB7FM3DtheggxGv3emIA9NanNOawQer E5WJ4vpqM5/zLowv00jL7cULXER+M+FekDNGa/rsPMm1O15QPPvQY621xdNI1LGZoG7V /gzFklQEl4T+nLwJ58b/04XwFR1pNF5bJ/ffN2OexLw1qQmyPB3IaPgUs2J+6iCwYrIg ecAmEvq3p8icnhyaYz18UQDPWESRjGrqAAV09P+a28H99Ul/48LP6gC5iJhDvLUT1siT huPOQP12LlGp2KlvO5wnqyPUFIw6CWiorAiuUoU+O7jxpsFsWkSYDOsrc5a2VhWPth1J 3IBg== X-Gm-Message-State: AOJu0Yygi18xXdd6WSJLv0f4kKtq2QDB3BzHT1MpoMuXeB2InTkw5UWy iqq1caxqy/0xhdfE+BcwFyJe6pJharLB6wQdETSm+OcNS4rrlyVk X-Gm-Gg: ASbGncvm5Fz/NbHzipiUMZBVoZhVM0f5unS/taEZ0VFVanhTutetw7d6ik1I/TDHif7 kvOEAKJPPgkSUp1tPDrOSyoBFxYYvRK8a9WBer72Crx3gna/q8GqrDgNF7U/6GfYhbI5ksuRyQ8 uu1vri1mKnKkdxNBxAdER1Ftn5e3CIBYytPhH55/MUWNSW7CrfNwPdqq3fXVxKH7+zjBSG7cynG NozGLh5aCw7r9CDt9VjIKeEdsXPza7fM577Ou4yw9hTPpR6qoCKYjmkF/atsGactRMr+T5w1TIE snVpurKjGLFeSddETEH8IWlO1Het+e8Iv6gHNTj7VmacJnoTL6FqfrhSMsB/hn5j/s8v5PF4ZcM qdfk1n5tW4Qw= X-Google-Smtp-Source: AGHT+IFM9+qSbHZo6PrAllTRnzE6ZKUFkumQZ/B0AYyUyUFgvdPZvBGr40PMIlqIRsils5Ezf29wWA== X-Received: by 2002:a17:902:e84b:b0:223:5c33:56a8 with SMTP id d9443c01a7336-22df581e52cmr18188695ad.35.1745987269925; Tue, 29 Apr 2025 21:27:49 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db50e7c1bsm112367585ad.107.2025.04.29.21.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:49 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 6F158E9481C; Wed, 30 Apr 2025 13:27:47 +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 v8 05/12] um: nommu: seccomp syscalls hook Date: Wed, 30 Apr 2025 13:27:11 +0900 Message-ID: <1a00eb90cbfa24befe9bdd5416a8fb837881deae.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250429_212751_065271_81060998 X-CRM114-Status: GOOD ( 23.39 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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. Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62a listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. 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/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 | 3 + 13 files changed, 164 insertions(+), 1 deletion(-) 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/kern_util.h index 00ca3e12fd9a..2c8c18bd5860 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 *, + void *mc); void um_idle_sleep(void); diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 152a60080d5b..7f6703869dde 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); +/* 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 7f050783885a..2b591e929eca 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c @@ -433,6 +433,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(); } 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 := os-Linux/ diff --git a/arch/um/nommu/os-Linux/Makefile b/arch/um/nommu/os-Linux/Makefile 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 := signal.o +USER_OBJS := $(obj-y) + +include $(srctree)/arch/um/scripts/Makefile.rules +USER_CFLAGS+=-I$(srctree)/arch/um/os-Linux diff --git a/arch/um/nommu/os-Linux/signal.c b/arch/um/nommu/os-Linux/signal.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 = (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 331564888400..6bfdfec8cbcc 100644 --- a/arch/um/os-Linux/Makefile +++ b/arch/um/os-Linux/Makefile @@ -21,4 +21,9 @@ USER_OBJS := $(user-objs-y) elf_aux.o execvp.o file.o helper.o irq.o \ main.o mem.o process.o registers.o sigio.o signal.o start_up.o time.o \ tty.o umid.o util.o +ifneq ($(CONFIG_MMU),y) +obj-y += seccomp.o +USER_OBJS += 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 = uml_reserved, + __userspace_end = high_physmem; + + struct sock_filter filter[] = { + /* 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=*/0, /*false-skip=*/1), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high == __userspace_end && IP_low >= __userspace_end) allow; */ + 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=*/0, /*false-skip=*/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=*/0, /*false-skip=*/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=*/1, /*false-skip=*/0), + BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW), + + /* if (IP_high == __userspace_start && IP_low < __userspace_start) allow; */ + 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=*/0, /*false-skip=*/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=*/1, /*false-skip=*/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 = { + .len = ARRAY_SIZE(filter), + .filter = filter, + }; + + err = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); + if (err) + os_warn("PR_SET_NO_NEW_PRIVS (err=%d, ernro=%d)\n", + err, errno); + + err = syscall(SYS_seccomp, SECCOMP_SET_MODE_FILTER, + SECCOMP_FILTER_FLAG_TSYNC, &prog); + if (err) { + os_warn("SECCOMP_SET_MODE_FILTER (err=%d, ernro=%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 e71e5b4878d1..9adc729c20bd 100644 --- a/arch/um/os-Linux/signal.c +++ b/arch/um/os-Linux/signal.c @@ -20,6 +20,7 @@ #include #include #include +#include void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *, void *mc) = { [SIGTRAP] = relay_signal, @@ -29,6 +30,7 @@ void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *, void *mc) = [SIGBUS] = relay_signal, [SIGSEGV] = segv_handler, [SIGIO] = sigio_handler, + [SIGSYS] = sigsys_handler, }; static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc) @@ -167,6 +169,11 @@ static void sigusr1_handler(int sig, struct siginfo *unused_si, mcontext_t *mc) uml_pm_wake(); } +__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); @@ -178,6 +185,7 @@ static void (*handlers[_NSIG])(int sig, struct siginfo *si, mcontext_t *mc) = { [SIGILL] = sig_handler, [SIGFPE] = sig_handler, [SIGTRAP] = sig_handler, + [SIGSYS] = sig_handler, [SIGIO] = sig_handler, [SIGWINCH] = sig_handler, 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 := 64 endif -obj-y = do_syscall_$(BITS).o entry_$(BITS).o +obj-y = 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-Linux/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 = mcontext.o +USER_OBJS := 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-Linux/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] = mc->gregs[REG_RIP]; + mc->gregs[REG_RIP] = (unsigned long) __kernel_vsyscall; +} diff --git a/arch/x86/um/shared/sysdep/mcontext.h b/arch/x86/um/shared/sysdep/mcontext.h index b724c54da316..15e9ff287021 100644 --- a/arch/x86/um/shared/sysdep/mcontext.h +++ b/arch/x86/um/shared/sysdep/mcontext.h @@ -7,6 +7,9 @@ #define __SYS_SIGCONTEXT_X86_H extern void get_regs_from_mc(struct uml_pt_regs *, mcontext_t *); +#ifndef CONFIG_MMU +extern void set_mc_sigsys_hook(mcontext_t *mc); +#endif #ifdef __i386__ From patchwork Wed Apr 30 04:27:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079236 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=o19OeGMk; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CVWJ/W/Z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMN4Nrrz1yMf for ; Wed, 30 Apr 2025 14:28:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Q5NKRA2Vd8iUo2TNfSXqtZxbhUvo/xKWVJfwrs+7skI=; b=o19OeGMk8w1lHmVD23ajLCeeia ysFs8aMH0UakSBru2/aRt/51AXd1OZc37kIeArPaGBd7sToPleK53asi3vLw1nuhxCqDM/gYs49AM K6ESOz13f/BVMQZNIOEmMy7i6zcH2mecb+R+AoIt++RR4uYCe9d0fTBZv05N8FCWdndu6G+SXGRq0 om5Yi5BOv148cJg/J7/rlcF9duIgiidNxXA61dOjbQmLuUx/9TG+YnaQV/NmpTn1pPUvGKGEwdA95 T/HIQ5wDleol4CvPKRRZOUXZ8FVa/NQMcVNfG8olndUIuUldZ3EwvRwroJ3lxKL7cCDtzVubEbQTC 10IUPnVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4B-0000000Bfg2-2eJo; Wed, 30 Apr 2025 04:29:03 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z32-0000000BfRi-3CBM for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:27:53 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-22409077c06so109264315ad.1 for ; Tue, 29 Apr 2025 21:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987272; x=1746592072; darn=lists.infradead.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=Q5NKRA2Vd8iUo2TNfSXqtZxbhUvo/xKWVJfwrs+7skI=; b=CVWJ/W/Z6YOqEQS6w//VLoeUyMrR4TZvh3FB0cYzawLSyu22HWV/oAhbABEwL2Lx0Q R3EvKe3GfcgsSd3N1FgmmoSpXa+Bhh8XQSpgbAbseGUbe5iyO3ZUV22ySaQL7gPvCP4n v2KWTwCHLM4U8lqdYMzLw+gegiW+wVM/Il+HVGra4gkfWv/XDjUx30WJ4eUQRkpPY3JU ILm+zxEqf5Otdd2iHiFD/HfYe5lkGpw129qa+wgLYM0ghGwWZtdMJrQpKJunikxmHuQn IdMFpb9ihy87PtA8T2CyZDTE2D0WAy5Y73oGm/IEcIyyG+qMZYshTVAcNbsgt/htx6do 6Ulg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987272; x=1746592072; 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=Q5NKRA2Vd8iUo2TNfSXqtZxbhUvo/xKWVJfwrs+7skI=; b=OxzgK9ejrkI+CSYk864qLYj+DP9eypxQqZJ0b956UoOsrgLx0+Aky6x7Luv0ImQHgo /lSfXz5zpy6kr6D2EAoFsCV0HL5EuvWvfbCX6H9CHf/vOVKhEj1Z+9llh8QU5aMG067V cWQw0TEW96XbsK7JFGoYz0mf5SL2BDTYAY3sZTfZjs/ls07ZEcb+Tbd43v+jfd5GAXvW +DrNim7ERyAbLgY3MNId59abAvpound7x36YcIkw2CxQpkvjsX3ieGTLaN8tCXpU8S7P o/YFpmTR7/tOCG3CsKDO3UWoSVs5N7CdwmRco/MaNLvGhY5GIedJbv8C1pLOs93tcG4d p6FQ== X-Gm-Message-State: AOJu0Yxf3T+cEbLwHyLbsdoyQWBXjs6RreFHR2Ix1Jh/24a3aH5iVE3p YFx4GiFFoFHyQaR14QqE32YfP3mu5UCvqp0qhpfUdfcpxPDajipeXUsVoLF1 X-Gm-Gg: ASbGncslS406ek7Gp6V3iJznOQqNFbYKCLt1uH/1sRRv6fI6XvDnlOD8IzaQ4SupsA6 PHJZRHwA1Ps0+UhWrBPzgRX0fFwwWgjJ7JGRa/2EA71vsej5GkUMbzAlqCnwlvGSHUVPWQbhijy v0hID501QRCjU44CJYzs/ZdBdPuduzndnvtzllTvE2oOR5paVk9pqie7JxoAlfUNoOkDHjIrfk4 oHTqYuBUEDEeiz4/l95XqJrSBwpGaACYKK7NbORF6kfcrRD5NwqsWpG8zEj1btpHwA5gFFRnNss tPkdbDMs5/sfBLgOEBk4jgX6YQ5zEWyxMf4jm6/Cg9MUcsSkg54pkLaIIZN2gEjsP3bT0IZQQEo CYON+VrLgCm0= X-Google-Smtp-Source: AGHT+IGOxIjchaID2CDqMQJI7v4ig2oBAAKA/o5gORT6xH9R/bvvse4aK4O3R8Prfqt9cmDnq/3Z6A== X-Received: by 2002:a17:903:298e:b0:224:1c1:4ac1 with SMTP id d9443c01a7336-22df358f9c2mr28149925ad.47.1745987271755; Tue, 29 Apr 2025 21:27:51 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db50e7a33sm112187705ad.146.2025.04.29.21.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:51 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id C7F08E9481E; Wed, 30 Apr 2025 13:27:49 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v8 06/12] x86/um: nommu: process/thread handling Date: Wed, 30 Apr 2025 13:27:12 +0900 Message-ID: <71d4afcd72f3ea4a513c012c8bc6db04419f57e9.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250429_212752_797699_D7EEDCAA X-CRM114-Status: GOOD ( 18.99 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 s [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62c listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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/um/os-Linux/process.c | 6 ++++ 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 ++++++++++++++++++++++++++++ 6 files changed, 76 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/ptrace-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; }; -#define arch_has_single_step() (1) +#define arch_has_single_step() (IS_ENABLED(CONFIG_MMU)) #define EMPTY_REGS { .regs = EMPTY_UML_PT_REGS } diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 8a615875d1a1..3ac01881e905 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -28,6 +28,9 @@ int unscheduled_userspace_iterations; void os_alarm_process(int pid) { + if (pid <= 0) + return; + kill(pid, SIGALRM); } @@ -45,6 +48,9 @@ void os_kill_process(int pid, int reap_child) void os_kill_ptraced_process(int pid, int reap_child) { + if (pid <= 0) + return; + kill(pid, SIGKILL); ptrace(PTRACE_KILL, pid); ptrace(PTRACE_CONT, pid); 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 += ../kernel/sys_ia32.o else -obj-y += syscalls_64.o vdso/ +obj-y += vdso/ +obj-$(CONFIG_MMU) += syscalls_64.o subarch-y = ../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 := 64 endif -obj-y = do_syscall_$(BITS).o entry_$(BITS).o os-Linux/ +obj-y = 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 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_64.c new file mode 100644 index 000000000000..c78c442aed1d --- /dev/null +++ b/arch/x86/um/nommu/syscalls_64.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2003 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) + * Copyright 2003 PathScale, Inc. + * + * Licensed under the GPL + */ + +#include +#include +#include +#include +#include /* XXX This should get the constants from libc */ +#include +#include +#include "syscalls.h" + +void arch_switch_to(struct task_struct *to) +{ + /* + * In !CONFIG_MMU, it doesn't ptrace thus, + * The FS_BASE/GS_BASE registers are saved here. + */ + current_top_of_stack = task_top_of_stack(to); + current_ptregs = (long)task_pt_regs(to); + + if ((to->thread.regs.regs.gp[FS_BASE / sizeof(unsigned long)] == 0) || + (to->mm == 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 long)]); +} + +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); +} From patchwork Wed Apr 30 04:27:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=2mjmO8CQ; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=jMu9acOT; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=G8BdMI3h; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMR1hFCz1yWn for ; Wed, 30 Apr 2025 14:28:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RhZelJwiTUJ/UkMrQlTULCdNhOyleWw7wnwmeZqJPjo=; b=2mjmO8CQkF9qDYEAzFZTvsKbQE E9JXQRUFg+6jlQZTfNGC34bCrL7YGaL6y9hHBE6A5ZWW27+ORjjHAXGAMCn80xIYRbMykrcr4iWqK tipQoCGe/LGMgEQOHWGfFktbzYt80u4cH4bcdReQD1p59KQLcfQ2E4yhl41OxC3PF3G57UjXYbWDk fAugGzmha8NR6D6mzGX/lcLsBwOEPLhKEKQMp+2yY4vzWM2EE98tf7nb9Q1c+3x0FXniPaYLGBBs+ Y/CmiF6kN6WNNXTZyygpzF3MS6j25M6wGVpHKrLy6BZrZq/DHkR41wZM9VulNdrm5bUASsbeCZj0j px4aCq5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4E-0000000BflN-1B3d; Wed, 30 Apr 2025 04:29:06 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z3P-0000000BfWx-1nkt for linux-um@bombadil.infradead.org; Wed, 30 Apr 2025 04:28:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=RhZelJwiTUJ/UkMrQlTULCdNhOyleWw7wnwmeZqJPjo=; b=jMu9acOT8S0sK8zSnEbhJ/4hSf VOzcZYuj9toNQNFLE2vxvOFfYPf3RPZX2YFrl4Ud7HNffJvMjzn1Gksly+FcYb4TM6/t0g06ncQhr u0aV6Mx6SHmsodvyhwybyFLUa6X7HQQJCrHqBg0N/wM2F7cEmpNGEJuAtdSnwNroU5wO8S2VGnx9z FdgmmQgk40rt51Rkav8XoW00ZU13GplB62H766GHNzVgJGS+Lmfk87+s6s5wPwHQZZzwpQ2dbZ25U AzMoLVJ9BBU84viGDycT51usi+qgnXfQWK8Au1eoIiCHhXnHEMP56wwTI6uMuuwwtJkWm5bbpvcu1 IVkS0epg==; Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by desiato.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u9z3A-0000000DgDM-2IOO for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:28:12 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-3035858c687so5745160a91.2 for ; Tue, 29 Apr 2025 21:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987275; x=1746592075; darn=lists.infradead.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=RhZelJwiTUJ/UkMrQlTULCdNhOyleWw7wnwmeZqJPjo=; b=G8BdMI3hqxXoBzbViBZM550TmUQHGUw8zmFm7holw8qEExvAZs5iNfKX06kM+IS4+w C5DBWA/RqVF7SvSozV5q89RewMoh01CJhiYH2vmtzzdD4yiEvvt9SK35vMpG6dkqxJm7 eDG/+MCBcM3K93/RtWCvOJ8KZJiTRpO34FGMXpHoK699lwneq5dn7saAg9i4LhIb70TM yStn/GBK47Fw7vSXbkTwk0bDj3Os5MNGy3vAzuvUXg/0MCa46kurY37BG6Q3WhoQU4Tg JvRKVKZmw7f/Uv5lBQ5nZq4Wy74z9lU9sRpAkWQpOpiypdde8eOiGEHZSOu4hBuKQWNE iqoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987275; x=1746592075; 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=RhZelJwiTUJ/UkMrQlTULCdNhOyleWw7wnwmeZqJPjo=; b=vZ0gg559hXkIaG2IPKH9AV8RXTJ0kfC+m1nSHVy0TsDU+ephFf8ZWplCEx0dumEYBn EijAPygo5BHvRe1VISIDPDdbb9/I+Zce5dMvC53fcyQvxxhhIi/7i71g71CipO7R03jL W/TuSVDS5fl+594/HzKCDYqmXYoJuMvSxYaC+0m5+v0+59yLbleVuWjlXWRfjYd9SJyJ s+Vv6gNVuaxxg2TDRC7BxClwCkcR8b5nJg7wKi6g3mcYMnykgDxglElxcbKSDOjeB27A ElP9nTiWFCn5ENlciLNILbtqjNObOSipLsVtwzW8QVALgWNk1r21FR8j+wuLJQaS/pzB o1jg== X-Gm-Message-State: AOJu0YyKDxXt6kwieErjOXFC0raABkypMCJMBExJ6Wg3qVSzhHw8wCm1 0JWrVAbnsCekk/7LeWXjYEed2lORQNPRjkQHaFssM6GnCcaWd//m X-Gm-Gg: ASbGnctA1iQuDZQvQ+oIcGg/Nmrc7oVh1xwVAZhjmyMK7qwBaOetv9SxbjClPTmcXuu fgLL/L9JXb0vytAlqFvan5u+8wNY4fg4Idqvc+3b3yKZsFeqUpbf3ScJ/9J2Gw0mUi4Epmy67zo QSSbPEwm/mWZY09GOFuxXpg7eZuaFaq5WuStGto1ycpeWT40j2kxIW2AZ8j/RzoQx3J+4uQG2hY j7sYmrB74HrZ0kEiReofquvrybD+rDQgohw9n2+ANRZW7ogzIEyLOP5wkYC+3Z9sBeVfgNI/5LP Ra9tXrrq4l8M/r2bs/JsDhlbv+m4pWUgXrMPUNbI0IMOzartP1BQ9KkYecABy6eizW2i0H5WZBn BO7R4Ous8CD4= X-Google-Smtp-Source: AGHT+IF7i/I3IdOLHAQ2T3n6rN/DkuQz7/uZDc2c33Jl4R9I8AWjlNgT7XTdUlU6shCJ7XEQ1alnEg== X-Received: by 2002:a17:90b:6d0:b0:2fe:b9be:216 with SMTP id 98e67ed59e1d1-30a3336ba48mr2266861a91.31.1745987275453; Tue, 29 Apr 2025 21:27:55 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a349e3c2csm566258a91.2.2025.04.29.21.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:54 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id CFEAFE94820; Wed, 30 Apr 2025 13:27:52 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v8 07/12] um: nommu: configure fs register on host syscall invocation Date: Wed, 30 Apr 2025 13:27:13 +0900 Message-ID: <3b21fc4fab514b550076b10e571a371dfee54a0d.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250430_052802_182669_0C1103F0 X-CRM114-Status: GOOD ( 21.11 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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. [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1031 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 | 20 +++++++++ arch/x86/um/nommu/do_syscall_64.c | 37 ++++++++++++++++ arch/x86/um/nommu/syscalls_64.c | 71 +++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+) diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 7f6703869dde..2e972ca55213 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -190,6 +190,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; /* 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 + void os_set_pdeathsig(void); diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 3ac01881e905..7806b51e38b3 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 @@ -155,6 +156,11 @@ int __init can_drop_memory(void) return ok; } +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 93fc82c01aba..dbab091892b3 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -28,6 +30,8 @@ #include #include "internal.h" +int host_has_fsgsbase; + static void ptrace_child(void) { int ret; @@ -278,6 +282,19 @@ void __init get_host_cpu_features( } } +static void __init check_fsgsbase(void) +{ + unsigned long auxv = getauxval(AT_HWCAP2); + + os_info("Checking FSGSBASE instructions..."); + if (auxv & HWCAP2_FSGSBASE) { + host_has_fsgsbase = 1; + os_info("OK\n"); + } else { + host_has_fsgsbase = 0; + os_info("disabled\n"); + } +} void __init os_early_checks(void) { @@ -293,6 +310,9 @@ void __init os_early_checks(void) */ check_tmpexec(); + /* probe fsgsbase instruction */ + check_fsgsbase(); + pid = 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_syscall_64.c index 5d0fa83e7fdc..796beb0089fc 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -2,10 +2,38 @@ #include #include +#include +#include #include #include #include +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 = rdfsbase(); + break; + case ARCH_GET_GS: + *arg2 = rdgsbase(); + break; + default: + pr_warn("%s: unsupported option: 0x%x", __func__, option); + break; + } + + return 0; +} + __visible void do_syscall_64(struct pt_regs *regs) { int syscall; @@ -17,6 +45,9 @@ __visible void do_syscall_64(struct pt_regs *regs) syscall, (unsigned long)current, (unsigned long)sys_call_table[syscall]); + /* set fs register to the original host one */ + os_x86_arch_prctl(0, ARCH_SET_FS, (void *)host_fs); + if (likely(syscall < NR_syscalls)) { PT_REGS_SET_SYSCALL_RETURN(regs, EXECUTE_SYSCALL(syscall, regs)); @@ -34,4 +65,10 @@ __visible void do_syscall_64(struct pt_regs *regs) /* force do_signal() --> is_syscall() */ set_thread_flag(TIF_SIGPENDING); interrupt_end(); + + /* restore back fs register to userspace configured one */ + os_x86_arch_prctl(0, ARCH_SET_FS, + (void *)(current->thread.regs.regs.gp[FS_BASE + / sizeof(unsigned long)])); + } diff --git a/arch/x86/um/nommu/syscalls_64.c b/arch/x86/um/nommu/syscalls_64.c index c78c442aed1d..5bb6d55b4bb5 100644 --- a/arch/x86/um/nommu/syscalls_64.c +++ b/arch/x86/um/nommu/syscalls_64.c @@ -13,8 +13,70 @@ #include /* XXX This should get the constants from libc */ #include #include +#include +#include #include "syscalls.h" +/* + * 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 = -1; + +long arch_prctl(struct task_struct *task, int option, + unsigned long __user *arg2) +{ + long ret = -EINVAL; + unsigned long *ptr = arg2, tmp; + + switch (option) { + case ARCH_SET_FS: + if (host_fs == -1) + os_arch_prctl(0, ARCH_GET_FS, (void *)&host_fs); + ret = 0; + break; + case ARCH_SET_GS: + ret = 0; + break; + case ARCH_GET_FS: + case ARCH_GET_GS: + ptr = &tmp; + break; + } + + ret = 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)] = + (unsigned long) arg2; + break; + case ARCH_SET_GS: + current->thread.regs.regs.gp[GS_BASE / sizeof(unsigned long)] = + (unsigned long) arg2; + break; + case ARCH_GET_FS: + ret = put_user(current->thread.regs.regs.gp[FS_BASE / sizeof(unsigned long)], arg2); + break; + case ARCH_GET_GS: + ret = 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 long, len, 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); From patchwork Wed Apr 30 04:27:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079247 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kKt2x7xH; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=laNTCaSV; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=F8UXLBmp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMR4yzHz1yVR for ; Wed, 30 Apr 2025 14:28:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0G7VVQnGQtrb3sGnx5GNm2Y3zP47y1QHGJfHFp/BsUc=; b=kKt2x7xHWCQvagLmG9D/Iz8/69 vdHSFPtbYoRSUBcx7RgGlW3HG2q9L7lAWKOP7rtUySwtfGVDDVxmYbQzJIooAHoPecLkrA+wox5FV oe2dOrHpN7Z3GVrgKI8f3o+ZvZKAx5UhgnVoXcj3jh8sM4lq+jbP4Hvvc12plGFOZGRP+3P2js9Vi P5VNaTbWKEFHaXkox2DiblyCJVGGF4PLF/U+G4Lysb1KVE5OvhvcubQIYeapCPK3oZNUXTRY4TD1t eQ4BLlMAD1fjHHTfbCMVExG5nbgFd6U2XQJJ84CpA+w59iuIN9hB4jtQxku5DejcRjgtUcvRky5zW 1UYGTbiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4E-0000000Bfmo-3uPG; Wed, 30 Apr 2025 04:29:06 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z3P-0000000BfWy-22KZ for linux-um@bombadil.infradead.org; Wed, 30 Apr 2025 04:28:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=0G7VVQnGQtrb3sGnx5GNm2Y3zP47y1QHGJfHFp/BsUc=; b=laNTCaSV21Y5WANtyvAiFtxuKL LdRypTd489CfU6DvxjCCvtQQ+vRW9GzEiyPZr7BbDPfClXYKe4ReyaHszlIzIYdVo9fSiVNJDr2ip hwJT+bcC3dWuISIQMRRtXzMRRF8pEPWTY5gdxzycqQqZwEthMVdI698+7Hc70i7B2LZO2PqLfeOUu rqF63KrFQZiiir/whW7rN3PJXO4y2KOIIv6E6lEx+h0v22os5m9dbmrocnWSq7rRgRoRtJy9+GdRU bULYCWZJS2D8kXg8AuhcMUbBob81MZKBtkahoxWZzhPcyhQeyAnDOs0CjQzatYnqB3gFnj5B129MI 5ZUZOOLg==; Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by desiato.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u9z3B-0000000DgDP-0nwK for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:28:13 +0000 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-af52a624283so527314a12.0 for ; Tue, 29 Apr 2025 21:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987277; x=1746592077; darn=lists.infradead.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=F8UXLBmpjYKFxkTxf64lnLZYGOO4KXv9VaAh+aXDcmCc2qFzGbFOcS74/OqUPLta6j GQwpdc40FRyHimldQN4CscT6WXGpQjOTPr7WsyCYgARmqUNrvH27MnZWr1m2WmEigpEW E0ubMaFOQNSW49SG2j5qXbi2AxgH3J2GRrJRJZNswLWU0eGpZ1IStEQo8MMbfm9rIJEO XOCB3gJ3OPIYzDo8zLwmeho1MBdR0phQiIX+wEwBQT3qKnf5T1EftCOuiLHRJsFUs2bt hVcFCwLv1YV6Y9J7PPSPOrvZeu1wNRugh5Y3vOCVfGFY4CmH9o9XwB+ALQsrtTnALqz0 KJOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987277; x=1746592077; 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=UPwCwKsdccjMXCyCHKQgYlnkEOEwaneCjjAi2K251GVRQTgcLyxcBiTn9l1f6D99p3 uc/dW3ihsqC6I7/Hf2+9X1s4LwJzQz2H+g0HIHzoXEXPXKYLWNZi6nSZgyRDR+oMQunh aRyWkFy/cbQce01/AuMi58CGyZvS3lKhZ4Zp1boW0SboDFPiGpVSuZDFH+qkVG6IcSy8 xHQ/jYZ5gaUWruQH0EYCOwzs6MjBfTrzCS117EY5S57yTex+F7glTrYlYcFFSpU5V3CX noTfy/PcHhpjuCnIWNT2HHpRHYFhDc/sDYEiFPll3aSLq65TyahzTpWI7IUlW12TZTA/ DgSg== X-Gm-Message-State: AOJu0YzKwwFw3X4rLAoADgtGY+sLJMsomiBL1TzdOPYurw+8XlNEr+yf /u1ET5st+rkEssSGDBalgxLEO5p2I2o50GAh/Wk/a+PO01PnM6GN X-Gm-Gg: ASbGncv7b7gwo5L0fm5A+uqZ1jY0kcRFe2bsTN5mNvzXQemRHNshSQBtMsirdA2v/zO /fECU1YEKmuIvvOZ29Lu1Ychb0kUvSJPS0Xx5owZDzDAym1igYurYVZyMIqQw8yAJRTTah6WU3u D0guRzFx/btC+DIWSnN7rrFgYmLrgfLymwVtcbJT5FEwt7xdA11/JNgbKJdxk+M+ovAyHeXmZA2 9/6aQsCPMdcsGxm1rBRQnTI6FbRUF2tk2OZFD44MFMy75Y+hK506g3F45RuYawmW1Xsfy2EbWhW ciK2P4cH7ZsupQBhCyb6VI3G4S3pGIMpB9qI6sk75Us+1p0rMpTwAz8IazcJRqoyR02gIlpIAUu 0mCswaD90DhQ= X-Google-Smtp-Source: AGHT+IECA9Apxbc6D2JhVwEUhYdUmhJiBYci0GxbrvHA3yJvjLnYDlridKGWIXBUNgsmhrFM8ye3SQ== X-Received: by 2002:a05:6a20:6f0a:b0:1e1:a449:ff71 with SMTP id adf61e73a8af0-20a8e173f9cmr2155932637.1.1745987277300; Tue, 29 Apr 2025 21:27:57 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74039a5bde6sm609398b3a.127.2025.04.29.21.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:56 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 52572E94822; Wed, 30 Apr 2025 13:27:55 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v8 08/12] x86/um/vdso: nommu: vdso memory update Date: Wed, 30 Apr 2025 13:27:14 +0900 Message-ID: <1670b88c2196a5fb2a6eed90c7a8714f03c040a7.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250430_052805_806152_35CC8408 X-CRM114-Status: GOOD ( 14.52 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:52e listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 static unsigned int __read_mostly vdso_enabled = 1; unsigned long um_vdso_addr; @@ -21,14 +22,24 @@ static int __init init_vdso(void) { BUG_ON(vdso_end - vdso_start > PAGE_SIZE); - um_vdso_addr = task_size - PAGE_SIZE; - um_vdso = alloc_page(GFP_KERNEL); if (!um_vdso) goto oom; copy_page(page_address(um_vdso), vdso_start); +#ifdef CONFIG_MMU + um_vdso_addr = task_size - PAGE_SIZE; +#else + /* this is fine with NOMMU as everything is accessible */ + um_vdso_addr = (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=%lx um_vdso_addr=%lx pg_um_vdso=%lx", + (unsigned long)vdso_start, um_vdso_addr, + (unsigned long)page_address(um_vdso)); + return 0; oom: @@ -39,6 +50,7 @@ static int __init init_vdso(void) } subsys_initcall(init_vdso); +#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) return IS_ERR(vma) ? PTR_ERR(vma) : 0; } +#endif From patchwork Wed Apr 30 04:27:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=QKOShYN1; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=dh9wd3AA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMP3zbTz1yWs for ; Wed, 30 Apr 2025 14:28:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mp6eKKbWpiSHyJXYBVOlGqFhgugHf5gGjyOnElsYIQ8=; b=QKOShYN19iYZsD4elJRw4L3Hz7 vVT3PV3aQiLrroWLx+Xv/KVl5I3BUbfrD5fSt9ZYwUnsTKavx0ESchnSb0Q6UjpjZCqMgZWHi/4vH sBX1HMUR9ezSmlc+8z8WRT7fW1D2552I3Y0v0tdiMxFyfpTTsHo1rKesHv4ncZNyQVpGrr1thmEVH 1JpLdYzONz3rSvX7TzgbmpoOJpt3H2LR7xnhx07IMMVv8PjO2TZSipJK4rN4v0bJ2+EGJpRGdXW2Y k0phtGR6u2mCxiBGBfszx9InKB5tV+B8RhiKd2pdZoOeU9bErglIfI9XXmZIETbhvYw/krMW951o9 /mSUJ8aQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4C-0000000Bfhh-20Iv; Wed, 30 Apr 2025 04:29:04 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z3B-0000000BfTm-0cjV for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:28:02 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-7369ce5d323so5752408b3a.1 for ; Tue, 29 Apr 2025 21:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987280; x=1746592080; darn=lists.infradead.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=mp6eKKbWpiSHyJXYBVOlGqFhgugHf5gGjyOnElsYIQ8=; b=dh9wd3AA1J/0wrWJWPtZVUXCNvVFIN1ZQa+Yadux8i+D3eRyJx+i8HQAifADu7GBOc Hr7kTLD4jzi32N19988g5uAcVSKbmttAV0101/rUSgCKGp/uwjL1KCfN0RD4gEryq6rB qFpPcYrYc9bsY0eVMwvF/rtT6cgoq9FAMZLRUXekpnvv8EDqKOrBPzcd3A4zqj5eyWVu TD8iYMCnDiAX9A+xFQ8Cixyq3zSlBucs5cQrsbRZT45wgnyI14QrAvHIuWrx0jpdAMQg Qg5UITRbWXOkx9oH8/AxJVcDxabcr/+XOggh/x74eo7Mn4T/XivW/UBCg9w9D57srqCd WnYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987280; x=1746592080; 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=mp6eKKbWpiSHyJXYBVOlGqFhgugHf5gGjyOnElsYIQ8=; b=A4t9QO1Oiy6ydx1VbaCuWxosY4jG1bhlYWKlTFoJM/EK1qw0YmG+mtJBF53IDp2MCh FZMjZ2QiWxK4vmA/d9JFIqTORBz+Z713ebNtV3PjNbC/35yHNsPf1+139Nz8Wi5k2rPC RTcjS2havavGd2BrjBO0r2dJwUlRgspNBcvTSqs3QWmBZQ59sm9X5/ejx9WWl5PotvX/ 8CvRv/6UI+naF7Kk/9jO91sGVTeI+ek5f1utErLwEmhlpNNfpuzD9GTGajRecG/QxXN+ M0O+JxBxnkh4i8PhTAP6PsWl6aOFQS1TX2Hs+UOG1sBHV1JcYMC5QO0JiEhJAplOb+3K L5Qw== X-Gm-Message-State: AOJu0YxZ7aWE/alWMiFf7HhKeDYJQAtktW/BdSTftMghFXpKe7/dQE8N M1XvyHK9C2ixJqJFw6Hh4ealzJyKqIUdEEfGlEOPDV+Nq68vjexd X-Gm-Gg: ASbGncvDeJcKgY3Mcy/zGOopLfDG4mu4FA/u31cFurVXVBRAbN/AL8Jt4hpHwzcqp9O 8XSZGkywdD8dTbGqEcQVdFxx1qOFr5LpusVls+J2EDDUfIuqtEtxCM1XKvO2fw7sTko7a/pxOhR 8oYwg1QsukGYtPKyD2BJrOcmDajoZkjcGi+9Y13JQhdAEaD3xVddt5Ln4rE5KgrfJzpDSBQqn5W ZnPaM2QGbXcwE2u6L5qgmiPV1orwXc+rAIZEUAIdh+qA7alhvosc6h9/saPLBb88kGvcSjRpm4B ZRmpcnpUCYonhXFFAGi2pStE2wdYTikzl/13R+DIGD2xkrzroW44SprU9agOBTz2HdnTtmvxp3B H6wCEEyVm/zE= X-Google-Smtp-Source: AGHT+IFs9TraF1kR6FW5u1Q5u6Tmlb0LDMb+CsM3q0Udn9dfC/0UdzNr3zkLiVA4e0ssPjXNHc5cNA== X-Received: by 2002:a05:6a20:d046:b0:1f5:8220:7452 with SMTP id adf61e73a8af0-20a87d4eb30mr2154035637.24.1745987280011; Tue, 29 Apr 2025 21:28:00 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b1b7efab4a5sm6348034a12.19.2025.04.29.21.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:27:59 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 98529E94824; Wed, 30 Apr 2025 13:27:57 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v8 09/12] x86/um: nommu: signal handling Date: Wed, 30 Apr 2025 13:27:15 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250429_212801_192146_8C49E079 X-CRM114-Status: GOOD ( 33.52 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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. Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:434 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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/kern_util.h index 2c8c18bd5860..85a4f154423b 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); void kasan_map_memory(void *start, size_t len); +#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 -obj-y := os-Linux/ +obj-y := trap.o os-Linux/ diff --git a/arch/um/nommu/os-Linux/signal.c b/arch/um/nommu/os-Linux/signal.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 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 = (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 = current; + struct faultinfo *fi = 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 = 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 struct. + * If the userfault did not happen in an UML userspace process, bad_segv is called. + * Otherwise the signal did happen in a cloned userspace process, handle it. + */ +void segv_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs, + void *mc) +{ + struct faultinfo *fi = UPT_FAULTINFO(regs); + + /* !MMU specific part; detection of userspace */ + /* mark is_user=1 when the IP is from userspace code. */ + if (UPT_IP(regs) > uml_reserved && UPT_IP(regs) < high_physmem) + regs->is_user = 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 = FAULT_WRITE(fi); + unsigned long address = FAULT_ADDRESS(fi); + + if (!is_user && regs) + current->thread.segv_regs = container_of(regs, struct pt_regs, regs); + + if (current->mm == 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 = handle_page_fault(address, ip, is_write, is_user, + &si_code); + else { + err = -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 = 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 == -EACCES) { + current->thread.arch.faultinfo = fi; + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address); + } else { + WARN_ON_ONCE(err != -EFAULT); + current->thread.arch.faultinfo = fi; + force_sig_fault(SIGSEGV, si_code, (void __user *) address); + } + +out: + if (regs) + current->thread.segv_regs = 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 == 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 = si->si_code; + err = si->si_errno; + if ((err == 0) && (siginfo_layout(sig, code) == SIL_FAULT)) { + struct faultinfo *fi = UPT_FAULTINFO(regs); + + current->thread.arch.faultinfo = *fi; + force_sig_fault(sig, code, (void __user *)FAULT_ADDRESS(*fi)); + } else { + pr_err("Attempted to relay unknown signal %d (si_code = %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_syscall_64.c index 796beb0089fc..48b3d29e2db1 100644 --- a/arch/x86/um/nommu/do_syscall_64.c +++ b/arch/x86/um/nommu/do_syscall_64.c @@ -48,6 +48,9 @@ __visible void do_syscall_64(struct pt_regs *regs) /* set fs register to the original host one */ os_x86_arch_prctl(0, ARCH_SET_FS, (void *)host_fs); + /* save fp registers */ + asm volatile("fxsaveq %0" : "=m"(*(struct _xstate *)regs->regs.fp)); + if (likely(syscall < NR_syscalls)) { PT_REGS_SET_SYSCALL_RETURN(regs, EXECUTE_SYSCALL(syscall, regs)); @@ -66,6 +69,9 @@ __visible void do_syscall_64(struct pt_regs *regs) set_thread_flag(TIF_SIGPENDING); interrupt_end(); + /* 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-Linux/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 +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] = (unsigned long) __userspace_relay_signal; +} + void set_mc_sigsys_hook(mcontext_t *mc) { mc->gregs[REG_RCX] = mc->gregs[REG_RIP]; diff --git a/arch/x86/um/shared/sysdep/mcontext.h b/arch/x86/um/shared/sysdep/mcontext.h index 15e9ff287021..0efe5ddf95af 100644 --- a/arch/x86/um/shared/sysdep/mcontext.h +++ b/arch/x86/um/shared/sysdep/mcontext.h @@ -9,6 +9,7 @@ extern void get_regs_from_mc(struct uml_pt_regs *, mcontext_t *); #ifndef CONFIG_MMU extern void set_mc_sigsys_hook(mcontext_t *mc); +extern void set_mc_userspace_relay_signal(mcontext_t *mc); #endif #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; /* Dynamically sized FP registers (holds an XSTATE) */ - unsigned long fp[]; + unsigned long fp[] __attribute__((aligned(16))); }; #define EMPTY_UML_PT_REGS { } From patchwork Wed Apr 30 04:27:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=bd1tK859; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=G3XO04C7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMP5mHvz1yWv for ; Wed, 30 Apr 2025 14:28:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=B/ZhA8POgOa1pDP88Eiedzl7Qg41tN4Rus19EAaNMog=; b=bd1tK859bdFoJD5hbGn48JKK44 nyMug9ytWExbUivPq5+FSA955bLHjpyLLTS8OLQJOJp1gri5hJ8HD7plo7mUUO0kBQ2d+r+YMOCgv E1Hj/fQnqwtgA6OUJTCnDDqcerkIEjtnZxScNyLnJJsj873/MZf/kYHb/T1ERsZBFjSqHU7syxQe/ KljH+ox/pVROv3DLCrfSqB+sJiE4qvaBSsDkiQVXLGRxC6HXJ/1eXd9lU649CtmW16HmtWVC+MYRn HMUU667dAj+PARByWRFmFWLXWRrsJLPm7sKjPeBC+kxDsvATbCOzULoO+/p+ktJdgxLMfPa9D2uQI klNBpmvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4C-0000000BfiO-3UKd; Wed, 30 Apr 2025 04:29:04 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z3D-0000000BfUL-2UA1 for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:28:04 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2255003f4c6so76263155ad.0 for ; Tue, 29 Apr 2025 21:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987283; x=1746592083; darn=lists.infradead.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=B/ZhA8POgOa1pDP88Eiedzl7Qg41tN4Rus19EAaNMog=; b=G3XO04C7Jj8OH2yU5AK/zVv38XCsp+Oq7zMXNpmBoGSJ+LPKAHqL9sb9k9ctq+gmSF bE8efSL/ovbno7Cr9AHRq/JVWux4H8YTMLWjnEpwtWsbgZhyPXNP/jUNvq81SafIJBpg VGr5aZh7UpbqiT/pPB1XSmaHR/Nzc7UCsFTw8rQ7QBmCQInpVpMtY2+6OpBoEVFQSAbm L9PgZ2fxCmS7okBKc3Cayc1Bppo936YgJte2nrienED0aOeusouKmw25Rpsxr+hilm2B DMX60+WL224PTZ5DTltbmp4Sv0cuT8dyArL6LbSks9DTuC/2F8HjCxZxUxbwECYkzxyJ Zf5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987283; x=1746592083; 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=B/ZhA8POgOa1pDP88Eiedzl7Qg41tN4Rus19EAaNMog=; b=SRcsvmt975zhWizkDi+8opFGRyq6sN6TyARegG74urfFLXmYk2uyPB+AIEUbB203CR qHAiLaF4nM6+NCcUQAC8AxN/AnPfznCzXoHeV1wTRP0JaV3DIm77toV69+GQrGvv5DkB PeO0miOLPlSlcSy5Nr9yG7mRoygFM+4V7dcRDrzKfDhUFOtpZNr8xv022liLogTJF5mr uBxn0aVAhnCf3pguU/bzRiiC0KTjikO08QtTVIn64/BYkWcsDhpJKZvdN6DgqwNmrxwt bypIDHCqIl01C8mB6JDQwMHKTRSZ/ETl3QPFOn5P9r8KM5nc4XWJt4G2p2/4vixsDnca 9Qnw== X-Gm-Message-State: AOJu0Yz4UA/xXCxsP9pmdIzMYijh+HeBMc1JzNH/VoIWSlZ1cXAa5EYq KSLeaaDd3MPbW0G2EY4q30IZSRElBP5i8IJJ9bVErla5mJCVnx+V X-Gm-Gg: ASbGncsfv7zSqvNM10Av/Gr8LMSd4vYigSiNKAND3+E9WgQy1ze/SJQJL7Pb8w+TXCV NoD01OycHLNX/9eIqDWeXalIcR3LaJ1N/4Gdd01NgRu/C27Iv/E9IgsX3o5GaLVchWHPY0Yo0HX n9XP3kfjzUsG+XkujTcqiStCsmqFqBwIP7cvI1Sv6RPW++/tdOQToTNxDNAA7VJCXsbA4mzx9mV xkNwGZagNIvDjwvoGiIGUkAnPToQlvcsX6T8A8P9yEdSaepS8BqC+wswQJ7caohS29gG3pDstbx LJfKYOqdyne5lD/iCySQ8gNoSsVDaGE/2fPKI7NgEsMb0SecmFwpQ+h2dAJyd4lYtln8uQ5E/c+ N9djVOgRqREAtqnTK+9tjhA== X-Google-Smtp-Source: AGHT+IHLnJV1jRxDa8YUV/nZ0brQ2Gx6YopooEOeWXq2tdOwSnZ7t3052ntTYHbm7mId/W8e0+yiSA== X-Received: by 2002:a17:902:d58b:b0:224:26fd:82e5 with SMTP id d9443c01a7336-22df35caa68mr29021325ad.48.1745987282966; Tue, 29 Apr 2025 21:28:02 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db51062casm111526675ad.208.2025.04.29.21.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:28:02 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 33EA2E94826; Wed, 30 Apr 2025 13:28:00 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH v8 10/12] um: change machine name for uname output Date: Wed, 30 Apr 2025 13:27:16 +0900 Message-ID: <64d60cf0ac06f49a4ff7f79df4c60e364d11464f.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250429_212803_629204_3DA40CD7 X-CRM114-Status: GOOD ( 10.56 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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(-) Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:632 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 fcf4bb915a31..722a3bd03f24 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -155,6 +155,12 @@ export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) $(CC_FLAGS_ CLEAN_FILES += linux x.i gmon.out MRPROPER_FILES += $(HOST_DIR)/include/generated +ifeq ($(CONFIG_MMU),y) +UTS_MACHINE := "um" +else +UTS_MACHINE := "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); } void setup_hostinfo(char *buf, int len) From patchwork Wed Apr 30 04:27:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079243 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=QUyWthC5; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=L4XgA0nV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMQ1Hnmz1yWy for ; Wed, 30 Apr 2025 14:28:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hHaVuq4Zwe9gLJutKzuA+VGXPhun5t5NN63IcV8lR68=; b=QUyWthC5Tpf8q+V91UIuOlttpa ILP6rdjCz3tg0ZTHkjl7nMyCZ0gmTLOB94PsWRaq4NnvUyMEeGaj8LSscYffzx/sQZeOMBz3QM+P0 n9R+9IvndoCLlLuAi/3GetVVxXxHB5ZaA30KAEsD+XkchE2y8hP5yV5sthISwscvDwNKzb/iaJqUP HD9ZfNbTNX+pkA9igOM163R3GKuOr1lrKhupIsDBzQZnV68WLGpJ7GSZLniVNdIMVB7KG1cYIshDG cpFmBNzpVK7Y1ZlgO2MzQPFsuC+0WhiWNOnwaJR12IiHQFnB2udTLqnwskBMzDLoM3Y2+Ja7mv7Mh IpJKPtUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4D-0000000Bfit-0eCJ; Wed, 30 Apr 2025 04:29:05 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z3G-0000000BfUk-1lPg for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:28:07 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-73bf1cef6ceso6865130b3a.0 for ; Tue, 29 Apr 2025 21:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987285; x=1746592085; darn=lists.infradead.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=hHaVuq4Zwe9gLJutKzuA+VGXPhun5t5NN63IcV8lR68=; b=L4XgA0nVdEGfL4jHVGdbDcaE4TCLjozYNZpYEmSbPl0kjCZVbDrbq26OLwaS3IalMb R8kg1bymsPK1ULCHcL1TRBViuKotbxg5oxR6/41+31qiCp7pwgok58hJ1M5ppRxQYpHR zrJt9xHU23ewcJwZUyvgDaMLq7AW5iJWDAAnN6la4u20zMu4391jlX3SevuOGLWFKcFE ugfHeH1wY+TECQjK1ykedL6UzYLxniusVMpu0gfl2Q80HImte3gjPbXR1qbtLz0bFvPz o3IcXiGpM5zHjJf7vD8219hTSpbnsarLKf1U+5nkiIsKdMojyfxDM6DGQK7UI9w6beW6 cdYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987285; x=1746592085; 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=hHaVuq4Zwe9gLJutKzuA+VGXPhun5t5NN63IcV8lR68=; b=Wf6oYTqSeu/vgK3+Kh7HLzubrvV5Mjre0+9xRL6b297joim3wDzxc/kkOIEkq+uQxl ZqzIIB13c37F7ZlxEURFtr/WcCp5RshTWdlyahaoHlUbteEpq2lNTkoPLOIIpzsybvFU JGGATM7ZvD7yMZWicv3tq/IGTVzyZQnOA5KXfCr/qcPHtzRL44tDbr6/11NhhORiFiAg X50giicMmYnFUK51APh5JcVnYQrdsorGYKK6nHSlXK1aj4eP55boQDMTSlzRJ9Xbrifl YW8vbaPgn+bnJFVhymUSrYA3smT6Gt9kjDxGCuOXssZNMGUhllRuh9L5LFcdxaWq2Gj4 ugJg== X-Gm-Message-State: AOJu0YyHK42xiWE2g0TkkDTdAC3XGym5wHMH31PT3gPfWYvAR4u6rfwF YBGaPYSyINdxkxZeoGlhxXHIop6Fqnww0UFbZlOBGNgvz149a0OR X-Gm-Gg: ASbGncvMP435gcqwku2NSzHLjevBGqTjYgzkin9JgOn295EW94YwBBlg9BDw9T3TG7N YYAR6R6lX10Nx17pTnSR2Y93hpiy0Ob+hg6QlabTjKbi2vN60A1lhjaPo5a2k8Jd1QxVI74nlKU Do0z9LgyqRBuHCAfdmzuzZu8PKRQbORyrpNGXPJbY35oStgrJu2Anf/jEMSoFS7iCd6Y/7EV8nQ PiIGl7NjIIJ/VkEeLOvPd/zmM7USbQNvqyGY3+zxqD3YFBn1rfWZuk39SbusSdVX90txTj3v0xP czavh0bOz0G8+t5qB8ZLQtq4sbIbD9fUkoxz7r7BsEHv/bdowg8ju43pJ8FPEoRoeZ7cyyHNCvG T/GeAxTDufbY= X-Google-Smtp-Source: AGHT+IFcLglsLp35fpVY5aAm/RiBDEo8ho6SSo1+56LkhDY+q9Ov9DaIySaSK81WgYdSZ4+KxLTB2A== X-Received: by 2002:a05:6a00:22d4:b0:736:8c0f:7758 with SMTP id d2e1a72fcca58-7403a784350mr1721050b3a.10.1745987285190; Tue, 29 Apr 2025 21:28:05 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-740399230e6sm648218b3a.68.2025.04.29.21.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:28:04 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 798A2E94828; Wed, 30 Apr 2025 13:28:02 +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 v8 11/12] um: nommu: add documentation of nommu UML Date: Wed, 30 Apr 2025 13:27:17 +0900 Message-ID: <254209f7e93f7fcdbc16853cad9f0a0ab34c8032.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250429_212806_459490_F57D1AD0 X-CRM114-Status: GOOD ( 23.93 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This commit adds an initial documentation for !MMU mode of UML. Signed-off-by: Hajime Tazaki --- Documentation/virt/uml/nommu-uml.rst | 177 +++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 178 insertions(+) create mode 100644 Documentation/virt/uml [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42d listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This commit adds an initial documentation for !MMU mode of UML. Signed-off-by: Hajime Tazaki --- Documentation/virt/uml/nommu-uml.rst | 177 +++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 178 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..2034ba4d397a --- /dev/null +++ b/Documentation/virt/uml/nommu-uml.rst @@ -0,0 +1,177 @@ +.. 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 ? +================ + +- 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 ? +============== + +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_vsyscall`` +- call handler function in ``sys_call_table[]`` and follow how UML syscall + works. +- return to userspace + + +What are the differences from MMU-full UML ? +============================================ + +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 +======= + +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 +================ + +:: + + make ARCH=um x86_64_nommu_defconfig + make ARCH=um + +will build UML with ``CONFIG_MMU=n`` applied. + +Kunit tests can run with the following command:: + + ./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_MMU=n + +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 +========================= + +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=$(docker create ghcr.io/thehajime/alpine:3.20.3-um-nommu) + docker start $container_id + docker wait $container_id + docker export $container_id > alpine.tar + docker rm $container_id + + mnt=$(mktemp -d) + dd if=/dev/zero of=alpine.ext4 bs=1 count=0 seek=1G + 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=`` to the UML command line:: + + ./vmlinux ubd0=./alpine.ext4 rw mem=1024m loglevel=8 init=/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 +======================= + +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 +========= + +The below shows an example of performance measurement conducted with +lmbench and (self-crafted) getpid benchmark (with v6.13-rc5 uml/next +tree). + +.. csv-table:: lmbench (usec) + :header: ,native,um,um-nommu(s) + + select-10 ,0.5569,27.0149,2.9772 + select-100 ,2.3964,26.9242,3.8947 + select-1000 ,20.8101,39.6842,12.8161 + syscall ,0.1735,25.7706,2.6997 + read ,0.3488,25.7922,2.7923 + write ,0.2861,26.5560,2.7961 + stat ,1.9171,36.2893,3.2678 + open/close ,3.8475,62.2847,6.3909 + fork+sh ,1159.0000,5230.3333,409.1786 + fork+execve ,535.3000,2075.8333,135.4074 + +.. csv-table:: do_getpid bench (nsec) + :header: ,native,um,um-nommu(s) + + getpid, 172 , 24979 , 2691 + +Limitations +=========== + +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 +================================ + +- NOMMU UML (original code by Ricardo Koller) + - https://static.sched.com/hosted_files/ossna2020/ec/kollerr_linux_um_nommu.pdf diff --git a/MAINTAINERS b/MAINTAINERS index 8e0736dc2ee0..6738c3fc1256 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -24743,6 +24743,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 From patchwork Wed Apr 30 04:27:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 2079242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=HgUetcBi; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=MW8Vq6Bt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZnPMQ2FmYz1yX0 for ; Wed, 30 Apr 2025 14:28:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rT31LZBxKQU6eu4tlFml+AuOML692n2PMZhnY9YLrtA=; b=HgUetcBiViQa7czCWRZUWxBZ9h 0dnUmKXNCKwptMsm3sxUwz40vXllAQ8K7JtAQ6wWWq69d3JE/2foskgjpVyPNEhaVdqwIDdWQPcwy Flv/RJKSMJIrS+Wf2k3AEJF3dqJ913c/+tiHrE49X/ou6o+gWTY90sbPElcxoiGx7VwyoHK6rg1VT BiBE7iW2qeEgpgM9k1dyHQs6lrcj2riYNf37otYkgDAl4eZv9Q94Iic0CVHkIRFWE1ru0ceiVxKbg qWsW5VSd3o6OYiQryJfUXFxlzJBimUbm27Whq2jJYNpyXs/yy+X/QfHcO/br6sz5ACQCuR3vyXZ9C a8D2eenw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z4D-0000000Bfjc-2Jid; Wed, 30 Apr 2025 04:29:05 +0000 Received: from mail-pj1-f41.google.com ([209.85.216.41]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u9z3I-0000000BfV7-39pW for linux-um@lists.infradead.org; Wed, 30 Apr 2025 04:28:09 +0000 Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-301302a328bso9391019a91.2 for ; Tue, 29 Apr 2025 21:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745987287; x=1746592087; darn=lists.infradead.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=rT31LZBxKQU6eu4tlFml+AuOML692n2PMZhnY9YLrtA=; b=MW8Vq6BtNt+wn66s6tw9tAfrFA3J82/aslyl9p6v90U9qQOYQqNilxIeuv62YACAnD 727T0GJaVIjktAothLwpbkDJ6AuWKv1JAV6vFQEGnK9s4S8qQJXi4kGAqGY30yD5iCTr n8yO4pqZv/7a1bJIDjJtUcpx7IEqx9LSe0+MLrvEj3P4aCilXsma9ZfM6sMx5RQcdDSY bGhKPqglv2esBZbvDLYwlE/A99fdxEpM/RJw2K8v7P4JaEHx9N8x3Kt+wk8N3x3bqu7O Zzy8GJodZ4OBsBhaGcvogMVQzu/mTBTFef0JdBBcroYBLuJVmWpNvpX5XReq+URcr67K /7Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745987287; x=1746592087; 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=rT31LZBxKQU6eu4tlFml+AuOML692n2PMZhnY9YLrtA=; b=AlhW88Zq7PT2uCfi4n8E8BXqp0j1J/fwvVBOucBdS8+fUqKJbAE3SHSIR/OcuQxzaU VfRljXwLx4HNokx05LsBpsjVYaXI6pNqy+P4h/i47jiZwS1Y5DVqlQixxOmNpxqjBYga OiBJd3e+Ew1jLIs0Q2MDAknXWcD6qE3kfJgnOXFx0CoTQvBZAYhN3JZqHLAbv6C7Mwdm 0ogOXnYQ0lL0+jAPtU6SirsGl3punTuWoPSKq6qZgshBAvCHTX1iDaYEv+d4WZ1ylsIL CAJY/lCcxum3VlciLelUMQDaV1Mo7sn0s6tG0gvGU00/Vd0lfWVktil4/sPcsWND5CKR 72eQ== X-Gm-Message-State: AOJu0YyBoU2WLVhgImyoryEIKh+bPpyBG4moNHRAIbC1cIgvhZm4T6in 77qCnKRg/D+Gaj+Zo/2iLgjIsKbR/IDAjQt+4otO0F6Q6UANg0RH X-Gm-Gg: ASbGncvzpMV6OJd3Oye0aOaHWAyeLp+vr7/+KbrtuK1hs9zy5Tr09Se61Pogbmv+aTM BhbJVm1vEVTuy9iRRT/qYMsBzBxySFq4E+JKMt1eTimICaer9IU8A1LO/WQnJZaVOlX1iyg8iVJ nibSvBGAkWGjkFefX5pSgBfk1xQoVm4fVyc4nBg+geo6t4l9HgEZLHSmNnEPL3ZuXDBh3GaAm88 FgdL73DBQhSHZByltiqosczp2xQ1VZVrTilD4CVZh8oOCHWHcsxMKTp2QTQQuMYAaoYtiRcANYh LxHsT1n2HX/432ipl1OOjT4gNAXoxLt2DO8tn7XaIT/PvjVG4tPa2JUzPdG0+un2rMYKPVjpya/ YQjazOJ/Gc0E= X-Google-Smtp-Source: AGHT+IHs8ctUZrSNL4gP9gYydAnVaHBNQJH8vTsp9SOtrT3bTdbngoqV9WtXcIXTZkQTZdyv3JUqTQ== X-Received: by 2002:a17:90b:1f8e:b0:2f4:432d:250d with SMTP id 98e67ed59e1d1-30a33302091mr2229467a91.21.1745987287552; Tue, 29 Apr 2025 21:28:07 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a34a1113csm493273a91.22.2025.04.29.21.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Apr 2025 21:28:06 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id EFAB9E9482A; Wed, 30 Apr 2025 13:28:04 +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 v8 12/12] um: nommu: plug nommu code into build system Date: Wed, 30 Apr 2025 13:27:18 +0900 Message-ID: <5a59722b1cab960187461701df76d6f4d3f1249f.1745980082.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250429_212808_789196_261FE3C1 X-CRM114-Status: GOOD ( 13.28 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 | 64 ++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.216.41 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [thehajime(at)gmail.com] 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [209.85.216.41 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [209.85.216.41 listed in sa-accredit.habeas.com] 0.0 UPPERCASE_50_75 message body is 50-75% uppercase 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.216.41 listed in wl.mailspike.net] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [209.85.216.41 listed in bl.score.senderscore.com] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 | 64 ++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 arch/um/configs/x86_64_nommu_defconfig diff --git a/arch/um/Kconfig b/arch/um/Kconfig index 79509c7f39de..84b2ee7129ae 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 config MMU - bool + bool "MMU-based Paged Memory Management Support" if 64BIT default y config UML_DMA_EMULATION @@ -191,8 +194,15 @@ config MAGIC_SYSRQ The keys are documented in . Don't say Y unless you really know what this hack does. +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_64_nommu_defconfig new file mode 100644 index 000000000000..c2e0fb546987 --- /dev/null +++ b/arch/um/configs/x86_64_nommu_defconfig @@ -0,0 +1,64 @@ +CONFIG_SYSVIPC=y +CONFIG_POSIX_MQUEUE=y +CONFIG_NO_HZ=y +CONFIG_HIGH_RES_TIMERS=y +CONFIG_BSD_PROCESS_ACCT=y +CONFIG_IKCONFIG=y +CONFIG_IKCONFIG_PROC=y +CONFIG_LOG_BUF_SHIFT=14 +CONFIG_CGROUPS=y +CONFIG_BLK_CGROUP=y +CONFIG_CGROUP_SCHED=y +CONFIG_CGROUP_DEVICE=y +CONFIG_CGROUP_CPUACCT=y +# CONFIG_PID_NS is not set +CONFIG_CC_OPTIMIZE_FOR_SIZE=y +# CONFIG_MMU is not set +CONFIG_HOSTFS=y +CONFIG_MAGIC_SYSRQ=y +CONFIG_SSL=y +CONFIG_NULL_CHAN=y +CONFIG_PORT_CHAN=y +CONFIG_PTY_CHAN=y +CONFIG_TTY_CHAN=y +CONFIG_CON_CHAN="pts" +CONFIG_SSL_CHAN="pts" +CONFIG_UML_SOUND=m +CONFIG_UML_NET=y +CONFIG_UML_NET_ETHERTAP=y +CONFIG_UML_NET_TUNTAP=y +CONFIG_UML_NET_SLIP=y +CONFIG_UML_NET_DAEMON=y +CONFIG_UML_NET_MCAST=y +CONFIG_UML_NET_SLIRP=y +CONFIG_MODULES=y +CONFIG_MODULE_UNLOAD=y +CONFIG_IOSCHED_BFQ=m +CONFIG_BINFMT_MISC=m +CONFIG_NET=y +CONFIG_PACKET=y +CONFIG_UNIX=y +CONFIG_INET=y +CONFIG_DEVTMPFS=y +CONFIG_DEVTMPFS_MOUNT=y +CONFIG_BLK_DEV_UBD=y +CONFIG_BLK_DEV_LOOP=m +CONFIG_BLK_DEV_NBD=m +CONFIG_DUMMY=m +CONFIG_TUN=m +CONFIG_PPP=m +CONFIG_SLIP=m +CONFIG_LEGACY_PTY_COUNT=32 +CONFIG_UML_RANDOM=y +CONFIG_SOUND=m +CONFIG_EXT4_FS=y +CONFIG_REISERFS_FS=y +CONFIG_QUOTA=y +CONFIG_AUTOFS_FS=m +CONFIG_ISO9660_FS=m +CONFIG_JOLIET=y +CONFIG_NLS=y +CONFIG_DEBUG_KERNEL=y +CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y +CONFIG_FRAME_WARN=1024 +CONFIG_IPV6=y