gntdev.c (d48524e21f1a49752485418324538755571ed13f) gntdev.c (38e3125d6df98919983ed800471673ff0e5c2337)
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

--- 549 unchanged lines hidden (view full) ---

558 * destruction of the mgtdevice pager, which happens when all mmaps to
559 * it have been removed, and the unmap-ioctl has been performed.
560 */
561static int
562notify_unmap_cleanup(struct gntdev_gmap *gmap)
563{
564 uint32_t i;
565 int error, count;
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

--- 549 unchanged lines hidden (view full) ---

558 * destruction of the mgtdevice pager, which happens when all mmaps to
559 * it have been removed, and the unmap-ioctl has been performed.
560 */
561static int
562notify_unmap_cleanup(struct gntdev_gmap *gmap)
563{
564 uint32_t i;
565 int error, count;
566 vm_page_t m;
567 struct gnttab_unmap_grant_ref *unmap_ops;
568
569 unmap_ops = malloc(sizeof(struct gnttab_unmap_grant_ref) * gmap->count,
570 M_GNTDEV, M_WAITOK);
571
572 /* Enumerate freeable maps. */
573 count = 0;
574 for (i = 0; i < gmap->count; i++) {

--- 12 unchanged lines hidden (view full) ---

587 uint64_t page_offset;
588
589 page_offset = gmap->notify->index - gmap->file_index;
590 page = PHYS_TO_VM_PAGE(gmap->map->phys_base_addr + page_offset);
591 notify(gmap->notify, page);
592 }
593
594 /* Free the pages. */
566 struct gnttab_unmap_grant_ref *unmap_ops;
567
568 unmap_ops = malloc(sizeof(struct gnttab_unmap_grant_ref) * gmap->count,
569 M_GNTDEV, M_WAITOK);
570
571 /* Enumerate freeable maps. */
572 count = 0;
573 for (i = 0; i < gmap->count; i++) {

--- 12 unchanged lines hidden (view full) ---

586 uint64_t page_offset;
587
588 page_offset = gmap->notify->index - gmap->file_index;
589 page = PHYS_TO_VM_PAGE(gmap->map->phys_base_addr + page_offset);
590 notify(gmap->notify, page);
591 }
592
593 /* Free the pages. */
595 VM_OBJECT_WLOCK(gmap->map->mem);
596retry:
597 for (i = 0; i < gmap->count; i++) {
598 m = vm_page_lookup(gmap->map->mem, i);
599 if (m == NULL)
600 continue;
601 if (vm_page_busy_acquire(m, VM_ALLOC_WAITFAIL) == 0)
602 goto retry;
603 cdev_mgtdev_pager_free_page(gmap->map->mem, m);
604 }
605 VM_OBJECT_WUNLOCK(gmap->map->mem);
594 cdev_mgtdev_pager_free_pages(gmap->map->mem);
606
607 /* Perform unmap hypercall. */
608 error = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
609 unmap_ops, count);
610
611 for (i = 0; i < gmap->count; i++) {
612 gmap->grant_map_ops[i].handle = -1;
613 gmap->grant_map_ops[i].host_addr = 0;

--- 666 unchanged lines hidden ---
595
596 /* Perform unmap hypercall. */
597 error = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
598 unmap_ops, count);
599
600 for (i = 0; i < gmap->count; i++) {
601 gmap->grant_map_ops[i].handle = -1;
602 gmap->grant_map_ops[i].host_addr = 0;

--- 666 unchanged lines hidden ---