From nobody Fri Oct 29 08:31:39 2021
X-Original-To: dev-commits-src-main@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 85CDD1826847;
	Fri, 29 Oct 2021 08:31:39 +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 4HgbHv3MjSz4SpZ;
	Fri, 29 Oct 2021 08:31:39 +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 53F831401A;
	Fri, 29 Oct 2021 08:31:39 +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 19T8Vdil073735;
	Fri, 29 Oct 2021 08:31:39 GMT
	(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
	by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19T8Vdcl073734;
	Fri, 29 Oct 2021 08:31:39 GMT
	(envelope-from git)
Date: Fri, 29 Oct 2021 08:31:39 GMT
Message-Id: <202110290831.19T8Vdcl073734@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
        dev-commits-src-main@FreeBSD.org
From: Wojciech Macek <wma@FreeBSD.org>
Subject: git: 3c02da8096b1 - main - dmar: Don't try to reserve PCI regions for non-existing devices
List-Id: Commit messages for the main branch of the src repository <dev-commits-src-main.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main
List-Help: <mailto:dev-commits-src-main+help@freebsd.org>
List-Post: <mailto:dev-commits-src-main@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-main+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-main+unsubscribe@freebsd.org>
Sender: owner-dev-commits-src-main@freebsd.org
X-BeenThere: dev-commits-src-main@freebsd.org
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: wma
X-Git-Repository: src
X-Git-Refname: refs/heads/main
X-Git-Reftype: branch
X-Git-Commit: 3c02da8096b142ef243da8da667c3a5a7d591105
Auto-Submitted: auto-generated
X-ThisMailContainsUnwantedMimeParts: N

The branch main has been updated by wma:

URL: https://cgit.FreeBSD.org/src/commit/?id=3c02da8096b142ef243da8da667c3a5a7d591105

commit 3c02da8096b142ef243da8da667c3a5a7d591105
Author:     Kornel Duleba <mindal@semihalf.com>
AuthorDate: 2021-10-21 12:46:51 +0000
Commit:     Wojciech Macek <wma@FreeBSD.org>
CommitDate: 2021-10-29 08:08:25 +0000

    dmar: Don't try to reserve PCI regions for non-existing devices
    
    In some cases we might have to create DMAR context before the
    corresponding device has been enumerated by the PCI bus.
    In that case we get called with NULL dev, because of that trying
    to reserve PCI regions causes a NULL pointer dereference in
    pci_find_pcie_root_port.
    
    Sponsored by:           Stormshield
    Obtained from:          Semihalf
    MFC after:              2 weeks
    Reviewed by:            kib, rlibby
    Differential revision:  https://reviews.freebsd.org/D32589
---
 sys/x86/iommu/intel_ctx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/x86/iommu/intel_ctx.c b/sys/x86/iommu/intel_ctx.c
index 34730306000b..7aedbf159ac7 100644
--- a/sys/x86/iommu/intel_ctx.c
+++ b/sys/x86/iommu/intel_ctx.c
@@ -561,7 +561,7 @@ dmar_get_ctx_for_dev1(struct dmar_unit *dmar, device_t dev, uint16_t rid,
 			error = domain_init_rmrr(domain1, dev, bus,
 			    slot, func, dev_domain, dev_busno, dev_path,
 			    dev_path_len);
-			if (error == 0)
+			if (error == 0 && dev != NULL)
 				error = dmar_reserve_pci_regions(domain1, dev);
 			if (error != 0) {
 				dmar_domain_destroy(domain1);