Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2089649imm; Sat, 4 Aug 2018 19:06:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdkaNmZL5MI67Er2i5xmL7fEALT0yvWjsDf0omu7gxUWLkKPXseup/Up36J86wkjrSUcttS X-Received: by 2002:a62:5984:: with SMTP id k4-v6mr11064986pfj.116.1533434783781; Sat, 04 Aug 2018 19:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533434783; cv=none; d=google.com; s=arc-20160816; b=O3d4e9iw7TNuyYqZr+Yr+/5vxS9si+97EZm5JGPfX9nEVvD6FzcCzqJfQAcjIqwx0f v4Fw7Jzw6sBxQaQ9zV//YAyvICR+ZHHEAwlIh0ElatpiKLTVU+CUugWRSEPcSIrfZgAR efFPkP9ntfnvlP086l/gK4Y6OMucv7aSY6gLjjCIbXYzyOKQgnBDklZpreH0f3Dxo5qz B9JcphMAFfg/6UElJwOwAst7pTv40WqcxwWj0fxNkbilZAVFdamoOT3Hw+huC8mvTPWL Gnl2+6b/vus58Jt18vACNfOdBralyvBKoSFEUfm+ybxN8tW6aD8JvSH8gefOMh+wfxow /HUQ== 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=4h61ZLHsHbCTvZplZoSKCc5Te/yk5HPmZkHiws9kUxY=; b=w9HRPhkau1IgcLTEjE38XTvd38/z/GxTRdzw8CuxMismE/1zta7+J8oZiDxdNNSzoY dIhORfNV8Qd7jnJMRGaou/DBTQp3j2rgTyXMjkEepKxoV5hPoGk+qkslAhcaWtm8urKz HbRkysRcMM54cBhHdZgwgHmhPi+FN1ioZnimKZez1TZUAQOl8IyEm0BauzsOhC7m/dLi +EThXqV4gxxZo/dQnHQ+wP0opz8D6gEeW9zQY+/GGTlJAQnVkvkYQKpxIvV7+b0BnurA xJpYYY/kzBF+XKbAQtXzvkaO/MlfZtPuNGAJ2K0VSyQ+v3511IzF5gxhjOb0mnBovxoW GvHQ== 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 m11-v6si6985451pla.45.2018.08.04.19.06.09; Sat, 04 Aug 2018 19:06:23 -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 S1726082AbeHEEIK (ORCPT + 99 others); Sun, 5 Aug 2018 00:08:10 -0400 Received: from gate.crashing.org ([63.228.1.57]:46952 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725721AbeHEEIJ (ORCPT ); Sun, 5 Aug 2018 00:08:09 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w751AHxe004284; Sat, 4 Aug 2018 20:10:27 -0500 Message-ID: Subject: Re: [RFC 0/4] Virtio uses DMA API for all devices From: Benjamin Herrenschmidt To: Christoph Hellwig Cc: "Michael S. Tsirkin" , 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: Sun, 05 Aug 2018 11:10:15 +1000 In-Reply-To: <20180804082120.GB4421@infradead.org> References: <20180802182959-mutt-send-email-mst@kernel.org> <82ccef6ec3d95ee43f3990a4a2d0aea87eb45e89.camel@kernel.crashing.org> <20180802200646-mutt-send-email-mst@kernel.org> <20180802225738-mutt-send-email-mst@kernel.org> <20180803070507.GA1344@infradead.org> <20180803160246.GA13794@infradead.org> <22310f58605169fe9de83abf78b59f593ff7fbb7.camel@kernel.crashing.org> <20180804082120.GB4421@infradead.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 Sat, 2018-08-04 at 01:21 -0700, Christoph Hellwig wrote: > No matter if you like it or not (I don't!) virtio is defined to bypass > dma translations, it is very clearly stated in the spec. It has some > ill-defined bits to bypass it, so if you want the dma mapping API > to be used you'll have to set that bit (in its original form, a refined > form, or an entirely newly defined sane form) and make sure your > hypersivors always sets it. It's not rocket science, just a little bit > for work to make sure your setup is actually going to work reliably > and portably. I think you are conflating completely different things, let me try to clarify, we might actually be talking past each other. > > We aren't going to cancel years of HW and SW development for our > > Maybe you should have actually read the specs you are claiming to > implemented before spending all that effort. Anyway, let's cool our respective jets and sort that out, there are indeed other approaches than overriding the DMA ops with special ones, though I find them less tasty ... but here's my attempt at a (simpler) description. Bear with me for the long-ish email, this tries to describe the system so you get an idea where we come from, and options we can use to get out of this. So we *are* implementing the spec, since qemu is currently unmodified: Default virtio will bypass the iommu emulated by qemu as per spec etc.. On the Linux side, thus, virtio "sees" a normal iommu-bypassing device and will treat it as such. The problem is the assumption in the middle that qemu can access all guest pages directly, which holds true for traditional VMs, but breaks when the VM in our case turns itself into a secure VM. This isn't under the action (or due to changes in) the hypervisor. KVM operates (almost) normally here. But there's this (very thin and open source btw) layer underneath called ultravisor, which exploits some HW facilities to maintain a separate pool of "secure" memory, which cannot be physically accessed by a non-secure entity. So in our scenario, qemu and KVM create a VM totally normally, there is no changes required to the VM firmware, bootloader(s), etc... in fact we support Linux based bootloaders, and those will work as normal linux would in a VM, virtio works normally, etc... Until that VM (via grub or kexec for example) loads a "secure image". That secure image is a Linux kernel which has been "wrapped" (to simply imagine a modified zImage wrapper though that's not entirely exact). When that is run, before it modifies it's .data, it will interact with the ultravisor using a specific HW facility to make itself secure. What happens then is that the UV cryptographically verifies the kernel and ramdisk, and copies them to the secure memory where execution returns. The Ultravisor is then involved as a small shim for hypercalls between the secure VM and KVM to prevent leakage of information (sanitize registers etc...). Now at this point, qemu can no longer access the secure VM pages (there's more to this, such as using HMM to allow migration/encryption accross etc... but let's not get bogged down). So virtio can no longer access any page in the VM. Now the VM *can* request from the Ultravisor some selected pages to be made "insecure" and thus shared with qemu. This is how we handle some of the pages used in our paravirt stuff, and that's how we want to deal with virtio, by creating an insecure swiotlb pool. At this point, thus, there are two options. - One you have rejected, which is to have a way for "no-iommu" virtio (which still doesn't use an iommu on the qemu side and doesn't need to), to be forced to use some custom DMA ops on the VM side. - One, which sadly has more overhead and will require modifying more pieces of the puzzle, which is to make qemu uses an emulated iommu. Once we make qemu do that, we can then layer swiotlb on top of the emulated iommu on the guest side, and pass that as dma_ops to virtio. Now, assuming you still absolutely want us to go down the second option, there are several ways to get there. We would prefer to avoid requiring the user to pass some special option to qemu. That has an impact up the food chain (libvirt, management tools etc...) and users probably won't understand what it's about. In fact the *end user* might not even need to know a VM is secure, though applications inside might. There's the additional annoyance that currently our guest FW (SLOF) cannot deal with virtio in IOMMU mode, but that's fixable. From there, refer to the email chain between Michael and I where we are discussing options to "switch" virtio at runtime on the qemu side. Any comment or suggestion ? Cheers, Ben.