From nobody Sat May 18 23:14:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626896160040651.8828493383688; Wed, 21 Jul 2021 12:36:00 -0700 (PDT) Received: from localhost ([::1]:42152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6I0c-0002ry-TT for importer@patchew.org; Wed, 21 Jul 2021 15:35:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hz2-0000fv-9w for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hyz-00050o-Gt for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:19 -0400 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-563-NUyE21bGPHyucKk8u_g2hQ-1; Wed, 21 Jul 2021 15:34:15 -0400 Received: by mail-qk1-f198.google.com with SMTP id k12-20020a05620a414cb02903b9ade0af31so1812401qko.1 for ; Wed, 21 Jul 2021 12:34:15 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id 8sm10755867qkb.105.2021.07.21.12.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 12:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626896056; 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=psIdSZ42TG6zIOWJSN4HC5NZuEOzx+F89j4lZhOXZEk=; b=ixkhQ0WPmyfSs6oTtdVP9j8KZxG8pHqLg4Wp5VZdF1Nz3GjYKwGW9/iMlselX36sW4kRsP a3iqVuah0dbSwFVgKUvIMMnBcvZ7tBntESTC0pMTWnmNMBpNr+l6mg5mEiqZIeIcuxOzvI wbhS2ZH2Vhhe0db1tEKV9Q6sTF3gZoU= X-MC-Unique: NUyE21bGPHyucKk8u_g2hQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=psIdSZ42TG6zIOWJSN4HC5NZuEOzx+F89j4lZhOXZEk=; b=keb7ihhYRVqp4OSPpB76QC22hBJBSD4pA7f4AEiq7GJ6+sTyXMjShfUUlGH1DpHm/F IgFGHm54Bf9YQfN3uTP4NYJT2FQ4m9hH+D5YXZDABys/dLaghfjdIfyADT3ZkCXlH3bS 73CRPxC0erZvnRG5wZZSJfXO4cGTP/9VqvP/h05XfTg0NEPPcWSxkfHPBdSndkoGwDaW +ZJRQ7US36UZ7Coiwd+sAGOoqHnOSMfI4zOofdsmQxNXNGSvxUdC1G/RetwD8nxxqrpI h0Pux4nSjCiUfEFFanAoEOUxLztVOuHkHu4LY1O/8t5YkMr/kI7QlMzRfmE6leEGvMKF Ty4g== X-Gm-Message-State: AOAM530vuRAzheYiW1s3QUb9SgbMD3UNxJut7V5e6XKlH9qSAOZBWEbk 90QLs0X1csWuntq4CiX0GGoNUZlqibQPFK20s3e4YmddMxvkJw7zZFfxOKhr+m2q6MGd02OxXWd jaBOEe1qrwJTepxKWTLIOwpy7TDjj69oEqlm0oTd1J5edrKyb3cE2XE+O42xzNcoE X-Received: by 2002:ac8:5a12:: with SMTP id n18mr21026744qta.3.1626896054956; Wed, 21 Jul 2021 12:34:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsFAXPZSXNucehq1+QhFIKFJXNu7np77gCAiCKCpnum1qyh/SE2Qb+7ETKyuhu+/PhkpDINg== X-Received: by 2002:ac8:5a12:: with SMTP id n18mr21026717qta.3.1626896054614; Wed, 21 Jul 2021 12:34:14 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 1/5] migration: Fix missing join() of rp_thread Date: Wed, 21 Jul 2021 15:34:05 -0400 Message-Id: <20210721193409.910462-2-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721193409.910462-1-peterx@redhat.com> References: <20210721193409.910462-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.459, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Lukas Straub , "Daniel P . Berrange" , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Leonardo Bras Soares Passos Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626896160531100001 Content-Type: text/plain; charset="utf-8" It's possible that the migration thread skip the join() of the rp_thread in below race and crash on src right at finishing migration: migration_thread rp_thread ---------------- --------- migration_completion() (before rp_thread quits) from_dst_file=3DNULL [thread got scheduled out] s->rp_state.from_dst_file=3D=3DNULL (skip join() of rp_thread) migrate_fd_cleanup() qemu_fclose(s->to_dst_file) yank_unregister_instance() assert(yank_find_entry()) <------- crash It could mostly happen with postcopy, but that shouldn't be required, e.g.,= I think it could also trigger with MIGRATION_CAPABILITY_RETURN_PATH set. It's suspected that above race could be the root cause of a recent (but rar= e) migration-test break reported by either Dave or PMM: https://lore.kernel.org/qemu-devel/YPamXAHwan%2FPPXLf@work-vm/ The issue is: from_dst_file is reset in the rp_thread, so if the thread res= et it to NULL fast enough then the migration thread will assume there's no rp_thread at all. This could potentially cause more severe issue (e.g. crash) after the yank = code. Fix it by using a boolean to keep "whether we've created rp_thread". Cc: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/migration.c | 4 +++- migration/migration.h | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index 2d306582eb..21b94f75a3 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2867,6 +2867,7 @@ static int open_return_path_on_source(MigrationState = *ms, =20 qemu_thread_create(&ms->rp_state.rp_thread, "return path", source_return_path_thread, ms, QEMU_THREAD_JOINABLE= ); + ms->rp_state.rp_thread_created =3D true; =20 trace_open_return_path_on_source_continue(); =20 @@ -2891,6 +2892,7 @@ static int await_return_path_close_on_source(Migratio= nState *ms) } trace_await_return_path_close_on_source_joining(); qemu_thread_join(&ms->rp_state.rp_thread); + ms->rp_state.rp_thread_created =3D false; trace_await_return_path_close_on_source_close(); return ms->rp_state.error; } @@ -3170,7 +3172,7 @@ static void migration_completion(MigrationState *s) * it will wait for the destination to send it's status in * a SHUT command). */ - if (s->rp_state.from_dst_file) { + if (s->rp_state.rp_thread_created) { int rp_error; trace_migration_return_path_end_before(); rp_error =3D await_return_path_close_on_source(s); diff --git a/migration/migration.h b/migration/migration.h index 2ebb740dfa..c302879fad 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -195,6 +195,13 @@ struct MigrationState { QEMUFile *from_dst_file; QemuThread rp_thread; bool error; + /* + * We can also check non-zero of rp_thread, but there's no "offici= al" + * way to do this, so this bool makes it slightly more elegant. + * Checking from_dst_file for this is racy because from_dst_file w= ill + * be cleared in the rp_thread! + */ + bool rp_thread_created; QemuSemaphore rp_sem; } rp_state; =20 --=20 2.31.1 From nobody Sat May 18 23:14:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626896242162734.4064040501479; Wed, 21 Jul 2021 12:37:22 -0700 (PDT) Received: from localhost ([::1]:46896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6I1x-00065O-7O for importer@patchew.org; Wed, 21 Jul 2021 15:37:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hz2-0000iO-W7 for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47485) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hz0-000528-NP for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:20 -0400 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-111-gbKTX51gMM-bZMOCn3-54g-1; Wed, 21 Jul 2021 15:34:17 -0400 Received: by mail-qv1-f72.google.com with SMTP id x18-20020ad440d20000b02902e121b2b364so2239010qvp.12 for ; Wed, 21 Jul 2021 12:34:17 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id 8sm10755867qkb.105.2021.07.21.12.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 12:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626896058; 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=JY/hBnyyaXIQ1Hc7JqYuUGXeJi6bgQg0sNKHhut1eJs=; b=c1tXbjOuxbPIQ+jpxsfVlhqoYRe2L0AzxRLirLnEP3aRqgsXvzxmGdFv8vHmCMceDrh9UA Po3lbDSKFPJJO5Ts22pej36BX0OWotoKkjo+Ph6g2kYK8hljO7N/n+rtfZ/3BejdvJMvgI wHgnjd6VMnRjEvtYhVA7yOyUeH83yEg= X-MC-Unique: gbKTX51gMM-bZMOCn3-54g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JY/hBnyyaXIQ1Hc7JqYuUGXeJi6bgQg0sNKHhut1eJs=; b=Kq7vXzymaqvomOnJQBRTP7b9qUlyG8lvWRlrKTBH9W+NzNUAzrBDqMdV2tPEhYB/Le 2apqU1ntz2bjBqq2Lsvq7GUrP+ll25rG/+OUKBx9Q4GmMx7sZ8GL7WIYwM9WDpawBGNZ ICm0NKw+ZOQ5O1xFMMbdMi67EzukWel3HrZ6XotsOGZkdEJKJTBWkAO6WK4vWPpAiD06 PBY4hvdscpKOK5RHfoRLuBPTExzj2TyFDCjmppknRob1TvDlDQwtk8Px/I5qU6c4BDD8 DZEm5ua81zkW7+BkdPvapGrJi5O9UEhCQ6olykbGfi4Uc9zvmXvoH3tSkPxCEg6ErX1h vNvA== X-Gm-Message-State: AOAM533+HFOHjps1n4sv0YL6D9a1V27qv0K/Z8fsp3bF4bSjkwDh5gYe uXlf6K4mmxPEAMp9BUZqe/qT9KtTU1NCx+/Mm9rBvHK1wM/57FLGtkpc1gx7Y+BLhHIrKnqCRGw p1Dhq9rn9zaQvzhCKyITAHespi1iqGJhjalh3FR1FmKPNPKmaRW39PDx6MzyC1jfW X-Received: by 2002:ac8:4a19:: with SMTP id x25mr32834306qtq.389.1626896056385; Wed, 21 Jul 2021 12:34:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoewZfJIwBXYm+fAx7PCXKDTu1C9EmASd2dJ3aBVi9f/huaPFR4J/bbdlHtNZaX/dy8xpWQA== X-Received: by 2002:ac8:4a19:: with SMTP id x25mr32834275qtq.389.1626896056065; Wed, 21 Jul 2021 12:34:16 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 2/5] migration: Make from_dst_file accesses thread-safe Date: Wed, 21 Jul 2021 15:34:06 -0400 Message-Id: <20210721193409.910462-3-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721193409.910462-1-peterx@redhat.com> References: <20210721193409.910462-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.459, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Lukas Straub , "Daniel P . Berrange" , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Leonardo Bras Soares Passos Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626896243032100001 Content-Type: text/plain; charset="utf-8" Accessing from_dst_file is potentially racy in current code base like below: if (s->from_dst_file) do_something(s->from_dst_file); Because from_dst_file can be reset right after the check in another thread (rp_thread). One example is migrate_fd_cancel(). Use the same qemu_file_lock to protect it too, just like to_dst_file. When it's safe to access without lock, comment it. There's one special reference in migration_thread() that can be replaced by the newly introduced rp_thread_created flag. Reported-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 32 +++++++++++++++++++++++++------- migration/migration.h | 8 +++++--- migration/ram.c | 1 + 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 21b94f75a3..fa70400f98 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1879,10 +1879,12 @@ static void migrate_fd_cancel(MigrationState *s) QEMUFile *f =3D migrate_get_current()->to_dst_file; trace_migrate_fd_cancel(); =20 + qemu_mutex_lock(&s->qemu_file_lock); if (s->rp_state.from_dst_file) { /* shutdown the rp socket, so causing the rp thread to shutdown */ qemu_file_shutdown(s->rp_state.from_dst_file); } + qemu_mutex_unlock(&s->qemu_file_lock); =20 do { old_state =3D s->state; @@ -2686,6 +2688,22 @@ static int migrate_handle_rp_resume_ack(MigrationSta= te *s, uint32_t value) return 0; } =20 +/* Release ms->rp_state.from_dst_file in a safe way */ +static void migration_release_from_dst_file(MigrationState *ms) +{ + QEMUFile *file =3D ms->rp_state.from_dst_file; + + qemu_mutex_lock(&ms->qemu_file_lock); + /* + * Reset the from_dst_file pointer first before releasing it, as we ca= n't + * block within lock section + */ + ms->rp_state.from_dst_file =3D NULL; + qemu_mutex_unlock(&ms->qemu_file_lock); + + qemu_fclose(file); +} + /* * Handles messages sent on the return path towards the source VM * @@ -2827,11 +2845,13 @@ out: * Maybe there is something we can do: it looks like a * network down issue, and we pause for a recovery. */ - qemu_fclose(rp); - ms->rp_state.from_dst_file =3D NULL; + migration_release_from_dst_file(ms); rp =3D NULL; if (postcopy_pause_return_path_thread(ms)) { - /* Reload rp, reset the rest */ + /* + * Reload rp, reset the rest. Referencing it is save since + * it's reset only by us above, or when migration completes + */ rp =3D ms->rp_state.from_dst_file; ms->rp_state.error =3D false; goto retry; @@ -2843,8 +2863,7 @@ out: } =20 trace_source_return_path_thread_end(); - ms->rp_state.from_dst_file =3D NULL; - qemu_fclose(rp); + migration_release_from_dst_file(ms); rcu_unregister_thread(); return NULL; } @@ -2852,7 +2871,6 @@ out: static int open_return_path_on_source(MigrationState *ms, bool create_thread) { - ms->rp_state.from_dst_file =3D qemu_file_get_return_path(ms->to_dst_fi= le); if (!ms->rp_state.from_dst_file) { return -1; @@ -3746,7 +3764,7 @@ static void *migration_thread(void *opaque) * If we opened the return path, we need to make sure dst has it * opened as well. */ - if (s->rp_state.from_dst_file) { + if (s->rp_state.rp_thread_created) { /* Now tell the dest that it should open its end so it can reply */ qemu_savevm_send_open_return_path(s->to_dst_file); =20 diff --git a/migration/migration.h b/migration/migration.h index c302879fad..7a5aa8c2fd 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -154,12 +154,13 @@ struct MigrationState { QemuThread thread; QEMUBH *vm_start_bh; QEMUBH *cleanup_bh; + /* Protected by qemu_file_lock */ QEMUFile *to_dst_file; QIOChannelBuffer *bioc; /* - * Protects to_dst_file pointer. We need to make sure we won't - * yield or hang during the critical section, since this lock will - * be used in OOB command handler. + * Protects to_dst_file/from_dst_file pointers. We need to make sure = we + * won't yield or hang during the critical section, since this lock wi= ll be + * used in OOB command handler. */ QemuMutex qemu_file_lock; =20 @@ -192,6 +193,7 @@ struct MigrationState { =20 /* State related to return path */ struct { + /* Protected by qemu_file_lock */ QEMUFile *from_dst_file; QemuThread rp_thread; bool error; diff --git a/migration/ram.c b/migration/ram.c index b5fc454b2f..f728f5072f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4012,6 +4012,7 @@ static void ram_dirty_bitmap_reload_notify(MigrationS= tate *s) int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) { int ret =3D -EINVAL; + /* from_dst_file is always valid because we're within rp_thread */ QEMUFile *file =3D s->rp_state.from_dst_file; unsigned long *le_bitmap, nbits =3D block->used_length >> TARGET_PAGE_= BITS; uint64_t local_size =3D DIV_ROUND_UP(nbits, 8); --=20 2.31.1 From nobody Sat May 18 23:14:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626896162695731.0597790098815; Wed, 21 Jul 2021 12:36:02 -0700 (PDT) Received: from localhost ([::1]:42390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6I0f-00036g-GE for importer@patchew.org; Wed, 21 Jul 2021 15:36:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hz4-0000kw-B4 for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hz2-00053J-Ke for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:22 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-377-CvP62ESKPzu5iH7t1EWLbQ-1; Wed, 21 Jul 2021 15:34:19 -0400 Received: by mail-qk1-f199.google.com with SMTP id y3-20020ae9f4030000b02903b916ae903fso2416647qkl.6 for ; Wed, 21 Jul 2021 12:34:19 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id 8sm10755867qkb.105.2021.07.21.12.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 12:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626896060; 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=wKMAloDbSrO635HHxiPXxMG2SXVNhWvMxDfE+ax/uns=; b=WjY7V9kcp31/+el3aTOBzBMbHNVW4BjMeP5fzE6hw3roVncGvrt3HWpBA/725O5tnP/8X4 APOpXu9Bq1XT6mQBejw3FmgywAqW9nudulaxPBd2rN7ZEEnPo7mIcoSXjjqOX+JsF+k4qN S80IVijynYZtfd5Q30OtB/LSclbUQqk= X-MC-Unique: CvP62ESKPzu5iH7t1EWLbQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wKMAloDbSrO635HHxiPXxMG2SXVNhWvMxDfE+ax/uns=; b=oA/koglOE2hC3grZKhFlvpn8xjv/LPes5p8TbpHZTPWKB4obijDxTYVHHe4vhGDrZc pJiiJeR7sAk/asqlmOxqa4sMrfQtOyDPR7RIHcYluV72BwHpsC/bz0sMipzvWLBUhexQ mCP3ZXSI9CuTlY0VmYZeL/Oa920g840MF0qy5ed2HjLU+fCQEz8NpblSHWJ6mUyp0Ptt rs2M07pQmwqa4uPy3Li8O+kQzsKhQgPO5RIDZBNJjAh3Esqe36pOirOI6yfLpZwvX51Y 73owx4QVMtK+jqZawEEdJ/pNeyM90N0uUx4OPCvl9Bb+O+sCBllvOLieZdEJackDXSNF d9AQ== X-Gm-Message-State: AOAM531g3jIUD0LCSAID4QF6aXEJURU5cf4uKj2N08VepcX6eNgNC3Db dDREppCoJbvSqqQGkmQgVPnfBGzZYckJ2FwE/7hNFuCLdMVvqG8YwmvVYSKx7ex5GXOxPdioFLp 8dD/agZ8lQmKeFY8ivdkU+RXqg1zBCZty4q/FLtCa1bNombQmYp81CJWszUsTGnGR X-Received: by 2002:a05:622a:1805:: with SMTP id t5mr32964202qtc.340.1626896058018; Wed, 21 Jul 2021 12:34:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQb9dByEH9Bc+mrD8uOrmvrE8q/NQMjwtVJ79lddY3vuljO3oIKkd5s0GHObmN9hLBYvAK0Q== X-Received: by 2002:a05:622a:1805:: with SMTP id t5mr32964166qtc.340.1626896057688; Wed, 21 Jul 2021 12:34:17 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 3/5] migration: Introduce migration_ioc_[un]register_yank() Date: Wed, 21 Jul 2021 15:34:07 -0400 Message-Id: <20210721193409.910462-4-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721193409.910462-1-peterx@redhat.com> References: <20210721193409.910462-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.459, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Lukas Straub , "Daniel P . Berrange" , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Leonardo Bras Soares Passos Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626896164700100001 Content-Type: text/plain; charset="utf-8" There're plenty of places in migration/* that checks against either socket = or tls typed ioc for yank operations. Provide two helpers to hide all these information. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- migration/channel.c | 15 ++------------- migration/multifd.c | 8 ++------ migration/qemu-file-channel.c | 8 ++------ migration/yank_functions.c | 28 ++++++++++++++++++++++++++++ migration/yank_functions.h | 2 ++ 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/migration/channel.c b/migration/channel.c index 01275a9162..c4fc000a1a 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -44,13 +44,7 @@ void migration_channel_process_incoming(QIOChannel *ioc) TYPE_QIO_CHANNEL_TLS)) { migration_tls_channel_process_incoming(s, ioc, &local_err); } else { - if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) || - object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS)) { - yank_register_function(MIGRATION_YANK_INSTANCE, - migration_yank_iochannel, - QIO_CHANNEL(ioc)); - } - + migration_ioc_register_yank(ioc); migration_ioc_process_incoming(ioc, &local_err); } =20 @@ -94,12 +88,7 @@ void migration_channel_connect(MigrationState *s, } else { QEMUFile *f =3D qemu_fopen_channel_output(ioc); =20 - if (object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) = || - object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS)) { - yank_register_function(MIGRATION_YANK_INSTANCE, - migration_yank_iochannel, - QIO_CHANNEL(ioc)); - } + migration_ioc_register_yank(ioc); =20 qemu_mutex_lock(&s->qemu_file_lock); s->to_dst_file =3D f; diff --git a/migration/multifd.c b/migration/multifd.c index ab41590e71..377da78f5b 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -987,12 +987,8 @@ int multifd_load_cleanup(Error **errp) for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 - if ((object_dynamic_cast(OBJECT(p->c), TYPE_QIO_CHANNEL_SOCKET) || - object_dynamic_cast(OBJECT(p->c), TYPE_QIO_CHANNEL_TLS)) - && OBJECT(p->c)->ref =3D=3D 1) { - yank_unregister_function(MIGRATION_YANK_INSTANCE, - migration_yank_iochannel, - QIO_CHANNEL(p->c)); + if (OBJECT(p->c)->ref =3D=3D 1) { + migration_ioc_unregister_yank(p->c); } =20 object_unref(OBJECT(p->c)); diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index fad340ea7a..867a5ed0c3 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -107,12 +107,8 @@ static int channel_close(void *opaque, Error **errp) int ret; QIOChannel *ioc =3D QIO_CHANNEL(opaque); ret =3D qio_channel_close(ioc, errp); - if ((object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) || - object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS)) - && OBJECT(ioc)->ref =3D=3D 1) { - yank_unregister_function(MIGRATION_YANK_INSTANCE, - migration_yank_iochannel, - QIO_CHANNEL(ioc)); + if (OBJECT(ioc)->ref =3D=3D 1) { + migration_ioc_unregister_yank(ioc); } object_unref(OBJECT(ioc)); return ret; diff --git a/migration/yank_functions.c b/migration/yank_functions.c index 96c90e17dc..23697173ae 100644 --- a/migration/yank_functions.c +++ b/migration/yank_functions.c @@ -11,6 +11,9 @@ #include "qapi/error.h" #include "io/channel.h" #include "yank_functions.h" +#include "qemu/yank.h" +#include "io/channel-socket.h" +#include "io/channel-tls.h" =20 void migration_yank_iochannel(void *opaque) { @@ -18,3 +21,28 @@ void migration_yank_iochannel(void *opaque) =20 qio_channel_shutdown(ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); } + +/* Return whether yank is supported on this ioc */ +static bool migration_ioc_yank_supported(QIOChannel *ioc) +{ + return object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_SOCKET) || + object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS); +} + +void migration_ioc_register_yank(QIOChannel *ioc) +{ + if (migration_ioc_yank_supported(ioc)) { + yank_register_function(MIGRATION_YANK_INSTANCE, + migration_yank_iochannel, + QIO_CHANNEL(ioc)); + } +} + +void migration_ioc_unregister_yank(QIOChannel *ioc) +{ + if (migration_ioc_yank_supported(ioc)) { + yank_unregister_function(MIGRATION_YANK_INSTANCE, + migration_yank_iochannel, + QIO_CHANNEL(ioc)); + } +} diff --git a/migration/yank_functions.h b/migration/yank_functions.h index 055ea22523..74c7f18c91 100644 --- a/migration/yank_functions.h +++ b/migration/yank_functions.h @@ -15,3 +15,5 @@ * @opaque: QIOChannel to shutdown */ void migration_yank_iochannel(void *opaque); +void migration_ioc_register_yank(QIOChannel *ioc); +void migration_ioc_unregister_yank(QIOChannel *ioc); --=20 2.31.1 From nobody Sat May 18 23:14:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626896385468333.0401624857144; Wed, 21 Jul 2021 12:39:45 -0700 (PDT) Received: from localhost ([::1]:52230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6I4G-0001Lx-CO for importer@patchew.org; Wed, 21 Jul 2021 15:39:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hz6-0000pw-7Q for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60968) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hz4-000558-GI for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:23 -0400 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-bwilF7TUPY6UhyxIvAyRPA-1; Wed, 21 Jul 2021 15:34:20 -0400 Received: by mail-qv1-f72.google.com with SMTP id d10-20020a0ce44a0000b02902c99dfad03fso2239727qvm.8 for ; Wed, 21 Jul 2021 12:34:20 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id 8sm10755867qkb.105.2021.07.21.12.34.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 12:34:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626896061; 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=DWPj3h23PENZST3rJ31jnS0NnnoQ2JOXMtDihViJ7dA=; b=G2JYtLP6vXK6E3i9NaiorHX5Jrena92lBxiYJeiNAeDwd2/t52IW1tSBhsneRDyqfl0UME /IMdakOXoKLflGhvvpAFfq+D60OAVAdAUDS5kpcm2t/MpHkVEnLmzol8ZWsNFjZQDBIJGH DYSjnKFH1ZxkQS7lEURTXQ6fRi1Op5M= X-MC-Unique: bwilF7TUPY6UhyxIvAyRPA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DWPj3h23PENZST3rJ31jnS0NnnoQ2JOXMtDihViJ7dA=; b=QSycmee7TlAWCOj7tleUTW8FRu+rbDB0WwPRJrx2X34GKHurnhVjX6FPJKGO268chS jZDa8echJ1+70EMvxhUizD42TaZb4LJZp6XyaDaBqEUHT3LbiYB+i4H1P/Y2eqCXgDe3 zvdOdlchK2nQv40XCv8HyIWbZP5yTikDJmLlDJEfJIt157tHoKKmHwyBGkf+Dee6oORy lJhb8t1N9KW+m8yZ6Qjw1Yp6iWtVEYPS8/pZLS+gmWDwRvyL69LqyRZoRmRyUXkvrjOy TEjaVwrHmWaRom02KqBsAo0ePOOya6Cxdzchl1lxSBymhK8hFpdbuGwG4tYSoEoJxNq9 3mjA== X-Gm-Message-State: AOAM5334OTSf2FX/Vdb0dtUncicnlkLy8V334gy1Sq5Nh4a3m1h3FnAo zBvpQltpb1t6w0UCW84CINGwKfgoRyymlPLDgIRxq/v/82FiwKE0LNPDipLadyeVRkYSU809V1H gKue2hfUaahqul4WJBAH0TCLnIOAD84u6QH9dybof9PLosXXABk5ggYJIQylftIFP X-Received: by 2002:a37:a78d:: with SMTP id q135mr22530102qke.192.1626896059828; Wed, 21 Jul 2021 12:34:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzazIna7Ps9PUA9qKAJpNUiGKx8VvhmVCIML107ULOVrql4ouDoGpKUHxbp6xfjfu+Xe8qAnA== X-Received: by 2002:a37:a78d:: with SMTP id q135mr22530074qke.192.1626896059506; Wed, 21 Jul 2021 12:34:19 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 4/5] migration: Teach QEMUFile to be QIOChannel-aware Date: Wed, 21 Jul 2021 15:34:08 -0400 Message-Id: <20210721193409.910462-5-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721193409.910462-1-peterx@redhat.com> References: <20210721193409.910462-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.459, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Lukas Straub , "Daniel P . Berrange" , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Leonardo Bras Soares Passos Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626896387185100001 Content-Type: text/plain; charset="utf-8" migration uses QIOChannel typed qemufiles. In follow up patches, we'll need the capability to identify this fact, so that we can get the backing QIOCha= nnel from a QEMUFile. We can also define types for QEMUFile but so far since we only need to be a= ble to identify QIOChannel, introduce a boolean which is simpler. Introduce another helper qemu_file_get_ioc() to return the ioc backend of a qemufile if has_ioc is set. No functional change. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/qemu-file-channel.c | 4 ++-- migration/qemu-file.c | 17 ++++++++++++++++- migration/qemu-file.h | 4 +++- migration/ram.c | 2 +- migration/savevm.c | 4 ++-- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 867a5ed0c3..2f8b1fcd46 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -187,11 +187,11 @@ static const QEMUFileOps channel_output_ops =3D { QEMUFile *qemu_fopen_channel_input(QIOChannel *ioc) { object_ref(OBJECT(ioc)); - return qemu_fopen_ops(ioc, &channel_input_ops); + return qemu_fopen_ops(ioc, &channel_input_ops, true); } =20 QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc) { object_ref(OBJECT(ioc)); - return qemu_fopen_ops(ioc, &channel_output_ops); + return qemu_fopen_ops(ioc, &channel_output_ops, true); } diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 1eacf9e831..6338d8e2ff 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -55,6 +55,8 @@ struct QEMUFile { Error *last_error_obj; /* has the file has been shutdown */ bool shutdown; + /* Whether opaque points to a QIOChannel */ + bool has_ioc; }; =20 /* @@ -101,7 +103,7 @@ bool qemu_file_mode_is_not_valid(const char *mode) return false; } =20 -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops) +QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_io= c) { QEMUFile *f; =20 @@ -109,6 +111,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOp= s *ops) =20 f->opaque =3D opaque; f->ops =3D ops; + f->has_ioc =3D has_ioc; return f; } =20 @@ -851,3 +854,15 @@ void qemu_file_set_blocking(QEMUFile *f, bool block) f->ops->set_blocking(f->opaque, block, NULL); } } + +/* + * Return the ioc object if it's a migration channel. Note: it can return= NULL + * for callers passing in a non-migration qemufile. E.g. see qemu_fopen_b= drv() + * and its usage in e.g. load_snapshot(). So we need to check against NULL + * before using it. If without the check, migration_incoming_state_destro= y() + * could fail for load_snapshot(). + */ +QIOChannel *qemu_file_get_ioc(QEMUFile *file) +{ + return file->has_ioc ? QIO_CHANNEL(file->opaque) : NULL; +} diff --git a/migration/qemu-file.h b/migration/qemu-file.h index a9b6d6ccb7..3f36d4dc8c 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -27,6 +27,7 @@ =20 #include #include "exec/cpu-common.h" +#include "io/channel.h" =20 /* Read a chunk of data from a file at the given position. The pos argume= nt * can be ignored if the file is only be used for streaming. The number of @@ -119,7 +120,7 @@ typedef struct QEMUFileHooks { QEMURamSaveFunc *save_page; } QEMUFileHooks; =20 -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops); +QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_io= c); void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); @@ -179,5 +180,6 @@ void ram_control_load_hook(QEMUFile *f, uint64_t flags,= void *data); size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, ram_addr_t offset, size_t size, uint64_t *bytes_sent); +QIOChannel *qemu_file_get_ioc(QEMUFile *file); =20 #endif diff --git a/migration/ram.c b/migration/ram.c index f728f5072f..08b3cb7a4a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -550,7 +550,7 @@ static int compress_threads_save_setup(void) /* comp_param[i].file is just used as a dummy buffer to save data, * set its ops to empty. */ - comp_param[i].file =3D qemu_fopen_ops(NULL, &empty_ops); + comp_param[i].file =3D qemu_fopen_ops(NULL, &empty_ops, false); comp_param[i].done =3D true; comp_param[i].quit =3D false; qemu_mutex_init(&comp_param[i].mutex); diff --git a/migration/savevm.c b/migration/savevm.c index 72848b946c..96b5e5d639 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -168,9 +168,9 @@ static const QEMUFileOps bdrv_write_ops =3D { static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable) { if (is_writable) { - return qemu_fopen_ops(bs, &bdrv_write_ops); + return qemu_fopen_ops(bs, &bdrv_write_ops, false); } - return qemu_fopen_ops(bs, &bdrv_read_ops); + return qemu_fopen_ops(bs, &bdrv_read_ops, false); } =20 =20 --=20 2.31.1 From nobody Sat May 18 23:14:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626896481201178.0401962216771; Wed, 21 Jul 2021 12:41:21 -0700 (PDT) Received: from localhost ([::1]:54840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6I5n-00037b-W2 for importer@patchew.org; Wed, 21 Jul 2021 15:41:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hz7-0000vl-Ro for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25543) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6Hz6-00056L-5d for qemu-devel@nongnu.org; Wed, 21 Jul 2021 15:34:25 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-496-q4ge83KPM3SrcMNzfeGP6g-1; Wed, 21 Jul 2021 15:34:22 -0400 Received: by mail-qk1-f199.google.com with SMTP id d14-20020a05620a240eb02903b9402486c5so2403222qkn.13 for ; Wed, 21 Jul 2021 12:34:22 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id 8sm10755867qkb.105.2021.07.21.12.34.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 12:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626896063; 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=sDpg/hapVGWUKLp3temSvW5kh612oZQ5Aiw4osVkfSI=; b=DsuLR37kAQlnh6a2lDoCluvbpZGg1rdgQxSm5iaWdfswBp5BM/uwdFczz0QDFAS2D4N0mV 6lyAHYdGCJAmxz+V33q49MKBpZ33w3GgYaGJSVlmNIUEt4wv46+f0fYzkaWexVnBqgPbXz CU9VDv94QzUcfpaMkadAifT7gWKbor8= X-MC-Unique: q4ge83KPM3SrcMNzfeGP6g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sDpg/hapVGWUKLp3temSvW5kh612oZQ5Aiw4osVkfSI=; b=kUr7rY4KVsRC2D9Ju8Z3uw+n1xhECwJQWYZ38O8KRvAQVZAlwwGAD/djSjkHU84/x7 YFZhc8EhyASHeDFAarPcoXL+lWF4zvLYb8vRu0RqsptHwuHsGoewyB5vNvkh9SyKndZO kO3jAYQ943yW+B5wF8vnE09uuNhge9dy/Dc7yHNVao6FPm+HjZAKkcoO7Ukcjt3BZvaB IucZXhYLlctEd6vkDaDqGqE3iq3DkBYzJLE48e2QWpGqMo/UfZOoNios5JGshf6b3Thm 50ECz+rRqIOrVEEGiB52ZfIUWBAtlpAHEVAg4Cwcvd37Lko0s7L3LxZ95NG6SzAme9n4 5gCg== X-Gm-Message-State: AOAM533B2HP6LU4hJSLSolRQv75l3zk/jfB8AXEW0SOvdvk5a/1HPD/V pmZg7ikzq0+netlkeapK45U44roOvLc/YdwhV6gCmsGeuAjHTRgV5Zf5BfO86OfaQF+tlw8A69/ GpjeYoju8Lg+CmunPjnKVWCqAkjRVhG+DqL+lvOeU93liCvHprYRhcrRjjy/iMjtI X-Received: by 2002:a05:622a:1a11:: with SMTP id f17mr32442104qtb.308.1626896061184; Wed, 21 Jul 2021 12:34:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylUnZKIOfp/bnBxs5RYmqgjhh0cKSU6zfojV3ryGHflEJDGkWtOjlMhPF3ulsUni/JmQ7fIw== X-Received: by 2002:a05:622a:1a11:: with SMTP id f17mr32442081qtb.308.1626896060889; Wed, 21 Jul 2021 12:34:20 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v2 5/5] migration: Move the yank unregister of channel_close out Date: Wed, 21 Jul 2021 15:34:09 -0400 Message-Id: <20210721193409.910462-6-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721193409.910462-1-peterx@redhat.com> References: <20210721193409.910462-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.459, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Lukas Straub , "Daniel P . Berrange" , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Leonardo Bras Soares Passos Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1626896482601100001 Content-Type: text/plain; charset="utf-8" It's efficient, but hackish to call yank unregister calls in channel_close(= ), especially it'll be hard to debug when qemu crashed with some yank function leaked. Remove that hack, but instead explicitly unregister yank functions at the places where needed, they are: (on src) - migrate_fd_cleanup - postcopy_pause (on dst) - migration_incoming_state_destroy - postcopy_pause_incoming Signed-off-by: Peter Xu --- migration/migration.c | 5 +++++ migration/qemu-file-channel.c | 3 --- migration/savevm.c | 7 +++++++ migration/yank_functions.c | 14 ++++++++++++++ migration/yank_functions.h | 1 + 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index fa70400f98..bfeb65b8f7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -59,6 +59,7 @@ #include "multifd.h" #include "qemu/yank.h" #include "sysemu/cpus.h" +#include "yank_functions.h" =20 #define MAX_THROTTLE (128 << 20) /* Migration transfer speed throttl= ing */ =20 @@ -273,6 +274,7 @@ void migration_incoming_state_destroy(void) } =20 if (mis->from_src_file) { + migration_ioc_unregister_yank_from_file(mis->from_src_file); qemu_fclose(mis->from_src_file); mis->from_src_file =3D NULL; } @@ -1811,6 +1813,7 @@ static void migrate_fd_cleanup(MigrationState *s) * Close the file handle without the lock to make sure the * critical section won't block for long. */ + migration_ioc_unregister_yank_from_file(tmp); qemu_fclose(tmp); } =20 @@ -3352,6 +3355,8 @@ static MigThrError postcopy_pause(MigrationState *s) =20 /* Current channel is possibly broken. Release it. */ assert(s->to_dst_file); + /* Unregister yank for current channel */ + migration_ioc_unregister_yank_from_file(s->to_dst_file); qemu_mutex_lock(&s->qemu_file_lock); file =3D s->to_dst_file; s->to_dst_file =3D NULL; diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 2f8b1fcd46..bb5a5752df 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -107,9 +107,6 @@ static int channel_close(void *opaque, Error **errp) int ret; QIOChannel *ioc =3D QIO_CHANNEL(opaque); ret =3D qio_channel_close(ioc, errp); - if (OBJECT(ioc)->ref =3D=3D 1) { - migration_ioc_unregister_yank(ioc); - } object_unref(OBJECT(ioc)); return ret; } diff --git a/migration/savevm.c b/migration/savevm.c index 96b5e5d639..7b7b64bd13 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -65,6 +65,7 @@ #include "qemu/bitmap.h" #include "net/announce.h" #include "qemu/yank.h" +#include "yank_functions.h" =20 const unsigned int postcopy_ram_discard_version; =20 @@ -2568,6 +2569,12 @@ static bool postcopy_pause_incoming(MigrationIncomin= gState *mis) /* Clear the triggered bit to allow one recovery */ mis->postcopy_recover_triggered =3D false; =20 + /* + * Unregister yank with either from/to src would work, since ioc behin= d it + * is the same + */ + migration_ioc_unregister_yank_from_file(mis->from_src_file); + assert(mis->from_src_file); qemu_file_shutdown(mis->from_src_file); qemu_fclose(mis->from_src_file); diff --git a/migration/yank_functions.c b/migration/yank_functions.c index 23697173ae..8c08aef14a 100644 --- a/migration/yank_functions.c +++ b/migration/yank_functions.c @@ -14,6 +14,7 @@ #include "qemu/yank.h" #include "io/channel-socket.h" #include "io/channel-tls.h" +#include "qemu-file.h" =20 void migration_yank_iochannel(void *opaque) { @@ -46,3 +47,16 @@ void migration_ioc_unregister_yank(QIOChannel *ioc) QIO_CHANNEL(ioc)); } } + +void migration_ioc_unregister_yank_from_file(QEMUFile *file) +{ + QIOChannel *ioc =3D qemu_file_get_ioc(file); + + if (ioc) { + /* + * For migration qemufiles, we'll always reach here. Though we'll= skip + * calls from e.g. savevm/loadvm as they don't use yank. + */ + migration_ioc_unregister_yank(ioc); + } +} diff --git a/migration/yank_functions.h b/migration/yank_functions.h index 74c7f18c91..a7577955ed 100644 --- a/migration/yank_functions.h +++ b/migration/yank_functions.h @@ -17,3 +17,4 @@ void migration_yank_iochannel(void *opaque); void migration_ioc_register_yank(QIOChannel *ioc); void migration_ioc_unregister_yank(QIOChannel *ioc); +void migration_ioc_unregister_yank_from_file(QEMUFile *file); --=20 2.31.1