From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Franklin S Cooper Jr." Subject: Re: [RFC] [PATCH v2 1/3] scatterlist: Add support to clone scatterlist Date: Thu, 7 Jul 2016 10:58:02 -0500 Message-ID: <577E7C0A.2000103@ti.com> References: <1467039249-7816-1-git-send-email-fcooper@ti.com> <1467039249-7816-2-git-send-email-fcooper@ti.com> <577D3B5C.7080805@ti.com> <577D5E78.2010307@ti.com> <871t368lu6.fsf@belgarion.home> Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Cc: Andy Shevchenko , , Jens Axboe , Andrew Morton , Ming Lin , "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , Mark Brown , linux-spi , Sekhar Nori , Peter Ujfalusi To: Robert Jarzmik Return-path: In-Reply-To: <871t368lu6.fsf-4ty26DBLk+jEm7gnYqmdkQ@public.gmane.org> Sender: linux-spi-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: On 07/06/2016 05:04 PM, Robert Jarzmik wrote: > "Franklin S Cooper Jr." writes: > >> Unfortunately, for the original purpose of this series the scatterlist I >> want to clone is indeed DMA mapped. >> >> The times I've seen dma_length != length is when the dma_map_sg is >> trying to combine contiguous sgl (ex ppc_iommu_map_sg and dma_map_cont). >> So maybe it is better to subtract a value from length and dma_length >> rather than explicitly setting it to a value. This way it wouldn't >> matter that dma_length and length aren't equal. >> >> This looks like a similar approach used by sg_split_mapped. Although >> sg_split skips first x number of bytes while I want to skip the last x >> number of bytes. >> >> Maybe Robert can add his thoughts since he created sg_split. > > Hi, > > I've not read it all, but the above chapter is right : dma_length might be > different from length when a dma mapping operation coallesced 2 sg entries into > a "DMA contiguous one". This coallescing might happen for at least for 2 reasons > as far as I know : > - 2 sg entries are physically contiguous, ie : > sg_phys(sga) + sga.length == sg_phys(sgb) > - 2 sg entries are DMA contiguous when an IOMMU maps them contiguously, ie : > sg_dma_address(sga) + sga.length == sg_dma_address(sgb) > > Moreover, this 2 coallescing cases imply a "shift" between (page_link, length) > and (dma_address and dma_length). For example a mapped sglist might look like : > -sg0: page_link=>page@0k, length=4096, dma_address=0, dma_length=8192 > -sg1: page_link=>page@4k, length=4096, dma_address=8192, dma_length=16 > \=> see the shift here > coming from sg2 > -sg2: page_link=>page@8k, length=16, dma_address=0, dma_length=0 > > For these "tricky" cases, at the time I created sg_split I had done a tester as > well. It's very basic, doesn't cover all the corner cases, is a bit dumb, but > you might have a look, and the brain cost you'll pay to adapt it to test what > you want will hopefully pay off by the knowledge gained on scatterlist. It is > appended at the end of the mail. Thanks Robert for your input and sharing your test program. After looking at sg_split and test program I realized that I can use it instead of creating my own clone function. Seems like you and your patch reviewers already considered and dealt with the above complex scenario. I updated my patchset to use sg_split rather than my custom function since it seems to solve my original problem. I plan on sending out a v3 that incorporates this change. > > Cheers. > -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753124AbcGGP60 (ORCPT ); Thu, 7 Jul 2016 11:58:26 -0400 Received: from arroyo.ext.ti.com ([198.47.19.12]:51014 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751090AbcGGP6S (ORCPT ); Thu, 7 Jul 2016 11:58:18 -0400 Subject: Re: [RFC] [PATCH v2 1/3] scatterlist: Add support to clone scatterlist To: Robert Jarzmik References: <1467039249-7816-1-git-send-email-fcooper@ti.com> <1467039249-7816-2-git-send-email-fcooper@ti.com> <577D3B5C.7080805@ti.com> <577D5E78.2010307@ti.com> <871t368lu6.fsf@belgarion.home> CC: Andy Shevchenko , , Jens Axboe , Andrew Morton , Ming Lin , "linux-kernel@vger.kernel.org" , Mark Brown , linux-spi , Sekhar Nori , Peter Ujfalusi From: "Franklin S Cooper Jr." Message-ID: <577E7C0A.2000103@ti.com> Date: Thu, 7 Jul 2016 10:58:02 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <871t368lu6.fsf@belgarion.home> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/06/2016 05:04 PM, Robert Jarzmik wrote: > "Franklin S Cooper Jr." writes: > >> Unfortunately, for the original purpose of this series the scatterlist I >> want to clone is indeed DMA mapped. >> >> The times I've seen dma_length != length is when the dma_map_sg is >> trying to combine contiguous sgl (ex ppc_iommu_map_sg and dma_map_cont). >> So maybe it is better to subtract a value from length and dma_length >> rather than explicitly setting it to a value. This way it wouldn't >> matter that dma_length and length aren't equal. >> >> This looks like a similar approach used by sg_split_mapped. Although >> sg_split skips first x number of bytes while I want to skip the last x >> number of bytes. >> >> Maybe Robert can add his thoughts since he created sg_split. > > Hi, > > I've not read it all, but the above chapter is right : dma_length might be > different from length when a dma mapping operation coallesced 2 sg entries into > a "DMA contiguous one". This coallescing might happen for at least for 2 reasons > as far as I know : > - 2 sg entries are physically contiguous, ie : > sg_phys(sga) + sga.length == sg_phys(sgb) > - 2 sg entries are DMA contiguous when an IOMMU maps them contiguously, ie : > sg_dma_address(sga) + sga.length == sg_dma_address(sgb) > > Moreover, this 2 coallescing cases imply a "shift" between (page_link, length) > and (dma_address and dma_length). For example a mapped sglist might look like : > -sg0: page_link=>page@0k, length=4096, dma_address=0, dma_length=8192 > -sg1: page_link=>page@4k, length=4096, dma_address=8192, dma_length=16 > \=> see the shift here > coming from sg2 > -sg2: page_link=>page@8k, length=16, dma_address=0, dma_length=0 > > For these "tricky" cases, at the time I created sg_split I had done a tester as > well. It's very basic, doesn't cover all the corner cases, is a bit dumb, but > you might have a look, and the brain cost you'll pay to adapt it to test what > you want will hopefully pay off by the knowledge gained on scatterlist. It is > appended at the end of the mail. Thanks Robert for your input and sharing your test program. After looking at sg_split and test program I realized that I can use it instead of creating my own clone function. Seems like you and your patch reviewers already considered and dealt with the above complex scenario. I updated my patchset to use sg_split rather than my custom function since it seems to solve my original problem. I plan on sending out a v3 that incorporates this change. > > Cheers. >