Skip to contentSkip to conversation

x86: Address "Bitwise-and with zero CONSTANT_EXPRESSION_RESULT" Coverity issues

PATCH In review Andrew Cooper 2 participants 2 messages Jun 27, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Address "Bitwise-and with zero CONSTANT_EXPRESSION_RESULT" Coverity issues

Coverity complains at code which which performs a bitwise and with a constant that happens to be zero. Both _PAGE_GNTTAB and PG_SH_enable may be 0 depending on Kconfig settings.

Rearrange the C to test the constant first and short circuit the bitwise and.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>

---
 xen/arch/x86/mm.c            | 2 +-
 xen/include/asm-x86/paging.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/mm.c +1 -1
index 2b74392..8d1120a 100644
@@ -1225,7 +1225,7 @@ void put_page_from_l1e(l1_pgentry_t l1e, struct domain *l1e_owner)
      * (Note that the undestroyable active grants are not a security hole in
      * Xen. All active grants can safely be cleaned up when the domain dies.)
      */
-    if ( (l1e_get_flags(l1e) & _PAGE_GNTTAB) &&
+    if ( _PAGE_GNTTAB && (l1e_get_flags(l1e) & _PAGE_GNTTAB) &&
          !l1e_owner->is_shutting_down && !l1e_owner->is_dying )
     {
         gdprintk(XENLOG_WARNING,
xen/include/asm-x86/paging.h +2 -1
index f008551..f0b6705 100644
@@ -61,7 +61,8 @@
 #define PG_MASK (PG_refcounts | PG_log_dirty | PG_translate | PG_external)
 
 #define paging_mode_enabled(_d)   (!!(_d)->arch.paging.mode)
-#define paging_mode_shadow(_d)    (!!((_d)->arch.paging.mode & PG_SH_enable))
+#define paging_mode_shadow(_d)    (PG_SH_enable && \
+                                   !!((_d)->arch.paging.mode & PG_SH_enable))
 #define paging_mode_hap(_d)       (!!((_d)->arch.paging.mode & PG_HAP_enable))
 
 #define paging_mode_refcounts(_d) (!!((_d)->arch.paging.mode & PG_refcounts))
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 27.06.18 at 14:27, <[email protected]> wrote:

Coverity complains at code which which performs a bitwise and with a constant that happens to be zero. Both _PAGE_GNTTAB and PG_SH_enable may be 0 depending on Kconfig settings.

Rearrange the C to test the constant first and short circuit the bitwise and.

Hmm, well, this makes the code look quite, ehem, interesting. Normally such would seem a prime candidate for cleaning up, especially without any comment attached. But anyway, if it helps ...

Quoted 3 lines

No functional change.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel