From nobody Sat Aug 22 00:26:31 2026 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 4hRdJr70M6z6ppyW for ; Sat, 22 Aug 2026 00:26:36 +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 4hRdJr3vKhz3D03 for ; Sat, 22 Aug 2026 00:26:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787358396; 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=lUFe2ZKrdEjECBBR4TBt5MxMNlNveycNevLBv/wk0w7CRRcZOqcW89WUTRPln9ZfgaOFxA Qq1oy670FR05JZRLxbxuLDpI+0TJLfjC2rfXOUeiUN4sBiQr7RbLtzDWnr00elcNRHiAA1 xlw9m9L2BGZ0lg1+bqOgBK0qkPk+L3hRcdw0750sp7BPSukpO+KUaFJvLWQdm+v25TQ9DM DBGX4WVJsf8e4MqJ/0LBKeQb73KvV8F1niYNXzRsg6uf5gNY+jnU8Uv9oh+VWLroSBY3ra ZTcqre261pJMEVT5ag/bXhUtgHnzMn4NGUUtK1bnxasc1byNzg+eZ8DNMlpQOA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787358396; a=rsa-sha256; cv=none; b=HzPlWSm7vdl1y3tOH8rZFn+VJPifuqGRw6AzxEKoAZZjpiQ2sQRm0RIiKjzAyM9JZ5UnCP vz+cTMhoNVlgRaLLf70++pBlNfur+tcqfqI+mTSylyTXKbETRprgyB//iP1Q0WgqIONpb/ G9a2ldCVwLItH3EGTgpeWJszQjuS2qajO9kcSMdMy9e+Hbtwz2x/kN7Jsmy7voUf4QeLID Se+sVEZMDajfDO9omSy/XIJwgtG9x9VzjtrYlwL+Kh1ZIZmRMz9Xf4/OpQ54L7CWtFpqzL A7YEkyZYEIqaMes24ufEPoMFfQbotU9bP60QAP+EQlevXAvGcgPjr1Go98PM+A== 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=1787358396; 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=tpcaAx8eLhNFUjeTzN/52wu5dZdyqUq7LZVuC3dqoSKH3k0+MpXoFvJapFzp3o2D3bausU caGGSFvg3OS+dWvckcZWIyrKXD9Y0CoyXx+3wvyMTvZyo5IIB4qIhezIv8T0rE8BD+DAR5 Tf528AYpPNL5kQCubXVDFSgqxGhtgGEE41tuVGBRU6WmURI+lL24Rkrt0mlHp2G9tdMaHQ VIcZ26f49eAJlnK3LAkDh+O0/bpZraHLhhgGUUU/+2U66CE1KsAhASqUZ5kfVOFfJRk6qq SutblVOlo8yZz4wG/lW6s5DbBa+KryNoHGkvzdDQDLVbhD0PJDH85ED+9RXr1A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hRdJr2ZPYz9wm for ; Sat, 22 Aug 2026 00:26:36 +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: 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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