Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vhost-user-backend: fetch 'used' index from guest #180

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

germag
Copy link
Collaborator

@germag germag commented Aug 8, 2023

Summary of the PR

commit 958cdec stopped GET_VRING_BASE from resetting the vring. This was required because when the VM is stopped/resumed the index will be 0 instead of the correct value.

However, after the guest driver changes, for instance, after reboot, the 'used' index should be 0. The bug fixed in that commit had the unintended side effect of setting the 'used' index to 0 after a driver change.

QEMU sets the 'used' index when receiving SET_VRING_ADDR, probably to make sure that the VQ is configured. Perhaps the appropriate place is when receiving the first kick. A better solution would be to send the used index in SET_VRING_BASE, as is done when using packed VQs.

To keep compatibility with QEMU and just in case, any implementation expects the 'used' index to be set when receiving SET_VRING_ADDR let's fetch the 'used' index from the guest when receiving that message.

@germag
Copy link
Collaborator Author

germag commented Aug 9, 2023

v2:

  • Replace fetch_queue_next_used_from_guest() by set_queue_next_used() and queue_used_idx()

commit 958cdec stopped GET_VRING_BASE
from resetting the vring. This was required because when the VM is
stopped/resumed the index will be 0 instead of the correct value.

However, after the guest driver changes, for instance, after reboot,
the 'used' index should be reset to 0. The bug fixed in that commit had
the unintended side effect of setting the 'used' index to 0 after a
driver change.

QEMU's vhost-user library sets the 'used' index when receiving
SET_VRING_ADDR, _probably_ to make sure that the VQ is configured.
Perhaps the appropriate place is when receiving the first kick.
A better solution would be to send the 'used' index in SET_VRING_BASE,
as is done when using packed VQs.

To keep compatibility with QEMU and just in case, any implementation
expects the 'used' index to be set when receiving SET_VRING_ADDR let's
fetch the 'used' index from the guest when receiving that message.

Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: German Maglione <gmaglione@redhat.com>
@germag
Copy link
Collaborator Author

germag commented Aug 9, 2023

v3:

  • remove .write_lock()
  • improve code comment

@stefano-garzarella stefano-garzarella merged commit 8a4ba9d into rust-vmm:main Aug 9, 2023
1 check passed
@stefano-garzarella
Copy link
Member

I think we need to release this fix ASAP with v0.10.1 since I had the same issue also with vhost-device-vsock.

I'm going to prepare the release.

@sboeuf @jiangliu @slp @eryugey WDYT?

@stefano-garzarella
Copy link
Member

FYI PR opened here with the release: #183

We can discuss there.

stefano-garzarella added a commit to stefano-garzarella/vhost-device that referenced this pull request Aug 22, 2023
vhost-user-backend v0.10.0 introduced an issue that affects
all vhost-user backends. I easily reproduced the problem with
vhost-device-vsock: just restart the guest kernel and the
device no longer works.

vhost-user-backend v0.10.1 includes the fix [1] for that issue.

[1] rust-vmm/vhost#180

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
vireshk pushed a commit to rust-vmm/vhost-device that referenced this pull request Aug 22, 2023
vhost-user-backend v0.10.0 introduced an issue that affects
all vhost-user backends. I easily reproduced the problem with
vhost-device-vsock: just restart the guest kernel and the
device no longer works.

vhost-user-backend v0.10.1 includes the fix [1] for that issue.

[1] rust-vmm/vhost#180

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
birktj pushed a commit to birktj/virtiofsd that referenced this pull request Jan 5, 2024
The new version of vhost-user-backend fetches the used idx from the
guest[0], without this fix the guest hangs after a reboot, because
the used idx is not reset.

This error was introduced when we fixed GET_VRING_BASE to incorrectly
reset the vring[1], which left the vring in an inconsistent state after
a stop/cont cycle. Resetting the VQ when receiving GET_VRING_BASE had
the unintended side effect of setting the 'used' index to 0 after a
driver change (e.g., after a reboot).

[0] rust-vmm/vhost#180
(commit: 8a4ba9d0c5666075aa7f7e2e32ceeaf8d827f9da)

[1] rust-vmm/vhost#161
(commit: 958cdec2b8741af77b7f90214ec9c97040bf5a8a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants