Skip to content

Commit ad6c002

Browse files
willdeaconkonradwilk
authored andcommitted
swiotlb: Free tbl memory in swiotlb_exit()
Although swiotlb_exit() frees the 'slots' metadata array referenced by 'io_tlb_default_mem', it leaves the underlying buffer pages allocated despite no longer being usable. Extend swiotlb_exit() to free the buffer pages as well as the slots array. Cc: Claire Chang <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Robin Murphy <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Tested-by: Claire Chang <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
1 parent 1efd3fc commit ad6c002

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

kernel/dma/swiotlb.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,27 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
328328

329329
void __init swiotlb_exit(void)
330330
{
331-
size_t size;
332331
struct io_tlb_mem *mem = &io_tlb_default_mem;
332+
unsigned long tbl_vaddr;
333+
size_t tbl_size, slots_size;
333334

334335
if (!mem->nslabs)
335336
return;
336337

337338
pr_info("tearing down default memory pool\n");
338-
size = array_size(sizeof(*mem->slots), mem->nslabs);
339-
if (mem->late_alloc)
340-
free_pages((unsigned long)mem->slots, get_order(size));
341-
else
342-
memblock_free_late(__pa(mem->slots), PAGE_ALIGN(size));
339+
tbl_vaddr = (unsigned long)phys_to_virt(mem->start);
340+
tbl_size = PAGE_ALIGN(mem->end - mem->start);
341+
slots_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), mem->nslabs));
342+
343+
set_memory_encrypted(tbl_vaddr, tbl_size >> PAGE_SHIFT);
344+
if (mem->late_alloc) {
345+
free_pages(tbl_vaddr, get_order(tbl_size));
346+
free_pages((unsigned long)mem->slots, get_order(slots_size));
347+
} else {
348+
memblock_free_late(mem->start, tbl_size);
349+
memblock_free_late(__pa(mem->slots), slots_size);
350+
}
351+
343352
memset(mem, 0, sizeof(*mem));
344353
}
345354

0 commit comments

Comments
 (0)