From patchwork Thu Oct 18 14:30:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 149149 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2074928lji; Thu, 18 Oct 2018 07:49:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV60xrwltHTWoIyT7HVYa7g6nHnvo0KeEpoCO71jAj7U0hYLk5Jbo3DUIUhpf0XKP1AK38DEj X-Received: by 2002:ac8:1c1a:: with SMTP id a26-v6mr30254357qtk.16.1539874176684; Thu, 18 Oct 2018 07:49:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539874176; cv=none; d=google.com; s=arc-20160816; b=HHzYbcEkmXKGDsWzvBNlPZJN9ipl9gB3pv8rSHOXegnOtkCZ6Bxs5zozRCgppCrSSZ 3DASJu+IhoAuTQ6vtdxhWFLPtOtCoeEaQ/YvgZQJ2eK12hDtT0k2Y7L/A1OdWrF1VN55 atlG9oba7wfgxNfeJ9NfuiQr0+Ootrd4UDXatyY9gLG4lAjfkfLfBYzwoG/B23/T2NSY 8ISRoiqNfX3lUEvqTiDKRvULHbhlSlcT0tGwXAK9aDnmguFPLtNG3amhQ8NMG6j26hc8 it3ZNfyMbc98bKh3RLg1uKsBXd7sFNpeBzPrKqyheoFdKORxZIPKV9Axfl/o948GjUJX e9kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from; bh=ySm1KNYC5NIeS7JynpDCR8kKK26rDNpI8Ki8atmKPPk=; b=xqzGptvj/x9oIimvyfWbK6tNr4UMpFD2TQka49s1y7aPsTqm0Qf4qjGpPs0PXXQ50N lAn5Gd5BZVXuyB2ZvLNIWU6acjuUtS9VkJnsbMV0MmhFO1s6Wdw4X7pB85F0Gc9PzeCW X+kOySbBpnML/2c1iDWEFgZcOeAJNfrG5cOoLPdemtHienfi2XGbyIt8R8SIWjya3hSJ NEG5dDTCv9LbOJi44/83/QzNFz8wR3ol2Yrs+RGsdpffdChtLlGD6Zfs6O2yhWw/4L84 +ooRLx93YyghfX6sTT/Lb2JXXXEaRtpcDGzu//tV1QHYvWDWrnOMKxXq9h777oJXbFSI bCkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e189-v6si2018451qka.82.2018.10.18.07.49.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 18 Oct 2018 07:49:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:42789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD9cF-0003rC-Vs for patch@linaro.org; Thu, 18 Oct 2018 10:49:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD9LC-000665-Hg for qemu-devel@nongnu.org; Thu, 18 Oct 2018 10:31:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD9LB-0007Uf-I3 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 10:31:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34532) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gD9L6-0007Qm-6D; Thu, 18 Oct 2018 10:31:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2538E7F7B5; Thu, 18 Oct 2018 14:31:51 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-215.ams2.redhat.com [10.36.116.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id A65E060150; Thu, 18 Oct 2018 14:31:42 +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, david@redhat.com Date: Thu, 18 Oct 2018 16:30:35 +0200 Message-Id: <20181018143042.29588-10-eric.auger@redhat.com> In-Reply-To: <20181018143042.29588-1-eric.auger@redhat.com> References: <20181018143042.29588-1-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 18 Oct 2018 14:31:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v4 09/16] hw/arm/virt: Add memory 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: , Cc: drjones@redhat.com, dgilbert@redhat.com, Suzuki.Poulose@arm.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Shameer Kolothum This patch adds the the memory hot-plug/hot-unplug infrastructure in machvirt. Signed-off-by: Eric Auger Signed-off-by: Shameer Kolothum Signed-off-by: Kwangwoo Lee --- v3 -> v4: - check the memory device is not hotplugged v2 -> v3: - change in pc_dimm_plug()'s signature - add pc_dimm_pre_plug call v1 -> v2: - s/virt_dimm_plug|unplug/virt_memory_plug|unplug - s/pc_dimm_memory_plug/pc_dimm_plug - reworded title and commit message - added pre_plug cb - don't handle get_memory_region failure anymore --- default-configs/arm-softmmu.mak | 2 ++ hw/arm/virt.c | 64 ++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index 2420491aac..1c110cfe7f 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -159,3 +159,5 @@ CONFIG_PCI_DESIGNWARE=y CONFIG_STRONGARM=y CONFIG_HIGHBANK=y CONFIG_MUSICPAL=y +CONFIG_MEM_HOTPLUG=y + diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 9b06797090..1548e9480a 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -60,6 +60,8 @@ #include "standard-headers/linux/input.h" #include "hw/arm/smmuv3.h" #include "hw/acpi/acpi.h" +#include "hw/mem/pc-dimm.h" +#include "hw/mem/nvdimm.h" #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -1771,6 +1773,49 @@ static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms) return ms->possible_cpus; } +static void virt_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, + Error **errp) +{ + const bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM); + + if (dev->hotplugged) { + error_setg(errp, "memory hotplug is not supported"); + } + + if (is_nvdimm) { + error_setg(errp, "nvdimm is not yet supported"); + return; + } + + pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), NULL, errp); +} + +static void virt_memory_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + VirtMachineState *vms = VIRT_MACHINE(hotplug_dev); + Error *local_err = NULL; + + pc_dimm_plug(dev, MACHINE(vms), &local_err); + + error_propagate(errp, local_err); +} + +static void virt_memory_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + pc_dimm_unplug(dev, MACHINE(hotplug_dev)); + object_unparent(OBJECT(dev)); +} + +static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + virt_memory_pre_plug(hotplug_dev, dev, errp); + } +} + static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -1782,12 +1827,27 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, SYS_BUS_DEVICE(dev)); } } + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + virt_memory_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_memory_unplug(hotplug_dev, dev, errp); + } else { + error_setg(errp, "device unplug request for unsupported device" + " type: %s", object_get_typename(OBJECT(dev))); + } } static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine, 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); } @@ -1853,7 +1913,9 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->kvm_type = virt_kvm_type; assert(!mc->get_hotplug_handler); mc->get_hotplug_handler = virt_machine_get_hotplug_handler; + hc->pre_plug = virt_machine_device_pre_plug_cb; hc->plug = virt_machine_device_plug_cb; + hc->unplug = virt_machine_device_unplug_cb; } static const TypeInfo virt_machine_info = {