feat(patches): add Intel WHPX suspend and Win32 mapped-ram I/O patches

This commit is contained in:
YXC0915 committed 2026-12-01 07:44:35 +08:00
1 parent 9eb8d95443
commit 585669e0b3
4 files changed
+1653

No files matched your search

+18
View File
@@ -30,6 +30,8 @@
| [`qemu-whpx-win10-startup-ipis.patch`](qemu-whpx-win10-startup-ipis.patch) | `vendor/qemu` (`target/i386/whpx/whpx-all.c`) | 在 Win10 开启 `kernel-irqchip` 且多核启动时经 `WHvRequestInterrupt` 转发 INIT/SIPI,避免 XNU 从核卡死(依赖上一项) | 8/12 核冷启动通过;客体软重启待验证,待提 PR |
| [`qemu-whpx-nested-virt-nonfatal.patch`](qemu-whpx-nested-virt-nonfatal.patch) | `vendor/qemu` (`target/i386/whpx/whpx-all.c`) | 部分 Win11 宿主设置嵌套虚拟化属性返回 `0x80370302` 时改为警告并清零特性位,保留 `kernel-irqchip=on` 加速(依赖前两项) | 待编入 `alpha` 并在 Win11 真机验证后提 PR |
| [`qemu-win32-coroutine-fiber-commit.patch`](qemu-win32-coroutine-fiber-commit.patch) | `vendor/qemu` (`util/coroutine-windows.c`) | 改用 `CreateFiberEx(64 KiB, 1 MiB, ...)` 将协程初始提交降至 1/16,并判空与检查 `IsThreadAFiber()`,避免高并发 I/O 时 `SwitchToFiber(NULL)` 崩溃 | `git apply --check` 通过;待编入 `alpha` 真机验证后提 PR |
| [`qemu-win32-mapped-ram-io.patch`](qemu-win32-mapped-ram-io.patch) | `vendor/qemu` (`io/channel*.c`, `migration/*.c`) | 为 Win32 `QIOChannelFile` 实现 `preadv`/`pwritev`(合并读写路径、零写保护与文件指针恢复),并解除 `mapped-ram` + `multifd` 文件快照在 Windows 下的 POSIX 限制 | Win11 WHPX 真机跨进程及真实宿主重启恢复实测通过;待提 PR |
| [`qemu-intel-whpx-suspend.patch`](qemu-intel-whpx-suspend.patch) | `vendor/qemu` (`accel/whpx/`, `target/i386/whpx/`, `hw/misc/applesmc.c`, `hw/display/reims-graphics-pci.c`, `migration/`) | 为 Intel x86-64 WHPX 实现停机文件挂起(限制在已暂停 VM 的 `MIG_MODE_NORMAL` + `file:` 迁移入口,保留非 `normal`/在线迁移与 `savevm` 拦截)、完整 LAPIC/x2APIC/TSC/AppleSMC 与 `reims-graphics-pci` VMState 保存恢复 | 7 项 QMP 闸门回归 + Win11 WHPX 真机解锁桌面同 PID Metal 读回及真实宿主重启通过;待提 PR |
---
@@ -103,6 +105,22 @@
- **最小修复**:仅当磁盘为 `qcow2` 且本地可读有效头时,读取虚拟容量与 `cluster_bits` 计算 `virtual_size / cluster_size * 8` 向上取整至 MiB(上限 32 MiB),大于 8 MiB 时追加 `,l2-cache-size={mib}M`;不存在文件时静默忽略,不影响现有单元测试。
- **实测证据**(128 GiB 镜像 16 MiB L2 缓存):`rand-read-large`(热缓存)QEMU 块层平均读延迟从 128.5 μs 降至 70.6 μs(-45.1%),端到端耗时从 1,623.6 ms 降至 1,498.7 ms(-7.7%),仅增加 8 MiB 内存占用且无稳定性风险。
### 9. `qemu-win32-mapped-ram-io.patch`
- **建议 PR 标题**:`io/channel-file & migration: support Win32 positioned vector I/O for mapped-ram file snapshots`
- **目标**:`steelbrain/qemu-reims-vgpu`(`io/channel-file.c`, `io/channel*.c`, `migration/file.c`, `migration/ram.c`, `migration/qemu-file.c`, `migration/channel-block.c`)
- **影响环境**:Windows 宿主使用 `mapped-ram` + `multifd` 执行停机文件挂起与恢复的场景。
- **根因**:上游 `QIOChannelFile` 的 `preadv`/`pwritev` 仅在非 Win32 路径实现,`mapped-ram` 与 `multifd` 文件通道在 Windows 上直接受限。
- **最小修复**:合并 Win32 定位读写公共逻辑(统一偏移校验、溢出安全分块、EOF/短写语义区分、零字节写入返回 `EIO` 防止死循环以及恢复原文件指针),并开放 Win32 `mapped-ram` + `multifd` 文件路径。
### 10. `qemu-intel-whpx-suspend.patch`
- **建议 PR 标题**:`whpx & reims-graphics-pci: support paused-VM file suspend and resume on Intel x86-64`
- **目标**:`steelbrain/qemu-reims-vgpu`(`accel/whpx/whpx-common.c`, `include/system/whpx-common.h`, `target/i386/whpx/whpx-all.c`, `target/i386/whpx/whpx-apic.c`, `hw/misc/applesmc.c`, `hw/display/reims-graphics-pci.c`, `migration/migration.c`, `migration/savevm.c`)
- **影响环境**:Intel x86-64 macOS 客体在 Windows WHPX 上的停机挂起至磁盘与跨进程/跨宿主重启恢复。
- **最小修复**:
1. 保留非 `MIG_MODE_NORMAL` 模式的 WHPX migration blocker,并在 `qmp_migrate()`、WHPX `MIG_EVENT_SETUP` 回调与 `save_snapshot()` 强制检查:仅放行已暂停 VM 的 `MIG_MODE_NORMAL` + `file:` 路径,拒绝运行中迁移、非 `file:` 传输、postcopy、background-snapshot、COLO 及 `savevm`。
2. 补齐 WHPX x86-64 vCPU/LAPIC/x2APIC/TSC 寄存器与 AppleSMC、`reims-graphics-pci` 设备 VMState 保存恢复回调(含损坏快照向 QMP 返回错误并保留挂起文件)。
- **实测证据**:7 项 QMP 闸门回归全部通过;Windows 11 WHPX + RTX A5000 + Intel macOS 26.7.3 解锁桌面实测跨完整 QEMU 退出及真实 Windows 重启恢复,首帧 1920×1080 SHA-256 完全一致,原应用 PID / Metal 队列 / Private 资源读回 100% 匹配。
---
## 关注中的上游 PR 与演进
+906
View File
@@ -0,0 +1,906 @@
diff --git a/accel/whpx/whpx-common.c b/accel/whpx/whpx-common.c
index 63e941496d055f1075e8e860b3785a179bb42edf..13bf3e890a93000e32fd0036fc1fde7a75c46eb4 100644
--- a/accel/whpx/whpx-common.c
+++ b/accel/whpx/whpx-common.c
@@ -50,8 +50,14 @@ struct WHPDispatch whp_dispatch;
void whpx_flush_cpu_state(CPUState *cpu)
{
if (cpu->vcpu_dirty) {
- whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE);
+ WHPXStateLevel level = (cpu->accel && cpu->accel->loadvm_pending)
+ ? WHPX_LEVEL_FULL_STATE
+ : WHPX_LEVEL_RUNTIME_STATE;
+ whpx_set_registers(cpu, level);
cpu->vcpu_dirty = false;
+ if (cpu->accel) {
+ cpu->accel->loadvm_pending = false;
+ }
}
}
@@ -207,6 +213,19 @@ static void do_whpx_cpu_synchronize_pre_loadvm(CPUState *cpu,
run_on_cpu_data arg)
{
cpu->vcpu_dirty = true;
+ if (cpu->accel) {
+ cpu->accel->loadvm_pending = true;
+ }
+}
+
+static void do_whpx_cpu_synchronize_post_loadvm(CPUState *cpu,
+ run_on_cpu_data arg)
+{
+ if (cpu->accel && cpu->accel->loadvm_pending) {
+ whpx_set_registers(cpu, WHPX_LEVEL_FULL_STATE);
+ cpu->vcpu_dirty = false;
+ cpu->accel->loadvm_pending = false;
+ }
}
/*
@@ -237,7 +256,36 @@ void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu)
static void whpx_pre_resume_vm(AccelState *as, bool step_pending)
{
+ CPUState *cpu;
+ bool any_loadvm = false;
+
whpx_global.step_pending = step_pending;
+
+ CPU_FOREACH(cpu) {
+ if (cpu->accel && cpu->accel->loadvm_pending) {
+ any_loadvm = true;
+ break;
+ }
+ }
+ if (any_loadvm) {
+ uint64_t max_tsc = 0;
+ CPU_FOREACH(cpu) {
+ uint64_t t = cpu_env(cpu)->tsc;
+ if (t > max_tsc) {
+ max_tsc = t;
+ }
+ }
+ if (whp_dispatch.WHvSuspendPartitionTime) {
+ whp_dispatch.WHvSuspendPartitionTime(whpx_global.partition);
+ }
+ CPU_FOREACH(cpu) {
+ if (cpu->accel && cpu->accel->loadvm_pending) {
+ cpu_env(cpu)->tsc = max_tsc;
+ run_on_cpu(cpu, do_whpx_cpu_synchronize_post_loadvm,
+ RUN_ON_CPU_NULL);
+ }
+ }
+ }
}
/*
@@ -525,7 +573,7 @@ static void whpx_log_sync(MemoryListener *listener,
{
MemoryRegion *mr = section->mr;
- if (!memory_region_is_ram(mr)) {
+ if (!memory_region_is_ram(mr) || !runstate_is_running()) {
return;
}
diff --git a/hw/display/reims-graphics-pci.c b/hw/display/reims-graphics-pci.c
index db10858b65dc0447f7d0e660fca6f1acc3bb7473..976b5d4e3bd4d93d2e9a401fd494eeb2d8e6a442 100644
--- a/hw/display/reims-graphics-pci.c
+++ b/hw/display/reims-graphics-pci.c
@@ -114,7 +114,9 @@
#endif
#include "qapi/error.h"
#include "qapi/qapi-commands-ui.h"
-#include "migration/blocker.h"
+#include "migration/misc.h"
+#include "migration/vmstate.h"
+#include "migration/qemu-file-types.h"
#include "hw/core/qdev-properties.h"
#include "hw/pci/pci_device.h"
#include "hw/pci/msix.h"
@@ -232,6 +234,10 @@ struct ReimsGraphicsPCIState {
bool irqfd_made; /* the notifier is initialised */
RvgGraphicsDevice *device;
VMChangeStateEntry *vm_state; /* the teardown at QEMU's quit */
+ NotifierWithReturn mig_notifier;
+ bool mig_notifier_added;
+ bool mig_quiesced;
+ bool region_registered;
/* The displays, display i head i: the first `displays` of them. */
ReimsGraphicsHead heads[RVG_GRAPHICS_DISPLAYS_MAX];
ThreadPool *pool; /* where the consoles' reads of the displays run */
@@ -283,7 +289,6 @@ struct ReimsGraphicsPCIState {
QEMU_BUILD_BUG_ON(RVG_GRAPHICS_MSIX_VECTORS != 1);
-static Error *reims_graphics_mig_blocker;
/* ------ Interrupts ------ */
@@ -1388,6 +1393,7 @@ static bool reims_graphics_pool_add(ReimsGraphicsPCIState *s,
memory_region_init_ram_ptr(&piece->mr, OBJECT(piece),
"reims-graphics-pci.pool-piece", ask->size,
ask->host);
+ qemu_ram_unset_migratable(piece->mr.ram_block);
/*
* Inside the add's transaction: on its own, set_unmergeable commits
* (and renders every flat view) for a region that is in none yet.
@@ -2111,6 +2117,14 @@ static void reims_graphics_pci_teardown(ReimsGraphicsPCIState *s, bool quit)
ReimsGraphicsHead *head;
uint32_t i;
+ if (s->mig_notifier_added) {
+ migration_remove_notifier(&s->mig_notifier);
+ s->mig_notifier_added = false;
+ }
+ if (s->region_registered) {
+ vmstate_unregister_ram(&s->region, DEVICE(dev));
+ s->region_registered = false;
+ }
if (s->vm_state) {
qemu_del_vm_change_state_handler(s->vm_state);
s->vm_state = NULL;
@@ -2477,6 +2491,158 @@ static bool reims_graphics_linux_floor(Error **errp)
return true;
}
+
+static int reims_graphics_pci_mig_notify(NotifierWithReturn *notify,
+ MigrationEvent *e, Error **errp)
+{
+ ReimsGraphicsPCIState *s =
+ container_of(notify, ReimsGraphicsPCIState, mig_notifier);
+
+ if (!s->device) {
+ return 0;
+ }
+ switch (e->type) {
+ case MIG_EVENT_SETUP:
+ if (!s->mig_quiesced) {
+ RvgStatus status = rvg_graphics_device_quiesce(s->device);
+ if (status != RVG_OK) {
+ error_setg(errp, "%s: rvg_graphics_device_quiesce failed: %s",
+ TYPE_REIMS_GRAPHICS_PCI, rvg_status_message(status));
+ return -1;
+ }
+ reims_graphics_pool_bh(s);
+ s->mig_quiesced = true;
+ }
+ break;
+ case MIG_EVENT_DONE:
+ case MIG_EVENT_FAILED:
+ if (s->mig_quiesced) {
+ rvg_graphics_device_unquiesce(s->device);
+ s->mig_quiesced = false;
+ }
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static int reims_graphics_vgpu_snapshot_put(QEMUFile *f, void *pv, size_t size,
+ const VMStateField *field,
+ JSONWriter *vmdesc)
+{
+ ReimsGraphicsPCIState *s = pv;
+ uint8_t *data = NULL;
+ uintptr_t len = 0;
+ uintptr_t off = 0;
+ RvgStatus status;
+
+ if (!s->device) {
+ qemu_put_be64(f, 0);
+ return 0;
+ }
+ status = rvg_graphics_device_snapshot_save(s->device, &data, &len);
+ if (status != RVG_OK) {
+ error_report("%s: rvg_graphics_device_snapshot_save failed: %s",
+ TYPE_REIMS_GRAPHICS_PCI, rvg_status_message(status));
+ return -EIO;
+ }
+ qemu_put_be64(f, (uint64_t)len);
+ while (off < len) {
+ size_t chunk = (size_t)MIN(len - off, (uintptr_t)(1 * MiB));
+ qemu_put_buffer(f, data + off, chunk);
+ off += chunk;
+ }
+ rvg_graphics_snapshot_free(data, len);
+ return qemu_file_get_error(f);
+}
+
+static int reims_graphics_vgpu_snapshot_get(QEMUFile *f, void *pv, size_t size,
+ const VMStateField *field)
+{
+ ReimsGraphicsPCIState *s = pv;
+ uint64_t len = qemu_get_be64(f);
+ uint8_t *buf = NULL;
+ uint64_t off = 0;
+ RvgStatus status;
+
+ if (qemu_file_get_error(f)) {
+ return qemu_file_get_error(f);
+ }
+ if (len == 0) {
+ return 0;
+ }
+ if (len > (uint64_t)8 * GiB || !s->device) {
+ error_report("%s: invalid vgpu snapshot length %" PRIu64,
+ TYPE_REIMS_GRAPHICS_PCI, len);
+ return -EINVAL;
+ }
+ buf = g_try_malloc(len);
+ if (!buf) {
+ return -ENOMEM;
+ }
+ while (off < len) {
+ size_t chunk = (size_t)MIN(len - off, (uint64_t)(1 * MiB));
+ size_t got = qemu_get_buffer(f, buf + off, chunk);
+ if (got != chunk) {
+ g_free(buf);
+ return -EIO;
+ }
+ off += got;
+ }
+ status = rvg_graphics_device_snapshot_load(s->device, buf, (size_t)len);
+ g_free(buf);
+ if (status != RVG_OK) {
+ error_report("%s: rvg_graphics_device_snapshot_load failed: %s",
+ TYPE_REIMS_GRAPHICS_PCI, rvg_status_message(status));
+ return -EIO;
+ }
+ return 0;
+}
+
+static const VMStateInfo vmstate_info_reims_vgpu_snapshot = {
+ .name = "reims-vgpu-snapshot",
+ .get = reims_graphics_vgpu_snapshot_get,
+ .put = reims_graphics_vgpu_snapshot_put,
+};
+
+static int reims_graphics_pci_post_load(void *opaque, int version_id)
+{
+ ReimsGraphicsPCIState *s = opaque;
+ PCIDevice *dev = PCI_DEVICE(s);
+
+ /* Synchronously map all restored Shared Pool pieces into guest GPA before cont. */
+ reims_graphics_pool_bh(s);
+
+ if (msix_enabled(dev)) {
+ if (s->irqfd_made) {
+ reims_graphics_pci_irqfd_enable(s);
+ } else if (s->msi_direct_made) {
+ reims_graphics_pci_direct_enable(s);
+ }
+ }
+ return 0;
+}
+
+static const VMStateDescription vmstate_reims_graphics_pci = {
+ .name = TYPE_REIMS_GRAPHICS_PCI,
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .post_load = reims_graphics_pci_post_load,
+ .fields = (const VMStateField[]) {
+ VMSTATE_PCI_DEVICE(parent_obj, ReimsGraphicsPCIState),
+ VMSTATE_MSIX(parent_obj, ReimsGraphicsPCIState),
+ {
+ .name = "reims_vgpu_snapshot",
+ .info = &vmstate_info_reims_vgpu_snapshot,
+ .flags = VMS_SINGLE,
+ .size = sizeof(ReimsGraphicsPCIState),
+ .offset = 0,
+ },
+ VMSTATE_END_OF_LIST()
+ }
+};
+
static void reims_graphics_pci_realize(PCIDevice *dev, Error **errp)
{
ReimsGraphicsPCIState *s = REIMS_GRAPHICS_PCI(dev);
@@ -2577,13 +2743,7 @@ static void reims_graphics_pci_realize(PCIDevice *dev, Error **errp)
}
reims_graphics_pci_check_low_ram();
- if (reims_graphics_mig_blocker == NULL) {
- error_setg(&reims_graphics_mig_blocker,
- "Migration state blocked by reims-graphics-pci");
- if (migrate_add_blocker(&reims_graphics_mig_blocker, errp) < 0) {
- return;
- }
- }
+
/*
* The guest's RAM, through which the GPU uses an IOSurface's own pages in
@@ -2707,6 +2867,8 @@ static void reims_graphics_pci_realize(PCIDevice *dev, Error **errp)
base = rvg_graphics_device_region(s->device, &size);
memory_region_init_ram_ptr(&s->region, OBJECT(dev),
"reims-graphics-pci.region", size, base);
+ vmstate_register_ram(&s->region, DEVICE(dev));
+ s->region_registered = true;
pci_register_bar(dev, RVG_GRAPHICS_PCI_BAR_REGION,
PCI_BASE_ADDRESS_SPACE_MEMORY |
PCI_BASE_ADDRESS_MEM_TYPE_64 |
@@ -2728,6 +2890,8 @@ static void reims_graphics_pci_realize(PCIDevice *dev, Error **errp)
}
s->vm_state = qemu_add_vm_change_state_handler(
reims_graphics_pci_vm_state_change, s);
+ migration_add_notifier(&s->mig_notifier, reims_graphics_pci_mig_notify);
+ s->mig_notifier_added = true;
return;
fail:
@@ -2795,6 +2959,7 @@ static void reims_graphics_pci_class_init(ObjectClass *klass, const void *data)
rc->phases.hold = reims_graphics_pci_reset;
dc->desc = "reims-graphics GPU";
+ dc->vmsd = &vmstate_reims_graphics_pci;
dc->hotpluggable = false;
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
device_class_set_props(dc, reims_graphics_pci_properties);
diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c
index 84bcf4df0abb15ea73fc03ecc2a2c236ae4a7c8c..2dcc20aa0e28104f5d9fa2e2a4a5ffaee4648821 100644
--- a/hw/misc/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -37,6 +37,7 @@
#include "qemu/error-report.h"
#include "qemu/module.h"
#include "qemu/timer.h"
+#include "migration/vmstate.h"
#include "qom/object.h"
#include "hw/acpi/acpi_aml_interface.h"
@@ -108,7 +109,7 @@ struct AppleSMCState {
uint8_t status;
uint8_t status_1e;
uint8_t last_ret;
- char key[4];
+ uint8_t key[4];
uint8_t read_pos;
uint8_t data_len;
uint8_t data_pos;
@@ -407,11 +408,30 @@ static void build_applesmc_aml(AcpiDevAmlIf *adev, Aml *scope)
aml_append(scope, dev);
}
+static const VMStateDescription vmstate_applesmc = {
+ .name = "applesmc",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (const VMStateField[]) {
+ VMSTATE_UINT8(cmd, AppleSMCState),
+ VMSTATE_UINT8(status, AppleSMCState),
+ VMSTATE_UINT8(status_1e, AppleSMCState),
+ VMSTATE_UINT8(last_ret, AppleSMCState),
+ VMSTATE_UINT8_ARRAY(key, AppleSMCState, 4),
+ VMSTATE_UINT8(read_pos, AppleSMCState),
+ VMSTATE_UINT8(data_len, AppleSMCState),
+ VMSTATE_UINT8(data_pos, AppleSMCState),
+ VMSTATE_UINT8_ARRAY(data, AppleSMCState, 255),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
static void qdev_applesmc_class_init(ObjectClass *klass, const void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(klass);
+ dc->vmsd = &vmstate_applesmc;
dc->realize = applesmc_isa_realize;
dc->unrealize = applesmc_unrealize;
device_class_set_legacy_reset(dc, qdev_applesmc_isa_reset);
diff --git a/include/system/whpx-common.h b/include/system/whpx-common.h
index 79710e2fb3c96edda813fadbda5f8ceabcc5afac..a6fcbd2346b8e34a26f868a0ec19250a0fd268a6 100644
--- a/include/system/whpx-common.h
+++ b/include/system/whpx-common.h
@@ -9,6 +9,7 @@ struct AccelCPUState {
bool ready_for_pic_interrupt;
uint64_t tpr;
bool interruption_pending;
+ bool loadvm_pending;
/* Must be the last field as it may have a tail */
WHV_RUN_VP_EXIT_CONTEXT exit_ctx;
};
diff --git a/migration/migration.c b/migration/migration.c
index 5686209ab11b263b20776d79df79baecd26c5970..f105f616d1dbc88daac2c573c9a95cd02305d9ab 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -63,6 +63,7 @@
#include "system/dirtylimit.h"
#include "qemu/sockets.h"
#include "system/kvm.h"
+#include "system/whpx.h"
#include "math.h"
#define NOTIFIER_ELEM_INIT(array, elem) \
@@ -2174,6 +2175,34 @@ void qmp_migrate(const char *uri, bool has_channels,
return;
}
+ if (whpx_enabled()) {
+ if (has_resume && resume) {
+ error_setg(errp, "WHPX: migration resume is not supported");
+ return;
+ }
+ if (migrate_mode() != MIG_MODE_NORMAL) {
+ error_setg(errp, "WHPX: only normal migration mode is supported");
+ return;
+ }
+ if (runstate_is_running()) {
+ error_setg(errp,
+ "WHPX: live migration is not supported while the VM is running; stop the VM first");
+ return;
+ }
+ if (main_ch->addr->transport != MIGRATION_ADDRESS_TYPE_FILE) {
+ error_setg(errp,
+ "WHPX: only stopped-VM file suspend (file: URI) is supported");
+ return;
+ }
+ if (migrate_postcopy() || migrate_background_snapshot() ||
+ migrate_colo() || migrate_dirty_bitmaps() ||
+ migrate_return_path()) {
+ error_setg(errp,
+ "WHPX: unsupported migration capability for stopped-VM file suspend");
+ return;
+ }
+ }
+
if (!migrate_prepare(s, has_resume && resume, errp)) {
/* Error detected, put into errp */
return;
diff --git a/migration/savevm.c b/migration/savevm.c
index fe94ba96e432c8555bcfc58d97f3830a86eaab60..2a1944010c595995f6d75d3cb4d6ca67525ec1fa 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -64,6 +64,7 @@
#include "system/runstate.h"
#include "system/system.h"
#include "system/xen.h"
+#include "system/whpx.h"
#include "migration/colo.h"
#include "qemu/bitmap.h"
#include "net/announce.h"
@@ -3317,6 +3318,12 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
return false;
}
+ if (whpx_enabled()) {
+ error_setg(errp,
+ "WHPX: internal VM snapshots are not supported; use stopped-VM file migration");
+ return false;
+ }
+
if (!replay_can_snapshot()) {
error_setg(errp, "Record/replay does not allow making snapshot "
"right now. Try once more later.");
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index f093b59c0f04e1cdf6a14172d3b059068e61ac00..30b64eb901dcb6d0781c87dfc4241e6b4abe635c 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -32,6 +32,7 @@
#include "qapi/qapi-types-common.h"
#include "qapi/qapi-type-infos-common.h"
#include "migration/blocker.h"
+#include "migration/misc.h"
#include "host-cpu.h"
#include "accel/accel-cpu-target.h"
#include <winerror.h>
@@ -56,6 +57,24 @@
#define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073
#define HV_X64_MSR_GUEST_IDLE 0x400000f0
+#define WHPX_MP_STATE_RUNNABLE 0
+#define WHPX_MP_STATE_UNINITIALIZED 1
+#define WHPX_MP_STATE_HALTED 3
+
+static void whpx_set_reg_optional(CPUState *cpu, WHV_REGISTER_NAME reg,
+ WHV_REGISTER_VALUE val)
+{
+ whp_dispatch.WHvSetVirtualProcessorRegisters(
+ whpx_global.partition, cpu->cpu_index, &reg, 1, &val);
+}
+
+static bool whpx_get_reg_optional(CPUState *cpu, WHV_REGISTER_NAME reg,
+ WHV_REGISTER_VALUE *val)
+{
+ return SUCCEEDED(whp_dispatch.WHvGetVirtualProcessorRegisters(
+ whpx_global.partition, cpu->cpu_index, &reg, 1, val));
+}
+
static bool is_modern_os = true;
static bool whpx_msr_exits_available = true;
static bool whpx_forward_startup_ipis;
@@ -636,18 +655,8 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel level)
whpx_set_reg(cpu, WHvX64RegisterCr8, cr8);
}
- /* 8 Debug Registers - Skipped */
-
- /*
- * Extended control registers needs to be handled separately depending
- * on whether xsave is supported/enabled or not.
- */
- whpx_set_xcrs(cpu);
-
- if (whpx_is_xsave_enabled(cpu)) {
- whpx_set_xsave_state(cpu);
- }
- whpx_set_legacy_fp_registers(cpu, level);
+ /* 8 Debug Registers - restored below for FULL_STATE */
+ /* XCR0/XSAVE/FP restored AFTER CR0/CR4/EFER are committed to WHPX */
/* MSRs */
assert(whpx_register_names[idx] == WHvX64RegisterEfer);
@@ -694,10 +703,77 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel level)
hr);
}
+ if (level > WHPX_LEVEL_FAST_RUNTIME_STATE) {
+ whpx_set_xcrs(cpu);
+ if (!whpx_is_xsave_enabled(cpu) || whpx_set_xsave_state(cpu) != 0) {
+ whpx_set_legacy_fp_registers(cpu, level);
+ }
+ }
+
if (level >= WHPX_LEVEL_FULL_STATE) {
- WHV_REGISTER_VALUE apic_base = {};
- apic_base.Reg64 = cpu_get_apic_base(X86_CPU(cpu)->apic_state);
- whpx_set_reg(cpu, WHvX64RegisterApicBase, apic_base);
+ static const WHV_REGISTER_NAME dr_names[6] = {
+ WHvX64RegisterDr0, WHvX64RegisterDr1, WHvX64RegisterDr2,
+ WHvX64RegisterDr3, WHvX64RegisterDr6, WHvX64RegisterDr7,
+ };
+ WHV_REGISTER_VALUE dr_vals[6] = {
+ { .Reg64 = env->dr[0] }, { .Reg64 = env->dr[1] },
+ { .Reg64 = env->dr[2] }, { .Reg64 = env->dr[3] },
+ { .Reg64 = env->dr[6] }, { .Reg64 = env->dr[7] },
+ };
+ whp_dispatch.WHvSetVirtualProcessorRegisters(
+ whpx->partition, cpu->cpu_index, dr_names, 6, dr_vals);
+
+ WHV_REGISTER_VALUE v = {};
+ v.Reg64 = env->tsc_aux;
+ whpx_set_reg_optional(cpu, WHvX64RegisterTscAux, v);
+
+ /* Do not write WHvX64RegisterTscAdjust after WHvX64RegisterTsc,
+ * as MSR_IA32_TSC_ADJUST shifts the vCPU TSC offset in Hyper-V. */
+ if (env->spec_ctrl) {
+ v.Reg64 = env->spec_ctrl;
+ whpx_set_reg_optional(cpu, WHvX64RegisterSpecCtrl, v);
+ }
+ if (env->mtrr_deftype) {
+ v.Reg64 = env->mtrr_deftype;
+ whpx_set_reg_optional(cpu, WHvX64RegisterMsrMtrrDefType, v);
+ for (i = 0; i < MSR_MTRRcap_VCNT; i++) {
+ v.Reg64 = env->mtrr_var[i].base;
+ whpx_set_reg_optional(cpu, WHvX64RegisterMsrMtrrPhysBase0 + i, v);
+ v.Reg64 = env->mtrr_var[i].mask;
+ whpx_set_reg_optional(cpu, WHvX64RegisterMsrMtrrPhysMask0 + i, v);
+ }
+ for (i = 0; i < 11; i++) {
+ v.Reg64 = env->mtrr_fixed[i];
+ whpx_set_reg_optional(cpu, WHvX64RegisterMsrMtrrFix64k00000 + i, v);
+ }
+ }
+
+ if (!whpx_irqchip_in_kernel()) {
+ WHV_REGISTER_VALUE apic_base = {};
+ apic_base.Reg64 = cpu_get_apic_base(X86_CPU(cpu)->apic_state);
+ whpx_set_reg(cpu, WHvX64RegisterApicBase, apic_base);
+ }
+
+ if (!whpx->tsc_deadline_refused) {
+ WHV_REGISTER_VALUE tsc_deadline = { .Reg64 = env->tsc_deadline };
+ whpx_set_reg(cpu, WHvX64RegisterTscDeadline, tsc_deadline);
+ }
+
+ if (whpx_irqchip_in_kernel()) {
+ WHV_REGISTER_VALUE activity = {};
+ whpx_get_reg_optional(cpu, WHvRegisterInternalActivityState, &activity);
+ activity.InternalActivity.StartupSuspend =
+ (env->mp_state == WHPX_MP_STATE_UNINITIALIZED);
+ activity.InternalActivity.HaltSuspend = 0;
+ whpx_set_reg(cpu, WHvRegisterInternalActivityState, activity);
+ }
+
+ {
+ WHV_REGISTER_VALUE intr_state = {};
+ intr_state.InterruptState.InterruptShadow =
+ !!(env->hflags & HF_INHIBIT_IRQ_MASK);
+ whpx_set_reg_optional(cpu, WHvRegisterInterruptState, intr_state);
+ }
}
}
@@ -940,6 +1016,9 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel level)
}
if (!env->tsc_valid) {
+ if (!runstate_is_running() && whp_dispatch.WHvSuspendPartitionTime) {
+ whp_dispatch.WHvSuspendPartitionTime(whpx->partition);
+ }
whpx_get_tsc(cpu);
env->tsc_valid = !runstate_is_running();
}
@@ -1016,10 +1095,9 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel level)
*/
whpx_get_xcrs(cpu);
- if (whpx_is_xsave_enabled(cpu)) {
- whpx_get_xsave_state(cpu);
+ if (!whpx_is_xsave_enabled(cpu) || whpx_get_xsave_state(cpu) != 0) {
+ whpx_get_legacy_fp_registers(cpu, level);
}
- whpx_get_legacy_fp_registers(cpu, level);
/* MSRs */
assert(whpx_register_names[idx] == WHvX64RegisterEfer);
@@ -1051,11 +1129,83 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel level)
assert(idx == RTL_NUMBER_OF(whpx_register_names));
+ if (level >= WHPX_LEVEL_FULL_STATE) {
+ static const WHV_REGISTER_NAME dr_names[6] = {
+ WHvX64RegisterDr0, WHvX64RegisterDr1, WHvX64RegisterDr2,
+ WHvX64RegisterDr3, WHvX64RegisterDr6, WHvX64RegisterDr7,
+ };
+ WHV_REGISTER_VALUE dr_vals[6] = {};
+ if (SUCCEEDED(whp_dispatch.WHvGetVirtualProcessorRegisters(
+ whpx->partition, cpu->cpu_index, dr_names, 6, dr_vals))) {
+ env->dr[0] = dr_vals[0].Reg64;
+ env->dr[1] = dr_vals[1].Reg64;
+ env->dr[2] = dr_vals[2].Reg64;
+ env->dr[3] = dr_vals[3].Reg64;
+ env->dr[6] = dr_vals[4].Reg64;
+ env->dr[7] = dr_vals[5].Reg64;
+ }
+
+ WHV_REGISTER_VALUE v = {};
+ if (whpx_get_reg_optional(cpu, WHvX64RegisterTscAux, &v)) {
+ env->tsc_aux = v.Reg64;
+ }
+ if (whpx_get_reg_optional(cpu, WHvX64RegisterTscAdjust, &v)) {
+ env->tsc_adjust = v.Reg64;
+ }
+ if (whpx_get_reg_optional(cpu, WHvX64RegisterSpecCtrl, &v)) {
+ env->spec_ctrl = v.Reg64;
+ }
+ if (whpx_get_reg_optional(cpu, WHvX64RegisterMsrMtrrDefType, &v)) {
+ env->mtrr_deftype = v.Reg64;
+ for (i = 0; i < MSR_MTRRcap_VCNT; i++) {
+ if (whpx_get_reg_optional(cpu, WHvX64RegisterMsrMtrrPhysBase0 + i, &v)) {
+ env->mtrr_var[i].base = v.Reg64;
+ }
+ if (whpx_get_reg_optional(cpu, WHvX64RegisterMsrMtrrPhysMask0 + i, &v)) {
+ env->mtrr_var[i].mask = v.Reg64;
+ }
+ }
+ for (i = 0; i < 11; i++) {
+ if (whpx_get_reg_optional(cpu, WHvX64RegisterMsrMtrrFix64k00000 + i, &v)) {
+ env->mtrr_fixed[i] = v.Reg64;
+ }
+ }
+ }
+ if (!whpx->tsc_deadline_refused &&
+ whpx_get_reg_optional(cpu, WHvX64RegisterTscDeadline, &v)) {
+ env->tsc_deadline = v.Reg64;
+ }
+ if (whpx_irqchip_in_kernel() &&
+ whpx_get_reg_optional(cpu, WHvRegisterInternalActivityState, &v)) {
+ if (v.InternalActivity.StartupSuspend) {
+ env->mp_state = WHPX_MP_STATE_UNINITIALIZED;
+ } else if (v.InternalActivity.HaltSuspend) {
+ env->mp_state = WHPX_MP_STATE_HALTED;
+ } else {
+ env->mp_state = WHPX_MP_STATE_RUNNABLE;
+ }
+ }
+ if (whpx_get_reg_optional(cpu, WHvRegisterPendingInterruption, &v) &&
+ v.PendingInterruption.InterruptionPending) {
+ warn_report("WHPX: vCPU %d saved with PendingInterruption type=%u vec=%u",
+ cpu->cpu_index,
+ (unsigned)v.PendingInterruption.InterruptionType,
+ (unsigned)v.PendingInterruption.InterruptionVector);
+ }
+ }
+
if (whpx_irqchip_in_kernel()) {
whpx_apic_get(x86_cpu->apic_state);
}
x86_update_hflags(env);
+ if (level >= WHPX_LEVEL_FULL_STATE) {
+ WHV_REGISTER_VALUE intr_state = {};
+ if (whpx_get_reg_optional(cpu, WHvRegisterInterruptState, &intr_state) &&
+ intr_state.InterruptState.InterruptShadow) {
+ env->hflags |= HF_INHIBIT_IRQ_MASK;
+ }
+ }
}
static int emulate_instruction(CPUState *cpu, const uint8_t *insn_bytes, size_t insn_len)
@@ -2515,8 +2665,12 @@ int whpx_vcpu_run(CPUState *cpu)
do {
if (cpu->vcpu_dirty) {
- whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE);
+ WHPXStateLevel level = vcpu->loadvm_pending
+ ? WHPX_LEVEL_FULL_STATE
+ : WHPX_LEVEL_RUNTIME_STATE;
+ whpx_set_registers(cpu, level);
cpu->vcpu_dirty = false;
+ vcpu->loadvm_pending = false;
}
if (exclusive_step_mode == WHPX_STEP_NONE) {
@@ -2982,6 +3136,28 @@ int whpx_vcpu_run(CPUState *cpu)
*/
static Error *whpx_migration_blocker;
+static NotifierWithReturn whpx_migration_notifier;
+static bool whpx_migration_notifier_added;
+
+static int whpx_migration_setup_notifier(NotifierWithReturn *notify,
+ MigrationEvent *e, Error **errp)
+{
+ if (e->type != MIG_EVENT_SETUP) {
+ return 0;
+ }
+ if (runstate_is_running()) {
+ error_setg(errp,
+ "WHPX: live migration is not supported while the VM is running; stop the VM first");
+ return -1;
+ }
+ if (migrate_mode() != MIG_MODE_NORMAL ||
+ migrate_postcopy_ram() || migrate_background_snapshot()) {
+ error_setg(errp,
+ "WHPX: only stopped-VM normal file suspend is supported");
+ return -1;
+ }
+ return 0;
+}
static void whpx_cpu_update_state(void *opaque, bool running, RunState state)
{
@@ -3006,20 +3182,27 @@ int whpx_init_vcpu(CPUState *cpu)
UINT64 freq = 0;
int ret;
- /* Add migration blockers for all unsupported features of the
- * Windows Hypervisor Platform
+ /*
+ * WHPX lacks dirty-page tracking, so live migration and non-normal modes
+ * remain blocked. Only stopped-VM normal file suspend (stop -> migrate ->
+ * quit) is permitted and enforced both at migration entry and on setup.
*/
- if (whpx_migration_blocker == NULL) {
+ if (!whpx_migration_blocker) {
+ unsigned non_normal_modes = (BIT(MIG_MODE__MAX) - 1) &
+ ~BIT(MIG_MODE_NORMAL);
error_setg(&whpx_migration_blocker,
- "State blocked due to missing dirty memory tracking support,"
- "And some system register/state save-restore ");
-
- if (migrate_add_blocker(&whpx_migration_blocker, &local_error) < 0) {
- error_report_err(local_error);
- ret = -EINVAL;
- goto error;
+ "WHPX: migration mode is not supported (only stopped-VM normal file suspend)");
+ migrate_add_blocker_modes(&whpx_migration_blocker, non_normal_modes,
+ &local_error);
+ if (local_error) {
+ error_propagate(&error_fatal, local_error);
}
}
+ if (!whpx_migration_notifier_added) {
+ migration_add_notifier(&whpx_migration_notifier,
+ whpx_migration_setup_notifier);
+ whpx_migration_notifier_added = true;
+ }
vcpu = g_new0(AccelCPUState, 1);
diff --git a/target/i386/whpx/whpx-apic.c b/target/i386/whpx/whpx-apic.c
index 547b1cd2671bb6b8fb5a826ab5af5ef89b0997be..75ecf48feb48b448cb39d5878d9bb86b0fa5746a 100644
--- a/target/i386/whpx/whpx-apic.c
+++ b/target/i386/whpx/whpx-apic.c
@@ -35,13 +35,17 @@ static void whpx_put_apic_state(APICCommonState *s,
memset(kapic, 0, sizeof(*kapic));
if (s->apicbase & MSR_IA32_APICBASE_EXTD) {
kapic->fields[0x2].data = s->initial_apic_id;
+ kapic->fields[0xd].data =
+ ((s->initial_apic_id & ~0xfu) << 12) |
+ (1u << (s->initial_apic_id & 0xfu));
+ kapic->fields[0xe].data = 0;
} else {
kapic->fields[0x2].data = s->id << 24;
+ kapic->fields[0xd].data = s->log_dest << 24;
+ kapic->fields[0xe].data = s->dest_mode << 28 | 0x0fffffff;
}
kapic->fields[0x3].data = s->version | ((APIC_LVT_NB - 1) << 16);
kapic->fields[0x8].data = s->tpr;
- kapic->fields[0xd].data = s->log_dest << 24;
- kapic->fields[0xe].data = s->dest_mode << 28 | 0x0fffffff;
kapic->fields[0xf].data = s->spurious_vec;
for (i = 0; i < 8; i++) {
kapic->fields[0x10 + i].data = s->isr[i];
@@ -212,10 +216,18 @@ static void whpx_apic_put(CPUState *cs, run_on_cpu_data data)
&kapic,
sizeof(kapic));
if (FAILED(hr)) {
+ struct whpx_lapic_state cur = {};
+ whp_dispatch.WHvGetVirtualProcessorInterruptControllerState2(
+ whpx_global.partition, cs->cpu_index, &cur, sizeof(cur), NULL);
fprintf(stderr,
- "WHvSetVirtualProcessorInterruptControllerState failed: %08lx\n",
- hr);
-
+ "WHvSetVirtualProcessorInterruptControllerState2 failed: %08lx cpu=%d apicbase=0x%llx\n",
+ hr, cs->cpu_index, (unsigned long long)s->apicbase);
+ for (int idx = 0; idx < 256; idx++) {
+ if (kapic.fields[idx].data || cur.fields[idx].data) {
+ fprintf(stderr, " lapic[0x%02x]: put=0x%08x cur=0x%08x\n",
+ idx, kapic.fields[idx].data, cur.fields[idx].data);
+ }
+ }
abort();
}
}
@@ -224,8 +236,17 @@ void whpx_apic_get(APICCommonState *s)
{
CPUState *cpu = CPU(s->cpu);
struct whpx_lapic_state kapic;
+ WHV_REGISTER_NAME base_reg = WHvX64RegisterApicBase;
+ WHV_REGISTER_VALUE base_val = {};
+ HRESULT hr;
+
+ hr = whp_dispatch.WHvGetVirtualProcessorRegisters(
+ whpx_global.partition, cpu->cpu_index, &base_reg, 1, &base_val);
+ if (SUCCEEDED(hr)) {
+ s->apicbase = base_val.Reg64;
+ }
- HRESULT hr = whp_dispatch.WHvGetVirtualProcessorInterruptControllerState2(
+ hr = whp_dispatch.WHvGetVirtualProcessorInterruptControllerState2(
whpx_global.partition,
cpu->cpu_index,
&kapic,
@@ -233,7 +254,7 @@ void whpx_apic_get(APICCommonState *s)
NULL);
if (FAILED(hr)) {
fprintf(stderr,
- "WHvSetVirtualProcessorInterruptControllerState failed: %08lx\n",
+ "WHvGetVirtualProcessorInterruptControllerState2 failed: %08lx\n",
hr);
abort();
@@ -242,6 +263,17 @@ void whpx_apic_get(APICCommonState *s)
whpx_get_apic_state(s, &kapic);
}
+static void do_whpx_apic_get(CPUState *cs, run_on_cpu_data data)
+{
+ APICCommonState *s = data.host_ptr;
+ whpx_apic_get(s);
+}
+
+static void whpx_apic_pre_save(APICCommonState *s)
+{
+ run_on_cpu(CPU(s->cpu), do_whpx_apic_get, RUN_ON_CPU_HOST_PTR(s));
+}
+
static void whpx_apic_post_load(APICCommonState *s)
{
run_on_cpu(CPU(s->cpu), whpx_apic_put, RUN_ON_CPU_HOST_PTR(s));
@@ -379,6 +411,7 @@ static void whpx_apic_class_init(ObjectClass *klass, const void *data)
k->set_base = apic_set_base;
k->set_tpr = whpx_apic_set_tpr;
k->get_tpr = whpx_apic_get_tpr;
+ k->pre_save = whpx_apic_pre_save;
k->post_load = whpx_apic_post_load;
k->vapic_base_update = whpx_apic_vapic_base_update;
k->external_nmi = whpx_apic_external_nmi;
+727
View File
@@ -0,0 +1,727 @@
diff --git a/include/io/channel.h b/include/io/channel.h
index 834ba7c30986dd48686705da5aa7197eb228cef7..87f751308d6fdd7b87e31be44fca07fe93501aba 100644
--- a/include/io/channel.h
+++ b/include/io/channel.h
@@ -146,12 +146,12 @@ struct QIOChannelClass {
ssize_t (*io_pwritev)(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp);
ssize_t (*io_preadv)(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp);
int (*io_shutdown)(QIOChannel *ioc,
QIOChannelShutdown how,
@@ -160,8 +160,8 @@ struct QIOChannelClass {
bool enabled);
void (*io_set_delay)(QIOChannel *ioc,
bool enabled);
- off_t (*io_seek)(QIOChannel *ioc,
- off_t offset,
+ int64_t (*io_seek)(QIOChannel *ioc,
+ int64_t offset,
int whence,
Error **errp);
void (*io_set_aio_fd_handler)(QIOChannel *ioc,
@@ -579,7 +579,7 @@ int qio_channel_close(QIOChannel *ioc,
*
*/
ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov,
- size_t niov, off_t offset, Error **errp);
+ size_t niov, int64_t offset, Error **errp);
/**
* qio_channel_pwrite
@@ -595,7 +595,7 @@ ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov,
*
*/
ssize_t qio_channel_pwrite(QIOChannel *ioc, void *buf, size_t buflen,
- off_t offset, Error **errp);
+ int64_t offset, Error **errp);
/**
* qio_channel_pwritev_all:
@@ -614,7 +614,7 @@ ssize_t qio_channel_pwrite(QIOChannel *ioc, void *buf, size_t buflen,
int coroutine_mixed_fn qio_channel_pwritev_all(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp);
/**
@@ -635,7 +635,7 @@ int coroutine_mixed_fn qio_channel_pwritev_all(QIOChannel *ioc,
int coroutine_mixed_fn qio_channel_pwrite_all(QIOChannel *ioc,
const void *buf,
size_t buflen,
- off_t offset,
+ int64_t offset,
Error **errp);
/**
@@ -656,7 +656,7 @@ int coroutine_mixed_fn qio_channel_pwrite_all(QIOChannel *ioc,
*
*/
ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov,
- size_t niov, off_t offset, Error **errp);
+ size_t niov, int64_t offset, Error **errp);
/**
* qio_channel_pread
@@ -672,7 +672,7 @@ ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov,
*
*/
ssize_t qio_channel_pread(QIOChannel *ioc, void *buf, size_t buflen,
- off_t offset, Error **errp);
+ int64_t offset, Error **errp);
/**
* qio_channel_preadv_all_eof:
@@ -695,7 +695,7 @@ ssize_t qio_channel_pread(QIOChannel *ioc, void *buf, size_t buflen,
int coroutine_mixed_fn qio_channel_preadv_all_eof(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp);
/**
@@ -717,7 +717,7 @@ int coroutine_mixed_fn qio_channel_preadv_all_eof(QIOChannel *ioc,
int coroutine_mixed_fn qio_channel_preadv_all(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp);
/**
@@ -741,7 +741,7 @@ int coroutine_mixed_fn qio_channel_preadv_all(QIOChannel *ioc,
int coroutine_mixed_fn qio_channel_pread_all_eof(QIOChannel *ioc,
void *buf,
size_t buflen,
- off_t offset,
+ int64_t offset,
Error **errp);
/**
@@ -763,7 +763,7 @@ int coroutine_mixed_fn qio_channel_pread_all_eof(QIOChannel *ioc,
int coroutine_mixed_fn qio_channel_pread_all(QIOChannel *ioc,
void *buf,
size_t buflen,
- off_t offset,
+ int64_t offset,
Error **errp);
/**
@@ -861,10 +861,10 @@ void qio_channel_set_cork(QIOChannel *ioc,
* Not all implementations will support this facility,
* so may report an error.
*
- * Returns: the new position on success, (off_t)-1 on failure
+ * Returns: the new position on success, (int64_t)-1 on failure
*/
-off_t qio_channel_io_seek(QIOChannel *ioc,
- off_t offset,
+int64_t qio_channel_io_seek(QIOChannel *ioc,
+ int64_t offset,
int whence,
Error **errp);
diff --git a/include/system/ramblock.h b/include/system/ramblock.h
index 24c970d393e9cc3463fa46a9bcace7937e50fde4..981470f59d569181f859718942ecb9a855f33078 100644
--- a/include/system/ramblock.h
+++ b/include/system/ramblock.h
@@ -68,7 +68,7 @@ struct RAMBlock {
* offset in the file pages belonging to this ramblock are saved,
* used only during migration to a file.
*/
- off_t bitmap_offset;
+ int64_t bitmap_offset;
uint64_t pages_offset;
/* Bitmap of already received pages. Only used on destination side. */
diff --git a/io/channel-buffer.c b/io/channel-buffer.c
index 189fa67ac21df8a8dff868a477a8021873bd22c7..873e80faeb8a8496ddb6fb0743a17ad599a60654 100644
--- a/io/channel-buffer.c
+++ b/io/channel-buffer.c
@@ -124,8 +124,8 @@ static int qio_channel_buffer_set_blocking(QIOChannel *ioc G_GNUC_UNUSED,
}
-static off_t qio_channel_buffer_seek(QIOChannel *ioc,
- off_t offset,
+static int64_t qio_channel_buffer_seek(QIOChannel *ioc,
+ int64_t offset,
int whence,
Error **errp)
{
diff --git a/io/channel-file.c b/io/channel-file.c
index 2487adaea2ad7108310b94910153a4ffbf6eb094..2fb80f90e1c6251c1b2b493e8ebb6566b6b0b769 100644
--- a/io/channel-file.c
+++ b/io/channel-file.c
@@ -27,6 +27,9 @@
#include "qemu/module.h"
#include "qemu/sockets.h"
#include "trace.h"
+#ifdef WIN32
+#include <winioctl.h>
+#endif
QIOChannelFile *
qio_channel_file_new_fd(int fd)
@@ -42,7 +45,7 @@ qio_channel_file_new_fd(int fd)
ioc->fd = fd;
- if (lseek(fd, 0, SEEK_CUR) != (off_t)-1) {
+ if (lseek(fd, 0, SEEK_CUR) != (int64_t)-1) {
qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SEEKABLE);
}
@@ -74,6 +77,9 @@ qio_channel_file_new_path(const char *path,
ioc = QIO_CHANNEL_FILE(object_new(TYPE_QIO_CHANNEL_FILE));
+#ifdef O_BINARY
+ flags |= O_BINARY;
+#endif
if (flags & O_CREAT) {
ioc->fd = qemu_create(path, flags & ~O_CREAT, mode, errp);
} else {
@@ -84,9 +90,18 @@ qio_channel_file_new_path(const char *path,
return NULL;
}
- if (lseek(ioc->fd, 0, SEEK_CUR) != (off_t)-1) {
+ if (lseek(ioc->fd, 0, SEEK_CUR) != (int64_t)-1) {
qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SEEKABLE);
}
+#ifdef WIN32
+ if (flags & O_CREAT) {
+ HANDLE h = (HANDLE)_get_osfhandle(ioc->fd);
+ if (h != INVALID_HANDLE_VALUE && GetFileType(h) == FILE_TYPE_DISK) {
+ DWORD br = 0;
+ DeviceIoControl(h, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &br, NULL);
+ }
+ }
+#endif
trace_qio_channel_file_new_path(ioc, path, flags, mode, ioc->fd);
@@ -170,7 +185,7 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc,
static ssize_t qio_channel_file_preadv(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp)
{
QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
@@ -196,7 +211,7 @@ static ssize_t qio_channel_file_preadv(QIOChannel *ioc,
static ssize_t qio_channel_file_pwritev(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp)
{
QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
@@ -216,6 +231,125 @@ static ssize_t qio_channel_file_pwritev(QIOChannel *ioc,
}
return ret;
}
+#elif defined(WIN32)
+static ssize_t qio_channel_file_prw_win32(QIOChannel *ioc,
+ const struct iovec *iov,
+ size_t niov,
+ int64_t offset,
+ bool is_write,
+ Error **errp)
+{
+ static const size_t max_chunk = 16U * 1024U * 1024U;
+ QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
+ HANDLE h = (HANDLE)_get_osfhandle(fioc->fd);
+ LARGE_INTEGER zero = { .QuadPart = 0 };
+ LARGE_INTEGER saved = { .QuadPart = 0 };
+ bool have_saved = false;
+ uint64_t cur;
+ ssize_t total = 0;
+ ssize_t ret = -1;
+ size_t i = 0;
+
+ if (offset < 0) {
+ error_setg_errno(errp, EINVAL, "Invalid negative offset for %s",
+ is_write ? "pwritev" : "preadv");
+ return -1;
+ }
+ if (h == INVALID_HANDLE_VALUE) {
+ error_setg_errno(errp, EBADF, "Invalid file handle for %s",
+ is_write ? "pwritev" : "preadv");
+ return -1;
+ }
+
+ cur = (uint64_t)offset;
+ have_saved = SetFilePointerEx(h, zero, &saved, FILE_CURRENT);
+
+ while (i < niov) {
+ uint8_t *base = (uint8_t *)iov[i].iov_base;
+ size_t run = iov[i].iov_len;
+ size_t j = i + 1;
+
+ while (j < niov && (uint8_t *)iov[j].iov_base == base + run &&
+ run < max_chunk && iov[j].iov_len <= max_chunk - run) {
+ run += iov[j].iov_len;
+ j++;
+ }
+ if (run == 0) {
+ i = j;
+ continue;
+ }
+
+ size_t done = 0;
+ while (done < run) {
+ DWORD chunk = (DWORD)MIN(run - done, max_chunk);
+ DWORD xfer = 0;
+ OVERLAPPED ov;
+ BOOL ok;
+
+ memset(&ov, 0, sizeof(ov));
+ ov.Offset = (DWORD)(cur & 0xFFFFFFFFULL);
+ ov.OffsetHigh = (DWORD)(cur >> 32);
+ if (is_write) {
+ ok = WriteFile(h, base + done, chunk, &xfer, &ov);
+ } else {
+ ok = ReadFile(h, base + done, chunk, &xfer, &ov);
+ }
+ if (!ok) {
+ DWORD err = GetLastError();
+ if (!is_write && err == ERROR_HANDLE_EOF) {
+ ret = total;
+ goto out;
+ }
+ error_setg_win32(errp, err,
+ is_write ? "Unable to pwritev to file"
+ : "Unable to preadv from file");
+ goto out;
+ }
+ if (xfer == 0) {
+ if (!is_write || total > 0) {
+ ret = total;
+ goto out;
+ }
+ error_setg_errno(errp, EIO, "pwritev made no progress");
+ goto out;
+ }
+ done += xfer;
+ cur += xfer;
+ total += xfer;
+ if (is_write && xfer < chunk) {
+ /* Preserve short-write semantics for caller retry/error handling. */
+ ret = total;
+ goto out;
+ }
+ }
+ i = j;
+ }
+
+ ret = total;
+out:
+ if (have_saved) {
+ SetFilePointerEx(h, saved, NULL, FILE_BEGIN);
+ }
+ return ret;
+}
+
+static ssize_t qio_channel_file_preadv(QIOChannel *ioc,
+ const struct iovec *iov,
+ size_t niov,
+ int64_t offset,
+ Error **errp)
+{
+ return qio_channel_file_prw_win32(ioc, iov, niov, offset, false, errp);
+}
+
+static ssize_t qio_channel_file_pwritev(QIOChannel *ioc,
+ const struct iovec *iov,
+ size_t niov,
+ int64_t offset,
+ Error **errp)
+{
+ return qio_channel_file_prw_win32(ioc, iov, niov, offset, true, errp);
+}
#endif /* CONFIG_PREADV */
static int qio_channel_file_set_blocking(QIOChannel *ioc,
@@ -223,7 +357,11 @@ static int qio_channel_file_set_blocking(QIOChannel *ioc,
Error **errp)
{
#ifdef WIN32
- /* not implemented */
+ QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
+ if (enabled ||
+ GetFileType((HANDLE)_get_osfhandle(fioc->fd)) == FILE_TYPE_DISK) {
+ return 0;
+ }
error_setg_errno(errp, errno, "Failed to set FD nonblocking");
return -1;
#else
@@ -237,16 +375,20 @@ static int qio_channel_file_set_blocking(QIOChannel *ioc,
}
-static off_t qio_channel_file_seek(QIOChannel *ioc,
- off_t offset,
+static int64_t qio_channel_file_seek(QIOChannel *ioc,
+ int64_t offset,
int whence,
Error **errp)
{
QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
- off_t ret;
+ int64_t ret;
+#ifdef WIN32
+ ret = (int64_t)_lseeki64(fioc->fd, (int64_t)offset, whence);
+#else
ret = lseek(fioc->fd, offset, whence);
- if (ret == (off_t)-1) {
+#endif
+ if (ret == (int64_t)-1) {
error_setg_errno(errp, errno,
"Unable to seek to offset %lld whence %d in file",
(long long int)offset, whence);
@@ -314,7 +456,7 @@ static void qio_channel_file_class_init(ObjectClass *klass,
ioc_klass->io_writev = qio_channel_file_writev;
ioc_klass->io_readv = qio_channel_file_readv;
ioc_klass->io_set_blocking = qio_channel_file_set_blocking;
-#ifdef CONFIG_PREADV
+#if defined(CONFIG_PREADV) || defined(WIN32)
ioc_klass->io_pwritev = qio_channel_file_pwritev;
ioc_klass->io_preadv = qio_channel_file_preadv;
#endif
diff --git a/io/channel-null.c b/io/channel-null.c
index 49f1c80a54e1337aa39010ef39a5ea5de4c5392f..2032d26b3c14a28fc36aedc8a3f0248a4701abb9 100644
--- a/io/channel-null.c
+++ b/io/channel-null.c
@@ -105,9 +105,9 @@ qio_channel_null_set_blocking(QIOChannel *ioc G_GNUC_UNUSED,
}
-static off_t
+static int64_t
qio_channel_null_seek(QIOChannel *ioc G_GNUC_UNUSED,
- off_t offset G_GNUC_UNUSED,
+ int64_t offset G_GNUC_UNUSED,
int whence G_GNUC_UNUSED,
Error **errp G_GNUC_UNUSED)
{
diff --git a/io/channel.c b/io/channel.c
index 620256f310dbeb060113e71055246ca29431d13d..03d721ec0d699d7c9bcbf2866881d53d7e6b25c0 100644
--- a/io/channel.c
+++ b/io/channel.c
@@ -450,7 +450,7 @@ GSource *qio_channel_add_watch_source(QIOChannel *ioc,
ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov,
- size_t niov, off_t offset, Error **errp)
+ size_t niov, int64_t offset, Error **errp)
{
QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
@@ -468,7 +468,7 @@ ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov,
}
ssize_t qio_channel_pwrite(QIOChannel *ioc, void *buf, size_t buflen,
- off_t offset, Error **errp)
+ int64_t offset, Error **errp)
{
struct iovec iov = {
.iov_base = buf,
@@ -481,7 +481,7 @@ ssize_t qio_channel_pwrite(QIOChannel *ioc, void *buf, size_t buflen,
int coroutine_mixed_fn qio_channel_pwritev_all(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp)
{
int ret = -1;
@@ -519,7 +519,7 @@ int coroutine_mixed_fn qio_channel_pwritev_all(QIOChannel *ioc,
int coroutine_mixed_fn qio_channel_pwrite_all(QIOChannel *ioc,
const void *buf,
size_t buflen,
- off_t offset,
+ int64_t offset,
Error **errp)
{
struct iovec iov = { .iov_base = (char *)buf, .iov_len = buflen };
@@ -527,7 +527,7 @@ int coroutine_mixed_fn qio_channel_pwrite_all(QIOChannel *ioc,
}
ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov,
- size_t niov, off_t offset, Error **errp)
+ size_t niov, int64_t offset, Error **errp)
{
QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
@@ -545,7 +545,7 @@ ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov,
}
ssize_t qio_channel_pread(QIOChannel *ioc, void *buf, size_t buflen,
- off_t offset, Error **errp)
+ int64_t offset, Error **errp)
{
struct iovec iov = {
.iov_base = buf,
@@ -558,7 +558,7 @@ ssize_t qio_channel_pread(QIOChannel *ioc, void *buf, size_t buflen,
int coroutine_mixed_fn qio_channel_preadv_all_eof(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp)
{
int ret = -1;
@@ -609,7 +609,7 @@ int coroutine_mixed_fn qio_channel_preadv_all_eof(QIOChannel *ioc,
int coroutine_mixed_fn qio_channel_preadv_all(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp)
{
int ret = qio_channel_preadv_all_eof(ioc, iov, niov, offset, errp);
@@ -629,7 +629,7 @@ int coroutine_mixed_fn qio_channel_preadv_all(QIOChannel *ioc,
int coroutine_mixed_fn qio_channel_pread_all_eof(QIOChannel *ioc,
void *buf,
size_t buflen,
- off_t offset,
+ int64_t offset,
Error **errp)
{
struct iovec iov = { .iov_base = buf, .iov_len = buflen };
@@ -639,7 +639,7 @@ int coroutine_mixed_fn qio_channel_pread_all_eof(QIOChannel *ioc,
int coroutine_mixed_fn qio_channel_pread_all(QIOChannel *ioc,
void *buf,
size_t buflen,
- off_t offset,
+ int64_t offset,
Error **errp)
{
struct iovec iov = { .iov_base = buf, .iov_len = buflen };
@@ -696,8 +696,8 @@ int qio_channel_get_peerpid(QIOChannel *ioc,
return 0;
}
-off_t qio_channel_io_seek(QIOChannel *ioc,
- off_t offset,
+int64_t qio_channel_io_seek(QIOChannel *ioc,
+ int64_t offset,
int whence,
Error **errp)
{
diff --git a/migration/channel-block.c b/migration/channel-block.c
index 9cf383d4b57728b2561dbb45afd44c72df15061b..8a0893fb7e4d4cb9e5e91d1418e99674f4562c23 100644
--- a/migration/channel-block.c
+++ b/migration/channel-block.c
@@ -101,7 +101,7 @@ static ssize_t
qio_channel_block_preadv(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp)
{
QIOChannelBlock *bioc = QIO_CHANNEL_BLOCK(ioc);
@@ -122,7 +122,7 @@ static ssize_t
qio_channel_block_pwritev(QIOChannel *ioc,
const struct iovec *iov,
size_t niov,
- off_t offset,
+ int64_t offset,
Error **errp)
{
QIOChannelBlock *bioc = QIO_CHANNEL_BLOCK(ioc);
@@ -152,9 +152,9 @@ qio_channel_block_set_blocking(QIOChannel *ioc,
}
-static off_t
+static int64_t
qio_channel_block_seek(QIOChannel *ioc,
- off_t offset,
+ int64_t offset,
int whence,
Error **errp)
{
@@ -169,7 +169,7 @@ qio_channel_block_seek(QIOChannel *ioc,
break;
case SEEK_END:
error_setg(errp, "Size of VMstate region is unknown");
- return (off_t)-1;
+ return (int64_t)-1;
default:
g_assert_not_reached();
}
diff --git a/migration/channel-block.h b/migration/channel-block.h
index 31673824e6971398b73f55cfb36a521ca0d91791..b2f6768f6ce5a058dc0a082ccd4d0d9297befd3f 100644
--- a/migration/channel-block.h
+++ b/migration/channel-block.h
@@ -39,7 +39,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(QIOChannelBlock, QIO_CHANNEL_BLOCK)
struct QIOChannelBlock {
QIOChannel parent;
BlockDriverState *bs;
- off_t offset;
+ int64_t offset;
};
diff --git a/migration/file.c b/migration/file.c
index 8ba1de2006eed5a643b7394b9bc4c83cb8d9b4af..5419455d6d314e7529c20116b274d61ce1e38e99 100644
--- a/migration/file.c
+++ b/migration/file.c
@@ -108,7 +108,11 @@ QIOChannel *file_connect_outgoing(MigrationState *s,
goto out;
}
+#ifdef WIN32
+ if (_chsize_s(fioc->fd, (int64_t)offset) != 0) {
+#else
if (ftruncate(fioc->fd, offset)) {
+#endif
error_setg_errno(errp, errno,
"failed to truncate migration file to offset %" PRIx64,
offset);
diff --git a/migration/multifd.h b/migration/multifd.h
index fbc35702b062fdc3213ce92baed35994f5967c2b..2ce94f07403fe1cbe1655728e13c58eeb53dbbe5 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -133,7 +133,7 @@ struct MultiFDRecvData {
void *opaque;
size_t size;
/* for preadv */
- off_t file_offset;
+ int64_t file_offset;
};
typedef struct {
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index df3f96fb24005d0fcf397bf8035b460a04eb2490..4aef4856599e83c6bb72012dbea3f163ab838add 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -532,7 +532,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size)
}
void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
- off_t pos)
+ int64_t pos)
{
Error *err = NULL;
@@ -550,7 +550,7 @@ void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
}
-size_t qemu_get_buffer_at(QEMUFile *f, uint8_t *buf, size_t buflen, off_t pos,
+size_t qemu_get_buffer_at(QEMUFile *f, uint8_t *buf, size_t buflen, int64_t pos,
Error **errp)
{
if (f->last_error) {
@@ -566,10 +566,10 @@ size_t qemu_get_buffer_at(QEMUFile *f, uint8_t *buf, size_t buflen, off_t pos,
return buflen;
}
-void qemu_set_offset(QEMUFile *f, off_t off, int whence)
+void qemu_set_offset(QEMUFile *f, int64_t off, int whence)
{
Error *err = NULL;
- off_t ret;
+ int64_t ret;
if (qemu_file_is_writable(f)) {
qemu_fflush(f);
@@ -580,20 +580,20 @@ void qemu_set_offset(QEMUFile *f, off_t off, int whence)
}
ret = qio_channel_io_seek(f->ioc, off, whence, &err);
- if (ret == (off_t)-1) {
+ if (ret == (int64_t)-1) {
qemu_file_set_error_obj(f, -EIO, err);
}
}
-off_t qemu_get_offset(QEMUFile *f)
+int64_t qemu_get_offset(QEMUFile *f)
{
Error *err = NULL;
- off_t ret;
+ int64_t ret;
qemu_fflush(f);
ret = qio_channel_io_seek(f->ioc, 0, SEEK_CUR, &err);
- if (ret == (off_t)-1) {
+ if (ret == (int64_t)-1) {
qemu_file_set_error_obj(f, -EIO, err);
}
return ret;
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index 966766788ddfb11e08eb8b059d43c69a66260818..c5d2a984611da615e8561866af954f6e778780bf 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -72,11 +72,11 @@ QEMUFile *qemu_file_get_return_path(QEMUFile *f);
int qemu_fflush(QEMUFile *f);
bool qemu_file_set_blocking(QEMUFile *f, bool block, Error **errp);
int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
-void qemu_set_offset(QEMUFile *f, off_t off, int whence);
-off_t qemu_get_offset(QEMUFile *f);
+void qemu_set_offset(QEMUFile *f, int64_t off, int whence);
+int64_t qemu_get_offset(QEMUFile *f);
void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
- off_t pos);
-size_t qemu_get_buffer_at(QEMUFile *f, uint8_t *buf, size_t buflen, off_t pos,
+ int64_t pos);
+size_t qemu_get_buffer_at(QEMUFile *f, uint8_t *buf, size_t buflen, int64_t pos,
Error **errp);
QIOChannel *qemu_file_get_ioc(QEMUFile *file);
diff --git a/migration/ram.c b/migration/ram.c
index e6db3bf523855ee1ea20e79495326979f00d3192..410cfa6a1c2bfe84308d19c36bd8a00157226581 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1010,7 +1010,7 @@ static uint64_t physical_memory_sync_dirty_bitmap(RAMBlock *rb,
unsigned long *dest = rb->bmap;
/* start address and length is aligned at the start of a word? */
- if (((word * BITS_PER_LONG) << TARGET_PAGE_BITS) ==
+ if ((((ram_addr_t)word * BITS_PER_LONG) << TARGET_PAGE_BITS) ==
(start + rb->offset) &&
!(length & ((BITS_PER_LONG << TARGET_PAGE_BITS) - 1))) {
int k;
@@ -4137,8 +4137,8 @@ static bool handle_zero_mapped_ram(RAMBlock *block, unsigned long from_bit_idx,
return true;
}
- size = TARGET_PAGE_SIZE * (to_bit_idx - from_bit_idx);
- offset = from_bit_idx << TARGET_PAGE_BITS;
+ size = (size_t)TARGET_PAGE_SIZE * (to_bit_idx - from_bit_idx);
+ offset = ((ram_addr_t)from_bit_idx) << TARGET_PAGE_BITS;
host = host_from_ram_block_offset(block, offset);
if (!host) {
error_setg(errp, "zero page outside of ramblock %s range",
@@ -4172,8 +4172,8 @@ static bool read_ramblock_mapped_ram(QEMUFile *f, RAMBlock *block,
/* Non-zero pages */
clear_bit_idx = find_next_zero_bit(bitmap, num_pages, set_bit_idx + 1);
- unread = TARGET_PAGE_SIZE * (clear_bit_idx - set_bit_idx);
- offset = set_bit_idx << TARGET_PAGE_BITS;
+ unread = (size_t)TARGET_PAGE_SIZE * (clear_bit_idx - set_bit_idx);
+ offset = ((ram_addr_t)set_bit_idx) << TARGET_PAGE_BITS;
while (unread > 0) {
host = host_from_ram_block_offset(block, offset);
+2
View File
@@ -14,3 +14,5 @@ vendor/qemu qemu-whpx-win10-compat.patch
vendor/qemu qemu-whpx-win10-startup-ipis.patch
vendor/qemu qemu-whpx-nested-virt-nonfatal.patch
vendor/qemu qemu-win32-coroutine-fiber-commit.patch
vendor/qemu qemu-win32-mapped-ram-io.patch
vendor/qemu qemu-intel-whpx-suspend.patch