Re: Using /dev/mem to access memory allocated with kmalloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just a follow up:

I tried reading the address with lseek and read and it works correctly! But when I use mmap it stops working. I tried mmaping a regular file to make sure I was using mmap correctly. It seemed to work fine. I get consistent non-mmaped/mmaped read results with the regular file, just not with /dev/mem!

What could be wrong?

Marek

Marek Olszewski wrote:

Hello, I'm doing a little project that investigates the benefits of using the new (seemingly only accessible from privileged code) x86 SSE3 monitor/mwait instructions for locks on hyperthreaded machines.

To get this to work, I need to allocate some contiguous memory in kernel space that is memory mapped to some address range in a userspace app. For now, I'm just trying to get this to work by mmaping /dev/mem. I use virt_to_phys on a kmalloced address and return it to my user app via a syscall. I then try to mmap /dev/mem in my user app at an offset of the returned address. The memory mapping seems to succeed, but when I check the contents of the address (which I wrote to in kernel space), I don't get a match. Is there some /dev/mem file location-to-physical memory address mapping that I am not aware of? man mem says that they are the same.

I also tried returning a kernel address and mapping /dev/kmem. In this case mmap doesn't even succeed.
Any ideas?

I'm running debian testing with linux 2.6.12.1

Also, I'm aware that mmap requires a page aligned offset. I take care of this in all of my tests by mmaping memory at the first offset that is page aligned preceding my desired address/offset.

Thanks in advance,

Marek

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux