Skip to content

Commit

Permalink
swiotlb: fix setting ->force_bounce
Browse files Browse the repository at this point in the history
The swiotlb_init refactor messed up assigning ->force_bounce by doing
it in different places based on what caused the setting of the flag.

Fix this by passing the SWIOTLB_* flags to swiotlb_init_io_tlb_mem
and just setting it there.

Fixes: c6af2aa ("swiotlb: make the swiotlb_init interface more useful")
Reported-by: Nathan Chancellor <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>
  • Loading branch information
Christoph Hellwig committed Jun 2, 2022
1 parent e19f8fa commit e15db62
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions kernel/dma/swiotlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void __init swiotlb_update_mem_attributes(void)
}

static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
unsigned long nslabs, bool late_alloc)
unsigned long nslabs, unsigned int flags, bool late_alloc)
{
void *vaddr = phys_to_virt(start);
unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
Expand All @@ -203,8 +203,7 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
mem->index = 0;
mem->late_alloc = late_alloc;

if (swiotlb_force_bounce)
mem->force_bounce = true;
mem->force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE);

spin_lock_init(&mem->lock);
for (i = 0; i < mem->nslabs; i++) {
Expand Down Expand Up @@ -275,8 +274,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
__func__, alloc_size, PAGE_SIZE);

swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false);
mem->force_bounce = flags & SWIOTLB_FORCE;
swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false);

if (flags & SWIOTLB_VERBOSE)
swiotlb_print_info();
Expand Down Expand Up @@ -348,7 +346,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,

set_memory_decrypted((unsigned long)vstart,
(nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, true);
swiotlb_init_io_tlb_mem(mem, virt_to_phys(vstart), nslabs, 0, true);

swiotlb_print_info();
return 0;
Expand Down Expand Up @@ -835,8 +833,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,

set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
rmem->size >> PAGE_SHIFT);
swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, false);
mem->force_bounce = true;
swiotlb_init_io_tlb_mem(mem, rmem->base, nslabs, SWIOTLB_FORCE,
false);
mem->for_alloc = true;

rmem->priv = mem;
Expand Down

0 comments on commit e15db62

Please sign in to comment.