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

* [tip:x86/hyperv] x86/hyperv: Stop suppressing X86_FEATURE_PCID
  2018-01-24 10:36 [PATCH] x86/hyper-v: stop suppressing X86_FEATURE_PCID Vitaly Kuznetsov
@ 2018-01-24 12:48 ` tip-bot for Vitaly Kuznetsov
  2018-01-24 16:27   ` Andy Lutomirski
  2018-01-25  8:46 ` tip-bot for Vitaly Kuznetsov
  1 sibling, 1 reply; 5+ messages in thread
From: tip-bot for Vitaly Kuznetsov @ 2018-01-24 12:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: dazhan, haiyangz, kys, hpa, linux-kernel, luto, vkuznets, mingo,
	sthemmin, tglx, adityabh, Michael.H.Kelley

Commit-ID:  04651dd978a8749e59065df14b970a127f219ac2
Gitweb:     https://git.kernel.org/tip/04651dd978a8749e59065df14b970a127f219ac2
Author:     Vitaly Kuznetsov <vkuznets@redhat.com>
AuthorDate: Wed, 24 Jan 2018 11:36:29 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 24 Jan 2018 13:44:57 +0100

x86/hyperv: Stop suppressing X86_FEATURE_PCID

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.

>From TLFS (as of 5.0b) it is unclear how TLB flush hypercalls combine with
PCID. In particular the usage of PCID is per-cpu based: the same mm gets
different CR3 values on different CPUs. If the hypercall does exact
matching this will fail. However, this is not the case. David Zhang
explains:

 "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>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: David Zhang <dazhan@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: "Michael Kelley (EOSG)" <Michael.H.Kelley@microsoft.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: devel@linuxdriverproject.org
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Aditya Bhandari <adityabh@microsoft.com>
Link: https://lkml.kernel.org/r/20180124103629.29980-1-vkuznets@redhat.com
---
 arch/x86/hyperv/mmu.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
index 9cc9e1c..694abf1 100644
--- a/arch/x86/hyperv/mmu.c
+++ b/arch/x86/hyperv/mmu.c
@@ -111,7 +111,7 @@ static void hyperv_flush_tlb_others(const struct cpumask *cpus,
 	int cpu, vcpu, gva_n, max_gvas;
 	struct hv_flush_pcpu **flush_pcpu;
 	struct hv_flush_pcpu *flush;
-	u64 status = U64_MAX;
+	u64 base, status = U64_MAX;
 	unsigned long flags;
 
 	trace_hyperv_mmu_flush_tlb_others(cpus, info);
@@ -137,7 +137,12 @@ static void hyperv_flush_tlb_others(const struct cpumask *cpus,
 	}
 
 	if (info->mm) {
+		/*
+		 * AddressSpace argument must match the CR3 with PCID bits
+		 * stripped out.
+		 */
 		flush->address_space = virt_to_phys(info->mm->pgd);
+		flush->address_space &= 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) {
+		/*
+		 * AddressSpace argument must match the CR3 with PCID bits
+		 * stripped out.
+		 */
 		flush->address_space = virt_to_phys(info->mm->pgd);
+		flush->address_space &= 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;

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

* Re: [tip:x86/hyperv] x86/hyperv: Stop suppressing X86_FEATURE_PCID
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Lutomirski @ 2018-01-24 16:27 UTC (permalink / raw)
  To: dazhan, Haiyang Zhang, KY Srinivasan, LKML, H. Peter Anvin,
	Andrew Lutomirski, Vitaly Kuznetsov, Thomas Gleixner,
	Michael.H.Kelley, adityabh, Ingo Molnar, Stephen Hemminger
  Cc: linux-tip-commits

On Wed, Jan 24, 2018 at 4:48 AM, tip-bot for Vitaly Kuznetsov
<tipbot@zytor.com> wrote:
> Commit-ID:  04651dd978a8749e59065df14b970a127f219ac2
> Gitweb:     https://git.kernel.org/tip/04651dd978a8749e59065df14b970a127f219ac2
> Author:     Vitaly Kuznetsov <vkuznets@redhat.com>
> AuthorDate: Wed, 24 Jan 2018 11:36:29 +0100
> Committer:  Thomas Gleixner <tglx@linutronix.de>
> CommitDate: Wed, 24 Jan 2018 13:44:57 +0100
>
> x86/hyperv: Stop suppressing X86_FEATURE_PCID
>
> 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.
>
> From TLFS (as of 5.0b) it is unclear how TLB flush hypercalls combine with
> PCID. In particular the usage of PCID is per-cpu based: the same mm gets
> different CR3 values on different CPUs. If the hypercall does exact
> matching this will fail. However, this is not the case. David Zhang
> explains:
>
>  "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.

So what, exactly, does the flush hypercall do?

--Andy

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

* [tip:x86/hyperv] x86/hyperv: Stop suppressing X86_FEATURE_PCID
  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-25  8:46 ` tip-bot for Vitaly Kuznetsov
  1 sibling, 0 replies; 5+ messages in thread
From: tip-bot for Vitaly Kuznetsov @ 2018-01-25  8:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: adityabh, dazhan, kys, hpa, mingo, haiyangz, tglx, linux-kernel,
	luto, Michael.H.Kelley, vkuznets, sthemmin

Commit-ID:  617ab45c9a8900e64a78b43696c02598b8cad68b
Gitweb:     https://git.kernel.org/tip/617ab45c9a8900e64a78b43696c02598b8cad68b
Author:     Vitaly Kuznetsov <vkuznets@redhat.com>
AuthorDate: Wed, 24 Jan 2018 11:36:29 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 25 Jan 2018 09:40:59 +0100

x86/hyperv: Stop suppressing X86_FEATURE_PCID

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.

>From TLFS (as of 5.0b) it is unclear how TLB flush hypercalls combine with
PCID. In particular the usage of PCID is per-cpu based: the same mm gets
different CR3 values on different CPUs. If the hypercall does exact
matching this will fail. However, this is not the case. David Zhang
explains:

 "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>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: David Zhang <dazhan@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: "Michael Kelley (EOSG)" <Michael.H.Kelley@microsoft.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: devel@linuxdriverproject.org
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Aditya Bhandari <adityabh@microsoft.com>
Link: https://lkml.kernel.org/r/20180124103629.29980-1-vkuznets@redhat.com

---
 arch/x86/hyperv/mmu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
index 9cc9e1c..56c9eba 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) {
+		/*
+		 * AddressSpace argument must match the CR3 with PCID bits
+		 * stripped out.
+		 */
 		flush->address_space = virt_to_phys(info->mm->pgd);
+		flush->address_space &= 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) {
+		/*
+		 * AddressSpace argument must match the CR3 with PCID bits
+		 * stripped out.
+		 */
 		flush->address_space = virt_to_phys(info->mm->pgd);
+		flush->address_space &= 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;

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

* RE: [tip:x86/hyperv] x86/hyperv: Stop suppressing X86_FEATURE_PCID
  2018-01-24 16:27   ` Andy Lutomirski
@ 2018-01-25 16:32     ` David Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: David Zhang @ 2018-01-25 16:32 UTC (permalink / raw)
  To: Andy Lutomirski, Haiyang Zhang, KY Srinivasan, LKML,
	H. Peter Anvin, Vitaly Kuznetsov, Thomas Gleixner,
	Michael Kelley (EOSG),
	Aditya Bhandari, Ingo Molnar, Stephen Hemminger
  Cc: linux-tip-commits

When the FLUSH_ALL_VIRTUAL_ADDRESS_SPACES flag (0x2) is not specified, the flush hypercall matches the AddressSpace parameter with the base address of the page table root on each processor (the base address is page-aligned in long/32-bit mode, 32-byte aligned in PAE mode). If there is a match, it flushes the specified VAs, for all PCIDs.

The flush hypercall is allowed to flush more than the above, however.

We will update the TLFS with this behavior. 

-----Original Message-----
From: Andy Lutomirski [mailto:luto@kernel.org] 
Sent: Wednesday, January 24, 2018 8:28 AM
To: David Zhang <dazhan@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>; KY Srinivasan <kys@microsoft.com>; LKML <linux-kernel@vger.kernel.org>; H. Peter Anvin <hpa@zytor.com>; Andrew Lutomirski <luto@kernel.org>; Vitaly Kuznetsov <vkuznets@redhat.com>; Thomas Gleixner <tglx@linutronix.de>; Michael Kelley (EOSG) <Michael.H.Kelley@microsoft.com>; Aditya Bhandari <adityabh@microsoft.com>; Ingo Molnar <mingo@kernel.org>; Stephen Hemminger <sthemmin@microsoft.com>
Cc: linux-tip-commits@vger.kernel.org
Subject: Re: [tip:x86/hyperv] x86/hyperv: Stop suppressing X86_FEATURE_PCID

On Wed, Jan 24, 2018 at 4:48 AM, tip-bot for Vitaly Kuznetsov <tipbot@zytor.com> wrote:
> Commit-ID:  04651dd978a8749e59065df14b970a127f219ac2
> Gitweb:     https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Ftip%2F04651dd978a8749e59065df14b970a127f219ac2&data=02%7C01%7Cdazhan%40microsoft.com%7C59a83800e5b84e1bb97008d56347705b%7Cee3303d7fb734b0c8589bcd847f1c277%7C1%7C0%7C636524080843155861&sdata=qA5eG6L9MieOSWL8SCBQaWcYJtN7IT75rO0I1PdoZ%2FE%3D&reserved=0
> Author:     Vitaly Kuznetsov <vkuznets@redhat.com>
> AuthorDate: Wed, 24 Jan 2018 11:36:29 +0100
> Committer:  Thomas Gleixner <tglx@linutronix.de>
> CommitDate: Wed, 24 Jan 2018 13:44:57 +0100
>
> x86/hyperv: Stop suppressing X86_FEATURE_PCID
>
> 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.
>
> From TLFS (as of 5.0b) it is unclear how TLB flush hypercalls combine 
> with PCID. In particular the usage of PCID is per-cpu based: the same 
> mm gets different CR3 values on different CPUs. If the hypercall does 
> exact matching this will fail. However, this is not the case. David 
> Zhang
> explains:
>
>  "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.

So what, exactly, does the flush hypercall do?

--Andy

^ permalink raw reply	[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.