mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Rob Herring <robh+dt@kernel.org>
Cc: "Mårten Lindahl" <marten.lindahl@axis.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>, kernel <kernel@axis.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] driver core: Free DMA range map when device is released
Date: Tue, 22 Feb 2022 08:40:42 +0100	[thread overview]
Message-ID: <YhSTelz4q2XW8man@kroah.com> (raw)
In-Reply-To: <CAL_JsqKQ2sZ1YnxGzBvVfHBAq7b34pT4=qs147RsFMjFuFJc+Q@mail.gmail.com>

On Wed, Feb 16, 2022 at 09:45:09AM -0600, Rob Herring wrote:
> On Wed, Feb 16, 2022 at 3:42 AM Mårten Lindahl <marten.lindahl@axis.com> wrote:
> >
> > When unbinding/binding a driver with DMA mapped memory, the DMA map is
> > not freed before the driver is reloaded. This leads to a memory leak
> > when the DMA map is overwritten when reprobing the driver.
> >
> > This can be reproduced with a platform driver having a dma-range:
> >
> > dummy {
> >         ...
> >         #address-cells = <0x2>;
> >         #size-cells = <0x2>;
> >         ranges;
> >         dma-ranges = <...>;
> >         ...
> > };
> >
> > and then unbinding/binding it:
> >
> > ~# echo soc:dummy >/sys/bus/platform/drivers/<driver>/unbind
> >
> > DMA map object 0xffffff800b0ae540 still being held by &pdev->dev
> >
> > ~# echo soc:dummy >/sys/bus/platform/drivers/<driver>/bind
> > ~# echo scan > /sys/kernel/debug/kmemleak
> > ~# cat /sys/kernel/debug/kmemleak
> > unreferenced object 0xffffff800b0ae540 (size 64):
> >   comm "sh", pid 833, jiffies 4295174550 (age 2535.352s)
> >   hex dump (first 32 bytes):
> >     00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00  ................
> >     00 00 00 80 00 00 00 00 00 00 00 80 00 00 00 00  ................
> >   backtrace:
> >     [<ffffffefd1694708>] create_object.isra.0+0x108/0x344
> >     [<ffffffefd1d1a850>] kmemleak_alloc+0x8c/0xd0
> >     [<ffffffefd167e2d0>] __kmalloc+0x440/0x6f0
> >     [<ffffffefd1a960a4>] of_dma_get_range+0x124/0x220
> >     [<ffffffefd1a8ce90>] of_dma_configure_id+0x40/0x2d0
> >     [<ffffffefd198b68c>] platform_dma_configure+0x5c/0xa4
> >     [<ffffffefd198846c>] really_probe+0x8c/0x514
> >     [<ffffffefd1988990>] __driver_probe_device+0x9c/0x19c
> >     [<ffffffefd1988cd8>] device_driver_attach+0x54/0xbc
> >     [<ffffffefd1986634>] bind_store+0xc4/0x120
> >     [<ffffffefd19856e0>] drv_attr_store+0x30/0x44
> >     [<ffffffefd173c9b0>] sysfs_kf_write+0x50/0x60
> >     [<ffffffefd173c1c4>] kernfs_fop_write_iter+0x124/0x1b4
> >     [<ffffffefd16a013c>] new_sync_write+0xdc/0x160
> >     [<ffffffefd16a256c>] vfs_write+0x23c/0x2a0
> >     [<ffffffefd16a2758>] ksys_write+0x64/0xec
> >
> > To prevent this we should free the dma_range_map when the device is
> > released.
> >
> > Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
> 
> Suggested-by: Rob Herring <robh@kernel.org>
> Fixes: e0d072782c73 ("dma-mapping: introduce DMA range map,
> supplanting dma_pfn_offset")
> Reviewed-by: Rob Herring <robh@kernel.org>
> 
> I've got a follow-up patch to refactor the 3 occurrences of this same
> deinit code.

Now queued up, so feel free to send the follow-up patch too.

thanks,

greg k-h

      reply	other threads:[~2022-02-22  7:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-16  9:41 Mårten Lindahl
2022-02-16 15:45 ` Rob Herring
2022-02-22  7:40   ` Greg Kroah-Hartman [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=YhSTelz4q2XW8man@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=kernel@axis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marten.lindahl@axis.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    /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®