On Thu, 26 Feb 2026 21:03:03 -0800
Chaitanya Kulkarni <[email protected]> wrote:

> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> index 3b7c102a6eb3..488552036583 100644
> --- a/kernel/trace/blktrace.c
> +++ b/kernel/trace/blktrace.c
> @@ -383,7 +383,9 @@ static void __blk_add_trace(struct blk_trace *bt, 
> sector_t sector, int bytes,
>       cpu = raw_smp_processor_id();
>  
>       if (blk_tracer) {
> +             preempt_disable_notrace();
>               tracing_record_cmdline(current);
> +             preempt_enable_notrace();
>  
>               buffer = blk_tr->array_buffer.buffer;
>               trace_ctx = tracing_gen_ctx_flags(0);

Do you know when this started? rcu_read_lock() doesn't disable preemption
in PREEMPT environments, and hasn't for a very long time. I'm surprised it
took this long to detect this? Perhaps this was a bug from day one?

Anyway, the tracing_record_cmdline() is to update the COMM cache so that
the trace has way to show the task->comm based on the saved PID in the
trace. It sets a flag to record the COMM from the sched_switch event if a
trace event happened. It's not needed if no trace event occurred. That
means, instead of adding preempt_disable() here, just move it after the
ring buffer event is reserved, as that means preemption is disabled until
the event is committed.

i.e.

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index e6988929ead2..3735cbc1f99f 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -383,8 +383,6 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t 
sector, int bytes,
        cpu = raw_smp_processor_id();
 
        if (blk_tracer) {
-               tracing_record_cmdline(current);
-
                buffer = blk_tr->array_buffer.buffer;
                trace_ctx = tracing_gen_ctx_flags(0);
                switch (bt->version) {
@@ -419,6 +417,8 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t 
sector, int bytes,
                if (!event)
                        return;
 
+               tracing_record_cmdline(current);
+
                switch (bt->version) {
                case 1:
                        record_blktrace_event(ring_buffer_event_data(event),

-- Steve

Reply via email to