From owner-freebsd-hackers@freebsd.org Wed May 12 19:15:00 2021 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9BA2D6495E1 for ; Wed, 12 May 2021 19:15:00 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "gate2.funkthat.com", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FgPcf6f2Wz3Dcj for ; Wed, 12 May 2021 19:14:58 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (localhost [127.0.0.1]) by gold.funkthat.com (8.15.2/8.15.2) with ESMTPS id 14CJEprN053384 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 12 May 2021 12:14:51 -0700 (PDT) (envelope-from jmg@gold.funkthat.com) Received: (from jmg@localhost) by gold.funkthat.com (8.15.2/8.15.2/Submit) id 14CJEmDP053380; Wed, 12 May 2021 12:14:48 -0700 (PDT) (envelope-from jmg) Date: Wed, 12 May 2021 12:14:48 -0700 From: John-Mark Gurney To: Naina Patrascu Cc: freebsd-hackers@freebsd.org, lucian_ioan.popescu@stud.acs.upb.ro, Elena Mihailescu Subject: Re: Indexing problem with address number of a USB device Message-ID: <20210512191448.GK14975@funkthat.com> Mail-Followup-To: Naina Patrascu , freebsd-hackers@freebsd.org, lucian_ioan.popescu@stud.acs.upb.ro, Elena Mihailescu References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 11.3-STABLE amd64 X-PGP-Fingerprint: D87A 235F FB71 1F3F 55B7 ED9B D5FF 5A51 C0AC 3D65 X-Files: The truth is out there X-URL: https://www.funkthat.com/ X-Resume: https://www.funkthat.com/~jmg/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? User-Agent: Mutt/1.6.1 (2016-04-27) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (gold.funkthat.com [127.0.0.1]); Wed, 12 May 2021 12:14:51 -0700 (PDT) X-Rspamd-Queue-Id: 4FgPcf6f2Wz3Dcj X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of jmg@gold.funkthat.com has no SPF policy when checking 208.87.223.18) smtp.mailfrom=jmg@gold.funkthat.com X-Spamd-Result: default: False [-0.22 / 15.00]; FREEMAIL_CC(0.00)[freebsd.org,stud.acs.upb.ro,gmail.com]; TO_DN_SOME(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FREEMAIL_TO(0.00)[gmail.com]; FORGED_SENDER(0.30)[jmg@funkthat.com,jmg@gold.funkthat.com]; MIME_TRACE(0.00)[0:+]; RBL_DBL_DONT_QUERY_IPS(0.00)[208.87.223.18:from]; ASN(0.00)[asn:32354, ipnet:208.87.216.0/21, country:US]; MID_RHS_MATCH_FROM(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jmg@funkthat.com,jmg@gold.funkthat.com]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.92)[-0.920]; FREEFALL_USER(0.00)[jmg]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; NEURAL_HAM_LONG(-1.00)[-1.000]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; AUTH_NA(1.00)[]; DMARC_NA(0.00)[funkthat.com]; SPAMHAUS_ZRD(0.00)[208.87.223.18:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; R_DKIM_NA(0.00)[]; R_SPF_NA(0.00)[no SPF record]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[]; MAILMAN_DEST(0.00)[freebsd-hackers] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Technical discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 May 2021 19:15:00 -0000 Naina Patrascu wrote this message on Tue, May 11, 2021 at 18:47 +0300: > We are working on the USB passthrough functionality for bhyve. We are > currently focusing on the passthrough of a USB stick and a USB keyboard. > > We are facing an indexing problem when trying to assign a USB device to a > virtual machine. > For example, we have the USB keyboard at busnum=1 and devaddr=2 on the > FreeBSD host virtual machine: > > # usbconfig -d ugen1.2 > ugen1.2: at usbus1, cfg=0 md=HOST spd=LOW (1.5Mbps) > pwr=ON (100mA) > > We specify to "bhyve" command to pass through the device to a guest virtual > machine: -s 30,xhci,1-2 > > As part of the enumeration process, the host controller executes the > internal scan to discover the physical devices and to compare them with the > ones assigned with the bhyve command. > But the USB device is discovered at bus 1 address 1, and we have to adjust > accordingly when parsing the bus-port to match the port number: > > 04f3:152e 1-1 connecting. > 04f3:152e 1-1 belong to this vm. > 04F3:152E 1-1 is attached to virtual port 5. > > We hardcoded when parsing bus-port: port -= 1. > When trying to pass through a USB stick, we have to increase the port > number to match the one discovered in the internal scan: > > # usbconfig -d ugen3.2 > ugen3.2: at usbus3, cfg=0 md=HOST spd=HIGH > (480Mbps) pwr=ON (300mA) > > 0951:1666 3-3 connecting. > 0951:1666 3-3 belong to this vm. > 0951:1666 3-3 is attached to virtual port 1. > > In our last investigation, we discovered that when increasing the number of > USB devices on the FreeBSD host vm, the port indexes of the devices > discovered by the internal scan, also varies. > > In function [1] we get the physical devices using libusb library and then > we execute the internal scan using function [2]. We get the information > about the physical device in function [3], also using libusb library. > > Can you help us understand where this problem could come from and how to > debug it? Yes, the ugen named does not map to port naming. I ran across this when I did the work to make serial devices consistent based upon the port number. The review for that work is here: https://reviews.freebsd.org/D21886#554613 The device address is a different enumeration from the port address information. The script linked in the review creates a mapping from the device name to the proper port number mapping. To see this, you can look at devinfo -v, and look at the port value vs the devaddr (device address assigned at enumeration). Hope this helps. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."