mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: deepakraog <gaikwad.dcg@gmail.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Pekka Paalanen <ppaalanen@gmail.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org,
	linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing/mmiotrace: fix resource leak on trace_pipe close
Date: Tue, 21 Jul 2026 20:38:43 -0400	[thread overview]
Message-ID: <20260721203843.65d06a69@gandalf.local.home> (raw)
In-Reply-To: <20260715143604.14481-1-gaikwad.dcg@gmail.com>

On Wed, 15 Jul 2026 20:06:04 +0530
deepakraog <gaikwad.dcg@gmail.com> wrote:

> mmio_pipe_open() allocates a header_iter and takes a pci_dev reference
> when trace_pipe is opened. mmio_close() frees them, but it was only
> wired to the tracer's .close callback.

Were you able to trigger a kmemleak?

> 
> tracing_release_pipe() invokes .pipe_close, not .close, when the
> trace_pipe file is released. As a result, closing trace_pipe with the
> mmiotrace tracer active leaked the header_iter allocation and left a
> stale pci_dev reference.

It would be good if you showed how a leak can happen, as the mmio_read()
does clean up the descriptor, making the above statement incorrect.

> 
> Set .pipe_close to mmio_close, matching how function_graph wires both
> callbacks to the same handler.
> 


The mmio_read() will free up the descriptor if you read the trace_pipe file
until it blocks. But reading part of it may trigger the leak. Such as:

  # head -n 1 /sys/kernel/tracing/trace_pipe 
 head: /sys/kernel/tracing/trace_pipe: cannot seek to relative offset 0: Illegal seek
 VERSION 20070824

and running that over and over again will produce a leak caught by kmemleak.

I'll update the change log.

-- Steve

      reply	other threads:[~2026-07-22  0:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15 14:36 deepakraog
2026-07-22  0:38 ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260721203843.65d06a69@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=gaikwad.dcg@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ppaalanen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®