From nobody Sat May 18 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975813; cv=none; d=zohomail.com; s=zohoarc; b=HOHYte/sldOVMSXOxbPnLwOJd+yX+7zS667JxGklLAC7CjzZ8FxVB/kcvQy1HIenxOigy0zZBhXP0P0jy6zjX0LUxY+bRlFXHdQ42MfJGprymuA8rZTUeJwQtmicIU3mDCT0wd/0mri6OYomqldlRGEpx4a9Eyqw3As+kQ76CbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975813; 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=h3FzcW4YkQIfGDu7vetopn4MP4AyUdLcKukRg+tfNZE=; b=YmIOEKGTEAcvUu+F93Xlaia8oGvhYeMm7w/6vR7x9j2riHs8GfdWSTHEe5J2h7JrjPGwoIPv5/qV3l3mLWZCPLYjkB1PhJWghKTafWs7Sg0+pwPmCsOJDnXKqGBOAyunUqC5A02hlgVtDZWXBzHG7qAaC1+gl0EJOLThRUjYUwo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975813271401.35616665289285; Wed, 10 Feb 2021 08:50:13 -0800 (PST) Received: from localhost ([::1]:59916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sgu-0007r0-3O for importer@patchew.org; Wed, 10 Feb 2021 11:50:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sXs-00072J-Ex for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:40:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58677) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sXn-0008J4-9s for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:40:52 -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-330-G4H6vON8MeyjgXpAyBogcQ-1; Wed, 10 Feb 2021 11:40:41 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E6AB107ACC7 for ; Wed, 10 Feb 2021 16:40:40 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80D485D9E8; Wed, 10 Feb 2021 16:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975243; 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=h3FzcW4YkQIfGDu7vetopn4MP4AyUdLcKukRg+tfNZE=; b=Nih6nrnuqtOtYgKHaf9Lhkv6hQ7nWIxhAjMPkeay4z2j/qoFr0Lg+pz1j/T2L4DzCPYj3v sTHmmy80l3nx07rdevn93ZMXRzekVV/fINqRjzw8qoXO3+/WXIL++n0alzYTiGguwpv2pu sE1PxS8fkeSXUe30CsYE1w9JmN3JmGg= X-MC-Unique: G4H6vON8MeyjgXpAyBogcQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 01/21] i386: keep hyperv_vendor string up-to-date Date: Wed, 10 Feb 2021 17:40:13 +0100 Message-Id: <20210210164033.607612-2-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 | 4 ++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 9c3d2d60b7e5..d03c1588ba0e 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6547,17 +6547,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 e97f84175707..6ae4be44aa6f 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1214,6 +1214,10 @@ 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)); } =20 c =3D cpuid_find_entry(cpuid, HV_CPUID_INTERFACE, 0); --=20 2.29.2 From nobody Sat May 18 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975390; cv=none; d=zohomail.com; s=zohoarc; b=RcLNjcOx0KLvQ6YyMYiQ3et+wwyeblrmw0W8PnGuoKagF+rREEfdxfoez24VwMKzUphuPCXn0Gpc7/dvibbt2kyygorW/zVMT6yp+F8oSdYl6NUf8h5dVLN36EkjC+FqojU+Ze+ohiySqj7PzYJ7mf4kV5913fzZwpbIZDwfVUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975390; 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=AzY4EVn/Wh23H/MyDxH9Ksw5zBGd6mWab6F9cH7kG5M=; b=HbMmTrvb5LGIGC41sXN7eGT4ZxiK+ctqWH9+wxZDmwWmaxi5Q/ak9CfSNqGoPM+kxoifxkhVf1io+TngwspL3YXfV9E+x8CfgjDNKm51CG6Wn2Lb9+EMziyaR4ut045PPjJmB9KAWhbg4p7UFoXJ/GGqrSgawatvHZzGVoAaVMk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975390227622.5201854601422; Wed, 10 Feb 2021 08:43:10 -0800 (PST) Received: from localhost ([::1]:43210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sa5-0000PS-3Y for importer@patchew.org; Wed, 10 Feb 2021 11:43:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sXr-00071M-8b for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:40:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23130) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sXn-0008JU-3X for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:40: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-409-wi2mQ4gfOGiox8XSLm6pvw-1; Wed, 10 Feb 2021 11:40:43 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A1541936B66 for ; Wed, 10 Feb 2021 16:40:42 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C6C05D9D0; Wed, 10 Feb 2021 16:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975244; 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=AzY4EVn/Wh23H/MyDxH9Ksw5zBGd6mWab6F9cH7kG5M=; b=RYNnjAh1k5LB1su2qX7VQA93oW7xDpHN6Lp9e90fZZnWgToUy6C/CbEmkFH/GOZOXnzT0/ u2aNoJqsyuaT8coK7TyOCRLHqYDoP+MbzylL/nsqWH0rnq7Oge52gSgItEGk8/zMlUKKei klRBkrd/Z0Szp4ebCLifPJpfO/veW3U= X-MC-Unique: wi2mQ4gfOGiox8XSLm6pvw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 02/21] i386: invert hyperv_spinlock_attempts setting logic with hv_passthrough Date: Wed, 10 Feb 2021 17:40:14 +0100 Message-Id: <20210210164033.607612-3-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 6ae4be44aa6f..211efbd13b49 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1254,11 +1254,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975608; cv=none; d=zohomail.com; s=zohoarc; b=nvBBwVXyHwC03MCZBk7VJLyD4F1Cm2ETxlEHydOrQU9PO0RBRORhNPJoL5TzFc77i+DiuP9YwL2kbkvdLjYTOgdssQRUi+q5AjiekAH4b0ZZeFLuJisUolZMiEk9P4LQweLT4erShvfHryRSbmAZzlw0J2WlWr+UZ2yHrv3NzCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975608; 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=ee3IZXj1PsPCi9G25ei8tWCodyL6T+WK4xsjb7cw7aQ=; b=Gf2XOcLRZT8QtQg7p7qdol/STYzE+fgrJUVQmvEcxw05zIffnMwsN09nu8mL6OAYAJH+vQ6Zwnnko3TAqGOgau9u+Ny9Znn7cIHx6Qmlqz7Ye+YAbqU0JUMwD7tIq0V1g4KVg5WLfBN6S98SkrlECaNjaSBeVNifP7ZebcnDOZk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975608297678.1346065158402; Wed, 10 Feb 2021 08:46:48 -0800 (PST) Received: from localhost ([::1]:51490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sda-0003yY-TO for importer@patchew.org; Wed, 10 Feb 2021 11:46:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sXs-000729-9U for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:40:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sXn-0008KA-R2 for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:40:52 -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-603-sJOSZeWQP5m6nK402zfA_g-1; Wed, 10 Feb 2021 11:40:45 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69B48107ACE8 for ; Wed, 10 Feb 2021 16:40:44 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 987FF5D9D0; Wed, 10 Feb 2021 16:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975247; 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=ee3IZXj1PsPCi9G25ei8tWCodyL6T+WK4xsjb7cw7aQ=; b=WEZjaT5VFgOhFO/5Boc6g3N4oRgkMcbscM6R/zL+ucZDCh3jzCaBkFPyHgvGQJHNjLqc0+ rJCtLgpQxboqSytuiK/Q3+ZlZUSDI4M0BtOGA6FbXwSx1Yjxl4AvOyua3hskGATMZTG7UN 7KhjP7bvEHG/bIu8mRYp98S+E1NJY7U= X-MC-Unique: sJOSZeWQP5m6nK402zfA_g-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 03/21] i386: always fill Hyper-V CPUID feature leaves from X86CPU data Date: Wed, 10 Feb 2021 17:40:15 +0100 Message-Id: <20210210164033.607612-4-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 211efbd13b49..ba285a364792 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1206,9 +1206,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; @@ -1307,12 +1304,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975462; cv=none; d=zohomail.com; s=zohoarc; b=gyTnleWGuMuSYEOPn/v4oWGcLMpbinTCP9cuJij9L8yXBxnullqSx+PQccWeeJjzAiftdltQiXWX0bhdcHzTQxGZZS9f/4LF8WWgE3in1+YctdEF720aEKMiqVjfxgy7VXKec+i4Kffl3BFbf6tOIhg4S5LmrbJpc/oHnlwrcmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975462; 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=+8OfNTM7yS3bU/X9ZcC4jNhY/nu/uQ1ZS2oN67R+nJI=; b=dItQc00yXWWxPEBieVPCJc0y6kPbgnZdgbrSuKp4m293BtMBwl7QPEZb16ogC9tw8SMDlHyPJKQaYhTEVNKcHSJx84yw+8Ud8zUJ/v2N7efYN+UlGDgSNxcCr8FpzN2kf+dj7j8QKL63VMDC2+thvGtsjFsBFFs9rUfXAvZWA6U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975461760786.4517879056506; Wed, 10 Feb 2021 08:44:21 -0800 (PST) Received: from localhost ([::1]:45910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sbE-0001be-Js for importer@patchew.org; Wed, 10 Feb 2021 11:44:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sY1-00074P-PP for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sXt-0008M2-0E for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:40:59 -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-196-U0q7sJOYOd6c9boumY9Qeg-1; Wed, 10 Feb 2021 11:40:50 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7569791275 for ; Wed, 10 Feb 2021 16:40:49 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC8D65D9E3; Wed, 10 Feb 2021 16:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975252; 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=+8OfNTM7yS3bU/X9ZcC4jNhY/nu/uQ1ZS2oN67R+nJI=; b=ZxMwyaILWNNx/p2NV0L0EXnX02vjsrq0og+St4QZ2JrHGOTwg0TTROWTykEC67XbgAlelC vVWOV9WoleoVtqDwtwulaib3OrX9lATpn++drWU47NyMBpE+UyODWHlF5HKezNnriUUE67 f+HFpmcdxRWJLu7Ux5UvPBGC2fXQIco= X-MC-Unique: U0q7sJOYOd6c9boumY9Qeg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 04/21] i386: stop using env->features[] for filling Hyper-V CPUIDs Date: Wed, 10 Feb 2021 17:40:16 +0100 Message-Id: <20210210164033.607612-5-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 8d599bb5b8f7..21a1758b4b1a 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1678,6 +1678,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 ba285a364792..2734b01c95e1 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1110,7 +1110,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; @@ -1150,8 +1149,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) { @@ -1161,6 +1158,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 @@ -1170,9 +1190,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 @@ -1193,9 +1212,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 @@ -1233,13 +1250,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; @@ -1250,23 +1260,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 */ @@ -1296,9 +1291,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; @@ -1328,15 +1320,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; @@ -1356,7 +1360,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975692; cv=none; d=zohomail.com; s=zohoarc; b=TcxeLl+0BPQ5CQ3DJbUIBl87mQe3nfOU4ANjDANmJM2Tj/FXy1JTs404apuErOalhgn4BASUo2ECFDsKnJmog/W5Ml2MCahGCpSwom5o6nMdrzO1LXLgyYQ/AetLBl3MQQYHQJHu5mfK6i5/VWmfDzOygrXD271UeW0fCroKenI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975692; 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=tFJD1ahGcmzhQcclqSL95E02IbjfeBq/+ldjET+gxng=; b=D1Gn6JcstQc8dcRN5yUrGYK3uVYfnlY5teMpV9819CiUN0OBaHERGmLQLacVbkhk+MEGhinQUSjIyADYCu1f9Ub0W5aCVQN/4d7UiR1RcA/iZvIsEmzddbiwyS8l8h7nZNq6rpC+hZvS8kiyLcH7tvTR0R3+wMtFMDxYxRKvvx0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975692496819.2427085256021; Wed, 10 Feb 2021 08:48:12 -0800 (PST) Received: from localhost ([::1]:54214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sex-00058i-Ao for importer@patchew.org; Wed, 10 Feb 2021 11:48:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sY3-00075Y-N2 for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33610) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sXy-0008NH-0V for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:03 -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-166-BbYPyDsgOgmJM6qe5IqcTw-1; Wed, 10 Feb 2021 11:40:52 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55A11835E2D for ; Wed, 10 Feb 2021 16:40:51 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id C11ED5D9D0; Wed, 10 Feb 2021 16:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975253; 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=tFJD1ahGcmzhQcclqSL95E02IbjfeBq/+ldjET+gxng=; b=W2dCflX1tDEFLlokZKqv4B8dkg19WJBy+HdS/R0yy4ZEKp9boYgm5ve0twO7VHuypL8U6e wp5dHG5H6XEZ0immzQ5mxkIbrnbAl1O6Ig/cda8TVw+GJVC1Uwvn830RpivodGMnLG0wA+ 08ZhjWLl/tjNkAIr6zRcGsfGuD3imjo= X-MC-Unique: BbYPyDsgOgmJM6qe5IqcTw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 05/21] i386: introduce hyperv_feature_supported() Date: Wed, 10 Feb 2021 17:40:17 +0100 Message-Id: <20210210164033.607612-6-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 2734b01c95e1..dd80b46bc604 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1106,13 +1106,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; @@ -1131,23 +1151,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975914; cv=none; d=zohomail.com; s=zohoarc; b=TMYLszE0LxhMFBYIDW0MVLK62JoSSZbNzb0WMZEcsDSFckCgaaQvm+/46M5rT7BwQbgLfHkraYQXlwqOo7cj61infC+LOt2HW0R6ELcCvJXHhtGqvRXSrBlWD42dzuxyDfORjl1pDNFPu0UEnTFC6/xcXxuIEeMkssUSWL4+JMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975914; 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=3MijN3B7/5RTCPwXE9AM3P5Gt6OGFmifGDgCjh2ygzA=; b=OYwWoqWQNaFbgzMQxndL3GvelISZbvqUIcOsSgw6QVKcjqbwMwLAIYd5PJS2kK2Aourd6hspWRVl/zZrU0Q5tiaeuqo7hGbfbNTcpEwfXKoiWwTKB6byiYXEFyGhrHSyq5j+d969+1XgUihKtGKFm7oyKNfi07psOFcyKOZh5FQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975914053611.2832655266078; Wed, 10 Feb 2021 08:51:54 -0800 (PST) Received: from localhost ([::1]:34420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9siW-0000nT-UF for importer@patchew.org; Wed, 10 Feb 2021 11:51:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sY2-00075N-P8 for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sXy-0008OS-Vo for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:02 -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-346-Pb0zVyCmNpuphMpHEoxqCQ-1; Wed, 10 Feb 2021 11:40:54 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 304251936B60 for ; Wed, 10 Feb 2021 16:40:53 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id A49D55D9D0; Wed, 10 Feb 2021 16:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975255; 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=3MijN3B7/5RTCPwXE9AM3P5Gt6OGFmifGDgCjh2ygzA=; b=R+R9gYkMR5X5jIVBVEeYnJNNq174UW4AgBtPsSu++2co+Tv1dvMd5wIJfRmTBJ9mHswVRq +GYzx9BrplP+7OumPU/wcLELJU9bKB6Vl+RKvF6x/KhTukPcYzxmO+++TBYtIv2tJOBId2 YFm6OQxzmpe2ybWCpq4z4PeMnrmboMA= X-MC-Unique: Pb0zVyCmNpuphMpHEoxqCQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 06/21] i386: introduce hv_cpuid_get_host() Date: Wed, 10 Feb 2021 17:40:18 +0100 Message-Id: <20210210164033.607612-7-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 | 100 +++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index dd80b46bc604..762c4f893467 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1106,6 +1106,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; @@ -1202,7 +1215,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 @@ -1234,45 +1247,46 @@ 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)); - } - - 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_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 */ @@ -1346,10 +1360,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975454; cv=none; d=zohomail.com; s=zohoarc; b=awzRiKdLzVFoVh04VbxyvEBOpO7f1tIMjH8aCKXiODr9uHvQiZD9u472LfJnDZxrMg/1iHbHYZaQWLjsOebdfyPZ9rOdyGYfqOydSLGv4SAfzIqPsBvfm6NSOQutnsB9x8WKTHeJWfWnTpDTUGotWkkPbgo7Y8fMsO4y5lWQS4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975454; 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=HCV4GsKRTLr2J5uhJZnvF9PdbQ1CosnI2t505+iyVRI=; b=bk1UDX/7aQHDv9B9azLOdqCsN1cv/mh0w1BgsgrNgeWwAkf1qo7eNw/wWguNtCeRJ8s8c4FRbhcp8mTfzS901b/Bnv5N6dszZOhRxfAT0Pe2nyJ7yNZ21FO3lj0ePIVncUSHGap4aFQjlNgWH4c9aAEub5xgNO++WE+KZXuwQ0s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975453940644.8730814375132; Wed, 10 Feb 2021 08:44:13 -0800 (PST) Received: from localhost ([::1]:45466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sb6-0001Pe-SD for importer@patchew.org; Wed, 10 Feb 2021 11:44:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sY5-000767-Lq for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sY1-0008P2-IK for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:04 -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-297-j_KZicQqNPG9TC1hbeUDyw-1; Wed, 10 Feb 2021 11:40:56 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F914107ACE3 for ; Wed, 10 Feb 2021 16:40:55 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EEC95D9D0; Wed, 10 Feb 2021 16:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975258; 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=HCV4GsKRTLr2J5uhJZnvF9PdbQ1CosnI2t505+iyVRI=; b=WAhv0Y2/jWi7iD9ifj2di9MMOYGo8bcd/7q78yJdWpBdFBOatU6GmGzZEWS+akM/yhsYAr zKQWbqsR38IKxMz8PNcWyOFLm+vV09xrjbkRQazbtFSZlT4TbslxJtQ+Gx+1g0hs+Dg9MM MDXnTa9nLIkiL6a8Sy4USUJm7FRr98o= X-MC-Unique: j_KZicQqNPG9TC1hbeUDyw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 07/21] i386: drop FEAT_HYPERV feature leaves Date: Wed, 10 Feb 2021 17:40:19 +0100 Message-Id: <20210210164033.607612-8-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 d03c1588ba0e..f0f826997ba0 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 { @@ -6951,7 +6863,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 21a1758b4b1a..7ea14822aab5 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -518,11 +518,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 762c4f893467..d2c524376342 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -799,7 +799,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; @@ -807,25 +808,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} } @@ -833,42 +834,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) @@ -876,23 +877,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} }, @@ -901,7 +902,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) @@ -909,7 +910,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} }, @@ -918,7 +919,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) @@ -1064,48 +1065,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) { @@ -1121,18 +1080,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; } } @@ -1182,7 +1143,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; @@ -1194,7 +1155,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 @@ -1345,16 +1309,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975692; cv=none; d=zohomail.com; s=zohoarc; b=htnS4+vpExM11kjAy1elNfHbdecg9h0qVFU141sGX3Xcl1D7zBeJdLd2aEgd25Z17R6puA0Hr6YOop3wM2UZ4bjYRnkJHhJA/mBA8C7ZT8O7/mlX0uFmrxytIydGXsuR2XZCV8qrZxqv4i2BN7j3klSnLr34Sz36WEIGdHwgv78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975692; 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=gCXzaXgNdXY5tuuAe1Wb0e3DvPNtP6rs6xxYVwJuOmg=; b=Nt4oGceiWfvaI3W3IArFvgSYgkX8WDv4Jwo3gh53SjLirDVu1X+zwfRSs/sx5YLT7AFz7tBfnqWb5fpsiZPoO8xpXyBuq3X19+dzoiSrxcXaGJ4V+B0zK2Ch11kZ+ypv2LWwxWQgJvAntB1sOxcQsw1xrmJvLaEc5sZJMMdHAYY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975691957302.392110045696; Wed, 10 Feb 2021 08:48:11 -0800 (PST) Received: from localhost ([::1]:54166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sew-00057V-Rs for importer@patchew.org; Wed, 10 Feb 2021 11:48:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sY9-00076Z-OF for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47268) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sY2-0008PE-1b for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:09 -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-488-yCh7Oc6wMXqtTTV7mmIgLA-1; Wed, 10 Feb 2021 11:40:59 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 799F21936B79 for ; Wed, 10 Feb 2021 16:40:57 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE65D5D9E8; Wed, 10 Feb 2021 16:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975261; 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=gCXzaXgNdXY5tuuAe1Wb0e3DvPNtP6rs6xxYVwJuOmg=; b=R5M0/UhzGh6sLWDTfvVHkBN+JXcWA5+GkSJxm0JZ1hnDrEwFEGQ7ImOdlbRUZY21tk0Jk0 YHGVwN8zjlpPqwzotz4p2p23aKWaMPUOn6KiFb+s80ElbGDbuD2xFGhX/IK85NBpwKFDCq haUC9IOD3BermhxJBe/c86wCTzPuPsU= X-MC-Unique: yCh7Oc6wMXqtTTV7mmIgLA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 08/21] i386: introduce hv_cpuid_cache Date: Wed, 10 Feb 2021 17:40:20 +0100 Message-Id: <20210210164033.607612-9-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 d2c524376342..bcc5709ec467 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -127,6 +127,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) @@ -1065,10 +1066,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) { @@ -1078,7 +1094,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; @@ -1093,7 +1109,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; } } @@ -1101,8 +1117,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; @@ -1125,7 +1140,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", @@ -1178,7 +1193,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; @@ -1204,71 +1218,65 @@ 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, sizeof(cpu->hyperv_vendor_id)); =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) && @@ -1281,8 +1289,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++]; @@ -1324,7 +1331,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 @@ -1349,12 +1356,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612976059; cv=none; d=zohomail.com; s=zohoarc; b=ckzuIfSQphFysd1Z1IRAvXQuFB0Gj825Jt8CyjVJ2Y2ipB3Ou4LBzgfq/QxQnKD2UqFOTVJ+sM0pGFnzcR1G6mH4EFy27RkFnOh3vQfA+3DWmVyNg+dfas2ECJLgR4hrNyRFxfGAWXNmdBJ4zBWCmWjySEKOPgcekaP4MNwp3qg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612976059; 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=roL0mRNB/R5YIewqpjZmy8mF5yT80a4hlFQadesvpIA=; b=GDo24+VZMNjAMumVuOo+XZD1GE85ZrDJfhMeEVdrZMUg3gOopJAgxHBY/14EwLRpwdxlWxkFm+GBNr+KCHeS2nHEkrOGPz40I25yfrdEPA/0ctSsJEoUb2hZ2oIy7IEuJ696qd1RfxHo510XuNF2UyuwpPqZbrkmMO5JhJjZDvc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612976059187504.60016297899665; Wed, 10 Feb 2021 08:54:19 -0800 (PST) Received: from localhost ([::1]:39988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sks-0003Ba-1q for importer@patchew.org; Wed, 10 Feb 2021 11:54:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYB-00078i-1q for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42378) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sY2-0008Pu-LR for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:10 -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-557-BrO7pBqLNomXjLIsxQ1HYQ-1; Wed, 10 Feb 2021 11:41:00 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 761B3107ACE8 for ; Wed, 10 Feb 2021 16:40:59 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7C835D9D0; Wed, 10 Feb 2021 16:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975262; 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=roL0mRNB/R5YIewqpjZmy8mF5yT80a4hlFQadesvpIA=; b=UNipAC/Q6/AFs+77YPj+urYRun/p7tOd6bbmMWDVuSfnEO0zpKClH9RwSL7j70sMlbcnGt J0dKBGHeE78wXZNOmwxVZ/jkve9NmDWDo2ROZ2uPf7QGf7QwdTN7Xn9JvM71Mo975X5QrU mkxOrCL7ULK9EL1yA+1ykr9DwekdXHQ= X-MC-Unique: BrO7pBqLNomXjLIsxQ1HYQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 09/21] i386: split hyperv_handle_properties() into hyperv_expand_features()/hyperv_fill_cpuids() Date: Wed, 10 Feb 2021 17:40:21 +0100 Message-Id: <20210210164033.607612-10-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 bcc5709ec467..893c9c515fbb 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1185,16 +1185,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)) @@ -1292,6 +1291,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) ? @@ -1499,11 +1511,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975609; cv=none; d=zohomail.com; s=zohoarc; b=WUVO4Zpho/TLAnr5PkNcsaiJVIUKgtHcYZaXlew/U1FzwnFQpUoEo+M2jemWnZCoRJAyFzjsnwlt/YtjyCFval6YoEvR2FQ7EE/rYxzqfoMttdI84ySqy9cnXnIMvNPosRXSN5+HK2snfgI+go2eZkmqrU/opyv8nL0pEiciy6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975609; 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=fAm1Ev9ofq0v6+7mtrvoQC1c6x56+yBXAKh3p/0hHQA=; b=gbYd5Zk/dhUSFoazgu+OWRvLChOM31Vl/hiX0qNjG6AHUNuQrZMIQ9bS0JlKhpUNeA+yUrXt/p9b1l6Lg08u13IQPBRA/LbWntNlAf96J/75EFwSlaQ1QafrTbyXdfj1OcpSn3QsiGx8EsU3FZUwh0D7rlz1A4OjiBdddWFMxZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975608603800.7279256791008; Wed, 10 Feb 2021 08:46:48 -0800 (PST) Received: from localhost ([::1]:51698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sdb-00043V-CF for importer@patchew.org; Wed, 10 Feb 2021 11:46:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYB-0007Ay-VZ for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sY5-0008Qf-Jh for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:11 -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-372-BfMDRO4yMAaxYhMiwyau0g-1; Wed, 10 Feb 2021 11:41:02 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E41E9126F for ; Wed, 10 Feb 2021 16:41:01 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFE535D9D0; Wed, 10 Feb 2021 16:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975264; 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=fAm1Ev9ofq0v6+7mtrvoQC1c6x56+yBXAKh3p/0hHQA=; b=E/hwXT5iCyhumOb6uMoq43NPKerU7I3FigAzKFicdkJe7TqRGE67RPu5qQ1t/ABOlkjO7k /Et8vI2i+usVKSE5M7VxFw7qx02jcvPyuT/wvTAMcAtul++Eov+w9V4z8Hq/mVg/0qbvAh pX64Wnn/1SRFMx7AWjyeu/28QtbIv/A= X-MC-Unique: BfMDRO4yMAaxYhMiwyau0g-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 10/21] i386: move eVMCS enablement to hyperv_init_vcpu() Date: Wed, 10 Feb 2021 17:40:22 +0100 Message-Id: <20210210164033.607612-11-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 893c9c515fbb..4cab175fa95c 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -961,6 +961,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 @@ -970,6 +971,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 @@ -1199,24 +1216,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= ); @@ -1453,6 +1452,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 @@ -1517,6 +1531,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; @@ -1866,11 +1885,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612976284; cv=none; d=zohomail.com; s=zohoarc; b=lo1/0foQpCpad5799PVlJ+ikc/yC+0kT6W380KnVrCmulDUQdxtj/BO2Xka4m293pLRjbj7ZIuBNNBvT/uW6xQXpzOzjLEtbg0p6ayz9N1yhL09sRrdBnGdlJpiuVDjqe0VNHwlnrM2RCNlrjkdAbGlvsV6zjLPYKUwzJVaMYnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612976284; 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=A2BEneaZMniIeumScUDuUeWZABXz4Z6He1fyR/b7NS8=; b=gOwyInHXCyVGghoUFrqQc6r/zm0qsNve0T3OGVFzqsfvCGIYvIdER//uaLXOxP+do4Z1c8OEE0hlp430OnngEAEl1x5odlWv/d625DXMm68ZYvEgL/HvnEYBoMH30KkNCRKm+0ZajazFuAugstlMnynK/FW9jUkduzg5rEYtZR0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612976284211851.2499144724586; Wed, 10 Feb 2021 08:58:04 -0800 (PST) Received: from localhost ([::1]:48586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9soV-0006zf-3p for importer@patchew.org; Wed, 10 Feb 2021 11:58:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYB-00079D-8b for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sY9-0008R9-C6 for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:10 -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-64-cNOqAfZrNiePkRaBUHBngg-1; Wed, 10 Feb 2021 11:41:04 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 517E0835E23 for ; Wed, 10 Feb 2021 16:41:03 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCDBE5D9D0; Wed, 10 Feb 2021 16:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975266; 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=A2BEneaZMniIeumScUDuUeWZABXz4Z6He1fyR/b7NS8=; b=C446NkosV8lQtxZA0uuVT4JzxQTKsprsJR4xp7gbZhNu3Z0lmEv1xhmRTKeqi7edwGZ5EL pvyHeC379yRRVzMiGoYxENE1Z/p+CGISHkMshIh7hNGGpzORwiVMah0iVCDBXn/tNgA0dz CtFWXtSFLp7wrtBbko7xwveJcygLy+Y= X-MC-Unique: cNOqAfZrNiePkRaBUHBngg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 11/21] i386: switch hyperv_expand_features() to using error_setg() Date: Wed, 10 Feb 2021 17:40:23 +0100 Message-Id: <20210210164033.607612-12-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 4cab175fa95c..3c1e84576184 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1134,7 +1134,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; @@ -1148,20 +1148,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; @@ -1208,13 +1206,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 @@ -1260,37 +1257,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 /* @@ -1525,9 +1545,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612976147; cv=none; d=zohomail.com; s=zohoarc; b=cM8aFxHeb4An/IYN1wgS8HK6uBnX99fmJ9CQCRr+6P26HrN7W6ckOe24DLGX0vTGBlWYdTj/iax49uViHZZ3mVfuhVxepTTLTLa0oqVoNSBax/htKpaDS8RSHsx8OZxENYdNP5FhhgE2ZTiK6xpo4RSQMa8X4lD+7d/mAs8r7as= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612976147; 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=zVp54fFCz5m4iBYSgeDnxYFqNa0yZEFKWtPZQnYLWic=; b=YIXPjZ315knLcejXzrndS4eFCr4vkMHzGPRWClOYBLk1HMWU6ToBFzZp7NhgIzwKpmZ6F4fbBOW9sv7qM64stXwLEcnmZMvSAu5DWgcY4wd5qAbQ13WcBsEzv+zYkEajlRzA5IvmneTwZswsRsSWVUC5icUAig3l5ExY/Kc/+j4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612976146904612.6011185693814; Wed, 10 Feb 2021 08:55:46 -0800 (PST) Received: from localhost ([::1]:42596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9smH-0004M5-MS for importer@patchew.org; Wed, 10 Feb 2021 11:55:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYC-0007B7-08 for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45234) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sY9-0008Rk-IB for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:11 -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-451-DTAWf7IfMZCtZvk3oHOadA-1; Wed, 10 Feb 2021 11:41:07 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44C50107ACE3 for ; Wed, 10 Feb 2021 16:41:06 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF3485D9D0; Wed, 10 Feb 2021 16:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975268; 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=zVp54fFCz5m4iBYSgeDnxYFqNa0yZEFKWtPZQnYLWic=; b=PBcd0MxklsYVbZ+NAD9kBnT+qJGsuEwjW36LS3JKGi7vp6owLfjIySLBvnxyDH2StqwCfy t+i6ytD3198g3npFYWQ95V040BMUsi3JBQTVv3i/7wqacJe+S01svTQSUSS/cbRnDucuhS 0fUx4O9kPYBOWzomdGrlIWjvwEPAmTg= X-MC-Unique: DTAWf7IfMZCtZvk3oHOadA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 12/21] i386: adjust the expected KVM_GET_SUPPORTED_HV_CPUID array size Date: Wed, 10 Feb 2021 17:40:24 +0100 Message-Id: <20210210164033.607612-13-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 3c1e84576184..f4edfbb10879 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -960,7 +960,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975914; cv=none; d=zohomail.com; s=zohoarc; b=Q1P/L//uqrgGSRdMJ1fyMMcpZjFau0kJqNajIlFRgcfSWRqIT6LNb4nGwqbtWXGGTRVyYyw5bcXmJOg5adp8qLRLACl5em9uSjKJv/De737PGzdhn+vOUQZgY+cySSZWGctgmXgMmHBRxS3qGx23xYWGCpETNw6BQKhTPG9+BnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975914; 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=w81onXbmpy2ZaOb2880BdziCRwKQuKadykFk94gHIII=; b=BboLCQ3cwu7X0Qh9FvpzqL1MVA7U7dAVIZcoJ2dNgIwcnQm8n0Q1rVA20tNn2Ytw+bpXnqiI/nvCt5ok3Y9J7/7S3TYFxd9NGoPCgivqaJaoyIorwtTWaK8UniKsre+Rx9DN46Rbyx7owUs7esepgIvvXZUvk0X4V0aYAom+Gt4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975914778875.8956707263914; Wed, 10 Feb 2021 08:51:54 -0800 (PST) Received: from localhost ([::1]:34524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9siX-0000q4-Kz for importer@patchew.org; Wed, 10 Feb 2021 11:51:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYF-0007GA-FL for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57607) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sYD-0008TH-NN for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41: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-43-OW3VoD9OOvOftefSH43zFA-1; Wed, 10 Feb 2021 11:41:11 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67887835E25 for ; Wed, 10 Feb 2021 16:41:10 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65B285D9D0; Wed, 10 Feb 2021 16:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975273; 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=w81onXbmpy2ZaOb2880BdziCRwKQuKadykFk94gHIII=; b=Hr2Bu9FmU00z3aC3SMNZ7QWZ3h3KBLuYgKbnPjkKc0K8Ln9Hij4q7MqokmC4EW/GAtOkj2 0M/IjPx666++L5ZfdjbN5IQUYeBYVUAdRrS80QYF8LFFFt1/qZyaUeIC8MvKay5cUs4U7m 0PZ2GuKNyirBSaAC35q7mCCMCjOGEWM= X-MC-Unique: OW3VoD9OOvOftefSH43zFA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 13/21] i386: prefer system KVM_GET_SUPPORTED_HV_CPUID ioctl over vCPU's one Date: Wed, 10 Feb 2021 17:40:25 +0100 Message-Id: <20210210164033.607612-14-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 f4edfbb10879..48484592fc03 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -927,7 +927,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; @@ -936,7 +937,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; } @@ -963,13 +968,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 @@ -979,7 +988,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612976555; cv=none; d=zohomail.com; s=zohoarc; b=MJvwHwFxk7Ut4wesRRQaLoZPnwTOvUrDMR1y4ZgeC2FZVlXYIKA8QX5kiapVhFh4AUiaMSSsa2alZSopbumcimGSef+7+bKEDqcByfQ/EEw3hjQ7wkV4wXDhrvsU9EHa90lNyv37now/m6rZhVwOknTh9+3OpdSv4CxwCSS54lQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612976555; 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=j+AV2GFi+kjWFIUo+RE5H3HntnGgd3kq3702cA43x6g=; b=AdAwzWHJv6/X3dXlgQ/Lk/GTJuoOMWtQ9nNJufR/7zTZSuvJyWSZmftHV0MLwmmcOOK5Gn1eH2ihYKqvOnVr5Jbfl0P4JiP512iNnykDncX3A+6HoYQ56wNNcex78Y7QGQdsItCITuXmayuwcLSMjNdf1QnVQZHMoNiSWI5sk+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612976555442990.5998817251186; Wed, 10 Feb 2021 09:02:35 -0800 (PST) Received: from localhost ([::1]:57212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9ssr-0002pz-Oq for importer@patchew.org; Wed, 10 Feb 2021 12:02:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYQ-0007IV-4l for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44003) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sYJ-0008U6-23 for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:24 -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-116-ImeZkCV5Pg2G1Is0yVc_rQ-1; Wed, 10 Feb 2021 11:41:14 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6FCA11936B65 for ; Wed, 10 Feb 2021 16:41:12 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id D83975D9D0; Wed, 10 Feb 2021 16:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975275; 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=j+AV2GFi+kjWFIUo+RE5H3HntnGgd3kq3702cA43x6g=; b=JTHBCHNlvNTN+TDxUSkqUzkcqg7Eq8AHXqUE0ySCFoYdW01h2PDtbXOaSt+Um3t09Q+Fv9 /vhM96kNXd/vE77yfSpFovNXhvEEDk83dmErSHGvT3fAZyig32Chq6IMtSfEeIzuEMlZ9W E1++TQghZbf69lJvjcJOflrhgJCErPM= X-MC-Unique: ImeZkCV5Pg2G1Is0yVc_rQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 14/21] i386: use global kvm_state in hyperv_enabled() check Date: Wed, 10 Feb 2021 17:40:26 +0100 Message-Id: <20210210164033.607612-15-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 48484592fc03..47fc564747a3 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -714,8 +714,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612976064; cv=none; d=zohomail.com; s=zohoarc; b=mDXOhMRmMNAw97Ev1zEsTgkP9vIy6U5LDi1Jo7fhTWAFhWMFmqotjE7BQQ6tPi7DTG8B2/kgsxA2n0u046aGMsDeorCEfral37ZknM0FQMe/hg2ihM3LwdAUa4IVbCp3J97emaMFf6/AT/b+3kTMOqx2wt/BiHVSGjw/Ufspn8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612976064; 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=yaByhcodYuSE+UilLnVylwNvFqTJrI/ygDJgi0H0Yqw=; b=iu8ou7QNwsxMTTCoGzkEh930NAOHrpcXIViaL5x/Ko/DX0TByoL23R+s0YWu4gxLq4wQB3LTUE4N7br82g7oxX+YHr7U2dfbLRJMQ8YUURZGtelpaQlC6NvBYNZl6yQIrmIqmmdmnlEI6HRnwcsyWKoX4/4WurTdm6xY3Do5TWk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 161297606446893.93797806104476; Wed, 10 Feb 2021 08:54:24 -0800 (PST) Received: from localhost ([::1]:40144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9skv-0003HA-J6 for importer@patchew.org; Wed, 10 Feb 2021 11:54:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42378) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYR-0007If-Oj for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46385) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sYJ-0008UE-22 for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41: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-421-3PrfofEuMnCNFMXdquTY5A-1; Wed, 10 Feb 2021 11:41:15 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 81A4A107ACE6 for ; Wed, 10 Feb 2021 16:41:14 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB09B5D9D0; Wed, 10 Feb 2021 16:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975277; 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=yaByhcodYuSE+UilLnVylwNvFqTJrI/ygDJgi0H0Yqw=; b=h0la85YgOWDZliHLHLNlU2XkNIEhWWoeOwEtOhgAffPkPIx+YfocZgSfodvIDfc1osvLTe dq0J069MhLuAgYQiAwVM+P04pJg7R39RpjV8HE5FO767dfIpoi3miiXQD7HsJd4p/jYbce Tr3YTbooNspPzqd8u/1JdTFbYjLwFk4= X-MC-Unique: 3PrfofEuMnCNFMXdquTY5A-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 15/21] i386: expand Hyper-V features during CPU feature expansion time Date: Wed, 10 Feb 2021 17:40:27 +0100 Message-Id: <20210210164033.607612-16-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 f0f826997ba0..c4e8863c7ca0 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6396,6 +6396,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 47fc564747a3..30013f0d7cee 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1215,13 +1215,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= ); @@ -1554,7 +1563,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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612975813; cv=none; d=zohomail.com; s=zohoarc; b=FQLoRJ9exrCr0J7D8X8M43cQBNtKar/1rK0g/t08AVuaiMFX6uBzljXqOKoQ6PyqxEhnE9UZBPqzSXeR0DMmAz25bXrsn9BoZlJVluxOrhDKvVIQp7StKhC9fGHbZIlE46MWo4x5PIvlIDkmN/06j41f5fHRCldBWGcYTrY2r+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612975813; 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=1u9mcxYZQJ7ypVFtmUk66plC0dIbUY+DLO2gdZxDyf4=; b=K80V/R7N4fkC2cK+m0YLGsbdmoQOiN2l4/Fn7W2khAVIRwPdoUkiiDXbKTVa97UwBEVS7e8PwRTZocBM4T7WNCP0ci91D3QTa8ldie0jZJ3ZxKRqGm9FSYJyvcgVPugzRflbXaZqaM+4T/vbjI+w6yWNhus7OcyBW8kv8DkZ9Wo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612975813509754.5209280068915; Wed, 10 Feb 2021 08:50:13 -0800 (PST) Received: from localhost ([::1]:59944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sgu-0007rv-Cr for importer@patchew.org; Wed, 10 Feb 2021 11:50:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYR-0007Ih-Qb for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38371) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sYN-0008Uq-Nz for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:27 -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-8-kAVlKYSZMe6NEp13Odw5aQ-1; Wed, 10 Feb 2021 11:41:17 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6A70C1009617 for ; Wed, 10 Feb 2021 16:41:16 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id E728F5D9E3; Wed, 10 Feb 2021 16:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975279; 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=1u9mcxYZQJ7ypVFtmUk66plC0dIbUY+DLO2gdZxDyf4=; b=HDqOYDGck2pzIPRnrG+c+mrnTv2I/7QAIGgzGBHWgZhMaM7kRoaWVOvLgSmPA4bnhBy8gc Q7SACmolSXOBtpGji/fVefj7IkUBDI3sR41DwwWg7C7+tCzFqhcu69hLRohseHi4pS+Coc hds+nBGJdq4fpCoTHHibb1lc2JVchL4= X-MC-Unique: kAVlKYSZMe6NEp13Odw5aQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 16/21] i386: track explicit 'hv-*' features enablement/disablement Date: Wed, 10 Feb 2021 17:40:28 +0100 Message-Id: <20210210164033.607612-17-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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=170.10.133.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Sometimes we'd like to know which features were explicitly enabled and which were explicitly disabled on the command line. E.g. it seems logical to hand= le 'hv_passthrough,hv_feature=3Doff' as "enable everything supported by the ho= st except for hv_feature" but this doesn't seem to be possible with the current 'hyperv_features' bit array. Introduce 'hv_features_on'/'hv_features_off' add-ons and track explicit enablement/disablement there. Note, it doesn't seem to be possible to fill 'hyperv_features' array during CPU creation time when 'hv-passthrough' is specified and we're running on an older kernel without KVM_CAP_SYS_HYPERV_CPUID support. To get the list of the supported Hyper-V features we need to actually create KVM VCPU and this happens much later. No functional change intended. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 237 ++++++++++++++++++++++++++++++++++++++++------ target/i386/cpu.h | 2 + 2 files changed, 209 insertions(+), 30 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c4e8863c7ca0..e8a004c39d04 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4553,6 +4553,178 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Vis= itor *v, const char *name, cpu->env.tsc_khz =3D cpu->env.user_tsc_khz =3D value / 1000; } =20 +static bool x86_hv_feature_get(Object *obj, int feature) +{ + X86CPU *cpu =3D X86_CPU(obj); + + return cpu->hyperv_features & BIT(feature); +} + +static void x86_hv_feature_set(Object *obj, bool value, int feature) +{ + X86CPU *cpu =3D X86_CPU(obj); + + if (value) { + cpu->hyperv_features |=3D BIT(feature); + cpu->hyperv_features_on |=3D BIT(feature); + cpu->hyperv_features_off &=3D ~BIT(feature); + } else { + cpu->hyperv_features &=3D ~BIT(feature); + cpu->hyperv_features_on &=3D ~BIT(feature); + cpu->hyperv_features_off |=3D BIT(feature); + } +} + +static bool x86_hv_relaxed_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_RELAXED); +} + +static void x86_hv_relaxed_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_RELAXED); +} + +static bool x86_hv_vapic_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_VAPIC); +} + +static void x86_hv_vapic_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_VAPIC); +} + +static bool x86_hv_time_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_TIME); +} + +static void x86_hv_time_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_TIME); +} + +static bool x86_hv_crash_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_CRASH); +} + +static void x86_hv_crash_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_CRASH); +} + +static bool x86_hv_reset_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_RESET); +} + +static void x86_hv_reset_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_RESET); +} + +static bool x86_hv_vpindex_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_VPINDEX); +} + +static void x86_hv_vpindex_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_VPINDEX); +} + +static bool x86_hv_runtime_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_RUNTIME); +} + +static void x86_hv_runtime_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_RUNTIME); +} + +static bool x86_hv_synic_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_SYNIC); +} + +static void x86_hv_synic_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_SYNIC); +} + +static bool x86_hv_stimer_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_STIMER); +} + +static void x86_hv_stimer_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_STIMER); +} + +static bool x86_hv_frequencies_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_FREQUENCIES); +} + +static void x86_hv_frequencies_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_FREQUENCIES); +} + +static bool x86_hv_reenlightenment_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_REENLIGHTENMENT); +} + +static void x86_hv_reenlightenment_set(Object *obj, bool value, Error **er= rp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_REENLIGHTENMENT); +} + +static bool x86_hv_tlbflush_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_TLBFLUSH); +} + +static void x86_hv_tlbflush_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_TLBFLUSH); +} + +static bool x86_hv_evmcs_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_EVMCS); +} + +static void x86_hv_evmcs_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_EVMCS); +} + +static bool x86_hv_ipi_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_IPI); +} + +static void x86_hv_ipi_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_IPI); +} + +static bool x86_hv_stimer_direct_get(Object *obj, Error **errp) +{ + return x86_hv_feature_get(obj, HYPERV_FEAT_STIMER_DIRECT); +} + +static void x86_hv_stimer_direct_set(Object *obj, bool value, Error **errp) +{ + x86_hv_feature_set(obj, value, HYPERV_FEAT_STIMER_DIRECT); +} + /* 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, @@ -7107,36 +7279,6 @@ static Property x86_cpu_properties[] =3D { =20 DEFINE_PROP_UINT32("hv-spinlocks", X86CPU, hyperv_spinlock_attempts, HYPERV_SPINLOCK_NEVER_NOTIFY), - DEFINE_PROP_BIT64("hv-relaxed", X86CPU, hyperv_features, - HYPERV_FEAT_RELAXED, 0), - DEFINE_PROP_BIT64("hv-vapic", X86CPU, hyperv_features, - HYPERV_FEAT_VAPIC, 0), - DEFINE_PROP_BIT64("hv-time", X86CPU, hyperv_features, - HYPERV_FEAT_TIME, 0), - DEFINE_PROP_BIT64("hv-crash", X86CPU, hyperv_features, - HYPERV_FEAT_CRASH, 0), - DEFINE_PROP_BIT64("hv-reset", X86CPU, hyperv_features, - HYPERV_FEAT_RESET, 0), - DEFINE_PROP_BIT64("hv-vpindex", X86CPU, hyperv_features, - HYPERV_FEAT_VPINDEX, 0), - DEFINE_PROP_BIT64("hv-runtime", X86CPU, hyperv_features, - HYPERV_FEAT_RUNTIME, 0), - DEFINE_PROP_BIT64("hv-synic", X86CPU, hyperv_features, - HYPERV_FEAT_SYNIC, 0), - DEFINE_PROP_BIT64("hv-stimer", X86CPU, hyperv_features, - HYPERV_FEAT_STIMER, 0), - DEFINE_PROP_BIT64("hv-frequencies", X86CPU, hyperv_features, - HYPERV_FEAT_FREQUENCIES, 0), - DEFINE_PROP_BIT64("hv-reenlightenment", X86CPU, hyperv_features, - HYPERV_FEAT_REENLIGHTENMENT, 0), - DEFINE_PROP_BIT64("hv-tlbflush", X86CPU, hyperv_features, - HYPERV_FEAT_TLBFLUSH, 0), - DEFINE_PROP_BIT64("hv-evmcs", X86CPU, hyperv_features, - HYPERV_FEAT_EVMCS, 0), - DEFINE_PROP_BIT64("hv-ipi", X86CPU, hyperv_features, - HYPERV_FEAT_IPI, 0), - DEFINE_PROP_BIT64("hv-stimer-direct", X86CPU, hyperv_features, - HYPERV_FEAT_STIMER_DIRECT, 0), DEFINE_PROP_ON_OFF_AUTO("hv-no-nonarch-coresharing", X86CPU, hyperv_no_nonarch_cs, ON_OFF_AUTO_OFF), DEFINE_PROP_BOOL("hv-passthrough", X86CPU, hyperv_passthrough, false), @@ -7283,6 +7425,41 @@ 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-relaxed", + x86_hv_relaxed_get, x86_hv_relaxed_set); + object_class_property_add_bool(oc, "hv-vapic", + x86_hv_vapic_get, x86_hv_vapic_set); + object_class_property_add_bool(oc, "hv-time", + x86_hv_time_get, x86_hv_time_set); + object_class_property_add_bool(oc, "hv-crash", + x86_hv_crash_get, x86_hv_crash_set); + object_class_property_add_bool(oc, "hv-reset", + x86_hv_reset_get, x86_hv_reset_set); + object_class_property_add_bool(oc, "hv-vpindex", + x86_hv_vpindex_get, x86_hv_vpindex_set); + object_class_property_add_bool(oc, "hv-runtime", + x86_hv_runtime_get, x86_hv_runtime_set); + object_class_property_add_bool(oc, "hv-synic", + x86_hv_synic_get, x86_hv_synic_set); + object_class_property_add_bool(oc, "hv-stimer", + x86_hv_stimer_get, x86_hv_stimer_set); + object_class_property_add_bool(oc, "hv-frequencies", + x86_hv_frequencies_get, + x86_hv_frequencies_set); + object_class_property_add_bool(oc, "hv-reenlightenment", + x86_hv_reenlightenment_get, + x86_hv_reenlightenment_set); + object_class_property_add_bool(oc, "hv-tlbflush", + x86_hv_tlbflush_get, x86_hv_tlbflush_se= t); + object_class_property_add_bool(oc, "hv-evmcs", + x86_hv_evmcs_get, + x86_hv_evmcs_set); + object_class_property_add_bool(oc, "hv-ipi", + x86_hv_ipi_get, x86_hv_ipi_set); + object_class_property_add_bool(oc, "hv-stimer-direct", + x86_hv_stimer_direct_get, + x86_hv_stimer_direct_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 7ea14822aab5..b4fbd46f0fc9 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1667,6 +1667,8 @@ struct X86CPU { char *hyperv_vendor; bool hyperv_synic_kvm_only; uint64_t hyperv_features; + uint64_t hyperv_features_on; + uint64_t hyperv_features_off; bool hyperv_passthrough; OnOffAuto hyperv_no_nonarch_cs; uint32_t hyperv_vendor_id[3]; --=20 2.29.2 From nobody Sat May 18 18:13:08 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=1612979732; cv=none; d=zohomail.com; s=zohoarc; b=g935u47GgX9uQC1VI0E1aVMIj/aFCJ5+2yOLhIVnUbCzjQTYhsZY+lyzXs36PiOU33/jT6ddjR0hikt8VnBPRqI9RdbME7lt33eaDjWnvdH0jceX/MAbnjj7relGt9825ZHW1GYuiZEpRhGk+ZYG6WFq2Zpk7TFWGs0HoLGyXh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612979732; 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=gCzFwz5A2M5u86vlKhF3IJuBm7ZN0Qaa9eC8NVbtT9g=; b=WWp3YiuvgdGUDNR63zmjY3BOn2m7zkl9Yn7vfEWX7+yJYPgD/TF2dvDQfw68GSz3mpW7tpJEnDlcMpxl+W0O/0gAV2Qfs0fdWuOuwA5JdzgVb8TKw6JOCaGIM9AbeSm+vgXDQKZcFkdlT8XI3KA/k0Sa9/f7m1IKUeSUuHBSYos= 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 1612979731976581.0718397467549; Wed, 10 Feb 2021 09:55:31 -0800 (PST) Received: from localhost ([::1]:37444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9sve-0007VW-QH for importer@patchew.org; Wed, 10 Feb 2021 12:05:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYW-0007LE-BE for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32689) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sYO-0008VE-53 for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:32 -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-472-MgYUTyygOf2GHhTmjWx3Ng-1; Wed, 10 Feb 2021 11:41:19 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 448699127C for ; Wed, 10 Feb 2021 16:41:18 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF2BD5D9D0; Wed, 10 Feb 2021 16:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975280; 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=gCzFwz5A2M5u86vlKhF3IJuBm7ZN0Qaa9eC8NVbtT9g=; b=P2QjyiGZlZlYkI4NIFa6iYp5xVlFzBY5xG2GIzuxfwCAaWAlS+kqviKsge5wlaBtW7Trkg A1NiDEJzSnbCBeeZuRutKuQx9xsrrZ+DI2fkxpCedtfouiJBn9QYTipK0YHQopuHo4AusX 3YmfNJTDqfAaxH4UvpXXjA2eU7ynW7M= X-MC-Unique: MgYUTyygOf2GHhTmjWx3Ng-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 17/21] i386: support 'hv-passthrough, hv-feature=off' on the command line Date: Wed, 10 Feb 2021 17:40:29 +0100 Message-Id: <20210210164033.607612-18-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , 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" Currently, we support 'hv-passthrough,hv-feature=3Don' enablement, this is supposed to mean "hv-feature is mandatory, don't start without it". Add support for 'hv-passthrough,hv-feature=3Doff' meaning "enable everything supported by the host except for hv-feature". While on it, make 'hv-passthrough' parse semantics in-line with other options in qemu: when specified, it overrides what was previously set with what's supported by the host. This can later be modified with 'hv-feature= =3Don'/ 'hv-feature=3Doff'. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 28 +++++++++++++++++++++++++++- target/i386/kvm/kvm.c | 4 ++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e8a004c39d04..f8df2caed779 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4725,6 +4725,29 @@ static void x86_hv_stimer_direct_set(Object *obj, bo= ol value, Error **errp) x86_hv_feature_set(obj, value, HYPERV_FEAT_STIMER_DIRECT); } =20 +static bool x86_hv_passthrough_get(Object *obj, Error **errp) +{ + X86CPU *cpu =3D X86_CPU(obj); + + return cpu->hyperv_passthrough; +} + +static void x86_hv_passthrough_set(Object *obj, bool value, Error **errp) +{ + X86CPU *cpu =3D X86_CPU(obj); + + cpu->hyperv_passthrough =3D value; + + /* hv-passthrough overrides everything with what's supported by the ho= st */ + if (value) { + cpu->hyperv_features =3D 0; + cpu->hyperv_features_on =3D 0; + cpu->hyperv_features_off =3D 0; + } + + return; +} + /* 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, @@ -7281,7 +7304,6 @@ static Property x86_cpu_properties[] =3D { HYPERV_SPINLOCK_NEVER_NOTIFY), DEFINE_PROP_ON_OFF_AUTO("hv-no-nonarch-coresharing", X86CPU, hyperv_no_nonarch_cs, ON_OFF_AUTO_OFF), - DEFINE_PROP_BOOL("hv-passthrough", X86CPU, hyperv_passthrough, false), =20 DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), @@ -7460,6 +7482,10 @@ static void x86_cpu_common_class_init(ObjectClass *o= c, void *data) x86_hv_stimer_direct_get, x86_hv_stimer_direct_set); =20 + object_class_property_add_bool(oc, "hv-passthrough", + x86_hv_passthrough_get, + x86_hv_passthrough_set); + for (w =3D 0; w < FEATURE_WORDS; w++) { int bitnr; for (bitnr =3D 0; bitnr < 64; bitnr++) { diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 30013f0d7cee..fca088d4d3b5 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1153,6 +1153,10 @@ static int hv_cpuid_check_and_set(CPUState *cs, int = feature, Error **errp) return 0; } =20 + if (cpu->hyperv_passthrough && (cpu->hyperv_features_off & BIT(feature= ))) { + return 0; + } + deps =3D kvm_hyperv_properties[feature].dependencies; while (deps) { dep_feat =3D ctz64(deps); --=20 2.29.2 From nobody Sat May 18 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612976284; cv=none; d=zohomail.com; s=zohoarc; b=Mim/A097+SdtY/9ci5VCRzxvtsOtwspF3cN86aXq5/5FGBvB0HzpubNV4CW5Y+SkjVD1Cy/67ROv+jOvcPTPhhtTbbk8i3Wg8BQz8eGmJfNJxbCrWQ3UaPosg/Lh3wFNBPFW3nPrSmqZ6bL9jrGfwWicb8BDB9YQVYmVwsUuofw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612976284; 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=OyGuZSwO/lx4FxtJ5gDgP/LIZ375ifM28YqMTyS9PtU=; b=IqYIPCKFm2KYB0GwOOkPiVPQeKqrwphdRnXH1zFRQmxvigGdaDgQj8HE9xUq043vkPODHfqeBCbc2yGsTHm6pNPBSKcyE95WNO9p4UXZZbJtHW1b0LsWkQiD7FGIlntCvELko/RdO1NHko9Ruv+s7Vv9v1VcYSwyEIkvBCGqnTo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612976284144878.853690179236; Wed, 10 Feb 2021 08:58:04 -0800 (PST) Received: from localhost ([::1]:48554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9soU-0006yz-R2 for importer@patchew.org; Wed, 10 Feb 2021 11:58:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYW-0007LD-7t for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38219) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sYP-0008VM-Uv for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:30 -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-111-zpErjX73P4ac6u7unzZUaw-1; Wed, 10 Feb 2021 11:41:21 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 371D71005501 for ; Wed, 10 Feb 2021 16:41:20 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id A34005D9D0; Wed, 10 Feb 2021 16:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975282; 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=OyGuZSwO/lx4FxtJ5gDgP/LIZ375ifM28YqMTyS9PtU=; b=TC8KEvlUQIrHlSs+fLj+dn1KF1H9bb0eQhVij2JQ9QPaqauDd+pyml2uBhN86z0/P4FvDR 7XoeWR9gs7+n4KJ+SiA8edinfH22vXvRIWuGtbA5ON3MRPrUVEJLDHfRC0ErDd5bUxwmVc jf0oTnNvwVj7YOIotqNzEdmZuHAEp8g= X-MC-Unique: zpErjX73P4ac6u7unzZUaw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 18/21] i386: be more picky about implicit 'hv-evmcs' enablement Date: Wed, 10 Feb 2021 17:40:30 +0100 Message-Id: <20210210164033.607612-19-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Enlightened VMCS is the only (currently implemented in QEMU) Hyper-V feature with hardware dependencies, it pairs with Intel VMX. It doesn't seem right to enable this feature when VMX wasn't enabled in the guest and when it wasn't explicitly requested on the command line. Currently, the only possible scenario is 'hv-passthrough' which will enable 'hv-evmcs' when the host supports it, regardless of guest VMX exposure. The upcoming 'hv-default' should also avoid enabling 'hv-evmcs' without VMX. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index fca088d4d3b5..480908b2463a 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1315,8 +1315,17 @@ void kvm_hyperv_expand_features(X86CPU *cpu, Error *= *errp) if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH, errp)) { return; } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS, errp)) { - return; + /* + * 'hv-evmcs' is not enabled when it wasn't explicitly requested and g= uest + * CPU lacks VMX. + */ + if (cpu_has_vmx(&cpu->env) || + (cpu->hyperv_features_on & BIT(HYPERV_FEAT_EVMCS))) { + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS, errp)) { + return; + } + } else { + cpu->hyperv_features &=3D ~BIT(HYPERV_FEAT_EVMCS); } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI, errp)) { return; --=20 2.29.2 From nobody Sat May 18 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612978479; cv=none; d=zohomail.com; s=zohoarc; b=Fc8/0TgXc+xbcQhpoPFC4QmlLk6JeDFD3jQNcwKlSOJf1wErZMvVk12tZk5d4WEOUS8QTuI0l9JEfHbk/NkGM7NVtgSA1OrzegUw5S8Xj05Hn7OSOTo+jzSfRgWZxQw1cSjsIYbS0UmWzda4hXPgtUm1QvvqCpQIrpqg+F1d4fs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612978479; 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=h0QvmjX98VbM0hJDAiWjHMsOGh3uS/mkzUm9fqxf+c0=; b=eY4F6o/YJ7Q93Tsl0Vpm8Bnjd/jcnq1fd6TC1Q88bvy12GXueHd9Cj1s/a4Bedc0a/SdhRC1wueevGi6TqNq07H5SP5DXl/pGLtDmcJqjupf0N5q+HGTe6EWREgSaIsaqeAQoht1Klk6Amin1IrMSgGTODRWSyaQ4GBQyIHIpc8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612978479286246.19421732904038; Wed, 10 Feb 2021 09:34:39 -0800 (PST) Received: from localhost ([::1]:45974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9szQ-0003Fh-PR for importer@patchew.org; Wed, 10 Feb 2021 12:09:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYZ-0007QL-Dj for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26955) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sYP-0008VZ-UM for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:35 -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-170-RRSRKQTXMtaCXFBI-2uPXQ-1; Wed, 10 Feb 2021 11:41:23 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B040801962 for ; Wed, 10 Feb 2021 16:41:22 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 972D25D9D0; Wed, 10 Feb 2021 16:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975284; 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=h0QvmjX98VbM0hJDAiWjHMsOGh3uS/mkzUm9fqxf+c0=; b=OgLG29xca1go4UsZbnkJ6znB1xGYKF8bwq4oj7SqssckipNFtnMrLT1G+xu80KBzFGvJ7/ f1PE5sTm4xWrnwoZY8xYrk2dJepFKUQJ9JPuv8uPAqFcMZbzlNq6UVHOfx82Dx3X+Tlw46 Vblmy4Aldle2lnDgA1TwBar/9uR/fYo= X-MC-Unique: RRSRKQTXMtaCXFBI-2uPXQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 19/21] i386: introduce kvm_hv_evmcs_available() Date: Wed, 10 Feb 2021 17:40:31 +0100 Message-Id: <20210210164033.607612-20-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Enlightened VMCS feature is hardware specific, it is only supported on Intel CPUs. Introduce a simple kvm_hv_evmcs_available() helper, it will be used to filter out 'hv_evmcs' when 'hyperv=3Don' option is added to X86MachineClass. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm-stub.c | 5 +++++ target/i386/kvm/kvm.c | 8 ++++++++ target/i386/kvm/kvm_i386.h | 1 + 3 files changed, 14 insertions(+) diff --git a/target/i386/kvm/kvm-stub.c b/target/i386/kvm/kvm-stub.c index 7f175faa3abd..4e486f41a60a 100644 --- a/target/i386/kvm/kvm-stub.c +++ b/target/i386/kvm/kvm-stub.c @@ -44,3 +44,8 @@ void kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) { return; } + +bool kvm_hv_evmcs_available(void) +{ + return false; +} diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 480908b2463a..6c26b2091d4a 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -96,6 +96,7 @@ static bool has_msr_hv_crash; static bool has_msr_hv_reset; static bool has_msr_hv_vpindex; static bool hv_vpindex_settable; +static bool hv_evmcs_available; static bool has_msr_hv_runtime; static bool has_msr_hv_synic; static bool has_msr_hv_stimer; @@ -195,6 +196,11 @@ bool kvm_hv_vpindex_settable(void) return hv_vpindex_settable; } =20 +bool kvm_hv_evmcs_available(void) +{ + return hv_evmcs_available; +} + static int kvm_get_tsc(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); @@ -2235,6 +2241,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) has_pit_state2 =3D kvm_check_extension(s, KVM_CAP_PIT_STATE2); =20 hv_vpindex_settable =3D kvm_check_extension(s, KVM_CAP_HYPERV_VP_INDEX= ); + hv_evmcs_available =3D + kvm_check_extension(s, KVM_CAP_HYPERV_ENLIGHTENED_VMCS); =20 has_exception_payload =3D kvm_check_extension(s, KVM_CAP_EXCEPTION_PAY= LOAD); if (has_exception_payload) { diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index f1176491051d..0fa00511be27 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -48,6 +48,7 @@ bool kvm_has_waitpkg(void); =20 bool kvm_hv_vpindex_settable(void); void kvm_hyperv_expand_features(X86CPU *cpu, Error **errp); +bool kvm_hv_evmcs_available(void); =20 uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address); =20 --=20 2.29.2 From nobody Sat May 18 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612976493; cv=none; d=zohomail.com; s=zohoarc; b=SbiWGhwL0Ju3V49VZV7nEfA7JFHFPpPzCpSU4stOd4bAJAOdKc9xC3DMWO+AYWSesdH4ERiSaLoi2XemjVHkmPkygks+LFY3N5AMehjRb8y/5uNdryB7kB7tA1OAnq4AMaR8iWC8M92JqULK6kbl+qWBUgeNsCqLnfUfNBvYKRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612976493; 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=1+pMs6qYjHqm8UjfJLma0Z1tkMqnmcp9Y730qatau+c=; b=fe7pszQrwCtfTcKiDLIeikFOWiv/BxNnJ2WqzAuA9mskVMgC0CZu35Tz0tCzi9nKimxMffK/fvgZBTzHh2xOdOf0cuVJ3tb9yz+tfvrfGoLDgfepMFZ2TuovgFF/ptPYksjdunklPKlC5t9DarPEhtFoY0Q5/rCTsKdjgSV5AYY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612976492494159.88221209955134; Wed, 10 Feb 2021 09:01:32 -0800 (PST) Received: from localhost ([::1]:54122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9srp-0001JW-Qn for importer@patchew.org; Wed, 10 Feb 2021 12:01:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYZ-0007PZ-4c for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47670) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sYR-0008Vm-Io for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41: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-382-wEIEAY-oMN6TF2IxfcBEMQ-1; Wed, 10 Feb 2021 11:41:24 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 13343107ACE3 for ; Wed, 10 Feb 2021 16:41:24 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88CF25D9E8; Wed, 10 Feb 2021 16:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975286; 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=1+pMs6qYjHqm8UjfJLma0Z1tkMqnmcp9Y730qatau+c=; b=fTPsO7h0T96BzxBIzeGhF18hP8OgGEN7Q6yHOiiUl2fpkpB2MUEdeWSz/fcr2I0vdy4nt0 HTLIIbWkNmwaTcCfxEwGLhMKoZxmL/w8ziyIK89yTK+CS64KC9O7bmO76adkSfuvNXBfZQ MuEFl+xGBqfw0c90kw11wxKLYdKBsug= X-MC-Unique: wEIEAY-oMN6TF2IxfcBEMQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 20/21] i386: provide simple 'hv-default=on' option Date: Wed, 10 Feb 2021 17:40:32 +0100 Message-Id: <20210210164033.607612-21-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 | 16 ++++++++++++--- target/i386/cpu.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ target/i386/cpu.h | 3 +++ 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index 5df00da54fc4..a54c066cab09 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -17,10 +17,20 @@ 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: +All currently supported Hyper-V enlightenments can be enabled by specifying +'hv-default=3Don' 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 f8df2caed779..013aa60272d8 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4736,6 +4736,12 @@ static void x86_hv_passthrough_set(Object *obj, bool= value, Error **errp) { X86CPU *cpu =3D X86_CPU(obj); =20 + if (cpu->hyperv_default) { + error_setg(errp, + "'hv-default' and 'hv-paththrough' are mutually exclusi= ve"); + return; + } + cpu->hyperv_passthrough =3D value; =20 /* hv-passthrough overrides everything with what's supported by the ho= st */ @@ -4748,6 +4754,33 @@ static void x86_hv_passthrough_set(Object *obj, bool= value, Error **errp) return; } =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); + + if (cpu->hyperv_passthrough) { + error_setg(errp, + "'hv-default' and 'hv-paththrough' are mutually exclusi= ve"); + return; + } + + cpu->hyperv_default =3D value; + + /* hv-default overrides everything with the default set */ + if (value) { + cpu->hyperv_features =3D cpu->hyperv_default_features; + cpu->hyperv_features_on =3D 0; + cpu->hyperv_features_off =3D 0; + } +} + /* 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, @@ -7152,6 +7185,21 @@ 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' */ + 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); + + /* Enlightened VMCS is only available on Intel/VMX */ + if (kvm_hv_evmcs_available()) { + cpu->hyperv_default_features |=3D BIT(HYPERV_FEAT_EVMCS); + } } =20 static int64_t x86_cpu_get_arch_id(CPUState *cs) @@ -7486,6 +7534,10 @@ static void x86_cpu_common_class_init(ObjectClass *o= c, void *data) x86_hv_passthrough_get, x86_hv_passthrough_set); =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 b4fbd46f0fc9..59350e70fb51 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1670,6 +1670,9 @@ struct X86CPU { uint64_t hyperv_features_on; uint64_t hyperv_features_off; 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 18:13:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612976160; cv=none; d=zohomail.com; s=zohoarc; b=UTN4rbfRL6nezy1O1ttDfwLTGLNti8pruYjXmOvxDIQJvEr5XwLqx0ks090pDgHI6EirlAg9FrJlevqPzV5LVeihyowb2z82pkqRvX7LZwnM5zc8kVChy/OQquq8uFCCFIpPYFgJHnORUP20mlCZ4psQ/OeSq8L5Gz6tcA8hCy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612976160; 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=ChhryVByy9XFedwMozwGyNdQifIOUoAwDcNzqIvgGRE=; b=GE8bANcLnMkScXEbXoQIOo1iSOqcty6ri2SKWe/7eGnw2O0pUo7rRWA+Iux1bosXyWFBn4U2bXk1CgLQnVfECzRfEi/iRmv3m5E2ELRq88F+E/7zsz6tsMAoqFg/J6ZteAg5uEa5LTJhvU7ZvNypyMk57lFOFRIfs6S44qBGx14= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 1612976159925559.416781709579; Wed, 10 Feb 2021 08:55:59 -0800 (PST) Received: from localhost ([::1]:43236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9smU-0004bX-R2 for importer@patchew.org; Wed, 10 Feb 2021 11:55:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9sYX-0007Ls-2p for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9sYU-0008WE-Jg for qemu-devel@nongnu.org; Wed, 10 Feb 2021 11:41:32 -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-365-sD5ovckCM1-bQkmGtXRcww-1; Wed, 10 Feb 2021 11:41:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FEBE107ACE3 for ; Wed, 10 Feb 2021 16:41:26 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B6BC5D9E3; Wed, 10 Feb 2021 16:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612975289; 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=ChhryVByy9XFedwMozwGyNdQifIOUoAwDcNzqIvgGRE=; b=hrtICxm8qvnbXl9ZAXFwMYuBWyUn7g/0wEqAhrZz0GWuZdZszJSq/J1tQOujpnlenpYYNM wcz0X3tDZJ2cPlG+vw/2BnxuuCNwCbAezdugDRg562UmqRCvJlimOxUV7zv2wfYe8rMi+0 Aggc5fPpy5dKwMZOHAgBlS4loxeyqrA= X-MC-Unique: sD5ovckCM1-bQkmGtXRcww-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v4 21/21] qtest/hyperv: Introduce a simple hyper-v test Date: Wed, 10 Feb 2021 17:40:33 +0100 Message-Id: <20210210164033.607612-22-vkuznets@redhat.com> In-Reply-To: <20210210164033.607612-1-vkuznets@redhat.com> References: <20210210164033.607612-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, 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 , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) 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 | 312 ++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 3 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/hyperv-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 06635ba81a2c..0488e74473cc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1505,6 +1505,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..dd2b30aa71af --- /dev/null +++ b/tests/qtest/hyperv-test.c @@ -0,0 +1,312 @@ +/* + * 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_assert_hyperv_all(QTestState *qts) +{ + QDict *resp; + + 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"); + } +} + +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(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; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-passthrough"); + if (!kvm_enabled(qts)) { + qtest_quit(qts); + return; + } + + test_assert_hyperv_all(qts); + + qtest_quit(qts); +} + +static void test_query_cpu_hv_passthrough_minus(const void *data) +{ + QTestState *qts; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-passthrough,hv_tlbflush= =3Doff"); + if (!kvm_enabled(qts)) { + qtest_quit(qts); + return; + } + + assert_has_feature_enabled(qts, "host", "hv-vpindex"); + assert_has_feature_disabled(qts, "host", "hv-tlbflush"); + + 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); +} + +static void test_query_cpu_hv_evmcs_novmx_passthrough(const void *data) +{ + QTestState *qts; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,-vmx,hv-passthrough"); + 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-passthrough-minus", + NULL, test_query_cpu_hv_passthrough_minus); + qtest_add_data_func("/hyperv/hv-evmcs-novmx-default", NULL, + test_query_cpu_hv_evmcs_novmx_default); + qtest_add_data_func("/hyperv/hv-evmcs-novmx-passthrough", NULL, + test_query_cpu_hv_evmcs_novmx_passthrough); + } + } + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c83bc211b6a6..13dd65a8bf3f 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