From nobody Sun May 5 16:31:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612797324; cv=none; d=zohomail.com; s=zohoarc; b=P6ai+uEL4ZSCMu3pk0avDBDLBbnDm+pJHYrmwf4IX8YbQtaiwGMOfn9v6VZ5uTm78vl0Mn5SinTmvvmK+cfMo9e1OvYJg048qyjX1dflWtqHo3GdlIn6Z6ypJvuNE/nL4BQ5zFJpLAkdoW7FmfPkV/W5Nc6g+pjefVibzF6D6UQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612797324; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=zzA5fDpzymyWqJP+IOIHaUNinTsNhcPy17ADvPVEqYo=; b=R1jWRvISZ4XXgCJWK7G62gOrwj27O/MdQeoRat4pSFIzrZdFx8JE/XxWCjlCILwwrCBASTWW52ywf/03pj1SnRFwh8Rx7Hzbtw1RGAFW9p4bmJjy/bLkxXpApWfYDh5oharScoYxdwSq9Jz4wqAPLwW0NfQSV5pz0GgX70jUO5A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612797324550505.6880928912135; Mon, 8 Feb 2021 07:15:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-264-Gw0L2l75MVG8KFsgCX1HMQ-1; Mon, 08 Feb 2021 10:15:20 -0500 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 078F8100CCC2; Mon, 8 Feb 2021 15:15:12 +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 77E5B5D9E2; Mon, 8 Feb 2021 15:15:10 +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 7E6564E58E; Mon, 8 Feb 2021 15:15:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 118FF3rB010604 for ; Mon, 8 Feb 2021 10:15:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2F9721002388; Mon, 8 Feb 2021 15:15:03 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.209]) by smtp.corp.redhat.com (Postfix) with ESMTP id A43FE10016F8 for ; Mon, 8 Feb 2021 15:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612797323; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zzA5fDpzymyWqJP+IOIHaUNinTsNhcPy17ADvPVEqYo=; b=flcPtDHGGy03kLvNYxC9jhskfuPoJo8TzxRIPrZriIzbeXAAbHqFcUXPPNhbISLyvKNsmm W2aO/8zbLHlECq4wad0/MkoG/pCDLj/pUPqib2j8gpEFjSUhswpuWFwX2gknPPNrHFGJNt 54pR90Jbex7B9OOYBIchgLeFzzRyoB4= X-MC-Unique: Gw0L2l75MVG8KFsgCX1HMQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] qemu: Release device address on failed hotplug Date: Mon, 8 Feb 2021 16:14:54 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.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) Content-Type: text/plain; charset="utf-8" A few commits back I've introduced new 'virtio-pmem' device. Since it's virtio it goes onto PCI bus. Therefore, on hotplug new PCI address is generated (or provided one is reserved). However, if hotplug fails (for whatever reason) the address needs to be released. This is different to 'dimm' type of address because for that type we don't keep a map of used slots rather generate one on each address assign request. The map is then thrown away. But for PCI addresses we keep internal state and thus has to keep it updated. Therefore, this new qemuDomainReleaseMemoryDeviceSlot() function is NOP for those models which use 'dimm' address type ('dimm' and 'nvdimm'). While I'm at it, let's release the address in case of hot unplug. Not that is supported (any such attempt fails with the following error: "virtio based memory devices cannot be unplugged" But if QEMU ever implements hot unplug then we don't have to remember to fix our code. Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- src/qemu/qemu_domain_address.c | 23 +++++++++++++++++++++++ src/qemu/qemu_domain_address.h | 3 +++ src/qemu/qemu_hotplug.c | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 1171dc5b14..68dbf9e95b 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -3122,6 +3122,29 @@ qemuDomainAssignMemoryDeviceSlot(virQEMUDriverPtr dr= iver, } =20 =20 +void +qemuDomainReleaseMemoryDeviceSlot(virDomainObjPtr vm, + virDomainMemoryDefPtr mem) +{ + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + /* We don't need to release anything. Slot map is not + * kept around. It's constructed every time when + * assigning new slot. */ + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + qemuDomainReleaseDeviceAddress(vm, &mem->info); + break; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + break; + } +} + + static int qemuDomainAssignMemorySlots(virDomainDefPtr def) { diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index 20a46160d5..bfd56e163e 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -60,6 +60,9 @@ int qemuDomainAssignMemoryDeviceSlot(virQEMUDriverPtr dri= ver, virDomainObjPtr vm, virDomainMemoryDefPtr mem); =20 +void qemuDomainReleaseMemoryDeviceSlot(virDomainObjPtr vm, + virDomainMemoryDefPtr mem); + int qemuDomainEnsureVirtioAddress(bool *releaseAddr, virDomainObjPtr vm, virDomainDeviceDefPtr dev, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 94c3df6368..dc2b46057c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2400,6 +2400,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, g_autofree char *devstr =3D NULL; g_autofree char *objalias =3D NULL; bool objAdded =3D false; + bool releaseaddr =3D false; bool teardownlabel =3D false; bool teardowncgroup =3D false; bool teardowndevice =3D false; @@ -2416,6 +2417,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, =20 if (qemuDomainAssignMemoryDeviceSlot(driver, vm, mem) < 0) goto cleanup; + releaseaddr =3D true; =20 /* in cases where we are using a VM with aliases generated according t= o the * index of the memory device we need to keep continue using that sche= me */ @@ -2492,6 +2494,8 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, if (teardowndevice && qemuDomainNamespaceTeardownMemory(vm, mem) < 0) VIR_WARN("Unable to remove memory device from /dev"); + if (releaseaddr) + qemuDomainReleaseMemoryDeviceSlot(vm, mem); } =20 virJSONValueFree(props); @@ -4457,6 +4461,8 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver, if (qemuProcessDestroyMemoryBackingPath(driver, vm, mem) < 0) VIR_WARN("Unable to destroy memory backing path"); =20 + qemuDomainReleaseMemoryDeviceSlot(vm, mem); + virDomainMemoryDefFree(mem); =20 /* fix the balloon size */ --=20 2.26.2