Received: from eggs.gnu.org ([2001:4830:134:3::10]:38305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxb2N-0004nY-55 for qemu-devel@nongnu.org; Fri, 21 Oct 2016 10:43:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxb2K-00016s-0W for qemu-devel@nongnu.org; Fri, 21 Oct 2016 10:43:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37368) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxb2J-00015W-PU for qemu-devel@nongnu.org; Fri, 21 Oct 2016 10:43:07 -0400 Date: Fri, 21 Oct 2016 08:43:05 -0600 From: Alex Williamson Message-ID: <20161021084305.6f261879@t450s.home> In-Reply-To: <20161021051708.GP15168@pxdev.xzpeter.org> References: <1476719064-9242-1-git-send-email-bd.aviv@gmail.com> <20161017100736.68a56fd9@t450s.home> <20161020140608.0f373ea9@t450s.home> <20161021005005.GV11140@umbus.fritz.box> <20161021051708.GP15168@pxdev.xzpeter.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4 RESEND 0/3] IOMMU: intel_iommu support map and unmap notifications List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Xu Cc: David Gibson , "Aviv B.D." , qemu-devel@nongnu.org, "Michael S. Tsirkin" , Jan Kiszka On Fri, 21 Oct 2016 13:17:08 +0800 Peter Xu wrote: > On Fri, Oct 21, 2016 at 11:50:05AM +1100, David Gibson wrote: > > [...] > > > > > In my setup the VFIO registered two memory areas with one page of > > > > unregistered memory > > > > between them. > > > > > > > > When I'm calling memory_region_notify_iommu it calls the notifier function > > > > of VFIO twice > > > > when the second time is failing with warning to console as the new mapping > > > > is already present. > > > > > > > > The notifier function of VFIO should ignore IOMMUTLBEntry that is not in > > > > the correct > > > > range. > > > > > > Hmm, right vfio_listener_region_add() is called for a > > > MemoryRegionSection, but then we add an iommu notifier to the > > > MemoryRegion, so we end up with a notifier per MemoryRegionSection > > > regardless of whether they're backed by the same MemoryRegion. Seems > > > like we need a MemoryRegion based list of VFIOGuestIOMMUs so we only > > > register once per MemoryRegion and then sort though the list of > > > VFIOGuestIOMMUs for a given MemoryRegion to find the one affected. > > > David, does that sound right to you? > > I think we already have such a list (VFIOContainer.giommu_list)? Can > we use that to do it? When we try to add a new IOMMU notifier for > specific MemoryRegion, we can first traverse VFIOContainer.giommu_list > and see whether there are existing MemoryRegion registered, and we > only register if it's the first one. That's effectively what I'm suggesting except I was trying to add some efficiency by tracking both the MemoryRegion and the MemoryRegionSection separately so we don't need to traverse a list to see if a MemoryRegion is already registered. > > > > Well, I think that would work. But I think it would be better to fix > > it from the other side: > > > > We add the range to be notified into the IOMMUNotifier structure and > > filter based on that range in memory_region_notify_iommu. > > > > It means a little more list searching and filtering on notify, but it > > avoids having to have another list and search on the VFIO side. I > > think it will also better deal with cases where part of an IOMMU > > mapped region is inaccessible due to an intermediate bridge. > > IIUC, this will still need to keep several VFIOGuestIOMMUs which > contains exactly the same content? The contain different offsets since this is based on the section rather than the MemoryRegion. Thanks, Alex