From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796230908; b=hVMSk751sX9DIBWPgZ0I4mydfKa09fH/6TpWpmTmnEw7RktrM06dCmsAqiEfLHskAQa4 U2uEEYnokz5PRGZCg8f3dBinHBgIEcgWiQiYNdTUc/RqhjEjRHc6oBHSlVUwCbnlWM45h 9V3E9/a2tF/ltksHiRnYgSuj4qKz1Nsyl/7aE9ot+zwYkYY/R4UljiTch/97uy2v3uJAr qlfcU1qfM6AUxfYMDRULd8gmRc3edQBzJvxTLH4vCD+Dm4wmpfd7m0SI94mC616mHOS6s qe6ZhmtJbXO4VYCZSp1aytKyKP4gdLaMfAOWxPKhxx41CPgTnW1rukjM80MNyRyUurQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230908; h=Received:DKIM-Signature:Received:Received:X-ME-Sender: X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:X-Mailer: MIME-Version:X-ThreadId:Date:From:To:Cc:Message-Id:In-Reply-To: References:Subject:Content-Type:Content-Transfer-Encoding; bh=2VJKmYQXu553SEKX5pYZkoWXATkkkDq6Q08Eni9RutI=; b=Ilm6bBuvrxvdIAVjpVeRo6H6HlFKOEYAIN59BB8tONdpFZWUA+YCs6M6Wb8sVfVB4sN6 MaPi2aSInFCAkA1aYkPeQNsmvi9d0luqc4XSCiRS3sIR+y7DsBT7a1qWX7A2C7HTb5d5H IrnCtpCx3xNc5M8z8jIhmo63JWKzJDcPuzxKrixx0/ong3kaCfG879nH7PO+c2GbcZv5k zlYFCw5+C/34r7osZhiQyduI9bOQ8Rou3mGJSJPdUkA3104p0h3cQ62gW1BXNGKEeymVn GGpFzwysiImlEC7+iWMjIMbojk8UeGZkhlLE4142930gjx+M0EKNC5DqdzR6MjQNGkA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Gy9B2czb; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A472F606A31A for ; Wed, 2 Dec 2026 17:01:48 +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=Gy9B2czb Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7A0A1F00899; Wed, 2 Dec 2026 17:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796230908; bh=2VJKmYQXu553SEKX5pYZkoWXATkkkDq6Q08Eni9RutI=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=Gy9B2czbgC28MJe5eVSHZBPUD+46lPJz/uxElSZx9wcHxPiS1leo6vF9AbLG05FtW CqtsF2zNShMuJklGEvyJ4xqfT1zybuulUWA3G6oLtF1HlUUyDftTWwP38bSS3InU8x N+pE0rqm1scoI8A0oehPPUAozdZbbMnxZvfuiKxZ5PHdM5oHWcm/7LDyed2RuS0WtY h/GCWgcM6hwHIEqSkFg2SDpykMIr0aEqlJRTqmwVaxmrvi0i9l0JGjabcaAfueeQp/ r//J4Dbs9b4fcCc8gJEI4/pxbyy7rfFOBEkSDXsc2R5j/s7SizMKfeT+DJY68jgAc6 Wm94Ou4RX7ExQ== Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id B8202F40068; Wed, 2 Dec 2026 12:01:45 -0500 (EST) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-01.internal (MEProxy); Wed, 02 Dec 2026 12:01:45 -0500 X-ME-Sender: X-ME-Proxy-Cause: dmFkZTE3Fee1XZbnCspAw3c58+gI/UhAW8avUa1aHM8YIRfpIcC2om0ZxR9r3MHoV8iuyI MXcSyycRF4uOzGNcfGgGIf0N2+rLrh5h6vSanpPF4cLvIWl9brmkMe4z2gR8LuZSm5HKBm 63Q0o2kjXK+1KKTdPMZ+1poWLGs1wQ3p8R/AooHBDYHzDh7dPNTN3/M47KyYrWCXMNdwbm AR285zQYdVYOGPesyF0FqyThBKVuUbImGf8qhtYuA+uvlwRRD/PlyIknvCw/heKyBMdFkc 4wkK3pjNNJDmBevSj5zoikY06SUqPSptxERXPf2yHb0cUYuut4g98zvKi2T5MEsbi6EATo 8g0S6tytspjSOmauJFPn7xXZ6LoRCKwztrSh1KEmWxeq84D1vlhmICZ8HjZAoykgi9CW0m rQfvFVHFP6LVYJQbUr4NvdQugNx63/WhoTWJZnrbQe1XoOLfl51AFwCjw2CrZ/VvbVRoJw 2z5+rb5ODDIoa5QH08ABWKI6+W41JD64TAhujho6wcAvm99cFM08jnp/sX+as16x0zItl8 ieNUPt4AQkoAKXUtbcRdF/Xnylf/j9BZP8k3F/uy6hjV+8MzFUyeGq3k7mkp3esvYtOzyS Nspd/03sQ9On8Cz/NYdNtQKVPW8IXXj+ZWMVOkyB7kKi0uB+fELRasSVBIAQ X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 8068170006B; Wed, 2 Dec 2026 12:01:45 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-ThreadId: Ag4FU-lxcIVg Date: Wed, 02 Dec 2026 09:01:25 -0800 From: "Andy Lutomirski" To: "Valentin Schneider" , "Steven Rostedt" , "Dave Hansen" Cc: "Mathieu Desnoyers" , "Linux Kernel Mailing List" , linux-mm@kvack.org, "the arch/x86 maintainers" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , "H. Peter Anvin" , "Peter Zijlstra (Intel)" , "Arnaldo Carvalho de Melo" , "Josh Poimboeuf" , "Paolo Bonzini" , "Arnd Bergmann" , "Frederic Weisbecker" , "Paul E. McKenney" , "Jason Baron" , "Ard Biesheuvel" , "Sami Tolvanen" , "David S. Miller" , "Neeraj Upadhyay" , "Joel Fernandes" , "Josh Triplett" , "Boqun Feng" , "Uladzislau Rezki" , "Mel Gorman" , "Andrew Morton" , "Masahiro Yamada" , "Han Shen" , "Rik van Riel" , "Jann Horn" , "Dan Carpenter" , "Oleg Nesterov" , "Juri Lelli" , "Clark Williams" , "Tomas Glozar" , "Yair Podemsky" , "Marcelo Tosatti" , "Daniel Wagner" , "Petr Tesarik" , "Shrikanth Hegde" , "Dan Beimborn" , "Pak Hung Vincent Chiu" Message-Id: In-Reply-To: References: <20261127201221.434876-1-vschneid@redhat.com> <20261130124446.72136a89@gandalf.local.home> <75c1f916-5696-4ac2-8c47-5d44fa567e98@intel.com> <20261130135027.364e6272@gandalf.local.home> <85c2ea19-a274-4a64-b8bb-b30ba3b7ef55@intel.com> <20261130141551.48e2a4a2@gandalf.local.home> <08791bec-73d8-497b-8bd9-4787d5325421@intel.com> <20261130152239.154d8f0f@gandalf.local.home> Subject: Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Content-Type: text/plain Content-Transfer-Encoding: 7bit On Tue, Dec 1, 2026, at 3:10 AM, Valentin Schneider wrote: > On 30/11/26 15:22, Steven Rostedt wrote: >> On Mon, 30 Nov 2026 11:40:40 -0800 >> Dave Hansen wrote: >> >>> On 11/30/26 11:31, Mathieu Desnoyers wrote: >>> > 1- the kernel needs to learn about quiescence of all CPUs (e.g. context >>> > synchronizing instructions) when it does code patching. >>> >>> There was also an attempt to "quiesce" the TLB invalidation IPIs. That >>> one means that the TLB needs to be flushed on the way back in to the >>> kernel as well. >>> >>> There are a whole lot of moving parts on this one. :) >> >> Yes, and we have an awful hack to get around that one. As vkfree will >> eventually trigger a TLB for all the virtual addresses it needs to clean >> up, and reading the proc file system causes a lot of vmalloc and vkfree's >> to be called, monitoring the proc file system from the house keeping CPUs >> will eventually trigger a TLB shootdown on all CPUS! The nasty hack is to >> delay that until *after* trading hours have finished! :-p >> >> Yes, we really rather have what Valentin is proposing! >> > > I'm replying to the tail end of that thread to clear things up somewhat; > > The whole x86-specific grubby kernel entry tracking is *not* required for > text_poke() IPI quiescing. Thanks to Josh's objtool patches we can actually > validate which keys get used where, and that means we can shove the > catch-up sequence (serialize()) in C code. For reference this is what I had > for v7, leveraging context_tracking: > > https://lore.kernel.org/lkml/20251114151428.1064524-4-vschneid@redhat.com/ I don't think entry tracking is required in a correctness sense. But I do think it might be required in a don't-make-a-giant-mess sense. The issue is that we have at least three different things that all uses IPIs and that, with appropriate care, can skip the IPIs to "quiescent" CPUs: text_poke, kernel TLB flushes, and RCU. We have "context tracking" for RCU and we're talking about introducing a new thing for text_poke and maybe IPIs. Each one of these has, as its primary overhead in the no-actual-IPI-skipped case, a full barrier upon leaving quiescent mode. I think it would be REALLY REALLY nice if we could unify all of them into *one* full barrier on kernel entry. Then we could consider being quite aggressive about going quiescent in all three senses in userspace without taking an absurd performance hit. P.S. I have thought, and I still think, that any sensible CPU architecture MUST have the property, even if undocumented, that a TLB fill from a no-entry-in-TLB state on a page of text is sufficient to make prior writes to that page correctly executable. I have not convinced any CPU architect to confirm this, but I also don't see how one could build a CPU that runs userspace code correctly if it didn't have this property. If I'm right, text_poke IPIs could be changed to RAR or INVLPBG invocations. > > And on the plus side this mostly architecture-agnostic; AFAICT arm64 would > need that too as of at least: > > cfb00a357864 ("arm64: jump_label: Ensure patched jump_labels are > visible to all CPUs") > > > The real problem is those (kernel) TLB flushes. I found no way to > check/validate when/where exactly vmalloc accesses can happen in the kernel > entry, so the only sane approach was to have the catch-up sequence (TLB > flush) happen exactly when any vmalloc becomes possible: at the kPTI CR3 > switch. > > All of that ugly ASM code is to pretty much reproduce context_tracking but > at CR3-switch level. If we can somehow validate/confirm that we can live > with stale vmalloc entries down to where ct_kernel_enter_state() happens, > then I could have this all be tied back to context_tracking() which was so > much cleaner. Unfortunately from what I understood from Dave regarding what > the CPU is allowed to cache behind our backs, it's really not that > straightforward, nor maybe even possible. If we can tidy up context tracking to run it early in the noinstr entry code, I bet we can pull this off. --Andy