On 2/17/2021 8:44 PM, Jason Wang wrote:
On 2021/2/10 下午4:59, Si-Wei Liu wrote:
quoted
On 2/9/2021 7:53 PM, Jason Wang wrote:
quoted
On 2021/2/10 上午10:30, Si-Wei Liu wrote:
quoted
On 2/8/2021 10:37 PM, Jason Wang wrote:
quoted
On 2021/2/9 下午2:12, Eli Cohen wrote:
quoted
On Tue, Feb 09, 2021 at 11:20:14AM +0800, Jason Wang wrote:
quoted
On 2021/2/8 下午6:04, Eli Cohen wrote:
quoted
On Mon, Feb 08, 2021 at 05:04:27PM +0800, Jason Wang wrote:
quoted
On 2021/2/8 下午2:37, Eli Cohen wrote:
quoted
On Mon, Feb 08, 2021 at 12:27:18PM +0800, Jason Wang wrote:
quoted
On 2021/2/6 上午7:07, Si-Wei Liu wrote:
quoted
On 2/3/2021 11:36 PM, Eli Cohen wrote:
quoted
When a change of memory map occurs, the hardware resources are destroyed
and then re-created again with the new memory map. In such case, we need
to restore the hardware available and used indices. The driver failed to
restore the used index which is added here.
Also, since the driver also fails to reset the available and used
indices upon device reset, fix this here to avoid regression caused by
the fact that used index may not be zero upon device reset.
Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5
devices")
Signed-off-by: Eli Cohen<redacted>
---
v0 -> v1:
Clear indices upon device reset
drivers/vdpa/mlx5/net/mlx5_vnet.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c
b/drivers/vdpa/mlx5/net/mlx5_vnet.c
156 more quoted lines
The hw_available_index not showing the correct last_avail_index value is technically a firmware bug, as Eli alluded to. That's why I had the original question for how this entire synchronization scheme could work if just saving and restoring this cached value. In my observation, the hw_available_index was seen far off from the hw_used_index post vq suspension, I just pointed out the fact that this hardware value is neither last_avail_idx nor last_used_idx that is useful to represent vq state.
However, the core question I'm having is should we care about fixing this in the firmware interface level (actually, the hardware implementation), or rather, just as said, some devices e.g. network device could live with the simplified form of assumption (used_idx == last_used_idx == last_avail_idx) where pending requests can be drained and completed before device is stopped or suspended. Despite of what device behavior would be expected or defined in the virtio spec, the get/set_vq_state() API should have very clear semantics: whether both forms (i.e. restore either one of used_idx or last_avail_idx is fine) are acceptable, or it needs to be religious to restore vq state via last_avail_idx only. In the latter case, both the mlx5 vdpa net driver and the firmware interface needs to be fixed to accommodate the stricter API requirement.
FWIW I don't think network (Ethernet) device should always assume (used_idx == last_used_idx == last_avail_idx) while being stopped (were there virtio RDMA device in reality this assumption would break): it could well follow the golden rules in virtio S/W implementation to have separate last_used_idx and last_avail_idx in the hardware, then it'll be 100% API compliant.. But we know that such implementation is unnecessarily complicated for Ethernet device. Hence I thought there could be sort of reliefs for some driver/device and it's totally up to the device/driver to choose the implementation.
quoted
I doubt it's the one you talked about in software implementation.
Actually not, it's a virtio general issue:
Consider there's not indices wrap. And:
- used_idx is the used index in the virtqueue
- last_used_idx is the used index maintained by the device, it points to the location where to put the next done requests to the used_ring
- avail_idx is the available index in the virtqueue
- last_avail_idx is the index maintained by the device, it points to the location where device need to read from the available.
So bascially, from device POV, it only cares the buffer that belong to itself which are [used_idx, avail_idx). So we have:
[used_idx, last_used_idx) The requests that have been completed by the device but not completed to the used ring (or at least used_idx is not updated).
[last_used_idx, last_avail_idx) The requests that are being processed by the device.
[last_avail_idx, avail_idx) The requests that are made available by the driver but not processed by the device.
During device stop/suspend, the device should:
- stop reading new request from available ring (or read until the end of descriptor chain)
- sync used_idx with last_used_idx. Otherwise we need a complicated but not necessary API to sync last_used_idx and the indices that are not committed to used ring (since device may complete the request out of order)
So we know used_idx == last_used_idx in this case, so we have:
[used_idx/last_used_idx, last_avail_idx) The requests that are being processed.
[last_avail_idx, avail_idx) The requests that are available for the driver but not yet processed.
For networking device, it's sufficient to think the requests are completed when TX/RX DMA are finished. So there's no requests that are being processed after the stop. In this case we had: used_idx == last_used_idx == last_avail_idx. Then we only had:
[used_idx/last_used_idx/last_avail_idx, avail_idx] The requests that are made available by the driver but not processed by the device. That's why you may think only used_idx matters here.
For block device, the completion of the request might require the communication with the remote backend, so we can't assume last_used_idx is equal to the last_avail_idx. Whether or not to wait for the drain the request is still being discussed[1].
I guess this requirement is very subject to the specific storage setup (networked v.s. local) including the guest app/configuration (retry v.s. time out). IMHO there shouldn't be a definite yes-or-no answer here. But in general, for req-ack type of request if the completion (ack) cannot simply replicate across live migration, it should wait until the pending requests are completely drained.
So you can see, for all the cases, what really matters is the last_avail_idx. The device should know where it need to start reading for the next request, and it is not necessarily equal to last_used_idx or used_idx. What makes things a little bit easier is the networking device whose last_used_idx is equal to last_avail_idx.
quoted
If I understand Eli correctly, hardware will always reload the latest avail_index from memory whenever it's being sync'ed again.
<quote>
The hardware always goes to read the available index from memory. The requirement to configure it when creating a new object is still a requirement defined by the interface so I must not violate interface requirments.
</quote>
If the hardware does everything perfectly that is able to flush pending requests, update descriptors, rings plus used indices all at once before the suspension, there's no need for hardware to maintain a separate internal index than the h/w used_index. The hardware can get started from the saved used_index upon resuming. I view this is of (hardware) implementation choices and thought it does not violate the virtio spec?
Yes, but as you said, it has a lot of assumptions which may not work for other type of devices. So what I refer "last_avail_idx" is probably the "used_idx" in your description here. It might be the same in this case for networking device.
quoted
quoted
quoted
And the used_idx in the virtqueue is always in sync with the hardware used_index, and hardware is supposed to commit pending used buffers to the ring while bumping up the hardware used_index (and also committed to memory) altogether prior to suspension, is my understanding correct here? Double checking if this is the expected semantics of what modify_virtqueue(MLX5_VIRTIO_NET_Q_OBJECT_STATE_SUSPEND) should achieve.
If the above is true, then it looks to me for mlx5 vdpa we should really return h/w used_idx rather than the last_avail_idx through get_vq_state(), in order to reconstruct the virt queue state post live migration. For the set_map case, the internal last_avail_idx really doesn't matter, although both indices are saved and restored transparently as-is.
Right, a subtle thing here is that: for the device that might have can't not complete all virtqueue requests during vq suspending, the "last_avail_idx" might not be equal to the hardware used_idx. Thing might be true for the storage devices that needs to connect to a remote backend. But this is not the case of networking device, so last_avail_idx should be equal to hardware used_idx here. Eli, since it's your hardware, does it work this way? i.e. does the firmware interface see a case where virtqueue requests can't be completed before suspending vq?
For storage device, I think it can happen.
quoted
quoted
But using the "last_avail_idx" or hardware avail_idx should always be better in this case since it's guaranteed to correct and will have less confusion. We use this convention in other types of vhost backends (vhost-kernel, vhost-user).
So looking at mlx5_set_vq_state(), it probably won't work since it doesn't not set either hardware avail_idx or hardware used_idx:
The saved mvq->avail_idx will be used to recreate hardware virtq object and the used index in create_virtqueue(), once status DRIVER_OK is set. I suspect we should pass the index to mvq->used_idx in mlx5_vdpa_set_vq_state() below instead.
It depends on what did mvq->used_idx meant? If it's last_used_idx, it should be the same with mvq->avail_idx for networking device.
It's the last_used_idx. Note, Eli already posted a patch ("vdpa/mlx5: Fix suspend/resume index restoration") to repurpose set_vq_state() to restore both used_idx and avail_idx (both indices should be conceptually equal in that device model) across reset. Which implies the simplified assumption I mentioned earlier. The requirement of set_vq_state() API should make it clear if this kind of assumption is acceptable.
Thanks,
-Siwei
Thanks
quoted
Thanks,
-Siwei
quoted
static int mlx5_vdpa_set_vq_state(struct vdpa_device *vdev, u16 idx,
const struct vdpa_vq_state *state)
{
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[idx];
if (mvq->fw_state == MLX5_VIRTIO_NET_Q_OBJECT_STATE_RDY) {
mlx5_vdpa_warn(mvdev, "can't modify available index\n");
return -EINVAL;
}
mvq->avail_idx = state->avail_index;
return 0;
}
Depends on the hardware, we should either set hardware used_idx or hardware avail_idx here.
I think we need to clarify how device is supposed to work in the virtio spec.
Thanks
quoted
-Siwei
quoted
quoted
Now the vritqueue is copied to the new VM and the
hardware now has to continue execution from index 20. We need to tell
the hardware via configuring the last used_index.
30 more quoted lines