From nobody Wed May 1 08:25:37 2024 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 1529662875746484.50149700176325; Fri, 22 Jun 2018 03:21:15 -0700 (PDT) Received: from localhost ([::1]:60586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJBo-0001RO-4H for importer@patchew.org; Fri, 22 Jun 2018 06:21:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJA4-0000Jp-Nq for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fWJA2-0005bL-Ux for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57192 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 1fWJ9y-0005Xl-3i; Fri, 22 Jun 2018 06:19:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A65DA8151D6F; Fri, 22 Jun 2018 10:19:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-106.ams2.redhat.com [10.36.117.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 416BD11166E1; Fri, 22 Jun 2018 10:19:16 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, shameerali.kolothum.thodi@huawei.com, kwangwoo.lee@sk.com, imammedo@redhat.com Date: Fri, 22 Jun 2018 12:19:05 +0200 Message-Id: <1529662749-32069-2-git-send-email-eric.auger@redhat.com> In-Reply-To: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> References: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 22 Jun 2018 10:19:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 22 Jun 2018 10:19:17 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@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] [RFC 1/5] hw/arm/virt: Allocate device_memory 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: , 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" We define a new hotpluggable RAM region (aka. device memory). Its base is 2TB GPA. This obviously requires 42b IPA support in KVM/ARM, FW and guest kernel. At the moment the device memory region is max 2TB. This is largely inspired of device memory initialization in pc machine code. Signed-off-by: Eric Auger Signed-off-by: Kwangwoo Lee --- hw/arm/virt.c | 105 ++++++++++++++++++++++++++++++++++++----------= ---- include/hw/arm/arm.h | 2 + include/hw/arm/virt.h | 1 + 3 files changed, 80 insertions(+), 28 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 8c001c1..a251054 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -59,6 +59,7 @@ #include "qapi/visitor.h" #include "standard-headers/linux/input.h" #include "hw/arm/smmuv3.h" +#include "hw/acpi/acpi.h" =20 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -94,34 +95,25 @@ =20 #define PLATFORM_BUS_NUM_IRQS 64 =20 -/* RAM limit in GB. Since VIRT_MEM starts at the 1GB mark, this means - * RAM can go up to the 256GB mark, leaving 256GB of the physical - * address space unallocated and free for future use between 256G and 512G. - * If we need to provide more RAM to VMs in the future then we need to: - * * allocate a second bank of RAM starting at 2TB and working up - * * fix the DT and ACPI table generation code in QEMU to correctly - * report two split lumps of RAM to the guest - * * fix KVM in the host kernel to allow guests with >40 bit address spac= es - * (We don't want to fill all the way up to 512GB with RAM because - * we might want it for non-RAM purposes later. Conversely it seems - * reasonable to assume that anybody configuring a VM with a quarter - * of a terabyte of RAM will be doing it on a host with more than a - * terabyte of physical address space.) - */ -#define RAMLIMIT_GB 255 -#define RAMLIMIT_BYTES (RAMLIMIT_GB * 1024ULL * 1024 * 1024) +#define SZ_64K 0x10000 +#define SZ_1G (1024ULL * 1024 * 1024) =20 /* Addresses and sizes of our components. - * 0..128MB is space for a flash device so we can run bootrom code such as= UEFI. - * 128MB..256MB is used for miscellaneous device I/O. - * 256MB..1GB is reserved for possible future PCI support (ie where the - * PCI memory window will go if we add a PCI host controller). - * 1GB and up is RAM (which may happily spill over into the - * high memory region beyond 4GB). - * This represents a compromise between how much RAM can be given to - * a 32 bit VM and leaving space for expansion and in particular for PCI. - * Note that devices should generally be placed at multiples of 0x10000, + * 0..128MB is space for a flash device so we can run bootrom code such as= UEFI, + * 128MB..256MB is used for miscellaneous device I/O, + * 256MB..1GB is used for PCI host controller, + * 1GB..256GB is RAM (not hotpluggable), + * 256GB..512GB: is left for device I/O (non RAM purpose), + * 512GB..1TB: high mem PCI MMIO region, + * 2TB..4TB is used for hot-pluggable DIMM (assumes 42b GPA is supported). + * + * Note that IO devices should generally be placed at multiples of 0x10000, * to accommodate guests using 64K pages. + * + * Conversely it seems reasonable to assume that anybody configuring a VM + * with a quarter of a terabyte of RAM will be doing it on a host with more + * than a terabyte of physical address space.) + * */ static const MemMapEntry a15memmap[] =3D { /* Space up to 0x8000000 is reserved for a boot ROM */ @@ -148,9 +140,11 @@ static const MemMapEntry a15memmap[] =3D { [VIRT_PCIE_MMIO] =3D { 0x10000000, 0x2eff0000 }, [VIRT_PCIE_PIO] =3D { 0x3eff0000, 0x00010000 }, [VIRT_PCIE_ECAM] =3D { 0x3f000000, 0x01000000 }, - [VIRT_MEM] =3D { 0x40000000, RAMLIMIT_BYTES }, + /* 255GB RAM */ + [VIRT_MEM] =3D { SZ_1G , 255 * SZ_1G }, /* Second PCIe window, 512GB wide at the 512GB boundary */ - [VIRT_PCIE_MMIO_HIGH] =3D { 0x8000000000ULL, 0x8000000000ULL }, + [VIRT_PCIE_MMIO_HIGH] =3D { 512 * SZ_1G, 512 * SZ_1G }, + [VIRT_HOTPLUG_MEM] =3D { 2048 * SZ_1G, 2048 * SZ_1G }, }; =20 static const int a15irqmap[] =3D { @@ -1166,6 +1160,58 @@ static void create_secure_ram(VirtMachineState *vms, g_free(nodename); } =20 +static void create_device_memory(VirtMachineState *vms, MemoryRegion *sysm= em) +{ + MachineState *ms =3D MACHINE(vms); + uint64_t device_memory_size; + uint64_t align =3D SZ_64K; + + /* always allocate the device memory information */ + ms->device_memory =3D g_malloc0(sizeof(*ms->device_memory)); + + if (vms->max_vm_phys_shift < 42) { + /* device memory starts at 2TB whereas this VM supports less than + * 2TB GPA */ + if (ms->maxram_size > ms->ram_size || ms->ram_slots) { + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + + error_report("\"-memory 'slots|maxmem'\" is not supported by %= s " + "since KVM does not support more than 41b IPA", + mc->name); + exit(EXIT_FAILURE); + } + return; + } + + if (ms->ram_slots > ACPI_MAX_RAM_SLOTS) { + error_report("unsupported number of memory slots: %"PRIu64, + ms->ram_slots); + exit(EXIT_FAILURE); + } + + if (QEMU_ALIGN_UP(ms->maxram_size, align) !=3D ms->maxram_size) { + error_report("maximum memory size must be aligned to multiple of 0= x%" + PRIx64, align); + exit(EXIT_FAILURE); + } + + ms->device_memory->base =3D vms->memmap[VIRT_HOTPLUG_MEM].base; + device_memory_size =3D ms->maxram_size - ms->ram_size; + + if (device_memory_size > vms->memmap[VIRT_HOTPLUG_MEM].size) { + error_report("unsupported amount of maximum memory: " RAM_ADDR_FMT, + ms->maxram_size); + exit(EXIT_FAILURE); + } + + memory_region_init(&ms->device_memory->mr, OBJECT(vms), + "device-memory", device_memory_size); + memory_region_add_subregion(sysmem, ms->device_memory->base, + &ms->device_memory->mr); + vms->bootinfo.device_memory_start =3D ms->device_memory->base; + vms->bootinfo.device_memory_size =3D device_memory_size; +} + static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size) { const VirtMachineState *board =3D container_of(binfo, VirtMachineState, @@ -1371,7 +1417,8 @@ static void machvirt_init(MachineState *machine) vms->smp_cpus =3D smp_cpus; =20 if (machine->ram_size > vms->memmap[VIRT_MEM].size) { - error_report("mach-virt: cannot model more than %dGB RAM", RAMLIMI= T_GB); + error_report("mach-virt: cannot model more than %dGB RAM", + (int)(vms->memmap[VIRT_MEM].size / SZ_1G)); exit(1); } =20 @@ -1464,6 +1511,8 @@ static void machvirt_init(MachineState *machine) machine->ram_size); memory_region_add_subregion(sysmem, vms->memmap[VIRT_MEM].base, ram); =20 + create_device_memory(vms, sysmem); + create_flash(vms, sysmem, secure_sysmem ? secure_sysmem : sysmem); =20 create_gic(vms, pic); diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h index ffed392..76269e6 100644 --- a/include/hw/arm/arm.h +++ b/include/hw/arm/arm.h @@ -116,6 +116,8 @@ struct arm_boot_info { bool secure_board_setup; =20 arm_endianness endianness; + hwaddr device_memory_start; + hwaddr device_memory_size; }; =20 /** diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 600d96d..3b0c765 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -74,6 +74,7 @@ enum { VIRT_GPIO, VIRT_SECURE_UART, VIRT_SECURE_MEM, + VIRT_HOTPLUG_MEM, }; =20 typedef enum VirtIOMMUType { --=20 2.5.5 From nobody Wed May 1 08:25:37 2024 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 1529662901642273.3072744150046; Fri, 22 Jun 2018 03:21:41 -0700 (PDT) Received: from localhost ([::1]:60588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJCH-0001oI-09 for importer@patchew.org; Fri, 22 Jun 2018 06:21:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41434) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJA3-0000Jf-BO for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fWJA2-0005aL-9m for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40780 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 1fWJ9z-0005YA-KI; Fri, 22 Jun 2018 06:19:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 355C27CBBA; Fri, 22 Jun 2018 10:19:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-106.ams2.redhat.com [10.36.117.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF62C11166E1; Fri, 22 Jun 2018 10:19:17 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, shameerali.kolothum.thodi@huawei.com, kwangwoo.lee@sk.com, imammedo@redhat.com Date: Fri, 22 Jun 2018 12:19:06 +0200 Message-Id: <1529662749-32069-3-git-send-email-eric.auger@redhat.com> In-Reply-To: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> References: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 22 Jun 2018 10:19:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 22 Jun 2018 10:19:19 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@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] [RFC 2/5] hw/arm/virt: Add pc-dimm mem hotplug framework 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: , 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" From: Shameer Kolothum This patch adds the the PC-DIMM hot-plug/hot-unplug infrastructure in machvirt. Signed-off-by: Eric Auger Signed-off-by: Shameer Kolothum Signed-off-by: Kwangwoo Lee --- default-configs/arm-softmmu.mak | 2 ++ hw/arm/virt.c | 53 +++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index 7cf73d2..0840a56 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -151,3 +151,5 @@ CONFIG_PCI_DESIGNWARE=3Dy CONFIG_STRONGARM=3Dy CONFIG_HIGHBANK=3Dy CONFIG_MUSICPAL=3Dy +CONFIG_MEM_HOTPLUG=3Dy + diff --git a/hw/arm/virt.c b/hw/arm/virt.c index a251054..a6e3b3d 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -60,6 +60,7 @@ #include "standard-headers/linux/input.h" #include "hw/arm/smmuv3.h" #include "hw/acpi/acpi.h" +#include "hw/mem/pc-dimm.h" =20 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -1723,6 +1724,40 @@ static const CPUArchIdList *virt_possible_cpu_arch_i= ds(MachineState *ms) return ms->possible_cpus; } =20 +static void virt_dimm_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + PCDIMMDevice *dimm =3D PC_DIMM(dev); + PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + Error *local_err =3D NULL; + MemoryRegion *mr; + uint64_t align; + + mr =3D ddc->get_memory_region(dimm, &local_err); + if (local_err) { + goto out; + } + + if (memory_region_get_alignment(mr)) { + align =3D memory_region_get_alignment(mr); + } else { + /* by default we align on 64KB page size */ + align =3D SZ_64K; + } + + pc_dimm_memory_plug(dev, MACHINE(hotplug_dev), align, &local_err); + +out: + error_propagate(errp, local_err); +} + +static void virt_dimm_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + pc_dimm_memory_unplug(dev, MACHINE(hotplug_dev)); + object_unparent(OBJECT(dev)); +} + static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -1734,12 +1769,27 @@ static void virt_machine_device_plug_cb(HotplugHand= ler *hotplug_dev, SYS_BUS_DEVICE(dev)); } } + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + virt_dimm_plug(hotplug_dev, dev, errp); + } +} + +static void virt_machine_device_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + virt_dimm_unplug(hotplug_dev, dev, errp); + } else { + error_setg(errp, "device unplug request for unsupported device" + " type: %s", object_get_typename(OBJECT(dev))); + } } =20 static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *mach= ine, DeviceState *dev) { - if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE)) { + if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE) || + (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM))) { return HOTPLUG_HANDLER(machine); } =20 @@ -1800,6 +1850,7 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) assert(!mc->get_hotplug_handler); mc->get_hotplug_handler =3D virt_machine_get_hotplug_handler; hc->plug =3D virt_machine_device_plug_cb; + hc->unplug =3D virt_machine_device_unplug_cb; } =20 static const TypeInfo virt_machine_info =3D { --=20 2.5.5 From nobody Wed May 1 08:25:37 2024 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 1529662902649826.8010502502788; Fri, 22 Jun 2018 03:21:42 -0700 (PDT) Received: from localhost ([::1]:60589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJCH-0001ox-Ve for importer@patchew.org; Fri, 22 Jun 2018 06:21:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJA9-0000Ok-U0 for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fWJA6-0005dO-O5 for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40796 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 1fWJA1-0005Yg-6A; Fri, 22 Jun 2018 06:19:21 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B78FB6167F; Fri, 22 Jun 2018 10:19:20 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-106.ams2.redhat.com [10.36.117.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D52711166E1; Fri, 22 Jun 2018 10:19:19 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, shameerali.kolothum.thodi@huawei.com, kwangwoo.lee@sk.com, imammedo@redhat.com Date: Fri, 22 Jun 2018 12:19:07 +0200 Message-Id: <1529662749-32069-4-git-send-email-eric.auger@redhat.com> In-Reply-To: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> References: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 22 Jun 2018 10:19:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 22 Jun 2018 10:19:20 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@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] [RFC 3/5] hw/arm/boot: introduce fdt_add_memory_node helper 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: , 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" From: Shameer Kolothum We introduce an helper to create a memory node. Also we nop existing /memory node in numa and non numa case. Signed-off-by: Eric Auger Signed-off-by: Shameer Kolothum --- the nop related change should disappear if the following series lands upstream: [PATCH v2 0/3] ARM virt: Silence dtc warnings --- hw/arm/boot.c | 70 +++++++++++++++++++++++++++++++++----------------------= ---- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 1e48166..cc425ce 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -413,6 +413,36 @@ static void set_kernel_args_old(const struct arm_boot_= info *info, } } =20 +static int fdt_add_memory_node(void *fdt, uint32_t acells, hwaddr mem_base, + uint32_t scells, hwaddr mem_len, + int numa_node_id) +{ + char *nodename =3D NULL; + int ret; + + nodename =3D g_strdup_printf("/memory@%" PRIx64, mem_base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory"); + ret =3D qemu_fdt_setprop_sized_cells(fdt, nodename, "reg", acells, mem= _base, + scells, mem_len); + if (ret < 0) { + fprintf(stderr, "couldn't set %s/reg\n", nodename); + goto out; + } + if (numa_node_id < 0) { + goto out; + } + + ret =3D qemu_fdt_setprop_cell(fdt, nodename, "numa-node-id", numa_node= _id); + if (ret < 0) { + fprintf(stderr, "couldn't set %s/numa-node-id\n", nodename); + } + +out: + g_free(nodename); + return ret; +} + static void fdt_add_psci_node(void *fdt) { uint32_t cpu_suspend_fn; @@ -492,7 +522,6 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, void *fdt =3D NULL; int size, rc; uint32_t acells, scells; - char *nodename; unsigned int i; hwaddr mem_base, mem_len; =20 @@ -545,49 +574,28 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_i= nfo *binfo, "RAM size > 4GB\n"); goto fail; } + /* + * Turn the /memory node created before into a NOP node, then create + * /memory@addr nodes. + */ + qemu_fdt_nop_node(fdt, "/memory"); =20 if (nb_numa_nodes > 0) { - /* - * Turn the /memory node created before into a NOP node, then crea= te - * /memory@addr nodes for all numa nodes respectively. - */ - qemu_fdt_nop_node(fdt, "/memory"); mem_base =3D binfo->loader_start; for (i =3D 0; i < nb_numa_nodes; i++) { mem_len =3D numa_info[i].node_mem; - nodename =3D g_strdup_printf("/memory@%" PRIx64, mem_base); - qemu_fdt_add_subnode(fdt, nodename); - qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory"= ); - rc =3D qemu_fdt_setprop_sized_cells(fdt, nodename, "reg", - acells, mem_base, - scells, mem_len); + rc =3D fdt_add_memory_node(fdt, acells, mem_base, + scells, mem_len, i); if (rc < 0) { - fprintf(stderr, "couldn't set %s/reg for node %d\n", noden= ame, - i); goto fail; } =20 - qemu_fdt_setprop_cell(fdt, nodename, "numa-node-id", i); mem_base +=3D mem_len; - g_free(nodename); } } else { - Error *err =3D NULL; - - rc =3D fdt_path_offset(fdt, "/memory"); + rc =3D fdt_add_memory_node(fdt, acells, binfo->loader_start, + scells, binfo->ram_size, -1); if (rc < 0) { - qemu_fdt_add_subnode(fdt, "/memory"); - } - - if (!qemu_fdt_getprop(fdt, "/memory", "device_type", NULL, &err)) { - qemu_fdt_setprop_string(fdt, "/memory", "device_type", "memory= "); - } - - rc =3D qemu_fdt_setprop_sized_cells(fdt, "/memory", "reg", - acells, binfo->loader_start, - scells, binfo->ram_size); - if (rc < 0) { - fprintf(stderr, "couldn't set /memory/reg\n"); goto fail; } } --=20 2.5.5 From nobody Wed May 1 08:25:37 2024 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 1529663070315894.2753671953502; Fri, 22 Jun 2018 03:24:30 -0700 (PDT) Received: from localhost ([::1]:60608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJEv-0003gb-F3 for importer@patchew.org; Fri, 22 Jun 2018 06:24:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41535) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJA9-0000Ol-Ud for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fWJA6-0005dT-Pf for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57204 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 1fWJA2-0005ab-R9; Fri, 22 Jun 2018 06:19:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45FF28151D6F; Fri, 22 Jun 2018 10:19:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-106.ams2.redhat.com [10.36.117.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id F11C011166E1; Fri, 22 Jun 2018 10:19:20 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, shameerali.kolothum.thodi@huawei.com, kwangwoo.lee@sk.com, imammedo@redhat.com Date: Fri, 22 Jun 2018 12:19:08 +0200 Message-Id: <1529662749-32069-5-git-send-email-eric.auger@redhat.com> In-Reply-To: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> References: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 22 Jun 2018 10:19:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 22 Jun 2018 10:19:22 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@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] [RFC 4/5] hw/arm/boot: Expose the PC-DIMM nodes in the DT 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: , 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" From: Shameer Kolothum This patch add memory nodes corresponding to PC-DIMM regions. Signed-off-by: Shameer Kolothum Signed-off-by: Eric Auger --- hw/arm/boot.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index cc425ce..81668bd 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -19,6 +19,7 @@ #include "sysemu/numa.h" #include "hw/boards.h" #include "hw/loader.h" +#include "hw/mem/memory-device.h" #include "elf.h" #include "sysemu/device_tree.h" #include "qemu/config-file.h" @@ -516,6 +517,37 @@ static void fdt_add_psci_node(void *fdt) qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn); } =20 +static int fdt_add_hotpluggable_memory_nodes(void *fdt, + uint64_t base, uint64_t len, + uint32_t acells, uint32_t sce= lls) { + MemoryDeviceInfoList *info_list =3D qmp_memory_device_list(); + MemoryDeviceInfoList *info; + uint64_t end, cur, size; + MemoryDeviceInfo *mi; + PCDIMMDeviceInfo *di; + bool is_nvdimm; + int ret; + + end =3D base + len; + for (cur =3D base, info =3D info_list; cur < end; + cur +=3D size, info =3D info->next) { + if (!info) { + break; + } + mi =3D info->value; + is_nvdimm =3D (mi->type =3D=3D MEMORY_DEVICE_INFO_KIND_NVDIMM); + di =3D !is_nvdimm ? mi->u.dimm.data : mi->u.nvdimm.data; + + ret =3D fdt_add_memory_node(fdt, acells, di->addr, + scells, di->size, di->node); + if (ret < 0) { + return ret; + } + size =3D di->size; + } + return 0; +} + int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, hwaddr addr_limit, AddressSpace *as) { @@ -600,6 +632,14 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_in= fo *binfo, } } =20 + rc =3D fdt_add_hotpluggable_memory_nodes(fdt, binfo->device_memory_sta= rt, + binfo->device_memory_size, + acells, scells); + if (rc < 0) { + fprintf(stderr, "couldn't add hotpluggable memory nodes\n"); + goto fail; + } + rc =3D fdt_path_offset(fdt, "/chosen"); if (rc < 0) { qemu_fdt_add_subnode(fdt, "/chosen"); --=20 2.5.5 From nobody Wed May 1 08:25:37 2024 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 1529663134378818.8507099728782; Fri, 22 Jun 2018 03:25:34 -0700 (PDT) Received: from localhost ([::1]:60617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJG1-0004Uq-Nn for importer@patchew.org; Fri, 22 Jun 2018 06:25:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWJA9-0000Oi-Te for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fWJA6-0005dJ-OA for qemu-devel@nongnu.org; Fri, 22 Jun 2018 06:19:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48640 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 1fWJA4-0005c9-86; Fri, 22 Jun 2018 06:19:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C64804023132; Fri, 22 Jun 2018 10:19:23 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-106.ams2.redhat.com [10.36.117.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EA4B11166E1; Fri, 22 Jun 2018 10:19:22 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, shameerali.kolothum.thodi@huawei.com, kwangwoo.lee@sk.com, imammedo@redhat.com Date: Fri, 22 Jun 2018 12:19:09 +0200 Message-Id: <1529662749-32069-6-git-send-email-eric.auger@redhat.com> In-Reply-To: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> References: <1529662749-32069-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 22 Jun 2018 10:19:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 22 Jun 2018 10:19:23 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@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] [RFC 5/5] hw/arm/virt-acpi-build: Add PC-DIMM in SRAT 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: , 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" From: Shameer Kolothum Generate Memory Affinity Structures for PC-DIMM ranges. Signed-off-by: Shameer Kolothum Signed-off-by: Eric Auger --- hw/arm/virt-acpi-build.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 74f5744..38a6886 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -43,6 +43,7 @@ #include "hw/pci/pcie_host.h" #include "hw/pci/pci.h" #include "hw/arm/virt.h" +#include "hw/mem/memory-device.h" #include "sysemu/numa.h" #include "kvm_arm.h" =20 @@ -532,6 +533,35 @@ build_spcr(GArray *table_data, BIOSLinker *linker, Vir= tMachineState *vms) "SPCR", table_data->len - spcr_start, 2, NULL, NULL); } =20 +static void build_srat_hotpluggable_memory(GArray *table_data, uint64_t ba= se, + uint64_t len, int default_node) +{ + MemoryDeviceInfoList *info_list =3D qmp_memory_device_list(); + AcpiSratMemoryAffinity *numamem; + MemoryDeviceInfoList *info; + MemoryDeviceInfo *mi; + PCDIMMDeviceInfo *di; + uint64_t end =3D base + len, cur, size; + + for (cur =3D base, info =3D info_list; cur < end; + cur +=3D size, info =3D info->next) { + bool is_nvdimm; + + if (!info) { + break; + } + numamem =3D acpi_data_push(table_data, sizeof(*numamem)); + + mi =3D info->value; + is_nvdimm =3D (mi->type =3D=3D MEMORY_DEVICE_INFO_KIND_NVDIMM); + di =3D !is_nvdimm ? mi->u.dimm.data : mi->u.nvdimm.data; + + build_srat_memory(numamem, di->addr, di->size, + 0, MEM_AFFINITY_ENABLED); + size =3D di->size; + } +} + static void build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) { @@ -564,6 +594,10 @@ build_srat(GArray *table_data, BIOSLinker *linker, Vir= tMachineState *vms) mem_base +=3D numa_info[i].node_mem; } =20 + build_srat_hotpluggable_memory(table_data, + vms->bootinfo.device_memory_start, + vms->bootinfo.device_memory_size , 0); + build_header(linker, table_data, (void *)(table_data->data + srat_star= t), "SRAT", table_data->len - srat_start, 3, NULL, NULL); } --=20 2.5.5