All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Valdis Kletnieks <Valdis.Kletnieks@vt.edu>,
	Gleb Natapov <gleb@kernel.org>,
	x86@kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Aruna Hewapathirane <aruna.hewapathirane@gmail.com>
Subject: Re: Silence compiler warning in arch/x86/kvm/emulate.c
Date: Fri, 19 Feb 2016 13:05:10 +0100	[thread overview]
Message-ID: <56C704F6.5000604@redhat.com> (raw)
In-Reply-To: <20160219111139.GA22041@aurel32.net>



On 19/02/2016 12:11, Aurelien Jarno wrote:
> On 2015-08-29 17:49, Valdis Kletnieks wrote:
>> Compiler warning:
>>
>>  CC [M]  arch/x86/kvm/emulate.o
>> arch/x86/kvm/emulate.c: In function "__do_insn_fetch_bytes":
>> arch/x86/kvm/emulate.c:814:9: warning: "linear" may be used uninitialized in this function [-Wmaybe-uninitialized]
>>
>> GCC is smart enough to realize that the inlined __linearize may return before
>> setting the value of linear, but not smart enough to realize the same
>> X86EMU_CONTINUE blocks actual use of the value.  However, the value of
>> 'linear' can only be set to one value, so hoisting the one line of code
>> upwards makes GCC happy with the code.
>>
>> Reported-by: Aruna Hewapathirane <aruna.hewapathirane@gmail.com>
>> Tested-by: Aruna Hewapathirane <aruna.hewapathirane@gmail.com>
>> Signed-off-by: Valdis Kletnieks <valdis.kletnieks@vt.edu>
>>
>> --- a/arch/x86/kvm/emulate.c.dist	2015-08-11 14:10:05.366061993 -0400
>> +++ b/arch/x86/kvm/emulate.c	2015-08-29 13:43:13.014163958 -0400
>> @@ -650,6 +650,7 @@ static __always_inline int __linearize(s
>>  	u16 sel;
>>  
>>  	la = seg_base(ctxt, addr.seg) + addr.ea;
>> +	*linear = la;
>>  	*max_size = 0;
>>  	switch (mode) {
>>  	case X86EMUL_MODE_PROT64:
>> @@ -693,7 +694,6 @@ static __always_inline int __linearize(s
>>  	}
>>  	if (insn_aligned(ctxt, size) && ((la & (size - 1)) != 0))
>>  		return emulate_gp(ctxt, 0);
>> -	*linear = la;
>>  	return X86EMUL_CONTINUE;
>>  bad:
>>  	if (addr.seg == VCPU_SREG_SS)
>>
> 
> Unfortunately this patch broke GNU/Hurd when running under KVM. It fails
> to boot almost immediately. I haven't debug it more, but it looks like
> *linear should not always be written. This can easily be reproduced by
> trying to boot Debian Installer from this ISO:
> 
> http://ftp.debian-ports.org/debian-cd/hurd-i386/debian-hurd-2015/debian-hurd-2015-i386-CD-1.iso

The bug is that la can be changed by the "la &= (u32)-1" line.

So the fix could be like:

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 1505587d06e9..b9b09fec173b 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -650,10 +650,10 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
 	u16 sel;
 
 	la = seg_base(ctxt, addr.seg) + addr.ea;
-	*linear = la;
 	*max_size = 0;
 	switch (mode) {
 	case X86EMUL_MODE_PROT64:
+		*linear = la;
 		if (is_noncanonical_address(la))
 			goto bad;
 
@@ -662,6 +662,7 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
 			goto bad;
 		break;
 	default:
+		*linear = la = (u32)la;
 		usable = ctxt->ops->get_segment(ctxt, &sel, &desc, NULL,
 						addr.seg);
 		if (!usable)
@@ -689,7 +690,6 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
 			if (size > *max_size)
 				goto bad;
 		}
-		la &= (u32)-1;
 		break;
 	}
 	if (insn_aligned(ctxt, size) && ((la & (size - 1)) != 0))


Can you test it?

Paolo

  reply	other threads:[~2016-02-19 12:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-29 21:49 Silence compiler warning in arch/x86/kvm/emulate.c Valdis Kletnieks
2016-02-19 11:11 ` Aurelien Jarno
2016-02-19 12:05   ` Paolo Bonzini [this message]
2016-02-19 17:04     ` Aurelien Jarno
2016-02-19 16:45   ` Aurelien Jarno
2016-02-19 17:54     ` Valdis.Kletnieks
2016-02-19 17:56       ` Paolo Bonzini
2016-02-20  0:33         ` Valdis.Kletnieks

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=56C704F6.5000604@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=aruna.hewapathirane@gmail.com \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.