Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xen: support priv-mapping in an HVM tools domain

If the domain has XENFEAT_auto_translated_physmap then use of the PV-
specific HYPERVISOR_mmu_update hypercall is clearly incorrect.

This patch adds checks in xen_remap_domain_gfn_array() and
xen_unmap_domain_gfn_array() which call through to the approprate
xlate_mmu function if the feature is present. A check is also added
to xen_remap_domain_gfn_range() to fail with -EOPNOTSUPP since this
should not be used in an HVM tools domain.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>

authored by

Paul Durrant and committed by
Boris Ostrovsky
ec4001c3 773aaadc

+36 -2
+12 -2
arch/x86/xen/mmu.c
··· 172 172 pgprot_t prot, unsigned domid, 173 173 struct page **pages) 174 174 { 175 + if (xen_feature(XENFEAT_auto_translated_physmap)) 176 + return -EOPNOTSUPP; 177 + 175 178 return do_remap_gfn(vma, addr, &gfn, nr, NULL, prot, domid, pages); 176 179 } 177 180 EXPORT_SYMBOL_GPL(xen_remap_domain_gfn_range); ··· 185 182 int *err_ptr, pgprot_t prot, 186 183 unsigned domid, struct page **pages) 187 184 { 185 + if (xen_feature(XENFEAT_auto_translated_physmap)) 186 + return xen_xlate_remap_gfn_array(vma, addr, gfn, nr, err_ptr, 187 + prot, domid, pages); 188 + 188 189 /* We BUG_ON because it's a programmer error to pass a NULL err_ptr, 189 190 * and the consequences later is quite hard to detect what the actual 190 191 * cause of "wrong memory was mapped in". ··· 200 193 201 194 /* Returns: 0 success */ 202 195 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma, 203 - int numpgs, struct page **pages) 196 + int nr, struct page **pages) 204 197 { 205 - if (!pages || !xen_feature(XENFEAT_auto_translated_physmap)) 198 + if (xen_feature(XENFEAT_auto_translated_physmap)) 199 + return xen_xlate_unmap_gfn_range(vma, nr, pages); 200 + 201 + if (!pages) 206 202 return 0; 207 203 208 204 return -EINVAL;
+24
include/xen/xen-ops.h
··· 104 104 struct page **pages); 105 105 int xen_unmap_domain_gfn_range(struct vm_area_struct *vma, 106 106 int numpgs, struct page **pages); 107 + 108 + #ifdef CONFIG_XEN_AUTO_XLATE 107 109 int xen_xlate_remap_gfn_array(struct vm_area_struct *vma, 108 110 unsigned long addr, 109 111 xen_pfn_t *gfn, int nr, ··· 114 112 struct page **pages); 115 113 int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma, 116 114 int nr, struct page **pages); 115 + #else 116 + /* 117 + * These two functions are called from arch/x86/xen/mmu.c and so stubs 118 + * are needed for a configuration not specifying CONFIG_XEN_AUTO_XLATE. 119 + */ 120 + static inline int xen_xlate_remap_gfn_array(struct vm_area_struct *vma, 121 + unsigned long addr, 122 + xen_pfn_t *gfn, int nr, 123 + int *err_ptr, pgprot_t prot, 124 + unsigned int domid, 125 + struct page **pages) 126 + { 127 + return -EOPNOTSUPP; 128 + } 129 + 130 + static inline int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma, 131 + int nr, struct page **pages) 132 + { 133 + return -EOPNOTSUPP; 134 + } 135 + #endif 136 + 117 137 int xen_xlate_map_ballooned_pages(xen_pfn_t **pfns, void **vaddr, 118 138 unsigned long nr_grant_frames); 119 139