From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11E682EB84E for ; Tue, 6 Jan 2026 11:51:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767700292; cv=none; b=MsRoK0o+fiYf/tF0wZjqxPfsNMy7al4Dnc3GGXt+NZmZDkBSc8zn0KJdtAvLkDeQvFWwSH4LI2yeoorjlJ6dLgsUedXiNGIgv1vzgglMyQaT2UO4yew/xz8DD6MyctbdZJVTcavViVDh/3tE3AylIpUXJHF8zduOqe+aVVi57Dc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767700292; c=relaxed/simple; bh=o3nw8VTLD4be1EAoFM5mfjEm88YfosHjVIezn8MLQME=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=pZ1EsAy0bTUaDQQtk4vvRBvnR18SA1AEU0NjfaQEPPI9hwuj81ozjLvCaKxCsk9F/rFaaagkrMhYEGCrlVJAKJNC1N7L3fEJnH63zwZoVuPUyuOSycjeX22qLU0m8FP3/Krtl0sEJo6pB8mfPP34c+B1zy6QMu56lW7Jye523Dw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=e1LM69EH; arc=none smtp.client-ip=95.215.58.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="e1LM69EH" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767700286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=iklw0RInONOSh+e9xelR5uEAOvlruMIvuc7amxeOT2I=; b=e1LM69EHdQpzC3zUSFx18F7ADHBf3b1Hls/i3QoR1He+c2eOrmtGPTw7XCnpLwoyBEEjZ2 T2OebBCEnpsLQemldztcr1Af3povcEeNa03S8f/agpusP1CwenaOpdY5ODQzmvCFvjIkm5 pzp5LKhTFWROjxnbIIWVIXpmQInyeJk= From: lance.yang@linux.dev To: akpm@linux-foundation.org Cc: david@kernel.org, dave.hansen@intel.com, dave.hansen@linux.intel.com, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, lorenzo.stoakes@oracle.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, shy828301@gmail.com, riel@surriel.com, jannh@google.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, ioworker0@gmail.com Subject: [PATCH v3 0/2] skip redundant TLB sync IPIs Date: Tue, 6 Jan 2026 19:50:51 +0800 Message-ID: <20260106115053.32328-1-lance.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Hi all, When unsharing hugetlb PMD page tables or collapsing pages in khugepaged, we send two IPIs: one for TLB invalidation, and another to synchronize with concurrent GUP-fast walkers. However, if the TLB flush already reaches all CPUs, the second IPI is redundant. GUP-fast runs with IRQs disabled, so when the TLB flush IPI completes, any concurrent GUP-fast must have finished. We now track whether IPIs were actually sent during TLB flush. We pass the mmu_gather context through the flush path, and native_flush_tlb_multi() sets a flag when sending IPIs. Works with PV and INVLPGB since only native_flush_tlb_multi() sets the flag - no matter what replaces pv_ops.mmu.flush_tlb_multi or whether INVLPGB is available. David Hildenbrand did the initial implementation. I built on his work and relied on off-list discussions to push it further - thanks a lot David! v2 -> v3: - Complete rewrite: use dynamic IPI tracking instead of static checks (per Dave Hansen, thanks!) - Track IPIs via mmu_gather: native_flush_tlb_multi() sets flag when actually sending IPIs - Motivation for skipping redundant IPIs explained by David: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ - https://lore.kernel.org/linux-mm/20251229145245.85452-1-lance.yang@linux.dev/ v1 -> v2: - Fix cover letter encoding to resolve send-email issues. Apologies for any email flood caused by the failed send attempts :( RFC -> v1: - Use a callback function in pv_mmu_ops instead of comparing function pointers (per David) - Embed the check directly in tlb_remove_table_sync_one() instead of requiring every caller to check explicitly (per David) - Move tlb_table_flush_implies_ipi_broadcast() outside of CONFIG_MMU_GATHER_RCU_TABLE_FREE to fix build error on architectures that don't enable this config. https://lore.kernel.org/oe-kbuild-all/202512142156.cShiu6PU-lkp@intel.com/ - https://lore.kernel.org/linux-mm/20251213080038.10917-1-lance.yang@linux.dev/ Lance Yang (2): mm/tlb: skip redundant IPI when TLB flush already synchronized mm: introduce pmdp_collapse_flush_sync() to skip redundant IPI arch/x86/include/asm/tlb.h | 3 ++- arch/x86/include/asm/tlbflush.h | 9 +++++---- arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/ldt.c | 2 +- arch/x86/mm/tlb.c | 22 +++++++++++++++------ include/asm-generic/tlb.h | 14 +++++++++----- include/linux/pgtable.h | 13 +++++++++---- mm/khugepaged.c | 9 +++------ mm/mmu_gather.c | 26 ++++++++++++++++++------- mm/pgtable-generic.c | 34 +++++++++++++++++++++++++++++++++ 10 files changed, 99 insertions(+), 35 deletions(-) -- 2.49.0