From nobody Sat May 18 22:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585909274; cv=none; d=zohomail.com; s=zohoarc; b=gfgYcRCyNVlkslilLeKYmtSFxLqu2D9CzaXClK5t5BWhl1mOJnoeyEWmkjymMD8rWDpUnvWOSh54h6djQUDTE8uqS/IsPLxkyw+0n8RkZcTe1th9JtpIv1YiXMCKZlkrtAuhaevT9JA5wCvb+GEoEBonH2Q/heJfHJGRMOIr1+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585909274; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=03uQ+dj2JgryyO3ADbA5Mb9GveRHlXJTpyoD8u33LPY=; b=gkjs03d27kRE40b2+wPyEVPU/Q4SUp6AQM3V5XK+4efVKNMUQd/yAjDwyxkHDpfY9zO3du7NXjjZxuindSexOIHneWrKtY2nUrWtRARmBISTCBxIvp3XoyIdrDn6wwdblwjOcAriNUmIR1T8N7rtMn4oyxeXetKy+5dmWh/x6ds= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585909274396942.5569736765848; Fri, 3 Apr 2020 03:21:14 -0700 (PDT) Received: from localhost ([::1]:53252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKJRp-0004vr-6b for importer@patchew.org; Fri, 03 Apr 2020 06:21:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35877) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKJQT-0003NQ-Uy for qemu-devel@nongnu.org; Fri, 03 Apr 2020 06:19:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKJQS-0001rw-MN for qemu-devel@nongnu.org; Fri, 03 Apr 2020 06:19:49 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:50350 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKJQQ-0001kF-7I; Fri, 03 Apr 2020 06:19:46 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 5692B4E3BDC0BABAAD09; Fri, 3 Apr 2020 18:19:39 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.24.31) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Fri, 3 Apr 2020 18:19:32 +0800 From: Shameer Kolothum To: , , , Subject: [PATCH for-5.0 v2 1/3] acpi: Use macro for table-loader file name Date: Fri, 3 Apr 2020 11:18:25 +0100 Message-ID: <20200403101827.30664-2-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20200403101827.30664-1-shameerali.kolothum.thodi@huawei.com> References: <20200403101827.30664-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.24.31] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, xiaoguangrong.eric@gmail.com, david@redhat.com, mst@redhat.com, dgilbert@redhat.com, xuwei5@hisilicon.com, linuxarm@huawei.com, shannon.zhaosl@gmail.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use macro for "etc/table-loader" and move it to the header file similar to ACPI_BUILD_TABLE_FILE/ACPI_BUILD_RSDP_FILE etc. Signed-off-by: Shameer Kolothum Reviewed-by: Igor Mammedov Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/virt-acpi-build.c | 2 +- hw/i386/acpi-build.c | 2 +- include/hw/acpi/aml-build.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 7ef0733d71..81d41a3990 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -929,7 +929,7 @@ void virt_acpi_setup(VirtMachineState *vms) =20 build_state->linker_mr =3D acpi_add_rom_blob(virt_acpi_build_update, build_state, - tables.linker->cmd_blob, "etc/table-loader", 0); + tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE,= 0); =20 fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->d= ata, acpi_data_len(tables.tcpalog)); diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 2a7e55bae7..23c77eeb95 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -3043,7 +3043,7 @@ void acpi_setup(void) =20 build_state->linker_mr =3D acpi_add_rom_blob(acpi_build_update, build_state, - tables.linker->cmd_blob, "etc/table-loader", 0); + tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE,= 0); =20 fw_cfg_add_file(x86ms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, acpi_data_len(tables.tcpalog)); diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index de4a406568..0f4ed53d7f 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -13,6 +13,7 @@ #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp" #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log" +#define ACPI_BUILD_LOADER_FILE "etc/table-loader" =20 #define AML_NOTIFY_METHOD "NTFY" =20 --=20 2.17.1 From nobody Sat May 18 22:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585909354; cv=none; d=zohomail.com; s=zohoarc; b=QjMUj/leZwnR07vXYnRIqBXqrRfByOy6snwx2muBX+JN9yO0Q0DuQc2Xu73rGjDCnr16M491GsPlHQcomPmgTtf4V2Sd9Pgsyn0E1FOaMViWPNahJmWroip4Lrjb52pZR56sRBmFQIEKEpQaVjNuM2uz/0QEAQU6egu7PjQMwWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585909354; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=58pL0fdPMi7pI9zyqK+P8plDqu0z9oRvn08j+xJ2bb4=; b=fM4fHoMVk1vWaQ4gVyyzHIHaxhtM8V1SuWTU50cyteGF1NL89PsQNFgzPp+4A2gPek87Nh+HBjGNqv408kHsfN92pePcF6ylTZclo5aeXXWVQ1VUf7kC4sOli2idcl6BKGiJQRcSAgQYgtb4WX+cUYAXljb3nN1SQwEtt1NnijU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585909354308170.59552333339195; Fri, 3 Apr 2020 03:22:34 -0700 (PDT) Received: from localhost ([::1]:53284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKJT6-00087D-SA for importer@patchew.org; Fri, 03 Apr 2020 06:22:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35903) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKJQW-0003Rv-TP for qemu-devel@nongnu.org; Fri, 03 Apr 2020 06:19:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKJQV-0001uj-9F for qemu-devel@nongnu.org; Fri, 03 Apr 2020 06:19:52 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3732 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKJQR-0001mn-8c; Fri, 03 Apr 2020 06:19:47 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 99CC9233FAEC22757881; Fri, 3 Apr 2020 18:19:44 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.24.31) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Fri, 3 Apr 2020 18:19:37 +0800 From: Shameer Kolothum To: , , , Subject: [PATCH for-5.0 v2 2/3] fw_cfg: Migrate ACPI table mr sizes separately Date: Fri, 3 Apr 2020 11:18:26 +0100 Message-ID: <20200403101827.30664-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20200403101827.30664-1-shameerali.kolothum.thodi@huawei.com> References: <20200403101827.30664-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.24.31] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.191 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, xiaoguangrong.eric@gmail.com, david@redhat.com, mst@redhat.com, dgilbert@redhat.com, xuwei5@hisilicon.com, linuxarm@huawei.com, shannon.zhaosl@gmail.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Shameer Kolothum Acked-by: David Hildenbrand --- v1 --> v2 - Changed *_mr_size from size_t to uint64_t to address portability. - post_copy only done if sizes are not aligned. Please find previous discussions here, https://patchwork.kernel.org/patch/11339591/#23140343 --- hw/core/machine.c | 1 + hw/nvram/fw_cfg.c | 91 ++++++++++++++++++++++++++++++++++++++- include/hw/nvram/fw_cfg.h | 6 +++ 3 files changed, 97 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[] =3D { { "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 =3D G_N_ELEMENTS(hw_compat_4_2); =20 diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 179b302f01..4be6c9d9fd 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" =20 #define FW_CFG_FILE_SLOTS_DFLT 0x20 =20 @@ -610,6 +611,55 @@ bool fw_cfg_dma_enabled(void *opaque) return s->dma_enabled; } =20 +static bool fw_cfg_acpi_mr_restore(void *opaque) +{ + FWCfgState *s =3D opaque; + bool mr_aligned; + + mr_aligned =3D QEMU_IS_ALIGNED(s->table_mr_size, qemu_real_host_page_s= ize) && + QEMU_IS_ALIGNED(s->linker_mr_size, qemu_real_host_page_si= ze) && + QEMU_IS_ALIGNED(s->rsdp_mr_size, qemu_real_host_page_size= ); + return s->acpi_mr_restore && !mr_aligned; +} + +static void fw_cfg_update_mr(FWCfgState *s, uint16_t key, size_t size) +{ + MemoryRegion *mr; + ram_addr_t offset; + int arch =3D !!(key & FW_CFG_ARCH_LOCAL); + void *ptr; + + key &=3D FW_CFG_ENTRY_MASK; + assert(key < fw_cfg_max_entry(s)); + + ptr =3D s->entries[arch][key].data; + mr =3D 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 =3D opaque; + int i, index; + + assert(s->files); + + index =3D be32_to_cpu(s->files->count); + + for (i =3D 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 =3D { .name =3D "fw_cfg/dma", .needed =3D fw_cfg_dma_enabled, @@ -619,6 +669,20 @@ static const VMStateDescription vmstate_fw_cfg_dma =3D= { }, }; =20 +static const VMStateDescription vmstate_fw_cfg_acpi_mr =3D { + .name =3D "fw_cfg/acpi_mr", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D fw_cfg_acpi_mr_restore, + .post_load =3D fw_cfg_acpi_mr_restore_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT64(table_mr_size, FWCfgState), + VMSTATE_UINT64(linker_mr_size, FWCfgState), + VMSTATE_UINT64(rsdp_mr_size, FWCfgState), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_fw_cfg =3D { .name =3D "fw_cfg", .version_id =3D 2, @@ -631,6 +695,7 @@ static const VMStateDescription vmstate_fw_cfg =3D { }, .subsections =3D (const VMStateDescription*[]) { &vmstate_fw_cfg_dma, + &vmstate_fw_cfg_acpi_mr, NULL, } }; @@ -815,6 +880,23 @@ static struct { #define FW_CFG_ORDER_OVERRIDE_LAST 200 }; =20 +/* + * Any sub-page size update to these table MRs will be lost during migrati= on, + * 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 =3D len; + } else if (!strcmp(filename, ACPI_BUILD_LOADER_FILE)) { + s->linker_mr_size =3D len; + } else if (!strcmp(filename, ACPI_BUILD_RSDP_FILE)) { + s->rsdp_mr_size =3D len; + } +} + static int get_fw_cfg_order(FWCfgState *s, const char *name) { int i; @@ -914,6 +996,7 @@ void fw_cfg_add_file_callback(FWCfgState *s, const cha= r *filename, trace_fw_cfg_add_file(s, index, s->files->f[index].name, len); =20 s->files->count =3D cpu_to_be32(count+1); + fw_cfg_acpi_mr_save(s, filename, len); } =20 void fw_cfg_add_file(FWCfgState *s, const char *filename, @@ -937,6 +1020,7 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *fi= lename, ptr =3D fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i, data, len); s->files->f[i].size =3D cpu_to_be32(len); + fw_cfg_acpi_mr_save(s, filename, len); return ptr; } } @@ -973,7 +1057,10 @@ static void fw_cfg_machine_ready(struct Notifier *n, = void *data) qemu_register_reset(fw_cfg_machine_reset, s); } =20 - +static Property fw_cfg_properties[] =3D { + DEFINE_PROP_BOOL("acpi-mr-restore", FWCfgState, acpi_mr_restore, true), + DEFINE_PROP_END_OF_LIST(), +}; =20 static void fw_cfg_common_realize(DeviceState *dev, Error **errp) { @@ -1097,6 +1184,8 @@ static void fw_cfg_class_init(ObjectClass *klass, voi= d *data) =20 dc->reset =3D fw_cfg_reset; dc->vmsd =3D &vmstate_fw_cfg; + + device_class_set_props(dc, fw_cfg_properties); } =20 static const TypeInfo fw_cfg_info =3D { diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h index b5291eefad..25d9307018 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; + uint64_t table_mr_size; + uint64_t linker_mr_size; + uint64_t rsdp_mr_size; }; =20 struct FWCfgIoState { --=20 2.17.1 From nobody Sat May 18 22:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585909287; cv=none; d=zohomail.com; s=zohoarc; b=gmLN4g4Lp9wwd3uAZu1o5kOPQZeXq0FiBCZ8OUQFkjY4UHfcZef9IwsTI2I+QwdehIlJuuJiBW8uvH2O8SpfppWPCvP9wc0tpsiybcCpLCHHzFpknDmqtnJqSPBx77DrHAf1UgZ+sP/+f0BepRZvFwzBPU0lpfCipxSknjJES2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585909287; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iFUpAzeliQFHgW5uVlrZOFQswa0SqmFF2uG4ZCQ1Crs=; b=R0kTrD8H9IAFX6+yq/7igYHpndjCgG1iVys4x6OEE65Oq+8Q+H5ZcsBcEUlNHInwfaIfhDwbY7lYRvqS/TcF6HUg2LNTaKOkU5tI+41X/7CCFkjkFEiIndX05mS6zb2U6j//mnUEl9tQapwbUWf2NbHMLdC8b+8rCspOjnRILnw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585909287446722.3397552797761; Fri, 3 Apr 2020 03:21:27 -0700 (PDT) Received: from localhost ([::1]:53256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKJS2-0005XO-6I for importer@patchew.org; Fri, 03 Apr 2020 06:21:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35922) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKJQd-0003W2-24 for qemu-devel@nongnu.org; Fri, 03 Apr 2020 06:20:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKJQb-0001yY-Sy for qemu-devel@nongnu.org; Fri, 03 Apr 2020 06:19:59 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:50482 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKJQV-0001tp-Ei; Fri, 03 Apr 2020 06:19:51 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 761F4107A88BBB4C1FF1; Fri, 3 Apr 2020 18:19:49 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.24.31) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Fri, 3 Apr 2020 18:19:41 +0800 From: Shameer Kolothum To: , , , Subject: [PATCH for-5.0 v2 3/3] exec: Fix for qemu_ram_resize() callback Date: Fri, 3 Apr 2020 11:18:27 +0100 Message-ID: <20200403101827.30664-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20200403101827.30664-1-shameerali.kolothum.thodi@huawei.com> References: <20200403101827.30664-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.24.31] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, xiaoguangrong.eric@gmail.com, david@redhat.com, mst@redhat.com, dgilbert@redhat.com, xuwei5@hisilicon.com, linuxarm@huawei.com, shannon.zhaosl@gmail.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Summarizing the issue: 1. Memory regions contain ram blocks with a different size, if the size is not properly aligned. While memory regions can have an unaligned size, ram blocks can't. This is true when creating resizable memory region with an unaligned size. 2. When resizing a ram block/memory region, the size of the memory region is set to the aligned size. The callback is called with the aligned size. The unaligned piece is lost. Because of the above, if ACPI blob length modifications happens after the initial virt_acpi_build() call, and the changed blob length is within the PAGE size boundary, then the revised size is not seen by the firmware on Guest reboot. Hence make sure callback is called if memory region size is changed, irrespective of aligned or not. Signed-off-by: David Hildenbrand [Shameer: added commit log] Signed-off-by: Shameer Kolothum Reviewed-by: Igor Mammedov Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- Please find previous discussion here, https://patchwork.kernel.org/patch/11432375/#23216751 --- exec.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index de9d949902..2874bb5088 100644 --- a/exec.c +++ b/exec.c @@ -2074,11 +2074,23 @@ static int memory_try_enable_merging(void *addr, si= ze_t len) */ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp) { + const ram_addr_t unaligned_size =3D newsize; + assert(block); =20 newsize =3D HOST_PAGE_ALIGN(newsize); =20 if (block->used_length =3D=3D newsize) { + /* + * We don't have to resize the ram block (which only knows aligned + * sizes), however, we have to notify if the unaligned size change= d. + */ + if (unaligned_size !=3D memory_region_size(block->mr)) { + memory_region_set_size(block->mr, unaligned_size); + if (block->resized) { + block->resized(block->idstr, unaligned_size, block->host); + } + } return 0; } =20 @@ -2102,9 +2114,9 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsi= ze, Error **errp) block->used_length =3D newsize; cpu_physical_memory_set_dirty_range(block->offset, block->used_length, DIRTY_CLIENTS_ALL); - memory_region_set_size(block->mr, newsize); + memory_region_set_size(block->mr, unaligned_size); if (block->resized) { - block->resized(block->idstr, newsize, block->host); + block->resized(block->idstr, unaligned_size, block->host); } return 0; } --=20 2.17.1