From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH] xen/x86: Avoid undefined behaviour by shifting into a sign bit
Date: Tue, 9 Aug 2016 13:48:03 +0100 [thread overview]
Message-ID: <1470746884-27118-2-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1470746884-27118-1-git-send-email-andrew.cooper3@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
v2:
* Use ~0u as opposed to -1u
---
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..577a01f 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 = (~(~0u << 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..2d8ecf5 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 int)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@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-08-09 12:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-05 13:50 [PATCH 1/3] xen/common: Avoid undefined behaviour by shifting into a sign bit Andrew Cooper
2016-08-05 13:50 ` [PATCH 2/3] xen/x86: " Andrew Cooper
2016-08-05 14:06 ` Jan Beulich
2016-08-05 13:50 ` [PATCH 3/3] x86/microcode: Avoid undefined behaviour from signed integer overflow Andrew Cooper
2016-08-05 14:09 ` Jan Beulich
2016-08-11 8:42 ` Tian, Kevin
2016-08-05 14:04 ` [PATCH 1/3] xen/common: Avoid undefined behaviour by shifting into a sign bit Jan Beulich
2016-08-05 14:07 ` George Dunlap
2016-08-09 12:48 ` [PATCH] " Andrew Cooper
2016-08-09 12:48 ` Andrew Cooper [this message]
2016-08-09 12:48 ` [PATCH] x86/microcode: Avoid undefined behaviour from signed integer overflow Andrew Cooper
2016-08-09 14:00 ` [PATCH] xen/common: Avoid undefined behaviour by shifting into a sign bit Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470746884-27118-2-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).