using BPF for driver memory leak detection


Krishna Chaitanya
 

On Mon, Aug 6, 2018 at 3:12 PM Krishna Chaitanya
<chaitanya.mgit@...> wrote:

Hi,

If we want to use BPF for memory leak for driver modules, we can only
print outstanding allocations which could potentially be freed at a
later time.

Is there a simple way we could pre-load BPF (before driver insertion)
and check for the outstanding entries after the driver removal, which
are confirmed leaks?

This is useful to debug memory allocations at insmod/rmmod.

Currently, without insmod, BPF compilation fails as tracepoints are
not installed. And also if tracing is active, rmmod fails with
"resource in use".
+dev


Yonghong Song
 

On Mon, Aug 6, 2018 at 2:44 AM, Krishna Chaitanya
<chaitanya.mgit@...> wrote:
On Mon, Aug 6, 2018 at 3:12 PM Krishna Chaitanya
<chaitanya.mgit@...> wrote:

Hi,

If we want to use BPF for memory leak for driver modules, we can only
print outstanding allocations which could potentially be freed at a
later time.

Is there a simple way we could pre-load BPF (before driver insertion)
and check for the outstanding entries after the driver removal, which
are confirmed leaks?

This is useful to debug memory allocations at insmod/rmmod.

Currently, without insmod, BPF compilation fails as tracepoints are
not installed. And also if tracing is active, rmmod fails with
"resource in use".
Which tracepoint you tried to attach? For kernel memory, a few kmem
tracepoints are attached in memleak. If you want to attach a tracepoint
only defined by the module, yes, you may have to wait until the module
is inserted into the kernel.

+dev



Krishna Chaitanya
 

On Mon, Aug 6, 2018 at 11:15 PM Y Song <ys114321@...> wrote:

On Mon, Aug 6, 2018 at 2:44 AM, Krishna Chaitanya
<chaitanya.mgit@...> wrote:
On Mon, Aug 6, 2018 at 3:12 PM Krishna Chaitanya
<chaitanya.mgit@...> wrote:

Hi,

If we want to use BPF for memory leak for driver modules, we can only
print outstanding allocations which could potentially be freed at a
later time.

Is there a simple way we could pre-load BPF (before driver insertion)
and check for the outstanding entries after the driver removal, which
are confirmed leaks?

This is useful to debug memory allocations at insmod/rmmod.

Currently, without insmod, BPF compilation fails as tracepoints are
not installed. And also if tracing is active, rmmod fails with
"resource in use".
Which tracepoint you tried to attach? For kernel memory, a few kmem
tracepoints are attached in memleak. If you want to attach a tracepoint
only defined by the module, yes, you may have to wait until the module
is inserted into the kernel.
I have defined a new tracepoint in my module and tried to attach to it.
I am using the memleak.py script as a reference and extended it to check
for leaks in my modules (using tracepoints defined by the module).

Ideally, I would like to run BPF and do rmmod, and check is there are
still outstanding entries and print out the call stack of the leaked allocation.


Krishna Chaitanya
 

On Tue, Aug 7, 2018 at 1:00 PM Krishna Chaitanya
<chaitanya.mgit@...> wrote:

On Mon, Aug 6, 2018 at 11:15 PM Y Song <ys114321@...> wrote:

On Mon, Aug 6, 2018 at 2:44 AM, Krishna Chaitanya
<chaitanya.mgit@...> wrote:
On Mon, Aug 6, 2018 at 3:12 PM Krishna Chaitanya
<chaitanya.mgit@...> wrote:

Hi,

If we want to use BPF for memory leak for driver modules, we can only
print outstanding allocations which could potentially be freed at a
later time.

Is there a simple way we could pre-load BPF (before driver insertion)
and check for the outstanding entries after the driver removal, which
are confirmed leaks?

This is useful to debug memory allocations at insmod/rmmod.

Currently, without insmod, BPF compilation fails as tracepoints are
not installed. And also if tracing is active, rmmod fails with
"resource in use".
Which tracepoint you tried to attach? For kernel memory, a few kmem
tracepoints are attached in memleak. If you want to attach a tracepoint
only defined by the module, yes, you may have to wait until the module
is inserted into the kernel.
I have defined a new tracepoint in my module and tried to attach to it.
I am using the memleak.py script as a reference and extended it to check
for leaks in my modules (using tracepoints defined by the module).

Ideally, I would like to run BPF and do rmmod, and check is there are
still outstanding entries and print out the call stack of the leaked allocation.
Only solutions i can think of is

a) in insmod do the basic stuff, but block any memory allocs till BPF is loaded
and in rmmod free the allocs, but dont exit yet, then stop the BPF and exit.

b) move all memory alloc/free to interface down/up (my module is a
wlan network driver).