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

[Xen-devel] [PATCH 12/22] arch/x86: convert platform_hypercall to use XSM



The newly introduced xsm_platform_op hook addresses new sub-ops, while
most ops already have their own XSM hooks.

Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
Cc: Keir Fraser <keir@xxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/platform_hypercall.c | 11 ++++++++---
 xen/include/xsm/dummy.h           |  7 +++++++
 xen/include/xsm/xsm.h             |  6 ++++++
 xen/xsm/dummy.c                   |  1 +
 xen/xsm/flask/hooks.c             | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/platform_hypercall.c 
b/xen/arch/x86/platform_hypercall.c
index 073a2ea..50b5f1d 100644
--- a/xen/arch/x86/platform_hypercall.c
+++ b/xen/arch/x86/platform_hypercall.c
@@ -66,15 +66,16 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) 
u_xenpf_op)
     ret_t ret = 0;
     struct xen_platform_op curop, *op = &curop;
 
-    if ( !IS_PRIV(current->domain) )
-        return -EPERM;
-
     if ( copy_from_guest(op, u_xenpf_op, 1) )
         return -EFAULT;
 
     if ( op->interface_version != XENPF_INTERFACE_VERSION )
         return -EACCES;
 
+    ret = xsm_platform_op(op->cmd);
+    if ( ret )
+        return ret;
+
     /*
      * Trylock here avoids deadlock with an existing platform critical section
      * which might (for some current or future reason) want to synchronise
@@ -507,6 +508,10 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xen_platform_op_t) 
u_xenpf_op)
     {
         struct xenpf_pcpu_version *ver = &op->u.pcpu_version;
 
+        ret = xsm_getcpuinfo();
+        if ( ret )
+            break;
+
         if ( !get_cpu_maps() )
         {
             ret = -EBUSY;
diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h
index 31f862d..3f0a6d8 100644
--- a/xen/include/xsm/dummy.h
+++ b/xen/include/xsm/dummy.h
@@ -574,6 +574,13 @@ static XSM_DEFAULT(int, platform_quirk) (uint32_t quirk)
     return 0;
 }
 
+static XSM_DEFAULT(int, platform_op) (uint32_t op)
+{
+    if ( !IS_PRIV(current->domain) )
+        return -EPERM;
+    return 0;
+}
+
 static XSM_DEFAULT(int, firmware_info) (void)
 {
     return 0;
diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h
index ba5a89e..171acb2 100644
--- a/xen/include/xsm/xsm.h
+++ b/xen/include/xsm/xsm.h
@@ -158,6 +158,7 @@ struct xsm_operations {
     int (*microcode) (void);
     int (*physinfo) (void);
     int (*platform_quirk) (uint32_t);
+    int (*platform_op) (uint32_t cmd);
     int (*firmware_info) (void);
     int (*efi_call) (void);
     int (*acpi_sleep) (void);
@@ -696,6 +697,11 @@ static inline int xsm_platform_quirk (uint32_t quirk)
     return xsm_ops->platform_quirk(quirk);
 }
 
+static inline int xsm_platform_op (uint32_t op)
+{
+    return xsm_ops->platform_op(op);
+}
+
 static inline int xsm_firmware_info (void)
 {
     return xsm_ops->firmware_info();
diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c
index af532b8..7f9c753 100644
--- a/xen/xsm/dummy.c
+++ b/xen/xsm/dummy.c
@@ -142,6 +142,7 @@ void xsm_fixup_ops (struct xsm_operations *ops)
     set_to_dummy_if_null(ops, microcode);
     set_to_dummy_if_null(ops, physinfo);
     set_to_dummy_if_null(ops, platform_quirk);
+    set_to_dummy_if_null(ops, platform_op);
     set_to_dummy_if_null(ops, firmware_info);
     set_to_dummy_if_null(ops, efi_call);
     set_to_dummy_if_null(ops, acpi_sleep);
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index 10c2163..1cbf2f2 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -1207,6 +1207,38 @@ static int flask_platform_quirk(uint32_t quirk)
                         XEN__QUIRK, NULL);
 }
 
+static int flask_platform_op(uint32_t op)
+{
+    switch ( op )
+    {
+    case XENPF_settime:
+    case XENPF_add_memtype:
+    case XENPF_del_memtype:
+    case XENPF_read_memtype:
+    case XENPF_microcode_update:
+    case XENPF_platform_quirk:
+    case XENPF_firmware_info:
+    case XENPF_efi_runtime_call:
+    case XENPF_enter_acpi_sleep:
+    case XENPF_change_freq:
+    case XENPF_getidletime:
+    case XENPF_set_processor_pminfo:
+    case XENPF_get_cpuinfo:
+    case XENPF_get_cpu_version:
+    case XENPF_cpu_online:
+    case XENPF_cpu_offline:
+    case XENPF_cpu_hotadd:
+    case XENPF_mem_hotadd:
+        /* These operations have their own XSM hooks */
+        return 0;
+    case XENPF_core_parking:
+        return domain_has_xen(current->domain, XEN__PM_OP);
+    default:
+        printk("flask_platform_op: Unknown op %d\n", op);
+        return -EPERM;
+    }
+}
+
 static int flask_firmware_info(void)
 {
     return domain_has_xen(current->domain, XEN__FIRMWARE);
@@ -1577,6 +1609,7 @@ static struct xsm_operations flask_ops = {
     .microcode = flask_microcode,
     .physinfo = flask_physinfo,
     .platform_quirk = flask_platform_quirk,
+    .platform_op = flask_platform_op,
     .firmware_info = flask_firmware_info,
     .efi_call = flask_efi_call,
     .acpi_sleep = flask_acpi_sleep,
-- 
1.7.11.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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