Skip to contentSkip to conversation

coroutine: Make yield_until_fd_readable() detach fd handler always

PATCH Superseded Peter Xu 3 participants 8 messages Nov 19 – Nov 20

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 coroutine: Make yield_until_fd_readable() detach fd handler always

Hongyan reported a possible use-after-free of RDMA migration code:

https://lore.kernel.org/all/[email protected]

The issue seems real, while this patch is a proposal to fix it in a simpler way, meanwhile it should be a problem to the yield_until_fd_readable() helper in general, so it should make more sense to be fixed there too.

The problem is about the use of the stack allocated FDYieldUntilData where we must make sure after yield_until_fd_readable() returns it's not used anywhere. If the coroutine yielded can be entered from outside of this helper (fd_coroutine_enter()), then the aio handler might be installed even after yield_until_fd_readable() returns, and that makes the stack variable accessible by aio codd, even if stack gone.

Fix it by moving the aio handler removal outside the handler.

Cc Stefan Hajnoczi <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Fabiano Rosas <[email protected]>
Cc Zhijian Li (Fujitsu) <[email protected]>
Cc Hongyan Xu <[email protected]>

---

NOTE: I targeted this for 12.0 because the bug was not introduced in 11.2, however this seems to be a real bug fix to coroutine in general, I'll leave that to maintainers to decide if to pick it for 11.2.

---
 util/qemu-coroutine-io.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
util/qemu-coroutine-io.c +5 -1
index 364f4d5abf..3c0a7feafa 100644
@@ -74,7 +74,6 @@ typedef struct {
 static void fd_coroutine_enter(void *opaque)
 {
     FDYieldUntilData *data = opaque;
-    aio_set_fd_handler(data->ctx, data->fd, NULL, NULL, NULL, NULL, NULL);
     qemu_coroutine_enter(data->co);
 }
 
@@ -89,4 +88,9 @@ void coroutine_fn yield_until_fd_readable(int fd)
     aio_set_fd_handler(data.ctx, fd, fd_coroutine_enter, NULL, NULL, NULL,
                        &data);
     qemu_coroutine_yield();
+    /*
+     * Always remove the fd handler, no matter the re-entering of this
+     * coroutine was caused by fd_coroutine_enter() or something else.
+     */
+    aio_set_fd_handler(data.ctx, fd, NULL, NULL, NULL, NULL, NULL);
 }
Signature · 1 line
2.56.0
#1 lore raw
Quoted 46 lines · Peter Xu

Hongyan reported a possible use-after-free of RDMA migration code:

https://lore.kernel.org/all/[email protected]

The issue seems real, while this patch is a proposal to fix it in a simpler way, meanwhile it should be a problem to the yield_until_fd_readable() helper in general, so it should make more sense to be fixed there too.

The problem is about the use of the stack allocated FDYieldUntilData where we must make sure after yield_until_fd_readable() returns it's not used anywhere. If the coroutine yielded can be entered from outside of this helper (fd_coroutine_enter()), then the aio handler might be installed even after yield_until_fd_readable() returns, and that makes the stack variable accessible by aio codd, even if stack gone.

Fix it by moving the aio handler removal outside the handler.

Cc Stefan Hajnoczi <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Fabiano Rosas <[email protected]>
Cc Zhijian Li (Fujitsu) <[email protected]>
Cc Hongyan Xu <[email protected]>

---

NOTE: I targeted this for 12.0 because the bug was not introduced in 11.2, however this seems to be a real bug fix to coroutine in general, I'll leave that to maintainers to decide if to pick it for 11.2.

---
 util/qemu-coroutine-io.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
util/qemu-coroutine-io.c +0 -1
index 364f4d5abf..3c0a7feafa 100644
@@ -74,7 +74,6 @@ typedef struct {
 static void fd_coroutine_enter(void *opaque)
 {
     FDYieldUntilData *data = opaque;
-    aio_set_fd_handler(data->ctx, data->fd, NULL, NULL, NULL, NULL, NULL);
     qemu_coroutine_enter(data->co);
 }
 

util/qemu-coroutine-io.c void coroutine_fn yield_until_fd_readable(int fd) · line 96

Quoted 9 lines
util/qemu-coroutine-io.c +5 -0
@@ -89,4 +88,9 @@ void coroutine_fn yield_until_fd_readable(int fd)
     aio_set_fd_handler(data.ctx, fd, fd_coroutine_enter, NULL, NULL, NULL,
                        &data);
     qemu_coroutine_yield();
+    /*
+     * Always remove the fd handler, no matter the re-entering of this
+     * coroutine was caused by fd_coroutine_enter() or something else.
+     */
+    aio_set_fd_handler(data.ctx, fd, NULL, NULL, NULL, NULL, NULL);
 }

Why would the coroutine be entered? Should there be a loop around qemu_coroutine_yield() - otherwise we fix the invalid stack memory access but return to the caller without fulfilling the purpose of the function (waiting for the fd to become readable), which could cause further bugs?

Stefan

author
#2 lore raw
Quoted 46 lines · Stefan Hajnoczi
Quoted 45 lines · Peter Xu

Hongyan reported a possible use-after-free of RDMA migration code:

https://lore.kernel.org/all/[email protected]

The issue seems real, while this patch is a proposal to fix it in a simpler way, meanwhile it should be a problem to the yield_until_fd_readable() helper in general, so it should make more sense to be fixed there too.

The problem is about the use of the stack allocated FDYieldUntilData where we must make sure after yield_until_fd_readable() returns it's not used anywhere. If the coroutine yielded can be entered from outside of this helper (fd_coroutine_enter()), then the aio handler might be installed even after yield_until_fd_readable() returns, and that makes the stack variable accessible by aio codd, even if stack gone.

Fix it by moving the aio handler removal outside the handler.

Cc Stefan Hajnoczi <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Fabiano Rosas <[email protected]>
Cc Zhijian Li (Fujitsu) <[email protected]>
Cc Hongyan Xu <[email protected]>

---

NOTE: I targeted this for 12.0 because the bug was not introduced in 11.2, however this seems to be a real bug fix to coroutine in general, I'll leave that to maintainers to decide if to pick it for 11.2.

---
 util/qemu-coroutine-io.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
util/qemu-coroutine-io.c +0 -1
index 364f4d5abf..3c0a7feafa 100644
@@ -74,7 +74,6 @@ typedef struct {
 static void fd_coroutine_enter(void *opaque)
 {
     FDYieldUntilData *data = opaque;
-    aio_set_fd_handler(data->ctx, data->fd, NULL, NULL, NULL, NULL, NULL);
     qemu_coroutine_enter(data->co);
 }
 
Quoted 12 lines

util/qemu-coroutine-io.c void coroutine_fn yield_until_fd_readable(int fd) · line 96

Quoted 10 lines
util/qemu-coroutine-io.c +5 -0
@@ -89,4 +88,9 @@ void coroutine_fn yield_until_fd_readable(int fd)
     aio_set_fd_handler(data.ctx, fd, fd_coroutine_enter, NULL, NULL, NULL,
                        &data);
     qemu_coroutine_yield();
+    /*
+     * Always remove the fd handler, no matter the re-entering of this
+     * coroutine was caused by fd_coroutine_enter() or something else.
+     */
+    aio_set_fd_handler(data.ctx, fd, NULL, NULL, NULL, NULL, NULL);
 }

Why would the coroutine be entered?

In case of RDMA, rdma_cm_poll_handler() could receive a disconnect event on another management fd, then it knows the link is down, hence it needs to kickoff this coroutine to quit. See 923709896b1.

Quoted 5 lines

Should there be a loop around
qemu_coroutine_yield() - otherwise we fix the invalid stack memory access but return to the caller without fulfilling the purpose of the function (waiting for the fd to become readable), which could cause further bugs?

I feel like these are two separate things.

IMO fixing reset of aio handler should be a pure positive fix, because not fixing it doesn't stop user from re-entering of the coroutine and bypass fd_coroutine_enter().

My understanding is the caller should have full control of this: when the caller requires "fd must be readable", it should always wait until fd_coroutine_enter() returns. This patch should have no functional difference.

But it seems still legal if the caller is benign and can properly handle the case even if fd is still not readable. In this case, this patch fixes a real issue.

In case of RDMA migration, only the quit path can cause it to re-enter, so either there is IO or we need to quit. RDMA code works well with either event, it can even loop back and wait on the fd again, but since quit is the only path kicking this off, it's also not possible even if the caller handles this.

Thanks,

Signature · 1 line
Peter Xu
#3 lore raw
Quoted 60 lines · Peter Xu
Quoted 46 lines · Stefan Hajnoczi
Quoted 45 lines · Peter Xu

Hongyan reported a possible use-after-free of RDMA migration code:

https://lore.kernel.org/all/[email protected]

The issue seems real, while this patch is a proposal to fix it in a simpler way, meanwhile it should be a problem to the yield_until_fd_readable() helper in general, so it should make more sense to be fixed there too.

The problem is about the use of the stack allocated FDYieldUntilData where we must make sure after yield_until_fd_readable() returns it's not used anywhere. If the coroutine yielded can be entered from outside of this helper (fd_coroutine_enter()), then the aio handler might be installed even after yield_until_fd_readable() returns, and that makes the stack variable accessible by aio codd, even if stack gone.

Fix it by moving the aio handler removal outside the handler.

Cc Stefan Hajnoczi <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Fabiano Rosas <[email protected]>
Cc Zhijian Li (Fujitsu) <[email protected]>
Cc Hongyan Xu <[email protected]>

---

NOTE: I targeted this for 12.0 because the bug was not introduced in 11.2, however this seems to be a real bug fix to coroutine in general, I'll leave that to maintainers to decide if to pick it for 11.2.

---
 util/qemu-coroutine-io.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
util/qemu-coroutine-io.c +0 -1
index 364f4d5abf..3c0a7feafa 100644
@@ -74,7 +74,6 @@ typedef struct {
 static void fd_coroutine_enter(void *opaque)
 {
     FDYieldUntilData *data = opaque;
-    aio_set_fd_handler(data->ctx, data->fd, NULL, NULL, NULL, NULL, NULL);
     qemu_coroutine_enter(data->co);
 }
 
Quoted 12 lines

util/qemu-coroutine-io.c void coroutine_fn yield_until_fd_readable(int fd) · line 96

Quoted 10 lines
util/qemu-coroutine-io.c +5 -0
@@ -89,4 +88,9 @@ void coroutine_fn yield_until_fd_readable(int fd)
     aio_set_fd_handler(data.ctx, fd, fd_coroutine_enter, NULL, NULL, NULL,
                        &data);
     qemu_coroutine_yield();
+    /*
+     * Always remove the fd handler, no matter the re-entering of this
+     * coroutine was caused by fd_coroutine_enter() or something else.
+     */
+    aio_set_fd_handler(data.ctx, fd, NULL, NULL, NULL, NULL, NULL);
 }

Why would the coroutine be entered?

Quoted 3 lines

In case of RDMA, rdma_cm_poll_handler() could receive a disconnect event on another management fd, then it knows the link is down, hence it needs to kickoff this coroutine to quit. See 923709896b1.

Commit 923709896b1 is not safe in general. It would be necessary to audit all yield points and see how they react to an unexpected coroutine re-entry. There could be more bugs related to this.

Quoted 8 lines
Quoted 5 lines

Should there be a loop around
qemu_coroutine_yield() - otherwise we fix the invalid stack memory access but return to the caller without fulfilling the purpose of the function (waiting for the fd to become readable), which could cause further bugs?

I feel like these are two separate things.

Quoted 8 lines

IMO fixing reset of aio handler should be a pure positive fix, because not fixing it doesn't stop user from re-entering of the coroutine and bypass fd_coroutine_enter().

My understanding is the caller should have full control of this: when the caller requires "fd must be readable", it should always wait until fd_coroutine_enter() returns. This patch should have no functional difference.

I don't understand this paragraph because the caller has no way of knowing whether fd_coroutine_enter() ran when yield_until_fd_readable() returns with this patch applied. How can the caller wait until fd_coroutine_enter() returns?

Quoted 9 lines

But it seems still legal if the caller is benign and can properly handle the case even if fd is still not readable. In this case, this patch fixes a real issue.

In case of RDMA migration, only the quit path can cause it to re-enter, so either there is IO or we need to quit. RDMA code works well with either event, it can even loop back and wait on the fd again, but since quit is the only path kicking this off, it's also not possible even if the caller handles this.

The caller of yield_until_fd_readable() expects the function return to mean the fd is now readable, not that the fd is readable or something else happened. At minimum this patch would need to add a comment to clarify this and then audit all callers to be sure they can handle those semantics correctly.

It would be better to also add a return value differentiating between success and failure (due to interruption) so that callers can propagate the interruption (a caller may be several frames into a call stack where a parent function will loop on early return, defeating the purpose of reentering the coroutine to notify it that the connection on a separate fd was dropped, so it must be possible to propagate the interruption up the call stack).

Any part of QEMU could use util/qemu-coroutine-io.c, so even if this patch happens to work for RDMA migration, the yield_until_fd_readable() API needs a more disciplined approach so that it can be used correctly by anyone.

Stefan

author
#4 lore raw
Quoted 61 lines · Stefan Hajnoczi
Quoted 60 lines · Peter Xu
Quoted 58 lines · Stefan Hajnoczi
Quoted 46 lines · Peter Xu

Hongyan reported a possible use-after-free of RDMA migration code:

https://lore.kernel.org/all/[email protected]

The issue seems real, while this patch is a proposal to fix it in a simpler way, meanwhile it should be a problem to the yield_until_fd_readable() helper in general, so it should make more sense to be fixed there too.

The problem is about the use of the stack allocated FDYieldUntilData where we must make sure after yield_until_fd_readable() returns it's not used anywhere. If the coroutine yielded can be entered from outside of this helper (fd_coroutine_enter()), then the aio handler might be installed even after yield_until_fd_readable() returns, and that makes the stack variable accessible by aio codd, even if stack gone.

Fix it by moving the aio handler removal outside the handler.

Cc Stefan Hajnoczi <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Fabiano Rosas <[email protected]>
Cc Zhijian Li (Fujitsu) <[email protected]>
Cc Hongyan Xu <[email protected]>

---

NOTE: I targeted this for 12.0 because the bug was not introduced in 11.2, however this seems to be a real bug fix to coroutine in general, I'll leave that to maintainers to decide if to pick it for 11.2.

---
 util/qemu-coroutine-io.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
util/qemu-coroutine-io.c +0 -1
index 364f4d5abf..3c0a7feafa 100644
@@ -74,7 +74,6 @@ typedef struct {
 static void fd_coroutine_enter(void *opaque)
 {
     FDYieldUntilData *data = opaque;
-    aio_set_fd_handler(data->ctx, data->fd, NULL, NULL, NULL, NULL, NULL);
     qemu_coroutine_enter(data->co);
 }
 

util/qemu-coroutine-io.c void coroutine_fn yield_until_fd_readable(int fd) · line 96

Quoted 9 lines
util/qemu-coroutine-io.c +5 -0
@@ -89,4 +88,9 @@ void coroutine_fn yield_until_fd_readable(int fd)
     aio_set_fd_handler(data.ctx, fd, fd_coroutine_enter, NULL, NULL, NULL,
                        &data);
     qemu_coroutine_yield();
+    /*
+     * Always remove the fd handler, no matter the re-entering of this
+     * coroutine was caused by fd_coroutine_enter() or something else.
+     */
+    aio_set_fd_handler(data.ctx, fd, NULL, NULL, NULL, NULL, NULL);
 }

Why would the coroutine be entered?

Quoted 7 lines
Quoted 3 lines

In case of RDMA, rdma_cm_poll_handler() could receive a disconnect event on another management fd, then it knows the link is down, hence it needs to kickoff this coroutine to quit. See 923709896b1.

Commit 923709896b1 is not safe in general. It would be necessary to audit all yield points and see how they react to an unexpected coroutine re-entry. There could be more bugs related to this.

AFAIU, this is really the only caller. :)

Per my understanding, RDMA migration code was written in a way that it sololy rely on qemu_rdma_block_for_wrid() to block waiting for completion events.

Quoted 18 lines
Quoted 9 lines
Quoted 6 lines

Should there be a loop around
qemu_coroutine_yield() - otherwise we fix the invalid stack memory access but return to the caller without fulfilling the purpose of the function (waiting for the fd to become readable), which could cause further bugs?

I feel like these are two separate things.

Quoted 8 lines

IMO fixing reset of aio handler should be a pure positive fix, because not fixing it doesn't stop user from re-entering of the coroutine and bypass fd_coroutine_enter().

My understanding is the caller should have full control of this: when the caller requires "fd must be readable", it should always wait until fd_coroutine_enter() returns. This patch should have no functional difference.

Quoted 4 lines

I don't understand this paragraph because the caller has no way of knowing whether fd_coroutine_enter() ran when yield_until_fd_readable() returns with this patch applied. How can the caller wait until fd_coroutine_enter() returns?

What I meant is, after returning from yield_until_fd_readable(), the caller can re-check everything again to be tolerant to other events, e.g. poll() the fd again to re-check if the fd is really readable, then it can go back and yield again if it wants when not readable. So that the code (depending on how it was implemented) flows all fine no matter if the fd will be readable. Thats, AFAICT, how RDMA migration works.

Quoted 25 lines
Quoted 10 lines

But it seems still legal if the caller is benign and can properly handle the case even if fd is still not readable. In this case, this patch fixes a real issue.

In case of RDMA migration, only the quit path can cause it to re-enter, so either there is IO or we need to quit. RDMA code works well with either event, it can even loop back and wait on the fd again, but since quit is the only path kicking this off, it's also not possible even if the caller handles this.

The caller of yield_until_fd_readable() expects the function return to mean the fd is now readable, not that the fd is readable or something else happened. At minimum this patch would need to add a comment to clarify this and then audit all callers to be sure they can handle those semantics correctly.

It would be better to also add a return value differentiating between success and failure (due to interruption) so that callers can propagate the interruption (a caller may be several frames into a call stack where a parent function will loop on early return, defeating the purpose of reentering the coroutine to notify it that the connection on a separate fd was dropped, so it must be possible to propagate the interruption up the call stack).

Quoted 4 lines

Any part of QEMU could use util/qemu-coroutine-io.c, so even if this patch happens to work for RDMA migration, the yield_until_fd_readable() API needs a more disciplined approach so that it can be used correctly by anyone.

I get the point that this API might be tricky to use, actually I don't think I'm good enough knowing coroutines to say what is a best API, but so far it's only used in RDMA migration and over many years no new user came up. So maybe it's not a major concern yet.

The other thing just to mention, I actually have code trying to remove RDMA migration from using coroutine too:

https://lore.kernel.org/qemu-devel/[email protected]/

After that maybe we can drop this API. For now, fixing that seems reasonable if it's trivial, and also because it's not yet confirmed it'll happen.

Thanks,

Signature · 1 line
Peter Xu
#5 lore raw
In reply to Stefan Hajnoczi

Am 19.11.2026 um 23:29 hat Stefan Hajnoczi geschrieben:

Quoted 46 lines · Peter Xu
Quoted 45 lines

Hongyan reported a possible use-after-free of RDMA migration code:

https://lore.kernel.org/all/[email protected]

The issue seems real, while this patch is a proposal to fix it in a simpler way, meanwhile it should be a problem to the yield_until_fd_readable() helper in general, so it should make more sense to be fixed there too.

The problem is about the use of the stack allocated FDYieldUntilData where we must make sure after yield_until_fd_readable() returns it's not used anywhere. If the coroutine yielded can be entered from outside of this helper (fd_coroutine_enter()), then the aio handler might be installed even after yield_until_fd_readable() returns, and that makes the stack variable accessible by aio codd, even if stack gone.

Fix it by moving the aio handler removal outside the handler.

Cc Stefan Hajnoczi <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Fabiano Rosas <[email protected]>
Cc Zhijian Li (Fujitsu) <[email protected]>
Cc Hongyan Xu <[email protected]>

---

NOTE: I targeted this for 12.0 because the bug was not introduced in 11.2, however this seems to be a real bug fix to coroutine in general, I'll leave that to maintainers to decide if to pick it for 11.2.

---
 util/qemu-coroutine-io.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
util/qemu-coroutine-io.c +0 -1
index 364f4d5abf..3c0a7feafa 100644
@@ -74,7 +74,6 @@ typedef struct {
 static void fd_coroutine_enter(void *opaque)
 {
     FDYieldUntilData *data = opaque;
-    aio_set_fd_handler(data->ctx, data->fd, NULL, NULL, NULL, NULL, NULL);
     qemu_coroutine_enter(data->co);
 }
 
Quoted 16 lines

util/qemu-coroutine-io.c void coroutine_fn yield_until_fd_readable(int fd) · line 96

Quoted 10 lines
util/qemu-coroutine-io.c +5 -0
@@ -89,4 +88,9 @@ void coroutine_fn yield_until_fd_readable(int fd)
     aio_set_fd_handler(data.ctx, fd, fd_coroutine_enter, NULL, NULL, NULL,
                        &data);
     qemu_coroutine_yield();
+    /*
+     * Always remove the fd handler, no matter the re-entering of this
+     * coroutine was caused by fd_coroutine_enter() or something else.
+     */
+    aio_set_fd_handler(data.ctx, fd, NULL, NULL, NULL, NULL, NULL);
 }

Why would the coroutine be entered? Should there be a loop around qemu_coroutine_yield() - otherwise we fix the invalid stack memory access but return to the caller without fulfilling the purpose of the function (waiting for the fd to become readable), which could cause further bugs?

A loop around qemu_coroutine_yield() is almost never what you want. It may happen in cases where you spawn multiple operations and wait for all of them to complete, but if you're just waiting for a condition to become true, then entering the coroutine before the condition is true means that the caller is doing something wrong.

In this case, I think the additional caller intentionally wants to cancel the waiting.

Having multiple places that can reenter a coroutine tends to be tricky because aio_co_wake() introduces a window where both places could trigger, which leads to an abort(). But here, qemu_coroutine_enter() is directly used (which also implies that the coroutine and all the places that reenter it are in the same thread), so it should be okay.

Kevin

#6 lore raw
In reply to Peter Xu

Am 19.11.2026 um 15:53 hat Peter Xu geschrieben:

Quoted 17 lines

Hongyan reported a possible use-after-free of RDMA migration code:

https://lore.kernel.org/all/[email protected]

The issue seems real, while this patch is a proposal to fix it in a simpler way, meanwhile it should be a problem to the yield_until_fd_readable() helper in general, so it should make more sense to be fixed there too.

The problem is about the use of the stack allocated FDYieldUntilData where we must make sure after yield_until_fd_readable() returns it's not used anywhere. If the coroutine yielded can be entered from outside of this helper (fd_coroutine_enter()), then the aio handler might be installed even after yield_until_fd_readable() returns, and that makes the stack variable accessible by aio codd, even if stack gone.

Fix it by moving the aio handler removal outside the handler.

Quoted 7 lines
Cc Stefan Hajnoczi <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Fabiano Rosas <[email protected]>
Cc Zhijian Li (Fujitsu) <[email protected]>
Cc Hongyan Xu <[email protected]>

The fix looks right to me, however now FDYieldUntilData has two unused fields. I suppose you could get rid of it entirely now and pass the coroutine pointer as opaque.

Kevin

author
#7 lore raw
Quoted 26 lines · Kevin Wolf

Am 19.11.2026 um 15:53 hat Peter Xu geschrieben:

Quoted 17 lines

Hongyan reported a possible use-after-free of RDMA migration code:

https://lore.kernel.org/all/[email protected]

The issue seems real, while this patch is a proposal to fix it in a simpler way, meanwhile it should be a problem to the yield_until_fd_readable() helper in general, so it should make more sense to be fixed there too.

The problem is about the use of the stack allocated FDYieldUntilData where we must make sure after yield_until_fd_readable() returns it's not used anywhere. If the coroutine yielded can be entered from outside of this helper (fd_coroutine_enter()), then the aio handler might be installed even after yield_until_fd_readable() returns, and that makes the stack variable accessible by aio codd, even if stack gone.

Fix it by moving the aio handler removal outside the handler.

Quoted 7 lines
Cc Stefan Hajnoczi <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Fabiano Rosas <[email protected]>
Cc Zhijian Li (Fujitsu) <[email protected]>
Cc Hongyan Xu <[email protected]>
Quoted 3 lines

The fix looks right to me, however now FDYieldUntilData has two unused fields. I suppose you could get rid of it entirely now and pass the coroutine pointer as opaque.

Indeed, I'll respin, thanks both for reviewing!

Signature · 1 line
Peter Xu