[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH v8 13/18] hw/usb/redirect-server: Announce the exported device


  • To: "marcandre.lureau@xxxxxxxxxx" <marcandre.lureau@xxxxxxxxxx>
  • From: Jamin Lin <jamin_lin@xxxxxxxxxxxxxx>
  • Date: Tue, 3 Nov 2026 07:14:13 +0000
  • Accept-language: zh-TW, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=aspeedtech.com; dmarc=pass action=none header.from=aspeedtech.com; dkim=pass header.d=aspeedtech.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ITg0zpWtqw67dO/HL30blrN/GXLvdv9ic/n/2a8we2M=; b=ewHObis4WlPNhOPRxHG0bWwwHW9lyDWtgrQcBnRWI04h6jOMQAAhA7nNRudoyscjBnw7+Bzv/2N+cpZJ5nmrGJNAWhRU9UnSj7TBwzUV991waDBcEsiEeT4a4d90dCNMIRctWSYKHmpbCNHGO5t7A4k8U6hwA/ecqVeJhD6cEIRgdT0QAsoFXav2RcXPHp90YUlse10nroTi3YEYDIrCqe5WEgwck02D7HILKF2gJML9dExt5m9ZMig5hpXNWOlHVkBBdpd3az3jcYFXtnQh2uf9IOydZOU4gFrGU1jLrKpwSO+mPT0ki+zUQAIZ+HvulHPb4yorgTvs8S1O12xRpQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xtALvLMYw8/9yvbzCPp6jgyGFvvDfma2govi/kc8Tcpp7+hTxWXZHZR7NqwAWnNZKAHzrr72e/WEJ2oKr2DGXk31x707tGL6s+z9X4uCYlAY7Sw9XFs+pHXHJTN3V+u/vozsU8mLCm7BX0LMp3bcCgcBO2g++IkIbp2e5MSQBsxlJ/DGAlCTB+lj8jaCLsS6wL7vxFb4LRVPXTw6rBYoKkYO1zMPNHZ6BapTEsCILSxkHCESOJGMsP7AaWTVT3f4t6GkCdu+E73hG1AZJKsUGdp23bRl3srQzstcb6UG+hTYdmD/qNrE9yKtJNnqYo0TXpRTvZDHI630QWfzyXaWew==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=aspeedtech.com header.i="@aspeedtech.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=aspeedtech.com;
  • Cc: "kraxel@xxxxxxxxxx" <kraxel@xxxxxxxxxx>, "junjie.cao@xxxxxxxxx" <junjie.cao@xxxxxxxxx>, "junjie.cao@xxxxxxxxx" <junjie.cao@xxxxxxxxx>, "clg@xxxxxxxx" <clg@xxxxxxxx>, Pierrick Bouvier <pierrick.bouvier@xxxxxxxxxxxxxxxx>, Peter Maydell <peter.maydell@xxxxxxxxxx>, Kane Chen <kane_chen@xxxxxxxxxxxxxx>, Philippe Mathieu-Daudé <philmd@xxxxxxxxxxxxxxxx>, Tyrone Ting <kfting@xxxxxxxxxxx>, Hao Wu <wuhaotsh@xxxxxxxxxx>, Zhao Liu <zhao1.liu@xxxxxxxxx>, Richard Henderson <richard.henderson@xxxxxxxxxx>, Helge Deller <deller@xxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony@xxxxxxxxxxxxxx>, "Edgar E. Iglesias" <edgar.iglesias@xxxxxxxxx>, "open list:All patches CC here" <qemu-devel@xxxxxxxxxx>, "open list:ASPEED BMCs" <qemu-arm@xxxxxxxxxx>, "open list:X86 Xen CPUs" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Troy Lee <troy_lee@xxxxxxxxxxxxxx>
  • Delivery-date: Tue, 03 Nov 2026 07:14:43 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdaqupvmzo6sFN+0K1iqt887RtJLca0acAgAEdGdA=
  • Thread-topic: [PATCH v8 13/18] hw/usb/redirect-server: Announce the exported device

Hi Marc-André Lureau

> Subject: Re: [PATCH v8 13/18] hw/usb/redirect-server: Announce the exported
> device
> 
> > Send device_connect when a device is attached and the host has greeted
> > us, device_disconnect when it goes away, and handle the bus reset the
> > host sends before enumerating.
> >
> > device_connect carries no identity. The peer asks the device itself
> > with GET_DESCRIPTOR as soon as it enumerates, so anything we put there
> > would be made up. The speed is real: it comes from the device on our port.
> >
> > Signed-off-by: Jamin Lin <jamin_lin@xxxxxxxxxxxxxx>
> > Message-ID: <20261102092201.1729245-14-jamin_lin@xxxxxxxxxxxxxx>
> > ---
> >  hw/usb/redirect-server.c | 150
> ++++++++++++++++++++++++++++++++++++++-
> >  hw/usb/trace-events      |   7 ++
> >  2 files changed, 156 insertions(+), 1 deletion(-)
> >
> > diff --git a/hw/usb/redirect-server.c b/hw/usb/redirect-server.c index
> > f78351bde919..e207f5a7eb56 100644
> > --- a/hw/usb/redirect-server.c
> > +++ b/hw/usb/redirect-server.c
> > @@ -56,6 +56,7 @@
> >  #include "qemu/main-loop.h"
> >  #include "qemu/module.h"
> >  #include "migration/vmstate.h"
> > +#include "qemu/cutils.h"
> >  #include "hw/core/sysbus.h"
> >  #include "hw/usb/usb.h"
> >  #include "chardev/char-fe.h"
> > @@ -85,17 +86,105 @@ struct USBRedirServer {
> >      /* usbredir over the chardev */
> >      struct usbredirparser *parser;
> >      QEMUBH *chardev_close_bh;
> > +    QEMUBH *announce_bh;
> >      const uint8_t *read_buf;
> >      int read_buf_size;
> >      bool in_write;
> >      guint watch;
> >      bool host_connected;
> > +    bool device_announced;
> >  };
> >
> > +/*
> > + * The device is whatever USBDevice the user plugged into our port
> > +with
> > + * "-device <device>,bus=<id>.0". NULL until then.
> > + */
> > +static USBDevice *usbredir_server_device(USBRedirServer *s) {
> > +    return s->port.dev;
> > +}
> > +
> > +/*
> > + * Device announcement
> > + */
> > +
> > +static uint8_t usbredir_server_speed(USBDevice *device) {
> > +    switch (device->speed) {
> > +    case USB_SPEED_LOW:
> > +        return usb_redir_speed_low;
> > +    case USB_SPEED_FULL:
> > +        return usb_redir_speed_full;
> > +    default:
> > +        return usb_redir_speed_high;
> > +    }
> > +}
> > +
> > +static void usbredir_server_announce_device(void *opaque) {
> > +    USBRedirServer *s = opaque;
> > +    USBDevice *device = usbredir_server_device(s);
> > +    struct usb_redir_interface_info_header iface_info = {
> > +        .interface_count = 0,
> > +    };
> > +    struct usb_redir_device_connect_header conn = {};
> > +
> > +    if (!s->host_connected || s->device_announced ||
> > +        !device || !device->attached) {
> > +        return;
> > +    }
> > +    s->device_announced = true;
> > +    conn.speed = usbredir_server_speed(device);
> > +
> > +    /*
> > +     * The device has to be in DEFAULT state before it can answer
> > +     * anything, so reset it here.
> > +     */
> > +    usb_device_reset(device);
> > +
> > +    /* Send this before device_connect. The peer needs it to accept us. */
> > +    usbredirparser_send_interface_info(s->parser, &iface_info);
> 
> The peer's usb-redir client evaluates its "filter" property against
> device_connect and this interface_info. With interface_count == 0 and the
> all-zero connect header above, any non-empty filter (vendor/product, class or
> interface rule) rejects the exported device. Fill interface_info from the 
> saved
> configuration descriptor (interface number, class/subclass/ protocol) and
> device_connect from the local USBDevice?
> 

Thanks for the review and suggestion.

I will rework the series to read the descriptors from the device instead of 
hard code 0. The host has no device
until device_connect arrives, so it cannot ask for anything itself. The server 
read the descriptors in the 
announce path before it sends device_connect.

I will add a patch for this and the patch order will be changed.

Thanks,
Jamin
> --
> Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.