Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp808377pxv; Thu, 15 Jul 2021 16:48:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvoKfuTiFPAryl44Jdx9eftSO7i1ahzGqaPAkrCFHnsZ9tYwUnC3fCDRc5abJcyo+5WoYo X-Received: by 2002:a92:d388:: with SMTP id o8mr4286893ilo.247.1626392930128; Thu, 15 Jul 2021 16:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626392930; cv=none; d=google.com; s=arc-20160816; b=t/LXmaCPV8Rwr86bXIx06OZ94lD1ZUyzbO11BjM0UaNbFBZuV39tQVfeQo8fhx/ruR ChbEghFojtNANm3CUKPm5QSzda0lXQWEw0l6xWoTNU4OrlEPcMkwDL6VCPyoOJsQtIRT X27cMMifJbmbZ1o7LN4UtXa+0BID2Uhrx/wiyfAkjR5cIATkrSLuHvUwcbY9tAGXSuzo XiBSe+562dkDYuvCr9AJFZz0LawyDCvudbJaiuf7d0qXOCiwCYEqUz6q3hHWMJgMpLw9 TJIJ5e2T5kzJsEOu5VQqwvM5PILz1l9q+8jNhFY1XROvIvlLjzQoxrFbYmwnTxe2P28i j4/g== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5OQMDn6Hx/yHVRBDOLcOoarZgTpJ6ou0lJ0Voq0OG4M=; b=xFhqDyWQFiArvXeGTNCtkaXht9KZlqi9NbT5x0p1YDka0NuZqr7O2fBkYYkZCQey8q H4KoVRapDbLK+1nkTXCNWHshVGXE5iWv0loECYQf8qsoxbzQsCl+PE9IuQLP3tWwoJSV cj2VQfxlG4PLB+ShcJVomw76ORLODGo3H9pxowPfp2l5u4KBAMR7DFdmi3VrbbzcrfkT 4PEj3W/SJ7xePXbbqW9zy12Mj5w4Bt68tYx99aJfqNhSduW7X5DJFGDLPejpjeJuwsXm SVn5KR0JOyaM362Anb81+IKF0DWt3VD/lz319dR+8Xat4/nyJ37UgIPeYi/5H9YZnSWW 9cBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Xerp+3Ma; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-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 w5si8940470ilh.139.2021.07.15.16.48.26; Thu, 15 Jul 2021 16:48:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=Xerp+3Ma; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-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 S232437AbhGOXvS (ORCPT + 99 others); Thu, 15 Jul 2021 19:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232427AbhGOXvS (ORCPT ); Thu, 15 Jul 2021 19:51:18 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66599C061764 for ; Thu, 15 Jul 2021 16:48:24 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id 37so8260116pgq.0 for ; Thu, 15 Jul 2021 16:48:24 -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:in-reply-to; bh=5OQMDn6Hx/yHVRBDOLcOoarZgTpJ6ou0lJ0Voq0OG4M=; b=Xerp+3Ma+7CKr4/78JI541G8uYD8//jwvClMOF/fOO7QmiQm8HAEUnu6NpDbBLMH1q bZGV9qTn+NrOGGYaOzCjTB7B/aPpvd5It43hKuUVskOmztUVNBp7D+395FsS2sQvlrxq xVAo8FpFCDhowTVg4hGaiMCdbGyqn6qUNM0miSvgPCaSI49UBGL5vj48ibmF6+Rb17X0 w7C8AuBB8wkZlc1aeNQ5K9KigBlX9jYvbv1ccsercnerPpuW03IdweX4DvdjBnQR82bX e0jajjskDBGjMsxL7Fj/B+zCTGGj135zbVxs9kViMAV8ZYC/Kcwbxlf9wsPPlckGHHm4 ds+Q== 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=5OQMDn6Hx/yHVRBDOLcOoarZgTpJ6ou0lJ0Voq0OG4M=; b=EBUlcDuqe3peUVRjLjk/Jk6LFGJbeNZaqpo7oFVzfR+ye/mlgqYWe9UUrncM9dz7T4 mIwSK3V5EuWdpsoGhm9zFWp5uiyMu4hQkkWezhpaksQY7mu5D370PT83w7HwcxIT/8rV 6sE8ryST77hHsbzzgUA9VyxKpeoOHBx9+rEdV9jWzZiNRxRIGoBxz9vZTJVFjr/Aks2i gnvqbZZU45HXOGVapvXWshwqCkl3XX1srgjuQEhudyrOwWZvaqZntOc/uxPwNamujy/Z wSlF9Osb6cNoc5AaL0QVYvvlQt4Qt853Ochb2TTNE7Bm4RCPXA/nF2t5LbR39Eji5Hd+ yTqg== X-Gm-Message-State: AOAM533gU/MaxHvFoyBl53Le5ejEsfQgu7nlbxynIAohwVQp3nJXrcpK nf7cglYG40483tglTPZadYDrRA== X-Received: by 2002:a63:4e5d:: with SMTP id o29mr275121pgl.379.1626392903572; Thu, 15 Jul 2021 16:48:23 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id o184sm8719553pga.18.2021.07.15.16.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 16:48:22 -0700 (PDT) Date: Thu, 15 Jul 2021 23:48:19 +0000 From: Sean Christopherson To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , tony.luck@intel.com, npmccallum@redhat.com, brijesh.ksingh@gmail.com Subject: Re: [PATCH Part2 RFC v4 15/40] crypto: ccp: Handle the legacy TMR allocation when SNP is enabled Message-ID: References: <20210707183616.5620-1-brijesh.singh@amd.com> <20210707183616.5620-16-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210707183616.5620-16-brijesh.singh@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Jul 07, 2021, Brijesh Singh wrote: > The behavior and requirement for the SEV-legacy command is altered when > the SNP firmware is in the INIT state. See SEV-SNP firmware specification > for more details. > > When SNP is INIT state, all the SEV-legacy commands that cause the > firmware to write memory must be in the firmware state. The TMR memory It'd be helpful to spell out Trusted Memory Region, I hadn't seen that term before and for some reason my brain immediately thought "xAPIC register!". > is allocated by the host but updated by the firmware, so, it must be > in the firmware state. Additionally, the TMR memory must be a 2MB aligned > instead of the 1MB, and the TMR length need to be 2MB instead of 1MB. > The helper __snp_{alloc,free}_firmware_pages() can be used for allocating > and freeing the memory used by the firmware. None of this actually states what the patch does, e.g. it's not clear whether all allocations are being converted to 2mb or just the SNP. Looks like it's just SNP. Something like this? Allocate the Trusted Memory Region (TMR) as a 2mb sized/aligned region when SNP is enabled to satisfy new requirements for SNP. Continue allocating a 1mb region for !SNP configuration. > While at it, provide API that can be used by others to allocate a page > that can be used by the firmware. The immediate user for this API will > be the KVM driver. The KVM driver to need to allocate a firmware context > page during the guest creation. The context page need to be updated > by the firmware. See the SEV-SNP specification for further details. ... > @@ -1153,8 +1269,10 @@ static void sev_firmware_shutdown(struct sev_device *sev) > /* The TMR area was encrypted, flush it from the cache */ > wbinvd_on_all_cpus(); > > - free_pages((unsigned long)sev_es_tmr, > - get_order(SEV_ES_TMR_SIZE)); > + > + __snp_free_firmware_pages(virt_to_page(sev_es_tmr), > + get_order(sev_es_tmr_size), > + false); > sev_es_tmr = NULL; > } > > @@ -1204,16 +1322,6 @@ void sev_pci_init(void) > sev_update_firmware(sev->dev) == 0) > sev_get_api_version(); > > - /* Obtain the TMR memory area for SEV-ES use */ > - tmr_page = alloc_pages(GFP_KERNEL, get_order(SEV_ES_TMR_SIZE)); > - if (tmr_page) { > - sev_es_tmr = page_address(tmr_page); > - } else { > - sev_es_tmr = NULL; > - dev_warn(sev->dev, > - "SEV: TMR allocation failed, SEV-ES support unavailable\n"); > - } > - > /* > * If boot CPU supports the SNP, then first attempt to initialize > * the SNP firmware. > @@ -1229,6 +1337,16 @@ void sev_pci_init(void) > } > } > > + /* Obtain the TMR memory area for SEV-ES use */ > + tmr_page = __snp_alloc_firmware_pages(GFP_KERNEL, get_order(sev_es_tmr_size), false); > + if (tmr_page) { > + sev_es_tmr = page_address(tmr_page); > + } else { > + sev_es_tmr = NULL; > + dev_warn(sev->dev, > + "SEV: TMR allocation failed, SEV-ES support unavailable\n"); > + } I think your patch ordering got a bit wonky. AFAICT, the chunk that added sev_snp_init() and friends in the previous patch 14 should have landed above the TMR allocation, i.e. the code movement here should be unnecessary. > /* Initialize the platform */ > rc = sev_platform_init(&error); > if (rc && (error == SEV_RET_SECURE_DATA_INVALID)) { ... > @@ -961,6 +965,13 @@ static inline int snp_guest_dbg_decrypt(struct sev_data_snp_dbg *data, int *erro > return -ENODEV; > } > > +static inline void *snp_alloc_firmware_page(gfp_t mask) > +{ > + return NULL; > +} > + > +static inline void snp_free_firmware_page(void *addr) { } Hmm, I think we should probably bite the bullet and #ifdef and/or stub out large swaths of svm/sev.c before adding SNP support. sev.c is getting quite massive, and we're accumulating more and more stubs outside of KVM because its SEV code is compiled unconditionally.