Skip to contentSkip to conversation

x86/shadow: convert non-const statics

PATCH Superseded Jan Beulich 3 participants 3 messages Jan 28, 2015 – Jan 29, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/shadow: convert non-const statics

To make obvious that such statics are safe to use, they should be const. In some of the cases, they don't even need to be static.

xen/arch/x86/mm/shadow/common.c +5 -5
@@ -2164,7 +2164,7 @@ int sh_remove_write_access(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2414,7 +2414,7 @@ int sh_remove_all_mappings(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2558,7 +2558,7 @@ void sh_remove_shadows(struct vcpu *v, m
     };
 
     /* Another lookup table, for choosing which mask to use */
-    static unsigned int masks[SH_type_unused] = {
+    static const unsigned int masks[SH_type_unused] = {
         0, /* none    */
         1 << SH_type_l2_32_shadow, /* l1_32   */
         0, /* fl1_32  */
@@ -2685,7 +2685,7 @@ static int sh_clear_up_pointer(struct vc
 
 void sh_reset_l3_up_pointers(struct vcpu *v)
 {
-    static hash_callback_t callbacks[SH_type_unused] = {
+    static const hash_callback_t callbacks[SH_type_unused] = {
         NULL, /* none    */
         NULL, /* l1_32   */
         NULL, /* fl1_32  */
@@ -2703,7 +2703,7 @@ void sh_reset_l3_up_pointers(struct vcpu
         NULL, /* p2m     */
         NULL  /* unused  */
     };
-    static unsigned int callback_mask = 1 << SH_type_l3_64_shadow;    
+    const unsigned int callback_mask = 1 << SH_type_l3_64_shadow;
 
     hash_foreach(v, callback_mask, callbacks, _mfn(INVALID_MFN));
 }

x86/shadow: convert non-const statics

To make obvious that such statics are safe to use, they should be const. In some of the cases, they don't even need to be static.

xen/arch/x86/mm/shadow/common.c +5 -5
@@ -2164,7 +2164,7 @@ int sh_remove_write_access(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2414,7 +2414,7 @@ int sh_remove_all_mappings(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2558,7 +2558,7 @@ void sh_remove_shadows(struct vcpu *v, m
     };
 
     /* Another lookup table, for choosing which mask to use */
-    static unsigned int masks[SH_type_unused] = {
+    static const unsigned int masks[SH_type_unused] = {
         0, /* none    */
         1 << SH_type_l2_32_shadow, /* l1_32   */
         0, /* fl1_32  */
@@ -2685,7 +2685,7 @@ static int sh_clear_up_pointer(struct vc
 
 void sh_reset_l3_up_pointers(struct vcpu *v)
 {
-    static hash_callback_t callbacks[SH_type_unused] = {
+    static const hash_callback_t callbacks[SH_type_unused] = {
         NULL, /* none    */
         NULL, /* l1_32   */
         NULL, /* fl1_32  */
@@ -2703,7 +2703,7 @@ void sh_reset_l3_up_pointers(struct vcpu
         NULL, /* p2m     */
         NULL  /* unused  */
     };
-    static unsigned int callback_mask = 1 << SH_type_l3_64_shadow;    
+    const unsigned int callback_mask = 1 << SH_type_l3_64_shadow;
 
     hash_foreach(v, callback_mask, callbacks, _mfn(INVALID_MFN));
 }

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

Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Jan Beulich

To make obvious that such statics are safe to use, they should be const. In some of the cases, they don't even need to be static.

Quoted 53 lines
xen/arch/x86/mm/shadow/common.c +5 -5
@@ -2164,7 +2164,7 @@ int sh_remove_write_access(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2414,7 +2414,7 @@ int sh_remove_all_mappings(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2558,7 +2558,7 @@ void sh_remove_shadows(struct vcpu *v, m
     };
 
     /* Another lookup table, for choosing which mask to use */
-    static unsigned int masks[SH_type_unused] = {
+    static const unsigned int masks[SH_type_unused] = {
         0, /* none    */
         1 << SH_type_l2_32_shadow, /* l1_32   */
         0, /* fl1_32  */
@@ -2685,7 +2685,7 @@ static int sh_clear_up_pointer(struct vc
 
 void sh_reset_l3_up_pointers(struct vcpu *v)
 {
-    static hash_callback_t callbacks[SH_type_unused] = {
+    static const hash_callback_t callbacks[SH_type_unused] = {
         NULL, /* none    */
         NULL, /* l1_32   */
         NULL, /* fl1_32  */
@@ -2703,7 +2703,7 @@ void sh_reset_l3_up_pointers(struct vcpu
         NULL, /* p2m     */
         NULL  /* unused  */
     };
-    static unsigned int callback_mask = 1 << SH_type_l3_64_shadow;    
+    const unsigned int callback_mask = 1 << SH_type_l3_64_shadow;
 
     hash_foreach(v, callback_mask, callbacks, _mfn(INVALID_MFN));
 }
Quoted 4 lines

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

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

#2 lore raw
In reply to Jan Beulich
Quoted 4 lines · Jan Beulich

To make obvious that such statics are safe to use, they should be const. In some of the cases, they don't even need to be static.

Happy to have the consts, but please keep the statics, to make it clear that they are compile-time constants.

Cheers,

Tim.

Quoted 105 lines
xen/arch/x86/mm/shadow/common.c +5 -5
@@ -2164,7 +2164,7 @@ int sh_remove_write_access(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2414,7 +2414,7 @@ int sh_remove_all_mappings(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2558,7 +2558,7 @@ void sh_remove_shadows(struct vcpu *v, m
     };
 
     /* Another lookup table, for choosing which mask to use */
-    static unsigned int masks[SH_type_unused] = {
+    static const unsigned int masks[SH_type_unused] = {
         0, /* none    */
         1 << SH_type_l2_32_shadow, /* l1_32   */
         0, /* fl1_32  */
@@ -2685,7 +2685,7 @@ static int sh_clear_up_pointer(struct vc
 
 void sh_reset_l3_up_pointers(struct vcpu *v)
 {
-    static hash_callback_t callbacks[SH_type_unused] = {
+    static const hash_callback_t callbacks[SH_type_unused] = {
         NULL, /* none    */
         NULL, /* l1_32   */
         NULL, /* fl1_32  */
@@ -2703,7 +2703,7 @@ void sh_reset_l3_up_pointers(struct vcpu
         NULL, /* p2m     */
         NULL  /* unused  */
     };
-    static unsigned int callback_mask = 1 << SH_type_l3_64_shadow;    
+    const unsigned int callback_mask = 1 << SH_type_l3_64_shadow;
 
     hash_foreach(v, callback_mask, callbacks, _mfn(INVALID_MFN));
 }

x86/shadow: convert non-const statics

To make obvious that such statics are safe to use, they should be const. In some of the cases, they don't even need to be static.

xen/arch/x86/mm/shadow/common.c +5 -5
@@ -2164,7 +2164,7 @@ int sh_remove_write_access(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2414,7 +2414,7 @@ int sh_remove_all_mappings(struct vcpu *
         NULL  /* unused  */
     };
 
-    static unsigned int callback_mask = 
+    const unsigned int callback_mask =
           1 << SH_type_l1_32_shadow
         | 1 << SH_type_fl1_32_shadow
         | 1 << SH_type_l1_pae_shadow
@@ -2558,7 +2558,7 @@ void sh_remove_shadows(struct vcpu *v, m
     };
 
     /* Another lookup table, for choosing which mask to use */
-    static unsigned int masks[SH_type_unused] = {
+    static const unsigned int masks[SH_type_unused] = {
         0, /* none    */
         1 << SH_type_l2_32_shadow, /* l1_32   */
         0, /* fl1_32  */
@@ -2685,7 +2685,7 @@ static int sh_clear_up_pointer(struct vc
 
 void sh_reset_l3_up_pointers(struct vcpu *v)
 {
-    static hash_callback_t callbacks[SH_type_unused] = {
+    static const hash_callback_t callbacks[SH_type_unused] = {
         NULL, /* none    */
         NULL, /* l1_32   */
         NULL, /* fl1_32  */
@@ -2703,7 +2703,7 @@ void sh_reset_l3_up_pointers(struct vcpu
         NULL, /* p2m     */
         NULL  /* unused  */
     };
-    static unsigned int callback_mask = 1 << SH_type_l3_64_shadow;    
+    const unsigned int callback_mask = 1 << SH_type_l3_64_shadow;
 
     hash_foreach(v, callback_mask, callbacks, _mfn(INVALID_MFN));
 }