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

[Xen-users] How to get the PFN of a vmalloc'ed address in a domU ?



Hello,

I've mapped granted pages in a module inserted in a domU and I'm trying to get the PFN or the struct page * of these pages to map them in the user space :

Mapping granted pages (that's xensocket's code) :

if (!(x->buffer_area = alloc_vm_area(buffer_num_pages * PAGE_SIZE, NULL))) {
    DPRINTK("error: cannot allocate %d buffer pages\n", buffer_num_pages);
    goto err_unmap;
}

x->buffer_addr = (unsigned long)x->buffer_area->addr;

grefp = &d->buffer_first_gref;
for (i = 0; i < buffer_num_pages; i++) {
printk(KERN_INFO "Mounting GREF %d\n", *grefp);
    memset(&op, 0, sizeof(op));
    op.host_addr = x->buffer_addr + i * PAGE_SIZE;
    op.flags = GNTMAP_host_map;
    op.ref = *grefp;
    op.dom = x->otherend_id;

    rc = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
    if (rc == -ENOSYS) {
        goto err_unmap;
    }

    if (op.status) {
        DPRINTK("error: grant table mapping failed\n");
        goto err_unmap;
    }

    x->buffer_handles[i] = op.handle;
    grefp = (int *)(x->buffer_addr + i * PAGE_SIZE);
}

The mapping is successful. I then try to get a reference to these pages :

if(is_vmalloc_addr((void *)(x->buffer_addr+recv_offset*PAGE_SIZE)))
    printk(KERN_INFO "Is vmalloc addr\n"); // As this text is displayed, I verified it's a vmalloc'ed page
if(virt_addr_valid((void *)(x->buffer_addr+recv_offset*PAGE_SIZE)))
    printk(KERN_INFO "Is virt addr\n");

unsigned long pfn = vmalloc_to_pfn((void *)(x->buffer_addr+recv_offset*PAGE_SIZE));
printk(KERN_INFO "PFN 1 : %lu\n", pfn); // The returned PFN is "0", it's therefore useless
if(pfn_valid(pfn)){
    printk(KERN_INFO "PFN 1 est valide\n");
}
struct page * shPage = vmalloc_to_page((void *)(x->buffer_addr+recv_offset*PAGE_SIZE));
if(!page_count(shPage)){
    printk(KERN_INFO "Error in page_count\n"); // I get a page, but the function page_count fails
}

I also tried to apply the operation >> PAGE_SHIFT to "manually" get the PFN but the PFN I get is not a valid PFN.

Does someone please know how to get the PFN or the struct page * from a vmalloc'ed address in a domU ?

Thank you,

Best regards,

Sebastien Fremal
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxx
http://lists.xen.org/xen-users

 


Rackspace

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