From nobody Wed Nov 5 05:45:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530216806253953.6111164301954; Thu, 28 Jun 2018 13:13:26 -0700 (PDT) Received: from localhost ([::1]:38320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdID-0005JA-D9 for importer@patchew.org; Thu, 28 Jun 2018 16:13:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdAW-00079Y-87 for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdAT-0000Fu-VZ for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:27 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:38580) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYdAT-0000EY-GJ for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:25 -0400 Received: by mail-wr0-x243.google.com with SMTP id e18-v6so6690684wrs.5 for ; Thu, 28 Jun 2018 13:05:25 -0700 (PDT) Received: from 640k.lan ([82.84.124.111]) by smtp.gmail.com with ESMTPSA id 127-v6sm6211110wmd.18.2018.06.28.13.05.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 13:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=xqSzARrgUhz3MLYpyOPMSZGJdmSf99ltKL8TIxTV4MU=; b=GSWijIpNeJ5Kp/dXube3WCsT80GnPR6hkKWQ6Z8eihAsD7X1r8JWmi/A2ER/gaeSWk 4IHaH7MQnwBUSvqu6arL09R15dy0F7j9IL/k4FCBfLcFyoR6P3zWNi1H5pBvsq8/rH6l Q+xGJJv6T5C7n5dAKOiuzmtIuoqXXcL73KZnhAxZuhBAh7jiop4HWKaWEExdvGMq0AU4 /7+USRhPDHi4WsngpDI6kG2q3KfWldy6rdtK03n0NGCYceMzCt5NLGgoPbbBIos30fU/ JV2kgJp6RAVZh6Mr6sfqZ4xbA6P1NOJlO9dSynNKWrCrLVj17gqXOGSJK18P7/5DI0Ij JFcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=xqSzARrgUhz3MLYpyOPMSZGJdmSf99ltKL8TIxTV4MU=; b=G2UsEq+Zuf34/2HxBTYwnRHMjjR/xo+EBAzrpqCkz14zGTZa7X9uIS67FTzu8o0MVB 9rYGQEaxfKEEb8hbbnbPtbF3pK/0ByqPF0vTzTXkLu6dNzIO3xKboYZFi/NC6kd3IC6I cqSGoRVrVPHDd5yScbHReFqMA+VJrUOoLFQCGlHqT0h5tYu9ywriHMLR3eFObIPO03aK bunqVUWTDknIXKyOQlzOq3zkBg63y9IHtVyQurWumItjRIOKU2M+gNsBpGrkJr8WGk5h Ji7cRhCGGmbqH0XBb/Jnw5fYT5Am8o9qCamC8vrS+H8hEJ9vX/sPnodlCHLm/thLYEP4 zfew== X-Gm-Message-State: APt69E14ZJnJGu3g82z/7CQjiDrFp4vI4+uc3QKBMNLDcPXvNLipBk4C HqIj6PmzESdWU2G7cHsWWD2zlQEZ X-Google-Smtp-Source: AAOMgpdDLq/FbM4+cQu9asAH7+aXy0NsHMPR5cd7cMPtCYTNDwFwqI/0UJQPYrPCZ6LCYdxmZkhUGA== X-Received: by 2002:adf:82cf:: with SMTP id 73-v6mr9583783wrc.77.1530216324161; Thu, 28 Jun 2018 13:05:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 22:04:20 +0200 Message-Id: <1530216310-52873-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> References: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PULL 10/60] kvm: Delete the slot if and only if the KVM_MEM_READONLY flag is changed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Shannon Zhao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Shannon Zhao 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 Message-Id: <1526462314-19720-1-git-send-email-zhaoshenglong@huawei.com> Signed-off-by: Paolo Bonzini --- 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, voi= d *ram, return 0; } =20 -static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slo= t) +static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slo= t, bool new) { KVMState *s =3D 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 =3D (unsigned long)slot->ram; mem.flags =3D slot->flags; =20 - if (slot->memory_size && mem.flags & KVM_MEM_READONLY) { + if (slot->memory_size && !new && (mem.flags ^ slot->old_flags) & KVM_M= EM_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 =3D 0; @@ -275,6 +275,7 @@ static int kvm_set_user_memory_region(KVMMemoryListener= *kml, KVMSlot *slot) } mem.memory_size =3D slot->memory_size; ret =3D kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); + slot->old_flags =3D 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 =3D mem->flags; mem->flags =3D kvm_mem_flags(mr); =20 /* If nothing changed effectively, no need to issue ioctl */ - if (mem->flags =3D=3D old_flags) { + if (mem->flags =3D=3D mem->old_flags) { return 0; } =20 - return kvm_set_user_memory_region(kml, mem); + return kvm_set_user_memory_region(kml, mem, false); } =20 static int kvm_section_update_flags(KVMMemoryListener *kml, @@ -755,7 +753,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, =20 /* unregister the slot */ mem->memory_size =3D 0; - err =3D kvm_set_user_memory_region(kml, mem); + mem->flags =3D 0; + err =3D 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 =3D ram; mem->flags =3D kvm_mem_flags(mr); =20 - err =3D kvm_set_user_memory_region(kml, mem); + err =3D 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; =20 typedef struct KVMMemoryListener { --=20 1.8.3.1