From nobody Sat May 4 16:05:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622721009; cv=none; d=zohomail.com; s=zohoarc; b=KXaHu6ugnypnnDNfynZ9TnqKXc0507Gpvicmt3tkeBKDchgW3h5dUqzsBLbE5DArhQG8iCefpCm1P1vWR0xYvaBljqg68OEWhHsJt7Js/RmjVCv1HeNXKuP0lKJOCLfAIVax4YVSvOXJLx+XCKp+YetL2Xq95fWbpSCe6mM0gok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622721009; 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=Y9z+D1lI4IVrYvvo11z5Q83r0R8VCoLW7BD2OfYfE8c=; b=E9AC0bqYNfvM+RICjrRjBFWFtoDniQIUFRcW7naCVOoC7mJ6xWh/asq8OqoSexiZ0EbI/s9moTzxmWY1aPz2VNLUf5s31tmtI8Tc+8CZLxs7BQF3c1whAHh9kxaC9N0+s0pNaRTsE5ZSXI9A2VENfDf9XlY87eWr56EosjwuETc= 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+importer2=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 1622721009487608.4078492726366; Thu, 3 Jun 2021 04:50:09 -0700 (PDT) Received: from localhost ([::1]:49526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lolrU-0007DN-E5 for importer2@patchew.org; Thu, 03 Jun 2021 07:50:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqA-0004ov-3r for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60120) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolq8-00020H-3t for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:45 -0400 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-128-YrrbEhFvPLedQBoSr3CCwA-1; Thu, 03 Jun 2021 07:48:41 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E13D107ACC7 for ; Thu, 3 Jun 2021 11:48:41 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F6921A868; Thu, 3 Jun 2021 11:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720923; 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=Y9z+D1lI4IVrYvvo11z5Q83r0R8VCoLW7BD2OfYfE8c=; b=U6FJKd7s3aLnj234JG4NBQbyp6hZmXAqCC+u0BBMsd4aH79+DsMafpMXE5BF+YiBQQpmVb +pGhZIe4BaCW64uxJx3IXprhOBxLWEexxe178n+whdit2JSVBHS5SFfhfCSdazct4Lj4d4 uc4iRu/usn1rpkvNmVGs3HB8Af7IJ/Y= X-MC-Unique: YrrbEhFvPLedQBoSr3CCwA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v7 1/9] i386: avoid hardcoding '12' as 'hyperv_vendor_id' length Date: Thu, 3 Jun 2021 13:48:27 +0200 Message-Id: <20210603114835.847451-2-vkuznets@redhat.com> In-Reply-To: <20210603114835.847451-1-vkuznets@redhat.com> References: <20210603114835.847451-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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+importer2=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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.37, 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" While this is very unlikely to change, let's avoid hardcoding '12' as 'hyperv_vendor_id' length. No functional change intended. Signed-off-by: Vitaly Kuznetsov Reviewed-by: Eduardo Habkost --- target/i386/cpu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index fa282a07013f..b2d8e5713911 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6057,11 +6057,12 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu) &error_abort); } len =3D strlen(cpu->hyperv_vendor); - if (len > 12) { - warn_report("hv-vendor-id truncated to 12 characters"); - len =3D 12; + if (len > sizeof(cpu->hyperv_vendor_id)) { + warn_report("hv-vendor-id truncated to %ld characters", + sizeof(cpu->hyperv_vendor_id)); + len =3D sizeof(cpu->hyperv_vendor_id); } - memset(cpu->hyperv_vendor_id, 0, 12); + memset(cpu->hyperv_vendor_id, 0, sizeof(cpu->hyperv_vendor_id)); memcpy(cpu->hyperv_vendor_id, cpu->hyperv_vendor, len); =20 /* 'Hv#1' interface identification*/ --=20 2.31.1 From nobody Sat May 4 16:05:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622721111; cv=none; d=zohomail.com; s=zohoarc; b=bFQUxt4Pkj+qTGDlAsMxca9UEVLDU83+Em63LJT/aGEvmQt3pwsobHv2MhZ8ZWLSPqpy4BPQGP59hRpp0LF8eeGZzh4W8+9wgQwrhvxCC3GYfXqWrXqJB7e9TCQjcMEgSr/XXXY7ThnhsGpdyWK9s8L8CTXJYIWUctp96XoksQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622721111; 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=3QCY58JX8hnn40e/d2Qq11GOt2O++6pCaxA+8FKsrUs=; b=RmjZ+O6oHVGKRhWTQZk39IKPtxvMh6VkbZJvaW7AOllTe0eRQcE94R2ktxTtIbNGgbxYVPnaF5B8MQJ+lrLadZoxf6/MZzbCuyWZd85AQFCUj9kreqbdLBIwpW9yWwHPSf+doWZBVeLglOBemlpyuKpc0szwB/HC2UzJlPDzkkw= 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+importer2=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 1622721111621681.758650906418; Thu, 3 Jun 2021 04:51:51 -0700 (PDT) Received: from localhost ([::1]:56626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lolt8-0003aN-F4 for importer2@patchew.org; Thu, 03 Jun 2021 07:51:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqC-0004qa-U5 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60706) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolq9-00021Z-T0 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:48 -0400 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-454-oDx5cUpLN-Ke9lP9xY6Uvw-1; Thu, 03 Jun 2021 07:48:43 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1935E6A2B2 for ; Thu, 3 Jun 2021 11:48:43 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E8F319704; Thu, 3 Jun 2021 11:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720925; 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=3QCY58JX8hnn40e/d2Qq11GOt2O++6pCaxA+8FKsrUs=; b=Siaad9xbBdKLGgCBxyv1wlIFyobE6r8q5fCUkR8NyEDj5Nny8Av0DX1p/YY1avVbs6Z8N2 6nfB8clr7//ZqH9AEoostNp7RktizuUymfZejgabnjK1AydyVFIL7p2fqEoPbJq+AX2rvJ bRbRDBkNWo1wED3dHJ7lo/h9PPXGt30= X-MC-Unique: oDx5cUpLN-Ke9lP9xY6Uvw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v7 2/9] i386: clarify 'hv-passthrough' behavior Date: Thu, 3 Jun 2021 13:48:28 +0200 Message-Id: <20210603114835.847451-3-vkuznets@redhat.com> In-Reply-To: <20210603114835.847451-1-vkuznets@redhat.com> References: <20210603114835.847451-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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+importer2=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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.37, 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Clarify the fact that 'hv-passthrough' only enables features which are already known to QEMU and that it overrides all other 'hv-*' settings. Signed-off-by: Vitaly Kuznetsov Reviewed-by: Eduardo Habkost --- docs/hyperv.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index e53c581f4586..a51953daa833 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -209,8 +209,11 @@ In some cases (e.g. during development) it may make se= nse to use QEMU in 'pass-through' mode and give Windows guests all enlightenments currently supported by KVM. This pass-through mode is enabled by "hv-passthrough" CPU flag. -Note: enabling this flag effectively prevents migration as supported featu= res -may differ between target and destination. +Note: "hv-passthrough" flag only enables enlightenments which are known to= QEMU +(have corresponding "hv-*" flag) and copies "hv-spinlocks=3D"/"hv-vendor-i= d=3D" +values from KVM to QEMU. "hv-passthrough" overrides all other "hv-*" setti= ngs on +the command line. Also, enabling this flag effectively prevents migration = as the +list of enabled enlightenments may differ between target and destination h= osts. =20 =20 4. Useful links --=20 2.31.1 From nobody Sat May 4 16:05:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622721208; cv=none; d=zohomail.com; s=zohoarc; b=H8TvcBCqJ9EygMFIUJM0a5mzh9qw5Ry7K4k+OZan5z/oYAOtcuRZBtDxjGMD/EJRXLr3G0sY+ttDykwj+Hig8r3G4GQlQ4YAmEPF08wvVeySYOyyW/EPYh6DgQN4Ns7wlZPPsKACvhlLd7ub2Lg4O8jO6pTjb2Ou5CM60Sfj0AI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622721208; 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=xL+X0F0Ai06zrlvOnlOoPjnfjRWpxoxzgv6QaQOdKBQ=; b=am33P1Fd+NzngPwIdZR8/LnLGGxguDdW1OR/tyuQnjpzDpdjO55Tqjgkv/kCLR5W83MDb6bC/gTF8ATpFYiVYJRkSO3hNaUELYDzBLQZpfms3qFif9SxSqMcSku7tcHJAHMKgHndDdNBiCmkBb2Ls0gSs3U9Qo92kMhXNHZlEP0= 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+importer2=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 1622721208622502.1835942546011; Thu, 3 Jun 2021 04:53:28 -0700 (PDT) Received: from localhost ([::1]:34556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1loluh-0007jD-LV for importer2@patchew.org; Thu, 03 Jun 2021 07:53:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqD-0004s1-Ky for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqB-00022o-Qx for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:49 -0400 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-256-H5CnCdZuO1uEuLd3EkXWeQ-1; Thu, 03 Jun 2021 07:48:45 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 136DC8015F5 for ; Thu, 3 Jun 2021 11:48:45 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D6EF17A75; Thu, 3 Jun 2021 11:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720927; 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=xL+X0F0Ai06zrlvOnlOoPjnfjRWpxoxzgv6QaQOdKBQ=; b=ZZIOUTj4+M67KAdJXQTtw5pzR9LrLmhTLgu1QI7RaY/THQfScqt6RTV8+h/z7cC0+Ri37k /29A7qkTvlRZrROulXrnhJu7U4l+RIr5IaCfCw3l9W2IMPe78q1/jojt4roCYLW7GQvXFl 2nwdC04t2a66gyJGvvY02ng/9EFGWrw= X-MC-Unique: H5CnCdZuO1uEuLd3EkXWeQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v7 3/9] i386: hardcode supported eVMCS version to '1' Date: Thu, 3 Jun 2021 13:48:29 +0200 Message-Id: <20210603114835.847451-4-vkuznets@redhat.com> In-Reply-To: <20210603114835.847451-1-vkuznets@redhat.com> References: <20210603114835.847451-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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+importer2=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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.37, 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Currently, the only eVMCS version, supported by KVM (and described in TLFS) is '1'. When Enlightened VMCS feature is enabled, QEMU takes the supported eVMCS version range (from KVM_CAP_HYPERV_ENLIGHTENED_VMCS enablement) and puts it to guest visible CPUIDs. When (and if) eVMCS ver.2 appears a problem on migration is expected: it doesn't seem to be possible to migrate from a host supporting eVMCS ver.2 to a host, which only support eVMCS ver.1. Hardcode eVMCS ver.1 as the result of 'hv-evmcs' enablement for now. Newer eVMCS versions will have to have their own enablement options (e.g. 'hv-evmcs=3D2'). Signed-off-by: Vitaly Kuznetsov --- docs/hyperv.txt | 2 +- target/i386/kvm/kvm.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index a51953daa833..000638a2fd38 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -170,7 +170,7 @@ Recommended: hv-frequencies 3.16. hv-evmcs =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The enlightenment is nested specific, it targets Hyper-V on KVM guests. Wh= en -enabled, it provides Enlightened VMCS feature to the guest. The feature +enabled, it provides Enlightened VMCS version 1 feature to the guest. The = feature implements paravirtualized protocol between L0 (KVM) and L1 (Hyper-V) hypervisors making L2 exits to the hypervisor faster. The feature is Intel= -only. Note: some virtualization features (e.g. Posted Interrupts) are disabled w= hen diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index c676ee8b38a7..d57eede5dc81 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1490,13 +1490,19 @@ static int hyperv_init_vcpu(X86CPU *cpu) ret =3D kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, (uintptr_t)&evmcs_version); =20 - if (ret < 0) { - fprintf(stderr, "Hyper-V %s is not supported by kernel\n", - kvm_hyperv_properties[HYPERV_FEAT_EVMCS].desc); + /* + * KVM is required to support EVMCS ver.1. as that's what 'hv-evmc= s' + * option sets. Note: we hardcode the maximum supported eVMCS vers= ion + * to '1' as well so 'hv-evmcs' feature is migratable even when (a= nd if) + * ver.2 is implemented. A new option (e.g. 'hv-evmcs=3D2') will t= hen have + * to be added. + */ + if (ret < 0 || (uint8_t)evmcs_version > 1) { + error_report("Hyper-V %s verson 1 is not supported by kernel", + kvm_hyperv_properties[HYPERV_FEAT_EVMCS].desc); return ret; } - - cpu->hyperv_nested[0] =3D evmcs_version; + cpu->hyperv_nested[0] =3D (1 << 8) | 1; } =20 return 0; --=20 2.31.1 From nobody Sat May 4 16:05:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622721028; cv=none; d=zohomail.com; s=zohoarc; b=A5Uw11tsYieM/bzt6MLqi6HxC2txPSwYOoVRltE5bp+RGPioCk1qbfftwHsniuQZpbeCk9KuUitwWrgxt7+UAKcxUvfCWbn/wgtfwGwUsFGricpA+9Ffi6Y6EF8jIca/8Vye0huFpzAJ4mlKerMhBn7hbUFUaXBp5QkNpBJa8g8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622721028; 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=YqblTZYk+hZsky9NIxgGLm7Qg1ty1pGjUIIGwAwCcRM=; b=TSveoCZG8bmcjhvom+ar3SGYkJZE45M8okrrX/Im+ARhYM1zFa8o+45upwUXigeBu8hGthtMURV6En+/ZdCv2Hl7ZYMXAo5bD+KTo4zYqV7xrgDW3G2qfXvpl9Au1Smrrjmy9E4CXlJhgIiLJbpBcOsbF8jkRCxmI4/dt6V7Q1I= 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+importer2=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 1622721028809460.1219710168235; Thu, 3 Jun 2021 04:50:28 -0700 (PDT) Received: from localhost ([::1]:50058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lolrm-0007aJ-KH for importer2@patchew.org; Thu, 03 Jun 2021 07:50:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqG-0004yy-0e for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqE-00024H-AN for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:51 -0400 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-508-aFfUcJt2MAWO6grRvxJj_A-1; Thu, 03 Jun 2021 07:48:47 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D321800D55 for ; Thu, 3 Jun 2021 11:48:47 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D73A19704; Thu, 3 Jun 2021 11:48:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720929; 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=YqblTZYk+hZsky9NIxgGLm7Qg1ty1pGjUIIGwAwCcRM=; b=Sl3GkISREysq0avnexONOa1JT4tuoC46U6oSsBAlOyKAfLTXgNGRC6xurxidAUT/eR5q2r JLInUEODR1svbLvjtRZx/+F1EHglI8LdnD+RGvOK+/FTWGHDpK/EZh+1zozzXU2i/e1UdG my+tIUZvPlAj7eewFH1qGLHto5T7Dfw= X-MC-Unique: aFfUcJt2MAWO6grRvxJj_A-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v7 4/9] i386: make hyperv_expand_features() return bool Date: Thu, 3 Jun 2021 13:48:30 +0200 Message-Id: <20210603114835.847451-5-vkuznets@redhat.com> In-Reply-To: <20210603114835.847451-1-vkuznets@redhat.com> References: <20210603114835.847451-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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+importer2=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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.37, 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Return 'false' when hyperv_expand_features() sets an error. No functional change intended. Signed-off-by: Vitaly Kuznetsov Reviewed-by: Eduardo Habkost --- target/i386/kvm/kvm.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index d57eede5dc81..a5f8553af921 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1217,12 +1217,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 void hyperv_expand_features(CPUState *cs, Error **errp) +static bool hyperv_expand_features(CPUState *cs, Error **errp) { X86CPU *cpu =3D X86_CPU(cs); =20 if (!hyperv_enabled(cpu)) - return; + return true; =20 if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D @@ -1270,49 +1270,49 @@ static void hyperv_expand_features(CPUState *cs, Er= ror **errp) =20 /* Features */ if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI, errp)) { - return; + return false; } if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT, errp)) { - return; + return false; } =20 /* Additional dependencies not covered by kvm_hyperv_properties[] */ @@ -1322,7 +1322,10 @@ static void hyperv_expand_features(CPUState *cs, Err= or **errp) 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 false; } + + return true; } =20 /* @@ -1563,8 +1566,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); - if (local_err) { + if (!hyperv_expand_features(cs, &local_err)) { error_report_err(local_err); return -ENOSYS; } --=20 2.31.1 From nobody Sat May 4 16:05:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622721111; cv=none; d=zohomail.com; s=zohoarc; b=BK/iD9jtQ9GrhHbWteyDiN9P+eRLm1GDHjICH5dhNzqFJ67pj+YaTQzxerrWr/bvVirr3CGqWrxRhX5vGPTiL8a0NPj5r7wONYU6MLmjxihyD1fd3n+19xZFLpVoTv6FmR6MXhTr1NDw9DGU/nB/v9U87fDI1dTRdmLawqBSWAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622721111; 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=34qKPvNzu1oFZe/knosJ1iPvRUUAV4SkRvnh5ZZbcUs=; b=ksh72gq95WweejsUpU0ze0B+e2CWxRSxksZQRPXfIcEKpMy2dbuaKOjsXO6qpKI2tSx66JcugxDkzcqx1UiU6XPouLqd0rgBmELg6kqxBInu69JRFPumoaE8fA0JTBrc+OT4EwIYmAkS099KNjrtpXlgInLEqWfHaRcNqF5P7EA= 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+importer2=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 1622721111630387.6015492554086; Thu, 3 Jun 2021 04:51:51 -0700 (PDT) Received: from localhost ([::1]:56622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lolt8-0003aE-HZ for importer2@patchew.org; Thu, 03 Jun 2021 07:51:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqK-0005Ee-7U for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52569) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqI-00026k-GU for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:56 -0400 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-284-zPjZAuE2Mmq8OtJ6fE_MvQ-1; Thu, 03 Jun 2021 07:48:52 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B9B06101372D for ; Thu, 3 Jun 2021 11:48:51 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7835B1A868; Thu, 3 Jun 2021 11:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720933; 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=34qKPvNzu1oFZe/knosJ1iPvRUUAV4SkRvnh5ZZbcUs=; b=WP53FlsTG6AEqspR+5/2qMXj73KFrNRQAdxs2W0tzvobPGph2RSqy7hnMoBQ0z6eIwauXs mBP/+YF+472/5mx8WqJO4jPaeeoh3iZPQ9CDz6cjwJs9FSVPeehCsQnI0YRXr36YFyxbU1 U27ZI462e11FBNNFVslvmCrtYazVu7I= X-MC-Unique: zPjZAuE2Mmq8OtJ6fE_MvQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v7 5/9] i386: expand Hyper-V features during CPU feature expansion time Date: Thu, 3 Jun 2021 13:48:31 +0200 Message-Id: <20210603114835.847451-6-vkuznets@redhat.com> In-Reply-To: <20210603114835.847451-1-vkuznets@redhat.com> References: <20210603114835.847451-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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+importer2=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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.37, 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+importer2=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 Reviewed-by: Eduardo Habkost --- target/i386/cpu.c | 4 ++++ target/i386/kvm/kvm-stub.c | 5 +++++ target/i386/kvm/kvm.c | 24 ++++++++++++++++++++---- target/i386/kvm/kvm_i386.h | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b2d8e5713911..159b7aa8f073 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5990,6 +5990,10 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **er= rp) 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..f6e7e4466e1a 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; } + +bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) +{ + abort(); +} diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index a5f8553af921..650fdd970d6e 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1217,13 +1217,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 bool hyperv_expand_features(CPUState *cs, Error **errp) +bool 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 true; =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 true; + if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EBX= ); @@ -1565,8 +1574,15 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 env->apic_bus_freq =3D KVM_APIC_BUS_FREQUENCY; =20 - /* Paravirtualization CPUIDs */ - if (!hyperv_expand_features(cs, &local_err)) { + /* + * kvm_hyperv_expand_features() is called here for the second time in = case + * KVM_CAP_SYS_HYPERV_CPUID is not supported. While we can't possibly = handle + * 'query-cpu-model-expansion' in this case as we don't have a KVM vCP= U to + * check which Hyper-V enlightenments are supported and which are not,= we + * can still proceed and check/expand Hyper-V enlightenments here so l= egacy + * behavior is preserved. + */ + if (!kvm_hyperv_expand_features(cpu, &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..54667b35f09c 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); +bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp); =20 uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address); =20 --=20 2.31.1 From nobody Sat May 4 16:05:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622721297; cv=none; d=zohomail.com; s=zohoarc; b=MY6Yz+mtVNaPdzkrTdjRD3pWYlKTB4IvX1Uu0IpN76m36WBMOT/m1shp99D5xIygRMxHD3M1JRlk63XbRxnFzECLBLdpf4AsZmIl2/sMEc3ozwWJna2HhaPyBd5h51xZZEO4yN5Yy/cii0+EqY606CNfoFHjHn2c+K+V1w4AiE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622721297; 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=pz2/710VPhARJiG6WmvfqdeuMcSC/SrTvFoQu6eAoJI=; b=HetuI1rhYahgYGRGKXN1MKj0QPCWhr5R3GaQ/ylp0lZMNF3/4pT/F3mA7W054ZZnLw3QNqBZx9MddHVmwXESlVVAc5Qwsz7cl6rRP+KhTqRpq9Ln/KonKQCb+A3wmtAHspWooLwFN9ofMqdc0l+d17V3Bg/3n8+8fVw+lWMquAs= 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+importer2=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 1622721297422329.7767816844182; Thu, 3 Jun 2021 04:54:57 -0700 (PDT) Received: from localhost ([::1]:39278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lolw7-0002b7-Gb for importer2@patchew.org; Thu, 03 Jun 2021 07:54:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqM-0005Mi-Ay for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34615) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqK-00028M-Gz for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:48:58 -0400 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-570-3AybSlHePPKI2OsjTqHwtw-1; Thu, 03 Jun 2021 07:48:54 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9A971013724 for ; Thu, 3 Jun 2021 11:48:53 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 264671A8A0; Thu, 3 Jun 2021 11:48:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720936; 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=pz2/710VPhARJiG6WmvfqdeuMcSC/SrTvFoQu6eAoJI=; b=CJLwP7gGqnTefU9T43Z7Rf/esrpSRQPTSDWe31+iripsLJHeu8HdjW+2OQdEmJoPItf2tm gx1Ym5U3ZKUUAhR4EUeGsHn5TjS9lRG0WP2f5hNAmbYrIP84Y/136vsbz6Dcr8MeID2hVS GVRB095s0v9EqCSFBpVwq8hJNFpZnrw= X-MC-Unique: 3AybSlHePPKI2OsjTqHwtw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v7 6/9] i386: kill off hv_cpuid_check_and_set() Date: Thu, 3 Jun 2021 13:48:32 +0200 Message-Id: <20210603114835.847451-7-vkuznets@redhat.com> In-Reply-To: <20210603114835.847451-1-vkuznets@redhat.com> References: <20210603114835.847451-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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+importer2=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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.37, 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" hv_cpuid_check_and_set() does too much: - Checks if the feature is supported by KVM; - Checks if all dependencies are enabled; - Sets the feature bit in cpu->hyperv_features for 'passthrough' mode. To reduce the complexity, move all the logic except for dependencies check out of it. Also, in 'passthrough' mode we don't really need to check dependencies because KVM is supposed to provide a consistent set anyway. Reviewed-by: Eduardo Habkost Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/kvm.c | 104 +++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 68 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 650fdd970d6e..93f9b5a457d5 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1145,16 +1145,12 @@ static bool hyperv_feature_supported(CPUState *cs, = int feature) return true; } =20 -static int hv_cpuid_check_and_set(CPUState *cs, int feature, Error **errp) +/* Checks that all feature dependencies are enabled */ +static bool hv_feature_check_deps(X86CPU *cpu, int feature, Error **errp) { - X86CPU *cpu =3D X86_CPU(cs); uint64_t deps; int dep_feat; =20 - if (!hyperv_feat_enabled(cpu, feature) && !cpu->hyperv_passthrough) { - return 0; - } - deps =3D kvm_hyperv_properties[feature].dependencies; while (deps) { dep_feat =3D ctz64(deps); @@ -1162,26 +1158,12 @@ static int hv_cpuid_check_and_set(CPUState *cs, int= feature, Error **errp) error_setg(errp, "Hyper-V %s requires Hyper-V %s", kvm_hyperv_properties[feature].desc, kvm_hyperv_properties[dep_feat].desc); - return 1; + return false; } deps &=3D ~(1ull << dep_feat); } =20 - if (!hyperv_feature_supported(cs, feature)) { - if (hyperv_feat_enabled(cpu, feature)) { - error_setg(errp, "Hyper-V %s is not supported by kernel", - kvm_hyperv_properties[feature].desc); - return 1; - } else { - return 0; - } - } - - if (cpu->hyperv_passthrough) { - cpu->hyperv_features |=3D BIT(feature); - } - - return 0; + return true; } =20 static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t func, int reg) @@ -1220,6 +1202,8 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, uin= t32_t func, int reg) bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) { CPUState *cs =3D CPU(cpu); + Error *local_err =3D NULL; + int feat; =20 if (!hyperv_enabled(cpu)) return true; @@ -1275,53 +1259,37 @@ bool kvm_hyperv_expand_features(X86CPU *cpu, Error = **errp) =20 cpu->hyperv_spinlock_attempts =3D hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EBX); - } =20 - /* Features */ - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI, errp)) { - return false; - } - if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT, errp)) { - return false; + /* + * Mark feature as enabled in 'cpu->hyperv_features' as + * hv_build_cpuid_leaf() uses this info to build guest CPUIDs. + */ + for (feat =3D 0; feat < ARRAY_SIZE(kvm_hyperv_properties); feat++)= { + if (hyperv_feature_supported(cs, feat)) { + cpu->hyperv_features |=3D BIT(feat); + } + } + } else { + /* Check features availability and dependencies */ + for (feat =3D 0; feat < ARRAY_SIZE(kvm_hyperv_properties); feat++)= { + /* If the feature was not requested skip it. */ + if (!hyperv_feat_enabled(cpu, feat)) { + continue; + } + + /* Check if the feature is supported by KVM */ + if (!hyperv_feature_supported(cs, feat)) { + error_setg(errp, "Hyper-V %s is not supported by kernel", + kvm_hyperv_properties[feat].desc); + return false; + } + + /* Check dependencies */ + if (!hv_feature_check_deps(cpu, feat, &local_err)) { + error_propagate(errp, local_err); + return false; + } + } } =20 /* Additional dependencies not covered by kvm_hyperv_properties[] */ --=20 2.31.1 From nobody Sat May 4 16:05:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622721048; cv=none; d=zohomail.com; s=zohoarc; b=DOoFbwgaFkl4kGofQjTCbCVGtZtuJ6Fh2Y9gN72G3DodEKHYHadIie6c0rwtfAb/qWAd8CL94q5nqpczojR5SXiDekBu1GMBXGrkpzqmZ/AmT+SPW8AzT1dAiOCZzVWEM7ydzv6aSrbe2t0OmY9WNNSABvNkeWnXnRt41IPSUS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622721048; 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=O5jFFxFei3pu3SlNpH6OKiipvIDwFG68UPcE4Ah0fFg=; b=bQqn5xq2G7+n3BxKEdvosgreqmO76MROjA/jGtxCYikyHM1+OHDynjCmdf1G+uW2QyMmZ+61JmB3DPS/KrviyyZQYpjYNLhlEIti8deKHbJ0f4kn9K+ER1w0I2HwmSy1rRb7HBS8xUdd8+pTwJwUv5on9E4LYjCU83fV3u/pODw= 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+importer2=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 1622721048972337.8321055771411; Thu, 3 Jun 2021 04:50:48 -0700 (PDT) Received: from localhost ([::1]:51182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lols7-0008KI-PK for importer2@patchew.org; Thu, 03 Jun 2021 07:50:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqO-0005UW-D6 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:49:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26094) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqM-00029N-LQ for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:49:00 -0400 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-370-vLsyURPwOJCPZk9STSAdSw-1; Thu, 03 Jun 2021 07:48:56 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6BBE1013727 for ; Thu, 3 Jun 2021 11:48:55 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 188841A868; Thu, 3 Jun 2021 11:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720938; 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=O5jFFxFei3pu3SlNpH6OKiipvIDwFG68UPcE4Ah0fFg=; b=hmugZn2WboOI7Pd2GOxLZuccIhaCTRPNzCugRD8CjHXYR5t8lpOVKw6BF+k0cyY5OOm1Q9 NiP1V3z3vExrCUuBnu9eFrfyfQFGm39YHuwBh2zGBB3V0+c9296G7tVl9mV98e0tihdHHD pU7UoqY1IHTC2lUmSGxnVoNdDnusI3o= X-MC-Unique: vLsyURPwOJCPZk9STSAdSw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v7 7/9] i386: HV_HYPERCALL_AVAILABLE privilege bit is always needed Date: Thu, 3 Jun 2021 13:48:33 +0200 Message-Id: <20210603114835.847451-8-vkuznets@redhat.com> In-Reply-To: <20210603114835.847451-1-vkuznets@redhat.com> References: <20210603114835.847451-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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+importer2=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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.37, 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" According to TLFS, Hyper-V guest is supposed to check HV_HYPERCALL_AVAILABLE privilege bit before accessing HV_X64_MSR_GUEST_OS_ID/HV_X64_MSR_HYPERCALL MSRs but at least some Windows versions ignore that. As KVM is very permissive and allows accessing these MSRs unconditionally, no issue is observed. We may, however, want to tighten the checks eventually. Conforming to the spec is probably also a good idea. Enable HV_HYPERCALL_AVAILABLE bit unconditionally. Signed-off-by: Vitaly Kuznetsov Reviewed-by: Eduardo Habkost --- target/i386/kvm/kvm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 93f9b5a457d5..a3897d4d8788 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -810,8 +810,6 @@ static struct { [HYPERV_FEAT_RELAXED] =3D { .desc =3D "relaxed timing (hv-relaxed)", .flags =3D { - {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, - .bits =3D HV_HYPERCALL_AVAILABLE}, {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_RELAXED_TIMING_RECOMMENDED} } @@ -820,7 +818,7 @@ static struct { .desc =3D "virtual APIC (hv-vapic)", .flags =3D { {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, - .bits =3D HV_HYPERCALL_AVAILABLE | HV_APIC_ACCESS_AVAILABLE}, + .bits =3D HV_APIC_ACCESS_AVAILABLE}, {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_APIC_ACCESS_RECOMMENDED} } @@ -829,8 +827,7 @@ static struct { .desc =3D "clocksources (hv-time)", .flags =3D { {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, - .bits =3D HV_HYPERCALL_AVAILABLE | HV_TIME_REF_COUNT_AVAILABL= E | - HV_REFERENCE_TSC_AVAILABLE} + .bits =3D HV_TIME_REF_COUNT_AVAILABLE | HV_REFERENCE_TSC_AVAI= LABLE} } }, [HYPERV_FEAT_CRASH] =3D { @@ -1343,6 +1340,9 @@ static int hyperv_fill_cpuids(CPUState *cs, 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 + /* Unconditionally required with any Hyper-V enlightenment */ + c->eax |=3D HV_HYPERCALL_AVAILABLE; + /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ c->edx |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE; =20 --=20 2.31.1 From nobody Sat May 4 16:05:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622721364; cv=none; d=zohomail.com; s=zohoarc; b=kM33zRy44DSwaly6WrhilqWWid8GhOGgUUYe+aucV/zgD5tGWZtApQY5AMbYB2X0hjUz5LD8xcAdO262kByR+hFJaUiJyBCk07aauLNhqGwZ5YKyQfAvnO4e3YaE+sg0R8Hrl3kvXbPxLlPbLNA99sPXM6/5Yayog3vEcLhDBXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622721364; 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=3+WeXJaJYzTaKvefMUC6ffYWX8vYTQP1Tl+XzsqOGQw=; b=kuHhOfMxAtUey8REEMgOF65xDviq1I/B/EWchC30Yb7Z0VprJS1Nkra3OJflSBUl3YYWB9+OK1KQLtiZJ7w+92Q1KrqwKcaVIzOhX/yzvTPaW/zyLPSK1MXu1dD7SpCKQ5cv2KIg5xYz0xHAMjyzj4FZ2rRoWdJpkXA5VYkaLK4= 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+importer2=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 1622721364650902.458351494912; Thu, 3 Jun 2021 04:56:04 -0700 (PDT) Received: from localhost ([::1]:42778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lolxD-00051n-Nt for importer2@patchew.org; Thu, 03 Jun 2021 07:56:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50548) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqP-0005Zb-Ot for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:49:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42865) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqO-0002Ah-76 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:49:01 -0400 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-602-NG7axeZdM8CnBX8huX0vwQ-1; Thu, 03 Jun 2021 07:48:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 86005180FD67 for ; Thu, 3 Jun 2021 11:48:57 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FB501A8A0; Thu, 3 Jun 2021 11:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720939; 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=3+WeXJaJYzTaKvefMUC6ffYWX8vYTQP1Tl+XzsqOGQw=; b=hoSA5EW2DHe8eoRyAGaaJz3BM1It93Vtw3eUut4SniDlSLMS+foTfPsdzCh7VY600iQe5K dPxpXr5z7UIM4vD7AOlBqm4qhFNowB1DSbibBtjWhtS9smSY2JVoqF626109y+YsIFTU9O OXv+vBpQfmXdqNKIDwkkfoLs5HTAKNw= X-MC-Unique: NG7axeZdM8CnBX8huX0vwQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v7 8/9] i386: Hyper-V SynIC requires POST_MESSAGES/SIGNAL_EVENTS priviliges Date: Thu, 3 Jun 2021 13:48:34 +0200 Message-Id: <20210603114835.847451-9-vkuznets@redhat.com> In-Reply-To: <20210603114835.847451-1-vkuznets@redhat.com> References: <20210603114835.847451-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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+importer2=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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.37, 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When Hyper-V SynIC is enabled, we may need to allow Windows guests to make hypercalls (POST_MESSAGES/SIGNAL_EVENTS). No issue is currently observed because KVM is very permissive, allowing these hypercalls regarding of guest visible CPUid bits. Signed-off-by: Vitaly Kuznetsov Reviewed-by: Eduardo Habkost --- target/i386/kvm/hyperv-proto.h | 6 ++++++ target/i386/kvm/kvm.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/target/i386/kvm/hyperv-proto.h b/target/i386/kvm/hyperv-proto.h index e30d64b4ade4..5fbb385cc136 100644 --- a/target/i386/kvm/hyperv-proto.h +++ b/target/i386/kvm/hyperv-proto.h @@ -38,6 +38,12 @@ #define HV_ACCESS_FREQUENCY_MSRS (1u << 11) #define HV_ACCESS_REENLIGHTENMENTS_CONTROL (1u << 13) =20 +/* + * HV_CPUID_FEATURES.EBX bits + */ +#define HV_POST_MESSAGES (1u << 4) +#define HV_SIGNAL_EVENTS (1u << 5) + /* * HV_CPUID_FEATURES.EDX bits */ diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index a3897d4d8788..6a32d43e6ec1 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1343,6 +1343,12 @@ static int hyperv_fill_cpuids(CPUState *cs, /* Unconditionally required with any Hyper-V enlightenment */ c->eax |=3D HV_HYPERCALL_AVAILABLE; =20 + /* SynIC and Vmbus devices require messages/signals hypercalls */ + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) && + !cpu->hyperv_synic_kvm_only) { + c->ebx |=3D HV_POST_MESSAGES | HV_SIGNAL_EVENTS; + } + /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ c->edx |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE; =20 --=20 2.31.1 From nobody Sat May 4 16:05:14 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622721221; cv=none; d=zohomail.com; s=zohoarc; b=XLrRGyI9d6vtrxTZ2YOKukQRn1oRlmQNPB06RrnDZw9P3zUmMpj7Oxq08mk9PCpjeWl2kYtpP0eii+1686PDCv3vjQgkfEyB1jg0LapbfbK8Yl8PSlZG80M0GUpB0Y+v/fpHrjwAWiTJLbKssUcUE/45spAYh1Z5SisqilIv0Bs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622721221; 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=zDmgG4X1saqa0QllHPrWBjVSN1wTsSb3zS1ZF7Gn6fg=; b=fRsOAhDe4N+As+nOYR0/Y5oK53JPCZqhZwy8MpBpf5Y6st2PADKt9WQ85kt0Msbc8YuLkzF2Ckzt3GQMr4H8+/CtDgztSwpWdxsalPTbVKIUIp+oQ8COdOdGppKRcfjNtxfjb/9xLNgbzO1GZmWWVddXAvZyvMYROqRQKG/o5dU= 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+importer2=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 1622721221445970.4718476216494; Thu, 3 Jun 2021 04:53:41 -0700 (PDT) Received: from localhost ([::1]:35176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1loluu-00088X-Dl for importer2@patchew.org; Thu, 03 Jun 2021 07:53:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqX-0005yU-Rs for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:49:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59703) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lolqS-0002Cv-NQ for qemu-devel@nongnu.org; Thu, 03 Jun 2021 07:49:09 -0400 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-201-rHXeZCXaOYWixOKwYbOCLQ-1; Thu, 03 Jun 2021 07:49:00 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 790026D249 for ; Thu, 3 Jun 2021 11:48:59 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0BEE1A868; Thu, 3 Jun 2021 11:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720944; 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=zDmgG4X1saqa0QllHPrWBjVSN1wTsSb3zS1ZF7Gn6fg=; b=PIXBTdzmE90kqoTfegftug4+9vu070YaXr8PRUH6Q3BLDh3xqETDAKM7A+KXFiaalaUhrM /MhlcTptiKRk5fqqrMGM+Vc0Z+H6gVu0MRyDBe7/zmTSwY4J57xsoxLTg4ALKBC/L2pOws RPDc4L/0cEYI0fTf6qf0F08MqxVcsaU= X-MC-Unique: rHXeZCXaOYWixOKwYbOCLQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Eduardo Habkost Subject: [PATCH v7 9/9] qtest/hyperv: Introduce a simple hyper-v test Date: Thu, 3 Jun 2021 13:48:35 +0200 Message-Id: <20210603114835.847451-10-vkuznets@redhat.com> In-Reply-To: <20210603114835.847451-1-vkuznets@redhat.com> References: <20210603114835.847451-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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+importer2=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: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.37, 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+importer2=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-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 | 225 ++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 3 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/hyperv-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 5f55404f2fae..862720016b3a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1537,6 +1537,7 @@ F: hw/isa/apm.c F: include/hw/isa/apm.h F: tests/unit/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..0be689548e18 --- /dev/null +++ b/tests/qtest/hyperv-test.c @@ -0,0 +1,225 @@ +/* + * Hyper-V emulation CPU feature test cases + * + * Copyright (c) 2021 Red Hat Inc. + * Authors: + * Vitaly Kuznetsov + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include +#include + +#include "qemu/osdep.h" +#include "qemu/bitops.h" +#include "libqos/libqtest.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" + +#define MACHINE_KVM "-machine pc-q35-5.2 -accel kvm " +#define QUERY_HEAD "{ 'execute': 'query-cpu-model-expansion', " \ + " 'arguments': { 'type': 'full', " +#define QUERY_TAIL "}}" + +static bool kvm_enabled(QTestState *qts) +{ + QDict *resp, *qdict; + bool enabled; + + resp =3D qtest_qmp(qts, "{ 'execute': 'query-kvm' }"); + g_assert(qdict_haskey(resp, "return")); + qdict =3D qdict_get_qdict(resp, "return"); + g_assert(qdict_haskey(qdict, "enabled")); + enabled =3D qdict_get_bool(qdict, "enabled"); + qobject_unref(resp); + + return enabled; +} + +static bool kvm_has_sys_hyperv_cpuid(void) +{ + int fd =3D open("/dev/kvm", O_RDWR); + int ret; + + g_assert(fd > 0); + + ret =3D ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_SYS_HYPERV_CPUID); + + close(fd); + + return ret > 0; +} + +static QDict *do_query_no_props(QTestState *qts, const char *cpu_type) +{ + return qtest_qmp(qts, QUERY_HEAD "'model': { 'name': %s }" + QUERY_TAIL, cpu_type); +} + +static bool resp_has_props(QDict *resp) +{ + QDict *qdict; + + g_assert(resp); + + if (!qdict_haskey(resp, "return")) { + return false; + } + qdict =3D qdict_get_qdict(resp, "return"); + + if (!qdict_haskey(qdict, "model")) { + return false; + } + qdict =3D qdict_get_qdict(qdict, "model"); + + return qdict_haskey(qdict, "props"); +} + +static QDict *resp_get_props(QDict *resp) +{ + QDict *qdict; + + g_assert(resp); + g_assert(resp_has_props(resp)); + + qdict =3D qdict_get_qdict(resp, "return"); + qdict =3D qdict_get_qdict(qdict, "model"); + qdict =3D qdict_get_qdict(qdict, "props"); + + return qdict; +} + +static bool resp_get_feature(QDict *resp, const char *feature) +{ + QDict *props; + + g_assert(resp); + g_assert(resp_has_props(resp)); + props =3D resp_get_props(resp); + g_assert(qdict_get(props, feature)); + return qdict_get_bool(props, feature); +} + +#define assert_has_feature(qts, cpu_type, feature) \ +({ \ + QDict *_resp =3D do_query_no_props(qts, cpu_type); \ + g_assert(_resp); \ + g_assert(resp_has_props(_resp)); \ + g_assert(qdict_get(resp_get_props(_resp), feature)); \ + qobject_unref(_resp); \ +}) + +#define resp_assert_feature(resp, feature, expected_value) \ +({ \ + QDict *_props; \ + \ + g_assert(_resp); \ + g_assert(resp_has_props(_resp)); \ + _props =3D resp_get_props(_resp); \ + g_assert(qdict_get(_props, feature)); \ + g_assert(qdict_get_bool(_props, feature) =3D=3D (expected_value)); = \ +}) + +#define assert_feature(qts, cpu_type, feature, expected_value) \ +({ \ + QDict *_resp; \ + \ + _resp =3D do_query_no_props(qts, cpu_type); \ + g_assert(_resp); \ + resp_assert_feature(_resp, feature, expected_value); \ + qobject_unref(_resp); \ +}) + +#define assert_has_feature_enabled(qts, cpu_type, feature) \ + assert_feature(qts, cpu_type, feature, true) + +#define assert_has_feature_disabled(qts, cpu_type, feature) \ + assert_feature(qts, cpu_type, feature, false) + +static void test_assert_hyperv_all_but_evmcs(QTestState *qts) +{ + assert_has_feature_enabled(qts, "host", "hv-relaxed"); + assert_has_feature_enabled(qts, "host", "hv-vapic"); + assert_has_feature_enabled(qts, "host", "hv-vpindex"); + assert_has_feature_enabled(qts, "host", "hv-runtime"); + assert_has_feature_enabled(qts, "host", "hv-crash"); + assert_has_feature_enabled(qts, "host", "hv-time"); + assert_has_feature_enabled(qts, "host", "hv-synic"); + assert_has_feature_enabled(qts, "host", "hv-stimer"); + assert_has_feature_enabled(qts, "host", "hv-tlbflush"); + assert_has_feature_enabled(qts, "host", "hv-ipi"); + assert_has_feature_enabled(qts, "host", "hv-reset"); + assert_has_feature_enabled(qts, "host", "hv-frequencies"); + assert_has_feature_enabled(qts, "host", "hv-reenlightenment"); + assert_has_feature_enabled(qts, "host", "hv-stimer-direct"); +} + +static void test_query_cpu_hv_all_but_evmcs(const void *data) +{ + QTestState *qts; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-relaxed,hv-vapic,hv-vpind= ex," + "hv-runtime,hv-crash,hv-time,hv-synic,hv-stimer," + "hv-tlbflush,hv-ipi,hv-reset,hv-frequencies," + "hv-reenlightenment,hv-stimer-direct"); + + test_assert_hyperv_all_but_evmcs(qts); + + qtest_quit(qts); +} + +static void test_query_cpu_hv_custom(const void *data) +{ + QTestState *qts; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-vpindex"); + + assert_has_feature_enabled(qts, "host", "hv-vpindex"); + assert_has_feature_disabled(qts, "host", "hv-synic"); + + qtest_quit(qts); +} + +static void test_query_cpu_hv_passthrough(const void *data) +{ + QTestState *qts; + QDict *resp; + + qts =3D qtest_init(MACHINE_KVM "-cpu host,hv-passthrough"); + if (!kvm_enabled(qts)) { + qtest_quit(qts); + return; + } + + test_assert_hyperv_all_but_evmcs(qts); + + resp =3D do_query_no_props(qts, "host"); + if (resp_get_feature(resp, "vmx")) { + assert_has_feature_enabled(qts, "host", "hv-evmcs"); + } else { + assert_has_feature_disabled(qts, "host", "hv-evmcs"); + } + + qtest_quit(qts); +} + +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-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); + } + } + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c3a223a83d6a..958a88d0c8b4 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -83,7 +83,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.31.1