Skip to content

Commit

Permalink
swiotlb: ensure a segment doesn't cross the area boundary
Browse files Browse the repository at this point in the history
Free slots tracking assumes that slots in a segment can be allocated to
fulfill a request. This implies that slots in a segment should belong to
the same area. Although the possibility of a violation is low, it is better
to explicitly enforce segments won't span multiple areas by adjusting the
number of slabs when configuring areas.

Signed-off-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Chao Gao authored and Christoph Hellwig committed Jul 18, 2022
1 parent 4433548 commit 57e6840
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion kernel/dma/swiotlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,21 @@ struct io_tlb_area {
/*
* Round up number of slabs to the next power of 2. The last area is going
* be smaller than the rest if default_nslabs is not power of two.
* The number of slot in an area should be a multiple of IO_TLB_SEGSIZE,
* otherwise a segment may span two or more areas. It conflicts with free
* contiguous slots tracking: free slots are treated contiguous no matter
* whether they cross an area boundary.
*
* Return true if default_nslabs is rounded up.
*/
static bool round_up_default_nslabs(void)
{
if (!default_nareas || is_power_of_2(default_nslabs))
if (!default_nareas)
return false;

if (default_nslabs < IO_TLB_SEGSIZE * default_nareas)
default_nslabs = IO_TLB_SEGSIZE * default_nareas;
else if (is_power_of_2(default_nslabs))
return false;
default_nslabs = roundup_pow_of_two(default_nslabs);
return true;
Expand Down

0 comments on commit 57e6840

Please sign in to comment.