From nobody Tue May 21 02:02:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1578474744; cv=none; d=zohomail.com; s=zohoarc; b=G7nR2iWMIVrWZNpakdH6GjnhQaKsO3E1G9nMfXuiNmJfETLmB0j5rxMNlrAu+Is5nDuwfaX9g6J+wSW4NM4UxT4xR667Aor0EOvtX7eXBk+pXuv+JNHpXgGmntXchUhXqNhFwLwXLNSh1z2aQHYWOYPEOhbwVOFx37mV9kyzb5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578474744; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=FfQ6ZU1kHSKwI7VaafvEzLdyLb8c87IhxHy4wK5k72w=; b=Y+vZjItMda/OUaUE8zbjNtfgosSNFcJTXj+4eImuJf+H+WGV+/Mw02XRRg2O4trhzQpguATe4JMj46BKj2ieJ9RTdYiE5z0FZrhSwVg6LI9dQfJ0VKO8aL9JgsxVZiB0vmQXVmsKMz3ZaQqGLGxDUKDxrYfdaj3diWLSLh91iVU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578474744329553.2123050850312; Wed, 8 Jan 2020 01:12:24 -0800 (PST) Received: from localhost ([::1]:40844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip7O2-0003r0-PV for importer@patchew.org; Wed, 08 Jan 2020 04:12:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55446) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip7Me-0002aT-5C for qemu-devel@nongnu.org; Wed, 08 Jan 2020 04:10:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ip7Mc-0004PG-QY for qemu-devel@nongnu.org; Wed, 08 Jan 2020 04:10:56 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:54158) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ip7Mc-0004O8-K4 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 04:10:54 -0500 Received: by mail-wm1-x342.google.com with SMTP id m24so1617882wmc.3 for ; Wed, 08 Jan 2020 01:10:54 -0800 (PST) Received: from f2.redhat.com (bzq-79-177-42-131.red.bezeqint.net. [79.177.42.131]) by smtp.gmail.com with ESMTPSA id q3sm2892676wmc.47.2020.01.08.01.10.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Jan 2020 01:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FfQ6ZU1kHSKwI7VaafvEzLdyLb8c87IhxHy4wK5k72w=; b=wt6nzUBrBTYyYtFArc5RVuE0WBeuu4ExOp42eXZSR0/r89An7y075bjsLfczTNLwQo Bmd9PK+PX9DNJqLsnpF/TdQoMnN8nFTltWcJ7rGdXqzbY/t8ThfL5TYWNrhM5mtovEGu F53DrutXXTPirwzQVf0HzY6Ep/2ywTGY/T2q8JH0TNduV9nw1c/tBHqL5e9bvBeoRPxH 46m0rvE8OFbzeFAlciFKDxz5mmnoRQz/dxhG5LrJx2NJx80BdV05sQu+25Z51cOruVrK NiB/4tM6it3uo9kELh2TwskHYnjkeTbCvDfNbY3mcemMEwU/jQ5gLn/MR8Jz+DaqyQQB rVpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FfQ6ZU1kHSKwI7VaafvEzLdyLb8c87IhxHy4wK5k72w=; b=a9so5sAhk7uphRUbY5BKPCYJQx+DZvja3tJDtEVC78s+wOzsDrJSuCPTQgDa8K5GL1 SDH47E4SI34T0JC+3MeNC1atP176XHdtqrou9VgMT1Osem3vxXQ5AjwmR3ZYIfru6Gu2 p8T1Hr9MCYjWiEsaIdPwf9L1WafL9sIAj9LQ8gtfdhutLy20xuIPAnzgg13Lh38E2OIS zOQgKGLSfUsWEOPK1qiCjJQ2uq0zXnCPJ5WXYs/XUYuo5YdWE2cIGu3/p9xkjlbgaTnJ tp9vWrQ2diEJMY6meJWav6bMonNUgSYYRvMEpTl0y6hq8d80dVG2STH7uYbRVX9JjaUA L3lQ== X-Gm-Message-State: APjAAAXHf8vk0a0soewIyun2g8aMkZuZLYfShI5SOLJ9YAAoudE016jl 9NtZzAYlB43r+IJGv5e/m7luNSerRUQ= X-Google-Smtp-Source: APXvYqxFdf+QYjIDJ0a5eteifRwgm/DUBDvEq4voVkrdxLyukPmuC1k5wnGcn4rUT1+/Tpx5Boe1Mg== X-Received: by 2002:a7b:ce98:: with SMTP id q24mr2386722wmj.41.1578474653640; Wed, 08 Jan 2020 01:10:53 -0800 (PST) From: Yuri Benditovich To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, kraxel@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v3 1/2] usb-host: remove 'remote wakeup' flag from configuration descriptor Date: Wed, 8 Jan 2020 11:10:43 +0200 Message-Id: <20200108091044.18055-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200108091044.18055-1-yuri.benditovich@daynix.com> References: <20200108091044.18055-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If the redirected device has this capability, Windows guest may place the device into D2 and expect it to wake when the device becomes active, but this will never happen. For example, when internal Bluetooth adapter is redirected, keyboards and mice connected to it do not work. Current commit removes this capability (starting from machine 5.0) Set 'usb-host.suppress-remote-wake' property to 'off' to keep 'remote wake' as is or to 'on' to remove 'remote wake' on 4.2 or earlier. Signed-off-by: Yuri Benditovich --- hw/core/machine.c | 1 + hw/usb/host-libusb.c | 20 ++++++++++++++++++++ hw/usb/trace-events | 1 + 3 files changed, 22 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 4f30fb5646..c5d32f56db 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -32,6 +32,7 @@ GlobalProperty hw_compat_4_2[] =3D { { "virtio-blk-device", "seg-max-adjust", "off"}, { "virtio-scsi-device", "seg_max_adjust", "off"}, { "vhost-blk-device", "seg_max_adjust", "off"}, + { "usb-host", "suppress-remote-wake", "off" }, }; const size_t hw_compat_4_2_len =3D G_N_ELEMENTS(hw_compat_4_2); =20 diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index fcf48c0193..00e0e36369 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -88,6 +88,7 @@ struct USBHostDevice { bool needs_autoscan; bool allow_one_guest_reset; bool allow_all_guest_resets; + bool suppress_remote_wake; =20 /* state */ QTAILQ_ENTRY(USBHostDevice) next; @@ -386,6 +387,8 @@ static void LIBUSB_CALL usb_host_req_complete_ctrl(stru= ct libusb_transfer *xfer) r->p->status =3D status_map[xfer->status]; r->p->actual_length =3D xfer->actual_length; if (r->in && xfer->actual_length) { + USBDevice *udev =3D USB_DEVICE(s); + struct libusb_config_descriptor *conf =3D (void *)r->cbuf; memcpy(r->cbuf, r->buffer + 8, xfer->actual_length); =20 /* Fix up USB-3 ep0 maxpacket size to allow superspeed connected d= evices @@ -394,6 +397,21 @@ static void LIBUSB_CALL usb_host_req_complete_ctrl(str= uct libusb_transfer *xfer) r->cbuf[7] =3D=3D 9) { r->cbuf[7] =3D 64; } + /* + *If this is GET_DESCRIPTOR request for configuration descriptor, + * remove 'remote wakeup' flag from it to prevent idle power down + * in Windows guest + */ + if (s->suppress_remote_wake && + udev->setup_buf[0] =3D=3D USB_DIR_IN && + udev->setup_buf[1] =3D=3D USB_REQ_GET_DESCRIPTOR && + udev->setup_buf[3] =3D=3D USB_DT_CONFIG && udev->setup_buf[2] = =3D=3D 0 && + xfer->actual_length > + offsetof(struct libusb_config_descriptor, bmAttributes) && + (conf->bmAttributes & USB_CFG_ATT_WAKEUP)) { + trace_usb_host_remote_wakeup_removed(s->bus_num, s->addr); + conf->bmAttributes &=3D ~USB_CFG_ATT_WAKEUP; + } } trace_usb_host_req_complete(s->bus_num, s->addr, r->p, r->p->status, r->p->actual_length); @@ -1596,6 +1614,8 @@ static Property usb_host_dev_properties[] =3D { LIBUSB_LOG_LEVEL_WARNING), DEFINE_PROP_BIT("pipeline", USBHostDevice, options, USB_HOST_OPT_PIPELINE, true), + DEFINE_PROP_BOOL("suppress-remote-wake", USBHostDevice, + suppress_remote_wake, true), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/usb/trace-events b/hw/usb/trace-events index 2d3713351c..1c24d82c09 100644 --- a/hw/usb/trace-events +++ b/hw/usb/trace-events @@ -266,3 +266,4 @@ usb_host_parse_config(int bus, int addr, int value, int= active) "dev %d:%d, valu usb_host_parse_interface(int bus, int addr, int num, int alt, int active) = "dev %d:%d, num %d, alt %d, active %d" usb_host_parse_endpoint(int bus, int addr, int ep, const char *dir, const = char *type, int active) "dev %d:%d, ep %d, %s, %s, active %d" usb_host_parse_error(int bus, int addr, const char *errmsg) "dev %d:%d, ms= g %s" +usb_host_remote_wakeup_removed(int bus, int addr) "dev %d:%d" --=20 2.17.1 From nobody Tue May 21 02:02:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1578474744; cv=none; d=zohomail.com; s=zohoarc; b=YEHWFeOP1nxpaJ2l12dnTBicWk018nvOoWptMLXvN26JfB8MhSebbkm9bMYwxSTtxvL6Da6/ZG8Wn06vo93iBYhIquoc9wLkfCJV5/RZFr42qj4vdrYcQm2dpFRsVBAVuF/sgNbepLvl9Xxu0mYk/VZ6zNr7sigQPvbqIiwG++w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578474744; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=oleLHXvsiH5kmJRmH4yj69sUgKLCLz1ATCZG6rLhml8=; b=nE7ygxCPEIyQJNmprv9nMRtIe8+T7MiBP1KIrfRjvpJoyDEXUUoMYM0hMblrtAod0zP4WPVBfz+mGVdy5t4iTmd/tfrUiZ5soOdbvQ7DfKhTDG5cN4hhnsq2QqhZ+ehK5NSgkcALiD+hCV6wp6m2AuFtPMRY9AlSec3ejHPMVIQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578474744567127.59977685453293; Wed, 8 Jan 2020 01:12:24 -0800 (PST) Received: from localhost ([::1]:40846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip7O3-0003uH-82 for importer@patchew.org; Wed, 08 Jan 2020 04:12:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55487) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ip7Mg-0002bv-8v for qemu-devel@nongnu.org; Wed, 08 Jan 2020 04:11:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ip7Md-0004QP-Ty for qemu-devel@nongnu.org; Wed, 08 Jan 2020 04:10:57 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:40500) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ip7Md-0004Ph-O6 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 04:10:55 -0500 Received: by mail-wm1-x344.google.com with SMTP id t14so1620838wmi.5 for ; Wed, 08 Jan 2020 01:10:55 -0800 (PST) Received: from f2.redhat.com (bzq-79-177-42-131.red.bezeqint.net. [79.177.42.131]) by smtp.gmail.com with ESMTPSA id q3sm2892676wmc.47.2020.01.08.01.10.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Jan 2020 01:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oleLHXvsiH5kmJRmH4yj69sUgKLCLz1ATCZG6rLhml8=; b=uPvEhTNVhjiWZZo9jyzEevVEDzgTrr7TFaD3a5bQ3ql/sTjrPmqE/OoAfwjZCwzxL3 EypB6cu8s/4R8Siot7du+u3J3DvsSk7fKDid6YIagrG5LVQsBPhF9nGnKgO9UbbAyovc tmHo58ecp/W9gJ1SIGGCl4YflsebLIPoqCDtuflz+ffGbXnfuLHkByrQHQQr/ZjPblR6 LhpFT2T5/zzuMkhRYKYk0083yQdJpBTZBdlPT35ssxFWg7yZp6Yv1li3W18G0Jhs4rtR PjZIQrZLB9oXY9cjc5AqOsZRln5HeMyHBX6uGeulET3gDyCNVVITg9mBq5t4FvrhlN1A Rfjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oleLHXvsiH5kmJRmH4yj69sUgKLCLz1ATCZG6rLhml8=; b=FHo+WWKMKL7mxm+Dj5xwdCuZ3J769Omw//JClhbPoZfswPWHMpQnkln/C6t2B1uuf9 oKwu+9ieelh7hnz39wLzP2tSkxL3q3t3ymLrFMpmor9s5+APtost1MyG7dDM9k1thtRm TtvWBWxNK2MdNOWuKnW10795qMcoJZ69aDx6nagZ/CVyfEkhi8MUFlWhlpNnMJno24BA UtFon0trKaXFex16Xr9NA4pI3oMSyX/dTceLJOfpeJMTL4+vo0bLioXN8Rg2kRT6AnBi 8vnz+A67zXTohweIVRghqRFpD6jAtzHd/z+ISqRwxZsleyHKNLBZPXbfvgZwWb2c4FMI /vAw== X-Gm-Message-State: APjAAAVq+KapDRhlAmAhSqGXSnoHTkCJNZIrkWpzaHHdzdvPZSUSO8cy HwauxnWdsLEFpEominmsoG0qOg== X-Google-Smtp-Source: APXvYqxxyPWZesJhQ/bLsYNtXblEAU2yspabipZx/hKEEAA6xkDy9k/xmkNFnJ325lB6Xw170lFajw== X-Received: by 2002:a1c:7c11:: with SMTP id x17mr2480758wmc.168.1578474654781; Wed, 08 Jan 2020 01:10:54 -0800 (PST) From: Yuri Benditovich To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, kraxel@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v3 2/2] usb-redir: remove 'remote wakeup' flag from configuration descriptor Date: Wed, 8 Jan 2020 11:10:44 +0200 Message-Id: <20200108091044.18055-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200108091044.18055-1-yuri.benditovich@daynix.com> References: <20200108091044.18055-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If the redirected device has this capability, Windows guest may place the device into D2 and expect it to wake when the device becomes active, but this will never happen. For example, when internal Bluetooth adapter is redirected, keyboards and mice connected to it do not work. Current commit removes this capability (starting from machine 5.0) Set 'usb-redir.suppress-remote-wake' property to 'off' to keep 'remote wake' as is or to 'on' to remove 'remote wake' on 4.2 or earlier. Signed-off-by: Yuri Benditovich --- hw/core/machine.c | 1 + hw/usb/redirect.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index c5d32f56db..3e288bfceb 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -33,6 +33,7 @@ GlobalProperty hw_compat_4_2[] =3D { { "virtio-scsi-device", "seg_max_adjust", "off"}, { "vhost-blk-device", "seg_max_adjust", "off"}, { "usb-host", "suppress-remote-wake", "off" }, + { "usb-redir", "suppress-remote-wake", "off" }, }; const size_t hw_compat_4_2_len =3D G_N_ELEMENTS(hw_compat_4_2); =20 diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index e0f5ca6f81..b5c1558687 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -113,6 +113,7 @@ struct USBRedirDevice { /* Properties */ CharBackend cs; bool enable_streams; + bool suppress_remote_wake; uint8_t debug; int32_t bootindex; char *filter_str; @@ -1989,6 +1990,23 @@ static void usbredir_control_packet(void *priv, uint= 64_t id, memcpy(dev->dev.data_buf, data, data_len); } p->actual_length =3D len; + /* + * If this is GET_DESCRIPTOR request for configuration descriptor, + * remove 'remote wakeup' flag from it to prevent idle power down + * in Windows guest + */ + if (dev->suppress_remote_wake && + control_packet->requesttype =3D=3D USB_DIR_IN && + control_packet->request =3D=3D USB_REQ_GET_DESCRIPTOR && + control_packet->value =3D=3D (USB_DT_CONFIG << 8) && + control_packet->index =3D=3D 0 && + /* bmAttributes field of config descriptor */ + len > 7 && (dev->dev.data_buf[7] & USB_CFG_ATT_WAKEUP)) { + DPRINTF("Removed remote wake %04X:%04X\n", + dev->device_info.vendor_id, + dev->device_info.product_id); + dev->dev.data_buf[7] &=3D ~USB_CFG_ATT_WAKEUP; + } usb_generic_async_ctrl_complete(&dev->dev, p); } free(data); @@ -2530,6 +2548,8 @@ static Property usbredir_properties[] =3D { DEFINE_PROP_UINT8("debug", USBRedirDevice, debug, usbredirparser_warni= ng), DEFINE_PROP_STRING("filter", USBRedirDevice, filter_str), DEFINE_PROP_BOOL("streams", USBRedirDevice, enable_streams, true), + DEFINE_PROP_BOOL("suppress-remote-wake", USBRedirDevice, + suppress_remote_wake, true), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.17.1