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  */
14 
15 #ifndef __XSM_H__
16 #define __XSM_H__
17 
18 #include <xen/sched.h>
19 #include <xen/multiboot.h>
20 
21 typedef void xsm_op_t;
22 DEFINE_XEN_GUEST_HANDLE(xsm_op_t);
23 
24 /* policy magic number (defined by XSM_MAGIC) */
25 typedef u32 xsm_magic_t;
26 
27 #ifdef CONFIG_FLASK
28 #define XSM_MAGIC 0xf97cff8c
29 #else
30 #define XSM_MAGIC 0x0
31 #endif
32 
33 /* These annotations are used by callers and in dummy.h to document the
34  * default actions of XSM hooks. They should be compiled out otherwise.
35  */
36 enum xsm_default {
37     XSM_HOOK,     /* Guests can normally access the hypercall */
38     XSM_DM_PRIV,  /* Device model can perform on its target domain */
39     XSM_TARGET,   /* Can perform on self or your target domain */
40     XSM_PRIV,     /* Privileged - normally restricted to dom0 */
41     XSM_XS_PRIV,  /* Xenstore domain - can do some privileged operations */
42     XSM_OTHER     /* Something more complex */
43 };
44 typedef enum xsm_default xsm_default_t;
45 
46 struct xsm_operations {
47     void (*security_domaininfo) (struct domain *d,
48                                         struct xen_domctl_getdomaininfo *info);
49     int (*domain_create) (struct domain *d, u32 ssidref);
50     int (*getdomaininfo) (struct domain *d);
51     int (*domctl_scheduler_op) (struct domain *d, int op);
52     int (*sysctl_scheduler_op) (int op);
53     int (*set_target) (struct domain *d, struct domain *e);
54     int (*domctl) (struct domain *d, int cmd);
55     int (*sysctl) (int cmd);
56     int (*readconsole) (uint32_t clear);
57 
58     int (*evtchn_unbound) (struct domain *d, struct evtchn *chn, domid_t id2);
59     int (*evtchn_interdomain) (struct domain *d1, struct evtchn *chn1,
60                                         struct domain *d2, struct evtchn *chn2);
61     void (*evtchn_close_post) (struct evtchn *chn);
62     int (*evtchn_send) (struct domain *d, struct evtchn *chn);
63     int (*evtchn_status) (struct domain *d, struct evtchn *chn);
64     int (*evtchn_reset) (struct domain *d1, struct domain *d2);
65 
66     int (*grant_mapref) (struct domain *d1, struct domain *d2, uint32_t flags);
67     int (*grant_unmapref) (struct domain *d1, struct domain *d2);
68     int (*grant_setup) (struct domain *d1, struct domain *d2);
69     int (*grant_transfer) (struct domain *d1, struct domain *d2);
70     int (*grant_copy) (struct domain *d1, struct domain *d2);
71     int (*grant_query_size) (struct domain *d1, struct domain *d2);
72 
73     int (*alloc_security_domain) (struct domain *d);
74     void (*free_security_domain) (struct domain *d);
75     int (*alloc_security_evtchn) (struct evtchn *chn);
76     void (*free_security_evtchn) (struct evtchn *chn);
77     char *(*show_security_evtchn) (struct domain *d, const struct evtchn *chn);
78     int (*init_hardware_domain) (struct domain *d);
79 
80     int (*get_pod_target) (struct domain *d);
81     int (*set_pod_target) (struct domain *d);
82     int (*memory_exchange) (struct domain *d);
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 *d1, struct domain *d2, struct page_info *page);
86     int (*add_to_physmap) (struct domain *d1, struct domain *d2);
87     int (*remove_from_physmap) (struct domain *d1, struct domain *d2);
88     int (*map_gmfn_foreign) (struct domain *d, struct domain *t);
89     int (*claim_pages) (struct domain *d);
90 
91     int (*console_io) (struct domain *d, int cmd);
92 
93     int (*profile) (struct domain *d, int op);
94 
95     int (*kexec) (void);
96     int (*schedop_shutdown) (struct domain *d1, struct domain *d2);
97 
98     char *(*show_irq_sid) (int irq);
99     int (*map_domain_pirq) (struct domain *d);
100     int (*map_domain_irq) (struct domain *d, int irq, void *data);
101     int (*unmap_domain_pirq) (struct domain *d);
102     int (*unmap_domain_irq) (struct domain *d, int irq, void *data);
103     int (*bind_pt_irq) (struct domain *d, struct xen_domctl_bind_pt_irq *bind);
104     int (*unbind_pt_irq) (struct domain *d, struct xen_domctl_bind_pt_irq *bind);
105     int (*irq_permission) (struct domain *d, int pirq, uint8_t allow);
106     int (*iomem_permission) (struct domain *d, uint64_t s, uint64_t e, uint8_t allow);
107     int (*iomem_mapping) (struct domain *d, uint64_t s, uint64_t e, uint8_t allow);
108     int (*pci_config_permission) (struct domain *d, uint32_t machine_bdf, uint16_t start, uint16_t end, uint8_t access);
109 
110 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_PCI)
111     int (*get_device_group) (uint32_t machine_bdf);
112     int (*assign_device) (struct domain *d, uint32_t machine_bdf);
113     int (*deassign_device) (struct domain *d, uint32_t machine_bdf);
114 #endif
115 
116 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE)
117     int (*assign_dtdevice) (struct domain *d, const char *dtpath);
118     int (*deassign_dtdevice) (struct domain *d, const char *dtpath);
119 #endif
120 
121     int (*resource_plug_core) (void);
122     int (*resource_unplug_core) (void);
123     int (*resource_plug_pci) (uint32_t machine_bdf);
124     int (*resource_unplug_pci) (uint32_t machine_bdf);
125     int (*resource_setup_pci) (uint32_t machine_bdf);
126     int (*resource_setup_gsi) (int gsi);
127     int (*resource_setup_misc) (void);
128 
129     int (*page_offline)(uint32_t cmd);
130     int (*tmem_op)(void);
131 
132     long (*do_xsm_op) (XEN_GUEST_HANDLE_PARAM(xsm_op_t) op);
133 #ifdef CONFIG_COMPAT
134     int (*do_compat_op) (XEN_GUEST_HANDLE_PARAM(xsm_op_t) op);
135 #endif
136 
137     int (*hvm_param) (struct domain *d, unsigned long op);
138     int (*hvm_control) (struct domain *d, unsigned long op);
139     int (*hvm_param_nested) (struct domain *d);
140     int (*hvm_param_altp2mhvm) (struct domain *d);
141     int (*hvm_altp2mhvm_op) (struct domain *d, uint64_t mode, uint32_t op);
142     int (*get_vnumainfo) (struct domain *d);
143 
144     int (*vm_event_control) (struct domain *d, int mode, int op);
145 
146 #ifdef CONFIG_HAS_MEM_ACCESS
147     int (*mem_access) (struct domain *d);
148 #endif
149 
150 #ifdef CONFIG_HAS_MEM_PAGING
151     int (*mem_paging) (struct domain *d);
152 #endif
153 
154 #ifdef CONFIG_HAS_MEM_SHARING
155     int (*mem_sharing) (struct domain *d);
156 #endif
157 
158     int (*platform_op) (uint32_t cmd);
159 
160 #ifdef CONFIG_X86
161     int (*do_mca) (void);
162     int (*shadow_control) (struct domain *d, uint32_t op);
163     int (*mem_sharing_op) (struct domain *d, struct domain *cd, int op);
164     int (*apic) (struct domain *d, int cmd);
165     int (*memtype) (uint32_t access);
166     int (*machine_memory_map) (void);
167     int (*domain_memory_map) (struct domain *d);
168 #define XSM_MMU_UPDATE_READ      1
169 #define XSM_MMU_UPDATE_WRITE     2
170 #define XSM_MMU_NORMAL_UPDATE    4
171 #define XSM_MMU_MACHPHYS_UPDATE  8
172     int (*mmu_update) (struct domain *d, struct domain *t,
173                        struct domain *f, uint32_t flags);
174     int (*mmuext_op) (struct domain *d, struct domain *f);
175     int (*update_va_mapping) (struct domain *d, struct domain *f, l1_pgentry_t pte);
176     int (*priv_mapping) (struct domain *d, struct domain *t);
177     int (*ioport_permission) (struct domain *d, uint32_t s, uint32_t e, uint8_t allow);
178     int (*ioport_mapping) (struct domain *d, uint32_t s, uint32_t e, uint8_t allow);
179     int (*pmu_op) (struct domain *d, unsigned int op);
180     int (*dm_op) (struct domain *d);
181 #endif
182     int (*xen_version) (uint32_t cmd);
183 };
184 
185 #ifdef CONFIG_XSM
186 
187 extern struct xsm_operations *xsm_ops;
188 
189 #ifndef XSM_NO_WRAPPERS
190 
xsm_security_domaininfo(struct domain * d,struct xen_domctl_getdomaininfo * info)191 static inline void xsm_security_domaininfo (struct domain *d,
192                                         struct xen_domctl_getdomaininfo *info)
193 {
194     xsm_ops->security_domaininfo(d, info);
195 }
196 
xsm_domain_create(xsm_default_t def,struct domain * d,u32 ssidref)197 static inline int xsm_domain_create (xsm_default_t def, struct domain *d, u32 ssidref)
198 {
199     return xsm_ops->domain_create(d, ssidref);
200 }
201 
xsm_getdomaininfo(xsm_default_t def,struct domain * d)202 static inline int xsm_getdomaininfo (xsm_default_t def, struct domain *d)
203 {
204     return xsm_ops->getdomaininfo(d);
205 }
206 
xsm_domctl_scheduler_op(xsm_default_t def,struct domain * d,int cmd)207 static inline int xsm_domctl_scheduler_op (xsm_default_t def, struct domain *d, int cmd)
208 {
209     return xsm_ops->domctl_scheduler_op(d, cmd);
210 }
211 
xsm_sysctl_scheduler_op(xsm_default_t def,int cmd)212 static inline int xsm_sysctl_scheduler_op (xsm_default_t def, int cmd)
213 {
214     return xsm_ops->sysctl_scheduler_op(cmd);
215 }
216 
xsm_set_target(xsm_default_t def,struct domain * d,struct domain * e)217 static inline int xsm_set_target (xsm_default_t def, struct domain *d, struct domain *e)
218 {
219     return xsm_ops->set_target(d, e);
220 }
221 
xsm_domctl(xsm_default_t def,struct domain * d,int cmd)222 static inline int xsm_domctl (xsm_default_t def, struct domain *d, int cmd)
223 {
224     return xsm_ops->domctl(d, cmd);
225 }
226 
xsm_sysctl(xsm_default_t def,int cmd)227 static inline int xsm_sysctl (xsm_default_t def, int cmd)
228 {
229     return xsm_ops->sysctl(cmd);
230 }
231 
xsm_readconsole(xsm_default_t def,uint32_t clear)232 static inline int xsm_readconsole (xsm_default_t def, uint32_t clear)
233 {
234     return xsm_ops->readconsole(clear);
235 }
236 
xsm_evtchn_unbound(xsm_default_t def,struct domain * d1,struct evtchn * chn,domid_t id2)237 static inline int xsm_evtchn_unbound (xsm_default_t def, struct domain *d1, struct evtchn *chn,
238                                                                     domid_t id2)
239 {
240     return xsm_ops->evtchn_unbound(d1, chn, id2);
241 }
242 
xsm_evtchn_interdomain(xsm_default_t def,struct domain * d1,struct evtchn * chan1,struct domain * d2,struct evtchn * chan2)243 static inline int xsm_evtchn_interdomain (xsm_default_t def, struct domain *d1,
244                 struct evtchn *chan1, struct domain *d2, struct evtchn *chan2)
245 {
246     return xsm_ops->evtchn_interdomain(d1, chan1, d2, chan2);
247 }
248 
xsm_evtchn_close_post(struct evtchn * chn)249 static inline void xsm_evtchn_close_post (struct evtchn *chn)
250 {
251     xsm_ops->evtchn_close_post(chn);
252 }
253 
xsm_evtchn_send(xsm_default_t def,struct domain * d,struct evtchn * chn)254 static inline int xsm_evtchn_send (xsm_default_t def, struct domain *d, struct evtchn *chn)
255 {
256     return xsm_ops->evtchn_send(d, chn);
257 }
258 
xsm_evtchn_status(xsm_default_t def,struct domain * d,struct evtchn * chn)259 static inline int xsm_evtchn_status (xsm_default_t def, struct domain *d, struct evtchn *chn)
260 {
261     return xsm_ops->evtchn_status(d, chn);
262 }
263 
xsm_evtchn_reset(xsm_default_t def,struct domain * d1,struct domain * d2)264 static inline int xsm_evtchn_reset (xsm_default_t def, struct domain *d1, struct domain *d2)
265 {
266     return xsm_ops->evtchn_reset(d1, d2);
267 }
268 
xsm_grant_mapref(xsm_default_t def,struct domain * d1,struct domain * d2,uint32_t flags)269 static inline int xsm_grant_mapref (xsm_default_t def, struct domain *d1, struct domain *d2,
270                                                                 uint32_t flags)
271 {
272     return xsm_ops->grant_mapref(d1, d2, flags);
273 }
274 
xsm_grant_unmapref(xsm_default_t def,struct domain * d1,struct domain * d2)275 static inline int xsm_grant_unmapref (xsm_default_t def, struct domain *d1, struct domain *d2)
276 {
277     return xsm_ops->grant_unmapref(d1, d2);
278 }
279 
xsm_grant_setup(xsm_default_t def,struct domain * d1,struct domain * d2)280 static inline int xsm_grant_setup (xsm_default_t def, struct domain *d1, struct domain *d2)
281 {
282     return xsm_ops->grant_setup(d1, d2);
283 }
284 
xsm_grant_transfer(xsm_default_t def,struct domain * d1,struct domain * d2)285 static inline int xsm_grant_transfer (xsm_default_t def, struct domain *d1, struct domain *d2)
286 {
287     return xsm_ops->grant_transfer(d1, d2);
288 }
289 
xsm_grant_copy(xsm_default_t def,struct domain * d1,struct domain * d2)290 static inline int xsm_grant_copy (xsm_default_t def, struct domain *d1, struct domain *d2)
291 {
292     return xsm_ops->grant_copy(d1, d2);
293 }
294 
xsm_grant_query_size(xsm_default_t def,struct domain * d1,struct domain * d2)295 static inline int xsm_grant_query_size (xsm_default_t def, struct domain *d1, struct domain *d2)
296 {
297     return xsm_ops->grant_query_size(d1, d2);
298 }
299 
xsm_alloc_security_domain(struct domain * d)300 static inline int xsm_alloc_security_domain (struct domain *d)
301 {
302     return xsm_ops->alloc_security_domain(d);
303 }
304 
xsm_free_security_domain(struct domain * d)305 static inline void xsm_free_security_domain (struct domain *d)
306 {
307     xsm_ops->free_security_domain(d);
308 }
309 
xsm_alloc_security_evtchn(struct evtchn * chn)310 static inline int xsm_alloc_security_evtchn (struct evtchn *chn)
311 {
312     return xsm_ops->alloc_security_evtchn(chn);
313 }
314 
xsm_free_security_evtchn(struct evtchn * chn)315 static inline void xsm_free_security_evtchn (struct evtchn *chn)
316 {
317     (void)xsm_ops->free_security_evtchn(chn);
318 }
319 
xsm_show_security_evtchn(struct domain * d,const struct evtchn * chn)320 static inline char *xsm_show_security_evtchn (struct domain *d, const struct evtchn *chn)
321 {
322     return xsm_ops->show_security_evtchn(d, chn);
323 }
324 
xsm_init_hardware_domain(xsm_default_t def,struct domain * d)325 static inline int xsm_init_hardware_domain (xsm_default_t def, struct domain *d)
326 {
327     return xsm_ops->init_hardware_domain(d);
328 }
329 
xsm_get_pod_target(xsm_default_t def,struct domain * d)330 static inline int xsm_get_pod_target (xsm_default_t def, struct domain *d)
331 {
332     return xsm_ops->get_pod_target(d);
333 }
334 
xsm_set_pod_target(xsm_default_t def,struct domain * d)335 static inline int xsm_set_pod_target (xsm_default_t def, struct domain *d)
336 {
337     return xsm_ops->set_pod_target(d);
338 }
339 
xsm_memory_exchange(xsm_default_t def,struct domain * d)340 static inline int xsm_memory_exchange (xsm_default_t def, struct domain *d)
341 {
342     return xsm_ops->memory_exchange(d);
343 }
344 
xsm_memory_adjust_reservation(xsm_default_t def,struct domain * d1,struct domain * d2)345 static inline int xsm_memory_adjust_reservation (xsm_default_t def, struct domain *d1, struct
346                                                                     domain *d2)
347 {
348     return xsm_ops->memory_adjust_reservation(d1, d2);
349 }
350 
xsm_memory_stat_reservation(xsm_default_t def,struct domain * d1,struct domain * d2)351 static inline int xsm_memory_stat_reservation (xsm_default_t def, struct domain *d1,
352                                                             struct domain *d2)
353 {
354     return xsm_ops->memory_stat_reservation(d1, d2);
355 }
356 
xsm_memory_pin_page(xsm_default_t def,struct domain * d1,struct domain * d2,struct page_info * page)357 static inline int xsm_memory_pin_page(xsm_default_t def, struct domain *d1, struct domain *d2,
358                                       struct page_info *page)
359 {
360     return xsm_ops->memory_pin_page(d1, d2, page);
361 }
362 
xsm_add_to_physmap(xsm_default_t def,struct domain * d1,struct domain * d2)363 static inline int xsm_add_to_physmap(xsm_default_t def, struct domain *d1, struct domain *d2)
364 {
365     return xsm_ops->add_to_physmap(d1, d2);
366 }
367 
xsm_remove_from_physmap(xsm_default_t def,struct domain * d1,struct domain * d2)368 static inline int xsm_remove_from_physmap(xsm_default_t def, struct domain *d1, struct domain *d2)
369 {
370     return xsm_ops->remove_from_physmap(d1, d2);
371 }
372 
xsm_map_gmfn_foreign(xsm_default_t def,struct domain * d,struct domain * t)373 static inline int xsm_map_gmfn_foreign (xsm_default_t def, struct domain *d, struct domain *t)
374 {
375     return xsm_ops->map_gmfn_foreign(d, t);
376 }
377 
xsm_claim_pages(xsm_default_t def,struct domain * d)378 static inline int xsm_claim_pages(xsm_default_t def, struct domain *d)
379 {
380     return xsm_ops->claim_pages(d);
381 }
382 
xsm_console_io(xsm_default_t def,struct domain * d,int cmd)383 static inline int xsm_console_io (xsm_default_t def, struct domain *d, int cmd)
384 {
385     return xsm_ops->console_io(d, cmd);
386 }
387 
xsm_profile(xsm_default_t def,struct domain * d,int op)388 static inline int xsm_profile (xsm_default_t def, struct domain *d, int op)
389 {
390     return xsm_ops->profile(d, op);
391 }
392 
xsm_kexec(xsm_default_t def)393 static inline int xsm_kexec (xsm_default_t def)
394 {
395     return xsm_ops->kexec();
396 }
397 
xsm_schedop_shutdown(xsm_default_t def,struct domain * d1,struct domain * d2)398 static inline int xsm_schedop_shutdown (xsm_default_t def, struct domain *d1, struct domain *d2)
399 {
400     return xsm_ops->schedop_shutdown(d1, d2);
401 }
402 
xsm_show_irq_sid(int irq)403 static inline char *xsm_show_irq_sid (int irq)
404 {
405     return xsm_ops->show_irq_sid(irq);
406 }
407 
xsm_map_domain_pirq(xsm_default_t def,struct domain * d)408 static inline int xsm_map_domain_pirq (xsm_default_t def, struct domain *d)
409 {
410     return xsm_ops->map_domain_pirq(d);
411 }
412 
xsm_map_domain_irq(xsm_default_t def,struct domain * d,int irq,void * data)413 static inline int xsm_map_domain_irq (xsm_default_t def, struct domain *d, int irq, void *data)
414 {
415     return xsm_ops->map_domain_irq(d, irq, data);
416 }
417 
xsm_unmap_domain_pirq(xsm_default_t def,struct domain * d)418 static inline int xsm_unmap_domain_pirq (xsm_default_t def, struct domain *d)
419 {
420     return xsm_ops->unmap_domain_pirq(d);
421 }
422 
xsm_unmap_domain_irq(xsm_default_t def,struct domain * d,int irq,void * data)423 static inline int xsm_unmap_domain_irq (xsm_default_t def, struct domain *d, int irq, void *data)
424 {
425     return xsm_ops->unmap_domain_irq(d, irq, data);
426 }
427 
xsm_bind_pt_irq(xsm_default_t def,struct domain * d,struct xen_domctl_bind_pt_irq * bind)428 static inline int xsm_bind_pt_irq(xsm_default_t def, struct domain *d,
429                                   struct xen_domctl_bind_pt_irq *bind)
430 {
431     return xsm_ops->bind_pt_irq(d, bind);
432 }
433 
xsm_unbind_pt_irq(xsm_default_t def,struct domain * d,struct xen_domctl_bind_pt_irq * bind)434 static inline int xsm_unbind_pt_irq(xsm_default_t def, struct domain *d,
435                                     struct xen_domctl_bind_pt_irq *bind)
436 {
437     return xsm_ops->unbind_pt_irq(d, bind);
438 }
439 
xsm_irq_permission(xsm_default_t def,struct domain * d,int pirq,uint8_t allow)440 static inline int xsm_irq_permission (xsm_default_t def, struct domain *d, int pirq, uint8_t allow)
441 {
442     return xsm_ops->irq_permission(d, pirq, allow);
443 }
444 
xsm_iomem_permission(xsm_default_t def,struct domain * d,uint64_t s,uint64_t e,uint8_t allow)445 static inline int xsm_iomem_permission (xsm_default_t def, struct domain *d, uint64_t s, uint64_t e, uint8_t allow)
446 {
447     return xsm_ops->iomem_permission(d, s, e, allow);
448 }
449 
xsm_iomem_mapping(xsm_default_t def,struct domain * d,uint64_t s,uint64_t e,uint8_t allow)450 static inline int xsm_iomem_mapping (xsm_default_t def, struct domain *d, uint64_t s, uint64_t e, uint8_t allow)
451 {
452     return xsm_ops->iomem_mapping(d, s, e, allow);
453 }
454 
xsm_pci_config_permission(xsm_default_t def,struct domain * d,uint32_t machine_bdf,uint16_t start,uint16_t end,uint8_t access)455 static inline int xsm_pci_config_permission (xsm_default_t def, struct domain *d, uint32_t machine_bdf, uint16_t start, uint16_t end, uint8_t access)
456 {
457     return xsm_ops->pci_config_permission(d, machine_bdf, start, end, access);
458 }
459 
460 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_PCI)
xsm_get_device_group(xsm_default_t def,uint32_t machine_bdf)461 static inline int xsm_get_device_group(xsm_default_t def, uint32_t machine_bdf)
462 {
463     return xsm_ops->get_device_group(machine_bdf);
464 }
465 
xsm_assign_device(xsm_default_t def,struct domain * d,uint32_t machine_bdf)466 static inline int xsm_assign_device(xsm_default_t def, struct domain *d, uint32_t machine_bdf)
467 {
468     return xsm_ops->assign_device(d, machine_bdf);
469 }
470 
xsm_deassign_device(xsm_default_t def,struct domain * d,uint32_t machine_bdf)471 static inline int xsm_deassign_device(xsm_default_t def, struct domain *d, uint32_t machine_bdf)
472 {
473     return xsm_ops->deassign_device(d, machine_bdf);
474 }
475 #endif /* HAS_PASSTHROUGH && HAS_PCI) */
476 
477 #if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_DEVICE_TREE)
xsm_assign_dtdevice(xsm_default_t def,struct domain * d,const char * dtpath)478 static inline int xsm_assign_dtdevice(xsm_default_t def, struct domain *d,
479                                       const char *dtpath)
480 {
481     return xsm_ops->assign_dtdevice(d, dtpath);
482 }
483 
xsm_deassign_dtdevice(xsm_default_t def,struct domain * d,const char * dtpath)484 static inline int xsm_deassign_dtdevice(xsm_default_t def, struct domain *d,
485                                         const char *dtpath)
486 {
487     return xsm_ops->deassign_dtdevice(d, dtpath);
488 }
489 
490 #endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE */
491 
xsm_resource_plug_pci(xsm_default_t def,uint32_t machine_bdf)492 static inline int xsm_resource_plug_pci (xsm_default_t def, uint32_t machine_bdf)
493 {
494     return xsm_ops->resource_plug_pci(machine_bdf);
495 }
496 
xsm_resource_unplug_pci(xsm_default_t def,uint32_t machine_bdf)497 static inline int xsm_resource_unplug_pci (xsm_default_t def, uint32_t machine_bdf)
498 {
499     return xsm_ops->resource_unplug_pci(machine_bdf);
500 }
501 
xsm_resource_plug_core(xsm_default_t def)502 static inline int xsm_resource_plug_core (xsm_default_t def)
503 {
504     return xsm_ops->resource_plug_core();
505 }
506 
xsm_resource_unplug_core(xsm_default_t def)507 static inline int xsm_resource_unplug_core (xsm_default_t def)
508 {
509     return xsm_ops->resource_unplug_core();
510 }
511 
xsm_resource_setup_pci(xsm_default_t def,uint32_t machine_bdf)512 static inline int xsm_resource_setup_pci (xsm_default_t def, uint32_t machine_bdf)
513 {
514     return xsm_ops->resource_setup_pci(machine_bdf);
515 }
516 
xsm_resource_setup_gsi(xsm_default_t def,int gsi)517 static inline int xsm_resource_setup_gsi (xsm_default_t def, int gsi)
518 {
519     return xsm_ops->resource_setup_gsi(gsi);
520 }
521 
xsm_resource_setup_misc(xsm_default_t def)522 static inline int xsm_resource_setup_misc (xsm_default_t def)
523 {
524     return xsm_ops->resource_setup_misc();
525 }
526 
xsm_page_offline(xsm_default_t def,uint32_t cmd)527 static inline int xsm_page_offline(xsm_default_t def, uint32_t cmd)
528 {
529     return xsm_ops->page_offline(cmd);
530 }
531 
xsm_tmem_op(xsm_default_t def)532 static inline int xsm_tmem_op(xsm_default_t def)
533 {
534     return xsm_ops->tmem_op();
535 }
536 
xsm_do_xsm_op(XEN_GUEST_HANDLE_PARAM (xsm_op_t)op)537 static inline long xsm_do_xsm_op (XEN_GUEST_HANDLE_PARAM(xsm_op_t) op)
538 {
539     return xsm_ops->do_xsm_op(op);
540 }
541 
542 #ifdef CONFIG_COMPAT
xsm_do_compat_op(XEN_GUEST_HANDLE_PARAM (xsm_op_t)op)543 static inline int xsm_do_compat_op (XEN_GUEST_HANDLE_PARAM(xsm_op_t) op)
544 {
545     return xsm_ops->do_compat_op(op);
546 }
547 #endif
548 
xsm_hvm_param(xsm_default_t def,struct domain * d,unsigned long op)549 static inline int xsm_hvm_param (xsm_default_t def, struct domain *d, unsigned long op)
550 {
551     return xsm_ops->hvm_param(d, op);
552 }
553 
xsm_hvm_control(xsm_default_t def,struct domain * d,unsigned long op)554 static inline int xsm_hvm_control(xsm_default_t def, struct domain *d, unsigned long op)
555 {
556     return xsm_ops->hvm_control(d, op);
557 }
558 
xsm_hvm_param_nested(xsm_default_t def,struct domain * d)559 static inline int xsm_hvm_param_nested (xsm_default_t def, struct domain *d)
560 {
561     return xsm_ops->hvm_param_nested(d);
562 }
563 
xsm_hvm_param_altp2mhvm(xsm_default_t def,struct domain * d)564 static inline int xsm_hvm_param_altp2mhvm (xsm_default_t def, struct domain *d)
565 {
566     return xsm_ops->hvm_param_altp2mhvm(d);
567 }
568 
xsm_hvm_altp2mhvm_op(xsm_default_t def,struct domain * d,uint64_t mode,uint32_t op)569 static inline int xsm_hvm_altp2mhvm_op (xsm_default_t def, struct domain *d, uint64_t mode, uint32_t op)
570 {
571     return xsm_ops->hvm_altp2mhvm_op(d, mode, op);
572 }
573 
xsm_get_vnumainfo(xsm_default_t def,struct domain * d)574 static inline int xsm_get_vnumainfo (xsm_default_t def, struct domain *d)
575 {
576     return xsm_ops->get_vnumainfo(d);
577 }
578 
xsm_vm_event_control(xsm_default_t def,struct domain * d,int mode,int op)579 static inline int xsm_vm_event_control (xsm_default_t def, struct domain *d, int mode, int op)
580 {
581     return xsm_ops->vm_event_control(d, mode, op);
582 }
583 
584 #ifdef CONFIG_HAS_MEM_ACCESS
xsm_mem_access(xsm_default_t def,struct domain * d)585 static inline int xsm_mem_access (xsm_default_t def, struct domain *d)
586 {
587     return xsm_ops->mem_access(d);
588 }
589 #endif
590 
591 #ifdef CONFIG_HAS_MEM_PAGING
xsm_mem_paging(xsm_default_t def,struct domain * d)592 static inline int xsm_mem_paging (xsm_default_t def, struct domain *d)
593 {
594     return xsm_ops->mem_paging(d);
595 }
596 #endif
597 
598 #ifdef CONFIG_HAS_MEM_SHARING
xsm_mem_sharing(xsm_default_t def,struct domain * d)599 static inline int xsm_mem_sharing (xsm_default_t def, struct domain *d)
600 {
601     return xsm_ops->mem_sharing(d);
602 }
603 #endif
604 
xsm_platform_op(xsm_default_t def,uint32_t op)605 static inline int xsm_platform_op (xsm_default_t def, uint32_t op)
606 {
607     return xsm_ops->platform_op(op);
608 }
609 
610 #ifdef CONFIG_X86
xsm_do_mca(xsm_default_t def)611 static inline int xsm_do_mca(xsm_default_t def)
612 {
613     return xsm_ops->do_mca();
614 }
615 
xsm_shadow_control(xsm_default_t def,struct domain * d,uint32_t op)616 static inline int xsm_shadow_control (xsm_default_t def, struct domain *d, uint32_t op)
617 {
618     return xsm_ops->shadow_control(d, op);
619 }
620 
xsm_mem_sharing_op(xsm_default_t def,struct domain * d,struct domain * cd,int op)621 static inline int xsm_mem_sharing_op (xsm_default_t def, struct domain *d, struct domain *cd, int op)
622 {
623     return xsm_ops->mem_sharing_op(d, cd, op);
624 }
625 
xsm_apic(xsm_default_t def,struct domain * d,int cmd)626 static inline int xsm_apic (xsm_default_t def, struct domain *d, int cmd)
627 {
628     return xsm_ops->apic(d, cmd);
629 }
630 
xsm_memtype(xsm_default_t def,uint32_t access)631 static inline int xsm_memtype (xsm_default_t def, uint32_t access)
632 {
633     return xsm_ops->memtype(access);
634 }
635 
xsm_machine_memory_map(xsm_default_t def)636 static inline int xsm_machine_memory_map(xsm_default_t def)
637 {
638     return xsm_ops->machine_memory_map();
639 }
640 
xsm_domain_memory_map(xsm_default_t def,struct domain * d)641 static inline int xsm_domain_memory_map(xsm_default_t def, struct domain *d)
642 {
643     return xsm_ops->domain_memory_map(d);
644 }
645 
xsm_mmu_update(xsm_default_t def,struct domain * d,struct domain * t,struct domain * f,uint32_t flags)646 static inline int xsm_mmu_update (xsm_default_t def, struct domain *d, struct domain *t,
647                                   struct domain *f, uint32_t flags)
648 {
649     return xsm_ops->mmu_update(d, t, f, flags);
650 }
651 
xsm_mmuext_op(xsm_default_t def,struct domain * d,struct domain * f)652 static inline int xsm_mmuext_op (xsm_default_t def, struct domain *d, struct domain *f)
653 {
654     return xsm_ops->mmuext_op(d, f);
655 }
656 
xsm_update_va_mapping(xsm_default_t def,struct domain * d,struct domain * f,l1_pgentry_t pte)657 static inline int xsm_update_va_mapping(xsm_default_t def, struct domain *d, struct domain *f,
658                                                             l1_pgentry_t pte)
659 {
660     return xsm_ops->update_va_mapping(d, f, pte);
661 }
662 
xsm_priv_mapping(xsm_default_t def,struct domain * d,struct domain * t)663 static inline int xsm_priv_mapping(xsm_default_t def, struct domain *d, struct domain *t)
664 {
665     return xsm_ops->priv_mapping(d, t);
666 }
667 
xsm_ioport_permission(xsm_default_t def,struct domain * d,uint32_t s,uint32_t e,uint8_t allow)668 static inline int xsm_ioport_permission (xsm_default_t def, struct domain *d, uint32_t s, uint32_t e, uint8_t allow)
669 {
670     return xsm_ops->ioport_permission(d, s, e, allow);
671 }
672 
xsm_ioport_mapping(xsm_default_t def,struct domain * d,uint32_t s,uint32_t e,uint8_t allow)673 static inline int xsm_ioport_mapping (xsm_default_t def, struct domain *d, uint32_t s, uint32_t e, uint8_t allow)
674 {
675     return xsm_ops->ioport_mapping(d, s, e, allow);
676 }
677 
xsm_pmu_op(xsm_default_t def,struct domain * d,unsigned int op)678 static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int op)
679 {
680     return xsm_ops->pmu_op(d, op);
681 }
682 
xsm_dm_op(xsm_default_t def,struct domain * d)683 static inline int xsm_dm_op(xsm_default_t def, struct domain *d)
684 {
685     return xsm_ops->dm_op(d);
686 }
687 
688 #endif /* CONFIG_X86 */
689 
xsm_xen_version(xsm_default_t def,uint32_t op)690 static inline int xsm_xen_version (xsm_default_t def, uint32_t op)
691 {
692     return xsm_ops->xen_version(op);
693 }
694 
695 #endif /* XSM_NO_WRAPPERS */
696 
697 #ifdef CONFIG_MULTIBOOT
698 extern int xsm_multiboot_init(unsigned long *module_map,
699                               const multiboot_info_t *mbi,
700                               void *(*bootstrap_map)(const module_t *));
701 extern int xsm_multiboot_policy_init(unsigned long *module_map,
702                                      const multiboot_info_t *mbi,
703                                      void *(*bootstrap_map)(const module_t *),
704                                      void **policy_buffer,
705                                      size_t *policy_size);
706 #endif
707 
708 #ifdef CONFIG_HAS_DEVICE_TREE
709 extern int xsm_dt_init(void);
710 extern int xsm_dt_policy_init(void **policy_buffer, size_t *policy_size);
711 extern bool has_xsm_magic(paddr_t);
712 #endif
713 
714 extern int register_xsm(struct xsm_operations *ops);
715 
716 extern struct xsm_operations dummy_xsm_ops;
717 extern void xsm_fixup_ops(struct xsm_operations *ops);
718 
719 #ifdef CONFIG_FLASK
720 extern void flask_init(const void *policy_buffer, size_t policy_size);
721 #else
flask_init(const void * policy_buffer,size_t policy_size)722 static inline void flask_init(const void *policy_buffer, size_t policy_size)
723 {
724 }
725 #endif
726 
727 #ifdef CONFIG_XSM_POLICY
728 extern const unsigned char xsm_init_policy[];
729 extern const unsigned int xsm_init_policy_size;
730 #endif
731 
732 #else /* CONFIG_XSM */
733 
734 #include <xsm/dummy.h>
735 
736 #ifdef CONFIG_MULTIBOOT
xsm_multiboot_init(unsigned long * module_map,const multiboot_info_t * mbi,void * (* bootstrap_map)(const module_t *))737 static inline int xsm_multiboot_init (unsigned long *module_map,
738                                       const multiboot_info_t *mbi,
739                                       void *(*bootstrap_map)(const module_t *))
740 {
741     return 0;
742 }
743 #endif
744 
745 #ifdef CONFIG_HAS_DEVICE_TREE
xsm_dt_init(void)746 static inline int xsm_dt_init(void)
747 {
748     return 0;
749 }
750 
has_xsm_magic(paddr_t start)751 static inline bool has_xsm_magic(paddr_t start)
752 {
753     return false;
754 }
755 #endif /* CONFIG_HAS_DEVICE_TREE */
756 
757 #endif /* CONFIG_XSM */
758 
759 #endif /* __XSM_H */
760