Skip to contentSkip to conversation

x86/shadow: fix DO_UNSHADOW()

PATCH In review Jan Beulich 3 participants 3 messages May 19, 2021 – May 24, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/shadow: fix DO_UNSHADOW()

When adding the HASH_CALLBACKS_CHECK() I failed to properly recognize the (somewhat unusually formatted) if() around the call to hash_domain_foreach()). Gcc 11 is absolutely right in pointing out the apparently misleading indentation. Besides adding the missing braces, also adjust the two oddly formatted if()-s in the macro.

Fixes 90629587e16e ("x86/shadow: replace stale literal numbers in hash_{vcpu,domain}_foreach()")

---
I'm puzzled as to why this bug didn't cause any fallout.

xen/arch/x86/mm/shadow/common.c +7 -5
@@ -2220,8 +2220,8 @@ void sh_remove_shadows(struct domain *d,
      */
 #define DO_UNSHADOW(_type) do {                                         \
     t = (_type);                                                        \
-    if( !(pg->count_info & PGC_page_table)                              \
-        || !(pg->shadow_flags & (1 << t)) )                             \
+    if ( !(pg->count_info & PGC_page_table) ||                          \
+         !(pg->shadow_flags & (1 << t)) )                               \
         break;                                                          \
     smfn = shadow_hash_lookup(d, mfn_x(gmfn), t);                       \
     if ( unlikely(!mfn_valid(smfn)) )                                   \
@@ -2235,11 +2235,13 @@ void sh_remove_shadows(struct domain *d,
         sh_unpin(d, smfn);                                              \
     else if ( sh_type_has_up_pointer(d, t) )                            \
         sh_remove_shadow_via_pointer(d, smfn);                          \
-    if( !fast                                                           \
-        && (pg->count_info & PGC_page_table)                            \
-        && (pg->shadow_flags & (1 << t)) )                              \
+    if ( !fast &&                                                       \
+         (pg->count_info & PGC_page_table) &&                           \
+         (pg->shadow_flags & (1 << t)) )                                \
+    {                                                                   \
         HASH_CALLBACKS_CHECK(SHF_page_type_mask);                       \
         hash_domain_foreach(d, masks[t], callbacks, smfn);              \
+    }                                                                   \
 } while (0)
 
     DO_UNSHADOW(SH_type_l2_32_shadow);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Jan Beulich

When adding the HASH_CALLBACKS_CHECK() I failed to properly recognize the (somewhat unusually formatted) if() around the call to hash_domain_foreach()). Gcc 11 is absolutely right in pointing out the apparently misleading indentation. Besides adding the missing braces, also adjust the two oddly formatted if()-s in the macro.

Fixes 90629587e16e ("x86/shadow: replace stale literal numbers in hash_{vcpu,domain}_foreach()")

Cheers,
Luca

Quoted 34 lines

---
I'm puzzled as to why this bug didn't cause any fallout.

xen/arch/x86/mm/shadow/common.c +7 -5
@@ -2220,8 +2220,8 @@ void sh_remove_shadows(struct domain *d,
     */
 #define DO_UNSHADOW(_type) do {                                         \
    t = (_type);                                                        \
-    if( !(pg->count_info & PGC_page_table)                              \
-        || !(pg->shadow_flags & (1 << t)) )                             \
+    if ( !(pg->count_info & PGC_page_table) ||                          \
+         !(pg->shadow_flags & (1 << t)) )                               \
        break;                                                          \
    smfn = shadow_hash_lookup(d, mfn_x(gmfn), t);                       \
    if ( unlikely(!mfn_valid(smfn)) )                                   \
@@ -2235,11 +2235,13 @@ void sh_remove_shadows(struct domain *d,
        sh_unpin(d, smfn);                                              \
    else if ( sh_type_has_up_pointer(d, t) )                            \
        sh_remove_shadow_via_pointer(d, smfn);                          \
-    if( !fast                                                           \
-        && (pg->count_info & PGC_page_table)                            \
-        && (pg->shadow_flags & (1 << t)) )                              \
+    if ( !fast &&                                                       \
+         (pg->count_info & PGC_page_table) &&                           \
+         (pg->shadow_flags & (1 << t)) )                                \
+    {                                                                   \
        HASH_CALLBACKS_CHECK(SHF_page_type_mask);                       \
        hash_domain_foreach(d, masks[t], callbacks, smfn);              \
+    }                                                                   \
 } while (0)
 
    DO_UNSHADOW(SH_type_l2_32_shadow);
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jan Beulich
Quoted 8 lines · Jan Beulich

When adding the HASH_CALLBACKS_CHECK() I failed to properly recognize the (somewhat unusually formatted) if() around the call to hash_domain_foreach()). Gcc 11 is absolutely right in pointing out the apparently misleading indentation. Besides adding the missing braces, also adjust the two oddly formatted if()-s in the macro.

Fixes 90629587e16e ("x86/shadow: replace stale literal numbers in hash_{vcpu,domain}_foreach()")