Skip to content

Commit 84e1f4d

Browse files
committed
net/netvsc: handle VF recovery events for service reset
Register callbacks for RTE_ETH_EVENT_ERR_RECOVERING, RTE_ETH_EVENT_RECOVERY_SUCCESS, and RTE_ETH_EVENT_RECOVERY_FAILED events on the VF port to handle MANA service resets. - On ERR_RECOVERING: switch data path to synthetic but keep the VF device attached in DPDK - On RECOVERY_SUCCESS: switch data path back to VF - On RECOVERY_FAILED: do full VF removal (same as INTR_RMV) - Unregister all recovery callbacks during detach, removal, and close This ensures that during a service reset (kernel suspend/resume without PCI remove), netvsc keeps the VF attached and seamlessly switches back to it after recovery, without requiring a PCI hot-add event. This change is compatible with the current behavior when no service reset messages are received. Signed-off-by: Long Li <longli@microsoft.com>
1 parent df44aa9 commit 84e1f4d

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

drivers/net/netvsc/hn_vf.c

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ static int hn_vf_match(const struct rte_eth_dev *dev)
5050
}
5151

5252

53+
static int hn_eth_recovering_callback(uint16_t port_id,
54+
enum rte_eth_event_type event, void *cb_arg, void *out);
55+
static int hn_eth_recovery_success_callback(uint16_t port_id,
56+
enum rte_eth_event_type event, void *cb_arg, void *out);
57+
static int hn_eth_recovery_failed_callback(uint16_t port_id,
58+
enum rte_eth_event_type event, void *cb_arg, void *out);
59+
5360
/*
5461
* Attach new PCI VF device and return the port_id
5562
*/
@@ -111,7 +118,56 @@ static int hn_vf_attach(struct rte_eth_dev *dev, struct hn_data *hv)
111118
return ret;
112119
}
113120

121+
/* Register recovery event callbacks for service reset handling */
122+
ret = rte_eth_dev_callback_register(hv->vf_ctx.vf_port,
123+
RTE_ETH_EVENT_ERR_RECOVERING,
124+
hn_eth_recovering_callback, hv);
125+
if (ret) {
126+
PMD_DRV_LOG(ERR,
127+
"Registering recovering callback failed for vf port %d ret %d",
128+
port, ret);
129+
goto err_recovering;
130+
}
131+
132+
ret = rte_eth_dev_callback_register(hv->vf_ctx.vf_port,
133+
RTE_ETH_EVENT_RECOVERY_SUCCESS,
134+
hn_eth_recovery_success_callback, hv);
135+
if (ret) {
136+
PMD_DRV_LOG(ERR,
137+
"Registering recovery success callback failed for vf port %d ret %d",
138+
port, ret);
139+
goto err_recovery_success;
140+
}
141+
142+
ret = rte_eth_dev_callback_register(hv->vf_ctx.vf_port,
143+
RTE_ETH_EVENT_RECOVERY_FAILED,
144+
hn_eth_recovery_failed_callback, hv);
145+
if (ret) {
146+
PMD_DRV_LOG(ERR,
147+
"Registering recovery failed callback failed for vf port %d ret %d",
148+
port, ret);
149+
goto err_recovery_failed;
150+
}
151+
114152
return 0;
153+
154+
err_recovery_failed:
155+
rte_eth_dev_callback_unregister(hv->vf_ctx.vf_port,
156+
RTE_ETH_EVENT_RECOVERY_SUCCESS,
157+
hn_eth_recovery_success_callback, hv);
158+
err_recovery_success:
159+
rte_eth_dev_callback_unregister(hv->vf_ctx.vf_port,
160+
RTE_ETH_EVENT_ERR_RECOVERING,
161+
hn_eth_recovering_callback, hv);
162+
err_recovering:
163+
rte_eth_dev_callback_unregister(hv->vf_ctx.vf_port,
164+
RTE_ETH_EVENT_INTR_RMV,
165+
hn_eth_rmv_event_callback, hv);
166+
hv->vf_ctx.vf_attached = false;
167+
hv->vf_ctx.vf_port = 0;
168+
if (rte_eth_dev_owner_unset(port, hv->owner.id) < 0)
169+
PMD_DRV_LOG(ERR, "Failed to unset owner for port %d", port);
170+
return ret;
115171
}
116172

117173
static void hn_vf_remove_unlocked(struct hn_data *hv);
@@ -143,6 +199,12 @@ static void hn_remove_delayed(void *args)
143199
PMD_DRV_LOG(ERR,
144200
"rte_eth_dev_callback_unregister failed ret=%d",
145201
ret);
202+
rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_ERR_RECOVERING,
203+
hn_eth_recovering_callback, hv);
204+
rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_RECOVERY_SUCCESS,
205+
hn_eth_recovery_success_callback, hv);
206+
rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_RECOVERY_FAILED,
207+
hn_eth_recovery_failed_callback, hv);
146208

147209
/* Detach and release port_id from system */
148210
ret = rte_eth_dev_stop(port_id);
@@ -187,6 +249,85 @@ int hn_eth_rmv_event_callback(uint16_t port_id,
187249
return 0;
188250
}
189251

252+
/*
253+
* Handle VF error recovery event from MANA PMD.
254+
* Switch data path to synthetic but keep the VF attached.
255+
*
256+
* Unlike hn_eth_rmv_event_callback (which defers via rte_eal_alarm_set
257+
* to break potential lock-order coupling), we acquire vf_lock directly
258+
* here. This is safe because the MANA PMD fires recovery events from
259+
* its interrupt handler context without holding any lock that could
260+
* overlap with vf_lock.
261+
*/
262+
static int
263+
hn_eth_recovering_callback(uint16_t port_id,
264+
enum rte_eth_event_type event __rte_unused,
265+
void *cb_arg, void *out __rte_unused)
266+
{
267+
struct hn_data *hv = cb_arg;
268+
269+
PMD_DRV_LOG(NOTICE, "VF port %u recovering from error", port_id);
270+
271+
rte_rwlock_write_lock(&hv->vf_lock);
272+
hn_vf_remove_unlocked(hv);
273+
rte_rwlock_write_unlock(&hv->vf_lock);
274+
275+
return 0;
276+
}
277+
278+
/*
279+
* Handle VF recovery success event from MANA PMD.
280+
* Switch data path back to VF.
281+
*/
282+
static int
283+
hn_eth_recovery_success_callback(uint16_t port_id,
284+
enum rte_eth_event_type event __rte_unused,
285+
void *cb_arg, void *out __rte_unused)
286+
{
287+
struct hn_data *hv = cb_arg;
288+
struct rte_eth_dev *dev = &rte_eth_devices[hv->port_id];
289+
int ret;
290+
291+
PMD_DRV_LOG(NOTICE, "VF port %u recovery succeeded", port_id);
292+
293+
rte_rwlock_write_lock(&hv->vf_lock);
294+
/* Only switch data path to VF if the netvsc device is started,
295+
* mirroring the check in hn_vf_add_unlocked. If the device was
296+
* stopped during recovery, defer to hn_vf_start().
297+
*/
298+
if (dev->data->dev_started &&
299+
hv->vf_ctx.vf_attached && !hv->vf_ctx.vf_vsc_switched) {
300+
ret = hn_nvs_set_datapath(hv, NVS_DATAPATH_VF);
301+
if (ret)
302+
PMD_DRV_LOG(ERR, "Failed to switch to VF after recovery");
303+
else
304+
hv->vf_ctx.vf_vsc_switched = true;
305+
}
306+
rte_rwlock_write_unlock(&hv->vf_lock);
307+
308+
return 0;
309+
}
310+
311+
/*
312+
* Handle VF recovery failure event from MANA PMD.
313+
* VF is unusable, do full removal.
314+
*/
315+
static int
316+
hn_eth_recovery_failed_callback(uint16_t port_id,
317+
enum rte_eth_event_type event __rte_unused,
318+
void *cb_arg, void *out __rte_unused)
319+
{
320+
struct hn_data *hv = cb_arg;
321+
322+
PMD_DRV_LOG(NOTICE, "VF port %u recovery failed, removing", port_id);
323+
324+
/* Guard against concurrent INTR_RMV that already detached the VF */
325+
if (hv->vf_ctx.vf_attached)
326+
rte_eal_alarm_set(1, hn_remove_delayed, hv);
327+
328+
return 0;
329+
}
330+
190331
static int hn_setup_vf_queues(int port, struct rte_eth_dev *dev)
191332
{
192333
struct hn_rx_queue *rx_queue;
@@ -247,6 +388,12 @@ static void hn_vf_detach(struct hn_data *hv)
247388

248389
rte_eth_dev_callback_unregister(port, RTE_ETH_EVENT_INTR_RMV,
249390
hn_eth_rmv_event_callback, hv);
391+
rte_eth_dev_callback_unregister(port, RTE_ETH_EVENT_ERR_RECOVERING,
392+
hn_eth_recovering_callback, hv);
393+
rte_eth_dev_callback_unregister(port, RTE_ETH_EVENT_RECOVERY_SUCCESS,
394+
hn_eth_recovery_success_callback, hv);
395+
rte_eth_dev_callback_unregister(port, RTE_ETH_EVENT_RECOVERY_FAILED,
396+
hn_eth_recovery_failed_callback, hv);
250397

251398
if (rte_eth_dev_owner_unset(port, hv->owner.id) < 0)
252399
PMD_DRV_LOG(ERR, "Failed to unset owner for port %d", port);
@@ -630,6 +777,18 @@ int hn_vf_close(struct rte_eth_dev *dev)
630777
RTE_ETH_EVENT_INTR_RMV,
631778
hn_eth_rmv_event_callback,
632779
hv);
780+
rte_eth_dev_callback_unregister(hv->vf_ctx.vf_port,
781+
RTE_ETH_EVENT_ERR_RECOVERING,
782+
hn_eth_recovering_callback,
783+
hv);
784+
rte_eth_dev_callback_unregister(hv->vf_ctx.vf_port,
785+
RTE_ETH_EVENT_RECOVERY_SUCCESS,
786+
hn_eth_recovery_success_callback,
787+
hv);
788+
rte_eth_dev_callback_unregister(hv->vf_ctx.vf_port,
789+
RTE_ETH_EVENT_RECOVERY_FAILED,
790+
hn_eth_recovery_failed_callback,
791+
hv);
633792
rte_eal_alarm_cancel(hn_remove_delayed, hv);
634793
ret = rte_eth_dev_close(hv->vf_ctx.vf_port);
635794
hv->vf_ctx.vf_attached = false;

0 commit comments

Comments
 (0)