Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2100198ybv; Sun, 23 Feb 2020 22:44:22 -0800 (PST) X-Google-Smtp-Source: APXvYqzZmKuhCYayNHM0fKZI5G6LkxwztQ7bmjmKlUYLNrObPuVE+a4ZkPhpyGq/8eZas5rnYbJJ X-Received: by 2002:a05:6830:22d8:: with SMTP id q24mr24650697otc.0.1582526661951; Sun, 23 Feb 2020 22:44:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582526661; cv=none; d=google.com; s=arc-20160816; b=sRDrsOz1CKj3WH7WbrjgI4Gis2lHnKfoeui0Wq0XybUXM1j1rh/uX2BK5kDDtCMtEO DLnQbGVMk46cRUQH7mCosVz8Z0RNuSv2l2M0WoNaICUjBJi1CKh13NLgXkGQ69IaQnRe +JR2NIGVq4+3DuW63IqVShGhmDEpSSW82Ml4HdpChlxJOxbJ1A2e0gGIdH7uPLDMucNC q1pUvsikR/zm3b6PH9x2PtA6PFMOe4hZq1efWihadrHwBLKb6SoJCO4BUl6dbMIkNmvi 9KluOBSBIoVaZQzItJ6X4TbIIxC/QnQYGpINugt8+eQm8v2smuHk32N14RL/W2hWoE7G tnLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=y20oF9vQe9AweNI9VSdzWX28WL9hHTO0YaB8Phy48KE=; b=MePYaIcpbiWsVkU6x2dN25CsjSuLe+/MyP6yr4Dg9kt3KOAIX+j/29HVg7W6j1FMcz lBszXXaAJ0ESPZ+abXLge6qaTIn/xINk4qh46NMObmdMcbp0yxBvy7V0/BHG5uRo38xf PorXdbMInuksAVJaE2UTjWTU5aweOjc+cGk0feupvO5qVHqsOHSPvbmp7dbohrLxAK3I oO4OSV7HZzHbgjq8yCw1u6VLaPIVTeeiZMtGk+whRp6nGo1I0FJJDjMGIgbZR3WomfXi VZBTY5yQlLAAVM++xA+3YGIutNc+fapZmENV5nHLe6mR+nUCEX9sKmyI2JUEtQzn1rM1 2KRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=EdoHemir; 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 o20si5403943otl.60.2020.02.23.22.44.10; Sun, 23 Feb 2020 22:44:21 -0800 (PST) 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; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=EdoHemir; 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 S1727351AbgBXGn7 (ORCPT + 99 others); Mon, 24 Feb 2020 01:43:59 -0500 Received: from ozlabs.org ([203.11.71.1]:56775 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727306AbgBXGn4 (ORCPT ); Mon, 24 Feb 2020 01:43:56 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 48QswS4FsCz9sSD; Mon, 24 Feb 2020 17:43:52 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1582526632; bh=PgCI+bQgZ1XEAWYR7dFuO4T5LpjfnQ3xxjbWGrDvPA0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EdoHemir0eTgk8BRcIPowD0AcmEOyYGN8DMhWrfYjA45tXuHpS0wUH3Y65npJ23PS 2pQo0daNHIii7W9t8lSK+AezB8S3C4RPLWlBDg3Tf3LiPs2CQWVzeigXD7nDQXprhX toNPDPF6tsj41hTAEsfQxq38VaNq0RlRTNO+xg6U= Date: Mon, 24 Feb 2020 17:40:41 +1100 From: David Gibson To: Tom Lendacky Cc: Halil Pasic , "Michael S. Tsirkin" , Jason Wang , Marek Szyprowski , Robin Murphy , Christoph Hellwig , linux-s390@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Christian Borntraeger , Janosch Frank , Viktor Mihajlovski , Cornelia Huck , Ram Pai , Thiago Jung Bauermann , Michael Mueller , "Singh, Brijesh" , "Huang, Wei" , Suravee Suthikulpanit Subject: Re: [PATCH 2/2] virtio: let virtio use DMA API when guest RAM is protected Message-ID: <20200224064041.GL1751@umbus.fritz.box> References: <20200220160606.53156-1-pasic@linux.ibm.com> <20200220160606.53156-3-pasic@linux.ibm.com> <20200220154904-mutt-send-email-mst@kernel.org> <20200221141230.13eebc35.pasic@linux.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="huBJOJF9BsF479P6" Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --huBJOJF9BsF479P6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 21, 2020 at 09:39:38AM -0600, Tom Lendacky wrote: > On 2/21/20 7:12 AM, Halil Pasic wrote: > > On Thu, 20 Feb 2020 15:55:14 -0500 > > "Michael S. Tsirkin" wrote: > >=20 > >> On Thu, Feb 20, 2020 at 05:06:06PM +0100, Halil Pasic wrote: > >>> Currently the advanced guest memory protection technologies (AMD SEV, > >>> powerpc secure guest technology and s390 Protected VMs) abuse the > >>> VIRTIO_F_IOMMU_PLATFORM flag to make virtio core use the DMA API, whi= ch > >>> is in turn necessary, to make IO work with guest memory protection. > >>> > >>> But VIRTIO_F_IOMMU_PLATFORM a.k.a. VIRTIO_F_ACCESS_PLATFORM is really= a > >>> different beast: with virtio devices whose implementation runs on an = SMP > >>> CPU we are still fine with doing all the usual optimizations, it is j= ust > >>> that we need to make sure that the memory protection mechanism does n= ot > >>> get in the way. The VIRTIO_F_ACCESS_PLATFORM mandates more work on the > >>> side of the guest (and possibly he host side as well) than we actually > >>> need. > >>> > >>> An additional benefit of teaching the guest to make the right decision > >>> (and use DMA API) on it's own is: removing the need, to mandate speci= al > >>> VM configuration for guests that may run with protection. This is > >>> especially interesting for s390 as VIRTIO_F_IOMMU_PLATFORM pushes all > >>> the virtio control structures into the first 2G of guest memory: > >>> something we don't necessarily want to do per-default. > >>> > >>> Signed-off-by: Halil Pasic > >>> Tested-by: Ram Pai > >>> Tested-by: Michael Mueller > >> > >> This might work for you but it's fragile, since without > >> VIRTIO_F_ACCESS_PLATFORM hypervisor assumes it gets > >> GPA's, not DMA addresses. > >> > >=20 > > Thanks for your constructive approach. I do want the hypervisor to > > assume it gets GPA's. My train of thought was that the guys that need > > to use IOVA's that are not GPA's when force_dma_unencrypted() will have > > to to specify VIRTIO_F_ACCESS_PLATFORM (at the device) anyway, because > > otherwise it won't work. But I see your point: in case of a > > mis-configuration and provided the DMA API returns IOVA's one could end > > up trying to touch wrong memory locations. But this should be similar to > > what would happen if DMA ops are not used, and memory is not made acces= sible. > >=20 > >> > >> > >> IOW this looks like another iteration of: > >> > >> virtio: Support encrypted memory on powerpc secure guests > >> > >> which I was under the impression was abandoned as unnecessary. > >=20 > > Unnecessary for powerpc because they do normal PCI. In the context of > > CCW there are only guest physical addresses (CCW I/O has no concept of > > IOMMU or IOVAs). > >=20 > >> > >> > >> To summarize, the necessary conditions for a hack along these lines > >> (using DMA API without VIRTIO_F_ACCESS_PLATFORM) are that we detect th= at: > >> > >> - secure guest mode is enabled - so we know that since we don't share > >> most memory regular virtio code won't > >> work, even though the buggy hypervisor didn't set VIRTIO_F_ACCESS_= PLATFORM > >=20 > > force_dma_unencrypted(&vdev->dev) is IMHO exactly about this. > >=20 > >> - DMA API is giving us addresses that are actually also physical > >> addresses > >=20 > > In case of s390 this is given. I talked with the power people before > > posting this, and they ensured me they can are willing to deal with > > this. I was hoping to talk abut this with the AMD SEV people here (hence > > the cc). >=20 > Yes, physical addresses are fine for SEV - the key is that the DMA API is > used so that an address for unencrypted, or shared, memory is returned. > E.g. for a dma_alloc_coherent() call this is an allocation that has had > set_memory_decrypted() called or for a dma_map_page() call this is an > address from SWIOTLB, which was mapped shared during boot, where the data > will be bounce-buffered. >=20 > We don't currently support an emulated IOMMU in our SEV guest because that > would require a lot of support in the driver to make IOMMU data available > to the hypervisor (I/O page tables, etc.). We would need hardware support > to really make this work easily in the guest. A tangent here: note that on POWER our IOMMU is paravirtualized (updated with hypercalls), it's also always enabled. For that reason we can and do combine vIOMMU translation with the need for bounce buffering for secure guests. (We generally statically configure the vIOMMU to have a huge window which just maps GPAs 1-to-1, which means we can still use dma-direct, but the vIOMMU is still there from the platform point of view) --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --huBJOJF9BsF479P6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAl5Tb+cACgkQbDjKyiDZ s5JuYA/+PfSvSTQHH+JQEj0OF/7dpLptTGSV1vu254FmtjttOv1Jp6vV1qNrERui WrRDf1Hu/dKxuJty9TNapcUvBHFWP5NtSSRXXYsTRm+A629Ykjtom+0/2TjOzKbF oX7NvwxIc33a0Y64z3cstNSKcj8eTrRZC1SvIwezFXL1uldfKOq+WH42U/cImXy7 Br6oWhkuV5EHDcshTAQ2FLz6zxhzp0hPuL2+PrYETrqHJq2Vx08goX4ZgwH6iL40 NDTT6JNniVQE3rZ8NimqdXJETTXVuqTKPVinVod77U6V/QSEKf1YYL9upvc6oYSU LZKsXAlQVgdSepYV/3PMafrZ6OhX0ZorfqzfDn/p0FkHYAKmSNgBG3mzI8JbIrE/ kPCF6Jo8vbs0SX24V4N/cTFxAodz+YQaMGtf+IZQ1LB56XhQBv2GES82btCMM8Re 1e6T6AXQuXUb0db5JsYzh9Iopa8cqABVVNqYKoCcDKll1bkCDW2OA0jK3qtz9wH6 mNNLn8ZLZDX0OjwINwQK2brVa6p5UTrk0l+Tgg94EbpISG5R4pb1e9rGK8UUrVcg G4AqmwA8NkFmCJPEbeWxYwE2Rg73yJx1C3okR5KTC/odF/7Pw6KParzV1Wn3lMdz WLYS9wIe5ZmNIjpbAPS1dEM1cjyza4Qyuu3xyvKcoKuT/uxPl5c= =VdBp -----END PGP SIGNATURE----- --huBJOJF9BsF479P6--