Patch "swiotlb: fix slot alignment checks" has been added to the 6.2-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    swiotlb: fix slot alignment checks

to the 6.2-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     swiotlb-fix-slot-alignment-checks.patch
and it can be found in the queue-6.2 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 5b40da7a8b4802ef6cf63b3c2ed19fb62f374878
Author: Petr Tesarik <petr.tesarik.ext@xxxxxxxxxx>
Date:   Tue Mar 21 09:31:27 2023 +0100

    swiotlb: fix slot alignment checks
    
    [ Upstream commit 0eee5ae1025699ea93d44fdb6ef2365505082103 ]
    
    Explicit alignment and page alignment are used only to calculate
    the stride, not when checking actual slot physical address.
    
    Originally, only page alignment was implemented, and that worked,
    because the whole SWIOTLB is allocated on a page boundary, so
    aligning the start index was sufficient to ensure a page-aligned
    slot.
    
    When commit 1f221a0d0dbf ("swiotlb: respect min_align_mask") added
    support for min_align_mask, the index could be incremented in the
    search loop, potentially finding an unaligned slot if minimum device
    alignment is between IO_TLB_SIZE and PAGE_SIZE.  The bug could go
    unnoticed, because the slot size is 2 KiB, and the most common page
    size is 4 KiB, so there is no alignment value in between.
    
    IIUC the intention has been to find a slot that conforms to all
    alignment constraints: device minimum alignment, an explicit
    alignment (given as function parameter) and optionally page
    alignment (if allocation size is >= PAGE_SIZE). The most
    restrictive mask can be trivially computed with logical AND. The
    rest can stay.
    
    Fixes: 1f221a0d0dbf ("swiotlb: respect min_align_mask")
    Fixes: e81e99bacc9f ("swiotlb: Support aligned swiotlb buffers")
    Signed-off-by: Petr Tesarik <petr.tesarik.ext@xxxxxxxxxx>
    Signed-off-by: Christoph Hellwig <hch@xxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 869dd6667c464..312458506e6d5 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -642,22 +642,26 @@ static int swiotlb_do_find_slots(struct device *dev, int area_index,
 	BUG_ON(!nslots);
 	BUG_ON(area_index >= mem->nareas);
 
+	/*
+	 * For allocations of PAGE_SIZE or larger only look for page aligned
+	 * allocations.
+	 */
+	if (alloc_size >= PAGE_SIZE)
+		iotlb_align_mask &= PAGE_MASK;
+	iotlb_align_mask &= alloc_align_mask;
+
 	/*
 	 * For mappings with an alignment requirement don't bother looping to
-	 * unaligned slots once we found an aligned one.  For allocations of
-	 * PAGE_SIZE or larger only look for page aligned allocations.
+	 * unaligned slots once we found an aligned one.
 	 */
 	stride = (iotlb_align_mask >> IO_TLB_SHIFT) + 1;
-	if (alloc_size >= PAGE_SIZE)
-		stride = max(stride, stride << (PAGE_SHIFT - IO_TLB_SHIFT));
-	stride = max(stride, (alloc_align_mask >> IO_TLB_SHIFT) + 1);
 
 	spin_lock_irqsave(&area->lock, flags);
 	if (unlikely(nslots > mem->area_nslabs - area->used))
 		goto not_found;
 
 	slot_base = area_index * mem->area_nslabs;
-	index = wrap_area_index(mem, ALIGN(area->index, stride));
+	index = area->index;
 
 	for (slots_checked = 0; slots_checked < mem->area_nslabs; ) {
 		slot_index = slot_base + index;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux