From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 3850F330B38 for ; Sun, 1 Mar 2026 08:36:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772354179; cv=none; b=AQjt5NVdKRB+027JK18L1INMc8npA5iT+zExOCSZK2aYuu7cG+rd4yFOY0TFOKYsY+GG1Wodkhb7ZR6vL+4Y/RADoxckMKlf0IVA9c6Xh43WKeurAVZPrTX9OlJlZEaLFdPnn8ff647GLJ5cHdpeVAjGCe3qRgndkZqqvdYtjZA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772354179; c=relaxed/simple; bh=cyo8XaIOmqFWgcYr1otMeSpfuc9fTs4DsJkq94nrhEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kf+uTRU9lWB2ApYHrDSSzxDPJTGUSQY6uNDWyC0xUvF9uhTvosQgNO86qta+/9SC/uzYjOXKS4Feks3862hKGe8qWAvSbQ94LxXc1ZP+EtmypMN1XbC9+iGiENFt8e1zj4BQx5EC7FqYJf+oIxjFpBatd50Hm5CNbSR7HC/Colk= 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=FkiK98Ma; arc=none smtp.client-ip=209.85.214.177 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="FkiK98Ma" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2ae46b9c70dso1537425ad.1 for ; Sun, 01 Mar 2026 00:36:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772354178; x=1772958978; 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=Ko+ugxRDc+WgmTI5BSqQ1uqwnGCsuAabwvqTgvkx7tk=; b=FkiK98Mab4ZH317z8qphfzBMNjRhkboMHib5eT21NVCFdnUVDMuImRfiuoiqFu/s0C oCKqN/p27Hn9I1qAGtDjFjs3+uuaWrpmEm6PTGEs/rlg+mQaRYBkCc7AdGPld18XUagT ReovjPDYerPpIwBkMWynFwGr6mrGphKWHN6PeklANVZBwVI0ogNPL5lkXRDQn2nXkwYG 0jnfqoJ5GcNBj2DIX1cNqKyUP14claYcZan847sOBsJctPfHGlGymnu9FWlpDdgJ156k +trRlsPakMvqVdydWH7kYMueS+j927tmF4DEnAKT8H7sw4ivT4MOXFo3qWYDiNsLp7vK Uxww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772354178; x=1772958978; 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=Ko+ugxRDc+WgmTI5BSqQ1uqwnGCsuAabwvqTgvkx7tk=; b=V8uTjrWCDoub/PFugtfWMRHvMuHBftfGBAbdVP9TgcepnxvCMO94kt7prcna2/iQCs vA3ZjAPgHUn6o7bz0fyVpG4R6OC9og0QRbi0MCKBFXbDlqsg3jZLzQJYbJAcTg+4EEVx wggEHsuXlRjvetjOQNTwnIJP4UIPyGdlLb95HdYioacOshgf2PxQh1eNZKMslcMDZfsA skCNQiummtZqi5YSa4kGgGd3UIyEefYo/A1DJKHip/jVmmSekdM1cx3E8A40C+sb5pwP Kw6gT4P5topwmf+FcLGyNRsiCXtQxFBdDV5pq5pOBFicaxj5cnzSfN9Eavzxy3Cofpsy x/xA== X-Forwarded-Encrypted: i=1; AJvYcCVxz/Nt1qemaVBYLaykZcF3tNWGk+IGGa5iwGGatmChFRNLM5vRB4B/TeC4/iCr7TqVTXxqGwBtVsWKeDg=@vger.kernel.org X-Gm-Message-State: AOJu0YxipRZNwxBxpDv7BAWZCroXzmNYFYjGx+wpPGVATrVeMU0FXjnH k203KCxTP0aYnI2tWj7iNbNevziZSD7FU/QqRDrOMyqQKQ0IpqBM4ElF X-Gm-Gg: ATEYQzwvyUV+YoLkN2M5rm7Sf0SstvLBY3gs00WBkbUHErDJWrhtbC6q7k/DrtyFkhM dwJO6h2RDkqTPi1xBI6d1y1b/7xIZaz2uPq6cox+MB88/8ruZi6axuyI2v/JZCNBlI+g5+nFbCq ezqFPELokvljV6UKt94M9a8Gb0PHlYkA0uHEKy0JwsXuWSSsJKf5V0XcJU5Ty0tEV+Yl7z1+bmw CDgkDCDg48vNsmo5IaOyk9dHYKPQ+9XetJFI4RL4p/LfmyapMg7FTph4y/EdcmkCGZ9a7fhERmV +p2XdFvrE2FKEqBTs6sq6EtdIAgtT4N2ms6V5Ms3i5cxRhdXcX61hIKkPIurvU7t2iYaZHZCTsh kh/Rll4z5zWxHky7naSw6V6J1Q78hiFHeODY1GhRKXkR1r9S68Ge7qYYsq2x36hBQ59POEXKhFf dkyAJ6xfmCCmriP2ll80+N8pucbOLvDMocs76nadUiE5w= X-Received: by 2002:a17:902:cec7:b0:2a9:616c:1716 with SMTP id d9443c01a7336-2ae2bbde27emr95266335ad.26.1772354177479; Sun, 01 Mar 2026 00:36:17 -0800 (PST) Received: from DESKTOP-3LEPQG8.localdomain ([119.28.20.50]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2adfb6b416bsm107799835ad.61.2026.03.01.00.36.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2026 00:36:17 -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, mingo@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 v8 1/3] x86/mm/tlb: Make enter_lazy_tlb() always inline on x86 Date: Sun, 1 Mar 2026 16:35:18 +0800 Message-ID: <20260301083520.110969-2-qq570070308@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260301083520.110969-1-qq570070308@gmail.com> References: <20260301083520.110969-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 (Arm) 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..0545fe75c3fa 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