Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp7624011ioo; Fri, 3 Jun 2022 10:06:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVh0tayZRVZgErFGa/CBHsD+7kDtQSQAO+AGcmbiI/LgEJtQbiWcyZVDWgQlD8bP8NTWwj X-Received: by 2002:a05:6402:2682:b0:42e:1c85:7ddc with SMTP id w2-20020a056402268200b0042e1c857ddcmr8275174edd.143.1654275965217; Fri, 03 Jun 2022 10:06:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654275965; cv=none; d=google.com; s=arc-20160816; b=pkHMYoKcXglKRDbAqZyiO+XqvdmlTmHPVRTXNxZtjBmgMgQh4JBsuv/PijPZPh6Bbi 22bTTVXsBuNFGm22drqh53EqaPO9n5QQumDXl1XUPy+08Cm62rwf+5OcYZhZcKUzJGVR cwQWz832n0GANoZKOXJA9lMRxBbx19yGEsaA/LOjTnH0NG6zee4q0GnlkRlnsncs2BOs gxt+4BZbY5wRtX1I3490Nju7EFTndMmp8O8CbYkOAaWAUM2FLZLruoxH26eKFvHkpvza Mn6/PePQ8ZlbxT5E1F/Wx5i9+I66kLbhzPvXw2nDuaADO47GEgikT0/ZCran/Hx6y2xG Sv9A== 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:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=i7TyyG/pheXHSCAMN2TUl4WUF9LIX1YQpLdcH3B6/rg=; b=u7YyOdjIv/gpuCveCTLT+qw81My+8HhJ+6RGX78KO6URfTscbfiBfjFXzrF+/wGoSA oODHl04LJwcGbHmz3KlzfOprAyYbXGtHRLb1fsXIRBfpXtKDXCN9K4dF7nC0ENhvPw/J jyVouYmcPL+x17hVMxSUeYhgpHspBz9jZsIE2meTKCUuWkOyes2XxEAsN0CO9xzU+VdF SKT+VJyBh0WiJxp4UxLGKkYoB8TQLXXVp5+0f6ZlQyCAFpgk6M8ef0Kb7b0+VubyzjDE Q2sszKhvHC5aUazVZjFA5U6u8+iAsAWzOlcAA94Kkoyech43SX7zd7baq9pPqbb6dSkk zo8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=eJHqEVN5; 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 z5-20020aa7c645000000b0042dbc7920d7si7509680edr.126.2022.06.03.10.05.39; Fri, 03 Jun 2022 10:06:05 -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=eJHqEVN5; 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 S241263AbiFCAuc (ORCPT + 99 others); Thu, 2 Jun 2022 20:50:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240217AbiFCApI (ORCPT ); Thu, 2 Jun 2022 20:45:08 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EFB033887 for ; Thu, 2 Jun 2022 17:45:07 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id h10-20020a170902f54a00b00166449db7f8so1559856plf.9 for ; Thu, 02 Jun 2022 17:45:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=i7TyyG/pheXHSCAMN2TUl4WUF9LIX1YQpLdcH3B6/rg=; b=eJHqEVN5MVelv00NchUI0BZIRKsIQEv+Gq5cslmQpY1sO4avZyHI3M7BGccJ4bc2v1 uF2dHcPQ5MyodQd9CXrbG5uM3Ox4lGFumLtbQvHC6RwQGOY1NBa12/UAnm8piJVm7KaY UXPMv5N1VuxcsE0aMrjRjlhYsuFuTdzcc1GfWt2QNUZ3FauIW5IhIgBSMAFShkYrlXS+ qoF+E6r+YqUpk+FhMgXmV5bOoIbO7579xy9C86hUmv05OZuf4O6SNbWv2g8jN82dnsQf khWPyTKs6wLo1jMEAmr2eCUu44cQXo6FHEYWFJ3ZUB/735moyDSrttQWG92u4iEZEjoX ON+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=i7TyyG/pheXHSCAMN2TUl4WUF9LIX1YQpLdcH3B6/rg=; b=FXcyGk+V3ak3pCQn5z2GhVh0M20yXV/kF5/Gm15Np6Qplaj8+wtGZV26k45KKmPtNk gH1TlEbbL0I1Z1f3v1pm++yKsBVgG6YLQSO6cTU/gdjTeVtXrMGn8rFIA+/WEaEUyozQ rdHj11fd8Pr2ddKEiin89OPmlwRwYAQhwl3eSTnpswxkD0svuiUl7keBaSsNCX2GdurV J5EY7vyyoNoTN9m98iA0NiulPYNFjjpYAMmY91bPfinrK05wT367jIoy8CEevXySCyoX skcZj+lc3c5J5vvg86YHzrRibU7E5MRC8nkowJJw4egzlnJUBxXFJcA6hBU/+bhLppzN pZ9w== X-Gm-Message-State: AOAM533oUJmU/nXdyBzvJqS+m+8w/yuqpGfGYfEOWOliBBoumHxcWyYd O6QDKqg+xzvQhLM1wWXyFDkheZ7zCfE= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:9891:b0:166:496a:b44d with SMTP id s17-20020a170902989100b00166496ab44dmr3892350plp.13.1654217106370; Thu, 02 Jun 2022 17:45:06 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 3 Jun 2022 00:41:56 +0000 In-Reply-To: <20220603004331.1523888-1-seanjc@google.com> Message-Id: <20220603004331.1523888-50-seanjc@google.com> Mime-Version: 1.0 References: <20220603004331.1523888-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH v2 049/144] KVM: selftests: Return the created vCPU from vm_vcpu_add() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , Andrew Jones , David Matlack , Ben Gardon , Oliver Upton , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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,T_SCC_BODY_TEXT_LINE,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 Return the created vCPU from vm_vcpu_add() so that callers don't need to manually retrieve the vCPU that was just added. Opportunistically drop the "heavy" function comment, it adds a lot of lines of "code" but not much value, e.g. it's pretty obvious that @vm is a virtual machine... Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/kvm_util_base.h | 2 +- tools/testing/selftests/kvm/lib/kvm_util.c | 27 +++++++------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index d2c7fb391fc7..fbc54e920383 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -324,7 +324,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags); void vm_mem_region_move(struct kvm_vm *vm, uint32_t slot, uint64_t new_gpa); void vm_mem_region_delete(struct kvm_vm *vm, uint32_t slot); -void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid); +struct kvm_vcpu *vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid); vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min); vm_vaddr_t vm_vaddr_alloc_pages(struct kvm_vm *vm, int nr_pages); vm_vaddr_t vm_vaddr_alloc_page(struct kvm_vm *vm); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 99d6c5a8659e..8348fa19690a 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -397,8 +397,7 @@ struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm) { kvm_vm_restart(vm); - vm_vcpu_add(vm, 0); - return vcpu_get(vm, 0); + return vm_vcpu_add(vm, 0); } /* @@ -1063,33 +1062,23 @@ static int vcpu_mmap_sz(void) } /* - * VM VCPU Add - * - * Input Args: - * vm - Virtual Machine - * vcpuid - VCPU ID - * - * Output Args: None - * - * Return: None - * - * Adds a virtual CPU to the VM specified by vm with the ID given by vcpuid. - * No additional VCPU setup is done. + * Adds a virtual CPU to the VM specified by vm with the ID given by vcpu_id. + * No additional vCPU setup is done. Returns the vCPU. */ -void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid) +struct kvm_vcpu *vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id) { struct kvm_vcpu *vcpu; /* Confirm a vcpu with the specified id doesn't already exist. */ - TEST_ASSERT(!vcpu_find(vm, vcpuid), "vCPU%d already exists\n", vcpuid); + TEST_ASSERT(!vcpu_find(vm, vcpu_id), "vCPU%d already exists\n", vcpu_id); /* Allocate and initialize new vcpu structure. */ vcpu = calloc(1, sizeof(*vcpu)); TEST_ASSERT(vcpu != NULL, "Insufficient Memory"); vcpu->vm = vm; - vcpu->id = vcpuid; - vcpu->fd = __vm_ioctl(vm, KVM_CREATE_VCPU, (void *)(unsigned long)vcpuid); + vcpu->id = vcpu_id; + vcpu->fd = __vm_ioctl(vm, KVM_CREATE_VCPU, (void *)(unsigned long)vcpu_id); TEST_ASSERT(vcpu->fd >= 0, KVM_IOCTL_ERROR(KVM_CREATE_VCPU, vcpu->fd)); TEST_ASSERT(vcpu_mmap_sz() >= sizeof(*vcpu->run), "vcpu mmap size " @@ -1102,6 +1091,8 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid) /* Add to linked-list of VCPUs. */ list_add(&vcpu->list, &vm->vcpus); + + return vcpu; } /* -- 2.36.1.255.ge46751e96f-goog