Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1160538rwi; Thu, 27 Oct 2022 12:01:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7PkZ3RXLxoXfwsQPNswItCPjINb4ly/yew38FHCn0LB7z1gMalioONjaizVGuYKvLb/2U9 X-Received: by 2002:a05:6402:428a:b0:42e:8f7e:1638 with SMTP id g10-20020a056402428a00b0042e8f7e1638mr47336931edc.228.1666897313892; Thu, 27 Oct 2022 12:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666897313; cv=none; d=google.com; s=arc-20160816; b=Lm32Xsq6JDgNIvGFrhBdweAuTQOmM4YSYcjoKPxZFumdvAZNSzCRv3kyaPAu01mlvj RtkaDTFwN6vJxHYEzgAn8rSMT6aOKB0RetIm/noMfbTRFfVGSAwfYsaypJXZojbp20Ou PyhpS/PCj3+e1KVBgYRhWH14G2dpN4vq1jGmKbYBSqNGAjP6qFpXzJURIrzHEJrmV0Jd AMgL+1pk1zt9ITQHCp+7/0W4FpTqOf60K+3HBmNprY2SYefQzS54FCeJtHtehBjv8BzD uV2siiIWUkp+0DpXWZwXrJIIX3BnybScbeXgVIW7oDhatXWXx28vR13cs4te5AY8gCi3 p+Eg== 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=rImRM8lUYQwKUuhHi33Xv0slNDyY9fPfRBiZY4CGcO8=; b=IlZ2zkg5xKzFRu3mfCuAwZCY0fnOGMziOxQAInWZoELeRp94R4B2ZYm+0RRCEZ2K3E M6NKzFN4m9z/+alD7jrSoeI4zTJJK1hv6Nkz8b4kV8RWiEoEpL9kJi3ll/rFyDCGtkis ULmebWzCxTXZHU0PjZwnx/mQQCz6yTuGbmyZvgGkT56hMTNaBDJd609ca2bG9+5pLVQR 4s92z4BtYE5Ghn62Iks1CutKdhVvR8HsCqlUY/doftj+HHvZxXl1E9Pwja4H6PLt6qwP pdR2FE0xiCNeXL4tGkI2MDWg9cQ87ZoE/nIkWF3b9Mzgw0L5ZMl7EZGKggHmRvi8chK6 v6+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=pIlYlWR1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 g16-20020a50ee10000000b0045d189ac60esi1748005eds.401.2022.10.27.12.01.26; Thu, 27 Oct 2022 12:01:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=pIlYlWR1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S235768AbiJ0Sej (ORCPT + 99 others); Thu, 27 Oct 2022 14:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233965AbiJ0Seg (ORCPT ); Thu, 27 Oct 2022 14:34:36 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95929D2C3 for ; Thu, 27 Oct 2022 11:34:34 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id u2so4923519ljl.3 for ; Thu, 27 Oct 2022 11:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rImRM8lUYQwKUuhHi33Xv0slNDyY9fPfRBiZY4CGcO8=; b=pIlYlWR1qxP4Us0NHBx+aE76CTtlViPPRDK3+wueE5cjtAq26qHBbWpEP4mIjWcUWZ YVqZdbRf/W6tdLjzUiVroX2d9vVt5fF8sEmwQ4q3YwQ/mfA/fdY2ABeCNLfIoTgbLNuA aKsWrjullJiJp3MadhZ6dYErUCpCbX6Cs+6xawriBBcmT0OoYA2rUM9f0xI/8SMB65Q8 xsWL2A/0fBFwIcztXgMaUUQnMSOK7d9fdhoko7WN9UjBzfiQs03EnomhdDdAaHU/zbd0 lURafjqfblsqGQbyXeMOKpRy1Pwb5w1mAXuN7rTyeL24PRCL8k1GXLoARqARraNlQqGe Za6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rImRM8lUYQwKUuhHi33Xv0slNDyY9fPfRBiZY4CGcO8=; b=57VAX1DsoHiUZl4yDa3e4dUVM4qe9wzop/4JOtNfd6uKDyEhdoRtlQaoMnJ/i6dkpF BG09dr9O19U/jD1iI48el8ivJSB/4+MHcGoCPPHQ2QpMGOWs44DvN2HJ+NnRG+Y//cqw h9i6RUNT+jy2G9RcumW9tk5efa/sum+DmuO6w5EfYgXi1AgaXBLxLrFsTRlc8DwneLxz sjX2ZthJjBNHRSM5mqy/7PNWXEUrFrE0WKdsFxB7UO5nw4FNaVRxwqA1r+yT3SnemBfx iLgEwTIEpYzuKOWWILy0QZ5JM4EovPyeC5iFnNjFYkBUBlRg4yoYlj19+FKhf8BgLA3f tF3Q== X-Gm-Message-State: ACrzQf23Uq7DW+czH0IKVQ4Cd9ag6E5/1XLr6HCqWszU1TGDcUjA14cl R589ud1bvV7t0t5zcK55UUCGQdzQbxcNG+RlBOleLntpjI8= X-Received: by 2002:a2e:94cf:0:b0:26c:5d14:6ec7 with SMTP id r15-20020a2e94cf000000b0026c5d146ec7mr20536772ljh.237.1666895671322; Thu, 27 Oct 2022 11:34:31 -0700 (PDT) MIME-Version: 1.0 References: <20220829171021.701198-1-pgonda@google.com> <20220829171021.701198-7-pgonda@google.com> In-Reply-To: From: Peter Gonda Date: Thu, 27 Oct 2022 12:34:19 -0600 Message-ID: Subject: Re: [V4 6/8] KVM: selftests: add library for creating/interacting with SEV guests To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, marcorr@google.com, michael.roth@amd.com, thomas.lendacky@amd.com, joro@8bytes.org, mizhang@google.com, pbonzini@redhat.com, andrew.jones@linux.dev 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, 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-kernel@vger.kernel.org On Thu, Oct 27, 2022 at 11:59 AM Sean Christopherson wrote: > > On Thu, Oct 27, 2022, Peter Gonda wrote: > > On Wed, Oct 19, 2022 at 10:34 AM Sean Christopherson wrote: > > > > > > On Tue, Oct 18, 2022, Peter Gonda wrote: > > > > On Mon, Oct 17, 2022 at 2:34 PM Sean Christopherson wrote: > > > > > > > > > > On Mon, Oct 17, 2022, Peter Gonda wrote: > > > > > > I think this means we don't need to add VM_MODE_PXXV48_4K_SEV since we > > > > > > can set up the c-bit from inside of vm_sev_create_*(), thoughts? > > > > > > > > > > Configuring the C-bit inside vm_sev_create_*() won't work (at least not well). > > > > > The C-bit needs to be known before kvm_vm_elf_load(), i.e. can't be handled after > > > > > __vm_create(), and needs to be tracked inside the VM, i.e. can't be handled before > > > > > __vm_create(). > > > > > > > > > > The proposed kvm_init_vm_address_properties() seems like the best fit since the > > > > > C-bit (and TDX's S-bit) is stolen from GPA space, i.e. directly affects the other > > > > > values computed in that path. > > > > > > > > > > As for the kvm_vm_arch allocation ugliness, when we talked off-list I didn't > > > > > consider the need to allocate in kvm_init_vm_address_properties(). That's quite > > > > > gross, especially since the pointer will be larger than the thing being allocated. > > > > > > > > > > With that in mind, adding .../include//kvm_util.h so that "struct kvm_vm_arch" > > > > > can be defined and referenced directly doesn't seem so bad. Having to stub in the > > > > > struct for the other architectures is annoying, but not the end of the world. > > > > > > > > I'll make "struct kvm_vm_arch" a non pointer member, so adding > > > > /include//kvm_util.h files. > > > > > > > > But I think we do not need VM_MODE_PXXV48_4K_SEV, see: > > > > > > I really don't want to open code __vm_create() with a slight tweak. E.g. the > > > below code will be broken by Ricardo's series to add memslot0 is moved out of > > > ____vm_create()[1], and kinda sorta be broken again by Vishal's series to add an > > > arch hook to __vm_create()[2]. > > > > > > AFAICT, there is no requirement that KVM_SEV_INIT be called before computing the > > > C-Bit, the only requirement is that KVM_SEV_INIT is called before adding vCPUs. > > > > > > [1] https://lore.kernel.org/all/20221017195834.2295901-8-ricarkol@google.com > > > [2] https://lore.kernel.org/all/YzsC4ibDqGh5qaP9@google.com > > > > Oh I misunderstood your suggestion above. > > > > I should make KVM_SEV_INIT happen from kvm_arch_vm_post_create(). Add > > VM_MODE_PXXV48_4K_SEV for c-bit setting inside of > > kvm_init_vm_address_properties(). > > > > Inside of vm_sev_create_with_one_vcpu() I use > > __vm_create_with_vcpus(), then call KVM_SEV_LAUNCH_FINISH. > > > > Is that correct? > > Yep, I'm pretty sure that was what I was thinking. Duh! Should have realized that at first. You said you were going to rebase your selftest series. I'll follow up with a V6 ontop of that rebase.