Linux IOMMU Development
 help / color / mirror / Atom feed
From: Mario Limonciello via iommu <iommu@lists.linux-foundation.org>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>
Cc: Hegde Vasant <Vasant.Hegde@amd.com>,
	open list <linux-kernel@vger.kernel.org>,
	Christoph Hellwig <hch@infradead.org>,
	"open list:IOMMU DRIVERS" <iommu@lists.linux-foundation.org>,
	Mario Limonciello <mario.limonciello@amd.com>,
	Robin Murphy <robin.murphy@arm.com>
Subject: [PATCH 1/2] swiotlb: Check that slabs have been allocated when requested
Date: Mon, 4 Apr 2022 11:47:06 -0500	[thread overview]
Message-ID: <20220404164707.1128-2-mario.limonciello@amd.com> (raw)
In-Reply-To: <20220404164707.1128-1-mario.limonciello@amd.com>

If the IOMMU is in use and an untrusted device is connected to an external
facing port but the address requested isn't page aligned will cause the
kernel to attempt to use bounce buffers.

If the bounce buffers have not been allocated however, this leads
to messages like this:

swiotlb buffer is full (sz: 4096 bytes), total 0 (slots), used 0 (slots)

Clarify the error message because the buffer isn't full, it doesn't
exist!

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 kernel/dma/swiotlb.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 73a41cec9e38..d2a20cedf0d2 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -591,6 +591,11 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
 	if (!mem)
 		panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer");
 
+	if (!mem->nslabs) {
+		dev_warn_once(dev, "No slabs have been configured, unable to use SWIOTLB buffer");
+		return (phys_addr_t)DMA_MAPPING_ERROR;
+	}
+
 	if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
 		pr_warn_once("Memory encryption is active and system is using DMA bounce buffers\n");
 
-- 
2.34.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2022-04-04 16:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 16:47 [PATCH 0/2] Fix issues with untrusted devices and AMD IOMMU Mario Limonciello via iommu
2022-04-04 16:47 ` Mario Limonciello via iommu [this message]
2022-04-04 16:47 ` [PATCH 2/2] iommu: Don't use swiotlb unless it's active Mario Limonciello via iommu
2022-04-04 16:54 ` [PATCH 0/2] Fix issues with untrusted devices and AMD IOMMU Christoph Hellwig
2022-04-04 17:05   ` Limonciello, Mario via iommu
2022-04-04 17:24     ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220404164707.1128-2-mario.limonciello@amd.com \
    --to=iommu@lists.linux-foundation.org \
    --cc=Vasant.Hegde@amd.com \
    --cc=hch@infradead.org \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox