diff options
Diffstat (limited to 'tools/libxc')
-rw-r--r-- | tools/libxc/Makefile | 5 | ||||
-rw-r--r-- | tools/libxc/xc_acm.c | 54 | ||||
-rw-r--r-- | tools/libxc/xc_linux.c | 114 | ||||
-rw-r--r-- | tools/libxc/xc_linux_save.c | 11 | ||||
-rw-r--r-- | tools/libxc/xc_misc.c | 13 | ||||
-rw-r--r-- | tools/libxc/xc_private.c | 57 | ||||
-rw-r--r-- | tools/libxc/xc_private.h | 37 | ||||
-rw-r--r-- | tools/libxc/xc_tbuf.c | 46 | ||||
-rw-r--r-- | tools/libxc/xenctrl.h | 15 | ||||
-rw-r--r-- | tools/libxc/xg_private.h | 2 |
10 files changed, 243 insertions, 111 deletions
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 |