From mboxrd@z Thu Jan 1 00:00:00 1970 From: gaspa@yattaweb.it (Andrea Gasparini) Date: Fri, 23 Sep 2011 13:50:08 +0200 Subject: What's wrong on this mmap() ? Message-ID: <201109231350.08326.gaspa@yattaweb.it> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org Hi, I'm having some problem understanding how mmap really works. I have a (dummy) driver that allocate some memory (4k), and gives it to a userspace through mmap() - the usual remap_pfn_pages found in every example. The userspace can read the memory correctly, but can't write to it. (though it maps with PROT_WRITE) As the manpage says: PROT_WRITE - Pages may be written. I'm attaching both the driver and the userspace testbed, with the hope someone tells me what's wrong with this. Note that I tested on ARM and x86 architectures, and different kernel, so It seems more likely a fault of mine, that a kernel strangeness. (obviusly, you'll say... :P ) The userspace log are something like that: Base userspace address for mmapped buffer is 0xb7786000 Wrote 00 in user-space 0xb7786000. Reading from it seems 00 Wrote 01 in user-space 0xb7786001. Reading from it seems 01 Wrote 02 in user-space 0xb7786002. Reading from it seems 02 [ .... snip ... ] While the kernel are: allocated: 4096 @virt: c7000000 @phys: 8c800000 virtToPhys(): 87000000 mmap worked. vmaflasg: 40184477 phys: 87000000 virt: c7000000 VMA open: vma->vm_start: 40236000 - vma->pgoffs: 87000 - vma->vm_end: 40237000, vma_flags: 40184477 VMA close: vma->vm_start: 40236000 - vma->pgoffs: 87000 - vma->vm_end: 40237000, vma_flags: 40184477 00 ff fe fd fc fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef ee ed ec eb ea e9 e8 e7 e6 e5 e4 e3 e2 e1 Regards, bye! -- - Andrea Gasparini - ----------------------------------------------- -------- https://launchpad.net/~gaspa --------- ----- HomePage: http://gaspa.yattaweb.it ------ -------------- next part -------------- A non-text attachment was scrubbed... Name: mmap_testbed.c Type: text/x-csrc Size: 3288 bytes Desc: not available Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110923/cb7fc648/attachment.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: mmap_test.c Type: text/x-csrc Size: 4477 bytes Desc: not available Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110923/cb7fc648/attachment-0001.bin