From nobody Tue Jan 11 18:32:02 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 86A8B1945376; Tue, 11 Jan 2022 18:32:03 +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 4JYK6W1pr7z4YYg; Tue, 11 Jan 2022 18:32:03 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 053211E316; Tue, 11 Jan 2022 18:32:03 +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 20BIW2dk024035; Tue, 11 Jan 2022 18:32:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20BIW2d3024034; Tue, 11 Jan 2022 18:32:02 GMT (envelope-from git) Date: Tue, 11 Jan 2022 18:32:02 GMT Message-Id: <202201111832.20BIW2d3024034@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: f1b8efb1b4ff - releng/12.2 - Hyper-V: vPCI: Prepopulate device bars 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/releng/12.2 X-Git-Reftype: branch X-Git-Commit: f1b8efb1b4ffc2182385d3f5cc26c37a4ad59026 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641925923; 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=l/hxb1vIZbMWCsMqtZWelVbqzim3J1Am5UKAFXsfIvc=; b=NIZa2qyWWdE8uRhz1xyW/AvJfDepXdP+ookibOR4tPR/tlRO7hkCfYjTD2kq5XfS3NwSGW c5TZMldm0xRMBLrElETVXdqBc1zwqrmRx+sA9ie6i0Tn+YsfeGE1XcollfJgLAdYpcV0/R vPCMB+VxKg45/USBafHMlY8bzt7FYbgPkmQlDnUQfEFFUV6b/wTrXBNgaMeHY7xJeAJO6g XQPTyY28QZlGSldFisSIvGITkTR+jWSxr9ltMYbQwxmhwyW7IlLg9LNqFtuls734VwK6DC aUPNWa/S2Pa90mirI6CVLdDAkTH2J+r6rktqA2qFQFhrpsXCKz12aNmZNJgL4A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641925923; a=rsa-sha256; cv=none; b=DanQQjk8a6b5VfWP60SWIo1wHxym8XsM1elwqk6XopJmt7kKqtU/McbVpiphK46jg8Ek0H lnxthMgGxZUj7hddxVxaK0vSLhjix2lFyM3x0IzW4gmgBVCPmuWtmxsWnUMKIwPGLrhy8U kdh+gGD51xNEW/TEySpgEqSizVRmjQKDZapgDQj3jEtVPRCl8bPEp/u9Nr8BlzStuwSqYi 6ywWHODieVznsIanJntmpXRg9bD99yIiyF+dsxHSglNFGQD8tHhm1vQ9TjZMGQxpKGGJwc zhV3tvuts7CSQ+5UA4e/FMTQ8gKVaqV9RCZh6AcYt/1NVIqH7QDlqy9RhU30lQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/12.2 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=f1b8efb1b4ffc2182385d3f5cc26c37a4ad59026 commit f1b8efb1b4ffc2182385d3f5cc26c37a4ad59026 Author: Wei Hu AuthorDate: 2021-11-27 06:42:34 +0000 Commit: Ed Maste CommitDate: 2022-01-10 18:04:06 +0000 Hyper-V: vPCI: Prepopulate device bars In recent Hyper-V releases on Windows Server 2022, vPCI code does not initialize the last 4 bit of device bar registers. This behavior change could result weird problems cuasing PCI code failure when configuring bars. Just write all 1's to those bars whose probed values are not the same as current read ones. This seems to make Hyper-V vPCI and pci_write_bar() to cooperate correctly on these releases. Reported by: khng@freebsd.org Tested by: khng@freebsd.org MFC after: 2 weeks Sponsored by: Microsoft (cherry picked from commit 75412a521f60d4b0393c730ffb284e7c6ff9d2de) (cherry picked from commit eabea1c700ad8eacb8dc780d8620b59ce72b2cf2) Approved by: so Errata: FreeBSD-EN-22:03.hyperv --- sys/dev/hyperv/pcib/vmbus_pcib.c | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/sys/dev/hyperv/pcib/vmbus_pcib.c b/sys/dev/hyperv/pcib/vmbus_pcib.c index 0d49ae313ccd..a822e64b86e6 100644 --- a/sys/dev/hyperv/pcib/vmbus_pcib.c +++ b/sys/dev/hyperv/pcib/vmbus_pcib.c @@ -1304,6 +1304,47 @@ _hv_pcifront_write_config(struct hv_pci_dev *hpdev, int where, int size, } } +/* + * The vPCI in some Hyper-V releases do not initialize the last 4 + * bit of BAR registers. This could result weird problems causing PCI + * code fail to configure BAR correctly. + * + * Just write all 1's to those BARs whose probed values are not zero. + * This seems to make the Hyper-V vPCI and pci_write_bar() to cooperate + * correctly. + */ + +static void +vmbus_pcib_prepopulate_bars(struct hv_pcibus *hbus) +{ + struct hv_pci_dev *hpdev; + int i; + + mtx_lock(&hbus->device_list_lock); + TAILQ_FOREACH(hpdev, &hbus->children, link) { + for (i = 0; i < 6; i++) { + /* Ignore empty bar */ + if (hpdev->probed_bar[i] == 0) + continue; + + uint32_t bar_val = 0; + + _hv_pcifront_read_config(hpdev, PCIR_BAR(i), + 4, &bar_val); + + if (hpdev->probed_bar[i] != bar_val) { + if (bootverbose) + printf("vmbus_pcib: initialize bar %d " + "by writing all 1s\n", i); + + _hv_pcifront_write_config(hpdev, PCIR_BAR(i), + 4, 0xffffffff); + } + } + } + mtx_unlock(&hbus->device_list_lock); +} + static void vmbus_pcib_set_detaching(void *arg, int pending __unused) { @@ -1425,6 +1466,8 @@ vmbus_pcib_attach(device_t dev) if (ret) goto vmbus_close; + vmbus_pcib_prepopulate_bars(hbus); + hbus->pci_bus = device_add_child(dev, "pci", -1); if (!hbus->pci_bus) { device_printf(dev, "failed to create pci bus\n");