Re: [PATCH v7 net-next 2/4] net: Introduce generic failover module

2018-04-23 Thread Samudrala, Sridhar

On 4/22/2018 10:06 AM, Michael S. Tsirkin wrote:

On Thu, Apr 19, 2018 at 06:42:02PM -0700, Sridhar Samudrala wrote:

+#if IS_ENABLED(CONFIG_NET_FAILOVER)
+
+int failover_create(struct net_device *standby_dev,
+   struct failover **pfailover);

Should we rename all these structs net_failover?
It's possible to extend the concept to storage I think.


We could, the only downside is that the names become longer. i think we need
to change the filenames and the function names also to be consistent.





+void failover_destroy(struct failover *failover);
+
+int failover_register(struct net_device *standby_dev, struct failover_ops *ops,
+ struct failover **pfailover);
+void failover_unregister(struct failover *failover);
+
+int failover_slave_unregister(struct net_device *slave_dev);
+
+#else
+
+static inline
+int failover_create(struct net_device *standby_dev,
+   struct failover **pfailover);
+{
+   return 0;

Does this make callers do something sane?
Shouldn't these return an error?


Yes. i think i should return -EOPNOTSUPP here, so that we fail
when CONFIG_NET_FAILOVER is not enabled and the virtio-net driver is trying
to create a failover device.



+}
+
+static inline
+void failover_destroy(struct failover *failover)
+{
+}
+
+static inline
+int failover_register(struct net_device *standby_dev, struct failover_ops *ops,
+ struct pfailover **pfailover);
+{
+   return 0;
+}

struct pfailover seems like a typo.


yes. will also change the return to -EOPNOTSUPP




+
+static inline
+void failover_unregister(struct failover *failover)
+{
+}
+
+static inline
+int failover_slave_unregister(struct net_device *slave_dev)
+{
+   return 0;
+}

Does anyone test return value of unregister?
should this be void?


yes. can be changed to void.





+
+#endif
+
+#endif /* _NET_FAILOVER_H */


___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v7 net-next 2/4] net: Introduce generic failover module

2018-04-22 Thread kbuild test robot
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
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> net/core/failover.c:99:36: sparse: incorrect type in argument 1 (different 
>> address spaces) @@expected struct net_device *dev @@got struct 
>> net_devicestruct net_device *dev @@
   net/core/failover.c:99:36:expected struct net_device *dev
   net/core/failover.c:99:36:got struct net_device [noderef] 
*standby_dev
   net/core/failover.c:102:36: sparse: incorrect type in argument 1 (different 
address spaces) @@expected struct net_device *dev @@got struct 
net_devicestruct net_device *dev @@
   net/core/failover.c:102:36:expected struct net_device *dev
   net/core/failover.c:102:36:got struct net_device [noderef] 
*primary_dev
>> net/core/failover.c:468:12: sparse: context imbalance in 
>> 'failover_select_queue' - wrong count at exit

vim +99 net/core/failover.c

58  
59  static int failover_slave_join(struct net_device *slave_dev,
60 struct net_device *failover_dev,
61 struct failover_ops *failover_ops)
62  {
63  struct failover_info *finfo;
64  int err, orig_mtu;
65  bool standby;
66  
67  if (failover_ops) {
68  if (!failover_ops->slave_join)
69  return -EINVAL;
70  
71  return failover_ops->slave_join(slave_dev, 
failover_dev);
72  }
73  
74  if (netif_running(failover_dev)) {
75  err = dev_open(slave_dev);
76  if (err && (err != -EBUSY)) {
77  netdev_err(failover_dev, "Opening slave %s 
failed err:%d\n",
78 slave_dev->name, err);
79  goto err_dev_open;
80  }
81  }
82  
83  /* Align MTU of slave with failover dev */
84  orig_mtu = slave_dev->mtu;
85  err = dev_set_mtu(slave_dev, failover_dev->mtu);
86  if (err) {
87  netdev_err(failover_dev, "unable to change mtu of %s to 
%u register failed\n",
88 slave_dev->name, failover_dev->mtu);
89  goto err_set_mtu;
90  }
91  
92  finfo = netdev_priv(failover_dev);
93  standby = (slave_dev->dev.parent == failover_dev->dev.parent);
94  
95  dev_hold(slave_dev);
96  
97  if (standby) {
98  rcu_assign_pointer(finfo->standby_dev, slave_dev);
  > 99  dev_get_stats(finfo->standby_dev, 
>standby_stats);
   100  } else {
   101  rcu_assign_pointer(finfo->primary_dev, slave_dev);
   102  dev_get_stats(finfo->primary_dev, 
>primary_stats);
   103  failover_dev->min_mtu = slave_dev->min_mtu;
   104  failover_dev->max_mtu = slave_dev->max_mtu;
   105  }
   106  
   107  netdev_info(failover_dev, "failover slave:%s joined\n",
   108  slave_dev->name);
   109  
   110  return 0;
   111  
   112  err_set_mtu:
   113  dev_close(slave_dev);
   114  err_dev_open:
   115  return err;
   116  }
   117  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v7 net-next 2/4] net: Introduce generic failover module

2018-04-22 Thread Michael S. Tsirkin
On Thu, Apr 19, 2018 at 06:42:02PM -0700, Sridhar Samudrala wrote:
> +#if IS_ENABLED(CONFIG_NET_FAILOVER)
> +
> +int failover_create(struct net_device *standby_dev,
> + struct failover **pfailover);

Should we rename all these structs net_failover?
It's possible to extend the concept to storage I think.

> +void failover_destroy(struct failover *failover);
> +
> +int failover_register(struct net_device *standby_dev, struct failover_ops 
> *ops,
> +   struct failover **pfailover);
> +void failover_unregister(struct failover *failover);
> +
> +int failover_slave_unregister(struct net_device *slave_dev);
> +
> +#else
> +
> +static inline
> +int failover_create(struct net_device *standby_dev,
> + struct failover **pfailover);
> +{
> + return 0;

Does this make callers do something sane?
Shouldn't these return an error?

> +}
> +
> +static inline
> +void failover_destroy(struct failover *failover)
> +{
> +}
> +
> +static inline
> +int failover_register(struct net_device *standby_dev, struct failover_ops 
> *ops,
> +   struct pfailover **pfailover);
> +{
> + return 0;
> +}

struct pfailover seems like a typo.

> +
> +static inline
> +void failover_unregister(struct failover *failover)
> +{
> +}
> +
> +static inline
> +int failover_slave_unregister(struct net_device *slave_dev)
> +{
> + return 0;
> +}

Does anyone test return value of unregister?
should this be void?

> +
> +#endif
> +
> +#endif /* _NET_FAILOVER_H */
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [virtio-dev] Re: [PATCH v7 net-next 2/4] net: Introduce generic failover module

2018-04-20 Thread Michael S. Tsirkin
On Fri, Apr 20, 2018 at 08:56:57AM -0700, Alexander Duyck wrote:
> On Fri, Apr 20, 2018 at 8:34 AM, Michael S. Tsirkin  wrote:
> > On Fri, Apr 20, 2018 at 08:21:00AM -0700, Samudrala, Sridhar wrote:
> >> > > + finfo = netdev_priv(failover_dev);
> >> > > +
> >> > > + primary_dev = rtnl_dereference(finfo->primary_dev);
> >> > > + standby_dev = rtnl_dereference(finfo->standby_dev);
> >> > > +
> >> > > + if (slave_dev != primary_dev && slave_dev != standby_dev)
> >> > > + goto done;
> >> > > +
> >> > > + if ((primary_dev && failover_xmit_ready(primary_dev)) ||
> >> > > + (standby_dev && failover_xmit_ready(standby_dev))) {
> >> > > + netif_carrier_on(failover_dev);
> >> > > + netif_tx_wake_all_queues(failover_dev);
> >> > > + } else {
> >> > > + netif_carrier_off(failover_dev);
> >> > > + netif_tx_stop_all_queues(failover_dev);
> >> > And I think it's a good idea to get stats from device here too.
> >>
> >> Not sure why we need to get stats from lower devs here?
> >
> > link down is often indication of a hardware problem.
> > lower dev might stop responding down the road.
> >
> >> > > +static const struct net_device_ops failover_dev_ops = {
> >> > > + .ndo_open   = failover_open,
> >> > > + .ndo_stop   = failover_close,
> >> > > + .ndo_start_xmit = failover_start_xmit,
> >> > > + .ndo_select_queue   = failover_select_queue,
> >> > > + .ndo_get_stats64= failover_get_stats,
> >> > > + .ndo_change_mtu = failover_change_mtu,
> >> > > + .ndo_set_rx_mode= failover_set_rx_mode,
> >> > > + .ndo_validate_addr  = eth_validate_addr,
> >> > > + .ndo_features_check = passthru_features_check,
> >> > xdp support?
> >>
> >> I think it should be possible to add it be calling the lower dev ndo_xdp 
> >> routines
> >> with proper checks. can we add this later?
> >
> > I'd be concerned that if you don't xdp userspace will keep poking
> > at lower devs. Then it will stop working if you add this later.
> 
> The failover device is better off not providing in-driver XDP since
> there are already skbs allocated by the time that we see the packet
> here anyway. As such generic XDP is the preferred way to handle this
> since it will work regardless of what lower devices are present.
>
> The only advantage of having XDP down at the virtio or VF level would
> be that it performs better, but at the cost of complexity since we
> would need to rebind the eBPF program any time a device is hotplugged
> out and then back in. For now the current approach is in keeping with
> how bonding and other similar drivers are currently handling this.
> 
> Thanks.
> 
> - Alex

OK fair enough.

-- 
MST
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [virtio-dev] Re: [PATCH v7 net-next 2/4] net: Introduce generic failover module

2018-04-20 Thread Alexander Duyck
On Fri, Apr 20, 2018 at 8:34 AM, Michael S. Tsirkin  wrote:
> On Fri, Apr 20, 2018 at 08:21:00AM -0700, Samudrala, Sridhar wrote:
>> > > + finfo = netdev_priv(failover_dev);
>> > > +
>> > > + primary_dev = rtnl_dereference(finfo->primary_dev);
>> > > + standby_dev = rtnl_dereference(finfo->standby_dev);
>> > > +
>> > > + if (slave_dev != primary_dev && slave_dev != standby_dev)
>> > > + goto done;
>> > > +
>> > > + if ((primary_dev && failover_xmit_ready(primary_dev)) ||
>> > > + (standby_dev && failover_xmit_ready(standby_dev))) {
>> > > + netif_carrier_on(failover_dev);
>> > > + netif_tx_wake_all_queues(failover_dev);
>> > > + } else {
>> > > + netif_carrier_off(failover_dev);
>> > > + netif_tx_stop_all_queues(failover_dev);
>> > And I think it's a good idea to get stats from device here too.
>>
>> Not sure why we need to get stats from lower devs here?
>
> link down is often indication of a hardware problem.
> lower dev might stop responding down the road.
>
>> > > +static const struct net_device_ops failover_dev_ops = {
>> > > + .ndo_open   = failover_open,
>> > > + .ndo_stop   = failover_close,
>> > > + .ndo_start_xmit = failover_start_xmit,
>> > > + .ndo_select_queue   = failover_select_queue,
>> > > + .ndo_get_stats64= failover_get_stats,
>> > > + .ndo_change_mtu = failover_change_mtu,
>> > > + .ndo_set_rx_mode= failover_set_rx_mode,
>> > > + .ndo_validate_addr  = eth_validate_addr,
>> > > + .ndo_features_check = passthru_features_check,
>> > xdp support?
>>
>> I think it should be possible to add it be calling the lower dev ndo_xdp 
>> routines
>> with proper checks. can we add this later?
>
> I'd be concerned that if you don't xdp userspace will keep poking
> at lower devs. Then it will stop working if you add this later.

The failover device is better off not providing in-driver XDP since
there are already skbs allocated by the time that we see the packet
here anyway. As such generic XDP is the preferred way to handle this
since it will work regardless of what lower devices are present.

The only advantage of having XDP down at the virtio or VF level would
be that it performs better, but at the cost of complexity since we
would need to rebind the eBPF program any time a device is hotplugged
out and then back in. For now the current approach is in keeping with
how bonding and other similar drivers are currently handling this.

Thanks.

- Alex
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v7 net-next 2/4] net: Introduce generic failover module

2018-04-20 Thread Michael S. Tsirkin
On Fri, Apr 20, 2018 at 08:21:00AM -0700, Samudrala, Sridhar wrote:
> > > + finfo = netdev_priv(failover_dev);
> > > +
> > > + primary_dev = rtnl_dereference(finfo->primary_dev);
> > > + standby_dev = rtnl_dereference(finfo->standby_dev);
> > > +
> > > + if (slave_dev != primary_dev && slave_dev != standby_dev)
> > > + goto done;
> > > +
> > > + if ((primary_dev && failover_xmit_ready(primary_dev)) ||
> > > + (standby_dev && failover_xmit_ready(standby_dev))) {
> > > + netif_carrier_on(failover_dev);
> > > + netif_tx_wake_all_queues(failover_dev);
> > > + } else {
> > > + netif_carrier_off(failover_dev);
> > > + netif_tx_stop_all_queues(failover_dev);
> > And I think it's a good idea to get stats from device here too.
> 
> Not sure why we need to get stats from lower devs here?

link down is often indication of a hardware problem.
lower dev might stop responding down the road.

> > > +static const struct net_device_ops failover_dev_ops = {
> > > + .ndo_open   = failover_open,
> > > + .ndo_stop   = failover_close,
> > > + .ndo_start_xmit = failover_start_xmit,
> > > + .ndo_select_queue   = failover_select_queue,
> > > + .ndo_get_stats64= failover_get_stats,
> > > + .ndo_change_mtu = failover_change_mtu,
> > > + .ndo_set_rx_mode= failover_set_rx_mode,
> > > + .ndo_validate_addr  = eth_validate_addr,
> > > + .ndo_features_check = passthru_features_check,
> > xdp support?
> 
> I think it should be possible to add it be calling the lower dev ndo_xdp 
> routines
> with proper checks. can we add this later?

I'd be concerned that if you don't xdp userspace will keep poking
at lower devs. Then it will stop working if you add this later.

-- 
MST
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v7 net-next 2/4] net: Introduce generic failover module

2018-04-20 Thread Samudrala, Sridhar


On 4/19/2018 7:44 PM, Michael S. Tsirkin wrote:

On Thu, Apr 19, 2018 at 06:42:02PM -0700, Sridhar Samudrala wrote:

This provides a generic interface for paravirtual drivers to listen
for netdev register/unregister/link change events from pci ethernet
devices with the same MAC and takeover their datapath. The notifier and
event handling code is based on the existing netvsc implementation.

It exposes 2 sets of interfaces to the paravirtual drivers.
1. existing netvsc driver that uses 2 netdev model. In this model, no
master netdev is created. The paravirtual driver registers each instance
of netvsc as a 'failover' instance  along with a set of ops to manage the
slave events.
  failover_register()
  failover_unregister()
2. new virtio_net based solution that uses 3 netdev model. In this model,
the failover module provides interfaces to create/destroy additional master
netdev and all the slave events are managed internally.
   failover_create()
   failover_destroy()
These functions call failover_register()/failover_unregister() with the
master netdev created by the failover module.

Signed-off-by: Sridhar Samudrala 

I like this patch. Yes something to improve (see below)


---
  include/linux/netdevice.h |  16 +
  include/net/failover.h|  96 ++
  net/Kconfig   |  18 +
  net/core/Makefile |   1 +
  net/core/failover.c   | 844 ++
  5 files changed, 975 insertions(+)
  create mode 100644 include/net/failover.h
  create mode 100644 net/core/failover.c

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index cf44503ea81a..ed535b6724e1 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1401,6 +1401,8 @@ struct net_device_ops {
   *entity (i.e. the master device for bridged veth)
   * @IFF_MACSEC: device is a MACsec device
   * @IFF_NO_RX_HANDLER: device doesn't support the rx_handler hook
+ * @IFF_FAILOVER: device is a failover master device
+ * @IFF_FAILOVER_SLAVE: device is lower dev of a failover master device
   */
  enum netdev_priv_flags {
IFF_802_1Q_VLAN = 1<<0,
@@ -1430,6 +1432,8 @@ enum netdev_priv_flags {
IFF_PHONY_HEADROOM  = 1<<24,
IFF_MACSEC  = 1<<25,
IFF_NO_RX_HANDLER   = 1<<26,
+   IFF_FAILOVER= 1<<27,
+   IFF_FAILOVER_SLAVE  = 1<<28,
  };
  
  #define IFF_802_1Q_VLAN			IFF_802_1Q_VLAN

@@ -1458,6 +1462,8 @@ enum netdev_priv_flags {
  #define IFF_RXFH_CONFIGURED   IFF_RXFH_CONFIGURED
  #define IFF_MACSECIFF_MACSEC
  #define IFF_NO_RX_HANDLER IFF_NO_RX_HANDLER
+#define IFF_FAILOVER   IFF_FAILOVER
+#define IFF_FAILOVER_SLAVE IFF_FAILOVER_SLAVE
  
  /**

   *struct net_device - The DEVICE structure.
@@ -4308,6 +4314,16 @@ static inline bool netif_is_rxfh_configured(const struct 
net_device *dev)
return dev->priv_flags & IFF_RXFH_CONFIGURED;
  }
  
+static inline bool netif_is_failover(const struct net_device *dev)

+{
+   return dev->priv_flags & IFF_FAILOVER;
+}
+
+static inline bool netif_is_failover_slave(const struct net_device *dev)
+{
+   return dev->priv_flags & IFF_FAILOVER_SLAVE;
+}
+
  /* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
  static inline void netif_keep_dst(struct net_device *dev)
  {
diff --git a/include/net/failover.h b/include/net/failover.h
new file mode 100644
index ..0b8601043d90
--- /dev/null
+++ b/include/net/failover.h
@@ -0,0 +1,96 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2018, Intel Corporation. */
+
+#ifndef _NET_FAILOVER_H
+#define _NET_FAILOVER_H
+
+#include 
+
+struct failover_ops {
+   int (*slave_pre_register)(struct net_device *slave_dev,
+ struct net_device *failover_dev);
+   int (*slave_join)(struct net_device *slave_dev,
+ struct net_device *failover_dev);
+   int (*slave_pre_unregister)(struct net_device *slave_dev,
+   struct net_device *failover_dev);
+   int (*slave_release)(struct net_device *slave_dev,
+struct net_device *failover_dev);
+   int (*slave_link_change)(struct net_device *slave_dev,
+struct net_device *failover_dev);
+   rx_handler_result_t (*handle_frame)(struct sk_buff **pskb);
+};
+
+struct failover {
+   struct list_head list;
+   struct net_device __rcu *failover_dev;
+   struct failover_ops __rcu *ops;
+};
+
+/* failover state */
+struct failover_info {
+   /* primary netdev with same MAC */
+   struct net_device __rcu *primary_dev;
+
+   /* standby netdev */
+   struct net_device __rcu *standby_dev;
+
+   /* primary netdev stats */
+   struct rtnl_link_stats64 primary_stats;
+
+   /* 

Re: [PATCH v7 net-next 2/4] net: Introduce generic failover module

2018-04-19 Thread Michael S. Tsirkin
On Thu, Apr 19, 2018 at 06:42:02PM -0700, Sridhar Samudrala wrote:
> +static struct net_device *failover_get_bymac(u8 *mac, struct failover_ops 
> **ops)
> +{
> + struct net_device *failover_dev;
> + struct failover *failover;
> +
> + spin_lock(_lock);
> + list_for_each_entry(failover, _list, list) {
> + failover_dev = rtnl_dereference(failover->failover_dev);
> + if (ether_addr_equal(failover_dev->perm_addr, mac)) {
> + *ops = rtnl_dereference(failover->ops);
> + spin_unlock(_lock);
> + return failover_dev;
> + }
> + }
> + spin_unlock(_lock);
> + return NULL;
> +}

So it bothers me that this ties to just any device at all.

I thought hard about it, and I see a nice solution.
Here goes:

QEMU has a pci-bridge-seat device. It is used currently to
group e.g. input devices for multiseat support.

Now if you squint at it hard enough, you can see we are also
in a grouping problem. So how about the following:

1. allocate a virtio pci bridge device failover grouping id (reserve through 
virtio TC).
2. only group two devices in a failover configuration if both
   are under the same bridge with this id (in addition to a mac check).

In particular a bridged configuration makes it easier to
make sure the standby is enumerated before the primary.
In fact we could fail init of failover if we see
appear standby *after* primary.

And this allows many devices with the same ethernet address
without any issues - just under separate bridges.

Further if we ever want to enumerate in parallel this can
be supported by adding a driver for the bridge.

In fact, I see how down the road such a device could
be the beginning of the more ambitious plan to
expose a powerful switchdev interface for
more advanced 


So far so good, but I see a couple of issues:

- it is PCI specific
 Not a big deal: we limit ourselves to PCI anyway ATM.

- does not work across PCI domains - which are helpful for NUMA
  (e.g. we want to be able to move to primary
   which is on a different numa
   node without losing connectivity).

Idea: add a "group ID" register to each of these pci bridge
devices (e.g. in device specific config space).
Match two bridges if they have the same group ID.

- all these extra bridges slow enumeration down somewhat

Idea: as a fallback if no bridge is found,
just assume all devices match, which will result
in falling back on the "match by mac" logic like in
this patchset. Will be fine for simple setups.


Thoughts?

-- 
MST
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH v7 net-next 2/4] net: Introduce generic failover module

2018-04-19 Thread Michael S. Tsirkin
On Thu, Apr 19, 2018 at 06:42:02PM -0700, Sridhar Samudrala wrote:
> This provides a generic interface for paravirtual drivers to listen
> for netdev register/unregister/link change events from pci ethernet
> devices with the same MAC and takeover their datapath. The notifier and
> event handling code is based on the existing netvsc implementation.
> 
> It exposes 2 sets of interfaces to the paravirtual drivers.
> 1. existing netvsc driver that uses 2 netdev model. In this model, no
> master netdev is created. The paravirtual driver registers each instance
> of netvsc as a 'failover' instance  along with a set of ops to manage the
> slave events.
>  failover_register()
>  failover_unregister()
> 2. new virtio_net based solution that uses 3 netdev model. In this model,
> the failover module provides interfaces to create/destroy additional master
> netdev and all the slave events are managed internally.
>   failover_create()
>   failover_destroy()
> These functions call failover_register()/failover_unregister() with the
> master netdev created by the failover module.
> 
> Signed-off-by: Sridhar Samudrala 

I like this patch. Yes something to improve (see below)

> ---
>  include/linux/netdevice.h |  16 +
>  include/net/failover.h|  96 ++
>  net/Kconfig   |  18 +
>  net/core/Makefile |   1 +
>  net/core/failover.c   | 844 
> ++
>  5 files changed, 975 insertions(+)
>  create mode 100644 include/net/failover.h
>  create mode 100644 net/core/failover.c
> 
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index cf44503ea81a..ed535b6724e1 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -1401,6 +1401,8 @@ struct net_device_ops {
>   *   entity (i.e. the master device for bridged veth)
>   * @IFF_MACSEC: device is a MACsec device
>   * @IFF_NO_RX_HANDLER: device doesn't support the rx_handler hook
> + * @IFF_FAILOVER: device is a failover master device
> + * @IFF_FAILOVER_SLAVE: device is lower dev of a failover master device
>   */
>  enum netdev_priv_flags {
>   IFF_802_1Q_VLAN = 1<<0,
> @@ -1430,6 +1432,8 @@ enum netdev_priv_flags {
>   IFF_PHONY_HEADROOM  = 1<<24,
>   IFF_MACSEC  = 1<<25,
>   IFF_NO_RX_HANDLER   = 1<<26,
> + IFF_FAILOVER= 1<<27,
> + IFF_FAILOVER_SLAVE  = 1<<28,
>  };
>  
>  #define IFF_802_1Q_VLAN  IFF_802_1Q_VLAN
> @@ -1458,6 +1462,8 @@ enum netdev_priv_flags {
>  #define IFF_RXFH_CONFIGURED  IFF_RXFH_CONFIGURED
>  #define IFF_MACSEC   IFF_MACSEC
>  #define IFF_NO_RX_HANDLERIFF_NO_RX_HANDLER
> +#define IFF_FAILOVER IFF_FAILOVER
> +#define IFF_FAILOVER_SLAVE   IFF_FAILOVER_SLAVE
>  
>  /**
>   *   struct net_device - The DEVICE structure.
> @@ -4308,6 +4314,16 @@ static inline bool netif_is_rxfh_configured(const 
> struct net_device *dev)
>   return dev->priv_flags & IFF_RXFH_CONFIGURED;
>  }
>  
> +static inline bool netif_is_failover(const struct net_device *dev)
> +{
> + return dev->priv_flags & IFF_FAILOVER;
> +}
> +
> +static inline bool netif_is_failover_slave(const struct net_device *dev)
> +{
> + return dev->priv_flags & IFF_FAILOVER_SLAVE;
> +}
> +
>  /* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
>  static inline void netif_keep_dst(struct net_device *dev)
>  {
> diff --git a/include/net/failover.h b/include/net/failover.h
> new file mode 100644
> index ..0b8601043d90
> --- /dev/null
> +++ b/include/net/failover.h
> @@ -0,0 +1,96 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (c) 2018, Intel Corporation. */
> +
> +#ifndef _NET_FAILOVER_H
> +#define _NET_FAILOVER_H
> +
> +#include 
> +
> +struct failover_ops {
> + int (*slave_pre_register)(struct net_device *slave_dev,
> +   struct net_device *failover_dev);
> + int (*slave_join)(struct net_device *slave_dev,
> +   struct net_device *failover_dev);
> + int (*slave_pre_unregister)(struct net_device *slave_dev,
> + struct net_device *failover_dev);
> + int (*slave_release)(struct net_device *slave_dev,
> +  struct net_device *failover_dev);
> + int (*slave_link_change)(struct net_device *slave_dev,
> +  struct net_device *failover_dev);
> + rx_handler_result_t (*handle_frame)(struct sk_buff **pskb);
> +};
> +
> +struct failover {
> + struct list_head list;
> + struct net_device __rcu *failover_dev;
> + struct failover_ops __rcu *ops;
> +};
> +
> +/* failover state */
> +struct failover_info {
> + /* primary netdev with same MAC */
> + struct net_device __rcu *primary_dev;
> +
> + /* standby netdev */
> + struct net_device