Skip to content

Commit

Permalink
swiotlb: lift the double initialization protection from xen-swiotlb
Browse files Browse the repository at this point in the history
Lift the double initialization protection from xen-swiotlb to the core
code to avoid exposing too many swiotlb internals.  Also upgrade the
check to a warning as it should not happen.

Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
  • Loading branch information
Christoph Hellwig authored and konradwilk committed Mar 17, 2021
1 parent cbce995 commit 5d0538b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 0 additions & 7 deletions drivers/xen/swiotlb-xen.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@ int __ref xen_swiotlb_init(int verbose, bool early)
bytes = nslabs << IO_TLB_SHIFT;
order = get_order(bytes);

/*
* IO TLB memory already allocated. Just use it.
*/
if (io_tlb_start != 0)
goto end;

/*
* Get IO TLB memory from any location.
*/
Expand Down Expand Up @@ -232,7 +226,6 @@ int __ref xen_swiotlb_init(int verbose, bool early)
} else
rc = swiotlb_late_init_with_tbl(start, nslabs);

end:
if (!rc)
swiotlb_set_max_segment(PAGE_SIZE);

Expand Down
8 changes: 8 additions & 0 deletions kernel/dma/swiotlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
unsigned long i, bytes;
size_t alloc_size;

/* protect against double initialization */
if (WARN_ON_ONCE(io_tlb_start))
return -ENOMEM;

bytes = nslabs << IO_TLB_SHIFT;

io_tlb_nslabs = nslabs;
Expand Down Expand Up @@ -367,6 +371,10 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
{
unsigned long i, bytes;

/* protect against double initialization */
if (WARN_ON_ONCE(io_tlb_start))
return -ENOMEM;

bytes = nslabs << IO_TLB_SHIFT;

io_tlb_nslabs = nslabs;
Expand Down

0 comments on commit 5d0538b

Please sign in to comment.