Skip to content

Commit 3176e97

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vdpa/mlx5: should keep avail_index despite device status
A VM with mlx5 vDPA has below warnings while being reset: vhost VQ 0 ring restore failed: -1: Resource temporarily unavailable (11) vhost VQ 1 ring restore failed: -1: Resource temporarily unavailable (11) We should allow userspace emulating the virtio device be able to get to vq's avail_index, regardless of vDPA device status. Save the index that was last seen when virtq was stopped, so that userspace doesn't complain. Signed-off-by: Si-Wei Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Eli Cohen <[email protected]>
1 parent 7ed9e3d commit 3176e97

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,15 +1133,17 @@ static void suspend_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *m
11331133
if (!mvq->initialized)
11341134
return;
11351135

1136-
if (query_virtqueue(ndev, mvq, &attr)) {
1137-
mlx5_vdpa_warn(&ndev->mvdev, "failed to query virtqueue\n");
1138-
return;
1139-
}
11401136
if (mvq->fw_state != MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY)
11411137
return;
11421138

11431139
if (modify_virtqueue(ndev, mvq, MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND))
11441140
mlx5_vdpa_warn(&ndev->mvdev, "modify to suspend failed\n");
1141+
1142+
if (query_virtqueue(ndev, mvq, &attr)) {
1143+
mlx5_vdpa_warn(&ndev->mvdev, "failed to query virtqueue\n");
1144+
return;
1145+
}
1146+
mvq->avail_idx = attr.available_index;
11451147
}
11461148

11471149
static void suspend_vqs(struct mlx5_vdpa_net *ndev)
@@ -1411,8 +1413,14 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device *vdev, u16 idx, struct vdpa
14111413
struct mlx5_virtq_attr attr;
14121414
int err;
14131415

1414-
if (!mvq->initialized)
1415-
return -EAGAIN;
1416+
/* If the virtq object was destroyed, use the value saved at
1417+
* the last minute of suspend_vq. This caters for userspace
1418+
* that cares about emulating the index after vq is stopped.
1419+
*/
1420+
if (!mvq->initialized) {
1421+
state->avail_index = mvq->avail_idx;
1422+
return 0;
1423+
}
14161424

14171425
err = query_virtqueue(ndev, mvq, &attr);
14181426
if (err) {

0 commit comments

Comments
 (0)