From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiaofeng Ling Subject: [PATCH][6/6] setup grant table share page for vmx guest Date: Mon, 05 Sep 2005 18:41:54 +0800 Message-ID: <431C20F2.50909@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Pratt , Keir Fraser Cc: xen-devel List-Id: xen-devel@lists.xenproject.org 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 Signed-off-by: Arun Sharma 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<