Skip to contentSkip to conversation

convert acm hypercall interface to new style

PATCH New Reiner Sailer 1 participant 1 message May 21, 2006 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 convert acm hypercall interface to new style

This patch replaces the union structure parameter of the Access Control Module hypercalls with command-specific request structures. It aligns the ACM hypercalls with the way parameters are passed in the event channel hypercalls.

Advantages include backward-compatibility regarding old guests when new calls are added and clarity of the code.

Regards
Reiner

Signed-off by: Reiner Sailer <[email protected]>

---
 tools/libxc/xc_acm.c                |   31 ++---
 tools/libxc/xenctrl.h               |    2 
 tools/python/xen/lowlevel/acm/acm.c |   44 ++++----
 tools/security/secpol_tool.c        |   32 +++---
 xen/common/acm_ops.c                |  188 +++++++++++++++++-------------------
 xen/include/public/acm_ops.h        |   54 +++++-----
 xen/include/xen/hypercall.h         |    2 
 7 files changed, 169 insertions(+), 184 deletions(-)
tools/libxc/xc_acm.c +11 -20
Index: xen-unstable.hg-shype/tools/libxc/xc_acm.c
===================================================================
@@ -1,14 +1,11 @@
 /******************************************************************************
+ * xc_acm.c
  *
- * Copyright (C) 2005 IBM Corporation
+ * Copyright (C) 2005, 2006 IBM Corporation, R Sailer
  *
  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
- * Authors:
- * Reiner Sailer <[email protected]>
- * Stefan Berger <[email protected]>
- *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation, version 2 of the
@@ -17,29 +14,23 @@
 
 #include "xc_private.h"
 
-int xc_acm_op(int xc_handle, struct acm_op *op)
+
+int xc_acm_op(int xc_handle, int cmd, void *arg, size_t arg_size)
 {
     int ret = -1;
     DECLARE_HYPERCALL;
 
-    op->interface_version = ACM_INTERFACE_VERSION;
-
     hypercall.op = __HYPERVISOR_acm_op;
-    hypercall.arg[0] = (unsigned long) op;
+    hypercall.arg[0] = cmd;
+    hypercall.arg[1] = (unsigned long) arg;
 
-    if (mlock(op, sizeof(*op)) != 0) {
-        PERROR("Could not lock memory for Xen policy hypercall");
-        goto out1;
+    if (mlock(arg, arg_size) != 0) {
+        PERROR("xc_acm_op: arg mlock failed");
+        goto out;
     }
-
     ret = do_xen_hypercall(xc_handle, &hypercall);
-    ret = ioctl(xc_handle, IOCTL_PRIVCMD_HYPERCALL, &hypercall);
-    if (ret < 0) {
-        goto out2;
-    }
- out2:
-    safe_munlock(op, sizeof(*op));
- out1:
+    safe_munlock(arg, arg_size);
+ out:
     return ret;
 }
 
tools/libxc/xenctrl.h +1 -1
Index: xen-unstable.hg-shype/tools/libxc/xenctrl.h
===================================================================
@@ -594,6 +594,6 @@ int xc_add_mmu_update(int xc_handle, xc_
                    unsigned long long ptr, unsigned long long val);
 int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
 
-int xc_acm_op(int xc_handle, struct acm_op *op);
+int xc_acm_op(int xc_handle, int cmd, void *arg, size_t arg_size);
 
 #endif
tools/python/xen/lowlevel/acm/acm.c +21 -23

83 lines not on this page · raw message

tools/security/secpol_tool.c +17 -15
Index: xen-unstable.hg-shype/tools/security/secpol_tool.c
===================================================================
@@ -231,14 +231,16 @@ void acm_dump_policy_buffer(void *buf, i
 uint8_t pull_buffer[PULL_CACHE_SIZE];
 int acm_domain_getpolicy(int xc_handle)
 {
-    struct acm_op op;
+    struct acm_getpolicy getpolicy;
     int ret;
 
     memset(pull_buffer, 0x00, sizeof(pull_buffer));
-    op.cmd = ACM_GETPOLICY;
-    op.u.getpolicy.pullcache = (void *) pull_buffer;
-    op.u.getpolicy.pullcache_size = sizeof(pull_buffer);
-    if ((ret = xc_acm_op(xc_handle, &op)) < 0) {
+    getpolicy.interface_version = ACM_INTERFACE_VERSION;
+    getpolicy.pullcache = (void *) pull_buffer;
+    getpolicy.pullcache_size = sizeof(pull_buffer);
+    ret = xc_acm_op(xc_handle, ACMOP_getpolicy, &getpolicy, sizeof(getpolicy));
+
+    if (ret < 0) {
         printf("ACM operation failed: errno=%d\n", errno);
         if (errno == EACCES)
             fprintf(stderr, "ACM operation failed -- need to"
@@ -275,13 +277,13 @@ int acm_domain_loadpolicy(int xc_handle,
         goto free_out;
     }
     if (len == read(fd, buffer, len)) {
-        struct acm_op op;
+        struct acm_setpolicy setpolicy;
         /* dump it and then push it down into xen/acm */
         acm_dump_policy_buffer(buffer, len);
-        op.cmd = ACM_SETPOLICY;
-        op.u.setpolicy.pushcache = (void *) buffer;
-        op.u.setpolicy.pushcache_size = len;
-        ret = xc_acm_op(xc_handle, &op);
+        setpolicy.interface_version = ACM_INTERFACE_VERSION;
+        setpolicy.pushcache = (void *) buffer;
+        setpolicy.pushcache_size = len;
+        ret = xc_acm_op(xc_handle, ACMOP_setpolicy, &setpolicy, sizeof(setpolicy));
 
         if (ret)
             printf
@@ -322,15 +324,15 @@ void dump_ste_stats(struct acm_ste_stats
 int acm_domain_dumpstats(int xc_handle)
 {
     uint8_t stats_buffer[PULL_STATS_SIZE];
-    struct acm_op op;
+    struct acm_dumpstats dumpstats;
     int ret;
     struct acm_stats_buffer *stats;
 
     memset(stats_buffer, 0x00, sizeof(stats_buffer));
-    op.cmd = ACM_DUMPSTATS;
-    op.u.dumpstats.pullcache = (void *) stats_buffer;
-    op.u.dumpstats.pullcache_size = sizeof(stats_buffer);
-    ret = xc_acm_op(xc_handle, &op);
+    dumpstats.interface_version = ACM_INTERFACE_VERSION;
+    dumpstats.pullcache = (void *) stats_buffer;
+    dumpstats.pullcache_size = sizeof(stats_buffer);
+    ret = xc_acm_op(xc_handle, ACMOP_dumpstats, &dumpstats, sizeof(dumpstats));
 
     if (ret < 0) {
         printf
xen/common/acm_ops.c +90 -98

286 lines not on this page · raw message

xen/include/public/acm_ops.h +28 -26

110 lines not on this page · raw message

xen/include/xen/hypercall.h +1 -1
Index: xen-unstable.hg-shype/xen/include/xen/hypercall.h
===================================================================
@@ -80,7 +80,7 @@ do_vcpu_op(
 
 extern long
 do_acm_op(
-    XEN_GUEST_HANDLE(acm_op_t) u_acm_op);
+    int cmd, XEN_GUEST_HANDLE(void) arg);
 
 extern long
 do_nmi_op(

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel