From: "Jan Beulich" Subject: [PATCH v3 10/10] x86/MSI-X: provide hypercall interface for mask-all control Date: Fri, 05 Jun 2015 12:28:18 +0100 Message-ID: <5571A3F202000078000814CA@mail.emea.novell.com> References: <55719F9D0200007800081425@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part093D20C2.2__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z0pnT-00058T-6a for xen-devel@lists.xenproject.org; Fri, 05 Jun 2015 11:28:23 +0000 In-Reply-To: <55719F9D0200007800081425@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Wei Liu , Stefano Stabellini , Andrew Cooper , Ian Jackson , Ian Campbell , Keir Fraser , 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. --=__Part093D20C2.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Qemu shouldn't be fiddling with this bit directly, as the hypervisor may (and now does) use it for its own purposes. Provide it with a replacement interface, allowing the hypervisor to track host and guest masking intentions independently (clearing the bit only when both want it clear). Signed-off-by: Jan Beulich --- Whether the permission check should really be an XSM_TARGET one needs to be determined: That allowing the guest to issue the hypercalls on itself means permitting it to bypass the device model, and thus render device model state stale. --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1807,6 +1807,17 @@ int xc_physdev_unmap_pirq(xc_interface * int domid, int pirq); =20 +int xc_physdev_msix_enable(xc_interface *xch, + int segment, + int bus, + int devfn, + int on); +int xc_physdev_msix_mask_all(xc_interface *xch, + int segment, + int bus, + int devfn, + int mask); + int xc_hvm_set_pci_intx_level( xc_interface *xch, domid_t dom, uint8_t domain, uint8_t bus, uint8_t device, uint8_t intx, --- a/tools/libxc/xc_physdev.c +++ b/tools/libxc/xc_physdev.c @@ -112,3 +112,38 @@ int xc_physdev_unmap_pirq(xc_interface * return rc; } =20 +int xc_physdev_msix_enable(xc_interface *xch, + int segment, + int bus, + int devfn, + int on) +{ + struct physdev_pci_device dev =3D { + .seg =3D segment, + .bus =3D bus, + .devfn =3D devfn + }; + + return do_physdev_op(xch, + on ? PHYSDEVOP_msix_enable + : PHYSDEVOP_msix_disable, + &dev, sizeof(dev)); +} + +int xc_physdev_msix_mask_all(xc_interface *xch, + int segment, + int bus, + int devfn, + int mask) +{ + struct physdev_pci_device dev =3D { + .seg =3D segment, + .bus =3D bus, + .devfn =3D devfn + }; + + return do_physdev_op(xch, + mask ? PHYSDEVOP_msix_mask_all + : PHYSDEVOP_msix_unmask_all, + &dev, sizeof(dev)); +} --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -392,7 +392,7 @@ static bool_t msi_set_mask_bit(struct ir struct pci_dev *pdev; u16 seg, control; u8 bus, slot, func; - bool_t flag =3D host || guest; + bool_t flag =3D host || guest, maskall; =20 ASSERT(spin_is_locked(&desc->lock)); BUG_ON(!entry || !entry->dev); @@ -415,13 +415,17 @@ static bool_t msi_set_mask_bit(struct ir } break; case PCI_CAP_ID_MSIX: + maskall =3D pdev->msix->host_maskall; control =3D pci_conf_read16(seg, bus, slot, func, msix_control_reg(entry->msi_attrib.pos))= ; if ( unlikely(!(control & PCI_MSIX_FLAGS_ENABLE)) ) + { + pdev->msix->host_maskall =3D 1; pci_conf_write16(seg, bus, slot, func, msix_control_reg(entry->msi_attrib.pos), control | (PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL)); + } if ( likely(memory_decoded(pdev)) ) { writel(flag, entry->mask_base + PCI_MSIX_ENTRY_VECTOR_CTRL_OFF= SET); @@ -434,7 +438,7 @@ static bool_t msi_set_mask_bit(struct ir { domid_t domid =3D pdev->domain->domain_id; =20 - control |=3D PCI_MSIX_FLAGS_MASKALL; + maskall =3D 1; if ( pdev->msix->warned !=3D domid ) { pdev->msix->warned =3D domid; @@ -444,6 +448,9 @@ static bool_t msi_set_mask_bit(struct ir PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); } } + pdev->msix->host_maskall =3D maskall; + if ( maskall || pdev->msix->guest_maskall ) + control |=3D PCI_MSIX_FLAGS_MASKALL; pci_conf_write16(seg, bus, slot, func, msix_control_reg(entry->msi_attrib.pos), = control); return flag; @@ -840,6 +847,7 @@ static int msix_capability_init(struct p u8 bus =3D dev->bus; u8 slot =3D PCI_SLOT(dev->devfn); u8 func =3D PCI_FUNC(dev->devfn); + bool_t maskall =3D msix->host_maskall; =20 ASSERT(spin_is_locked(&pcidevs_lock)); =20 @@ -850,6 +858,7 @@ static int msix_capability_init(struct p * to mask all the vectors to prevent interrupts coming in before = they're * fully set up. */ + msix->host_maskall =3D 1; pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos), control | (PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL)); @@ -972,6 +981,10 @@ static int msix_capability_init(struct p =20 if ( !msix->used_entries ) { + maskall =3D 0; + msix->guest_maskall =3D 0; + control &=3D ~PCI_MSIX_FLAGS_MASKALL; + if ( rangeset_add_range(mmio_ro_ranges, msix->table.first, msix->table.last) ) WARN(); @@ -1002,6 +1015,7 @@ static int msix_capability_init(struct p ++msix->used_entries; =20 /* Restore MSI-X enabled bits */ + msix->host_maskall =3D maskall; pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos), = control); =20 return 0; @@ -1142,11 +1156,15 @@ static void __pci_disable_msix(struct ms PCI_CAP_ID_MSIX); u16 control =3D pci_conf_read16(seg, bus, slot, func, msix_control_reg(entry->msi_attrib.pos))= ; + bool_t maskall =3D dev->msix->host_maskall; =20 if ( unlikely(!(control & PCI_MSIX_FLAGS_ENABLE)) ) + { + dev->msix->host_maskall =3D 1; pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos), control | (PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL)); + } =20 BUG_ON(list_empty(&dev->msi_list)); =20 @@ -1158,8 +1176,11 @@ static void __pci_disable_msix(struct ms "cannot disable IRQ %d: masking MSI-X on %04x:%02x:%02x.%u\= n", entry->irq, dev->seg, dev->bus, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); - control |=3D PCI_MSIX_FLAGS_MASKALL; + maskall =3D 1; } + dev->msix->host_maskall =3D maskall; + if ( maskall || dev->msix->guest_maskall ) + control |=3D PCI_MSIX_FLAGS_MASKALL; pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos), = control); =20 _pci_cleanup_msix(dev->msix); @@ -1203,6 +1224,62 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 return rc; } =20 +int pci_msix_enable(u16 seg, u8 bus, u8 devfn, bool_t on) +{ + int rc; + struct pci_dev *pdev; + + if ( !use_msi ) + return -EOPNOTSUPP; + + spin_lock(&pcidevs_lock); + pdev =3D pci_get_pdev(seg, bus, devfn); + if ( !pdev || !pdev->msix || !pdev->domain ) + rc =3D -ENODEV; + else if ( !is_hvm_domain(pdev->domain) ) + rc =3D -ENXIO; + else if ( (rc =3D xsm_manage_domain_pirq(XSM_TARGET, pdev->domain)) = =3D=3D 0 ) + msix_set_enable(pdev, on); + spin_unlock(&pcidevs_lock); + + return rc; +} + +int pci_msix_maskall(u16 seg, u8 bus, u8 devfn, bool_t mask) +{ + int rc; + struct pci_dev *pdev; + u8 slot =3D PCI_SLOT(devfn), func =3D PCI_FUNC(devfn); + + if ( !use_msi ) + return -EOPNOTSUPP; + + spin_lock(&pcidevs_lock); + pdev =3D pci_get_pdev(seg, bus, devfn); + if ( !pdev || !pdev->msix || !pdev->domain ) + rc =3D -ENODEV; + else if ( !is_hvm_domain(pdev->domain) ) + rc =3D -ENXIO; + else if ( (rc =3D xsm_manage_domain_pirq(XSM_TARGET, pdev->domain)) = =3D=3D 0 ) + { + unsigned int pos =3D pci_find_cap_offset(seg, bus, slot, func, + PCI_CAP_ID_MSIX); + u16 control =3D pci_conf_read16(seg, bus, slot, func, + msix_control_reg(pos)); + + BUG_ON(!pos); + pdev->msix->guest_maskall =3D mask; + if ( pdev->msix->host_maskall || mask ) + control |=3D PCI_MSIX_FLAGS_MASKALL; + else + control &=3D ~PCI_MSIX_FLAGS_MASKALL; + pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos), = control); + } + spin_unlock(&pcidevs_lock); + + return rc; +} + /* * Notice: only construct the msi_desc * no change to irq_desc here, and the interrupt is masked --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -665,6 +665,30 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H break; } =20 + case PHYSDEVOP_msix_enable: + case PHYSDEVOP_msix_disable: { + struct physdev_pci_device dev; + + if ( copy_from_guest(&dev, arg, 1) ) + ret =3D -EFAULT; + else + ret =3D pci_msix_enable(dev.seg, dev.bus, dev.devfn, + cmd =3D=3D PHYSDEVOP_msix_enable); + break; + } + + case PHYSDEVOP_msix_mask_all: + case PHYSDEVOP_msix_unmask_all: { + struct physdev_pci_device dev; + + if ( copy_from_guest(&dev, arg, 1) ) + ret =3D -EFAULT; + else + ret =3D pci_msix_maskall(dev.seg, dev.bus, dev.devfn, + cmd =3D=3D PHYSDEVOP_msix_mask_all); + break; + } + case PHYSDEVOP_pci_mmcfg_reserved: { struct physdev_pci_mmcfg_reserved info; =20 --- a/xen/include/asm-x86/msi.h +++ b/xen/include/asm-x86/msi.h @@ -83,6 +83,8 @@ struct msi_desc; extern int pci_enable_msi(struct msi_info *msi, struct msi_desc **desc); extern void pci_disable_msi(struct msi_desc *desc); extern int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool_t off); +extern int pci_msix_enable(u16 seg, u8 bus, u8 devfn, bool_t on); +extern int pci_msix_maskall(u16 seg, u8 bus, u8 devfn, bool_t mask); extern void pci_cleanup_msi(struct pci_dev *pdev); extern int setup_msi_irq(struct irq_desc *, struct msi_desc *); extern int __setup_msi_irq(struct irq_desc *, struct msi_desc *, @@ -233,6 +235,7 @@ struct arch_msix { int table_refcnt[MAX_MSIX_TABLE_PAGES]; int table_idx[MAX_MSIX_TABLE_PAGES]; spinlock_t table_lock; + bool_t host_maskall, guest_maskall; domid_t warned; }; =20 --- a/xen/include/public/physdev.h +++ b/xen/include/public/physdev.h @@ -315,6 +315,14 @@ DEFINE_XEN_GUEST_HANDLE(physdev_pci_devi */ #define PHYSDEVOP_prepare_msix 30 #define PHYSDEVOP_release_msix 31 +/* + * The device model domain for a guest should be using these instead of + * fiddling with the respective flags in the MSI-X capability structure. + */ +#define PHYSDEVOP_msix_enable 32 +#define PHYSDEVOP_msix_disable 33 +#define PHYSDEVOP_msix_mask_all 34 +#define PHYSDEVOP_msix_unmask_all 35 struct physdev_pci_device { /* IN */ uint16_t seg; --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -462,6 +462,12 @@ static XSM_INLINE int xsm_map_domain_irq return xsm_default_action(action, current->domain, d); } =20 +static XSM_INLINE int xsm_manage_domain_pirq(XSM_DEFAULT_ARG struct = domain *d) +{ + XSM_ASSERT_ACTION(XSM_TARGET); + return xsm_default_action(action, current->domain, d); +} + static XSM_INLINE int xsm_unmap_domain_pirq(XSM_DEFAULT_ARG struct domain = *d) { XSM_ASSERT_ACTION(XSM_TARGET); --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -105,6 +105,7 @@ struct xsm_operations { char *(*show_irq_sid) (int irq); int (*map_domain_pirq) (struct domain *d); int (*map_domain_irq) (struct domain *d, int irq, void *data); + int (*manage_domain_pirq) (struct domain *d); int (*unmap_domain_pirq) (struct domain *d); int (*unmap_domain_irq) (struct domain *d, int irq, void *data); int (*bind_pt_irq) (struct domain *d, struct xen_domctl_bind_pt_irq = *bind); @@ -424,6 +425,11 @@ static inline int xsm_map_domain_irq (xs return xsm_ops->map_domain_irq(d, irq, data); } =20 +static inline int xsm_manage_domain_pirq(xsm_default_t def, struct domain = *d) +{ + return xsm_ops->manage_domain_pirq(d); +} + static inline int xsm_unmap_domain_pirq (xsm_default_t def, struct domain = *d) { return xsm_ops->unmap_domain_pirq(d); --- a/xen/xsm/dummy.c +++ b/xen/xsm/dummy.c @@ -79,6 +79,7 @@ void xsm_fixup_ops (struct xsm_operation set_to_dummy_if_null(ops, show_irq_sid); set_to_dummy_if_null(ops, map_domain_pirq); set_to_dummy_if_null(ops, map_domain_irq); + set_to_dummy_if_null(ops, manage_domain_pirq); set_to_dummy_if_null(ops, unmap_domain_pirq); set_to_dummy_if_null(ops, unmap_domain_irq); set_to_dummy_if_null(ops, bind_pt_irq); --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -881,6 +881,11 @@ static int flask_map_domain_irq (struct=20 return rc; } =20 +static int flask_manage_domain_pirq(struct domain *d) +{ + return current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__USE); +} + static int flask_unmap_domain_pirq (struct domain *d) { return current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__REMOVE); @@ -1633,6 +1638,7 @@ static struct xsm_operations flask_ops =3D =20 .map_domain_pirq =3D flask_map_domain_pirq, .map_domain_irq =3D flask_map_domain_irq, + .manage_domain_pirq =3D flask_manage_domain_pirq, .unmap_domain_pirq =3D flask_unmap_domain_pirq, .unmap_domain_irq =3D flask_unmap_domain_irq, .bind_pt_irq =3D flask_bind_pt_irq, --=__Part093D20C2.2__= Content-Type: text/plain; name="x86-MSI-X-maskall.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-MSI-X-maskall.patch" x86/MSI-X: provide hypercall interface for mask-all control=0A=0AQemu = shouldn't be fiddling with this bit directly, as the hypervisor=0Amay (and = now does) use it for its own purposes. Provide it with a=0Areplacement = interface, allowing the hypervisor to track host and guest=0Amasking = intentions independently (clearing the bit only when both want=0Ait = clear).=0A=0ASigned-off-by: Jan Beulich =0A---=0AWhether= the permission check should really be an XSM_TARGET one needs=0Ato be = determined: That allowing the guest to issue the hypercalls on=0Aitself = means permitting it to bypass the device model, and thus render=0Adevice = model state stale.=0A=0A--- a/tools/libxc/include/xenctrl.h=0A+++ = b/tools/libxc/include/xenctrl.h=0A@@ -1807,6 +1807,17 @@ int xc_physdev_unm= ap_pirq(xc_interface *=0A int domid,=0A = int pirq);=0A =0A+int xc_physdev_msix_enable(xc_interface = *xch,=0A+ int segment,=0A+ = int bus,=0A+ int devfn,=0A+ = int on);=0A+int xc_physdev_msix_mask_all(xc_interface *xch,=0A+ = int segment,=0A+ int = bus,=0A+ int devfn,=0A+ = int mask);=0A+=0A int xc_hvm_set_pci_intx_level(=0A xc_interface = *xch, domid_t dom,=0A uint8_t domain, uint8_t bus, uint8_t device, = uint8_t intx,=0A--- a/tools/libxc/xc_physdev.c=0A+++ b/tools/libxc/xc_physd= ev.c=0A@@ -112,3 +112,38 @@ int xc_physdev_unmap_pirq(xc_interface *=0A = return rc;=0A }=0A =0A+int xc_physdev_msix_enable(xc_interface *xch,=0A+ = int segment,=0A+ int = bus,=0A+ int devfn,=0A+ = int on)=0A+{=0A+ struct physdev_pci_device dev =3D {=0A+ .seg = =3D segment,=0A+ .bus =3D bus,=0A+ .devfn =3D devfn=0A+ = };=0A+=0A+ return do_physdev_op(xch,=0A+ on ? = PHYSDEVOP_msix_enable=0A+ : PHYSDEVOP_msix_disab= le,=0A+ &dev, sizeof(dev));=0A+}=0A+=0A+int = xc_physdev_msix_mask_all(xc_interface *xch,=0A+ = int segment,=0A+ int bus,=0A+ = int devfn,=0A+ int mask)=0A+{=0A+ = struct physdev_pci_device dev =3D {=0A+ .seg =3D segment,=0A+ = .bus =3D bus,=0A+ .devfn =3D devfn=0A+ };=0A+=0A+ return = do_physdev_op(xch,=0A+ mask ? PHYSDEVOP_msix_mask_a= ll=0A+ : PHYSDEVOP_msix_unmask_all,=0A+ = &dev, sizeof(dev));=0A+}=0A--- a/xen/arch/x86/msi.c=0A+++= b/xen/arch/x86/msi.c=0A@@ -392,7 +392,7 @@ static bool_t msi_set_mask_bit(= struct ir=0A struct pci_dev *pdev;=0A u16 seg, control;=0A u8 = bus, slot, func;=0A- bool_t flag =3D host || guest;=0A+ bool_t flag = =3D host || guest, maskall;=0A =0A ASSERT(spin_is_locked(&desc->lock));= =0A BUG_ON(!entry || !entry->dev);=0A@@ -415,13 +415,17 @@ static = bool_t msi_set_mask_bit(struct ir=0A }=0A break;=0A = case PCI_CAP_ID_MSIX:=0A+ maskall =3D pdev->msix->host_maskall;=0A = control =3D pci_conf_read16(seg, bus, slot, func,=0A = msix_control_reg(entry->msi_attrib.pos));=0A if = ( unlikely(!(control & PCI_MSIX_FLAGS_ENABLE)) )=0A+ {=0A+ = pdev->msix->host_maskall =3D 1;=0A pci_conf_write16(seg, = bus, slot, func,=0A msix_control_reg(entry->ms= i_attrib.pos),=0A control | (PCI_MSIX_FLAGS_EN= ABLE |=0A PCI_MSIX_FLAGS_MASKALL));= =0A+ }=0A if ( likely(memory_decoded(pdev)) )=0A = {=0A writel(flag, entry->mask_base + PCI_MSIX_ENTRY_VECTOR_CTRL= _OFFSET);=0A@@ -434,7 +438,7 @@ static bool_t msi_set_mask_bit(struct = ir=0A {=0A domid_t domid =3D pdev->domain->domain_id;= =0A =0A- control |=3D PCI_MSIX_FLAGS_MASKALL;=0A+ = maskall =3D 1;=0A if ( pdev->msix->warned !=3D domid )=0A = {=0A pdev->msix->warned =3D domid;=0A@@ -444,6 = +448,9 @@ static bool_t msi_set_mask_bit(struct ir=0A = PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));=0A }=0A = }=0A+ pdev->msix->host_maskall =3D maskall;=0A+ if ( = maskall || pdev->msix->guest_maskall )=0A+ control |=3D = PCI_MSIX_FLAGS_MASKALL;=0A pci_conf_write16(seg, bus, slot, = func,=0A msix_control_reg(entry->msi_attrib.pos), = control);=0A return flag;=0A@@ -840,6 +847,7 @@ static int = msix_capability_init(struct p=0A u8 bus =3D dev->bus;=0A u8 slot = =3D PCI_SLOT(dev->devfn);=0A u8 func =3D PCI_FUNC(dev->devfn);=0A+ = bool_t maskall =3D msix->host_maskall;=0A =0A ASSERT(spin_is_locked(&pc= idevs_lock));=0A =0A@@ -850,6 +858,7 @@ static int msix_capability_init(str= uct p=0A * to mask all the vectors to prevent interrupts coming in = before they're=0A * fully set up.=0A */=0A+ msix->host_maskall= =3D 1;=0A pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos)= ,=0A control | (PCI_MSIX_FLAGS_ENABLE |=0A = PCI_MSIX_FLAGS_MASKALL));=0A@@ -972,6 +981,10 @@ = static int msix_capability_init(struct p=0A =0A if ( !msix->used_entrie= s )=0A {=0A+ maskall =3D 0;=0A+ msix->guest_maskall =3D = 0;=0A+ control &=3D ~PCI_MSIX_FLAGS_MASKALL;=0A+=0A if ( = rangeset_add_range(mmio_ro_ranges, msix->table.first,=0A = msix->table.last) )=0A WARN();=0A@@ -1002,6 = +1015,7 @@ static int msix_capability_init(struct p=0A ++msix->used_ent= ries;=0A =0A /* Restore MSI-X enabled bits */=0A+ msix->host_maskall= =3D maskall;=0A pci_conf_write16(seg, bus, slot, func, msix_control_re= g(pos), control);=0A =0A return 0;=0A@@ -1142,11 +1156,15 @@ static = void __pci_disable_msix(struct ms=0A = PCI_CAP_ID_MSIX);=0A u16 control =3D pci_conf_read16(seg, bus, = slot, func,=0A msix_control_reg(entry->ms= i_attrib.pos));=0A+ bool_t maskall =3D dev->msix->host_maskall;=0A =0A = if ( unlikely(!(control & PCI_MSIX_FLAGS_ENABLE)) )=0A+ {=0A+ = dev->msix->host_maskall =3D 1;=0A pci_conf_write16(seg, bus, slot, = func, msix_control_reg(pos),=0A control | = (PCI_MSIX_FLAGS_ENABLE |=0A PCI_MSIX_FL= AGS_MASKALL));=0A+ }=0A =0A BUG_ON(list_empty(&dev->msi_list));=0A = =0A@@ -1158,8 +1176,11 @@ static void __pci_disable_msix(struct ms=0A = "cannot disable IRQ %d: masking MSI-X on %04x:%02x:%02x.%u\n",=0A= entry->irq, dev->seg, dev->bus,=0A = PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));=0A- control |=3D = PCI_MSIX_FLAGS_MASKALL;=0A+ maskall =3D 1;=0A }=0A+ = dev->msix->host_maskall =3D maskall;=0A+ if ( maskall || dev->msix->gues= t_maskall )=0A+ control |=3D PCI_MSIX_FLAGS_MASKALL;=0A = pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos), control);=0A = =0A _pci_cleanup_msix(dev->msix);=0A@@ -1203,6 +1224,62 @@ int = pci_prepare_msix(u16 seg, u8 bus, u8=0A return rc;=0A }=0A =0A+int = pci_msix_enable(u16 seg, u8 bus, u8 devfn, bool_t on)=0A+{=0A+ int = rc;=0A+ struct pci_dev *pdev;=0A+=0A+ if ( !use_msi )=0A+ = return -EOPNOTSUPP;=0A+=0A+ spin_lock(&pcidevs_lock);=0A+ pdev =3D = pci_get_pdev(seg, bus, devfn);=0A+ if ( !pdev || !pdev->msix || = !pdev->domain )=0A+ rc =3D -ENODEV;=0A+ else if ( !is_hvm_domain(= pdev->domain) )=0A+ rc =3D -ENXIO;=0A+ else if ( (rc =3D = xsm_manage_domain_pirq(XSM_TARGET, pdev->domain)) =3D=3D 0 )=0A+ = msix_set_enable(pdev, on);=0A+ spin_unlock(&pcidevs_lock);=0A+=0A+ = return rc;=0A+}=0A+=0A+int pci_msix_maskall(u16 seg, u8 bus, u8 devfn, = bool_t mask)=0A+{=0A+ int rc;=0A+ struct pci_dev *pdev;=0A+ u8 = slot =3D PCI_SLOT(devfn), func =3D PCI_FUNC(devfn);=0A+=0A+ if ( = !use_msi )=0A+ return -EOPNOTSUPP;=0A+=0A+ spin_lock(&pcidevs_loc= k);=0A+ pdev =3D pci_get_pdev(seg, bus, devfn);=0A+ if ( !pdev || = !pdev->msix || !pdev->domain )=0A+ rc =3D -ENODEV;=0A+ else if ( = !is_hvm_domain(pdev->domain) )=0A+ rc =3D -ENXIO;=0A+ else if ( = (rc =3D xsm_manage_domain_pirq(XSM_TARGET, pdev->domain)) =3D=3D 0 )=0A+ = {=0A+ unsigned int pos =3D pci_find_cap_offset(seg, bus, slot, = func,=0A+ PCI_CAP_ID_MSIX);= =0A+ u16 control =3D pci_conf_read16(seg, bus, slot, func,=0A+ = msix_control_reg(pos));=0A+=0A+ = BUG_ON(!pos);=0A+ pdev->msix->guest_maskall =3D mask;=0A+ if = ( pdev->msix->host_maskall || mask )=0A+ control |=3D PCI_MSIX_F= LAGS_MASKALL;=0A+ else=0A+ control &=3D ~PCI_MSIX_FLAGS_M= ASKALL;=0A+ pci_conf_write16(seg, bus, slot, func, msix_control_reg(= pos), control);=0A+ }=0A+ spin_unlock(&pcidevs_lock);=0A+=0A+ = return rc;=0A+}=0A+=0A /*=0A * Notice: only construct the msi_desc=0A * = no change to irq_desc here, and the interrupt is masked=0A--- a/xen/arch/x8= 6/physdev.c=0A+++ b/xen/arch/x86/physdev.c=0A@@ -665,6 +665,30 @@ ret_t = do_physdev_op(int cmd, XEN_GUEST_H=0A break;=0A }=0A =0A+ = case PHYSDEVOP_msix_enable:=0A+ case PHYSDEVOP_msix_disable: {=0A+ = struct physdev_pci_device dev;=0A+=0A+ if ( copy_from_guest(&dev, = arg, 1) )=0A+ ret =3D -EFAULT;=0A+ else=0A+ = ret =3D pci_msix_enable(dev.seg, dev.bus, dev.devfn,=0A+ = cmd =3D=3D PHYSDEVOP_msix_enable);=0A+ break;=0A+ = }=0A+=0A+ case PHYSDEVOP_msix_mask_all:=0A+ case PHYSDEVOP_msix_unmas= k_all: {=0A+ struct physdev_pci_device dev;=0A+=0A+ if ( = copy_from_guest(&dev, arg, 1) )=0A+ ret =3D -EFAULT;=0A+ = else=0A+ ret =3D pci_msix_maskall(dev.seg, dev.bus, dev.devfn,= =0A+ cmd =3D=3D PHYSDEVOP_msix_mask_all);= =0A+ break;=0A+ }=0A+=0A case PHYSDEVOP_pci_mmcfg_reserved: = {=0A struct physdev_pci_mmcfg_reserved info;=0A =0A--- a/xen/includ= e/asm-x86/msi.h=0A+++ b/xen/include/asm-x86/msi.h=0A@@ -83,6 +83,8 @@ = struct msi_desc;=0A extern int pci_enable_msi(struct msi_info *msi, struct = msi_desc **desc);=0A extern void pci_disable_msi(struct msi_desc *desc);=0A= extern int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool_t off);=0A+ext= ern int pci_msix_enable(u16 seg, u8 bus, u8 devfn, bool_t on);=0A+extern = int pci_msix_maskall(u16 seg, u8 bus, u8 devfn, bool_t mask);=0A extern = void pci_cleanup_msi(struct pci_dev *pdev);=0A extern int setup_msi_irq(str= uct irq_desc *, struct msi_desc *);=0A extern int __setup_msi_irq(struct = irq_desc *, struct msi_desc *,=0A@@ -233,6 +235,7 @@ struct arch_msix {=0A = int table_refcnt[MAX_MSIX_TABLE_PAGES];=0A int table_idx[MAX_MSIX_T= ABLE_PAGES];=0A spinlock_t table_lock;=0A+ bool_t host_maskall, = guest_maskall;=0A domid_t warned;=0A };=0A =0A--- a/xen/include/public/= physdev.h=0A+++ b/xen/include/public/physdev.h=0A@@ -315,6 +315,14 @@ = DEFINE_XEN_GUEST_HANDLE(physdev_pci_devi=0A */=0A #define PHYSDEVOP_prepar= e_msix 30=0A #define PHYSDEVOP_release_msix 31=0A+/*=0A+ = * The device model domain for a guest should be using these instead of=0A+ = * fiddling with the respective flags in the MSI-X capability structure.=0A+= */=0A+#define PHYSDEVOP_msix_enable 32=0A+#define PHYSDEVOP_msix= _disable 33=0A+#define PHYSDEVOP_msix_mask_all 34=0A+#defi= ne PHYSDEVOP_msix_unmask_all 35=0A struct physdev_pci_device {=0A = /* IN */=0A uint16_t seg;=0A--- a/xen/include/xsm/dummy.h=0A+++ = b/xen/include/xsm/dummy.h=0A@@ -462,6 +462,12 @@ static XSM_INLINE int = xsm_map_domain_irq=0A return xsm_default_action(action, current->domain= , d);=0A }=0A =0A+static XSM_INLINE int xsm_manage_domain_pirq(XSM_DEFAULT_= ARG struct domain *d)=0A+{=0A+ XSM_ASSERT_ACTION(XSM_TARGET);=0A+ = return xsm_default_action(action, current->domain, d);=0A+}=0A+=0A static = XSM_INLINE int xsm_unmap_domain_pirq(XSM_DEFAULT_ARG struct domain *d)=0A = {=0A XSM_ASSERT_ACTION(XSM_TARGET);=0A--- a/xen/include/xsm/xsm.h=0A+++= b/xen/include/xsm/xsm.h=0A@@ -105,6 +105,7 @@ struct xsm_operations {=0A = char *(*show_irq_sid) (int irq);=0A int (*map_domain_pirq) (struct = domain *d);=0A int (*map_domain_irq) (struct domain *d, int irq, void = *data);=0A+ int (*manage_domain_pirq) (struct domain *d);=0A int = (*unmap_domain_pirq) (struct domain *d);=0A int (*unmap_domain_irq) = (struct domain *d, int irq, void *data);=0A int (*bind_pt_irq) (struct = domain *d, struct xen_domctl_bind_pt_irq *bind);=0A@@ -424,6 +425,11 @@ = static inline int xsm_map_domain_irq (xs=0A return xsm_ops->map_domain_= irq(d, irq, data);=0A }=0A =0A+static inline int xsm_manage_domain_pirq(xsm= _default_t def, struct domain *d)=0A+{=0A+ return xsm_ops->manage_domain= _pirq(d);=0A+}=0A+=0A static inline int xsm_unmap_domain_pirq (xsm_default_= t def, struct domain *d)=0A {=0A return xsm_ops->unmap_domain_pirq(d);= =0A--- a/xen/xsm/dummy.c=0A+++ b/xen/xsm/dummy.c=0A@@ -79,6 +79,7 @@ void = xsm_fixup_ops (struct xsm_operation=0A set_to_dummy_if_null(ops, = show_irq_sid);=0A set_to_dummy_if_null(ops, map_domain_pirq);=0A = set_to_dummy_if_null(ops, map_domain_irq);=0A+ set_to_dummy_if_null(ops,= manage_domain_pirq);=0A set_to_dummy_if_null(ops, unmap_domain_pirq);= =0A set_to_dummy_if_null(ops, unmap_domain_irq);=0A set_to_dummy_if= _null(ops, bind_pt_irq);=0A--- a/xen/xsm/flask/hooks.c=0A+++ b/xen/xsm/flas= k/hooks.c=0A@@ -881,6 +881,11 @@ static int flask_map_domain_irq (struct = =0A return rc;=0A }=0A =0A+static int flask_manage_domain_pirq(struct = domain *d)=0A+{=0A+ return current_has_perm(d, SECCLASS_RESOURCE, = RESOURCE__USE);=0A+}=0A+=0A static int flask_unmap_domain_pirq (struct = domain *d)=0A {=0A return current_has_perm(d, SECCLASS_RESOURCE, = RESOURCE__REMOVE);=0A@@ -1633,6 +1638,7 @@ static struct xsm_operations = flask_ops =3D=0A =0A .map_domain_pirq =3D flask_map_domain_pirq,=0A = .map_domain_irq =3D flask_map_domain_irq,=0A+ .manage_domain_pirq =3D = flask_manage_domain_pirq,=0A .unmap_domain_pirq =3D flask_unmap_domain_= pirq,=0A .unmap_domain_irq =3D flask_unmap_domain_irq,=0A = .bind_pt_irq =3D flask_bind_pt_irq,=0A --=__Part093D20C2.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part093D20C2.2__=--