io_uring: annotate remote tasks for kcoverage
PATCH 1/1 io_uring: annotate remote tasks for kcoverage
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated by kcov_remote_start and kcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.
The value of the handle needs to be passed by userspace when enabling remote coverage collection. I chose the cgroup ns inum, because it is predictable and flexible enough for consumers to control which group of processes should be included for remote coverage collection, should they create an instance of io-uring.
--- include/linux/io_uring_types.h | 4 ++++ include/uapi/linux/kcov.h | 1 + io_uring/io-wq.c | 4 ++++ io_uring/io_uring.c | 18 ++++++++++++++++++ io_uring/io_uring.h | 22 ++++++++++++++++++++++ io_uring/sqpoll.c | 4 ++++ kernel/kcov.c | 2 ++ 7 files changed, 55 insertions(+)
include/linux/io_uring_types.h +4 -0
@@ -504,6 +504,10 @@ struct io_ring_ctx {struct io_mapped_region ring_region;/* used for optimised request parameter and wait argument passing */ struct io_mapped_region param_region; + +#ifdef CONFIG_KCOV +u64 kcov_handle; +#endif };/*
include/uapi/linux/kcov.h +1 -0
@@ -49,6 +49,7 @@ enum {#define KCOV_SUBSYSTEM_COMMON (0x00ull << 56)#define KCOV_SUBSYSTEM_USB (0x01ull << 56) +#define KCOV_SUBSYSTEM_IOURING (0x02ull << 56)#define KCOV_SUBSYSTEM_MASK (0xffull << 56)#define KCOV_INSTANCE_MASK (0xffffffffull)
io_uring/io-wq.c +4 -0
@@ -639,6 +639,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,/* handle a whole dependent link */ do { struct io_wq_work *next_hashed, *linked; + struct io_kiocb *req; unsigned int work_flags = atomic_read(&work->flags); unsigned int hash = __io_wq_is_hashed(work_flags) ? __io_get_work_hash(work_flags)
@@ -649,7 +650,10 @@ static void io_worker_handle_work(struct io_wq_acct *acct,if (do_kill && (work_flags &IO_WQ_WORK_UNBOUND ))atomic_or (IO_WQ_WORK_CANCEL , &work->flags); + req = container_of(work, struct io_kiocb, work); +io_kcov_remote_start (req->ctx);io_wq_submit_work (work); +io_kcov_remote_stop ();io_assign_current_work (worker,NULL ); linked =io_wq_free_work (work);
io_uring/io_uring.c +18 -0
@@ -222,6 +222,21 @@ static void io_free_alloc_caches(struct io_ring_ctx *ctx)io_rsrc_cache_free (ctx); } +#ifdef CONFIG_KCOV +static __cold u64 io_ring_get_kcov_handle (void ) +{ +struct nsproxy *ns_proxy = current->nsproxy; +struct ns_common *ns; +u64 inst =0 ; + +if (ns_proxy) { + ns =to_ns_common (ns_proxy->cgroup_ns); + inst = ns->inum; + } +return kcov_remote_handle (KCOV_SUBSYSTEM_IOURING , inst); +} +#endif +static __cold struct io_ring_ctx *io_ring_ctx_alloc (struct io_uring_params *p) {struct io_ring_ctx *ctx;
@@ -293,6 +308,9 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)INIT_HLIST_HEAD (&ctx->cancelable_uring_cmd);io_napi_init (ctx);mutex_init (&ctx->mmap_lock); +#ifdef CONFIG_KCOV + ctx->kcov_handle =io_ring_get_kcov_handle (); +#endif return ctx;
io_uring/io_uring.h +22 -0
@@ -7,6 +7,7 @@#include <linux/resume_user_mode.h> #include <linux/poll.h> #include <linux/io_uring_types.h> +#include <linux/kcov.h> #include <uapi/linux/eventpoll.h> #include "alloc_cache.h" #include "io-wq.h"
@@ -581,4 +582,25 @@ static inline bool io_has_work(struct io_ring_ctx *ctx)return test_bit (IO_CHECK_CQ_OVERFLOW_BIT , &ctx->check_cq) || io_local_work_pending(ctx); } + +#ifdef CONFIG_KCOV +static inline void io_kcov_remote_start (struct io_ring_ctx *ctx) +{ +kcov_remote_start (ctx->kcov_handle); +} + +static inline void io_kcov_remote_stop (void ) +{ +kcov_remote_stop (); +} +#else +static inline void io_kcov_remote_start (struct io_ring_ctx *ctx) +{ +} + +static inline void io_kcov_remote_stop (void ) +{ +} +#endif +#endif
io_uring/sqpoll.c +4 -0
@@ -342,19 +342,23 @@ static int io_sq_thread(void *data) cap_entries = !list_is_singular (&sqd->ctx_list);list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +io_kcov_remote_start (ctx);int ret =__io_sq_thread (ctx, sqd, cap_entries, &ist);if (!sqt_spin && (ret >0 || !list_empty (&ctx->iopoll_list))) sqt_spin = true; +io_kcov_remote_stop (); }if (io_sq_tw (&retry_list,IORING_TW_CAP_ENTRIES_VALUE )) sqt_spin = true;list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +io_kcov_remote_start (ctx);if (io_napi (ctx)) {io_sq_start_worktime (&ist);io_napi_sqpoll_busy_poll (ctx); } +io_kcov_remote_stop (); }io_sq_update_worktime (sqd, &ist);
kernel/kcov.c +2 -0
@@ -585,6 +585,8 @@ static inline bool kcov_check_handle(u64 handle, bool common_valid, common_valid : zero_valid;case KCOV_SUBSYSTEM_USB :return uncommon_valid; +case KCOV_SUBSYSTEM_IOURING : +return uncommon_valid;default :return false; }
Signature · 1 line
2.54.0
Andrey Konovalov
reviewerQuoted 44 lines · Robert Femmer
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (
CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated bykcov_remote_startandkcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.The value of the handle needs to be passed by userspace when enabling remote coverage collection. I chose the cgroup ns inum, because it is predictable and flexible enough for consumers to control which group of processes should be included for remote coverage collection, should they create an instance of io-uring.
Signed-off-by Robert Femmer <[email protected]>--- include/linux/io_uring_types.h | 4 ++++ include/uapi/linux/kcov.h | 1 + io_uring/io-wq.c | 4 ++++ io_uring/io_uring.c | 18 ++++++++++++++++++ io_uring/io_uring.h | 22 ++++++++++++++++++++++ io_uring/sqpoll.c | 4 ++++ kernel/kcov.c | 2 ++ 7 files changed, 55 insertions(+)include/linux/io_uring_types.h +4
-0@@ -504,6 +504,10 @@ struct io_ring_ctx {struct io_mapped_region ring_region;/* used for optimised request parameter and wait argument passing */ struct io_mapped_region param_region; + +#ifdef CONFIG_KCOV +u64 kcov_handle; +#endif };/* include/uapi/linux/kcov.h +0
-0
include/uapi/linux/kcov.h enum { · line 52
Quoted 4 lines
include/uapi/linux/kcov.h +1
-0@@ -49,6 +49,7 @@ enum {#define KCOV_SUBSYSTEM_COMMON (0x00ull << 56)#define KCOV_SUBSYSTEM_USB (0x01ull << 56) +#define KCOV_SUBSYSTEM_IOURING (0x02ull << 56)
Hi Robet,
Would it be possible to use the common_handle functionality of KCOV for io_uring?
The global KCOV handles were not the best design decision. They arguably make sense for kernel tasks that get created during boot. But if a kernel task gets spawned as a result of a user task actions, the common handles are a better approach.
Quoted 144 lines
include/uapi/linux/kcov.h +0
-0#define KCOV_SUBSYSTEM_MASK (0xffull << 56)#define KCOV_INSTANCE_MASK (0xffffffffull)io_uring/io-wq.c +4
-0@@ -639,6 +639,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,/* handle a whole dependent link */ do { struct io_wq_work *next_hashed, *linked; + struct io_kiocb *req; unsigned int work_flags = atomic_read(&work->flags); unsigned int hash = __io_wq_is_hashed(work_flags) ? __io_get_work_hash(work_flags)@@ -649,7 +650,10 @@ static void io_worker_handle_work(struct io_wq_acct *acct,if (do_kill && (work_flags &IO_WQ_WORK_UNBOUND ))atomic_or (IO_WQ_WORK_CANCEL , &work->flags); + req = container_of(work, struct io_kiocb, work); +io_kcov_remote_start (req->ctx);io_wq_submit_work (work); +io_kcov_remote_stop ();io_assign_current_work (worker,NULL ); linked =io_wq_free_work (work);io_uring/io_uring.c +18
-0@@ -222,6 +222,21 @@ static void io_free_alloc_caches(struct io_ring_ctx *ctx)io_rsrc_cache_free (ctx); } +#ifdef CONFIG_KCOV +static __cold u64 io_ring_get_kcov_handle (void ) +{ +struct nsproxy *ns_proxy = current->nsproxy; +struct ns_common *ns; +u64 inst =0 ; + +if (ns_proxy) { + ns =to_ns_common (ns_proxy->cgroup_ns); + inst = ns->inum; + } +return kcov_remote_handle (KCOV_SUBSYSTEM_IOURING , inst); +} +#endif +static __cold struct io_ring_ctx *io_ring_ctx_alloc (struct io_uring_params *p) {struct io_ring_ctx *ctx;@@ -293,6 +308,9 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)INIT_HLIST_HEAD (&ctx->cancelable_uring_cmd);io_napi_init (ctx);mutex_init (&ctx->mmap_lock); +#ifdef CONFIG_KCOV + ctx->kcov_handle =io_ring_get_kcov_handle (); +#endif return ctx;io_uring/io_uring.h +22
-0@@ -7,6 +7,7 @@#include <linux/resume_user_mode.h> #include <linux/poll.h> #include <linux/io_uring_types.h> +#include <linux/kcov.h> #include <uapi/linux/eventpoll.h> #include "alloc_cache.h" #include "io-wq.h" @@ -581,4 +582,25 @@ static inline bool io_has_work(struct io_ring_ctx *ctx)return test_bit (IO_CHECK_CQ_OVERFLOW_BIT , &ctx->check_cq) || io_local_work_pending(ctx); } + +#ifdef CONFIG_KCOV +static inline void io_kcov_remote_start (struct io_ring_ctx *ctx) +{ +kcov_remote_start (ctx->kcov_handle); +} + +static inline void io_kcov_remote_stop (void ) +{ +kcov_remote_stop (); +} +#else +static inline void io_kcov_remote_start (struct io_ring_ctx *ctx) +{ +} + +static inline void io_kcov_remote_stop (void ) +{ +} +#endif +#endif io_uring/sqpoll.c +4
-0@@ -342,19 +342,23 @@ static int io_sq_thread(void *data) cap_entries = !list_is_singular (&sqd->ctx_list);list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +io_kcov_remote_start (ctx);int ret =__io_sq_thread (ctx, sqd, cap_entries, &ist);if (!sqt_spin && (ret >0 || !list_empty (&ctx->iopoll_list))) sqt_spin = true; +io_kcov_remote_stop (); }if (io_sq_tw (&retry_list,IORING_TW_CAP_ENTRIES_VALUE )) sqt_spin = true;list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +io_kcov_remote_start (ctx);if (io_napi (ctx)) {io_sq_start_worktime (&ist);io_napi_sqpoll_busy_poll (ctx); } +io_kcov_remote_stop (); }io_sq_update_worktime (sqd, &ist);kernel/kcov.c +2
-1@@ -585,6 +585,8 @@ static inline bool kcov_check_handle(u64 handle, bool common_valid, common_valid : zero_valid;case KCOV_SUBSYSTEM_USB :return uncommon_valid; +case KCOV_SUBSYSTEM_IOURING : +return uncommon_valid;default :return false; } --2.54.0
PATCH v2 1/1 io_uring: annotate remote tasks for kcoverage
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated by kcov_remote_start and kcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.
--- include/linux/io_uring_types.h | 4 ++++ io_uring/io-wq.c | 4 ++++ io_uring/io_uring.c | 3 +++ io_uring/io_uring.h | 24 ++++++++++++++++++++++++ io_uring/sqpoll.c | 4 ++++ 5 files changed, 39 insertions(+)
include/linux/io_uring_types.h +4 -0
@@ -504,6 +504,10 @@ struct io_ring_ctx {struct io_mapped_region ring_region;/* used for optimised request parameter and wait argument passing */ struct io_mapped_region param_region; + +#ifdef CONFIG_KCOV +u64 kcov_handle; +#endif };/*
io_uring/io-wq.c +4 -0
@@ -639,6 +639,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,/* handle a whole dependent link */ do { struct io_wq_work *next_hashed, *linked; + struct io_kiocb *req; unsigned int work_flags = atomic_read(&work->flags); unsigned int hash = __io_wq_is_hashed(work_flags) ? __io_get_work_hash(work_flags)
@@ -649,7 +650,10 @@ static void io_worker_handle_work(struct io_wq_acct *acct,if (do_kill && (work_flags &IO_WQ_WORK_UNBOUND ))atomic_or (IO_WQ_WORK_CANCEL , &work->flags); + req = container_of(work, struct io_kiocb, work); +io_kcov_remote_start (req->ctx);io_wq_submit_work (work); +io_kcov_remote_stop (req->ctx);io_assign_current_work (worker,NULL ); linked =io_wq_free_work (work);
io_uring/io_uring.c +3 -0
@@ -293,6 +293,9 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)INIT_HLIST_HEAD (&ctx->cancelable_uring_cmd);io_napi_init (ctx);mutex_init (&ctx->mmap_lock); +#ifdef CONFIG_KCOV + ctx->kcov_handle = current->kcov_handle; +#endif return ctx;
io_uring/io_uring.h +24 -0
@@ -7,6 +7,7 @@#include <linux/resume_user_mode.h> #include <linux/poll.h> #include <linux/io_uring_types.h> +#include <linux/kcov.h> #include <uapi/linux/eventpoll.h> #include "alloc_cache.h" #include "io-wq.h"
@@ -581,4 +582,27 @@ static inline bool io_has_work(struct io_ring_ctx *ctx)return test_bit (IO_CHECK_CQ_OVERFLOW_BIT , &ctx->check_cq) || io_local_work_pending(ctx); } + +#ifdef CONFIG_KCOV +static inline void io_kcov_remote_start (struct io_ring_ctx *ctx) +{ +if (ctx->kcov_handle) +kcov_remote_start (ctx->kcov_handle); +} + +static inline void io_kcov_remote_stop (struct io_ring_ctx *ctx) +{ +if (ctx->kcov_handle) +kcov_remote_stop (); +} +#else +static inline void io_kcov_remote_start (struct io_ring_ctx *ctx) +{ +} + +static inline void io_kcov_remote_stop (struct io_ring_ctx *ctx) +{ +} +#endif +#endif
io_uring/sqpoll.c +4 -0
@@ -342,19 +342,23 @@ static int io_sq_thread(void *data) cap_entries = !list_is_singular (&sqd->ctx_list);list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +io_kcov_remote_start (ctx);int ret =__io_sq_thread (ctx, sqd, cap_entries, &ist);if (!sqt_spin && (ret >0 || !list_empty (&ctx->iopoll_list))) sqt_spin = true; +io_kcov_remote_stop (ctx); }if (io_sq_tw (&retry_list,IORING_TW_CAP_ENTRIES_VALUE )) sqt_spin = true;list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +io_kcov_remote_start (ctx);if (io_napi (ctx)) {io_sq_start_worktime (&ist);io_napi_sqpoll_busy_poll (ctx); } +io_kcov_remote_stop (ctx); }io_sq_update_worktime (sqd, &ist);
Signature · 1 line
2.54.0
Andrey Konovalov
reviewerQuoted 21 lines · Robert Femmer
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (
CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated bykcov_remote_startandkcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.Signed-off-by Robert Femmer <[email protected]>--- include/linux/io_uring_types.h | 4 ++++ io_uring/io-wq.c | 4 ++++ io_uring/io_uring.c | 3 +++ io_uring/io_uring.h | 24 ++++++++++++++++++++++++ io_uring/sqpoll.c | 4 ++++ 5 files changed, 39 insertions(+)include/linux/io_uring_types.h +0
-0
include/linux/io_uring_types.h struct io_ring_ctx { · line 510
Quoted 7 lines
include/linux/io_uring_types.h +4
-0@@ -504,6 +504,10 @@ struct io_ring_ctx {struct io_mapped_region ring_region;/* used for optimised request parameter and wait argument passing */ struct io_mapped_region param_region; + +#ifdef CONFIG_KCOV +u64 kcov_handle; +#endif
Jann recently sent a patch that added kcov_common_handle_id, I think you can base your code on it and use that helper struct here.
https://lore.kernel.org/all/20260430-kcov-refactor-common-handle-v1-1-23a0c7a0ba38@google.com/
Quoted 16 lines
include/linux/io_uring_types.h +0
-0};/* io_uring/io-wq.c +1
-0@@ -639,6 +639,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,/* handle a whole dependent link */ do { struct io_wq_work *next_hashed, *linked; + struct io_kiocb *req; unsigned int work_flags = atomic_read(&work->flags); unsigned int hash = __io_wq_is_hashed(work_flags) ? __io_get_work_hash(work_flags)
io_uring/io-wq.c static void io_worker_handle_work(struct io_wq_acct *acct, · line 654
Quoted 5 lines
io_uring/io-wq.c +2
-0@@ -649,7 +650,10 @@ static void io_worker_handle_work(struct io_wq_acct *acct,if (do_kill && (work_flags &IO_WQ_WORK_UNBOUND ))atomic_or (IO_WQ_WORK_CANCEL , &work->flags); + req = container_of(work, struct io_kiocb, work); +io_kcov_remote_start (req->ctx);
And also use kcov_remote_start_common() here.
Quoted 94 lines
io_uring/io-wq.c +1
-0io_wq_submit_work (work); +io_kcov_remote_stop (req->ctx);io_assign_current_work (worker,NULL ); linked =io_wq_free_work (work);io_uring/io_uring.c +3
-0@@ -293,6 +293,9 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)INIT_HLIST_HEAD (&ctx->cancelable_uring_cmd);io_napi_init (ctx);mutex_init (&ctx->mmap_lock); +#ifdef CONFIG_KCOV + ctx->kcov_handle = current->kcov_handle; +#endif return ctx;io_uring/io_uring.h +24
-0@@ -7,6 +7,7 @@#include <linux/resume_user_mode.h> #include <linux/poll.h> #include <linux/io_uring_types.h> +#include <linux/kcov.h> #include <uapi/linux/eventpoll.h> #include "alloc_cache.h" #include "io-wq.h" @@ -581,4 +582,27 @@ static inline bool io_has_work(struct io_ring_ctx *ctx)return test_bit (IO_CHECK_CQ_OVERFLOW_BIT , &ctx->check_cq) || io_local_work_pending(ctx); } + +#ifdef CONFIG_KCOV +static inline void io_kcov_remote_start (struct io_ring_ctx *ctx) +{ +if (ctx->kcov_handle) +kcov_remote_start (ctx->kcov_handle); +} + +static inline void io_kcov_remote_stop (struct io_ring_ctx *ctx) +{ +if (ctx->kcov_handle) +kcov_remote_stop (); +} +#else +static inline void io_kcov_remote_start (struct io_ring_ctx *ctx) +{ +} + +static inline void io_kcov_remote_stop (struct io_ring_ctx *ctx) +{ +} +#endif +#endif io_uring/sqpoll.c +4
-1@@ -342,19 +342,23 @@ static int io_sq_thread(void *data) cap_entries = !list_is_singular (&sqd->ctx_list);list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +io_kcov_remote_start (ctx);int ret =__io_sq_thread (ctx, sqd, cap_entries, &ist);if (!sqt_spin && (ret >0 || !list_empty (&ctx->iopoll_list))) sqt_spin = true; +io_kcov_remote_stop (ctx); }if (io_sq_tw (&retry_list,IORING_TW_CAP_ENTRIES_VALUE )) sqt_spin = true;list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +io_kcov_remote_start (ctx);if (io_napi (ctx)) {io_sq_start_worktime (&ist);io_napi_sqpoll_busy_poll (ctx); } +io_kcov_remote_stop (ctx); }io_sq_update_worktime (sqd, &ist); --2.54.0
--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/kasan-dev/20260520204303.558392-2-robert%40fmmr.tech.
PATCH v3 1/1 io_uring: annotate remote tasks for kcoverage
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated by kcov_remote_start and kcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.
Depends-on: 20260430-kcov-refactor-common-handle-v1-1-23a0c7a0ba38@google.com
--- include/linux/io_uring_types.h | 2 ++ io_uring/io-wq.c | 4 ++++ io_uring/io_uring.c | 1 + io_uring/io_uring.h | 2 ++ io_uring/sqpoll.c | 4 ++++ 5 files changed, 13 insertions(+)
include/linux/io_uring_types.h +2 -0
@@ -504,6 +504,8 @@ struct io_ring_ctx {struct io_mapped_region ring_region;/* used for optimised request parameter and wait argument passing */ struct io_mapped_region param_region; + +struct kcov_common_handle_id kcov_handle; };/*
io_uring/io-wq.c +4 -0
@@ -639,6 +639,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,/* handle a whole dependent link */ do { struct io_wq_work *next_hashed, *linked; + struct io_kiocb *req; unsigned int work_flags = atomic_read(&work->flags); unsigned int hash = __io_wq_is_hashed(work_flags) ? __io_get_work_hash(work_flags)
@@ -649,7 +650,10 @@ static void io_worker_handle_work(struct io_wq_acct *acct,if (do_kill && (work_flags &IO_WQ_WORK_UNBOUND ))atomic_or (IO_WQ_WORK_CANCEL , &work->flags); + req = container_of(work, struct io_kiocb, work); +kcov_remote_start_common (req->ctx->kcov_handle);io_wq_submit_work (work); +kcov_remote_stop ();io_assign_current_work (worker,NULL ); linked =io_wq_free_work (work);
io_uring/io_uring.c +1 -0
@@ -293,6 +293,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)INIT_HLIST_HEAD (&ctx->cancelable_uring_cmd);io_napi_init (ctx);mutex_init (&ctx->mmap_lock); + ctx->kcov_handle =kcov_common_handle ();return ctx;
io_uring/io_uring.h +2 -0
@@ -7,6 +7,7 @@#include <linux/resume_user_mode.h> #include <linux/poll.h> #include <linux/io_uring_types.h> +#include <linux/kcov.h> #include <uapi/linux/eventpoll.h> #include "alloc_cache.h" #include "io-wq.h"
@@ -581,4 +582,5 @@ static inline bool io_has_work(struct io_ring_ctx *ctx)return test_bit (IO_CHECK_CQ_OVERFLOW_BIT , &ctx->check_cq) || io_local_work_pending(ctx); } +#endif
io_uring/sqpoll.c +4 -0
@@ -342,19 +342,23 @@ static int io_sq_thread(void *data) cap_entries = !list_is_singular (&sqd->ctx_list);list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +kcov_remote_start_common (ctx->kcov_handle);int ret =__io_sq_thread (ctx, sqd, cap_entries, &ist);if (!sqt_spin && (ret >0 || !list_empty (&ctx->iopoll_list))) sqt_spin = true; +kcov_remote_stop (); }if (io_sq_tw (&retry_list,IORING_TW_CAP_ENTRIES_VALUE )) sqt_spin = true;list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +kcov_remote_start_common (ctx->kcov_handle);if (io_napi (ctx)) {io_sq_start_worktime (&ist);io_napi_sqpoll_busy_poll (ctx); } +kcov_remote_stop (); }io_sq_update_worktime (sqd, &ist);
Signature · 1 line
2.54.0
Quoted 5 lines · Robert Femmer
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (
CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated bykcov_remote_startandkcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.
I think this is a useful change overall.
@maintainers: For context, this should have no impact on normal builds
- "struct kcov_common_handle_id" is zero-sized in normal builds, and all the helpers used here are empty inline functions.
Quoted 63 lines
Depends-on: 20260430-kcov-refactor-common-handle-v1-1-23a0c7a0ba38@google.com
Signed-off-by Robert Femmer <[email protected]>--- include/linux/io_uring_types.h | 2 ++ io_uring/io-wq.c | 4 ++++ io_uring/io_uring.c | 1 + io_uring/io_uring.h | 2 ++ io_uring/sqpoll.c | 4 ++++ 5 files changed, 13 insertions(+)include/linux/io_uring_types.h +2
-0@@ -504,6 +504,8 @@ struct io_ring_ctx {struct io_mapped_region ring_region;/* used for optimised request parameter and wait argument passing */ struct io_mapped_region param_region; + +struct kcov_common_handle_id kcov_handle; };/* io_uring/io-wq.c +4
-0@@ -639,6 +639,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,/* handle a whole dependent link */ do { struct io_wq_work *next_hashed, *linked; + struct io_kiocb *req; unsigned int work_flags = atomic_read(&work->flags); unsigned int hash = __io_wq_is_hashed(work_flags) ? __io_get_work_hash(work_flags)@@ -649,7 +650,10 @@ static void io_worker_handle_work(struct io_wq_acct *acct,if (do_kill && (work_flags &IO_WQ_WORK_UNBOUND ))atomic_or (IO_WQ_WORK_CANCEL , &work->flags); + req = container_of(work, struct io_kiocb, work); +kcov_remote_start_common (req->ctx->kcov_handle);io_wq_submit_work (work); +kcov_remote_stop ();io_assign_current_work (worker,NULL ); linked =io_wq_free_work (work);io_uring/io_uring.c +1
-0@@ -293,6 +293,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)INIT_HLIST_HEAD (&ctx->cancelable_uring_cmd);io_napi_init (ctx);mutex_init (&ctx->mmap_lock); + ctx->kcov_handle =kcov_common_handle ();return ctx;io_uring/io_uring.h +0
-0
io_uring/io_uring.h line 10
Quoted 4 lines
io_uring/io_uring.h +1
-0@@ -7,6 +7,7 @@#include <linux/resume_user_mode.h> #include <linux/poll.h> #include <linux/io_uring_types.h> +#include <linux/kcov.h>
I think instead of this, normal kernel coding style is to use includes directly in the files where they are needed.
https://docs.kernel.org/process/submit-checklist.html says:
"If you use a facility then #include the file that defines/declares that facility. Don’t depend on other header files pulling in ones that you use."
io_uring/io_uring.h static inline bool io_has_work(struct io_ring_ctx *ctx) · line 586
Quoted 9 lines
io_uring/io_uring.h +1
-0#include <uapi/linux/eventpoll.h> #include "alloc_cache.h" #include "io-wq.h" @@ -581,4 +582,5 @@ static inline bool io_has_work(struct io_ring_ctx *ctx)return test_bit (IO_CHECK_CQ_OVERFLOW_BIT , &ctx->check_cq) || io_local_work_pending(ctx); } +#endif
This looks like an accidental whitespace change.
Quoted 15 lines
io_uring/sqpoll.c +2
-0@@ -342,19 +342,23 @@ static int io_sq_thread(void *data) cap_entries = !list_is_singular (&sqd->ctx_list);list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +kcov_remote_start_common (ctx->kcov_handle);int ret =__io_sq_thread (ctx, sqd, cap_entries, &ist);if (!sqt_spin && (ret >0 || !list_empty (&ctx->iopoll_list))) sqt_spin = true; +kcov_remote_stop (); }
io_uring/sqpoll.c static int io_sq_thread(void *data) · line 361
Quoted 10 lines
io_uring/sqpoll.c +2
-0if (io_sq_tw (&retry_list,IORING_TW_CAP_ENTRIES_VALUE )) sqt_spin = true;list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +kcov_remote_start_common (ctx->kcov_handle);if (io_napi (ctx)) {io_sq_start_worktime (&ist);io_napi_sqpoll_busy_poll (ctx); } +kcov_remote_stop ();
Someone who knows more about networking than me might know this area better, but I think we probably don't want to have KCOV coverage around the call to io_napi_sqpoll_busy_poll() for two reasons:
1. This is NAPI busypolling code, designed to busy-loop until network packets arrive - meaning the limited KCOV coverage buffer will quickly fill up even if no data is actually being processed.
2. As far as I know, io_napi_sqpoll_busy_poll() doesn't really process data related to the uring instance - it (more or less) merely busy-polls network interfaces specified by the user. Received packets are not necessarily actually related to this uring instance.
Quoted 6 lines
io_uring/sqpoll.c +0
-1}io_sq_update_worktime (sqd, &ist); --2.54.0
Quoted 7 lines · Jann Horn
Quoted 5 lines · Robert Femmer
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (
CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated bykcov_remote_startandkcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.
Quoted 5 lines
I think this is a useful change overall.
@maintainers: For context, this should have no impact on normal builds
- "structkcov_common_handle_id" is zero-sized in normal builds, and all the helpers used here are empty inline functions.
(That was supposed to be "are empty inline functions in normal builds". I should've re-read this before hitting send...)
Quoted 1 line
Quoted 1 line
Depends-on: 20260430-kcov-refactor-common-handle-v1-1-23a0c7a0ba38@google.com
(This landed in mainline in the current merge window.)
PATCH v4 1/1 io_uring: annotate remote tasks for kcoverage
In reply to Jann HornFuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated by kcov_remote_start and kcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.
Depends-On: 20260430-kcov-refactor-common-handle-v1-1-23a0c7a0ba38@google.com
--- include/linux/io_uring_types.h | 2 ++ io_uring/io-wq.c | 5 +++++ io_uring/io_uring.c | 2 ++ io_uring/sqpoll.c | 3 +++ 4 files changed, 12 insertions(+)
include/linux/io_uring_types.h +2 -0
@@ -504,6 +504,8 @@ struct io_ring_ctx {struct io_mapped_region ring_region;/* used for optimised request parameter and wait argument passing */ struct io_mapped_region param_region; + +struct kcov_common_handle_id kcov_handle; };/*
io_uring/io-wq.c +5 -0
@@ -19,6 +19,7 @@#include <linux/mmu_context.h> #include <linux/sched/sysctl.h> #include <uapi/linux/io_uring.h> +#include <linux/kcov.h> #include "io-wq.h" #include "slist.h"
@@ -639,6 +640,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,/* handle a whole dependent link */ do { struct io_wq_work *next_hashed, *linked; + struct io_kiocb *req; unsigned int work_flags = atomic_read(&work->flags); unsigned int hash = __io_wq_is_hashed(work_flags) ? __io_get_work_hash(work_flags)
@@ -649,7 +651,10 @@ static void io_worker_handle_work(struct io_wq_acct *acct,if (do_kill && (work_flags &IO_WQ_WORK_UNBOUND ))atomic_or (IO_WQ_WORK_CANCEL , &work->flags); + req = container_of(work, struct io_kiocb, work); +kcov_remote_start_common (req->ctx->kcov_handle);io_wq_submit_work (work); +kcov_remote_stop ();io_assign_current_work (worker,NULL ); linked =io_wq_free_work (work);
io_uring/io_uring.c +2 -0
@@ -59,6 +59,7 @@#include <linux/audit.h> #include <linux/security.h> #include <linux/jump_label.h> +#include <linux/kcov.h> #define CREATE_TRACE_POINTS #include <trace/events/io_uring.h>
@@ -293,6 +294,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)INIT_HLIST_HEAD (&ctx->cancelable_uring_cmd);io_napi_init (ctx);mutex_init (&ctx->mmap_lock); + ctx->kcov_handle =kcov_common_handle ();return ctx;
io_uring/sqpoll.c +3 -0
@@ -13,6 +13,7 @@#include <linux/cpuset.h> #include <linux/sched/cputime.h> #include <linux/io_uring.h> +#include <linux/kcov.h> #include <uapi/linux/io_uring.h>
@@ -342,10 +343,12 @@ static int io_sq_thread(void *data) cap_entries = !list_is_singular (&sqd->ctx_list);list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +kcov_remote_start_common (ctx->kcov_handle);int ret =__io_sq_thread (ctx, sqd, cap_entries, &ist);if (!sqt_spin && (ret >0 || !list_empty (&ctx->iopoll_list))) sqt_spin = true; +kcov_remote_stop (); }if (io_sq_tw (&retry_list,IORING_TW_CAP_ENTRIES_VALUE )) sqt_spin = true;
Signature · 1 line
2.54.0
Jens Axboe
maintainerQuoted 8 lines · Jann Horn
Quoted 5 lines · Robert Femmer
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (
CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated bykcov_remote_startandkcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.I think this is a useful change overall.
Agree, mostly waiting on Andrey and Robert to hash out the details and we can get this landed for 7.3. On vacation the next weeks, not much going on on my end, work wise.
Signature · 1 line
Jens Axboe
Quoted 106 lines · Robert Femmer
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (
CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated bykcov_remote_startandkcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.Depends-On: 20260430-kcov-refactor-common-handle-v1-1-23a0c7a0ba38@google.com
Signed-off-by Robert Femmer <[email protected]>--- include/linux/io_uring_types.h | 2 ++ io_uring/io-wq.c | 5 +++++ io_uring/io_uring.c | 2 ++ io_uring/sqpoll.c | 3 +++ 4 files changed, 12 insertions(+)include/linux/io_uring_types.h +2
-0@@ -504,6 +504,8 @@ struct io_ring_ctx {struct io_mapped_region ring_region;/* used for optimised request parameter and wait argument passing */ struct io_mapped_region param_region; + +struct kcov_common_handle_id kcov_handle; };/* io_uring/io-wq.c +5
-0@@ -19,6 +19,7 @@#include <linux/mmu_context.h> #include <linux/sched/sysctl.h> #include <uapi/linux/io_uring.h> +#include <linux/kcov.h> #include "io-wq.h" #include "slist.h" @@ -639,6 +640,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,/* handle a whole dependent link */ do { struct io_wq_work *next_hashed, *linked; + struct io_kiocb *req; unsigned int work_flags = atomic_read(&work->flags); unsigned int hash = __io_wq_is_hashed(work_flags) ? __io_get_work_hash(work_flags)@@ -649,7 +651,10 @@ static void io_worker_handle_work(struct io_wq_acct *acct,if (do_kill && (work_flags &IO_WQ_WORK_UNBOUND ))atomic_or (IO_WQ_WORK_CANCEL , &work->flags); + req = container_of(work, struct io_kiocb, work); +kcov_remote_start_common (req->ctx->kcov_handle);io_wq_submit_work (work); +kcov_remote_stop ();io_assign_current_work (worker,NULL ); linked =io_wq_free_work (work);io_uring/io_uring.c +2
-0@@ -59,6 +59,7 @@#include <linux/audit.h> #include <linux/security.h> #include <linux/jump_label.h> +#include <linux/kcov.h> #define CREATE_TRACE_POINTS #include <trace/events/io_uring.h> @@ -293,6 +294,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)INIT_HLIST_HEAD (&ctx->cancelable_uring_cmd);io_napi_init (ctx);mutex_init (&ctx->mmap_lock); + ctx->kcov_handle =kcov_common_handle ();return ctx;io_uring/sqpoll.c +3
-1@@ -13,6 +13,7 @@#include <linux/cpuset.h> #include <linux/sched/cputime.h> #include <linux/io_uring.h> +#include <linux/kcov.h> #include <uapi/linux/io_uring.h> @@ -342,10 +343,12 @@ static int io_sq_thread(void *data) cap_entries = !list_is_singular (&sqd->ctx_list);list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +kcov_remote_start_common (ctx->kcov_handle);int ret =__io_sq_thread (ctx, sqd, cap_entries, &ist);if (!sqt_spin && (ret >0 || !list_empty (&ctx->iopoll_list))) sqt_spin = true; +kcov_remote_stop (); }if (io_sq_tw (&retry_list,IORING_TW_CAP_ENTRIES_VALUE )) sqt_spin = true; --
Quoted 2 lines
2.54.0
From KCOV API side:
Thanks!
Jens Axboe
maintainerQuoted 13 lines · Robert Femmer
io_uring/io-wq.c +1
-0@@ -19,6 +19,7 @@#include <linux/mmu_context.h> #include <linux/sched/sysctl.h> #include <uapi/linux/io_uring.h> +#include <linux/kcov.h> #include "io-wq.h" #include "slist.h"
io_uring/io-wq.c static void io_worker_handle_work(struct io_wq_acct *acct, · line 646
Quoted 7 lines
io_uring/io-wq.c +1
-0@@ -639,6 +640,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,/* handle a whole dependent link */ do { struct io_wq_work *next_hashed, *linked; + struct io_kiocb *req; unsigned int work_flags = atomic_read(&work->flags); unsigned int hash = __io_wq_is_hashed(work_flags) ? __io_get_work_hash(work_flags)
We try to, roughly, keep this in reverse xmas tree order. I've fixed it up.
Quoted 13 lines
io_uring/sqpoll.c +1
-0@@ -13,6 +13,7 @@#include <linux/cpuset.h> #include <linux/sched/cputime.h> #include <linux/io_uring.h> +#include <linux/kcov.h> #include <uapi/linux/io_uring.h>
io_uring/sqpoll.c static int io_sq_thread(void *data) · line 347
Quoted 5 lines
io_uring/sqpoll.c +1
-0@@ -342,10 +343,12 @@ static int io_sq_thread(void *data) cap_entries = !list_is_singular (&sqd->ctx_list);list_for_each_entry (ctx, &sqd->ctx_list, sqd_list) { +kcov_remote_start_common (ctx->kcov_handle);int ret =__io_sq_thread (ctx, sqd, cap_entries, &ist);
Never code before variable declarations in the scope. I've also fixed that one up.
Also not sure what branch this was against, because it doesn't apply to any current one. Guessing something old? I had applied 2 hunks, fwiw. Please check the result!
Signature · 1 line
Jens Axboe
Quoted 8 lines · Robert Femmer
Fuzzers use coverage information to guide generation of test cases towards new or interesting code paths. Syzkaller, specifically, makes use kcoverage (
CONFIG_KCOV). Coverage information is not collected for kernel tasks unless annotated bykcov_remote_startandkcov_remote_stop. This patch annotates io-uring's work queue and sqpoll tasks.[...]
Applied, thanks!
[1/1] io_uring: annotate remote tasks for kcoverage
commit: c905736a46892e4776efc7f50888d67715d6ec08
Best regards,
Signature · 1 line
Jens Axboe