From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B17EB606A32A for ; Mon, 30 Nov 2026 15:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ByjcyjUE Received: by kanga.kvack.org (Postfix) id CEA2F6B05B2; Mon, 30 Nov 2026 10:00:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC22B6B05B4; Mon, 30 Nov 2026 10:00:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFF9B6B05B5; Mon, 30 Nov 2026 10:00:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8D46A6B05B2 for ; Mon, 30 Nov 2026 10:00:00 -0500 (EST) Received: from smtpin17.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0F20E80A9E for ; Mon, 30 Nov 2026 15:00:00 +0000 (UTC) X-FDA: 85492095360.17.9B83123 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf28.hostedemail.com (Postfix) with ESMTP id 4D8C0C0010 for ; Mon, 30 Nov 2026 14:59:58 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=ByjcyjUE; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of tglx@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=tglx@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796050798; b=iSjnXbMi3kG3Kq92YcJ2VHYWLhqsUtDWsJ11LY+Znnz+OqYLgjv1knJBOz3JEP7vxIV9VQ dymV1ubb15Xvfx2TmD0oE+1pcoi/rKbooEfjFcmqJMWrTnMRZvEubBPxoUqN0oPgfTuw1+ j/2Iymdo6zLDt1/K5R45LbUYXmVt0ho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796050798; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=P3Bg3J8nM18q7dLL0JZaEPtkMyIzpekqxYnfeU+jJXM=; b=l9ISIxQWFHNqRR3vt1GKnoR0SCqGAG0kl9X2swtSS0ML1L/yykFC5eqvxpPSdqJpmC1GSh cqAFPFWXA88JYMQs432XRoSbyC5pgayvPjXAhQV7u1mq9f16t45eTzJcDy0QATc33zZ+vY 5kRoEEw7pR0+e7AV5lEH+2s4AbPnRIc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=ByjcyjUE; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of tglx@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=tglx@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 785EE4124D; Mon, 30 Nov 2026 14:59:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 402031F00897; Mon, 30 Nov 2026 14:59:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796050797; bh=P3Bg3J8nM18q7dLL0JZaEPtkMyIzpekqxYnfeU+jJXM=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=ByjcyjUEG7YQUs4kXEuxMuUtwxFwn4IZa9cmtjQsle2+ECOpkKpAR22B7FX7/9vZa 0z7SNqGkaFwN8VjMMdTZqUwcfcTYE7WzWUwOY+5tNk87A2+9m+Zj75CXlgEt3Pzmc1 UXvIygJfca2uFZVEMu4wcprijXU6US+3dHwlSxf7cqdYeBM4CeAeGw90AJldQoTW5H e3YvByra4zOhUDpK850HofjmGaKEgw9DZE42q8GSEg8bnixAFAknezoxUNApnBJMMq 03+jMzWzQMMt6lpRVPiF/eQLljjwbHUEfIMaZYxCUQabLbvXZQcaJ7bnOuKTRbzFRc dg//zTH3QMpaQ== From: Thomas Gleixner To: Karl Mehltretter Cc: Mathieu Desnoyers , peterz@infradead.org, linux-kernel@vger.kernel.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, paulmck@kernel.org, boqun@kernel.org, shuah@kernel.org, kees@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, oleg@redhat.com, bestswngs@gmail.com, xmei5@asu.edu, xujiakai24@mails.ucas.ac.cn, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, Dominik Maier Subject: Re: [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity In-Reply-To: References: <87bj79s11m.ffs@fw13> <20261128192202.93895-1-kmehltretter@gmail.com> <875wxgshou.ffs@fw13> <8733sjs408.ffs@fw13> Date: Mon, 30 Nov 2026 15:59:53 +0100 Message-ID: <87ecc2qs9i.ffs@fw13> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 4D8C0C0010 X-Stat-Signature: qszyfkieqpfx4c5d7pe8zrpz1jtwjwnx X-Rspam-User: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Server: rspam04 X-HE-Tag: 1796050798-924500 X-HE-Meta: U2FsdGVkX1/avjUInhBxOcVA9edggsah7Mx5WuLEVdeULHOdTkAsHt9vbA4qAHva+lXMXLxtLoQo0k9RGUNCHvwUhhFx8LuOTq0ENByTL1wFzJ3hP+WFsMlwc3LkvoXtaFm4DlzRHAugGGOckYXxKHG/Mic2+j2NdKrvCx9coQB8gnp6SmP/0eCPMBvTBoKSrqAjV3RZyWW1DM+YqwchmSlDZz+DwqZpekd87dCSecWdBO+X3rM2UCNAQxKEzJGmFwYDj62XL5faUmIhS5YVqkBmYp/5OMgiLuG66kkbiL82owouOQos6J/+QsvpVgTlmTl9ZzS1KjHVy9ECweI6u3Wu3Y/sNubLT9j329xYMmJGJIs3M/rNVoD6lxodu73pgkLyb0PVkcd2jOcVutAsRokxT/wiNhulaC6FoOdhPREVgMh6ZO9HfOLRk/FZJ0hkeowCJtbYzdRD5qWsxy9lMiY7NEC4v4pJL9axJ9gIM72BulP1ubOK70BofiKKg/m0X9swPNLWdtmKSgXMbhH1WOzbT42/okhvOgfK40SIe7hluncgO4DvTAVNDgJyqoDq6KPNZlLD6P1Zp75bycaaLzNhwlUt+sa25HIzGaiUowkxwENQND4fSHurnwVUlkvLqYilx6Wb+n2PS7yUka1eqSqSygSkEjudZtiNNxfVOx+WW92lQtVS/D+vpbW68GDLQgfeCCTjWeb/sP8aXPSJojs1kriYYK9RQclTtij7k86N/FWH2wHN01vWwiP8QChEcl3o73l+TW9sUPlGZu+L/fQxXJHJsqgAmb32ezqsd9M+KcH0WbEVqprbLaZRwq9f4S3M+avgrMqvoUi60p20ll6QrYt8o+/42OYBfjQgXOILC61PX5qBv9oVTqP9bWoofZWUT/Tm7/Biw+bstBZcZSbET6hXweyRe/OFyKbhpdFeyCbrfu4r7nPAcZl/NjFkJAnp4YVuOq+oU5y7YV/ 0EE9QBRa Z2W/nJG9k+AxR1Vz5MHEKg0LS/wnc3aJZqBdVRTntGxAFSHJQg9EeBsEkBffkLXuFFSZrJgSqzXjtgTFIaVWo2bNXTW406GBYwfAFSlVzY3GoQrDS8z+C4C7oIah97PtuSnIKSGN3h5qEdp31pLnr0GUOMk3tW3EkNm6HN7mi09kujKZHXfzdcXLferMz3uafhnsJtF+J4jVwSvtvuSndpSLX3gVSyhW/c+/2ERR6txoDR3MkD5voodBsvq8hIzcJcDNcUQCl9j3Kg8H8omnyvxt6RVISvkreXkhwKmyqq10/Cl3A0LNg47NPVcNrE4/8TE54fH7v1QEy4ceiiEQAi9qXR3fqJqpPIvf+S+Sb5v/EkRRADuHbL7QY++kk35DLw2hzLfB1wUCGTOt7JC/PrcRBGpouzjkCM/62Vb3RGwUwv0TcWqYN6hPN0n1SpCnWC51ILNdLWaijLZiNjtv7fKk8BuhC2earYWNGhmSfU9+SDuVYZT0+ruUdHg== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Sun, Nov 29 2026 at 23:54, Karl Mehltretter wrote: > On Sun, Nov 29, 2026 at 10:48:39PM +0100, Thomas Gleixner wrote: > vfork() and CLONE_VM without CLONE_THREAD breaks that assumption: > de_thread() only terminates threads in the same thread group, not other > tasks sharing the MM. > > When execve() fails in a CLONE_VM child before the MM switch, > sched_mm_cid_cleanup_execve() modifies the shared MM locklessly while > the parent's threads are still active. Allocation-failure injection on > x86 KVM hits: > > WARNING: kernel/sched/core.c:11198 at sched_mm_cid_after_execve+0x309/0x3a0 Groan. This MM sharing is a real pain... > Could both hooks move into exec_mmap() instead? > > Leave the old MM after mm_exit_exec_release() and join the new one after > mmap_read_unlock(). The only failures in between are killable lock > waits, which require a pending SIGKILL, so the old MM never needs to be > rejoined. This removes new_mm and sched_mm_cid_cleanup_execve(), and > avoids holding the locks across irq_work_sync() and cancel_work_sync(). I thought about that and then discarded the idea because of your ptrace overriding signal thing. My tired brain obviously did not see the connection to SIGKILL. Thanks for pointing it out! That makes the whole thing even simpler. Updated patch below. Thanks, tglx --- fs/exec.c | 13 ++++++++++--- kernel/sched/core.c | 14 ++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) --- a/fs/exec.c +++ b/fs/exec.c @@ -858,6 +858,15 @@ static int exec_mmap(struct linux_binprm /* Clean up futexes and release the mm */ mm_exit_exec_release(tsk, old_mm); + /* + * The below lock acquisitions can only fail due to a SIGKILL. In + * that case the task will die and even PTRACE won't be able to + * resurrect it. So this is the safest place to leave MM CID + * management as there is no way that this will go back to user + * space. + */ + sched_mm_cid_before_execve(current); + ret = down_write_killable(&tsk->signal->exec_update_lock); if (ret) return ret; @@ -908,6 +917,7 @@ static int exec_mmap(struct linux_binprm } else { mmdrop_lazy_tlb(active_mm); } + sched_mm_cid_after_execve(current); futex_exec_done(tsk); return 0; } @@ -1853,7 +1863,6 @@ static int bprm_execve(struct linux_binp */ check_unsafe_exec(bprm); current->in_execve = 1; - sched_mm_cid_before_execve(current); sched_exec(); @@ -1866,7 +1875,6 @@ static int bprm_execve(struct linux_binp if (retval < 0) goto out; - sched_mm_cid_after_execve(current); rseq_execve(current); /* execve succeeded */ current->in_execve = 0; @@ -1885,7 +1893,6 @@ static int bprm_execve(struct linux_binp if (bprm->point_of_no_return && !fatal_signal_pending(current)) force_fatal_sig(SIGSEGV); - sched_mm_cid_after_execve(current); rseq_force_update(); current->in_execve = 0; --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11063,7 +11063,7 @@ static void sched_mm_cid_fork(struct tas if (!mm->mm_cid.users) { sched_mm_cid_add_user(t, mm); t->mm_cid.cid = mm_get_cid(mm); - /* Required for execve() */ + /* Required for execve() as the task is running */ pcp->cid = t->mm_cid.cid; return; } @@ -11161,10 +11161,12 @@ void sched_mm_cid_exit(struct task_struc } /* Last user */ scoped_guard(raw_spinlock_irq, &mm->mm_cid.lock) { - /* Required across execve() */ - if (t == current) - mm_cid_transit_to_task(t, this_cpu_ptr(mm->mm_cid.pcpu)); - /* Ignore mode change. There is nothing to do. */ + /* + * Ignore mode change. There is nothing to do as the MM + * is going away in the common case. A potential execve() + * failure which requires to re-join the MM's MM CID + * handles a stale transit in sched_mm_cid_after_execve(). + */ sched_mm_cid_remove_user(t); } } @@ -11181,7 +11183,7 @@ void sched_mm_cid_exit(struct task_struc cancel_work_sync(&mm->mm_cid.work); } -/* Deactivate MM CID allocation across execve() */ +/* Deactivate MM CID allocation across execve() switching the MM */ void sched_mm_cid_before_execve(struct task_struct *t) { sched_mm_cid_exit(t);