lkml.org 
[lkml]   [2019]   [Apr]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v3 02/10] swiotlb: Factor out slot allocation and free
From
Date
Hi Christoph,

On 4/23/19 2:12 PM, Christoph Hellwig wrote:
> On Tue, Apr 23, 2019 at 09:58:19AM +0800, Lu Baolu wrote:
>> 554 for (i = 0; i < nslots; i++)
>> 555 io_tlb_orig_addr[index+i] = orig_addr + (i <<
>> IO_TLB_SHIFT);
>>
>> Could the tlb orig address set to PAGE_ALIGN_DOWN(orig_addr)? We
>> couldn't assume the bounce buffer just starts from the beginning of the
>> slot. Or anything I missed?
>
> I don't see why we need to align the orig_addr. We only use
> io_tlb_orig_addr to find the address(es) for the swiotlb_bounce calls,
> and I don't see a good reason why we'd need to align those.
>

Let me show you an example. Normally, if IOMMU is on, the device DMAs
with an iova. IOMMU takes the responsibility to translate the iova to
the physical address in paging mode.

Physical
IOVA Buffer
.---------. .---------.
| IOMMU | | IOMMU |
| PAGE | | PAGE |
.---------. -------> .---------.
| Buffer | | Buffer |
'---------' '---------'
| | | |
| | | |
'---------' '---------'
.-------.
| IOMMU |
'-------'

When we add the bounce buffer between IOVA and physical buffer, the
bounced buffer must starts from the same offset in a page, otherwise,
IOMMU can't work here.


Bouce Physical
IOVA Buffer Buffer
.---------. .---------. .---------.
| | .-----> | Buffer | <---. | |
| | | '---------' | | |
.---------. | | | | .---------.
| Buffer | NO | | YES | Buffer |
'---------' | | '---------'
| | | | | |
| | | | | |
'---------' '---------' '---------'
.-------. .---------.
| IOMMU | | swiotlb |
'-------' '---------'

A workable buffer location looks like below.


Bouce Physical
IOVA Buffer Buffer
.---------. .---------. .---------.
| | | | | |
| | | | | |
.---------. ------->.---------.<----- .---------.
| Buffer | YES | Buffer | YES | Buffer |
'---------' '---------' '---------'
| | | | | |
| | | | | |
'---------' '---------' '---------'
.-------. .---------.
| IOMMU | | swiotlb |
'-------' '---------'

Best regards,
Lu Baolu

\
 
 \ /
  Last update: 2019-04-23 09:39    [W:0.057 / U:10.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site