diff mbox

VMX: use non-atomic bitops to manage MSR state

Message ID 5767F02202000078000F6A32@prv-mh.provo.novell.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Beulich June 20, 2016, 11:31 a.m. UTC
All host_msr_state accesses are solely on the owning CPU, and all
guest_msr_state ones solely when the vCPU is current or being switched
to. This, btw, is also in line with the use of find_first_set_bit()
(which would be bogus if ->flags could get updated behind its back).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
VMX: use non-atomic bitops to manage MSR state

All host_msr_state accesses are solely on the owning CPU, and all
guest_msr_state ones solely when the vCPU is current or being switched
to. This, btw, is also in line with the use of find_first_set_bit()
(which would be bogus if ->flags could get updated behind its back).

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -339,9 +339,9 @@ void vmx_save_host_msrs(void)
 
 #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);    \
+        __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);     \
+        __set_bit(VMX_INDEX_MSR_ ## address, &host_msr_state->flags);   \
     } while ( 0 )
 
 static enum handler_return
@@ -462,7 +462,7 @@ static void vmx_restore_host_msrs(void)
     {
         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);
+        __clear_bit(i, &host_msr_state->flags);
     }
 }
 
@@ -495,9 +495,9 @@ static void vmx_restore_guest_msrs(struc
         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);
+        __set_bit(i, &host_msr_state->flags);
         wrmsrl(msr_index[i], guest_msr_state->msrs[i]);
-        clear_bit(i, &guest_flags);
+        __clear_bit(i, &guest_flags);
     }
 
     if ( (v->arch.hvm_vcpu.guest_efer ^ read_efer()) & EFER_SCE )

Comments

Andrew Cooper June 20, 2016, 12:25 p.m. UTC | #1
On 20/06/16 12:31, Jan Beulich wrote:
> All host_msr_state accesses are solely on the owning CPU, and all
> guest_msr_state ones solely when the vCPU is current or being switched
> to. This, btw, is also in line with the use of find_first_set_bit()
> (which would be bogus if ->flags could get updated behind its back).
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Tian, Kevin June 23, 2016, 7:36 a.m. UTC | #2
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: Monday, June 20, 2016 7:31 PM
> 
> All host_msr_state accesses are solely on the owning CPU, and all
> guest_msr_state ones solely when the vCPU is current or being switched
> to. This, btw, is also in line with the use of find_first_set_bit()
> (which would be bogus if ->flags could get updated behind its back).
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 

Acked-by: Kevin Tian <kevin.tian@intel.com>
diff mbox

Patch

--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -339,9 +339,9 @@  void vmx_save_host_msrs(void)
 
 #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);    \
+        __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);     \
+        __set_bit(VMX_INDEX_MSR_ ## address, &host_msr_state->flags);   \
     } while ( 0 )
 
 static enum handler_return
@@ -462,7 +462,7 @@  static void vmx_restore_host_msrs(void)
     {
         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);
+        __clear_bit(i, &host_msr_state->flags);
     }
 }
 
@@ -495,9 +495,9 @@  static void vmx_restore_guest_msrs(struc
         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);
+        __set_bit(i, &host_msr_state->flags);
         wrmsrl(msr_index[i], guest_msr_state->msrs[i]);
-        clear_bit(i, &guest_flags);
+        __clear_bit(i, &guest_flags);
     }
 
     if ( (v->arch.hvm_vcpu.guest_efer ^ read_efer()) & EFER_SCE )