Virtuozzo QEMU development (svt-core@virtuozzo.com)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@virtuozzo.com>
To: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>,
	svt-core@virtuozzo.com
Cc: den@openvz.org
Subject: Re: [PATCH QEMU HCI-8.0 v5 00/13] usb-host: support CPR migration
Date: Mon, 28 Sep 2026 19:06:05 +0200	[thread overview]
Message-ID: <c69482a9-d5bf-4947-8dd4-880b66126fab@virtuozzo.com> (raw)
In-Reply-To: <20260925-usb-host_v3-v5-0-e5b21724db4d@virtuozzo.com>

On 9/25/26 16:11, Andrey Drobyshev wrote:
> v4 -> v5:
>
>   * Patch 5: deliver URBs that already completed in the kernel instead
>     of dropping their data, and error out any a drain can't reap in
>     time;
>
>   * Patch 6 (NEW): drain each usb-host before its host controller is
>     migrated, so a shared-context completion can't advance xHCI after
>     it was saved;
>
>   * Patch 7: remember the packets to replay from the reap callback, so
>     only the genuinely in-flight ones are re-issued.
>
> v4: http://lore.virtuozzo.com/qemu/20260924-usb-host_v3-v4-0-1cc48bf630e7@virtuozzo.com
>
> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
> ---
> Andrey Drobyshev (13):
>       usb-host: don't leak hostdev FD on open failure #VSTOR-137800
>       usb-host: add migration blocker for CPR modes #VSTOR-137800
>       usb-host: preserve hostdev FD during CPR migration #VSTOR-137800
>       usb-host: factor out usb_host_reap_xfers() #VSTOR-137800
>       usb-host: drain in-flight URBs across CPR #VSTOR-137800
>       usb-host: drain before the host controller is migrated #VSTOR-137800
>       usb-host: re-issue drained URBs if CPR is aborted #VSTOR-137800
>       usb-host: skip product-string read on CPR incoming #VSTOR-137800
>       usb-host: hand off the device across cpr-transfer #VSTOR-137800
>       usb: migrate the interface altsetting #VSTOR-137800
>       usb-host: reconfigure endpoints on CPR incoming #VSTOR-137800
>       hcd-xhci: resync isochronous endpoints after CPR #VSTOR-137800
>       usb-host: make CPR migration blocker conditional #VSTOR-137800
>
>  hw/usb/bus.c                |  36 ++++
>  hw/usb/hcd-xhci.c           |  20 ++
>  hw/usb/host-libusb.c        | 512 ++++++++++++++++++++++++++++++++++++++++----
>  include/migration/vmstate.h |   1 +
>  4 files changed, 530 insertions(+), 39 deletions(-)
> ---
> base-commit: f2f4b3de1a1be3360a77ca6ab79762466d238804
> change-id: 20260914-usb-host_v3-bbfea86d1dad
>
> Best regards,
> --  
> Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
  What v5 fixes from v4:
  - Draining now happens before the xHCI controller's state is saved
(new patch 6).
  - Transfers that already finished in the kernel are delivered to the
guest instead of dropped.
  - If migration fails, only the transfers that were really cancelled
are sent again, so none go to the device
    twice.

  Blocking:
  1. The guest can lose an interrupt and USB stops working on the
target. The CPU state, including the KVM
     interrupt controller, is saved (migration/savevm.c:1668) before
usb_host_pre_save() drains. Any transfer
     completed during the drain makes xHCI send an MSI
(message-signalled interrupt) after that snapshot, so the
     new process never sees it. The saved xHCI state still has ERDP_EHB
set, so xhci_intr_raise() sends no more
     interrupts until the guest writes ERDP, which it only does from the
handler that never runs. That kills the
     whole interrupter, not just delays one event. v5 makes this more
likely than v4, because it now delivers
     completed transfers during the drain.
  2. A transfer cancelled halfway is re-run from the start. For a bulk
IN transfer, the bytes already read from
     the device are lost. For bulk OUT, bytes the device already
accepted are sent again. This is the normal case
     whenever the VM stops under I/O. The fix is to deliver a cancelled
transfer that has actual_length != 0 as a
     short transfer, and replay only the ones that moved no data.

  Proposed direction: drain from a VM state change handler when the VM
enters FINISH_MIGRATE in a CPR mode, and
  re-issue from the handler that runs when the VM starts again. That
runs before the CPU state is saved, which
  fixes item 1 and makes patch 6 unnecessary. It also closes the window
from the v2 review where vm_start() runs
  before the failure notifier. That window now has a second problem:
with pipelined bulk endpoints, newer OUT data
  can reach the device before the re-issued older data. I left one
question open for Andrey: a VM already paused
  before migration starts never gets that handler call, so it still
needs some fallback.


      parent reply	other threads:[~2026-09-28 17:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 14:11 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 01/13] usb-host: don't leak hostdev FD on open failure #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 02/13] usb-host: add migration blocker for CPR modes #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 03/13] usb-host: preserve hostdev FD during CPR migration #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 04/13] usb-host: factor out usb_host_reap_xfers() #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 05/13] usb-host: drain in-flight URBs across CPR #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 06/13] usb-host: drain before the host controller is migrated #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 07/13] usb-host: re-issue drained URBs if CPR is aborted #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 08/13] usb-host: skip product-string read on CPR incoming #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 09/13] usb-host: hand off the device across cpr-transfer #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 10/13] usb: migrate the interface altsetting #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 11/13] usb-host: reconfigure endpoints on CPR incoming #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 12/13] hcd-xhci: resync isochronous endpoints after CPR #VSTOR-137800 Andrey Drobyshev
2026-09-25 14:11 ` [PATCH QEMU HCI-8.0 v5 13/13] usb-host: make CPR migration blocker conditional #VSTOR-137800 Andrey Drobyshev
2026-09-28 17:06 ` Denis V. Lunev [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c69482a9-d5bf-4947-8dd4-880b66126fab@virtuozzo.com \
    --to=den@virtuozzo.com \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=svt-core@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox