Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp754834imi; Thu, 21 Jul 2022 10:15:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uimUkgsl+iJlQfVyRqbUBP+OC2jfkQjI3OJOUlkcMxNh7+/n10YKtSfEPdbIdSDAvkwwyi X-Received: by 2002:a17:907:7396:b0:72d:a080:86a9 with SMTP id er22-20020a170907739600b0072da08086a9mr38920908ejc.49.1658423729861; Thu, 21 Jul 2022 10:15:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658423729; cv=none; d=google.com; s=arc-20160816; b=VcdrgWWSLTTcJfn22L9nropYDsURd4T2qw7SDz4lKzuVu7DrcvYkAd8IU2Wihi5Loj nPB/qKffZtUANSjg73SMU2cZthKblskictM8mycQKyTx4iLk5qecMmPksuacKQ8bqgfW Q0tZBCJnfz8HLNOMelyiiULcUWXryyl2UECz0pyHN95SkKx6jk0Rq2Xi6X8LlDpf353K 19CSz0f7XEonralt86HBJHjj4C75c8min1gBC03JWePQJ+BYRinbZJgcmpk7o7fPXtjN cK7l02eeMHXBJuRpmE+eIJd79bzDpMlK+TkT2cjV0/BkFkUcE4xiU8uUnZIRfej6ylom ibQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=EFyc/IZY2b7zEiQJsg67a2Wdu1r7NFYuYOWstFphxjM=; b=LxyjWkjwUtux3VfxTmUwscwO2Rz+18s+3bYybhpZw/DIKHxlebKTEcjXr8kVp6vl92 PtwdjUBIBNuaEuAOgh6cuXXZHY3KYidW3emmiZiYhEY+cQ9RXG9xNnnJax7KkzAMtj5R eRycO3oXo9R55ebeVhC6rHPZl98yXybkyPJTmLwZkKsEVLAw+oeyJf0hPYYLuBG1jJr3 ruQuU83LdcsawH2JrgAqCySKUTP2eRU1ah7A+1VPrhgbqpYPdbWn1foRqcr1VBhkpZsN ne9OuixjBqrIsCpZtIz7GkTLkFTKNUVtxXiCGJGy4DKLgKc6M+cA/W4tAFFZ/uPXCcyC wlZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g7gyPnXq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e39-20020a056402332700b0043bc8f2015esi1685256eda.603.2022.07.21.10.15.04; Thu, 21 Jul 2022 10:15:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g7gyPnXq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231889AbiGUQmz (ORCPT + 99 others); Thu, 21 Jul 2022 12:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbiGUQmx (ORCPT ); Thu, 21 Jul 2022 12:42:53 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79648743DC for ; Thu, 21 Jul 2022 09:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658421772; x=1689957772; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=Grj6Db995/Rp4smNtuo4xU1C5cdPHv5qH/01R47s5tg=; b=g7gyPnXqlgy/BHvGnnhCo36p6+5MCtKMWcJwTKUF0NG8p2/3+ZHbp0WZ ns4Mecakucl7dARXvjdC3zcXAFfnRlMgFgUb+qf2/QZNEJ91KfP61MZNX LgDCRvc7a3ANAc+oVNLNzCOxq82ygXbToLnaGlfbPEBq0FNjvDC0ul7rS B+mBbgehAxc4Lr5hhFWBHONWLnf5dUvwiiLtMtshm222YeWcoej43kwpD 9qbfD9xJJY4CqBngnFth/64+YvSHV3PADM1p/VUUK7gYwLWCOl4lUu6d+ ikimw8QsKYTQge4cc4ZIf3hvm9UUx7AgPe/wTtYwh6xG81HIRAm44NvCw g==; X-IronPort-AV: E=McAfee;i="6400,9594,10415"; a="348799574" X-IronPort-AV: E=Sophos;i="5.93,183,1654585200"; d="scan'208";a="348799574" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2022 09:42:52 -0700 X-IronPort-AV: E=Sophos;i="5.93,183,1654585200"; d="scan'208";a="598527821" Received: from sattaran-mobl1.amr.corp.intel.com (HELO [10.212.246.186]) ([10.212.246.186]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2022 09:42:51 -0700 Message-ID: Date: Thu, 21 Jul 2022 09:42:51 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.11.0 Subject: Re: [PATCH v8 5/5] x86/tdx: Add Quote generation support Content-Language: en-US To: Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H . Peter Anvin" , "Kirill A . Shutemov" , Tony Luck , Andi Kleen , Kai Huang , Wander Lairson Costa , Isaku Yamahata , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, linux-kernel@vger.kernel.org References: <20220609025220.2615197-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20220609025220.2615197-6-sathyanarayanan.kuppuswamy@linux.intel.com> From: Sathyanarayanan Kuppuswamy In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dave, On 7/21/22 9:08 AM, Dave Hansen wrote: > On 6/8/22 19:52, Kuppuswamy Sathyanarayanan wrote: >> For shared buffer allocation, alternatives like using the DMA API is >> also considered. Although it simpler to use, it is not preferred because >> dma_alloc_*() APIs require a valid bus device as argument, which would >> need converting the attestation driver into a platform device driver. >> This is unnecessary, and since the attestation driver does not do real >> DMA, there is no need to use real DMA APIs. > > Let's actually try to walk through the requirements for the memory > allocation here. > > 1. The guest kernel needs to allocate some guest physical memory > for the attestation data buffer Physically contiguous memory. > 2. The guest physical memory must be mapped by the guest so that > it can be read/written. > 3. The guest mapping must be a "TDX Shared" mapping. Since all > guest physical memory is "TDX Private" by default, something > must convert the memory from Private->Shared. > 4. If there are alias mappings with "TDX Private" page table > permissions, those mappings must never be used while the page is > in its shared state. > 4a. load_unaligned_zeropad() must be prevented from being used > on the page immediately preceding a Private alias to a Shared > page. > 5. Actions that increasingly fracture the direct map must be avoided. > Attestation may happen many times and repeated allocations that > fracture the direct map have performance consequences. > 6. A softer requirement: presuming that bounce buffers won't be used > for TDX devices *forever*, it would be nice to use a mechanism that > will continue to work on systems that don't have swiotlb on. > Other than the above-mentioned correction, the rest of the requirements are correct. > I think we've talked about three different solutions: > > == vmalloc() == > > So, let's say we used a relatively plain vmalloc(). That's great for > #1->#3 as long as the vmalloc() mapping gets the "TDX Shared" bit set > properly on its PTEs. But, it falls over for *either* #4 or #5. If it > leaves the direct map alone, it's exposed to load_unaligned_zeropad(). > If it unmaps the memory from the direct map, it runs afoul of #5 Since we need physically contiguous memory, vmalloc is not preferred. > > == order-1 + vmap() == > > Let's now consider a vmalloc() variant: allocate a bunch of order-1 > pages and vmap() page[1], leaving page[0] as a guard page against > load_unaligned_zeropad() on the direct map. That works, but it's an > annoying amount of code. > > == swiotlb pages == > > Using the swiotlb bounce buffer pages is the other proposed option. > They already have a working kernel mapping and have already been > converted. They are mitigated against load_unaligned_zeropad(). They > do cause direct map fracturing, but only once since they're allocated > statically. They don't increasingly degrade things. It's a one-time > cost. Their interaction with #6 is not great. > > Did I miss anything? Does that accurately capture where we are? -- Sathyanarayanan Kuppuswamy Linux Kernel Developer