Skip to contentSkip to conversation

VMX MSRs policy for Nested Virt: part 1

PATCH Superseded Sergey Dyasli 2 participants 15 messages Oct 18, 2017 – Nov 28, 2017

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover VMX MSRs policy for Nested Virt: part 1

The end goal of having VMX MSRs policy is to be able to manage L1 VMX features. This patch series is the first part of this work. There is no functional change to what L1 sees in VMX MSRs at this point. But each domain will have a policy object which allows to sensibly query what VMX features the domain has. This will unblock some other nested virtualization work items.

Currently, when nested virt is enabled, the set of L1 VMX features is fixed and calculated by nvmx_msr_read_intercept() as an intersection between the full set of Xen's supported L1 VMX features, the set of actual H/W features and, for MSR_IA32_VMX_EPT_VPID_CAP, the set of features that Xen uses.

The above makes L1 VMX feature set inconsistent between different H/W and there is no ability to control what features are available to L1. The overall set of issues has much in common with CPUID policy.

Part 1 adds VMX MSRs into struct msr_domain_policy and initializes them during domain creation based on CPUID policy. In the future it should be possible to independently configure values of VMX MSRs for each domain.

v3 --> v4:
- VMX MSRs are now separated into 5 logical blocks
- Per MSR availability flags are dropped
- Separate patch for hvm_cr4_guest_valid_bits() is added

v2 --> v3:
- Rebase on top of Generic MSR Policy
- Each VMX MSR now has its own availability flag
- VMX MSRs are now completely defined during domain creation (all CPUID policy changes are taken into account)

Sergey Dyasli (7):
x86/msr: add Raw and Host domain policies x86/msr: add VMX MSRs into struct msr_domain_policy x86/msr: read VMX MSRs values into Raw policy x86/msr: add VMX MSRs into HVM_max domain policy x86/cpuid: update signature of hvm_cr4_guest_valid_bits() x86/msr: update domain policy on CPUID policy changes x86/msr: handle VMX MSRs with guest_rd/wrmsr()

 xen/arch/x86/domctl.c              |   1 +
 xen/arch/x86/hvm/domain.c          |   3 +-
 xen/arch/x86/hvm/hvm.c             |   7 +-
 xen/arch/x86/hvm/svm/svmdebug.c    |   4 +-
 xen/arch/x86/hvm/vmx/vmx.c         |   6 -
 xen/arch/x86/hvm/vmx/vvmx.c        | 178 ------------------
 xen/arch/x86/msr.c                 | 343 ++++++++++++++++++++++++++++++++-
 xen/include/asm-x86/hvm/hvm.h      |   2 +-
 xen/include/asm-x86/hvm/vmx/vvmx.h |   2 -
 xen/include/asm-x86/msr.h          | 376 +++++++++++++++++++++++++++++++++++++
 10 files changed, 727 insertions(+), 195 deletions(-)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v4 1/7 x86/msr: add Raw and Host domain policies

Raw policy contains the actual values from H/W MSRs. PLATFORM_INFO msr needs to be read again because probe_intel_cpuid_faulting() records the presence of X86_FEATURE_CPUID_FAULTING but not the presence of msr itself (if cpuid faulting is not available).

Host policy might have certain features disabled if Xen decides not to use them. For now, make Host policy equal to Raw policy.

---
 xen/arch/x86/msr.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
xen/arch/x86/msr.c +25 -1
index baba44f43d..9737ed706e 100644
@@ -24,12 +24,34 @@
 #include <xen/sched.h>
 #include <asm/msr.h>
 
-struct msr_domain_policy __read_mostly hvm_max_msr_domain_policy,
+struct msr_domain_policy __read_mostly     raw_msr_domain_policy,
+                         __read_mostly    host_msr_domain_policy,
+                         __read_mostly hvm_max_msr_domain_policy,
                          __read_mostly  pv_max_msr_domain_policy;
 
 struct msr_vcpu_policy __read_mostly hvm_max_msr_vcpu_policy,
                        __read_mostly  pv_max_msr_vcpu_policy;
 
+static void __init calculate_raw_policy(void)
+{
+    struct msr_domain_policy *dp = &raw_msr_domain_policy;
+    uint64_t val;
+
+    if ( rdmsr_safe(MSR_INTEL_PLATFORM_INFO, val) == 0 )
+    {
+        dp->plaform_info.available = true;
+        if ( val & MSR_PLATFORM_INFO_CPUID_FAULTING )
+            dp->plaform_info.cpuid_faulting = true;
+    }
+}
+
+static void __init calculate_host_policy(void)
+{
+    struct msr_domain_policy *dp = &host_msr_domain_policy;
+
+    *dp = raw_msr_domain_policy;
+}
+
 static void __init calculate_hvm_max_policy(void)
 {
     struct msr_domain_policy *dp = &hvm_max_msr_domain_policy;
@@ -67,6 +89,8 @@ static void __init calculate_pv_max_policy(void)
 
 void __init init_guest_msr_policy(void)
 {
+    calculate_raw_policy();
+    calculate_host_policy();
     calculate_hvm_max_policy();
     calculate_pv_max_policy();
 }
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH v4 1/7] x86/msr: add Raw and Host domain policies

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.10.17 at 10:27, <[email protected]> wrote:

Raw policy contains the actual values from H/W MSRs. PLATFORM_INFO msr needs to be read again because probe_intel_cpuid_faulting() records the presence of X86_FEATURE_CPUID_FAULTING but not the presence of msr itself (if cpuid faulting is not available).

It would be nice if this information could be propagated to avoid the second read - I really dislike the traces such failed reads leave in logs; at the first glance this always looks as if something was wrong.

Apart from this the patch looks fine.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

PATCH v4 2/7 x86/msr: add VMX MSRs into struct msr_domain_policy

In reply to Sergey Dyasli

New definitions provide a convenient way of accessing contents of VMX MSRs. They are separated into 5 logical blocks:

1. vmx: [VMX_BASIC, VMX_VMCS_ENUM]
2. VMX_PROCBASED_CTLS2
3. VMX_EPT_VPID_CAP
4. vmx_true_ctls: [VMX_TRUE_PINBASED_CTLS, VMX_TRUE_ENTRY_CTLS]
5. VMX_VMFUNC

Every bit value is accessible by its name and bit names match existing Xen's definitions as close as possible. There is a "raw" 64-bit field for each MSR as well as "raw" arrays for vmx and vmx_true_ctls blocks.

---
 xen/arch/x86/msr.c        |  63 ++++++++
 xen/include/asm-x86/msr.h | 373 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 436 insertions(+)
xen/arch/x86/msr.c +63 -0
index 9737ed706e..9dc3de8ce1 100644
@@ -216,6 +216,69 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
     return X86EMUL_EXCEPTION;
 }
 
+static void __init __maybe_unused build_assertions(void)
+{
+    struct msr_domain_policy dp;
+
+    BUILD_BUG_ON(sizeof(dp.vmx.basic) !=
+                 sizeof(dp.vmx.basic.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.pinbased_ctls) !=
+                 sizeof(dp.vmx.pinbased_ctls.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.procbased_ctls) !=
+                 sizeof(dp.vmx.procbased_ctls.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.exit_ctls) !=
+                 sizeof(dp.vmx.exit_ctls.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.entry_ctls) !=
+                 sizeof(dp.vmx.entry_ctls.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.misc) !=
+                 sizeof(dp.vmx.misc.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.cr0_fixed0) !=
+                 sizeof(dp.vmx.cr0_fixed0.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.cr0_fixed1) !=
+                 sizeof(dp.vmx.cr0_fixed1.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.cr4_fixed0) !=
+                 sizeof(dp.vmx.cr4_fixed0.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.cr4_fixed1) !=
+                 sizeof(dp.vmx.cr4_fixed1.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.vmcs_enum) !=
+                 sizeof(dp.vmx.vmcs_enum.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx.raw) !=
+                     sizeof(dp.vmx.basic) +
+                     sizeof(dp.vmx.pinbased_ctls) +
+                     sizeof(dp.vmx.procbased_ctls) +
+                     sizeof(dp.vmx.exit_ctls) +
+                     sizeof(dp.vmx.entry_ctls) +
+                     sizeof(dp.vmx.misc) +
+                     sizeof(dp.vmx.cr0_fixed0) +
+                     sizeof(dp.vmx.cr0_fixed1) +
+                     sizeof(dp.vmx.cr4_fixed0) +
+                     sizeof(dp.vmx.cr4_fixed1) +
+                     sizeof(dp.vmx.vmcs_enum));
+
+    BUILD_BUG_ON(sizeof(dp.vmx_procbased_ctls2) !=
+                 sizeof(dp.vmx_procbased_ctls2.raw));
+
+    BUILD_BUG_ON(sizeof(dp.vmx_ept_vpid_cap) !=
+                 sizeof(dp.vmx_ept_vpid_cap.raw));
+
+    BUILD_BUG_ON(sizeof(dp.vmx_true_ctls.pinbased) !=
+                 sizeof(dp.vmx_true_ctls.pinbased.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx_true_ctls.procbased) !=
+                 sizeof(dp.vmx_true_ctls.procbased.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx_true_ctls.exit) !=
+                 sizeof(dp.vmx_true_ctls.exit.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx_true_ctls.entry) !=
+                 sizeof(dp.vmx_true_ctls.entry.raw));
+    BUILD_BUG_ON(sizeof(dp.vmx_true_ctls.raw) !=
+                     sizeof(dp.vmx_true_ctls.pinbased) +
+                     sizeof(dp.vmx_true_ctls.procbased) +
+                     sizeof(dp.vmx_true_ctls.exit) +
+                     sizeof(dp.vmx_true_ctls.entry));
+
+    BUILD_BUG_ON(sizeof(dp.vmx_vmfunc) !=
+                 sizeof(dp.vmx_vmfunc.raw));
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm-x86/msr.h +373 -0

385 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw

Re: [PATCH v4 2/7] x86/msr: add VMX MSRs into struct msr_domain_policy

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.10.17 at 10:27, <[email protected]> wrote:

New definitions provide a convenient way of accessing contents of VMX MSRs. They are separated into 5 logical blocks:

1. vmx: [VMX_BASIC, VMX_VMCS_ENUM]
2. VMX_PROCBASED_CTLS2
3. VMX_EPT_VPID_CAP
4. vmx_true_ctls: [VMX_TRUE_PINBASED_CTLS, VMX_TRUE_ENTRY_CTLS]
5. VMX_VMFUNC

By merely listing them it is not really possible to judge why e.g. PROCBASED_CTLS2 aren't being grouped into (1). Please clarify the reasons for the split.

Quoted 33 lines
xen/include/asm-x86/msr.h +33 -0
+struct cr0_bits {
+    bool     pe:1;
+    bool     mp:1;
+    bool     em:1;
+    bool     ts:1;
+    bool     et:1;
+    bool     ne:1;
+    uint32_t   :10; /* 6:15 reserved */
+    bool     wp:1;
+    uint32_t   :1;  /* 17 reserved */
+    bool     am:1;
+    uint32_t   :10; /* 19:28 reserved */
+    bool     nw:1;
+    bool     cd:1;
+    bool     pg:1;
+};
+
+struct cr4_bits {
+    bool        vme:1;
+    bool        pvi:1;
+    bool        tsd:1;
+    bool         de:1;
+    bool        pse:1;
+    bool        pae:1;
+    bool        mce:1;
+    bool        pge:1;
+    bool        pce:1;
+    bool     osfxsr:1;
+    bool osxmmexcpt:1;
+    bool       umip:1;
+    uint32_t       :1;  /* 12 reserved */
+    bool       vmxe:1;
+    bool       smxe:1;

xen/include/asm-x86/msr.h void write_efer(u64 val); · line 368

Quoted 10 lines
xen/include/asm-x86/msr.h +10 -0
+    uint32_t       :1;  /* 15 reserved */
+    bool   fsgsbase:1;
+    bool      pcide:1;
+    bool    osxsave:1;
+    uint32_t       :1;  /* 19 reserved */
+    bool       smep:1;
+    bool       smap:1;
+    bool        pke:1;
+    uint32_t       :9;  /* 23:31 reserved */
+};

I don't think these belong in this header - a new x86-structs.h or some such would seem more suitable. Also both are 64-bit registers, and I'm missing the "raw" field anyway (allowing them to be used elsewhere later on).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

PATCH v4 3/7 x86/msr: read VMX MSRs values into Raw policy

In reply to Sergey Dyasli

Add calculate_raw_vmx_policy() which fills Raw policy with H/W values of VMX MSRs. Host policy will contain a copy of these values.

---
 xen/arch/x86/msr.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
xen/arch/x86/msr.c +33 -0
index 9dc3de8ce1..7ac0fceb49 100644
@@ -32,6 +32,37 @@ struct msr_domain_policy __read_mostly     raw_msr_domain_policy,
 struct msr_vcpu_policy __read_mostly hvm_max_msr_vcpu_policy,
                        __read_mostly  pv_max_msr_vcpu_policy;
 
+static void __init calculate_raw_vmx_policy(struct msr_domain_policy *dp)
+{
+    unsigned int i;
+
+    if ( !cpu_has_vmx )
+        return;
+
+    for ( i = MSR_IA32_VMX_BASIC; i <= MSR_IA32_VMX_VMCS_ENUM; i++ )
+        rdmsrl(i, dp->vmx.raw[i - MSR_IA32_VMX_BASIC]);
+
+    if ( dp->vmx.procbased_ctls.allowed_1.activate_secondary_controls )
+    {
+        rdmsrl(MSR_IA32_VMX_PROCBASED_CTLS2, dp->vmx_procbased_ctls2.raw);
+
+        if ( dp->vmx_procbased_ctls2.allowed_1.enable_ept ||
+             dp->vmx_procbased_ctls2.allowed_1.enable_vpid )
+            rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, dp->vmx_ept_vpid_cap.raw);
+    }
+
+    if ( dp->vmx.basic.default1_zero )
+    {
+        for ( i = MSR_IA32_VMX_TRUE_PINBASED_CTLS;
+              i <= MSR_IA32_VMX_TRUE_ENTRY_CTLS; i++ )
+            rdmsrl(i,
+                   dp->vmx_true_ctls.raw[i - MSR_IA32_VMX_TRUE_PINBASED_CTLS]);
+    }
+
+    if ( dp->vmx_procbased_ctls2.allowed_1.enable_vm_functions )
+        rdmsrl(MSR_IA32_VMX_VMFUNC, dp->vmx_vmfunc.raw);
+}
+
 static void __init calculate_raw_policy(void)
 {
     struct msr_domain_policy *dp = &raw_msr_domain_policy;
@@ -43,6 +74,8 @@ static void __init calculate_raw_policy(void)
         if ( val & MSR_PLATFORM_INFO_CPUID_FAULTING )
             dp->plaform_info.cpuid_faulting = true;
     }
+
+    calculate_raw_vmx_policy(dp);
 }
 
 static void __init calculate_host_policy(void)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#6 lore raw

Re: [PATCH v4 3/7] x86/msr: read VMX MSRs values into Raw policy

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 18.10.17 at 10:27, <[email protected]> wrote:
xen/arch/x86/msr.c +7 -0
@@ -32,6 +32,37 @@ struct msr_domain_policy __read_mostly     raw_msr_domain_policy,
 struct msr_vcpu_policy __read_mostly hvm_max_msr_vcpu_policy,
                        __read_mostly  pv_max_msr_vcpu_policy;
 
+static void __init calculate_raw_vmx_policy(struct msr_domain_policy *dp)
+{
+    unsigned int i;
+
+    if ( !cpu_has_vmx )
+        return;
+

xen/arch/x86/msr.c struct msr_domain_policy __read_mostly raw_msr_domain_policy, · line 51

Quoted 10 lines
xen/arch/x86/msr.c +10 -0
+    for ( i = MSR_IA32_VMX_BASIC; i <= MSR_IA32_VMX_VMCS_ENUM; i++ )
+        rdmsrl(i, dp->vmx.raw[i - MSR_IA32_VMX_BASIC]);
+
+    if ( dp->vmx.procbased_ctls.allowed_1.activate_secondary_controls )
+    {
+        rdmsrl(MSR_IA32_VMX_PROCBASED_CTLS2, dp->vmx_procbased_ctls2.raw);
+
+        if ( dp->vmx_procbased_ctls2.allowed_1.enable_ept ||
+             dp->vmx_procbased_ctls2.allowed_1.enable_vpid )
+            rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, dp->vmx_ept_vpid_cap.raw);

For consistency please either move this out of the if() or ...

xen/arch/x86/msr.c struct msr_domain_policy __read_mostly raw_msr_domain_policy, · line 63

Quoted 12 lines
xen/arch/x86/msr.c +12 -0
+    }
+
+    if ( dp->vmx.basic.default1_zero )
+    {
+        for ( i = MSR_IA32_VMX_TRUE_PINBASED_CTLS;
+              i <= MSR_IA32_VMX_TRUE_ENTRY_CTLS; i++ )
+            rdmsrl(i,
+                   dp->vmx_true_ctls.raw[i - MSR_IA32_VMX_TRUE_PINBASED_CTLS]);
+    }
+
+    if ( dp->vmx_procbased_ctls2.allowed_1.enable_vm_functions )
+        rdmsrl(MSR_IA32_VMX_VMFUNC, dp->vmx_vmfunc.raw);

... move this one into that same if() above.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

PATCH v4 4/7 x86/msr: add VMX MSRs into HVM_max domain policy

In reply to Sergey Dyasli

Currently, when nested virt is enabled, the set of L1 VMX features is fixed and calculated by nvmx_msr_read_intercept() as an intersection between the full set of Xen's supported L1 VMX features, the set of actual H/W features and, for MSR_IA32_VMX_EPT_VPID_CAP, the set of features that Xen uses.

Add calculate_hvm_max_vmx_policy() which will save the end result of nvmx_msr_read_intercept() on current H/W into HVM_max domain policy. There will be no functional change to what L1 sees in VMX MSRs. But the actual use of HVM_max domain policy will happen later, when VMX MSRs are handled by guest_rd/wrmsr().

---
 xen/arch/x86/msr.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 129 insertions(+)
xen/arch/x86/msr.c +129 -0
index 7ac0fceb49..ff270befbb 100644
@@ -85,6 +85,133 @@ static void __init calculate_host_policy(void)
     *dp = raw_msr_domain_policy;
 }
 
+#define vmx_host_allowed_cpy(dp, msr, field)                            \
+    do {                                                                \
+        dp->msr.allowed_1.field =                                       \
+            host_msr_domain_policy.msr.allowed_1.field;                 \
+        dp->msr.allowed_0.field =                                       \
+            host_msr_domain_policy.msr.allowed_0.field;                 \
+    } while (0)
+
+#define vmx_host_allowed_cpyb(dp, block, msr, field)                    \
+    do {                                                                \
+        dp->block.msr.allowed_1.field =                                 \
+            host_msr_domain_policy.block.msr.allowed_1.field;           \
+        dp->block.msr.allowed_0.field =                                 \
+            host_msr_domain_policy.block.msr.allowed_0.field;           \
+    } while (0)
+
+static void __init calculate_hvm_max_vmx_policy(struct msr_domain_policy *dp)
+{
+    if ( !cpu_has_vmx )
+        return;
+
+    dp->vmx.basic.raw = host_msr_domain_policy.vmx.basic.raw;
+
+    dp->vmx.pinbased_ctls.raw = ((uint64_t) VMX_PINBASED_CTLS_DEFAULT1 << 32) |
+                                            VMX_PINBASED_CTLS_DEFAULT1;
+    vmx_host_allowed_cpyb(dp, vmx, pinbased_ctls, ext_intr_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, pinbased_ctls, nmi_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, pinbased_ctls, preempt_timer);
+
+    dp->vmx.procbased_ctls.raw =
+        ((uint64_t) VMX_PROCBASED_CTLS_DEFAULT1 << 32) |
+                    VMX_PROCBASED_CTLS_DEFAULT1;
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, virtual_intr_pending);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, use_tsc_offseting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, hlt_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, invlpg_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, mwait_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, rdpmc_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, rdtsc_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, cr8_load_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, cr8_store_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, tpr_shadow);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, virtual_nmi_pending);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, mov_dr_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, uncond_io_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, activate_io_bitmap);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, monitor_trap_flag);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, activate_msr_bitmap);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, monitor_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, pause_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, activate_secondary_controls);
+
+    dp->vmx.exit_ctls.raw = ((uint64_t) VMX_EXIT_CTLS_DEFAULT1 << 32) |
+                                        VMX_EXIT_CTLS_DEFAULT1;
+    vmx_host_allowed_cpyb(dp, vmx, exit_ctls, ia32e_mode);
+    vmx_host_allowed_cpyb(dp, vmx, exit_ctls, load_perf_global_ctrl);
+    vmx_host_allowed_cpyb(dp, vmx, exit_ctls, ack_intr_on_exit);
+    vmx_host_allowed_cpyb(dp, vmx, exit_ctls, save_guest_pat);
+    vmx_host_allowed_cpyb(dp, vmx, exit_ctls, load_host_pat);
+    vmx_host_allowed_cpyb(dp, vmx, exit_ctls, save_guest_efer);
+    vmx_host_allowed_cpyb(dp, vmx, exit_ctls, load_host_efer);
+    vmx_host_allowed_cpyb(dp, vmx, exit_ctls, save_preempt_timer);
+
+    dp->vmx.entry_ctls.raw = ((uint64_t) VMX_ENTRY_CTLS_DEFAULT1 << 32) |
+                                         VMX_ENTRY_CTLS_DEFAULT1;
+    vmx_host_allowed_cpyb(dp, vmx, entry_ctls, ia32e_mode);
+    vmx_host_allowed_cpyb(dp, vmx, entry_ctls, load_perf_global_ctrl);
+    vmx_host_allowed_cpyb(dp, vmx, entry_ctls, load_guest_pat);
+    vmx_host_allowed_cpyb(dp, vmx, entry_ctls, load_guest_efer);
+
+    dp->vmx.misc.raw = host_msr_domain_policy.vmx.misc.raw;
+    /* Do not support CR3-target feature now */
+    dp->vmx.misc.cr3_target = false;
+
+    /* PG, PE bits must be 1 in VMX operation */
+    dp->vmx.cr0_fixed0.allowed_0.pe = true;
+    dp->vmx.cr0_fixed0.allowed_0.pg = true;
+
+    /* allow 0-settings for all bits */
+    dp->vmx.cr0_fixed1.raw = 0xffffffff;
+
+    /* VMXE bit must be 1 in VMX operation */
+    dp->vmx.cr4_fixed0.allowed_0.vmxe = true;
+
+    /*
+     * Allowed CR4 bits will be updated during domain creation by
+     * hvm_cr4_guest_valid_bits()
+     */
+    dp->vmx.cr4_fixed1.raw = host_msr_domain_policy.vmx.cr4_fixed1.raw;
+
+    /* The max index of VVMCS encoding is 0x1f. */
+    dp->vmx.vmcs_enum.vmcs_encoding_max_idx = 0x1f;
+
+    if ( dp->vmx.procbased_ctls.allowed_1.activate_secondary_controls )
+    {
+        vmx_host_allowed_cpy(dp, vmx_procbased_ctls2, virtualize_apic_accesses);
+        vmx_host_allowed_cpy(dp, vmx_procbased_ctls2, enable_ept);
+        vmx_host_allowed_cpy(dp, vmx_procbased_ctls2, descriptor_table_exiting);
+        vmx_host_allowed_cpy(dp, vmx_procbased_ctls2, enable_vpid);
+        vmx_host_allowed_cpy(dp, vmx_procbased_ctls2, unrestricted_guest);
+
+        if ( dp->vmx_procbased_ctls2.allowed_1.enable_ept ||
+             dp->vmx_procbased_ctls2.allowed_1.enable_vpid )
+        {
+            dp->vmx_ept_vpid_cap.raw = nept_get_ept_vpid_cap();
+        }
+    }
+
+    if ( dp->vmx.basic.default1_zero )
+    {
+        dp->vmx_true_ctls.pinbased.raw = dp->vmx.pinbased_ctls.raw;
+
+        dp->vmx_true_ctls.procbased.raw = dp->vmx.procbased_ctls.raw;
+        vmx_host_allowed_cpyb(dp, vmx_true_ctls, procbased, cr3_load_exiting);
+        vmx_host_allowed_cpyb(dp, vmx_true_ctls, procbased, cr3_store_exiting);
+
+        dp->vmx_true_ctls.exit.raw = dp->vmx.exit_ctls.raw;
+
+        dp->vmx_true_ctls.entry.raw = dp->vmx.entry_ctls.raw;
+    }
+
+    /* MSR_IA32_VMX_VMFUNC is N/A */
+}
+
+#undef vmx_host_allowed_cpy
+#undef vmx_host_allowed_cpyb
+
 static void __init calculate_hvm_max_policy(void)
 {
     struct msr_domain_policy *dp = &hvm_max_msr_domain_policy;
@@ -102,6 +229,8 @@ static void __init calculate_hvm_max_policy(void)
 
     /* 0x00000140  MSR_INTEL_MISC_FEATURES_ENABLES */
     vp->misc_features_enables.available = dp->plaform_info.available;
+
+    calculate_hvm_max_vmx_policy(dp);
 }
 
 static void __init calculate_pv_max_policy(void)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#8 lore raw

Re: [PATCH v4 4/7] x86/msr: add VMX MSRs into HVM_max domain policy

xen/arch/x86/msr.c static void __init calculate_host_policy(void) · line 111

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 18.10.17 at 10:27, <[email protected]> wrote:
xen/arch/x86/msr.c +8 -0
+static void __init calculate_hvm_max_vmx_policy(struct msr_domain_policy *dp)
+{
+    if ( !cpu_has_vmx )
+        return;
+
+    dp->vmx.basic.raw = host_msr_domain_policy.vmx.basic.raw;
+
+    dp->vmx.pinbased_ctls.raw = ((uint64_t) VMX_PINBASED_CTLS_DEFAULT1 << 32) |

Stray blank after cast.

xen/arch/x86/msr.c static void __init calculate_host_policy(void) · line 118

Quoted 7 lines
xen/arch/x86/msr.c +7 -0
+                                            VMX_PINBASED_CTLS_DEFAULT1;
+    vmx_host_allowed_cpyb(dp, vmx, pinbased_ctls, ext_intr_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, pinbased_ctls, nmi_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, pinbased_ctls, preempt_timer);
+
+    dp->vmx.procbased_ctls.raw =
+        ((uint64_t) VMX_PROCBASED_CTLS_DEFAULT1 << 32) |

Again.

Quoted 10 lines
xen/arch/x86/msr.c +10 -0
+                    VMX_PROCBASED_CTLS_DEFAULT1;
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, virtual_intr_pending);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, use_tsc_offseting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, hlt_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, invlpg_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, mwait_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, rdpmc_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, rdtsc_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, cr8_load_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, cr8_store_exiting);

xen/arch/x86/msr.c static void __init calculate_host_policy(void) · line 138

Quoted 10 lines
xen/arch/x86/msr.c +10 -0
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, tpr_shadow);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, virtual_nmi_pending);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, mov_dr_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, uncond_io_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, activate_io_bitmap);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, monitor_trap_flag);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, activate_msr_bitmap);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, monitor_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, pause_exiting);
+    vmx_host_allowed_cpyb(dp, vmx, procbased_ctls, activate_secondary_controls);

This looks pretty ugly and hard to maintain to me. Wouldn't it be possible to have static const instances of the structures describing which fields should come from where, allowing simple & and | to be done on the raw fields instead. I understand we won't get away without listing the individual bits, but the overhead here is far higher than if there was a simple initializer line for each field.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw

PATCH v4 5/7 x86/cpuid: update signature of hvm_cr4_guest_valid_bits()

In reply to Sergey Dyasli

With the new cpuid infrastructure there is a domain-wide struct cpuid policy and there is no need to pass a separate struct vcpu * into hvm_cr4_guest_valid_bits() anymore. Make the function accept struct domain * instead and update callers.

---
 xen/arch/x86/hvm/domain.c       | 3 ++-
 xen/arch/x86/hvm/hvm.c          | 7 +++----
 xen/arch/x86/hvm/svm/svmdebug.c | 4 ++--
 xen/arch/x86/hvm/vmx/vvmx.c     | 2 +-
 xen/include/asm-x86/hvm/hvm.h   | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)
xen/arch/x86/hvm/domain.c +2 -1
index 60474649de..ce15ce0470 100644
@@ -111,6 +111,7 @@ static int check_segment(struct segment_register *reg, enum x86_segment seg)
 /* Called by VCPUOP_initialise for HVM guests. */
 int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx)
 {
+    const struct domain *d = v->domain;
     struct cpu_user_regs *uregs = &v->arch.user_regs;
     struct segment_register cs, ds, ss, es, tr;
     const char *errstr;
@@ -272,7 +273,7 @@ int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx)
     if ( v->arch.hvm_vcpu.guest_efer & EFER_LME )
         v->arch.hvm_vcpu.guest_efer |= EFER_LMA;
 
-    if ( v->arch.hvm_vcpu.guest_cr[4] & ~hvm_cr4_guest_valid_bits(v, 0) )
+    if ( v->arch.hvm_vcpu.guest_cr[4] & ~hvm_cr4_guest_valid_bits(d, false) )
     {
         gprintk(XENLOG_ERR, "Bad CR4 value: %#016lx\n",
                 v->arch.hvm_vcpu.guest_cr[4]);
xen/arch/x86/hvm/hvm.c +3 -4
index 205b4cb685..1784c32c7e 100644
@@ -928,9 +928,8 @@ const char *hvm_efer_valid(const struct vcpu *v, uint64_t value,
         X86_CR0_CD | X86_CR0_PG)))
 
 /* These bits in CR4 can be set by the guest. */
-unsigned long hvm_cr4_guest_valid_bits(const struct vcpu *v, bool restore)
+unsigned long hvm_cr4_guest_valid_bits(const struct domain *d, bool restore)
 {
-    const struct domain *d = v->domain;
     const struct cpuid_policy *p;
     bool mce, vmxe;
 
@@ -997,7 +996,7 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
         return -EINVAL;
     }
 
-    if ( ctxt.cr4 & ~hvm_cr4_guest_valid_bits(v, 1) )
+    if ( ctxt.cr4 & ~hvm_cr4_guest_valid_bits(d, true) )
     {
         printk(XENLOG_G_ERR "HVM%d restore: bad CR4 %#" PRIx64 "\n",
                d->domain_id, ctxt.cr4);
@@ -2308,7 +2307,7 @@ int hvm_set_cr4(unsigned long value, bool_t may_defer)
     struct vcpu *v = current;
     unsigned long old_cr;
 
-    if ( value & ~hvm_cr4_guest_valid_bits(v, 0) )
+    if ( value & ~hvm_cr4_guest_valid_bits(v->domain, false) )
     {
         HVM_DBG_LOG(DBG_LEVEL_1,
                     "Guest attempts to set reserved bit in CR4: %lx",
xen/arch/x86/hvm/svm/svmdebug.c +2 -2
index 89ef2db932..e25e3e0423 100644
@@ -119,9 +119,9 @@ bool svm_vmcb_isvalid(const char *from, const struct vmcb_struct *vmcb,
            (cr3 >> v->domain->arch.cpuid->extd.maxphysaddr))) )
         PRINTF("CR3: MBZ bits are set (%#"PRIx64")\n", cr3);
 
-    if ( cr4 & ~hvm_cr4_guest_valid_bits(v, false) )
+    if ( cr4 & ~hvm_cr4_guest_valid_bits(v->domain, false) )
         PRINTF("CR4: invalid bits are set (%#"PRIx64", valid: %#"PRIx64")\n",
-               cr4, hvm_cr4_guest_valid_bits(v, false));
+               cr4, hvm_cr4_guest_valid_bits(v->domain, false));
 
     if ( vmcb_get_dr6(vmcb) >> 32 )
         PRINTF("DR6: bits [63:32] are not zero (%#"PRIx64")\n",
xen/arch/x86/hvm/vmx/vvmx.c +1 -1
index dde02c076b..4d9ffc490c 100644
@@ -2136,7 +2136,7 @@ int nvmx_msr_read_intercept(unsigned int msr, u64 *msr_content)
         data = X86_CR4_VMXE;
         break;
     case MSR_IA32_VMX_CR4_FIXED1:
-        data = hvm_cr4_guest_valid_bits(v, 0);
+        data = hvm_cr4_guest_valid_bits(d, false);
         break;
     case MSR_IA32_VMX_MISC:
         /* Do not support CR3-target feature now */
xen/include/asm-x86/hvm/hvm.h +1 -1
index b687e03dce..47a5f7916d 100644
@@ -612,7 +612,7 @@ static inline bool altp2m_vcpu_emulate_ve(struct vcpu *v)
 /* Check CR4/EFER values */
 const char *hvm_efer_valid(const struct vcpu *v, uint64_t value,
                            signed int cr0_pg);
-unsigned long hvm_cr4_guest_valid_bits(const struct vcpu *v, bool restore);
+unsigned long hvm_cr4_guest_valid_bits(const struct domain *d, bool restore);
 
 /*
  * This must be defined as a macro instead of an inline function,
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v4 5/7
#10 lore raw

Re: [PATCH v4 5/7] x86/cpuid: update signature of hvm_cr4_guest_valid_bits()

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.10.17 at 10:27, <[email protected]> wrote:

With the new cpuid infrastructure there is a domain-wide struct cpuid policy and there is no need to pass a separate struct vcpu * into hvm_cr4_guest_valid_bits() anymore. Make the function accept struct domain * instead and update callers.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#11 lore raw

PATCH v4 6/7 x86/msr: update domain policy on CPUID policy changes

In reply to Sergey Dyasli

Availability of some MSRs depends on certain CPUID bits. Add function recalculate_domain_msr_policy() which updates availability of per-domain MSRs based on current domain's CPUID policy. This function is called when CPUID policy is changed from a toolstack.

Add recalculate_domain_vmx_msr_policy() which changes availability of VMX MSRs based on domain's nested virt settings. Unavailable MSRs are zeroed which allows checking availability bits in them directly without preliminary checks (e.g. cpuid->basic.vmx, activate_secondary_controls, enable_ept).

---
 xen/arch/x86/domctl.c     |  1 +
 xen/arch/x86/msr.c        | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/msr.h |  3 +++
 3 files changed, 59 insertions(+)
xen/arch/x86/domctl.c +1 -0
index 80b4df9ec9..334c67d261 100644
@@ -124,6 +124,7 @@ static int update_domain_cpuid_info(struct domain *d,
     }
 
     recalculate_cpuid_policy(d);
+    recalculate_domain_msr_policy(d);
 
     switch ( ctl->input[0] )
     {
xen/arch/x86/msr.c +55 -0

73 lines not on this page · raw message

xen/include/asm-x86/msr.h +3 -0
index 150000551f..f19e113612 100644
@@ -608,6 +608,9 @@ int init_vcpu_msr_policy(struct vcpu *v);
 int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val);
 int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val);
 
+/* Update availability of per-domain MSRs based on CPUID policy */
+void recalculate_domain_msr_policy(struct domain *d);
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __ASM_MSR_H */
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw

Re: [PATCH v4 6/7] x86/msr: update domain policy on CPUID policy changes

xen/arch/x86/domctl.c static int update_domain_cpuid_info(struct domain *d, · line 127

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 18.10.17 at 10:27, <[email protected]> wrote:
xen/arch/x86/domctl.c +1 -0
@@ -124,6 +124,7 @@ static int update_domain_cpuid_info(struct domain *d,
     }
 
     recalculate_cpuid_policy(d);
+    recalculate_domain_msr_policy(d);

Considering the name of the other function, why not without the "_domain"?

Quoted 33 lines
xen/arch/x86/domctl.c +33 -0
+static void recalculate_domain_vmx_msr_policy(struct domain *d)
+{
+    struct msr_domain_policy *dp = d->arch.msr;
+
+    if ( !nestedhvm_enabled(d) || !d->arch.cpuid->basic.vmx )
+    {
+        memset(dp->vmx.raw, 0, sizeof(dp->vmx.raw));
+        dp->vmx_procbased_ctls2.raw = 0;
+        dp->vmx_ept_vpid_cap.raw = 0;
+        memset(dp->vmx_true_ctls.raw, 0, sizeof(dp->vmx_true_ctls.raw));
+        dp->vmx_vmfunc.raw = 0;
+    }
+    else
+    {
+        memcpy(dp->vmx.raw, hvm_max_msr_domain_policy.vmx.raw,
+               sizeof(dp->vmx.raw));
+        /* Get allowed CR4 bits from CPUID policy */
+        dp->vmx.cr4_fixed1.raw = hvm_cr4_guest_valid_bits(d, false);
+
+        if ( dp->vmx.procbased_ctls.allowed_1.activate_secondary_controls )
+        {
+            dp->vmx_procbased_ctls2.raw =
+                hvm_max_msr_domain_policy.vmx_procbased_ctls2.raw;
+
+            if ( dp->vmx_procbased_ctls2.allowed_1.enable_ept ||
+                 dp->vmx_procbased_ctls2.allowed_1.enable_vpid )
+                dp->vmx_ept_vpid_cap.raw =
+                    hvm_max_msr_domain_policy.vmx_ept_vpid_cap.raw;
+            else
+                dp->vmx_ept_vpid_cap.raw = 0;
+        }
+        else
+        {

xen/arch/x86/domctl.c static int update_domain_cpuid_info(struct domain *d,

Quoted 10 lines
xen/arch/x86/domctl.c +10 -0
+            dp->vmx_procbased_ctls2.raw = 0;
+            dp->vmx_ept_vpid_cap.raw = 0;
+        }
+
+        if ( dp->vmx.basic.default1_zero )
+            memcpy(dp->vmx_true_ctls.raw,
+                   hvm_max_msr_domain_policy.vmx_true_ctls.raw,
+                   sizeof(dp->vmx_true_ctls.raw));
+        else
+            memset(dp->vmx_true_ctls.raw, 0, sizeof(dp->vmx_true_ctls.raw));

Except for the "else" paths this looks pretty similar to code in one of the earlier patches. Any chance the two copies could be morphed into a single way of doing this, so the same logic (which will only get more complicated over time) won't be present in two places?

Also it looks like there's an implied assumption that this won't be called anymore after the guest is first started. While just like for CPUID this is reasonable, is this actually being enforced anywhere?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#13 lore raw

PATCH v4 7/7 x86/msr: handle VMX MSRs with guest_rd/wrmsr()

In reply to Sergey Dyasli

Now that each domain has a correct view of VMX MSRs in it's per-domain MSR policy, it's possible to handle guest's RD/WRMSR with the new handlers. Do it and remove the old nvmx_msr_read_intercept() and associated bits.

There is no functional change to what a guest sees in VMX MSRs.

---
 xen/arch/x86/hvm/vmx/vmx.c         |   6 --
 xen/arch/x86/hvm/vmx/vvmx.c        | 178 -------------------------------------
 xen/arch/x86/msr.c                 |  37 ++++++++
 xen/include/asm-x86/hvm/vmx/vvmx.h |   2 -
 4 files changed, 37 insertions(+), 186 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +0 -6
index c2148701ee..1a1cb98069 100644
@@ -2906,10 +2906,6 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
         if ( nestedhvm_enabled(curr->domain) )
             *msr_content |= IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX;
         break;
-    case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_VMFUNC:
-        if ( !nvmx_msr_read_intercept(msr, msr_content) )
-            goto gp_fault;
-        break;
     case MSR_IA32_MISC_ENABLE:
         rdmsrl(MSR_IA32_MISC_ENABLE, *msr_content);
         /* Debug Trace Store is not supported. */
@@ -3133,8 +3129,6 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         break;
     }
     case MSR_IA32_FEATURE_CONTROL:
-    case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
-        /* None of these MSRs are writeable. */
         goto gp_fault;
 
     case MSR_P6_PERFCTR(0)...MSR_P6_PERFCTR(7):
xen/arch/x86/hvm/vmx/vvmx.c +0 -178

184 lines not on this page · raw message

xen/arch/x86/msr.c +37 -0
index 9ea7447de3..a1c48b6769 100644
@@ -360,8 +360,10 @@ int init_vcpu_msr_policy(struct vcpu *v)
 
 int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
 {
+    const struct domain *d = v->domain;
     const struct msr_domain_policy *dp = v->domain->arch.msr;
     const struct msr_vcpu_policy *vp = v->arch.msr;
+    const struct cpuid_policy *p = d->arch.cpuid;
 
     switch ( msr )
     {
@@ -379,6 +381,37 @@ int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
                _MSR_MISC_FEATURES_CPUID_FAULTING;
         break;
 
+    case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMCS_ENUM:
+        if ( !nestedhvm_enabled(d) || !p->basic.vmx )
+            goto gp_fault;
+        *val = dp->vmx.raw[msr - MSR_IA32_VMX_BASIC];
+        break;
+
+    case MSR_IA32_VMX_PROCBASED_CTLS2:
+        if ( !dp->vmx.procbased_ctls.allowed_1.activate_secondary_controls )
+            goto gp_fault;
+        *val = dp->vmx_procbased_ctls2.raw;
+        break;
+
+    case MSR_IA32_VMX_EPT_VPID_CAP:
+        if ( !(dp->vmx_procbased_ctls2.allowed_1.enable_ept ||
+               dp->vmx_procbased_ctls2.allowed_1.enable_vpid) )
+            goto gp_fault;
+        *val = dp->vmx_ept_vpid_cap.raw;
+        break;
+
+    case MSR_IA32_VMX_TRUE_PINBASED_CTLS ... MSR_IA32_VMX_TRUE_ENTRY_CTLS:
+        if ( !dp->vmx.basic.default1_zero )
+            goto gp_fault;
+        *val = dp->vmx_true_ctls.raw[msr - MSR_IA32_VMX_TRUE_PINBASED_CTLS];
+        break;
+
+    case MSR_IA32_VMX_VMFUNC:
+        if ( !dp->vmx_procbased_ctls2.allowed_1.enable_vm_functions )
+            goto gp_fault;
+        *val = dp->vmx_vmfunc.raw;
+        break;
+
     default:
         return X86EMUL_UNHANDLEABLE;
     }
@@ -423,6 +456,10 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
         break;
     }
 
+    case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
+        /* None of these MSRs are writeable. */
+        goto gp_fault;
+
     default:
         return X86EMUL_UNHANDLEABLE;
     }
xen/include/asm-x86/hvm/vmx/vvmx.h +0 -2
index 3285b03bbb..5950672e93 100644
@@ -222,8 +222,6 @@ int nvmx_handle_vmresume(struct cpu_user_regs *regs);
 int nvmx_handle_vmlaunch(struct cpu_user_regs *regs);
 int nvmx_handle_invept(struct cpu_user_regs *regs);
 int nvmx_handle_invvpid(struct cpu_user_regs *regs);
-int nvmx_msr_read_intercept(unsigned int msr,
-                                u64 *msr_content);
 
 void nvmx_update_exec_control(struct vcpu *v, u32 value);
 void nvmx_update_secondary_exec_control(struct vcpu *v,
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#14 lore raw

Re: [PATCH v4 7/7] x86/msr: handle VMX MSRs with guest_rd/wrmsr()

xen/arch/x86/msr.c int init_vcpu_msr_policy(struct vcpu *v) · line 366

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 18.10.17 at 10:27, <[email protected]> wrote:
xen/arch/x86/msr.c +2 -0
@@ -360,8 +360,10 @@ int init_vcpu_msr_policy(struct vcpu *v)
 
 int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
 {
+    const struct domain *d = v->domain;
     const struct msr_domain_policy *dp = v->domain->arch.msr;
     const struct msr_vcpu_policy *vp = v->arch.msr;
+    const struct cpuid_policy *p = d->arch.cpuid;

"p" is clearly not a name helpful to the reader. Why not "cpuid"?

xen/arch/x86/msr.c int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val) · line 391

Quoted 12 lines
xen/arch/x86/msr.c +8 -0
@@ -379,6 +381,37 @@ int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
                _MSR_MISC_FEATURES_CPUID_FAULTING;
         break;
 
+    case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMCS_ENUM:
+        if ( !nestedhvm_enabled(d) || !p->basic.vmx )
+            goto gp_fault;
+        *val = dp->vmx.raw[msr - MSR_IA32_VMX_BASIC];
+        break;
+
+    case MSR_IA32_VMX_PROCBASED_CTLS2:
+        if ( !dp->vmx.procbased_ctls.allowed_1.activate_secondary_controls )

Here and ...

xen/arch/x86/msr.c int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val) · line 398

Quoted 7 lines
xen/arch/x86/msr.c +7 -0
+            goto gp_fault;
+        *val = dp->vmx_procbased_ctls2.raw;
+        break;
+
+    case MSR_IA32_VMX_EPT_VPID_CAP:
+        if ( !(dp->vmx_procbased_ctls2.allowed_1.enable_ept ||
+               dp->vmx_procbased_ctls2.allowed_1.enable_vpid) )

... here (and more below) again similar logic to what was there in an earlier patch? Wouldn't it be better to generically express the existence of an MSR in the policy (and then perhaps also its writeability, albeit that may need to be a bitmap instead of a single flag for the entire register)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel