From nobody Sun May 19 23:41:32 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=1575404927; cv=none; d=zohomail.com; s=zohoarc; b=m8nDUnqT+NmvEOJdBqzS19cLryahle1Y9hGWC5HSiRransfi+zJk2VuXXzw+8M7WLC/RZRIm9qlNtyYiNLlB3rtmVwn8xZ6Hw8vyaw/lzAmq+dlQYqURJGSIl1/UL0s4h8sFZxnVeVK/SrDaehF1ANcs1zdDoeyEv9tTuXMf7Qw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575404927; 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=/PylRFnWKtD+HhPQYtsbijiWyCF1YZ11JweXKECL7sA=; b=hdCtLoZAc3+jTTMxJ5/WoOwN7I/Y+pgGjE/ESnRrNMxeDJcORuSxHOhio2Wc9SdHc8D73aGr65ZMSib66jNjVm/n9nnL9vW9s+Jo+zMEvm5LXD2Zcz/PZnmI39FP58CkPo1D0SmY0Wtuai/3il1SUp3seZqWUM7zDTwYBaSvCEU= 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 1575404927258978.5960738257955; Tue, 3 Dec 2019 12:28:47 -0800 (PST) Received: from localhost ([::1]:58200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icEmp-0001br-MT for importer@patchew.org; Tue, 03 Dec 2019 15:28:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49642) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icDWP-0008DD-6J for qemu-devel@nongnu.org; Tue, 03 Dec 2019 14:07:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1icDWI-000561-Sy for qemu-devel@nongnu.org; Tue, 03 Dec 2019 14:07:37 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:43004) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1icDWI-0004n5-Lj for qemu-devel@nongnu.org; Tue, 03 Dec 2019 14:07:34 -0500 Received: by mail-wr1-x441.google.com with SMTP id a15so5099115wrf.9 for ; Tue, 03 Dec 2019 11:07:29 -0800 (PST) Received: from f2.redhat.com (bzq-79-182-78-197.red.bezeqint.net. [79.182.78.197]) by smtp.gmail.com with ESMTPSA id t12sm4828810wrs.96.2019.12.03.11.07.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Dec 2019 11:07:25 -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=/PylRFnWKtD+HhPQYtsbijiWyCF1YZ11JweXKECL7sA=; b=AqtdBSs8QladLyDlvHgykPQmk0rlU0JCZT7rwOGzWmzUNGszjHs+/XvTIlnyze5ogZ kWlxq8cuR9c3ah3bm5ui2MFouYhISghjRgNTpHFzQRfLDkpMPpAkoc9V69sGzaObjAaT vq5sjeVjvHnrb1jbhy5Fu3voWD+FGUlET8WqrFDh+BGtZ9J4z25qHFvx/vuYNOougjXy L1XI2ICdhZon493NqrXD3OS4NfXiMEzIkPnkyY5vJeqicyyZv1xOyqZ8Ng5mAUApQWcJ up3LXk+TpolyGj+viyw+rcZvibg+w3SvPkOuWi8kl4M8vPGeHFnzWhFjwzskExvYkaBJ C+Dg== 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=/PylRFnWKtD+HhPQYtsbijiWyCF1YZ11JweXKECL7sA=; b=F/8d1LcWOxNCgN482F10Arox1UlgjEEiFwz8fGs4arO9J1jRYGUhUuaPgAeSmQTii+ qm7M6AcI5eLtRFanqNwZGOp17OsH2jRD1AUnBV+I3xx0k5RTL0nFjVatuCZoh/AzGCy4 5utmvi/T9HGOrVoUI5C0Do4dgfz1ZutS9L4cbcpzK2Nd2aKpSXNbPBg4fkMiwmsfQ/Jo AF6XoRicGazEYiRlhv3gd40YWxTsxxkfCBHOfaiAbc+JA2PgIBc2bcJtgv/2JzHxYD/L FoFfgrNrk6DWvL2KHmE/GDBVw+dXawjRLR6ez+bWnsBl3xtu31jltvKF26azLKjxa62p 8sVw== X-Gm-Message-State: APjAAAVnmMeOCc0z6ZWjqXTVrAYIU4ocjzBl9BuWRSv2sLpplsiY2d/U HecVZm/7Q38NDU/rM03fSGvzbg== X-Google-Smtp-Source: APXvYqyo991/uohTrjDcIJ4Wd0+xjTtepF1EgIbejzVOLo25KfTsvH3eSFHrmwvofQrqt3GgW1nu0A== X-Received: by 2002:a5d:50cf:: with SMTP id f15mr6857291wrt.381.1575400047195; Tue, 03 Dec 2019 11:07:27 -0800 (PST) From: Yuri Benditovich To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, kraxel@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 1/2] usb-host: remove 'remote wakeup' flag from configuration descriptor Date: Tue, 3 Dec 2019 21:07:15 +0200 Message-Id: <20191203190716.18917-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191203190716.18917-1-yuri.benditovich@daynix.com> References: <20191203190716.18917-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::441 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 4.2) Set 'usb-host.suppress-remote-wake' property to 'off' to keep 'remote wake' as is or to 'on' to remove 'remote wake' on 4.1 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 1689ad3bf8..8c0eaad091 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -29,6 +29,7 @@ =20 GlobalProperty hw_compat_4_1[] =3D { { "virtio-pci", "x-pcie-flr-init", "off" }, + { "usb-host", "suppress-remote-wake", "off" }, }; const size_t hw_compat_4_1_len =3D G_N_ELEMENTS(hw_compat_4_1); =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 Sun May 19 23:41:32 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=1575403922; cv=none; d=zohomail.com; s=zohoarc; b=AjtqLGVQjNfK0SklZ+/S9XFvtGf/SYARFaYGUoe5BDtAlfR/sFSxg81r4fRy/yedE95kTHmyvG+p5Fuab3jTf+dN0XWj6Agq9fi0byf792FIzCAtU5UFmAWqrZ4PttjXGthAyKVBArFSetRUs20QBSM4Kv4/FDCWVzsBEAF3aBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575403922; 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=4IEYfz9t+Zw7YNj6ThlO0KBz4N6TfDMprFZHPoQ5uBc=; b=NnUKZ91VdiwTrD1LEvzTPBkX/CrQKwnIBrDIXnC5WYHFg+J8aaLK45l045x0Ufwo+EzoN4hmtcHZKoE62m3MpvGWWGbvghgt60aav3xL+b/7uVqCcurhkX726kJoCmml2ddEycOj6MGKtv7Z3FGCRPZslVQ4OPY3EJgGfojHcHc= 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 1575403922552562.0038009922689; Tue, 3 Dec 2019 12:12:02 -0800 (PST) Received: from localhost ([::1]:58104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icEWZ-0004o1-Mv for importer@patchew.org; Tue, 03 Dec 2019 15:11:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49640) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icDWN-0008DB-5h for qemu-devel@nongnu.org; Tue, 03 Dec 2019 14:07:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1icDWH-00050v-1l for qemu-devel@nongnu.org; Tue, 03 Dec 2019 14:07:37 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:39092) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1icDWG-0004r3-LX for qemu-devel@nongnu.org; Tue, 03 Dec 2019 14:07:32 -0500 Received: by mail-wm1-x343.google.com with SMTP id s14so4834086wmh.4 for ; Tue, 03 Dec 2019 11:07:31 -0800 (PST) Received: from f2.redhat.com (bzq-79-182-78-197.red.bezeqint.net. [79.182.78.197]) by smtp.gmail.com with ESMTPSA id t12sm4828810wrs.96.2019.12.03.11.07.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Dec 2019 11:07:27 -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=4IEYfz9t+Zw7YNj6ThlO0KBz4N6TfDMprFZHPoQ5uBc=; b=b1XvUhqY5P1h84B5HP3HngILr1Iyo+jVtfua1NfjpeHD96vGni8JYS4Y1nLY+AiduB 3kZQqM4OzBvDzPdSTaQmtVJog/Y85xYcY8cvUsiGvKVMfGvcv3JjBCtTdBql1ozXxh5Z /GAiGb0JfSEq8Z9Ea7lXs0NEPcL3dRhPoTrraMagyfnSqB3o8MZK4nm+Yii+e5G3/G+S Cmsq6ASBd2SDCx/XUUu/VHPziSvrpdQwODGt+SdqL4sHtbP9ha85Mg2Uc7Xvaee6H0cU yRfsQ+evtGR6mX4cc5ypVJRnzEmQsXM99jEALNct4DbOW/qDMHO6GZhG4v6GpNQ3usIQ ccGg== 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=4IEYfz9t+Zw7YNj6ThlO0KBz4N6TfDMprFZHPoQ5uBc=; b=uoLztg9K0jRHlY26UNx6PdVi9VmsXRNqYrB2CXmxWsNK/cARmYEZ4tq82Wb9S5MhnM 0FcQq/IKNHEuQgxXSTPd31wMtACmjO6uNdymctHl5uFF7hgNSasbvFM/DbIPdZ8IKNWD sqU9m1RHLAesJYq35qNyUoP7ibZmbCH8jXziCxmKt73PYKkmCmcu04UEwFJGEyimsSV2 Us6H9IvysIF+ikav6hp+rYa3+vU3hyu4ieNHjI0RaGSejm49gbNwxYhRx9pG7Y3AW6hZ z7FTjAg0uynCCmYgMwleoUyckbxeSdA6XgwBW/vWbd9Gc2XzbwVciRLpeb1xscQMtOp9 1t0g== X-Gm-Message-State: APjAAAXqWiSnpP2FLZbXH3s0Eharw1V5073ASYnatdVjK36XIqjNjyOR a37DcQJzzsc5l9G6lA7CVNFvsg== X-Google-Smtp-Source: APXvYqzEvT1Btuzy8FZzAodgtEn3lWRtVa+1iS9kg5Unopv1qfEBado6iguijFxGtxfAmkwL0XfOyQ== X-Received: by 2002:a7b:cc97:: with SMTP id p23mr37630553wma.89.1575400050218; Tue, 03 Dec 2019 11:07:30 -0800 (PST) From: Yuri Benditovich To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, kraxel@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 2/2] usb-redir: remove 'remote wakeup' flag from configuration descriptor Date: Tue, 3 Dec 2019 21:07:16 +0200 Message-Id: <20191203190716.18917-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191203190716.18917-1-yuri.benditovich@daynix.com> References: <20191203190716.18917-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::343 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 4.2) Set 'usb-redir.suppress-remote-wake' property to 'off' to keep 'remote wake' as is or to 'on' to remove 'remote wake' on 4.1 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 8c0eaad091..44408ff87c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -30,6 +30,7 @@ GlobalProperty hw_compat_4_1[] =3D { { "virtio-pci", "x-pcie-flr-init", "off" }, { "usb-host", "suppress-remote-wake", "off" }, + { "usb-redir", "suppress-remote-wake", "off" }, }; const size_t hw_compat_4_1_len =3D G_N_ELEMENTS(hw_compat_4_1); =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