Xen Test Framework
grant_table.h
Go to the documentation of this file.
1/*
2 * Xen public Grant Table hypercall interface
3 */
4
5#ifndef XEN_PUBLIC_GRANT_TABLE_H
6#define XEN_PUBLIC_GRANT_TABLE_H
7
8#include "xen.h"
9
10#define GNTST_okay (0) /* Normal return. */
11#define GNTST_general_error (-1) /* General undefined error. */
12#define GNTST_bad_domain (-2) /* Unrecognsed domain id. */
13#define GNTST_bad_gntref (-3) /* Unrecognised or inappropriate gntref. */
14#define GNTST_bad_handle (-4) /* Unrecognised or inappropriate handle. */
15#define GNTST_bad_virt_addr (-5) /* Inappropriate virtual address to map. */
16#define GNTST_bad_dev_addr (-6) /* Inappropriate device address to unmap.*/
17#define GNTST_no_device_space (-7) /* Out of space in I/O MMU. */
18#define GNTST_permission_denied (-8) /* Not enough privilege for operation. */
19#define GNTST_bad_page (-9) /* Specified page was invalid for op. */
20#define GNTST_bad_copy_arg (-10) /* copy arguments cross page boundary. */
21#define GNTST_address_too_big (-11) /* transfer page address too large. */
22#define GNTST_eagain (-12) /* Operation not done; try again. */
23
24#define GNTTABOP_error_msgs { \
25 "okay", \
26 "undefined error", \
27 "unrecognised domain id", \
28 "invalid grant reference", \
29 "invalid mapping handle", \
30 "invalid virtual address", \
31 "invalid device address", \
32 "no spare translation slot in the I/O MMU", \
33 "permission denied", \
34 "bad page", \
35 "copy arguments cross page boundary", \
36 "page address size too large", \
37 "operation not done; try again", \
38 }
39
40/*
41 * Type of grant entry.
42 * GTF_invalid: This grant entry grants no privileges.
43 * GTF_permit_access: Allow @domid to map/access @frame.
44 * GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
45 * to this guest. Xen writes the page number to @frame.
46 * GTF_transitive: Allow @domid to transitively access a subrange of
47 * @trans_grant in @trans_domid. No mappings are allowed.
48 */
49#define GTF_invalid (0 << 0)
50#define GTF_permit_access (1 << 0)
51#define GTF_accept_transfer (2 << 0)
52#define GTF_transitive (3 << 0)
53#define GTF_type_mask (3 << 0)
54
55/*
56 * Subflags for GTF_permit_access.
57 * GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
58 * GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
59 * GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
60 * GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST]
61 * GTF_sub_page: Grant access to only a subrange of the page. @domid
62 * will only be allowed to copy from the grant, and not
63 * map it. [GST]
64 */
65#define _GTF_readonly 2
66#define GTF_readonly (1 << _GTF_readonly)
67
68#define _GTF_reading 3
69#define GTF_reading (1 << _GTF_reading)
70
71#define _GTF_writing 4
72#define GTF_writing (1 << _GTF_writing)
73
74#define _GTF_PWT 5
75#define GTF_PWT (1 << _GTF_PWT)
76
77#define _GTF_PCD 6
78#define GTF_PCD (1 << _GTF_PCD)
79
80#define _GTF_PAT 7
81#define GTF_PAT (1 << _GTF_PAT)
82
83#define _GTF_sub_page 8
84#define GTF_sub_page (1 << _GTF_sub_page)
85
86/*
87 * Subflags for GTF_accept_transfer:
88 * GTF_transfer_committed: Xen sets this flag to indicate that it is committed
89 * to transferring ownership of a page frame. When a guest sees this flag
90 * it must /not/ modify the grant entry until GTF_transfer_completed is
91 * set by Xen.
92 * GTF_transfer_completed: It is safe for the guest to spin-wait on this flag
93 * after reading GTF_transfer_committed. Xen will always write the frame
94 * address, followed by ORing this flag, in a timely manner.
95 */
96#define _GTF_transfer_committed 2
97#define GTF_transfer_committed (1 << _GTF_transfer_committed)
98
99#define _GTF_transfer_completed 3
100#define GTF_transfer_completed (1 << _GTF_transfer_completed)
101
104
105typedef struct
106{
107 /* GTF_xxx: various type and flag information. [XEN,GST] */
109 /* The domain being granted foreign privileges. [GST] */
111 /*
112 * GTF_permit_access: GFN that @domid is allowed to map and access. [GST]
113 * GTF_accept_transfer: GFN that @domid is allowed to transfer into. [GST]
114 * GTF_transfer_completed: MFN whose ownership transferred by @domid
115 * (non-translated guests only). [XEN]
116 */
119
120typedef struct {
124
125typedef union {
127
128 /*
129 * This member is used for V1-style full page grants, where either:
130 *
131 * -- hdr.type is GTF_accept_transfer, or
132 * -- hdr.type is GTF_permit_access and GTF_sub_page is not set.
133 *
134 * In that case, the frame field has the same semantics as the
135 * field of the same name in the V1 entry structure.
136 */
137 struct {
141 } full_page;
142
143 /*
144 * If the grant type is GTF_grant_access and GTF_sub_page is set,
145 * @domid is allowed to access bytes [@page_off,@page_off+@length)
146 * in frame @frame.
147 */
148 struct {
153 } sub_page;
154
155 /*
156 * If the grant is GTF_transitive, @domid is allowed to use the
157 * grant @gref in domain @trans_domid, as if it was the local
158 * domain. Obviously, the transitive access must be compatible
159 * with the original grant.
160 *
161 * The current version of Xen does not allow transitive grants
162 * to be mapped.
163 */
164 struct {
169 } transitive;
170
171 uint32_t __spacer[4]; /* Pad to a power of two */
173
174/* Map the grant entry for access by I/O devices. */
175#define _GNTMAP_device_map 0
176#define GNTMAP_device_map (1 << _GNTMAP_device_map)
177/* Map the grant entry for access by host CPUs. */
178#define _GNTMAP_host_map 1
179#define GNTMAP_host_map (1 << _GNTMAP_host_map)
180/* Accesses to the granted frame will be restricted to read-only access. */
181#define _GNTMAP_readonly 2
182#define GNTMAP_readonly (1 << _GNTMAP_readonly)
183/*
184 * GNTMAP_host_map subflag:
185 * 0 => The host mapping is usable only by the guest OS.
186 * 1 => The host mapping is usable by guest OS + current application.
187 */
188#define _GNTMAP_application_map 3
189#define GNTMAP_application_map (1 << _GNTMAP_application_map)
190
191/*
192 * GNTMAP_contains_pte subflag:
193 * 0 => This map request contains a host virtual address.
194 * 1 => This map request contains the machine addess of the PTE to update.
195 */
196#define _GNTMAP_contains_pte 4
197#define GNTMAP_contains_pte (1 << _GNTMAP_contains_pte)
198
199/*
200 * Bits to be placed in guest kernel available PTE bits (architecture
201 * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set).
202 */
203#define _GNTMAP_guest_avail0 16
204#define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0)
205
206/*
207 * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
208 * by devices and/or host CPUs. If successful, <handle> is a tracking number
209 * that must be presented later to destroy the mapping(s). On error, <status>
210 * is a negative status code.
211 * NOTES:
212 * 1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address
213 * via which I/O devices may access the granted frame.
214 * 2. If GNTMAP_host_map is specified then a mapping will be added at
215 * either a host virtual address in the current address space, or at
216 * a PTE at the specified machine address. The type of mapping to
217 * perform is selected through the GNTMAP_contains_pte flag, and the
218 * address is specified in <host_addr>.
219 * 3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a
220 * host mapping is destroyed by other means then it is *NOT* guaranteed
221 * to be accounted to the correct grant reference!
222 */
223#define GNTTABOP_map_grant_ref 0
225 /* IN parameters. */
227 uint32_t flags; /* GNTMAP_* */
230 /* OUT parameters. */
231 int16_t status; /* => enum grant_status */
234};
235
236/*
237 * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings
238 * tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that
239 * field is ignored. If non-zero, they must refer to a device/host mapping
240 * that is tracked by <handle>
241 * NOTES:
242 * 1. The call may fail in an undefined manner if either mapping is not
243 * tracked by <handle>.
244 * 3. After executing a batch of unmaps, it is guaranteed that no stale
245 * mappings will remain in the device or host TLBs.
246 */
247#define GNTTABOP_unmap_grant_ref 1
249 /* IN parameters. */
253 /* OUT parameters. */
254 int16_t status; /* => enum grant_status */
255};
256
257/*
258 * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least
259 * <nr_frames> pages. The frame addresses are written to the <frame_list>.
260 * Only <nr_frames> addresses are written, even if the table is larger.
261 * NOTES:
262 * 1. <dom> may be specified as DOMID_SELF.
263 * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
264 * 3. Xen may not support more than a single grant-table page per domain.
265 */
266#define GNTTABOP_setup_table 2
268{
269 /* IN parameters. */
272 /* OUT parameters. */
274 unsigned long *frame_list;
275};
276
277/*
278 * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings
279 * tracked by <handle> but atomically replace the page table entry with one
280 * pointing to the machine address under <new_addr>. <new_addr> will be
281 * redirected to the null entry.
282 * NOTES:
283 * 1. The call may fail in an undefined manner if either mapping is not
284 * tracked by <handle>.
285 * 2. After executing a batch of unmaps, it is guaranteed that no stale
286 * mappings will remain in the device or host TLBs.
287 */
288#define GNTTABOP_unmap_and_replace 7
290 /* IN parameters. */
294 /* OUT parameters. */
295 int16_t status; /* => enum grant_status */
296};
297
298/*
299 * GNTTABOP_set_version: Request a particular version of the grant
300 * table shared table structure. This operation may be used to toggle
301 * between different versions, but must be performed while no grants
302 * are active. The only defined versions are 1 and 2.
303 */
304#define GNTTABOP_set_version 8
306 /* IN/OUT parameters */
308};
309
310/*
311 * GNTTABOP_get_status_frames: Get the list of frames used to store grant
312 * status for <dom>. In grant format version 2, the status is separated
313 * from the other shared grant fields to allow more efficient synchronization
314 * using barriers instead of atomic cmpxchg operations.
315 */
316#define GNTTABOP_get_status_frames 9
318 /* IN parameters. */
321 /* OUT parameters. */
322 int16_t status; /* => enum grant_status */
324};
325
326/*
327 * Issue one or more cache maintenance operations on a portion of a
328 * page granted to the calling domain by a foreign domain.
329 */
330#define GNTTABOP_cache_flush 12
332 union {
335 } a;
336 uint16_t offset; /* offset from start of grant */
337 uint16_t length; /* size within the grant */
338#define GNTTAB_CACHE_CLEAN (1<<0)
339#define GNTTAB_CACHE_INVAL (1<<1)
340#define GNTTAB_CACHE_SOURCE_GREF (1<<31)
342};
343
344#endif /* XEN_PUBLIC_GRANT_TABLE_H */
345
346/*
347 * Local variables:
348 * mode: C
349 * c-file-style: "BSD"
350 * c-basic-offset: 4
351 * tab-width: 4
352 * indent-tabs-mode: nil
353 * End:
354 */
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
__UINT16_TYPE__ uint16_t
Definition: stdint.h:15
__INT16_TYPE__ int16_t
Definition: stdint.h:10
grant_ref_t ref
Definition: grant_table.h:334
union gnttab_cache_flush::@45 a
uint64_t dev_bus_addr
Definition: grant_table.h:333
grant_handle_t handle
Definition: grant_table.h:232
unsigned long * frame_list
Definition: grant_table.h:274
grant_handle_t handle
Definition: grant_table.h:293
grant_handle_t handle
Definition: grant_table.h:252
Definition: grant_table.h:120
uint16_t flags
Definition: grant_table.h:121
domid_t domid
Definition: grant_table.h:122
Definition: grant_table.h:106
uint16_t flags
Definition: grant_table.h:108
uint32_t frame
Definition: grant_table.h:117
domid_t domid
Definition: grant_table.h:110
Definition: grant_table.h:125
uint16_t pad0
Definition: grant_table.h:167
uint16_t length
Definition: grant_table.h:151
domid_t trans_domid
Definition: grant_table.h:166
uint64_t frame
Definition: grant_table.h:140
uint16_t page_off
Definition: grant_table.h:150
grant_entry_header_t hdr
Definition: grant_table.h:126
grant_ref_t gref
Definition: grant_table.h:168
uint32_t pad0
Definition: grant_table.h:139
uint32_t grant_handle_t
Definition: grant_table.h:103
uint32_t grant_ref_t
Definition: grant_table.h:102
uint16_t domid_t
Definition: xen.h:66
static uint8_t frame[PAGE_SIZE]
Definition: main.c:23