All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/2] Usb 20210218 patches
@ 2021-02-18 11:51 Gerd Hoffmann
  2021-02-18 11:52 ` [PULL 1/2] usb-host: use correct altsetting in usb_host_ep_update Gerd Hoffmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2021-02-18 11:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

The following changes since commit 18543229fd7a2c79dcd6818c7b1f0f62512b5220:

  Merge remote-tracking branch 'remotes/cleber-gitlab/tags/python-next-pull-r=
equest' into staging (2021-02-16 14:37:57 +0000)

are available in the Git repository at:

  git://git.kraxel.org/qemu tags/usb-20210218-pull-request

for you to fetch changes up to 6ba5a437ad48f10931592f649b5b7375968f362d:

  usb/pcap: set flag_setup (2021-02-17 14:29:12 +0100)

----------------------------------------------------------------
usb: two bugfixes.

----------------------------------------------------------------

Gerd Hoffmann (1):
  usb/pcap: set flag_setup

Nick Rosbrook (1):
  usb-host: use correct altsetting in usb_host_ep_update

 hw/usb/host-libusb.c | 18 +++++++++++++++---
 hw/usb/pcap.c        |  2 ++
 2 files changed, 17 insertions(+), 3 deletions(-)

--=20
2.29.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PULL 1/2] usb-host: use correct altsetting in usb_host_ep_update
  2021-02-18 11:51 [PULL 0/2] Usb 20210218 patches Gerd Hoffmann
@ 2021-02-18 11:52 ` Gerd Hoffmann
  2021-02-18 11:52 ` [PULL 2/2] usb/pcap: set flag_setup Gerd Hoffmann
  2021-02-18 16:33 ` [PULL 0/2] Usb 20210218 patches Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2021-02-18 11:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Nick Rosbrook, Gerd Hoffmann, Nick Rosbrook

From: Nick Rosbrook <rosbrookn@gmail.com>

In order to keep track of the alternate setting that should be used for
a given interface, the USBDevice struct keeps an array of alternate
setting values, which is indexed by the interface number. In
usb_host_set_interface, when this array is updated, usb_host_ep_update
is called as a result. However, when usb_host_ep_update accesses the
active libusb_config_descriptor, it indexes udev->altsetting with the
loop variable, rather than the interface number.

With the simple trace backend enable, this behavior can be seen:

  [...]

  usb_xhci_xfer_start 0.440 pid=1215 xfer=0x5596a4b85930 slotid=0x1 epid=0x1 streamid=0x0
  usb_packet_state_change 1.703 pid=1215 bus=0x1 port=b'1' ep=0x0 p=0x5596a4b85938 o=b'undef' n=b'setup'
  usb_host_req_control 2.269 pid=1215 bus=0x1 addr=0x5 p=0x5596a4b85938 req=0x10b value=0x1 index=0xd
  usb_host_set_interface 0.449 pid=1215 bus=0x1 addr=0x5 interface=0xd alt=0x1
  usb_host_parse_config 2542.648 pid=1215 bus=0x1 addr=0x5 value=0x2 active=0x1
  usb_host_parse_interface 1.804 pid=1215 bus=0x1 addr=0x5 num=0xc alt=0x0 active=0x1
  usb_host_parse_endpoint 2.012 pid=1215 bus=0x1 addr=0x5 ep=0x2 dir=b'in' type=b'int' active=0x1
  usb_host_parse_interface 1.598 pid=1215 bus=0x1 addr=0x5 num=0xd alt=0x0 active=0x1
  usb_host_req_emulated 3.593 pid=1215 bus=0x1 addr=0x5 p=0x5596a4b85938 status=0x0
  usb_packet_state_change 2.550 pid=1215 bus=0x1 port=b'1' ep=0x0 p=0x5596a4b85938 o=b'setup' n=b'complete'
  usb_xhci_xfer_success 4.298 pid=1215 xfer=0x5596a4b85930 bytes=0x0

  [...]

In particular, it is seen that although usb_host_set_interface sets the
alternate setting of interface 0xd to 0x1, usb_host_ep_update uses 0x0
as the alternate setting due to using the incorrect index to
udev->altsetting.

Fix this problem by getting the interface number from the active
libusb_config_descriptor, and then using that as the index to
udev->altsetting.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
Message-Id: <20210201213021.500277-1-rosbrookn@ainfosec.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/host-libusb.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 7dde3d12069e..354713a77dc9 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -836,7 +836,7 @@ static void usb_host_ep_update(USBHostDevice *s)
     struct libusb_ss_endpoint_companion_descriptor *endp_ss_comp;
 #endif
     uint8_t devep, type;
-    int pid, ep;
+    int pid, ep, alt;
     int rc, i, e;
 
     usb_ep_reset(udev);
@@ -848,8 +848,20 @@ static void usb_host_ep_update(USBHostDevice *s)
                                 conf->bConfigurationValue, true);
 
     for (i = 0; i < conf->bNumInterfaces; i++) {
-        assert(udev->altsetting[i] < conf->interface[i].num_altsetting);
-        intf = &conf->interface[i].altsetting[udev->altsetting[i]];
+        /*
+         * The udev->altsetting array indexes alternate settings
+         * by the interface number. Get the 0th alternate setting
+         * first so that we can grab the interface number, and
+         * then correct the alternate setting value if necessary.
+         */
+        intf = &conf->interface[i].altsetting[0];
+        alt = udev->altsetting[intf->bInterfaceNumber];
+
+        if (alt != 0) {
+            assert(alt < conf->interface[i].num_altsetting);
+            intf = &conf->interface[i].altsetting[alt];
+        }
+
         trace_usb_host_parse_interface(s->bus_num, s->addr,
                                        intf->bInterfaceNumber,
                                        intf->bAlternateSetting, true);
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PULL 2/2] usb/pcap: set flag_setup
  2021-02-18 11:51 [PULL 0/2] Usb 20210218 patches Gerd Hoffmann
  2021-02-18 11:52 ` [PULL 1/2] usb-host: use correct altsetting in usb_host_ep_update Gerd Hoffmann
@ 2021-02-18 11:52 ` Gerd Hoffmann
  2021-02-18 16:33 ` [PULL 0/2] Usb 20210218 patches Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2021-02-18 11:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Without that wireshark complains about invalid control setup data
for non-control transfers.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-Id: <20210216144939.841873-1-kraxel@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/pcap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/usb/pcap.c b/hw/usb/pcap.c
index 4350989d3a71..dbff00be252e 100644
--- a/hw/usb/pcap.c
+++ b/hw/usb/pcap.c
@@ -127,6 +127,7 @@ static void do_usb_pcap_ctrl(FILE *fp, USBPacket *p, bool setup)
         .xfer_type  = usbmon_xfer_type[USB_ENDPOINT_XFER_CONTROL],
         .epnum      = in ? 0x80 : 0,
         .devnum     = dev->addr,
+        .flag_setup = setup ? 0 : '-',
         .flag_data  = '=',
         .length     = dev->setup_len,
     };
@@ -169,6 +170,7 @@ static void do_usb_pcap_data(FILE *fp, USBPacket *p, bool setup)
         .xfer_type  = usbmon_xfer_type[p->ep->type],
         .epnum      = usbmon_epnum(p),
         .devnum     = p->ep->dev->addr,
+        .flag_setup = '-',
         .flag_data  = '=',
         .length     = p->iov.size,
     };
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PULL 0/2] Usb 20210218 patches
  2021-02-18 11:51 [PULL 0/2] Usb 20210218 patches Gerd Hoffmann
  2021-02-18 11:52 ` [PULL 1/2] usb-host: use correct altsetting in usb_host_ep_update Gerd Hoffmann
  2021-02-18 11:52 ` [PULL 2/2] usb/pcap: set flag_setup Gerd Hoffmann
@ 2021-02-18 16:33 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2021-02-18 16:33 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU Developers

On Thu, 18 Feb 2021 at 11:57, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> The following changes since commit 18543229fd7a2c79dcd6818c7b1f0f62512b5220:
>
>   Merge remote-tracking branch 'remotes/cleber-gitlab/tags/python-next-pull-r=
> equest' into staging (2021-02-16 14:37:57 +0000)
>
> are available in the Git repository at:
>
>   git://git.kraxel.org/qemu tags/usb-20210218-pull-request
>
> for you to fetch changes up to 6ba5a437ad48f10931592f649b5b7375968f362d:
>
>   usb/pcap: set flag_setup (2021-02-17 14:29:12 +0100)
>
> ----------------------------------------------------------------
> usb: two bugfixes.
>
> ----------------------------------------------------------------
>
> Gerd Hoffmann (1):
>   usb/pcap: set flag_setup
>
> Nick Rosbrook (1):
>   usb-host: use correct altsetting in usb_host_ep_update
>
>  hw/usb/host-libusb.c | 18 +++++++++++++++---
>  hw/usb/pcap.c        |  2 ++
>  2 files changed, 17 insertions(+), 3 deletions(-)


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/6.0
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-18 16:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-18 11:51 [PULL 0/2] Usb 20210218 patches Gerd Hoffmann
2021-02-18 11:52 ` [PULL 1/2] usb-host: use correct altsetting in usb_host_ep_update Gerd Hoffmann
2021-02-18 11:52 ` [PULL 2/2] usb/pcap: set flag_setup Gerd Hoffmann
2021-02-18 16:33 ` [PULL 0/2] Usb 20210218 patches Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.