From nobody Sat Feb 7 21:14:54 2026 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.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 98E6721ADC7 for ; Mon, 29 Dec 2025 14:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017615; cv=none; b=fDeGliD0CW9DbtU4IdvIuwLSuo7W0H+wAL2cNrVnM5zkpy/FyvRCweZlwwQ6qZ0NLW0EIfWMDU7tM/xj0oqFJ+Jp0ycEjYT4CvEVHNphEs5dlvuKJK2Ikd7+aaaE5beMCd4PtDdfh01r2atbkaR651unyiLUw1h5LR/fg9M2ClM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017615; c=relaxed/simple; bh=QELGmcYo0okd7XeZ+8OIMQ2Ox7GoXMWa9Ttw3qK5W4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RXSuDU468iCx3+QNvrs3qIHSTC0SdCa7oG2eUFzM+ap4Mfq2vpoY/v4Wm0LYFpaV/yigIi9hhl56Y6eN0sxHC1pXvMF32f5svMUukdQrnb9hvNNer5i21W0LNCeJR+X09AO2+ErGp2gxSeRLHnc9rRMhkDGC0/SczBYbiJ1QDpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7b80fed1505so9168901b3a.3 for ; Mon, 29 Dec 2025 06:13:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767017613; x=1767622413; 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=K2pBV4vyT2c4GBUcrUp/G3rP2JcNWZOiRH8LtGLdyis=; b=Fc8hYQlyOVgOVCY1ROcGSwzo5rkj00pBuJasheaSZDEof61gi93n6Rkks/xOr0FB14 LODHonWWvZ6AebpKGfe+chDuBUS2+sLMyQ88J7crKG3GGAL8Jz2MioUngp66MlS+iIbl JjkNH9h6pnyhACfdob1aUwLTn6I7v1D6d1piA5q9a2/ljtyODgX55E6S2d8uJD9ovFsP R6KphjKEreV8nBMcWShWQz9KaWQxlk15ZdmD0zC9k0Bh38CXameCjc5efQyO10ZOFjVa evteiwAWxqI7zILOoZaMnxmkYC/3gvIfEk8wb9Xmuo1ROORvAlXybG5CcCA3x1UUtIrG ovdw== X-Forwarded-Encrypted: i=1; AJvYcCVuQIlw1v2BsQ1bpLIuhlmjlcTpTINngIIS9s6c9Zu/21uw3EnPrcPqbwamMzEa5rI+HFpQA/mb6JI9yNE=@vger.kernel.org X-Gm-Message-State: AOJu0YxBRyRL4uWQPPSqmUHg9pNqr/6rK93PXm+LxKlfRnM/NrYfCVcp kbnOklNr+8hmObntRB11ftST6hkqoY5yuojwKnJuq+ACMciSpxvBVi7r X-Gm-Gg: AY/fxX72C/j2VzpfF5c42reyYMGUOwwXb17NVWbhzOI2CCHJ/8LaAmBb8Dxh4rzoW2r YdBXCdOrqIkBa4w37Z2VP07kwkwA8nTU6qZZoNT2aJtlvlWtWJ6v4QJjdGM+2kqwlwdDISlhCZd PslLYJCj3tJcEQ2NF9boCcN++T4JDf2UHXzLv1hyT3prEUNVU2sBm0AlSncjEg6OYOoJZPnvgcy us71DfAPGHvQGRky86b+zoOLixNoHYyuhOp6J4mEpS8+KKR8XCKJT+jxFU4RuabXheJ3WM7QFi0 FG22BEmuxVhx1mvuJNUmU54UbndWkyNZetVgVcmkPfgmGq2ljH8VtjXkqN5rWRWY6Y20+CNYhFM eJtzkT/JmcYdg34WDWuHpiDeTAHpXGnfmMpRACYqP5YXMDX1mYqVwcif5USr9pFhxgYux3EUxFz +thG6E4vPWKlg1nhg9PpGI X-Google-Smtp-Source: AGHT+IEQcka9ib1s/U4Ml1PaEUtFGR87vhYFW2tWQf/4rd0WuelWAoKlS5mhRUJT7d3+jGEwNTk6bw== X-Received: by 2002:a05:6a00:450c:b0:7e8:4398:b373 with SMTP id d2e1a72fcca58-7ff66d5f557mr25343417b3a.70.1767017612759; Mon, 29 Dec 2025 06:13:32 -0800 (PST) Received: from EBJ9932692.tcent.cn ([103.88.46.167]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7a93ab3csm29472636b3a.7.2025.12.29.06.13.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Dec 2025 06:13:32 -0800 (PST) From: Lance Yang To: akpm@linux-foundation.org Cc: will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, david@kernel.org, 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, ioworker0@gmail.com, shy828301@gmail.com, riel@surriel.com, jannh@google.com, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lance Yang Subject: [PATCH v1 3/3] mm: embed TLB flush IPI check in tlb_remove_table_sync_one() Date: Mon, 29 Dec 2025 22:12:45 +0800 Message-ID: <20251229141246.63435-4-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251229141246.63435-1-lance.yang@linux.dev> References: <20251229141246.63435-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Lance Yang Embed the tlb_table_flush_implies_ipi_broadcast() check directly inside tlb_remove_table_sync_one() instead of requiring every caller to check it explicitly. This relies on callers to do the right thing: flush with freed_tables=3Dtrue or unshared_tables=3Dtrue beforehand. All existing callers satisfy this requirement: 1. mm/khugepaged.c:1188 (collapse_huge_page): pmdp_collapse_flush(vma, address, pmd) -> flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE) -> flush_tlb_mm_range(mm, ..., freed_tables =3D true) -> flush_tlb_multi(mm_cpumask(mm), info) So freed_tables=3Dtrue before calling tlb_remove_table_sync_one(). 2. include/asm-generic/tlb.h:861 (tlb_flush_unshared_tables): tlb_flush_mmu_tlbonly(tlb) -> tlb_flush(tlb) -> flush_tlb_mm_range(mm, ..., unshared_tables =3D true) -> flush_tlb_multi(mm_cpumask(mm), info) unshared_tables=3Dtrue (equivalent to freed_tables for sending IPIs). 3. mm/mmu_gather.c:341 (__tlb_remove_table_one): When we can't allocate a batch page in tlb_remove_table(), we do: tlb_table_invalidate(tlb) -> tlb_flush_mmu_tlbonly(tlb) -> flush_tlb_mm_range(mm, ..., freed_tables =3D true) -> flush_tlb_multi(mm_cpumask(mm), info) Then: tlb_remove_table_one(table) -> __tlb_remove_table_one(table) // if !CONFIG_PT_RECLAIM -> tlb_remove_table_sync_one() freed_tables=3Dtrue, and this should work too. Why is tlb->freed_tables guaranteed? Because callers like pte_free_tlb() (via free_pte_range) set freed_tables=3Dtrue before calling __pte_free_tlb(), which then calls tlb_remove_table(). We cannot free page tables without freed_tables=3Dtrue. Note that tlb_remove_table_sync_one() was a NOP on bare metal x86 (CONFIG_MMU_GATHER_RCU_TABLE_FREE=3Dn) before commit a37259732a7d ("x86/mm: Make MMU_GATHER_RCU_TABLE_FREE unconditional"). 4-5. mm/khugepaged.c:1683,1819 (pmdp_get_lockless_sync macro): Same as #1. These also use pmdp_collapse_flush() beforehand. Suggested-by: David Hildenbrand (Red Hat) Signed-off-by: Lance Yang --- mm/mmu_gather.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index 7468ec388455..7b588643cbae 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -276,6 +276,10 @@ static void tlb_remove_table_smp_sync(void *arg) =20 void tlb_remove_table_sync_one(void) { + /* Skip the IPI if the TLB flush already synchronized with other CPUs. */ + if (tlb_table_flush_implies_ipi_broadcast()) + return; + /* * This isn't an RCU grace period and hence the page-tables cannot be * assumed to be actually RCU-freed. --=20 2.49.0