All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
@ 2007-05-06 18:45 John Reiser
  2007-05-06 20:04 ` Thiemo Seufer
  0 siblings, 1 reply; 11+ messages in thread
From: John Reiser @ 2007-05-06 18:45 UTC (permalink / raw)
  To: qemu-devel

Hi,

qemu-0.9.0 compiled and running on Debian 2.6.18-4-amd64,
[compiled by gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)],
emulating Debian 2.6.18-4-qemu mipsel (32-bit MIPS R3000 little endian),
errs when gdb 6.4.90-debian (running on the emulated mipsel)
single-steps the user-mode instruction:
	lw      a2,-44(s7)
After single-stepping the 'lw', then register a2 contains garbage
instead of the memory contents at address -44(s7).
This is reproducible every time (and the bad value is the same.)
Also, executing the 'lw' by some means other than single stepping
(such as by setting a breakpoint _beyond_ the 'lw' and continuing)
apparently works correctly.

Here is the gdb console log:
-----
0x001060e4 in ?? ()
0x1060e4:       lw      a2,-44(s7)
(gdb) p $a2
$3 = 0x0
(gdb) x/x $s7-44
0x105458:       0x00120000
(gdb) g   # step one instruction and show next instruction
warning: GDB can't find the start of the function at 0x1060e8.
warning: GDB can't find the start of the function at 0x1060e8.
0x001060e8 in ?? ()
0x1060e8:       addiu   sp,sp,-32
(gdb) p $a2
$4 = 0x5000d
-----
where 'g' is a single-step macro for gdb:
   define g
   stepi
   x/i $pc
   end

I have posted the user-mode executable (28KB) at
    http://bitwagon.com/ftp/date.qemu-0.9.0.bug
The complete gdb session is eight (8) instructions:
-----
(gdb) set output-radix 16
(gdb) run
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00105478 in ?? ()   # the entry point
(gdb) x/i $pc
0x105478:       break
(gdb) set $pc+=4   # skip over the 'break' at entry
(gdb) x/i $pc
0x10547c:       bal     0x10617c    # use 'g' or 'stepi' 5 times
0x105480:         addiu   s7,ra,0   # delay slot; executed but not stopped
0x10617c:       lw      s5,-48(s7)  # this 'lw' executes correctly
0x106180:       bal     0x1060e0
0x106184:         move    s6,ra   # delay slot
0x1060e0:       addiu   s5,s5,-92
0x1060e4:       lw      a2,-44(s7)  # bug: register a2 gets bad value
0x1060e8:       addiu   sp,sp,-32
(gdb) p $a2
$1 = 0x5000d   # (Even after allowing for 1-cycle load delay.)
(gdb) x/x $s7-44
0x105458:       0x00120000   # value that should be in register a2, but is not
-----

The emulated Debian system was installed using the directions at
   http://www.aurel32.net/info/debian_mips_qemu.php
and the actual installed kernel and initrd was:
   http://people.debian.org/~ths/d-i/mipsel/images/20070503-02:00/qemu/netboot/initrd.gz
   http://people.debian.org/~ths/d-i/mipsel/images/20070503-02:00/qemu/netboot/vmlinux-2.6.18-4-qemu
After installation, then the emulation is invoked by:
   qemu-system-mipsel -kernel vmlinux-2.6.18-4-qemu -initrd initrd.gz \
        -hda hda.img -append "root=/dev/hda1 console=ttyS0" -nographic \
        -net nic -net tap
The gdb transcript was copy+paste from an xterm running ssh into the
emulated system.  ["apt-get install ssh" on the emulated system.]

Please suggest how to find and fix this bug?
(It's hard to remember to avoid single-stepping 'lw'.)

-- 
John Reiser, jreiser@BitWagon.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-06 18:45 [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64 John Reiser
@ 2007-05-06 20:04 ` Thiemo Seufer
  2007-05-06 20:07   ` Thiemo Seufer
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Thiemo Seufer @ 2007-05-06 20:04 UTC (permalink / raw)
  To: John Reiser; +Cc: qemu-devel

John Reiser wrote:
> Hi,
> 
> qemu-0.9.0 compiled and running on Debian 2.6.18-4-amd64,
> [compiled by gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)],
> emulating Debian 2.6.18-4-qemu mipsel (32-bit MIPS R3000 little endian),
> errs when gdb 6.4.90-debian (running on the emulated mipsel)
> single-steps the user-mode instruction:
> 	lw      a2,-44(s7)
> After single-stepping the 'lw', then register a2 contains garbage
> instead of the memory contents at address -44(s7).

This looks like another instance of "Qemu/MIPS doesn't handle
self-modifying code correctly" (the break instructions inserted
by gdb are exactly this).

A gross workaround is
http://lists.nongnu.org/archive/html/qemu-devel/2007-05/msg00037.html


Thiemo

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-06 20:04 ` Thiemo Seufer
@ 2007-05-06 20:07   ` Thiemo Seufer
  2007-05-07 12:13   ` Daniel Jacobowitz
  2007-05-08 23:50   ` John Reiser
  2 siblings, 0 replies; 11+ messages in thread
From: Thiemo Seufer @ 2007-05-06 20:07 UTC (permalink / raw)
  To: John Reiser; +Cc: qemu-devel

ths wrote:
> John Reiser wrote:
> > Hi,
> > 
> > qemu-0.9.0 compiled and running on Debian 2.6.18-4-amd64,
> > [compiled by gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)],
> > emulating Debian 2.6.18-4-qemu mipsel (32-bit MIPS R3000 little endian),
> > errs when gdb 6.4.90-debian (running on the emulated mipsel)
> > single-steps the user-mode instruction:
> > 	lw      a2,-44(s7)
> > After single-stepping the 'lw', then register a2 contains garbage
> > instead of the memory contents at address -44(s7).
> 
> This looks like another instance of "Qemu/MIPS doesn't handle
> self-modifying code correctly" (the break instructions inserted
> by gdb are exactly this).
> 
> A gross workaround is
> http://lists.nongnu.org/archive/html/qemu-devel/2007-05/msg00037.html

That is, that's a workaround for another instance of the problem.


Thiemo

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-06 20:04 ` Thiemo Seufer
  2007-05-06 20:07   ` Thiemo Seufer
@ 2007-05-07 12:13   ` Daniel Jacobowitz
  2007-05-07 15:46     ` Paul Brook
                       ` (2 more replies)
  2007-05-08 23:50   ` John Reiser
  2 siblings, 3 replies; 11+ messages in thread
From: Daniel Jacobowitz @ 2007-05-07 12:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: John Reiser

On Sun, May 06, 2007 at 09:04:52PM +0100, Thiemo Seufer wrote:
> This looks like another instance of "Qemu/MIPS doesn't handle
> self-modifying code correctly" (the break instructions inserted
> by gdb are exactly this).
> 
> A gross workaround is
> http://lists.nongnu.org/archive/html/qemu-devel/2007-05/msg00037.html

Someone might want to try:
  http://lists.nongnu.org/archive/html/qemu-devel/2007-04/msg00514.html

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-07 12:13   ` Daniel Jacobowitz
@ 2007-05-07 15:46     ` Paul Brook
  2007-05-07 22:46     ` [Qemu-devel] workaround: " John Reiser
  2007-05-08 18:03     ` [Qemu-devel] bug: " Stefan Weil
  2 siblings, 0 replies; 11+ messages in thread
From: Paul Brook @ 2007-05-07 15:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: John Reiser

On Monday 07 May 2007, Daniel Jacobowitz wrote:
> On Sun, May 06, 2007 at 09:04:52PM +0100, Thiemo Seufer wrote:
> > This looks like another instance of "Qemu/MIPS doesn't handle
> > self-modifying code correctly" (the break instructions inserted
> > by gdb are exactly this).
> >
> > A gross workaround is
> > http://lists.nongnu.org/archive/html/qemu-devel/2007-05/msg00037.html
>
> Someone might want to try:
>   http://lists.nongnu.org/archive/html/qemu-devel/2007-04/msg00514.html

I think breakpoints and FPU are separate bugs.

I notice that the FPU enable bit (CP0C1_FP) is not included in the TB flags. 
My guess is you need to modify exec.c:tb_find_fast to include this.

Paul

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] workaround: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-07 12:13   ` Daniel Jacobowitz
  2007-05-07 15:46     ` Paul Brook
@ 2007-05-07 22:46     ` John Reiser
  2007-05-07 23:03       ` Paul Brook
  2007-05-08 18:03     ` [Qemu-devel] bug: " Stefan Weil
  2 siblings, 1 reply; 11+ messages in thread
From: John Reiser @ 2007-05-07 22:46 UTC (permalink / raw)
  To: qemu-devel

Daniel Jacobowitz wrote:
> On Sun, May 06, 2007 at 09:04:52PM +0100, Thiemo Seufer wrote:
> 
>>This looks like another instance of "Qemu/MIPS doesn't handle
>>self-modifying code correctly" (the break instructions inserted
>>by gdb are exactly this).
>>
>>A gross workaround is
>>http://lists.nongnu.org/archive/html/qemu-devel/2007-05/msg00037.html
> 
> 
> Someone might want to try:
>   http://lists.nongnu.org/archive/html/qemu-devel/2007-04/msg00514.html
> 

This works for me so far: I can single-step reliably in gdb.

--- a/qemu-0.9.0/target-mips/helper.c   2007-05-05 15:39:21.000000000 -0700
+++ b/qemu-0.9.0/target-mips/helper.c   2007-05-07 13:24:50.000000000 -0700
@@ -358,6 +358,7 @@
         goto set_EPC;
     case EXCP_BREAK:
         cause = 9;
+       tlb_flush_page(env, env->PC);
         goto set_EPC;
     case EXCP_RI:
         cause = 10;


-- 
John Reiser, jreiser@BitWagon.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] workaround: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-07 22:46     ` [Qemu-devel] workaround: " John Reiser
@ 2007-05-07 23:03       ` Paul Brook
  2007-05-07 23:08         ` Paul Brook
  0 siblings, 1 reply; 11+ messages in thread
From: Paul Brook @ 2007-05-07 23:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: John Reiser

On Monday 07 May 2007, John Reiser wrote:
> Daniel Jacobowitz wrote:
> > On Sun, May 06, 2007 at 09:04:52PM +0100, Thiemo Seufer wrote:
> >>This looks like another instance of "Qemu/MIPS doesn't handle
> >>self-modifying code correctly" (the break instructions inserted
> >>by gdb are exactly this).
> >>
> >>A gross workaround is
> >>http://lists.nongnu.org/archive/html/qemu-devel/2007-05/msg00037.html
> >
> > Someone might want to try:
> >   http://lists.nongnu.org/archive/html/qemu-devel/2007-04/msg00514.html
>
> This works for me so far: I can single-step reliably in gdb.
>
> --- a/qemu-0.9.0/target-mips/helper.c   2007-05-05 15:39:21.000000000 -0700
> +++ b/qemu-0.9.0/target-mips/helper.c   2007-05-07 13:24:50.000000000 -0700
> @@ -358,6 +358,7 @@
>          goto set_EPC;
>      case EXCP_BREAK:
>          cause = 9;
> +       tlb_flush_page(env, env->PC);
>          goto set_EPC;
>      case EXCP_RI:
>          cause = 10;

I think this is still broken if the breakpoint is the first instruction on a 
page. The changes Daniel mentioned should make this sort of flushing 
unnecessary.

Paul

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] workaround: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-07 23:03       ` Paul Brook
@ 2007-05-07 23:08         ` Paul Brook
  0 siblings, 0 replies; 11+ messages in thread
From: Paul Brook @ 2007-05-07 23:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: John Reiser

> > --- a/qemu-0.9.0/target-mips/helper.c   2007-05-05 15:39:21.000000000
> > -0700 +++ b/qemu-0.9.0/target-mips/helper.c   2007-05-07
> > 13:24:50.000000000 -0700 @@ -358,6 +358,7 @@
> >          goto set_EPC;
> >      case EXCP_BREAK:
> >          cause = 9;
> > +       tlb_flush_page(env, env->PC);
> >          goto set_EPC;
> >      case EXCP_RI:
> >          cause = 10;
>
> I think this is still broken if the breakpoint is the first instruction on
> a page. The changes Daniel mentioned should make this sort of flushing
> unnecessary.

On second thoughts it probably does work, but I think it is the wrong way to 
fix this problem.

Paul

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-07 12:13   ` Daniel Jacobowitz
  2007-05-07 15:46     ` Paul Brook
  2007-05-07 22:46     ` [Qemu-devel] workaround: " John Reiser
@ 2007-05-08 18:03     ` Stefan Weil
  2 siblings, 0 replies; 11+ messages in thread
From: Stefan Weil @ 2007-05-08 18:03 UTC (permalink / raw)
  To: qemu-devel

This won't help for the problems with MIPS FPU emulation, will it?

Both breakpoints and the FPU emulation in the Linux kernel use
self-modifying code, so there should be a general solution for
both (and more related) problems.

As long as this general solution is missing, the published code
patches help.

Stefan


Daniel Jacobowitz schrieb:
> On Sun, May 06, 2007 at 09:04:52PM +0100, Thiemo Seufer wrote:
>> This looks like another instance of "Qemu/MIPS doesn't handle
>> self-modifying code correctly" (the break instructions inserted
>> by gdb are exactly this).
>>
>> A gross workaround is
>> http://lists.nongnu.org/archive/html/qemu-devel/2007-05/msg00037.html
>
> Someone might want to try:
> http://lists.nongnu.org/archive/html/qemu-devel/2007-04/msg00514.html

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-06 20:04 ` Thiemo Seufer
  2007-05-06 20:07   ` Thiemo Seufer
  2007-05-07 12:13   ` Daniel Jacobowitz
@ 2007-05-08 23:50   ` John Reiser
  2007-05-09  1:04     ` Thiemo Seufer
  2 siblings, 1 reply; 11+ messages in thread
From: John Reiser @ 2007-05-08 23:50 UTC (permalink / raw)
  To: qemu-devel

>>qemu-0.9.0 ...
>>emulating Debian 2.6.18-4-qemu mipsel ...
>>errs when gdb 6.4.90-debian (running on the emulated mipsel)
>>single-steps the user-mode instruction ...

> This looks like another instance of "Qemu/MIPS doesn't handle
> self-modifying code correctly" (the break instructions inserted
> by gdb are exactly this).

No, the usage by gdb does *not* qualify as "self-modifying code."
gdb uses the system call ptrace(PTRACE_POKETEXT, pid, addr, data)
to have the emulated operating system kernel itself modify the memory
of the child process.  Nobody has to guess or to "snoop" the memory
bus in order to discover that the instruction stream is being modified.
Instead, there is direct notification of what is happening.  If nothing
else, then under CONFIG_QEMU the implementation of sys_ptrace()
must notify the emulator to flush the appropriate translations.

-- 
John Reiser, jreiser@BitWagon.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64
  2007-05-08 23:50   ` John Reiser
@ 2007-05-09  1:04     ` Thiemo Seufer
  0 siblings, 0 replies; 11+ messages in thread
From: Thiemo Seufer @ 2007-05-09  1:04 UTC (permalink / raw)
  To: John Reiser; +Cc: qemu-devel

John Reiser wrote:
> >>qemu-0.9.0 ...
> >>emulating Debian 2.6.18-4-qemu mipsel ...
> >>errs when gdb 6.4.90-debian (running on the emulated mipsel)
> >>single-steps the user-mode instruction ...
> 
> > This looks like another instance of "Qemu/MIPS doesn't handle
> > self-modifying code correctly" (the break instructions inserted
> > by gdb are exactly this).
> 
> No, the usage by gdb does *not* qualify as "self-modifying code."

In the context of Qemu system emulation it does...

> gdb uses the system call ptrace(PTRACE_POKETEXT, pid, addr, data)
> to have the emulated operating system kernel itself modify the memory
> of the child process.

... since "child processes" etc. run by the guest kernel are just a
foreign thing to Qemu.

> Nobody has to guess or to "snoop" the memory
> bus in order to discover that the instruction stream is being modified.
> Instead, there is direct notification of what is happening.

The Linux kernel happily does cache flushes, and Qemu happily ignores
them, since it doesn't implement a cache model. (A cache model is not
the answer. It would be slow, it would only paper over the problem,
it wouldn't help for uncached accesses or cacheless systems).

> If nothing
> else, then under CONFIG_QEMU the implementation of sys_ptrace()
> must notify the emulator to flush the appropriate translations.

Hacking special facilities in the guest kernel just to work around
a Qemu bug is IMHO the wrong approach.


Thiemo

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-05-09  1:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-06 18:45 [Qemu-devel] bug: qemu-0.9.0 emulating mipsel (32-bit R3000) on amd64 John Reiser
2007-05-06 20:04 ` Thiemo Seufer
2007-05-06 20:07   ` Thiemo Seufer
2007-05-07 12:13   ` Daniel Jacobowitz
2007-05-07 15:46     ` Paul Brook
2007-05-07 22:46     ` [Qemu-devel] workaround: " John Reiser
2007-05-07 23:03       ` Paul Brook
2007-05-07 23:08         ` Paul Brook
2007-05-08 18:03     ` [Qemu-devel] bug: " Stefan Weil
2007-05-08 23:50   ` John Reiser
2007-05-09  1:04     ` Thiemo Seufer

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.