Skip to contentSkip to conversation

net/tls: Act on going down event

PATCH In review Or Gerlitz 3 participants 4 messages Feb 13, 2020 – Feb 14, 2020

Subsystems (3)
lore
Share & tools
lore

Or Gerlitz

author
#0 lore raw

PATCH 1/1 net/tls: Act on going down event

By the time of the down event, the netdevice stop ndo was already called and the nic driver is likely to destroy the HW objects/constructs which are used for the tls_dev_resync op.

Instead, act on the going down event which is triggered before the stop ndo.

Fixes e8f69799810c ("net/tls: Add generic NIC offload infrastructure")

---

compile tested only.

# vim net/core/dev.c +1555
 *	This function moves an active device into down state. A
 *	%NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device
 *	is then deactivated and finally a %NETDEV_DOWN is sent to the notifier chain.
[..]
void dev_close(struct net_device *dev)
 net/tls/tls_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tls/tls_device.c +1 -1
index 1ba5a92832bb..457c4b8352d8 100644
@@ -1246,7 +1246,7 @@ static int tls_dev_event(struct notifier_block *this, unsigned long event,
 			return NOTIFY_DONE;
 		else
 			return NOTIFY_BAD;
-	case NETDEV_DOWN:
+	case NETDEV_GOING_DOWN:
 		return tls_device_down(dev);
 	}
 	return NOTIFY_DONE;
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 4 lines · On Thu, 13 Feb 2020 16:54:07 +0000 Or Gerlitz wrote:

By the time of the down event, the netdevice stop ndo was already called and the nic driver is likely to destroy the HW objects/constructs which are used for the tls_dev_resync op.

Quoted 8 lines

Instead, act on the going down event which is triggered before the stop ndo.

Fixes e8f69799810c ("net/tls: Add generic NIC offload infrastructure")

---

compile tested only.

For a fix that you have hardware to test that is a little disappointing :(

Quoted 6 lines
# vim net/core/dev.c +1555
 *	This function moves an active device into down state. A
 *	%NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device
 *	is then deactivated and finally a %NETDEV_DOWN is sent to the notifier chain.
[..]
void dev_close(struct net_device *dev)

As is quoting a comment rather than justifying changes based on the code.

net/tls/tls_device.c static int tls_dev_event(struct notifier_block *this, unsigned long event, · line 1249

Quoted 10 lines
net/tls/tls_device.c +1 -1
index 1ba5a92832bb..457c4b8352d8 100644
@@ -1246,7 +1246,7 @@ static int tls_dev_event(struct notifier_block *this, unsigned long event,
 			return NOTIFY_DONE;
 		else
 			return NOTIFY_BAD;
-	case NETDEV_DOWN:
+	case NETDEV_GOING_DOWN:

Now we'll have two race conditions. 1. Traffic is still running while we remove the connection state. 2. We clean out the state and then close the device. Between the two new connections may be installed.

I think it's an inherently racy to only be able to perform clean up while the device is still up.

Quoted 3 lines
net/tls/tls_device.c +0 -0
 		return tls_device_down(dev);
 	}
 	return NOTIFY_DONE;
#2 lore raw
Quoted 13 lines · Jakub Kicinski

net/tls/tls_device.c static int tls_dev_event(struct notifier_block *this, unsigned long event, · line 1246

Quoted 7 lines · On Thu, 13 Feb 2020 16:54:07 +0000 Or Gerlitz wrote:

By the time of the down event, the netdevice stop ndo was already called and the nic driver is likely to destroy the HW objects/constructs which are used for the tls_dev_resync op.

net/tls/tls_device.c +1 -1
@@ -1246,7 +1246,7 @@ static int tls_dev_event(struct notifier_block *this, unsigned long event,
-     case NETDEV_DOWN:
+     case NETDEV_GOING_DOWN:

Now we'll have two race conditions. 1. Traffic is still running while we remove the connection state. 2. We clean out the state and then close the device. Between the two new connections may be installed.

Quoted 2 lines

I think it's an inherently racy to only be able to perform clean up while the device is still up.

good points, I have to think on both of them and re/sync (..) with the actual design details here, I came across this while working on something else which is still more of a research so just throwing a patch here was moving too fast.

Repeating myself -- by the time of the down event, the netdevice stop ndo was already called and the nic driver is likely to destroy HW objects/constructs which are used for the tls_dev_resync op.

For example suppose a NIC driver uses some QP/ring to post resync request to the HW and these rings are part of the driver's channels and the channels are destroyed when the stop ndo is called - the tls code here uses RW synchronization between invoking the resync driver op to the down event handling. But the down event comes only after these resources were destroyed, too late. If we will safely/stop the offload at the going down stage, we can avoid a much more complex and per nic driver locking which I guess would be needed to protect against that race.

thoughts?

- so here's
the point -- the driver resync op may use some HW

Quoted 4 lines
Quoted 4 lines
net/tls/tls_device.c +0 -0
              return tls_device_down(dev);
      }
      return NOTIFY_DONE;
maintainer
#3 lore raw
Quoted 35 lines · On Thu, 13 Feb 2020 22:07:19 +0200 Or Gerlitz wrote:
Quoted 13 lines · Jakub Kicinski

net/tls/tls_device.c static int tls_dev_event(struct notifier_block *this, unsigned long event, · line 1246

Quoted 7 lines · On Thu, 13 Feb 2020 16:54:07 +0000 Or Gerlitz wrote:

By the time of the down event, the netdevice stop ndo was already called and the nic driver is likely to destroy the HW objects/constructs which are used for the tls_dev_resync op.

net/tls/tls_device.c +1 -1
@@ -1246,7 +1246,7 @@ static int tls_dev_event(struct notifier_block *this, unsigned long event,
-     case NETDEV_DOWN:
+     case NETDEV_GOING_DOWN:  

Now we'll have two race conditions. 1. Traffic is still running while we remove the connection state. 2. We clean out the state and then close the device. Between the two new connections may be installed.

Quoted 2 lines

I think it's an inherently racy to only be able to perform clean up while the device is still up.

good points, I have to think on both of them and re/sync (..) with the actual design details here, I came across this while working on something else which is still more of a research so just throwing a patch here was moving too fast.

Repeating myself -- by the time of the down event, the netdevice stop ndo was already called and the nic driver is likely to destroy HW objects/constructs which are used for the tls_dev_resync op.

For example suppose a NIC driver uses some QP/ring to post resync request to the HW and these rings are part of the driver's channels and the channels are destroyed when the stop ndo is called - the tls code here uses RW synchronization between invoking the resync driver op to the down event handling. But the down event comes only after these resources were destroyed, too late. If we will safely/stop the offload at the going down stage, we can avoid a much more complex and per nic driver locking which I guess would be needed to protect against that race.

Quoted 1 line

thoughts?

I'm not sure what happens on the device side, so take this with a pinch of salt.

The device flushing some state automatically on down sounds like a pretty error prone design, I don't think you'd do that :)

So I think you're just using datapath components associated with a vNIC/function to speed up communication with the device? That does get painful quite quickly if the device does not have a idea of control QPs/functions/vNICs with independent state :S

We could slice the downing in the stack into one more stage where device is considered down but resources (mem, irq, qps) are not freed, but I think that's not a complete fix, because one day you may want to do BPF offloads or use QPs for devlink and those are independent of vNIC/function state, anyway..

Quoted 2 lines

- so here's
the point -- the driver resync op may use some HW