From nobody Fri Mar 29 10:23:27 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=1575290285; cv=none; d=zohomail.com; s=zohoarc; b=BIkGj8SOBNkdQh5aeRBputsBs4XjR1FUZxXz818c/C9t5yYewJ8ohSiljIuYUi9dKxOutICPLTGy1YHUNe3tTIvbPSzFOA0rv5xoDfBJlQxFZiVu37dHLEeEvCOwlPS5q/xXvR2iE8uQQ6QxvRmYOIovMANQu5B+3j82EiIlN5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575290285; 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=TjZliZhEsVF0vv2Qzf2ABh+Szj2+Cht1CR4qLXA8WKs=; b=HjiKdIRtN3dgeuZQZ74w782WsAnXpJD+z0JJW+o2M7DUT9yNgMFJr9hIa3cyczZI1QiILoAbreWXDiuu8NbHloHFW5CnbE00aHiuSjHv57pSDF7QzAjhepAc0Jg5wOifXdFuaB18rrAjdhaFopUYe/nGmGuMEhdhmWx2NBx0Pyc= 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 1575290285976812.8541907476858; Mon, 2 Dec 2019 04:38:05 -0800 (PST) Received: from localhost ([::1]:35126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibkxn-0007AA-Ty for importer@patchew.org; Mon, 02 Dec 2019 07:38:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51966) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibkua-0003mG-IV for qemu-devel@nongnu.org; Mon, 02 Dec 2019 07:34:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibkuZ-0004gl-7p for qemu-devel@nongnu.org; Mon, 02 Dec 2019 07:34:44 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:35084) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ibkuY-0004dX-Sz for qemu-devel@nongnu.org; Mon, 02 Dec 2019 07:34:43 -0500 Received: by mail-wr1-x442.google.com with SMTP id g17so11991245wro.2 for ; Mon, 02 Dec 2019 04:34:41 -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 k8sm17134658wrl.3.2019.12.02.04.34.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Dec 2019 04:34:39 -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=TjZliZhEsVF0vv2Qzf2ABh+Szj2+Cht1CR4qLXA8WKs=; b=grv1X8MxVimO/Q+FdZ0YDA+bnXbd2HE1haSmWTq70yIUhTiHkKoQJPMf8wzP7PLhO2 u3n6Y87x374NmY967CeXgXyFusBZfq8lSUS6GRvKKwcF2fKo8JAJ5O16mxvaF5O+bYLa WFt1F2yei46k5N3qx+1e6mMGSLCmedTgtMAzcWC7zqMHZMZ/Fd2Wirkt9kucb72Y/ou2 S4uXbh1gcJEr1kfEkOlU0inAcK+ieelSO0irGrRUgZKRJZnjGkdU38cegtEV0U+QTznz 6B7NDEwVpKy3HNulL8p4XiXZFVarlFwhRmERU2rs6kGsBxYmF/0Q/p8JKKS5eDUuBhVp DR9g== 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=TjZliZhEsVF0vv2Qzf2ABh+Szj2+Cht1CR4qLXA8WKs=; b=Lr7yAhzvL36eJ3YNfPCzjzJudvahVQY8Liuh8hX+mNnunpZLcFrouX8hJ0aUm+JpKn uhhoMxe0QpTqqXPJ0DREa/FgnJz+8sT7ses85pMyX9cwfuh7pib2DuqzVrDOx0svQYpu PWO4jf4zEkRCG7qDBB9JIpTU/n5aw909JcDbjBNbDLd6HykMg3Y3MZqDIKVPWB3rpOMU hGKa/yiEw9nttRzYOrU+gdbvzHA3vdTNoIHdSpQYthNYw4UpsuiXPy6WaGQ315lyt73a wOmYSv4h+WrGX7DQVsoMR62U74v2+fRQLDVgupPPq27ogXzlZ/+awA6iUkqrgCCAobnO 2OeQ== X-Gm-Message-State: APjAAAWg3G5cEb4X34KJqbuzuBwf31+DKf5g1vHupdahClSjmMqK7m2K vjOXAdm8XPaipVWdNQXdCLNIUA== X-Google-Smtp-Source: APXvYqxtIcgrBiDKLeASvf8gn0lOXPTTmaDcm7OTaoZzAxinWkAmEe+ADlHRDANovxJgHzTiYp0XOQ== X-Received: by 2002:a5d:6652:: with SMTP id f18mr28426278wrw.246.1575290080160; Mon, 02 Dec 2019 04:34:40 -0800 (PST) From: Yuri Benditovich To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, kraxel@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 1/2] usb-host: remove 'remote wakeup' flag from configuration descriptor Date: Mon, 2 Dec 2019 14:34:29 +0200 Message-Id: <20191202123430.7125-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191202123430.7125-1-yuri.benditovich@daynix.com> References: <20191202123430.7125-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::442 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 | 18 ++++++++++++++++++ hw/usb/trace-events | 1 + 3 files changed, 20 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..77c2720ec6 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,20 @@ 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)) { + struct libusb_device_descriptor desc; + libusb_get_device_descriptor(s->dev, &desc); + trace_usb_host_remote_wakeup_removed(desc.idVendor, desc.i= dProduct); + 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 +1613,7 @@ 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_remot= e_wake, true), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/usb/trace-events b/hw/usb/trace-events index 2d3713351c..6f87b5262a 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(uint16_t vid, uint16_t pid) "dev %04x:%04x" --=20 2.17.1 From nobody Fri Mar 29 10:23:27 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=1575290229; cv=none; d=zohomail.com; s=zohoarc; b=SmWY9ufaztK2+Oc7y0EDHaC2ZB9P/LEnDz2I9Q5mKV1sZvEsQadr0+RHFUdKY0eKDPa1zEqFG+3y45q66bPbpfdOQ/FTX31akkELxD+Z7q4h3sz7t2oSxHa+liq8Cmpsxhya7xfG6Z5g1NLaCzbfoWhWsWnjht3ve6/QLKek1do= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575290229; 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=CaeYcD+6toYjz5yaN6fm3AEu5nHQdWi6KOlgGrLZDsY=; b=X8SvwVEGjGGj1D+/o7tGSXRRXAtt5n1SjBgZ6gHMRNmRh0cl1tK/pucct6T3Xr4OWX4bEp1RNacUNq/1Er+ZbVVhFc6u+ICy9efJcjs7jiI6sBZg0F9Lnjj55dsgTDgLVPo7YzhKgdatkR+w+yOEtMVjtWKJ321ZSkGqFulkxBo= 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 1575290229609680.414739853978; Mon, 2 Dec 2019 04:37:09 -0800 (PST) Received: from localhost ([::1]:35112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibkwt-00069x-KX for importer@patchew.org; Mon, 02 Dec 2019 07:37:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51964) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibkua-0003m4-F4 for qemu-devel@nongnu.org; Mon, 02 Dec 2019 07:34:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibkuZ-0004gz-9x for qemu-devel@nongnu.org; Mon, 02 Dec 2019 07:34:44 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:46602) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ibkuY-0004er-U5 for qemu-devel@nongnu.org; Mon, 02 Dec 2019 07:34:43 -0500 Received: by mail-wr1-x444.google.com with SMTP id z7so40572842wrl.13 for ; Mon, 02 Dec 2019 04:34:42 -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 k8sm17134658wrl.3.2019.12.02.04.34.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Dec 2019 04:34:40 -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=CaeYcD+6toYjz5yaN6fm3AEu5nHQdWi6KOlgGrLZDsY=; b=TpnYE5wWjj92bgSewhTuKaxA2m994ZMG7van9fXWF7k69zHqT4sNtacgJA1LwPesxA rziFP61TWpgXdkRzY73PUhBso58JwotUM7TVrgWInedABNwNrr8rLhDFLZLhE28iFbcl x1MQKBKT/PsBNmeBlvFxhH/oPF+PnzvSS9hCLXWGzxiUfIDhq4L7dh9JQoBPHyJYzJkS 40R+IChG4n8OY1CylJeCqqv2zXUAQB9ci5WeoJbIGIi9M+gnrr4TxhcDhX+b6cTWV1w4 qzD2nWWgVBgTYXVcoAFSAJISDpnwJP9KQ/ukbXnWxW9dF97AwZxWATaM5B7EvAnZHU0H ROKg== 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=CaeYcD+6toYjz5yaN6fm3AEu5nHQdWi6KOlgGrLZDsY=; b=kzGx1Wdww0djcy0J93QbG/kWnlW1Zj7ArmQ0orFY180TQkmNeK7JxtRxTb4B746GpB AeaZrCSJQ0hxVzLMwl59nALjiXBL0g6Lp2DXuB/q0aqtyvZDmBaySODz3OjCjeBumSXa uGLmHVXmX4AdQ8tcn2reI2/dwHzRYQJK7RT6x7GxVMSK6RaNd2TWkDaTeqFLXNDTYf80 128y9GzHD9QJMhOUHyGXRPsOULRot8b83PjPM0K4a9jGR+3M8DZxD+s8/TKJVZdwSI6I HLkwDgWtzHHCGFS+8jrZ4z4Iexbi1dKLoAn/dunfXLmQ9Q5uHBBG0RqsdmBvF0R+2lzp MORA== X-Gm-Message-State: APjAAAXzL0X8ExRCrhkrDzEJX1iU7iEJSRB/JypUgAV6SQV+3WkoHWW5 7KggE1qN7apJtBYgdYxZ9Pfjxw== X-Google-Smtp-Source: APXvYqzttkUEeZfMN7aTH6e6gi7mN8eiQIYHfrKX5eTBwHeUwqAh7iVmJbX5khErxThXu38LU2lXvQ== X-Received: by 2002:a5d:480b:: with SMTP id l11mr27362791wrq.129.1575290081354; Mon, 02 Dec 2019 04:34:41 -0800 (PST) From: Yuri Benditovich To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, kraxel@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 2/2] usb-redir: remove 'remote wakeup' flag from configuration descriptor Date: Mon, 2 Dec 2019 14:34:30 +0200 Message-Id: <20191202123430.7125-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191202123430.7125-1-yuri.benditovich@daynix.com> References: <20191202123430.7125-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::444 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 | 19 +++++++++++++++++++ 2 files changed, 20 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..7cc9c2aa00 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,7 @@ 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_remo= te_wake, true), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.17.1