From nobody Thu Nov 6 10:24:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540475074380189.01502778527936; Thu, 25 Oct 2018 06:44:34 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id EC66031500B6; Thu, 25 Oct 2018 13:44:30 +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 AF14F5D6AA; Thu, 25 Oct 2018 13:44: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 53F334CAAE; Thu, 25 Oct 2018 13:44:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9PDbOHG008265 for ; Thu, 25 Oct 2018 09:37:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id A4B72662FC; Thu, 25 Oct 2018 13:37:24 +0000 (UTC) Received: from localhost (unknown [10.33.36.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id 170B8662DF; Thu, 25 Oct 2018 13:36:58 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 10:32:44 -0300 Message-Id: <20181025133301.16578-27-ehabkost@redhat.com> In-Reply-To: <20181025133301.16578-1-ehabkost@redhat.com> References: <20181025133301.16578-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: "Michael S. Tsirkin" , libvir-list@redhat.com, Jason Wang , Mark Cave-Ayland , Max Filippov , "Edgar E. Iglesias" , Rob Herring , David Hildenbrand , Alexander Graf , Marcel Apfelbaum , Richard Henderson , Artyom Tarasenko , Laurent Vivier , Thomas Huth , Eduardo Habkost , Alistair Francis , qemu-arm@nongnu.org, Paolo Bonzini , David Gibson , Xiao Guangrong , Peter Crosthwaite , Michael Walle , qemu-ppc@nongnu.org, Aleksandar Markovic , Igor Mammedov , Aurelien Jarno Subject: [libvirt] [PULL v2 26/43] memory-device: factor out get_memory_region() from pc-dimm 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 25 Oct 2018 13:44:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand The memory region is necessary for plugging/unplugging a memory device. The region size (via get_region_size()) is no longer sufficient, as besides the alignment, also the region itself is required in order to add it to the device memory region of the machine via - memory_region_add_subregion - memory_region_del_subregion So, to factor out plugging/unplugging of memory devices from pc-dimm code, we have to factor out access to the memory region first. Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20181005092024.14344-11-david@redhat.com> Signed-off-by: Eduardo Habkost --- include/hw/mem/memory-device.h | 15 +++++++++++++++ include/hw/mem/pc-dimm.h | 4 ---- hw/mem/nvdimm.c | 9 ++++++--- hw/mem/pc-dimm.c | 27 ++++++++++++++++++--------- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 898df3057d..659f38385c 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -38,6 +38,11 @@ typedef struct MemoryDeviceState { * mapped into guest physical address space at a certain address. The * address in guest physical memory can either be specified explicitly * or get assigned automatically. + * + * Conceptually, memory devices only span one memory region. If multiple + * successive memory regions are used, a covering memory region has to + * be provided. Scattered memory regions are not supported for single + * devices. */ typedef struct MemoryDeviceClass { /* private */ @@ -68,6 +73,16 @@ typedef struct MemoryDeviceClass { uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp= ); uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp); =20 + /* + * Return the memory region of the memory device. + * + * Called when (un)plugging the memory device, to (un)map the + * memory region in guest physical memory, but also to detect the + * required alignment during address assignment or when the size of the + * memory region is required. + */ + MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp= ); + /* * Translate the memory device into #MemoryDeviceInfo. */ diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 99cbd54de7..01436b9f50 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -61,9 +61,6 @@ typedef struct PCDIMMDevice { * PCDIMMDeviceClass: * @realize: called after common dimm is realized so that the dimm based * devices get the chance to do specified operations. - * @get_memory_region: returns #MemoryRegion associated with @dimm which - * is directly mapped into the physical address space of guest. Will not - * fail after the device was realized. * @get_vmstate_memory_region: returns #MemoryRegion which indicates the * memory of @dimm should be kept during live migration. Will not fail * after the device was realized. @@ -74,7 +71,6 @@ typedef struct PCDIMMDeviceClass { =20 /* public */ void (*realize)(PCDIMMDevice *dimm, Error **errp); - MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm, Error **errp); MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm, Error **errp); } PCDIMMDeviceClass; diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 1c6674c4ed..49324f3fae 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -27,6 +27,7 @@ #include "qapi/error.h" #include "qapi/visitor.h" #include "hw/mem/nvdimm.h" +#include "hw/mem/memory-device.h" =20 static void nvdimm_get_label_size(Object *obj, Visitor *v, const char *nam= e, void *opaque, Error **errp) @@ -118,9 +119,10 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice = *nvdimm, Error **errp) nvdimm->nvdimm_mr->align =3D align; } =20 -static MemoryRegion *nvdimm_get_memory_region(PCDIMMDevice *dimm, Error **= errp) +static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md, + Error **errp) { - NVDIMMDevice *nvdimm =3D NVDIMM(dimm); + NVDIMMDevice *nvdimm =3D NVDIMM(md); Error *local_err =3D NULL; =20 if (!nvdimm->nvdimm_mr) { @@ -190,11 +192,12 @@ static Property nvdimm_properties[] =3D { static void nvdimm_class_init(ObjectClass *oc, void *data) { PCDIMMDeviceClass *ddc =3D PC_DIMM_CLASS(oc); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(oc); NVDIMMClass *nvc =3D NVDIMM_CLASS(oc); DeviceClass *dc =3D DEVICE_CLASS(oc); =20 ddc->realize =3D nvdimm_realize; - ddc->get_memory_region =3D nvdimm_get_memory_region; + mdc->get_memory_region =3D nvdimm_md_get_memory_region; dc->props =3D nvdimm_properties; =20 nvc->read_label_data =3D nvdimm_read_label_data; diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 3e43ec8742..c9f6ad589e 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -32,7 +32,7 @@ static int pc_dimm_get_free_slot(const int *hint, int max= _slots, Error **errp); void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine, const uint64_t *legacy_align, Error **errp) { - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(dimm); Error *local_err =3D NULL; MemoryRegion *mr; uint64_t addr, align; @@ -49,7 +49,7 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *m= achine, &error_abort); trace_mhp_pc_dimm_assigned_slot(slot); =20 - mr =3D ddc->get_memory_region(dimm, &local_err); + mr =3D mdc->get_memory_region(MEMORY_DEVICE(dimm), &local_err); if (local_err) { goto out; } @@ -72,9 +72,11 @@ out: void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp) { PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm, &error_abort= ); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); + MemoryRegion *mr =3D mdc->get_memory_region(MEMORY_DEVICE(dimm), + &error_abort); uint64_t addr; =20 addr =3D object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP, @@ -87,9 +89,11 @@ void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *mach= ine, Error **errp) void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine) { PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm, &error_abort= ); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); + MemoryRegion *mr =3D mdc->get_memory_region(MEMORY_DEVICE(dimm), + &error_abort); =20 memory_device_unplug_region(machine, mr); vmstate_unregister_ram(vmstate_mr, DEVICE(dimm)); @@ -235,12 +239,11 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDevic= eState *md) static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md, Error **errp) { - /* dropping const here is fine as we don't touch the memory region */ - PCDIMMDevice *dimm =3D PC_DIMM(md); - const PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(md); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); MemoryRegion *mr; =20 - mr =3D ddc->get_memory_region(dimm, errp); + /* dropping const here is fine as we don't touch the memory region */ + mr =3D mdc->get_memory_region((MemoryDeviceState *)md, errp); if (!mr) { return 0; } @@ -248,6 +251,12 @@ static uint64_t pc_dimm_md_get_region_size(const Memor= yDeviceState *md, return memory_region_size(mr); } =20 +static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md, + Error **errp) +{ + return pc_dimm_get_memory_region(PC_DIMM(md), errp); +} + static void pc_dimm_md_fill_device_info(const MemoryDeviceState *md, MemoryDeviceInfo *info) { @@ -289,13 +298,13 @@ static void pc_dimm_class_init(ObjectClass *oc, void = *data) dc->props =3D pc_dimm_properties; dc->desc =3D "DIMM memory module"; =20 - ddc->get_memory_region =3D pc_dimm_get_memory_region; ddc->get_vmstate_memory_region =3D pc_dimm_get_memory_region; =20 mdc->get_addr =3D pc_dimm_md_get_addr; /* for a dimm plugged_size =3D=3D region_size */ mdc->get_plugged_size =3D pc_dimm_md_get_region_size; mdc->get_region_size =3D pc_dimm_md_get_region_size; + mdc->get_memory_region =3D pc_dimm_md_get_memory_region; mdc->fill_device_info =3D pc_dimm_md_fill_device_info; } =20 --=20 2.18.0.rc1.1.g3f1ff2140 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list