Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp932284iog; Mon, 13 Jun 2022 16:36:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbbY1uQ5V+S++wt1DDACx5ouHnw2SyT+A5tH2AcYsaeLsleIls5Mw4sH83sa6Rz+VG+49O X-Received: by 2002:a63:ec0f:0:b0:3fd:e23d:b9f9 with SMTP id j15-20020a63ec0f000000b003fde23db9f9mr1796146pgh.612.1655163378431; Mon, 13 Jun 2022 16:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655163378; cv=none; d=google.com; s=arc-20160816; b=UKjMPRLZVHPjsmdGjD2hT47+wkYhrG8NjbMESyHdhUQW7Ac/YtFr322KY8yxAkyIJm pkWspt62JY7k+6fAVLfC9b2HBqTIabJMFiWnZiBx+n5XWcJXHY2oYWIKR6GF+0OTdb/g AZLqinesTKpLpcc+I6grsgXiNdT5j8phWTCX0kppcK6hx3D59Ut95CDCLFeerpwBs5cZ BsGsntrhUfGt793lTAHJnsY9Q4zIqHOomb4+gfrXvPZ+Ywl9+J8gNTXGIVVJnDhkA3Pp pUyVbt8v4zEG77AKEJQRXTlIsuLHrgENldISUSP0YD8uYzQBNLR42IMYlQZx3O91ka08 3JgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7klOn/n2ISdaUz2eIXWWcqcQBg4U27lMXyVywy5WCjY=; b=WPMnOUbH49JTz4AQbFJJPJFAxmmW7oPZobNTsjA5Pb9uB20rjPZnL9Vh7Tv6gX8SFJ 2FmS40R4dokoa/G89XojSEJCFv+n74zPZk6I7wKHQ4JmofCl58cvQiJH+0QM06bOJ9L4 cTa7n4+5o8oSe68ay48zMyAMM3TplXw96c+90ICdt/RscqWTECH++goGRekiZLT1fsP/ sNRRN7ROWrYRmnlqIIItlc/xIFkCfenBMBMQ8wAvQD87gQAchlBWSu5WZgsoiV3pjs6/ gFV3auj3AeMFnKpf1E7Wv4h/MZR26pmlCe4bVAjqzJZAaZtKuvHV5U4CgO+w+K0qXjmA FozQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Pt4uO6D7; 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 y24-20020a63de58000000b003f61820466fsi11288523pgi.578.2022.06.13.16.36.00; Mon, 13 Jun 2022 16:36:18 -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=Pt4uO6D7; 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 S235989AbiFMXeB (ORCPT + 99 others); Mon, 13 Jun 2022 19:34:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231971AbiFMXd7 (ORCPT ); Mon, 13 Jun 2022 19:33:59 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7ADB30F4A for ; Mon, 13 Jun 2022 16:33:58 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id d123so7761162iof.10 for ; Mon, 13 Jun 2022 16:33:58 -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; bh=7klOn/n2ISdaUz2eIXWWcqcQBg4U27lMXyVywy5WCjY=; b=Pt4uO6D7w05L89kAG3AkG+VxqIN5vQCQvkc++FaNCyNy9/ogT1Ad0WIp6FP8U/vQuC yFLRfhV+TzvsbtTPTdGrp72FAJibDLhuymdGCxaZzVcgAH3SavqY82+mFTytm1tPar5L 9iiyBdo7zbMda9RS5PZWg38dm0N+aCbgyjgdQd0unSij+sCHtpj4VLdBmD5/kvVWbAoE DiF86xT2V+XxAJyxF+uWMQNILr+Lf9HKFX5kHTYPX02VMujTkqw63eVGKjQ/tA1W7XGV MS6cGtitxY5fPKKS3usaM9YWExzYnli+wkopye1Dwum6g6Qw11KUth03Gdx7AdVFwtVw 00Tg== 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; bh=7klOn/n2ISdaUz2eIXWWcqcQBg4U27lMXyVywy5WCjY=; b=VV0mMMxgNoE9/8+Vlp6vguXJTiUBPjzlMh7DgdPGKhHnTg0bSbTaafwT+9fhNcdzsD KUI3RssEnSM/UoX2I6AL6P6jWPvbHbglJ9jj9r6FoT1pJk5YuHUETuLl8aiBXu3wzpmk AFjUlN8pleUFWfvCGEjbuky94vQvxZj3ptAX6PFi54AdGnCvL+esIT2Ps50TSyjwX0g1 Wrj/ha3vGfWyR0ojiPfRa08FdhaJuUcnC8+L+FnGeoRufLq6bXLuLJNXm/M6PbJa0y7x IOTId6QJVMOfwc0C7FeTt/mZGKijr45V1vPo5wG3v4fWhZz5iyUdX1yL59OxuosvQTPw j4jA== X-Gm-Message-State: AOAM533/8LfhaDFYGOcvvahCF+6MgZJyAvelgnxO/I3sS82jEnFl/N4m XdjyL5/AaQBvxF6vLEmDNJV3RfhIH8vlQMZEwx98RA== X-Received: by 2002:a5e:c30b:0:b0:668:825c:8556 with SMTP id a11-20020a5ec30b000000b00668825c8556mr1092877iok.68.1655163237901; Mon, 13 Jun 2022 16:33:57 -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: <1cadca0d-c3dc-68ed-075f-f88ccb0ccc0a@amd.com> From: Alper Gun Date: Mon, 13 Jun 2022 16:33:46 -0700 Message-ID: Subject: Re: [PATCH Part2 v5 23/45] KVM: SVM: Add KVM_SNP_INIT command To: Ashish Kalra Cc: Brijesh Singh , Ashish.Kalra@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org, kvm@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 , Sean Christopherson , 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 , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, Marc Orr , sathyanarayanan.kuppuswamy@linux.intel.com, Pavan Kumar Paluri Content-Type: text/plain; charset="UTF-8" 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 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 = (argp->id == KVM_SEV_ES_INIT || argp->id == KVM_SEV_SNP_INIT); > >> struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; > >> - bool es_active = argp->id == KVM_SEV_ES_INIT; > >> + bool snp_active = argp->id == 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 = es_active; > >> + sev->snp_active = snp_active; > >> asid = sev_asid_new(sev); > >> if (asid < 0) > >> goto e_no_asid; > >> sev->asid = asid; > >> > >> - ret = sev_platform_init(&argp->error); > >> + if (snp_active) { > >> + ret = verify_snp_init_flags(kvm, argp); > >> + if (ret) > >> + goto e_free; > >> + > >> + ret = sev_snp_init(&argp->error); > >> + } else { > >> + ret = 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 tests. > > 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 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. > Before launching the first SNP/SEV guest launch after INIT, we need to > issue SEV_CMD_DF_FLUSH command. > > I assume that we will always be initially doing SNP firmware > initialization with SNP_INIT command followed by sev_platform_init(), if > SNP is enabled on boot CPU. > > Thanks, Ashish >