Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4581269yba; Wed, 17 Apr 2019 14:46:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyO4eAUcKrlUVmOlc0MqeCivOXOiOx1U173lWJ9G5U+MCAg0MIvCw8ra1DhkOFKIW4I33sg X-Received: by 2002:a65:62c9:: with SMTP id m9mr79253202pgv.309.1555537577357; Wed, 17 Apr 2019 14:46:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555537577; cv=none; d=google.com; s=arc-20160816; b=KG3aW+C8Nrp/QTWyttw7xtqAk2kKyaniZxFTXOATirsx4dj1oa1YYsUxIQUDcq/BB0 4G3gOzikkCn1sPGZNncZEk6Kly/U8wVij2e1hytf4s1dJQ/hsD1Msf87Q3jgl209y84Y +vvEQNUivT0OUzvHyuqd3kJEoyMjncqsp7rhDcgijjxH6VC6iEuyzOnZc0x4htFXtF49 +k0EWAQKTcp8j51zkuFwSlM8+5UqIdlbdKG5KroIxWWQwtcjlxtBcUU0/kbVfdZIi/6E 3PLlQsgJ5K/BKNBE5sYHbILSnkI8ErWXT1HuSMld9317XvNFA8kQDOQONRKggU81ZYDc ATPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:mime-version:date:in-reply-to :subject:cc:to:from:user-agent:references; bh=jRR1pPBtY1wKRjMhkjWJ5ygLV9v1PuCuGmOeG5NuJaI=; b=jtHeO8FbW+4zNeVv2m9mtbA+GMXeoaqtLSx0Fs/IyXnIl4jjtAq86Z0SmHQFcOslxK wGO4fl9lYiq6+f0UfwhXDNSxp1QXeWq0C+IPlVlqBL/MQRgPhB4BKC+e+Nax00lhCkSt uZ5GIR51QTIPg4EOFTkCj8sh0Lpf3XwL/lcfp4W2/gok/cRxsWBPxRVlVPVDu+vzoUoN v6TuDJS1ayd+biLepcj6/x32mJiYIHRqdQWYVhzNKEJ2jX7ATOqObb7Fy1xZzeMzvvus vNc4/WVGVtUbojug8lszn79vbHKZVpDBZ6GScNHgCYcMj3P3nlFi690wgaETdI4ove5B Pxtw== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o19si49234499pgv.355.2019.04.17.14.46.00; Wed, 17 Apr 2019 14:46:17 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387546AbfDQVmX (ORCPT + 99 others); Wed, 17 Apr 2019 17:42:23 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:52200 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbfDQVmR (ORCPT ); Wed, 17 Apr 2019 17:42:17 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x3HLYT2b023387 for ; Wed, 17 Apr 2019 17:42:16 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rx7a7vaqc-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 17 Apr 2019 17:42:15 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 17 Apr 2019 22:42:15 +0100 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 17 Apr 2019 22:42:11 +0100 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x3HLg9h29568440 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Apr 2019 21:42:09 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 94A37C6059; Wed, 17 Apr 2019 21:42:09 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C26A0C6055; Wed, 17 Apr 2019 21:42:05 +0000 (GMT) Received: from morokweng.localdomain (unknown [9.85.230.182]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTPS; Wed, 17 Apr 2019 21:42:05 +0000 (GMT) References: <87zhrj8kcp.fsf@morokweng.localdomain> <87womn8inf.fsf@morokweng.localdomain> <20190129134750-mutt-send-email-mst@kernel.org> <877eefxvyb.fsf@morokweng.localdomain> <20190204144048-mutt-send-email-mst@kernel.org> <87ef71seve.fsf@morokweng.localdomain> <20190320171027-mutt-send-email-mst@kernel.org> <87tvfvbwpb.fsf@morokweng.localdomain> <20190323165456-mutt-send-email-mst@kernel.org> User-agent: mu4e 1.0; emacs 26.1 From: Thiago Jung Bauermann To: "Michael S. Tsirkin" Cc: virtualization@lists.linux-foundation.org, linuxppc-dev@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 , Jean-Philippe Brucker , Michael Roth , Mike Anderson Subject: Re: [RFC PATCH] virtio_ring: Use DMA API if guest memory is encrypted In-reply-to: <20190323165456-mutt-send-email-mst@kernel.org> Date: Wed, 17 Apr 2019 18:42:00 -0300 MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 x-cbid: 19041721-0016-0000-0000-000009A2014C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010946; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000284; SDB=6.01190543; UDB=6.00623874; IPR=6.00971342; MB=3.00026490; MTD=3.00000008; XFM=3.00000015; UTC=2019-04-17 21:42:14 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19041721-0017-0000-0000-000042DA68A3 Message-Id: <87a7go71hz.fsf@morokweng.localdomain> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-17_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904170137 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Michael S. Tsirkin writes: > On Thu, Mar 21, 2019 at 09:05:04PM -0300, Thiago Jung Bauermann wrote: >> >> Michael S. Tsirkin writes: >> >> > On Wed, Mar 20, 2019 at 01:13:41PM -0300, Thiago Jung Bauermann wrote: >> >> >From what I understand of the ACCESS_PLATFORM definition, the host will >> >> only ever try to access memory addresses that are supplied to it by the >> >> guest, so all of the secure guest memory that the host cares about is >> >> accessible: >> >> >> >> If this feature bit is set to 0, then the device has same access to >> >> memory addresses supplied to it as the driver has. In particular, >> >> the device will always use physical addresses matching addresses >> >> used by the driver (typically meaning physical addresses used by the >> >> CPU) and not translated further, and can access any address supplied >> >> to it by the driver. When clear, this overrides any >> >> platform-specific description of whether device access is limited or >> >> translated in any way, e.g. whether an IOMMU may be present. >> >> >> >> All of the above is true for POWER guests, whether they are secure >> >> guests or not. >> >> >> >> Or are you saying that a virtio device may want to access memory >> >> addresses that weren't supplied to it by the driver? >> > >> > Your logic would apply to IOMMUs as well. For your mode, there are >> > specific encrypted memory regions that driver has access to but device >> > does not. that seems to violate the constraint. >> >> Right, if there's a pre-configured 1:1 mapping in the IOMMU such that >> the device can ignore the IOMMU for all practical purposes I would >> indeed say that the logic would apply to IOMMUs as well. :-) >> >> I guess I'm still struggling with the purpose of signalling to the >> driver that the host may not have access to memory addresses that it >> will never try to access. > > For example, one of the benefits is to signal to host that driver does > not expect ability to access all memory. If it does, host can > fail initialization gracefully. But why would the ability to access all memory be necessary or even useful? When would the host access memory that the driver didn't tell it to access? >> >> >> > But the name "sev_active" makes me scared because at least AMD guys who >> >> >> > were doing the sensible thing and setting ACCESS_PLATFORM >> >> >> >> >> >> My understanding is, AMD guest-platform knows in advance that their >> >> >> guest will run in secure mode and hence sets the flag at the time of VM >> >> >> instantiation. Unfortunately we dont have that luxury on our platforms. >> >> > >> >> > Well you do have that luxury. It looks like that there are existing >> >> > guests that already acknowledge ACCESS_PLATFORM and you are not happy >> >> > with how that path is slow. So you are trying to optimize for >> >> > them by clearing ACCESS_PLATFORM and then you have lost ability >> >> > to invoke DMA API. >> >> > >> >> > For example if there was another flag just like ACCESS_PLATFORM >> >> > just not yet used by anyone, you would be all fine using that right? >> >> >> >> Yes, a new flag sounds like a great idea. What about the definition >> >> below? >> >> >> >> VIRTIO_F_ACCESS_PLATFORM_NO_IOMMU This feature has the same meaning as >> >> VIRTIO_F_ACCESS_PLATFORM both when set and when not set, with the >> >> exception that the IOMMU is explicitly defined to be off or bypassed >> >> when accessing memory addresses supplied to the device by the >> >> driver. This flag should be set by the guest if offered, but to >> >> allow for backward-compatibility device implementations allow for it >> >> to be left unset by the guest. It is an error to set both this flag >> >> and VIRTIO_F_ACCESS_PLATFORM. >> > >> > It looks kind of narrow but it's an option. >> >> Great! >> >> > I wonder how we'll define what's an iommu though. >> >> Hm, it didn't occur to me it could be an issue. I'll try. I rephrased it in terms of address translation. What do you think of this version? The flag name is slightly different too: VIRTIO_F_ACCESS_PLATFORM_NO_TRANSLATION This feature has the same meaning as VIRTIO_F_ACCESS_PLATFORM both when set and when not set, with the exception that address translation is guaranteed to be unnecessary when accessing memory addresses supplied to the device by the driver. Which is to say, the device will always use physical addresses matching addresses used by the driver (typically meaning physical addresses used by the CPU) and not translated further. This flag should be set by the guest if offered, but to allow for backward-compatibility device implementations allow for it to be left unset by the guest. It is an error to set both this flag and VIRTIO_F_ACCESS_PLATFORM. >> > Another idea is maybe something like virtio-iommu? >> >> You mean, have legacy guests use virtio-iommu to request an IOMMU >> bypass? If so, it's an interesting idea for new guests but it doesn't >> help with guests that are out today in the field, which don't have A >> virtio-iommu driver. > > I presume legacy guests don't use encrypted memory so why do we > worry about them at all? They don't use encrypted memory, but a host machine will run a mix of secure and legacy guests. And since the hypervisor doesn't know whether a guest will be secure or not at the time it is launched, legacy guests will have to be launched with the same configuration as secure guests. >> >> > Is there any justification to doing that beyond someone putting >> >> > out slow code in the past? >> >> >> >> The definition of the ACCESS_PLATFORM flag is generic and captures the >> >> notion of memory access restrictions for the device. Unfortunately, on >> >> powerpc pSeries guests it also implies that the IOMMU is turned on >> > >> > IIUC that's really because on pSeries IOMMU is *always* turned on. >> > Platform has no way to say what you want it to say >> > which is bypass the iommu for the specific device. >> >> Yes, that's correct. pSeries guests running on KVM are in a gray area >> where theoretically they use an IOMMU but in practice KVM ignores it. >> It's unfortunate but it's the reality on the ground today. :-/ > > Well it's not just the reality, virt setups need something that > emulated IOMMUs don't provide. That is not uncommon, e.g. > intel's VTD has a "cache mode" field which AFAIK is only used for virt. That's good to know. Thanks for this example. -- Thiago Jung Bauermann IBM Linux Technology Center