#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    8
    Rep Power
    0

    Tricky : how to put the same page twice in the same address range


    Hello,

    What I'm trying to do is a little tricky. I want to implement a shared buffer ring with page sharing. It means I share a page between 2 processes and this page is used has the buffer of a buffer ring. I try to use the trick introduced by Michael Tyson, Philip Howard and Kurt Davis : "virtual copy of the buffer is inserted directly after the end of the buffer, so that you can write past the end of the buffer, but have your writes automatically wrapped around to the start". The goal is to get an address range in the virtual memory which size is twice the size of a page (the buffer in my case). Then I put my page twice in this address range so there is twice the same data in the address range. All that is really tricky and hard to understand, I hope I did no mistake.

    I was wondering if someone knew which functions I have to use to do that ? From the user space, I need to allocate a page and to map it twice in an address range. I thank you for your help.

    Best regards.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,407
    Rep Power
    1871
    Well it would be a lot easier if you told us which OS/Compiler you're using, so we could suggest which API to use.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    8
    Rep Power
    0
    Oh yes, sorry, long day. I use Linux (Ubuntu) and the Gnu compiler (gcc). I think I have to allocate a virtual memory area and then put the page twice in it, but I don't understand how to do that.

    I have an idea on how to do it by creating a module which allocates the page and implements the mmap function, but I would like to avoid working in the kernel space if possible.
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,407
    Rep Power
    1871
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    8
    Rep Power
    0
    Thanks, I knew how shared memory work, but I'm not trying to share data between processes but between virtual machines (that's why I need to work with pages). I know how to do that stuff with a module in the kernel space, but I would like to try another solution, if it exists.
  10. #6
  11. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,407
    Rep Power
    1871
    > but I'm not trying to share data between processes but between virtual machines (that's why I need to work with pages)
    Perhaps you should have been more open about your intentions in the first instance.

    Next question, what is your virtualisation solution?

    The whole point about a VM is that it is very well sand-boxed away from other VM's. Assuming that this is at all possible, it represents a gaping security hole IMO.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    8
    Rep Power
    0
    Sorry, I'm using Xen and several domU's must access to a device connected on the PCI port. As only one machine at a time can access the PCI port, I built a server running on dom0 to receive and execute requests on the device.

    I'm building a ring buffer to transfer data and requests without copy between the domU's and the dom0. I know sharing page can be a security breach, but I've got no other choices.

    I think that what I'm willing to do is not possible in the user space, I will write a module to allocate pages and mmaping them in the processus.

    Thanks for your help.

IMN logo majestic logo threadwatch logo seochat tools logo