WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] Grant tables

To: Carlo Bertoldi <mcbain@xxxxxxxxxx>
Subject: Re: [Xen-devel] Grant tables
From: Daniel Stodden <stodden@xxxxxxxxxx>
Date: Mon, 07 Apr 2008 18:18:23 +0200
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Mon, 07 Apr 2008 09:18:57 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <47FA46B8.8050206@xxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: Fakultät für Informatik I10, Technische Universität München
References: <47F648A6.3000104@xxxxxxxxxx> <20080404214240.GE4014@implementation> <47F73411.6010705@xxxxxxxxxx> <200804052214.02300.mark.williamson@xxxxxxxxxxxx> <47FA46B8.8050206@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxx
PGP Fingerprint: F5A4 1575 4C56 E26A 0B33  3D80 457E 82AE B0D8 735B



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>