From nobody Sat Aug 22 00:26:31 2026 X-Original-To: dev-commits-src-branches@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 4hRdJl71Blz6pq1Y for ; Sat, 22 Aug 2026 00:26:31 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hRdJl4dTPz3DDv for ; Sat, 22 Aug 2026 00:26:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787358391; 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=vUJoG39tyS2DMjhREKRh5rB6kCk1HtB9oBkWDNbk7Xw=; b=kBpIqFrHRKHSLXsf5pjGiQNMfLaHicx2rNaPh0GPQHLorx8ueU8ESIwGM78EzG1jZ3HbE+ aELXvqOFCilYfU4VkNxlCafa9ivbnoIk4xiSp8z9W7MHYlb1r3kj8Cdmdn/abyvyTQgWpU Y0SksLZBUcinivI8LRuM/EqrkSeOYucbUhg3fh+ws8LhJy4pvOqqbsTy9X/jZEYf8XeL1x sikF6jsrWcEqB484vh36yNs8KwYxObM/lQnGAgu+1+RfCg8ohoNCHnAhKWjlAxYo+pLFlH TM9rgByBpwfuz/HqYfBcwLDoIILf3K0LLl0WRAuj03KoE+cPjF8hV6t6Yr7qQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787358391; a=rsa-sha256; cv=none; b=slt8erLF8Uh3FSInWljchct4rYnP41bG+XFhOzuTItspuC1HGwAPhSxrPtVfP4ed5pY0Fr OofbRXfLWpjeSL3LybSaQphfZAaPjScbUaDrl3xuHjXZhxw2MRre35eG/Lb062d5uod/HD hPUhtQpN97DFC4lWVKdSzb2pdDPcoTm+lDYSgMwgjGU7CRbiCg46UWi23lU1Rd/OTk4omQ dT9ZXnZI3gfAIHj3hLHMF55C4/IkEgN+A5fbDEFuGRv6dApKbnaRWHg9i31i8nyYi86hU9 51hymtWZ88e5cj+xlumJW95Xyl7JOXkMxfEsHWjeQNhaCz0QFs/BDftp5W+J7w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787358391; 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=vUJoG39tyS2DMjhREKRh5rB6kCk1HtB9oBkWDNbk7Xw=; b=oMnvW25YgpRqI4f78PD/cQc/0s653vrEUwmmhW4kHi/5RzvTOHZyP3FBSWASWuRis2bttu qTw+Wqgh8SNfumfimzvkLeXx3CpuVweBMHLx9tCrfgGNfop+Q41fdYrNTsmtJfyNH9lyZv KoNtPKpveI7Or9hDMsFBUYxW1sGF81dN+dAPRg/G9e+xWVpk9qvSOjMw10ZUcRO0aC5UpK PM/NAN85BC2g2Xfi8RVKqsHS/640VL6prPgsur+bHv74zonQp+onmF2M3Kbqbb4qi22ZCF rqhC+v1QTnrCUJnuZRqOZpy1UUE7qDOEt0+Pd2R+4r9BZvk3meO+Pf+ws6xnRA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hRdJl2bk7zB5F for ; Sat, 22 Aug 2026 00:26:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 24083 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 22 Aug 2026 00:26:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: e234bdff9874 - stable/15 - vmm: Tear down the IOMMU before AMD-Vi detach List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: e234bdff9874b8fbe54858acae015af9d5eb8164 Auto-Submitted: auto-generated Date: Sat, 22 Aug 2026 00:26:31 +0000 Message-Id: <6a88ecb7.24083.2252cefa@gitrepo.freebsd.org> The branch stable/15 has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=e234bdff9874b8fbe54858acae015af9d5eb8164 commit e234bdff9874b8fbe54858acae015af9d5eb8164 Author: Kevin Bowling AuthorDate: 2026-08-06 11:06:00 +0000 Commit: Kevin Bowling CommitDate: 2026-08-22 00:26:22 +0000 vmm: Tear down the IOMMU before AMD-Vi detach Register the vmm module handler after both the bundled device drivers and SMP. On platforms without EARLY_AP_STARTUP, SI_SUB_SMP follows SI_SUB_DRIVERS; using the later subsystem preserves the smp_rendezvous() requirement. The resulting reverse unload order performs IOMMU cleanup while every IVHD softc remains valid. Refuse an independent IVHD detach while translation state remains initialized. (cherry picked from commit 42d54a8fd4665b97f56f91f450e310c61d4aee2c) --- sys/amd64/vmm/amd/ivrs_drv.c | 14 +++++++++----- sys/amd64/vmm/io/iommu.c | 12 ++++++++++-- sys/amd64/vmm/io/iommu.h | 1 + sys/dev/vmm/vmm_dev.c | 10 ++++++++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/sys/amd64/vmm/amd/ivrs_drv.c b/sys/amd64/vmm/amd/ivrs_drv.c index c75e0fcc2d68..bbe45230b1a1 100644 --- a/sys/amd64/vmm/amd/ivrs_drv.c +++ b/sys/amd64/vmm/amd/ivrs_drv.c @@ -711,15 +711,19 @@ ivhd_detach(device_t dev) { struct amdvi_softc *softc; + /* + * amdvi_disable() and domain teardown require every IVHD softc. The + * vmm module handler normally performs that cleanup before the IVHD + * driver is unloaded. Refuse an out-of-order detach rather than leave + * enabled translation hardware referring to resources freed below. + */ + if (iommu_is_initialized()) + return (EBUSY); + softc = device_get_softc(dev); amdvi_teardown_hw(softc); free(softc->dev_cfg, M_DEVBUF); - - /* - * XXX: delete the device. - * don't allow detach, return EBUSY. - */ return (0); } diff --git a/sys/amd64/vmm/io/iommu.c b/sys/amd64/vmm/io/iommu.c index 9fc612244699..71d3cb9ab883 100644 --- a/sys/amd64/vmm/io/iommu.c +++ b/sys/amd64/vmm/io/iommu.c @@ -194,7 +194,7 @@ iommu_init(void) if (error) return; - iommu_avail = 1; + atomic_store_rel_int(&iommu_avail, 1); /* * Create a domain for the devices owned by the host @@ -205,7 +205,7 @@ iommu_init(void) printf("iommu_init: unable to create a host domain"); IOMMU_CLEANUP(); ops = NULL; - iommu_avail = 0; + atomic_store_rel_int(&iommu_avail, 0); return; } @@ -268,6 +268,7 @@ iommu_cleanup_int(bool iommu_disable) IOMMU_DESTROY_DOMAIN(host_domain); host_domain = NULL; IOMMU_CLEANUP(); + atomic_store_rel_int(&iommu_avail, 0); } void @@ -276,6 +277,13 @@ iommu_cleanup(void) iommu_cleanup_int(true); } +bool +iommu_is_initialized(void) +{ + + return (atomic_load_acq_int(&iommu_avail) != 0); +} + void * iommu_create_domain(vm_paddr_t maxaddr) { diff --git a/sys/amd64/vmm/io/iommu.h b/sys/amd64/vmm/io/iommu.h index 5294a9d92a6b..3224b4884e9a 100644 --- a/sys/amd64/vmm/io/iommu.h +++ b/sys/amd64/vmm/io/iommu.h @@ -62,6 +62,7 @@ extern const struct iommu_ops iommu_ops_intel; extern const struct iommu_ops iommu_ops_amd; void iommu_cleanup(void); +bool iommu_is_initialized(void); void *iommu_host_domain(void); void *iommu_create_domain(vm_paddr_t maxaddr); void iommu_destroy_domain(void *dom); diff --git a/sys/dev/vmm/vmm_dev.c b/sys/dev/vmm/vmm_dev.c index 302a73be25b8..c7900df57eeb 100644 --- a/sys/dev/vmm/vmm_dev.c +++ b/sys/dev/vmm/vmm_dev.c @@ -1189,9 +1189,15 @@ static moduledata_t vmm_kmod = { * * - Initialization requires smp_rendezvous() and therefore must happen * after SMP is fully functional (after SI_SUB_SMP). - * - vmm device initialization requires an initialized devfs. + * - vmm device initialization requires an initialized devfs + * (SI_SUB_DRIVERS is after SI_SUB_DEVFS). + * - On amd64, vmm.ko also contains device drivers such as ppt and AMD-Vi/IVHD. + * Load this module handler after SI_SUB_DRIVERS so reverse-order unload runs + * iommu_cleanup() before those drivers detach. AMD-Vi disable still needs + * the IVHD softcs, and ivhd_detach() refuses while the IOMMU is initialized. */ -DECLARE_MODULE(vmm, vmm_kmod, MAX(SI_SUB_SMP, SI_SUB_DEVFS) + 1, SI_ORDER_ANY); +DECLARE_MODULE(vmm, vmm_kmod, MAX(SI_SUB_DRIVERS, SI_SUB_SMP) + 1, + SI_ORDER_ANY); MODULE_VERSION(vmm, 1); static int