OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:19 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 6:45 am 
Offline

Joined: Sat May 20, 2017 6:29 am
Posts: 7
Hi there,

I have recently been working on my OS Dev project with a friend of mine as a little bit of a hobby in my free time - I have just hit the point where it is necessary to implement paging, I have a higher-half kernel setup, GDT, IDT & IRQs set-up and paging is active (4MiB pages).

My issue seems to be non-persistent, I have two memory-managers, the physical memory manager used to keep track of assigned 4MiB blocks of physical memory, and the virtual memory manager that requests a free block from physical memory and then maps that block into a new page in the active page directory.

The issue arises when mapping a new page on different virtualization environments, as an example on QEmu:
- Request Page(0) --> Will Request a Physical Block --> Physical Is Mapped to the Page Table [Page_Num << 22] (with Present, R/W & Size Bits Set) --> Success is returned to caller.
- now, It should be safe to assume that I can Read and Write to $00000000:$003FFFFF
- So I write a 32-bit value @ $00000000
- I read that value back and ALAS it works!
But this is where things get weird - If my friend tries this on his QEmu in a Linux64 Host (But QEmu set as a i386 env) the 32-bit value is not read back, infact, it seems although it was never written, but no Page Fault or GPF occurs.
If I try this on VirtualBox (i386) with Hardware or Paravirtualization enabled, it doesn't write or read the value, but again, no GPF or Page Fault occur.
If I try this on my AMD Ryzen Computer, same as above.
If I try this on my Girlfriends laptop it works fine, the value is read back correctly.

Has anyone had issues similar to this? Any pointers towards what could be going wrong?

If you need any snippets of source-code, please do not hesitate to ask.

Many thanks in advance,

t3hn3rd.


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 7:10 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 384
Don't really have any good ideas as to what might be causing your issues, so I'd recommend debugging with gdb.

Also Qemu so support for inspecting the paging structures IIRC, so you may want to look at those to see what Qemu thinks of your page dir (check the Qemu console, I think it's alt-2 or ctrl-alt-2, etc).

If you can't resolve with those two alone, then copy the relevant info and paste it here, that would help give me/us some idea.

Here's at least some info on gdb:
http://wiki.osdev.org/GDB


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 7:38 am 
Offline

Joined: Mon Sep 21, 2015 2:37 am
Posts: 4
This is the stuff we got back.

Image

If you read our OS output, the 0's after the writing 1234 message is supposed to be 0..1234, but this only works on some systems and some emulators.


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 8:34 am 
Offline

Joined: Sat May 20, 2017 6:29 am
Posts: 7
This is a dump of our Page Directory (4MiB Pages):

Code:
0000000000104000: 0x000030e3 0x00000000 0x00000000 0x00000000 //Entry 0 where we try and write the 32-bit value to
0000000000104010: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104020: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104030: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104040: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104050: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104060: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104070: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104080: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104090: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001040a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001040b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001040c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001040d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001040e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001040f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104100: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104110: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104120: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104130: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104140: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104150: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104160: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104170: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104180: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104190: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001041a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001041b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001041c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001041d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001041e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001041f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104200: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104210: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104220: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104230: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104240: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104250: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104260: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104270: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104280: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104290: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001042a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001042b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001042c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001042d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001042e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001042f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104300: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104310: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104320: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104330: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104340: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104350: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104360: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104370: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104380: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104390: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001043a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001043b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001043c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001043d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001043e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001043f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104400: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104410: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104420: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104430: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104440: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104450: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104460: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104470: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104480: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104490: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001044a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001044b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001044c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001044d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001044e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001044f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104500: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104510: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104520: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104530: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104540: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104550: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104560: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104570: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104580: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104590: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001045a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001045b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001045c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001045d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001045e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001045f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104600: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104610: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104620: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104630: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104640: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104650: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104660: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104670: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104680: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104690: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001046a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001046b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001046c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001046d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001046e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001046f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104700: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104710: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104720: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104730: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104740: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104750: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104760: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104770: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104780: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104790: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001047a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001047b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001047c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001047d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001047e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001047f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104800: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104810: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104820: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104830: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104840: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104850: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104860: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104870: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104880: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104890: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001048a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001048b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001048c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001048d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001048e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001048f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104900: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104910: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104920: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104930: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104940: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104950: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104960: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104970: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104980: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104990: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001049a0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001049b0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001049c0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001049d0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001049e0: 0x00000000 0x00000000 0x00000000 0x00000000
00000000001049f0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a00: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a10: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a20: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a30: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a40: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a50: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a60: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a70: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a80: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104a90: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104aa0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ab0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ac0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ad0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ae0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104af0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b00: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b10: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b20: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b30: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b40: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b50: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b60: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b70: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b80: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104b90: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ba0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104bb0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104bc0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104bd0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104be0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104bf0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104c00: 0x000000e3 0x00001083 0x00002083 0x00000000 // (KERNEL_VIRTUAL_BASE >> 22) to (KERNEL_VIRTUAL_BASE >> 22) + 2 our kernel code.
0000000000104c10: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104c20: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104c30: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104c40: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104c50: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104c60: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104c70: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104c80: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104c90: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ca0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104cb0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104cc0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104cd0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ce0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104cf0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d00: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d10: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d20: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d30: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d40: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d50: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d60: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d70: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d80: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104d90: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104da0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104db0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104dc0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104dd0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104de0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104df0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e00: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e10: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e20: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e30: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e40: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e50: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e60: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e70: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e80: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104e90: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ea0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104eb0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ec0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ed0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ee0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ef0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f00: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f10: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f20: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f30: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f40: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f50: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f60: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f70: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f80: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104f90: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104fa0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104fb0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104fc0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104fd0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104fe0: 0x00000000 0x00000000 0x00000000 0x00000000
0000000000104ff0: 0x00000000 0x00000000 0x00000000 0x00000000


Many thanks,

t3hn3rd.


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 10:20 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
Do the old paging structure entries have their present bit set? If so, do you issue invlpg?

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 10:29 am 
Offline

Joined: Sat May 20, 2017 6:29 am
Posts: 7
I'm not sure what you mean by old paging structure, as it stands (given that we only have the kernel running at this point) we only have a single page directory, representing 4MiB * 1024 of Memory - we have 4 entries in the structure, 3 of them cover the Kernel area for a total of 12MiB and the last one is 4MiB of memory with a virtual address of $00000000 mapped to a free 4MiB portion of Physical memory.

For debugging purposes, each time a new page is issued I reload CR3 with the Page Directory, which, if I'm understanding correctly should flush the TLB and Directory much like invlpg would to a single entry?

Regards,

t3hn3rd.


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 10:35 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
t3hn3rd wrote:
For debugging purposes, each time a new page is issued I reload CR3 with the Page Directory, which, if I'm understanding correctly should flush the TLB and Directory much like invlpg would to a single entry?

That is true.

Are you sure that your test boxes really have physical memory installed at the locations you're trying to map? What physical address are you mapping that page to? Did you check the BIOS address map if that physical address is backed by RAM? Are you sure PSE is enabled?

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 10:41 am 
Offline

Joined: Sat May 20, 2017 6:29 am
Posts: 7
Korona wrote:
t3hn3rd wrote:
For debugging purposes, each time a new page is issued I reload CR3 with the Page Directory, which, if I'm understanding correctly should flush the TLB and Directory much like invlpg would to a single entry?

That is true.

Are you sure that your test boxes really have physical memory installed at the locations you're trying to map? What physical address are you mapping that page to? Did you check the BIOS address map if that physical address is backed by RAM? Are you sure PSE is enabled?


I'm pretty sure - the virtual environments have as follows:
- QEmu: 128MB
- VirtualBox: 256MB
- Bochs: 1024MB

Physical Environments:
- My PC: 16GB (Although, obviously only 4GB will be visible to the kernel)
- Laptop: 8GB (Although, again, same as above)

The kernel pages are mapped to locations 1*4MiB, 2*4MiB & 3*4MiB respectively and the test page for the 32-bit int is mapped to the next available block which should be 4*4MiB.

PSE is definitely enabled with:
Code:
mov ecx, cr4
or ecx, 0x00000010
mov cr4, ecx


I haven't checked the BIOS, I will try to give that a go.

Regards,

t3hn3rd.


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 10:55 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
It's possible that your computers have a memory hole at or around 16 MiB. That can be the case even if they have large amounts (i.e. GiB range) of memory installed. ISA devices for example could not perform DMA to >= 16 MiB addresses and are sometimes mapped just below 16 MiB. The only way to be sure that there is physical memory at that (or any other) location is to check the BIOS.

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 11:03 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 384
Quote:
If I try this on VirtualBox (i386) with Hardware or Paravirtualization enabled, it doesn't write or read the value, but again, no GPF or Page Fault occur.


How do you know it doesn't write it? What happens instead?

As for what Korona mentioned, you basically have two choices if using BIOS (as opposed to UEFI which is different):
- Use GRUB or something
- BIOS E820 (http://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820)

By the looks of it, Qemu is saying that all four 4MiB virtual pages map to 0x0 physical?

In your memory dump "0x000030e3":
If I deciphered that correctly it would seem that that page is dirty, so you have written to it, which would be same thing "info tlb" is saying. You should probably also check what is actually loaded in CR3.. Qemu "info registers" might show it..


Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 11:11 am 
Offline

Joined: Sat May 20, 2017 6:29 am
Posts: 7
Korona wrote:
It's possible that your computers have a memory hole at or around 16 MiB. That can be the case even if they have large amounts (i.e. GiB range) of memory installed. ISA devices for example could not perform DMA to >= 16 MiB addresses and are sometimes mapped just below 16 MiB. The only way to be sure that there is physical memory at that (or any other) location is to check the BIOS.

I think the Memory Hole would perfectly explain this and was something that I failed to take into account, "and given that we are booted by GRUB it looks difficult to find the holes" - Scrap that, read into the multiboot structs more carefully and facepalmed as I realized it is all in there. Thank you so much for your help, I will let you know if this solves the issue - if it does, I owe you a beer.

LtG wrote:
Quote:
If I try this on VirtualBox (i386) with Hardware or Paravirtualization enabled, it doesn't write or read the value, but again, no GPF or Page Fault occur.


How do you know it doesn't write it? What happens instead?

As for what Korona mentioned, you basically have two choices if using BIOS (as opposed to UEFI which is different):
- Use GRUB or something
- BIOS E820 (http://wiki.osdev.org/Detecting_Memory_(x86)#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820)

By the looks of it, Qemu is saying that all four 4MiB virtual pages map to 0x0 physical?

In your memory dump "0x000030e3":
If I deciphered that correctly it would seem that that page is dirty, so you have written to it, which would be same thing "info tlb" is saying. You should probably also check what is actually loaded in CR3.. Qemu "info registers" might show it..

We write to the memory and then attempt to read back, the Dirty Flag and Accessed flag are both being set, but the data read back is all 0's.
We are being booted by GRUB.
As for the QEmu output: That's what we thought, but upon inspection that doesn't seem the case.


Last edited by t3hn3rd on Sat May 20, 2017 11:15 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Question Regarding Paging & Virtualization
PostPosted: Sat May 20, 2017 11:14 am 
Offline

Joined: Mon Sep 21, 2015 2:37 am
Posts: 4
Oh, well x86 is worse than I thought it was. Thanks guys!


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], SemrushBot [Bot] and 75 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