Page 1 of 1

virtual memory problem

Posted: Thu Sep 15, 2016 2:23 pm
by stdcall
I have a very strange behavior that doesn't make sense to me.
I'm writing a value to a virtual memory location I just mapped, and the value doesn't stick.
when I read back I get 0.

I assume that there's no issues with the paging setup, as I would expect a page fault to occur, I just can find a reason why this could happen.

Can you think of a possible bug/issue I have that can cause this ?

Configuration: x86 32 bit kernel running on qemu. paging enabled, without PAE.

The code for reference:

Code: Select all

printk("value before: %x\r\n", physmem.bitmap[0]);
physmem.bitmap[0] = 0xFF;
printk("value after: %x\r\n", physmem.bitmap[0]);
What I already tested:
* printk is ok, GDB also shows 0 in the memory.

Re: virtual memory problem

Posted: Thu Sep 15, 2016 3:44 pm
by Ch4ozz
You should declare your map as volatile and turn off optimizations to make sure its executed in the right order and compiler doesnt store the value in a register.
Does it work without paging?

Re: virtual memory problem

Posted: Thu Sep 15, 2016 11:39 pm
by stdcall
Ch4ozz wrote:You should declare your map as volatile and turn off optimizations to make sure its executed in the right order and compiler doesnt store the value in a register.
Does it work without paging?
I'm building without optimization.
The assembly code looks good. I singled stepped it. It writes to memory.

Re: virtual memory problem

Posted: Fri Sep 16, 2016 2:26 am
by jnc100
What is the physical address of the page you have mapped and are trying to write to? Are you trying to write to non-existant memory or a device rather than RAM?

Regards,
John.

Re: virtual memory problem

Posted: Fri Sep 16, 2016 2:31 am
by Velko
Check the address of physical page virtual location is mapped to. AFAIK MMU does not check if physical memory at mapped location exists, so there will be no page fault.

Re: virtual memory problem

Posted: Fri Sep 16, 2016 4:24 am
by stdcall
Velko wrote:Check the address of physical page virtual location is mapped to. AFAIK MMU does not check if physical memory at mapped location exists, so there will be no page fault.
Yep. that was the problem.... damn.