|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [v4][PATCH 4/9] tools:libxc: check if mmio BAR is out of RMRR mappings
We need to avoid allocating MMIO BAR conflicting to RMRR range.
Signed-off-by: Tiejun Chen <tiejun.chen@xxxxxxxxx>
---
tools/libxc/xc_hvm_build_x86.c | 69 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/tools/libxc/xc_hvm_build_x86.c b/tools/libxc/xc_hvm_build_x86.c
index c81a25b..20e4e0c 100644
--- a/tools/libxc/xc_hvm_build_x86.c
+++ b/tools/libxc/xc_hvm_build_x86.c
@@ -239,6 +239,71 @@ static int check_mmio_hole(uint64_t start, uint64_t
memsize,
return 1;
}
+/*
+ * Check whether there exists mmio overplap with the specified RMRR
+ * memory range.
+ */
+static int check_rmrr_overlap(xc_interface *xch, uint64_t mmio_start,
+ uint64_t mmio_size)
+{
+ struct xen_reserved_device_memory *map = NULL;
+ uint64_t rmrr_start = 0, rmrr_end = 0;
+ unsigned int i = 0;
+ int rc = 0;
+
+ /* We should check if mmio range is out of RMRR mapping.
+ *
+ * Assume we have one entry if not enough we'll expand.
+ */
+ if ( (map = malloc(1 * sizeof(xen_reserved_device_memory_t))) == NULL )
+ {
+ PERROR("Could not allocate memory for map.");
+ return -1;
+ }
+ rc = xc_reserved_device_memory_map(xch, map, 1);
+ if ( rc < 0 )
+ {
+ /* RMRR doesn't exist. */
+ if ( rc == -ENOENT )
+ rc = 0;
+ else
+ PERROR("Could not get RMRR info on domain");
+ } else if ( rc > 0 ) {
+ free(map);
+ /* Now we need more space to map all RMRR mappings.
+ */
+ if ( (map = malloc(rc * sizeof(xen_reserved_device_memory_t))) == NULL
)
+ {
+ PERROR("Could not allocate memory for map.");
+ return -1;
+ }
+ rc = xc_reserved_device_memory_map(xch, map, rc);
+ if ( rc < 0 )
+ {
+ PERROR("Could not get RMRR info on domain");
+ free(map);
+ return rc;
+ }
+ }
+
+ for ( i = 0; i < rc; i++ )
+ {
+ rmrr_start = map[i].pfn << PAGE_SHIFT;
+ rmrr_end = rmrr_start + map[i].count * PAGE_SIZE;
+ if ( check_mmio_hole(rmrr_start, map[i].count * PAGE_SIZE,
+ mmio_start, mmio_size) )
+ {
+ PERROR("MMIO: [%lx]<->[%lx] overlap RMRR [%lx]<->[%lx]\n",
+ mmio_start, (mmio_start + mmio_size), rmrr_start, rmrr_end);
+ free(map);
+ return -1;
+ }
+ }
+
+ free(map);
+ return rc;
+}
+
static int setup_guest(xc_interface *xch,
uint32_t dom, struct xc_hvm_build_args *args,
char *image, unsigned long image_size)
@@ -300,6 +365,10 @@ static int setup_guest(xc_interface *xch,
goto error_out;
}
+ rc = check_rmrr_overlap(xch, mmio_start, mmio_start);
+ if ( rc < 0 )
+ goto error_out;
+
for ( i = 0; i < nr_pages; i++ )
page_array[i] = i;
for ( i = mmio_start >> PAGE_SHIFT; i < nr_pages; i++ )
--
1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |