1 /*- 2 * Copyright (c) 2016 Akshay Jaggi <jaggi@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * gntdev.c 27 * 28 * Interface to /dev/xen/gntdev. 29 * 30 */ 31 32 #include <sys/cdefs.h> 33 __FBSDID("$FreeBSD$"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/uio.h> 38 #include <sys/bus.h> 39 #include <sys/malloc.h> 40 #include <sys/kernel.h> 41 #include <sys/lock.h> 42 #include <sys/mutex.h> 43 #include <sys/rwlock.h> 44 #include <sys/selinfo.h> 45 #include <sys/poll.h> 46 #include <sys/conf.h> 47 #include <sys/fcntl.h> 48 #include <sys/ioccom.h> 49 #include <sys/rman.h> 50 #include <sys/tree.h> 51 #include <sys/module.h> 52 #include <sys/proc.h> 53 #include <sys/bitset.h> 54 #include <sys/queue.h> 55 #include <sys/mman.h> 56 #include <sys/syslog.h> 57 #include <sys/taskqueue.h> 58 59 #include <vm/vm.h> 60 #include <vm/vm_param.h> 61 #include <vm/vm_extern.h> 62 #include <vm/vm_kern.h> 63 #include <vm/vm_page.h> 64 #include <vm/vm_map.h> 65 #include <vm/vm_object.h> 66 #include <vm/vm_pager.h> 67 #include <vm/vm_phys.h> 68 69 #include <machine/md_var.h> 70 71 #include <xen/xen-os.h> 72 #include <xen/hypervisor.h> 73 #include <xen/error.h> 74 #include <xen/xen_intr.h> 75 #include <xen/gnttab.h> 76 #include <xen/gntdev.h> 77 78 MALLOC_DEFINE(M_GNTDEV, "gntdev", "Xen grant-table user-space device"); 79 80 #define MAX_OFFSET_COUNT ((0xffffffffffffffffull >> PAGE_SHIFT) + 1) 81 82 static d_open_t gntdev_open; 83 static d_ioctl_t gntdev_ioctl; 84 static d_mmap_single_t gntdev_mmap_single; 85 86 static struct cdevsw gntdev_devsw = { 87 .d_version = D_VERSION, 88 .d_open = gntdev_open, 89 .d_ioctl = gntdev_ioctl, 90 .d_mmap_single = gntdev_mmap_single, 91 .d_name = "gntdev", 92 }; 93 94 static device_t gntdev_dev = NULL; 95 96 struct gntdev_gref; 97 struct gntdev_gmap; 98 STAILQ_HEAD(gref_list_head, gntdev_gref); 99 STAILQ_HEAD(gmap_list_head, gntdev_gmap); 100 RB_HEAD(gref_tree_head, gntdev_gref); 101 RB_HEAD(gmap_tree_head, gntdev_gmap); 102 103 struct file_offset_struct { 104 RB_ENTRY(file_offset_struct) next; 105 uint64_t file_offset; 106 uint64_t count; 107 }; 108 109 static int 110 offset_cmp(struct file_offset_struct *f1, struct file_offset_struct *f2) 111 { 112 return (f1->file_offset - f2->file_offset); 113 } 114 115 RB_HEAD(file_offset_head, file_offset_struct); 116 RB_GENERATE_STATIC(file_offset_head, file_offset_struct, next, offset_cmp); 117 118 struct per_user_data { 119 struct mtx user_data_lock; 120 struct gref_tree_head gref_tree; 121 struct gmap_tree_head gmap_tree; 122 struct file_offset_head file_offset; 123 }; 124 125 /* 126 * Get offset into the file which will be used while mmapping the 127 * appropriate pages by the userspace program. 128 */ 129 static int 130 get_file_offset(struct per_user_data *priv_user, uint32_t count, 131 uint64_t *file_offset) 132 { 133 struct file_offset_struct *offset, *offset_tmp; 134 135 if (count == 0) 136 return (EINVAL); 137 mtx_lock(&priv_user->user_data_lock); 138 RB_FOREACH_SAFE(offset, file_offset_head, &priv_user->file_offset, 139 offset_tmp) { 140 if (offset->count >= count) { 141 offset->count -= count; 142 *file_offset = offset->file_offset + offset->count * 143 PAGE_SIZE; 144 if (offset->count == 0) { 145 RB_REMOVE(file_offset_head, 146 &priv_user->file_offset, offset); 147 free(offset, M_GNTDEV); 148 } 149 mtx_unlock(&priv_user->user_data_lock); 150 return (0); 151 } 152 } 153 mtx_unlock(&priv_user->user_data_lock); 154 155 return (ENOSPC); 156 } 157 158 static void 159 put_file_offset(struct per_user_data *priv_user, uint32_t count, 160 uint64_t file_offset) 161 { 162 struct file_offset_struct *offset, *offset_nxt, *offset_prv; 163 164 offset = malloc(sizeof(*offset), M_GNTDEV, M_WAITOK | M_ZERO); 165 offset->file_offset = file_offset; 166 offset->count = count; 167 168 mtx_lock(&priv_user->user_data_lock); 169 RB_INSERT(file_offset_head, &priv_user->file_offset, offset); 170 offset_nxt = RB_NEXT(file_offset_head, &priv_user->file_offset, offset); 171 offset_prv = RB_PREV(file_offset_head, &priv_user->file_offset, offset); 172 if (offset_nxt != NULL && 173 offset_nxt->file_offset == offset->file_offset + offset->count * 174 PAGE_SIZE) { 175 offset->count += offset_nxt->count; 176 RB_REMOVE(file_offset_head, &priv_user->file_offset, 177 offset_nxt); 178 free(offset_nxt, M_GNTDEV); 179 } 180 if (offset_prv != NULL && 181 offset->file_offset == offset_prv->file_offset + offset_prv->count * 182 PAGE_SIZE) { 183 offset_prv->count += offset->count; 184 RB_REMOVE(file_offset_head, &priv_user->file_offset, offset); 185 free(offset, M_GNTDEV); 186 } 187 mtx_unlock(&priv_user->user_data_lock); 188 } 189 190 static int gntdev_gmap_pg_ctor(void *handle, vm_ooffset_t size, 191 vm_prot_t prot, vm_ooffset_t foff, struct ucred *cred, u_short *color); 192 static void gntdev_gmap_pg_dtor(void *handle); 193 static int gntdev_gmap_pg_fault(vm_object_t object, vm_ooffset_t offset, 194 int prot, vm_page_t *mres); 195 196 static struct cdev_pager_ops gntdev_gmap_pg_ops = { 197 .cdev_pg_fault = gntdev_gmap_pg_fault, 198 .cdev_pg_ctor = gntdev_gmap_pg_ctor, 199 .cdev_pg_dtor = gntdev_gmap_pg_dtor, 200 }; 201 202 struct cleanup_data_struct { 203 struct mtx to_kill_grefs_mtx; 204 struct mtx to_kill_gmaps_mtx; 205 struct gref_list_head to_kill_grefs; 206 struct gmap_list_head to_kill_gmaps; 207 }; 208 209 static struct cleanup_data_struct cleanup_data = { 210 .to_kill_grefs = STAILQ_HEAD_INITIALIZER(cleanup_data.to_kill_grefs), 211 .to_kill_gmaps = STAILQ_HEAD_INITIALIZER(cleanup_data.to_kill_gmaps), 212 }; 213 MTX_SYSINIT(to_kill_grefs_mtx, &cleanup_data.to_kill_grefs_mtx, 214 "gntdev to_kill_grefs mutex", MTX_DEF); 215 MTX_SYSINIT(to_kill_gmaps_mtx, &cleanup_data.to_kill_gmaps_mtx, 216 "gntdev to_kill_gmaps mutex", MTX_DEF); 217 218 static void cleanup_function(void *arg, __unused int pending); 219 static struct task cleanup_task = TASK_INITIALIZER(0, cleanup_function, 220 &cleanup_data); 221 222 struct notify_data { 223 uint64_t index; 224 uint32_t action; 225 uint32_t event_channel_port; 226 xen_intr_handle_t notify_evtchn_handle; 227 }; 228 229 static void notify(struct notify_data *notify, vm_page_t page); 230 231 /*-------------------- Grant Allocation Methods -----------------------------*/ 232 233 struct gntdev_gref { 234 union gref_next_union { 235 STAILQ_ENTRY(gntdev_gref) list; 236 RB_ENTRY(gntdev_gref) tree; 237 } gref_next; 238 uint64_t file_index; 239 grant_ref_t gref_id; 240 vm_page_t page; 241 struct notify_data *notify; 242 }; 243 244 static int 245 gref_cmp(struct gntdev_gref *g1, struct gntdev_gref *g2) 246 { 247 return (g1->file_index - g2->file_index); 248 } 249 250 RB_GENERATE_STATIC(gref_tree_head, gntdev_gref, gref_next.tree, gref_cmp); 251 252 /* 253 * Traverse over the device-list of to-be-deleted grants allocated, and 254 * if all accesses, both local mmaps and foreign maps, to them have ended, 255 * destroy them. 256 */ 257 static void 258 gref_list_dtor(struct cleanup_data_struct *cleanup_data) 259 { 260 struct gref_list_head tmp_grefs; 261 struct gntdev_gref *gref, *gref_tmp, *gref_previous; 262 263 STAILQ_INIT(&tmp_grefs); 264 mtx_lock(&cleanup_data->to_kill_grefs_mtx); 265 STAILQ_SWAP(&cleanup_data->to_kill_grefs, &tmp_grefs, gntdev_gref); 266 mtx_unlock(&cleanup_data->to_kill_grefs_mtx); 267 268 gref_previous = NULL; 269 STAILQ_FOREACH_SAFE(gref, &tmp_grefs, gref_next.list, gref_tmp) { 270 if (gref->page && gref->page->object == NULL) { 271 if (gref->notify) { 272 notify(gref->notify, gref->page); 273 } 274 if (gref->gref_id != GRANT_REF_INVALID) { 275 if (gnttab_query_foreign_access(gref->gref_id)) 276 continue; 277 if (gnttab_end_foreign_access_ref(gref->gref_id) 278 == 0) 279 continue; 280 gnttab_free_grant_reference(gref->gref_id); 281 } 282 vm_page_unwire(gref->page, PQ_NONE); 283 vm_page_free(gref->page); 284 gref->page = NULL; 285 } 286 if (gref->page == NULL) { 287 if (gref_previous == NULL) 288 STAILQ_REMOVE_HEAD(&tmp_grefs, gref_next.list); 289 else 290 STAILQ_REMOVE_AFTER(&tmp_grefs, gref_previous, 291 gref_next.list); 292 if (gref->notify) 293 free(gref->notify, M_GNTDEV); 294 free(gref, M_GNTDEV); 295 } 296 else 297 gref_previous = gref; 298 } 299 300 if (!STAILQ_EMPTY(&tmp_grefs)) { 301 mtx_lock(&cleanup_data->to_kill_grefs_mtx); 302 STAILQ_CONCAT(&cleanup_data->to_kill_grefs, &tmp_grefs); 303 mtx_unlock(&cleanup_data->to_kill_grefs_mtx); 304 } 305 } 306 307 /* 308 * Find count number of contiguous allocated grants for a given userspace 309 * program by file-offset (index). 310 */ 311 static struct gntdev_gref* 312 gntdev_find_grefs(struct per_user_data *priv_user, 313 uint64_t index, uint32_t count) 314 { 315 struct gntdev_gref find_gref, *gref, *gref_start = NULL; 316 317 find_gref.file_index = index; 318 319 mtx_lock(&priv_user->user_data_lock); 320 gref_start = RB_FIND(gref_tree_head, &priv_user->gref_tree, &find_gref); 321 for (gref = gref_start; gref != NULL && count > 0; gref = 322 RB_NEXT(gref_tree_head, &priv_user->gref_tree, gref)) { 323 if (index != gref->file_index) 324 break; 325 index += PAGE_SIZE; 326 count--; 327 } 328 mtx_unlock(&priv_user->user_data_lock); 329 330 if (count) 331 return (NULL); 332 return (gref_start); 333 } 334 335 /* 336 * IOCTL_GNTDEV_ALLOC_GREF 337 * Allocate required number of wired pages for the request, grant foreign 338 * access to the physical frames for these pages, and add details about 339 * this allocation to the per user private data, so that these pages can 340 * be mmapped by the userspace program. 341 */ 342 static int 343 gntdev_alloc_gref(struct ioctl_gntdev_alloc_gref *arg) 344 { 345 uint32_t i; 346 int error, readonly; 347 uint64_t file_offset; 348 struct gntdev_gref *grefs; 349 struct per_user_data *priv_user; 350 351 readonly = !(arg->flags & GNTDEV_ALLOC_FLAG_WRITABLE); 352 353 error = devfs_get_cdevpriv((void**) &priv_user); 354 if (error != 0) 355 return (EINVAL); 356 357 /* Cleanup grefs and free pages. */ 358 taskqueue_enqueue(taskqueue_thread, &cleanup_task); 359 360 /* Get file offset for this request. */ 361 error = get_file_offset(priv_user, arg->count, &file_offset); 362 if (error != 0) 363 return (error); 364 365 /* Allocate grefs. */ 366 grefs = malloc(sizeof(*grefs) * arg->count, M_GNTDEV, M_WAITOK); 367 368 for (i = 0; i < arg->count; i++) { 369 grefs[i].file_index = file_offset + i * PAGE_SIZE; 370 grefs[i].gref_id = GRANT_REF_INVALID; 371 grefs[i].notify = NULL; 372 grefs[i].page = vm_page_alloc(NULL, 0, VM_ALLOC_NORMAL 373 | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED | VM_ALLOC_ZERO); 374 if (grefs[i].page == NULL) { 375 log(LOG_ERR, "Page allocation failed."); 376 error = ENOMEM; 377 break; 378 } 379 if ((grefs[i].page->flags & PG_ZERO) == 0) { 380 /* 381 * Zero the allocated page, as we don't want to 382 * leak our memory to other domains. 383 */ 384 pmap_zero_page(grefs[i].page); 385 } 386 grefs[i].page->valid = VM_PAGE_BITS_ALL; 387 388 error = gnttab_grant_foreign_access(arg->domid, 389 (VM_PAGE_TO_PHYS(grefs[i].page) >> PAGE_SHIFT), 390 readonly, &grefs[i].gref_id); 391 if (error != 0) { 392 log(LOG_ERR, "Grant Table Hypercall failed."); 393 break; 394 } 395 } 396 397 if (error != 0) { 398 /* 399 * If target domain maps the gref (by guessing the gref-id), 400 * then we can't clean it up yet and we have to leave the 401 * page in place so as to not leak our memory to that domain. 402 * Add it to a global list to be cleaned up later. 403 */ 404 mtx_lock(&cleanup_data.to_kill_grefs_mtx); 405 for (i = 0; i < arg->count; i++) 406 STAILQ_INSERT_TAIL(&cleanup_data.to_kill_grefs, 407 &grefs[i], gref_next.list); 408 mtx_unlock(&cleanup_data.to_kill_grefs_mtx); 409 410 taskqueue_enqueue(taskqueue_thread, &cleanup_task); 411 412 return (error); 413 } 414 415 /* Copy the output values. */ 416 arg->index = file_offset; 417 for (i = 0; i < arg->count; i++) 418 arg->gref_ids[i] = grefs[i].gref_id; 419 420 /* Modify the per user private data. */ 421 mtx_lock(&priv_user->user_data_lock); 422 for (i = 0; i < arg->count; i++) 423 RB_INSERT(gref_tree_head, &priv_user->gref_tree, &grefs[i]); 424 mtx_unlock(&priv_user->user_data_lock); 425 426 return (error); 427 } 428 429 /* 430 * IOCTL_GNTDEV_DEALLOC_GREF 431 * Remove grant allocation information from the per user private data, so 432 * that it can't be mmapped anymore by the userspace program, and add it 433 * to the to-be-deleted grants global device-list. 434 */ 435 static int 436 gntdev_dealloc_gref(struct ioctl_gntdev_dealloc_gref *arg) 437 { 438 int error; 439 uint32_t count; 440 struct gntdev_gref *gref, *gref_tmp; 441 struct per_user_data *priv_user; 442 443 error = devfs_get_cdevpriv((void**) &priv_user); 444 if (error != 0) 445 return (EINVAL); 446 447 gref = gntdev_find_grefs(priv_user, arg->index, arg->count); 448 if (gref == NULL) { 449 log(LOG_ERR, "Can't find requested grant-refs."); 450 return (EINVAL); 451 } 452 453 /* Remove the grefs from user private data. */ 454 count = arg->count; 455 mtx_lock(&priv_user->user_data_lock); 456 mtx_lock(&cleanup_data.to_kill_grefs_mtx); 457 for (; gref != NULL && count > 0; gref = gref_tmp) { 458 gref_tmp = RB_NEXT(gref_tree_head, &priv_user->gref_tree, gref); 459 RB_REMOVE(gref_tree_head, &priv_user->gref_tree, gref); 460 STAILQ_INSERT_TAIL(&cleanup_data.to_kill_grefs, gref, 461 gref_next.list); 462 count--; 463 } 464 mtx_unlock(&cleanup_data.to_kill_grefs_mtx); 465 mtx_unlock(&priv_user->user_data_lock); 466 467 taskqueue_enqueue(taskqueue_thread, &cleanup_task); 468 put_file_offset(priv_user, arg->count, arg->index); 469 470 return (0); 471 } 472 473 /*-------------------- Grant Mapping Methods --------------------------------*/ 474 475 struct gntdev_gmap_map { 476 vm_object_t mem; 477 struct resource *pseudo_phys_res; 478 int pseudo_phys_res_id; 479 vm_paddr_t phys_base_addr; 480 }; 481 482 struct gntdev_gmap { 483 union gmap_next_union { 484 STAILQ_ENTRY(gntdev_gmap) list; 485 RB_ENTRY(gntdev_gmap) tree; 486 } gmap_next; 487 uint64_t file_index; 488 uint32_t count; 489 struct gnttab_map_grant_ref *grant_map_ops; 490 struct gntdev_gmap_map *map; 491 struct notify_data *notify; 492 }; 493 494 static int 495 gmap_cmp(struct gntdev_gmap *g1, struct gntdev_gmap *g2) 496 { 497 return (g1->file_index - g2->file_index); 498 } 499 500 RB_GENERATE_STATIC(gmap_tree_head, gntdev_gmap, gmap_next.tree, gmap_cmp); 501 502 /* 503 * Traverse over the device-list of to-be-deleted grant mappings, and if 504 * the region is no longer mmapped by anyone, free the memory used to 505 * store information about the mapping. 506 */ 507 static void 508 gmap_list_dtor(struct cleanup_data_struct *cleanup_data) 509 { 510 struct gmap_list_head tmp_gmaps; 511 struct gntdev_gmap *gmap, *gmap_tmp, *gmap_previous; 512 513 STAILQ_INIT(&tmp_gmaps); 514 mtx_lock(&cleanup_data->to_kill_gmaps_mtx); 515 STAILQ_SWAP(&cleanup_data->to_kill_gmaps, &tmp_gmaps, gntdev_gmap); 516 mtx_unlock(&cleanup_data->to_kill_gmaps_mtx); 517 518 gmap_previous = NULL; 519 STAILQ_FOREACH_SAFE(gmap, &tmp_gmaps, gmap_next.list, gmap_tmp) { 520 if (gmap->map == NULL) { 521 if (gmap_previous == NULL) 522 STAILQ_REMOVE_HEAD(&tmp_gmaps, gmap_next.list); 523 else 524 STAILQ_REMOVE_AFTER(&tmp_gmaps, gmap_previous, 525 gmap_next.list); 526 527 if (gmap->notify) 528 free(gmap->notify, M_GNTDEV); 529 free(gmap->grant_map_ops, M_GNTDEV); 530 free(gmap, M_GNTDEV); 531 } 532 else 533 gmap_previous = gmap; 534 } 535 536 if (!STAILQ_EMPTY(&tmp_gmaps)) { 537 mtx_lock(&cleanup_data->to_kill_gmaps_mtx); 538 STAILQ_CONCAT(&cleanup_data->to_kill_gmaps, &tmp_gmaps); 539 mtx_unlock(&cleanup_data->to_kill_gmaps_mtx); 540 } 541 } 542 543 /* 544 * Find mapped grants for a given userspace program, by file-offset (index) 545 * and count, as supplied during the map-ioctl. 546 */ 547 static struct gntdev_gmap* 548 gntdev_find_gmap(struct per_user_data *priv_user, 549 uint64_t index, uint32_t count) 550 { 551 struct gntdev_gmap find_gmap, *gmap; 552 553 find_gmap.file_index = index; 554 555 mtx_lock(&priv_user->user_data_lock); 556 gmap = RB_FIND(gmap_tree_head, &priv_user->gmap_tree, &find_gmap); 557 mtx_unlock(&priv_user->user_data_lock); 558 559 if (gmap != NULL && gmap->count == count) 560 return (gmap); 561 return (NULL); 562 } 563 564 /* 565 * Remove the pages from the mgtdevice pager, call the unmap hypercall, 566 * free the xenmem resource. This function is called during the 567 * destruction of the mgtdevice pager, which happens when all mmaps to 568 * it have been removed, and the unmap-ioctl has been performed. 569 */ 570 static int 571 notify_unmap_cleanup(struct gntdev_gmap *gmap) 572 { 573 uint32_t i; 574 int error, count; 575 vm_page_t m; 576 struct gnttab_unmap_grant_ref *unmap_ops; 577 578 unmap_ops = malloc(sizeof(struct gnttab_unmap_grant_ref) * gmap->count, 579 M_GNTDEV, M_WAITOK); 580 581 /* Enumerate freeable maps. */ 582 count = 0; 583 for (i = 0; i < gmap->count; i++) { 584 if (gmap->grant_map_ops[i].handle != -1) { 585 unmap_ops[count].handle = gmap->grant_map_ops[i].handle; 586 unmap_ops[count].host_addr = 587 gmap->grant_map_ops[i].host_addr; 588 unmap_ops[count].dev_bus_addr = 0; 589 count++; 590 } 591 } 592 593 /* Perform notification. */ 594 if (count > 0 && gmap->notify) { 595 vm_page_t page; 596 uint64_t page_offset; 597 598 page_offset = gmap->notify->index - gmap->file_index; 599 page = PHYS_TO_VM_PAGE(gmap->map->phys_base_addr + page_offset); 600 notify(gmap->notify, page); 601 } 602 603 /* Free the pages. */ 604 VM_OBJECT_WLOCK(gmap->map->mem); 605 retry: 606 for (i = 0; i < gmap->count; i++) { 607 m = vm_page_lookup(gmap->map->mem, i); 608 if (m == NULL) 609 continue; 610 if (vm_page_sleep_if_busy(m, "pcmdum")) 611 goto retry; 612 cdev_pager_free_page(gmap->map->mem, m); 613 } 614 VM_OBJECT_WUNLOCK(gmap->map->mem); 615 616 /* Perform unmap hypercall. */ 617 error = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, 618 unmap_ops, count); 619 620 for (i = 0; i < gmap->count; i++) { 621 gmap->grant_map_ops[i].handle = -1; 622 gmap->grant_map_ops[i].host_addr = 0; 623 } 624 625 if (gmap->map) { 626 error = xenmem_free(gntdev_dev, gmap->map->pseudo_phys_res_id, 627 gmap->map->pseudo_phys_res); 628 KASSERT(error == 0, 629 ("Unable to release memory resource: %d", error)); 630 631 free(gmap->map, M_GNTDEV); 632 gmap->map = NULL; 633 } 634 635 free(unmap_ops, M_GNTDEV); 636 637 return (error); 638 } 639 640 /* 641 * IOCTL_GNTDEV_MAP_GRANT_REF 642 * Populate structures for mapping the grant reference in the per user 643 * private data. Actual resource allocation and map hypercall is performed 644 * during the mmap. 645 */ 646 static int 647 gntdev_map_grant_ref(struct ioctl_gntdev_map_grant_ref *arg) 648 { 649 uint32_t i; 650 int error; 651 struct gntdev_gmap *gmap; 652 struct per_user_data *priv_user; 653 654 error = devfs_get_cdevpriv((void**) &priv_user); 655 if (error != 0) 656 return (EINVAL); 657 658 gmap = malloc(sizeof(*gmap), M_GNTDEV, M_WAITOK | M_ZERO); 659 gmap->count = arg->count; 660 gmap->grant_map_ops = 661 malloc(sizeof(struct gnttab_map_grant_ref) * arg->count, 662 M_GNTDEV, M_WAITOK | M_ZERO); 663 664 error = get_file_offset(priv_user, arg->count, &gmap->file_index); 665 if (error != 0) 666 return (error); 667 668 for (i = 0; i < arg->count; i++) { 669 gmap->grant_map_ops[i].dom = arg->refs[i].domid; 670 gmap->grant_map_ops[i].ref = arg->refs[i].ref; 671 gmap->grant_map_ops[i].handle = -1; 672 gmap->grant_map_ops[i].flags = GNTMAP_host_map; 673 } 674 675 mtx_lock(&priv_user->user_data_lock); 676 RB_INSERT(gmap_tree_head, &priv_user->gmap_tree, gmap); 677 mtx_unlock(&priv_user->user_data_lock); 678 679 arg->index = gmap->file_index; 680 681 return (error); 682 } 683 684 /* 685 * IOCTL_GNTDEV_UNMAP_GRANT_REF 686 * Remove the map information from the per user private data and add it 687 * to the global device-list of mappings to be deleted. A reference to 688 * the mgtdevice pager is also decreased, the reason for which is 689 * explained in mmap_gmap(). 690 */ 691 static int 692 gntdev_unmap_grant_ref(struct ioctl_gntdev_unmap_grant_ref *arg) 693 { 694 int error; 695 struct gntdev_gmap *gmap; 696 struct per_user_data *priv_user; 697 698 error = devfs_get_cdevpriv((void**) &priv_user); 699 if (error != 0) 700 return (EINVAL); 701 702 gmap = gntdev_find_gmap(priv_user, arg->index, arg->count); 703 if (gmap == NULL) { 704 log(LOG_ERR, "Can't find requested grant-map."); 705 return (EINVAL); 706 } 707 708 mtx_lock(&priv_user->user_data_lock); 709 mtx_lock(&cleanup_data.to_kill_gmaps_mtx); 710 RB_REMOVE(gmap_tree_head, &priv_user->gmap_tree, gmap); 711 STAILQ_INSERT_TAIL(&cleanup_data.to_kill_gmaps, gmap, gmap_next.list); 712 mtx_unlock(&cleanup_data.to_kill_gmaps_mtx); 713 mtx_unlock(&priv_user->user_data_lock); 714 715 if (gmap->map) 716 vm_object_deallocate(gmap->map->mem); 717 718 taskqueue_enqueue(taskqueue_thread, &cleanup_task); 719 put_file_offset(priv_user, arg->count, arg->index); 720 721 return (0); 722 } 723 724 /* 725 * IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR 726 * Get file-offset and count for a given mapping, from the virtual address 727 * where the mapping is mmapped. 728 * Please note, this only works for grants mapped by this domain, and not 729 * grants allocated. Count doesn't make much sense in reference to grants 730 * allocated. Also, because this function is present in the linux gntdev 731 * device, but not in the linux gntalloc one, most userspace code only use 732 * it for mapped grants. 733 */ 734 static int 735 gntdev_get_offset_for_vaddr(struct ioctl_gntdev_get_offset_for_vaddr *arg, 736 struct thread *td) 737 { 738 int error; 739 vm_map_t map; 740 vm_map_entry_t entry; 741 vm_object_t mem; 742 vm_pindex_t pindex; 743 vm_prot_t prot; 744 boolean_t wired; 745 struct gntdev_gmap *gmap; 746 747 map = &td->td_proc->p_vmspace->vm_map; 748 error = vm_map_lookup(&map, arg->vaddr, VM_PROT_NONE, &entry, 749 &mem, &pindex, &prot, &wired); 750 if (error != KERN_SUCCESS) 751 return (EINVAL); 752 vm_map_lookup_done(map, entry); 753 754 if ((mem->type != OBJT_MGTDEVICE) || 755 (mem->un_pager.devp.ops != &gntdev_gmap_pg_ops)) 756 return (EINVAL); 757 758 gmap = mem->handle; 759 if (gmap == NULL || 760 (entry->end - entry->start) != (gmap->count * PAGE_SIZE)) 761 return (EINVAL); 762 763 arg->count = gmap->count; 764 arg->offset = gmap->file_index; 765 return (0); 766 } 767 768 /*-------------------- Grant Mapping Pager ----------------------------------*/ 769 770 static int 771 gntdev_gmap_pg_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot, 772 vm_ooffset_t foff, struct ucred *cred, u_short *color) 773 { 774 775 return (0); 776 } 777 778 static void 779 gntdev_gmap_pg_dtor(void *handle) 780 { 781 782 notify_unmap_cleanup((struct gntdev_gmap *)handle); 783 } 784 785 static int 786 gntdev_gmap_pg_fault(vm_object_t object, vm_ooffset_t offset, int prot, 787 vm_page_t *mres) 788 { 789 struct gntdev_gmap *gmap = object->handle; 790 vm_pindex_t pidx, ridx; 791 vm_page_t page, oldm; 792 vm_ooffset_t relative_offset; 793 794 if (gmap->map == NULL) 795 return (VM_PAGER_FAIL); 796 797 relative_offset = offset - gmap->file_index; 798 799 pidx = OFF_TO_IDX(offset); 800 ridx = OFF_TO_IDX(relative_offset); 801 if (ridx >= gmap->count || 802 gmap->grant_map_ops[ridx].status != GNTST_okay) 803 return (VM_PAGER_FAIL); 804 805 page = PHYS_TO_VM_PAGE(gmap->map->phys_base_addr + relative_offset); 806 if (page == NULL) 807 return (VM_PAGER_FAIL); 808 809 KASSERT((page->flags & PG_FICTITIOUS) != 0, 810 ("not fictitious %p", page)); 811 KASSERT(page->wire_count == 1, ("wire_count not 1 %p", page)); 812 KASSERT(vm_page_busied(page) == 0, ("page %p is busy", page)); 813 814 if (*mres != NULL) { 815 oldm = *mres; 816 vm_page_lock(oldm); 817 vm_page_free(oldm); 818 vm_page_unlock(oldm); 819 *mres = NULL; 820 } 821 822 vm_page_insert(page, object, pidx); 823 page->valid = VM_PAGE_BITS_ALL; 824 vm_page_xbusy(page); 825 *mres = page; 826 return (VM_PAGER_OK); 827 } 828 829 /*------------------ Grant Table Methods ------------------------------------*/ 830 831 static void 832 notify(struct notify_data *notify, vm_page_t page) 833 { 834 if (notify->action & UNMAP_NOTIFY_CLEAR_BYTE) { 835 uint8_t *mem; 836 uint64_t offset; 837 838 offset = notify->index & PAGE_MASK; 839 mem = (uint8_t *)pmap_quick_enter_page(page); 840 mem[offset] = 0; 841 pmap_quick_remove_page((vm_offset_t)mem); 842 } 843 if (notify->action & UNMAP_NOTIFY_SEND_EVENT) { 844 xen_intr_signal(notify->notify_evtchn_handle); 845 xen_intr_unbind(¬ify->notify_evtchn_handle); 846 } 847 notify->action = 0; 848 } 849 850 /* 851 * Helper to copy new arguments from the notify ioctl into 852 * the existing notify data. 853 */ 854 static int 855 copy_notify_helper(struct notify_data *destination, 856 struct ioctl_gntdev_unmap_notify *source) 857 { 858 xen_intr_handle_t handlep = NULL; 859 860 /* 861 * "Get" before "Put"ting previous reference, as we might be 862 * holding the last reference to the event channel port. 863 */ 864 if (source->action & UNMAP_NOTIFY_SEND_EVENT) 865 if (xen_intr_get_evtchn_from_port(source->event_channel_port, 866 &handlep) != 0) 867 return (EINVAL); 868 869 if (destination->action & UNMAP_NOTIFY_SEND_EVENT) 870 xen_intr_unbind(&destination->notify_evtchn_handle); 871 872 destination->action = source->action; 873 destination->event_channel_port = source->event_channel_port; 874 destination->index = source->index; 875 destination->notify_evtchn_handle = handlep; 876 877 return (0); 878 } 879 880 /* 881 * IOCTL_GNTDEV_SET_UNMAP_NOTIFY 882 * Set unmap notification inside the appropriate grant. It sends a 883 * notification when the grant is completely munmapped by this domain 884 * and ready for destruction. 885 */ 886 static int 887 gntdev_set_unmap_notify(struct ioctl_gntdev_unmap_notify *arg) 888 { 889 int error; 890 uint64_t index; 891 struct per_user_data *priv_user; 892 struct gntdev_gref *gref = NULL; 893 struct gntdev_gmap *gmap; 894 895 error = devfs_get_cdevpriv((void**) &priv_user); 896 if (error != 0) 897 return (EINVAL); 898 899 if (arg->action & ~(UNMAP_NOTIFY_CLEAR_BYTE|UNMAP_NOTIFY_SEND_EVENT)) 900 return (EINVAL); 901 902 index = arg->index & ~PAGE_MASK; 903 gref = gntdev_find_grefs(priv_user, index, 1); 904 if (gref) { 905 if (gref->notify == NULL) 906 gref->notify = malloc(sizeof(*arg), M_GNTDEV, 907 M_WAITOK | M_ZERO); 908 return (copy_notify_helper(gref->notify, arg)); 909 } 910 911 error = EINVAL; 912 mtx_lock(&priv_user->user_data_lock); 913 RB_FOREACH(gmap, gmap_tree_head, &priv_user->gmap_tree) { 914 if (arg->index >= gmap->file_index && 915 arg->index < gmap->file_index + gmap->count * PAGE_SIZE) { 916 if (gmap->notify == NULL) 917 gmap->notify = malloc(sizeof(*arg), M_GNTDEV, 918 M_WAITOK | M_ZERO); 919 error = copy_notify_helper(gmap->notify, arg); 920 break; 921 } 922 } 923 mtx_unlock(&priv_user->user_data_lock); 924 925 return (error); 926 } 927 928 /*------------------ Gntdev Char Device Methods -----------------------------*/ 929 930 static void 931 cleanup_function(void *arg, __unused int pending) 932 { 933 934 gref_list_dtor((struct cleanup_data_struct *) arg); 935 gmap_list_dtor((struct cleanup_data_struct *) arg); 936 } 937 938 static void 939 per_user_data_dtor(void *arg) 940 { 941 struct gntdev_gref *gref, *gref_tmp; 942 struct gntdev_gmap *gmap, *gmap_tmp; 943 struct file_offset_struct *offset, *offset_tmp; 944 struct per_user_data *priv_user; 945 946 priv_user = (struct per_user_data *) arg; 947 948 mtx_lock(&priv_user->user_data_lock); 949 950 mtx_lock(&cleanup_data.to_kill_grefs_mtx); 951 RB_FOREACH_SAFE(gref, gref_tree_head, &priv_user->gref_tree, gref_tmp) { 952 RB_REMOVE(gref_tree_head, &priv_user->gref_tree, gref); 953 STAILQ_INSERT_TAIL(&cleanup_data.to_kill_grefs, gref, 954 gref_next.list); 955 } 956 mtx_unlock(&cleanup_data.to_kill_grefs_mtx); 957 958 mtx_lock(&cleanup_data.to_kill_gmaps_mtx); 959 RB_FOREACH_SAFE(gmap, gmap_tree_head, &priv_user->gmap_tree, gmap_tmp) { 960 RB_REMOVE(gmap_tree_head, &priv_user->gmap_tree, gmap); 961 STAILQ_INSERT_TAIL(&cleanup_data.to_kill_gmaps, gmap, 962 gmap_next.list); 963 if (gmap->map) 964 vm_object_deallocate(gmap->map->mem); 965 } 966 mtx_unlock(&cleanup_data.to_kill_gmaps_mtx); 967 968 RB_FOREACH_SAFE(offset, file_offset_head, &priv_user->file_offset, 969 offset_tmp) { 970 RB_REMOVE(file_offset_head, &priv_user->file_offset, offset); 971 free(offset, M_GNTDEV); 972 } 973 974 mtx_unlock(&priv_user->user_data_lock); 975 976 taskqueue_enqueue(taskqueue_thread, &cleanup_task); 977 978 mtx_destroy(&priv_user->user_data_lock); 979 free(priv_user, M_GNTDEV); 980 } 981 982 static int 983 gntdev_open(struct cdev *dev, int flag, int otyp, struct thread *td) 984 { 985 int error; 986 struct per_user_data *priv_user; 987 struct file_offset_struct *offset; 988 989 priv_user = malloc(sizeof(*priv_user), M_GNTDEV, M_WAITOK | M_ZERO); 990 RB_INIT(&priv_user->gref_tree); 991 RB_INIT(&priv_user->gmap_tree); 992 RB_INIT(&priv_user->file_offset); 993 offset = malloc(sizeof(*offset), M_GNTDEV, M_WAITOK | M_ZERO); 994 offset->file_offset = 0; 995 offset->count = MAX_OFFSET_COUNT; 996 RB_INSERT(file_offset_head, &priv_user->file_offset, offset); 997 mtx_init(&priv_user->user_data_lock, 998 "per user data mutex", NULL, MTX_DEF); 999 1000 error = devfs_set_cdevpriv(priv_user, per_user_data_dtor); 1001 if (error != 0) 1002 per_user_data_dtor(priv_user); 1003 1004 return (error); 1005 } 1006 1007 static int 1008 gntdev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, 1009 int fflag, struct thread *td) 1010 { 1011 int error; 1012 1013 switch (cmd) { 1014 case IOCTL_GNTDEV_SET_UNMAP_NOTIFY: 1015 error = gntdev_set_unmap_notify( 1016 (struct ioctl_gntdev_unmap_notify*) data); 1017 break; 1018 case IOCTL_GNTDEV_ALLOC_GREF: 1019 error = gntdev_alloc_gref( 1020 (struct ioctl_gntdev_alloc_gref*) data); 1021 break; 1022 case IOCTL_GNTDEV_DEALLOC_GREF: 1023 error = gntdev_dealloc_gref( 1024 (struct ioctl_gntdev_dealloc_gref*) data); 1025 break; 1026 case IOCTL_GNTDEV_MAP_GRANT_REF: 1027 error = gntdev_map_grant_ref( 1028 (struct ioctl_gntdev_map_grant_ref*) data); 1029 break; 1030 case IOCTL_GNTDEV_UNMAP_GRANT_REF: 1031 error = gntdev_unmap_grant_ref( 1032 (struct ioctl_gntdev_unmap_grant_ref*) data); 1033 break; 1034 case IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR: 1035 error = gntdev_get_offset_for_vaddr( 1036 (struct ioctl_gntdev_get_offset_for_vaddr*) data, td); 1037 break; 1038 default: 1039 error = ENOSYS; 1040 break; 1041 } 1042 1043 return (error); 1044 } 1045 1046 /* 1047 * MMAP an allocated grant into user memory. 1048 * Please note, that the grants must not already be mmapped, otherwise 1049 * this function will fail. 1050 */ 1051 static int 1052 mmap_gref(struct per_user_data *priv_user, struct gntdev_gref *gref_start, 1053 uint32_t count, vm_size_t size, struct vm_object **object) 1054 { 1055 vm_object_t mem_obj; 1056 struct gntdev_gref *gref; 1057 1058 mem_obj = vm_object_allocate(OBJT_PHYS, size); 1059 if (mem_obj == NULL) 1060 return (ENOMEM); 1061 1062 mtx_lock(&priv_user->user_data_lock); 1063 VM_OBJECT_WLOCK(mem_obj); 1064 for (gref = gref_start; gref != NULL && count > 0; gref = 1065 RB_NEXT(gref_tree_head, &priv_user->gref_tree, gref)) { 1066 if (gref->page->object) 1067 break; 1068 1069 vm_page_insert(gref->page, mem_obj, 1070 OFF_TO_IDX(gref->file_index)); 1071 1072 count--; 1073 } 1074 VM_OBJECT_WUNLOCK(mem_obj); 1075 mtx_unlock(&priv_user->user_data_lock); 1076 1077 if (count) { 1078 vm_object_deallocate(mem_obj); 1079 return (EINVAL); 1080 } 1081 1082 *object = mem_obj; 1083 1084 return (0); 1085 1086 } 1087 1088 /* 1089 * MMAP a mapped grant into user memory. 1090 */ 1091 static int 1092 mmap_gmap(struct per_user_data *priv_user, struct gntdev_gmap *gmap_start, 1093 vm_ooffset_t *offset, vm_size_t size, struct vm_object **object, int nprot) 1094 { 1095 uint32_t i; 1096 int error; 1097 1098 /* 1099 * The grant map hypercall might already be done. 1100 * If that is the case, increase a reference to the 1101 * vm object and return the already allocated object. 1102 */ 1103 if (gmap_start->map) { 1104 vm_object_reference(gmap_start->map->mem); 1105 *object = gmap_start->map->mem; 1106 return (0); 1107 } 1108 1109 gmap_start->map = malloc(sizeof(*(gmap_start->map)), M_GNTDEV, 1110 M_WAITOK | M_ZERO); 1111 1112 /* Allocate the xen pseudo physical memory resource. */ 1113 gmap_start->map->pseudo_phys_res_id = 0; 1114 gmap_start->map->pseudo_phys_res = xenmem_alloc(gntdev_dev, 1115 &gmap_start->map->pseudo_phys_res_id, size); 1116 if (gmap_start->map->pseudo_phys_res == NULL) { 1117 free(gmap_start->map, M_GNTDEV); 1118 gmap_start->map = NULL; 1119 return (ENOMEM); 1120 } 1121 gmap_start->map->phys_base_addr = 1122 rman_get_start(gmap_start->map->pseudo_phys_res); 1123 1124 /* Allocate the mgtdevice pager. */ 1125 gmap_start->map->mem = cdev_pager_allocate(gmap_start, OBJT_MGTDEVICE, 1126 &gntdev_gmap_pg_ops, size, nprot, *offset, NULL); 1127 if (gmap_start->map->mem == NULL) { 1128 xenmem_free(gntdev_dev, gmap_start->map->pseudo_phys_res_id, 1129 gmap_start->map->pseudo_phys_res); 1130 free(gmap_start->map, M_GNTDEV); 1131 gmap_start->map = NULL; 1132 return (ENOMEM); 1133 } 1134 1135 for (i = 0; i < gmap_start->count; i++) { 1136 gmap_start->grant_map_ops[i].host_addr = 1137 gmap_start->map->phys_base_addr + i * PAGE_SIZE; 1138 1139 if ((nprot & PROT_WRITE) == 0) 1140 gmap_start->grant_map_ops[i].flags |= GNTMAP_readonly; 1141 } 1142 /* Make the MAP hypercall. */ 1143 error = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, 1144 gmap_start->grant_map_ops, gmap_start->count); 1145 if (error != 0) { 1146 /* 1147 * Deallocate pager. 1148 * Pager deallocation will automatically take care of 1149 * xenmem deallocation, etc. 1150 */ 1151 vm_object_deallocate(gmap_start->map->mem); 1152 1153 return (EINVAL); 1154 } 1155 1156 /* Retry EAGAIN maps. */ 1157 for (i = 0; i < gmap_start->count; i++) { 1158 int delay = 1; 1159 while (delay < 256 && 1160 gmap_start->grant_map_ops[i].status == GNTST_eagain) { 1161 HYPERVISOR_grant_table_op( GNTTABOP_map_grant_ref, 1162 &gmap_start->grant_map_ops[i], 1); 1163 pause(("gntmap"), delay * SBT_1MS); 1164 delay++; 1165 } 1166 if (gmap_start->grant_map_ops[i].status == GNTST_eagain) 1167 gmap_start->grant_map_ops[i].status = GNTST_bad_page; 1168 1169 if (gmap_start->grant_map_ops[i].status != GNTST_okay) { 1170 /* 1171 * Deallocate pager. 1172 * Pager deallocation will automatically take care of 1173 * xenmem deallocation, notification, unmap hypercall, 1174 * etc. 1175 */ 1176 vm_object_deallocate(gmap_start->map->mem); 1177 1178 return (EINVAL); 1179 } 1180 } 1181 1182 /* 1183 * Add a reference to the vm object. We do not want 1184 * the vm object to be deleted when all the mmaps are 1185 * unmapped, because it may be re-mmapped. Instead, 1186 * we want the object to be deleted, when along with 1187 * munmaps, we have also processed the unmap-ioctl. 1188 */ 1189 vm_object_reference(gmap_start->map->mem); 1190 1191 *object = gmap_start->map->mem; 1192 1193 return (0); 1194 } 1195 1196 static int 1197 gntdev_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t size, 1198 struct vm_object **object, int nprot) 1199 { 1200 int error; 1201 uint32_t count; 1202 struct gntdev_gref *gref_start; 1203 struct gntdev_gmap *gmap_start; 1204 struct per_user_data *priv_user; 1205 1206 error = devfs_get_cdevpriv((void**) &priv_user); 1207 if (error != 0) 1208 return (EINVAL); 1209 1210 count = OFF_TO_IDX(size); 1211 1212 gref_start = gntdev_find_grefs(priv_user, *offset, count); 1213 if (gref_start) { 1214 error = mmap_gref(priv_user, gref_start, count, size, object); 1215 return (error); 1216 } 1217 1218 gmap_start = gntdev_find_gmap(priv_user, *offset, count); 1219 if (gmap_start) { 1220 error = mmap_gmap(priv_user, gmap_start, offset, size, object, 1221 nprot); 1222 return (error); 1223 } 1224 1225 return (EINVAL); 1226 } 1227 1228 /*------------------ Private Device Attachment Functions --------------------*/ 1229 static void 1230 gntdev_identify(driver_t *driver, device_t parent) 1231 { 1232 1233 KASSERT((xen_domain()), 1234 ("Trying to attach gntdev device on non Xen domain")); 1235 1236 if (BUS_ADD_CHILD(parent, 0, "gntdev", 0) == NULL) 1237 panic("unable to attach gntdev user-space device"); 1238 } 1239 1240 static int 1241 gntdev_probe(device_t dev) 1242 { 1243 1244 gntdev_dev = dev; 1245 device_set_desc(dev, "Xen grant-table user-space device"); 1246 return (BUS_PROBE_NOWILDCARD); 1247 } 1248 1249 static int 1250 gntdev_attach(device_t dev) 1251 { 1252 1253 make_dev_credf(MAKEDEV_ETERNAL, &gntdev_devsw, 0, NULL, UID_ROOT, 1254 GID_WHEEL, 0600, "xen/gntdev"); 1255 return (0); 1256 } 1257 1258 /*-------------------- Private Device Attachment Data -----------------------*/ 1259 static device_method_t gntdev_methods[] = { 1260 DEVMETHOD(device_identify, gntdev_identify), 1261 DEVMETHOD(device_probe, gntdev_probe), 1262 DEVMETHOD(device_attach, gntdev_attach), 1263 DEVMETHOD_END 1264 }; 1265 1266 static driver_t gntdev_driver = { 1267 "gntdev", 1268 gntdev_methods, 1269 0, 1270 }; 1271 1272 devclass_t gntdev_devclass; 1273 1274 DRIVER_MODULE(gntdev, xenpv, gntdev_driver, gntdev_devclass, 0, 0); 1275 MODULE_DEPEND(gntdev, xenpv, 1, 1, 1); 1276