Skip to content

Commit 8e95960

Browse files
nvishwa1dledford
authored andcommitted
IB/core, opa_vnic, hfi1, mlx5: Properly free rdma_netdev
IPOIB is calling free_rdma_netdev even though alloc_rdma_netdev has returned -EOPNOTSUPP. Move free_rdma_netdev from ib_device structure to rdma_netdev structure thus ensuring proper cleanup function is called for the rdma net device. Fix the following trace: ib0: Failed to modify QP to ERROR state BUG: unable to handle kernel paging request at 0000000000001d20 IP: hfi1_vnic_free_rn+0x26/0xb0 [hfi1] Call Trace: ipoib_remove_one+0xbe/0x160 [ib_ipoib] ib_unregister_device+0xd0/0x170 [ib_core] rvt_unregister_device+0x29/0x90 [rdmavt] hfi1_unregister_ib_device+0x1a/0x100 [hfi1] remove_one+0x4b/0x220 [hfi1] pci_device_remove+0x39/0xc0 device_release_driver_internal+0x141/0x200 driver_detach+0x3f/0x80 bus_remove_driver+0x55/0xd0 driver_unregister+0x2c/0x50 pci_unregister_driver+0x2a/0xa0 hfi1_mod_cleanup+0x10/0xf65 [hfi1] SyS_delete_module+0x171/0x250 do_syscall_64+0x67/0x150 entry_SYSCALL64_slow_path+0x25/0x25 Reviewed-by: Dennis Dalessandro <[email protected]> Signed-off-by: Niranjana Vishwanathapura <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 5ecce4c commit 8e95960

File tree

7 files changed

+39
-31
lines changed

7 files changed

+39
-31
lines changed

drivers/infiniband/hw/hfi1/verbs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,6 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
17791779
ibdev->alloc_hw_stats = alloc_hw_stats;
17801780
ibdev->get_hw_stats = get_hw_stats;
17811781
ibdev->alloc_rdma_netdev = hfi1_vnic_alloc_rn;
1782-
ibdev->free_rdma_netdev = hfi1_vnic_free_rn;
17831782

17841783
/* keep process mad in the driver */
17851784
ibdev->process_mad = hfi1_process_mad;

drivers/infiniband/hw/hfi1/vnic.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
176176
const char *name,
177177
unsigned char name_assign_type,
178178
void (*setup)(struct net_device *));
179-
void hfi1_vnic_free_rn(struct net_device *netdev);
180179
int hfi1_vnic_send_dma(struct hfi1_devdata *dd, u8 q_idx,
181180
struct hfi1_vnic_vport_info *vinfo,
182181
struct sk_buff *skb, u64 pbc, u8 plen);

drivers/infiniband/hw/hfi1/vnic_main.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,15 @@ static const struct net_device_ops hfi1_netdev_ops = {
833833
.ndo_get_stats64 = hfi1_vnic_get_stats64,
834834
};
835835

836+
static void hfi1_vnic_free_rn(struct net_device *netdev)
837+
{
838+
struct hfi1_vnic_vport_info *vinfo = opa_vnic_dev_priv(netdev);
839+
840+
hfi1_vnic_deinit(vinfo);
841+
mutex_destroy(&vinfo->lock);
842+
free_netdev(netdev);
843+
}
844+
836845
struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
837846
u8 port_num,
838847
enum rdma_netdev_t type,
@@ -864,6 +873,7 @@ struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
864873
vinfo->num_tx_q = dd->chip_sdma_engines;
865874
vinfo->num_rx_q = HFI1_NUM_VNIC_CTXT;
866875
vinfo->netdev = netdev;
876+
rn->free_rdma_netdev = hfi1_vnic_free_rn;
867877
rn->set_id = hfi1_vnic_set_vesw_id;
868878

869879
netdev->features = NETIF_F_HIGHDMA | NETIF_F_SG;
@@ -892,12 +902,3 @@ struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
892902
free_netdev(netdev);
893903
return ERR_PTR(rc);
894904
}
895-
896-
void hfi1_vnic_free_rn(struct net_device *netdev)
897-
{
898-
struct hfi1_vnic_vport_info *vinfo = opa_vnic_dev_priv(netdev);
899-
900-
hfi1_vnic_deinit(vinfo);
901-
mutex_destroy(&vinfo->lock);
902-
free_netdev(netdev);
903-
}

drivers/infiniband/hw/mlx5/main.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,6 +3542,11 @@ static int mlx5_ib_get_hw_stats(struct ib_device *ibdev,
35423542
return num_counters;
35433543
}
35443544

3545+
static void mlx5_ib_free_rdma_netdev(struct net_device *netdev)
3546+
{
3547+
return mlx5_rdma_netdev_free(netdev);
3548+
}
3549+
35453550
static struct net_device*
35463551
mlx5_ib_alloc_rdma_netdev(struct ib_device *hca,
35473552
u8 port_num,
@@ -3550,16 +3555,19 @@ mlx5_ib_alloc_rdma_netdev(struct ib_device *hca,
35503555
unsigned char name_assign_type,
35513556
void (*setup)(struct net_device *))
35523557
{
3558+
struct net_device *netdev;
3559+
struct rdma_netdev *rn;
3560+
35533561
if (type != RDMA_NETDEV_IPOIB)
35543562
return ERR_PTR(-EOPNOTSUPP);
35553563

3556-
return mlx5_rdma_netdev_alloc(to_mdev(hca)->mdev, hca,
3557-
name, setup);
3558-
}
3559-
3560-
static void mlx5_ib_free_rdma_netdev(struct net_device *netdev)
3561-
{
3562-
return mlx5_rdma_netdev_free(netdev);
3564+
netdev = mlx5_rdma_netdev_alloc(to_mdev(hca)->mdev, hca,
3565+
name, setup);
3566+
if (likely(!IS_ERR_OR_NULL(netdev))) {
3567+
rn = netdev_priv(netdev);
3568+
rn->free_rdma_netdev = mlx5_ib_free_rdma_netdev;
3569+
}
3570+
return netdev;
35633571
}
35643572

35653573
static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
@@ -3692,10 +3700,9 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
36923700
dev->ib_dev.check_mr_status = mlx5_ib_check_mr_status;
36933701
dev->ib_dev.get_port_immutable = mlx5_port_immutable;
36943702
dev->ib_dev.get_dev_fw_str = get_dev_fw_str;
3695-
if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads)) {
3703+
if (MLX5_CAP_GEN(mdev, ipoib_enhanced_offloads))
36963704
dev->ib_dev.alloc_rdma_netdev = mlx5_ib_alloc_rdma_netdev;
3697-
dev->ib_dev.free_rdma_netdev = mlx5_ib_free_rdma_netdev;
3698-
}
3705+
36993706
if (mlx5_core_is_pf(mdev)) {
37003707
dev->ib_dev.get_vf_config = mlx5_ib_get_vf_config;
37013708
dev->ib_dev.set_vf_link_state = mlx5_ib_set_vf_link_state;

drivers/infiniband/ulp/ipoib/ipoib_main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,7 @@ static struct net_device
18931893
rn->send = ipoib_send;
18941894
rn->attach_mcast = ipoib_mcast_attach;
18951895
rn->detach_mcast = ipoib_mcast_detach;
1896+
rn->free_rdma_netdev = free_netdev;
18961897
rn->hca = hca;
18971898

18981899
dev->netdev_ops = &ipoib_netdev_default_pf;
@@ -2288,6 +2289,8 @@ static void ipoib_remove_one(struct ib_device *device, void *client_data)
22882289
return;
22892290

22902291
list_for_each_entry_safe(priv, tmp, dev_list, list) {
2292+
struct rdma_netdev *rn = netdev_priv(priv->dev);
2293+
22912294
ib_unregister_event_handler(&priv->event_handler);
22922295
flush_workqueue(ipoib_workqueue);
22932296

@@ -2304,10 +2307,7 @@ static void ipoib_remove_one(struct ib_device *device, void *client_data)
23042307
flush_workqueue(priv->wq);
23052308

23062309
unregister_netdev(priv->dev);
2307-
if (device->free_rdma_netdev)
2308-
device->free_rdma_netdev(priv->dev);
2309-
else
2310-
free_netdev(priv->dev);
2310+
rn->free_rdma_netdev(priv->dev);
23112311

23122312
list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list)
23132313
kfree(cpriv);

drivers/infiniband/ulp/opa_vnic/opa_vnic_netdev.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,13 @@ struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,
323323
else if (IS_ERR(netdev))
324324
return ERR_CAST(netdev);
325325

326+
rn = netdev_priv(netdev);
326327
adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
327328
if (!adapter) {
328329
rc = -ENOMEM;
329330
goto adapter_err;
330331
}
331332

332-
rn = netdev_priv(netdev);
333333
rn->clnt_priv = adapter;
334334
rn->hca = ibdev;
335335
rn->port_num = port_num;
@@ -366,7 +366,7 @@ struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,
366366
mutex_destroy(&adapter->mactbl_lock);
367367
kfree(adapter);
368368
adapter_err:
369-
ibdev->free_rdma_netdev(netdev);
369+
rn->free_rdma_netdev(netdev);
370370

371371
return ERR_PTR(rc);
372372
}
@@ -375,13 +375,13 @@ struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,
375375
void opa_vnic_rem_netdev(struct opa_vnic_adapter *adapter)
376376
{
377377
struct net_device *netdev = adapter->netdev;
378-
struct ib_device *ibdev = adapter->ibdev;
378+
struct rdma_netdev *rn = netdev_priv(netdev);
379379

380380
v_info("removing\n");
381381
unregister_netdev(netdev);
382382
opa_vnic_release_mac_tbl(adapter);
383383
mutex_destroy(&adapter->lock);
384384
mutex_destroy(&adapter->mactbl_lock);
385385
kfree(adapter);
386-
ibdev->free_rdma_netdev(netdev);
386+
rn->free_rdma_netdev(netdev);
387387
}

include/rdma/ib_verbs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,9 @@ struct rdma_netdev {
19271927
struct ib_device *hca;
19281928
u8 port_num;
19291929

1930+
/* cleanup function must be specified */
1931+
void (*free_rdma_netdev)(struct net_device *netdev);
1932+
19301933
/* control functions */
19311934
void (*set_id)(struct net_device *netdev, int id);
19321935
/* send packet */
@@ -2194,7 +2197,7 @@ struct ib_device {
21942197
struct ib_udata *udata);
21952198
int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
21962199
/**
2197-
* rdma netdev operations
2200+
* rdma netdev operation
21982201
*
21992202
* Driver implementing alloc_rdma_netdev must return -EOPNOTSUPP if it
22002203
* doesn't support the specified rdma netdev type.
@@ -2206,7 +2209,6 @@ struct ib_device {
22062209
const char *name,
22072210
unsigned char name_assign_type,
22082211
void (*setup)(struct net_device *));
2209-
void (*free_rdma_netdev)(struct net_device *netdev);
22102212

22112213
struct module *owner;
22122214
struct device dev;

0 commit comments

Comments
 (0)