From: Vinod Koul <vkoul@kernel.org>
To: Logan Gunthorpe <logang@deltatee.com>
Cc: linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org,
Dan Williams <dan.j.williams@intel.com>
Subject: Re: [PATCH 1/5] dmaengine: Store module owner in dma_device struct
Date: Sat, 9 Nov 2019 22:48:53 +0530 [thread overview]
Message-ID: <20191109171853.GF952516@vkoul-mobl> (raw)
In-Reply-To: <20191022214616.7943-2-logang@deltatee.com>
Hi Logan,
Sorry for delay in reply!
On 22-10-19, 15:46, Logan Gunthorpe wrote:
> dma_chan_to_owner() dereferences the driver from the struct device to
> obtain the owner and call module_[get|put](). However, if the backing
> device is unbound before the dma_device is unregistered, the driver
> will be cleared and this will cause a NULL pointer dereference.
Have you been able to repro this? If so how..?
The expectation is that the driver shall unregister before removed.
>
> Instead, store a pointer to the owner module in the dma_device struct
> so the module reference can be properly put when the channel is put, even
> if the backing device was destroyed first.
>
> This change helps to support a safer unbind of DMA engines.
For error cases which should be fixed, so maybe this is a right way and
gets things fixed :)
> If the dma_device is unregistered in the driver's remove function,
> there's no guarantee that there are no existing clients and a users
> action may trigger the WARN_ONCE in dma_async_device_unregister()
> which is unlikely to leave the system in a consistent state.
> Instead, a better approach is to allow the backing driver to go away
> and fail any subsequent requests to it.
>
> Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
> ---
> drivers/dma/dmaengine.c | 4 +++-
> include/linux/dmaengine.h | 2 ++
> 2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 03ac4b96117c..4b604086b1b3 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -179,7 +179,7 @@ __dma_device_satisfies_mask(struct dma_device *device,
>
> static struct module *dma_chan_to_owner(struct dma_chan *chan)
> {
> - return chan->device->dev->driver->owner;
> + return chan->device->owner;
> }
>
> /**
> @@ -919,6 +919,8 @@ int dma_async_device_register(struct dma_device *device)
> return -EIO;
> }
>
> + device->owner = device->dev->driver->owner;
> +
> if (dma_has_cap(DMA_MEMCPY, device->cap_mask) && !device->device_prep_dma_memcpy) {
> dev_err(device->dev,
> "Device claims capability %s, but op is not defined\n",
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index 8fcdee1c0cf9..13aa0abb71de 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -674,6 +674,7 @@ struct dma_filter {
> * @fill_align: alignment shift for memset operations
> * @dev_id: unique device ID
> * @dev: struct device reference for dma mapping api
> + * @owner: owner module (automatically set based on the provided dev)
> * @src_addr_widths: bit mask of src addr widths the device supports
> * Width is specified in bytes, e.g. for a device supporting
> * a width of 4 the mask should have BIT(4) set.
> @@ -737,6 +738,7 @@ struct dma_device {
>
> int dev_id;
> struct device *dev;
> + struct module *owner;
>
> u32 src_addr_widths;
> u32 dst_addr_widths;
> --
> 2.20.1
--
~Vinod
next prev parent reply other threads:[~2019-11-09 17:19 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-22 21:46 [PATCH 0/5] PLX Switch DMA Engine Driver Logan Gunthorpe
2019-10-22 21:46 ` [PATCH 1/5] dmaengine: Store module owner in dma_device struct Logan Gunthorpe
2019-11-09 17:18 ` Vinod Koul [this message]
2019-11-11 16:50 ` Logan Gunthorpe
2019-11-12 5:56 ` Vinod Koul
2019-11-12 16:45 ` Logan Gunthorpe
2019-11-14 4:55 ` Vinod Koul
2019-11-14 17:03 ` Logan Gunthorpe
2019-11-22 5:20 ` Vinod Koul
2019-11-22 16:53 ` Dave Jiang
2019-11-22 20:50 ` Dan Williams
2019-11-22 20:56 ` Logan Gunthorpe
2019-11-22 21:01 ` Dan Williams
2019-11-22 21:42 ` Dave Jiang
2019-12-10 9:53 ` Vinod Koul
2019-12-10 17:39 ` Logan Gunthorpe
2019-10-22 21:46 ` [PATCH 2/5] dmaengine: Call module_put() after device_free_chan_resources() Logan Gunthorpe
2019-10-22 21:46 ` [PATCH 3/5] dmaengine: plx-dma: Introduce PLX DMA engine PCI driver skeleton Logan Gunthorpe
2019-11-09 17:35 ` Vinod Koul
2019-11-11 17:50 ` Logan Gunthorpe
2019-11-12 6:09 ` Vinod Koul
2019-11-12 17:22 ` Logan Gunthorpe
2019-10-22 21:46 ` [PATCH 4/5] dmaengine: plx-dma: Implement hardware initialization and cleanup Logan Gunthorpe
2019-10-22 21:46 ` [PATCH 5/5] dmaengine: plx-dma: Implement descriptor submission Logan Gunthorpe
2019-11-09 17:40 ` Vinod Koul
2019-11-11 18:11 ` Logan Gunthorpe
2019-12-16 19:01 [PATCH 0/5] Support hot-unbind in IOAT Logan Gunthorpe
2019-12-16 19:01 ` [PATCH 1/5] dmaengine: Store module owner in dma_device struct Logan Gunthorpe
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=20191109171853.GF952516@vkoul-mobl \
--to=vkoul@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=logang@deltatee.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;
as well as URLs for NNTP newsgroup(s).