Re: [PATCH v5] kcov: fix data corruption and race conditions on PREEMPT_RT by moving saved remote state to task_struct

From: Alexander Potapenko

Date: Wed Jul 08 2026 - 11:29:47 EST


>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 373bcc0598d1..7a53c15cecb5 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1543,6 +1543,14 @@ struct task_struct {
>
> /* Collect coverage from softirq context: */
> unsigned int kcov_softirq;
> +
> + /* Temporary storage for preempting remote coverage collection: */
> + unsigned int kcov_saved_mode;
> + unsigned int kcov_saved_size;
> + void *kcov_saved_area;
> + struct kcov *kcov_saved_kcov;
> + int kcov_saved_sequence;

I think we need to land "kcov: factor out struct kcov_state"
(https://lore.kernel.org/all/20250731115139.3035888-4-glider@xxxxxxxxxx/#r),
these stray members of task_struct are getting out of control.
Let me send it separately from the rest of my changes.

Also note these new fields will need to be initialized in kcov_task_init().

>
> - if (in_task()) {
> + if (1) {

Why? Can you remove this if statement?
(I am also curious why Sashiko did not report it, CC Roman)


> +#ifdef CONFIG_PREEMPT_RT
> + /* Allocate some extra buffers in order to prepare for softirq preemption. */
> + cpu = cpu >= 4 ? cpu * 2 : cpu + 4;
> +#endif
> + while (cpu--) {
> + void *area = vmalloc(CONFIG_KCOV_IRQ_AREA_SIZE * sizeof(unsigned long));

We need a NULL check here, kcov_remote_area_put() is going to dereference area.