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/
Home Products Support Community News


[Xen-devel] How to share a page between dom0 and Hypervisror

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] How to share a page between dom0 and Hypervisror
From: veerasena reddy <veeruyours@xxxxxxxxx>
Date: Mon, 6 Jun 2011 18:58:46 +0530
Delivery-date: Mon, 06 Jun 2011 06:31:08 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=H14R3gGMDmVDCD1x+OIjdgdN0gMKzDz5SM8q2Jza8K4=; b=MO1IsPY7CqPLpCPnILf9eC0ECfJtNXu8KKh5ZE2Me+xGsc3HIqGKxIrcBfrGV9oJQU kTQJq60ZZWmMbvZgC9S46AM72OQt/9ouq/XH+hOGmfeUe+bOULr5bC9rDShQpbX336uZ cW9EBYM6G2bgrnf3cfZuCiYcuClWkEi9vlN90=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=So/YPr+24zjv0cgp6UvfXBQNrBKNTnnm6HWUF+ceznY9PXpY8RvJShsXD4zNXWFsDn NayRWxDwU4JWoQmOuLsbyKR7YXVN8l7LriaT+IwXPICuBngwMPH0Yj+1wgLqnfyb5XAL IFOdC8/+HQmy2IXy9dcMK+THIxGvZyj3kPtbU=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
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/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx

In one of experiments, I need to map a page allocated in dom0 to hypervisor and access/modify the page contents in hypervisor.
I tried this by adding a new hypercall, and pass the GPA of the page to its handler in hypervisor which does the following:

==================== Hypercall handler  ================
DO(my_rd_wr)(int cmd, XEN_GUEST_HANDLE(void) arg)
        unsigned long dom0_gpa;
        unsigned long gmfn;
        unsigned long mfn;
        void *my_rd_wr_page;
        struct domain *d = current->domain;

        printk(XENLOG_G_DEBUG "%s:L%u: Entered\n", __FUNCTION__, __LINE__);
        switch( cmd )
                case 0x1:
                        if ( copy_from_guest(&dom0_gpa, arg, 1) )
                                return -EFAULT;
                        printk(XENLOG_G_DEBUG "%s:L%u: GPA read 0x%lx\n",
                                                __FUNCTION__, __LINE__, dom0_gpa);

                        gmfn = dom0_gpa >> 12;
                        mfn = gmfn_to_mfn(d, gmfn);
                        if ( !mfn_valid(mfn) ||
                             !get_page_and_type(mfn_to_page(mfn), d, PGT_writable_page) )
                                        "Bad GMFN %lx (MFN %lx)\n", gmfn, mfn);
                                return 0;
                        my_rd_wr_page = map_domain_page(mfn);

                        /* Do your initialization of the page here; just write '2' in all bytes */
                        memset(my_rd_wr_page, 2, 1<<12);

                        printk(XENLOG_G_DEBUG "%s:L%u: unhandled\n",
                                                __FUNCTION__, __LINE__);

        return 0;

I have allocated a page from a sample dom0 kernel module (using vmalloc()), and passed the physical address of it to hypercall.

void my_rd_wr_page_setup(void)
    unsigned long my_gpa;
    int err;
    char *my_rd_wr_page = NULL;

    my_rd_wr_page     = __vmalloc(
                        1 * PAGE_SIZE,
                        GFP_KERNEL | __GFP_HIGHMEM,
                        __pgprot(__PAGE_KERNEL & ~_PAGE_NX));

    my_gpa = vmalloc_to_pfn((char *)&my_rd_wr_page) << PAGE_SHIFT;
    printk("%s: Before Hypercall; my_rd_wr_page=%p my_gpa=%lx\n", __FUNCTION__, my_rd_wr_page, my_gpa);
    memset(my_rd_wr_page, 0, PAGE_SIZE);
    err = _hypercall2(int, my_rd_wr, 0x1, (void *)&my_gpa);
    printk("%s: Hypercall returned; errno-%d\n", __FUNCTION__, err);

When I loaded the module, the following error has been observed:

=============== On dom0 ===========
xen_features[0].writable_page_tables = 0
xen_features[0].writable_descriptor_tables = 0
xen_features[0].auto_translated_physmap = 0
xen_features[0].supervisor_mode_kernel = 0
xen_features[0].pae_pgdir_above_4gb = 1
my_rd_wr_page_setup: Before Hypercall; my_rd_wr_page=ffffc90010f7e000 my_gpa=d7cf000
my_rd_wr_page_setup: Hypercall returned; errno-0
On hypervisor:
(XEN) do_my_rd_wr:L178: GPA read 0xd7cf000
(XEN) mm.c:2037:d0 Error pfn d7cf: rd=ffff8300773c0000, od=0000000000000000, caf=180000000000000, taf=0000000000000000
(XEN) Bad GMFN d7cf (MFN d7cf)

From the dom0 messages (where i read the features), it looks like writable_page_tables is not set. Is it causing the issue in my case.

Could you please advice if i did something wrong here.
You are most welcome if you have completely different approach which works;

Thanks a lot in advance

Xen-devel mailing list
<Prev in Thread] Current Thread [Next in Thread>