From nobody Sun Feb 8 16:12:20 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1610719984; cv=none; d=zohomail.com; s=zohoarc; b=FzV96Htl6DcOz2nQJsewsp8XJE91yoB9pg8GQDvOPz2bOqTF0NUQwUbQqZD1HmRcEHs2sCCcdgTXg+WnBhqLosvZVm2GwsM0wyXV9upkED+hjJEo2OpRBufNRUIBSM+JVytHwB5GV8YQR/RP9leh8G2aqWch8WJPd+aV82Clk40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610719984; 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=We3cUTnPPT4zSDibpQsnt2y32UrwjSBJg5tLuZOrIVg=; b=a1nN0J4TI6vLhlVygLIxsnr1ox6iGgu0CMtYJ2FQS+3GqGLu8yvxqnZjR7yibkT+9rTZV9+rFNUrz0dnFUVRiujT/fd/8RgwfRGZk171IX2A+3xcbU4g7C03ZM4/zr0YcB5/ex9jaFh7gao51YQS/9gNVcAVSgod8SMRAju9xq8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1610719984164368.8370735336109; Fri, 15 Jan 2021 06:13:04 -0800 (PST) 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-207-0dGvhowePgSzWwFY0MWtvQ-1; Fri, 15 Jan 2021 09:12:57 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B20A6192296B; Fri, 15 Jan 2021 14:12: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 910F1629DA; Fri, 15 Jan 2021 14:12: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 5CAA01809CA8; Fri, 15 Jan 2021 14:12:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10FECVBu025967 for ; Fri, 15 Jan 2021 09:12:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 13DB860C6E; Fri, 15 Jan 2021 14:12:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89A5B60BF3 for ; Fri, 15 Jan 2021 14:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610719982; 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=We3cUTnPPT4zSDibpQsnt2y32UrwjSBJg5tLuZOrIVg=; b=awpzfR9qDjbSv1sJ+wK+vHluAXR0iwSNL/GAPcitKTjKjzQ/bqelFVAPOK03UFuhWZ0fzf 6+Ae8CvWBCexVuuTV7l7wORKTiMJV1SWQCFinNBXUcTN2VT8C1TGpv80+B0Ili1hUADku+ CZRpbnm64qzP4yD/W20i6Bxml4jI8+s= X-MC-Unique: 0dGvhowePgSzWwFY0MWtvQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 6/6] qemu: Build command line for virtio-pmem Date: Fri, 15 Jan 2021 15:12:20 +0100 Message-Id: <2e692e2b61222229c8cdeab6dc52ff398f1a696b.1610719802.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Now we have everything prepared for generating the command line. The device alias prefix was chosen to be 'virtiopmem'. Since virtio-pmem-pci device goes onto PCI bus generating device alias must have been changed slightly because qemuAssignDeviceMemoryAlias() might have used DIMM slot number to generate the alias. This obviously won't work and thus the "old" way (which includes qemuDomainDeviceAliasIndex()) must be used. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1735375 Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_alias.c | 58 ++++++++++----- src/qemu/qemu_command.c | 72 ++++++++++--------- ...ory-hotplug-virtio-pmem.x86_64-latest.args | 45 ++++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 126 insertions(+), 50 deletions(-) create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_6= 4-latest.args diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index dcb6c7156d..b3492d6e85 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -466,6 +466,29 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def, } =20 =20 +static int +qemuDeviceMemoryGetAliasID(virDomainDefPtr def, + virDomainMemoryDefPtr mem, + bool oldAlias, + const char *prefix) +{ + size_t i; + int maxidx =3D 0; + + /* virtio-pmem goes onto PCI bus and thus DIMM address is not valid */ + if (!oldAlias && mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM) + return mem->info.addr.dimm.slot; + + for (i =3D 0; i < def->nmems; i++) { + int idx; + if ((idx =3D qemuDomainDeviceAliasIndex(&def->mems[i]->info, prefi= x)) >=3D maxidx) + maxidx =3D idx + 1; + } + + return maxidx; +} + + /** * qemuAssignDeviceMemoryAlias: * @def: domain definition. Necessary only if @oldAlias is true. @@ -483,29 +506,32 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def, virDomainMemoryDefPtr mem, bool oldAlias) { - size_t i; - int maxidx =3D 0; - int idx; - const char *prefix; + const char *prefix =3D NULL; + int idx =3D 0; =20 if (mem->info.alias) return 0; =20 - if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM) + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: prefix =3D "dimm"; - else + break; + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: prefix =3D "nvdimm"; - - if (oldAlias) { - for (i =3D 0; i < def->nmems; i++) { - if ((idx =3D qemuDomainDeviceAliasIndex(&def->mems[i]->info, p= refix)) >=3D maxidx) - maxidx =3D idx + 1; - } - } else { - maxidx =3D mem->info.addr.dimm.slot; + break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + prefix =3D "virtiopmem"; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + default: + virReportEnumRangeError(virDomainMemoryModel, mem->model); + return -1; + break; } =20 - mem->info.alias =3D g_strdup_printf("%s%d", prefix, maxidx); + idx =3D qemuDeviceMemoryGetAliasID(def, mem, oldAlias, prefix); + mem->info.alias =3D g_strdup_printf("%s%d", prefix, idx); =20 return 0; } @@ -680,7 +706,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCap= sPtr qemuCaps) return -1; } for (i =3D 0; i < def->nmems; i++) { - if (qemuAssignDeviceMemoryAlias(NULL, def->mems[i], false) < 0) + if (qemuAssignDeviceMemoryAlias(def, def->mems[i], false) < 0) return -1; } if (def->vsock) { diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6a4ad6c412..64b189fd11 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3087,8 +3087,9 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, if (mem->nvdimmPath) { memPath =3D g_strdup(mem->nvdimmPath); /* If the NVDIMM is a real device then there's nothing to prea= lloc. - * If anything, we would be only wearing off the device. */ - if (!mem->nvdimmPmem) + * If anything, we would be only wearing off the device. + * Simirarly, virtio-pmem-pci doesn't need prealloc either. */ + if (!mem->nvdimmPmem && mem->model !=3D VIR_DOMAIN_MEMORY_MODE= L_VIRTIO_PMEM) prealloc =3D true; } else if (useHugepage) { if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &m= emPath) < 0) @@ -3282,7 +3283,7 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, virQEMUCapsPtr qemuCaps) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - const char *device; + const char *device =3D NULL; =20 if (!mem->info.alias) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -3291,47 +3292,50 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, } =20 switch (mem->model) { - case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: case VIR_DOMAIN_MEMORY_MODEL_DIMM: - - if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM) - device =3D "pc-dimm"; - else - device =3D "nvdimm"; - - virBufferAsprintf(&buf, "%s,", device); - - if (mem->targetNode >=3D 0) - virBufferAsprintf(&buf, "node=3D%d,", mem->targetNode); - - if (mem->labelsize) - virBufferAsprintf(&buf, "label-size=3D%llu,", mem->labelsize *= 1024); - - if (virUUIDIsValid(mem->uuid)) { - char uuidstr[VIR_UUID_STRING_BUFLEN]; - - virUUIDFormat(mem->uuid, uuidstr); - virBufferAsprintf(&buf, "uuid=3D%s,", uuidstr); - } - - if (mem->readonly) { - virBufferAddLit(&buf, "unarmed=3Don,"); - } - - virBufferAsprintf(&buf, "memdev=3Dmem%s,id=3D%s", - mem->info.alias, mem->info.alias); - - if (qemuBuildDeviceAddressStr(&buf, def, &mem->info, qemuCaps) < 0) - return NULL; + device =3D "pc-dimm"; + break; + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + device =3D "nvdimm"; break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + device =3D "virtio-pmem-pci"; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: + default: + virReportEnumRangeError(virDomainMemoryModel, mem->model); + return NULL; break; + } + + virBufferAsprintf(&buf, "%s,", device); + + if (mem->targetNode >=3D 0) + virBufferAsprintf(&buf, "node=3D%d,", mem->targetNode); + + if (mem->labelsize) + virBufferAsprintf(&buf, "label-size=3D%llu,", mem->labelsize * 102= 4); + + if (virUUIDIsValid(mem->uuid)) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 + virUUIDFormat(mem->uuid, uuidstr); + virBufferAsprintf(&buf, "uuid=3D%s,", uuidstr); } =20 + if (mem->readonly) { + virBufferAddLit(&buf, "unarmed=3Don,"); + } + + virBufferAsprintf(&buf, "memdev=3Dmem%s,id=3D%s", + mem->info.alias, mem->info.alias); + + if (qemuBuildDeviceAddressStr(&buf, def, &mem->info, qemuCaps) < 0) + return NULL; + return virBufferContentAndReset(&buf); } =20 diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-lates= t.args b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-latest.ar= gs new file mode 100644 index 0000000000..e2f5097424 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-latest.args @@ -0,0 +1,45 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-i386 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ +-cpu qemu64 \ +-m size=3D2095104k,slots=3D16,maxmem=3D1099511627776k \ +-overcommit mem-lock=3Doff \ +-smp 2,sockets=3D2,dies=3D1,cores=3D1,threads=3D1 \ +-object memory-backend-ram,id=3Dram-node0,size=3D2145386496 \ +-numa node,nodeid=3D0,cpus=3D0-1,memdev=3Dram-node0 \ +-object memory-backend-file,id=3Dmemvirtiopmem0,mem-path=3D/tmp/virtio_pme= m,\ +share=3Dyes,size=3D536870912 \ +-device virtio-pmem-pci,memdev=3Dmemvirtiopmem0,id=3Dvirtiopmem0,bus=3Dpci= .0,\ +addr=3D0x5 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\ +"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw= ",\ +"file":"libvirt-1-storage"}' \ +-device ide-hd,bus=3Dide.0,unit=3D0,drive=3Dlibvirt-1-format,id=3Dide0-0-0= ,bootindex=3D1 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 4a2ab6bec1..cf77224fc3 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3053,6 +3053,7 @@ mymain(void) QEMU_CAPS_OBJECT_MEMORY_FILE, QEMU_CAPS_DEVICE_NVDIMM, QEMU_CAPS_LAST); + DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); =20 DO_TEST("machine-aeskeywrap-on-caps", QEMU_CAPS_AES_KEY_WRAP, --=20 2.26.2