From nobody Sun May 12 13:32:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695385022; cv=none; d=zohomail.com; s=zohoarc; b=jvjmr+p5BDsBc23NjNXyKKxz0WEFEJGaukkqsBv9l0gEK7T+hdHC47HAVKoKJaFYfhGMgDiW7CfE5Mu/zf/7OprB9PDUMFD+UdnqO8HiPSFmK9lIQY1Gr0hCDPt670I5aOeLtAlmYw8Um2tbpWSJ3Rb8lRqSeYOiM4oaLOv+8wc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695385022; h=Content-Type:Content-Transfer-Encoding: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=+T7O73v+lhsZTgSwngu683HSwdHSKDvAIlh5uDHIn8M=; b=F2iOS3LA4yX2eXOq+6h3ZmDa/Ei7i68IM6VJgZLLHUq65epmH1Xx+7j56SiWI6/EWGaD3pDxThGHOIkeXn8XPskakBJqGXSUNM2ZvBLKPoY342a57rmycxZD2sA9ob1WBCEXzV0h5zt53bOeDM4yaKyG7T6ghQkL+Pd0fY4/xGM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1695385022932266.7947697228758; Fri, 22 Sep 2023 05:17:02 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-508-btLTQQWZMjO6Tz_uVFqBoQ-1; Fri, 22 Sep 2023 08:16:57 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 988DD3C0F676; Fri, 22 Sep 2023 12:16:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75A14C154CB; Fri, 22 Sep 2023 12:16:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3218119466F8; Fri, 22 Sep 2023 12:16:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3782219466F5 for ; Fri, 22 Sep 2023 12:16:52 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 19544C154CA; Fri, 22 Sep 2023 12:16:52 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.2.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4D05C15BB8 for ; Fri, 22 Sep 2023 12:16:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695385022; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+T7O73v+lhsZTgSwngu683HSwdHSKDvAIlh5uDHIn8M=; b=B88/NCp47rKI3p2WoxabZ9gD5keZyJjcDrpZj/R6iW64qPtRGrdKTO4VUzTzm0nZgbnoey 6abIwfBQJqBeV7XopBNg6BLc3cD8+sMQp6Fz/jGe7DlpBMl75eAdu8UQv5bGWS31XQizxG sxGK5LCpwhPsTBHRQtDRe6Bnrnmy03A= X-MC-Unique: btLTQQWZMjO6Tz_uVFqBoQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/3] domain_validate: Validate VIRTIO_PMEM address alignment Date: Fri, 22 Sep 2023 14:16:47 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695385024242100005 Content-Type: text/plain; charset="utf-8"; x-default="true" QEMU mandates the VIRTIO_PMEM address is aligned to a pagesize. This is a very reasonable requirement. So much so, that it deserves to be in hypervisor agnostic validation code (virDomainMemoryDefValidate()). Not that any other hypervisor would support VIRTIO_PMEM yet. But even if they did, this would surely be still valid. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_validate.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index ac32fa1477..e423383e22 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2221,6 +2221,7 @@ static int virDomainMemoryDefValidate(const virDomainMemoryDef *mem, const virDomainDef *def) { + const long pagesize =3D virGetSystemPageSize(); unsigned long long thpSize; =20 /* Guest NUMA nodes are continuous and indexed from zero. */ @@ -2295,6 +2296,14 @@ virDomainMemoryDefValidate(const virDomainMemoryDef = *mem, _("virtio-pmem does not support NUMA nodes")); return -1; } + + if (pagesize > 0 && + mem->target.virtio_pmem.address % pagesize !=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory address must be aligned to %1$ld byte= s"), + pagesize); + return -1; + } break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: --=20 2.41.0 From nobody Sun May 12 13:32:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695385021; cv=none; d=zohomail.com; s=zohoarc; b=Sy/szjM6ubZ3EZDJX7GbifHdQtmEKs+NCT2w9ITJUJ75cO6LlkpZYqcBo12fVfYUHgHUMOIJWW31uFUcybEpd7XZS9z7sK2wrhEQbF53F0wrKafE2nnDFqeLOAkVIQrNnUC5sKv63wbSnKzvNSObMtRhBjvE+6L9bSxjznwAbRo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695385021; h=Content-Type:Content-Transfer-Encoding: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=T+yc0SsNKzyM0qQL2tWVmpumX/fI9t/rqG3fMqDQ7ls=; b=Q6pu48C0lehAuv7IkUel0enKoYW+mQ/Oq8mXwujVF/Yn+k9MFSTFfT+G/e33iwdV6hkVogGCb9FV5O2KprPvhIPDJmGA4wd907hryqJts1EYenzbkAAB10bhzQxxcjS//Sav9eWdcRnBVe2K2vDE8R4cYQ7gnmSRsaVHS8vzrRI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1695385021404853.6297197507942; Fri, 22 Sep 2023 05:17:01 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647-wBnDfW4DMfuIixnGgVse2w-1; Fri, 22 Sep 2023 08:16:57 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B6EB85A5BE; Fri, 22 Sep 2023 12:16:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0332A14171B6; Fri, 22 Sep 2023 12:16:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DB6C91946588; Fri, 22 Sep 2023 12:16:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D55271946586 for ; Fri, 22 Sep 2023 12:16:52 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A8221C03292; Fri, 22 Sep 2023 12:16:52 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.2.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 502B5C15BB8 for ; Fri, 22 Sep 2023 12:16:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695385020; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=T+yc0SsNKzyM0qQL2tWVmpumX/fI9t/rqG3fMqDQ7ls=; b=hDOMsgxW3Tvnlzr+4+1kW6PIyVYdBkCuhJBeT62BeluOzA+++LtfwAaFBoWH9EmJc45jbd 4S+VX/NFc9RjAyZWt46HWPORRz2S+yGKGTZGZTvbSUVeBq23isnjdVevVQBo0wCWMx7Jq4 5m1qiO5wr8zgOZDQRl7k7SgGYD0qZlY= X-MC-Unique: wBnDfW4DMfuIixnGgVse2w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/3] virDomainMemoryDefValidate: Fix VIRTIO_MEM alignment check Date: Fri, 22 Sep 2023 14:16:48 +0200 Message-ID: <231a074aaf8cd424ae7b55081a1488937e2dc781.1695384981.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695385022919100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Inside of virDomainMemoryDefValidate() there's a check that address where a virtio-mem memory device is mapped to is a multiple of its block size. But this check is off by a couple of bits, because the memory address is in bytes while the block size is in kibibytes. Therefore, when checking whether address is a multiple of the block size, the latter has to be multiplied by a factor of 1024. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_validate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index e423383e22..d14559cd73 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2341,7 +2341,8 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *= mem, return -1; } =20 - if (mem->target.virtio_mem.address % mem->target.virtio_mem.blocks= ize !=3D 0) { + /* blocksize is stored in KiB while address is in bytes */ + if (mem->target.virtio_mem.address % (mem->target.virtio_mem.block= size * 1024) !=3D 0) { virReportError(VIR_ERR_XML_DETAIL, "%s", _("memory device address must be aligned to blo= cksize")); return -1; --=20 2.41.0 From nobody Sun May 12 13:32:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1695385022; cv=none; d=zohomail.com; s=zohoarc; b=bxEsQ+y34XNTcYvPzgbUTUHMAW0V45urbgdG8xF98DzD6oXFBYUmm1ErXONXtrXJ6fs7hc2cnqWufVEL4sA3uPQW+6QPniuEVOBEEnu9MxXnqCoM+UZb964oifAcBSzIJ6KaqaTdtviT6+xisCehElMxpmkDjFgGGNrkMDuKr0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695385022; h=Content-Type:Content-Transfer-Encoding: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=JyTy9i92ge4cKwFM3UGtuUY0IFYIHtEyFirkxHyZBCw=; b=Mkr5uW+tlo9MYdwG2YCZ+jvUzMp2NwLf8DOROzmfiLctgl6pv+XpQ/sQe/9rCZkt3O2VIIPHqV19goFWLt+N6iAUqILcd+n440nQ8DSxEpLMwDwQikIcevhRVCITzteuRNR/TlN2Hm2VGYwSlr21rcTt5uvAxsbcat54vTCxVUc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1695385022835586.0242801451722; Fri, 22 Sep 2023 05:17:02 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-sPiOKeDQOxO12nY7fLaBvw-1; Fri, 22 Sep 2023 08:16:58 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DC6B8280BC98; Fri, 22 Sep 2023 12:16:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5EBF400F10; Fri, 22 Sep 2023 12:16:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 68E381946595; Fri, 22 Sep 2023 12:16:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6513B1946586 for ; Fri, 22 Sep 2023 12:16:53 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 44392C154CC; Fri, 22 Sep 2023 12:16:53 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.2.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF99AC154CA for ; Fri, 22 Sep 2023 12:16:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695385021; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JyTy9i92ge4cKwFM3UGtuUY0IFYIHtEyFirkxHyZBCw=; b=CrvDKrcKKJb2djnrQO39jpkYKwaA2a7R7vVVypH8+4wg9WQWevfCRSex5ogrXaLLTSKIbn 1+isShlPrsBeeo5VerG1BGVx/7Kfh/kX5gjUqLibuSB1uv2/logZjYURP10N6h26Y5h7D5 cA5oUxmOx+mbNc4gT9GAnRKFysphpS8= X-MC-Unique: sPiOKeDQOxO12nY7fLaBvw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/3] virDomainMemoryDefValidate: Check for overlapping memory devices Date: Fri, 22 Sep 2023 14:16:49 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695385023327100003 Content-Type: text/plain; charset="utf-8"; x-default="true" As of v9.4.0-rc2~5 it is possible to specify guest address where a virtio-mem/virtio-pmem memory device is mapped to. What that commit forgot to introduce was a check for overlaps. And yes, this is technically an O(n^2) algorithm, as virDomainMemoryDefValidate() is called over each memory device and after this, virDomainMemoryDefValidate() also iterates over each memory device. But given there's usually only a handful of such devices, and this runs only when parsing domain XML I guess code readability wins over some less obvious solution. Resolves: https://issues.redhat.com/browse/RHEL-4452 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_validate.c | 47 +++++++++++++++++ ...rtio-mem-overlap-address.x86_64-latest.err | 1 + ...ory-hotplug-virtio-mem-overlap-address.xml | 50 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 99 insertions(+) create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overla= p-address.x86_64-latest.err create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overla= p-address.xml diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index d14559cd73..6962fe76bf 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2223,6 +2223,9 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *= mem, { const long pagesize =3D virGetSystemPageSize(); unsigned long long thpSize; + unsigned long long thisStart =3D 0; + unsigned long long thisEnd =3D 0; + size_t i; =20 /* Guest NUMA nodes are continuous and indexed from zero. */ if (mem->targetNode !=3D -1) { @@ -2304,6 +2307,7 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *= mem, pagesize); return -1; } + thisStart =3D mem->target.virtio_pmem.address; break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: @@ -2347,6 +2351,7 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *= mem, _("memory device address must be aligned to blo= cksize")); return -1; } + thisStart =3D mem->target.virtio_mem.address; break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: @@ -2368,6 +2373,48 @@ virDomainMemoryDefValidate(const virDomainMemoryDef = *mem, return -1; } =20 + if (thisStart =3D=3D 0) { + return 0; + } + + /* thisStart and thisEnd are in bytes, mem->size in kibibytes */ + thisEnd =3D thisStart + mem->size * 1024; + + for (i =3D 0; i < def->nmems; i++) { + const virDomainMemoryDef *other =3D def->mems[i]; + unsigned long long otherStart =3D 0; + + if (other =3D=3D mem) + continue; + + switch (other->model) { + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + continue; + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + otherStart =3D other->target.virtio_pmem.address; + break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + otherStart =3D other->target.virtio_mem.address; + break; + } + + if (otherStart =3D=3D 0) + continue; + + if (thisStart <=3D otherStart && thisEnd > otherStart) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory device address [0x%1$llx:0x%2$llx] ov= erlaps with other memory device (0x%3$llx)"), + thisStart, thisEnd, otherStart); + return -1; + } + } + return 0; } =20 diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-addre= ss.x86_64-latest.err b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-ove= rlap-address.x86_64-latest.err new file mode 100644 index 0000000000..36d5b8a6e6 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.x86_= 64-latest.err @@ -0,0 +1 @@ +unsupported configuration: memory device address [0x140000000:0x180000000]= overlaps with other memory device (0x170000000) diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-addre= ss.xml b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.x= ml new file mode 100644 index 0000000000..65999ccd99 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem-overlap-address.xml @@ -0,0 +1,50 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 1099511627776 + 8388608 + 8388608 + 2 + + hvm + + + + qemu64 + + + + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + 1048576 + 0 + 2048 + 524288 +
+ +
+ + + + 1-3 + 2048 + + + 2097152 + 0 + 2048 + 1048576 +
+ +
+ + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 2195d8efa3..a454dcb205 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2114,6 +2114,7 @@ mymain(void) DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); DO_TEST_CAPS_LATEST("memory-hotplug-virtio-mem"); DO_TEST_CAPS_LATEST("memory-hotplug-multiple"); + DO_TEST_CAPS_LATEST_PARSE_ERROR("memory-hotplug-virtio-mem-overlap-add= ress"); =20 DO_TEST_CAPS_ARCH_LATEST("machine-aeskeywrap-on-caps", "s390x"); DO_TEST_CAPS_ARCH_LATEST("machine-aeskeywrap-on-cap", "s390x"); --=20 2.41.0