[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH V7 1/3] libxl: Add support for generic virtio device


  • To: Viresh Kumar <viresh.kumar@xxxxxxxxxx>
  • From: Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Date: Fri, 9 Dec 2022 14:16:19 +0000
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: <xen-devel@xxxxxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Vincent Guittot <vincent.guittot@xxxxxxxxxx>, <stratos-dev@xxxxxxxxxxxxxxxxxxx>, Alex Bennée <alex.bennee@xxxxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxxxxx>, Mathieu Poirier <mathieu.poirier@xxxxxxxxxx>, Mike Holmes <mike.holmes@xxxxxxxxxx>, Oleksandr Tyshchenko <olekstysh@xxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 09 Dec 2022 14:16:52 +0000
  • Ironport-data: A9a23:xB4BiKJl0LrSahYaFE+RupIlxSXFcZb7ZxGr2PjKsXjdYENS12MAz GccCDvVM/qMMWuheo9zPNu19RtV6sDdy9M2QABlqX01Q3x08seUXt7xwmUcnc+xBpaaEB84t ZV2hv3odp1coqr0/0/1WlTZhSAgk/rOHv+kUrWs1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpJrfPdwP9TlK6q4mlB5ARvPaojUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c5oQm9f3 P5Dcgsscw/EptmfmJy/ZrFj05FLwMnDZOvzu1llxDDdS/0nXYrCU+PB4towMDUY354UW6yEP oxANGQpPE+ojx5nYz/7DLo3m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HbUQ2TQr2KhrGSoAEIdReeygdr79 YFT0EvMrbN5IBB/LzHCdODYq4dKQS8gcaVbDvlvgxQpN9RGtxdB2gQMHfjLnFL
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, Dec 09, 2022 at 05:43:54AM +0530, Viresh Kumar wrote:
> On 08-12-22, 18:06, Anthony PERARD wrote:
> > Nit: Something like:
> >     const char check[] = "virtio,device";
> >     const size_t checkl = sizeof(check) - 1;
> >     ... strncmp(tmp, check, checkl)...
> >     (or just strncmp(tmp, check, sizeof(check)-1))
> > would avoid issue with both string "virtio,device" potentially been
> > different.
> 
> I think that is a generic problem with all the strings I am using. What about
> this diff over current patch ?
> 
> diff --git a/tools/libs/light/libxl_internal.h 
> b/tools/libs/light/libxl_internal.h
> index cdd155d925c1..a062fca0e2bb 100644
> --- a/tools/libs/light/libxl_internal.h
> +++ b/tools/libs/light/libxl_internal.h
> @@ -166,6 +166,11 @@
>  /* Convert pfn to physical address space. */
>  #define pfn_to_paddr(x) ((uint64_t)(x) << XC_PAGE_SHIFT)
>  
> +/* Virtio device types */
> +#define VIRTIO_DEVICE_TYPE_GENERIC   "virtio,device"
> +#define VIRTIO_DEVICE_TYPE_GPIO      "virtio,device22"
> +#define VIRTIO_DEVICE_TYPE_I2C       "virtio,device29"

That a good idea.

>  /* logging */
>  _hidden void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int 
> errnoval,
>               const char *file /* may be 0 */, int line /* ignored if !file 
> */,
> diff --git a/tools/libs/light/libxl_virtio.c b/tools/libs/light/libxl_virtio.c
> index 64cec989c674..183d9c906e27 100644
> --- a/tools/libs/light/libxl_virtio.c
> +++ b/tools/libs/light/libxl_virtio.c
> @@ -62,7 +62,7 @@ static int libxl__virtio_from_xenstore(libxl__gc *gc, const 
> char *libxl_path,
>                                         libxl_device_virtio *virtio)
>  {
>      const char *be_path, *tmp = NULL;
> -    int rc;
> +    int rc, len = sizeof(VIRTIO_DEVICE_TYPE_GENERIC) - 1;

That `len` variable is initialized quite far away from where it's used,
so ...
>  
>      virtio->devid = devid;
>  
> @@ -112,8 +110,8 @@ static int libxl__virtio_from_xenstore(libxl__gc *gc, 
> const char *libxl_path,
>      if (rc) goto out;
>  
>      if (tmp) {

... you could declare `len` here instead.

> -        if (!strncmp(tmp, "virtio,device", strlen("virtio,device"))) {
> -            virtio->type = strdup(tmp);
> +        if (!strncmp(tmp, VIRTIO_DEVICE_TYPE_GENERIC, len)) {
> +            virtio->type = libxl__strdup(NOGC, tmp);
>          } else {
>              return ERROR_INVAL;
>          }
> 


Otherwise, those change looks fine.
Thanks,

-- 
Anthony PERARD



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.