From: "Jan Beulich" Subject: [PATCH 10/11] hvmctl: convert HVMOP_*ioreq_server* Date: Mon, 20 Jun 2016 06:57:47 -0600 Message-ID: <5768046B02000078000F6C02@prv-mh.provo.novell.com> References: <5768002C02000078000F6B8D@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartEBDDD65B.3__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bEyoV-0007xm-T9 for xen-devel@lists.xenproject.org; Mon, 20 Jun 2016 13:00:28 +0000 In-Reply-To: <5768002C02000078000F6B8D@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Paul Durrant , dgdegra@tycho.nsa.gov List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartEBDDD65B.3__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Note that we can't adjust HVM_IOREQSRV_BUFIOREQ_* to properly obey name space rules, as these constants as in use by callers of the libxc interface. Signed-off-by: Jan Beulich --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -1416,23 +1416,14 @@ int xc_hvm_create_ioreq_server(xc_interf int handle_bufioreq, ioservid_t *id) { - DECLARE_HYPERCALL_BUFFER(xen_hvm_create_ioreq_server_t, arg); + DECLARE_HVMCTL(create_ioreq_server, domid, + .handle_bufioreq =3D handle_bufioreq); int rc; =20 - arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg =3D=3D NULL ) - return -1; - - arg->domid =3D domid; - arg->handle_bufioreq =3D handle_bufioreq; - - rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_create_ioreq_server, - HYPERCALL_BUFFER_AS_ARG(arg)); + rc =3D do_hvmctl(xch, &hvmctl); =20 - *id =3D arg->id; + *id =3D hvmctl.u.create_ioreq_server.id; =20 - xc_hypercall_buffer_free(xch, arg); return rc; } =20 @@ -1443,84 +1434,52 @@ int xc_hvm_get_ioreq_server_info(xc_inte xen_pfn_t *bufioreq_pfn, evtchn_port_t *bufioreq_port) { - DECLARE_HYPERCALL_BUFFER(xen_hvm_get_ioreq_server_info_t, arg); + DECLARE_HVMCTL(get_ioreq_server_info, domid, + .id =3D id); int rc; =20 - arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg =3D=3D NULL ) - return -1; - - arg->domid =3D domid; - arg->id =3D id; - - rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_get_ioreq_server_info, - HYPERCALL_BUFFER_AS_ARG(arg)); + rc =3D do_hvmctl(xch, &hvmctl); if ( rc !=3D 0 ) - goto done; + return rc; =20 if ( ioreq_pfn ) - *ioreq_pfn =3D arg->ioreq_pfn; + *ioreq_pfn =3D hvmctl.u.get_ioreq_server_info.ioreq_pfn; =20 if ( bufioreq_pfn ) - *bufioreq_pfn =3D arg->bufioreq_pfn; + *bufioreq_pfn =3D hvmctl.u.get_ioreq_server_info.bufioreq_pfn; =20 if ( bufioreq_port ) - *bufioreq_port =3D arg->bufioreq_port; + *bufioreq_port =3D hvmctl.u.get_ioreq_server_info.bufioreq_port; =20 -done: - xc_hypercall_buffer_free(xch, arg); - return rc; + return 0; } =20 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_BUFFER(xen_hvm_io_range_t, arg); - int rc; - - arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg =3D=3D NULL ) - return -1; - - arg->domid =3D domid; - arg->id =3D id; - arg->type =3D is_mmio ? HVMOP_IO_RANGE_MEMORY : HVMOP_IO_RANGE_PORT; - arg->start =3D start; - arg->end =3D end; - - rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_map_io_range_to_ioreq_server, - HYPERCALL_BUFFER_AS_ARG(arg)); + DECLARE_HVMCTL(map_io_range_to_ioreq_server, domid, + .id =3D id, + .type =3D is_mmio ? XEN_HVMCTL_IO_RANGE_MEMORY + : XEN_HVMCTL_IO_RANGE_PORT, + .start =3D start, + .end =3D end); =20 - xc_hypercall_buffer_free(xch, arg); - return rc; + return do_hvmctl(xch, &hvmctl); } =20 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_BUFFER(xen_hvm_io_range_t, arg); - int rc; - - arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg =3D=3D NULL ) - return -1; + DECLARE_HVMCTL(unmap_io_range_from_ioreq_server, domid, + .id =3D id, + .type =3D is_mmio ? XEN_HVMCTL_IO_RANGE_MEMORY + : XEN_HVMCTL_IO_RANGE_PORT, + .start =3D start, + .end =3D end); =20 - arg->domid =3D domid; - arg->id =3D id; - arg->type =3D is_mmio ? HVMOP_IO_RANGE_MEMORY : HVMOP_IO_RANGE_PORT; - arg->start =3D start; - arg->end =3D end; - - rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_unmap_io_range_from_ioreq_server, - HYPERCALL_BUFFER_AS_ARG(arg)); - - xc_hypercall_buffer_free(xch, arg); - return rc; + return do_hvmctl(xch, &hvmctl); } =20 int xc_hvm_map_pcidev_to_ioreq_server(xc_interface *xch, domid_t domid, @@ -1528,37 +1487,23 @@ int xc_hvm_map_pcidev_to_ioreq_server(xc uint8_t bus, uint8_t device, uint8_t function) { - DECLARE_HYPERCALL_BUFFER(xen_hvm_io_range_t, arg); - int rc; + /* + * The underlying hypercall will deal with ranges of PCI SBDF + * but, for simplicity, the API only uses singletons. + */ + uint32_t sbdf =3D XEN_HVMCTL_PCI_SBDF(segment, bus, device, function);= + DECLARE_HVMCTL(map_io_range_to_ioreq_server, domid, + .id =3D id, + .type =3D XEN_HVMCTL_IO_RANGE_PCI, + .start =3D sbdf, + .end =3D sbdf); =20 if (device > 0x1f || function > 0x7) { errno =3D EINVAL; return -1; } =20 - arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg =3D=3D NULL ) - return -1; - - arg->domid =3D domid; - arg->id =3D id; - arg->type =3D HVMOP_IO_RANGE_PCI; - - /* - * The underlying hypercall will deal with ranges of PCI SBDF - * but, for simplicity, the API only uses singletons. - */ - arg->start =3D arg->end =3D HVMOP_PCI_SBDF((uint64_t)segment, - (uint64_t)bus, - (uint64_t)device, - (uint64_t)function); - - rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_map_io_range_to_ioreq_server, - HYPERCALL_BUFFER_AS_ARG(arg)); - - xc_hypercall_buffer_free(xch, arg); - return rc; + return do_hvmctl(xch, &hvmctl); } =20 int xc_hvm_unmap_pcidev_from_ioreq_server(xc_interface *xch, domid_t = domid, @@ -1566,54 +1511,29 @@ int xc_hvm_unmap_pcidev_from_ioreq_serve uint8_t bus, uint8_t device, uint8_t function) { - DECLARE_HYPERCALL_BUFFER(xen_hvm_io_range_t, arg); - int rc; + uint32_t sbdf =3D XEN_HVMCTL_PCI_SBDF(segment, bus, device, function);= + DECLARE_HVMCTL(unmap_io_range_from_ioreq_server, domid, + .id =3D id, + .type =3D XEN_HVMCTL_IO_RANGE_PCI, + .start =3D sbdf, + .end =3D sbdf); =20 if (device > 0x1f || function > 0x7) { errno =3D EINVAL; return -1; } =20 - arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg =3D=3D NULL ) - return -1; - - arg->domid =3D domid; - arg->id =3D id; - arg->type =3D HVMOP_IO_RANGE_PCI; - arg->start =3D arg->end =3D HVMOP_PCI_SBDF((uint64_t)segment, - (uint64_t)bus, - (uint64_t)device, - (uint64_t)function); - - rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_unmap_io_range_from_ioreq_server, - HYPERCALL_BUFFER_AS_ARG(arg)); - - xc_hypercall_buffer_free(xch, arg); - return rc; + return do_hvmctl(xch, &hvmctl); } =20 int xc_hvm_destroy_ioreq_server(xc_interface *xch, domid_t domid, ioservid_t id) { - DECLARE_HYPERCALL_BUFFER(xen_hvm_destroy_ioreq_server_t, arg); - int rc; - - arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg =3D=3D NULL ) - return -1; + DECLARE_HVMCTL(destroy_ioreq_server, domid, + .id =3D id); =20 - arg->domid =3D domid; - arg->id =3D id; - - rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_destroy_ioreq_server, - HYPERCALL_BUFFER_AS_ARG(arg)); - - xc_hypercall_buffer_free(xch, arg); - return rc; + return do_hvmctl(xch, &hvmctl); } =20 int xc_hvm_set_ioreq_server_state(xc_interface *xch, @@ -1621,23 +1541,11 @@ int xc_hvm_set_ioreq_server_state(xc_int ioservid_t id, int enabled) { - DECLARE_HYPERCALL_BUFFER(xen_hvm_set_ioreq_server_state_t, arg); - int rc; - - arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg)); - if ( arg =3D=3D NULL ) - return -1; + DECLARE_HVMCTL(set_ioreq_server_state, domid, + .id =3D id, + .enabled =3D !!enabled); =20 - arg->domid =3D domid; - arg->id =3D id; - arg->enabled =3D !!enabled; - - rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op, - HVMOP_set_ioreq_server_state, - HYPERCALL_BUFFER_AS_ARG(arg)); - - xc_hypercall_buffer_free(xch, arg); - return rc; + return do_hvmctl(xch, &hvmctl); } =20 int xc_domain_setdebugging(xc_interface *xch, --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -34,8 +34,6 @@ #define XC_INTERNAL_COMPAT_MAP_FOREIGN_API #include "xenctrl.h" =20 -#include - #include #include =20 --- a/xen/arch/x86/hvm/control.c +++ b/xen/arch/x86/hvm/control.c @@ -20,6 +20,7 @@ #include #include #include +#include #include =20 static int set_pci_intx_level(struct domain *d, @@ -299,6 +300,50 @@ long do_hvmctl(XEN_GUEST_HANDLE_PARAM(xe rc =3D hvm_inject_msi(d, op.u.inject_msi.addr, op.u.inject_msi.dat= a); break; =20 + case XEN_HVMCTL_create_ioreq_server: + rc =3D -EINVAL; + if ( op.u.create_ioreq_server.rsvd ) + break; + rc =3D hvm_create_ioreq_server(d, current->domain->domain_id, 0, + op.u.create_ioreq_server.handle_bufio= req, + &op.u.create_ioreq_server.id); + if ( rc =3D=3D 0 && copy_field_to_guest(u_hvmctl, &op, + u.create_ioreq_server.id) ) + rc =3D -EFAULT; + break; + + case XEN_HVMCTL_get_ioreq_server_info: + rc =3D -EINVAL; + if ( op.u.get_ioreq_server_info.rsvd ) + break; + rc =3D hvm_get_ioreq_server_info(d, &op.u.get_ioreq_server_info); + if ( rc =3D=3D 0 && copy_field_to_guest(u_hvmctl, &op, + u.get_ioreq_server_info) ) + rc =3D -EFAULT; + break; + + case XEN_HVMCTL_map_io_range_to_ioreq_server: + rc =3D hvm_map_io_range_to_ioreq_server( + d, &op.u.map_io_range_to_ioreq_server); + break; + + case XEN_HVMCTL_unmap_io_range_from_ioreq_server: + rc =3D hvm_unmap_io_range_from_ioreq_server( + d, &op.u.unmap_io_range_from_ioreq_server); + break; + + case XEN_HVMCTL_destroy_ioreq_server: + rc =3D hvm_destroy_ioreq_server(d, op.u.destroy_ioreq_server.id); + break; + + case XEN_HVMCTL_set_ioreq_server_state: + rc =3D -EINVAL; + if ( op.u.set_ioreq_server_state.rsvd ) + break; + rc =3D hvm_set_ioreq_server_state(d, op.u.set_ioreq_server_state.i= d, + !!op.u.set_ioreq_server_state.enab= led); + break; + default: rc =3D -EOPNOTSUPP; break; --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4487,195 +4487,6 @@ static int hvmop_flush_tlb_all(void) return 0; } =20 -static int hvmop_create_ioreq_server( - XEN_GUEST_HANDLE_PARAM(xen_hvm_create_ioreq_server_t) uop) -{ - struct domain *curr_d =3D current->domain; - xen_hvm_create_ioreq_server_t op; - struct domain *d; - int rc; - - if ( copy_from_guest(&op, uop, 1) ) - return -EFAULT; - - rc =3D rcu_lock_remote_domain_by_id(op.domid, &d); - if ( rc !=3D 0 ) - return rc; - - rc =3D -EINVAL; - if ( !is_hvm_domain(d) ) - goto out; - - rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, HVMOP_create_ioreq_server)= ; - if ( rc !=3D 0 ) - goto out; - - rc =3D hvm_create_ioreq_server(d, curr_d->domain_id, 0, - op.handle_bufioreq, &op.id); - if ( rc !=3D 0 ) - goto out; - - rc =3D copy_to_guest(uop, &op, 1) ? -EFAULT : 0; - =20 - out: - rcu_unlock_domain(d); - return rc; -} - -static int hvmop_get_ioreq_server_info( - XEN_GUEST_HANDLE_PARAM(xen_hvm_get_ioreq_server_info_t) uop) -{ - xen_hvm_get_ioreq_server_info_t op; - struct domain *d; - int rc; - - if ( copy_from_guest(&op, uop, 1) ) - return -EFAULT; - - rc =3D rcu_lock_remote_domain_by_id(op.domid, &d); - if ( rc !=3D 0 ) - return rc; - - rc =3D -EINVAL; - if ( !is_hvm_domain(d) ) - goto out; - - rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, HVMOP_get_ioreq_server_inf= o); - if ( rc !=3D 0 ) - goto out; - - rc =3D hvm_get_ioreq_server_info(d, op.id, - &op.ioreq_pfn, - &op.bufioreq_pfn,=20 - &op.bufioreq_port); - if ( rc !=3D 0 ) - goto out; - - rc =3D copy_to_guest(uop, &op, 1) ? -EFAULT : 0; - =20 - out: - rcu_unlock_domain(d); - return rc; -} - -static int hvmop_map_io_range_to_ioreq_server( - XEN_GUEST_HANDLE_PARAM(xen_hvm_io_range_t) uop) -{ - xen_hvm_io_range_t op; - struct domain *d; - int rc; - - if ( copy_from_guest(&op, uop, 1) ) - return -EFAULT; - - rc =3D rcu_lock_remote_domain_by_id(op.domid, &d); - if ( rc !=3D 0 ) - return rc; - - rc =3D -EINVAL; - if ( !is_hvm_domain(d) ) - goto out; - - rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, HVMOP_map_io_range_to_iore= q_server); - if ( rc !=3D 0 ) - goto out; - - rc =3D hvm_map_io_range_to_ioreq_server(d, op.id, op.type, - op.start, op.end); - - out: - rcu_unlock_domain(d); - return rc; -} - -static int hvmop_unmap_io_range_from_ioreq_server( - XEN_GUEST_HANDLE_PARAM(xen_hvm_io_range_t) uop) -{ - xen_hvm_io_range_t op; - struct domain *d; - int rc; - - if ( copy_from_guest(&op, uop, 1) ) - return -EFAULT; - - rc =3D rcu_lock_remote_domain_by_id(op.domid, &d); - if ( rc !=3D 0 ) - return rc; - - rc =3D -EINVAL; - if ( !is_hvm_domain(d) ) - goto out; - - rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, HVMOP_unmap_io_range_from_= ioreq_server); - if ( rc !=3D 0 ) - goto out; - - rc =3D hvm_unmap_io_range_from_ioreq_server(d, op.id, op.type, - op.start, op.end); - =20 - out: - rcu_unlock_domain(d); - return rc; -} - -static int hvmop_set_ioreq_server_state( - XEN_GUEST_HANDLE_PARAM(xen_hvm_set_ioreq_server_state_t) uop) -{ - xen_hvm_set_ioreq_server_state_t op; - struct domain *d; - int rc; - - if ( copy_from_guest(&op, uop, 1) ) - return -EFAULT; - - rc =3D rcu_lock_remote_domain_by_id(op.domid, &d); - if ( rc !=3D 0 ) - return rc; - - rc =3D -EINVAL; - if ( !is_hvm_domain(d) ) - goto out; - - rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, HVMOP_set_ioreq_server_sta= te); - if ( rc !=3D 0 ) - goto out; - - rc =3D hvm_set_ioreq_server_state(d, op.id, !!op.enabled); - - out: - rcu_unlock_domain(d); - return rc; -} - -static int hvmop_destroy_ioreq_server( - XEN_GUEST_HANDLE_PARAM(xen_hvm_destroy_ioreq_server_t) uop) -{ - xen_hvm_destroy_ioreq_server_t op; - struct domain *d; - int rc; - - if ( copy_from_guest(&op, uop, 1) ) - return -EFAULT; - - rc =3D rcu_lock_remote_domain_by_id(op.domid, &d); - if ( rc !=3D 0 ) - return rc; - - rc =3D -EINVAL; - if ( !is_hvm_domain(d) ) - goto out; - - rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, HVMOP_destroy_ioreq_server= ); - if ( rc !=3D 0 ) - goto out; - - rc =3D hvm_destroy_ioreq_server(d, op.id); - - out: - rcu_unlock_domain(d); - return rc; -} - static int hvmop_set_evtchn_upcall_vector( XEN_GUEST_HANDLE_PARAM(xen_hvm_evtchn_upcall_vector_t) uop) { @@ -5192,36 +5003,6 @@ long do_hvm_op(unsigned long op, XEN_GUE =20 switch ( op ) { - case HVMOP_create_ioreq_server: - rc =3D hvmop_create_ioreq_server( - guest_handle_cast(arg, xen_hvm_create_ioreq_server_t)); - break; - =20 - case HVMOP_get_ioreq_server_info: - rc =3D hvmop_get_ioreq_server_info( - guest_handle_cast(arg, xen_hvm_get_ioreq_server_info_t)); - break; - =20 - case HVMOP_map_io_range_to_ioreq_server: - rc =3D hvmop_map_io_range_to_ioreq_server( - guest_handle_cast(arg, xen_hvm_io_range_t)); - break; - =20 - case HVMOP_unmap_io_range_from_ioreq_server: - rc =3D hvmop_unmap_io_range_from_ioreq_server( - guest_handle_cast(arg, xen_hvm_io_range_t)); - break; - - case HVMOP_set_ioreq_server_state: - rc =3D hvmop_set_ioreq_server_state( - guest_handle_cast(arg, xen_hvm_set_ioreq_server_state_t)); - break; - =20 - case HVMOP_destroy_ioreq_server: - rc =3D hvmop_destroy_ioreq_server( - guest_handle_cast(arg, xen_hvm_destroy_ioreq_server_t)); - break; - =20 case HVMOP_set_evtchn_upcall_vector: rc =3D hvmop_set_evtchn_upcall_vector( guest_handle_cast(arg, xen_hvm_evtchn_upcall_vector_t)); --- a/xen/arch/x86/hvm/ioreq.c +++ b/xen/arch/x86/hvm/ioreq.c @@ -513,9 +513,9 @@ static int hvm_ioreq_server_alloc_ranges char *name; =20 rc =3D asprintf(&name, "ioreq_server %d %s", s->id, - (i =3D=3D HVMOP_IO_RANGE_PORT) ? "port" : - (i =3D=3D HVMOP_IO_RANGE_MEMORY) ? "memory" : - (i =3D=3D HVMOP_IO_RANGE_PCI) ? "pci" : + (i =3D=3D XEN_HVMCTL_IO_RANGE_PORT) ? "port" : + (i =3D=3D XEN_HVMCTL_IO_RANGE_MEMORY) ? "memory" : + (i =3D=3D XEN_HVMCTL_IO_RANGE_PCI) ? "pci" : ""); if ( rc ) goto fail; @@ -686,7 +686,8 @@ int hvm_create_ioreq_server(struct domai struct hvm_ioreq_server *s; int rc; =20 - if ( bufioreq_handling > HVM_IOREQSRV_BUFIOREQ_ATOMIC ) + if ( !is_hvm_domain(d) || + bufioreq_handling > HVM_IOREQSRV_BUFIOREQ_ATOMIC ) return -EINVAL; =20 rc =3D -ENOMEM; @@ -738,6 +739,9 @@ int hvm_destroy_ioreq_server(struct doma struct hvm_ioreq_server *s; int rc; =20 + if ( !is_hvm_domain(d) ) + return -EINVAL; + spin_lock_recursive(&d->arch.hvm_domain.ioreq_server.lock); =20 rc =3D -ENOENT; @@ -772,14 +776,15 @@ int hvm_destroy_ioreq_server(struct doma return rc; } =20 -int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, - unsigned long *ioreq_pfn, - unsigned long *bufioreq_pfn, - evtchn_port_t *bufioreq_port) +int hvm_get_ioreq_server_info(struct domain *d, + struct xen_hvm_get_ioreq_server_info *info) { struct hvm_ioreq_server *s; int rc; =20 + if ( !is_hvm_domain(d) ) + return -EINVAL; + spin_lock_recursive(&d->arch.hvm_domain.ioreq_server.lock); =20 rc =3D -ENOENT; @@ -790,15 +795,15 @@ int hvm_get_ioreq_server_info(struct dom if ( s =3D=3D d->arch.hvm_domain.default_ioreq_server ) continue; =20 - if ( s->id !=3D id ) + if ( s->id !=3D info->id ) continue; =20 - *ioreq_pfn =3D s->ioreq.gmfn; + info->ioreq_pfn =3D s->ioreq.gmfn; =20 if ( s->bufioreq.va !=3D NULL ) { - *bufioreq_pfn =3D s->bufioreq.gmfn; - *bufioreq_port =3D s->bufioreq_evtchn; + info->bufioreq_pfn =3D s->bufioreq.gmfn; + info->bufioreq_port =3D s->bufioreq_evtchn; } =20 rc =3D 0; @@ -810,13 +815,15 @@ int hvm_get_ioreq_server_info(struct dom return rc; } =20 -int hvm_map_io_range_to_ioreq_server(struct domain *d, ioservid_t id, - uint32_t type, uint64_t start, - uint64_t end) +int hvm_map_io_range_to_ioreq_server(struct domain *d, + const struct xen_hvm_io_range *ior) { struct hvm_ioreq_server *s; int rc; =20 + if ( ior->rsvd || !is_hvm_domain(d) ) + return -EINVAL; + spin_lock_recursive(&d->arch.hvm_domain.ioreq_server.lock); =20 rc =3D -ENOENT; @@ -827,16 +834,16 @@ int hvm_map_io_range_to_ioreq_server(str if ( s =3D=3D d->arch.hvm_domain.default_ioreq_server ) continue; =20 - if ( s->id =3D=3D id ) + if ( s->id =3D=3D ior->id ) { struct rangeset *r; =20 - switch ( type ) + switch ( ior->type ) { - case HVMOP_IO_RANGE_PORT: - case HVMOP_IO_RANGE_MEMORY: - case HVMOP_IO_RANGE_PCI: - r =3D s->range[type]; + case XEN_HVMCTL_IO_RANGE_PORT: + case XEN_HVMCTL_IO_RANGE_MEMORY: + case XEN_HVMCTL_IO_RANGE_PCI: + r =3D s->range[ior->type]; break; =20 default: @@ -849,10 +856,10 @@ int hvm_map_io_range_to_ioreq_server(str break; =20 rc =3D -EEXIST; - if ( rangeset_overlaps_range(r, start, end) ) + if ( rangeset_overlaps_range(r, ior->start, ior->end) ) break; =20 - rc =3D rangeset_add_range(r, start, end); + rc =3D rangeset_add_range(r, ior->start, ior->end); break; } } @@ -862,13 +869,15 @@ int hvm_map_io_range_to_ioreq_server(str return rc; } =20 -int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id, - uint32_t type, uint64_t start, - uint64_t end) +int hvm_unmap_io_range_from_ioreq_server(struct domain *d, + const struct xen_hvm_io_range = *ior) { struct hvm_ioreq_server *s; int rc; =20 + if ( ior->rsvd || !is_hvm_domain(d) ) + return -EINVAL; + spin_lock_recursive(&d->arch.hvm_domain.ioreq_server.lock); =20 rc =3D -ENOENT; @@ -879,16 +888,16 @@ int hvm_unmap_io_range_from_ioreq_server if ( s =3D=3D d->arch.hvm_domain.default_ioreq_server ) continue; =20 - if ( s->id =3D=3D id ) + if ( s->id =3D=3D ior->id ) { struct rangeset *r; =20 - switch ( type ) + switch ( ior->type ) { - case HVMOP_IO_RANGE_PORT: - case HVMOP_IO_RANGE_MEMORY: - case HVMOP_IO_RANGE_PCI: - r =3D s->range[type]; + case XEN_HVMCTL_IO_RANGE_PORT: + case XEN_HVMCTL_IO_RANGE_MEMORY: + case XEN_HVMCTL_IO_RANGE_PCI: + r =3D s->range[ior->type]; break; =20 default: @@ -901,10 +910,10 @@ int hvm_unmap_io_range_from_ioreq_server break; =20 rc =3D -ENOENT; - if ( !rangeset_contains_range(r, start, end) ) + if ( !rangeset_contains_range(r, ior->start, ior->end) ) break; =20 - rc =3D rangeset_remove_range(r, start, end); + rc =3D rangeset_remove_range(r, ior->start, ior->end); break; } } @@ -920,6 +929,9 @@ int hvm_set_ioreq_server_state(struct do struct list_head *entry; int rc; =20 + if ( !is_hvm_domain(d) ) + return -EINVAL; + spin_lock_recursive(&d->arch.hvm_domain.ioreq_server.lock); =20 rc =3D -ENOENT; @@ -1128,12 +1140,12 @@ struct hvm_ioreq_server *hvm_select_iore =20 /* PCI config data cycle */ =20 - sbdf =3D HVMOP_PCI_SBDF(0, - PCI_BUS(CF8_BDF(cf8)), - PCI_SLOT(CF8_BDF(cf8)), - PCI_FUNC(CF8_BDF(cf8))); + sbdf =3D XEN_HVMCTL_PCI_SBDF(0, + PCI_BUS(CF8_BDF(cf8)), + PCI_SLOT(CF8_BDF(cf8)), + PCI_FUNC(CF8_BDF(cf8))); =20 - type =3D HVMOP_IO_RANGE_PCI; + type =3D XEN_HVMCTL_IO_RANGE_PCI; addr =3D ((uint64_t)sbdf << 32) | CF8_ADDR_LO(cf8) | (p->addr & 3); @@ -1152,7 +1164,7 @@ struct hvm_ioreq_server *hvm_select_iore else { type =3D (p->type =3D=3D IOREQ_TYPE_PIO) ? - HVMOP_IO_RANGE_PORT : HVMOP_IO_RANGE_MEMORY; + XEN_HVMCTL_IO_RANGE_PORT : XEN_HVMCTL_IO_RANGE_MEMORY; addr =3D p->addr; } =20 @@ -1174,19 +1186,19 @@ struct hvm_ioreq_server *hvm_select_iore { unsigned long end; =20 - case HVMOP_IO_RANGE_PORT: + case XEN_HVMCTL_IO_RANGE_PORT: end =3D addr + p->size - 1; if ( rangeset_contains_range(r, addr, end) ) return s; =20 break; - case HVMOP_IO_RANGE_MEMORY: + case XEN_HVMCTL_IO_RANGE_MEMORY: end =3D addr + (p->size * p->count) - 1; if ( rangeset_contains_range(r, addr, end) ) return s; =20 break; - case HVMOP_IO_RANGE_PCI: + case XEN_HVMCTL_IO_RANGE_PCI: if ( rangeset_contains_singleton(r, addr >> 32) ) { p->type =3D IOREQ_TYPE_PCI_CONFIG; --- a/xen/include/asm-x86/hvm/domain.h +++ b/xen/include/asm-x86/hvm/domain.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,7 @@ struct hvm_ioreq_vcpu { bool_t pending; }; =20 -#define NR_IO_RANGE_TYPES (HVMOP_IO_RANGE_PCI + 1) +#define NR_IO_RANGE_TYPES (XEN_HVMCTL_IO_RANGE_PCI + 1) #define MAX_NR_IO_RANGES 256 =20 struct hvm_ioreq_server { --- a/xen/include/asm-x86/hvm/ioreq.h +++ b/xen/include/asm-x86/hvm/ioreq.h @@ -19,6 +19,8 @@ #ifndef __ASM_X86_HVM_IOREQ_H__ #define __ASM_X86_HVM_IOREQ_H__ =20 +#include + bool_t hvm_io_pending(struct vcpu *v); bool_t handle_hvm_io_completion(struct vcpu *v); bool_t is_ioreq_server_page(struct domain *d, const struct page_info = *page); @@ -27,16 +29,12 @@ int hvm_create_ioreq_server(struct domai bool_t is_default, int bufioreq_handling, ioservid_t *id); int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id); -int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, - unsigned long *ioreq_pfn, - unsigned long *bufioreq_pfn, - evtchn_port_t *bufioreq_port); -int hvm_map_io_range_to_ioreq_server(struct domain *d, ioservid_t id, - uint32_t type, uint64_t start, - uint64_t end); -int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id, - uint32_t type, uint64_t start, - uint64_t end); +int hvm_get_ioreq_server_info(struct domain *d, + struct xen_hvm_get_ioreq_server_info = *info); +int hvm_map_io_range_to_ioreq_server(struct domain *d, + const struct xen_hvm_io_range *r); +int hvm_unmap_io_range_from_ioreq_server(struct domain *d, + const struct xen_hvm_io_range = *r); int hvm_set_ioreq_server_state(struct domain *d, ioservid_t id, bool_t enabled); =20 --- a/xen/include/public/hvm/control.h +++ b/xen/include/public/hvm/control.h @@ -26,6 +26,7 @@ #endif =20 #include "../xen.h" +#include "../event_channel.h" =20 #define XEN_HVMCTL_INTERFACE_VERSION 0x00000001 =20 @@ -130,6 +131,131 @@ struct xen_hvm_inject_msi { uint64_t addr; }; =20 +/* + * IOREQ Servers + * + * The interface between an I/O emulator an Xen is called an IOREQ = Server. + * A domain supports a single 'legacy' IOREQ Server which is instantiated = if + * parameter... + * + * HVM_PARAM_IOREQ_PFN is read (to get the gmfn containing the synchronous= + * ioreq structures), or... + * HVM_PARAM_BUFIOREQ_PFN is read (to get the gmfn containing the = buffered + * ioreq ring), or... + * HVM_PARAM_BUFIOREQ_EVTCHN is read (to get the event channel that Xen = uses + * to request buffered I/O emulation). + * + * The following hypercalls facilitate the creation of IOREQ Servers for + * 'secondary' emulators which are invoked to implement port I/O, memory, = or + * PCI config space ranges which they explicitly register. + */ + +typedef uint16_t ioservid_t; + +/* + * XEN_HVMCTL_create_ioreq_server: Instantiate a new IOREQ Server for a + * secondary emulator servicing domain + * . + * + * The handed back is unique for . If is = zero + * the buffered ioreq ring will not be allocated and hence all emulation + * requestes to this server will be synchronous. + */ +struct xen_hvm_create_ioreq_server { +#define HVM_IOREQSRV_BUFIOREQ_OFF 0 +#define HVM_IOREQSRV_BUFIOREQ_LEGACY 1 +/* + * Use this when read_pointer gets updated atomically and + * the pointer pair gets read atomically: + */ +#define HVM_IOREQSRV_BUFIOREQ_ATOMIC 2 + uint8_t handle_bufioreq; /* IN - should server handle buffered ioreqs = */ + uint8_t rsvd; /* IN - must be zero */ + ioservid_t id; /* OUT - server id */ +}; + +/* + * XEN_HVMCTL_get_ioreq_server_info: Get all the information necessary to + * access IOREQ Server . + * + * The emulator needs to map the synchronous ioreq structures and = buffered + * ioreq ring (if it exists) that Xen uses to request emulation. These = are + * hosted in domain 's gmfns and + * respectively. In addition, if the IOREQ Server is handling buffered + * emulation requests, the emulator needs to bind to event channel + * to listen for them. (The event channels used for + * synchronous emulation requests are specified in the per-CPU ioreq + * structures in ). + * If the IOREQ Server is not handling buffered emulation requests then = the + * values handed back in and will both be = 0. + */ +struct xen_hvm_get_ioreq_server_info { + ioservid_t id; /* IN - server id */ + uint16_t rsvd; /* IN - must be zero */ + evtchn_port_t bufioreq_port; /* OUT - buffered ioreq port */ + uint64_aligned_t ioreq_pfn; /* OUT - sync ioreq pfn */ + uint64_aligned_t bufioreq_pfn; /* OUT - buffered ioreq pfn */ +}; + +/* + * XEN_HVMCTL_map_io_range_to_ioreq_server: Register an I/O range of = domain + * for emulation by the + * client of IOREQ Server + * XEN_HVMCTL_unmap_io_range_from_ioreq_server: Deregister an I/O range = of + * for emulation by = the + * client of IOREQ Server = + * + * There are three types of I/O that can be emulated: port I/O, memory = accesses + * and PCI config space accesses. The field denotes which type of = range + * the and (inclusive) fields are specifying. + * PCI config space ranges are specified by segment/bus/device/function = values + * which should be encoded using the XEN_HVMCTL_PCI_SBDF helper macro = below. + * + * NOTE: unless an emulation request falls entirely within a range mapped + * by a secondary emulator, it will not be passed to that emulator. + */ +struct xen_hvm_io_range { + ioservid_t id; /* IN - server id */ + uint16_t type; /* IN - type of range */ + uint32_t rsvd; /* IN - must be zero */ +#define XEN_HVMCTL_IO_RANGE_PORT 0 /* I/O port range */ +#define XEN_HVMCTL_IO_RANGE_MEMORY 1 /* MMIO range */ +#define XEN_HVMCTL_IO_RANGE_PCI 2 /* PCI segment/bus/dev/func range */ + uint64_aligned_t start, end; /* IN - inclusive start and end of range = */ +}; + +#define XEN_HVMCTL_PCI_SBDF(s, b, d, f) \ + ((((s) & 0xffff) << 16) | \ + (((b) & 0xff) << 8) | \ + (((d) & 0x1f) << 3) | \ + ((f) & 0x07)) + +/* + * XEN_HVMCTL_destroy_ioreq_server: Destroy the IOREQ Server = servicing + * domain . + * + * Any registered I/O ranges will be automatically deregistered. + */ +struct xen_hvm_destroy_ioreq_server { + ioservid_t id; /* IN - server id */ +}; + +/* + * XEN_HVMCTL_set_ioreq_server_state: Enable or disable the IOREQ Server = + * servicing domain . + * + * 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 + * XEN_HVMCTL_get_ioreq_server_info) are not meaningful until the IOREQ = Server + * is in the enabled state. + */ +struct xen_hvm_set_ioreq_server_state { + ioservid_t id; /* IN - server id */ + uint8_t enabled; /* IN - enabled? */ + uint8_t rsvd; /* IN - must be zero */ +}; + struct xen_hvmctl { uint16_t interface_version; /* XEN_HVMCTL_INTERFACE_VERSION */ domid_t domain; @@ -142,6 +268,12 @@ struct xen_hvmctl { #define XEN_HVMCTL_set_mem_type 6 #define XEN_HVMCTL_inject_trap 7 #define XEN_HVMCTL_inject_msi 8 +#define XEN_HVMCTL_create_ioreq_server 9 +#define XEN_HVMCTL_get_ioreq_server_info 10 +#define XEN_HVMCTL_map_io_range_to_ioreq_server 11 +#define XEN_HVMCTL_unmap_io_range_from_ioreq_server 12 +#define XEN_HVMCTL_destroy_ioreq_server 13 +#define XEN_HVMCTL_set_ioreq_server_state 14 uint16_t opaque; /* Must be zero on initial invocation. = */ union { struct xen_hvm_set_pci_intx_level set_pci_intx_level; @@ -152,6 +284,12 @@ struct xen_hvmctl { struct xen_hvm_set_mem_type set_mem_type; struct xen_hvm_inject_trap inject_trap; struct xen_hvm_inject_msi inject_msi; + struct xen_hvm_create_ioreq_server create_ioreq_server; + struct xen_hvm_get_ioreq_server_info get_ioreq_server_info; + struct xen_hvm_io_range map_io_range_to_ioreq_server; + struct xen_hvm_io_range unmap_io_range_from_ioreq_server; + struct xen_hvm_destroy_ioreq_server destroy_ioreq_server; + struct xen_hvm_set_ioreq_server_state set_ioreq_server_state; uint8_t pad[120]; } u; }; --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -25,7 +25,6 @@ =20 #include "../xen.h" #include "../trace.h" -#include "../event_channel.h" =20 /* Get/set subcommands: extra argument =3D=3D pointer to xen_hvm_param = struct. */ #define HVMOP_set_param 0 @@ -137,152 +136,6 @@ struct xen_hvm_get_mem_type { typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t; DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_mem_type_t); =20 -/* Following tools-only interfaces may change in future. */ -#if defined(__XEN__) || defined(__XEN_TOOLS__) - -/* - * IOREQ Servers - * - * The interface between an I/O emulator an Xen is called an IOREQ = Server. - * A domain supports a single 'legacy' IOREQ Server which is instantiated = if - * parameter... - * - * HVM_PARAM_IOREQ_PFN is read (to get the gmfn containing the synchronous= - * ioreq structures), or... - * HVM_PARAM_BUFIOREQ_PFN is read (to get the gmfn containing the = buffered - * ioreq ring), or... - * HVM_PARAM_BUFIOREQ_EVTCHN is read (to get the event channel that Xen = uses - * to request buffered I/O emulation). - *=20 - * The following hypercalls facilitate the creation of IOREQ Servers for - * 'secondary' emulators which are invoked to implement port I/O, memory, = or - * PCI config space ranges which they explicitly register. - */ - -typedef uint16_t ioservid_t; - -/* - * HVMOP_create_ioreq_server: Instantiate a new IOREQ Server for a = secondary - * emulator servicing domain . - * - * The handed back is unique for . If 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 17 -struct xen_hvm_create_ioreq_server { - domid_t domid; /* IN - domain to be serviced */ -#define HVM_IOREQSRV_BUFIOREQ_OFF 0 -#define HVM_IOREQSRV_BUFIOREQ_LEGACY 1 -/* - * Use this when read_pointer gets updated atomically and - * the pointer pair gets read atomically: - */ -#define HVM_IOREQSRV_BUFIOREQ_ATOMIC 2 - 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); - -/* - * HVMOP_get_ioreq_server_info: Get all the information necessary to = access - * IOREQ Server .=20 - * - * The emulator needs to map the synchronous ioreq structures and = buffered - * ioreq ring (if it exists) that Xen uses to request emulation. These = are - * hosted in domain 's gmfns and - * respectively. In addition, if the IOREQ Server is handling buffered - * emulation requests, the emulator needs to bind to event channel - * to listen for them. (The event channels used for - * synchronous emulation requests are specified in the per-CPU ioreq - * structures in ). - * If the IOREQ Server is not handling buffered emulation requests then = the - * values handed back in and will both be = 0. - */ -#define HVMOP_get_ioreq_server_info 18 -struct xen_hvm_get_ioreq_server_info { - domid_t domid; /* IN - domain to be serviced */ - ioservid_t id; /* IN - server id */ - evtchn_port_t bufioreq_port; /* OUT - buffered ioreq port */ - uint64_aligned_t ioreq_pfn; /* OUT - sync ioreq pfn */ - uint64_aligned_t bufioreq_pfn; /* OUT - buffered ioreq pfn */ -}; -typedef struct xen_hvm_get_ioreq_server_info xen_hvm_get_ioreq_server_info= _t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t); - -/* - * HVM_map_io_range_to_ioreq_server: Register an I/O range of domain = - * for emulation by the client of IOREQ - * Server - * HVM_unmap_io_range_from_ioreq_server: Deregister an I/O range of = - * for emulation by the client of = IOREQ - * Server - * - * There are three types of I/O that can be emulated: port I/O, memory = accesses - * and PCI config space accesses. The field denotes which type of = range - * the and (inclusive) fields are specifying. - * PCI config space ranges are specified by segment/bus/device/function = values - * which should be encoded using the HVMOP_PCI_SBDF helper macro below. - * - * NOTE: unless an emulation request falls entirely within a range mapped - * by a secondary emulator, it will not be passed to that emulator. - */ -#define HVMOP_map_io_range_to_ioreq_server 19 -#define HVMOP_unmap_io_range_from_ioreq_server 20 -struct xen_hvm_io_range { - domid_t domid; /* IN - domain to be serviced */ - ioservid_t id; /* IN - server id */ - uint32_t type; /* IN - type of range */ -# define HVMOP_IO_RANGE_PORT 0 /* I/O port range */ -# define HVMOP_IO_RANGE_MEMORY 1 /* MMIO range */ -# define HVMOP_IO_RANGE_PCI 2 /* PCI segment/bus/dev/func range */ - uint64_aligned_t start, end; /* IN - inclusive start and end of range = */ -}; -typedef struct xen_hvm_io_range xen_hvm_io_range_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_io_range_t); - -#define HVMOP_PCI_SBDF(s,b,d,f) \ - ((((s) & 0xffff) << 16) | \ - (((b) & 0xff) << 8) | \ - (((d) & 0x1f) << 3) | \ - ((f) & 0x07)) - -/* - * HVMOP_destroy_ioreq_server: Destroy the IOREQ Server servicing = domain - * . - * - * Any registered I/O ranges will be automatically deregistered. - */ -#define HVMOP_destroy_ioreq_server 21 -struct xen_hvm_destroy_ioreq_server { - domid_t domid; /* IN - domain to be serviced */ - ioservid_t id; /* IN - server id */ -}; -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 = servicing - * domain . - * - * 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? */ =20 -}; -typedef struct xen_hvm_set_ioreq_server_state xen_hvm_set_ioreq_server_sta= te_t; -DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t); - -#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ - #if defined(__i386__) || defined(__x86_64__) =20 /* --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -609,12 +609,6 @@ static XSM_INLINE int xsm_shadow_control return xsm_default_action(action, current->domain, d); } =20 -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_sharing_op(XSM_DEFAULT_ARG struct domain = *d, struct domain *cd, int op) { XSM_ASSERT_ACTION(XSM_DM_PRIV); --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -174,7 +174,6 @@ struct xsm_operations { int (*do_mca) (void); int (*shadow_control) (struct domain *d, uint32_t op); int (*hvm_set_pci_link_route) (struct domain *d); - int (*hvm_ioreq_server) (struct domain *d, int op); int (*mem_sharing_op) (struct domain *d, struct domain *cd, int op); int (*apic) (struct domain *d, int cmd); int (*memtype) (uint32_t access); @@ -648,11 +647,6 @@ static inline int xsm_hvm_set_pci_link_r return xsm_ops->hvm_set_pci_link_route(d); } =20 -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_sharing_op (xsm_default_t def, struct domain = *d, struct domain *cd, int op) { return xsm_ops->mem_sharing_op(d, cd, op); --- a/xen/xsm/dummy.c +++ b/xen/xsm/dummy.c @@ -145,7 +145,6 @@ void xsm_fixup_ops (struct xsm_operation #ifdef CONFIG_X86 set_to_dummy_if_null(ops, do_mca); set_to_dummy_if_null(ops, shadow_control); - set_to_dummy_if_null(ops, hvm_ioreq_server); set_to_dummy_if_null(ops, mem_sharing_op); set_to_dummy_if_null(ops, apic); set_to_dummy_if_null(ops, machine_memory_map); --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -1526,11 +1526,6 @@ static int flask_ioport_mapping(struct d return flask_ioport_permission(d, start, end, access); } =20 -static int flask_hvm_ioreq_server(struct domain *d, int op) -{ - return current_has_perm(d, SECCLASS_HVM, HVM__HVMCTL); -} - static int flask_mem_sharing_op(struct domain *d, struct domain *cd, int = op) { int rc =3D current_has_perm(cd, SECCLASS_HVM, HVM__MEM_SHARING); @@ -1799,7 +1794,6 @@ static struct xsm_operations flask_ops =3D #ifdef CONFIG_X86 .do_mca =3D flask_do_mca, .shadow_control =3D flask_shadow_control, - .hvm_ioreq_server =3D flask_hvm_ioreq_server, .mem_sharing_op =3D flask_mem_sharing_op, .apic =3D flask_apic, .machine_memory_map =3D flask_machine_memory_map, --=__PartEBDDD65B.3__= Content-Type: text/plain; name="hvmctl-09.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="hvmctl-09.patch" hvmctl: convert HVMOP_*ioreq_server*=0A=0ANote that we can't adjust = HVM_IOREQSRV_BUFIOREQ_* to properly obey=0Aname space rules, as these = constants as in use by callers of the libxc=0Ainterface.=0A=0ASigned-off-by= : Jan Beulich =0A=0A--- a/tools/libxc/include/xenctrl.h= =0A+++ b/tools/libxc/include/xenctrl.h=0A@@ -41,6 +41,7 @@=0A #include = =0A #include =0A #include =0A= +#include =0A #include =0A #include = =0A #include =0A--- a/tools/libxc/xc_domain= .c=0A+++ b/tools/libxc/xc_domain.c=0A@@ -1416,23 +1416,14 @@ int xc_hvm_cre= ate_ioreq_server(xc_interf=0A int handle_buf= ioreq,=0A ioservid_t *id)=0A {=0A- = DECLARE_HYPERCALL_BUFFER(xen_hvm_create_ioreq_server_t, arg);=0A+ = DECLARE_HVMCTL(create_ioreq_server, domid,=0A+ .handle_bu= fioreq =3D handle_bufioreq);=0A int rc;=0A =0A- arg =3D xc_hypercall= _buffer_alloc(xch, arg, sizeof(*arg));=0A- if ( arg =3D=3D NULL )=0A- = return -1;=0A-=0A- arg->domid =3D domid;=0A- arg->handle_bufiore= q =3D handle_bufioreq;=0A-=0A- rc =3D xencall2(xch->xcall, __HYPERVISOR_= hvm_op,=0A- HVMOP_create_ioreq_server,=0A- = HYPERCALL_BUFFER_AS_ARG(arg));=0A+ rc =3D do_hvmctl(xch, &hvmctl);=0A = =0A- *id =3D arg->id;=0A+ *id =3D hvmctl.u.create_ioreq_server.id;=0A= =0A- xc_hypercall_buffer_free(xch, arg);=0A return rc;=0A }=0A = =0A@@ -1443,84 +1434,52 @@ int xc_hvm_get_ioreq_server_info(xc_inte=0A = xen_pfn_t *bufioreq_pfn,=0A = evtchn_port_t *bufioreq_port)=0A {=0A- DECLARE_HYPERCALL_= BUFFER(xen_hvm_get_ioreq_server_info_t, arg);=0A+ DECLARE_HVMCTL(get_ior= eq_server_info, domid,=0A+ .id =3D id);=0A int = rc;=0A =0A- arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));= =0A- if ( arg =3D=3D NULL )=0A- return -1;=0A-=0A- arg->domid = =3D domid;=0A- arg->id =3D id;=0A-=0A- rc =3D xencall2(xch->xcall, = __HYPERVISOR_hvm_op,=0A- HVMOP_get_ioreq_server_info,=0A- = HYPERCALL_BUFFER_AS_ARG(arg));=0A+ rc =3D do_hvmctl(xch= , &hvmctl);=0A if ( rc !=3D 0 )=0A- goto done;=0A+ = return rc;=0A =0A if ( ioreq_pfn )=0A- *ioreq_pfn =3D arg->ioreq= _pfn;=0A+ *ioreq_pfn =3D hvmctl.u.get_ioreq_server_info.ioreq_pfn;= =0A =0A if ( bufioreq_pfn )=0A- *bufioreq_pfn =3D arg->bufioreq_= pfn;=0A+ *bufioreq_pfn =3D hvmctl.u.get_ioreq_server_info.bufioreq_p= fn;=0A =0A if ( bufioreq_port )=0A- *bufioreq_port =3D = arg->bufioreq_port;=0A+ *bufioreq_port =3D hvmctl.u.get_ioreq_server= _info.bufioreq_port;=0A =0A-done:=0A- xc_hypercall_buffer_free(xch, = arg);=0A- return rc;=0A+ return 0;=0A }=0A =0A int xc_hvm_map_io_rang= e_to_ioreq_server(xc_interface *xch, domid_t domid,=0A = ioservid_t id, int is_mmio,=0A = uint64_t start, uint64_t end)=0A {=0A- DECLARE_HYPERCALL= _BUFFER(xen_hvm_io_range_t, arg);=0A- int rc;=0A-=0A- arg =3D = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));=0A- if ( arg =3D=3D = NULL )=0A- return -1;=0A-=0A- arg->domid =3D domid;=0A- = arg->id =3D id;=0A- arg->type =3D is_mmio ? HVMOP_IO_RANGE_MEMORY : = HVMOP_IO_RANGE_PORT;=0A- arg->start =3D start;=0A- arg->end =3D = end;=0A-=0A- rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op,=0A- = HVMOP_map_io_range_to_ioreq_server,=0A- = HYPERCALL_BUFFER_AS_ARG(arg));=0A+ DECLARE_HVMCTL(map_io_range_to_ioreq_= server, domid,=0A+ .id =3D id,=0A+ = .type =3D is_mmio ? XEN_HVMCTL_IO_RANGE_MEMORY=0A+ = : XEN_HVMCTL_IO_RANGE_PORT,=0A+ .start =3D = start,=0A+ .end =3D end);=0A =0A- xc_hypercall_buffer_= free(xch, arg);=0A- return rc;=0A+ return do_hvmctl(xch, &hvmctl);=0A= }=0A =0A int xc_hvm_unmap_io_range_from_ioreq_server(xc_interface *xch, = domid_t domid,=0A ioservid_t = id, int is_mmio,=0A uint64_t = start, uint64_t end)=0A {=0A- DECLARE_HYPERCALL_BUFFER(xen_hvm_io_range_= t, arg);=0A- int rc;=0A-=0A- arg =3D xc_hypercall_buffer_alloc(xch, = arg, sizeof(*arg));=0A- if ( arg =3D=3D NULL )=0A- return = -1;=0A+ DECLARE_HVMCTL(unmap_io_range_from_ioreq_server, domid,=0A+ = .id =3D id,=0A+ .type =3D is_mmio ? = XEN_HVMCTL_IO_RANGE_MEMORY=0A+ : = XEN_HVMCTL_IO_RANGE_PORT,=0A+ .start =3D start,=0A+ = .end =3D end);=0A =0A- arg->domid =3D domid;=0A- = arg->id =3D id;=0A- arg->type =3D is_mmio ? HVMOP_IO_RANGE_MEMORY : = HVMOP_IO_RANGE_PORT;=0A- arg->start =3D start;=0A- arg->end =3D = end;=0A-=0A- rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op,=0A- = HVMOP_unmap_io_range_from_ioreq_server,=0A- = HYPERCALL_BUFFER_AS_ARG(arg));=0A-=0A- xc_hypercall_buffer_free(xch, = arg);=0A- return rc;=0A+ return do_hvmctl(xch, &hvmctl);=0A }=0A =0A = int xc_hvm_map_pcidev_to_ioreq_server(xc_interface *xch, domid_t domid,=0A@= @ -1528,37 +1487,23 @@ int xc_hvm_map_pcidev_to_ioreq_server(xc=0A = uint8_t bus, uint8_t device,=0A = uint8_t function)=0A {=0A- DECLARE_HYPERCALL_BU= FFER(xen_hvm_io_range_t, arg);=0A- int rc;=0A+ /*=0A+ * The = underlying hypercall will deal with ranges of PCI SBDF=0A+ * but, for = simplicity, the API only uses singletons.=0A+ */=0A+ uint32_t sbdf = =3D XEN_HVMCTL_PCI_SBDF(segment, bus, device, function);=0A+ DECLARE_HVM= CTL(map_io_range_to_ioreq_server, domid,=0A+ .id =3D = id,=0A+ .type =3D XEN_HVMCTL_IO_RANGE_PCI,=0A+ = .start =3D sbdf,=0A+ .end =3D sbdf);=0A =0A = if (device > 0x1f || function > 0x7) {=0A errno =3D EINVAL;=0A = return -1;=0A }=0A =0A- arg =3D xc_hypercall_buffer_alloc(xch, = arg, sizeof(*arg));=0A- if ( arg =3D=3D NULL )=0A- return = -1;=0A-=0A- arg->domid =3D domid;=0A- arg->id =3D id;=0A- = arg->type =3D HVMOP_IO_RANGE_PCI;=0A-=0A- /*=0A- * The underlying = hypercall will deal with ranges of PCI SBDF=0A- * but, for simplicity, = the API only uses singletons.=0A- */=0A- arg->start =3D arg->end = =3D HVMOP_PCI_SBDF((uint64_t)segment,=0A- = (uint64_t)bus,=0A- = (uint64_t)device,=0A- (uint64_t)f= unction);=0A-=0A- rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op,=0A- = HVMOP_map_io_range_to_ioreq_server,=0A- = HYPERCALL_BUFFER_AS_ARG(arg));=0A-=0A- xc_hypercall_buffer_free(xch, = arg);=0A- return rc;=0A+ return do_hvmctl(xch, &hvmctl);=0A }=0A =0A = int xc_hvm_unmap_pcidev_from_ioreq_server(xc_interface *xch, domid_t = domid,=0A@@ -1566,54 +1511,29 @@ int xc_hvm_unmap_pcidev_from_ioreq_serve= =0A uint8_t bus, uint8_t = device,=0A uint8_t function)=0A = {=0A- DECLARE_HYPERCALL_BUFFER(xen_hvm_io_range_t, arg);=0A- int = rc;=0A+ uint32_t sbdf =3D XEN_HVMCTL_PCI_SBDF(segment, bus, device, = function);=0A+ DECLARE_HVMCTL(unmap_io_range_from_ioreq_server, = domid,=0A+ .id =3D id,=0A+ .type =3D = XEN_HVMCTL_IO_RANGE_PCI,=0A+ .start =3D sbdf,=0A+ = .end =3D sbdf);=0A =0A if (device > 0x1f || function > 0x7) = {=0A errno =3D EINVAL;=0A return -1;=0A }=0A =0A- = arg =3D xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));=0A- if ( arg = =3D=3D NULL )=0A- return -1;=0A-=0A- arg->domid =3D domid;=0A- = arg->id =3D id;=0A- arg->type =3D HVMOP_IO_RANGE_PCI;=0A- arg->start= =3D arg->end =3D HVMOP_PCI_SBDF((uint64_t)segment,=0A- = (uint64_t)bus,=0A- = (uint64_t)device,=0A- = (uint64_t)function);=0A-=0A- rc =3D xencall2(xch->xcall, __HYPERVISOR_hv= m_op,=0A- HVMOP_unmap_io_range_from_ioreq_server,=0A- = HYPERCALL_BUFFER_AS_ARG(arg));=0A-=0A- xc_hypercall_buffer_= free(xch, arg);=0A- return rc;=0A+ return do_hvmctl(xch, &hvmctl);=0A= }=0A =0A int xc_hvm_destroy_ioreq_server(xc_interface *xch,=0A = domid_t domid,=0A = ioservid_t id)=0A {=0A- DECLARE_HYPERCALL_BUFFER(xen_hvm_destroy_ioreq_s= erver_t, arg);=0A- int rc;=0A-=0A- arg =3D xc_hypercall_buffer_alloc(= xch, arg, sizeof(*arg));=0A- if ( arg =3D=3D NULL )=0A- return = -1;=0A+ DECLARE_HVMCTL(destroy_ioreq_server, domid,=0A+ = .id =3D id);=0A =0A- arg->domid =3D domid;=0A- arg->id =3D = id;=0A-=0A- rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op,=0A- = HVMOP_destroy_ioreq_server,=0A- HYPERCALL_BUFFER= _AS_ARG(arg));=0A-=0A- xc_hypercall_buffer_free(xch, arg);=0A- = return rc;=0A+ return do_hvmctl(xch, &hvmctl);=0A }=0A =0A int = xc_hvm_set_ioreq_server_state(xc_interface *xch,=0A@@ -1621,23 +1541,11 @@ = int xc_hvm_set_ioreq_server_state(xc_int=0A = ioservid_t id,=0A int enabled)=0A = {=0A- DECLARE_HYPERCALL_BUFFER(xen_hvm_set_ioreq_server_state_t, = arg);=0A- int rc;=0A-=0A- arg =3D xc_hypercall_buffer_alloc(xch, = arg, sizeof(*arg));=0A- if ( arg =3D=3D NULL )=0A- return = -1;=0A+ DECLARE_HVMCTL(set_ioreq_server_state, domid,=0A+ = .id =3D id,=0A+ .enabled =3D !!enabled);=0A =0A- = arg->domid =3D domid;=0A- arg->id =3D id;=0A- arg->enabled =3D = !!enabled;=0A-=0A- rc =3D xencall2(xch->xcall, __HYPERVISOR_hvm_op,=0A- = HVMOP_set_ioreq_server_state,=0A- = HYPERCALL_BUFFER_AS_ARG(arg));=0A-=0A- xc_hypercall_buffer_free(xch, = arg);=0A- return rc;=0A+ return do_hvmctl(xch, &hvmctl);=0A }=0A =0A = int xc_domain_setdebugging(xc_interface *xch,=0A--- a/tools/libxc/xc_privat= e.h=0A+++ b/tools/libxc/xc_private.h=0A@@ -34,8 +34,6 @@=0A #define = XC_INTERNAL_COMPAT_MAP_FOREIGN_API=0A #include "xenctrl.h"=0A =0A-#include = =0A-=0A #include =0A #include =0A =0A--- a/xen/arch/x86/hvm/control.c=0A+++ b/xen/arch/x86/hvm/contr= ol.c=0A@@ -20,6 +20,7 @@=0A #include =0A #include = =0A #include =0A+#include =0A #include = =0A =0A static int set_pci_intx_level(struct domain *d,=0A@@ = -299,6 +300,50 @@ long do_hvmctl(XEN_GUEST_HANDLE_PARAM(xe=0A rc = =3D hvm_inject_msi(d, op.u.inject_msi.addr, op.u.inject_msi.data);=0A = break;=0A =0A+ case XEN_HVMCTL_create_ioreq_server:=0A+ rc = =3D -EINVAL;=0A+ if ( op.u.create_ioreq_server.rsvd )=0A+ = break;=0A+ rc =3D hvm_create_ioreq_server(d, current->domain->domai= n_id, 0,=0A+ op.u.create_ioreq_server.h= andle_bufioreq,=0A+ &op.u.create_ioreq_= server.id);=0A+ if ( rc =3D=3D 0 && copy_field_to_guest(u_hvmctl, = &op,=0A+ u.create_ioreq_server.i= d) )=0A+ rc =3D -EFAULT;=0A+ break;=0A+=0A+ case = XEN_HVMCTL_get_ioreq_server_info:=0A+ rc =3D -EINVAL;=0A+ if = ( op.u.get_ioreq_server_info.rsvd )=0A+ break;=0A+ rc = =3D hvm_get_ioreq_server_info(d, &op.u.get_ioreq_server_info);=0A+ = if ( rc =3D=3D 0 && copy_field_to_guest(u_hvmctl, &op,=0A+ = u.get_ioreq_server_info) )=0A+ rc = =3D -EFAULT;=0A+ break;=0A+=0A+ case XEN_HVMCTL_map_io_range_to_i= oreq_server:=0A+ rc =3D hvm_map_io_range_to_ioreq_server(=0A+ = d, &op.u.map_io_range_to_ioreq_server);=0A+ break;=0A+=0A+= case XEN_HVMCTL_unmap_io_range_from_ioreq_server:=0A+ rc =3D = hvm_unmap_io_range_from_ioreq_server(=0A+ d, &op.u.unmap_io= _range_from_ioreq_server);=0A+ break;=0A+=0A+ case XEN_HVMCTL_des= troy_ioreq_server:=0A+ rc =3D hvm_destroy_ioreq_server(d, op.u.destr= oy_ioreq_server.id);=0A+ break;=0A+=0A+ case XEN_HVMCTL_set_ioreq= _server_state:=0A+ rc =3D -EINVAL;=0A+ if ( op.u.set_ioreq_se= rver_state.rsvd )=0A+ break;=0A+ rc =3D hvm_set_ioreq_ser= ver_state(d, op.u.set_ioreq_server_state.id,=0A+ = !!op.u.set_ioreq_server_state.enabled);=0A+ break;=0A+= =0A default:=0A rc =3D -EOPNOTSUPP;=0A break;=0A--- = a/xen/arch/x86/hvm/hvm.c=0A+++ b/xen/arch/x86/hvm/hvm.c=0A@@ -4487,195 = +4487,6 @@ static int hvmop_flush_tlb_all(void)=0A return 0;=0A }=0A = =0A-static int hvmop_create_ioreq_server(=0A- XEN_GUEST_HANDLE_PARAM(xen= _hvm_create_ioreq_server_t) uop)=0A-{=0A- struct domain *curr_d =3D = current->domain;=0A- xen_hvm_create_ioreq_server_t op;=0A- struct = domain *d;=0A- int rc;=0A-=0A- if ( copy_from_guest(&op, uop, 1) = )=0A- return -EFAULT;=0A-=0A- rc =3D rcu_lock_remote_domain_by_id= (op.domid, &d);=0A- if ( rc !=3D 0 )=0A- return rc;=0A-=0A- = rc =3D -EINVAL;=0A- if ( !is_hvm_domain(d) )=0A- goto out;=0A-=0A= - rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, HVMOP_create_ioreq_server)= ;=0A- if ( rc !=3D 0 )=0A- goto out;=0A-=0A- rc =3D hvm_create= _ioreq_server(d, curr_d->domain_id, 0,=0A- = op.handle_bufioreq, &op.id);=0A- if ( rc !=3D 0 )=0A- goto = out;=0A-=0A- rc =3D copy_to_guest(uop, &op, 1) ? -EFAULT : 0;=0A- = =0A- out:=0A- rcu_unlock_domain(d);=0A- return rc;=0A-}=0A-=0A-static= int hvmop_get_ioreq_server_info(=0A- XEN_GUEST_HANDLE_PARAM(xen_hvm_get= _ioreq_server_info_t) uop)=0A-{=0A- xen_hvm_get_ioreq_server_info_t = op;=0A- struct domain *d;=0A- int rc;=0A-=0A- if ( copy_from_guest= (&op, uop, 1) )=0A- return -EFAULT;=0A-=0A- rc =3D rcu_lock_remot= e_domain_by_id(op.domid, &d);=0A- if ( rc !=3D 0 )=0A- return = rc;=0A-=0A- rc =3D -EINVAL;=0A- if ( !is_hvm_domain(d) )=0A- = goto out;=0A-=0A- rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, HVMOP_get_= ioreq_server_info);=0A- if ( rc !=3D 0 )=0A- goto out;=0A-=0A- = rc =3D hvm_get_ioreq_server_info(d, op.id,=0A- = &op.ioreq_pfn,=0A- &op.bufioreq_pf= n, =0A- &op.bufioreq_port);=0A- if ( = rc !=3D 0 )=0A- goto out;=0A-=0A- rc =3D copy_to_guest(uop, &op, = 1) ? -EFAULT : 0;=0A- =0A- out:=0A- rcu_unlock_domain(d);=0A- = return rc;=0A-}=0A-=0A-static int hvmop_map_io_range_to_ioreq_server(=0A- = XEN_GUEST_HANDLE_PARAM(xen_hvm_io_range_t) uop)=0A-{=0A- xen_hvm_io_ra= nge_t op;=0A- struct domain *d;=0A- int rc;=0A-=0A- if ( = copy_from_guest(&op, uop, 1) )=0A- return -EFAULT;=0A-=0A- rc = =3D rcu_lock_remote_domain_by_id(op.domid, &d);=0A- if ( rc !=3D 0 = )=0A- return rc;=0A-=0A- rc =3D -EINVAL;=0A- if ( !is_hvm_doma= in(d) )=0A- goto out;=0A-=0A- rc =3D xsm_hvm_ioreq_server(XSM_DM_= PRIV, d, HVMOP_map_io_range_to_ioreq_server);=0A- if ( rc !=3D 0 )=0A- = goto out;=0A-=0A- rc =3D hvm_map_io_range_to_ioreq_server(d, = op.id, op.type,=0A- op.start, = op.end);=0A-=0A- out:=0A- rcu_unlock_domain(d);=0A- return = rc;=0A-}=0A-=0A-static int hvmop_unmap_io_range_from_ioreq_server(=0A- = XEN_GUEST_HANDLE_PARAM(xen_hvm_io_range_t) uop)=0A-{=0A- xen_hvm_io_rang= e_t op;=0A- struct domain *d;=0A- int rc;=0A-=0A- if ( copy_from_g= uest(&op, uop, 1) )=0A- return -EFAULT;=0A-=0A- rc =3D rcu_lock_r= emote_domain_by_id(op.domid, &d);=0A- if ( rc !=3D 0 )=0A- = return rc;=0A-=0A- rc =3D -EINVAL;=0A- if ( !is_hvm_domain(d) )=0A- = goto out;=0A-=0A- rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, = HVMOP_unmap_io_range_from_ioreq_server);=0A- if ( rc !=3D 0 )=0A- = goto out;=0A-=0A- rc =3D hvm_unmap_io_range_from_ioreq_server(d, = op.id, op.type,=0A- op.start, = op.end);=0A- =0A- out:=0A- rcu_unlock_domain(d);=0A- return = rc;=0A-}=0A-=0A-static int hvmop_set_ioreq_server_state(=0A- XEN_GUEST_H= ANDLE_PARAM(xen_hvm_set_ioreq_server_state_t) uop)=0A-{=0A- xen_hvm_set_= ioreq_server_state_t op;=0A- struct domain *d;=0A- int rc;=0A-=0A- = if ( copy_from_guest(&op, uop, 1) )=0A- return -EFAULT;=0A-=0A- = rc =3D rcu_lock_remote_domain_by_id(op.domid, &d);=0A- if ( rc !=3D 0 = )=0A- return rc;=0A-=0A- rc =3D -EINVAL;=0A- if ( !is_hvm_doma= in(d) )=0A- goto out;=0A-=0A- rc =3D xsm_hvm_ioreq_server(XSM_DM_= PRIV, d, HVMOP_set_ioreq_server_state);=0A- if ( rc !=3D 0 )=0A- = goto out;=0A-=0A- rc =3D hvm_set_ioreq_server_state(d, op.id, !!op.enabl= ed);=0A-=0A- out:=0A- rcu_unlock_domain(d);=0A- return rc;=0A-}=0A-= =0A-static int hvmop_destroy_ioreq_server(=0A- XEN_GUEST_HANDLE_PARAM(xe= n_hvm_destroy_ioreq_server_t) uop)=0A-{=0A- xen_hvm_destroy_ioreq_server= _t op;=0A- struct domain *d;=0A- int rc;=0A-=0A- if ( copy_from_gu= est(&op, uop, 1) )=0A- return -EFAULT;=0A-=0A- rc =3D rcu_lock_re= mote_domain_by_id(op.domid, &d);=0A- if ( rc !=3D 0 )=0A- return = rc;=0A-=0A- rc =3D -EINVAL;=0A- if ( !is_hvm_domain(d) )=0A- = goto out;=0A-=0A- rc =3D xsm_hvm_ioreq_server(XSM_DM_PRIV, d, HVMOP_dest= roy_ioreq_server);=0A- if ( rc !=3D 0 )=0A- goto out;=0A-=0A- = rc =3D hvm_destroy_ioreq_server(d, op.id);=0A-=0A- out:=0A- rcu_unlock_d= omain(d);=0A- return rc;=0A-}=0A-=0A static int hvmop_set_evtchn_upcall_= vector(=0A XEN_GUEST_HANDLE_PARAM(xen_hvm_evtchn_upcall_vector_t) = uop)=0A {=0A@@ -5192,36 +5003,6 @@ long do_hvm_op(unsigned long op, = XEN_GUE=0A =0A switch ( op )=0A {=0A- case HVMOP_create_ioreq_se= rver:=0A- rc =3D hvmop_create_ioreq_server(=0A- = guest_handle_cast(arg, xen_hvm_create_ioreq_server_t));=0A- = break;=0A- =0A- case HVMOP_get_ioreq_server_info:=0A- rc =3D = hvmop_get_ioreq_server_info(=0A- guest_handle_cast(arg, = xen_hvm_get_ioreq_server_info_t));=0A- break;=0A- =0A- case = HVMOP_map_io_range_to_ioreq_server:=0A- rc =3D hvmop_map_io_range_to= _ioreq_server(=0A- guest_handle_cast(arg, xen_hvm_io_range_t));= =0A- break;=0A- =0A- case HVMOP_unmap_io_range_from_ioreq_serv= er:=0A- rc =3D hvmop_unmap_io_range_from_ioreq_server(=0A- = guest_handle_cast(arg, xen_hvm_io_range_t));=0A- break;=0A-=0A- = case HVMOP_set_ioreq_server_state:=0A- rc =3D hvmop_set_ioreq_serve= r_state(=0A- guest_handle_cast(arg, xen_hvm_set_ioreq_server_sta= te_t));=0A- break;=0A- =0A- case HVMOP_destroy_ioreq_server:= =0A- rc =3D hvmop_destroy_ioreq_server(=0A- guest_handle_= cast(arg, xen_hvm_destroy_ioreq_server_t));=0A- break;=0A- =0A = case HVMOP_set_evtchn_upcall_vector:=0A rc =3D hvmop_set_evtchn_u= pcall_vector(=0A guest_handle_cast(arg, xen_hvm_evtchn_upcall_v= ector_t));=0A--- a/xen/arch/x86/hvm/ioreq.c=0A+++ b/xen/arch/x86/hvm/ioreq.= c=0A@@ -513,9 +513,9 @@ static int hvm_ioreq_server_alloc_ranges=0A = char *name;=0A =0A rc =3D asprintf(&name, "ioreq_server %d %s", = s->id,=0A- (i =3D=3D HVMOP_IO_RANGE_PORT) ? "port" = :=0A- (i =3D=3D HVMOP_IO_RANGE_MEMORY) ? "memory" = :=0A- (i =3D=3D HVMOP_IO_RANGE_PCI) ? "pci" :=0A+ = (i =3D=3D XEN_HVMCTL_IO_RANGE_PORT) ? "port" :=0A+ = (i =3D=3D XEN_HVMCTL_IO_RANGE_MEMORY) ? "memory" :=0A+ = (i =3D=3D XEN_HVMCTL_IO_RANGE_PCI) ? "pci" :=0A = "");=0A if ( rc )=0A goto fail;=0A@@ -686,7 = +686,8 @@ int hvm_create_ioreq_server(struct domai=0A struct hvm_ioreq_= server *s;=0A int rc;=0A =0A- if ( bufioreq_handling > HVM_IOREQSRV_= BUFIOREQ_ATOMIC )=0A+ if ( !is_hvm_domain(d) ||=0A+ bufioreq_han= dling > HVM_IOREQSRV_BUFIOREQ_ATOMIC )=0A return -EINVAL;=0A =0A = rc =3D -ENOMEM;=0A@@ -738,6 +739,9 @@ int hvm_destroy_ioreq_server(struct= doma=0A struct hvm_ioreq_server *s;=0A int rc;=0A =0A+ if ( = !is_hvm_domain(d) )=0A+ return -EINVAL;=0A+=0A spin_lock_recursi= ve(&d->arch.hvm_domain.ioreq_server.lock);=0A =0A rc =3D -ENOENT;=0A@@ = -772,14 +776,15 @@ int hvm_destroy_ioreq_server(struct doma=0A return = rc;=0A }=0A =0A-int hvm_get_ioreq_server_info(struct domain *d, ioservid_t = id,=0A- unsigned long *ioreq_pfn,=0A- = unsigned long *bufioreq_pfn,=0A- = evtchn_port_t *bufioreq_port)=0A+int hvm_get_ioreq_server_info(stru= ct domain *d,=0A+ struct xen_hvm_get_ioreq_ser= ver_info *info)=0A {=0A struct hvm_ioreq_server *s;=0A int rc;=0A = =0A+ if ( !is_hvm_domain(d) )=0A+ return -EINVAL;=0A+=0A = spin_lock_recursive(&d->arch.hvm_domain.ioreq_server.lock);=0A =0A rc = =3D -ENOENT;=0A@@ -790,15 +795,15 @@ int hvm_get_ioreq_server_info(struct = dom=0A if ( s =3D=3D d->arch.hvm_domain.default_ioreq_server )=0A = continue;=0A =0A- if ( s->id !=3D id )=0A+ if ( = s->id !=3D info->id )=0A continue;=0A =0A- *ioreq_pfn = =3D s->ioreq.gmfn;=0A+ info->ioreq_pfn =3D s->ioreq.gmfn;=0A =0A = if ( s->bufioreq.va !=3D NULL )=0A {=0A- *bufioreq_= pfn =3D s->bufioreq.gmfn;=0A- *bufioreq_port =3D s->bufioreq_evt= chn;=0A+ info->bufioreq_pfn =3D s->bufioreq.gmfn;=0A+ = info->bufioreq_port =3D s->bufioreq_evtchn;=0A }=0A =0A = rc =3D 0;=0A@@ -810,13 +815,15 @@ int hvm_get_ioreq_server_info(struct = dom=0A return rc;=0A }=0A =0A-int hvm_map_io_range_to_ioreq_server(stru= ct domain *d, ioservid_t id,=0A- = uint32_t type, uint64_t start,=0A- = uint64_t end)=0A+int hvm_map_io_range_to_ioreq_server(struct domain = *d,=0A+ const struct xen_hvm_io_range = *ior)=0A {=0A struct hvm_ioreq_server *s;=0A int rc;=0A =0A+ if = ( ior->rsvd || !is_hvm_domain(d) )=0A+ return -EINVAL;=0A+=0A = spin_lock_recursive(&d->arch.hvm_domain.ioreq_server.lock);=0A =0A rc = =3D -ENOENT;=0A@@ -827,16 +834,16 @@ int hvm_map_io_range_to_ioreq_server(s= tr=0A if ( s =3D=3D d->arch.hvm_domain.default_ioreq_server )=0A = continue;=0A =0A- if ( s->id =3D=3D id )=0A+ if ( = s->id =3D=3D ior->id )=0A {=0A struct rangeset *r;=0A = =0A- switch ( type )=0A+ switch ( ior->type )=0A = {=0A- case HVMOP_IO_RANGE_PORT:=0A- case = HVMOP_IO_RANGE_MEMORY:=0A- case HVMOP_IO_RANGE_PCI:=0A- = r =3D s->range[type];=0A+ case XEN_HVMCTL_IO_RANGE_PORT:= =0A+ case XEN_HVMCTL_IO_RANGE_MEMORY:=0A+ case = XEN_HVMCTL_IO_RANGE_PCI:=0A+ r =3D s->range[ior->type];=0A = break;=0A =0A default:=0A@@ -849,10 +856,10 @@ = int hvm_map_io_range_to_ioreq_server(str=0A break;=0A =0A = rc =3D -EEXIST;=0A- if ( rangeset_overlaps_range(r, = start, end) )=0A+ if ( rangeset_overlaps_range(r, ior->start, = ior->end) )=0A break;=0A =0A- rc =3D rangeset_ad= d_range(r, start, end);=0A+ rc =3D rangeset_add_range(r, = ior->start, ior->end);=0A break;=0A }=0A }=0A@@ = -862,13 +869,15 @@ int hvm_map_io_range_to_ioreq_server(str=0A return = rc;=0A }=0A =0A-int hvm_unmap_io_range_from_ioreq_server(struct domain *d, = ioservid_t id,=0A- uint32_t type, = uint64_t start,=0A- uint64_t = end)=0A+int hvm_unmap_io_range_from_ioreq_server(struct domain *d,=0A+ = const struct xen_hvm_io_range *ior)=0A = {=0A struct hvm_ioreq_server *s;=0A int rc;=0A =0A+ if ( = ior->rsvd || !is_hvm_domain(d) )=0A+ return -EINVAL;=0A+=0A = spin_lock_recursive(&d->arch.hvm_domain.ioreq_server.lock);=0A =0A rc = =3D -ENOENT;=0A@@ -879,16 +888,16 @@ int hvm_unmap_io_range_from_ioreq_serv= er=0A if ( s =3D=3D d->arch.hvm_domain.default_ioreq_server )=0A = continue;=0A =0A- if ( s->id =3D=3D id )=0A+ if ( = s->id =3D=3D ior->id )=0A {=0A struct rangeset *r;=0A = =0A- switch ( type )=0A+ switch ( ior->type )=0A = {=0A- case HVMOP_IO_RANGE_PORT:=0A- case = HVMOP_IO_RANGE_MEMORY:=0A- case HVMOP_IO_RANGE_PCI:=0A- = r =3D s->range[type];=0A+ case XEN_HVMCTL_IO_RANGE_PORT:= =0A+ case XEN_HVMCTL_IO_RANGE_MEMORY:=0A+ case = XEN_HVMCTL_IO_RANGE_PCI:=0A+ r =3D s->range[ior->type];=0A = break;=0A =0A default:=0A@@ -901,10 +910,10 @@ = int hvm_unmap_io_range_from_ioreq_server=0A break;=0A =0A = rc =3D -ENOENT;=0A- if ( !rangeset_contains_range(r, = start, end) )=0A+ if ( !rangeset_contains_range(r, ior->start, = ior->end) )=0A break;=0A =0A- rc =3D rangeset_re= move_range(r, start, end);=0A+ rc =3D rangeset_remove_range(r, = ior->start, ior->end);=0A break;=0A }=0A }=0A@@ = -920,6 +929,9 @@ int hvm_set_ioreq_server_state(struct do=0A struct = list_head *entry;=0A int rc;=0A =0A+ if ( !is_hvm_domain(d) )=0A+ = return -EINVAL;=0A+=0A spin_lock_recursive(&d->arch.hvm_domain.ior= eq_server.lock);=0A =0A rc =3D -ENOENT;=0A@@ -1128,12 +1140,12 @@ = struct hvm_ioreq_server *hvm_select_iore=0A =0A /* PCI config data = cycle */=0A =0A- sbdf =3D HVMOP_PCI_SBDF(0,=0A- = PCI_BUS(CF8_BDF(cf8)),=0A- PCI_SLOT(C= F8_BDF(cf8)),=0A- PCI_FUNC(CF8_BDF(cf8)));=0A+= sbdf =3D XEN_HVMCTL_PCI_SBDF(0,=0A+ = PCI_BUS(CF8_BDF(cf8)),=0A+ PCI_SLOT(CF= 8_BDF(cf8)),=0A+ PCI_FUNC(CF8_BDF(cf8)));= =0A =0A- type =3D HVMOP_IO_RANGE_PCI;=0A+ type =3D XEN_HVMCTL= _IO_RANGE_PCI;=0A addr =3D ((uint64_t)sbdf << 32) |=0A = CF8_ADDR_LO(cf8) |=0A (p->addr & 3);=0A@@ -1152,7 = +1164,7 @@ struct hvm_ioreq_server *hvm_select_iore=0A else=0A = {=0A type =3D (p->type =3D=3D IOREQ_TYPE_PIO) ?=0A- = HVMOP_IO_RANGE_PORT : HVMOP_IO_RANGE_MEMORY;=0A+ XEN_HVMCTL_= IO_RANGE_PORT : XEN_HVMCTL_IO_RANGE_MEMORY;=0A addr =3D p->addr;=0A= }=0A =0A@@ -1174,19 +1186,19 @@ struct hvm_ioreq_server *hvm_select_io= re=0A {=0A unsigned long end;=0A =0A- case = HVMOP_IO_RANGE_PORT:=0A+ case XEN_HVMCTL_IO_RANGE_PORT:=0A = end =3D addr + p->size - 1;=0A if ( rangeset_contains_range(= r, addr, end) )=0A return s;=0A =0A break;=0A- = case HVMOP_IO_RANGE_MEMORY:=0A+ case XEN_HVMCTL_IO_RANGE_MEMO= RY:=0A end =3D addr + (p->size * p->count) - 1;=0A = if ( rangeset_contains_range(r, addr, end) )=0A return = s;=0A =0A break;=0A- case HVMOP_IO_RANGE_PCI:=0A+ = case XEN_HVMCTL_IO_RANGE_PCI:=0A if ( rangeset_contains_single= ton(r, addr >> 32) )=0A {=0A p->type =3D = IOREQ_TYPE_PCI_CONFIG;=0A--- a/xen/include/asm-x86/hvm/domain.h=0A+++ = b/xen/include/asm-x86/hvm/domain.h=0A@@ -30,6 +30,7 @@=0A #include = =0A #include =0A #include = =0A+#include =0A #include = =0A #include =0A #include = =0A@@ -47,7 +48,7 @@ struct hvm_ioreq_vcpu {=0A = bool_t pending;=0A };=0A =0A-#define NR_IO_RANGE_TYPES (HVMOP_IO_= RANGE_PCI + 1)=0A+#define NR_IO_RANGE_TYPES (XEN_HVMCTL_IO_RANGE_PCI + = 1)=0A #define MAX_NR_IO_RANGES 256=0A =0A struct hvm_ioreq_server {=0A--- = a/xen/include/asm-x86/hvm/ioreq.h=0A+++ b/xen/include/asm-x86/hvm/ioreq.h= =0A@@ -19,6 +19,8 @@=0A #ifndef __ASM_X86_HVM_IOREQ_H__=0A #define = __ASM_X86_HVM_IOREQ_H__=0A =0A+#include =0A+=0A = bool_t hvm_io_pending(struct vcpu *v);=0A bool_t handle_hvm_io_completion(s= truct vcpu *v);=0A bool_t is_ioreq_server_page(struct domain *d, const = struct page_info *page);=0A@@ -27,16 +29,12 @@ int hvm_create_ioreq_server(= struct domai=0A bool_t is_default, int = bufioreq_handling,=0A ioservid_t *id);=0A int = hvm_destroy_ioreq_server(struct domain *d, ioservid_t id);=0A-int = hvm_get_ioreq_server_info(struct domain *d, ioservid_t id,=0A- = unsigned long *ioreq_pfn,=0A- = unsigned long *bufioreq_pfn,=0A- evtchn_port_= t *bufioreq_port);=0A-int hvm_map_io_range_to_ioreq_server(struct domain = *d, ioservid_t id,=0A- uint32_t type, = uint64_t start,=0A- uint64_t end);=0A-i= nt hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t = id,=0A- uint32_t type, uint64_t = start,=0A- uint64_t end);=0A+int = hvm_get_ioreq_server_info(struct domain *d,=0A+ = struct xen_hvm_get_ioreq_server_info *info);=0A+int hvm_map_io_range_to_i= oreq_server(struct domain *d,=0A+ = const struct xen_hvm_io_range *r);=0A+int hvm_unmap_io_range_from_ioreq_ser= ver(struct domain *d,=0A+ const = struct xen_hvm_io_range *r);=0A int hvm_set_ioreq_server_state(struct = domain *d, ioservid_t id,=0A bool_t = enabled);=0A =0A--- a/xen/include/public/hvm/control.h=0A+++ b/xen/include/= public/hvm/control.h=0A@@ -26,6 +26,7 @@=0A #endif=0A =0A #include = "../xen.h"=0A+#include "../event_channel.h"=0A =0A #define XEN_HVMCTL_INTER= FACE_VERSION 0x00000001=0A =0A@@ -130,6 +131,131 @@ struct xen_hvm_inject_m= si {=0A uint64_t addr;=0A };=0A =0A+/*=0A+ * IOREQ Servers=0A+ *=0A+ = * The interface between an I/O emulator an Xen is called an IOREQ = Server.=0A+ * A domain supports a single 'legacy' IOREQ Server which is = instantiated if=0A+ * parameter...=0A+ *=0A+ * HVM_PARAM_IOREQ_PFN is read = (to get the gmfn containing the synchronous=0A+ * ioreq structures), = or...=0A+ * HVM_PARAM_BUFIOREQ_PFN is read (to get the gmfn containing the = buffered=0A+ * ioreq ring), or...=0A+ * HVM_PARAM_BUFIOREQ_EVTCHN is read = (to get the event channel that Xen uses=0A+ * to request buffered I/O = emulation).=0A+ *=0A+ * The following hypercalls facilitate the creation = of IOREQ Servers for=0A+ * 'secondary' emulators which are invoked to = implement port I/O, memory, or=0A+ * PCI config space ranges which they = explicitly register.=0A+ */=0A+=0A+typedef uint16_t ioservid_t;=0A+=0A+/*= =0A+ * XEN_HVMCTL_create_ioreq_server: Instantiate a new IOREQ Server for = a=0A+ * secondary emulator servicing = domain=0A+ * .=0A+ *=0A+ * The = handed back is unique for . If is zero=0A+ * the = buffered ioreq ring will not be allocated and hence all emulation=0A+ * = requestes to this server will be synchronous.=0A+ */=0A+struct xen_hvm_crea= te_ioreq_server {=0A+#define HVM_IOREQSRV_BUFIOREQ_OFF 0=0A+#define = HVM_IOREQSRV_BUFIOREQ_LEGACY 1=0A+/*=0A+ * Use this when read_pointer gets = updated atomically and=0A+ * the pointer pair gets read atomically:=0A+ = */=0A+#define HVM_IOREQSRV_BUFIOREQ_ATOMIC 2=0A+ uint8_t handle_bufioreq= ; /* IN - should server handle buffered ioreqs */=0A+ uint8_t rsvd; = /* IN - must be zero */=0A+ ioservid_t id; /* OUT - = server id */=0A+};=0A+=0A+/*=0A+ * XEN_HVMCTL_get_ioreq_server_info: Get = all the information necessary to=0A+ * = access IOREQ Server .=0A+ *=0A+ * The emulator needs to map the = synchronous ioreq structures and buffered=0A+ * ioreq ring (if it exists) = that Xen uses to request emulation. These are=0A+ * hosted in domain = 's gmfns and =0A+ * respectively. In = addition, if the IOREQ Server is handling buffered=0A+ * emulation = requests, the emulator needs to bind to event channel=0A+ * = to listen for them. (The event channels used for=0A+ * synchronous = emulation requests are specified in the per-CPU ioreq=0A+ * structures in = ).=0A+ * If the IOREQ Server is not handling buffered emulation = requests then the=0A+ * values handed back in and will both be 0.=0A+ */=0A+struct xen_hvm_get_ioreq_server_info {=0A+ = ioservid_t id; /* IN - server id */=0A+ uint16_t = rsvd; /* IN - must be zero */=0A+ evtchn_port_t = bufioreq_port; /* OUT - buffered ioreq port */=0A+ uint64_aligned_t = ioreq_pfn; /* OUT - sync ioreq pfn */=0A+ uint64_aligned_t bufioreq_p= fn; /* OUT - buffered ioreq pfn */=0A+};=0A+=0A+/*=0A+ * XEN_HVMCTL_map_io_= range_to_ioreq_server: Register an I/O range of domain=0A+ * = for emulation by the=0A+ * = client of IOREQ Server =0A+ * XEN_HVMCTL_un= map_io_range_from_ioreq_server: Deregister an I/O range of=0A+ * = for emulation by the=0A+ * = client of IOREQ Server =0A+ = *=0A+ * There are three types of I/O that can be emulated: port I/O, = memory accesses=0A+ * and PCI config space accesses. The field = denotes which type of range=0A+ * the and (inclusive) fields = are specifying.=0A+ * PCI config space ranges are specified by segment/bus/= device/function values=0A+ * which should be encoded using the XEN_HVMCTL_P= CI_SBDF helper macro below.=0A+ *=0A+ * NOTE: unless an emulation request = falls entirely within a range mapped=0A+ * by a secondary emulator, it = will not be passed to that emulator.=0A+ */=0A+struct xen_hvm_io_range = {=0A+ ioservid_t id; /* IN - server id */=0A+ uint16_t = type; /* IN - type of range */=0A+ uint32_t rsvd; = /* IN - must be zero */=0A+#define XEN_HVMCTL_IO_RANGE_PORT 0 /* = I/O port range */=0A+#define XEN_HVMCTL_IO_RANGE_MEMORY 1 /* MMIO range = */=0A+#define XEN_HVMCTL_IO_RANGE_PCI 2 /* PCI segment/bus/dev/func = range */=0A+ uint64_aligned_t start, end; /* IN - inclusive start and = end of range */=0A+};=0A+=0A+#define XEN_HVMCTL_PCI_SBDF(s, b, d, f) \=0A+ = ((((s) & 0xffff) << 16) | \=0A+ (((b) & 0xff) << 8) | \=0A+ (((d) & = 0x1f) << 3) | \=0A+ ((f) & 0x07))=0A+=0A+/*=0A+ * XEN_HVMCTL_destroy_i= oreq_server: Destroy the IOREQ Server servicing=0A+ * = domain .=0A+ *=0A+ * Any registered I/O ranges = will be automatically deregistered.=0A+ */=0A+struct xen_hvm_destroy_ioreq_= server {=0A+ ioservid_t id; /* IN - server id */=0A+};=0A+=0A+/*=0A+ * = XEN_HVMCTL_set_ioreq_server_state: Enable or disable the IOREQ Server = =0A+ * servicing domain .=0A+= *=0A+ * The IOREQ Server will not be passed any emulation requests until = it is in=0A+ * the enabled state.=0A+ * Note that the contents of the = ioreq_pfn and bufioreq_fn (see=0A+ * XEN_HVMCTL_get_ioreq_server_info) are = not meaningful until the IOREQ Server=0A+ * is in the enabled state.=0A+ = */=0A+struct xen_hvm_set_ioreq_server_state {=0A+ ioservid_t id; /* = IN - server id */=0A+ uint8_t enabled; /* IN - enabled? */=0A+ = uint8_t rsvd; /* IN - must be zero */=0A+};=0A+=0A struct xen_hvmctl = {=0A uint16_t interface_version; /* XEN_HVMCTL_INTERFACE_VERSION = */=0A domid_t domain;=0A@@ -142,6 +268,12 @@ struct xen_hvmctl {=0A = #define XEN_HVMCTL_set_mem_type 6=0A #define XEN_HVMCTL_in= ject_trap 7=0A #define XEN_HVMCTL_inject_msi = 8=0A+#define XEN_HVMCTL_create_ioreq_server 9=0A+#define = XEN_HVMCTL_get_ioreq_server_info 10=0A+#define XEN_HVMCTL_map_io_ran= ge_to_ioreq_server 11=0A+#define XEN_HVMCTL_unmap_io_range_from_ioreq_serve= r 12=0A+#define XEN_HVMCTL_destroy_ioreq_server 13=0A+#define = XEN_HVMCTL_set_ioreq_server_state 14=0A uint16_t opaque; = /* Must be zero on initial invocation. */=0A union {=0A = struct xen_hvm_set_pci_intx_level set_pci_intx_level;=0A@@ -152,6 +284,12 = @@ struct xen_hvmctl {=0A struct xen_hvm_set_mem_type set_mem_type;= =0A struct xen_hvm_inject_trap inject_trap;=0A struct = xen_hvm_inject_msi inject_msi;=0A+ struct xen_hvm_create_ioreq_serve= r create_ioreq_server;=0A+ struct xen_hvm_get_ioreq_server_info = get_ioreq_server_info;=0A+ struct xen_hvm_io_range map_io_range_to_i= oreq_server;=0A+ struct xen_hvm_io_range unmap_io_range_from_ioreq_s= erver;=0A+ struct xen_hvm_destroy_ioreq_server destroy_ioreq_server;= =0A+ struct xen_hvm_set_ioreq_server_state set_ioreq_server_state;= =0A uint8_t pad[120];=0A } u;=0A };=0A--- a/xen/include/public/= hvm/hvm_op.h=0A+++ b/xen/include/public/hvm/hvm_op.h=0A@@ -25,7 +25,6 = @@=0A =0A #include "../xen.h"=0A #include "../trace.h"=0A-#include = "../event_channel.h"=0A =0A /* Get/set subcommands: extra argument =3D=3D = pointer to xen_hvm_param struct. */=0A #define HVMOP_set_param = 0=0A@@ -137,152 +136,6 @@ struct xen_hvm_get_mem_type {=0A typedef struct = xen_hvm_get_mem_type xen_hvm_get_mem_type_t;=0A DEFINE_XEN_GUEST_HANDLE(xen= _hvm_get_mem_type_t);=0A =0A-/* Following tools-only interfaces may change = in future. */=0A-#if defined(__XEN__) || defined(__XEN_TOOLS__)=0A-=0A-/*= =0A- * IOREQ Servers=0A- *=0A- * The interface between an I/O emulator an = Xen is called an IOREQ Server.=0A- * A domain supports a single 'legacy' = IOREQ Server which is instantiated if=0A- * parameter...=0A- *=0A- * = HVM_PARAM_IOREQ_PFN is read (to get the gmfn containing the synchronous=0A-= * ioreq structures), or...=0A- * HVM_PARAM_BUFIOREQ_PFN is read (to get = the gmfn containing the buffered=0A- * ioreq ring), or...=0A- * HVM_PARAM_B= UFIOREQ_EVTCHN is read (to get the event channel that Xen uses=0A- * to = request buffered I/O emulation).=0A- * =0A- * The following hypercalls = facilitate the creation of IOREQ Servers for=0A- * 'secondary' emulators = which are invoked to implement port I/O, memory, or=0A- * PCI config space = ranges which they explicitly register.=0A- */=0A-=0A-typedef uint16_t = ioservid_t;=0A-=0A-/*=0A- * HVMOP_create_ioreq_server: Instantiate a new = IOREQ Server for a secondary=0A- * emulator = servicing domain .=0A- *=0A- * The handed back is unique for = . If is zero=0A- * the buffered ioreq ring will = not be allocated and hence all emulation=0A- * requestes to this server = will be synchronous.=0A- */=0A-#define HVMOP_create_ioreq_server 17=0A-stru= ct xen_hvm_create_ioreq_server {=0A- domid_t domid; /* IN - = domain to be serviced */=0A-#define HVM_IOREQSRV_BUFIOREQ_OFF 0=0A-#defi= ne HVM_IOREQSRV_BUFIOREQ_LEGACY 1=0A-/*=0A- * Use this when read_pointer = gets updated atomically and=0A- * the pointer pair gets read atomically:=0A= - */=0A-#define HVM_IOREQSRV_BUFIOREQ_ATOMIC 2=0A- uint8_t handle_bufior= eq; /* IN - should server handle buffered ioreqs */=0A- ioservid_t id; = /* OUT - server id */=0A-};=0A-typedef struct xen_hvm_create_ioreq= _server xen_hvm_create_ioreq_server_t;=0A-DEFINE_XEN_GUEST_HANDLE(xen_hvm_c= reate_ioreq_server_t);=0A-=0A-/*=0A- * HVMOP_get_ioreq_server_info: Get = all the information necessary to access=0A- * = IOREQ Server . =0A- *=0A- * The emulator needs to map the synchronous = ioreq structures and buffered=0A- * ioreq ring (if it exists) that Xen = uses to request emulation. These are=0A- * hosted in domain 's = gmfns and =0A- * respectively. In addition, if = the IOREQ Server is handling buffered=0A- * emulation requests, the = emulator needs to bind to event channel=0A- * to listen = for them. (The event channels used for=0A- * synchronous emulation = requests are specified in the per-CPU ioreq=0A- * structures in = ).=0A- * If the IOREQ Server is not handling buffered emulation requests = then the=0A- * values handed back in and = will both be 0.=0A- */=0A-#define HVMOP_get_ioreq_server_info 18=0A-struct = xen_hvm_get_ioreq_server_info {=0A- domid_t domid; /* = IN - domain to be serviced */=0A- ioservid_t id; /* IN = - server id */=0A- evtchn_port_t bufioreq_port; /* OUT - buffered = ioreq port */=0A- uint64_aligned_t ioreq_pfn; /* OUT - sync ioreq = pfn */=0A- uint64_aligned_t bufioreq_pfn; /* OUT - buffered ioreq pfn = */=0A-};=0A-typedef struct xen_hvm_get_ioreq_server_info xen_hvm_get_ioreq_= server_info_t;=0A-DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_ioreq_server_info_t);= =0A-=0A-/*=0A- * HVM_map_io_range_to_ioreq_server: Register an I/O range = of domain =0A- * for emulation by = the client of IOREQ=0A- * Server = =0A- * HVM_unmap_io_range_from_ioreq_server: Deregister an I/O range = of =0A- * for emulation by = the client of IOREQ=0A- * Server = =0A- *=0A- * There are three types of I/O that can be emulated: port = I/O, memory accesses=0A- * and PCI config space accesses. The field = denotes which type of range=0A- * the and (inclusive) fields = are specifying.=0A- * PCI config space ranges are specified by segment/bus/= device/function values=0A- * which should be encoded using the HVMOP_PCI_SB= DF helper macro below.=0A- *=0A- * NOTE: unless an emulation request falls = entirely within a range mapped=0A- * by a secondary emulator, it will not = be passed to that emulator.=0A- */=0A-#define HVMOP_map_io_range_to_ioreq_s= erver 19=0A-#define HVMOP_unmap_io_range_from_ioreq_server 20=0A-struct = xen_hvm_io_range {=0A- domid_t domid; /* IN - domain to = be serviced */=0A- ioservid_t id; /* IN - server id = */=0A- uint32_t type; /* IN - type of range */=0A-# = define HVMOP_IO_RANGE_PORT 0 /* I/O port range */=0A-# define HVMOP_IO_RA= NGE_MEMORY 1 /* MMIO range */=0A-# define HVMOP_IO_RANGE_PCI 2 /* PCI = segment/bus/dev/func range */=0A- uint64_aligned_t start, end; /* IN - = inclusive start and end of range */=0A-};=0A-typedef struct xen_hvm_io_rang= e xen_hvm_io_range_t;=0A-DEFINE_XEN_GUEST_HANDLE(xen_hvm_io_range_t);=0A-= =0A-#define HVMOP_PCI_SBDF(s,b,d,f) \=0A- ((((s) & = 0xffff) << 16) | \=0A- (((b) & 0xff) << 8) | = \=0A- (((d) & 0x1f) << 3) | \=0A- = ((f) & 0x07))=0A-=0A-/*=0A- * HVMOP_destroy_ioreq_server: Destroy the = IOREQ Server servicing domain=0A- * = .=0A- *=0A- * Any registered I/O ranges will be automatically = deregistered.=0A- */=0A-#define HVMOP_destroy_ioreq_server 21=0A-struct = xen_hvm_destroy_ioreq_server {=0A- domid_t domid; /* IN - domain to be = serviced */=0A- ioservid_t id; /* IN - server id */=0A-};=0A-typedef = struct xen_hvm_destroy_ioreq_server xen_hvm_destroy_ioreq_server_t;=0A-DEFI= NE_XEN_GUEST_HANDLE(xen_hvm_destroy_ioreq_server_t);=0A-=0A-/*=0A- * = HVMOP_set_ioreq_server_state: Enable or disable the IOREQ Server = servicing=0A- * domain .=0A- *=0A- * = The IOREQ Server will not be passed any emulation requests until it is in = the=0A- * enabled state.=0A- * Note that the contents of the ioreq_pfn and = bufioreq_fn (see=0A- * HVMOP_get_ioreq_server_info) are not meaningful = until the IOREQ Server is in=0A- * the enabled state.=0A- */=0A-#define = HVMOP_set_ioreq_server_state 22=0A-struct xen_hvm_set_ioreq_server_state = {=0A- domid_t domid; /* IN - domain to be serviced */=0A- = ioservid_t id; /* IN - server id */=0A- uint8_t enabled; /* IN - = enabled? */ =0A-};=0A-typedef struct xen_hvm_set_ioreq_server_state = xen_hvm_set_ioreq_server_state_t;=0A-DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_io= req_server_state_t);=0A-=0A-#endif /* defined(__XEN__) || defined(__XEN_TOO= LS__) */=0A-=0A #if defined(__i386__) || defined(__x86_64__)=0A =0A = /*=0A--- a/xen/include/xsm/dummy.h=0A+++ b/xen/include/xsm/dummy.h=0A@@ = -609,12 +609,6 @@ static XSM_INLINE int xsm_shadow_control=0A return = xsm_default_action(action, current->domain, d);=0A }=0A =0A-static = XSM_INLINE int xsm_hvm_ioreq_server(XSM_DEFAULT_ARG struct domain *d, int = op)=0A-{=0A- XSM_ASSERT_ACTION(XSM_DM_PRIV);=0A- return xsm_default_a= ction(action, current->domain, d);=0A-}=0A-=0A static XSM_INLINE int = xsm_mem_sharing_op(XSM_DEFAULT_ARG struct domain *d, struct domain *cd, = int op)=0A {=0A XSM_ASSERT_ACTION(XSM_DM_PRIV);=0A--- a/xen/include/xsm= /xsm.h=0A+++ b/xen/include/xsm/xsm.h=0A@@ -174,7 +174,6 @@ struct = xsm_operations {=0A int (*do_mca) (void);=0A int (*shadow_control) = (struct domain *d, uint32_t op);=0A int (*hvm_set_pci_link_route) = (struct domain *d);=0A- int (*hvm_ioreq_server) (struct domain *d, int = op);=0A int (*mem_sharing_op) (struct domain *d, struct domain *cd, = int op);=0A int (*apic) (struct domain *d, int cmd);=0A int = (*memtype) (uint32_t access);=0A@@ -648,11 +647,6 @@ static inline int = xsm_hvm_set_pci_link_r=0A return xsm_ops->hvm_set_pci_link_route(d);=0A= }=0A =0A-static inline int xsm_hvm_ioreq_server (xsm_default_t def, = struct domain *d, int op)=0A-{=0A- return xsm_ops->hvm_ioreq_server(d, = op);=0A-}=0A-=0A static inline int xsm_mem_sharing_op (xsm_default_t def, = struct domain *d, struct domain *cd, int op)=0A {=0A return xsm_ops->me= m_sharing_op(d, cd, op);=0A--- a/xen/xsm/dummy.c=0A+++ b/xen/xsm/dummy.c=0A= @@ -145,7 +145,6 @@ void xsm_fixup_ops (struct xsm_operation=0A #ifdef = CONFIG_X86=0A set_to_dummy_if_null(ops, do_mca);=0A set_to_dummy_if= _null(ops, shadow_control);=0A- set_to_dummy_if_null(ops, hvm_ioreq_serv= er);=0A set_to_dummy_if_null(ops, mem_sharing_op);=0A set_to_dummy_= if_null(ops, apic);=0A set_to_dummy_if_null(ops, machine_memory_map);= =0A--- a/xen/xsm/flask/hooks.c=0A+++ b/xen/xsm/flask/hooks.c=0A@@ -1526,11 = +1526,6 @@ static int flask_ioport_mapping(struct d=0A return = flask_ioport_permission(d, start, end, access);=0A }=0A =0A-static int = flask_hvm_ioreq_server(struct domain *d, int op)=0A-{=0A- return = current_has_perm(d, SECCLASS_HVM, HVM__HVMCTL);=0A-}=0A-=0A static int = flask_mem_sharing_op(struct domain *d, struct domain *cd, int op)=0A {=0A = int rc =3D current_has_perm(cd, SECCLASS_HVM, HVM__MEM_SHARING);=0A@@ = -1799,7 +1794,6 @@ static struct xsm_operations flask_ops =3D=0A #ifdef = CONFIG_X86=0A .do_mca =3D flask_do_mca,=0A .shadow_control =3D = flask_shadow_control,=0A- .hvm_ioreq_server =3D flask_hvm_ioreq_server,= =0A .mem_sharing_op =3D flask_mem_sharing_op,=0A .apic =3D = flask_apic,=0A .machine_memory_map =3D flask_machine_memory_map,=0A --=__PartEBDDD65B.3__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --=__PartEBDDD65B.3__=--