Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1743054iog; Tue, 14 Jun 2022 12:16:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoirXdPnYG0R1zjz7vD00HgoldRVu3OsRaLPCwk0qgR8SThbMfLxT2VYE7Aqn5NaDyMZGU X-Received: by 2002:a17:902:c651:b0:164:127:cdfd with SMTP id s17-20020a170902c65100b001640127cdfdmr5967453pls.154.1655234162936; Tue, 14 Jun 2022 12:16:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655234162; cv=none; d=google.com; s=arc-20160816; b=PPkLYJ4A8hP9osII4Q8Fu7qWc+PjJU2FbPYhlYCjCwmFyKL4RvHD/jnRLmRZD3FelB 5+iFpH8lZOyFpB4/wTttQR30C54HYqSDeE4lF9TTIYqr34qimavheXHFH1qhRJCY3b6G qJbvOy6TVjU9GVbYHVmpDfeTOCWz5jtpNGL1SnPSp5D1d50EZGR9KWQa7z4LDRVjqWeG sOmaS3wJjcPBOFMUeJIT2hPoNUcOOQUlhgV7rFAsAJrANCyF4XjXG1j3x+KhIJxuaSgC rD+yjmPV1KUCTKx9fSnetCEk6B7gVsHHh8fOKJyr5h/QBOG4n/YMw1PLL4e6SCNhRPVu dFaQ== 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=UcrIrSk5Swd+nvSBeuVYmeu1PhD4aHQkIlKjjep/U/8=; b=gN/ic+FsNDwEHh6+8SZJZh6y64FPTdpMIj9NdgpKVgHxuQ2oNXHc6n0DrQ0QnaKsaA cWJ57ttXfswhMpGNrWNSZW/j9Qn38eT+OpYd8X/4IOga0z4148MLWTgQ1ZRHYGZXwnzO oeYpJf2N/HbYp5g3wwRDOzBKMJZznC4O6lkjbtWFn58RWnhCLnmAGLqIktFXkYzkV/Fv 2W06n4NRe80OwexK4M0wkBvHH/xqfKDd6XRLvrZVWe+oMDI9Fku8byWnUIbYLylmmpV4 8mCrS1iknxt7DeqQB2w2ONuuFqvyfD8njZSNejb8WuUXDo8U/aijKFRQwMspVa5WGgSt Xdww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gXwMwJIL; 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 i63-20020a638742000000b003fa67e446fasi15704136pge.549.2022.06.14.12.15.27; Tue, 14 Jun 2022 12:16:02 -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=gXwMwJIL; 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 S1357917AbiFNTBT (ORCPT + 99 others); Tue, 14 Jun 2022 15:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357923AbiFNTA4 (ORCPT ); Tue, 14 Jun 2022 15:00:56 -0400 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A410B66 for ; Tue, 14 Jun 2022 11:58:31 -0700 (PDT) Received: by mail-io1-xd30.google.com with SMTP id i16so10376263ioa.6 for ; Tue, 14 Jun 2022 11:58:31 -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=UcrIrSk5Swd+nvSBeuVYmeu1PhD4aHQkIlKjjep/U/8=; b=gXwMwJILGwkplNokon5zOdE2RQ1Qwvww6dSg4uCJAviXw5icGHnP09W33KGxS29FEj lQmoqXPAK+SY+SmDsCO/uWap3n/Movp3Wt4rOczfaAgqPoAhpMfjyUVxCTjKBao8mOHb xNde4umF8iDkfU55A43FTeYvB/iSrFz+vmF/5fknkICPrZ4tHShvwl3ctm6Jte1duC9w vGIuBcYhURzJCMJ0clNbF4yJswoL63YXLGidU23WgOeR+iaDgxtj7l+QnDEogu1l+H7l NemjvgzAPpKbQcnFV8aV5xNVWnYnLA+pLXhiZY49PjBL982JWxAL2SISJKdAwponp74I homg== 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=UcrIrSk5Swd+nvSBeuVYmeu1PhD4aHQkIlKjjep/U/8=; b=u/YWFJQrI71o73Cyk69VbNnrS4zBSPF/HmPT1gXrgO+0zouSggYG1z4p/JlIm4GCrM 5kdhWJ9sIQghjuVnNnc9/GzA9PaJrto79LsKb6YcpJOx246PWEgFGkSLe4PNOR2z5e4T yY0ycQsQZLdwqitqRLYSlMyvgRCAeWnqU3KGPASmROJt5jGxQZN1t8SKMFl2I27vpZEe Sc+3O609XD5miA2kEp0gEMsBR1k8bRdHMJzqr/I/WI7puA2yyfc7ekuTvuBNOmt5rHCm 8+o4zbrKU90UoGfkLGrShChEcj3NkUBbhKAnUT63kfSjLn0wQFv4MnHnpMGaOADxAZ9S vZqg== X-Gm-Message-State: AOAM533zIJ6qPi+VUGdPa2tGYc7BvPW2gOdXjJPqmIxCMUIEE4aM5jdC wMSVOY5siFtU+JG9IS7vLh8xfxF1lswyqOgAPU5+Kg== X-Received: by 2002:a05:6638:13d5:b0:331:a6f2:3dbf with SMTP id i21-20020a05663813d500b00331a6f23dbfmr3907072jaj.9.1655233110381; Tue, 14 Jun 2022 11:58:30 -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: Alper Gun Date: Tue, 14 Jun 2022 11:58:19 -0700 Message-ID: Subject: Re: [PATCH Part2 v5 23/45] KVM: SVM: Add KVM_SNP_INIT command To: "Kalra, Ashish" Cc: Peter Gonda , "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 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=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-crypto@vger.kernel.org Let me summarize what I tried. 1- when using psp_init_probe false, the SNP VM fails in SNP_LAUNCH_START step with error SEV_RET_DFFLUSH_REQUIRED(15). 2- added SEV_DF_FLUSH just after SNP platform init and it didn't fail in launch start but failed later during SNP_LAUNCH_UPDATE with SEV_RET_INVALID_PARAM(22) 3- added SNP_DF_FLUSH just after SNP platform init and it failed again during SNP_LAUNCH_UPDATE with SEV_RET_INVALID_PARAM(22) 4- added sev_platform_init for SNP VMs and it worked. For me DF_FLUSH alone didn' help boot a VM. I don't know yet why sev platform status impacts the SNP VM, but sev_platform_init fixes the problem. On Tue, Jun 14, 2022 at 10:16 AM Kalra, Ashish wrote= : > > [AMD Official Use Only - General] > > Hello Alper, Peter, > > -----Original Message----- > From: Peter Gonda > Sent: Tuesday, June 14, 2022 11:30 AM > To: Kalra, Ashish > Cc: Alper Gun ; Brijesh Singh ; the arch/x86 maintainers ; LKML ; kvm list ; linux-coco@lists.linux.dev; linux-m= m@kvack.org; Linux Crypto Mailing List ; Thom= as Gleixner ; Ingo Molnar ; Joerg Roe= del ; Lendacky, Thomas ; H. Peter= Anvin ; Ard Biesheuvel ; Paolo Bonzini ; Sean Christopherson ; Vitaly Kuznets= ov ; Wanpeng Li ; Jim Mattson <= jmattson@google.com>; Andy Lutomirski ; Dave Hansen ; Sergio Lopez ; Peter Zijlstra ; Srinivas Pandruvada ; David Rientjes ; Dov Murik ; Tobin Feldman-Fitzthum ; Borislav Petkov ; = Roth, Michael ; Vlastimil Babka ; Kir= ill A . Shutemov ; Andi Kleen ; T= ony Luck ; Marc Orr ; Sathyanaraya= nan Kuppuswamy ; Pavan Kumar Pa= luri > Subject: Re: [PATCH Part2 v5 23/45] KVM: SVM: Add KVM_SNP_INIT command > > On Tue, Jun 14, 2022 at 10:11 AM Kalra, Ashish wro= te: > > > > [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 > > 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 > > > > 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 wro= te: > > > >> 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 || > > > >>>> + argp->id =3D=3D KVM_SEV_SNP_INIT); > > > >>>> struct kvm_sev_info *sev =3D &to_kvm_svm(kvm)->sev_inf= o; > > > >>>> - 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 = platform 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 te= sts. > > > >> 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_= snp_init() ... > > > >> sev_platform_init() code path has still not executed on the host B= SP ? > > > >> > > > > 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= for enabling SEV if SNP is being enabled but another solution could be to = just directly place a DF_FLUSH command instead of calling sev_platform_init= (). > > > > Actually sev_platform_init() is already called on module init if psp_in= it_on_probe is not false. Only need to ensure that SNP firmware is initiali= zed first with SNP_INIT command. > > > But if psp_init_on_probe is false, sev_platform_init() isn't called dow= n 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 som= ething? > > >After SEV INIT_EX support patches, SEV may be initialized in the platfor= m 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. > > Are you getting the DLFLUSH_REQUIRED error after the SNP activate command= ? > > Also did you use the SEV_DF_FLUSH command or the SNP_DF_FLUSH command ? > > With SNP you need to use SNP_DF_FLUSH command. > > Thanks, > Ashish