Skip to contentSkip to conversation

Fixes and improvements to SYSCALL MSR handling

PATCH In review Andrew Cooper 3 participants 29 messages Feb 13, 2017 – Feb 21, 2017

lore
Share & tools
lore
#0 lore raw

cover Fixes and improvements to SYSCALL MSR handling

Andrew Cooper (4):
x86/vmx: Don't leak host syscall MSR state into HVM guests x86/setup: Minor cleanup to host SYSCALL MSR handling x86/vmx: Remove vmx_save_host_msrs() and host_msr_state x86/vmx: Drop vmx_msr_state infrastructure

 xen/arch/x86/acpi/suspend.c            |  14 ++--
 xen/arch/x86/hvm/svm/svm.c             |   2 +-
 xen/arch/x86/hvm/vmx/vmcs.c            |   2 -
 xen/arch/x86/hvm/vmx/vmx.c             | 113 ++++++++-------------------------
 xen/arch/x86/x86_64/traps.c            |  23 ++++---
 xen/include/asm-x86/hvm/vmx/vmcs.h     |  22 ++-----
 xen/include/asm-x86/processor.h        |   3 +
 xen/include/public/arch-x86/hvm/save.h |   4 +-
 8 files changed, 62 insertions(+), 121 deletions(-)
Signature · 7 lines
2.1.4


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

PATCH 1/4 x86/vmx: Don't leak host syscall MSR state into HVM guests

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to be restored when switching into guest context. It should never have been part of the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>

---
 xen/arch/x86/hvm/svm/svm.c             | 2 +-
 xen/arch/x86/hvm/vmx/vmcs.c            | 3 +++
 xen/arch/x86/hvm/vmx/vmx.c             | 5 ++---
 xen/include/public/arch-x86/hvm/save.h | 4 ++--
 4 files changed, 8 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/svm/svm.c +1 -1
index 01c7b58..e09c102 100644
@@ -348,7 +348,7 @@ static void svm_save_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data)
     data->msr_cstar        = vmcb->cstar;
     data->msr_syscall_mask = vmcb->sfmask;
     data->msr_efer         = v->arch.hvm_vcpu.guest_efer;
-    data->msr_flags        = -1ULL;
+    data->msr_flags        = 0;
 }
 
 
xen/arch/x86/hvm/vmx/vmcs.c +3 -0
index 0b77dbc..62340bb 100644
@@ -1090,6 +1090,9 @@ static int construct_vmcs(struct vcpu *v)
             vmx_disable_intercept_for_msr(v, MSR_IA32_BNDCFGS, MSR_TYPE_R | MSR_TYPE_W);
     }
 
+    /* All guest MSR state is dirty. */
+    v->arch.hvm_vmx.msr_state.flags = ((1u << VMX_MSR_COUNT) - 1);
+
     /* I/O access bitmap. */
     __vmwrite(IO_BITMAP_A, __pa(d->arch.hvm_domain.io_bitmap));
     __vmwrite(IO_BITMAP_B, __pa(d->arch.hvm_domain.io_bitmap) + PAGE_SIZE);
xen/arch/x86/hvm/vmx/vmx.c +2 -3
index d3d98da..e3694b3 100644
@@ -779,13 +779,12 @@ static int vmx_vmcs_restore(struct vcpu *v, struct hvm_hw_cpu *c)
 static void vmx_save_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data)
 {
     struct vmx_msr_state *guest_state = &v->arch.hvm_vmx.msr_state;
-    unsigned long guest_flags = guest_state->flags;
 
     data->shadow_gs = v->arch.hvm_vmx.shadow_gs;
     data->msr_cstar = v->arch.hvm_vmx.cstar;
 
     /* save msrs */
-    data->msr_flags        = guest_flags;
+    data->msr_flags        = 0;
     data->msr_lstar        = guest_state->msrs[VMX_INDEX_MSR_LSTAR];
     data->msr_star         = guest_state->msrs[VMX_INDEX_MSR_STAR];
     data->msr_syscall_mask = guest_state->msrs[VMX_INDEX_MSR_SYSCALL_MASK];
@@ -796,7 +795,7 @@ static void vmx_load_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data)
     struct vmx_msr_state *guest_state = &v->arch.hvm_vmx.msr_state;
 
     /* restore msrs */
-    guest_state->flags = data->msr_flags & 7;
+    guest_state->flags = ((1u << VMX_MSR_COUNT) - 1);
     guest_state->msrs[VMX_INDEX_MSR_LSTAR]        = data->msr_lstar;
     guest_state->msrs[VMX_INDEX_MSR_STAR]         = data->msr_star;
     guest_state->msrs[VMX_INDEX_MSR_SYSCALL_MASK] = data->msr_syscall_mask;
xen/include/public/arch-x86/hvm/save.h +2 -2
index 8d73b51..419a3b2 100644
@@ -135,7 +135,7 @@ struct hvm_hw_cpu {
     uint64_t shadow_gs;
 
     /* msr content saved/restored. */
-    uint64_t msr_flags;
+    uint64_t msr_flags; /* Obsolete, ignored. */
     uint64_t msr_lstar;
     uint64_t msr_star;
     uint64_t msr_cstar;
@@ -249,7 +249,7 @@ struct hvm_hw_cpu_compat {
     uint64_t shadow_gs;
 
     /* msr content saved/restored. */
-    uint64_t msr_flags;
+    uint64_t msr_flags; /* Obsolete, ignored. */
     uint64_t msr_lstar;
     uint64_t msr_star;
     uint64_t msr_cstar;
Signature · 7 lines
2.1.4


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

PATCH 2/4 x86/setup: Minor cleanup to host SYSCALL MSR handling

In reply to Andrew Cooper

Xen's choice of the MSR_STAR value is constant across all pcpus. Introduce a new define and use it to avoid the opencoding in subarch_percpu_traps_init() and restore_rest_processor_state().

Despite Intel hardware having an MSR_CSTAR register, nothing actually uses it as the SYSCALL instruction raises #UD out of 64bit mode, meaning that MSR_LSTAR is the only %rip value hardware will use.

Therefore, only create a CSTAR trampoline stub, and save/restore the CSTAR value across suspend/resume on AMD hardware. MSR_CSTAR should now be consistently 0 on Intel hardware.

---
CC: Jan Beulich <[email protected]>

---
 xen/arch/x86/acpi/suspend.c     | 14 ++++++++++----
 xen/arch/x86/x86_64/traps.c     | 17 ++++++++++-------
 xen/include/asm-x86/processor.h |  3 +++
 3 files changed, 23 insertions(+), 11 deletions(-)
xen/arch/x86/acpi/suspend.c +10 -4
index d5c67ee..37fde7d 100644
@@ -32,8 +32,11 @@ void save_rest_processor_state(void)
     saved_fs_base = rdfsbase();
     saved_gs_base = rdgsbase();
     rdmsrl(MSR_SHADOW_GS_BASE, saved_kernel_gs_base);
-    rdmsrl(MSR_CSTAR, saved_cstar);
     rdmsrl(MSR_LSTAR, saved_lstar);
+
+    if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD )
+        rdmsrl(MSR_CSTAR, saved_cstar);
+
     if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL ||
          boot_cpu_data.x86_vendor == X86_VENDOR_CENTAUR )
     {
@@ -53,9 +56,12 @@ void restore_rest_processor_state(void)
 
     /* Recover syscall MSRs */
     wrmsrl(MSR_LSTAR, saved_lstar);
-    wrmsrl(MSR_CSTAR, saved_cstar);
-    wrmsr(MSR_STAR, 0, (FLAT_RING3_CS32<<16) | __HYPERVISOR_CS);
-    wrmsr(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK, 0U);
+
+    if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD )
+        wrmsrl(MSR_CSTAR, saved_cstar);
+
+    wrmsrl(MSR_STAR, XEN_MSR_STAR);
+    wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK);
 
     wrfsbase(saved_fs_base);
     wrgsbase(saved_gs_base);
xen/arch/x86/x86_64/traps.c +10 -7
index fc8cde6..5afe286 100644
@@ -403,11 +403,14 @@ void subarch_percpu_traps_init(void)
         wrmsr(MSR_IA32_SYSENTER_CS, __HYPERVISOR_CS, 0);
     }
 
-    /* Trampoline for SYSCALL entry from compatibility mode. */
-    wrmsrl(MSR_CSTAR, stub_va);
-    offset += write_stub_trampoline(stub_page + (stub_va & ~PAGE_MASK),
-                                    stub_va, stack_bottom,
-                                    (unsigned long)cstar_enter);
+    if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD )
+    {
+        /* Trampoline for SYSCALL entry from compatibility mode. */
+        wrmsrl(MSR_CSTAR, stub_va);
+        offset += write_stub_trampoline(stub_page + (stub_va & ~PAGE_MASK),
+                                        stub_va, stack_bottom,
+                                        (unsigned long)cstar_enter);
+    }
 
     /* Don't consume more than half of the stub space here. */
     ASSERT(offset <= STUB_BUF_SIZE / 2);
@@ -415,8 +418,8 @@ void subarch_percpu_traps_init(void)
     unmap_domain_page(stub_page);
 
     /* Common SYSCALL parameters. */
-    wrmsr(MSR_STAR, 0, ((unsigned int)FLAT_RING3_CS32 << 16) | __HYPERVISOR_CS);
-    wrmsr(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK, 0U);
+    wrmsrl(MSR_STAR, XEN_MSR_STAR);
+    wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK);
 }
 
 void init_int80_direct_trap(struct vcpu *v)
xen/include/asm-x86/processor.h +3 -0
index 7735bc2..843f072 100644
@@ -87,6 +87,9 @@
 
 #define XEN_CR4_PV32_BITS (X86_CR4_SMEP|X86_CR4_SMAP)
 
+/* Common SYSCALL parameters. */
+#define XEN_MSR_STAR (((uint64_t)FLAT_RING3_CS32 << 48) |   \
+                      ((uint64_t)__HYPERVISOR_CS << 32))
 #define XEN_SYSCALL_MASK (X86_EFLAGS_AC|X86_EFLAGS_VM|X86_EFLAGS_RF|    \
                           X86_EFLAGS_NT|X86_EFLAGS_DF|X86_EFLAGS_IF|    \
                           X86_EFLAGS_TF)
Signature · 7 lines
2.1.4


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

PATCH 3/4 x86/vmx: Remove vmx_save_host_msrs() and host_msr_state

In reply to Andrew Cooper

A pcpu's LSTAR, STAR and SYSCALL_MASK MSRs are unconditionally switched when moving in and out of HVM vcpu context. Two of these values are compile time constants, and the third is directly available in an existing per-cpu variable.

There is no need to save host state in vmx_cpu_up() into a different per-cpu structure, so drop all the infrastructure. vmx_restore_host_msrs() is simplified to 3 plain WRMSR instructions.

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/hvm/vmx/vmcs.c        |  2 --
 xen/arch/x86/hvm/vmx/vmx.c         | 33 +++++----------------------------
 xen/arch/x86/x86_64/traps.c        |  6 +++++-
 xen/include/asm-x86/hvm/vmx/vmcs.h |  1 -
 4 files changed, 10 insertions(+), 32 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +0 -2
index 62340bb..a6e1294 100644
@@ -588,8 +588,6 @@ int vmx_cpu_up(void)
 
     BUG_ON(!(read_cr4() & X86_CR4_VMXE));
 
-    vmx_save_host_msrs();
-
     /* 
      * Ensure the current processor operating mode meets 
      * the requred CRO fixed bits in VMX operation. 
xen/arch/x86/hvm/vmx/vmx.c +5 -28
index e3694b3..33e18af 100644
@@ -358,8 +358,6 @@ static void vmx_vcpu_destroy(struct vcpu *v)
     passive_domain_destroy(v);
 }
 
-static DEFINE_PER_CPU(struct vmx_msr_state, host_msr_state);
-
 static const u32 msr_index[VMX_MSR_COUNT] =
 {
     [VMX_INDEX_MSR_LSTAR]        = MSR_LSTAR,
@@ -367,23 +365,10 @@ static const u32 msr_index[VMX_MSR_COUNT] =
     [VMX_INDEX_MSR_SYSCALL_MASK] = MSR_SYSCALL_MASK
 };
 
-void vmx_save_host_msrs(void)
-{
-    struct vmx_msr_state *host_msr_state = &this_cpu(host_msr_state);
-    unsigned int i;
-
-    for ( i = 0; i < ARRAY_SIZE(msr_index); i++ )
-    {
-        ASSERT(msr_index[i]);
-        rdmsrl(msr_index[i], host_msr_state->msrs[i]);
-    }
-}
-
 #define WRITE_MSR(address) do {                                         \
         guest_msr_state->msrs[VMX_INDEX_MSR_ ## address] = msr_content; \
         __set_bit(VMX_INDEX_MSR_ ## address, &guest_msr_state->flags);  \
         wrmsrl(MSR_ ## address, msr_content);                           \
-        __set_bit(VMX_INDEX_MSR_ ## address, &host_msr_state->flags);   \
     } while ( 0 )
 
 static enum handler_return
@@ -436,7 +421,6 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content)
 {
     struct vcpu *v = current;
     struct vmx_msr_state *guest_msr_state = &v->arch.hvm_vmx.msr_state;
-    struct vmx_msr_state *host_msr_state = &this_cpu(host_msr_state);
 
     HVM_DBG_LOG(DBG_LEVEL_MSR, "msr %#x content %#"PRIx64, msr, msr_content);
 
@@ -497,15 +481,10 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content)
  */
 static void vmx_restore_host_msrs(void)
 {
-    struct vmx_msr_state *host_msr_state = &this_cpu(host_msr_state);
-    int i;
-
-    while ( host_msr_state->flags )
-    {
-        i = find_first_set_bit(host_msr_state->flags);
-        wrmsrl(msr_index[i], host_msr_state->msrs[i]);
-        __clear_bit(i, &host_msr_state->flags);
-    }
+    /* Relies on the SYSCALL trampoline being at the start of the stubs. */
+    wrmsrl(MSR_STAR,         XEN_MSR_STAR);
+    wrmsrl(MSR_LSTAR,        this_cpu(stubs.addr));
+    wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK);
 }
 
 static void vmx_save_guest_msrs(struct vcpu *v)
@@ -519,12 +498,11 @@ static void vmx_save_guest_msrs(struct vcpu *v)
 
 static void vmx_restore_guest_msrs(struct vcpu *v)
 {
-    struct vmx_msr_state *guest_msr_state, *host_msr_state;
+    struct vmx_msr_state *guest_msr_state;
     unsigned long guest_flags;
     int i;
 
     guest_msr_state = &v->arch.hvm_vmx.msr_state;
-    host_msr_state = &this_cpu(host_msr_state);
 
     wrmsrl(MSR_SHADOW_GS_BASE, v->arch.hvm_vmx.shadow_gs);
 
@@ -537,7 +515,6 @@ static void vmx_restore_guest_msrs(struct vcpu *v)
         HVM_DBG_LOG(DBG_LEVEL_2,
                     "restore guest's index %d msr %x with value %lx",
                     i, msr_index[i], guest_msr_state->msrs[i]);
-        __set_bit(i, &host_msr_state->flags);
         wrmsrl(msr_index[i], guest_msr_state->msrs[i]);
         __clear_bit(i, &guest_flags);
     }
xen/arch/x86/x86_64/traps.c +5 -1
index 5afe286..8697f1d 100644
@@ -387,7 +387,11 @@ void subarch_percpu_traps_init(void)
 
     stub_page = map_domain_page(_mfn(this_cpu(stubs.mfn)));
 
-    /* Trampoline for SYSCALL entry from 64-bit mode. */
+    /*
+     * Trampoline for SYSCALL entry from 64-bit mode.  The VT-x HVM vcpu
+     * context switch logic relies on the SYSCALL trampoline being at the
+     * start of the stubs.
+     */
     wrmsrl(MSR_LSTAR, stub_va);
     offset = write_stub_trampoline(stub_page + (stub_va & ~PAGE_MASK),
                                    stub_va, stack_bottom,
xen/include/asm-x86/hvm/vmx/vmcs.h +0 -1
index 3eb11e7..99dde44 100644
@@ -28,7 +28,6 @@ extern int  vmx_cpu_up_prepare(unsigned int cpu);
 extern void vmx_cpu_dead(unsigned int cpu);
 extern int  vmx_cpu_up(void);
 extern void vmx_cpu_down(void);
-extern void vmx_save_host_msrs(void);
 
 struct vmcs_struct {
     u32 vmcs_revision_id;
Signature · 7 lines
2.1.4


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

PATCH 4/4 x86/vmx: Drop vmx_msr_state infrastructure

In reply to Andrew Cooper

To avoid leaking host MSR state into guests, guest LSTAR, STAR and SYSCALL_MASK state is unconditionally loaded when switching into guest context.

Attempting to dirty-track the state is pointless; host state is always restoring upon exit from guest context, meaning that guest state is always considered dirty.

Drop struct vmx_msr_state, enum VMX_INDEX_MSR_* and msr_index[]. The guests MSR values are stored plainly in arch_vmx_struct, in the same way as shadow_gs and cstar are. vmx_restore_guest_msrs() and long_mode_do_msr_write() ensure that the hardware MSR values are always up-to-date.

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/hvm/vmx/vmcs.c        |  3 --
 xen/arch/x86/hvm/vmx/vmx.c         | 79 ++++++++++----------------------------
 xen/include/asm-x86/hvm/vmx/vmcs.h | 21 +++-------
 3 files changed, 26 insertions(+), 77 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +0 -3
index a6e1294..e28b649 100644
@@ -1088,9 +1088,6 @@ static int construct_vmcs(struct vcpu *v)
             vmx_disable_intercept_for_msr(v, MSR_IA32_BNDCFGS, MSR_TYPE_R | MSR_TYPE_W);
     }
 
-    /* All guest MSR state is dirty. */
-    v->arch.hvm_vmx.msr_state.flags = ((1u << VMX_MSR_COUNT) - 1);
-
     /* I/O access bitmap. */
     __vmwrite(IO_BITMAP_A, __pa(d->arch.hvm_domain.io_bitmap));
     __vmwrite(IO_BITMAP_B, __pa(d->arch.hvm_domain.io_bitmap) + PAGE_SIZE);
xen/arch/x86/hvm/vmx/vmx.c +21 -58

146 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vmcs.h +5 -16
index 99dde44..199932e 100644
@@ -40,19 +40,6 @@ struct vmx_msr_entry {
     u64 data;
 };
 
-enum {
-    VMX_INDEX_MSR_LSTAR = 0,
-    VMX_INDEX_MSR_STAR,
-    VMX_INDEX_MSR_SYSCALL_MASK,
-
-    VMX_MSR_COUNT
-};
-
-struct vmx_msr_state {
-    unsigned long flags;
-    unsigned long msrs[VMX_MSR_COUNT];
-};
-
 #define EPT_DEFAULT_MT      MTRR_TYPE_WRBACK
 
 struct ept_data {
@@ -124,9 +111,11 @@ struct arch_vmx_struct {
     u32                  secondary_exec_control;
     u32                  exception_bitmap;
 
-    struct vmx_msr_state msr_state;
-    unsigned long        shadow_gs;
-    unsigned long        cstar;
+    uint64_t             shadow_gs;
+    uint64_t             star;
+    uint64_t             lstar;
+    uint64_t             cstar;
+    uint64_t             sfmask;
 
     unsigned long       *msr_bitmap;
     unsigned int         msr_count;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

In reply to Andrew Cooper
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to be restored when switching into guest context. It should never have been part of the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Quoted 7 lines

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

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

#12 lore raw

Re: [PATCH 2/4] x86/setup: Minor cleanup to host SYSCALL MSR handling

In reply to Andrew Cooper
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

Xen's choice of the MSR_STAR value is constant across all pcpus. Introduce a new define and use it to avoid the opencoding in subarch_percpu_traps_init() and restore_rest_processor_state().

Despite Intel hardware having an MSR_CSTAR register, nothing actually uses it as the SYSCALL instruction raises #UD out of 64bit mode, meaning that

Did you mean "32-bit"?

Quoted 5 lines

MSR_LSTAR is the only %rip value hardware will use.

Therefore, only create a CSTAR trampoline stub, and save/restore the CSTAR value across suspend/resume on AMD hardware. MSR_CSTAR should now be consistently 0 on Intel hardware.

It's not documented to be zero when coming out of reset, and you never write zero to it.

Plus, if there would be an Intel CPU supporting compat mode SYSCALL, we'd end up with PV guests having a way to transfer control to ring 0 execution at RIP 0. Sadly the instruction doesn't #GP(0) on a null selector found in STAR, so I think we need to keep storing a valid pointer into CSTAR as long as we set EFER.SCE (which we can't really avoid).

Jan

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

#13 lore raw

Re: [PATCH 2/4] x86/setup: Minor cleanup to host SYSCALL MSR handling

Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

Xen's choice of the MSR_STAR value is constant across all pcpus. Introduce a new define and use it to avoid the opencoding in subarch_percpu_traps_init() and restore_rest_processor_state().

Despite Intel hardware having an MSR_CSTAR register, nothing actually uses it as the SYSCALL instruction raises #UD out of 64bit mode, meaning that

Did you mean "32-bit"?

SYSCALL on Intel will #UD if CS.L == 0, so you can't even use it from a compatability mode segment.

Quoted 9 lines
Quoted 6 lines

MSR_LSTAR is the only %rip value hardware will use.

Therefore, only create a CSTAR trampoline stub, and save/restore the CSTAR value across suspend/resume on AMD hardware. MSR_CSTAR should now be consistently 0 on Intel hardware.

It's not documented to be zero when coming out of reset, and you never write zero to it.

Quoted 6 lines

Plus, if there would be an Intel CPU supporting compat mode SYSCALL, we'd end up with PV guests having a way to transfer control to ring 0 execution at RIP 0. Sadly the instruction doesn't #GP(0) on a null selector found in STAR, so I think we need to keep storing a valid pointer into CSTAR as long as we set EFER.SCE (which we can't really avoid).

Ok. All good points. I will drop this part of the patch and keep it set up unconditionally. This doesn't actually affect the rest of the series.

~Andrew

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

#14 lore raw

Re: [PATCH 2/4] x86/setup: Minor cleanup to host SYSCALL MSR handling

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 16:26, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

Xen's choice of the MSR_STAR value is constant across all pcpus. Introduce a new define and use it to avoid the opencoding in subarch_percpu_traps_init() and restore_rest_processor_state().

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

Despite Intel hardware having an MSR_CSTAR register, nothing actually uses it as the SYSCALL instruction raises #UD out of 64bit mode, meaning that

Did you mean "32-bit"?

SYSCALL on Intel will #UD if CS.L == 0, so you can't even use it from a compatability mode segment.

Right - so my comment stands. Or did you mean "outside of 64-bit mode"?

Jan

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

#15 lore raw

Re: [PATCH 2/4] x86/setup: Minor cleanup to host SYSCALL MSR handling

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 16:26, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

Xen's choice of the MSR_STAR value is constant across all pcpus. Introduce a new define and use it to avoid the opencoding in subarch_percpu_traps_init() and restore_rest_processor_state().

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Despite Intel hardware having an MSR_CSTAR register, nothing actually uses it as the SYSCALL instruction raises #UD out of 64bit mode, meaning that

Did you mean "32-bit"?

SYSCALL on Intel will #UD if CS.L == 0, so you can't even use it from a compatability mode segment.

Right - so my comment stands. Or did you mean "outside of 64-bit mode"?

I did, but I don't see how that is meaningfully different from what I wrote.

OTOH, It doesn't matter as I am dropping that half of the patch.

~Andrew

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

#16 lore raw

Re: [PATCH 2/4] x86/setup: Minor cleanup to host SYSCALL MSR handling

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 16:33, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 16:26, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

Xen's choice of the MSR_STAR value is constant across all pcpus. Introduce a new define and use it to avoid the opencoding in subarch_percpu_traps_init() and restore_rest_processor_state().

Despite Intel hardware having an MSR_CSTAR register, nothing actually uses it as the SYSCALL instruction raises #UD out of 64bit mode, meaning that

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Did you mean "32-bit"?

SYSCALL on Intel will #UD if CS.L == 0, so you can't even use it from a compatability mode segment.

Right - so my comment stands. Or did you mean "outside of 64-bit mode"?

I did, but I don't see how that is meaningfully different from what I wrote.

Interesting, you'll have to correct my English understanding then:
"out of <something>" to me so far meant originating in <something>, quite the opposite of "outside of <something>".

Jan

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

Reviewed-by on v1 3/4
#20 lore raw

Re: [PATCH 3/4] x86/vmx: Remove vmx_save_host_msrs() and host_msr_state

In reply to Andrew Cooper
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

A pcpu's LSTAR, STAR and SYSCALL_MASK MSRs are unconditionally switched when moving in and out of HVM vcpu context. Two of these values are compile time constants, and the third is directly available in an existing per-cpu variable.

There is no need to save host state in vmx_cpu_up() into a different per-cpu structure, so drop all the infrastructure. vmx_restore_host_msrs() is simplified to 3 plain WRMSR instructions.

Nice.

Jan

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

#17 lore raw

PATCH v2 2/4 x86/setup: Intoduce XEN_MSR_STAR

In reply to Andrew Cooper

Xen's choice of the MSR_STAR value is constant across all pcpus. Introduce a new define and use it to avoid the opencoding in subarch_percpu_traps_init() and restore_rest_processor_state().

---
CC: Jan Beulich <[email protected]>

v2:
* Drop all the adjustments to MSR_CSTAR

---
 xen/arch/x86/acpi/suspend.c     | 4 ++--
 xen/arch/x86/x86_64/traps.c     | 4 ++--
 xen/include/asm-x86/processor.h | 3 +++
 3 files changed, 7 insertions(+), 4 deletions(-)
xen/arch/x86/acpi/suspend.c +2 -2
index d5c67ee..0dba3e5 100644
@@ -54,8 +54,8 @@ void restore_rest_processor_state(void)
     /* Recover syscall MSRs */
     wrmsrl(MSR_LSTAR, saved_lstar);
     wrmsrl(MSR_CSTAR, saved_cstar);
-    wrmsr(MSR_STAR, 0, (FLAT_RING3_CS32<<16) | __HYPERVISOR_CS);
-    wrmsr(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK, 0U);
+    wrmsrl(MSR_STAR, XEN_MSR_STAR);
+    wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK);
 
     wrfsbase(saved_fs_base);
     wrgsbase(saved_gs_base);
xen/arch/x86/x86_64/traps.c +2 -2
index fc8cde6..252d2d0 100644
@@ -415,8 +415,8 @@ void subarch_percpu_traps_init(void)
     unmap_domain_page(stub_page);
 
     /* Common SYSCALL parameters. */
-    wrmsr(MSR_STAR, 0, ((unsigned int)FLAT_RING3_CS32 << 16) | __HYPERVISOR_CS);
-    wrmsr(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK, 0U);
+    wrmsrl(MSR_STAR, XEN_MSR_STAR);
+    wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK);
 }
 
 void init_int80_direct_trap(struct vcpu *v)
xen/include/asm-x86/processor.h +3 -0
index 7735bc2..843f072 100644
@@ -87,6 +87,9 @@
 
 #define XEN_CR4_PV32_BITS (X86_CR4_SMEP|X86_CR4_SMAP)
 
+/* Common SYSCALL parameters. */
+#define XEN_MSR_STAR (((uint64_t)FLAT_RING3_CS32 << 48) |   \
+                      ((uint64_t)__HYPERVISOR_CS << 32))
 #define XEN_SYSCALL_MASK (X86_EFLAGS_AC|X86_EFLAGS_VM|X86_EFLAGS_RF|    \
                           X86_EFLAGS_NT|X86_EFLAGS_DF|X86_EFLAGS_IF|    \
                           X86_EFLAGS_TF)
Signature · 7 lines
2.1.4


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

Re: [PATCH 4/4] x86/vmx: Drop vmx_msr_state infrastructure

In reply to Andrew Cooper
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

To avoid leaking host MSR state into guests, guest LSTAR, STAR and SYSCALL_MASK state is unconditionally loaded when switching into guest context.

Attempting to dirty-track the state is pointless; host state is always restoring upon exit from guest context, meaning that guest state is always considered dirty.

Quoted 6 lines

Drop struct vmx_msr_state, enum VMX_INDEX_MSR_* and msr_index[]. The guests MSR values are stored plainly in arch_vmx_struct, in the same way as shadow_gs and cstar are. vmx_restore_guest_msrs() and long_mode_do_msr_write() ensure that the hardware MSR values are always up-to-date.

However, the description above made me think whether always saving/restoring these MSRs is really needed (and desirable):
We don't need the host values in place unless we context switch to a PV guest, so perhaps we should rather write them in paravirt_ctxt_switch_to()?

Jan

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

Reviewed-by on v2 2/4
#18 lore raw

Re: [PATCH v2 2/4] x86/setup: Intoduce XEN_MSR_STAR

In reply to Andrew Cooper
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 16:56, <[email protected]> wrote:

Xen's choice of the MSR_STAR value is constant across all pcpus. Introduce a new define and use it to avoid the opencoding in subarch_percpu_traps_init() and restore_rest_processor_state().

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

#24 lore raw

Re: [PATCH 4/4] x86/vmx: Drop vmx_msr_state infrastructure

In reply to Jan Beulich
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

To avoid leaking host MSR state into guests, guest LSTAR, STAR and SYSCALL_MASK state is unconditionally loaded when switching into guest context.

Attempting to dirty-track the state is pointless; host state is always restoring upon exit from guest context, meaning that guest state is always considered dirty.

Drop struct vmx_msr_state, enum VMX_INDEX_MSR_* and msr_index[]. The guests MSR values are stored plainly in arch_vmx_struct, in the same way as shadow_gs and cstar are. vmx_restore_guest_msrs() and long_mode_do_msr_write() ensure that the hardware MSR values are always up-to-date.

Quoted 8 lines
Quoted 1 line

However, the description above made me think whether always saving/restoring these MSRs is really needed (and desirable):
We don't need the host values in place unless we context switch to a PV guest, so perhaps we should rather write them in paravirt_ctxt_switch_to()?

That would leak the values between different HVM guests.

In principle we could skip the update if context switching to the idle cpu, but that would involve leaking a VT-x-ism into the common code. SVM on the other hand automatically switches these MSRs on all vmentries/exits so Xen always has its MSRs in context.

~Andrew

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

#25 lore raw

Re: [PATCH 4/4] x86/vmx: Drop vmx_msr_state infrastructure

Quoted 23 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

To avoid leaking host MSR state into guests, guest LSTAR, STAR and SYSCALL_MASK state is unconditionally loaded when switching into guest context.

Attempting to dirty-track the state is pointless; host state is always restoring upon exit from guest context, meaning that guest state is always considered dirty.

Drop struct vmx_msr_state, enum VMX_INDEX_MSR_* and msr_index[]. The guests MSR values are stored plainly in arch_vmx_struct, in the same way as shadow_gs and cstar are. vmx_restore_guest_msrs() and long_mode_do_msr_write() ensure that the hardware MSR values are always up-to-date.

Quoted 8 lines
Quoted 1 line

However, the description above made me think whether always saving/restoring these MSRs is really needed (and desirable):
We don't need the host values in place unless we context switch to a PV guest, so perhaps we should rather write them in paravirt_ctxt_switch_to()?

Quoted 6 lines

That would leak the values between different HVM guests.

In principle we could skip the update if context switching to the idle cpu, but that would involve leaking a VT-x-ism into the common code. SVM on the other hand automatically switches these MSRs on all vmentries/exits so Xen always has its MSRs in context.

Furthermore, I did consider whether we should allow the guest to write to those MSRs directly, and handle them like shadow_gs.

I don't expect a plain OS to change them after initial setup, but a nested hypervisor (particularly Xen) is taking quite a performance hit on its context switch path because of these MSRs being intercepted at L0.

~Andrew

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

#27 lore raw

Re: [PATCH 4/4] x86/vmx: Drop vmx_msr_state infrastructure

In reply to Andrew Cooper
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 17:12, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

To avoid leaking host MSR state into guests, guest LSTAR, STAR and SYSCALL_MASK state is unconditionally loaded when switching into guest context.

Attempting to dirty-track the state is pointless; host state is always restoring upon exit from guest context, meaning that guest state is always considered dirty.

Quoted 6 lines

Drop struct vmx_msr_state, enum VMX_INDEX_MSR_* and msr_index[]. The guests MSR values are stored plainly in arch_vmx_struct, in the same way as shadow_gs and cstar are. vmx_restore_guest_msrs() and long_mode_do_msr_write() ensure that the hardware MSR values are always up-to-date.

Quoted 7 lines
Quoted 5 lines

However, the description above made me think whether always saving/restoring these MSRs is really needed (and desirable):
We don't need the host values in place unless we context switch to a PV guest, so perhaps we should rather write them in paravirt_ctxt_switch_to()?

That would leak the values between different HVM guests.

How that? Each HVM guest gets its values written. If what you say were the case, there would then continue to be a host value leak, as you'd imply nothing writes these MSRs when entering a HVM guest.

Quoted 2 lines

In principle we could skip the update if context switching to the idle cpu,

Doesn't that happen already, by virtue of __context_switch() being skipped in that case, yet ->ctxt_switch_from() being invoked from there (and itself being guarded by an idle domain check)?

Quoted 3 lines

but that would involve leaking a VT-x-ism into the common code. SVM on the other hand automatically switches these MSRs on all vmentries/exits so Xen always has its MSRs in context.

Yes, the difference to SVM makes this a little unwieldy.

Jan

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

#26 lore raw

Re: [PATCH 4/4] x86/vmx: Drop vmx_msr_state infrastructure

In reply to Andrew Cooper
Quoted 32 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 17:22, <[email protected]> wrote:
Quoted 23 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 13.02.17 at 15:32, <[email protected]> wrote:

To avoid leaking host MSR state into guests, guest LSTAR, STAR and SYSCALL_MASK state is unconditionally loaded when switching into guest context.

Attempting to dirty-track the state is pointless; host state is always restoring upon exit from guest context, meaning that guest state is always considered dirty.

Drop struct vmx_msr_state, enum VMX_INDEX_MSR_* and msr_index[]. The guests MSR values are stored plainly in arch_vmx_struct, in the same way as shadow_gs and cstar are. vmx_restore_guest_msrs() and long_mode_do_msr_write() ensure that the hardware MSR values are always up-to-date.

Quoted 8 lines
Quoted 1 line

However, the description above made me think whether always saving/restoring these MSRs is really needed (and desirable):
We don't need the host values in place unless we context switch to a PV guest, so perhaps we should rather write them in paravirt_ctxt_switch_to()?

Quoted 6 lines

That would leak the values between different HVM guests.

In principle we could skip the update if context switching to the idle cpu, but that would involve leaking a VT-x-ism into the common code. SVM on the other hand automatically switches these MSRs on all vmentries/exits so Xen always has its MSRs in context.

Quoted 6 lines

Furthermore, I did consider whether we should allow the guest to write to those MSRs directly, and handle them like shadow_gs.

I don't expect a plain OS to change them after initial setup, but a nested hypervisor (particularly Xen) is taking quite a performance hit on its context switch path because of these MSRs being intercepted at L0.

Ah, yes, that would likely help quite a bit.

Jan

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

Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

In reply to Andrew Cooper
Quoted 8 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:32 PM

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to be restored when switching into guest context. It should never have been part of the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Quoted 7 lines

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

the effect of this patch should be more than not leaking syscall MSR. what about making the subject clearer when check-in?

Thanks
Kevin

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

Acked-by on v1 3/4
#21 lore raw

Re: [PATCH 3/4] x86/vmx: Remove vmx_save_host_msrs() and host_msr_state

In reply to Andrew Cooper
Quoted 8 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:32 PM

A pcpu's LSTAR, STAR and SYSCALL_MASK MSRs are unconditionally switched when moving in and out of HVM vcpu context. Two of these values are compile time constants, and the third is directly available in an existing per-cpu variable.

Quoted 5 lines

There is no need to save host state in vmx_cpu_up() into a different per-cpu structure, so drop all the infrastructure. vmx_restore_host_msrs() is simplified to 3 plain WRMSR instructions.

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

Acked-by on v1 4/4
#28 lore raw

Re: [PATCH 4/4] x86/vmx: Drop vmx_msr_state infrastructure

In reply to Andrew Cooper
Quoted 11 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:33 PM

To avoid leaking host MSR state into guests, guest LSTAR, STAR and SYSCALL_MASK state is unconditionally loaded when switching into guest context.

Attempting to dirty-track the state is pointless; host state is always restoring upon exit from guest context, meaning that guest state is always considered dirty.

Quoted 6 lines

Drop struct vmx_msr_state, enum VMX_INDEX_MSR_* and msr_index[]. The guests MSR values are stored plainly in arch_vmx_struct, in the same way as shadow_gs and cstar are. vmx_restore_guest_msrs() and long_mode_do_msr_write() ensure that the hardware MSR values are always up-to-date.

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

#4 lore raw

Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

In reply to Tian, Kevin
Quoted 11 lines · Kevin
Quoted 11 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:32 PM

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to be restored when switching into guest context. It should never have been part of the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

Quoted 8 lines
Quoted 4 lines

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

the effect of this patch should be more than not leaking syscall MSR. what about making the subject clearer when check-in?

What other effects do you think are going on here? Yes, we now context switch the MSRs right from the start of the domain, but that is necessary to avoid leaking them.

~Andrew

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

#5 lore raw

Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

Quoted 19 lines

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew Cooper
Sent: Tuesday, February 14, 2017 3:59 PM

Quoted 15 lines · Kevin
Quoted 15 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:32 PM

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to be restored when switching into guest context. It should never have been part of the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

Quoted 9 lines
Quoted 4 lines

the effect of this patch should be more than not leaking syscall MSR. what about making the subject clearer when check-in?

What other effects do you think are going on here? Yes, we now context switch the MSRs right from the start of the domain, but that is necessary to avoid leaking them.

If just looking at this patch, it's for general MSR save/restore policy, nothing specific to syscall MSR.

Thanks
Kevin

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

#6 lore raw

Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

Quoted 21 lines · Kevin
Quoted 21 lines

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew Cooper
Sent: Tuesday, February 14, 2017 3:59 PM

Quoted 17 lines · Kevin
Quoted 8 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:32 PM

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to be restored when switching into guest context. It should never have been part of the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Quoted 7 lines

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

the effect of this patch should be more than not leaking syscall MSR. what about making the subject clearer when check-in?

What other effects do you think are going on here? Yes, we now context switch the MSRs right from the start of the domain, but that is necessary to avoid leaking them.

If just looking at this patch, it's for general MSR save/restore policy, nothing specific to syscall MSR.

The only three MSRs which use this infrastructure are LSTAR, STAR and FMASK. What if I were to clarify that in the first paragraph?

~Andrew

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

#7 lore raw

Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

Quoted 32 lines

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew Cooper
Sent: Tuesday, February 14, 2017 4:19 PM

Quoted 1 line · Kevin
Quoted 1 line

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew

Cooper

Quoted 26 lines
Quoted 26 lines

Sent: Tuesday, February 14, 2017 3:59 PM

Quoted 11 lines · Kevin
Quoted 11 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:32 PM

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to be restored when switching into guest context. It should never have been part of the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

Quoted 8 lines
Quoted 4 lines

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

the effect of this patch should be more than not leaking syscall MSR. what about making the subject clearer when check-in?

What other effects do you think are going on here? Yes, we now context switch the MSRs right from the start of the domain, but that is necessary to avoid leaking them.

Quoted 7 lines
Quoted 2 lines

If just looking at this patch, it's for general MSR save/restore policy, nothing specific to syscall MSR.

The only three MSRs which use this infrastructure are LSTAR, STAR and FMASK. What if I were to clarify that in the first paragraph?

~Andrew

I meant the subject line (talk about syscall MSR leakage) mismatches the commit message (for general MSR load)

Thanks
Kevin

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

#8 lore raw

Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

Quoted 33 lines
Quoted 33 lines
Quoted 1 line · On 14.02.17 at 09:40, <[email protected]> wrote:

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew Cooper
Sent: Tuesday, February 14, 2017 4:19 PM

Quoted 1 line · Kevin
Quoted 1 line

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew

Cooper

Quoted 26 lines
Quoted 26 lines

Sent: Tuesday, February 14, 2017 3:59 PM

Quoted 11 lines · Kevin
Quoted 11 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:32 PM

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to be restored when switching into guest context. It should never have been part of the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

Quoted 8 lines
Quoted 4 lines

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

the effect of this patch should be more than not leaking syscall MSR. what about making the subject clearer when check-in?

What other effects do you think are going on here? Yes, we now context switch the MSRs right from the start of the domain, but that is necessary to avoid leaking them.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If just looking at this patch, it's for general MSR save/restore policy, nothing specific to syscall MSR.

The only three MSRs which use this infrastructure are LSTAR, STAR and FMASK. What if I were to clarify that in the first paragraph?

I meant the subject line (talk about syscall MSR leakage) mismatches the commit message (for general MSR load)

I'm with Andrew here: The title seems perfectly fine to me, considering that the generic mechanism is only used for the syscall MSRs. Hence I would think his offer to clarify the change in the first paragraph of the commit message ought to suffice. Otherwise, may I ask that you make a concrete suggestion as to what you'd like to see?

Jan

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

#9 lore raw

Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

Quoted 37 lines · Jan Beulich
Quoted 37 lines
Quoted 37 lines
Quoted 1 line · On 14.02.17 at 09:40, <[email protected]> wrote:

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew Cooper
Sent: Tuesday, February 14, 2017 4:19 PM

Quoted 1 line · Kevin
Quoted 1 line

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew

Cooper

Quoted 20 lines
Quoted 20 lines

Sent: Tuesday, February 14, 2017 3:59 PM

Quoted 17 lines · Kevin
Quoted 8 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:32 PM

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to be restored when switching into guest context. It should never have been part of the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Quoted 7 lines

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

the effect of this patch should be more than not leaking syscall MSR. what about making the subject clearer when check-in?

What other effects do you think are going on here? Yes, we now context switch the MSRs right from the start of the domain, but that is necessary to avoid leaking them.

If just looking at this patch, it's for general MSR save/restore policy, nothing specific to syscall MSR.

The only three MSRs which use this infrastructure are LSTAR, STAR and FMASK. What if I were to clarify that in the first paragraph?

Quoted 7 lines
Quoted 2 lines

I meant the subject line (talk about syscall MSR leakage) mismatches the commit message (for general MSR load)

I'm with Andrew here: The title seems perfectly fine to me, considering that the generic mechanism is only used for the syscall MSRs. Hence I would think his offer to clarify the change in the first paragraph of the commit message ought to suffice. Otherwise, may I ask that you make a concrete suggestion as to what you'd like to see?

Kevin: Do you have any other concerns?

~Andrew

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

#10 lore raw

Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

Quoted 55 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 20, 2017 7:17 PM
To: Tian, Kevin
Cc: Jan Beulich; Suravee Suthikulpanit; Nakajima, Jun; Xen-devel; Boris Ostrovsky
Subject: Re: [PATCH 1/4] x86/vmx: Don't leak host syscall MSR state into HVM guests

Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 2 lines
Quoted 1 line · On 14.02.17 at 09:40, <[email protected]> wrote:

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew

Cooper

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Sent: Tuesday, February 14, 2017 4:19 PM

Quoted 1 line · Kevin
Quoted 1 line

From: Andrew Cooper [mailto:[email protected]] On Behalf Of Andrew

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Cooper

Quoted 7 lines
Quoted 7 lines

Sent: Tuesday, February 14, 2017 3:59 PM

Quoted 4 lines · Kevin
Quoted 4 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, February 13, 2017 10:32 PM

hvm_hw_cpu->msr_flags is in fact the VMX dirty bitmap of MSRs needing to

be

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

restored when switching into guest context. It should never have been part

of

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 10 lines

the migration state to start with, and Xen must not make any decisions based on the value seen during restore.

Identify it as obsolete in the header files, consistently save it as zero and ignore it on restore.

The MSRs must be considered dirty during VMCS creation to cause the proper defaults of 0 to be visible to the guest.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

the effect of this patch should be more than not leaking syscall MSR. what about making the subject clearer when check-in?

What other effects do you think are going on here? Yes, we now context switch the MSRs right from the start of the domain, but that is necessary to avoid leaking them.

If just looking at this patch, it's for general MSR save/restore policy, nothing specific to syscall MSR.

The only three MSRs which use this infrastructure are LSTAR, STAR and FMASK. What if I were to clarify that in the first paragraph?

Quoted 7 lines
Quoted 2 lines

I meant the subject line (talk about syscall MSR leakage) mismatches the commit message (for general MSR load)

I'm with Andrew here: The title seems perfectly fine to me, considering that the generic mechanism is only used for the syscall MSRs. Hence I would think his offer to clarify the change in the first paragraph of the commit message ought to suffice. Otherwise, may I ask that you make a concrete suggestion as to what you'd like to see?

Quoted 3 lines

Kevin: Do you have any other concerns?

~Andrew

fine to me.

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