[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] arch/x86: add distinct XSM hooks for map/unmap


  • To: xen-changelog@xxxxxxxxxxxxxxxxxxx
  • From: Xen patchbot-unstable <patchbot@xxxxxxx>
  • Date: Fri, 11 Jan 2013 03:33:13 +0000
  • Delivery-date: Fri, 11 Jan 2013 03:33:50 +0000
  • List-id: "Change log for Mercurial \(receive only\)" <xen-changelog.lists.xen.org>

# HG changeset patch
# User Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
# Date 1357839130 0
# Node ID 35a0556a7f76c9a6f616cfc9d5a82dccfe36b994
# Parent  68e8cfca220f1d4dfcc1c74c8c117a0567490c14
arch/x86: add distinct XSM hooks for map/unmap

The xsm_iomem_permission and xsm_ioport_permission hooks are intended
to be called by the domain builder, while the calls in
arch/x86/domctl.c which control mapping are also performed by the
device model.  Because these operations require distinct access
control policies, they cannot use the same XSM hooks.

This also adds a missing XSM hook in the unbind IRQ domctl.

Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
Committed-by: Keir Fraser <keir@xxxxxxx>
---


diff -r 68e8cfca220f -r 35a0556a7f76 xen/arch/x86/domctl.c
--- a/xen/arch/x86/domctl.c     Thu Jan 10 17:30:47 2013 +0000
+++ b/xen/arch/x86/domctl.c     Thu Jan 10 17:32:10 2013 +0000
@@ -656,6 +656,10 @@ long arch_do_domctl(
              !irq_access_permitted(current->domain, bind->machine_irq) )
             break;
 
+        ret = xsm_unbind_pt_irq(d, bind);
+        if ( ret )
+            break;
+
         if ( iommu_enabled )
         {
             spin_lock(&pcidevs_lock);
@@ -687,7 +691,7 @@ long arch_do_domctl(
              !iomem_access_permitted(current->domain, mfn, mfn + nr_mfns - 1) )
             break;
 
-        ret = xsm_iomem_permission(d, mfn, mfn + nr_mfns - 1, add);
+        ret = xsm_iomem_mapping(d, mfn, mfn + nr_mfns - 1, add);
         if ( ret )
             break;
 
@@ -765,7 +769,7 @@ long arch_do_domctl(
              !ioports_access_permitted(current->domain, fmp, fmp + np - 1) )
             break;
 
-        ret = xsm_ioport_permission(d, fmp, fmp + np - 1, add);
+        ret = xsm_ioport_mapping(d, fmp, fmp + np - 1, add);
         if ( ret )
             break;
 
diff -r 68e8cfca220f -r 35a0556a7f76 xen/arch/x86/physdev.c
--- a/xen/arch/x86/physdev.c    Thu Jan 10 17:30:47 2013 +0000
+++ b/xen/arch/x86/physdev.c    Thu Jan 10 17:32:10 2013 +0000
@@ -242,7 +242,7 @@ int physdev_unmap_pirq(domid_t domid, in
     if ( !IS_PRIV_FOR(current->domain, d) )
         goto free_domain;
 
-    ret = xsm_irq_permission(d, domain_pirq_to_irq(d, pirq), 0);
+    ret = xsm_unmap_domain_pirq(d, domain_pirq_to_irq(d, pirq));
     if ( ret )
         goto free_domain;
 
diff -r 68e8cfca220f -r 35a0556a7f76 xen/include/xsm/dummy.h
--- a/xen/include/xsm/dummy.h   Thu Jan 10 17:30:47 2013 +0000
+++ b/xen/include/xsm/dummy.h   Thu Jan 10 17:32:10 2013 +0000
@@ -394,6 +394,11 @@ static XSM_INLINE int xsm_map_domain_pir
     return 0;
 }
 
+static XSM_INLINE int xsm_unmap_domain_pirq(struct domain *d, int irq)
+{
+    return 0;
+}
+
 static XSM_INLINE int xsm_irq_permission(struct domain *d, int pirq, uint8_t 
allow)
 {
     return 0;
@@ -404,6 +409,11 @@ static XSM_INLINE int xsm_iomem_permissi
     return 0;
 }
 
+static XSM_INLINE int xsm_iomem_mapping(struct domain *d, uint64_t s, uint64_t 
e, uint8_t allow)
+{
+    return 0;
+}
+
 static XSM_INLINE int xsm_pci_config_permission(struct domain *d, uint32_t 
machine_bdf,
                                         uint16_t start, uint16_t end,
                                         uint8_t access)
@@ -585,7 +595,7 @@ static XSM_INLINE int xsm_bind_pt_irq(st
     return 0;
 }
 
-static XSM_INLINE int xsm_unbind_pt_irq(struct domain *d)
+static XSM_INLINE int xsm_unbind_pt_irq(struct domain *d, struct 
xen_domctl_bind_pt_irq *bind)
 {
     return 0;
 }
@@ -610,4 +620,9 @@ static XSM_INLINE int xsm_ioport_permiss
     return 0;
 }
 
+static XSM_INLINE int xsm_ioport_mapping(struct domain *d, uint32_t s, 
uint32_t e, uint8_t allow)
+{
+    return 0;
+}
+
 #endif
diff -r 68e8cfca220f -r 35a0556a7f76 xen/include/xsm/xsm.h
--- a/xen/include/xsm/xsm.h     Thu Jan 10 17:30:47 2013 +0000
+++ b/xen/include/xsm/xsm.h     Thu Jan 10 17:32:10 2013 +0000
@@ -111,8 +111,10 @@ struct xsm_operations {
 
     char *(*show_irq_sid) (int irq);
     int (*map_domain_pirq) (struct domain *d, int irq, void *data);
+    int (*unmap_domain_pirq) (struct domain *d, int irq);
     int (*irq_permission) (struct domain *d, int pirq, uint8_t allow);
     int (*iomem_permission) (struct domain *d, uint64_t s, uint64_t e, uint8_t 
allow);
+    int (*iomem_mapping) (struct domain *d, uint64_t s, uint64_t e, uint8_t 
allow);
     int (*pci_config_permission) (struct domain *d, uint32_t machine_bdf, 
uint16_t start, uint16_t end, uint8_t access);
 
     int (*get_device_group) (uint32_t machine_bdf);
@@ -170,11 +172,12 @@ struct xsm_operations {
     int (*add_to_physmap) (struct domain *d1, struct domain *d2);
     int (*sendtrigger) (struct domain *d);
     int (*bind_pt_irq) (struct domain *d, struct xen_domctl_bind_pt_irq *bind);
-    int (*unbind_pt_irq) (struct domain *d);
+    int (*unbind_pt_irq) (struct domain *d, struct xen_domctl_bind_pt_irq 
*bind);
     int (*pin_mem_cacheattr) (struct domain *d);
     int (*ext_vcpucontext) (struct domain *d, uint32_t cmd);
     int (*vcpuextstate) (struct domain *d, uint32_t cmd);
     int (*ioport_permission) (struct domain *d, uint32_t s, uint32_t e, 
uint8_t allow);
+    int (*ioport_mapping) (struct domain *d, uint32_t s, uint32_t e, uint8_t 
allow);
 #endif
 };
 
@@ -489,6 +492,11 @@ static inline int xsm_map_domain_pirq (s
     return xsm_ops->map_domain_pirq(d, irq, data);
 }
 
+static inline int xsm_unmap_domain_pirq (struct domain *d, int irq)
+{
+    return xsm_ops->unmap_domain_pirq(d, irq);
+}
+
 static inline int xsm_irq_permission (struct domain *d, int pirq, uint8_t 
allow)
 {
     return xsm_ops->irq_permission(d, pirq, allow);
@@ -499,6 +507,11 @@ static inline int xsm_iomem_permission (
     return xsm_ops->iomem_permission(d, s, e, allow);
 }
 
+static inline int xsm_iomem_mapping (struct domain *d, uint64_t s, uint64_t e, 
uint8_t allow)
+{
+    return xsm_ops->iomem_mapping(d, s, e, allow);
+}
+
 static inline int xsm_pci_config_permission (struct domain *d, uint32_t 
machine_bdf, uint16_t start, uint16_t end, uint8_t access)
 {
     return xsm_ops->pci_config_permission(d, machine_bdf, start, end, access);
@@ -754,9 +767,10 @@ static inline int xsm_bind_pt_irq(struct
     return xsm_ops->bind_pt_irq(d, bind);
 }
 
-static inline int xsm_unbind_pt_irq(struct domain *d)
+static inline int xsm_unbind_pt_irq(struct domain *d,
+                                                struct xen_domctl_bind_pt_irq 
*bind)
 {
-    return xsm_ops->unbind_pt_irq(d);
+    return xsm_ops->unbind_pt_irq(d, bind);
 }
 
 static inline int xsm_pin_mem_cacheattr(struct domain *d)
@@ -777,6 +791,11 @@ static inline int xsm_ioport_permission 
 {
     return xsm_ops->ioport_permission(d, s, e, allow);
 }
+
+static inline int xsm_ioport_mapping (struct domain *d, uint32_t s, uint32_t 
e, uint8_t allow)
+{
+    return xsm_ops->ioport_mapping(d, s, e, allow);
+}
 #endif /* CONFIG_X86 */
 #endif /* XSM_NO_WRAPPERS */
 
diff -r 68e8cfca220f -r 35a0556a7f76 xen/xsm/dummy.c
--- a/xen/xsm/dummy.c   Thu Jan 10 17:30:47 2013 +0000
+++ b/xen/xsm/dummy.c   Thu Jan 10 17:32:10 2013 +0000
@@ -96,8 +96,10 @@ 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, unmap_domain_pirq);
     set_to_dummy_if_null(ops, irq_permission);
     set_to_dummy_if_null(ops, iomem_permission);
+    set_to_dummy_if_null(ops, iomem_mapping);
     set_to_dummy_if_null(ops, pci_config_permission);
 
     set_to_dummy_if_null(ops, get_device_group);
@@ -160,5 +162,6 @@ void xsm_fixup_ops (struct xsm_operation
     set_to_dummy_if_null(ops, ext_vcpucontext);
     set_to_dummy_if_null(ops, vcpuextstate);
     set_to_dummy_if_null(ops, ioport_permission);
+    set_to_dummy_if_null(ops, ioport_mapping);
 #endif
 }
diff -r 68e8cfca220f -r 35a0556a7f76 xen/xsm/flask/hooks.c
--- a/xen/xsm/flask/hooks.c     Thu Jan 10 17:30:47 2013 +0000
+++ b/xen/xsm/flask/hooks.c     Thu Jan 10 17:32:10 2013 +0000
@@ -721,41 +721,39 @@ static int flask_map_domain_pirq (struct
     return rc;
 }
 
-static int flask_irq_permission (struct domain *d, int irq, uint8_t access)
+static int flask_unmap_domain_pirq (struct domain *d, int irq)
 {
-    u32 perm;
-    u32 rsid;
+    u32 sid;
     int rc = -EPERM;
 
-    struct domain_security_struct *ssec, *tsec;
+    struct domain_security_struct *ssec;
     struct avc_audit_data ad;
 
-    rc = domain_has_perm(current->domain, d, SECCLASS_RESOURCE,
-                         resource_to_perm(access));
-
+    rc = domain_has_perm(current->domain, d, SECCLASS_RESOURCE, 
RESOURCE__REMOVE);
     if ( rc )
         return rc;
 
-    if ( access )
-        perm = RESOURCE__ADD_IRQ;
-    else
-        perm = RESOURCE__REMOVE_IRQ;
+    ssec = current->domain->ssid;
 
-    ssec = current->domain->ssid;
-    tsec = d->ssid;
-
-    rc = get_irq_sid(irq, &rsid, &ad);
+    if ( irq < nr_static_irqs ) {
+        rc = get_irq_sid(irq, &sid, &ad);
+    } else {
+        /* It is currently not possible to check the specific MSI IRQ being
+         * removed, since we do not have the msi_info like map_domain_pirq */
+        return 0;
+    }
     if ( rc )
         return rc;
 
-    rc = avc_has_perm(ssec->sid, rsid, SECCLASS_RESOURCE, perm, &ad);
-    if ( rc )
-        return rc;
+    rc = avc_has_perm(ssec->sid, sid, SECCLASS_RESOURCE, RESOURCE__REMOVE_IRQ, 
&ad);
+    return rc;
+}
 
-    if ( access )
-        rc = avc_has_perm(tsec->sid, rsid, SECCLASS_RESOURCE, 
-                            RESOURCE__USE, &ad);
-    return rc;
+static int flask_irq_permission (struct domain *d, int pirq, uint8_t access)
+{
+    /* the PIRQ number is not useful; real IRQ is checked during mapping */
+    return domain_has_perm(current->domain, d, SECCLASS_RESOURCE,
+                           resource_to_perm(access));
 }
 
 struct iomem_has_perm_data {
@@ -1413,7 +1411,7 @@ static int flask_bind_pt_irq (struct dom
     return avc_has_perm(tsec->sid, rsid, SECCLASS_RESOURCE, RESOURCE__USE, 
&ad);
 }
 
-static int flask_unbind_pt_irq (struct domain *d)
+static int flask_unbind_pt_irq (struct domain *d, struct 
xen_domctl_bind_pt_irq *bind)
 {
     return domain_has_perm(current->domain, d, SECCLASS_RESOURCE, 
RESOURCE__REMOVE);
 }
@@ -1533,6 +1531,7 @@ static struct xsm_operations flask_ops =
     .show_irq_sid = flask_show_irq_sid,
 
     .map_domain_pirq = flask_map_domain_pirq,
+    .unmap_domain_pirq = flask_unmap_domain_pirq,
     .irq_permission = flask_irq_permission,
     .iomem_permission = flask_iomem_permission,
     .pci_config_permission = flask_pci_config_permission,

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.