Ian Campbell
2011-Jan-10 13:20 UTC
[Xen-devel] [PATCH 0 of 4] libxl: pci passthrough fixes
The following contains a couple of fixes (first two patches) and a couple of cleanups (second two patches) for libxl PCI passthrough. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2011-Jan-10 13:20 UTC
[Xen-devel] [PATCH 1 of 4] libxl: write PCI frontend xenstore nodes to the frontend directory
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1294665479 0 # Node ID e52d2333fb1616f9d0e30257a788d455fd44e6a2 # Parent 8326f4a35023d1bdaaff5bdd8d9a95ffdc020e2e libxl: write PCI frontend xenstore nodes to the frontend directory. They accidentally got moved to the backend directory by 22680:03718b569d97. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 8326f4a35023 -r e52d2333fb16 tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Mon Jan 10 11:01:39 2011 +0000 +++ b/tools/libxl/libxl_pci.c Mon Jan 10 13:17:59 2011 +0000 @@ -261,9 +261,11 @@ static int libxl_create_pci_backend(libx flexarray_append(back, libxl__sprintf(gc, "msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt)); flexarray_vappend(back, libxl__sprintf(gc, "state-%d", i), libxl__sprintf(gc, "%d", 1), NULL); } - flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num), - "backend-id", libxl__sprintf(gc, "%d", 0), - "state", libxl__sprintf(gc, "%d", 1), NULL); + flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num)); + + flexarray_vappend(front, + "backend-id", libxl__sprintf(gc, "%d", 0), + "state", libxl__sprintf(gc, "%d", 1), NULL); libxl__device_generic_add(ctx, &device, libxl__xs_kvs_of_flexarray(gc, back, back->count), _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2011-Jan-10 13:20 UTC
[Xen-devel] [PATCH 2 of 4] libxl: do not leak front flexarray on error in libxl_create_pci_backend
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1294665479 0 # Node ID 3334667c23d1ce06628f768aafc0c683b1c5414e # Parent e52d2333fb1616f9d0e30257a788d455fd44e6a2 libxl: do not leak front flexarray on error in libxl_create_pci_backend Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r e52d2333fb16 -r 3334667c23d1 tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Mon Jan 10 13:17:59 2011 +0000 +++ b/tools/libxl/libxl_pci.c Mon Jan 10 13:17:59 2011 +0000 @@ -224,17 +224,19 @@ static int libxl_create_pci_backend(libx static int libxl_create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int num) { libxl_ctx *ctx = libxl__gc_owner(gc); - flexarray_t *front; - flexarray_t *back; + flexarray_t *front = NULL; + flexarray_t *back = NULL; libxl__device device; - int i; + int ret = ERROR_NOMEM, i; front = flexarray_make(16, 1); if (!front) - return ERROR_NOMEM; + goto out; back = flexarray_make(16, 1); if (!back) - return ERROR_NOMEM; + goto out; + + ret = 0; LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Creating pci backend"); @@ -271,8 +273,11 @@ static int libxl_create_pci_backend(libx libxl__xs_kvs_of_flexarray(gc, back, back->count), libxl__xs_kvs_of_flexarray(gc, front, front->count)); - flexarray_free(back); - flexarray_free(front); +out: + if (back) + flexarray_free(back); + if (front) + flexarray_free(front); return 0; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2011-Jan-10 13:20 UTC
[Xen-devel] [PATCH 3 of 4] libxl: log which PCI device could not be reset
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1294665540 0 # Node ID 5ddd417071b01461c06f99e547052fd533b57d66 # Parent 3334667c23d1ce06628f768aafc0c683b1c5414e libxl: log which PCI device could not be reset. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 3334667c23d1 -r 5ddd417071b0 tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Mon Jan 10 13:17:59 2011 +0000 +++ b/tools/libxl/libxl_pci.c Mon Jan 10 13:19:00 2011 +0000 @@ -756,7 +756,7 @@ static int libxl_device_pci_reset(libxl_ return rc < 0 ? rc : 0; } if (errno == ENOENT) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "The kernel doesn''t support PCI device reset from sysfs"); + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "The kernel doesn''t support reset from sysfs for PCI device "PCI_BDF, domain, bus, dev, func); } else { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Failed to access reset path %s", reset); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2011-Jan-10 13:20 UTC
[Xen-devel] [PATCH 4 of 4] libxl: refactor code which adds per-PCI device backend nodes in xenstore
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1294665593 0 # Node ID fef5b51177bd82e1168051a934bb91f65c61d8bb # Parent 5ddd417071b01461c06f99e547052fd533b57d66 libxl: refactor code which adds per-PCI device backend nodes in xenstore libxl_create_pci_backend and libxl_device_pci_add_xenstore contains identical code to setup the per device xenstore nodes in the backend. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 5ddd417071b0 -r fef5b51177bd tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Mon Jan 10 13:19:00 2011 +0000 +++ b/tools/libxl/libxl_pci.c Mon Jan 10 13:19:53 2011 +0000 @@ -221,6 +221,19 @@ parse_error: return ERROR_INVAL; } +static void libxl_create_pci_backend_device(libxl__gc *gc, flexarray_t *back, int num, libxl_device_pci *pcidev) +{ + flexarray_append(back, libxl__sprintf(gc, "key-%d", num)); + flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func)); + flexarray_append(back, libxl__sprintf(gc, "dev-%d", num)); + flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func)); + if (pcidev->vdevfn) + flexarray_vappend(back, libxl__sprintf(gc, "vdevfn-%d", num), libxl__sprintf(gc, "%x", pcidev->vdevfn), NULL); + flexarray_append(back, libxl__sprintf(gc, "opts-%d", num)); + flexarray_append(back, libxl__sprintf(gc, "msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt)); + flexarray_vappend(back, libxl__sprintf(gc, "state-%d", num), libxl__sprintf(gc, "%d", 1), NULL); +} + static int libxl_create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int num) { libxl_ctx *ctx = libxl__gc_owner(gc); @@ -249,20 +262,12 @@ static int libxl_create_pci_backend(libx device.kind = DEVICE_PCI; flexarray_vappend(back, "frontend-id", libxl__sprintf(gc, "%d", domid), - "online", "1", "state", libxl__sprintf(gc, "%d", 1), - "domain", libxl__domid_to_name(gc, domid), NULL); - for (i = 0; i < num; i++) { - flexarray_append(back, libxl__sprintf(gc, "key-%d", i)); - flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func)); - flexarray_append(back, libxl__sprintf(gc, "dev-%d", i)); - flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func)); - if (pcidev->vdevfn) { - flexarray_vappend(back, libxl__sprintf(gc, "vdevfn-%d", i), libxl__sprintf(gc, "%x", pcidev->vdevfn), NULL); - } - flexarray_append(back, libxl__sprintf(gc, "opts-%d", i)); - flexarray_append(back, libxl__sprintf(gc, "msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt)); - flexarray_vappend(back, libxl__sprintf(gc, "state-%d", i), libxl__sprintf(gc, "%d", 1), NULL); - } + "online", "1", "state", libxl__sprintf(gc, "%d", 1), + "domain", libxl__domid_to_name(gc, domid), NULL); + + for (i = 0; i < num; i++, pcidev++) + libxl_create_pci_backend_device(gc, back, i, pcidev); + flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num)); flexarray_vappend(front, @@ -305,17 +310,7 @@ static int libxl_device_pci_add_xenstore LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Adding new pci device to xenstore"); num = atoi(num_devs); - flexarray_append(back, libxl__sprintf(gc, "key-%d", num)); - flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func)); - flexarray_append(back, libxl__sprintf(gc, "dev-%d", num)); - flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func)); - if (pcidev->vdevfn) { - flexarray_append(back, libxl__sprintf(gc, "vdevfn-%d", num)); - flexarray_append(back, libxl__sprintf(gc, "%x", pcidev->vdevfn)); - } - flexarray_append(back, libxl__sprintf(gc, "opts-%d", num)); - flexarray_append(back, libxl__sprintf(gc, "msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt)); - flexarray_vappend(back, libxl__sprintf(gc, "state-%d", num), libxl__sprintf(gc, "%d", 1), NULL); + libxl_create_pci_backend_device(gc, back, num, pcidev); flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num + 1), NULL); flexarray_vappend(back, "state", libxl__sprintf(gc, "%d", 7), NULL); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2011-Jan-11 18:17 UTC
Re: [Xen-devel] [PATCH 4 of 4] libxl: refactor code which adds per-PCI device backend nodes in xenstore
Ian Campbell writes ("[Xen-devel] [PATCH 4 of 4] libxl: refactor code which adds per-PCI device backend nodes in xenstore"):> libxl: refactor code which adds per-PCI device backend nodes in xenstoreI have applied all four. Thanks, Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel