Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1893517ybl; Sat, 10 Aug 2019 11:59:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxajIANv+R339R52SH2kFEND1cduTNai508p/AZiWAd3KYzywB0+GKPUChbivxsmkTZBeaP X-Received: by 2002:a17:902:45:: with SMTP id 63mr8818144pla.264.1565463590079; Sat, 10 Aug 2019 11:59:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565463590; cv=none; d=google.com; s=arc-20160816; b=w5HYiAhdOcYCIUKjtEyLjgN+WkmFbneNsotqV7M+Gj8lY9f+3GMW2bXKuVDy+boc4+ LBhujvzXEAw0tFPYzVPeeqZaGvHeqtZYab2RA+IL+0r+/9b8k8aQ3CkAckKH9Ugf8+Pq 4SUYbdQXAIU5ZHweYYYtHLAGkKcJVMcTEEikOpyiR5NKj94xykbGfd9d8wj+fgaYPRgl 7hi13k0wYAtJo5msExQXKT/sB+p+csC5b/BSJ9IuTYGDh7V/2ak2MU5Bs7+LUYMiZXg1 FK+prntIf2e4C9aSRgsLu18RuU7LQ7EXl6fQvCvkxWlxQ98ZoydXNAqLubeBX6e2U8Zu 7Oow== 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; bh=n6gqfGDHe7+MTEnADmz166g2MOtyyjqswDo8TxgNKgo=; b=iFsFs9K/RKcPBi1HJM6QZ2CdGRV2SAiwbntPineCG+irZ0rWISWQDZJ/KiXa1dSYrK 8voCcHiBjuQXonDAd+wC+bXSVEsOQej2lDkipdLbZfVllipgNlrrSjIVrerBECJeWNc2 Rk/VYzMhPS8X6CqP+92EHOc43a1XAIjD7G5PuK2LO/Zx+rjHiDrT8pOpTubHfTd6SfBL FrG71ABTZQs+M1oGXI16HDqzyk5Jd9/qsM5cu2b3/FHYCz0Gd6Paw5lA4Z+yv0sRUw1i prA1qRhU8hcxcv7g9kJ/c8gZ4svrSYIzPZI4QraW5eeBWgVRetfPlSxLJXJxMkN5ap0I kxsg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si59718464pgk.456.2019.08.10.11.59.21; Sat, 10 Aug 2019 11:59:50 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726136AbfHJS50 (ORCPT + 99 others); Sat, 10 Aug 2019 14:57:26 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:35505 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726055AbfHJS50 (ORCPT ); Sat, 10 Aug 2019 14:57:26 -0400 Received: by mail-qk1-f195.google.com with SMTP id r21so74294234qke.2 for ; Sat, 10 Aug 2019 11:57:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=n6gqfGDHe7+MTEnADmz166g2MOtyyjqswDo8TxgNKgo=; b=Q6ifeRUiJq/FlCl5IBuzL5lNwagaKSUMnyZ8bqTaIw7CF4rI61xezB1u4usfoeP5bn JIbPoiOqhQfExHGQRChBRHTn+4Ypx3TfEpabKUZFNr+1QjLi9p+R6hCCIUalZcimu8su 1+PWhSEuywpvY1JVmIKNZbBgTsSHf8j1k64MRE8FM38H+eNUDM0cELPmPywemY+BXpak nb0nR8HkzFLkA35Oyjv+c/SYHVRvJQ1HRHdmvWgQSyxbCxXSKXOXnRH+Zgz7hKLZpTqq 9ttIiwvHRbPR65WbG/5ljkAbTE/nlICu7AqpltSusmkLBKkaIMxtR/oaG14EnBR1sL3F 1rSQ== X-Gm-Message-State: APjAAAVAX+FKvVlMApeu/tPDhcJAYY3cE/zKCWoNT7uLuA1sIseOBm2q OrxYyjrZ6Ck/iEeplSkw4KJu6Q== X-Received: by 2002:a05:620a:1f0:: with SMTP id x16mr12879248qkn.11.1565463444927; Sat, 10 Aug 2019 11:57:24 -0700 (PDT) Received: from redhat.com (bzq-79-181-91-42.red.bezeqint.net. [79.181.91.42]) by smtp.gmail.com with ESMTPSA id l3sm100152qkb.67.2019.08.10.11.57.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 10 Aug 2019 11:57:23 -0700 (PDT) Date: Sat, 10 Aug 2019 14:57:17 -0400 From: "Michael S. Tsirkin" To: Thiago Jung Bauermann Cc: virtualization@lists.linux-foundation.org, linuxppc-devel@lists.ozlabs.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Jason Wang , Christoph Hellwig , David Gibson , Alexey Kardashevskiy , Paul Mackerras , Benjamin Herrenschmidt , Ram Pai Subject: Re: [RFC PATCH] virtio_ring: Use DMA API if guest memory is encrypted Message-ID: <20190810143038-mutt-send-email-mst@kernel.org> References: <87zhrj8kcp.fsf@morokweng.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87zhrj8kcp.fsf@morokweng.localdomain> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 29, 2019 at 03:08:12PM -0200, Thiago Jung Bauermann wrote: > > Hello, > > With Christoph's rework of the DMA API that recently landed, the patch > below is the only change needed in virtio to make it work in a POWER > secure guest under the ultravisor. > > The other change we need (making sure the device's dma_map_ops is NULL > so that the dma-direct/swiotlb code is used) can be made in > powerpc-specific code. > > Of course, I also have patches (soon to be posted as RFC) which hook up > to the powerpc secure guest support code. > > What do you think? > > >From d0629a36a75c678b4a72b853f8f7f8c17eedd6b3 Mon Sep 17 00:00:00 2001 > From: Thiago Jung Bauermann > Date: Thu, 24 Jan 2019 22:08:02 -0200 > Subject: [RFC PATCH] virtio_ring: Use DMA API if guest memory is encrypted > > The host can't access the guest memory when it's encrypted, so using > regular memory pages for the ring isn't an option. Go through the DMA API. > > Signed-off-by: Thiago Jung Bauermann > --- > drivers/virtio/virtio_ring.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index cd7e755484e3..321a27075380 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -259,8 +259,11 @@ static bool vring_use_dma_api(struct virtio_device *vdev) > * not work without an even larger kludge. Instead, enable > * the DMA API if we're a Xen guest, which at least allows > * all of the sensible Xen configurations to work correctly. > + * > + * Also, if guest memory is encrypted the host can't access > + * it directly. In this case, we'll need to use the DMA API. > */ > - if (xen_domain()) > + if (xen_domain() || sev_active()) > return true; > > return false; So I gave this lots of thought, and I'm coming round to basically accepting something very similar to this patch. But not exactly like this :). Let's see what are the requirements. If 1. We do not trust the device (so we want to use a bounce buffer with it) 2. DMA address is also a physical address of a buffer then we should use DMA API with virtio. sev_active() above is one way to put (1). I can't say I love it but it's tolerable. But we also want promise from DMA API about 2. Without promise 2 we simply can't use DMA API with a legacy device. Otherwise, on a SEV system with an IOMMU which isn't 1:1 and with a virtio device without ACCESS_PLATFORM, we are trying to pass a virtual address, and devices without ACCESS_PLATFORM can only access CPU physical addresses. So something like: dma_addr_is_phys_addr? -- MST