xen/privcmd: add IOCTL_PRIVCMD_MMAP_RESOURCE
Subsystems (5)
PATCH v3 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: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Stefano Stabellini <[email protected]>
v2:
- Fix bug when mapping multiple pages of a resource
v3:
- Addres comments from Boris
- Fix ARM build
--- arch/arm/xen/enlighten.c | 11 ++++ arch/x86/xen/mmu.c | 60 +++++++++++++------ drivers/xen/privcmd.c | 130 +++++++++++++++++++++++++++++++++++++++++ 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, 288 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 +130 -0
148 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
Quoted 8 lines · Paul Durrant
My recent Xen patch series introduces a new
HYPERVISOR_memory_opto 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.
Quoted 6 lines
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.Signed-off-by Paul Durrant <[email protected]>
I think this will have to wait until 4.18 though, it's somewhat late for current merge window right now.
-boris
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 8 lines · Paul Durrant
My recent Xen patch series introduces a new
HYPERVISOR_memory_opto 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.
Quoted 6 lines
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.Signed-off-by Paul Durrant <[email protected]>
I think this will have to wait until 4.18 though, it's somewhat late for current merge window right now.
-boris
Boris Ostrovsky
reviewerQuoted 14 lines · Boris Ostrovsky
Quoted 13 lines · Paul Durrant
My recent Xen patch series introduces a new
HYPERVISOR_memory_opto 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.
Quoted 5 lines
Quoted 1 line
Signed-off-by Paul Durrant <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>I think this will have to wait until 4.18 though, it's somewhat late for current merge window right now.
Warns on 32-bit ARM build:
CC drivers/xen/privcmd.o
In file included from /data/upstream/linux-xen/include/linux/kernel.h:14:0, from /data/upstream/linux-xen/drivers/xen/privcmd.c:11:
/data/upstream/linux-xen/drivers/xen/privcmd.c: In function ‘privcmd_ioctl_mmap_resource’:
/data/upstream/linux-xen/drivers/xen/privcmd.c:788:33: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] pr_info("pfn[%u] = %p\n", i, (void *)pfns[i]);
^ /data/upstream/linux-xen/include/linux/printk.h:308:34: note: in definition of macro ‘pr_info’
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
^~~~~~~~~~~
AR drivers/xen/xen-privcmd.o
-boris
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Boris Ostrovsky
reviewerQuoted 14 lines · Boris Ostrovsky
Quoted 13 lines · Paul Durrant
My recent Xen patch series introduces a new
HYPERVISOR_memory_opto 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.
Quoted 5 lines
Quoted 1 line
Signed-off-by Paul Durrant <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>I think this will have to wait until 4.18 though, it's somewhat late for current merge window right now.
Warns on 32-bit ARM build:
CC drivers/xen/privcmd.o
In file included from /data/upstream/linux-xen/include/linux/kernel.h:14:0, from /data/upstream/linux-xen/drivers/xen/privcmd.c:11:
/data/upstream/linux-xen/drivers/xen/privcmd.c: In function ‘privcmd_ioctl_mmap_resource’:
/data/upstream/linux-xen/drivers/xen/privcmd.c:788:33: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] pr_info("pfn[%u] = %p\n", i, (void *)pfns[i]);
^ /data/upstream/linux-xen/include/linux/printk.h:308:34: note: in definition of macro ‘pr_info’
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
^~~~~~~~~~~
AR drivers/xen/xen-privcmd.o
-boris
Quoted 38 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:boris.ostrovsky at oracle.com]
Sent: 09 April 2018 20:19
To: Paul Durrant <[email protected]>; xen-devel at lists.xenproject.org; linux-arm-kernel at lists.infradead.org; linux-kernel at vger.kernel.org
Cc: Juergen Gross <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v3] xen/privcmd: addIOCTL_PRIVCMD_MMAP_RESOURCEQuoted 2 lines · Boris Ostrovsky
Quoted 1 line · Paul Durrant
My recent Xen patch series introduces a new
HYPERVISOR_memory_opto
Quoted 8 lines
Quoted 8 lines
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
Quoted 1 line
Quoted 1 line
allow a PV tools domain to map guest pages either by GFN or MFN,
thus
Quoted 8 lines
Quoted 4 lines
the term 'mfn' has been swapped for 'pfn' in the lower layers of the remap code.
Signed-off-by Paul Durrant <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>I think this will have to wait until 4.18 though, it's somewhat late for current merge window right now.
Warns on 32-bit ARM build:
Quoted 8 lines
? CC?????
drivers/xen/privcmd.o
In file included from /data/upstream/linux-xen/include/linux/kernel.h:14:0, ???????????????? from /data/upstream/linux-xen/drivers/xen/privcmd.c:11:
/data/upstream/linux-xen/drivers/xen/privcmd.c: In function ?privcmd_ioctl_mmap_resource?:
/data/upstream/linux-xen/drivers/xen/privcmd.c:788:33: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] ???pr_info("pfn[%u] = %p\n", i, (void *)pfns[i]);
I'm glad that was caught. It was a line of debug that was supposed to have been removed.
Paul
Quoted 9 lines
???????????????????????????????? ^ /data/upstream/linux-xen/include/linux/printk.h:308:34: note: in definition of macro ?pr_info?
?printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)????????????????????????????????? ^~~~~~~~~~~
? AR?????drivers/xen/xen-privcmd.o-boris
Quoted 38 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 09 April 2018 20:19
To: Paul Durrant <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Juergen Gross <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v3] xen/privcmd: addIOCTL_PRIVCMD_MMAP_RESOURCEQuoted 2 lines · Boris Ostrovsky
Quoted 1 line · Paul Durrant
My recent Xen patch series introduces a new
HYPERVISOR_memory_opto
Quoted 8 lines
Quoted 8 lines
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
Quoted 1 line
Quoted 1 line
allow a PV tools domain to map guest pages either by GFN or MFN,
thus
Quoted 8 lines
Quoted 4 lines
the term 'mfn' has been swapped for 'pfn' in the lower layers of the remap code.
Signed-off-by Paul Durrant <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>I think this will have to wait until 4.18 though, it's somewhat late for current merge window right now.
Warns on 32-bit ARM build:
Quoted 8 lines
CC
drivers/xen/privcmd.o
In file included from /data/upstream/linux-xen/include/linux/kernel.h:14:0, from /data/upstream/linux-xen/drivers/xen/privcmd.c:11:
/data/upstream/linux-xen/drivers/xen/privcmd.c: In function ‘privcmd_ioctl_mmap_resource’:
/data/upstream/linux-xen/drivers/xen/privcmd.c:788:33: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]pr_info("pfn[%u] = %p\n", i, (void *)pfns[i]);
I'm glad that was caught. It was a line of debug that was supposed to have been removed.
Paul
Quoted 9 lines
^ /data/upstream/linux-xen/include/linux/printk.h:308:34: note: in definition of macro ‘pr_info’
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)^~~~~~~~~~~
ARdrivers/xen/xen-privcmd.o-boris
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel