From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CD88C12002 for ; Wed, 21 Jul 2021 17:53:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 756006124C for ; Wed, 21 Jul 2021 17:53:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231224AbhGURM6 (ORCPT ); Wed, 21 Jul 2021 13:12:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230004AbhGURM6 (ORCPT ); Wed, 21 Jul 2021 13:12:58 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B27EEC0613CF for ; Wed, 21 Jul 2021 10:53:34 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id c68so2850690qkf.9 for ; Wed, 21 Jul 2021 10:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6yFvLCK83EARCEJW2USL66XPk2Snwg9rOn4V8eQnKq4=; b=LmYH4vBpP8tsrP/2QQX/a4c4LvuM1+b4/24JikG+Eg3ffRRWq1sLdvVWqmdZSpffFs zYMHn1k1Y7JSxueTKglktRFPafjcur+BGgT8Ux3LXzZB1CNjBqPF55WMoTS3UHR/naUy 5HN4fHlgHkJlsYXgo1YafStP4kmIs1l/2txFBajcHQd5DgvTLQTHypzSg1u2dEsyWtNa 1Gnt5R/qqXAZ4zGACvt2zRiwgMwtDzYJEII9SZ5Ev6ztWv9+tg0z29/yQFcibOFahdej SPDfQhV5wiSgG/WdTlqfqtvyXLh0cVDvfnKvx7ZZJF7FSQsGy43aezRKof8MJZkcTPGM o0VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6yFvLCK83EARCEJW2USL66XPk2Snwg9rOn4V8eQnKq4=; b=LaRIokKicXCHfUtx7C4ezuq/w8PW8/2y/Et2u36CNXqmVmfDqZWxn0SVolvpD8PG78 JpVKyF0D1UTcxsk6llBCDt9RNS6IBaXuA2ww7cIf3y1GzYR9gPLCk+rgEPDU3iXXGpIG lkGwZndC8K9eF7BdQxhdqE6AdSVR6BpLyVg3kcbjQcP42py426uPqFOBdQ3pyZyw1GYM WtRzgVAYYzLe48P8qxtB0AIQq3gHzHtTdZ/cKxNG6yDNr6Fiv5NcDk/HDEWphoTeG09P MhO2fO6eHRNoREZU3Ooj6biN985jRALT+fG7EhKi6+q/pys8tygyggwDSTWAxF9edWmT 3W/w== X-Gm-Message-State: AOAM532WQxThdgeJpClY2nKfzrlAdTcA+iBjWugydLu/qTIE32E9gwhu g1rNyuno4wA/BXw2GkQ9JknqD4Mjvdg5ASGWhKKOwg== X-Google-Smtp-Source: ABdhPJzkyyOAFQakNLKPpJl5joOFjae/AcNTO5l2I8TPcjJJXSsAIKXc+xGIz33Gsbm9HQbKLCjKhxqfB9nnHVogi3Y= X-Received: by 2002:a37:8044:: with SMTP id b65mr22312539qkd.150.1626890013396; Wed, 21 Jul 2021 10:53:33 -0700 (PDT) MIME-Version: 1.0 References: <20210707183616.5620-1-brijesh.singh@amd.com> <20210707183616.5620-27-brijesh.singh@amd.com> <9ee5a991-3e43-3489-5ee1-ff8c66cfabc1@amd.com> In-Reply-To: From: Marc Orr Date: Wed, 21 Jul 2021 10:53:22 -0700 Message-ID: Subject: Re: [PATCH Part2 RFC v4 26/40] KVM: SVM: Add KVM_SEV_SNP_LAUNCH_FINISH command To: Sean Christopherson Cc: Brijesh Singh , x86@kernel.org, linux-kernel@vger.kernel.org, kvm list , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Mon, Jul 19, 2021 at 9:54 AM Sean Christopherson wrote: > > On Fri, Jul 16, 2021, Brijesh Singh wrote: > > > > On 7/16/21 3:18 PM, Sean Christopherson wrote: > > > On Wed, Jul 07, 2021, Brijesh Singh wrote: > > >> + data->gctx_paddr = __psp_pa(sev->snp_context); > > >> + ret = sev_issue_cmd(kvm, SEV_CMD_SNP_LAUNCH_FINISH, data, &argp->error); > > > Shouldn't KVM unwind everything it did if LAUNCH_FINISH fails? And if that's > > > not possible, take steps to make the VM unusable? > > > > Well, I am not sure if VM need to unwind. If the command fail but VMM decide > > to ignore the error then VMRUN will probably fail and user will get the KVM > > shutdown event. The LAUNCH_FINISH command finalizes the VM launch process, > > the firmware will probably not load the memory encryption keys until it moves > > to the running state. > > Within reason, KVM needs to provide consistent, deterministic behavior. Yes, more > than likely failure at this point will be fatal to the VM, but that doesn't justify > leaving the VM in a random/bogus state. In addition to being a poor ABI, it also > makes it more difficult to reason about what is/isn't possible in KVM. +1 to Sean's feedback to unwind everything here properly here. Comments of the nature of "XYZ should happen" -- without a test (e.g., selftest or kvm-unit-test) to ensure the XYZ _does_ happen -- are a time bomb waiting to happen. Also, I wonder if we leave pages, RMPUPDATE'd to immutable in previous loop iterations, is it possible for them to remain as immutable and be reused later on (after this guest is destroyed)? And if this happens, will we get an RMP violation? Even if the answer is no -- go read this code 2,000 lines away -- it handles this case. That's still not a very satisfying answer. I'd rather see things cleaned up ASAP as soon as the code starts to go off the rails.