From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (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 064ED34CFA8 for ; Wed, 11 Feb 2026 17:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770830987; cv=none; b=j24xpMce+KjLiwgdM1vhXRQ+WV6mxt2oq/QhiXCal68mhvCrBItEjJZ0ize9rLy5annUcVYVLZ3O1iWMC3CbJPm43achoHGkxKano4EPbw3uat/d9PM/rG+sGV/MKBY0+yVZbv2ikhF/OR+c/iPY6saUyhHG260T0u37EwE6MK4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770830987; c=relaxed/simple; bh=Td8kg4r9cDhRvPK/3A8yTPwemI4PyNCsV4iwAUxSdGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tg0PnK5QoxW3vlSCz88PFlfaa3kYs5NFcDVa7K9uYOs0LeZRhTXmbRhDYM9aDTaiAjBBw9GxO+ZE65woiiNxNj4HQYyXiWd6bvtgLdUAF0bXiM+6FrANpXl2P70PfewrNrjAheHnK3lRu+mBSVGn3Ly/0DSn2RNemgurv8qqs68= 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=CuW4SfNp; arc=none smtp.client-ip=209.85.219.50 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="CuW4SfNp" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-896f8feee14so40741226d6.0 for ; Wed, 11 Feb 2026 09:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770830985; x=1771435785; 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=h7Wu0xLTKx/tUTYAJXA0/STXJ2G0VtSvEtOKAci8/E8=; b=CuW4SfNp06ZZuSufEnkh/6x9YlrQ7V9JWPROX/ZkmlbL/FEm/n3NutGl5WW3B1tI+u 2/8vBMl0AOs/kKgdRsKfxc7fCuC9OXwpq6e96WEySzqdF2kP+W02zMDJdh5sEycpWwyU ZU00GaC+lZ+vS6LyrNJPB7zRzczqU1RGaac6iT3ysfMBEMVyRv8k+edMs1PCMg7rfd7Y VamSUnSLQxy3JfHC5sEarHUFO+QwheR+rLXoMA63rgA/84EgaDZx6MsZeCZdGcc0O41c DmGxQIjimY7BRnLS6JMp6aWCyTlzvtuSzzaAujkf6auTPVu2JSwUeWkcsc+BMMQtvETz Xs+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770830985; x=1771435785; 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=h7Wu0xLTKx/tUTYAJXA0/STXJ2G0VtSvEtOKAci8/E8=; b=ptUBU31KkAsug8zWEzdP+IZz8tk5pHBaeuwPZwX4+U4fqFMUAZQu7N6mzWNKirvSjS zSo5rkvyXlCLIxRgKE6/IJ+EkfmF9g1uktcHYa7Hbfks7fJ/md3pgo/ijH8VzKd7pWBZ 8dF2CuXcuf6BfrtPmn9dO1XoXO++ru5WNXGZBP7Lvne97T9qKutTQvC5Dybd8VyEkxdS m8oKCws6C5Mr01zcvan6xLoYgrCF49hJ2RoZqYX6pcNriX5do2wGI4/NOsRNIj0bGl/N 4YiaqMaVnbh77Pqa3rZtUTZIo7r0aYwAnvwYlDO5aIVnFGeeP0oWe7JU4rEsLbjeiOYk kj/g== X-Gm-Message-State: AOJu0Ywc2zou3EPLawLBrnA9r6eaY5ZMaqCWpcjsSgi6lIpvplAI8NPk dvfldyQ+bs0QfwyKrKzH9pFzKuHMePid4yVLdlZcMvvSQ+39J5O/zCdkwGch/S6N X-Gm-Gg: AZuq6aJIZCvtsvvEYGG5QYcuMqZ4MkwuTB5cBS2R+BTm7FdJfoJM2Ne2PRzDt1yUqT4 FzaXnQDCYHkkGx0j7/OxLPVIAHMQGtcY8f5bHdyv1UHC49dy2pGYdYQ+mbXPIrDqhViNcyZdqE9 hGXRgfAB/1qE+1Jgaa0NLlT54O4HZWcS/uVHAnj9QQehXHhGspTjI6JeNH5BQh8FRl3UHmc6YWw 1P3iKv66W0e23q0cLnN/ki/8o2TpvPGJqcsuquARzwWcfM7gucUmRQ2sCTTIU1JohvvNP+xwa0z HwkEWkBV7A2QULYPLypFa6HriK84+8U1JUPr2hIDE7F9XDP30mbu26vTlTqfhDNIrF7Tt9uXHVP Vy0zx3jhcr6ubXH3emuZD36GqogHoew+ep5dbqgq7Kdr2XDNM3nJFY6CCFcdy7V2BkB+IBCHAuO CHbdtRacfq72WbURuGhhAhx+G0XNploXBJpKIn2i704Vf4 X-Received: by 2002:a05:6a20:c703:b0:392:e5eb:f0b with SMTP id adf61e73a8af0-39417fb5e07mr5719529637.64.1770824186541; Wed, 11 Feb 2026 07:36:26 -0800 (PST) Received: from DESKTOP-3LEPQG8.localdomain ([23.225.64.159]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6e196a8597sm3738797a12.12.2026.02.11.07.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 07:36:26 -0800 (PST) From: Xie Yuanbin To: dave.hansen@intel.com, peterz@infradead.org, tglx@kernel.org, riel@surriel.com, segher@kernel.crashing.org, david@kernel.org, hpa@zytor.com, arnd@arndb.de, anna-maria@linutronix.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, dave.hansen@linux.intel.com, luto@kernel.org, houwenlong.hwl@antgroup.com, frederic@kernel.org, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, bhe@redhat.com, ryan.roberts@arm.com, urezki@gmail.com, nysal@linux.ibm.com, max.kellermann@ionos.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Xie Yuanbin Subject: Re: [PATCH v6 RESEND 1/3] x86/mm/tlb: Make enter_lazy_tlb() always inline on x86 Date: Wed, 11 Feb 2026 23:36:08 +0800 Message-ID: <20260211153608.78083-1-qq570070308@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Tue, 10 Feb 2026 08:07:38 -0800, Dave Hansen wrote: > On 2/10/26 07:32, Xie Yuanbin wrote: >> This was just to fix a compilation error: >> 'cpu_tlbstate' is defined in 'include/asm/tlbflush.h' inside of >> '#ifndef MODULE'. So if the '#ifndef MODULE' is not added here, >> the compilation error will be triggered: > > Rather than sprinkling #ifdefs and 'cpu_tlbstate' references around, > could we try to keep them confined to asm/tlbflush.h as much as > possible, please? > > I mean, mmu_context.h _does_ include asm/tlbflush.h, so even if you > stuck enter_lazy_tlb() in asm/tlbflush.h, everything should keep > working, no? > > That would both prevent adding a random #ifdef and keep 'cpu_tlbstate' > references limited. I apologize for misunderstanding your meaning bedore. I tried your suggestion and there were no compilation warnings or errors: ```patch 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..4bc5eb84e135 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -172,6 +172,15 @@ struct tlb_state_shared { }; DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state_shared, cpu_tlbstate_shared); +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); +} +#define enter_lazy_tlb enter_lazy_tlb + bool nmi_uaccess_okay(void); #define nmi_uaccess_okay nmi_uaccess_okay diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 621e09d049cb..55143cbd6cd2 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -984,13 +984,6 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, * 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 ``` However, I'm a little worried that moving '#define enter_lazy_tlb enter_lazy_tlb' into '#ifndef MODULE' might cause other issues, so I placed it outside '#ifndef MODULE' outside in my first patch. What about this (compilation tested): ```patch diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 1acafb1c6a93..14e776876c69 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -136,8 +136,12 @@ 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); +#define enter_lazy_tlb(mm, tsk) \ + do { \ + if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm) \ + break; \ + this_cpu_write(cpu_tlbstate_shared.is_lazy, true); \ + } while (0) 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/mm/tlb.c b/arch/x86/mm/tlb.c index 621e09d049cb..55143cbd6cd2 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -984,13 +984,6 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, * 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 ```