Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1619030iog; Tue, 14 Jun 2022 09:30:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uZk3gAMD0hShemev6aQZaJRtHo+GfuMe6M+NfYQnbyZrtbOgcoA/i6ynZjdJRWMWfqQPvc X-Received: by 2002:a17:90a:488c:b0:1c7:b62e:8e8c with SMTP id b12-20020a17090a488c00b001c7b62e8e8cmr5346680pjh.157.1655224253237; Tue, 14 Jun 2022 09:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655224253; cv=none; d=google.com; s=arc-20160816; b=yx2fmbT782SFkruS8RBE7B/QgWU/kgmcx1is6ZJZofQOfzXFfo1hqx2DjNjovGteys /OQM9RZthmzT2MZhS5rQ+PsiwjlTSv8jn/cK1wLOlhE7vtVKHcc9djeddcS1j+6O+gxx BVxpt/GKEx5Zt3KLhXNnP0sr+0WHcdElOUa7EC3HaNEbHns3n+CUxDirh+bHNN+Syjwv RG6kl3uu7xFzMWRMWNegRZ3o7pKwhx8rPxkYEJpebaK+75RsuqYSfxLmOpHBUw4elEdA vN2X7qm8p8p8p/mvVIPQ9XZ3Oqt8xjTwtFKM1CfRwPVnCmQ8yr5FZiUQ4tX8pyG7K2WU k7rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1L/1V22FQTP6Uf5RjDMsd5iGn20Bp4Z0qQsZlN/wiJ8=; b=NekQJsSu200fvDQcmJW3FYJC06DyrfO/xt0ZrsHBpaJv341o24OWrM7fAVsBcd8PlY udxzG5S3MPc4opqpYDNM5yAMLmK8diQ+1mD82Z7ZTWwsmN6kGsmBkhJ4yIkZ2d/zsoiF gEm7CDJfDWFZO4h/eKUVOKQDtMRkZA0axGvACTJILYbFn6bMmv7CRXKhaEBJj554p3dI PSNNxsmMEb6uP1RS7DDOn56fGwuOKvsP6KiwJS57Wsfcm1Dv/BhPw5qXrbMOO4+pLP/6 KwUGqGawaU5GCI92dKXJ+0wVpMrjTAppQX9V8mD5GRhkk4KwDeEu8F1UiZjoojApzv5G KbZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qFmR7YNL; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a2-20020a056a000c8200b0051bac3bbca0si15561770pfv.174.2022.06.14.09.30.33; Tue, 14 Jun 2022 09:30:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@google.com header.s=20210112 header.b=qFmR7YNL; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1344014AbiFNQa0 (ORCPT + 99 others); Tue, 14 Jun 2022 12:30:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241036AbiFNQaZ (ORCPT ); Tue, 14 Jun 2022 12:30:25 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDA3D443F5 for ; Tue, 14 Jun 2022 09:30:23 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id b7so10345577ljr.6 for ; Tue, 14 Jun 2022 09:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1L/1V22FQTP6Uf5RjDMsd5iGn20Bp4Z0qQsZlN/wiJ8=; b=qFmR7YNLv7Th4BWm9n4sQfAo/PamFEtFIgQo01hMs9y/guIfaSpbzw30kSsZXq7LPM RYUpHNijz3++3idrKi0BGIZCrd1Bbpr1Vg8xXkBD2vZkOg8647Nog/rnDpzhNQMjXK0a jhUI/35a1v6xe8BkqWXX0aeSASjUJCpyj2Leoj78w7CQFxDVvyZY3pMB7TufCV6tzuP4 khzu9tkF0h44QUyRaG1Sm+qr0ov6IKXX3MYEJg70A8Y7Nu9W5B/ieOGkqOAXbfc1Qatr cvb7o0Z42kszhW4WBh9cD2Lb8poWxCGMv9Nf2A3RfMGcxE1siyVeHVITwdjWJnE2pIGO AKQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1L/1V22FQTP6Uf5RjDMsd5iGn20Bp4Z0qQsZlN/wiJ8=; b=QPIwRmhDjUYYzxVOcwpcEjb2TBzRUqaPzWufjKuQOBgefDFcTmsrKA/vuX7ORqNPHe zhZbCyRzXVrazm1CPAnazHY0uYgNjWgowyvSx+Hl3AYYad4e1jZmc5FG4/T2JyHQL1Rd 7OLyXmhRqboKWoIi3CWhTVPlPySGxr55ogCryc/7b0HWQt/2qmqmWHO+19piggwtMEGu E4s+VIsIeierQtHLLcSppCvp/Ujim8VhuTYHO2b9MraRl/nW+Un4bX2CZEdKcJV4Bic+ +ig4fbTph9Th4ayPVwfXbgqsbxixup23WD3Iyf1lrwDOxY8gFk4l4W9SycTfvuHEIW2Z D/vw== X-Gm-Message-State: AJIora+4mZ9KVs2nYtmBOxGWbS0UH+P5/s78rARajHTtxajaV+/DY7qY Gj/I4skOsM9z2ccH1k5VRaayOSWFh+uKovFXDMQZBA== X-Received: by 2002:a2e:a385:0:b0:259:ac23:8d15 with SMTP id r5-20020a2ea385000000b00259ac238d15mr926331lje.278.1655224221833; Tue, 14 Jun 2022 09:30:21 -0700 (PDT) MIME-Version: 1.0 References: <20210820155918.7518-1-brijesh.singh@amd.com> <20210820155918.7518-24-brijesh.singh@amd.com> <1cadca0d-c3dc-68ed-075f-f88ccb0ccc0a@amd.com> In-Reply-To: From: Peter Gonda Date: Tue, 14 Jun 2022 10:30:10 -0600 Message-ID: Subject: Re: [PATCH Part2 v5 23/45] KVM: SVM: Add KVM_SNP_INIT command To: "Kalra, Ashish" Cc: Alper Gun , Brijesh Singh , "the arch/x86 maintainers" , LKML , kvm list , "linux-coco@lists.linux.dev" , "linux-mm@kvack.org" , Linux Crypto Mailing List , Thomas Gleixner , Ingo Molnar , Joerg Roedel , "Lendacky, Thomas" , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , "Roth, Michael" , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , Tony Luck , Marc Orr , Sathyanarayanan Kuppuswamy , Pavan Kumar Paluri Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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-crypto@vger.kernel.org On Tue, Jun 14, 2022 at 10:11 AM Kalra, Ashish wrote= : > > [AMD Official Use Only - General] > > > -----Original Message----- > From: Peter Gonda > Sent: Tuesday, June 14, 2022 10:38 AM > To: Kalra, Ashish > Cc: Alper Gun ; Brijesh Singh ; Kalra, Ashish ; the arch/x86 maintainers ; LKML ; kvm list ; linux-coco@lists.linux.dev; linux-mm@kvack.org; Linux Crypto Mailing Lis= t ; Thomas Gleixner ; Ing= o Molnar ; Joerg Roedel ; Lendacky, Thom= as ; H. Peter Anvin ; Ard Biesheuve= l ; Paolo Bonzini ; Sean Christophers= on ; Vitaly Kuznetsov ; Wanpeng Li = ; Jim Mattson ; Andy Lutomirski= ; Dave Hansen ; Sergio Lopez= ; Peter Zijlstra ; Srinivas Pandruva= da ; David Rientjes ; Dov Murik ; Tobin Feldman-Fitzthum ; Borislav Petkov ; Roth, Michael ;= Vlastimil Babka ; Kirill A . Shutemov ; Andi Kleen ; Tony Luck ; Marc = Orr ; Sathyanarayanan Kuppuswamy ; Pavan Kumar Paluri > Subject: Re: [PATCH Part2 v5 23/45] KVM: SVM: Add KVM_SNP_INIT command > > On Mon, Jun 13, 2022 at 6:21 PM Ashish Kalra wrote: > > > > > > On 6/13/22 23:33, Alper Gun wrote: > > > On Mon, Jun 13, 2022 at 4:15 PM Ashish Kalra wrote= : > > >> Hello Alper, > > >> > > >> On 6/13/22 20:58, Alper Gun wrote: > > >>> static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd > > >>> *argp) > > >>>> { > > >>>> + bool es_active =3D (argp->id =3D=3D KVM_SEV_ES_INIT || arg= p->id > > >>>> + =3D=3D KVM_SEV_SNP_INIT); > > >>>> struct kvm_sev_info *sev =3D &to_kvm_svm(kvm)->sev_info; > > >>>> - bool es_active =3D argp->id =3D=3D KVM_SEV_ES_INIT; > > >>>> + bool snp_active =3D argp->id =3D=3D KVM_SEV_SNP_INIT; > > >>>> int asid, ret; > > >>>> > > >>>> if (kvm->created_vcpus) @@ -249,12 +269,22 @@ static > > >>>> int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) > > >>>> return ret; > > >>>> > > >>>> sev->es_active =3D es_active; > > >>>> + sev->snp_active =3D snp_active; > > >>>> asid =3D sev_asid_new(sev); > > >>>> if (asid < 0) > > >>>> goto e_no_asid; > > >>>> sev->asid =3D asid; > > >>>> > > >>>> - ret =3D sev_platform_init(&argp->error); > > >>>> + if (snp_active) { > > >>>> + ret =3D verify_snp_init_flags(kvm, argp); > > >>>> + if (ret) > > >>>> + goto e_free; > > >>>> + > > >>>> + ret =3D sev_snp_init(&argp->error); > > >>>> + } else { > > >>>> + ret =3D sev_platform_init(&argp->error); > > >>> After SEV INIT_EX support patches, SEV may be initialized in the pl= atform late. > > >>> In my tests, if SEV has not been initialized in the platform yet, > > >>> SNP VMs fail with SEV_DF_FLUSH required error. I tried calling > > >>> SEV_DF_FLUSH right after the SNP platform init but this time it > > >>> failed later on the SNP launch update command with > > >>> SEV_RET_INVALID_PARAM error. Looks like there is another > > >>> dependency on SEV platform initialization. > > >>> > > >>> Calling sev_platform_init for SNP VMs fixes the problem in our test= s. > > >> Trying to get some more context for this issue. > > >> > > >> When you say after SEV_INIT_EX support patches, SEV may be > > >> initialized in the platform late, do you mean sev_pci_init()->sev_sn= p_init() ... > > >> sev_platform_init() code path has still not executed on the host BSP= ? > > >> > > > Correct, INIT_EX requires the file system to be ready and there is a > > > ccp module param to call it only when needed. > > > > > > MODULE_PARM_DESC(psp_init_on_probe, " if true, the PSP will be > > > initialized on module init. Else the PSP will be initialized on the > > > first command requiring it"); > > > > > > If this module param is false, it won't initialize SEV on the > > > platform until the first SEV VM. > > > > > Ok, that makes sense. > > > > So the fix will be to call sev_platform_init() unconditionally here in > > sev_guest_init(), and both sev_snp_init() and sev_platform_init() are > > protected from being called again, so there won't be any issues if > > these functions are invoked again at SNP/SEV VM launch if they have > > been invoked earlier during module init. > > >That's one solution. I don't know if there is a downside to the system f= or enabling SEV if SNP is being enabled but another solution could be to ju= st directly place a DF_FLUSH command instead of calling sev_platform_init()= . > > Actually sev_platform_init() is already called on module init if psp_init= _on_probe is not false. Only need to ensure that SNP firmware is initialize= d first with SNP_INIT command. But if psp_init_on_probe is false, sev_platform_init() isn't called down this path. Alper has suggested we always call sev_platform_init() but we could just place an SEV_DF_FLUSH command instead. Or am I still missing something? > > Thanks, > Ashish