From nobody Sun Feb 8 13:09:05 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 2960E315D49 for ; Mon, 29 Dec 2025 14:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767019093; cv=none; b=M9MCPSkyStGj8y0A/vduvDQVDzOQYJpvHjb19HTydbI1rjLeX8SGotGoYvTeEInjxLSczWihueDmSLhuRvldUu0/SWaqSrMnqmvSli2EMgjaNd6r548bcSlwlDyCeqPzYmkUpF8lBpIMWkWgO/izVmAUmHLYEGNE7f6Aas1ltfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767019093; c=relaxed/simple; bh=m4iHj+AwFx2PCF5x5k1miVOJkb/O+RupWNG1Z8Fowrc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JuF+MyYy95o9MAvCw3ElsYfUdTnBkCfPzCs5yad4/B9CYehvg3slGQ5IKkJB+HrwC9flEFJ6UUCbXfdMd6hdsW/ZUGjw9byjgT7rCRQPugfwko57YFsiPL0Ee6YX/Vid/aQiLPe6HXf4anPENMH6hX3yvhKrIAHe6ztXAHa/6KU= 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.173 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-f173.google.com with SMTP id d9443c01a7336-2a0c09bb78cso66632325ad.0 for ; Mon, 29 Dec 2025 06:38:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767019089; x=1767623889; 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=KJyO1JQGNthNR1WUwDbEhOjD0vXf03uv76DZkpXNCGN0R/NnRzX+K+BSt9Fl4U7sJn +6tk1mURmCNcDBM9t6+8OibB0/tYuqNbI1IHFLwnQs876BBq7+KyaEVKXoJZqCQToIu8 Sp20Q1o+nR6GN+OEMo9zPcohsScw6GQPWpegZoRW+Gk2m82H2wuhyfG0R+wykMqlJNY3 r9FojluZxRcrFXL1yIVLINUt5neT0OOe1ZzfZpaqHct4AkDLxynUlgW99yoY9sOwKBbU CgO7IiYtbleu5+XVoALTarFuqPr8lyVxpQWwr8Ty0MNhgEcTDocx0vDW1t94zTBtsa6T M3vQ== X-Forwarded-Encrypted: i=1; AJvYcCXGninA5sUex+HZ7g+2aPZeIXLfzzxmZYBVyTMUPliqY0j6ENscTAFOyA6vulTJBldapt6q0mkJtHPfb+U=@vger.kernel.org X-Gm-Message-State: AOJu0YwOnNi9aarXXVffl206zlTnzqmbfRs+KztnITkYjBTgTnfAuDkI 7RpbdU/cTkAJ5gxcJcFkM6EbIzbaqZcgea3ZteDyhXiDsa8GbonEKJQj X-Gm-Gg: AY/fxX4lXUs+6I6KEHo99caY8d3JztzxxpBISkUzptDc+3c3HMlzDGBqgeOtCgdmmYT jrgtzCQUAgkswlB8MeUI1yrl5MYFgOdEBOG4vHVPVIYG2+ZLX/IogUGcuiVH2fczk/LOAgKB3FQ ZNhGno/SBEcmkMHVRDWEGh8Gem0X3VzcBfUCYqK1teikw8Xd1PPJeyYJsqHRIwP1cv3u10g6R5N M7tb0ae2/i9d0I5B9UZms8vm9uRhXXCcJXmXMbi1PpeYq5dNpI460Aq6io66qNAmgB4+SkMnjSA qrG3WzqZx4qvhJe79/EXZDITxduJW9rk+sQS9lYRQeqqXYf0lnRdR2JhtclzSIwfWVy1h9yHP89 rtJYbGxSBTay5fusqsTXzDiz27fSII7owyzWjwkXs1PY4qzyGj8lQpOytBVW70aDs9WFKKPC6Rj jHCEYwtPtqo/MpBr9utmTS X-Google-Smtp-Source: AGHT+IGbzQsFnxYP9S+gBanduwTJYp5i/avcPenp0gxUy3BJDakAIqFIQWIEeOZwEbX1DJzlvouniA== X-Received: by 2002:a17:902:cf0d:b0:298:45e5:54a4 with SMTP id d9443c01a7336-2a2f0caa6fdmr287168855ad.1.1767019089301; Mon, 29 Dec 2025 06:38:09 -0800 (PST) Received: from EBJ9932692.tcent.cn ([45.8.220.167]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3d7736fsm279669625ad.92.2025.12.29.06.38.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Dec 2025 06:38:08 -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:36:56 +0800 Message-ID: <20251229143657.76968-3-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251229143657.76968-1-lance.yang@linux.dev> References: <20251229143657.76968-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