vfio-helpers.c (95a9457fd44ad97c518858a4e1586a5498f9773c) vfio-helpers.c (038adc2f5850e32019bda06c559d0301be436eae)
1/*
2 * VFIO utility
3 *
4 * Copyright 2016 - 2018 Red Hat, Inc.
5 *
6 * Authors:
7 * Fam Zheng <famz@redhat.com>
8 *

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

509static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
510 void *host, size_t size,
511 int index, uint64_t iova)
512{
513 int shift;
514 IOVAMapping m = {.host = host, .size = size, .iova = iova};
515 IOVAMapping *insert;
516
1/*
2 * VFIO utility
3 *
4 * Copyright 2016 - 2018 Red Hat, Inc.
5 *
6 * Authors:
7 * Fam Zheng <famz@redhat.com>
8 *

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

509static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
510 void *host, size_t size,
511 int index, uint64_t iova)
512{
513 int shift;
514 IOVAMapping m = {.host = host, .size = size, .iova = iova};
515 IOVAMapping *insert;
516
517 assert(QEMU_IS_ALIGNED(size, getpagesize()));
518 assert(QEMU_IS_ALIGNED(s->low_water_mark, getpagesize()));
519 assert(QEMU_IS_ALIGNED(s->high_water_mark, getpagesize()));
517 assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
518 assert(QEMU_IS_ALIGNED(s->low_water_mark, qemu_real_host_page_size));
519 assert(QEMU_IS_ALIGNED(s->high_water_mark, qemu_real_host_page_size));
520 trace_qemu_vfio_new_mapping(s, host, size, index, iova);
521
522 assert(index >= 0);
523 s->nr_mappings++;
524 s->mappings = g_renew(IOVAMapping, s->mappings, s->nr_mappings);
525 insert = &s->mappings[index];
526 shift = s->nr_mappings - index - 1;
527 if (shift) {

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

562 .argsz = sizeof(unmap),
563 .flags = 0,
564 .iova = mapping->iova,
565 .size = mapping->size,
566 };
567
568 index = mapping - s->mappings;
569 assert(mapping->size > 0);
520 trace_qemu_vfio_new_mapping(s, host, size, index, iova);
521
522 assert(index >= 0);
523 s->nr_mappings++;
524 s->mappings = g_renew(IOVAMapping, s->mappings, s->nr_mappings);
525 insert = &s->mappings[index];
526 shift = s->nr_mappings - index - 1;
527 if (shift) {

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

562 .argsz = sizeof(unmap),
563 .flags = 0,
564 .iova = mapping->iova,
565 .size = mapping->size,
566 };
567
568 index = mapping - s->mappings;
569 assert(mapping->size > 0);
570 assert(QEMU_IS_ALIGNED(mapping->size, getpagesize()));
570 assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size));
571 assert(index >= 0 && index < s->nr_mappings);
572 if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
573 error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
574 }
575 memmove(mapping, &s->mappings[index + 1],
576 sizeof(s->mappings[0]) * (s->nr_mappings - index - 1));
577 s->nr_mappings--;
578 s->mappings = g_renew(IOVAMapping, s->mappings, s->nr_mappings);

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

608int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
609 bool temporary, uint64_t *iova)
610{
611 int ret = 0;
612 int index;
613 IOVAMapping *mapping;
614 uint64_t iova0;
615
571 assert(index >= 0 && index < s->nr_mappings);
572 if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
573 error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
574 }
575 memmove(mapping, &s->mappings[index + 1],
576 sizeof(s->mappings[0]) * (s->nr_mappings - index - 1));
577 s->nr_mappings--;
578 s->mappings = g_renew(IOVAMapping, s->mappings, s->nr_mappings);

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

608int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
609 bool temporary, uint64_t *iova)
610{
611 int ret = 0;
612 int index;
613 IOVAMapping *mapping;
614 uint64_t iova0;
615
616 assert(QEMU_PTR_IS_ALIGNED(host, getpagesize()));
617 assert(QEMU_IS_ALIGNED(size, getpagesize()));
616 assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
617 assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
618 trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
619 qemu_mutex_lock(&s->lock);
620 mapping = qemu_vfio_find_mapping(s, host, &index);
621 if (mapping) {
622 iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
623 } else {
624 if (s->high_water_mark - s->low_water_mark + 1 < size) {
625 ret = -ENOMEM;

--- 99 unchanged lines hidden ---
618 trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
619 qemu_mutex_lock(&s->lock);
620 mapping = qemu_vfio_find_mapping(s, host, &index);
621 if (mapping) {
622 iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
623 } else {
624 if (s->high_water_mark - s->low_water_mark + 1 < size) {
625 ret = -ENOMEM;

--- 99 unchanged lines hidden ---