From nobody Sun Feb 8 18:32:31 2026 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 --- 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