Skip to content

Commit 609ea65

Browse files
Vadim Lomovtsevdavem330
authored andcommitted
net: thunderx: add mutex to protect mailbox from concurrent calls for same VF
In some cases it could happen that nicvf_send_msg_to_pf() could be called concurrently for the same NIC VF, and thus re-writing mailbox contents and breaking messaging sequence with PF by re-writing NICVF data. This commit is to implement mutex for NICVF to protect mailbox registers and NICVF messaging control data from concurrent access. Signed-off-by: Vadim Lomovtsev <vlomovtsev@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5354439 commit 609ea65

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

drivers/net/ethernet/cavium/thunder/nic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ struct nicvf {
329329
spinlock_t rx_mode_wq_lock;
330330
/* workqueue for handling kernel ndo_set_rx_mode() calls */
331331
struct workqueue_struct *nicvf_rx_mode_wq;
332+
/* mutex to protect VF's mailbox contents from concurrent access */
333+
struct mutex rx_mode_mtx;
332334

333335
/* PTP timestamp */
334336
struct cavium_ptp *ptp_clock;

drivers/net/ethernet/cavium/thunder/nicvf_main.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ int nicvf_send_msg_to_pf(struct nicvf *nic, union nic_mbx *mbx)
124124
{
125125
int timeout = NIC_MBOX_MSG_TIMEOUT;
126126
int sleep = 10;
127+
int ret = 0;
128+
129+
mutex_lock(&nic->rx_mode_mtx);
127130

128131
nic->pf_acked = false;
129132
nic->pf_nacked = false;
@@ -136,7 +139,8 @@ int nicvf_send_msg_to_pf(struct nicvf *nic, union nic_mbx *mbx)
136139
netdev_err(nic->netdev,
137140
"PF NACK to mbox msg 0x%02x from VF%d\n",
138141
(mbx->msg.msg & 0xFF), nic->vf_id);
139-
return -EINVAL;
142+
ret = -EINVAL;
143+
break;
140144
}
141145
msleep(sleep);
142146
if (nic->pf_acked)
@@ -146,10 +150,12 @@ int nicvf_send_msg_to_pf(struct nicvf *nic, union nic_mbx *mbx)
146150
netdev_err(nic->netdev,
147151
"PF didn't ACK to mbox msg 0x%02x from VF%d\n",
148152
(mbx->msg.msg & 0xFF), nic->vf_id);
149-
return -EBUSY;
153+
ret = -EBUSY;
154+
break;
150155
}
151156
}
152-
return 0;
157+
mutex_unlock(&nic->rx_mode_mtx);
158+
return ret;
153159
}
154160

155161
/* Checks if VF is able to comminicate with PF
@@ -2208,6 +2214,7 @@ static int nicvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
22082214
nic->vf_id);
22092215
INIT_WORK(&nic->rx_mode_work.work, nicvf_set_rx_mode_task);
22102216
spin_lock_init(&nic->rx_mode_wq_lock);
2217+
mutex_init(&nic->rx_mode_mtx);
22112218

22122219
err = register_netdev(netdev);
22132220
if (err) {

0 commit comments

Comments
 (0)