From nobody Mon Feb 9 03:14:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1606999049; cv=none; d=zohomail.com; s=zohoarc; b=JHDmgAJSMTg0BpLnMwJkgL1MHoSq4stmoWlHcOdDIC3dIa8z8YDwL1xfE62HQ00KsYwoTHc2B0IxxZrCjZapSNoalSsu2yjWglN/uRTEaY2pNH2cl+b7fYaHlj0G18OjtH7F9WXk9fo6Nb1UaXAqQEZRq4pqTqVxtuHnuBBx2Zs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606999049; 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=Td2tUNRCQsXXF2OLFGtWleLLIns9JX3gcNwG3a6hShM=; b=aNZ7tHSUWQBoF6EWNdKJh1ugCWpPE4VzOgEyWJJHI+kTLQEzE86d00N3ZCZxZGrgsyPwmh+15WACvjvB9qksxojTx1bfZYE++dNp/eS0Odxu+janzL9Cm1fMjFX5QseVEwkKRA1WJ5Rtue8buv11oJ9b8znBV1WTmSSvBvc+GOA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606999049556746.0101887398525; Thu, 3 Dec 2020 04:37:29 -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-567-VHdCSOKJPaSn5LeBrhvD2Q-1; Thu, 03 Dec 2020 07:37:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEEC0107ACF7; Thu, 3 Dec 2020 12:37:19 +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 BDC1060C17; Thu, 3 Dec 2020 12:37:19 +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 7BBF85004B; Thu, 3 Dec 2020 12:37:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B3CbI4e003325 for ; Thu, 3 Dec 2020 07:37:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id BE9315C1CF; Thu, 3 Dec 2020 12:37:18 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4033C5C1C2 for ; Thu, 3 Dec 2020 12:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606999048; 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=Td2tUNRCQsXXF2OLFGtWleLLIns9JX3gcNwG3a6hShM=; b=Axx4NDsWNTwjXq2tuGCVlR8wgLSFZF55NEugyo4N3Bc3UxouNKZQuYXpBzhRGo7yLbrKoY ROsSSQcKxdgomVhxjku3bt65vsR7u05pfSswAp9fcKCCotVMycDaTsyCW/5E/eVmnE4CLo 3kL8yV+j/QRBKyNQYTuKOEQ7J6uMBI4= X-MC-Unique: VHdCSOKJPaSn5LeBrhvD2Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 19/27] qemu: Build command line for virtio-pmem Date: Thu, 3 Dec 2020 13:36:22 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.12 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'. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1735375 Signed-off-by: Michal Privoznik --- src/qemu/qemu_alias.c | 44 ++++++---- src/qemu/qemu_command.c | 82 ++++++++++--------- ...ory-hotplug-virtio-pmem.x86_64-latest.args | 45 ++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 120 insertions(+), 52 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 931dbd4e84..68d4a7b480 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -466,6 +466,28 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def, } =20 =20 +static int +qemuDeviceMemoryGetAliasID(virDomainDefPtr def, + virDomainMemoryDefPtr mem, + bool oldAlias, + const char *prefix) +{ + size_t i; + int maxidx =3D 0; + + if (!oldAlias) + 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,10 +505,8 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def, virDomainMemoryDefPtr mem, bool oldAlias) { - size_t i; - int maxidx =3D 0; - int idx; const char *prefix =3D NULL; + int idx =3D 0; =20 if (mem->info.alias) return 0; @@ -494,26 +514,22 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def, switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: prefix =3D "dimm"; + idx =3D qemuDeviceMemoryGetAliasID(def, mem, oldAlias, prefix); break; case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: prefix =3D "nvdimm"; + idx =3D qemuDeviceMemoryGetAliasID(def, mem, oldAlias, prefix); break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + prefix =3D "virtiopmem"; + idx =3D qemuDeviceMemoryGetAliasID(def, mem, true, prefix); + break; case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; } =20 - 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; - } - - mem->info.alias =3D g_strdup_printf("%s%d", prefix, maxidx); + mem->info.alias =3D g_strdup_printf("%s%d", prefix, idx); =20 return 0; } @@ -688,7 +704,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 49241fc507..501deff1ee 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2957,7 +2957,8 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, virDomainMemoryAccess memAccess =3D mem->access; size_t i; g_autofree char *memPath =3D NULL; - bool prealloc =3D false; + bool wantPrealloc =3D false; + bool allowPrealloc =3D !priv->memPrealloc; virBitmapPtr nodemask =3D NULL; int rc; g_autoptr(virJSONValue) props =3D NULL; @@ -2991,6 +2992,11 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backend= Props, nvdimmPmem =3D mem->s.nvdimm.pmem; break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + nvdimmPath =3D mem->s.virtio.path; + /* virtio-pmem doesn't need prealloc, it's very likely exposing a = real + * device and thus there's nothing to prealloc */ + allowPrealloc =3D false; + break; case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; @@ -3020,7 +3026,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, discard =3D def->mem.discard; =20 if (def->mem.allocation =3D=3D VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) - prealloc =3D true; + wantPrealloc =3D true; =20 if (virDomainNumatuneGetMode(def->numa, mem->targetNode, &mode) < 0 && virDomainNumatuneGetMode(def->numa, -1, &mode) < 0) @@ -3095,7 +3101,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, return -1; } =20 - prealloc =3D true; + wantPrealloc =3D true; } =20 if (qemuBuildMemoryBackendPropsShare(props, memAccess) < 0) @@ -3106,11 +3112,11 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backen= dProps, =20 if (nvdimmPath) { memPath =3D g_strdup(nvdimmPath); - prealloc =3D true; + wantPrealloc =3D true; } else if (useHugepage) { if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &m= emPath) < 0) return -1; - prealloc =3D true; + wantPrealloc =3D true; } else { /* We can have both pagesize and mem source. If that's the cas= e, * prefer hugepages as those are more specific. */ @@ -3143,8 +3149,8 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, backendType =3D "memory-backend-ram"; } =20 - if (!priv->memPrealloc && - virJSONValueObjectAdd(props, "B:prealloc", prealloc, NULL) < 0) + if (allowPrealloc && + virJSONValueObjectAdd(props, "B:prealloc", wantPrealloc, NULL) < 0) return -1; =20 if (virJSONValueObjectAdd(props, "U:size", mem->size * 1024, NULL) < 0) @@ -3299,7 +3305,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", @@ -3308,46 +3314,46 @@ 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); - - qemuBuildDeviceAddressStr(&buf, def, &mem->info, qemuCaps); + device =3D "pc-dimm"; + break; + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + device =3D "nvdimm"; break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO: + device =3D "virtio-pmem-pci"; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: 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); + + qemuBuildDeviceAddressStr(&buf, def, &mem->info, qemuCaps); + + 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 409680c84e..c79246e0bb 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3012,6 +3012,7 @@ mymain(void) DO_TEST_CAPS_LATEST("memory-hotplug-nvdimm-pmem"); DO_TEST_CAPS_LATEST("memory-hotplug-nvdimm-readonly"); DO_TEST_CAPS_ARCH_LATEST("memory-hotplug-nvdimm-ppc64", "ppc64"); + DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); =20 DO_TEST("machine-aeskeywrap-on-caps", QEMU_CAPS_AES_KEY_WRAP, --=20 2.26.2