Re: [Xen-devel] [PATCH v2 04/11] hvmctl: convert HVMOP_set_pci_link_route

2016-07-05 Thread Daniel De Graaf

On 06/24/2016 06:30 AM, Jan Beulich wrote:

Note that this retains the hvmop interface definitions as those had
(wrongly) been exposed to non-tool stack consumers (albeit the
operation wouldn't have succeeded when requested by a domain for
itself).

Signed-off-by: Jan Beulich 
Reviewed-by: Wei Liu 
Reviewed-by: Andrew Cooper 


Acked-by: Daniel De Graaf 

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v2 04/11] hvmctl: convert HVMOP_set_pci_link_route

2016-06-24 Thread Jan Beulich
Note that this retains the hvmop interface definitions as those had
(wrongly) been exposed to non-tool stack consumers (albeit the
operation wouldn't have succeeded when requested by a domain for
itself).

Signed-off-by: Jan Beulich 
Reviewed-by: Wei Liu 
Reviewed-by: Andrew Cooper 

--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -498,27 +498,11 @@ int xc_hvm_set_isa_irq_level(
 int xc_hvm_set_pci_link_route(
 xc_interface *xch, domid_t dom, uint8_t link, uint8_t isa_irq)
 {
-DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_pci_link_route, arg);
-int rc;
+DECLARE_HVMCTL(set_pci_link_route, dom,
+   .link= link,
+   .isa_irq = isa_irq);
 
-arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-if ( arg == NULL )
-{
-PERROR("Could not allocate memory for xc_hvm_set_pci_link_route 
hypercall");
-return -1;
-}
-
-arg->domid   = dom;
-arg->link= link;
-arg->isa_irq = isa_irq;
-
-rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-  HVMOP_set_pci_link_route,
-  HYPERCALL_BUFFER_AS_ARG(arg));
-
-xc_hypercall_buffer_free(xch, arg);
-
-return rc;
+return do_hvmctl(xch, );
 }
 
 int xc_hvm_inject_msi(
--- a/xen/arch/x86/hvm/control.c
+++ b/xen/arch/x86/hvm/control.c
@@ -108,6 +108,11 @@ long do_hvmctl(XEN_GUEST_HANDLE_PARAM(xe
 rc = set_isa_irq_level(d, _isa_irq_level);
 break;
 
+case XEN_HVMCTL_set_pci_link_route:
+rc = hvm_set_pci_link_route(d, op.u.set_pci_link_route.link,
+op.u.set_pci_link_route.isa_irq);
+break;
+
 default:
 rc = -EOPNOTSUPP;
 break;
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -4446,39 +4446,6 @@ static void hvm_s3_resume(struct domain
 }
 }
 
-static int hvmop_set_pci_link_route(
-XEN_GUEST_HANDLE_PARAM(xen_hvm_set_pci_link_route_t) uop)
-{
-struct xen_hvm_set_pci_link_route op;
-struct domain *d;
-int rc;
-
-if ( copy_from_guest(, uop, 1) )
-return -EFAULT;
-
-if ( (op.link > 3) || (op.isa_irq > 15) )
-return -EINVAL;
-
-rc = rcu_lock_remote_domain_by_id(op.domid, );
-if ( rc != 0 )
-return rc;
-
-rc = -EINVAL;
-if ( !is_hvm_domain(d) )
-goto out;
-
-rc = xsm_hvm_set_pci_link_route(XSM_DM_PRIV, d);
-if ( rc )
-goto out;
-
-rc = 0;
-hvm_set_pci_link_route(d, op.link, op.isa_irq);
-
- out:
-rcu_unlock_domain(d);
-return rc;
-}
-
 static int hvmop_inject_msi(
 XEN_GUEST_HANDLE_PARAM(xen_hvm_inject_msi_t) uop)
 {
@@ -5325,11 +5292,6 @@ long do_hvm_op(unsigned long op, XEN_GUE
 guest_handle_cast(arg, xen_hvm_inject_msi_t));
 break;
 
-case HVMOP_set_pci_link_route:
-rc = hvmop_set_pci_link_route(
-guest_handle_cast(arg, xen_hvm_set_pci_link_route_t));
-break;
-
 case HVMOP_flush_tlbs:
 rc = guest_handle_is_null(arg) ? hvmop_flush_tlb_all() : -ENOSYS;
 break;
--- a/xen/arch/x86/hvm/irq.c
+++ b/xen/arch/x86/hvm/irq.c
@@ -229,13 +229,17 @@ void hvm_assert_evtchn_irq(struct vcpu *
 hvm_set_callback_irq_level(v);
 }
 
-void hvm_set_pci_link_route(struct domain *d, u8 link, u8 isa_irq)
+int hvm_set_pci_link_route(struct domain *d, u8 link, u8 isa_irq)
 {
 struct hvm_irq *hvm_irq = >arch.hvm_domain.irq;
 u8 old_isa_irq;
 int i;
 
-ASSERT((link <= 3) && (isa_irq <= 15));
+if ( link > 3 || isa_irq > 15 )
+return -EINVAL;
+
+if ( !is_hvm_domain(d) )
+return -EINVAL;
 
 spin_lock(>arch.hvm_domain.irq_lock);
 
@@ -273,6 +277,8 @@ void hvm_set_pci_link_route(struct domai
 
 dprintk(XENLOG_G_INFO, "Dom%u PCI link %u changed %u -> %u\n",
 d->domain_id, link, old_isa_irq, isa_irq);
+
+return 0;
 }
 
 int hvm_inject_msi(struct domain *d, uint64_t addr, uint32_t data)
--- a/xen/include/public/hvm/control.h
+++ b/xen/include/public/hvm/control.h
@@ -47,16 +47,26 @@ struct xen_hvm_set_isa_irq_level {
 uint8_t  level;
 };
 
+/* XEN_HVMCTL_set_pci_link_route */
+struct xen_hvm_set_pci_link_route {
+/* PCI link identifier (0-3). */
+uint8_t  link;
+/* ISA IRQ (1-15), or 0 (disable link). */
+uint8_t  isa_irq;
+};
+
 struct xen_hvmctl {
 uint16_t interface_version;/* XEN_HVMCTL_INTERFACE_VERSION */
 domid_t domain;
 uint32_t cmd;
 #define XEN_HVMCTL_set_pci_intx_level1
 #define XEN_HVMCTL_set_isa_irq_level 2
+#define XEN_HVMCTL_set_pci_link_route3
 uint64_t opaque;   /* Must be zero on initial invocation. */
 union {
 struct xen_hvm_set_pci_intx_level set_pci_intx_level;
 struct xen_hvm_set_isa_irq_level set_isa_irq_level;
+struct xen_hvm_set_pci_link_route set_pci_link_route;
 uint8_t pad[120];
 } u;
 };
---