aboutsummaryrefslogtreecommitdiffstats
path: root/include/xen
diff options
context:
space:
mode:
authorAnnie Li <annie.li@oracle.com>2011-11-21 20:58:06 -0500
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2011-11-22 09:23:44 -0500
commit0f9f5a9588468cddeccc9146b86798492c7cd4f5 (patch)
tree2743d8d40497383c1f4edc92d3ee9ddbf42d28a9 /include/xen
parent3b456ae900705dda029f81a6cceed64d7f1ddfbd (diff)
xen/granttable: Introducing grant table V2 stucture
This patch introduces new structures of grant table V2, grant table V2 is an extension from V1. Grant table is shared between guest and Xen, and Xen is responsible to do corresponding work for grant operations, such as: figure out guest's grant table version, perform different actions based on different grant table version, etc. Although full-page structure of V2 is different from V1, it play the same role as V1. Acked-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Annie Li <annie.li@oracle.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'include/xen')
-rw-r--r--include/xen/grant_table.h4
-rw-r--r--include/xen/interface/grant_table.h167
-rw-r--r--include/xen/interface/xen.h2
3 files changed, 166 insertions, 7 deletions
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 11e2dfce42f8..c7a40f8d455a 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -145,8 +145,8 @@ gnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, phys_addr_t addr,
145 145
146int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes, 146int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
147 unsigned long max_nr_gframes, 147 unsigned long max_nr_gframes,
148 struct grant_entry **__shared); 148 void **__shared);
149void arch_gnttab_unmap_shared(struct grant_entry *shared, 149void arch_gnttab_unmap_shared(void *shared,
150 unsigned long nr_gframes); 150 unsigned long nr_gframes);
151 151
152extern unsigned long xen_hvm_resume_frames; 152extern unsigned long xen_hvm_resume_frames;
diff --git a/include/xen/interface/grant_table.h b/include/xen/interface/grant_table.h
index 39e571796e32..a17d84433e6a 100644
--- a/include/xen/interface/grant_table.h
+++ b/include/xen/interface/grant_table.h
@@ -85,12 +85,22 @@
85 */ 85 */
86 86
87/* 87/*
88 * Reference to a grant entry in a specified domain's grant table.
89 */
90typedef uint32_t grant_ref_t;
91
92/*
88 * A grant table comprises a packed array of grant entries in one or more 93 * A grant table comprises a packed array of grant entries in one or more
89 * page frames shared between Xen and a guest. 94 * page frames shared between Xen and a guest.
90 * [XEN]: This field is written by Xen and read by the sharing guest. 95 * [XEN]: This field is written by Xen and read by the sharing guest.
91 * [GST]: This field is written by the guest and read by Xen. 96 * [GST]: This field is written by the guest and read by Xen.
92 */ 97 */
93struct grant_entry { 98
99/*
100 * Version 1 of the grant table entry structure is maintained purely
101 * for backwards compatibility. New guests should use version 2.
102 */
103struct grant_entry_v1 {
94 /* GTF_xxx: various type and flag information. [XEN,GST] */ 104 /* GTF_xxx: various type and flag information. [XEN,GST] */
95 uint16_t flags; 105 uint16_t flags;
96 /* The domain being granted foreign privileges. [GST] */ 106 /* The domain being granted foreign privileges. [GST] */
@@ -108,10 +118,13 @@ struct grant_entry {
108 * GTF_permit_access: Allow @domid to map/access @frame. 118 * GTF_permit_access: Allow @domid to map/access @frame.
109 * GTF_accept_transfer: Allow @domid to transfer ownership of one page frame 119 * GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
110 * to this guest. Xen writes the page number to @frame. 120 * to this guest. Xen writes the page number to @frame.
121 * GTF_transitive: Allow @domid to transitively access a subrange of
122 * @trans_grant in @trans_domid. No mappings are allowed.
111 */ 123 */
112#define GTF_invalid (0U<<0) 124#define GTF_invalid (0U<<0)
113#define GTF_permit_access (1U<<0) 125#define GTF_permit_access (1U<<0)
114#define GTF_accept_transfer (2U<<0) 126#define GTF_accept_transfer (2U<<0)
127#define GTF_transitive (3U<<0)
115#define GTF_type_mask (3U<<0) 128#define GTF_type_mask (3U<<0)
116 129
117/* 130/*
@@ -119,6 +132,9 @@ struct grant_entry {
119 * GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST] 132 * GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
120 * GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN] 133 * GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
121 * GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN] 134 * GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
135 * GTF_sub_page: Grant access to only a subrange of the page. @domid
136 * will only be allowed to copy from the grant, and not
137 * map it. [GST]
122 */ 138 */
123#define _GTF_readonly (2) 139#define _GTF_readonly (2)
124#define GTF_readonly (1U<<_GTF_readonly) 140#define GTF_readonly (1U<<_GTF_readonly)
@@ -126,6 +142,8 @@ struct grant_entry {
126#define GTF_reading (1U<<_GTF_reading) 142#define GTF_reading (1U<<_GTF_reading)
127#define _GTF_writing (4) 143#define _GTF_writing (4)
128#define GTF_writing (1U<<_GTF_writing) 144#define GTF_writing (1U<<_GTF_writing)
145#define _GTF_sub_page (8)
146#define GTF_sub_page (1U<<_GTF_sub_page)
129 147
130/* 148/*
131 * Subflags for GTF_accept_transfer: 149 * Subflags for GTF_accept_transfer:
@@ -142,15 +160,81 @@ struct grant_entry {
142#define _GTF_transfer_completed (3) 160#define _GTF_transfer_completed (3)
143#define GTF_transfer_completed (1U<<_GTF_transfer_completed) 161#define GTF_transfer_completed (1U<<_GTF_transfer_completed)
144 162
163/*
164 * Version 2 grant table entries. These fulfil the same role as
165 * version 1 entries, but can represent more complicated operations.
166 * Any given domain will have either a version 1 or a version 2 table,
167 * and every entry in the table will be the same version.
168 *
169 * The interface by which domains use grant references does not depend
170 * on the grant table version in use by the other domain.
171 */
145 172
146/*********************************** 173/*
147 * GRANT TABLE QUERIES AND USES 174 * Version 1 and version 2 grant entries share a common prefix. The
175 * fields of the prefix are documented as part of struct
176 * grant_entry_v1.
148 */ 177 */
178struct grant_entry_header {
179 uint16_t flags;
180 domid_t domid;
181};
149 182
150/* 183/*
151 * Reference to a grant entry in a specified domain's grant table. 184 * Version 2 of the grant entry structure, here is an union because three
185 * different types are suppotted: full_page, sub_page and transitive.
186 */
187union grant_entry_v2 {
188 struct grant_entry_header hdr;
189
190 /*
191 * This member is used for V1-style full page grants, where either:
192 *
193 * -- hdr.type is GTF_accept_transfer, or
194 * -- hdr.type is GTF_permit_access and GTF_sub_page is not set.
195 *
196 * In that case, the frame field has the same semantics as the
197 * field of the same name in the V1 entry structure.
198 */
199 struct {
200 struct grant_entry_header hdr;
201 uint32_t pad0;
202 uint64_t frame;
203 } full_page;
204
205 /*
206 * If the grant type is GTF_grant_access and GTF_sub_page is set,
207 * @domid is allowed to access bytes [@page_off,@page_off+@length)
208 * in frame @frame.
209 */
210 struct {
211 struct grant_entry_header hdr;
212 uint16_t page_off;
213 uint16_t length;
214 uint64_t frame;
215 } sub_page;
216
217 /*
218 * If the grant is GTF_transitive, @domid is allowed to use the
219 * grant @gref in domain @trans_domid, as if it was the local
220 * domain. Obviously, the transitive access must be compatible
221 * with the original grant.
222 */
223 struct {
224 struct grant_entry_header hdr;
225 domid_t trans_domid;
226 uint16_t pad0;
227 grant_ref_t gref;
228 } transitive;
229
230 uint32_t __spacer[4]; /* Pad to a power of two */
231};
232
233typedef uint16_t grant_status_t;
234
235/***********************************
236 * GRANT TABLE QUERIES AND USES
152 */ 237 */
153typedef uint32_t grant_ref_t;
154 238
155/* 239/*
156 * Handle to track a mapping created via a grant reference. 240 * Handle to track a mapping created via a grant reference.
@@ -322,6 +406,79 @@ struct gnttab_query_size {
322DEFINE_GUEST_HANDLE_STRUCT(gnttab_query_size); 406DEFINE_GUEST_HANDLE_STRUCT(gnttab_query_size);
323 407
324/* 408/*
409 * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings
410 * tracked by <handle> but atomically replace the page table entry with one
411 * pointing to the machine address under <new_addr>. <new_addr> will be
412 * redirected to the null entry.
413 * NOTES:
414 * 1. The call may fail in an undefined manner if either mapping is not
415 * tracked by <handle>.
416 * 2. After executing a batch of unmaps, it is guaranteed that no stale
417 * mappings will remain in the device or host TLBs.
418 */
419#define GNTTABOP_unmap_and_replace 7
420struct gnttab_unmap_and_replace {
421 /* IN parameters. */
422 uint64_t host_addr;
423 uint64_t new_addr;
424 grant_handle_t handle;
425 /* OUT parameters. */
426 int16_t status; /* GNTST_* */
427};
428DEFINE_GUEST_HANDLE_STRUCT(gnttab_unmap_and_replace);
429
430/*
431 * GNTTABOP_set_version: Request a particular version of the grant
432 * table shared table structure. This operation can only be performed
433 * once in any given domain. It must be performed before any grants
434 * are activated; otherwise, the domain will be stuck with version 1.
435 * The only defined versions are 1 and 2.
436 */
437#define GNTTABOP_set_version 8
438struct gnttab_set_version {
439 /* IN parameters */
440 uint32_t version;
441};
442DEFINE_GUEST_HANDLE_STRUCT(gnttab_set_version);
443
444/*
445 * GNTTABOP_get_status_frames: Get the list of frames used to store grant
446 * status for <dom>. In grant format version 2, the status is separated
447 * from the other shared grant fields to allow more efficient synchronization
448 * using barriers instead of atomic cmpexch operations.
449 * <nr_frames> specify the size of vector <frame_list>.
450 * The frame addresses are returned in the <frame_list>.
451 * Only <nr_frames> addresses are returned, even if the table is larger.
452 * NOTES:
453 * 1. <dom> may be specified as DOMID_SELF.
454 * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
455 */
456#define GNTTABOP_get_status_frames 9
457struct gnttab_get_status_frames {
458 /* IN parameters. */
459 uint32_t nr_frames;
460 domid_t dom;
461 /* OUT parameters. */
462 int16_t status; /* GNTST_* */
463 GUEST_HANDLE(uint64_t) frame_list;
464};
465DEFINE_GUEST_HANDLE_STRUCT(gnttab_get_status_frames);
466
467/*
468 * GNTTABOP_get_version: Get the grant table version which is in
469 * effect for domain <dom>.
470 */
471#define GNTTABOP_get_version 10
472struct gnttab_get_version {
473 /* IN parameters */
474 domid_t dom;
475 uint16_t pad;
476 /* OUT parameters */
477 uint32_t version;
478};
479DEFINE_GUEST_HANDLE_STRUCT(gnttab_get_version);
480
481/*
325 * Bitfield values for update_pin_status.flags. 482 * Bitfield values for update_pin_status.flags.
326 */ 483 */
327 /* Map the grant entry for access by I/O devices. */ 484 /* Map the grant entry for access by I/O devices. */
diff --git a/include/xen/interface/xen.h b/include/xen/interface/xen.h
index 6a6e91449347..a890804945e3 100644
--- a/include/xen/interface/xen.h
+++ b/include/xen/interface/xen.h
@@ -523,6 +523,8 @@ struct tmem_op {
523 } u; 523 } u;
524}; 524};
525 525
526DEFINE_GUEST_HANDLE(u64);
527
526#else /* __ASSEMBLY__ */ 528#else /* __ASSEMBLY__ */
527 529
528/* In assembly code we cannot use C numeric constant suffixes. */ 530/* In assembly code we cannot use C numeric constant suffixes. */