From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965516AbbI2Od3 (ORCPT ); Tue, 29 Sep 2015 10:33:29 -0400 Received: from pandora.arm.linux.org.uk ([78.32.30.218]:55335 "EHLO pandora.arm.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965065AbbI2OdL (ORCPT ); Tue, 29 Sep 2015 10:33:11 -0400 Date: Tue, 29 Sep 2015 15:32:41 +0100 From: Russell King - ARM Linux To: Robin Murphy Cc: Tomasz Figa , "iommu@lists.linux-foundation.org" , Olav Haugan , Alexandre Courbot , Paul Walmsley , Arnd Bergmann , Tomeu Vizoso , Stephen Warren , Antonios Motakis , Will Deacon , "linux-kernel@vger.kernel.org" , "linux-tegra@vger.kernel.org" , Thierry Reding , Nicolas Iooss , Vince Hsu , Mikko Perttunen Subject: Re: [RFC PATCH 0/3] iommu: Add range flush operation Message-ID: <20150929143241.GI21513@n2100.arm.linux.org.uk> References: <1443504379-31841-1-git-send-email-tfiga@chromium.org> <560A9E36.9030903@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <560A9E36.9030903@arm.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 29, 2015 at 03:20:38PM +0100, Robin Murphy wrote: > A single callback doesn't really generalise well enough: If we wanted to > implement this in the ARM SMMU drivers to optimise the unmap() case [ask > Will how long he spends waiting for a software model to tear down an entire > VFIO domain invalidating one page at a time ;)], then we'd either regress > performance in the map() case with an unnecessary TLB flush, or have to do a > table walk in every flush() call to infer what actually needs doing. And this is the problem of frameworks. They get in the way of doing things efficiently. Fine, we have the DMA ops, and that calls a map_sg() method. What we then need is to have a series of standardised library functions which can be called to perform various actions. Consider this: an IOMMU driver gets the raw scatterlist which the driver passed. The IOMMU driver walks the scatterlist, creating the IOMMU side mapping, and writing the device DMA addresses and DMA lengths to the scatterlist, possibly coalescing some of the entries. It remembers the number of scatterlist entries that the DMA operation now requires. The IOMMU code can setup whatever mappings it wants using whatever sizes it wants to satisfy the requested scatterlist. It then goes on to call the arch backend with the original scatterlist, asking it to _only_ deal with the CPU coherency for the mapping. The arch code walks the scatterlist again, this time dealing with the CPU coherency part. Finally, the IOMMU code returns the number of DMA scatterlist entries. When it comes to tearing it down, it's a similar operation to the above, except reversing those actions. The only issue with this approach is that it opens up some of the cache handling to the entire kernel, and that will be _too_ big a target for idiotic driver writers to think they have permission to directly use those interfaces. To solve this, I'd love to be able to have the linker link together certain objects in the kernel build, and then convert some global symbols to be local symbols, thus denying access to functions that driver authors have no business what so ever touching. > Personally I think it would be nicest to have two separate callbacks, e.g. > .map_sync/.unmap_sync, but at the very least some kind of additional > 'direction' kind of parameter would be necessary. No, not more callbacks - that's the framework thinking, not the library thinking. -- FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.