Skip to contentSkip to conversation

PC-BSD installer does not boot with 1.7.4 (bisected)

Qemu-devel Michael Tokarev 3 participants 8 messages Feb 4, 2014 – Feb 17, 2014

lore
Share & tools
lore
#0 lore raw

We have a bugreport in debian, http://bugs.debian.org/737142,
stating that PC-BSD does not work with seabios-1.7.4 anymore.

I digged in, and found out that it fails only with -vga std (cirrus works fine). So I bisected the issue - only changing vgabios-stdvga.bin, and found this:

9332f9b172dd59253365a83b5f1c0e40c5f6f66d is the first bad commit commit 9332f9b172dd59253365a83b5f1c0e40c5f6f66d

Author: Kevin O'Connor <[email protected]>
Date:   Sat Nov 30 12:52:44 2013 -0500

vgabios: Work around lack of support for "calll" in x86emu emulation.

Replace 32 bit call instructions with 16 bit call instructions in the vgabios to workaround problems in old versions of x86emu. This change allows fc13 and fc14 to boot. (Other x86emu emulation bugs still prevent fc11 and fc12 from booting.)

I'm not sure what is better - to have semi-working FC13 or non-working PC-BSD ;)

Seriously, I don't really have any expirience in this area to understand what's going on. Note that PC-BSD fails clearly in some VGA-related code, and this is trivially reproducible.

Thanks,

/mjt

#1 lore raw
Quoted 7 lines · Michael Tokarev

We have a bugreport in debian, http://bugs.debian.org/737142,
stating that PC-BSD does not work with seabios-1.7.4 anymore.

I digged in, and found out that it fails only with -vga std (cirrus works fine). So I bisected the issue - only changing vgabios-stdvga.bin, and found this:

Quoted 6 lines

9332f9b172dd59253365a83b5f1c0e40c5f6f66d is the first bad commit commit 9332f9b172dd59253365a83b5f1c0e40c5f6f66d

Author: Kevin O'Connor <[email protected]>
Date:   Sat Nov 30 12:52:44 2013 -0500

vgabios: Work around lack of support for "calll" in x86emu emulation.

Thanks. I've downloaded the image and I've looked into the crash.

This seems to be similar to the freebsd problem reported last year - see:
http://lists.gnu.org/archive/html/qemu-stable/2013-03/msg00037.html

I haven't downloaded the freebsd kernel this time, but I have tried multiple seavgabios binaries and here is what I think is occurring:

1 - The freebsd kernel seems to be trying to emulate the vgabios to make vesa calls. Its emulator is buggy.

2 - Prior to the SeaBIOS 9332f9b1 commit, the freebsd x86 emulator seems to go "off the deep end" quickly and it is generally caught by the kernel and the boot proceeds.

3 - After SeaBIOS 9332f9b1, the freebsd x86 emulator gets further along in its x86 emulation and then goes "off the deep end" in a way it doesn't catch. The boot then fails.

With trivial changes to the vgabios, I can see freebsd fail (eg, loop infinitely) even prior to SeaBIOS 9332f9b1. With trivial changes to the vgabios after 9332f9b1, I can get freebsd to loop infinitely instead of trap, or even sometimes catch itself and proceed with the boot.

Anyway, this seems to be a freebsd issue, and I think it requires someone with knowledge of the freebsd internals and the freebsd develop/compile/test cycle.

I don't see a good way to address this issue in SeaBIOS (*).

-Kevin

(*) The best I can think of is to try and construct some hand crafted assembler that can catch buggy x86emu emulators and force a failure..

#2 lore raw
Quoted 7 lines · Kevin O'Connor
Quoted 6 lines · Michael Tokarev

We have a bugreport in debian, http://bugs.debian.org/737142,
stating that PC-BSD does not work with seabios-1.7.4 anymore.

I digged in, and found out that it fails only with -vga std (cirrus works fine). So I bisected the issue - only changing vgabios-stdvga.bin, and found this:

[...]

Quoted 3 lines

This seems to be similar to the freebsd problem reported last year - see:
http://lists.gnu.org/archive/html/qemu-stable/2013-03/msg00037.html

[...]

Quoted 2 lines

(*) The best I can think of is to try and construct some hand crafted assembler that can catch buggy x86emu emulators and force a failure..

I have put together some assember to try and run-time test for known broken versions of x86emu. This patch to SeaVGABIOS does seem to catch the freebsd issue and in my tests it convinces freebsd to take a different approach. The patch is a bit ugly though.

Comments welcome.
-Kevin

commit e3caa553e940efb6184b30a5637134c4aa9f8b65

Author: Kevin O'Connor <[email protected]>
Date:   Wed Feb 5 22:47:29 2014 -0500

vgabios: Attempt to detect old x86emu and force a fault.

Check for cases where the leal instruction does not work. This instruction is known to not be emulated properly on old versions of x86emu. If a broken version of x86emu is found, force a fault that x86emu will easily detect. This should help prevent soft failures when running old software.

vgasrc/vgaentry.S +23 -5
index 9854448..e246e7c 100644
@@ -45,9 +45,27 @@ _rom_header_signature:
  * Entry points
  ****************************************************************/
 
-        // This macro is the same as ENTRY_ARG except the "calll"
-        // instruction is avoided to work around known issues in the
-        // emulation of some versions of x86emu.
+        // Force a fault if found to be running on broken x86emu versions.
+        DECLFUNC x86emu_fault
+x86emu_fault:
+        int $0x03
+1:      hlt
+        jmp 1b
+
+        // This macro implements a call while avoiding instructions
+        // that old versions of x86emu have problems with.
+        .macro VGA_CALLL cfunc
+        // Make sure leal instruction works.
+        movl $0x8000, %ecx
+        leal (%ecx, %ecx, 1), %ecx
+        cmpl $0x10000, %ecx
+        jne x86emu_fault
+        // Use callw instead of calll
+        push %ax
+        callw \cfunc
+        .endm
+
+        // This macro is the same as ENTRY_ARG except VGA_CALLL is used.
         .macro ENTRY_ARG_VGA cfunc
         cli
         cld
@@ -57,7 +75,7 @@ _rom_header_signature:
         movl %esp, %ebx         // Backup %esp, then zero high bits
         movzwl %sp, %esp
         movl %esp, %eax         // First arg is pointer to struct bregs
-        pushw %ax ; callw \cfunc
+        VGA_CALLL \cfunc
         movl %ebx, %esp         // Restore %esp (including high bits)
         POPBREGS
         .endm
@@ -103,7 +121,7 @@ entry_10_extrastack:
         movw %ds, %dx           // Setup %ss/%esp and call function
         movw %dx, %ss
         movl %eax, %esp
-        pushw %ax ; callw handle_10
+        VGA_CALLL handle_10
 
         movl %esp, %eax         // Restore registers and return
         movw BREGS_size+4(%eax), %ss
#3 lore raw

Re: [Qemu-devel] *BSD kernel crash at boot in qemu with seabios 1.7.4 (bisected)

[Changing subject to reflect reality]

I don't really understand what it is all about, as I initially said. But I've been told on freebsd IRC channels to post the issue to freebsd-emulation list, which I'm Cc'ing now, and if noone there answers, also to John Baldwin <jhb@FreeBSD>.

To bring some context back, here are a few pointers:

http://bugs.debian.org/737142 --
talking about pc-bsd, but it appears that the prob affects other BSD kernels too
http://thread.gmane.org/gmane.comp.emulators.qemu/254074 -- this thread
http://lists.gnu.org/archive/html/qemu-stable/2013-03/msg00037.html - a
weird issue with freebsd reported last december

If it's a bug in *BSD kernels, maybe someone there will be glad to fix it. And maybe together we can come out with a more elegant solution to this issue, or maybe to confirm (or deny) that the proposed patch is a right thing to do.

Thanks,

/mjt

Quoted 93 lines · Kevin O'Connor
Quoted 7 lines · Kevin O'Connor
Quoted 6 lines · Michael Tokarev

We have a bugreport in debian, http://bugs.debian.org/737142,
stating that PC-BSD does not work with seabios-1.7.4 anymore.

I digged in, and found out that it fails only with -vga std (cirrus works fine). So I bisected the issue - only changing vgabios-stdvga.bin, and found this:

[...]

Quoted 3 lines

This seems to be similar to the freebsd problem reported last year - see:
http://lists.gnu.org/archive/html/qemu-stable/2013-03/msg00037.html

[...]

Quoted 2 lines

(*) The best I can think of is to try and construct some hand crafted assembler that can catch buggy x86emu emulators and force a failure..

I have put together some assember to try and run-time test for known broken versions of x86emu. This patch to SeaVGABIOS does seem to catch the freebsd issue and in my tests it convinces freebsd to take a different approach. The patch is a bit ugly though.

Comments welcome.
-Kevin

commit e3caa553e940efb6184b30a5637134c4aa9f8b65

Author: Kevin O'Connor <[email protected]>
Date:   Wed Feb 5 22:47:29 2014 -0500

vgabios: Attempt to detect old x86emu and force a fault.

Check for cases where the leal instruction does not work. This instruction is known to not be emulated properly on old versions of x86emu. If a broken version of x86emu is found, force a fault that x86emu will easily detect. This should help prevent soft failures when running old software.

vgasrc/vgaentry.S +23 -5
index 9854448..e246e7c 100644
@@ -45,9 +45,27 @@ _rom_header_signature:
  * Entry points
  ****************************************************************/
 
-        // This macro is the same as ENTRY_ARG except the "calll"
-        // instruction is avoided to work around known issues in the
-        // emulation of some versions of x86emu.
+        // Force a fault if found to be running on broken x86emu versions.
+        DECLFUNC x86emu_fault
+x86emu_fault:
+        int $0x03
+1:      hlt
+        jmp 1b
+
+        // This macro implements a call while avoiding instructions
+        // that old versions of x86emu have problems with.
+        .macro VGA_CALLL cfunc
+        // Make sure leal instruction works.
+        movl $0x8000, %ecx
+        leal (%ecx, %ecx, 1), %ecx
+        cmpl $0x10000, %ecx
+        jne x86emu_fault
+        // Use callw instead of calll
+        push %ax
+        callw \cfunc
+        .endm
+
+        // This macro is the same as ENTRY_ARG except VGA_CALLL is used.
         .macro ENTRY_ARG_VGA cfunc
         cli
         cld
@@ -57,7 +75,7 @@ _rom_header_signature:
         movl %esp, %ebx         // Backup %esp, then zero high bits
         movzwl %sp, %esp
         movl %esp, %eax         // First arg is pointer to struct bregs
-        pushw %ax ; callw \cfunc
+        VGA_CALLL \cfunc
         movl %ebx, %esp         // Restore %esp (including high bits)
         POPBREGS
         .endm
@@ -103,7 +121,7 @@ entry_10_extrastack:
         movw %ds, %dx           // Setup %ss/%esp and call function
         movw %dx, %ss
         movl %eax, %esp
-        pushw %ax ; callw handle_10
+        VGA_CALLL handle_10
 
         movl %esp, %eax         // Restore registers and return
         movw BREGS_size+4(%eax), %ss
#5 lore raw
In reply to Kevin O'Connor
Quoted 12 lines · Kevin O'Connor
Quoted 7 lines · Kevin O'Connor
Quoted 6 lines · Michael Tokarev

We have a bugreport in debian, http://bugs.debian.org/737142,
stating that PC-BSD does not work with seabios-1.7.4 anymore.

I digged in, and found out that it fails only with -vga std (cirrus works fine). So I bisected the issue - only changing vgabios-stdvga.bin, and found this:

[...]

Quoted 3 lines

This seems to be similar to the freebsd problem reported last year - see:
http://lists.gnu.org/archive/html/qemu-stable/2013-03/msg00037.html

Quoted 8 lines

[...]

Quoted 2 lines

(*) The best I can think of is to try and construct some hand crafted assembler that can catch buggy x86emu emulators and force a failure..

I have put together some assember to try and run-time test for known broken versions of x86emu. This patch to SeaVGABIOS does seem to catch the freebsd issue and in my tests it convinces freebsd to take a different approach. The patch is a bit ugly though.

There hasn't been much comment, but I have pushed this patch to the main seabios repo for now.

-Kevin

#4 lore raw

Re: [Qemu-devel] *BSD kernel crash at boot in qemu with seabios 1.7.4 (bisected)

In reply to Michael Tokarev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Quoted 16 lines · Michael Tokarev

[Changing subject to reflect reality]

I don't really understand what it is all about, as I initially said. But I've been told on freebsd IRC channels to post the issue to freebsd-emulation list, which I'm Cc'ing now, and if noone there answers, also to John Baldwin <jhb@FreeBSD>.

To bring some context back, here are a few pointers:

http://bugs.debian.org/737142 -- talking about pc-bsd, but it appears that the prob affects other BSD kernels too
http://thread.gmane.org/gmane.comp.emulators.qemu/254074 -- this thread
http://lists.gnu.org/archive/html/qemu-stable/2013-03/msg00037.html
- a weird issue with freebsd reported last december

Quoted 4 lines

If it's a bug in *BSD kernels, maybe someone there will be glad to fix it. And maybe together we can come out with a more elegant solution to this issue, or maybe to confirm (or deny) that the proposed patch is a right thing to do.

Yes it does look like a bug in FreeBSD kernel. Is there a PR already or should I create one and assign to myself? I will try to fix this when I have some free cycles.

I assume this also happens when running FreeBSD under qemu on FreeBSD, right?

Cheers,

Quoted 21 lines

Thanks,

/mjt

Quoted 16 lines · Kevin O'Connor
Quoted 9 lines · Kevin O'Connor
Quoted 7 lines · Michael Tokarev

We have a bugreport in debian,
http://bugs.debian.org/737142, stating that PC-BSD does not work with seabios-1.7.4 anymore.

I digged in, and found out that it fails only with -vga std (cirrus works fine). So I bisected the issue - only changing vgabios-stdvga.bin, and found this:

[...]

Quoted 5 lines

This seems to be similar to the freebsd problem reported last year - see:
http://lists.gnu.org/archive/html/qemu-stable/2013-03/msg00037.html

[...]

Quoted 56 lines
Quoted 56 lines
Quoted 3 lines

(*) The best I can think of is to try and construct some hand crafted assembler that can catch buggy x86emu emulators and force a failure..

I have put together some assember to try and run-time test for known broken versions of x86emu. This patch to SeaVGABIOS does seem to catch the freebsd issue and in my tests it convinces freebsd to take a different approach. The patch is a bit ugly though.

Comments welcome. -Kevin

commit e3caa553e940efb6184b30a5637134c4aa9f8b65 Author: Kevin
O'Connor <[email protected]> Date: Wed Feb 5 22:47:29 2014
-0500

vgabios: Attempt to detect old x86emu and force a fault.

Check for cases where the leal instruction does not work. This instruction is known to not be emulated properly on old versions of x86emu. If a broken version of x86emu is found, force a fault that x86emu will easily detect. This should help prevent soft failures when running old software.

vgasrc/vgaentry.S index renamed from vgasrc/vgaentry.S +0 -0

9854448..e246e7c 100644 --- a/vgasrc/vgaentry.S +++ b/vgasrc/vgaentry.S @@ -45,9 +45,27 @@ _rom_header_signature: * Entry points ****************************************************************/

- // This macro is the same as ENTRY_ARG except the
"calll" - // instruction is avoided to work around known
issues in the - // emulation of some versions of x86emu. +
// Force a fault if found to be running on broken x86emu
versions. + DECLFUNC x86emu_fault +x86emu_fault: +
int $0x03 +1: hlt + jmp 1b + + // This macro
implements a call while avoiding instructions + // that
old versions of x86emu have problems with. + .macro
VGA_CALLL cfunc + // Make sure leal instruction works. +
movl $0x8000, %ecx + leal (%ecx, %ecx, 1), %ecx +
cmpl $0x10000, %ecx + jne x86emu_fault + // Use
callw instead of calll + push %ax + callw \cfunc +
.endm + + // This macro is the same as ENTRY_ARG except
VGA_CALLL is used. .macro ENTRY_ARG_VGA cfunc cli cld @@ -57,7
+75,7 @@ _rom_header_signature: movl %esp, %ebx // Backup
%esp, then zero high bits movzwl %sp, %esp movl %esp, %eax
// First arg is pointer to struct bregs - pushw %ax ;
callw \cfunc + VGA_CALLL \cfunc movl %ebx, %esp //
Restore %esp (including high bits) POPBREGS .endm @@ -103,7
+121,7 @@ entry_10_extrastack: movw %ds, %dx // Setup
%ss/%esp and call function movw %dx, %ss movl %eax, %esp -
pushw %ax ; callw handle_10 + VGA_CALLL handle_10

Quoted 10 lines
Quoted 3 lines

movl %esp, %eax // Restore registers and return movw
BREGS_size+4(%eax), %ss

_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-emulation To unsubscribe, send any mail to "[email protected]"

-----BEGIN PGP SIGNATURE-----

iQIcBAEBCgAGBQJS+qWRAAoJEJW2GBstM+nsz3sP/AsGiEPWzHAbQP5nYR9alDiL dmMd8RB4yVYLmJJXCxLldMjNw3kuHRcZ8IrvCaxsFvUHnzdQudmqCc6uxgcWdC3Y gqSYP2/dnG5OXsUqmRHW0yKpfrBlbOA/utRDZz9MzTx4m7sudY8y8ZEUmb2OyJOZ CjQrW5OyHIXUxzdKMlcpiAy5+edQVWk5TBdyz6h0WVrk4A9uuAjOw/DYse05lGVF l1d/Eto+Wui38fMTjfdVJqVcPrfy859aODf/vRkmznujd0Zumr/8OMXmEsF+Q+iv ktRNWab39DXIArMsYbCGr7Xg7Q0ZjZB0eAjB8zxW1a0p/7V4Spf9QQu9wNHVi4sf DOwiaU2K+2/zz/BYIyicyZN+glQMLcq+t3u8uagm6GOcHMx1ZsyFeyIhj8Gbtjfl VUPOVZfu25dogr5GY2U68tPHoiQStsSvdSg4+jaDYK5AZcs1BGZ5i5ncArjATV1Z KIe3ISOzu20BMhjAXHALnTNMFuBWD6+Va6ExVHWkWuz445aQ0REx3hJDqWbm7iVd DTD2N6Bs/uL7P3aVODgz8EqQ6EMhswFYgqSirMb9w38FCLnJ56aAA31kFU00U28p OG8kzgc3dY0II1vVfNLhrJ5kGNDOKxZ62KsXbLHPdBl3cgKweqghd53WTjU/dSo6 0NVfAqheJ3ifZ0I0yB3d
=jTIz
-----END PGP SIGNATURE-----

#6 lore raw
In reply to Kevin O'Connor

10.02.2014 19:41, Kevin O'Connor wrote:
[]

Quoted 2 lines

There hasn't been much comment, but I have pushed this patch to the main seabios repo for now.

Xin Li (Cc'ed) replied to this email.

Meanwhile I tried your patch, and it indeed fixes the reported issues with FreeBSD and PCBSD.

Even if FreeBSD fixes this bug, we still have to support runnin old, unfixed, systems in qemu/kvm, so seabios-side change is needed anyway.

Oh well.

Thanks,

/mjt

#7 lore raw
Quoted 6 lines · Michael Tokarev

10.02.2014 19:41, Kevin O'Connor wrote:
[]

Quoted 2 lines

There hasn't been much comment, but I have pushed this patch to the main seabios repo for now.

Xin Li (Cc'ed) replied to this email.

Yes. Thanks. It would be good for FreeBSD to also fix the underlying issue.

Quoted 5 lines

Meanwhile I tried your patch, and it indeed fixes the reported issues with FreeBSD and PCBSD.

Even if FreeBSD fixes this bug, we still have to support runnin old, unfixed, systems in qemu/kvm, so seabios-side change is needed anyway.

Yeah. That's why I went ahead and committed the SeaVGABIOS workaround. The workaround also makes early versions of X11 behave better (they fail outright now instead of hanging).

-Kevin