From: Gleb Natapov <gleb@redhat.com>
To: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
Cc: seabios@seabios.org, qemu-devel@nongnu.org, kvm@vger.kernel.org,
avi@redhat.com
Subject: Re: [RFC PATCH 8/9] pc: adjust e820 map on hot-add and hot-remove
Date: Sun, 22 Apr 2012 16:58:47 +0300 [thread overview]
Message-ID: <20120422135847.GB15413@redhat.com> (raw)
In-Reply-To: <1334844527-18869-9-git-send-email-vasilis.liaskovitis@profitbricks.com>
On Thu, Apr 19, 2012 at 04:08:46PM +0200, Vasilis Liaskovitis wrote:
> 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.
>
Why do you need this path and the next one? Bios can restore the state
of memslots and build e820 map by reading mems_sts.
> Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
> ---
> 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
> --
> 1.7.9
--
Gleb.
next prev parent reply other threads:[~2012-04-22 13:58 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-19 14:08 [RFC PATCH 0/9] ACPI memory hotplug Vasilis Liaskovitis
2012-04-19 14:08 ` [RFC PATCH 1/9][SeaBIOS] Add SSDT memory device support Vasilis Liaskovitis
2012-04-19 14:08 ` [RFC PATCH 2/9][SeaBIOS] Implement acpi-dsdt functions for memory hotplug Vasilis Liaskovitis
2012-04-20 10:55 ` Igor Mammedov
2012-04-20 14:11 ` [Qemu-devel] " Vasilis Liaskovitis
2012-04-19 14:08 ` [RFC PATCH 3/9][SeaBIOS] acpi: generate hotplug memory devices Vasilis Liaskovitis
2012-04-23 23:37 ` Kevin O'Connor
2012-04-24 8:27 ` Vasilis Liaskovitis
2012-04-19 14:08 ` [RFC PATCH 4/9] Implement memslot device abstraction Vasilis Liaskovitis
2012-04-19 14:08 ` [RFC PATCH 5/9] acpi_piix4: Implement memory device hotplug registers Vasilis Liaskovitis
2012-04-19 14:08 ` [RFC PATCH 6/9] pc: pass paravirt info for hotplug memory slots to BIOS Vasilis Liaskovitis
2012-04-19 14:21 ` Avi Kivity
2012-04-20 10:33 ` Igor Mammedov
2012-04-20 16:35 ` [Qemu-devel] " Vasilis Liaskovitis
2012-04-19 14:08 ` [RFC PATCH 7/9] Implement memslot command-line option and memslot hmp command Vasilis Liaskovitis
2012-04-19 14:22 ` Avi Kivity
2012-04-19 18:10 ` Vasilis Liaskovitis
2012-04-19 14:08 ` [RFC PATCH 8/9] pc: adjust e820 map on hot-add and hot-remove Vasilis Liaskovitis
2012-04-22 13:58 ` Gleb Natapov [this message]
2012-04-23 11:27 ` Vasilis Liaskovitis
2012-04-23 11:30 ` Gleb Natapov
2012-04-19 14:08 ` [RFC PATCH 9/9][SeaBIOS] enable memory devices if e820 entry is present Vasilis Liaskovitis
2012-04-26 0:58 ` [SeaBIOS] [RFC PATCH 9/9] " Wen Congyang
2012-04-19 14:49 ` [Qemu-devel] [RFC PATCH 0/9] ACPI memory hotplug Anthony Liguori
2012-04-19 18:09 ` Vasilis Liaskovitis
2012-04-20 14:20 ` Vasilis Liaskovitis
2012-04-22 13:56 ` Gleb Natapov
2012-04-22 14:06 ` Avi Kivity
2012-04-22 14:09 ` Gleb Natapov
2012-04-22 14:13 ` Avi Kivity
2012-04-22 14:20 ` Gleb Natapov
2012-04-23 12:31 ` Vasilis Liaskovitis
2012-04-24 7:52 ` Gleb Natapov
2012-04-24 8:24 ` Vasilis Liaskovitis
2012-04-24 8:34 ` Gleb Natapov
2012-04-23 13:31 ` Avi Kivity
2012-04-24 7:21 ` Gleb Natapov
2012-04-24 9:09 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120422135847.GB15413@redhat.com \
--to=gleb@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=seabios@seabios.org \
--cc=vasilis.liaskovitis@profitbricks.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox