From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sg-1-104.ptr.blmpb.com (sg-1-104.ptr.blmpb.com [118.26.132.104]) (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 0F2E7387348 for ; Mon, 2 Mar 2026 07:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.104 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772438128; cv=none; b=sxvE6z+Rcs2w7IxM+yVM9dUK3XYdOXHKPBuZ+QcJWKCvNtrCwY/AasZqv8sPBG+98jFn2CcU4j2dKWJyWBc22mT8jq0NDBk0oY1WUi1AxdbebeNDsyojkwQgEth+Jk2lAKOeyN/w1N7l/+/XTj2SDirnKXCh5YgKHA72xDRtKVo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772438128; c=relaxed/simple; bh=7RuIyUQBYovh4IrD1W4gq+5RbcVdcgrK/QFad3BFaLQ=; h=To:Subject:From:Mime-Version:Content-Type:Cc:Date:Message-Id: In-Reply-To:References; b=bMrMuvfxs02xOL3ui5pGtySdVUhP0HmTJYQsaKptWFbYFStzdw7JBzlqCC7MLuF0KQeFJSOcXu/WQTbpCTM/KscYOkII/FZG5lhTSYedH8T6NpHqNtM+Y/UbA50MelOiHuTTUUEUnv3d1m9xkjnucxRBfT1WKttb0An6YnYkrlc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=F11W3LOE; arc=none smtp.client-ip=118.26.132.104 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="F11W3LOE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1772438115; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=2HjLzxVFAdciSC+xw+Bt+ewKYjmFDkMaGqIa1/RlcuU=; b=F11W3LOECzTLxqzNYCgaJHjiDpsddy02iJTtgAMhlJHgiXQ1azJ6cC/8Yo9I8YjoKIvSN+ TXSQutuuKYov3NuO+M2m3t9yBSPlQ+hI+wxZC+vIZOyd0tJ1LOnH6l9VzC48J/idKXNm10 C7F+9oDT5UbOwyelbSBdTZ4zIkkpCoVMlps/5iVFlkWFGX0FhvV+9gpaWfgcXSosfi6dIP PF7j3NABpes4Z8UyZsZ9/8nct2VPHsaW8lOLnWlEJcU48OyHIZ6PNyHXgXTmN/Uq14XE0t DLG3HsrlfXwhFxjB1Jv4wwA0UDLEWpyPv3iHkztc/TwhFK7cZ5XDcADc3kJb6g== To: , , , , , , , , , , , Subject: [PATCH v2 12/12] x86/mm: Enable preemption during flush_tlb_kernel_range X-Mailer: git-send-email 2.20.1 X-Lms-Return-Path: From: "Chuyi Zhou" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 X-Original-From: Chuyi Zhou Cc: , "Chuyi Zhou" Date: Mon, 2 Mar 2026 15:52:16 +0800 Message-Id: <20260302075216.2170675-13-zhouchuyi@bytedance.com> In-Reply-To: <20260302075216.2170675-1-zhouchuyi@bytedance.com> References: <20260302075216.2170675-1-zhouchuyi@bytedance.com> flush_tlb_kernel_range() is invoked when kernel memory mapping changes. On x86 platforms without the INVLPGB feature enabled, we need to send IPIs to every online CPU and synchronously wait for them to complete do_kernel_range_flush(). This process can be time-consuming due to factors such as a large number of CPUs or other issues (like interrupts being disabled). flush_tlb_kernel_range() always disables preemption, this may affect the scheduling latency of other tasks on the current CPU. Previous patch convert flush_tlb_info from per-cpu variable to on-stack variable. Additionally, it's no longer necessary to explicitly disable preemption before calling smp_call*() since they internally handles the preemption logic. Now is's safe to enable preemption during flush_tlb_kernel_range(). Signed-off-by: Chuyi Zhou --- arch/x86/mm/tlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 86d9c208e424..48371eb36773 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -1467,6 +1467,8 @@ static void invlpgb_kernel_range_flush(struct flush_tlb_info *info) { unsigned long addr, nr; + guard(preempt)(); + for (addr = info->start; addr < info->end; addr += nr << PAGE_SHIFT) { nr = (info->end - addr) >> PAGE_SHIFT; @@ -1517,8 +1519,6 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end) .new_tlb_gen = TLB_GENERATION_INVALID }; - guard(preempt)(); - if ((end - start) >> PAGE_SHIFT > tlb_single_page_flush_ceiling) { start = 0; end = TLB_FLUSH_ALL; -- 2.20.1