From: Daniel Stodden Subject: Re: Grant tables Date: Mon, 07 Apr 2008 18:18:23 +0200 Message-ID: <1207585103.13737.8.camel@thinkpad.localdomain> References: <47F648A6.3000104@tiscali.it> <20080404214240.GE4014@implementation> <47F73411.6010705@tiscali.it> <200804052214.02300.mark.williamson@cl.cam.ac.uk> <47FA46B8.8050206@tiscali.it> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <47FA46B8.8050206@tiscali.it> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Carlo Bertoldi Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org 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=20 > some creation of grant references. As Samuel says, searching for grant= =20 > table functions under drivers/xen/ is going to find you some interestin= g=20 > examples in various places. > > > I studied the suggested code and I wrote something to test my=20 > understanding. It compiles and run fine, but I've got a problem: when I= =20 > read the value of the shared structure it's not right. >=20 > This is the function, contained in a module, that creates the grant: >=20 > static void offer_page() > { > int code; > struct foo foo_struct; >=20 > foo_struct.numero =3D 5; >=20 > if ( ( code =3D gnttab_grant_foreign_access(0,=20 > virt_to_mfn(&foo_struct), 0)) =3D=3D -1) { > printk(KERN_INFO "grant error\n"); > } > } >=20 > 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 --=20 Daniel Stodden LRR - Lehrstuhl f=C3=BCr Rechnertechnik und Rechnerorganisation Institut f=C3=BCr Informatik der TU M=C3=BCnchen D-85748 Garc= hing http://www.lrr.in.tum.de/~stodden mailto:stodden@cs.tum.edu PGP Fingerprint: F5A4 1575 4C56 E26A 0B33 3D80 457E 82AE B0D8 735B