From nobody Tue Jun 01 09:09:59 2021 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 3F8CEC7E696 for ; Tue, 1 Jun 2021 09:10:13 +0000 (UTC) (envelope-from patrascu.naina14@gmail.com) Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FvRFc2JrZz4Wd5 for ; Tue, 1 Jun 2021 09:10:12 +0000 (UTC) (envelope-from patrascu.naina14@gmail.com) Received: by mail-pj1-x1032.google.com with SMTP id mq2-20020a17090b3802b0290162428291f5so1501036pjb.4 for ; Tue, 01 Jun 2021 02:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iTdy/AaJeBZrEkcZO4eL20HM0cmOLhekZOKjv+LLk9k=; b=EgbE7+Sr+h3O1amRja2Wx6dnyx7s5KtF3VrXAU4twuyny31nC2GeG5n+CAruSdDqX1 RVoC0NaLZc5MqDK2R+N+Y3nZihoI2pT0WvDWrzMQPQKEZt2jCSdloshlNr7qTYnRDUh2 m/2yWmz7oCrswFCfgSAPu+gchY55HuqvIDNKrdBejGVnbqpCvCgkpRL5+Rdqqd3ziJ8p Y826QaLMw17h+yiGlKNHVxy9Op9IuwYMUi2ibHHVxr4q+4PyT2fyGdr3BucI8CqYzEk6 LhxnkOcJGD3zFIsXC/uRb+tkTMs+fg+VOdZ4ns3eW4JoBosBuuSxxtDj10gOzN6HZUHv yHLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iTdy/AaJeBZrEkcZO4eL20HM0cmOLhekZOKjv+LLk9k=; b=tQF+8GsNGZwLZ//zYDRcxKuMhC96bbm/itfzTy8c33nZkXltw3PHTzYgh89UGXlnOu E3AV6R8A8Ay2eRPMWiLstRp9B0wIllX4mcK7Rn63di1ZxNV3k12hzYEM3uSG/+CXkHAg DTbqYIL5WPc0WvTz9xIzvl8/1JQk5+Yyu9IpqcUCGeaRjLDzwvF8+qxX/VJr4tYfI/nW z8LWCkAiszuHFBUFHrUXJ1qJvLkPkZ8ypcuJ3/seYbU9Ecgtl7NwGZXXyisE80pZSKqy bIiqhSzsHcAl8mAkWuFHq9PKoVOsYtfKar7Z5xGpkO5iTWilSl6wTOjcYPOVaMMOm4Fs Qchg== X-Gm-Message-State: AOAM533loixqx1m7TAle83Zy9xWIVB78yLy+9I8y895MYQJYnGiILTtf j8Lp6Aw1unWIdA4uM/8D54+/fla/uyBA3iQF3aU= X-Google-Smtp-Source: ABdhPJzVzAxQ5EyCotBM5vzjd+ymliAMnc6rPg7pe7LKuKUMcTQdVdNFpvekY279ebCnjIYLiyEWlLW3J6WMHnaWQRk= X-Received: by 2002:a17:90a:3fca:: with SMTP id u10mr3933869pjm.76.1622538610846; Tue, 01 Jun 2021 02:10:10 -0700 (PDT) List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 References: <20210512191448.GK14975@funkthat.com> In-Reply-To: From: Naina Patrascu Date: Tue, 1 Jun 2021 12:09:59 +0300 Message-ID: Subject: Re: Indexing problem with address number of a USB device To: jmg@funkthat.com, Hans Petter Selasky Cc: freebsd-hackers@freebsd.org, lucian_ioan.popescu@stud.acs.upb.ro, Elena Mihailescu Content-Type: multipart/alternative; boundary="00000000000088ae5405c3b0b582" X-Rspamd-Queue-Id: 4FvRFc2JrZz4Wd5 X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=EgbE7+Sr; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of patrascunaina14@gmail.com designates 2607:f8b0:4864:20::1032 as permitted sender) smtp.mailfrom=patrascunaina14@gmail.com X-Spamd-Result: default: False [-4.00 / 15.00]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RBL_DBL_DONT_QUERY_IPS(0.00)[2607:f8b0:4864:20::1032:from]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; TAGGED_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; SPAMHAUS_ZRD(0.00)[2607:f8b0:4864:20::1032:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::1032:from]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-hackers]; FREEMAIL_CC(0.00)[freebsd.org,stud.acs.upb.ro,gmail.com] X-ThisMailContainsUnwantedMimeParts: Y --00000000000088ae5405c3b0b582 Content-Type: text/plain; charset="UTF-8" It worked! Thank you! You were right, we assigned the USB through bus and device address, but we were comparing the port number in the enumeration process. On Wed, May 12, 2021 at 10:24 PM Hans Petter Selasky wrote: > On 5/12/21 9:14 PM, John-Mark Gurney wrote: > > 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. > > > > > > Hi, > > LibUSB in FreeBSD has a helper function to compute the full port topology: > > libusb_get_port_numbers() > and: > > libusb20_dev_get_port_path() > > --HPS > --00000000000088ae5405c3b0b582--