From patchwork Tue Dec 18 12:41:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasilis Liaskovitis X-Patchwork-Id: 207101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CE4012C008D for ; Wed, 19 Dec 2012 00:14:03 +1100 (EST) Received: from localhost ([::1]:49056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tkwzh-0004my-Jf for incoming@patchwork.ozlabs.org; Tue, 18 Dec 2012 08:14:01 -0500 Received: from eggs.gnu.org ([208.118.235.92]:46333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkwVZ-0000Ge-DX for qemu-devel@nongnu.org; Tue, 18 Dec 2012 07:42:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TkwVX-00007B-RK for qemu-devel@nongnu.org; Tue, 18 Dec 2012 07:42:53 -0500 Received: from mail-bk0-f43.google.com ([209.85.214.43]:53900) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TkwVX-000075-Je for qemu-devel@nongnu.org; Tue, 18 Dec 2012 07:42:51 -0500 Received: by mail-bk0-f43.google.com with SMTP id jf20so294123bkc.30 for ; Tue, 18 Dec 2012 04:42:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=iwXvcqj66n2nLcsXfjWOQQ8+WZOKnwa8qCWdlhCKVcc=; b=VtjjodKZVO1pc8MRQMSnj1Jb+l2kyp1ETa78uXESMGBwSsXMEF6eF+iQsTqfrVADmH 9LEZ1bvVRc1flFs+AdpPHsXDyKM2gEqbcaS5/GuZaDmTN/H14tpRnAR+1O+JLSv+zDCA CISwRZzoAAuEjSLOlxDX/qr4Z6IStb3t8tVzutS9Wkja8FoSqTaTsoUujQDtFyOQR+Ah +gZMoR3pmFrIb/dEPYbeZcx+o629agkx0uHPrJO0ng7hPLVuXl/O5s2jP9hDoE4tYk+q wkUarB2loVr46k5uAgsDGPOVfDWt8+NekZy9H+fnJpg6XEAOLKsPe1GIvQCQbq/xQltB uZRg== X-Received: by 10.204.9.147 with SMTP id l19mr711759bkl.15.1355834570544; Tue, 18 Dec 2012 04:42:50 -0800 (PST) Received: from dhcp-192-168-178-175.ri.profitbricks.localdomain ([62.217.45.26]) by mx.google.com with ESMTPS id f24sm1169954bkv.7.2012.12.18.04.42.48 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 18 Dec 2012 04:42:49 -0800 (PST) From: Vasilis Liaskovitis To: qemu-devel@nongnu.org, seabios@seabios.org Date: Tue, 18 Dec 2012 13:41:51 +0100 Message-Id: <1355834518-17989-24-git-send-email-vasilis.liaskovitis@profitbricks.com> X-Mailer: git-send-email 1.7.9 In-Reply-To: <1355834518-17989-1-git-send-email-vasilis.liaskovitis@profitbricks.com> References: <1355834518-17989-1-git-send-email-vasilis.liaskovitis@profitbricks.com> X-Gm-Message-State: ALoCoQnylmuWeyhbbeBXbYZJvlDZWifF/Mo1QdOGv6qqhnIqdXWJhkB4MPrXupgIA1h4gaK/rtYB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.214.43 Cc: Vasilis Liaskovitis , pingfank@linux.vnet.ibm.com, gleb@redhat.com, stefanha@gmail.com, jbaron@redhat.com, blauwirbel@gmail.com, kevin@koconnor.net, kraxel@redhat.com, anthony@codemonkey.ws Subject: [Qemu-devel] [RFC PATCH v4 23/30] dimm: add hot-remove capability X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On a succesfull _EJ0 operation unmap the device from the guest by using the new qdev function qdev_unplug_complete, see: https://lists.gnu.org/archive/html/qemu-devel/2012-11/msg02699.html The memory of the device should be freed when the last subsystem using it unmaps it, see the following two series: https://lists.gnu.org/archive/html/qemu-devel/2012-11/msg00728.html https://lists.gnu.org/archive/html/qemu-devel/2012-11/msg02697.html Needs testing. Other subsystems (e.g. virtio-blk) may have to install new memorylisteners to complete pending I/O before device memory can be freed. Signed-off-by: Vasilis Liaskovitis --- hw/dimm.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 1 + 2 files changed, 52 insertions(+), 0 deletions(-) diff --git a/hw/dimm.c b/hw/dimm.c index e79f23d..0b4e22d 100644 --- a/hw/dimm.c +++ b/hw/dimm.c @@ -120,6 +120,18 @@ static void dimm_populate(DimmDevice *s) s->mr = new; } +static int dimm_depopulate(DeviceState *dev) +{ + DimmDevice *s = DIMM(dev); + assert(s); + vmstate_unregister_ram(s->mr, NULL); + memory_region_del_subregion(get_system_memory(), s->mr); + memory_region_destroy(s->mr); + s->populated = false; + s->mr = NULL; + return 0; +} + void dimm_config_create(char *id, uint64_t size, const char *bus, uint64_t node, uint32_t dimm_idx, uint32_t populated) { @@ -159,6 +171,11 @@ static void dimm_plug_device(DimmDevice *slot) static int dimm_unplug_device(DeviceState *qdev) { + DimmBus *bus = DIMM_BUS(qdev_get_parent_bus(qdev)); + + if (bus->dimm_hotplug) { + bus->dimm_hotplug(bus->dimm_hotplug_qdev, DIMM(qdev), 0); + } return 1; } @@ -186,6 +203,21 @@ static DimmDevice *dimm_find_from_name(DimmBus *bus, const char *name) return NULL; } +static DimmDevice *dimm_find_from_idx(uint32_t idx) +{ + DimmDevice *slot; + DimmBus *bus; + + QLIST_FOREACH(bus, &memory_buses, next) { + QTAILQ_FOREACH(slot, &bus->dimmlist, nextdimm) { + if (slot->idx == idx) { + return slot; + } + } + } + return NULL; +} + void dimm_setup_fwcfg_layout(uint64_t *fw_cfg_slots) { DimmConfig *slot; @@ -275,6 +307,24 @@ static int dimm_init(DeviceState *s) return 0; } +void dimm_notify(uint32_t idx, uint32_t event) +{ + DimmBus *bus; + DimmDevice *slot; + + slot = dimm_find_from_idx(idx); + assert(slot != NULL); + bus = DIMM_BUS(qdev_get_parent_bus(&slot->qdev)); + + switch (event) { + case DIMM_REMOVE_SUCCESS: + qdev_unplug_complete((DeviceState *)slot, NULL); + QTAILQ_REMOVE(&bus->dimmlist, slot, nextdimm); + break; + default: + break; + } +} static void dimm_class_init(ObjectClass *klass, void *data) { @@ -283,6 +333,7 @@ static void dimm_class_init(ObjectClass *klass, void *data) dc->props = dimm_properties; dc->unplug = dimm_unplug_device; dc->init = dimm_init; + dc->exit = dimm_depopulate; dc->bus_type = TYPE_DIMM_BUS; } diff --git a/hw/dimm.h b/hw/dimm.h index 5130b2c..86c7cd5 100644 --- a/hw/dimm.h +++ b/hw/dimm.h @@ -86,5 +86,6 @@ DimmBus *dimm_bus_create(Object *parent, const char *name, uint32_t max_dimms, void dimm_config_create(char *id, uint64_t size, const char *bus, uint64_t node, uint32_t dimm_idx, uint32_t populated); uint64_t get_hp_memory_total(void); +void dimm_notify(uint32_t idx, uint32_t event); #endif