debuggers.hg

view tools/libxc/xc_private.h @ 19826:2f9e1348aa98

x86_64: allow more vCPU-s per guest

Since the shared info layout is fixed, guests are required to use
VCPUOP_register_vcpu_info prior to booting any vCPU beyond the
traditional limit of 32.

MAX_VIRT_CPUS, being an implemetation detail of the hypervisor, is no
longer being exposed in the public headers.

The tools changes are clearly incomplete (and done only so things
would
build again), and the current state of the tools (using scalar
variables all over the place to represent vCPU bitmaps) very likely
doesn't permit booting DomU-s with more than the traditional number of
vCPU-s. Testing of the extended functionality was done with Dom0 (96
vCPU-s, as well as 128 vCPU-s out of which the kernel elected - by way
of a simple kernel side patch - to use only some, resulting in a
sparse
bitmap).

ia64 changes only to make things build, and build-tested only (and the
tools part only as far as the build would go without encountering
unrelated problems in the blktap code).

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 18 10:14:16 2009 +0100 (2009-06-18)
parents f6b92526e916
children 809b20f066fb 0447c5532e9f
line source
2 #ifndef XC_PRIVATE_H
3 #define XC_PRIVATE_H
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <string.h>
10 #include <sys/mman.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <stdlib.h>
14 #include <sys/ioctl.h>
16 #include "xenctrl.h"
18 #include <xen/sys/privcmd.h>
20 /* valgrind cannot see when a hypercall has filled in some values. For this
21 reason, we must zero the privcmd_hypercall_t or domctl/sysctl instance
22 before a call, if using valgrind. */
23 #ifdef VALGRIND
24 #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall = { 0 }
25 #define DECLARE_DOMCTL struct xen_domctl domctl = { 0 }
26 #define DECLARE_SYSCTL struct xen_sysctl sysctl = { 0 }
27 #define DECLARE_PHYSDEV_OP struct physdev_op physdev_op = { 0 }
28 #else
29 #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
30 #define DECLARE_DOMCTL struct xen_domctl domctl
31 #define DECLARE_SYSCTL struct xen_sysctl sysctl
32 #define DECLARE_PHYSDEV_OP struct physdev_op physdev_op
33 #endif
35 #undef PAGE_SHIFT
36 #undef PAGE_SIZE
37 #undef PAGE_MASK
38 #define PAGE_SHIFT XC_PAGE_SHIFT
39 #define PAGE_SIZE (1UL << PAGE_SHIFT)
40 #define PAGE_MASK (~(PAGE_SIZE-1))
42 #define DEBUG 1
43 #define INFO 1
44 #define PROGRESS 0
46 /* Force a compilation error if condition is true */
47 #define XC_BUILD_BUG_ON(p) ((void)sizeof(struct { int:-!!(p); }))
49 /*
50 ** Define max dirty page cache to permit during save/restore -- need to balance
51 ** keeping cache usage down with CPU impact of invalidating too often.
52 ** (Currently 16MB)
53 */
54 #define MAX_PAGECACHE_USAGE (4*1024)
56 #if INFO
57 #define IPRINTF(_f, _a...) printf(_f , ## _a)
58 #else
59 #define IPRINTF(_f, _a...) ((void)0)
60 #endif
62 #if DEBUG
63 #define DPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
64 #else
65 #define DPRINTF(_f, _a...) ((void)0)
66 #endif
68 #if PROGRESS
69 #define PPRINTF(_f, _a...) fprintf(stderr, _f , ## _a)
70 #else
71 #define PPRINTF(_f, _a...)
72 #endif
74 char *safe_strerror(int errcode);
75 void xc_set_error(int code, const char *fmt, ...);
77 #define ERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m , ## _a )
78 #define PERROR(_m, _a...) xc_set_error(XC_INTERNAL_ERROR, _m " (%d = %s)", \
79 ## _a , errno, safe_strerror(errno))
81 int lock_pages(void *addr, size_t len);
82 void unlock_pages(void *addr, size_t len);
84 static inline void safe_munlock(const void *addr, size_t len)
85 {
86 int saved_errno = errno;
87 (void)munlock(addr, len);
88 errno = saved_errno;
89 }
91 int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall);
93 static inline int do_xen_version(int xc_handle, int cmd, void *dest)
94 {
95 DECLARE_HYPERCALL;
97 hypercall.op = __HYPERVISOR_xen_version;
98 hypercall.arg[0] = (unsigned long) cmd;
99 hypercall.arg[1] = (unsigned long) dest;
101 return do_xen_hypercall(xc_handle, &hypercall);
102 }
104 static inline int do_physdev_op(int xc_handle, int cmd, void *op)
105 {
106 int ret = -1;
108 DECLARE_HYPERCALL;
109 hypercall.op = __HYPERVISOR_physdev_op;
110 hypercall.arg[0] = (unsigned long) cmd;
111 hypercall.arg[1] = (unsigned long) op;
113 if ( lock_pages(op, sizeof(*op)) != 0 )
114 {
115 PERROR("Could not lock memory for Xen hypercall");
116 goto out1;
117 }
119 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
120 {
121 if ( errno == EACCES )
122 DPRINTF("physdev operation failed -- need to"
123 " rebuild the user-space tool set?\n");
124 }
126 unlock_pages(op, sizeof(*op));
128 out1:
129 return ret;
130 }
132 static inline int do_domctl(int xc_handle, struct xen_domctl *domctl)
133 {
134 int ret = -1;
135 DECLARE_HYPERCALL;
137 domctl->interface_version = XEN_DOMCTL_INTERFACE_VERSION;
139 hypercall.op = __HYPERVISOR_domctl;
140 hypercall.arg[0] = (unsigned long)domctl;
142 if ( lock_pages(domctl, sizeof(*domctl)) != 0 )
143 {
144 PERROR("Could not lock memory for Xen hypercall");
145 goto out1;
146 }
148 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
149 {
150 if ( errno == EACCES )
151 DPRINTF("domctl operation failed -- need to"
152 " rebuild the user-space tool set?\n");
153 }
155 unlock_pages(domctl, sizeof(*domctl));
157 out1:
158 return ret;
159 }
161 static inline int do_sysctl(int xc_handle, struct xen_sysctl *sysctl)
162 {
163 int ret = -1;
164 DECLARE_HYPERCALL;
166 sysctl->interface_version = XEN_SYSCTL_INTERFACE_VERSION;
168 hypercall.op = __HYPERVISOR_sysctl;
169 hypercall.arg[0] = (unsigned long)sysctl;
171 if ( lock_pages(sysctl, sizeof(*sysctl)) != 0 )
172 {
173 PERROR("Could not lock memory for Xen hypercall");
174 goto out1;
175 }
177 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
178 {
179 if ( errno == EACCES )
180 DPRINTF("sysctl operation failed -- need to"
181 " rebuild the user-space tool set?\n");
182 }
184 unlock_pages(sysctl, sizeof(*sysctl));
186 out1:
187 return ret;
188 }
190 void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
191 size_t size, int prot, size_t chunksize,
192 privcmd_mmap_entry_t entries[], int nentries);
194 void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
195 void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
197 /* Optionally flush file to disk and discard page cache */
198 void discard_file_cache(int fd, int flush);
200 #define MAX_MMU_UPDATES 1024
201 struct xc_mmu {
202 mmu_update_t updates[MAX_MMU_UPDATES];
203 int idx;
204 domid_t subject;
205 };
206 /* Structure returned by xc_alloc_mmu_updates must be free()'ed by caller. */
207 struct xc_mmu *xc_alloc_mmu_updates(int xc_handle, domid_t dom);
208 int xc_add_mmu_update(int xc_handle, struct xc_mmu *mmu,
209 unsigned long long ptr, unsigned long long val);
210 int xc_flush_mmu_updates(int xc_handle, struct xc_mmu *mmu);
212 /* Return 0 on success; -1 on error. */
213 int read_exact(int fd, void *data, size_t size);
214 int write_exact(int fd, const void *data, size_t size);
216 int xc_ffs8(uint8_t x);
217 int xc_ffs16(uint16_t x);
218 int xc_ffs32(uint32_t x);
219 int xc_ffs64(uint64_t x);
221 #endif /* __XC_PRIVATE_H__ */