From nobody Sat Nov 23 18:12:41 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=1729805517; cv=none; d=zohomail.com; s=zohoarc; b=F+02JBKwB77bC0NVuEUrxgWuIqjkyJrpWfOti4U1k0a6ckjQR3tEfIE7p0vuLwwcDWOUq13u75watrEDvveAk9Pot/RmcH1aVNN7qOoRf+ZMQTMnpIbU8QAeZijtC0El/g8ViogZMYoOoIKXwo4wO7g1xB+xqdrc/QY+SGgT/RU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729805517; 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=kQuiqCDFP7O6dGnJw0uzIfXFNnqGc/QZrj0NrKoRZoA=; b=c6SFWzqZTDXOFYm1RnlOlGSROkN92ln0+Q2p/X+uzpx19r+bzJg2BKLi0ErZ/cwMlGcD4oXKrmVKPMraDj448X6b+XWPxDFfqzjvoYVZYdh5zD/dFLARWV0NgYDlDrX6DYxjXfEC1LyoclLt1GOSeZASVGz0ICyDxg8d/3NW1gI= 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 1729805517546880.8803545094609; Thu, 24 Oct 2024 14:31:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t45QJ-0005et-Nz; Thu, 24 Oct 2024 17:31:16 -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 1t45QD-0005dK-7v for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:09 -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 1t45Q8-0005X4-Ab for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:07 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-115-i2T0jw7OPSqRnFb0-FQumA-1; Thu, 24 Oct 2024 17:31:01 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-460afc4747bso26777841cf.0 for ; Thu, 24 Oct 2024 14:31:01 -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 d75a77b69052e-460d3c3a434sm55465091cf.19.2024.10.24.14.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 14:30:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729805463; 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=kQuiqCDFP7O6dGnJw0uzIfXFNnqGc/QZrj0NrKoRZoA=; b=dapSrsSveM0iMTkcX1KDAJQut2OaUhp5eJXyNMjgLIALxraleysE03Rk1rNdV6rMzWiV/1 +jhEUj+wLBVC+3X99gXGDAvsBLxvQHPdIMTY3SSMY6DaSrUMNIXEnNxafhWu2Ci/DH3sV4 f4UoIjEvGQHycrNLR1TPonpnbC+8jQ4= X-MC-Unique: i2T0jw7OPSqRnFb0-FQumA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729805461; x=1730410261; 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=kQuiqCDFP7O6dGnJw0uzIfXFNnqGc/QZrj0NrKoRZoA=; b=KsCCkVVM8Q5HwBAwVS3EHPiKf9i6oeFOxTc2/flXkHwdfnBFE14pIN4FbB5oOFfyiY DyEmvKksMOfZkKHoalsQahFGSqFtVGnVCgTLCVNsCPLQ17agG8Rg/MNNL5NJDd/QyzE/ wKrjnw8JH7DVD2LBDVyLh6hgxhMr2lVUf3ZafXuc/zE/gtsggGmnkFbCNemLNgwQG4nP 7UWoDtLmIhygVTlmlaC8dUt1DzzITiV3a+VkRg48QeWo4yP4/X7YpTcGF60lRDL8qPvy sjJcpznZz4BwPi6EIg5bJCoIzKTrlSS5nOo+aGZbUqgjVCsy5x0Y73qLPWtGQuEk3LMs 5/kA== X-Gm-Message-State: AOJu0Yw2MU/Oc3bUeLJq+sXvwUqeHCPPhVWKYblGTSshJaMuo7u9WQii BpqP4m64OXrPHfTYAFQFWKXa1KV+31LFFuKaWWN/00aVpHKIRyd4Mip3YLZyTuRrH2T3F0AXzIz ehhhOC6og+8QWOFzcZJ0zStYYts/O4PZBQfOQrQ5TAAvva9dX6A+NeayoI/JCeGe+KIE+dk1G7j 4wB7hy4NFc98yFQ0qBWVMVpeQ9ghllSGDXMA== X-Received: by 2002:a05:622a:1992:b0:460:a82a:39c9 with SMTP id d75a77b69052e-4612525f1d1mr52367221cf.10.1729805460731; Thu, 24 Oct 2024 14:31:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHs0Kkco9NPHLR6DyTeQgaXjiAae4BYQ7N0k1m99KfGVb8p8HZ/bVQIkjtE0mJV4IjUFEz3vQ== X-Received: by 2002:a05:622a:1992:b0:460:a82a:39c9 with SMTP id d75a77b69052e-4612525f1d1mr52366921cf.10.1729805460308; Thu, 24 Oct 2024 14:31:00 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , peterx@redhat.com, Fabiano Rosas , Alex Williamson Subject: [PATCH v3 1/8] migration: Take migration object refcount earlier for threads Date: Thu, 24 Oct 2024 17:30:49 -0400 Message-ID: <20241024213056.1395400-2-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241024213056.1395400-1-peterx@redhat.com> References: <20241024213056.1395400-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: 1729805519573116600 Content-Type: text/plain; charset="utf-8" Both migration thread or background snapshot thread will take a refcount of the migration object at the entrace of the thread function. That makes sense, because it protects the object from being freed by the main thread in migration_shutdown() later, but it might still race with it if the thread is scheduled too late. Consider the case right after pthread_create() happened, VM shuts down with the object released, but right after that the migration thread finally got created, referencing MigrationState* in the opaque pointer which is already freed. The only 100% safe way to make sure it won't get freed is taking the refcount right before the thread is created, meanwhile when BQL is held. Signed-off-by: Peter Xu Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Fabiano Rosas --- migration/migration.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 74812ca785..e82ffa8cf3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3491,7 +3491,6 @@ static void *migration_thread(void *opaque) =20 rcu_register_thread(); =20 - object_ref(OBJECT(s)); update_iteration_initial_status(s); =20 if (!multifd_send_setup()) { @@ -3629,7 +3628,6 @@ static void *bg_migration_thread(void *opaque) int ret; =20 rcu_register_thread(); - object_ref(OBJECT(s)); =20 migration_rate_set(RATE_LIMIT_DISABLED); =20 @@ -3841,6 +3839,14 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) } } =20 + /* + * Take a refcount to make sure the migration object won't get freed by + * the main thread already in migration_shutdown(). + * + * The refcount will be released at the end of the thread function. + */ + object_ref(OBJECT(s)); + if (migrate_background_snapshot()) { qemu_thread_create(&s->thread, MIGRATION_THREAD_SNAPSHOT, bg_migration_thread, s, QEMU_THREAD_JOINABLE); --=20 2.45.0 From nobody Sat Nov 23 18:12:41 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=1729805548; cv=none; d=zohomail.com; s=zohoarc; b=O8/uQQsNmCGeGv4LNCnZ0krEtUoJ/0BbUd/KYirC3kIlxX+4n/o1brP5yolid0gKuVLFENA+5h6gGD5+0riPpmCKx4/Vda3V/5wYU3jJKrAe4nol2sPRXgnq09zmEdqm80yySclqAIkzHOLmrM+7npGvbtks0jr+KXn5VR79ZNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729805548; 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=EWRyd4OZJ6jBP8fA6DWDgLSRD9yOdT4Rv9GVAf37TEgnlqshZtWMSjQ9UK7VRNKBO2uY52lguDsUFUYHwCSyboYAsihdeynOC5bnV2FMnEjrgzzsyeJoYDouogaC6jh3QyBEY/eYGTcnxD7xoO5hgiQQzfje+zfIcQ/UdIN9rJk= 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 1729805548652118.88486900154021; Thu, 24 Oct 2024 14:32:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t45QM-0005gR-7Y; Thu, 24 Oct 2024 17:31:18 -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 1t45QF-0005dY-Ob for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:13 -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 1t45QB-0005XZ-UF for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:10 -0400 Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-449-wAFJxnQiMJimptAh-OgsPw-1; Thu, 24 Oct 2024 17:31:04 -0400 Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-4a470b7ff49so444714137.2 for ; Thu, 24 Oct 2024 14:31:04 -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 d75a77b69052e-460d3c3a434sm55465091cf.19.2024.10.24.14.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 14:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729805465; 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=g9FugSj754VdO0tswSuKFzQkHiQ9Z3LRern8Xx42cEF67rDHwoqo074Ue6UN0xdan9Q8J7 c1d3gw/dqq/c+u+e3L08KEUNTohvxM6B4KPPh1Oqy7aX9yn7npjCqBJIAO82I9BZQEHKt4 pzV5hEL5UF6AH591Me4VScjBfpl9UTM= X-MC-Unique: wAFJxnQiMJimptAh-OgsPw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729805463; x=1730410263; 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=dxfVcMUWk+a2pFY2IVTg8JFuDC9hXFrNlMKTQqZdzg/6qfCCmpEULNOK3JwW4U2MGy pni/m+xocAyYQBRQuzR7ho7PJBD9+/c4fev+Wd41dug0OGI8RM7w2MDFPKC+Bz5I1dZS UMgxcppSvyVJ2ojusfaJ/wt/P9wGoSoTihicche1d9bI1ojGUIkGAXmshLD1kHMEYItO LLzNMJlhrZq0UU/tYipYMP5a4OykTEnOIhJIQmHSOoNMRyafy9prFtfVXaCRvM9R+ORo Z7x8mAN4sxFsfitTQJ+cIRkQISGCXQ4UcuA0Tq4bfXCH2ZWw7UzJ/L9/jAyEieH36t0b XULQ== X-Gm-Message-State: AOJu0YwJEgj0uCECyR8DpJrqcZ6ET2djphLdK4pKO2A+9uBDJf58HlIh CdA1AS4GtGD6lfa+OGE/fAIoxz83cb2qS9xX9YNMCxhfliUUCMAkp9u7ein8RstQD8t3cElVc/x DVHBX2W0i4f0P53bfKk8t3JgUVcruuz5ObfzF8WTmyufT93VTNnaZepzbMOfEoUUeNun1DmqmDS dzTHs0/51Aw5QgH52sSTQnf/9IM05rEfScsA== X-Received: by 2002:a05:6102:955:b0:4a7:4900:4b83 with SMTP id ada2fe7eead31-4a751c0b89cmr9617324137.15.1729805462797; Thu, 24 Oct 2024 14:31:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEB6u934XPonhdzpQjPiG5vkxK3ZjOKaQEkToJjnesu6BmSqva8uW+Wru+VQEuSP6n9jWapow== X-Received: by 2002:a05:6102:955:b0:4a7:4900:4b83 with SMTP id ada2fe7eead31-4a751c0b89cmr9617289137.15.1729805462382; Thu, 24 Oct 2024 14:31:02 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , peterx@redhat.com, Fabiano Rosas , Alex Williamson Subject: [PATCH v3 2/8] migration: Unexport dirty_bitmap_mig_init() Date: Thu, 24 Oct 2024 17:30:50 -0400 Message-ID: <20241024213056.1395400-3-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241024213056.1395400-1-peterx@redhat.com> References: <20241024213056.1395400-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: 1729805549434116600 It's only used within migration/, so it shouldn't be exported. Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 18:12:41 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=1729805583; cv=none; d=zohomail.com; s=zohoarc; b=dl+e4zaCiU9+1kpw9p6QjUqKgkXS/StTkaovltuNL/Ho4TNV+389Cttrt1sOWPhPchPYwvD3ap0he/s9BAlP55tE6fwRmPZwah0vLegfVfqc04yrd6CA7xa0wzRnI1RJHlxU/+7TseL/BuzMylATkCInr0LYPiCT6+2F7loqd80= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729805583; 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=h5qDUbT0oI/ii3wep25YhtJ0lpIyWNP4aqcokwUdLXo=; b=JC58lgL9F6R7qzXTMQIaw4L2pt2xA66qxiL2MlwZFw492JNylgLP/nr3Gm4AI5npywISRkMYc5i90HcqF4urTdnrAMVQNsutmClxaMa0ejBJzBzs3l6j/p70vNA0W1hXTTHGc1yy3OE5mLLCkjTRCX3wCBWSD2hffs5WY/ANnR0= 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 1729805583259912.3726702171848; Thu, 24 Oct 2024 14:33:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t45QL-0005fE-8R; Thu, 24 Oct 2024 17:31:17 -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 1t45QF-0005dX-OP for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:13 -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 1t45QC-0005YA-Vu for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:10 -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-441-rHNI_zGZN3OM1ViNBm0c7g-1; Thu, 24 Oct 2024 17:31:06 -0400 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-460dd31b4c1so20491691cf.1 for ; Thu, 24 Oct 2024 14:31:06 -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 d75a77b69052e-460d3c3a434sm55465091cf.19.2024.10.24.14.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 14:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729805467; 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=h5qDUbT0oI/ii3wep25YhtJ0lpIyWNP4aqcokwUdLXo=; b=V3XPPWa/RwDQXoZZ1GmjkzSlKSBoLMJIywQJpkcOw1GDB2Od5ClJBaELjO3jm/caqScHCb WIpcBmNmXMfYTmFwGN0M+MldlyLDsLTBfXSMOWUany21KAM2RWS5GTgfwV10hDtny7B2Wa bJRsXoL3yKlud/1tdtSXhgtEOc9/6ZA= X-MC-Unique: rHNI_zGZN3OM1ViNBm0c7g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729805465; x=1730410265; 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=h5qDUbT0oI/ii3wep25YhtJ0lpIyWNP4aqcokwUdLXo=; b=RbmDk25tLd52eTskvKqWIHWKT64MnvANl6PwqYxjlhXw5MeocRJYwL9/dN0Dw3yokC 0F488vRr7BadMAF9XhZNSd93Jy0/WhlFoTLk0EUXPniEv0348EhnPVjwbAvGajWAPjoc xmcPxKkgwhBK77AH8aiQoVa+1AcroV09/ScDfHvU5K3Wi/rNDJD5L854Kk5yXIDzCKFb qH/r0eON95r+RXH3ylGRGYnn58LFZ7GBc70wE0acGXpzkFEB39vrHJzH0M8ilFPooVBR nMiv0RFMImoFlmrNGoTt9UtbGXUHXkDBZDbQLNQuRSBtgHlCBAcP2TFEuv26JPl39AEe Y8eg== X-Gm-Message-State: AOJu0YzuL+fwXoRpuSygfeAZZtGSHs1iEmdStxRrMfloL6KlQPut3vGd ooQEARPVUi+X68T+l/DhHg3w0QI/vWvG9zYhuQ8W1mz/+HQR86wCC7o5dQdy4Ianyz3q3tlfrgN RwgnnEMQaNIJJd1RgQnaQzEpd2RgcGCZ+i5LNpkT667ZpiJYT48CR92MIMK70aUjH8VJP+r3UPQ vXKhuPi8WBT22+axOB5vXY5zinkfatNZH/FA== X-Received: by 2002:a05:622a:14cc:b0:45e:ff67:e058 with SMTP id d75a77b69052e-46114715486mr89951351cf.44.1729805464947; Thu, 24 Oct 2024 14:31:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9Ya/zv4qjiQLCLXoG1QByfJGhOsaXZRQq+Kw5POUEhex2J1GYkXh31NxoWNv1VOfKsrT/Sw== X-Received: by 2002:a05:622a:14cc:b0:45e:ff67:e058 with SMTP id d75a77b69052e-46114715486mr89951091cf.44.1729805464543; Thu, 24 Oct 2024 14:31:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , peterx@redhat.com, Fabiano Rosas , Alex Williamson Subject: [PATCH v3 3/8] migration: Unexport ram_mig_init() Date: Thu, 24 Oct 2024 17:30:51 -0400 Message-ID: <20241024213056.1395400-4-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241024213056.1395400-1-peterx@redhat.com> References: <20241024213056.1395400-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: 1729805583572116600 Content-Type: text/plain; charset="utf-8" It's only used within migration/. Signed-off-by: Peter Xu Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Fabiano Rosas --- include/migration/misc.h | 1 - migration/ram.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index df57be6b5e..e8490e3af5 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -39,7 +39,6 @@ void precopy_add_notifier(NotifierWithReturn *n); void precopy_remove_notifier(NotifierWithReturn *n); int precopy_notify(PrecopyNotifyReason reason, Error **errp); =20 -void ram_mig_init(void); void qemu_guest_free_page_hint(void *addr, size_t len); bool migrate_ram_is_ignored(RAMBlock *block); =20 diff --git a/migration/ram.h b/migration/ram.h index bc0318b834..0d1981f888 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -44,6 +44,7 @@ extern XBZRLECacheStats xbzrle_counters; INTERNAL_RAMBLOCK_FOREACH(block) \ if (!qemu_ram_is_migratable(block)) {} else =20 +void ram_mig_init(void); int xbzrle_cache_resize(uint64_t new_size, Error **errp); uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); --=20 2.45.0 From nobody Sat Nov 23 18:12:41 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=1729805517; cv=none; d=zohomail.com; s=zohoarc; b=e/zedlfg5RXqP1DgZsn/8zTUV8tJ5v2ajYKAQHrSPshrdGNRTqxDbSTJVEO3z6H1h3ezhKPzNxFmFanZFct7iSNMxZLNs4UymrraiDP1xJqK6jG/+07mg3VuX8TFcRIDBS5VjCXjAOzEcV4hOld+sVqWbHOoMUfzCDnGuQ2AwDw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729805517; 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=3olLJmt75jk+FJwxKOAC+XSuUICRdqFmF+p2v48vhJw=; b=FA1fGgNUyRVeHNFs8vYnvdxHyaaA87t3AA/dCrfRpmwJFCj4MnfGHt55zu2ZKG4AzpkkoI3xOfiEuFF8swuRvhGZc4vIKdaL0dViTV7iLA9baHzzZtJtkwMF4uGLkv4ffCVU4DWKpzrGUYfHJe3iFmNEVgYqpfZaT4MjYnMwg/c= 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 172980551728932.541080257691874; Thu, 24 Oct 2024 14:31:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t45QK-0005fC-UT; Thu, 24 Oct 2024 17:31:16 -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 1t45QH-0005eC-F7 for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:13 -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 1t45QE-0005Yn-2w for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:12 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-DohlQ0LmOmKiiaBxkhuYYw-1; Thu, 24 Oct 2024 17:31:08 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-460b638b668so20330341cf.0 for ; Thu, 24 Oct 2024 14:31:08 -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 d75a77b69052e-460d3c3a434sm55465091cf.19.2024.10.24.14.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 14:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729805469; 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=3olLJmt75jk+FJwxKOAC+XSuUICRdqFmF+p2v48vhJw=; b=SCpGLYdXndl5HlztTUyUbQy1cdcSz7SS1N+15C6o/UOTw/GnamUCoAsV+RLQHBuE7YynrI epmMmym9OBDNfdykG3lwxrsFT29gQJpCpg1fRXJirK8SvpfnAENUwSs2AF/K1pyVOmj9iy cL6EK3w+OwNh8pbSfymbms22t2C3aZo= X-MC-Unique: DohlQ0LmOmKiiaBxkhuYYw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729805467; x=1730410267; 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=3olLJmt75jk+FJwxKOAC+XSuUICRdqFmF+p2v48vhJw=; b=Bup7Rtu7fkFzWaHUHJ9PyA2aFX1H3oAWDh5wkX5evOI1sPz5+Bi/sQceGYTQgGCR5U y6JmHWfPThS/y3pM9luwBB9pny4lxSYCL5Rora3LkGCr6BW2ILAAKAps2OxgX9L/TU+4 FLhp4nMV1gqf0y5ycCf0LCY+VCIEJJ1RYcDo+l2F47yjuNrgieNPfNLSJ1lr0xQXLutn ptUcQP81BYlkHImMOVVvmqHW8kkggnaFONZV8JTJOEO15rQCdpgbWIU8FT6ou7sanSJz 4TrhP8P2PI02sOFcBJuN7G1EX57xyacos/mft4PfCbC1S3BXm0cbgqG87El9j0gNS8yS qEIA== X-Gm-Message-State: AOJu0YyJacr1vMhd7r0+e8UpPj+adF2dCTVr6pyDdZ9i/sjN19wkrvJ/ kuefvTnLKJOguuUaNEZ0d01rstraGepTAfJDW5T0vbXq+pgni+9WDMSEbeAUEsXoKGwRenmtIPt 5+g9KbvOGvcdbzHfxw7fZNohxb+lbjvZI3RapTzgTIYhPazbtZuMYlJ2G+CZYVO3l7DOROtXCO7 sTAVplX/THRymhXJH6aSfC6Rm2I0RuPnBzQw== X-Received: by 2002:a05:622a:1109:b0:461:1474:2059 with SMTP id d75a77b69052e-461258e3428mr42551471cf.13.1729805466804; Thu, 24 Oct 2024 14:31:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEM4IdpNMXK7juRo68WjGvXa/gEzd365qeeAJM4Omi4FyNvz10hSvFKOb2LsgeFi0qVUeGcmQ== X-Received: by 2002:a05:622a:1109:b0:461:1474:2059 with SMTP id d75a77b69052e-461258e3428mr42551191cf.13.1729805466487; Thu, 24 Oct 2024 14:31:06 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , peterx@redhat.com, Fabiano Rosas , Alex Williamson Subject: [PATCH v3 4/8] migration: Drop migration_is_setup_or_active() Date: Thu, 24 Oct 2024 17:30:52 -0400 Message-ID: <20241024213056.1395400-5-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241024213056.1395400-1-peterx@redhat.com> References: <20241024213056.1395400-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: 1729805520385116600 Content-Type: text/plain; charset="utf-8" This helper is mostly the same as migration_is_running(), except that one has COLO reported as true, the other has CANCELLING reported as true. Per my past years experience on the state changes, none of them should matter. To make it slightly safer, report both COLO || CANCELLING to be true in migration_is_running(), then drop the other one. We kept the 1st only because the name is simpler, and clear enough. Signed-off-by: Peter Xu Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Fabiano Rosas --- include/migration/misc.h | 4 ++-- hw/vfio/common.c | 2 +- migration/migration.c | 35 +++-------------------------------- migration/ram.c | 5 ++--- net/vhost-vdpa.c | 3 +-- 5 files changed, 9 insertions(+), 40 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index e8490e3af5..86ef160f19 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -52,11 +52,12 @@ void dump_vmstate_json_to_file(FILE *out_fp); /* migration/migration.c */ void migration_object_init(void); void migration_shutdown(void); + bool migration_is_idle(void); bool migration_is_active(void); bool migration_is_device(void); +bool migration_is_running(void); bool migration_thread_is_self(void); -bool migration_is_setup_or_active(void); =20 typedef enum MigrationEventType { MIG_EVENT_PRECOPY_SETUP, @@ -95,7 +96,6 @@ void migration_add_notifier_mode(NotifierWithReturn *noti= fy, MigrationNotifyFunc func, MigMode mode); =20 void migration_remove_notifier(NotifierWithReturn *notify); -bool migration_is_running(void); void migration_file_set_error(int ret, Error *err); =20 /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */ diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 36d0cf6585..dcef44fe55 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -149,7 +149,7 @@ bool vfio_viommu_preset(VFIODevice *vbasedev) =20 static void vfio_set_migration_error(int ret) { - if (migration_is_setup_or_active()) { + if (migration_is_running()) { migration_file_set_error(ret, NULL); } } diff --git a/migration/migration.c b/migration/migration.c index e82ffa8cf3..3365195def 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1116,33 +1116,6 @@ void migrate_send_rp_resume_ack(MigrationIncomingSta= te *mis, uint32_t value) migrate_send_rp_message(mis, MIG_RP_MSG_RESUME_ACK, sizeof(buf), &buf); } =20 -/* - * Return true if we're already in the middle of a migration - * (i.e. any of the active or setup states) - */ -bool migration_is_setup_or_active(void) -{ - MigrationState *s =3D current_migration; - - switch (s->state) { - case MIGRATION_STATUS_ACTIVE: - case MIGRATION_STATUS_POSTCOPY_ACTIVE: - case MIGRATION_STATUS_POSTCOPY_PAUSED: - case MIGRATION_STATUS_POSTCOPY_RECOVER_SETUP: - case MIGRATION_STATUS_POSTCOPY_RECOVER: - case MIGRATION_STATUS_SETUP: - case MIGRATION_STATUS_PRE_SWITCHOVER: - case MIGRATION_STATUS_DEVICE: - case MIGRATION_STATUS_WAIT_UNPLUG: - case MIGRATION_STATUS_COLO: - return true; - - default: - return false; - - } -} - bool migration_is_running(void) { MigrationState *s =3D current_migration; @@ -1158,11 +1131,10 @@ bool migration_is_running(void) case MIGRATION_STATUS_DEVICE: case MIGRATION_STATUS_WAIT_UNPLUG: case MIGRATION_STATUS_CANCELLING: + case MIGRATION_STATUS_COLO: return true; - default: return false; - } } =20 @@ -1661,8 +1633,7 @@ bool migration_incoming_postcopy_advised(void) =20 bool migration_in_bg_snapshot(void) { - return migrate_background_snapshot() && - migration_is_setup_or_active(); + return migrate_background_snapshot() && migration_is_running(); } =20 bool migration_is_idle(void) @@ -2335,7 +2306,7 @@ static void *source_return_path_thread(void *opaque) trace_source_return_path_thread_entry(); rcu_register_thread(); =20 - while (migration_is_setup_or_active()) { + while (migration_is_running()) { trace_source_return_path_thread_loop_top(); =20 header_type =3D qemu_get_be16(rp); diff --git a/migration/ram.c b/migration/ram.c index d284f63854..5646a0b882 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2860,7 +2860,7 @@ void qemu_guest_free_page_hint(void *addr, size_t len) size_t used_len, start, npages; =20 /* This function is currently expected to be used during live migratio= n */ - if (!migration_is_setup_or_active()) { + if (!migration_is_running()) { return; } =20 @@ -3208,8 +3208,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } =20 out: - if (ret >=3D 0 - && migration_is_setup_or_active()) { + if (ret >=3D 0 && migration_is_running()) { if (migrate_multifd() && migrate_multifd_flush_after_each_section(= ) && !migrate_mapped_ram()) { ret =3D multifd_ram_flush_and_sync(); diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 46b02c50be..231b45246c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -375,8 +375,7 @@ static int vhost_vdpa_net_data_start(NetClientState *nc) =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); =20 - if (s->always_svq || - migration_is_setup_or_active()) { + if (s->always_svq || migration_is_running()) { v->shadow_vqs_enabled =3D true; } else { v->shadow_vqs_enabled =3D false; --=20 2.45.0 From nobody Sat Nov 23 18:12:41 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=1729805576; cv=none; d=zohomail.com; s=zohoarc; b=iMmVelP1cZGcnHIimrT84tscQ8IRtcmWtaxlb6naYJhOuZWUDMBk+JAmyzOgQ8jeIruBVb1MlZEYgGD2XpsfwjvhOU2/Apr2unabqThf0hbxxZ+2rjnVwWPqa3Na+aJ/A/s4obBb9qpcJO5SSY4xgNqSe39PQ8TlddRB4W/IpiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729805576; 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=/6k9K1F4sWItx0KAORYMPzbNGOJ+dvY3NLwf36xd2l4=; b=OseVToL3i+Ark0xhzqWdISm0nc3HGfbBHW4IGIs8krUxKGcbVYPIq+LXki64JmD9XnaL1fiOspjSM7WSXSfrcEoltf+JWrJp9XCOBCHsrbc3BxaTcZKuDkGOZdAdf0pZzsf47eQ47Catr0iJODvCsu4yANoF4oSy4vyGJFHWnVw= 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 1729805576178302.4970438975803; Thu, 24 Oct 2024 14:32:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t45QL-0005fM-Cp; Thu, 24 Oct 2024 17:31:17 -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 1t45QJ-0005ev-OS for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:16 -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 1t45QH-0005Z8-7O for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:15 -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-414-lCTRQEExPbCnVSwUuNEi6w-1; Thu, 24 Oct 2024 17:31:10 -0400 Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-7181ca4eca5so1553388a34.1 for ; Thu, 24 Oct 2024 14:31:10 -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 d75a77b69052e-460d3c3a434sm55465091cf.19.2024.10.24.14.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 14:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729805472; 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=/6k9K1F4sWItx0KAORYMPzbNGOJ+dvY3NLwf36xd2l4=; b=YykItHm2JTlA62fZcwT4rSeS20FbAnVkwhA1vOxUAzu5s0ssM6SV9SNuTgZBKiL5t0d9TM Ca0fbJIhZFr48jOmCJS6H9gZx1W8bys32A/0JuI/JwYSPmPtrsXyrSys2dWCvf7VBEL5ou QZNdYW1tPhIPfP+0rtK7ASEYfIJKlTI= X-MC-Unique: lCTRQEExPbCnVSwUuNEi6w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729805469; x=1730410269; 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=/6k9K1F4sWItx0KAORYMPzbNGOJ+dvY3NLwf36xd2l4=; b=p5pG+18ShGulXr5pWdxFwLdIF3cJX502hA/aYMMHq0PbFTOMozcUtwD9fgeVX+Y8Oc EdsGnkk9cNYkl32DeGc4R32NGYN65zRJTAnwF/0CvYDTESN++EvdeLlUVeT35X7jKuje LuElrANuIYyGQuFOdy6AUHFGrUy3cXBM55xM4QO3tuAUU1K/fcv/8wRERSzqf307GI+F yOFoYdjZVEwynLsTBheyhM1JQcczteZmIhmN2+DqmuU9ArRBTe8MpogiYicKROSR2pae yQR8vOI+wsNE2ryAU8gKGzUw2XBXQDnN/POoj1TSi7yNombmpDFiCM0hWeyNv6MGFxE5 Djxw== X-Gm-Message-State: AOJu0Yzv0s6N7NGei40HRQIjWXjxJnHTABdZc0OA0sAiJWydEL53Rwyg QGt7mRAIUEs1Oe4s9lD61svKpsUr9AWC/MphiEcnYEnHm02Rqt+L6CK75Sz1YNbVdMDgawXn2El U9OqDHHQcithz0MgWNrkERVoXarKhtwvKWmh+ks1UG+A35J+VghEwdmPrBCr2EzcWZLZW+B0EhT JVJlPZIfqTm1hpXLjzJ6VE40nyzpfMfCNe2A== X-Received: by 2002:a05:6358:7211:b0:197:df0e:f23c with SMTP id e5c5f4694b2df-1c3e4d1fd0emr265778355d.11.1729805468913; Thu, 24 Oct 2024 14:31:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgNXyX+9BUC5E8HTotTZ7ubI6ph201MDCgEpTCL2YHdpRoHyl6p9kTRr3NCUYtR5o+uY242w== X-Received: by 2002:a05:6358:7211:b0:197:df0e:f23c with SMTP id e5c5f4694b2df-1c3e4d1fd0emr265776055d.11.1729805468481; Thu, 24 Oct 2024 14:31:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , peterx@redhat.com, Fabiano Rosas , Alex Williamson Subject: [PATCH v3 5/8] migration: Drop migration_is_idle() Date: Thu, 24 Oct 2024 17:30:53 -0400 Message-ID: <20241024213056.1395400-6-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241024213056.1395400-1-peterx@redhat.com> References: <20241024213056.1395400-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: 1729805577750116600 Content-Type: text/plain; charset="utf-8" Now with the current migration_is_running(), it will report exactly the opposite of what will be reported by migration_is_idle(). Drop migration_is_idle(), instead use "!migration_is_running()" which should be identical on functionality. In reality, most of the idle check is inverted, so it's even easier to write with "migrate_is_running()" check. Signed-off-by: Peter Xu Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Fabiano Rosas --- include/migration/misc.h | 1 - hw/virtio/virtio-mem.c | 2 +- migration/migration.c | 21 +-------------------- migration/ram.c | 2 +- system/qdev-monitor.c | 4 ++-- 5 files changed, 5 insertions(+), 25 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index 86ef160f19..804eb23c06 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -53,7 +53,6 @@ void dump_vmstate_json_to_file(FILE *out_fp); void migration_object_init(void); void migration_shutdown(void); =20 -bool migration_is_idle(void); bool migration_is_active(void); bool migration_is_device(void); bool migration_is_running(void); diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index ae1e81d7ba..80ada89551 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -188,7 +188,7 @@ static bool virtio_mem_is_busy(void) * after plugging them) until we're running on the destination (as we = didn't * migrate these blocks when they were unplugged). */ - return migration_in_incoming_postcopy() || !migration_is_idle(); + return migration_in_incoming_postcopy() || migration_is_running(); } =20 typedef int (*virtio_mem_range_cb)(VirtIOMEM *vmem, void *arg, diff --git a/migration/migration.c b/migration/migration.c index 3365195def..f86c709699 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1636,25 +1636,6 @@ bool migration_in_bg_snapshot(void) return migrate_background_snapshot() && migration_is_running(); } =20 -bool migration_is_idle(void) -{ - MigrationState *s =3D current_migration; - - if (!s) { - return true; - } - - switch (s->state) { - case MIGRATION_STATUS_NONE: - case MIGRATION_STATUS_CANCELLED: - case MIGRATION_STATUS_COMPLETED: - case MIGRATION_STATUS_FAILED: - return true; - default: - return false; - } -} - bool migration_is_active(void) { MigrationState *s =3D current_migration; @@ -1733,7 +1714,7 @@ static bool is_busy(Error **reasonp, Error **errp) ERRP_GUARD(); =20 /* Snapshots are similar to migrations, so check RUN_STATE_SAVE_VM too= . */ - if (runstate_check(RUN_STATE_SAVE_VM) || !migration_is_idle()) { + if (runstate_check(RUN_STATE_SAVE_VM) || migration_is_running()) { error_propagate_prepend(errp, *reasonp, "disallowing migration blocker " "(migration/snapshot in progress) for: "); diff --git a/migration/ram.c b/migration/ram.c index 5646a0b882..504b48d584 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4498,7 +4498,7 @@ static void ram_mig_ram_block_resized(RAMBlockNotifie= r *n, void *host, return; } =20 - if (!migration_is_idle()) { + if (migration_is_running()) { /* * Precopy code on the source cannot deal with the size of RAM blo= cks * changing at random points in time - especially after sending the diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 1310f35c9f..83fa684475 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -686,7 +686,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, return NULL; } =20 - if (!migration_is_idle()) { + if (migration_is_running()) { error_setg(errp, "device_add not allowed while migrating"); return NULL; } @@ -935,7 +935,7 @@ void qdev_unplug(DeviceState *dev, Error **errp) return; } =20 - if (!migration_is_idle() && !dev->allow_unplug_during_migration) { + if (migration_is_running() && !dev->allow_unplug_during_migration) { error_setg(errp, "device_del not allowed while migrating"); return; } --=20 2.45.0 From nobody Sat Nov 23 18:12:41 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=1729805559; cv=none; d=zohomail.com; s=zohoarc; b=n2iO0gjN4KbiOm9yEWeOXq/ZmpacAWE22Ii+r3uZpPh1+7HY7LsgkJKuRGQauR145DA4aDvslxMMPubzE0F/txPY/MHNTKweFvzZCCjI3wP0eJSQaT1DvXa7fs0Y6NCe8S4k30vhCRw7H2S9PM1Ehy8kbYzBmrTQnqyXYi4oHAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729805559; 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=/6xFER4Y5so64URVhMy+JgrIVvXPCbxhauceydNM1kE=; b=BhkJEfKoQpBRzKMc49/xq93z9UOUmEJ/AYjDbodPkIAqN88pS3huHMN/stZwn56Rf61NR9zEZ9d4HT9Mmp4WK3ON5BaUOnLxlwq7LqrTCJqZJWvCRgP18pYnY9vPmMh8WXLJF8EoqizhpKFQDERuiYqF0IH7Wt0fA5cl9wHbVrw= 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 1729805559687300.53955349471187; Thu, 24 Oct 2024 14:32:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t45QO-0005ht-Qy; Thu, 24 Oct 2024 17:31:20 -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 1t45QK-0005fD-T8 for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:16 -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 1t45QJ-0005ZT-1z for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:16 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-224-ZPrxl4qHM9yPLOi-VXapIw-1; Thu, 24 Oct 2024 17:31:12 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-460dd31b4c1so20493181cf.1 for ; Thu, 24 Oct 2024 14:31:12 -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 d75a77b69052e-460d3c3a434sm55465091cf.19.2024.10.24.14.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 14:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729805473; 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=/6xFER4Y5so64URVhMy+JgrIVvXPCbxhauceydNM1kE=; b=aEUkbczaE/9ZbE1sFFayZ2r0Hsg/rJ6zYpd4rh4oDDsSytHG7DCLpfWulUJxqg/CIojFkP 8BjgO7Hwa/of/3sh2XLPX1Cu4rHUt6vidwA1DfZVg/XJ2/aIibqniWrpJ10UK4AVWyZ0FL qmPQT+jlxh+p905l35PPj0YhpOs4A7U= X-MC-Unique: ZPrxl4qHM9yPLOi-VXapIw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729805471; x=1730410271; 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=/6xFER4Y5so64URVhMy+JgrIVvXPCbxhauceydNM1kE=; b=mBQr6GrKkYfAF85STJSNzERqIC39harh9+tCMjccrYsBxRKBW5cs5EiDheNEDWzXgo 7iu7kx3UK12GE6LDfVkptZduy1rhtRbyxt3tA39xgt24IRw4fMwrsS1HSHYbbm8GryE4 StWACVE2HSFU520u/S/NTIh+L4Oeh7+9u1tUDVD4D0GKvrJXdvf65oK8IM2p4++6JXIc mtzq55VLdm0VOM0dO0Q3AKY6sLjikx04cbuAN6uwaviLY6cXHLrxyU4mMbwvfr9CZz14 Hw3vQyQ5wTmq/I9wBVaT//0gh6FyP8omxLQ7SQUYjHqB7S54o97KUxkrGJDomRacbozp OdGA== X-Gm-Message-State: AOJu0Yx4G0N1tN5fLC/vrksG9VX7F7F1QYlRjGKiEWU1Tmac/TZ7uE2C GwvAQqkxYsjpCg3vGQNETaeJScVH1aNx+z/g7sFy/62fXZiWfBK8wLH5qyTAuCa96hqrtNrUyRy 0AhgJSPXAWunpWgE7dqWqTPSGPeiwj19K87Crev31V8VcP/UEblkXqZSw8INJaEBZatQT7Smniv bq5K8nFsMQPxUTzp+gKBB1vxuSv4AUbCSu8g== X-Received: by 2002:ac8:58d4:0:b0:460:42f7:fa3f with SMTP id d75a77b69052e-461145b938fmr109750001cf.19.1729805470827; Thu, 24 Oct 2024 14:31:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3m0nKmt3RafhxwjJOPF+IsczbS53HQlvyevm7dIpOkCCIx4ascOxYgpbvG4H7ywL2aAz2vA== X-Received: by 2002:ac8:58d4:0:b0:460:42f7:fa3f with SMTP id d75a77b69052e-461145b938fmr109749621cf.19.1729805470431; Thu, 24 Oct 2024 14:31:10 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , peterx@redhat.com, Fabiano Rosas , Alex Williamson Subject: [PATCH v3 6/8] migration: Drop migration_is_device() Date: Thu, 24 Oct 2024 17:30:54 -0400 Message-ID: <20241024213056.1395400-7-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241024213056.1395400-1-peterx@redhat.com> References: <20241024213056.1395400-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: 1729805561612116600 Content-Type: text/plain; charset="utf-8" This only checks the DEVICE stage, which is a very special stage, and only checked together with ACTIVE+POSTCOPY_ACTIVE. It's debatable why this needs a separate helper just to be exported. Theoretically speaking, DEVICE stage is also part of ACTIVE stage, where we're reaching the switchover phase but waiting for some external operation, during which VM stopped but migration is definitely active. Report DEVICE as active too, then we can drop migration_is_device(). Signed-off-by: Peter Xu --- include/migration/misc.h | 1 - hw/vfio/common.c | 2 +- migration/migration.c | 19 +++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index 804eb23c06..ad1e25826a 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -54,7 +54,6 @@ void migration_object_init(void); void migration_shutdown(void); =20 bool migration_is_active(void); -bool migration_is_device(void); bool migration_is_running(void); bool migration_thread_is_self(void); =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index dcef44fe55..cc72282c71 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -174,7 +174,7 @@ static bool vfio_devices_all_dirty_tracking(VFIOContain= erBase *bcontainer) { VFIODevice *vbasedev; =20 - if (!migration_is_active() && !migration_is_device()) { + if (!migration_is_active()) { return false; } =20 diff --git a/migration/migration.c b/migration/migration.c index f86c709699..127b01734d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1638,17 +1638,16 @@ bool migration_in_bg_snapshot(void) =20 bool migration_is_active(void) { - MigrationState *s =3D current_migration; - - return (s->state =3D=3D MIGRATION_STATUS_ACTIVE || - s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE); -} + MigrationStatus state =3D current_migration->state; =20 -bool migration_is_device(void) -{ - MigrationState *s =3D current_migration; - - return s->state =3D=3D MIGRATION_STATUS_DEVICE; + switch (state) { + case MIGRATION_STATUS_ACTIVE: + case MIGRATION_STATUS_POSTCOPY_ACTIVE: + case MIGRATION_STATUS_DEVICE: + return true; + default: + return false; + } } =20 bool migration_thread_is_self(void) --=20 2.45.0 From nobody Sat Nov 23 18:12:41 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=1729805563; cv=none; d=zohomail.com; s=zohoarc; b=MGFVRVLi3ZZs42U8Bi5nXEVvmx6ZDmcTc1fCvfCr62ygrHyCnCiDbL5OscK/aqf6GybBTfggtmjVJVPeRfI+qMwA3eC7cUD6Etr+3FLNN5aaQ8xBPow8auGgEVmsPlzY6TcPfystBbmkxBICBvtswPRjXD2q0/73jhI0RxzO2hY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729805563; 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=vte9HPiXE32VhwFKsE2SGPglzqTAs5Z4orbp/UZZ2ec=; b=dABDNDwb9UB/PnjRnaIAohg38TQt/9JODAtZ0nK2Sxrx37ZChhuS2Gi/ydJOS4IAiZmMaAc/qJE9+kUr2RyLjGI6l9dgBKuAf/chFxf9mbvheM0be5+/EMEW+JLbbwqfgWWFomKFHg6Tr9G9IKwjxu98dz3IIYGtt4lKNE2CPXw= 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 1729805563567258.37555075407045; Thu, 24 Oct 2024 14:32:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t45QO-0005hN-4K; Thu, 24 Oct 2024 17:31:20 -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 1t45QL-0005fL-5D for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:17 -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 1t45QJ-0005Zg-Lx for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:16 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-401-U5Q76G8nP8-8Tjuft_Q-9g-1; Thu, 24 Oct 2024 17:31:13 -0400 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7ac9b08cb77so207102185a.1 for ; Thu, 24 Oct 2024 14:31:13 -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 d75a77b69052e-460d3c3a434sm55465091cf.19.2024.10.24.14.31.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 14:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729805475; 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=vte9HPiXE32VhwFKsE2SGPglzqTAs5Z4orbp/UZZ2ec=; b=FvaLUDRBiXJRl8ITv5yw7iRjHH2dfWuUPK1qVqALa8fPwiTQi7y+iKKiFolc49LWEIDKoz fNQVdQ5iVpEEchlwkwMdyL2rZCYu0olnvmMDb97OQn95JhSkvo90r1e4f7k68wt4pBTbyN Rc0/hSjNCwXHFtoft6YnO+q5qCAhDK0= X-MC-Unique: U5Q76G8nP8-8Tjuft_Q-9g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729805473; x=1730410273; 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=vte9HPiXE32VhwFKsE2SGPglzqTAs5Z4orbp/UZZ2ec=; b=PZclegvjxGBR1k+u4FSBBP9f0Y14oP32LrT7722FGpcYcxHwRa7Ri+2CFApMyorxJS DaWy2IGbCqEwZfbJNMK9iRae7HZffktA5Ac3PxiTBPXrpRcTgqwqZqxsON5DDjh/4xQ6 pZdaaOnr9zC9uHY3tEKNauAGnrvA6uwwjxGKBWoaBspC0HhIY7bUcPdWlByg84Hn36tK zgpRyBykPBZYqsv0QbCmYlFp3J46U2YsYJ59ONe2wri3sVGUGV1LLjgYtDaM+mHoDryz Fz5sxEki1L7/gaF3gcH4TfcZFMZrXklu2cY5h8t9aw/lggPLRsCyf2IRxPYSxuAotq6A RGtQ== X-Gm-Message-State: AOJu0YzadpGvYyUBxccNtQDDDh/mES3YMTorcPlaO7hObSpPYjgJDbm/ N9t+0h9BLze627YvXEuewJGq4HECtKb3yBmJ7+402pXN2TydDi9+0R9GD+8YbOOH2/kBIxnBjdj aM8LZF0ikjVJuLxAXCLps3jp7wSThVItHg8wlsZkB9Rem7FA6y80buw6aJz0pIoE0gop4VGWAtP mIyoRHqLI7vqD2t9bpQPPGFuwB5YNHSV8Vsw== X-Received: by 2002:ac8:5a52:0:b0:457:cab4:6e4a with SMTP id d75a77b69052e-4611471f04dmr108164791cf.37.1729805472866; Thu, 24 Oct 2024 14:31:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQOcNK9ZtKvtLWG7+ZNpte+LVc/3X0MTpv+8D7V2VzBaT08OCRfXpMgl0wZJdfENNshehb4A== X-Received: by 2002:ac8:5a52:0:b0:457:cab4:6e4a with SMTP id d75a77b69052e-4611471f04dmr108164411cf.37.1729805472410; Thu, 24 Oct 2024 14:31:12 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , peterx@redhat.com, Fabiano Rosas , Alex Williamson Subject: [PATCH v3 7/8] migration: Unexport migration_is_active() Date: Thu, 24 Oct 2024 17:30:55 -0400 Message-ID: <20241024213056.1395400-8-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241024213056.1395400-1-peterx@redhat.com> References: <20241024213056.1395400-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: 1729805565498116600 Content-Type: text/plain; charset="utf-8" We have two outside users of this API, so it's exported. Is it really necessary? Does it matter whether it must be ACTIVE/POSTCOPY_ACTIVE/DEVICE? I guess no. The external user is trying to detect whether migration is running or not, as simple as that. To make the migration_is*() APIs even shorter, let's use migration_is_running() for outside worlds. Internally there're actually three places that literally needs migration_is_active() rather than running(). Keep that an internal helper. After this patch, we finally only export one helper that allows external world to try detect migration status, which is migration_is_running(). Signed-off-by: Peter Xu --- include/migration/misc.h | 1 - migration/migration.h | 1 + hw/vfio/common.c | 4 ++-- system/dirtylimit.c | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index ad1e25826a..c0e23fdac9 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -53,7 +53,6 @@ void dump_vmstate_json_to_file(FILE *out_fp); void migration_object_init(void); void migration_shutdown(void); =20 -bool migration_is_active(void); bool migration_is_running(void); bool migration_thread_is_self(void); =20 diff --git a/migration/migration.h b/migration/migration.h index 0956e9274b..9fa26ab06a 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -492,6 +492,7 @@ int migration_call_notifiers(MigrationState *s, Migrati= onEventType type, =20 int migrate_init(MigrationState *s, Error **errp); bool migration_is_blocked(Error **errp); +bool migration_is_active(void); /* True if outgoing migration has entered postcopy phase */ bool migration_in_postcopy(void); bool migration_postcopy_is_alive(MigrationStatus state); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index cc72282c71..7eb99ebd4d 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -174,7 +174,7 @@ static bool vfio_devices_all_dirty_tracking(VFIOContain= erBase *bcontainer) { VFIODevice *vbasedev; =20 - if (!migration_is_active()) { + if (!migration_is_running()) { return false; } =20 @@ -219,7 +219,7 @@ vfio_devices_all_running_and_mig_active(const VFIOConta= inerBase *bcontainer) { VFIODevice *vbasedev; =20 - if (!migration_is_active()) { + if (!migration_is_running()) { return false; } =20 diff --git a/system/dirtylimit.c b/system/dirtylimit.c index ab20da34bb..d7a855c603 100644 --- a/system/dirtylimit.c +++ b/system/dirtylimit.c @@ -80,8 +80,7 @@ static void vcpu_dirty_rate_stat_collect(void) int i =3D 0; int64_t period =3D DIRTYLIMIT_CALC_TIME_MS; =20 - if (migrate_dirty_limit() && - migration_is_active()) { + if (migrate_dirty_limit() && migration_is_running()) { period =3D migrate_vcpu_dirty_limit_period(); } =20 --=20 2.45.0 From nobody Sat Nov 23 18:12:41 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=1729805578; cv=none; d=zohomail.com; s=zohoarc; b=Fm57oAdoSghpe7ZXzL8qB78e1cGwngQgCSi2BHoYtKnTfGHe3X4ZIIsjmhJVL+giF+j2aA+OrAvk//JmAc0jYpVgBIf1U8wpqORHzy5OJ0X+LhV1xfrlZzqIgrGPRe9uMrsAYJOsmotpvbA/St9Anu1zJ54hf01UBK+ZtLNTrRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729805578; 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=bJXamzqrq7AiFagiu9llJXewSi82uD7Ymbaq7adW03I=; b=mVg7P7pzOVrJYf4GC5kBqUaK8ddW62XDe/zZM2CRkDXMBhGclLNiX0Rly8i21s0xKCp/K/potV5Xc5k0HUFwRKbGhFRxTU87qjzs55WZnKxq6vHLvjh0OQkPY/w6Ac5cvtwgJOgQJ0axykfscP2bGDF18wTltAWmAaVV3G4O3CQ= 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 1729805578869437.40765088368903; Thu, 24 Oct 2024 14:32:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t45QQ-0005iX-Ek; Thu, 24 Oct 2024 17:31:22 -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 1t45QN-0005hR-Kt for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:20 -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 1t45QL-0005aF-Tz for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:31:19 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-541-o7G2DmmTMo-ADXYSKrWmPw-1; Thu, 24 Oct 2024 17:31:15 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-460b07774a7so21584551cf.2 for ; Thu, 24 Oct 2024 14:31:15 -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 d75a77b69052e-460d3c3a434sm55465091cf.19.2024.10.24.14.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 14:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729805477; 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=bJXamzqrq7AiFagiu9llJXewSi82uD7Ymbaq7adW03I=; b=MlqG7o+lyGN0PsuB1WNl4cAgQmJJgVcLXHcBZx7jlIGj84MZLadn0xuawu/1Boj6tCIMy5 tnoMXg5PwvCKOtivMhM3YwFiToA81vMw1FYQwjXsybYh+sq4zBu7Xudml96x98J7KPAHH+ /9tS0ApUtMztd77uUStjkp/o0hZFzgo= X-MC-Unique: o7G2DmmTMo-ADXYSKrWmPw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729805474; x=1730410274; 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=bJXamzqrq7AiFagiu9llJXewSi82uD7Ymbaq7adW03I=; b=Kdq4VnNmjgZkXc8WsrLQZEbiKl+UMHYnjN8rXW+XlyuiOu35rPBnbEHvms8SMsWunm nwzXm2JpXcjfqW/zvt+bJ5l6gPjjLQQP96INzDi6wCwcMnE03wEAkkxkcJdxY2SJNGwb UZ0qq88puM1Jtgwy6NlVwH0gEFwuoNmPpo5KYI5t+xwbH+/qovMPDlIQhj2kJHWQQh6Z Z2Onyv2UqQht1gTtsF4D4qfBgQ6gEHQkHvGfo9KN+Y7PdVDuWhbwQacOgdCjeRFly9t1 eZIi7rM1rnfB3TgJ9JJSocE/nP04weKE3qzWcO8KQA/GyG3mIF+OjbRq9PUwwy2XhHCY yt1Q== X-Gm-Message-State: AOJu0Yy6a6EKnPYDg/r5X+lVdve3ZI7dM1BjqGxBtTOKNradCctoIRGE xXU9ST/Lh7vjX83YELZ4QXmxDyj7QTUlw7r4rso6I4yxA/f/kJyCz5yuS4I3+052MpZGRpbqb0k AonPZ/J5D7748lnFIAvOYB12MTE047JnSZu5ixDb17IRt/1tZtOaPtnfXd+bCZcdF65oPg9DBrb Jtmv+NSd3DqvOC9UFg0qpqBttoxlzpoxU4OA== X-Received: by 2002:a05:622a:30b:b0:460:9a7c:8dd0 with SMTP id d75a77b69052e-46114745ea3mr102531841cf.55.1729805474459; Thu, 24 Oct 2024 14:31:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWRcFG/xreUGKLjkXNCc+1IMxAXwaEE4kuCf0QBvjEHQYqdQt1NC5dwVPkayPhJzgdunfPJg== X-Received: by 2002:a05:622a:30b:b0:460:9a7c:8dd0 with SMTP id d75a77b69052e-46114745ea3mr102531551cf.55.1729805474084; Thu, 24 Oct 2024 14:31:14 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , peterx@redhat.com, Fabiano Rosas , Alex Williamson Subject: [PATCH v3 8/8] migration: Protect updates to current_migration with a mutex Date: Thu, 24 Oct 2024 17:30:56 -0400 Message-ID: <20241024213056.1395400-9-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241024213056.1395400-1-peterx@redhat.com> References: <20241024213056.1395400-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: 1729805579655116600 Content-Type: text/plain; charset="utf-8" Introduce migration_mutex, protecting concurrent updates to current_migration. In reality, most of the exported migration functions are safe to access migration objects on capabilities, etc., e.g. many of the code is invoked within migration thread via different hooks (e.g., precopy notifier, vmstate handler hooks, etc.). So literally the mutex so far only makes sure below two APIs that are prone to accessing freed current_migration: migration_is_running() migration_file_set_error() Then we'll need to take the mutex too when init/free the migration object. Signed-off-by: Peter Xu --- migration/migration.h | 3 +++ migration/migration.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/migration/migration.h b/migration/migration.h index 9fa26ab06a..05edcf0c49 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -473,6 +473,9 @@ struct MigrationState { bool rdma_migration; }; =20 +extern QemuMutex migration_mutex; +#define QEMU_MIGRATION_LOCK_GUARD() QEMU_LOCK_GUARD(&migration_mutex) + void migrate_set_state(MigrationStatus *state, MigrationStatus old_state, MigrationStatus new_state); =20 diff --git a/migration/migration.c b/migration/migration.c index 127b01734d..ef044968df 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -97,6 +97,14 @@ enum mig_rp_message_type { migrations at once. For now we don't need to add dynamic creation of migration */ =20 +/* + * Protects current_migration below. Must be hold when using migration + * exported functions unless the caller knows it won't get freed. For + * example, when in the context of migration_thread() it's safe to access + * current_migration without the mutex, because the thread holds one extra + * refcount of the object, so it literally pins the object in-memory. + */ +QemuMutex migration_mutex; static MigrationState *current_migration; static MigrationIncomingState *current_incoming; =20 @@ -110,6 +118,17 @@ static void migrate_fd_cancel(MigrationState *s); static bool close_return_path_on_source(MigrationState *s); static void migration_completion_end(MigrationState *s); =20 +/* + * This is explicitly done without migration_object_init(), because it may + * start to use this lock already when instance_init() of the object. The + * mutex is alive for the whole lifecycle of QEMU, so it's always usable + * and never destroyed. + */ +static void __attribute__((constructor)) migration_mutex_init(void) +{ + qemu_mutex_init(&migration_mutex); +} + static void migration_downtime_start(MigrationState *s) { trace_vmstate_downtime_checkpoint("src-downtime-start"); @@ -336,6 +355,14 @@ void migration_shutdown(void) * stop the migration using this structure */ migration_cancel(NULL); + /* + * Release the refcount from the main thread. It means it can be freed + * here if migration thread is not running. + * + * NOTE: we don't need QEMU_MIGRATION_LOCK_GUARD() on this access + * because we're sure there's one refcount. The lock will be taken in + * finalize() if it triggers, so we can't take it here anyway. + */ object_unref(OBJECT(current_migration)); =20 /* @@ -1118,8 +1145,14 @@ void migrate_send_rp_resume_ack(MigrationIncomingSta= te *mis, uint32_t value) =20 bool migration_is_running(void) { + QEMU_MIGRATION_LOCK_GUARD(); + MigrationState *s =3D current_migration; =20 + if (!s) { + return false; + } + switch (s->state) { case MIGRATION_STATUS_ACTIVE: case MIGRATION_STATUS_POSTCOPY_ACTIVE: @@ -3029,8 +3062,14 @@ static MigThrError postcopy_pause(MigrationState *s) =20 void migration_file_set_error(int ret, Error *err) { + QEMU_MIGRATION_LOCK_GUARD(); + MigrationState *s =3D current_migration; =20 + if (!s) { + return; + } + WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) { if (s->to_dst_file) { qemu_file_set_error_obj(s->to_dst_file, ret, err); @@ -3835,6 +3874,8 @@ static void migration_instance_finalize(Object *obj) { MigrationState *ms =3D MIGRATION_OBJ(obj); =20 + QEMU_MIGRATION_LOCK_GUARD(); + qemu_mutex_destroy(&ms->error_mutex); qemu_mutex_destroy(&ms->qemu_file_lock); qemu_sem_destroy(&ms->wait_unplug_sem); @@ -3858,6 +3899,8 @@ static void migration_instance_init(Object *obj) { MigrationState *ms =3D MIGRATION_OBJ(obj); =20 + QEMU_MIGRATION_LOCK_GUARD(); + /* * There can only be one migration object globally. Keep a record of * the pointer in current_migration, which will be reset after the --=20 2.45.0