From nobody Sat May 4 22:41:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1642785255; cv=pass; d=zohomail.com; s=zohoarc; b=AB6GEotq712G6GM7Fm8Ome82/9JM8eOaX0GFFKI6JQCwVJ6Ku1j3WTNBa3QtNckM0ce+HX8eTIXqmfABJ7I4qCGflfClpczFXaSzrPd14i9fVxMRR75gnRGDC4BZoTQWzsWqxn7ElkfAyUrefWyofZCcUmlcrsi8aj6OGXQeeD0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642785255; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=CqLzZHN0H995YMchR5QYAKCR7gF5miTDNwenQEef+4Y=; b=cOMo2SMyrXC0gb7tp9bY+fh9/RTphh+XT/dSwWVCcRQeTwKBWML+/9nyE/mvCn4VDmfs7Gb9hb2D9Yf8TAybOLNAL50xuXVJJ/Iv+zo+hUeDy2+8PxpIoge85itS6GsKBczzv1txksUY/oVe04JIGcnqm0D0mbWj8qSU9dUxy7I= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642785254863627.1275958420846; Fri, 21 Jan 2022 09:14:14 -0800 (PST) Received: from localhost ([::1]:39894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAxUL-0007VR-Kb for importer@patchew.org; Fri, 21 Jan 2022 12:14:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAwxF-0006qH-FN for qemu-devel@nongnu.org; Fri, 21 Jan 2022 11:40:01 -0500 Received: from mail-eopbgr130127.outbound.protection.outlook.com ([40.107.13.127]:29034 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAwxC-0003yE-Cf for qemu-devel@nongnu.org; Fri, 21 Jan 2022 11:40:00 -0500 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM0PR08MB3348.eurprd08.prod.outlook.com (2603:10a6:208:65::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Fri, 21 Jan 2022 16:39:54 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd%3]) with mapi id 15.20.4909.012; Fri, 21 Jan 2022 16:39:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MNmxwc6A7iDn/ndQ+i/8nnSBsH66tnx6K5P+8Aq5hXqjFLSz8REZFIHAAhrStY9e1MezxI100psyGn2Digr6wEgPqtKR+3Ue2HJz+fNDpI/KQ4aVNOpMlCziDKlpCpXYioscxHkQku/Q0nrgt9z8+SDiSrc7Go3vEwlbcG6wruWsAJEmUr/04bH7iPwERH4zqcW9zRddx09p0dCsRZHUAQpvf2qWC7mvB5QLH5YvFLoc0w4krM5Wvcw5CCAq4ideRkljWBqEkL+23ZjtuuVFgkwETPw5kXYktczzy2ihQBtmIVVYfKWmnTpJw/cNFObIYVtrLVgIvkvEdlbb6cmvWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CqLzZHN0H995YMchR5QYAKCR7gF5miTDNwenQEef+4Y=; b=iKP4aG+ewKZnL/lTo321rHE+rAgTajnYdMaA1Ns5ZyQgS7G8eOuYq7afBOQLzq7eQeBk+A1/vMRoY781F3sGCu1cdGvmMzGfbI7VzjNTsYb4oUwGA1YVnfLST02KfrdFzwvgbMS4PxUf/Dgjw9UgCkzBXfcj1o+qVwKSWvWgmWl2PmNzasUMZDcs/3b85jvGEIxZqtTwExaM9Wyd/NfVs8ud64a2o/N5TI1Qoo2Cdg9Ug/sEEOM9FfjlGM0B1jQ5vgrirclK65A9v6HVMrLW8RHCl0us2M4VgyeM+Wx7T9FgjwVNBC7bYnP7qC2Ueg/Djl3nUq9c8i37zsUVvkhCQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CqLzZHN0H995YMchR5QYAKCR7gF5miTDNwenQEef+4Y=; b=Vr+fo4Q/X/JF2vl6I7gqfN/TVdbER150UXSL+cZJV5qlMaS3jrLUUT4ZyLMZWkqZhuZjgkzF5tUEiYVf6n0UQsxzNi8zY5j/YT9OXeZA003hRrcVq2rK5yCnVGjiS7T1e+jqSkhAaPyosDTIJAdxNKfBOwcQd57EXjSps3a5kFI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, lvivier@redhat.com, thuth@redhat.com, mtosatti@redhat.com, richard.henderson@linaro.org, pbonzini@redhat.com, armbru@redhat.com, eblake@redhat.com, wangyanan55@huawei.com, f4bug@amsat.org, marcel.apfelbaum@gmail.com, eduardo@habkost.net, vsementsov@virtuozzo.com, valery.vdovin.s@gmail.com, den@openvz.org, Valeriy Vdovin Subject: [PATCH v17] qapi: introduce 'x-query-x86-cpuid' QMP command. Date: Fri, 21 Jan 2022 17:39:43 +0100 Message-Id: <20220121163943.2720015-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM6PR10CA0097.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::38) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6e5edb4d-a475-4939-9754-08d9dcfca697 X-MS-TrafficTypeDiagnostic: AM0PR08MB3348:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wKwj5a4V0JL9trXUYSHIVKLTrNogxAFFiCDsFVQ9elb7UtaYTrBx9NGMaW9Y07JfQFBvaB6e720JK4Ano2xkELd38asluHpsqUdPniE6pyupssoFDiErmW01/mKxmaAJqngLBSV+Jga4/ROnhs8wi+TbBxvQC7SyNIilBn79xg6tKe/7IjtuaXQCSK7zcL3nM8LmcXDSTlCo9WnoBH1/R5ESO6m1eCLQPvJO2MajoeCGOgbIHec+I4fNWHH1OMhXPpoUWpSFx7WFUjPft8+Zb1wjskZutSJGYoC4X9N27zPBBYPpjXLasL2D6OORYZWYECGeVxx87T5bFOdsH8cihtpV/Q7SdyRI7kVAxAdSXGhE0WQas5r+Tzn2MhzPpWKtHes3OB0qosPLAh8chWDvF1AjkUVvGeBFUV26HeMWlmsXFnekUiOM/7WxeZs0K/1Qojhj7Xikq+B7lGDlcwW+VdWzDi0NxHJxgSg6zQGiEahMx0Aw+rt6JzGYR3aXgwvyHEwHOyuoCrVZ3/3TZotTkGYB7KG35Z4S/tVZvXluWLgrtwwCm8mU3ljZH8+Ox7j3vRE7xtYrp63bbG2eYInqn6HWpSiWs+jqoBctBeReLS5XY2wAZ4nZnQodXUMdxlcDMnZbRGXRFEgKyDmfHPob1jvWSKuDmBF2BRyTI9HTI6KR4SKNNgxPVnhoBmMdcST6bhicstX6FO3BUFbWmg7cVQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(66476007)(66556008)(5660300002)(38100700002)(36756003)(26005)(508600001)(66946007)(6506007)(6486002)(38350700002)(6666004)(4326008)(107886003)(1076003)(186003)(316002)(83380400001)(2616005)(2906002)(52116002)(6512007)(8676002)(86362001)(8936002)(7416002)(6916009); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?049K0OPxFNbB/GRz9+PDUjA/V6cmr1cKmBpyZwjTXHRh3RMTbdmmLjaCfuMx?= =?us-ascii?Q?O8wcWJ8xanY81BXsscpxeM/fW+I8XwG4kMR3CN2oQIbLz0Cw/X6l1Eor1oHk?= =?us-ascii?Q?nVLJfQWa1H1rXzXQtfm3fyZENUhUKpqe3PDOpv5cSWegyBAhvJqMwv75fdi1?= =?us-ascii?Q?g3IsSMZqS9wCsxQA3JT7AuKqkysHKL2mPbhNu6/WX2u8AFvlsNH1z67lAXhQ?= =?us-ascii?Q?+/e6XdzXWtqsBysKFioDQNWXWKeWpnLmtp4zRTxcHuHBjn5J39cD78xU6Jmg?= =?us-ascii?Q?NPcPXrYbvz5iH5+XLoIEtwor6qvOY7XPdIT+OPHis6kw6AKnYB2LBbMFH7eY?= =?us-ascii?Q?Ty8wALIVFFKrjN8irC0ybjYgFBF/vfVIwm2HnsCiMvUN1o3jFaLl5ratltwq?= =?us-ascii?Q?AMWl8ZMKrli6LDZ6ySFYQgfjesxxdSfCru6BjgzfpBBOnAihD6mnc2gCqx9/?= =?us-ascii?Q?sm8evf0sdAI2rdXVrggz5xfdJbKD0zxUe1lbdB6Z/8F/P6nNJk6cI30NVAn8?= =?us-ascii?Q?EYxy9ugtTQuSfRVuZWm4sUtf2gl7X5CG6WeOCeUDrGPpz70uZ7ZeqFYipdBw?= =?us-ascii?Q?MJglIUygxHUyiHusQdzaEdi3WUF9ezRIMpAcnHfRyxXjILjgBbi3Tc4vTLS9?= =?us-ascii?Q?a9U5W7gDIe2XTUQ4jqbdHciNsJ/9DTpp6NmRcMVqDAV/I5/zUzmVGg6zSL/x?= =?us-ascii?Q?iO9F6qO+xK6IQP0cHMWWP1Qu0ICRXWWazF+v8kqftMf1+HkWGymfsbD4SMHh?= =?us-ascii?Q?bbChq3aWtt9P/8UKzZb/ZV9Husa5IfPOyRDBpjyYcsPXofRcOVc7Ut1cR0OZ?= =?us-ascii?Q?dFNiNnPkXcOyGHyx1z7uw6gEkHMWzwfmz+HZIUwf0sKgOXwSkerZ1iWbOlnE?= =?us-ascii?Q?UGOgr1IecD1vCh/dmv+Bqz2qf0m9SDHf23BIWQmw4mVGvTzgNa+3q8RQIVC0?= =?us-ascii?Q?n3Yi6L2HFgRy+SP6rmVgV2QpPTMT3msUhhWmWkSnv5W+f9Ji9eX4NSCpDnli?= =?us-ascii?Q?U4b2W3tGmIggC40+3dvrAuhs8dxM85Qu+6J995EvG2qYSV+J3kPn+9aKV0Ii?= =?us-ascii?Q?hiVdInpu21E8BqdRI8E6djc51qz2/GVRuk0zcQ3DZEqmlO8y7HDKOTqwEKP/?= =?us-ascii?Q?gvUddCPF3EGnOynhtnTz5xts2m6FApztqcvIeFiXgB4DXYfO6/FRNjHiASpW?= =?us-ascii?Q?KxjL4ecoDH+4SbGcBchh73XUaW/3x3ZrY7W2O4m2amgTIrIPvZhDFJJgePwe?= =?us-ascii?Q?FMgqPnDbqsguHOqTlIO+Kx6D25t5inQ+0dFOL4JOv+XyUNMFAT0eNY8MhQ3F?= =?us-ascii?Q?qFZh0GDspumFJ+dhiV22A2MTQTSlDAbVUifQ0wpUF+OWPYOSvWnVt384UNj2?= =?us-ascii?Q?ffJVDZOPI2VFlFCDOMGuDm/atP9y7FY4xaN+cDh4pifnweSAUggcMP9PFwpF?= =?us-ascii?Q?r8RY+pJRvOpJKEPRf/eLsmVOcWye6q0M/L7aE0mMhl842ccLYnZ4yFBlBkLJ?= =?us-ascii?Q?nCcjrwvwZ8TcfCJczJsg/ZQ0IJI5yCnsZ1vB4H7MnTp2t6PDaR8C5ebWvVp+?= =?us-ascii?Q?pJ4+ZbXk9LWb4q5qOx6/WLw5O3wea6R8JJ70pVoVUoNFilHFKQy3sMRYuEB8?= =?us-ascii?Q?wa4MlWGplTvQ3YorEoC0VhTahnHZ2hm8mmittboYjTXbNKdQ2048B1e3FbUR?= =?us-ascii?Q?tPozwQ=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e5edb4d-a475-4939-9754-08d9dcfca697 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2022 16:39:53.9312 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eaNHJdhqdHhU7MCPBqA+keiD3Gcx6+0j87tSUVNu9ZLVS+vVA3IADB6qd0PIAb4x4vmN7yJF7RZ6dg6k6SUyOkhM4We4yS3LTHAK7M8ajH8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3348 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.13.127; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1642785257073100001 Content-Type: text/plain; charset="utf-8" From: Valeriy Vdovin Introducing new QMP command 'query-x86-cpuid'. This command can be used to 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' 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 '=3Don'/'=3Doff'). 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. To learn exactly how virtual CPU is presented to the guest machine via CPUID instruction, new QMP command can be used. By calling 'query-x86-cpuid' command, one can get a full listing of all CPUID leaves with subleaves which are supported by the initialized virtual CPU. Other than debug, the command 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. The command is specific to x86. It is currenly only implemented for KVM acceleator. Output format: The output is a plain list of leaf/subleaf argument combinations, that return 4 words in registers EAX, EBX, ECX, EDX. Use example: qmp_request: { "execute": "x-query-x86-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 Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Markus Armbruster --- v17: wrap long lines, add QAPI feature 'unstable' [Markus] qapi/machine-target.json | 50 ++++++++++++++++++++++++++++++++++++++ softmmu/cpus.c | 2 +- target/i386/kvm/kvm-stub.c | 9 +++++++ target/i386/kvm/kvm.c | 44 +++++++++++++++++++++++++++++++++ tests/qtest/qmp-cmd-test.c | 1 + 5 files changed, 105 insertions(+), 1 deletion(-) diff --git a/qapi/machine-target.json b/qapi/machine-target.json index f5ec4bc172..1568e17e74 100644 --- a/qapi/machine-target.json +++ b/qapi/machine-target.json @@ -341,3 +341,53 @@ 'TARGET_I386', 'TARGET_S390X', '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 arguments to that instruction. ecx is an optional argument as +# not all of the leaves support it. +# +# @in-eax: CPUID argument in eax +# @in-ecx: CPUID argument in ecx +# @eax: CPUID result in eax +# @ebx: CPUID result in ebx +# @ecx: CPUID result in ecx +# @edx: CPUID result in edx +# +# Since: 7.0 +## +{ 'struct': 'CpuidEntry', + 'data': { 'in-eax' : 'uint32', + '*in-ecx' : 'uint32', + 'eax' : 'uint32', + 'ebx' : 'uint32', + 'ecx' : 'uint32', + 'edx' : 'uint32' + }, + 'if': 'TARGET_I386' } + +## +# @x-query-x86-cpuid: +# +# Returns raw data from the emulated CPUID table for the first VCPU. +# The emulated CPUID table defines the response to the CPUID +# instruction when executed by the guest operating system. +# +# Features: +# @unstable: This command is experimental. +# +# Returns: a list of CpuidEntry. Returns error when qemu is configured +# with --disable-kvm flag or if qemu is run with any other +# accelerator than KVM. +# +# Since: 7.0 +## +{ 'command': 'x-query-x86-cpuid', + 'returns': [ 'CpuidEntry' ], + 'if': 'TARGET_I386', + 'features': [ 'unstable' ] } diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 23bca46b07..33045bf45c 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -129,7 +129,7 @@ void hw_error(const char *fmt, ...) /* * The chosen accelerator is supposed to register this. */ -static const AccelOpsClass *cpus_accel; +const AccelOpsClass *cpus_accel; =20 void cpu_synchronize_all_states(void) { diff --git a/target/i386/kvm/kvm-stub.c b/target/i386/kvm/kvm-stub.c index f6e7e4466e..71631e560d 100644 --- a/target/i386/kvm/kvm-stub.c +++ b/target/i386/kvm/kvm-stub.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "cpu.h" #include "kvm_i386.h" +#include "qapi/error.h" =20 #ifndef __OPTIMIZE__ bool kvm_has_smm(void) @@ -44,3 +45,11 @@ bool kvm_hyperv_expand_features(X86CPU *cpu, Error **err= p) { abort(); } + +CpuidEntryList *qmp_x_query_x86_cpuid(Error **errp); + +CpuidEntryList *qmp_x_query_x86_cpuid(Error **errp) +{ + error_setg(errp, "Not implemented in --disable-kvm configuration"); + return NULL; +} diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 2c8feb4a6f..eb73869039 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -20,11 +20,13 @@ =20 #include #include "standard-headers/asm-x86/kvm_para.h" +#include "qapi/qapi-commands-machine-target.h" =20 #include "cpu.h" #include "host-cpu.h" #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" +#include "sysemu/accel-ops.h" #include "sysemu/kvm_int.h" #include "sysemu/runstate.h" #include "kvm_i386.h" @@ -1565,6 +1567,44 @@ static Error *invtsc_mig_blocker; =20 #define KVM_MAX_CPUID_ENTRIES 100 =20 +struct kvm_cpuid2 *cpuid_data_cached; + + +CpuidEntryList *qmp_x_query_x86_cpuid(Error **errp) +{ + int i; + struct kvm_cpuid_entry2 *kvm_entry; + CpuidEntryList *head =3D NULL, **tail =3D &head; + CpuidEntry *entry; + + if (!kvm_enabled()) { + error_setg(errp, "Not implemented for non-kvm accel"); + return NULL; + } + + if (!cpuid_data_cached) { + error_setg(errp, "VCPU was not initialized yet"); + return NULL; + } + + for (i =3D 0; i < cpuid_data_cached->nent; ++i) { + kvm_entry =3D &cpuid_data_cached->entries[i]; + entry =3D g_malloc0(sizeof(*entry)); + entry->in_eax =3D kvm_entry->function; + if (kvm_entry->flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX) { + entry->in_ecx =3D kvm_entry->index; + entry->has_in_ecx =3D true; + } + entry->eax =3D kvm_entry->eax; + entry->ebx =3D kvm_entry->ebx; + entry->ecx =3D kvm_entry->ecx; + entry->edx =3D kvm_entry->edx; + QAPI_LIST_APPEND(tail, entry); + } + + return head; +} + int kvm_arch_init_vcpu(CPUState *cs) { struct { @@ -1981,6 +2021,10 @@ int kvm_arch_init_vcpu(CPUState *cs) if (r) { goto fail; } + if (!cpuid_data_cached) { + cpuid_data_cached =3D g_malloc0(sizeof(cpuid_data)); + memcpy(cpuid_data_cached, &cpuid_data, sizeof(cpuid_data)); + } =20 if (has_xsave) { env->xsave_buf_len =3D sizeof(struct kvm_xsave); diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c index 7f103ea3fd..94d9184a84 100644 --- a/tests/qtest/qmp-cmd-test.c +++ b/tests/qtest/qmp-cmd-test.c @@ -54,6 +54,7 @@ static int query_error_class(const char *cmd) /* Only valid with accel=3Dtcg */ { "x-query-jit", ERROR_CLASS_GENERIC_ERROR }, { "x-query-opcount", ERROR_CLASS_GENERIC_ERROR }, + { "x-query-x86-cpuid", ERROR_CLASS_GENERIC_ERROR }, { NULL, -1 } }; int i; --=20 2.31.1