From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614606886; cv=none; d=zohomail.com; s=zohoarc; b=kQx6c44qIwf7VB0oJ5Ll588P9iNiKlg9n1oXxKZhHXmJmHVyap0jkWjdd1UrLgWL+EtgMW9lDHLa+9dN6Rpqk07YM5vuaCmn+PMncopppFm9SM3mEOMCbS93ZEGE6o+/WPf4rPNw9UPF2NukwYE3q5Vc39LswNBr7WWkZ21JQ20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614606886; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vZZ+6cjdYvXjAQueMSXVi2Hk39X3kgiy8hj6VSuKDas=; b=eSXh6irPyL767aTG1ww9QZxxMYHynEVat7N8nd5UNq30Ngf+Uml3n++a3EQOCLqg+St4jU9zShlXuk8TH9wcZen/HZQosfcrqLxM9IPw52n6lOTJM4ciQ9wl+G4Dhjrh2cNPizkt6kvbYL8Q2fxIXSeUwd+13C9RfJDybX4orCA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16146068866841020.9355633396262; Mon, 1 Mar 2021 05:54:46 -0800 (PST) Received: from localhost ([::1]:47492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj0X-0002j1-KL for importer@patchew.org; Mon, 01 Mar 2021 08:54:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGix9-0006Kt-5g for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38362) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGix7-0008Av-Hu for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:14 -0500 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-484-jUL8ragCN8WnD-u7ocQPRw-1; Mon, 01 Mar 2021 08:51:10 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15A9D8030D4 for ; Mon, 1 Mar 2021 13:51:09 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 668A45D735; Mon, 1 Mar 2021 13:51:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606672; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vZZ+6cjdYvXjAQueMSXVi2Hk39X3kgiy8hj6VSuKDas=; b=Y7ZD0euwYqR286mUIN8XJreNneJZdFfPCoz8tRIgLxHTwkZHnX2Rj2LQ/LMiOaYiV9Pdsa W++NZZQkKyFGEKAODDYyObeYvOE3/wk1mwcjpBFfLKtGbpy3odBDb9tPjy8exJHvdhDSfv y7ejkdRkFTKKinRgcLKWu9LpQpBpCow= X-MC-Unique: jUL8ragCN8WnD-u7ocQPRw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 01/17] i386: keep hyperv_vendor string up-to-date Date: Mon, 1 Mar 2021 14:50:47 +0100 Message-Id: <20210301135103.306003-2-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When cpu->hyperv_vendor is not set manually we default to "Microsoft Hv" and in 'hv_passthrough' mode we get the information from the host. This information is stored in cpu->hyperv_vendor_id[] array but we don't update cpu->hyperv_vendor string so e.g. QMP's query-cpu-model-expansion output is incorrect. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 19 +++++++++---------- target/i386/kvm/kvm.c | 5 +++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6a53446e6a56..ee094877d7a1 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6653,17 +6653,16 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu) =20 /* Hyper-V vendor id */ if (!cpu->hyperv_vendor) { - memcpy(cpu->hyperv_vendor_id, "Microsoft Hv", 12); - } else { - len =3D strlen(cpu->hyperv_vendor); - - if (len > 12) { - warn_report("hv-vendor-id truncated to 12 characters"); - len =3D 12; - } - memset(cpu->hyperv_vendor_id, 0, 12); - memcpy(cpu->hyperv_vendor_id, cpu->hyperv_vendor, len); + object_property_set_str(OBJECT(cpu), "hv-vendor-id", "Microsoft Hv= ", + &error_abort); + } + len =3D strlen(cpu->hyperv_vendor); + if (len > 12) { + warn_report("hv-vendor-id truncated to 12 characters"); + len =3D 12; } + memset(cpu->hyperv_vendor_id, 0, 12); + memcpy(cpu->hyperv_vendor_id, cpu->hyperv_vendor, len); =20 /* 'Hv#1' interface identification*/ cpu->hyperv_interface_id[0] =3D 0x31237648; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 0b5755e42b87..8e9ae7522582 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1215,6 +1215,11 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_vendor_id[0] =3D c->ebx; cpu->hyperv_vendor_id[1] =3D c->ecx; cpu->hyperv_vendor_id[2] =3D c->edx; + cpu->hyperv_vendor =3D g_realloc(cpu->hyperv_vendor, + sizeof(cpu->hyperv_vendor_id) += 1); + memcpy(cpu->hyperv_vendor, cpu->hyperv_vendor_id, + sizeof(cpu->hyperv_vendor_id)); + cpu->hyperv_vendor[sizeof(cpu->hyperv_vendor_id)] =3D 0; } =20 c =3D cpuid_find_entry(cpuid, HV_CPUID_INTERFACE, 0); --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607021; cv=none; d=zohomail.com; s=zohoarc; b=mbFFZzpV6aEfd7T7BCny9jyWXJlM+0SU6cWTdFGJ1hznRZaGwir765VtSu7Za2cEVO42AVUvCaRdOxryQcwbd7pWvvfH/Bmr8igg7zBS9ldapDhSYsM8DhacdJ3YF7FLj0Lfh9ENoM0XhbW+wULZjt/4dmSnoiwTNLSuY3nuWoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607021; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=STDYG2C0r5ezYHC953mhUFGQmj+wVZ38k9FuWXE1Uco=; b=nBK5iHehYSp4GT5lpanx4z5ZspI4LZK//ngB6w5NF27A+6WNV9XoMfklYEnBZ+N+G7IS+ONVkgSHqzRUF5VRZBJgJYqN5+8hr5XvI08OI7Pr8ncRweGqFr4gDslnWupugpaI7cGDJvmgBv7D8/XvbWJwnmojUX2rPkdDu5GbK4I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607021911530.8656959530459; Mon, 1 Mar 2021 05:57:01 -0800 (PST) Received: from localhost ([::1]:55956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj2i-0006G2-QO for importer@patchew.org; Mon, 01 Mar 2021 08:57:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGix9-0006Le-QI for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34580) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGix8-0008Bb-7t for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:15 -0500 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-445-C6XmRZc1NmezXxoKJsWAmg-1; Mon, 01 Mar 2021 08:51:12 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17A7B8030CC for ; Mon, 1 Mar 2021 13:51:11 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76E0A5D735; Mon, 1 Mar 2021 13:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606673; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=STDYG2C0r5ezYHC953mhUFGQmj+wVZ38k9FuWXE1Uco=; b=FMSoFWeRSwDlUsfFsohQp9b8W+oY4yWJ/5tLQpj+c71T8F/L0JwP2XOhHcP7fsijlryxE6 Ax/ifPrWd3zEUuvUv+oZJVglTWh/M7bNmX1bCYBesLjsoIY1SgZg5Ur9iRw4PjOIWNsD8O HCcWlFiU/XB1EAZBkDqyqNH1nJTjxu4= X-MC-Unique: C6XmRZc1NmezXxoKJsWAmg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 02/17] i386: invert hyperv_spinlock_attempts setting logic with hv_passthrough Date: Mon, 1 Mar 2021 14:50:48 +0100 Message-Id: <20210301135103.306003-3-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There is no need to have this special case: like all other Hyper-V enlightenments we can just use kernel's supplied value in hv_passthrough mode. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 8e9ae7522582..3c1202333d9d 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1256,11 +1256,7 @@ static int hyperv_handle_properties(CPUState *cs, c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); if (c) { env->features[FEAT_HV_RECOMM_EAX] =3D c->eax; - - /* hv-spinlocks may have been overriden */ - if (cpu->hyperv_spinlock_attempts !=3D HYPERV_SPINLOCK_NEVER_N= OTIFY) { - c->ebx =3D cpu->hyperv_spinlock_attempts; - } + cpu->hyperv_spinlock_attempts =3D c->ebx; } c =3D cpuid_find_entry(cpuid, HV_CPUID_NESTED_FEATURES, 0); if (c) { --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614606780; cv=none; d=zohomail.com; s=zohoarc; b=bgdIuiqO4l8dQnH2UIW+dRZXAiAEDtWzJ+FZafBDaP36KovWI1E0836yAcT74A5/0xSnONcJpnjk0YK3MpAsD6dSwNc5qrbpiI42qC2ApFRr31JMWJLk1xXyZ70c+VE2JF4x3yCGftnNF4DtRsYPHDr3KXkIXLm4NFVTNyld+jY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614606780; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lxKYocY3dRF/V489uoPf+ippWT4zDZvTE/iE/p81QxM=; b=nPYw1d2HdXswnS/109qc8Pi1Lli1nNCVClYdEUGcXQgxwYExU3A26Q4P6uU2eQpIIaPOfDn8P2FtCQKVbueP/jYdoSUiURiA89WDuBBpSL+LPjqD7X3JZHKn5aweNNYlJeH7fXwDRgfZ1PREtFOFsswOkijVn7JgqATAouaTLm8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614606780447127.65111885570411; Mon, 1 Mar 2021 05:53:00 -0800 (PST) Received: from localhost ([::1]:40020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGiyp-00085e-0V for importer@patchew.org; Mon, 01 Mar 2021 08:52:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixD-0006Pd-9o for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixB-0008DH-OQ for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:19 -0500 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-528-ix8e_eFfOEShsRlYRF6mhQ-1; Mon, 01 Mar 2021 08:51:14 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30E878030CC for ; Mon, 1 Mar 2021 13:51:13 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C14C5D71F; Mon, 1 Mar 2021 13:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606676; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lxKYocY3dRF/V489uoPf+ippWT4zDZvTE/iE/p81QxM=; b=AFfDfnHbVpSpOLEPmK0QsOk3tOzWw7Hi82W44RuJWuAjKnmaO8umJ0pqTMicBESnnhejHU gz8VKif8VpW7P6DqHpP6jUiryiJyRKerxZYfycwaFb6AWy5LXdWHFj5Z2FniPI8keD0sdv iVsh+KyQXovWXXShdu9SQtZSnjpMUzw= X-MC-Unique: ix8e_eFfOEShsRlYRF6mhQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 03/17] i386: always fill Hyper-V CPUID feature leaves from X86CPU data Date: Mon, 1 Mar 2021 14:50:49 +0100 Message-Id: <20210301135103.306003-4-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We have all the required data in X86CPU already and as we are about to split hyperv_handle_properties() into hyperv_expand_features()/ hyperv_fill_cpuids() we can remove the blind copy. The functional change is that QEMU won't pass CPUID leaves it doesn't currently know about to the guest but arguably this is a good change. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 3c1202333d9d..1b1934362a89 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1207,9 +1207,6 @@ static int hyperv_handle_properties(CPUState *cs, } =20 if (cpu->hyperv_passthrough) { - memcpy(cpuid_ent, &cpuid->entries[0], - cpuid->nent * sizeof(cpuid->entries[0])); - c =3D cpuid_find_entry(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, 0= ); if (c) { cpu->hyperv_vendor_id[0] =3D c->ebx; @@ -1309,12 +1306,6 @@ static int hyperv_handle_properties(CPUState *cs, goto free; } =20 - if (cpu->hyperv_passthrough) { - /* We already copied all feature words from KVM as is */ - r =3D cpuid->nent; - goto free; - } - c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; c->eax =3D hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ? --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614606780; cv=none; d=zohomail.com; s=zohoarc; b=W/xjLXRcfeWTS4y6Yufu1x7ysgjuWtpuG6aHSRbNqX+iBAXO3g+0lBo4p5ktFkrqTDzEgU9L4gDd1+g2riwydg9squtM97R28E7/Uidmxm+dPBBC5qysVCHpI1suLxUW1B4zeYTWyU+QeT0fFaGqXce6OqZ7alKsJZRJl+vfmJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614606780; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TpgBmxViYUNjZmI1mbT08a0Y//cd3hNvTbOOCcGvvPk=; b=dKoCkDCe/uPqwlPTY6zB8jTgtOzr1jb2aIczpICUY5tbUgNfLp/81mIJzGQraLkQCKK/wtB6WFuaLr62ZMVbcPt2WKv502MR4kkUTusmsiGaGojMV1dcO7wvrvPgAEQbYGnN3+UMoA2IxrWxC05XvUe+7JCISMuJU0emiFAJtmE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614606780977433.6058648780429; Mon, 1 Mar 2021 05:53:00 -0800 (PST) Received: from localhost ([::1]:40110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGiyp-00087y-Rz for importer@patchew.org; Mon, 01 Mar 2021 08:52:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixE-0006QY-2M for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59339) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixC-0008DV-9I for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:19 -0500 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-399-PfRx-OCwNkGc3zDqnlQcRw-1; Mon, 01 Mar 2021 08:51:16 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35DE6801965 for ; Mon, 1 Mar 2021 13:51:15 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F1815D760; Mon, 1 Mar 2021 13:51:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606677; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TpgBmxViYUNjZmI1mbT08a0Y//cd3hNvTbOOCcGvvPk=; b=czkgQ9oWXPMEo+8cYbkE/rSkuFQ1CZ8LvrjNZRzoz9HOVarZv7FsQnkGuTZpzUCxJxzbYE 85FHrOayViUFlz1h+t9ILz7EZhxicMMVgQ/OH4bVSk74a5aTS5ri3XtbvTgT01It8mjfOM hMqwMScwcDI6lJSD+iFa6y1IsRyLSig= X-MC-Unique: PfRx-OCwNkGc3zDqnlQcRw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 04/17] i386: stop using env->features[] for filling Hyper-V CPUIDs Date: Mon, 1 Mar 2021 14:50:50 +0100 Message-Id: <20210301135103.306003-5-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As a preparatory patch to dropping Hyper-V CPUID leaves from feature_word_info[] stop using env->features[] as a temporary storage of Hyper-V CPUIDs, just build Hyper-V CPUID leaves directly from kvm_hyperv_properties[] data. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.h | 1 + target/i386/kvm/kvm.c | 80 +++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 8be39cfb62e5..118454d24b8f 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1683,6 +1683,7 @@ struct X86CPU { uint32_t hyperv_interface_id[4]; uint32_t hyperv_version_id[4]; uint32_t hyperv_limits[3]; + uint32_t hyperv_nested[4]; =20 bool check_cpuid; bool enforce_cpuid; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 1b1934362a89..dc372ed213ff 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1111,7 +1111,6 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, int feature) { X86CPU *cpu =3D X86_CPU(cs); - CPUX86State *env =3D &cpu->env; uint32_t r, fw, bits; uint64_t deps; int i, dep_feat; @@ -1151,8 +1150,6 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, return 0; } } - - env->features[fw] |=3D bits; } =20 if (cpu->hyperv_passthrough) { @@ -1162,6 +1159,29 @@ static int hv_cpuid_check_and_set(CPUState *cs, stru= ct kvm_cpuid2 *cpuid, return 0; } =20 +static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t fw) +{ + X86CPU *cpu =3D X86_CPU(cs); + uint32_t r =3D 0; + int i, j; + + for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties); i++) { + if (!hyperv_feat_enabled(cpu, i)) { + continue; + } + + for (j =3D 0; j < ARRAY_SIZE(kvm_hyperv_properties[i].flags); j++)= { + if (kvm_hyperv_properties[i].flags[j].fw !=3D fw) { + continue; + } + + r |=3D kvm_hyperv_properties[i].flags[j].bits; + } + } + + return r; +} + /* * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_e= nt in * case of success, errno < 0 in case of failure and 0 when no Hyper-V @@ -1171,9 +1191,8 @@ static int hyperv_handle_properties(CPUState *cs, struct kvm_cpuid_entry2 *cpuid_ent) { X86CPU *cpu =3D X86_CPU(cs); - CPUX86State *env =3D &cpu->env; struct kvm_cpuid2 *cpuid; - struct kvm_cpuid_entry2 *c; + struct kvm_cpuid_entry2 *c, *c2; uint32_t cpuid_i =3D 0; int r; =20 @@ -1194,9 +1213,7 @@ static int hyperv_handle_properties(CPUState *cs, } =20 if (!r) { - env->features[FEAT_HV_RECOMM_EAX] |=3D - HV_ENLIGHTENED_VMCS_RECOMMENDED; - env->features[FEAT_HV_NESTED_EAX] =3D evmcs_version; + cpu->hyperv_nested[0] =3D evmcs_version; } } =20 @@ -1235,13 +1252,6 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_version_id[3] =3D c->edx; } =20 - c =3D cpuid_find_entry(cpuid, HV_CPUID_FEATURES, 0); - if (c) { - env->features[FEAT_HYPERV_EAX] =3D c->eax; - env->features[FEAT_HYPERV_EBX] =3D c->ebx; - env->features[FEAT_HYPERV_EDX] =3D c->edx; - } - c =3D cpuid_find_entry(cpuid, HV_CPUID_IMPLEMENT_LIMITS, 0); if (c) { cpu->hv_max_vps =3D c->eax; @@ -1252,23 +1262,8 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); if (c) { - env->features[FEAT_HV_RECOMM_EAX] =3D c->eax; cpu->hyperv_spinlock_attempts =3D c->ebx; } - c =3D cpuid_find_entry(cpuid, HV_CPUID_NESTED_FEATURES, 0); - if (c) { - env->features[FEAT_HV_NESTED_EAX] =3D c->eax; - } - } - - if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { - env->features[FEAT_HV_RECOMM_EAX] |=3D HV_NO_NONARCH_CORESHARING; - } else if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_AUTO) { - c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); - if (c) { - env->features[FEAT_HV_RECOMM_EAX] |=3D - c->eax & HV_NO_NONARCH_CORESHARING; - } } =20 /* Features */ @@ -1298,9 +1293,6 @@ static int hyperv_handle_properties(CPUState *cs, r |=3D 1; } =20 - /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ - env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; - if (r) { r =3D -ENOSYS; goto free; @@ -1330,15 +1322,27 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_FEATURES; - c->eax =3D env->features[FEAT_HYPERV_EAX]; - c->ebx =3D env->features[FEAT_HYPERV_EBX]; - c->edx =3D env->features[FEAT_HYPERV_EDX]; + c->eax =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EAX); + c->ebx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EBX); + c->edx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EDX); + + /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ + c->edx |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE; =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_ENLIGHTMENT_INFO; - c->eax =3D env->features[FEAT_HV_RECOMM_EAX]; + c->eax =3D hv_build_cpuid_leaf(cs, FEAT_HV_RECOMM_EAX); c->ebx =3D cpu->hyperv_spinlock_attempts; =20 + if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { + c->eax |=3D HV_NO_NONARCH_CORESHARING; + } else if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_AUTO) { + c2 =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); + if (c2) { + c->eax |=3D c2->eax & HV_NO_NONARCH_CORESHARING; + } + } + c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_IMPLEMENT_LIMITS; c->eax =3D cpu->hv_max_vps; @@ -1358,7 +1362,7 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_NESTED_FEATURES; - c->eax =3D env->features[FEAT_HV_NESTED_EAX]; + c->eax =3D cpu->hyperv_nested[0]; } r =3D cpuid_i; =20 --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614606785; cv=none; d=zohomail.com; s=zohoarc; b=PWph/nhCgkE0ASkSyGTL2m4kCcnBpVEVHA8b8TRmoX32lkq4wquqUcQnNHtbItKaYp75o4IXmgUnU1B6Al6uaI3BT0apo2s7EGV23Sh9pNkBy5lZd/Ikl0CTD2BwpRe0lI8gSQRoyZacHvP5QQw2mff5YoyKv3DnwjqWxIill8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614606785; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SuDcUOoMtT8YSMMJhfHeJ+yRkl8rCLFl2pmTlogZdz0=; b=FL51dzbbUdTps3PItnvMuwizQf4h7dilqsqF3UlxObgPS8B+8xlZ/ZClwT9RGzN3v2rjbN3lVdBow/k2ijw3qfQDZSI0sezp7PtkJG3CCmZGFfsLeUKMWDrwGBlDLjzsePPyGlydg2rhyEuhsOMkOCsMdL9HC5b0QVU3pRjlt18= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16146067850791023.2835139097454; Mon, 1 Mar 2021 05:53:05 -0800 (PST) Received: from localhost ([::1]:40348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGiyt-0008DX-Fl for importer@patchew.org; Mon, 01 Mar 2021 08:53:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixG-0006UM-5I for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixE-0008ET-Iz for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:21 -0500 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-500-OkQ5ufiFMWCYXBV8fYG3ng-1; Mon, 01 Mar 2021 08:51:18 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5AF3F107ACF2 for ; Mon, 1 Mar 2021 13:51:17 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACA575D71F; Mon, 1 Mar 2021 13:51:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606679; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SuDcUOoMtT8YSMMJhfHeJ+yRkl8rCLFl2pmTlogZdz0=; b=QJgpp2LMqLNdKlYMI+BEooK419+LbZFdKaGEKyyqTt3MdmYEkzPs3XTHEag+LnCK/Oklam hLvxsOaSOxmBwjKvGpLMhElUxfryjTgpy5fWDUh1E1EVaBR42UkVSFuMcwdJBCMcDt15Px 5cax2SHgode483SPZWZNhrGx8mAZyJI= X-MC-Unique: OkQ5ufiFMWCYXBV8fYG3ng-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 05/17] i386: introduce hyperv_feature_supported() Date: Mon, 1 Mar 2021 14:50:51 +0100 Message-Id: <20210301135103.306003-6-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Clean up hv_cpuid_check_and_set() by separating hyperv_feature_supported() off it. No functional change intended. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 49 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index dc372ed213ff..bbc76a7475cd 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1107,13 +1107,33 @@ static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid= , int fw, uint32_t *r) return 0; } =20 +static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature) +{ + uint32_t r, fw, bits; + int i; + + for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i+= +) { + fw =3D kvm_hyperv_properties[feature].flags[i].fw; + bits =3D kvm_hyperv_properties[feature].flags[i].bits; + + if (!fw) { + continue; + } + + if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) !=3D bits) { + return false; + } + } + + return true; +} + static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, int feature) { X86CPU *cpu =3D X86_CPU(cs); - uint32_t r, fw, bits; uint64_t deps; - int i, dep_feat; + int dep_feat; =20 if (!hyperv_feat_enabled(cpu, feature) && !cpu->hyperv_passthrough) { return 0; @@ -1132,23 +1152,14 @@ static int hv_cpuid_check_and_set(CPUState *cs, str= uct kvm_cpuid2 *cpuid, deps &=3D ~(1ull << dep_feat); } =20 - for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i+= +) { - fw =3D kvm_hyperv_properties[feature].flags[i].fw; - bits =3D kvm_hyperv_properties[feature].flags[i].bits; - - if (!fw) { - continue; - } - - if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) !=3D bits) { - if (hyperv_feat_enabled(cpu, feature)) { - fprintf(stderr, - "Hyper-V %s is not supported by kernel\n", - kvm_hyperv_properties[feature].desc); - return 1; - } else { - return 0; - } + if (!hyperv_feature_supported(cpuid, feature)) { + if (hyperv_feat_enabled(cpu, feature)) { + fprintf(stderr, + "Hyper-V %s is not supported by kernel\n", + kvm_hyperv_properties[feature].desc); + return 1; + } else { + return 0; } } =20 --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614606923; cv=none; d=zohomail.com; s=zohoarc; b=O8JQucoaifFp4rprNlj43T0dPgJ45P9+2LgK+LrHI4WBXEs7JNfzzqTW2a8bj0WKwH9NC4hgvE9AtJ03FICPsDdxK0rG9ES6Kd3hejYPte9zGF2y5nmFLssIe7KYRjyT/ZofS0qMeyu6fxF50M9jc5YhyFylPVTF7L11bhdIYHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614606923; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=K6srJnxqT9Fe/QG/By9bjDq+TK+qJVCrY9KPcLjj9eU=; b=A0V5x9F2C744Ztsvui3tTC4nJVTP1gNtqC5A+qu8uDWdh0YwiFOU2fzqnhK28sXczcxxl8CGaaeV793BPdSHN59OJyq2xaNTAbYmp0h6Fd6wYgBpgsAMqM4q6CzsutPkfAVS5wYg0c2i88J+lnWrQ8uVZenKmMIqjtzO+08vA0I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614606923754771.9430252667839; Mon, 1 Mar 2021 05:55:23 -0800 (PST) Received: from localhost ([::1]:48636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj18-0003C5-Ls for importer@patchew.org; Mon, 01 Mar 2021 08:55:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixJ-0006ZT-Au for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixH-0008Gv-K6 for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:25 -0500 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-295-oLMmz9-NP5q82iRIZIiy4A-1; Mon, 01 Mar 2021 08:51:21 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74EA6C7401 for ; Mon, 1 Mar 2021 13:51:19 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id B856A5D71F; Mon, 1 Mar 2021 13:51:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606683; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K6srJnxqT9Fe/QG/By9bjDq+TK+qJVCrY9KPcLjj9eU=; b=eGh9AOqQXcCMZdMdIDzip5yPldiNgBQY1PwbqmSAb0JwGqo2psXNZ+M34sLMEuNGHtaYq7 RR3cGE+2cQSu5TGUrrlQxjp/bTRCtFhyfRtUowrQCQ+afLmN8i+cSDr/SrK3izR+tXg/k5 OGrnj49l6ZFRCrdeHD9Tstf/LKtJtLU= X-MC-Unique: oLMmz9-NP5q82iRIZIiy4A-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 06/17] i386: introduce hv_cpuid_get_host() Date: Mon, 1 Mar 2021 14:50:52 +0100 Message-Id: <20210301135103.306003-7-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As a preparation to implementing hv_cpuid_cache intro introduce hv_cpuid_get_host(). No functional change intended. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 102 +++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index bbc76a7475cd..9835c3809723 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1107,6 +1107,19 @@ static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid,= int fw, uint32_t *r) return 0; } =20 +static uint32_t hv_cpuid_get_host(struct kvm_cpuid2 *cpuid, uint32_t func, + int reg) +{ + struct kvm_cpuid_entry2 *entry; + + entry =3D cpuid_find_entry(cpuid, func, 0); + if (!entry) { + return 0; + } + + return cpuid_entry_get_reg(entry, reg); +} + static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature) { uint32_t r, fw, bits; @@ -1203,7 +1216,7 @@ static int hyperv_handle_properties(CPUState *cs, { X86CPU *cpu =3D X86_CPU(cs); struct kvm_cpuid2 *cpuid; - struct kvm_cpuid_entry2 *c, *c2; + struct kvm_cpuid_entry2 *c; uint32_t cpuid_i =3D 0; int r; =20 @@ -1235,46 +1248,47 @@ static int hyperv_handle_properties(CPUState *cs, } =20 if (cpu->hyperv_passthrough) { - c =3D cpuid_find_entry(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, 0= ); - if (c) { - cpu->hyperv_vendor_id[0] =3D c->ebx; - cpu->hyperv_vendor_id[1] =3D c->ecx; - cpu->hyperv_vendor_id[2] =3D c->edx; - cpu->hyperv_vendor =3D g_realloc(cpu->hyperv_vendor, - sizeof(cpu->hyperv_vendor_id) += 1); - memcpy(cpu->hyperv_vendor, cpu->hyperv_vendor_id, - sizeof(cpu->hyperv_vendor_id)); - cpu->hyperv_vendor[sizeof(cpu->hyperv_vendor_id)] =3D 0; - } - - c =3D cpuid_find_entry(cpuid, HV_CPUID_INTERFACE, 0); - if (c) { - cpu->hyperv_interface_id[0] =3D c->eax; - cpu->hyperv_interface_id[1] =3D c->ebx; - cpu->hyperv_interface_id[2] =3D c->ecx; - cpu->hyperv_interface_id[3] =3D c->edx; - } - - c =3D cpuid_find_entry(cpuid, HV_CPUID_VERSION, 0); - if (c) { - cpu->hyperv_version_id[0] =3D c->eax; - cpu->hyperv_version_id[1] =3D c->ebx; - cpu->hyperv_version_id[2] =3D c->ecx; - cpu->hyperv_version_id[3] =3D c->edx; - } - - c =3D cpuid_find_entry(cpuid, HV_CPUID_IMPLEMENT_LIMITS, 0); - if (c) { - cpu->hv_max_vps =3D c->eax; - cpu->hyperv_limits[0] =3D c->ebx; - cpu->hyperv_limits[1] =3D c->ecx; - cpu->hyperv_limits[2] =3D c->edx; - } - - c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); - if (c) { - cpu->hyperv_spinlock_attempts =3D c->ebx; - } + cpu->hyperv_vendor_id[0] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= EBX); + cpu->hyperv_vendor_id[1] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= ECX); + cpu->hyperv_vendor_id[2] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= EDX); + cpu->hyperv_vendor =3D g_realloc(cpu->hyperv_vendor, + sizeof(cpu->hyperv_vendor_id) + 1); + memcpy(cpu->hyperv_vendor, cpu->hyperv_vendor_id, + sizeof(cpu->hyperv_vendor_id)); + cpu->hyperv_vendor[sizeof(cpu->hyperv_vendor_id)] =3D 0; + + cpu->hyperv_interface_id[0] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EAX); + cpu->hyperv_interface_id[1] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EBX); + cpu->hyperv_interface_id[2] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_ECX); + cpu->hyperv_interface_id[3] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EDX); + + cpu->hyperv_version_id[0] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EAX); + cpu->hyperv_version_id[1] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EBX); + cpu->hyperv_version_id[2] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_ECX); + cpu->hyperv_version_id[3] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EDX); + + cpu->hv_max_vps =3D hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LI= MITS, + R_EAX); + cpu->hyperv_limits[0] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_EBX); + cpu->hyperv_limits[1] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_ECX); + cpu->hyperv_limits[2] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_EDX); + + cpu->hyperv_spinlock_attempts =3D + hv_cpuid_get_host(cpuid, HV_CPUID_ENLIGHTMENT_INFO, R_EBX); } =20 /* Features */ @@ -1348,10 +1362,8 @@ static int hyperv_handle_properties(CPUState *cs, if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { c->eax |=3D HV_NO_NONARCH_CORESHARING; } else if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_AUTO) { - c2 =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); - if (c2) { - c->eax |=3D c2->eax & HV_NO_NONARCH_CORESHARING; - } + c->eax |=3D hv_cpuid_get_host(cpuid, HV_CPUID_ENLIGHTMENT_INFO, R_= EAX) & + HV_NO_NONARCH_CORESHARING; } =20 c =3D &cpuid_ent[cpuid_i++]; --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614606929; cv=none; d=zohomail.com; s=zohoarc; b=TnpINg94UD53kKA+SnXO865IbDAFHcwYasV8NFgk8uKleNWitkP23QlTP/vhpZWJq1/H0aeGZdYT28c4L67K8Bxn98DzTd2KRU5Rg3pe3QYIhELujzU5vvDrwpxJjYOOjlQyRbnQ+1fSHbCXvCXAvm/zDe4opKgdfA3uaXJu0MY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614606929; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6Ed2g0jcVxw3CtKUT07jociisBzIQple32UX4drBzDg=; b=ag+rHbINvt+M5LbqkzUASq/1iGFXspZip/wiT3uDDv+10UTIavJkIVu52IwVxVR2jF0onfeJT1U/ABMugzM8NoUQ9ZCBbgJJSVA1yc1tqw784q+dc2Yh/C2pbyXcuny232pV4tFhjxocdbUIrfEwzDC34boYdJ0PQixoV9tqrLk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614606929371525.3643161667089; Mon, 1 Mar 2021 05:55:29 -0800 (PST) Received: from localhost ([::1]:49068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj1D-0003MZ-37 for importer@patchew.org; Mon, 01 Mar 2021 08:55:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixN-0006ax-Eh for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24271) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixI-0008IE-Q3 for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:29 -0500 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-55-2hhVdsO0NbexLfeTwTQblg-1; Mon, 01 Mar 2021 08:51:22 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 771C28030D0 for ; Mon, 1 Mar 2021 13:51:21 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD49D5D71F; Mon, 1 Mar 2021 13:51:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606684; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6Ed2g0jcVxw3CtKUT07jociisBzIQple32UX4drBzDg=; b=JfkACikkXLxdcb3H+pLwMLirk/M9TYQ+amjzvDK/Hwz/fHUOrpKTSd24ndF8L/KWGkNbY4 Pc4mzc3BA6TUUOc4c5wJ5x4MlQLblbcYuhunGOUmlKoYIg6kNKRLTX1lNa/d/giuS2QBqz 1xzbpRptLYVQHvNCa2jyymKX2dLGbLU= X-MC-Unique: 2hhVdsO0NbexLfeTwTQblg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 07/17] i386: drop FEAT_HYPERV feature leaves Date: Mon, 1 Mar 2021 14:50:53 +0100 Message-Id: <20210301135103.306003-8-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Hyper-V feature leaves are weird. We have some of them in feature_word_info[] array but we don't use feature_word_info magic to enable them. Neither do we use feature_dependencies[] mechanism to validate the configuration as it doesn't allign well with Hyper-V's many-to-many dependency chains. Some of the feature leaves hold not only feature bits, but also values. E.g. FEAT_HV_NESTED_EAX contains both features and the supported Enlightened VMCS range. Hyper-V features are already represented in 'struct X86CPU' with uint64_t hyperv_features so duplicating them in env->features adds little (or zero) benefits. THe other half of Hyper-V emulation features is also stored with values in hyperv_vendor_id[], hyperv_limits[],... so env->features[] is already incomplete. Remove Hyper-V feature leaves from env->features[] completely. kvm_hyperv_properties[] is converted to using raw CPUID func/reg pairs for features, this allows us to get rid of hv_cpuid_get_fw() conversion. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 90 +---------------------------------- target/i386/cpu.h | 5 -- target/i386/kvm/kvm.c | 108 ++++++++++++++---------------------------- 3 files changed, 37 insertions(+), 166 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ee094877d7a1..e943d42569db 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -832,94 +832,6 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS= ] =3D { */ .no_autoenable_flags =3D ~0U, }, - /* - * .feat_names are commented out for Hyper-V enlightenments because we - * don't want to have two different ways for enabling them on QEMU com= mand - * line. Some features (e.g. "hyperv_time", "hyperv_vapic", ...) requi= re - * enabling several feature bits simultaneously, exposing these bits - * individually may just confuse guests. - */ - [FEAT_HYPERV_EAX] =3D { - .type =3D CPUID_FEATURE_WORD, - .feat_names =3D { - NULL /* hv_msr_vp_runtime_access */, NULL /* hv_msr_time_refco= unt_access */, - NULL /* hv_msr_synic_access */, NULL /* hv_msr_stimer_access *= /, - NULL /* hv_msr_apic_access */, NULL /* hv_msr_hypercall_access= */, - NULL /* hv_vpindex_access */, NULL /* hv_msr_reset_access */, - NULL /* hv_msr_stats_access */, NULL /* hv_reftsc_access */, - NULL /* hv_msr_idle_access */, NULL /* hv_msr_frequency_access= */, - NULL /* hv_msr_debug_access */, NULL /* hv_msr_reenlightenment= _access */, - NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - }, - .cpuid =3D { .eax =3D 0x40000003, .reg =3D R_EAX, }, - }, - [FEAT_HYPERV_EBX] =3D { - .type =3D CPUID_FEATURE_WORD, - .feat_names =3D { - NULL /* hv_create_partitions */, NULL /* hv_access_partition_i= d */, - NULL /* hv_access_memory_pool */, NULL /* hv_adjust_message_bu= ffers */, - NULL /* hv_post_messages */, NULL /* hv_signal_events */, - NULL /* hv_create_port */, NULL /* hv_connect_port */, - NULL /* hv_access_stats */, NULL, NULL, NULL /* hv_debugging *= /, - NULL /* hv_cpu_power_management */, NULL /* hv_configure_profi= ler */, - NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - }, - .cpuid =3D { .eax =3D 0x40000003, .reg =3D R_EBX, }, - }, - [FEAT_HYPERV_EDX] =3D { - .type =3D CPUID_FEATURE_WORD, - .feat_names =3D { - NULL /* hv_mwait */, NULL /* hv_guest_debugging */, - NULL /* hv_perf_monitor */, NULL /* hv_cpu_dynamic_part */, - NULL /* hv_hypercall_params_xmm */, NULL /* hv_guest_idle_stat= e */, - NULL, NULL, - NULL, NULL, NULL /* hv_guest_crash_msr */, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - }, - .cpuid =3D { .eax =3D 0x40000003, .reg =3D R_EDX, }, - }, - [FEAT_HV_RECOMM_EAX] =3D { - .type =3D CPUID_FEATURE_WORD, - .feat_names =3D { - NULL /* hv_recommend_pv_as_switch */, - NULL /* hv_recommend_pv_tlbflush_local */, - NULL /* hv_recommend_pv_tlbflush_remote */, - NULL /* hv_recommend_msr_apic_access */, - NULL /* hv_recommend_msr_reset */, - NULL /* hv_recommend_relaxed_timing */, - NULL /* hv_recommend_dma_remapping */, - NULL /* hv_recommend_int_remapping */, - NULL /* hv_recommend_x2apic_msrs */, - NULL /* hv_recommend_autoeoi_deprecation */, - NULL /* hv_recommend_pv_ipi */, - NULL /* hv_recommend_ex_hypercalls */, - NULL /* hv_hypervisor_is_nested */, - NULL /* hv_recommend_int_mbec */, - NULL /* hv_recommend_evmcs */, - NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - }, - .cpuid =3D { .eax =3D 0x40000004, .reg =3D R_EAX, }, - }, - [FEAT_HV_NESTED_EAX] =3D { - .type =3D CPUID_FEATURE_WORD, - .cpuid =3D { .eax =3D 0x4000000A, .reg =3D R_EAX, }, - }, [FEAT_SVM] =3D { .type =3D CPUID_FEATURE_WORD, .feat_names =3D { @@ -7057,7 +6969,7 @@ static GuestPanicInformation *x86_cpu_get_crash_info(= CPUState *cs) CPUX86State *env =3D &cpu->env; GuestPanicInformation *panic_info =3D NULL; =20 - if (env->features[FEAT_HYPERV_EDX] & HV_GUEST_CRASH_MSR_AVAILABLE) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_CRASH)) { panic_info =3D g_malloc0(sizeof(GuestPanicInformation)); =20 panic_info->type =3D GUEST_PANIC_INFORMATION_TYPE_HYPER_V; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 118454d24b8f..265e552746e7 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -519,11 +519,6 @@ typedef enum FeatureWord { FEAT_C000_0001_EDX, /* CPUID[C000_0001].EDX */ FEAT_KVM, /* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */ FEAT_KVM_HINTS, /* CPUID[4000_0001].EDX */ - FEAT_HYPERV_EAX, /* CPUID[4000_0003].EAX */ - FEAT_HYPERV_EBX, /* CPUID[4000_0003].EBX */ - FEAT_HYPERV_EDX, /* CPUID[4000_0003].EDX */ - FEAT_HV_RECOMM_EAX, /* CPUID[4000_0004].EAX */ - FEAT_HV_NESTED_EAX, /* CPUID[4000_000A].EAX */ FEAT_SVM, /* CPUID[8000_000A].EDX */ FEAT_XSAVE, /* CPUID[EAX=3D0xd,ECX=3D1].EAX */ FEAT_6_EAX, /* CPUID[6].EAX */ diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 9835c3809723..a65f2ccc1052 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -800,7 +800,8 @@ static bool tsc_is_stable_and_known(CPUX86State *env) static struct { const char *desc; struct { - uint32_t fw; + uint32_t func; + int reg; uint32_t bits; } flags[2]; uint64_t dependencies; @@ -808,25 +809,25 @@ static struct { [HYPERV_FEAT_RELAXED] =3D { .desc =3D "relaxed timing (hv-relaxed)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_HYPERCALL_AVAILABLE}, - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_RELAXED_TIMING_RECOMMENDED} } }, [HYPERV_FEAT_VAPIC] =3D { .desc =3D "virtual APIC (hv-vapic)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_HYPERCALL_AVAILABLE | HV_APIC_ACCESS_AVAILABLE}, - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_APIC_ACCESS_RECOMMENDED} } }, [HYPERV_FEAT_TIME] =3D { .desc =3D "clocksources (hv-time)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_HYPERCALL_AVAILABLE | HV_TIME_REF_COUNT_AVAILABL= E | HV_REFERENCE_TSC_AVAILABLE} } @@ -834,42 +835,42 @@ static struct { [HYPERV_FEAT_CRASH] =3D { .desc =3D "crash MSRs (hv-crash)", .flags =3D { - {.fw =3D FEAT_HYPERV_EDX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EDX, .bits =3D HV_GUEST_CRASH_MSR_AVAILABLE} } }, [HYPERV_FEAT_RESET] =3D { .desc =3D "reset MSR (hv-reset)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_RESET_AVAILABLE} } }, [HYPERV_FEAT_VPINDEX] =3D { .desc =3D "VP_INDEX MSR (hv-vpindex)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_VP_INDEX_AVAILABLE} } }, [HYPERV_FEAT_RUNTIME] =3D { .desc =3D "VP_RUNTIME MSR (hv-runtime)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_VP_RUNTIME_AVAILABLE} } }, [HYPERV_FEAT_SYNIC] =3D { .desc =3D "synthetic interrupt controller (hv-synic)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_SYNIC_AVAILABLE} } }, [HYPERV_FEAT_STIMER] =3D { .desc =3D "synthetic timers (hv-stimer)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_SYNTIMERS_AVAILABLE} }, .dependencies =3D BIT(HYPERV_FEAT_SYNIC) | BIT(HYPERV_FEAT_TIME) @@ -877,23 +878,23 @@ static struct { [HYPERV_FEAT_FREQUENCIES] =3D { .desc =3D "frequency MSRs (hv-frequencies)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_ACCESS_FREQUENCY_MSRS}, - {.fw =3D FEAT_HYPERV_EDX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EDX, .bits =3D HV_FREQUENCY_MSRS_AVAILABLE} } }, [HYPERV_FEAT_REENLIGHTENMENT] =3D { .desc =3D "reenlightenment MSRs (hv-reenlightenment)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_ACCESS_REENLIGHTENMENTS_CONTROL} } }, [HYPERV_FEAT_TLBFLUSH] =3D { .desc =3D "paravirtualized TLB flush (hv-tlbflush)", .flags =3D { - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_REMOTE_TLB_FLUSH_RECOMMENDED | HV_EX_PROCESSOR_MASKS_RECOMMENDED} }, @@ -902,7 +903,7 @@ static struct { [HYPERV_FEAT_EVMCS] =3D { .desc =3D "enlightened VMCS (hv-evmcs)", .flags =3D { - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_ENLIGHTENED_VMCS_RECOMMENDED} }, .dependencies =3D BIT(HYPERV_FEAT_VAPIC) @@ -910,7 +911,7 @@ static struct { [HYPERV_FEAT_IPI] =3D { .desc =3D "paravirtualized IPI (hv-ipi)", .flags =3D { - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_CLUSTER_IPI_RECOMMENDED | HV_EX_PROCESSOR_MASKS_RECOMMENDED} }, @@ -919,7 +920,7 @@ static struct { [HYPERV_FEAT_STIMER_DIRECT] =3D { .desc =3D "direct mode synthetic timers (hv-stimer-direct)", .flags =3D { - {.fw =3D FEAT_HYPERV_EDX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EDX, .bits =3D HV_STIMER_DIRECT_MODE_AVAILABLE} }, .dependencies =3D BIT(HYPERV_FEAT_STIMER) @@ -1065,48 +1066,6 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid_leg= acy(CPUState *cs) return cpuid; } =20 -static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid, int fw, uint32_t *r) -{ - struct kvm_cpuid_entry2 *entry; - uint32_t func; - int reg; - - switch (fw) { - case FEAT_HYPERV_EAX: - reg =3D R_EAX; - func =3D HV_CPUID_FEATURES; - break; - case FEAT_HYPERV_EDX: - reg =3D R_EDX; - func =3D HV_CPUID_FEATURES; - break; - case FEAT_HV_RECOMM_EAX: - reg =3D R_EAX; - func =3D HV_CPUID_ENLIGHTMENT_INFO; - break; - default: - return -EINVAL; - } - - entry =3D cpuid_find_entry(cpuid, func, 0); - if (!entry) { - return -ENOENT; - } - - switch (reg) { - case R_EAX: - *r =3D entry->eax; - break; - case R_EDX: - *r =3D entry->edx; - break; - default: - return -EINVAL; - } - - return 0; -} - static uint32_t hv_cpuid_get_host(struct kvm_cpuid2 *cpuid, uint32_t func, int reg) { @@ -1122,18 +1081,20 @@ static uint32_t hv_cpuid_get_host(struct kvm_cpuid2= *cpuid, uint32_t func, =20 static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature) { - uint32_t r, fw, bits; - int i; + uint32_t func, bits; + int i, reg; =20 for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i+= +) { - fw =3D kvm_hyperv_properties[feature].flags[i].fw; + + func =3D kvm_hyperv_properties[feature].flags[i].func; + reg =3D kvm_hyperv_properties[feature].flags[i].reg; bits =3D kvm_hyperv_properties[feature].flags[i].bits; =20 - if (!fw) { + if (!func) { continue; } =20 - if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) !=3D bits) { + if ((hv_cpuid_get_host(cpuid, func, reg) & bits) !=3D bits) { return false; } } @@ -1183,7 +1144,7 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, return 0; } =20 -static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t fw) +static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t func, int reg) { X86CPU *cpu =3D X86_CPU(cs); uint32_t r =3D 0; @@ -1195,7 +1156,10 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, ui= nt32_t fw) } =20 for (j =3D 0; j < ARRAY_SIZE(kvm_hyperv_properties[i].flags); j++)= { - if (kvm_hyperv_properties[i].flags[j].fw !=3D fw) { + if (kvm_hyperv_properties[i].flags[j].func !=3D func) { + continue; + } + if (kvm_hyperv_properties[i].flags[j].reg !=3D reg) { continue; } =20 @@ -1347,16 +1311,16 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_FEATURES; - c->eax =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EAX); - c->ebx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EBX); - c->edx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EDX); + c->eax =3D hv_build_cpuid_leaf(cs, HV_CPUID_FEATURES, R_EAX); + c->ebx =3D hv_build_cpuid_leaf(cs, HV_CPUID_FEATURES, R_EBX); + c->edx =3D hv_build_cpuid_leaf(cs, HV_CPUID_FEATURES, R_EDX); =20 /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ c->edx |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE; =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_ENLIGHTMENT_INFO; - c->eax =3D hv_build_cpuid_leaf(cs, FEAT_HV_RECOMM_EAX); + c->eax =3D hv_build_cpuid_leaf(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EAX); c->ebx =3D cpu->hyperv_spinlock_attempts; =20 if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607175; cv=none; d=zohomail.com; s=zohoarc; b=G4y26OtGJRy74JKp2OlLtlG/CyPupdZ6tua/YTXoEq8pXws64/dCUgotTBn+XY8OruVcdDYrlKjvLhe8jSJqWIBK6LCGgQ1YHddNqNk3Iwmw4V6O9wLnPDawCqITaz8wa5GNFaUJZrszgqTugj4hg35AHwp1V5FpxEJp2yJtYk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607175; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WXgL9s7JiPq3aijbiNqeS9XbsWtwTTZ2ojCO9s+Cawg=; b=AFcRKva9fqRq4yaZqOtl4JNKu9kZbW69DYRjgGICRpCa23bLDt7YZRKTWmeOg0u4D2gxa+SR1X4/jcaFgdqTiDbaAX2elkOUqub6M/97vua+usM4LmH+mqlOafg1RQ7UKTiABpDxmIr053megUPOKmHI3ksq0fskKQ6eXgWcq3k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607175644190.52194942569906; Mon, 1 Mar 2021 05:59:35 -0800 (PST) Received: from localhost ([::1]:34156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj5C-0000XU-EP for importer@patchew.org; Mon, 01 Mar 2021 08:59:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixR-0006d5-K3 for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixL-0008KS-2N for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:33 -0500 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-187-uxNDqC8dNl-h9OLUojFnyw-1; Mon, 01 Mar 2021 08:51:24 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 940B5C742F for ; Mon, 1 Mar 2021 13:51:23 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFD1E62465; Mon, 1 Mar 2021 13:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606686; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WXgL9s7JiPq3aijbiNqeS9XbsWtwTTZ2ojCO9s+Cawg=; b=N+Z9axVFIzO+UqR3qOoHPH3omAIDtxKsRA9t/2+s6AE4oQ6/OdUT/OHXhGXuCDRBd+eIGV RAWGa+IwqVCoCYQIrYlZgvYmV8Kt6+S9FtAr+tOIaxixtNYqzUk7f304yvbm7+4yqGKnFb 29xDSngxd4OTJtjavTAhs+N62kR1KTc= X-MC-Unique: uxNDqC8dNl-h9OLUojFnyw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 08/17] i386: introduce hv_cpuid_cache Date: Mon, 1 Mar 2021 14:50:54 +0100 Message-Id: <20210301135103.306003-9-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Just like with cpuid_cache, it makes no sense to call KVM_GET_SUPPORTED_HV_CPUID more than once and instead of (ab)using env->features[] and/or trying to keep all the code in one place, it is better to introduce persistent hv_cpuid_cache and hv_cpuid_get_host() accessor to it. Note, hv_cpuid_get_fw() is converted to using hv_cpuid_get_host() just to be removed later with Hyper-V specific feature words. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 109 ++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index a65f2ccc1052..043d4c84d2d2 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -128,6 +128,7 @@ static int has_exception_payload; static bool has_msr_mcg_ext_ctl; =20 static struct kvm_cpuid2 *cpuid_cache; +static struct kvm_cpuid2 *hv_cpuid_cache; static struct kvm_msr_list *kvm_feature_msrs; =20 int kvm_has_pit_state2(void) @@ -1066,10 +1067,25 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid_le= gacy(CPUState *cs) return cpuid; } =20 -static uint32_t hv_cpuid_get_host(struct kvm_cpuid2 *cpuid, uint32_t func, - int reg) +static uint32_t hv_cpuid_get_host(CPUState *cs, uint32_t func, int reg) { struct kvm_cpuid_entry2 *entry; + struct kvm_cpuid2 *cpuid; + + if (hv_cpuid_cache) { + cpuid =3D hv_cpuid_cache; + } else { + if (kvm_check_extension(kvm_state, KVM_CAP_HYPERV_CPUID) > 0) { + cpuid =3D get_supported_hv_cpuid(cs); + } else { + cpuid =3D get_supported_hv_cpuid_legacy(cs); + } + hv_cpuid_cache =3D cpuid; + } + + if (!cpuid) { + return 0; + } =20 entry =3D cpuid_find_entry(cpuid, func, 0); if (!entry) { @@ -1079,7 +1095,7 @@ static uint32_t hv_cpuid_get_host(struct kvm_cpuid2 *= cpuid, uint32_t func, return cpuid_entry_get_reg(entry, reg); } =20 -static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature) +static bool hyperv_feature_supported(CPUState *cs, int feature) { uint32_t func, bits; int i, reg; @@ -1094,7 +1110,7 @@ static bool hyperv_feature_supported(struct kvm_cpuid= 2 *cpuid, int feature) continue; } =20 - if ((hv_cpuid_get_host(cpuid, func, reg) & bits) !=3D bits) { + if ((hv_cpuid_get_host(cs, func, reg) & bits) !=3D bits) { return false; } } @@ -1102,8 +1118,7 @@ static bool hyperv_feature_supported(struct kvm_cpuid= 2 *cpuid, int feature) return true; } =20 -static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, - int feature) +static int hv_cpuid_check_and_set(CPUState *cs, int feature) { X86CPU *cpu =3D X86_CPU(cs); uint64_t deps; @@ -1126,7 +1141,7 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, deps &=3D ~(1ull << dep_feat); } =20 - if (!hyperv_feature_supported(cpuid, feature)) { + if (!hyperv_feature_supported(cs, feature)) { if (hyperv_feat_enabled(cpu, feature)) { fprintf(stderr, "Hyper-V %s is not supported by kernel\n", @@ -1179,7 +1194,6 @@ static int hyperv_handle_properties(CPUState *cs, struct kvm_cpuid_entry2 *cpuid_ent) { X86CPU *cpu =3D X86_CPU(cs); - struct kvm_cpuid2 *cpuid; struct kvm_cpuid_entry2 *c; uint32_t cpuid_i =3D 0; int r; @@ -1205,19 +1219,13 @@ static int hyperv_handle_properties(CPUState *cs, } } =20 - if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_CPUID) > 0) { - cpuid =3D get_supported_hv_cpuid(cs); - } else { - cpuid =3D get_supported_hv_cpuid_legacy(cs); - } - if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= EBX); + hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EBX= ); cpu->hyperv_vendor_id[1] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= ECX); + hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_ECX= ); cpu->hyperv_vendor_id[2] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= EDX); + hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EDX= ); cpu->hyperv_vendor =3D g_realloc(cpu->hyperv_vendor, sizeof(cpu->hyperv_vendor_id) + 1); memcpy(cpu->hyperv_vendor, cpu->hyperv_vendor_id, @@ -1225,52 +1233,52 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_vendor[sizeof(cpu->hyperv_vendor_id)] =3D 0; =20 cpu->hyperv_interface_id[0] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EAX); + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EAX); cpu->hyperv_interface_id[1] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EBX); + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EBX); cpu->hyperv_interface_id[2] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_ECX); + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_ECX); cpu->hyperv_interface_id[3] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EDX); + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EDX); =20 cpu->hyperv_version_id[0] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EAX); + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EAX); cpu->hyperv_version_id[1] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EBX); + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EBX); cpu->hyperv_version_id[2] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_ECX); + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_ECX); cpu->hyperv_version_id[3] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EDX); + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EDX); =20 - cpu->hv_max_vps =3D hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LI= MITS, + cpu->hv_max_vps =3D hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMIT= S, R_EAX); cpu->hyperv_limits[0] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_EBX); + hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_EBX); cpu->hyperv_limits[1] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_ECX); + hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_ECX); cpu->hyperv_limits[2] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_EDX); + hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_EDX); =20 cpu->hyperv_spinlock_attempts =3D - hv_cpuid_get_host(cpuid, HV_CPUID_ENLIGHTMENT_INFO, R_EBX); + hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EBX); } =20 /* Features */ - r =3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_RELAXED); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_VAPIC); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_TIME); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_CRASH); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_RESET); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_VPINDEX); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_RUNTIME); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_SYNIC); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_STIMER); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_FREQUENCIES); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_REENLIGHTENMENT); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_TLBFLUSH); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_EVMCS); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_IPI); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_STIMER_DIRECT); + r =3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT); =20 /* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) && @@ -1283,8 +1291,7 @@ static int hyperv_handle_properties(CPUState *cs, } =20 if (r) { - r =3D -ENOSYS; - goto free; + return -ENOSYS; } =20 c =3D &cpuid_ent[cpuid_i++]; @@ -1326,7 +1333,7 @@ static int hyperv_handle_properties(CPUState *cs, if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { c->eax |=3D HV_NO_NONARCH_CORESHARING; } else if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_AUTO) { - c->eax |=3D hv_cpuid_get_host(cpuid, HV_CPUID_ENLIGHTMENT_INFO, R_= EAX) & + c->eax |=3D hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EAX= ) & HV_NO_NONARCH_CORESHARING; } =20 @@ -1351,12 +1358,8 @@ static int hyperv_handle_properties(CPUState *cs, c->function =3D HV_CPUID_NESTED_FEATURES; c->eax =3D cpu->hyperv_nested[0]; } - r =3D cpuid_i; =20 -free: - g_free(cpuid); - - return r; + return cpuid_i; } =20 static Error *hv_passthrough_mig_blocker; --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614606921; cv=none; d=zohomail.com; s=zohoarc; b=bEe01hciJ57gCoZwLoR4fIDQSSHbfq07u+EAnYAyeNbAU+1xjICy7Z8YAFjksjeghfGHxFTJ6Us3aIqnUsMvPk9/0urdw7Qw5THXI63EDvQ+/5z7EDWZ9yiwunMa0BkbqDZQgMTD4K+DAzNVcw9Dz6PLoQbHUyXUflmkPePvIbI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614606921; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EuDOUK3ZK+bXVyO3r9unm7HC+7f6UPPKS0/3jh68/tM=; b=KMIgEzebk8zF2idtgiEZP0wj55YnPNq8oBXYQbXlS++gFH9Awppo2Tx/ruGK5pUBNT01HJMNSWZvf4pPhfhSLGYlJNCJfIQ+M3KP+ZPcAHoFLl81Q8Svujk8vFuukxEZTK8oB2n5p/bU2Qty6vW+n6eo79+5Sg9ypW7U9niTx0g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161460692186040.52867811386648; Mon, 1 Mar 2021 05:55:21 -0800 (PST) Received: from localhost ([::1]:48486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj16-00038B-O7 for importer@patchew.org; Mon, 01 Mar 2021 08:55:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixP-0006bI-8h for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47058) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixN-0008Lh-6L for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:31 -0500 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-440-8_dBPyTfNn2LVwpKgHBZdQ-1; Mon, 01 Mar 2021 08:51:26 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D8A9218B9EF8 for ; Mon, 1 Mar 2021 13:51:25 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00A3562679; Mon, 1 Mar 2021 13:51:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606688; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EuDOUK3ZK+bXVyO3r9unm7HC+7f6UPPKS0/3jh68/tM=; b=FTjHGMBAAnSZCIwtNXDm+xSu0G2yIxFrlWbaZCt4MkIljBPfjN2U57Jh6fZpX5o7tUoCVx VwBTzp0BjCo7jaRfZ2SR9/SwZfpWdONA1hjB08FbMjQFYbrh0KmegT19oTJOyZPq1+9Jtg QVlKnb/3MGCcK/wfYwnax9O+v5nA8HE= X-MC-Unique: 8_dBPyTfNn2LVwpKgHBZdQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 09/17] i386: split hyperv_handle_properties() into hyperv_expand_features()/hyperv_fill_cpuids() Date: Mon, 1 Mar 2021 14:50:55 +0100 Message-Id: <20210301135103.306003-10-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The intention is to call hyperv_expand_features() early, before vCPUs are created and use the acquired data later when we set guest visible CPUID data. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 043d4c84d2d2..ab828df397e8 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1186,16 +1186,15 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, u= int32_t func, int reg) } =20 /* - * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_e= nt in - * case of success, errno < 0 in case of failure and 0 when no Hyper-V - * extentions are enabled. + * Expand Hyper-V CPU features. In partucular, check that all the requested + * features are supported by the host and the sanity of the configuration + * (that all the required dependencies are included). Also, this takes care + * of 'hv_passthrough' mode and fills the environment with all supported + * Hyper-V features. */ -static int hyperv_handle_properties(CPUState *cs, - struct kvm_cpuid_entry2 *cpuid_ent) +static int hyperv_expand_features(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); - struct kvm_cpuid_entry2 *c; - uint32_t cpuid_i =3D 0; int r; =20 if (!hyperv_enabled(cpu)) @@ -1294,6 +1293,19 @@ static int hyperv_handle_properties(CPUState *cs, return -ENOSYS; } =20 + return 0; +} + +/* + * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_e= nt. + */ +static int hyperv_fill_cpuids(CPUState *cs, + struct kvm_cpuid_entry2 *cpuid_ent) +{ + X86CPU *cpu =3D X86_CPU(cs); + struct kvm_cpuid_entry2 *c; + uint32_t cpuid_i =3D 0; + c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; c->eax =3D hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ? @@ -1501,11 +1513,13 @@ int kvm_arch_init_vcpu(CPUState *cs) env->apic_bus_freq =3D KVM_APIC_BUS_FREQUENCY; =20 /* Paravirtualization CPUIDs */ - r =3D hyperv_handle_properties(cs, cpuid_data.entries); + r =3D hyperv_expand_features(cs); if (r < 0) { return r; - } else if (r > 0) { - cpuid_i =3D r; + } + + if (hyperv_enabled(cpu)) { + cpuid_i =3D hyperv_fill_cpuids(cs, cpuid_data.entries); kvm_base =3D KVM_CPUID_SIGNATURE_NEXT; has_msr_hv_hypercall =3D true; } --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607049; cv=none; d=zohomail.com; s=zohoarc; b=NpTamJV0WiRyrRSXmhCMJpPtwkq6i41Tznxxam460cj/IUF9AB9CadXy2rYfMfgruvo0t3i8X7qXdWE4OhoB7cCUWN0stxAqhTmSgomJVuFvw/3tWDsOvfSx1k2GegYvV5XLq9jzL/kWPqKLd+Rlwm3GJWUK3BqKo+xCxl7m3EE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607049; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r4VKWXiNbH98zFMTi5hs8zoxZZzeIMOL0FFXkNrT+Ek=; b=YLCn9sQe9vSFiFp3c6dc4vrFLiHnhA824wUS1dnhQF69tUXFMGrvfc1F8trzpIbxJWjI0JTmzva7Sdq4jOGY71c1UcAYbgBDPx1cvzNpGInwuiEi3Myy9vFP/lHdoQnvh7h5Hjho6CJmySvgFBhifTXAVJXWrZANheW1dbQgtL4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607049484769.8306371067612; Mon, 1 Mar 2021 05:57:29 -0800 (PST) Received: from localhost ([::1]:56948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj3A-0006eP-Fm for importer@patchew.org; Mon, 01 Mar 2021 08:57:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixS-0006dC-UO for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44222) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixP-0008Nr-CM for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:34 -0500 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-189-0grDytwgPnSFViWBVo2oYA-1; Mon, 01 Mar 2021 08:51:28 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEDE4814733 for ; Mon, 1 Mar 2021 13:51:27 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4488D5B6A4; Mon, 1 Mar 2021 13:51:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606690; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r4VKWXiNbH98zFMTi5hs8zoxZZzeIMOL0FFXkNrT+Ek=; b=GtygsUzj+sR/LEZ1/nqg4f1S0Fi6WHXJohvIvAEuKnkjOEXqJn6ST4VKcH2xHdnO6YAQB1 H/7CNqRCC+ICeZBuH+jsdlACV4GDUo249+/yruWKi0YCSfyc3xBH7v3N2OXuD03dicOygc YKAPOaLdzrR2FkuOloBwvB/7wmRwUgo= X-MC-Unique: 0grDytwgPnSFViWBVo2oYA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 10/17] i386: move eVMCS enablement to hyperv_init_vcpu() Date: Mon, 1 Mar 2021 14:50:56 +0100 Message-Id: <20210301135103.306003-11-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" hyperv_expand_features() will be called before we create vCPU so evmcs enablement should go away. hyperv_init_vcpu() looks like the right place. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 60 ++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index ab828df397e8..34820c3ef29a 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -962,6 +962,7 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUSta= te *cs) { struct kvm_cpuid2 *cpuid; int max =3D 7; /* 0x40000000..0x40000005, 0x4000000A */ + int i; =20 /* * When the buffer is too small, KVM_GET_SUPPORTED_HV_CPUID fails with @@ -971,6 +972,22 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUSt= ate *cs) while ((cpuid =3D try_get_hv_cpuid(cs, max)) =3D=3D NULL) { max++; } + + /* + * KVM_GET_SUPPORTED_HV_CPUID does not set EVMCS CPUID bit before + * KVM_CAP_HYPERV_ENLIGHTENED_VMCS is enabled but we want to get the + * information early, just check for the capability and set the bit + * manually. + */ + if (kvm_check_extension(cs->kvm_state, + KVM_CAP_HYPERV_ENLIGHTENED_VMCS) > 0) { + for (i =3D 0; i < cpuid->nent; i++) { + if (cpuid->entries[i].function =3D=3D HV_CPUID_ENLIGHTMENT_INF= O) { + cpuid->entries[i].eax |=3D HV_ENLIGHTENED_VMCS_RECOMMENDED; + } + } + } + return cpuid; } =20 @@ -1200,24 +1217,6 @@ static int hyperv_expand_features(CPUState *cs) if (!hyperv_enabled(cpu)) return 0; =20 - if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) || - cpu->hyperv_passthrough) { - uint16_t evmcs_version; - - r =3D kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, - (uintptr_t)&evmcs_version); - - if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) && r) { - fprintf(stderr, "Hyper-V %s is not supported by kernel\n", - kvm_hyperv_properties[HYPERV_FEAT_EVMCS].desc); - return -ENOSYS; - } - - if (!r) { - cpu->hyperv_nested[0] =3D evmcs_version; - } - } - if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EBX= ); @@ -1455,6 +1454,21 @@ static int hyperv_init_vcpu(X86CPU *cpu) } } =20 + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { + uint16_t evmcs_version; + + ret =3D kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, + (uintptr_t)&evmcs_version); + + if (ret < 0) { + fprintf(stderr, "Hyper-V %s is not supported by kernel\n", + kvm_hyperv_properties[HYPERV_FEAT_EVMCS].desc); + return ret; + } + + cpu->hyperv_nested[0] =3D evmcs_version; + } + return 0; } =20 @@ -1519,6 +1533,11 @@ int kvm_arch_init_vcpu(CPUState *cs) } =20 if (hyperv_enabled(cpu)) { + r =3D hyperv_init_vcpu(cpu); + if (r) { + return r; + } + cpuid_i =3D hyperv_fill_cpuids(cs, cpuid_data.entries); kvm_base =3D KVM_CPUID_SIGNATURE_NEXT; has_msr_hv_hypercall =3D true; @@ -1868,11 +1887,6 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 kvm_init_msrs(cpu); =20 - r =3D hyperv_init_vcpu(cpu); - if (r) { - goto fail; - } - return 0; =20 fail: --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607393; cv=none; d=zohomail.com; s=zohoarc; b=bPrFetDZV0Tjq4CQR0sV0KmwnnofHF8GMJNlCm8VJl11vPwJwk0i+MVsB/c/6nJf76bJT9ICthLVbCp1r2CKu2+xUh0plHaDGSm1+xvcxxnQ3PMqWfZa4KQR+9SoZQm/62vHksthx0otPoAipp4tcvMQbmjWpPx+pvusVO2FolM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607393; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cQU1cTJ7XO8XceYhXedqJ0hEdKprF45Wab9FXCXL/T4=; b=I0odVsZNXiLDZoWVzdSKr3f4Z9d+o7oRQLQXjRRNpFrhCrPqYzok2WhtXmf2czQntpYe5IKvCus81GMJz7ErSq/KtCYKiWnNuN3HOpObUZN9AGwNs+dVBZEHZbpufOqetY+yZXbDj4+3GVr6Cx3BKhc2xJ9riA4omj1N7iNxUP8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607393410626.4369154359783; Mon, 1 Mar 2021 06:03:13 -0800 (PST) Received: from localhost ([::1]:39064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj8h-0002oA-SA for importer@patchew.org; Mon, 01 Mar 2021 09:03:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixU-0006eh-N2 for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixR-0008PA-7o for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:36 -0500 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-421-RhdaBjRZPA2BLuq_8vL2kA-1; Mon, 01 Mar 2021 08:51:30 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10F31CC626 for ; Mon, 1 Mar 2021 13:51:30 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DA1062677; Mon, 1 Mar 2021 13:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606692; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cQU1cTJ7XO8XceYhXedqJ0hEdKprF45Wab9FXCXL/T4=; b=QB7Z92l0tOZLDaw1BuXJ7gurySQOuC56ihvnDH8CqPCe9+NzpWNEWci+9wpl78KAJ36prK QroT2qAFw1Ur71OOnf0lbNgPD/jX/dtUCKKVAzQeHDa9v+qTftQk/nae/j7DK8pH65CX7C NguSkaBAv4dYyAJK9QTz6OUmH+nOm0A= X-MC-Unique: RhdaBjRZPA2BLuq_8vL2kA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 11/17] i386: switch hyperv_expand_features() to using error_setg() Date: Mon, 1 Mar 2021 14:50:57 +0100 Message-Id: <20210301135103.306003-12-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use standard error_setg() mechanism in hyperv_expand_features(). Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 101 +++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 34820c3ef29a..5cdceb6e34c4 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1135,7 +1135,7 @@ static bool hyperv_feature_supported(CPUState *cs, in= t feature) return true; } =20 -static int hv_cpuid_check_and_set(CPUState *cs, int feature) +static int hv_cpuid_check_and_set(CPUState *cs, int feature, Error **errp) { X86CPU *cpu =3D X86_CPU(cs); uint64_t deps; @@ -1149,20 +1149,18 @@ static int hv_cpuid_check_and_set(CPUState *cs, int= feature) while (deps) { dep_feat =3D ctz64(deps); if (!(hyperv_feat_enabled(cpu, dep_feat))) { - fprintf(stderr, - "Hyper-V %s requires Hyper-V %s\n", - kvm_hyperv_properties[feature].desc, - kvm_hyperv_properties[dep_feat].desc); - return 1; + error_setg(errp, "Hyper-V %s requires Hyper-V %s", + kvm_hyperv_properties[feature].desc, + kvm_hyperv_properties[dep_feat].desc); + return 1; } deps &=3D ~(1ull << dep_feat); } =20 if (!hyperv_feature_supported(cs, feature)) { if (hyperv_feat_enabled(cpu, feature)) { - fprintf(stderr, - "Hyper-V %s is not supported by kernel\n", - kvm_hyperv_properties[feature].desc); + error_setg(errp, "Hyper-V %s is not supported by kernel", + kvm_hyperv_properties[feature].desc); return 1; } else { return 0; @@ -1209,13 +1207,12 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, u= int32_t func, int reg) * of 'hv_passthrough' mode and fills the environment with all supported * Hyper-V features. */ -static int hyperv_expand_features(CPUState *cs) +static void hyperv_expand_features(CPUState *cs, Error **errp) { X86CPU *cpu =3D X86_CPU(cs); - int r; =20 if (!hyperv_enabled(cpu)) - return 0; + return; =20 if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D @@ -1262,37 +1259,60 @@ static int hyperv_expand_features(CPUState *cs) } =20 /* Features */ - r =3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT); + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT, errp)) { + return; + } =20 /* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) && !cpu->hyperv_synic_kvm_only && !hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX)) { - fprintf(stderr, "Hyper-V %s requires Hyper-V %s\n", - kvm_hyperv_properties[HYPERV_FEAT_SYNIC].desc, - kvm_hyperv_properties[HYPERV_FEAT_VPINDEX].desc); - r |=3D 1; - } - - if (r) { - return -ENOSYS; + error_setg(errp, "Hyper-V %s requires Hyper-V %s", + kvm_hyperv_properties[HYPERV_FEAT_SYNIC].desc, + kvm_hyperv_properties[HYPERV_FEAT_VPINDEX].desc); } - - return 0; } =20 /* @@ -1527,9 +1547,10 @@ int kvm_arch_init_vcpu(CPUState *cs) env->apic_bus_freq =3D KVM_APIC_BUS_FREQUENCY; =20 /* Paravirtualization CPUIDs */ - r =3D hyperv_expand_features(cs); - if (r < 0) { - return r; + hyperv_expand_features(cs, &local_err); + if (local_err) { + error_report_err(local_err); + return -ENOSYS; } =20 if (hyperv_enabled(cpu)) { --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607053; cv=none; d=zohomail.com; s=zohoarc; b=dlB74olgAWxkLMdYZHlBcc3moKpJBnBKQyHACvmu32F9ks9HufGSM4A7p15jbKVIuWk9yb0BJzDx103LJfHb61OX2z1pG4R+pkItkgfb8SOFgZY9SAq7QoGjCFnN/uVbJFf0JpvI589z8TqDIU8MNSIvLdziywnP/fvfphaZq9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607053; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ar4PiAMgTsLpqKIgYbANVALODcwWUZSVr2lwDAqNnpk=; b=fVsk0qzsi+7WXH5Bru3wuXgstafQvIXUflD307EamMt7FJAVnUWKRZW2MiqdX9m1behwFHyiQszGZOtxYmBkaxmoaQIT4ZhQGcLlUK6qQNigzORBFXBwwsR39z6cz8JEsjV8exHBTmRceOBsAMCPYaVRaH4TJCQm2Dx+/hSf9SI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607053819228.40336379257656; Mon, 1 Mar 2021 05:57:33 -0800 (PST) Received: from localhost ([::1]:57370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj3E-0006om-Pk for importer@patchew.org; Mon, 01 Mar 2021 08:57:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixW-0006fp-Az for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37057) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixU-0008Q2-En for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:38 -0500 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-251-hSBLJYSrMGWWB_4IptRpXQ-1; Mon, 01 Mar 2021 08:51:34 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1BEC5CC632 for ; Mon, 1 Mar 2021 13:51:32 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7134462679; Mon, 1 Mar 2021 13:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606695; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ar4PiAMgTsLpqKIgYbANVALODcwWUZSVr2lwDAqNnpk=; b=OHym4LqcWmQHatThyZsfnzSnfvnv0F+Ynx+l8nVR/nJGJ/AnuJHk40/ghaTJFT/O3CPClc spoIXjzTXex2cCWPyU70AoyO8sQoOxGypl6ePu27io1EO/ElP+JvbM2LoFagv0qelLT7ik BJl2BthwOuQnm7iRBIEVNqmJNpQKQX0= X-MC-Unique: hSBLJYSrMGWWB_4IptRpXQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 12/17] i386: adjust the expected KVM_GET_SUPPORTED_HV_CPUID array size Date: Mon, 1 Mar 2021 14:50:58 +0100 Message-Id: <20210301135103.306003-13-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" SYNDBG leaves were recently (Linux-5.8) added to KVM but we haven't updated the expected size of KVM_GET_SUPPORTED_HV_CPUID output in KVM so we now make serveral tries before succeeding. Update the default. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 5cdceb6e34c4..4d301da7375e 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -961,7 +961,8 @@ static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs= , int max) static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState *cs) { struct kvm_cpuid2 *cpuid; - int max =3D 7; /* 0x40000000..0x40000005, 0x4000000A */ + /* 0x40000000..0x40000005, 0x4000000A, 0x40000080..0x40000080 leaves */ + int max =3D 10; int i; =20 /* --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607185; cv=none; d=zohomail.com; s=zohoarc; b=QATJJueVVahoKPW9Cie89oeGitPSy8dZRULBqpyAvzI+BbKODBRr57mZOOST0/yrZ2D5dJtomxK4RZ6nxHyTtIf6RyH++k1zFZGaRKMn2ZyHOIdPd+6OUUUU4ufOH93yxTUGWAZ/sNbNQq0LfFWb6/7qY9PLufZsh/SK8uD+1EE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607185; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5M+K8bs83qCm/w7AXg7FXWxRQ6Ohiihq9e9exPuzGNY=; b=Xa4HP88Zkwj6hb3eHNkyNj35zswkLC70JZ5E01FAGOAkL3YYEuNW89Fs2T2utTghalo9VhvXYhei6m4gAPjiyv/2NVKRhAFbUTUo+L3dk7/hvnib/ivXsTfcTzDS/YVP5pO6jueed1EuEdjh2GzQuUAfH5hr3bIuVstsjufzkdg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607185104359.93851083714935; Mon, 1 Mar 2021 05:59:45 -0800 (PST) Received: from localhost ([::1]:35028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj5M-0000t1-1B for importer@patchew.org; Mon, 01 Mar 2021 08:59:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixY-0006hb-N5 for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46101) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixV-0008Qd-3K for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:40 -0500 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-418-_cN4Mg5dMWm429mj-dnhRg-1; Mon, 01 Mar 2021 08:51:34 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0635B108BD0C for ; Mon, 1 Mar 2021 13:51:34 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A2D562679; Mon, 1 Mar 2021 13:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606696; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5M+K8bs83qCm/w7AXg7FXWxRQ6Ohiihq9e9exPuzGNY=; b=Si385XC7lZiNT/OcWc+uMmSzlmwvzPA+laxySljTqdf4cp0yBP1mBhkY8OZeFnDYG0UK99 J3uzC39FSdCgsrh1zH1pNJVXREXkPLZf63DwADQMD3nh8zWzr+g22H2elEBCa/fpqW6ezi seDtSbR3hrue7Sn0KM2K+2RruOoQXU8= X-MC-Unique: _cN4Mg5dMWm429mj-dnhRg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 13/17] i386: prefer system KVM_GET_SUPPORTED_HV_CPUID ioctl over vCPU's one Date: Mon, 1 Mar 2021 14:50:59 +0100 Message-Id: <20210301135103.306003-14-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" KVM_GET_SUPPORTED_HV_CPUID was made a system wide ioctl which can be called prior to creating vCPUs and we are going to use that to expand Hyper-V cpu features early. Use it when it is supported by KVM. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 4d301da7375e..264f879cd257 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -928,7 +928,8 @@ static struct { }, }; =20 -static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max) +static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max, + bool do_sys_ioctl) { struct kvm_cpuid2 *cpuid; int r, size; @@ -937,7 +938,11 @@ static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *c= s, int max) cpuid =3D g_malloc0(size); cpuid->nent =3D max; =20 - r =3D kvm_vcpu_ioctl(cs, KVM_GET_SUPPORTED_HV_CPUID, cpuid); + if (do_sys_ioctl) { + r =3D kvm_ioctl(kvm_state, KVM_GET_SUPPORTED_HV_CPUID, cpuid); + } else { + r =3D kvm_vcpu_ioctl(cs, KVM_GET_SUPPORTED_HV_CPUID, cpuid); + } if (r =3D=3D 0 && cpuid->nent >=3D max) { r =3D -E2BIG; } @@ -964,13 +969,17 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUS= tate *cs) /* 0x40000000..0x40000005, 0x4000000A, 0x40000080..0x40000080 leaves */ int max =3D 10; int i; + bool do_sys_ioctl; + + do_sys_ioctl =3D + kvm_check_extension(kvm_state, KVM_CAP_SYS_HYPERV_CPUID) > 0; =20 /* * When the buffer is too small, KVM_GET_SUPPORTED_HV_CPUID fails with * -E2BIG, however, it doesn't report back the right size. Keep increa= sing * it and re-trying until we succeed. */ - while ((cpuid =3D try_get_hv_cpuid(cs, max)) =3D=3D NULL) { + while ((cpuid =3D try_get_hv_cpuid(cs, max, do_sys_ioctl)) =3D=3D NULL= ) { max++; } =20 @@ -980,7 +989,7 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUSta= te *cs) * information early, just check for the capability and set the bit * manually. */ - if (kvm_check_extension(cs->kvm_state, + if (!do_sys_ioctl && kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_ENLIGHTENED_VMCS) > 0) { for (i =3D 0; i < cpuid->nent; i++) { if (cpuid->entries[i].function =3D=3D HV_CPUID_ENLIGHTMENT_INF= O) { --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607410; cv=none; d=zohomail.com; s=zohoarc; b=RuegW12jkLL8AWXuyqem/jDC1/DNuKF8Niq5ZS4ddwLwu/X1akXQN2HwPAihMDZhfvi3lqXim5MkrmY+5txWhvDdgGWAoCr1CU3Sc7dxIu+drwiKqBNbJzqIG1ugG6hhlIZ8FPrGP1pG/B7efZKs63eM5UtWc+tJtm5xBer0hho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607410; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J4/oe0btS0bHA7+XPJuN0jPkWuUB5KN7Jk1ITp7qEuQ=; b=KhKXfh7sxPXG+qUtxeTcASkEwtrR5C5kQkfmdFLmervMkZDrh/imqtkrQQqQUHf3PZsj7BppV29stftT+xRiPJ4V0SBPo7JqHeK0MNft152yqmahdHS8trHOo/ralXoisMA+7/jqL1r1M0/eMDTE6pcOM7o6gCkO1AXyfZ19q7c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607410864598.5270576629418; Mon, 1 Mar 2021 06:03:30 -0800 (PST) Received: from localhost ([::1]:39948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGj8w-0003Cx-2b for importer@patchew.org; Mon, 01 Mar 2021 09:03:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixb-0006jE-8R for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28020) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixZ-0008TB-2U for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:42 -0500 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-470-y48GCpREPu2FYYZjnS-W4A-1; Mon, 01 Mar 2021 08:51:38 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF21F10513CD for ; Mon, 1 Mar 2021 13:51:36 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B2236A8FF; Mon, 1 Mar 2021 13:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606700; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J4/oe0btS0bHA7+XPJuN0jPkWuUB5KN7Jk1ITp7qEuQ=; b=I4Qybvd5jXevhICGLNoQGwbwl2pbOWReX1jug+ud5c8+ScimaIu20BrgmC3KgMJDLEr3sS fk/TEiwOzdLQ2k4F5IXX0Gl5pGAAsG0dwJ1luTBLVjV/r1M+tgpHd+fMrtlBjpkWqSL0b0 vv61cLus3T+FiL8qGLAXyZJj6ygO1PM= X-MC-Unique: y48GCpREPu2FYYZjnS-W4A-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 14/17] i386: use global kvm_state in hyperv_enabled() check Date: Mon, 1 Mar 2021 14:51:00 +0100 Message-Id: <20210301135103.306003-15-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There is no need to use vCPU-specific kvm state in hyperv_enabled() check and we need to do that when feature expansion happens early, before vCPU specific KVM state is created. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 264f879cd257..3fa6570215b6 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -715,8 +715,7 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs) =20 static bool hyperv_enabled(X86CPU *cpu) { - CPUState *cs =3D CPU(cpu); - return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 && + return kvm_check_extension(kvm_state, KVM_CAP_HYPERV) > 0 && ((cpu->hyperv_spinlock_attempts !=3D HYPERV_SPINLOCK_NEVER_NOTIFY)= || cpu->hyperv_features || cpu->hyperv_passthrough); } --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607566; cv=none; d=zohomail.com; s=zohoarc; b=LMu6P4UmUolJx6TxuCmRwiyV+bNRuoqr49nGW7/PmwTjw779j3f5rVa0Qxn4yGwB8MSrNNN5Z7rJ3SngmAL7/dsz1s+COiE/bqaPFTXINpvOSt1cNWtHj7EQhnmTCA/8r4y30kRLseOyfDd98/Vn0yalOYQ/IINSdxINeKJ/h+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607566; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/WXk2J6Fex6BYJmkCCt67MwHzahup/gXxO3sEMHsDlw=; b=THIH61wmza/dDrezuL6u5NI93ckbFjq0OcumZOtHB9nwCAguQYQc8YZawVkqhGVurYB73F/0/xu1hV2PuiCjcl4hfGcuvQir/zuvDjTYNzgvRohbxfM1slSLfVvK6sRNGK7PFDGILJQJyE5fNYt/7Zx00IX6pUd3jZIXmqjizis= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607566224777.1887196655908; Mon, 1 Mar 2021 06:06:06 -0800 (PST) Received: from localhost ([::1]:44794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGjBU-0005Iq-Qq for importer@patchew.org; Mon, 01 Mar 2021 09:06:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixd-0006qP-Q5 for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixa-0008TK-Ql for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:45 -0500 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-483-p4nw5AYwMW-PAU9BXWxCWg-1; Mon, 01 Mar 2021 08:51:39 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF23F85B6C1 for ; Mon, 1 Mar 2021 13:51:38 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 648B86A90E; Mon, 1 Mar 2021 13:51:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606701; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/WXk2J6Fex6BYJmkCCt67MwHzahup/gXxO3sEMHsDlw=; b=QaYJd8EsioSyDpPI75DF1yq+F5fhhBya64tI3Pvd6he4QDM26hyi0C5F567LeqSs4evmq8 usz7aJRB4pJgudPZOn7JPXzHpQimkivq+V0T0SRQN8r4xZt72Z220z1jCjTHDxvCqPphEV QcnECteNu+2rDy6ge7axWTtZunCpqDs= X-MC-Unique: p4nw5AYwMW-PAU9BXWxCWg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 15/17] i386: expand Hyper-V features during CPU feature expansion time Date: Mon, 1 Mar 2021 14:51:01 +0100 Message-Id: <20210301135103.306003-16-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" To make Hyper-V features appear in e.g. QMP query-cpu-model-expansion we need to expand and set the corresponding CPUID leaves early. Modify x86_cpu_get_supported_feature_word() to call newly intoduced Hyper-V specific kvm_hv_get_supported_cpuid() instead of kvm_arch_get_supported_cpuid(). We can't use kvm_arch_get_supported_cpuid() as Hyper-V specific CPUID leaves intersect with KVM's. Note, early expansion will only happen when KVM supports system wide KVM_GET_SUPPORTED_HV_CPUID ioctl (KVM_CAP_SYS_HYPERV_CPUID). Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 4 ++++ target/i386/kvm/kvm-stub.c | 5 +++++ target/i386/kvm/kvm.c | 15 ++++++++++++--- target/i386/kvm/kvm_i386.h | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e943d42569db..dd639dd06784 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6502,6 +6502,10 @@ static void x86_cpu_expand_features(X86CPU *cpu, Err= or **errp) if (env->cpuid_xlevel2 =3D=3D UINT32_MAX) { env->cpuid_xlevel2 =3D env->cpuid_min_xlevel2; } + + if (kvm_enabled()) { + kvm_hyperv_expand_features(cpu, errp); + } } =20 /* diff --git a/target/i386/kvm/kvm-stub.c b/target/i386/kvm/kvm-stub.c index 92f49121b8fa..7f175faa3abd 100644 --- a/target/i386/kvm/kvm-stub.c +++ b/target/i386/kvm/kvm-stub.c @@ -39,3 +39,8 @@ bool kvm_hv_vpindex_settable(void) { return false; } + +void kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) +{ + return; +} diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 3fa6570215b6..f865057a81dd 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1216,13 +1216,22 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, u= int32_t func, int reg) * of 'hv_passthrough' mode and fills the environment with all supported * Hyper-V features. */ -static void hyperv_expand_features(CPUState *cs, Error **errp) +void kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) { - X86CPU *cpu =3D X86_CPU(cs); + CPUState *cs =3D CPU(cpu); =20 if (!hyperv_enabled(cpu)) return; =20 + /* + * When kvm_hyperv_expand_features is called at CPU feature expansion + * time per-CPU kvm_state is not available yet so we can only proceed + * when KVM_CAP_SYS_HYPERV_CPUID is supported. + */ + if (!cs->kvm_state && + !kvm_check_extension(kvm_state, KVM_CAP_SYS_HYPERV_CPUID)) + return; + if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EBX= ); @@ -1556,7 +1565,7 @@ int kvm_arch_init_vcpu(CPUState *cs) env->apic_bus_freq =3D KVM_APIC_BUS_FREQUENCY; =20 /* Paravirtualization CPUIDs */ - hyperv_expand_features(cs, &local_err); + kvm_hyperv_expand_features(cpu, &local_err); if (local_err) { error_report_err(local_err); return -ENOSYS; diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index dc725083891c..f1176491051d 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -47,6 +47,7 @@ bool kvm_has_x2apic_api(void); bool kvm_has_waitpkg(void); =20 bool kvm_hv_vpindex_settable(void); +void kvm_hyperv_expand_features(X86CPU *cpu, Error **errp); =20 uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address); =20 --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607604; cv=none; d=zohomail.com; s=zohoarc; b=KXGyGMdWNy+TDevHdDu2YjmiOZwy5ZIVxGAsG0r18fuOcpl5GcR+vt+zURIWlS/us9IXCZn0N+tMINtaZ9BA/jhC76uJWGYnETl/lfmuh5JKZuQABAKIzs5kURHS3WpS5PTZw/CEnu6AWyrbhwNf90MOUmpal3+9Spv/pImkQXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607604; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=b8bIwmfTIMcTXViwqHfwsf2z/AAHcupjBkRSyHakUM4=; b=DicuyQcyUcahQm6TPyWSQqyy3jz4aidBHjncDV73yktxoif7eDhUIhS/BPvnwhMpvh/f6WoG9gZNia3JWNAHtfp7hEv8V8UbA+vyelHaXL/3P6FG98hYWuVLqUXokG0cPbgqJaaKI9UD3v5lupdX+grn5VC3z9tIjKZactWre1U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607604161520.2917046490744; Mon, 1 Mar 2021 06:06:44 -0800 (PST) Received: from localhost ([::1]:45558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGjC7-0005hu-2c for importer@patchew.org; Mon, 01 Mar 2021 09:06:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixf-0006uM-9s for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33952) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixd-0008Uj-8g for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:47 -0500 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-301-IIf0PHbwMlSqxnzYwZYXqA-1; Mon, 01 Mar 2021 08:51:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1EFC985B6C1 for ; Mon, 1 Mar 2021 13:51:41 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5898862465; Mon, 1 Mar 2021 13:51:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606704; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b8bIwmfTIMcTXViwqHfwsf2z/AAHcupjBkRSyHakUM4=; b=hQKttINSClmGwKBj15Q5n7vpPq4JhN46mI2T9FSJ1A1co9TvuKpwkr6x7Dh1xVk7aHtTHD mSjEnEtskpFMqpz+Sls2qOHuXGVyjs1fjeaZQDXhrlAticwHS6MVPdb05WFBXSkqXUogwN vpxzBYclcwu79vFYKPJhmJtP2JHKc6M= X-MC-Unique: IIf0PHbwMlSqxnzYwZYXqA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 16/17] i386: provide simple 'hv-default=on' option Date: Mon, 1 Mar 2021 14:51:02 +0100 Message-Id: <20210301135103.306003-17-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Enabling Hyper-V emulation for a Windows VM is a tiring experience as it requires listing all currently supported enlightenments ("hv-*" CPU features) explicitly. We do have 'hv-passthrough' mode enabling everything but it can't be used in production as it prevents migration. Introduce a simple 'hv-default=3Don' CPU flag enabling all currently suppor= ted Hyper-V enlightenments. Later, when new enlightenments get implemented, compat_props mechanism will be used to disable them for legacy machine type= s, this will keep 'hv-default=3Don' configurations migratable. Signed-off-by: Vitaly Kuznetsov --- docs/hyperv.txt | 18 ++++++++++++++--- target/i386/cpu.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- target/i386/cpu.h | 3 +++ 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index 5df00da54fc4..0a15cf026017 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -17,10 +17,22 @@ compatible hypervisor and use Hyper-V specific features. =20 2. Setup =3D=3D=3D=3D=3D=3D=3D=3D=3D -No Hyper-V enlightenments are enabled by default by either KVM or QEMU. In -QEMU, individual enlightenments can be enabled through CPU flags, e.g: +The default set of currently supported Hyper-V enlightenments (consisting = of all +currently supported enlightenments except for 'hv-evmcs' which can only be +enabled on VMX enabled guests) can be enabled by specifying 'hv-default=3D= on' CPU +flag: =20 - qemu-system-x86_64 --enable-kvm --cpu host,hv_relaxed,hv_vpindex,hv_time= , ... + qemu-system-x86_64 --enable-kvm --cpu host,hv-default ... + +Alternatively, it is possible to do fine-grained enablement through CPU fl= ags, +e.g: + + qemu-system-x86_64 --enable-kvm --cpu host,hv-relaxed,hv-vpindex,hv-time= ... + +It is also possible to disable individual enlightenments from the default = list, +this can be used for debugging purposes: + + qemu-system-x86_64 --enable-kvm --cpu host,hv-default=3Don,hv-evmcs=3Dof= f ... =20 Sometimes there are dependencies between enlightenments, QEMU is supposed = to check that the supplied configuration is sane. diff --git a/target/i386/cpu.c b/target/i386/cpu.c index dd639dd06784..14f566cfde57 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4658,6 +4658,25 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visi= tor *v, const char *name, cpu->env.tsc_khz =3D cpu->env.user_tsc_khz =3D value / 1000; } =20 +static bool x86_hv_default_get(Object *obj, Error **errp) +{ + X86CPU *cpu =3D X86_CPU(obj); + + return cpu->hyperv_default; +} + +static void x86_hv_default_set(Object *obj, bool value, Error **errp) +{ + X86CPU *cpu =3D X86_CPU(obj); + + cpu->hyperv_default =3D value; + + /* hv-default overrides everything with the default set */ + if (value) { + cpu->hyperv_features =3D cpu->hyperv_default_features; + } +} + /* Generic getter for "feature-words" and "filtered-features" properties */ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, const char *name, void *opaque, @@ -6563,10 +6582,16 @@ static void x86_cpu_filter_features(X86CPU *cpu, bo= ol verbose) } } =20 -static void x86_cpu_hyperv_realize(X86CPU *cpu) +static void x86_cpu_hyperv_realize(X86CPU *cpu, Error **errp) { size_t len; =20 + if (cpu->hyperv_passthrough && cpu->hyperv_default) { + error_setg(errp, + "'hv-default' and 'hv-paththrough' are mutually exclusi= ve"); + return; + } + /* Hyper-V vendor id */ if (!cpu->hyperv_vendor) { object_property_set_str(OBJECT(cpu), "hv-vendor-id", "Microsoft Hv= ", @@ -6768,7 +6793,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) } =20 /* Process Hyper-V enlightenments */ - x86_cpu_hyperv_realize(cpu); + x86_cpu_hyperv_realize(cpu, &local_err); + if (local_err) { + goto out; + } =20 cpu_exec_realizefn(cs, &local_err); if (local_err !=3D NULL) { @@ -7063,6 +7091,20 @@ static void x86_cpu_initfn(Object *obj) if (xcc->model) { x86_cpu_load_model(cpu, xcc->model); } + + /* + * Hyper-V features enabled with 'hv-default=3Don' + * TODO: add 'HYPERV_FEAT_EVMCS' to the list. Enlightened VMCS can only + * be enabled for VMX enabled guests but here it can't be checked. + */ + cpu->hyperv_default_features =3D BIT(HYPERV_FEAT_RELAXED) | + BIT(HYPERV_FEAT_VAPIC) | BIT(HYPERV_FEAT_TIME) | + BIT(HYPERV_FEAT_CRASH) | BIT(HYPERV_FEAT_RESET) | + BIT(HYPERV_FEAT_VPINDEX) | BIT(HYPERV_FEAT_RUNTIME) | + BIT(HYPERV_FEAT_SYNIC) | BIT(HYPERV_FEAT_STIMER) | + BIT(HYPERV_FEAT_FREQUENCIES) | BIT(HYPERV_FEAT_REENLIGHTENMENT) | + BIT(HYPERV_FEAT_TLBFLUSH) | BIT(HYPERV_FEAT_IPI) | + BIT(HYPERV_FEAT_STIMER_DIRECT); } =20 static int64_t x86_cpu_get_arch_id(CPUState *cs) @@ -7389,6 +7431,10 @@ static void x86_cpu_common_class_init(ObjectClass *o= c, void *data) x86_cpu_get_crash_info_qom, NULL, NULL, NULL= ); #endif =20 + object_class_property_add_bool(oc, "hv-default", + x86_hv_default_get, + x86_hv_default_set); + for (w =3D 0; w < FEATURE_WORDS; w++) { int bitnr; for (bitnr =3D 0; bitnr < 64; bitnr++) { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 265e552746e7..f014f1a89f89 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1673,6 +1673,9 @@ struct X86CPU { bool hyperv_synic_kvm_only; uint64_t hyperv_features; bool hyperv_passthrough; + /* 'hv-default' enablement */ + uint64_t hyperv_default_features; + bool hyperv_default; OnOffAuto hyperv_no_nonarch_cs; uint32_t hyperv_vendor_id[3]; uint32_t hyperv_interface_id[4]; --=20 2.29.2 From nobody Sat May 18 23:44:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614607744; cv=none; d=zohomail.com; s=zohoarc; b=QSLmK2FS+rh+vic6w0ehwy7B44JVvtjSZvLPV6NQooO+v3W/8RoSQt0NchlphVwxdbR70dW9qvSLHagZ4XmvA/FlY5/qiHLbwnqoUtEC0/yGFTwitSvQygq8V4LeQSyXoZ+TDuU1SReKcBKzbqTHGg4w3damHLh5/HvWGtYcMoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614607744; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=P9pZ7wjQBUw+dawFA27I6LH4bMwfs72CHr1Yo2wFCAc=; b=easjGYbKUAiYXH5OHmppt9ziC0JwrIuXEz/X1KSJZJlLPRph5k7JdGGN/sd4bmHSNY6CcWbq6o5Nl4uRFlEzB/KsUHkJebrV5j55Hm8ol12PltrZb4llTf4lpscYMHV7nzvb92eLWdD3+Wul8YPlvlYU3WanBDoTAmoBk3RIk5w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614607744173892.9102615395072; Mon, 1 Mar 2021 06:09:04 -0800 (PST) Received: from localhost ([::1]:51172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGjEL-00088F-PU for importer@patchew.org; Mon, 01 Mar 2021 09:09:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGixi-00071Y-FT for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21402) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lGixe-0008Uv-FC for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:51:50 -0500 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-480-1JLORJt0Osuld-CkUYG6fw-1; Mon, 01 Mar 2021 08:51:44 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2627F801990 for ; Mon, 1 Mar 2021 13:51:43 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D171772E0; Mon, 1 Mar 2021 13:51:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614606705; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P9pZ7wjQBUw+dawFA27I6LH4bMwfs72CHr1Yo2wFCAc=; b=EgKZ2XIjXUOfP0Wnde/LxBxcaM68a8tuU1+1lOX7r66+2AZSekO6CMctvf857PTWrsVNhN myBW7OCwIqu/esoCfL6tmcBa0QoWV8mA/61in+AsLv3eoOpDB1zqvgSHoCjos3RwS4qRKI PYuYlEboQ2QGFdTdB6y1JBUTZfosGwU= X-MC-Unique: 1JLORJt0Osuld-CkUYG6fw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH v5 17/17] qtest/hyperv: Introduce a simple hyper-v test Date: Mon, 1 Mar 2021 14:51:03 +0100 Message-Id: <20210301135103.306003-18-vkuznets@redhat.com> In-Reply-To: <20210301135103.306003-1-vkuznets@redhat.com> References: <20210301135103.306003-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vkuznets@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For the beginning, just test 'hv-default', 'hv-passthrough' and a couple of custom Hyper-V enlightenments configurations through QMP. Later, it would be great to complement this by checking CPUID values from within the guest. Signed-off-by: Vitaly Kuznetsov --- MAINTAINERS | 1 + tests/qtest/hyperv-test.c | 270 ++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 3 files changed, 273 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/hyperv-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 9b2aa18e1fe3..9c4152588f3e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1517,6 +1517,7 @@ F: hw/isa/apm.c F: include/hw/isa/apm.h F: tests/test-x86-cpuid.c F: tests/qtest/test-x86-cpuid-compat.c +F: tests/qtest/hyperv-test.c =20 PC Chipset M: Michael S. Tsirkin diff --git a/tests/qtest/hyperv-test.c b/tests/qtest/hyperv-test.c new file mode 100644 index 000000000000..707fce80c5a0 --- /dev/null +++ b/tests/qtest/hyperv-test.c @@ -0,0 +1,270 @@ +/* + * Hyper-V emulation CPU feature test cases + * + * Copyright (c) 2021 Red Hat Inc. + * Authors: + * Vitaly Kuznetsov + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include +#include + +#include "qemu/osdep.h" +#include "qemu/bitops.h" +#include "libqos/libqtest.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" + +#define MACHINE_KVM "-machine pc-q35-5.2 -accel kvm " +#define QUERY_HEAD "{ 'execute': 'query-cpu-model-expansion', " \ + " 'arguments': { 'type': 'full', " +#define QUERY_TAIL "}}" + +static bool kvm_enabled(QTestState *qts) +{ + QDict *resp, *qdict; + bool enabled; + + resp =3D qtest_qmp(qts, "{ 'execute': 'query-kvm' }"); + g_assert(qdict_haskey(resp, "return")); + qdict =3D qdict_get_qdict(resp, "return"); + g_assert(qdict_haskey(qdict, "enabled")); + enabled =3D qdict_get_bool(qdict, "enabled"); + qobject_unref(resp); + + return enabled; +} + +static bool kvm_has_sys_hyperv_cpuid(void) +{ + int fd =3D open("/dev/kvm", O_RDWR); + int ret; + + g_assert(fd > 0); + + ret =3D ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_SYS_HYPERV_CPUID); + + close(fd); + + return ret > 0; +} + +static QDict *do_query_no_props(QTestState *qts, const char *cpu_type) +{ + return qtest_qmp(qts, QUERY_HEAD "'model': { 'name': %s }" + QUERY_TAIL, cpu_type); +} + +static bool resp_has_props(QDict *resp) +{ + QDict *qdict; + + g_assert(resp); + + if (!qdict_haskey(resp, "return")) { + return false; + } + qdict =3D qdict_get_qdict(resp, "return"); + + if (!qdict_haskey(qdict, "model")) { + return false; + } + qdict =3D qdict_get_qdict(qdict, "model"); + + return qdict_haskey(qdict, "props"); +} + +static QDict *resp_get_props(QDict *resp) +{ + QDict *qdict; + + g_assert(resp); + g_assert(resp_has_props(resp)); + + qdict =3D qdict_get_qdict(resp, "return"); + qdict =3D qdict_get_qdict(qdict, "model"); + qdict =3D qdict_get_qdict(qdict, "props"); + + return qdict; +} + +static bool resp_get_feature(QDict *resp, const char *feature) +{ + QDict *props; + + g_assert(resp); + g_assert(resp_has_props(resp)); + props =3D resp_get_props(resp); + g_assert(qdict_get(props, feature)); + return qdict_get_bool(props, feature); +} + +#define assert_has_feature(qts, cpu_type, feature) \ +({ \ + QDict *_resp =3D do_query_no_props(qts, cpu_type); \ + g_assert(_resp); \ + g_assert(resp_has_props(_resp)); \ + g_assert(qdict_get(resp_get_props(_resp), feature)); \ + qobject_unref(_resp); \ +}) + +#define resp_assert_feature(resp, feature, expected_value) \ +({ \ + QDict *_props; \ + \ + g_assert(_resp); \ + g_assert(resp_has_props(_resp)); \ + _props =3D resp_get_props(_resp); \ + g_assert(qdict_get(_props, feature)); \ + g_assert(qdict_get_bool(_props, feature) =3D=3D (expected_value)); = \ +}) + +#define assert_feature(qts, cpu_type, feature, expected_value) \ +({ \ + QDict *_resp; \ + \ + _resp =3D do_query_no_props(qts, cpu_type); \ + g_assert(_resp); \ + resp_assert_feature(_resp, feature, expected_value); \ + qobject_unref(_resp); \ +}) + +#define assert_has_feature_enabled(qts, cpu_type, feature) \ + assert_feature(qts, cpu_type, feature, true) + +#define assert_has_feature_disabled(qts, cpu_type, feature) \ + assert_feature(qts, cpu_type, feature, false) + +static void test_assert_hyperv_all_but_evmcs(QTestState *qts) +{ + assert_has_feature_enabled(qts, "host", "hv-relaxed"); + assert_has_feature_enabled(qts, "host", "hv-vapic"); + assert_has_feature_enabled(qts, "host", "hv-vpindex"); + assert_has_feature_enabled(qts, "host", "hv-runtime"); + assert_has_feature_enabled(qts, "host", "hv-crash"); + assert_has_feature_enabled(qts, "host", "hv-time"); + assert_has_feature_enabled(qts, "host", "hv-synic"); + assert_has_feature_enabled(qts, "host", "hv-stimer"); + assert_has_feature_enabled(qts, "host", "hv-tlbflush"); + assert_has_feature_enabled(qts, "host", "hv-ipi"); + assert_has_feature_enabled(qts, "host", "hv-reset"); + assert_has_feature_enabled(qts, "host", "hv-frequencies"); + assert_has_feature_enabled(qts, "host", "hv-reenlightenment"); + assert_has_feature_enabled(qts, "host", "hv-stimer-direct"); +} + +static void test_query_cpu_hv_all_but_evmcs(const void *data) +{ + QTestState *qts; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-relaxed,hv-vapic,hv-vpind= ex," + "hv-runtime,hv-crash,hv-time,hv-synic,hv-stimer," + "hv-tlbflush,hv-ipi,hv-reset,hv-frequencies," + "hv-reenlightenment,hv-stimer-direct"); + + test_assert_hyperv_all_but_evmcs(qts); + + qtest_quit(qts); +} + +static void test_query_cpu_hv_default(const void *data) +{ + QTestState *qts; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-default"); + + test_assert_hyperv_all_but_evmcs(qts); + + qtest_quit(qts); +} + +static void test_query_cpu_hv_default_minus(const void *data) +{ + QTestState *qts; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-default,hv_ipi=3Doff"); + + assert_has_feature_enabled(qts, "host", "hv-tlbflush"); + assert_has_feature_disabled(qts, "host", "hv-ipi"); + + qtest_quit(qts); +} + +static void test_query_cpu_hv_custom(const void *data) +{ + QTestState *qts; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-vpindex"); + + assert_has_feature_enabled(qts, "host", "hv-vpindex"); + assert_has_feature_disabled(qts, "host", "hv-synic"); + + qtest_quit(qts); +} + +static void test_query_cpu_hv_passthrough(const void *data) +{ + QTestState *qts; + QDict *resp; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-passthrough"); + if (!kvm_enabled(qts)) { + qtest_quit(qts); + return; + } + + test_assert_hyperv_all_but_evmcs(qts); + + resp =3D do_query_no_props(qts, "host"); + if (resp_get_feature(resp, "vmx")) { + assert_has_feature_enabled(qts, "host", "hv-evmcs"); + } else { + assert_has_feature_disabled(qts, "host", "hv-evmcs"); + } + + qtest_quit(qts); +} + +static void test_query_cpu_hv_evmcs_novmx_default(const void *data) +{ + QTestState *qts; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,-vmx,hv-default"); + if (!kvm_enabled(qts)) { + qtest_quit(qts); + return; + } + + assert_has_feature_disabled(qts, "host", "vmx"); + assert_has_feature_disabled(qts, "host", "hv-evmcs"); + + qtest_quit(qts); +} + +int main(int argc, char **argv) +{ + const char *arch =3D qtest_get_arch(); + + g_test_init(&argc, &argv, NULL); + + if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64")) { + qtest_add_data_func("/hyperv/hv-all-but-evmcs", + NULL, test_query_cpu_hv_all_but_evmcs); + qtest_add_data_func("/hyperv/hv-default", + NULL, test_query_cpu_hv_default); + qtest_add_data_func("/hyperv/hv-default-minus", + NULL, test_query_cpu_hv_default_minus); + qtest_add_data_func("/hyperv/hv-custom", + NULL, test_query_cpu_hv_custom); + if (kvm_has_sys_hyperv_cpuid()) { + qtest_add_data_func("/hyperv/hv-passthrough", + NULL, test_query_cpu_hv_passthrough); + qtest_add_data_func("/hyperv/hv-evmcs-novmx-default", NULL, + test_query_cpu_hv_evmcs_novmx_default); + } + } + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index ba6ecaed3256..c65f2098defc 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -65,7 +65,8 @@ qtests_i386 =3D \ 'vmgenid-test', 'migration-test', 'test-x86-cpuid-compat', - 'numa-test'] + 'numa-test', + 'hyperv-test'] =20 dbus_daemon =3D find_program('dbus-daemon', required: false) if dbus_daemon.found() and config_host.has_key('GDBUS_CODEGEN') --=20 2.29.2