Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4073464imm; Mon, 6 Aug 2018 16:23:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcXvOFB97SEq3GLu8F5yJQiw+gzj38CPguAsVuFr6EmqYatquqIHKPtQwWstjfmpvpaQ3Mr X-Received: by 2002:a17:902:7202:: with SMTP id ba2-v6mr15520110plb.179.1533597793194; Mon, 06 Aug 2018 16:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533597793; cv=none; d=google.com; s=arc-20160816; b=V0x66J73r0Jh4VagtYYoPPNHe070nEtz+2Fk0XyGQTtOZ2mdjds2sgWI7elbPZpN6G 7taQNax/6QsdAYyNqI8f8Sn1KFlG1/bza+u6Q0xbkkNWW0wGoppDq4ffWjawmGn7VD2j y0biMUzMIppkG7RVd7JcNUXP1+u3UwHU4fGSZPwQgwabDGjmlezqSF8HcXju9rk270Cf OuupT4rAl6hsGohQvBEtnEAK2UiArLWrI3r/PusdUCtiJPwSK5t35OAr09SvIB3Bojz3 BfLVn3Zz56vsIaP1N+iLShxHBID8BEn3WX/l8Zj79zQoBUyrWNWcbvsKj1EkJztqdmGm 3ycg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=A8JtYqMNp481WDNU5pKMfAER36unF7z7EEurwY9iGNc=; b=bnRnS5Zbvcfy48tUgT7f601hcdLjuP2vxdra5GBouX0xM4/DuW14cGgi1VEfs0xqCS ESTBKZ+FDzK4W+JofVm9hoUVhx/S9NvWUqbdagmyrH/UihF1mECUWR6KdNLEDauH0AVD UmVAu+WDdU03JTTyNF9bmen4v4CaghubgV1RLl1tuNMJAIdM0k/woZ+wq6aY3op25bQj GFOdensUp8uBUYm+Nu8D8Um4hlD+1k3ZJ1+AHQsXO8ly4g4DGeD6bt4VKylzo+SJ1PLF MA3YxZ7z4izUTf6xkBcnzjbSvCZ6Ez4/z4iAxgxiCCtYXWcCOKKojjUl7mh4bGOOIqq9 Ab6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f35-v6si11244618plh.50.2018.08.06.16.22.58; Mon, 06 Aug 2018 16:23:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387812AbeHGB3X (ORCPT + 99 others); Mon, 6 Aug 2018 21:29:23 -0400 Received: from gate.crashing.org ([63.228.1.57]:51427 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387522AbeHGB3W (ORCPT ); Mon, 6 Aug 2018 21:29:22 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w76NGhW1013183; Mon, 6 Aug 2018 18:16:45 -0500 Message-ID: <8e00f0310fa78882d3d32270c03b0b6257f35f83.camel@kernel.crashing.org> Subject: Re: [RFC 0/4] Virtio uses DMA API for all devices From: Benjamin Herrenschmidt To: "Michael S. Tsirkin" Cc: Christoph Hellwig , Will Deacon , Anshuman Khandual , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, aik@ozlabs.ru, robh@kernel.org, joe@perches.com, elfring@users.sourceforge.net, david@gibson.dropbear.id.au, jasowang@redhat.com, mpe@ellerman.id.au, linuxram@us.ibm.com, haren@linux.vnet.ibm.com, paulus@samba.org, srikar@linux.vnet.ibm.com, robin.murphy@arm.com, jean-philippe.brucker@arm.com, marc.zyngier@arm.com Date: Tue, 07 Aug 2018 09:16:43 +1000 In-Reply-To: <93518075238a07e9f011774d89bdc652c083f1ba.camel@kernel.crashing.org> References: <20180803070507.GA1344@infradead.org> <20180803220443-mutt-send-email-mst@kernel.org> <051fd78e15595b414839fa8f9d445b9f4d7576c6.camel@kernel.crashing.org> <20180805031046-mutt-send-email-mst@kernel.org> <20180806164106-mutt-send-email-mst@kernel.org> <20180806233024-mutt-send-email-mst@kernel.org> <0967fc30001323e6e38ed12c8dba8ee3d1aa13f5.camel@kernel.crashing.org> <20180807002857-mutt-send-email-mst@kernel.org> <93518075238a07e9f011774d89bdc652c083f1ba.camel@kernel.crashing.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.4 (3.28.4-1.fc28) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-08-07 at 08:13 +1000, Benjamin Herrenschmidt wrote: > > OK well, assuming Christoph can solve the direct case in a way that > also work for the virtio !iommu case, we still want some bit of logic > somewhere that will "switch" to swiotlb based ops if the DMA mask is > limited. > > You mentioned an RFC for that ? Do you happen to have a link ? > > It would be indeed ideal if all we had to do was setup some kind of > bus_dma_mask on all PCI devices and have virtio automagically insert > swiotlb when necessary. Actually... I can think of a simpler option (Anshuman, didn't you prototype this earlier ?): Since that limitaiton of requiring bounce buffering via swiotlb is true of any device in a secure VM, whether it goes through the iommu or not, the iommu remapping is essentially pointless. Thus, we could ensure that the iommu maps 1:1 the swiotlb bounce buffer (either that or we configure it as "disabled" which is equivalent in this case). That way, we can now use the basic swiotlb ops everywhere, the same dma_ops (swiotlb) will work whether a device uses the iommu or not. Which boils down now to only making virtio use dma ops, there is no need to override the dma_ops. Which means all we have to do is either make xen_domain() return true (yuck) or replace that one test with arch_virtio_force_dma_api() which resolves to xen_domain() on x86 and can do something else for us. As to using a virtio feature flag for that, which is what Christoph proposes, I'm not too fan of it because this means effectively exposing this to the peer, ie the interface. I don't think it belong there. The interface, from the hypervisor perspective, whether it's qemu, vmware, hyperz etc... have no business knowing how the guest manages its dma operations, and may not even be aware of the access limitations (in our case they are somewhat guest self-imposed). Now, if this flag really is what we have to do, then we'd probably need a qemu hack which will go set that flag on all virtio devices when it detects that the VM is going secure. But I don't think that's where that information "need to use the dma API even for direct mode" belongs. Cheers, Ben.