Skip to contentSkip to conversation

Bug in drivers/kvm/vmx.c inject_rmode_irq()?

DISCUSSION Applied Eric Sesterhenn / Snakebyte 2 participants 2 messages Apr 9, 2007 – Apr 10, 2007 3 messages not in the archive KVM

lore
Share & tools
lore
#3 lore raw
In reply to a message not in the archive
Quoted 18 lines · * Avi Kivity (avi-atKUWr5tajBWk0Htik3J/[email protected]) wrote:
Quoted 8 lines · Eric Sesterhenn / Snakebyte

i was testing the gcc 4.3 against the latest git kernel, and got a warning in your code (using -Wstrict-overflow=1)

drivers/kvm/vmx.c: In function 'inject_rmode_irq':
drivers/kvm/vmx.c:1193: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false

Quoted 9 lines

The problem is basically that gcc 4.3 handles integer overflows different, when using -O2 and -Os, the code triggering this is the following:

if (sp > ss_limit || sp - 6 > sp) {

I am not completely sure, but wouldnt a check for
( sp > ss_limit || sp > 6 ) be enough?

Quoted 9 lines

hmm. sp is declared as u16, which is unsigned. I don't see how gcc can promote it to a signed type, unless I'm misremembering C's promotion rules.

Anyway, it could just be coded as

   if (sp > ss_limit || sp < 6)

and achieve the same effect.

Since 4.2 gcc might decide that overflows can never occur, and optimize away this check, see http://gcc.gnu.org/gcc-4.2/changes.html
Lets make sure we still check this.

drivers/kvm/vmx.c renamed from drivers/kvm/vmx.c.orig +1 -1
@@ -1190,7 +1190,7 @@ static void inject_rmode_irq(struct kvm_
 	u16 sp =  vmcs_readl(GUEST_RSP);
 	u32 ss_limit = vmcs_read32(GUEST_SS_LIMIT);
 
-	if (sp > ss_limit || sp - 6 > sp) {
+	if (sp > ss_limit || sp < 6 ) {
 		vcpu_printf(vcpu, "%s: #SS, rsp 0x%lx ss 0x%lx limit 0x%x\n",
 			    __FUNCTION__,
 			    vmcs_readl(GUEST_RSP),

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Applied
#4 lore raw
Quoted 32 lines · Eric Sesterhenn / Snakebyte
Quoted 19 lines · * Avi Kivity (avi-atKUWr5tajBWk0Htik3J/[email protected]) wrote:
Quoted 7 lines · Eric Sesterhenn / Snakebyte

i was testing the gcc 4.3 against the latest git kernel, and got a warning in your code (using -Wstrict-overflow=1)

drivers/kvm/vmx.c: In function 'inject_rmode_irq':
drivers/kvm/vmx.c:1193: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false

Quoted 10 lines

The problem is basically that gcc 4.3 handles integer overflows different, when using -O2 and -Os, the code triggering this is the following:

if (sp > ss_limit || sp - 6 > sp) {

I am not completely sure, but wouldnt a check for
( sp > ss_limit || sp > 6 ) be enough?

Quoted 10 lines

hmm. sp is declared as u16, which is unsigned. I don't see how gcc can promote it to a signed type, unless I'm misremembering C's promotion rules.

Anyway, it could just be coded as

   if (sp > ss_limit || sp < 6)

and achieve the same effect.

Quoted 6 lines

Since 4.2 gcc might decide that overflows can never occur, and optimize away this check, see http://gcc.gnu.org/gcc-4.2/changes.html
Lets make sure we still check this.

Applied, thanks.

Signature · 8 lines
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV