From nobody Sun Feb 8 17:41:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=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 --- 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