From nobody Mon Feb 9 06:49:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495649537680748.3485901563151; Wed, 24 May 2017 11:12:17 -0700 (PDT) Received: from localhost ([::1]:56214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDalb-0000dy-7O for importer@patchew.org; Wed, 24 May 2017 14:12:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDafY-0003vI-JR for qemu-devel@nongnu.org; Wed, 24 May 2017 14:06:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDafU-0001Lz-Jv for qemu-devel@nongnu.org; Wed, 24 May 2017 14:06:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59096) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dDafU-0001Lb-2w for qemu-devel@nongnu.org; Wed, 24 May 2017 14:05:56 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FE6180F93 for ; Wed, 24 May 2017 18:05:55 +0000 (UTC) Received: from flash.redhat.com (ovpn-116-215.phx2.redhat.com [10.3.116.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE15477D5B; Wed, 24 May 2017 18:05:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1FE6180F93 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=vyasevic@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1FE6180F93 From: Vladislav Yasevich To: qemu-devel@nongnu.org, dgilbert@redhat.com, quintela@redhat.com Date: Wed, 24 May 2017 14:05:23 -0400 Message-Id: <1495649128-10529-8-git-send-email-vyasevic@redhat.com> In-Reply-To: <1495649128-10529-1-git-send-email-vyasevic@redhat.com> References: <1495649128-10529-1-git-send-email-vyasevic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 24 May 2017 18:05:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/12] migration: Allow for a limited number of announce timers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: germano@redhat.com, lvivier@redhat.com, mst@redhat.com, jasowang@redhat.com, Vladislav Yasevich , armbru@redhat.com, kashyap@redhat.com, jdenemar@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We currently create a new announcement timer every time qemu_announce_self() is called. Since this is now a qmp command, this can lead to abuse. Limit the number of timers that are created. Give QMP interface and migration process 1 timer each. This way, QMP can't abuse the announce_self mechanism. Signed-off-by: Vladislav Yasevich --- include/migration/vmstate.h | 1 + include/sysemu/sysemu.h | 9 ++++++++- migration/migration.c | 2 +- migration/savevm.c | 24 +++++++++++++++++++----- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index f8aed9b..689b685 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1057,6 +1057,7 @@ void vmstate_register_ram_global(struct MemoryRegion = *memory); =20 typedef struct AnnounceTimer { QEMUTimer *tm; + struct AnnounceTimer **entry; AnnounceParameters params; QEMUClockType type; int round; diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 2ef1687..85a2af1 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -78,14 +78,21 @@ void qemu_remove_machine_init_done_notifier(Notifier *n= otify); int save_vmstate(const char *name, Error **errp); int load_vmstate(const char *name, Error **errp); =20 +typedef enum AnnounceType { + QEMU_ANNOUNCE_MIGRATION, + QEMU_ANNOUNCE_USER, + QEMU_ANNOUNCE__MAX, +} AnnounceType; + AnnounceParameters *qemu_get_announce_params(void); void qemu_fill_announce_parameters(AnnounceParameters **to, AnnounceParameters *from); + bool qemu_validate_announce_parameters(AnnounceParameters *params, Error **errp); void qemu_set_announce_parameters(AnnounceParameters *announce_params, AnnounceParameters *params); -void qemu_announce_self(AnnounceParameters *params); +void qemu_announce_self(AnnounceParameters *params, AnnounceType type); =20 /* Subcommands for QEMU_VM_COMMAND */ enum qemu_vm_cmd { diff --git a/migration/migration.c b/migration/migration.c index 987c1cf..724fc40 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -345,7 +345,7 @@ static void process_incoming_migration_bh(void *opaque) * This must happen after all error conditions are dealt with and * we're sure the VM is going to be running on this host. */ - qemu_announce_self(qemu_get_announce_params()); + qemu_announce_self(qemu_get_announce_params(), QEMU_ANNOUNCE_MIGRATION= ); =20 /* If global state section was not received or we are in running state, we need to obey autostart. Any other state is set with diff --git a/migration/savevm.c b/migration/savevm.c index b55ce6a..dcba8bd 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -218,6 +218,8 @@ static void qemu_announce_self_iter(NICState *nic, void= *opaque) } } =20 +AnnounceTimer *announce_timers[QEMU_ANNOUNCE__MAX]; + static void qemu_announce_self_once(void *opaque) { AnnounceTimer *timer =3D (AnnounceTimer *)opaque; @@ -228,6 +230,7 @@ static void qemu_announce_self_once(void *opaque) timer_mod(timer->tm, qemu_clock_get_ms(timer->type) + self_announce_delay(timer)); } else { + *(timer->entry) =3D NULL; timer_del(timer->tm); timer_free(timer->tm); g_free(timer); @@ -256,12 +259,23 @@ AnnounceTimer *qemu_announce_timer_create(AnnouncePar= ameters *params, return timer; } =20 -void qemu_announce_self(AnnounceParameters *params) +void qemu_announce_self(AnnounceParameters *params, AnnounceType type) { AnnounceTimer *timer; =20 - timer =3D qemu_announce_timer_create(params, QEMU_CLOCK_REALTIME, - qemu_announce_self_once); + timer =3D announce_timers[type]; + if (!timer) { + timer =3D qemu_announce_timer_create(params, QEMU_CLOCK_REALTIME, + qemu_announce_self_once); + announce_timers[type] =3D timer; + timer->entry =3D &announce_timers[type]; + } else { + /* For now, don't do anything. If we want to reset the timer, + * we'll need to add locking to each announce timer to prevent + * races between timeout handling and a reset. + */ + return; + } qemu_announce_self_once(timer); } =20 @@ -276,7 +290,7 @@ void qmp_announce_self(bool has_params, AnnounceParamet= ers *params, if (has_params) qemu_set_announce_parameters(&announce_params, params); =20 - qemu_announce_self(&announce_params); + qemu_announce_self(&announce_params, QEMU_ANNOUNCE_USER); } =20 /***********************************************************/ @@ -1750,7 +1764,7 @@ static void loadvm_postcopy_handle_run_bh(void *opaqu= e) */ cpu_synchronize_all_post_init(); =20 - qemu_announce_self(qemu_get_announce_params()); + qemu_announce_self(qemu_get_announce_params(), QEMU_ANNOUNCE_MIGRATION= ); =20 /* Make sure all file formats flush their mutable metadata. * If we get an error here, just don't restart the VM yet. */ --=20 2.7.4