From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SU7qZ-00064J-9Q for qemu-devel@nongnu.org; Mon, 14 May 2012 22:50:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SU7qX-00070f-02 for qemu-devel@nongnu.org; Mon, 14 May 2012 22:50:46 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:47899) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SU7qW-00070Z-Pz for qemu-devel@nongnu.org; Mon, 14 May 2012 22:50:44 -0400 Received: by obbwd20 with SMTP id wd20so10152786obb.4 for ; Mon, 14 May 2012 19:50:43 -0700 (PDT) Message-ID: <4FB1C480.1030408@codemonkey.ws> Date: Mon, 14 May 2012 21:50:40 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1336625347-10169-1-git-send-email-benh@kernel.crashing.org> <1336625347-10169-9-git-send-email-benh@kernel.crashing.org> <4FB1A80C.1010103@codemonkey.ws> <20120515014204.GE30229@truffala.fritz.box> <4FB1B95A.20209@codemonkey.ws> <1337049166.6727.32.camel@pasglop> In-Reply-To: <1337049166.6727.32.camel@pasglop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 08/13] iommu: Introduce IOMMU emulation infrastructure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Benjamin Herrenschmidt Cc: Richard Henderson , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Eduard - Gabriel Munteanu On 05/14/2012 09:32 PM, Benjamin Herrenschmidt wrote: > On Mon, 2012-05-14 at 21:03 -0500, Anthony Liguori wrote: >> So the CPU thread runs in lock-step with the I/O thread. Dropping the CPU >> thread lock to let the I/O thread run is a dangerous thing to do in a place like >> this. >> >> Also, I think you'd effectively block the CPU until pending DMA operations >> complete? This could be many, many, milliseconds, no? That's going to make >> guests very upset. > > Do you see any other option ? Yes, ignore it. I have a hard time believing software depends on changing DMA translation mid-way through a transaction. > > IE. When the guest invalidates iommu translations, it must have a way to > synchronize with anything that may have used such translations. IE. It > must have a way to guarantee that > > - The translation is no longer used You can certainly prevent future uses of the translation. We're only talking about pending mapped requests. My assertion is that they don't matter. > - Any physical address obtained as a result of looking at > the translation table/tree/... is no longer used Why does this need to be guaranteed? How can software depend on this in a meaningful way? > This is true regardless of the iommu model. For the PAPR TCE model, we > need to provide such synchronization whenever we clear a TCE entry, but > if I was to emulate the HW iommu of a G5 for example, I would have to > provide similar guarantees in my emulation of MMIO accesses to the iommu > TLB invalidate register. > > This is a problem with devices using the map/unmap calls. This is going > to be even more of a problem as we start being more threaded (which from > discussions I've read here or there seem to be the goal) since > synchronizing with the IO thread isn't going to be enough. > > As long as the actual data transfer through the iommu is under control > of the iommu code, then the iommu implementation can use whatever > locking it needs to ensure this synchronization. > > But map/unmap defeats that. > > David's approach may not be the best long term, but provided it's not > totally broken (I don't know qemu locking well enough to judge how > dangerous it is) then it might be a "good enough" first step until we > come up with something better ? No, it's definitely not good enough. Dropping the global mutex in random places is asking for worlds of hurt. If this is really important, then we need some sort of cancellation API to go along with map/unmap although I doubt that's really possible. MMIO/PIO operations cannot block. Regards, Anthony Liguori > > The normal case will be that no map exist, ie, it will almost always be > a guest programming error to remove an iommu mapping while a device is > actively using it, so having this case be slow is probably a non-issue. > > Cheers, > Ben. > >