RDMA/mana_ib: handle net event for pointing to the current netdev
Subsystems (5)
PATCH 1/1 RDMA/mana_ib: handle net event for pointing to the current netdev
From: Long Li <[email protected]>
When running under Hyper-V, the master device to the RDMA device is always bonded to this RDMA device if it's present in the kernel. This is not user-configurable.
The master device can be unbind/bind from the kernel. During those events, the RDMA device should set to the current netdev to relect the change of master device from those events.
--- drivers/infiniband/hw/mana/device.c | 35 ++++++++++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 1 + 2 files changed, 36 insertions(+)
drivers/infiniband/hw/mana/device.c +35 -0
@@ -51,6 +51,37 @@ static const struct ib_device_ops mana_ib_dev_ops = { ib_ind_table), }; +static int mana_ib_netdev_event (struct notifier_block *this, +unsigned long event,void *ptr) +{ + struct mana_ib_dev *dev = container_of(this, struct mana_ib_dev, nb); +struct net_device *event_dev =netdev_notifier_info_to_dev (ptr); +struct gdma_context *gc = dev->gdma_dev->gdma_context; +struct mana_context *mc = gc->mana.driver_data; +struct net_device *ndev; + +if (event_dev != mc->ports[0 ]) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_CHANGEUPPER : +rcu_read_lock (); + ndev =mana_get_primary_netdev_rcu (mc,0 ); +rcu_read_unlock (); + +/* +* RDMA core will setup GID based on updated netdev. +* It's not possible to race with the core as rtnl lock is being +* held. +*/ +ib_device_set_netdev (&dev->ib_dev, ndev,1 ); + +return NOTIFY_OK ; +default : +return NOTIFY_DONE ; + } +} +static int mana_ib_probe (struct auxiliary_device *adev,const struct auxiliary_device_id *id) {
@@ -109,6 +140,9 @@ static int mana_ib_probe(struct auxiliary_device *adev, } dev->gdma_dev = &mdev->gdma_context->mana_ib; + dev->nb.notifier_call = mana_ib_netdev_event; +register_netdevice_notifier (&dev->nb); + ret =mana_ib_gd_query_adapter_caps (dev);if (ret) { ibdev_err(&dev->ib_dev, "Failed to query device caps, ret %d",
@@ -159,6 +193,7 @@ static void mana_ib_remove(struct auxiliary_device *adev) {struct mana_ib_dev *dev =dev_get_drvdata (&adev->dev); +unregister_netdevice_notifier (&dev->nb);ib_unregister_device (&dev->ib_dev);xa_destroy (&dev->qp_table_wq);mana_ib_gd_destroy_rnic_adapter (dev);
drivers/infiniband/hw/mana/mana_ib.h +1 -0
@@ -64,6 +64,7 @@ struct mana_ib_dev {struct gdma_queue **eqs;struct xarray qp_table_wq;struct mana_ib_adapter_caps adapter_caps; +struct notifier_block nb; };struct mana_ib_wq {
Signature · 1 line
2.34.1
Quoted 9 lines
Subject: [Patch rdma-next] RDMA/mana_ib: handle net event for pointing to the current netdev
From: Long Li <[email protected]>
When running under Hyper-V, the master device to the RDMA device is always bonded to this RDMA device if it's present in the kernel. This is not user- configurable.
Quoted 5 lines
The master device can be unbind/bind from the kernel. During those events, the RDMA device should set to the current netdev to relect the change of master device from those events.
Signed-off-by Long Li <[email protected]>
This is not the correct patch. Please discard this patch.
Quoted 82 lines
--- drivers/infiniband/hw/mana/device.c | 35 ++++++++++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 1 + 2 files changed, 36 insertions(+)drivers/infiniband/hw/mana/device.c +36
-0@@ -51,6 +51,37 @@ static const struct ib_device_ops mana_ib_dev_ops = { ib_ind_table), }; +static int mana_ib_netdev_event (struct notifier_block *this, +unsigned long event,void *ptr) +{ + struct mana_ib_dev *dev = container_of(this, struct mana_ib_dev, nb); +struct net_device *event_dev =netdev_notifier_info_to_dev (ptr); +struct gdma_context *gc = dev->gdma_dev->gdma_context; +struct mana_context *mc = gc->mana.driver_data; +struct net_device *ndev; + +if (event_dev != mc->ports[0 ]) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_CHANGEUPPER : +rcu_read_lock (); + ndev =mana_get_primary_netdev_rcu (mc,0 ); +rcu_read_unlock (); + +/* +* RDMA core will setup GID based on updated netdev. +* It's not possible to race with the core as rtnl lock is being +* held. +*/ +ib_device_set_netdev (&dev->ib_dev, ndev,1 ); + +return NOTIFY_OK ; +default : +return NOTIFY_DONE ; + } +} +static int mana_ib_probe (struct auxiliary_device *adev, const struct auxiliary_device_id *id) { @@ -109,6 +140,9 @@ static int mana_ib_probe(struct auxiliary_device *adev, } dev->gdma_dev = &mdev->gdma_context->mana_ib; + dev->nb.notifier_call = mana_ib_netdev_event; +register_netdevice_notifier (&dev->nb); + ret =mana_ib_gd_query_adapter_caps (dev);if (ret) { ibdev_err(&dev->ib_dev, "Failed to query device caps, ret %d",@@ -159,6 +193,7 @@ static void mana_ib_remove(struct auxiliary_device *adev) {struct mana_ib_dev *dev =dev_get_drvdata (&adev->dev); +unregister_netdevice_notifier (&dev->nb);ib_unregister_device (&dev->ib_dev);xa_destroy (&dev->qp_table_wq);mana_ib_gd_destroy_rnic_adapter (dev);drivers/infiniband/hw/mana/mana_ib.h +1
-1@@ -64,6 +64,7 @@ struct mana_ib_dev {struct gdma_queue **eqs;struct xarray qp_table_wq;struct mana_ib_adapter_caps adapter_caps; +struct notifier_block nb; };struct mana_ib_wq { --2.34.1
Quoted 4 lines · On Fri, Feb 28, 2025 at 02:41:59PM -0800, [email protected] wrote:
drivers/infiniband/hw/mana/device.c +4
-0+ struct mana_ib_dev *dev = container_of(this, struct mana_ib_dev, nb); +struct net_device *event_dev =netdev_notifier_info_to_dev (ptr); +struct gdma_context *gc = dev->gdma_dev->gdma_context; +struct mana_context *mc = gc->mana.driver_data;
drivers/infiniband/hw/mana/device.c static const struct ib_device_ops mana_ib_dev_ops = { · line 70
Quoted 10 lines
drivers/infiniband/hw/mana/device.c +10
-0+struct net_device *ndev; + +if (event_dev != mc->ports[0 ]) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_CHANGEUPPER : +rcu_read_lock (); + ndev =mana_get_primary_netdev_rcu (mc,0 ); +rcu_read_unlock ();
That locking sure looks weird/wrong.
Jason
Quoted 22 lines
Subject: [EXTERNAL] Re: [Patch rdma-next] RDMA/mana_ib: handle net event for pointing to the current netdev
Review
Quoted 1 line · On Fri, Feb 28, 2025 at 02:41:59PM -0800, [email protected] wrote:
(quoted diff) +1
-0+ struct mana_ib_dev *dev = container_of(this, struct mana_ib_dev,nb);
drivers/infiniband/hw/mana/device.c static const struct ib_device_ops mana_ib_dev_ops = { · line 70
Quoted 13 lines
drivers/infiniband/hw/mana/device.c +13
-0+struct net_device *event_dev =netdev_notifier_info_to_dev (ptr); +struct gdma_context *gc = dev->gdma_dev->gdma_context; +struct mana_context *mc = gc->mana.driver_data; +struct net_device *ndev; + +if (event_dev != mc->ports[0 ]) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_CHANGEUPPER : +rcu_read_lock (); + ndev =mana_get_primary_netdev_rcu (mc,0 ); +rcu_read_unlock ();That locking sure looks weird/wrong.
Quoted 1 line
Jason
I think the locking is necessary as mana_get_primary_netdev_rcu() requires a RCU lock. It's safe to nest rcu_read_lock() if it's already held.
I have sent v2. v1 is from an earlier branch and is missing some error handling code.
Thanks,
Long
Quoted 41 lines · On 2025-03-01 at 04:11:59, [email protected] ([email protected])…
From: Long Li <[email protected]>
When running under Hyper-V, the master device to the RDMA device is always bonded to this RDMA device if it's present in the kernel. This is not user-configurable.
The master device can be unbind/bind from the kernel. During those events, the RDMA device should set to the current netdev to relect the change of master device from those events.
Signed-off-by Long Li <[email protected]>--- drivers/infiniband/hw/mana/device.c | 35 ++++++++++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 1 + 2 files changed, 36 insertions(+)drivers/infiniband/hw/mana/device.c +17
-0@@ -51,6 +51,37 @@ static const struct ib_device_ops mana_ib_dev_ops = { ib_ind_table), }; +static int mana_ib_netdev_event (struct notifier_block *this, +unsigned long event,void *ptr) +{ + struct mana_ib_dev *dev = container_of(this, struct mana_ib_dev, nb); +struct net_device *event_dev =netdev_notifier_info_to_dev (ptr); +struct gdma_context *gc = dev->gdma_dev->gdma_context; +struct mana_context *mc = gc->mana.driver_data; +struct net_device *ndev; + +if (event_dev != mc->ports[0 ]) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_CHANGEUPPER : +rcu_read_lock (); + ndev =mana_get_primary_netdev_rcu (mc,0 ); +rcu_read_unlock ();
...
drivers/infiniband/hw/mana/device.c static const struct ib_device_ops mana_ib_dev_ops = { · line 77
Quoted 7 lines
drivers/infiniband/hw/mana/device.c +7
-0+ +/* +* RDMA core will setup GID based on updated netdev. +* It's not possible to race with the core as rtnl lock is being +* held. +*/ +ib_device_set_netdev (&dev->ib_dev, ndev,1 );
rcu_read_unlock() should be here, right ?
Quoted 8 lines
drivers/infiniband/hw/mana/device.c +7
-0+ +return NOTIFY_OK ; +default : +return NOTIFY_DONE ; + } +} +
Quoted 44 lines
Quoted 41 lines · On 2025-03-01 at 04:11:59, [email protected] ([email protected])…
From: Long Li <[email protected]>
When running under Hyper-V, the master device to the RDMA device is always bonded to this RDMA device if it's present in the kernel. This is not user-configurable.
The master device can be unbind/bind from the kernel. During those events, the RDMA device should set to the current netdev to relect the change of master device from those events.
Signed-off-by Long Li <[email protected]>--- drivers/infiniband/hw/mana/device.c | 35 ++++++++++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 1 + 2 files changed, 36 insertions(+)drivers/infiniband/hw/mana/device.c +16
-0@@ -51,6 +51,37 @@ static const struct ib_device_ops mana_ib_dev_ops = { ib_ind_table), }; +static int mana_ib_netdev_event (struct notifier_block *this, +unsigned long event,void *ptr) { + struct mana_ib_dev *dev = container_of(this, struct mana_ib_dev, nb); +struct net_device *event_dev =netdev_notifier_info_to_dev (ptr); +struct gdma_context *gc = dev->gdma_dev->gdma_context; +struct mana_context *mc = gc->mana.driver_data; +struct net_device *ndev; + +if (event_dev != mc->ports[0 ]) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_CHANGEUPPER : +rcu_read_lock (); + ndev =mana_get_primary_netdev_rcu (mc,0 ); +rcu_read_unlock ();...
Quoted 8 lines
drivers/infiniband/hw/mana/device.c static const struct ib_device_ops mana_ib_dev_ops = { · line 77
Quoted 7 lines
drivers/infiniband/hw/mana/device.c +7
-0+ +/* +* RDMA core will setup GID based on updated netdev. +* It's not possible to race with the core as rtnl lock is being +* held. +*/ +ib_device_set_netdev (&dev->ib_dev, ndev,1 );
rcu_read_unlock()should be here, right ?
It can't. ib_device_set_netdev() is calling alloc_port_data() and may sleep.
I think this locking is okay. This event only comes in when:
1. the master device has changed to netvsc. In this case ndev is guaranteed to be valid as this notification is triggered by netvsc.
2. the master device has changed to itself (the ethernet device parent for the IB device). In this case, ndev is valid because mana_ib is an auxiliary device to ndev and it can't unload itself at this time.
Quoted 51 lines · Long Li
Quoted 51 lines
Quoted 41 lines · On 2025-03-01 at 04:11:59, [email protected] ([email protected])…
From: Long Li <[email protected]>
When running under Hyper-V, the master device to the RDMA device is always bonded to this RDMA device if it's present in the kernel. This is not user-configurable.
The master device can be unbind/bind from the kernel. During those events, the RDMA device should set to the current netdev to relect the change of master device from those events.
Signed-off-by Long Li <[email protected]>--- drivers/infiniband/hw/mana/device.c | 35 ++++++++++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 1 + 2 files changed, 36 insertions(+)drivers/infiniband/hw/mana/device.c +16
-0@@ -51,6 +51,37 @@ static const struct ib_device_ops mana_ib_dev_ops = { ib_ind_table), }; +static int mana_ib_netdev_event (struct notifier_block *this, +unsigned long event,void *ptr) { + struct mana_ib_dev *dev = container_of(this, struct mana_ib_dev, nb); +struct net_device *event_dev =netdev_notifier_info_to_dev (ptr); +struct gdma_context *gc = dev->gdma_dev->gdma_context; +struct mana_context *mc = gc->mana.driver_data; +struct net_device *ndev; + +if (event_dev != mc->ports[0 ]) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_CHANGEUPPER : +rcu_read_lock (); + ndev =mana_get_primary_netdev_rcu (mc,0 ); +rcu_read_unlock ();...
Quoted 7 lines
drivers/infiniband/hw/mana/device.c +7
-0+ +/* +* RDMA core will setup GID based on updated netdev. +* It's not possible to race with the core as rtnl lock is being +* held. +*/ +ib_device_set_netdev (&dev->ib_dev, ndev,1 );
Quoted 7 lines
Quoted 1 line
rcu_read_unlock()should be here, right ?It can't.
ib_device_set_netdev()is callingalloc_port_data()and may sleep.I think this locking is okay. This event only comes in when:
1. the master device has changed to netvsc. In this case ndev is guaranteed to be valid as this notification is triggered by netvsc.
2. the master device has changed to itself (the ethernet device parent for the IB device). In this case, ndev is valid becausemana_ibis an auxiliary device to ndev and it can't unload itself at this time.
Why not return with the netdev refcount held so you don't need this weirdo rcu thing?
Jason
Quoted 65 lines
Subject: Re: [EXTERNAL] Re: [Patch rdma-next] RDMA/mana_ib: handle net event for pointing to the current netdev
Quoted 20 lines · Long Li
Quoted 20 lines
Quoted 18 lines · On 2025-03-01 at 04:11:59, [email protected] ([email protected])…
From: Long Li <[email protected]>
When running under Hyper-V, the master device to the RDMA device is always bonded to this RDMA device if it's present in the kernel. This is not user-configurable.
The master device can be unbind/bind from the kernel. During those events, the RDMA device should set to the current netdev to relect the change of master device from those events.
Signed-off-by Long Li <[email protected]>--- drivers/infiniband/hw/mana/device.c | 35 ++++++++++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h ++++++++++++++++++++++++++++ | 1 + 2 files changed, 36 insertions(+)Quoted 6 lines
Quoted 6 lines
drivers/infiniband/hw/mana/device.c static const struct ib_device_ops mana_ib_dev_ops =
Quoted 6 lines
drivers/infiniband/hw/mana/device.c +0
-0@@ -51,6 +51,37 @@ static const struct ib_device_ops mana_ib_dev_ops ={
Quoted 26 lines
Quoted 26 lines
Quoted 18 lines
drivers/infiniband/hw/mana/device.c +16
-0ib_ind_table), }; +static int mana_ib_netdev_event (struct notifier_block *this, +unsigned long event,void *ptr) { + struct mana_ib_dev *dev = container_of(this, struct mana_ib_dev, nb); +struct net_device *event_dev =netdev_notifier_info_to_dev (ptr); +struct gdma_context *gc = dev->gdma_dev->gdma_context; +struct mana_context *mc = gc->mana.driver_data; +struct net_device *ndev; + +if (event_dev != mc->ports[0 ]) +return NOTIFY_DONE ; + +switch (event) { +case NETDEV_CHANGEUPPER : +rcu_read_lock (); + ndev =mana_get_primary_netdev_rcu (mc,0 ); +rcu_read_unlock ();...
Quoted 7 lines
drivers/infiniband/hw/mana/device.c +7
-0+ +/* +* RDMA core will setup GID based on updated netdev. +* It's not possible to race with the core as rtnl lock is being +* held. +*/ +ib_device_set_netdev (&dev->ib_dev, ndev,1 );Quoted 6 lines
Quoted 1 line
rcu_read_unlock()should be here, right ?It can't.
ib_device_set_netdev()is callingalloc_port_data()and may sleep.I think this locking is okay. This event only comes in when:
1. the master device has changed to netvsc. In this case ndev is guaranteed tobe valid as this notification is triggered by netvsc.
Quoted 1 line
2. the master device has changed to itself (the ethernet device parent for the IB
Quoted 8 lines
device). In this case, ndev is valid because
mana_ibis an auxiliary device to ndev and it can't unload itself at this time.Why not return with the netdev refcount held so you don't need this weirdo rcu thing?
Jason
I sent v3 with netdev refcount held. Thank you.
Long