* Capturing all writes as fault on a memory mapped page.
@ 2014-05-28 13:17 Pranay Srivastava
2014-05-28 13:29 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: Pranay Srivastava @ 2014-05-28 13:17 UTC (permalink / raw)
To: kernelnewbies
Hi
I need to capture all writes on page which is memory mapped by the
user program. I've tried setting the vm_page_prot by disabling the
VM_WRITE flag but even then the page fault occurs only once during the
first write. VM_SHARED is set to stop COW in the __do_fault.
I was also trying to set_memory_ro(this may not be available for all
archs?) however I can't do that while handling the fault since the
page table entries are created later after the
vm_operations_struct->fault has installed the page for the fault.
I'm not having any clues on how to do this. Any help would be really
helpful on this.
Thanks
--
---P.K.S
^ permalink raw reply [flat|nested] 5+ messages in thread
* Capturing all writes as fault on a memory mapped page.
2014-05-28 13:17 Capturing all writes as fault on a memory mapped page Pranay Srivastava
@ 2014-05-28 13:29 ` Greg KH
2014-05-28 13:43 ` Pranay Srivastava
0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2014-05-28 13:29 UTC (permalink / raw)
To: kernelnewbies
On Wed, May 28, 2014 at 06:47:24PM +0530, Pranay Srivastava wrote:
> Hi
>
> I need to capture all writes on page which is memory mapped by the
> user program.
For what and what are you going to do with them once you "capture" them?
Are you trying to capture them in the kernel or in userspace?
> I've tried setting the vm_page_prot by disabling the
> VM_WRITE flag but even then the page fault occurs only once during the
> first write. VM_SHARED is set to stop COW in the __do_fault.
>
> I was also trying to set_memory_ro(this may not be available for all
> archs?) however I can't do that while handling the fault since the
> page table entries are created later after the
> vm_operations_struct->fault has installed the page for the fault.
>
> I'm not having any clues on how to do this. Any help would be really
> helpful on this.
I don't think this is going to be possible, sorry, please go revisit
the reason you think you want to do this.
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Capturing all writes as fault on a memory mapped page.
2014-05-28 13:29 ` Greg KH
@ 2014-05-28 13:43 ` Pranay Srivastava
2014-05-28 14:25 ` Greg KH
0 siblings, 1 reply; 5+ messages in thread
From: Pranay Srivastava @ 2014-05-28 13:43 UTC (permalink / raw)
To: kernelnewbies
On 5/28/14, Greg KH <greg@kroah.com> wrote:
> On Wed, May 28, 2014 at 06:47:24PM +0530, Pranay Srivastava wrote:
>> Hi
>>
>> I need to capture all writes on page which is memory mapped by the
>> user program.
>
> For what and what are you going to do with them once you "capture" them?
>
This is just as an exercise nothing in specific. Currently what I've
is a misc_device having a page of memory. I've made it available
through mmap to user space programs(again this is just an exercise).
> Are you trying to capture them in the kernel or in userspace?
So after a user space program has done mmap of this page to its
address space, I wanted the writes to be captured. Now if i don't set
the VM_WRITE in vm_flags then __do_fault sends sends the SEGV and if I
do set it then I'm able to get the first fault (read or write access).
>
>> I've tried setting the vm_page_prot by disabling the
>> VM_WRITE flag but even then the page fault occurs only once during the
>> first write. VM_SHARED is set to stop COW in the __do_fault.
>>
>> I was also trying to set_memory_ro(this may not be available for all
>> archs?) however I can't do that while handling the fault since the
>> page table entries are created later after the
>> vm_operations_struct->fault has installed the page for the fault.
>>
>> I'm not having any clues on how to do this. Any help would be really
>> helpful on this.
>
> I don't think this is going to be possible, sorry, please go revisit
> the reason you think you want to do this.
>
> greg k-h
>
Actually trying to do something like if there's a write being done on
the page by a task currently then other tasks should wait( was hoping
that the fault handler code would be called for write but doesn't
happen that way).
Yes through write operation I can do with mutex but I was wondering
what if this has to be done through mmap of my misc_device then no
read/write calls involved so just wanted to see how would I stop
multiple writes to my misc_device.
Perhaps there are other methods as to how device memory can be mapped
to user space? or they aren't at all? Not really sure just reading and
trying.
--
---P.K.S
^ permalink raw reply [flat|nested] 5+ messages in thread
* Capturing all writes as fault on a memory mapped page.
2014-05-28 13:43 ` Pranay Srivastava
@ 2014-05-28 14:25 ` Greg KH
2014-05-28 14:38 ` Pranay Srivastava
0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2014-05-28 14:25 UTC (permalink / raw)
To: kernelnewbies
On Wed, May 28, 2014 at 07:13:55PM +0530, Pranay Srivastava wrote:
> Actually trying to do something like if there's a write being done on
> the page by a task currently then other tasks should wait( was hoping
> that the fault handler code would be called for write but doesn't
> happen that way).
If you have multiple writers on the same page, why would you want any
other writer to wait? That's the joy of mmap, you don't have to worry
about any of this from userspace, the kernel backing store handles it
all for you automatically.
> Yes through write operation I can do with mutex but I was wondering
> what if this has to be done through mmap of my misc_device then no
> read/write calls involved so just wanted to see how would I stop
> multiple writes to my misc_device.
Either you don't allow multiple opens, or you just live with the mess
that userspace is wanting to do here.
> Perhaps there are other methods as to how device memory can be mapped
> to user space? or they aren't at all? Not really sure just reading and
> trying.
As you mapped it to userspace, it's now up to the user to deal with any
serialization that it wants to enforce, it's out of the hands of your
misc driver.
good luck,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Capturing all writes as fault on a memory mapped page.
2014-05-28 14:25 ` Greg KH
@ 2014-05-28 14:38 ` Pranay Srivastava
0 siblings, 0 replies; 5+ messages in thread
From: Pranay Srivastava @ 2014-05-28 14:38 UTC (permalink / raw)
To: kernelnewbies
On 5/28/14, Greg KH <greg@kroah.com> wrote:
> On Wed, May 28, 2014 at 07:13:55PM +0530, Pranay Srivastava wrote:
>> Actually trying to do something like if there's a write being done on
>> the page by a task currently then other tasks should wait( was hoping
>> that the fault handler code would be called for write but doesn't
>> happen that way).
>
> If you have multiple writers on the same page, why would you want any
> other writer to wait? That's the joy of mmap, you don't have to worry
> about any of this from userspace, the kernel backing store handles it
> all for you automatically.
>
>> Yes through write operation I can do with mutex but I was wondering
>> what if this has to be done through mmap of my misc_device then no
>> read/write calls involved so just wanted to see how would I stop
>> multiple writes to my misc_device.
>
> Either you don't allow multiple opens, or you just live with the mess
> that userspace is wanting to do here.
>
>> Perhaps there are other methods as to how device memory can be mapped
>> to user space? or they aren't at all? Not really sure just reading and
>> trying.
>
> As you mapped it to userspace, it's now up to the user to deal with any
> serialization that it wants to enforce, it's out of the hands of your
> misc driver.
>
Thanks a lot.
> good luck,
>
> greg k-h
>
--
---P.K.S
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-28 14:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-28 13:17 Capturing all writes as fault on a memory mapped page Pranay Srivastava
2014-05-28 13:29 ` Greg KH
2014-05-28 13:43 ` Pranay Srivastava
2014-05-28 14:25 ` Greg KH
2014-05-28 14:38 ` Pranay Srivastava
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).