target-i386: add pcid to both Sandy Bridge and Ivy Bridge
PATCH 1/1 target-i386: add pcid to both Sandy Bridge and Ivy Bridge
PCID has been introduced in Sandy Bridge and, currently, KVM doesn't object exposing it to VM as long as it is present on the host. Update CPU model for both Sandy Bridge and Ivy Bridge accordingly.
--- target/i386/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/i386/cpu.c +3 -2
@@ -1109,7 +1109,7 @@ static X86CPUDefinition builtin_x86_defs[] = {CPUID_EXT_TSC_DEADLINE_TIMER |CPUID_EXT_POPCNT |CPUID_EXT_X2APIC |CPUID_EXT_SSE42 |CPUID_EXT_SSE41 |CPUID_EXT_CX16 |CPUID_EXT_SSSE3 |CPUID_EXT_PCLMULQDQ | - CPUID_EXT_SSE3, + CPUID_EXT_SSE3 | CPUID_EXT_PCID, .features[FEAT_8000_0001_EDX ] =CPUID_EXT2_LM |CPUID_EXT2_RDTSCP |CPUID_EXT2_NX | CPUID_EXT2_SYSCALL,
@@ -1140,7 +1140,8 @@ static X86CPUDefinition builtin_x86_defs[] = {CPUID_EXT_TSC_DEADLINE_TIMER |CPUID_EXT_POPCNT |CPUID_EXT_X2APIC |CPUID_EXT_SSE42 |CPUID_EXT_SSE41 |CPUID_EXT_CX16 |CPUID_EXT_SSSE3 |CPUID_EXT_PCLMULQDQ | - CPUID_EXT_SSE3 | CPUID_EXT_F16C | CPUID_EXT_RDRAND, +CPUID_EXT_SSE3 |CPUID_EXT_F16C |CPUID_EXT_RDRAND | + CPUID_EXT_PCID, .features[FEAT_7_0_EBX ] =CPUID_7_0_EBX_FSGSBASE |CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_ERMS,
Signature · 1 line
2.15.1
Quoted 5 lines · Vincent Bernat
PCID has been introduced in Sandy Bridge and, currently, KVM doesn't object exposing it to VM as long as it is present on the host. Update CPU model for both Sandy Bridge and Ivy Bridge accordingly.
Signed-off-by Vincent Bernat <[email protected]>
Thanks for your patch.
We need two things, though:
First, confirming that all hosts where the SandyBridge and IvyBridge CPU models are runnable will support exposing PCID to guests (otherwise updating QEMU can make a runnable VM configuration suddenly stop being runnable). This can happen if the host kernel is too old.
One possible way to work around this problem is to declare that QEMU 2.12 with KVM will require Linux v3.6 and newer (because we need Linux kernel commit ad756a1603c5 "KVM: VMX: Implement PCID/INVPCID for guests with EPT"). I have proposed something similar to allow us to enable kvm_pv_eoi by default, some time ago:
https://www.mail-archive.com/[email protected]/msg486559.html
("qemu-doc: Document minimum kernel version for KVM in x86_64").
Second, we need compatibility entries setting pcid=off on PC_COMPAT_2_10 so we don't break compatibility on older machine-types.
Quoted 30 lines
--- target/i386/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)target/i386/cpu.c +3
-2@@ -1109,7 +1109,7 @@ static X86CPUDefinition builtin_x86_defs[] = {CPUID_EXT_TSC_DEADLINE_TIMER |CPUID_EXT_POPCNT |CPUID_EXT_X2APIC |CPUID_EXT_SSE42 |CPUID_EXT_SSE41 |CPUID_EXT_CX16 |CPUID_EXT_SSSE3 |CPUID_EXT_PCLMULQDQ | - CPUID_EXT_SSE3, + CPUID_EXT_SSE3 | CPUID_EXT_PCID, .features[FEAT_8000_0001_EDX ] =CPUID_EXT2_LM |CPUID_EXT2_RDTSCP |CPUID_EXT2_NX | CPUID_EXT2_SYSCALL,@@ -1140,7 +1140,8 @@ static X86CPUDefinition builtin_x86_defs[] = {CPUID_EXT_TSC_DEADLINE_TIMER |CPUID_EXT_POPCNT |CPUID_EXT_X2APIC |CPUID_EXT_SSE42 |CPUID_EXT_SSE41 |CPUID_EXT_CX16 |CPUID_EXT_SSSE3 |CPUID_EXT_PCLMULQDQ | - CPUID_EXT_SSE3 | CPUID_EXT_F16C | CPUID_EXT_RDRAND, +CPUID_EXT_SSE3 |CPUID_EXT_F16C |CPUID_EXT_RDRAND | + CPUID_EXT_PCID, .features[FEAT_7_0_EBX ] =CPUID_7_0_EBX_FSGSBASE |CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_ERMS,Signature · 1 line
2.15.1
Signature · 1 line
Eduardo
❦ 8 janvier 2018 19:16 -0200, Eduardo Habkost <[email protected]> :
Quoted 8 lines
One possible way to work around this problem is to declare that QEMU 2.12 with KVM will require Linux v3.6 and newer (because we need Linux kernel commit
ad756a1603c5"KVM: VMX: Implement PCID/INVPCID for guests with EPT"). I have proposed something similar to allow us to enablekvm_pv_eoiby default, some time ago:
https://www.mail-archive.com/[email protected]/msg486559.html
("qemu-doc: Document minimum kernel version for KVM inx86_64").
I don't see a way to probe KVM to know what's supported, so yes. Should I add a paragraph similar to yours or would your patch be merged soon? What are the consequences of running a too old kernel? Would KVM just hide PCID flag?
Quoted 3 lines
Second, we need compatibility entries setting pcid=off on
PC_COMPAT_2_10so we don't break compatibility on older machine-types.
include/hw/i386/pc.h +8 -0
@@ -327,6 +327,14 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); .driver = TYPE_X86_CPU,\ .property = "x-hv-max-vps",\ .value = "0x40",\ + },{\ + .driver = "SandyBridge-" TYPE_X86_CPU,\ + .property = "pcid",\ + .value = "off",\ + },{\ + .driver = "IvyBridge-" TYPE_X86_CPU,\ + .property = "pcid",\ + .value = "off",\ },{\ .driver = "i440FX-pcihost",\ .property = "x-pci-hole64-fix",\
I'll resend a proper patch once the first point is cleared.
Signature · 2 lines
Make sure input cannot violate the limits of the program.
- The Elements of Programming Style (Kernighan & Plauger)Quoted 11 lines · Vincent Bernat
❦ 8 janvier 2018 19:16 -0200, Eduardo Habkost <[email protected]> :
Quoted 8 lines
One possible way to work around this problem is to declare that QEMU 2.12 with KVM will require Linux v3.6 and newer (because we need Linux kernel commit
ad756a1603c5"KVM: VMX: Implement PCID/INVPCID for guests with EPT"). I have proposed something similar to allow us to enablekvm_pv_eoiby default, some time ago:
https://www.mail-archive.com/[email protected]/msg486559.html
("qemu-doc: Document minimum kernel version for KVM inx86_64").
Quoted 1 line
I don't see a way to probe KVM to know what's supported, so yes.
We do have a way to probe KVM: GET_SUPPORTED_CPUID. The problem here is breaking libvirt and management software expectations.
libvirt assumes "stable runnability": a CPU model that is runnable on a host using QEMU/machine-type version will stay runnable on the same host after a QEMU or machine-type upgrade.
Quoted 2 lines
Should
I add a paragraph similar to yours or would your patch be merged soon?
My patch was dropped because we decided to wait a bit before enabling kvm_pv_eoi by default. My paragraph could be improved by a description of what could happen if an older kernel version is used (see below).
Quoted 2 lines
What are the consequences of running a too old kernel? Would KVM just hide PCID flag?
On an old kernel, the SandyBridge and IvyBridge CPU models will be unexpectedly become not runnable.
Quoted 4 lines
Quoted 4 lines
Second, we need compatibility entries setting pcid=off on
PC_COMPAT_2_10so we don't break compatibility on older machine-types.
(Oops, I should have said PC_COMPAT_2_11 here)
Quoted 10 lines
include/hw/i386/pc.h +1
-0@@ -327,6 +327,14 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); .driver = TYPE_X86_CPU,\ .property = "x-hv-max-vps",\ .value = "0x40",\ + },{\
include/hw/i386/pc.h bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); · line 340
Quoted 10 lines
include/hw/i386/pc.h +7
-0+ .driver = "SandyBridge-" TYPE_X86_CPU,\ + .property = "pcid",\ + .value = "off",\ + },{\ + .driver = "IvyBridge-" TYPE_X86_CPU,\ + .property = "pcid",\ + .value = "off",\ },{\ .driver = "i440FX-pcihost",\ .property = "x-pci-hole64-fix",\
This is correct, but it should be done on PC_COMPAT_2_11 instead (sorry for my confusion above).
If you don't find PC_COMPAT_2_11 on master, please look for the "pc: add 2.12 machine types" patch. I thought it was already merged on master. I just queued it on my x86-next tree[1].
[1] https://github.com/ehabkost/qemu x86-next
Quoted 2 lines
I'll resend a proper patch once the first point is cleared.
Thanks!
Signature · 1 line
Eduardo
❦ 8 janvier 2018 20:14 -0200, Eduardo Habkost <[email protected]> :
Quoted 5 lines
Quoted 2 lines
What are the consequences of running a too old kernel? Would KVM just hide PCID flag?
On an old kernel, the SandyBridge and IvyBridge CPU models will be unexpectedly become not runnable.
But, isn't it the same for more recent models that already have PCID enabled?
Signature · 2 lines
Extreme fear can neither fight nor fly. -- William Shakespeare, "The Rape of Lucrece"
Quoted 10 lines · Vincent Bernat
❦ 8 janvier 2018 20:14 -0200, Eduardo Habkost <[email protected]> :
Quoted 5 lines
Quoted 2 lines
What are the consequences of running a too old kernel? Would KVM just hide PCID flag?
On an old kernel, the SandyBridge and IvyBridge CPU models will be unexpectedly become not runnable.
But, isn't it the same for more recent models that already have PCID enabled?
Yes, the more recent models are already not runnable on those hosts. The key here is "unexpectedly": management software can assume that the CPU model won't become unrunnable when it was runnable in the past, and logic that decides if/where a VM can be started (or migrated to) might break.
Signature · 1 line
Eduardo
----- Original Message -----
Quoted 15 lines
From: "Eduardo Habkost" <[email protected]>
To: "Vincent Bernat" <[email protected]>
Cc: "Paolo Bonzini" <[email protected]>, "Richard Henderson" <[email protected]>, [email protected]
Sent: Monday, January 8, 2018 10:16:23 PM
Subject: Re: [PATCH] target-i386: add pcid to both Sandy Bridge and Ivy BridgeQuoted 5 lines · Vincent Bernat
PCID has been introduced in Sandy Bridge and, currently, KVM doesn't object exposing it to VM as long as it is present on the host. Update CPU model for both Sandy Bridge and Ivy Bridge accordingly.
Signed-off-by Vincent Bernat <[email protected]>Thanks for your patch.
Quoted 7 lines
We need two things, though:
First, confirming that all hosts where the SandyBridge and IvyBridge CPU models are runnable will support exposing PCID to guests (otherwise updating QEMU can make a runnable VM configuration suddenly stop being runnable). This can happen if the host kernel is too old.
I've been reading it's also Westmere. I'll check more carefully tomorrow. The difference between consumer and server SKUs is important too.
Quoted 4 lines
One possible way to work around this problem is to declare that QEMU 2.12 with KVM will require Linux v3.6 and newer (because we need Linux kernel commit
ad756a1603c5"KVM: VMX: Implement PCID/INVPCID for guests with EPT").
Note that PCID is still not supported for guests without EPT, so this would break ept=0 with recent "-cpu" models. I'm not sure of a way to fix it; probably it just has to be documented.
Paolo
Quoted 29 lines · Paolo Bonzini
----- Original Message -----
Quoted 15 lines
From: "Eduardo Habkost" <[email protected]>
To: "Vincent Bernat" <[email protected]>
Cc: "Paolo Bonzini" <[email protected]>, "Richard Henderson" <[email protected]>, [email protected]
Sent: Monday, January 8, 2018 10:16:23 PM
Subject: Re: [PATCH] target-i386: add pcid to both Sandy Bridge and Ivy BridgeQuoted 5 lines · Vincent Bernat
PCID has been introduced in Sandy Bridge and, currently, KVM doesn't object exposing it to VM as long as it is present on the host. Update CPU model for both Sandy Bridge and Ivy Bridge accordingly.
Signed-off-by Vincent Bernat <[email protected]>Thanks for your patch.
Quoted 7 lines
We need two things, though:
First, confirming that all hosts where the SandyBridge and IvyBridge CPU models are runnable will support exposing PCID to guests (otherwise updating QEMU can make a runnable VM configuration suddenly stop being runnable). This can happen if the host kernel is too old.
I've been reading it's also Westmere. I'll check more carefully tomorrow. The difference between consumer and server SKUs is important too.
Quoted 8 lines
Quoted 4 lines
One possible way to work around this problem is to declare that QEMU 2.12 with KVM will require Linux v3.6 and newer (because we need Linux kernel commit
ad756a1603c5"KVM: VMX: Implement PCID/INVPCID for guests with EPT").Note that PCID is still not supported for guests without EPT, so this would break ept=0 with recent "-cpu" models. I'm not sure of a way to fix it; probably it just has to be documented.
GET_SUPPORTED_CPUID seems to still return PCID as supported without EPT, doesn't it?
(BTW, is PCID useful for KPTI performance without INVPCID?)
Signature · 1 line
Eduardo
----- Original Message -----
Quoted 43 lines
From: "Eduardo Habkost" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Vincent Bernat" <[email protected]>, "Richard Henderson" <[email protected]>, [email protected]
Sent: Monday, January 8, 2018 11:56:25 PM
Subject: Re: [PATCH] target-i386: add pcid to both Sandy Bridge and Ivy BridgeQuoted 36 lines · Paolo Bonzini
----- Original Message -----
Quoted 17 lines
From: "Eduardo Habkost" <[email protected]>
To: "Vincent Bernat" <[email protected]>
Cc: "Paolo Bonzini" <[email protected]>, "Richard Henderson" <[email protected]>, [email protected]
Sent: Monday, January 8, 2018 10:16:23 PM
Subject: Re: [PATCH] target-i386: add pcid to both Sandy Bridge and Ivy BridgeQuoted 5 lines · Vincent Bernat
PCID has been introduced in Sandy Bridge and, currently, KVM doesn't object exposing it to VM as long as it is present on the host. Update CPU model for both Sandy Bridge and Ivy Bridge accordingly.
Signed-off-by Vincent Bernat <[email protected]>Thanks for your patch.
Quoted 7 lines
We need two things, though:
First, confirming that all hosts where the SandyBridge and IvyBridge CPU models are runnable will support exposing PCID to guests (otherwise updating QEMU can make a runnable VM configuration suddenly stop being runnable). This can happen if the host kernel is too old.
I've been reading it's also Westmere. I'll check more carefully tomorrow. The difference between consumer and server SKUs is important too.
Quoted 4 lines
One possible way to work around this problem is to declare that QEMU 2.12 with KVM will require Linux v3.6 and newer (because we need Linux kernel commit
ad756a1603c5"KVM: VMX: Implement PCID/INVPCID for guests with EPT").
Quoted 6 lines
Quoted 3 lines
Note that PCID is still not supported for guests without EPT, so this would break ept=0 with recent "-cpu" models. I'm not sure of a way to fix it; probably it just has to be documented.
GET_SUPPORTED_CPUIDseems to still return PCID as supported without EPT, doesn't it?
Indeed it is! It will also be useful for KPTI performance without INVPCID, but it won't be useful without EPT.
Paolo
Quoted 1 line
(BTW, is PCID useful for KPTI performance without INVPCID?)
Quoted 50 lines · Paolo Bonzini
----- Original Message -----
Quoted 47 lines
From: "Eduardo Habkost" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Vincent Bernat" <[email protected]>, "Richard Henderson" <[email protected]>, [email protected]
Sent: Monday, January 8, 2018 11:56:25 PM
Subject: Re: [PATCH] target-i386: add pcid to both Sandy Bridge and Ivy BridgeQuoted 39 lines · Paolo Bonzini
----- Original Message -----
Quoted 17 lines
From: "Eduardo Habkost" <[email protected]>
To: "Vincent Bernat" <[email protected]>
Cc: "Paolo Bonzini" <[email protected]>, "Richard Henderson" <[email protected]>, [email protected]
Sent: Monday, January 8, 2018 10:16:23 PM
Subject: Re: [PATCH] target-i386: add pcid to both Sandy Bridge and Ivy BridgeQuoted 5 lines · Vincent Bernat
PCID has been introduced in Sandy Bridge and, currently, KVM doesn't object exposing it to VM as long as it is present on the host. Update CPU model for both Sandy Bridge and Ivy Bridge accordingly.
Signed-off-by Vincent Bernat <[email protected]>Thanks for your patch.
Quoted 7 lines
We need two things, though:
First, confirming that all hosts where the SandyBridge and IvyBridge CPU models are runnable will support exposing PCID to guests (otherwise updating QEMU can make a runnable VM configuration suddenly stop being runnable). This can happen if the host kernel is too old.
I've been reading it's also Westmere. I'll check more carefully tomorrow. The difference between consumer and server SKUs is important too.
Quoted 4 lines
One possible way to work around this problem is to declare that QEMU 2.12 with KVM will require Linux v3.6 and newer (because we need Linux kernel commit
ad756a1603c5"KVM: VMX: Implement PCID/INVPCID for guests with EPT").Note that PCID is still not supported for guests without EPT, so this would break ept=0 with recent "-cpu" models. I'm not sure of a way to fix it; probably it just has to be documented.
Quoted 5 lines
Quoted 2 lines
GET_SUPPORTED_CPUIDseems to still return PCID as supported without EPT, doesn't it?Indeed it is! It will also be useful for KPTI performance without INVPCID, but it won't be useful without EPT.
Well, I can live with "not useful without EPT", as long as it doesn't mean "broken without EPT". It looks like we can safely enable it, as long as:
2) we confirm if all Intel Westmere/SandyBridge/IvyBridge CPUs have PCID;
1) QEMU documentation states that it requires Linux v3.6 or newer for KVM.
Signature · 1 line
Eduardo
❦ 8 janvier 2018 21:19 -0200, Eduardo Habkost <[email protected]> :
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
GET_SUPPORTED_CPUIDseems to still return PCID as supported without EPT, doesn't it?Indeed it is! It will also be useful for KPTI performance without INVPCID, but it won't be useful without EPT.
Quoted 6 lines
Well, I can live with "not useful without EPT", as long as it doesn't mean "broken without EPT". It looks like we can safely enable it, as long as:
2) we confirm if all Intel Westmere/SandyBridge/IvyBridge CPUs have PCID;
I didn't find an authoritative information about that on Intel website. Various sites indeed says the feature was introduced in Westmere. And Greg KH mentions Westmere here too:
https://mail-archive.com/[email protected]/msg1576774.html
Quoted 2 lines
1) QEMU documentation states that it requires Linux v3.6 or newer for KVM.
I have updated the patch and sent it in a new thread. It's now based on x86-next.
Signature · 2 lines
Clothes make the man. Naked people have little or no influence on society. -- Mark Twain
❦ 8 janvier 2018 20:56 -0200, Eduardo Habkost <[email protected]> :
Quoted 1 line
(BTW, is PCID useful for KPTI performance without INVPCID?)
It seems it is:
https://mail-archive.com/[email protected]/msg1576774.html
Signature · 2 lines
Don't use conditional branches as a substitute for a logical expression.
- The Elements of Programming Style (Kernighan & Plauger)❦ 8 janvier 2018 17:37 -0500, Paolo Bonzini <[email protected]> :
Quoted 10 lines
Quoted 4 lines
One possible way to work around this problem is to declare that QEMU 2.12 with KVM will require Linux v3.6 and newer (because we need Linux kernel commit
ad756a1603c5"KVM: VMX: Implement PCID/INVPCID for guests with EPT").Note that PCID is still not supported for guests without EPT, so this would break ept=0 with recent "-cpu" models. I'm not sure of a way to fix it; probably it just has to be documented.
From the above patch, it seems only INVPCID needs EPT. KVM exposes PCID
whenever it is present on the host.
Signature · 2 lines
When you are about to die, a wombat is better than no company at all. -- Roger Zelazny, "Doorways in the Sand"