From nobody Thu May 9 14:20:14 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=1632232337; cv=none; d=zohomail.com; s=zohoarc; b=IYOaghaAqe3fEGvmEecyKTPE4zi17g3TdZ6OUws6yBk63ID3bxK/i6sIlVM9GSfK/KOHw439SoSkuNSoYmLwAvmUVSvYJWC7Itu40fVAAWTX1KQn/l6/+j3WWID1I7uZwMu1nwDpVpDmZS9Zue8SxtTzygWrDbIcBYX5S/j6lcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232337; h=Content-Type:Content-Transfer-Encoding:Cc: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=5gKuUV3oYO/eYXzJW11ZJUJW5Nes3R4CWFsFDXPGKfE=; b=OI10ymL4U4svpg8j88xkm+jkMZzcdmHF+iym5k2xg4nrYUaV8CVC7PIhXoDW7IFhRYPZNGQYOwYrqyLq9Ru3Fjn1bb/r5OJMrvFAx4DsgE//DgkWMsgc5cApgyu2SLqNeAmQkZMa9/kCfGI0cbrG+0Itn4BwfyCWLBIIBJupNaU= 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 1632232337150180.10434242860117; Tue, 21 Sep 2021 06:52:17 -0700 (PDT) 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-474-4UixDuSSMkiF6RWd7leSUw-1; Tue, 21 Sep 2021 09:52:13 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB762802921; Tue, 21 Sep 2021 13:52:08 +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 9689A18761; Tue, 21 Sep 2021 13:52:08 +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 4E9FB1803B30; Tue, 21 Sep 2021 13:52:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDq7v9004228 for ; Tue, 21 Sep 2021 09:52:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3959760877; Tue, 21 Sep 2021 13:52:07 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90D105BAE0; Tue, 21 Sep 2021 13:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232336; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=5gKuUV3oYO/eYXzJW11ZJUJW5Nes3R4CWFsFDXPGKfE=; b=d4DNT8q33Nen1HV2yq+AIAzy8Z5OxbxkHD84izI1bf48LnK+yjnFnFxvvEYWw5cnUxMV1x Krjm1dfV7B6hza4+gjDVFeMQsPvv20nkGFQqHnnpxuQbvUSm3H3A4eSG+NNRuinPcOnPc9 /aMtY9i7RoleAWgVseSnOYoI8s0VYtY= X-MC-Unique: 4UixDuSSMkiF6RWd7leSUw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 01/16] virhostmem: Introduce virHostMemGetTHPSize() Date: Tue, 21 Sep 2021 15:51:17 +0200 Message-Id: <610eb41f9354411f6bbc01f6c2af8e3aa0219238.1632231694.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.16 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) X-ZM-MESSAGEID: 1632232339165100001 Content-Type: text/plain; charset="utf-8" New virHostMemGetTHPSize() is introduced which allows caller to obtain THP PMD (Page Middle Directory) size, which is equal to the minimal size that THP can use, taken from kernel doc (Documentation/admin-guide/mm/transhuge.rst): Some userspace (such as a test program, or an optimized memory allocation library) may want to know the size (in bytes) of a transparent hugepage:: cat /sys/kernel/mm/transparent_hugepage/hpage_pmd_size Since this size depends on the host architecture and the kernel it won't change whilst libvirtd is running. Therefore, we can use virOnce() and cache the value. Of course, we can be running under kernel that has THP disabled or has no notion of THP at all. In that case a negative value is returned to signal error. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virhostmem.c | 54 ++++++++++++++++++++++++++++++++++++++++ src/util/virhostmem.h | 3 +++ tests/domaincapsmock.c | 9 +++++++ 4 files changed, 67 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 25ee21463c..efb6648913 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2410,6 +2410,7 @@ virHostMemGetFreePages; virHostMemGetInfo; virHostMemGetParameters; virHostMemGetStats; +virHostMemGetTHPSize; virHostMemSetParameters; =20 =20 diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index b13c3fe38e..5984dfab3f 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -45,11 +45,14 @@ #include "virstring.h" #include "virnuma.h" #include "virlog.h" +#include "virthread.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 VIR_LOG_INIT("util.hostmem"); =20 +static unsigned long long virHostTHPPMDSize; /* in kibibytes */ +static virOnceControl virHostMemGetTHPSizeOnce =3D VIR_ONCE_CONTROL_INITIA= LIZER; =20 #ifdef __FreeBSD__ # define BSD_MEMORY_STATS_ALL 4 @@ -930,3 +933,54 @@ virHostMemAllocPages(unsigned int npages, =20 return ncounts; } + +#if defined(__linux__) +# define HPAGE_PMD_SIZE_PATH "/sys/kernel/mm/transparent_hugepage/hpage_pm= d_size" +static void +virHostMemGetTHPSizeSysfs(unsigned long long *size) +{ + if (virFileReadValueUllong(size, "%s", HPAGE_PMD_SIZE_PATH) < 0) { + VIR_WARN("unable to get THP PMD size: %s", g_strerror(errno)); + return; + } + + /* Size is now in bytes. Convert to KiB. */ + *size >>=3D 10; +} +#endif /* defined(__linux__) */ + + +static void +virHostMemGetTHPSizeOnceInit(void) +{ +#if defined(__linux__) + virHostMemGetTHPSizeSysfs(&virHostTHPPMDSize); +#else /* !defined(__linux__) */ + VIR_WARN("Getting THP size not ported yet"); +#endif /* !defined(__linux__) */ +} + + +/** + * virHostMemGetTHPSize: + * @size: returned size of THP in kibibytes + * + * Obtain Transparent Huge Page size in kibibytes. The size + * depends on host architecture and kernel. Because of virOnce(), + * do not rely on errno in case of failure. + * + * Returns: 0 on success, + * -1 on failure. + */ +int +virHostMemGetTHPSize(unsigned long long *size) +{ + if (virOnce(&virHostMemGetTHPSizeOnce, virHostMemGetTHPSizeOnceInit) <= 0) + return -1; + + if (virHostTHPPMDSize =3D=3D 0) + return -1; + + *size =3D virHostTHPPMDSize; + return 0; +} diff --git a/src/util/virhostmem.h b/src/util/virhostmem.h index 3265215d84..c36de94f0f 100644 --- a/src/util/virhostmem.h +++ b/src/util/virhostmem.h @@ -55,3 +55,6 @@ int virHostMemAllocPages(unsigned int npages, unsigned int cellCount, int lastCell, bool add); + +int virHostMemGetTHPSize(unsigned long long *size) + G_GNUC_NO_INLINE; diff --git a/tests/domaincapsmock.c b/tests/domaincapsmock.c index 0a6c541f77..d382d06e27 100644 --- a/tests/domaincapsmock.c +++ b/tests/domaincapsmock.c @@ -17,6 +17,7 @@ #include =20 #include "virhostcpu.h" +#include "virhostmem.h" =20 #if WITH_QEMU # include "virmock.h" @@ -51,3 +52,11 @@ virQEMUCapsGetKVMSupportsSecureGuest(virQEMUCaps *qemuCa= ps) return real_virQEMUCapsGetKVMSupportsSecureGuest(qemuCaps); } #endif + +int +virHostMemGetTHPSize(unsigned long long *size) +{ + /* Pretend Transparent Huge Page size is 2MiB. */ + *size =3D 2048; + return 0; +} --=20 2.32.0 From nobody Thu May 9 14:20:14 2024 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=1632232355; cv=none; d=zohomail.com; s=zohoarc; b=DCn8qOMDKxv2Mnw61FiVCHZCteLtrCRpHZv9GFfg7gd1WjK80B/PTBNNepkJMFVakAOMaTHrjDvlioFA9Y0/YQTE2hqGwOjEfatnvhh0uYqlhqSDl//lsyJC0IhY3CZSC95Da950mQQL/ch39FvOo4PhY+lc486akStPBfpZmcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232355; h=Content-Type:Content-Transfer-Encoding:Cc: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=x3WSwgxjAe1Wderem5FrR2lQRivGqtZoSczI0EFcVgs=; b=CANhHyPNCnhMhgNq+Aczhj/YJyG/VqVsN6iyMU+utAWHdyC0WCEir8OIesiKwvwchkOXg7dyldXx4heQbpI1oIYFLzIeCvvcomsjEt05pnhlJAhODdsKqDrH/u3V4nSrvILPyjVVhdMReOnZX9dy1MRGsrnJnLKvazoZv4frSmQ= 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) 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 1632232355238816.212672217216; Tue, 21 Sep 2021 06:52:35 -0700 (PDT) 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-125-wpj0u4ubM1q9XHQ1XsArzA-1; Tue, 21 Sep 2021 09:52:32 -0400 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 84C72362F9; Tue, 21 Sep 2021 13:52:27 +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 D8D3760C17; Tue, 21 Sep 2021 13:52:26 +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 A3C471803B30; Tue, 21 Sep 2021 13:52:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDqPW9004290 for ; Tue, 21 Sep 2021 09:52:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7202E608BA; Tue, 21 Sep 2021 13:52:25 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 848F360938; Tue, 21 Sep 2021 13:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232354; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=x3WSwgxjAe1Wderem5FrR2lQRivGqtZoSczI0EFcVgs=; b=YWXsUdUZLGqCE4Sqoy7Svd2RvZDnnZh9RHPmbcLLTGZRE+ab9EtIbYxBpZvsM1AoMtvxJL Z1aAFJpvt4pHMGGrlNdyre6vzJxUdFSJLso2wPB0P6uSjNXu8wHoDiUAfpie4QatVb4wu3 7SV55hOxpp3hpZueZyDM6kN0ra4OKuU= X-MC-Unique: wpj0u4ubM1q9XHQ1XsArzA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 02/16] qemu_capabilities: Introduce QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI Date: Tue, 21 Sep 2021 15:51:18 +0200 Message-Id: <837c3cc3bf52afdb4f735971da62f5792c1331fd.1632231694.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1632232355681100001 Content-Type: text/plain; charset="utf-8" This commit introduces a new capability that reflects virtio-mem-pci device support in QEMU: QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI, /* -device virtio-mem-pci */ The virtio-mem-pci device was introduced in QEMU 5.1. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 4 ++++ src/qemu/qemu_capabilities.h | 3 +++ tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_6.0.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml | 1 + 6 files changed, 11 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 63516c3d8e..e32eda18b0 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -639,6 +639,9 @@ VIR_ENUM_IMPL(virQEMUCaps, "s390-pv-guest", /* QEMU_CAPS_S390_PV_GUEST */ "set-action", /* QEMU_CAPS_SET_ACTION */ "virtio-blk.queue-size", /* QEMU_CAPS_VIRTIO_BLK_QUEUE_SIZE = */ + + /* 410 */ + "virtio-mem-pci", /* QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI */ ); =20 =20 @@ -1355,6 +1358,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[= ] =3D { { "virtio-gpu-gl-pci", QEMU_CAPS_VIRTIO_GPU_GL_PCI }, { "virtio-vga-gl", QEMU_CAPS_VIRTIO_VGA_GL }, { "s390-pv-guest", QEMU_CAPS_S390_PV_GUEST }, + { "virtio-mem-pci", QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI }, }; =20 =20 diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 23aa434f2c..12fb0b3da0 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -620,6 +620,9 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_SET_ACTION, /* 'set-action' QMP command */ QEMU_CAPS_VIRTIO_BLK_QUEUE_SIZE, /* virtio-blk-*.queue-size */ =20 + /* 410 */ + QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI, /* -device virtio-mem-pci */ + QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; =20 diff --git a/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_5.1.0.x86_64.xml index 364526a971..8bc210136c 100644 --- a/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml @@ -238,6 +238,7 @@ + 5001000 0 43100242 diff --git a/tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_5.2.0.x86_64.xml index 2df847c7d7..f01fc82a89 100644 --- a/tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml @@ -239,6 +239,7 @@ + 5002000 0 43100243 diff --git a/tests/qemucapabilitiesdata/caps_6.0.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_6.0.0.x86_64.xml index 0fb1b4538d..31a10ec1a5 100644 --- a/tests/qemucapabilitiesdata/caps_6.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_6.0.0.x86_64.xml @@ -247,6 +247,7 @@ + 6000000 0 43100242 diff --git a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_6.1.0.x86_64.xml index 31a5223c40..fa9c724617 100644 --- a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml @@ -249,6 +249,7 @@ + 6001000 0 43100243 --=20 2.32.0 From nobody Thu May 9 14:20:14 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=1632232363; cv=none; d=zohomail.com; s=zohoarc; b=cYH30/eN98tMWIKd7iyMNfDCwsGrRqEeGOAuek2n23vYI4UudDkf+FpLH+aVzz3XBQ9X1gIsWUR43iGlZsJc4ZeVoPShywZMFiddNHC52oKrq/gFS+yYiQ4wD/ohDIPW7R+do3JQIslWtt1EtDHxDZnOZu0tQhjqwfbsStR6wnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232363; h=Content-Type:Content-Transfer-Encoding:Cc: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=7Nixqw+Va7EyH1KxAgDrmPxC636xEw/PxPpWM6W7qg0=; b=ZMEPDMJpIpTxWDXF9mJjMvFUvuRj2z/9XNyYJkKsK7gGZ+cARVfLMozVLqRlpoZVz8EnMTNQJqVNHzHzaxVt6EeCxJYxYz+45Uh2PcNVUZFfmurrkCWg/wZETjVYmvMpgvCdmQCH5UTVX+vRsrwnd811jdaG98yhAzwD8iu3LKg= 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 1632232363733134.7656082243359; Tue, 21 Sep 2021 06:52:43 -0700 (PDT) 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-120-HNxvNeBkPDOosXsAOLikyw-1; Tue, 21 Sep 2021 09:52:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADDB250755; Tue, 21 Sep 2021 13:52:35 +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 92FB769FAD; Tue, 21 Sep 2021 13:52:35 +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 625471809C81; Tue, 21 Sep 2021 13:52:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDqY7h004356 for ; Tue, 21 Sep 2021 09:52:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 266CC608BA; Tue, 21 Sep 2021 13:52:34 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1348260938; Tue, 21 Sep 2021 13:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232362; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=7Nixqw+Va7EyH1KxAgDrmPxC636xEw/PxPpWM6W7qg0=; b=K2QhhMQwWBTxP+gtOZEV+AqkR/hwN/9cTEfssiU6t5yoeqTv4lGahktzRsBMWGm1ky9NXc UuKGvGoKugmFT7PvMpxJLbr9h9VL188pxcoJhwM1+F+m8gAvGt/bD++oFmki1G2aTOjQD1 sPSvPiYh4s2rrpBmwuonC+9UNu71YVc= X-MC-Unique: HNxvNeBkPDOosXsAOLikyw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 03/16] qemu_capabilities: Introduce QEMU_CAPS_MEMORY_BACKEND_RESERVE Date: Tue, 21 Sep 2021 15:51:19 +0200 Message-Id: <3fc08cb5432051bc1c457b3f692b63294c65b837.1632231694.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.11 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) X-ZM-MESSAGEID: 1632232365123100001 Content-Type: text/plain; charset="utf-8" This capability tracks whether memory-backend-* supports .reserve attribute which is going to be important for backends associated with virtio-mem devices. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml | 1 + 3 files changed, 4 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index e32eda18b0..7b08b5b2cb 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -642,6 +642,7 @@ VIR_ENUM_IMPL(virQEMUCaps, =20 /* 410 */ "virtio-mem-pci", /* QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI */ + "memory-backend-file.reserve", /* QEMU_CAPS_MEMORY_BACKEND_R= ESERVE */ ); =20 =20 @@ -1723,6 +1724,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsObjec= tPropsMemoryBackendFile[] =3D * supported. The 'x-' prefix was kept for compatibility with already * released qemu versions. */ { "x-use-canonical-path-for-ramblock-id", QEMU_CAPS_X_USE_CANONICAL_PA= TH_FOR_RAMBLOCK_ID }, + { "reserve", QEMU_CAPS_MEMORY_BACKEND_RESERVE }, }; =20 static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsMemoryBackendMe= mfd[] =3D { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 12fb0b3da0..ff790ab670 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -622,6 +622,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ =20 /* 410 */ QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI, /* -device virtio-mem-pci */ + QEMU_CAPS_MEMORY_BACKEND_RESERVE, /* -object memory-backend-*.reserve= =3D */ =20 QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_6.1.0.x86_64.xml index fa9c724617..729c70be3d 100644 --- a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml @@ -250,6 +250,7 @@ + 6001000 0 43100243 --=20 2.32.0 From nobody Thu May 9 14:20:14 2024 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=1632232364; cv=none; d=zohomail.com; s=zohoarc; b=ZEsJ1WfeJerAwv5DldEG8lyIoUXHmKioko51yj2YShlKtbucpwBm7QwKdP9Njoq8TJQkxPb+tnsgDkOQWuh+uoT+65moPpFZfnQGBRctrKkXEHJ1dyGw6+mvDkCNCUdD8w8tu0j8SjUhaF9p31aP/xMbAoVHjJpgIuLCnIoYoWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232364; h=Content-Type:Content-Transfer-Encoding:Cc: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=N3g71QDJHkvBnbdKNzEnQkRWSVTGZs8kO1mxJys24Xo=; b=CGUpI/Dwij8kIzf2f+7gRG1Ss7cBYagtFikJ3B3B5KomoumYH9xOffzGo1KqynS6bQdxuj8eE+dkfmP/RFwRe+hRhP3Fy+ulHnpa103/7d1QUP4JP5LjKo4YpMlLmWxoZECrFk8ADv30SIFKwGeP6xQ+sCQMrtmTBsXkIizY76w= 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) 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 1632232364365174.37849757527397; Tue, 21 Sep 2021 06:52:44 -0700 (PDT) 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-485-FxJPkOhYPfCBaJVH0TCcmA-1; Tue, 21 Sep 2021 09:52:41 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C0DCD5074C; Tue, 21 Sep 2021 13:52:36 +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 9E5C55C23A; Tue, 21 Sep 2021 13:52:36 +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 6DD7E4E58F; Tue, 21 Sep 2021 13:52:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDqZth004361 for ; Tue, 21 Sep 2021 09:52:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 41710608BA; Tue, 21 Sep 2021 13:52:35 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71EA560C2B; Tue, 21 Sep 2021 13:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232363; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=N3g71QDJHkvBnbdKNzEnQkRWSVTGZs8kO1mxJys24Xo=; b=duP/2eD4EK7P89Yj5+9nDyTp76rB2E8TV8dP++mWeAHKRsZv9IJ/zaRBzzDgbU6/wF/t3g F49A7W8dwIfL802m26zxdU2IsLUCZUD6X2ZuqRf6aK5qIz8BS7hiQY0dYtl66XqAcb/BW6 aaHWsVw1uO62uH7WqjlHmIXvoeYFfyE= X-MC-Unique: FxJPkOhYPfCBaJVH0TCcmA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 04/16] conf: Introduce virtio-mem model Date: Tue, 21 Sep 2021 15:51:20 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.16 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) X-ZM-MESSAGEID: 1632232365197100002 Content-Type: text/plain; charset="utf-8" The virtio-mem is paravirtualized mechanism of adding/removing memory to/from a VM. A virtio-mem-pci device is split into blocks of equal size which are then exposed (all or only a requested portion of them) to the guest kernel to use as regular memory. Therefore, the device has two important attributes: 1) block-size, which defines the size of a block 2) requested-size, which defines how much memory (in bytes) is the device requested to expose to the guest. The 'block-size' is configured on command line and immutable throughout device's lifetime. The 'requested-size' can be set on the command line too, but also is adjustable via monitor. In fact, that is how management software places its requests to change the memory allocation. If it wants to give more memory to the guest it changes 'requested-size' to a bigger value, and if it wants to shrink guest memory it changes the 'requested-size' to a smaller value. Note, value of zero means that guest should release all memory offered by the device. Of course, guest has to cooperate. Therefore, there is a third attribute 'size' which is read only and reflects how much memory the guest still has. This can be different to 'requested-size', obviously. Because of name clash, I've named it 'current' and it is dealt with in future commits (it is a runtime information anyway). In the backend, memory for virtio-mem is backed by usual objects: memory-backend-{ram,file,memfd} and their size puts the cap on the amount of memory that a virtio-mem device can offer to a guest. But we are already able to express this info using under . Therefore, we need only two more elements to cover 'block-size' and 'requested-size' attributes. This is the XML I've came up with: 1-3 2048 2097152 0 2048 1048576
I hope by now it is obvious that: 1) 'requested-size' must be an integer multiple of 'block-size', and 2) virtio-mem-pci device goes onto PCI bus and thus needs PCI address. Then there is a limitation that the minimal 'block-size' is transparent huge page size (I'll leave this without explanation). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- docs/formatdomain.rst | 38 +++++++++-- docs/schemas/domaincommon.rng | 11 +++ src/conf/domain_conf.c | 53 ++++++++++++++- src/conf/domain_conf.h | 3 + src/conf/domain_validate.c | 39 +++++++++++ src/qemu/qemu_alias.c | 1 + src/qemu/qemu_command.c | 1 + src/qemu/qemu_domain.c | 10 +++ src/qemu/qemu_domain_address.c | 38 ++++++++--- src/qemu/qemu_process.c | 2 + src/qemu/qemu_validate.c | 8 +++ src/security/security_apparmor.c | 1 + src/security/security_dac.c | 2 + src/security/security_selinux.c | 2 + .../memory-hotplug-virtio-mem.xml | 67 +++++++++++++++++++ ...emory-hotplug-virtio-mem.x86_64-latest.xml | 1 + tests/qemuxml2xmltest.c | 1 + 17 files changed, 261 insertions(+), 17 deletions(-) create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml create mode 120000 tests/qemuxml2xmloutdata/memory-hotplug-virtio-mem.x86_= 64-latest.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 0f5d833521..87fa8b617d 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -7792,6 +7792,18 @@ Example: usage of the memory devices 524288 + + + 1-3 + 2048 + + + 2097152 + 0 + 2048 + 1048576 + + ... =20 @@ -7799,7 +7811,8 @@ Example: usage of the memory devices Provide ``dimm`` to add a virtual DIMM module to the guest. :since:`Sin= ce 1.2.14` Provide ``nvdimm`` model that adds a Non-Volatile DIMM module. :since:`Since 3.2.0` Provide ``virtio-pmem`` model to add a paravirtual= ized - persistent memory device. :since:`Since 7.1.0` + persistent memory device. :since:`Since 7.1.0` Provide ``virtio-mem`` m= odel + to add paravirtualized memory device. :since:`Since 7.4.0` =20 ``access`` An optional attribute ``access`` ( :since:`since 3.2.0` ) that provides @@ -7822,10 +7835,11 @@ Example: usage of the memory devices allowed only for ``model=3D'nvdimm'`` for pSeries guests. :since:`Since= 6.2.0` =20 ``source`` - For model ``dimm`` this element is optional and allows to fine tune the - source of the memory used for the given memory device. If the element i= s not - provided defaults configured via ``numatune`` are used. If ``dimm`` is - provided, then the following optional elements can be provided as well: + For model ``dimm`` and model ``virtio-mem`` this element is optional and + allows to fine tune the source of the memory used for the given memory + device. If the element is not provided defaults configured via ``numatu= ne`` + are used. If the element is provided, then the following optional eleme= nts + can be provided: =20 ``pagesize`` This element can be used to override the default host page size used= for @@ -7864,7 +7878,8 @@ Example: usage of the memory devices added memory from the perspective of the guest. =20 The mandatory ``size`` subelement configures the size of the added memo= ry as - a scaled integer. + a scaled integer. For ``virtio-mem`` this represents the maximum possib= le + size exposed to the guest. =20 The ``node`` subelement configures the guest NUMA node to attach the me= mory to. The element shall be used only if the guest has NUMA nodes configur= ed. @@ -7891,6 +7906,17 @@ Example: usage of the memory devices so other backend types should use the ``readonly`` element. :since:`= Since 5.0.0` =20 + ``block`` + For ``virtio-mem`` only. + The size of an individual block, granularity of division of memory bl= ock. + Must be power of two and at least equal to size of a transparent huge= page + (2MiB on x84_64). The default is hypervisor dependent. + + ``requested`` + For ``virtio-mem`` only. + The total size exposed to the guest. Must respect ``block`` granulari= ty + and be smaller than or equal to ``size``. + :anchor:`` =20 IOMMU devices diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index fdc04f90aa..9e7d74d43e 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -6600,6 +6600,7 @@ dimm nvdimm virtio-pmem + virtio-mem @@ -6687,6 +6688,16 @@ + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 62b9720d0a..82d4d124ad 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1392,6 +1392,7 @@ VIR_ENUM_IMPL(virDomainMemoryModel, "dimm", "nvdimm", "virtio-pmem", + "virtio-mem", ); =20 VIR_ENUM_IMPL(virDomainShmemModel, @@ -5494,6 +5495,7 @@ virDomainMemoryDefPostParse(virDomainMemoryDef *mem, } break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: @@ -14653,6 +14655,7 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, =20 switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: if (virDomainParseMemory("./pagesize", "./pagesize/@unit", ctxt, &def->pagesize, false, false) < 0) return -1; @@ -14719,7 +14722,8 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node, &def->size, true, false) < 0) return -1; =20 - if (def->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { + switch (def->model) { + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (virDomainParseMemory("./label/size", "./label/size/@unit", ctx= t, &def->labelsize, false, false) < 0) return -1; @@ -14738,6 +14742,23 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node, =20 if (virXPathBoolean("boolean(./readonly)", ctxt)) def->readonly =3D true; + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (virDomainParseMemory("./block", "./block/@unit", ctxt, + &def->blocksize, false, false) < 0) + return -1; + + if (virDomainParseMemory("./requested", "./requested/@unit", ctxt, + &def->requestedsize, false, false) < 0) + return -1; + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; } =20 return 0; @@ -16494,11 +16515,14 @@ virDomainMemoryFindByDefInternal(virDomainDef *de= f, /* target info -> always present */ if (tmp->model !=3D mem->model || tmp->targetNode !=3D mem->targetNode || - tmp->size !=3D mem->size) + tmp->size !=3D mem->size || + tmp->blocksize !=3D mem->blocksize || + tmp->requestedsize !=3D mem->requestedsize) continue; =20 switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: /* source stuff -> match with device */ if (tmp->pagesize !=3D mem->pagesize) continue; @@ -21892,6 +21916,22 @@ virDomainMemoryDefCheckABIStability(virDomainMemor= yDef *src, return false; } =20 + if (src->blocksize !=3D dst->blocksize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target memory device block size '%llu' doesn't m= atch " + "source memory device block size '%llu'"), + dst->blocksize, src->blocksize); + return false; + } + + if (src->requestedsize !=3D dst->requestedsize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target memory device requested size '%llu' doesn= 't match " + "source memory device requested size '%llu'"), + dst->requestedsize, src->requestedsize); + return false; + } + if (src->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { if (src->labelsize !=3D dst->labelsize) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -25800,6 +25840,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf, =20 switch (def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: if (def->sourceNodes) { if (!(bitmap =3D virBitmapFormat(def->sourceNodes))) return -1; @@ -25856,6 +25897,14 @@ virDomainMemoryTargetDefFormat(virBuffer *buf, if (def->readonly) virBufferAddLit(&childBuf, "\n"); =20 + if (def->blocksize) { + virBufferAsprintf(&childBuf, "%llu\n", + def->blocksize); + + virBufferAsprintf(&childBuf, "%llu\n", + def->requestedsize); + } + virXMLFormatElement(buf, "target", NULL, &childBuf); } =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 688a842660..8356d38dcb 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2473,6 +2473,7 @@ typedef enum { VIR_DOMAIN_MEMORY_MODEL_DIMM, /* dimm hotpluggable memory device */ VIR_DOMAIN_MEMORY_MODEL_NVDIMM, /* nvdimm memory device */ VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM, /* virtio-pmem memory device */ + VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM, /* virtio-mem memory device */ =20 VIR_DOMAIN_MEMORY_MODEL_LAST } virDomainMemoryModel; @@ -2493,6 +2494,8 @@ struct _virDomainMemoryDef { int targetNode; unsigned long long size; /* kibibytes */ unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */ + unsigned long long blocksize; /* kibibytes; valid only for VIRTIO_MEM = */ + unsigned long long requestedsize; /* kibibytes; valid only for VIRTIO_= MEM */ bool readonly; /* valid only for NVDIMM */ =20 /* required for QEMU NVDIMM ppc64 support */ diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 1bc62c364d..f023d22f23 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -28,6 +28,7 @@ #include "virlog.h" #include "virutil.h" #include "virstring.h" +#include "virhostmem.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 @@ -1966,6 +1967,8 @@ static int virDomainMemoryDefValidate(const virDomainMemoryDef *mem, const virDomainDef *def) { + unsigned long long thpSize; + switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (!mem->nvdimmPath) { @@ -2019,6 +2022,42 @@ virDomainMemoryDefValidate(const virDomainMemoryDef = *mem, _("virtio-pmem does not support NUMA nodes")); return -1; } + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (mem->requestedsize > mem->size) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("requested size must be smaller than or equal= to @size")); + return -1; + } + + if (!VIR_IS_POW2(mem->blocksize)) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("block size must be a power of two")); + return -1; + } + + if (virHostMemGetTHPSize(&thpSize) < 0) { + /* We failed to get THP size, fall back to a sane default. On + * almost every architecture the size will be 2MiB, except for= some + * funky arches like sparc and m68k. Use 2MiB and refine later= if + * somebody complains. */ + thpSize =3D 2048; + } + + if (mem->blocksize < thpSize) { + virReportError(VIR_ERR_XML_DETAIL, + _("block size too small, must be at least %lluK= iB"), + thpSize); + return -1; + } + + if (mem->requestedsize % mem->blocksize !=3D 0) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("requested size must be an integer multiple o= f block size")); + return -1; + } + break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: break; diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index ed47fa335a..79e8953b2f 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -522,6 +522,7 @@ qemuAssignDeviceMemoryAlias(virDomainDef *def, case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: prefix =3D "virtiopmem"; break; + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: default: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3de37aa5c5..8beb3cdedc 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3320,6 +3320,7 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, device =3D "virtio-pmem-pci"; break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: default: diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 5de7461fb3..298f9b076d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9038,6 +9038,16 @@ qemuDomainDefValidateMemoryHotplugDevice(const virDo= mainMemoryDef *mem, needsNuma =3D false; break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (mem->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI && + mem->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("only 'pci' addresses are supported for the %= s device"), + virDomainMemoryModelTypeToString(mem->model)); + return -1; + } + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: return -1; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 392368bd38..c43ad23cf5 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -380,9 +380,18 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDef *def, } =20 for (i =3D 0; i < def->nmems; i++) { - if (def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM= && - def->mems[i]->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_= NONE) - def->mems[i]->info.type =3D type; + switch (def->mems[i]->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (def->mems[i]->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_T= YPE_NONE) + def->mems[i]->info.type =3D type; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } } =20 if (type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) { @@ -1010,6 +1019,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDev= iceDef *dev, case VIR_DOMAIN_DEVICE_MEMORY: switch (dev->data.memory->model) { case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: return virtioFlags; =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: @@ -2370,12 +2380,19 @@ qemuDomainAssignDevicePCISlots(virDomainDef *def, for (i =3D 0; i < def->nmems; i++) { virDomainMemoryDef *mem =3D def->mems[i]; =20 - if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM || - !virDeviceInfoPCIAddressIsWanted(&mem->info)) - continue; - - if (qemuDomainPCIAddressReserveNextAddr(addrs, &mem->info) < 0) - return -1; + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (virDeviceInfoPCIAddressIsWanted(&mem->info) && + qemuDomainPCIAddressReserveNextAddr(addrs, &mem->info) < 0) + return -1; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } } =20 return 0; @@ -3034,6 +3051,7 @@ qemuDomainAssignMemoryDeviceSlot(virQEMUDriver *drive= r, break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: return qemuDomainEnsurePCIAddress(vm, &dev, driver); break; =20 @@ -3059,6 +3077,7 @@ qemuDomainReleaseMemoryDeviceSlot(virDomainObj *vm, break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: qemuDomainReleaseDeviceAddress(vm, &mem->info); break; =20 @@ -3093,6 +3112,7 @@ qemuDomainAssignMemorySlots(virDomainDef *def) break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: /* handled in qemuDomainAssignPCIAddresses() */ break; case VIR_DOMAIN_MEMORY_MODEL_NONE: diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 632cb817b9..07bd7e928a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3791,6 +3791,7 @@ qemuProcessDomainMemoryDefNeedHugepagesPath(const vir= DomainMemoryDef *mem, { switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: return mem->pagesize && mem->pagesize !=3D system_pagesize; =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: @@ -3859,6 +3860,7 @@ qemuProcessNeedMemoryBackingPath(virDomainDef *def, if (mem) { switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: if (mem->access !=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) { /* No need to check for access mode on the target node, * it was checked for in the previous loop. */ diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 4fc344b493..444d9eff03 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4964,6 +4964,14 @@ qemuValidateDomainDeviceDefMemory(virDomainMemoryDef= *mem, } break; =20 + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("virtio-mem isn't supported by this QEMU bina= ry")); + return -1; + } + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index d942ea5005..2cc15ba6af 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -693,6 +693,7 @@ AppArmorSetMemoryLabel(virSecurityManager *mgr, return reload_profile(mgr, def, mem->nvdimmPath, true); case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; } diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 04b9ecf028..1733d63410 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1849,6 +1849,7 @@ virSecurityDACRestoreMemoryLabel(virSecurityManager *= mgr, break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_LAST: case VIR_DOMAIN_MEMORY_MODEL_NONE: ret =3D 0; @@ -2033,6 +2034,7 @@ virSecurityDACSetMemoryLabel(virSecurityManager *mgr, break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_LAST: case VIR_DOMAIN_MEMORY_MODEL_NONE: ret =3D 0; diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 0e5ea0366d..cc72453329 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1582,6 +1582,7 @@ virSecuritySELinuxSetMemoryLabel(virSecurityManager *= mgr, =20 case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; } @@ -1609,6 +1610,7 @@ virSecuritySELinuxRestoreMemoryLabel(virSecurityManag= er *mgr, break; =20 case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: ret =3D 0; diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml b/tests/q= emuxml2argvdata/memory-hotplug-virtio-mem.xml new file mode 100644 index 0000000000..c10528aad8 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml @@ -0,0 +1,67 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 1099511627776 + 8388608 + 8388608 + 2 + + hvm + + + + qemu64 + + + + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + +
+ + +
+ + +
+ + + + +
+ + + + 1048576 + 0 + 2048 + 524288 + +
+ + + + 1-3 + 2048 + + + 2097152 + 0 + 2048 + 1048576 + +
+ + + diff --git a/tests/qemuxml2xmloutdata/memory-hotplug-virtio-mem.x86_64-late= st.xml b/tests/qemuxml2xmloutdata/memory-hotplug-virtio-mem.x86_64-latest.x= ml new file mode 120000 index 0000000000..a9d298129c --- /dev/null +++ b/tests/qemuxml2xmloutdata/memory-hotplug-virtio-mem.x86_64-latest.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/memory-hotplug-virtio-mem.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 59d1e24289..f264320f48 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1214,6 +1214,7 @@ mymain(void) QEMU_CAPS_DEVICE_NVDIMM, QEMU_CAPS_LAST, ARG_END); DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); + DO_TEST_CAPS_LATEST("memory-hotplug-virtio-mem"); =20 DO_TEST_NOCAPS("net-udp"); =20 --=20 2.32.0 From nobody Thu May 9 14:20:14 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=1632232368; cv=none; d=zohomail.com; s=zohoarc; b=ZHewUMZI8w/qkl+Z4nzgvTstFmWflLzsOCgRCgG5gXMVeQh5VMGEsTECRwofho5ym9nQ7c9tTqAZ4Mu+LNWtt6c0JVdJiOVZkIYFn82/eo7ngAdNuaWuMk5ycReGuuEt2JRioCT+yyB3KFrz4VH5SlFjV1YfjI04/haVPpfcfI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232368; h=Content-Type:Content-Transfer-Encoding:Cc: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=3l9E9w0OZ21PQ60M5LloIvxJRJU2P44x85ntoZOV/t4=; b=TiHoC9AwnZJ4mbnkW+X4juFVwDC3sJgSk/OJbcCPrEdL6soAGV66pJ4usfQzwZjqHTShJqdmSk7POLw08dpVdRs9EWjCpTpoUlUhMM8d3G9GHLqdiMxgdIuQIsyitbo0vVp0ilImNequZ0RYTWtur23WZ9/vFl24CLeEr5esybE= 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 1632232368241279.94736802834257; Tue, 21 Sep 2021 06:52:48 -0700 (PDT) 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-270-V-v0sNmkMX2IJbVj0k5xWA-1; Tue, 21 Sep 2021 09:52:45 -0400 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 802481084690; Tue, 21 Sep 2021 13:52:39 +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 34E176B545; Tue, 21 Sep 2021 13:52:39 +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 041294E9F5; Tue, 21 Sep 2021 13:52:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDqaDI004371 for ; Tue, 21 Sep 2021 09:52:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 34EE660938; Tue, 21 Sep 2021 13:52:36 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C726608BA; Tue, 21 Sep 2021 13:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232367; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=3l9E9w0OZ21PQ60M5LloIvxJRJU2P44x85ntoZOV/t4=; b=dWR+rmFnuLHzTFUlX+qvz6d/eKUIyUzuXXnse0VtO7RdQ+wnR3n7NNcZB80k3NkUMF7ls3 QwQiVH+gFSf12fTYX0tCUNHJCU0EFjRnqVJmkz4jhDXJ6UF7otYcm2YOa+REVAkgC1XQ8c alPrKuzjVFCFwgdtNCd09vC4LYGX83s= X-MC-Unique: V-v0sNmkMX2IJbVj0k5xWA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 05/16] qemu: Build command line for virtio-mem Date: Tue, 21 Sep 2021 15:51:21 +0200 Message-Id: <7a254e7e4666cf3d6b9ea1301066abae1ff7aa96.1632231694.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1632232369411100001 Content-Type: text/plain; charset="utf-8" Nothing special is happening here. All important changes were done when for 'virtio-pmem' (adjusting the code to put virtio memory on PCI bus, generating alias using qemuDomainDeviceAliasIndex(). The only bit that might look suspicious is no prealloc for virtio-mem. But if you think about it, the whole purpose of this device is to change amount of memory exposed to guest on the fly. There is no point in locking the whole backend in memory. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_alias.c | 9 +++- src/qemu/qemu_command.c | 28 +++++++++++-- ...mory-hotplug-virtio-mem.x86_64-latest.args | 41 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64= -latest.args diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 79e8953b2f..81a1e7eeed 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -475,8 +475,11 @@ qemuDeviceMemoryGetAliasID(virDomainDef *def, size_t i; int maxidx =3D 0; =20 - /* virtio-pmem goes onto PCI bus and thus DIMM address is not valid */ - if (!oldAlias && mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM) + /* virtio-pmem and virtio-mem go onto PCI bus and thus DIMM address is= not + * valid */ + if (!oldAlias && + mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM && + mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM) return mem->info.addr.dimm.slot; =20 for (i =3D 0; i < def->nmems; i++) { @@ -523,6 +526,8 @@ qemuAssignDeviceMemoryAlias(virDomainDef *def, prefix =3D "virtiopmem"; break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + prefix =3D "virtiomem"; + break; case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: default: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 8beb3cdedc..fb307f3c61 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3139,9 +3139,23 @@ qemuBuildMemoryBackendProps(virJSONValue **backendPr= ops, virJSONValueObjectAdd(props, "b:x-use-canonical-path-for-ramblock-= id", false, NULL) < 0) return -1; =20 - if (!priv->memPrealloc && - virJSONValueObjectAdd(props, "B:prealloc", prealloc, NULL) < 0) - return -1; + if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM) { + /* Explicitly disable prealloc for virtio-mem as it's not supported + * currently. Warn users if their config would result in prealloc.= */ + if (priv->memPrealloc || prealloc) { + VIR_WARN("Memory preallocation is unsupported for virtio-mem m= emory devices"); + } + if (priv->memPrealloc && + virJSONValueObjectAppendBoolean(props, "prealloc", 0) < 0) + return -1; + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MEMORY_BACKEND_RESERV= E) && + virJSONValueObjectAppendBoolean(props, "reserve", 0) < 0) + return -1; + } else { + if (!priv->memPrealloc && + virJSONValueObjectAdd(props, "B:prealloc", prealloc, NULL) < 0) + return -1; + } =20 if (virJSONValueObjectAdd(props, "U:size", mem->size * 1024, NULL) < 0) return -1; @@ -3321,6 +3335,9 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, break; =20 case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + device =3D "virtio-mem-pci"; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: default: @@ -3337,6 +3354,11 @@ qemuBuildMemoryDeviceStr(const virDomainDef *def, if (mem->labelsize) virBufferAsprintf(&buf, "label-size=3D%llu,", mem->labelsize * 102= 4); =20 + if (mem->blocksize) { + virBufferAsprintf(&buf, "block-size=3D%llu,", mem->blocksize * 102= 4); + virBufferAsprintf(&buf, "requested-size=3D%llu,", mem->requestedsi= ze * 1024); + } + if (mem->uuid) { char uuidstr[VIR_UUID_STRING_BUFLEN]; =20 diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest= .args b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args new file mode 100644 index 0000000000..22ee1bc459 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args @@ -0,0 +1,41 @@ +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 \ +/usr/bin/qemu-system-i386 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tm= p/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 '{"qom-type":"memory-backend-ram","id":"ram-node0","size":21453864= 96}' \ +-numa node,nodeid=3D0,cpus=3D0-1,memdev=3Dram-node0 \ +-object '{"qom-type":"memory-backend-ram","id":"memvirtiomem0","reserve":f= alse,"size":1073741824}' \ +-device virtio-mem-pci,node=3D0,block-size=3D2097152,requested-size=3D5368= 70912,memdev=3Dmemvirtiomem0,id=3Dvirtiomem0,bus=3Dpci.0,addr=3D0x2 \ +-object '{"qom-type":"memory-backend-file","id":"memvirtiomem1","mem-path"= :"/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1","reserve":false,"size":21474= 83648,"host-nodes":[1,2,3],"policy":"bind"}' \ +-device virtio-mem-pci,node=3D0,block-size=3D2097152,requested-size=3D1073= 741824,memdev=3Dmemvirtiomem1,id=3Dvirtiomem1,bus=3Dpci.0,addr=3D0x3 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-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","no= de-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 \ +-audiodev id=3Daudio1,driver=3Dnone \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x4 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 18b7b0ecf1..c375d7e895 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3137,6 +3137,7 @@ mymain(void) ARG_END); DO_TEST_CAPS_VER("memory-hotplug-virtio-pmem", "5.2.0"); DO_TEST_CAPS_LATEST("memory-hotplug-virtio-pmem"); + DO_TEST_CAPS_LATEST("memory-hotplug-virtio-mem"); =20 DO_TEST("machine-aeskeywrap-on-caps", QEMU_CAPS_AES_KEY_WRAP, --=20 2.32.0 From nobody Thu May 9 14:20:14 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=1632232368; cv=none; d=zohomail.com; s=zohoarc; b=MS6GBsnt2lwUSrwcTeurgAcQMHgsjfcNxTJ3lrfzrZsd1BfOL5lb4eTNzJWeUgtq9ZS5GrVh6dSlO9mXKxE07babrFf/EKOZH1Zbw0yr2aVo9QcEO/Ef5ASWCy7FATbT9o7LJNVn7xIJFjEvSYKh/xy6uhxi1DhEtNirvIHnJxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232368; h=Content-Type:Content-Transfer-Encoding:Cc: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=5ZE2fLL7wLCODq003UK2xSmsl4kNGgZ2pBoUVb/JVUA=; b=KzGsEQzmNxt/bBODGwFht3PPG0bbeuMF7IPoFvDG0ybe542FWVu3M4an4t2RjvMY1ymTN9AmB3+dWRafk6bp3MQaEFEjFYIVPlM5rHCrXMVB6MF1z7NPRM5eO7/irCP2o+CqdJLeR1HDWs8n1kiPVKMtnXkv3jr2vy6jdB84MHg= 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 163223236799444.106645776163646; Tue, 21 Sep 2021 06:52:47 -0700 (PDT) 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-27-CLN4iXnPPyaS6xvDuD2sQA-1; Tue, 21 Sep 2021 09:52:45 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C475450766; Tue, 21 Sep 2021 13:52:39 +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 A888669FAE; Tue, 21 Sep 2021 13:52:39 +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 787014EA2F; Tue, 21 Sep 2021 13:52:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDqb9k004386 for ; Tue, 21 Sep 2021 09:52:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4EFE360938; Tue, 21 Sep 2021 13:52:37 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 807D1608BA; Tue, 21 Sep 2021 13:52:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232366; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=5ZE2fLL7wLCODq003UK2xSmsl4kNGgZ2pBoUVb/JVUA=; b=Nv/+AL4P13vWBKa0o1eIkqY9FlcYv5Po9rHZLlkiy7LRV0ydPg6e1T2aOtOZ9MGPSYm2NP +gdcEBW0POaTmBJlnRp9VqaSBph7R7TO65gC0rSrpJeQNgp/UuVcWLbNGgq16fklb++LsH 6R79G4ELTW2nU+7kWmlX68CJOaUbA4A= X-MC-Unique: CLN4iXnPPyaS6xvDuD2sQA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 06/16] qemu: Wire up live update Date: Tue, 21 Sep 2021 15:51:22 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.11 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) X-ZM-MESSAGEID: 1632232369450100002 Content-Type: text/plain; charset="utf-8" As advertised in one of previous commits, we want to be able to change 'requested-size' attribute of virtio-mem on the fly. This commit does exactly that. Changing anything else is checked for and forbidden. Once guest has changed the allocation, QEMU emits an event which we will use to track the allocation. In the next commit. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 47 +++++++++- src/conf/domain_conf.h | 5 + src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 174 ++++++++++++++++++++++++++++++++++- src/qemu/qemu_hotplug.c | 18 ++++ src/qemu/qemu_hotplug.h | 5 + src/qemu/qemu_monitor.c | 13 +++ src/qemu/qemu_monitor.h | 5 + src/qemu/qemu_monitor_json.c | 15 +++ src/qemu/qemu_monitor_json.h | 5 + 10 files changed, 286 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 82d4d124ad..c84158d0f1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16577,6 +16577,50 @@ virDomainMemoryFindInactiveByDef(virDomainDef *def, } =20 =20 +/** + * virDomainMemoryFindByDeviceInfo: + * @def: domain defintion + * @info: device info to match + * @pos: store position within array + * + * For given domain definition @def find device with + * matching address and matching device alias (if set in @info, + * otherwise ignored). + * + * If @pos is not NULL then the position of the matched device + * within the array is stored there. + * + * Returns: device if found, + * NULL otherwise. + */ +virDomainMemoryDef * +virDomainMemoryFindByDeviceInfo(virDomainDef *def, + virDomainDeviceInfo *info, + int *pos) +{ + size_t i; + + for (i =3D 0; i < def->nmems; i++) { + virDomainMemoryDef *tmp =3D def->mems[i]; + + if (!virDomainDeviceInfoAddressIsEqual(&tmp->info, info)) + continue; + + /* alias, if present */ + if (info->alias && + STRNEQ_NULLABLE(tmp->info.alias, info->alias)) + continue; + + if (pos) + *pos =3D i; + + return tmp; + } + + return NULL; +} + + /** * virDomainMemoryInsert: * @@ -28594,7 +28638,8 @@ virDomainDefCompatibleDevice(virDomainDef *def, return -1; } =20 - if ((virDomainDefGetMemoryTotal(def) + sz) > def->mem.max_memory) { + if (action =3D=3D VIR_DOMAIN_DEVICE_ACTION_ATTACH && + (virDomainDefGetMemoryTotal(def) + sz) > def->mem.max_memory) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Attaching memory device with size '%llu' wou= ld " "exceed domain's maxMemory config size '%llu'= "), diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8356d38dcb..9db15a87fb 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3807,6 +3807,11 @@ int virDomainMemoryFindByDef(virDomainDef *def, virD= omainMemoryDef *mem) int virDomainMemoryFindInactiveByDef(virDomainDef *def, virDomainMemoryDef *mem) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; +virDomainMemoryDef * +virDomainMemoryFindByDeviceInfo(virDomainDef *dev, + virDomainDeviceInfo *info, + int *pos) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; =20 int virDomainShmemDefInsert(virDomainDef *def, virDomainShmemDef *shmem) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index efb6648913..d77502922d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -508,6 +508,7 @@ virDomainMemballoonModelTypeFromString; virDomainMemballoonModelTypeToString; virDomainMemoryDefFree; virDomainMemoryFindByDef; +virDomainMemoryFindByDeviceInfo; virDomainMemoryFindInactiveByDef; virDomainMemoryInsert; virDomainMemoryModelTypeToString; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6ae678b165..1dee792dfd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7088,6 +7088,175 @@ qemuDomainChangeDiskLive(virDomainObj *vm, return 0; } =20 + +static bool +qemuDomainChangeMemoryLiveValidateChange(const virDomainMemoryDef *oldDef, + const virDomainMemoryDef *newDef) +{ + /* The only thing that is allowed to change is 'requestedsize' for + * virtio-mem model. Check if user isn't trying to sneak in change for + * something else. */ + + switch (oldDef->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory of model '%s'"), + virDomainMemoryModelTypeToString(oldDef->model)); + return false; + break; + } + + if (oldDef->model !=3D newDef->model) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory model from '%s' to '%s'"), + virDomainMemoryModelTypeToString(oldDef->model), + virDomainMemoryModelTypeToString(newDef->model)); + return false; + } + + if (oldDef->access !=3D newDef->access) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory access from '%s' to '%s'"), + virDomainMemoryAccessTypeToString(oldDef->access), + virDomainMemoryAccessTypeToString(newDef->access)); + return false; + } + + if (oldDef->discard !=3D newDef->discard) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory discard from '%s' to '%s'"), + virTristateBoolTypeToString(oldDef->discard), + virTristateBoolTypeToString(newDef->discard)); + return false; + } + + if (!virBitmapEqual(oldDef->sourceNodes, + newDef->sourceNodes)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory source nodes")); + return false; + } + + if (oldDef->pagesize !=3D newDef->pagesize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory pagesize from '%llu' to '%l= lu'"), + oldDef->pagesize, + newDef->pagesize); + return false; + } + + if (STRNEQ_NULLABLE(oldDef->nvdimmPath, newDef->nvdimmPath)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory path from '%s' to '%s'"), + NULLSTR(oldDef->nvdimmPath), + NULLSTR(newDef->nvdimmPath)); + return false; + } + + if (oldDef->alignsize !=3D newDef->alignsize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory align size from '%llu' to '= %llu'"), + oldDef->alignsize, newDef->alignsize); + return false; + } + + if (oldDef->nvdimmPmem !=3D newDef->nvdimmPmem) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory pmem from '%d' to '%d'"), + oldDef->nvdimmPmem, newDef->nvdimmPmem); + return false; + } + + if (oldDef->targetNode !=3D newDef->targetNode) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory targetNode from '%d' to '%d= '"), + oldDef->targetNode, newDef->targetNode); + return false; + } + + if (oldDef->size !=3D newDef->size) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory size from '%llu' to '%llu'"= ), + oldDef->size, newDef->size); + return false; + } + + if (oldDef->labelsize !=3D newDef->labelsize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory label size from '%llu' to '= %llu'"), + oldDef->labelsize, newDef->labelsize); + return false; + } + if (oldDef->blocksize !=3D newDef->blocksize) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("cannot modify memory block size from '%llu' to '= %llu'"), + oldDef->blocksize, newDef->blocksize); + return false; + } + + /* requestedsize can change */ + + if (oldDef->readonly !=3D newDef->readonly) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory pmem flag")); + return false; + } + + if ((oldDef->uuid || newDef->uuid) && + !(oldDef->uuid && newDef->uuid && + memcmp(oldDef->uuid, newDef->uuid, VIR_UUID_BUFLEN) =3D=3D 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("cannot modify memory UUID")); + return false; + } + + return true; +} + + +static int +qemuDomainChangeMemoryLive(virQEMUDriver *driver G_GNUC_UNUSED, + virDomainObj *vm, + virDomainDeviceDef *dev) +{ + virDomainDeviceDef oldDev =3D { .type =3D VIR_DOMAIN_DEVICE_MEMORY }; + virDomainMemoryDef *newDef =3D dev->data.memory; + virDomainMemoryDef *oldDef =3D NULL; + + oldDef =3D virDomainMemoryFindByDeviceInfo(vm->def, &dev->data.memory-= >info, NULL); + if (!oldDef) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory '%s' not found"), dev->data.memory->info.= alias); + return -1; + } + + oldDev.data.memory =3D oldDef; + + if (virDomainDefCompatibleDevice(vm->def, dev, &oldDev, + VIR_DOMAIN_DEVICE_ACTION_UPDATE, + true) < 0) + return -1; + + if (!qemuDomainChangeMemoryLiveValidateChange(oldDef, newDef)) + return -1; + + if (qemuDomainChangeMemoryRequestedSize(driver, vm, + newDef->info.alias, + newDef->requestedsize) < 0) + return -1; + + oldDef->requestedsize =3D newDef->requestedsize; + return 0; +} + + static int qemuDomainUpdateDeviceLive(virDomainObj *vm, virDomainDeviceDef *dev, @@ -7129,6 +7298,10 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm, ret =3D qemuDomainChangeNet(driver, vm, dev); break; =20 + case VIR_DOMAIN_DEVICE_MEMORY: + ret =3D qemuDomainChangeMemoryLive(driver, vm, dev); + break; + case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: @@ -7144,7 +7317,6 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm, case VIR_DOMAIN_DEVICE_HOSTDEV: case VIR_DOMAIN_DEVICE_CONTROLLER: case VIR_DOMAIN_DEVICE_REDIRDEV: - case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_CHR: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_TPM: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 9c16ab4567..ccfd83cf66 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6800,3 +6800,21 @@ qemuDomainSetVcpuInternal(virQEMUDriver *driver, virBitmapFree(livevcpus); return ret; } + + +int +qemuDomainChangeMemoryRequestedSize(virQEMUDriver *driver, + virDomainObj *vm, + const char *alias, + unsigned long long requestedsize) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + int rc; + + qemuDomainObjEnterMonitor(driver, vm); + rc =3D qemuMonitorChangeMemoryRequestedSize(priv->mon, alias, requeste= dsize); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + return -1; + + return rc; +} diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index b5f7afb076..ae8feb459c 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -166,3 +166,8 @@ int qemuHotplugAttachDBusVMState(virQEMUDriver *driver, int qemuHotplugRemoveDBusVMState(virQEMUDriver *driver, virDomainObj *vm, qemuDomainAsyncJob asyncJob); + +int qemuDomainChangeMemoryRequestedSize(virQEMUDriver *driver, + virDomainObj *vm, + const char *alias, + unsigned long long requestedsize); diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 42846349c4..24119ef66e 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4625,3 +4625,16 @@ qemuMonitorSetAction(qemuMonitor *mon, =20 return qemuMonitorJSONSetAction(mon, shutdown, reboot, watchdog, panic= ); } + + +int +qemuMonitorChangeMemoryRequestedSize(qemuMonitor *mon, + const char *alias, + unsigned long long requestedsize) +{ + VIR_DEBUG("alias=3D%s requestedsize=3D%llu", alias, requestedsize); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONChangeMemoryRequestedSize(mon, alias, requesteds= ize); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 2f08357c0c..0ebe73ac04 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1537,3 +1537,8 @@ qemuMonitorSetAction(qemuMonitor *mon, qemuMonitorActionReboot reboot, qemuMonitorActionWatchdog watchdog, qemuMonitorActionPanic panic); + +int +qemuMonitorChangeMemoryRequestedSize(qemuMonitor *mon, + const char *alias, + unsigned long long requestedsize); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 37e9c05d27..4ef8abb537 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -9398,3 +9398,18 @@ qemuMonitorJSONSetAction(qemuMonitor *mon, =20 return 0; } + + +int +qemuMonitorJSONChangeMemoryRequestedSize(qemuMonitor *mon, + const char *alias, + unsigned long long requestedsize) +{ + g_autofree char *path =3D g_strdup_printf("/machine/peripheral/%s", al= ias); + qemuMonitorJSONObjectProperty prop =3D { + .type =3D QEMU_MONITOR_OBJECT_PROPERTY_ULONG, + .val.ul =3D requestedsize * 1024, /* monitor needs bytes */ + }; + + return qemuMonitorJSONSetObjectProperty(mon, path, "requested-size", &= prop); +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index c8cf734a1c..0289f8c3bf 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -710,3 +710,8 @@ qemuMonitorJSONSetAction(qemuMonitor *mon, qemuMonitorActionReboot reboot, qemuMonitorActionWatchdog watchdog, qemuMonitorActionPanic panic); + +int +qemuMonitorJSONChangeMemoryRequestedSize(qemuMonitor *mon, + const char *alias, + unsigned long long requestedsize); --=20 2.32.0 From nobody Thu May 9 14:20:14 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=1632232374; cv=none; d=zohomail.com; s=zohoarc; b=Sb38SB31ICYKt7+Br96MQadHgU3Xc+JAlTYAz9AB6GJwqI/YcUN9szxZUDYNCKUwuC4ntk5vfxSrF0BMBXKkCorxD7c5yZiwMwAP8/3hO4nrN0g7qDH3Cy/H/k5SjTK+HasCD09m6DPPWoGNPi/YQRb9qs+xpoOgDWRo2ccXt74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232374; h=Content-Type:Content-Transfer-Encoding:Cc: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=8H0zGWoGIycvb8qy/ccFFx5zjSBSaX+uQDJIHcqyLPE=; b=j3n5eMIa20UYe0Q/glra53Sxw7o/ZQCNZx525CpuAI53rD2+H9ajCiEvsUiM6oaYr0CLpJTKSWu4jmMUvDBhBc0sGFu90NkaaJE9kc32sV6Ahx3kSiLH20M38yRsOC7svNrkUUKbk56dRDSWAoR5J5wuUzy3L/Y8cBFXQv3HNuY= 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 163223237401667.3455424055054; Tue, 21 Sep 2021 06:52:54 -0700 (PDT) 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-416-6ogh6yEMPJaO2vz3XSODDw-1; Tue, 21 Sep 2021 09:52:51 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67E411084693; Tue, 21 Sep 2021 13:52:42 +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 464FB5C23A; Tue, 21 Sep 2021 13:52:42 +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 137B0180BAD1; Tue, 21 Sep 2021 13:52:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDqc7V004404 for ; Tue, 21 Sep 2021 09:52:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 42E71608BA; Tue, 21 Sep 2021 13:52:38 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A1AE60C2B; Tue, 21 Sep 2021 13:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232372; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=8H0zGWoGIycvb8qy/ccFFx5zjSBSaX+uQDJIHcqyLPE=; b=OfaJUHHnf4fxsgBCAGw0nkTw+edpDVXlBP9/CiICJSwZf21E9IZj+iK9IyAvzcb3oqLvF+ 01hA0zHSR1VQ3ljDIodpapXOjBAxCRS6mlrCug+i9sZt+bJETwPF+bjKdcmz/k9eek/K6k MJIz8+wdP3XQg/KjQdp0brbNfoF9Ar0= X-MC-Unique: 6ogh6yEMPJaO2vz3XSODDw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 07/16] qemu: Wire up offline update Date: Tue, 21 Sep 2021 15:51:23 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.16 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) X-ZM-MESSAGEID: 1632232374878100001 Content-Type: text/plain; charset="utf-8" Updating offline XML of devices might come handy when dealing with virtio-mem devices. But it's implemented to just replace one virDomainMemoryDef with another so it can be used to change almost anything. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1dee792dfd..e6557ce997 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7765,6 +7765,7 @@ qemuDomainUpdateDeviceConfig(virDomainDef *vmdef, virDomainDiskDef *newDisk; virDomainGraphicsDef *newGraphics; virDomainNetDef *net; + virDomainMemoryDef *mem; virDomainDeviceDef oldDev =3D { .type =3D dev->type }; int pos; =20 @@ -7827,6 +7828,23 @@ qemuDomainUpdateDeviceConfig(virDomainDef *vmdef, dev->data.net =3D NULL; break; =20 + case VIR_DOMAIN_DEVICE_MEMORY: + mem =3D virDomainMemoryFindByDeviceInfo(vmdef, &dev->data.memory->= info, &pos); + if (!mem) { + virReportError(VIR_ERR_INVALID_ARG, "%s", _("memory not found"= )); + return -1; + } + + oldDev.data.memory =3D mem; + if (virDomainDefCompatibleDevice(vmdef, dev, &oldDev, + VIR_DOMAIN_DEVICE_ACTION_UPDATE, + false) < 0) + return -1; + + virDomainMemoryDefFree(vmdef->mems[pos]); + vmdef->mems[pos] =3D g_steal_pointer(&dev->data.memory); + break; + case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: @@ -7843,7 +7861,6 @@ qemuDomainUpdateDeviceConfig(virDomainDef *vmdef, case VIR_DOMAIN_DEVICE_CONTROLLER: case VIR_DOMAIN_DEVICE_REDIRDEV: case VIR_DOMAIN_DEVICE_CHR: - case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: --=20 2.32.0 From nobody Thu May 9 14:20:14 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=1632232441; cv=none; d=zohomail.com; s=zohoarc; b=GP9PUyDIsafsgyrjCWQEeDRIpnnU0Spcf82UJRrRhWeC/YvWHEEUcG1PcRTzZo4Il7FowHL+cdrEpNhQw6mx4sgn37wSIZ0ghkkGJXdaINrMXPpdD772XBecAOnIWKAkBR7j0xfo+IM67+PB4qoGOtPAxattemXXSsgOFEo86fI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232441; h=Content-Type:Content-Transfer-Encoding:Cc: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=YkDz5OZo8msZgozwsrE2nz5sv15dR1LAZAElHNyEJCw=; b=CpYRb/EYmNsHHxn3WWvCWkvtaEocSg3g5SmC1maYxa2efVw9XeojBRTMQPN7q2GikhxhVNWfUtOtXU/PsTYo7o2f3L8wJjd41Vw0oLTubwPt6yAaJNpZUKlTkP7RVh5gruegzAxfQJYUBqxYfN/SWGgo6sHcqb2HYFZWs17iVwE= 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 1632232441171853.1739535077894; Tue, 21 Sep 2021 06:54:01 -0700 (PDT) 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-173-iY-6vg6tMvWFEAnCDo9EIQ-1; Tue, 21 Sep 2021 09:52:56 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 05458814706; Tue, 21 Sep 2021 13:52:46 +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 61DA779590; Tue, 21 Sep 2021 13:52:45 +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 EF6394EA38; Tue, 21 Sep 2021 13:52:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDqdIi004410 for ; Tue, 21 Sep 2021 09:52:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 36D16608BA; Tue, 21 Sep 2021 13:52:39 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DFC760938; Tue, 21 Sep 2021 13:52:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232439; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=YkDz5OZo8msZgozwsrE2nz5sv15dR1LAZAElHNyEJCw=; b=Ir72l0w04CkNOx35AQoU3EPVZvNTl5omdmwa8ufRi88mj4TOX6ryN+Adee8XXrpvycy4ok EQFioBhpj1DZwLf9AGusPsfhuttyjbQtllgQ5tCVYUpk4g7EWjar7AWohOiNej+MdrgEUK 7Q0tRsx6SkKupvOsyHgrjd75cu/FjuU= X-MC-Unique: iY-6vg6tMvWFEAnCDo9EIQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 08/16] Introduce property to virtio-mem Date: Tue, 21 Sep 2021 15:51:24 +0200 Message-Id: <6ffdc810bf656b383b454b0be49b947630356767.1632231694.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.16 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) X-ZM-MESSAGEID: 1632232442019100001 Content-Type: text/plain; charset="utf-8" The virtio-mem has another property that isn't exposed yet: current size exposed to the guest. Please note, that this is different to because esp. on sizing the memory down guest may refuse to release some blocks. Therefore, let's have another size to report in the XML. But because of its nature, the won't be parsed and is report only (for live XMLs). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- docs/formatdomain.rst | 7 +++++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 9 +++++++-- src/conf/domain_conf.h | 3 +++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 87fa8b617d..01572da542 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -7802,6 +7802,7 @@ Example: usage of the memory devices 0 2048 1048576 + 524288 @@ -7917,6 +7918,12 @@ Example: usage of the memory devices The total size exposed to the guest. Must respect ``block`` granulari= ty and be smaller than or equal to ``size``. =20 + ``current`` + Active XML for ``virtio-mem`` model may contain ``current`` element t= hat + reflects the current size of the corresponding virtio memory device. = The + element is formatted into live XML and never parsed, i.e. it is + output-only element. + :anchor:`` =20 IOMMU devices diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 9e7d74d43e..ec5bd91740 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -6698,6 +6698,11 @@ + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c84158d0f1..37cc3c3343 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25925,7 +25925,8 @@ virDomainMemorySourceDefFormat(virBuffer *buf, =20 static void virDomainMemoryTargetDefFormat(virBuffer *buf, - virDomainMemoryDef *def) + virDomainMemoryDef *def, + unsigned int flags) { g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); =20 @@ -25947,6 +25948,10 @@ virDomainMemoryTargetDefFormat(virBuffer *buf, =20 virBufferAsprintf(&childBuf, "%llu\n", def->requestedsize); + if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { + virBufferAsprintf(&childBuf, "%llu\n", + def->currentsize); + } } =20 virXMLFormatElement(buf, "target", NULL, &childBuf); @@ -25979,7 +25984,7 @@ virDomainMemoryDefFormat(virBuffer *buf, if (virDomainMemorySourceDefFormat(buf, def) < 0) return -1; =20 - virDomainMemoryTargetDefFormat(buf, def); + virDomainMemoryTargetDefFormat(buf, def, flags); =20 virDomainDeviceInfoFormat(buf, &def->info, flags); =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 9db15a87fb..b7f9e66487 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2496,6 +2496,9 @@ struct _virDomainMemoryDef { unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */ unsigned long long blocksize; /* kibibytes; valid only for VIRTIO_MEM = */ unsigned long long requestedsize; /* kibibytes; valid only for VIRTIO_= MEM */ + unsigned long long currentsize; /* kibibytes, valid for VIRTIO_MEM and + active domain only, only to report = never + parse */ bool readonly; /* valid only for NVDIMM */ =20 /* required for QEMU NVDIMM ppc64 support */ --=20 2.32.0 From nobody Thu May 9 14:20:14 2024 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=1632232371; cv=none; d=zohomail.com; s=zohoarc; b=J9/n2cvyW4kq6rsHWCPqXtu+//zQRvN+JWUDJT5LQmKCSsTRKguHz4IuOoLNnf1qFu2GQ1SHreC9qUuL6IV/rrNnvannA03lo+xZD/vn9u0ONuFlqJjGvnyNwvIEVzyF6ndyHdMSknu0qjc52wI/Dwdb66xrls4Bs6BogB/GAMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232371; h=Content-Type:Content-Transfer-Encoding:Cc: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=JZ2jHVOiiSkvyhoCz8XmhqcLPHU3NZe2Wlypwzk72GA=; b=WoxuFYkSYLLZXVxBHeAqtnKBcLpaeK0295Yw0ffMsmV39isH5zpWaa42W1M55LDFUvc1220y2xnxmuCNsvFpIR/i55hwIAdgGv5k67Y2uJQ/ksFtdYo729VcDEywM6kL99QRTcHqSi6p79VEx4t2GRGTyW7lUwoqLCB+4gMkJuY= 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) 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 1632232371040846.7310447692671; Tue, 21 Sep 2021 06:52:51 -0700 (PDT) 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-121-yrwDyZToMcOOAOGmjfqS1A-1; Tue, 21 Sep 2021 09:52:48 -0400 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 5D6DB56B29; Tue, 21 Sep 2021 13:52:42 +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 3FEA46B54E; Tue, 21 Sep 2021 13:52:42 +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 0CE181806D04; Tue, 21 Sep 2021 13:52:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDqeYY004425 for ; Tue, 21 Sep 2021 09:52:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A5DE608BA; Tue, 21 Sep 2021 13:52:40 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8235560C2B; Tue, 21 Sep 2021 13:52:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232370; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=JZ2jHVOiiSkvyhoCz8XmhqcLPHU3NZe2Wlypwzk72GA=; b=fbifxY/PFgGIINNcjIx7/uO7XW6Q9IMS3xlnQEpK3Rj4AqJI4WiMOxyuGBb+SoWM1P5dVa QsX0a0u2Xie4ucFwV48X+qVrTnj5DRdfWflrsiyU0epGJEIW537k95WOGKoh1kGXaeMk8Y aFq5MufuvqGXQFwDaIKjM3RNqhTC3Uc= X-MC-Unique: yrwDyZToMcOOAOGmjfqS1A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 09/16] conf: Introduce virDomainMemoryFindByDeviceAlias() Date: Tue, 21 Sep 2021 15:51:25 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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) X-ZM-MESSAGEID: 1632232371750100005 Content-Type: text/plain; charset="utf-8" This function will be needed in the next commit where we will want to find virtio-mem given its alias by QEMU on the monitor. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 17 +++++++++++++++++ src/conf/domain_conf.h | 5 +++++ src/libvirt_private.syms | 1 + 3 files changed, 23 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 37cc3c3343..b2b92726ab 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16621,6 +16621,23 @@ virDomainMemoryFindByDeviceInfo(virDomainDef *def, } =20 =20 +virDomainMemoryDef * +virDomainMemoryFindByDeviceAlias(virDomainDef *def, + const char *alias) +{ + size_t i; + + for (i =3D 0; i < def->nmems; i++) { + virDomainMemoryDef *tmp =3D def->mems[i]; + + if (STREQ_NULLABLE(tmp->info.alias, alias)) + return tmp; + } + + return NULL; +} + + /** * virDomainMemoryInsert: * diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index b7f9e66487..e054c1508e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3816,6 +3816,11 @@ virDomainMemoryFindByDeviceInfo(virDomainDef *dev, int *pos) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; =20 +virDomainMemoryDef * +virDomainMemoryFindByDeviceAlias(virDomainDef *def, + const char *alias) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; + int virDomainShmemDefInsert(virDomainDef *def, virDomainShmemDef *shmem) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; bool virDomainShmemDefEquals(virDomainShmemDef *src, virDomainShmemDef *ds= t) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d77502922d..21d10ec7a3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -508,6 +508,7 @@ virDomainMemballoonModelTypeFromString; virDomainMemballoonModelTypeToString; virDomainMemoryDefFree; virDomainMemoryFindByDef; +virDomainMemoryFindByDeviceAlias; virDomainMemoryFindByDeviceInfo; virDomainMemoryFindInactiveByDef; virDomainMemoryInsert; --=20 2.32.0 From nobody Thu May 9 14:20:14 2024 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=1632232392; cv=none; d=zohomail.com; s=zohoarc; b=On5IZVgmwrngSAC7ABrxdGbwqEXk1lPwvi5eMQ90xn4W4nYbYKF8xiobALKhKRH8q60iKqtpjN/eQnirUKBZMQmqIots/al+LhndbNirAAd+mE6bnDc1xXHDk1c/t6uwIKTev2sTOx5dW11W2BVe2TvYPYqsIx+NeapBExM+RYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232392; h=Content-Type:Content-Transfer-Encoding:Cc: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=9y0hETiDCb8y4PUUg75ZibMe1P9JBkQuOyPRDh+UTZg=; b=EbgK2Fe7WdfbN7IlCK1LZUhq6Pd9jzlTR8CPmuF2CtaabqD4ZxQo/qVuo36g9VZDkE6nMQkfclUPV48Njx5RDk1YpWZtBLKkCt28brEw825vYXsmszZn54QRqyGRIfzpg534nT6NgO8HKt1/KBg0lZYLnwwcGkk5VHQSEdPdYIQ= 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) 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 1632232392490671.8643959053534; Tue, 21 Sep 2021 06:53:12 -0700 (PDT) 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-111-X-MBsB2HMRCTbp7IhyAtdA-1; Tue, 21 Sep 2021 09:53:09 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EE6CD802937; Tue, 21 Sep 2021 13:52:58 +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 C764919730; Tue, 21 Sep 2021 13:52:58 +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 91D654EA3A; Tue, 21 Sep 2021 13:52:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDqvJP004569 for ; Tue, 21 Sep 2021 09:52:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 28B4C1B5C1; Tue, 21 Sep 2021 13:52:57 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id A119860C2B; Tue, 21 Sep 2021 13:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232391; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=9y0hETiDCb8y4PUUg75ZibMe1P9JBkQuOyPRDh+UTZg=; b=bQTuWv/eEfvgz/hWLC37cx+ELYiD6LmRixl1Nyn7N9PL5BbkKVoy67GD9UHFB7CFOMpX/d R6XeTE/zZkuX8o3utqFKhPBG6/h4Co9IXO7ilgCsjm6LRpI+fTF0GzgKZ0bY64xBmqe5VI uYTHedw08+F9+7w7FrM1ajrbPKO53/Y= X-MC-Unique: X-MBsB2HMRCTbp7IhyAtdA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 10/16] qemu: Wire up MEMORY_DEVICE_SIZE_CHANGE event Date: Tue, 21 Sep 2021 15:51:26 +0200 Message-Id: <772fd99c281211d59490c6d95b4e210b34dd2adc.1632231694.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.84 on 10.5.11.23 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) X-ZM-MESSAGEID: 1632232393879100001 Content-Type: text/plain; charset="utf-8" As advertised in previous commit, this event is delivered to us when virtio-mem module changes the allocation inside the guest. It comes with one attribute - size - which holds the new size of the virtio-mem (well, allocated size), in bytes. Mind you, this is not necessarily the same number as 'requested size'. It almost certainly will be when sizing the memory up, but it might not be when sizing the memory down - the guest kernel might be unable to free some blocks. This current size is reported in the domain XML as an output element only. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- examples/c/misc/event-test.c | 17 ++++++ include/libvirt/libvirt-domain.h | 24 +++++++++ src/conf/domain_event.c | 84 +++++++++++++++++++++++++++++ src/conf/domain_event.h | 10 ++++ src/libvirt_private.syms | 2 + src/qemu/qemu_domain.c | 3 ++ src/qemu/qemu_domain.h | 1 + src/qemu/qemu_driver.c | 37 +++++++++++++ src/qemu/qemu_monitor.c | 21 ++++++++ src/qemu/qemu_monitor.h | 20 +++++++ src/qemu/qemu_monitor_json.c | 24 +++++++++ src/qemu/qemu_process.c | 42 +++++++++++++++ src/remote/remote_daemon_dispatch.c | 30 +++++++++++ src/remote/remote_driver.c | 32 +++++++++++ src/remote/remote_protocol.x | 15 +++++- src/remote_protocol-structs | 7 +++ tools/virsh-domain.c | 20 +++++++ 17 files changed, 388 insertions(+), 1 deletion(-) diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c index 10c707e66b..1eec76c79d 100644 --- a/examples/c/misc/event-test.c +++ b/examples/c/misc/event-test.c @@ -982,6 +982,22 @@ myDomainEventMemoryFailureCallback(virConnectPtr conn = G_GNUC_UNUSED, } =20 =20 +static int +myDomainEventMemoryDeviceSizeChangeCallback(virConnectPtr conn G_GNUC_UNUS= ED, + virDomainPtr dom, + const char *alias, + unsigned long long size, + void *opaque G_GNUC_UNUSED) +{ + /* Casts to uint64_t to work around mingw not knowing %lld */ + printf("%s EVENT: Domain %s(%d) memory device size change: " + "alias: '%s' new size %" PRIu64 "'\n", + __func__, virDomainGetName(dom), virDomainGetID(dom), + alias, (uint64_t)size); + return 0; +} + + static int myDomainEventMigrationIterationCallback(virConnectPtr conn G_GNUC_UNUSED, virDomainPtr dom, @@ -1113,6 +1129,7 @@ struct domainEventData domainEvents[] =3D { DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_METADATA_CHANGE, myDomainEventMetadat= aChangeCallback), DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD, myDomainEventBlockTh= resholdCallback), DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE, myDomainEventMemoryFa= ilureCallback), + DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE, myDomainEv= entMemoryDeviceSizeChangeCallback), }; =20 struct storagePoolEventData { diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 7ef8ac51e5..eaafcc6b29 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -4655,6 +4655,29 @@ typedef void (*virConnectDomainEventMemoryFailureCal= lback)(virConnectPtr conn, void *opaque); =20 =20 +/** + * virConnectDomainEventMemoryDeviceSizeChangeCallback: + * @conn: connection object + * @dom: domain on which the event occurred + * @alias: memory device alias + * @size: new current size of memory device (in KiB) + * @opaque: application specified data + * + * The callback occurs when the guest acknowledges request to change size = of + * memory device (so far only virtio-mem model supports this). The @size t= hen + * reflects the new amount of guest visible memory (in kibibytes). + * + * The callback signature to use when registering for an event of type + * VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE with + * virConnectDomainEventRegisterAny(). + */ +typedef void (*virConnectDomainEventMemoryDeviceSizeChangeCallback)(virCon= nectPtr conn, + virDom= ainPtr dom, + const = char *alias, + unsign= ed long long size, + void *= opaque); + + /** * VIR_DOMAIN_EVENT_CALLBACK: * @@ -4698,6 +4721,7 @@ typedef enum { VIR_DOMAIN_EVENT_ID_METADATA_CHANGE =3D 23, /* virConnectDomainEventMe= tadataChangeCallback */ VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD =3D 24, /* virConnectDomainEventBl= ockThresholdCallback */ VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE =3D 25, /* virConnectDomainEventMe= moryFailureCallback */ + VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE =3D 26, /* virConnectDom= ainEventMemoryDeviceSizeChangeCallback */ =20 # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_EVENT_ID_LAST diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index 15a3baedf7..18539e348b 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -58,6 +58,7 @@ static virClass *virDomainEventDeviceRemovalFailedClass; static virClass *virDomainEventMetadataChangeClass; static virClass *virDomainEventBlockThresholdClass; static virClass *virDomainEventMemoryFailureClass; +static virClass *virDomainEventMemoryDeviceSizeChangeClass; =20 static void virDomainEventDispose(void *obj); static void virDomainEventLifecycleDispose(void *obj); @@ -81,6 +82,7 @@ static void virDomainEventDeviceRemovalFailedDispose(void= *obj); static void virDomainEventMetadataChangeDispose(void *obj); static void virDomainEventBlockThresholdDispose(void *obj); static void virDomainEventMemoryFailureDispose(void *obj); +static void virDomainEventMemoryDeviceSizeChangeDispose(void *obj); =20 static void virDomainEventDispatchDefaultFunc(virConnectPtr conn, @@ -277,6 +279,15 @@ struct _virDomainEventMemoryFailure { }; typedef struct _virDomainEventMemoryFailure virDomainEventMemoryFailure; =20 +struct _virDomainEventMemoryDeviceSizeChange { + virDomainEvent parent; + + char *alias; + unsigned long long size; +}; +typedef struct _virDomainEventMemoryDeviceSizeChange virDomainEventMemoryD= eviceSizeChange; +typedef virDomainEventMemoryDeviceSizeChange *virDomainEventMemoryDeviceSi= zeChangePtr; + static int virDomainEventsOnceInit(void) { @@ -324,6 +335,8 @@ virDomainEventsOnceInit(void) return -1; if (!VIR_CLASS_NEW(virDomainEventMemoryFailure, virDomainEventClass)) return -1; + if (!VIR_CLASS_NEW(virDomainEventMemoryDeviceSizeChange, virDomainEven= tClass)) + return -1; return 0; } =20 @@ -540,6 +553,14 @@ virDomainEventMemoryFailureDispose(void *obj) VIR_DEBUG("obj=3D%p", event); } =20 +static void +virDomainEventMemoryDeviceSizeChangeDispose(void *obj) +{ + virDomainEventMemoryDeviceSizeChangePtr event =3D obj; + VIR_DEBUG("obj=3D%p", event); + + g_free(event->alias); +} =20 static void * virDomainEventNew(virClass *klass, @@ -1664,6 +1685,57 @@ virDomainEventMemoryFailureNewFromDom(virDomainPtr d= om, recipient, action, flags); } =20 + +static virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNew(int id, + const char *name, + unsigned char *uuid, + const char *alias, + unsigned long long size) +{ + virDomainEventMemoryDeviceSizeChangePtr ev; + + if (virDomainEventsInitialize() < 0) + return NULL; + + if (!(ev =3D virDomainEventNew(virDomainEventMemoryDeviceSizeChangeCla= ss, + VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CH= ANGE, + id, name, uuid))) + return NULL; + + ev->alias =3D g_strdup(alias); + ev->size =3D size; + + return (virObjectEvent *)ev; +} + + +virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNewFromObj(virDomainObj *obj, + const char *alias, + unsigned long long size) +{ + return virDomainEventMemoryDeviceSizeChangeNew(obj->def->id, + obj->def->name, + obj->def->uuid, + alias, + size); +} + + +virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNewFromDom(virDomainPtr dom, + const char *alias, + unsigned long long size) +{ + return virDomainEventMemoryDeviceSizeChangeNew(dom->id, + dom->name, + dom->uuid, + alias, + size); +} + + static void virDomainEventDispatchDefaultFunc(virConnectPtr conn, virObjectEvent *event, @@ -1960,6 +2032,18 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn, goto cleanup; } =20 + case VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE: + { + virDomainEventMemoryDeviceSizeChangePtr memoryDeviceSizeChange= Event; + + memoryDeviceSizeChangeEvent =3D (virDomainEventMemoryDeviceSiz= eChangePtr)event; + ((virConnectDomainEventMemoryDeviceSizeChangeCallback)cb)(conn= , dom, + memo= ryDeviceSizeChangeEvent->alias, + memo= ryDeviceSizeChangeEvent->size, + cbop= aque); + goto cleanup; + } + case VIR_DOMAIN_EVENT_ID_LAST: break; } diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index 2a59e613cd..4a9f6b988b 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -267,6 +267,16 @@ virDomainEventMemoryFailureNewFromDom(virDomainPtr dom, int action, unsigned int flags); =20 +virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNewFromObj(virDomainObj *obj, + const char *alias, + unsigned long long size); + +virObjectEvent * +virDomainEventMemoryDeviceSizeChangeNewFromDom(virDomainPtr dom, + const char *alias, + unsigned long long size); + int virDomainEventStateRegister(virConnectPtr conn, virObjectEventState *state, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 21d10ec7a3..20eb39fb75 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -726,6 +726,8 @@ virDomainEventLifecycleNew; virDomainEventLifecycleNewFromDef; virDomainEventLifecycleNewFromDom; virDomainEventLifecycleNewFromObj; +virDomainEventMemoryDeviceSizeChangeNewFromDom; +virDomainEventMemoryDeviceSizeChangeNewFromObj; virDomainEventMemoryFailureNewFromDom; virDomainEventMemoryFailureNewFromObj; virDomainEventMetadataChangeNewFromDom; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 298f9b076d..325e45d009 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11033,6 +11033,9 @@ qemuProcessEventFree(struct qemuProcessEvent *event) case QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE: virObjectUnref(event->data); break; + case QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHANGE: + qemuMonitorMemoryDeviceSizeChangeFree(event->data); + break; case QEMU_PROCESS_EVENT_PR_DISCONNECT: case QEMU_PROCESS_EVENT_LAST: break; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index ae9d76ec4a..802de93e2e 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -438,6 +438,7 @@ typedef enum { QEMU_PROCESS_EVENT_PR_DISCONNECT, QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED, QEMU_PROCESS_EVENT_GUEST_CRASHLOADED, + QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHANGE, =20 QEMU_PROCESS_EVENT_LAST } qemuProcessEventType; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e6557ce997..eabbd53bd0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4255,6 +4255,40 @@ processGuestCrashloadedEvent(virQEMUDriver *driver, } =20 =20 +static void +processMemoryDeviceSizeChange(virQEMUDriver *driver, + virDomainObj *vm, + qemuMonitorMemoryDeviceSizeChange *info) +{ + virDomainMemoryDef *mem =3D NULL; + virObjectEvent *event =3D NULL; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + return; + + if (!virDomainObjIsActive(vm)) { + VIR_DEBUG("Domain is not running"); + goto endjob; + } + + mem =3D virDomainMemoryFindByDeviceAlias(vm->def, info->devAlias); + if (!mem) { + VIR_DEBUG("Memory device '%s' not found", info->devAlias); + goto endjob; + } + + mem->currentsize =3D VIR_DIV_UP(info->size, 1024); + + event =3D virDomainEventMemoryDeviceSizeChangeNewFromObj(vm, + info->devAlias, + mem->currentsiz= e); + + endjob: + qemuDomainObjEndJob(driver, vm); + virObjectEventStateQueue(driver->domainEventState, event); +} + + static void qemuProcessEventHandler(void *data, void *opaque) { struct qemuProcessEvent *processEvent =3D data; @@ -4304,6 +4338,9 @@ static void qemuProcessEventHandler(void *data, void = *opaque) case QEMU_PROCESS_EVENT_GUEST_CRASHLOADED: processGuestCrashloadedEvent(driver, vm); break; + case QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHANGE: + processMemoryDeviceSizeChange(driver, vm, processEvent->data); + break; case QEMU_PROCESS_EVENT_LAST: break; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 24119ef66e..5fc23f13d3 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1382,6 +1382,17 @@ qemuMonitorEmitSpiceMigrated(qemuMonitor *mon) } =20 =20 +void +qemuMonitorEmitMemoryDeviceSizeChange(qemuMonitor *mon, + const char *devAlias, + unsigned long long size) +{ + VIR_DEBUG("mon=3D%p, devAlias=3D'%s', size=3D%llu", mon, devAlias, siz= e); + + QEMU_MONITOR_CALLBACK(mon, domainMemoryDeviceSizeChange, mon->vm, devA= lias, size); +} + + void qemuMonitorEmitMemoryFailure(qemuMonitor *mon, qemuMonitorEventMemoryFailure *mfp) @@ -4266,6 +4277,16 @@ qemuMonitorEventRdmaGidStatusFree(qemuMonitorRdmaGid= Status *info) } =20 =20 +void +qemuMonitorMemoryDeviceSizeChangeFree(qemuMonitorMemoryDeviceSizeChangePtr= info) +{ + if (!info) + return; + + g_free(info->devAlias); +} + + int qemuMonitorSetWatchdogAction(qemuMonitor *mon, const char *action) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 0ebe73ac04..962b516542 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -101,6 +101,14 @@ struct _qemuMonitorRdmaGidStatus { }; =20 =20 +typedef struct _qemuMonitorMemoryDeviceSizeChange qemuMonitorMemoryDeviceS= izeChange; +typedef qemuMonitorMemoryDeviceSizeChange *qemuMonitorMemoryDeviceSizeChan= gePtr; +struct _qemuMonitorMemoryDeviceSizeChange { + char *devAlias; + unsigned long long size; +}; + + typedef enum { QEMU_MONITOR_ACTION_SHUTDOWN_KEEP, /* do not change the current settin= g */ QEMU_MONITOR_ACTION_SHUTDOWN_POWEROFF, @@ -187,6 +195,7 @@ struct _qemuMonitorJobInfo { char *qemuMonitorGuestPanicEventInfoFormatMsg(qemuMonitorEventPanicInfo *i= nfo); void qemuMonitorEventPanicInfoFree(qemuMonitorEventPanicInfo *info); void qemuMonitorEventRdmaGidStatusFree(qemuMonitorRdmaGidStatus *info); +void qemuMonitorMemoryDeviceSizeChangeFree(qemuMonitorMemoryDeviceSizeChan= ge *info); =20 typedef void (*qemuMonitorDestroyCallback)(qemuMonitor *mon, virDomainObj *vm, @@ -403,6 +412,12 @@ typedef void (*qemuMonitorDomainMemoryFailureCallback)= (qemuMonitor *mon, qemuMonitorEventMem= oryFailure *mfp, void *opaque); =20 +typedef int (*qemuMonitorDomainMemoryDeviceSizeChange)(qemuMonitor *mon, + virDomainObj *vm, + const char *alias, + unsigned long long = size, + void *opaque); + typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks; struct _qemuMonitorCallbacks { qemuMonitorEofNotifyCallback eofNotify; @@ -437,6 +452,7 @@ struct _qemuMonitorCallbacks { qemuMonitorDomainRdmaGidStatusChangedCallback domainRdmaGidStatusChang= ed; qemuMonitorDomainGuestCrashloadedCallback domainGuestCrashloaded; qemuMonitorDomainMemoryFailureCallback domainMemoryFailure; + qemuMonitorDomainMemoryDeviceSizeChange domainMemoryDeviceSizeChange; }; =20 qemuMonitor *qemuMonitorOpen(virDomainObj *vm, @@ -532,6 +548,10 @@ void qemuMonitorEmitSerialChange(qemuMonitor *mon, bool connected); void qemuMonitorEmitSpiceMigrated(qemuMonitor *mon); =20 +void qemuMonitorEmitMemoryDeviceSizeChange(qemuMonitor *mon, + const char *devAlias, + unsigned long long size); + void qemuMonitorEmitMemoryFailure(qemuMonitor *mon, qemuMonitorEventMemoryFailure *mfp); =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 4ef8abb537..fc3bb388be 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -112,6 +112,7 @@ static void qemuMonitorJSONHandleDumpCompleted(qemuMoni= tor *mon, virJSONValue *d static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitor *mon, = virJSONValue *data); static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitor *mon, vi= rJSONValue *data); static void qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, virJSONVa= lue *data); +static void qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, = virJSONValue *data); =20 typedef struct { const char *type; @@ -132,6 +133,7 @@ static qemuEventHandler eventHandlers[] =3D { { "GUEST_CRASHLOADED", qemuMonitorJSONHandleGuestCrashloaded, }, { "GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic, }, { "JOB_STATUS_CHANGE", qemuMonitorJSONHandleJobStatusChange, }, + { "MEMORY_DEVICE_SIZE_CHANGE", qemuMonitorJSONHandleMemoryDeviceSizeCh= ange, }, { "MEMORY_FAILURE", qemuMonitorJSONHandleMemoryFailure, }, { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, }, { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, }, @@ -1313,6 +1315,28 @@ qemuMonitorJSONHandleSpiceMigrated(qemuMonitor *mon, } =20 =20 +static void +qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, + virJSONValue *data) +{ + const char *name; + unsigned long long size; + + if (!(name =3D virJSONValueObjectGetString(data, "id"))) { + VIR_WARN("missing device alias in MEMORY_DEVICE_SIZE_CHANGE event"= ); + return; + } + + if (virJSONValueObjectGetNumberUlong(data, "size", &size) < 0) { + VIR_WARN("missing new size for '%s' in MEMORY_DEVICE_SIZE_CHANGE e= vent", name); + return; + } + + + qemuMonitorEmitMemoryDeviceSizeChange(mon, name, size); +} + + static void qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, virJSONValue *data) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 07bd7e928a..8ca496cfb4 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1833,6 +1833,47 @@ qemuProcessHandleMemoryFailure(qemuMonitor *mon G_GN= UC_UNUSED, } =20 =20 +static int +qemuProcessHandleMemoryDeviceSizeChange(qemuMonitor *mon G_GNUC_UNUSED, + virDomainObj *vm, + const char *devAlias, + unsigned long long size, + void *opaque) +{ + virQEMUDriver *driver =3D opaque; + struct qemuProcessEvent *processEvent =3D NULL; + qemuMonitorMemoryDeviceSizeChange *info =3D NULL; + int ret =3D -1; + + virObjectLock(vm); + + VIR_DEBUG("Memory device '%s' changed size to '%llu' in domain '%s'", + devAlias, size, vm->def->name); + + info =3D g_new0(qemuMonitorMemoryDeviceSizeChange, 1); + info->devAlias =3D g_strdup(devAlias); + info->size =3D size; + + processEvent =3D g_new0(struct qemuProcessEvent, 1); + processEvent->eventType =3D QEMU_PROCESS_EVENT_MEMORY_DEVICE_SIZE_CHAN= GE; + processEvent->vm =3D virObjectRef(vm); + processEvent->data =3D g_steal_pointer(&info); + + if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) { + qemuProcessEventFree(processEvent); + virObjectUnref(vm); + goto cleanup; + } + + processEvent =3D NULL; + ret =3D 0; + cleanup: + qemuProcessEventFree(processEvent); + virObjectUnlock(vm); + return ret; +} + + static qemuMonitorCallbacks monitorCallbacks =3D { .eofNotify =3D qemuProcessHandleMonitorEOF, .errorNotify =3D qemuProcessHandleMonitorError, @@ -1866,6 +1907,7 @@ static qemuMonitorCallbacks monitorCallbacks =3D { .domainRdmaGidStatusChanged =3D qemuProcessHandleRdmaGidStatusChanged, .domainGuestCrashloaded =3D qemuProcessHandleGuestCrashloaded, .domainMemoryFailure =3D qemuProcessHandleMemoryFailure, + .domainMemoryDeviceSizeChange =3D qemuProcessHandleMemoryDeviceSizeCha= nge, }; =20 static void diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 0bac7d4f51..bcfeadc2ae 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1334,6 +1334,35 @@ remoteRelayDomainEventMemoryFailure(virConnectPtr co= nn, } =20 =20 +static int +remoteRelayDomainEventMemoryDeviceSizeChange(virConnectPtr conn, + virDomainPtr dom, + const char *alias, + unsigned long long size, + void *opaque) +{ + daemonClientEventCallback *callback =3D opaque; + remote_domain_event_memory_device_size_change_msg data; + + if (callback->callbackID < 0 || + !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) + return -1; + + /* build return data */ + memset(&data, 0, sizeof(data)); + data.callbackID =3D callback->callbackID; + data.alias =3D g_strdup(alias); + data.size =3D size; + make_nonnull_domain(&data.dom, dom); + + remoteDispatchObjectEventSend(callback->client, remoteProgram, + REMOTE_PROC_DOMAIN_EVENT_MEMORY_DEVICE_S= IZE_CHANGE, + (xdrproc_t)xdr_remote_domain_event_memor= y_device_size_change_msg, + &data); + return 0; +} + + static virConnectDomainEventGenericCallback domainEventCallbacks[] =3D { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot), @@ -1361,6 +1390,7 @@ static virConnectDomainEventGenericCallback domainEve= ntCallbacks[] =3D { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMetadataChange), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockThreshold), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMemoryFailure), + VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMemoryDeviceSizeChange= ), }; =20 G_STATIC_ASSERT(G_N_ELEMENTS(domainEventCallbacks) =3D=3D VIR_DOMAIN_EVENT= _ID_LAST); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 83ea33e91b..719fcf4297 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -410,6 +410,10 @@ remoteDomainBuildEventMemoryFailure(virNetClientProgra= m *prog, void *evdata, void *opaque); =20 static void +remoteDomainBuildEventMemoryDeviceSizeChange(virNetClientProgram *prog, + virNetClient *client, + void *evdata, void *opaque); +static void remoteConnectNotifyEventConnectionClosed(virNetClientProgram *prog G_GNUC_= UNUSED, virNetClient *client G_GNUC_UNUSE= D, void *evdata, void *opaque); @@ -624,6 +628,10 @@ static virNetClientProgramEvent remoteEvents[] =3D { remoteDomainBuildEventMemoryFailure, sizeof(remote_domain_event_memory_failure_msg), (xdrproc_t)xdr_remote_domain_event_memory_failure_msg }, + { REMOTE_PROC_DOMAIN_EVENT_MEMORY_DEVICE_SIZE_CHANGE, + remoteDomainBuildEventMemoryDeviceSizeChange, + sizeof(remote_domain_event_memory_device_size_change_msg), + (xdrproc_t)xdr_remote_domain_event_memory_device_size_change_msg }, }; =20 static void @@ -5436,6 +5444,30 @@ remoteDomainBuildEventMemoryFailure(virNetClientProg= ram *prog G_GNUC_UNUSED, } =20 =20 +static void +remoteDomainBuildEventMemoryDeviceSizeChange(virNetClientProgram *prog G_G= NUC_UNUSED, + virNetClient *client G_GNUC_U= NUSED, + void *evdata, void *opaque) +{ + virConnectPtr conn =3D opaque; + remote_domain_event_memory_device_size_change_msg *msg =3D evdata; + struct private_data *priv =3D conn->privateData; + virDomainPtr dom; + virObjectEvent *event =3D NULL; + + if (!(dom =3D get_nonnull_domain(conn, msg->dom))) + return; + + event =3D virDomainEventMemoryDeviceSizeChangeNewFromDom(dom, + msg->alias, + msg->size); + + virObjectUnref(dom); + + virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackI= D); +} + + static int remoteStreamSend(virStreamPtr st, const char *data, diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 296610a94d..60010778ca 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3893,6 +3893,13 @@ struct remote_domain_start_dirty_rate_calc_args { }; =20 =20 +struct remote_domain_event_memory_device_size_change_msg { + int callbackID; + remote_nonnull_domain dom; + remote_nonnull_string alias; + unsigned hyper size; +}; + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -6892,5 +6899,11 @@ enum remote_procedure { * @acl: network:write * @acl: network:start */ - REMOTE_PROC_NETWORK_CREATE_XML_FLAGS =3D 437 + REMOTE_PROC_NETWORK_CREATE_XML_FLAGS =3D 437, + + /** + * @generate: both + * @acl: none + */ + REMOTE_PROC_DOMAIN_EVENT_MEMORY_DEVICE_SIZE_CHANGE =3D 438 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index de06895d53..dbef4ace79 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -3235,6 +3235,12 @@ struct remote_domain_start_dirty_rate_calc_args { int seconds; u_int flags; }; +struct remote_domain_event_memory_device_size_change_msg { + int callbackID; + remote_nonnull_domain dom; + remote_nonnull_string alias; + uint64_t size; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3673,4 +3679,5 @@ enum remote_procedure { REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT =3D 435, REMOTE_PROC_NODE_DEVICE_IS_ACTIVE =3D 436, REMOTE_PROC_NETWORK_CREATE_XML_FLAGS =3D 437, + REMOTE_PROC_DOMAIN_EVENT_MEMORY_DEVICE_SIZE_CHANGE =3D 438, }; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f876f30cc5..5150c216d7 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13220,6 +13220,24 @@ virshEventMemoryFailurePrint(virConnectPtr conn G_= GNUC_UNUSED, } =20 =20 +static void +virshEventMemoryDeviceSizeChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *alias, + unsigned long long size, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, + _("event 'memory-device-size-change' for domain '%s'= :\n" + "alias: %s\nsize: %llu\n"), + virDomainGetName(dom), alias, size); + + virshEventPrint(opaque, &buf); +} + + virshDomainEventCallback virshDomainEventCallbacks[] =3D { { "lifecycle", VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), }, @@ -13271,6 +13289,8 @@ virshDomainEventCallback virshDomainEventCallbacks[= ] =3D { VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockThresholdPrint), }, { "memory-failure", VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryFailurePrint), }, + { "memory-device-size-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryDeviceSizeChangePrint), }, }; G_STATIC_ASSERT(VIR_DOMAIN_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshDomainEv= entCallbacks)); =20 --=20 2.32.0 From nobody Thu May 9 14:20:14 2024 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=1632232412; cv=none; d=zohomail.com; s=zohoarc; b=hxd1kbcwzV6/gwMfK3Sx7zAFG28cYGfQmvMynVfOvEm2Cuno3LVyqKTnja8eIoXh4YMUozviuBduHJ77/MsscNI8XP7BmgMr2CVcHVa858mcOgnL8nTo7m5YGhPuJYBmS5LornLWo1SxW8V793SYThw2o3DK5oYgvP0rufYUaIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232412; h=Content-Type:Content-Transfer-Encoding:Cc: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=N4h6+IM7mZvCPQb5/dpTLF/prqJ4P+qFS7BcMWRb14g=; b=O+IqoAXednK0s7hnr2D4rF0y3LdR0UMKxQRiMBKKsoCB8JEj2Gcx/x+fXLqwWLscQENBDcJ8cnQ2IDkLEplk0lsWAjD3RvrvbMrHmu54maGxLYqG9/zPU8qehhNIO+Oxzr7d6RpxtfHIZdhorlqMGi4JWUP/wNYfQo2MJrgfaD8= 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) 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 1632232412835185.21098435932686; Tue, 21 Sep 2021 06:53:32 -0700 (PDT) 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-593-PZaJdnPrOo6zwnfJA64BBQ-1; Tue, 21 Sep 2021 09:53:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70A1D1019996; Tue, 21 Sep 2021 13:53:25 +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 5535B60C2B; Tue, 21 Sep 2021 13:53:25 +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 EFE271819AC1; Tue, 21 Sep 2021 13:53:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDrNAq004766 for ; Tue, 21 Sep 2021 09:53:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7B00060938; Tue, 21 Sep 2021 13:53:23 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id C945B5BAE4; Tue, 21 Sep 2021 13:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232411; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=N4h6+IM7mZvCPQb5/dpTLF/prqJ4P+qFS7BcMWRb14g=; b=L1i57RG9To+YtY6b3h873zoPmG8PdJDhPMRvyO9LVg815WuZJNVZRWrGH/bxqNCf31lId6 lurfk7y2NaqmC3awYyddO9COCQ/KuAVTGk2AVpaYu7583/6j8/1TVkS/TAUeQj3oFzkOHz N6lOO7Mwmnz1uL4K3m2ITHa7/hI99Ko= X-MC-Unique: PZaJdnPrOo6zwnfJA64BBQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 11/16] qemu: Refresh the current size of virtio-mem on monitor reconnect Date: Tue, 21 Sep 2021 15:51:27 +0200 Message-Id: <4c72f6afe078982b0cfc176f041acdb000f40575.1632231694.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.13 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) X-ZM-MESSAGEID: 1632232413830100001 Content-Type: text/plain; charset="utf-8" If the QEMU driver restarts it loses the track of the current size of virtio-mem (because it's runtime type of information and thus not stored in XML) and therefore, we have to refresh it when reconnecting to the domain monitor. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_domain.c | 20 +++++++++++-- src/qemu/qemu_monitor.h | 3 ++ src/qemu/qemu_monitor_json.c | 58 ++++++++++++++++++++++-------------- src/qemu/qemu_process.c | 3 ++ 4 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 325e45d009..00c6ae877c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8375,9 +8375,23 @@ qemuDomainUpdateMemoryDeviceInfo(virQEMUDriver *driv= er, if (!(dimm =3D virHashLookup(meminfo, mem->info.alias))) continue; =20 - mem->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM; - mem->info.addr.dimm.slot =3D dimm->slot; - mem->info.addr.dimm.base =3D dimm->address; + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + mem->currentsize =3D VIR_DIV_UP(dimm->size, 1024); + break; + + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + mem->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM; + mem->info.addr.dimm.slot =3D dimm->slot; + mem->info.addr.dimm.base =3D dimm->address; + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } } =20 virHashFree(meminfo); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 962b516542..648fe293ed 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1385,10 +1385,13 @@ int qemuMonitorSetIOThread(qemuMonitor *mon, =20 typedef struct _qemuMonitorMemoryDeviceInfo qemuMonitorMemoryDeviceInfo; struct _qemuMonitorMemoryDeviceInfo { + /* For pc-dimm */ unsigned long long address; unsigned int slot; bool hotplugged; bool hotpluggable; + /* For virtio-mem */ + unsigned long long size; /* in bytes */ }; =20 int qemuMonitorGetMemoryDeviceInfo(qemuMonitor *mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index fc3bb388be..1b98baa4c7 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7978,7 +7978,6 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, virJSONValue *cmd; virJSONValue *reply =3D NULL; virJSONValue *data =3D NULL; - qemuMonitorMemoryDeviceInfo *meminfo =3D NULL; size_t i; =20 if (!(cmd =3D qemuMonitorJSONMakeCommand("query-memory-devices", NULL)= )) @@ -7999,6 +7998,9 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, =20 for (i =3D 0; i < virJSONValueArraySize(data); i++) { virJSONValue *elem =3D virJSONValueArrayGet(data, i); + g_autofree qemuMonitorMemoryDeviceInfo *meminfo =3D NULL; + virJSONValue *dimminfo; + const char *devalias; const char *type; =20 if (!(type =3D virJSONValueObjectGetString(elem, "type"))) { @@ -8008,26 +8010,26 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, goto cleanup; } =20 + if (!(dimminfo =3D virJSONValueObjectGetObject(elem, "data"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-memory-devices reply data doesn't " + "contain enum data")); + goto cleanup; + } + + /* While 'id' attribute is marked as optional in QEMU's QAPI + * specification, Libvirt always sets it. Thus we can fail if not + * present. */ + if (!(devalias =3D virJSONValueObjectGetString(dimminfo, "id"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("dimm memory info data is missing 'id'")); + goto cleanup; + } + + meminfo =3D g_new0(qemuMonitorMemoryDeviceInfo, 1); + /* dimm memory devices */ if (STREQ(type, "dimm")) { - virJSONValue *dimminfo; - const char *devalias; - - if (!(dimminfo =3D virJSONValueObjectGetObject(elem, "data")))= { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-memory-devices reply data doesn't " - "contain enum data")); - goto cleanup; - } - - if (!(devalias =3D virJSONValueObjectGetString(dimminfo, "id")= )) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("dimm memory info data is missing 'id'")); - goto cleanup; - } - - meminfo =3D g_new0(qemuMonitorMemoryDeviceInfo, 1); - if (virJSONValueObjectGetNumberUlong(dimminfo, "addr", &meminfo->address) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -8058,17 +8060,27 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, =20 } =20 - if (virHashAddEntry(info, devalias, meminfo) < 0) + } else if (STREQ(type, "virtio-mem")) { + if (virJSONValueObjectGetNumberUlong(dimminfo, "size", + &meminfo->size) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing size in virtio memory = info")); goto cleanup; - - meminfo =3D NULL; + } + } else { + /* type not handled yet */ + continue; } + + if (virHashAddEntry(info, devalias, meminfo) < 0) + goto cleanup; + + meminfo =3D NULL; } =20 ret =3D 0; =20 cleanup: - VIR_FREE(meminfo); virJSONValueFree(cmd); virJSONValueFree(reply); return ret; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8ca496cfb4..b2ac5937ec 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8718,6 +8718,9 @@ qemuProcessReconnect(void *opaque) =20 qemuDomainVcpuPersistOrder(obj->def); =20 + if (qemuDomainUpdateMemoryDeviceInfo(driver, obj, QEMU_ASYNC_JOB_NONE)= < 0) + goto error; + if (qemuProcessDetectIOThreadPIDs(driver, obj, QEMU_ASYNC_JOB_NONE) < = 0) goto error; =20 --=20 2.32.0 From nobody Thu May 9 14:20:14 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=1632232414; cv=none; d=zohomail.com; s=zohoarc; b=h8nUt9QMDcOzOQulQfrkyZZILnvFF8X8MIoX5Ksf9xMVkBP+55JgwOa5Nlh5D9WC5AcR2kbq6NZmwkTk7jldX+RgOmMYyUkZO3KdexsgRdQFmHlitQU1OKmOKHkNB6JtqCStXE7JoeeNdL8vveRddVGCEbnrx2ZQ80utu0UZStk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232414; h=Content-Type:Content-Transfer-Encoding:Cc: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=KCzoJGA4RsmClD6D3qRw9x+JqjHbQ1ufYdqL81XadAQ=; b=gEqvppdQ1Lw4kzF6mqRtebsncF2o/hr1Yym0rlMQGUQOI5ApT8lXNX2t9r7K2lv/u91ugJpHCGi9MPu+MfiTiLqKge87RSLsqWAyIgee9wfvh2p9BMXL3fPdhkzKzlZiux00qoaSfcrCaEDo4k1+ClVmWv5pWQrcKCP2Rol+Nzk= 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 1632232414303463.14939842913225; Tue, 21 Sep 2021 06:53:34 -0700 (PDT) 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-574-GNfkRxRmPjCK2ryuoHoEvA-1; Tue, 21 Sep 2021 09:53:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A1771084684; Tue, 21 Sep 2021 13:53:26 +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 2E4FF6D995; Tue, 21 Sep 2021 13:53:26 +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 F15CB4EA3F; Tue, 21 Sep 2021 13:53:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDrO8r004784 for ; Tue, 21 Sep 2021 09:53:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6DF7A60938; Tue, 21 Sep 2021 13:53:24 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5E6960877; Tue, 21 Sep 2021 13:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232413; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=KCzoJGA4RsmClD6D3qRw9x+JqjHbQ1ufYdqL81XadAQ=; b=TdKze+c55zGZDqfG26/IHMY1MpTpraEPQL6a1ujvOnMRqMLblDjtXaipIi1jS31QkVqL8+ HpdTFtcieCPYXufRhnkSgOFkdZWXfldnXHJH8F9UMO+sBcSOapjb0TOfiLBwQyI8YUKHqZ 7HzysaKhRdFnVVBDZmGJLi4GukdS6W4= X-MC-Unique: GNfkRxRmPjCK2ryuoHoEvA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 12/16] qemu: Account for both memballoon and virtio-mem Date: Tue, 21 Sep 2021 15:51:28 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.11 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) X-ZM-MESSAGEID: 1632232416065100001 Content-Type: text/plain; charset="utf-8" Reporting how much memory is exposed to the guest happens under which is taken from def->mem.cur_balloon. The reported amount should account for both balloon size and the sum of @currentsize of all virtio-mems. For instance, if domain has 4GiB via balloon and additional 2GiB via virtio-mem, then the domain XML should report 6GiB. The same applies for domain statistics. The way to achieve this is to account for either balloon or virtio-mem when the size of the other is changed, e.g. on balloon change we have to add all @currentsize (for non virtio-mem these will be zero, so the check for memory model is needless, but makes it more obvious what's happening), and vice versa. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 9 +++++++++ src/qemu/qemu_process.c | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index eabbd53bd0..8bae2d014d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4262,6 +4262,7 @@ processMemoryDeviceSizeChange(virQEMUDriver *driver, { virDomainMemoryDef *mem =3D NULL; virObjectEvent *event =3D NULL; + unsigned long long balloon; =20 if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) return; @@ -4277,7 +4278,15 @@ processMemoryDeviceSizeChange(virQEMUDriver *driver, goto endjob; } =20 + /* If this looks weird it's because it is. The balloon size + * as reported by QEMU does not include any of @currentsize. + * It really contains just the balloon size. But in domain + * definition we want to report also sum of @currentsize. Do + * a bit of math to fix the domain definition. */ + balloon =3D vm->def->mem.cur_balloon - mem->currentsize; mem->currentsize =3D VIR_DIV_UP(info->size, 1024); + balloon +=3D mem->currentsize; + vm->def->mem.cur_balloon =3D balloon; =20 event =3D virDomainEventMemoryDeviceSizeChangeNewFromObj(vm, info->devAlias, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b2ac5937ec..f8e7345329 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1213,10 +1213,22 @@ qemuProcessHandleBalloonChange(qemuMonitor *mon G_G= NUC_UNUSED, virQEMUDriver *driver =3D opaque; virObjectEvent *event =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + size_t i; =20 virObjectLock(vm); event =3D virDomainEventBalloonChangeNewFromObj(vm, actual); =20 + /* We want the balloon size stored in domain definition to + * account for the actual size of virtio-mem too. But the + * balloon size as reported by QEMU (@actual) contains just + * the balloon size without any virtio-mem. Do a wee bit of + * math to fix it. */ + VIR_DEBUG("balloon size before fix is %lld", actual); + for (i =3D 0; i < vm->def->nmems; i++) { + if (vm->def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_= MEM) + actual +=3D vm->def->mems[i]->currentsize; + } + VIR_DEBUG("Updating balloon from %lld to %lld kb", vm->def->mem.cur_balloon, actual); vm->def->mem.cur_balloon =3D actual; @@ -2343,6 +2355,7 @@ qemuProcessRefreshBalloonState(virQEMUDriver *driver, int asyncJob) { unsigned long long balloon; + size_t i; int rc; =20 /* if no ballooning is available, the current size equals to the curre= nt @@ -2359,6 +2372,18 @@ qemuProcessRefreshBalloonState(virQEMUDriver *driver, if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) return -1; =20 + /* We want the balloon size stored in domain definition to + * account for the actual size of virtio-mem too. But the + * balloon size as reported by QEMU (@balloon) contains just + * the balloon size without any virtio-mem. Do a wee bit of + * math to fix it. */ + VIR_DEBUG("balloon size before fix is %lld", balloon); + for (i =3D 0; i < vm->def->nmems; i++) { + if (vm->def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_= MEM) + balloon +=3D vm->def->mems[i]->currentsize; + } + VIR_DEBUG("Updating balloon from %lld to %lld kb", + vm->def->mem.cur_balloon, balloon); vm->def->mem.cur_balloon =3D balloon; =20 return 0; --=20 2.32.0 From nobody Thu May 9 14:20:14 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=1632232417; cv=none; d=zohomail.com; s=zohoarc; b=KZy3cFcHZTZuhqsVWWbn4LDyVeeFK8UmiSkaiZBPtu0HtMYOAcGHZolLoPGXquyMAbviJaKbWTHENfi0ysHGzVif0qFyOd9k5lYzu/lo1v30M6BYsgKUKayX49YGP0QNZnyeU7r19Lwq7/CTLdz4wG2K88udpb1KBixEH1HY3AQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232417; h=Content-Type:Content-Transfer-Encoding:Cc: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=2bCnKc36GFv2srPQm5PjU2+Ypzxf2oOE/X86fm67I9w=; b=LZ3kEVM2k5r5abU/zyB/YAXBKLn/E1Yrp0wqKFHlD5MHCXRduGB5GiJEtGdojHQhIHXj5ztP3oEAfaY1nnSRiobr2lTpyzHijCC40wbOHWF5tlKKj9l1dMr8tc2pOYTYcUh2KRU5u86rOLR5vyjDv74K4aOwxwXtM6PBm1gdrVo= 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 1632232417013108.55206093660263; Tue, 21 Sep 2021 06:53:37 -0700 (PDT) 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-36-o-kMetybOB-eBjj0uc6rhg-1; Tue, 21 Sep 2021 09:53:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 137841084685; Tue, 21 Sep 2021 13:53:29 +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 EA05260877; Tue, 21 Sep 2021 13:53:28 +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 B8D1B4EA43; Tue, 21 Sep 2021 13:53:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDrPXY004791 for ; Tue, 21 Sep 2021 09:53:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6161160938; Tue, 21 Sep 2021 13:53:25 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id B952960877; Tue, 21 Sep 2021 13:53:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232416; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=2bCnKc36GFv2srPQm5PjU2+Ypzxf2oOE/X86fm67I9w=; b=YPwXKY65bFQhvt/OgkKqhJvT5dkoS9kiMxXzy4ZuByE/rNJ0z7P+r1Q6n6Sk4C5PIZcndr K3zE4ljXTQSjOGdZ7x2tzZZEH+mEJTiCPkexYkxRmdf/b3ciDNkE8dx8sn7RxV2slBC/GO 2g/7zfJplQp+FSzphCdwbMsTWrRMqAw= X-MC-Unique: o-kMetybOB-eBjj0uc6rhg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 13/16] qemuDomainSetMemoryFlags: Take virtio-mem into consideration Date: Tue, 21 Sep 2021 15:51:29 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.13 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) X-ZM-MESSAGEID: 1632232418600100001 Content-Type: text/plain; charset="utf-8" The qemuDomainSetMemoryFlags() allows for memballoon () changes for both active and inactive guests. And just before doing any change, we have to make sure that the new size is not greater than the total memory (). However, the total memory includes not only the regular guest memory, but also sum of maximum sizes of all virtio-mems (in fact all memory devices for that matter). But virtio-mem devices are modified differently (via virDomainUpdateDevice()) and thus the upper limit for new balloon size has to be lowered. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8bae2d014d..d5f9560ee4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2388,12 +2388,28 @@ static int qemuDomainSetMemoryFlags(virDomainPtr do= m, unsigned long newmem, } else { /* resize the current memory */ unsigned long oldmax =3D 0; + size_t i; =20 - if (def) + if (def) { oldmax =3D virDomainDefGetMemoryTotal(def); + + /* While virtio-mem is regular mem from guest POV, it can't be + * modified through this API. */ + for (i =3D 0; i < def->nmems; i++) { + if (def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_VIR= TIO_MEM) + oldmax -=3D def->mems[i]->size; + } + } + if (persistentDef) { - if (!oldmax || oldmax > virDomainDefGetMemoryTotal(persistentD= ef)) + if (!def || oldmax > virDomainDefGetMemoryTotal(persistentDef)= ) { oldmax =3D virDomainDefGetMemoryTotal(persistentDef); + + for (i =3D 0; i < persistentDef->nmems; i++) { + if (persistentDef->mems[i]->model =3D=3D VIR_DOMAIN_ME= MORY_MODEL_VIRTIO_MEM) + oldmax -=3D persistentDef->mems[i]->size; + } + } } =20 if (newmem > oldmax) { --=20 2.32.0 From nobody Thu May 9 14:20:14 2024 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=1632232415; cv=none; d=zohomail.com; s=zohoarc; b=VLIrgO317rqkBCbvKwL3GZRA4VkaVnnEZ93heVVlgsTZnjdYUz3VcWqXNBhFWlj3u5aC13AJuZqn+dqg5k6LLyFX9zO78t+7XOOMSpxANUqEyZnrhTDh4KJpWjeasJhRnAqd6updrRWlK2gJmo6pxYa5aoQZbDTUPIlix98OKrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232415; h=Content-Type:Content-Transfer-Encoding:Cc: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=huSXUGBiN7erO3ojtyAXxURKxN3IySDuFze4FgbEy3k=; b=CQVqmR8tEyUOW8BDOPuxnau5xzVdlqgHPkP8IpGfqBeXRP2924KvcX3nNqvulwV5MD35X1Xct4FwTuwV/qOPX3WKGLvO3KGj5P3I3x0dA9Dv9Rjsc4Bxe99Xi2x187mHM5QbCHEYL3Qx085gLFKJtvz8qHpfc3FC42YiyMZeXVE= 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) 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 16322324158891018.9479460170467; Tue, 21 Sep 2021 06:53:35 -0700 (PDT) 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-493-c_MmVbtsOzu_5r7P4OfsGw-1; Tue, 21 Sep 2021 09:53:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1838196632B; Tue, 21 Sep 2021 13:53:27 +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 B21B65DEB8; Tue, 21 Sep 2021 13:53:27 +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 82F36181A1D1; Tue, 21 Sep 2021 13:53:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDrQEm004805 for ; Tue, 21 Sep 2021 09:53:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5643A60938; Tue, 21 Sep 2021 13:53:26 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADD1B5BAE4; Tue, 21 Sep 2021 13:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232414; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=huSXUGBiN7erO3ojtyAXxURKxN3IySDuFze4FgbEy3k=; b=F4+SeRUkEOb+zXJb4Oy/Pjra8YzNuiREmHqmBmuzXszIqVilnFdNva2p6vsxzcqFt7C6sT PCetma8xwLXIgI7Ayq8c5a2KlIZDFFvJKvVFmx32EnESScJnvFNN3Q0d2wM48kWO+lRlPx 9gwtU5Z7u10M76vjEJjGn3fH0GvJXX4= X-MC-Unique: c_MmVbtsOzu_5r7P4OfsGw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 14/16] virsh: Introduce update-memory-device command Date: Tue, 21 Sep 2021 15:51:30 +0200 Message-Id: <38c22294b53b24516c5987278a74e786e66c479b.1632231694.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.14 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) X-ZM-MESSAGEID: 1632232416401100003 Content-Type: text/plain; charset="utf-8" New 'update-memory-device' command is introduced which aims on making it user friendly to change device. So far I just need to change so I'm introducing --requested-size only; but the idea is that this is extensible for other cases too. For instance, want to change ? A new --my-element argument can be easily introduced. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- docs/manpages/virsh.rst | 30 ++++++++ tools/virsh-domain.c | 161 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 350ded2026..4c5341d00d 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -4919,6 +4919,36 @@ results as some fields may be autogenerated and thus= match devices other than expected. =20 =20 +update-memory-device +-------------------- + +**Syntax:** + +:: + + update-memory-device domain [--print-xml] [[--alias alias] | [--node no= de]] + [[--live] [--config] | [--current]] + [--requested-size size] + +This command finds ```` device inside given *domain*, changes +requested values and passes updated device XML to daemon. If *--print-xml*= is +specified then the device is not changed, but the updated device XML is pr= inted +to stdout. If there are more than one ```` devices in *domain* u= se +*--alias* or *--node* to select the desired one. + +If *--live* is specified, affect a running domain. +If *--config* is specified, affect the next startup of a persistent guest. +If *--current* is specified, it is equivalent to either *--live* or +*--config*, depending on the current state of the guest. +Both *--live* and *--config* flags may be given, but *--current* is +exclusive. Not specifying any flag is the same as specifying *--current*. + +If *--requested-size* is specified then ```` under memory targ= et is +changed to requested *size* (as scaled integer, see ``NOTES`` above). It +defaults to kibibytes if no suffix is provided. The option is valid only f= or +``virtio-mem`` memory device model. + + change-media ------------ =20 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 5150c216d7..906654674e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8968,6 +8968,161 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) return true; } =20 + +/* + * "update-memory-device" command + */ +static const vshCmdInfo info_update_memory_device[] =3D { + {.name =3D "help", + .data =3D N_("update memory device of a domain") + }, + {.name =3D "desc", + .data =3D N_("Update values of a memory device of a domain") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_update_memory_device[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + VIRSH_COMMON_OPT_DOMAIN_CONFIG, + VIRSH_COMMON_OPT_DOMAIN_LIVE, + VIRSH_COMMON_OPT_DOMAIN_CURRENT, + {.name =3D "print-xml", + .type =3D VSH_OT_BOOL, + .help =3D N_("print updated memory device XML instead of executing th= e change") + }, + {.name =3D "alias", + .type =3D VSH_OT_STRING, + .completer =3D virshDomainDeviceAliasCompleter, + .help =3D N_("memory device alias") + }, + {.name =3D "node", + .type =3D VSH_OT_INT, + .help =3D N_("memory device target node") + }, + {.name =3D "requested-size", + .type =3D VSH_OT_INT, + .help =3D N_("new value of size, as scaled integer (defa= ult KiB)") + }, + {.name =3D NULL} +}; + +static int +virshGetUpdatedMemoryXML(char **updatedMemoryXML, + vshControl *ctl, + const vshCmd *cmd, + virDomainPtr dom, + unsigned int flags) +{ + const char *alias =3D NULL; + bool nodeOpt =3D false; + unsigned int node =3D 0; + g_autoptr(xmlDoc) doc =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autofree char *xpath =3D NULL; + int nmems; + g_autofree xmlNodePtr *mems =3D NULL; + unsigned int domainXMLFlags =3D 0; + + if (flags & VIR_DOMAIN_AFFECT_CONFIG) + domainXMLFlags |=3D VIR_DOMAIN_XML_INACTIVE; + + if (virshDomainGetXMLFromDom(ctl, dom, domainXMLFlags, &doc, &ctxt) < = 0) + return -1; + + nodeOpt =3D vshCommandOptBool(cmd, "node"); + if (vshCommandOptStringReq(ctl, cmd, "alias", &alias) < 0 || + vshCommandOptUInt(ctl, cmd, "node", &node) < 0) { + return -1; + } + + if (nodeOpt) { + xpath =3D g_strdup_printf("/domain/devices/memory[./target/node=3D= '%u']", node); + } else if (alias) { + xpath =3D g_strdup_printf("/domain/devices/memory[./alias/@name=3D= '%s']", alias); + } else { + xpath =3D g_strdup("/domain/devices/memory"); + } + + nmems =3D virXPathNodeSet(xpath, ctxt, &mems); + if (nmems < 0) { + vshSaveLibvirtError(); + return -1; + } else if (nmems =3D=3D 0) { + vshError(ctl, _("no memory device found")); + return -1; + } else if (nmems > 1) { + vshError(ctl, _("multiple memory devices found, use --alias or --n= ode to select one")); + return -1; + } + + ctxt->node =3D mems[0]; + + if (vshCommandOptBool(cmd, "requested-size")) { + xmlNodePtr requestedSizeNode; + g_autofree char *kibibytesStr =3D NULL; + unsigned long long bytes =3D 0; + unsigned long kibibytes =3D 0; + + if (vshCommandOptScaledInt(ctl, cmd, "requested-size", &bytes, 102= 4, ULLONG_MAX) < 0) + return -1; + kibibytes =3D VIR_DIV_UP(bytes, 1024); + + requestedSizeNode =3D virXPathNode("./target/requested", ctxt); + + if (!requestedSizeNode) { + vshError(ctl, _("virtio-mem device is missing ")); + return -1; + } + + kibibytesStr =3D g_strdup_printf("%lu", kibibytes); + xmlNodeSetContent(requestedSizeNode, BAD_CAST kibibytesStr); + } + + if (!(*updatedMemoryXML =3D virXMLNodeToString(doc, mems[0]))) { + vshSaveLibvirtError(); + return -1; + } + + return 0; +} + +static bool +cmdUpdateMemoryDevice(vshControl *ctl, const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + bool config =3D vshCommandOptBool(cmd, "config"); + bool live =3D vshCommandOptBool(cmd, "live"); + bool current =3D vshCommandOptBool(cmd, "current"); + g_autofree char *updatedMemoryXML =3D NULL; + unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + VSH_EXCLUSIVE_OPTIONS("node", "alias"); + + if (config) + flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |=3D VIR_DOMAIN_AFFECT_LIVE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (virshGetUpdatedMemoryXML(&updatedMemoryXML, ctl, cmd, dom, flags) = < 0) + return false; + + if (vshCommandOptBool(cmd, "print-xml")) { + vshPrint(ctl, "%s", updatedMemoryXML); + } else { + if (virDomainUpdateDeviceFlags(dom, updatedMemoryXML, flags) < 0) + return false; + } + + return true; +} + + /* * "memtune" command */ @@ -14748,6 +14903,12 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_update_device, .flags =3D 0 }, + {.name =3D "update-memory-device", + .handler =3D cmdUpdateMemoryDevice, + .opts =3D opts_update_memory_device, + .info =3D info_update_memory_device, + .flags =3D 0 + }, {.name =3D "vcpucount", .handler =3D cmdVcpucount, .opts =3D opts_vcpucount, --=20 2.32.0 From nobody Thu May 9 14:20:14 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=1632232420; cv=none; d=zohomail.com; s=zohoarc; b=BN0bO+cVquagyCz63RuQtrq8/uYiZeiapaQoNDiHKlaoAy59g2rh7Pxl43xFK0elZ6SxP+U3Jx9URO9YKoVAMQYq80nJqwCSRcPUZN2LFA4GhVNy1LHPg2LtvoJIQ/mXghGSszXJ40BJsJ2EonoGCUiWbwYcemimWJIpAFxDbEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232420; h=Content-Type:Content-Transfer-Encoding:Cc: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=s0Vh+kK7xytfW2DCfEfKgXGZiksWaQusQll+x7zyLU4=; b=NrLLWtTXpTGGUuG1cbes9tndFJzLQEn69IkXn4FePYek9Dk2b87qC34czqjSX0tDoA3mILYMRbh0KBw7gE3TM6Nysq2Z58tPyvVhX9rHxhDf/jKx3LLi71Z+mJOCDFpqM0xsXCHSGTMuK3zOOLcrnVw4Ecwupgc7NuV7qME9D7M= 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 1632232420632441.14346675672493; Tue, 21 Sep 2021 06:53:40 -0700 (PDT) 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-190-3Kk2kIVsMRWxn7QJ9fV5Tg-1; Tue, 21 Sep 2021 09:53:38 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C996F1966329; Tue, 21 Sep 2021 13:53:29 +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 A9DDD177C0; Tue, 21 Sep 2021 13:53:29 +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 777764EA45; Tue, 21 Sep 2021 13:53:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDrRjX004828 for ; Tue, 21 Sep 2021 09:53:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 494E760877; Tue, 21 Sep 2021 13:53:27 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id A11715BAE3; Tue, 21 Sep 2021 13:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232419; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=s0Vh+kK7xytfW2DCfEfKgXGZiksWaQusQll+x7zyLU4=; b=ItM2z1dCrPUOFDszxI2I8fx7ocQfi+4HFBrA0Er6rHovP5Q8PWTAJDyMKrn7mpnzT0iRWx Oxu1ZyeUv4za2QifUWzjZnBbLbyNl/qeOfsKH8If/cUiDjweMQBWQ1H/x9tqFglDeYvN5Q Z3SBaqLNubx9p82Ax2HXAVomFlUdqQI= X-MC-Unique: 3Kk2kIVsMRWxn7QJ9fV5Tg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 15/16] news: document recent virtio memory addition Date: Tue, 21 Sep 2021 15:51:31 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.16 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) X-ZM-MESSAGEID: 1632232420957100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- NEWS.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index fd20e50d18..62af02b33e 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -29,6 +29,13 @@ v7.8.0 (unreleased) active. This information can also be retrieved with the new virsh comm= and ``nodedev-info``. =20 + * Introduce virtio-mem ```` model + + New virtio-mem model is introduced for ```` device which is a + paravirtualized mechanism of adding/removing memory to/from a VM. Use + ``virDomainUpdateDeviceFlags()`` API to adjust amount of memory or ``v= irsh + update-memory-device`` for convenience. + * **Improvements** =20 * **Bug fixes** --=20 2.32.0 From nobody Thu May 9 14:20:14 2024 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=1632232445; cv=none; d=zohomail.com; s=zohoarc; b=U0gSPjTASGWOKAfgWbZOUW92vMjqFNylM4NX/9zehkaMnyK9av9Hg6GgLaQlxJpD/QBINR/3yy2cHWkjEvJ3CZ1i90lQqUpHEFxVkiOh/gUFw4/Sy5wjtKGSx7+FS9UKnUgEQLA9k9O4cfsZczLDZ7MiBLx+VNMmqybfe+h4dEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632232445; h=Content-Type:Content-Transfer-Encoding:Cc: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=5Vr7xtZchMYJKtgaloUBkg9wcCFoqRpocUrkk7NGsFM=; b=OkF7bvBM+3/6LROtkn+Ezz9lHzEgQpuLCLTpZWFwVNtDVlbiINJNcENiONvd0yOdRt7XT1m9CSAsM5upDEtwB22dtc8xb9Djq5y+ttPLJZKL75MaNnWEtD3jUYGILduwoiabookJ29XLVxxq73y1ySfBMCKrIXH/3Kx46mr/TAI= 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) 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 1632232445172847.7611282122981; Tue, 21 Sep 2021 06:54:05 -0700 (PDT) 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-499-shPCPP4PMDCew2l_6hu4GA-1; Tue, 21 Sep 2021 09:53:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89CAB835DE6; Tue, 21 Sep 2021 13:53:30 +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 6BE2B60938; Tue, 21 Sep 2021 13:53:30 +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 3A6F21832DD5; Tue, 21 Sep 2021 13:53:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18LDrShn004841 for ; Tue, 21 Sep 2021 09:53:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3FA3960877; Tue, 21 Sep 2021 13:53:28 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94AE85BAE9; Tue, 21 Sep 2021 13:53:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632232443; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=5Vr7xtZchMYJKtgaloUBkg9wcCFoqRpocUrkk7NGsFM=; b=Nt/2GkUjVoL1pmGjj8lPrU1VwutrnrFI7gi4jKENUW0lQz1dgF3abQ6AhXwjhWsweETHjs HoJ7AtsgS2NMHjt17Sf8YVxEW6muxY/MO+jIQSefl9anaO3qcjUsiDoFNYnrnZ1RrF7xqO /+9xMHdK4OPx1tjDcYzUMu044TcfJ4E= X-MC-Unique: shPCPP4PMDCew2l_6hu4GA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v6 16/16] kbase: Document virtio-mem Date: Tue, 21 Sep 2021 15:51:32 +0200 Message-Id: <05cdc6fb5f5ad7b8e0439a44202d40e23738c7fb.1632231694.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: david@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.13 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) X-ZM-MESSAGEID: 1632232446440100001 Content-Type: text/plain; charset="utf-8" This commit adds new memorydevices.rst page which should serve all models of memory devices. Yet, I'm documenting virtio-mem quirks only. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- docs/kbase/index.rst | 4 + docs/kbase/memorydevices.rst | 150 +++++++++++++++++++++++++++++++++++ docs/kbase/meson.build | 1 + 3 files changed, 155 insertions(+) create mode 100644 docs/kbase/memorydevices.rst diff --git a/docs/kbase/index.rst b/docs/kbase/index.rst index 351ea2c93b..09b19ed1af 100644 --- a/docs/kbase/index.rst +++ b/docs/kbase/index.rst @@ -52,6 +52,10 @@ Usage `PCI topology <../pci-addresses.html>`__ Addressing schemes for PCI devices =20 +`Memory devices `__ + Memory devices and their use + + Internals / Debugging --------------------- =20 diff --git a/docs/kbase/memorydevices.rst b/docs/kbase/memorydevices.rst new file mode 100644 index 0000000000..7f58a4247b --- /dev/null +++ b/docs/kbase/memorydevices.rst @@ -0,0 +1,150 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Memory devices +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. contents:: + +Basics +=3D=3D=3D=3D=3D=3D + +Memory devices can be divided into two families: volatile and non-volatile. +The former is typical RAM memory: it's volatile and thus its contents does= n't +survive guest reboots or power cycles. The latter retains its contents acr= oss +reboots or power outages. + +In Libvirt, there are two models for volatile memory: + +* ``dimm`` model: + + :: + + + + 523264 + 0 + +
+ + +* ``virtio-mem`` model: + + :: + + + + 1048576 + 0 + 2048 + 524288 + +
+ + +Then there are two models for non-volatile memory: + +* ``nvdimm`` model: + + :: + + + + /tmp/nvdimm + + + 523264 + 0 + +
+ + +* ``virtio-pmem`` model: + + :: + + + + /tmp/virtio_pmem + + + 524288 + +
+ + + +Please note that (maybe somewhat surprisingly) virtio models go onto PCI b= us +instead of DIMM slots. + +Furthermore, DIMMs can have ```` element which configures backend= for +devices. For NVDIMMs the element is mandatory and reflects where the conte= nt +is saved. + +See `memory devices documentation <../formatdomain.html#elementsMemory>`_. + +``virtio-mem`` model +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The ``virtio-mem`` model can be viewed as revised memory balloon. It offers +adding and removing memory (without the actual hotplug of the device). It +solves problems that memory balloon can't solve on its own and thus is more +flexible than DIMM + balloon solution. ``virtio-mem`` is NUMA aware, and t= hus +memory can be inflated/deflated only for a subset of guest NUMA nodes. Al= so, +it works with chunks that are either exposed to guest or reclaimed from it. + +See https://virtio-mem.gitlab.io/ + +Under the hood, ``virtio-mem`` device is split into chunks of equal size w= hich +are then exposed to the guest. Either all of them or only a portion depend= ing +on user's request. Therefore there are three important sizes for +``virtio-mem``. All are to be found under ```` element: + +#. The maximum size the device can ever offer, exposed under ```` +#. The size of a single block, exposed under ```` +#. The current size exposed to the guest, exposed under ```` + +For instance, in the following example the maximum size is 4GiB, the block= size +is 2MiB and only 1GiB should be exposed to the guest: + + :: + + + + 4194304 + 2048 + 1048576 + + + +Please note that ```` must be an integer multiple of ```` +size or zero (no blocks exposed to the guest) and has to be less or equal = to +```` (all blocks exposed to the guest). Furthermore, QEMU recommend= s the +```` size to be as big as a Transparent Huge Page (usually 2MiB). + +To change the size exposed to the guest, users should pass memory device X= ML +with nothing but ```` changed into the +``virDomainUpdateDeviceFlags()`` API. For user's convenience this can be d= one +via virsh too: + + :: + + # virsh update-memory-device $dom --requested-size 2GiB + +If there are two or more ```` devices then ``--alias`` shall be u= sed +to tell virsh which memory device should be updated. + +For running guests there is fourth size that can be found under ````: + + :: + + 2097152 + +The ```` reflects the current size used by the guest. In general= it +can differ from ````. Reasons include guest kernel missing +``virtio-mem`` module and thus being unable to take offered memory, or gue= st +kernel being unable to free memory. Since ```` only reports siz= e to +users, the element is never parsed. It is formatted only into live XML. + +Since changing ```` allocation requires cooperation with guest +kernel, requests for change are not instant. Therefore, libvirt emits +``VIR_DOMAIN_EVENT_ID_MEMORY_DEVICE_SIZE_CHANGE`` event whenever current +allocation changed. diff --git a/docs/kbase/meson.build b/docs/kbase/meson.build index 73dc11837f..af067db453 100644 --- a/docs/kbase/meson.build +++ b/docs/kbase/meson.build @@ -10,6 +10,7 @@ docs_kbase_files =3D [ 'locking-lockd', 'locking', 'locking-sanlock', + 'memorydevices', 'merging_disk_image_chains', 'migrationinternals', 'qemu-core-dump', --=20 2.32.0