From nobody Sat Nov 23 19:35:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729706596; cv=none; d=zohomail.com; s=zohoarc; b=ITUQE4dMi2mqDxCDWskIl3WezegZYpzN2b5AV5jiHzFiHdOARTdJG7ZvlVElnvBRxjBDgsUpuI+3lvEBsU1YVGsjB7PvwVmI1Bsl8OKGUTBWl25PuQ/PmFZi5w5kYrr1pPEDxrL7DCBLfnktnWHNdqVG+1PnkqEq5jw+qnhOJ9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729706596; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aQi0jNBi64+93LR6lEvSe205PyBWXB4O7JAmokml2GE=; b=j9tVvhMicmNqclPh2DB/+DQMntYObmiu7sYp46yfXNlQRhjfcRP0EmpubSuppBMy2YPyK0qm8j5NDTzFGYEq7ZIPYCSfdFDPf8gOfQX6kPVI/MJy6H+CeUr4GqHxiy1V8XiZgB9qknMWCZXUozbUhyka5jslPCLgWwp2rvNO2eo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729706596534689.5592678699053; Wed, 23 Oct 2024 11:03:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3fh0-0002NS-1t; Wed, 23 Oct 2024 14:02:46 -0400 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 1t3fgk-0002Ld-Bn for qemu-devel@nongnu.org; Wed, 23 Oct 2024 14:02:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3fgh-00040X-Rs for qemu-devel@nongnu.org; Wed, 23 Oct 2024 14:02:29 -0400 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-387-gtlfmt_vPHyoNdMyIcbM3A-1; Wed, 23 Oct 2024 14:02:24 -0400 Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-71806ab1a97so88352a34.0 for ; Wed, 23 Oct 2024 11:02:24 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce009fcd0esm41746716d6.132.2024.10.23.11.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 11:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729706546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aQi0jNBi64+93LR6lEvSe205PyBWXB4O7JAmokml2GE=; b=FzFTpDQfxeTOYiWn+AH1aj5iAyp4jEbGpKuGui1/7dFhOsAd4wWBo/rd8o6KzvlGAUuKaY SnQmEE4ludguxwfN3W1skrxHcz1GV13pPYz+NljVsj1M8lF/xZS9+MyrJsy5RGrpEMJPfj iEz2PB8cHX4HolZm9JDjXO/JmDpe7bQ= X-MC-Unique: gtlfmt_vPHyoNdMyIcbM3A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729706543; x=1730311343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aQi0jNBi64+93LR6lEvSe205PyBWXB4O7JAmokml2GE=; b=nALD0cRoUMWezvdaxISoBPGj/E9mKot9fMhoUymGa04c14Nw2e6KDIqpjM0F1O0D+m UWvoFBArsdfqgvQnTjkJQhAJJIaF7Hk09WrUCJHli7gu+ykT9bhUUwZGHU2TfUOU+NH6 nit8QbFCgd8SurSr1joqlw7GCJ/xkutpNcUiGkO/k3MgaozfuVvRd3AG3ISfzKFAkwQr 3TDUsZpbTMAa18zTWIPawjRFgjxVcliU6hBbtPgxi/64jl3UDoTCMICDe+EudK1UBW/m LQ1dXHj9lxQ5tL9s+ANiZAg2XS0Y7FVBh1HWJDv/+bXTktj75FxAmQQ4HFhzfmn7ztNX ZHRw== X-Gm-Message-State: AOJu0YxiU75w1dQAfiNAw0/KuXR3bVeOpOnqmLp4ObnNfi0WM4e3vYi3 PkDi2WxDzuMOrA6ntnoZjvEyUW/AwPVUNnMNBLDJeiM/AAPo526kFbrmP1thjsGpnq9RyjFdeZJ WFXVQekJjYOB27TY8HFEA7CNH//JUoXDa5L6dV22XOYW+n8QEl1FplINd1QULVsZH84yqroRUoU cuIgA91cFNR9rFAVzTkbTb85AmB6rUyjb2tA== X-Received: by 2002:a05:6358:71c8:b0:1c3:6f59:fe3b with SMTP id e5c5f4694b2df-1c3d8122bf1mr242284955d.16.1729706541857; Wed, 23 Oct 2024 11:02:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmn6yFChVSCmeLaCr4qv2RHZMO9pPhoYeEkVqv/N0bbtcZqtTpNV1ujXwBzEXTcSaSjyIHEw== X-Received: by 2002:a05:6358:71c8:b0:1c3:6f59:fe3b with SMTP id e5c5f4694b2df-1c3d8122bf1mr242267555d.16.1729706539985; Wed, 23 Oct 2024 11:02:19 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Alex Williamson , Fabiano Rosas , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2 1/4] migration: Unexport dirty_bitmap_mig_init() in misc.h Date: Wed, 23 Oct 2024 14:02:13 -0400 Message-ID: <20241023180216.1072575-2-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241023180216.1072575-1-peterx@redhat.com> References: <20241023180216.1072575-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.263, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.697, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729706597629116600 It's only used within migration/, so it shouldn't be exported. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Peter Xu --- include/migration/misc.h | 3 --- migration/migration.h | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index bfadc5613b..df57be6b5e 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -108,7 +108,4 @@ bool migration_incoming_postcopy_advised(void); /* True if background snapshot is active */ bool migration_in_bg_snapshot(void); =20 -/* migration/block-dirty-bitmap.c */ -void dirty_bitmap_mig_init(void); - #endif diff --git a/migration/migration.h b/migration/migration.h index 7dc59c5e8d..0956e9274b 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -552,4 +552,8 @@ int migration_rp_wait(MigrationState *s); void migration_rp_kick(MigrationState *s); =20 void migration_bitmap_sync_precopy(bool last_stage); + +/* migration/block-dirty-bitmap.c */ +void dirty_bitmap_mig_init(void); + #endif --=20 2.45.0 From nobody Sat Nov 23 19:35:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729706596; cv=none; d=zohomail.com; s=zohoarc; b=HmxYlbL8xB5jMjKb5QVgGcA5W3Iief2I5akM8oqaADql4/A58GtCgJwa1BIpg1AnhUrgH3JytzWsGevpRBhcrJguOGIH+A8DgmmAPJzgtio00joFRYJe5jpBk4BLh33/Nas8DNVVsTFuIYAyELO7QVKYbl+aw5Yqil62Z4cEnlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729706596; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ffbOb1zLkckP3Rme6JyfNXdz8ft6fnCYj3dIDD3fnGQ=; b=jZnNjVy0Ve7FAcGPW3nhcd2NtHMdwdGiSSzED4gaxMgzj4TpF5RZsykslvt6EAlEzm0AjKgr900VhePpRgFCuZJBEdPt55xFxwrGmHhEhiFTh09CXIIE7taHyReYDmtpfy7aaceuqqnf/vdq6gg9K+VUTJZVOMMzxU9GhcH1KHc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729706596511525.0141450380929; Wed, 23 Oct 2024 11:03:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3fgo-0002Lk-DM; Wed, 23 Oct 2024 14:02:34 -0400 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 1t3fgi-0002L6-3H for qemu-devel@nongnu.org; Wed, 23 Oct 2024 14:02:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3fgf-00040G-Ig for qemu-devel@nongnu.org; Wed, 23 Oct 2024 14:02:27 -0400 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-HM65LBG8M_WVl8TJBID7ww-1; Wed, 23 Oct 2024 14:02:23 -0400 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6cc32a0b26bso1497326d6.1 for ; Wed, 23 Oct 2024 11:02:22 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce009fcd0esm41746716d6.132.2024.10.23.11.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 11:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729706544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ffbOb1zLkckP3Rme6JyfNXdz8ft6fnCYj3dIDD3fnGQ=; b=BVFI++px5zwMedn1RMmvtJHBGHegzyMygP424DfOs2SL398mmh7ZIYiLDBWY7jCPU7RwEJ ou8a7NPEIR0L/MkWBe3gHz6uoMKvkJ8wYNggKd30rVv71xmyjWOfyPXDi+o5luC0rWHSx+ Sl/mD81LRxoeJPsV6xJ/gnU+3B7++1w= X-MC-Unique: HM65LBG8M_WVl8TJBID7ww-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729706542; x=1730311342; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ffbOb1zLkckP3Rme6JyfNXdz8ft6fnCYj3dIDD3fnGQ=; b=mzonZRs9R1w+HLy2N/fZ9cO3zP5WCoURWaBwY7/KJ9K8Uy1Jl53lpkRcUAQJ5NrMMz Jeqd6SMyV1iWTsGFqgG//XOb82kQ1HxpAbKiizHki/B476EOykaKsAxY+yNoOhI47tjv ovzIp9h7QyWrU+N8hkskpU7CEkxBMmeH1txhF18MmsDB0EjIwtDuc3HOiWCQ+cvmUsiB OKpHw5qZt27gIehwxnlZmsH2NKLn2jlzOu+yC4g+I6jMstbVHOYB4LF5cBRZisvbN2L3 LgvbZBmygXTXLU9jQkglpeORKLs0upNvubRiZoyihNXGPR/KlyZrqEXDkfqyEy44yxzw GSmA== X-Gm-Message-State: AOJu0YwIPHQqPf17H264glIP+rZeJ853mFOw8wKkw6917Z/lv6qZcwmj cY/sAFMQv5cFCrIqaffLpohf5dd9e/PsbxfEN8j4moSLgPsNQZ4lYhOvjMh30ERXDnHunjEqhba hXknk7hzrklp1mbKwiLuiQUe3/ocRfFYlQFRViad08P42fh2Bp6mt+KLi+QLCrxXNhR5G3lmEM2 o+o+flGAJZBo5QSIERIOSTPPY0aLaZtMen/w== X-Received: by 2002:a05:6214:390d:b0:6cb:e9a5:acfb with SMTP id 6a1803df08f44-6ce34259feemr39838446d6.38.1729706541633; Wed, 23 Oct 2024 11:02:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxKojU9TywE/snPaG/+JCr7UIS85Mv5QmXatQKlX6i1h4/7Doyl2/UvMXhyeOSHY/gkW0b1w== X-Received: by 2002:a05:6214:390d:b0:6cb:e9a5:acfb with SMTP id 6a1803df08f44-6ce34259feemr39838076d6.38.1729706541202; Wed, 23 Oct 2024 11:02:21 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Alex Williamson , Fabiano Rosas , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2 2/4] migration: Reset current_migration properly Date: Wed, 23 Oct 2024 14:02:14 -0400 Message-ID: <20241023180216.1072575-3-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241023180216.1072575-1-peterx@redhat.com> References: <20241023180216.1072575-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.263, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729706597655116600 Content-Type: text/plain; charset="utf-8" current_migration is never reset, even if the migration object is freed already. It means anyone references that can trigger UAF and it'll be hard to debug. Properly clear the pointer now, so far by doing it in the finalize() (as we know there's only one instance of it). Add a TODO entry for it showing that we can do better in the future. To make it clear, also initialize the variable in the instance_init() so it's very well paired at least. Signed-off-by: Peter Xu --- migration/migration.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index bcb735869b..a82297db0f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -232,9 +232,9 @@ static int migration_stop_vm(MigrationState *s, RunStat= e state) =20 void migration_object_init(void) { - /* This can only be called once. */ - assert(!current_migration); - current_migration =3D MIGRATION_OBJ(object_new(TYPE_MIGRATION)); + MIGRATION_OBJ(object_new(TYPE_MIGRATION)); + /* This should be set when initialize the object */ + assert(current_migration); =20 /* * Init the migrate incoming object as well no matter whether @@ -3877,12 +3877,31 @@ static void migration_instance_finalize(Object *obj) qemu_sem_destroy(&ms->rp_state.rp_pong_acks); qemu_sem_destroy(&ms->postcopy_qemufile_src_sem); error_free(ms->error); + + /* + * We know we only have one intance of migration, and when reaching + * here it means migration object is gone. Clear the global reference + * to reflect that. + */ + current_migration =3D NULL; } =20 static void migration_instance_init(Object *obj) { MigrationState *ms =3D MIGRATION_OBJ(obj); =20 + /* + * There can only be one migration object globally. Keep a record of + * the pointer in current_migration, which will be reset after the + * object finalize(). + * + * TODO: after migration/ code can always take a MigrationObject* + * pointer all over the place, logically we can drop current_migration + * variable. + */ + assert(!current_migration); + current_migration =3D ms; + ms->state =3D MIGRATION_STATUS_NONE; ms->mbps =3D -1; ms->pages_per_second =3D -1; --=20 2.45.0 From nobody Sat Nov 23 19:35:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729706634; cv=none; d=zohomail.com; s=zohoarc; b=VXRgWY+NKJHuERSu9VrB7HHvuVajQTeS2uAPrVczm3uZ8w/Q5UToEKN8brSh78bCzKynyc+urptU4vyVqYVEimRhYyg+IhhDvF/tGS+kr6j+YDXjx9hEbTXbQs4V9vhIdfQmfpQq9TXlN/6CAFAynLTikDNvo2UJRmHzU7qpn7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729706634; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=E8pWkArmtfUuABCkN8q7bum98R07KaedLND3Mn0kzzA=; b=SofR6aJIktQUNNruPPPq0KD4fVMsMKII1l52JyX3gQVsmyF9MVTyqyzJFZw9eZhf98q6UoB4MPa0uKY9xQA7vrDyKiLDpdxNuDzBE9WIRd/O1vUnUA1Jqrefb2Z9VPB5ENHs5a2mlQW2+FvBpzP8wjF71poF93OWfOk13yipPZw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729706634639556.8061692957459; Wed, 23 Oct 2024 11:03:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3fgv-0002Mq-OG; Wed, 23 Oct 2024 14:02:41 -0400 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 1t3fgk-0002Lc-BR for qemu-devel@nongnu.org; Wed, 23 Oct 2024 14:02:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3fgh-00040S-S5 for qemu-devel@nongnu.org; Wed, 23 Oct 2024 14:02:29 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-OGKjWmoOPciWSFCvRgbLyA-1; Wed, 23 Oct 2024 14:02:25 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-461011bd338so836681cf.3 for ; Wed, 23 Oct 2024 11:02:24 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce009fcd0esm41746716d6.132.2024.10.23.11.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 11:02:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729706546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E8pWkArmtfUuABCkN8q7bum98R07KaedLND3Mn0kzzA=; b=dHxaYP6pHo4KuOTZcdgsS9dG/3l0wJrxhi85lJcwpTojUQUqFN4+QKmkR/LGs1uvRc4zAC 1ufHXOT4qKUeiyiSzdKvkwX5gHMd1THeefu+OBEvg1UlQn10W+sRrAq3nOyffPjzRjd98u zjcyAQMPkC1C0qpuEYJ8TnoTUrV1MXs= X-MC-Unique: OGKjWmoOPciWSFCvRgbLyA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729706543; x=1730311343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E8pWkArmtfUuABCkN8q7bum98R07KaedLND3Mn0kzzA=; b=ohYyZfZKjaBuDsPiNPdsMRas4w9vVCI+GYugBXBxdOxnQGhRv7L3j61vqKrjtZ2ZAc Nb29nXG7htGt2tjbQysQKc3XXs+keabQKcAbeBr+TW+2/PN6Ha0YoLHfEMWozxLVy/xs wmIDPNj4JdMv6/UCJk0dRopO47uuHzDukXsqK27ZEBG+JeotH17EkHh1mZnSKfF65Beu jqVMaBRmOjA5sSV7LBzvuv2pdgMzlSGYwBG48anlGGuvucIyabVjE2OQ2VX8w8Ko0RcX oe1QVTsMXDtGDkdKRXYBKfw8G6Tczx1vdY6rBgbVUXj6Qg/kDBLmj7W+CsWjFUkRFLCx Qf3A== X-Gm-Message-State: AOJu0Yy298UwRly6+L45SMP1t200F2/d10UUog3w7YyXImTfPslghnSs MIbmLO86AdxJufoaaG4VErdipVrnI56+5V1Zc0e/ad2paI7UQlQ4CIPShmDHYSm6tJNnbPqaDUP zqn4FMrrNGQ9MKBkIn/IucSCu8T6V8WKJVLnV7grAJu3cyPPrvZLH5Rf7+fpt3oXhXtTfwZJHgW SLp0HEt3gIrCLEFbAFKkd3LMjjVt+KD540sA== X-Received: by 2002:a05:622a:d0:b0:460:a9da:42b8 with SMTP id d75a77b69052e-461146bff6amr40873061cf.22.1729706543728; Wed, 23 Oct 2024 11:02:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkiPd6HQAIvBizypMj9qmSkBmmIcMzdl6KqwcYi5PN1NYJrvegvqT2vnBNF/gQoUza1sJq7Q== X-Received: by 2002:a05:622a:d0:b0:460:a9da:42b8 with SMTP id d75a77b69052e-461146bff6amr40872541cf.22.1729706543176; Wed, 23 Oct 2024 11:02:23 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Alex Williamson , Fabiano Rosas , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2 3/4] migration: Add global_migration Date: Wed, 23 Oct 2024 14:02:15 -0400 Message-ID: <20241023180216.1072575-4-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241023180216.1072575-1-peterx@redhat.com> References: <20241023180216.1072575-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.263, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.697, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729706636087116600 Content-Type: text/plain; charset="utf-8" Add a variable that is only used in exported / global migration helpers, reflecting whether migration is available to the outside world. Note that we haven't yet started using this variable, but hopefully that is still better already because now we have an explicit place to say who owns the initial migration refcount. In this case, it's the global_migration pointer (rather than current_migration) that owns it. Then in shutdown() we clear that pointer right after the unref() would make sense. We'll start to use the variable in the next patch to provide thread safety to all migration exported helpers. Signed-off-by: Peter Xu --- migration/migration.c | 44 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index a82297db0f..c4adad7972 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -96,7 +96,36 @@ enum mig_rp_message_type { migrations at once. For now we don't need to add dynamic creation of migration */ =20 -static MigrationState *current_migration; +/* + * We have two pointers for the global migration objects. Both of them are + * initialized early during QEMU starts, but they have different lifecycle= s. + * + * - current_migration + * + * This variable reflects the whole lifecycle of the migration object + * (which each QEMU can only have one). It is valid until the migration + * object is destroyed. + * + * This is the object that internal migration so far use. For example, + * internal helper migrate_get_current() references it. + * + * When all migration code can always pass over a MigrationState* around, + * this variable can logically be dropped. But we're not yet there. + * + * - global_migration + * + * This is valid only until the migration object is still valid to the + * outside-migration world (until migration_shutdown()). + * + * This should normally be always set, cleared or accessed by the main + * thread only, rather than the migration thread. + * + * All the exported functions (in include/migration) should reference the + * exported migration object only to avoid race conditions, as + * current_migration can be freed concurrently by migration thread when + * the migration thread holds the last refcount. + */ +static MigrationState *current_migration, *global_migration; static MigrationIncomingState *current_incoming; =20 static GSList *migration_blockers[MIG_MODE__MAX]; @@ -232,7 +261,9 @@ static int migration_stop_vm(MigrationState *s, RunStat= e state) =20 void migration_object_init(void) { - MIGRATION_OBJ(object_new(TYPE_MIGRATION)); + /* The global variable holds the refcount */ + global_migration =3D MIGRATION_OBJ(object_new(TYPE_MIGRATION)); + /* This should be set when initialize the object */ assert(current_migration); =20 @@ -333,7 +364,14 @@ void migration_shutdown(void) * stop the migration using this structure */ migration_cancel(NULL); - object_unref(OBJECT(current_migration)); + + /* + * This marks that migration object is not visible anymore to + * outside-migration world. Migration might still hold a refcount if + * it's still in progress. + */ + object_unref(OBJECT(global_migration)); + global_migration =3D NULL; =20 /* * Cancel outgoing migration of dirty bitmaps. It should --=20 2.45.0 From nobody Sat Nov 23 19:35:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729706645; cv=none; d=zohomail.com; s=zohoarc; b=B1Rdy17yyMuLtjtEKs6PQ+6+8rSgw8AopiogE0oYMlcC1vPus8zg68laKP1f/Z+5rwjTrfmgp5lk9wpNeh37ghykcIyf/CNI4MzctMHvbehz+HddB2dx0iAyI6B+Wr+iD4z1VEWTcFVIvkIGLk0e9vf0t3m7C8GEPQwgSGmfijY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729706645; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=irG+E1FaN1Hl9lD+YLjc9uevqLdXpkeOECPEiSEa5DE=; b=bgLeW/ozalTuA2uPCdwUBmdzZIyyDy2R4LWDl3dppjize6hFMoPB09Nm619fqx3PVWd+friY/oIyLd/JXEWX43+P5hs4yd8hIdq8VasQojtLGfLJKz5dYmjdUIy2n5CFqyPotqSabnloU/IKqNu0rhST0bjrmA/b2cnQB/iQubA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729706645962867.8111303020723; Wed, 23 Oct 2024 11:04:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3fgv-0002Mo-Dy; Wed, 23 Oct 2024 14:02:41 -0400 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 1t3fgl-0002Lj-SE for qemu-devel@nongnu.org; Wed, 23 Oct 2024 14:02:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3fgk-00040z-4S for qemu-devel@nongnu.org; Wed, 23 Oct 2024 14:02:31 -0400 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-Qzd1uc7YNTGE9Kp-eyZ6gA-1; Wed, 23 Oct 2024 14:02:27 -0400 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6cbe4a123fdso1363446d6.2 for ; Wed, 23 Oct 2024 11:02:27 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ce009fcd0esm41746716d6.132.2024.10.23.11.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 11:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729706548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=irG+E1FaN1Hl9lD+YLjc9uevqLdXpkeOECPEiSEa5DE=; b=Y77Bxw+My+iJfdU/Toocd8r8rV9uStnwCnv/P/r30jhnT7w++6rBZd2hy0ywZKhFQOQ13j UUAT1cp+IKUR3sHXa4vKp+LhNXW2fPfVCpcAauaeRu2nfpHZ0ltltTddtzx5/vBq4bUa9O VPI4KPS0HgbY8i4FXeO+JVrF/yVoVug= X-MC-Unique: Qzd1uc7YNTGE9Kp-eyZ6gA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729706546; x=1730311346; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=irG+E1FaN1Hl9lD+YLjc9uevqLdXpkeOECPEiSEa5DE=; b=ZLu3iEGR53H3VWfhNgq1PHcN3/3h8A3sAgOQyJP3lVn+zGW5MCZTMicKTR5ZVXJdZO /vAx1N7VXoR/wEditkHA1oT0NN+M9cqizQ7uYTtbifPF2JgICBlwuUpeqWsjo1uHS5nY Hs6J4rlCcnEZzt3filkNdr1Wfb9ji9LPhfiYG9cKbFjW30wk2iO4x3eqrt/k3Z47z0BY cGdb3LHK3TPmEc154H4w75SVSqap+iw2CEWjMfT4ylX2g5hdmzW+yl880cCs07CrqVpB FL+qfhHQ26P2F1osQbel5jeBd2cH9yHXQWFQRqsLkMtPH2Nz1MvCeoDz/tXsmOmqrMts D5xA== X-Gm-Message-State: AOJu0Ywomf5efLrnRG+Vko0TIZcVB1jiMeDKOrP4XlC7lfeNwZ2upnE3 GJJ3qua2aza+6hSgVORbhhxuKU1cyYblzkiepZVH4ZJIdyPDKh3OroEiUId2eL038qCFyaZXC5i 4FX4cb0V0dzBnUKMUeJmOveeNq3otRdLPQZIsQiV/hoMcLGnuqKggZWxPmccIVC0/Pwoy2h6PDS nTWpA16WGTDDrMzc/4fiuC1R1oV0MITwRR7A== X-Received: by 2002:a05:6214:4186:b0:6cb:5273:7265 with SMTP id 6a1803df08f44-6ce341a2c77mr31532296d6.20.1729706545638; Wed, 23 Oct 2024 11:02:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEV5voK3721NW9DdugT/oFGZywAfbgQ148v30ZBAPoF84sUiNspXlqcr/U0XlDQ4ELS03MBfA== X-Received: by 2002:a05:6214:4186:b0:6cb:5273:7265 with SMTP id 6a1803df08f44-6ce341a2c77mr31531916d6.20.1729706545234; Wed, 23 Oct 2024 11:02:25 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Alex Williamson , Fabiano Rosas , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , "Dr . David Alan Gilbert" Subject: [PATCH v2 4/4] migration: Make all helpers in misc.h safe to use without migration Date: Wed, 23 Oct 2024 14:02:16 -0400 Message-ID: <20241023180216.1072575-5-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241023180216.1072575-1-peterx@redhat.com> References: <20241023180216.1072575-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.263, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.697, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729706647925116600 Migration object can be freed (e.g. after migration_shutdown()) before some other device codes can still run, while we do have a bunch of migration helpers exported in migration/misc.h that logically can be invoked at any time of QEMU, even during destruction of a VM. Make all these functions safe to be called, especially, not crashing after the migration object is unreferenced from the main context. To achieve it, only reference global_migration variable in the exported functions. The variable is only reset with BQL, so it's safe to access. Add a comment in the header explaining how to guarantee thread safe on using these functions, and we choose BQL because fundamentally that's how it's working now. We can move to other things (e.g. RCU) whenever necessary in the future but it's an overkill if we have BQL anyway in most/all existing callers. When at it, update some comments, e.g. migrate_announce_params() is exported from options.c now. Cc: C=C3=A9dric Le Goater Cc: Avihai Horon Cc: Fabiano Rosas Cc: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- include/migration/misc.h | 26 +++++++++++++++++++++----- migration/migration.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index df57be6b5e..48892f9672 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -19,8 +19,19 @@ #include "qapi/qapi-types-net.h" #include "migration/client-options.h" =20 -/* migration/ram.c */ +/* + * Misc migration functions exported to be used in QEMU generic system + * code outside migration/. + * + * By default, BQL is recommended before using below functions to avoid + * race conditions (concurrent updates to global_migration variable). It's + * caller's responsibility to make sure it's thread safe otherwise when + * below helpers are used without BQL held. When unsure, take BQL always. + */ =20 +/* + * migration/ram.c + */ typedef enum PrecopyNotifyReason { PRECOPY_NOTIFY_SETUP =3D 0, PRECOPY_NOTIFY_BEFORE_BITMAP_SYNC =3D 1, @@ -43,14 +54,19 @@ void ram_mig_init(void); void qemu_guest_free_page_hint(void *addr, size_t len); bool migrate_ram_is_ignored(RAMBlock *block); =20 -/* migration/block.c */ - +/* + * migration/options.c + */ AnnounceParameters *migrate_announce_params(void); -/* migration/savevm.c */ =20 +/* + * migration/savevm.c + */ void dump_vmstate_json_to_file(FILE *out_fp); =20 -/* migration/migration.c */ +/* + * migration/migration.c + */ void migration_object_init(void); void migration_shutdown(void); bool migration_is_idle(void); diff --git a/migration/migration.c b/migration/migration.c index c4adad7972..667816cc65 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1157,7 +1157,11 @@ void migrate_send_rp_resume_ack(MigrationIncomingSta= te *mis, uint32_t value) */ bool migration_is_setup_or_active(void) { - MigrationState *s =3D current_migration; + MigrationState *s =3D global_migration; + + if (!s) { + return false; + } =20 switch (s->state) { case MIGRATION_STATUS_ACTIVE: @@ -1174,7 +1178,6 @@ bool migration_is_setup_or_active(void) =20 default: return false; - } } =20 @@ -1721,7 +1724,11 @@ bool migration_is_idle(void) =20 bool migration_is_active(void) { - MigrationState *s =3D current_migration; + MigrationState *s =3D global_migration; + + if (!s) { + return false; + } =20 return (s->state =3D=3D MIGRATION_STATUS_ACTIVE || s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE); @@ -1729,14 +1736,23 @@ bool migration_is_active(void) =20 bool migration_is_device(void) { - MigrationState *s =3D current_migration; + MigrationState *s =3D global_migration; + + if (!s) { + return false; + } =20 return s->state =3D=3D MIGRATION_STATUS_DEVICE; } =20 bool migration_thread_is_self(void) { - MigrationState *s =3D current_migration; + MigrationState *s =3D global_migration; + + /* If no migration object, must not be the migration thread */ + if (!s) { + return false; + } =20 return qemu_thread_is_self(&s->thread); } @@ -3113,7 +3129,11 @@ static MigThrError postcopy_pause(MigrationState *s) =20 void migration_file_set_error(int ret, Error *err) { - MigrationState *s =3D current_migration; + MigrationState *s =3D global_migration; + + if (!s) { + return; + } =20 WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) { if (s->to_dst_file) { --=20 2.45.0