From nobody Fri Jan 14 14:20:36 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 3D7A8195D908; Fri, 14 Jan 2022 14:20:37 +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 4Jb3P103hzz3Lrc; Fri, 14 Jan 2022 14:20:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642170037; 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=Jo06Gchd1cyFaNWmtiSaYSysbeNG/8kP8YrZ0hyp40g=; b=s9O/mD+j7zWtHbeDuTcFNxCLyvsHoqcQCN0Hnzm5KnRjChX+Rio1USJPGaFRlojCTkgxaU dDWIqY5h8dkmRDWk/OJJIQZFXngrBqOAiPUs0lC4wN3ipwbjo8E5HJPEKNzN96/k1nW3zX xOnOgFzVrCIBDmWifhrSa275klAFjhrrr1rdvOIVUtchWxkXNJjHTZ/kYIeuRSV7+we/S6 pTGI8dAVhf/NCt5QOa8wmiT4gynZqjpZt099IuGMnAqaDyQVop7+GMcHYfclCR0uKfxkn6 nVI3s3ccEbvEa30aOoSfJ57Ot74VM1Va/EMqyuMZ7nQlnB/+IsLk67epqwG6lA== 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 D640C15748; Fri, 14 Jan 2022 14:20:36 +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 20EEKaeH087808; Fri, 14 Jan 2022 14:20:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20EEKacN087794; Fri, 14 Jan 2022 14:20:36 GMT (envelope-from git) Date: Fri, 14 Jan 2022 14:20:36 GMT Message-Id: <202201141420.20EEKacN087794@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Emmanuel Vadot Subject: git: 99cc129ea469 - stable/13 - bhyve: ignore low bits of CFGADR 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: manu X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 99cc129ea469c59ce75df17cc78eee6dceaca46c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642170037; 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=Jo06Gchd1cyFaNWmtiSaYSysbeNG/8kP8YrZ0hyp40g=; b=LzMhHJmU/Bo7LfjBm4OKxWaYopX9SWPP4ZQ1bRovQzMNPQqleQasjhbeya+/+PgdjGk3a8 FG/h5SShFtZs+QpBYPHOp3YmlBLhqS6ZpDynw696oOYpJ/Vt9hE1PfcqtR0WoRUE8Ok3eu btvswguP4I4W1WVCMkd6UVwvOFmPax2pgk0o7sm1H3Jcsa7TsdW66dNgkFtZhksDsi9O27 NMZDaQwEgHCOoxmvPeOvjpVQNhgichE1DpS6YKhvP6vDNSdzNFNyB9KaPyJCuGmLFYdt/J bCD5VoWoLc5N5PE//4SPXIJDslzUskLexuW6i3vtQSOTkdsuV0rmutEdiFbfzw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642170037; a=rsa-sha256; cv=none; b=TNgOKliMVJ0w8/QycyS7TMb0HYICuIOfBY/wh/DKfn3x3eo/XzLIpXmzlapZfYfo+bLqq4 46OnfQ7IsWjq/9sCXwPGWvG+lo8Sv240b1bSnHJvmH12QPAnmV72ERJlHTuXxYNnBztJtq 0MjYDt2lOD7PGuJhDELL6EnaLuxU9XdTitiYMGwBtJQRqQ2R9TBKyDnXAsKkkszOe4EM91 YqNT79R3DiDpkf42qqxXVAbGyct78kndgRZebdR28By1Sp65A9tk9/1GJLSk2t+ISHNVBm krDH+IxKHRo28Nxl5TPenN/bJchMKQczsHu49FYAI5WvmedOw8GmVMCUMNvKMQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=99cc129ea469c59ce75df17cc78eee6dceaca46c commit 99cc129ea469c59ce75df17cc78eee6dceaca46c Author: Corvin Köhne AuthorDate: 2021-10-15 07:25:54 +0000 Commit: Emmanuel Vadot CommitDate: 2022-01-14 13:51:44 +0000 bhyve: ignore low bits of CFGADR Bhyve could emulate wrong PCI registers. In the best case, the guest reads wrong registers and the device driver would report some errors. In the worst case, the guest writes to wrong PCI registers and could brick hardware when using PCI passthrough. According to Intels specification, low bits of CFGADR should be ignored. Some OS like linux may rely on it. Otherwise, bhyve could emulate a wrong PCI register. E.g. If linux would like to read 2 bytes from offset 0x02, following would happen. linux: outl 0x80000002 at CFGADR inw at CFGDAT + 2 bhyve: cfgoff = 0x80000002 & 0xFF = 0x02 coff = cfgoff + (port - CFGDAT) = 0x02 + 0x02 = 0x04 Bhyve would emulate the register at offset 0x04 not 0x02. Reviewed By: #bhyve, grehan Differential Revision: https://reviews.freebsd.org/D31819 Sponsored by: Beckhoff Automation GmbH & Co. KG (cherry picked from commit 1b0e2f0b607e88feb57accc9521e9623b56ab7e2) --- usr.sbin/bhyve/pci_emul.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c index d155029d269f..86a2f995126e 100644 --- a/usr.sbin/bhyve/pci_emul.c +++ b/usr.sbin/bhyve/pci_emul.c @@ -2018,7 +2018,7 @@ pci_emul_cfgaddr(struct vmctx *ctx, int vcpu, int in, int port, int bytes, } else { x = *eax; cfgenable = (x & CONF1_ENABLE) == CONF1_ENABLE; - cfgoff = x & PCI_REGMAX; + cfgoff = (x & PCI_REGMAX) & ~0x03; cfgfunc = (x >> 8) & PCI_FUNCMAX; cfgslot = (x >> 11) & PCI_SLOTMAX; cfgbus = (x >> 16) & PCI_BUSMAX;