qemu/kvm-Add-support-for-CSV2-reboot.patch

172 lines
5.7 KiB
Diff
Raw Permalink Normal View History

QEMU update to version 8.2.0-18: - hw/loongarch/virt: Fix FDT memory node address width - hw/loongarch: Fix fdt memory node wrong 'reg' - load_elf: fix iterator's type for elf file processing - migration/colo: Fix bdrv_graph_rdlock_main_loop: Assertion `!qemu_in_… - target/i386: no single-step exception after MOV or POP SS - char-stdio: Restore blocking mode of stdout on exit - backends/cryptodev-builtin: Fix local_error leaks - target/loongarch: fix a wrong print in cpu dump - virtio-pci: fix use of a released vector - target/arm: Disable SVE extensions when SVE is disabled - hw/misc/bcm2835_property: Fix handling of FRAMEBUFFER_SET_PALETTE - target/i386: Introduce SapphireRapids-v3 to add missing features - virtio-net: Ensure queue index fits with RSS (CVE-2024-6505) - nbd/server: CVE-2024-7409: Avoid use-after-free when closing server - update io/trace-events. Parameters should remain consistent. - update docs/tools/virtfs-proxy-helper.rst. This place is spelled wrong. - kvm: Add support for CSV2 reboot - target/i386/kvm: Fix the resettable info when emulate Hygon CSV2 guest - target/i386: get/set/migrate GHCB state - target/i386: csv: Add support for migrate VMSA for CSV2 guest - migration/ram: Accelerate the loading of CSV guest's encrypted pages - migration/ram: Accelerate the transmission of CSV guest's encrypted pages - target/i386: csv: add support to load incoming encrypted pages queued in the CMD list - target/i386: csv: add support to queue the incoming page into a list - target/i386: csv: add support to encrypt the outgoing pages in the list queued before. - target/i386: csv: add support to queue the outgoing page into a list - target/i386: csv: Read cert chain from file when prepared for CSV live migration - target/i386: Introduce header file csv.h - migration/ram: Fix calculation of gfn correpond to a page in ramblock - target/i386: sev: Clear shared_regions_list when reboot CSV Guest - migration/ram: Force encrypted status for VGA vram - target/i386: sev: Return 0 if sev_send_get_packet_len() fails - kvm: Add support for userspace MSR filtering and handling of MSR_KVM_MIGRATION_CONTROL. - migration/ram: Force encrypted status for flash0 & flash1 devices. - migration/ram: add support to send encrypted pages - migration: add support to migrate shared regions list - kvm: Add support for SEV shared regions list and KVM_EXIT_HYPERCALL. - target/i386: sev: add support to load incoming encrypted page - target/i386: sev: add support to encrypt the outgoing page - target/i386: sev: do not create launch context for an incoming guest - target/i386: sev: provide callback to setup outgoing context - confidential guest support: introduce ConfidentialGuestMemoryEncryptionOps for encrypted VMs - migration.json: add AMD SEV specific migration parameters - doc: update AMD SEV to include Live migration flow - crypto/tlscredspsk: Free username on finalize - hw/nvme: fix leak of uninitialized memory in io_mgmt_recv - hw/display/vhost-user-gpu.c: fix vhost_user_gpu_chr_read() - cvm : Implement command blacklist for cvm security enhancement - crypto: Introduce SM3 hash hmac pbkdf algorithm - virtio-net: Use virtual time for RSC timers - vvfat: Fix bug in writing to middle of file - hw/core/ptimer: fix timer zero period condition for freq > 1GHz - hw/misc: support vpsp Signed-off-by: Jiabo Feng <fengjiabo1@huawei.com>
2024-09-18 15:20:53 +08:00
From 09934a231a513289caaae68e68912b735cb44b75 Mon Sep 17 00:00:00 2001
From: hanliyang <hanliyang@hygon.cn>
Date: Thu, 15 Apr 2021 08:32:24 -0400
Subject: [PATCH] kvm: Add support for CSV2 reboot
Linux will set vcpu.arch.guest_state_protected to true after execute
LAUNCH_UPDATE_VMSA successfully, and then KVM will prevent any changes
to VMCB State Save Area.
In order to support CSV2 guest reboot, calls cpus_control_pre_system_reset()
to set vcpu.arch.guest_state_protected to false, and calls
cpus_control_post_system_reset() to restore VMSA of guest's vcpu with
data generated by LAUNCH_UPDATE_VMSA.
In addition, for memory encrypted guest, additional works may be
required during system reset, such as flushing the cache. The function
cpus_control_post_system_reset() hints linux to flush caches of guest
memory.
Signed-off-by: hanliyang <hanliyang@hygon.cn>
---
accel/kvm/kvm-accel-ops.c | 3 +++
accel/kvm/kvm-all.c | 10 ++++++++++
accel/kvm/kvm-cpus.h | 3 +++
include/sysemu/accel-ops.h | 3 +++
include/sysemu/cpus.h | 2 ++
linux-headers/linux/kvm.h | 4 ++++
system/cpus.c | 14 ++++++++++++++
system/runstate.c | 5 +++++
8 files changed, 44 insertions(+)
diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c
index 6195150a0b..54f19028b8 100644
--- a/accel/kvm/kvm-accel-ops.c
+++ b/accel/kvm/kvm-accel-ops.c
@@ -112,6 +112,9 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data)
ops->remove_breakpoint = kvm_remove_breakpoint;
ops->remove_all_breakpoints = kvm_remove_all_breakpoints;
#endif
+
+ ops->control_pre_system_reset = kvm_cpus_control_pre_system_reset;
+ ops->control_post_system_reset = kvm_cpus_control_post_system_reset;
}
static const TypeInfo kvm_accel_ops_type = {
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index dc3605e648..8077630825 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2810,6 +2810,16 @@ void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu)
run_on_cpu(cpu, do_kvm_cpu_synchronize_pre_loadvm, RUN_ON_CPU_NULL);
}
+void kvm_cpus_control_pre_system_reset(void)
+{
+ kvm_vm_ioctl(kvm_state, KVM_CONTROL_VCPU_PRE_SYSTEM_RESET, NULL);
+}
+
+void kvm_cpus_control_post_system_reset(void)
+{
+ kvm_vm_ioctl(kvm_state, KVM_CONTROL_VCPU_POST_SYSTEM_RESET, NULL);
+}
+
#ifdef KVM_HAVE_MCE_INJECTION
static __thread void *pending_sigbus_addr;
static __thread int pending_sigbus_code;
diff --git a/accel/kvm/kvm-cpus.h b/accel/kvm/kvm-cpus.h
index ca40add32c..27b9d0d9db 100644
--- a/accel/kvm/kvm-cpus.h
+++ b/accel/kvm/kvm-cpus.h
@@ -23,4 +23,7 @@ int kvm_insert_breakpoint(CPUState *cpu, int type, vaddr addr, vaddr len);
int kvm_remove_breakpoint(CPUState *cpu, int type, vaddr addr, vaddr len);
void kvm_remove_all_breakpoints(CPUState *cpu);
+void kvm_cpus_control_pre_system_reset(void);
+void kvm_cpus_control_post_system_reset(void);
+
#endif /* KVM_CPUS_H */
diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h
index ef91fc28bb..7a32e7f820 100644
--- a/include/sysemu/accel-ops.h
+++ b/include/sysemu/accel-ops.h
@@ -53,6 +53,9 @@ struct AccelOpsClass {
int (*insert_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len);
int (*remove_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len);
void (*remove_all_breakpoints)(CPUState *cpu);
+
+ void (*control_pre_system_reset)(void);
+ void (*control_post_system_reset)(void);
};
#endif /* ACCEL_OPS_H */
diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
index b4a566cfe7..f24d27daf5 100644
--- a/include/sysemu/cpus.h
+++ b/include/sysemu/cpus.h
@@ -44,6 +44,8 @@ extern int icount_align_option;
void qemu_cpu_kick_self(void);
bool cpus_are_resettable(void);
+void cpus_control_pre_system_reset(void);
+void cpus_control_post_system_reset(void);
void cpu_synchronize_all_states(void);
void cpu_synchronize_all_post_reset(void);
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index e796105b76..eb30402c2d 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -1626,6 +1626,10 @@ struct kvm_master_dev_info
#define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr)
#define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr)
+/* ioctls for control vcpu setup during system reset */
+#define KVM_CONTROL_VCPU_PRE_SYSTEM_RESET _IO(KVMIO, 0xe8)
+#define KVM_CONTROL_VCPU_POST_SYSTEM_RESET _IO(KVMIO, 0xe9)
+
/*
* ioctls for vcpu fds
*/
diff --git a/system/cpus.c b/system/cpus.c
index f2289e9545..d9de09b9e8 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -193,6 +193,20 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)
}
}
+void cpus_control_pre_system_reset(void)
+{
+ if (cpus_accel->control_pre_system_reset) {
+ cpus_accel->control_pre_system_reset();
+ }
+}
+
+void cpus_control_post_system_reset(void)
+{
+ if (cpus_accel->control_post_system_reset) {
+ cpus_accel->control_post_system_reset();
+ }
+}
+
bool cpus_are_resettable(void)
{
if (cpus_accel->cpus_are_resettable) {
diff --git a/system/runstate.c b/system/runstate.c
index 538c645326..7e41626bb1 100644
--- a/system/runstate.c
+++ b/system/runstate.c
@@ -487,6 +487,8 @@ void qemu_system_reset(ShutdownCause reason)
mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
+ cpus_control_pre_system_reset();
+
cpu_synchronize_all_states();
if (mc && mc->reset) {
@@ -503,6 +505,9 @@ void qemu_system_reset(ShutdownCause reason)
qapi_event_send_reset(shutdown_caused_by_guest(reason), reason);
}
cpu_synchronize_all_post_reset();
+
+ cpus_control_post_system_reset();
+
monitor_qapi_event_discard_io_error();
}
--
2.41.0.windows.1