OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 21, 2018 1:49 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [SOLVED] VT-x and indirect jump cause triple fault
PostPosted: Thu Jan 11, 2018 12:02 pm 
Offline

Joined: Fri Oct 13, 2017 6:59 pm
Posts: 17
Hi there,

My kernel use a high half setup and every thing seem to work on qemu.
But when I try on a real hardware or on VirtualBox, the CPU reset with a triple fault.
A found that disabling VT-x in VirtualBox fix the issue.

The triple fault occure when I'm jumping into the high half part after enabling paging (as you can see below in AT&T syntax). The triple fault point the jmp instruction.
Any idea why it's happen ? I don't find any informations (but maybe I search in the wrong place) :/

Code:
/****** in the first section located at standard address (virt=phys) for grub *******/
_entry32:
/* Load GDT and clear segments registers */
    lgdt GDT32_pointer
    ljmp $0x8, $(.Lreset)
.Lreset:
    mov $0x10, %edx
    mov %edx, %ds
    mov %edx, %es
    mov %edx, %fs
    mov %edx, %gs
    mov %edx, %ss

    /* Enable stack and reset EFLAGS */
    mov $stack_top, %esp
    mov %esp, %ebp
    pushl $0
    popf

    /* Save multiboot informations */
    push %ebx
    push %eax

    /* Do the paging initialization */
    call init_kernel

    /* Install page directory (in %eax because call return into it) */
    mov %eax, %cr3

    /* Enable paging */
    mov %cr0, %eax
    or $(1 << 31), %eax
    mov %eax, %cr0

    /* Jump far into the half-high kernel */
    lea _high_entry, %eax
    jmp *%eax                    /* <---------- TRIPLE FAULT with VT-x enabled in VirtualBox */

/****** in a different section linked in high virtual address space *******/
_high_entry:
    call kernel_main
_halt:
.Lhang:
    cli
    hlt
    jmp .Lhang


Last edited by Tutul on Fri Jan 12, 2018 9:33 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: VT-x and indirect jump cause triple fault
PostPosted: Thu Jan 11, 2018 9:41 pm 
Offline
Member
Member

Joined: Sat Jul 02, 2016 7:02 am
Posts: 71
Since your machine supports virtualization, was qemu run with kvm enabled (to reproduce the issue)?
It has debug options which you can list using 'qemu-system-x86_64 -d help'. Of interest are the flags 'int,mmu,cpu_reset,unimp,guest_errors'.

Virtualbox log files should have the dump of the guest state, which can point towards the cause.


Top
 Profile  
 
 Post subject: Re: VT-x and indirect jump cause triple fault
PostPosted: Fri Jan 12, 2018 7:28 am 
Offline

Joined: Fri Oct 13, 2017 6:59 pm
Posts: 17
I do use qemu debug flags but qemu work just fine.
I didn't check if I use kvm or not (look at it later).

VirtualBox log only signal the triple fault at the jump and the guest state is the same as the qemu guest state except for the VM flag and EBX value. I assume EBX is different because my init function loop one more time (probably different mmap block in the mbi because I let VB using full 4GB when my last test with qemu only use 2MB)


Top
 Profile  
 
 Post subject: Re: VT-x and indirect jump cause triple fault
PostPosted: Fri Jan 12, 2018 8:00 am 
Offline
Member
Member

Joined: Sat Jul 02, 2016 7:02 am
Posts: 71
The sequence of faults is most likely initiated by a page fault arising because of an error in setting up the page tables.

Since the faults occur when VT-x is enabled when running under Virtualbox, qemu with kvm may also be similarly affected. If so, qemu's debug options, its monitor, and its gdb debug capabilities can be used to examine the cpu state and tables.

Another option towards debugging it is to see if Bochs reports any problems.


Top
 Profile  
 
 Post subject: Re: VT-x and indirect jump cause triple fault
PostPosted: Fri Jan 12, 2018 8:20 am 
Offline

Joined: Fri Oct 13, 2017 6:59 pm
Posts: 17
So I found how tu run kvm (on Fedora kvm and qemu merge but I was missing a package to use it directly).
KVM reset too but the log only show CPU_RESET and no error (no TRIPLE FAULT, I just saw A20 enabling by grub and normal CPU_RESET).
It's seem that the CPU reset on the same instructions.
But something seem strange with my GDT. My kernel is 32-bit, I setup a 32-bit GDT but with kvm CS seem to be 64-bit ?!

Code:
CPU Reset (CPU 0)
EAX=c0100e31 EBX=00107888 ECX=00005714 EDX=00107001
ESI=00000000 EDI=00000000 EBP=00101000 ESP=00100ff8
EIP=0010009a EFL=00010086 [--S--P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 1fffffff 00f09300 DPL=0 DS   [-WA]
CS =0008 00000000 1fffffff 00f09b00 DPL=0 CS64 [-RA]
SS =0010 00000000 1fffffff 00f09300 DPL=0 DS   [-WA]
DS =0010 00000000 1fffffff 00f09300 DPL=0 DS   [-WA]
FS =0010 00000000 1fffffff 00f09300 DPL=0 DS   [-WA]
GS =0010 00000000 1fffffff 00f09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     001006f0 00000017
IDT=     00000000 00000000
CR0=80000011 CR2=00000000 CR3=00106000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000000 CCO=DYNAMIC
EFER=0000000000000000
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=00000000000000000000000000000000 XMM01=00000000000000000000000000000000
XMM02=00000000000000000000000000000000 XMM03=00000000000000000000000000000000
XMM04=00000000000000000000000000000000 XMM05=00000000000000000000000000000000
XMM06=00000000000000000000000000000000 XMM07=00000000000000000000000000000000
CR0 update: CR0=0x60000010


Top
 Profile  
 
 Post subject: Re: VT-x and indirect jump cause triple fault
PostPosted: Fri Jan 12, 2018 9:18 am 
Offline
Member
Member

Joined: Sat Jul 02, 2016 7:02 am
Posts: 71
The flags-limit_hi byte is set to 0xf0. The L bit in on.

Code:
CS =0008 00000000 1fffffff 00f09b00 DPL=0 CS64 [-RA]


Top
 Profile  
 
 Post subject: Re: VT-x and indirect jump cause triple fault
PostPosted: Fri Jan 12, 2018 9:30 am 
Offline

Joined: Fri Oct 13, 2017 6:59 pm
Posts: 17
Thanks, didn't see it :) Probably a typo ^^"
It's fix the error on kvm and virtualbox :)
Now I saw an other error but it's for the next time (setting RAM to 4G seem to loop or freeze with only the cusror on the screen, blinking).


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 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