From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 7F216274B28 for ; Mon, 29 Dec 2025 14:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017615; cv=none; b=fv8LZ+Lg2pSQq6goR8XrtBwwhrDLwSr3BzPeS/BQL21l31FhgeC8jg/OQLPRMsB6w42GJ7gAkipbuJ0pllkFml3uOJTa79VY8Ya5NrWJ9cC6zjMUSR/vThbCBGabVo5Tf7ZiJe55gTXL7MpsrU9owK3MuoSuCYrHFxQJB9nV6iM= 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.179 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-f179.google.com with SMTP id d2e1a72fcca58-7b7828bf7bcso10601107b3a.2 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=JOBMqqQA9WONG4g+lABufrR2URv5FKrlH3AY669bcYUmBrRrjb1616YrvfxaY635Z/ 80PD1ahpOFrv5UwSzS8JHEj90z8kh3Xb0dM7sgnarO7JdTbPIERmEn74gFz4BmEvoj+w YjqKaIwKhTLSLKC+ptvjnIRoxC4X9WQYTkeMMl7RycpZ+GWhgMdv9lYc57+Aagg349pd 4AeL2XEquAofMoF0BWZCYzjs/n3JufbG9lhV7GD6U/pbpl3uDSyOYKOuRl3qMShXJ4+E nQKOrRJoUIV/DqCb3qLgwFkVzyXhJ70rUFBPfmyCHKUQSaAwfJNdWv3tP3U5epgCTvXk thOg== X-Forwarded-Encrypted: i=1; AJvYcCVtSfgelEAtEqUvPd6i7+pETd95nlO6n/VopOHbjsbdzHoothE24/5zjbqNuwMFNMh8rnG7+8Hx1dhf@vger.kernel.org X-Gm-Message-State: AOJu0YyGehEjHqMPVeL/WIKGC2/7rEHFZ/iy8j7og7CCudccLXs4zk2B pauM4kp5FJDUjWDl8tCAx0goZOKVloHGnCgCg6+0qvkIKGkYG7cqt5DA X-Gm-Gg: AY/fxX7rT4yQiSBidB7pWzmPlqN5WsspiAxSxPgDWqUmMX8N5beWSdRnpX03qOaCy1/ nErd8Fcbdcz5gleuV9+3uYJbHpeh/2iuAyw7T8V/47e+05WfT/l7FPQe4RTqUtinnG6oe2vgjpr 3Zo3FFsEI4doQbjxX+/arKdAWoLB+nKzLEHq8unJezBqZsl9crJC/i3ypI1SzAYtScYu3QwB6bO dz0uao6h7cJzDm4/QL+cXF6/7dWAm3fJtADu6JaUDDake2E/J/0OI6n3ak8O6qWVoQY/r+n61tR RokeXZ66TtzyesH5TS57Pa5S3dpXjuYH27yh66AidUVMGYuzBCnf+iXOgdSdYgfsma8DSmC5lFz 8NSZ0hDbbJ/v8G7z28dSZNWYXtAd/bYLsSW4bbpSmK/6vJNmoqGHnXi8mg+QPCpOtlaVvV1M92Q 4yZuMtCC2J1g3ZoPO/1o6Z 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-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=true or unshared_tables=true 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 = true) -> flush_tlb_multi(mm_cpumask(mm), info) So freed_tables=true 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 = true) -> flush_tlb_multi(mm_cpumask(mm), info) unshared_tables=true (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 = 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=true, and this should work too. Why is tlb->freed_tables guaranteed? Because callers like pte_free_tlb() (via free_pte_range) set freed_tables=true before calling __pte_free_tlb(), which then calls tlb_remove_table(). We cannot free page tables without freed_tables=true. Note that tlb_remove_table_sync_one() was a NOP on bare metal x86 (CONFIG_MMU_GATHER_RCU_TABLE_FREE=n) 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) 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. -- 2.49.0