Use the new reserved_regions API to ensure that RAM doesn't overlap any reserved region. This prevents for instance from mapping an MSI doorbell into the guest IOVA space. For the moment we reject any overlapping. In the future, we might carve reserved regions out of the guest physical space. Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@xxxxxxx> --- vfio.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/vfio.c b/vfio.c index 0f6c2f24..f4fd4090 100644 --- a/vfio.c +++ b/vfio.c @@ -870,6 +870,36 @@ static int vfio_configure_dev_irqs(struct kvm *kvm, struct vfio_device *device) return ret; } +static int vfio_configure_reserved_regions(struct kvm *kvm, + struct vfio_group *group) +{ + int ret = 0; + FILE *file; + char filename[PATH_MAX]; + unsigned long long start, end; + char type[9]; + + snprintf(filename, PATH_MAX, IOMMU_GROUP_DIR "/%lu/reserved_regions", + group->id); + + if (access(filename, F_OK)) + return 0; + + file = fopen(filename, "r"); + if (!file) + return -errno; + + while (fscanf(file, "0x%llx 0x%llx %8s\n", &start, &end, type) == 3) { + ret = kvm__reserve_mem(kvm, start, end - start + 1); + if (ret) + break; + } + + fclose(file); + + return ret; +} + static int vfio_configure_device(struct kvm *kvm, struct vfio_group *group, struct dirent *dirent) { @@ -967,6 +997,10 @@ static int vfio_configure_iommu_groups(struct kvm *kvm) if (closedir(dir)) pr_warning("Failed to close IOMMU group %s", dirpath); + + ret = vfio_configure_reserved_regions(kvm, group); + if (ret) + return ret; } return 0; -- 2.12.1