[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/3] xen/x86: Avoid undefined behaviour by shifting into a sign bit



Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
---
 xen/arch/x86/apic.c           | 2 +-
 xen/arch/x86/cpu/common.c     | 2 +-
 xen/arch/x86/x86_64/traps.c   | 2 +-
 xen/include/asm-x86/apicdef.h | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/apic.c b/xen/arch/x86/apic.c
index f3727cd..3fb9a82 100644
--- a/xen/arch/x86/apic.c
+++ b/xen/arch/x86/apic.c
@@ -571,7 +571,7 @@ void setup_local_APIC(void)
     for (i = APIC_ISR_NR - 1; i >= 0; i--) {
         value = apic_read(APIC_ISR + i*0x10);
         for (j = 31; j >= 0; j--) {
-            if (value & (1<<j))
+            if (value & (1u << j))
                 ack_APIC_irq();
         }
     }
diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index 2c47589..3336908 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -476,7 +476,7 @@ void detect_extended_topology(struct cpuinfo_x86 *c)
                sub_index++;
        } while ( LEAFB_SUBTYPE(ecx) != INVALID_TYPE );
 
-       core_select_mask = (~(-1 << core_plus_mask_width)) >> ht_mask_width;
+       core_select_mask = (~(-1u << core_plus_mask_width)) >> ht_mask_width;
 
        c->cpu_core_id = phys_pkg_id(initial_apicid, ht_mask_width)
                & core_select_mask;
diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c
index 19f58a1..1b1b61a 100644
--- a/xen/arch/x86/x86_64/traps.c
+++ b/xen/arch/x86/x86_64/traps.c
@@ -414,7 +414,7 @@ void subarch_percpu_traps_init(void)
     unmap_domain_page(stub_page);
 
     /* Common SYSCALL parameters. */
-    wrmsr(MSR_STAR, 0, (FLAT_RING3_CS32<<16) | __HYPERVISOR_CS);
+    wrmsr(MSR_STAR, 0, ((unsigned)FLAT_RING3_CS32 << 16) | __HYPERVISOR_CS);
     wrmsr(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK, 0U);
 }
 
diff --git a/xen/include/asm-x86/apicdef.h b/xen/include/asm-x86/apicdef.h
index 8752287..da7f4d3 100644
--- a/xen/include/asm-x86/apicdef.h
+++ b/xen/include/asm-x86/apicdef.h
@@ -30,7 +30,7 @@
 #define                        APIC_EIO_ACK            0x0             /* 
Write this to the EOI register */
 #define                APIC_RRR        0xC0
 #define                APIC_LDR        0xD0
-#define                        APIC_LDR_MASK           (0xFF<<24)
+#define                        APIC_LDR_MASK           (0xFFu<<24)
 #define                        GET_xAPIC_LOGICAL_ID(x) (((x)>>24)&0xFF)
 #define                        SET_xAPIC_LOGICAL_ID(x) (((x)<<24))
 #define                        APIC_ALL_CPUS           0xFF
-- 
2.1.4


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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.