ia64/xen-unstable

view xen/include/xsm/xsm.h @ 16508:d2bef6551c12

xsm: Consolidate xsm processing within domain control hypercall.

Consolidate all the 15 xsm calls from within do_domctl a single
routine that is only called in one place, xsm_domctl:

int xsm_domctl (struct xen_domctl *domctl);

The parameter to domctl is a pointer to the xen_domctl structure that
contains a union of all sub operational parameters.

The benefits of this patch include:

(1) Easier to maintain because there is one place in the entire
hypercall to check with the xsm, instead of 15 or more.

(2) New sub-operations don't also need to add a corresponding xsm
function.

(3) Removes 178 lines of code.

(4) Enhanced security because of 1-4.

Signed-off-by: Mike D. Day <ncmike@us.ibm.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Dec 04 10:25:35 2007 +0000 (2007-12-04)
parents 453f87d6e7f0
children a583f3a7eafc
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 (*domctl) (struct xen_domctl *domctl);
55 int (*domain_create) (struct domain *d, u32 ssidref);
56 int (*getdomaininfo) (struct domain *d);
57 int (*tbufcontrol) (void);
58 int (*readconsole) (uint32_t clear);
59 int (*sched_id) (void);
60 int (*perfcontrol) (void);
62 int (*evtchn_unbound) (struct domain *d, struct evtchn *chn, domid_t id2);
63 int (*evtchn_interdomain) (struct domain *d1, struct evtchn *chn1,
64 struct domain *d2, struct evtchn *chn2);
65 void (*evtchn_close_post) (struct evtchn *chn);
66 int (*evtchn_send) (struct domain *d, struct evtchn *chn);
67 int (*evtchn_status) (struct domain *d, struct evtchn *chn);
68 int (*evtchn_reset) (struct domain *d1, struct domain *d2);
70 int (*grant_mapref) (struct domain *d1, struct domain *d2, uint32_t flags);
71 int (*grant_unmapref) (struct domain *d1, struct domain *d2);
72 int (*grant_setup) (struct domain *d1, struct domain *d2);
73 int (*grant_transfer) (struct domain *d1, struct domain *d2);
74 int (*grant_copy) (struct domain *d1, struct domain *d2);
75 int (*grant_query_size) (struct domain *d1, struct domain *d2);
77 int (*alloc_security_domain) (struct domain *d);
78 void (*free_security_domain) (struct domain *d);
79 int (*alloc_security_evtchn) (struct evtchn *chn);
80 void (*free_security_evtchn) (struct evtchn *chn);
82 int (*translate_gpfn_list) (struct domain *d, unsigned long mfn);
83 int (*memory_adjust_reservation) (struct domain *d1, struct domain *d2);
84 int (*memory_stat_reservation) (struct domain *d1, struct domain *d2);
85 int (*memory_pin_page) (struct domain *d, struct page_info *page);
87 int (*console_io) (struct domain *d, int cmd);
89 int (*profile) (struct domain *d, int op);
91 int (*kexec) (void);
92 int (*schedop_shutdown) (struct domain *d1, struct domain *d2);
94 long (*__do_xsm_op) (XEN_GUEST_HANDLE(xsm_op_t) op);
95 void (*complete_init) (struct domain *d);
97 #ifdef CONFIG_X86
98 int (*shadow_control) (struct domain *d, uint32_t op);
99 int (*ioport_permission) (struct domain *d, uint32_t ioport,
100 uint8_t access);
101 int (*getpageframeinfo) (struct page_info *page);
102 int (*getmemlist) (struct domain *d);
103 int (*hypercall_init) (struct domain *d);
104 int (*hvmcontext) (struct domain *d, uint32_t op);
105 int (*address_size) (struct domain *d, uint32_t op);
106 int (*hvm_param) (struct domain *d, unsigned long op);
107 int (*hvm_set_pci_intx_level) (struct domain *d);
108 int (*hvm_set_isa_irq_level) (struct domain *d);
109 int (*hvm_set_pci_link_route) (struct domain *d);
110 int (*apic) (struct domain *d, int cmd);
111 int (*assign_vector) (struct domain *d, uint32_t pirq);
112 int (*xen_settime) (void);
113 int (*memtype) (uint32_t access);
114 int (*microcode) (void);
115 int (*physinfo) (void);
116 int (*platform_quirk) (uint32_t);
117 int (*machine_memory_map) (void);
118 int (*domain_memory_map) (struct domain *d);
119 int (*mmu_normal_update) (struct domain *d, intpte_t fpte);
120 int (*mmu_machphys_update) (struct domain *d, unsigned long mfn);
121 int (*update_va_mapping) (struct domain *d, l1_pgentry_t pte);
122 int (*add_to_physmap) (struct domain *d1, struct domain *d2);
123 #endif
124 };
126 #endif
128 extern struct xsm_operations *xsm_ops;
130 static inline void xsm_security_domaininfo (struct domain *d,
131 struct xen_domctl_getdomaininfo *info)
132 {
133 xsm_call(security_domaininfo(d, info));
134 }
136 static inline int xsm_domctl(struct xen_domctl *domctl)
137 {
138 return xsm_call(domctl(domctl));
139 }
141 static inline int xsm_domain_create(struct domain *d, u32 ssidref)
142 {
143 return xsm_call(domain_create(d, ssidref));
144 }
146 static inline int xsm_getdomaininfo(struct domain *d)
147 {
148 return xsm_call(domain_getdomaininfo(d));
149 }
151 static inline int xsm_tbufcontrol (void)
152 {
153 return xsm_call(tbufcontrol());
154 }
156 static inline int xsm_readconsole (uint32_t clear)
157 {
158 return xsm_call(readconsole(clear));
159 }
161 static inline int xsm_sched_id (void)
162 {
163 return xsm_call(sched_id());
164 }
166 static inline int xsm_perfcontrol (void)
167 {
168 return xsm_call(perfcontrol());
169 }
171 static inline int xsm_evtchn_unbound (struct domain *d1, struct evtchn *chn,
172 domid_t id2)
173 {
174 return xsm_call(evtchn_unbound(d1, chn, id2));
175 }
177 static inline int xsm_evtchn_interdomain (struct domain *d1,
178 struct evtchn *chan1, struct domain *d2, struct evtchn *chan2)
179 {
180 return xsm_call(evtchn_interdomain(d1, chan1, d2, chan2));
181 }
183 static inline void xsm_evtchn_close_post (struct evtchn *chn)
184 {
185 xsm_call(evtchn_close_post(chn));
186 }
188 static inline int xsm_evtchn_send (struct domain *d, struct evtchn *chn)
189 {
190 return xsm_call(evtchn_send(d, chn));
191 }
193 static inline int xsm_evtchn_status (struct domain *d, struct evtchn *chn)
194 {
195 return xsm_call(evtchn_status(d, chn));
196 }
198 static inline int xsm_evtchn_reset (struct domain *d1, struct domain *d2)
199 {
200 return xsm_call(evtchn_reset(d1, d2));
201 }
203 static inline int xsm_grant_mapref (struct domain *d1, struct domain *d2,
204 uint32_t flags)
205 {
206 return xsm_call(grant_mapref(d1, d2, flags));
207 }
209 static inline int xsm_grant_unmapref (struct domain *d1, struct domain *d2)
210 {
211 return xsm_call(grant_unmapref(d1, d2));
212 }
214 static inline int xsm_grant_setup (struct domain *d1, struct domain *d2)
215 {
216 return xsm_call(grant_setup(d1, d2));
217 }
219 static inline int xsm_grant_transfer (struct domain *d1, struct domain *d2)
220 {
221 return xsm_call(grant_transfer(d1, d2));
222 }
224 static inline int xsm_grant_copy (struct domain *d1, struct domain *d2)
225 {
226 return xsm_call(grant_copy(d1, d2));
227 }
229 static inline int xsm_grant_query_size (struct domain *d1, struct domain *d2)
230 {
231 return xsm_call(grant_query_size(d1, d2));
232 }
234 static inline int xsm_alloc_security_domain (struct domain *d)
235 {
236 return xsm_call(alloc_security_domain(d));
237 }
239 static inline void xsm_free_security_domain (struct domain *d)
240 {
241 xsm_call(free_security_domain(d));
242 }
244 static inline int xsm_alloc_security_evtchn (struct evtchn *chn)
245 {
246 return xsm_call(alloc_security_evtchn(chn));
247 }
249 static inline void xsm_free_security_evtchn (struct evtchn *chn)
250 {
251 xsm_call(free_security_evtchn(chn));
252 }
254 static inline int xsm_translate_gpfn_list (struct domain *d, unsigned long mfn)
255 {
256 return xsm_call(translate_gpfn_list(d, mfn));
257 }
259 static inline int xsm_memory_adjust_reservation (struct domain *d1, struct
260 domain *d2)
261 {
262 return xsm_call(memory_adjust_reservation(d1, d2));
263 }
265 static inline int xsm_memory_stat_reservation (struct domain *d1,
266 struct domain *d2)
267 {
268 return xsm_call(memory_stat_reservation(d1, d2));
269 }
271 static inline int xsm_memory_pin_page(struct domain *d, struct page_info *page)
272 {
273 return xsm_call(memory_pin_page(d, page));
274 }
276 static inline int xsm_console_io (struct domain *d, int cmd)
277 {
278 return xsm_call(console_io(d, cmd));
279 }
281 static inline int xsm_profile (struct domain *d, int op)
282 {
283 return xsm_call(profile(d, op));
284 }
286 static inline int xsm_kexec (void)
287 {
288 return xsm_call(kexec());
289 }
291 static inline int xsm_schedop_shutdown (struct domain *d1, struct domain *d2)
292 {
293 return xsm_call(schedop_shutdown(d1, d2));
294 }
296 static inline long __do_xsm_op (XEN_GUEST_HANDLE(xsm_op_t) op)
297 {
298 return xsm_call(__do_xsm_op(op));
299 }
301 static inline void xsm_complete_init (struct domain *d)
302 {
303 xsm_call(complete_init(d));
304 }
306 #ifdef XSM_ENABLE
307 extern int xsm_init(unsigned int *initrdidx, const multiboot_info_t *mbi,
308 unsigned long initial_images_start);
309 extern int xsm_policy_init(unsigned int *initrdidx, const multiboot_info_t *mbi,
310 unsigned long initial_images_start);
311 extern int register_xsm(struct xsm_operations *ops);
312 extern int unregister_xsm(struct xsm_operations *ops);
313 #else
314 static inline int xsm_init (unsigned int *initrdidx,
315 const multiboot_info_t *mbi, unsigned long initial_images_start)
316 {
317 return 0;
318 }
319 #endif
321 #ifdef CONFIG_X86
322 static inline int xsm_shadow_control (struct domain *d, uint32_t op)
323 {
324 return xsm_call(shadow_control(d, op));
325 }
327 static inline int xsm_ioport_permission (struct domain *d, uint32_t ioport,
328 uint8_t access)
329 {
330 return xsm_call(ioport_permission(d, ioport, access));
331 }
333 static inline int xsm_getpageframeinfo (struct page_info *page)
334 {
335 return xsm_call(getpageframeinfo(page));
336 }
338 static inline int xsm_getmemlist (struct domain *d)
339 {
340 return xsm_call(getmemlist(d));
341 }
343 static inline int xsm_hypercall_init (struct domain *d)
344 {
345 return xsm_call(hypercall_init(d));
346 }
348 static inline int xsm_hvmcontext (struct domain *d, uint32_t cmd)
349 {
350 return xsm_call(hvmcontext(d, cmd));
351 }
353 static inline int xsm_address_size (struct domain *d, uint32_t cmd)
354 {
355 return xsm_call(address_size(d, cmd));
356 }
358 static inline int xsm_hvm_param (struct domain *d, unsigned long op)
359 {
360 return xsm_call(hvm_param(d, op));
361 }
363 static inline int xsm_hvm_set_pci_intx_level (struct domain *d)
364 {
365 return xsm_call(hvm_set_pci_intx_level(d));
366 }
368 static inline int xsm_hvm_set_isa_irq_level (struct domain *d)
369 {
370 return xsm_call(hvm_set_isa_irq_level(d));
371 }
373 static inline int xsm_hvm_set_pci_link_route (struct domain *d)
374 {
375 return xsm_call(hvm_set_pci_link_route(d));
376 }
378 static inline int xsm_apic (struct domain *d, int cmd)
379 {
380 return xsm_call(apic(d, cmd));
381 }
383 static inline int xsm_assign_vector (struct domain *d, uint32_t pirq)
384 {
385 return xsm_call(assign_vector(d, pirq));
386 }
388 static inline int xsm_xen_settime (void)
389 {
390 return xsm_call(xen_settime());
391 }
393 static inline int xsm_memtype (uint32_t access)
394 {
395 return xsm_call(memtype(access));
396 }
398 static inline int xsm_microcode (void)
399 {
400 return xsm_call(microcode());
401 }
403 static inline int xsm_physinfo (void)
404 {
405 return xsm_call(physinfo());
406 }
408 static inline int xsm_platform_quirk (uint32_t quirk)
409 {
410 return xsm_call(platform_quirk(quirk));
411 }
413 static inline int xsm_machine_memory_map(void)
414 {
415 return xsm_call(machine_memory_map());
416 }
418 static inline int xsm_domain_memory_map(struct domain *d)
419 {
420 return xsm_call(domain_memory_map(d));
421 }
423 static inline int xsm_mmu_normal_update (struct domain *d, intpte_t fpte)
424 {
425 return xsm_call(mmu_normal_update(d, fpte));
426 }
428 static inline int xsm_mmu_machphys_update (struct domain *d, unsigned long mfn)
429 {
430 return xsm_call(mmu_machphys_update(d, mfn));
431 }
433 static inline int xsm_update_va_mapping(struct domain *d, l1_pgentry_t pte)
434 {
435 return xsm_call(update_va_mapping(d, pte));
436 }
438 static inline int xsm_add_to_physmap(struct domain *d1, struct domain *d2)
439 {
440 return xsm_call(add_to_physmap(d1, d2));
441 }
442 #endif /* CONFIG_X86 */
444 #endif /* __XSM_H */