Linux-HyperV List
 help / color / mirror / Atom feed
From: Naman Jain <namjain@linux.microsoft.com>
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: hpa@zytor.com, riel@surriel.com, mhklinux@outlook.com,
	bigeasy@linutronix.de, zhouchuyi@bytedance.com,
	houwenlong.hwl@antgroup.com, qq570070308@gmail.com,
	bastien.curutchet@bootlin.com, namjain@linux.microsoft.com,
	dianders@chromium.org, jgross@suse.com, hawk@kernel.org,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 5/5] x86/hyperv: Request mask cleanup when no remote target remains
Date: Tue, 17 Nov 2026 09:15:07 +0000	[thread overview]
Message-ID: <20261117091507.2088642-6-namjain@linux.microsoft.com> (raw)
In-Reply-To: <20261117091507.2088642-1-namjain@linux.microsoft.com>

Filtering avoids unnecessary hypercalls but leaves historical CPU-mask
entries in place. These entries can keep later flushes on the multi-CPU
path even when only local work is needed.

When no remote target remains after filtering, request native trimming
of the original candidate mask instead of waiting for the periodic trim.
Copy the const request so only this call requests cleanup.

The native predicate still skips lazy CPUs, so cleanup may not leave a
local-only mask. The new early return also makes the empty basic
processor-mask check unnecessary.

Signed-off-by: Naman Jain <namjain@linux.microsoft.com>
---
 arch/x86/hyperv/mmu.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
index 833eaea1d3fa8..545a25fcf6c34 100644
--- a/arch/x86/hyperv/mmu.c
+++ b/arch/x86/hyperv/mmu.c
@@ -102,6 +102,21 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
 		}
 	}
 
+	/*
+	 * No remote target remains after filtering. Request native cleanup
+	 * of stale, non-lazy memberships so later flushes can take the local
+	 * fast path when possible. Lazy memberships may remain.
+	 */
+	if (cpumask_any_but(flush_cpus, smp_processor_id()) >= nr_cpu_ids) {
+		/* Keep the caller's const request unchanged. */
+		struct flush_tlb_info trim_info = *info;
+
+		trim_info.trim_cpumask = 1;
+		local_irq_restore(flags);
+		native_flush_tlb_multi(cpus, &trim_info);
+		return;
+	}
+
 	if (info->mm) {
 		/*
 		 * AddressSpace argument must match the CR3 with PCID bits
@@ -148,12 +163,6 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus,
 			__set_bit(vcpu, (unsigned long *)
 				  &flush->processor_mask);
 		}
-
-		/* nothing to flush if 'processor_mask' ends up being empty */
-		if (!flush->processor_mask) {
-			local_irq_restore(flags);
-			return;
-		}
 	}
 
 	/*
-- 
2.43.0


      parent reply	other threads:[~2026-11-17  9:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  9:15 [PATCH v2 0/5] x86/hyperv: Account for lazy mm_cpumask maintenance Naman Jain
2026-11-17  9:15 ` [PATCH v2 1/5] x86/hyperv: Reject unrepresentable TLB flush VP sets Naman Jain
2026-11-17  9:15 ` [PATCH v2 2/5] x86/tlb: Make the conditional flush predicate reusable Naman Jain
2026-11-17  9:15 ` [PATCH v2 3/5] x86/hyperv: Use native callbacks for trimming and ASID transitions Naman Jain
2026-11-17  9:15 ` [PATCH v2 4/5] x86/hyperv: Filter TLB targets before building hypercalls Naman Jain
2026-11-17  9:24   ` sashiko-bot
2026-11-17  9:15 ` Naman Jain [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117091507.2088642-6-namjain@linux.microsoft.com \
    --to=namjain@linux.microsoft.com \
    --cc=bastien.curutchet@bootlin.com \
    --cc=bigeasy@linutronix.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=dianders@chromium.org \
    --cc=haiyangz@microsoft.com \
    --cc=hawk@kernel.org \
    --cc=houwenlong.hwl@antgroup.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=qq570070308@gmail.com \
    --cc=riel@surriel.com \
    --cc=tglx@kernel.org \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    --cc=zhouchuyi@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox