Blame view
drivers/xen/grant-table.c
30.2 KB
ad9a86121 xen: Add grant ta... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/****************************************************************************** * grant_table.c * * Granting foreign access to our memory reservation. * * Copyright (c) 2005-2006, Christopher Clark * Copyright (c) 2004-2005, K A Fraser * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation; or, when distributed * separately from the Linux kernel or incorporated into other * software packages, subject to the following license: * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this source file (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ |
283c0972d xen: Convert prin... |
33 |
#define pr_fmt(fmt) "xen:" KBUILD_MODNAME ": " fmt |
ad9a86121 xen: Add grant ta... |
34 35 |
#include <linux/sched.h> #include <linux/mm.h> |
5a0e3ad6a include cleanup: ... |
36 |
#include <linux/slab.h> |
ad9a86121 xen: Add grant ta... |
37 38 |
#include <linux/vmalloc.h> #include <linux/uaccess.h> |
183d03cc4 xen: Xen PCI plat... |
39 |
#include <linux/io.h> |
c571898ff xen/gndev: Xen ba... |
40 |
#include <linux/delay.h> |
f62805f1f xen: enter/exit l... |
41 |
#include <linux/hardirq.h> |
3f9f1c675 xen/grant-table: ... |
42 |
#include <linux/workqueue.h> |
29d11cfd8 xen/grant-table: ... |
43 |
#include <linux/ratelimit.h> |
ad9a86121 xen: Add grant ta... |
44 |
|
1ccbf5344 xen: move Xen-tes... |
45 |
#include <xen/xen.h> |
ad9a86121 xen: Add grant ta... |
46 47 48 |
#include <xen/interface/xen.h> #include <xen/page.h> #include <xen/grant_table.h> |
183d03cc4 xen: Xen PCI plat... |
49 |
#include <xen/interface/memory.h> |
85ff6acb0 xen/granttable: G... |
50 |
#include <xen/hvc-console.h> |
3d24bbd7d grant-table: call... |
51 |
#include <xen/swiotlb-xen.h> |
ff4b156f1 xen/grant-table: ... |
52 |
#include <xen/balloon.h> |
ecbf29cdb xen: clean up asm... |
53 |
#include <asm/xen/hypercall.h> |
4d9310e39 xen: missing incl... |
54 |
#include <asm/xen/interface.h> |
ad9a86121 xen: Add grant ta... |
55 56 57 |
#include <asm/pgtable.h> #include <asm/sync_bitops.h> |
ad9a86121 xen: Add grant ta... |
58 59 60 |
/* External tools reserve first few grant table entries. */ #define NR_RESERVED_ENTRIES 8 #define GNTTAB_LIST_END 0xffffffff |
ad9a86121 xen: Add grant ta... |
61 62 63 |
static grant_ref_t **gnttab_list; static unsigned int nr_grant_frames; |
ad9a86121 xen: Add grant ta... |
64 65 66 |
static int gnttab_free_count; static grant_ref_t gnttab_free_head; static DEFINE_SPINLOCK(gnttab_list_lock); |
efaf30a33 xen/grant: Implem... |
67 |
struct grant_frames xen_auto_xlat_grant_frames; |
ad9a86121 xen: Add grant ta... |
68 |
|
0f9f5a958 xen/granttable: I... |
69 70 71 72 73 74 75 76 |
static union { struct grant_entry_v1 *v1; void *addr; } gnttab_shared; /*This is a structure of function pointers for grant table*/ struct gnttab_ops { /* |
9dbc71d53 xen/granttable: I... |
77 78 79 80 |
* Mapping a list of frames for storing grant entries. Frames parameter * is used to store grant table address when grant table being setup, * nr_gframes is the number of frames to map grant table. Returning * GNTST_okay means success and negative value means failure. |
0f9f5a958 xen/granttable: I... |
81 |
*/ |
ef32f8929 xen: grant: use x... |
82 |
int (*map_frames)(xen_pfn_t *frames, unsigned int nr_gframes); |
0f9f5a958 xen/granttable: I... |
83 84 85 86 87 88 |
/* * Release a list of frames which are mapped in map_frames for grant * entry status. */ void (*unmap_frames)(void); /* |
9dbc71d53 xen/granttable: I... |
89 90 91 92 93 |
* Introducing a valid entry into the grant table, granting the frame of * this grant entry to domain for accessing or transfering. Ref * parameter is reference of this introduced grant entry, domid is id of * granted domain, frame is the page frame to be granted, and flags is * status of the grant entry to be updated. |
0f9f5a958 xen/granttable: I... |
94 |
*/ |
9dbc71d53 xen/granttable: I... |
95 96 |
void (*update_entry)(grant_ref_t ref, domid_t domid, unsigned long frame, unsigned flags); |
0f9f5a958 xen/granttable: I... |
97 |
/* |
9dbc71d53 xen/granttable: I... |
98 99 100 |
* Stop granting a grant entry to domain for accessing. Ref parameter is * reference of a grant entry whose grant access will be stopped, * readonly is not in use in this function. If the grant entry is |
0f9f5a958 xen/granttable: I... |
101 102 103 104 |
* currently mapped for reading or writing, just return failure(==0) * directly and don't tear down the grant access. Otherwise, stop grant * access for this entry and return success(==1). */ |
9dbc71d53 xen/granttable: I... |
105 |
int (*end_foreign_access_ref)(grant_ref_t ref, int readonly); |
0f9f5a958 xen/granttable: I... |
106 |
/* |
9dbc71d53 xen/granttable: I... |
107 108 109 110 111 |
* Stop granting a grant entry to domain for transfer. Ref parameter is * reference of a grant entry whose grant transfer will be stopped. If * tranfer has not started, just reclaim the grant entry and return * failure(==0). Otherwise, wait for the transfer to complete and then * return the frame. |
0f9f5a958 xen/granttable: I... |
112 |
*/ |
9dbc71d53 xen/granttable: I... |
113 |
unsigned long (*end_foreign_transfer_ref)(grant_ref_t ref); |
0f9f5a958 xen/granttable: I... |
114 |
/* |
9dbc71d53 xen/granttable: I... |
115 |
* Query the status of a grant entry. Ref parameter is reference of |
0f9f5a958 xen/granttable: I... |
116 117 118 119 |
* queried grant entry, return value is the status of queried entry. * Detailed status(writing/reading) can be gotten from the return value * by bit operations. */ |
9dbc71d53 xen/granttable: I... |
120 |
int (*query_foreign_access)(grant_ref_t ref); |
0f9f5a958 xen/granttable: I... |
121 |
}; |
b44166cd4 xen/grant: introd... |
122 123 124 125 |
struct unmap_refs_callback_data { struct completion completion; int result; }; |
86fc21367 xen/grant-table: ... |
126 |
static const struct gnttab_ops *gnttab_interface; |
0f9f5a958 xen/granttable: I... |
127 128 |
static int grant_table_version; |
d0b4d64aa xen/grant-table: ... |
129 |
static int grefs_per_grant_frame; |
ad9a86121 xen: Add grant ta... |
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
static struct gnttab_free_callback *gnttab_free_callback_list; static int gnttab_expand(unsigned int req_entries); #define RPP (PAGE_SIZE / sizeof(grant_ref_t)) static inline grant_ref_t *__gnttab_entry(grant_ref_t entry) { return &gnttab_list[(entry) / RPP][(entry) % RPP]; } /* This can be used as an l-value */ #define gnttab_entry(entry) (*__gnttab_entry(entry)) static int get_free_entries(unsigned count) { unsigned long flags; |
272800dc4 xen/grant: Fix co... |
147 |
int ref, rc = 0; |
ad9a86121 xen: Add grant ta... |
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
grant_ref_t head; spin_lock_irqsave(&gnttab_list_lock, flags); if ((gnttab_free_count < count) && ((rc = gnttab_expand(count - gnttab_free_count)) < 0)) { spin_unlock_irqrestore(&gnttab_list_lock, flags); return rc; } ref = head = gnttab_free_head; gnttab_free_count -= count; while (count-- > 1) head = gnttab_entry(head); gnttab_free_head = gnttab_entry(head); gnttab_entry(head) = GNTTAB_LIST_END; spin_unlock_irqrestore(&gnttab_list_lock, flags); return ref; } static void do_free_callbacks(void) { struct gnttab_free_callback *callback, *next; callback = gnttab_free_callback_list; gnttab_free_callback_list = NULL; while (callback != NULL) { next = callback->next; if (gnttab_free_count >= callback->count) { callback->next = NULL; callback->fn(callback->arg); } else { callback->next = gnttab_free_callback_list; gnttab_free_callback_list = callback; } callback = next; } } static inline void check_free_callbacks(void) { if (unlikely(gnttab_free_callback_list)) do_free_callbacks(); } static void put_free_entry(grant_ref_t ref) { unsigned long flags; spin_lock_irqsave(&gnttab_list_lock, flags); gnttab_entry(ref) = gnttab_free_head; gnttab_free_head = ref; gnttab_free_count++; check_free_callbacks(); spin_unlock_irqrestore(&gnttab_list_lock, flags); } |
0f9f5a958 xen/granttable: I... |
206 |
/* |
438b33c71 xen/grant-table: ... |
207 |
* Following applies to gnttab_update_entry_v1. |
0f9f5a958 xen/granttable: I... |
208 209 210 211 212 213 214 215 216 217 218 |
* Introducing a valid entry into the grant table: * 1. Write ent->domid. * 2. Write ent->frame: * GTF_permit_access: Frame to which access is permitted. * GTF_accept_transfer: Pseudo-phys frame slot being filled by new * frame, or zero if none. * 3. Write memory barrier (WMB). * 4. Write ent->flags, inc. valid type. */ static void gnttab_update_entry_v1(grant_ref_t ref, domid_t domid, unsigned long frame, unsigned flags) |
ad9a86121 xen: Add grant ta... |
219 |
{ |
0f9f5a958 xen/granttable: I... |
220 221 |
gnttab_shared.v1[ref].domid = domid; gnttab_shared.v1[ref].frame = frame; |
ad9a86121 xen: Add grant ta... |
222 |
wmb(); |
0f9f5a958 xen/granttable: I... |
223 |
gnttab_shared.v1[ref].flags = flags; |
ad9a86121 xen: Add grant ta... |
224 225 226 227 228 229 230 231 |
} /* * Public grant-issuing interface functions */ void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, unsigned long frame, int readonly) { |
0f9f5a958 xen/granttable: I... |
232 |
gnttab_interface->update_entry(ref, domid, frame, |
ad9a86121 xen: Add grant ta... |
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
GTF_permit_access | (readonly ? GTF_readonly : 0)); } EXPORT_SYMBOL_GPL(gnttab_grant_foreign_access_ref); int gnttab_grant_foreign_access(domid_t domid, unsigned long frame, int readonly) { int ref; ref = get_free_entries(1); if (unlikely(ref < 0)) return -ENOSPC; gnttab_grant_foreign_access_ref(ref, domid, frame, readonly); return ref; } EXPORT_SYMBOL_GPL(gnttab_grant_foreign_access); |
0f9f5a958 xen/granttable: I... |
251 |
static int gnttab_query_foreign_access_v1(grant_ref_t ref) |
ad9a86121 xen: Add grant ta... |
252 |
{ |
0f9f5a958 xen/granttable: I... |
253 254 |
return gnttab_shared.v1[ref].flags & (GTF_reading|GTF_writing); } |
ad9a86121 xen: Add grant ta... |
255 |
|
0f9f5a958 xen/granttable: I... |
256 257 258 |
int gnttab_query_foreign_access(grant_ref_t ref) { return gnttab_interface->query_foreign_access(ref); |
ad9a86121 xen: Add grant ta... |
259 260 |
} EXPORT_SYMBOL_GPL(gnttab_query_foreign_access); |
0f9f5a958 xen/granttable: I... |
261 |
static int gnttab_end_foreign_access_ref_v1(grant_ref_t ref, int readonly) |
ad9a86121 xen: Add grant ta... |
262 263 |
{ u16 flags, nflags; |
b1e495b2f xen/granttable: R... |
264 |
u16 *pflags; |
ad9a86121 xen: Add grant ta... |
265 |
|
b1e495b2f xen/granttable: R... |
266 267 |
pflags = &gnttab_shared.v1[ref].flags; nflags = *pflags; |
ad9a86121 xen: Add grant ta... |
268 269 |
do { flags = nflags; |
569ca5b3f xen/gnttab: add d... |
270 |
if (flags & (GTF_reading|GTF_writing)) |
ad9a86121 xen: Add grant ta... |
271 |
return 0; |
b1e495b2f xen/granttable: R... |
272 |
} while ((nflags = sync_cmpxchg(pflags, flags, 0)) != flags); |
ad9a86121 xen: Add grant ta... |
273 274 275 |
return 1; } |
0f9f5a958 xen/granttable: I... |
276 |
|
569ca5b3f xen/gnttab: add d... |
277 |
static inline int _gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly) |
0f9f5a958 xen/granttable: I... |
278 279 280 |
{ return gnttab_interface->end_foreign_access_ref(ref, readonly); } |
569ca5b3f xen/gnttab: add d... |
281 282 283 284 285 286 287 288 289 |
int gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly) { if (_gnttab_end_foreign_access_ref(ref, readonly)) return 1; pr_warn("WARNING: g.e. %#x still in use! ", ref); return 0; } |
ad9a86121 xen: Add grant ta... |
290 |
EXPORT_SYMBOL_GPL(gnttab_end_foreign_access_ref); |
569ca5b3f xen/gnttab: add d... |
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
struct deferred_entry { struct list_head list; grant_ref_t ref; bool ro; uint16_t warn_delay; struct page *page; }; static LIST_HEAD(deferred_list); static void gnttab_handle_deferred(unsigned long); static DEFINE_TIMER(deferred_timer, gnttab_handle_deferred, 0, 0); static void gnttab_handle_deferred(unsigned long unused) { unsigned int nr = 10; struct deferred_entry *first = NULL; unsigned long flags; spin_lock_irqsave(&gnttab_list_lock, flags); while (nr--) { struct deferred_entry *entry = list_first_entry(&deferred_list, struct deferred_entry, list); if (entry == first) break; list_del(&entry->list); spin_unlock_irqrestore(&gnttab_list_lock, flags); if (_gnttab_end_foreign_access_ref(entry->ref, entry->ro)) { put_free_entry(entry->ref); if (entry->page) { pr_debug("freeing g.e. %#x (pfn %#lx) ", entry->ref, page_to_pfn(entry->page)); |
05c062c36 xen/grant-table: ... |
324 |
put_page(entry->page); |
569ca5b3f xen/gnttab: add d... |
325 326 327 328 329 330 331 |
} else pr_info("freeing g.e. %#x ", entry->ref); kfree(entry); entry = NULL; } else { if (!--entry->warn_delay) |
283c0972d xen: Convert prin... |
332 333 |
pr_info("g.e. %#x still pending ", entry->ref); |
569ca5b3f xen/gnttab: add d... |
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
if (!first) first = entry; } spin_lock_irqsave(&gnttab_list_lock, flags); if (entry) list_add_tail(&entry->list, &deferred_list); else if (list_empty(&deferred_list)) break; } if (!list_empty(&deferred_list) && !timer_pending(&deferred_timer)) { deferred_timer.expires = jiffies + HZ; add_timer(&deferred_timer); } spin_unlock_irqrestore(&gnttab_list_lock, flags); } static void gnttab_add_deferred(grant_ref_t ref, bool readonly, struct page *page) { struct deferred_entry *entry = kmalloc(sizeof(*entry), GFP_ATOMIC); const char *what = KERN_WARNING "leaking"; if (entry) { unsigned long flags; entry->ref = ref; entry->ro = readonly; entry->page = page; entry->warn_delay = 60; spin_lock_irqsave(&gnttab_list_lock, flags); list_add_tail(&entry->list, &deferred_list); if (!timer_pending(&deferred_timer)) { deferred_timer.expires = jiffies + HZ; add_timer(&deferred_timer); } spin_unlock_irqrestore(&gnttab_list_lock, flags); what = KERN_DEBUG "deferring"; } printk("%s g.e. %#x (pfn %#lx) ", what, ref, page ? page_to_pfn(page) : -1); } |
ad9a86121 xen: Add grant ta... |
376 377 378 379 380 381 |
void gnttab_end_foreign_access(grant_ref_t ref, int readonly, unsigned long page) { if (gnttab_end_foreign_access_ref(ref, readonly)) { put_free_entry(ref); if (page != 0) |
05c062c36 xen/grant-table: ... |
382 |
put_page(virt_to_page(page)); |
569ca5b3f xen/gnttab: add d... |
383 384 385 |
} else gnttab_add_deferred(ref, readonly, page ? virt_to_page(page) : NULL); |
ad9a86121 xen: Add grant ta... |
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
} EXPORT_SYMBOL_GPL(gnttab_end_foreign_access); int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn) { int ref; ref = get_free_entries(1); if (unlikely(ref < 0)) return -ENOSPC; gnttab_grant_foreign_transfer_ref(ref, domid, pfn); return ref; } EXPORT_SYMBOL_GPL(gnttab_grant_foreign_transfer); void gnttab_grant_foreign_transfer_ref(grant_ref_t ref, domid_t domid, unsigned long pfn) { |
0f9f5a958 xen/granttable: I... |
405 |
gnttab_interface->update_entry(ref, domid, pfn, GTF_accept_transfer); |
ad9a86121 xen: Add grant ta... |
406 407 |
} EXPORT_SYMBOL_GPL(gnttab_grant_foreign_transfer_ref); |
0f9f5a958 xen/granttable: I... |
408 |
static unsigned long gnttab_end_foreign_transfer_ref_v1(grant_ref_t ref) |
ad9a86121 xen: Add grant ta... |
409 410 411 |
{ unsigned long frame; u16 flags; |
b1e495b2f xen/granttable: R... |
412 413 414 |
u16 *pflags; pflags = &gnttab_shared.v1[ref].flags; |
ad9a86121 xen: Add grant ta... |
415 416 417 418 419 |
/* * If a transfer is not even yet started, try to reclaim the grant * reference and return failure (== 0). */ |
b1e495b2f xen/granttable: R... |
420 421 |
while (!((flags = *pflags) & GTF_transfer_committed)) { if (sync_cmpxchg(pflags, flags, 0) == flags) |
ad9a86121 xen: Add grant ta... |
422 423 424 425 426 427 |
return 0; cpu_relax(); } /* If a transfer is in progress then wait until it is completed. */ while (!(flags & GTF_transfer_completed)) { |
b1e495b2f xen/granttable: R... |
428 |
flags = *pflags; |
ad9a86121 xen: Add grant ta... |
429 430 431 432 |
cpu_relax(); } rmb(); /* Read the frame number /after/ reading completion status. */ |
0f9f5a958 xen/granttable: I... |
433 |
frame = gnttab_shared.v1[ref].frame; |
ad9a86121 xen: Add grant ta... |
434 435 436 437 |
BUG_ON(frame == 0); return frame; } |
0f9f5a958 xen/granttable: I... |
438 439 440 441 442 |
unsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref) { return gnttab_interface->end_foreign_transfer_ref(ref); } |
ad9a86121 xen: Add grant ta... |
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
EXPORT_SYMBOL_GPL(gnttab_end_foreign_transfer_ref); unsigned long gnttab_end_foreign_transfer(grant_ref_t ref) { unsigned long frame = gnttab_end_foreign_transfer_ref(ref); put_free_entry(ref); return frame; } EXPORT_SYMBOL_GPL(gnttab_end_foreign_transfer); void gnttab_free_grant_reference(grant_ref_t ref) { put_free_entry(ref); } EXPORT_SYMBOL_GPL(gnttab_free_grant_reference); void gnttab_free_grant_references(grant_ref_t head) { grant_ref_t ref; unsigned long flags; int count = 1; if (head == GNTTAB_LIST_END) return; spin_lock_irqsave(&gnttab_list_lock, flags); ref = head; while (gnttab_entry(ref) != GNTTAB_LIST_END) { ref = gnttab_entry(ref); count++; } gnttab_entry(ref) = gnttab_free_head; gnttab_free_head = head; gnttab_free_count += count; check_free_callbacks(); spin_unlock_irqrestore(&gnttab_list_lock, flags); } EXPORT_SYMBOL_GPL(gnttab_free_grant_references); int gnttab_alloc_grant_references(u16 count, grant_ref_t *head) { int h = get_free_entries(count); if (h < 0) return -ENOSPC; *head = h; return 0; } EXPORT_SYMBOL_GPL(gnttab_alloc_grant_references); int gnttab_empty_grant_references(const grant_ref_t *private_head) { return (*private_head == GNTTAB_LIST_END); } EXPORT_SYMBOL_GPL(gnttab_empty_grant_references); int gnttab_claim_grant_reference(grant_ref_t *private_head) { grant_ref_t g = *private_head; if (unlikely(g == GNTTAB_LIST_END)) return -ENOSPC; *private_head = gnttab_entry(g); return g; } EXPORT_SYMBOL_GPL(gnttab_claim_grant_reference); void gnttab_release_grant_reference(grant_ref_t *private_head, grant_ref_t release) { gnttab_entry(release) = *private_head; *private_head = release; } EXPORT_SYMBOL_GPL(gnttab_release_grant_reference); void gnttab_request_free_callback(struct gnttab_free_callback *callback, void (*fn)(void *), void *arg, u16 count) { unsigned long flags; |
5f338d900 xen-gnt: prevent ... |
521 |
struct gnttab_free_callback *cb; |
ad9a86121 xen: Add grant ta... |
522 |
spin_lock_irqsave(&gnttab_list_lock, flags); |
5f338d900 xen-gnt: prevent ... |
523 524 525 526 527 528 529 530 |
/* Check if the callback is already on the list */ cb = gnttab_free_callback_list; while (cb) { if (cb == callback) goto out; cb = cb->next; } |
ad9a86121 xen: Add grant ta... |
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
callback->fn = fn; callback->arg = arg; callback->count = count; callback->next = gnttab_free_callback_list; gnttab_free_callback_list = callback; check_free_callbacks(); out: spin_unlock_irqrestore(&gnttab_list_lock, flags); } EXPORT_SYMBOL_GPL(gnttab_request_free_callback); void gnttab_cancel_free_callback(struct gnttab_free_callback *callback) { struct gnttab_free_callback **pcb; unsigned long flags; spin_lock_irqsave(&gnttab_list_lock, flags); for (pcb = &gnttab_free_callback_list; *pcb; pcb = &(*pcb)->next) { if (*pcb == callback) { *pcb = callback->next; break; } } spin_unlock_irqrestore(&gnttab_list_lock, flags); } EXPORT_SYMBOL_GPL(gnttab_cancel_free_callback); static int grow_gnttab_list(unsigned int more_frames) { unsigned int new_nr_grant_frames, extra_entries, i; |
bbc60c18e xen: fix grant ta... |
561 |
unsigned int nr_glist_frames, new_nr_glist_frames; |
ad9a86121 xen: Add grant ta... |
562 |
|
d0b4d64aa xen/grant-table: ... |
563 |
BUG_ON(grefs_per_grant_frame == 0); |
ad9a86121 xen: Add grant ta... |
564 |
new_nr_grant_frames = nr_grant_frames + more_frames; |
d0b4d64aa xen/grant-table: ... |
565 |
extra_entries = more_frames * grefs_per_grant_frame; |
ad9a86121 xen: Add grant ta... |
566 |
|
d0b4d64aa xen/grant-table: ... |
567 |
nr_glist_frames = (nr_grant_frames * grefs_per_grant_frame + RPP - 1) / RPP; |
bbc60c18e xen: fix grant ta... |
568 |
new_nr_glist_frames = |
d0b4d64aa xen/grant-table: ... |
569 |
(new_nr_grant_frames * grefs_per_grant_frame + RPP - 1) / RPP; |
bbc60c18e xen: fix grant ta... |
570 |
for (i = nr_glist_frames; i < new_nr_glist_frames; i++) { |
ad9a86121 xen: Add grant ta... |
571 572 573 574 |
gnttab_list[i] = (grant_ref_t *)__get_free_page(GFP_ATOMIC); if (!gnttab_list[i]) goto grow_nomem; } |
d0b4d64aa xen/grant-table: ... |
575 576 |
for (i = grefs_per_grant_frame * nr_grant_frames; i < grefs_per_grant_frame * new_nr_grant_frames - 1; i++) |
ad9a86121 xen: Add grant ta... |
577 578 579 |
gnttab_entry(i) = i + 1; gnttab_entry(i) = gnttab_free_head; |
d0b4d64aa xen/grant-table: ... |
580 |
gnttab_free_head = grefs_per_grant_frame * nr_grant_frames; |
ad9a86121 xen: Add grant ta... |
581 582 583 584 585 586 587 588 589 |
gnttab_free_count += extra_entries; nr_grant_frames = new_nr_grant_frames; check_free_callbacks(); return 0; grow_nomem: |
46e3626ad xen/grant-table: ... |
590 |
while (i-- > nr_glist_frames) |
ad9a86121 xen: Add grant ta... |
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
free_page((unsigned long) gnttab_list[i]); return -ENOMEM; } static unsigned int __max_nr_grant_frames(void) { struct gnttab_query_size query; int rc; query.dom = DOMID_SELF; rc = HYPERVISOR_grant_table_op(GNTTABOP_query_size, &query, 1); if ((rc < 0) || (query.status != GNTST_okay)) return 4; /* Legacy max supported number of frames */ return query.max_nr_frames; } |
183d03cc4 xen: Xen PCI plat... |
608 |
unsigned int gnttab_max_grant_frames(void) |
ad9a86121 xen: Add grant ta... |
609 610 |
{ unsigned int xen_max = __max_nr_grant_frames(); |
7f256020c xen/grants: Remov... |
611 612 613 614 615 |
static unsigned int boot_max_nr_grant_frames; /* First time, initialize it properly. */ if (!boot_max_nr_grant_frames) boot_max_nr_grant_frames = __max_nr_grant_frames(); |
ad9a86121 xen: Add grant ta... |
616 617 618 619 620 |
if (xen_max > boot_max_nr_grant_frames) return boot_max_nr_grant_frames; return xen_max; } |
183d03cc4 xen: Xen PCI plat... |
621 |
EXPORT_SYMBOL_GPL(gnttab_max_grant_frames); |
ad9a86121 xen: Add grant ta... |
622 |
|
47c542050 xen/gnttab: Use p... |
623 |
int gnttab_setup_auto_xlat_frames(phys_addr_t addr) |
efaf30a33 xen/grant: Implem... |
624 625 626 627 628 629 630 631 |
{ xen_pfn_t *pfn; unsigned int max_nr_gframes = __max_nr_grant_frames(); unsigned int i; void *vaddr; if (xen_auto_xlat_grant_frames.count) return -EINVAL; |
5ed5451d9 xen/grant-table: ... |
632 |
vaddr = xen_remap(addr, XEN_PAGE_SIZE * max_nr_gframes); |
efaf30a33 xen/grant: Implem... |
633 |
if (vaddr == NULL) { |
47c542050 xen/gnttab: Use p... |
634 635 636 |
pr_warn("Failed to ioremap gnttab share frames (addr=%pa)! ", &addr); |
efaf30a33 xen/grant: Implem... |
637 638 639 640 641 642 643 644 |
return -ENOMEM; } pfn = kcalloc(max_nr_gframes, sizeof(pfn[0]), GFP_KERNEL); if (!pfn) { xen_unmap(vaddr); return -ENOMEM; } for (i = 0; i < max_nr_gframes; i++) |
5ed5451d9 xen/grant-table: ... |
645 |
pfn[i] = XEN_PFN_DOWN(addr) + i; |
efaf30a33 xen/grant: Implem... |
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
xen_auto_xlat_grant_frames.vaddr = vaddr; xen_auto_xlat_grant_frames.pfn = pfn; xen_auto_xlat_grant_frames.count = max_nr_gframes; return 0; } EXPORT_SYMBOL_GPL(gnttab_setup_auto_xlat_frames); void gnttab_free_auto_xlat_frames(void) { if (!xen_auto_xlat_grant_frames.count) return; kfree(xen_auto_xlat_grant_frames.pfn); xen_unmap(xen_auto_xlat_grant_frames.vaddr); xen_auto_xlat_grant_frames.pfn = NULL; xen_auto_xlat_grant_frames.count = 0; xen_auto_xlat_grant_frames.vaddr = NULL; } EXPORT_SYMBOL_GPL(gnttab_free_auto_xlat_frames); |
ff4b156f1 xen/grant-table: ... |
667 668 669 670 671 672 673 |
/** * gnttab_alloc_pages - alloc pages suitable for grant mapping into * @nr_pages: number of pages to alloc * @pages: returns the pages */ int gnttab_alloc_pages(int nr_pages, struct page **pages) { |
8da7633f1 xen: mark grant m... |
674 |
int i; |
ff4b156f1 xen/grant-table: ... |
675 |
int ret; |
81b286e0f xen/balloon: make... |
676 |
ret = alloc_xenballooned_pages(nr_pages, pages); |
ff4b156f1 xen/grant-table: ... |
677 678 |
if (ret < 0) return ret; |
8da7633f1 xen: mark grant m... |
679 680 681 682 683 684 685 686 687 688 689 690 691 |
for (i = 0; i < nr_pages; i++) { #if BITS_PER_LONG < 64 struct xen_page_foreign *foreign; foreign = kzalloc(sizeof(*foreign), GFP_KERNEL); if (!foreign) { gnttab_free_pages(nr_pages, pages); return -ENOMEM; } set_page_private(pages[i], (unsigned long)foreign); #endif SetPagePrivate(pages[i]); } |
ff4b156f1 xen/grant-table: ... |
692 693 694 695 696 697 698 699 700 701 702 |
return 0; } EXPORT_SYMBOL(gnttab_alloc_pages); /** * gnttab_free_pages - free pages allocated by gnttab_alloc_pages() * @nr_pages; number of pages to free * @pages: the pages */ void gnttab_free_pages(int nr_pages, struct page **pages) { |
8da7633f1 xen: mark grant m... |
703 704 705 706 707 708 709 710 711 712 |
int i; for (i = 0; i < nr_pages; i++) { if (PagePrivate(pages[i])) { #if BITS_PER_LONG < 64 kfree((void *)page_private(pages[i])); #endif ClearPagePrivate(pages[i]); } } |
ff4b156f1 xen/grant-table: ... |
713 714 715 |
free_xenballooned_pages(nr_pages, pages); } EXPORT_SYMBOL(gnttab_free_pages); |
c571898ff xen/gndev: Xen ba... |
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
/* Handling of paged out grant targets (GNTST_eagain) */ #define MAX_DELAY 256 static inline void gnttab_retry_eagain_gop(unsigned int cmd, void *gop, int16_t *status, const char *func) { unsigned delay = 1; do { BUG_ON(HYPERVISOR_grant_table_op(cmd, gop, 1)); if (*status == GNTST_eagain) msleep(delay++); } while ((*status == GNTST_eagain) && (delay < MAX_DELAY)); if (delay >= MAX_DELAY) { |
283c0972d xen: Convert prin... |
731 732 |
pr_err("%s: %s eagain grant ", func, current->comm); |
c571898ff xen/gndev: Xen ba... |
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
*status = GNTST_bad_page; } } void gnttab_batch_map(struct gnttab_map_grant_ref *batch, unsigned count) { struct gnttab_map_grant_ref *op; if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, batch, count)) BUG(); for (op = batch; op < batch + count; op++) if (op->status == GNTST_eagain) gnttab_retry_eagain_gop(GNTTABOP_map_grant_ref, op, &op->status, __func__); } EXPORT_SYMBOL_GPL(gnttab_batch_map); void gnttab_batch_copy(struct gnttab_copy *batch, unsigned count) { struct gnttab_copy *op; if (HYPERVISOR_grant_table_op(GNTTABOP_copy, batch, count)) BUG(); for (op = batch; op < batch + count; op++) if (op->status == GNTST_eagain) gnttab_retry_eagain_gop(GNTTABOP_copy, op, &op->status, __func__); } EXPORT_SYMBOL_GPL(gnttab_batch_copy); |
008c320a9 xen/grant: Introd... |
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 |
void gnttab_foreach_grant_in_range(struct page *page, unsigned int offset, unsigned int len, xen_grant_fn_t fn, void *data) { unsigned int goffset; unsigned int glen; unsigned long xen_pfn; len = min_t(unsigned int, PAGE_SIZE - offset, len); goffset = xen_offset_in_page(offset); xen_pfn = page_to_xen_pfn(page) + XEN_PFN_DOWN(offset); while (len) { glen = min_t(unsigned int, XEN_PAGE_SIZE - goffset, len); fn(pfn_to_gfn(xen_pfn), goffset, glen, data); goffset = 0; xen_pfn++; len -= glen; } } EXPORT_SYMBOL_GPL(gnttab_foreach_grant_in_range); |
f73314b28 xen/grant-table: ... |
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
void gnttab_foreach_grant(struct page **pages, unsigned int nr_grefs, xen_grant_fn_t fn, void *data) { unsigned int goffset = 0; unsigned long xen_pfn = 0; unsigned int i; for (i = 0; i < nr_grefs; i++) { if ((i % XEN_PFN_PER_PAGE) == 0) { xen_pfn = page_to_xen_pfn(pages[i / XEN_PFN_PER_PAGE]); goffset = 0; } fn(pfn_to_gfn(xen_pfn), goffset, XEN_PAGE_SIZE, data); goffset += XEN_PAGE_SIZE; xen_pfn++; } } |
e85fc9805 Revert "xen/grant... |
808 |
int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, |
c123799a4 xen/granttable: K... |
809 |
struct gnttab_map_grant_ref *kmap_ops, |
e85fc9805 Revert "xen/grant... |
810 |
struct page **pages, unsigned int count) |
289b777ea xen: introduce gn... |
811 812 |
{ int i, ret; |
289b777ea xen: introduce gn... |
813 814 |
ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map_ops, count); |
87f1d40a7 xen p2m: clear th... |
815 816 |
if (ret) return ret; |
289b777ea xen: introduce gn... |
817 |
|
8da7633f1 xen: mark grant m... |
818 819 |
for (i = 0; i < count; i++) { /* Retry eagain maps */ |
c571898ff xen/gndev: Xen ba... |
820 821 822 |
if (map_ops[i].status == GNTST_eagain) gnttab_retry_eagain_gop(GNTTABOP_map_grant_ref, map_ops + i, &map_ops[i].status, __func__); |
8da7633f1 xen: mark grant m... |
823 824 825 826 827 828 829 830 831 |
if (map_ops[i].status == GNTST_okay) { struct xen_page_foreign *foreign; SetPageForeign(pages[i]); foreign = xen_page_foreign(pages[i]); foreign->domid = map_ops[i].dom; foreign->gref = map_ops[i].ref; } } |
1429d46df xen/grant-table: ... |
832 |
return set_foreign_p2m_mapping(map_ops, kmap_ops, pages, count); |
289b777ea xen: introduce gn... |
833 834 |
} EXPORT_SYMBOL_GPL(gnttab_map_refs); |
e85fc9805 Revert "xen/grant... |
835 |
int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, |
853d02893 xen/grant-table: ... |
836 |
struct gnttab_unmap_grant_ref *kunmap_ops, |
e85fc9805 Revert "xen/grant... |
837 |
struct page **pages, unsigned int count) |
289b777ea xen: introduce gn... |
838 |
{ |
8da7633f1 xen: mark grant m... |
839 |
unsigned int i; |
1429d46df xen/grant-table: ... |
840 |
int ret; |
289b777ea xen: introduce gn... |
841 842 |
ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap_ops, count); |
87f1d40a7 xen p2m: clear th... |
843 844 |
if (ret) return ret; |
8da7633f1 xen: mark grant m... |
845 846 |
for (i = 0; i < count; i++) ClearPageForeign(pages[i]); |
853d02893 xen/grant-table: ... |
847 |
return clear_foreign_p2m_mapping(unmap_ops, kunmap_ops, pages, count); |
289b777ea xen: introduce gn... |
848 849 |
} EXPORT_SYMBOL_GPL(gnttab_unmap_refs); |
3f9f1c675 xen/grant-table: ... |
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 |
#define GNTTAB_UNMAP_REFS_DELAY 5 static void __gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item); static void gnttab_unmap_work(struct work_struct *work) { struct gntab_unmap_queue_data *unmap_data = container_of(work, struct gntab_unmap_queue_data, gnttab_work.work); if (unmap_data->age != UINT_MAX) unmap_data->age++; __gnttab_unmap_refs_async(unmap_data); } static void __gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item) { int ret; int pc; for (pc = 0; pc < item->count; pc++) { if (page_count(item->pages[pc]) > 1) { unsigned long delay = GNTTAB_UNMAP_REFS_DELAY * (item->age + 1); schedule_delayed_work(&item->gnttab_work, msecs_to_jiffies(delay)); return; } } ret = gnttab_unmap_refs(item->unmap_ops, item->kunmap_ops, item->pages, item->count); item->done(ret, item); } void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item) { INIT_DELAYED_WORK(&item->gnttab_work, gnttab_unmap_work); item->age = 0; __gnttab_unmap_refs_async(item); } EXPORT_SYMBOL_GPL(gnttab_unmap_refs_async); |
b44166cd4 xen/grant: introd... |
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 |
static void unmap_refs_callback(int result, struct gntab_unmap_queue_data *data) { struct unmap_refs_callback_data *d = data->data; d->result = result; complete(&d->completion); } int gnttab_unmap_refs_sync(struct gntab_unmap_queue_data *item) { struct unmap_refs_callback_data data; init_completion(&data.completion); item->data = &data; item->done = &unmap_refs_callback; gnttab_unmap_refs_async(item); wait_for_completion(&data.completion); return data.result; } EXPORT_SYMBOL_GPL(gnttab_unmap_refs_sync); |
ef32f8929 xen: grant: use x... |
914 |
static int gnttab_map_frames_v1(xen_pfn_t *frames, unsigned int nr_gframes) |
0f9f5a958 xen/granttable: I... |
915 916 917 918 919 920 921 922 923 924 925 926 927 |
{ int rc; rc = arch_gnttab_map_shared(frames, nr_gframes, gnttab_max_grant_frames(), &gnttab_shared.addr); BUG_ON(rc); return 0; } static void gnttab_unmap_frames_v1(void) { |
85ff6acb0 xen/granttable: G... |
928 929 |
arch_gnttab_unmap(gnttab_shared.addr, nr_grant_frames); } |
ad9a86121 xen: Add grant ta... |
930 931 932 |
static int gnttab_map(unsigned int start_idx, unsigned int end_idx) { struct gnttab_setup_table setup; |
ef32f8929 xen: grant: use x... |
933 |
xen_pfn_t *frames; |
ad9a86121 xen: Add grant ta... |
934 935 |
unsigned int nr_gframes = end_idx + 1; int rc; |
6926f6d61 xen/pvh: Piggybac... |
936 |
if (xen_feature(XENFEAT_auto_translated_physmap)) { |
183d03cc4 xen: Xen PCI plat... |
937 938 939 |
struct xen_add_to_physmap xatp; unsigned int i = end_idx; rc = 0; |
efaf30a33 xen/grant: Implem... |
940 |
BUG_ON(xen_auto_xlat_grant_frames.count < nr_gframes); |
183d03cc4 xen: Xen PCI plat... |
941 942 943 944 945 946 947 948 |
/* * Loop backwards, so that the first hypercall has the largest * index, ensuring that the table will grow only once. */ do { xatp.domid = DOMID_SELF; xatp.idx = i; xatp.space = XENMAPSPACE_grant_table; |
efaf30a33 xen/grant: Implem... |
949 |
xatp.gpfn = xen_auto_xlat_grant_frames.pfn[i]; |
183d03cc4 xen: Xen PCI plat... |
950 951 |
rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp); if (rc != 0) { |
283c0972d xen: Convert prin... |
952 953 954 |
pr_warn("grant table add_to_physmap failed, err=%d ", rc); |
183d03cc4 xen: Xen PCI plat... |
955 956 957 958 959 960 |
break; } } while (i-- > start_idx); return rc; } |
85ff6acb0 xen/granttable: G... |
961 962 963 |
/* No need for kzalloc as it is initialized in following hypercall * GNTTABOP_setup_table. */ |
ad9a86121 xen: Add grant ta... |
964 965 966 967 968 969 |
frames = kmalloc(nr_gframes * sizeof(unsigned long), GFP_ATOMIC); if (!frames) return -ENOMEM; setup.dom = DOMID_SELF; setup.nr_frames = nr_gframes; |
87e27cf62 xen: add missing ... |
970 |
set_xen_guest_handle(setup.frame_list, frames); |
ad9a86121 xen: Add grant ta... |
971 972 973 974 975 976 977 978 |
rc = HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1); if (rc == -ENOSYS) { kfree(frames); return -ENOSYS; } BUG_ON(rc || setup.status); |
0f9f5a958 xen/granttable: I... |
979 |
rc = gnttab_interface->map_frames(frames, nr_gframes); |
ad9a86121 xen: Add grant ta... |
980 981 |
kfree(frames); |
0f9f5a958 xen/granttable: I... |
982 983 |
return rc; } |
86fc21367 xen/grant-table: ... |
984 |
static const struct gnttab_ops gnttab_v1_ops = { |
0f9f5a958 xen/granttable: I... |
985 986 987 988 989 990 991 992 993 994 |
.map_frames = gnttab_map_frames_v1, .unmap_frames = gnttab_unmap_frames_v1, .update_entry = gnttab_update_entry_v1, .end_foreign_access_ref = gnttab_end_foreign_access_ref_v1, .end_foreign_transfer_ref = gnttab_end_foreign_transfer_ref_v1, .query_foreign_access = gnttab_query_foreign_access_v1, }; static void gnttab_request_version(void) { |
438b33c71 xen/grant-table: ... |
995 996 |
/* Only version 1 is used, which will always be available. */ grant_table_version = 1; |
5ed5451d9 xen/grant-table: ... |
997 |
grefs_per_grant_frame = XEN_PAGE_SIZE / sizeof(struct grant_entry_v1); |
438b33c71 xen/grant-table: ... |
998 |
gnttab_interface = &gnttab_v1_ops; |
85ff6acb0 xen/granttable: G... |
999 |
|
283c0972d xen: Convert prin... |
1000 1001 |
pr_info("Grant tables using version %d layout ", grant_table_version); |
ad9a86121 xen: Add grant ta... |
1002 |
} |
d0b4d64aa xen/grant-table: ... |
1003 |
static int gnttab_setup(void) |
ad9a86121 xen: Add grant ta... |
1004 |
{ |
183d03cc4 xen: Xen PCI plat... |
1005 1006 1007 1008 |
unsigned int max_nr_gframes; max_nr_gframes = gnttab_max_grant_frames(); if (max_nr_gframes < nr_grant_frames) |
ad9a86121 xen: Add grant ta... |
1009 |
return -ENOSYS; |
183d03cc4 xen: Xen PCI plat... |
1010 |
|
456847533 xen/grant-table: ... |
1011 |
if (xen_feature(XENFEAT_auto_translated_physmap) && gnttab_shared.addr == NULL) { |
efaf30a33 xen/grant: Implem... |
1012 |
gnttab_shared.addr = xen_auto_xlat_grant_frames.vaddr; |
0f9f5a958 xen/granttable: I... |
1013 |
if (gnttab_shared.addr == NULL) { |
efaf30a33 xen/grant: Implem... |
1014 1015 1016 |
pr_warn("gnttab share frames (addr=0x%08lx) is not mapped! ", (unsigned long)xen_auto_xlat_grant_frames.vaddr); |
183d03cc4 xen: Xen PCI plat... |
1017 1018 1019 |
return -ENOMEM; } } |
456847533 xen/grant-table: ... |
1020 |
return gnttab_map(0, nr_grant_frames - 1); |
ad9a86121 xen: Add grant ta... |
1021 |
} |
d0b4d64aa xen/grant-table: ... |
1022 1023 1024 1025 1026 |
int gnttab_resume(void) { gnttab_request_version(); return gnttab_setup(); } |
0e91398f2 xen: implement sa... |
1027 |
int gnttab_suspend(void) |
ad9a86121 xen: Add grant ta... |
1028 |
{ |
13cd36a37 xen/grant-table: ... |
1029 1030 |
if (!xen_feature(XENFEAT_auto_translated_physmap)) gnttab_interface->unmap_frames(); |
ad9a86121 xen: Add grant ta... |
1031 1032 1033 1034 1035 1036 1037 |
return 0; } static int gnttab_expand(unsigned int req_entries) { int rc; unsigned int cur, extra; |
d0b4d64aa xen/grant-table: ... |
1038 |
BUG_ON(grefs_per_grant_frame == 0); |
ad9a86121 xen: Add grant ta... |
1039 |
cur = nr_grant_frames; |
d0b4d64aa xen/grant-table: ... |
1040 1041 |
extra = ((req_entries + (grefs_per_grant_frame-1)) / grefs_per_grant_frame); |
29d11cfd8 xen/grant-table: ... |
1042 1043 1044 1045 1046 1047 1048 |
if (cur + extra > gnttab_max_grant_frames()) { pr_warn_ratelimited("xen/grant-table: max_grant_frames reached" " cur=%u extra=%u limit=%u" " gnttab_free_count=%u req_entries=%u ", cur, extra, gnttab_max_grant_frames(), gnttab_free_count, req_entries); |
ad9a86121 xen: Add grant ta... |
1049 |
return -ENOSPC; |
29d11cfd8 xen/grant-table: ... |
1050 |
} |
ad9a86121 xen: Add grant ta... |
1051 1052 1053 1054 1055 1056 1057 |
rc = gnttab_map(cur, cur + extra - 1); if (rc == 0) rc = grow_gnttab_list(extra); return rc; } |
183d03cc4 xen: Xen PCI plat... |
1058 |
int gnttab_init(void) |
ad9a86121 xen: Add grant ta... |
1059 1060 |
{ int i; |
162e37171 x86/xen: safely m... |
1061 |
unsigned long max_nr_grant_frames; |
bbc60c18e xen: fix grant ta... |
1062 |
unsigned int max_nr_glist_frames, nr_glist_frames; |
ad9a86121 xen: Add grant ta... |
1063 |
unsigned int nr_init_grefs; |
6b5e7d9ef xen/grant-table: ... |
1064 |
int ret; |
ad9a86121 xen: Add grant ta... |
1065 |
|
d0b4d64aa xen/grant-table: ... |
1066 |
gnttab_request_version(); |
162e37171 x86/xen: safely m... |
1067 |
max_nr_grant_frames = gnttab_max_grant_frames(); |
ad9a86121 xen: Add grant ta... |
1068 |
nr_grant_frames = 1; |
ad9a86121 xen: Add grant ta... |
1069 1070 1071 1072 |
/* Determine the maximum number of frames required for the * grant reference free list on the current hypervisor. */ |
d0b4d64aa xen/grant-table: ... |
1073 |
BUG_ON(grefs_per_grant_frame == 0); |
162e37171 x86/xen: safely m... |
1074 |
max_nr_glist_frames = (max_nr_grant_frames * |
d0b4d64aa xen/grant-table: ... |
1075 |
grefs_per_grant_frame / RPP); |
ad9a86121 xen: Add grant ta... |
1076 1077 1078 1079 1080 |
gnttab_list = kmalloc(max_nr_glist_frames * sizeof(grant_ref_t *), GFP_KERNEL); if (gnttab_list == NULL) return -ENOMEM; |
d0b4d64aa xen/grant-table: ... |
1081 |
nr_glist_frames = (nr_grant_frames * grefs_per_grant_frame + RPP - 1) / RPP; |
bbc60c18e xen: fix grant ta... |
1082 |
for (i = 0; i < nr_glist_frames; i++) { |
ad9a86121 xen: Add grant ta... |
1083 |
gnttab_list[i] = (grant_ref_t *)__get_free_page(GFP_KERNEL); |
6b5e7d9ef xen/grant-table: ... |
1084 1085 |
if (gnttab_list[i] == NULL) { ret = -ENOMEM; |
ad9a86121 xen: Add grant ta... |
1086 |
goto ini_nomem; |
6b5e7d9ef xen/grant-table: ... |
1087 |
} |
ad9a86121 xen: Add grant ta... |
1088 |
} |
438b33c71 xen/grant-table: ... |
1089 |
ret = arch_gnttab_init(max_nr_grant_frames); |
162e37171 x86/xen: safely m... |
1090 1091 |
if (ret < 0) goto ini_nomem; |
d0b4d64aa xen/grant-table: ... |
1092 |
if (gnttab_setup() < 0) { |
6b5e7d9ef xen/grant-table: ... |
1093 1094 1095 |
ret = -ENODEV; goto ini_nomem; } |
ad9a86121 xen: Add grant ta... |
1096 |
|
d0b4d64aa xen/grant-table: ... |
1097 |
nr_init_grefs = nr_grant_frames * grefs_per_grant_frame; |
ad9a86121 xen: Add grant ta... |
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 |
for (i = NR_RESERVED_ENTRIES; i < nr_init_grefs - 1; i++) gnttab_entry(i) = i + 1; gnttab_entry(nr_init_grefs - 1) = GNTTAB_LIST_END; gnttab_free_count = nr_init_grefs - NR_RESERVED_ENTRIES; gnttab_free_head = NR_RESERVED_ENTRIES; printk("Grant table initialized "); return 0; ini_nomem: for (i--; i >= 0; i--) free_page((unsigned long)gnttab_list[i]); kfree(gnttab_list); |
6b5e7d9ef xen/grant-table: ... |
1114 |
return ret; |
ad9a86121 xen: Add grant ta... |
1115 |
} |
183d03cc4 xen: Xen PCI plat... |
1116 |
EXPORT_SYMBOL_GPL(gnttab_init); |
345a52558 Drivers: xen: rem... |
1117 |
static int __gnttab_init(void) |
183d03cc4 xen: Xen PCI plat... |
1118 |
{ |
8613d78ab xen/pvh: Initiali... |
1119 1120 |
if (!xen_domain()) return -ENODEV; |
183d03cc4 xen: Xen PCI plat... |
1121 |
/* Delay grant-table initialization in the PV on HVM case */ |
8613d78ab xen/pvh: Initiali... |
1122 |
if (xen_hvm_domain() && !xen_pvh_domain()) |
183d03cc4 xen: Xen PCI plat... |
1123 |
return 0; |
183d03cc4 xen: Xen PCI plat... |
1124 1125 |
return gnttab_init(); } |
6926f6d61 xen/pvh: Piggybac... |
1126 1127 1128 |
/* Starts after core_initcall so that xen_pvh_gnttab_setup can be called * beforehand to initialize xen_auto_xlat_grant_frames. */ core_initcall_sync(__gnttab_init); |