[dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 Thread Loftus, Ciara
Hi Konstantin,

Thank you for the feedback. 

As regards the following:
"So if sizeof(ifr.ifr_name) > sizeof(dev->ifname) then we can endup with 
dev->ifname not being null-termianted?"
This should never be the case as now both dev->ifname and ifr.ifr_name are of 
size IFNAMSIZ in v2 of the patch.

Thanks,
Ciara

-Original Message-
From: Ananyev, Konstantin 
Sent: Thursday, December 18, 2014 5:03 PM
To: Loftus, Ciara; dev at dpdk.org
Cc: Anthony Fee
Subject: RE: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct



> -Original Message-
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of 
> ciara.loftus at intel.com
> Sent: Thursday, December 18, 2014 2:55 PM
> To: dev at dpdk.org
> Cc: Anthony Fee
> Subject: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net 
> struct
> 
> From: Ciara Loftus 
> 
> This patch fixes the issue whereby when using userspace vhost ports in 
> the context of vSwitching, the name provided to the hypervisor/QEMU of 
> the vhost tap device needs to be exposed in the library, in order for 
> the vSwitch to be able to direct packets to the correct device.
> This patch introduces an 'ifname' member to the virtio-net structure 
> which is populated with the tap device name when QEMU is brought up 
> with a vhost device.
> 
> Signed-off-by: Ciara Loftus 
> Signed-off-by: Anthony Fee 
> Acked-by: Huawei Xie 
> ---
>  lib/librte_vhost/rte_virtio_net.h |1 +
>  lib/librte_vhost/virtio-net.c |   41 
> -
>  2 files changed, 41 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/librte_vhost/rte_virtio_net.h 
> b/lib/librte_vhost/rte_virtio_net.h
> index 00b1328..aebb4b5 100644
> --- a/lib/librte_vhost/rte_virtio_net.h
> +++ b/lib/librte_vhost/rte_virtio_net.h
> @@ -96,6 +96,7 @@ struct virtio_net {
>   uint64_tfeatures;   /**< Negotiated feature set. */
>   uint64_tdevice_fh;  /**< device identifier. */
>   uint32_tflags;  /**< Device flags. Only used to 
> check if device is running on data core. */
> + charifname[32]; /** Name of the tap device **/
>   void*priv;  /**< private context */
>  } __rte_cache_aligned;
> 
> diff --git a/lib/librte_vhost/virtio-net.c 
> b/lib/librte_vhost/virtio-net.c index 852b6d1..7f90ecf 100644
> --- a/lib/librte_vhost/virtio-net.c
> +++ b/lib/librte_vhost/virtio-net.c
> @@ -43,6 +43,10 @@
>  #include 
>  #include 
> 
> +#include 
> +#include 
> +#include 
> +
>  #include 
>  #include 
>  #include 
> @@ -1000,6 +1004,39 @@ set_vring_kick(struct vhost_device_ctx ctx, 
> struct vhost_vring_file *file)  }
> 
>  /*
> + * Function to get the tap device name from the provided file 
> +descriptor and
> + * save it in the device structure.
> + */
> +static int
> +get_ifname(struct virtio_net *dev, int tap_fd, int pid) {
> + struct eventfd_copy fd_tap;
> + struct ifreq ifr;
> + uint32_t size;
> +
> + fd_tap.source_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
> + fd_tap.target_fd = tap_fd;
> + fd_tap.target_pid = pid;
> +
> + if (eventfd_copy(dev, &fd_tap))
> + return -1;
> +
> + ioctl(fd_tap.source_fd, TUNGETIFF, &ifr);

Shouldn't we check that ioctl() returns with success here, and if it fails, 
don't copy stuff over?

> +
> + if (close(fd_tap.source_fd) < 0)
> + RTE_LOG(ERR, VHOST_CONFIG,
> + "(%"PRIu64") fd close failed\n",
> + dev->device_fh);
> +
> + size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)) > 
> sizeof(dev->ifname)?
> + sizeof(dev->ifname): strnlen(ifr.ifr_name, 
> sizeof(ifr.ifr_name));
> +

So if sizeof(ifr.ifr_name) > sizeof(dev->ifname) then we can endup with 
dev->ifname not being null-termianted?
Another nit: there is no need to call strnlen() twice.

Konstantin

> + strncpy(dev->ifname, ifr.ifr_name, size);
> +
> + return 0;
> +}
> +
> +/*
>   * Called from CUSE IOCTL: VHOST_NET_SET_BACKEND
>   * To complete device initialisation when the virtio driver is loaded,
>   * we are provided with a valid fd for a tap device (not used by us).
> @@ -1026,8 +1063,10 @@ set_backend(struct vhost_device_ctx ctx, struct 
> vhost_vring_file *file)
>*/
>   if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
>   if (((int)dev->virtqueue[VIRTIO_TXQ]->backend != 
> VIRTIO_DEV_STOPPED) &&
> - ((int)dev->virtqueue[VIRTIO_RXQ]->backend != 

[dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 Thread Vincent JARDIN
>> +charifname[32]; /** Name of the tap device **/
>
> Linux and BSD the maximum network device name size is 16
>
In any case, please, use IF_NAMESIZE or IFNAMSIZ

see:
http://fxr.watson.org/fxr/ident?v=FREEBSD51;im=bigexcerpts;i=IF_NAMESIZE




[dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 Thread Czesnowicz, Przemyslaw

> Hi Thomas,
> 
> A basic vHost use case will work, for example a single Virtual Machine with a
> vHost port. However normal vSwitching use cases will require the use of 
> multiple
> vHost ports and multiple VMs. With that in mind, it is essential that the 
> vSwitch
> has some way of knowing which vHost port it is sending to and receiving 
> packets
> from. This patch resolves this issue by exposing the tap device name of the
> vHost device. Without that information we cannot determine the particular
> vHost port to send/receive from, which in the context of switching, is a 
> critical
> problem.


Exactly.
The vSwitch uses tap name to associate the virtio device with ovs port.
Without this change the vhost library cannot be used in vSwitch.

Regards
Przemek

> 
> Thanks,
> Ciara
> 



[dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 Thread Xie, Huawei
> -Original Message-
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Loftus, Ciara
> Sent: Thursday, December 18, 2014 10:02 AM
> To: Thomas Monjalon
> Cc: dev at dpdk.org; Anthony Fee
> Subject: Re: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct
> 
> Hi Thomas,
> 
> A basic vHost use case will work, for example a single Virtual Machine with a
> vHost port. However normal vSwitching use cases will require the use of 
> multiple
> vHost ports and multiple VMs. With that in mind, it is essential that the 
> vSwitch
> has some way of knowing which vHost port it is sending to and receiving 
> packets
> from. This patch resolves this issue by exposing the tap device name of the
> vHost device. Without that information we cannot determine the particular
> vHost port to send/receive from, which in the context of switching, is a 
> critical
> problem.


For example, in qemu command line, we specify tap device "tap1" for virtio 
device in "VM1", and "tap2" for virtio device in "VM2".
vSwitch wants to expose the tap device name in the virtio_net device structure 
otherwise it doesn't know the virtio_device it gets
is for which VM.
The mac address isn't enough for vSwitch.
The problem is for vhost-user, we have no such kind of identity, unless we 
create socket for each virtio device, and use the socket
path string.

> 
> Thanks,
> Ciara
> 
> -Original Message-
> From: Thomas Monjalon [mailto:thomas.monjalon at 6wind.com]
> Sent: Thursday, December 18, 2014 3:33 PM
> To: Loftus, Ciara
> Cc: dev at dpdk.org; Anthony Fee
> Subject: Re: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct
> 
> 2014-12-18 14:55, ciara.loftus at intel.com:
> > This patch fixes the issue whereby when using userspace vhost ports in
> > the context of vSwitching, the name provided to the hypervisor/QEMU of
> > the vhost tap device needs to be exposed in the library, in order for
> > the vSwitch to be able to direct packets to the correct device.
> 
> Do you mean that vhost was not working at all?
> Please precise the context and how it is critical.
> More informations are needed to understand wether it should be merged in
> release 1.8.0 or not.
> 
> > --- a/lib/librte_vhost/rte_virtio_net.h
> > +++ b/lib/librte_vhost/rte_virtio_net.h
> > @@ -96,6 +96,7 @@ struct virtio_net {
> > uint64_tfeatures;   /**< Negotiated feature set.
> */
> > uint64_tdevice_fh;  /**< device identifier. */
> > uint32_tflags;  /**< Device flags. Only used to
> check if device is running on data core. */
> > +   charifname[32]; /** Name of the tap device
> **/
> 
> Wrong comment style.
> 
> --
> Thomas 



[dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 Thread Ananyev, Konstantin


> -Original Message-
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of ciara.loftus at 
> intel.com
> Sent: Thursday, December 18, 2014 2:55 PM
> To: dev at dpdk.org
> Cc: Anthony Fee
> Subject: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct
> 
> From: Ciara Loftus 
> 
> This patch fixes the issue whereby when using userspace vhost ports
> in the context of vSwitching, the name provided to the hypervisor/QEMU
> of the vhost tap device needs to be exposed in the library, in order
> for the vSwitch to be able to direct packets to the correct device.
> This patch introduces an 'ifname' member to the virtio-net structure
> which is populated with the tap device name when QEMU is brought up
> with a vhost device.
> 
> Signed-off-by: Ciara Loftus 
> Signed-off-by: Anthony Fee 
> Acked-by: Huawei Xie 
> ---
>  lib/librte_vhost/rte_virtio_net.h |1 +
>  lib/librte_vhost/virtio-net.c |   41 
> -
>  2 files changed, 41 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/librte_vhost/rte_virtio_net.h 
> b/lib/librte_vhost/rte_virtio_net.h
> index 00b1328..aebb4b5 100644
> --- a/lib/librte_vhost/rte_virtio_net.h
> +++ b/lib/librte_vhost/rte_virtio_net.h
> @@ -96,6 +96,7 @@ struct virtio_net {
>   uint64_tfeatures;   /**< Negotiated feature set. */
>   uint64_tdevice_fh;  /**< device identifier. */
>   uint32_tflags;  /**< Device flags. Only used to 
> check if device is running on data core. */
> + charifname[32]; /** Name of the tap device **/
>   void*priv;  /**< private context */
>  } __rte_cache_aligned;
> 
> diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
> index 852b6d1..7f90ecf 100644
> --- a/lib/librte_vhost/virtio-net.c
> +++ b/lib/librte_vhost/virtio-net.c
> @@ -43,6 +43,10 @@
>  #include 
>  #include 
> 
> +#include 
> +#include 
> +#include 
> +
>  #include 
>  #include 
>  #include 
> @@ -1000,6 +1004,39 @@ set_vring_kick(struct vhost_device_ctx ctx, struct 
> vhost_vring_file *file)
>  }
> 
>  /*
> + * Function to get the tap device name from the provided file descriptor and
> + * save it in the device structure.
> + */
> +static int
> +get_ifname(struct virtio_net *dev, int tap_fd, int pid)
> +{
> + struct eventfd_copy fd_tap;
> + struct ifreq ifr;
> + uint32_t size;
> +
> + fd_tap.source_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
> + fd_tap.target_fd = tap_fd;
> + fd_tap.target_pid = pid;
> +
> + if (eventfd_copy(dev, &fd_tap))
> + return -1;
> +
> + ioctl(fd_tap.source_fd, TUNGETIFF, &ifr);

Shouldn't we check that ioctl() returns with success here,
and if it fails, don't copy stuff over?

> +
> + if (close(fd_tap.source_fd) < 0)
> + RTE_LOG(ERR, VHOST_CONFIG,
> + "(%"PRIu64") fd close failed\n",
> + dev->device_fh);
> +
> + size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)) > 
> sizeof(dev->ifname)?
> + sizeof(dev->ifname): strnlen(ifr.ifr_name, 
> sizeof(ifr.ifr_name));
> +

So if sizeof(ifr.ifr_name) > sizeof(dev->ifname) then we can endup with 
dev->ifname not being null-termianted?
Another nit: there is no need to call strnlen() twice.

Konstantin

> + strncpy(dev->ifname, ifr.ifr_name, size);
> +
> + return 0;
> +}
> +
> +/*
>   * Called from CUSE IOCTL: VHOST_NET_SET_BACKEND
>   * To complete device initialisation when the virtio driver is loaded,
>   * we are provided with a valid fd for a tap device (not used by us).
> @@ -1026,8 +1063,10 @@ set_backend(struct vhost_device_ctx ctx, struct 
> vhost_vring_file *file)
>*/
>   if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
>   if (((int)dev->virtqueue[VIRTIO_TXQ]->backend != 
> VIRTIO_DEV_STOPPED) &&
> - ((int)dev->virtqueue[VIRTIO_RXQ]->backend != 
> VIRTIO_DEV_STOPPED))
> + ((int)dev->virtqueue[VIRTIO_RXQ]->backend != 
> VIRTIO_DEV_STOPPED)) {
> + get_ifname(dev, file->fd, ctx.pid);
>   return notify_ops->new_device(dev);
> + }
>   /* Otherwise we remove it. */
>   } else
>   if (file->fd == VIRTIO_DEV_STOPPED)
> --
> 1.7.4.1



[dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 Thread Loftus, Ciara
Hi Thomas,

A basic vHost use case will work, for example a single Virtual Machine with a 
vHost port. However normal vSwitching use cases will require the use of 
multiple vHost ports and multiple VMs. With that in mind, it is essential that 
the vSwitch has some way of knowing which vHost port it is sending to and 
receiving packets from. This patch resolves this issue by exposing the tap 
device name of the vHost device. Without that information we cannot determine 
the particular vHost port to send/receive from, which in the context of 
switching, is a critical problem.

Thanks,
Ciara

-Original Message-
From: Thomas Monjalon [mailto:thomas.monja...@6wind.com] 
Sent: Thursday, December 18, 2014 3:33 PM
To: Loftus, Ciara
Cc: dev at dpdk.org; Anthony Fee
Subject: Re: [dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 14:55, ciara.loftus at intel.com:
> This patch fixes the issue whereby when using userspace vhost ports in 
> the context of vSwitching, the name provided to the hypervisor/QEMU of 
> the vhost tap device needs to be exposed in the library, in order for 
> the vSwitch to be able to direct packets to the correct device.

Do you mean that vhost was not working at all?
Please precise the context and how it is critical.
More informations are needed to understand wether it should be merged in 
release 1.8.0 or not.

> --- a/lib/librte_vhost/rte_virtio_net.h
> +++ b/lib/librte_vhost/rte_virtio_net.h
> @@ -96,6 +96,7 @@ struct virtio_net {
>   uint64_tfeatures;   /**< Negotiated feature set. */
>   uint64_tdevice_fh;  /**< device identifier. */
>   uint32_tflags;  /**< Device flags. Only used to 
> check if device is running on data core. */
> + charifname[32]; /** Name of the tap device **/

Wrong comment style.

--
Thomas
--
Intel Shannon Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263
Business address: Dromore House, East Park, Shannon, Co. Clare

This e-mail and any attachments may contain confidential material for the sole 
use of the intended recipient(s). Any review or distribution by others is 
strictly prohibited. If you are not the intended recipient, please contact the 
sender and delete all copies.




[dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 Thread Thomas Monjalon
2014-12-18 14:55, ciara.loftus at intel.com:
> This patch fixes the issue whereby when using userspace vhost ports
> in the context of vSwitching, the name provided to the hypervisor/QEMU
> of the vhost tap device needs to be exposed in the library, in order
> for the vSwitch to be able to direct packets to the correct device.

Do you mean that vhost was not working at all?
Please precise the context and how it is critical.
More informations are needed to understand wether it should be merged in
release 1.8.0 or not.

> --- a/lib/librte_vhost/rte_virtio_net.h
> +++ b/lib/librte_vhost/rte_virtio_net.h
> @@ -96,6 +96,7 @@ struct virtio_net {
>   uint64_tfeatures;   /**< Negotiated feature set. */
>   uint64_tdevice_fh;  /**< device identifier. */
>   uint32_tflags;  /**< Device flags. Only used to 
> check if device is running on data core. */
> + charifname[32]; /** Name of the tap device **/

Wrong comment style.

-- 
Thomas


[dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 Thread ciara.lof...@intel.com
From: Ciara Loftus 

This patch fixes the issue whereby when using userspace vhost ports
in the context of vSwitching, the name provided to the hypervisor/QEMU
of the vhost tap device needs to be exposed in the library, in order
for the vSwitch to be able to direct packets to the correct device.
This patch introduces an 'ifname' member to the virtio-net structure
which is populated with the tap device name when QEMU is brought up
with a vhost device.

Signed-off-by: Ciara Loftus 
Signed-off-by: Anthony Fee 
Acked-by: Huawei Xie 
---
 lib/librte_vhost/rte_virtio_net.h |1 +
 lib/librte_vhost/virtio-net.c |   41 -
 2 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/lib/librte_vhost/rte_virtio_net.h 
b/lib/librte_vhost/rte_virtio_net.h
index 00b1328..aebb4b5 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -96,6 +96,7 @@ struct virtio_net {
uint64_tfeatures;   /**< Negotiated feature set. */
uint64_tdevice_fh;  /**< device identifier. */
uint32_tflags;  /**< Device flags. Only used to 
check if device is running on data core. */
+   charifname[32]; /** Name of the tap device **/
void*priv;  /**< private context */
 } __rte_cache_aligned;

diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 852b6d1..7f90ecf 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -43,6 +43,10 @@
 #include 
 #include 

+#include 
+#include 
+#include 
+
 #include 
 #include 
 #include 
@@ -1000,6 +1004,39 @@ set_vring_kick(struct vhost_device_ctx ctx, struct 
vhost_vring_file *file)
 }

 /*
+ * Function to get the tap device name from the provided file descriptor and
+ * save it in the device structure.
+ */
+static int
+get_ifname(struct virtio_net *dev, int tap_fd, int pid)
+{
+   struct eventfd_copy fd_tap;
+   struct ifreq ifr;
+   uint32_t size;
+
+   fd_tap.source_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
+   fd_tap.target_fd = tap_fd;
+   fd_tap.target_pid = pid;
+
+   if (eventfd_copy(dev, &fd_tap))
+   return -1;
+
+   ioctl(fd_tap.source_fd, TUNGETIFF, &ifr);
+
+   if (close(fd_tap.source_fd) < 0)
+   RTE_LOG(ERR, VHOST_CONFIG,
+   "(%"PRIu64") fd close failed\n",
+   dev->device_fh);
+
+   size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)) > 
sizeof(dev->ifname)?
+   sizeof(dev->ifname): strnlen(ifr.ifr_name, 
sizeof(ifr.ifr_name));
+
+   strncpy(dev->ifname, ifr.ifr_name, size);
+
+   return 0;
+}
+
+/*
  * Called from CUSE IOCTL: VHOST_NET_SET_BACKEND
  * To complete device initialisation when the virtio driver is loaded,
  * we are provided with a valid fd for a tap device (not used by us).
@@ -1026,8 +1063,10 @@ set_backend(struct vhost_device_ctx ctx, struct 
vhost_vring_file *file)
 */
if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
if (((int)dev->virtqueue[VIRTIO_TXQ]->backend != 
VIRTIO_DEV_STOPPED) &&
-   ((int)dev->virtqueue[VIRTIO_RXQ]->backend != 
VIRTIO_DEV_STOPPED))
+   ((int)dev->virtqueue[VIRTIO_RXQ]->backend != 
VIRTIO_DEV_STOPPED)) {
+   get_ifname(dev, file->fd, ctx.pid);
return notify_ops->new_device(dev);
+   }
/* Otherwise we remove it. */
} else
if (file->fd == VIRTIO_DEV_STOPPED)
-- 
1.7.4.1



[dpdk-dev] [PATCH] vhost: add interface name to virtio-net struct

2014-12-18 Thread Stephen Hemminger
On Thu, 18 Dec 2014 14:55:23 +
ciara.loftus at intel.com wrote:

> diff --git a/lib/librte_vhost/rte_virtio_net.h 
> b/lib/librte_vhost/rte_virtio_net.h
> index 00b1328..aebb4b5 100644
> --- a/lib/librte_vhost/rte_virtio_net.h
> +++ b/lib/librte_vhost/rte_virtio_net.h
> @@ -96,6 +96,7 @@ struct virtio_net {
>   uint64_tfeatures;   /**< Negotiated feature set. */
>   uint64_tdevice_fh;  /**< device identifier. */
>   uint32_tflags;  /**< Device flags. Only used to 
> check if device is running on data core. */
> + charifname[32]; /** Name of the tap device **/

Linux and BSD the maximum network device name size is 16