From nobody Fri Nov 18 19:13:06 2022 X-Original-To: dev-commits-src-all@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 4NDRJL6q97z4dGv3; Fri, 18 Nov 2022 19:13:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NDRJL6K02z3LST; Fri, 18 Nov 2022 19:13:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668798786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jUpN3HFRS2HJuiNnnNVjvNwYhjE76mF35JQyQreZqWE=; b=nC14rW3iP2ONCCULhwQK/BSHWHUpL39ilUYasqzHyYgRGpiFqw5rnrkXhfpQM5PVcqlj0W /+iGEiYpcGdJbLM63IWbU1arhqvPunpk3OtO8JAr5FN6vm+BZtonhSoWOXfephS+BsJnyE 26DvQhXWwkSyxzje2VrwjIl9Ry0PAIZDBoGXi2fXNeMUW4EOSoYdD19xuWzNJzPDaWLEpe GlvlRjBgEDgvbnxmMQ8wF/Q35yb7WyohX6HBLyZmG/SeV1odx8kFgv9haS66s/knSEsCq/ 5qd6dOYhGcPKsuMkrdwBGkzHUmgE3f5mnUW5/U4NcJnK0U8kWOAHP2FypQo8zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668798786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jUpN3HFRS2HJuiNnnNVjvNwYhjE76mF35JQyQreZqWE=; b=sO4YTXiKxkSVo/IZX50OCgMbLMPCvBC4WJo31nHpIbl2k6WZuzATZHzb91b2iFTgL4uzNw EzYPmsInsQ+y5g6R97xz8igFO5d94FC1bvCtourWHUgT9fJwJjLo8pLopOfZxTp81pqNjl SWxl4oav+SPeoH34Jhp41SE2a5lRdaVpV8wV5/s0zrtZGvq7Udj9YUs6R2gbxVidfTqMEO dXZIovg+9P6ahhFHIXOctFmRomS9JZZxkmjQp/HQOVXQnhQc2qjYAQp8isYWwMqBrDm5An aUSqKUrgNmu5iEvuTFM/xZxWh+RdFtGPGjNks/a7ZVHIwqYWH3rfQa5SSDoatw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668798786; a=rsa-sha256; cv=none; b=l5VV0Gs/SyCrs9hkGuF/6eZy32p4NtD4TZVA5gv+vtwIaCM2hAUScXfPZx0mLKXzgutGCU UPmdKCdivdmdGElAXLekkh/68wNklP0UtJdtYhm1r96sP34D5A6Gvkkjvjz428w1tlVtIW owVUmnynQvpCFF7+jZVct1nhXjmxQqXNELQoZu7qBgmWRMP9RgGS/yCIQ4mqfS2ZXtvEpK ux7d6bukW9izKHb8SYaA8EhsFJYJEwk8RQgCp7ctVsR0Lw5j8LUIHYkiKwx/rxHHj6Wt44 EhlG3TvnwgJ2fsvM8GKamheZrggpGVpOPhPkpFR+nR7Be01Uw0bbCpdgIgEe8w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NDRJL5R86zHYC; Fri, 18 Nov 2022 19:13:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AIJD6I8001673; Fri, 18 Nov 2022 19:13:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AIJD6rs001672; Fri, 18 Nov 2022 19:13:06 GMT (envelope-from git) Date: Fri, 18 Nov 2022 19:13:06 GMT Message-Id: <202211181913.2AIJD6rs001672@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 0705b7f4e64f - main - bhyve: Avoid using a packed struct for xhci port registers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0705b7f4e64fdbad49a3a6d9131029a9734deb2c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=0705b7f4e64fdbad49a3a6d9131029a9734deb2c commit 0705b7f4e64fdbad49a3a6d9131029a9734deb2c Author: Mark Johnston AuthorDate: 2022-11-18 19:07:38 +0000 Commit: Mark Johnston CommitDate: 2022-11-18 19:11:48 +0000 bhyve: Avoid using a packed struct for xhci port registers I believe the __packed annotation is there only because pci_xhci_portregs_read() is treating the register set as an array of uint32_t. clang warns about taking the address of portregs->portsc because it is a packed member and thus might not have expected alignment. Fix the problem by simply selecting the field to read with a switch statement. This mimics pci_xhci_portregs_write(). While here, switch to using some symbolic constants. There is a small semantic change here in that pci_xhci_portregs_read() would silently truncate unaligned offsets. For consistency with pci_xhci_portregs_write(), which does not do that, return all ones for unaligned reads instead. MFC after: 2 weeks Reviewed by: corvink, jhb Differential Revision: https://reviews.freebsd.org/D37408 --- usr.sbin/bhyve/pci_xhci.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c index 1f3d78a4cfea..f95f62fbf0e5 100644 --- a/usr.sbin/bhyve/pci_xhci.c +++ b/usr.sbin/bhyve/pci_xhci.c @@ -568,6 +568,10 @@ pci_xhci_portregs_write(struct pci_xhci_softc *sc, uint64_t offset, */ p->porthlpmc = value; break; + default: + DPRINTF(("pci_xhci: unaligned portreg write offset %#lx", + offset)); + break; } } @@ -2132,12 +2136,13 @@ pci_xhci_portregs_read(struct pci_xhci_softc *sc, uint64_t offset) { struct pci_xhci_portregs *portregs; int port; - uint32_t *p; + uint32_t reg; if (sc->portregs == NULL) return (0); - port = (offset - 0x3F0) / 0x10; + port = (offset - XHCI_PORTREGS_PORT0) / XHCI_PORTREGS_SETSZ; + offset = (offset - XHCI_PORTREGS_PORT0) % XHCI_PORTREGS_SETSZ; if (port > XHCI_MAX_DEVS) { DPRINTF(("pci_xhci: portregs_read port %d >= XHCI_MAX_DEVS", @@ -2147,16 +2152,31 @@ pci_xhci_portregs_read(struct pci_xhci_softc *sc, uint64_t offset) return (XHCI_PS_SPEED_SET(3)); } - offset = (offset - 0x3F0) % 0x10; - portregs = XHCI_PORTREG_PTR(sc, port); - p = &portregs->portsc; - p += offset / sizeof(uint32_t); + switch (offset) { + case 0: + reg = portregs->portsc; + break; + case 4: + reg = portregs->portpmsc; + break; + case 8: + reg = portregs->portli; + break; + case 12: + reg = portregs->porthlpmc; + break; + default: + DPRINTF(("pci_xhci: unaligned portregs read offset %#lx", + offset)); + reg = 0xffffffff; + break; + } DPRINTF(("pci_xhci: portregs read offset 0x%lx port %u -> 0x%x", - offset, port, *p)); + offset, port, reg)); - return (*p); + return (reg); } static void