Skip to contentSkip to conversation

hvm/vmx: WRITE_MSR() macro hygene

PATCH In review Andrew Cooper 3 participants 3 messages Jan 8, 2015 – Jan 9, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hvm/vmx: WRITE_MSR() macro hygene

Use the standard "do { } while ( 0 )" semantics, and don't hide the break statement, incase this macro wants to be used anywhere outside of a switch.

No functional change, but it is now clear that long_mode_do_msr_write() doesn't have fallthough for the STAR, LSTAR and SYSCALL_MASK cases.

CC Jan Beulich <[email protected]>
CC Jun Nakajima <[email protected]>
CC Eddie Dong <[email protected]>
CC Kevin Tian <[email protected]>
---
 xen/arch/x86/hvm/vmx/vmx.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +5 -2
index f2554d6..522892f 100644
@@ -152,12 +152,12 @@ void vmx_save_host_msrs(void)
         rdmsrl(msr_index[i], host_msr_state->msrs[i]);
 }
 
-#define WRITE_MSR(address)                                              \
+#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);     \
-        break
+    } while ( 0 )
 
 static enum handler_return
 long_mode_do_msr_read(unsigned int msr, uint64_t *msr_content)
@@ -232,11 +232,13 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content)
 
     case MSR_STAR:
         WRITE_MSR(STAR);
+        break;
 
     case MSR_LSTAR:
         if ( !is_canonical_address(msr_content) )
             goto uncanonical_address;
         WRITE_MSR(LSTAR);
+        break;
 
     case MSR_CSTAR:
         if ( !is_canonical_address(msr_content) )
@@ -246,6 +248,7 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content)
 
     case MSR_SYSCALL_MASK:
         WRITE_MSR(SYSCALL_MASK);
+        break;
 
     default:
         return HNDL_unhandled;
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Andrew Cooper

Use the standard "do { } while ( 0 )" semantics, and don't hide the break statement, incase this macro wants to be used anywhere outside of a switch.

No functional change, but it is now clear that long_mode_do_msr_write() doesn't have fallthough for the STAR, LSTAR and SYSCALL_MASK cases.

Acked-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 6 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Thursday, January 08, 2015 11:39 PM

Use the standard "do { } while ( 0 )" semantics, and don't hide the break statement, incase this macro wants to be used anywhere outside of a switch.

Quoted 8 lines

No functional change, but it is now clear that long_mode_do_msr_write() doesn't have fallthough for the STAR, LSTAR and SYSCALL_MASK cases.

CC Jan Beulich <[email protected]>
CC Jun Nakajima <[email protected]>
CC Eddie Dong <[email protected]>
CC Kevin Tian <[email protected]>
Quoted 55 lines
---
 xen/arch/x86/hvm/vmx/vmx.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index f2554d6..522892f 100644
@@ -152,12 +152,12 @@ void vmx_save_host_msrs(void)
         rdmsrl(msr_index[i], host_msr_state->msrs[i]);
 }
 
-#define WRITE_MSR(address)
 \
+#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);

\

xen/arch/x86/hvm/vmx/vmx.c +3 -1
-        break
+    } while ( 0 )
 
 static enum handler_return
 long_mode_do_msr_read(unsigned int msr, uint64_t *msr_content)
@@ -232,11 +232,13 @@ long_mode_do_msr_write(unsigned int msr,
 uint64_t msr_content)
 
     case MSR_STAR:
         WRITE_MSR(STAR);
+        break;
 
     case MSR_LSTAR:
         if ( !is_canonical_address(msr_content) )
             goto uncanonical_address;
         WRITE_MSR(LSTAR);
+        break;
 
     case MSR_CSTAR:

if ( !is_canonical_address(msr_content) )

xen/arch/x86/hvm/vmx/vmx.c +1 -0
@@ -246,6 +248,7 @@ long_mode_do_msr_write(unsigned int msr, uint64_t
 msr_content)
 
     case MSR_SYSCALL_MASK:
         WRITE_MSR(SYSCALL_MASK);
+        break;
 
     default:
         return HNDL_unhandled;

--
1.7.10.4