From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 1255A23A994 for ; Sat, 13 Dec 2025 08:01:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765612873; cv=none; b=BewdfvkaXFnZhc8bxR7C9KubNJ7JjhwJ1NUTiaDYccW+TwNMR3Io12WtRxtnBNoCwaHhRPuvRFPStGYQ6NKCwUbnp0+tKNEiV5ryJPUtfOaXyx2CykX3ds4wAQKP8CdWRNgHzu4g7iXT7Am/J2I2fOjyRp1oKFQq+4r8T0KKO70= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765612873; c=relaxed/simple; bh=BcvVy/2hQ35U0ulolpe9ekEUJgrhZcDUmd2SZgR1tmw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OZ+41yvXgtOXNKnclnuujThlaJsqT7EY5eZUuuLDDANkeprbt8KXnJM1IDCTqEBO8Y8BbDRY0i7ux7uKZiroUe3gahzGFW1RGunPrGG01OyGZKw2kuw45+YnsjRBzym8+qLvMiuJb8VfDSzQqVFDp2tiu9/KkJ1VJ77Wv/xERaE= 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.214.171 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-pl1-f171.google.com with SMTP id d9443c01a7336-297dd95ffe4so18989355ad.3 for ; Sat, 13 Dec 2025 00:01:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765612871; x=1766217671; 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=IKeRxMOvOPVkMEpeJrhYXUzwhdbko1M2EXmC4O4D0Xg=; b=qQOFXXuFB+1DrWUNepSEYs9elnbQMdsSCzZtU5C7K7Hu/XpnXsD0vLl2yVB1Rw902K ssKzwvgsfyJXeU7XTuXva3ITNuolOfIDqOJctRTjw6Dn+fIUSVFS9tFz/wQH0HqOePy8 ekDzDhbM0JC6GuPD7+hN5IWf3R2f02Pj4lVnjN58EJwMfv6kw2yqU1J/nywPTnw4mLuc MCI2iFvqd4RdcMsqXrIBSHHVDOB/+BBOfbHOtvTzFwqsr4H8qemVzYaOsj+8jjMfl8JE y5y2sEML2LkLe6YoKkDjRxenviHY7RMGaqwAaLh5gyB3DhpdB5GWRBuauUjt0RRCqlpd ActQ== X-Forwarded-Encrypted: i=1; AJvYcCX6b1SBGixRCqe/fcN29ThWOjmEK2pHGtTGd7dGCvOfWuYtRtY6JkZDem5+/+liS2nuyRIAezq+chnIS8U=@vger.kernel.org X-Gm-Message-State: AOJu0YxOWWYiHCpK578XuF9/45MpEvN+Pi/stmkKLPDS5T6qiTI3foCe aIyha/lflcBw0oUey+P/EEExw6xsMq0eqgE5JYgUFN30gvG+AOoqVNsH X-Gm-Gg: AY/fxX74Kk0DSpVxsroPPfKifph4SpAiwjQReKhbwE6IPXRb1CxE2MPYbVVksxQby7N TjemG3xAA7UwBjQrXNgmPrYPfrqJBTBfSJsZ3SgYFVUHQK87RIbeDzOP2QKCC1uU5vjLMxM/wiG UCCdIXJM36iZr/megeAzs0rttwl+SAgPBmVqcrPTJzMEp5ZP4ZhTUjYPsmlt4T4zwPZf/h/d5sW uCPJ42M8nlbx5LcygP+DJFHlw6/RszqsgsaqXIHwD1TglOfD9xb9/lbVQD81WhYE3nHOcRXHCI+ 5XkECiPvY/FBDsCQP4txUbQkTKatxCJn6zKmDhQ42aaQTTEXiYRB+QAarmf9rlP5gY4h5a6C2n+ Bm9/ZnSCeIm+yW4wq+r8CzLvmfja820oYPM/SVS+YHifQfpYR4Jf5NVOrcnu5jXsdpZbLAvEOkk 6PFIzBeOMfQ25swwL/jDlXR8KYRw== X-Google-Smtp-Source: AGHT+IF+7XHnXgrhyzygY7I1rYSWeg9b2h4e3tV2K6rz3wu/Ladawz1GxFoLm3IkAXfgeDDX1CPE4w== X-Received: by 2002:a17:903:8cc:b0:297:f0a8:e84c with SMTP id d9443c01a7336-29f24386514mr51433605ad.52.1765612871142; Sat, 13 Dec 2025 00:01:11 -0800 (PST) Received: from localhost.localdomain ([45.142.165.134]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29f05287fa3sm53149155ad.5.2025.12.13.00.01.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 13 Dec 2025 00:01:10 -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 RFC 1/3] mm/tlb: allow architectures to skip redundant TLB sync IPIs Date: Sat, 13 Dec 2025 16:00:23 +0800 Message-ID: <20251213080038.10917-2-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251213080038.10917-1-lance.yang@linux.dev> References: <20251213080038.10917-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 From: Lance Yang When unsharing hugetlb PMD page tables, we currently 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. Add tlb_table_flush_implies_ipi_broadcast() to let architectures indicate their TLB flush provides full synchronization, enabling the redundant IPI to be skipped. The default implementation returns false to maintain current behavior. Suggested-by: David Hildenbrand (Red Hat) Signed-off-by: Lance Yang --- include/asm-generic/tlb.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 324a21f53b64..3f0add95604f 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -248,6 +248,21 @@ static inline void tlb_remove_table(struct mmu_gather *tlb, void *table) #define tlb_needs_table_invalidate() (true) #endif +/* + * Architectures can override if their TLB flush already broadcasts IPIs to all + * CPUs when freeing or unsharing page tables. + * + * Return true only when the flush guarantees: + * - IPIs reach all CPUs with potentially stale paging-structure cache entries + * - Synchronization with IRQ-disabled code like GUP-fast + */ +#ifndef tlb_table_flush_implies_ipi_broadcast +static inline bool tlb_table_flush_implies_ipi_broadcast(void) +{ + return false; +} +#endif + void tlb_remove_table_sync_one(void); #else @@ -829,12 +844,17 @@ static inline void tlb_flush_unshared_tables(struct mmu_gather *tlb) * We only perform this when we are the last sharer of a page table, * as the IPI will reach all CPUs: any GUP-fast. * + * However, if the TLB flush already synchronized with other CPUs + * (indicated by tlb_table_flush_implies_ipi_broadcast()), we can skip + * the additional IPI. + * * Note that on configs where tlb_remove_table_sync_one() is a NOP, * the expectation is that the tlb_flush_mmu_tlbonly() would have issued * required IPIs already for us. */ if (tlb->fully_unshared_tables) { - tlb_remove_table_sync_one(); + if (!tlb_table_flush_implies_ipi_broadcast()) + tlb_remove_table_sync_one(); tlb->fully_unshared_tables = false; } } -- 2.49.0