All of lore.kernel.org
 help / color / mirror / Atom feed
* What's wrong on this mmap() ?
@ 2011-09-23 11:50 Andrea Gasparini
  2011-09-23 15:22 ` Gasparini Andrea
  0 siblings, 1 reply; 2+ messages in thread
From: Andrea Gasparini @ 2011-09-23 11:50 UTC (permalink / raw)
  To: kernelnewbies

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 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* What's wrong on this mmap() ?
  2011-09-23 11:50 What's wrong on this mmap() ? Andrea Gasparini
@ 2011-09-23 15:22 ` Gasparini Andrea
  0 siblings, 0 replies; 2+ messages in thread
From: Gasparini Andrea @ 2011-09-23 15:22 UTC (permalink / raw)
  To: kernelnewbies

Hi,

On Fri, Sep 23, 2011 at 1:50 PM, Andrea Gasparini <gaspa@yattaweb.it> wrote:
> 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.

Aerhm. If opened with  O_RDRW and mapped with MAP_SHARED it works as expected :)

Sorry for the silly question.
Bye!
--
- Andrea Gasparini -
-----------------------------------------------
-------- https://launchpad.net/~gaspa ---------
----- HomePage: http://gaspa.yattaweb.it ------

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-23 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-23 11:50 What's wrong on this mmap() ? Andrea Gasparini
2011-09-23 15:22 ` Gasparini Andrea

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.