[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] How to map memory by grant table.


  • To: xen-devel@xxxxxxxxxxxxx
  • From: 夏业添 <summerxyt@xxxxxxxxx>
  • Date: Wed, 18 Apr 2012 17:56:12 +0800
  • Delivery-date: Wed, 18 Apr 2012 09:56:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>

Hi everyone,

I know it's not a place for technical support queries, but I really need some help on how to use grant table.

My goal to use grant table to transfer data by shared memory, and now want to only share only one page. I try to learn how to use it by checking aseemsethi's instruction and gntdev.c. Although the sender seems OK, the reciever cannot map memory by gref, and the ops.status always returns  -1, meaning undefined error.

I‘m totally confused about this. I guess it might due to memory-allocating, but perhaps not. Could someone give some hints to me? Thanks!

Here is part of my code.

In the sender:
static int server_alloc_one_page_to_
grant(unsigned long* mypage,domid_t rdom){
        unsigned long addr=0;
       
        gref=-1; //gref is globle
        addr=get_zeroed_page(GFP_KERNEL);
        if(addr==0){
                printk("cannot alloc page\n");
        }

        sprintf((char*)addr,"%s\naaa\n","This is in sender.");

        gref=gnttab_grant_foreign_access(rdom,virt_to_mfn(addr),1);      
        if(gref<0){
                 free_page(addr);
        }

        printk("gref:%d\n",gref);
        return gref;
}

and it seems works well.

But in reciver:
static int client_map_page(domid_t rdom,grant_ref_t ref,struct vm_struct** pvm){
  struct vm_struct *v_start;
  struct gnttab_map_grant_ref ops;
  struct gnttab_unmap_grant_ref unmap_ops;

  memset(&ops,0,sizeof(ops));
  memset(&ops,0,sizeof(unmap_ops));
  v_start=alloc_vm_area(PAGE_SIZE,NULL);
  if(v_start==0){
    printk("could not allocate page in client.\n");
    return -1;
  }

  /***************************things goes wrong ************************************************/
  gnttab_set_map_op(&ops,(unsigned long)v_start->addr,GNTMAP_host_map,ref,rdom);
  if(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,&ops,1)){
    free_vm_area(v_start);
    printk("\nHYPERVISOR map grant ref failed\n");
    return -1;
  }
   //ops,status always equals to -1, and map failed
  if(ops.status){   
    printk("xen:HYPERVISOR map grant ref failed status=%d",ops.status);
    free_vm_area(v_start);
    return -1;
  }

  /*access memory by v_start->addr and unmap memory*/
  ...
}
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.