: PVH mmu changes
Subsystems (3)
PATCH 2/8 : PVH mmu changes
--- arch/x86/xen/mmu.c | 180 +++++++++++++++++++++++++++++++++++++++++++++++-- arch/x86/xen/mmu.h | 2 + include/xen/xen-ops.h | 12 +++- 3 files changed, 188 insertions(+), 6 deletions(-)
arch/x86/xen/mmu.c +175 -5
@@ -73,6 +73,7 @@#include <xen/interface/version.h> #include <xen/interface/memory.h> #include <xen/hvc-console.h> +#include <xen/balloon.h> #include "multicalls.h" #include "mmu.h"
@@ -330,6 +331,26 @@ static void xen_set_pte(pte_t *ptep, pte_t pteval)__xen_set_pte (ptep, pteval); } +void xen_set_clr_mmio_pvh_pte (unsigned long pfn,unsigned long mfn, +int nr_mfns,int add_mapping) +{ +struct physdev_map_iomem iomem; + + iomem.first_gfn = pfn; + iomem.first_mfn = mfn; + iomem.nr_mfns = nr_mfns; + iomem.add_mapping = add_mapping; + +if (HYPERVISOR_physdev_op (PHYSDEVOP_pvh_map_iomem, &iomem)) +BUG (); +} + +static void xen_dom0pvh_set_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval) +{ +native_set_pte (ptep, pteval); +} +static void xen_set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval) {
@@ -1197,6 +1218,10 @@ static void xen_post_allocator_init(void);static void __init xen_pagetable_setup_done (pgd_t *base) {xen_setup_shared_info (); + +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +xen_post_allocator_init (); }
@@ -1455,6 +1480,10 @@ static void __init xen_set_pte_init(pte_t *ptep, pte_t pte)static void pin_pagetable_pfn (unsigned cmd,unsigned long pfn) {struct mmuext_op op; + +if (xen_feature (XENFEAT_writable_page_tables)) +return ; + op.cmd = cmd; op.arg1.mfn =pfn_to_mfn (pfn);if (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF ))
@@ -1652,6 +1681,10 @@ static void set_page_prot(void *addr, pgprot_t prot)unsigned long pfn =__pa (addr) >>PAGE_SHIFT ;pte_t pte =pfn_pte (pfn, prot); +/* recall for PVH, page tables are native. */ +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +if (HYPERVISOR_update_va_mapping ((unsigned long )addr, pte,0 ))BUG (); }
@@ -1729,6 +1762,9 @@ static void convert_pfn_mfn(void *v)pte_t *pte = v;int i; +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +/* All levels are converted the same way, so just treat them as ptes. */ for (i =0 ; i <PTRS_PER_PTE ; i++)
@@ -1745,6 +1781,7 @@ static void convert_pfn_mfn(void *v)* but that's enough to get __va working. We need to fill in the rest * of the physical mapping once some sort of allocator has been set * up. +* NOTE: for PVH, the page tables are native. */ pgd_t *__init xen_setup_kernel_pagetable (pgd_t *pgd,unsigned long max_pfn)
@@ -1802,9 +1839,13 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,* structure to attach it to, so make sure we just set kernel * pgd. */ -xen_mc_batch (); -__xen_write_cr3 (true,__pa (pgd)); -xen_mc_issue (PARAVIRT_LAZY_CPU ); +if (xen_feature (XENFEAT_writable_page_tables)) { +native_write_cr3 (__pa (pgd)); + }else { +xen_mc_batch (); +__xen_write_cr3 (true,__pa (pgd)); +xen_mc_issue (PARAVIRT_LAZY_CPU ); + }memblock_reserve (__pa (xen_start_info->pt_base), xen_start_info->nr_pt_frames *PAGE_SIZE );
@@ -2067,9 +2108,21 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {void __init xen_init_mmu_ops (void ) { + x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; + +if (xen_feature (XENFEAT_auto_translated_physmap)) { + pv_mmu_ops.flush_tlb_others = xen_flush_tlb_others; + +/* set_pte* for PCI devices to map iomem. */ +if (xen_initial_domain ()) { + pv_mmu_ops.set_pte = native_set_pte; + pv_mmu_ops.set_pte_at = xen_dom0pvh_set_pte_at; + } +return ; + } + x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve; x86_init.paging.pagetable_setup_start = xen_pagetable_setup_start; - x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; pv_mmu_ops = xen_mmu_ops;memset (dummy_mapping,0xff ,PAGE_SIZE );
@@ -2305,6 +2358,92 @@ void __init xen_hvm_init_mmu_ops(void) }#endif +/* Map foreign gmfn, fgmfn, to local pfn, lpfn. This for the user space +* creating new guest on PVH dom0 and needs to map domU pages. +*/ +static int pvh_add_to_xen_p2m (unsigned long lpfn,unsigned long fgmfn, +unsigned int domid) +{ +int rc; +struct xen_add_to_physmap xatp = { .u.foreign_domid = domid }; + + xatp.gpfn = lpfn; + xatp.idx = fgmfn; + xatp.domid =DOMID_SELF ; + xatp.space = XENMAPSPACE_gmfn_foreign; + rc =HYPERVISOR_memory_op (XENMEM_add_to_physmap, &xatp); +if (rc) +pr_warn ("d0: Failed to map pfn to mfn rc:%d pfn:%lx mfn:%lx\n" , + rc, lpfn, fgmfn); +return rc; +} + +int pvh_rem_xen_p2m (unsigned long spfn,int count) +{ +struct xen_remove_from_physmap xrp; +int i, rc; + +for (i=0 ; i < count; i++) { + xrp.domid =DOMID_SELF ; + xrp.gpfn = spfn+i; + rc =HYPERVISOR_memory_op (XENMEM_remove_from_physmap, &xrp); +if (rc) { +pr_warn ("Failed to unmap pfn:%lx rc:%d done:%d\n" , + spfn+i, rc, i); +return 1 ; + } + } +return 0 ; +} +EXPORT_SYMBOL_GPL (pvh_rem_xen_p2m); + +struct pvh_remap_data { +unsigned long fgmfn;/* foreign domain's gmfn */ +pgprot_t prot; +domid_t domid; +struct xen_pvh_pfn_info *pvhinfop; +}; + +static int pvh_map_pte_fn (pte_t *ptep,pgtable_t token,unsigned long addr, +void *data) +{ +int rc; +struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; +unsigned long pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo++]); +pte_t pteval =pte_mkspecial (pfn_pte (pfn, remapp->prot)); + +if ((rc=pvh_add_to_xen_p2m (pfn, remapp->fgmfn, remapp->domid))) +return rc; +native_set_pte (ptep, pteval); + +return 0 ; +} + +/* The only caller at moment passes one gmfn at a time. +* PVH TBD/FIXME: expand this in future to honor batch requests. +*/ +static int pvh_remap_gmfn_range (struct vm_area_struct *vma, +unsigned long addr,unsigned long mfn,int nr, +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) +{ +int err; +struct pvh_remap_data pvhdata; + +if (nr >1 ) +return -EINVAL ; + + pvhdata.fgmfn = mfn; + pvhdata.prot = prot; + pvhdata.domid = domid; + pvhdata.pvhinfop = pvhp; + err =apply_to_page_range (vma->vm_mm, addr, nr <<PAGE_SHIFT , + pvh_map_pte_fn, &pvhdata); +flush_tlb_all (); +return err; +} +#define REMAP_BATCH_SIZE 16struct remap_data {
@@ -2329,7 +2468,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid) +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) + {struct remap_data rmd;struct mmu_update mmu_update[REMAP_BATCH_SIZE ];
@@ -2342,6 +2483,12 @@ int xen_remap_domain_mfn_range(struct vm_area_struct *vma,BUG_ON (!((vma->vm_flags & (VM_PFNMAP |VM_RESERVED |VM_IO )) == (VM_PFNMAP |VM_RESERVED |VM_IO ))); +if (xen_feature (XENFEAT_auto_translated_physmap)) { +/* We need to update the local page tables and the xen HAP */ +return pvh_remap_gmfn_range (vma, addr, mfn, nr, prot, domid, + pvhp); + } + rmd.mfn = mfn; rmd.prot = prot;
@@ -2371,3 +2518,26 @@ out:return err; }EXPORT_SYMBOL_GPL (xen_remap_domain_mfn_range); + +/* Returns: Number of pages unmapped */ +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp) +{ +int count =0 ; + +if (!pvhp || !xen_feature (XENFEAT_auto_translated_physmap)) +return 0 ; + +while (pvhp->pi_next_todo--) { +unsigned long pfn; + +/* the mmu has already cleaned up the process mmu resources at +* this point (lookup_address will return NULL). */ + pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo]); +pvh_rem_xen_p2m (pfn,1 ); + count++; + } +flush_tlb_all (); +return count; +} +EXPORT_SYMBOL_GPL (xen_unmap_domain_mfn_range);
arch/x86/xen/mmu.h +2 -0
@@ -23,4 +23,6 @@ unsigned long xen_read_cr2_direct(void);extern void xen_init_mmu_ops (void );extern void xen_hvm_init_mmu_ops (void ); +extern void xen_set_clr_mmio_pvh_pte (unsigned long pfn,unsigned long mfn, +int nr_mfns,int add_mapping);#endif /* _XEN_MMU_H */
include/xen/xen-ops.h +11 -1
@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsigned long vstart, unsigned int order,void xen_destroy_contiguous_region (unsigned long vstart,unsigned int order);struct vm_area_struct ; +struct xen_pvh_pfn_info ;int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid); +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info { +struct page **pi_paga;/* pfn info page array */ +int pi_num_pgs; +int pi_next_todo; +};#endif /* INCLUDE_XEN_OPS_H */
Signature · 1 line
1.7.2.3
There are few code style issues on this patch, I suggest you run it through scripts/checkpatch.pl, it should be able to catch all these errors.
Quoted 31 lines · Mukesh Rathor
--- arch/x86/xen/mmu.c | 180 +++++++++++++++++++++++++++++++++++++++++++++++-- arch/x86/xen/mmu.h | 2 + include/xen/xen-ops.h | 12 +++- 3 files changed, 188 insertions(+), 6 deletions(-)arch/x86/xen/mmu.c +10
-0@@ -73,6 +73,7 @@#include <xen/interface/version.h> #include <xen/interface/memory.h> #include <xen/hvc-console.h> +#include <xen/balloon.h> #include "multicalls.h" #include "mmu.h" @@ -330,6 +331,26 @@ static void xen_set_pte(pte_t *ptep, pte_t pteval)__xen_set_pte (ptep, pteval); } +void xen_set_clr_mmio_pvh_pte (unsigned long pfn,unsigned long mfn, +int nr_mfns,int add_mapping) +{ +struct physdev_map_iomem iomem; + + iomem.first_gfn = pfn; + iomem.first_mfn = mfn; + iomem.nr_mfns = nr_mfns; + iomem.add_mapping = add_mapping;
arch/x86/xen/mmu.c static void xen_set_pte(pte_t *ptep, pte_t pteval) · line 352
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+ +if (HYPERVISOR_physdev_op (PHYSDEVOP_pvh_map_iomem, &iomem)) +BUG (); +} + +static void xen_dom0pvh_set_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval) +{ +native_set_pte (ptep, pteval); +}
can't you just set set_pte_at to native_set_pte?
arch/x86/xen/mmu.c static void xen_post_allocator_init(void); · line 1226
Quoted 13 lines
arch/x86/xen/mmu.c +4
-0static void xen_set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval) {@@ -1197,6 +1218,10 @@ static void xen_post_allocator_init(void);static void __init xen_pagetable_setup_done (pgd_t *base) {xen_setup_shared_info (); + +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +xen_post_allocator_init (); }
Can we move the if..return at the beginning of xen_post_allocator_init? It would make it easier to understand what it is for.
Or maybe we could have xen_setup_shared_info take a pgd_t *base parameter so that you can set pagetable_setup_done to xen_setup_shared_info directly on pvh.
arch/x86/xen/mmu.c static void __init xen_set_pte_init(pte_t *ptep, pte_t pte) · line 1489
Quoted 11 lines
arch/x86/xen/mmu.c +4
-0@@ -1455,6 +1480,10 @@ static void __init xen_set_pte_init(pte_t *ptep, pte_t pte)static void pin_pagetable_pfn (unsigned cmd,unsigned long pfn) {struct mmuext_op op; + +if (xen_feature (XENFEAT_writable_page_tables)) +return ; + op.cmd = cmd; op.arg1.mfn =pfn_to_mfn (pfn);if (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF ))
given the very limited set of mmu pvops that we initialize on pvh, I cannot find who would actually call pin_pagetable_pfn on pvh.
Quoted 59 lines
arch/x86/xen/mmu.c +24
-3@@ -1652,6 +1681,10 @@ static void set_page_prot(void *addr, pgprot_t prot)unsigned long pfn =__pa (addr) >>PAGE_SHIFT ;pte_t pte =pfn_pte (pfn, prot); +/* recall for PVH, page tables are native. */ +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +if (HYPERVISOR_update_va_mapping ((unsigned long )addr, pte,0 ))BUG (); }@@ -1729,6 +1762,9 @@ static void convert_pfn_mfn(void *v)pte_t *pte = v;int i; +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +/* All levels are converted the same way, so just treat them as ptes. */ for (i =0 ; i <PTRS_PER_PTE ; i++)@@ -1745,6 +1781,7 @@ static void convert_pfn_mfn(void *v)* but that's enough to get __va working. We need to fill in the rest * of the physical mapping once some sort of allocator has been set * up. +* NOTE: for PVH, the page tables are native. */ pgd_t *__init xen_setup_kernel_pagetable (pgd_t *pgd,unsigned long max_pfn)@@ -1802,9 +1839,13 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,* structure to attach it to, so make sure we just set kernel * pgd. */ -xen_mc_batch (); -__xen_write_cr3 (true,__pa (pgd)); -xen_mc_issue (PARAVIRT_LAZY_CPU ); +if (xen_feature (XENFEAT_writable_page_tables)) { +native_write_cr3 (__pa (pgd)); + }else { +xen_mc_batch (); +__xen_write_cr3 (true,__pa (pgd)); +xen_mc_issue (PARAVIRT_LAZY_CPU ); + }memblock_reserve (__pa (xen_start_info->pt_base), xen_start_info->nr_pt_frames *PAGE_SIZE );@@ -2067,9 +2108,21 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {void __init xen_init_mmu_ops (void ) { + x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; + +if (xen_feature (XENFEAT_auto_translated_physmap)) { + pv_mmu_ops.flush_tlb_others = xen_flush_tlb_others; + +/* set_pte* for PCI devices to map iomem. */ +if (xen_initial_domain ()) { + pv_mmu_ops.set_pte = native_set_pte; + pv_mmu_ops.set_pte_at = xen_dom0pvh_set_pte_at;
arch/x86/xen/mmu.c static const struct pv_mmu_ops xen_mmu_ops __initconst = { · line 2128
Quoted 10 lines
arch/x86/xen/mmu.c +4
-1+ } +return ; + } + x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve; x86_init.paging.pagetable_setup_start = xen_pagetable_setup_start; - x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; pv_mmu_ops = xen_mmu_ops;memset (dummy_mapping,0xff ,PAGE_SIZE );
I wonder whether it would make sense to have a xen_pvh_init_mmu_ops, given that they end up being so different...
Quoted 52 lines
arch/x86/xen/mmu.c +48
-0@@ -2305,6 +2358,92 @@ void __init xen_hvm_init_mmu_ops(void) }#endif +/* Map foreign gmfn, fgmfn, to local pfn, lpfn. This for the user space +* creating new guest on PVH dom0 and needs to map domU pages. +*/ +static int pvh_add_to_xen_p2m (unsigned long lpfn,unsigned long fgmfn, +unsigned int domid) +{ +int rc; +struct xen_add_to_physmap xatp = { .u.foreign_domid = domid }; + + xatp.gpfn = lpfn; + xatp.idx = fgmfn; + xatp.domid =DOMID_SELF ; + xatp.space = XENMAPSPACE_gmfn_foreign; + rc =HYPERVISOR_memory_op (XENMEM_add_to_physmap, &xatp); +if (rc) +pr_warn ("d0: Failed to map pfn to mfn rc:%d pfn:%lx mfn:%lx\n" , + rc, lpfn, fgmfn); +return rc; +} + +int pvh_rem_xen_p2m (unsigned long spfn,int count) +{ +struct xen_remove_from_physmap xrp; +int i, rc; + +for (i=0 ; i < count; i++) { + xrp.domid =DOMID_SELF ; + xrp.gpfn = spfn+i; + rc =HYPERVISOR_memory_op (XENMEM_remove_from_physmap, &xrp); +if (rc) { +pr_warn ("Failed to unmap pfn:%lx rc:%d done:%d\n" , + spfn+i, rc, i); +return 1 ; + } + } +return 0 ; +} +EXPORT_SYMBOL_GPL (pvh_rem_xen_p2m); + +struct pvh_remap_data { +unsigned long fgmfn;/* foreign domain's gmfn */ +pgprot_t prot; +domid_t domid; +struct xen_pvh_pfn_info *pvhinfop; +}; + +static int pvh_map_pte_fn (pte_t *ptep,pgtable_t token,unsigned long addr, +void *data)
arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2418
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+{ +int rc; +struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; +unsigned long pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo++]); +pte_t pteval =pte_mkspecial (pfn_pte (pfn, remapp->prot)); + +if ((rc=pvh_add_to_xen_p2m (pfn, remapp->fgmfn, remapp->domid))) +return rc; +native_set_pte (ptep, pteval);
Do we actually need the pte to be "special"?
I would think that being in the guest p2m, it is actually quite a normal page.
Quoted 14 lines
arch/x86/xen/mmu.c +14
-0+return 0 ; +} + +/* The only caller at moment passes one gmfn at a time. +* PVH TBD/FIXME: expand this in future to honor batch requests. +*/ +static int pvh_remap_gmfn_range (struct vm_area_struct *vma, +unsigned long addr,unsigned long mfn,int nr, +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) +{ +int err; +struct pvh_remap_data pvhdata; +
arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2443
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+if (nr >1 ) +return -EINVAL ; + + pvhdata.fgmfn = mfn; + pvhdata.prot = prot; + pvhdata.domid = domid; + pvhdata.pvhinfop = pvhp; + err =apply_to_page_range (vma->vm_mm, addr, nr <<PAGE_SHIFT , + pvh_map_pte_fn, &pvhdata); +flush_tlb_all ();
Maybe we can use one of the flush_tlb_range varieties instead of a flush_tlb_all?
Quoted 45 lines
arch/x86/xen/mmu.c +23
-1+return err; +} +#define REMAP_BATCH_SIZE 16struct remap_data {@@ -2329,7 +2468,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid) +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) + {struct remap_data rmd;struct mmu_update mmu_update[REMAP_BATCH_SIZE ];@@ -2342,6 +2483,12 @@ int xen_remap_domain_mfn_range(struct vm_area_struct *vma,BUG_ON (!((vma->vm_flags & (VM_PFNMAP |VM_RESERVED |VM_IO )) == (VM_PFNMAP |VM_RESERVED |VM_IO ))); +if (xen_feature (XENFEAT_auto_translated_physmap)) { +/* We need to update the local page tables and the xen HAP */ +return pvh_remap_gmfn_range (vma, addr, mfn, nr, prot, domid, + pvhp); + } + rmd.mfn = mfn; rmd.prot = prot;@@ -2371,3 +2518,26 @@ out:return err; }EXPORT_SYMBOL_GPL (xen_remap_domain_mfn_range); + +/* Returns: Number of pages unmapped */ +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp) +{ +int count =0 ; + +if (!pvhp || !xen_feature (XENFEAT_auto_translated_physmap)) +return 0 ; + +while (pvhp->pi_next_todo--) {
arch/x86/xen/mmu.c out: · line 2541
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+unsigned long pfn; + +/* the mmu has already cleaned up the process mmu resources at +* this point (lookup_address will return NULL). */ + pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo]); +pvh_rem_xen_p2m (pfn,1 ); + count++; + } +flush_tlb_all (); +return count;
Who is going to remove the corresponding mapping from the vma? Also we might be able to replace the flush_tlb_all with a flush_tlb_range.
Quoted 40 lines
arch/x86/xen/mmu.c +1
-0+EXPORT_SYMBOL_GPL (xen_unmap_domain_mfn_range);arch/x86/xen/mmu.h +2
-0@@ -23,4 +23,6 @@ unsigned long xen_read_cr2_direct(void);extern void xen_init_mmu_ops (void );extern void xen_hvm_init_mmu_ops (void ); +extern void xen_set_clr_mmio_pvh_pte (unsigned long pfn,unsigned long mfn, +int nr_mfns,int add_mapping);#endif /* _XEN_MMU_H */ include/xen/xen-ops.h +11
-1@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsigned long vstart, unsigned int order,void xen_destroy_contiguous_region (unsigned long vstart,unsigned int order);struct vm_area_struct ; +struct xen_pvh_pfn_info ;int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid); +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info { +struct page **pi_paga;/* pfn info page array */ +int pi_num_pgs; +int pi_next_todo; +};#endif /* INCLUDE_XEN_OPS_H */ Signature · 1 line
1.7.2.3
Quoted 3 lines · Stefano Stabellini
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.
It would also be nice to starting having some changelogs entries for these patches for the next posting. There's a lot of complex stuff going on here.
Quoted 21 lines
Quoted 21 lines
arch/x86/xen/mmu.c +17
-0@@ -2371,3 +2518,26 @@ out:return err; }EXPORT_SYMBOL_GPL (xen_remap_domain_mfn_range); + +/* Returns: Number of pages unmapped */ +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp) +{ +int count =0 ; + +if (!pvhp || !xen_feature (XENFEAT_auto_translated_physmap)) +return 0 ; + +while (pvhp->pi_next_todo--) { +unsigned long pfn; + +/* the mmu has already cleaned up the process mmu resources at +* this point (lookup_address will return NULL). */ + pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo]); +pvh_rem_xen_p2m (pfn,1 );
Quoted 8 lines
arch/x86/xen/mmu.c out: · line 2541
Quoted 4 lines
arch/x86/xen/mmu.c +4
-0+ count++; + } +flush_tlb_all (); +return count;Who is going to remove the corresponding mapping from the vma? Also we might be able to replace the
flush_tlb_allwith aflush_tlb_range.
I'm not convinced that a guest level TLB flush is either necessary or sufficient here. What we are doing is removing entries from the P2M which means that we need to do the appropriate HAP flush in the hypervisor, which must necessarily invalidate any stage 1 mappings which this flush might also touch (i.e. the HAP flush must be a super set of this flush).
Without the HAP flush in the hypervisor you risk guests being able to see old p2m mappings via the TLB entries which is a security issue AFAICT.
Ian.
Quoted 46 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.It would also be nice to starting having some changelogs entries for these patches for the next posting. There's a lot of complex stuff going on here.
Quoted 21 lines
Quoted 21 lines
arch/x86/xen/mmu.c +17
-0@@ -2371,3 +2518,26 @@ out:return err; }EXPORT_SYMBOL_GPL (xen_remap_domain_mfn_range); + +/* Returns: Number of pages unmapped */ +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp) +{ +int count =0 ; + +if (!pvhp || !xen_feature (XENFEAT_auto_translated_physmap)) +return 0 ; + +while (pvhp->pi_next_todo--) { +unsigned long pfn; + +/* the mmu has already cleaned up the process mmu resources at +* this point (lookup_address will return NULL). */ + pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo]); +pvh_rem_xen_p2m (pfn,1 );Quoted 8 lines
arch/x86/xen/mmu.c out: · line 2541
Quoted 4 lines
arch/x86/xen/mmu.c +4
-0+ count++; + } +flush_tlb_all (); +return count;Who is going to remove the corresponding mapping from the vma? Also we might be able to replace the
flush_tlb_allwith aflush_tlb_range.I'm not convinced that a guest level TLB flush is either necessary or sufficient here. What we are doing is removing entries from the P2M which means that we need to do the appropriate HAP flush in the hypervisor, which must necessarily invalidate any stage 1 mappings which this flush might also touch (i.e. the HAP flush must be a super set of this flush).
Quoted 3 lines
Without the HAP flush in the hypervisor you risk guests being able to see old p2m mappings via the TLB entries which is a security issue AFAICT.
Yes, you are right, we need a flush in the hypervisor to flush the EPT. It could probably live in the implementation of XENMEM_add_to_physmap.
This one should be just for the vma mappings, so in the case of xen_unmap_domain_mfn_range is unnecessary (given that it is not removing the vma mappings).
Quoted 25 lines · On Mon, 24 Sep 2012 13:24:12 +0100 Stefano Stabellini…
Quoted 20 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.It would also be nice to starting having some changelogs entries for these patches for the next posting. There's a lot of complex stuff
Quoted 5 lines
arch/x86/xen/mmu.c out: · line 2541
Quoted 1 line
arch/x86/xen/mmu.c +1
-0+return count;Who is going to remove the corresponding mapping from the vma? Also we might be able to replace the
flush_tlb_allwith aflush_tlb_range.I'm not convinced that a guest level TLB flush is either necessary or sufficient here. What we are doing is removing entries from the P2M which means that we need to do the appropriate HAP flush in the hypervisor, which must necessarily invalidate any stage 1 mappings which this flush might also touch (i.e. the HAP flush must be a super set of this flush).
Quoted 3 lines
Without the HAP flush in the hypervisor you risk guests being able to see old p2m mappings via the TLB entries which is a security issue AFAICT.
Quoted 7 lines
Yes, you are right, we need a flush in the hypervisor to flush the EPT. It could probably live in the implementation of
XENMEM_add_to_physmap.This one should be just for the vma mappings, so in the case of
xen_unmap_domain_mfn_rangeis unnecessary (given that it is not removing the vma mappings).
My head spins looking at INVEPT and INVVPID docs, but doesn't it already happen in ept_set_entry():
if ( needs_sync )
ept_sync_domain(p2m->domain);
Quoted 20 lines · Mukesh Rathor
Quoted 11 lines
Quoted 10 lines
I'm not convinced that a guest level TLB flush is either necessary or sufficient here. What we are doing is removing entries from the P2M which means that we need to do the appropriate HAP flush in the hypervisor, which must necessarily invalidate any stage 1 mappings which this flush might also touch (i.e. the HAP flush must be a super set of this flush).
Without the HAP flush in the hypervisor you risk guests being able to see old p2m mappings via the TLB entries which is a security issue AFAICT.
Quoted 7 lines
Yes, you are right, we need a flush in the hypervisor to flush the EPT. It could probably live in the implementation of
XENMEM_add_to_physmap.This one should be just for the vma mappings, so in the case of
xen_unmap_domain_mfn_rangeis unnecessary (given that it is not removing the vma mappings).
Quoted 5 lines
My head spins looking at INVEPT and INVVPID docs, but doesn't it already happen in
ept_set_entry():if (
needs_sync)
ept_sync_domain(p2m->domain);
Yes, the point of having a clean p2m interface is that you shouldn't need to figure out when to do hap flushes.
-George
Quoted 37 lines · Mukesh Rathor
Quoted 25 lines · On Mon, 24 Sep 2012 13:24:12 +0100 Stefano Stabellini…
Quoted 20 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.It would also be nice to starting having some changelogs entries for these patches for the next posting. There's a lot of complex stuff
Quoted 5 lines
arch/x86/xen/mmu.c out: · line 2541
Quoted 1 line
arch/x86/xen/mmu.c +1
-0+return count;Who is going to remove the corresponding mapping from the vma? Also we might be able to replace the
flush_tlb_allwith aflush_tlb_range.I'm not convinced that a guest level TLB flush is either necessary or sufficient here. What we are doing is removing entries from the P2M which means that we need to do the appropriate HAP flush in the hypervisor, which must necessarily invalidate any stage 1 mappings which this flush might also touch (i.e. the HAP flush must be a super set of this flush).
Quoted 3 lines
Without the HAP flush in the hypervisor you risk guests being able to see old p2m mappings via the TLB entries which is a security issue AFAICT.
Quoted 7 lines
Yes, you are right, we need a flush in the hypervisor to flush the EPT. It could probably live in the implementation of
XENMEM_add_to_physmap.This one should be just for the vma mappings, so in the case of
xen_unmap_domain_mfn_rangeis unnecessary (given that it is not removing the vma mappings).
Quoted 6 lines
My head spins looking at INVEPT and INVVPID docs, but doesn't it already happen in
ept_set_entry():if (
needs_sync)
ept_sync_domain(p2m->domain);
Right. So we should be able to get away without any tlb flushes in xen_unmap_domain_mfn_range.
Quoted 61 lines · Stefano Stabellini
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.Quoted 31 lines · Mukesh Rathor
--- arch/x86/xen/mmu.c | 180 +++++++++++++++++++++++++++++++++++++++++++++++-- arch/x86/xen/mmu.h | 2 + include/xen/xen-ops.h | 12 +++- 3 files changed, 188 insertions(+), 6 deletions(-)arch/x86/xen/mmu.c +10
-0@@ -73,6 +73,7 @@#include <xen/interface/version.h> #include <xen/interface/memory.h> #include <xen/hvc-console.h> +#include <xen/balloon.h> #include "multicalls.h" #include "mmu.h" @@ -330,6 +331,26 @@ static void xen_set_pte(pte_t *ptep, pte_t pteval)__xen_set_pte (ptep, pteval); } +void xen_set_clr_mmio_pvh_pte (unsigned long pfn,unsigned long mfn, +int nr_mfns,int add_mapping) +{ +struct physdev_map_iomem iomem; + + iomem.first_gfn = pfn; + iomem.first_mfn = mfn; + iomem.nr_mfns = nr_mfns; + iomem.add_mapping = add_mapping;arch/x86/xen/mmu.c static void xen_set_pte(pte_t *ptep, pte_t pteval) · line 352
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+ +if (HYPERVISOR_physdev_op (PHYSDEVOP_pvh_map_iomem, &iomem)) +BUG (); +} + +static void xen_dom0pvh_set_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval) +{ +native_set_pte (ptep, pteval); +}can't you just set
set_pte_attonative_set_pte?Quoted 11 lines
arch/x86/xen/mmu.c +4
-0static void xen_set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval) {@@ -1197,6 +1218,10 @@ static void xen_post_allocator_init(void);static void __init xen_pagetable_setup_done (pgd_t *base) {xen_setup_shared_info (); + +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +
Quoted 8 lines
arch/x86/xen/mmu.c static void xen_post_allocator_init(void); · line 1226
Quoted 2 lines
arch/x86/xen/mmu.c +0
-0xen_post_allocator_init (); }Can we move the if..return at the beginning of
xen_post_allocator_init? It would make it easier to understand what it is for.
Or maybe we could havexen_setup_shared_infotake apgd_t*base parameter so that you can setpagetable_setup_donetoxen_setup_shared_infodirectly on pvh.
It actually ends up nicely aligning with my patches since I end up using 'if (xen_feature(..)'. But you can't see that since these patches are not rebased on that - which is OK.
Quoted 290 lines
arch/x86/xen/mmu.c static void __init xen_set_pte_init(pte_t *ptep, pte_t pte) · line 1489
Quoted 13 lines
arch/x86/xen/mmu.c +4
-0@@ -1455,6 +1480,10 @@ static void __init xen_set_pte_init(pte_t *ptep, pte_t pte)static void pin_pagetable_pfn (unsigned cmd,unsigned long pfn) {struct mmuext_op op; + +if (xen_feature (XENFEAT_writable_page_tables)) +return ; + op.cmd = cmd; op.arg1.mfn =pfn_to_mfn (pfn);if (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF ))given the very limited set of mmu pvops that we initialize on pvh, I cannot find who would actually call
pin_pagetable_pfnon pvh.Quoted 59 lines
arch/x86/xen/mmu.c +24
-3@@ -1652,6 +1681,10 @@ static void set_page_prot(void *addr, pgprot_t prot)unsigned long pfn =__pa (addr) >>PAGE_SHIFT ;pte_t pte =pfn_pte (pfn, prot); +/* recall for PVH, page tables are native. */ +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +if (HYPERVISOR_update_va_mapping ((unsigned long )addr, pte,0 ))BUG (); }@@ -1729,6 +1762,9 @@ static void convert_pfn_mfn(void *v)pte_t *pte = v;int i; +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +/* All levels are converted the same way, so just treat them as ptes. */ for (i =0 ; i <PTRS_PER_PTE ; i++)@@ -1745,6 +1781,7 @@ static void convert_pfn_mfn(void *v)* but that's enough to get __va working. We need to fill in the rest * of the physical mapping once some sort of allocator has been set * up. +* NOTE: for PVH, the page tables are native. */ pgd_t *__init xen_setup_kernel_pagetable (pgd_t *pgd,unsigned long max_pfn)@@ -1802,9 +1839,13 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,* structure to attach it to, so make sure we just set kernel * pgd. */ -xen_mc_batch (); -__xen_write_cr3 (true,__pa (pgd)); -xen_mc_issue (PARAVIRT_LAZY_CPU ); +if (xen_feature (XENFEAT_writable_page_tables)) { +native_write_cr3 (__pa (pgd)); + }else { +xen_mc_batch (); +__xen_write_cr3 (true,__pa (pgd)); +xen_mc_issue (PARAVIRT_LAZY_CPU ); + }memblock_reserve (__pa (xen_start_info->pt_base), xen_start_info->nr_pt_frames *PAGE_SIZE );@@ -2067,9 +2108,21 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {void __init xen_init_mmu_ops (void ) { + x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; + +if (xen_feature (XENFEAT_auto_translated_physmap)) { + pv_mmu_ops.flush_tlb_others = xen_flush_tlb_others; + +/* set_pte* for PCI devices to map iomem. */ +if (xen_initial_domain ()) { + pv_mmu_ops.set_pte = native_set_pte; + pv_mmu_ops.set_pte_at = xen_dom0pvh_set_pte_at;arch/x86/xen/mmu.c static const struct pv_mmu_ops xen_mmu_ops __initconst = { · line 2128
Quoted 10 lines
arch/x86/xen/mmu.c +4
-1+ } +return ; + } + x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve; x86_init.paging.pagetable_setup_start = xen_pagetable_setup_start; - x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; pv_mmu_ops = xen_mmu_ops;memset (dummy_mapping,0xff ,PAGE_SIZE );I wonder whether it would make sense to have a
xen_pvh_init_mmu_ops, given that they end up being so different...Quoted 52 lines
arch/x86/xen/mmu.c +48
-0@@ -2305,6 +2358,92 @@ void __init xen_hvm_init_mmu_ops(void) }#endif +/* Map foreign gmfn, fgmfn, to local pfn, lpfn. This for the user space +* creating new guest on PVH dom0 and needs to map domU pages. +*/ +static int pvh_add_to_xen_p2m (unsigned long lpfn,unsigned long fgmfn, +unsigned int domid) +{ +int rc; +struct xen_add_to_physmap xatp = { .u.foreign_domid = domid }; + + xatp.gpfn = lpfn; + xatp.idx = fgmfn; + xatp.domid =DOMID_SELF ; + xatp.space = XENMAPSPACE_gmfn_foreign; + rc =HYPERVISOR_memory_op (XENMEM_add_to_physmap, &xatp); +if (rc) +pr_warn ("d0: Failed to map pfn to mfn rc:%d pfn:%lx mfn:%lx\n" , + rc, lpfn, fgmfn); +return rc; +} + +int pvh_rem_xen_p2m (unsigned long spfn,int count) +{ +struct xen_remove_from_physmap xrp; +int i, rc; + +for (i=0 ; i < count; i++) { + xrp.domid =DOMID_SELF ; + xrp.gpfn = spfn+i; + rc =HYPERVISOR_memory_op (XENMEM_remove_from_physmap, &xrp); +if (rc) { +pr_warn ("Failed to unmap pfn:%lx rc:%d done:%d\n" , + spfn+i, rc, i); +return 1 ; + } + } +return 0 ; +} +EXPORT_SYMBOL_GPL (pvh_rem_xen_p2m); + +struct pvh_remap_data { +unsigned long fgmfn;/* foreign domain's gmfn */ +pgprot_t prot; +domid_t domid; +struct xen_pvh_pfn_info *pvhinfop; +}; + +static int pvh_map_pte_fn (pte_t *ptep,pgtable_t token,unsigned long addr, +void *data)arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2418
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+{ +int rc; +struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; +unsigned long pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo++]); +pte_t pteval =pte_mkspecial (pfn_pte (pfn, remapp->prot)); + +if ((rc=pvh_add_to_xen_p2m (pfn, remapp->fgmfn, remapp->domid))) +return rc; +native_set_pte (ptep, pteval);Do we actually need the pte to be "special"?
I would think that being in the guest p2m, it is actually quite a normal page.Quoted 14 lines
arch/x86/xen/mmu.c +14
-0+return 0 ; +} + +/* The only caller at moment passes one gmfn at a time. +* PVH TBD/FIXME: expand this in future to honor batch requests. +*/ +static int pvh_remap_gmfn_range (struct vm_area_struct *vma, +unsigned long addr,unsigned long mfn,int nr, +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) +{ +int err; +struct pvh_remap_data pvhdata; +arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2443
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+if (nr >1 ) +return -EINVAL ; + + pvhdata.fgmfn = mfn; + pvhdata.prot = prot; + pvhdata.domid = domid; + pvhdata.pvhinfop = pvhp; + err =apply_to_page_range (vma->vm_mm, addr, nr <<PAGE_SHIFT , + pvh_map_pte_fn, &pvhdata); +flush_tlb_all ();Maybe we can use one of the
flush_tlb_rangevarieties instead of aflush_tlb_all?Quoted 45 lines
arch/x86/xen/mmu.c +23
-1+return err; +} +#define REMAP_BATCH_SIZE 16struct remap_data {@@ -2329,7 +2468,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid) +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) + {struct remap_data rmd;struct mmu_update mmu_update[REMAP_BATCH_SIZE ];@@ -2342,6 +2483,12 @@ int xen_remap_domain_mfn_range(struct vm_area_struct *vma,BUG_ON (!((vma->vm_flags & (VM_PFNMAP |VM_RESERVED |VM_IO )) == (VM_PFNMAP |VM_RESERVED |VM_IO ))); +if (xen_feature (XENFEAT_auto_translated_physmap)) { +/* We need to update the local page tables and the xen HAP */ +return pvh_remap_gmfn_range (vma, addr, mfn, nr, prot, domid, + pvhp); + } + rmd.mfn = mfn; rmd.prot = prot;@@ -2371,3 +2518,26 @@ out:return err; }EXPORT_SYMBOL_GPL (xen_remap_domain_mfn_range); + +/* Returns: Number of pages unmapped */ +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp) +{ +int count =0 ; + +if (!pvhp || !xen_feature (XENFEAT_auto_translated_physmap)) +return 0 ; + +while (pvhp->pi_next_todo--) {arch/x86/xen/mmu.c out: · line 2541
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+unsigned long pfn; + +/* the mmu has already cleaned up the process mmu resources at +* this point (lookup_address will return NULL). */ + pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo]); +pvh_rem_xen_p2m (pfn,1 ); + count++; + } +flush_tlb_all (); +return count;Who is going to remove the corresponding mapping from the vma? Also we might be able to replace the
flush_tlb_allwith aflush_tlb_range.Quoted 40 lines
arch/x86/xen/mmu.c +1
-0+EXPORT_SYMBOL_GPL (xen_unmap_domain_mfn_range);arch/x86/xen/mmu.h +2
-0@@ -23,4 +23,6 @@ unsigned long xen_read_cr2_direct(void);extern void xen_init_mmu_ops (void );extern void xen_hvm_init_mmu_ops (void ); +extern void xen_set_clr_mmio_pvh_pte (unsigned long pfn,unsigned long mfn, +int nr_mfns,int add_mapping);#endif /* _XEN_MMU_H */ include/xen/xen-ops.h +11
-1@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsigned long vstart, unsigned int order,void xen_destroy_contiguous_region (unsigned long vstart,unsigned int order);struct vm_area_struct ; +struct xen_pvh_pfn_info ;int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid); +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info { +struct page **pi_paga;/* pfn info page array */ +int pi_num_pgs; +int pi_next_todo; +};#endif /* INCLUDE_XEN_OPS_H */ Signature · 1 line
1.7.2.3
Quoted 11 lines · On Mon, 24 Sep 2012 12:55:31 +0100 Stefano Stabellini…
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.Quoted 6 lines · Mukesh Rathor
--- arch/x86/xen/mmu.c | 180 +++++++++++++++++++++++++++++++++++++++++++++++-- arch/x86/xen/mmu.h | 2 + include/xen/xen-ops.h | 12 +++- 3 files changed, 188 insertions(+), 6 deletions(-)
Quoted 8 lines
arch/x86/xen/mmu.c static void xen_set_pte(pte_t *ptep, pte_t pteval) · line 352
Quoted 6 lines
arch/x86/xen/mmu.c +0
-0long addr,
arch/x86/xen/mmu.c +4
-0+ pte_t *ptep, pte_t pteval) +{ +native_set_pte (ptep ,pteval ); +}can't you just set
set_pte_attonative_set_pte?
yup. oh, i had other code there, which is why it's not already native_set_pte_at.
Quoted 12 lines
Quoted 12 lines
static void xen_set_pte_at(struct
mm_struct*mm, unsigned long
addr,pte_t*ptep,pte_tpteval)
{arch/x86/xen/mmu.c +4
-0@@ -1197,6 +1218,10 @@ static void xen_post_allocator_init(void);static void __init xen_pagetable_setup_done (pgd_t *base) {xen_setup_shared_info (); + +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +
Quoted 8 lines
arch/x86/xen/mmu.c static void xen_post_allocator_init(void); · line 1226
Quoted 2 lines
arch/x86/xen/mmu.c +0
-0xen_post_allocator_init (); }Can we move the if..return at the beginning of
xen_post_allocator_init? It would make it easier to understand what it is for. Or maybe we could havexen_setup_shared_infotake apgd_t*base parameter so that you can setpagetable_setup_donetoxen_setup_shared_infodirectly on pvh.
done.
Quoted 15 lines
arch/x86/xen/mmu.c static void __init xen_set_pte_init(pte_t · line 1489
Quoted 12 lines
arch/x86/xen/mmu.c +4
-0@@ -1455,6 +1480,10 @@ static void __init xen_set_pte_init(pte_t *ptep, pte_t pte) static void pin_pagetable_pfn(unsigned cmd,unsigned long pfn) {struct mmuext_op op; + +if (xen_feature (XENFEAT_writable_page_tables)) +return ; + op.cmd = cmd; op.arg1.mfn =pfn_to_mfn (pfn);if (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF ))given the very limited set of mmu pvops that we initialize on pvh, I cannot find who would actually call
pin_pagetable_pfnon pvh.
xen_setup_kernel_pagetable().
Quoted 18 lines
Quoted 18 lines
arch/x86/xen/mmu.c +8
-0@@ -1652,6 +1681,10 @@ static void set_page_prot(void *addr, pgprot_t prot) unsigned long pfn = __pa(addr) >> PAGE_SHIFT; +/* set_pte* for PCI devices to map iomem. */ +if (xen_initial_domain ()) { + pv_mmu_ops.set_pte = native_set_pte; + pv_mmu_ops.set_pte_at = xen_dom0pvh_set_pte_at; + } +return ; + } + x86_init.mapping.pagetable_reserve =
xen_mapping_pagetable_reserve; x86_init.paging.pagetable_setup_start =xen_pagetable_setup_start;arch/x86/xen/mmu.c +0
-1- x86_init.paging.pagetable_setup_done =
xen_pagetable_setup_done;pv_mmu_ops=xen_mmu_ops;
Quoted 4 lines
Quoted 1 line
memset(dummy_mapping, 0xff, PAGE_SIZE);I wonder whether it would make sense to have a
xen_pvh_init_mmu_ops, given that they end up being so different...
It's not a pv ops call. It's called from xen_start_kernel in enlighten.c. So lets just leave it like that.
Quoted 9 lines
Quoted 9 lines
arch/x86/xen/mmu.c +6
-0+ void *data) +{ +int rc; +struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; + unsigned long pfn =
page_to_pfn(pvhp->pi_paga[pvhp->pi_next_todo++]);arch/x86/xen/mmu.c +2
-0+pte_t pteval =pte_mkspecial (pfn_pte (pfn, remapp->prot)); +
Quoted 8 lines
arch/x86/xen/mmu.c
Quoted 4 lines
arch/x86/xen/mmu.c +1
-0+ if ((rc=pvh_add_to_xen_p2m(pfn, remapp->fgmfn,
remapp->domid)))arch/x86/xen/mmu.c +2
-0+return rc; +native_set_pte (ptep, pteval);Do we actually need the pte to be "special"?
I would think that being in the guest p2m, it is actually quite a normal page.
Ah, I remember. The reason I had it special is because earlier I was allocating pfn's from high up address space. These pfns' were greater than highest_memmap_pfn. But, now I'm allocating them via ballooing. So I can change it to normal. If we go back to allocating pfn's space from high up, then we'd need this back for this check:
vm_normal_page():
if (unlikely(pfn > highest_memmap_pfn)) {
print_bad_pte(vma, addr, pte, NULL);
return NULL;Quoted 21 lines
Quoted 21 lines
arch/x86/xen/mmu.c +8
-0+return 0 ; +} + +/* The only caller at moment passes one gmfn at a time. +* PVH TBD/FIXME: expand this in future to honor batch requests. +*/ +static int pvh_remap_gmfn_range (struct vm_area_struct *vma, + unsigned long addr, unsigned longmfn, int nr,
arch/x86/xen/mmu.c +12
-0+ pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp) +{ + int err; +struct pvh_remap_data pvhdata; + +if (nr >1 ) +return -EINVAL ; + + pvhdata.fgmfn = mfn; + pvhdata.prot = prot; + pvhdata.domid = domid;
Quoted 8 lines
arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2443
Quoted 5 lines
arch/x86/xen/mmu.c +2
-0+ pvhdata.pvhinfop = pvhp; + err = apply_to_page_range(vma->vm_mm, addr, nr <<
PAGE_SHIFT,arch/x86/xen/mmu.c +2
-0+ pvh_map_pte_fn, &pvhdata); +flush_tlb_all ();Maybe we can use one of the
flush_tlb_rangevarieties instead of aflush_tlb_all?
changed it to : flush_tlb_page(vma, addr);
Quoted 13 lines
Quoted 13 lines
arch/x86/xen/mmu.c +8
-0+ +if (!pvhp || !xen_feature (XENFEAT_auto_translated_physmap)) +return 0 ; + +while (pvhp->pi_next_todo--) { +unsigned long pfn; + +/* the mmu has already cleaned up the process mmu resources at
arch/x86/xen/mmu.c +2
-0+* this point (lookup_address will return NULL). */ + pfn =
page_to_pfn(pvhp->pi_paga[pvhp->pi_next_todo]);arch/x86/xen/mmu.c +1
-0+pvh_rem_xen_p2m (pfn,1 );
Quoted 8 lines
arch/x86/xen/mmu.c out: · line 2541
Quoted 4 lines
arch/x86/xen/mmu.c +4
-0+ count++; + } +flush_tlb_all (); +return count;Who is going to remove the corresponding mapping from the vma? Also we might be able to replace the
flush_tlb_allwith aflush_tlb_range.
the kernel already does that before privcmd_close is called. don't have the addrs for flush_tlb_range in privcmd_close().
thanks,
Mukesh
Quoted 17 lines · Mukesh Rathor
Quoted 17 lines
Quoted 17 lines
arch/x86/xen/mmu.c +8
-0@@ -1652,6 +1681,10 @@ static void set_page_prot(void *addr, pgprot_t prot) unsigned long pfn = __pa(addr) >> PAGE_SHIFT; +/* set_pte* for PCI devices to map iomem. */ +if (xen_initial_domain ()) { + pv_mmu_ops.set_pte = native_set_pte; + pv_mmu_ops.set_pte_at = xen_dom0pvh_set_pte_at; + } +return ; + } + x86_init.mapping.pagetable_reserve =
xen_mapping_pagetable_reserve; x86_init.paging.pagetable_setup_start =xen_pagetable_setup_start;(quoted diff) +0
-1- x86_init.paging.pagetable_setup_done =
xen_pagetable_setup_done;pv_mmu_ops=xen_mmu_ops;
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
memset(dummy_mapping, 0xff, PAGE_SIZE);I wonder whether it would make sense to have a
xen_pvh_init_mmu_ops, given that they end up being so different...It's not a pv ops call. It's called from
xen_start_kernelinenlighten.c. So lets just leave it like that.
I meant having a completely different initialization function in mmu.c, instead of trying to reuse xen_init_mmu_ops, because at the end of the day the two cases are very different
Quoted 3 lines · On Mon, 24 Sep 2012 12:55:31 +0100 Stefano Stabellini…
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.
All patches were run thru checkpatch.pl already. So not sure what you are referring to.
Quoted 6 lines
Quoted 6 lines
arch/x86/xen/mmu.c +3
-0+struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; + unsigned long pfn =
page_to_pfn(pvhp->pi_paga[pvhp->pi_next_todo++]);(quoted diff) +2
-0+ pte_t pteval = pte_mkspecial(pfn_pte(pfn, remapp->prot)); +
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +1
-0+ if ((rc=pvh_add_to_xen_p2m(pfn, remapp->fgmfn,
remapp->domid)))(quoted diff) +2
-0+ return rc; + native_set_pte(ptep, pteval);Do we actually need the pte to be "special"?
I would think that being in the guest p2m, it is actually quite a normal page.
Hmm... well, doesn't like removing "special":
BUG: Bad page map in process xl pte:800000027b57b467 pmd:2b408d067
page:ffffea0008afb2e8 count:1 mapcount:-1 mapping: (null) index:0x0
page flags: 0x40000000000414(referenced|dirty|reserved)
addr:00007fb4345b0000 vm_flags:000a44fb anon_vma: (null) mapping:ffff88003911a3d0 index:4vma->vm_ops->fault: privcmd_fault+0x0/0x40 vma->vm_file->f_op->mmap: privcmd_mmap+0x0/0x30
Pid: 2737, comm: xl Tainted: G B 3.6.0-rc6-merge+ #17
Call Trace: [<ffffffff8113dabc>] print_bad_pte+0x1dc/0x250 [<ffffffff8113e57e>] zap_pte_range+0x45e/0x4c0 [<ffffffff8113f30e>] unmap_page_range+0x1ae/0x310 [<ffffffff8113f4d1>] unmap_single_vma+0x61/0xe0 [<ffffffff8113f5a4>] unmap_vmas+0x54/0xa0 [<ffffffff8114514b>] unmap_region+0xab/0x120 [<ffffffff81313263>] ? privcmd_ioctl+0x93/0x100 [<ffffffff8114733d>] do_munmap+0x25d/0x380
This from:
if (unlikely(page_mapcount(page) < 0))
print_bad_pte(vma, addr, ptent, page);
So, the mapcount must be not be getting set in "normal" case properly it appears. Marking it special causes it so skip few things. Debugging...
thanks,
Mukesh
Quoted 36 lines · On Mon, 1 Oct 2012 14:32:44 -0700 Mukesh Rathor <[email protected]>…
Quoted 15 lines
Review
Quoted 11 lines
arch/x86/xen/mmu.c +3
-0+struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; + unsigned long pfn =
page_to_pfn(pvhp->pi_paga[pvhp->pi_next_todo++]);arch/x86/xen/mmu.c +3
-0+pte_t pteval =pte_mkspecial (pfn_pte (pfn, remapp->prot)); + + if ((rc=pvh_add_to_xen_p2m(pfn, remapp->fgmfn,
remapp->domid)))(quoted diff) +2
-0+ return rc; + native_set_pte(ptep, pteval);Do we actually need the pte to be "special"?
I would think that being in the guest p2m, it is actually quite a normal page.Hmm... well, doesn't like removing "special":
BUG: Bad page map in process xl pte:800000027b57b467 pmd:2b408d067page:ffffea0008afb2e8 count:1 mapcount:-1 mapping: (null)
index:0x0 page flags: 0x40000000000414(referenced|dirty|reserved)
addr:00007fb4345b0000 vm_flags:000a44fbanon_vma: (null)
mapping:ffff88003911a3d0 index:4vma->vm_ops->fault:privcmd_fault+0x0/0x40vma->vm_file->f_op->mmap:privcmd_mmap+0x0/0x30
Pid: 2737, comm: xl Tainted: G B 3.6.0-rc6-merge+ #17Call Trace: [<ffffffff8113dabc>] print_bad_pte+0x1dc/0x250 [<ffffffff8113e57e>] zap_pte_range+0x45e/0x4c0 [<ffffffff8113f30e>] unmap_page_range+0x1ae/0x310 [<ffffffff8113f4d1>] unmap_single_vma+0x61/0xe0 [<ffffffff8113f5a4>] unmap_vmas+0x54/0xa0 [<ffffffff8114514b>] unmap_region+0xab/0x120 [<ffffffff81313263>] ? privcmd_ioctl+0x93/0x100 [<ffffffff8114733d>] do_munmap+0x25d/0x380
Quoted 8 lines
This from:
if (unlikely(page_mapcount(page) < 0))
print_bad_pte(vma, addr, ptent, page);So, the mapcount must be not be getting set in "normal" case properly it appears. Marking it special causes it so skip few things. Debugging...
Shall I just leave it special for now, and come back and revisit this later?
thanks
Mukesh
Quoted 44 lines · Mukesh Rathor
Quoted 41 lines · On Mon, 1 Oct 2012 14:32:44 -0700 Mukesh Rathor <[email protected]>…
Quoted 15 lines
Review
Quoted 11 lines
arch/x86/xen/mmu.c +3
-0+struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; + unsigned long pfn =
page_to_pfn(pvhp->pi_paga[pvhp->pi_next_todo++]);arch/x86/xen/mmu.c +3
-0+pte_t pteval =pte_mkspecial (pfn_pte (pfn, remapp->prot)); + + if ((rc=pvh_add_to_xen_p2m(pfn, remapp->fgmfn,
remapp->domid)))(quoted diff) +2
-0+ return rc; + native_set_pte(ptep, pteval);Do we actually need the pte to be "special"?
I would think that being in the guest p2m, it is actually quite a normal page.Hmm... well, doesn't like removing "special":
BUG: Bad page map in process xl pte:800000027b57b467 pmd:2b408d067page:ffffea0008afb2e8 count:1 mapcount:-1 mapping: (null)
index:0x0 page flags: 0x40000000000414(referenced|dirty|reserved)
addr:00007fb4345b0000 vm_flags:000a44fbanon_vma: (null)
mapping:ffff88003911a3d0 index:4vma->vm_ops->fault:privcmd_fault+0x0/0x40vma->vm_file->f_op->mmap:privcmd_mmap+0x0/0x30
Pid: 2737, comm: xl Tainted: G B 3.6.0-rc6-merge+ #17Call Trace: [<ffffffff8113dabc>] print_bad_pte+0x1dc/0x250 [<ffffffff8113e57e>] zap_pte_range+0x45e/0x4c0 [<ffffffff8113f30e>] unmap_page_range+0x1ae/0x310 [<ffffffff8113f4d1>] unmap_single_vma+0x61/0xe0 [<ffffffff8113f5a4>] unmap_vmas+0x54/0xa0 [<ffffffff8114514b>] unmap_region+0xab/0x120 [<ffffffff81313263>] ? privcmd_ioctl+0x93/0x100 [<ffffffff8114733d>] do_munmap+0x25d/0x380This from:
if (unlikely(page_mapcount(page) < 0))
print_bad_pte(vma, addr, ptent, page);
Quoted 6 lines
Quoted 3 lines
So, the mapcount must be not be getting set in "normal" case properly it appears. Marking it special causes it so skip few things. Debugging...
Shall I just leave it special for now, and come back and revisit this later?
special is going to create troubles if somebody starts using these pages in unexpected ways (for example dma from hardware ot gupf).
Also I fail to see how this case is any different from mapping pages using gntdev (see gntdev_mmap) that works fine without special.
Maybe we are not setting some vm_flags that we are supposed to set (VM_RESERVED | VM_IO | VM_DONTCOPY)?
I see that we are setting them in privcmd_mmap but not in privcmd_ioctl_mmap_batch...
Quoted 15 lines · On Tue, 2 Oct 2012 12:23:58 +0100 Stefano Stabellini…
Quoted 10 lines · Mukesh Rathor
Quoted 4 lines · On Mon, 1 Oct 2012 14:32:44 -0700 Mukesh Rathor <[email protected]>…
So, the mapcount must be not be getting set in "normal" case properly it appears. Marking it special causes it so skip few things. Debugging...
Shall I just leave it special for now, and come back and revisit this later?
special is going to create troubles if somebody starts using these pages in unexpected ways (for example dma from hardware ot gupf).
Quoted 7 lines
Also I fail to see how this case is any different from mapping pages using gntdev (see
gntdev_mmap) that works fine without special.Maybe we are not setting some
vm_flagsthat we are supposed to set (VM_RESERVED|VM_IO|VM_DONTCOPY)?
I see that we are setting them inprivcmd_mmapbut not inprivcmd_ioctl_mmap_batch...
No, that is getting set. privcmd_mmap is hook for mmap(), so it gets called for both. If its not marked special, vm_normal_page() will not check for the VM_PFNMAP flag, which is what we want.
It works for PV dom0 because remap_area_mfn_pte_fn() has also marked it special:
static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,
unsigned long addr, void *data)
{
struct remap_data *rmd = data;
pte_t pte = pte_mkspecial(pfn_pte(rmd->mfn++, rmd->prot));thanks,
Mukesh
Quoted 9 lines · Mukesh Rathor
Quoted 3 lines · On Mon, 24 Sep 2012 12:55:31 +0100 Stefano Stabellini…
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.All patches were run thru checkpatch.pl already. So not sure what you are referring to.
I'll go back to your series and tell you whenever I find a code style issue.
Quoted 3 lines · On Mon, 24 Sep 2012 12:55:31 +0100 Stefano Stabellini…
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.
Oh, my bad. I was running them thru cleanpatch and not checkpatch. It's my first linux submission, so please bear with me. I'll run them all thru checkpatch this time.
Thanks
Mukesh
Quoted 10 lines · Mukesh Rathor
Quoted 3 lines · On Mon, 24 Sep 2012 12:55:31 +0100 Stefano Stabellini…
There are few code style issues on this patch, I suggest you run it through
scripts/checkpatch.pl, it should be able to catch all these errors.Oh, my bad. I was running them thru cleanpatch and not checkpatch. It's my first linux submission, so please bear with me. I'll run them all thru checkpatch this time.
I'd never heard of cleanpatch before, looks like it is pretty obsolete (not updated since 2007 and still requires 79 char lines).
Ian.
Quoted 51 lines · Mukesh Rathor
arch/x86/xen/mmu.c +47
-0+struct pvh_remap_data { +unsigned long fgmfn;/* foreign domain's gmfn */ +pgprot_t prot; +domid_t domid; +struct xen_pvh_pfn_info *pvhinfop; +}; + +static int pvh_map_pte_fn (pte_t *ptep,pgtable_t token,unsigned long addr, +void *data) +{ +int rc; +struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; +unsigned long pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo++]); +pte_t pteval =pte_mkspecial (pfn_pte (pfn, remapp->prot)); + +if ((rc=pvh_add_to_xen_p2m (pfn, remapp->fgmfn, remapp->domid))) +return rc; +native_set_pte (ptep, pteval); + +return 0 ; +} + +/* The only caller at moment passes one gmfn at a time. +* PVH TBD/FIXME: expand this in future to honor batch requests. +*/ +static int pvh_remap_gmfn_range (struct vm_area_struct *vma, +unsigned long addr,unsigned long mfn,int nr, +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) +{ +int err; +struct pvh_remap_data pvhdata; + +if (nr >1 ) +return -EINVAL ; + + pvhdata.fgmfn = mfn; + pvhdata.prot = prot; + pvhdata.domid = domid; + pvhdata.pvhinfop = pvhp; + err =apply_to_page_range (vma->vm_mm, addr, nr <<PAGE_SHIFT , + pvh_map_pte_fn, &pvhdata); +flush_tlb_all (); +return err; +} +#define REMAP_BATCH_SIZE 16struct remap_data {
arch/x86/xen/mmu.c static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token, · line 2473
Quoted 7 lines
arch/x86/xen/mmu.c +3
-1@@ -2329,7 +2468,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid) +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) +
xen_remap_domain_mfn_range is a cross-architecture call (it is available on ARM as well). We cannot leak architecture specific informations like xen_pvh_pfn_info in the parameter list.
It seems to be that xen_pvh_pfn_info contains arch-agnostic information:
in that case you just need to rename the struct to something more generic. Otherwise if it really contains x86 specific info, you can change it into an opaque pointer.
Quoted 60 lines · Stefano Stabellini
Quoted 51 lines · Mukesh Rathor
arch/x86/xen/mmu.c +47
-0+struct pvh_remap_data { +unsigned long fgmfn;/* foreign domain's gmfn */ +pgprot_t prot; +domid_t domid; +struct xen_pvh_pfn_info *pvhinfop; +}; + +static int pvh_map_pte_fn (pte_t *ptep,pgtable_t token,unsigned long addr, +void *data) +{ +int rc; +struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; +unsigned long pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo++]); +pte_t pteval =pte_mkspecial (pfn_pte (pfn, remapp->prot)); + +if ((rc=pvh_add_to_xen_p2m (pfn, remapp->fgmfn, remapp->domid))) +return rc; +native_set_pte (ptep, pteval); + +return 0 ; +} + +/* The only caller at moment passes one gmfn at a time. +* PVH TBD/FIXME: expand this in future to honor batch requests. +*/ +static int pvh_remap_gmfn_range (struct vm_area_struct *vma, +unsigned long addr,unsigned long mfn,int nr, +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) +{ +int err; +struct pvh_remap_data pvhdata; + +if (nr >1 ) +return -EINVAL ; + + pvhdata.fgmfn = mfn; + pvhdata.prot = prot; + pvhdata.domid = domid; + pvhdata.pvhinfop = pvhp; + err =apply_to_page_range (vma->vm_mm, addr, nr <<PAGE_SHIFT , + pvh_map_pte_fn, &pvhdata); +flush_tlb_all (); +return err; +} +#define REMAP_BATCH_SIZE 16struct remap_data {arch/x86/xen/mmu.c static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token, · line 2473
Quoted 7 lines
arch/x86/xen/mmu.c +3
-1@@ -2329,7 +2468,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid) +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) +
Quoted 7 lines
xen_remap_domain_mfn_rangeis a cross-architecture call (it is available on ARM as well). We cannot leak architecture specific informations likexen_pvh_pfn_infoin the parameter list.
It seems to be thatxen_pvh_pfn_infocontains arch-agnostic information:
in that case you just need to rename the struct to something more generic. Otherwise if it really contains x86 specific info, you can change it into an opaque pointer.
... or explode it into the relevant constituents struct members which need to be passed over the interface when calling these functions.
Ian.
Quoted 12 lines · On Mon, 24 Sep 2012 15:04:22 +0100 Stefano Stabellini…
arch/x86/xen/mmu.c static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token, · line 2473
Quoted 10 lines · Mukesh Rathor
arch/x86/xen/mmu.c +1
-0+struct pvh_remap_data { struct remap_data {@@ -2329,7 +2468,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep,
pgtable_ttoken, int xen_remap_domain_mfn_range(structvm_area_struct*vma, unsigned long addr,arch/x86/xen/mmu.c +3
-1unsigned long mfn, int nr, - pgprot_t prot, unsigned domid) + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp) +
Quoted 7 lines
xen_remap_domain_mfn_rangeis a cross-architecture call (it is available on ARM as well). We cannot leak architecture specific informations likexen_pvh_pfn_infoin the parameter list. It seems to be thatxen_pvh_pfn_infocontains arch-agnostic
information: in that case you just need to rename the struct to something more generic. Otherwise if it really contains x86 specific info, you can change it into an opaque pointer.
Ok, how about I just change it to:
- struct xen_pvh_pfn_info *pvhp)
+ void *arch_spec_info)
thanks,
Mukesh
Quoted 25 lines · Mukesh Rathor
Quoted 12 lines · On Mon, 24 Sep 2012 15:04:22 +0100 Stefano Stabellini…
arch/x86/xen/mmu.c static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token, · line 2473
Quoted 10 lines · Mukesh Rathor
arch/x86/xen/mmu.c +1
-0+struct pvh_remap_data { struct remap_data {@@ -2329,7 +2468,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep,
pgtable_ttoken, int xen_remap_domain_mfn_range(structvm_area_struct*vma, unsigned long addr,arch/x86/xen/mmu.c +3
-1unsigned long mfn, int nr, - pgprot_t prot, unsigned domid) + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp) +Quoted 7 lines
xen_remap_domain_mfn_rangeis a cross-architecture call (it is available on ARM as well). We cannot leak architecture specific informations likexen_pvh_pfn_infoin the parameter list. It seems to be thatxen_pvh_pfn_infocontains arch-agnostic
information: in that case you just need to rename the struct to something more generic. Otherwise if it really contains x86 specific info, you can change it into an opaque pointer.Ok, how about I just change it to:
Review
Quoted 2 lines
(quoted diff) +1
-1- struct xen_pvh_pfn_info *pvhp) + void *arch_spec_info)
Sorry for misleading you, but on second thought, an opaque pointer is not a good idea: xen_remap_domain_mfn_range is called from privcmd.c, that is arch-agnostic code, so I think that all the parameters should be well specified and arch-agnostic.
I think that you should:
- rename xen_pvh_pfn_info to something non-x86 specific, for example xen_remap_pfn_info;
- move the definition of struct xen_remap_pfn_info to include/xen/xen-ops.h;
- add a good comment on top of the struct to explain what each field represents, because other people (me and Ian) might have to reimplement xen_remap_domain_mfn_range in the near future for another popular architecture ;-)
Review int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 32
Quoted 11 lines
(quoted diff) +3
-1@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsigned long vstart, unsigned int order, void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order); struct vm_area_struct; +struct xen_pvh_pfn_info; int xen_remap_domain_mfn_range(struct vm_area_struct *vma, unsigned long addr, unsigned long mfn, int nr, - pgprot_t prot, unsigned domid); + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp);
This change during a git bisection (where we only applied patch #1 and patch #2) will cause a build breakage like this:
/home/konrad/ssd/linux/drivers/xen/privcmd.c: In function ‘mmap_mfn_range’:/home/konrad/ssd/linux/drivers/xen/privcmd.c:181: error: too few arguments to function ‘xen_remap_domain_mfn_range’ /home/konrad/ssd/linux/drivers/xen/privcmd.c: In function ‘mmap_batch_fn’:/home/konrad/ssd/linux/drivers/xen/privcmd.c:270: error: too few arguments to function ‘xen_remap_domain_mfn_range’ make[4]: *** [drivers/xen/privcmd.o] Error 1
make[3]: *** [drivers/xen] Error 2
Please squash this patch:
drivers/xen/privcmd.c +2 -2
@@ -178,7 +178,7 @@ static int mmap_mfn_range(void *data, void *state) msg->va &PAGE_MASK , msg->mfn, msg->npages, vma->vm_page_prot, - st->domain); + st->domain, NULL);if (rc <0 )return rc;
@@ -267,7 +267,7 @@ static int mmap_batch_fn(void *data, void *state)int ret; ret =xen_remap_domain_mfn_range (st->vma, st->va &PAGE_MASK , *mfnp,1 , - st->vma->vm_page_prot, st->domain); + st->vma->vm_page_prot, st->domain,NULL );/* Store error code for second pass. */ *(st->err++) = ret;
into this patch.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 156 lines · Mukesh Rathor
--- arch/x86/xen/mmu.c | 180 +++++++++++++++++++++++++++++++++++++++++++++++-- arch/x86/xen/mmu.h | 2 + include/xen/xen-ops.h | 12 +++- 3 files changed, 188 insertions(+), 6 deletions(-)arch/x86/xen/mmu.c +73
-4@@ -73,6 +73,7 @@#include <xen/interface/version.h> #include <xen/interface/memory.h> #include <xen/hvc-console.h> +#include <xen/balloon.h> #include "multicalls.h" #include "mmu.h" @@ -330,6 +331,26 @@ static void xen_set_pte(pte_t *ptep, pte_t pteval)__xen_set_pte (ptep, pteval); } +void xen_set_clr_mmio_pvh_pte (unsigned long pfn,unsigned long mfn, +int nr_mfns,int add_mapping) +{ +struct physdev_map_iomem iomem; + + iomem.first_gfn = pfn; + iomem.first_mfn = mfn; + iomem.nr_mfns = nr_mfns; + iomem.add_mapping = add_mapping; + +if (HYPERVISOR_physdev_op (PHYSDEVOP_pvh_map_iomem, &iomem)) +BUG (); +} + +static void xen_dom0pvh_set_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pteval) +{ +native_set_pte (ptep, pteval); +} +static void xen_set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep,pte_t pteval) {@@ -1197,6 +1218,10 @@ static void xen_post_allocator_init(void);static void __init xen_pagetable_setup_done (pgd_t *base) {xen_setup_shared_info (); + +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +xen_post_allocator_init (); }@@ -1455,6 +1480,10 @@ static void __init xen_set_pte_init(pte_t *ptep, pte_t pte)static void pin_pagetable_pfn (unsigned cmd,unsigned long pfn) {struct mmuext_op op; + +if (xen_feature (XENFEAT_writable_page_tables)) +return ; + op.cmd = cmd; op.arg1.mfn =pfn_to_mfn (pfn);if (HYPERVISOR_mmuext_op (&op,1 ,NULL ,DOMID_SELF ))@@ -1652,6 +1681,10 @@ static void set_page_prot(void *addr, pgprot_t prot)unsigned long pfn =__pa (addr) >>PAGE_SHIFT ;pte_t pte =pfn_pte (pfn, prot); +/* recall for PVH, page tables are native. */ +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +if (HYPERVISOR_update_va_mapping ((unsigned long )addr, pte,0 ))BUG (); }@@ -1729,6 +1762,9 @@ static void convert_pfn_mfn(void *v)pte_t *pte = v;int i; +if (xen_feature (XENFEAT_auto_translated_physmap)) +return ; +/* All levels are converted the same way, so just treat them as ptes. */ for (i =0 ; i <PTRS_PER_PTE ; i++)@@ -1745,6 +1781,7 @@ static void convert_pfn_mfn(void *v)* but that's enough to get __va working. We need to fill in the rest * of the physical mapping once some sort of allocator has been set * up. +* NOTE: for PVH, the page tables are native. */ pgd_t *__init xen_setup_kernel_pagetable (pgd_t *pgd,unsigned long max_pfn)@@ -1802,9 +1839,13 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,* structure to attach it to, so make sure we just set kernel * pgd. */ -xen_mc_batch (); -__xen_write_cr3 (true,__pa (pgd)); -xen_mc_issue (PARAVIRT_LAZY_CPU ); +if (xen_feature (XENFEAT_writable_page_tables)) { +native_write_cr3 (__pa (pgd)); + }else { +xen_mc_batch (); +__xen_write_cr3 (true,__pa (pgd)); +xen_mc_issue (PARAVIRT_LAZY_CPU ); + }memblock_reserve (__pa (xen_start_info->pt_base), xen_start_info->nr_pt_frames *PAGE_SIZE );@@ -2067,9 +2108,21 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {void __init xen_init_mmu_ops (void ) { + x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; + +if (xen_feature (XENFEAT_auto_translated_physmap)) { + pv_mmu_ops.flush_tlb_others = xen_flush_tlb_others; + +/* set_pte* for PCI devices to map iomem. */ +if (xen_initial_domain ()) { + pv_mmu_ops.set_pte = native_set_pte; + pv_mmu_ops.set_pte_at = xen_dom0pvh_set_pte_at; + } +return ; + } + x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve; x86_init.paging.pagetable_setup_start = xen_pagetable_setup_start; - x86_init.paging.pagetable_setup_done = xen_pagetable_setup_done; pv_mmu_ops = xen_mmu_ops;memset (dummy_mapping,0xff ,PAGE_SIZE );@@ -2305,6 +2358,92 @@ void __init xen_hvm_init_mmu_ops(void) }#endif +/* Map foreign gmfn, fgmfn, to local pfn, lpfn. This for the user space +* creating new guest on PVH dom0 and needs to map domU pages. +*/ +static int pvh_add_to_xen_p2m (unsigned long lpfn,unsigned long fgmfn, +unsigned int domid) +{ +int rc; +struct xen_add_to_physmap xatp = { .u.foreign_domid = domid }; + + xatp.gpfn = lpfn; + xatp.idx = fgmfn; + xatp.domid =DOMID_SELF ; + xatp.space = XENMAPSPACE_gmfn_foreign; + rc =HYPERVISOR_memory_op (XENMEM_add_to_physmap, &xatp); +if (rc) + pr_warn("d0: Failed to map pfn to mfn rc:%d pfn:%lx mfn:%lx\n",
arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2386
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+ rc, lpfn, fgmfn); +return rc; +} + +int pvh_rem_xen_p2m (unsigned long spfn,int count) +{ +struct xen_remove_from_physmap xrp; +int i, rc; + +for (i=0 ; i < count; i++) {
i = 0
arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2388
Quoted 2 lines
arch/x86/xen/mmu.c +2
-0+ xrp.domid =DOMID_SELF ; + xrp.gpfn = spfn+i;
spfn + i
arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2392
Quoted 4 lines
arch/x86/xen/mmu.c +4
-0+ rc =HYPERVISOR_memory_op (XENMEM_remove_from_physmap, &xrp); +if (rc) { +pr_warn ("Failed to unmap pfn:%lx rc:%d done:%d\n" , + spfn+i, rc, i);
spfn + i
Quoted 15 lines
arch/x86/xen/mmu.c +15
-0+return 1 ; + } + } +return 0 ; +} +EXPORT_SYMBOL_GPL (pvh_rem_xen_p2m); + +struct pvh_remap_data { +unsigned long fgmfn;/* foreign domain's gmfn */ +pgprot_t prot; +domid_t domid; +struct xen_pvh_pfn_info *pvhinfop; +}; + +static int pvh_map_pte_fn(pte_t *ptep, pgtable_t token, unsigned long addr,
arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2417
Quoted 10 lines
arch/x86/xen/mmu.c +10
-0+ void *data) +{ +int rc; +struct pvh_remap_data *remapp = data; +struct xen_pvh_pfn_info *pvhp = remapp->pvhinfop; +unsigned long pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo++]); +pte_t pteval =pte_mkspecial (pfn_pte (pfn, remapp->prot)); + +if ((rc=pvh_add_to_xen_p2m (pfn, remapp->fgmfn, remapp->domid))) +return rc;
rc = pvh_add_to_xen_p2m
Quoted 122 lines
arch/x86/xen/mmu.c +61
-1+native_set_pte (ptep, pteval); + +return 0 ; +} + +/* The only caller at moment passes one gmfn at a time. +* PVH TBD/FIXME: expand this in future to honor batch requests. +*/ +static int pvh_remap_gmfn_range (struct vm_area_struct *vma, +unsigned long addr,unsigned long mfn,int nr, +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) +{ +int err; +struct pvh_remap_data pvhdata; + +if (nr >1 ) +return -EINVAL ; + + pvhdata.fgmfn = mfn; + pvhdata.prot = prot; + pvhdata.domid = domid; + pvhdata.pvhinfop = pvhp; + err =apply_to_page_range (vma->vm_mm, addr, nr <<PAGE_SHIFT , + pvh_map_pte_fn, &pvhdata); +flush_tlb_all (); +return err; +} +#define REMAP_BATCH_SIZE 16struct remap_data {@@ -2329,7 +2468,9 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid) +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp) + {struct remap_data rmd;struct mmu_update mmu_update[REMAP_BATCH_SIZE ];@@ -2342,6 +2483,12 @@ int xen_remap_domain_mfn_range(struct vm_area_struct *vma,BUG_ON (!((vma->vm_flags & (VM_PFNMAP |VM_RESERVED |VM_IO )) == (VM_PFNMAP |VM_RESERVED |VM_IO ))); +if (xen_feature (XENFEAT_auto_translated_physmap)) { +/* We need to update the local page tables and the xen HAP */ +return pvh_remap_gmfn_range (vma, addr, mfn, nr, prot, domid, + pvhp); + } + rmd.mfn = mfn; rmd.prot = prot;@@ -2371,3 +2518,26 @@ out:return err; }EXPORT_SYMBOL_GPL (xen_remap_domain_mfn_range); + +/* Returns: Number of pages unmapped */ +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp) +{ +int count =0 ; + +if (!pvhp || !xen_feature (XENFEAT_auto_translated_physmap)) +return 0 ; + +while (pvhp->pi_next_todo--) { +unsigned long pfn; + +/* the mmu has already cleaned up the process mmu resources at +* this point (lookup_address will return NULL). */ + pfn =page_to_pfn (pvhp->pi_paga[pvhp->pi_next_todo]); +pvh_rem_xen_p2m (pfn,1 ); + count++; + } +flush_tlb_all (); +return count; +} +EXPORT_SYMBOL_GPL (xen_unmap_domain_mfn_range);arch/x86/xen/mmu.h +2
-0@@ -23,4 +23,6 @@ unsigned long xen_read_cr2_direct(void);extern void xen_init_mmu_ops (void );extern void xen_hvm_init_mmu_ops (void ); +extern void xen_set_clr_mmio_pvh_pte (unsigned long pfn,unsigned long mfn, +int nr_mfns,int add_mapping);#endif /* _XEN_MMU_H */ include/xen/xen-ops.h +11
-1@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsigned long vstart, unsigned int order,void xen_destroy_contiguous_region (unsigned long vstart,unsigned int order);struct vm_area_struct ; +struct xen_pvh_pfn_info ;int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid); +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info { +struct page **pi_paga;/* pfn info page array */ +int pi_num_pgs; +int pi_next_todo; +};#endif /* INCLUDE_XEN_OPS_H */ Signature · 1 line
1.7.2.3
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 27
Quoted 10 lines
include/xen/xen-ops.h +1
-0@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsigned long vstart, unsigned int order,void xen_destroy_contiguous_region (unsigned long vstart,unsigned int order);struct vm_area_struct ; +struct xen_pvh_pfn_info ;
If you move the struct def'n up you don't need this forward decl.
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 36
Quoted 10 lines
include/xen/xen-ops.h +6
-1int xen_remap_domain_mfn_range (struct vm_area_struct *vma,unsigned long addr,unsigned long mfn,int nr, -pgprot_t prot,unsigned domid); +pgprot_t prot,unsigned domid, +struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info {
Can we call this xen_remap_mfn_info or something? PVH is x86 specific while this struct is also useful on ARM.
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 37
Quoted 1 line
include/xen/xen-ops.h +1
-0+struct page **pi_paga;/* pfn info page array */
can we just call this "pages"? paga is pretty meaningless.
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 39
Quoted 2 lines
include/xen/xen-ops.h +2
-0+int pi_num_pgs; +int pi_next_todo;
I don't think we need the pi_ prefix for any of these.
Ian.
Quoted 13 lines · On Wed, 3 Oct 2012 16:42:43 +0100 Ian Campbell <[email protected]> wrote:
Quoted 10 lines
include/xen/xen-ops.h +0
-0@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsigned longvstart, unsigned int order, void
xen_destroy_contiguous_region(unsigned long vstart, unsigned int order); structvm_area_struct;
+structxen_pvh_pfn_info;If you move the struct def'n up you don't need this forward decl.
Quoted 13 lines
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 36
Quoted 10 lines
int xen_remap_domain_mfn_range(struct
vm_area_struct*vma,include/xen/xen-ops.h +6
-1unsigned long addr, unsigned long mfn, int nr, - pgprot_t prot, unsigned domid); + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info {Can we call this
xen_remap_mfn_infoor something? PVH is x86 specific while this struct is also useful on ARM.
I already renamed it to: xen_xlat_pfn_info.
Quoted 4 lines
Quoted 2 lines
include/xen/xen-ops.h +1
-0+struct page **pi_paga;/* pfn info page array */
can we just call this "pages"? paga is pretty meaningless.
page array! i can rename page_array or page_a.
Quoted 4 lines
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 39
Quoted 2 lines
include/xen/xen-ops.h +2
-0+int pi_num_pgs; +int pi_next_todo;I don't think we need the
pi_prefix for any of these.
The prefix for fields in struct make it easy to find via cscope or grep, otherwise, it's a nightmare to find common field names like pages when reading code. I really get frustrated. I prefer prefixing all field names.
thanks
Mukesh
Quoted 30 lines · Mukesh Rathor
Quoted 13 lines · On Wed, 3 Oct 2012 16:42:43 +0100 Ian Campbell <[email protected]> wrote:
Quoted 10 lines
include/xen/xen-ops.h +0
-0@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsigned longvstart, unsigned int order, void
xen_destroy_contiguous_region(unsigned long vstart, unsigned int order); structvm_area_struct;
+structxen_pvh_pfn_info;If you move the struct def'n up you don't need this forward decl.
Quoted 13 lines
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 36
Quoted 10 lines
int xen_remap_domain_mfn_range(struct
vm_area_struct*vma,include/xen/xen-ops.h +6
-1unsigned long addr, unsigned long mfn, int nr, - pgprot_t prot, unsigned domid); + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info {Can we call this
xen_remap_mfn_infoor something? PVH is x86 specific while this struct is also useful on ARM.
Quoted 1 line
I already renamed it to:
xen_xlat_pfn_info.
What does xlat refer to here? I don't think we translate anything with this struct.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
include/xen/xen-ops.h +1
-0+struct page **pi_paga;/* pfn info page array */
can we just call this "pages"? paga is pretty meaningless.
page array! i can rename
page_arrayorpage_a.
What's wrong with pages? It's short (some of the lines using this stuff are necessarily pretty long) and obvious.
Quoted 9 lines
Quoted 4 lines
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 39
Quoted 2 lines
include/xen/xen-ops.h +2
-0+int pi_num_pgs; +int pi_next_todo;I don't think we need the
pi_prefix for any of these.The prefix for fields in struct make it easy to find via cscope or grep, otherwise, it's a nightmare to find common field names like pages when reading code. I really get frustrated. I prefer prefixing all field names.
It's not common practice in Linux to do so but fair enough.
While implementing the ARM version of this interface it occurred to me that the num_pgs and next_todo fields here are not really needed across the arch interface e.g. you already get pi_num_pgs from the nr argument to xen_remap_domain_mfn_range and pi_next_todo is really state which fits in struct pvh_remap_data. That would mean that remap_foo could take a struct page * directly and I think you would save an allocation.
I may look into implementing that change as I code up the ARM side.
Ian.
Quoted 19 lines · On Thu, 4 Oct 2012 09:27:59 +0100 Ian Campbell <[email protected]> wrote:
Quoted 18 lines · Mukesh Rathor
Quoted 14 lines · On Wed, 3 Oct 2012 16:42:43 +0100 Ian Campbell <[email protected]> wrote:
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 36
Quoted 11 lines
int xen_remap_domain_mfn_range(struct
vm_area_struct*vma,include/xen/xen-ops.h +6
-1unsigned long addr, unsigned long mfn, int nr, - pgprot_t prot, unsigned domid); + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info {Can we call this
xen_remap_mfn_infoor something? PVH is x86 specific while this struct is also useful on ARM.
Quoted 4 lines
Quoted 1 line
I already renamed it to:
xen_xlat_pfn_info.What does xlat refer to here? I don't think we translate anything with this struct.
paging mode xlate! See stefanno's prev email where he suggested changing name to this.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
(quoted diff) +1
-0+ struct page **pi_paga; /* pfn info pagearray */
can we just call this "pages"? paga is pretty meaningless.
page array! i can rename
page_arrayorpage_a.What's wrong with pages? It's short (some of the lines using this stuff are necessarily pretty long) and obvious.
grep'ing pages would give thousands results. I can prefix with something and use pages.
Quoted 12 lines
Quoted 9 lines
Quoted 4 lines
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 39
Quoted 2 lines
include/xen/xen-ops.h +2
-0+int pi_num_pgs; +int pi_next_todo;I don't think we need the
pi_prefix for any of these.The prefix for fields in struct make it easy to find via cscope or grep, otherwise, it's a nightmare to find common field names like pages when reading code. I really get frustrated. I prefer prefixing all field names.
It's not common practice in Linux to do so but fair enough.
Quoted 7 lines
While implementing the ARM version of this interface it occurred to me that the
num_pgsandnext_todofields here are not really needed across the arch interface e.g. you already getpi_num_pgsfrom the nr argument toxen_remap_domain_mfn_rangeandpi_next_todois really state which fits in structpvh_remap_data. That would mean thatremap_foocould take a struct page * directly and I think you would save an allocation.
Ok, let me explore this.
thanks
Mukesh
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
(quoted diff) +1
-0+ struct page **pi_paga; /* pfn info pagearray */
can we just call this "pages"? paga is pretty meaningless.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
page array! i can rename
page_arrayorpage_a.What's wrong with pages? It's short (some of the lines using this stuff are necessarily pretty long) and obvious.
grep'ing pages would give thousands results. I can prefix with something and use pages.
Please don't prefix it. 'pages' is good.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 39
Quoted 4 lines
include/xen/xen-ops.h +2
-0+int pi_num_pgs; +int pi_next_todo;I don't think we need the
pi_prefix for any of these.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
The prefix for fields in struct make it easy to find via cscope or grep, otherwise, it's a nightmare to find common field names like pages when reading code. I really get frustrated. I prefer prefixing all field names.
It's not common practice in Linux to do so but fair enough.
Please remove the 'pi_' field. Everytime I see it I think of bathroom and then 3.1415... I've no idea what it actually stands for and I am not sure if there is a need to know what it stands for? If the 'pi_' is very important - it should be part of the structure's name. And then probably unrolled.
If you are searching for a field in a structure - why? Why not search for the structure itself? Making the structure name unique should be enough right to find in cscope/ctags?
Both ctags and cscope are good at helping you (once you have the structure or code name) at finding the definitions of the fields if you need to.
Quoted 22 lines · Mukesh Rathor
Quoted 19 lines · On Thu, 4 Oct 2012 09:27:59 +0100 Ian Campbell <[email protected]> wrote:
Quoted 18 lines · Mukesh Rathor
Quoted 14 lines · On Wed, 3 Oct 2012 16:42:43 +0100 Ian Campbell <[email protected]> wrote:
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 36
Quoted 11 lines
int xen_remap_domain_mfn_range(struct
vm_area_struct*vma,include/xen/xen-ops.h +6
-1unsigned long addr, unsigned long mfn, int nr, - pgprot_t prot, unsigned domid); + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info {Can we call this
xen_remap_mfn_infoor something? PVH is x86 specific while this struct is also useful on ARM.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
I already renamed it to:
xen_xlat_pfn_info.What does xlat refer to here? I don't think we translate anything with this struct.
paging mode xlate! See stefanno's prev email where he suggested changing name to this.
Oh, because the uses are under XENFEAT_auto_translated_physmap? I suppose that makes sense, kind of.
I guess it doesn't really matter since I reckon we can get rid of the struct entirely anyway ;-)
Ian.
Quoted 11 lines · On Thu, 4 Oct 2012 09:27:59 +0100 Ian Campbell <[email protected]> wrote:
Quoted 3 lines · Mukesh Rathor
On Wed, 3 Oct 2012 16:42:43 +0100
Ian Campbell <[email protected]> wrote:While implementing the ARM version of this interface it occurred to me that the
num_pgsandnext_todofields here are not really needed across the arch interface e.g. you already getpi_num_pgsfrom the nr argument toxen_remap_domain_mfn_rangeandpi_next_todois really state which fits in structpvh_remap_data. That would mean thatremap_foocould take a struct page * directly and I think you would save an allocation.
Ok, take a look at the attached and inlined diffs. I redid it, passing struct page to the api, and getting rid of the pi_* struct completely.
thanks
Mukesh
drivers/xen/privcmd.c +66 -2
@@ -33,6 +33,7 @@#include <xen/features.h> #include <xen/page.h> #include <xen/xen-ops.h> +#include <xen/balloon.h> #include "privcmd.h"
@@ -178,7 +179,7 @@ static int mmap_mfn_range(void *data, void *state) msg->va &PAGE_MASK , msg->mfn, msg->npages, vma->vm_page_prot, - st->domain); + st->domain, NULL);if (rc <0 )return rc;
@@ -199,6 +200,10 @@ static long privcmd_ioctl_mmap(void __user *udata)if (!xen_initial_domain ())return -EPERM ; +/* We only support privcmd_ioctl_mmap_batch for auto translated. */ +if (xen_feature (XENFEAT_auto_translated_physmap)) +return -ENOSYS ; +if (copy_from_user (&mmapcmd, udata,sizeof (mmapcmd)))return -EFAULT ;
@@ -246,6 +251,7 @@ struct mmap_batch_state {domid_t domain;unsigned long va;struct vm_area_struct *vma; +int index;/* A tristate: * 0 for no errors * 1 if at least one error has happened (and no
@@ -260,14 +266,20 @@ struct mmap_batch_state {xen_pfn_t __user *user_mfn; }; +/* PVH dom0 fyi: if domU being created is PV, then mfn is mfn(addr on bus). If +* it's PVH then mfn is pfn (input to HAP). */ static int mmap_batch_fn (void *data,void *state) {xen_pfn_t *mfnp = data;struct mmap_batch_state *st = state; +struct vm_area_struct *vma = st->vma; +struct page **pages = vma ? vma->vm_private_data :NULL ; +struct page *cur_page = pages[st->index++];int ret; ret =xen_remap_domain_mfn_range (st->vma, st->va &PAGE_MASK , *mfnp,1 , - st->vma->vm_page_prot, st->domain); + st->vma->vm_page_prot, st->domain, + &cur_page);/* Store error code for second pass. */ *(st->err++) = ret;
@@ -303,6 +315,32 @@ static int mmap_return_errors_v1(void *data, void *state)return __put_user (*mfnp, st->user_mfn++); } +/* Allocate pfns that are then mapped with gmfns from foreign domid. Update +* the vma with the page info to use later. +* Returns: 0 if success, otherwise -errno +*/ +static int pvh_privcmd_resv_pfns (struct vm_area_struct *vma,int numpgs) +{ +int rc; +struct page **pages; + + pages =kcalloc (numpgs,sizeof (pages[0 ]),GFP_KERNEL ); +if (pages ==NULL ) +return -ENOMEM ; + + rc =alloc_xenballooned_pages (numpgs, pages,0 ); +if (rc !=0 ) { +pr_warn ("%s Could not alloc %d pfns rc:%d\n" , __func__, + numpgs, rc); +kfree (pages); +return -ENOMEM ; + } +BUG_ON (vma->vm_private_data); + vma->vm_private_data = pages; + +return 0 ; +} +static struct vm_operations_struct privcmd_vm_ops;static long privcmd_ioctl_mmap_batch (void __user *udata,int version)
@@ -370,10 +408,17 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)up_write (&mm->mmap_sem); goto out; } +if (xen_feature (XENFEAT_auto_translated_physmap)) { +if ((ret =pvh_privcmd_resv_pfns (vma, m.num)) <0 ) { +up_write (&mm->mmap_sem); + goto out; + } + } state.domain = m.dom; state.vma = vma; state.va = m.addr; + state.index =0 ; state.global_error =0 ; state.err = err_array;
@@ -438,6 +483,20 @@ static long privcmd_ioctl(struct file *file,return ret; } +static void privcmd_close (struct vm_area_struct *vma) +{ +struct page **pages = vma ? vma->vm_private_data :NULL ; +int numpgs = (vma->vm_end - vma->vm_start) >>PAGE_SHIFT ; + +if (!pages || !numpgs || !xen_feature (XENFEAT_auto_translated_physmap)) +return ; + +xen_unmap_domain_mfn_range (vma); +while (numpgs--) +free_xenballooned_pages (1 , &pages[numpgs]); +kfree (pages); +} +static int privcmd_fault (struct vm_area_struct *vma,struct vm_fault *vmf) { printk(KERN_DEBUG "privcmd_fault: vma=%p %lx-%lx, pgoff=%lx, uv=%p\n",
@@ -448,6 +507,7 @@ static int privcmd_fault(struct vm_area_struct *vma, struct vm_fault *vmf) }static struct vm_operations_struct privcmd_vm_ops = { + .close = privcmd_close, .fault = privcmd_fault };
@@ -464,6 +524,10 @@ static int privcmd_mmap(struct file *file, struct vm_area_struct *vma)static int privcmd_enforce_singleshot_mapping (struct vm_area_struct *vma) { +if (xen_feature (XENFEAT_auto_translated_physmap)) { +int sz =sizeof (vma->vm_private_data); +return (!__cmpxchg (&vma->vm_private_data,NULL ,NULL , sz)); + }return (xchg (&vma->vm_private_data, (void *)1 ) ==NULL ); }
===============================================================================================
arch/x86/xen/mmu.c +168 -9
264 lines not on this page · raw message
drivers/xen/privcmd.c +66 -2
139 lines not on this page · raw message
arch/x86/xen/mmu.c +168 -9
264 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 15 lines · Mukesh Rathor
Quoted 11 lines · On Thu, 4 Oct 2012 09:27:59 +0100 Ian Campbell <[email protected]> wrote:
Quoted 3 lines · Mukesh Rathor
On Wed, 3 Oct 2012 16:42:43 +0100
Ian Campbell <[email protected]> wrote:While implementing the ARM version of this interface it occurred to me that the
num_pgsandnext_todofields here are not really needed across the arch interface e.g. you already getpi_num_pgsfrom the nr argument toxen_remap_domain_mfn_rangeandpi_next_todois really state which fits in structpvh_remap_data. That would mean thatremap_foocould take a struct page * directly and I think you would save an allocation.
Quoted 2 lines
Ok, take a look at the attached and inlined diffs. I redid it, passing struct page to the api, and getting rid of the pi_* struct completely.
Excellent, thanks.
drivers/xen/privcmd.c struct mmap_batch_state { · line 270
Quoted 6 lines
drivers/xen/privcmd.c +2
-0@@ -260,14 +266,20 @@ struct mmap_batch_state {xen_pfn_t __user *user_mfn; }; +/* PVH dom0 fyi: if domU being created is PV, then mfn is mfn(addr on bus). If +* it's PVH then mfn is pfn (input to HAP). */
Can we say XENFEAT_auto_translated_physmap (or some abbrev.) instead of PVH here, since this is generic code.
Quoted 16 lines
drivers/xen/privcmd.c +5
-1static int mmap_batch_fn (void *data,void *state) {xen_pfn_t *mfnp = data;struct mmap_batch_state *st = state; +struct vm_area_struct *vma = st->vma; +struct page **pages = vma ? vma->vm_private_data :NULL ; +struct page *cur_page = pages[st->index++];int ret; ret =xen_remap_domain_mfn_range (st->vma, st->va &PAGE_MASK , *mfnp,1 , - st->vma->vm_page_prot, st->domain); + st->vma->vm_page_prot, st->domain, + &cur_page);/* Store error code for second pass. */ *(st->err++) = ret;
[...]
drivers/xen/privcmd.c static long privcmd_ioctl_mmap_batch(void __user *udata, int version) · line 412
Quoted 6 lines
drivers/xen/privcmd.c +2
-0@@ -370,10 +408,17 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)up_write (&mm->mmap_sem); goto out; } +if (xen_feature (XENFEAT_auto_translated_physmap)) { +if ((ret =pvh_privcmd_resv_pfns (vma, m.num)) <0 ) {
I renamed this alloc_empty_pages to avoid the PVH terminology in common code.
There could be an argument for moving this to next to alloc_xenballooned_pages e.g. as alloc_xenballooned_pagearray. We used to have alloc_empty_pages_and_pagevec() In the classic kernels which was effectively that same function.
Ian.
Quoted 30 lines · Mukesh Rathor
Quoted 13 lines · On Wed, 3 Oct 2012 16:42:43 +0100 Ian Campbell <[email protected]> wrote:
Quoted 10 lines
include/xen/xen-ops.h +0
-0@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsigned longvstart, unsigned int order, void
xen_destroy_contiguous_region(unsigned long vstart, unsigned int order); structvm_area_struct;
+structxen_pvh_pfn_info;If you move the struct def'n up you don't need this forward decl.
Quoted 13 lines
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 36
Quoted 10 lines
int xen_remap_domain_mfn_range(struct
vm_area_struct*vma,include/xen/xen-ops.h +6
-1unsigned long addr, unsigned long mfn, int nr, - pgprot_t prot, unsigned domid); + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info {Can we call this
xen_remap_mfn_infoor something? PVH is x86 specific while this struct is also useful on ARM.
Quoted 1 line
I already renamed it to:
xen_xlat_pfn_info.
BTW, where can I find you latest patches?
I've just noticed that you've not been CCing LKML with this series -- was that deliberate?
Ian.
Quoted 31 lines · On Thu, 4 Oct 2012 09:31:36 +0100 Ian Campbell <[email protected]> wrote:
Quoted 30 lines · Mukesh Rathor
Quoted 26 lines · On Wed, 3 Oct 2012 16:42:43 +0100 Ian Campbell <[email protected]> wrote:
Quoted 10 lines
include/xen/xen-ops.h +0
-0@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsignedlong vstart, unsigned int order, void
xen_destroy_contiguous_region(unsigned long vstart, unsigned int order); structvm_area_struct;
+structxen_pvh_pfn_info;If you move the struct def'n up you don't need this forward decl.
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 36
Quoted 10 lines
int xen_remap_domain_mfn_range(struct
vm_area_struct*vma,include/xen/xen-ops.h +6
-1unsigned long addr, unsigned long mfn, int nr, - pgprot_t prot, unsigned domid); + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info {Can we call this
xen_remap_mfn_infoor something? PVH is x86 specific while this struct is also useful on ARM.
Quoted 3 lines
Quoted 1 line
I already renamed it to:
xen_xlat_pfn_info.BTW, where can I find you latest patches?
In my local tree here. Will be submitting v3 soon.
Quoted 2 lines
I've just noticed that you've not been CCing LKML with this series -- was that deliberate?
I was told I didn't need to since there is no common code change.
thanks
Mukesh
Quoted 34 lines · Mukesh Rathor
Quoted 31 lines · On Thu, 4 Oct 2012 09:31:36 +0100 Ian Campbell <[email protected]> wrote:
Quoted 30 lines · Mukesh Rathor
Quoted 26 lines · On Wed, 3 Oct 2012 16:42:43 +0100 Ian Campbell <[email protected]> wrote:
Quoted 10 lines
include/xen/xen-ops.h +0
-0@@ -24,9 +24,19 @@ int xen_create_contiguous_region(unsignedlong vstart, unsigned int order, void
xen_destroy_contiguous_region(unsigned long vstart, unsigned int order); structvm_area_struct;
+structxen_pvh_pfn_info;If you move the struct def'n up you don't need this forward decl.
include/xen/xen-ops.h int xen_create_contiguous_region(unsigned long vstart, unsigned int order, · line 36
Quoted 10 lines
int xen_remap_domain_mfn_range(struct
vm_area_struct*vma,include/xen/xen-ops.h +6
-1unsigned long addr, unsigned long mfn, int nr, - pgprot_t prot, unsigned domid); + pgprot_t prot, unsigned domid, + struct xen_pvh_pfn_info *pvhp); +int xen_unmap_domain_mfn_range (struct vm_area_struct *vma, +struct xen_pvh_pfn_info *pvhp); + +struct xen_pvh_pfn_info {Can we call this
xen_remap_mfn_infoor something? PVH is x86 specific while this struct is also useful on ARM.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I already renamed it to:
xen_xlat_pfn_info.BTW, where can I find you latest patches?
In my local tree here. Will be submitting v3 soon.
Great, thanks.
Quoted 4 lines
Quoted 2 lines
I've just noticed that you've not been CCing LKML with this series -- was that deliberate?
I was told I didn't need to since there is no common code change.
I always (try to) CC both regardless but I suppose that's not really a rule.
Ian.
arch/x86/xen/mmu.c void __init xen_hvm_init_mmu_ops(void) · line 2389
Quoted 10 lines · Mukesh Rathor
arch/x86/xen/mmu.c +9
-0+int pvh_rem_xen_p2m (unsigned long spfn,int count) +{ +struct xen_remove_from_physmap xrp; +int i, rc; + +for (i=0 ; i < count; i++) { + xrp.domid =DOMID_SELF ; + xrp.gpfn = spfn+i; + rc =HYPERVISOR_memory_op (XENMEM_remove_from_physmap, &xrp);
It seems that the current implementation of this hypercall in the h/v doesn't handle unmapping of foreign pages, since it requires that the page be owned by the domain whose P2M it is manipulating.
How did you fix this on the hypervisor side? I'd like to make sure I do things consistently on the ARM side.
Talking with Tim it seems like having foreign mappings in a p2m is a bit tricky and needs a bit of careful thought WRT reference counting etc.
Ian.
Quoted 9 lines
arch/x86/xen/mmu.c +9
-0+if (rc) { +pr_warn ("Failed to unmap pfn:%lx rc:%d done:%d\n" , + spfn+i, rc, i); +return 1 ; + } + } +return 0 ; +} +EXPORT_SYMBOL_GPL (pvh_rem_xen_p2m);
Quoted 17 lines · On Thu, 4 Oct 2012 14:54:47 +0100 Ian Campbell <[email protected]> wrote:
Quoted 11 lines · Mukesh Rathor
arch/x86/xen/mmu.c +9
-0+int pvh_rem_xen_p2m (unsigned long spfn,int count) +{ +struct xen_remove_from_physmap xrp; +int i, rc; + +for (i=0 ; i < count; i++) { + xrp.domid =DOMID_SELF ; + xrp.gpfn = spfn+i; + rc =
HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrp);It seems that the current implementation of this hypercall in the h/v doesn't handle unmapping of foreign pages, since it requires that the page be owned by the domain whose P2M it is manipulating.
Quoted 6 lines
How did you fix this on the hypervisor side? I'd like to make sure I do things consistently on the ARM side.
Talking with Tim it seems like having foreign mappings in a p2m is a bit tricky and needs a bit of careful thought WRT reference counting etc.
Hey Ian,
This is what I've (don't worry about "hybrid" word for now, i'll fix it):
casee XENMEM_remove_from_physmap:
{
struct xen_remove_from_physmap xrfp;
struct page_info *page;
struct domain *d;
p2m_type_t p2mt;
if ( copy_from_guest(&xrfp, arg, 1) )
return -EFAULT;
rc = rcu_lock_target_domain_by_id(xrfp.domid, &d);
if ( rc != 0 )
return rc;
if ( xsm_remove_from_physmap(current->domain, d) )
{
rcu_unlock_domain(d);
return -EPERM;
}
domain_lock(d);
page = get_page_from_gfn(d, xrfp.gpfn, &p2mt, P2M_ALLOC);
if ( page || (is_hybrid_vcpu(current) &&
(p2m_is_mmio(p2mt) || p2m_is_foreign(p2mt))) )
{
unsigned long argmfn = page ? page_to_mfn(page) : INVALID_MFN;
guest_physmap_remove_page(d, xrfp.gpfn, argmfn, 0);
if (page)
put_page(page);
}
else {
if ( is_hybrid_vcpu(current) )
gdprintk(XENLOG_WARNING, "%s: Domain:%u gmfn:%lx invalid\n",
__FUNCTION__, current->domain->domain_id, xrfp.gpfn);
rc = -ENOENT;
}
domain_unlock(d);
rcu_unlock_domain(d);
break;
}