Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1690750pxj; Wed, 19 May 2021 11:33:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO3o459DbZEzllnf7ne8G6UD50CK5rQS/4dPo+GKF9LHuXVjru8iVhnL9/fE4BCIxnmMqo X-Received: by 2002:a05:6602:2d8f:: with SMTP id k15mr922076iow.114.1621449198948; Wed, 19 May 2021 11:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621449198; cv=none; d=google.com; s=arc-20160816; b=VVRBxszLDETmXiGQ3q9GzNVVbuENe2yN3XfiGnTwgFBT9mjex1DLZcDQAwufOGp4M4 OYPPixcbFLd/f+NB1mvrwkbPcEVuK5nIrB0UIxG/n48oGXOvbk4Vmn9C5+bDkHNozD4p C5OunYqcgfAGAcf8nVuFzLS4KXgoV9LK70nEtGDyo/CPC6Mrc/wDyMQklU1MRos5zyYr uNufcDsdZik4hD4S+EqKveFBARhDGczi5bm4iCBMPpo+p3b6o4kW/aBnT7nljS8c1UbV A7RwoC8Zo35zbFMq0h0PeY7V/aewZWN5Vc8wyANlzPAFZMGFUxlKDimmffnwlDgISQPR qg4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HRboTMWcVL2UZH3bRp+LA1JCHR25V76yBK5UJMIVTcg=; b=zAjcqogkd5lqar7bCtyk3AyJpYgBiqjJ4UYmUBtiYNhfVN3fsjOGCCMe2MAmlN433b FssnQ9AB4R6+7J9UQxQw9g30sygdQxBNKLmynTrjkINN3kYmflEAKJjA7QyNA4CQ8kLu QaXfjTxuRjXgLSD1ziksyACyVr2qWHz9pXsDWGmC8RGz/Lv3oBgtct0ZyHV/Mpi9tyfD Ty7RYdkZHoRm1Up0/swDuIsSKDX30/+2IhkXcr8Qp1dqEWmuLdIIM+HrubEd53e5tAhH UGXfii8yt2qYEPMFLChTO8h9qxJ401SL887Piq2zGKbSTJnkr18Pbrjv8Hu1Y5s6hcss NXww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QFIb1Zce; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h7si358060ilo.77.2021.05.19.11.33.06; Wed, 19 May 2021 11:33:18 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=QFIb1Zce; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241345AbhERT5D (ORCPT + 99 others); Tue, 18 May 2021 15:57:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239073AbhERT5C (ORCPT ); Tue, 18 May 2021 15:57:02 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F481C061573 for ; Tue, 18 May 2021 12:55:44 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id b9-20020a17090a9909b029015cf9effaeaso2166539pjp.5 for ; Tue, 18 May 2021 12:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=HRboTMWcVL2UZH3bRp+LA1JCHR25V76yBK5UJMIVTcg=; b=QFIb1ZcejdFx8BN6fWQrtd4GLjTXxcmP9rUQldfauaSBQYByinqpDRlYPGIJKvw1tK R7ehaPJJagouMRcWbGQfajGeWDKp7OvHYESj9E0Zf12UPMKyGrkGAmensTzF8xdHhTd9 V65Grakm8ZxCwPchXmcABcSssiB/wJTPkdEVnh7/8op1trpEK4zj+/RY73VaEiV9MaA0 zPdOkYaSK+Irfaae4aPI0/LqMe0aQIzySJWX+iu7IWRwLMYAdkTiagqmLntcPiSc2anv /kctR6hYWv8nCaUUhEHms9ZIKPiC6bPjjAPZg1LBLkpKRW1a6BANRPx79Usts1+Pseiv ivkg== 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:content-transfer-encoding :in-reply-to; bh=HRboTMWcVL2UZH3bRp+LA1JCHR25V76yBK5UJMIVTcg=; b=U+39bWb/9z3wjgWXJ6wrFMUHUVqdylyXyuoTB+P3fYcDLMY8hNg2HeoSmYD+fpB4iC 3NUGxsg8z0IZB9X7TybQ4dU0TqCnenJ1eYl3978/N3l1WxV/vqCAtrQ1DTw2wL9ImVpI 6x8GJyTjkxaFIL7/nht13ftQJTtdgmiv9HDyUWy7VzJWRBULEaQD2SmgfRS6gZZk8Hfc ezBRKxUN//uL8VGm/TPHkjqzLUzes1be1IxpaqaFVwgGISGqLARoIm2oX4W7hc8x2Eqg o02ounXbDsC7RN9wmdf5fURDTGmXtvd/39j4x2bA4DPI1rHnIvHRlt8xisCpgy/3jpZF Q61w== X-Gm-Message-State: AOAM533Br1Bcxal//5iwBWTnDVjZbZdGuk+GozFeKKbCGBCmNk7ezlar kDZD8Qv+Q1Kf5xyq/buypglj8Q== X-Received: by 2002:a17:90a:66c3:: with SMTP id z3mr7121930pjl.196.1621367743910; Tue, 18 May 2021 12:55:43 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id w206sm3020841pfc.61.2021.05.18.12.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 12:55:43 -0700 (PDT) Date: Tue, 18 May 2021 19:55:39 +0000 From: Sean Christopherson To: Kuppuswamy Sathyanarayanan Cc: Peter Zijlstra , Andy Lutomirski , Dave Hansen , Tony Luck , Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Dan Williams , Raj Ashok , linux-kernel@vger.kernel.org, Kai Huang , Sean Christopherson Subject: Re: [RFC v2-fix 1/1] x86/tdx: Make DMA pages shared Message-ID: References: <1ccf5e60d2d79308d50f93c8c3b32b1394bc7baf.1619458733.git.sathyanarayanan.kuppuswamy@linux.intel.com> <20210518011912.259112-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210518011912.259112-1-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 17, 2021, Kuppuswamy Sathyanarayanan wrote: > From: "Kirill A. Shutemov" > > Intel TDX doesn't allow VMM to access guest memory. Any memory ^ |- private And to be pedantic, the VMM can _access_ guest private memory all it wants, it just can't decrypt guest private memory. > that is required for communication with VMM must be shared > explicitly by setting the bit in page table entry. And, after > setting the shared bit, the conversion must be completed with > MapGPA TDVMALL. The call informs VMM about the conversion and > makes it remove the GPA from the S-EPT mapping. The VMM is _not_ required to remove the GPA from the S-EPT. E.g. if the VMM wants to, it can leave a 2mb private page intact and create a 4kb shared page translation within the same range (ignoring the shared bit). > The shared memory is similar to unencrypted memory in AMD SME/SEV > terminology but the underlying process of sharing/un-sharing the memory is > different for Intel TDX guest platform. > > SEV assumes that I/O devices can only do DMA to "decrypted" > physical addresses without the C-bit set.  In order for the CPU > to interact with this memory, the CPU needs a decrypted mapping. > To add this support, AMD SME code forces force_dma_unencrypted() > to return true for platforms that support AMD SEV feature. It will > be used for DMA memory allocation API to trigger > set_memory_decrypted() for platforms that support AMD SEV feature. > > TDX is similar.  TDX architecturally prevents access to private TDX doesn't prevent accesses. If hardware _prevented_ accesses then we wouldn't have to deal with the #MC mess. > guest memory by anything other than the guest itself. This means > that any DMA buffers must be shared. > > So create a new file mem_encrypt_tdx.c to hold TDX specific memory > initialization code, and re-define force_dma_unencrypted() for > TDX guest and make it return true to get DMA pages mapped as shared. > > __set_memory_enc_dec() is now aware about TDX and sets Shared bit > accordingly following with relevant TDVMCALL. > > Also, Do TDACCEPTPAGE on every 4k page after mapping the GPA range when This should call out that the current TDX spec only supports 4kb AUG/ACCEPT. On that topic... are there plans to support 2mb and/or 1gb TDH.MEM.PAGE.AUG? If so, will TDG.MEM.PAGE.ACCEPT also support 2mb/1gb granularity? > converting memory to private.  If the VMM uses a common pool for private > and shared memory, it will likely do TDAUGPAGE in response to MAP_GPA > (or on the first access to the private GPA), What the VMM does or does not do is irrelevant. What matters is what the VMM is _allowed_ to do without violating the GHCI. Specifically, the VMM is allowed to unmap a private page in response to MAP_GPA to convert to a shared page. If the GPA (range) was already mapped as an active, private page, the host VMM may remove the private page from the TD by following the “Removing TD Private Pages” sequence in the Intel TDX-module specification [3] to safely block the mapping(s), flush the TLB and cache, and remove the mapping(s). That would also provide a nice segue into the "already accepted" error below. > in which case TDX-Module will hold the page in a non-present "pending" state > until it is explicitly accepted. > > BUG() if TDACCEPTPAGE fails (except the above case) What above case? The code handles the case where the page was already accepted, but the changelog doesn't talk about that at all. > as the guest is completely hosed if it can't access memory.