From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 95C14C433E6 for ; Tue, 30 Mar 2021 19:00:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BABD619D2 for ; Tue, 30 Mar 2021 19:00:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233007AbhC3S7o (ORCPT ); Tue, 30 Mar 2021 14:59:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35089 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232943AbhC3S7N (ORCPT ); Tue, 30 Mar 2021 14:59:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617130752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=84Zr99k/BLMEUkVeh+jVwwXBIWqAlip0+t5vxhNu95E=; b=g8kQQr3ijCxx1MKdK1cNy4mgNlrlPI4bcf/PnmV3Iaa+0Ui2z/pCfhmCU1Mx739mKNz0Ru LCe/Azxbh/4eDwwWA1nVj7Hecr0YZOd6dAksKG7Bc4OeC1CWgolM0+gl4bhui+craCrJ0E 3bna7xWKbXHA0BiQlf8EwSIdLfmpfWk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-78-mqI_QNfmOumQG9reoZ_7yA-1; Tue, 30 Mar 2021 14:59:08 -0400 X-MC-Unique: mqI_QNfmOumQG9reoZ_7yA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3D5F911E3; Tue, 30 Mar 2021 18:59:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-41.ams2.redhat.com [10.36.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 826F019C44; Tue, 30 Mar 2021 18:59:02 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Shuah Khan , Alexander Graf , Andrew Jones , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH 3/4] selftests: add kvm_get_emulated_cpuid Date: Tue, 30 Mar 2021 20:58:40 +0200 Message-Id: <20210330185841.44792-4-eesposit@redhat.com> In-Reply-To: <20210330185841.44792-1-eesposit@redhat.com> References: <20210330185841.44792-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As the similar kvm_get_supported_cpuid, allocates and gets the struct kvm_cpuid2 filled with emulated features. Signed-off-by: Emanuele Giuseppe Esposito --- .../selftests/kvm/include/x86_64/processor.h | 1 + .../selftests/kvm/lib/x86_64/processor.c | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 0b30b4e15c38..ae1b9530e187 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -353,6 +353,7 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_msr_list *kvm_get_msr_index_list(void); uint64_t kvm_get_feature_msr(uint64_t msr_index); struct kvm_cpuid2 *kvm_get_supported_cpuid(void); +struct kvm_cpuid2 *kvm_get_emulated_cpuid(void); struct kvm_cpuid2 *vcpu_get_cpuid(struct kvm_vm *vm, uint32_t vcpuid); void vcpu_set_cpuid(struct kvm_vm *vm, uint32_t vcpuid, diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index e676fe40bfe6..2ea14421bdfe 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -669,6 +669,39 @@ struct kvm_cpuid2 *kvm_get_supported_cpuid(void) return cpuid; } +/* + * KVM Emulated CPUID Get + * + * Input Args: None + * + * Output Args: + * + * Return: The emulated KVM CPUID + * + * Get the guest CPUID emulated by KVM. + */ +struct kvm_cpuid2 *kvm_get_emulated_cpuid(void) +{ + static struct kvm_cpuid2 *cpuid; + int ret; + int kvm_fd; + + if (cpuid) + return cpuid; + + cpuid = allocate_kvm_cpuid2(); + kvm_fd = open(KVM_DEV_PATH, O_RDONLY); + if (kvm_fd < 0) + exit(KSFT_SKIP); + + ret = ioctl(kvm_fd, KVM_GET_EMULATED_CPUID, cpuid); + TEST_ASSERT(ret == 0, "KVM_GET_EMULATED_CPUID failed %d %d\n", + ret, errno); + + close(kvm_fd); + return cpuid; +} + /* * KVM Get MSR * -- 2.30.2