[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <dff50b2c-5e31-8b4a-7fdf-99d17852746b@linux.intel.com>
Date: Tue, 23 Apr 2019 15:32:16 +0800
From: Lu Baolu <baolu.lu@...ux.intel.com>
To: Christoph Hellwig <hch@....de>
Cc: baolu.lu@...ux.intel.com, David Woodhouse <dwmw2@...radead.org>,
Joerg Roedel <joro@...tes.org>, ashok.raj@...el.com,
jacob.jun.pan@...el.com, alan.cox@...el.com, kevin.tian@...el.com,
mika.westerberg@...ux.intel.com, pengfei.xu@...el.com,
Konrad Rzeszutek Wilk <konrad.wilk@...cle.com>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Robin Murphy <robin.murphy@....com>,
iommu@...ts.linux-foundation.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 02/10] swiotlb: Factor out slot allocation and free
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
Powered by blists - more mailing lists