ia64/xen-unstable

view xen/include/xsm/xsm.h @ 18394:dade7f0bdc8d

hvm: Use main memory for video memory.

When creating an HVM domain, if e.g. another domain is created before
qemu allocates video memory, the extra 8MB memory ballooning is not
available any more, because it got consumed by the other domain.

This fixes it by taking video memory from the main memory:

- make hvmloader use e820_malloc to reserve some of the main memory
and notify ioemu of its address through the Xen platform PCI card.
- add XENMAPSPACE_mfn to the xen_add_to_physmap memory op, to allow
ioemu to move the MFNs between the original position and the PCI
mapping, when LFB acceleration is disabled/enabled
- add a remove_from_physmap memory op, to allow ioemu to unmap it
completely for the case of old guests with acceleration disabled.
- add xc_domain_memory_translate_gpfn_list to libxc to allow ioemu to
get the MFNs of the video memory.
- have xend save the PCI memory space instead of ioemu: if a memory
page is there, the guest can access it like usual memory, so xend
can safely be responsible to save it. The extra benefit is that
live migration will apply the logdirty optimization there too.
- handle old saved images, populating the video memory from ioemu if
really needed.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Aug 27 14:53:39 2008 +0100 (2008-08-27)
parents 217c8b6ebfab
children 44f039c4aee4
line source
1 /*
2 * This file contains the XSM hook definitions for Xen.
3 *
4 * This work is based on the LSM implementation in Linux 2.6.13.4.
5 *
6 * Author: George Coker, <gscoker@alpha.ncsc.mil>
7 *
8 * Contributors: Michael LeMay, <mdlemay@epoch.ncsc.mil>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 */
15 #ifndef __XSM_H__
16 #define __XSM_H__
18 #include <xen/sched.h>
19 #include <xen/multiboot.h>
21 typedef void xsm_op_t;
22 DEFINE_XEN_GUEST_HANDLE(xsm_op_t);
24 extern long do_xsm_op (XEN_GUEST_HANDLE(xsm_op_t) op);
26 #ifdef XSM_ENABLE
27 #define xsm_call(fn) xsm_ops->fn
28 #else
29 #define xsm_call(fn) 0
30 #endif
32 /* policy magic number (defined by XSM_MAGIC) */
33 typedef u32 xsm_magic_t;
34 #ifndef XSM_MAGIC
35 #define XSM_MAGIC 0x00000000
36 #endif
38 #ifdef XSM_ENABLE
40 extern char *policy_buffer;
41 extern u32 policy_size;
43 typedef int (*xsm_initcall_t)(void);
45 extern xsm_initcall_t __xsm_initcall_start[], __xsm_initcall_end[];
47 #define xsm_initcall(fn) \
48 static xsm_initcall_t __initcall_##fn \
49 __attribute_used__ __attribute__((__section__(".xsm_initcall.init"))) = fn
51 struct xsm_operations {
52 void (*security_domaininfo) (struct domain *d,
53 struct xen_domctl_getdomaininfo *info);
54 int (*setvcpucontext) (struct domain *d);
55 int (*pausedomain) (struct domain *d);
56 int (*unpausedomain) (struct domain *d);
57 int (*resumedomain) (struct domain *d);
58 int (*domain_create) (struct domain *d, u32 ssidref);
59 int (*max_vcpus) (struct domain *d);
60 int (*destroydomain) (struct domain *d);
61 int (*vcpuaffinity) (int cmd, struct domain *d);
62 int (*scheduler) (struct domain *d);
63 int (*getdomaininfo) (struct domain *d);
64 int (*getvcpucontext) (struct domain *d);
65 int (*getvcpuinfo) (struct domain *d);
66 int (*domain_settime) (struct domain *d);
67 int (*tbufcontrol) (void);
68 int (*readconsole) (uint32_t clear);
69 int (*sched_id) (void);
70 int (*setdomainmaxmem) (struct domain *d);
71 int (*setdomainhandle) (struct domain *d);
72 int (*setdebugging) (struct domain *d);
73 int (*irq_permission) (struct domain *d, uint8_t pirq, uint8_t access);
74 int (*iomem_permission) (struct domain *d, unsigned long mfn,
75 uint8_t access);
76 int (*perfcontrol) (void);
78 int (*evtchn_unbound) (struct domain *d, struct evtchn *chn, domid_t id2);
79 int (*evtchn_interdomain) (struct domain *d1, struct evtchn *chn1,
80 struct domain *d2, struct evtchn *chn2);
81 void (*evtchn_close_post) (struct evtchn *chn);
82 int (*evtchn_send) (struct domain *d, struct evtchn *chn);
83 int (*evtchn_status) (struct domain *d, struct evtchn *chn);
84 int (*evtchn_reset) (struct domain *d1, struct domain *d2);
86 int (*grant_mapref) (struct domain *d1, struct domain *d2, uint32_t flags);
87 int (*grant_unmapref) (struct domain *d1, struct domain *d2);
88 int (*grant_setup) (struct domain *d1, struct domain *d2);
89 int (*grant_transfer) (struct domain *d1, struct domain *d2);
90 int (*grant_copy) (struct domain *d1, struct domain *d2);
91 int (*grant_query_size) (struct domain *d1, struct domain *d2);
93 int (*alloc_security_domain) (struct domain *d);
94 void (*free_security_domain) (struct domain *d);
95 int (*alloc_security_evtchn) (struct evtchn *chn);
96 void (*free_security_evtchn) (struct evtchn *chn);
98 int (*translate_gpfn_list) (struct domain *d, unsigned long mfn);
99 int (*memory_adjust_reservation) (struct domain *d1, struct domain *d2);
100 int (*memory_stat_reservation) (struct domain *d1, struct domain *d2);
101 int (*memory_pin_page) (struct domain *d, struct page_info *page);
103 int (*console_io) (struct domain *d, int cmd);
105 int (*profile) (struct domain *d, int op);
107 int (*kexec) (void);
108 int (*schedop_shutdown) (struct domain *d1, struct domain *d2);
110 long (*__do_xsm_op) (XEN_GUEST_HANDLE(xsm_op_t) op);
112 #ifdef CONFIG_X86
113 int (*shadow_control) (struct domain *d, uint32_t op);
114 int (*ioport_permission) (struct domain *d, uint32_t ioport,
115 uint8_t access);
116 int (*getpageframeinfo) (struct page_info *page);
117 int (*getmemlist) (struct domain *d);
118 int (*hypercall_init) (struct domain *d);
119 int (*hvmcontext) (struct domain *d, uint32_t op);
120 int (*address_size) (struct domain *d, uint32_t op);
121 int (*machine_address_size) (struct domain *d, uint32_t op);
122 int (*hvm_param) (struct domain *d, unsigned long op);
123 int (*hvm_set_pci_intx_level) (struct domain *d);
124 int (*hvm_set_isa_irq_level) (struct domain *d);
125 int (*hvm_set_pci_link_route) (struct domain *d);
126 int (*apic) (struct domain *d, int cmd);
127 int (*assign_vector) (struct domain *d, uint32_t pirq);
128 int (*xen_settime) (void);
129 int (*memtype) (uint32_t access);
130 int (*microcode) (void);
131 int (*physinfo) (void);
132 int (*platform_quirk) (uint32_t);
133 int (*machine_memory_map) (void);
134 int (*domain_memory_map) (struct domain *d);
135 int (*mmu_normal_update) (struct domain *d, intpte_t fpte);
136 int (*mmu_machphys_update) (struct domain *d, unsigned long mfn);
137 int (*update_va_mapping) (struct domain *d, l1_pgentry_t pte);
138 int (*add_to_physmap) (struct domain *d1, struct domain *d2);
139 int (*remove_from_physmap) (struct domain *d1, struct domain *d2);
140 #endif
141 };
143 #endif
145 extern struct xsm_operations *xsm_ops;
147 static inline void xsm_security_domaininfo (struct domain *d,
148 struct xen_domctl_getdomaininfo *info)
149 {
150 xsm_call(security_domaininfo(d, info));
151 }
153 static inline int xsm_setvcpucontext(struct domain *d)
154 {
155 return xsm_call(setvcpucontext(d));
156 }
158 static inline int xsm_pausedomain (struct domain *d)
159 {
160 return xsm_call(pausedomain(d));
161 }
163 static inline int xsm_unpausedomain (struct domain *d)
164 {
165 return xsm_call(unpausedomain(d));
166 }
168 static inline int xsm_resumedomain (struct domain *d)
169 {
170 return xsm_call(resumedomain(d));
171 }
173 static inline int xsm_domain_create (struct domain *d, u32 ssidref)
174 {
175 return xsm_call(domain_create(d, ssidref));
176 }
178 static inline int xsm_max_vcpus(struct domain *d)
179 {
180 return xsm_call(max_vcpus(d));
181 }
183 static inline int xsm_destroydomain (struct domain *d)
184 {
185 return xsm_call(destroydomain(d));
186 }
188 static inline int xsm_vcpuaffinity (int cmd, struct domain *d)
189 {
190 return xsm_call(vcpuaffinity(cmd, d));
191 }
193 static inline int xsm_scheduler (struct domain *d)
194 {
195 return xsm_call(scheduler(d));
196 }
198 static inline int xsm_getdomaininfo (struct domain *d)
199 {
200 return xsm_call(getdomaininfo(d));
201 }
203 static inline int xsm_getvcpucontext (struct domain *d)
204 {
205 return xsm_call(getvcpucontext(d));
206 }
208 static inline int xsm_getvcpuinfo (struct domain *d)
209 {
210 return xsm_call(getvcpuinfo(d));
211 }
213 static inline int xsm_domain_settime (struct domain *d)
214 {
215 return xsm_call(domain_settime(d));
216 }
218 static inline int xsm_tbufcontrol (void)
219 {
220 return xsm_call(tbufcontrol());
221 }
223 static inline int xsm_readconsole (uint32_t clear)
224 {
225 return xsm_call(readconsole(clear));
226 }
228 static inline int xsm_sched_id (void)
229 {
230 return xsm_call(sched_id());
231 }
233 static inline int xsm_setdomainmaxmem (struct domain *d)
234 {
235 return xsm_call(setdomainmaxmem(d));
236 }
238 static inline int xsm_setdomainhandle (struct domain *d)
239 {
240 return xsm_call(setdomainhandle(d));
241 }
243 static inline int xsm_setdebugging (struct domain *d)
244 {
245 return xsm_call(setdebugging(d));
246 }
248 static inline int xsm_irq_permission (struct domain *d, uint8_t pirq,
249 uint8_t access)
250 {
251 return xsm_call(irq_permission(d, pirq, access));
252 }
254 static inline int xsm_iomem_permission (struct domain *d, unsigned long mfn,
255 uint8_t access)
256 {
257 return xsm_call(iomem_permission(d, mfn, access));
258 }
260 static inline int xsm_perfcontrol (void)
261 {
262 return xsm_call(perfcontrol());
263 }
265 static inline int xsm_evtchn_unbound (struct domain *d1, struct evtchn *chn,
266 domid_t id2)
267 {
268 return xsm_call(evtchn_unbound(d1, chn, id2));
269 }
271 static inline int xsm_evtchn_interdomain (struct domain *d1,
272 struct evtchn *chan1, struct domain *d2, struct evtchn *chan2)
273 {
274 return xsm_call(evtchn_interdomain(d1, chan1, d2, chan2));
275 }
277 static inline void xsm_evtchn_close_post (struct evtchn *chn)
278 {
279 xsm_call(evtchn_close_post(chn));
280 }
282 static inline int xsm_evtchn_send (struct domain *d, struct evtchn *chn)
283 {
284 return xsm_call(evtchn_send(d, chn));
285 }
287 static inline int xsm_evtchn_status (struct domain *d, struct evtchn *chn)
288 {
289 return xsm_call(evtchn_status(d, chn));
290 }
292 static inline int xsm_evtchn_reset (struct domain *d1, struct domain *d2)
293 {
294 return xsm_call(evtchn_reset(d1, d2));
295 }
297 static inline int xsm_grant_mapref (struct domain *d1, struct domain *d2,
298 uint32_t flags)
299 {
300 return xsm_call(grant_mapref(d1, d2, flags));
301 }
303 static inline int xsm_grant_unmapref (struct domain *d1, struct domain *d2)
304 {
305 return xsm_call(grant_unmapref(d1, d2));
306 }
308 static inline int xsm_grant_setup (struct domain *d1, struct domain *d2)
309 {
310 return xsm_call(grant_setup(d1, d2));
311 }
313 static inline int xsm_grant_transfer (struct domain *d1, struct domain *d2)
314 {
315 return xsm_call(grant_transfer(d1, d2));
316 }
318 static inline int xsm_grant_copy (struct domain *d1, struct domain *d2)
319 {
320 return xsm_call(grant_copy(d1, d2));
321 }
323 static inline int xsm_grant_query_size (struct domain *d1, struct domain *d2)
324 {
325 return xsm_call(grant_query_size(d1, d2));
326 }
328 static inline int xsm_alloc_security_domain (struct domain *d)
329 {
330 return xsm_call(alloc_security_domain(d));
331 }
333 static inline void xsm_free_security_domain (struct domain *d)
334 {
335 xsm_call(free_security_domain(d));
336 }
338 static inline int xsm_alloc_security_evtchn (struct evtchn *chn)
339 {
340 return xsm_call(alloc_security_evtchn(chn));
341 }
343 static inline void xsm_free_security_evtchn (struct evtchn *chn)
344 {
345 xsm_call(free_security_evtchn(chn));
346 }
348 static inline int xsm_translate_gpfn_list (struct domain *d, unsigned long mfn)
349 {
350 return xsm_call(translate_gpfn_list(d, mfn));
351 }
353 static inline int xsm_memory_adjust_reservation (struct domain *d1, struct
354 domain *d2)
355 {
356 return xsm_call(memory_adjust_reservation(d1, d2));
357 }
359 static inline int xsm_memory_stat_reservation (struct domain *d1,
360 struct domain *d2)
361 {
362 return xsm_call(memory_stat_reservation(d1, d2));
363 }
365 static inline int xsm_memory_pin_page(struct domain *d, struct page_info *page)
366 {
367 return xsm_call(memory_pin_page(d, page));
368 }
370 static inline int xsm_console_io (struct domain *d, int cmd)
371 {
372 return xsm_call(console_io(d, cmd));
373 }
375 static inline int xsm_profile (struct domain *d, int op)
376 {
377 return xsm_call(profile(d, op));
378 }
380 static inline int xsm_kexec (void)
381 {
382 return xsm_call(kexec());
383 }
385 static inline int xsm_schedop_shutdown (struct domain *d1, struct domain *d2)
386 {
387 return xsm_call(schedop_shutdown(d1, d2));
388 }
390 static inline long __do_xsm_op (XEN_GUEST_HANDLE(xsm_op_t) op)
391 {
392 return xsm_call(__do_xsm_op(op));
393 }
395 #ifdef XSM_ENABLE
396 extern int xsm_init(unsigned int *initrdidx, const multiboot_info_t *mbi,
397 unsigned long initial_images_start);
398 extern int xsm_policy_init(unsigned int *initrdidx, const multiboot_info_t *mbi,
399 unsigned long initial_images_start);
400 extern int register_xsm(struct xsm_operations *ops);
401 extern int unregister_xsm(struct xsm_operations *ops);
402 #else
403 static inline int xsm_init (unsigned int *initrdidx,
404 const multiboot_info_t *mbi, unsigned long initial_images_start)
405 {
406 return 0;
407 }
408 #endif
410 #ifdef CONFIG_X86
411 static inline int xsm_shadow_control (struct domain *d, uint32_t op)
412 {
413 return xsm_call(shadow_control(d, op));
414 }
416 static inline int xsm_ioport_permission (struct domain *d, uint32_t ioport,
417 uint8_t access)
418 {
419 return xsm_call(ioport_permission(d, ioport, access));
420 }
422 static inline int xsm_getpageframeinfo (struct page_info *page)
423 {
424 return xsm_call(getpageframeinfo(page));
425 }
427 static inline int xsm_getmemlist (struct domain *d)
428 {
429 return xsm_call(getmemlist(d));
430 }
432 static inline int xsm_hypercall_init (struct domain *d)
433 {
434 return xsm_call(hypercall_init(d));
435 }
437 static inline int xsm_hvmcontext (struct domain *d, uint32_t cmd)
438 {
439 return xsm_call(hvmcontext(d, cmd));
440 }
442 static inline int xsm_address_size (struct domain *d, uint32_t cmd)
443 {
444 return xsm_call(address_size(d, cmd));
445 }
447 static inline int xsm_machine_address_size (struct domain *d, uint32_t cmd)
448 {
449 return xsm_call(machine_address_size(d, cmd));
450 }
452 static inline int xsm_hvm_param (struct domain *d, unsigned long op)
453 {
454 return xsm_call(hvm_param(d, op));
455 }
457 static inline int xsm_hvm_set_pci_intx_level (struct domain *d)
458 {
459 return xsm_call(hvm_set_pci_intx_level(d));
460 }
462 static inline int xsm_hvm_set_isa_irq_level (struct domain *d)
463 {
464 return xsm_call(hvm_set_isa_irq_level(d));
465 }
467 static inline int xsm_hvm_set_pci_link_route (struct domain *d)
468 {
469 return xsm_call(hvm_set_pci_link_route(d));
470 }
472 static inline int xsm_apic (struct domain *d, int cmd)
473 {
474 return xsm_call(apic(d, cmd));
475 }
477 static inline int xsm_assign_vector (struct domain *d, uint32_t pirq)
478 {
479 return xsm_call(assign_vector(d, pirq));
480 }
482 static inline int xsm_xen_settime (void)
483 {
484 return xsm_call(xen_settime());
485 }
487 static inline int xsm_memtype (uint32_t access)
488 {
489 return xsm_call(memtype(access));
490 }
492 static inline int xsm_microcode (void)
493 {
494 return xsm_call(microcode());
495 }
497 static inline int xsm_physinfo (void)
498 {
499 return xsm_call(physinfo());
500 }
502 static inline int xsm_platform_quirk (uint32_t quirk)
503 {
504 return xsm_call(platform_quirk(quirk));
505 }
507 static inline int xsm_machine_memory_map(void)
508 {
509 return xsm_call(machine_memory_map());
510 }
512 static inline int xsm_domain_memory_map(struct domain *d)
513 {
514 return xsm_call(domain_memory_map(d));
515 }
517 static inline int xsm_mmu_normal_update (struct domain *d, intpte_t fpte)
518 {
519 return xsm_call(mmu_normal_update(d, fpte));
520 }
522 static inline int xsm_mmu_machphys_update (struct domain *d, unsigned long mfn)
523 {
524 return xsm_call(mmu_machphys_update(d, mfn));
525 }
527 static inline int xsm_update_va_mapping(struct domain *d, l1_pgentry_t pte)
528 {
529 return xsm_call(update_va_mapping(d, pte));
530 }
532 static inline int xsm_add_to_physmap(struct domain *d1, struct domain *d2)
533 {
534 return xsm_call(add_to_physmap(d1, d2));
535 }
537 static inline int xsm_remove_from_physmap(struct domain *d1, struct domain *d2)
538 {
539 return xsm_call(remove_from_physmap(d1, d2));
540 }
541 #endif /* CONFIG_X86 */
543 #endif /* __XSM_H */