qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladislav Yasevich <vyasevic@redhat.com>
To: qemu-devel@nongnu.org, dgilbert@redhat.com, quintela@redhat.com
Cc: germano@redhat.com, lvivier@redhat.com, jasowang@redhat.com,
	jdenemar@redhat.com, kashyap@redhat.com, armbru@redhat.com,
	mst@redhat.com, Vladislav Yasevich <vyasevic@redhat.com>
Subject: [Qemu-devel] [PATCH 07/12] migration: Allow for a limited number of announce timers
Date: Wed, 24 May 2017 14:05:23 -0400	[thread overview]
Message-ID: <1495649128-10529-8-git-send-email-vyasevic@redhat.com> (raw)
In-Reply-To: <1495649128-10529-1-git-send-email-vyasevic@redhat.com>

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 <vyasevic@redhat.com>
---
 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);
 
 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 *notify);
 int save_vmstate(const char *name, Error **errp);
 int load_vmstate(const char *name, Error **errp);
 
+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);
 
 /* 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);
 
     /* 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)
     }
 }
 
+AnnounceTimer *announce_timers[QEMU_ANNOUNCE__MAX];
+
 static void qemu_announce_self_once(void *opaque)
 {
     AnnounceTimer *timer = (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) = NULL;
             timer_del(timer->tm);
             timer_free(timer->tm);
             g_free(timer);
@@ -256,12 +259,23 @@ AnnounceTimer *qemu_announce_timer_create(AnnounceParameters *params,
     return timer;
 }
 
-void qemu_announce_self(AnnounceParameters *params)
+void qemu_announce_self(AnnounceParameters *params, AnnounceType type)
 {
     AnnounceTimer *timer;
 
-    timer = qemu_announce_timer_create(params, QEMU_CLOCK_REALTIME,
-                                       qemu_announce_self_once);
+    timer = announce_timers[type];
+    if (!timer) {
+        timer = qemu_announce_timer_create(params, QEMU_CLOCK_REALTIME,
+                                            qemu_announce_self_once);
+        announce_timers[type] = timer;
+        timer->entry = &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);
 }
 
@@ -276,7 +290,7 @@ void qmp_announce_self(bool has_params, AnnounceParameters *params,
     if (has_params)
         qemu_set_announce_parameters(&announce_params, params);
 
-    qemu_announce_self(&announce_params);
+    qemu_announce_self(&announce_params, QEMU_ANNOUNCE_USER);
 }
 
 /***********************************************************/
@@ -1750,7 +1764,7 @@ static void loadvm_postcopy_handle_run_bh(void *opaque)
      */
     cpu_synchronize_all_post_init();
 
-    qemu_announce_self(qemu_get_announce_params());
+    qemu_announce_self(qemu_get_announce_params(), QEMU_ANNOUNCE_MIGRATION);
 
     /* Make sure all file formats flush their mutable metadata.
      * If we get an error here, just don't restart the VM yet. */
-- 
2.7.4

  parent reply	other threads:[~2017-05-24 18:06 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 18:05 [Qemu-devel] [PATCH 00/12] self-announce updates Vladislav Yasevich
2017-05-24 18:05 ` [Qemu-devel] [PATCH 01/12] migration: Introduce announce parameters Vladislav Yasevich
2017-05-26  4:03   ` Jason Wang
2017-05-26 13:06     ` Vlad Yasevich
2017-05-30 18:57       ` Dr. David Alan Gilbert
2017-06-01  7:02         ` Jason Wang
2017-06-01 13:45           ` Vlad Yasevich
2017-06-01 14:02             ` Dr. David Alan Gilbert
2017-05-26 13:08   ` Eric Blake
2017-05-26 13:17     ` Vlad Yasevich
2017-05-30  9:58   ` Juan Quintela
2017-05-30 13:45     ` Vlad Yasevich
2017-05-30 19:08   ` Dr. David Alan Gilbert
2017-05-24 18:05 ` [Qemu-devel] [PATCH 02/12] migration: Introduce announcement timer Vladislav Yasevich
2017-05-26  4:13   ` Jason Wang
2017-05-30 10:00   ` Juan Quintela
2017-05-24 18:05 ` [Qemu-devel] [PATCH 03/12] migration: Switch to using " Vladislav Yasevich
2017-05-26  4:16   ` Jason Wang
2017-05-26 13:01     ` Vlad Yasevich
2017-05-30 10:10   ` Juan Quintela
2017-05-30 13:46     ` Vlad Yasevich
2017-05-30 19:19   ` Dr. David Alan Gilbert
2017-05-30 19:34     ` Vlad Yasevich
2017-05-24 18:05 ` [Qemu-devel] [PATCH 04/12] net: Add a network device specific self-announcement ability Vladislav Yasevich
2017-05-26  4:17   ` Jason Wang
2017-05-24 18:05 ` [Qemu-devel] [PATCH 05/12] virtio-net: Allow qemu_announce_self to trigger virtio announcements Vladislav Yasevich
2017-05-26  4:21   ` Jason Wang
2017-05-24 18:05 ` [Qemu-devel] [PATCH 06/12] qmp: Expose qemu_announce_self as a qmp command Vladislav Yasevich
2017-05-26 13:16   ` Eric Blake
2017-05-26 13:19     ` Vlad Yasevich
2017-05-30 10:11   ` Juan Quintela
2017-05-30 13:49     ` Vlad Yasevich
2017-05-30 14:24       ` Juan Quintela
2017-05-30 14:43         ` Vlad Yasevich
2017-05-30 14:14   ` Daniel P. Berrange
2017-05-30 15:01     ` Vlad Yasevich
2017-05-24 18:05 ` Vladislav Yasevich [this message]
2017-05-30 10:13   ` [Qemu-devel] [PATCH 07/12] migration: Allow for a limited number of announce timers Juan Quintela
2017-05-30 19:31   ` Dr. David Alan Gilbert
2017-05-24 18:05 ` [Qemu-devel] [PATCH 08/12] announce_timer: Add ability to reset an existing Vladislav Yasevich
2017-05-30 10:15   ` Juan Quintela
2017-05-30 19:35   ` Dr. David Alan Gilbert
2017-05-30 20:01     ` Vlad Yasevich
2017-05-24 18:05 ` [Qemu-devel] [PATCH 09/12] hmp: add announce paraters info/set Vladislav Yasevich
2017-05-30 10:18   ` Juan Quintela
2017-05-30 13:57     ` Vlad Yasevich
2017-05-24 18:05 ` [Qemu-devel] [PATCH 10/12] hmp: Add hmp_announce_self Vladislav Yasevich
2017-05-31  9:47   ` Dr. David Alan Gilbert
2017-05-24 18:05 ` [Qemu-devel] [PATCH 11/12] tests/test-hmp: Add announce parameter tests Vladislav Yasevich
2017-05-31  9:53   ` Dr. David Alan Gilbert
2017-05-24 18:05 ` [Qemu-devel] [PATCH 12/12] tests: Add a test for qemu self announcments Vladislav Yasevich
2017-05-24 18:19 ` [Qemu-devel] [PATCH 00/12] self-announce updates no-reply
2017-05-24 18:38 ` no-reply
2017-05-24 18:40 ` no-reply
2017-05-31 10:29 ` Dr. David Alan Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1495649128-10529-8-git-send-email-vyasevic@redhat.com \
    --to=vyasevic@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=germano@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jdenemar@redhat.com \
    --cc=kashyap@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).