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.9 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=ham 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 30EA1C2B9F4 for ; Thu, 17 Jun 2021 05:22:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B449613BF for ; Thu, 17 Jun 2021 05:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbhFQFY5 (ORCPT ); Thu, 17 Jun 2021 01:24:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53109 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbhFQFYt (ORCPT ); Thu, 17 Jun 2021 01:24:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623907361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZyyHSrmDn9lggOnRJXhd5UV4zz1gTs3y67TMBTj2nvg=; b=ZE9ya2Na8p1j4gbTMsNbA8c3/YDKX9+u0sCx/sz7z31khnId999yGy08trVC5UiSMXq8br gbUIbm5Se5JtvLV58OgVj1TM/rPXRsq6BEoCC4kVZmwYrwx+7KObTHzRpJop4xOtHi9aWE G+ovWqg6sxxOo51p/8YIdx2a1I4iT1o= 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-343-_IZ2WPTAMJCW1bde_Kb3lA-1; Thu, 17 Jun 2021 01:22:40 -0400 X-MC-Unique: _IZ2WPTAMJCW1bde_Kb3lA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 59AEE801B15; Thu, 17 Jun 2021 05:22:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-104.ams2.redhat.com [10.36.112.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96E265C1C5; Thu, 17 Jun 2021 05:22:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2C266113865F; Thu, 17 Jun 2021 07:22:36 +0200 (CEST) From: Markus Armbruster To: Valeriy Vdovin Cc: qemu-devel@nongnu.org, Eduardo Habkost , Marcel Apfelbaum , Eric Blake , Paolo Bonzini , Marcelo Tosatti , Richard Henderson , Thomas Huth , Laurent Vivier , kvm@vger.kernel.org, Denis Lunev , Vladimir Sementsov-Ogievskiy Subject: Re: [PATCH v9] qapi: introduce 'query-kvm-cpuid' action References: <20210603090753.11688-1-valeriy.vdovin@virtuozzo.com> Date: Thu, 17 Jun 2021 07:22:36 +0200 In-Reply-To: <20210603090753.11688-1-valeriy.vdovin@virtuozzo.com> (Valeriy Vdovin's message of "Thu, 3 Jun 2021 12:07:53 +0300") Message-ID: <87im2d6p5v.fsf@dusky.pond.sub.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Valeriy Vdovin writes: > Introducing new qapi method 'query-kvm-cpuid'. This method can be used to It's actually a QMP command. There are no "qapi methods". > get virtualized cpu model info generated by QEMU during VM initialization in > the form of cpuid representation. > > Diving into more details about virtual cpu generation: QEMU first parses '-cpu' virtual CPU > command line option. From there it takes the name of the model as the basis for > feature set of the new virtual cpu. After that it uses trailing '-cpu' options, > that state if additional cpu features should be present on the virtual cpu or > excluded from it (tokens '+'/'-' or '=on'/'=off'). > After that QEMU checks if the host's cpu can actually support the derived > feature set and applies host limitations to it. > After this initialization procedure, virtual cpu has it's model and > vendor names, and a working feature set and is ready for identification > instructions such as CPUID. > > Currently full output for this method is only supported for x86 cpus. Not sure about "currently": the interface looks quite x86-specific to me. The commit message doesn't mention KVM except in the command name. The schema provides the command only if defined(CONFIG_KVM). Can you explain why you need the restriction to CONFIG_KVM? > To learn exactly how virtual cpu is presented to the guest machine via CPUID > instruction, new qapi method can be used. By calling 'query-kvm-cpuid' QMP command again. > method, one can get a full listing of all CPUID leafs with subleafs which are > supported by the initialized virtual cpu. > > Other than debug, the method is useful in cases when we would like to > utilize QEMU's virtual cpu initialization routines and put the retrieved > values into kernel CPUID overriding mechanics for more precise control > over how various processes perceive its underlying hardware with > container processes as a good example. > > Output format: > The output is a plain list of leaf/subleaf agrument combinations, that Typo: argument > return 4 words in registers EAX, EBX, ECX, EDX. > > Use example: > qmp_request: { > "execute": "query-kvm-cpuid" > } > > qmp_response: { > "return": [ > { > "eax": 1073741825, > "edx": 77, > "in-eax": 1073741824, > "ecx": 1447775574, > "ebx": 1263359563 > }, > { > "eax": 16777339, > "edx": 0, > "in-eax": 1073741825, > "ecx": 0, > "ebx": 0 > }, > { > "eax": 13, > "edx": 1231384169, > "in-eax": 0, > "ecx": 1818588270, > "ebx": 1970169159 > }, > { > "eax": 198354, > "edx": 126614527, > "in-eax": 1, > "ecx": 2176328193, > "ebx": 2048 > }, > .... > { > "eax": 12328, > "edx": 0, > "in-eax": 2147483656, > "ecx": 0, > "ebx": 0 > } > ] > } > > Signed-off-by: Valeriy Vdovin > --- > v2: - Removed leaf/subleaf iterators. > - Modified cpu_x86_cpuid to return false in cases when count is > greater than supported subleaves. > v3: - Fixed structure name coding style. > - Added more comments > - Ensured buildability for non-x86 targets. > v4: - Fixed cpu_x86_cpuid return value logic and handling of 0xA leaf. > - Fixed comments. > - Removed target check in qmp_query_cpu_model_cpuid. > v5: - Added error handling code in qmp_query_cpu_model_cpuid > v6: - Fixed error handling code. Added method to query_error_class > v7: - Changed implementation in favor of cached cpuid_data for > KVM_SET_CPUID2 > v8: - Renamed qmp method to query-kvm-cpuid and some fields in response. > - Modified documentation to qmp method > - Removed helper struct declaration > v9: - Renamed 'in_eax' / 'in_ecx' fields to 'in-eax' / 'in-ecx' > - Pasted more complete response to commit message. > > qapi/machine-target.json | 43 ++++++++++++++++++++++++++++++++++++++ > target/i386/kvm/kvm.c | 37 ++++++++++++++++++++++++++++++++ > tests/qtest/qmp-cmd-test.c | 1 + > 3 files changed, 81 insertions(+) > > diff --git a/qapi/machine-target.json b/qapi/machine-target.json > index e7811654b7..1e591ba481 100644 > --- a/qapi/machine-target.json > +++ b/qapi/machine-target.json > @@ -329,3 +329,46 @@ > ## > { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'], > 'if': 'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386) || defined(TARGET_S390X) || defined(TARGET_MIPS)' } > + > +## > +# @CpuidEntry: > +# > +# A single entry of a CPUID response. > +# > +# One entry holds full set of information (leaf) returned to the guest in response > +# to it calling a CPUID instruction with eax, ecx used as the agruments to that Typi: agruments > +# instruction. ecx is an optional argument as not all of the leaves support it. Please wrap doc comment lines around column 70. > +# > +# @in-eax: CPUID argument in eax > +# @in-ecx: CPUID argument in ecx > +# @eax: eax > +# @ebx: ebx > +# @ecx: ecx > +# @edx: edx Suggest # @eax: CPUID result in eax and so forth. > +# > +# Since: 6.1 > +## > +{ 'struct': 'CpuidEntry', > + 'data': { 'in-eax' : 'uint32', > + '*in-ecx' : 'uint32', > + 'eax' : 'uint32', > + 'ebx' : 'uint32', > + 'ecx' : 'uint32', > + 'edx' : 'uint32' > + }, > + 'if': 'defined(TARGET_I386) && defined(CONFIG_KVM)' } > + > +## > +# @query-kvm-cpuid: > +# > +# Returns raw data from the KVM CPUID table for the first VCPU. > +# The KVM CPUID table defines the response to the CPUID > +# instruction when executed by the guest operating system. > +# > +# Returns: a list of CpuidEntry > +# > +# Since: 6.1 > +## > +{ 'command': 'query-kvm-cpuid', > + 'returns': ['CpuidEntry'], > + 'if': 'defined(TARGET_I386) && defined(CONFIG_KVM)' } Is this intended to be a stable interface? Interfaces intended just for debugging usually aren't. [...]