From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Daniel P . Berrange" <berrange@redhat.com>,
peterx@redhat.com, "Eric Blake" <eblake@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: [Qemu-devel] [PATCH 7/9] monitor: restrict response queue length too
Date: Wed, 4 Jul 2018 16:45:05 +0800 [thread overview]
Message-ID: <20180704084507.14560-8-peterx@redhat.com> (raw)
In-Reply-To: <20180704084507.14560-1-peterx@redhat.com>
Before this patch we were only monitoring the request queue, but it's
still possible that a client only sends requests but it never eats any
reply from us. In that case our response queue might grow with
unlimited responses and put us at risk.
Now we play the similar trick as we have done to the request queue to
make sure we apply the same queue length rule to the response queue as
well. Then we also need to peek at the queue length after we unqueue a
response now, to make sure we'll kick the monitor to alive if it was
suspended due to "response queue full".
Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
monitor.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/monitor.c b/monitor.c
index ebf862914f..9b78cf1c63 100644
--- a/monitor.c
+++ b/monitor.c
@@ -393,18 +393,15 @@ static void monitor_qmp_cleanup_queues(Monitor *mon)
qemu_mutex_unlock(&mon->qmp.qmp_lock);
}
-/* Try to resume the monitor if it was suspended due to any reason */
-static void monitor_qmp_try_resume(Monitor *mon)
+/* Callers must be with Monitor.qmp.qmp_lock held. */
+static void monitor_qmp_try_resume_locked(Monitor *mon)
{
- assert(monitor_is_qmp(mon));
- qemu_mutex_lock(&mon->qmp.qmp_lock);
-
- if (mon->qmp.qmp_requests->length >= QMP_REQ_QUEUE_LEN_MAX) {
+ if (mon->qmp.qmp_requests->length >= QMP_REQ_QUEUE_LEN_MAX ||
+ mon->qmp.qmp_responses->length >= QMP_REQ_QUEUE_LEN_MAX) {
/*
* This should not happen, but in case if it happens, we
* should still keep the monitor in suspend state
*/
- qemu_mutex_unlock(&mon->qmp.qmp_lock);
return;
}
@@ -412,7 +409,14 @@ static void monitor_qmp_try_resume(Monitor *mon)
monitor_resume(mon);
mon->qmp.need_resume = false;
}
+}
+/* Try to resume the monitor if it was suspended due to any reason */
+static void monitor_qmp_try_resume(Monitor *mon)
+{
+ assert(monitor_is_qmp(mon));
+ qemu_mutex_lock(&mon->qmp.qmp_lock);
+ monitor_qmp_try_resume_locked(mon);
qemu_mutex_unlock(&mon->qmp.qmp_lock);
}
@@ -574,6 +578,8 @@ static QDict *monitor_qmp_response_pop_one(Monitor *mon)
qemu_mutex_lock(&mon->qmp.qmp_lock);
data = g_queue_pop_head(mon->qmp.qmp_responses);
+ /* In case if we were suspended due to response queue full */
+ monitor_qmp_try_resume_locked(mon);
qemu_mutex_unlock(&mon->qmp.qmp_lock);
return data;
@@ -4289,12 +4295,13 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
monitor_qmp_suspend_locked(mon);
} else {
/*
- * If the queue is reaching the length limitation, we queue
- * this command, meanwhile we suspend the monitor to block new
- * commands. We'll resume ourselves until the queue has more
- * space.
+ * If any of the req/resp queue is reaching the length
+ * limitation, we queue this command, meanwhile we suspend the
+ * monitor to block new commands. We'll resume ourselves
+ * until both of the queues have more spaces.
*/
- if (mon->qmp.qmp_requests->length >= QMP_REQ_QUEUE_LEN_MAX - 1) {
+ if (mon->qmp.qmp_requests->length >= QMP_REQ_QUEUE_LEN_MAX - 1 ||
+ mon->qmp.qmp_responses->length >= QMP_REQ_QUEUE_LEN_MAX - 1) {
monitor_qmp_suspend_locked(mon);
}
}
--
2.17.1
next prev parent reply other threads:[~2018-07-04 8:45 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-04 8:44 [Qemu-devel] [PATCH 0/9] monitor: enable OOB by default Peter Xu
2018-07-04 8:44 ` [Qemu-devel] [PATCH 1/9] monitor: simplify monitor_qmp_setup_handlers_bh Peter Xu
2018-07-05 5:44 ` Markus Armbruster
2018-07-04 8:45 ` [Qemu-devel] [PATCH 2/9] qapi: allow build_params to return "void" Peter Xu
2018-07-05 6:02 ` Markus Armbruster
2018-07-05 6:18 ` Peter Xu
2018-07-04 8:45 ` [Qemu-devel] [PATCH 3/9] qapi: remove error checks for event emission Peter Xu
2018-07-05 8:43 ` Markus Armbruster
2018-07-05 9:17 ` Peter Xu
2018-07-04 8:45 ` [Qemu-devel] [PATCH 4/9] monitor: move need_resume flag into monitor struct Peter Xu
2018-07-05 8:51 ` Markus Armbruster
2018-07-05 9:49 ` Peter Xu
2018-07-05 11:09 ` Markus Armbruster
2018-07-05 11:32 ` Marc-André Lureau
2018-07-05 12:01 ` Peter Xu
2018-07-04 8:45 ` [Qemu-devel] [PATCH 5/9] monitor: suspend monitor instead of send CMD_DROP Peter Xu
2018-07-05 16:47 ` Eric Blake
2018-07-06 3:49 ` Peter Xu
2018-07-06 8:00 ` Markus Armbruster
2018-07-06 8:09 ` Markus Armbruster
2018-07-06 9:39 ` Peter Xu
2018-07-06 13:19 ` Markus Armbruster
2018-07-10 4:27 ` Peter Xu
2018-07-12 6:10 ` Markus Armbruster
2018-07-12 13:23 ` Markus Armbruster
2018-07-04 8:45 ` [Qemu-devel] [PATCH 6/9] qapi: remove COMMAND_DROPPED event Peter Xu
2018-07-04 8:45 ` Peter Xu [this message]
2018-07-04 8:45 ` [Qemu-devel] [PATCH 8/9] monitor: remove "x-oob", turn oob on by default Peter Xu
2018-07-04 8:45 ` [Qemu-devel] [PATCH 9/9] Revert "tests: Add parameter to qtest_init_without_qmp_handshake" Peter Xu
2018-07-16 17:18 ` [Qemu-devel] [PATCH 0/9] monitor: enable OOB by default Markus Armbruster
2018-07-17 12:08 ` Peter Xu
2018-07-18 8:47 ` Peter Xu
2018-07-18 13:09 ` Markus Armbruster
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=20180704084507.14560-8-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.