From patchwork Thu Apr 19 14:08:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasilis Liaskovitis X-Patchwork-Id: 153824 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 87638B6FDF for ; Fri, 20 Apr 2012 01:53:51 +1000 (EST) Received: from localhost ([::1]:36115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKs4S-0001ba-M8 for incoming@patchwork.ozlabs.org; Thu, 19 Apr 2012 10:10:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37569) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKs3o-0008KP-IS for qemu-devel@nongnu.org; Thu, 19 Apr 2012 10:10:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKs3j-0006E1-Ew for qemu-devel@nongnu.org; Thu, 19 Apr 2012 10:10:12 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:48024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKs3j-0005r3-8D for qemu-devel@nongnu.org; Thu, 19 Apr 2012 10:10:07 -0400 Received: by mail-bk0-f45.google.com with SMTP id ji1so416421bkc.4 for ; Thu, 19 Apr 2012 07:10:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=HafZybRTKZK3QzyImK2fnMXNuEBiMWuIG4FMPLLy16Y=; b=ibWVCRrGI7klGZOCBzm+g9IyUPJ5tuy+LwUUYARfa+FoDXvGNgJEq1qAkvc5L1oGzB GDrQlKmM3gNA6XANBvxueZRMb9jonACaS0RLBrJiozm9jX17Cjmm/9x8V/WmVkajbIlz AbyZ4e+/EYh8rSucRMLSWA5aPTFKBqE3Ygw8wuW56osmDlsxpuqO6MXkZBL7SNEOw/+l at0UihTNG0T31Huhkc9hHcnRBFBzAhj4sPgRfXWXVDH2Lf97KjwV6/jyTM3D/y5RgtGD UgIWYELDFL3lt5LbBGXvarrTiSD5h3n58dKC1iFfhnQP5eV6igWG/yMUVu+juOQcU5QF LKeA== Received: by 10.204.143.149 with SMTP id v21mr683504bku.123.1334844606282; Thu, 19 Apr 2012 07:10:06 -0700 (PDT) Received: from dhcp-192-168-178-175.ri.profitbricks.localdomain ([62.217.45.26]) by mx.google.com with ESMTPS id gu12sm4434954bkc.1.2012.04.19.07.10.05 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 Apr 2012 07:10:05 -0700 (PDT) From: Vasilis Liaskovitis To: qemu-devel@nongnu.org, kvm@vger.kernel.org, seabios@seabios.org Date: Thu, 19 Apr 2012 16:08:46 +0200 Message-Id: <1334844527-18869-9-git-send-email-vasilis.liaskovitis@profitbricks.com> X-Mailer: git-send-email 1.7.9 In-Reply-To: <1334844527-18869-1-git-send-email-vasilis.liaskovitis@profitbricks.com> References: <1334844527-18869-1-git-send-email-vasilis.liaskovitis@profitbricks.com> X-Gm-Message-State: ALoCoQkyul1CdsfLojK4XWWXB8w5eqx8iOVRUxIcajYF7zCDPSr7OfSxvHBNnjbvrE/mRhlqI8jL X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.45 Cc: Vasilis Liaskovitis , avi@redhat.com, gleb@redhat.com Subject: [Qemu-devel] [RFC PATCH 8/9] pc: adjust e820 map on hot-add and hot-remove 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 Hotplugged memory is not persistent in the e820 memory maps. After hotplugging a memslot and rebooting the VM, the hotplugged device is not present. A possible solution is to add an e820 for the new memslot in the acpi_piix4 hot-add handler. On a reset, Seabios (see next patch in series) will enable all memory devices for which it finds an e820 entry that covers the devices's address range. On hot-remove, the acpi_piix4 handler will try to remove the e820 entry corresponding to the device. This will work when no VM reboots happen between hot-add and hot-remove, but it is not a sufficient solution in general: Seabios and GuestOS merge adjacent e820 entries on machine reboot, so the sequence hot-add/ rebootVM / hot-remove will fail to remove a corresponding e820 entry at the hot-remove phase. Signed-off-by: Vasilis Liaskovitis --- hw/acpi_piix4.c | 6 ++++++ hw/pc.c | 28 ++++++++++++++++++++++++++++ hw/pc.h | 1 + 3 files changed, 35 insertions(+), 0 deletions(-) diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c index 2921d18..2b5fd04 100644 --- a/hw/acpi_piix4.c +++ b/hw/acpi_piix4.c @@ -619,6 +619,9 @@ static void piix4_memslot_eject(uint32_t addr, uint32_t val) s = memslot_find_from_idx(start + idx); assert(s != NULL); memslot_depopulate(s); + if (e820_del_entry(s->start, s->size, E820_RAM) == -EBUSY) + PIIX4_DPRINTF("failed to remove e820 entry for memslot %u\n", + s->idx); } val = val >> 1; idx++; @@ -634,6 +637,9 @@ static int piix4_memslot_hotplug(DeviceState *qdev, SysBusDevice *dev, int if (add) { enable_mem_device(s, slot->idx); + if (e820_add_entry(slot->start, slot->size, E820_RAM) == -EBUSY) + PIIX4_DPRINTF("failed to add e820 entry for memslot %u\n", + slot->idx); } else { disable_mem_device(s, slot->idx); diff --git a/hw/pc.c b/hw/pc.c index f1f550a..04d243f 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -593,6 +593,34 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type) return index; } +int e820_del_entry(uint64_t address, uint64_t length, uint32_t type) +{ + int index = le32_to_cpu(e820_table.count); + int search; + struct e820_entry *entry; + + if (index == 0) + return -EBUSY; + search = index - 1; + entry = &e820_table.entry[search]; + while (search >= 0) { + if ((entry->address == cpu_to_le64(address)) && + (entry->length == cpu_to_le64(length)) && + (entry->type == cpu_to_le32(type))){ + if (search != index - 1) { + memcpy(&e820_table.entry[search], &e820_table.entry[search + 1], + sizeof(struct e820_entry) * (index - search)); + } + index--; + e820_table.count = cpu_to_le32(index); + return 1; + } + search--; + entry = &e820_table.entry[search]; + } + return -EBUSY; +} + static void bochs_bios_setup_hp_memslots(uint64_t *fw_cfg_slots); static void *bochs_bios_init(void) diff --git a/hw/pc.h b/hw/pc.h index 74d3369..4925e8c 100644 --- a/hw/pc.h +++ b/hw/pc.h @@ -226,5 +226,6 @@ void pc_system_firmware_init(MemoryRegion *rom_memory); #define E820_UNUSABLE 5 int e820_add_entry(uint64_t, uint64_t, uint32_t); +int e820_del_entry(uint64_t, uint64_t, uint32_t); #endif