From: Dave Jiang <dave.jiang@intel.com>
To: Reinette Chatre <reinette.chatre@intel.com>,
fenghua.yu@intel.com, vkoul@kernel.org,
dmaengine@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] dmaengine: idxd: Let probe fail when workqueue cannot be enabled
Date: Fri, 2 Dec 2022 11:44:10 -0700 [thread overview]
Message-ID: <13d4bbcb-244e-df72-4281-755d4bc51274@intel.com> (raw)
In-Reply-To: <1e74e8d74255ff47271c4c9eada7635676ccd320.1670005163.git.reinette.chatre@intel.com>
On 12/2/2022 11:25 AM, Reinette Chatre wrote:
> The workqueue is enabled when the appropriate driver is loaded and
> disabled when the driver is removed. When the driver is removed it
> assumes that the workqueue was enabled successfully and proceeds to
> free allocations made during workqueue enabling.
>
> Failure during workqueue enabling does not prevent the driver from
> being loaded. This is because the error path within drv_enable_wq()
> returns success unless a second failure is encountered
> during the error path. By returning success it is possible to load
> the driver even if the workqueue cannot be enabled and
> allocations that do not exist are attempted to be freed during
> driver remove.
>
> Some examples of problematic flows:
> (a)
>
> idxd_dmaengine_drv_probe() -> drv_enable_wq() -> idxd_wq_request_irq():
> In above flow, if idxd_wq_request_irq() fails then
> idxd_wq_unmap_portal() is called on error exit path, but
> drv_enable_wq() returns 0 because idxd_wq_disable() succeeds. The
> driver is thus loaded successfully.
>
> idxd_dmaengine_drv_remove()->drv_disable_wq()->idxd_wq_unmap_portal()
> Above flow on driver unload triggers the WARN in devm_iounmap() because
> the device resource has already been removed during error path of
> drv_enable_wq().
>
> (b)
>
> idxd_dmaengine_drv_probe() -> drv_enable_wq() -> idxd_wq_request_irq():
> In above flow, if idxd_wq_request_irq() fails then
> idxd_wq_init_percpu_ref() is never called to initialize the percpu
> counter, yet the driver loads successfully because drv_enable_wq()
> returns 0.
>
> idxd_dmaengine_drv_remove()->__idxd_wq_quiesce()->percpu_ref_kill():
> Above flow on driver unload triggers a BUG when attempting to drop the
> initial ref of the uninitialized percpu ref:
> BUG: kernel NULL pointer dereference, address: 0000000000000010
>
> Fix the drv_enable_wq() error path by returning the original error that
> indicates failure of workqueue enabling. This ensures that the probe
> fails when an error is encountered and the driver remove paths are only
> attempted when the workqueue was enabled successfully.
>
> Fixes: 1f2bb40337f0 ("dmaengine: idxd: move wq_enable() to device.c")
> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/dma/idxd/device.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
> index 6f44fa8f78a5..fcd03d29a941 100644
> --- a/drivers/dma/idxd/device.c
> +++ b/drivers/dma/idxd/device.c
> @@ -1391,8 +1391,7 @@ int drv_enable_wq(struct idxd_wq *wq)
> err_irq:
> idxd_wq_unmap_portal(wq);
> err_map_portal:
> - rc = idxd_wq_disable(wq, false);
> - if (rc < 0)
> + if (idxd_wq_disable(wq, false))
> dev_dbg(dev, "wq %s disable failed\n", dev_name(wq_confdev(wq)));
> err:
> return rc;
next prev parent reply other threads:[~2022-12-02 18:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-02 18:25 [PATCH 0/3] dmaengine: idxd: Error path fixes Reinette Chatre
2022-12-02 18:25 ` [PATCH 1/3] dmaengine: idxd: Let probe fail when workqueue cannot be enabled Reinette Chatre
2022-12-02 18:44 ` Dave Jiang [this message]
2022-12-02 18:52 ` Yu, Fenghua
2022-12-02 18:25 ` [PATCH 2/3] dmaengine: idxd: Prevent use after free on completion memory Reinette Chatre
2022-12-02 18:44 ` Dave Jiang
2022-12-02 19:45 ` Yu, Fenghua
2022-12-02 18:25 ` [PATCH 3/3] dmaengine: idxd: Do not call DMX TX callbacks during workqueue disable Reinette Chatre
2022-12-02 18:45 ` Dave Jiang
2022-12-02 21:12 ` Yu, Fenghua
2022-12-02 21:51 ` Reinette Chatre
2022-12-02 21:32 ` [PATCH 0/3] dmaengine: idxd: Error path fixes Yu, Fenghua
2022-12-02 21:53 ` Reinette Chatre
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=13d4bbcb-244e-df72-4281-755d4bc51274@intel.com \
--to=dave.jiang@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=fenghua.yu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=reinette.chatre@intel.com \
--cc=vkoul@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