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

[Xen-devel] [PATCH][6/6] setup grant table share page for vmx guest

To: Ian Pratt <m+Ian.Pratt@xxxxxxxxxxxx>, Keir Fraser <Keir.Fraser@xxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH][6/6] setup grant table share page for vmx guest
From: Xiaofeng Ling <xiaofeng.ling@xxxxxxxxx>
Date: Mon, 05 Sep 2005 18:41:54 +0800
Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Mon, 05 Sep 2005 10:43:33 +0000
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/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>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040510
Setup grant table share page for vmx guest.
Unmodified linux can not use fix map to setup the grant table
share page. This patch put the grant table share page into
the guest phys_to_machine mapping, so that guest can use ioremap
to access these pages. The guest physical address is passed from
guest and it is in the event channel pci device mmio space.
By this way, no extra hypercall needed.

Signed-off-by: Xiaofeng Ling <xiaofeng.ling@xxxxxxxxx>
Signed-off-by: Arun Sharma <arun.sharma@xxxxxxxxx>

diff -r 287d36b46fa3 xen/common/grant_table.c
--- a/xen/common/grant_table.c  Tue Aug 30 20:36:49 2005
+++ b/xen/common/grant_table.c  Fri Sep  2 22:46:13 2005
@@ -693,11 +693,30 @@
     if ( op.nr_frames <= NR_GRANT_FRAMES )
     {
         ASSERT(d->grant_table != NULL);
-        (void)put_user(GNTST_okay, &uop->status);
-        for ( i = 0; i < op.nr_frames; i++ )
+        if(!shadow_mode_external(current->domain))
+        {
+            (void)put_user(GNTST_okay, &uop->status);
+            for ( i = 0; i < op.nr_frames; i++ )
             (void)put_user(
                 (virt_to_phys(d->grant_table->shared) >> PAGE_SHIFT) + i,
                 &uop->frame_list[i]);
+        }
+        else
+        {
+            unsigned long mfn, gpa;
+            op.status = GNTST_okay;
+
+            gpa = (unsigned long)op.frame_list;
+            for ( i = 0; i < op.nr_frames; i++ )
+            {
+                mfn = (virt_to_phys(d->grant_table->shared) >> PAGE_SHIFT)
+                       + i,
+                DPRINTK("gpa:%lx share mfn:%lx\n", gpa, mfn);
+                set_phystomachine(gpa >> PAGE_SHIFT, mfn);
+                gpa = gpa + PAGE_SIZE;
+            }
+            (void)copy_to_user(uop, &op, sizeof(op));
+        }
     }

     put_domain(d);
diff -r 287d36b46fa3 xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Tue Aug 30 20:36:49 2005
+++ b/xen/arch/x86/mm.c Fri Sep  2 22:46:13 2005
@@ -3454,6 +3454,50 @@
     map_pages_to_xen(fix_to_virt(idx), p >> PAGE_SHIFT, 1, flags);
 }

+#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
+unsigned long add_new_p2m_page(unsigned long phys)
+{
+    l2_pgentry_t mpl2e;
+    l1_pgentry_t *vl2tab;
+    struct vcpu *v = current;
+    struct pfn_info *newpg;
+
+    mpl2e = v->arch.monitor_vtable[l2_table_offset(RO_MPT_VIRT_START)];
+    vl2tab = map_domain_page(l2e_get_pfn(mpl2e));
+    v->domain->max_pages++;
+    newpg = alloc_domheap_page(v->domain);
+    if(!newpg)
+    {
+        MEM_LOG("alloc_domheap_page fail\n");
+        return 0;
+    }
+ vl2tab[l2_table_offset(phys)] = l1e_from_paddr(page_to_phys(newpg), L2_PROT);
+    unmap_domain_page(vl2tab);
+    return page_to_phys(newpg);
+}
+
+unsigned long set_phystomachine(unsigned long pfn,
+                                              unsigned long mfn)
+{
+    l1_pgentry_t pte;
+    unsigned long oldmfn;
+
+    if (__copy_from_user(&pte, (phys_to_machine_mapping + pfn),
+                        sizeof(pte))) {
+        if(!add_new_p2m_page(pfn<<PAGE_SHIFT))
+            return INVALID_MFN;
+    }
+
+    oldmfn = l1e_get_pfn(pte);
+    pte = l1e_from_pfn(mfn, l1e_get_flags(pte)|_PAGE_PRESENT);
+
+    if(__copy_to_user((phys_to_machine_mapping + pfn), &pte, sizeof(pte)))
+        return INVALID_MFN;
+
+    return oldmfn;
+}
+
 #ifdef MEMORY_GUARD

 void memguard_init(void)
diff -r 287d36b46fa3 xen/include/asm-x86/mm.h
--- a/xen/include/asm-x86/mm.h  Tue Aug 30 20:36:49 2005
+++ b/xen/include/asm-x86/mm.h  Fri Sep  2 22:46:13 2005
@@ -289,6 +289,9 @@
     return mfn;
 }

+unsigned long set_phystomachine(unsigned long pfn,
+                                unsigned long mfn);
+
 #ifdef MEMORY_GUARD
 void memguard_init(void);
 void memguard_guard_range(void *p, unsigned long l);

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH][6/6] setup grant table share page for vmx guest, Xiaofeng Ling <=