diff mbox series

[v7,net-next,3/4] virtio_net: Extend virtio to use VF datapath when available

Message ID 1524188524-28411-4-git-send-email-sridhar.samudrala@intel.com
State Changes Requested, archived
Delegated to: David Miller
Headers show
Series Enable virtio_net to act as a standby for a passthru device | expand

Commit Message

Samudrala, Sridhar April 20, 2018, 1:42 a.m. UTC
This patch enables virtio_net to switch over to a VF datapath when a VF
netdev is present with the same MAC address. It allows live migration
of a VM with a direct attached VF without the need to setup a bond/team
between a VF and virtio net device in the guest.

The hypervisor needs to enable only one datapath at any time so that
packets don't get looped back to the VM over the other datapath. When a VF
is plugged, the virtio datapath link state can be marked as down. The
hypervisor needs to unplug the VF device from the guest on the source host
and reset the MAC filter of the VF to initiate failover of datapath to
virtio before starting the migration. After the migration is completed,
the destination hypervisor sets the MAC filter on the VF and plugs it back
to the guest to switch over to VF datapath.

It uses the generic failover framework that provides 2 functions to create
and destroy a master failover netdev. When STANDBY feature is enabled, an
additional netdev(failover netdev) is created that acts as a master device
and tracks the state of the 2 lower netdevs. The original virtio_net netdev
is marked as 'standby' netdev and a passthru device with the same MAC is
registered as 'primary' netdev.

This patch is based on the discussion initiated by Jesse on this thread.
https://marc.info/?l=linux-virtualization&m=151189725224231&w=2

Signed-off-by: Sridhar Samudrala <sridhar.samudrala@intel.com>
---
 drivers/net/Kconfig      |  1 +
 drivers/net/virtio_net.c | 36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

Comments

Michael S. Tsirkin April 20, 2018, 2:46 a.m. UTC | #1
On Thu, Apr 19, 2018 at 06:42:03PM -0700, Sridhar Samudrala wrote:
> @@ -3010,6 +3043,7 @@ static __init int virtio_net_driver_init(void)
>          ret = register_virtio_driver(&virtio_net_driver);
>  	if (ret)
>  		goto err_virtio;
> +
>  	return 0;
>  err_virtio:
>  	cpuhp_remove_multi_state(CPUHP_VIRT_NET_DEAD);

I'd rather you didn't let's not mix in whitespace changes.

> -- 
> 2.14.3
kernel test robot April 22, 2018, 3:41 p.m. UTC | #2
Hi Sridhar,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net/master]
[also build test ERROR on v4.17-rc1]
[cannot apply to net-next/master next-20180420]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Sridhar-Samudrala/Enable-virtio_net-to-act-as-a-standby-for-a-passthru-device/20180422-210557
config: i386-randconfig-x071-201816 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All error/warnings (new ones prefixed by >>):

   In file included from drivers//net/virtio_net.c:37:0:
>> include/net/failover.h:67:1: error: expected identifier or '(' before '{' token
    {
    ^
>> include/net/failover.h:78:16: warning: 'struct pfailover' declared inside parameter list will not be visible outside of this definition or declaration
            struct pfailover **pfailover);
                   ^~~~~~~~~
   include/net/failover.h:79:1: error: expected identifier or '(' before '{' token
    {
    ^
>> include/net/failover.h:65:5: warning: 'failover_create' used but never defined
    int failover_create(struct net_device *standby_dev,
        ^~~~~~~~~~~~~~~
   include/net/failover.h:77:5: warning: 'failover_register' declared 'static' but never defined [-Wunused-function]
    int failover_register(struct net_device *standby_dev, struct failover_ops *ops,
        ^~~~~~~~~~~~~~~~~

vim +67 include/net/failover.h

891cac68 Sridhar Samudrala 2018-04-19  63  
891cac68 Sridhar Samudrala 2018-04-19  64  static inline
891cac68 Sridhar Samudrala 2018-04-19 @65  int failover_create(struct net_device *standby_dev,
891cac68 Sridhar Samudrala 2018-04-19  66  		    struct failover **pfailover);
891cac68 Sridhar Samudrala 2018-04-19 @67  {
891cac68 Sridhar Samudrala 2018-04-19  68  	return 0;
891cac68 Sridhar Samudrala 2018-04-19  69  }
891cac68 Sridhar Samudrala 2018-04-19  70  
891cac68 Sridhar Samudrala 2018-04-19  71  static inline
891cac68 Sridhar Samudrala 2018-04-19  72  void failover_destroy(struct failover *failover)
891cac68 Sridhar Samudrala 2018-04-19  73  {
891cac68 Sridhar Samudrala 2018-04-19  74  }
891cac68 Sridhar Samudrala 2018-04-19  75  
891cac68 Sridhar Samudrala 2018-04-19  76  static inline
891cac68 Sridhar Samudrala 2018-04-19  77  int failover_register(struct net_device *standby_dev, struct failover_ops *ops,
891cac68 Sridhar Samudrala 2018-04-19 @78  		      struct pfailover **pfailover);
891cac68 Sridhar Samudrala 2018-04-19  79  {
891cac68 Sridhar Samudrala 2018-04-19  80  	return 0;
891cac68 Sridhar Samudrala 2018-04-19  81  }
891cac68 Sridhar Samudrala 2018-04-19  82  

:::::: The code at line 67 was first introduced by commit
:::::: 891cac68e9283c9561d0097af77e7189b9752719 net: Introduce generic failover module

:::::: TO: Sridhar Samudrala <sridhar.samudrala@intel.com>
:::::: CC: 0day robot <fengguang.wu@intel.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot April 22, 2018, 3:41 p.m. UTC | #3
Hi Sridhar,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net/master]
[also build test WARNING on v4.17-rc1]
[cannot apply to net-next/master next-20180420]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Sridhar-Samudrala/Enable-virtio_net-to-act-as-a-standby-for-a-passthru-device/20180422-210557
config: i386-randconfig-a1-04221429 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   In file included from drivers//net/virtio_net.c:37:0:
   include/net/failover.h:67:1: error: expected identifier or '(' before '{' token
    {
    ^
>> include/net/failover.h:78:16: warning: 'struct pfailover' declared inside parameter list
            struct pfailover **pfailover);
                   ^
>> include/net/failover.h:78:16: warning: its scope is only this definition or declaration, which is probably not what you want
   include/net/failover.h:79:1: error: expected identifier or '(' before '{' token
    {
    ^
   include/net/failover.h:65:5: warning: 'failover_create' used but never defined
    int failover_create(struct net_device *standby_dev,
        ^
   include/net/failover.h:77:5: warning: 'failover_register' declared 'static' but never defined [-Wunused-function]
    int failover_register(struct net_device *standby_dev, struct failover_ops *ops,
        ^

vim +78 include/net/failover.h

891cac68 Sridhar Samudrala 2018-04-19  63  
891cac68 Sridhar Samudrala 2018-04-19  64  static inline
891cac68 Sridhar Samudrala 2018-04-19  65  int failover_create(struct net_device *standby_dev,
891cac68 Sridhar Samudrala 2018-04-19  66  		    struct failover **pfailover);
891cac68 Sridhar Samudrala 2018-04-19 @67  {
891cac68 Sridhar Samudrala 2018-04-19  68  	return 0;
891cac68 Sridhar Samudrala 2018-04-19  69  }
891cac68 Sridhar Samudrala 2018-04-19  70  
891cac68 Sridhar Samudrala 2018-04-19  71  static inline
891cac68 Sridhar Samudrala 2018-04-19  72  void failover_destroy(struct failover *failover)
891cac68 Sridhar Samudrala 2018-04-19  73  {
891cac68 Sridhar Samudrala 2018-04-19  74  }
891cac68 Sridhar Samudrala 2018-04-19  75  
891cac68 Sridhar Samudrala 2018-04-19  76  static inline
891cac68 Sridhar Samudrala 2018-04-19  77  int failover_register(struct net_device *standby_dev, struct failover_ops *ops,
891cac68 Sridhar Samudrala 2018-04-19 @78  		      struct pfailover **pfailover);
891cac68 Sridhar Samudrala 2018-04-19  79  {
891cac68 Sridhar Samudrala 2018-04-19  80  	return 0;
891cac68 Sridhar Samudrala 2018-04-19  81  }
891cac68 Sridhar Samudrala 2018-04-19  82  

:::::: The code at line 78 was first introduced by commit
:::::: 891cac68e9283c9561d0097af77e7189b9752719 net: Introduce generic failover module

:::::: TO: Sridhar Samudrala <sridhar.samudrala@intel.com>
:::::: CC: 0day robot <fengguang.wu@intel.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 891846655000..5abe328973da 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -331,6 +331,7 @@  config VETH
 config VIRTIO_NET
 	tristate "Virtio network driver"
 	depends on VIRTIO
+	depends on MAY_USE_FAILOVER
 	---help---
 	  This is the virtual network driver for virtio.  It can be used with
 	  QEMU based VMMs (like KVM or Xen).  Say Y or M.
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 6f95719ede40..42b9f9bff48b 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -30,8 +30,11 @@ 
 #include <linux/cpu.h>
 #include <linux/average.h>
 #include <linux/filter.h>
+#include <linux/netdevice.h>
+#include <linux/pci.h>
 #include <net/route.h>
 #include <net/xdp.h>
+#include <net/failover.h>
 
 static int napi_weight = NAPI_POLL_WEIGHT;
 module_param(napi_weight, int, 0444);
@@ -206,6 +209,9 @@  struct virtnet_info {
 	u32 speed;
 
 	unsigned long guest_offloads;
+
+	/* failover when STANDBY feature enabled */
+	struct failover *failover;
 };
 
 struct padded_vnet_hdr {
@@ -2275,6 +2281,22 @@  static int virtnet_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 	}
 }
 
+static int virtnet_get_phys_port_name(struct net_device *dev, char *buf,
+				      size_t len)
+{
+	struct virtnet_info *vi = netdev_priv(dev);
+	int ret;
+
+	if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_STANDBY))
+		return -EOPNOTSUPP;
+
+	ret = snprintf(buf, len, "_sby");
+	if (ret >= len)
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+
 static const struct net_device_ops virtnet_netdev = {
 	.ndo_open            = virtnet_open,
 	.ndo_stop   	     = virtnet_close,
@@ -2292,6 +2314,7 @@  static const struct net_device_ops virtnet_netdev = {
 	.ndo_xdp_xmit		= virtnet_xdp_xmit,
 	.ndo_xdp_flush		= virtnet_xdp_flush,
 	.ndo_features_check	= passthru_features_check,
+	.ndo_get_phys_port_name	= virtnet_get_phys_port_name,
 };
 
 static void virtnet_config_changed_work(struct work_struct *work)
@@ -2839,10 +2862,16 @@  static int virtnet_probe(struct virtio_device *vdev)
 
 	virtnet_init_settings(dev);
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_STANDBY)) {
+		err = failover_create(vi->dev, &vi->failover);
+		if (err)
+			goto free_vqs;
+	}
+
 	err = register_netdev(dev);
 	if (err) {
 		pr_debug("virtio_net: registering device failed\n");
-		goto free_vqs;
+		goto free_failover;
 	}
 
 	virtio_device_ready(vdev);
@@ -2879,6 +2908,8 @@  static int virtnet_probe(struct virtio_device *vdev)
 	vi->vdev->config->reset(vdev);
 
 	unregister_netdev(dev);
+free_failover:
+	failover_destroy(vi->failover);
 free_vqs:
 	cancel_delayed_work_sync(&vi->refill);
 	free_receive_page_frags(vi);
@@ -2913,6 +2944,8 @@  static void virtnet_remove(struct virtio_device *vdev)
 
 	unregister_netdev(vi->dev);
 
+	failover_destroy(vi->failover);
+
 	remove_vq_common(vi);
 
 	free_netdev(vi->dev);
@@ -3010,6 +3043,7 @@  static __init int virtio_net_driver_init(void)
         ret = register_virtio_driver(&virtio_net_driver);
 	if (ret)
 		goto err_virtio;
+
 	return 0;
 err_virtio:
 	cpuhp_remove_multi_state(CPUHP_VIRT_NET_DEAD);