Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4855624rwi; Mon, 17 Oct 2022 11:41:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6HN2/Q7TagWbBjac8pL0sUIvp8pJMIb2+Z4KLrT6XbbnzYLCROcnky/0HnjlhgOyb3o8aK X-Received: by 2002:a17:902:c942:b0:180:3f94:2975 with SMTP id i2-20020a170902c94200b001803f942975mr13402597pla.50.1666032094804; Mon, 17 Oct 2022 11:41:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666032094; cv=none; d=google.com; s=arc-20160816; b=iFWUvlmhpNwNl9r+DMDiC4wcN8wsasa484ahqwARk/tUfEOijVMsB8A1xlBM8uINFg Cp20Ts9LZBIR2vlYZilbJ4Yl4iGQODaPSQCMd6XUBhs18XalR0lVol7HTrCr+D1MV09b AScpdKQNQpvmJhmkM/G0gkAAxIoM1sv0okyim4n5Fe6BAkZkBysBG+zkrQlzV6qHN481 V1dW8suLJ4yR3lt294tjQxS8+sv3jCORJFXC653W8k8901csPQi0cPhf1phKPABtAzRJ Y17kQjICppKYvJUwnUTFSg7rEosYQfxRSEo8uWDXd6W6AXGo78wxbNR2mTttH6Pfpg1D N/Ng== 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=s0J5M786TwaMLoMsZ1Scm7fs/H+L1tdOLwBM6CQTWeI=; b=TqIrPeZq4mKE9yHL3ghjHITJXDiy8S4wksC0oxqvsEuqMd6fHsqPlSmlTrHKKgqZr9 htYoHR9HCw3zU9xhogEWrUpWry1scmZyPEpy2e0ThkrhdiBQVHl++dvOu914WbGCkI8a 1Sb8KLH/0RK1zyczBLTA//tMZLi0bzJ7YI2kQTfEmRSTegAsCXXsL+mYdaaDyNuN3oKh PwEGckMtB4Ouv+nz0dyGpRleMu3JP+4RGikt6wSM30m7HE7JHABO+UAAlAmp6r92SuI+ 129Z/IfanNUKi2SShBhTKkcd2v3PQJQQZPeH30r3buOu5nqxcjaIKJQRtkrIbKD6UqHx bT4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ipD578I3; 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 m5-20020a170902db0500b00177e7e14f66si8681440plx.624.2022.10.17.11.41.22; Mon, 17 Oct 2022 11:41:34 -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=ipD578I3; 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 S230033AbiJQSZv (ORCPT + 99 others); Mon, 17 Oct 2022 14:25:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbiJQSZt (ORCPT ); Mon, 17 Oct 2022 14:25:49 -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 0AFAE71BEA for ; Mon, 17 Oct 2022 11:25:46 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id h8so14999637lja.11 for ; Mon, 17 Oct 2022 11:25:46 -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=s0J5M786TwaMLoMsZ1Scm7fs/H+L1tdOLwBM6CQTWeI=; b=ipD578I3BnnfeMqQ/xcTjxHYz3cX6TI59AYe00AjkAU6nGV+Q4GiPC8EO4sQnVGrwM d9RsREiia8cfIgb8q8f8Evaa2nf/zEpw4jeK+KgLQbAfAhT8wrkgCdoVbtjt3upSxoag G8T5O5j259sPtYDszziZ6q899421SWMASVuP50YovJMxS/SUrT5lQ+vxYZZibcKP7hYK A68Hs1ILFe/Qj9itaDs3xvMdl+BpCAounrj11jHn9KD/jsodwPS0EAxbi40BB+EPyJT0 eCvMGiD+kdLSCMByEYAVOsWULFHg466L3MqT/5Eckgluy+YnDqUjhLMnNBKEYV6GA9Ik SflQ== 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=s0J5M786TwaMLoMsZ1Scm7fs/H+L1tdOLwBM6CQTWeI=; b=F/ZU6r2K7KLaVYItjOCaNWBFVk8V0ZOaig1hczm6KHTPT1aXcOTJYJP3EU/qoBpPdh jiBeokv01NZBvbCF9Wz53FNu0VhGgh1INd6DR0MAWAjONZu5hkK96dao8ZgDzFcK97W6 le2YJiOQG7LPyntt/sJIxn6W+HS+tWqs8HAJSd/JES56A7kdMF65GO5Gfefkx9wB0Sgx prKtyilrhfKE/Ms/3RDEkHneH5Rrica49M0qMkXTKpy0psg2wrViaH3HleO5JbPjw2Nq 6ma5b7gSuhHCtzJZMmzSWG08c8T87pc+N8QT6DYZWE/gZO2CMGldl83jrINSdHsyarvq 5+Ug== X-Gm-Message-State: ACrzQf14u05emmaHniLlVIzgPTBaI5/BDhWaHUwFEapP1YFZRNZGJf8E UYLkkwaFPWe5dYp70xKwrVPwFVc3lwhqJbmNdvjiNA== X-Received: by 2002:a2e:7c17:0:b0:26e:4f7:3c95 with SMTP id x23-20020a2e7c17000000b0026e04f73c95mr4732936ljc.455.1666031144602; Mon, 17 Oct 2022 11:25:44 -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: Mon, 17 Oct 2022 12:25:32 -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=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-kernel@vger.kernel.org On Mon, Oct 17, 2022 at 12:04 PM Sean Christopherson wrote: > > On Mon, Oct 17, 2022, Peter Gonda wrote: > > On Thu, Oct 6, 2022 at 12:25 PM Sean Christopherson wrote: > > > And with that, I believe sev_vm_create() can go away entirely and the SEV encryption > > > stuff can be handled via a new vm_guest_mode. ____vm_create() already has a gross > > > __x86_64__ hook that we can tweak, e.g. > > > > > > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > > > index 54b8d8825f5d..2d6cbca2c01a 100644 > > > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > > > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > > > @@ -238,9 +238,10 @@ struct kvm_vm *____vm_create(enum vm_guest_mode mode, uint64_t nr_pages) > > > case VM_MODE_P36V47_16K: > > > vm->pgtable_levels = 3; > > > break; > > > + case VM_MODE_PXXV48_4K_SEV: > > > case VM_MODE_PXXV48_4K: > > > #ifdef __x86_64__ > > > - kvm_get_cpu_address_width(&vm->pa_bits, &vm->va_bits); > > > + kvm_init_vm_address_properties(vm); > > > /* > > > * Ignore KVM support for 5-level paging (vm->va_bits == 57), > > > * it doesn't take effect unless a CR4.LA57 is set, which it > > > > > > Then kvm_init_vm_address_properties() can pivot on vm->mode to deal with SEV > > > specific stuff. > > ... > > > This refactor sounds good, working on this with a few changes. > > > > Instead of kvm_init_vm_address_properties() as you suggested I've added this: > > > > @@ -272,6 +275,8 @@ struct kvm_vm *____vm_create(enum vm_guest_mode > > mode, uint64_t nr_pages) > > vm->type = KVM_VM_TYPE_ARM_IPA_SIZE(vm->pa_bits); > > #endif > > > > + kvm_init_vm_arch(vm); > > Why? I'm not necessarily opposed to adding kvm_init_vm_arch(), but since x86 > "needs" a dedicated hook to unpack the mode, why not piggyback that one? > Well I since I need to do more than just kvm_init_vm_address_properties() I thought the more generic name would be better. We need to allocate kvm_vm_arch, find the c-bit, and call KVM_SEV_INIT. I can put it back in that switch case if thats better, thoughts? > > + > > vm_open(vm); > > > > /* Limit to VA-bit canonical virtual addresses. */ > > > > And I need to put kvm_arch_vm_post_create() after the vCPUs are > > created because the ordering we need is: KVM_SEV_INIT -> Create vCPUS > > -> KVM_SEV_LAUNCH_FINISH. > > Hrm, that's annoying. Please don't use kvm_arch_vm_post_create() as the name, > that's a better fit for what Vishal is doing since the "vm_post_create()" implies > that it's called for "all" VM creation paths, where "all" means "everything > except barebones VMs". E.g. in Vishal's series, kvm_arch_vm_post_create() can > be used to drop the vm_create_irqchip() call in common code. In your case, IIUC > the hook will be invoked from __vm_create_with_vcpus(). > > I'm a little hesitant to have an arch hook for this case since it can't be > all-or-nothing (again, ignoring barebones VMs). If a "finalize" arch hook is added, > then arguably tests that do __vm_create() and manually add vCPUs should call the > arch hook, i.e. we'd be adding maintenance burden to tests that in all likelihood > don't care about SEV and never will. > > It's somewhat unfortunate, but dedicated vm_sev_create_with_one_vcpu() and > and vm_sev_create_with_vcpus() wrappers is probably the least awful solution. Make sense. I think we can go back to your suggestion of kvm_init_vm_address_properties() above since we can now do all the KVM_SEV_* stuff. 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?