From nobody Mon Nov 03 05:31:46 2025 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 4d0Kvl3DpDz6GLfG; Mon, 03 Nov 2025 05:31:47 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d0Kvl0hjNz3SDD; Mon, 03 Nov 2025 05:31:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762147907; 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=krctFDPbJm3Yxb6e+1uGlL+NUUhdYFENlLuebdx3jbs=; b=P/avO0CXkGuTWKbzh9yyG3IIegGReqh7UZgulS5z2oS+7pDgHylxLSnsnft4GZMeaviE5x 9IunxJcJErhozOkTSeqLDR2JF5JRCp92LRJpxYZA6EfT3+NqnpbtqxMY1Pq6DmIj5oiT7O J2dlGC+yb36P8lbGwYXjuklUS7HzCGngsEZmab8hHgHXD3DCoaB0Qug1pmJdVKa8nLn0qg /HCl4oXxG8W0ecjosZgXGe7dSri4N4oaDU78imxuc/7F8a29khPyKYot5d7Xj66D5gYlFl VXr4eF/1GsYu+uLfJMTfteDqgfFg3knZyNTQzTSm+MM/RPdX8zlhc0u9lPEaGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762147907; 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=krctFDPbJm3Yxb6e+1uGlL+NUUhdYFENlLuebdx3jbs=; b=ROToUx8OR21xx5N0eb6A246RYOkS+DrxqzsFZAhgF5ngXQejkFwtfi2TzF1F7Z1ei4oArz fJxmZg1a8hA592iv/g5ZpkZZTui5F0rP+iyfDIWNSHcIpqx9IzYVU0Ri9yfbmhmJfRV8U5 SJ24miIZo0j8U6QeLTkT1EskW33hQeyEp2qYjZnGDn1th+OYflw2IcEXtSwY8+jueuIY8+ AhrWYkiqIsySZxebJKuc5Y4ksbL6bEcJqL3HSc2j1BMMf55dikBT/p0iwqnO8bF8hQEku4 HPWtTQa6BpaZcgNbilP+hBwQa/efX/SNKy8KLPK7hvogyZifevzquCYyzyNVbg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1762147907; a=rsa-sha256; cv=none; b=D17UCG7emSZqH5fT0M2WGM2pkL79mbp7AjDBQt6KbO2QGXSePrgXX56qvvKu9KWfzxeyVg b3nNKeUFbfKcI1mAP10DKd016kI7KyXrzJCa/f+Soc1nMIbFTmL7fVTT3wV3cwFy7M3Kbo wm5U65eCP12dcZ1XJpO4CJE7+lzn10gThLu9Pm2UaHHTIh4aFvefWJggaketja3M/CTePU zsXquPTS4LrQRPx5BEaQ4xfmSbd2CaPrflvkKRL3eEq3zG7Kcme/it+rVHmu66H7dW4x6l +8ydxHPnuM2D8u2pqd14TjRcMrUhJBSyXdu6FHDQw7tP1q4FdhPCcyCRZN8P5A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4d0Kvk72G5zy9P; Mon, 03 Nov 2025 05:31:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5A35VkZk071205; Mon, 3 Nov 2025 05:31:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5A35VkcQ071202; Mon, 3 Nov 2025 05:31:46 GMT (envelope-from git) Date: Mon, 3 Nov 2025 05:31:46 GMT Message-Id: <202511030531.5A35VkcQ071202@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Jason A. Harmening" Subject: git: b67bcababa9d - stable/15 - AMD IOMMU: fix per-device IOMMU bypass when IR is enabled 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jah X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: b67bcababa9dbbe567548ef0fa300a151837d8fe Auto-Submitted: auto-generated The branch stable/15 has been updated by jah: URL: https://cgit.FreeBSD.org/src/commit/?id=b67bcababa9dbbe567548ef0fa300a151837d8fe commit b67bcababa9dbbe567548ef0fa300a151837d8fe Author: Jason A. Harmening AuthorDate: 2025-10-20 01:53:08 +0000 Commit: Jason A. Harmening CommitDate: 2025-11-03 04:34:28 +0000 AMD IOMMU: fix per-device IOMMU bypass when IR is enabled When interrupt remapping (IR) is enabled, the device table entry (DTE) for a given device will likely be initialized by amdiommu_ir_find() during MSI configuration. This function directly calls amdiommu_get_ctx_for_dev() with id_mapped=false, which means that any attempt to disable DMA remapping for the device (e.g. by setting hw.busdma.pciD.B.S.F='bounce' in the loader tunables) will effectively be ignored as the paging mode field in the DTE will not be set to 0 as required for identity mapping. This will ultimately produce an unusable device, because busdma will later observe the bounce configuration through iommu_instantiate_ctx() and will employ the non-translated 'bounce' busdma methods for the device, while the DTE remains configured to enable translation. Fix this by tweaking iommu_instantiate_ctx() to always return the relevant per-device context object even if translation is disabled, and adopt it in amdiommu_ir_find() instead of directly calling amdiommu_get_ctx_for_dev(). Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D53209 (cherry picked from commit 35170408a7b86a879d7e2ffb5ddb70fe75951d89) --- sys/dev/iommu/busdma_iommu.c | 7 +++++-- sys/x86/iommu/amd_intrmap.c | 9 ++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c index 668ccf056463..82f73d469585 100644 --- a/sys/dev/iommu/busdma_iommu.c +++ b/sys/dev/iommu/busdma_iommu.c @@ -295,7 +295,6 @@ iommu_instantiate_ctx(struct iommu_unit *unit, device_t dev, bool rmrr) } else { iommu_free_ctx_locked(unit, ctx); } - ctx = NULL; } return (ctx); } @@ -303,6 +302,7 @@ iommu_instantiate_ctx(struct iommu_unit *unit, device_t dev, bool rmrr) struct iommu_ctx * iommu_get_dev_ctx(device_t dev) { + struct iommu_ctx *ctx; struct iommu_unit *unit; unit = iommu_find(dev, bootverbose); @@ -313,7 +313,10 @@ iommu_get_dev_ctx(device_t dev) return (NULL); iommu_unit_pre_instantiate_ctx(unit); - return (iommu_instantiate_ctx(unit, dev, false)); + ctx = iommu_instantiate_ctx(unit, dev, false); + if (ctx != NULL && (ctx->flags & IOMMU_CTX_DISABLED) != 0) + ctx = NULL; + return (ctx); } bus_dma_tag_t diff --git a/sys/x86/iommu/amd_intrmap.c b/sys/x86/iommu/amd_intrmap.c index f8900fe0561f..cce4f57ca323 100644 --- a/sys/x86/iommu/amd_intrmap.c +++ b/sys/x86/iommu/amd_intrmap.c @@ -223,9 +223,9 @@ static struct amdiommu_ctx * amdiommu_ir_find(device_t src, uint16_t *ridp, bool *is_iommu) { devclass_t src_class; - device_t requester; struct amdiommu_unit *unit; struct amdiommu_ctx *ctx; + struct iommu_ctx *ioctx; uint32_t edte; uint16_t rid; uint8_t dte; @@ -255,10 +255,9 @@ amdiommu_ir_find(device_t src, uint16_t *ridp, bool *is_iommu) error = amdiommu_find_unit(src, &unit, &rid, &dte, &edte, bootverbose); if (error == 0) { - error = iommu_get_requester(src, &requester, &rid); - MPASS(error == 0); - ctx = amdiommu_get_ctx_for_dev(unit, src, - rid, 0, false /* XXXKIB */, false, dte, edte); + ioctx = iommu_instantiate_ctx(AMD2IOMMU(unit), src, false); + if (ioctx != NULL) + ctx = IOCTX2CTX(ioctx); } } if (ridp != NULL)