From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 578BFCCF9F0 for ; Wed, 29 Oct 2025 14:49:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F07F8E007A; Wed, 29 Oct 2025 10:49:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A2368E0045; Wed, 29 Oct 2025 10:49:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 891228E007A; Wed, 29 Oct 2025 10:49:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 726C18E0045 for ; Wed, 29 Oct 2025 10:49:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2E1BE140814 for ; Wed, 29 Oct 2025 14:49:09 +0000 (UTC) X-FDA: 84051434418.08.08FC52D Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf14.hostedemail.com (Postfix) with ESMTP id 807E5100010 for ; Wed, 29 Oct 2025 14:49:07 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tlja5Mq4; spf=pass (imf14.hostedemail.com: domain of frederic@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1761749347; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Z4c969Ew16GaJeZGLcqILIvlzS8wxu70yq5/8cQrC1U=; b=CaNowG0JY3Lf/v8U6Vd1sHm8FSVX1EyPwZ9ZlbOlL8jI/8yJmW4rEGe0TtuFZSnUI+fGsF +IZnXidAbSZXcsIMm5TkitCVeD1c9IelYb7RoszrnFBlQBsMcRNq9mbpfjE80OoxgKT6hG XktvZ7+jMRBy3w5FHaL5AWfYOrHX/y0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tlja5Mq4; spf=pass (imf14.hostedemail.com: domain of frederic@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=frederic@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1761749347; a=rsa-sha256; cv=none; b=0Jpp4y/HDr9SQYg8XjF1l3G3uo1QtQy+Y969WlvvAG2JIri5b+orx+Fix/OV/l0X0vXpPM RN/zVqe7DllmBhhJZ6TbugWiEqep31dqSJuA78mzcEuxjMeNJTwLQ4QMQflB0Tl/04/kIK UUWClRG95T2YhUwKoH9jYYv9koZWSgI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id A44E661E65; Wed, 29 Oct 2025 14:49:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA588C4CEF7; Wed, 29 Oct 2025 14:49:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761749346; bh=HxTqJgI/0X/CEmspyZav8h3FXPWX3qB1qsKFzsoN4as=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tlja5Mq4eRWp697QA/xQ+7a9KJbcnrMdob9cxsXt9OIQA755+bFzbNzRv16bZ4K7i B9LDftZXKO7gStpMqGdXCVrWsVQ+ROKQ4K+QvkxPz38VTj++u90ce6yRHNCsPSi5pD v/JhE3LMKbYoWFWsQEzSVXb3Hm7XB2z8+8xOj7ZC7Xvnlx4rEDqU8ejlyTgLe/T9R2 3vUJArOhgOLb46RZqe+pCWQx7olKyL6EJb+OqaocNuhbMh3d/KGFm/ek9z7wlrO99H rF7V3yVMeDSwqgzEw1be+gsJR70/J/KwRrqpNcrj62az9WVQF5F5bIT1qWPQ84EK24 yw1IH2IxbPQpw== Date: Wed, 29 Oct 2025 15:49:03 +0100 From: Frederic Weisbecker To: Valentin Schneider Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, rcu@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Arnaldo Carvalho de Melo , Josh Poimboeuf , Paolo Bonzini , Arnd Bergmann , "Paul E. McKenney" , Jason Baron , Steven Rostedt , Ard Biesheuvel , Sami Tolvanen , "David S. Miller" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Mathieu Desnoyers , Mel Gorman , Andrew Morton , Masahiro Yamada , Han Shen , Rik van Riel , Jann Horn , Dan Carpenter , Oleg Nesterov , Juri Lelli , Clark Williams , Yair Podemsky , Marcelo Tosatti , Daniel Wagner , Petr Tesarik Subject: Re: [RFC PATCH v6 27/29] x86/mm/pti: Implement a TLB flush immediately after a switch to kernel CR3 Message-ID: References: <20251010153839.151763-1-vschneid@redhat.com> <20251010153839.151763-28-vschneid@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Stat-Signature: rfpx6t7ju77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ZebFtk1ox2SZzqTfimi8aGpOvLHpC0DTix3kDcLLsHqvh7fWPuM8u2ESEnJYoLWxG+sGnp4LfAgf3HNris0IilF1bnC3FlR69OO6qHtP0/sQuUPF4nBhcgoQYCLW0dnL1BApe5aNupFbfZaFnUk4E8ixJXcaWJvHjRSCb2wjCNe4KD5drGuDzkg6oMfXS1Bq9oCY1pibh7IVdGiZw3u9jRdhlJpnF9beBhKPfcjY9kn7XbvwOpE6WwdOmGaEdBl8DVquH6j8AhS8UqzY7KNyITdxr5cUDORi8vnz/Jjer3d6TXYrC4iVcw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Le Wed, Oct 29, 2025 at 03:13:59PM +0100, Valentin Schneider a écrit : > On 29/10/25 11:31, Frederic Weisbecker wrote: > > Le Wed, Oct 29, 2025 at 11:16:23AM +0100, Valentin Schneider a écrit : > >> On 28/10/25 16:59, Frederic Weisbecker wrote: > >> > Le Fri, Oct 10, 2025 at 05:38:37PM +0200, Valentin Schneider a écrit : > >> >> @@ -171,8 +172,27 @@ For 32-bit we have the following conventions - kernel is built with > >> >> andq $(~PTI_USER_PGTABLE_AND_PCID_MASK), \reg > >> >> .endm > >> >> > >> >> -.macro COALESCE_TLBI > >> >> +.macro COALESCE_TLBI scratch_reg:req > >> >> #ifdef CONFIG_COALESCE_TLBI > >> >> + /* No point in doing this for housekeeping CPUs */ > >> >> + movslq PER_CPU_VAR(cpu_number), \scratch_reg > >> >> + bt \scratch_reg, tick_nohz_full_mask(%rip) > >> >> + jnc .Lend_tlbi_\@ > >> > > >> > I assume it's not possible to have a static call/branch to > >> > take care of all this ? > >> > > >> > >> I think technically yes, but that would have to be a per-cpu patchable > >> location, which would mean something like each CPU having its own copy of > >> that text page... Unless there's some existing way to statically optimize > >> > >> if (cpumask_test_cpu(smp_processor_id(), mask)) > >> > >> where @mask is a boot-time constant (i.e. the nohz_full mask). > > > > Or just check housekeeping_overriden static key before everything. This one is > > enabled only if either nohz_full, isolcpus or cpuset isolated partition (well, > > it's on the way for the last one) are running, but those are all niche, which > > means you spare 99.999% kernel usecases. > > > > Oh right, if NOHZ_FULL is actually in use. > > Yeah that housekeeping key could do since, at least for the cmdline > approach, it's set during start_kernel(). I need to have a think about the > runtime cpuset case. You can ignore the runtime thing and simply check the static key before reading the housekeeping mask. For now nohz_full is only enabled by cmdline. > Given we have ALTERNATIVE's in there I assume something like a > boot-time-driven static key could do, but I haven't found out yet if and > how that can be shoved in an ASM file. Right, I thought I had seen static keys in ASM already but I can't find it anymore. arch/x86/include/asm/jump_label.h is full of reusable magic though. Thanks. -- Frederic Weisbecker SUSE Labs