From patchwork Sat Jan 21 00:15:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 46709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp496247wrn; Fri, 20 Jan 2023 16:17:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXvwmgqAV657ccC1eDkFU5hPNrxjxpWkCr8IHvvXLaQ5bpCwzg3A95sxxKd3hlnRqSqYERxh X-Received: by 2002:a17:907:1107:b0:870:e329:5f2f with SMTP id qu7-20020a170907110700b00870e3295f2fmr17044712ejb.51.1674260272883; Fri, 20 Jan 2023 16:17:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674260272; cv=none; d=google.com; s=arc-20160816; b=Q+NZHhMICrgnly5TOVsCVEEzsyllvQQfCEnud0GCiv65Q8E79ngrC0E8eQ+4Hka8Wq Q4kHoOaCtzGpS+DII0hwI6SxYch8YVqqD813ksoMwIs3mQngXs6uAEzob2ZPsjKQ7+f0 1KtpvleasboeaB7Og/FP57VZ1GBTFjW54YnWaW6s+zTYmzmAwzW2tW+kyxXZTe9fFmbp qFC8xlPZVXr6RjXLLuhW4cHGPXRAKgii9PZ78bgipYVFaPGMzZgeqXvfyFZeEhvItIFB /lqAkP19j58oET3UUZNp4JawgUpPyYaZS/5TC8+5K6PHta0kZBtMgdtrPCPJrCNrrSlU YCdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=T7o4vSmm7ZL1KEassKDMWSbS80FYjDRO3LkEb1B3l7A=; b=oG7kwyQKDf9YD6BaAh1iitB50zf/xdqjlep5y+MO4kmX2BYB878aqyWGWlie9Vs17v iBfaq5lhsnuqUC+lFkuuXq3CH51Fdfh0DVGNrGMSB4J7t33u8WNPs+PjyRDnChpn02bz vl5tRMtKrYXuffTDGGsoO+eEG+su6uJgMQS4FpRiUoAhzWCRUBoYb+XYJ+4BFw8BjAsB lMPl2Iz8xKZODozSlYfbnd9GB+CPEo4Uw9bnfObx4fd2oHavuPiGGAAR9u/K+BTz4cmd smvwvgHfob4ewxtpPr9mK+z5DwRj+dHyf+GrNbBMsfoGLSp8luhapt42bRrgGOjsngF/ LPaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ol7HjVsc; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb8-20020a1709070a0800b0084d34979417si15936074ejc.323.2023.01.20.16.17.29; Fri, 20 Jan 2023 16:17:52 -0800 (PST) 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=Ol7HjVsc; 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 S229661AbjAUAQi (ORCPT + 99 others); Fri, 20 Jan 2023 19:16:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229768AbjAUAQa (ORCPT ); Fri, 20 Jan 2023 19:16:30 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E69BA5792 for ; Fri, 20 Jan 2023 16:16:19 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id y66-20020a253245000000b007cb4f1e3e57so7415087yby.8 for ; Fri, 20 Jan 2023 16:16:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=T7o4vSmm7ZL1KEassKDMWSbS80FYjDRO3LkEb1B3l7A=; b=Ol7HjVscoT8ho/9hbUrrCazQ67jYdiv/WqZ3xCCEBOmLMoRYL3BVBpX9yE4cKVDNaM k2Bs1B5PSpElX8QFPMjeAqEYDtW6CtPgpDi+gHVAujrUnMRQfAvsZpqSatGSNrRowTaY qWOU0SderZMc9TdF+m65z5N/Gy26LtNslf/DkyoJYelWAo3xwiQtDsGz+8R91hjiD+1B l5KYpyddlEv1NtUoggfZL9Kb5LuD9WrfVdLaMcy96u+xYmf8sycyvox4f0JLDUf/+mvX dEbJG3xxtHu7lbyab1L26tQFECJWcXKTfIsiqYhE4WfGeXUMwnPZA6OXAjwJsBj9Ko2T /7RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T7o4vSmm7ZL1KEassKDMWSbS80FYjDRO3LkEb1B3l7A=; b=zGd3JhJ/qy1KWWx4QCoKYFk+ac3c5l7MtOOlfjH5IhDy9cK7NR1Z5jruGPdfMLYl4s /eeS8j0LUjNmepjv9ni4WSKi+Uvxa9PIqx3MTRFqr8zDA4I+oRCpI4Xd8jSawy22xUW3 zXk7i4u5UuR5YPVXhE+eHtedF9wynmUxKpzu5LG4tvqPA4nwSQoyBMmyF6iFlhI1SqpC je/P7C7PnnsdY706V+wpL2pFW9gb2EUt1IP27bQyoCzRY/IsMeQqgiNnukeoeSBZ1Vda 4jRoNKNL3F/wMmCmxB9A2S59AVkoNn6a0vxMyyBn6dXMJtFJ+zKyCB140a7qWHfVQ2n4 dTNw== X-Gm-Message-State: AFqh2kq6cnTdKdswvl7pYtU2UiQzurj9sODRd8vF4BDh4NCsggGQLBGQ 6JGo2Wik4jmkMYfdMJjgSL7eY81495csvHRnBQ== X-Received: from ackerleytng-cloudtop-sg.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:b30]) (user=ackerleytng job=sendgmr) by 2002:a0d:d5c6:0:b0:4ef:ce3a:a54 with SMTP id x189-20020a0dd5c6000000b004efce3a0a54mr2181857ywd.485.1674260179077; Fri, 20 Jan 2023 16:16:19 -0800 (PST) Date: Sat, 21 Jan 2023 00:15:13 +0000 In-Reply-To: <20230121001542.2472357-1-ackerleytng@google.com> Mime-Version: 1.0 References: <20230121001542.2472357-1-ackerleytng@google.com> X-Mailer: git-send-email 2.39.0.246.g2a6d74b583-goog Message-ID: <20230121001542.2472357-3-ackerleytng@google.com> Subject: [RFC PATCH v3 02/31] KVM: selftests: Add support for creating non-default type VMs From: Ackerley Tng To: linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, isaku.yamahata@intel.com, sagis@google.com, erdemaktas@google.com, afranji@google.com, runanwang@google.com, shuah@kernel.org, drjones@redhat.com, maz@kernel.org, bgardon@google.com, jmattson@google.com, dmatlack@google.com, peterx@redhat.com, oupton@google.com, ricarkol@google.com, yang.zhong@intel.com, wei.w.wang@intel.com, xiaoyao.li@intel.com, pgonda@google.com, marcorr@google.com, eesposit@redhat.com, borntraeger@de.ibm.com, eric.auger@redhat.com, wangyanan55@huawei.com, aaronlewis@google.com, vkuznets@redhat.com, pshier@google.com, axelrasmussen@google.com, zhenzhong.duan@intel.com, maciej.szmigiero@oracle.com, like.xu@linux.intel.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Ackerley Tng X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755589139793153651?= X-GMAIL-MSGID: =?utf-8?q?1755589139793153651?= From: Erdem Aktas Currently vm_create function only creates KVM_VM_TYPE_DEFAULT type VMs. Adding type parameter to ____vm_create to create new VM types. Signed-off-by: Erdem Aktas Reviewed-by: David Matlack Signed-off-by: Ryan Afranji Signed-off-by: Sagi Shahar Signed-off-by: Ackerley Tng --- tools/testing/selftests/kvm/include/kvm_util_base.h | 6 ++++-- tools/testing/selftests/kvm/lib/kvm_util.c | 6 +++--- tools/testing/selftests/kvm/lib/x86_64/sev.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 0db5cd4b8383a..0fa4dab3d8e52 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -27,6 +27,8 @@ #define NSEC_PER_SEC 1000000000L +#define KVM_VM_TYPE_DEFAULT 0 + typedef uint64_t vm_paddr_t; /* Virtual Machine (Guest) physical address */ typedef uint64_t vm_vaddr_t; /* Virtual Machine (Guest) virtual address */ @@ -686,13 +688,13 @@ uint64_t vm_nr_pages_required(enum vm_guest_mode mode, * __vm_create() does NOT create vCPUs, @nr_runnable_vcpus is used purely to * calculate the amount of memory needed for per-vCPU data, e.g. stacks. */ -struct kvm_vm *____vm_create(enum vm_guest_mode mode, uint64_t nr_pages); +struct kvm_vm *____vm_create(enum vm_guest_mode mode, uint64_t nr_pages, int type); struct kvm_vm *__vm_create(enum vm_guest_mode mode, uint32_t nr_runnable_vcpus, uint64_t nr_extra_pages); static inline struct kvm_vm *vm_create_barebones(void) { - return ____vm_create(VM_MODE_DEFAULT, 0); + return ____vm_create(VM_MODE_DEFAULT, 0, KVM_VM_TYPE_DEFAULT); } static inline struct kvm_vm *vm_create(uint32_t nr_runnable_vcpus) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 5257bce6f546d..14246f0fd2e78 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -185,7 +185,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = { _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES, "Missing new mode params?"); -struct kvm_vm *____vm_create(enum vm_guest_mode mode, uint64_t nr_pages) +struct kvm_vm *____vm_create(enum vm_guest_mode mode, uint64_t nr_pages, int type) { struct kvm_vm *vm; @@ -201,7 +201,7 @@ struct kvm_vm *____vm_create(enum vm_guest_mode mode, uint64_t nr_pages) hash_init(vm->regions.slot_hash); vm->mode = mode; - vm->type = 0; + vm->type = type; vm->pa_bits = vm_guest_mode_params[mode].pa_bits; vm->va_bits = vm_guest_mode_params[mode].va_bits; @@ -337,7 +337,7 @@ struct kvm_vm *__vm_create(enum vm_guest_mode mode, uint32_t nr_runnable_vcpus, struct userspace_mem_region *slot0; struct kvm_vm *vm; - vm = ____vm_create(mode, nr_pages); + vm = ____vm_create(mode, nr_pages, KVM_VM_TYPE_DEFAULT); kvm_vm_elf_load(vm, program_invocation_name); diff --git a/tools/testing/selftests/kvm/lib/x86_64/sev.c b/tools/testing/selftests/kvm/lib/x86_64/sev.c index faed2ebe63ac9..dedfd9f45cfb3 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/sev.c +++ b/tools/testing/selftests/kvm/lib/x86_64/sev.c @@ -221,7 +221,7 @@ struct kvm_vm *vm_sev_create_with_one_vcpu(uint32_t policy, void *guest_code, uint64_t nr_pages = vm_nr_pages_required(mode, 1, 0); struct kvm_vm *vm; - vm = ____vm_create(mode, nr_pages); + vm = ____vm_create(mode, nr_pages, KVM_VM_TYPE_DEFAULT); kvm_sev_ioctl(vm, KVM_SEV_INIT, NULL);