Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=13.77.154.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796099819; b=n1xYhnR7g1Gz8RKFuToP7ZZ9TPgI4EEna61qtAnPT5ogfckWxKBB7OCH/cX0dZF02XU6 23pAiDQ6lpmfp943IJBo58x6BlOesuIUymXTFkIV91dPIlIBUURTDG8sQ5tIAu9GlVCxB +KwaijMKIH9Hq4lSdqe//vpx/Z/Wc98h5fPQVVVW7govh57qaWietRU+8r71Hl42nDrNX MGBr4inANMCMglGPr7H6BCaeKe7RzBH5yLJ4AGyzLDdXF3wd3A/3dz6DPRlAG0EZ/3ytj VcAMk9HqKLUs+4eP63O235fFU+h2lfNjyUfMucEedzehSZ7gvRfqrbvuyharEICVU+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796099819; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding: X-Spam-Status:X-Spam-Checker-Version; bh=A6FswsyOpx/UpGjiArnlBXGmgoI0qQkKKyFL7zU5SlU=; b=z+8M/9y2pA3e99gGJRKkSd4bQ39XTcwYseOty/jN1VhCjGOCkJSPf2T04lDXdH4A+dXJ KrIEr4DpA4wUwY5x3NAF0bZDLV8eb0mpeguGwC07oBfxnIYA3xWhIrkpghE6DrLsFWz/t y6aBD2uf8chHMHbZ1zxZN1cXCbzKYWFSef4XoZ5sn9R5LBQX31XQk5t783iJvbSJ21xrh uW4eJ42WSZ24FnIMSwSUfcdozj4tSE+GQhKkBo2235u+qo1N9MwO62Fyqno/pfBmL4Us1 Ss1Hkc5323p4DV8g0j51C6KuysYXiafurbDnjdiFCP3OSEOzzh4IwuQspHmjc62jf0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=XRlGoArd; arc=none smtp.remote-ip=13.77.154.182 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 50490606A31A; Tue, 1 Dec 2026 04:36:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 50490606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=XRlGoArd Received: from CPC-namja-026ON.localdomain (unknown [4.213.232.23]) by linux.microsoft.com (Postfix) with ESMTPSA id CDEDF20B7166; Mon, 30 Nov 2026 20:36:38 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CDEDF20B7166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1796099803; bh=A6FswsyOpx/UpGjiArnlBXGmgoI0qQkKKyFL7zU5SlU=; h=From:To:Cc:Subject:Date:From; b=XRlGoArdvIelO6l/1FiEj1lifjUE0VTvQqy+Ya2akJMU28LhdQg8wXBqDMOWvkrre M0ceTvjwEuCbUwzZ3sraXHPByW4e7AQ4q5j2WLDPtp2omzvnULoxSwALvFcu1mU4SC 3J/O1a4fyFgGK3YW1fV5RZV3zsUqEv3NyZTNXUYw= From: Naman Jain To: haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, luto@kernel.org, peterz@infradead.org Cc: dave.hansen@intel.com, hpa@zytor.com, riel@surriel.com, mhklinux@outlook.com, schandna@linux.microsoft.com, namjain@linux.microsoft.com, qq570070308@gmail.com, houwenlong.hwl@antgroup.com, zhouchuyi@bytedance.com, jgross@suse.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 0/5] x86/hyperv: Account for lazy mm_cpumask maintenance Date: Tue, 1 Dec 2026 04:36:37 +0000 Message-ID: <20261201043642.1054258-1-namjain@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-hyperv@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Lazy mm_cpumask maintenance leaves a CPU's bit set after it switches to another address space. Linux removes stale bits by running flush_tlb_func() on the target CPUs. A Hyper-V TLB flush hypercall invalidates translations but does not run this function. Stale bits can therefore remain and cause unnecessary remote invalidations. hyperv_flush_tlb_multi() can also select HV_FLUSH_ALL_PROCESSORS from a mask containing stale bits before reaching its per-CPU lazy-TLB checks. The regression was found in SuperBench's eight-GPU PyTorch LSTM training on Azure MI300X VMs when comparing Linux 6.8 and 7.0. Recreating DataLoader workers each epoch caused host-to-GPU copy stalls and timeouts. Bisection identified commit 209954cbc7d0 ("x86/mm/tlb: Update mm_cpumask lazily") as the cause of the regression. Patches 1-3 prepare for target filtering in patch 4 while patch 5 adds immediate cleanup. Patch 1 falls back to native flushing if VP-set conversion returns zero. This can happen when the maximum VP index is at least 4096. The check is defensive; the issue has not been seen in practice. Patch 2 lets the Hyper-V PV TLB flush functions call should_flush_tlb(). Its argument is const because the function only reads the request. A wrapper keeps the void * argument required by on_each_cpu_cond_mask(). Patch 3 uses native flushing when mask trimming is requested or a global ASID transition is in progress. This lets flush_tlb_func() run on the target CPUs to clear stale mask bits or switch to the global ASID. Patch 4 uses should_flush_tlb() to decide which CPUs to include in a Hyper-V flush before choosing the hypercall format or the all-processors flag. When freeing page tables, it keeps the full mask to include CPUs in lazy TLB mode. Stale bits can still cause all-processor flushes in that case. Patch 5 requests native cleanup if filtering leaves no remote CPU that needs a flush. Removing stale mm_cpumask() bits lets later flushes take the local-only path when possible. Lazy CPUs are still skipped, so some bits may remain. The earlier mask-weight > mm_users experiment on a 32-vCPU Hyper-V VM found that lazy bits could keep the comparison true across 10,000 flush requests. With three remote readers, mm_users was 4 and mask weights were 26-32. Each reader received 10,000 native callbacks; the corresponding run using cleanup only when no remote target remained used hypercalls. A doubled threshold and a rate-limited policy have not been tested. On a 32-vCPU Hyper-V VM, after a single-threaded process visited all CPUs and returned to one CPU, the reproducer's median time per iteration (two mprotect() calls and a write) dropped from 17.235 us to 1.622 us with the fix. On the reporter's 96-vCPU VM, the application hit the 600-second timeout without the fix and completed in 424 and 436 seconds with it. Changes since v2: https://lore.kernel.org/all/20261117091507.2088642-1-namjain@linux.microsoft.com/ * Replace vague descriptions with function names in commit messages and comments (Dave, Michael). * Describe the VP-set limit as theoretical and remove the confusing explanation about filtering an all-present mask (Michael). * Use the agreed wording about successfully taking the Hyper-V hypercall path, and the accepted patch 3 commit message (Michael). * Make the cleanup comment conditional and name mm_cpumask() explicitly in its commit message (Michael). * Clarify that page-table-freeing flushes can still target stale members (Sahil). Changes since v1: https://lore.kernel.org/all/20261029064234.362385-1-namjain@linux.microsoft.com/ * Split the change into five patches with separate explanations (Dave). * Add the workload and regression context (Michael). * Explain ASID handling and filtering exceptions separately (Dave). * Test the mm_users heuristic and keep immediate cleanup separate for policy review (Dave). Naman Jain (5): x86/hyperv: Reject unrepresentable TLB flush VP sets x86/tlb: Make should_flush_tlb() available to Hyper-V x86/hyperv: Use native flushes for mask trimming and ASID transitions x86/hyperv: Filter TLB targets before building hypercalls x86/hyperv: Request mask cleanup when no remote target remains arch/x86/hyperv/mmu.c | 71 +++++++++++++++++++++++---------- arch/x86/include/asm/tlbflush.h | 1 + arch/x86/mm/tlb.c | 17 ++++++-- 3 files changed, 64 insertions(+), 25 deletions(-) base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d -- 2.43.0