Hi, I need to use the grant table mechanism, but I can''t find any example regarding how to do it. Could you please provide some examples? Thanks Carlo -- È molto più bello sapere qualcosa di tutto, che sapere tutto di una cosa. Blaise Pascal _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Carlo Bertoldi, le Fri 04 Apr 2008 17:26:30 +0200, a écrit :> I need to use the grant table mechanism, but I can''t find any example > regarding how to do it. Could you please provide some examples?See tools/fs-back/fs-ops.c for instance (xc_gnttab* functions). Samuel _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Samuel Thibault wrote, on the 04/04/2008 17.31: Thanks, for the prompt answer. > See tools/fs-back/fs-ops.c for instance (xc_gnttab* functions). > Ok, so I found this: buf = xc_gnttab_map_grant_ref(mount->gnth, mount->dom_id, req->u.fwrite.gref, PROT_READ); it''s fine, except that I don''t understand how to obtain the gref. IOW how can I build a grant reference from a domain? Carlo -- È molto più bello sapere qualcosa di tutto, che sapere tutto di una cosa. Blaise Pascal _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Carlo Bertoldi, le Fri 04 Apr 2008 18:56:06 +0200, a écrit :> Samuel Thibault wrote, on the 04/04/2008 17.31: > > Thanks, for the prompt answer. > > See tools/fs-back/fs-ops.c for instance (xc_gnttab* functions). > > > Ok, so I found this: > > buf = xc_gnttab_map_grant_ref(mount->gnth, > mount->dom_id, > req->u.fwrite.gref, > PROT_READ); > > it''s fine, except that I don''t understand how to obtain the gref. IOW > how can I build a grant reference from a domain?To my knowledge, there is no user interface for that yet, you need to do it from the Linux kernel. Samuel _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Samuel Thibault wrote, on the 04/04/2008 23.42: >> >> it''s fine, except that I don''t understand how to obtain the gref. IOW how can I build a grant reference from a domain? > > To my knowledge, there is no user interface for that yet, you need to do > it from the Linux kernel. > I agree, can you provide some examples about that? > Samuel Thanks, Carlo -- È molto più bello sapere qualcosa di tutto, che sapere tutto di una cosa. Blaise Pascal _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Carlo Bertoldi, le Sat 05 Apr 2008 10:08:59 +0200, a écrit :> Samuel Thibault wrote, on the 04/04/2008 23.42: > >> > >>it''s fine, except that I don''t understand how to obtain the gref. IOW > >>how can I build a grant reference from a domain? > > > >To my knowledge, there is no user interface for that yet, you need to do > >it from the Linux kernel. > > > I agree, can you provide some examples about that?Look for gnttab_grant_foreign_access in linux/drivers/xen Samuel _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
> >> it''s fine, except that I don''t understand how to obtain the gref. > > IOW how can I build a grant reference from a domain?The idea is that the domain you''re mapping memory from will create a grant reference, then (somehow) tell your mapping code what that reference is. For the split front/back drivers, the frontend picks a page to be used for the communications ring, grants it to the backend domain, and puts the grant reference into XenStore so the backend can map that page. During IO, grant references can then be passed through the shared memory ring already established, which is more efficient. This is how most of the driver code does things under Xen.> > To my knowledge, there is no user interface for that yet, you need to do > > it from the Linux kernel. > > I agree, can you provide some examples about that?Take a look in the Xen Linux tree at the drivers/xen/blkfront/ for some creation of grant references. As Samuel says, searching for grant table functions under drivers/xen/ is going to find you some interesting examples in various places. hope that helps, Cheers, Mark -- Push Me Pull You - Distributed SCM tool (http://www.cl.cam.ac.uk/~maw48/pmpu/) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Mark Williamson wrote, on the 05/04/2008 23.14: > Take a look in the Xen Linux tree at the drivers/xen/blkfront/ for some creation of grant references. As Samuel says, searching for grant table functions under drivers/xen/ is going to find you some interesting examples in various places. > I studied the suggested code and I wrote something to test my understanding. It compiles and run fine, but I''ve got a problem: when I read the value of the shared structure it''s not right. This is the function, contained in a module, that creates the grant: static void offer_page() { int code; struct foo foo_struct; foo_struct.numero = 5; if ( ( code = gnttab_grant_foreign_access(0, virt_to_mfn(&foo_struct), 0)) == -1) { printk(KERN_INFO "grant error\n"); } } In userspace I use the following code to read the granted page: void grant(int xcg_handle, int domid) { struct foo *foo_struct; void *buf; int i; buf = xc_gnttab_map_grant_ref(xcg_handle, domid, 851, PROT_READ); // yes, ugly hardcoded value if (buf != NULL) { foo_struct = (struct foo *) buf; printf("numero = %d\n", foo_struct->numero); } } I''d expect it to print five, but it always write zero. What am I doing wrong here? > hope that helps, > Cheers, > Mark Thanks, Carlo -- È molto più bello sapere qualcosa di tutto, che sapere tutto di una cosa. Blaise Pascal _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On Mon, 2008-04-07 at 18:07 +0200, Carlo Bertoldi wrote:> Mark Williamson wrote, on the 05/04/2008 23.14: > > Take a look in the Xen Linux tree at the drivers/xen/blkfront/ for > some creation of grant references. As Samuel says, searching for grant > table functions under drivers/xen/ is going to find you some interesting > examples in various places. > > > I studied the suggested code and I wrote something to test my > understanding. It compiles and run fine, but I''ve got a problem: when I > read the value of the shared structure it''s not right. > > This is the function, contained in a module, that creates the grant: > > static void offer_page() > { > int code; > struct foo foo_struct; > > foo_struct.numero = 5; > > if ( ( code = gnttab_grant_foreign_access(0, > virt_to_mfn(&foo_struct), 0)) == -1) { > printk(KERN_INFO "grant error\n"); > } > } > > In userspace I use the following code to read the granted page:you''re granting a part of the kernel stack. the allocation of the memory block you''re using won''t survive subsequent return from the function. the granttab_-functions probably let you get away with it, but numero is likely to be overwritten shortly after executing the code above. allocate a whole frame (e.g. via get_free_page[s]()) and use that. remember to release it upon module unload. regards, daniel -- Daniel Stodden LRR - Lehrstuhl für Rechnertechnik und Rechnerorganisation Institut für Informatik der TU München D-85748 Garching http://www.lrr.in.tum.de/~stodden mailto:stodden@cs.tum.edu PGP Fingerprint: F5A4 1575 4C56 E26A 0B33 3D80 457E 82AE B0D8 735B _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel