From nobody Sun Feb 8 11:43:19 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 3A95132A3C9 for ; Mon, 29 Dec 2025 14:31:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767018675; cv=none; b=Op32e3VcfagZC4INSSQZLB0w2FkeKbIKrFR7P3PpX3IN0d4G+JPvUvgijaAjfjRW+ZxwWkhLLRFN1RwXY7125UCuoYbREyhSUxydc5WKs82zBIH75335xrrGn+3SOkxssWMTfqgUu+e9F/hSnah4ZH9Qg+QXp0p/EPtS8/Eo66o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767018675; c=relaxed/simple; bh=m4iHj+AwFx2PCF5x5k1miVOJkb/O+RupWNG1Z8Fowrc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qUTj3jr1koUi8/v+lN0DVZoZMNq2jg4Dph3iQA57nlvQxZULfLuBh2+Dp7IqjMOYmaebOKYq4XcxXqW1OyHJq7wIoQyGjnmLeAa/Sai/QMnCUdnFbcq9J7eIk4PMKK6aahieQiCpvrRev8wgAPVNmJ7Tv/4zAkFVTjVAFaM6wGQ= 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.178 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-f178.google.com with SMTP id d2e1a72fcca58-7bb710d1d1dso12739844b3a.1 for ; Mon, 29 Dec 2025 06:31:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767018673; x=1767623473; 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=ZldRDJqtH1ig79a3NbAjYulmXt3x4GlRPqkLpWEwBdc=; b=jDUWnpaZGLQ7gyqkbU+lP4CVEzu6iwuYUI8gNR7PWlsXpHFzvScwqWUSPVTsFwRJ0N nySfuscQ5MmfakMcqGK/12xT9eK7ijTKO2F/q8abx/F878R4KK9zvn5L5NOjGW1y0QYs uUfqVcVWyvRqJlU2HGEeqMffxHqEKHlY6dLnQLlzRAtF2/KIIH6lCsa8bLgTzAw9/uyO lHsYLafa+q3rwHQmUYJoGs7TPN6wzh3WUptEOw0bZ8vnifnH4Ah5Tx1oqxV0c3uizCZq l0u+S47MQGp8PgTiUXAW5y0RatoxeMAN0iBVoTjHDnbB/n22hVb1NB7Iyk1sQSmrPF2n uRhg== X-Forwarded-Encrypted: i=1; AJvYcCVn4yJ25v7je7EMwAOOh2czUz0ZR7vn8MpVTyEeaqdPpPWsXRie4ZzaI9zPMVMGrUUu15HJCRsa1MgWqDA=@vger.kernel.org X-Gm-Message-State: AOJu0YxfUD4hT4iPZWosRRwlZGv5rxhUzjXliwiM1s2x4w+XiQFBuvyo 81NG8HbVNVZiGf2zAqfopiL/4B0NQMynW/0CSwQIESPVlWNTi6/f6kS1 X-Gm-Gg: AY/fxX7erFImQjts59GkA4TlK1XxbQuopSQfLiujW3ZdXJApzpGJbuf5He/clqAIMcW P5ImdXxeJUVWl+iP99Pld5mqvNR40H0lwNktJlm1jNfDnJt/Tz6NG+KDODQJor3fvA5VDK8TM3J lDkcfIctE5njrOuPISyE8mMu/Yrb+0NCTKs8nvGhxNsJYACYgLNoEK4TaICiEdAwvtmv+HFPIdM I0E3oAf/cZXcL9HqXaY1/kWWTAKaDeb5KbiWUVOsni23zxrXJ6vT2qC0Jkobe5jFX2DLTLtvk8N a5Pa2saWvkIHpjBnu9JomgO118b9nP/ak89QW7dcJJFaktgkoYH+K4yg2bmEFZe7lo3qRejZAZm Bbt66sDgvWqEY9O6bB7gES4dWJ+eC26Z//gaJDPiAQ48s9uXEIRYif19MBvPQQ5bWGdvlgBRD9e M9iFVD+ngUvwIWe9qMh8fT X-Google-Smtp-Source: AGHT+IFcZGgxztN2EeAun4quNpAXXOKNWX6LSnFOxrijtlTfhRDRGQK0tPKQ/9UZzDdFUSs+EvX5Jw== X-Received: by 2002:aa7:9a85:0:b0:7f7:5d81:172b with SMTP id d2e1a72fcca58-7ff664807a0mr29842840b3a.42.1767018672206; Mon, 29 Dec 2025 06:31:12 -0800 (PST) Received: from EBJ9932692.tcent.cn ([103.88.46.167]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7dfac28fsm29705159b3a.32.2025.12.29.06.31.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Dec 2025 06:31:11 -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 RESEND v1 2/3] x86/mm: implement redundant IPI elimination for page table operations Date: Mon, 29 Dec 2025 22:30:32 +0800 Message-ID: <20251229143038.73315-3-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251229143038.73315-1-lance.yang@linux.dev> References: <20251229143038.73315-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 Add a callback function flush_tlb_multi_implies_ipi_broadcast to pv_mmu_ops to explicitly track whether flush_tlb_multi IPIs provide sufficient synchronization for GUP-fast when freeing or unsharing page tables. Pass both freed_tables and unshared_tables to flush_tlb_mm_range() to ensure lazy-TLB CPUs receive IPIs and flush their paging-structure caches: flush_tlb_mm_range(..., freed_tables || unshared_tables); Suggested-by: David Hildenbrand (Red Hat) Signed-off-by: Lance Yang --- arch/x86/include/asm/paravirt_types.h | 6 ++++++ arch/x86/include/asm/tlb.h | 19 ++++++++++++++++++- arch/x86/kernel/paravirt.c | 10 ++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/p= aravirt_types.h index 3502939415ad..a5bd0983da1f 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -133,6 +133,12 @@ struct pv_mmu_ops { void (*flush_tlb_multi)(const struct cpumask *cpus, const struct flush_tlb_info *info); =20 + /* + * Indicates whether flush_tlb_multi IPIs provide sufficient + * synchronization for GUP-fast when freeing or unsharing page tables. + */ + bool (*flush_tlb_multi_implies_ipi_broadcast)(void); + /* Hook for intercepting the destruction of an mm_struct. */ void (*exit_mmap)(struct mm_struct *mm); void (*notify_page_enc_status_changed)(unsigned long pfn, int npages, boo= l enc); diff --git a/arch/x86/include/asm/tlb.h b/arch/x86/include/asm/tlb.h index 866ea78ba156..3a7cdfdcea8e 100644 --- a/arch/x86/include/asm/tlb.h +++ b/arch/x86/include/asm/tlb.h @@ -5,10 +5,26 @@ #define tlb_flush tlb_flush static inline void tlb_flush(struct mmu_gather *tlb); =20 +#define tlb_table_flush_implies_ipi_broadcast tlb_table_flush_implies_ipi_= broadcast +static inline bool tlb_table_flush_implies_ipi_broadcast(void); + #include #include #include #include +#include + +static inline bool tlb_table_flush_implies_ipi_broadcast(void) +{ +#ifdef CONFIG_PARAVIRT + if (pv_ops.mmu.flush_tlb_multi_implies_ipi_broadcast) + return pv_ops.mmu.flush_tlb_multi_implies_ipi_broadcast(); + + return false; +#else + return !cpu_feature_enabled(X86_FEATURE_INVLPGB); +#endif +} =20 static inline void tlb_flush(struct mmu_gather *tlb) { @@ -20,7 +36,8 @@ static inline void tlb_flush(struct mmu_gather *tlb) end =3D tlb->end; } =20 - flush_tlb_mm_range(tlb->mm, start, end, stride_shift, tlb->freed_tables); + flush_tlb_mm_range(tlb->mm, start, end, stride_shift, + tlb->freed_tables || tlb->unshared_tables); } =20 static inline void invlpg(unsigned long addr) diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index ab3e172dcc69..4eaa44800b39 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -60,6 +60,15 @@ void __init native_pv_lock_init(void) static_branch_enable(&virt_spin_lock_key); } =20 +static bool native_flush_tlb_multi_implies_ipi_broadcast(void) +{ + /* Paravirt may use hypercalls that don't send real IPIs. */ + if (pv_ops.mmu.flush_tlb_multi !=3D native_flush_tlb_multi) + return false; + + return !cpu_feature_enabled(X86_FEATURE_INVLPGB); +} + struct static_key paravirt_steal_enabled; struct static_key paravirt_steal_rq_enabled; =20 @@ -173,6 +182,7 @@ struct paravirt_patch_template pv_ops =3D { .mmu.flush_tlb_kernel =3D native_flush_tlb_global, .mmu.flush_tlb_one_user =3D native_flush_tlb_one_user, .mmu.flush_tlb_multi =3D native_flush_tlb_multi, + .mmu.flush_tlb_multi_implies_ipi_broadcast =3D native_flush_tlb_multi_imp= lies_ipi_broadcast, =20 .mmu.exit_mmap =3D paravirt_nop, .mmu.notify_page_enc_status_changed =3D paravirt_nop, --=20 2.49.0