From patchwork Fri Sep 22 22:37:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1838456 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=elO34kG9; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=sipsolutions.net header.i=@sipsolutions.net header.a=rsa-sha256 header.s=mail header.b=LSisxhSq; 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 4RsnJZ045Qz1ynF for ; Sat, 23 Sep 2023 08:39:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=niPMJN8pL9cMrhl20oaYMMnLPXDrwF/KzeM5NakJ7Q8=; b=elO34kG92ImXpu +NLQ/eUFqegJnq38NpNV0uPB/fdVysw0h0fSLzSGIZeZ6ne2pVUgYBTxV4pblql3vazgpbD4Gm9D/ bi/VS5sbmRDHqc9Cgt+opEkxhHSqdYacQSdetE03mUPEQV0l748PIgChbBTCUbbt8SGIZ/SzGaYON nIU7Z5RkRvlCR9yBrCG2kjJ755GGVeTBPEu8jxyinpu8r0/vTePomDPAluLfwJ4rPvQoeVey6Wd/r yorFhnktuZu09wOCBKebQrJLtJlWWv9qVObeXT5QntlKl66COpu+NK5DVFxmwmNWbXnZ8wNloF5Na xL88waAObgqwi85rjSfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qjoo6-009vXn-12; Fri, 22 Sep 2023 22:39:30 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qjoo2-009vWI-2Z for linux-um@lists.infradead.org; Fri, 22 Sep 2023 22:39:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=d15QR+C/cKPE7lUbgEdFsX9RQUItxjtiuUeFnxwv4OE=; t=1695422363; x=1696631963; b=LSisxhSqvhU4ISvsuEQsdN61Rubq4poNbbie43LnuNG1OgQ hEzzsEizbWCMtluCG8M88n3fj1gyvTKquPjViSlzKwK2X+j7wAAbjTM+pICRUb0+uDtpG7pUOdNQX GVyLz8aUtA4oVLJxB0AIdTFgcXnUdT2XA28P34btUgHPrEM2xUMfCgZh7m7t58zIpTvDlN1g/yJon 5UdsIV9BwwLtMfl1LnzbF0/DIcKZk4u5WzdW15eknfbsgO1+iLx7cZ34eZj1urz7N3rTDYuM1wMb2 8KxBP0ui8WfoGyggwAjKet0BrM3tDgXdWEU9UvoDyWz8WHOvnrtj7n+lBZegjKpA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1qjonw-00FtWi-2h; Sat, 23 Sep 2023 00:39:21 +0200 From: Johannes Berg To: linux-um@lists.infradead.org Cc: Anton Ivanov , Johannes Berg Subject: [RFC PATCH 1/3] um/x86: remove ldt mutex and use mmap lock instead Date: Sat, 23 Sep 2023 00:37:39 +0200 Message-ID: <20230923003737.97896a6a5213.Ibb36a758aa737a028eea3a73ed8718bf18109b99@changeid> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230922223737.1206223-4-johannes@sipsolutions.net> References: <20230922223737.1206223-4-johannes@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230922_153926_884237_198CA2D6 X-CRM114-Status: GOOD ( 14.76 ) X-Spam-Score: -0.2 (/) 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: From: Johannes Berg There's really not much value in having this as a separate lock, and having it makes it harder to clean up the init_new_context() semantics to not rely on 'current', even if dup_mm() is really only ca [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 From: Johannes Berg There's really not much value in having this as a separate lock, and having it makes it harder to clean up the init_new_context() semantics to not rely on 'current', even if dup_mm() is really only called with 'current->mm' as the source today. Replace the locking accordingly with mmap read and write lock, and remove it from init_new_ldt() entirely since it already holds the source lock. Signed-off-by: Johannes Berg --- arch/x86/um/asm/mm_context.h | 1 - arch/x86/um/ldt.c | 14 ++++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/arch/x86/um/asm/mm_context.h b/arch/x86/um/asm/mm_context.h index dc32dc023c2f..2b1a76a87e14 100644 --- a/arch/x86/um/asm/mm_context.h +++ b/arch/x86/um/asm/mm_context.h @@ -25,7 +25,6 @@ struct ldt_entry { typedef struct uml_ldt { int entry_count; - struct mutex lock; union { struct ldt_entry * pages[LDT_PAGES_MAX]; struct ldt_entry entries[LDT_DIRECT_ENTRIES]; diff --git a/arch/x86/um/ldt.c b/arch/x86/um/ldt.c index 255a44dd415a..6b8e368f779c 100644 --- a/arch/x86/um/ldt.c +++ b/arch/x86/um/ldt.c @@ -65,7 +65,7 @@ static int read_ldt(void __user * ptr, unsigned long bytecount) bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES; err = bytecount; - mutex_lock(&ldt->lock); + mmap_read_lock(current->mm); if (ldt->entry_count <= LDT_DIRECT_ENTRIES) { size = LDT_ENTRY_SIZE*LDT_DIRECT_ENTRIES; if (size > bytecount) @@ -89,7 +89,7 @@ static int read_ldt(void __user * ptr, unsigned long bytecount) ptr += size; } } - mutex_unlock(&ldt->lock); + mmap_read_unlock(current->mm); if (bytecount == 0 || err == -EFAULT) goto out; @@ -146,7 +146,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int func) goto out; } - mutex_lock(&ldt->lock); + mmap_write_lock(current->mm); err = write_ldt_entry(mm_idp, func, &ldt_info, &addr, 1); if (err) @@ -201,7 +201,7 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int func) err = 0; out_unlock: - mutex_unlock(&ldt->lock); + mmap_write_unlock(current->mm); out: return err; } @@ -305,9 +305,6 @@ long init_new_ldt(struct mm_context *new_mm, struct mm_context *from_mm) long page, err=0; void *addr = NULL; - - mutex_init(&new_mm->arch.ldt.lock); - if (!from_mm) { memset(&desc, 0, sizeof(desc)); /* @@ -334,7 +331,6 @@ long init_new_ldt(struct mm_context *new_mm, struct mm_context *from_mm) * i.e., we have to use the stub for modify_ldt, which * can't handle the big read buffer of up to 64kB. */ - mutex_lock(&from_mm->arch.ldt.lock); if (from_mm->arch.ldt.entry_count <= LDT_DIRECT_ENTRIES) memcpy(new_mm->arch.ldt.u.entries, from_mm->arch.ldt.u.entries, sizeof(new_mm->arch.ldt.u.entries)); @@ -353,8 +349,6 @@ long init_new_ldt(struct mm_context *new_mm, struct mm_context *from_mm) } } new_mm->arch.ldt.entry_count = from_mm->arch.ldt.entry_count; - mutex_unlock(&from_mm->arch.ldt.lock); - out: return err; } From patchwork Fri Sep 22 22:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1838455 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=hTJEbAjE; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=sipsolutions.net header.i=@sipsolutions.net header.a=rsa-sha256 header.s=mail header.b=HMlU3VlB; 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 4RsnJZ09RYz1ypP for ; Sat, 23 Sep 2023 08:39:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rCMaQVSp2NOfqyCY65GXz9pEyZfvROyfIlmngC+gcX0=; b=hTJEbAjECNbeye W3RCKAuvM1cehhdZmHRLRUwO51Bv7cPDuZKOCSDF828qv20yBodLY2zJXu9ffTYAiO+sWovCgmOc4 sIy/7rzhJN9MWaNP3Rtxf2k8QxfS7XemuAA3Bv8NRp1dxud2EZqIzjzMu7rs71UxlymZVWHsMk5zF cGcb0LW3yLaofzumNpDtkWJybUboAEInyKDisbtKctskvQu1UtllameoImzbDsM7N2qKOhH7Zkalf JYijA9do1BJs+1XEy+Kqwt2QGroNc0CNS+64FJopQ48q3jC6RP5hgQJ9sZEPtx4w9cJl2gnbWW5Ej RdOKBa6BS6QDVwOiL9MQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qjoo8-009vYP-34; Fri, 22 Sep 2023 22:39:32 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qjoo2-009vWJ-2Z for linux-um@lists.infradead.org; Fri, 22 Sep 2023 22:39:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=3Ewb8X8qwzdej/Dyi2h0QcVlpfouhJGR7F+AnRSf4Wo=; t=1695422364; x=1696631964; b=HMlU3VlBhVvGXxtELUzw5ILKSH4H8NlCFxSrUl7C2HGHu9y 5rpVwDp5inc7RINErnxJl29BgtqHlKPvwJeAHC7uaJ88oBUg5IrctVpXBfZaY9WT75d3ZHW0oevmj K5AIT3iBOPpEPA1GxVKLfcSOnprGaaX65PLiXEjnIrXcLuUSGdorW084REIbAIvoHve4Ab1ASnxo+ 8QmDqkBlu9cFEam/B+k/vHWCdfrtocrBbl9noc3YTVNSSOQExzQj6rawakzazSocf4Soj3/FOmyFa HrEjekFaJlhQ96ZpLxZtfCs/s5ZZi4hMUd5SACDLkRiL1ZjAuI11l3GiSdMl+Taw==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1qjonx-00FtWi-2l; Sat, 23 Sep 2023 00:39:22 +0200 From: Johannes Berg To: linux-um@lists.infradead.org Cc: Anton Ivanov , Johannes Berg Subject: [RFC PATCH 2/3] um: clean up init_new_context() Date: Sat, 23 Sep 2023 00:37:40 +0200 Message-ID: <20230923003737.c4494349a21a.I909ad341512baae41901f4e5b8ccb57ce9fd0d6a@changeid> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230922223737.1206223-4-johannes@sipsolutions.net> References: <20230922223737.1206223-4-johannes@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230922_153926_882536_F001F69F X-CRM114-Status: GOOD ( 15.90 ) X-Spam-Score: -0.2 (/) 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: From: Johannes Berg This function gets a context that's already copied from the old context if making a copy, or memset to 0 if not. This means we don't need to play games with current, even if those games are OK now sin [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 From: Johannes Berg This function gets a context that's already copied from the old context if making a copy, or memset to 0 if not. This means we don't need to play games with current, even if those games are OK now since dup_mm() is only ever called with current->mm as the source. Also memset() our context to 0 since we don't have in there anything that we need to keep - except the LDT but we have to copy that separately, so make a temporary local copy. Signed-off-by: Johannes Berg --- arch/um/kernel/skas/mmu.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c index 656fe16c9b63..ea0c37b92581 100644 --- a/arch/um/kernel/skas/mmu.c +++ b/arch/um/kernel/skas/mmu.c @@ -16,6 +16,7 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm) { + struct mm_context _from_mm; struct mm_context *from_mm = NULL; struct mm_context *to_mm = &mm->context; unsigned long stack = 0; @@ -25,15 +26,26 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm) if (stack == 0) goto out; + /* + * If the kernel wants a copy, it already copied the entire context. + * If not, it's all memset to 0. + * So we can detect here whether or not we should copy, and have the + * pid we should copy _from_ in our own context struct of the new mm. + */ + if (to_mm->id.u.pid) { + _from_mm = *to_mm; + from_mm = &_from_mm; + } + + memset(to_mm, 0, sizeof(*to_mm)); to_mm->id.stack = stack; - if (current->mm != NULL && current->mm != &init_mm) - from_mm = ¤t->mm->context; block_signals_trace(); if (from_mm) to_mm->id.u.pid = copy_context_skas0(stack, from_mm->id.u.pid); - else to_mm->id.u.pid = start_userspace(stack); + else + to_mm->id.u.pid = start_userspace(stack); unblock_signals_trace(); if (to_mm->id.u.pid < 0) { From patchwork Fri Sep 22 22:37:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1838458 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=q9IC/D0Z; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=sipsolutions.net header.i=@sipsolutions.net header.a=rsa-sha256 header.s=mail header.b=V2cZterl; 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 4RsnJZ115lz1yqK for ; Sat, 23 Sep 2023 08:39:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JOv9WiB+C27vxeTDFw0vHOIZogvKUD6BMnyP7uB9m28=; b=q9IC/D0ZXNl6Sb /F6XQ4TZC7nEsHrwhcT/y7Kk8h+hM9wCBTJSYngKJDOmg0lxIy+3LhIyyRZOYOFsqjt3YzHAqTCVT 57GViVvp4ePgYYN5C6ISN2vyxFoNdOMa7j+ZC8JA5e1Ivk27b+AW1xrl1D55YxHZwlFH70nKHcQOp Q6IWdB3n3SpjOcBmE6rcC96UzddvtKEe63z8eWzMo1gYL+s9fzk6cJ17RzHQPjtKyx9N1uEqewtn2 d+dBRaNm0Gil1KxjrdbUre5yLV8n2KMO1D8XjTiwnunK9AU21AyCopL3hwhSeMyrpF+0QOfsSBk+D L9OOkHA4Gv4i0xC6ItTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qjoo9-009vYj-0v; Fri, 22 Sep 2023 22:39:33 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:242:246e::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qjoo2-009vWM-2Z for linux-um@lists.infradead.org; Fri, 22 Sep 2023 22:39:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=kEwXZHPisBHr3NbWodnXmnPjGrHOUdXL7gyyIHy/vOw=; t=1695422366; x=1696631966; b=V2cZterlPBypqsn86UEmcGjcGI7B82viPLFRCVvtnPsDNlc jqm4sNOeEn55/cOBuHDItXvKij6X1W/b8kvXUkN4qZx4AKD00wDpEMZ3T2eb4NGsIHVKfsib0uAnA 54tZugnLoLsySmkC7moVuEYWFDdOx8k/RKTU1ANcPKnpWNh1ZImHOTmaJx7tQ87OxIHolqlpVrec5 FGKUxgbjpvaH10ir+UDkuUO6/nhLwsIS+XsGKbjpOaejqPoyun8j2HKNl4BWT1+bf9bBTO9FSAEf8 duAEjJglCPZ9pa5aALOnv/nCIW3iVtj1IEWU911nmWWuvUhtaNiNpaFgTbs4LA3Q==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1qjonz-00FtWi-0R; Sat, 23 Sep 2023 00:39:23 +0200 From: Johannes Berg To: linux-um@lists.infradead.org Cc: Anton Ivanov , Johannes Berg Subject: [RFC PATCH 3/3] um: don't force-flush in mm/userspace process start Date: Sat, 23 Sep 2023 00:37:41 +0200 Message-ID: <20230923003737.0bfe4730802e.I479958276048d012396d29bab539588094d74010@changeid> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230922223737.1206223-4-johannes@sipsolutions.net> References: <20230922223737.1206223-4-johannes@sipsolutions.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230922_153926_886403_6A52683C X-CRM114-Status: GOOD ( 16.71 ) X-Spam-Score: -0.2 (/) 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: From: Johannes Berg The reason to flush here is to resynchronize the mm after a copy. For exec we don't need to since flush_thread() will anyway clear everything. Thus, we can just do this in arch_dup_mmap(), since when that's invoked, the new mm has been setup sufficiently. This isn't true if we just flush in init_new_context(). Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 From: Johannes Berg The reason to flush here is to resynchronize the mm after a copy. For exec we don't need to since flush_thread() will anyway clear everything. Thus, we can just do this in arch_dup_mmap(), since when that's invoked, the new mm has been setup sufficiently. This isn't true if we just flush in init_new_context(). Signed-off-by: Johannes Berg --- arch/um/include/asm/Kbuild | 1 - arch/um/include/asm/mm_hooks.h | 22 ++++++++++++++++++++++ arch/um/include/asm/mmu_context.h | 2 +- arch/um/kernel/process.c | 2 -- arch/um/kernel/skas/mmu.c | 7 +++++++ arch/um/kernel/tlb.c | 5 +---- 6 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 arch/um/include/asm/mm_hooks.h diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild index b2d834a29f3a..de8d82a6fd7b 100644 --- a/arch/um/include/asm/Kbuild +++ b/arch/um/include/asm/Kbuild @@ -26,5 +26,4 @@ generic-y += switch_to.h generic-y += topology.h generic-y += trace_clock.h generic-y += kprobes.h -generic-y += mm_hooks.h generic-y += vga.h diff --git a/arch/um/include/asm/mm_hooks.h b/arch/um/include/asm/mm_hooks.h new file mode 100644 index 000000000000..b1016520c5b8 --- /dev/null +++ b/arch/um/include/asm/mm_hooks.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UM_MM_HOOKS_H +#define _ASM_UM_MM_HOOKS_H + +int arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm); + +static inline void arch_exit_mmap(struct mm_struct *mm) +{ +} + +static inline void arch_unmap(struct mm_struct *mm, + unsigned long start, unsigned long end) +{ +} + +static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, + bool write, bool execute, bool foreign) +{ + /* by default, allow everything */ + return true; +} +#endif /* _ASM_UM_MM_HOOKS_H */ diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_context.h index 68e2eb9cfb47..8668861d4a85 100644 --- a/arch/um/include/asm/mmu_context.h +++ b/arch/um/include/asm/mmu_context.h @@ -13,7 +13,7 @@ #include #include -extern void force_flush_all(void); +void force_flush_all(struct mm_struct *mm); #define activate_mm activate_mm static inline void activate_mm(struct mm_struct *old, struct mm_struct *new) diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 6daffb9d8a8d..d7545ba6522a 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -139,8 +139,6 @@ void new_thread_handler(void) /* Called magically, see new_thread_handler above */ void fork_handler(void) { - force_flush_all(); - schedule_tail(current->thread.prev_sched); /* diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c index ea0c37b92581..97e731180f70 100644 --- a/arch/um/kernel/skas/mmu.c +++ b/arch/um/kernel/skas/mmu.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -69,6 +70,12 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm) return ret; } +int arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm) +{ + force_flush_all(mm); + return 0; +} + void destroy_context(struct mm_struct *mm) { struct mm_context *mmu = &mm->context; diff --git a/arch/um/kernel/tlb.c b/arch/um/kernel/tlb.c index 34ec8e677fb9..7c0161321fd9 100644 --- a/arch/um/kernel/tlb.c +++ b/arch/um/kernel/tlb.c @@ -600,14 +600,11 @@ void flush_tlb_mm(struct mm_struct *mm) fix_range(mm, vma->vm_start, vma->vm_end, 0); } -void force_flush_all(void) +void force_flush_all(struct mm_struct *mm) { - struct mm_struct *mm = current->mm; struct vm_area_struct *vma; VMA_ITERATOR(vmi, mm, 0); - mmap_read_lock(mm); for_each_vma(vmi, vma) fix_range(mm, vma->vm_start, vma->vm_end, 1); - mmap_read_unlock(mm); }