coroutine: add missing annotations
cover coroutine: add missing annotations
Hi
Add missing coroutine_fn, coroutine_mixed_fn annotations and fix a few related issues across monitor, migration, io, block, and 9pfs subsystems.
---
Marc-André Lureau (8):
monitor: annotate monitor_qmp_dispatcher_pop_any() as coroutine
migration: fix qemu_get_counted_string annotation
io: add missing coroutine annotation
block: add missing coroutine annotation
qcow2: remove invalid qcow2_check_refcounts calls
block: add missing coroutine_fn annotations
hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn migration/rdma: annotate and simplify wait_comp_channel()
hw/9pfs/9p.h | 26 +++++++++++++++----------- include/block/blockjob_int.h | 2 +- include/io/channel.h | 4 ++-- block/commit.c | 5 +++-- block/crypto.c | 13 +++++++------ block/io.c | 8 +++++--- block/parallels.c | 5 +++-- block/qcow2-snapshot.c | 18 ------------------ block/qcow2.c | 11 +++++++---- blockjob.c | 3 ++- hw/9pfs/9p.c | 31 +++++++++++++++++++------------ hw/9pfs/virtio-9p-device.c | 24 +++++++++++++----------- hw/9pfs/xen-9p-backend.c | 34 +++++++++++++++++----------------- io/channel.c | 5 +++-- migration/qemu-file.c | 2 +- migration/rdma.c | 12 ++++-------- monitor/qmp.c | 3 ++- 17 files changed, 104 insertions(+), 102 deletions(-)
---
base-commit: 5ef0ecc5942ee07bb581cc96a97bbfc0fdf4005c
change-id: 20260720-co-625d98c7dc5e
Best regards,
Signature · 1 line
Marc-André Lureau <[email protected]>
PATCH 1/8 monitor: annotate monitor_qmp_dispatcher_pop_any() as coroutine
The function calls qemu_coroutine_yield(), and is called from monitor_qmp_dispatcher_co().
--- monitor/qmp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
monitor/qmp.c +2 -1
@@ -342,7 +342,8 @@ static QMPRequest *monitor_qmp_requests_pop_any_with_lock(void)return req_obj; } -static QMPRequest *monitor_qmp_dispatcher_pop_any (void ) +static QMPRequest * coroutine_fn +monitor_qmp_dispatcher_pop_any (void) {while (true) {/*
Signature · 1 line
2.55.0
Re: [PATCH 1/8] monitor: annotate monitor_qmp_dispatcher_pop_any() as coroutine
Quoted 14 lines · Marc-André Lureau
The function calls
qemu_coroutine_yield(), and is called frommonitor_qmp_dispatcher_co().Fixes 60f4f62efeb ("monitor: extract request dequeuing to a new function")Signed-off-by Marc-André Lureau <[email protected]>--- monitor/qmp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)monitor/qmp.c +0
-0
monitor/qmp.c static QMPRequest *monitor_qmp_requests_pop_any_with_lock(void) · line 349
Quoted 9 lines
monitor/qmp.c +2
-1@@ -342,7 +342,8 @@ static QMPRequest *monitor_qmp_requests_pop_any_with_lock(void)return req_obj; } -static QMPRequest *monitor_qmp_dispatcher_pop_any (void ) +static QMPRequest * coroutine_fn +monitor_qmp_dispatcher_pop_any (void) {while (true) {/*
Re: [PATCH 1/8] monitor: annotate monitor_qmp_dispatcher_pop_any() as coroutine
In reply to Marc-André LureauQuoted 8 lines · Marc-André Lureau
The function calls
qemu_coroutine_yield(), and is called frommonitor_qmp_dispatcher_co().Fixes 60f4f62efeb ("monitor: extract request dequeuing to a new function")Signed-off-by Marc-André Lureau <[email protected]>--- monitor/qmp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH 2/8 migration: fix qemu_get_counted_string annotation
In reply to Marc-André Lureau--- migration/qemu-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
migration/qemu-file.c +1 -1
@@ -830,7 +830,7 @@ uint64_t qemu_get_be64(QEMUFile *f)* else 0 * (Note a 0 length string will return 0 either way) */ -size_t coroutine_fn qemu_get_counted_string(QEMUFile *f, char buf[256]) +size_t coroutine_mixed_fn qemu_get_counted_string(QEMUFile *f, char buf[256]) {size_t len =qemu_get_byte (f);size_t res =qemu_get_buffer (f, (uint8_t *)buf, len);
Signature · 1 line
2.55.0
Re: [PATCH 2/8] migration: fix qemu_get_counted_string annotation
Quoted 2 lines · Marc-André Lureau
Fixes 394b9407e4c ("migration: mark mixed functions that can suspend")Signed-off-by Marc-André Lureau <[email protected]>
Signature · 1 line
Peter Xu
Re: [PATCH 2/8] migration: fix qemu_get_counted_string annotation
In reply to Marc-André LureauQuoted 5 lines · Marc-André Lureau
Fixes 394b9407e4c ("migration: mark mixed functions that can suspend")Signed-off-by Marc-André Lureau <[email protected]>--- migration/qemu-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 3/8 io: add missing coroutine annotation
In reply to Marc-André Lureau--- include/io/channel.h | 4 ++-- io/channel.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-)
include/io/channel.h +2 -2
@@ -1016,8 +1016,8 @@ void qio_channel_wait(QIOChannel *ioc,* This will work with/without a coroutine context, by automatically select * the proper API to wait. */ -void qio_channel_wait_cond (QIOChannel *ioc, -GIOCondition condition); +void coroutine_mixed_fn qio_channel_wait_cond(QIOChannel *ioc, +GIOCondition condition);/** * qio_channel_set_aio_fd_handler:
io/channel.c +3 -2
@@ -905,8 +905,9 @@ void qio_channel_wait(QIOChannel *ioc,g_main_context_unref (ctxt); } -void qio_channel_wait_cond (QIOChannel *ioc, -GIOCondition condition) +void coroutine_mixed_fn +qio_channel_wait_cond (QIOChannel *ioc, +GIOCondition condition) {if (qemu_in_coroutine ()) {qio_channel_yield (ioc, condition);
Signature · 1 line
2.55.0
Re: [PATCH 3/8] io: add missing coroutine annotation
Quoted 12 lines · Marc-André Lureau
Fixes 1edf0df28409 ("io: Add qio_channel_wait_cond() helper")Signed-off-by Marc-André Lureau <[email protected]>--- include/io/channel.h | 4 ++-- io/channel.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-)include/io/channel.h +0
-0
include/io/channel.h void qio_channel_wait(QIOChannel *ioc, · line 1019
Quoted 6 lines
include/io/channel.h +1
-2@@ -1016,8 +1016,8 @@ void qio_channel_wait(QIOChannel *ioc,* This will work with/without a coroutine context, by automatically select * the proper API to wait. */ -void qio_channel_wait_cond (QIOChannel *ioc, -GIOCondition condition); +void coroutine_mixed_fn qio_channel_wait_cond(QIOChannel *ioc,
Better using same alignment than below (more importantly in a header), otherwise:
Quoted 21 lines
include/io/channel.h +1
-0+ GIOCondition condition);/** * qio_channel_set_aio_fd_handler: io/channel.c +3
-2@@ -905,8 +905,9 @@ void qio_channel_wait(QIOChannel *ioc,g_main_context_unref (ctxt); } -void qio_channel_wait_cond (QIOChannel *ioc, -GIOCondition condition) +void coroutine_mixed_fn +qio_channel_wait_cond (QIOChannel *ioc, +GIOCondition condition) {if (qemu_in_coroutine ()) {qio_channel_yield (ioc, condition);
PATCH 4/8 block: add missing coroutine annotation
In reply to Marc-André LureauThe function was extracted without carrying the annotation.
--- block/commit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
block/commit.c +3 -2
@@ -128,8 +128,9 @@ static void commit_clean(Job *job)blk_unref (s->top); } -static int commit_iteration (CommitBlockJob *s,int64_t offset, -int64_t *requested_bytes,void *buf) +static int coroutine_fn +commit_iteration (CommitBlockJob *s,int64_t offset, +int64_t *requested_bytes,void *buf) {BlockErrorAction action;int64_t bytes = *requested_bytes;
Signature · 1 line
2.55.0
Re: [PATCH 4/8] block: add missing coroutine annotation
Quoted 7 lines · Marc-André Lureau
The function was extracted without carrying the annotation.
Fixes 23743ab282af ("block: move commit_run loop to separate function")Signed-off-by Marc-André Lureau <[email protected]>--- block/commit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Re: [PATCH 4/8] block: add missing coroutine annotation
In reply to Marc-André LureauAm 20.07.2026 um 09:55 hat Marc-André Lureau geschrieben:
Quoted 4 lines
The function was extracted without carrying the annotation.
Fixes 23743ab282af ("block: move commit_run loop to separate function")Signed-off-by Marc-André Lureau <[email protected]>
PATCH 5/8 qcow2: remove invalid qcow2_check_refcounts calls
In reply to Marc-André LureauThose DEBUG_ALLOC-guarded are dead code incorrectly calling coroutine fn from non-coroutine. Remove it.
--- block/qcow2-snapshot.c | 18 ------------------ 1 file changed, 18 deletions(-)
block/qcow2-snapshot.c +0 -18
@@ -740,12 +740,6 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)ROUND_UP (sn->vm_state_size, s->cluster_size), QCOW2_DISCARD_NEVER, false); -#ifdef DEBUG_ALLOC - { -BdrvCheckResult result = {0 }; -qcow2_check_refcounts (bs, &result,0 ); - } -#endif return 0 ; fail:
@@ -893,12 +887,6 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) goto fail; } -#ifdef DEBUG_ALLOC - { -BdrvCheckResult result = {0 }; -qcow2_check_refcounts (bs, &result,0 ); - } -#endif return 0 ; fail:
@@ -975,12 +963,6 @@ int qcow2_snapshot_delete(BlockDriverState *bs,return ret; } -#ifdef DEBUG_ALLOC - { -BdrvCheckResult result = {0 }; -qcow2_check_refcounts (bs, &result,0 ); - } -#endif return 0 ; }
Signature · 1 line
2.55.0
Re: [PATCH 5/8] qcow2: remove invalid qcow2_check_refcounts calls
Quoted 14 lines · Marc-André Lureau
Those DEBUG_ALLOC-guarded are dead code incorrectly calling coroutine fn from non-coroutine. Remove it.
Signed-off-by Marc-André Lureau <[email protected]>--- block/qcow2-snapshot.c | 18 ------------------ 1 file changed, 18 deletions(-)block/qcow2-snapshot.c +0
-0@@ -740,12 +740,6 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) ROUND_UP(sn->vm_state_size, s->cluster_size),
block/qcow2-snapshot.c int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) · line 744
Quoted 10 lines
block/qcow2-snapshot.c +0
-6QCOW2_DISCARD_NEVER, false); -#ifdef DEBUG_ALLOC - { -BdrvCheckResult result = {0 }; -qcow2_check_refcounts (bs, &result,0 ); - } -#endif return 0 ;
While here we could remove DEBUG_ALLOC:
-- >8 --
block/qcow2.h +0 -1
@@ -33,3 +33,2 @@ -//#define DEBUG_ALLOC //#define DEBUG_ALLOC2
block/qcow2.c +0 -7
@@ -1965,9 +1965,2 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, -#ifdef DEBUG_ALLOC - { -BdrvCheckResult result = {0 }; -qcow2_check_refcounts (bs, &result,0 ); - } -#endif -qemu_co_queue_init (&s->thread_task_queue);
---
PATCH 6/8 block: add missing coroutine_fn annotations
In reply to Marc-André LureauThe functions call coroutine functions or are called by coroutine.
Add an assert() in qcow2_do_close() code path which calls a no_coroutine_fn bdrv_graph_wrlock_drained().
--- include/block/blockjob_int.h | 2 +- block/crypto.c | 13 +++++++------ block/io.c | 8 +++++--- block/parallels.c | 5 +++-- block/qcow2.c | 11 +++++++---- blockjob.c | 3 ++- 6 files changed, 25 insertions(+), 17 deletions(-)
include/block/blockjob_int.h +1 -1
@@ -150,7 +150,7 @@ void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n);* Put the job to sleep (assuming that it wasn't canceled) to throttle it to the * right speed according to its rate limiting. */ -void block_job_ratelimit_sleep (BlockJob *job); +void coroutine_fn block_job_ratelimit_sleep(BlockJob *job);/** * block_job_error_action:
block/crypto.c +7 -6
@@ -56,12 +56,13 @@ static int block_crypto_probe_generic(QCryptoBlockFormat format, } -static int block_crypto_read_func (QCryptoBlock *block, -size_t offset, -uint8_t *buf, -size_t buflen, -void *opaque, -Error **errp) +static int coroutine_mixed_fn +block_crypto_read_func (QCryptoBlock *block, +size_t offset, +uint8_t *buf, +size_t buflen, +void *opaque, +Error **errp) {BlockDriverState *bs = opaque;BlockCrypto *crypto = bs->opaque;
block/io.c +5 -3
@@ -346,8 +346,9 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,assert (data.done); } -static void bdrv_do_drained_begin (BlockDriverState *bs,BdrvChild *parent, -bool poll) +static void coroutine_mixed_fn +bdrv_do_drained_begin (BlockDriverState *bs,BdrvChild *parent, +bool poll) {IO_OR_GS_CODE ();
@@ -397,7 +398,8 @@ bdrv_drained_begin(BlockDriverState *bs)* This function does not poll, nor must any of its recursively called * functions. */ -static void bdrv_do_drained_end (BlockDriverState *bs,BdrvChild *parent) +static void coroutine_mixed_fn +bdrv_do_drained_end (BlockDriverState *bs,BdrvChild *parent) {IO_OR_GS_CODE ();
block/parallels.c +3 -2
@@ -142,8 +142,9 @@ static uint32_t host_cluster_index(BDRVParallelsState *s, int64_t off)return off / s->cluster_size; } -static int64_t block_status (BDRVParallelsState *s,int64_t sector_num, -int nb_sectors,int *pnum) +static int64_t coroutine_fn +block_status (BDRVParallelsState *s,int64_t sector_num, +int nb_sectors,int *pnum) {int64_t start_off =-2 , prev_end_off =-2 ;
block/qcow2.c +7 -4
@@ -1287,9 +1287,10 @@ fail: }/* s_locked specifies whether s->lock is held or not */ -static void qcow2_update_options_commit (BlockDriverState *bs, -Qcow2ReopenState *r, -bool s_locked) +static void coroutine_fn +qcow2_update_options_commit (BlockDriverState *bs, +Qcow2ReopenState *r, +bool s_locked) {BDRVQcow2State *s = bs->opaque;int i;
@@ -2126,7 +2127,8 @@ fail:return ret; } -static void qcow2_reopen_commit (BDRVReopenState *state) +static void coroutine_fn +qcow2_reopen_commit (BDRVReopenState *state) {BDRVQcow2State *s = state->bs->opaque;
@@ -2905,6 +2907,7 @@ qcow2_do_close(BlockDriverState *bs, bool close_data_file)g_free (s->image_backing_format);if (close_data_file &&has_data_file (bs)) { +assert (!qemu_in_coroutine ());GLOBAL_STATE_CODE ();bdrv_graph_rdunlock_main_loop ();bdrv_graph_wrlock_drained ();
blockjob.c +2 -1
@@ -338,7 +338,8 @@ void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n)ratelimit_calculate_delay (&job->limit, n); } -void block_job_ratelimit_sleep (BlockJob *job) +void coroutine_fn +block_job_ratelimit_sleep (BlockJob *job) {uint64_t delay_ns;
Signature · 1 line
2.55.0
Re: [PATCH 6/8] block: add missing coroutine_fn annotations
Quoted 6 lines · Marc-André Lureau
The functions call coroutine functions or are called by coroutine.
Add an
assert()inqcow2_do_close()code path which calls ano_coroutine_fnbdrv_graph_wrlock_drained().Signed-off-by Marc-André Lureau <[email protected]>
Quoted 8 lines
--- include/block/blockjob_int.h | 2 +- block/crypto.c | 13 +++++++------ block/io.c | 8 +++++--- block/parallels.c | 5 +++-- block/qcow2.c | 11 +++++++---- blockjob.c | 3 ++- 6 files changed, 25 insertions(+), 17 deletions(-)
Too many distinct code paths in a single patch to my taste, I'll skip.
Re: [PATCH 6/8] block: add missing coroutine_fn annotations
In reply to Marc-André LureauQuoted 136 lines · Marc-André Lureau
The functions call coroutine functions or are called by coroutine.
Add an
assert()inqcow2_do_close()code path which calls ano_coroutine_fnbdrv_graph_wrlock_drained().Signed-off-by Marc-André Lureau <[email protected]>--- include/block/blockjob_int.h | 2 +- block/crypto.c | 13 +++++++------ block/io.c | 8 +++++--- block/parallels.c | 5 +++-- block/qcow2.c | 11 +++++++---- blockjob.c | 3 ++- 6 files changed, 25 insertions(+), 17 deletions(-)include/block/blockjob_int.h +1
-1@@ -150,7 +150,7 @@ void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n);* Put the job to sleep (assuming that it wasn't canceled) to throttle it to the * right speed according to its rate limiting. */ -void block_job_ratelimit_sleep (BlockJob *job); +void coroutine_fn block_job_ratelimit_sleep(BlockJob *job);/** * block_job_error_action: block/crypto.c +7
-6@@ -56,12 +56,13 @@ static int block_crypto_probe_generic(QCryptoBlockFormat format, } -static int block_crypto_read_func (QCryptoBlock *block, -size_t offset, -uint8_t *buf, -size_t buflen, -void *opaque, -Error **errp) +static int coroutine_mixed_fn +block_crypto_read_func (QCryptoBlock *block, +size_t offset, +uint8_t *buf, +size_t buflen, +void *opaque, +Error **errp) {BlockDriverState *bs = opaque;BlockCrypto *crypto = bs->opaque;block/io.c +5
-3@@ -346,8 +346,9 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,assert (data.done); } -static void bdrv_do_drained_begin (BlockDriverState *bs,BdrvChild *parent, -bool poll) +static void coroutine_mixed_fn +bdrv_do_drained_begin (BlockDriverState *bs,BdrvChild *parent, +bool poll) {IO_OR_GS_CODE ();@@ -397,7 +398,8 @@ bdrv_drained_begin(BlockDriverState *bs)* This function does not poll, nor must any of its recursively called * functions. */ -static void bdrv_do_drained_end (BlockDriverState *bs,BdrvChild *parent) +static void coroutine_mixed_fn +bdrv_do_drained_end (BlockDriverState *bs,BdrvChild *parent) {IO_OR_GS_CODE ();block/parallels.c +3
-2@@ -142,8 +142,9 @@ static uint32_t host_cluster_index(BDRVParallelsState *s, int64_t off)return off / s->cluster_size; } -static int64_t block_status (BDRVParallelsState *s,int64_t sector_num, -int nb_sectors,int *pnum) +static int64_t coroutine_fn +block_status (BDRVParallelsState *s,int64_t sector_num, +int nb_sectors,int *pnum) {int64_t start_off =-2 , prev_end_off =-2 ;block/qcow2.c +7
-4@@ -1287,9 +1287,10 @@ fail: }/* s_locked specifies whether s->lock is held or not */ -static void qcow2_update_options_commit (BlockDriverState *bs, -Qcow2ReopenState *r, -bool s_locked) +static void coroutine_fn +qcow2_update_options_commit (BlockDriverState *bs, +Qcow2ReopenState *r, +bool s_locked) {BDRVQcow2State *s = bs->opaque;int i;@@ -2126,7 +2127,8 @@ fail:return ret; } -static void qcow2_reopen_commit (BDRVReopenState *state) +static void coroutine_fn +qcow2_reopen_commit (BDRVReopenState *state) {BDRVQcow2State *s = state->bs->opaque;@@ -2905,6 +2907,7 @@ qcow2_do_close(BlockDriverState *bs, bool close_data_file)g_free (s->image_backing_format);if (close_data_file &&has_data_file (bs)) { +assert (!qemu_in_coroutine ());GLOBAL_STATE_CODE ();bdrv_graph_rdunlock_main_loop ();bdrv_graph_wrlock_drained ();blockjob.c +0
-0
blockjob.c void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n) · line 345
Quoted 9 lines
blockjob.c +2
-1@@ -338,7 +338,8 @@ void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n)ratelimit_calculate_delay (&job->limit, n); } -void block_job_ratelimit_sleep (BlockJob *job) +void coroutine_fn +block_job_ratelimit_sleep (BlockJob *job) {uint64_t delay_ns;
Re: [PATCH 6/8] block: add missing coroutine_fn annotations
In reply to Marc-André LureauAm 20.07.2026 um 09:55 hat Marc-André Lureau geschrieben:
Quoted 1 line
The functions call coroutine functions or are called by coroutine.
That it's called only by coroutines isn't a reason to make a function coroutine_fn as long as it theoretically could be called by non-coroutine code and it would still work fine (i.e. it doesn't yield).
Quoted 11 lines
Add an
assert()inqcow2_do_close()code path which calls ano_coroutine_fnbdrv_graph_wrlock_drained().Signed-off-by Marc-André Lureau <[email protected]>block/parallels.c +0
-0@@ -142,8 +142,9 @@ static uint32_t host_cluster_index(BDRVParallelsState *s, int64_t off)return off / s->cluster_size;
block/parallels.c static uint32_t host_cluster_index(BDRVParallelsState *s, int64_t off) · line 150
Quoted 10 lines
block/parallels.c +3
-2} -static int64_t block_status (BDRVParallelsState *s,int64_t sector_num, -int nb_sectors,int *pnum) +static int64_t coroutine_fn +block_status (BDRVParallelsState *s,int64_t sector_num, +int nb_sectors,int *pnum) {int64_t start_off =-2 , prev_end_off =-2 ;
Specifically this hunk is unclear to me.
As far as I can see, block_status() can't yield. Why did you add the coroutine_fn marker here, but not e.g. for seek_to_sector() or cluster_remainder(), which are only called by block_status() and therefore also always only in coroutine context?
I believe the right way to stay consistent is to leave all of them unmarked because there is no fundamental reason why they would only make sense in coroutine context.
Quoted 19 lines
block/qcow2.c +4
-3@@ -1287,9 +1287,10 @@ fail: }/* s_locked specifies whether s->lock is held or not */ -static void qcow2_update_options_commit (BlockDriverState *bs, -Qcow2ReopenState *r, -bool s_locked) +static void coroutine_fn +qcow2_update_options_commit (BlockDriverState *bs, +Qcow2ReopenState *r, +bool s_locked) {BDRVQcow2State *s = bs->opaque;int i;
block/qcow2.c fail: · line 2134
Quoted 9 lines
block/qcow2.c +2
-1@@ -2126,7 +2127,8 @@ fail:return ret; } -static void qcow2_reopen_commit (BDRVReopenState *state) +static void coroutine_fn +qcow2_reopen_commit (BDRVReopenState *state) {BDRVQcow2State *s = state->bs->opaque;
This doesn't match the declaration of the .bdrv_reopen_commit callback in BlockDriver, and as far as I can see, the callers are actually guaranteed to _not_ be in coroutine context.
If this is true, qcow2_update_options_commit() should probably be marked coroutine_mixed_fn and this one stay unannotated or no_coroutine_fn.
The other parts of the patch looks correct.
Kevin
Re: [PATCH 6/8] block: add missing coroutine_fn annotations
Hi
Quoted 32 lines · Kevin Wolf
Am 20.07.2026 um 09:55 hat Marc-André Lureau geschrieben:
Quoted 1 line
The functions call coroutine functions or are called by coroutine.
That it's called only by coroutines isn't a reason to make a function
coroutine_fnas long as it theoretically could be called by non-coroutine code and it would still work fine (i.e. it doesn't yield).Quoted 11 lines
Add an
assert()inqcow2_do_close()code path which calls ano_coroutine_fnbdrv_graph_wrlock_drained().Signed-off-by Marc-André Lureau <[email protected]>block/parallels.c +0
-0@@ -142,8 +142,9 @@ static uint32_t host_cluster_index(BDRVParallelsState *s, int64_t off)return off / s->cluster_size;block/parallels.c static uint32_t host_cluster_index(BDRVParallelsState *s, int64_t off) · line 150
Quoted 10 lines
block/parallels.c +3
-2} -static int64_t block_status (BDRVParallelsState *s,int64_t sector_num, -int nb_sectors,int *pnum) +static int64_t coroutine_fn +block_status (BDRVParallelsState *s,int64_t sector_num, +int nb_sectors,int *pnum) {int64_t start_off =-2 , prev_end_off =-2 ;Specifically this hunk is unclear to me.
Quoted 5 lines
As far as I can see,
block_status()can't yield. Why did you add thecoroutine_fnmarker here, but not e.g. forseek_to_sector()orcluster_remainder(), which are only called byblock_status()and therefore also always only in coroutine context?
Indeed, that's a wrong annotation I added
Quoted 37 lines
I believe the right way to stay consistent is to leave all of them unmarked because there is no fundamental reason why they would only make sense in coroutine context.
Quoted 19 lines
block/qcow2.c +4
-3@@ -1287,9 +1287,10 @@ fail: }/* s_locked specifies whether s->lock is held or not */ -static void qcow2_update_options_commit (BlockDriverState *bs, -Qcow2ReopenState *r, -bool s_locked) +static void coroutine_fn +qcow2_update_options_commit (BlockDriverState *bs, +Qcow2ReopenState *r, +bool s_locked) {BDRVQcow2State *s = bs->opaque;int i;block/qcow2.c fail: · line 2134
Quoted 9 lines
block/qcow2.c +2
-1@@ -2126,7 +2127,8 @@ fail:return ret; } -static void qcow2_reopen_commit (BDRVReopenState *state) +static void coroutine_fn +qcow2_reopen_commit (BDRVReopenState *state) {BDRVQcow2State *s = state->bs->opaque;This doesn't match the declaration of the .bdrv_reopen_commit callback in BlockDriver, and as far as I can see, the callers are actually guaranteed to _not_ be in coroutine context.
Quoted 2 lines
If this is true,
qcow2_update_options_commit()should probably be markedcoroutine_mixed_fnand this one stay unannotated orno_coroutine_fn.
it calls qcow2_update_options_commit(), which itself calls coroutine cache_clean_timer_co_locked_del_and_wait(bs).
But since s_locked is false, the function is safe it call in non-coroutine.
Given that there are 2 callers, I suggest we move the coroutine call outside and drop the annotation.
Quoted 6 lines
The other parts of the patch looks correct.
Kevin
PATCH 7/8 hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
In reply to Marc-André LureauAll V9fsTransport callbacks are invoked exclusively from coroutine context (the v9fs_* PDU handlers). Annotate the function pointer types in V9fsTransport and all implementations (virtio and xen backends), as well as intermediate callers in 9p.c (pdu_marshal, pdu_unmarshal, v9fs_init_qiov_from_pdu, etc.).
--- hw/9pfs/9p.h | 26 +++++++++++++++----------- hw/9pfs/9p.c | 31 +++++++++++++++++++------------ hw/9pfs/virtio-9p-device.c | 24 +++++++++++++----------- hw/9pfs/xen-9p-backend.c | 34 +++++++++++++++++----------------- 4 files changed, 64 insertions(+), 51 deletions(-)
hw/9pfs/9p.h +15 -11
@@ -472,17 +472,21 @@ void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr);void v9fs_reset (V9fsState *s);struct V9fsTransport { -ssize_t (*pdu_vmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -void (*init_in_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size); -void (*init_out_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size); -void (*push_and_notify)(V9fsPDU *pdu); -size_t (*msize_limit)(V9fsState *s); -size_t (*response_buffer_size)(V9fsPDU *pdu); + ssize_t coroutine_fn (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, +const char *fmt,va_list ap); + ssize_t coroutine_fn (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, +const char *fmt,va_list ap); + void coroutine_fn (*init_in_iov_from_pdu)(V9fsPDU *pdu, +struct iovec **piov, +unsigned int *pniov, +size_t size); + void coroutine_fn (*init_out_iov_from_pdu)(V9fsPDU *pdu, +struct iovec **piov, +unsigned int *pniov, +size_t size); + void coroutine_fn (*push_and_notify)(V9fsPDU *pdu); + size_t coroutine_fn (*msize_limit)(V9fsState *s); + size_t coroutine_fn (*response_buffer_size)(V9fsPDU *pdu); };#endif
hw/9pfs/9p.c +19 -12
@@ -55,7 +55,8 @@ enum {P9ARRAY_DEFINE_TYPE (V9fsPath, v9fs_path_free); -static ssize_t pdu_marshal (V9fsPDU *pdu,size_t offset,const char *fmt, ...) +static ssize_t coroutine_fn +pdu_marshal (V9fsPDU *pdu,size_t offset,const char *fmt, ...) {ssize_t ret;va_list ap;
@@ -67,7 +68,8 @@ static ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)return ret; } -static ssize_t pdu_unmarshal (V9fsPDU *pdu,size_t offset,const char *fmt, ...) +static ssize_t coroutine_fn +pdu_unmarshal (V9fsPDU *pdu,size_t offset,const char *fmt, ...) {ssize_t ret;va_list ap;
@@ -1841,7 +1843,8 @@ out_nofid:pdu_complete (pdu, err); } -static int v9fs_walk_marshal (V9fsPDU *pdu,uint16_t nwnames,V9fsQID *qids) +static int coroutine_fn +v9fs_walk_marshal (V9fsPDU *pdu,uint16_t nwnames,V9fsQID *qids) {int i;ssize_t err;
@@ -2363,9 +2366,10 @@ out_nofid:* The resulting QEMUIOVector has heap-allocated iovecs and must be cleaned up * with qemu_iovec_destroy(). */ -static void v9fs_init_qiov_from_pdu (QEMUIOVector *qiov,V9fsPDU *pdu, -size_t skip,size_t size, -bool is_write) +static void coroutine_fn +v9fs_init_qiov_from_pdu (QEMUIOVector *qiov,V9fsPDU *pdu, +size_t skip,size_t size, +bool is_write) {QEMUIOVector elem;struct iovec *iov;
@@ -2382,8 +2386,9 @@ static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu,qemu_iovec_concat (qiov, &elem, skip, size); } -static int v9fs_xattr_read (V9fsState *s,V9fsPDU *pdu,V9fsFidState *fidp, -uint64_t off,uint32_t max_count) +static int coroutine_fn +v9fs_xattr_read (V9fsState *s,V9fsPDU *pdu,V9fsFidState *fidp, +uint64_t off,uint32_t max_count) {ssize_t err;size_t offset =7 ;
@@ -2793,9 +2798,10 @@ out_nofid:pdu_complete (pdu, retval); } -static int v9fs_xattr_write (V9fsState *s,V9fsPDU *pdu,V9fsFidState *fidp, -uint64_t off,uint32_t count, -struct iovec *sg,int cnt) +static int coroutine_fn +v9fs_xattr_write (V9fsState *s,V9fsPDU *pdu,V9fsFidState *fidp, +uint64_t off,uint32_t count, +struct iovec *sg,int cnt) {int i, to_copy;ssize_t err =0 ;
@@ -3729,7 +3735,8 @@ out_nofid:pdu_complete (pdu, err); } -static int v9fs_fill_statfs (V9fsState *s,V9fsPDU *pdu,struct statfs *stbuf) +static int coroutine_fn +v9fs_fill_statfs (V9fsState *s,V9fsPDU *pdu,struct statfs *stbuf) {uint32_t f_type;uint32_t f_bsize;
hw/9pfs/virtio-9p-device.c +13 -11
@@ -28,7 +28,7 @@#include "qemu/module.h" #include "system/qtest.h" -static void virtio_9p_push_and_notify (V9fsPDU *pdu) +static void coroutine_fn virtio_9p_push_and_notify(V9fsPDU *pdu) {V9fsState *s = pdu->s;V9fsVirtioState *v =container_of (s, V9fsVirtioState, state);
@@ -117,8 +117,8 @@ static void virtio_9p_reset(VirtIODevice *vdev)v9fs_reset (&v->state); } -static ssize_t virtio_pdu_vmarshal (V9fsPDU *pdu,size_t offset, -const char *fmt,va_list ap) +static ssize_t coroutine_fn +virtio_pdu_vmarshal (V9fsPDU *pdu,size_t offset,const char *fmt,va_list ap) {V9fsState *s = pdu->s;V9fsVirtioState *v =container_of (s, V9fsVirtioState, state);
@@ -135,8 +135,8 @@ static ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,return ret; } -static ssize_t virtio_pdu_vunmarshal (V9fsPDU *pdu,size_t offset, -const char *fmt,va_list ap) +static ssize_t coroutine_fn +virtio_pdu_vunmarshal (V9fsPDU *pdu,size_t offset,const char *fmt,va_list ap) {V9fsState *s = pdu->s;V9fsVirtioState *v =container_of (s, V9fsVirtioState, state);
@@ -152,8 +152,9 @@ static ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,return ret; } -static void virtio_init_in_iov_from_pdu (V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size) +static void coroutine_fn +virtio_init_in_iov_from_pdu (V9fsPDU *pdu,struct iovec **piov, +unsigned int *pniov,size_t size) {V9fsState *s = pdu->s;V9fsVirtioState *v =container_of (s, V9fsVirtioState, state);
@@ -172,8 +173,9 @@ static void virtio_init_in_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov, *pniov = elem->in_num; } -static void virtio_init_out_iov_from_pdu (V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size) +static void coroutine_fn +virtio_init_out_iov_from_pdu (V9fsPDU *pdu,struct iovec **piov, +unsigned int *pniov,size_t size) {V9fsState *s = pdu->s;V9fsVirtioState *v =container_of (s, V9fsVirtioState, state);
@@ -192,13 +194,13 @@ static void virtio_init_out_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov, *pniov = elem->out_num; } -static size_t virtio_9p_msize_limit (V9fsState *s) +static size_t coroutine_fn virtio_9p_msize_limit(V9fsState *s) {const size_t guestPageSize =4096 ;return (VIRTQUEUE_MAX_SIZE -2 ) * guestPageSize; } -static size_t virtio_9p_response_buffer_size (V9fsPDU *pdu) +static size_t coroutine_fn virtio_9p_response_buffer_size(V9fsPDU *pdu) {V9fsState *s = pdu->s;V9fsVirtioState *v =container_of (s, V9fsVirtioState, state);
hw/9pfs/xen-9p-backend.c +17 -17
@@ -131,10 +131,10 @@ static void xen_9pfs_out_sg(Xen9pfsRing *ring, } } -static ssize_t xen_9pfs_pdu_vmarshal (V9fsPDU *pdu, -size_t offset, -const char *fmt, -va_list ap) +static ssize_t coroutine_fn xen_9pfs_pdu_vmarshal(V9fsPDU *pdu, +size_t offset, +const char *fmt, +va_list ap) {Xen9pfsDev *xen_9pfs =container_of (pdu->s, Xen9pfsDev, state);struct iovec in_sg[2 ];
@@ -155,10 +155,10 @@ static ssize_t xen_9pfs_pdu_vmarshal(V9fsPDU *pdu,return ret; } -static ssize_t xen_9pfs_pdu_vunmarshal (V9fsPDU *pdu, -size_t offset, -const char *fmt, -va_list ap) +static ssize_t coroutine_fn xen_9pfs_pdu_vunmarshal(V9fsPDU *pdu, +size_t offset, +const char *fmt, +va_list ap) {Xen9pfsDev *xen_9pfs =container_of (pdu->s, Xen9pfsDev, state);struct iovec out_sg[2 ];
@@ -178,10 +178,10 @@ static ssize_t xen_9pfs_pdu_vunmarshal(V9fsPDU *pdu,return ret; } -static void xen_9pfs_init_out_iov_from_pdu (V9fsPDU *pdu, -struct iovec **piov, -unsigned int *pniov, -size_t size) +static void coroutine_fn xen_9pfs_init_out_iov_from_pdu(V9fsPDU *pdu, +struct iovec **piov, +unsigned int *pniov, +size_t size) {Xen9pfsDev *xen_9pfs =container_of (pdu->s, Xen9pfsDev, state);Xen9pfsRing *ring = &xen_9pfs->rings[pdu->tag % xen_9pfs->num_rings];
@@ -195,10 +195,10 @@ static void xen_9pfs_init_out_iov_from_pdu(V9fsPDU *pdu, *pniov = num; } -static void xen_9pfs_init_in_iov_from_pdu (V9fsPDU *pdu, -struct iovec **piov, -unsigned int *pniov, -size_t size) +static void coroutine_fn xen_9pfs_init_in_iov_from_pdu(V9fsPDU *pdu, +struct iovec **piov, +unsigned int *pniov, +size_t size) {Xen9pfsDev *xen_9pfs =container_of (pdu->s, Xen9pfsDev, state);Xen9pfsRing *ring = &xen_9pfs->rings[pdu->tag % xen_9pfs->num_rings];
@@ -227,7 +227,7 @@ again: *pniov = num; } -static void xen_9pfs_push_and_notify (V9fsPDU *pdu) +static void coroutine_fn xen_9pfs_push_and_notify(V9fsPDU *pdu) {RING_IDX prod;Xen9pfsDev *priv =container_of (pdu->s, Xen9pfsDev, state);
Signature · 1 line
2.55.0
Re: [PATCH 7/8] hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
Quoted 40 lines · On Monday, 20 July 2026 09:55:36 CEST Marc-André Lureau wrote:
All V9fsTransport callbacks are invoked exclusively from coroutine context (the v9fs_* PDU handlers). Annotate the function pointer types in V9fsTransport and all implementations (virtio and xen backends), as well as intermediate callers in
9p.c(pdu_marshal,pdu_unmarshal,v9fs_init_qiov_from_pdu, etc.).Signed-off-by Marc-André Lureau <[email protected]>--- hw/9pfs/9p.h | 26 +++++++++++++++----------- hw/9pfs/9p.c | 31 +++++++++++++++++++------------ hw/9pfs/virtio-9p-device.c | 24 +++++++++++++----------- hw/9pfs/xen-9p-backend.c | 34 +++++++++++++++++----------------- 4 files changed, 64 insertions(+), 51 deletions(-)hw/9pfs/9p.h +6
-11@@ -472,17 +472,21 @@ void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr);void v9fs_reset (V9fsState *s);struct V9fsTransport { -ssize_t (*pdu_vmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -void (*init_in_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size); -void (*init_out_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size); -void (*push_and_notify)(V9fsPDU *pdu); -size_t (*msize_limit)(V9fsState *s); -size_t (*response_buffer_size)(V9fsPDU *pdu); + ssize_t coroutine_fn (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, +const char *fmt,va_list ap); + ssize_t coroutine_fn (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, +const char *fmt,va_list ap); + void coroutine_fn (*init_in_iov_from_pdu)(V9fsPDU *pdu, + struct iovec **piov,
hw/9pfs/9p.h void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr); · line 491
Quoted 10 lines
hw/9pfs/9p.h +9
-0+unsigned int *pniov, + size_t size); + void coroutine_fn (*init_out_iov_from_pdu)(V9fsPDU *pdu, +struct iovec **piov, +unsigned int *pniov, +size_t size); + void coroutine_fn (*push_and_notify)(V9fsPDU *pdu); + size_t coroutine_fn (*msize_limit)(V9fsState *s); + size_t coroutine_fn (*response_buffer_size)(V9fsPDU *pdu); };
I wonder whether that could be made more diff/blame-friendly. Especially as this currently only serves documentation purposes.
They way you are positioning coroutine_fn it usually resolves to an attribute attached to the function's return type, not to the function itself, even though clang/gcc handling it flexible. For attaching an attribute to the function itself the attribute should either be attached before the function declaration or after the function declaration. In both cases you could then add it to its own, separate line, avoiding a lot of noise.
/Christian
Re: [PATCH 7/8] hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
Quoted 55 lines · Christian Schoenebeck
Quoted 40 lines · On Monday, 20 July 2026 09:55:36 CEST Marc-André Lureau wrote:
All V9fsTransport callbacks are invoked exclusively from coroutine context (the v9fs_* PDU handlers). Annotate the function pointer types in V9fsTransport and all implementations (virtio and xen backends), as well as intermediate callers in
9p.c(pdu_marshal,pdu_unmarshal,v9fs_init_qiov_from_pdu, etc.).Signed-off-by Marc-André Lureau <[email protected]>--- hw/9pfs/9p.h | 26 +++++++++++++++----------- hw/9pfs/9p.c | 31 +++++++++++++++++++------------ hw/9pfs/virtio-9p-device.c | 24 +++++++++++++----------- hw/9pfs/xen-9p-backend.c | 34 +++++++++++++++++----------------- 4 files changed, 64 insertions(+), 51 deletions(-)hw/9pfs/9p.h +6
-11@@ -472,17 +472,21 @@ void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr);void v9fs_reset (V9fsState *s);struct V9fsTransport { -ssize_t (*pdu_vmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -void (*init_in_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size); -void (*init_out_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size); -void (*push_and_notify)(V9fsPDU *pdu); -size_t (*msize_limit)(V9fsState *s); -size_t (*response_buffer_size)(V9fsPDU *pdu); + ssize_t coroutine_fn (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, +const char *fmt,va_list ap); + ssize_t coroutine_fn (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, +const char *fmt,va_list ap); + void coroutine_fn (*init_in_iov_from_pdu)(V9fsPDU *pdu, + struct iovec **piov,hw/9pfs/9p.h void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr); · line 491
Quoted 10 lines
hw/9pfs/9p.h +9
-0+unsigned int *pniov, + size_t size); + void coroutine_fn (*init_out_iov_from_pdu)(V9fsPDU *pdu, +struct iovec **piov, +unsigned int *pniov, +size_t size); + void coroutine_fn (*push_and_notify)(V9fsPDU *pdu); + size_t coroutine_fn (*msize_limit)(V9fsState *s); + size_t coroutine_fn (*response_buffer_size)(V9fsPDU *pdu); };I wonder whether that could be made more diff/blame-friendly. Especially as this currently only serves documentation purposes.
Quoted 5 lines
They way you are positioning
coroutine_fnit usually resolves to an attribute attached to the function's return type, not to the function itself, even though clang/gcc handling it flexible. For attaching an attribute to the function itself the attribute should either be attached before the function declaration or after the function declaration.
I tend to aggree it would be clearer to have these attributes /before/ the function prototype declaration.
Quoted 8 lines
In both cases you could then
add it to its own, separate line, avoiding a lot of noise./Christian
Re: [PATCH 7/8] hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
Quoted 70 lines · Philippe Mathieu-Daudé
Quoted 69 lines · Christian Schoenebeck
Quoted 56 lines · On Monday, 20 July 2026 09:55:36 CEST Marc-André Lureau wrote:
All V9fsTransport callbacks are invoked exclusively from coroutine context (the v9fs_* PDU handlers). Annotate the function pointer types in V9fsTransport and all implementations (virtio and xen backends), as well as intermediate callers in
9p.c(pdu_marshal,pdu_unmarshal,v9fs_init_qiov_from_pdu, etc.).Signed-off-by Marc-André Lureau <[email protected]>---
hw/9pfs/9p.h | 26 +++++++++++++++----------- hw/9pfs/9p.c | 31 +++++++++++++++++++------------hw/9pfs/virtio-9p-device.c| 24 +++++++++++++----------- hw/9pfs/xen-9p-backend.c | 34 +++++++++++++++++-----------------4 files changed, 64 insertions(+), 51 deletions(-)hw/9pfs/9p.h +0
-8@@ -472,17 +472,21 @@ void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr); void v9fs_reset(V9fsState *s); struct V9fsTransport { - ssize_t (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, constchar *fmt, - va_list ap); - ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt, - va_list ap); - void (*init_in_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov, - unsigned int *pniov, size_t size); - void (*init_out_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov, - unsigned int *pniov, size_tsize);
- void (*push_and_notify)(V9fsPDU *pdu);
- size_t (*msize_limit)(V9fsState *s);
- size_t (*response_buffer_size)(V9fsPDU *pdu);
+ ssize_tcoroutine_fn(*pdu_vmarshal)(V9fsPDU *pdu,size_toffset,
+ const char *fmt,va_listap);
+ ssize_tcoroutine_fn(*pdu_vunmarshal)(V9fsPDU *pdu,size_toffset,
+ const char *fmt,va_listap);
+ voidcoroutine_fn(*init_in_iov_from_pdu)(V9fsPDU *pdu, + struct iovec **piov,
+ unsigned int *pniov,
+size_tsize); + voidcoroutine_fn(*init_out_iov_from_pdu)(V9fsPDU *pdu, + struct iovecQuoted 8 lines
**piov,
+ unsigned int *pniov,
+size_tsize); + voidcoroutine_fn(*push_and_notify)(V9fsPDU *pdu); + size_tcoroutine_fn(*msize_limit)(V9fsState *s); + size_tcoroutine_fn(*response_buffer_size)(V9fsPDU *pdu); };I wonder whether that could be made more diff/blame-friendly. Especially as this currently only serves documentation purposes.
Quoted 8 lines
Quoted 5 lines
They way you are positioning
coroutine_fnit usually resolves to an attribute attached to the function's return type, not to the function itself, even though clang/gcc handling it flexible. For attaching an attribute to the function itself the attribute should either be attached before the function declaration or after the function declaration.I tend to aggree it would be clearer to have these attributes /before/ the function prototype declaration.
$ git grep -E '^(static )?coroutine_(mixed_)?fn' | wc -l
90block/block-copy.c:47:static coroutine_fn int block_copy_task_entry(AioTask *task); block/copy-before-write.c:106:static coroutine_fn int cbw_do_copy_before_write(BlockDriverState *bs, block/nvme.c:1351:static coroutine_fn int nvme_co_flush(BlockDriverState *bs) block/ssh.c:1223:static coroutine_fn int ssh_flush(BDRVSSHState *s, BlockDriverState *bs) nbd/server.c:3077:static coroutine_fn void nbd_trip(void *opaque) block/block-copy.c:581:static coroutine_fn int block_copy_task_entry(AioTask *task)
...
Quoted 11 lines
Quoted 9 lines
In both cases you could then
add it to its own, separate line, avoiding a lot of noise./Christian
Re: [PATCH 7/8] hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
Hi
Quoted 81 lines · Philippe Mathieu-Daudé
Quoted 79 lines · Philippe Mathieu-Daudé
Quoted 77 lines · Christian Schoenebeck
Quoted 59 lines · On Monday, 20 July 2026 09:55:36 CEST Marc-André Lureau wrote:
All V9fsTransport callbacks are invoked exclusively from coroutine context (the v9fs_* PDU handlers). Annotate the function pointer types in V9fsTransport and all implementations (virtio and xen backends), as well as intermediate callers in
9p.c(pdu_marshal,pdu_unmarshal,v9fs_init_qiov_from_pdu, etc.).Signed-off-by Marc-André Lureau <[email protected]>--- hw/9pfs/9p.h | 26 +++++++++++++++----------- hw/9pfs/9p.c | 31 +++++++++++++++++++------------ hw/9pfs/virtio-9p-device.c | 24 +++++++++++++----------- hw/9pfs/xen-9p-backend.c | 34 +++++++++++++++++----------------- 4 files changed, 64 insertions(+), 51 deletions(-)hw/9pfs/9p.h +0
-8@@ -472,17 +472,21 @@ void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr);void v9fs_reset (V9fsState *s);struct V9fsTransport { -ssize_t (*pdu_vmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -void (*init_in_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size); -void (*init_out_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, - unsigned int *pniov, size_tsize);
hw/9pfs/9p.h +1
-3-void (*push_and_notify)(V9fsPDU *pdu); -size_t (*msize_limit)(V9fsState *s); -size_t (*response_buffer_size)(V9fsPDU *pdu); + ssize_t coroutine_fn (*pdu_vmarshal)(V9fsPDU *pdu, size_toffset,
+ const char *fmt,va_listap);
+ssize_tcoroutine_fn(*pdu_vunmarshal)(V9fsPDU *pdu,size_t
offset,
+ const char *fmt,va_listap);hw/9pfs/9p.h +2
-0+ void coroutine_fn (*init_in_iov_from_pdu)(V9fsPDU *pdu, + struct iovec**piov,
+ unsigned int
*pniov,hw/9pfs/9p.h +3
-0+ size_t size); + void coroutine_fn (*init_out_iov_from_pdu)(V9fsPDU *pdu, + struct iovec**piov,
+ unsigned int
*pniov,hw/9pfs/9p.h void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr); · line 490
Quoted 5 lines
hw/9pfs/9p.h +4
-0+ size_t size); + void coroutine_fn (*push_and_notify)(V9fsPDU *pdu); + size_t coroutine_fn (*msize_limit)(V9fsState *s); + size_t coroutine_fn (*response_buffer_size)(V9fsPDU *pdu); };I wonder whether that could be made more diff/blame-friendly. Especially as
this currently only serves documentation purposes.They way you are positioning
coroutine_fnit usually resolves to an attribute
attached to the function's return type, not to the function itself, even though clang/gcc handling it flexible. For attaching an attribute to the function itself the attribute should either be attached before the function
declaration or after the function declaration.
Quoted 5 lines
Quoted 2 lines
I tend to aggree it would be clearer to have these attributes /before/ the function prototype declaration.
$ git grep -E '^(static )?coroutine_(mixed_)?fn' | wc -l 90
More like
$ git grep -rnE '\b(coroutine_fn|co_wrapper[a-z_]*)\b' | wc -l 1343
most of them are "return-type co_annotation fn(..)" we even have scripts/block-coroutine-wrapper.py that relies and produce this order..
a bit late to change the style imho...
At least, let's not make this a requirement for this series, please
Quoted 25 lines
Quoted 1 line
block/block-copy.c:47:static
coroutine_fnint
block_copy_task_entry(AioTask *task); block/copy-before-write.c:106:staticcoroutine_fnint cbw_do_copy_before_write(BlockDriverState *bs, block/nvme.c:1351:staticcoroutine_fnintnvme_co_flush(BlockDriverState *bs)
block/ssh.c:1223:staticcoroutine_fnintssh_flush(BDRVSSHState *s, BlockDriverState *bs)
nbd/server.c:3077:staticcoroutine_fnvoidnbd_trip(void *opaque)block/block-copy.c:581:staticcoroutine_fnintblock_copy_task_entry(AioTask *task)
...Quoted 11 lines
Quoted 9 lines
In both cases you could then
add it to its own, separate line, avoiding a lot of noise./Christian
Re: [PATCH 7/8] hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
Hi
Quoted 89 lines · Marc-André Lureau
Hi
Quoted 84 lines · Philippe Mathieu-Daudé
Quoted 81 lines · Philippe Mathieu-Daudé
Quoted 70 lines · Christian Schoenebeck
Quoted 59 lines · On Monday, 20 July 2026 09:55:36 CEST Marc-André Lureau wrote:
All V9fsTransport callbacks are invoked exclusively from coroutine context (the v9fs_* PDU handlers). Annotate the function pointer types in V9fsTransport and all implementations (virtio and xen backends), as well as intermediate callers in
9p.c(pdu_marshal,pdu_unmarshal,v9fs_init_qiov_from_pdu, etc.).Signed-off-by Marc-André Lureau <[email protected]>--- hw/9pfs/9p.h | 26 +++++++++++++++----------- hw/9pfs/9p.c | 31 +++++++++++++++++++------------ hw/9pfs/virtio-9p-device.c | 24 +++++++++++++----------- hw/9pfs/xen-9p-backend.c | 34 +++++++++++++++++----------------- 4 files changed, 64 insertions(+), 51 deletions(-)hw/9pfs/9p.h +0
-8@@ -472,17 +472,21 @@ void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr);void v9fs_reset (V9fsState *s);struct V9fsTransport { -ssize_t (*pdu_vmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -void (*init_in_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size); -void (*init_out_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, - unsigned int *pniov, size_tsize);
hw/9pfs/9p.h +1
-3-void (*push_and_notify)(V9fsPDU *pdu); -size_t (*msize_limit)(V9fsState *s); -size_t (*response_buffer_size)(V9fsPDU *pdu); + ssize_t coroutine_fn (*pdu_vmarshal)(V9fsPDU *pdu, size_toffset,
+ const char *fmt,va_listap);
+ssize_tcoroutine_fn(*pdu_vunmarshal)(V9fsPDU *pdu,size_t
offset,
+ const char *fmt,va_listap);hw/9pfs/9p.h +2
-0+ void coroutine_fn (*init_in_iov_from_pdu)(V9fsPDU *pdu, + struct iovec**piov,
+ unsigned int
*pniov,hw/9pfs/9p.h +3
-0+ size_t size); + void coroutine_fn (*init_out_iov_from_pdu)(V9fsPDU *pdu, + struct iovec**piov,
+ unsigned int
*pniov,hw/9pfs/9p.h void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr); · line 490
Quoted 5 lines
hw/9pfs/9p.h +4
-0+ size_t size); + void coroutine_fn (*push_and_notify)(V9fsPDU *pdu); + size_t coroutine_fn (*msize_limit)(V9fsState *s); + size_t coroutine_fn (*response_buffer_size)(V9fsPDU *pdu); };I wonder whether that could be made more diff/blame-friendly. Especially as
this currently only serves documentation purposes.Quoted 7 lines
They way you are positioning
coroutine_fnit usually resolves to an attribute
attached to the function's return type, not to the function itself, even though clang/gcc handling it flexible. For attaching an attribute to the function itself the attribute should either be attached before the function
declaration or after the function declaration.I tend to aggree it would be clearer to have these attributes /before/ the function prototype declaration.
Quoted 7 lines
Quoted 2 lines
$ git grep -E '^(static )?coroutine_(mixed_)?fn' | wc -l 90More like
$ git grep -rnE '\b(coroutine_fn|co_wrapper[a-z_]*)\b' | wc -l 1343
That matching is not accurate, it's actually hard enough to match all annotations instances.. but this should be a rough estimation.
Quoted 32 lines
most of them are "return-type
co_annotationfn(..)" we even havescripts/block-coroutine-wrapper.pythat relies and produce this order..
a bit late to change the style imho...At least, let's not make this a requirement for this series, please
Quoted 25 lines
Quoted 1 line
block/block-copy.c:47:static
coroutine_fnint
block_copy_task_entry(AioTask *task); block/copy-before-write.c:106:staticcoroutine_fnint cbw_do_copy_before_write(BlockDriverState *bs, block/nvme.c:1351:staticcoroutine_fnintnvme_co_flush(BlockDriverState *bs)
block/ssh.c:1223:staticcoroutine_fnintssh_flush(BDRVSSHState *s, BlockDriverState *bs)
nbd/server.c:3077:staticcoroutine_fnvoidnbd_trip(void *opaque)block/block-copy.c:581:staticcoroutine_fnintblock_copy_task_entry(AioTask *task)
...Quoted 11 lines
Quoted 9 lines
In both cases you could then
add it to its own, separate line, avoiding a lot of noise./Christian
Re: [PATCH 7/8] hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
Quoted 96 lines · Marc-André Lureau
Hi
Quoted 92 lines · Marc-André Lureau
Hi
Quoted 86 lines · Philippe Mathieu-Daudé
Quoted 79 lines · Philippe Mathieu-Daudé
Quoted 70 lines · Christian Schoenebeck
Quoted 59 lines · On Monday, 20 July 2026 09:55:36 CEST Marc-André Lureau wrote:
All V9fsTransport callbacks are invoked exclusively from coroutine context (the v9fs_* PDU handlers). Annotate the function pointer types in V9fsTransport and all implementations (virtio and xen backends), as well as intermediate callers in
9p.c(pdu_marshal,pdu_unmarshal,v9fs_init_qiov_from_pdu, etc.).Signed-off-by Marc-André Lureau <[email protected]>--- hw/9pfs/9p.h | 26 +++++++++++++++----------- hw/9pfs/9p.c | 31 +++++++++++++++++++------------ hw/9pfs/virtio-9p-device.c | 24 +++++++++++++----------- hw/9pfs/xen-9p-backend.c | 34 +++++++++++++++++----------------- 4 files changed, 64 insertions(+), 51 deletions(-)hw/9pfs/9p.h +0
-8@@ -472,17 +472,21 @@ void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr);void v9fs_reset (V9fsState *s);struct V9fsTransport { -ssize_t (*pdu_vmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu,size_t offset,const char *fmt, -va_list ap); -void (*init_in_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, -unsigned int *pniov,size_t size); -void (*init_out_iov_from_pdu)(V9fsPDU *pdu,struct iovec **piov, - unsigned int *pniov, size_tsize);
hw/9pfs/9p.h +1
-3-void (*push_and_notify)(V9fsPDU *pdu); -size_t (*msize_limit)(V9fsState *s); -size_t (*response_buffer_size)(V9fsPDU *pdu); + ssize_t coroutine_fn (*pdu_vmarshal)(V9fsPDU *pdu, size_toffset,
+ const char *fmt,va_listap);
+ssize_tcoroutine_fn(*pdu_vunmarshal)(V9fsPDU *pdu,size_t
offset,
+ const char *fmt,va_listap);hw/9pfs/9p.h +2
-0+ void coroutine_fn (*init_in_iov_from_pdu)(V9fsPDU *pdu, + struct iovec**piov,
+ unsigned int
*pniov,hw/9pfs/9p.h +3
-0+ size_t size); + void coroutine_fn (*init_out_iov_from_pdu)(V9fsPDU *pdu, + struct iovec**piov,
+ unsigned int
*pniov,hw/9pfs/9p.h void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr); · line 490
Quoted 5 lines
hw/9pfs/9p.h +4
-0+ size_t size); + void coroutine_fn (*push_and_notify)(V9fsPDU *pdu); + size_t coroutine_fn (*msize_limit)(V9fsState *s); + size_t coroutine_fn (*response_buffer_size)(V9fsPDU *pdu); };I wonder whether that could be made more diff/blame-friendly. Especially as
this currently only serves documentation purposes.Quoted 7 lines
They way you are positioning
coroutine_fnit usually resolves to an attribute
attached to the function's return type, not to the function itself, even though clang/gcc handling it flexible. For attaching an attribute to the function itself the attribute should either be attached before the function
declaration or after the function declaration.Quoted 2 lines
I tend to aggree it would be clearer to have these attributes /before/ the function prototype declaration.
$ git grep -E '^(static )?coroutine_(mixed_)?fn' | wc -l 90
Quoted 14 lines
Quoted 4 lines
More like
$ git grep -rnE '\b(coroutine_fn|co_wrapper[a-z_]*)\b' | wc -l 1343That matching is not accurate, it's actually hard enough to match all annotations instances.. but this should be a rough estimation.
Quoted 6 lines
most of them are "return-type
co_annotationfn(..)" we even havescripts/block-coroutine-wrapper.pythat relies and produce this order..
a bit late to change the style imho...At least, let's not make this a requirement for this series, please
Not a requirement on my side, but if we had to pick a style, I'd vote for "attribute before return type".
Quoted 28 lines
Quoted 26 lines
Quoted 26 lines
Quoted 2 lines
block/block-copy.c:47:static
coroutine_fnint
block_copy_task_entry(AioTask *task); block/copy-before-write.c:106:staticcoroutine_fnint cbw_do_copy_before_write(BlockDriverState *bs, block/nvme.c:1351:staticcoroutine_fnintnvme_co_flush(BlockDriverState *bs)
block/ssh.c:1223:staticcoroutine_fnintssh_flush(BDRVSSHState *s, BlockDriverState *bs)
nbd/server.c:3077:staticcoroutine_fnvoidnbd_trip(void *opaque)block/block-copy.c:581:staticcoroutine_fnintblock_copy_task_entry(AioTask *task)
...Quoted 11 lines
Quoted 9 lines
In both cases you could then
add it to its own, separate line, avoiding a lot of noise./Christian
Re: [PATCH 7/8] hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
Quoted 6 lines · On Tuesday, 21 July 2026 10:25:34 CEST Philippe Mathieu-Daudé wrote:
Quoted 5 lines · Marc-André Lureau
Hi
On Tue, Jul 21, 2026 at 11:58 AM Marc-André Lureau
<[email protected]> wrote:
[...]
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
most of them are "return-type
co_annotationfn(..)" we even havescripts/block-coroutine-wrapper.pythat relies and produce this order..
a bit late to change the style imho...At least, let's not make this a requirement for this series, please
Not a requirement on my side, but if we had to pick a style, I'd vote for "attribute before return type".
Yep, because that's a) the most compiler-friendly option (all compilers allow it, including MSC) and b) it's the most diff-noise friendly solution (can be prepended on its own line without touching any of the existing line(s) at all).
/Christian
Re: [PATCH 7/8] hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
Hi
Quoted 16 lines · Christian Schoenebeck
Quoted 6 lines · On Tuesday, 21 July 2026 10:25:34 CEST Philippe Mathieu-Daudé wrote:
Quoted 5 lines · Marc-André Lureau
Hi
On Tue, Jul 21, 2026 at 11:58 AM Marc-André Lureau
<[email protected]> wrote:
[...]
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
most of them are "return-type
co_annotationfn(..)" we even havescripts/block-coroutine-wrapper.pythat relies and produce this order..
a bit late to change the style imho...At least, let's not make this a requirement for this series, please
Quoted 8 lines
Quoted 2 lines
Not a requirement on my side, but if we had to pick a style, I'd vote for "attribute before return type".
Yep, because that's a) the most compiler-friendly option (all compilers allow it, including MSC) and b) it's the most diff-noise friendly solution (can be prepended on its own line without touching any of the existing line(s) at all).
ok, what should I do? Send a preliminary patch to fix all annotation positions? or just change the position in this patch or series?
Christian Schoenebeck
Acked-byRe: [PATCH 7/8] hw/9pfs: annotate V9fsTransport callbacks as coroutine_fn
Quoted 24 lines · On Tuesday, 21 July 2026 10:39:52 CEST Marc-André Lureau wrote:
Hi
On Tue, Jul 21, 2026 at 12:38 PM Christian Schoenebeck
Quoted 19 lines · <[email protected]> wrote:
Quoted 6 lines · On Tuesday, 21 July 2026 10:25:34 CEST Philippe Mathieu-Daudé wrote:
Quoted 5 lines · Marc-André Lureau
Hi
On Tue, Jul 21, 2026 at 11:58 AM Marc-André Lureau
<[email protected]> wrote:
[...]
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
most of them are "return-type
co_annotationfn(..)" we even havescripts/block-coroutine-wrapper.pythat relies and produce this order..
a bit late to change the style imho...At least, let's not make this a requirement for this series, please
Not a requirement on my side, but if we had to pick a style, I'd vote for "attribute before return type".
Quoted 7 lines
Quoted 4 lines
Yep, because that's a) the most compiler-friendly option (all compilers allow it, including MSC) and b) it's the most diff-noise friendly solution (can be prepended on its own line without touching any of the existing line(s) at all).
ok, what should I do? Send a preliminary patch to fix all annotation positions? or just change the position in this patch or series?
Your decision. I'm just giving my 2cts. As this is not a behaviour change, it is way below my threshold level for taking any strong position. If you can make this for this patch for now, that would nice, but if not, not a deal breaker either:
PATCH 8/8 migration/rdma: annotate and simplify wait_comp_channel()
In reply to Marc-André LureauThe function calls yield_until_fd_readable() (coroutine_fn) when in coroutine context, and polls with qemu_poll_ns() otherwise.
Replace the migration-state proxy check with qemu_in_coroutine(), which directly tests what matters.
--- migration/rdma.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
migration/rdma.c +4 -8
@@ -1348,17 +1348,13 @@ static int qemu_rdma_poll(RDMAContext *rdma, struct ibv_cq *cq,/* Wait for activity on the completion channel. * Returns 0 on success, none-0 on error. */ -static int qemu_rdma_wait_comp_channel (RDMAContext *rdma, -struct ibv_comp_channel *comp_channel) +static int coroutine_mixed_fn +qemu_rdma_wait_comp_channel (RDMAContext *rdma, +struct ibv_comp_channel *comp_channel) {struct rdma_cm_event *cm_event; -/* -* Coroutine doesn't start until migration_fd_process_incoming() -* so don't yield unless we know we're running inside of a coroutine. -*/ -if (rdma->migration_started_on_destination && -migration_incoming_get_current ()->state ==MIGRATION_STATUS_ACTIVE ) { +if (qemu_in_coroutine ()) {yield_until_fd_readable (comp_channel->fd); }else {/* This is the source side, we're in a separate thread
Signature · 1 line
2.55.0
Re: [PATCH 8/8] migration/rdma: annotate and simplify wait_comp_channel()
Quoted 8 lines · Marc-André Lureau
The function calls
yield_until_fd_readable()(coroutine_fn) when in coroutine context, and polls withqemu_poll_ns()otherwise.Replace the migration-state proxy check with
qemu_in_coroutine(), which directly tests what matters.Fixes 2da776db4846 ("rdma: core logic")Signed-off-by Marc-André Lureau <[email protected]>
Just to say we can also drop the var. I have a patch did it already but I didn't get chance to revisit the series:
https://lore.kernel.org/qemu-devel/[email protected]/
So we can also pick that single patch up, then this patch can be annotation-only. I'll leave it to you.
Thanks,
Quoted 34 lines
--- migration/rdma.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)migration/rdma.c +4
-8@@ -1348,17 +1348,13 @@ static int qemu_rdma_poll(RDMAContext *rdma, struct ibv_cq *cq,/* Wait for activity on the completion channel. * Returns 0 on success, none-0 on error. */ -static int qemu_rdma_wait_comp_channel (RDMAContext *rdma, -struct ibv_comp_channel *comp_channel) +static int coroutine_mixed_fn +qemu_rdma_wait_comp_channel (RDMAContext *rdma, +struct ibv_comp_channel *comp_channel) {struct rdma_cm_event *cm_event; -/* -* Coroutine doesn't start until migration_fd_process_incoming() -* so don't yield unless we know we're running inside of a coroutine. -*/ -if (rdma->migration_started_on_destination && -migration_incoming_get_current ()->state ==MIGRATION_STATUS_ACTIVE ) { +if (qemu_in_coroutine ()) {yield_until_fd_readable (comp_channel->fd); }else {/* This is the source side, we're in a separate thread Signature · 2 lines
-- 2.55.0
Signature · 1 line
Peter Xu