xen/privcmd: add IOCTL_PRIVCMD_MMAP_RESOURCE
Subsystems (5)
PATCH v5 1/1 xen/privcmd: add IOCTL_PRIVCMD_MMAP_RESOURCE
My recent Xen patch series introduces a new HYPERVISOR_memory_op to support direct priv-mapping of certain guest resources (such as ioreq pages, used by emulators) by a tools domain, rather than having to access such resources via the guest P2M.
This patch adds the necessary infrastructure to the privcmd driver and Xen MMU code to support direct resource mapping.
NOTE: The adjustment in the MMU code is partially cosmetic. Xen will now
allow a PV tools domain to map guest pages either by GFN or MFN, thus the term 'mfn' has been swapped for 'pfn' in the lower layers of the remap code.
---
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Stefano Stabellini <[email protected]>
v5:
- Handle the case of xen_feature(XENFEAT_auto_translated_physmap) && (PAGE_SIZE > XEN_PAGE_SIZE)
v4:
- Remove stray line of debug that causes a build warning on ARM 32-bit
v3:
- Addres comments from Boris
- Fix ARM build
v2:
- Fix bug when mapping multiple pages of a resource
--- arch/arm/xen/enlighten.c | 11 ++++ arch/x86/xen/mmu.c | 60 +++++++++++++------ drivers/xen/privcmd.c | 133 +++++++++++++++++++++++++++++++++++++++++ include/uapi/xen/privcmd.h | 11 ++++ include/xen/interface/memory.h | 66 ++++++++++++++++++++ include/xen/interface/xen.h | 7 ++- include/xen/xen-ops.h | 24 +++++++- 7 files changed, 291 insertions(+), 21 deletions(-)
arch/arm/xen/enlighten.c +11 -0
@@ -89,6 +89,17 @@ int xen_unmap_domain_gfn_range(struct vm_area_struct *vma, }EXPORT_SYMBOL_GPL (xen_unmap_domain_gfn_range); +/* Not used by XENFEAT_auto_translated guests. */ +int xen_remap_domain_mfn_array (struct vm_area_struct *vma, +unsigned long addr, +xen_pfn_t *mfn,int nr, +int *err_ptr,pgprot_t prot, +unsigned int domid,struct page **pages) +{ +return -ENOSYS ; +} +EXPORT_SYMBOL_GPL (xen_remap_domain_mfn_array); +static void xen_read_wallclock (struct timespec64 *ts) {u32 version;
arch/x86/xen/mmu.c +43 -17
115 lines not on this page · raw message
drivers/xen/privcmd.c +133 -0
151 lines not on this page · raw message
include/uapi/xen/privcmd.h +11 -0
@@ -89,6 +89,15 @@ struct privcmd_dm_op {const struct privcmd_dm_op_buf __user *ubufs; }; +struct privcmd_mmap_resource { +domid_t dom; +__u32 type; +__u32 id; +__u32 idx; +__u64 num; +__u64 addr; +}; +/* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t
@@ -114,5 +123,7 @@ struct privcmd_dm_op { _IOC(_IOC_NONE, 'P', 5, sizeof(struct privcmd_dm_op))#define IOCTL_PRIVCMD_RESTRICT \ _IOC(_IOC_NONE, 'P', 6, sizeof(domid_t)) +#define IOCTL_PRIVCMD_MMAP_RESOURCE \ + _IOC(_IOC_NONE, 'P', 7, sizeof(struct privcmd_mmap_resource))#endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
include/xen/interface/memory.h +66 -0
70 lines not on this page · raw message
include/xen/interface/xen.h +4 -3
@@ -265,9 +265,10 @@* * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7. */ -#define MMU_NORMAL_PT_UPDATE 0/* checked '*ptr = val'. ptr is MA. */ -#define MMU_MACHPHYS_UPDATE 1/* ptr = MA of frame to modify entry for */ -#define MMU_PT_UPDATE_PRESERVE_AD 2/* atomically: *ptr = val | (*ptr&(A|D)) */ +#define MMU_NORMAL_PT_UPDATE 0/* checked '*ptr = val'. ptr is MA. */ +#define MMU_MACHPHYS_UPDATE 1/* ptr = MA of frame to modify entry for */ +#define MMU_PT_UPDATE_PRESERVE_AD 2/* atomically: *ptr = val | (*ptr&(A|D)) */ +#define MMU_PT_UPDATE_NO_TRANSLATE 3/* checked '*ptr = val'. ptr is MA. */ /* * MMU EXTENDED OPERATIONS
include/xen/xen-ops.h +23 -1
@@ -63,7 +63,7 @@ static inline void xen_destroy_contiguous_region(phys_addr_t pstart,struct vm_area_struct ;/* -* xen_remap_domain_gfn_array() - map an array of foreign frames +* xen_remap_domain_gfn_array() - map an array of foreign frames by gfn * @vma: VMA to map the pages into * @addr: Address at which to map the pages * @gfn: Array of GFNs to map
@@ -86,6 +86,28 @@ int xen_remap_domain_gfn_array(struct vm_area_struct *vma,unsigned domid, struct page **pages); +/* +* xen_remap_domain_mfn_array() - map an array of foreign frames by mfn +* @vma: VMA to map the pages into +* @addr: Address at which to map the pages +* @mfn: Array of MFNs to map +* @nr: Number entries in the MFN array +* @err_ptr: Returns per-MFN error status. +* @prot: page protection mask +* @domid: Domain owning the pages +* @pages: Array of pages if this domain has an auto-translated physmap +* +* @mfn and @err_ptr may point to the same buffer, the MFNs will be +* overwritten by the error codes after they are mapped. +* +* Returns the number of successfully mapped frames, or a -ve error +* code. +*/ +int xen_remap_domain_mfn_array (struct vm_area_struct *vma, +unsigned long addr,xen_pfn_t *mfn,int nr, +int *err_ptr,pgprot_t prot, +unsigned int domid,struct page **pages); +/* xen_remap_domain_gfn_range() - map a range of foreign frames * @vma: VMA to map the pages into * @addr: Address at which to map the pages
Signature · 1 line
2.11.0