From patchwork Tue Jul 3 07:19:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 140915 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp839546ljj; Tue, 3 Jul 2018 00:32:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeALaEM4YdjfChVJRBKSTdTU1usRrYPWvC4P2D7Sbe1qE7YvMoJpMKs0Z4xqzigAmlO99TF X-Received: by 2002:ac8:2c86:: with SMTP id 6-v6mr26584941qtw.420.1530603166476; Tue, 03 Jul 2018 00:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530603166; cv=none; d=google.com; s=arc-20160816; b=Ab5ICma20idxVgk7Ri7PhIpk7h2MbYpH+jvyaymFRXppllF9BAz8RyX6rv93lKyc5Z FC3h4VudJ2QoQKV97wwdyGZn6BoN1IcQAJ/NcUWlt8To+17YJYXRAol/EqkXIijskipN 1pdJTk9PGAIoAnWhZHEcAnNE0Yd9mnTQNG3+Ti8CazUGf8LQbPnAD0aLgO7T/BDFsMbL 1V/64//9VJiytMySksJ2W3B6iEXIQPpzIYar5Pp/+myRdmQCkShJoZ+/wCGtQ9MoOJ/O K4j1jSkQw4J6OqlprD2N9w5AVbLc+sfIlyZUPb5q1a3LPlj/i0HmtgtRavFOYGMXakIh SrNw== 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:arc-authentication-results; bh=MD5FWFTHqHcqNQMAgyK4vZSep1yEYXrpCdl/NeIiQAg=; b=BHt+sRU+I+NTyyySb95EOL9Ne5FMewpsWUWBxzTAlFfXX552FsH2huwgMIvCg7yVrq KLB+VkDUPOR7KPn3lCWYleOcGW32WNFzzZG42Vb6ERXHhceqR6a+JXziXC4rM569USWU YigvnShKH9Dp/oihSS/8yfW0vArS+N807tfUwxX3Ul/TFlNqRQsIzJc6QMxdStf3xLpd fwL2CL+cfsRN8t9O/7V3JHpQyzoha5Reoeyu071pV7YSzsGaPawQJe6lR3ilmrDbsmcG QjXQt/dUZO9brZDApg0nDJgldeOTgvqL+98ZK11K8a9hUmXd4e9kqED2bv1kzq0IpFoJ R+DA== 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 c66-v6si484863qkg.161.2018.07.03.00.32.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 03 Jul 2018 00:32:46 -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]:38530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faFnp-0007aL-QA for patch@linaro.org; Tue, 03 Jul 2018 03:32:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faFl2-00045R-99 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 03:31:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faFgj-0001XY-N4 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 03:29:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46828 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 1faFc9-0005M2-8d; Tue, 03 Jul 2018 03:20:41 -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 A6E433466E; Tue, 3 Jul 2018 07:20:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-71.ams2.redhat.com [10.36.116.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA72F1C5B8; Tue, 3 Jul 2018 07:20:38 +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, imammedo@redhat.com, david@redhat.com Date: Tue, 3 Jul 2018 09:19:50 +0200 Message-Id: <1530602398-16127-8-git-send-email-eric.auger@redhat.com> In-Reply-To: <1530602398-16127-1-git-send-email-eric.auger@redhat.com> References: <1530602398-16127-1-git-send-email-eric.auger@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.2]); Tue, 03 Jul 2018 07:20:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 03 Jul 2018 07:20:40 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 v3 07/15] 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: wei@redhat.com, drjones@redhat.com, david@gibson.dropbear.id.au, dgilbert@redhat.com, agraf@suse.de 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 --- 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 | 68 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) -- 2.5.5 diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index 834d45c..28fe8f3 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -152,3 +152,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 6fefb78..7190962 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, \ @@ -1785,6 +1787,53 @@ 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 (is_nvdimm) { + error_setg(errp, "nvdimm is not yet supported"); + return; + } +} + +static void virt_memory_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + PCDIMMDevice *dimm = PC_DIMM(dev); + PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); + MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort); + Error *local_err = NULL; + uint64_t align; + + if (memory_region_get_alignment(mr)) { + align = memory_region_get_alignment(mr); + } else { + /* by default we align on 64KB page size */ + align = SZ_64K; + } + + pc_dimm_plug(dev, MACHINE(hotplug_dev), align, &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) { @@ -1796,12 +1845,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); } @@ -1861,7 +1925,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 = {