libxl: pci passthrough fixes
PATCH 1/1 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.
PATCH 1/1 libxl: write PCI frontend xenstore nodes to the frontend directory
# HG changeset patch
# User Ian Campbell <[email protected]>
# 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.
tools/libxl/libxl_pci.c +5 -3
@@ -261,9 +261,11 @@ static int libxl_create_pci_backend(libxflexarray_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),
PATCH 1/1 libxl: do not leak front flexarray on error in libxl_create_pci_backend
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1294665479 0
# Node ID 3334667c23d1ce06628f768aafc0c683b1c5414e
# Parent e52d2333fb1616f9d0e30257a788d455fd44e6a2
libxl: do not leak front flexarray on error in libxl_create_pci_backend
tools/libxl/libxl_pci.c +12 -7
@@ -224,17 +224,19 @@ static int libxl_create_pci_backend(libxstatic 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(libxlibxl__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 ; }
PATCH 1/1 libxl: log which PCI device could not be reset
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1294665540 0
# Node ID 5ddd417071b01461c06f99e547052fd533b57d66 # Parent 3334667c23d1ce06628f768aafc0c683b1c5414e
libxl: log which PCI device could not be reset.
tools/libxl/libxl_pci.c +1 -1
@@ -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); }
PATCH 1/1 libxl: refactor code which adds per-PCI device backend nodes in xenstore
In reply to Ian Campbell# HG changeset patch
# User Ian Campbell <[email protected]>
# 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.
tools/libxl/libxl_pci.c +20 -25
@@ -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_xenstoreLIBXL__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 );
Re: [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"):
Quoted 1 line
libxl: refactor code which adds per-PCI device backend nodes in xenstore
I have applied all four.
Thanks,
Ian.