From: Bin Wu <wu.wubin@huawei.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, boby.chen@huawei.com,
subo7@huawei.com, kathy.wangting@huawei.com,
rudy.zhangmin@huawei.com, arei.gonglei@huawei.com,
stefanha@redhat.com, pbonzini@redhat.com, bruce.fon@huawei.com,
Bin Wu <wu.wubin@huawei.com>
Subject: [Qemu-devel] [PATCH] qemu-coroutine: fix qemu_co_queue_run_restart error
Date: Mon, 9 Feb 2015 12:09:24 +0800 [thread overview]
Message-ID: <1423454964-6840-2-git-send-email-wu.wubin@huawei.com> (raw)
In-Reply-To: <1423454964-6840-1-git-send-email-wu.wubin@huawei.com>
From: Bin Wu <wu.wubin@huawei.com>
The error scenario is as follow: coroutine C1 enters C2, C2 yields
back to C1, then C1 ternimates and the related coroutine memory
becomes invalid. After a while, the C2 coroutine is entered again.
At this point, C1 is used as a parameter passed to
qemu_co_queue_run_restart. Therefore, qemu_co_queue_run_restart
accesses an invalid memory and a segfault error ocurrs.
The qemu_co_queue_run_restart function re-enters coroutines waiting
in the co_queue. However, this function should be only used int the
qemu_coroutine_enter context. Only in this context, when the current
coroutine gets execution control again(after the execution of
qemu_coroutine_switch), we can restart the target coutine because the
target coutine has yielded back to the current coroutine or it has
terminated.
First we want to put qemu_co_queue_run_restart in qemu_coroutine_enter,
but we find we can not access the target coroutine if it terminates.
Signed-off-by: Bin Wu <wu.wubin@huawei.com>
---
qemu-coroutine.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/qemu-coroutine.c b/qemu-coroutine.c
index 525247b..9a294c4 100644
--- a/qemu-coroutine.c
+++ b/qemu-coroutine.c
@@ -99,24 +99,25 @@ static void coroutine_delete(Coroutine *co)
qemu_coroutine_delete(co);
}
-static void coroutine_swap(Coroutine *from, Coroutine *to)
+static CoroutineAction coroutine_swap(Coroutine *from, Coroutine *to)
{
CoroutineAction ret;
ret = qemu_coroutine_switch(from, to, COROUTINE_YIELD);
- qemu_co_queue_run_restart(to);
-
switch (ret) {
case COROUTINE_YIELD:
- return;
+ break;
case COROUTINE_TERMINATE:
trace_qemu_coroutine_terminate(to);
+ qemu_co_queue_run_restart(to);
coroutine_delete(to);
- return;
+ break;
default:
abort();
}
+
+ return ret;
}
void qemu_coroutine_enter(Coroutine *co, void *opaque)
@@ -133,6 +134,8 @@ void qemu_coroutine_enter(Coroutine *co, void *opaque)
co->caller = self;
co->entry_arg = opaque;
coroutine_swap(self, co);
+ if (ret == COROUTINE_YIELD)
+ qemu_co_queue_run_restart(co);
}
void coroutine_fn qemu_coroutine_yield(void)
--
1.7.12.4
next prev parent reply other threads:[~2015-02-09 4:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-09 4:09 [Qemu-devel] [PATCH] qemu-coroutine: segfault when restarting co_queue Bin Wu
2015-02-09 4:09 ` Bin Wu [this message]
2015-02-09 6:34 ` [Qemu-devel] [PATCH] qemu-coroutine: fix qemu_co_queue_run_restart error Bin Wu
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=1423454964-6840-2-git-send-email-wu.wubin@huawei.com \
--to=wu.wubin@huawei.com \
--cc=arei.gonglei@huawei.com \
--cc=boby.chen@huawei.com \
--cc=bruce.fon@huawei.com \
--cc=famz@redhat.com \
--cc=kathy.wangting@huawei.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rudy.zhangmin@huawei.com \
--cc=stefanha@redhat.com \
--cc=subo7@huawei.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).