Grant tables
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
Signature · 3 lines
È molto più bello sapere qualcosa di tutto, che sapere tutto di una cosa. Blaise Pascal
Quoted 2 lines · 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
Samuel Thibault wrote, on the 04/04/2008 17.31:
Thanks, for the prompt answer.
Quoted 2 lines
See
tools/fs-back/fs-ops.cfor 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
Signature · 3 lines
È molto più bello sapere qualcosa di tutto, che sapere tutto di una cosa. Blaise Pascal
Quoted 7 lines · 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.
Quoted 2 lines
See
tools/fs-back/fs-ops.cfor instance (xc_gnttab* functions).Ok, so I found this:
Quoted 7 lines
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
Samuel Thibault wrote, on the 04/04/2008 23.42:
Quoted 6 lines
Quoted 2 lines
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?
Quoted 1 line
Samuel
Thanks,
Carlo
Signature · 3 lines
È molto più bello sapere qualcosa di tutto, che sapere tutto di una cosa. Blaise Pascal
Quoted 9 lines · Carlo Bertoldi, le Sat 05 Apr 2008 10:08:59 +0200, a écrit :
Samuel Thibault wrote, on the 04/04/2008 23.42:
Quoted 7 lines
Quoted 3 lines
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
Quoted 3 lines
Quoted 1 line
Quoted 1 line
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.
Quoted 4 lines
Quoted 2 lines
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
Signature · 1 line
Push Me Pull You - Distributed SCM tool (http://www.cl.cam.ac.uk/~maw48/pmpu/)
Mark Williamson wrote, on the 05/04/2008 23.14:
Quoted 2 lines
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 underdrivers/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?
Quoted 3 lines
hope that helps,
Cheers,
Mark
Thanks,
Carlo
Signature · 3 lines
È molto più bello sapere qualcosa di tutto, che sapere tutto di una cosa. Blaise Pascal
Quoted 25 lines · Carlo Bertoldi
Mark Williamson wrote, on the 05/04/2008 23.14:
Quoted 1 line
Take a look in the Xen Linux tree at the
drivers/xen/blkfront/forsome 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.Quoted 1 line
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"); } }
Quoted 1 line
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
Signature · 5 lines
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:[email protected] PGP Fingerprint: F5A4 1575 4C56 E26A 0B33 3D80 457E 82AE B0D8 735B