From: Fabio Estevam <festevam@gmail.com>
To: stable@vger.kernel.org
Cc: will@kernel.org, mhklinux@outlook.com,
petr.tesarik1@huawei-partners.com, nicolinc@nvidia.com,
hch@lst.de, Fabio Estevam <festevam@denx.de>
Subject: [PATCH 1/3] swiotlb: Enforce page alignment in swiotlb_alloc()
Date: Mon, 17 Jun 2024 11:23:13 -0300 [thread overview]
Message-ID: <20240617142315.2656683-2-festevam@gmail.com> (raw)
In-Reply-To: <20240617142315.2656683-1-festevam@gmail.com>
From: Will Deacon <will@kernel.org>
commit 823353b7cf0ea9dfb09f5181d5fb2825d727200b upstream.
When allocating pages from a restricted DMA pool in swiotlb_alloc(),
the buffer address is blindly converted to a 'struct page *' that is
returned to the caller. In the unlikely event of an allocation bug,
page-unaligned addresses are not detected and slots can silently be
double-allocated.
Add a simple check of the buffer alignment in swiotlb_alloc() to make
debugging a little easier if something has gone wonky.
Cc: stable@vger.kernel.org # v6.6+
Signed-off-by: Will Deacon <will@kernel.org>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Reviewed-by: Petr Tesarik <petr.tesarik1@huawei-partners.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Tested-by: Michael Kelley <mhklinux@outlook.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Fabio Estevam <festevam@denx.de>
---
kernel/dma/swiotlb.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index a7d5fb473b32..4c10700c61d2 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -1627,6 +1627,12 @@ struct page *swiotlb_alloc(struct device *dev, size_t size)
return NULL;
tlb_addr = slot_addr(pool->start, index);
+ if (unlikely(!PAGE_ALIGNED(tlb_addr))) {
+ dev_WARN_ONCE(dev, 1, "Cannot allocate pages from non page-aligned swiotlb addr 0x%pa.\n",
+ &tlb_addr);
+ swiotlb_release_slots(dev, tlb_addr);
+ return NULL;
+ }
return pfn_to_page(PFN_DOWN(tlb_addr));
}
--
2.34.1
next prev parent reply other threads:[~2024-06-17 14:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-17 14:23 [PATCH 0/3] swiotlb: Backport to linux-stable 6.6 Fabio Estevam
2024-06-17 14:23 ` Fabio Estevam [this message]
2024-06-17 14:23 ` [PATCH 2/3] swiotlb: Reinstate page-alignment for mappings >= PAGE_SIZE Fabio Estevam
2024-06-17 14:23 ` [PATCH 3/3] swiotlb: extend buffer pre-padding to alloc_align_mask if necessary Fabio Estevam
2024-06-18 6:47 ` [PATCH 0/3] swiotlb: Backport to linux-stable 6.6 Christoph Hellwig
2024-06-19 8:46 ` Greg KH
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=20240617142315.2656683-2-festevam@gmail.com \
--to=festevam@gmail.com \
--cc=festevam@denx.de \
--cc=hch@lst.de \
--cc=mhklinux@outlook.com \
--cc=nicolinc@nvidia.com \
--cc=petr.tesarik1@huawei-partners.com \
--cc=stable@vger.kernel.org \
--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