All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/hyper-v: stop suppressing X86_FEATURE_PCID
@ 2018-01-24 10:36 Vitaly Kuznetsov
  2018-01-24 12:48 ` [tip:x86/hyperv] x86/hyperv: Stop " tip-bot for Vitaly Kuznetsov
  2018-01-25  8:46 ` tip-bot for Vitaly Kuznetsov
  0 siblings, 2 replies; 5+ messages in thread
From: Vitaly Kuznetsov @ 2018-01-24 10:36 UTC (permalink / raw)
  To: x86
  Cc: David Zhang, Stephen Hemminger, Haiyang Zhang, linux-kernel,
	Michael Kelley (EOSG),
	Ingo Molnar, Andy Lutomirski, H. Peter Anvin, devel,
	Thomas Gleixner, Aditya Bhandari

When hypercall-based TLB flush was enabled for Hyper-V guests PCID feature
was deliberately suppressed as a precaution: back then PCID was never
exposed to Hyper-V guests and it wasn't clear what will happen if some day
it becomes available. The day came and PCID/INVPCID features are already
exposed on certain Hyper-V hosts.

I was asked if we can stop suppressing PCID. From TLFS (as of 5.0b) is is
unclear how TLB flush hypercalls combine with PCID. In particular, I was
worried about our usage of PCID where it is per-cpu based: the same mm gets
different CR3 values on different CPUs and if hypercall does exact matching
we're screwed. However, this is not the case. David Zhang writes:

"In practice, the AddressSpace argument is ignored on any VM that supports
 PCIDs.

Architecturally, the AddressSpace argument must match the CR3 with PCID
bits stripped out (i.e., the low 12 bits of AddressSpace should be 0 in
long mode). The flush hypercalls flush all PCIDs for the specified
AddressSpace."

With this, PCID can be enabled.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/hyperv/mmu.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
index 9cc9e1c1e2db..993a5dff1e40 100644
--- a/arch/x86/hyperv/mmu.c
+++ b/arch/x86/hyperv/mmu.c
@@ -137,7 +137,12 @@ static void hyperv_flush_tlb_others(const struct cpumask *cpus,
 	}
 
 	if (info->mm) {
-		flush->address_space = virt_to_phys(info->mm->pgd);
+		/*
+		 * AddressSpace argument must match the CR3 with PCID bits
+		 * stripped out.
+		 */
+		flush->address_space =
+			virt_to_phys(info->mm->pgd) & CR3_ADDR_MASK;
 		flush->flags = 0;
 	} else {
 		flush->address_space = 0;
@@ -219,7 +224,12 @@ static void hyperv_flush_tlb_others_ex(const struct cpumask *cpus,
 	}
 
 	if (info->mm) {
-		flush->address_space = virt_to_phys(info->mm->pgd);
+		/*
+		 * AddressSpace argument must match the CR3 with PCID bits
+		 * stripped out.
+		 */
+		flush->address_space =
+			virt_to_phys(info->mm->pgd) & CR3_ADDR_MASK;
 		flush->flags = 0;
 	} else {
 		flush->address_space = 0;
@@ -278,8 +288,6 @@ void hyperv_setup_mmu_ops(void)
 	if (!(ms_hyperv.hints & HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED))
 		return;
 
-	setup_clear_cpu_cap(X86_FEATURE_PCID);
-
 	if (!(ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) {
 		pr_info("Using hypercall for remote TLB flush\n");
 		pv_mmu_ops.flush_tlb_others = hyperv_flush_tlb_others;
-- 
2.14.3

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-25 16:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-24 10:36 [PATCH] x86/hyper-v: stop suppressing X86_FEATURE_PCID Vitaly Kuznetsov
2018-01-24 12:48 ` [tip:x86/hyperv] x86/hyperv: Stop " tip-bot for Vitaly Kuznetsov
2018-01-24 16:27   ` Andy Lutomirski
2018-01-25 16:32     ` David Zhang
2018-01-25  8:46 ` tip-bot for Vitaly Kuznetsov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.