From patchwork Thu Sep 9 01:38:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12482241 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 E4F46C433FE for ; Thu, 9 Sep 2021 01:46:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6B0F61181 for ; Thu, 9 Sep 2021 01:46:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B6B0F61181 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7cDGVhr8RNzq0lS0d5SoLsxUamb6MJ8mt0fbn7nmMW4=; b=NL67o0l5d2FAkbsifVMnD20NnD XTGOfWAy3mXnYNG2cTZaxCO9/YRvLWDexoD4s3Tjjg9BVqSwRcMaR8d5YR4SVfTKvLrkjOaNmU3K0 w/exx0jOA9RuSprTKUR0cn/q/Mj+H3GhZh8fIqdh/r0Cy4ysn2jg2f/wer0eoe120IdEqfheB7xV2 Bqbz6OBBLt87g10aofEN5g5kiqYEGHERy1hTTUCE0R5BXS3m4xGDei4OAMDMemZX1VPgvFNqlrnlO K/d5JFW98iyoCGPCaltuJ4MKLcl7KBPBKwFY0XxlBPEAchnTVAK+t2bXPKo83cWuME8zmRftN21mV cb3ZXfiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mO96c-007xkC-NW; Thu, 09 Sep 2021 01:43:59 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mO91j-007vRi-PT for linux-arm-kernel@lists.infradead.org; Thu, 09 Sep 2021 01:38:57 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id bp12-20020a05621407ec00b003773f981838so1931502qvb.22 for ; Wed, 08 Sep 2021 18:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ZaJi8CrqCPyJ9SPVj5/tYaTEiQv3pZu/dBaNxFMezdY=; b=PpNPK3uv3KYTEq4zFRqcV0VpV1U/YFs1TworIZSltJ6BzjGT+CFyrsaUQ81pFogUpL pbP/AhfGKn8nVNt0WTzGj6Z0pBSDe5pb8JxKb4lU3xhg4/hh859JoG10iSFxaDX/Ty8y ed8kkUkiiYlectcv79/1l4B0ScLwUy5TYyCI8eSdU1OIyOw3AlwBzYxwPV213RHZn+tL c92kEM3PpqswL8bzE3Rt3tU2Gb5AaGu+c6TGX+YETcwN19ItCASnme49ODyP5pAtuM20 5p6KnSq3BtkfvaGY7VjbVR/49ilbif92hnkWMBdj7yBJen8/3hFDiBNs3pao0KsWwySB MLNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ZaJi8CrqCPyJ9SPVj5/tYaTEiQv3pZu/dBaNxFMezdY=; b=fEtHuzi/+Nf/M0fMnhtyTfvreMFbVrpw7t6VYksPsXTK0beAZyDCpC6d9vsVmRsn0M LMNkwEpIza8u44avJWqFf8nfyqOvr74c0YiJzv3WNDOmrb5JuPI7ojNITmdY4srui1dB eAqVEcXcv1DCxhW2QaS/LrXq+gfERDke2OC3yPZ2B4ufH5lCN/4DhpeME5HijLNc7U6P oI6tcXHeRkZIJlh5KjN2+2no4OR9fs+co1bEIvKiyVhXm8+Ih6v6v/jq+NRLy3Xcmuo2 gXLBWuf3ApqcKtZRRZOnsfvltSNC1uy4VMHi2w0oLIvOJ6uNbQdGXVXEJrI+9z//rYxd P9+A== X-Gm-Message-State: AOAM530QeeVpGokm77CX/0+dfsYyQLHUrMAfCPRKUzAt/YJCwziULY1f S7B6R2uNbKg37uCEaevpIH+6lKwlArSl X-Google-Smtp-Source: ABdhPJy8pEbKtkdH/W5PM7WuN1paWanl2LDh5YKLnSr+Z8j+HMVfew5uBZscRMSLZ2k43Mgwzdxpo2kAQeIp X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a05:6214:104d:: with SMTP id l13mr485175qvr.13.1631151533677; Wed, 08 Sep 2021 18:38:53 -0700 (PDT) Date: Thu, 9 Sep 2021 01:38:12 +0000 In-Reply-To: <20210909013818.1191270-1-rananta@google.com> Message-Id: <20210909013818.1191270-13-rananta@google.com> Mime-Version: 1.0 References: <20210909013818.1191270-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [PATCH v4 12/18] KVM: selftests: Keep track of the number of vCPUs for a VM From: Raghavendra Rao Ananta To: Paolo Bonzini , Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210908_183855_873927_B0ECBD97 X-CRM114-Status: GOOD ( 12.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The host may want to know the number of vCPUs that were created for a particular VM (used in upcoming patches). Hence, include nr_vcpus as a part of 'struct kvm_vm' to keep track of vCPUs as and when they are added or deleted, and return to the caller via vm_get_nr_vcpus(). Signed-off-by: Raghavendra Rao Ananta --- tools/testing/selftests/kvm/include/kvm_util.h | 1 + tools/testing/selftests/kvm/lib/kvm_util.c | 7 +++++++ tools/testing/selftests/kvm/lib/kvm_util_internal.h | 1 + 3 files changed, 9 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index 010b59b13917..d5d0ca919928 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -399,5 +399,6 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc); int vm_get_stats_fd(struct kvm_vm *vm); int vcpu_get_stats_fd(struct kvm_vm *vm, uint32_t vcpuid); +int vm_get_nr_vcpus(struct kvm_vm *vm); #endif /* SELFTEST_KVM_UTIL_H */ diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 10a8ed691c66..1b5349b5132f 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -594,6 +594,7 @@ static void vm_vcpu_rm(struct kvm_vm *vm, struct vcpu *vcpu) list_del(&vcpu->list); free(vcpu); + vm->nr_vcpus--; } void kvm_vm_release(struct kvm_vm *vmp) @@ -1143,6 +1144,7 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid) /* Add to linked-list of VCPUs. */ list_add(&vcpu->list, &vm->vcpus); + vm->nr_vcpus++; } /* @@ -2343,3 +2345,8 @@ int vcpu_get_stats_fd(struct kvm_vm *vm, uint32_t vcpuid) return ioctl(vcpu->fd, KVM_GET_STATS_FD, NULL); } + +int vm_get_nr_vcpus(struct kvm_vm *vm) +{ + return vm->nr_vcpus; +} diff --git a/tools/testing/selftests/kvm/lib/kvm_util_internal.h b/tools/testing/selftests/kvm/lib/kvm_util_internal.h index a03febc24ba6..be4d852d2f3b 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util_internal.h +++ b/tools/testing/selftests/kvm/lib/kvm_util_internal.h @@ -56,6 +56,7 @@ struct kvm_vm { unsigned int va_bits; uint64_t max_gfn; struct list_head vcpus; + int nr_vcpus; struct userspace_mem_regions regions; struct sparsebit *vpages_valid; struct sparsebit *vpages_mapped;