aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllen M Kay <allen.m.kay@intel.com>2011-03-16 17:08:27 +0000
committerAllen M Kay <allen.m.kay@intel.com>2011-03-16 17:08:27 +0000
commit40b7da8a313792702da191a93aa8ed25d6d8821c (patch)
tree3d8bb69dbc94c24491fc5fb7e6e891206aed794b
parentf21647ecc2b3be3df191bb75cea5c107d6498767 (diff)
downloadxen-40b7da8a313792702da191a93aa8ed25d6d8821c.tar.gz
xen-40b7da8a313792702da191a93aa8ed25d6d8821c.tar.bz2
xen-40b7da8a313792702da191a93aa8ed25d6d8821c.zip
libxl: passthrough: avoid passing through devices not owned by pciback
This patch makes sure the passthrough device belongs to pciback before allow them passthrough to the guest. There are still many other checks missing. xm terminates the guest startup process when this type of condition is found. This patch just allows the guest to continue to boot but with no device passthrough. Signed-off-by: Allen Kay <allen.m.kay@intel.com> Acked-by: Gianni Tedesco <gianni.tedesco@citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
-rw-r--r--tools/libxl/libxl_pci.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index 56ec063888..6b5f715e29 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -763,6 +763,24 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcide
return libxl__device_pci_add(ctx, domid, pcidev, 0);
}
+static int libxl_pcidev_assignable(libxl_ctx *ctx, libxl_device_pci *pcidev)
+{
+ libxl_device_pci *pcidevs;
+ int num, i;
+
+ libxl_device_pci_list_assignable(ctx, &pcidevs, &num);
+ for (i = 0; i < num; i++) {
+ if (pcidevs[i].domain == pcidev->domain &&
+ pcidevs[i].bus == pcidev->bus &&
+ pcidevs[i].dev == pcidev->dev &&
+ pcidevs[i].func == pcidev->func)
+ {
+ return 1;
+ }
+ }
+ return 0;
+}
+
int libxl__device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev, int starting)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
@@ -771,6 +789,13 @@ int libxl__device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcid
int num_assigned, i, rc;
int stubdomid = 0;
+ if (!libxl_pcidev_assignable(ctx, pcidev)) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "PCI device %x:%x:%x.%x is not assignable",
+ pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func);
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
rc = get_all_assigned_devices(&gc, &assigned, &num_assigned);
if ( rc ) {
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot determine if device is assigned, refusing to continue");