Skip to contentSkip to conversation

add support for vNVDIMM - Part 1: enable instructions

PATCH Superseded Haozhong Zhang 5 participants 21 messages Dec 30, 2015 – Jan 8, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover add support for vNVDIMM - Part 1: enable instructions

I split the previous patch series "[PATCH 0/4] add support for vNVDIMM" into two parts. This is the first part that enables clflushopt/clwb/pcommit instructions for HVM guests.

[The second part will be sent separately after v1 patches get reviewed.]

Changes in v2:
* Refactor modifications in hvm_cpuid() per Andrew Cooper's comments.

Haozhong Zhang (2):
x86/hvm: allow guest to use clflushopt and clwb
x86/hvm: add support for pcommit instruction

 tools/libxc/xc_cpufeature.h        |  4 +++-
 tools/libxc/xc_cpuid_x86.c         |  5 ++++-
 xen/arch/x86/hvm/hvm.c             | 36 ++++++++++++++++++++++++------------
 xen/arch/x86/hvm/vmx/vmcs.c        |  6 +++++-
 xen/arch/x86/hvm/vmx/vmx.c         |  1 +
 xen/arch/x86/hvm/vmx/vvmx.c        |  3 +++
 xen/include/asm-x86/cpufeature.h   |  7 +++++++
 xen/include/asm-x86/hvm/vmx/vmcs.h |  3 +++
 xen/include/asm-x86/hvm/vmx/vmx.h  |  1 +
 9 files changed, 51 insertions(+), 15 deletions(-)
Signature · 1 line
2.4.8
#1 lore raw

PATCH v2 1/2 x86/hvm: allow guest to use clflushopt and clwb

Pass CPU features CLFLUSHOPT and CLWB into HVM domain so that those two instructions can be used by guest.

The specification of above two instructions can be found in
https://software.intel.com/sites/default/files/managed/0d/53/319433-022.pdf

---
 tools/libxc/xc_cpufeature.h      |  3 ++-
 tools/libxc/xc_cpuid_x86.c       |  4 +++-
 xen/arch/x86/hvm/hvm.c           | 33 +++++++++++++++++++++------------
 xen/include/asm-x86/cpufeature.h |  5 +++++
 4 files changed, 31 insertions(+), 14 deletions(-)
tools/libxc/xc_cpufeature.h +2 -1
index c3ddc80..5288ac6 100644
@@ -140,6 +140,7 @@
 #define X86_FEATURE_RDSEED      18 /* RDSEED instruction */
 #define X86_FEATURE_ADX         19 /* ADCX, ADOX instructions */
 #define X86_FEATURE_SMAP        20 /* Supervisor Mode Access Protection */
-
+#define X86_FEATURE_CLFLUSHOPT  23 /* CLFLUSHOPT instruction */
+#define X86_FEATURE_CLWB        24 /* CLWB instruction */
 
 #endif /* __LIBXC_CPUFEATURE_H */
tools/libxc/xc_cpuid_x86.c +3 -1
index 8882c01..fecfd6c 100644
@@ -426,7 +426,9 @@ static void xc_cpuid_hvm_policy(xc_interface *xch,
                         bitmaskof(X86_FEATURE_RDSEED)  |
                         bitmaskof(X86_FEATURE_ADX)  |
                         bitmaskof(X86_FEATURE_SMAP) |
-                        bitmaskof(X86_FEATURE_FSGSBASE));
+                        bitmaskof(X86_FEATURE_FSGSBASE) |
+                        bitmaskof(X86_FEATURE_CLWB) |
+                        bitmaskof(X86_FEATURE_CLFLUSHOPT));
         } else
             regs[1] = 0;
         regs[0] = regs[2] = regs[3] = 0;
xen/arch/x86/hvm/hvm.c +21 -12
index 21470ec..9099188 100644
@@ -4583,21 +4583,30 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
             *edx &= ~cpufeat_mask(X86_FEATURE_PSE36);
         break;
     case 0x7:
-        if ( (count == 0) && !cpu_has_smep )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+        if ( count == 0 )
+        {
+            if ( !cpu_has_smep )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+
+            if ( !cpu_has_smap )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+
+            /* Don't expose MPX to hvm when VMX support is not available */
+            if ( !(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
+                 !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
 
-        if ( (count == 0) && !cpu_has_smap )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+            /* Don't expose INVPCID to non-hap hvm. */
+            if ( !hap_enabled(d) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_INVPCID);
 
-        /* Don't expose MPX to hvm when VMX support is not available */
-        if ( (count == 0) &&
-             (!(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
-              !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS)) )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
+            if ( !cpu_has_clflushopt )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLFLUSHOPT);
+
+            if ( !cpu_has_clwb )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);
+        }
 
-        /* Don't expose INVPCID to non-hap hvm. */
-        if ( (count == 0) && !hap_enabled(d) )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_INVPCID);
         break;
     case 0xb:
         /* Fix the x2APIC identifier. */
xen/include/asm-x86/cpufeature.h +5 -0
index ef96514..5818228 100644
@@ -162,6 +162,8 @@
 #define X86_FEATURE_RDSEED	(7*32+18) /* RDSEED instruction */
 #define X86_FEATURE_ADX		(7*32+19) /* ADCX, ADOX instructions */
 #define X86_FEATURE_SMAP	(7*32+20) /* Supervisor Mode Access Prevention */
+#define X86_FEATURE_CLFLUSHOPT	(7*32+23) /* CLFLUSHOPT instruction */
+#define X86_FEATURE_CLWB	(7*32+24) /* CLWB instruction */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx), word 8 */
 #define X86_FEATURE_PKU	(8*32+ 3) /* Protection Keys for Userspace */
@@ -234,6 +236,9 @@
 #define cpu_has_xgetbv1		boot_cpu_has(X86_FEATURE_XGETBV1)
 #define cpu_has_xsaves		boot_cpu_has(X86_FEATURE_XSAVES)
 
+#define cpu_has_clflushopt  boot_cpu_has(X86_FEATURE_CLFLUSHOPT)
+#define cpu_has_clwb        boot_cpu_has(X86_FEATURE_CLWB)
+
 enum _cache_type {
     CACHE_TYPE_NULL = 0,
     CACHE_TYPE_DATA = 1,
Signature · 1 line
2.4.8
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] x86/hvm: allow guest to use clflushopt and clwb

Quoted 7 lines · Haozhong Zhang

Pass CPU features CLFLUSHOPT and CLWB into HVM domain so that those two instructions can be used by guest.

The specification of above two instructions can be found in
https://software.intel.com/sites/default/files/managed/0d/53/319433-022.pdf

Reviewed-by on v2 1/2
#3 lore raw

Re: [PATCH v2 1/2] x86/hvm: allow guest to use clflushopt and clwb

In reply to Haozhong Zhang
Quoted 10 lines

From: Zhang, Haozhong
Sent: Wednesday, December 30, 2015 7:49 PM

Pass CPU features CLFLUSHOPT and CLWB into HVM domain so that those two instructions can be used by guest.

The specification of above two instructions can be found in
https://software.intel.com/sites/default/files/managed/0d/53/319433-022.pdf

#4 lore raw

Re: [PATCH v2 1/2] x86/hvm: allow guest to use clflushopt and clwb

In reply to Haozhong Zhang
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 30.12.15 at 12:48, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +15 -4
@@ -4583,21 +4583,30 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
             *edx &= ~cpufeat_mask(X86_FEATURE_PSE36);
         break;
     case 0x7:
-        if ( (count == 0) && !cpu_has_smep )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+        if ( count == 0 )
+        {
+            if ( !cpu_has_smep )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+
+            if ( !cpu_has_smap )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+
+            /* Don't expose MPX to hvm when VMX support is not available */
+            if ( !(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
+                 !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
 
-        if ( (count == 0) && !cpu_has_smap )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+            /* Don't expose INVPCID to non-hap hvm. */
+            if ( !hap_enabled(d) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_INVPCID);
 

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, · line 4607

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +5 -5
-        /* Don't expose MPX to hvm when VMX support is not available */
-        if ( (count == 0) &&
-             (!(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
-              !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS)) )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
+            if ( !cpu_has_clflushopt )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLFLUSHOPT);
+
+            if ( !cpu_has_clwb )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);

I don't think we need this: Other than other things adjusted here, there's nothing disabling these two features when found available, and there are no extra conditions to consider. Otherwise, if we were to follow this route, quite a bit of code would need to be added to other case statements in this function. But that's all (I think) going to be taken care of by Andrew's CPUID leveling series.

Jan

#5 lore raw

Re: [PATCH v2 1/2] x86/hvm: allow guest to use clflushopt and clwb

Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 30.12.15 at 12:48, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +15 -4
@@ -4583,21 +4583,30 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
             *edx &= ~cpufeat_mask(X86_FEATURE_PSE36);
         break;
     case 0x7:
-        if ( (count == 0) && !cpu_has_smep )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+        if ( count == 0 )
+        {
+            if ( !cpu_has_smep )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+
+            if ( !cpu_has_smap )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+
+            /* Don't expose MPX to hvm when VMX support is not available */
+            if ( !(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
+                 !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
 
-        if ( (count == 0) && !cpu_has_smap )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+            /* Don't expose INVPCID to non-hap hvm. */
+            if ( !hap_enabled(d) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_INVPCID);
 
Quoted 16 lines

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, · line 4607

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +5 -5
-        /* Don't expose MPX to hvm when VMX support is not available */
-        if ( (count == 0) &&
-             (!(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
-              !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS)) )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
+            if ( !cpu_has_clflushopt )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLFLUSHOPT);
+
+            if ( !cpu_has_clwb )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);

I don't think we need this: Other than other things adjusted here, there's nothing disabling these two features when found available, and there are no extra conditions to consider. Otherwise, if we were to follow this route, quite a bit of code would need to be added to other case statements in this function. But that's all (I think) going to be taken care of by Andrew's CPUID leveling series.

My series does take care of all of this.

I would prefer that these two changes get taken as soon as they are ready, so I can rebase.

~Andrew

#6 lore raw

Re: [PATCH v2 1/2] x86/hvm: allow guest to use clflushopt and clwb

Quoted 48 lines
Quoted 1 line
Quoted 1 line · On 07.01.16 at 15:01, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 30.12.15 at 12:48, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -4583,21 +4583,30 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, 

unsigned int *ebx,

Quoted 24 lines
Quoted 24 lines
xen/arch/x86/hvm/hvm.c +15 -4
             *edx &= ~cpufeat_mask(X86_FEATURE_PSE36);
         break;
     case 0x7:
-        if ( (count == 0) && !cpu_has_smep )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+        if ( count == 0 )
+        {
+            if ( !cpu_has_smep )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+
+            if ( !cpu_has_smap )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+
+            /* Don't expose MPX to hvm when VMX support is not available */
+            if ( !(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
+                 !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
 
-        if ( (count == 0) && !cpu_has_smap )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+            /* Don't expose INVPCID to non-hap hvm. */
+            if ( !hap_enabled(d) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_INVPCID);
 
Quoted 16 lines

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, · line 4607

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +5 -5
-        /* Don't expose MPX to hvm when VMX support is not available */
-        if ( (count == 0) &&
-             (!(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
-              !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS)) )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
+            if ( !cpu_has_clflushopt )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLFLUSHOPT);
+
+            if ( !cpu_has_clwb )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);

I don't think we need this: Other than other things adjusted here, there's nothing disabling these two features when found available, and there are no extra conditions to consider. Otherwise, if we were to follow this route, quite a bit of code would need to be added to other case statements in this function. But that's all (I think) going to be taken care of by Andrew's CPUID leveling series.

Quoted 4 lines

My series does take care of all of this.

I would prefer that these two changes get taken as soon as they are ready, so I can rebase.

If we don't need the change quoted above, your rebase will actually be easier to do.

Jan

#7 lore raw

Re: [PATCH v2 1/2] x86/hvm: allow guest to use clflushopt and clwb

Quoted 50 lines · Jan Beulich
Quoted 50 lines
Quoted 1 line
Quoted 1 line · On 07.01.16 at 15:01, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 30.12.15 at 12:48, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -4583,21 +4583,30 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, 

unsigned int *ebx,

Quoted 24 lines
Quoted 24 lines
xen/arch/x86/hvm/hvm.c +15 -4
             *edx &= ~cpufeat_mask(X86_FEATURE_PSE36);
         break;
     case 0x7:
-        if ( (count == 0) && !cpu_has_smep )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+        if ( count == 0 )
+        {
+            if ( !cpu_has_smep )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+
+            if ( !cpu_has_smap )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+
+            /* Don't expose MPX to hvm when VMX support is not available */
+            if ( !(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
+                 !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
 
-        if ( (count == 0) && !cpu_has_smap )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+            /* Don't expose INVPCID to non-hap hvm. */
+            if ( !hap_enabled(d) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_INVPCID);
 
Quoted 16 lines

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, · line 4607

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +5 -5
-        /* Don't expose MPX to hvm when VMX support is not available */
-        if ( (count == 0) &&
-             (!(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
-              !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS)) )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
+            if ( !cpu_has_clflushopt )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLFLUSHOPT);
+
+            if ( !cpu_has_clwb )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);

I don't think we need this: Other than other things adjusted here, there's nothing disabling these two features when found available, and there are no extra conditions to consider. Otherwise, if we were to follow this route, quite a bit of code would need to be added to other case statements in this function. But that's all (I think) going to be taken care of by Andrew's CPUID leveling series.

My series does take care of all of this.

Quoted 8 lines
Quoted 2 lines

I would prefer that these two changes get taken as soon as they are ready, so I can rebase.

If we don't need the change quoted above, your rebase will actually be easier to do.

Jan

I'll remove changes in hvm_cpuid() in the next version. Changes in xen/include/asm-x86/cpufeature.h will be removed as well, because there will be no use of them.

Haozhong

#8 lore raw

Re: [PATCH v2 1/2] x86/hvm: allow guest to use clflushopt and clwb

Quoted 55 lines
Quoted 1 line
Quoted 1 line · On 08.01.16 at 09:27, <[email protected]> wrote:
Quoted 53 lines · Jan Beulich
Quoted 52 lines
Quoted 1 line
Quoted 1 line · On 07.01.16 at 15:01, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 30.12.15 at 12:48, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -4583,21 +4583,30 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, 

unsigned int *ebx,

Quoted 24 lines
Quoted 24 lines
xen/arch/x86/hvm/hvm.c +15 -4
             *edx &= ~cpufeat_mask(X86_FEATURE_PSE36);
         break;
     case 0x7:
-        if ( (count == 0) && !cpu_has_smep )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+        if ( count == 0 )
+        {
+            if ( !cpu_has_smep )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMEP);
+
+            if ( !cpu_has_smap )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+
+            /* Don't expose MPX to hvm when VMX support is not available */
+            if ( !(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
+                 !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
 
-        if ( (count == 0) && !cpu_has_smap )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_SMAP);
+            /* Don't expose INVPCID to non-hap hvm. */
+            if ( !hap_enabled(d) )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_INVPCID);
 
Quoted 16 lines

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, · line 4607

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +5 -5
-        /* Don't expose MPX to hvm when VMX support is not available */
-        if ( (count == 0) &&
-             (!(vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) ||
-              !(vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS)) )
-            *ebx &= ~cpufeat_mask(X86_FEATURE_MPX);
+            if ( !cpu_has_clflushopt )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLFLUSHOPT);
+
+            if ( !cpu_has_clwb )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);

I don't think we need this: Other than other things adjusted here, there's nothing disabling these two features when found available, and there are no extra conditions to consider. Otherwise, if we were to follow this route, quite a bit of code would need to be added to other case statements in this function. But that's all (I think) going to be taken care of by Andrew's CPUID leveling series.

My series does take care of all of this.

I would prefer that these two changes get taken as soon as they are ready, so I can rebase.

Quoted 6 lines
Quoted 3 lines

If we don't need the change quoted above, your rebase will actually be easier to do.

I'll remove changes in hvm_cpuid() in the next version. Changes in xen/include/asm-x86/cpufeature.h will be removed as well, because there will be no use of them.

Indeed - this should become a tools only patch.

Jan

#9 lore raw

PATCH v2 2/2 x86/hvm: add support for pcommit instruction

In reply to Haozhong Zhang

Pass PCOMMIT CPU feature into HMV domain. Currently, we do not intercept pcommit instruction for L1 guest, and allow L1 to intercept pcommit instruction for L2 guest.

The specification of pcommit instruction can be found in
https://software.intel.com/sites/default/files/managed/0d/53/319433-022.pdf

---
 tools/libxc/xc_cpufeature.h        | 1 +
 tools/libxc/xc_cpuid_x86.c         | 1 +
 xen/arch/x86/hvm/hvm.c             | 3 +++
 xen/arch/x86/hvm/vmx/vmcs.c        | 6 +++++-
 xen/arch/x86/hvm/vmx/vmx.c         | 1 +
 xen/arch/x86/hvm/vmx/vvmx.c        | 3 +++
 xen/include/asm-x86/cpufeature.h   | 2 ++
 xen/include/asm-x86/hvm/vmx/vmcs.h | 3 +++
 xen/include/asm-x86/hvm/vmx/vmx.h  | 1 +
 9 files changed, 20 insertions(+), 1 deletion(-)
tools/libxc/xc_cpufeature.h +1 -0
index 5288ac6..ee53679 100644
@@ -140,6 +140,7 @@
 #define X86_FEATURE_RDSEED      18 /* RDSEED instruction */
 #define X86_FEATURE_ADX         19 /* ADCX, ADOX instructions */
 #define X86_FEATURE_SMAP        20 /* Supervisor Mode Access Protection */
+#define X86_FEATURE_PCOMMIT     22 /* PCOMMIT instruction */
 #define X86_FEATURE_CLFLUSHOPT  23 /* CLFLUSHOPT instruction */
 #define X86_FEATURE_CLWB        24 /* CLWB instruction */
 
tools/libxc/xc_cpuid_x86.c +1 -0
index fecfd6c..c142595 100644
@@ -427,6 +427,7 @@ static void xc_cpuid_hvm_policy(xc_interface *xch,
                         bitmaskof(X86_FEATURE_ADX)  |
                         bitmaskof(X86_FEATURE_SMAP) |
                         bitmaskof(X86_FEATURE_FSGSBASE) |
+                        bitmaskof(X86_FEATURE_PCOMMIT) |
                         bitmaskof(X86_FEATURE_CLWB) |
                         bitmaskof(X86_FEATURE_CLFLUSHOPT));
         } else
xen/arch/x86/hvm/hvm.c +3 -0
index 9099188..ae8f8dc 100644
@@ -4605,6 +4605,9 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
 
             if ( !cpu_has_clwb )
                 *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);
+
+            if ( !cpu_has_pcommit )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_PCOMMIT);
         }
 
         break;
xen/arch/x86/hvm/vmx/vmcs.c +5 -1
index edd4c8d..9092a98 100644
@@ -242,7 +242,8 @@ static int vmx_init_vmcs_config(void)
                SECONDARY_EXEC_ENABLE_INVPCID |
                SECONDARY_EXEC_ENABLE_VM_FUNCTIONS |
                SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS |
-               SECONDARY_EXEC_XSAVES);
+               SECONDARY_EXEC_XSAVES |
+               SECONDARY_EXEC_PCOMMIT);
         rdmsrl(MSR_IA32_VMX_MISC, _vmx_misc_cap);
         if ( _vmx_misc_cap & VMX_MISC_VMWRITE_ALL )
             opt |= SECONDARY_EXEC_ENABLE_VMCS_SHADOWING;
@@ -1075,6 +1076,9 @@ static int construct_vmcs(struct vcpu *v)
         __vmwrite(PLE_WINDOW, ple_window);
     }
 
+    if ( cpu_has_vmx_pcommit )
+        v->arch.hvm_vmx.secondary_exec_control &= ~SECONDARY_EXEC_PCOMMIT;
+
     if ( cpu_has_vmx_secondary_exec_control )
         __vmwrite(SECONDARY_VM_EXEC_CONTROL,
                   v->arch.hvm_vmx.secondary_exec_control);
xen/arch/x86/hvm/vmx/vmx.c +1 -0
index b918b8a..0991cdf 100644
@@ -3517,6 +3517,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
     case EXIT_REASON_ACCESS_LDTR_OR_TR:
     case EXIT_REASON_VMX_PREEMPTION_TIMER_EXPIRED:
     case EXIT_REASON_INVPCID:
+    case EXIT_REASON_PCOMMIT:
     /* fall through */
     default:
     exit_and_crash:
xen/arch/x86/hvm/vmx/vvmx.c +3 -0
index ea1052e..271ec70 100644
@@ -1950,6 +1950,8 @@ int nvmx_msr_read_intercept(unsigned int msr, u64 *msr_content)
                SECONDARY_EXEC_ENABLE_VPID |
                SECONDARY_EXEC_UNRESTRICTED_GUEST |
                SECONDARY_EXEC_ENABLE_EPT;
+        if ( cpu_has_vmx_pcommit )
+            data |= SECONDARY_EXEC_PCOMMIT;
         data = gen_vmx_msr(data, 0, host_data);
         break;
     case MSR_IA32_VMX_EXIT_CTLS:
@@ -2226,6 +2228,7 @@ int nvmx_n2_vmexit_handler(struct cpu_user_regs *regs,
     case EXIT_REASON_VMXON:
     case EXIT_REASON_INVEPT:
     case EXIT_REASON_XSETBV:
+    case EXIT_REASON_PCOMMIT:
         /* inject to L1 */
         nvcpu->nv_vmexit_pending = 1;
         break;
xen/include/asm-x86/cpufeature.h +2 -0
index 5818228..7491e37 100644
@@ -162,6 +162,7 @@
 #define X86_FEATURE_RDSEED	(7*32+18) /* RDSEED instruction */
 #define X86_FEATURE_ADX		(7*32+19) /* ADCX, ADOX instructions */
 #define X86_FEATURE_SMAP	(7*32+20) /* Supervisor Mode Access Prevention */
+#define X86_FEATURE_PCOMMIT	(7*32+22) /* PCOMMIT instruction */
 #define X86_FEATURE_CLFLUSHOPT	(7*32+23) /* CLFLUSHOPT instruction */
 #define X86_FEATURE_CLWB	(7*32+24) /* CLWB instruction */
 
@@ -238,6 +239,7 @@
 
 #define cpu_has_clflushopt  boot_cpu_has(X86_FEATURE_CLFLUSHOPT)
 #define cpu_has_clwb        boot_cpu_has(X86_FEATURE_CLWB)
+#define cpu_has_pcommit     boot_cpu_has(X86_FEATURE_PCOMMIT)
 
 enum _cache_type {
     CACHE_TYPE_NULL = 0,
xen/include/asm-x86/hvm/vmx/vmcs.h +3 -0
index d1496b8..77cf8da 100644
@@ -236,6 +236,7 @@ extern u32 vmx_vmentry_control;
 #define SECONDARY_EXEC_ENABLE_PML               0x00020000
 #define SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS   0x00040000
 #define SECONDARY_EXEC_XSAVES                   0x00100000
+#define SECONDARY_EXEC_PCOMMIT                  0x00200000
 extern u32 vmx_secondary_exec_control;
 
 #define VMX_EPT_EXEC_ONLY_SUPPORTED                         0x00000001
@@ -303,6 +304,8 @@ extern u64 vmx_ept_vpid_cap;
     (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_PML)
 #define cpu_has_vmx_xsaves \
     (vmx_secondary_exec_control & SECONDARY_EXEC_XSAVES)
+#define cpu_has_vmx_pcommit \
+    (vmx_secondary_exec_control & SECONDARY_EXEC_PCOMMIT)
 
 #define VMCS_RID_TYPE_MASK              0x80000000
 
xen/include/asm-x86/hvm/vmx/vmx.h +1 -0
index 1719965..14f3d32 100644
@@ -213,6 +213,7 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc)
 #define EXIT_REASON_PML_FULL            62
 #define EXIT_REASON_XSAVES              63
 #define EXIT_REASON_XRSTORS             64
+#define EXIT_REASON_PCOMMIT             65
 
 /*
  * Interruption-information format
Signature · 1 line
2.4.8
Reviewed-by on v2 2/2
#10 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

Quoted 8 lines · Haozhong Zhang

Pass PCOMMIT CPU feature into HMV domain. Currently, we do not intercept pcommit instruction for L1 guest, and allow L1 to intercept pcommit instruction for L2 guest.

The specification of pcommit instruction can be found in
https://software.intel.com/sites/default/files/managed/0d/53/319433-022.pdf

#11 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

In reply to Haozhong Zhang
Quoted 6 lines

From: Zhang, Haozhong
Sent: Wednesday, December 30, 2015 7:49 PM

Pass PCOMMIT CPU feature into HMV domain. Currently, we do not intercept pcommit instruction for L1 guest, and allow L1 to intercept pcommit instruction for L2 guest.

Could you elaborate why different policies are used for L1/L2? And better add a comment in code (at least for vvmx) to describe the intention.

Thanks
Kevin

#12 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

Quoted 7 lines · Kevin
Quoted 6 lines

From: Zhang, Haozhong
Sent: Wednesday, December 30, 2015 7:49 PM

Pass PCOMMIT CPU feature into HMV domain. Currently, we do not intercept pcommit instruction for L1 guest, and allow L1 to intercept pcommit instruction for L2 guest.

Quoted 5 lines

Could you elaborate why different policies are used for L1/L2? And better add a comment in code (at least for vvmx) to describe the intention.

Thanks
Kevin

The intention is that we completely expose pcommit (both the instruction and VMEXIT caused by pcommit) to L1.

Haozhong

#13 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

Quoted 14 lines

From: Zhang, Haozhong
Sent: Tuesday, January 05, 2016 3:15 PM

Quoted 10 lines · Kevin
Quoted 6 lines

From: Zhang, Haozhong
Sent: Wednesday, December 30, 2015 7:49 PM

Pass PCOMMIT CPU feature into HMV domain. Currently, we do not intercept pcommit instruction for L1 guest, and allow L1 to intercept pcommit instruction for L2 guest.

Could you elaborate why different policies are used for L1/L2? And better add a comment in code (at least for vvmx) to describe the intention.

Quoted 7 lines
Quoted 2 lines

Thanks
Kevin

The intention is that we completely expose pcommit (both the instruction and VMEXIT caused by pcommit) to L1.

Haozhong

My question is why pcommit can't not be directly in L2 w/o interception?

Thanks
Kevin

#14 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

Quoted 20 lines · Kevin
Quoted 20 lines

From: Zhang, Haozhong
Sent: Tuesday, January 05, 2016 3:15 PM

Quoted 7 lines · Kevin
Quoted 6 lines

From: Zhang, Haozhong
Sent: Wednesday, December 30, 2015 7:49 PM

Pass PCOMMIT CPU feature into HMV domain. Currently, we do not intercept pcommit instruction for L1 guest, and allow L1 to intercept pcommit instruction for L2 guest.

Quoted 5 lines

Could you elaborate why different policies are used for L1/L2? And better add a comment in code (at least for vvmx) to describe the intention.

Thanks
Kevin

The intention is that we completely expose pcommit (both the instruction and VMEXIT caused by pcommit) to L1.

Quoted 7 lines
Quoted 1 line

Haozhong

My question is why pcommit can't not be directly in L2 w/o interception?

Thanks
Kevin

Isn't it because L1 hypervisor may decide to intercept L2 pcommit?

Haozhong

Acked-by
#15 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

Quoted 26 lines

From: Zhang, Haozhong
Sent: Tuesday, January 05, 2016 3:33 PM

Quoted 22 lines · Kevin
Quoted 21 lines

From: Zhang, Haozhong
Sent: Tuesday, January 05, 2016 3:15 PM

Quoted 7 lines · Kevin
Quoted 6 lines

From: Zhang, Haozhong
Sent: Wednesday, December 30, 2015 7:49 PM

Pass PCOMMIT CPU feature into HMV domain. Currently, we do not intercept pcommit instruction for L1 guest, and allow L1 to intercept pcommit instruction for L2 guest.

Quoted 5 lines

Could you elaborate why different policies are used for L1/L2? And better add a comment in code (at least for vvmx) to describe the intention.

Thanks
Kevin

The intention is that we completely expose pcommit (both the instruction and VMEXIT caused by pcommit) to L1.

Haozhong

Quoted 8 lines
Quoted 5 lines

My question is why pcommit can't not be directly in L2 w/o interception?

Thanks
Kevin

Isn't it because L1 hypervisor may decide to intercept L2 pcommit?

Well, I misunderstood the original statement and actual patch w/ the impression that pcommit interception is always enabled for L2 guest. Now I see that itt's just the intrinsic result when we don't intercept L1 pcommit (either a L1 guest or L1 hypervisor). So,

Thanks
Kevin

#16 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

In reply to Haozhong Zhang

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, · line 4610

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.12.15 at 12:48, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +3 -0
@@ -4605,6 +4605,9 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
 
             if ( !cpu_has_clwb )
                 *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);
+
+            if ( !cpu_has_pcommit )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_PCOMMIT);

Other than for patch 1, this not only need to stay, but needs to be extended along the lines of X86_FEATURE_MPX handling.

xen/arch/x86/hvm/hvm.c static int construct_vmcs(struct vcpu *v) · line 1080

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +2 -0
@@ -1075,6 +1076,9 @@ static int construct_vmcs(struct vcpu *v)
         __vmwrite(PLE_WINDOW, ple_window);
     }
 
+    if ( cpu_has_vmx_pcommit )
+        v->arch.hvm_vmx.secondary_exec_control &= ~SECONDARY_EXEC_PCOMMIT;

Why is this conditional? Instead of the if() there should be a comment imo.

Jan

#17 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 30.12.15 at 12:48, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -4605,6 +4605,9 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
 
Quoted 9 lines

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, · line 4610

Quoted 5 lines
xen/arch/x86/hvm/hvm.c +3 -0
             if ( !cpu_has_clwb )
                 *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);
+
+            if ( !cpu_has_pcommit )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_PCOMMIT);

Other than for patch 1, this not only need to stay, but needs to be extended along the lines of X86_FEATURE_MPX handling.

In section "PCOMMIT - Virtualization Support" of Intel Architecture Instruction Set Extensions Programming Reference, it says

IA32_VMX_PROCBASED_CTLS2[53] (which enumerates support for the 1-setting of “PCOMMIT exiting”) is always the same as CPUID.07H:EBX.PCOMMIT[bit 22].

so checking cpu_has_pcommit is enough here.

Quoted 10 lines

xen/arch/x86/hvm/hvm.c static int construct_vmcs(struct vcpu *v) · line 1080

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +2 -0
@@ -1075,6 +1076,9 @@ static int construct_vmcs(struct vcpu *v)
         __vmwrite(PLE_WINDOW, ple_window);
     }
 
+    if ( cpu_has_vmx_pcommit )
+        v->arch.hvm_vmx.secondary_exec_control &= ~SECONDARY_EXEC_PCOMMIT;

Why is this conditional? Instead of the if() there should be a comment imo.

The condition is not necessary. I'll remove it and add a comment in the next version.

Haozhong

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#18 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 08.01.16 at 02:15, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 30.12.15 at 12:48, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -4605,6 +4605,9 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, 

unsigned int *ebx,

Quoted 10 lines

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, · line 4610

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +3 -0
             if ( !cpu_has_clwb )
                 *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);
+
+            if ( !cpu_has_pcommit )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_PCOMMIT);

Other than for patch 1, this not only need to stay, but needs to be extended along the lines of X86_FEATURE_MPX handling.

Quoted 8 lines

In section "PCOMMIT - Virtualization Support" of Intel Architecture Instruction Set Extensions Programming Reference, it says

IA32_VMX_PROCBASED_CTLS2[53] (which enumerates support for the 1-setting of “PCOMMIT exiting”) is always the same as CPUID.07H:EBX.PCOMMIT[bit 22].

so checking cpu_has_pcommit is enough here.

Even if the documentation says so, I think it is appropriate (as indicated at the very least to match with MPX handling) to add the check (here or elsewhere), just to make obvious that both are a prereq.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#19 lore raw

Re: [PATCH v2 2/2] x86/hvm: add support for pcommit instruction

Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 08.01.16 at 02:15, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 30.12.15 at 12:48, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -4605,6 +4605,9 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, 

unsigned int *ebx,

Quoted 10 lines

xen/arch/x86/hvm/hvm.c void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, · line 4610

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +3 -0
             if ( !cpu_has_clwb )
                 *ebx &= ~cpufeat_mask(X86_FEATURE_CLWB);
+
+            if ( !cpu_has_pcommit )
+                *ebx &= ~cpufeat_mask(X86_FEATURE_PCOMMIT);

Other than for patch 1, this not only need to stay, but needs to be extended along the lines of X86_FEATURE_MPX handling.

In section "PCOMMIT - Virtualization Support" of Intel Architecture Instruction Set Extensions Programming Reference, it says

IA32_VMX_PROCBASED_CTLS2[53] (which enumerates support for the 1-setting of “PCOMMIT exiting”) is always the same as CPUID.07H:EBX.PCOMMIT[bit 22].

Quoted 8 lines
Quoted 1 line

so checking cpu_has_pcommit is enough here.

Even if the documentation says so, I think it is appropriate (as indicated at the very least to match with MPX handling) to add the check (here or elsewhere), just to make obvious that both are a prereq.

Jan

OK, I'll modify in the next version.

Haozhong

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on the v2 series
#20 lore raw
In reply to Haozhong Zhang
Quoted 9 lines · Haozhong Zhang

I split the previous patch series "[PATCH 0/4] add support for vNVDIMM" into two parts. This is the first part that enables clflushopt/clwb/pcommit instructions for HVM guests.

[The second part will be sent separately after v1 patches get reviewed.]

Changes in v2:
* Refactor modifications in hvm_cpuid() per Andrew Cooper's comments.

Quoted 6 lines

Haozhong Zhang (2):
x86/hvm: allow guest to use clflushopt and clwb
x86/hvm: add support for pcommit instruction

 tools/libxc/xc_cpufeature.h        |  4 +++-
 tools/libxc/xc_cpuid_x86.c         |  5 ++++-

Tools bits: