From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 E8AA74A23 for ; Sat, 13 Dec 2025 08:01:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765612884; cv=none; b=BbguJEwqoqfT4k089PltvnKwOBKpdh0bqkz5fY7JcDsb2umyN5rcH9fih38532K4z/pU5k+Q0lQIlbDPJTBfYnQOA8o/3g6G68T7pyqqneI/aN2sgLCoO0v2zmiNC9+Y2zFvLYV+2ql0i5cMruMVs4vsbbFMyqyCJkYNGG5LZtA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765612884; c=relaxed/simple; bh=pe/gvSlFR4wYZnv6+kYhhiB5IBjAo8oNhXAavMlFV78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fls7yoIOtRrTvnXnwkRql3SKBe3t0DkV0EfvQku9TBu0UGYpNdnlNoI54Gch4Ddh1ZHwHTLN7uzs+UPi4W8f09d3eetBkSCTFBmvYB12UeyorK68DbAE8Yk+sCtHIKDMuKNqJp1FQ35RfuydoXgBHyKrkO5t6w+akW1LsXYJ6b8= 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.177 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-f177.google.com with SMTP id d9443c01a7336-29f1bc40b35so24322485ad.2 for ; Sat, 13 Dec 2025 00:01:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765612882; x=1766217682; 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=hO0mmOrLQtX2f+WnOsj3vCPvjsJC7haFxv/QfsLP6Js=; b=Vmt93qZYQ3B1SBo6HIqXRDjlVSOnZuhW2LbAcq8GUlXRJnDQndkV1+G5+RuQN32k1+ VT9KDg1y1Dkk6n56yID+V9enCM9uAr+nPxo/nmkruIxK/+uPwtYq2hcSptocdbweLTQe 1PEAd5ZEMJZxVFxR55TUsGl5tJ8TLJGFv9K7FY8e5V278AskCmC3jvitfxAwe6JnredL SSxzdePfuB4T61FR0u5c7NwTgwIJSTdRmcAxMFP+m+XVFMiERrBzqdSKbAQcDAuKL4cs 2RN20Fdyzuuoqg1Kd3sTOqlR4L1LgSX3KKOa5tD0k6hLUzBQiRUTDUF75bWtG+XElWvS VFkQ== X-Forwarded-Encrypted: i=1; AJvYcCUI0NE65H3GGC3BQEki/NxQrHXlowY0IBaz1kHkXCUgxIuVGgGuNSzYxcDh7GsTlS/Pt54CEP7IVGyGLpI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+hZyGFMfdfF+bmGohCyUJSwWibdqjs9S1k4/DyzSMgJjebZhP s3L7rpuiheB8TFmNTZl2ayt+nAx++jMovQ6+x0KmtiGqyD7BwdCz0rOn X-Gm-Gg: AY/fxX6OEFvFcUIrmsjs/+XFy+poxfI6BzFho7rVhMY0SOFH3/fSyHZWwOnnVURhoqB +rrZGR7QAcpDNqcppsMcoeiCXEYndbXtgSqJbhOvXS8mGJ7zk0vfXzx7vxR7ibr2qkAui7ibX2Z v5AnEpyqMNJ332u1FGu7vH6VaN3oy79CkzKauUNxS/ECoecveemvq2XZ8P15M/WHH8B9ERqvfYE HeRY8j8rnq9EUyPOT/ga40jMCKRg/+A7M9GrIY+x8+ys2689BgEAGgc6codWrXojk0KGiY132v0 uJr5ew8ofPpMOKVTGprFjZ0UatmLB3LKF13t91nm8uyoKMO7WeY208F3cs6up1UhM/9QnRrVOqL THPZU8KeYmhokkIBIS3YFU8k2TK4mqLx3XxokWKv+QcBXKtDlFB94Xl2eeMWp2f44OGxuzxILPt rEq9o0D7Obz1Lm7RmKPPx2Ghr0ew== X-Google-Smtp-Source: AGHT+IHVDW7jzJQJmTW2QCX77VaaJ/gbOI8PVom/MrydMKNXuHfqI/AK6StmWZkRHj080xHzVr0NUw== X-Received: by 2002:a17:903:11d0:b0:297:fc22:3ab2 with SMTP id d9443c01a7336-29f23c7336emr45692435ad.36.1765612882029; Sat, 13 Dec 2025 00:01:22 -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.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 13 Dec 2025 00:01:21 -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 2/3] x86/mm: implement redundant IPI elimination for PMD unsharing Date: Sat, 13 Dec 2025 16:00:24 +0800 Message-ID: <20251213080038.10917-3-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 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); Implement tlb_table_flush_implies_ipi_broadcast() for x86: on native x86 without paravirt or INVLPGB, the TLB flush IPI already provides necessary synchronization, allowing the second IPI to be skipped. For paravirt with non-native flush_tlb_multi and for INVLPGB, conservatively keep both IPIs. Suggested-by: David Hildenbrand (Red Hat) Signed-off-by: Lance Yang --- arch/x86/include/asm/tlb.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/tlb.h b/arch/x86/include/asm/tlb.h index 866ea78ba156..96602b7b7210 100644 --- a/arch/x86/include/asm/tlb.h +++ b/arch/x86/include/asm/tlb.h @@ -5,10 +5,24 @@ #define tlb_flush tlb_flush static inline void tlb_flush(struct mmu_gather *tlb); +#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 + /* Paravirt may use hypercalls that don't send real IPIs. */ + if (pv_ops.mmu.flush_tlb_multi != native_flush_tlb_multi) + return false; +#endif + return !cpu_feature_enabled(X86_FEATURE_INVLPGB); +} static inline void tlb_flush(struct mmu_gather *tlb) { @@ -20,7 +34,8 @@ static inline void tlb_flush(struct mmu_gather *tlb) end = tlb->end; } - 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); } static inline void invlpg(unsigned long addr) -- 2.49.0