[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 10/60] kvm: Delete the slot if and only if the KVM_ME
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 10/60] kvm: Delete the slot if and only if the KVM_MEM_READONLY flag is changed |
Date: |
Thu, 28 Jun 2018 22:04:20 +0200 |
From: Shannon Zhao <address@hidden>
According to KVM commit 75d61fbc, it needs to delete the slot before
changing the KVM_MEM_READONLY flag. But QEMU commit 235e8982 only check
whether KVM_MEM_READONLY flag is set instead of changing. It doesn't
need to delete the slot if the KVM_MEM_READONLY flag is not changed.
This fixes a issue that migrating a VM at the OVMF startup stage and
VM is executing the codes in rom. Between the deleting and adding the
slot in kvm_set_user_memory_region, there is a chance that guest access
rom and trap to KVM, then KVM can't find the corresponding memslot.
While KVM (on ARM) injects an abort to guest due to the broken hva, then
guest will get stuck.
Signed-off-by: Shannon Zhao <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
accel/kvm/kvm-all.c | 17 ++++++++---------
include/sysemu/kvm_int.h | 1 +
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index ffee68e..eb7db92 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -256,7 +256,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void
*ram,
return 0;
}
-static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot)
+static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot,
bool new)
{
KVMState *s = kvm_state;
struct kvm_userspace_memory_region mem;
@@ -267,7 +267,7 @@ static int kvm_set_user_memory_region(KVMMemoryListener
*kml, KVMSlot *slot)
mem.userspace_addr = (unsigned long)slot->ram;
mem.flags = slot->flags;
- if (slot->memory_size && mem.flags & KVM_MEM_READONLY) {
+ if (slot->memory_size && !new && (mem.flags ^ slot->old_flags) &
KVM_MEM_READONLY) {
/* Set the slot size to 0 before setting the slot to the desired
* value. This is needed based on KVM commit 75d61fbc. */
mem.memory_size = 0;
@@ -275,6 +275,7 @@ static int kvm_set_user_memory_region(KVMMemoryListener
*kml, KVMSlot *slot)
}
mem.memory_size = slot->memory_size;
ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
+ slot->old_flags = mem.flags;
trace_kvm_set_user_memory(mem.slot, mem.flags, mem.guest_phys_addr,
mem.memory_size, mem.userspace_addr, ret);
return ret;
@@ -391,17 +392,14 @@ static int kvm_mem_flags(MemoryRegion *mr)
static int kvm_slot_update_flags(KVMMemoryListener *kml, KVMSlot *mem,
MemoryRegion *mr)
{
- int old_flags;
-
- old_flags = mem->flags;
mem->flags = kvm_mem_flags(mr);
/* If nothing changed effectively, no need to issue ioctl */
- if (mem->flags == old_flags) {
+ if (mem->flags == mem->old_flags) {
return 0;
}
- return kvm_set_user_memory_region(kml, mem);
+ return kvm_set_user_memory_region(kml, mem, false);
}
static int kvm_section_update_flags(KVMMemoryListener *kml,
@@ -755,7 +753,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
/* unregister the slot */
mem->memory_size = 0;
- err = kvm_set_user_memory_region(kml, mem);
+ mem->flags = 0;
+ err = kvm_set_user_memory_region(kml, mem, false);
if (err) {
fprintf(stderr, "%s: error unregistering slot: %s\n",
__func__, strerror(-err));
@@ -771,7 +770,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
mem->ram = ram;
mem->flags = kvm_mem_flags(mr);
- err = kvm_set_user_memory_region(kml, mem);
+ err = kvm_set_user_memory_region(kml, mem, true);
if (err) {
fprintf(stderr, "%s: error registering slot: %s\n", __func__,
strerror(-err));
diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h
index 888557a..f838412 100644
--- a/include/sysemu/kvm_int.h
+++ b/include/sysemu/kvm_int.h
@@ -20,6 +20,7 @@ typedef struct KVMSlot
void *ram;
int slot;
int flags;
+ int old_flags;
} KVMSlot;
typedef struct KVMMemoryListener {
--
1.8.3.1
- [Qemu-devel] [PULL 01/60] exec: Fix MAP_RAM for cached access, (continued)
- [Qemu-devel] [PULL 01/60] exec: Fix MAP_RAM for cached access, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 02/60] move public invalidate APIs out of translate-all.{c, h}, clean up, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 06/60] target/i386: Fix BLSR and BLSI, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 07/60] whpx: commit missing file, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 04/60] main-loop: document IOCanReadHandler, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 05/60] hw/char/serial: Only retry if qemu_chr_fe_write returns 0, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 08/60] memory-device: turn alignment assert into check, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 09/60] exec: check that alignment is a power of two, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 13/60] QemuMutex: support --enable-debug-mutex, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 12/60] qemu-thread: introduce qemu-thread-common.h, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 10/60] kvm: Delete the slot if and only if the KVM_MEM_READONLY flag is changed,
Paolo Bonzini <=
- [Qemu-devel] [PULL 11/60] tests/atomic_add-bench: add -m option to use mutexes, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 17/60] pc-dimm: remove leftover "struct pc_dimms_capacity", Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 15/60] Replace '-enable-kvm' with '-accel kvm' in docs and help texts, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 18/60] pc: rename pc_dimm_(plug|unplug|...)* into pc_memory_(plug|unplug|...)*, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 21/60] pc: factor out pc specific dimm checks into pc_memory_pre_plug(), Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 14/60] configure: enable debug-mutex if debug enabled, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 19/60] pc-dimm: rename pc_dimm_memory_* to pc_dimm_*, Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 22/60] nvdimm: no need to overwrite get_vmstate_memory_region(), Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 23/60] hostmem: drop error variable from host_memory_backend_get_memory(), Paolo Bonzini, 2018/06/28
- [Qemu-devel] [PULL 25/60] nvdimm: convert "unarmed" into a static property, Paolo Bonzini, 2018/06/28