From nobody Mon Feb 9 21:39:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676564446888355.1940513797683; Thu, 16 Feb 2023 08:20:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSgyw-0008Bk-GT; Thu, 16 Feb 2023 11:19:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSgyh-000866-LU for qemu-devel@nongnu.org; Thu, 16 Feb 2023 11:19:25 -0500 Received: from prt-mail.chinatelecom.cn ([42.123.76.223] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSgyf-00054c-EY for qemu-devel@nongnu.org; Thu, 16 Feb 2023 11:19:23 -0500 Received: from clientip-118.116.19.27 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 861F52800E3; Fri, 17 Feb 2023 00:19:14 +0800 (CST) Received: from ([118.116.19.27]) by app0023 with ESMTP id f08dd78b756545d9a1458872790a429d for qemu-devel@nongnu.org; Fri, 17 Feb 2023 00:19:18 CST HMM_SOURCE_IP: 172.18.0.188:50698.1319324123 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: huangy81@chinatelecom.cn X-Transaction-ID: f08dd78b756545d9a1458872790a429d X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 118.116.19.27 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: Markus Armbruster , Peter Xu , "Dr. David Alan Gilbert" , Juan Quintela , Thomas Huth , Paolo Bonzini , Eric Blake , Peter Maydell , Richard Henderson Subject: [PATCH v4 03/10] kvm: dirty-ring: Fix race with vcpu creation Date: Fri, 17 Feb 2023 00:18:32 +0800 Message-Id: <1d14deb6684bcb7de1c9633c5bd21113988cc698.1676563222.git.huangy81@chinatelecom.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.223; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1676564447073100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu It's possible that we want to reap a dirty ring on a vcpu that is during creation, because the vcpu is put onto list (CPU_FOREACH visible) before initialization of the structures. In this case: qemu_init_vcpu x86_cpu_realizefn cpu_exec_realizefn cpu_list_add <---- can be probed by CPU_FOREACH qemu_init_vcpu cpus_accel->create_vcpu_thread(cpu); kvm_init_vcpu map kvm_dirty_gfns <--- kvm_dirty_gfns valid Don't try to reap dirty ring on vcpus during creation or it'll crash. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D2124756 Reported-by: Xiaohui Li Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 9b26582655..47483cdfa0 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -685,6 +685,15 @@ static uint32_t kvm_dirty_ring_reap_one(KVMState *s, C= PUState *cpu) uint32_t ring_size =3D s->kvm_dirty_ring_size; uint32_t count =3D 0, fetch =3D cpu->kvm_fetch_index; =20 + /* + * It's possible that we race with vcpu creation code where the vcpu is + * put onto the vcpus list but not yet initialized the dirty ring + * structures. If so, skip it. + */ + if (!cpu->created) { + return 0; + } + assert(dirty_gfns && ring_size); trace_kvm_dirty_ring_reap_vcpu(cpu->cpu_index); =20 --=20 2.17.1