History

swiotlb: fix a braino in the alignment check fix

The alignment mask in swiotlb_do_find_slots() masks off the high bits which are not relevant for the alignment, so multiple requirements are combined with a bitwise OR rather than AND. In plain English, the stricter the alignment, the more bits must be set in iotlb_align_mask. Confusion may arise from the fact that the same variable is also used to mask off the offset within a swiotlb slot, which is achieved with a bitwise AND.

Petr Tesarik committed 3 years ago

Commit bbb73a11 parent 0eee5ae1 file · +3 −3Browse files

Unified · Split

kernel/dma/swiotlb.c+3−3
@@ -623,7 +623,7 @@ static int swiotlb_do_find_slots(struct device *dev, int area_index, · 622 unmodified lines
623 phys_to_dma_unencrypted(dev, mem->start) & boundary_mask;623 phys_to_dma_unencrypted(dev, mem->start) & boundary_mask;
624 unsigned long max_slots = get_max_slots(boundary_mask);624 unsigned long max_slots = get_max_slots(boundary_mask);
625 unsigned int iotlb_align_mask =625 unsigned int iotlb_align_mask =
626 dma_get_min_align_mask(dev) & ~(IO_TLB_SIZE - 1);626 dma_get_min_align_mask(dev) | alloc_align_mask;
627 unsigned int nslots = nr_slots(alloc_size), stride;627 unsigned int nslots = nr_slots(alloc_size), stride;
628 unsigned int offset = swiotlb_align_offset(dev, orig_addr);628 unsigned int offset = swiotlb_align_offset(dev, orig_addr);
629 unsigned int index, slots_checked, count = 0, i;629 unsigned int index, slots_checked, count = 0, i;
@@ -639,8 +639,8 @@ static int swiotlb_do_find_slots(struct device *dev, int area_index, · 9 unmodified lines
639 * allocations.639 * allocations.
640 */640 */
641 if (alloc_size >= PAGE_SIZE)641 if (alloc_size >= PAGE_SIZE)
642 iotlb_align_mask &= PAGE_MASK;642 iotlb_align_mask |= ~PAGE_MASK;
643 iotlb_align_mask &= alloc_align_mask;643 iotlb_align_mask &= ~(IO_TLB_SIZE - 1);
644 644
645 /*645 /*
646 * For mappings with an alignment requirement don't bother looping to646 * For mappings with an alignment requirement don't bother looping to

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t