Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp486433pxb; Wed, 1 Sep 2021 03:30:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyP3qgl9VrzXpB2JF/3KydzE/MW85lDEMVDrnm+HpQ2PEauLE1O302RskrxCymHR1vYKKHi X-Received: by 2002:a17:906:b08e:: with SMTP id x14mr35366932ejy.40.1630492243918; Wed, 01 Sep 2021 03:30:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630492243; cv=none; d=google.com; s=arc-20160816; b=u2SdAydx7lFGMqJ3uqg0Z5mJ3Py7bWuWtiejghyMT4l5DQVTPh+Rg9k7TMzaY059dm VGp/T1E2O2M50KnZdoPk+jy2+2qdyZ9U/RS3L+eTc2NvjRkJezurfJg78Cz5MkJG/3hU btllND78IPz4x1M85ZccEyp/GTgcR6B5XwaPhT0hjgCi9TA3s6TG2yUELhWsegz4DYwf KSe0bKX10QG6BhKhcdgogfFoN2C+SJ+jz9aSXHgEk6eSlRtKy/bhxUvFqIH+BOUYB96P Kyx3b/pP4EooIvO2cdVkp+dNBg3/VZ21YEa8bVnnqDhCxzqw2FS5iCFdypiOFmzNwU/r c+rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=d6duf1gxVCY23Bp7w39Un3cWbozVgeNldhEFJU0CO/k=; b=Ufmv+BUw29he6grtpDQzp1HDa2y0Q0PZxQwXWJGuz2HVbp0lMGfwzI03oQ3yNqjwHv g5F2WkD0XUi9SPH9aJlrQ38CVCiAu6z2evYszkUVxIqY3Agj1ZdxnfECZWYUfp2SQEGN V7WfiYskAhH+vTugXSob/ZS968jZsoobLbOXYXdwTK+4jg2XCb9uHPm32aR7ltdKcUgt HmVqfruT2SMnU5ScoxSn3Z46g62AhyIj6xlZ1suI4dz+olV1Nz9QU0Ue67FhOiy05RkS lLb8ktzrFgi4DuSQ1faO3eN+og0m2k0/6p4AWcVi35iG/ZX2EkOsPeP2Tb8Yz3QFdc6h 4DpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm23si19848805edb.174.2021.09.01.03.29.53; Wed, 01 Sep 2021 03:30:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234719AbhIAKZs (ORCPT + 99 others); Wed, 1 Sep 2021 06:25:48 -0400 Received: from mga03.intel.com ([134.134.136.65]:31593 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231903AbhIAKZr (ORCPT ); Wed, 1 Sep 2021 06:25:47 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10093"; a="218758489" X-IronPort-AV: E=Sophos;i="5.84,369,1620716400"; d="scan'208";a="218758489" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2021 03:24:50 -0700 X-IronPort-AV: E=Sophos;i="5.84,369,1620716400"; d="scan'208";a="645686130" Received: from zhibosun-mobl2.ccr.corp.intel.com (HELO localhost) ([10.255.31.93]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2021 03:24:40 -0700 Date: Wed, 1 Sep 2021 18:24:37 +0800 From: Yu Zhang To: Andy Lutomirski Cc: David Hildenbrand , Sean Christopherson , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm list , Linux Kernel Mailing List , Borislav Petkov , Andrew Morton , Joerg Roedel , Andi Kleen , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , "Peter Zijlstra (Intel)" , Ingo Molnar , Varad Gautam , Dario Faggioli , the arch/x86 maintainers , linux-mm@kvack.org, linux-coco@lists.linux.dev, "Kirill A. Shutemov" , "Kirill A . Shutemov" , Sathyanarayanan Kuppuswamy , Dave Hansen Subject: Re: [RFC] KVM: mm: fd-based approach for supporting KVM guest private memory Message-ID: <20210901102437.g5wrgezmrjqn3mvy@linux.intel.com> References: <20210824005248.200037-1-seanjc@google.com> <307d385a-a263-276f-28eb-4bc8dd287e32@redhat.com> <20210827023150.jotwvom7mlsawjh4@linux.intel.com> <8f3630ff-bd6d-4d57-8c67-6637ea2c9560@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8f3630ff-bd6d-4d57-8c67-6637ea2c9560@www.fastmail.com> User-Agent: NeoMutt/20171215 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 31, 2021 at 09:53:27PM -0700, Andy Lutomirski wrote: > > > On Thu, Aug 26, 2021, at 7:31 PM, Yu Zhang wrote: > > On Thu, Aug 26, 2021 at 12:15:48PM +0200, David Hildenbrand wrote: > > > Thanks a lot for this summary. A question about the requirement: do we or > > do we not have plan to support assigned device to the protected VM? > > > > If yes. The fd based solution may need change the VFIO interface as well( > > though the fake swap entry solution need mess with VFIO too). Because: > > > > 1> KVM uses VFIO when assigning devices into a VM. > > > > 2> Not knowing which GPA ranges may be used by the VM as DMA buffer, all > > guest pages will have to be mapped in host IOMMU page table to host pages, > > which are pinned during the whole life cycle fo the VM. > > > > 3> IOMMU mapping is done during VM creation time by VFIO and IOMMU driver, > > in vfio_dma_do_map(). > > > > 4> However, vfio_dma_do_map() needs the HVA to perform a GUP to get the HPA > > and pin the page. > > > > But if we are using fd based solution, not every GPA can have a HVA, thus > > the current VFIO interface to map and pin the GPA(IOVA) wont work. And I > > doubt if VFIO can be modified to support this easily. > > > > > > Do you mean assigning a normal device to a protected VM or a hypothetical protected-MMIO device? > > If the former, it should work more or less like with a non-protected VM. mmap the VFIO device, set up a memslot, and use it. I'm not sure whether anyone will actually do this, but it should be possible, at least in principle. Maybe someone will want to assign a NIC to a TDX guest. An NVMe device with the understanding that the guest can't trust it wouldn't be entirely crazy ether. > > If the latter, AFAIK there is no spec for how it would work even in principle. Presumably it wouldn't work quite like VFIO -- instead, the kernel could have a protection-virtual-io-fd mechanism, and that fd could be bound to a memslot in whatever way we settle on for binding secure memory to a memslot. > Thanks Andy. I was asking the first scenario. Well, I agree it is doable if someone really want some assigned device in TD guest. As Kevin mentioned in his reply, HPA can be generated, by extending VFIO with a new mapping protocol which uses fd+offset, instead of HVA. Another issue is current TDX does not support DMA encryption, and only shared GPA memory shall be mapped in the VT-d. So to support this, KVM may need to work with VFIO to dynamically program host IOPT(IOMMU Page Table) when TD guest notifies a shared GFN range(e.g., with a MAP_GPA TDVMCALL), instead of prepopulating the IOPT at VM creation time, by mapping entire GFN ranges of a guest. So my inclination would be to just disallow using of VFIO device in TDX first, until we have real requirement(with above enabling work finished). B.R. Yu