aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2006-05-02 15:12:06 +0100
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>2006-05-02 15:12:06 +0100
commit2d0922d5159b9855c1420f418318081d607c0df1 (patch)
tree6d84b52be10d50fe6a5d4fd3be7789a8f9f6041a
parent6a4be408e4f7be50ce912570883e6d6e9eb2cf53 (diff)
downloadxen-2d0922d5159b9855c1420f418318081d607c0df1.tar.gz
xen-2d0922d5159b9855c1420f418318081d607c0df1.tar.bz2
xen-2d0922d5159b9855c1420f418318081d607c0df1.zip
Move Linux-specific privcmd code into private libxc implementations.
Make header path for kernel's privcmd/evtchn headers generic. Remove pointless xi_*() interface that was using private libxc interfaces. Signed-off-by: John Levon <john.levon@sun.com>
-rw-r--r--tools/Rules.mk20
-rw-r--r--tools/debugger/pdb/pdb_caml_process.c1
-rw-r--r--tools/debugger/pdb/pdb_caml_xcs.c1
-rw-r--r--tools/libxc/Makefile5
-rw-r--r--tools/libxc/xc_acm.c54
-rw-r--r--tools/libxc/xc_linux.c114
-rw-r--r--tools/libxc/xc_linux_save.c11
-rw-r--r--tools/libxc/xc_misc.c13
-rw-r--r--tools/libxc/xc_private.c57
-rw-r--r--tools/libxc/xc_private.h37
-rw-r--r--tools/libxc/xc_tbuf.c46
-rw-r--r--tools/libxc/xenctrl.h15
-rw-r--r--tools/libxc/xg_private.h2
-rw-r--r--tools/python/xen/lowlevel/acm/acm.c55
-rw-r--r--tools/security/secpol_tool.c73
-rw-r--r--tools/xenmon/xenbaked.c3
-rw-r--r--tools/xenstat/libxenstat/Makefile14
-rw-r--r--tools/xenstat/libxenstat/src/xenstat.c35
-rw-r--r--tools/xentrace/xentrace.c75
19 files changed, 354 insertions, 277 deletions
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 8101c0c24a..0b83f77b2d 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -23,15 +23,23 @@ CFLAGS += -D__XEN_TOOLS__
%.o: %.cc
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
-.PHONY: mk-symlinks
-mk-symlinks: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse
-mk-symlinks:
+OS = $(shell uname -s)
+
+.PHONY: mk-symlinks mk-symlinks-xen mk-symlinks-$(OS)
+
+mk-symlinks-Linux: LINUX_ROOT=$(XEN_ROOT)/linux-2.6-xen-sparse
+mk-symlinks-Linux:
+ mkdir -p xen/linux
+ ( cd xen/linux && \
+ ln -sf ../../$(LINUX_ROOT)/include/xen/public/*.h . )
+ ( cd xen && rm -f sys && ln -sf linux sys )
+
+mk-symlinks-xen:
mkdir -p xen
( cd xen && ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
mkdir -p xen/hvm
( cd xen/hvm && ln -sf ../../$(XEN_ROOT)/xen/include/public/hvm/*.h . )
mkdir -p xen/io
( cd xen/io && ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
- mkdir -p xen/linux
- ( cd xen/linux && \
- ln -sf ../../$(LINUX_ROOT)/include/xen/public/*.h . )
+
+mk-symlinks: mk-symlinks-xen mk-symlinks-$(OS)
diff --git a/tools/debugger/pdb/pdb_caml_process.c b/tools/debugger/pdb/pdb_caml_process.c
index f332e1653e..3d39b846a7 100644
--- a/tools/debugger/pdb/pdb_caml_process.c
+++ b/tools/debugger/pdb/pdb_caml_process.c
@@ -18,7 +18,6 @@
#include <xenctrl.h>
#include <xen/xen.h>
#include <xen/io/domain_controller.h>
-#include <xen/linux/privcmd.h>
#include "pdb_module.h"
#include "pdb_caml_xen.h"
diff --git a/tools/debugger/pdb/pdb_caml_xcs.c b/tools/debugger/pdb/pdb_caml_xcs.c
index 974cf83925..d4ce1cdb4e 100644
--- a/tools/debugger/pdb/pdb_caml_xcs.c
+++ b/tools/debugger/pdb/pdb_caml_xcs.c
@@ -21,7 +21,6 @@
#include <xen/xen.h>
#include <xen/io/domain_controller.h>
-#include <xen/linux/privcmd.h>
#include <arpa/inet.h>
#include <xcs_proto.h>
diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index e4a6ac798a..b7caea3582 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -16,6 +16,7 @@ SRCS += xc_core.c
SRCS += xc_domain.c
SRCS += xc_evtchn.c
SRCS += xc_misc.c
+SRCS += xc_acm.c
SRCS += xc_physdev.c
SRCS += xc_private.c
SRCS += xc_sedf.c
@@ -27,6 +28,10 @@ SRCS += xc_ptrace_core.c
SRCS += xc_pagetab.c
endif
+SRCS_Linux += xc_linux.c
+
+SRCS += $(SRCS_Linux)
+
BUILD_SRCS :=
BUILD_SRCS += xc_linux_build.c
BUILD_SRCS += xc_load_bin.c
diff --git a/tools/libxc/xc_acm.c b/tools/libxc/xc_acm.c
new file mode 100644
index 0000000000..2aa9ba6a86
--- /dev/null
+++ b/tools/libxc/xc_acm.c
@@ -0,0 +1,54 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2005 IBM Corporation
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Authors:
+ * Reiner Sailer <sailer@watson.ibm.com>
+ * Stefan Berger <stefanb@watson.ibm.com>
+ *
+ * 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
+ * License.
+ */
+
+#include "xc_private.h"
+
+int xc_acm_op(int xc_handle, struct acm_op *op)
+{
+ int ret = -1;
+ DECLARE_HYPERCALL;
+
+ op->interface_version = ACM_INTERFACE_VERSION;
+
+ hypercall.op = __HYPERVISOR_acm_op;
+ hypercall.arg[0] = (unsigned long) op;
+
+ if (mlock(op, sizeof(*op)) != 0) {
+ PERROR("Could not lock memory for Xen policy hypercall");
+ goto out1;
+ }
+
+ 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:
+ return ret;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c
new file mode 100644
index 0000000000..4f7c78ad38
--- /dev/null
+++ b/tools/libxc/xc_linux.c
@@ -0,0 +1,114 @@
+/******************************************************************************
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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
+ * License.
+ */
+
+#include "xc_private.h"
+
+#include <xen/memory.h>
+#include <xen/sys/evtchn.h>
+
+int xc_interface_open(void)
+{
+ int fd = open("/proc/xen/privcmd", O_RDWR);
+ if ( fd == -1 )
+ PERROR("Could not obtain handle on privileged command interface");
+ return fd;
+}
+
+int xc_interface_close(int xc_handle)
+{
+ return close(xc_handle);
+}
+
+void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
+ unsigned long *arr, int num)
+{
+ privcmd_mmapbatch_t ioctlx;
+ void *addr;
+ addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
+ if ( addr == MAP_FAILED )
+ return NULL;
+
+ ioctlx.num=num;
+ ioctlx.dom=dom;
+ ioctlx.addr=(unsigned long)addr;
+ ioctlx.arr=arr;
+ if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+ {
+ int saved_errno = errno;
+ perror("XXXXXXXX");
+ (void)munmap(addr, num*PAGE_SIZE);
+ errno = saved_errno;
+ return NULL;
+ }
+ return addr;
+
+}
+
+void *xc_map_foreign_range(int xc_handle, uint32_t dom,
+ int size, int prot,
+ unsigned long mfn)
+{
+ privcmd_mmap_t ioctlx;
+ privcmd_mmap_entry_t entry;
+ void *addr;
+ addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
+ if ( addr == MAP_FAILED )
+ return NULL;
+
+ ioctlx.num=1;
+ ioctlx.dom=dom;
+ ioctlx.entry=&entry;
+ entry.va=(unsigned long) addr;
+ entry.mfn=mfn;
+ entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
+ if ( ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx) < 0 )
+ {
+ int saved_errno = errno;
+ (void)munmap(addr, size);
+ errno = saved_errno;
+ return NULL;
+ }
+ return addr;
+}
+
+int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
+ privcmd_mmap_entry_t *entries, int nr)
+{
+ privcmd_mmap_t ioctlx;
+
+ ioctlx.num = nr;
+ ioctlx.dom = dom;
+ ioctlx.entry = entries;
+
+ return ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx);
+}
+
+static int do_privcmd(int xc_handle, unsigned int cmd, unsigned long data)
+{
+ return ioctl(xc_handle, cmd, data);
+}
+
+int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
+{
+ return do_privcmd(xc_handle,
+ IOCTL_PRIVCMD_HYPERCALL,
+ (unsigned long)hypercall);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xc_linux_save.c b/tools/libxc/xc_linux_save.c
index 4223342703..34387abd07 100644
--- a/tools/libxc/xc_linux_save.c
+++ b/tools/libxc/xc_linux_save.c
@@ -12,6 +12,7 @@
#include <unistd.h>
#include <sys/time.h>
+#include "xc_private.h"
#include "xg_private.h"
#include "xg_save_restore.h"
@@ -505,7 +506,6 @@ static unsigned long *xc_map_m2p(int xc_handle,
int prot)
{
struct xen_machphys_mfn_list xmml;
- privcmd_mmap_t ioctlx;
privcmd_mmap_entry_t *entries;
unsigned long m2p_chunks, m2p_size;
unsigned long *m2p;
@@ -539,18 +539,15 @@ static unsigned long *xc_map_m2p(int xc_handle,
return NULL;
}
- ioctlx.num = m2p_chunks;
- ioctlx.dom = DOMID_XEN;
- ioctlx.entry = entries;
-
for (i=0; i < m2p_chunks; i++) {
entries[i].va = (unsigned long)(((void *)m2p) + (i * M2P_CHUNK_SIZE));
entries[i].mfn = extent_start[i];
entries[i].npages = M2P_CHUNK_SIZE >> PAGE_SHIFT;
}
- if ((rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx)) < 0) {
- ERR("ioctl_mmap failed (rc = %d)", rc);
+ if ((rc = xc_map_foreign_ranges(xc_handle, DOMID_XEN,
+ entries, m2p_chunks)) < 0) {
+ ERR("xc_mmap_foreign_ranges failed (rc = %d)", rc);
return NULL;
}
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index 5da4db8074..4c0cb24b90 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -6,19 +6,6 @@
#include "xc_private.h"
-int xc_interface_open(void)
-{
- int fd = open("/proc/xen/privcmd", O_RDWR);
- if ( fd == -1 )
- PERROR("Could not obtain handle on privileged command interface");
- return fd;
-}
-
-int xc_interface_close(int xc_handle)
-{
- return close(xc_handle);
-}
-
int xc_readconsolering(int xc_handle,
char **pbuffer,
unsigned int *pnr_chars,
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index c44ce2b0ec..f776d2ff0a 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -5,63 +5,6 @@
*/
#include "xc_private.h"
-#include <xen/memory.h>
-
-void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
- unsigned long *arr, int num )
-{
- privcmd_mmapbatch_t ioctlx;
- void *addr;
- addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
- if ( addr == MAP_FAILED )
- return NULL;
-
- ioctlx.num=num;
- ioctlx.dom=dom;
- ioctlx.addr=(unsigned long)addr;
- ioctlx.arr=arr;
- if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx ) < 0 )
- {
- int saved_errno = errno;
- perror("XXXXXXXX");
- (void)munmap(addr, num*PAGE_SIZE);
- errno = saved_errno;
- return NULL;
- }
- return addr;
-
-}
-
-/*******************/
-
-void *xc_map_foreign_range(int xc_handle, uint32_t dom,
- int size, int prot,
- unsigned long mfn )
-{
- privcmd_mmap_t ioctlx;
- privcmd_mmap_entry_t entry;
- void *addr;
- addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
- if ( addr == MAP_FAILED )
- return NULL;
-
- ioctlx.num=1;
- ioctlx.dom=dom;
- ioctlx.entry=&entry;
- entry.va=(unsigned long) addr;
- entry.mfn=mfn;
- entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
- if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 )
- {
- int saved_errno = errno;
- (void)munmap(addr, size);
- errno = saved_errno;
- return NULL;
- }
- return addr;
-}
-
-/*******************/
/* NB: arr must be mlock'ed */
int xc_get_pfn_type_batch(int xc_handle,
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index 2ea3b57491..f0ee3cc0ed 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -15,7 +15,7 @@
#include "xenctrl.h"
-#include <xen/linux/privcmd.h>
+#include <xen/sys/privcmd.h>
/* valgrind cannot see when a hypercall has filled in some values. For this
reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a
@@ -56,20 +56,7 @@ static inline void safe_munlock(const void *addr, size_t len)
errno = saved_errno;
}
-static inline int do_privcmd(int xc_handle,
- unsigned int cmd,
- unsigned long data)
-{
- return ioctl(xc_handle, cmd, data);
-}
-
-static inline int do_xen_hypercall(int xc_handle,
- privcmd_hypercall_t *hypercall)
-{
- return do_privcmd(xc_handle,
- IOCTL_PRIVCMD_HYPERCALL,
- (unsigned long)hypercall);
-}
+int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
static inline int do_xen_version(int xc_handle, int cmd, void *dest)
{
@@ -111,23 +98,7 @@ static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
return ret;
}
-
-/*
- * ioctl-based mfn mapping interface
- */
-
-/*
-typedef struct privcmd_mmap_entry {
- unsigned long va;
- unsigned long mfn;
- unsigned long npages;
-} privcmd_mmap_entry_t;
-
-typedef struct privcmd_mmap {
- int num;
- domid_t dom;
- privcmd_mmap_entry_t *entry;
-} privcmd_mmap_t;
-*/
+int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
+ privcmd_mmap_entry_t *entries, int nr);
#endif /* __XC_PRIVATE_H__ */
diff --git a/tools/libxc/xc_tbuf.c b/tools/libxc/xc_tbuf.c
index 3a427a0171..ea64c8533f 100644
--- a/tools/libxc/xc_tbuf.c
+++ b/tools/libxc/xc_tbuf.c
@@ -4,6 +4,14 @@
* API for manipulating and accessing trace buffer parameters
*
* Copyright (c) 2005, Rob Gardner
+ *
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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
+ * License.
*/
#include "xc_private.h"
@@ -49,3 +57,41 @@ int xc_tbuf_get_size(int xc_handle, uint32_t *size)
return rc;
}
+int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn)
+{
+ int rc;
+ DECLARE_DOM0_OP;
+
+ op.cmd = DOM0_TBUFCONTROL;
+ op.interface_version = DOM0_INTERFACE_VERSION;
+ op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO;
+
+ rc = xc_dom0_op(xc_handle, &op);
+ if ( rc == 0 )
+ *mfn = op.u.tbufcontrol.buffer_mfn;
+ return rc;
+}
+
+int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask)
+{
+ DECLARE_DOM0_OP;
+
+ op.cmd = DOM0_TBUFCONTROL;
+ op.interface_version = DOM0_INTERFACE_VERSION;
+ op.u.tbufcontrol.op = DOM0_TBUF_SET_CPU_MASK;
+ op.u.tbufcontrol.cpu_mask = mask;
+
+ return do_dom0_op(xc_handle, &op);
+}
+
+int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask)
+{
+ DECLARE_DOM0_OP;
+
+ op.cmd = DOM0_TBUFCONTROL;
+ op.interface_version = DOM0_INTERFACE_VERSION;
+ op.u.tbufcontrol.op = DOM0_TBUF_SET_EVT_MASK;
+ op.u.tbufcontrol.evt_mask = mask;
+
+ return do_dom0_op(xc_handle, &op);
+}
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index bb70bc7f48..f6c6037c02 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -19,6 +19,7 @@
#include <xen/sched_ctl.h>
#include <xen/memory.h>
#include <xen/acm.h>
+#include <xen/acm_ops.h>
#ifdef __ia64__
#define XC_PAGE_SHIFT 14
@@ -560,6 +561,18 @@ int xc_tbuf_set_size(int xc_handle, uint32_t size);
*/
int xc_tbuf_get_size(int xc_handle, uint32_t *size);
+/**
+ * This function retrieves the machine frame of the trace buffer.
+
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm mfn will contain the machine frame of the buffer.
+ * @return 0 on success, -1 on failure.
+ */
+int xc_tbuf_get_mfn(int xc_handle, unsigned long *mfn);
+
+int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask);
+
+int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask);
/* Execute a privileged dom0 operation. */
int xc_dom0_op(int xc_handle, dom0_op_t *op);
@@ -581,4 +594,6 @@ int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
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);
+
#endif
diff --git a/tools/libxc/xg_private.h b/tools/libxc/xg_private.h
index 477110b317..f7e8efac5b 100644
--- a/tools/libxc/xg_private.h
+++ b/tools/libxc/xg_private.h
@@ -13,7 +13,7 @@
#include "xenctrl.h"
#include "xenguest.h"
-#include <xen/linux/privcmd.h>
+#include <xen/sys/privcmd.h>
#include <xen/memory.h>
/* valgrind cannot see when a hypercall has filled in some values. For this
diff --git a/tools/python/xen/lowlevel/acm/acm.c b/tools/python/xen/lowlevel/acm/acm.c
index 327192d606..658ef43ef5 100644
--- a/tools/python/xen/lowlevel/acm/acm.c
+++ b/tools/python/xen/lowlevel/acm/acm.c
@@ -28,51 +28,22 @@
#include <netinet/in.h>
#include <xen/acm.h>
#include <xen/acm_ops.h>
-#include <xen/linux/privcmd.h>
+
+#include <xenctrl.h>
#define PERROR(_m, _a...) \
fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
errno, strerror(errno))
-
-
-static inline int do_acm_op(int xc_handle, struct acm_op *op)
-{
- int ret = -1;
- privcmd_hypercall_t hypercall;
-
- op->interface_version = ACM_INTERFACE_VERSION;
-
- hypercall.op = __HYPERVISOR_acm_op;
- hypercall.arg[0] = (unsigned long) op;
-
- if (mlock(op, sizeof(*op)) != 0) {
- PERROR("Could not lock memory for Xen policy hypercall");
- goto out1;
- }
- ret = ioctl(xc_handle, IOCTL_PRIVCMD_HYPERCALL, &hypercall);
- if (ret < 0) {
- if (errno == EACCES)
- PERROR("ACM operation failed.");
- goto out2;
- }
- out2:
- munlock(op, sizeof(*op));
- out1:
- return ret;
-}
-
-
-
/* generic shared function */
void * __getssid(int domid, uint32_t *buflen)
{
struct acm_op op;
- int acm_cmd_fd;
+ int xc_handle;
#define SSID_BUFFER_SIZE 4096
void *buf = NULL;
- if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) < 0) {
+ if ((xc_handle = xc_interface_open()) < 0) {
goto out1;
}
if ((buf = malloc(SSID_BUFFER_SIZE)) == NULL) {
@@ -87,7 +58,9 @@ void * __getssid(int domid, uint32_t *buflen)
op.u.getssid.get_ssid_by = DOMAINID;
op.u.getssid.id.domainid = domid;
- if (do_acm_op(acm_cmd_fd, &op) < 0) {
+ if (xc_acm_op(xc_handle, &op) < 0) {
+ if (errno == EACCES)
+ PERROR("ACM operation failed.");
free(buf);
buf = NULL;
goto out2;
@@ -96,7 +69,7 @@ void * __getssid(int domid, uint32_t *buflen)
goto out2;
}
out2:
- close(acm_cmd_fd);
+ xc_interface_close(xc_handle);
out1:
return buf;
}
@@ -175,13 +148,13 @@ static PyObject *getdecision(PyObject * self, PyObject * args)
{
char *arg1_name, *arg1, *arg2_name, *arg2, *decision = NULL;
struct acm_op op;
- int acm_cmd_fd, ret;
+ int xc_handle;
if (!PyArg_ParseTuple(args, "ssss", &arg1_name, &arg1, &arg2_name, &arg2)) {
return NULL;
}
- if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) {
+ if ((xc_handle = xc_interface_open()) <= 0) {
PERROR("Could not open xen privcmd device!\n");
return NULL;
}
@@ -208,8 +181,12 @@ static PyObject *getdecision(PyObject * self, PyObject * args)
op.u.getdecision.id2.ssidref = atol(arg2);
}
- ret = do_acm_op(acm_cmd_fd, &op);
- close(acm_cmd_fd);
+ if (xc_acm_op(xc_handle, &op) < 0) {
+ if (errno == EACCES)
+ PERROR("ACM operation failed.");
+ }
+
+ xc_interface_close(xc_handle);
if (op.u.getdecision.acm_decision == ACM_ACCESS_PERMITTED)
decision = "PERMITTED";
diff --git a/tools/security/secpol_tool.c b/tools/security/secpol_tool.c
index 883a38ed1e..e752b56a5d 100644
--- a/tools/security/secpol_tool.c
+++ b/tools/security/secpol_tool.c
@@ -14,7 +14,7 @@
*
* sHype policy management tool. This code runs in a domain and
* manages the Xen security policy by interacting with the
- * Xen access control module via a /proc/xen/privcmd proc-ioctl,
+ * Xen access control module via the privcmd device,
* which is translated into a acm_op hypercall into Xen.
*
* indent -i4 -kr -nut
@@ -36,7 +36,8 @@
#include <stdint.h>
#include <xen/acm.h>
#include <xen/acm_ops.h>
-#include <xen/linux/privcmd.h>
+
+#include <xenctrl.h>
#define PERROR(_m, _a...) \
fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
@@ -52,47 +53,6 @@ void usage(char *progname)
exit(-1);
}
-static inline int do_policycmd(int xc_handle, unsigned int cmd,
- unsigned long data)
-{
- return ioctl(xc_handle, cmd, data);
-}
-
-static inline int do_xen_hypercall(int xc_handle,
- privcmd_hypercall_t * hypercall)
-{
- return do_policycmd(xc_handle,
- IOCTL_PRIVCMD_HYPERCALL,
- (unsigned long) hypercall);
-}
-
-static inline int do_acm_op(int xc_handle, struct acm_op *op)
-{
- int ret = -1;
- privcmd_hypercall_t hypercall;
-
- op->interface_version = ACM_INTERFACE_VERSION;
-
- hypercall.op = __HYPERVISOR_acm_op;
- hypercall.arg[0] = (unsigned long) op;
-
- if (mlock(op, sizeof(*op)) != 0) {
- PERROR("Could not lock memory for Xen policy hypercall");
- goto out1;
- }
-
- if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0) {
- printf("ACM operation failed: errno=%d\n", errno);
- if (errno == EACCES)
- fprintf(stderr, "ACM operation failed -- need to"
- " rebuild the user-space tool set?\n");
- goto out2;
- }
-
- out2:(void) munlock(op, sizeof(*op));
- out1:return ret;
-}
-
/*************************** DUMPS *******************************/
void acm_dump_chinesewall_buffer(void *buf, int buflen)
@@ -276,10 +236,15 @@ int acm_domain_getpolicy(int xc_handle)
memset(pull_buffer, 0x00, sizeof(pull_buffer));
op.cmd = ACM_GETPOLICY;
- op.interface_version = ACM_INTERFACE_VERSION;
op.u.getpolicy.pullcache = (void *) pull_buffer;
op.u.getpolicy.pullcache_size = sizeof(pull_buffer);
- ret = do_acm_op(xc_handle, &op);
+ if ((ret = xc_acm_op(xc_handle, &op)) < 0) {
+ printf("ACM operation failed: errno=%d\n", errno);
+ if (errno == EACCES)
+ fprintf(stderr, "ACM operation failed -- need to"
+ " rebuild the user-space tool set?\n");
+ }
+
/* dump policy */
acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer));
return ret;
@@ -314,10 +279,9 @@ int acm_domain_loadpolicy(int xc_handle, const char *filename)
/* dump it and then push it down into xen/acm */
acm_dump_policy_buffer(buffer, len);
op.cmd = ACM_SETPOLICY;
- op.interface_version = ACM_INTERFACE_VERSION;
op.u.setpolicy.pushcache = (void *) buffer;
op.u.setpolicy.pushcache_size = len;
- ret = do_acm_op(xc_handle, &op);
+ ret = xc_acm_op(xc_handle, &op);
if (ret)
printf
@@ -364,10 +328,9 @@ int acm_domain_dumpstats(int xc_handle)
memset(stats_buffer, 0x00, sizeof(stats_buffer));
op.cmd = ACM_DUMPSTATS;
- op.interface_version = ACM_INTERFACE_VERSION;
op.u.dumpstats.pullcache = (void *) stats_buffer;
op.u.dumpstats.pullcache_size = sizeof(stats_buffer);
- ret = do_acm_op(xc_handle, &op);
+ ret = xc_acm_op(xc_handle, &op);
if (ret < 0) {
printf
@@ -426,12 +389,12 @@ int acm_domain_dumpstats(int xc_handle)
int main(int argc, char **argv)
{
- int acm_cmd_fd, ret = 0;
+ int xc_handle, ret = 0;
if (argc < 2)
usage(argv[0]);
- if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) {
+ if ((xc_handle = xc_interface_open()) <= 0) {
printf("ERROR: Could not open xen privcmd device!\n");
exit(-1);
}
@@ -439,18 +402,18 @@ int main(int argc, char **argv)
if (!strcmp(argv[1], "getpolicy")) {
if (argc != 2)
usage(argv[0]);
- ret = acm_domain_getpolicy(acm_cmd_fd);
+ ret = acm_domain_getpolicy(xc_handle);
} else if (!strcmp(argv[1], "loadpolicy")) {
if (argc != 3)
usage(argv[0]);
- ret = acm_domain_loadpolicy(acm_cmd_fd, argv[2]);
+ ret = acm_domain_loadpolicy(xc_handle, argv[2]);
} else if (!strcmp(argv[1], "dumpstats")) {
if (argc != 2)
usage(argv[0]);
- ret = acm_domain_dumpstats(acm_cmd_fd);
+ ret = acm_domain_dumpstats(xc_handle);
} else
usage(argv[0]);
- close(acm_cmd_fd);
+ xc_interface_close(xc_handle);
return ret;
}
diff --git a/tools/xenmon/xenbaked.c b/tools/xenmon/xenbaked.c
index 41db7def3a..402089c1f7 100644
--- a/tools/xenmon/xenbaked.c
+++ b/tools/xenmon/xenbaked.c
@@ -410,14 +410,13 @@ void get_tbufs(unsigned long *mfn, unsigned long *size)
struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
unsigned long size)
{
- int xc_handle; /* file descriptor for /proc/xen/privcmd */
+ int xc_handle;
struct t_buf *tbufs_mapped;
xc_handle = xc_interface_open();
if ( xc_handle < 0 )
{
- PERROR("Open /proc/xen/privcmd when mapping trace buffers\n");
exit(EXIT_FAILURE);
}
diff --git a/tools/xenstat/libxenstat/Makefile b/tools/xenstat/libxenstat/Makefile
index f97f2a7618..7eea316133 100644
--- a/tools/xenstat/libxenstat/Makefile
+++ b/tools/xenstat/libxenstat/Makefile
@@ -33,28 +33,26 @@ MINOR=0
LIB=src/libxenstat.a
SHLIB=src/libxenstat.so.$(MAJOR).$(MINOR)
SHLIB_LINKS=src/libxenstat.so.$(MAJOR) src/libxenstat.so
-OBJECTS=src/xenstat.o src/xen-interface.o
+OBJECTS=src/xenstat.o
SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.so.$(MAJOR)
WARN_FLAGS=-Wall -Werror
CFLAGS+=-Isrc -I$(XEN_LIBXC) -I$(XEN_XENSTORE)
-LDFLAGS+=-Lsrc
+LDFLAGS+=-Lsrc -L$(XEN_XENSTORE)/ -L$(XEN_LIBXC)/
.PHONY: all
all: $(LIB)
$(LIB): $(OBJECTS)
- $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so
+ $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so $(XEN_LIBXC)/libxenctrl.so
$(RANLIB) $@
$(SHLIB): $(OBJECTS)
- $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS)
+ $(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS) \
+ -lxenstore -lxenctrl
-src/xenstat.o: src/xenstat.c src/xenstat.h src/xen-interface.h
- $(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $<
-
-src/xen-interface.o: src/xen-interface.c src/xen-interface.h
+src/xenstat.o: src/xenstat.c src/xenstat.h
$(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $<
src/libxenstat.so.$(MAJOR): $(LIB)
diff --git a/tools/xenstat/libxenstat/src/xenstat.c b/tools/xenstat/libxenstat/src/xenstat.c
index 3332f2cad7..5f86b13d02 100644
--- a/tools/xenstat/libxenstat/src/xenstat.c
+++ b/tools/xenstat/libxenstat/src/xenstat.c
@@ -20,10 +20,11 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <xen-interface.h>
#include <xs.h>
#include "xenstat.h"
+#include "xenctrl.h"
+
/*
* Types
*/
@@ -31,7 +32,7 @@
#define VERSION_SIZE (2 * SHORT_ASC_LEN + 1 + sizeof(xen_extraversion_t) + 1)
struct xenstat_handle {
- xi_handle *xihandle;
+ int xc_handle;
struct xs_handle *xshandle; /* xenstore handle */
int page_size;
FILE *procnetdev;
@@ -150,9 +151,9 @@ xenstat_handle *xenstat_init(void)
}
#endif
- handle->xihandle = xi_init();
- if (handle->xihandle == NULL) {
- perror("xi_init");
+ handle->xc_handle = xc_interface_open();
+ if (handle->xc_handle == -1) {
+ perror("xc_interface_open");
free(handle);
return NULL;
}
@@ -160,6 +161,7 @@ xenstat_handle *xenstat_init(void)
handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/
if (handle->xshandle == NULL) {
perror("unable to open xenstore\n");
+ xc_interface_close(handle->xc_handle);
free(handle);
return NULL;
}
@@ -173,7 +175,7 @@ void xenstat_uninit(xenstat_handle * handle)
if (handle) {
for (i = 0; i < NUM_COLLECTORS; i++)
collectors[i].uninit(handle);
- xi_uninit(handle->xihandle);
+ xc_interface_close(handle->xc_handle);
xs_daemon_close(handle->xshandle);
free(handle);
}
@@ -197,7 +199,7 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
node->handle = handle;
/* Get information about the physical system */
- if (xi_get_physinfo(handle->xihandle, &physinfo) < 0) {
+ if (xc_physinfo(handle->xc_handle, &physinfo) < 0) {
free(node);
return NULL;
}
@@ -223,9 +225,8 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
do {
xenstat_domain *domain;
- new_domains = xi_get_domaininfolist(handle->xihandle,
- domaininfo, num_domains,
- DOMAIN_CHUNK_SIZE);
+ new_domains = xc_domain_getinfolist(handle->xc_handle,
+ num_domains, DOMAIN_CHUNK_SIZE, domaininfo);
node->domains = realloc(node->domains,
(num_domains + new_domains)
@@ -467,8 +468,8 @@ static int xenstat_collect_vcpus(xenstat_node * node)
/* FIXME: need to be using a more efficient mechanism*/
dom0_getvcpuinfo_t info;
- if (xi_get_domain_vcpu_info(node->handle->xihandle,
- node->domains[i].id, vcpu, &info) != 0)
+ if (xc_vcpu_getinfo(node->handle->xc_handle,
+ node->domains[i].id, vcpu, &info) != 0)
return 0;
node->domains[i].vcpus[vcpu].online = info.online;
@@ -677,8 +678,14 @@ static int xenstat_collect_xen_version(xenstat_node * node)
/* Collect Xen version information if not already collected */
if (node->handle->xen_version[0] == '\0') {
/* Get the Xen version number and extraversion string */
- if (xi_get_xen_version(node->handle->xihandle,
- &vnum, &version) < 0)
+ vnum = xc_version(node->handle->xc_handle,
+ XENVER_version, NULL);
+
+ if (vnum < 0)
+ return 0;
+
+ if (xc_version(node->handle->xc_handle, XENVER_extraversion,
+ &version) < 0)
return 0;
/* Format the version information as a string and store it */
snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s",
diff --git a/tools/xentrace/xentrace.c b/tools/xentrace/xentrace.c
index ee320c31dc..e001704d2c 100644
--- a/tools/xentrace/xentrace.c
+++ b/tools/xentrace/xentrace.c
@@ -20,11 +20,22 @@
#include <errno.h>
#include <argp.h>
#include <signal.h>
+#include <inttypes.h>
+#include <string.h>
-#include "xc_private.h"
-
+#include <xen/xen.h>
#include <xen/trace.h>
+#include <xenctrl.h>
+
+#define PERROR(_m, _a...) \
+do { \
+ int __saved_errno = errno; \
+ fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
+ __saved_errno, strerror(__saved_errno)); \
+ errno = __saved_errno; \
+} while (0)
+
extern FILE *stderr;
/***** Compile time configuration of defaults ********************************/
@@ -100,26 +111,22 @@ void write_rec(unsigned int cpu, struct t_rec *rec, FILE *out)
*/
void get_tbufs(unsigned long *mfn, unsigned long *size)
{
- int ret;
- dom0_op_t op; /* dom0 op we'll build */
+ uint32_t size32;
int xc_handle = xc_interface_open(); /* for accessing control interface */
- op.cmd = DOM0_TBUFCONTROL;
- op.interface_version = DOM0_INTERFACE_VERSION;
- op.u.tbufcontrol.op = DOM0_TBUF_GET_INFO;
+ if (xc_tbuf_get_size(xc_handle, &size32) != 0)
+ goto fail;
+ *size = size32;
- ret = do_dom0_op(xc_handle, &op);
+ if (xc_tbuf_get_mfn(xc_handle, mfn) != 0)
+ goto fail;
xc_interface_close(xc_handle);
+ return;
- if ( ret != 0 )
- {
- PERROR("Failure to get trace buffer pointer from Xen");
- exit(EXIT_FAILURE);
- }
-
- *mfn = op.u.tbufcontrol.buffer_mfn;
- *size = op.u.tbufcontrol.size;
+fail:
+ PERROR("Failure to get trace buffer pointer from Xen");
+ exit(EXIT_FAILURE);
}
/**
@@ -133,14 +140,13 @@ void get_tbufs(unsigned long *mfn, unsigned long *size)
struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
unsigned long size)
{
- int xc_handle; /* file descriptor for /proc/xen/privcmd */
+ int xc_handle;
struct t_buf *tbufs_mapped;
xc_handle = xc_interface_open();
if ( xc_handle < 0 )
{
- PERROR("Open /proc/xen/privcmd when mapping trace buffers\n");
exit(EXIT_FAILURE);
}
@@ -167,24 +173,17 @@ struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
*/
void set_mask(uint32_t mask, int type)
{
- int ret;
- dom0_op_t op; /* dom0 op we'll build */
+ int ret = 0;
int xc_handle = xc_interface_open(); /* for accessing control interface */
- op.cmd = DOM0_TBUFCONTROL;
- op.interface_version = DOM0_INTERFACE_VERSION;
- if (type == 1) { /* cpu mask */
- op.u.tbufcontrol.op = DOM0_TBUF_SET_CPU_MASK;
- op.u.tbufcontrol.cpu_mask = mask;
+ if (type == 1) {
+ ret = xc_tbuf_set_cpu_mask(xc_handle, mask);
fprintf(stderr, "change cpumask to 0x%x\n", mask);
- }else if (type == 0) { /* event mask */
- op.u.tbufcontrol.op = DOM0_TBUF_SET_EVT_MASK;
- op.u.tbufcontrol.evt_mask = mask;
+ } else if (type == 0) {
+ ret = xc_tbuf_set_evt_mask(xc_handle, mask);
fprintf(stderr, "change evtmask to 0x%x\n", mask);
}
- ret = do_dom0_op(xc_handle, &op);
-
xc_interface_close(xc_handle);
if ( ret != 0 )
@@ -192,7 +191,6 @@ void set_mask(uint32_t mask, int type)
PERROR("Failure to get trace buffer pointer from Xen and set the new mask");
exit(EXIT_FAILURE);
}
-
}
/**
@@ -260,14 +258,11 @@ struct t_rec **init_rec_ptrs(struct t_buf **meta, unsigned int num)
*/
unsigned int get_num_cpus(void)
{
- dom0_op_t op;
+ xc_physinfo_t physinfo;
int xc_handle = xc_interface_open();
int ret;
- op.cmd = DOM0_PHYSINFO;
- op.interface_version = DOM0_INTERFACE_VERSION;
-
- ret = do_dom0_op(xc_handle, &op);
+ ret = xc_physinfo(xc_handle, &physinfo);
if ( ret != 0 )
{
@@ -277,10 +272,10 @@ unsigned int get_num_cpus(void)
xc_interface_close(xc_handle);
- return (op.u.physinfo.threads_per_core *
- op.u.physinfo.cores_per_socket *
- op.u.physinfo.sockets_per_node *
- op.u.physinfo.nr_nodes);
+ return (physinfo.threads_per_core *
+ physinfo.cores_per_socket *
+ physinfo.sockets_per_node *
+ physinfo.nr_nodes);
}