xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] VMX: ensure MSR index enum and array remain in sync
@ 2016-06-20 11:32 Jan Beulich
  2016-06-20 12:31 ` Andrew Cooper
  2016-06-23  8:06 ` Tian, Kevin
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Beulich @ 2016-06-20 11:32 UTC (permalink / raw)
  To: xen-devel; +Cc: Kevin Tian, Jun Nakajima

[-- Attachment #1: Type: text/plain, Size: 1205 bytes --]

... by using dedicated initializers. Also add an ASSERT() to make sure
unintentional addition of holes to the array gets noticed. Ditch
MSR_INDEX_SIZE as redundant with VMX_MSR_COUNT.

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

--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -321,20 +321,23 @@ static void vmx_vcpu_destroy(struct vcpu
 
 static DEFINE_PER_CPU(struct vmx_msr_state, host_msr_state);
 
-static const u32 msr_index[] =
+static const u32 msr_index[VMX_MSR_COUNT] =
 {
-    MSR_LSTAR, MSR_STAR, MSR_SYSCALL_MASK
+    [VMX_INDEX_MSR_LSTAR]        = MSR_LSTAR,
+    [VMX_INDEX_MSR_STAR]         = MSR_STAR,
+    [VMX_INDEX_MSR_SYSCALL_MASK] = MSR_SYSCALL_MASK
 };
 
-#define MSR_INDEX_SIZE (ARRAY_SIZE(msr_index))
-
 void vmx_save_host_msrs(void)
 {
     struct vmx_msr_state *host_msr_state = &this_cpu(host_msr_state);
-    int i;
+    unsigned int i;
 
-    for ( i = 0; i < MSR_INDEX_SIZE; i++ )
+    for ( i = 0; i < VMX_MSR_COUNT; i++ )
+    {
+        ASSERT(msr_index[i]);
         rdmsrl(msr_index[i], host_msr_state->msrs[i]);
+    }
 }
 
 #define WRITE_MSR(address) do {                                         \




[-- Attachment #2: VMX-msr_index-initializers.patch --]
[-- Type: text/plain, Size: 1254 bytes --]

VMX: ensure MSR index enum and array remain in sync

... by using dedicated initializers. Also add an ASSERT() to make sure
unintentional addition of holes to the array gets noticed. Ditch
MSR_INDEX_SIZE as redundant with VMX_MSR_COUNT.

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

--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -321,20 +321,23 @@ static void vmx_vcpu_destroy(struct vcpu
 
 static DEFINE_PER_CPU(struct vmx_msr_state, host_msr_state);
 
-static const u32 msr_index[] =
+static const u32 msr_index[VMX_MSR_COUNT] =
 {
-    MSR_LSTAR, MSR_STAR, MSR_SYSCALL_MASK
+    [VMX_INDEX_MSR_LSTAR]        = MSR_LSTAR,
+    [VMX_INDEX_MSR_STAR]         = MSR_STAR,
+    [VMX_INDEX_MSR_SYSCALL_MASK] = MSR_SYSCALL_MASK
 };
 
-#define MSR_INDEX_SIZE (ARRAY_SIZE(msr_index))
-
 void vmx_save_host_msrs(void)
 {
     struct vmx_msr_state *host_msr_state = &this_cpu(host_msr_state);
-    int i;
+    unsigned int i;
 
-    for ( i = 0; i < MSR_INDEX_SIZE; i++ )
+    for ( i = 0; i < VMX_MSR_COUNT; i++ )
+    {
+        ASSERT(msr_index[i]);
         rdmsrl(msr_index[i], host_msr_state->msrs[i]);
+    }
 }
 
 #define WRITE_MSR(address) do {                                         \

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] VMX: ensure MSR index enum and array remain in sync
  2016-06-20 11:32 [PATCH] VMX: ensure MSR index enum and array remain in sync Jan Beulich
@ 2016-06-20 12:31 ` Andrew Cooper
  2016-06-23  8:06 ` Tian, Kevin
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2016-06-20 12:31 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Kevin Tian, Jun Nakajima

On 20/06/16 12:32, Jan Beulich wrote:
> ... by using dedicated initializers. Also add an ASSERT() to make sure
> unintentional addition of holes to the array gets noticed. Ditch
> MSR_INDEX_SIZE as redundant with VMX_MSR_COUNT.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -321,20 +321,23 @@ static void vmx_vcpu_destroy(struct vcpu
>  
>  static DEFINE_PER_CPU(struct vmx_msr_state, host_msr_state);
>  
> -static const u32 msr_index[] =
> +static const u32 msr_index[VMX_MSR_COUNT] =
>  {
> -    MSR_LSTAR, MSR_STAR, MSR_SYSCALL_MASK
> +    [VMX_INDEX_MSR_LSTAR]        = MSR_LSTAR,
> +    [VMX_INDEX_MSR_STAR]         = MSR_STAR,
> +    [VMX_INDEX_MSR_SYSCALL_MASK] = MSR_SYSCALL_MASK
>  };
>  
> -#define MSR_INDEX_SIZE (ARRAY_SIZE(msr_index))
> -
>  void vmx_save_host_msrs(void)
>  {
>      struct vmx_msr_state *host_msr_state = &this_cpu(host_msr_state);
> -    int i;
> +    unsigned int i;
>  
> -    for ( i = 0; i < MSR_INDEX_SIZE; i++ )
> +    for ( i = 0; i < VMX_MSR_COUNT; i++ )

I would recommend using ARRAY_SIZE(msr_index) here (as well as dropping
MSR_INDEX_SIZE).  It is better self-documentation, more resilient to
changes in msr_index[] length.

Otherwise, Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] VMX: ensure MSR index enum and array remain in sync
  2016-06-20 11:32 [PATCH] VMX: ensure MSR index enum and array remain in sync Jan Beulich
  2016-06-20 12:31 ` Andrew Cooper
@ 2016-06-23  8:06 ` Tian, Kevin
  1 sibling, 0 replies; 3+ messages in thread
From: Tian, Kevin @ 2016-06-23  8:06 UTC (permalink / raw)
  To: Jan Beulich, xen-devel; +Cc: Nakajima, Jun

> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: Monday, June 20, 2016 7:32 PM
> 
> ... by using dedicated initializers. Also add an ASSERT() to make sure
> unintentional addition of holes to the array gets noticed. Ditch
> MSR_INDEX_SIZE as redundant with VMX_MSR_COUNT.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

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

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-23  8:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-20 11:32 [PATCH] VMX: ensure MSR index enum and array remain in sync Jan Beulich
2016-06-20 12:31 ` Andrew Cooper
2016-06-23  8:06 ` Tian, Kevin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).