* [BUG ?] MIPS: KVM: condition with no effect
@ 2015-05-05 12:34 Nicholas Mc Guire
2015-05-05 21:42 ` James Hogan
0 siblings, 1 reply; 3+ messages in thread
From: Nicholas Mc Guire @ 2015-05-05 12:34 UTC (permalink / raw)
To: Gleb Natapov; +Cc: Paolo Bonzini, Ralf Baechle, kvm, linux-mips, linux-kernel
Hi !
Not sure if this is a bug or maybe a placeholder for
something... so patch - but maybe someone that knows this code can
give it a look.
arch/mips/kvm/emulate.c:emulation_result kvm_mips_complete_mmio_load()
<snip>
2414 case 2:
2415 if (vcpu->mmio_needed == 2)
2416 *gpr = *(int16_t *) run->mmio.data;
2417 else
2418 *gpr = *(int16_t *) run->mmio.data;
2419
2420 break;
<snip>
either the if/else is not needed or one of the branches is wrong
or it is a place-holder for somethign that did not get
done - in which case a few lines explaining this would be
nice (e.g. like in arch/sh/kernel/traps_64.c line 59)
line numbers refer to 4.1-rc2
thx!
hofrat
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG ?] MIPS: KVM: condition with no effect
2015-05-05 12:34 [BUG ?] MIPS: KVM: condition with no effect Nicholas Mc Guire
@ 2015-05-05 21:42 ` James Hogan
2015-05-07 12:18 ` Nicholas Mc Guire
0 siblings, 1 reply; 3+ messages in thread
From: James Hogan @ 2015-05-05 21:42 UTC (permalink / raw)
To: Nicholas Mc Guire
Cc: Gleb Natapov, Paolo Bonzini, Ralf Baechle, kvm, linux-mips,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1417 bytes --]
Hi,
On Tue, May 05, 2015 at 02:34:38PM +0200, Nicholas Mc Guire wrote:
>
> Hi !
>
> Not sure if this is a bug or maybe a placeholder for
> something... so patch - but maybe someone that knows this code can
> give it a look.
>
> arch/mips/kvm/emulate.c:emulation_result kvm_mips_complete_mmio_load()
> <snip>
> 2414 case 2:
> 2415 if (vcpu->mmio_needed == 2)
> 2416 *gpr = *(int16_t *) run->mmio.data;
> 2417 else
> 2418 *gpr = *(int16_t *) run->mmio.data;
> 2419
> 2420 break;
> <snip>
>
> either the if/else is not needed or one of the branches is wrong
> or it is a place-holder for somethign that did not get
> done - in which case a few lines explaining this would be
> nice (e.g. like in arch/sh/kernel/traps_64.c line 59)
>
> line numbers refer to 4.1-rc2
mmio_needed encodes whether the MMIO load is a signed (2) or unsigned
(1) load. E.g. the len == 1 case just below casts the pointer to u8 vs
int8_t to control sign extension. So it appears the else branch (line
2418 in your quote) should be uint16_t (or u16) to prevent the MMIO
value loaded by a lhu (load halfword unsigned) being sign extended to
the full width of the registers. Nice catch!
Feel free to send a patch to fix. Otherwise I'm happy to do it.
Thanks!
James
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG ?] MIPS: KVM: condition with no effect
2015-05-05 21:42 ` James Hogan
@ 2015-05-07 12:18 ` Nicholas Mc Guire
0 siblings, 0 replies; 3+ messages in thread
From: Nicholas Mc Guire @ 2015-05-07 12:18 UTC (permalink / raw)
To: James Hogan
Cc: Gleb Natapov, Paolo Bonzini, Ralf Baechle, kvm, linux-mips,
linux-kernel
On Tue, 05 May 2015, James Hogan wrote:
> Hi,
>
> On Tue, May 05, 2015 at 02:34:38PM +0200, Nicholas Mc Guire wrote:
> >
> > Hi !
> >
> > Not sure if this is a bug or maybe a placeholder for
> > something... so patch - but maybe someone that knows this code can
> > give it a look.
> >
> > arch/mips/kvm/emulate.c:emulation_result kvm_mips_complete_mmio_load()
> > <snip>
> > 2414 case 2:
> > 2415 if (vcpu->mmio_needed == 2)
> > 2416 *gpr = *(int16_t *) run->mmio.data;
> > 2417 else
> > 2418 *gpr = *(int16_t *) run->mmio.data;
> > 2419
> > 2420 break;
> > <snip>
> >
> > either the if/else is not needed or one of the branches is wrong
> > or it is a place-holder for somethign that did not get
> > done - in which case a few lines explaining this would be
> > nice (e.g. like in arch/sh/kernel/traps_64.c line 59)
> >
> > line numbers refer to 4.1-rc2
>
> mmio_needed encodes whether the MMIO load is a signed (2) or unsigned
> (1) load. E.g. the len == 1 case just below casts the pointer to u8 vs
> int8_t to control sign extension. So it appears the else branch (line
> 2418 in your quote) should be uint16_t (or u16) to prevent the MMIO
> value loaded by a lhu (load halfword unsigned) being sign extended to
> the full width of the registers. Nice catch!
>
thanks for the clarification - will send the patch out shortly.
This was found by a trivial coccinelle scanner
<snip>
virtual context
virtual org
virtual report
@cond@
position p;
statement S1;
@@
<+...
* if@p (...) S1 else S1
...+>
@script:python@
p << cond.p;
@@
print "%s:%s WARNING: condition with no effect (if branch == else)" % (p[0].file,p[0].line)
<snip>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-07 12:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-05 12:34 [BUG ?] MIPS: KVM: condition with no effect Nicholas Mc Guire
2015-05-05 21:42 ` James Hogan
2015-05-07 12:18 ` Nicholas Mc Guire
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox