From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA36B1465B4 for ; Mon, 16 Feb 2026 16:50:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771260657; cv=none; b=rBUjhrJvpNUlvTuRte+LxOah0yTDQL1are10H2zXeiprQSgpOaTndk4KEnad1Jy2JedrSvy87txvCXZCke3RlJTl2YOAFkSicaT854AqEzB/DK/K90S5v6+lypEuIR5yvBn9DZcggsHlvkO9ElfeXzxhuZkxHgD4E/cu3pWU+h8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771260657; c=relaxed/simple; bh=YkcrN4l7nXYGaVuXojfcw6J4rmGzSI1AVIKq/70Ci8k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aCUsddxt4ZDpqhDcHzTfxGje5wg2FFz1WwLCVUlJpE3slpdWOFVJkzd9pEq35uaDmYn+OhtGBbfMSLGhIEOFEK1jyBpISfwwJOHNVGPLKuvuCfyxZYSVPaOP5kXls1R0SseVFPvCxuzfZGVjXUcdGLdG2aYhJ4whEoZTkD573Ks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JPFbtcih; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JPFbtcih" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2aad1dc8856so22571985ad.1 for ; Mon, 16 Feb 2026 08:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771260656; x=1771865456; darn=vger.kernel.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=s+Ec0twm7mu0rpQv/1PNp+gi2IdKpcRP5zguU2JHFB8=; b=JPFbtcihi/mx/ePjZh0JXb3HjyQWAXNLr5iK72Klb+GBdq1ZZc9H20xe/1Z7qnH7in WpUpKDKvLNMXxHB5TKJrbPPUpr1xgwY0CcvoR+oJs8vpohc8Z8wqr50VBhjA7YlxgM7I uhnePNKv1ysPFmiiw3sbGS5bpu3uzq3sE5hdlns/U6agWN2uTFOsrvt8OYrbZ7r2P+HL wUpPtMfp9Jf9jd/2rzbC0DhfCDcqFJDL1bdkr3MEWfYmBjv0uRsXM9qrQW0+x+Oyk9iX kHa4B5NoT0em440TUn+hJacVGzH46jgCXw9YkhKNd+aLrowYfUdpw4wtabG+PzLf82pc lMjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771260656; x=1771865456; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=s+Ec0twm7mu0rpQv/1PNp+gi2IdKpcRP5zguU2JHFB8=; b=aXnN1UdSOb50fuyYAMcj4j8NdBJSJzLhf+KWQKubHm+QNAz4bkiSbwl+AGnoBL7i9U o9ckM0tx0vWzAuy97mzLGH6eW3g1maV59M0bOHbPk2R6ltLK12+ctHMW7z+Db3J7pP+S mxOq7dUxxXSlsKpiA9YfsRWfdAJSqQcTTnV6b49eWpQ8gIA00rHfMT+uCamgp3nDBppq VRhKQi2wmCUWy5e9byMG4U/gUdMTQLds1v8851LgRrZnl4Pw0NibDLclE1JgJt7sYX/R OYp20VhPhO8joQ2EWmWLBZxVdfj8hnoAVEiDza+GJ/X2p7XGHKJC/kWmVtrd+2U3YyGW MfWQ== X-Forwarded-Encrypted: i=1; AJvYcCWz8ETPZ4NbP6BoSsDGIvFgc7O38xA/HcTuRXDNceESrJAjGWl4WzFtclOl4LzNrMIq1urTl/UB+AZ7sw0=@vger.kernel.org X-Gm-Message-State: AOJu0YwXMUQ7cYS9pChkHiltPI7fTym4N9Pa+GsZXLdvJknDE5hC/VJk QKJnhwmWMOxb2JHkrkNcBDIWVgHfKdKOWnPO4TkUXCwdtaSLiR4A+thh X-Gm-Gg: AZuq6aJexPcqTc76POjY9S8fFAJPZMLc1vGTVOO6cTULhVjEhVjPhJ3UMQtkgNv047d r6OzPI3Ondy0QCga/AMthTiADM9KEHVJbFzmv5uRDz7SV4WWk2JGJKzTzHtMQe+xatviZUzfNQf qJYQB6NhDVHjJt4XvPcWMdn75mWcnmanp6AHDXD1jDD540ZPAONguTtd0vzyTHAwlaGd3zEtFgw Ol2lzYr5ivbOCMvml3IovpWJ9iFeLKjypSOeNofMwkkf4ELEaQgfYOHL1q+gb9PSmgkESnZE04L rtBIRxDahWYTl2bHgY4dB2eFupzWizD4bM1vcbCEYYSJ2rKadEEQ+UJQFZn2Ce8d/w8r2ifqB8X lctAN7n6/Yf+EJk6rAlm5q43MkSlbgpbBDwQ6iAXIOWFLYTdbwugR5kXkKUXwNgvsSabRW5EwP4 y54BHmcmYyxERE/yN1i4NMHyqMzCZAuBVXZiFZPPuIDs7n X-Received: by 2002:a17:903:11d0:b0:2ab:3169:347d with SMTP id d9443c01a7336-2ad1754590fmr78234515ad.42.1771260655787; Mon, 16 Feb 2026 08:50:55 -0800 (PST) Received: from DESKTOP-3LEPQG8.localdomain ([23.225.64.159]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ad1a6f9d34sm75238425ad.11.2026.02.16.08.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Feb 2026 08:50:55 -0800 (PST) From: Xie Yuanbin To: peterz@infradead.org, tglx@kernel.org, dave.hansen@linux.intel.com, hpa@zytor.com, riel@surriel.com, david@kernel.org, segher@kernel.crashing.org, arnd@arndb.de, 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, bp@alien8.de, luto@kernel.org, frederic@kernel.org, houwenlong.hwl@antgroup.com, will@kernel.org, akpm@linux-foundation.org, jgross@suse.com, baohua@kernel.org, ryan.roberts@arm.com, lorenzo.stoakes@oracle.com, nysal@linux.ibm.com, urezki@gmail.com, max.kellermann@ionos.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Xie Yuanbin , Dave Hansen Subject: [PATCH v7 1/3] x86/mm/tlb: Make enter_lazy_tlb() always inline on x86 Date: Tue, 17 Feb 2026 00:49:48 +0800 Message-ID: <20260216164950.147617-2-qq570070308@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260216164950.147617-1-qq570070308@gmail.com> References: <20260216164950.147617-1-qq570070308@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit enter_lazy_tlb() on x86 is short enough, and is called in context switching, which is the hot code path. Make enter_lazy_tlb() always inline on x86 to optimize performance. Cc: Thomas Gleixner Cc: Rik van Riel Cc: David Hildenbrand (Red Hat) Cc: Dave Hansen Suggested-by: Dave Hansen Signed-off-by: Xie Yuanbin --- arch/x86/include/asm/mmu_context.h | 3 --- arch/x86/include/asm/tlbflush.h | 26 ++++++++++++++++++++++++++ arch/x86/mm/tlb.c | 21 --------------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 1acafb1c6a93..ef5b507de34e 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -136,9 +136,6 @@ static inline void mm_reset_untag_mask(struct mm_struct *mm) } #endif -#define enter_lazy_tlb enter_lazy_tlb -extern void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk); - extern void mm_init_global_asid(struct mm_struct *mm); extern void mm_free_global_asid(struct mm_struct *mm); diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 5a3cdc439e38..382b544c11d5 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -172,6 +172,28 @@ struct tlb_state_shared { }; DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state_shared, cpu_tlbstate_shared); +/* + * Please ignore the name of this function. It should be called + * switch_to_kernel_thread(). + * + * enter_lazy_tlb() is a hint from the scheduler that we are entering a + * kernel thread or other context without an mm. Acceptable implementations + * include doing nothing whatsoever, switching to init_mm, or various clever + * lazy tricks to try to minimize TLB flushes. + * + * The scheduler reserves the right to call enter_lazy_tlb() several times + * in a row. It will notify us that we're going back to a real mm by + * calling switch_mm_irqs_off(). + */ +#define enter_lazy_tlb enter_lazy_tlb +static __always_inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) +{ + if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm) + return; + + this_cpu_write(cpu_tlbstate_shared.is_lazy, true); +} + bool nmi_uaccess_okay(void); #define nmi_uaccess_okay nmi_uaccess_okay @@ -480,6 +502,10 @@ static inline void cpu_tlbstate_update_lam(unsigned long lam, u64 untag_mask) { } #endif +#else /* !MODULE */ +#define enter_lazy_tlb enter_lazy_tlb +extern void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) + __compiletime_error("enter_lazy_tlb() should not be used in modules"); #endif /* !MODULE */ static inline void __native_tlb_flush_global(unsigned long cr4) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 621e09d049cb..af43d177087e 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -971,27 +971,6 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, } } -/* - * Please ignore the name of this function. It should be called - * switch_to_kernel_thread(). - * - * enter_lazy_tlb() is a hint from the scheduler that we are entering a - * kernel thread or other context without an mm. Acceptable implementations - * include doing nothing whatsoever, switching to init_mm, or various clever - * lazy tricks to try to minimize TLB flushes. - * - * The scheduler reserves the right to call enter_lazy_tlb() several times - * in a row. It will notify us that we're going back to a real mm by - * calling switch_mm_irqs_off(). - */ -void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) -{ - if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm) - return; - - this_cpu_write(cpu_tlbstate_shared.is_lazy, true); -} - /* * Using a temporary mm allows to set temporary mappings that are not accessible * by other CPUs. Such mappings are needed to perform sensitive memory writes -- 2.51.0