Commit 41d773e2 authored by Jean-Philippe Brucker's avatar Jean-Philippe Brucker Committed by Will Deacon
Browse files

vfio: check reserved regions before mapping DMA



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 IPA space. For the moment we reject any overlapping. In the
future, we might carve reserved regions out of the guest physical
space.

Reviewed-by: default avatarPunit Agrawal <punit.agrawal@arm.com>
Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent fa1076ab
......@@ -379,6 +379,51 @@ static int vfio_unmap_mem_bank(struct kvm *kvm, struct kvm_mem_bank *bank, void
return 0;
}
static int vfio_configure_reserved_regions(struct kvm *kvm,
struct vfio_group *group)
{
FILE *file;
int ret = 0;
char type[9];
char filename[PATH_MAX];
unsigned long long start, end;
snprintf(filename, PATH_MAX, IOMMU_GROUP_DIR "/%lu/reserved_regions",
group->id);
/* reserved_regions might not be present on older systems */
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_groups(struct kvm *kvm)
{
int ret;
struct vfio_group *group;
list_for_each_entry(group, &vfio_groups, list) {
ret = vfio_configure_reserved_regions(kvm, group);
if (ret)
return ret;
}
return 0;
}
static struct vfio_group *vfio_group_create(struct kvm *kvm, unsigned long id)
{
int ret;
......@@ -597,6 +642,10 @@ static int vfio__init(struct kvm *kvm)
if (ret)
return ret;
ret = vfio_configure_groups(kvm);
if (ret)
return ret;
ret = vfio_configure_devices(kvm);
if (ret)
return ret;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment