From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Cc: peter.maydell@linaro.org, xiaoguangrong.eric@gmail.com,
david@redhat.com, shannon.zhaosl@gmail.com, mst@redhat.com,
qemu-devel@nongnu.org, xuwei5@hisilicon.com, linuxarm@huawei.com,
eric.auger@redhat.com, qemu-arm@nongnu.org, imammedo@redhat.com,
lersek@redhat.com
Subject: Re: [PATCH for-5.0 2/3] fw_cfg: Migrate ACPI table mr sizes separately
Date: Tue, 31 Mar 2020 11:45:43 +0100 [thread overview]
Message-ID: <20200331104543.GA2942@work-vm> (raw)
In-Reply-To: <20200330164909.28324-3-shameerali.kolothum.thodi@huawei.com>
* Shameer Kolothum (shameerali.kolothum.thodi@huawei.com) wrote:
> Any sub-page size update to ACPI MRs will be lost during
> migration, as we use aligned size in ram_load_precopy() ->
> qemu_ram_resize() path. This will result in inconsistency in
> FWCfgEntry sizes between source and destination. In order to avoid
> this, save and restore them separately during migration.
>
> Up until now, this problem may not be that relevant for x86 as both
> ACPI table and Linker MRs gets padded and aligned. Also at present,
> qemu_ram_resize() doesn't invoke callback to update FWCfgEntry for
> unaligned size changes. But since we are going to fix the
> qemu_ram_resize() in the subsequent patch, the issue may become
> more serious especially for RSDP MR case.
>
> Moreover, the issue will soon become prominent in arm/virt as well
> where the MRs are not padded or aligned at all and eventually have
> acpi table changes as part of future additions like NVDIMM hot-add
> feature.
>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> Acked-by: David Hildenbrand <david@redhat.com>
> ---
> Please find previous discussions here,
> https://patchwork.kernel.org/patch/11339591/#23140343
> ---
>
> hw/core/machine.c | 1 +
> hw/nvram/fw_cfg.c | 86 ++++++++++++++++++++++++++++++++++++++-
> include/hw/nvram/fw_cfg.h | 6 +++
> 3 files changed, 92 insertions(+), 1 deletion(-)
>
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index de0c425605..c1a444cb75 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -39,6 +39,7 @@ GlobalProperty hw_compat_4_2[] = {
> { "usb-redir", "suppress-remote-wake", "off" },
> { "qxl", "revision", "4" },
> { "qxl-vga", "revision", "4" },
> + { "fw_cfg", "acpi-mr-restore", "false" },
> };
> const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2);
>
> diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
> index 179b302f01..36d1e32f83 100644
> --- a/hw/nvram/fw_cfg.c
> +++ b/hw/nvram/fw_cfg.c
> @@ -39,6 +39,7 @@
> #include "qemu/config-file.h"
> #include "qemu/cutils.h"
> #include "qapi/error.h"
> +#include "hw/acpi/aml-build.h"
>
> #define FW_CFG_FILE_SLOTS_DFLT 0x20
>
> @@ -610,6 +611,50 @@ bool fw_cfg_dma_enabled(void *opaque)
> return s->dma_enabled;
> }
>
> +static bool fw_cfg_acpi_mr_restore(void *opaque)
> +{
> + FWCfgState *s = opaque;
> + return s->acpi_mr_restore;
> +}
> +
> +static void fw_cfg_update_mr(FWCfgState *s, uint16_t key, size_t size)
> +{
> + MemoryRegion *mr;
> + ram_addr_t offset;
> + int arch = !!(key & FW_CFG_ARCH_LOCAL);
> + void *ptr;
> +
> + key &= FW_CFG_ENTRY_MASK;
> + assert(key < fw_cfg_max_entry(s));
> +
> + ptr = s->entries[arch][key].data;
> + mr = memory_region_from_host(ptr, &offset);
> +
> + memory_region_ram_resize(mr, size, &error_abort);
> +}
> +
> +static int fw_cfg_acpi_mr_restore_post_load(void *opaque, int version_id)
> +{
> + FWCfgState *s = opaque;
> + int i, index;
> +
> + assert(s->files);
> +
> + index = be32_to_cpu(s->files->count);
> +
> + for (i = 0; i < index; i++) {
> + if (!strcmp(s->files->f[i].name, ACPI_BUILD_TABLE_FILE)) {
> + fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->table_mr_size);
> + } else if (!strcmp(s->files->f[i].name, ACPI_BUILD_LOADER_FILE)) {
> + fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->linker_mr_size);
> + } else if (!strcmp(s->files->f[i].name, ACPI_BUILD_RSDP_FILE)) {
> + fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->rsdp_mr_size);
> + }
> + }
> +
> + return 0;
> +}
> +
> static const VMStateDescription vmstate_fw_cfg_dma = {
> .name = "fw_cfg/dma",
> .needed = fw_cfg_dma_enabled,
> @@ -619,6 +664,20 @@ static const VMStateDescription vmstate_fw_cfg_dma = {
> },
> };
>
> +static const VMStateDescription vmstate_fw_cfg_acpi_mr = {
> + .name = "fw_cfg/acpi_mr",
> + .version_id = 1,
> + .minimum_version_id = 1,
> + .needed = fw_cfg_acpi_mr_restore,
> + .post_load = fw_cfg_acpi_mr_restore_post_load,
> + .fields = (VMStateField[]) {
> + VMSTATE_UINT64(table_mr_size, FWCfgState),
> + VMSTATE_UINT64(linker_mr_size, FWCfgState),
> + VMSTATE_UINT64(rsdp_mr_size, FWCfgState),
The checker found something I also spotted; which is you can't use a
VMSTATE_UINT64 against a field that is size_t - it's not portable;
I suggest the easiest fix is to make your fields in fw_cfg.h uint64's.
Dave
> + VMSTATE_END_OF_LIST()
> + },
> +};
> +
> static const VMStateDescription vmstate_fw_cfg = {
> .name = "fw_cfg",
> .version_id = 2,
> @@ -631,6 +690,7 @@ static const VMStateDescription vmstate_fw_cfg = {
> },
> .subsections = (const VMStateDescription*[]) {
> &vmstate_fw_cfg_dma,
> + &vmstate_fw_cfg_acpi_mr,
> NULL,
> }
> };
> @@ -815,6 +875,23 @@ static struct {
> #define FW_CFG_ORDER_OVERRIDE_LAST 200
> };
>
> +/*
> + * Any sub-page size update to these table MRs will be lost during migration,
> + * as we use aligned size in ram_load_precopy() -> qemu_ram_resize() path.
> + * In order to avoid the inconsistency in sizes save them seperately and
> + * migrate over in vmstate post_load().
> + */
> +static void fw_cfg_acpi_mr_save(FWCfgState *s, const char *filename, size_t len)
> +{
> + if (!strcmp(filename, ACPI_BUILD_TABLE_FILE)) {
> + s->table_mr_size = len;
> + } else if (!strcmp(filename, ACPI_BUILD_LOADER_FILE)) {
> + s->linker_mr_size = len;
> + } else if (!strcmp(filename, ACPI_BUILD_RSDP_FILE)) {
> + s->rsdp_mr_size = len;
> + }
> +}
> +
> static int get_fw_cfg_order(FWCfgState *s, const char *name)
> {
> int i;
> @@ -914,6 +991,7 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
> trace_fw_cfg_add_file(s, index, s->files->f[index].name, len);
>
> s->files->count = cpu_to_be32(count+1);
> + fw_cfg_acpi_mr_save(s, filename, len);
> }
>
> void fw_cfg_add_file(FWCfgState *s, const char *filename,
> @@ -937,6 +1015,7 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
> ptr = fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i,
> data, len);
> s->files->f[i].size = cpu_to_be32(len);
> + fw_cfg_acpi_mr_save(s, filename, len);
> return ptr;
> }
> }
> @@ -973,7 +1052,10 @@ static void fw_cfg_machine_ready(struct Notifier *n, void *data)
> qemu_register_reset(fw_cfg_machine_reset, s);
> }
>
> -
> +static Property fw_cfg_properties[] = {
> + DEFINE_PROP_BOOL("acpi-mr-restore", FWCfgState, acpi_mr_restore, true),
> + DEFINE_PROP_END_OF_LIST(),
> +};
>
> static void fw_cfg_common_realize(DeviceState *dev, Error **errp)
> {
> @@ -1097,6 +1179,8 @@ static void fw_cfg_class_init(ObjectClass *klass, void *data)
>
> dc->reset = fw_cfg_reset;
> dc->vmsd = &vmstate_fw_cfg;
> +
> + device_class_set_props(dc, fw_cfg_properties);
> }
>
> static const TypeInfo fw_cfg_info = {
> diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
> index b5291eefad..457fee7425 100644
> --- a/include/hw/nvram/fw_cfg.h
> +++ b/include/hw/nvram/fw_cfg.h
> @@ -53,6 +53,12 @@ struct FWCfgState {
> dma_addr_t dma_addr;
> AddressSpace *dma_as;
> MemoryRegion dma_iomem;
> +
> + /* restore during migration */
> + bool acpi_mr_restore;
> + size_t table_mr_size;
> + size_t linker_mr_size;
> + size_t rsdp_mr_size;
> };
>
> struct FWCfgIoState {
> --
> 2.17.1
>
>
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2020-03-31 10:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-30 16:49 [PATCH for-5.0 0/3] acpi: Fixes for inconsistency in ACPI MR size during migration Shameer Kolothum
2020-03-30 16:49 ` [PATCH for-5.0 1/3] acpi: Use macro for table-loader file name Shameer Kolothum
2020-03-30 16:49 ` [PATCH for-5.0 2/3] fw_cfg: Migrate ACPI table mr sizes separately Shameer Kolothum
2020-03-31 10:45 ` Dr. David Alan Gilbert [this message]
2020-04-01 7:45 ` Shameerali Kolothum Thodi
2020-03-31 14:50 ` Igor Mammedov
2020-03-31 15:02 ` Michael S. Tsirkin
2020-03-31 15:03 ` Michael S. Tsirkin
2020-04-01 7:48 ` Shameerali Kolothum Thodi
2020-03-30 16:49 ` [PATCH for-5.0 3/3] exec: Fix for qemu_ram_resize() callback Shameer Kolothum
2020-03-30 19:59 ` [PATCH for-5.0 0/3] acpi: Fixes for inconsistency in ACPI MR size during migration no-reply
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=20200331104543.GA2942@work-vm \
--to=dgilbert@redhat.com \
--cc=david@redhat.com \
--cc=eric.auger@redhat.com \
--cc=imammedo@redhat.com \
--cc=lersek@redhat.com \
--cc=linuxarm@huawei.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=shannon.zhaosl@gmail.com \
--cc=xiaoguangrong.eric@gmail.com \
--cc=xuwei5@hisilicon.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;
as well as URLs for NNTP newsgroup(s).