From nobody Wed May 1 06:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507025411425104.96138870245181; Tue, 3 Oct 2017 03:10:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6AC04C059B64; Tue, 3 Oct 2017 10:10:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4519361F3D; Tue, 3 Oct 2017 10:10:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BAC0A18355C4; Tue, 3 Oct 2017 10:10:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v93957Yg011553 for ; Tue, 3 Oct 2017 05:05:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 47FBF60487; Tue, 3 Oct 2017 09:05:07 +0000 (UTC) Received: from dhcp-1-107.brq.redhat.com (ovpn-204-56.brq.redhat.com [10.40.204.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5A816046F for ; Tue, 3 Oct 2017 09:05:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6AC04C059B64 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Ladi Prosek To: libvir-list@redhat.com Date: Tue, 3 Oct 2017 11:04:56 +0200 Message-Id: <20171003090458.31130-2-lprosek@redhat.com> In-Reply-To: <20171003090458.31130-1-lprosek@redhat.com> References: <20171003090458.31130-1-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Tue, 03 Oct 2017 05:41:37 -0400 Subject: [libvirt] [PATCH 1/3] hyperv: Fix hypervInitConnection error reporting X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 03 Oct 2017 10:10:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" "%s is not a Hyper-V server" is not a correct generalization of all possible error conditions of hypervEnumAndPull. For example: $ virsh --connect hyperv://localhost/?transport=3Dhttp Enter username for localhost [administrator]: Enter administrator's password for localhost: error: failed to connect to the hypervisor error: internal error: localhost is not a Hyper-V server This commit fixes hypervEnumAndPull to set a meaningful internal error on a= ll error paths and removes the general virReportError. The same scenario with the fix: $ virsh --connect hyperv://localhost/?transport=3Dhttp Enter username for localhost [administrator]: Enter administrator's password for localhost: error: failed to connect to the hypervisor error: internal error: Transport error during enumeration: User, password= or similar was not accepted (26) Signed-off-by: Ladi Prosek --- src/hyperv/hyperv_driver.c | 2 -- src/hyperv/hyperv_wmi.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 09912610c..52274239c 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -105,8 +105,6 @@ hypervInitConnection(virConnectPtr conn, hypervPrivate = *priv, priv->wmiVersion =3D HYPERV_WMI_VERSION_V1; =20 if (hypervEnumAndPull(priv, &wqlQuery, &computerSystem) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("%s is not a Hyper-V server"), conn->uri->ser= ver); goto cleanup; } } diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 980a00e28..6a51eff20 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -985,6 +985,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPt= r wqlQuery, hypervObject *object; =20 if (virBufferCheckError(wqlQuery->query) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid query")); virBufferFreeAndReset(wqlQuery->query); return -1; } --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 06:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507025433184969.7057444291432; Tue, 3 Oct 2017 03:10:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF54D7E455; Tue, 3 Oct 2017 10:10:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9D3904DA0D; Tue, 3 Oct 2017 10:10:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4FB3B410B2; Tue, 3 Oct 2017 10:10:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v93958su011558 for ; Tue, 3 Oct 2017 05:05:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5544460487; Tue, 3 Oct 2017 09:05:08 +0000 (UTC) Received: from dhcp-1-107.brq.redhat.com (ovpn-204-56.brq.redhat.com [10.40.204.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BACB6046F for ; Tue, 3 Oct 2017 09:05:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BF54D7E455 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Ladi Prosek To: libvir-list@redhat.com Date: Tue, 3 Oct 2017 11:04:57 +0200 Message-Id: <20171003090458.31130-3-lprosek@redhat.com> In-Reply-To: <20171003090458.31130-1-lprosek@redhat.com> References: <20171003090458.31130-1-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Tue, 03 Oct 2017 05:41:37 -0400 Subject: [libvirt] [PATCH 2/3] hyperv: Escape WQL queries X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 03 Oct 2017 10:10:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The code was vulnerable to SQL injection. Likely not a security issue due to WMI SQL and other constraints but still lame. For example: virsh # dominfo \" error: failed to get domain '"' error: internal error: SOAP fault during enumeration: code 's:Sender', su= bcode 'n:CannotProcessFilter', reason 'The data source could not process the fi= lter. The filter might be missing or it might be invalid. Change the filter and= try the request again. ', detail 'The WS-Management service cannot process t= he request. The WQL query is invalid. ' This commit fixes the Hyper-V driver by escaping all WMI SQL string paramet= ers. The same command with the fix: virsh # dominfo \" error: failed to get domain '"' error: Domain not found: No domain with name " Signed-off-by: Ladi Prosek --- src/hyperv/hyperv_driver.c | 96 +++++++++++++++++++++++-------------------= ---- src/hyperv/hyperv_wmi.c | 2 +- src/util/virbuffer.c | 18 +++++++++ src/util/virbuffer.h | 3 ++ 4 files changed, 70 insertions(+), 49 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 52274239c..998780b80 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -302,12 +302,12 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr = info) } =20 /* Get Win32_Processor list */ - virBufferAsprintf(&query, - "associators of " - "{Win32_ComputerSystem.Name=3D\"%s\"} " - "where AssocClass =3D Win32_ComputerSystemProcessor " - "ResultClass =3D Win32_Processor", - computerSystem->data.common->Name); + virBufferEscapeSQL(&query, + "associators of " + "{Win32_ComputerSystem.Name=3D\"%s\"} " + "where AssocClass =3D Win32_ComputerSystemProcessor= " + "ResultClass =3D Win32_Processor", + computerSystem->data.common->Name); =20 if (hypervGetWin32ProcessorList(priv, &query, &processorList) < 0) goto cleanup; @@ -494,7 +494,7 @@ hypervDomainLookupByUUID(virConnectPtr conn, const unsi= gned char *uuid) virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_SELECT); virBufferAddLit(&query, "where "); virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_VIRTUAL); - virBufferAsprintf(&query, "and Name =3D \"%s\"", uuid_string); + virBufferEscapeSQL(&query, "and Name =3D \"%s\"", uuid_string); =20 if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) goto cleanup; @@ -526,7 +526,7 @@ hypervDomainLookupByName(virConnectPtr conn, const char= *name) virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_SELECT); virBufferAddLit(&query, "where "); virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_VIRTUAL); - virBufferAsprintf(&query, "and ElementName =3D \"%s\"", name); + virBufferEscapeSQL(&query, "and ElementName =3D \"%s\"", name); =20 if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) goto cleanup; @@ -674,13 +674,13 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInf= oPtr info) goto cleanup; =20 /* Get Msvm_VirtualSystemSettingData */ - virBufferAsprintf(&query, - "associators of " - "{Msvm_ComputerSystem.CreationClassName=3D\"Msvm_Com= puterSystem\"," - "Name=3D\"%s\"} " - "where AssocClass =3D Msvm_SettingsDefineState " - "ResultClass =3D Msvm_VirtualSystemSettingData", - uuid_string); + virBufferEscapeSQL(&query, + "associators of " + "{Msvm_ComputerSystem.CreationClassName=3D\"Msvm_Co= mputerSystem\"," + "Name=3D\"%s\"} " + "where AssocClass =3D Msvm_SettingsDefineState " + "ResultClass =3D Msvm_VirtualSystemSettingData", + uuid_string); =20 if (hypervGetMsvmVirtualSystemSettingDataList(priv, &query, &virtualSystemSettingDat= a) < 0) { @@ -696,12 +696,12 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInf= oPtr info) } =20 /* Get Msvm_ProcessorSettingData */ - virBufferAsprintf(&query, - "associators of " - "{Msvm_VirtualSystemSettingData.InstanceID=3D\"%s\"}= " - "where AssocClass =3D Msvm_VirtualSystemSettingDataC= omponent " - "ResultClass =3D Msvm_ProcessorSettingData", - virtualSystemSettingData->data.common->InstanceID); + virBufferEscapeSQL(&query, + "associators of " + "{Msvm_VirtualSystemSettingData.InstanceID=3D\"%s\"= } " + "where AssocClass =3D Msvm_VirtualSystemSettingData= Component " + "ResultClass =3D Msvm_ProcessorSettingData", + virtualSystemSettingData->data.common->InstanceID); =20 if (hypervGetMsvmProcessorSettingDataList(priv, &query, &processorSettingData) < 0) { @@ -717,12 +717,12 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInf= oPtr info) } =20 /* Get Msvm_MemorySettingData */ - virBufferAsprintf(&query, - "associators of " - "{Msvm_VirtualSystemSettingData.InstanceID=3D\"%s\"}= " - "where AssocClass =3D Msvm_VirtualSystemSettingDataC= omponent " - "ResultClass =3D Msvm_MemorySettingData", - virtualSystemSettingData->data.common->InstanceID); + virBufferEscapeSQL(&query, + "associators of " + "{Msvm_VirtualSystemSettingData.InstanceID=3D\"%s\"= } " + "where AssocClass =3D Msvm_VirtualSystemSettingData= Component " + "ResultClass =3D Msvm_MemorySettingData", + virtualSystemSettingData->data.common->InstanceID); =20 if (hypervGetMsvmMemorySettingDataList(priv, &query, &memorySettingData) < 0) { @@ -811,13 +811,13 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned = int flags) goto cleanup; =20 /* Get Msvm_VirtualSystemSettingData */ - virBufferAsprintf(&query, - "associators of " - "{Msvm_ComputerSystem.CreationClassName=3D\"Msvm_Com= puterSystem\"," - "Name=3D\"%s\"} " - "where AssocClass =3D Msvm_SettingsDefineState " - "ResultClass =3D Msvm_VirtualSystemSettingData", - uuid_string); + virBufferEscapeSQL(&query, + "associators of " + "{Msvm_ComputerSystem.CreationClassName=3D\"Msvm_Co= mputerSystem\"," + "Name=3D\"%s\"} " + "where AssocClass =3D Msvm_SettingsDefineState " + "ResultClass =3D Msvm_VirtualSystemSettingData", + uuid_string); =20 if (hypervGetMsvmVirtualSystemSettingDataList(priv, &query, &virtualSystemSettingDat= a) < 0) { @@ -833,12 +833,12 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned = int flags) } =20 /* Get Msvm_ProcessorSettingData */ - virBufferAsprintf(&query, - "associators of " - "{Msvm_VirtualSystemSettingData.InstanceID=3D\"%s\"}= " - "where AssocClass =3D Msvm_VirtualSystemSettingDataC= omponent " - "ResultClass =3D Msvm_ProcessorSettingData", - virtualSystemSettingData->data.common->InstanceID); + virBufferEscapeSQL(&query, + "associators of " + "{Msvm_VirtualSystemSettingData.InstanceID=3D\"%s\"= } " + "where AssocClass =3D Msvm_VirtualSystemSettingData= Component " + "ResultClass =3D Msvm_ProcessorSettingData", + virtualSystemSettingData->data.common->InstanceID); =20 if (hypervGetMsvmProcessorSettingDataList(priv, &query, &processorSettingData) < 0) { @@ -854,12 +854,12 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned = int flags) } =20 /* Get Msvm_MemorySettingData */ - virBufferAsprintf(&query, - "associators of " - "{Msvm_VirtualSystemSettingData.InstanceID=3D\"%s\"}= " - "where AssocClass =3D Msvm_VirtualSystemSettingDataC= omponent " - "ResultClass =3D Msvm_MemorySettingData", - virtualSystemSettingData->data.common->InstanceID); + virBufferEscapeSQL(&query, + "associators of " + "{Msvm_VirtualSystemSettingData.InstanceID=3D\"%s\"= } " + "where AssocClass =3D Msvm_VirtualSystemSettingData= Component " + "ResultClass =3D Msvm_MemorySettingData", + virtualSystemSettingData->data.common->InstanceID); =20 if (hypervGetMsvmMemorySettingDataList(priv, &query, &memorySettingData) < 0) { @@ -1398,7 +1398,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int= codeset, if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; =20 - virBufferAsprintf(&query, + virBufferEscapeSQL(&query, "associators of " "{Msvm_ComputerSystem.CreationClassName=3D\"Msvm_ComputerSyste= m\"," "Name=3D\"%s\"} " @@ -1535,7 +1535,7 @@ hypervDomainSetMemoryFlags(virDomainPtr domain, unsig= ned long memory, } =20 virBufferAddLit(&eprQuery, MSVM_COMPUTERSYSTEM_WQL_SELECT); - virBufferAsprintf(&eprQuery, "where Name =3D \"%s\"", uuid_string); + virBufferEscapeSQL(&eprQuery, "where Name =3D \"%s\"", uuid_string= ); =20 if (hypervAddEprParam(params, "ComputerSystem", priv, &eprQuery, Msvm_ComputerSystem_WmiInfo) < 0) diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 6a51eff20..21913f352 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -896,7 +896,7 @@ hypervInvokeMethod(hypervPrivate *priv, hypervInvokePar= amsListPtr params, */ while (!completed && timeout >=3D 0) { virBufferAddLit(&query, MSVM_CONCRETEJOB_WQL_SELECT); - virBufferAsprintf(&query, "where InstanceID =3D \"%s\"", insta= nceID); + virBufferEscapeSQL(&query, "where InstanceID =3D \"%s\"", inst= anceID); =20 if (hypervGetMsvmConcreteJobList(priv, &query, &job) < 0 || job =3D=3D NULL) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 28a291bb0..15f6e21fb 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -575,6 +575,24 @@ virBufferEscapeRegex(virBufferPtr buf, } =20 /** + * virBufferEscapeSQL: + * @buf: the buffer to append to + * @format: a printf like format string but with only one %s parameter + * @str: the string argument which needs to be escaped + * + * Do a formatted print with a single string to a buffer. The @str is + * escaped to prevent SQL injection (format is expected to contain \"%s\"). + * Auto indentation may be applied. + */ +void +virBufferEscapeSQL(virBufferPtr buf, + const char *format, + const char *str) +{ + virBufferEscape(buf, '\\', "'\"\\", format, str); +} + +/** * virBufferEscape: * @buf: the buffer to append to * @escape: the escape character to inject diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 3211c07b0..4f5ed162f 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -93,6 +93,9 @@ void virBufferEscapeSexpr(virBufferPtr buf, const char *f= ormat, void virBufferEscapeRegex(virBufferPtr buf, const char *format, const char *str); +void virBufferEscapeSQL(virBufferPtr buf, + const char *format, + const char *str); void virBufferEscapeShell(virBufferPtr buf, const char *str); void virBufferURIEncodeString(virBufferPtr buf, const char *str); =20 --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 06:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507025452433182.19287845085717; Tue, 3 Oct 2017 03:10:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8700681243; Tue, 3 Oct 2017 10:10:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 64B175C89D; Tue, 3 Oct 2017 10:10:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2317A18355C3; Tue, 3 Oct 2017 10:10:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v93959G1011563 for ; Tue, 3 Oct 2017 05:05:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 33D5D60487; Tue, 3 Oct 2017 09:05:09 +0000 (UTC) Received: from dhcp-1-107.brq.redhat.com (ovpn-204-56.brq.redhat.com [10.40.204.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7DF96046F for ; Tue, 3 Oct 2017 09:05:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8700681243 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Ladi Prosek To: libvir-list@redhat.com Date: Tue, 3 Oct 2017 11:04:58 +0200 Message-Id: <20171003090458.31130-4-lprosek@redhat.com> In-Reply-To: <20171003090458.31130-1-lprosek@redhat.com> References: <20171003090458.31130-1-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Tue, 03 Oct 2017 05:41:37 -0400 Subject: [libvirt] [PATCH 3/3] hyperv: Map Limit to max_memory and VirtualQuantity to cur_balloon X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 03 Oct 2017 10:10:51 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Hyper-V uses its own specific memory management so no mapping is going to be perfect. However, it is more correct to map Limit to max_memory (it really is the upper limit of what the VM may potentially use) and keep cur_balloon equal to total_memory. The typical value returned from Hyper-V in Limit is 1 TiB, which is not really going to work if interpreted as "startup memory" to be ballooned away later. Signed-off-by: Ladi Prosek --- src/hyperv/hyperv_driver.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 998780b80..4565af3ed 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -920,8 +920,10 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned i= nt flags) def->description =3D virBufferContentAndReset(&buf); } =20 - virDomainDefSetMemoryTotal(def, memorySettingData->data.common->Limit = * 1024); /* megabyte to kilobyte */ - def->mem.cur_balloon =3D memorySettingData->data.common->VirtualQuanti= ty * 1024; /* megabyte to kilobyte */ + /* mebibytes to kibibytes */ + def->mem.max_memory =3D memorySettingData->data.common->Limit * 1024; + def->mem.cur_balloon =3D memorySettingData->data.common->VirtualQuanti= ty * 1024; + virDomainDefSetMemoryTotal(def, memorySettingData->data.common->Virtua= lQuantity * 1024); =20 if (virDomainDefSetVcpusMax(def, processorSettingData->data.common->Virtual= Quantity, --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list