OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Mar 18, 2024 11:39 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Anyone got working long mode in Virtualbox?
PostPosted: Sun Mar 04, 2012 3:09 pm 
Offline
Member
Member
User avatar

Joined: Tue Feb 08, 2011 1:58 pm
Posts: 496
Ok, I'm fed up with this sh*t. Some mysterious error come up sometimes in VirtualBox, but only in VirtualBox (qemu, bochs, real machine fine). So I decided to debug it. After several nights, I ended up in debugging the exception handlers, because random faults happened (mostly PF) when I enabled interrupts, and I wanted to track down the instruction that caused it. For some reason, my own in-kernel debugger caused another fault (which is impossible, it's written in a way to avoid that (each exception handler checks the inpanic variable). It can only happened if IST1 pointed kernel stack is not available, but I've triple checked that, and it pointed to the top of the first page of userspace where i wanted it).
Code:
macro      exception_code      err, handler
{
if err
      pop         qword [sys.arch.cpu.excerr]
end if
      cmp         byte [panichandler.inpanic], 0
      jnz         .noexc
      cli
      clsavectx
...

Anyway I started to use VirtualBox's built-in debugger (which lack the step-by-step execution feature, gives me errors all the time, as well as modifying guest's registers, so it's really pain to use).
Look what I've found:
Code:
Welcome to the VirtualBox Debugger!
Current VM is 155db000, CPU #0
VBoxDbg>
dbf event: Fatal error! (hyper)
.eax=00000000 .ebx=00000000 .ecx=00000000 .edx=00000000 .esi=00000000 .edi=00000000
.eip=00000000 .esp=ff5c8000 .ebp=00000000 .iopl=0 nv up di pl nz na pe nc
.cs=fff8 .ds=fff0 .es=fff0 .fs=0000 .gs=0000 .ss=fff0              .eflags=00000000
Failed to disassemble instruction, skipping one byte.
u: error: Too many disassembly failures. Giving up: VINF_SUCCESS

FTW? Fatal error in hypervisor? But what about my guest vm?
Code:
VBoxDbg> rg64
rax=0000000000102232 rbx=ffffffffffffffff rcx=000000000018f0ff rdx=0000000000000000
rsi=65726f63202d205a rdi=000000000000d3e7 r8 =72617453202d205c r9 =0000000000192005
r10=00ff53f000ff53f0 r11=0000000000191007 r12=000000000001e045 r13=0000000000196007
r14=00000000000103ef r15=000000018f000001 iopl=0 rf nv up di pl zr na po nc
rip=000000000001a794 rsp=0000000040000fd4 rbp=000000018f000001
cs=0010 ds=001b es=001b fs=001b gs=001b ss=0000                     rflags=00210046
%000000000001a794 50                      push rax
VBoxDbg> dg
0008 DataRW Bas=00000000 Lim=f0000000 DPL=0 P  A  G     AVL=0 L=0
0010 CodeEO Bas=00000000 Lim=00000000 DPL=0 P  NA       AVL=0 L=1
0018 DataRW Bas=00000000 Lim=f0000000 DPL=3 P  A  G     AVL=0 L=0
0020 CodeEO Bas=00000000 Lim=00000000 DPL=3 P  NA       AVL=0 L=1
0028 Tss64B Bas=0000000040000000 Lim=00000068 DPL=0 P  B         AVL=0 R=0
0034 VERR_INVALID_SELECTOR
VBoxDbg> di 0d
000d Trap64 Sel:Off=0010:000000000001a780     DPL=3 P
VBoxDbg>

Code segment is a long mode segment, ok, rip points to the appropriate isr, that's fine. But rsp looks unaligned? That's more than unlikely. So I disassembled the code...
Code:
VBoxDbg> u 1a780
%000000000001a780 8f 05 8a 18 ff ff       pop dword [0ffff188ah wrt rip]
%000000000001a786 80 3d 4e 67 ff ff 00    cmp byte [0ffff674eh wrt rip], 000h
%000000000001a78d 0f 85 b3 f9 ff ff       jne -00000064dh (0000000000001a146h)
%000000000001a793 fa                      cli
%000000000001a794 50                      push rax
%000000000001a795 53                      push rbx
%000000000001a796 51                      push rcx
%000000000001a797 52                      push rdx
%000000000001a798 56                      push rsi
%000000000001a799 57                      push rdi

And my mind blow up (almost). How on earth could it pop 4 bytes from stack in long mode? Intel manuals more than clear on this one...
Code:
8F/0       POP r/m64     Valid     N.E.      Pop top of stack into m64; increment stack pointer. Cannot encode 32-bit operand size.

and
Code:
operand-size attribute of the current code segment deter- mines the amount the stack pointer is incremented (2, 4, 8 bytes).

This bugbag succeeded to interpret "pop" as dword in long mode.

Because of this, and many other annoying problems, I hereby declare that I officially drop VirtualBox support for my OS. Sayonara!


Top
 Profile  
 
 Post subject: Re: Anyone got working long mode in Virtualbox?
PostPosted: Sun Mar 04, 2012 3:34 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2426
Location: Canada
VirtualBox is unsupported by OpenBSD as well, it's a piece of crap.

_________________
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.


Top
 Profile  
 
 Post subject: Re: Anyone got working long mode in Virtualbox?
PostPosted: Mon Mar 05, 2012 4:25 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
One of those rare cases where the bug really isn't your own fault. Clever debugging!


Top
 Profile  
 
 Post subject: Re: Anyone got working long mode in Virtualbox?
PostPosted: Wed Mar 07, 2012 9:06 am 
Offline
Member
Member

Joined: Tue Nov 08, 2011 11:35 am
Posts: 453
What version of VirtualBox do you use? I.e., is it the most recent version?
And if it's the up-to-date version, did you file bugreport?


Top
 Profile  
 
 Post subject: Re: Anyone got working long mode in Virtualbox?
PostPosted: Wed Mar 07, 2012 10:49 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 08, 2011 1:58 pm
Posts: 496
Nable wrote:
What version of VirtualBox do you use? I.e., is it the most recent version?

Of course up-to-date.
Code:
$ VirtualBox --help
Oracle VM VirtualBox Manager 4.1.8

Quote:
And if it's the up-to-date version, did you file bugreport?

No, because it requires an oracle registration (not virtualbox forum or similar), and others have reported the problem already (not the "why" though). Feel free to report it if you like.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group