From nobody Mon Feb 9 08:56:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502516795963.2334985272785; Mon, 23 Apr 2018 09:55:16 -0700 (PDT) Received: from localhost ([::1]:54520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAek9-0001DU-KA for importer@patchew.org; Mon, 23 Apr 2018 12:55:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAehF-0007kE-IR for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAehD-0008PI-4q for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:09 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59166 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAehC-0008Ou-Uw; Mon, 23 Apr 2018 12:52:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 653A481A88C8; Mon, 23 Apr 2018 16:52:06 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1817F7C59; Mon, 23 Apr 2018 16:52:01 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:22 +0200 Message-Id: <20180423165126.15441-8-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:52:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:52:06 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 07/11] pc-dimm: move actual plug/unplug of a memory region to MemoryDevice X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Registering the memory region for migration has do be done by the owner. There could be cases, where we don't want to migrate the memory. Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 18 ++++++++++++++++++ hw/mem/pc-dimm.c | 5 ++--- include/hw/mem/memory-device.h | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 8535ddcb14..3e04f3954e 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -243,6 +243,24 @@ uint64_t get_plugged_memory_size(void) return size; } =20 +void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, + uint64_t addr) +{ + /* we expect a previous call to memory_device_get_free_addr() */ + g_assert(ms->device_memory); + + memory_region_add_subregion(&ms->device_memory->mr, + addr - ms->device_memory->base, mr); +} + +void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr) +{ + /* we expect a previous call to memory_device_get_free_addr() */ + g_assert(ms->device_memory); + + memory_region_del_subregion(&ms->device_memory->mr, mr); +} + static const TypeInfo memory_device_info =3D { .name =3D TYPE_MEMORY_DEVICE, .parent =3D TYPE_INTERFACE, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 8aa2d36ce9..0119c68e01 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -36,7 +36,6 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState *= machine, uint64_t align, Error **errp) { int slot; - MemoryHotplugState *hpms =3D machine->device_memory; PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); @@ -83,7 +82,7 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState *= machine, } trace_mhp_pc_dimm_assigned_slot(slot); =20 - memory_region_add_subregion(&hpms->mr, addr - hpms->base, mr); + memory_device_plug_region(machine, mr, addr); vmstate_register_ram(vmstate_mr, dev); =20 out: @@ -97,7 +96,7 @@ void pc_dimm_memory_unplug(DeviceState *dev, MachineState= *machine) MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); =20 - memory_region_del_subregion(&machine->device_memory->mr, mr); + memory_device_unplug_region(machine, mr); vmstate_unregister_ram(vmstate_mr, dev); } =20 diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 3427c7d424..2853b084b5 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -44,5 +44,8 @@ uint64_t get_plugged_memory_size(void); uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hin= t, uint64_t align, uint64_t size, Error **errp); +void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, + uint64_t addr); +void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); =20 #endif --=20 2.14.3