From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 6E0262D7387 for ; Sun, 14 Dec 2025 19:09:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765739387; cv=none; b=hRWu8RPanKiXVr4INI1WoQJjEU7KGnXfuUrGNiGwhq7fYN0NGloPVgowRLNcZP2AkGGFm0Aq/26q9qmmn9OWSbnHTfLuvBbb3tOn24L7w3ebAQ0A3s3E9sdQrmTkuYRUEzb328y44TazQdRyl2+R4Hb03gYDk9J0x1Gbw9KyH3w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765739387; c=relaxed/simple; bh=DKpN2zaUCAninkD0mDIlfHSb+/CVUZ6/kapYpRY+0nU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iFvmQKZSFVganso033TkTg5pblGOw9nuzcDYRslCPEhN95aXfOCwB/f/DwiwRoR4Tjpd+8ghc4P7HbSibbRLA5M4f5kbKljJH2Bd6eguU7UmEYYrTuXc8OmBfEJabB31FRKQINEGhczVtBnXbNKwJc7J7aB3ure88lWsnSQR+bw= 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=YH4jA7uP; arc=none smtp.client-ip=209.85.214.170 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="YH4jA7uP" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2a07f8dd9cdso14105715ad.1 for ; Sun, 14 Dec 2025 11:09:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765739384; x=1766344184; 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=kGRylMipBCZAbafLrwEo52FEPB30FFq/2/xIahus1R8=; b=YH4jA7uPGcmSeOqO7sbw5I/3QJc6ZqoU8VwvF6i77SORDr/ahiSsLoZUWYUbW/sdv1 hlvk5guiHXYuY6JI5ImPGnGTPXAd2T5+eRMVtwpDI5rIG0zYZBrqhN52KPIK4U5EEAn7 GfGlLcEi9yaHH0FIhRO+FctLmy14V0Md8BByvBwXwB3l0YOXnhKeEHJO+LgqV/z6/eLj IeNF0YHBffgFm1g677x4P2Nu3EvrdX1UCPWrWmrylX7T3krJRlRQpaqXwHmsCO7W1HeA P01Un1X6hab3p4AEycbRg4uyY9IUyg1ZuXHWcp5dJ73wRRIQxIuZ9b8bDcl93zKvTjj4 yAng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765739384; x=1766344184; 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=kGRylMipBCZAbafLrwEo52FEPB30FFq/2/xIahus1R8=; b=uTZDbG1UJZdaDfhQD85xn/ov4evdVaeNiTYpJl2qW4KFg54OVirPwdTW2iMOLw6e0l vl+4DLWUetH604FeBWoBoffoxhWjZEjm/zTY1bCYeEUBDYf+Ds/qn0o31rrL0p3XIDK4 RjR0FzHKNqNqH4nogoq0+qSHNICF0XDMl9080Py1i3bzJNIFnNJ212zuK9RlV2gaqqa5 SiMjZZecEKpUTx1Z//2819ZyXCwVSXXN6Vygcf2WNUtp8sdLM6vyQfuygbkw/z6R1/LV B4qcHLg8t7ivGv3u61Y3YbHs/44hwMEgYPRhcGbppsSqgiKzv2uU4aFuNiTPDGLutvHO SkGA== X-Gm-Message-State: AOJu0Yw+epzyP0n2zSjcODIJHT6MWpV5ikZX/P5aWzMykZe9LpuF3NVQ vZjtVXoCwtSfMMGMphRh8eYW5KAlP3SK4nD3Ggn+9Ov4sJMXSu1AIhlV X-Gm-Gg: AY/fxX54FlMWeot8Q7hyzJRg8MA+0K7Hsd7HuECKEVHhFUNIJLRIKnmtuiKGyiQ6PrH 1AbhT5/ITI9c6t58x8EXEruzKNlDudY/Wn3WZuD/7r+5bZFE4UYbjYg+JgN9o/n8gOOkIW8GuUE wDdpOQBZvqD1s6ihwOinK/LPMNzIVhe19HsE+1eGZOGXpcrPt1VxU3rXNM0hijc79lKCTvMOZ5Q kvqJlEsZcGFz8tC/GBHkP24yUXtJ3d+zj7NIM/fh9wja+sj9PZvChVBXhOAxNcLcQY+4aUmP3z4 SIPyMrFiiCY/8IAoLAJ0NhPT46ZYZ97C2I6A7fzbLAmJX+Xv0gOS3zm4kPg0w2ZK8Q6S9X9BwR0 31vSaRpqp4OeREh8hqou+VfaMmC4ry4jGR2sHt+5xiQ4p7j7QPYxjUcW+hkCY2qBaNZ6GgXbHfT m8pv0iIVjbu7tjmnz2l3wrIRDtY6dukhc= X-Google-Smtp-Source: AGHT+IFmYzgXFHkbQBQiUvnSACzpFFy+PJ8dOf4i/6tp+rBdDj8hhEPW3StEcaOty+tMnp+I1Z9nyA== X-Received: by 2002:a17:90b:54c3:b0:33e:2934:6e11 with SMTP id 98e67ed59e1d1-34abd7f7a9cmr6658481a91.11.1765739383476; Sun, 14 Dec 2025 11:09:43 -0800 (PST) Received: from DESKTOP-8TIG9K0.localdomain ([119.28.20.50]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34abe3a1c5esm6909062a91.3.2025.12.14.11.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Dec 2025 11:09:42 -0800 (PST) From: Xie Yuanbin To: tglx@linutronix.de, peterz@infradead.org, riel@surriel.com, segher@kernel.crashing.org, david@kernel.org, hpa@zytor.com, arnd@arndb.de, acme@kernel.org, adrian.hunter@intel.com, agordeev@linux.ibm.com, akpm@linux-foundation.org, alex@ghiti.fr, alexander.shishkin@linux.intel.com, andreas@gaisler.com, anshuman.khandual@arm.com, aou@eecs.berkeley.edu, borntraeger@linux.ibm.com, bp@alien8.de, bsegall@google.com, dave.hansen@linux.intel.com, davem@davemloft.net, dietmar.eggemann@arm.com, frederic@kernel.org, gor@linux.ibm.com, hca@linux.ibm.com, irogers@google.com, james.clark@linaro.org, jolsa@kernel.org, juri.lelli@redhat.com, justinstitt@google.com, lorenzo.stoakes@oracle.com, luto@kernel.org, mark.rutland@arm.com, mathieu.desnoyers@efficios.com, max.kellermann@ionos.com, mgorman@suse.de, mingo@redhat.com, morbo@google.com, namhyung@kernel.org, nathan@kernel.org, nick.desaulniers+lkml@gmail.com, nysal@linux.ibm.com, palmer@dabbelt.com, paulmck@kernel.org, pjw@kernel.org, rostedt@goodmis.org, ryan.roberts@arm.com, svens@linux.ibm.com, thuth@redhat.com, urezki@gmail.com, vincent.guittot@linaro.org, vschneid@redhat.com, linux@armlinux.org.uk Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v5 1/3] x86/mm/tlb: Make enter_lazy_tlb() always inline on x86 Date: Mon, 15 Dec 2025 03:09:05 +0800 Message-ID: <20251214190907.184793-2-qq570070308@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251214190907.184793-1-qq570070308@gmail.com> References: <20251214190907.184793-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. Signed-off-by: Xie Yuanbin Reviewed-by: Rik van Riel Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202511091959.kfmo9kPB-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202511092219.73aMMES4-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202511100042.ZklpqjOY-lkp@intel.com/ Cc: David Hildenbrand (Red Hat) Cc: Thomas Gleixner --- arch/x86/include/asm/mmu_context.h | 23 ++++++++++++++++++++++- arch/x86/mm/tlb.c | 21 --------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 73bf3b1b44e8..ecd134dcfb34 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -136,8 +136,29 @@ static inline void mm_reset_untag_mask(struct mm_struct *mm) } #endif +/* + * 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 -extern void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk); +#ifndef MODULE +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); +} +#endif #define mm_init_global_asid mm_init_global_asid extern void mm_init_global_asid(struct mm_struct *mm); diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index f5b93e01e347..71abaf0bdb91 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