From nobody Wed Oct 29 22:59:56 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; 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15264624859071013.0004680197258; Wed, 16 May 2018 02:21:25 -0700 (PDT) Received: from localhost ([::1]:36316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIscX-00034R-Bw for importer@patchew.org; Wed, 16 May 2018 05:21:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIsbX-0002kB-2C for qemu-devel@nongnu.org; Wed, 16 May 2018 05:20:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIsbS-0004hy-9b for qemu-devel@nongnu.org; Wed, 16 May 2018 05:20:15 -0400 Received: from [45.249.212.35] (port=59461 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fIsbR-0004WQ-Ub for qemu-devel@nongnu.org; Wed, 16 May 2018 05:20:10 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 9A81D750E3059; Wed, 16 May 2018 17:20:00 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.361.1; Wed, 16 May 2018 17:19:53 +0800 From: Shannon Zhao To: , , Date: Wed, 16 May 2018 17:18:34 +0800 Message-ID: <1526462314-19720-1-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.35 Subject: [Qemu-devel] [PATCH] kvm: Delete the slot only when 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.zhaosl@gmail.com, zhengxiang9@huawei.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- include/sysemu/kvm_int.h | 1 + kvm-all.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) 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 { diff --git a/kvm-all.c b/kvm-all.c index 2515a23..de8250e 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -252,7 +252,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 && (mem.flags ^ slot->old_flags) & KVM_MEM_READO= NLY) { /* 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; @@ -376,11 +376,11 @@ static int kvm_slot_update_flags(KVMMemoryListener *k= ml, KVMSlot *mem, { int old_flags; =20 - old_flags =3D mem->flags; + mem->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 --=20 2.0.4