Page 1 of 1

>20 tasks kills my kernel (triple fault)

Posted: Sat Feb 23, 2008 9:14 pm
by piranha
This post is not only a question, but is also a bug notification to JamesM, as my kernel is based off of his tutorials (the multitasking one, btw).
I don't know whether the problem is from my code, but every time load a bunch of new tasks, QEMU triple faults. Am I out of space? Something like it? Chnaging the amount of RAM in Qemu does nothing.
Here is the output:

Code: Select all

qemu: fatal: triple fault
EAX=dffffec0 EBX=00234000 ECX=0010426b EDX=dffffe98
ESI=00053ca9 EDI=00053caa EBP=dffffec0 ESP=dffffe98
EIP=001041bc EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300
CS =0008 00000000 ffffffff 00cf9a00
SS =0010 00000000 ffffffff 00cf9300
DS =0010 00000000 ffffffff 00cf9300
FS =0010 00000000 ffffffff 00cf9300
GS =0010 00000000 ffffffff 00cf9300
LDT=0000 00000000 0000ffff 00008000
TR =0000 00000000 0000ffff 00008000
GDT=     00125080 00000027
IDT=     001250c0 000007ff
CR0=e0000011 CR2=00125100 CR3=00234000 CR4=00000000
CCS=00012345 CCD=c00807b4 CCO=LOGICL
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
Aborted
I'd like to know how to fix it, and request that JamesM try to reproduce the problem, as it may be from that code.

-JL

Posted: Sat Feb 23, 2008 11:19 pm
by astrocrep
Theres a bug in the code for init paging...

The heap is not reproduced properly accross all P/Ds...

If you allocate enough memory its possible to bite it.

Ill find the bug... brb

This is where we prep the heap, before, identity mapping the kernel...

Code: Select all

for (i = KHEAP_START; i < KHEAP_START+KHEAP_INITIAL_SIZE; i += 0x1000) 
  get_page(i, 1, kernel_directory); 
to

Code: Select all

for (i = KHEAP_START; i < KHEAP_END; i += 0x1000) 
  get_page(i, 1, kernel_directory); 
KHEAP_END is not a constant in the code, but one I made up, its value is: 0xCFFFF000

Try that out...

Basically whats happening here is that only the first Page table of the heap is inserted into each P/D... if your heap extended into the second P/T it won't be there...

The fix above allocated all of the P/Ts for the Heap and ensures that the pointers will be in every P/D

-Rich

Posted: Sat Feb 23, 2008 11:48 pm
by piranha
Right, so I found 2 copies of that code in the procedure, one caused a page fault, the other didn't do anything.......
EDIT: Oopps, nevermind 'bout the page fault.
-JL

Posted: Sun Feb 24, 2008 7:57 am
by JamesM
astrocrep has already pointed that out to me - I thought I changed the downloadable tarball to include it. Possibly not.

Do let me know if the bug continues.

Posted: Sun Feb 24, 2008 9:31 am
by astrocrep
piranha wrote:Right, so I found 2 copies of that code in the procedure, one caused a page fault, the other didn't do anything.......
EDIT: Oopps, nevermind 'bout the page fault.
-JL
You only need to change the first one... just with the get page... the allocframe part is for actually loading memory to the heap. This is done dynamically as it expands.

What was the issue?
JamesM wrote:astrocrep has already pointed that out to me - I thought I changed the downloadable tarball to include it. Possibly not.

Do let me know if the bug continues.
I though maybe he was using Cut&Paste from the web-site.

-Rich

Posted: Sun Feb 24, 2008 11:00 am
by piranha
Well, first I tried updating the code to match your specifications, and triple fault.
Then, I tried downloading the source code for the The Heap tutorial. Do I need to download a different source tar ball? Or dows Qemu hate me, cause it still triple faults. I also tried messing with the paging code to no avail....

EDIT: @JamesM: I also tried to reproduce the problem in your original multitasking code, and it did triple fault.

-JL

Posted: Sun Feb 24, 2008 11:30 am
by JamesM
Damn. I'll investigate. It's probably to do with locking - in many places there are "TODO: Locks here" comments that indicate where synchronisation is required. Stress testing the code without these in place is a Bad Idea (tm).

Posted: Tue Mar 11, 2008 10:57 pm
by piranha
So, I did figure it out here.....
add:

Code: Select all

expand(0x400000, kheap);
right after initialize_paging();

...that works....125 tasks now.
EDIT: No, it didn't take me this long to figure out, I just didn't work on it before.
-JL

Posted: Wed Mar 12, 2008 2:29 am
by JamesM
In which case possibly the contract code is faulty. It should expand and contract as needed. Hmm.

Posted: Wed Mar 12, 2008 8:32 am
by piranha
Is that for a malloc kindof thing? Should I just add more mallocs?

One other funny thing is.....when it hit's exactly 125 tasks now, it page faults.

-JL