x86/shadow: misc minor adjustments
cover x86/shadow: misc minor adjustments
1: convert non-const statics
2: adjust mask shadow_audit_tables() passes to hash_foreach() 3: use shorter constants for callback masks
PATCH v2 1/3 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 wouldn't even need to be static, but keep them so upon the maintainer's request.
---
v2: Retain static-s, upon Tim's request.
xen/arch/x86/mm/shadow/common.c +5 -5
@@ -2162,7 +2162,7 @@ int sh_remove_write_access(struct vcpu * NULL /* unused */ }; -static unsigned int callback_mask = +static const unsigned int callback_mask =1 << SH_type_l1_32_shadow |1 << SH_type_fl1_32_shadow |1 << SH_type_l1_pae_shadow
@@ -2412,7 +2412,7 @@ int sh_remove_all_mappings(struct vcpu * NULL /* unused */ }; -static unsigned int callback_mask = +static const unsigned int callback_mask =1 << SH_type_l1_32_shadow |1 << SH_type_fl1_32_shadow |1 << SH_type_l1_pae_shadow
@@ -2556,7 +2556,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 */
@@ -2683,7 +2683,7 @@ static int sh_clear_up_pointer(struct vcvoid 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 */
@@ -2701,7 +2701,7 @@ void sh_reset_l3_up_pointers(struct vcpuNULL ,/* p2m */ NULL /* unused */ }; -static unsigned int callback_mask =1 << SH_type_l3_64_shadow; +static 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 wouldn't even need to be static, but keep them so upon the maintainer's request.
---
v2: Retain static-s, upon Tim's request.
xen/arch/x86/mm/shadow/common.c +5 -5
@@ -2162,7 +2162,7 @@ int sh_remove_write_access(struct vcpu * NULL /* unused */ }; -static unsigned int callback_mask = +static const unsigned int callback_mask =1 << SH_type_l1_32_shadow |1 << SH_type_fl1_32_shadow |1 << SH_type_l1_pae_shadow
@@ -2412,7 +2412,7 @@ int sh_remove_all_mappings(struct vcpu * NULL /* unused */ }; -static unsigned int callback_mask = +static const unsigned int callback_mask =1 << SH_type_l1_32_shadow |1 << SH_type_fl1_32_shadow |1 << SH_type_l1_pae_shadow
@@ -2556,7 +2556,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 */
@@ -2683,7 +2683,7 @@ static int sh_clear_up_pointer(struct vcvoid 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 */
@@ -2701,7 +2701,7 @@ void sh_reset_l3_up_pointers(struct vcpuNULL ,/* p2m */ NULL /* unused */ }; -static unsigned int callback_mask =1 << SH_type_l3_64_shadow; +static 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
PATCH 2/3 x86/shadow: adjust mask shadow_audit_tables() passes to hash_foreach()
In reply to Jan BeulichIt so far having been ~1 made most of the code preceding the call pointless, but I assume this wasn't meant to be that way. Also replace the remaining hard coded ~1 with an expression documenting the intention a little better.
---
Couldn't the ~1 instead be SHF_page_type_mask?
xen/arch/x86/mm/shadow/common.c +2 -2
@@ -3761,7 +3761,7 @@ void shadow_audit_tables(struct vcpu *v)#endif if (SHADOW_AUDIT &SHADOW_AUDIT_ENTRIES_FULL ) - mask = ~1 ;/* Audit every table in the system */ + mask = ~(1 << SH_type_none);/* Audit every table in the system */ else {/* Audit only the current mode's tables */
@@ -3776,7 +3776,7 @@ void shadow_audit_tables(struct vcpu *v) } } -hash_foreach (v, ~1 , callbacks,_mfn (INVALID_MFN )); +hash_foreach (v, mask, callbacks,_mfn (INVALID_MFN )); }#endif /* Shadow audit */
x86/shadow: adjust mask shadow_audit_tables() passes to hash_foreach()
It so far having been ~1 made most of the code preceding the call pointless, but I assume this wasn't meant to be that way. Also replace the remaining hard coded ~1 with an expression documenting the intention a little better.
---
Couldn't the ~1 instead be SHF_page_type_mask?
xen/arch/x86/mm/shadow/common.c +2 -2
@@ -3761,7 +3761,7 @@ void shadow_audit_tables(struct vcpu *v)#endif if (SHADOW_AUDIT &SHADOW_AUDIT_ENTRIES_FULL ) - mask = ~1 ;/* Audit every table in the system */ + mask = ~(1 << SH_type_none);/* Audit every table in the system */ else {/* Audit only the current mode's tables */
@@ -3776,7 +3776,7 @@ void shadow_audit_tables(struct vcpu *v) } } -hash_foreach (v, ~1 , callbacks,_mfn (INVALID_MFN )); +hash_foreach (v, mask, callbacks,_mfn (INVALID_MFN )); }#endif /* Shadow audit */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 3/3 x86/shadow: use shorter constants for callback masks
In reply to Jan Beulichprivate.h defining them I can't see why they couldn't be used here to make the code easier to read.
xen/arch/x86/mm/shadow/common.c +19 -21
@@ -2163,12 +2163,12 @@ int sh_remove_write_access(struct vcpu * };static const unsigned int callback_mask = -1 << SH_type_l1_32_shadow - |1 << SH_type_fl1_32_shadow - |1 << SH_type_l1_pae_shadow - |1 << SH_type_fl1_pae_shadow - |1 << SH_type_l1_64_shadow - |1 << SH_type_fl1_64_shadow +SHF_L1_32 + |SHF_FL1_32 + |SHF_L1_PAE + |SHF_FL1_PAE + |SHF_L1_64 + |SHF_FL1_64 ;struct page_info *pg =mfn_to_page (gmfn);
@@ -2413,12 +2413,12 @@ int sh_remove_all_mappings(struct vcpu * };static const unsigned int callback_mask = -1 << SH_type_l1_32_shadow - |1 << SH_type_fl1_32_shadow - |1 << SH_type_l1_pae_shadow - |1 << SH_type_fl1_pae_shadow - |1 << SH_type_l1_64_shadow - |1 << SH_type_fl1_64_shadow +SHF_L1_32 + |SHF_FL1_32 + |SHF_L1_PAE + |SHF_FL1_PAE + |SHF_L1_64 + |SHF_FL1_64 ;perfc_incr (shadow_mappings);
@@ -2558,20 +2558,18 @@ void sh_remove_shadows(struct vcpu *v, m/* Another lookup table, for choosing which mask to use */ static const unsigned int masks[SH_type_unused] = {0 ,/* none */ -1 << SH_type_l2_32_shadow,/* l1_32 */ +SHF_L2_32 ,/* l1_32 */ 0 ,/* fl1_32 */ 0 ,/* l2_32 */ - ((1 << SH_type_l2h_pae_shadow) - | (1 << SH_type_l2_pae_shadow)),/* l1_pae */ +SHF_L2H_PAE |SHF_L2_PAE ,/* l1_pae */ 0 ,/* fl1_pae */ 0 ,/* l2_pae */ 0 ,/* l2h_pae */ - ((1 << SH_type_l2h_64_shadow) - | (1 << SH_type_l2_64_shadow)),/* l1_64 */ +SHF_L2H_64 |SHF_L2_64 ,/* l1_64 */ 0 ,/* fl1_64 */ -1 << SH_type_l3_64_shadow,/* l2_64 */ -1 << SH_type_l3_64_shadow,/* l2h_64 */ -1 << SH_type_l4_64_shadow,/* l3_64 */ +SHF_L3_64 ,/* l2_64 */ +SHF_L3_64 ,/* l2h_64 */ +SHF_L4_64 ,/* l3_64 */ 0 ,/* l4_64 */ 0 ,/* p2m */ 0 /* unused */
@@ -2701,7 +2699,7 @@ void sh_reset_l3_up_pointers(struct vcpuNULL ,/* p2m */ NULL /* unused */ }; -static const unsigned int callback_mask =1 << SH_type_l3_64_shadow; +static const unsigned int callback_mask =SHF_L3_64 ;hash_foreach (v, callback_mask, callbacks,_mfn (INVALID_MFN )); }
x86/shadow: use shorter constants for callback masks
private.h defining them I can't see why they couldn't be used here to make the code easier to read.
xen/arch/x86/mm/shadow/common.c +19 -21
@@ -2163,12 +2163,12 @@ int sh_remove_write_access(struct vcpu * };static const unsigned int callback_mask = -1 << SH_type_l1_32_shadow - |1 << SH_type_fl1_32_shadow - |1 << SH_type_l1_pae_shadow - |1 << SH_type_fl1_pae_shadow - |1 << SH_type_l1_64_shadow - |1 << SH_type_fl1_64_shadow +SHF_L1_32 + |SHF_FL1_32 + |SHF_L1_PAE + |SHF_FL1_PAE + |SHF_L1_64 + |SHF_FL1_64 ;struct page_info *pg =mfn_to_page (gmfn);
@@ -2413,12 +2413,12 @@ int sh_remove_all_mappings(struct vcpu * };static const unsigned int callback_mask = -1 << SH_type_l1_32_shadow - |1 << SH_type_fl1_32_shadow - |1 << SH_type_l1_pae_shadow - |1 << SH_type_fl1_pae_shadow - |1 << SH_type_l1_64_shadow - |1 << SH_type_fl1_64_shadow +SHF_L1_32 + |SHF_FL1_32 + |SHF_L1_PAE + |SHF_FL1_PAE + |SHF_L1_64 + |SHF_FL1_64 ;perfc_incr (shadow_mappings);
@@ -2558,20 +2558,18 @@ void sh_remove_shadows(struct vcpu *v, m/* Another lookup table, for choosing which mask to use */ static const unsigned int masks[SH_type_unused] = {0 ,/* none */ -1 << SH_type_l2_32_shadow,/* l1_32 */ +SHF_L2_32 ,/* l1_32 */ 0 ,/* fl1_32 */ 0 ,/* l2_32 */ - ((1 << SH_type_l2h_pae_shadow) - | (1 << SH_type_l2_pae_shadow)),/* l1_pae */ +SHF_L2H_PAE |SHF_L2_PAE ,/* l1_pae */ 0 ,/* fl1_pae */ 0 ,/* l2_pae */ 0 ,/* l2h_pae */ - ((1 << SH_type_l2h_64_shadow) - | (1 << SH_type_l2_64_shadow)),/* l1_64 */ +SHF_L2H_64 |SHF_L2_64 ,/* l1_64 */ 0 ,/* fl1_64 */ -1 << SH_type_l3_64_shadow,/* l2_64 */ -1 << SH_type_l3_64_shadow,/* l2h_64 */ -1 << SH_type_l4_64_shadow,/* l3_64 */ +SHF_L3_64 ,/* l2_64 */ +SHF_L3_64 ,/* l2h_64 */ +SHF_L4_64 ,/* l3_64 */ 0 ,/* l4_64 */ 0 ,/* p2m */ 0 /* unused */
@@ -2701,7 +2699,7 @@ void sh_reset_l3_up_pointers(struct vcpuNULL ,/* p2m */ NULL /* unused */ }; -static const unsigned int callback_mask =1 << SH_type_l3_64_shadow; +static const unsigned int callback_mask =SHF_L3_64 ;hash_foreach (v, callback_mask, callbacks,_mfn (INVALID_MFN )); }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Tim Deegan
AppliedQuoted 5 lines · Jan Beulich
1: convert non-const statics
2: adjust maskshadow_audit_tables()passes tohash_foreach()3: use shorter constants for callback masksSigned-off-by Jan Beulich <[email protected]>
Applied, thanks. I adjusted the second patch to use SHF_page_type_mask,
as you suggested.
Cheers,
Tim.