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, Robin Murphy <robin.murphy@arm.com>,
Fabio Estevam <festevam@denx.de>
Subject: [PATCH 2/3] swiotlb: Reinstate page-alignment for mappings >= PAGE_SIZE
Date: Mon, 17 Jun 2024 11:23:14 -0300 [thread overview]
Message-ID: <20240617142315.2656683-3-festevam@gmail.com> (raw)
In-Reply-To: <20240617142315.2656683-1-festevam@gmail.com>
From: Will Deacon <will@kernel.org>
commit 14cebf689a78e8a1c041138af221ef6eac6bc7da upstream.
For swiotlb allocations >= PAGE_SIZE, the slab search historically
adjusted the stride to avoid checking unaligned slots. This had the
side-effect of aligning large mapping requests to PAGE_SIZE, but that
was broken by 0eee5ae10256 ("swiotlb: fix slot alignment checks").
Since this alignment could be relied upon drivers, reinstate PAGE_SIZE
alignment for swiotlb mappings >= PAGE_SIZE.
Cc: stable@vger.kernel.org # v6.6+
Reported-by: Michael Kelley <mhklinux@outlook.com>
Signed-off-by: Will Deacon <will@kernel.org>
Reviewed-by: Robin Murphy <robin.murphy@arm.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 | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 4c10700c61d2..0dc3ec199fe4 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -992,6 +992,17 @@ static int swiotlb_area_find_slots(struct device *dev, struct io_tlb_pool *pool,
BUG_ON(!nslots);
BUG_ON(area_index >= pool->nareas);
+ /*
+ * Historically, swiotlb allocations >= PAGE_SIZE were guaranteed to be
+ * page-aligned in the absence of any other alignment requirements.
+ * 'alloc_align_mask' was later introduced to specify the alignment
+ * explicitly, however this is passed as zero for streaming mappings
+ * and so we preserve the old behaviour there in case any drivers are
+ * relying on it.
+ */
+ if (!alloc_align_mask && !iotlb_align_mask && alloc_size >= PAGE_SIZE)
+ alloc_align_mask = PAGE_SIZE - 1;
+
/*
* Ensure that the allocation is at least slot-aligned and update
* 'iotlb_align_mask' to ignore bits that will be preserved when
@@ -1006,13 +1017,6 @@ static int swiotlb_area_find_slots(struct device *dev, struct io_tlb_pool *pool,
*/
stride = get_max_slots(max(alloc_align_mask, iotlb_align_mask));
- /*
- * For allocations of PAGE_SIZE or larger only look for page aligned
- * allocations.
- */
- if (alloc_size >= PAGE_SIZE)
- stride = umax(stride, PAGE_SHIFT - IO_TLB_SHIFT + 1);
-
spin_lock_irqsave(&area->lock, flags);
if (unlikely(nslots > pool->area_nslabs - area->used))
goto not_found;
--
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 ` [PATCH 1/3] swiotlb: Enforce page alignment in swiotlb_alloc() Fabio Estevam
2024-06-17 14:23 ` Fabio Estevam [this message]
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-3-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=robin.murphy@arm.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