Support for running secondary emulators
v8 cover Support for running secondary emulators
This patch series adds the ioreq server interface which I mentioned in my talk at the Xen developer summit in Edinburgh at the end of last year. The code is based on work originally done by Julien Grall but has been re-written to allow existing versions of QEMU to work unmodified.
The code is available in my xen.git [1] repo on xenbits, under the 'savannah8+' branch, and I have also written a demo emulator to test the code, which can be found in my demu.git [2] repo.
The series has been re-worked since v7. The modifications are now broken down as follows:
(Patches #1 - #6 of the v7 series have already been applied)
Patch #1 makes the single ioreq server of previous patches into the default ioreq server and introduces an API for creating secondary servers.
Patch #2 adds an enable/disable operation to the API for secondary servers which makes sure that they cannot be active whilst their shared pages are present in the guest's P2M.
Patch #3 adds makes handling buffered ioreqs optional for secondary servers. This saves a page of memory per server.
The hotplug controller patch of previous versions of this series has been dropped to give me more time for testing, and possible re-factoring. This means that, for now, bus rescans will need to be invoked from within the guest to notice devices provided by secondary emulators coming and going.
The demo emulator can simply be invoked from a shell. The emulated device is not an awful lot of use at this stage - it appears as a SCSI controller with one IO BAR and one MEM BAR and has no intrinsic functionality... but then it is only supposed to be demo :-)
Paul
[1] http://xenbits.xen.org/gitweb/?p=people/pauldu/xen.git
[2] http://xenbits.xen.org/gitweb/?p=people/pauldu/demu.git
v2:
- First non-RFC posting
v3:
- Addressed comments from Jan Beulich
v4:
- Addressed comments from Ian Campbell and George Dunlap
- Series heavily re-worked, 2 patches added
v5:
- One more patch added to separate out a bug-fix, as requested by Jan Beulich
- Switched to using rangesets as suggested by Jan Beulich
- Changed domain restore path as requested by Ian Campbell
- Added documentation for new hypercalls and libxenctrl API as requested by Ian Campbell
- Added handling of multi-byte GPE I/O as suggested by Jan Beulich
v6:
- Bugfix patch dropped as it has already been taken
- Addressed various comments from Jan Beulich and Ian Campbell
- Split out the addition of asprintf() into a separate patch
- Dropped hotplug controller patch for now, to allow more time for testing
- Split out rangeset patch and make range limit optional parameter
- Added missing XSM checks
v7:
- Addressed more comments from Jan Beulich
- Backed out argument change to rangset_new() in favour of new rangeset_limit() function
v8:
- Addressed more comments from Jan Beulich:
- Patch #1 (or patch #7 as-was) is the only patch that has been significantly modified (in hypervisor code)
- Patches #2 and #3 are (hopefully now) fixed for style and hence marked as acked. (There were no functional mods.)
- Fixed error message nit pointed out by Ian Campbell:
- Error message change in domain restore code in patch #1
PATCH v8 1/3 ioreq-server: add support for multiple servers
The previous single ioreq server that was created on demand now becomes the default server and an API is created to allow secondary servers, which handle specific IO ranges or PCI devices, to be added.
When the guest issues an IO the list of secondary servers is checked for a matching IO range or PCI device. If none is found then the IO is passed to the default server.
Secondary servers use guest pages to communicate with emulators, in the same way as the default server. These pages need to be in the guest physmap otherwise there is no suitable reference that can be queried by an emulator in order to map them. Therefore a pool of pages in the current E820 reserved region, just below the special pages is used. Secondary servers allocate from and free to this pool as they are created and destroyed.
The size of the pool is currently hardcoded in the domain build at a value of 8. This should be sufficient for now and both the location and size of the pool can be modified in future without any need to change the API.
--- tools/libxc/xc_domain.c | 224 ++++++++++ tools/libxc/xc_domain_restore.c | 48 ++ tools/libxc/xc_domain_save.c | 24 + tools/libxc/xc_hvm_build_x86.c | 50 ++- tools/libxc/xc_private.c | 16 +- tools/libxc/xenctrl.h | 143 +++++- tools/libxc/xg_save_restore.h | 3 + xen/arch/x86/hvm/hvm.c | 913 ++++++++++++++++++++++++++++++++++---- xen/arch/x86/hvm/io.c | 2 +- xen/include/asm-x86/hvm/domain.h | 27 +- xen/include/asm-x86/hvm/hvm.h | 1 + xen/include/public/hvm/hvm_op.h | 120 +++++ xen/include/public/hvm/ioreq.h | 9 +- xen/include/public/hvm/params.h | 5 +- xen/include/xen/list.h | 9 + xen/include/xsm/dummy.h | 6 + xen/include/xsm/xsm.h | 6 + xen/xsm/flask/hooks.c | 6 + 18 files changed, 1502 insertions(+), 110 deletions(-)
tools/libxc/xc_domain.c +224 -0
@@ -1284,6 +1284,230 @@ int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned longreturn rc; } +int xc_hvm_create_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t *id) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_create_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_create_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + + arg->domid = domid; + + rc =do_xen_hypercall (xch, &hypercall); + + *id = arg->id; + +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_get_ioreq_server_info (xc_interface *xch, +domid_t domid, +ioservid_t id, +xen_pfn_t *ioreq_pfn, +xen_pfn_t *bufioreq_pfn, +evtchn_port_t *bufioreq_port) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_get_ioreq_server_info_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_get_ioreq_server_info; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + + arg->domid = domid; + arg->id = id; + + rc =do_xen_hypercall (xch, &hypercall); +if ( rc !=0 ) + goto done; + +if ( ioreq_pfn ) + *ioreq_pfn = arg->ioreq_pfn; + +if ( bufioreq_pfn ) + *bufioreq_pfn = arg->bufioreq_pfn; + +if ( bufioreq_port ) + *bufioreq_port = arg->bufioreq_port; + +done: +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_map_io_range_to_ioreq_server (xc_interface *xch,domid_t domid, +ioservid_t id,int is_mmio, +uint64_t start,uint64_t end) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_io_range_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_map_io_range_to_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + + arg->domid = domid; + arg->id = id; + arg->type = is_mmio ?HVMOP_IO_RANGE_MEMORY :HVMOP_IO_RANGE_PORT ; + arg->start = start; + arg->end = end; + + rc =do_xen_hypercall (xch, &hypercall); + +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_unmap_io_range_from_ioreq_server (xc_interface *xch,domid_t domid, +ioservid_t id,int is_mmio, +uint64_t start,uint64_t end) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_io_range_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_unmap_io_range_from_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + + arg->domid = domid; + arg->id = id; + arg->type = is_mmio ?HVMOP_IO_RANGE_MEMORY :HVMOP_IO_RANGE_PORT ; + arg->start = start; + arg->end = end; + + rc =do_xen_hypercall (xch, &hypercall); + +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_map_pcidev_to_ioreq_server (xc_interface *xch,domid_t domid, +ioservid_t id,uint16_t segment, +uint8_t bus,uint8_t device, +uint8_t function) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_io_range_t, arg); +int rc; + +if (device >0x1f || function >0x7 ) { + errno =EINVAL ; +return -1 ; + } + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_map_io_range_to_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + + arg->domid = domid; + arg->id = id; + arg->type =HVMOP_IO_RANGE_PCI ; + +/* +* The underlying hypercall will deal with ranges of PCI SBDF +* but, for simplicity, the API only uses singletons. +*/ + arg->start = arg->end =HVMOP_PCI_SBDF ((uint64_t )segment, + (uint64_t )bus, + (uint64_t )device, + (uint64_t )function); + + rc =do_xen_hypercall (xch, &hypercall); + +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_unmap_pcidev_from_ioreq_server (xc_interface *xch,domid_t domid, +ioservid_t id,uint16_t segment, +uint8_t bus,uint8_t device, +uint8_t function) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_io_range_t, arg); +int rc; + +if (device >0x1f || function >0x7 ) { + errno =EINVAL ; +return -1 ; + } + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_unmap_io_range_from_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + + arg->domid = domid; + arg->id = id; + arg->type =HVMOP_IO_RANGE_PCI ; + arg->start = arg->end =HVMOP_PCI_SBDF ((uint64_t )segment, + (uint64_t )bus, + (uint64_t )device, + (uint64_t )function); + + rc =do_xen_hypercall (xch, &hypercall); + +xc_hypercall_buffer_free (xch, arg); +return rc; +} + +int xc_hvm_destroy_ioreq_server (xc_interface *xch, +domid_t domid, +ioservid_t id) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_destroy_ioreq_server_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_destroy_ioreq_server; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + + arg->domid = domid; + arg->id = id; + + rc =do_xen_hypercall (xch, &hypercall); + +xc_hypercall_buffer_free (xch, arg); +return rc; +} +int xc_domain_setdebugging (xc_interface *xch,uint32_t domid,unsigned int enable)
tools/libxc/xc_domain_restore.c +48 -0
72 lines not on this page · raw message
tools/libxc/xc_domain_save.c +24 -0
@@ -1737,6 +1737,30 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterPERROR ("Error when writing the viridian flag" ); goto out; } + + chunk.id =XC_SAVE_ID_HVM_IOREQ_SERVER_PFN ; + chunk.data =0 ; +xc_get_hvm_param (xch, dom,HVM_PARAM_IOREQ_SERVER_PFN , + (unsigned long *)&chunk.data); + +if ( (chunk.data !=0 ) && +wrexact (io_fd, &chunk,sizeof (chunk)) ) + { +PERROR ("Error when writing the ioreq server gmfn base" ); + goto out; + } + + chunk.id =XC_SAVE_ID_HVM_NR_IOREQ_SERVER_PAGES ; + chunk.data =0 ; +xc_get_hvm_param (xch, dom,HVM_PARAM_NR_IOREQ_SERVER_PAGES , + (unsigned long *)&chunk.data); + +if ( (chunk.data !=0 ) && +wrexact (io_fd, &chunk,sizeof (chunk)) ) + { +PERROR ("Error when writing the ioreq server gmfn count" ); + goto out; + } }if ( callbacks !=NULL && callbacks->toolstack_save !=NULL )
tools/libxc/xc_hvm_build_x86.c +40 -10
83 lines not on this page · raw message
tools/libxc/xc_private.c +9 -7
@@ -628,17 +628,19 @@ int xc_copy_to_domain_page(xc_interface *xch,return 0 ; } -int xc_clear_domain_page (xc_interface *xch, -uint32_t domid, -unsigned long dst_pfn) +int xc_clear_domain_pages (xc_interface *xch, +uint32_t domid, +unsigned long dst_pfn, +int num) { +size_t size = num *PAGE_SIZE ;void *vaddr =xc_map_foreign_range ( - xch, domid,PAGE_SIZE ,PROT_WRITE , dst_pfn); + xch, domid, size,PROT_WRITE , dst_pfn);if ( vaddr ==NULL )return -1 ; -memset (vaddr,0 ,PAGE_SIZE ); -munmap (vaddr,PAGE_SIZE ); -xc_domain_cacheflush (xch, domid, dst_pfn,1 ); +memset (vaddr,0 , size); +munmap (vaddr, size); +xc_domain_cacheflush (xch, domid, dst_pfn, num);return 0 ; }
tools/libxc/xenctrl.h +141 -2
158 lines not on this page · raw message
tools/libxc/xg_save_restore.h +3 -0
@@ -259,6 +259,9 @@#define XC_SAVE_ID_HVM_ACCESS_RING_PFN -16#define XC_SAVE_ID_HVM_SHARING_RING_PFN -17#define XC_SAVE_ID_TOOLSTACK -18/* Optional toolstack specific info */ +/* These are a pair; it is an error for one to exist without the other */ +#define XC_SAVE_ID_HVM_IOREQ_SERVER_PFN -19 +#define XC_SAVE_ID_HVM_NR_IOREQ_SERVER_PAGES -20/* ** We process save/restore/migrate in batches of pages; the below
xen/arch/x86/hvm/hvm.c +827 -86
1,171 lines not on this page · raw message
xen/arch/x86/hvm/io.c +1 -1
@@ -74,7 +74,7 @@ void send_invalidate_req(void) .data = ~0UL, /* flush all */ }; - (void )hvm_send_assist_req (&p); +hvm_broadcast_assist_req (&p); }int handle_mmio (void )
xen/include/asm-x86/hvm/domain.h +25 -2
@@ -34,8 +34,10 @@#include <public/grant_table.h> #include <public/hvm/params.h> #include <public/hvm/save.h> +#include <public/hvm/hvm_op.h> struct hvm_ioreq_page { +unsigned long gmfn;struct page_info *page;void *va; };
@@ -46,7 +48,11 @@ struct hvm_ioreq_vcpu {evtchn_port_t ioreq_evtchn; }; +#define NR_IO_RANGE_TYPES (HVMOP_IO_RANGE_PCI + 1) +#define MAX_NR_IO_RANGES 256 +struct hvm_ioreq_server { +struct list_head list_entry;struct domain *domain;/* Lock to serialize toolstack modifications */
@@ -54,6 +60,7 @@ struct hvm_ioreq_server {/* Domain id of emulating domain */ domid_t domid; +ioservid_t id;struct hvm_ioreq_page ioreq;struct list_head ioreq_vcpu_list;struct hvm_ioreq_page bufioreq;
@@ -61,11 +68,27 @@ struct hvm_ioreq_server {/* Lock to serialize access to buffered ioreq ring */ spinlock_t bufioreq_lock;evtchn_port_t bufioreq_evtchn; +struct rangeset *range[NR_IO_RANGE_TYPES ]; };struct hvm_domain { -spinlock_t ioreq_server_lock; -struct hvm_ioreq_server *ioreq_server; +/* Guest page range used for non-default ioreq servers */ +struct { +unsigned long base; +unsigned long mask; +unsigned int count; + } ioreq_gmfn; + +/* Lock protects all other values in the sub-struct and the default */ +struct { +spinlock_t lock; +ioservid_t id; +struct list_head list; + } ioreq_server; +struct hvm_ioreq_server *default_ioreq_server; + +/* Cached CF8 for guest PCI config cycles */ +uint32_t pci_cf8;struct pl_time pl_time;
xen/include/asm-x86/hvm/hvm.h +1 -0
@@ -233,6 +233,7 @@ int prepare_ring_for_helper(struct domain *d, unsigned long gmfn,void destroy_ring_for_helper (void **_va,struct page_info *page);bool_t hvm_send_assist_req (ioreq_t *p); +void hvm_broadcast_assist_req (ioreq_t *p);void hvm_get_guest_pat (struct vcpu *v,u64 *guest_pat);int hvm_set_guest_pat (struct vcpu *v,u64 guest_pat);
xen/include/public/hvm/hvm_op.h +120 -0
132 lines not on this page · raw message
xen/include/public/hvm/ioreq.h +8 -1
@@ -34,13 +34,20 @@#define IOREQ_TYPE_PIO 0/* pio */ #define IOREQ_TYPE_COPY 1/* mmio ops */ +#define IOREQ_TYPE_PCI_CONFIG 2#define IOREQ_TYPE_TIMEOFFSET 7#define IOREQ_TYPE_INVALIDATE 8/* mapcache */ /* * VMExit dispatcher should cooperate with instruction decoder to * prepare this structure and notify service OS and DM by sending -* virq +* virq. +* +* For I/O type IOREQ_TYPE_PCI_CONFIG, the physical address is formatted +* as follows: +* +* 63....48|47..40|39..35|34..32|31........0 +* SEGMENT |BUS |DEV |FN |OFFSET */ struct ioreq {uint64_t addr;/* physical address */
xen/include/public/hvm/params.h +4 -1
@@ -145,6 +145,9 @@/* SHUTDOWN_* action in case of a triple fault */ #define HVM_PARAM_TRIPLE_FAULT_REASON 31 -#define HVM_NR_PARAMS 32 +#define HVM_PARAM_IOREQ_SERVER_PFN 32 +#define HVM_PARAM_NR_IOREQ_SERVER_PAGES 33 + +#define HVM_NR_PARAMS 34#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
xen/include/xen/list.h +9 -0
@@ -304,6 +304,15 @@ static inline int list_empty(const struct list_head *head) }/** +* list_is_singular - tests whether a list has exactly one entry +* @head: the list to test. +*/ +static inline int list_is_singular (const struct list_head *head) +{ +return !list_empty (head) && (head->next == head->prev); +} + +/** * list_empty_careful - tests whether a list is empty and not being modified * @head: the list to test *
xen/include/xsm/dummy.h +6 -0
@@ -538,6 +538,12 @@ static XSM_INLINE int xsm_hvm_inject_msi(XSM_DEFAULT_ARG struct domain *d)return xsm_default_action (action, current->domain, d); } +static XSM_INLINE int xsm_hvm_ioreq_server(XSM_DEFAULT_ARG struct domain *d, int op) +{ +XSM_ASSERT_ACTION (XSM_DM_PRIV ); +return xsm_default_action (action, current->domain, d); +} + static XSM_INLINE int xsm_mem_event_control(XSM_DEFAULT_ARG struct domain *d, int mode, int op) {XSM_ASSERT_ACTION (XSM_PRIV );
xen/include/xsm/xsm.h +6 -0
@@ -146,6 +146,7 @@ struct xsm_operations {int (*hvm_set_isa_irq_level) (struct domain *d);int (*hvm_set_pci_link_route) (struct domain *d);int (*hvm_inject_msi) (struct domain *d); +int (*hvm_ioreq_server) (struct domain *d,int op);int (*mem_event_control) (struct domain *d,int mode,int op);int (*mem_event_op) (struct domain *d,int op);int (*mem_sharing_op) (struct domain *d,struct domain *cd,int op);
@@ -558,6 +559,11 @@ static inline int xsm_hvm_inject_msi (xsm_default_t def, struct domain *d)return xsm_ops->hvm_inject_msi (d); } +static inline int xsm_hvm_ioreq_server (xsm_default_t def,struct domain *d,int op) +{ +return xsm_ops->hvm_ioreq_server (d, op); +} +static inline int xsm_mem_event_control (xsm_default_t def,struct domain *d,int mode,int op) {return xsm_ops->mem_event_control (d, mode, op);
xen/xsm/flask/hooks.c +6 -0
@@ -1286,6 +1286,11 @@ static int flask_hvm_inject_msi(struct domain *d)return current_has_perm (d,SECCLASS_HVM ,HVM__SEND_IRQ ); } +static int flask_hvm_ioreq_server (struct domain *d) +{ +return current_has_perm (d,SECCLASS_HVM ,HVM__HVMCTL ); +} +static int flask_mem_event_control (struct domain *d,int mode,int op) {return current_has_perm (d,SECCLASS_HVM ,HVM__MEM_EVENT );
@@ -1568,6 +1573,7 @@ static struct xsm_operations flask_ops = { .hvm_set_isa_irq_level = flask_hvm_set_isa_irq_level, .hvm_set_pci_link_route = flask_hvm_set_pci_link_route, .hvm_inject_msi = flask_hvm_inject_msi, + .hvm_ioreq_server = flask_hvm_ioreq_server, .mem_event_control = flask_mem_event_control, .mem_event_op = flask_mem_event_op, .mem_sharing_op = flask_mem_sharing_op,
Signature · 1 line
1.7.10.4
Re: [PATCH v8 1/3] ioreq-server: add support for multiple servers
xen/arch/x86/hvm/hvm.c static int hvm_print_line( · line 590
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.05.14 at 15:47, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +7
-0+static int hvm_access_cf8 ( +int dir,uint32_t port,uint32_t bytes,uint32_t *val) +{ +struct domain *d = current->domain; + +if ( dir ==IOREQ_WRITE && + bytes ==4 )
Don't you also need to check port == 0xcf8 here?
Quoted 8 lines
xen/arch/x86/hvm/hvm.c +8
-0+static ioservid_t next_ioservid (struct domain *d) +{ +struct hvm_ioreq_server *s; +ioservid_t id; + +ASSERT (spin_is_locked (&d->arch.hvm_domain.ioreq_server.lock)); + + id = d->arch.hvm_domain.ioreq_server.id;
xen/arch/x86/hvm/hvm.c static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, struct domain *d, · line 919
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+ + again: + id++; + +/* Check for uniqueness */ +list_for_each_entry ( s, + &d->arch.hvm_domain.ioreq_server.list, + list_entry ) + { +if (id == s->id)
The beloved coding style remark again.
Quoted 18 lines
xen/arch/x86/hvm/hvm.c +5
-4@@ -757,25 +937,34 @@ static int hvm_create_ioreq_server(struct domain *d, domid_t domid) goto fail1;domain_pause (d); -spin_lock (&d->arch.hvm_domain.ioreq_server_lock); +spin_lock (&d->arch.hvm_domain.ioreq_server.lock); rc = -EEXIST ; -if ( d->arch.hvm_domain.ioreq_server !=NULL ) +if ( is_default && d->arch.hvm_domain.default_ioreq_server !=NULL ) goto fail2; - rc =hvm_ioreq_server_init (s, d, domid); + rc =hvm_ioreq_server_init (s, d, domid, is_default, +next_ioservid (d));if ( rc ) - goto fail2; + goto fail3;
xen/arch/x86/hvm/hvm.c static int hvm_create_ioreq_server(struct domain *d, domid_t domid) · line 957
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +6
-2+ +list_add (&s->list_entry, + &d->arch.hvm_domain.ioreq_server.list); - d->arch.hvm_domain.ioreq_server = s; +if ( is_default ) + d->arch.hvm_domain.default_ioreq_server = s; -spin_unlock (&d->arch.hvm_domain.ioreq_server_lock); +if (id !=NULL )
And again.
Quoted 16 lines
xen/arch/x86/hvm/hvm.c +16
-0+static struct hvm_ioreq_server *hvm_select_ioreq_server (struct domain *d, +ioreq_t *p) +{ +#define CF8_BDF (cf8) (((cf8) & 0x00ffff00) >> 8) +#define CF8_ADDR_LO (cf8) ((cf8) & 0x000000fc) +#define CF8_ADDR_HI (cf8) (((cf8) & 0x0f000000) >> 16) +#define CF8_ENABLED (cf8) (!!((cf8) & 0x80000000)) + +struct hvm_ioreq_server *s; +uint32_t cf8; +uint8_t type; +uint64_t addr; + +if (list_empty (&d->arch.hvm_domain.ioreq_server.list) ) +return NULL ; +
xen/arch/x86/hvm/hvm.c void hvm_vcpu_down(struct vcpu *v) · line 2174
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+if (list_is_singular (&d->arch.hvm_domain.ioreq_server.list) || + (p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) ) +return d->arch.hvm_domain.default_ioreq_server; + + cf8 = d->arch.hvm_domain.pci_cf8; + +/* +* NOTE: Only types IOREQ_TYPE_PIO and IOREQ_TYPE_COPY are valid +* on entry. +*/
I realize this got added in response to my comments on the previous version, but just now I realized that you had already then added a respective check in the second if() above (which I missed). With that the comment seems rather useless.
Quoted 1 line
+
Line with only blanks.
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 79
Quoted 8 lines
struct
hvm_domain{xen/include/asm-x86/hvm/domain.h +5
-2-spinlock_t ioreq_server_lock; -struct hvm_ioreq_server *ioreq_server; +/* Guest page range used for non-default ioreq servers */ +struct { +unsigned long base; +unsigned long mask; +unsigned int count;
Do you really need count and mask here? I suppose that partly depends on whether HVM_PARAM_IOREQ_SERVER_PFN can be changed more than once for a domain. If it can't/shouldn't, I suppose just mask would suffice (by simply setting all unavailable bits). If it can, the question arises what the right action is upon a request to lower the count below the number of currently registered servers.
Jan
Re: [PATCH v8 1/3] ioreq-server: add support for multiple servers
Quoted 8 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 20 May 2014 15:55
To: Paul Durrant
Cc: Ian Jackson; Stefano Stabellini; [email protected]
Subject: Re: [PATCH v8 1/3] ioreq-server: add support for multiple serversQuoted 1 line
Quoted 1 line
Quoted 1 line · On 19.05.14 at 15:47, <[email protected]> wrote:
Quoted 10 lines
xen/arch/x86/hvm/hvm.c static int hvm_print_line( · line 590
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +7
-0+static int hvm_access_cf8 ( +int dir,uint32_t port,uint32_t bytes,uint32_t *val) +{ +struct domain *d = current->domain; + +if ( dir ==IOREQ_WRITE && + bytes ==4 )Don't you also need to check port ==
0xcf8here?
I don't think I do because (for AFAICT port IO at least) Xen should ensure the only possible 4 byte write that can come in here has to be to cf8. Any access to cf9, cfa, or cfb would have to be less than 4 bytes long.
Quoted 12 lines
Quoted 12 lines
xen/arch/x86/hvm/hvm.c +12
-0+static ioservid_t next_ioservid (struct domain *d) +{ +struct hvm_ioreq_server *s; +ioservid_t id; + +ASSERT (spin_is_locked (&d->arch.hvm_domain.ioreq_server.lock)); + + id = d->arch.hvm_domain.ioreq_server.id; + + again: + id++; +
Quoted 9 lines
xen/arch/x86/hvm/hvm.c static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, struct domain *d, · line 919
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+/* Check for uniqueness */ +list_for_each_entry ( s, + &d->arch.hvm_domain.ioreq_server.list, + list_entry ) + { +if (id == s->id)The beloved coding style remark again.
Unnecessary braces? Ok.
Quoted 23 lines
Review static int hvm_create_ioreq_server(struct domain
Quoted 1 line
(quoted diff) +0
-0@@ -757,25 +937,34 @@ static int hvm_create_ioreq_server(struct domain*d,
domid_tdomid)Quoted 21 lines
xen/arch/x86/hvm/hvm.c +8
-4goto fail1;domain_pause (d); -spin_lock (&d->arch.hvm_domain.ioreq_server_lock); +spin_lock (&d->arch.hvm_domain.ioreq_server.lock); rc = -EEXIST ; -if ( d->arch.hvm_domain.ioreq_server !=NULL ) +if ( is_default && d->arch.hvm_domain.default_ioreq_server !=NULL ) goto fail2; - rc =hvm_ioreq_server_init (s, d, domid); + rc =hvm_ioreq_server_init (s, d, domid, is_default, +next_ioservid (d));if ( rc ) - goto fail2; + goto fail3; + +list_add (&s->list_entry, + &d->arch.hvm_domain.ioreq_server.list);
Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int hvm_create_ioreq_server(struct domain *d, domid_t domid) · line 957
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +3
-2- d->arch.hvm_domain.ioreq_server = s; +if ( is_default ) + d->arch.hvm_domain.default_ioreq_server = s; -spin_unlock (&d->arch.hvm_domain.ioreq_server_lock); +if (id !=NULL )And again.
Ok.
Quoted 25 lines
Review static int hvm_create_ioreq_server(struct domain · line 958
Quoted 2 lines
(quoted diff) +1
-0+static struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain*d,
Quoted 22 lines
xen/arch/x86/hvm/hvm.c +22
-0+ ioreq_t *p) +{ +#define CF8_BDF (cf8) (((cf8) & 0x00ffff00) >> 8) +#define CF8_ADDR_LO (cf8) ((cf8) & 0x000000fc) +#define CF8_ADDR_HI (cf8) (((cf8) & 0x0f000000) >> 16) +#define CF8_ENABLED (cf8) (!!((cf8) & 0x80000000)) + +struct hvm_ioreq_server *s; +uint32_t cf8; +uint8_t type; +uint64_t addr; + +if (list_empty (&d->arch.hvm_domain.ioreq_server.list) ) +return NULL ; + +if (list_is_singular (&d->arch.hvm_domain.ioreq_server.list) || + (p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO ) ) +return d->arch.hvm_domain.default_ioreq_server; + + cf8 = d->arch.hvm_domain.pci_cf8; + +/*
Quoted 9 lines
xen/arch/x86/hvm/hvm.c void hvm_vcpu_down(struct vcpu *v) · line 2174
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +3
-0+* NOTE: Only types IOREQ_TYPE_PIO and IOREQ_TYPE_COPY are valid +* on entry. +*/ I realize this got added in response to my comments on the previous version, but just now I realized that you had already then added a respective check in the second
if()above (which I missed). With that the comment seems rather useless.
Agreed. If you're happy, I'll remove it.
Quoted 4 lines
Quoted 1 line
+
Line with only blanks.
Oops.
Quoted 9 lines
xen/include/asm-x86/hvm/domain.h struct hvm_ioreq_server { · line 79
Quoted 8 lines
struct
hvm_domain{xen/include/asm-x86/hvm/domain.h +5
-2-spinlock_t ioreq_server_lock; -struct hvm_ioreq_server *ioreq_server; +/* Guest page range used for non-default ioreq servers */ +struct { +unsigned long base; +unsigned long mask; +unsigned int count;
Quoted 8 lines
Do you really need count and mask here? I suppose that partly depends on whether
HVM_PARAM_IOREQ_SERVER_PFNcan be changed more than once for a domain. If it can't/shouldn't, I suppose just mask would suffice (by simply setting all unavailable bits). If it can, the question arises what the right action is upon a request to lower the count below the number of currently registered servers.
No - I could lose the count field, that's true. I'll get rid of it.
Paul
Quoted 1 line
Jan
Re: [PATCH v8 1/3] ioreq-server: add support for multiple servers
Quoted 20 lines
Quoted 9 lines
Quoted 1 line · On 20.05.14 at 17:06, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 20 May 2014 15:55
To: Paul Durrant
Cc: Ian Jackson; Stefano Stabellini; [email protected]
Subject: Re: [PATCH v8 1/3] ioreq-server: add support for multiple serversQuoted 1 line
Quoted 1 line
Quoted 1 line · On 19.05.14 at 15:47, <[email protected]> wrote:
Quoted 10 lines
xen/arch/x86/hvm/hvm.c static int hvm_print_line( · line 590
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +7
-0+static int hvm_access_cf8 ( +int dir,uint32_t port,uint32_t bytes,uint32_t *val) +{ +struct domain *d = current->domain; + +if ( dir ==IOREQ_WRITE && + bytes ==4 )Don't you also need to check port ==
0xcf8here?
Quoted 3 lines
I don't think I do because (for AFAICT port IO at least) Xen should ensure the only possible 4 byte write that can come in here has to be to cf8. Any access to cf9, cfa, or cfb would have to be less than 4 bytes long.
Ah, indeed (and the same for MMIO). In that case if you could make the if() a single line...
Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
xen/arch/x86/hvm/hvm.c +12
-0+static ioservid_t next_ioservid (struct domain *d) +{ +struct hvm_ioreq_server *s; +ioservid_t id; + +ASSERT (spin_is_locked (&d->arch.hvm_domain.ioreq_server.lock)); + + id = d->arch.hvm_domain.ioreq_server.id; + + again: + id++; +Quoted 9 lines
xen/arch/x86/hvm/hvm.c static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, struct domain *d, · line 919
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+/* Check for uniqueness */ +list_for_each_entry ( s, + &d->arch.hvm_domain.ioreq_server.list, + list_entry ) + { +if (id == s->id)The beloved coding style remark again.
Quoted 1 line
Unnecessary braces? Ok.
No - the braces are a matter of taste. There are missing blanks inside the parentheses.
Jan
Re: [PATCH v8 1/3] ioreq-server: add support for multiple servers
Quoted 27 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 20 May 2014 16:28
To: Paul Durrant
Cc: Ian Jackson; Stefano Stabellini; [email protected]
Subject: RE: [PATCH v8 1/3] ioreq-server: add support for multiple serversQuoted 20 lines
Quoted 19 lines
Quoted 1 line · On 20.05.14 at 17:06, <[email protected]> wrote:
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 20 May 2014 15:55
To: Paul Durrant
Cc: Ian Jackson; Stefano Stabellini; [email protected]
Subject: Re: [PATCH v8 1/3] ioreq-server: add support for multiple serversxen/arch/x86/hvm/hvm.c static int hvm_print_line( · line 590
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.05.14 at 15:47, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +7
-0+static int hvm_access_cf8 ( +int dir,uint32_t port,uint32_t bytes,uint32_t *val) +{ +struct domain *d = current->domain; + +if ( dir ==IOREQ_WRITE && + bytes ==4 )Don't you also need to check port ==
0xcf8here?
Quoted 7 lines
Quoted 3 lines
I don't think I do because (for AFAICT port IO at least) Xen should ensure the only possible 4 byte write that can come in here has to be to cf8. Any access to cf9, cfa, or cfb would have to be less than 4 bytes long.
Ah, indeed (and the same for MMIO). In that case if you could make the
if()a single line...
Sure.
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 8 lines
xen/arch/x86/hvm/hvm.c +8
-0+static ioservid_t next_ioservid (struct domain *d) +{ +struct hvm_ioreq_server *s; +ioservid_t id; + +ASSERT (spin_is_locked (&d->arch.hvm_domain.ioreq_server.lock)); + + id = d->arch.hvm_domain.ioreq_server.id;xen/arch/x86/hvm/hvm.c static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, struct domain *d, · line 919
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+ + again: + id++; + +/* Check for uniqueness */ +list_for_each_entry ( s, + &d->arch.hvm_domain.ioreq_server.list, + list_entry ) + { +if (id == s->id)The beloved coding style remark again.
Quoted 5 lines
Quoted 1 line
Unnecessary braces? Ok.
No - the braces are a matter of taste. There are missing blanks inside the parentheses.
Yeah - I noticed that afterwards; I'll keep the braces then.
Paul
PATCH v8 2/3 ioreq-server: remove p2m entries when server is enabled
In reply to Paul DurrantFor secondary servers, add a hvm op to enable/disable the server. The server will not accept IO until it is enabled and the act of enabling the server removes its pages from the guest p2m, thus preventing the guest from directly mapping the pages and synthesizing ioreqs.
--- tools/libxc/xc_domain.c | 27 +++++++ tools/libxc/xenctrl.h | 18 +++++ xen/arch/x86/hvm/hvm.c | 151 +++++++++++++++++++++++++++++++++++++- xen/include/asm-x86/hvm/domain.h | 1 + xen/include/public/hvm/hvm_op.h | 19 +++++ 5 files changed, 215 insertions(+), 1 deletion(-)
tools/libxc/xc_domain.c +27 -0
@@ -1508,6 +1508,33 @@ int xc_hvm_destroy_ioreq_server(xc_interface *xch,return rc; } +int xc_hvm_set_ioreq_server_state (xc_interface *xch, +domid_t domid, +ioservid_t id, +int enabled) +{ +DECLARE_HYPERCALL ; +DECLARE_HYPERCALL_BUFFER (xen_hvm_set_ioreq_server_state_t, arg); +int rc; + + arg =xc_hypercall_buffer_alloc (xch, arg,sizeof (*arg)); +if ( arg ==NULL ) +return -1 ; + + hypercall.op = __HYPERVISOR_hvm_op; + hypercall.arg[0 ] = HVMOP_set_ioreq_server_state; + hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); + + arg->domid = domid; + arg->id = id; + arg->enabled = !!enabled; + + rc =do_xen_hypercall (xch, &hypercall); + +xc_hypercall_buffer_free (xch, arg); +return rc; +} +int xc_domain_setdebugging (xc_interface *xch,uint32_t domid,unsigned int enable)
tools/libxc/xenctrl.h +18 -0
@@ -1829,6 +1829,24 @@ int xc_hvm_get_ioreq_server_info(xc_interface *xch, evtchn_port_t *bufioreq_port);/** +* This function sets IOREQ Server state. An IOREQ Server +* will not be passed emulation requests until it is in +* the enabled state. +* Note that the contents of the ioreq_pfn and bufioreq_pfn are +* not meaningful until the IOREQ Server is in the enabled state. +* +* @parm xch a handle to an open hypervisor interface. +* @parm domid the domain id to be serviced +* @parm id the IOREQ Server id. +* @parm enabled the state. +* @return 0 on success, -1 on failure. +*/ +int xc_hvm_set_ioreq_server_state (xc_interface *xch, +domid_t domid, +ioservid_t id, +int enabled); + +/** * This function registers a range of memory or I/O ports for emulation. * * @parm xch a handle to an open hypervisor interface.
xen/arch/x86/hvm/hvm.c +150 -1
207 lines not on this page · raw message
xen/include/asm-x86/hvm/domain.h +1 -0
@@ -69,6 +69,7 @@ struct hvm_ioreq_server {spinlock_t bufioreq_lock;evtchn_port_t bufioreq_evtchn;struct rangeset *range[NR_IO_RANGE_TYPES ]; +bool_t enabled; };struct hvm_domain {
xen/include/public/hvm/hvm_op.h +19 -0
@@ -342,6 +342,25 @@ struct xen_hvm_destroy_ioreq_server {typedef struct xen_hvm_destroy_ioreq_server xen_hvm_destroy_ioreq_server_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_destroy_ioreq_server_t); +/* +* HVMOP_set_ioreq_server_state: Enable or disable the IOREQ Server <id> servicing +* domain <domid>. +* +* The IOREQ Server will not be passed any emulation requests until it is in the +* enabled state. +* Note that the contents of the ioreq_pfn and bufioreq_fn (see +* HVMOP_get_ioreq_server_info) are not meaningful until the IOREQ Server is in +* the enabled state. +*/ +#define HVMOP_set_ioreq_server_state 22 +struct xen_hvm_set_ioreq_server_state { +domid_t domid;/* IN - domain to be serviced */ +ioservid_t id;/* IN - server id */ +uint8_t enabled;/* IN - enabled? */ +}; +typedef struct xen_hvm_set_ioreq_server_state xen_hvm_set_ioreq_server_state_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_ioreq_server_state_t); +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ #endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */
Signature · 1 line
1.7.10.4
PATCH v8 3/3 ioreq-server: make buffered ioreq handling optional
In reply to Paul DurrantSome emulators will only register regions that require non-buffered access. (In practice the only region that a guest uses buffered access for today is the VGA aperture from 0xa0000-0xbffff). This patch therefore makes allocation of the buffered ioreq page and event channel optional for secondary ioreq servers.
If a guest attempts buffered access to an ioreq server that does not support it, the access will be handled via the normal synchronous path.
--- tools/libxc/xc_domain.c | 2 + tools/libxc/xenctrl.h | 2 + xen/arch/x86/hvm/hvm.c | 78 +++++++++++++++++++++++++++------------ xen/include/public/hvm/hvm_op.h | 24 +++++++----- 4 files changed, 74 insertions(+), 32 deletions(-)
tools/libxc/xc_domain.c +2 -0
@@ -1286,6 +1286,7 @@ int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned longint xc_hvm_create_ioreq_server (xc_interface *xch,domid_t domid, +int handle_bufioreq,ioservid_t *id) {DECLARE_HYPERCALL ;
@@ -1301,6 +1302,7 @@ int xc_hvm_create_ioreq_server(xc_interface *xch, hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); arg->domid = domid; + arg->handle_bufioreq = !!handle_bufioreq; rc =do_xen_hypercall (xch, &hypercall);
tools/libxc/xenctrl.h +2 -0
@@ -1802,11 +1802,13 @@ int xc_get_hvm_param(xc_interface *handle, domid_t dom, int param, unsigned long* * @parm xch a handle to an open hypervisor interface. * @parm domid the domain id to be serviced +* @parm handle_bufioreq should the IOREQ Server handle buffered requests? * @parm id pointer to an ioservid_t to receive the IOREQ Server id. * @return 0 on success, -1 on failure. */ int xc_hvm_create_ioreq_server (xc_interface *xch,domid_t domid, +int handle_bufioreq,ioservid_t *id);/**
xen/arch/x86/hvm/hvm.c +55 -23
209 lines not on this page · raw message
xen/include/public/hvm/hvm_op.h +15 -9
@@ -258,12 +258,15 @@ typedef uint16_t ioservid_t;* HVMOP_create_ioreq_server: Instantiate a new IOREQ Server for a secondary * emulator servicing domain <domid>. * -* The <id> handed back is unique for <domid>. +* The <id> handed back is unique for <domid>. If <handle_bufioreq> is zero +* the buffered ioreq ring will not be allocated and hence all emulation +* requestes to this server will be synchronous. */ #define HVMOP_create_ioreq_server 17struct xen_hvm_create_ioreq_server { -domid_t domid;/* IN - domain to be serviced */ -ioservid_t id;/* OUT - server id */ +domid_t domid;/* IN - domain to be serviced */ +uint8_t handle_bufioreq;/* IN - should server handle buffered ioreqs */ +ioservid_t id;/* OUT - server id */ };typedef struct xen_hvm_create_ioreq_server xen_hvm_create_ioreq_server_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_create_ioreq_server_t);
@@ -273,12 +276,15 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_create_ioreq_server_t);* IOREQ Server <id>. * * The emulator needs to map the synchronous ioreq structures and buffered -* ioreq ring that Xen uses to request emulation. These are hosted in domain -* <domid>'s gmfns <ioreq_pfn> and <bufioreq_pfn> respectively. In addition the -* emulator needs to bind to event channel <bufioreq_port> to listen for -* buffered emulation requests. (The event channels used for synchronous -* emulation requests are specified in the per-CPU ioreq structures in -* <ioreq_pfn>). +* ioreq ring (if it exists) that Xen uses to request emulation. These are +* hosted in domain <domid>'s gmfns <ioreq_pfn> and <bufioreq_pfn> +* respectively. In addition, if the IOREQ Server is handling buffered +* emulation requests, the emulator needs to bind to event channel +* <bufioreq_port> to listen for them. (The event channels used for +* synchronous emulation requests are specified in the per-CPU ioreq +* structures in <ioreq_pfn>). +* If the IOREQ Server is not handling buffered emulation requests then the +* values handed back in <bufioreq_pfn> and <bufioreq_port> will both be 0. */ #define HVMOP_get_ioreq_server_info 18struct xen_hvm_get_ioreq_server_info {
Signature · 1 line
1.7.10.4