dmaengine: introduce dmaengine_bh_wq and bh helpers
Subsystems (39)
Re: [PATCH v3 01/34] dmaengine: add tasklet-backed channel BH helpers
In reply to Allen PaisQuoted 10 lines · Allen Pais
DMAengine drivers commonly use a per-channel tasklet to invoke client callbacks. Add helpers that initialize, schedule, and kill a channel bottom half, with an initial tasklet-backed implementation that preserves the existing execution context.
Convert virt-dma to the new API and remove its private tasklet. Update all drivers that directly kill or override that tasklet in the same change so no stale users remain. While touching the completion handler, avoid forming a result pointer from a NULL cyclic descriptor.
Quoted 5 lines
This establishes a backend-independent API before changing how channel bottom halves are dispatched.
Signed-off-by Allen Pais <[email protected]>---
Quoted 724 lines
drivers/dma/bcm2835-dma.c | 2 +- drivers/dma/dma-axi-dmac.c | 10 +++-- drivers/dma/dma-jz4780.c | 2 +- drivers/dma/dmaengine.c | 42 +++++++++++++++++++ .../dma/dw-axi-dmac/dw-axi-dmac-platform.c | 2 +- drivers/dma/dw-edma/dw-edma-core.c | 2 +- drivers/dma/fsl-edma-common.c | 2 +- drivers/dma/fsl-qdma.c | 2 +- drivers/dma/hisi_dma.c | 2 +- drivers/dma/hsu/hsu.c | 2 +- drivers/dma/idma64.c | 4 +- drivers/dma/img-mdc-dma.c | 2 +- drivers/dma/imx-sdma.c | 4 +- drivers/dma/k3dma.c | 2 +- drivers/dma/loongson/loongson1-apb-dma.c | 2 +- drivers/dma/mediatek/mtk-cqdma.c | 2 +- drivers/dma/mediatek/mtk-hsdma.c | 2 +- drivers/dma/mediatek/mtk-uart-apdma.c | 4 +- drivers/dma/owl-dma.c | 2 +- drivers/dma/pxa_dma.c | 2 +- drivers/dma/qcom/bam_dma.c | 4 +- drivers/dma/qcom/qcom_adm.c | 4 +- drivers/dma/sa11x0-dma.c | 2 +- drivers/dma/sf-pdma/sf-pdma.c | 2 +- drivers/dma/sprd-dma.c | 2 +- drivers/dma/st_fdma.c | 2 +- drivers/dma/sun6i-dma.c | 2 +- drivers/dma/tegra186-gpc-dma.c | 2 +- drivers/dma/tegra210-adma.c | 2 +- drivers/dma/ti/edma.c | 2 +- drivers/dma/ti/k3-udma.c | 12 +++--- drivers/dma/ti/omap-dma.c | 2 +- drivers/dma/virt-dma.c | 12 +++--- drivers/dma/virt-dma.h | 7 ++-- include/linux/dmaengine.h | 28 +++++++++++++ 35 files changed, 125 insertions(+), 54 deletions(-)drivers/dma/bcm2835-dma.c +1
-1@@ -829,7 +829,7 @@ static void bcm2835_dma_free(struct bcm2835_dmadev *od)list_for_each_entry_safe (c, next, &od->ddev.channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); } dma_unmap_page_attrs(od->ddev.dev, od->zero_page, PAGE_SIZE,drivers/dma/dma-axi-dmac.c +6
-4@@ -1195,9 +1195,11 @@ static int axi_dmac_detect_caps(struct axi_dmac *dmac, unsigned int version)return 0 ; } -static void axi_dmac_tasklet_kill (void *task) +static void axi_dmac_kill_bh (void *data) { -tasklet_kill (task); +struct dma_chan *chan = data; + +dmaengine_kill_bh (chan); }static void axi_dmac_free_dma_controller (void *of_node)@@ -1302,8 +1304,8 @@ static int axi_dmac_probe(struct platform_device *pdev)* Put the action in here so it get's done before unregistering the DMA * device. */ - ret =devm_add_action_or_reset (&pdev->dev, axi_dmac_tasklet_kill, - &dmac->chan.vchan.task); + ret =devm_add_action_or_reset (&pdev->dev, axi_dmac_kill_bh, + &dmac->chan.vchan.chan);if (ret)return ret;drivers/dma/dma-jz4780.c +1
-1@@ -1019,7 +1019,7 @@ static void jz4780_dma_remove(struct platform_device *pdev)free_irq (jzdma->irq, jzdma);for (i =0 ; i < jzdma->soc_data->nb_channels; i++) -tasklet_kill (&jzdma->chan[i].vchan.task); +dmaengine_kill_bh (&jzdma->chan[i].vchan.chan); }static const struct jz4780_dma_soc_data jz4740_dma_soc_data = {drivers/dma/dmaengine.c +42
-0@@ -1428,6 +1428,48 @@ static void dmaengine_destroy_unmap_pool(void) } } +static void dma_chan_bh_entry (struct tasklet_struct *tasklet) +{ +struct dma_chan *chan =from_tasklet (chan, tasklet, bh_tasklet); +dmaengine_bh_work_fn fn =READ_ONCE (chan->bh_work_fn); + +if (fn) +fn (chan); +} + +void dmaengine_init_bh (struct dma_chan *chan,dmaengine_bh_work_fn fn) +{ +if (WARN_ON (!fn)) +return ; + +if (WARN_ON (chan->bh_work_initialized)) +return ; + + chan->bh_work_fn = fn; +tasklet_setup (&chan->bh_tasklet, dma_chan_bh_entry); + chan->bh_work_initialized = true; +} +EXPORT_SYMBOL_GPL (dmaengine_init_bh); + +bool dmaengine_schedule_bh (struct dma_chan *chan) +{ +if (WARN_ON (!chan->bh_work_initialized)) +return false; + +tasklet_schedule (&chan->bh_tasklet); +return true; +} +EXPORT_SYMBOL_GPL (dmaengine_schedule_bh); + +void dmaengine_kill_bh (struct dma_chan *chan) +{ +if (!chan->bh_work_initialized) +return ; + +tasklet_kill (&chan->bh_tasklet); +} +EXPORT_SYMBOL_GPL (dmaengine_kill_bh); +static int __init dmaengine_init_unmap_pool (void ) {int i;drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +1
-1@@ -1663,7 +1663,7 @@ static void dw_remove(struct platform_device *pdev)list_for_each_entry_safe (chan, _chan, &dw->dma.channels, vc.chan.device_node) {list_del (&chan->vc.chan.device_node); -tasklet_kill (&chan->vc.task); +dmaengine_kill_bh (&chan->vc.chan); } }drivers/dma/dw-edma/dw-edma-core.c +1
-1@@ -1170,7 +1170,7 @@ int dw_edma_remove(struct dw_edma_chip *chip)dma_async_device_unregister (&dw->dma);list_for_each_entry_safe (chan, _chan, &dw->dma.channels, vc.chan.device_node) { -tasklet_kill (&chan->vc.task); +dmaengine_kill_bh (&chan->vc.chan);list_del (&chan->vc.chan.device_node); }drivers/dma/fsl-edma-common.c +1
-1@@ -915,7 +915,7 @@ void fsl_edma_cleanup_vchan(struct dma_device *dmadev)list_for_each_entry_safe (chan, _chan, &dmadev->channels, vchan.chan.device_node) {list_del (&chan->vchan.chan.device_node); -tasklet_kill (&chan->vchan.task); +dmaengine_kill_bh (&chan->vchan.chan); } }drivers/dma/fsl-qdma.c +1
-1@@ -1255,7 +1255,7 @@ static void fsl_qdma_cleanup_vchan(struct dma_device *dmadev)list_for_each_entry_safe (chan, _chan, &dmadev->channels, vchan.chan.device_node) {list_del (&chan->vchan.chan.device_node); -tasklet_kill (&chan->vchan.task); +dmaengine_kill_bh (&chan->vchan.chan); } }drivers/dma/hisi_dma.c +1
-1@@ -720,7 +720,7 @@ static void hisi_dma_disable_qps(struct hisi_dma_dev *hdma_dev)for (i =0 ; i < hdma_dev->chan_num; i++) {hisi_dma_disable_qp (hdma_dev, i); -tasklet_kill (&hdma_dev->chan[i].vc.task); +dmaengine_kill_bh (&hdma_dev->chan[i].vc.chan); } }drivers/dma/hsu/hsu.c +1
-1@@ -500,7 +500,7 @@ int hsu_dma_remove(struct hsu_dma_chip *chip)for (i =0 ; i < hsu->nr_channels; i++) {struct hsu_dma_chan *hsuc = &hsu->chan[i]; -tasklet_kill (&hsuc->vchan.task); +dmaengine_kill_bh (&hsuc->vchan.chan); }return 0 ;drivers/dma/idma64.c +2
-2@@ -617,14 +617,14 @@ static void idma64_remove(struct idma64_chip *chip)/* * Explicitly call devm_request_irq() to avoid the side effects with -* the scheduled tasklets. +* scheduled BH work. */ devm_free_irq (chip->dev, chip->irq, idma64);for (i =0 ; i < idma64->dma.chancnt; i++) {struct idma64_chan *idma64c = &idma64->chan[i]; -tasklet_kill (&idma64c->vchan.task); +dmaengine_kill_bh (&idma64c->vchan.chan); } }drivers/dma/img-mdc-dma.c +1
-1@@ -1031,7 +1031,7 @@ static void mdc_dma_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, mchan->irq, mchan); -tasklet_kill (&mchan->vc.task); +dmaengine_kill_bh (&mchan->vc.chan); }pm_runtime_disable (&pdev->dev);drivers/dma/imx-sdma.c +2
-2@@ -2399,11 +2399,11 @@ static void sdma_remove(struct platform_device *pdev)int i;devm_free_irq (&pdev->dev, sdma->irq, sdma); -/* Kill the tasklet */ +/* Kill the channel BH */ for (i =0 ; i <MAX_DMA_CHANNELS ; i++) {struct sdma_channel *sdmac = &sdma->channel[i]; -tasklet_kill (&sdmac->vc.task); +dmaengine_kill_bh (&sdmac->vc.chan);sdma_free_chan_resources (&sdmac->vc.chan); }drivers/dma/k3dma.c +1
-1@@ -976,7 +976,7 @@ static void k3_dma_remove(struct platform_device *op)list_for_each_entry_safe (c, cn, &d->slave.channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); }tasklet_kill (&d->task);clk_disable_unprepare (d->clk);drivers/dma/loongson/loongson1-apb-dma.c +1
-1@@ -552,7 +552,7 @@ static void ls1x_dma_chan_remove(struct ls1x_dma *dma)if (chan->vc.chan.device == &dma->ddev) {list_del (&chan->vc.chan.device_node); -tasklet_kill (&chan->vc.task); +dmaengine_kill_bh (&chan->vc.chan); } } }drivers/dma/mediatek/mtk-cqdma.c +1
-1@@ -895,7 +895,7 @@ static void mtk_cqdma_remove(struct platform_device *pdev) vc = &cqdma->vc[i];list_del (&vc->vc.chan.device_node); -tasklet_kill (&vc->vc.task); +dmaengine_kill_bh (&vc->vc.chan); }/* disable interrupt */ drivers/dma/mediatek/mtk-hsdma.c +1
-1@@ -1020,7 +1020,7 @@ static void mtk_hsdma_remove(struct platform_device *pdev) vc = &hsdma->vc[i];list_del (&vc->vc.chan.device_node); -tasklet_kill (&vc->vc.task); +dmaengine_kill_bh (&vc->vc.chan); }/* Disable DMA interrupt */ drivers/dma/mediatek/mtk-uart-apdma.c +2
-2@@ -312,7 +312,7 @@ static void mtk_uart_apdma_free_chan_resources(struct dma_chan *chan)free_irq (c->irq, chan); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan);vchan_free_chan_resources (&c->vc);@@ -463,7 +463,7 @@ static void mtk_uart_apdma_free(struct mtk_uart_apdmadev *mtkd) struct mtk_chan, vc.chan.device_node);list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); } }drivers/dma/owl-dma.c +1
-1@@ -1055,7 +1055,7 @@ static inline void owl_dma_free(struct owl_dma *od)list_for_each_entry_safe (vchan, next, &od->dma.channels, vc.chan.device_node) {list_del (&vchan->vc.chan.device_node); -tasklet_kill (&vchan->vc.task); +dmaengine_kill_bh (&vchan->vc.chan); } }drivers/dma/pxa_dma.c +1
-1@@ -1215,7 +1215,7 @@ static void pxad_free_channels(struct dma_device *dmadev)list_for_each_entry_safe (c, cn, &dmadev->channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); } }drivers/dma/qcom/bam_dma.c +2
-2@@ -1387,7 +1387,7 @@ static int bam_dma_probe(struct platform_device *pdev)dma_async_device_unregister (&bdev->common); err_bam_channel_exit:for (i =0 ; i < bdev->num_channels; i++) -tasklet_kill (&bdev->channels[i].vc.task); +dmaengine_kill_bh (&bdev->channels[i].vc.chan); err_tasklet_kill:tasklet_kill (&bdev->task); err_disable_clk:@@ -1413,7 +1413,7 @@ static void bam_dma_remove(struct platform_device *pdev)for (i =0 ; i < bdev->num_channels; i++) {bam_dma_terminate_all (&bdev->channels[i].vc.chan); -tasklet_kill (&bdev->channels[i].vc.task); +dmaengine_kill_bh (&bdev->channels[i].vc.chan);if (!bdev->channels[i].fifo_virt)continue ;drivers/dma/qcom/qcom_adm.c +2
-2@@ -918,8 +918,8 @@ static void adm_dma_remove(struct platform_device *pdev)/* mask IRQs for this channel/EE pair */ writel (0 , adev->regs +ADM_CH_RSLT_CONF (achan->id, adev->ee)); -tasklet_kill (&adev->channels[i].vc.task); -adm_terminate_all (&adev->channels[i].vc.chan); +dmaengine_kill_bh (&achan->vc.chan); +adm_terminate_all (&achan->vc.chan); }devm_free_irq (adev->dev, adev->irq, adev);drivers/dma/sa11x0-dma.c +1
-1@@ -891,7 +891,7 @@ static void sa11x0_dma_free_channels(struct dma_device *dmadev)list_for_each_entry_safe (c, cn, &dmadev->channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan);kfree (c); } }drivers/dma/sf-pdma/sf-pdma.c +1
-1@@ -602,7 +602,7 @@ static void sf_pdma_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, ch->txirq, ch);devm_free_irq (&pdev->dev, ch->errirq, ch);list_del (&ch->vchan.chan.device_node); -tasklet_kill (&ch->vchan.task); +dmaengine_kill_bh (&ch->vchan.chan);tasklet_kill (&ch->done_tasklet);tasklet_kill (&ch->err_tasklet); }drivers/dma/sprd-dma.c +1
-1@@ -1253,7 +1253,7 @@ static void sprd_dma_remove(struct platform_device *pdev)list_for_each_entry_safe (c, cn, &sdev->dma_dev.channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); }of_dma_controller_free (pdev->dev.of_node);drivers/dma/st_fdma.c +1
-1@@ -733,7 +733,7 @@ static void st_fdma_free(struct st_fdma_dev *fdev)for (i =0 ; i < fdev->nr_channels; i++) { fchan = &fdev->chans[i];list_del (&fchan->vchan.chan.device_node); -tasklet_kill (&fchan->vchan.task); +dmaengine_kill_bh (&fchan->vchan.chan); } }drivers/dma/sun6i-dma.c +1
-1@@ -1094,7 +1094,7 @@ static inline void sun6i_dma_free(struct sun6i_dma_dev *sdev)struct sun6i_vchan *vchan = &sdev->vchans[i];list_del (&vchan->vc.chan.device_node); -tasklet_kill (&vchan->vc.task); +dmaengine_kill_bh (&vchan->vc.chan); } }drivers/dma/tegra186-gpc-dma.c +1
-1@@ -1284,7 +1284,7 @@ static void tegra_dma_free_chan_resources(struct dma_chan *dc)tegra_dma_terminate_all (dc);synchronize_irq (tdc->irq); -tasklet_kill (&tdc->vc.task); +dmaengine_kill_bh (&tdc->vc.chan); tdc->config_init = false; tdc->slave_id =-1 ; tdc->sid_dir =DMA_TRANS_NONE ;drivers/dma/tegra210-adma.c +1
-1@@ -811,7 +811,7 @@ static void tegra_adma_free_chan_resources(struct dma_chan *dc)tegra_adma_terminate_all (dc);vchan_free_chan_resources (&tdc->vc); -tasklet_kill (&tdc->vc.task); +dmaengine_kill_bh (&tdc->vc.chan);free_irq (tdc->irq, tdc);pm_runtime_put (tdc2dev (tdc));drivers/dma/ti/edma.c +1
-1@@ -2560,7 +2560,7 @@ static void edma_cleanupp_vchan(struct dma_device *dmadev)list_for_each_entry_safe (echan, _echan, &dmadev->channels, vchan.chan.device_node) {list_del (&echan->vchan.chan.device_node); -tasklet_kill (&echan->vchan.task); +dmaengine_kill_bh (&echan->vchan.chan); } }drivers/dma/ti/k3-udma.c +6
-6@@ -4042,12 +4042,12 @@ static void udma_desc_pre_callback(struct virt_dma_chan *vc, }/* -* This tasklet handles the completion of a DMA descriptor by +* This BH handles the completion of a DMA descriptor by * calling its callback and freeing it. */ -static void udma_vchan_complete (struct tasklet_struct *t) +static void udma_vchan_complete (struct dma_chan *chan) { -struct virt_dma_chan *vc =from_tasklet (vc, t, task); +struct virt_dma_chan *vc =to_virt_chan (chan);struct virt_dma_desc *vd, *_vd;struct dmaengine_desc_callback cb;LIST_HEAD (head);@@ -4112,7 +4112,7 @@ static void udma_free_chan_resources(struct dma_chan *chan) }vchan_free_chan_resources (&uc->vc); -tasklet_kill (&uc->vc.task); +dmaengine_kill_bh (&uc->vc.chan);bcdma_free_bchan_resources (uc);udma_free_tx_resources (uc);@@ -5627,8 +5627,8 @@ static int udma_probe(struct platform_device *pdev)if (!uc->name)return -ENOMEM ;vchan_init (&uc->vc, &ud->ddev); -/* Use custom vchan completion handling */ -tasklet_setup (&uc->vc.task, udma_vchan_complete); +/* Override the default vchan completion handler */ + uc->vc.chan.bh_work_fn = udma_vchan_complete;init_completion (&uc->teardown_completed);INIT_DELAYED_WORK (&uc->tx_drain.work, udma_check_tx_completion); }drivers/dma/ti/omap-dma.c +1
-1@@ -1521,7 +1521,7 @@ static void omap_dma_free(struct omap_dmadev *od) struct omap_chan, vc.chan.device_node);list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan);kfree (c); } }drivers/dma/virt-dma.c +6
-6@@ -77,12 +77,12 @@ struct virt_dma_desc *vchan_find_desc(struct virt_dma_chan *vc,EXPORT_SYMBOL_GPL (vchan_find_desc);/* -* This tasklet handles the completion of a DMA descriptor by -* calling its callback and freeing it. +* This bottom-half handler completes a DMA descriptor by invoking its +* callback and freeing it. */ -static void vchan_complete (struct tasklet_struct *t) +static void vchan_complete (struct dma_chan *chan) { -struct virt_dma_chan *vc =from_tasklet (vc, t, task); +struct virt_dma_chan *vc =to_virt_chan (chan);struct virt_dma_desc *vd, *_vd;struct dmaengine_desc_callback cb;LIST_HEAD (head);@@ -98,7 +98,7 @@ static void vchan_complete(struct tasklet_struct *t) }spin_unlock_irq (&vc->lock); -dmaengine_desc_callback_invoke (&cb, &vd->tx_result); +dmaengine_desc_callback_invoke (&cb, vd ? &vd->tx_result :NULL );list_for_each_entry_safe (vd, _vd, &head, node) {dmaengine_desc_get_callback (&vd->tx, &cb);@@ -131,7 +131,7 @@ void vchan_init(struct virt_dma_chan *vc, struct dma_device *dmadev)INIT_LIST_HEAD (&vc->desc_completed);INIT_LIST_HEAD (&vc->desc_terminated); -tasklet_setup (&vc->task, vchan_complete); +dmaengine_init_bh (&vc->chan, vchan_complete); vc->chan.device = dmadev;list_add_tail (&vc->chan.device_node, &dmadev->channels);drivers/dma/virt-dma.h +3
-4@@ -21,7 +21,6 @@ struct virt_dma_desc {struct virt_dma_chan {struct dma_chan chan; -struct tasklet_struct task;void (*desc_free)(struct virt_dma_desc *);spinlock_t lock;@@ -106,7 +105,7 @@ static inline void vchan_cookie_complete(struct virt_dma_desc *vd) vd, cookie);list_add_tail (&vd->node, &vc->desc_completed); -tasklet_schedule (&vc->task); +dmaengine_schedule_bh (&vc->chan); }/** @@ -137,7 +136,7 @@ static inline void vchan_cyclic_callback(struct virt_dma_desc *vd)struct virt_dma_chan *vc =to_virt_chan (vd->tx.chan); vc->cyclic = vd; -tasklet_schedule (&vc->task); +dmaengine_schedule_bh (&vc->chan); }/** @@ -223,7 +222,7 @@ static inline void vchan_synchronize(struct virt_dma_chan *vc)LIST_HEAD (head);unsigned long flags; -tasklet_kill (&vc->task); +dmaengine_kill_bh (&vc->chan);spin_lock_irqsave (&vc->lock, flags);include/linux/dmaengine.h +28
-1@@ -12,6 +12,7 @@#include <linux/scatterlist.h> #include <linux/bitmap.h> #include <linux/types.h> +#include <linux/interrupt.h> #include <asm/page.h> /** @@ -295,6 +296,10 @@ enum dma_desc_metadata_mode { DESC_METADATA_ENGINE = BIT(1), }; +struct dma_chan ; + +typedef void (*dmaengine_bh_work_fn )(struct dma_chan *chan); +/** * struct dma_chan_percpu - the per-CPU part of struct dma_chan * @memcpy_count: transaction counter @@ -334,6 +339,9 @@ struct dma_router {* @router: pointer to the DMA router structure * @route_data: channel specific data for the router * @private: private data for certain client-channel associations +* @bh_tasklet: bottom-half tasklet stored per-channel +* @bh_work_fn: callback executed when @bh_tasklet runs +* @bh_work_initialized: indicates whether @bh_tasklet has been initialized */ struct dma_chan {struct dma_device *device;@@ -359,6 +367,9 @@ struct dma_chan {void *route_data;void *private; +struct tasklet_struct bh_tasklet; +dmaengine_bh_work_fn bh_work_fn; +bool bh_work_initialized; };/** @@ -1529,6 +1540,9 @@ struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name);void dma_release_channel (struct dma_chan *chan);int dma_get_slave_caps (struct dma_chan *chan,struct dma_slave_caps *caps); +void dmaengine_init_bh (struct dma_chan *chan,dmaengine_bh_work_fn fn); +bool dmaengine_schedule_bh (struct dma_chan *chan); +void dmaengine_kill_bh (struct dma_chan *chan);#else static inline struct dma_chan *dma_find_channel (enum dma_transaction_type tx_type) {@@ -1576,6 +1590,20 @@ static inline int dma_get_slave_caps(struct dma_chan *chan, {return -ENXIO ; } + +static inline void dmaengine_init_bh (struct dma_chan *chan, +dmaengine_bh_work_fn fn) +{ +} + +static inline bool dmaengine_schedule_bh (struct dma_chan *chan) +{ +return false; +} + +static inline void dmaengine_kill_bh (struct dma_chan *chan) +{ +}#endif static inline int dmaengine_desc_set_reuse (struct dma_async_tx_descriptor *tx) --2.43.0
Re: [PATCH v3 01/34] dmaengine: add tasklet-backed channel BH helpers
In reply to Allen PaisQuoted 10 lines · Allen Pais
DMAengine drivers commonly use a per-channel tasklet to invoke client callbacks. Add helpers that initialize, schedule, and kill a channel bottom half, with an initial tasklet-backed implementation that preserves the existing execution context.
Convert virt-dma to the new API and remove its private tasklet. Update all drivers that directly kill or override that tasklet in the same change so no stale users remain. While touching the completion handler, avoid forming a result pointer from a NULL cyclic descriptor.
Quoted 5 lines
This establishes a backend-independent API before changing how channel bottom halves are dispatched.
Signed-off-by Allen Pais <[email protected]>---
Quoted 724 lines
drivers/dma/bcm2835-dma.c | 2 +- drivers/dma/dma-axi-dmac.c | 10 +++-- drivers/dma/dma-jz4780.c | 2 +- drivers/dma/dmaengine.c | 42 +++++++++++++++++++ .../dma/dw-axi-dmac/dw-axi-dmac-platform.c | 2 +- drivers/dma/dw-edma/dw-edma-core.c | 2 +- drivers/dma/fsl-edma-common.c | 2 +- drivers/dma/fsl-qdma.c | 2 +- drivers/dma/hisi_dma.c | 2 +- drivers/dma/hsu/hsu.c | 2 +- drivers/dma/idma64.c | 4 +- drivers/dma/img-mdc-dma.c | 2 +- drivers/dma/imx-sdma.c | 4 +- drivers/dma/k3dma.c | 2 +- drivers/dma/loongson/loongson1-apb-dma.c | 2 +- drivers/dma/mediatek/mtk-cqdma.c | 2 +- drivers/dma/mediatek/mtk-hsdma.c | 2 +- drivers/dma/mediatek/mtk-uart-apdma.c | 4 +- drivers/dma/owl-dma.c | 2 +- drivers/dma/pxa_dma.c | 2 +- drivers/dma/qcom/bam_dma.c | 4 +- drivers/dma/qcom/qcom_adm.c | 4 +- drivers/dma/sa11x0-dma.c | 2 +- drivers/dma/sf-pdma/sf-pdma.c | 2 +- drivers/dma/sprd-dma.c | 2 +- drivers/dma/st_fdma.c | 2 +- drivers/dma/sun6i-dma.c | 2 +- drivers/dma/tegra186-gpc-dma.c | 2 +- drivers/dma/tegra210-adma.c | 2 +- drivers/dma/ti/edma.c | 2 +- drivers/dma/ti/k3-udma.c | 12 +++--- drivers/dma/ti/omap-dma.c | 2 +- drivers/dma/virt-dma.c | 12 +++--- drivers/dma/virt-dma.h | 7 ++-- include/linux/dmaengine.h | 28 +++++++++++++ 35 files changed, 125 insertions(+), 54 deletions(-)drivers/dma/bcm2835-dma.c +1
-1@@ -829,7 +829,7 @@ static void bcm2835_dma_free(struct bcm2835_dmadev *od)list_for_each_entry_safe (c, next, &od->ddev.channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); } dma_unmap_page_attrs(od->ddev.dev, od->zero_page, PAGE_SIZE,drivers/dma/dma-axi-dmac.c +6
-4@@ -1195,9 +1195,11 @@ static int axi_dmac_detect_caps(struct axi_dmac *dmac, unsigned int version)return 0 ; } -static void axi_dmac_tasklet_kill (void *task) +static void axi_dmac_kill_bh (void *data) { -tasklet_kill (task); +struct dma_chan *chan = data; + +dmaengine_kill_bh (chan); }static void axi_dmac_free_dma_controller (void *of_node)@@ -1302,8 +1304,8 @@ static int axi_dmac_probe(struct platform_device *pdev)* Put the action in here so it get's done before unregistering the DMA * device. */ - ret =devm_add_action_or_reset (&pdev->dev, axi_dmac_tasklet_kill, - &dmac->chan.vchan.task); + ret =devm_add_action_or_reset (&pdev->dev, axi_dmac_kill_bh, + &dmac->chan.vchan.chan);if (ret)return ret;drivers/dma/dma-jz4780.c +1
-1@@ -1019,7 +1019,7 @@ static void jz4780_dma_remove(struct platform_device *pdev)free_irq (jzdma->irq, jzdma);for (i =0 ; i < jzdma->soc_data->nb_channels; i++) -tasklet_kill (&jzdma->chan[i].vchan.task); +dmaengine_kill_bh (&jzdma->chan[i].vchan.chan); }static const struct jz4780_dma_soc_data jz4740_dma_soc_data = {drivers/dma/dmaengine.c +42
-0@@ -1428,6 +1428,48 @@ static void dmaengine_destroy_unmap_pool(void) } } +static void dma_chan_bh_entry (struct tasklet_struct *tasklet) +{ +struct dma_chan *chan =from_tasklet (chan, tasklet, bh_tasklet); +dmaengine_bh_work_fn fn =READ_ONCE (chan->bh_work_fn); + +if (fn) +fn (chan); +} + +void dmaengine_init_bh (struct dma_chan *chan,dmaengine_bh_work_fn fn) +{ +if (WARN_ON (!fn)) +return ; + +if (WARN_ON (chan->bh_work_initialized)) +return ; + + chan->bh_work_fn = fn; +tasklet_setup (&chan->bh_tasklet, dma_chan_bh_entry); + chan->bh_work_initialized = true; +} +EXPORT_SYMBOL_GPL (dmaengine_init_bh); + +bool dmaengine_schedule_bh (struct dma_chan *chan) +{ +if (WARN_ON (!chan->bh_work_initialized)) +return false; + +tasklet_schedule (&chan->bh_tasklet); +return true; +} +EXPORT_SYMBOL_GPL (dmaengine_schedule_bh); + +void dmaengine_kill_bh (struct dma_chan *chan) +{ +if (!chan->bh_work_initialized) +return ; + +tasklet_kill (&chan->bh_tasklet); +} +EXPORT_SYMBOL_GPL (dmaengine_kill_bh); +static int __init dmaengine_init_unmap_pool (void ) {int i;drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +1
-1@@ -1663,7 +1663,7 @@ static void dw_remove(struct platform_device *pdev)list_for_each_entry_safe (chan, _chan, &dw->dma.channels, vc.chan.device_node) {list_del (&chan->vc.chan.device_node); -tasklet_kill (&chan->vc.task); +dmaengine_kill_bh (&chan->vc.chan); } }drivers/dma/dw-edma/dw-edma-core.c +1
-1@@ -1170,7 +1170,7 @@ int dw_edma_remove(struct dw_edma_chip *chip)dma_async_device_unregister (&dw->dma);list_for_each_entry_safe (chan, _chan, &dw->dma.channels, vc.chan.device_node) { -tasklet_kill (&chan->vc.task); +dmaengine_kill_bh (&chan->vc.chan);list_del (&chan->vc.chan.device_node); }drivers/dma/fsl-edma-common.c +1
-1@@ -915,7 +915,7 @@ void fsl_edma_cleanup_vchan(struct dma_device *dmadev)list_for_each_entry_safe (chan, _chan, &dmadev->channels, vchan.chan.device_node) {list_del (&chan->vchan.chan.device_node); -tasklet_kill (&chan->vchan.task); +dmaengine_kill_bh (&chan->vchan.chan); } }drivers/dma/fsl-qdma.c +1
-1@@ -1255,7 +1255,7 @@ static void fsl_qdma_cleanup_vchan(struct dma_device *dmadev)list_for_each_entry_safe (chan, _chan, &dmadev->channels, vchan.chan.device_node) {list_del (&chan->vchan.chan.device_node); -tasklet_kill (&chan->vchan.task); +dmaengine_kill_bh (&chan->vchan.chan); } }drivers/dma/hisi_dma.c +1
-1@@ -720,7 +720,7 @@ static void hisi_dma_disable_qps(struct hisi_dma_dev *hdma_dev)for (i =0 ; i < hdma_dev->chan_num; i++) {hisi_dma_disable_qp (hdma_dev, i); -tasklet_kill (&hdma_dev->chan[i].vc.task); +dmaengine_kill_bh (&hdma_dev->chan[i].vc.chan); } }drivers/dma/hsu/hsu.c +1
-1@@ -500,7 +500,7 @@ int hsu_dma_remove(struct hsu_dma_chip *chip)for (i =0 ; i < hsu->nr_channels; i++) {struct hsu_dma_chan *hsuc = &hsu->chan[i]; -tasklet_kill (&hsuc->vchan.task); +dmaengine_kill_bh (&hsuc->vchan.chan); }return 0 ;drivers/dma/idma64.c +2
-2@@ -617,14 +617,14 @@ static void idma64_remove(struct idma64_chip *chip)/* * Explicitly call devm_request_irq() to avoid the side effects with -* the scheduled tasklets. +* scheduled BH work. */ devm_free_irq (chip->dev, chip->irq, idma64);for (i =0 ; i < idma64->dma.chancnt; i++) {struct idma64_chan *idma64c = &idma64->chan[i]; -tasklet_kill (&idma64c->vchan.task); +dmaengine_kill_bh (&idma64c->vchan.chan); } }drivers/dma/img-mdc-dma.c +1
-1@@ -1031,7 +1031,7 @@ static void mdc_dma_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, mchan->irq, mchan); -tasklet_kill (&mchan->vc.task); +dmaengine_kill_bh (&mchan->vc.chan); }pm_runtime_disable (&pdev->dev);drivers/dma/imx-sdma.c +2
-2@@ -2399,11 +2399,11 @@ static void sdma_remove(struct platform_device *pdev)int i;devm_free_irq (&pdev->dev, sdma->irq, sdma); -/* Kill the tasklet */ +/* Kill the channel BH */ for (i =0 ; i <MAX_DMA_CHANNELS ; i++) {struct sdma_channel *sdmac = &sdma->channel[i]; -tasklet_kill (&sdmac->vc.task); +dmaengine_kill_bh (&sdmac->vc.chan);sdma_free_chan_resources (&sdmac->vc.chan); }drivers/dma/k3dma.c +1
-1@@ -976,7 +976,7 @@ static void k3_dma_remove(struct platform_device *op)list_for_each_entry_safe (c, cn, &d->slave.channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); }tasklet_kill (&d->task);clk_disable_unprepare (d->clk);drivers/dma/loongson/loongson1-apb-dma.c +1
-1@@ -552,7 +552,7 @@ static void ls1x_dma_chan_remove(struct ls1x_dma *dma)if (chan->vc.chan.device == &dma->ddev) {list_del (&chan->vc.chan.device_node); -tasklet_kill (&chan->vc.task); +dmaengine_kill_bh (&chan->vc.chan); } } }drivers/dma/mediatek/mtk-cqdma.c +1
-1@@ -895,7 +895,7 @@ static void mtk_cqdma_remove(struct platform_device *pdev) vc = &cqdma->vc[i];list_del (&vc->vc.chan.device_node); -tasklet_kill (&vc->vc.task); +dmaengine_kill_bh (&vc->vc.chan); }/* disable interrupt */ drivers/dma/mediatek/mtk-hsdma.c +1
-1@@ -1020,7 +1020,7 @@ static void mtk_hsdma_remove(struct platform_device *pdev) vc = &hsdma->vc[i];list_del (&vc->vc.chan.device_node); -tasklet_kill (&vc->vc.task); +dmaengine_kill_bh (&vc->vc.chan); }/* Disable DMA interrupt */ drivers/dma/mediatek/mtk-uart-apdma.c +2
-2@@ -312,7 +312,7 @@ static void mtk_uart_apdma_free_chan_resources(struct dma_chan *chan)free_irq (c->irq, chan); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan);vchan_free_chan_resources (&c->vc);@@ -463,7 +463,7 @@ static void mtk_uart_apdma_free(struct mtk_uart_apdmadev *mtkd) struct mtk_chan, vc.chan.device_node);list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); } }drivers/dma/owl-dma.c +1
-1@@ -1055,7 +1055,7 @@ static inline void owl_dma_free(struct owl_dma *od)list_for_each_entry_safe (vchan, next, &od->dma.channels, vc.chan.device_node) {list_del (&vchan->vc.chan.device_node); -tasklet_kill (&vchan->vc.task); +dmaengine_kill_bh (&vchan->vc.chan); } }drivers/dma/pxa_dma.c +1
-1@@ -1215,7 +1215,7 @@ static void pxad_free_channels(struct dma_device *dmadev)list_for_each_entry_safe (c, cn, &dmadev->channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); } }drivers/dma/qcom/bam_dma.c +2
-2@@ -1387,7 +1387,7 @@ static int bam_dma_probe(struct platform_device *pdev)dma_async_device_unregister (&bdev->common); err_bam_channel_exit:for (i =0 ; i < bdev->num_channels; i++) -tasklet_kill (&bdev->channels[i].vc.task); +dmaengine_kill_bh (&bdev->channels[i].vc.chan); err_tasklet_kill:tasklet_kill (&bdev->task); err_disable_clk:@@ -1413,7 +1413,7 @@ static void bam_dma_remove(struct platform_device *pdev)for (i =0 ; i < bdev->num_channels; i++) {bam_dma_terminate_all (&bdev->channels[i].vc.chan); -tasklet_kill (&bdev->channels[i].vc.task); +dmaengine_kill_bh (&bdev->channels[i].vc.chan);if (!bdev->channels[i].fifo_virt)continue ;drivers/dma/qcom/qcom_adm.c +2
-2@@ -918,8 +918,8 @@ static void adm_dma_remove(struct platform_device *pdev)/* mask IRQs for this channel/EE pair */ writel (0 , adev->regs +ADM_CH_RSLT_CONF (achan->id, adev->ee)); -tasklet_kill (&adev->channels[i].vc.task); -adm_terminate_all (&adev->channels[i].vc.chan); +dmaengine_kill_bh (&achan->vc.chan); +adm_terminate_all (&achan->vc.chan); }devm_free_irq (adev->dev, adev->irq, adev);drivers/dma/sa11x0-dma.c +1
-1@@ -891,7 +891,7 @@ static void sa11x0_dma_free_channels(struct dma_device *dmadev)list_for_each_entry_safe (c, cn, &dmadev->channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan);kfree (c); } }drivers/dma/sf-pdma/sf-pdma.c +1
-1@@ -602,7 +602,7 @@ static void sf_pdma_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, ch->txirq, ch);devm_free_irq (&pdev->dev, ch->errirq, ch);list_del (&ch->vchan.chan.device_node); -tasklet_kill (&ch->vchan.task); +dmaengine_kill_bh (&ch->vchan.chan);tasklet_kill (&ch->done_tasklet);tasklet_kill (&ch->err_tasklet); }drivers/dma/sprd-dma.c +1
-1@@ -1253,7 +1253,7 @@ static void sprd_dma_remove(struct platform_device *pdev)list_for_each_entry_safe (c, cn, &sdev->dma_dev.channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan); }of_dma_controller_free (pdev->dev.of_node);drivers/dma/st_fdma.c +1
-1@@ -733,7 +733,7 @@ static void st_fdma_free(struct st_fdma_dev *fdev)for (i =0 ; i < fdev->nr_channels; i++) { fchan = &fdev->chans[i];list_del (&fchan->vchan.chan.device_node); -tasklet_kill (&fchan->vchan.task); +dmaengine_kill_bh (&fchan->vchan.chan); } }drivers/dma/sun6i-dma.c +1
-1@@ -1094,7 +1094,7 @@ static inline void sun6i_dma_free(struct sun6i_dma_dev *sdev)struct sun6i_vchan *vchan = &sdev->vchans[i];list_del (&vchan->vc.chan.device_node); -tasklet_kill (&vchan->vc.task); +dmaengine_kill_bh (&vchan->vc.chan); } }drivers/dma/tegra186-gpc-dma.c +1
-1@@ -1284,7 +1284,7 @@ static void tegra_dma_free_chan_resources(struct dma_chan *dc)tegra_dma_terminate_all (dc);synchronize_irq (tdc->irq); -tasklet_kill (&tdc->vc.task); +dmaengine_kill_bh (&tdc->vc.chan); tdc->config_init = false; tdc->slave_id =-1 ; tdc->sid_dir =DMA_TRANS_NONE ;drivers/dma/tegra210-adma.c +1
-1@@ -811,7 +811,7 @@ static void tegra_adma_free_chan_resources(struct dma_chan *dc)tegra_adma_terminate_all (dc);vchan_free_chan_resources (&tdc->vc); -tasklet_kill (&tdc->vc.task); +dmaengine_kill_bh (&tdc->vc.chan);free_irq (tdc->irq, tdc);pm_runtime_put (tdc2dev (tdc));drivers/dma/ti/edma.c +1
-1@@ -2560,7 +2560,7 @@ static void edma_cleanupp_vchan(struct dma_device *dmadev)list_for_each_entry_safe (echan, _echan, &dmadev->channels, vchan.chan.device_node) {list_del (&echan->vchan.chan.device_node); -tasklet_kill (&echan->vchan.task); +dmaengine_kill_bh (&echan->vchan.chan); } }drivers/dma/ti/k3-udma.c +6
-6@@ -4042,12 +4042,12 @@ static void udma_desc_pre_callback(struct virt_dma_chan *vc, }/* -* This tasklet handles the completion of a DMA descriptor by +* This BH handles the completion of a DMA descriptor by * calling its callback and freeing it. */ -static void udma_vchan_complete (struct tasklet_struct *t) +static void udma_vchan_complete (struct dma_chan *chan) { -struct virt_dma_chan *vc =from_tasklet (vc, t, task); +struct virt_dma_chan *vc =to_virt_chan (chan);struct virt_dma_desc *vd, *_vd;struct dmaengine_desc_callback cb;LIST_HEAD (head);@@ -4112,7 +4112,7 @@ static void udma_free_chan_resources(struct dma_chan *chan) }vchan_free_chan_resources (&uc->vc); -tasklet_kill (&uc->vc.task); +dmaengine_kill_bh (&uc->vc.chan);bcdma_free_bchan_resources (uc);udma_free_tx_resources (uc);@@ -5627,8 +5627,8 @@ static int udma_probe(struct platform_device *pdev)if (!uc->name)return -ENOMEM ;vchan_init (&uc->vc, &ud->ddev); -/* Use custom vchan completion handling */ -tasklet_setup (&uc->vc.task, udma_vchan_complete); +/* Override the default vchan completion handler */ + uc->vc.chan.bh_work_fn = udma_vchan_complete;init_completion (&uc->teardown_completed);INIT_DELAYED_WORK (&uc->tx_drain.work, udma_check_tx_completion); }drivers/dma/ti/omap-dma.c +1
-1@@ -1521,7 +1521,7 @@ static void omap_dma_free(struct omap_dmadev *od) struct omap_chan, vc.chan.device_node);list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +dmaengine_kill_bh (&c->vc.chan);kfree (c); } }drivers/dma/virt-dma.c +6
-6@@ -77,12 +77,12 @@ struct virt_dma_desc *vchan_find_desc(struct virt_dma_chan *vc,EXPORT_SYMBOL_GPL (vchan_find_desc);/* -* This tasklet handles the completion of a DMA descriptor by -* calling its callback and freeing it. +* This bottom-half handler completes a DMA descriptor by invoking its +* callback and freeing it. */ -static void vchan_complete (struct tasklet_struct *t) +static void vchan_complete (struct dma_chan *chan) { -struct virt_dma_chan *vc =from_tasklet (vc, t, task); +struct virt_dma_chan *vc =to_virt_chan (chan);struct virt_dma_desc *vd, *_vd;struct dmaengine_desc_callback cb;LIST_HEAD (head);@@ -98,7 +98,7 @@ static void vchan_complete(struct tasklet_struct *t) }spin_unlock_irq (&vc->lock); -dmaengine_desc_callback_invoke (&cb, &vd->tx_result); +dmaengine_desc_callback_invoke (&cb, vd ? &vd->tx_result :NULL );list_for_each_entry_safe (vd, _vd, &head, node) {dmaengine_desc_get_callback (&vd->tx, &cb);@@ -131,7 +131,7 @@ void vchan_init(struct virt_dma_chan *vc, struct dma_device *dmadev)INIT_LIST_HEAD (&vc->desc_completed);INIT_LIST_HEAD (&vc->desc_terminated); -tasklet_setup (&vc->task, vchan_complete); +dmaengine_init_bh (&vc->chan, vchan_complete); vc->chan.device = dmadev;list_add_tail (&vc->chan.device_node, &dmadev->channels);drivers/dma/virt-dma.h +3
-4@@ -21,7 +21,6 @@ struct virt_dma_desc {struct virt_dma_chan {struct dma_chan chan; -struct tasklet_struct task;void (*desc_free)(struct virt_dma_desc *);spinlock_t lock;@@ -106,7 +105,7 @@ static inline void vchan_cookie_complete(struct virt_dma_desc *vd) vd, cookie);list_add_tail (&vd->node, &vc->desc_completed); -tasklet_schedule (&vc->task); +dmaengine_schedule_bh (&vc->chan); }/** @@ -137,7 +136,7 @@ static inline void vchan_cyclic_callback(struct virt_dma_desc *vd)struct virt_dma_chan *vc =to_virt_chan (vd->tx.chan); vc->cyclic = vd; -tasklet_schedule (&vc->task); +dmaengine_schedule_bh (&vc->chan); }/** @@ -223,7 +222,7 @@ static inline void vchan_synchronize(struct virt_dma_chan *vc)LIST_HEAD (head);unsigned long flags; -tasklet_kill (&vc->task); +dmaengine_kill_bh (&vc->chan);spin_lock_irqsave (&vc->lock, flags);include/linux/dmaengine.h +28
-1@@ -12,6 +12,7 @@#include <linux/scatterlist.h> #include <linux/bitmap.h> #include <linux/types.h> +#include <linux/interrupt.h> #include <asm/page.h> /** @@ -295,6 +296,10 @@ enum dma_desc_metadata_mode { DESC_METADATA_ENGINE = BIT(1), }; +struct dma_chan ; + +typedef void (*dmaengine_bh_work_fn )(struct dma_chan *chan); +/** * struct dma_chan_percpu - the per-CPU part of struct dma_chan * @memcpy_count: transaction counter @@ -334,6 +339,9 @@ struct dma_router {* @router: pointer to the DMA router structure * @route_data: channel specific data for the router * @private: private data for certain client-channel associations +* @bh_tasklet: bottom-half tasklet stored per-channel +* @bh_work_fn: callback executed when @bh_tasklet runs +* @bh_work_initialized: indicates whether @bh_tasklet has been initialized */ struct dma_chan {struct dma_device *device;@@ -359,6 +367,9 @@ struct dma_chan {void *route_data;void *private; +struct tasklet_struct bh_tasklet; +dmaengine_bh_work_fn bh_work_fn; +bool bh_work_initialized; };/** @@ -1529,6 +1540,9 @@ struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name);void dma_release_channel (struct dma_chan *chan);int dma_get_slave_caps (struct dma_chan *chan,struct dma_slave_caps *caps); +void dmaengine_init_bh (struct dma_chan *chan,dmaengine_bh_work_fn fn); +bool dmaengine_schedule_bh (struct dma_chan *chan); +void dmaengine_kill_bh (struct dma_chan *chan);#else static inline struct dma_chan *dma_find_channel (enum dma_transaction_type tx_type) {@@ -1576,6 +1590,20 @@ static inline int dma_get_slave_caps(struct dma_chan *chan, {return -ENXIO ; } + +static inline void dmaengine_init_bh (struct dma_chan *chan, +dmaengine_bh_work_fn fn) +{ +} + +static inline bool dmaengine_schedule_bh (struct dma_chan *chan) +{ +return false; +} + +static inline void dmaengine_kill_bh (struct dma_chan *chan) +{ +}#endif static inline int dmaengine_desc_set_reuse (struct dma_async_tx_descriptor *tx) --2.43.0
PATCH v3 2/34 dmaengine: back channel BH helpers with WQ_BH
In reply to Allen PaisReplace the tasklet implementation of the channel BH helpers with a dedicated WQ_BH | WQ_PERCPU workqueue. The public dmaengine_*_bh() API and its softirq execution context remain unchanged.
Keep the workqueue operations internal to dmaengine. Drain scheduled work in dmaengine_kill_bh() to preserve the completion semantics of tasklet_kill().
--- drivers/dma/dmaengine.c | 59 ++++++++++++++++++++++++++++++++------- include/linux/dmaengine.h | 10 +++---- 2 files changed, 54 insertions(+), 15 deletions(-)
drivers/dma/dmaengine.c +49 -10
@@ -54,6 +54,7 @@#include <linux/rcupdate.h> #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/workqueue.h> #include "dmaengine.h"
@@ -61,6 +62,7 @@ static DEFINE_MUTEX(dma_list_mutex);static DEFINE_IDA (dma_ida);static LIST_HEAD (dma_device_list);static long dmaengine_ref_count; +static struct workqueue_struct *dmaengine_bh_wq;/* --- debugfs implementation --- */ #ifdef CONFIG_DEBUG_FS
@@ -1428,9 +1430,34 @@ static void dmaengine_destroy_unmap_pool(void) } } -static void dma_chan_bh_entry (struct tasklet_struct *tasklet) +static void dmaengine_destroy_bh_wq (void ) { -struct dma_chan *chan =from_tasklet (chan, tasklet, bh_tasklet); +if (!dmaengine_bh_wq) +return ; + +destroy_workqueue (dmaengine_bh_wq); + dmaengine_bh_wq =NULL ; +} + +static bool dmaengine_queue_bh_work (struct work_struct *work) +{ +if (WARN_ON (!dmaengine_bh_wq)) +return false; + +return queue_work (dmaengine_bh_wq, work); +} + +static void dmaengine_flush_bh_work (struct work_struct *work) +{ +if (!work) +return ; + +flush_work (work); +} + +static void dma_chan_bh_entry (struct work_struct *work) +{ + struct dma_chan *chan = container_of(work, struct dma_chan, bh_work);dmaengine_bh_work_fn fn =READ_ONCE (chan->bh_work_fn);if (fn)
@@ -1446,7 +1473,7 @@ void dmaengine_init_bh(struct dma_chan *chan, dmaengine_bh_work_fn fn)return ; chan->bh_work_fn = fn; -tasklet_setup (&chan->bh_tasklet, dma_chan_bh_entry); +INIT_WORK (&chan->bh_work, dma_chan_bh_entry); chan->bh_work_initialized = true; }EXPORT_SYMBOL_GPL (dmaengine_init_bh);
@@ -1456,8 +1483,7 @@ bool dmaengine_schedule_bh(struct dma_chan *chan)if (WARN_ON (!chan->bh_work_initialized))return false; -tasklet_schedule (&chan->bh_tasklet); -return true; +return dmaengine_queue_bh_work (&chan->bh_work); }EXPORT_SYMBOL_GPL (dmaengine_schedule_bh);
@@ -1466,7 +1492,7 @@ void dmaengine_kill_bh(struct dma_chan *chan)if (!chan->bh_work_initialized)return ; -tasklet_kill (&chan->bh_tasklet); +dmaengine_flush_bh_work (&chan->bh_work); }EXPORT_SYMBOL_GPL (dmaengine_kill_bh);
@@ -1666,15 +1692,28 @@ EXPORT_SYMBOL_GPL(dma_run_dependencies);static int __init dma_bus_init (void ) { -int err =dmaengine_init_unmap_pool (); +int err; + dmaengine_bh_wq =alloc_workqueue ("dmaengine_bh" , +WQ_BH |WQ_PERCPU ,0 ); +if (!dmaengine_bh_wq) +return -ENOMEM ; + + err =dmaengine_init_unmap_pool ();if (err) -return err; + goto err_destroy_wq; err =class_register (&dma_devclass); -if (!err) -dmaengine_debugfs_init (); +if (err) + goto err_destroy_pool; +dmaengine_debugfs_init (); +return 0 ; + +err_destroy_pool: +dmaengine_destroy_unmap_pool (); +err_destroy_wq: +dmaengine_destroy_bh_wq ();return err; }arch_initcall (dma_bus_init);
include/linux/dmaengine.h +5 -5
@@ -12,7 +12,7 @@#include <linux/scatterlist.h> #include <linux/bitmap.h> #include <linux/types.h> -#include <linux/interrupt.h> +#include <linux/workqueue.h> #include <asm/page.h> /**
@@ -339,9 +339,9 @@ struct dma_router {* @router: pointer to the DMA router structure * @route_data: channel specific data for the router * @private: private data for certain client-channel associations -* @bh_tasklet: bottom-half tasklet stored per-channel -* @bh_work_fn: callback executed when @bh_tasklet runs -* @bh_work_initialized: indicates whether @bh_tasklet has been initialized +* @bh_work: bottom-half work item stored per-channel +* @bh_work_fn: callback executed when @bh_work runs +* @bh_work_initialized: indicates whether @bh_work has been initialized */ struct dma_chan {struct dma_device *device;
@@ -367,7 +367,7 @@ struct dma_chan {void *route_data;void *private; -struct tasklet_struct bh_tasklet; +struct work_struct bh_work;dmaengine_bh_work_fn bh_work_fn;bool bh_work_initialized; };
Signature · 1 line
2.43.0
Vinod Koul
maintainerRe: [PATCH v3 02/34] dmaengine: back channel BH helpers with WQ_BH
Quoted 7 lines · Allen Pais
Replace the tasklet implementation of the channel BH helpers with a dedicated
WQ_BH|WQ_PERCPUworkqueue. The public dmaengine_*_bh() API and its softirq execution context remain unchanged.Keep the workqueue operations internal to dmaengine. Drain scheduled work in
dmaengine_kill_bh()to preserve the completion semantics oftasklet_kill().
Thanks Allen, this lgtm. I am asking for to test the series and report any issues. If all is good, I plan to pick this up in 3 weeks time after rc1.
Quoted 162 lines
Signed-off-by Allen Pais <[email protected]>--- drivers/dma/dmaengine.c | 59 ++++++++++++++++++++++++++++++++------- include/linux/dmaengine.h | 10 +++---- 2 files changed, 54 insertions(+), 15 deletions(-)drivers/dma/dmaengine.c +49
-10@@ -54,6 +54,7 @@#include <linux/rcupdate.h> #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/workqueue.h> #include "dmaengine.h" @@ -61,6 +62,7 @@ static DEFINE_MUTEX(dma_list_mutex);static DEFINE_IDA (dma_ida);static LIST_HEAD (dma_device_list);static long dmaengine_ref_count; +static struct workqueue_struct *dmaengine_bh_wq;/* --- debugfs implementation --- */ #ifdef CONFIG_DEBUG_FS @@ -1428,9 +1430,34 @@ static void dmaengine_destroy_unmap_pool(void) } } -static void dma_chan_bh_entry (struct tasklet_struct *tasklet) +static void dmaengine_destroy_bh_wq (void ) { -struct dma_chan *chan =from_tasklet (chan, tasklet, bh_tasklet); +if (!dmaengine_bh_wq) +return ; + +destroy_workqueue (dmaengine_bh_wq); + dmaengine_bh_wq =NULL ; +} + +static bool dmaengine_queue_bh_work (struct work_struct *work) +{ +if (WARN_ON (!dmaengine_bh_wq)) +return false; + +return queue_work (dmaengine_bh_wq, work); +} + +static void dmaengine_flush_bh_work (struct work_struct *work) +{ +if (!work) +return ; + +flush_work (work); +} + +static void dma_chan_bh_entry (struct work_struct *work) +{ + struct dma_chan *chan = container_of(work, struct dma_chan, bh_work);dmaengine_bh_work_fn fn =READ_ONCE (chan->bh_work_fn);if (fn)@@ -1446,7 +1473,7 @@ void dmaengine_init_bh(struct dma_chan *chan, dmaengine_bh_work_fn fn)return ; chan->bh_work_fn = fn; -tasklet_setup (&chan->bh_tasklet, dma_chan_bh_entry); +INIT_WORK (&chan->bh_work, dma_chan_bh_entry); chan->bh_work_initialized = true; }EXPORT_SYMBOL_GPL (dmaengine_init_bh);@@ -1456,8 +1483,7 @@ bool dmaengine_schedule_bh(struct dma_chan *chan)if (WARN_ON (!chan->bh_work_initialized))return false; -tasklet_schedule (&chan->bh_tasklet); -return true; +return dmaengine_queue_bh_work (&chan->bh_work); }EXPORT_SYMBOL_GPL (dmaengine_schedule_bh);@@ -1466,7 +1492,7 @@ void dmaengine_kill_bh(struct dma_chan *chan)if (!chan->bh_work_initialized)return ; -tasklet_kill (&chan->bh_tasklet); +dmaengine_flush_bh_work (&chan->bh_work); }EXPORT_SYMBOL_GPL (dmaengine_kill_bh);@@ -1666,15 +1692,28 @@ EXPORT_SYMBOL_GPL(dma_run_dependencies);static int __init dma_bus_init (void ) { -int err =dmaengine_init_unmap_pool (); +int err; + dmaengine_bh_wq =alloc_workqueue ("dmaengine_bh" , +WQ_BH |WQ_PERCPU ,0 ); +if (!dmaengine_bh_wq) +return -ENOMEM ; + + err =dmaengine_init_unmap_pool ();if (err) -return err; + goto err_destroy_wq; err =class_register (&dma_devclass); -if (!err) -dmaengine_debugfs_init (); +if (err) + goto err_destroy_pool; +dmaengine_debugfs_init (); +return 0 ; + +err_destroy_pool: +dmaengine_destroy_unmap_pool (); +err_destroy_wq: +dmaengine_destroy_bh_wq ();return err; }arch_initcall (dma_bus_init);include/linux/dmaengine.h +5
-5@@ -12,7 +12,7 @@#include <linux/scatterlist.h> #include <linux/bitmap.h> #include <linux/types.h> -#include <linux/interrupt.h> +#include <linux/workqueue.h> #include <asm/page.h> /** @@ -339,9 +339,9 @@ struct dma_router {* @router: pointer to the DMA router structure * @route_data: channel specific data for the router * @private: private data for certain client-channel associations -* @bh_tasklet: bottom-half tasklet stored per-channel -* @bh_work_fn: callback executed when @bh_tasklet runs -* @bh_work_initialized: indicates whether @bh_tasklet has been initialized +* @bh_work: bottom-half work item stored per-channel +* @bh_work_fn: callback executed when @bh_work runs +* @bh_work_initialized: indicates whether @bh_work has been initialized */ struct dma_chan {struct dma_device *device;@@ -367,7 +367,7 @@ struct dma_chan {void *route_data;void *private; -struct tasklet_struct bh_tasklet; +struct work_struct bh_work;dmaengine_bh_work_fn bh_work_fn;bool bh_work_initialized; };Signature · 1 line
2.43.0
Signature · 1 line
~Vinod
Re: [PATCH v3 02/34] dmaengine: back channel BH helpers with WQ_BH
In reply to Allen PaisQuoted 10 lines · Allen Pais
Replace the tasklet implementation of the channel BH helpers with a dedicated
WQ_BH|WQ_PERCPUworkqueue. The public dmaengine_*_bh() API and its softirq execution context remain unchanged.Keep the workqueue operations internal to dmaengine. Drain scheduled work in
dmaengine_kill_bh()to preserve the completion semantics oftasklet_kill().Signed-off-by Allen Pais <[email protected]>---
Quoted 160 lines
drivers/dma/dmaengine.c | 59 ++++++++++++++++++++++++++++++++------- include/linux/dmaengine.h | 10 +++---- 2 files changed, 54 insertions(+), 15 deletions(-)drivers/dma/dmaengine.c +49
-10@@ -54,6 +54,7 @@#include <linux/rcupdate.h> #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/workqueue.h> #include "dmaengine.h" @@ -61,6 +62,7 @@ static DEFINE_MUTEX(dma_list_mutex);static DEFINE_IDA (dma_ida);static LIST_HEAD (dma_device_list);static long dmaengine_ref_count; +static struct workqueue_struct *dmaengine_bh_wq;/* --- debugfs implementation --- */ #ifdef CONFIG_DEBUG_FS @@ -1428,9 +1430,34 @@ static void dmaengine_destroy_unmap_pool(void) } } -static void dma_chan_bh_entry (struct tasklet_struct *tasklet) +static void dmaengine_destroy_bh_wq (void ) { -struct dma_chan *chan =from_tasklet (chan, tasklet, bh_tasklet); +if (!dmaengine_bh_wq) +return ; + +destroy_workqueue (dmaengine_bh_wq); + dmaengine_bh_wq =NULL ; +} + +static bool dmaengine_queue_bh_work (struct work_struct *work) +{ +if (WARN_ON (!dmaengine_bh_wq)) +return false; + +return queue_work (dmaengine_bh_wq, work); +} + +static void dmaengine_flush_bh_work (struct work_struct *work) +{ +if (!work) +return ; + +flush_work (work); +} + +static void dma_chan_bh_entry (struct work_struct *work) +{ + struct dma_chan *chan = container_of(work, struct dma_chan, bh_work);dmaengine_bh_work_fn fn =READ_ONCE (chan->bh_work_fn);if (fn)@@ -1446,7 +1473,7 @@ void dmaengine_init_bh(struct dma_chan *chan, dmaengine_bh_work_fn fn)return ; chan->bh_work_fn = fn; -tasklet_setup (&chan->bh_tasklet, dma_chan_bh_entry); +INIT_WORK (&chan->bh_work, dma_chan_bh_entry); chan->bh_work_initialized = true; }EXPORT_SYMBOL_GPL (dmaengine_init_bh);@@ -1456,8 +1483,7 @@ bool dmaengine_schedule_bh(struct dma_chan *chan)if (WARN_ON (!chan->bh_work_initialized))return false; -tasklet_schedule (&chan->bh_tasklet); -return true; +return dmaengine_queue_bh_work (&chan->bh_work); }EXPORT_SYMBOL_GPL (dmaengine_schedule_bh);@@ -1466,7 +1492,7 @@ void dmaengine_kill_bh(struct dma_chan *chan)if (!chan->bh_work_initialized)return ; -tasklet_kill (&chan->bh_tasklet); +dmaengine_flush_bh_work (&chan->bh_work); }EXPORT_SYMBOL_GPL (dmaengine_kill_bh);@@ -1666,15 +1692,28 @@ EXPORT_SYMBOL_GPL(dma_run_dependencies);static int __init dma_bus_init (void ) { -int err =dmaengine_init_unmap_pool (); +int err; + dmaengine_bh_wq =alloc_workqueue ("dmaengine_bh" , +WQ_BH |WQ_PERCPU ,0 ); +if (!dmaengine_bh_wq) +return -ENOMEM ; + + err =dmaengine_init_unmap_pool ();if (err) -return err; + goto err_destroy_wq; err =class_register (&dma_devclass); -if (!err) -dmaengine_debugfs_init (); +if (err) + goto err_destroy_pool; +dmaengine_debugfs_init (); +return 0 ; + +err_destroy_pool: +dmaengine_destroy_unmap_pool (); +err_destroy_wq: +dmaengine_destroy_bh_wq ();return err; }arch_initcall (dma_bus_init);include/linux/dmaengine.h +5
-6@@ -12,7 +12,7 @@#include <linux/scatterlist.h> #include <linux/bitmap.h> #include <linux/types.h> -#include <linux/interrupt.h> +#include <linux/workqueue.h> #include <asm/page.h> /** @@ -339,9 +339,9 @@ struct dma_router {* @router: pointer to the DMA router structure * @route_data: channel specific data for the router * @private: private data for certain client-channel associations -* @bh_tasklet: bottom-half tasklet stored per-channel -* @bh_work_fn: callback executed when @bh_tasklet runs -* @bh_work_initialized: indicates whether @bh_tasklet has been initialized +* @bh_work: bottom-half work item stored per-channel +* @bh_work_fn: callback executed when @bh_work runs +* @bh_work_initialized: indicates whether @bh_work has been initialized */ struct dma_chan {struct dma_device *device;@@ -367,7 +367,7 @@ struct dma_chan {void *route_data;void *private; -struct tasklet_struct bh_tasklet; +struct work_struct bh_work;dmaengine_bh_work_fn bh_work_fn;bool bh_work_initialized; }; --2.43.0
PATCH v3 3/34 dmaengine: apple-admac: use dmaengine BH callback
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/apple-admac.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/dma/apple-admac.c +6 -10
@@ -89,7 +89,6 @@ struct admac_chan {unsigned int no;struct admac_data *host;struct dma_chan chan; -struct tasklet_struct tasklet;u32 carveout;
@@ -521,10 +520,7 @@ static int admac_terminate_all(struct dma_chan *chan)list_add_tail (&adchan->current_tx->node, &adchan->to_free); adchan->current_tx =NULL ; } -/* -* Descriptors can only be freed after the tasklet -* has been killed (in admac_synchronize). -*/ +/* Descriptors are released once the BH is flushed in admac_synchronize */ list_splice_tail_init (&adchan->submitted, &adchan->to_free);list_splice_tail_init (&adchan->issued, &adchan->to_free);spin_unlock_irqrestore (&adchan->lock, flags);
@@ -543,7 +539,7 @@ static void admac_synchronize(struct dma_chan *chan)list_splice_tail_init (&adchan->to_free, &head);spin_unlock_irqrestore (&adchan->lock, flags); -tasklet_kill (&adchan->tasklet); +dmaengine_kill_bh (&adchan->chan);list_for_each_entry_safe (adtx, _adtx, &head, node) {list_del (&adtx->node);
@@ -662,7 +658,7 @@ static void admac_handle_status_desc_done(struct admac_data *ad, int channo) tx->reclaimed_pos %=2 * tx->buf_len;admac_cyclic_write_desc (ad, channo, tx); -tasklet_schedule (&adchan->tasklet); +dmaengine_schedule_bh (&adchan->chan); }spin_unlock_irqrestore (&adchan->lock, flags); }
@@ -712,9 +708,9 @@ static irqreturn_t admac_interrupt(int irq, void *devid)return IRQ_HANDLED ; } -static void admac_chan_tasklet (struct tasklet_struct *t) +static void admac_chan_bh (struct dma_chan *chan) { -struct admac_chan *adchan =from_tasklet (adchan, t, tasklet); +struct admac_chan *adchan =to_admac_chan (chan);struct admac_tx *adtx;struct dmaengine_desc_callback cb;struct dmaengine_result tx_result;
@@ -886,7 +882,7 @@ static int admac_probe(struct platform_device *pdev)INIT_LIST_HEAD (&adchan->issued);INIT_LIST_HEAD (&adchan->to_free);list_add_tail (&adchan->chan.device_node, &dma->channels); -tasklet_setup (&adchan->tasklet, admac_chan_tasklet); +dmaengine_init_bh (&adchan->chan, admac_chan_bh); } err =reset_control_reset (ad->rstc);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 03/34] dmaengine: apple-admac: use dmaengine BH callback
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing cancellation of the bottom half (BH) work in the driver's remove path (admac_remove) can lead to Use-After-Free if the driver is unbound via sysfs while channels are in use. --
--- Patch [3]: [PATCH v3 03/34] dmaengine: apple-admac: use dmaengine BH callback --- commit 6eb12029fd22d727d6a26b7c59c7dfc98c07ffa3
Author: Allen Pais <[email protected]>
dmaengine: apple-admac: use dmaengine BH callback
This patch replaces the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/apple-admac.c +0
-0
[ ... ]
drivers/dma/apple-admac.c static int admac_probe(struct platform_device *pdev) · line 888
Quoted 9 lines
drivers/dma/apple-admac.c +1
-1@@ -886,7 +882,7 @@ static int admac_probe(struct platform_device *pdev)INIT_LIST_HEAD (&adchan->issued);INIT_LIST_HEAD (&adchan->to_free);list_add_tail (&adchan->chan.device_node, &dma->channels); -tasklet_setup (&adchan->tasklet, admac_chan_tasklet); +dmaengine_init_bh (&adchan->chan, admac_chan_bh); } err =reset_control_reset (ad->rstc);
[Severity: High]
This is a pre-existing issue, but should the teardown path in admac_remove() explicitly terminate active hardware channels and flush the asynchronous work items?
If the driver is unbound via sysfs while channels are in use, admac_remove() returns without stopping the hardware or killing the BH work:
drivers/dma/apple-admac.c:admac_remove() {
struct admac_data *ad = platform_get_drvdata(pdev);
of_dma_controller_free(pdev->dev.of_node);
dma_async_device_unregister(&ad->dma);
free_irq(ad->irq, ad);
reset_control_rearm(ad->rstc);
}The devres framework then automatically frees the admac_data memory which contains the bh_work struct.
If an interrupt fires immediately before free_irq(), it will schedule the BH work item via dmaengine_schedule_bh(). The workqueue would then execute admac_chan_bh() after the memory has been freed, potentially leading to a use-after-free.
Could a loop be added to call dmaengine_kill_bh() for each channel in admac_remove() before letting devres free the memory?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v3 03/34] dmaengine: apple-admac: use dmaengine BH callback
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 69 lines
drivers/dma/apple-admac.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)drivers/dma/apple-admac.c +6
-11@@ -89,7 +89,6 @@ struct admac_chan {unsigned int no;struct admac_data *host;struct dma_chan chan; -struct tasklet_struct tasklet;u32 carveout;@@ -521,10 +520,7 @@ static int admac_terminate_all(struct dma_chan *chan)list_add_tail (&adchan->current_tx->node, &adchan->to_free); adchan->current_tx =NULL ; } -/* -* Descriptors can only be freed after the tasklet -* has been killed (in admac_synchronize). -*/ +/* Descriptors are released once the BH is flushed in admac_synchronize */ list_splice_tail_init (&adchan->submitted, &adchan->to_free);list_splice_tail_init (&adchan->issued, &adchan->to_free);spin_unlock_irqrestore (&adchan->lock, flags);@@ -543,7 +539,7 @@ static void admac_synchronize(struct dma_chan *chan)list_splice_tail_init (&adchan->to_free, &head);spin_unlock_irqrestore (&adchan->lock, flags); -tasklet_kill (&adchan->tasklet); +dmaengine_kill_bh (&adchan->chan);list_for_each_entry_safe (adtx, _adtx, &head, node) {list_del (&adtx->node);@@ -662,7 +658,7 @@ static void admac_handle_status_desc_done(struct admac_data *ad, int channo) tx->reclaimed_pos %=2 * tx->buf_len;admac_cyclic_write_desc (ad, channo, tx); -tasklet_schedule (&adchan->tasklet); +dmaengine_schedule_bh (&adchan->chan); }spin_unlock_irqrestore (&adchan->lock, flags); }@@ -712,9 +708,9 @@ static irqreturn_t admac_interrupt(int irq, void *devid)return IRQ_HANDLED ; } -static void admac_chan_tasklet (struct tasklet_struct *t) +static void admac_chan_bh (struct dma_chan *chan) { -struct admac_chan *adchan =from_tasklet (adchan, t, tasklet); +struct admac_chan *adchan =to_admac_chan (chan);struct admac_tx *adtx;struct dmaengine_desc_callback cb;struct dmaengine_result tx_result;@@ -886,7 +882,7 @@ static int admac_probe(struct platform_device *pdev)INIT_LIST_HEAD (&adchan->issued);INIT_LIST_HEAD (&adchan->to_free);list_add_tail (&adchan->chan.device_node, &dma->channels); -tasklet_setup (&adchan->tasklet, admac_chan_tasklet); +dmaengine_init_bh (&adchan->chan, admac_chan_bh); } err =reset_control_reset (ad->rstc); --2.43.0
PATCH v3 4/34 dmaengine: at_xdmac: move irq bottom half to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/at_xdmac.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/dma/at_xdmac.c +6 -7
@@ -228,7 +228,6 @@ struct at_xdmac_chan {u32 save_cndc;u32 irq_status;unsigned long status; -struct tasklet_struct tasklet;struct dma_slave_config sconfig;spinlock_t lock;
@@ -1759,9 +1758,9 @@ static void at_xdmac_handle_error(struct at_xdmac_chan *atchan)/* Then continue with usual descriptor management */ } -static void at_xdmac_tasklet (struct tasklet_struct *t) +static void at_xdmac_tasklet (struct dma_chan *chan) { -struct at_xdmac_chan *atchan =from_tasklet (atchan, t, tasklet); +struct at_xdmac_chan *atchan =to_at_xdmac_chan (chan);struct at_xdmac *atxdmac =to_at_xdmac (atchan->chan.device);struct at_xdmac_desc *desc;struct dma_async_tx_descriptor *txd;
@@ -1865,7 +1864,7 @@ static irqreturn_t at_xdmac_interrupt(int irq, void *dev_id)if (atchan->irq_status & (AT_XDMAC_CIS_RBEIS |AT_XDMAC_CIS_WBEIS ))at_xdmac_write (atxdmac,AT_XDMAC_GD , atchan->mask); -tasklet_schedule (&atchan->tasklet); +dmaengine_schedule_bh (&atchan->chan); ret =IRQ_HANDLED ; }
@@ -2317,7 +2316,7 @@ static int at_xdmac_probe(struct platform_device *pdev)return PTR_ERR (atxdmac->clk); } -/* Do not use dev res to prevent races with tasklet */ +/* Do not use devm resources to prevent races with the BH worker */ ret =request_irq (atxdmac->irq, at_xdmac_interrupt,0 ,"at_xdmac" , atxdmac);if (ret) {dev_err (&pdev->dev,"can't request irq\n" );
@@ -2397,7 +2396,7 @@ static int at_xdmac_probe(struct platform_device *pdev)spin_lock_init (&atchan->lock);INIT_LIST_HEAD (&atchan->xfers_list);INIT_LIST_HEAD (&atchan->free_descs_list); -tasklet_setup (&atchan->tasklet, at_xdmac_tasklet); +dmaengine_init_bh (&atchan->chan, at_xdmac_tasklet);/* Clear pending interrupts. */ while (at_xdmac_chan_read (atchan,AT_XDMAC_CIS ))
@@ -2458,7 +2457,7 @@ static void at_xdmac_remove(struct platform_device *pdev)for (i =0 ; i < atxdmac->dma.chancnt; i++) {struct at_xdmac_chan *atchan = &atxdmac->chan[i]; -tasklet_kill (&atchan->tasklet); +dmaengine_kill_bh (&atchan->chan);at_xdmac_free_chan_resources (&atchan->chan); } }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 04/34] dmaengine: at_xdmac: move irq bottom half to dmaengine BH
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
Pre-existing issues:
- [High] Hard lockup due to premature IRQ registration before software initialization and clock enablement.
- [High] Out-of-bounds access due to lack of BH synchronization and missing empty-list validation in at_xdmac_tasklet.
- [High] Out-of-bounds memory access on empty transfer list in at_xdmac_tx_status().
- [High] Contract violation allowing Use-After-Free due to missing .device_synchronize callback.
- [High] Hardware access fault in at_xdmac_remove() due to invalid teardown order.
- [High] Sleeping PM runtime calls executed while holding an atomic spinlock.
- [High] Use-after-free and memory leak in at_xdmac_remove() due to skipped cleanup loop.
--
--- Patch [4]: [PATCH v3 04/34] dmaengine: at_xdmac: move irq bottom half to dmaengine BH --- commit 2d0fd6f4bc8cb0e5708fc858f4f33ecff4ef0fc8
Author: Allen Pais <[email protected]>
dmaengine: at_xdmac: move irq bottom half to dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 6 lines
drivers/dma/at_xdmac.c +0
-0@@ -1759,9 +1758,9 @@ static void at_xdmac_handle_error(struct at_xdmac_chan *atchan)/* Then continue with usual descriptor management */
drivers/dma/at_xdmac.c static void at_xdmac_handle_error(struct at_xdmac_chan *atchan) · line 1766
Quoted 10 lines
drivers/dma/at_xdmac.c +2
-2} -static void at_xdmac_tasklet (struct tasklet_struct *t) +static void at_xdmac_tasklet (struct dma_chan *chan) { -struct at_xdmac_chan *atchan =from_tasklet (atchan, t, tasklet); +struct at_xdmac_chan *atchan =to_at_xdmac_chan (chan);struct at_xdmac *atxdmac =to_at_xdmac (atchan->chan.device);struct at_xdmac_desc *desc;struct dma_async_tx_descriptor *txd;
[Severity: High]
This is a pre-existing issue, but can this lead to an out-of-bounds access if the transfer list is empty?
If at_xdmac_device_terminate_all() is called, it removes all pending transfers from atchan->xfers_list but does not synchronize with or cancel a pending BH worker. If a hardware interrupt schedules the BH just before termination, at_xdmac_tasklet() will run concurrently or immediately after terminate_all().
The BH unconditionally invokes list_first_entry() without a list_empty() check:
desc = list_first_entry(&atchan->xfers_list, struct at_xdmac_desc,
xfer_node);
if (!desc->active_xfer) {
Since the list was emptied, would this return a bogus pointer and corrupt memory when accessed?
[Severity: High]
This is also a pre-existing issue, but does at_xdmac_tx_status() have a similar out-of-bounds memory access risk on an empty transfer list?
When at_xdmac_tx_status() is called, it checks if the cookie status is DMA_IN_PROGRESS. If a client terminates all transfers and then checks the status of a pending cookie, at_xdmac_tx_status() traverses the empty list without a list_empty() check:
desc = list_first_entry(&atchan->xfers_list, struct at_xdmac_desc, xfer_node); if (!desc->active_xfer) {
Would this also result in a bogus pointer dereference?
[Severity: High]
This is a pre-existing issue, but can this code sleep while holding an atomic spinlock?
Functions like at_xdmac_tasklet() and at_xdmac_issue_pending() acquire the atomic spinlock atchan->lock using spin_lock_irqsave(). While holding this lock, they call into execution paths like at_xdmac_advance_work() and at_xdmac_start_xfer() that eventually invoke pm_runtime_resume_and_get():
spin_lock_irqsave(&atchan->lock, flags);at_xdmac_advance_work(atchan);spin_unlock_irqrestore(&atchan->lock, flags);
Since the device is configured with autosuspend and does not use pm_runtime_irq_safe(), couldn't this PM runtime call sleep when attempting to resume the device, violating atomic context rules and risking deadlocks?
drivers/dma/at_xdmac.c static int at_xdmac_probe(struct platform_device *pdev) · line 2320
Quoted 8 lines
[ ... ]
drivers/dma/at_xdmac.c +1
-1@@ -2317,7 +2316,7 @@ static int at_xdmac_probe(struct platform_device *pdev)return PTR_ERR (atxdmac->clk); } -/* Do not use dev res to prevent races with tasklet */ +/* Do not use devm resources to prevent races with the BH worker */ ret =request_irq (atxdmac->irq, at_xdmac_interrupt,0 ,"at_xdmac" , atxdmac);
[Severity: High]
This isn't a bug introduced by this patch, but could this lead to a hard lockup due to premature IRQ registration before software initialization and clock enablement?
If an interrupt is asserted right after request_irq() is called in at_xdmac_probe(), the interrupt handler at_xdmac_interrupt() will execute while the hardware clock is still disabled.
Additionally, atxdmac->dma.chancnt is initialized much later in dma_async_device_register(). Because it evaluates to 0, the handler's internal processing loop is completely skipped:
for (i = 0; i < atxdmac->dma.chancnt; i++) {
if (!((1 << i) & pending))
continue;This means the device interrupt is never acknowledged or cleared. Would this result in the ISR spinning infinitely in its "while (pending);" loop, locking up the CPU?
drivers/dma/at_xdmac.c static int at_xdmac_probe(struct platform_device *pdev) · line 2402
Quoted 10 lines
[ ... ]
drivers/dma/at_xdmac.c +1
-1@@ -2397,7 +2396,7 @@ static int at_xdmac_probe(struct platform_device *pdev)spin_lock_init (&atchan->lock);INIT_LIST_HEAD (&atchan->xfers_list);INIT_LIST_HEAD (&atchan->free_descs_list); -tasklet_setup (&atchan->tasklet, at_xdmac_tasklet); +dmaengine_init_bh (&atchan->chan, at_xdmac_tasklet);/* Clear pending interrupts. */ while (at_xdmac_chan_read (atchan,AT_XDMAC_CIS ))
[Severity: High]
This is a pre-existing issue, but does this violate the dmaengine contract allowing a use-after-free due to a missing .device_synchronize callback?
According to the dmaengine core rules, any driver utilizing asynchronous contexts for callbacks (like BH workers) must implement the .device_synchronize API. at_xdmac does not provide this callback when registering the DMA device callbacks.
Consequently, dmaengine_synchronize() acts as a no-op. Could clients free memory buffers associated with a DMA completion while the BH worker is still accessing them or hasn't finished running?
drivers/dma/at_xdmac.c static void at_xdmac_remove(struct platform_device *pdev) · line 2463
Quoted 10 lines
[ ... ]
drivers/dma/at_xdmac.c +1
-1@@ -2458,7 +2457,7 @@ static void at_xdmac_remove(struct platform_device *pdev)for (i =0 ; i < atxdmac->dma.chancnt; i++) {struct at_xdmac_chan *atchan = &atxdmac->chan[i]; -tasklet_kill (&atchan->tasklet); +dmaengine_kill_bh (&atchan->chan);at_xdmac_free_chan_resources (&atchan->chan); } }
[Severity: High]
This is a pre-existing issue, but could this cause a hardware access fault in at_xdmac_remove() due to an invalid teardown order?
In at_xdmac_remove(), the driver calls clk_disable_unprepare(atxdmac->clk) before calling free_irq(). If a spurious interrupt fires or if the ISR is currently running on another CPU, it will attempt to access device registers after the clock has been turned off. Might this cause the system to hang or trigger a synchronous external abort?
[Severity: High]
This is also a pre-existing issue, but does this cause a use-after-free and memory leak because the cleanup loop is skipped?
In at_xdmac_remove(), dma_async_device_unregister() is called before this channel cleanup loop. dma_async_device_unregister() internally decrements atxdmac->dma.chancnt to 0.
Consequently, the loop condition (i < atxdmac->dma.chancnt) evaluates to false immediately, and the loop is skipped entirely. This prevents dmaengine_kill_bh() and at_xdmac_free_chan_resources() from executing.
If a BH worker is scheduled, could it run after the device memory is freed by devres, leading to a use-after-free while also leaking all pre-allocated descriptors?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v3 04/34] dmaengine: at_xdmac: move irq bottom half to dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 66 lines
drivers/dma/at_xdmac.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)drivers/dma/at_xdmac.c +6
-8@@ -228,7 +228,6 @@ struct at_xdmac_chan {u32 save_cndc;u32 irq_status;unsigned long status; -struct tasklet_struct tasklet;struct dma_slave_config sconfig;spinlock_t lock;@@ -1759,9 +1758,9 @@ static void at_xdmac_handle_error(struct at_xdmac_chan *atchan)/* Then continue with usual descriptor management */ } -static void at_xdmac_tasklet (struct tasklet_struct *t) +static void at_xdmac_tasklet (struct dma_chan *chan) { -struct at_xdmac_chan *atchan =from_tasklet (atchan, t, tasklet); +struct at_xdmac_chan *atchan =to_at_xdmac_chan (chan);struct at_xdmac *atxdmac =to_at_xdmac (atchan->chan.device);struct at_xdmac_desc *desc;struct dma_async_tx_descriptor *txd;@@ -1865,7 +1864,7 @@ static irqreturn_t at_xdmac_interrupt(int irq, void *dev_id)if (atchan->irq_status & (AT_XDMAC_CIS_RBEIS |AT_XDMAC_CIS_WBEIS ))at_xdmac_write (atxdmac,AT_XDMAC_GD , atchan->mask); -tasklet_schedule (&atchan->tasklet); +dmaengine_schedule_bh (&atchan->chan); ret =IRQ_HANDLED ; }@@ -2317,7 +2316,7 @@ static int at_xdmac_probe(struct platform_device *pdev)return PTR_ERR (atxdmac->clk); } -/* Do not use dev res to prevent races with tasklet */ +/* Do not use devm resources to prevent races with the BH worker */ ret =request_irq (atxdmac->irq, at_xdmac_interrupt,0 ,"at_xdmac" , atxdmac);if (ret) {dev_err (&pdev->dev,"can't request irq\n" );@@ -2397,7 +2396,7 @@ static int at_xdmac_probe(struct platform_device *pdev)spin_lock_init (&atchan->lock);INIT_LIST_HEAD (&atchan->xfers_list);INIT_LIST_HEAD (&atchan->free_descs_list); -tasklet_setup (&atchan->tasklet, at_xdmac_tasklet); +dmaengine_init_bh (&atchan->chan, at_xdmac_tasklet);/* Clear pending interrupts. */ while (at_xdmac_chan_read (atchan,AT_XDMAC_CIS ))@@ -2458,7 +2457,7 @@ static void at_xdmac_remove(struct platform_device *pdev)for (i =0 ; i < atxdmac->dma.chancnt; i++) {struct at_xdmac_chan *atchan = &atxdmac->chan[i]; -tasklet_kill (&atchan->tasklet); +dmaengine_kill_bh (&atchan->chan);at_xdmac_free_chan_resources (&atchan->chan); } } --2.43.0
PATCH v3 5/34 dmaengine: ep93xx: hook callbacks via dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/ep93xx_dma.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/dma/ep93xx_dma.c +5 -7
@@ -167,7 +167,6 @@ struct ep93xx_dma_chan_cfg {* @dma_cfg: channel number, direction * @irq: interrupt number of the channel * @clk: clock used by this channel -* @tasklet: channel specific tasklet used for callbacks * @lock: lock protecting the fields following * @flags: flags for the channel * @buffer: which buffer to use next (0/1)
@@ -196,7 +195,6 @@ struct ep93xx_dma_chan {struct ep93xx_dma_chan_cfg dma_cfg;int irq;struct clk *clk; -struct tasklet_struct tasklet;/* protects the fields following */ spinlock_t lock;unsigned long flags;
@@ -801,9 +799,9 @@ static void ep93xx_dma_advance_work(struct ep93xx_dma_chan *edmac)spin_unlock_irqrestore (&edmac->lock, flags); } -static void ep93xx_dma_tasklet (struct tasklet_struct *t) +static void ep93xx_dma_tasklet (struct dma_chan *chan) { -struct ep93xx_dma_chan *edmac =from_tasklet (edmac, t, tasklet); +struct ep93xx_dma_chan *edmac =to_ep93xx_dma_chan (chan);struct ep93xx_dma_desc *desc, *d;struct dmaengine_desc_callback cb;LIST_HEAD (list);
@@ -858,12 +856,12 @@ static irqreturn_t ep93xx_dma_interrupt(int irq, void *dev_id)switch (edmac->edma->hw_interrupt (edmac)) {case INTERRUPT_DONE : desc->complete = true; -tasklet_schedule (&edmac->tasklet); +dmaengine_schedule_bh (&edmac->chan);break ;case INTERRUPT_NEXT_BUFFER :if (test_bit (EP93XX_DMA_IS_CYCLIC , &edmac->flags)) -tasklet_schedule (&edmac->tasklet); +dmaengine_schedule_bh (&edmac->chan);break ;default :
@@ -1420,7 +1418,7 @@ static struct ep93xx_dma_engine *ep93xx_dma_of_probe(struct platform_device *pdeINIT_LIST_HEAD (&edmac->active);INIT_LIST_HEAD (&edmac->queue);INIT_LIST_HEAD (&edmac->free_list); -tasklet_setup (&edmac->tasklet, ep93xx_dma_tasklet); +dmaengine_init_bh (&edmac->chan, ep93xx_dma_tasklet);list_add_tail (&edmac->chan.device_node, &dma_dev->channels);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 05/34] dmaengine: ep93xx: hook callbacks via dmaengine BH
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing dmaengine_kill_bh() causes use-after-free and premature callback invocation --
--- Patch [5]: [PATCH v3 05/34] dmaengine: ep93xx: hook callbacks via dmaengine BH --- commit 3ccb9d1bebba979771c31fb7e0c5d8c45b92dd9c
Author: Allen Pais <[email protected]> Date: Mon Aug 10 18:09:06 2026 +0000
dmaengine: ep93xx: hook callbacks via dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/ep93xx_dma.c +0
-0
[ ... ]
drivers/dma/ep93xx_dma.c static struct ep93xx_dma_engine *ep93xx_dma_of_probe(struct platform_device *pde · line 1422
Quoted 6 lines
drivers/dma/ep93xx_dma.c +1
-1@@ -1421,7 +1419,7 @@ static struct ep93xx_dma_engine *ep93xx_dma_of_probe(struct platform_device *pdeINIT_LIST_HEAD (&edmac->active);INIT_LIST_HEAD (&edmac->queue);INIT_LIST_HEAD (&edmac->free_list); -tasklet_setup (&edmac->tasklet, ep93xx_dma_tasklet); +dmaengine_init_bh (&edmac->chan, ep93xx_dma_tasklet);
[Severity: High]
This is a pre-existing issue, but should we be terminating the bottom-half work during synchronization or resource cleanup?
If an interrupt fires and schedules the bottom-half work, but the client calls dmaengine_terminate_all() and dma_release_channel() before the work can execute, a new client could request the channel and submit a new descriptor.
When the delayed bottom-half finally runs, could it access the new client's descriptor from edmac->active and prematurely invoke its callback?
Also, if the driver is unbound via sysfs, devm_kzalloc frees the channel memory. If the bottom-half is still scheduled, would this result in a use-after-free?
It looks like we are missing a call to dmaengine_kill_bh() (and previously tasklet_kill()) in ep93xx_dma_synchronize() or ep93xx_dma_free_chan_resources():
drivers/dma/ep93xx_dma.c:ep93xx_dma_synchronize() {
...
if (edmac->edma->hw_synchronize)
edmac->edma->hw_synchronize(edmac);
...
}drivers/dma/ep93xx_dma.c:ep93xx_dma_free_chan_resources() {
...
clk_disable_unprepare(edmac->clk);
free_irq(edmac->irq, edmac);
...
}Quoted 3 lines
drivers/dma/ep93xx_dma.c +0
-0list_add_tail (&edmac->chan.device_node, &dma_dev->channels);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v3 05/34] dmaengine: ep93xx: hook callbacks via dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 62 lines
drivers/dma/ep93xx_dma.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/dma/ep93xx_dma.c +5
-8@@ -167,7 +167,6 @@ struct ep93xx_dma_chan_cfg {* @dma_cfg: channel number, direction * @irq: interrupt number of the channel * @clk: clock used by this channel -* @tasklet: channel specific tasklet used for callbacks * @lock: lock protecting the fields following * @flags: flags for the channel * @buffer: which buffer to use next (0/1) @@ -196,7 +195,6 @@ struct ep93xx_dma_chan {struct ep93xx_dma_chan_cfg dma_cfg;int irq;struct clk *clk; -struct tasklet_struct tasklet;/* protects the fields following */ spinlock_t lock;unsigned long flags;@@ -801,9 +799,9 @@ static void ep93xx_dma_advance_work(struct ep93xx_dma_chan *edmac)spin_unlock_irqrestore (&edmac->lock, flags); } -static void ep93xx_dma_tasklet (struct tasklet_struct *t) +static void ep93xx_dma_tasklet (struct dma_chan *chan) { -struct ep93xx_dma_chan *edmac =from_tasklet (edmac, t, tasklet); +struct ep93xx_dma_chan *edmac =to_ep93xx_dma_chan (chan);struct ep93xx_dma_desc *desc, *d;struct dmaengine_desc_callback cb;LIST_HEAD (list);@@ -858,12 +856,12 @@ static irqreturn_t ep93xx_dma_interrupt(int irq, void *dev_id)switch (edmac->edma->hw_interrupt (edmac)) {case INTERRUPT_DONE : desc->complete = true; -tasklet_schedule (&edmac->tasklet); +dmaengine_schedule_bh (&edmac->chan);break ;case INTERRUPT_NEXT_BUFFER :if (test_bit (EP93XX_DMA_IS_CYCLIC , &edmac->flags)) -tasklet_schedule (&edmac->tasklet); +dmaengine_schedule_bh (&edmac->chan);break ;default :@@ -1420,7 +1418,7 @@ static struct ep93xx_dma_engine *ep93xx_dma_of_probe(struct platform_device *pdeINIT_LIST_HEAD (&edmac->active);INIT_LIST_HEAD (&edmac->queue);INIT_LIST_HEAD (&edmac->free_list); -tasklet_setup (&edmac->tasklet, ep93xx_dma_tasklet); +dmaengine_init_bh (&edmac->chan, ep93xx_dma_tasklet);list_add_tail (&edmac->chan.device_node, &dma_dev->channels); --2.43.0
PATCH v3 6/34 dmaengine: fsldma: migrate tasklet to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/fsldma.c | 10 +++++----- drivers/dma/fsldma.h | 1 - 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/dma/fsldma.c +5 -5
@@ -968,18 +968,18 @@ static irqreturn_t fsldma_chan_irq(int irq, void *data)chan_err (chan,"irq: unhandled sr 0x%08x\n" , stat);/* -* Schedule the tasklet to handle all cleanup of the current +* Queue the BH worker to handle all cleanup of the current * transaction. It will start a new transaction if there is * one pending. */ -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common);chan_dbg (chan,"irq: Exit\n" );return IRQ_HANDLED ; } -static void dma_do_tasklet (struct tasklet_struct *t) +static void dma_do_tasklet (struct dma_chan *c) { -struct fsldma_chan *chan =from_tasklet (chan, t, tasklet); +struct fsldma_chan *chan =to_fsl_chan (c);chan_dbg (chan,"tasklet entry\n" );
@@ -1152,7 +1152,7 @@ static int fsl_dma_chan_probe(struct fsldma_device *fdev, } fdev->chan[chan->id] = chan; -tasklet_setup (&chan->tasklet, dma_do_tasklet); +dmaengine_init_bh (&chan->common, dma_do_tasklet);snprintf (chan->name,sizeof (chan->name),"chan%d" , chan->id);/* Initialize the channel */
drivers/dma/fsldma.h +0 -1
@@ -173,7 +173,6 @@ struct fsldma_chan {struct device *dev;/* Channel device */ int irq;/* Channel IRQ */ int id;/* Raw id of this channel */ -struct tasklet_struct tasklet;u32 feature;bool idle;/* DMA controller is idle */ #ifdef CONFIG_PM
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 06/34] dmaengine: fsldma: migrate tasklet to dmaengine BH
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing cancellation of the bottom-half work in the channel removal and error paths leads to a use-after-free.
- [High] The driver invokes client DMA completion callbacks and dependent transactions while holding the channel lock, which causes a recursive deadlock. --
--- Patch [6]: [PATCH v3 06/34] dmaengine: fsldma: migrate tasklet to dmaengine BH --- commit 9529606b1e089f3e7222105fc2792fecf8bf406b
Author: Allen Pais <[email protected]>
dmaengine: fsldma: migrate tasklet to dmaengine BH
This commit replaces the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/fsldma.c +0
-0
[ ... ]
Quoted 1 line
drivers/dma/fsldma.c +0
-0@@ -968,18 +968,18 @@ static irqreturn_t fsldma_chan_irq(int irq, void *data)
[ ... ]
drivers/dma/fsldma.c static irqreturn_t fsldma_chan_irq(int irq, void *data) · line 984
Quoted 7 lines
drivers/dma/fsldma.c +2
-2-static void dma_do_tasklet (struct tasklet_struct *t) +static void dma_do_tasklet (struct dma_chan *c) { -struct fsldma_chan *chan =from_tasklet (chan, t, tasklet); +struct fsldma_chan *chan =to_fsl_chan (c);chan_dbg (chan,"tasklet entry\n" );
[Severity: High]
This is a pre-existing issue, but since dma_do_tasklet invokes client callbacks, is there a risk of a recursive spinlock deadlock?
Looking at dma_do_tasklet(), it acquires the channel descriptor lock and then triggers cleanup:
dma_do_tasklet() {
spin_lock(&chan->desc_lock);
fsldma_cleanup_descriptors(chan);
...Inside the cleanup routine, it calls fsldma_run_tx_complete_actions(), which runs the client callback and dependencies with the lock still held:
fsldma_run_tx_complete_actions() {
...
dmaengine_desc_get_callback_invoke(txd, NULL);
dma_run_dependencies(txd);
}If a client callback or a dependent transaction attempts to submit a new transfer to the same channel, it will try to acquire the same lock:
fsl_dma_tx_submit() {
spin_lock_bh(&chan->desc_lock);
...Could this cause the subsystem to freeze when clients submit new transactions from their completion callbacks?
[ ... ]
drivers/dma/fsldma.c static int fsl_dma_chan_probe(struct fsldma_device *fdev, · line 1156
Quoted 7 lines
drivers/dma/fsldma.c +1
-1@@ -1152,7 +1152,7 @@ static int fsl_dma_chan_probe(struct fsldma_device *fdev, } fdev->chan[chan->id] = chan; -tasklet_setup (&chan->tasklet, dma_do_tasklet); +dmaengine_init_bh (&chan->common, dma_do_tasklet);snprintf (chan->name,sizeof (chan->name),"chan%d" , chan->id);
[Severity: High]
This isn't a bug introduced by this patch, but missing teardown logic might lead to a use-after-free during driver removal or probe errors.
The original code lacked a call to kill the tasklet, and the new code similarly omits a call to shut down the bottom half work.
If an interrupt fires right before the channel is freed, the bottom half could be scheduled and remain on the workqueue:
fsl_dma_chan_remove() {
...
kfree(chan);
}When the workqueue eventually processes the queued bottom half, it will dereference the freed channel structure:
dma_do_tasklet() {
...
spin_lock(&chan->desc_lock);Should we add a call to dmaengine_kill_bh(&chan->common) before freeing the channel structure to ensure the asynchronous work is safely flushed?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH v3 06/34] dmaengine: fsldma: migrate tasklet to dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 55 lines
drivers/dma/fsldma.c | 10 +++++----- drivers/dma/fsldma.h | 1 - 2 files changed, 5 insertions(+), 6 deletions(-)drivers/dma/fsldma.c +5
-5@@ -968,18 +968,18 @@ static irqreturn_t fsldma_chan_irq(int irq, void *data)chan_err (chan,"irq: unhandled sr 0x%08x\n" , stat);/* -* Schedule the tasklet to handle all cleanup of the current +* Queue the BH worker to handle all cleanup of the current * transaction. It will start a new transaction if there is * one pending. */ -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common);chan_dbg (chan,"irq: Exit\n" );return IRQ_HANDLED ; } -static void dma_do_tasklet (struct tasklet_struct *t) +static void dma_do_tasklet (struct dma_chan *c) { -struct fsldma_chan *chan =from_tasklet (chan, t, tasklet); +struct fsldma_chan *chan =to_fsl_chan (c);chan_dbg (chan,"tasklet entry\n" );@@ -1152,7 +1152,7 @@ static int fsl_dma_chan_probe(struct fsldma_device *fdev, } fdev->chan[chan->id] = chan; -tasklet_setup (&chan->tasklet, dma_do_tasklet); +dmaengine_init_bh (&chan->common, dma_do_tasklet);snprintf (chan->name,sizeof (chan->name),"chan%d" , chan->id);/* Initialize the channel */ drivers/dma/fsldma.h +0
-2@@ -173,7 +173,6 @@ struct fsldma_chan {struct device *dev;/* Channel device */ int irq;/* Channel IRQ */ int id;/* Raw id of this channel */ -struct tasklet_struct tasklet;u32 feature;bool idle;/* DMA controller is idle */ #ifdef CONFIG_PM --2.43.0
PATCH v3 7/34 dmaengine: fsl_raid: run completions via dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/fsl_raid.c | 11 ++++++----- drivers/dma/fsl_raid.h | 1 - 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/dma/fsl_raid.c +6 -5
@@ -155,9 +155,10 @@ static void fsl_re_cleanup_descs(struct fsl_re_chan *re_chan)fsl_re_issue_pending (&re_chan->chan); } -static void fsl_re_dequeue (struct tasklet_struct *t) +static void fsl_re_dequeue (struct dma_chan *chan) { -struct fsl_re_chan *re_chan =from_tasklet (re_chan, t, irqtask); + struct fsl_re_chan *re_chan = container_of(chan, struct fsl_re_chan, + chan);struct fsl_re_desc *desc, *_desc;struct fsl_re_hw_desc *hwdesc;unsigned long flags;
@@ -224,7 +225,7 @@ static irqreturn_t fsl_re_isr(int irq, void *data)/* Clear interrupt */ out_be32 (&re_chan->jrregs->jr_interrupt_status,FSL_RE_CLR_INTR ); -tasklet_schedule (&re_chan->irqtask); +dmaengine_schedule_bh (&re_chan->chan);return IRQ_HANDLED ; }
@@ -670,7 +671,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,snprintf (chan->name,sizeof (chan->name),"re_jr%02d" , q); chandev = &chan_ofdev->dev; -tasklet_setup (&chan->irqtask, fsl_re_dequeue); +dmaengine_init_bh (&chan->chan, fsl_re_dequeue); ret =request_irq (chan->irq, fsl_re_isr,0 , chan->name, chandev);if (ret) {
@@ -846,7 +847,7 @@ static int fsl_re_probe(struct platform_device *ofdev)static void fsl_re_remove_chan (struct fsl_re_chan *chan) { -tasklet_kill (&chan->irqtask); +dmaengine_kill_bh (&chan->chan);dma_pool_free (chan->re_dev->hw_desc_pool, chan->inb_ring_virt_addr, chan->inb_phys_addr);
drivers/dma/fsl_raid.h +0 -1
@@ -275,7 +275,6 @@ struct fsl_re_chan {struct dma_chan chan;struct fsl_re_chan_cfg *jrregs;int irq; -struct tasklet_struct irqtask;u32 alloc_count;/* hw descriptor ring for inbound queue*/
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 07/34] dmaengine: fsl_raid: run completions via dmaengine BH
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver requests an IRQ using request_irq() but never frees it on module unload or error paths, leading to a resource leak and potential Use-After-Free.
- [High] The IRQ handler is registered before the channel's critical state (locks, lists, and driver private data) is initialized, creating a race window for early interrupts.
- [High] Probe error handling in fsl_re_probe() ignores failures from fsl_re_chan_probe(), leaving partial state that causes NULL pointer dereferences and double-frees during device removal.
- [High] Channels are torn down and their memory pools freed before the DMA device is unregistered, creating a race window for use-after-free.
- [High] The RAID hardware engine is not explicitly stopped during channel removal, resulting in DMA continuing into freed memory.
- [High] The driver holds the internal channel spinlock (desc_lock) while synchronously invoking the client's DMA completion callback, leading to a potential AA deadlock. --
--- Patch [7]: [PATCH v3 07/34] dmaengine: fsl_raid: run completions via dmaengine BH --- commit 12282b5227658b803a18693207b1136ab132efae
Author: Allen Pais <[email protected]>
dmaengine: fsl_raid: run completions via dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 5 lines
drivers/dma/fsl_raid.c +0
-0
drivers/dma/fsl_raid.c static void fsl_re_cleanup_descs(struct fsl_re_chan *re_chan) · line 161
Quoted 9 lines
drivers/dma/fsl_raid.c +3
-2@@ -155,9 +155,10 @@ static void fsl_re_cleanup_descs(struct fsl_re_chan *re_chan)fsl_re_issue_pending (&re_chan->chan); } -static void fsl_re_dequeue (struct tasklet_struct *t) +static void fsl_re_dequeue (struct dma_chan *chan) { -struct fsl_re_chan *re_chan =from_tasklet (re_chan, t, irqtask); + struct fsl_re_chan *re_chan = container_of(chan, struct fsl_re_chan, + chan);
[Severity: High]
This isn't a bug introduced by this patch, but I spotted a potential deadlock in the completion path.
When fsl_re_dequeue() is running, it acquires the channel's desc_lock:
fsl_re_dequeue() {
...
spin_lock_irqsave(&re_chan->desc_lock, flags);
...
if (found) {
fsl_re_desc_done(desc);
...It then calls fsl_re_desc_done(desc), which invokes the client callback.
If the client calls dma_async_issue_pending() from within that callback, fsl_re_issue_pending() will try to acquire the exact same spinlock:
fsl_re_issue_pending() {
...
spin_lock_irqsave(&re_chan->desc_lock, flags);
...
}Could this sequence trigger an AA deadlock?
[ ... ]
drivers/dma/fsl_raid.c static int fsl_re_chan_probe(struct platform_device *ofdev, · line 677
Quoted 9 lines
drivers/dma/fsl_raid.c +1
-1@@ -670,7 +671,7 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,snprintf (chan->name,sizeof (chan->name),"re_jr%02d" , q); chandev = &chan_ofdev->dev; -tasklet_setup (&chan->irqtask, fsl_re_dequeue); +dmaengine_init_bh (&chan->chan, fsl_re_dequeue); ret =request_irq (chan->irq, fsl_re_isr,0 , chan->name, chandev);if (ret) {
[Severity: High]
This is a pre-existing issue, but I noticed the driver requests an IRQ using request_irq(), but it appears there's no matching free_irq() call on the module unload or error paths.
If the module is unbound, will the IRQ handler remain registered and potentially dereference a freed chan pointer when it fires?
[Severity: High]
This is also a pre-existing issue, but I noticed the IRQ handler is registered here before the channel's critical state (locks, lists, and driver private data) is fully initialized.
If an interrupt fires immediately after request_irq() completes:
fsl_re_isr() {
re_chan = dev_get_drvdata((struct device *)data);
irqstate = in_be32(&re_chan->jrregs->jr_interrupt_status);
}Could this result in a NULL pointer dereference since dev_set_drvdata() hasn't been called yet?
[ ... ]
drivers/dma/fsl_raid.c static int fsl_re_probe(struct platform_device *ofdev) · line 853
Quoted 9 lines
drivers/dma/fsl_raid.c +1
-1@@ -846,7 +847,7 @@ static int fsl_re_probe(struct platform_device *ofdev)static void fsl_re_remove_chan (struct fsl_re_chan *chan) { -tasklet_kill (&chan->irqtask); +dmaengine_kill_bh (&chan->chan);dma_pool_free (chan->re_dev->hw_desc_pool, chan->inb_ring_virt_addr, chan->inb_phys_addr);
[Severity: High]
This is a pre-existing issue, but fsl_re_remove_chan() frees the hardware descriptor rings without explicitly stopping the RAID hardware engine first.
Is there a risk that the hardware continues executing pending transactions into memory that has already been returned to the pool, potentially causing memory corruption?
Should we write a disable command to the jr_command register before freeing the rings?
[Severity: High]
Another pre-existing issue, but fsl_re_probe() doesn't check the return value of fsl_re_chan_probe():
fsl_re_probe() {
...
fsl_re_chan_probe(ofdev, child, ridx++, off);
re_priv->total_chans++;
...
}If fsl_re_chan_probe() fails, the channel state remains partially initialized. During module removal, fsl_re_remove() iterates up to total_chans:
fsl_re_remove() {
...
for (i = 0; i < re_priv->total_chans; i++)
fsl_re_remove_chan(re_priv->re_jrs[i]);
...
}Could this lead to double-frees or NULL pointer dereferences when fsl_re_remove_chan() operates on these failed channels?
[Severity: High]
Finally, this is a pre-existing issue, but I noticed channels are completely torn down before the DMA device is unregistered in fsl_re_remove():
fsl_re_remove() {
...
for (i = 0; i < re_priv->total_chans; i++)
fsl_re_remove_chan(re_priv->re_jrs[i]);
dma_async_device_unregister(&re_priv->dma_dev);
...
}Could the dmaengine core or clients still attempt to submit transfers to channels that are actively being destroyed? Should dma_async_device_unregister() happen before the resources are torn down?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v3 8/34 dmaengine: imx-dma: flip per-chan tasklet to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/imx-dma.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/dma/imx-dma.c +13 -13
@@ -145,7 +145,6 @@ struct imxdma_channel {struct imxdma_engine *imxdma;unsigned int channel; -struct tasklet_struct dma_tasklet;struct list_head ld_free;struct list_head ld_queue;struct list_head ld_active;
@@ -344,8 +343,8 @@ static void imxdma_watchdog(struct timer_list *t)imx_dmav1_writel (imxdma,0 ,DMA_CCR (channel)); -/* Tasklet watchdog error handler */ -tasklet_schedule (&imxdmac->dma_tasklet); +/* BH watchdog error handler */ +dmaengine_schedule_bh (&imxdmac->chan);dev_dbg (imxdma->dev,"channel %d: watchdog timeout!\n" , imxdmac->channel); }
@@ -390,8 +389,8 @@ static irqreturn_t imxdma_err_handler(int irq, void *dev_id)imx_dmav1_writel (imxdma,1 << i,DMA_DBOSR ); errcode |=IMX_DMA_ERR_BUFFER ; } -/* Tasklet error handler */ -tasklet_schedule (&imxdma->channel[i].dma_tasklet); +/* BH error handler */ +dmaengine_schedule_bh (&imxdma->channel[i].chan); dev_warn(imxdma->dev, "DMA timeout on channel %d -%s%s%s%s\n", i,
@@ -448,8 +447,8 @@ static void dma_irq_handle_channel(struct imxdma_channel *imxdmac)imx_dmav1_writel (imxdma, tmp,DMA_CCR (chno));if (imxdma_chan_is_doing_cyclic (imxdmac)) -/* Tasklet progression */ -tasklet_schedule (&imxdmac->dma_tasklet); +/* BH progression */ +dmaengine_schedule_bh (&imxdmac->chan);return ; }
@@ -462,8 +461,8 @@ static void dma_irq_handle_channel(struct imxdma_channel *imxdmac) out:imx_dmav1_writel (imxdma,0 ,DMA_CCR (chno)); -/* Tasklet irq */ -tasklet_schedule (&imxdmac->dma_tasklet); +/* Schedule the IRQ BH */ +dmaengine_schedule_bh (&imxdmac->chan); }static irqreturn_t dma_irq_handler (int irq,void *dev_id)
@@ -592,9 +591,10 @@ static int imxdma_xfer_desc(struct imxdma_desc *d)return 0 ; } -static void imxdma_tasklet (struct tasklet_struct *t) +static void imxdma_tasklet (struct dma_chan *chan) { -struct imxdma_channel *imxdmac =from_tasklet (imxdmac, t, dma_tasklet); + struct imxdma_channel *imxdmac = container_of(chan, struct imxdma_channel, + chan);struct imxdma_engine *imxdma = imxdmac->imxdma;struct imxdma_desc *desc, *next_desc;unsigned long flags;
@@ -1142,7 +1142,7 @@ static int __init imxdma_probe(struct platform_device *pdev)INIT_LIST_HEAD (&imxdmac->ld_free);INIT_LIST_HEAD (&imxdmac->ld_active); -tasklet_setup (&imxdmac->dma_tasklet, imxdma_tasklet); +dmaengine_init_bh (&imxdmac->chan, imxdma_tasklet); imxdmac->chan.device = &imxdma->dma_device;dma_cookie_init (&imxdmac->chan); imxdmac->channel = i;
@@ -1211,7 +1211,7 @@ static void imxdma_free_irq(struct platform_device *pdev, struct imxdma_engine *if (!is_imx1_dma (imxdma))disable_irq (imxdmac->irq); -tasklet_kill (&imxdmac->dma_tasklet); +dmaengine_kill_bh (&imxdmac->chan); } }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 08/34] dmaengine: imx-dma: flip per-chan tasklet to dmaengine BH
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] The watchdog timer is not safely canceled during teardown or error paths, leading to Use-After-Free.
- [High] Completed descriptors are moved to the free list before callback invocation, allowing lockless data races.
- [High] Bottom-half work is not flushed before freeing channel descriptors, leading to Use-After-Free.
- [High] IRQ is requested before initializing channel data structures and masking interrupts, leading to a NULL pointer dereference. --
--- Patch [8]: [PATCH v3 08/34] dmaengine: imx-dma: flip per-chan tasklet to dmaengine BH --- commit a54288aab8aa66cb0228a7320efe5075981ac5ce
Author: Allen Pais <[email protected]>
dmaengine: imx-dma: flip per-chan tasklet to dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/imx-dma.c +0
-0
[ ... ]
drivers/dma/imx-dma.c static int imxdma_xfer_desc(struct imxdma_desc *d) · line 600
Quoted 13 lines
drivers/dma/imx-dma.c +3
-2@@ -592,9 +591,10 @@ static int imxdma_xfer_desc(struct imxdma_desc *d)return 0 ; } -static void imxdma_tasklet (struct tasklet_struct *t) +static void imxdma_tasklet (struct dma_chan *chan) { -struct imxdma_channel *imxdmac =from_tasklet (imxdmac, t, dma_tasklet); + struct imxdma_channel *imxdmac = container_of(chan, struct imxdma_channel, + chan);struct imxdma_engine *imxdma = imxdmac->imxdma;struct imxdma_desc *desc, *next_desc;unsigned long flags;
[Severity: High]
This isn't a bug introduced by this patch, but could this lockless data race cause a loss of completion callbacks?
In imxdma_tasklet(), the completed descriptor is placed on the ld_free list before the channel lock is dropped and the callback is invoked:
imxdma_tasklet()
list_move_tail(imxdmac->ld_active.next, &imxdmac->ld_free);
spin_unlock_irqrestore(&imxdma->lock, flags);
dmaengine_desc_get_callback_invoke(&desc->desc, NULL);If another thread calls imxdma_prep_dma_memcpy() concurrently, it locklessly inspects ld_free. If ld_free was empty, it might immediately pick up this newly freed descriptor and overwrite its fields (desc->desc.callback = NULL) before imxdma_tasklet() invokes the callback.
Does this need to hold the descriptor off the free list until after the callback completes?
[ ... ]
drivers/dma/imx-dma.c static int __init imxdma_probe(struct platform_device *pdev) · line 1148
Quoted 9 lines
drivers/dma/imx-dma.c +1
-1@@ -1142,7 +1142,7 @@ static int __init imxdma_probe(struct platform_device *pdev)INIT_LIST_HEAD (&imxdmac->ld_free);INIT_LIST_HEAD (&imxdmac->ld_active); -tasklet_setup (&imxdmac->dma_tasklet, imxdma_tasklet); +dmaengine_init_bh (&imxdmac->chan, imxdma_tasklet); imxdmac->chan.device = &imxdma->dma_device;dma_cookie_init (&imxdmac->chan); imxdmac->channel = i;
[Severity: High]
This is a pre-existing issue, but does the interrupt handler get registered too early in imxdma_probe()?
For IMX1 DMA, devm_request_irq() is called before the interrupt mask register (DMA_DIMR) is disabled and before channel list heads like ld_active are initialized.
If an interrupt is pending or asserts immediately, dma_irq_handler() runs and calls dma_irq_handle_channel(). This evaluates list_empty() on uninitialized memory, incorrectly returning false, and then dereferences an invalid pointer from list_first_entry(), causing a crash.
Should the IRQ registration be moved after the hardware masking and list initializations?
[ ... ]
drivers/dma/imx-dma.c static void imxdma_free_irq(struct platform_device *pdev, struct imxdma_engine * · line 1216
Quoted 8 lines
drivers/dma/imx-dma.c +1
-1@@ -1211,7 +1211,7 @@ static void imxdma_free_irq(struct platform_device *pdev, struct imxdma_engine *if (!is_imx1_dma (imxdma))disable_irq (imxdmac->irq); -tasklet_kill (&imxdmac->dma_tasklet); +dmaengine_kill_bh (&imxdmac->chan); } }
[Severity: High]
This isn't a bug introduced by this patch, but could this lead to a use-after-free with the watchdog timer?
In imxdma_free_irq(), the dmaengine BH is killed, but the imxdmac->watchdog timer is never safely canceled. When devm frees the imxdma structure, a still-active timer could fire, executing imxdma_watchdog(). This would dereference freed memory to call dmaengine_schedule_bh().
Similarly in imxdma_probe(), if devm_request_irq() fails for a later channel, the error path jumps to disable_dma_ahb_clk and omits timer cleanup for already initialized channels.
Does this require timer_shutdown_sync() during teardown and error paths?
[Severity: High]
This isn't a bug introduced by this patch, but could descriptors be freed while the bottom-half work is still running?
When a channel is released, imxdma_free_chan_resources() iterates through ld_free and frees the descriptors with kfree(). However, the driver does not implement device_synchronize, and imxdma_free_chan_resources() does not flush pending bottom-half work.
If imxdma_tasklet() is executing concurrently, imxdma_free_chan_resources() could acquire the lock, splice the lists, and free the descriptor just as the tasklet drops the spinlock to invoke the callback. The bottom-half would then dereference the freed desc->desc to invoke the callback.
Does imxdma_free_chan_resources() need to flush pending BH work before freeing descriptors?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH v3 08/34] dmaengine: imx-dma: flip per-chan tasklet to dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 93 lines
drivers/dma/imx-dma.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)drivers/dma/imx-dma.c +13
-14@@ -145,7 +145,6 @@ struct imxdma_channel {struct imxdma_engine *imxdma;unsigned int channel; -struct tasklet_struct dma_tasklet;struct list_head ld_free;struct list_head ld_queue;struct list_head ld_active;@@ -344,8 +343,8 @@ static void imxdma_watchdog(struct timer_list *t)imx_dmav1_writel (imxdma,0 ,DMA_CCR (channel)); -/* Tasklet watchdog error handler */ -tasklet_schedule (&imxdmac->dma_tasklet); +/* BH watchdog error handler */ +dmaengine_schedule_bh (&imxdmac->chan);dev_dbg (imxdma->dev,"channel %d: watchdog timeout!\n" , imxdmac->channel); }@@ -390,8 +389,8 @@ static irqreturn_t imxdma_err_handler(int irq, void *dev_id)imx_dmav1_writel (imxdma,1 << i,DMA_DBOSR ); errcode |=IMX_DMA_ERR_BUFFER ; } -/* Tasklet error handler */ -tasklet_schedule (&imxdma->channel[i].dma_tasklet); +/* BH error handler */ +dmaengine_schedule_bh (&imxdma->channel[i].chan); dev_warn(imxdma->dev, "DMA timeout on channel %d -%s%s%s%s\n", i,@@ -448,8 +447,8 @@ static void dma_irq_handle_channel(struct imxdma_channel *imxdmac)imx_dmav1_writel (imxdma, tmp,DMA_CCR (chno));if (imxdma_chan_is_doing_cyclic (imxdmac)) -/* Tasklet progression */ -tasklet_schedule (&imxdmac->dma_tasklet); +/* BH progression */ +dmaengine_schedule_bh (&imxdmac->chan);return ; }@@ -462,8 +461,8 @@ static void dma_irq_handle_channel(struct imxdma_channel *imxdmac) out:imx_dmav1_writel (imxdma,0 ,DMA_CCR (chno)); -/* Tasklet irq */ -tasklet_schedule (&imxdmac->dma_tasklet); +/* Schedule the IRQ BH */ +dmaengine_schedule_bh (&imxdmac->chan); }static irqreturn_t dma_irq_handler (int irq,void *dev_id)@@ -592,9 +591,10 @@ static int imxdma_xfer_desc(struct imxdma_desc *d)return 0 ; } -static void imxdma_tasklet (struct tasklet_struct *t) +static void imxdma_tasklet (struct dma_chan *chan) { -struct imxdma_channel *imxdmac =from_tasklet (imxdmac, t, dma_tasklet); + struct imxdma_channel *imxdmac = container_of(chan, struct imxdma_channel, + chan);struct imxdma_engine *imxdma = imxdmac->imxdma;struct imxdma_desc *desc, *next_desc;unsigned long flags;@@ -1142,7 +1142,7 @@ static int __init imxdma_probe(struct platform_device *pdev)INIT_LIST_HEAD (&imxdmac->ld_free);INIT_LIST_HEAD (&imxdmac->ld_active); -tasklet_setup (&imxdmac->dma_tasklet, imxdma_tasklet); +dmaengine_init_bh (&imxdmac->chan, imxdma_tasklet); imxdmac->chan.device = &imxdma->dma_device;dma_cookie_init (&imxdmac->chan); imxdmac->channel = i;@@ -1211,7 +1211,7 @@ static void imxdma_free_irq(struct platform_device *pdev, struct imxdma_engine *if (!is_imx1_dma (imxdma))disable_irq (imxdmac->irq); -tasklet_kill (&imxdmac->dma_tasklet); +dmaengine_kill_bh (&imxdmac->chan); } } --2.43.0
Re: [PATCH v3 08/34] dmaengine: imx-dma: flip per-chan tasklet to dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 93 lines
drivers/dma/imx-dma.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)drivers/dma/imx-dma.c +13
-14@@ -145,7 +145,6 @@ struct imxdma_channel {struct imxdma_engine *imxdma;unsigned int channel; -struct tasklet_struct dma_tasklet;struct list_head ld_free;struct list_head ld_queue;struct list_head ld_active;@@ -344,8 +343,8 @@ static void imxdma_watchdog(struct timer_list *t)imx_dmav1_writel (imxdma,0 ,DMA_CCR (channel)); -/* Tasklet watchdog error handler */ -tasklet_schedule (&imxdmac->dma_tasklet); +/* BH watchdog error handler */ +dmaengine_schedule_bh (&imxdmac->chan);dev_dbg (imxdma->dev,"channel %d: watchdog timeout!\n" , imxdmac->channel); }@@ -390,8 +389,8 @@ static irqreturn_t imxdma_err_handler(int irq, void *dev_id)imx_dmav1_writel (imxdma,1 << i,DMA_DBOSR ); errcode |=IMX_DMA_ERR_BUFFER ; } -/* Tasklet error handler */ -tasklet_schedule (&imxdma->channel[i].dma_tasklet); +/* BH error handler */ +dmaengine_schedule_bh (&imxdma->channel[i].chan); dev_warn(imxdma->dev, "DMA timeout on channel %d -%s%s%s%s\n", i,@@ -448,8 +447,8 @@ static void dma_irq_handle_channel(struct imxdma_channel *imxdmac)imx_dmav1_writel (imxdma, tmp,DMA_CCR (chno));if (imxdma_chan_is_doing_cyclic (imxdmac)) -/* Tasklet progression */ -tasklet_schedule (&imxdmac->dma_tasklet); +/* BH progression */ +dmaengine_schedule_bh (&imxdmac->chan);return ; }@@ -462,8 +461,8 @@ static void dma_irq_handle_channel(struct imxdma_channel *imxdmac) out:imx_dmav1_writel (imxdma,0 ,DMA_CCR (chno)); -/* Tasklet irq */ -tasklet_schedule (&imxdmac->dma_tasklet); +/* Schedule the IRQ BH */ +dmaengine_schedule_bh (&imxdmac->chan); }static irqreturn_t dma_irq_handler (int irq,void *dev_id)@@ -592,9 +591,10 @@ static int imxdma_xfer_desc(struct imxdma_desc *d)return 0 ; } -static void imxdma_tasklet (struct tasklet_struct *t) +static void imxdma_tasklet (struct dma_chan *chan) { -struct imxdma_channel *imxdmac =from_tasklet (imxdmac, t, dma_tasklet); + struct imxdma_channel *imxdmac = container_of(chan, struct imxdma_channel, + chan);struct imxdma_engine *imxdma = imxdmac->imxdma;struct imxdma_desc *desc, *next_desc;unsigned long flags;@@ -1142,7 +1142,7 @@ static int __init imxdma_probe(struct platform_device *pdev)INIT_LIST_HEAD (&imxdmac->ld_free);INIT_LIST_HEAD (&imxdmac->ld_active); -tasklet_setup (&imxdmac->dma_tasklet, imxdma_tasklet); +dmaengine_init_bh (&imxdmac->chan, imxdma_tasklet); imxdmac->chan.device = &imxdma->dma_device;dma_cookie_init (&imxdmac->chan); imxdmac->channel = i;@@ -1211,7 +1211,7 @@ static void imxdma_free_irq(struct platform_device *pdev, struct imxdma_engine *if (!is_imx1_dma (imxdma))disable_irq (imxdmac->irq); -tasklet_kill (&imxdmac->dma_tasklet); +dmaengine_kill_bh (&imxdmac->chan); } } --2.43.0
PATCH v3 9/34 dmaengine: ioat: convert cleanup tasklet to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/ioat/dma.c | 14 +++++++------- drivers/dma/ioat/dma.h | 3 +-- drivers/dma/ioat/init.c | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-)
drivers/dma/ioat/dma.c +7 -7
@@ -110,7 +110,7 @@ irqreturn_t ioat_dma_do_interrupt(int irq, void *data)for_each_set_bit (bit, &attnstatus,BITS_PER_LONG ) { ioat_chan =ioat_chan_by_index (instance, bit);if (test_bit (IOAT_RUN , &ioat_chan->state)) -tasklet_schedule (&ioat_chan->cleanup_task); +dmaengine_schedule_bh (&ioat_chan->dma_chan); }writeb (intrctrl, instance->reg_base +IOAT_INTRCTRL_OFFSET );
@@ -127,7 +127,7 @@ irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)struct ioatdma_chan *ioat_chan = data;if (test_bit (IOAT_RUN , &ioat_chan->state)) -tasklet_schedule (&ioat_chan->cleanup_task); +dmaengine_schedule_bh (&ioat_chan->dma_chan);return IRQ_HANDLED ; }
@@ -161,11 +161,11 @@ void ioat_stop(struct ioatdma_chan *ioat_chan)/* flush inflight timers */ timer_delete_sync (&ioat_chan->timer); -/* flush inflight tasklet runs */ -tasklet_kill (&ioat_chan->cleanup_task); +/* flush inflight BH runs */ +dmaengine_kill_bh (&ioat_chan->dma_chan);/* final cleanup now that everything is quiesced and can't re-arm */ -ioat_cleanup_event (&ioat_chan->cleanup_task); +ioat_cleanup_event (&ioat_chan->dma_chan); }static void __ioat_issue_pending (struct ioatdma_chan *ioat_chan)
@@ -690,9 +690,9 @@ static void ioat_cleanup(struct ioatdma_chan *ioat_chan)spin_unlock_bh (&ioat_chan->cleanup_lock); } -void ioat_cleanup_event (struct tasklet_struct *t) +void ioat_cleanup_event (struct dma_chan *c) { -struct ioatdma_chan *ioat_chan =from_tasklet (ioat_chan, t, cleanup_task); +struct ioatdma_chan *ioat_chan =to_ioat_chan (c);ioat_cleanup (ioat_chan);if (!test_bit (IOAT_RUN , &ioat_chan->state))
drivers/dma/ioat/dma.h +1 -2
@@ -111,7 +111,6 @@ struct ioatdma_chan {struct ioatdma_device *ioat_dma;dma_addr_t completion_dma;u64 *completion; -struct tasklet_struct cleanup_task;struct kobject kobj;/* ioat v2 / v3 channel attributes
@@ -385,7 +384,7 @@ int ioat_reset_hw(struct ioatdma_chan *ioat_chan);enum dma_status ioat_tx_status (struct dma_chan *c,dma_cookie_t cookie,struct dma_tx_state *txstate); -void ioat_cleanup_event (struct tasklet_struct *t); +void ioat_cleanup_event (struct dma_chan *c);void ioat_timer_event (struct timer_list *t);int ioat_check_space_lock (struct ioatdma_chan *ioat_chan,int num_descs);void ioat_issue_pending (struct dma_chan *chan);
drivers/dma/ioat/init.c +1 -1
@@ -765,7 +765,7 @@ ioat_init_channel(struct ioatdma_device *ioat_dma,list_add_tail (&ioat_chan->dma_chan.device_node, &dma->channels); ioat_dma->idx[idx] = ioat_chan;timer_setup (&ioat_chan->timer, ioat_timer_event,0 ); -tasklet_setup (&ioat_chan->cleanup_task, ioat_cleanup_event); +dmaengine_init_bh (&ioat_chan->dma_chan, ioat_cleanup_event); }#define IOAT_NUM_SRC_TEST 6/* must be <= 8 */
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 09/34] dmaengine: ioat: convert cleanup tasklet to dmaengine BH
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The channel timer can be inadvertently re-armed during the teardown sequence in ioat_stop(), leading to a use-after-free when the timer fires after the channel resources are freed. --
--- Patch [9]: [PATCH v3 09/34] dmaengine: ioat: convert cleanup tasklet to dmaengine BH --- commit a9e2b8b1c21fd37939157d4bfd1e3ccc9c58d182
Author: Allen Pais <[email protected]>
dmaengine: ioat: convert cleanup tasklet to dmaengine BH
This commit replaces the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 3 lines
drivers/dma/ioat/dma.c +0
-0
[ ... ]
drivers/dma/ioat/dma.c void ioat_stop(struct ioatdma_chan *ioat_chan) · line 168
Quoted 12 lines
drivers/dma/ioat/dma.c +3
-3@@ -161,11 +161,11 @@ void ioat_stop(struct ioatdma_chan *ioat_chan)/* flush inflight timers */ timer_delete_sync (&ioat_chan->timer); -/* flush inflight tasklet runs */ -tasklet_kill (&ioat_chan->cleanup_task); +/* flush inflight BH runs */ +dmaengine_kill_bh (&ioat_chan->dma_chan);/* final cleanup now that everything is quiesced and can't re-arm */ -ioat_cleanup_event (&ioat_chan->cleanup_task); +ioat_cleanup_event (&ioat_chan->dma_chan);
[Severity: High]
This is a pre-existing issue, but can this teardown sequence result in a use-after-free by inadvertently re-arming the timer?
In ioat_stop(), we use timer_delete_sync() to stop the timer. However, we then manually call ioat_cleanup_event(), which eventually reaches ioat_cleanup_preamble(). If there are hardware completions pending, it will unconditionally re-arm the timer:
ioat_stop()
ioat_cleanup_event()
ioat_cleanup()
ioat_cleanup_preamble() {
...
clear_bit(IOAT_COMPLETION_ACK, &ioat_chan->state);
mod_timer(&ioat_chan->timer, jiffies + COMPLETION_TIMEOUT);
...
}Since timer_delete_sync() doesn't permanently prevent re-arming, the timer could be re-armed here right before the device is torn down and ioat_chan is freed.
Should this code use timer_shutdown_sync() instead to permanently deactivate the timer and prevent mod_timer() from succeeding during this final cleanup phase?
Quoted 1 line
drivers/dma/ioat/dma.c +0
-0}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Re: [PATCH v3 09/34] dmaengine: ioat: convert cleanup tasklet to dmaengine BH
In reply to Allen PaisQuoted 7 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>Acked-by Dave Jiang <[email protected]>---
Quoted 91 lines
drivers/dma/ioat/dma.c | 14 +++++++------- drivers/dma/ioat/dma.h | 3 +-- drivers/dma/ioat/init.c | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-)drivers/dma/ioat/dma.c +7
-7@@ -110,7 +110,7 @@ irqreturn_t ioat_dma_do_interrupt(int irq, void *data)for_each_set_bit (bit, &attnstatus,BITS_PER_LONG ) { ioat_chan =ioat_chan_by_index (instance, bit);if (test_bit (IOAT_RUN , &ioat_chan->state)) -tasklet_schedule (&ioat_chan->cleanup_task); +dmaengine_schedule_bh (&ioat_chan->dma_chan); }writeb (intrctrl, instance->reg_base +IOAT_INTRCTRL_OFFSET );@@ -127,7 +127,7 @@ irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)struct ioatdma_chan *ioat_chan = data;if (test_bit (IOAT_RUN , &ioat_chan->state)) -tasklet_schedule (&ioat_chan->cleanup_task); +dmaengine_schedule_bh (&ioat_chan->dma_chan);return IRQ_HANDLED ; }@@ -161,11 +161,11 @@ void ioat_stop(struct ioatdma_chan *ioat_chan)/* flush inflight timers */ timer_delete_sync (&ioat_chan->timer); -/* flush inflight tasklet runs */ -tasklet_kill (&ioat_chan->cleanup_task); +/* flush inflight BH runs */ +dmaengine_kill_bh (&ioat_chan->dma_chan);/* final cleanup now that everything is quiesced and can't re-arm */ -ioat_cleanup_event (&ioat_chan->cleanup_task); +ioat_cleanup_event (&ioat_chan->dma_chan); }static void __ioat_issue_pending (struct ioatdma_chan *ioat_chan)@@ -690,9 +690,9 @@ static void ioat_cleanup(struct ioatdma_chan *ioat_chan)spin_unlock_bh (&ioat_chan->cleanup_lock); } -void ioat_cleanup_event (struct tasklet_struct *t) +void ioat_cleanup_event (struct dma_chan *c) { -struct ioatdma_chan *ioat_chan =from_tasklet (ioat_chan, t, cleanup_task); +struct ioatdma_chan *ioat_chan =to_ioat_chan (c);ioat_cleanup (ioat_chan);if (!test_bit (IOAT_RUN , &ioat_chan->state))drivers/dma/ioat/dma.h +1
-2@@ -111,7 +111,6 @@ struct ioatdma_chan {struct ioatdma_device *ioat_dma;dma_addr_t completion_dma;u64 *completion; -struct tasklet_struct cleanup_task;struct kobject kobj;/* ioat v2 / v3 channel attributes @@ -385,7 +384,7 @@ int ioat_reset_hw(struct ioatdma_chan *ioat_chan);enum dma_status ioat_tx_status (struct dma_chan *c,dma_cookie_t cookie,struct dma_tx_state *txstate); -void ioat_cleanup_event (struct tasklet_struct *t); +void ioat_cleanup_event (struct dma_chan *c);void ioat_timer_event (struct timer_list *t);int ioat_check_space_lock (struct ioatdma_chan *ioat_chan,int num_descs);void ioat_issue_pending (struct dma_chan *chan);drivers/dma/ioat/init.c +1
-2@@ -765,7 +765,7 @@ ioat_init_channel(struct ioatdma_device *ioat_dma,list_add_tail (&ioat_chan->dma_chan.device_node, &dma->channels); ioat_dma->idx[idx] = ioat_chan;timer_setup (&ioat_chan->timer, ioat_timer_event,0 ); -tasklet_setup (&ioat_chan->cleanup_task, ioat_cleanup_event); +dmaengine_init_bh (&ioat_chan->dma_chan, ioat_cleanup_event); }#define IOAT_NUM_SRC_TEST 6/* must be <= 8 */ --2.43.0
PATCH v3 10/34 dmaengine: mmp_pdma: replace per-chan tasklet with dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/mmp_pdma.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/dma/mmp_pdma.c +5 -8
@@ -116,7 +116,6 @@ struct mmp_pdma_chan {* is in cyclic mode */ /* channel's basic info */ -struct tasklet_struct tasklet;u32 dcmd;u32 drcmr;u32 dev_addr;
@@ -374,7 +373,7 @@ static irqreturn_t mmp_pdma_chan_handler(int irq, void *dev_id)if (clear_chan_irq (phy) !=0 )return IRQ_NONE ; -tasklet_schedule (&phy->vchan->tasklet); +dmaengine_schedule_bh (&phy->vchan->chan);return IRQ_HANDLED ; }
@@ -1047,13 +1046,11 @@ static void mmp_pdma_issue_pending(struct dma_chan *dchan) }/* -* dma_do_tasklet -* Do call back -* Start pending list +* dma_do_tasklet - BH worker to process completions and kick pending work */ -static void dma_do_tasklet (struct tasklet_struct *t) +static void dma_do_tasklet (struct dma_chan *c) { -struct mmp_pdma_chan *chan =from_tasklet (chan, t, tasklet); + struct mmp_pdma_chan *chan = container_of(c, struct mmp_pdma_chan, chan);struct mmp_pdma_desc_sw *desc, *_desc;LIST_HEAD (chain_cleanup);unsigned long flags;
@@ -1170,7 +1167,7 @@ static int mmp_pdma_chan_init(struct mmp_pdma_device *pdev, int idx, int irq)spin_lock_init (&chan->desc_lock); chan->dev = pdev->dev; chan->chan.device = &pdev->device; -tasklet_setup (&chan->tasklet, dma_do_tasklet); +dmaengine_init_bh (&chan->chan, dma_do_tasklet);INIT_LIST_HEAD (&chan->chain_pending);INIT_LIST_HEAD (&chan->chain_running);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 10/34] dmaengine: mmp_pdma: replace per-chan tasklet with dmaengine BH
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver fails to flush or kill the dmaengine BH work item during channel teardown or module removal, leading to a potential use-after-free.
- [High] The interrupt handler mmp_pdma_chan_handler unconditionally dereferences phy->vchan, which can be NULL, leading to a kernel panic. --
--- Patch [10]: [PATCH v3 10/34] dmaengine: mmp_pdma: replace per-chan tasklet with dmaengine BH --- commit 8e2fd9bba919782b8255f7948fa3a9fec6c35960
Author: Allen Pais <[email protected]>
dmaengine: mmp_pdma: replace per-chan tasklet with dmaengine BH
This commit replaces the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/mmp_pdma.c +0
-0
[ ... ]
drivers/dma/mmp_pdma.c static irqreturn_t mmp_pdma_chan_handler(int irq, void *dev_id) · line 376
Quoted 6 lines
drivers/dma/mmp_pdma.c +1
-1@@ -374,7 +373,7 @@ static irqreturn_t mmp_pdma_chan_handler(int irq, void *dev_id)if (clear_chan_irq (phy) !=0 )return IRQ_NONE ; -tasklet_schedule (&phy->vchan->tasklet); +dmaengine_schedule_bh (&phy->vchan->chan);
[Severity: High]
This is a pre-existing issue, but could this lead to a NULL pointer dereference if a concurrent teardown happens?
The mmp_pdma_chan_handler() is executed in interrupt context. If the client driver terminates a transfer via dmaengine_terminate_all() concurrently with an interrupt firing for that channel, mmp_pdma_free_phy() will set phy->vchan = NULL without an accompanying synchronize_irq().
The handler then blindly dereferences phy->vchan when calling dmaengine_schedule_bh(). Interestingly, clear_chan_irq() explicitly checks if phy->vchan is NULL just above this, which suggests the state is structurally possible during interrupts.
Quoted 2 lines
drivers/dma/mmp_pdma.c +0
-0return IRQ_HANDLED ; }
[ ... ]
drivers/dma/mmp_pdma.c static int mmp_pdma_chan_init(struct mmp_pdma_device *pdev, int idx, int irq) · line 1170
Quoted 6 lines
drivers/dma/mmp_pdma.c +1
-1@@ -1170,7 +1167,7 @@ static int mmp_pdma_chan_init(struct mmp_pdma_device *pdev, int idx, int irq)spin_lock_init (&chan->desc_lock); chan->dev = pdev->dev; chan->chan.device = &pdev->device; -tasklet_setup (&chan->tasklet, dma_do_tasklet); +dmaengine_init_bh (&chan->chan, dma_do_tasklet);
[Severity: High]
This is a pre-existing issue, but does the driver ever flush or kill the pending work item before freeing resources?
During channel teardown or module removal, the driver doesn't seem to cancel the pending BH work. If a DMA operation completes right before or during mmp_pdma_free_chan_resources() or mmp_pdma_remove(), the work item might be scheduled on the dmaengine_bh_wq.
The cleanup code destroys chan->desc_pool in mmp_pdma_free_chan_resources() or frees the chan memory via devres without first calling dmaengine_kill_bh(). When the scheduled BH later executes in dma_do_tasklet(), it could access the destroyed pool or freed chan structure:
drivers/dma/mmp_pdma.c:dma_do_tasklet() {
...
dma_pool_free(chan->desc_pool, desc, txd->phys);
...
}Should there be a call to dmaengine_kill_bh() on the teardown paths?
Quoted 3 lines
drivers/dma/mmp_pdma.c +0
-0INIT_LIST_HEAD (&chan->chain_pending);INIT_LIST_HEAD (&chan->chain_running);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [PATCH v3 10/34] dmaengine: mmp_pdma: replace per-chan tasklet with dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 53 lines
drivers/dma/mmp_pdma.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)drivers/dma/mmp_pdma.c +5
-9@@ -116,7 +116,6 @@ struct mmp_pdma_chan {* is in cyclic mode */ /* channel's basic info */ -struct tasklet_struct tasklet;u32 dcmd;u32 drcmr;u32 dev_addr;@@ -374,7 +373,7 @@ static irqreturn_t mmp_pdma_chan_handler(int irq, void *dev_id)if (clear_chan_irq (phy) !=0 )return IRQ_NONE ; -tasklet_schedule (&phy->vchan->tasklet); +dmaengine_schedule_bh (&phy->vchan->chan);return IRQ_HANDLED ; }@@ -1047,13 +1046,11 @@ static void mmp_pdma_issue_pending(struct dma_chan *dchan) }/* -* dma_do_tasklet -* Do call back -* Start pending list +* dma_do_tasklet - BH worker to process completions and kick pending work */ -static void dma_do_tasklet (struct tasklet_struct *t) +static void dma_do_tasklet (struct dma_chan *c) { -struct mmp_pdma_chan *chan =from_tasklet (chan, t, tasklet); + struct mmp_pdma_chan *chan = container_of(c, struct mmp_pdma_chan, chan);struct mmp_pdma_desc_sw *desc, *_desc;LIST_HEAD (chain_cleanup);unsigned long flags;@@ -1170,7 +1167,7 @@ static int mmp_pdma_chan_init(struct mmp_pdma_device *pdev, int idx, int irq)spin_lock_init (&chan->desc_lock); chan->dev = pdev->dev; chan->chan.device = &pdev->device; -tasklet_setup (&chan->tasklet, dma_do_tasklet); +dmaengine_init_bh (&chan->chan, dma_do_tasklet);INIT_LIST_HEAD (&chan->chain_pending);INIT_LIST_HEAD (&chan->chain_running); --2.43.0
PATCH v3 11/34 dmaengine: mmp_tdma: hook completions to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/mmp_tdma.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/dma/mmp_tdma.c +4 -5
@@ -102,7 +102,6 @@ struct mmp_tdma_chan {struct device *dev;struct dma_chan chan;struct dma_async_tx_descriptor desc; -struct tasklet_struct tasklet;struct mmp_tdma_desc *desc_arr;dma_addr_t desc_arr_phys;
@@ -320,7 +319,7 @@ static irqreturn_t mmp_tdma_chan_handler(int irq, void *dev_id)struct mmp_tdma_chan *tdmac = dev_id;if (mmp_tdma_clear_chan_irq (tdmac) ==0 ) { -tasklet_schedule (&tdmac->tasklet); +dmaengine_schedule_bh (&tdmac->chan);return IRQ_HANDLED ; }else return IRQ_NONE ;
@@ -346,9 +345,9 @@ static irqreturn_t mmp_tdma_int_handler(int irq, void *dev_id)return IRQ_NONE ; } -static void dma_do_tasklet (struct tasklet_struct *t) +static void dma_do_tasklet (struct dma_chan *c) { -struct mmp_tdma_chan *tdmac =from_tasklet (tdmac, t, tasklet); + struct mmp_tdma_chan *tdmac = container_of(c, struct mmp_tdma_chan, chan);dmaengine_desc_get_callback_invoke (&tdmac->desc,NULL ); }
@@ -583,7 +582,7 @@ static int mmp_tdma_chan_init(struct mmp_tdma_device *tdev, tdmac->pool = pool; tdmac->status =DMA_COMPLETE ; tdev->tdmac[tdmac->idx] = tdmac; -tasklet_setup (&tdmac->tasklet, dma_do_tasklet); +dmaengine_init_bh (&tdmac->chan, dma_do_tasklet);/* add the channel to tdma_chan list */ list_add_tail(&tdmac->chan.device_node,
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 11/34] dmaengine: mmp_tdma: hook completions to dmaengine BH
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing explicit teardown of dmaengine BH work, leading to a potential Use-After-Free if work is pending when the driver is removed or the channel is freed.
- [High] The driver requests a shared interrupt before initializing the channel data structures, which can crash the kernel if the interrupt fires immediately. --
--- Patch [11]: [PATCH v3 11/34] dmaengine: mmp_tdma: hook completions to dmaengine BH --- commit fb6d690923127c3cb64e8e8d24e39f8004e89713
Author: Allen Pais <[email protected]>
dmaengine: mmp_tdma: hook completions to dmaengine BH
This commit replaces the per-channel tasklet with the shared dmaengine BH helper for completions. The handler is updated to schedule the BH work while teardown and common scheduling are managed by dmaengine.
drivers/dma/mmp_tdma.c static irqreturn_t mmp_tdma_chan_handler(int irq, void *dev_id) · line 321
Quoted 8 lines
drivers/dma/mmp_tdma.c +0
-0@@ -320,7 +319,7 @@ static irqreturn_t mmp_tdma_chan_handler(int irq, void *dev_id)struct mmp_tdma_chan *tdmac = dev_id;if (mmp_tdma_clear_chan_irq (tdmac) ==0 ) {
[Severity: High]
This isn't a bug introduced by this patch, but is it possible for tdmac to be NULL here if the interrupt fires early?
Looking at mmp_tdma_probe(), devm_request_irq() is called with IRQF_SHARED before mmp_tdma_chan_init() populates the tdev->tdmac array elements.
If another device on the shared interrupt line triggers an interrupt right after it is requested, mmp_tdma_int_handler() will iterate over the uninitialized tdev->tdmac array and pass a NULL tdmac pointer to mmp_tdma_chan_handler().
When mmp_tdma_clear_chan_irq() is called:
mmp_tdma_clear_chan_irq()
u32 reg = readl(tdmac->reg_base + TDISR);
Could this unconditionally dereference the NULL tdmac and cause a panic?
Quoted 4 lines
drivers/dma/mmp_tdma.c +1
-1-tasklet_schedule (&tdmac->tasklet); +dmaengine_schedule_bh (&tdmac->chan);return IRQ_HANDLED ; }else
[ ... ]
drivers/dma/mmp_tdma.c static int mmp_tdma_chan_init(struct mmp_tdma_device *tdev, · line 585
Quoted 6 lines
drivers/dma/mmp_tdma.c +1
-1@@ -583,7 +582,7 @@ static int mmp_tdma_chan_init(struct mmp_tdma_device *tdev, tdmac->pool = pool; tdmac->status =DMA_COMPLETE ; tdev->tdmac[tdmac->idx] = tdmac; -tasklet_setup (&tdmac->tasklet, dma_do_tasklet); +dmaengine_init_bh (&tdmac->chan, dma_do_tasklet);
[Severity: High]
This is a pre-existing issue, but does there need to be a corresponding call to dmaengine_kill_bh() during teardown?
If the driver is removed or the channel is freed while DMA is active or BH work is scheduled, it appears the work could execute after the channel structures are freed:
mmp_tdma_remove()
of_dma_controller_free(pdev->dev.of_node);
Since the tdmac channel structure is allocated via devm_kzalloc(), without explicitly flushing the pending work in mmp_tdma_remove() or mmp_tdma_free_chan_resources(), could this lead to a use-after-free when the pending work later dereferences the freed tdmac?
Quoted 4 lines
drivers/dma/mmp_tdma.c +0
-0/* add the channel to tdma_chan list */ list_add_tail(&tdmac->chan.device_node,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Re: [PATCH v3 11/34] dmaengine: mmp_tdma: hook completions to dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 48 lines
drivers/dma/mmp_tdma.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/dma/mmp_tdma.c +4
-6@@ -102,7 +102,6 @@ struct mmp_tdma_chan {struct device *dev;struct dma_chan chan;struct dma_async_tx_descriptor desc; -struct tasklet_struct tasklet;struct mmp_tdma_desc *desc_arr;dma_addr_t desc_arr_phys;@@ -320,7 +319,7 @@ static irqreturn_t mmp_tdma_chan_handler(int irq, void *dev_id)struct mmp_tdma_chan *tdmac = dev_id;if (mmp_tdma_clear_chan_irq (tdmac) ==0 ) { -tasklet_schedule (&tdmac->tasklet); +dmaengine_schedule_bh (&tdmac->chan);return IRQ_HANDLED ; }else return IRQ_NONE ;@@ -346,9 +345,9 @@ static irqreturn_t mmp_tdma_int_handler(int irq, void *dev_id)return IRQ_NONE ; } -static void dma_do_tasklet (struct tasklet_struct *t) +static void dma_do_tasklet (struct dma_chan *c) { -struct mmp_tdma_chan *tdmac =from_tasklet (tdmac, t, tasklet); + struct mmp_tdma_chan *tdmac = container_of(c, struct mmp_tdma_chan, chan);dmaengine_desc_get_callback_invoke (&tdmac->desc,NULL ); }@@ -583,7 +582,7 @@ static int mmp_tdma_chan_init(struct mmp_tdma_device *tdev, tdmac->pool = pool; tdmac->status =DMA_COMPLETE ; tdev->tdmac[tdmac->idx] = tdmac; -tasklet_setup (&tdmac->tasklet, dma_do_tasklet); +dmaengine_init_bh (&tdmac->chan, dma_do_tasklet);/* add the channel to tdma_chan list */ list_add_tail(&tdmac->chan.device_node, --2.43.0
PATCH v3 12/34 dmaengine: mv_xor: convert irq tasklet to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/mv_xor.c | 12 ++++++------ drivers/dma/mv_xor.h | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-)
drivers/dma/mv_xor.c +6 -6
@@ -327,7 +327,7 @@ static void mv_chan_slot_cleanup(struct mv_xor_chan *mv_chan)* some descriptors are still waiting * to be cleaned */ -tasklet_schedule (&mv_chan->irq_tasklet); +dmaengine_schedule_bh (&mv_chan->dmachan); } } }
@@ -336,9 +336,9 @@ static void mv_chan_slot_cleanup(struct mv_xor_chan *mv_chan) mv_chan->dmachan.completed_cookie = cookie; } -static void mv_xor_tasklet (struct tasklet_struct *t) +static void mv_xor_tasklet (struct dma_chan *c) { -struct mv_xor_chan *chan =from_tasklet (chan, t, irq_tasklet); +struct mv_xor_chan *chan =to_mv_xor_chan (c);spin_lock (&chan->lock);mv_chan_slot_cleanup (chan);
@@ -372,7 +372,7 @@ mv_chan_alloc_slot(struct mv_xor_chan *mv_chan)spin_unlock_bh (&mv_chan->lock);/* try to free some slots if the allocation fails */ -tasklet_schedule (&mv_chan->irq_tasklet); +dmaengine_schedule_bh (&mv_chan->dmachan);return NULL ; }
@@ -737,7 +737,7 @@ static irqreturn_t mv_xor_interrupt_handler(int irq, void *data)if (intr_cause &XOR_INTR_ERRORS )mv_chan_err_interrupt_handler (chan, intr_cause); -tasklet_schedule (&chan->irq_tasklet); +dmaengine_schedule_bh (&chan->dmachan);mv_chan_clear_eoc_cause (chan);
@@ -1107,7 +1107,7 @@ mv_xor_channel_add(struct mv_xor_device *xordev, mv_chan->mmr_base = xordev->xor_base; mv_chan->mmr_high_base = xordev->xor_high_base; -tasklet_setup (&mv_chan->irq_tasklet, mv_xor_tasklet); +dmaengine_init_bh (&mv_chan->dmachan, mv_xor_tasklet);/* clear errors before enabling interrupts */ mv_chan_clear_err_status (mv_chan);
drivers/dma/mv_xor.h +0 -2
@@ -98,7 +98,6 @@ struct mv_xor_device {* @device: parent device * @common: common dmaengine channel object members * @slots_allocated: records the actual size of the descriptor slot pool -* @irq_tasklet: bottom half where mv_xor_slot_cleanup runs * @op_in_desc: new mode of driver, each op is written to descriptor. */ struct mv_xor_chan {
@@ -118,7 +117,6 @@ struct mv_xor_chan {struct dma_device dmadev;struct dma_chan dmachan;int slots_allocated; -struct tasklet_struct irq_tasklet;int op_in_desc;char dummy_src[MV_XOR_MIN_BYTE_COUNT ];char dummy_dst[MV_XOR_MIN_BYTE_COUNT ];
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 12/34] dmaengine: mv_xor: convert irq tasklet to dmaengine BH
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing dmaengine_kill_bh() on error paths and device removal, leading to potential use-after-free of device resources.
- [High] The IRQ is requested and unmasked before critical locks and lists are initialized, leading to a NULL pointer dereference. --
--- Patch [12]: [PATCH v3 12/34] dmaengine: mv_xor: convert irq tasklet to dmaengine BH --- commit 59f9ab1622f4d6943ebdad668684fff90fe01b57
Author: Allen Pais <[email protected]>
dmaengine: mv_xor: convert irq tasklet to dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/mv_xor.c +0
-0
[ ... ]
drivers/dma/mv_xor.c mv_xor_channel_add(struct mv_xor_device *xordev, · line 1110
Quoted 6 lines
drivers/dma/mv_xor.c +1
-1@@ -1107,7 +1107,7 @@ mv_xor_channel_add(struct mv_xor_device *xordev, mv_chan->mmr_base = xordev->xor_base; mv_chan->mmr_high_base = xordev->xor_high_base; -tasklet_setup (&mv_chan->irq_tasklet, mv_xor_tasklet); +dmaengine_init_bh (&mv_chan->dmachan, mv_xor_tasklet);
[Severity: High]
This isn't a bug introduced by this patch, but does the error path miss a teardown for this BH work?
If the probe fails (e.g., during self-test timeouts) or the driver is unbound, free_irq() is called in mv_xor_channel_remove() and the err_free_irq path of mv_xor_channel_add(), but the scheduled bottom-half work is never canceled via dmaengine_kill_bh(&mv_chan->dmachan).
Since mv_chan is subsequently freed, couldn't this lead to a use-after-free if a scheduled bottom-half executes after the memory is freed?
drivers/dma/mv_xor.c mv_xor_channel_add(struct mv_xor_device *xordev, · line 1113
Quoted 3 lines
drivers/dma/mv_xor.c +0
-0/* clear errors before enabling interrupts */ mv_chan_clear_err_status (mv_chan);
[Severity: High]
This is a pre-existing issue, but is it safe to request and unmask the IRQ here before initializing the lock and lists?
A few lines down from here in mv_xor_channel_add():
ret = request_irq(mv_chan->irq, mv_xor_interrupt_handler, 0, dev_name(&pdev->dev), mv_chan); if (ret) goto err_free_dma; mv_chan_unmask_interrupts(mv_chan); ... spin_lock_init(&mv_chan->lock); INIT_LIST_HEAD(&mv_chan->chain);
If a bootloader left a pending End-Of-Chain (EOC) interrupt, couldn't it fire immediately upon unmasking? This would schedule the BH, which takes the uninitialized lock and checks list_empty(&mv_chan->chain).
Since devm_kzalloc zeroed the memory, list_empty() would return false, causing a NULL pointer dereference in the list_for_each_entry_safe() loop.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Re: [PATCH v3 12/34] dmaengine: mv_xor: convert irq tasklet to dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 79 lines
drivers/dma/mv_xor.c | 12 ++++++------ drivers/dma/mv_xor.h | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-)drivers/dma/mv_xor.c +6
-6@@ -327,7 +327,7 @@ static void mv_chan_slot_cleanup(struct mv_xor_chan *mv_chan)* some descriptors are still waiting * to be cleaned */ -tasklet_schedule (&mv_chan->irq_tasklet); +dmaengine_schedule_bh (&mv_chan->dmachan); } } }@@ -336,9 +336,9 @@ static void mv_chan_slot_cleanup(struct mv_xor_chan *mv_chan) mv_chan->dmachan.completed_cookie = cookie; } -static void mv_xor_tasklet (struct tasklet_struct *t) +static void mv_xor_tasklet (struct dma_chan *c) { -struct mv_xor_chan *chan =from_tasklet (chan, t, irq_tasklet); +struct mv_xor_chan *chan =to_mv_xor_chan (c);spin_lock (&chan->lock);mv_chan_slot_cleanup (chan);@@ -372,7 +372,7 @@ mv_chan_alloc_slot(struct mv_xor_chan *mv_chan)spin_unlock_bh (&mv_chan->lock);/* try to free some slots if the allocation fails */ -tasklet_schedule (&mv_chan->irq_tasklet); +dmaengine_schedule_bh (&mv_chan->dmachan);return NULL ; }@@ -737,7 +737,7 @@ static irqreturn_t mv_xor_interrupt_handler(int irq, void *data)if (intr_cause &XOR_INTR_ERRORS )mv_chan_err_interrupt_handler (chan, intr_cause); -tasklet_schedule (&chan->irq_tasklet); +dmaengine_schedule_bh (&chan->dmachan);mv_chan_clear_eoc_cause (chan);@@ -1107,7 +1107,7 @@ mv_xor_channel_add(struct mv_xor_device *xordev, mv_chan->mmr_base = xordev->xor_base; mv_chan->mmr_high_base = xordev->xor_high_base; -tasklet_setup (&mv_chan->irq_tasklet, mv_xor_tasklet); +dmaengine_init_bh (&mv_chan->dmachan, mv_xor_tasklet);/* clear errors before enabling interrupts */ mv_chan_clear_err_status (mv_chan);drivers/dma/mv_xor.h +0
-3@@ -98,7 +98,6 @@ struct mv_xor_device {* @device: parent device * @common: common dmaengine channel object members * @slots_allocated: records the actual size of the descriptor slot pool -* @irq_tasklet: bottom half where mv_xor_slot_cleanup runs * @op_in_desc: new mode of driver, each op is written to descriptor. */ struct mv_xor_chan {@@ -118,7 +117,6 @@ struct mv_xor_chan {struct dma_device dmadev;struct dma_chan dmachan;int slots_allocated; -struct tasklet_struct irq_tasklet;int op_in_desc;char dummy_src[MV_XOR_MIN_BYTE_COUNT ];char dummy_dst[MV_XOR_MIN_BYTE_COUNT ]; --2.43.0
PATCH v3 13/34 dmaengine: mxs-dma: use dmaengine BH scheduling
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/mxs-dma.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/dma/mxs-dma.c +5 -6
@@ -109,7 +109,6 @@ struct mxs_dma_chan {struct mxs_dma_engine *mxs_dma;struct dma_chan chan;struct dma_async_tx_descriptor desc; -struct tasklet_struct tasklet;unsigned int chan_irq;struct mxs_dma_ccw *ccw;dma_addr_t ccw_phys;
@@ -300,9 +299,9 @@ static dma_cookie_t mxs_dma_tx_submit(struct dma_async_tx_descriptor *tx)return dma_cookie_assign (tx); } -static void mxs_dma_tasklet (struct tasklet_struct *t) +static void mxs_dma_tasklet (struct dma_chan *chan) { -struct mxs_dma_chan *mxs_chan =from_tasklet (mxs_chan, t, tasklet); +struct mxs_dma_chan *mxs_chan =to_mxs_dma_chan (chan);dmaengine_desc_get_callback_invoke (&mxs_chan->desc,NULL ); }
@@ -386,8 +385,8 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)dma_cookie_complete (&mxs_chan->desc); } -/* schedule tasklet on this channel */ -tasklet_schedule (&mxs_chan->tasklet); +/* schedule BH on this channel */ +dmaengine_schedule_bh (&mxs_chan->chan);return IRQ_HANDLED ; }
@@ -781,7 +780,7 @@ static int mxs_dma_probe(struct platform_device *pdev) mxs_chan->chan.device = &mxs_dma->dma_device;dma_cookie_init (&mxs_chan->chan); -tasklet_setup (&mxs_chan->tasklet, mxs_dma_tasklet); +dmaengine_init_bh (&mxs_chan->chan, mxs_dma_tasklet);/* Add the channel to mxs_chan list */
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 13/34] dmaengine: mxs-dma: use dmaengine BH scheduling
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver does not kill the deferred bottom-half work during channel teardown or error paths, nor does it provide a device_synchronize callback, leading to a potential use-after-free.
- [High] Requesting the IRQ before enabling the device clock can result in a synchronous external abort and bus hang.
--
--- Patch [13]: [PATCH v3 13/34] dmaengine: mxs-dma: use dmaengine BH scheduling --- commit 84e84c7d902dd9157e789fe8d760954306bc43d6
Author: Allen Pais <[email protected]>
dmaengine: mxs-dma: use dmaengine BH scheduling
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/mxs-dma.c +0
-0
[ ... ]
drivers/dma/mxs-dma.c static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id) · line 392
Quoted 11 lines
drivers/dma/mxs-dma.c +2
-2@@ -386,8 +385,8 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)dma_cookie_complete (&mxs_chan->desc); } -/* schedule tasklet on this channel */ -tasklet_schedule (&mxs_chan->tasklet); +/* schedule BH on this channel */ +dmaengine_schedule_bh (&mxs_chan->chan);return IRQ_HANDLED ; }
[Severity: High]
This is a pre-existing issue, but since the driver is moving to the BH mechanism, should we also ensure the scheduled work is properly flushed during teardown and error paths?
Looking at mxs_dma_alloc_chan_resources(), if clk_prepare_enable() fails, the error path frees the IRQ and the channel ccw structure:
mxs_dma_alloc_chan_resources() {
...
err_clk:
free_irq(mxs_chan->chan_irq, mxs_dma);
err_irq:
dma_free_coherent(mxs_dma->dma_device.dev, CCW_BLOCK_SIZE,
mxs_chan->ccw, mxs_chan->ccw_phys);
...
}Because free_irq() waits for the hardirq handler but not the scheduled workqueue, if an early interrupt schedules the BH work, can the workqueue execute after the channel resources have been freed, leading to a use-after-free?
Similarly, mxs_dma_free_chan_resources() frees channel resources without calling dmaengine_kill_bh(). The driver also lacks a device_synchronize callback, which makes dmaengine_terminate_sync() a no-op.
Should we add dmaengine_kill_bh() and a synchronization callback to prevent the scheduled work from running after the client frees the channel?
[ ... ]
drivers/dma/mxs-dma.c static int mxs_dma_probe(struct platform_device *pdev) · line 786
Quoted 9 lines
drivers/dma/mxs-dma.c +1
-1@@ -781,7 +780,7 @@ static int mxs_dma_probe(struct platform_device *pdev) mxs_chan->chan.device = &mxs_dma->dma_device;dma_cookie_init (&mxs_chan->chan); -tasklet_setup (&mxs_chan->tasklet, mxs_dma_tasklet); +dmaengine_init_bh (&mxs_chan->chan, mxs_dma_tasklet);/* Add the channel to mxs_chan list */
[Severity: High]
This isn't a bug introduced by this patch, but I wanted to ask about the initialization ordering which can trigger the interrupt handler early.
When a channel is allocated in mxs_dma_alloc_chan_resources(), the IRQ is requested before the clock is enabled:
mxs_dma_alloc_chan_resources() {
...
ret = request_irq(mxs_chan->chan_irq, mxs_dma_int_handler,
0, "mxs-dma", mxs_dma);
if (ret)
goto err_irq;
ret = clk_prepare_enable(mxs_dma->clk);
...
}If an interrupt line is asserted early (for example, from a previously aborted transaction where the client didn't call terminate_all), mxs_dma_int_handler() will fire immediately. It then performs an MMIO read on the memory-mapped controller registers (mxs_dma->base + HW_APBHX_CTRL1).
Since accessing device registers with a disabled clock results in a bus hang on this platform, would it be safer to enable the clock before requesting the IRQ to prevent a synchronous external abort?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Re: [PATCH v3 13/34] dmaengine: mxs-dma: use dmaengine BH scheduling
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 50 lines
drivers/dma/mxs-dma.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/dma/mxs-dma.c +5
-7@@ -109,7 +109,6 @@ struct mxs_dma_chan {struct mxs_dma_engine *mxs_dma;struct dma_chan chan;struct dma_async_tx_descriptor desc; -struct tasklet_struct tasklet;unsigned int chan_irq;struct mxs_dma_ccw *ccw;dma_addr_t ccw_phys;@@ -300,9 +299,9 @@ static dma_cookie_t mxs_dma_tx_submit(struct dma_async_tx_descriptor *tx)return dma_cookie_assign (tx); } -static void mxs_dma_tasklet (struct tasklet_struct *t) +static void mxs_dma_tasklet (struct dma_chan *chan) { -struct mxs_dma_chan *mxs_chan =from_tasklet (mxs_chan, t, tasklet); +struct mxs_dma_chan *mxs_chan =to_mxs_dma_chan (chan);dmaengine_desc_get_callback_invoke (&mxs_chan->desc,NULL ); }@@ -386,8 +385,8 @@ static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)dma_cookie_complete (&mxs_chan->desc); } -/* schedule tasklet on this channel */ -tasklet_schedule (&mxs_chan->tasklet); +/* schedule BH on this channel */ +dmaengine_schedule_bh (&mxs_chan->chan);return IRQ_HANDLED ; }@@ -781,7 +780,7 @@ static int mxs_dma_probe(struct platform_device *pdev) mxs_chan->chan.device = &mxs_dma->dma_device;dma_cookie_init (&mxs_chan->chan); -tasklet_setup (&mxs_chan->tasklet, mxs_dma_tasklet); +dmaengine_init_bh (&mxs_chan->chan, mxs_dma_tasklet);/* Add the channel to mxs_chan list */ --2.43.0
PATCH v3 14/34 dmaengine: nbpfaxi: switch callbacks to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/nbpfaxi.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/dma/nbpfaxi.c +6 -7
@@ -174,7 +174,6 @@ struct nbpf_desc_page {/** * struct nbpf_channel - one DMAC channel * @dma_chan: standard dmaengine channel object -* @tasklet: channel specific tasklet used for callbacks * @base: register address base * @nbpf: DMAC * @name: IRQ name
@@ -200,7 +199,6 @@ struct nbpf_desc_page {*/ struct nbpf_channel {struct dma_chan dma_chan; -struct tasklet_struct tasklet;void __iomem *base;struct nbpf_device *nbpf;char name[16 ];
@@ -1125,9 +1123,10 @@ static struct dma_chan *nbpf_of_xlate(struct of_phandle_args *dma_spec,return dchan; } -static void nbpf_chan_tasklet (struct tasklet_struct *t) +static void nbpf_chan_tasklet (struct dma_chan *c) { -struct nbpf_channel *chan =from_tasklet (chan, t, tasklet); + struct nbpf_channel *chan = container_of(c, struct nbpf_channel, + dma_chan);struct nbpf_desc *desc, *tmp;struct dmaengine_desc_callback cb;
@@ -1228,7 +1227,7 @@ static irqreturn_t nbpf_chan_irq(int irq, void *dev)spin_unlock (&chan->lock);if (bh) -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->dma_chan);return ret; }
@@ -1272,7 +1271,7 @@ static int nbpf_chan_probe(struct nbpf_device *nbpf, int n)snprintf (chan->name,sizeof (chan->name),"nbpf %d" , n); -tasklet_setup (&chan->tasklet, nbpf_chan_tasklet); +dmaengine_init_bh (&chan->dma_chan, nbpf_chan_tasklet); ret =devm_request_irq (dma_dev->dev, chan->irq, nbpf_chan_irq,IRQF_SHARED , chan->name, chan);
@@ -1478,7 +1477,7 @@ static void nbpf_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, chan->irq, chan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->dma_chan); }of_dma_controller_free (pdev->dev.of_node);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 14/34] dmaengine: nbpfaxi: switch callbacks to dmaengine BH
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Shared IRQs are registered before the device clock is enabled, risking a bus fault or system crash. --
--- Patch [14]: [PATCH v3 14/34] dmaengine: nbpfaxi: switch callbacks to dmaengine BH --- commit 0e57a5ca2e574d87910252599a7cb1273a78c7e5
Author: Allen Pais <[email protected]>
dmaengine: nbpfaxi: switch callbacks to dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/nbpfaxi.c +0
-0
[ ... ]
drivers/dma/nbpfaxi.c static int nbpf_chan_probe(struct nbpf_device *nbpf, int n) · line 1277
Quoted 9 lines
drivers/dma/nbpfaxi.c +1
-1@@ -1272,7 +1271,7 @@ static int nbpf_chan_probe(struct nbpf_device *nbpf, int n)snprintf (chan->name,sizeof (chan->name),"nbpf %d" , n); -tasklet_setup (&chan->tasklet, nbpf_chan_tasklet); +dmaengine_init_bh (&chan->dma_chan, nbpf_chan_tasklet); ret =devm_request_irq (dma_dev->dev, chan->irq, nbpf_chan_irq,IRQF_SHARED , chan->name, chan);
[Severity: High]
This is a pre-existing issue, but shared IRQs are registered here in nbpf_chan_probe() before the device clock is enabled.
If another device sharing the IRQ line triggers an interrupt before clk_prepare_enable(nbpf->clk) is called later in nbpf_probe(), or if a spurious interrupt occurs, the kernel will invoke nbpf_chan_irq().
The handler calls nbpf_status_get() which reads from device registers. Accessing memory-mapped registers of a device while its clock is disabled can cause a synchronous external abort (bus fault) and crash the system.
Furthermore, on the error path of nbpf_probe(), clk_disable_unprepare() is called manually while the devm-managed IRQs remain active until devres cleanup runs, creating a second window for the same crash.
Does this initialization sequence need to be restructured so that IRQs are registered only after the clock is enabled, and disabled before the clock is turned off?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
PATCH v3 15/34 dmaengine: pch_dma: convert tasklet to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/pch_dma.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/dma/pch_dma.c +7 -7
@@ -91,7 +91,6 @@ struct pch_dma_chan {struct dma_chan chan;void __iomem *membase;enum dma_transfer_direction dir; -struct tasklet_struct tasklet;unsigned long err_status;spinlock_t lock;
@@ -665,9 +664,10 @@ static int pd_device_terminate_all(struct dma_chan *chan)return 0 ; } -static void pdc_tasklet (struct tasklet_struct *t) +static void pdc_tasklet (struct dma_chan *c) { -struct pch_dma_chan *pd_chan =from_tasklet (pd_chan, t, tasklet); + struct pch_dma_chan *pd_chan = container_of(c, struct pch_dma_chan, + chan);unsigned long flags;if (!pdc_is_idle (pd_chan)) {
@@ -707,7 +707,7 @@ static irqreturn_t pd_irq(int irq, void *devid)if (sts0 &DMA_STATUS0_ERR (i))set_bit (0 , &pd_chan->err_status); -tasklet_schedule (&pd_chan->tasklet); +dmaengine_schedule_bh (&pd_chan->chan); ret0 =IRQ_HANDLED ; } }else {
@@ -715,7 +715,7 @@ static irqreturn_t pd_irq(int irq, void *devid)if (sts2 &DMA_STATUS2_ERR (i))set_bit (0 , &pd_chan->err_status); -tasklet_schedule (&pd_chan->tasklet); +dmaengine_schedule_bh (&pd_chan->chan); ret2 =IRQ_HANDLED ; } }
@@ -877,7 +877,7 @@ static int pch_dma_probe(struct pci_dev *pdev,INIT_LIST_HEAD (&pd_chan->queue);INIT_LIST_HEAD (&pd_chan->free_list); -tasklet_setup (&pd_chan->tasklet, pdc_tasklet); +dmaengine_init_bh (&pd_chan->chan, pdc_tasklet);list_add_tail (&pd_chan->chan.device_node, &pd->dma.channels); }
@@ -930,7 +930,7 @@ static void pch_dma_remove(struct pci_dev *pdev) device_node) { pd_chan =to_pd_chan (chan); -tasklet_kill (&pd_chan->tasklet); +dmaengine_kill_bh (&pd_chan->chan); }dma_pool_destroy (pd->pool);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 15/34] dmaengine: pch_dma: convert tasklet to dmaengine BH
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing cancellation of scheduled BH work in the probe error path leads to a Use-After-Free.
- [High] The driver invokes the DMA client's callback with the channel spinlock held, causing a deadlock if the client queues a new transfer.
- [High] Missing softirq protection on process-context locks causes deadlocks when preempted by the softirq-context BH.
- [High] Using spin_lock_irq unconditionally re-enables interrupts, which causes IRQ state corruption if called from atomic context.
- [High] The driver requests a shared IRQ before the channel count is initialized and without masking hardware interrupts, causing a potential IRQ storm. --
--- Patch [15]: [PATCH v3 15/34] dmaengine: pch_dma: convert tasklet to dmaengine BH --- commit 7e489ac0179032bce9c722d41def47b8d30c50c9
Author: Allen Pais <[email protected]>
dmaengine: pch_dma: convert tasklet to dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/pch_dma.c +0
-0
[ ... ]
drivers/dma/pch_dma.c static int pd_device_terminate_all(struct dma_chan *chan) · line 665
Quoted 3 lines
drivers/dma/pch_dma.c +0
-0@@ -665,9 +664,10 @@ static int pd_device_terminate_all(struct dma_chan *chan)return 0 ; }
[Severity: High]
This is a pre-existing issue, but does pd_device_terminate_all() corrupt the caller's interrupt state?
If a DMA client calls dmaengine_terminate_all() from an atomic or interrupt context, pd_device_terminate_all() executes:
pd_device_terminate_all() {
spin_lock_irq(&pd_chan->lock);
...
spin_unlock_irq(&pd_chan->lock);
}Since spin_unlock_irq() unconditionally re-enables interrupts, could this cause unexpected nested interrupts if the caller had already disabled them?
drivers/dma/pch_dma.c static int pd_device_terminate_all(struct dma_chan *chan) · line 671
Quoted 7 lines
drivers/dma/pch_dma.c +3
-2-static void pdc_tasklet (struct tasklet_struct *t) +static void pdc_tasklet (struct dma_chan *c) { -struct pch_dma_chan *pd_chan =from_tasklet (pd_chan, t, tasklet); + struct pch_dma_chan *pd_chan = container_of(c, struct pch_dma_chan, + chan);unsigned long flags;
[Severity: High]
This isn't a bug introduced by this patch, but can the BH handler deadlock against new transfer submissions?
When the softirq executes pdc_tasklet(), it acquires pd_chan->lock using spin_lock_irqsave(). It can then call pdc_chain_complete(), which invokes the client's completion callback synchronously while still holding the lock:
pdc_chain_complete() {
...
dmaengine_desc_callback_invoke(&cb, NULL);
}If the client attempts to schedule a new DMA transaction during this callback, it calls pd_tx_submit(), which tries to acquire the exact same lock:
pd_tx_submit() {
spin_lock(&pd_chan->lock);
}Could this sequence result in an immediate self-deadlock?
[Severity: High]
This is also a pre-existing issue, but is there a missing softirq protection on process-context locks?
If a DMA client calls pd_tx_submit() or pd_issue_pending() from process context, they acquire the lock without disabling softirqs:
pd_tx_submit() {
spin_lock(&pd_chan->lock);
}If a softirq interrupts the CPU before the lock is released, and pdc_tasklet() executes, it will try to acquire the same lock using spin_lock_irqsave().
Will this cause the softirq to spin forever waiting for the preempted process to release the lock?
[ ... ]
drivers/dma/pch_dma.c static int pch_dma_probe(struct pci_dev *pdev, · line 882
Quoted 8 lines
drivers/dma/pch_dma.c +1
-1@@ -877,7 +877,7 @@ static int pch_dma_probe(struct pci_dev *pdev,INIT_LIST_HEAD (&pd_chan->queue);INIT_LIST_HEAD (&pd_chan->free_list); -tasklet_setup (&pd_chan->tasklet, pdc_tasklet); +dmaengine_init_bh (&pd_chan->chan, pdc_tasklet);list_add_tail (&pd_chan->chan.device_node, &pd->dma.channels); }
[Severity: High]
This isn't a bug introduced by this patch, but does the probe sequence risk an unhandled IRQ storm?
In pch_dma_probe(), the shared IRQ is requested before the channel count is initialized by dma_async_device_register():
pch_dma_probe() {
...
err = request_irq(pdev->irq, pd_irq, IRQF_SHARED, DRV_NAME, pd);
...
err = dma_async_device_register(&pd->dma);
}If the hardware has a pending interrupt and fires immediately, pd_irq() will execute while pd->dma.chancnt is still 0.
pd_irq() {
for (i = 0; i < pd->dma.chancnt; i++) { ... }
...
if (ret0)
dma_writel(pd, STS0, sts0);
}Because chancnt is 0, the loop is skipped, hardware status is not cleared, and IRQ_NONE is returned. Could this cause the kernel's spurious interrupt detector to permanently disable the shared IRQ line?
[Severity: High]
This is a pre-existing issue, but does the probe error path leave un-cancelled BH work?
If dma_async_device_register() fails after the IRQ has been requested and the BH has been initialized, the probe error path executes:
pch_dma_probe() {
...err_free_pool:
dma_pool_destroy(pd->pool);
err_free_irq:
free_irq(pdev->irq, pd);
err_iounmap:
pci_iounmap(pdev, pd->membase);
err_free_res:
pci_release_regions(pdev);
err_disable_pdev:
pci_disable_device(pdev);
err_free_mem:
kfree(pd);
}If a spurious interrupt fired and called dmaengine_schedule_bh() before free_irq() is called, this error path frees the pd memory without calling dmaengine_kill_bh(). Could the scheduled BH execute later and access the freed pd_chan structure, resulting in a use-after-free?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
Re: [PATCH v3 15/34] dmaengine: pch_dma: convert tasklet to dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 67 lines
drivers/dma/pch_dma.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/dma/pch_dma.c +7
-8@@ -91,7 +91,6 @@ struct pch_dma_chan {struct dma_chan chan;void __iomem *membase;enum dma_transfer_direction dir; -struct tasklet_struct tasklet;unsigned long err_status;spinlock_t lock;@@ -665,9 +664,10 @@ static int pd_device_terminate_all(struct dma_chan *chan)return 0 ; } -static void pdc_tasklet (struct tasklet_struct *t) +static void pdc_tasklet (struct dma_chan *c) { -struct pch_dma_chan *pd_chan =from_tasklet (pd_chan, t, tasklet); + struct pch_dma_chan *pd_chan = container_of(c, struct pch_dma_chan, + chan);unsigned long flags;if (!pdc_is_idle (pd_chan)) {@@ -707,7 +707,7 @@ static irqreturn_t pd_irq(int irq, void *devid)if (sts0 &DMA_STATUS0_ERR (i))set_bit (0 , &pd_chan->err_status); -tasklet_schedule (&pd_chan->tasklet); +dmaengine_schedule_bh (&pd_chan->chan); ret0 =IRQ_HANDLED ; } }else {@@ -715,7 +715,7 @@ static irqreturn_t pd_irq(int irq, void *devid)if (sts2 &DMA_STATUS2_ERR (i))set_bit (0 , &pd_chan->err_status); -tasklet_schedule (&pd_chan->tasklet); +dmaengine_schedule_bh (&pd_chan->chan); ret2 =IRQ_HANDLED ; } }@@ -877,7 +877,7 @@ static int pch_dma_probe(struct pci_dev *pdev,INIT_LIST_HEAD (&pd_chan->queue);INIT_LIST_HEAD (&pd_chan->free_list); -tasklet_setup (&pd_chan->tasklet, pdc_tasklet); +dmaengine_init_bh (&pd_chan->chan, pdc_tasklet);list_add_tail (&pd_chan->chan.device_node, &pd->dma.channels); }@@ -930,7 +930,7 @@ static void pch_dma_remove(struct pci_dev *pdev) device_node) { pd_chan =to_pd_chan (chan); -tasklet_kill (&pd_chan->tasklet); +dmaengine_kill_bh (&pd_chan->chan); }dma_pool_destroy (pd->pool); --2.43.0
PATCH v3 16/34 dmaengine: ppc4xx: replace irq tasklet with dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/ppc4xx/adma.c | 14 +++++++------- drivers/dma/ppc4xx/adma.h | 2 -- 2 files changed, 7 insertions(+), 9 deletions(-)
drivers/dma/ppc4xx/adma.c +7 -7
@@ -1658,9 +1658,9 @@ static void __ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan *chan)/** * ppc440spe_adma_tasklet - clean up watch-dog initiator */ -static void ppc440spe_adma_tasklet (struct tasklet_struct *t) +static void ppc440spe_adma_tasklet (struct dma_chan *c) { -struct ppc440spe_adma_chan *chan =from_tasklet (chan, t, irq_tasklet); +struct ppc440spe_adma_chan *chan =to_ppc440spe_adma_chan (c);spin_lock_nested (&chan->lock,SINGLE_DEPTH_NESTING );__ppc440spe_adma_slot_cleanup (chan);
@@ -1754,7 +1754,7 @@ static struct ppc440spe_adma_desc_slot *ppc440spe_adma_alloc_slots( goto retry;/* try to free some slots if the allocation fails */ -tasklet_schedule (&chan->irq_tasklet); +dmaengine_schedule_bh (&chan->common);return NULL ; }
@@ -3595,7 +3595,7 @@ static irqreturn_t ppc440spe_adma_eot_handler(int irq, void *data)dev_dbg (chan->device->common.dev,"ppc440spe adma%d: %s\n" , chan->device->id, __func__); -tasklet_schedule (&chan->irq_tasklet); +dmaengine_schedule_bh (&chan->common);ppc440spe_adma_device_clear_eot_status (chan);return IRQ_HANDLED ;
@@ -3612,7 +3612,7 @@ static irqreturn_t ppc440spe_adma_err_handler(int irq, void *data)dev_dbg (chan->device->common.dev,"ppc440spe adma%d: %s\n" , chan->device->id, __func__); -tasklet_schedule (&chan->irq_tasklet); +dmaengine_schedule_bh (&chan->common);ppc440spe_adma_device_clear_eot_status (chan);return IRQ_HANDLED ;
@@ -4137,7 +4137,7 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev) chan->common.device = &adev->common;dma_cookie_init (&chan->common);list_add_tail (&chan->common.device_node, &adev->common.channels); -tasklet_setup (&chan->irq_tasklet, ppc440spe_adma_tasklet); +dmaengine_init_bh (&chan->common, ppc440spe_adma_tasklet);/* allocate and map helper pages for async validation or * async_mult/async_sum_product operations on DMA0/1.
@@ -4247,7 +4247,7 @@ static void ppc440spe_adma_remove(struct platform_device *ofdev) device_node) { ppc440spe_chan =to_ppc440spe_adma_chan (chan);ppc440spe_adma_release_irqs (adev, ppc440spe_chan); -tasklet_kill (&ppc440spe_chan->irq_tasklet); +dmaengine_kill_bh (&ppc440spe_chan->common);if (adev->id !=PPC440SPE_XOR_ID ) {dma_unmap_page (&ofdev->dev, ppc440spe_chan->pdest,PAGE_SIZE ,DMA_BIDIRECTIONAL );
drivers/dma/ppc4xx/adma.h +0 -2
@@ -80,7 +80,6 @@ struct ppc440spe_adma_device {* @pending: allows batching of hardware operations * @slots_allocated: records the actual size of the descriptor slot pool * @hw_chain_inited: h/w descriptor chain initialization flag -* @irq_tasklet: bottom half where ppc440spe_adma_slot_cleanup runs * @needs_unmap: if buffers should not be unmapped upon final processing * @pdest_page: P destination page for async validate operation * @qdest_page: Q destination page for async validate operation
@@ -97,7 +96,6 @@ struct ppc440spe_adma_chan {int pending;int slots_allocated;int hw_chain_inited; -struct tasklet_struct irq_tasklet;u8 needs_unmap;struct page *pdest_page;struct page *qdest_page;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 16/34] dmaengine: ppc4xx: replace irq tasklet with dmaengine BH
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free due to missing dmaengine_kill_bh() on the probe error path.
- [High] Self-deadlock in the bottom-half callback when processing dependent DMA transactions on the same channel. --
--- Patch [16]: [PATCH v3 16/34] dmaengine: ppc4xx: replace irq tasklet with dmaengine BH --- commit 4ccd13b8e7ec3566e05878b1ca91b9e88ad9043a
Author: Allen Pais <[email protected]>
dmaengine: ppc4xx: replace irq tasklet with dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 6 lines
drivers/dma/ppc4xx/adma.c +0
-0@@ -1658,9 +1658,9 @@ static void __ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan *chan)/**
drivers/dma/ppc4xx/adma.c static void __ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan *chan) · line 1666
Quoted 10 lines
drivers/dma/ppc4xx/adma.c +2
-2* ppc440spe_adma_tasklet - clean up watch-dog initiator */ -static void ppc440spe_adma_tasklet (struct tasklet_struct *t) +static void ppc440spe_adma_tasklet (struct dma_chan *c) { -struct ppc440spe_adma_chan *chan =from_tasklet (chan, t, irq_tasklet); +struct ppc440spe_adma_chan *chan =to_ppc440spe_adma_chan (c);spin_lock_nested (&chan->lock,SINGLE_DEPTH_NESTING );__ppc440spe_adma_slot_cleanup (chan);
[Severity: High]
This is a pre-existing issue, but does this locking sequence cause a self-deadlock when processing dependent transactions?
If the callback processes a dependent transaction targeting the same channel, dma_run_dependencies() will call the submit callback:
ppc440spe_adma_tasklet()
spin_lock_nested(&chan->lock, ...)
__ppc440spe_adma_slot_cleanup()
ppc440spe_adma_run_tx_complete_actions()
dma_run_dependencies()
ppc440spe_adma_tx_submit()
spin_lock_bh(&chan->lock)Since the non-recursive spinlock is already held by this CPU, will this immediately deadlock?
Should the lock be dropped prior to evaluating completion callbacks or dependencies?
[ ... ]
drivers/dma/ppc4xx/adma.c static int ppc440spe_adma_probe(struct platform_device *ofdev) · line 4140
Quoted 6 lines
drivers/dma/ppc4xx/adma.c +1
-1@@ -4137,7 +4137,7 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev) chan->common.device = &adev->common;dma_cookie_init (&chan->common);list_add_tail (&chan->common.device_node, &adev->common.channels); -tasklet_setup (&chan->irq_tasklet, ppc440spe_adma_tasklet); +dmaengine_init_bh (&chan->common, ppc440spe_adma_tasklet);
[Severity: High]
This isn't a bug introduced by this patch, but could this lead to a use-after-free during probe failure?
If an early hardware interrupt fires during probe, ppc440spe_adma_eot_handler() will schedule this bottom half.
If a subsequent initialization step fails, the error path releases the interrupt via free_irq(), but does not cancel the scheduled bottom half:
err_dev_reg:
ppc440spe_adma_release_irqs(adev, chan); err_irq: ... err_page_alloc: kfree(chan);
If the bottom half executes after kfree(chan), will it access freed memory?
Should dmaengine_kill_bh() be added to the probe error path?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
Re: [PATCH v3 16/34] dmaengine: ppc4xx: replace irq tasklet with dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 88 lines
drivers/dma/ppc4xx/adma.c | 14 +++++++------- drivers/dma/ppc4xx/adma.h | 2 -- 2 files changed, 7 insertions(+), 9 deletions(-)drivers/dma/ppc4xx/adma.c +7
-7@@ -1658,9 +1658,9 @@ static void __ppc440spe_adma_slot_cleanup(struct ppc440spe_adma_chan *chan)/** * ppc440spe_adma_tasklet - clean up watch-dog initiator */ -static void ppc440spe_adma_tasklet (struct tasklet_struct *t) +static void ppc440spe_adma_tasklet (struct dma_chan *c) { -struct ppc440spe_adma_chan *chan =from_tasklet (chan, t, irq_tasklet); +struct ppc440spe_adma_chan *chan =to_ppc440spe_adma_chan (c);spin_lock_nested (&chan->lock,SINGLE_DEPTH_NESTING );__ppc440spe_adma_slot_cleanup (chan);@@ -1754,7 +1754,7 @@ static struct ppc440spe_adma_desc_slot *ppc440spe_adma_alloc_slots( goto retry;/* try to free some slots if the allocation fails */ -tasklet_schedule (&chan->irq_tasklet); +dmaengine_schedule_bh (&chan->common);return NULL ; }@@ -3595,7 +3595,7 @@ static irqreturn_t ppc440spe_adma_eot_handler(int irq, void *data)dev_dbg (chan->device->common.dev,"ppc440spe adma%d: %s\n" , chan->device->id, __func__); -tasklet_schedule (&chan->irq_tasklet); +dmaengine_schedule_bh (&chan->common);ppc440spe_adma_device_clear_eot_status (chan);return IRQ_HANDLED ;@@ -3612,7 +3612,7 @@ static irqreturn_t ppc440spe_adma_err_handler(int irq, void *data)dev_dbg (chan->device->common.dev,"ppc440spe adma%d: %s\n" , chan->device->id, __func__); -tasklet_schedule (&chan->irq_tasklet); +dmaengine_schedule_bh (&chan->common);ppc440spe_adma_device_clear_eot_status (chan);return IRQ_HANDLED ;@@ -4137,7 +4137,7 @@ static int ppc440spe_adma_probe(struct platform_device *ofdev) chan->common.device = &adev->common;dma_cookie_init (&chan->common);list_add_tail (&chan->common.device_node, &adev->common.channels); -tasklet_setup (&chan->irq_tasklet, ppc440spe_adma_tasklet); +dmaengine_init_bh (&chan->common, ppc440spe_adma_tasklet);/* allocate and map helper pages for async validation or * async_mult/async_sum_product operations on DMA0/1. @@ -4247,7 +4247,7 @@ static void ppc440spe_adma_remove(struct platform_device *ofdev) device_node) { ppc440spe_chan =to_ppc440spe_adma_chan (chan);ppc440spe_adma_release_irqs (adev, ppc440spe_chan); -tasklet_kill (&ppc440spe_chan->irq_tasklet); +dmaengine_kill_bh (&ppc440spe_chan->common);if (adev->id !=PPC440SPE_XOR_ID ) {dma_unmap_page (&ofdev->dev, ppc440spe_chan->pdest,PAGE_SIZE ,DMA_BIDIRECTIONAL );drivers/dma/ppc4xx/adma.h +0
-3@@ -80,7 +80,6 @@ struct ppc440spe_adma_device {* @pending: allows batching of hardware operations * @slots_allocated: records the actual size of the descriptor slot pool * @hw_chain_inited: h/w descriptor chain initialization flag -* @irq_tasklet: bottom half where ppc440spe_adma_slot_cleanup runs * @needs_unmap: if buffers should not be unmapped upon final processing * @pdest_page: P destination page for async validate operation * @qdest_page: Q destination page for async validate operation @@ -97,7 +96,6 @@ struct ppc440spe_adma_chan {int pending;int slots_allocated;int hw_chain_inited; -struct tasklet_struct irq_tasklet;u8 needs_unmap;struct page *pdest_page;struct page *qdest_page; --2.43.0
PATCH v3 17/34 dmaengine: ste_dma40: convert per-channel tasklet to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/ste_dma40.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/dma/ste_dma40.c +5 -8
@@ -461,8 +461,6 @@ struct d40_base;* @phy_chan: Pointer to physical channel which this instance runs on. If this * point is NULL, then the channel is not allocated. * @chan: DMA engine handle. -* @tasklet: Tasklet that gets scheduled from interrupt context to complete a -* transfer and call client callback. * @client: Cliented owned descriptor list. * @pending_queue: Submitted jobs, to be issued by issue_pending() * @active: Active descriptor.
@@ -489,7 +487,6 @@ struct d40_chan {bool busy;struct d40_phy_res *phy_chan;struct dma_chan chan; -struct tasklet_struct tasklet;struct list_head client;struct list_head pending_queue;struct list_head active;
@@ -1587,13 +1584,13 @@ static void dma_tc_handle(struct d40_chan *d40c) } d40c->pending_tx++; -tasklet_schedule (&d40c->tasklet); +dmaengine_schedule_bh (&d40c->chan); } -static void dma_tasklet (struct tasklet_struct *t) +static void dma_tasklet (struct dma_chan *chan) { -struct d40_chan *d40c =from_tasklet (d40c, t, tasklet); + struct d40_chan *d40c = container_of(chan, struct d40_chan, chan);struct d40_desc *d40d;unsigned long flags;bool callback_active;
@@ -1641,7 +1638,7 @@ static void dma_tasklet(struct tasklet_struct *t) d40c->pending_tx--;if (d40c->pending_tx) -tasklet_schedule (&d40c->tasklet); +dmaengine_schedule_bh (&d40c->chan);spin_unlock_irqrestore (&d40c->lock, flags);
@@ -2815,7 +2812,7 @@ static void __init d40_chan_init(struct d40_base *base, struct dma_device *dma,INIT_LIST_HEAD (&d40c->client);INIT_LIST_HEAD (&d40c->prepare_queue); -tasklet_setup (&d40c->tasklet, dma_tasklet); +dmaengine_init_bh (&d40c->chan, dma_tasklet);list_add_tail (&d40c->chan.device_node, &dma->channels);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 17/34] dmaengine: ste_dma40: convert per-channel tasklet to dmaengine BH
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing IRQ free on probe error path leads to Use-After-Free
- [High] Missing device_synchronize callback causes UAF race condition with client callbacks
- [High] Integer underflow and out-of-bounds array access on zero-length scatterlist --
--- Patch [17]: [PATCH v3 17/34] dmaengine: ste_dma40: convert per-channel tasklet to dmaengine BH --- commit fc9cce1bc39ef7ff38acb71e0dd932c23517c6a1
Author: Allen Pais <[email protected]>
dmaengine: ste_dma40: convert per-channel tasklet to dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/ste_dma40.c +0
-0
[ ... ]
drivers/dma/ste_dma40.c static void dma_tasklet(struct tasklet_struct *t) · line 1643
Quoted 8 lines
drivers/dma/ste_dma40.c +1
-1@@ -1641,7 +1638,7 @@ static void dma_tasklet(struct tasklet_struct *t) d40c->pending_tx--;if (d40c->pending_tx) -tasklet_schedule (&d40c->tasklet); +dmaengine_schedule_bh (&d40c->chan);spin_unlock_irqrestore (&d40c->lock, flags);
[Severity: High]
This is a pre-existing issue, but I noticed the callback is executed without the channel lock held here.
Is it possible for a concurrent client termination to return early and free resources?
The ste_dma40 driver does not implement the device_synchronize callback. When a client calls dmaengine_terminate_sync(), the core dmaengine_synchronize() fallback acts as a no-op.
If dmaengine_terminate_sync() is called while this background handler has dropped the lock to execute dmaengine_desc_callback_invoke(), could the termination return immediately instead of waiting for the callback to finish?
This might allow the client to proceed and free buffers or structures that the background callback is actively accessing.
Also, I noticed another pre-existing issue in the probe error path:
drivers/dma/ste_dma40.c:d40_probe() {
...
dev_err(dev,
"could not register of_dma_controller\n");
goto destroy_cache;
}
dev_info(base->dev, "initialized\n");
return 0; destroy_cache:
if (base->lcla_pool.dma_addr)
dma_unmap_single(base->dev, base->lcla_pool.dma_addr,
SZ_1K * base->num_phy_chans,
DMA_TO_DEVICE);
...
}[Severity: High]
This is a pre-existing issue, but does this error path need a free_irq()?
If a subsequent initialization step fails (e.g., of_dma_controller_register()), the code jumps to destroy_cache and returns an error without freeing the IRQ.
Then devres automatically frees the memory allocated for the d40_base structure.
If an interrupt fires after a probe failure, could d40_handle_interrupt() execute using the freed base pointer?
Finally, I saw a potential out-of-bounds access in the scatterlist preparation:
drivers/dma/ste_dma40.c:d40_prep_sg() {
...
desc = d40_prep_desc(chan, sg_src, sg_len, dma_flags);
if (desc == NULL)
goto unlock;
if (sg_next(&sg_src[sg_len - 1]) == sg_src)
desc->cyclic = true;
...
}[Severity: High]
This is a pre-existing issue, but does this code correctly handle an empty scatterlist?
If a client provides an empty scatterlist where sg_len is 0, does the subtraction sg_len - 1 underflow to UINT_MAX?
Could this lead to d40_prep_desc() successfully returning a zero-length allocation, and then the condition sg_next(&sg_src[UINT_MAX]) triggering a massive out-of-bounds memory read?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
Re: [PATCH v3 17/34] dmaengine: ste_dma40: convert per-channel tasklet to dmaengine BH
In reply to Allen PaisQuoted 7 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>Reviewed-by Linus Walleij <[email protected]>---
Quoted 62 lines
drivers/dma/ste_dma40.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)drivers/dma/ste_dma40.c +5
-9@@ -461,8 +461,6 @@ struct d40_base;* @phy_chan: Pointer to physical channel which this instance runs on. If this * point is NULL, then the channel is not allocated. * @chan: DMA engine handle. -* @tasklet: Tasklet that gets scheduled from interrupt context to complete a -* transfer and call client callback. * @client: Cliented owned descriptor list. * @pending_queue: Submitted jobs, to be issued by issue_pending() * @active: Active descriptor. @@ -489,7 +487,6 @@ struct d40_chan {bool busy;struct d40_phy_res *phy_chan;struct dma_chan chan; -struct tasklet_struct tasklet;struct list_head client;struct list_head pending_queue;struct list_head active;@@ -1587,13 +1584,13 @@ static void dma_tc_handle(struct d40_chan *d40c) } d40c->pending_tx++; -tasklet_schedule (&d40c->tasklet); +dmaengine_schedule_bh (&d40c->chan); } -static void dma_tasklet (struct tasklet_struct *t) +static void dma_tasklet (struct dma_chan *chan) { -struct d40_chan *d40c =from_tasklet (d40c, t, tasklet); + struct d40_chan *d40c = container_of(chan, struct d40_chan, chan);struct d40_desc *d40d;unsigned long flags;bool callback_active;@@ -1641,7 +1638,7 @@ static void dma_tasklet(struct tasklet_struct *t) d40c->pending_tx--;if (d40c->pending_tx) -tasklet_schedule (&d40c->tasklet); +dmaengine_schedule_bh (&d40c->chan);spin_unlock_irqrestore (&d40c->lock, flags);@@ -2815,7 +2812,7 @@ static void __init d40_chan_init(struct d40_base *base, struct dma_device *dma,INIT_LIST_HEAD (&d40c->client);INIT_LIST_HEAD (&d40c->prepare_queue); -tasklet_setup (&d40c->tasklet, dma_tasklet); +dmaengine_init_bh (&d40c->chan, dma_tasklet);list_add_tail (&d40c->chan.device_node, &dma->channels); --2.43.0
PATCH v3 18/34 dmaengine: xgene-dma: wire descriptor cleanup to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/xgene-dma.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/dma/xgene-dma.c +9 -10
@@ -260,7 +260,6 @@ struct xgene_dma_desc_sw {* These descriptors have already had their cleanup actions run. They * are waiting for the ACK bit to be set by the async tx API. * @desc_pool: descriptor pool for DMA operations -* @tasklet: bottom half where all completed descriptors cleans * @tx_ring: transmit ring descriptor that we use to prepare actual * descriptors for further executions * @rx_ring: receive ring descriptor that we use to get completed DMA
@@ -280,7 +279,6 @@ struct xgene_dma_chan {struct list_head ld_running;struct list_head ld_completed;struct dma_pool *desc_pool; -struct tasklet_struct tasklet;struct xgene_dma_ring tx_ring;struct xgene_dma_ring rx_ring; };
@@ -975,9 +973,10 @@ static enum dma_status xgene_dma_tx_status(struct dma_chan *dchan,return dma_cookie_status (dchan, cookie, txstate); } -static void xgene_dma_tasklet_cb (struct tasklet_struct *t) +static void xgene_dma_tasklet_cb (struct dma_chan *c) { -struct xgene_dma_chan *chan =from_tasklet (chan, t, tasklet); + struct xgene_dma_chan *chan = container_of(c, struct xgene_dma_chan, + dma_chan);/* Run all cleanup for descriptors which have been completed */ xgene_dma_cleanup_descriptors (chan);
@@ -999,11 +998,11 @@ static irqreturn_t xgene_dma_chan_ring_isr(int irq, void *id)disable_irq_nosync (chan->rx_irq);/* -* Schedule the tasklet to handle all cleanup of the current +* Schedule the bottom half to handle all cleanup of the current * transaction. It will start a new transaction if there is * one pending. */ -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->dma_chan);return IRQ_HANDLED ; }
@@ -1539,7 +1538,7 @@ static int xgene_dma_async_register(struct xgene_dma *pdma, int id)INIT_LIST_HEAD (&chan->ld_pending);INIT_LIST_HEAD (&chan->ld_running);INIT_LIST_HEAD (&chan->ld_completed); -tasklet_setup (&chan->tasklet, xgene_dma_tasklet_cb); +dmaengine_init_bh (&chan->dma_chan, xgene_dma_tasklet_cb); chan->pending =0 ; chan->desc_pool =NULL ;
@@ -1556,7 +1555,7 @@ static int xgene_dma_async_register(struct xgene_dma *pdma, int id) ret =dma_async_device_register (dma_dev);if (ret) {chan_err (chan,"Failed to register async device %d" , ret); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->dma_chan);return ret; }
@@ -1579,7 +1578,7 @@ static int xgene_dma_init_async(struct xgene_dma *pdma)if (ret) {for (j =0 ; j < i; j++) {dma_async_device_unregister (&pdma->dma_dev[j]); -tasklet_kill (&pdma->chan[j].tasklet); +dmaengine_kill_bh (&pdma->chan[j].dma_chan); }return ret;
@@ -1790,7 +1789,7 @@ static void xgene_dma_remove(struct platform_device *pdev)for (i =0 ; i <XGENE_DMA_MAX_CHANNEL ; i++) { chan = &pdma->chan[i]; -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->dma_chan);xgene_dma_delete_chan_rings (chan); }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 18/34] dmaengine: xgene-dma: wire descriptor cleanup to dmaengine BH
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Pre-existing issues:
- [High] Interrupts are requested and hardware interrupts unmasked before the DMA engine BH is initialized, exposing a race condition.
- [High] Potential self-deadlock in xgene_dma_free_chan_resources due to calling xgene_dma_cleanup_descriptors without disabling softirqs.
- [High] Use-after-free memory corruption in the error handling paths of xgene_dma_prep_xor and xgene_dma_prep_pq.
- [High] Failure to mask interrupts and disable hardware before calling dmaengine_kill_bh() in the probe error path leaves a race window where an interrupt can reschedule the BH, leading to a Use-After-Free.
- [High] The teardown sequence in xgene_dma_remove frees the device IRQs before killing the DMA engine BH, potentially causing enable_irq() to be called on a freed IRQ.
--
--- Patch [18]: [PATCH v3 18/34] dmaengine: xgene-dma: wire descriptor cleanup to dmaengine BH --- commit cdb570000a04c682157da4771610c096505551ac
Author: Allen Pais <[email protected]>
dmaengine: xgene-dma: wire descriptor cleanup to dmaengine BH
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/xgene-dma.c +0
-0
[ ... ]
drivers/dma/xgene-dma.c static enum dma_status xgene_dma_tx_status(struct dma_chan *dchan, · line 983
Quoted 13 lines
drivers/dma/xgene-dma.c +3
-2@@ -976,9 +974,10 @@ static enum dma_status xgene_dma_tx_status(struct dma_chan *dchan,return dma_cookie_status (dchan, cookie, txstate); } -static void xgene_dma_tasklet_cb (struct tasklet_struct *t) +static void xgene_dma_tasklet_cb (struct dma_chan *c) { -struct xgene_dma_chan *chan =from_tasklet (chan, t, tasklet); + struct xgene_dma_chan *chan = container_of(c, struct xgene_dma_chan, + dma_chan);/* Run all cleanup for descriptors which have been completed */ xgene_dma_cleanup_descriptors (chan);
[Severity: High]
This isn't a bug introduced by this patch, but can this lead to a self-deadlock?
Looking at xgene_dma_free_chan_resources(), it calls xgene_dma_cleanup_descriptors() directly from process context, which acquires chan->lock without disabling softirqs:
xgene_dma_free_chan_resources()
xgene_dma_cleanup_descriptors(chan)
spin_lock(&chan->lock);
If a DMA hardware interrupt arrives on the same CPU while this lock is held, the ISR will schedule the BH.
When returning from the hardware interrupt, irq_exit() will process softirqs and attempt to acquire the same chan->lock, deadlocking against the interrupted process context.
[ ... ]
drivers/dma/xgene-dma.c static int xgene_dma_async_register(struct xgene_dma *pdma, int id) · line 1542
Quoted 6 lines
drivers/dma/xgene-dma.c +1
-1@@ -1540,7 +1539,7 @@ static int xgene_dma_async_register(struct xgene_dma *pdma, int id)INIT_LIST_HEAD (&chan->ld_pending);INIT_LIST_HEAD (&chan->ld_running);INIT_LIST_HEAD (&chan->ld_completed); -tasklet_setup (&chan->tasklet, xgene_dma_tasklet_cb); +dmaengine_init_bh (&chan->dma_chan, xgene_dma_tasklet_cb);
[Severity: High]
This isn't a bug introduced by this patch, but is there a race condition during probe where the BH is scheduled before initialization?
In xgene_dma_probe(), interrupts are requested and hardware interrupts are unmasked before xgene_dma_init_async() is called to initialize the BH:
xgene_dma_probe()
ret = xgene_dma_request_irqs(pdma);
...
xgene_dma_init_hw(pdma);
...
ret = xgene_dma_init_async(pdma);
If a pending interrupt fires in this window, the ISR will call dmaengine_schedule_bh() on an uninitialized BH.
This triggers a WARN_ON and fails to queue the BH. Because the ISR disables the IRQ and relies on the BH to re-enable it, the interrupt line will remain permanently disabled.
Quoted 2 lines
drivers/dma/xgene-dma.c +0
-0chan->pending =0 ; chan->desc_pool =NULL ;
[ ... ]
drivers/dma/xgene-dma.c static int xgene_dma_init_async(struct xgene_dma *pdma) · line 1582
Quoted 6 lines
drivers/dma/xgene-dma.c +1
-1@@ -1580,7 +1579,7 @@ static int xgene_dma_init_async(struct xgene_dma *pdma)if (ret) {for (j =0 ; j < i; j++) {dma_async_device_unregister (&pdma->dma_dev[j]); -tasklet_kill (&pdma->chan[j].tasklet); +dmaengine_kill_bh (&pdma->chan[j].dma_chan);
[Severity: High]
This isn't a bug introduced by this patch, but does this error path leave a race window that could result in a use-after-free?
During driver probe, xgene_dma_init_hw() unmasks hardware interrupts. If a subsequent channel registration fails here, dmaengine_kill_bh() is called, but hardware interrupts are not masked.
An incoming interrupt could fire immediately after dmaengine_kill_bh(), causing the ISR to re-queue the BH.
When the probe function then returns an error, the device data structures are freed via devres. When the workqueue subsequently executes the re-queued BH, it will operate on freed memory.
Quoted 3 lines
drivers/dma/xgene-dma.c +0
-0}return ret;
[ ... ]
drivers/dma/xgene-dma.c static void xgene_dma_remove(struct platform_device *pdev) · line 1793
Quoted 6 lines
drivers/dma/xgene-dma.c +1
-1@@ -1791,7 +1790,7 @@ static void xgene_dma_remove(struct platform_device *pdev)for (i =0 ; i <XGENE_DMA_MAX_CHANNEL ; i++) { chan = &pdma->chan[i]; -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->dma_chan);
[Severity: High]
This isn't a bug introduced by this patch, but is the teardown ordering correct here?
In xgene_dma_remove(), xgene_dma_free_irqs() is called to free the interrupt handlers before the loop that flushes the BH work with dmaengine_kill_bh().
If a BH is currently pending, dmaengine_kill_bh() will wait for it to execute. The BH handler xgene_dma_tasklet_cb() unconditionally calls enable_irq(chan->rx_irq).
Because the IRQ has already been freed, calling enable_irq() operates on a torn-down IRQ.
drivers/dma/xgene-dma.c static void xgene_dma_remove(struct platform_device *pdev) · line 1794
Quoted 2 lines
drivers/dma/xgene-dma.c +0
-0xgene_dma_delete_chan_rings (chan); }
[Severity: High]
This isn't a bug introduced by this patch, but is there a use-after-free in the error handling path of xgene_dma_prep_xor() and xgene_dma_prep_pq()?
If descriptor allocation fails during a multi-descriptor transaction, the driver jumps to the fail label and passes the embedded list head of the first descriptor to the cleanup function:
xgene_dma_prep_xor()
fail:
if (!first)
return NULL;
xgene_dma_free_desc_list(chan, &first->tx_list);xgene_dma_free_desc_list() uses list_for_each_entry_safe() to iterate and free elements. On the first iteration, the first descriptor is freed.
However, list_for_each_entry_safe() evaluates the loop increment step at the end of the iteration, which accesses head->next. Since head is &first->tx_list, this reads from the freed first descriptor memory.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
Re: [PATCH v3 18/34] dmaengine: xgene-dma: wire descriptor cleanup to dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 89 lines
drivers/dma/xgene-dma.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/dma/xgene-dma.c +9
-11@@ -260,7 +260,6 @@ struct xgene_dma_desc_sw {* These descriptors have already had their cleanup actions run. They * are waiting for the ACK bit to be set by the async tx API. * @desc_pool: descriptor pool for DMA operations -* @tasklet: bottom half where all completed descriptors cleans * @tx_ring: transmit ring descriptor that we use to prepare actual * descriptors for further executions * @rx_ring: receive ring descriptor that we use to get completed DMA @@ -280,7 +279,6 @@ struct xgene_dma_chan {struct list_head ld_running;struct list_head ld_completed;struct dma_pool *desc_pool; -struct tasklet_struct tasklet;struct xgene_dma_ring tx_ring;struct xgene_dma_ring rx_ring; };@@ -975,9 +973,10 @@ static enum dma_status xgene_dma_tx_status(struct dma_chan *dchan,return dma_cookie_status (dchan, cookie, txstate); } -static void xgene_dma_tasklet_cb (struct tasklet_struct *t) +static void xgene_dma_tasklet_cb (struct dma_chan *c) { -struct xgene_dma_chan *chan =from_tasklet (chan, t, tasklet); + struct xgene_dma_chan *chan = container_of(c, struct xgene_dma_chan, + dma_chan);/* Run all cleanup for descriptors which have been completed */ xgene_dma_cleanup_descriptors (chan);@@ -999,11 +998,11 @@ static irqreturn_t xgene_dma_chan_ring_isr(int irq, void *id)disable_irq_nosync (chan->rx_irq);/* -* Schedule the tasklet to handle all cleanup of the current +* Schedule the bottom half to handle all cleanup of the current * transaction. It will start a new transaction if there is * one pending. */ -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->dma_chan);return IRQ_HANDLED ; }@@ -1539,7 +1538,7 @@ static int xgene_dma_async_register(struct xgene_dma *pdma, int id)INIT_LIST_HEAD (&chan->ld_pending);INIT_LIST_HEAD (&chan->ld_running);INIT_LIST_HEAD (&chan->ld_completed); -tasklet_setup (&chan->tasklet, xgene_dma_tasklet_cb); +dmaengine_init_bh (&chan->dma_chan, xgene_dma_tasklet_cb); chan->pending =0 ; chan->desc_pool =NULL ;@@ -1556,7 +1555,7 @@ static int xgene_dma_async_register(struct xgene_dma *pdma, int id) ret =dma_async_device_register (dma_dev);if (ret) {chan_err (chan,"Failed to register async device %d" , ret); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->dma_chan);return ret; }@@ -1579,7 +1578,7 @@ static int xgene_dma_init_async(struct xgene_dma *pdma)if (ret) {for (j =0 ; j < i; j++) {dma_async_device_unregister (&pdma->dma_dev[j]); -tasklet_kill (&pdma->chan[j].tasklet); +dmaengine_kill_bh (&pdma->chan[j].dma_chan); }return ret;@@ -1790,7 +1789,7 @@ static void xgene_dma_remove(struct platform_device *pdev)for (i =0 ; i <XGENE_DMA_MAX_CHANNEL ; i++) { chan = &pdma->chan[i]; -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->dma_chan);xgene_dma_delete_chan_rings (chan); } --2.43.0
PATCH v3 19/34 dmaengine: xilinx-dma: use dmaengine BH instead of tasklets
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/xilinx/xilinx_dma.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +9 -11
@@ -402,7 +402,6 @@ struct xilinx_dma_tx_descriptor {* @err: Channel has errors * @idle: Check for channel idle * @terminating: Check for channel being synchronized by user -* @tasklet: Cleanup work after irq * @config: Device configuration info * @flush_on_fsync: Flush on Frame sync * @desc_pendingcount: Descriptor pending count
@@ -441,7 +440,6 @@ struct xilinx_dma_chan {bool err;bool idle;bool terminating; -struct tasklet_struct tasklet;struct xilinx_vdma_config config;bool flush_on_fsync;u32 desc_pendingcount;
@@ -1115,11 +1113,12 @@ static void xilinx_dma_chan_desc_cleanup(struct xilinx_dma_chan *chan)/** * xilinx_dma_do_tasklet - Schedule completion tasklet -* @t: Pointer to the Xilinx DMA channel structure +* @c: Pointer to the Xilinx DMA channel structure */ -static void xilinx_dma_do_tasklet (struct tasklet_struct *t) +static void xilinx_dma_do_tasklet (struct dma_chan *c) { -struct xilinx_dma_chan *chan =from_tasklet (chan, t, tasklet); +struct xilinx_dma_chan *chan =container_of (c, + struct xilinx_dma_chan, common);xilinx_dma_chan_desc_cleanup (chan); }
@@ -1898,7 +1897,7 @@ static irqreturn_t xilinx_mcdma_irq_handler(int irq, void *data)spin_unlock (&chan->lock); } -tasklet_hi_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common);return IRQ_HANDLED ; }
@@ -1955,7 +1954,7 @@ static irqreturn_t xilinx_dma_irq_handler(int irq, void *data)spin_unlock (&chan->lock); } -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common);return IRQ_HANDLED ; }
@@ -2654,7 +2653,7 @@ static void xilinx_dma_synchronize(struct dma_chan *dchan) {struct xilinx_dma_chan *chan =to_xilinx_chan (dchan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->common); }/**
@@ -2745,7 +2744,7 @@ static void xilinx_dma_chan_remove(struct xilinx_dma_chan *chan)if (chan->irq >0 )free_irq (chan->irq, chan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->common);list_del (&chan->common.device_node); }
@@ -3075,8 +3074,7 @@ static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev, str_enabled_disabled(chan->has_sg)); } -/* Initialize the tasklet */ -tasklet_setup (&chan->tasklet, xilinx_dma_do_tasklet); +dmaengine_init_bh (&chan->common, xilinx_dma_do_tasklet);/* * Initialize the DMA channel and add it to the DMA engine channels
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 19/34] dmaengine: xilinx-dma: use dmaengine BH instead of tasklets
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Shared IRQ handler for MCDMA cross-schedules bottom halves for improperly masked removed channels, causing UAF.
- [High] Early IRQ request exposes uninitialized channel structures to premature interrupts, causing NULL pointer dereferences.
- [High] Unvalidated channel ID read from hardware causes an out-of-bounds array access.
- [High] Assuming all indexed channels in xdev->chan are fully populated causes a NULL pointer dereference for unprobed channels.
- [High] Missing bounds check on the dma-channels device tree property allows an out-of-bounds heap write. --
--- Patch [19]: [PATCH v3 19/34] dmaengine: xilinx-dma: use dmaengine BH instead of tasklets --- commit 2a691fa5fbfdf533a9f83a643b93d18aff3e2930
Author: Allen Pais <[email protected]>
Subject: dmaengine: xilinx-dma: use dmaengine BH instead of tasklets
This patch replaces per-channel tasklets with the shared dmaengine bottom half (BH) helper mechanism. It transitions the tasklet cleanup handler to run under the dmaengine's scheduling and teardown framework while continuing to execute in softirq context.
Quoted 4 lines
drivers/dma/xilinx/xilinx_dma.c +0
-0
[ ... ]
drivers/dma/xilinx/xilinx_dma.c static irqreturn_t xilinx_mcdma_irq_handler(int irq, void *data) · line 1902
Quoted 8 lines
drivers/dma/xilinx/xilinx_dma.c +1
-1@@ -1898,7 +1897,7 @@ static irqreturn_t xilinx_mcdma_irq_handler(int irq, void *data)spin_unlock (&chan->lock); } -tasklet_hi_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common);return IRQ_HANDLED ; }
[Severity: High]
This isn't a bug introduced by this patch, but looking at how xilinx_mcdma_irq_handler() computes the channel offset earlier in this function:
chan_sermask = dma_ctrl_read(chan, ser_offset);
chan_id = ffs(chan_sermask);
...
chan_offset = chan_offset + (chan_id - 1);
chan = chan->xdev->chan[chan_offset];Can a faulty hardware device or emulator asserting bits in the upper half of chan_sermask cause an out-of-bounds access? The array xdev->chan is statically sized to XILINX_MCDMA_MAX_CHANS_PER_DEVICE (32), but chan_offset could potentially reach up to 47 for DEV_TO_MEM transfers.
[Severity: High]
This is also a pre-existing issue, but immediately after fetching the channel pointer:
chan = chan->xdev->chan[chan_offset];
status = dma_ctrl_read(chan, XILINX_MCDMA_CHAN_SR_OFFSET(chan->tdest));If the device tree did not define all channels or some failed to probe, could the xdev->chan array contain NULL pointers? If the hardware asserts interrupts for unpopulated channels, it seems this would cause a NULL pointer dereference.
[ ... ]
drivers/dma/xilinx/xilinx_dma.c static void xilinx_dma_chan_remove(struct xilinx_dma_chan *chan) · line 2750
Quoted 9 lines
drivers/dma/xilinx/xilinx_dma.c +1
-1@@ -2745,7 +2744,7 @@ static void xilinx_dma_chan_remove(struct xilinx_dma_chan *chan)if (chan->irq >0 )free_irq (chan->irq, chan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->common);list_del (&chan->common.device_node); }
[Severity: Critical]
This isn't a bug introduced by this patch, but looking at the teardown sequence in xilinx_dma_chan_remove():
dma_ctrl_clr(chan, XILINX_DMA_REG_DMACR,
XILINX_DMA_DMAXR_ALL_IRQ_MASK);Does this write to the correct register for MCDMA channels? It appears to write to XILINX_DMA_REG_DMACR instead of an MCDMA-specific register like XILINX_MCDMA_CHAN_CR_OFFSET.
If the MCDMA hardware interrupts remain enabled, and the shared IRQ line fires after this channel structure is freed, couldn't the shared xilinx_mcdma_irq_handler() fetch this freed channel from the uncleared xdev->chan array and call dmaengine_schedule_bh() on freed memory?
[ ... ]
drivers/dma/xilinx/xilinx_dma.c static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev, · line 3080
Quoted 10 lines
drivers/dma/xilinx/xilinx_dma.c +1
-2@@ -3075,8 +3074,7 @@ static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev, str_enabled_disabled(chan->has_sg)); } -/* Initialize the tasklet */ -tasklet_setup (&chan->tasklet, xilinx_dma_do_tasklet); +dmaengine_init_bh (&chan->common, xilinx_dma_do_tasklet);/* * Initialize the DMA channel and add it to the DMA engine channels
[Severity: High]
This isn't a bug introduced by this patch, but earlier in xilinx_dma_chan_probe(), request_irq() is called before critical function pointers like chan->start_transfer are initialized:
err = request_irq(chan->irq, xdev->dma_config->irq_handler,
IRQF_SHARED, "xilinx-dma-controller", chan);If a shared interrupt fires immediately (or if there is pending hardware state), the handler xilinx_dma_irq_handler() will execute and might unconditionally call chan->start_transfer(chan). Could this cause a NULL pointer dereference since start_transfer is populated after request_irq()?
[Severity: High]
This is also a pre-existing issue, but further down in xilinx_dma_chan_probe():
xdev->chan[chan->id] = chan;
This relies on chan->id, which is incremented based on the loop in xilinx_dma_child_probe():
ret = of_property_read_u32(node, "dma-channels", &nr_channels);
for (i = 0; i < nr_channels; i++) {
ret = xilinx_dma_chan_probe(xdev, node);Is there any bounds checking to ensure nr_channels or chan->id does not exceed XILINX_MCDMA_MAX_CHANS_PER_DEVICE? Without it, an oversized device tree property might cause an out-of-bounds heap write here.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
Re: [PATCH v3 19/34] dmaengine: xilinx-dma: use dmaengine BH instead of tasklets
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 88 lines
drivers/dma/xilinx/xilinx_dma.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)drivers/dma/xilinx/xilinx_dma.c +9
-12@@ -402,7 +402,6 @@ struct xilinx_dma_tx_descriptor {* @err: Channel has errors * @idle: Check for channel idle * @terminating: Check for channel being synchronized by user -* @tasklet: Cleanup work after irq * @config: Device configuration info * @flush_on_fsync: Flush on Frame sync * @desc_pendingcount: Descriptor pending count @@ -441,7 +440,6 @@ struct xilinx_dma_chan {bool err;bool idle;bool terminating; -struct tasklet_struct tasklet;struct xilinx_vdma_config config;bool flush_on_fsync;u32 desc_pendingcount;@@ -1115,11 +1113,12 @@ static void xilinx_dma_chan_desc_cleanup(struct xilinx_dma_chan *chan)/** * xilinx_dma_do_tasklet - Schedule completion tasklet -* @t: Pointer to the Xilinx DMA channel structure +* @c: Pointer to the Xilinx DMA channel structure */ -static void xilinx_dma_do_tasklet (struct tasklet_struct *t) +static void xilinx_dma_do_tasklet (struct dma_chan *c) { -struct xilinx_dma_chan *chan =from_tasklet (chan, t, tasklet); +struct xilinx_dma_chan *chan =container_of (c, + struct xilinx_dma_chan, common);xilinx_dma_chan_desc_cleanup (chan); }@@ -1898,7 +1897,7 @@ static irqreturn_t xilinx_mcdma_irq_handler(int irq, void *data)spin_unlock (&chan->lock); } -tasklet_hi_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common);return IRQ_HANDLED ; }@@ -1955,7 +1954,7 @@ static irqreturn_t xilinx_dma_irq_handler(int irq, void *data)spin_unlock (&chan->lock); } -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common);return IRQ_HANDLED ; }@@ -2654,7 +2653,7 @@ static void xilinx_dma_synchronize(struct dma_chan *dchan) {struct xilinx_dma_chan *chan =to_xilinx_chan (dchan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->common); }/** @@ -2745,7 +2744,7 @@ static void xilinx_dma_chan_remove(struct xilinx_dma_chan *chan)if (chan->irq >0 )free_irq (chan->irq, chan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->common);list_del (&chan->common.device_node); }@@ -3075,8 +3074,7 @@ static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev, str_enabled_disabled(chan->has_sg)); } -/* Initialize the tasklet */ -tasklet_setup (&chan->tasklet, xilinx_dma_do_tasklet); +dmaengine_init_bh (&chan->common, xilinx_dma_do_tasklet);/* * Initialize the DMA channel and add it to the DMA engine channels -- 2.43.0
PATCH v3 20/34 dmaengine: xilinx-dpdma: kill vchan BH on remove
In reply to Allen Paisvirt-dma now dispatches completion callbacks through per-channel BH work. Cancel that work when removing a channel, while retaining the driver's separate error-handling tasklet.
--- drivers/dma/xilinx/xilinx_dpdma.c | 1 + 1 file changed, 1 insertion(+)
drivers/dma/xilinx/xilinx_dpdma.c +1 -0
@@ -1685,6 +1685,7 @@ static void xilinx_dpdma_chan_remove(struct xilinx_dpdma_chan *chan)return ;tasklet_kill (&chan->err_task); +dmaengine_kill_bh (&chan->vchan.chan);list_del (&chan->vchan.chan.device_node); }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 20/34] dmaengine: xilinx-dpdma: kill vchan BH on remove
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The device AXI clock is disabled before tasklets and BHs are explicitly killed in the remove path. This allows pending tasklets or BH work to execute and access hardware registers while the clock is off, causing fatal AXI bus errors. --
--- Patch [20]: [PATCH v3 20/34] dmaengine: xilinx-dpdma: kill vchan BH on remove --- commit cd30e3f8d0e3620da3deb8ffdbd41901ce171ab7
Author: Allen Pais <[email protected]>
dmaengine: xilinx-dpdma: kill vchan BH on remove
This commit modifies the xilinx-dpdma driver to cancel the virt-dma per-channel BH work when removing a channel. It adds a call to dmaengine_kill_bh() to ensure the BH is killed before the channel is removed, alongside the existing tasklet cleanup.
drivers/dma/xilinx/xilinx_dpdma.c static void xilinx_dpdma_chan_remove(struct xilinx_dpdma_chan *chan) · line 1688
Quoted 9 lines
drivers/dma/xilinx/xilinx_dpdma.c +1
-0@@ -1685,6 +1685,7 @@ static void xilinx_dpdma_chan_remove(struct xilinx_dpdma_chan *chan)return ;tasklet_kill (&chan->err_task); +dmaengine_kill_bh (&chan->vchan.chan);
[Severity: High]
This is a pre-existing issue, but could waiting for the BH or tasklet to finish here trigger an AXI bus fault?
In xilinx_dpdma_remove(), the AXI clock is disabled before the driver iterates over the channels to remove them:
drivers/dma/xilinx/xilinx_dpdma.c:xilinx_dpdma_remove() {
...
clk_disable_unprepare(xdev->axi_clk);
for (i = 0; i < ARRAY_SIZE(xdev->chan); i++)
xilinx_dpdma_chan_remove(xdev->chan[i]);
...
}If a tasklet like chan->err_task or a vchan BH was scheduled by the hardirq just before the IRQ is freed, it could execute while the clock is already disabled.
Functions like xilinx_dpdma_chan_err_task() read hardware registers via xilinx_dpdma_chan_poll_no_ostand(). Does accessing these memory-mapped registers without the required clock cause a system hang or panic?
Would it make sense to disable the AXI clock only after all channels have been removed and their tasklets and BHs killed?
Quoted 3 lines
drivers/dma/xilinx/xilinx_dpdma.c +0
-0list_del (&chan->vchan.chan.device_node); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
Re: [PATCH v3 20/34] dmaengine: xilinx-dpdma: kill vchan BH on remove
In reply to Allen PaisQuoted 6 lines · Allen Pais
virt-dma now dispatches completion callbacks through per-channel BH work. Cancel that work when removing a channel, while retaining the driver's separate error-handling tasklet.
Signed-off-by Allen Pais <[email protected]>---
Quoted 18 lines
drivers/dma/xilinx/xilinx_dpdma.c | 1 + 1 file changed, 1 insertion(+)drivers/dma/xilinx/xilinx_dpdma.c +1
-1@@ -1685,6 +1685,7 @@ static void xilinx_dpdma_chan_remove(struct xilinx_dpdma_chan *chan)return ;tasklet_kill (&chan->err_task); +dmaengine_kill_bh (&chan->vchan.chan);list_del (&chan->vchan.chan.device_node); } --2.43.0
PATCH v3 21/34 dmaengine: zynqmp-dma: switch completion tasklet to dmaengine BH
In reply to Allen PaisReplace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
--- drivers/dma/xilinx/zynqmp_dma.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/dma/xilinx/zynqmp_dma.c +9 -10
@@ -207,7 +207,6 @@ struct zynqmp_dma_desc_sw {* @dev: The dma device * @irq: Channel IRQ * @is_dmacoherent: Tells whether dma operations are coherent or not -* @tasklet: Cleanup work after irq * @idle : Channel status; * @desc_size: Size of the low level descriptor * @err: Channel has errors
@@ -232,7 +231,6 @@ struct zynqmp_dma_chan {struct device *dev;int irq;bool is_dmacoherent; -struct tasklet_struct tasklet;bool idle;size_t desc_size;bool err;
@@ -735,7 +733,7 @@ static irqreturn_t zynqmp_dma_irq_handler(int irq, void *data)writel (isr, chan->regs +ZYNQMP_DMA_ISR );if (status &ZYNQMP_DMA_INT_DONE ) { -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common); ret =IRQ_HANDLED ; }
@@ -744,7 +742,7 @@ static irqreturn_t zynqmp_dma_irq_handler(int irq, void *data)if (status &ZYNQMP_DMA_INT_ERR ) { chan->err = true; -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common);dev_err (chan->dev,"Channel %p has errors\n" , chan); ret =IRQ_HANDLED ; }
@@ -760,11 +758,12 @@ static irqreturn_t zynqmp_dma_irq_handler(int irq, void *data)/** * zynqmp_dma_do_tasklet - Schedule completion tasklet -* @t: Pointer to the ZynqMP DMA channel structure +* @c: Pointer to the ZynqMP DMA channel structure */ -static void zynqmp_dma_do_tasklet (struct tasklet_struct *t) +static void zynqmp_dma_do_tasklet (struct dma_chan *c) { -struct zynqmp_dma_chan *chan =from_tasklet (chan, t, tasklet); +struct zynqmp_dma_chan *chan =container_of (c, + struct zynqmp_dma_chan, common);u32 count;unsigned long irqflags;
@@ -815,7 +814,7 @@ static void zynqmp_dma_synchronize(struct dma_chan *dchan) {struct zynqmp_dma_chan *chan =to_chan (dchan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->common); }/**
@@ -887,7 +886,7 @@ static void zynqmp_dma_chan_remove(struct zynqmp_dma_chan *chan)if (chan->irq)devm_free_irq (chan->zdev->dev, chan->irq, chan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->common);list_del (&chan->common.device_node); }
@@ -937,7 +936,7 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev, chan->is_dmacoherent =of_property_read_bool (node,"dma-coherent" ); zdev->chan = chan; -tasklet_setup (&chan->tasklet, zynqmp_dma_do_tasklet); +dmaengine_init_bh (&chan->common, zynqmp_dma_do_tasklet);spin_lock_init (&chan->lock);INIT_LIST_HEAD (&chan->active_list);INIT_LIST_HEAD (&chan->pending_list);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 21/34] dmaengine: zynqmp-dma: switch completion tasklet to dmaengine BH
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Dropping the channel lock during list iteration allows concurrent list modifications, leading to an infinite loop and severe memory corruption.
- [High] Pre-existing PM runtime reference count leak in the probe error path.
--
--- Patch [21]: [PATCH v3 21/34] dmaengine: zynqmp-dma: switch completion tasklet to dmaengine BH --- commit 31456cd82dd8bdc7d99216cfcc194b9aecb47fb3
Author: Allen Pais <[email protected]>
dmaengine: zynqmp-dma: switch completion tasklet to dmaengine BH
This commit replaces the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
drivers/dma/xilinx/zynqmp_dma.c
Quoted 4 lines
drivers/dma/xilinx/zynqmp_dma.c +0
-0
[ ... ]
[Severity: High]
This is a pre-existing issue, but I noticed a potential regression in the probe error path.
In zynqmp_dma_probe(), if pm_runtime_resume_and_get() succeeds, it increments the usage count. If a subsequent initialization step like zynqmp_dma_chan_probe() fails, the execution jumps to err_disable_pm:
drivers/dma/xilinx/zynqmp_dma.c:zynqmp_dma_probe() {
...
ret = pm_runtime_resume_and_get(zdev->dev);
...
ret = zynqmp_dma_chan_probe(zdev, pdev);
if (ret) {
dev_err_probe(&pdev->dev, ret, "Probing channel failed\n");
goto err_disable_pm;
}
...
err_disable_pm:
if (!pm_runtime_enabled(zdev->dev))
zynqmp_dma_runtime_suspend(zdev->dev);
pm_runtime_disable(zdev->dev);
return ret;
}Because pm_runtime_enabled(zdev->dev) is true, it skips calling zynqmp_dma_runtime_suspend(zdev->dev). The function then calls pm_runtime_disable() and returns the error.
Does this regression miss calling pm_runtime_put_noidle() to balance the usage count or taking any action to power off the device?
[Severity: Critical]
This is a pre-existing issue, but I noticed a regression when iterating over the done list.
In zynqmp_dma_chan_desc_cleanup(), the code iterates over chan->done_list using list_for_each_entry_safe(). For each descriptor, it temporarily drops chan->lock to invoke the client callback:
drivers/dma/xilinx/zynqmp_dma.c:zynqmp_dma_chan_desc_cleanup() {
...
list_for_each_entry_safe(desc, next, &chan->done_list, node) {
struct dmaengine_desc_callback cb;
dmaengine_desc_get_callback(&desc->async_tx, &cb);
if (dmaengine_desc_callback_valid(&cb)) {
spin_unlock_irqrestore(&chan->lock, irqflags);
dmaengine_desc_callback_invoke(&cb, NULL);
spin_lock_irqsave(&chan->lock, irqflags);
}
...
}If a concurrent thread or the callback itself calls dmaengine_terminate_all(), zynqmp_dma_free_descriptors() will execute. This acquires the lock and unconditionally moves all descriptors from done_list (including the cached next descriptor) to free_list.
When the callback completes, the loop resumes with desc = next. Because next is now linked in free_list, the loop termination condition &desc->node != &chan->done_list will never be met.
Could this regression cause an infinite loop and arbitrary memory corruption as it iterates off the end of free_list?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
Re: [PATCH v3 21/34] dmaengine: zynqmp-dma: switch completion tasklet to dmaengine BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the per-channel tasklet with the shared dmaengine BH helper. The handler continues to run in softirq context while dmaengine owns the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>---
Quoted 87 lines
drivers/dma/xilinx/zynqmp_dma.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/dma/xilinx/zynqmp_dma.c +9
-11@@ -207,7 +207,6 @@ struct zynqmp_dma_desc_sw {* @dev: The dma device * @irq: Channel IRQ * @is_dmacoherent: Tells whether dma operations are coherent or not -* @tasklet: Cleanup work after irq * @idle : Channel status; * @desc_size: Size of the low level descriptor * @err: Channel has errors @@ -232,7 +231,6 @@ struct zynqmp_dma_chan {struct device *dev;int irq;bool is_dmacoherent; -struct tasklet_struct tasklet;bool idle;size_t desc_size;bool err;@@ -735,7 +733,7 @@ static irqreturn_t zynqmp_dma_irq_handler(int irq, void *data)writel (isr, chan->regs +ZYNQMP_DMA_ISR );if (status &ZYNQMP_DMA_INT_DONE ) { -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common); ret =IRQ_HANDLED ; }@@ -744,7 +742,7 @@ static irqreturn_t zynqmp_dma_irq_handler(int irq, void *data)if (status &ZYNQMP_DMA_INT_ERR ) { chan->err = true; -tasklet_schedule (&chan->tasklet); +dmaengine_schedule_bh (&chan->common);dev_err (chan->dev,"Channel %p has errors\n" , chan); ret =IRQ_HANDLED ; }@@ -760,11 +758,12 @@ static irqreturn_t zynqmp_dma_irq_handler(int irq, void *data)/** * zynqmp_dma_do_tasklet - Schedule completion tasklet -* @t: Pointer to the ZynqMP DMA channel structure +* @c: Pointer to the ZynqMP DMA channel structure */ -static void zynqmp_dma_do_tasklet (struct tasklet_struct *t) +static void zynqmp_dma_do_tasklet (struct dma_chan *c) { -struct zynqmp_dma_chan *chan =from_tasklet (chan, t, tasklet); +struct zynqmp_dma_chan *chan =container_of (c, + struct zynqmp_dma_chan, common);u32 count;unsigned long irqflags;@@ -815,7 +814,7 @@ static void zynqmp_dma_synchronize(struct dma_chan *dchan) {struct zynqmp_dma_chan *chan =to_chan (dchan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->common); }/** @@ -887,7 +886,7 @@ static void zynqmp_dma_chan_remove(struct zynqmp_dma_chan *chan)if (chan->irq)devm_free_irq (chan->zdev->dev, chan->irq, chan); -tasklet_kill (&chan->tasklet); +dmaengine_kill_bh (&chan->common);list_del (&chan->common.device_node); }@@ -937,7 +936,7 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev, chan->is_dmacoherent =of_property_read_bool (node,"dma-coherent" ); zdev->chan = chan; -tasklet_setup (&chan->tasklet, zynqmp_dma_do_tasklet); +dmaengine_init_bh (&chan->common, zynqmp_dma_do_tasklet);spin_lock_init (&chan->lock);INIT_LIST_HEAD (&chan->active_list);INIT_LIST_HEAD (&chan->pending_list); --2.43.0
PATCH v3 22/34 dmaengine: tegra20-apb: use channel BH helpers
In reply to Allen PaisSwitch the per-channel tasklet to dmaengine_*_bh so completion handling runs through the shared per-channel deferral mechanism.
--- drivers/dma/tegra20-apb-dma.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/dma/tegra20-apb-dma.c +9 -9
@@ -194,9 +194,8 @@ struct tegra_dma_channel {struct list_head free_dma_desc;struct list_head cb_desc; -/* ISR handler and tasklet for bottom half of isr handling */ +/* ISR handler for bottom-half processing */ dma_isr_handler isr_handler; -struct tasklet_struct tasklet;/* Channel-slave specific configuration */ unsigned int slave_id;
@@ -632,9 +631,10 @@ static void handle_cont_sngl_cycle_dma_done(struct tegra_dma_channel *tdc, } } -static void tegra_dma_tasklet (struct tasklet_struct *t) +static void tegra_dma_tasklet (struct dma_chan *chan) { -struct tegra_dma_channel *tdc =from_tasklet (tdc, t, tasklet); + struct tegra_dma_channel *tdc = container_of(chan, struct tegra_dma_channel, + dma_chan);struct dmaengine_desc_callback cb;struct tegra_dma_desc *dma_desc;unsigned int cb_count;
@@ -670,7 +670,7 @@ static irqreturn_t tegra_dma_isr(int irq, void *dev_id)if (status &TEGRA_APBDMA_STATUS_ISE_EOC ) {tdc_write (tdc,TEGRA_APBDMA_CHAN_STATUS , status); tdc->isr_handler (tdc, false); -tasklet_schedule (&tdc->tasklet); +dmaengine_schedule_bh (&tdc->dma_chan);wake_up_all (&tdc->wq);spin_unlock (&tdc->lock);return IRQ_HANDLED ;
@@ -819,7 +819,7 @@ static void tegra_dma_synchronize(struct dma_chan *dc)*/ wait_event (tdc->wq,tegra_dma_eoc_interrupt_deasserted (tdc)); -tasklet_kill (&tdc->tasklet); +dmaengine_kill_bh (&tdc->dma_chan);pm_runtime_put (tdc->tdma->dev); }
@@ -1317,7 +1317,7 @@ static void tegra_dma_free_chan_resources(struct dma_chan *dc)dev_dbg (tdc2dev (tdc),"Freeing channel %d\n" , tdc->id);tegra_dma_terminate_all (dc); -tasklet_kill (&tdc->tasklet); +dmaengine_kill_bh (&tdc->dma_chan);list_splice_init (&tdc->pending_sg_req, &sg_req_list);list_splice_init (&tdc->free_sg_req, &sg_req_list);
@@ -1511,7 +1511,7 @@ static int tegra_dma_probe(struct platform_device *pdev) tdc->id = i; tdc->slave_id =TEGRA_APBDMA_SLAVE_ID_INVALID ; -tasklet_setup (&tdc->tasklet, tegra_dma_tasklet); +dmaengine_init_bh (&tdc->dma_chan, tegra_dma_tasklet);spin_lock_init (&tdc->lock);init_waitqueue_head (&tdc->wq);
@@ -1617,7 +1617,7 @@ static int __maybe_unused tegra_dma_dev_suspend(struct device *dev)for (i =0 ; i < tdma->chip_data->nr_channels; i++) {struct tegra_dma_channel *tdc = &tdma->channels[i]; -tasklet_kill (&tdc->tasklet); +dmaengine_kill_bh (&tdc->dma_chan);spin_lock_irqsave (&tdc->lock, flags); busy = tdc->busy;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 22/34] dmaengine: tegra20-apb: use channel BH helpers
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The channel interrupt is requested before critical channel structures (spinlock, waitqueue, and bottom-half work) are initialized. --
--- Patch [22]: [PATCH v3 22/34] dmaengine: tegra20-apb: use channel BH helpers --- commit 4e26e9a252e11cfe82fed93039f39258debd48f7
Author: Allen Pais <[email protected]>
dmaengine: tegra20-apb: use channel BH helpers
Switch the per-channel tasklet to dmaengine_*_bh so completion handling runs through the shared per-channel deferral mechanism.
Quoted 4 lines
drivers/dma/tegra20-apb-dma.c +0
-0
[ ... ]
drivers/dma/tegra20-apb-dma.c static int tegra_dma_probe(struct platform_device *pdev) · line 1514
Quoted 6 lines
drivers/dma/tegra20-apb-dma.c +1
-1@@ -1511,7 +1511,7 @@ static int tegra_dma_probe(struct platform_device *pdev) tdc->id = i; tdc->slave_id =TEGRA_APBDMA_SLAVE_ID_INVALID ; -tasklet_setup (&tdc->tasklet, tegra_dma_tasklet); +dmaengine_init_bh (&tdc->dma_chan, tegra_dma_tasklet);
[Severity: High]
This is a pre-existing issue, but I noticed a potential race condition here during initialization.
In tegra_dma_probe(), the interrupt is requested and enabled earlier in the channel initialization loop before these critical structures are set up:
drivers/dma/tegra20-apb-dma.c:tegra_dma_probe() {
...
ret = devm_request_irq(&pdev->dev, irq, tegra_dma_isr, 0,
tdc->name, tdc);
...
}Could an early interrupt fire before dmaengine_init_bh(), spin_lock_init(), and init_waitqueue_head() are called?
If the bootloader leaves the DMA controller with a pending interrupt, or a spurious interrupt occurs immediately after devm_request_irq() enables the IRQ line, the ISR might execute before these initializations.
Would this result in acquiring an uninitialized spinlock, triggering a WARN when scheduling the uninitialized bottom-half work, or causing a kernel panic by dereferencing a NULL tdc->isr_handler?
Quoted 3 lines
drivers/dma/tegra20-apb-dma.c +0
-0spin_lock_init (&tdc->lock);init_waitqueue_head (&tdc->wq);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
PATCH v3 23/34 dmaengine: timb_dma: route callbacks via channel BH
In reply to Allen PaisSchedule per-channel BH work for completions so callbacks run through the dma_chan deferral mechanism while keeping the controller tasklet for IRQ handling.
--- drivers/dma/timb_dma.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/dma/timb_dma.c +16 -5
@@ -438,6 +438,8 @@ static void td_free_chan_resources(struct dma_chan *chan)dev_dbg (chan2dev (chan),"%s: Entry\n" , __func__); +dmaengine_kill_bh (&td_chan->chan); +/* check that all descriptors are free */ BUG_ON (!list_empty (&td_chan->active_list));BUG_ON (!list_empty (&td_chan->queue));
@@ -580,17 +582,25 @@ static void td_tasklet(struct tasklet_struct *t)for (i =0 ; i < td->dma.chancnt; i++)if (ipr & (1 << i)) {struct timb_dma_chan *td_chan = td->channels + i; -spin_lock (&td_chan->lock); -__td_finish (td_chan); -if (!list_empty (&td_chan->queue)) -__td_start_next (td_chan); -spin_unlock (&td_chan->lock); +dmaengine_schedule_bh (&td_chan->chan); } ier =__td_ier_mask (td);iowrite32 (ier, td->membase +TIMBDMA_IER ); } +static void timb_dma_chan_bh (struct dma_chan *chan) +{ + struct timb_dma_chan *td_chan = container_of(chan, struct timb_dma_chan, + chan); + +spin_lock (&td_chan->lock); +__td_finish (td_chan); +if (!list_empty (&td_chan->queue)) +__td_start_next (td_chan); +spin_unlock (&td_chan->lock); +} +static irqreturn_t td_irq (int irq,void *devid) {
@@ -697,6 +707,7 @@ static int td_probe(struct platform_device *pdev)INIT_LIST_HEAD (&td_chan->active_list);INIT_LIST_HEAD (&td_chan->queue);INIT_LIST_HEAD (&td_chan->free_list); +dmaengine_init_bh (&td_chan->chan, timb_dma_chan_bh); td_chan->descs = pchan->descriptors; td_chan->desc_elems = pchan->descriptor_elements;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 23/34] dmaengine: timb_dma: route callbacks via channel BH
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
New issues:
- [High] Data race and out-of-bounds read in __td_ier_mask introduced by asynchronous BH
- [High] Logic Error leading to permanent device hang for non-interrupt descriptors
- [High] Use-After-Free of td structure during driver teardown
Pre-existing issues:
- [High] Unsynchronized read-modify-write on global TIMBDMA_IER register
- [High] TOCTOU race causing premature descriptor completion --
--- Patch [23]: [PATCH v3 23/34] dmaengine: timb_dma: route callbacks via channel BH --- commit a7e38226e52fe6d87f6d1e2cd0a0ee22fbd778a9
Author: Allen Pais <[email protected]>
dmaengine: timb_dma: route callbacks via channel BH
This commit introduces a per-channel BH workqueue for completions so callbacks run through the dma_chan deferral mechanism while keeping the controller tasklet for IRQ handling.
Quoted 4 lines
drivers/dma/timb_dma.c +0
-0
[ ... ]
drivers/dma/timb_dma.c static void td_tasklet(struct tasklet_struct *t) · line 586
Quoted 11 lines
drivers/dma/timb_dma.c +1
-5@@ -580,17 +582,25 @@ static void td_tasklet(struct tasklet_struct *t)for (i =0 ; i < td->dma.chancnt; i++)if (ipr & (1 << i)) {struct timb_dma_chan *td_chan = td->channels + i; -spin_lock (&td_chan->lock); -__td_finish (td_chan); -if (!list_empty (&td_chan->queue)) -__td_start_next (td_chan); -spin_unlock (&td_chan->lock); +dmaengine_schedule_bh (&td_chan->chan); }
[Severity: High]
This is a pre-existing issue, but does the lockless caching of the completion event lead to a time-of-check to time-of-use race?
The td_tasklet() caches the completion status locklessly into the ipr variable before this loop. If td_issue_pending() executes concurrently, processes the real completion, and starts a new transfer, would the subsequent lock acquisition by the BH unconditionally pop the active descriptor via __td_finish() while the hardware is still actively processing the new transfer?
drivers/dma/timb_dma.c static void td_tasklet(struct tasklet_struct *t) · line 590
Quoted 4 lines
drivers/dma/timb_dma.c +0
-0ier =__td_ier_mask (td);iowrite32 (ier, td->membase +TIMBDMA_IER ); }
[Severity: High]
Does this sequence result in a permanent hardware hang regression for non-interrupt descriptors?
The tasklet schedules the BH but then immediately recalculates the hardware IER register using the stale ongoing = true state, which leaks the interrupt enable mask.
When the BH later completes the descriptor in __td_finish() by setting ongoing = false, it never updates IER. If a subsequent non-interrupt descriptor is submitted, might it trigger a spurious hardware interrupt that the tasklet drops, preventing the BH from ever being scheduled and hanging the channel?
[Severity: High]
Could the new asynchronous BH introduce a data race regression with __td_ier_mask()?
By deferring __td_finish() to a workqueue, the driver can now mutate active_list concurrently with the tasklet's execution of __td_ier_mask() above. If a concurrent list_move() in the BH sets the next pointer to the list head itself:
drivers/dma/timb_dma.c:__td_ier_mask() {
...
if (td_chan->ongoing) {
struct timb_dma_desc *td_desc =
list_entry(td_chan->active_list.next,
struct timb_dma_desc, desc_node);
if (td_desc->interrupt)
...
}Would the lockless __td_ier_mask() cast the list head to a descriptor and read an out-of-bounds interrupt field?
[ ... ]
drivers/dma/timb_dma.c static int td_probe(struct platform_device *pdev) · line 710
Quoted 5 lines
drivers/dma/timb_dma.c +1
-0@@ -697,6 +707,7 @@ static int td_probe(struct platform_device *pdev)INIT_LIST_HEAD (&td_chan->active_list);INIT_LIST_HEAD (&td_chan->queue);INIT_LIST_HEAD (&td_chan->free_list); +dmaengine_init_bh (&td_chan->chan, timb_dma_chan_bh);
[Severity: High]
Does the driver properly terminate these newly introduced channel BH workqueues during driver teardown to prevent a use-after-free regression?
While td_free_chan_resources() kills the BH, if a driver unbind occurs immediately after a transfer finishes via td_remove(), the td object is freed without calling dmaengine_kill_bh():
drivers/dma/timb_dma.c:td_remove() {
...
tasklet_kill(&td->tasklet);
iounmap(td->membase);
kfree(td);
...
}Could the pending system workqueue then execute timb_dma_chan_bh() on the freed memory to acquire the spinlock?
[Severity: High]
This isn't a bug introduced by this patch, but is there an unsynchronized read-modify-write on the global TIMBDMA_IER register?
Concurrent execution of td_tx_submit() on multiple channels appears to modify a shared hardware register protected only by a local per-channel lock:
drivers/dma/timb_dma.c:__td_enable_chan_irq() {
...
ier = ioread32(td->membase + TIMBDMA_IER);
ier |= 1 << id;
iowrite32(ier, td->membase + TIMBDMA_IER);
...
}Could this permanently drop interrupt masks for racing channels and stall their operation?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
Re: [PATCH v3 23/34] dmaengine: timb_dma: route callbacks via channel BH
In reply to Allen PaisQuoted 6 lines · Allen Pais
Schedule per-channel BH work for completions so callbacks run through the
dma_chandeferral mechanism while keeping the controller tasklet for IRQ handling.Signed-off-by Allen Pais <[email protected]>---
Quoted 58 lines
drivers/dma/timb_dma.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/dma/timb_dma.c +16
-6@@ -438,6 +438,8 @@ static void td_free_chan_resources(struct dma_chan *chan)dev_dbg (chan2dev (chan),"%s: Entry\n" , __func__); +dmaengine_kill_bh (&td_chan->chan); +/* check that all descriptors are free */ BUG_ON (!list_empty (&td_chan->active_list));BUG_ON (!list_empty (&td_chan->queue));@@ -580,17 +582,25 @@ static void td_tasklet(struct tasklet_struct *t)for (i =0 ; i < td->dma.chancnt; i++)if (ipr & (1 << i)) {struct timb_dma_chan *td_chan = td->channels + i; -spin_lock (&td_chan->lock); -__td_finish (td_chan); -if (!list_empty (&td_chan->queue)) -__td_start_next (td_chan); -spin_unlock (&td_chan->lock); +dmaengine_schedule_bh (&td_chan->chan); } ier =__td_ier_mask (td);iowrite32 (ier, td->membase +TIMBDMA_IER ); } +static void timb_dma_chan_bh (struct dma_chan *chan) +{ + struct timb_dma_chan *td_chan = container_of(chan, struct timb_dma_chan, + chan); + +spin_lock (&td_chan->lock); +__td_finish (td_chan); +if (!list_empty (&td_chan->queue)) +__td_start_next (td_chan); +spin_unlock (&td_chan->lock); +} +static irqreturn_t td_irq (int irq,void *devid) {@@ -697,6 +707,7 @@ static int td_probe(struct platform_device *pdev)INIT_LIST_HEAD (&td_chan->active_list);INIT_LIST_HEAD (&td_chan->queue);INIT_LIST_HEAD (&td_chan->free_list); +dmaengine_init_bh (&td_chan->chan, timb_dma_chan_bh); td_chan->descs = pchan->descriptors; td_chan->desc_elems = pchan->descriptor_elements; --2.43.0
PATCH v3 24/34 dmaengine: txx9dmac: route callbacks via channel BH
In reply to Allen PaisUse the per-channel BH helpers for descriptor completion handling and schedule per-channel work from both channel and controller IRQ paths.
--- drivers/dma/txx9dmac.c | 12 ++++++------ drivers/dma/txx9dmac.h | 1 - 2 files changed, 6 insertions(+), 7 deletions(-)
drivers/dma/txx9dmac.c +6 -6
@@ -601,13 +601,13 @@ static void txx9dmac_scan_descriptors(struct txx9dmac_chan *dc) } } -static void txx9dmac_chan_tasklet (struct tasklet_struct *t) +static void txx9dmac_chan_tasklet (struct dma_chan *chan) {int irq;u32 csr;struct txx9dmac_chan *dc; - dc =from_tasklet (dc, t, tasklet); + dc = container_of(chan, struct txx9dmac_chan, chan); csr =channel_readl (dc,CSR );dev_vdbg (chan2dev (&dc->chan),"tasklet: status=%x\n" , csr);
@@ -628,7 +628,7 @@ static irqreturn_t txx9dmac_chan_interrupt(int irq, void *dev_id)dev_vdbg (chan2dev (&dc->chan),"interrupt: status=%#x\n" ,channel_readl (dc,CSR )); -tasklet_schedule (&dc->tasklet); +dmaengine_schedule_bh (&dc->chan);/* * Just disable the interrupts. We'll turn them back on in the * softirq handler.
@@ -659,7 +659,7 @@ static void txx9dmac_tasklet(struct tasklet_struct *t)spin_lock (&dc->lock);if (csr & (TXX9_DMA_CSR_ABCHC |TXX9_DMA_CSR_NCHNC |TXX9_DMA_CSR_NTRNFC )) -txx9dmac_scan_descriptors (dc); +dmaengine_schedule_bh (&dc->chan);spin_unlock (&dc->lock); } }
@@ -1113,7 +1113,7 @@ static int __init txx9dmac_chan_probe(struct platform_device *pdev) irq =platform_get_irq (pdev,0 );if (irq <0 )return irq; -tasklet_setup (&dc->tasklet, txx9dmac_chan_tasklet); +dmaengine_init_bh (&dc->chan, txx9dmac_chan_tasklet); dc->irq = irq; err =devm_request_irq (&pdev->dev, dc->irq, txx9dmac_chan_interrupt,0 ,dev_name (&pdev->dev), dc);
@@ -1159,7 +1159,7 @@ static void txx9dmac_chan_remove(struct platform_device *pdev)dma_async_device_unregister (&dc->dma);if (dc->irq >=0 ) {devm_free_irq (&pdev->dev, dc->irq, dc); -tasklet_kill (&dc->tasklet); +dmaengine_kill_bh (&dc->chan); } dc->ddev->chan[pdev->id %TXX9_DMA_MAX_NR_CHANNELS ] =NULL ; }
drivers/dma/txx9dmac.h +0 -1
@@ -162,7 +162,6 @@ struct txx9dmac_chan {struct dma_device dma;struct txx9dmac_dev *ddev;void __iomem *ch_regs; -struct tasklet_struct tasklet;int irq;u32 ccr;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 24/34] dmaengine: txx9dmac: route callbacks via channel BH
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Uninitialized per-channel BH work in shared controller IRQ mode causes DMA transfers to stall and…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Uninitialized per-channel BH work in shared controller IRQ mode causes DMA transfers to stall and triggers warnings.
- [High] Deferring descriptor scanning to a background work while immediately re-enabling the shared IRQ causes an interrupt storm. --
--- Patch [24]: [PATCH v3 24/34] dmaengine: txx9dmac: route callbacks via channel BH --- commit c425e27c746c8c326d7eb6597032d4dcfe3fa1da
Author: Allen Pais <[email protected]>
Subject: dmaengine: txx9dmac: route callbacks via channel BH
This commit replaces tasklets with per-channel BH work helpers for handling descriptor completions in the txx9dmac driver. It updates the probe, remove, and interrupt handlers to schedule the channel BH work.
Quoted 4 lines
drivers/dma/txx9dmac.c +0
-0
[ ... ]
drivers/dma/txx9dmac.c static void txx9dmac_tasklet(struct tasklet_struct *t) · line 665
Quoted 9 lines
drivers/dma/txx9dmac.c +1
-1@@ -659,7 +659,7 @@ static void txx9dmac_tasklet(struct tasklet_struct *t)spin_lock (&dc->lock);if (csr & (TXX9_DMA_CSR_ABCHC |TXX9_DMA_CSR_NCHNC |TXX9_DMA_CSR_NTRNFC )) -txx9dmac_scan_descriptors (dc); +dmaengine_schedule_bh (&dc->chan);spin_unlock (&dc->lock); } }
[Severity: High]
Does deferring the descriptor scanning to a background work while immediately re-enabling the shared IRQ cause an interrupt storm?
Looking at the rest of txx9dmac_tasklet(), it calls enable_irq(irq) synchronously at the end. Since the hardware interrupt condition is cleared by the deferred workqueue (which runs after softirqs), will re-enabling the IRQ here instantly trigger the interrupt again, leading to an infinite loop that starves the workqueue?
[ ... ]
drivers/dma/txx9dmac.c static int __init txx9dmac_chan_probe(struct platform_device *pdev) · line 1119
Quoted 9 lines
drivers/dma/txx9dmac.c +1
-1@@ -1113,7 +1113,7 @@ static int __init txx9dmac_chan_probe(struct platform_device *pdev) irq =platform_get_irq (pdev,0 );if (irq <0 )return irq; -tasklet_setup (&dc->tasklet, txx9dmac_chan_tasklet); +dmaengine_init_bh (&dc->chan, txx9dmac_chan_tasklet); dc->irq = irq; err =devm_request_irq (&pdev->dev, dc->irq, txx9dmac_chan_interrupt,0 ,dev_name (&pdev->dev), dc);
[Severity: High]
Is the per-channel BH work left uninitialized in shared controller IRQ mode?
If dc->ddev->irq >= 0 in txx9dmac_chan_probe(), the code falls into the else block and dmaengine_init_bh() is skipped. When an interrupt occurs, the shared tasklet (txx9dmac_tasklet) will unconditionally call dmaengine_schedule_bh() for the channel.
Will this trigger a WARN_ON(!chan->bh_work_initialized) and return false, permanently stalling transfers for shared IRQ setups?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
Re: [PATCH v3 24/34] dmaengine: txx9dmac: route callbacks via channel BH
In reply to Allen PaisQuoted 5 lines · Allen Pais
Use the per-channel BH helpers for descriptor completion handling and schedule per-channel work from both channel and controller IRQ paths.
Signed-off-by Allen Pais <[email protected]>---
Quoted 75 lines
drivers/dma/txx9dmac.c | 12 ++++++------ drivers/dma/txx9dmac.h | 1 - 2 files changed, 6 insertions(+), 7 deletions(-)drivers/dma/txx9dmac.c +6
-6@@ -601,13 +601,13 @@ static void txx9dmac_scan_descriptors(struct txx9dmac_chan *dc) } } -static void txx9dmac_chan_tasklet (struct tasklet_struct *t) +static void txx9dmac_chan_tasklet (struct dma_chan *chan) {int irq;u32 csr;struct txx9dmac_chan *dc; - dc =from_tasklet (dc, t, tasklet); + dc = container_of(chan, struct txx9dmac_chan, chan); csr =channel_readl (dc,CSR );dev_vdbg (chan2dev (&dc->chan),"tasklet: status=%x\n" , csr);@@ -628,7 +628,7 @@ static irqreturn_t txx9dmac_chan_interrupt(int irq, void *dev_id)dev_vdbg (chan2dev (&dc->chan),"interrupt: status=%#x\n" ,channel_readl (dc,CSR )); -tasklet_schedule (&dc->tasklet); +dmaengine_schedule_bh (&dc->chan);/* * Just disable the interrupts. We'll turn them back on in the * softirq handler. @@ -659,7 +659,7 @@ static void txx9dmac_tasklet(struct tasklet_struct *t)spin_lock (&dc->lock);if (csr & (TXX9_DMA_CSR_ABCHC |TXX9_DMA_CSR_NCHNC |TXX9_DMA_CSR_NTRNFC )) -txx9dmac_scan_descriptors (dc); +dmaengine_schedule_bh (&dc->chan);spin_unlock (&dc->lock); } }@@ -1113,7 +1113,7 @@ static int __init txx9dmac_chan_probe(struct platform_device *pdev) irq =platform_get_irq (pdev,0 );if (irq <0 )return irq; -tasklet_setup (&dc->tasklet, txx9dmac_chan_tasklet); +dmaengine_init_bh (&dc->chan, txx9dmac_chan_tasklet); dc->irq = irq; err =devm_request_irq (&pdev->dev, dc->irq, txx9dmac_chan_interrupt,0 ,dev_name (&pdev->dev), dc);@@ -1159,7 +1159,7 @@ static void txx9dmac_chan_remove(struct platform_device *pdev)dma_async_device_unregister (&dc->dma);if (dc->irq >=0 ) {devm_free_irq (&pdev->dev, dc->irq, dc); -tasklet_kill (&dc->tasklet); +dmaengine_kill_bh (&dc->chan); } dc->ddev->chan[pdev->id %TXX9_DMA_MAX_NR_CHANNELS ] =NULL ; }drivers/dma/txx9dmac.h +0
-2@@ -162,7 +162,6 @@ struct txx9dmac_chan {struct dma_device dma;struct txx9dmac_dev *ddev;void __iomem *ch_regs; -struct tasklet_struct tasklet;int irq;u32 ccr; --2.43.0
PATCH v3 25/34 dmaengine: mv_xor_v2: use channel BH helpers
In reply to Allen PaisReplace the device tasklet with the per-channel BH helper so descriptor callbacks run through dmaengine_*_bh.
--- drivers/dma/mv_xor_v2.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/dma/mv_xor_v2.c +9 -11
@@ -139,7 +139,6 @@ struct mv_xor_v2_descriptor {* @reg_clk: reference to the 'reg' clock * @dma_base: memory mapped DMA register base * @glob_base: memory mapped global register base -* @irq_tasklet: tasklet used for IRQ handling call-backs * @free_sw_desc: linked list of free SW descriptors * @dmadev: dma device * @dmachan: dma channel
@@ -158,7 +157,6 @@ struct mv_xor_v2_device {void __iomem *glob_base;struct clk *clk;struct clk *reg_clk; -struct tasklet_struct irq_tasklet;struct list_head free_sw_desc;struct dma_device dmadev;struct dma_chan dmachan;
@@ -290,8 +288,8 @@ static irqreturn_t mv_xor_v2_interrupt_handler(int irq, void *data)if (!ndescs)return IRQ_NONE ; -/* schedule a tasklet to handle descriptors callbacks */ -tasklet_schedule (&xor_dev->irq_tasklet); +/* schedule a bottom half to handle descriptors callbacks */ +dmaengine_schedule_bh (&xor_dev->dmachan);return IRQ_HANDLED ; }
@@ -346,8 +344,8 @@ mv_xor_v2_prep_sw_desc(struct mv_xor_v2_device *xor_dev)if (list_empty (&xor_dev->free_sw_desc)) {spin_unlock_bh (&xor_dev->lock); -/* schedule tasklet to free some descriptors */ -tasklet_schedule (&xor_dev->irq_tasklet); +/* schedule bottom half to free some descriptors */ +dmaengine_schedule_bh (&xor_dev->dmachan);return NULL ; }
@@ -553,10 +551,10 @@ int mv_xor_v2_get_pending_params(struct mv_xor_v2_device *xor_dev,/* * handle the descriptors after HW process */ -static void mv_xor_v2_tasklet (struct tasklet_struct *t) +static void mv_xor_v2_tasklet (struct dma_chan *chan) { -struct mv_xor_v2_device *xor_dev =from_tasklet (xor_dev, t, - irq_tasklet); +struct mv_xor_v2_device *xor_dev = + container_of(chan, struct mv_xor_v2_device, dmachan);int pending_ptr, num_of_pending, i;struct mv_xor_v2_sw_desc *next_pending_sw_desc =NULL ;
@@ -760,7 +758,7 @@ static int mv_xor_v2_probe(struct platform_device *pdev)if (ret) goto free_msi_irqs; -tasklet_setup (&xor_dev->irq_tasklet, mv_xor_v2_tasklet); +dmaengine_init_bh (&xor_dev->dmachan, mv_xor_v2_tasklet); xor_dev->desc_size =mv_xor_v2_set_desc_size (xor_dev);
@@ -869,7 +867,7 @@ static void mv_xor_v2_remove(struct platform_device *pdev)platform_device_msi_free_irqs_all (&pdev->dev); -tasklet_kill (&xor_dev->irq_tasklet); +dmaengine_kill_bh (&xor_dev->dmachan); }#ifdef CONFIG_OF
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 25/34] dmaengine: mv_xor_v2: use channel BH helpers
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Incorrect teardown ordering in mv_xor_v2_remove() frees DMA memory before disabling interrupts and killing the bottom-half work.
- [High] The IRQ handler is registered before the bottom-half work is initialized and before descriptor memory is allocated, creating a race condition with early interrupts.
- [High] Probe error paths fail to kill the initialized bottom-half work, risking a use-after-free if an interrupt schedules the work before probe fails. --
--- Patch [25]: [PATCH v3 25/34] dmaengine: mv_xor_v2: use channel BH helpers --- commit 5bac7d61a8218a20b1f3b692adf51b25c890e0c1
Author: Allen Pais <[email protected]>
dmaengine: mv_xor_v2: use channel BH helpers
Replace the device tasklet with the per-channel BH helper so descriptor callbacks run through dmaengine_*_bh.
Quoted 4 lines
drivers/dma/mv_xor_v2.c +0
-0
[ ... ]
drivers/dma/mv_xor_v2.c static int mv_xor_v2_probe(struct platform_device *pdev) · line 764
Quoted 9 lines
drivers/dma/mv_xor_v2.c +1
-1@@ -760,7 +758,7 @@ static int mv_xor_v2_probe(struct platform_device *pdev)if (ret) goto free_msi_irqs; -tasklet_setup (&xor_dev->irq_tasklet, mv_xor_v2_tasklet); +dmaengine_init_bh (&xor_dev->dmachan, mv_xor_v2_tasklet); xor_dev->desc_size =mv_xor_v2_set_desc_size (xor_dev);
[Severity: High]
This is a pre-existing issue, but registering the IRQ handler before allocating the descriptor memory and initializing the bottom-half seems risky.
If the kernel is booted via kexec and there are pending hardware interrupts, could the IRQ handler fire immediately upon registration and schedule the bottom-half work?
If that happens, mv_xor_v2_tasklet() would execute and dereference xor_dev->hw_desq_virt before dma_alloc_coherent() has initialized it. Would it be safer to request the IRQ after the structures are fully set up?
[Severity: High]
This is a pre-existing issue, but looking at the error handling in probe:
xor_dev->hw_desq_virt =
dma_alloc_coherent(&pdev->dev, ...);
if (!xor_dev->hw_desq_virt) {
ret = -ENOMEM;
goto free_msi_irqs;
}In error paths like goto free_msi_irqs or goto free_hw_desq, the probe returns without killing the initialized bottom-half work. If an early interrupt already scheduled the bottom-half, could this lead to a use-after-free when devres frees the device structures but the scheduled workqueue still executes?
[ ... ]
drivers/dma/mv_xor_v2.c static void mv_xor_v2_remove(struct platform_device *pdev) · line 871
Quoted 7 lines
drivers/dma/mv_xor_v2.c +1
-1@@ -869,7 +867,7 @@ static void mv_xor_v2_remove(struct platform_device *pdev)platform_device_msi_free_irqs_all (&pdev->dev); -tasklet_kill (&xor_dev->irq_tasklet); +dmaengine_kill_bh (&xor_dev->dmachan); }
[Severity: High]
This isn't a bug introduced by this patch, but looking at the full mv_xor_v2_remove() function:
static void mv_xor_v2_remove(struct platform_device *pdev)
{
...
dma_free_coherent(&pdev->dev,
xor_dev->desc_size * MV_XOR_V2_DESC_NUM,
xor_dev->hw_desq_virt, xor_dev->hw_desq);
devm_free_irq(&pdev->dev, xor_dev->irq, xor_dev);
platform_device_msi_free_irqs_all(&pdev->dev);
dmaengine_kill_bh(&xor_dev->dmachan);
}Since dma_free_coherent() frees the descriptor memory before the bottom-half is killed, could an interrupt fire and schedule the bottom-half during this window?
If mv_xor_v2_tasklet() runs after dma_free_coherent(), it would dereference the freed xor_dev->hw_desq_virt memory. Should the IRQ be freed and dmaengine_kill_bh() be called before tearing down the DMA memory?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
Re: [PATCH v3 25/34] dmaengine: mv_xor_v2: use channel BH helpers
In reply to Allen PaisQuoted 5 lines · Allen Pais
Replace the device tasklet with the per-channel BH helper so descriptor callbacks run through dmaengine_*_bh.
Signed-off-by Allen Pais <[email protected]>---
Quoted 80 lines
drivers/dma/mv_xor_v2.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)drivers/dma/mv_xor_v2.c +9
-12@@ -139,7 +139,6 @@ struct mv_xor_v2_descriptor {* @reg_clk: reference to the 'reg' clock * @dma_base: memory mapped DMA register base * @glob_base: memory mapped global register base -* @irq_tasklet: tasklet used for IRQ handling call-backs * @free_sw_desc: linked list of free SW descriptors * @dmadev: dma device * @dmachan: dma channel @@ -158,7 +157,6 @@ struct mv_xor_v2_device {void __iomem *glob_base;struct clk *clk;struct clk *reg_clk; -struct tasklet_struct irq_tasklet;struct list_head free_sw_desc;struct dma_device dmadev;struct dma_chan dmachan;@@ -290,8 +288,8 @@ static irqreturn_t mv_xor_v2_interrupt_handler(int irq, void *data)if (!ndescs)return IRQ_NONE ; -/* schedule a tasklet to handle descriptors callbacks */ -tasklet_schedule (&xor_dev->irq_tasklet); +/* schedule a bottom half to handle descriptors callbacks */ +dmaengine_schedule_bh (&xor_dev->dmachan);return IRQ_HANDLED ; }@@ -346,8 +344,8 @@ mv_xor_v2_prep_sw_desc(struct mv_xor_v2_device *xor_dev)if (list_empty (&xor_dev->free_sw_desc)) {spin_unlock_bh (&xor_dev->lock); -/* schedule tasklet to free some descriptors */ -tasklet_schedule (&xor_dev->irq_tasklet); +/* schedule bottom half to free some descriptors */ +dmaengine_schedule_bh (&xor_dev->dmachan);return NULL ; }@@ -553,10 +551,10 @@ int mv_xor_v2_get_pending_params(struct mv_xor_v2_device *xor_dev,/* * handle the descriptors after HW process */ -static void mv_xor_v2_tasklet (struct tasklet_struct *t) +static void mv_xor_v2_tasklet (struct dma_chan *chan) { -struct mv_xor_v2_device *xor_dev =from_tasklet (xor_dev, t, - irq_tasklet); +struct mv_xor_v2_device *xor_dev = + container_of(chan, struct mv_xor_v2_device, dmachan);int pending_ptr, num_of_pending, i;struct mv_xor_v2_sw_desc *next_pending_sw_desc =NULL ;@@ -760,7 +758,7 @@ static int mv_xor_v2_probe(struct platform_device *pdev)if (ret) goto free_msi_irqs; -tasklet_setup (&xor_dev->irq_tasklet, mv_xor_v2_tasklet); +dmaengine_init_bh (&xor_dev->dmachan, mv_xor_v2_tasklet); xor_dev->desc_size =mv_xor_v2_set_desc_size (xor_dev);@@ -869,7 +867,7 @@ static void mv_xor_v2_remove(struct platform_device *pdev)platform_device_msi_free_irqs_all (&pdev->dev); -tasklet_kill (&xor_dev->irq_tasklet); +dmaengine_kill_bh (&xor_dev->dmachan); }#ifdef CONFIG_OF --2.43.0
PATCH v3 26/34 dmaengine: mpc512x: route callbacks via channel BH
In reply to Allen PaisSchedule per-channel BH work for completions and process callbacks there, leaving the controller tasklet for IRQ/error handling.
--- drivers/dma/mpc512x_dma.c | 74 +++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 27 deletions(-)
drivers/dma/mpc512x_dma.c +47 -27
@@ -372,45 +372,47 @@ static irqreturn_t mpc_dma_irq(int irq, void *data)return IRQ_HANDLED ; } -/* process completed descriptors */ -static void mpc_dma_process_completed (struct mpc_dma *mdma) +static void mpc_dma_process_chan_completed (struct mpc_dma_chan *mchan) {dma_cookie_t last_cookie =0 ; -struct mpc_dma_chan *mchan;struct mpc_dma_desc *mdesc;struct dma_async_tx_descriptor *desc;unsigned long flags;LIST_HEAD (list); -int i; -for (i =0 ; i < mdma->dma.chancnt; i++) { - mchan = &mdma->channels[i]; +/* Get all completed descriptors */ +spin_lock_irqsave (&mchan->lock, flags); +if (!list_empty (&mchan->completed)) +list_splice_tail_init (&mchan->completed, &list); +spin_unlock_irqrestore (&mchan->lock, flags); -/* Get all completed descriptors */ -spin_lock_irqsave (&mchan->lock, flags); -if (!list_empty (&mchan->completed)) -list_splice_tail_init (&mchan->completed, &list); -spin_unlock_irqrestore (&mchan->lock, flags); +if (list_empty (&list)) +return ; -if (list_empty (&list)) -continue ; +/* Execute callbacks and run dependencies */ +list_for_each_entry (mdesc, &list, node) { + desc = &mdesc->desc; -/* Execute callbacks and run dependencies */ -list_for_each_entry (mdesc, &list, node) { - desc = &mdesc->desc; +dmaengine_desc_get_callback_invoke (desc,NULL ); -dmaengine_desc_get_callback_invoke (desc,NULL ); + last_cookie = desc->cookie; +dma_run_dependencies (desc); + } - last_cookie = desc->cookie; -dma_run_dependencies (desc); - } +/* Free descriptors */ +spin_lock_irqsave (&mchan->lock, flags); +list_splice_tail_init (&list, &mchan->free); + mchan->chan.completed_cookie = last_cookie; +spin_unlock_irqrestore (&mchan->lock, flags); +} -/* Free descriptors */ -spin_lock_irqsave (&mchan->lock, flags); -list_splice_tail_init (&list, &mchan->free); - mchan->chan.completed_cookie = last_cookie; -spin_unlock_irqrestore (&mchan->lock, flags); - } +/* process completed descriptors */ +static void mpc_dma_process_completed (struct mpc_dma *mdma) +{ +int i; + +for (i =0 ; i < mdma->dma.chancnt; i++) +mpc_dma_process_chan_completed (&mdma->channels[i]); }/* DMA Tasklet */
@@ -419,6 +421,7 @@ static void mpc_dma_tasklet(struct tasklet_struct *t)struct mpc_dma *mdma =from_tasklet (mdma, t, tasklet);unsigned long flags;uint es; +int i;spin_lock_irqsave (&mdma->error_status_lock, flags); es = mdma->error_status;
@@ -453,7 +456,21 @@ static void mpc_dma_tasklet(struct tasklet_struct *t)dev_err (mdma->dma.dev,"- Destination Bus Error\n" ); } -mpc_dma_process_completed (mdma); +for (i =0 ; i < mdma->dma.chancnt; i++) { +struct mpc_dma_chan *mchan = &mdma->channels[i]; + +spin_lock_irqsave (&mchan->lock, flags); +if (!list_empty (&mchan->completed)) +dmaengine_schedule_bh (&mchan->chan); +spin_unlock_irqrestore (&mchan->lock, flags); + } +} + +static void mpc_dma_chan_bh (struct dma_chan *chan) +{ +struct mpc_dma_chan *mchan =dma_chan_to_mpc_dma_chan (chan); + +mpc_dma_process_chan_completed (mchan); }/* Submit descriptor to hardware */
@@ -551,6 +568,8 @@ static void mpc_dma_free_chan_resources(struct dma_chan *chan)unsigned long flags;LIST_HEAD (descs); +dmaengine_kill_bh (&mchan->chan); +spin_lock_irqsave (&mchan->lock, flags);/* Channel must be idle */
@@ -1007,6 +1026,7 @@ static int mpc_dma_probe(struct platform_device *op)INIT_LIST_HEAD (&mchan->completed);spin_lock_init (&mchan->lock); +dmaengine_init_bh (&mchan->chan, mpc_dma_chan_bh);list_add_tail (&mchan->chan.device_node, &dma->channels); }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 26/34] dmaengine: mpc512x: route callbacks via channel BH
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
New issues:
- [High] Missing dmaengine_kill_bh() in mpc_dma_remove() leads to Use-After-Free of per-channel BH work upon driver unbind.
Pre-existing issues:
- [High] Concurrent execution of completion processing can lead to backward progression of completed_cookie and out-of-order callbacks.
- [High] Inline descriptor processing in prep_ functions executes callbacks synchronously across all channels, risking deadlocks.
- [High] Missing device_synchronize implementation in dma_device to flush the deferred completion work.
- [High] Interrupt handler is requested before tasklet and locks are initialized, and tasklet cleanup is missing in probe error paths.
- [High] mpc_dma_device_terminate_all does not clear mchan->completed, leading to BUG_ON crash in free_chan_resources. --
--- Patch [26]: [PATCH v3 26/34] dmaengine: mpc512x: route callbacks via channel BH --- commit a8db08e8595cca1d5c7b07d2e006d85529289c2e
Author: Allen Pais <[email protected]>
Subject: dmaengine: mpc512x: route callbacks via channel BH
This patch modifies the MPC512x DMA driver to handle descriptor completions through per-channel bottom halves instead of a global tasklet. It introduces workqueue scheduling and cleanup for the channels to process callbacks, while leaving the tasklet to manage IRQ and error handling.
Quoted 4 lines
drivers/dma/mpc512x_dma.c +0
-0
[ ... ]
Quoted 45 lines
drivers/dma/mpc512x_dma.c +15
-18+static void mpc_dma_process_chan_completed (struct mpc_dma_chan *mchan) {dma_cookie_t last_cookie =0 ; -struct mpc_dma_chan *mchan;struct mpc_dma_desc *mdesc;struct dma_async_tx_descriptor *desc;unsigned long flags;LIST_HEAD (list); -int i; -for (i =0 ; i < mdma->dma.chancnt; i++) { - mchan = &mdma->channels[i]; +/* Get all completed descriptors */ +spin_lock_irqsave (&mchan->lock, flags); +if (!list_empty (&mchan->completed)) +list_splice_tail_init (&mchan->completed, &list); +spin_unlock_irqrestore (&mchan->lock, flags); -/* Get all completed descriptors */ -spin_lock_irqsave (&mchan->lock, flags); -if (!list_empty (&mchan->completed)) -list_splice_tail_init (&mchan->completed, &list); -spin_unlock_irqrestore (&mchan->lock, flags); +if (list_empty (&list)) +return ; -if (list_empty (&list)) -continue ; +/* Execute callbacks and run dependencies */ +list_for_each_entry (mdesc, &list, node) { + desc = &mdesc->desc; -/* Execute callbacks and run dependencies */ -list_for_each_entry (mdesc, &list, node) { - desc = &mdesc->desc; +dmaengine_desc_get_callback_invoke (desc,NULL ); -dmaengine_desc_get_callback_invoke (desc,NULL ); + last_cookie = desc->cookie; +dma_run_dependencies (desc); - } + } -/* Free descriptors */ -spin_lock_irqsave (&mchan->lock, flags);
drivers/dma/mpc512x_dma.c static irqreturn_t mpc_dma_irq(int irq, void *data)
Quoted 10 lines
drivers/dma/mpc512x_dma.c +6
-4-list_splice_tail_init (&list, &mchan->free); - mchan->chan.completed_cookie = last_cookie; -spin_unlock_irqrestore (&mchan->lock, flags); - } +/* Free descriptors */ +spin_lock_irqsave (&mchan->lock, flags); +list_splice_tail_init (&list, &mchan->free); + mchan->chan.completed_cookie = last_cookie; +spin_unlock_irqrestore (&mchan->lock, flags); +}
[Severity: High]
This is a pre-existing issue, but can concurrent execution of completion processing lead to out-of-order callbacks or backward progression of completed_cookie?
If mpc_dma_prep_memcpy() calls mpc_dma_process_completed() synchronously while the BH work executes concurrently, both paths take mchan->lock, splice a batch of completed descriptors to a local list, and drop the lock to execute callbacks.
If Thread A splices older descriptors and Thread B subsequently splices newer ones, Thread B might finish first and update completed_cookie. When Thread A finishes, could it overwrite completed_cookie with the older value?
drivers/dma/mpc512x_dma.c static irqreturn_t mpc_dma_irq(int irq, void *data) · line 416
Quoted 11 lines
drivers/dma/mpc512x_dma.c +7
-2-/* process completed descriptors */ -static void mpc_dma_process_completed(struct mpc_dma *mdma) +/* process completed descriptors */ +static void mpc_dma_process_completed (struct mpc_dma *mdma) +{ +int i; + +for (i =0 ; i < mdma->dma.chancnt; i++) +mpc_dma_process_chan_completed (&mdma->channels[i]); }
[Severity: High]
This is a pre-existing issue, but does iterating over all channels here risk cross-channel deadlocks?
When mpc_dma_prep_memcpy() or mpc_dma_prep_slave_sg() run out of free descriptors, they call mpc_dma_process_completed() directly, running callbacks inline for all channels.
If a client calls the prep_ function with a lock held, and a callback for another channel attempts to acquire the same lock, could this cause an ABBA deadlock?
[ ... ]
drivers/dma/mpc512x_dma.c static void mpc_dma_free_chan_resources(struct dma_chan *chan) · line 575
Quoted 9 lines
drivers/dma/mpc512x_dma.c +2
-0@@ -551,6 +568,8 @@ static void mpc_dma_free_chan_resources(struct dma_chan *chan)unsigned long flags;LIST_HEAD (descs); +dmaengine_kill_bh (&mchan->chan); +spin_lock_irqsave (&mchan->lock, flags);/* Channel must be idle */
[Severity: High]
This is a pre-existing issue, but does mpc_dma_device_terminate_all() leave completed descriptors on the list, causing a crash here?
mpc_dma_device_terminate_all() disables channel requests and splices prepared, queued, and active lists back to the free list, but it completely ignores mchan->completed.
If a hardware completion interrupt fires just before terminate_all is called, completed descriptors remain in mchan->completed. When the client subsequently calls dma_release_channel(), will mpc_dma_free_chan_resources() assert BUG_ON(!list_empty(&mchan->completed)) and crash the kernel?
[ ... ]
drivers/dma/mpc512x_dma.c static int mpc_dma_probe(struct platform_device *op) · line 1032
Quoted 8 lines
drivers/dma/mpc512x_dma.c +1
-0@@ -1007,6 +1026,7 @@ static int mpc_dma_probe(struct platform_device *op)INIT_LIST_HEAD (&mchan->completed);spin_lock_init (&mchan->lock); +dmaengine_init_bh (&mchan->chan, mpc_dma_chan_bh);list_add_tail (&mchan->chan.device_node, &dma->channels); }
[Severity: High]
Is it possible for per-channel BH work to remain queued after the driver is unbound?
The new workqueue is initialized here, but looking at mpc_dma_remove(), it only calls tasklet_kill(&mdma->tasklet) and does not iterate over channels to call dmaengine_kill_bh().
Could this cause the workqueue to execute mpc_dma_chan_bh() on freed memory if the driver is forcefully unbound via sysfs while DMA is active?
[Severity: High]
This is a pre-existing issue, but is the driver missing a device_synchronize callback?
Without this callback implemented in struct dma_device, dmaengine_terminate_sync() will return immediately without waiting for the bottom-half to finish.
If the client frees its DMA buffers immediately after terminate_sync() returns, will the pending workqueue execute callbacks that access the freed memory?
[Severity: High]
This is a pre-existing issue, but is it safe to request the interrupt before the tasklet and locks are initialized?
In mpc_dma_probe(), request_irq() is called before tasklet_setup(), per-channel list initialization, and spin_lock_init().
If a pending interrupt from the hardware fires immediately, could the ISR execute on uninitialized spinlocks and lists, or call tasklet_schedule() on a zero-initialized tasklet? Additionally, if probe fails later, the error path frees the IRQ but fails to call tasklet_kill(), which could allow a pending tasklet to run after devres frees the mdma structure.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
Re: [PATCH v3 26/34] dmaengine: mpc512x: route callbacks via channel BH
In reply to Allen PaisQuoted 5 lines · Allen Pais
Schedule per-channel BH work for completions and process callbacks there, leaving the controller tasklet for IRQ/error handling.
Signed-off-by Allen Pais <[email protected]>---
Quoted 132 lines
drivers/dma/mpc512x_dma.c | 74 +++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 27 deletions(-)drivers/dma/mpc512x_dma.c +47
-28@@ -372,45 +372,47 @@ static irqreturn_t mpc_dma_irq(int irq, void *data)return IRQ_HANDLED ; } -/* process completed descriptors */ -static void mpc_dma_process_completed (struct mpc_dma *mdma) +static void mpc_dma_process_chan_completed (struct mpc_dma_chan *mchan) {dma_cookie_t last_cookie =0 ; -struct mpc_dma_chan *mchan;struct mpc_dma_desc *mdesc;struct dma_async_tx_descriptor *desc;unsigned long flags;LIST_HEAD (list); -int i; -for (i =0 ; i < mdma->dma.chancnt; i++) { - mchan = &mdma->channels[i]; +/* Get all completed descriptors */ +spin_lock_irqsave (&mchan->lock, flags); +if (!list_empty (&mchan->completed)) +list_splice_tail_init (&mchan->completed, &list); +spin_unlock_irqrestore (&mchan->lock, flags); -/* Get all completed descriptors */ -spin_lock_irqsave (&mchan->lock, flags); -if (!list_empty (&mchan->completed)) -list_splice_tail_init (&mchan->completed, &list); -spin_unlock_irqrestore (&mchan->lock, flags); +if (list_empty (&list)) +return ; -if (list_empty (&list)) -continue ; +/* Execute callbacks and run dependencies */ +list_for_each_entry (mdesc, &list, node) { + desc = &mdesc->desc; -/* Execute callbacks and run dependencies */ -list_for_each_entry (mdesc, &list, node) { - desc = &mdesc->desc; +dmaengine_desc_get_callback_invoke (desc,NULL ); -dmaengine_desc_get_callback_invoke (desc,NULL ); + last_cookie = desc->cookie; +dma_run_dependencies (desc); + } - last_cookie = desc->cookie; -dma_run_dependencies (desc); - } +/* Free descriptors */ +spin_lock_irqsave (&mchan->lock, flags); +list_splice_tail_init (&list, &mchan->free); + mchan->chan.completed_cookie = last_cookie; +spin_unlock_irqrestore (&mchan->lock, flags); +} -/* Free descriptors */ -spin_lock_irqsave (&mchan->lock, flags); -list_splice_tail_init (&list, &mchan->free); - mchan->chan.completed_cookie = last_cookie; -spin_unlock_irqrestore (&mchan->lock, flags); - } +/* process completed descriptors */ +static void mpc_dma_process_completed (struct mpc_dma *mdma) +{ +int i; + +for (i =0 ; i < mdma->dma.chancnt; i++) +mpc_dma_process_chan_completed (&mdma->channels[i]); }/* DMA Tasklet */ @@ -419,6 +421,7 @@ static void mpc_dma_tasklet(struct tasklet_struct *t)struct mpc_dma *mdma =from_tasklet (mdma, t, tasklet);unsigned long flags;uint es; +int i;spin_lock_irqsave (&mdma->error_status_lock, flags); es = mdma->error_status;@@ -453,7 +456,21 @@ static void mpc_dma_tasklet(struct tasklet_struct *t)dev_err (mdma->dma.dev,"- Destination Bus Error\n" ); } -mpc_dma_process_completed (mdma); +for (i =0 ; i < mdma->dma.chancnt; i++) { +struct mpc_dma_chan *mchan = &mdma->channels[i]; + +spin_lock_irqsave (&mchan->lock, flags); +if (!list_empty (&mchan->completed)) +dmaengine_schedule_bh (&mchan->chan); +spin_unlock_irqrestore (&mchan->lock, flags); + } +} + +static void mpc_dma_chan_bh (struct dma_chan *chan) +{ +struct mpc_dma_chan *mchan =dma_chan_to_mpc_dma_chan (chan); + +mpc_dma_process_chan_completed (mchan); }/* Submit descriptor to hardware */ @@ -551,6 +568,8 @@ static void mpc_dma_free_chan_resources(struct dma_chan *chan)unsigned long flags;LIST_HEAD (descs); +dmaengine_kill_bh (&mchan->chan); +spin_lock_irqsave (&mchan->lock, flags);/* Channel must be idle */ @@ -1007,6 +1026,7 @@ static int mpc_dma_probe(struct platform_device *op)INIT_LIST_HEAD (&mchan->completed);spin_lock_init (&mchan->lock); +dmaengine_init_bh (&mchan->chan, mpc_dma_chan_bh);list_add_tail (&mchan->chan.device_node, &dma->channels); } --2.43.0
PATCH v3 27/34 dmaengine: plx_dma: use channel BH helpers
In reply to Allen PaisReplace the device tasklet with the per-channel BH helper so completion callbacks run via dmaengine_*_bh.
--- drivers/dma/plx_dma.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/dma/plx_dma.c +6 -6
@@ -105,7 +105,6 @@ struct plx_dma_dev {struct dma_chan dma_chan;struct pci_dev __rcu *pdev;void __iomem *bar; -struct tasklet_struct desc_task;spinlock_t ring_lock;bool ring_active;
@@ -241,9 +240,10 @@ static void plx_dma_stop(struct plx_dma_dev *plxdev)rcu_read_unlock (); } -static void plx_dma_desc_task (struct tasklet_struct *t) +static void plx_dma_desc_task (struct dma_chan *chan) { -struct plx_dma_dev *plxdev =from_tasklet (plxdev, t, desc_task); + struct plx_dma_dev *plxdev = container_of(chan, struct plx_dma_dev, + dma_chan);plx_dma_process_desc (plxdev); }
@@ -366,7 +366,7 @@ static irqreturn_t plx_dma_isr(int irq, void *devid)return IRQ_NONE ;if (status &PLX_REG_INTR_STATUS_DESC_DONE && plxdev->ring_active) -tasklet_schedule (&plxdev->desc_task); +dmaengine_schedule_bh (&plxdev->dma_chan);writew (status, plxdev->bar +PLX_REG_INTR_STATUS );
@@ -471,7 +471,7 @@ static void plx_dma_free_chan_resources(struct dma_chan *chan)if (irq >0 )synchronize_irq (irq); -tasklet_kill (&plxdev->desc_task); +dmaengine_kill_bh (&plxdev->dma_chan);plx_dma_abort_desc (plxdev);
@@ -510,7 +510,7 @@ static int plx_dma_create(struct pci_dev *pdev) goto free_plx;spin_lock_init (&plxdev->ring_lock); -tasklet_setup (&plxdev->desc_task, plx_dma_desc_task); +dmaengine_init_bh (&plxdev->dma_chan, plx_dma_desc_task);RCU_INIT_POINTER (plxdev->pdev, pdev); plxdev->bar =pcim_iomap_table (pdev)[0 ];
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 27/34] dmaengine: plx_dma: use channel BH helpers
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] plx_dma_process_desc() fails to disable bottom halves when acquiring ring_lock, leading to a spinlock deadlock if preempted by a softirq.
- [High] plx_dma_process_desc() and plx_dma_abort_desc() invoke client completion callbacks while holding the driver's ring_lock, causing a recursive deadlock if the client submits a new transaction.
- [High] Race condition in plx_dma_create() where request_irq() is called before plxdev->bar is initialized, leading to a potential NULL pointer dereference.
--
--- Patch [27]: [PATCH v3 27/34] dmaengine: plx_dma: use channel BH helpers --- commit 3f31218d1705896b2087c850d94c4632503584c8
Author: Allen Pais <[email protected]> Date: Mon Aug 10 18:09:28 2026 +0000
dmaengine: plx_dma: use channel BH helpers
Replace the device tasklet with the per-channel BH helper so completion callbacks run via dmaengine_*_bh.
Quoted 4 lines
drivers/dma/plx_dma.c +0
-0
[ ... ]
drivers/dma/plx_dma.c static void plx_dma_stop(struct plx_dma_dev *plxdev) · line 248
Quoted 12 lines
drivers/dma/plx_dma.c +3
-2@@ -241,9 +240,10 @@ static void plx_dma_stop(struct plx_dma_dev *plxdev)rcu_read_unlock (); } -static void plx_dma_desc_task (struct tasklet_struct *t) +static void plx_dma_desc_task (struct dma_chan *chan) { -struct plx_dma_dev *plxdev =from_tasklet (plxdev, t, desc_task); + struct plx_dma_dev *plxdev = container_of(chan, struct plx_dma_dev, + dma_chan);plx_dma_process_desc (plxdev);
[Severity: High]
This isn't a bug introduced by this patch, but does plx_dma_process_desc() leave bottom halves enabled while acquiring ring_lock?
If plx_dma_process_desc() is called from process context (like through plx_dma_tx_status() or plx_dma_abort_desc()), it acquires ring_lock with spin_lock():
spin_lock(&plxdev->ring_lock);
If a hardware interrupt fires on the same CPU, plx_dma_isr() schedules the BH work. When the ISR returns, the kernel will run the softirq before returning to the preempted process context. The BH work (plx_dma_desc_task) will then call plx_dma_process_desc() and try to acquire the already-held ring_lock, causing a deadlock.
[Severity: High]
This is a pre-existing issue, but can invoking the client callback synchronously while holding ring_lock cause a recursive deadlock?
In plx_dma_process_desc() and plx_dma_abort_desc(), the callback is invoked while holding the spinlock:
spin_lock(&plxdev->ring_lock); ... dmaengine_desc_get_callback_invoke(&desc->txd, &res);
If a DMA client prepares and submits a new DMA transaction directly from its completion callback, it will call plx_dma_prep_memcpy(). This attempts to acquire ring_lock via spin_lock_bh() on the same CPU, which is already held, resulting in a self-deadlock.
Quoted 1 line
drivers/dma/plx_dma.c +0
-0}
[ ... ]
drivers/dma/plx_dma.c static int plx_dma_create(struct pci_dev *pdev) · line 516
Quoted 9 lines
drivers/dma/plx_dma.c +1
-1@@ -510,7 +510,7 @@ static int plx_dma_create(struct pci_dev *pdev) goto free_plx;spin_lock_init (&plxdev->ring_lock); -tasklet_setup (&plxdev->desc_task, plx_dma_desc_task); +dmaengine_init_bh (&plxdev->dma_chan, plx_dma_desc_task);RCU_INIT_POINTER (plxdev->pdev, pdev); plxdev->bar =pcim_iomap_table (pdev)[0 ];
[Severity: High]
This isn't a bug introduced by this patch, but is there a race condition with the interrupt handler here?
request_irq() is called earlier in plx_dma_create(), unmasking the interrupt before plxdev->bar is initialized.
If an interrupt fires immediately upon registration (for example, due to pending hardware state), plx_dma_isr() executes and unconditionally reads from plxdev->bar:
status = readw(plxdev->bar + PLX_REG_INTR_STATUS);
Since plxdev->bar is still NULL at that point, this will result in a NULL pointer dereference.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
Re: [PATCH v3 27/34] dmaengine: plx_dma: use channel BH helpers
In reply to Allen PaisQuoted 6 lines · Allen Pais
Replace the device tasklet with the per-channel BH helper so completion callbacks run via dmaengine_*_bh.
Signed-off-by Allen Pais <[email protected]>Reviewed-by Logan Gunthorpe <[email protected]>---
Quoted 58 lines
drivers/dma/plx_dma.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/dma/plx_dma.c +6
-7@@ -105,7 +105,6 @@ struct plx_dma_dev {struct dma_chan dma_chan;struct pci_dev __rcu *pdev;void __iomem *bar; -struct tasklet_struct desc_task;spinlock_t ring_lock;bool ring_active;@@ -241,9 +240,10 @@ static void plx_dma_stop(struct plx_dma_dev *plxdev)rcu_read_unlock (); } -static void plx_dma_desc_task (struct tasklet_struct *t) +static void plx_dma_desc_task (struct dma_chan *chan) { -struct plx_dma_dev *plxdev =from_tasklet (plxdev, t, desc_task); + struct plx_dma_dev *plxdev = container_of(chan, struct plx_dma_dev, + dma_chan);plx_dma_process_desc (plxdev); }@@ -366,7 +366,7 @@ static irqreturn_t plx_dma_isr(int irq, void *devid)return IRQ_NONE ;if (status &PLX_REG_INTR_STATUS_DESC_DONE && plxdev->ring_active) -tasklet_schedule (&plxdev->desc_task); +dmaengine_schedule_bh (&plxdev->dma_chan);writew (status, plxdev->bar +PLX_REG_INTR_STATUS );@@ -471,7 +471,7 @@ static void plx_dma_free_chan_resources(struct dma_chan *chan)if (irq >0 )synchronize_irq (irq); -tasklet_kill (&plxdev->desc_task); +dmaengine_kill_bh (&plxdev->dma_chan);plx_dma_abort_desc (plxdev);@@ -510,7 +510,7 @@ static int plx_dma_create(struct pci_dev *pdev) goto free_plx;spin_lock_init (&plxdev->ring_lock); -tasklet_setup (&plxdev->desc_task, plx_dma_desc_task); +dmaengine_init_bh (&plxdev->dma_chan, plx_dma_desc_task);RCU_INIT_POINTER (plxdev->pdev, pdev); plxdev->bar =pcim_iomap_table (pdev)[0 ]; --2.43.0
PATCH v3 28/34 dmaengine: sf-pdma: route error callbacks through channel BH
In reply to Allen Paisvirt-dma now dispatches completion callbacks through per-channel BH work, but SF-PDMA invokes the client callback directly from its error tasklet after exhausting its retries.
Complete failed descriptors through virt-dma with an aborted result and the remaining transfer size, then start the next pending transfer. During removal, kill the producer tasklets before the channel BH so they cannot enqueue callback work after it has been canceled.
--- drivers/dma/sf-pdma/sf-pdma.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/dma/sf-pdma/sf-pdma.c +12 -2
@@ -328,7 +328,17 @@ static void sf_pdma_errbh_tasklet(struct tasklet_struct *t)if (chan->retries <=0 ) {/* fail to recover */ spin_unlock_irqrestore (&chan->lock, flags); -dmaengine_desc_get_callback_invoke (desc->async_tx,NULL ); + +spin_lock_irqsave (&chan->vchan.lock, flags); +list_del (&desc->vdesc.node); + desc->vdesc.tx_result.result =DMA_TRANS_ABORTED ; + desc->vdesc.tx_result.residue = desc->xfer_size; +vchan_cookie_complete (&desc->vdesc); + + chan->desc =sf_pdma_get_first_pending_desc (chan); +if (chan->desc) +sf_pdma_xfer_desc (chan); +spin_unlock_irqrestore (&chan->vchan.lock, flags); }else {/* retry */ chan->retries--;
@@ -602,9 +612,9 @@ static void sf_pdma_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, ch->txirq, ch);devm_free_irq (&pdev->dev, ch->errirq, ch);list_del (&ch->vchan.chan.device_node); -dmaengine_kill_bh (&ch->vchan.chan);tasklet_kill (&ch->done_tasklet);tasklet_kill (&ch->err_tasklet); +dmaengine_kill_bh (&ch->vchan.chan); }if (pdev->dev.of_node)
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 28/34] dmaengine: sf-pdma: route error callbacks through channel BH
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
New issues:
- [Medium] Starting the next descriptor in the error path fails to reset the channel's retry counter and status.
Pre-existing issues:
- [Critical] Unconditional double-free of the active descriptor (chan->desc) during channel termination or resource cleanup.
- [Critical] Driver removal does not stop active DMA hardware, potentially leading to memory corruption.
- [High] Lack of synchronization between sf_pdma_terminate_all and channel tasklets leads to Use-After-Free and NULL pointer dereferences.
- [High] Manual removal of the channel from the dma_dev.channels list permanently leaks dmaengine core resources on removal.
- [High] sf_pdma_desc_residue returns incorrect hardware residue for active transfers.
--
--- Patch [28]: [PATCH v3 28/34] dmaengine: sf-pdma: route error callbacks through channel BH --- commit 5c7ab16a62d08deb1ca0b90a739ae089b50989a2
Author: Allen Pais <[email protected]>
dmaengine: sf-pdma: route error callbacks through channel BH
Complete failed descriptors through virt-dma with an aborted result and the remaining transfer size, then start the next pending transfer. During removal, kill the producer tasklets before the channel BH so they cannot enqueue callback work after it has been canceled.
Quoted 3 lines
drivers/dma/sf-pdma/sf-pdma.c +0
-0
[ ... ]
drivers/dma/sf-pdma/sf-pdma.c static void sf_pdma_errbh_tasklet(struct tasklet_struct *t) · line 334
Quoted 8 lines
drivers/dma/sf-pdma/sf-pdma.c +3
-1@@ -329,7 +329,17 @@ static void sf_pdma_errbh_tasklet(struct tasklet_struct *t)if (chan->retries <=0 ) {/* fail to recover */ spin_unlock_irqrestore (&chan->lock, flags); -dmaengine_desc_get_callback_invoke (desc->async_tx,NULL ); + +spin_lock_irqsave (&chan->vchan.lock, flags); +list_del (&desc->vdesc.node);
[Severity: High]
This is a pre-existing issue, but is there a lack of synchronization between sf_pdma_terminate_all() and channel tasklets?
sf_pdma_terminate_all() frees chan->desc and sets it to NULL without synchronizing with scheduled tasklets:
drivers/dma/sf-pdma/sf-pdma.c:sf_pdma_terminate_all() {
...
kfree(chan->desc);
chan->desc = NULL;
...
}If it races with this tasklet, the pointer is cached before the lock and the list node is modified here after it may have been freed.
Additionally, in sf_pdma_donebh_tasklet(), the pointer is dereferenced unconditionally:
drivers/dma/sf-pdma/sf-pdma.c:sf_pdma_donebh_tasklet() {
...
list_del(&chan->desc->vdesc.node);
...
}Could this lead to use-after-free and NULL pointer dereferences?
drivers/dma/sf-pdma/sf-pdma.c static void sf_pdma_errbh_tasklet(struct tasklet_struct *t) · line 340
Quoted 7 lines
drivers/dma/sf-pdma/sf-pdma.c +7
-0+ desc->vdesc.tx_result.result =DMA_TRANS_ABORTED ; + desc->vdesc.tx_result.residue = desc->xfer_size; +vchan_cookie_complete (&desc->vdesc); + + chan->desc =sf_pdma_get_first_pending_desc (chan); +if (chan->desc) +sf_pdma_xfer_desc (chan);
[Severity: Medium]
When starting the next descriptor in the error path, should the channel's retry counter and status be reset?
If chan->retries remains <= 0, will the new transfer inherit the exhausted retry state and bypass the retry logic completely if it encounters an error?
Quoted 4 lines
drivers/dma/sf-pdma/sf-pdma.c +1
-0+spin_unlock_irqrestore (&chan->vchan.lock, flags); }else {/* retry */ chan->retries--;
[ ... ]
drivers/dma/sf-pdma/sf-pdma.c static void sf_pdma_remove(struct platform_device *pdev) · line 615
Quoted 4 lines
drivers/dma/sf-pdma/sf-pdma.c +0
-0@@ -603,9 +613,9 @@ static void sf_pdma_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, ch->txirq, ch);devm_free_irq (&pdev->dev, ch->errirq, ch);list_del (&ch->vchan.chan.device_node);
[Severity: High]
This is a pre-existing issue, but does manually removing the channel from the list prevent the dmaengine core from cleaning up resources?
The dmaengine core iterates over the channels list to unregister sysfs devices, free per-CPU memory, and release the IDA. Because the list is emptied here, the core skips cleanup, which might leave dangling sysfs nodes and IDAs that prevent driver reloads.
drivers/dma/sf-pdma/sf-pdma.c static void sf_pdma_remove(struct platform_device *pdev) · line 620
Quoted 7 lines
drivers/dma/sf-pdma/sf-pdma.c +1
-1-dmaengine_kill_bh (&ch->vchan.chan);tasklet_kill (&ch->done_tasklet);tasklet_kill (&ch->err_tasklet); +dmaengine_kill_bh (&ch->vchan.chan); }if (pdev->dev.of_node)
[Severity: Critical]
This is a pre-existing issue, but shouldn't driver removal stop active DMA hardware to prevent memory corruption?
If a transfer is running when the driver is forcefully unbound, the hardware DMA engine continues writing to memory. Since the software stack is torn down and the client buffers may be freed, does this lack of a call to disable the hardware requests or terminate channels allow ongoing hardware DMA to corrupt arbitrary physical memory?
[Severity: Critical]
This is a pre-existing issue, but does this code cause a double-free during channel termination?
drivers/dma/sf-pdma/sf-pdma.c:sf_pdma_terminate_all() {
...
kfree(chan->desc);
chan->desc = NULL;
chan->xfer_err = false;
vchan_get_all_descriptors(&chan->vchan, &head);
...
}Because the descriptor is never removed from the desc_issued list, the subsequent call to vchan_get_all_descriptors() collects this already-freed descriptor. Then, vchan_dma_desc_free_list() invokes sf_pdma_free_desc(), executing a second kfree() on the same memory.
The exact same double-free sequence also exists in sf_pdma_free_chan_resources().
[Severity: High]
This is a pre-existing issue, but does sf_pdma_desc_residue() return incorrect hardware residue for active transfers?
drivers/dma/sf-pdma/sf-pdma.c:sf_pdma_desc_residue() {
...
list_for_each_entry(vd, &chan->vchan.desc_submitted, node)
...
residue = readq(regs->residue);
...
}This iterates only over chan->vchan.desc_submitted. Actively running descriptors reside in desc_issued and are missed, resulting in a return value of 0. Conversely, if a transfer is merely pending in desc_submitted, it reads the live hardware residue register, improperly assigning the actively running transfer's residue to a pending transfer.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
Re: [PATCH v3 28/34] dmaengine: sf-pdma: route error callbacks through channel BH
In reply to Allen PaisQuoted 24 lines · Allen Pais
virt-dma now dispatches completion callbacks through per-channel BH work, but SF-PDMA invokes the client callback directly from its error tasklet after exhausting its retries.
Complete failed descriptors through virt-dma with an aborted result and the remaining transfer size, then start the next pending transfer. During removal, kill the producer tasklets before the channel BH so they cannot enqueue callback work after it has been canceled.
Signed-off-by Allen Pais <[email protected]>--- drivers/dma/sf-pdma/sf-pdma.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)drivers/dma/sf-pdma/sf-pdma.c +1
-1@@ -328,7 +328,17 @@ static void sf_pdma_errbh_tasklet(struct tasklet_struct *t)if (chan->retries <=0 ) {/* fail to recover */ spin_unlock_irqrestore (&chan->lock, flags); -dmaengine_desc_get_callback_invoke (desc->async_tx,NULL ); +
drivers/dma/sf-pdma/sf-pdma.c static void sf_pdma_errbh_tasklet(struct tasklet_struct *t) · line 341
Quoted 10 lines
drivers/dma/sf-pdma/sf-pdma.c +10
-0+spin_lock_irqsave (&chan->vchan.lock, flags); +list_del (&desc->vdesc.node); + desc->vdesc.tx_result.result =DMA_TRANS_ABORTED ; + desc->vdesc.tx_result.residue = desc->xfer_size; +vchan_cookie_complete (&desc->vdesc); + + chan->desc =sf_pdma_get_first_pending_desc (chan); +if (chan->desc) +sf_pdma_xfer_desc (chan); +spin_unlock_irqrestore (&chan->vchan.lock, flags);
I am not sure if logic is equal. It'd better someone can help test it.
Frank
Quoted 17 lines
drivers/dma/sf-pdma/sf-pdma.c +1
-2}else {/* retry */ chan->retries--;@@ -602,9 +612,9 @@ static void sf_pdma_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, ch->txirq, ch);devm_free_irq (&pdev->dev, ch->errirq, ch);list_del (&ch->vchan.chan.device_node); -dmaengine_kill_bh (&ch->vchan.chan);tasklet_kill (&ch->done_tasklet);tasklet_kill (&ch->err_tasklet); +dmaengine_kill_bh (&ch->vchan.chan); }if (pdev->dev.of_node) --2.43.0
PATCH v3 29/34 dmaengine: pl330: route callbacks via channel BH
In reply to Allen PaisConvert the per-channel tasklet to dmaengine_*_bh while keeping the controller tasklet for non-callback events.
--- drivers/dma/pl330.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/dma/pl330.c +8 -10
@@ -417,9 +417,6 @@ enum desc_status { };struct dma_pl330_chan { -/* Schedule desc completion */ -struct tasklet_struct task; -/* DMA-Engine Channel */ struct dma_chan chan;
@@ -1574,7 +1571,7 @@ static void dma_pl330_rqcb(struct dma_pl330_desc *desc, enum pl330_op_err err)spin_unlock_irqrestore (&pch->lock, flags); -tasklet_schedule (&pch->task); +dmaengine_schedule_bh (&pch->chan); }static void pl330_dotask (struct tasklet_struct *t)
@@ -2060,14 +2057,15 @@ static inline void fill_queue(struct dma_pl330_chan *pch) desc->status =DONE ;dev_err (pch->dmac->ddma.dev,"%s:%d Bad Desc(%d)\n" , __func__, __LINE__, desc->txd.cookie); -tasklet_schedule (&pch->task); +dmaengine_schedule_bh (&pch->chan); } } } -static void pl330_tasklet (struct tasklet_struct *t) +static void pl330_tasklet (struct dma_chan *chan) { -struct dma_pl330_chan *pch =from_tasklet (pch, t, task); + struct dma_pl330_chan *pch = container_of(chan, struct dma_pl330_chan, + chan);struct dma_pl330_desc *desc, *_dt;unsigned long flags;bool power_down = false;
@@ -2173,7 +2171,7 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)return -ENOMEM ; } -tasklet_setup (&pch->task, pl330_tasklet); +dmaengine_init_bh (&pch->chan, pl330_tasklet);spin_unlock_irqrestore (&pl330->lock, flags);
@@ -2354,7 +2352,7 @@ static void pl330_free_chan_resources(struct dma_chan *chan)struct pl330_dmac *pl330 = pch->dmac;unsigned long flags; -tasklet_kill (&pch->task); +dmaengine_kill_bh (&pch->chan);pm_runtime_get_sync (pch->dmac->ddma.dev);spin_lock_irqsave (&pl330->lock, flags);
@@ -2490,7 +2488,7 @@ static void pl330_issue_pending(struct dma_chan *chan)list_splice_tail_init (&pch->submitted_list, &pch->work_list);spin_unlock_irqrestore (&pch->lock, flags); -pl330_tasklet (&pch->task); +pl330_tasklet (&pch->chan); }/*
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 29/34] dmaengine: pl330: route callbacks via channel BH
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Calling dmaengine_init_bh() dynamically inside pl330_alloc_chan_resources() causes a kernel WARN_ON when a channel is freed and requested again.
Pre-existing issues:
- [High] Re-issuing a DMA request from within a completion callback causes an unbalanced PM runtime counter, potentially suspending the device mid-transfer. --
--- Patch [29]: [PATCH v3 29/34] dmaengine: pl330: route callbacks via channel BH --- commit 1ceab77643ee2c8f72930ed84f7872c29a5db235
Author: Allen Pais <[email protected]>
dmaengine: pl330: route callbacks via channel BH
Convert the per-channel tasklet to dmaengine_*_bh while keeping the controller tasklet for non-callback events.
Quoted 4 lines
drivers/dma/pl330.c +0
-0
[ ... ]
drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan *pch) · line 2066
Quoted 13 lines
drivers/dma/pl330.c +2
-2@@ -2060,14 +2057,15 @@ static inline void fill_queue(struct dma_pl330_chan *pch) desc->status =DONE ;dev_err (pch->dmac->ddma.dev,"%s:%d Bad Desc(%d)\n" , __func__, __LINE__, desc->txd.cookie); -tasklet_schedule (&pch->task); +dmaengine_schedule_bh (&pch->chan); } } } -static void pl330_tasklet (struct tasklet_struct *t) +static void pl330_tasklet (struct dma_chan *chan) {
[Severity: High]
This is a pre-existing issue, but can the PM runtime counter become unbalanced if a client re-issues a transfer from within the completion callback?
In pl330_tasklet(), the local power_down variable is set to true if the work_list is empty:
pl330_tasklet()
if (list_empty(&pch->work_list)) {
power_down = true;The lock is then dropped before invoking the client callback:
dmaengine_desc_callback_invoke(&cb, NULL);
If the client submits a new transfer and calls dma_async_issue_pending() from this callback, it invokes pl330_issue_pending() which calls pm_runtime_get_sync() and starts the transfer.
When the callback returns, the outer tasklet completes and unconditionally calls pm_runtime_put_autosuspend():
if (power_down)
pm_runtime_put_autosuspend(pch->dmac->ddma.dev);Since the local power_down is still true, wouldn't this incorrectly drop the newly acquired PM reference, potentially causing the hardware to autosuspend while the new transfer is actively running?
Quoted 6 lines
drivers/dma/pl330.c +2
-1-struct dma_pl330_chan *pch =from_tasklet (pch, t, task); + struct dma_pl330_chan *pch = container_of(chan, struct dma_pl330_chan, + chan);struct dma_pl330_desc *desc, *_dt;unsigned long flags;bool power_down = false;
[ ... ]
drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct dma_chan *chan) · line 2176
Quoted 8 lines
drivers/dma/pl330.c +1
-1@@ -2173,7 +2171,7 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)return -ENOMEM ; } -tasklet_setup (&pch->task, pl330_tasklet); +dmaengine_init_bh (&pch->chan, pl330_tasklet);spin_unlock_irqrestore (&pl330->lock, flags);
[Severity: High]
When a client driver requests a DMA channel, pl330_alloc_chan_resources() calls dmaengine_init_bh(), which sets chan->bh_work_initialized = true.
If the client later frees the channel via pl330_free_chan_resources(), dmaengine_kill_bh() is called, but this does not clear the initialized flag.
If any client requests the same channel again, wouldn't calling dmaengine_init_bh() here trip the WARN_ON(chan->bh_work_initialized) check in dmaengine_init_bh()?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
Re: [PATCH v3 29/34] dmaengine: pl330: route callbacks via channel BH
In reply to Allen PaisQuoted 5 lines · Allen Pais
Convert the per-channel tasklet to dmaengine_*_bh while keeping the controller tasklet for non-callback events.
Signed-off-by Allen Pais <[email protected]>---
Quoted 75 lines
drivers/dma/pl330.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)drivers/dma/pl330.c +8
-11@@ -417,9 +417,6 @@ enum desc_status { };struct dma_pl330_chan { -/* Schedule desc completion */ -struct tasklet_struct task; -/* DMA-Engine Channel */ struct dma_chan chan;@@ -1574,7 +1571,7 @@ static void dma_pl330_rqcb(struct dma_pl330_desc *desc, enum pl330_op_err err)spin_unlock_irqrestore (&pch->lock, flags); -tasklet_schedule (&pch->task); +dmaengine_schedule_bh (&pch->chan); }static void pl330_dotask (struct tasklet_struct *t)@@ -2060,14 +2057,15 @@ static inline void fill_queue(struct dma_pl330_chan *pch) desc->status =DONE ;dev_err (pch->dmac->ddma.dev,"%s:%d Bad Desc(%d)\n" , __func__, __LINE__, desc->txd.cookie); -tasklet_schedule (&pch->task); +dmaengine_schedule_bh (&pch->chan); } } } -static void pl330_tasklet (struct tasklet_struct *t) +static void pl330_tasklet (struct dma_chan *chan) { -struct dma_pl330_chan *pch =from_tasklet (pch, t, task); + struct dma_pl330_chan *pch = container_of(chan, struct dma_pl330_chan, + chan);struct dma_pl330_desc *desc, *_dt;unsigned long flags;bool power_down = false;@@ -2173,7 +2171,7 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)return -ENOMEM ; } -tasklet_setup (&pch->task, pl330_tasklet); +dmaengine_init_bh (&pch->chan, pl330_tasklet);spin_unlock_irqrestore (&pl330->lock, flags);@@ -2354,7 +2352,7 @@ static void pl330_free_chan_resources(struct dma_chan *chan)struct pl330_dmac *pl330 = pch->dmac;unsigned long flags; -tasklet_kill (&pch->task); +dmaengine_kill_bh (&pch->chan);pm_runtime_get_sync (pch->dmac->ddma.dev);spin_lock_irqsave (&pl330->lock, flags);@@ -2490,7 +2488,7 @@ static void pl330_issue_pending(struct dma_chan *chan)list_splice_tail_init (&pch->submitted_list, &pch->work_list);spin_unlock_irqrestore (&pch->lock, flags); -pl330_tasklet (&pch->task); +pl330_tasklet (&pch->chan); }/* -- 2.43.0
PATCH v3 30/34 dmaengine: altera-msgdma: use channel BH helpers
In reply to Allen PaisReplace the device tasklet with the per-channel BH helper so completion handling runs via dmaengine_*_bh.
--- drivers/dma/altera-msgdma.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/dma/altera-msgdma.c +7 -7
@@ -170,7 +170,6 @@ struct msgdma_sw_desc {struct msgdma_device {spinlock_t lock;struct device *dev; -struct tasklet_struct irq_tasklet;struct list_head pending_list;struct list_head free_list;struct list_head active_list;
@@ -684,11 +683,12 @@ static int msgdma_alloc_chan_resources(struct dma_chan *dchan)/** * msgdma_tasklet - Schedule completion tasklet -* @t: Pointer to the Altera sSGDMA channel structure +* @chan: Pointer to the Altera sSGDMA channel structure */ -static void msgdma_tasklet (struct tasklet_struct *t) +static void msgdma_tasklet (struct dma_chan *chan) { -struct msgdma_device *mdev =from_tasklet (mdev, t, irq_tasklet); + struct msgdma_device *mdev = container_of(chan, struct msgdma_device, + dmachan);u32 count;u32 __maybe_unused size;u32 __maybe_unused status;
@@ -748,7 +748,7 @@ static irqreturn_t msgdma_irq_handler(int irq, void *data)spin_unlock (&mdev->lock); } -tasklet_schedule (&mdev->irq_tasklet); +dmaengine_schedule_bh (&mdev->dmachan);/* Clear interrupt in mSGDMA controller */ iowrite32 (MSGDMA_CSR_STAT_IRQ , mdev->csr +MSGDMA_CSR_STATUS );
@@ -766,7 +766,7 @@ static void msgdma_dev_remove(struct msgdma_device *mdev)return ;devm_free_irq (mdev->dev, mdev->irq, mdev); -tasklet_kill (&mdev->irq_tasklet); +dmaengine_kill_bh (&mdev->dmachan);list_del (&mdev->dmachan.device_node); }
@@ -852,7 +852,7 @@ static int msgdma_probe(struct platform_device *pdev)if (ret)return ret; -tasklet_setup (&mdev->irq_tasklet, msgdma_tasklet); +dmaengine_init_bh (&mdev->dmachan, msgdma_tasklet);dma_cookie_init (&mdev->dmachan);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 30/34] dmaengine: altera-msgdma: use channel BH helpers
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
Pre-existing issues:
- [High] The failure path in msgdma_probe() does not call dma_async_device_unregister() if of_dma_controller_register() fails, leading to a Use-After-Free.
- [High] The IRQ handler is requested before crucial data structures, lists, spinlocks, and the bottom-half worker are initialized, which can cause a kernel panic on an early interrupt.
- [High] Batching multiple DMA transactions causes dropped transfers due to incorrect list splicing in msgdma_start_transfer().
- [High] Dropping the spinlock while iterating a list via list_for_each_entry_safe enables arbitrary concurrent list destruction, leading to a Use-After-Free.
- [High] Zero-length transfers bypass descriptor limit checking, breaking accounting metrics and eventually leading to a NULL pointer dereference.
- [High] A hardware-induced soft lockup where the driver spins infinitely with interrupts disabled if the hardware descriptor FIFO remains full.
- [High] Missing bitmask application when reading the response fill-level register allows undefined upper bits to impose massive computational loops, freezing the kernel. --
--- Patch [30]: [PATCH v3 30/34] dmaengine: altera-msgdma: use channel BH helpers --- commit 728ca1a7dab7d5ba74ab85afa0d21836b794d564
Author: Allen Pais <[email protected]>
dmaengine: altera-msgdma: use channel BH helpers
Replace the device tasklet with the per-channel BH helper so completion handling runs via dmaengine_*_bh.
Quoted 4 lines
drivers/dma/altera-msgdma.c +0
-0
[ ... ]
Quoted 6 lines
drivers/dma/altera-msgdma.c +1
-1@@ -684,11 +683,12 @@ static int msgdma_alloc_chan_resources(struct dma_chan *dchan)/** * msgdma_tasklet - Schedule completion tasklet -* @t: Pointer to the Altera sSGDMA channel structure +* @chan: Pointer to the Altera sSGDMA channel structure
drivers/dma/altera-msgdma.c static int msgdma_alloc_chan_resources(struct dma_chan *dchan) · line 694
Quoted 10 lines
drivers/dma/altera-msgdma.c +3
-2*/ -static void msgdma_tasklet (struct tasklet_struct *t) +static void msgdma_tasklet (struct dma_chan *chan) { -struct msgdma_device *mdev =from_tasklet (mdev, t, irq_tasklet); + struct msgdma_device *mdev = container_of(chan, struct msgdma_device, + dmachan);u32 count;u32 __maybe_unused size;u32 __maybe_unused status;
[Severity: High]
This isn't a bug introduced by this patch, but there appears to be a missing bitmask on the response fill-level read further down in this function:
if (mdev->resp) {
/* Read number of responses that are available */
count = ioread32(mdev->csr + MSGDMA_CSR_RESP_FILL_LEVEL);The macro MSGDMA_CSR_RESP_FILL_LEVEL_GET() exists but isn't used here. If the upper 16 bits contain non-zero data, count will be massively inflated. Could this cause the subsequent while (count--) loop to iterate excessively and cause a CPU stall?
[ ... ]
drivers/dma/altera-msgdma.c static void msgdma_dev_remove(struct msgdma_device *mdev) · line 771
Quoted 8 lines
drivers/dma/altera-msgdma.c +1
-1@@ -766,7 +766,7 @@ static void msgdma_dev_remove(struct msgdma_device *mdev)return ;devm_free_irq (mdev->dev, mdev->irq, mdev); -tasklet_kill (&mdev->irq_tasklet); +dmaengine_kill_bh (&mdev->dmachan);list_del (&mdev->dmachan.device_node); }
[Severity: High]
This is a pre-existing issue, but I have a question about the cleanup path.
If dma_async_device_register() succeeds in msgdma_probe(), but of_dma_controller_register() fails, the code jumps to the fail label and calls msgdma_dev_remove().
However, msgdma_dev_remove() lacks a dma_async_device_unregister() call. Since mdev was allocated with devm_kzalloc(), it is automatically freed on probe failure. Does this leave the dmaengine core with dangling pointers and cause a Use-After-Free?
[ ... ]
drivers/dma/altera-msgdma.c static int msgdma_probe(struct platform_device *pdev) · line 857
Quoted 8 lines
drivers/dma/altera-msgdma.c +1
-1@@ -852,7 +852,7 @@ static int msgdma_probe(struct platform_device *pdev)if (ret)return ret; -tasklet_setup (&mdev->irq_tasklet, msgdma_tasklet); +dmaengine_init_bh (&mdev->dmachan, msgdma_tasklet);dma_cookie_init (&mdev->dmachan);
[Severity: High]
This isn't a bug introduced by this patch, but I have a question about the initialization order here.
Higher up in msgdma_probe(), devm_request_irq() is called before the BH worker, spinlocks, and lists are initialized.
If an interrupt fires immediately upon registration, could msgdma_irq_handler() attempt to lock the uninitialized spinlock, access uninitialized lists in msgdma_start_transfer(), and schedule an uninitialized BH worker?
I also noticed several other pre-existing issues in this file:
[Severity: High]
This is a pre-existing issue, but I noticed something concerning in how batched transfers are handled.
In msgdma_start_transfer():
desc = list_first_entry_or_null(&mdev->pending_list, struct msgdma_sw_desc, node); if (!desc) return; list_splice_tail_init(&mdev->pending_list, &mdev->active_list); msgdma_copy_desc_to_fifo(mdev, desc);
When multiple transactions are queued, this takes the first descriptor but moves the entire pending_list to active_list using list_splice_tail_init(). However, it only copies the first descriptor to the hardware FIFO.
When this transfer completes, subsequent transactions remain trapped in active_list because msgdma_start_transfer() only checks pending_list. Does this result in dropped transfers when a client driver batches multiple requests?
[Severity: High]
This is a pre-existing issue, but the lock dropping pattern seems dangerous.
In msgdma_chan_desc_cleanup(), the code iterates over mdev->done_list using list_for_each_entry_safe and temporarily drops mdev->lock:
if (dmaengine_desc_callback_valid(&cb)) {
spin_unlock_irqrestore(&mdev->lock, irqflags);
dmaengine_desc_callback_invoke(&cb, NULL);
spin_lock_irqsave(&mdev->lock, irqflags);
}If dma_release_channel() is called concurrently, msgdma_free_chan_resources() can acquire the lock, reset all lists, and free the backing array with kfree(mdev->sw_desq). When msgdma_chan_desc_cleanup() reacquires the lock, its next pointer will reference freed memory. Can this race lead to a Use-After-Free?
[Severity: High]
This isn't a bug introduced by this patch, but there seems to be an accounting flaw for zero-length transfers.
In msgdma_prep_memcpy():
desc_cnt = DIV_ROUND_UP(len, MSGDMA_MAX_TRANS_LEN);
...
mdev->desc_free_cnt -= desc_cnt;
...
do {
/* Allocate and populate the descriptor */
new = msgdma_get_descriptor(mdev);
...
} while (len);If len is 0, desc_cnt is 0. The free count check passes, and desc_free_cnt is decremented by 0.
However, the do-while loop executes exactly once, withdrawing a physical descriptor from mdev->free_list via msgdma_get_descriptor(). If multiple zero-length requests are submitted, won't this drain free_list entirely without decrementing desc_free_cnt, eventually causing a NULL pointer dereference in msgdma_get_descriptor()?
[Severity: High]
This is a pre-existing issue, but I am worried about the polling loop in msgdma_copy_one():
while (ioread32(mdev->csr + MSGDMA_CSR_STATUS) & MSGDMA_CSR_STAT_DESC_BUF_FULL) mdelay(1);
Since this function is invoked under a spinlock with local interrupts disabled, could a malfunctioning hardware device permanently stall the CPU core and trigger the NMI watchdog?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
Re: [PATCH v3 30/34] dmaengine: altera-msgdma: use channel BH helpers
In reply to Allen PaisQuoted 5 lines · Allen Pais
Replace the device tasklet with the per-channel BH helper so completion handling runs via dmaengine_*_bh.
Signed-off-by Allen Pais <[email protected]>---
Quoted 61 lines
drivers/dma/altera-msgdma.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/dma/altera-msgdma.c +7
-8@@ -170,7 +170,6 @@ struct msgdma_sw_desc {struct msgdma_device {spinlock_t lock;struct device *dev; -struct tasklet_struct irq_tasklet;struct list_head pending_list;struct list_head free_list;struct list_head active_list;@@ -684,11 +683,12 @@ static int msgdma_alloc_chan_resources(struct dma_chan *dchan)/** * msgdma_tasklet - Schedule completion tasklet -* @t: Pointer to the Altera sSGDMA channel structure +* @chan: Pointer to the Altera sSGDMA channel structure */ -static void msgdma_tasklet (struct tasklet_struct *t) +static void msgdma_tasklet (struct dma_chan *chan) { -struct msgdma_device *mdev =from_tasklet (mdev, t, irq_tasklet); + struct msgdma_device *mdev = container_of(chan, struct msgdma_device, + dmachan);u32 count;u32 __maybe_unused size;u32 __maybe_unused status;@@ -748,7 +748,7 @@ static irqreturn_t msgdma_irq_handler(int irq, void *data)spin_unlock (&mdev->lock); } -tasklet_schedule (&mdev->irq_tasklet); +dmaengine_schedule_bh (&mdev->dmachan);/* Clear interrupt in mSGDMA controller */ iowrite32 (MSGDMA_CSR_STAT_IRQ , mdev->csr +MSGDMA_CSR_STATUS );@@ -766,7 +766,7 @@ static void msgdma_dev_remove(struct msgdma_device *mdev)return ;devm_free_irq (mdev->dev, mdev->irq, mdev); -tasklet_kill (&mdev->irq_tasklet); +dmaengine_kill_bh (&mdev->dmachan);list_del (&mdev->dmachan.device_node); }@@ -852,7 +852,7 @@ static int msgdma_probe(struct platform_device *pdev)if (ret)return ret; -tasklet_setup (&mdev->irq_tasklet, msgdma_tasklet); +dmaengine_init_bh (&mdev->dmachan, msgdma_tasklet);dma_cookie_init (&mdev->dmachan); --2.43.0
PATCH v3 31/34 dmaengine: dw: defer callbacks via channel BH
In reply to Allen PaisQueue completed descriptors on the channel and invoke their callbacks from per-channel BH work instead of the controller tasklet. Add a synchronize hook so termination can wait for deferred callbacks before their descriptor storage is released.
--- drivers/dma/dw/core.c | 42 ++++++++++++++++++++++++++++++++++-------- drivers/dma/dw/regs.h | 1 + 2 files changed, 35 insertions(+), 8 deletions(-)
drivers/dma/dw/core.c +34 -8
@@ -236,25 +236,24 @@ dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc,struct dma_async_tx_descriptor *txd = &desc->txd;struct dw_desc *child;unsigned long flags; -struct dmaengine_desc_callback cb;dev_vdbg (chan2dev (&dwc->chan),"descriptor %u complete\n" , txd->cookie);spin_lock_irqsave (&dwc->lock, flags);dma_cookie_complete (txd); -if (callback_required) -dmaengine_desc_get_callback (txd, &cb); -else -memset (&cb,0 ,sizeof (cb)); +list_del_init (&desc->desc_node);/* async_tx_ack */ list_for_each_entry (child, &desc->tx_list, desc_node)async_tx_ack (&child->txd);async_tx_ack (&desc->txd); -dwc_desc_put (dwc, desc); +if (callback_required) { +list_add_tail (&desc->desc_node, &dwc->completed_list); +dmaengine_schedule_bh (&dwc->chan); + }else { +dwc_desc_put (dwc, desc); + }spin_unlock_irqrestore (&dwc->lock, flags); - -dmaengine_desc_callback_invoke (&cb,NULL ); }static void dwc_complete_all (struct dw_dma *dw,struct dw_dma_chan *dwc)
@@ -285,6 +284,24 @@ static void dwc_complete_all(struct dw_dma *dw, struct dw_dma_chan *dwc)dwc_descriptor_complete (dwc, desc, true); } +static void dwc_chan_bh (struct dma_chan *chan) +{ +struct dw_dma_chan *dwc =to_dw_dma_chan (chan); +struct dw_desc *desc, *_desc; +struct dmaengine_desc_callback cb; +LIST_HEAD (list); + +spin_lock_irq (&dwc->lock); +list_splice_init (&dwc->completed_list, &list); +spin_unlock_irq (&dwc->lock); + +list_for_each_entry_safe (desc, _desc, &list, desc_node) { +dmaengine_desc_get_callback (&desc->txd, &cb); +dmaengine_desc_callback_invoke (&cb,NULL ); +dwc_desc_put (dwc, desc); + } +} +/* Returns how many bytes were already received from source */ static inline u32 dwc_get_sent (struct dw_dma_chan *dwc) {
@@ -965,6 +982,11 @@ static int dwc_terminate_all(struct dma_chan *chan)return 0 ; } +static void dwc_synchronize (struct dma_chan *chan) +{ +dmaengine_kill_bh (chan); +} +static struct dw_desc *dwc_find_desc (struct dw_dma_chan *dwc,dma_cookie_t c) {struct dw_desc *desc;
@@ -1256,6 +1278,8 @@ int do_dma_probe(struct dw_dma_chip *chip)INIT_LIST_HEAD (&dwc->active_list);INIT_LIST_HEAD (&dwc->queue); +INIT_LIST_HEAD (&dwc->completed_list); +dmaengine_init_bh (&dwc->chan, dwc_chan_bh);channel_clear_bit (dw,CH_EN , dwc->mask);
@@ -1321,6 +1345,7 @@ int do_dma_probe(struct dw_dma_chip *chip) dw->dma.device_pause = dwc_pause; dw->dma.device_resume = dwc_resume; dw->dma.device_terminate_all = dwc_terminate_all; + dw->dma.device_synchronize = dwc_synchronize; dw->dma.device_tx_status = dwc_tx_status; dw->dma.device_issue_pending = dwc_issue_pending;
@@ -1374,6 +1399,7 @@ int do_dma_remove(struct dw_dma_chip *chip)list_for_each_entry_safe (dwc, _dwc, &dw->dma.channels, chan.device_node) { +dmaengine_kill_bh (&dwc->chan);list_del (&dwc->chan.device_node);channel_clear_bit (dw,CH_EN , dwc->mask); }
drivers/dma/dw/regs.h +1 -0
@@ -279,6 +279,7 @@ struct dw_dma_chan {unsigned long flags;struct list_head active_list;struct list_head queue; +struct list_head completed_list;unsigned int descs_allocated;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 31/34] dmaengine: dw: defer callbacks via channel BH
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but dropping the channel lock during list iteration in dwc_scan_descriptors causes a Use-After-Free if dwc_terminate_all runs concurrently. --
--- Patch [31]: [PATCH v3 31/34] dmaengine: dw: defer callbacks via channel BH --- commit 15e9633a2c2daf5f60e16d885a4f6398581bad8b
Author: Allen Pais <[email protected]>
dmaengine: dw: defer callbacks via channel BH
This commit defers DMA descriptor callbacks to a per-channel bottom half workqueue instead of running them from the controller tasklet. It introduces a completed_list to hold descriptors pending callbacks and adds a synchronize hook to ensure termination waits for the BH to complete.
Quoted 4 lines
drivers/dma/dw/core.c +0
-0
[ ... ]
drivers/dma/dw/core.c static int dwc_terminate_all(struct dma_chan *chan) · line 984
Quoted 4 lines
drivers/dma/dw/core.c +0
-0@@ -965,6 +982,11 @@ static int dwc_terminate_all(struct dma_chan *chan)return 0 ; }
[Severity: High]
This isn't a bug introduced by this patch, but dropping the channel lock during list iteration in dwc_scan_descriptors() causes a Use-After-Free if dwc_terminate_all() runs concurrently.
dwc_scan_descriptors() iterates over dwc->active_list using list_for_each_entry_safe(). The loop iterator caches _desc (the next element). Before processing the next element, the lock is dropped to call dwc_descriptor_complete():
list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) {
...
spin_unlock_irqrestore(&dwc->lock, flags);
dwc_descriptor_complete(dwc, desc, true);
spin_lock_irqsave(&dwc->lock, flags);
}If dwc_terminate_all() runs concurrently on another CPU, it acquires the lock, splices active_list into a local list, and frees all of its descriptors:
spin_lock_irqsave(&dwc->lock, flags); ... list_splice_init(&dwc->active_list, &list); spin_unlock_irqrestore(&dwc->lock, flags); list_for_each_entry_safe(desc, _desc, &list, desc_node) dwc_descriptor_complete(dwc, desc, false);
When dwc_scan_descriptors() regains the lock, it advances the iterator to _desc, which has now been freed.
Can we address this to prevent memory corruption when channel operation and termination occur concurrently?
Quoted 5 lines
drivers/dma/dw/core.c +5
-0+static void dwc_synchronize (struct dma_chan *chan) +{ +dmaengine_kill_bh (chan); +} +
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=31
Andy Shevchenko
reviewerRe: [PATCH v3 31/34] dmaengine: dw: defer callbacks via channel BH
In reply to Allen PaisQuoted 4 lines · Allen Pais
Queue completed descriptors on the channel and invoke their callbacks from per-channel BH work instead of the controller tasklet. Add a synchronize hook so termination can wait for deferred callbacks before their descriptor storage is released.
This driver is so old and got a lot of stuff that may be cleaned up with converting it to use virt-dma. Have you considered that option?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 31/34] dmaengine: dw: defer callbacks via channel BH
In reply to Allen PaisQuoted 7 lines · Allen Pais
Queue completed descriptors on the channel and invoke their callbacks from per-channel BH work instead of the controller tasklet. Add a synchronize hook so termination can wait for deferred callbacks before their descriptor storage is released.
Signed-off-by Allen Pais <[email protected]>---
Quoted 118 lines
drivers/dma/dw/core.c | 42 ++++++++++++++++++++++++++++++++++-------- drivers/dma/dw/regs.h | 1 + 2 files changed, 35 insertions(+), 8 deletions(-)drivers/dma/dw/core.c +34
-8@@ -236,25 +236,24 @@ dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc,struct dma_async_tx_descriptor *txd = &desc->txd;struct dw_desc *child;unsigned long flags; -struct dmaengine_desc_callback cb;dev_vdbg (chan2dev (&dwc->chan),"descriptor %u complete\n" , txd->cookie);spin_lock_irqsave (&dwc->lock, flags);dma_cookie_complete (txd); -if (callback_required) -dmaengine_desc_get_callback (txd, &cb); -else -memset (&cb,0 ,sizeof (cb)); +list_del_init (&desc->desc_node);/* async_tx_ack */ list_for_each_entry (child, &desc->tx_list, desc_node)async_tx_ack (&child->txd);async_tx_ack (&desc->txd); -dwc_desc_put (dwc, desc); +if (callback_required) { +list_add_tail (&desc->desc_node, &dwc->completed_list); +dmaengine_schedule_bh (&dwc->chan); + }else { +dwc_desc_put (dwc, desc); + }spin_unlock_irqrestore (&dwc->lock, flags); - -dmaengine_desc_callback_invoke (&cb,NULL ); }static void dwc_complete_all (struct dw_dma *dw,struct dw_dma_chan *dwc)@@ -285,6 +284,24 @@ static void dwc_complete_all(struct dw_dma *dw, struct dw_dma_chan *dwc)dwc_descriptor_complete (dwc, desc, true); } +static void dwc_chan_bh (struct dma_chan *chan) +{ +struct dw_dma_chan *dwc =to_dw_dma_chan (chan); +struct dw_desc *desc, *_desc; +struct dmaengine_desc_callback cb; +LIST_HEAD (list); + +spin_lock_irq (&dwc->lock); +list_splice_init (&dwc->completed_list, &list); +spin_unlock_irq (&dwc->lock); + +list_for_each_entry_safe (desc, _desc, &list, desc_node) { +dmaengine_desc_get_callback (&desc->txd, &cb); +dmaengine_desc_callback_invoke (&cb,NULL ); +dwc_desc_put (dwc, desc); + } +} +/* Returns how many bytes were already received from source */ static inline u32 dwc_get_sent (struct dw_dma_chan *dwc) {@@ -965,6 +982,11 @@ static int dwc_terminate_all(struct dma_chan *chan)return 0 ; } +static void dwc_synchronize (struct dma_chan *chan) +{ +dmaengine_kill_bh (chan); +} +static struct dw_desc *dwc_find_desc (struct dw_dma_chan *dwc,dma_cookie_t c) {struct dw_desc *desc;@@ -1256,6 +1278,8 @@ int do_dma_probe(struct dw_dma_chip *chip)INIT_LIST_HEAD (&dwc->active_list);INIT_LIST_HEAD (&dwc->queue); +INIT_LIST_HEAD (&dwc->completed_list); +dmaengine_init_bh (&dwc->chan, dwc_chan_bh);channel_clear_bit (dw,CH_EN , dwc->mask);@@ -1321,6 +1345,7 @@ int do_dma_probe(struct dw_dma_chip *chip) dw->dma.device_pause = dwc_pause; dw->dma.device_resume = dwc_resume; dw->dma.device_terminate_all = dwc_terminate_all; + dw->dma.device_synchronize = dwc_synchronize; dw->dma.device_tx_status = dwc_tx_status; dw->dma.device_issue_pending = dwc_issue_pending;@@ -1374,6 +1399,7 @@ int do_dma_remove(struct dw_dma_chip *chip)list_for_each_entry_safe (dwc, _dwc, &dw->dma.channels, chan.device_node) { +dmaengine_kill_bh (&dwc->chan);list_del (&dwc->chan.device_node);channel_clear_bit (dw,CH_EN , dwc->mask); }drivers/dma/dw/regs.h +1
-1@@ -279,6 +279,7 @@ struct dw_dma_chan {unsigned long flags;struct list_head active_list;struct list_head queue; +struct list_head completed_list;unsigned int descs_allocated; --2.43.0
PATCH v3 32/34 dmaengine: hidma: defer callbacks via channel BH
In reply to Allen PaisMove descriptor callback processing out of the low-level completion path and schedule it through per-channel BH work. Drain that work while freeing channels so callbacks cannot outlive channel storage.
--- drivers/dma/qcom/hidma.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/dma/qcom/hidma.c +16 -2
@@ -90,7 +90,13 @@ static inline struct hidma_chan *to_hidma_chan(struct dma_chan *dmach)static void hidma_free (struct hidma_dev *dmadev) { -INIT_LIST_HEAD (&dmadev->ddev.channels); +struct hidma_chan *mchan, *next; + +list_for_each_entry_safe (mchan, next, &dmadev->ddev.channels, + chan.device_node) { +dmaengine_kill_bh (&mchan->chan); +list_del (&mchan->chan.device_node); + } }static unsigned int nr_desc_prm;
@@ -155,6 +161,13 @@ static void hidma_process_completed(struct hidma_chan *mchan) } } +static void hidma_chan_bh (struct dma_chan *chan) +{ +struct hidma_chan *mchan =to_hidma_chan (chan); + +hidma_process_completed (mchan); +} +/* * Called once for each submitted descriptor. * PM is locked once for each descriptor that is currently
@@ -181,7 +194,7 @@ static void hidma_callback(void *data) }spin_unlock_irqrestore (&mchan->lock, irqflags); -hidma_process_completed (mchan); +dmaengine_schedule_bh (&mchan->chan);if (queued) {pm_runtime_mark_last_busy (dmadev->ddev.dev);
@@ -203,6 +216,7 @@ static int hidma_chan_init(struct hidma_dev *dmadev, u32 dma_sig) mchan->dmadev = dmadev; mchan->chan.device = ddev;dma_cookie_init (&mchan->chan); +dmaengine_init_bh (&mchan->chan, hidma_chan_bh);INIT_LIST_HEAD (&mchan->free);INIT_LIST_HEAD (&mchan->prepared);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 32/34] dmaengine: hidma: defer callbacks via channel BH
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Use-After-Free of client callbacks and descriptors due to missing BH synchronization on channel release.
- [High] NULL pointer dereference in hidma_remove due to incorrect teardown ordering.
Pre-existing issues:
- [High] List corruption due to data race on mchan->free between channel termination and BH execution. --
--- Patch [32]: [PATCH v3 32/34] dmaengine: hidma: defer callbacks via channel BH --- commit d556674c4ac10d8d6acb039e370582921643ddd7
Author: Allen Pais <[email protected]>
dmaengine: hidma: defer callbacks via channel BH
Move descriptor callback processing out of the low-level completion path and schedule it through per-channel BH work. Drain that work while freeing channels so callbacks cannot outlive channel storage.
Quoted 5 lines
drivers/dma/qcom/hidma.c +0
-0
drivers/dma/qcom/hidma.c static inline struct hidma_chan *to_hidma_chan(struct dma_chan *dmach) · line 98
Quoted 9 lines
drivers/dma/qcom/hidma.c +5
-1@@ -91,7 +91,13 @@ static inline struct hidma_chan *to_hidma_chan(struct dma_chan *dmach)static void hidma_free (struct hidma_dev *dmadev) { -INIT_LIST_HEAD (&dmadev->ddev.channels); +struct hidma_chan *mchan, *next; + +list_for_each_entry_safe (mchan, next, &dmadev->ddev.channels, + chan.device_node) { +dmaengine_kill_bh (&mchan->chan);
[Severity: High]
Can this cause a NULL pointer dereference during device teardown?
During module unload, hidma_remove() calls hidma_ll_uninit() before hidma_free():
drivers/dma/qcom/hidma.c:hidma_remove() {
...
hidma_ll_uninit(dmadev->lldev);
hidma_free(dmadev);
...
}hidma_ll_uninit() clears the lower-level structures and sets lldev->trepool to NULL.
When hidma_free() then calls dmaengine_kill_bh(), it flushes any pending BH work, which calls hidma_process_completed() and eventually hidma_ll_status().
drivers/dma/qcom/hidma_ll.c:hidma_ll_status() {
...
tre = &lldev->trepool[tre_ch];
...
}Since lldev->trepool is already NULL, does this crash if there is pending work?
Quoted 6 lines
drivers/dma/qcom/hidma.c +2
-0+list_del (&mchan->chan.device_node); + } }static unsigned int nr_desc_prm;
drivers/dma/qcom/hidma.c static void hidma_process_completed(struct hidma_chan *mchan) · line 169
Quoted 8 lines
drivers/dma/qcom/hidma.c +5
-0@@ -156,6 +162,13 @@ static void hidma_process_completed(struct hidma_chan *mchan) } } +static void hidma_chan_bh (struct dma_chan *chan) +{ +struct hidma_chan *mchan =to_hidma_chan (chan); + +hidma_process_completed (mchan);
[Severity: High]
This is a pre-existing issue, but does moving the completion handling to an asynchronous BH significantly widen a data race window?
In hidma_terminate_channel(), descriptors are moved to the free list without holding mchan->lock:
drivers/dma/qcom/hidma.c:hidma_terminate_channel() {
...
/* move myself to free_list */
list_move(&mdesc->node, &mchan->free);
...
}If a client terminates a channel while a completion is pending, this unlocked access can run concurrently with the BH executing hidma_process_completed():
drivers/dma/qcom/hidma.c:hidma_process_completed() {
...
spin_lock_irqsave(&mchan->lock, irqflags);
list_move(&mdesc->node, &mchan->free);
spin_unlock_irqrestore(&mchan->lock, irqflags);
...
}Can this concurrent modification corrupt the mchan->free list?
Quoted 5 lines
drivers/dma/qcom/hidma.c +2
-0+} +/* * Called once for each submitted descriptor. * PM is locked once for each descriptor that is currently
[ ... ]
drivers/dma/qcom/hidma.c static int hidma_chan_init(struct hidma_dev *dmadev, u32 dma_sig) · line 220
Quoted 5 lines
drivers/dma/qcom/hidma.c +1
-0@@ -204,6 +217,7 @@ static int hidma_chan_init(struct hidma_dev *dmadev, u32 dma_sig) mchan->dmadev = dmadev; mchan->chan.device = ddev;dma_cookie_init (&mchan->chan); +dmaengine_init_bh (&mchan->chan, hidma_chan_bh);
[Severity: High]
Does this leave the BH work unsynchronized during channel release?
If a client calls dmaengine_terminate_sync() and dma_release_channel(), the driver currently lacks a device_synchronize callback, so dmaengine_terminate_sync() returns immediately.
When hidma_free_chan_resources() is called, it frees descriptors:
drivers/dma/qcom/hidma.c:hidma_free_chan_resources() {
...
hidma_terminate_channel(dmach);
...
kfree(mdesc);
...
}Since dmaengine_kill_bh() isn't called here, can an unflushed BH execute hidma_process_completed() later and cause a use-after-free on these descriptors and the client callbacks?
Quoted 3 lines
drivers/dma/qcom/hidma.c +0
-0INIT_LIST_HEAD (&mchan->free);INIT_LIST_HEAD (&mchan->prepared);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=32
Re: [PATCH v3 32/34] dmaengine: hidma: defer callbacks via channel BH
In reply to Allen PaisQuoted 14 lines · Allen Pais
Move descriptor callback processing out of the low-level completion path and schedule it through per-channel BH work. Drain that work while freeing channels so callbacks cannot outlive channel storage.
Signed-off-by Allen Pais <[email protected]>--- drivers/dma/qcom/hidma.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)drivers/dma/qcom/hidma.c +0
-0
drivers/dma/qcom/hidma.c static inline struct hidma_chan *to_hidma_chan(struct dma_chan *dmach) · line 98
Quoted 10 lines
drivers/dma/qcom/hidma.c +6
-1@@ -90,7 +90,13 @@ static inline struct hidma_chan *to_hidma_chan(struct dma_chan *dmach)static void hidma_free (struct hidma_dev *dmadev) { -INIT_LIST_HEAD (&dmadev->ddev.channels); +struct hidma_chan *mchan, *next; + +list_for_each_entry_safe (mchan, next, &dmadev->ddev.channels, + chan.device_node) { +dmaengine_kill_bh (&mchan->chan); +list_del (&mchan->chan.device_node);
origial code have not list_del(), is it fix other problem?
Frank
Quoted 38 lines
drivers/dma/qcom/hidma.c +10
-2+ } }static unsigned int nr_desc_prm;@@ -155,6 +161,13 @@ static void hidma_process_completed(struct hidma_chan *mchan) } } +static void hidma_chan_bh (struct dma_chan *chan) +{ +struct hidma_chan *mchan =to_hidma_chan (chan); + +hidma_process_completed (mchan); +} +/* * Called once for each submitted descriptor. * PM is locked once for each descriptor that is currently @@ -181,7 +194,7 @@ static void hidma_callback(void *data) }spin_unlock_irqrestore (&mchan->lock, irqflags); -hidma_process_completed (mchan); +dmaengine_schedule_bh (&mchan->chan);if (queued) {pm_runtime_mark_last_busy (dmadev->ddev.dev);@@ -203,6 +216,7 @@ static int hidma_chan_init(struct hidma_dev *dmadev, u32 dma_sig) mchan->dmadev = dmadev; mchan->chan.device = ddev;dma_cookie_init (&mchan->chan); +dmaengine_init_bh (&mchan->chan, hidma_chan_bh);INIT_LIST_HEAD (&mchan->free);INIT_LIST_HEAD (&mchan->prepared); --2.43.0
PATCH v3 33/34 dmaengine: qcom-gpi: defer callbacks via vchan
In reply to Allen PaisComplete descriptors through virt-dma instead of invoking callbacks directly from event processing. This preserves the transfer result for the shared vchan BH, which invokes the callback and frees the descriptor; drain that BH before releasing channel resources.
--- drivers/dma/qcom/gpi.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/dma/qcom/gpi.c +13 -4
@@ -981,8 +981,12 @@ static void gpi_process_imed_data_event(struct gchan *gchan, result.result =DMA_TRANS_NOERROR ; result.residue = gpi_desc->len - imed_event->length; -dma_cookie_complete (&vd->tx); -dmaengine_desc_get_callback_invoke (&vd->tx, &result); +spin_lock_irqsave (&gchan->vc.lock, flags); +list_del (&vd->node); + vd->tx_result = result; +vchan_cookie_complete (vd); +spin_unlock_irqrestore (&gchan->vc.lock, flags); +return ; gpi_free_desc:spin_lock_irqsave (&gchan->vc.lock, flags);
@@ -1060,8 +1064,12 @@ static void gpi_process_xfer_compl_event(struct gchan *gchan, result.residue = gpi_desc->len - compl_event->length;dev_dbg (gpii->gpi_dev->dev,"Residue %d\n" , result.residue); -dma_cookie_complete (&vd->tx); -dmaengine_desc_get_callback_invoke (&vd->tx, &result); +spin_lock_irqsave (&gchan->vc.lock, flags); +list_del (&vd->node); + vd->tx_result = result; +vchan_cookie_complete (vd); +spin_unlock_irqrestore (&gchan->vc.lock, flags); +return ; gpi_free_desc:spin_lock_irqsave (&gchan->vc.lock, flags);
@@ -2009,6 +2017,7 @@ static void gpi_free_chan_resources(struct dma_chan *chan)/* free all allocated memory */ gpi_free_ring (&gchan->ch_ring, gpii); +dmaengine_kill_bh (&gchan->vc.chan);vchan_free_chan_resources (&gchan->vc);kfree (gchan->config);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 33/34] dmaengine: qcom-gpi: defer callbacks via vchan
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] The driver defers completion callbacks to a bottom-half (virt-dma BH) but fails to implement the device_synchronize callback. This breaks dmaengine_terminate_sync(), allowing client callbacks to execute concurrently with client resource freeing, leading to potential use-after-free bugs.
- [High] dmaengine_kill_bh() is called after gpi_free_ring(), allowing the virt-dma bottom half to execute client callbacks while the channel's hardware ring buffer is already freed and zeroed, leading to a divide-by-zero kernel panic.
Pre-existing issues:
- [High] If a client submits multiple descriptors before calling dma_async_issue_pending(), gpi_issue_pending drops all but the last descriptor. --
--- Patch [33]: [PATCH v3 33/34] dmaengine: qcom-gpi: defer callbacks via vchan --- commit b8f9701fb8c3295335854c36b7913f03c0929404
Author: Allen Pais <[email protected]>
dmaengine: qcom-gpi: defer callbacks via vchan
Complete descriptors through virt-dma instead of invoking callbacks directly from event processing. This preserves the transfer result for the shared vchan BH, which invokes the callback and frees the descriptor; drain that BH before releasing channel resources.
Quoted 4 lines
drivers/dma/qcom/gpi.c +0
-0
[ ... ]
drivers/dma/qcom/gpi.c static void gpi_free_chan_resources(struct dma_chan *chan) · line 2020
Quoted 5 lines
drivers/dma/qcom/gpi.c +1
-0@@ -2009,6 +2017,7 @@ static void gpi_free_chan_resources(struct dma_chan *chan)/* free all allocated memory */ gpi_free_ring (&gchan->ch_ring, gpii); +dmaengine_kill_bh (&gchan->vc.chan);
[Severity: High]
Does this sequence leave a race window where the bottom half tasklet can access freed structures?
If dmaengine_kill_bh() is called after gpi_free_ring(), the virt-dma bottom half could execute client callbacks while the channel's hardware ring buffer is already freed and zeroed. If the client callback submits a new transfer, gpi_prep_slave_sg() will invoke gpi_ring_num_elements_avail(), which divides by ring->el_size. Since the ring is zeroed, would this cause a divide-by-zero kernel panic?
Could dmaengine_kill_bh() be called before tearing down hardware resources?
[Severity: High]
Since this patch defers completion callbacks to a virt-dma bottom half, how does the driver synchronize these callbacks during channel teardown?
drivers/dma/qcom/gpi.c:gpi_probe() {
...
gpi_dev->dma_device.device_free_chan_resources = gpi_free_chan_resources;
gpi_dev->dma_device.device_tx_status = dma_cookie_status;
...
}Without implementing the device_synchronize callback, does dmaengine_terminate_sync() operate as a no-op regarding synchronization of deferred callbacks? If a client terminates a channel and immediately frees its buffers, could the still-running bottom-half callback access freed memory?
Before this patch, gpi_terminate_all() acquired gpii->pm_lock, which natively synchronized with the event tasklet. Is it necessary to assign vchan_synchronize to gpi_dev->dma_device.device_synchronize to restore this safety guarantee?
[Severity: High]
This isn't a bug introduced by this patch, but looking at batched submissions in gpi_issue_pending():
drivers/dma/qcom/gpi.c:gpi_issue_pending() {
...
/* move all submitted descriptors to issued list */
spin_lock_irqsave(&gchan->vc.lock, flags);
if (vchan_issue_pending(&gchan->vc))
vd = list_last_entry(&gchan->vc.desc_issued,
struct virt_dma_desc, node);
...
}If a client submits multiple descriptors before calling dma_async_issue_pending(), does this logic drop all but the last descriptor?
Extracting only the last descriptor and queueing its TREs to the hardware ring would mean when the hardware completes this single transfer, the driver's event handler pops the first descriptor from the issued list. Could this mismatch between hardware transfers and software completions leave the remaining descriptors permanently uncompleted and corrupt data?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=33
Re: [PATCH v3 33/34] dmaengine: qcom-gpi: defer callbacks via vchan
In reply to Allen PaisQuoted 7 lines · Allen Pais
Complete descriptors through virt-dma instead of invoking callbacks directly from event processing. This preserves the transfer result for the shared vchan BH, which invokes the callback and frees the descriptor; drain that BH before releasing channel resources.
Signed-off-by Allen Pais <[email protected]>---
Quoted 48 lines
drivers/dma/qcom/gpi.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)drivers/dma/qcom/gpi.c +13
-5@@ -981,8 +981,12 @@ static void gpi_process_imed_data_event(struct gchan *gchan, result.result =DMA_TRANS_NOERROR ; result.residue = gpi_desc->len - imed_event->length; -dma_cookie_complete (&vd->tx); -dmaengine_desc_get_callback_invoke (&vd->tx, &result); +spin_lock_irqsave (&gchan->vc.lock, flags); +list_del (&vd->node); + vd->tx_result = result; +vchan_cookie_complete (vd); +spin_unlock_irqrestore (&gchan->vc.lock, flags); +return ; gpi_free_desc:spin_lock_irqsave (&gchan->vc.lock, flags);@@ -1060,8 +1064,12 @@ static void gpi_process_xfer_compl_event(struct gchan *gchan, result.residue = gpi_desc->len - compl_event->length;dev_dbg (gpii->gpi_dev->dev,"Residue %d\n" , result.residue); -dma_cookie_complete (&vd->tx); -dmaengine_desc_get_callback_invoke (&vd->tx, &result); +spin_lock_irqsave (&gchan->vc.lock, flags); +list_del (&vd->node); + vd->tx_result = result; +vchan_cookie_complete (vd); +spin_unlock_irqrestore (&gchan->vc.lock, flags); +return ; gpi_free_desc:spin_lock_irqsave (&gchan->vc.lock, flags);@@ -2009,6 +2017,7 @@ static void gpi_free_chan_resources(struct dma_chan *chan)/* free all allocated memory */ gpi_free_ring (&gchan->ch_ring, gpii); +dmaengine_kill_bh (&gchan->vc.chan);vchan_free_chan_resources (&gchan->vc);kfree (gchan->config); --2.43.0
PATCH v3 34/34 dmaengine: switchtec: use channel BH helpers
In reply to Allen PaisReplace the per-channel descriptor completion tasklet with the shared dmaengine BH helpers. Client callbacks remain in softirq context while using the common scheduling and teardown mechanism.
--- drivers/dma/switchtec_dma.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/dma/switchtec_dma.c +8 -8
@@ -133,8 +133,6 @@ struct switchtec_dma_chan {/* Serialize hardware control register access */ spinlock_t hw_ctrl_lock; -struct tasklet_struct desc_task; -/* Serialize descriptor preparation */ spinlock_t submit_lock;bool ring_active;
@@ -584,6 +582,7 @@ static void switchtec_dma_synchronize(struct dma_chan *chan)int rc; +dmaengine_kill_bh (chan);switchtec_dma_abort_desc (swdma_chan,1 ); rc =enable_channel (swdma_chan);
@@ -820,9 +819,10 @@ static int switchtec_dma_resume(struct dma_chan *chan)return ret; } -static void switchtec_dma_desc_task (unsigned long data) +static void switchtec_dma_desc_task (struct dma_chan *chan) { -struct switchtec_dma_chan *swdma_chan = (void *)data; +struct switchtec_dma_chan *swdma_chan = + container_of(chan, struct switchtec_dma_chan, dma_chan);switchtec_dma_cleanup_completed (swdma_chan); }
@@ -832,7 +832,7 @@ static irqreturn_t switchtec_dma_isr(int irq, void *chan)struct switchtec_dma_chan *swdma_chan = chan;if (swdma_chan->comp_ring_active) -tasklet_schedule (&swdma_chan->desc_task); +dmaengine_schedule_bh (&swdma_chan->dma_chan);return IRQ_HANDLED ; }
@@ -1041,6 +1041,7 @@ static void switchtec_dma_free_chan_resources(struct dma_chan *chan)spin_unlock_bh (&swdma_chan->complete_lock);switchtec_dma_chan_stop (swdma_chan); +dmaengine_kill_bh (chan);switchtec_dma_abort_desc (swdma_chan,0 );switchtec_dma_free_desc (swdma_chan);
@@ -1067,8 +1068,6 @@ static int switchtec_dma_chan_init(struct switchtec_dma_dev *swdma_dev,spin_lock_init (&swdma_chan->hw_ctrl_lock);spin_lock_init (&swdma_chan->submit_lock);spin_lock_init (&swdma_chan->complete_lock); -tasklet_init (&swdma_chan->desc_task, switchtec_dma_desc_task, - (unsigned long )swdma_chan); swdma_chan->mmio_chan_fw = swdma_dev->bar + SWITCHTEC_DMAC_CHAN_CFG_STS_OFFSET +
@@ -1116,6 +1115,7 @@ static int switchtec_dma_chan_init(struct switchtec_dma_dev *swdma_dev, chan = &swdma_chan->dma_chan; chan->device = dma;dma_cookie_init (chan); +dmaengine_init_bh (chan, switchtec_dma_desc_task);list_add_tail (&chan->device_node, &dma->channels);
@@ -1138,7 +1138,7 @@ static int switchtec_dma_chan_free(struct pci_dev *pdev,spin_unlock_bh (&swdma_chan->complete_lock);pci_free_irq (pdev, swdma_chan->irq, swdma_chan); -tasklet_kill (&swdma_chan->desc_task); +dmaengine_kill_bh (&swdma_chan->dma_chan);switchtec_dma_chan_stop (swdma_chan);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 34/34] dmaengine: switchtec: use channel BH helpers
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Stale hardware completion state is incorrectly processed after channel synchronization, leading to data corruption. --
--- Patch [34]: [PATCH v3 34/34] dmaengine: switchtec: use channel BH helpers --- commit d57e70e2d9fa1493ca8fd6bc467970ca44d80a8e
Author: Allen Pais <[email protected]>
Subject: dmaengine: switchtec: use channel BH helpers
Replace the per-channel descriptor completion tasklet with the shared dmaengine BH helpers. Client callbacks remain in softirq context while using the common scheduling and teardown mechanism.
Quoted 4 lines
drivers/dma/switchtec_dma.c +0
-0
[ ... ]
drivers/dma/switchtec_dma.c static void switchtec_dma_synchronize(struct dma_chan *chan) · line 588
Quoted 8 lines
drivers/dma/switchtec_dma.c +1
-0@@ -584,6 +582,7 @@ static void switchtec_dma_synchronize(struct dma_chan *chan)int rc; +dmaengine_kill_bh (chan);switchtec_dma_abort_desc (swdma_chan,1 ); rc =enable_channel (swdma_chan);
[Severity: High]
This isn't a bug introduced by this patch, but is it possible for stale hardware completion state to be incorrectly processed after channel synchronization?
Further down in switchtec_dma_synchronize(), the software state variables are reset:
swdma_chan->comp_ring_active = true; swdma_chan->phase_tag = 0; swdma_chan->tail = 0; swdma_chan->cq_tail = 0; swdma_chan->cid = 0;
However, the hardware completion queue memory (swdma_chan->hw_cq) is not cleared. If previous hardware completions left non-zero phase tags in the completion queue, would switchtec_dma_cleanup_completed() see le16_to_cpu(phase_tag) != swdma_chan->phase_tag and process the stale entries as new completions?
This might cause the client driver to read incomplete data or reuse buffers that are still under active DMA.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=34
Re: [PATCH v3 34/34] dmaengine: switchtec: use channel BH helpers
In reply to Allen PaisQuoted 7 lines · Allen Pais
Replace the per-channel descriptor completion tasklet with the shared dmaengine BH helpers. Client callbacks remain in softirq context while using the common scheduling and teardown mechanism.
Signed-off-by Allen Pais <[email protected]>Reviewed-by Logan Gunthorpe <[email protected]>---
Quoted 83 lines
drivers/dma/switchtec_dma.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)drivers/dma/switchtec_dma.c +8
-9@@ -133,8 +133,6 @@ struct switchtec_dma_chan {/* Serialize hardware control register access */ spinlock_t hw_ctrl_lock; -struct tasklet_struct desc_task; -/* Serialize descriptor preparation */ spinlock_t submit_lock;bool ring_active;@@ -584,6 +582,7 @@ static void switchtec_dma_synchronize(struct dma_chan *chan)int rc; +dmaengine_kill_bh (chan);switchtec_dma_abort_desc (swdma_chan,1 ); rc =enable_channel (swdma_chan);@@ -820,9 +819,10 @@ static int switchtec_dma_resume(struct dma_chan *chan)return ret; } -static void switchtec_dma_desc_task (unsigned long data) +static void switchtec_dma_desc_task (struct dma_chan *chan) { -struct switchtec_dma_chan *swdma_chan = (void *)data; +struct switchtec_dma_chan *swdma_chan = + container_of(chan, struct switchtec_dma_chan, dma_chan);switchtec_dma_cleanup_completed (swdma_chan); }@@ -832,7 +832,7 @@ static irqreturn_t switchtec_dma_isr(int irq, void *chan)struct switchtec_dma_chan *swdma_chan = chan;if (swdma_chan->comp_ring_active) -tasklet_schedule (&swdma_chan->desc_task); +dmaengine_schedule_bh (&swdma_chan->dma_chan);return IRQ_HANDLED ; }@@ -1041,6 +1041,7 @@ static void switchtec_dma_free_chan_resources(struct dma_chan *chan)spin_unlock_bh (&swdma_chan->complete_lock);switchtec_dma_chan_stop (swdma_chan); +dmaengine_kill_bh (chan);switchtec_dma_abort_desc (swdma_chan,0 );switchtec_dma_free_desc (swdma_chan);@@ -1067,8 +1068,6 @@ static int switchtec_dma_chan_init(struct switchtec_dma_dev *swdma_dev,spin_lock_init (&swdma_chan->hw_ctrl_lock);spin_lock_init (&swdma_chan->submit_lock);spin_lock_init (&swdma_chan->complete_lock); -tasklet_init (&swdma_chan->desc_task, switchtec_dma_desc_task, - (unsigned long )swdma_chan); swdma_chan->mmio_chan_fw = swdma_dev->bar + SWITCHTEC_DMAC_CHAN_CFG_STS_OFFSET +@@ -1116,6 +1115,7 @@ static int switchtec_dma_chan_init(struct switchtec_dma_dev *swdma_dev, chan = &swdma_chan->dma_chan; chan->device = dma;dma_cookie_init (chan); +dmaengine_init_bh (chan, switchtec_dma_desc_task);list_add_tail (&chan->device_node, &dma->channels);@@ -1138,7 +1138,7 @@ static int switchtec_dma_chan_free(struct pci_dev *pdev,spin_unlock_bh (&swdma_chan->complete_lock);pci_free_irq (pdev, swdma_chan->irq, swdma_chan); -tasklet_kill (&swdma_chan->desc_task); +dmaengine_kill_bh (&swdma_chan->dma_chan);switchtec_dma_chan_stop (swdma_chan); --2.43.0
Re: [PATCH v3 00/34] dmaengine: migrate channel tasklets to WQ_BH
In reply to Allen PaisQuoted 22 lines · Allen Pais
Hi Arnd, Vinod and Frank,
This series moves DMAengine client completion bottom halves from private tasklets to a common per-channel API backed by
WQ_BH.The first patch introduces the dmaengine_*_bh() API with a tasklet backend and converts virt-dma to it. It also updates every driver that directly accesses the removed
virt_dma_chantasklet, keeping the patch buildable on its own. This separates the driver-facing API from its implementation without changing callback context.The second patch switches that backend to a dedicated
WQ_BH|WQ_PERCPUworkqueue.WQ_BHkeeps callbacks in softirq context, while the common API centralizes initialization, scheduling, and synchronization. The workqueue helpers remain internal to DMAengine, anddmaengine_kill_bh()drains scheduled callbacks to preservetasklet_kill()semantics.The remaining patches convert driver-owned channel completion tasklets. Tasklets used for controller-level processing, recovery, or other non-client-callback work are deliberately left alone because the appropriate replacement may differ by driver.
Quoted 5 lines
As agreed in the RFC discussion, selecting hardirq callback delivery is a separate API change and is not part of this series.
Earlier discussion:
https://lore.kernel.org/all/[email protected]/
Never reply with a new version of such a long series into the same thread (of the previous version of it), it's now a mess in the mail thread.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 00/34] dmaengine: migrate channel tasklets to WQ_BH
In reply to Allen PaisQuoted 16 lines · Allen Pais
This series moves DMAengine client completion bottom halves from private tasklets to a common per-channel API backed by
WQ_BH.The first patch introduces the dmaengine_*_bh() API with a tasklet backend and converts virt-dma to it. It also updates every driver that directly accesses the removed
virt_dma_chantasklet, keeping the patch buildable on its own. This separates the driver-facing API from its implementation without changing callback context.The second patch switches that backend to a dedicated
WQ_BH|WQ_PERCPUworkqueue.WQ_BHkeeps callbacks in softirq context, while the common API centralizes initialization, scheduling, and synchronization. The workqueue helpers remain internal to DMAengine, anddmaengine_kill_bh()drains scheduled callbacks to preservetasklet_kill()semantics.
Quoted 4 lines
The remaining patches convert driver-owned channel completion tasklets. Tasklets used for controller-level processing, recovery, or other non-client-callback work are deliberately left alone because the appropriate replacement may differ by driver.
Right, I would actually expect that virt-dma (and others will follow the example) will switch to threaded IRQ instead of tasklets.
Quoted 2 lines
As agreed in the RFC discussion, selecting hardirq callback delivery is a separate API change and is not part of this series.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 00/34] dmaengine: migrate channel tasklets to WQ_BH
Quoted 15 lines
Quoted 15 lines
This series moves DMAengine client completion bottom halves from private tasklets to a common per-channel API backed by
WQ_BH.The first patch introduces the dmaengine_*_bh() API with a tasklet backend and converts virt-dma to it. It also updates every driver that directly accesses the removed
virt_dma_chantasklet, keeping the patch buildable on its own. This separates the driver-facing API from its implementation without changing callback context.The second patch switches that backend to a dedicated
WQ_BH|WQ_PERCPUworkqueue.WQ_BHkeeps callbacks in softirq context, while the common API centralizes initialization, scheduling, and synchronization. The workqueue helpers remain internal to DMAengine, anddmaengine_kill_bh()drains scheduled callbacks to preservetasklet_kill()semantics.
Quoted 7 lines
Quoted 4 lines
The remaining patches convert driver-owned channel completion tasklets. Tasklets used for controller-level processing, recovery, or other non-client-callback work are deliberately left alone because the appropriate replacement may differ by driver.
Right, I would actually expect that virt-dma (and others will follow the example) will switch to threaded IRQ instead of tasklets.
Thanks, Andy.
I had not considered a full virt-dma conversion for this series. Looking at the driver, that would also involve its descriptor pool, queue and active lists, software LLP and cyclic handling, and residue reporting. It would therefore be a substantially broader change than moving callback delivery to the common channel BH.
My intention here was to leave the existing descriptor lifecycle and scheduling unchanged and only move callback invocation out of the controller tasklet. I think converting the driver to virt-dma would be better handled as a separate series with hardware testing.
If you would prefer not to add the completed list ahead of such a conversion, I can drop this patch from the current series and leave the DW driver unchanged for now.
Regards,
Allen
Quoted 9 lines
Quoted 3 lines
As agreed in the RFC discussion, selecting hardirq callback delivery is a separate API change and is not part of this series.
--
With Best Regards,
Andy Shevchenko
Signature · 1 line
- Allen
Re: [PATCH v3 00/34] dmaengine: migrate channel tasklets to WQ_BH
On Tue, Aug 11, 2026 at 01:44:49PM -0700, Allen wrote:
...
Quoted 14 lines
Quoted 7 lines
Quoted 4 lines
The remaining patches convert driver-owned channel completion tasklets. Tasklets used for controller-level processing, recovery, or other non-client-callback work are deliberately left alone because the appropriate replacement may differ by driver.
Right, I would actually expect that virt-dma (and others will follow the example) will switch to threaded IRQ instead of tasklets.
I had not considered a full virt-dma conversion for this series. Looking at the driver, that would also involve its descriptor pool, queue and active lists, software LLP and cyclic handling, and residue reporting. It would therefore be a substantially broader change than moving callback delivery to the common channel BH.
Quoted 8 lines
My intention here was to leave the existing descriptor lifecycle and scheduling unchanged and only move callback invocation out of the controller tasklet. I think converting the driver to virt-dma would be better handled as a separate series with hardware testing.
If you would prefer not to add the completed list ahead of such a conversion, I can drop this patch from the current series and leave the DW driver unchanged for now.
I think this is unneeded churn for DW DMA driver. It requires a much bigger refactoring and cleaning up.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 00/34] dmaengine: migrate channel tasklets to WQ_BH
In reply to Allen PaisQuoted 159 lines · Allen Pais
Hi Arnd, Vinod and Frank,
This series moves DMAengine client completion bottom halves from private tasklets to a common per-channel API backed by
WQ_BH.The first patch introduces the dmaengine_*_bh() API with a tasklet backend and converts virt-dma to it. It also updates every driver that directly accesses the removed
virt_dma_chantasklet, keeping the patch buildable on its own. This separates the driver-facing API from its implementation without changing callback context.The second patch switches that backend to a dedicated
WQ_BH|WQ_PERCPUworkqueue.WQ_BHkeeps callbacks in softirq context, while the common API centralizes initialization, scheduling, and synchronization. The workqueue helpers remain internal to DMAengine, anddmaengine_kill_bh()drains scheduled callbacks to preservetasklet_kill()semantics.The remaining patches convert driver-owned channel completion tasklets. Tasklets used for controller-level processing, recovery, or other non-client-callback work are deliberately left alone because the appropriate replacement may differ by driver.
As agreed in the RFC discussion, selecting hardirq callback delivery is a separate API change and is not part of this series.
Earlier discussion:
https://lore.kernel.org/all/[email protected]/v2:
https://lore.kernel.org/all/[email protected]/Changes since v2:
- rename the new public helpers and callback type from dma_chan_* to dmaengine_* as requested by Vinod
- update all directvirt_dma_chantasklet users in patch 1, fixing the intermediate build failures reported by Sashiko
- fold the resulting 30 empty teardown patches, reducing the series from 64 to 34 patches without dropping any driver changes
- rebase from Linux 7.2-rc5 tod58772d8520c(latest Linus master)Review tags retained on unchanged standalone patches:
- 09/34 IOAT: Acked-by Dave Jiang
- 17/34 STE DMA40: Reviewed-by Linus Walleij
- 27/34 PLX DMA and 34/34 Switchtec: Reviewed-by Logan GunthorpeReview tags received on v2 patches now folded into 01/34:
- v2 41/64 HSU: Reviewed-by Andy Shevchenko
- v2 60/64 BAM DMA: Acked-by Bartosz GolaszewskiThe HSU and BAM DMA changes remain in 01/34, but those patch-specific trailers are not attached to the substantially broader 35-file patch. Andy and Bartosz are copied here and on 01/34 for visibility.
Testing:
-x86_64olddefconfig, make -j$(nproc) W=1drivers/dma/
- the same DMA build with patch 1 applied independently
-scripts/checkpatch.pl--strict on all 34 patchesAllen Pais (34):
dmaengine: add tasklet-backed channel BH helpers
dmaengine: back channel BH helpers withWQ_BH
dmaengine: apple-admac: use dmaengine BH callback
dmaengine:at_xdmac: move irq bottom half to dmaengine BH
dmaengine: ep93xx: hook callbacks via dmaengine BH
dmaengine: fsldma: migrate tasklet to dmaengine BH
dmaengine:fsl_raid: run completions via dmaengine BH
dmaengine: imx-dma: flip per-chan tasklet to dmaengine BH
dmaengine: ioat: convert cleanup tasklet to dmaengine BH
dmaengine:mmp_pdma: replace per-chan tasklet with dmaengine BH
dmaengine:mmp_tdma: hook completions to dmaengine BH
dmaengine:mv_xor: convert irq tasklet to dmaengine BH
dmaengine: mxs-dma: use dmaengine BH scheduling
dmaengine: nbpfaxi: switch callbacks to dmaengine BH
dmaengine:pch_dma: convert tasklet to dmaengine BH
dmaengine: ppc4xx: replace irq tasklet with dmaengine BH
dmaengine:ste_dma40: convert per-channel tasklet to dmaengine BH
dmaengine: xgene-dma: wire descriptor cleanup to dmaengine BH
dmaengine: xilinx-dma: use dmaengine BH instead of tasklets
dmaengine: xilinx-dpdma: kill vchan BH on remove
dmaengine: zynqmp-dma: switch completion tasklet to dmaengine BH
dmaengine: tegra20-apb: use channel BH helpers
dmaengine:timb_dma: route callbacks via channel BH
dmaengine: txx9dmac: route callbacks via channel BH
dmaengine:mv_xor_v2: use channel BH helpers
dmaengine: mpc512x: route callbacks via channel BH
dmaengine:plx_dma: use channel BH helpers
dmaengine: sf-pdma: route error callbacks through channel BH
dmaengine: pl330: route callbacks via channel BH
dmaengine: altera-msgdma: use channel BH helpers
dmaengine: dw: defer callbacks via channel BH
dmaengine: hidma: defer callbacks via channel BH
dmaengine: qcom-gpi: defer callbacks via vchan
dmaengine: switchtec: use channel BH helpersdrivers/dma/altera-msgdma.c | 14 +-- drivers/dma/apple-admac.c | 16 ++-- drivers/dma/at_xdmac.c | 13 ++- drivers/dma/bcm2835-dma.c | 2 +- drivers/dma/dma-axi-dmac.c | 10 ++- drivers/dma/dma-jz4780.c | 2 +- drivers/dma/dmaengine.c | 89 ++++++++++++++++++- .../dma/dw-axi-dmac/dw-axi-dmac-platform.c | 2 +- drivers/dma/dw-edma/dw-edma-core.c | 2 +- drivers/dma/dw/core.c | 42 +++++++-- drivers/dma/dw/regs.h | 1 + drivers/dma/ep93xx_dma.c | 12 ++- drivers/dma/fsl-edma-common.c | 2 +- drivers/dma/fsl-qdma.c | 2 +- drivers/dma/fsl_raid.c | 11 +-- drivers/dma/fsl_raid.h | 1 - drivers/dma/fsldma.c | 10 +-- drivers/dma/fsldma.h | 1 - drivers/dma/hisi_dma.c | 2 +- drivers/dma/hsu/hsu.c | 2 +- drivers/dma/idma64.c | 4 +- drivers/dma/img-mdc-dma.c | 2 +- drivers/dma/imx-dma.c | 26 +++--- drivers/dma/imx-sdma.c | 4 +- drivers/dma/ioat/dma.c | 14 +-- drivers/dma/ioat/dma.h | 3 +- drivers/dma/ioat/init.c | 2 +- drivers/dma/k3dma.c | 2 +- drivers/dma/loongson/loongson1-apb-dma.c | 2 +- drivers/dma/mediatek/mtk-cqdma.c | 2 +- drivers/dma/mediatek/mtk-hsdma.c | 2 +- drivers/dma/mediatek/mtk-uart-apdma.c | 4 +- drivers/dma/mmp_pdma.c | 13 ++- drivers/dma/mmp_tdma.c | 9 +- drivers/dma/mpc512x_dma.c | 74 +++++++++------ drivers/dma/mv_xor.c | 12 +-- drivers/dma/mv_xor.h | 2 - drivers/dma/mv_xor_v2.c | 20 ++--- drivers/dma/mxs-dma.c | 11 ++- drivers/dma/nbpfaxi.c | 13 ++- drivers/dma/owl-dma.c | 2 +- drivers/dma/pch_dma.c | 14 +-- drivers/dma/pl330.c | 18 ++-- drivers/dma/plx_dma.c | 12 +-- drivers/dma/ppc4xx/adma.c | 14 +-- drivers/dma/ppc4xx/adma.h | 2 - drivers/dma/pxa_dma.c | 2 +- drivers/dma/qcom/bam_dma.c | 4 +- drivers/dma/qcom/gpi.c | 17 +++- drivers/dma/qcom/hidma.c | 18 +++- drivers/dma/qcom/qcom_adm.c | 4 +- drivers/dma/sa11x0-dma.c | 2 +- drivers/dma/sf-pdma/sf-pdma.c | 14 ++- drivers/dma/sprd-dma.c | 2 +- drivers/dma/st_fdma.c | 2 +- drivers/dma/ste_dma40.c | 13 ++- drivers/dma/sun6i-dma.c | 2 +- drivers/dma/switchtec_dma.c | 16 ++-- drivers/dma/tegra186-gpc-dma.c | 2 +- drivers/dma/tegra20-apb-dma.c | 18 ++-- drivers/dma/tegra210-adma.c | 2 +- drivers/dma/ti/edma.c | 2 +- drivers/dma/ti/k3-udma.c | 12 +-- drivers/dma/ti/omap-dma.c | 2 +- drivers/dma/timb_dma.c | 21 +++--
Quoted 8 lines
drivers/dma/txx9dmac.c | 12 +-- drivers/dma/txx9dmac.h | 1 - drivers/dma/virt-dma.c | 12 +-- drivers/dma/virt-dma.h | 7 +- drivers/dma/xgene-dma.c | 19 ++-- drivers/dma/xilinx/xilinx_dma.c | 20 ++--- drivers/dma/xilinx/xilinx_dpdma.c | 1 + drivers/dma/xilinx/zynqmp_dma.c | 19 ++--
There are some dmaengine code out of drivers/dma tree. Do you plan to convert it also
Frank
Quoted 5 lines
include/linux/dmaengine.h | 28 ++++++ 74 files changed, 482 insertions(+), 311 deletions(-)--
2.43.0
Re: [PATCH v3 00/34] dmaengine: migrate channel tasklets to WQ_BH
Quoted 167 lines
Quoted 158 lines
This series moves DMAengine client completion bottom halves from private tasklets to a common per-channel API backed by
WQ_BH.The first patch introduces the dmaengine_*_bh() API with a tasklet backend and converts virt-dma to it. It also updates every driver that directly accesses the removed
virt_dma_chantasklet, keeping the patch buildable on its own. This separates the driver-facing API from its implementation without changing callback context.The second patch switches that backend to a dedicated
WQ_BH|WQ_PERCPUworkqueue.WQ_BHkeeps callbacks in softirq context, while the common API centralizes initialization, scheduling, and synchronization. The workqueue helpers remain internal to DMAengine, anddmaengine_kill_bh()drains scheduled callbacks to preservetasklet_kill()semantics.The remaining patches convert driver-owned channel completion tasklets. Tasklets used for controller-level processing, recovery, or other non-client-callback work are deliberately left alone because the appropriate replacement may differ by driver.
As agreed in the RFC discussion, selecting hardirq callback delivery is a separate API change and is not part of this series.
Earlier discussion:
https://lore.kernel.org/all/[email protected]/v2:
https://lore.kernel.org/all/[email protected]/Changes since v2:
- rename the new public helpers and callback type from dma_chan_* to dmaengine_* as requested by Vinod
- update all directvirt_dma_chantasklet users in patch 1, fixing the intermediate build failures reported by Sashiko
- fold the resulting 30 empty teardown patches, reducing the series from 64 to 34 patches without dropping any driver changes
- rebase from Linux 7.2-rc5 tod58772d8520c(latest Linus master)Review tags retained on unchanged standalone patches:
- 09/34 IOAT: Acked-by Dave Jiang
- 17/34 STE DMA40: Reviewed-by Linus Walleij
- 27/34 PLX DMA and 34/34 Switchtec: Reviewed-by Logan GunthorpeReview tags received on v2 patches now folded into 01/34:
- v2 41/64 HSU: Reviewed-by Andy Shevchenko
- v2 60/64 BAM DMA: Acked-by Bartosz GolaszewskiThe HSU and BAM DMA changes remain in 01/34, but those patch-specific trailers are not attached to the substantially broader 35-file patch. Andy and Bartosz are copied here and on 01/34 for visibility.
Testing:
-x86_64olddefconfig, make -j$(nproc) W=1drivers/dma/
- the same DMA build with patch 1 applied independently
-scripts/checkpatch.pl--strict on all 34 patchesAllen Pais (34):
dmaengine: add tasklet-backed channel BH helpers
dmaengine: back channel BH helpers withWQ_BH
dmaengine: apple-admac: use dmaengine BH callback
dmaengine:at_xdmac: move irq bottom half to dmaengine BH
dmaengine: ep93xx: hook callbacks via dmaengine BH
dmaengine: fsldma: migrate tasklet to dmaengine BH
dmaengine:fsl_raid: run completions via dmaengine BH
dmaengine: imx-dma: flip per-chan tasklet to dmaengine BH
dmaengine: ioat: convert cleanup tasklet to dmaengine BH
dmaengine:mmp_pdma: replace per-chan tasklet with dmaengine BH
dmaengine:mmp_tdma: hook completions to dmaengine BH
dmaengine:mv_xor: convert irq tasklet to dmaengine BH
dmaengine: mxs-dma: use dmaengine BH scheduling
dmaengine: nbpfaxi: switch callbacks to dmaengine BH
dmaengine:pch_dma: convert tasklet to dmaengine BH
dmaengine: ppc4xx: replace irq tasklet with dmaengine BH
dmaengine:ste_dma40: convert per-channel tasklet to dmaengine BH
dmaengine: xgene-dma: wire descriptor cleanup to dmaengine BH
dmaengine: xilinx-dma: use dmaengine BH instead of tasklets
dmaengine: xilinx-dpdma: kill vchan BH on remove
dmaengine: zynqmp-dma: switch completion tasklet to dmaengine BH
dmaengine: tegra20-apb: use channel BH helpers
dmaengine:timb_dma: route callbacks via channel BH
dmaengine: txx9dmac: route callbacks via channel BH
dmaengine:mv_xor_v2: use channel BH helpers
dmaengine: mpc512x: route callbacks via channel BH
dmaengine:plx_dma: use channel BH helpers
dmaengine: sf-pdma: route error callbacks through channel BH
dmaengine: pl330: route callbacks via channel BH
dmaengine: altera-msgdma: use channel BH helpers
dmaengine: dw: defer callbacks via channel BH
dmaengine: hidma: defer callbacks via channel BH
dmaengine: qcom-gpi: defer callbacks via vchan
dmaengine: switchtec: use channel BH helpersdrivers/dma/altera-msgdma.c | 14 +-- drivers/dma/apple-admac.c | 16 ++-- drivers/dma/at_xdmac.c | 13 ++- drivers/dma/bcm2835-dma.c | 2 +- drivers/dma/dma-axi-dmac.c | 10 ++- drivers/dma/dma-jz4780.c | 2 +- drivers/dma/dmaengine.c | 89 ++++++++++++++++++- .../dma/dw-axi-dmac/dw-axi-dmac-platform.c | 2 +- drivers/dma/dw-edma/dw-edma-core.c | 2 +- drivers/dma/dw/core.c | 42 +++++++-- drivers/dma/dw/regs.h | 1 + drivers/dma/ep93xx_dma.c | 12 ++- drivers/dma/fsl-edma-common.c | 2 +- drivers/dma/fsl-qdma.c | 2 +- drivers/dma/fsl_raid.c | 11 +-- drivers/dma/fsl_raid.h | 1 - drivers/dma/fsldma.c | 10 +-- drivers/dma/fsldma.h | 1 - drivers/dma/hisi_dma.c | 2 +- drivers/dma/hsu/hsu.c | 2 +- drivers/dma/idma64.c | 4 +- drivers/dma/img-mdc-dma.c | 2 +- drivers/dma/imx-dma.c | 26 +++--- drivers/dma/imx-sdma.c | 4 +- drivers/dma/ioat/dma.c | 14 +-- drivers/dma/ioat/dma.h | 3 +- drivers/dma/ioat/init.c | 2 +- drivers/dma/k3dma.c | 2 +- drivers/dma/loongson/loongson1-apb-dma.c | 2 +- drivers/dma/mediatek/mtk-cqdma.c | 2 +- drivers/dma/mediatek/mtk-hsdma.c | 2 +- drivers/dma/mediatek/mtk-uart-apdma.c | 4 +- drivers/dma/mmp_pdma.c | 13 ++- drivers/dma/mmp_tdma.c | 9 +- drivers/dma/mpc512x_dma.c | 74 +++++++++------ drivers/dma/mv_xor.c | 12 +-- drivers/dma/mv_xor.h | 2 - drivers/dma/mv_xor_v2.c | 20 ++--- drivers/dma/mxs-dma.c | 11 ++- drivers/dma/nbpfaxi.c | 13 ++- drivers/dma/owl-dma.c | 2 +- drivers/dma/pch_dma.c | 14 +-- drivers/dma/pl330.c | 18 ++-- drivers/dma/plx_dma.c | 12 +-- drivers/dma/ppc4xx/adma.c | 14 +-- drivers/dma/ppc4xx/adma.h | 2 - drivers/dma/pxa_dma.c | 2 +- drivers/dma/qcom/bam_dma.c | 4 +- drivers/dma/qcom/gpi.c | 17 +++- drivers/dma/qcom/hidma.c | 18 +++- drivers/dma/qcom/qcom_adm.c | 4 +- drivers/dma/sa11x0-dma.c | 2 +- drivers/dma/sf-pdma/sf-pdma.c | 14 ++- drivers/dma/sprd-dma.c | 2 +- drivers/dma/st_fdma.c | 2 +- drivers/dma/ste_dma40.c | 13 ++- drivers/dma/sun6i-dma.c | 2 +- drivers/dma/switchtec_dma.c | 16 ++-- drivers/dma/tegra186-gpc-dma.c | 2 +- drivers/dma/tegra20-apb-dma.c | 18 ++-- drivers/dma/tegra210-adma.c | 2 +- drivers/dma/ti/edma.c | 2 +- drivers/dma/ti/k3-udma.c | 12 +-- drivers/dma/ti/omap-dma.c | 2 +- drivers/dma/timb_dma.c | 21 +++--Quoted 8 lines
drivers/dma/txx9dmac.c | 12 +-- drivers/dma/txx9dmac.h | 1 - drivers/dma/virt-dma.c | 12 +-- drivers/dma/virt-dma.h | 7 +- drivers/dma/xgene-dma.c | 19 ++-- drivers/dma/xilinx/xilinx_dma.c | 20 ++--- drivers/dma/xilinx/xilinx_dpdma.c | 1 + drivers/dma/xilinx/zynqmp_dma.c | 19 ++--
Quoted 4 lines
There are some dmaengine code out of
drivers/dmatree. Do you plan to convert it alsoFrank
Apologies for the delayed response. yes. There's a handful of
dmaengine client-completion
tasklets outside drivers/dma/ as well. Since this series is already queued, I'd rather not grow
it further at this point. I'll send conversions for those as a follow-up series once this lands.
Thanks,
Allen
Quoted 6 lines
Quoted 6 lines
include/linux/dmaengine.h | 28 ++++++ 74 files changed, 482 insertions(+), 311 deletions(-)--
2.43.0
Signature · 1 line
- Allen
Vinod Koul
maintainerRe: [PATCH v3 00/34] dmaengine: migrate channel tasklets to WQ_BH
In reply to Allen PaisQuoted 4 lines · Allen Pais
Hi Arnd, Vinod and Frank,
This series moves DMAengine client completion bottom halves from private tasklets to a common per-channel API backed by
WQ_BH.
Hey Allen,
Any update, I am looking to pick updated patchset for this. Can you post v4?
Signature · 1 line
~Vinod
Re: [PATCH v3 00/34] dmaengine: migrate channel tasklets to WQ_BH
HI Vinod,
Quoted 5 lines
Hey Allen,
Any update, I am looking to pick updated patchset for this. Can you post v4?
Almost ready, will have it posted early tomorrow.
Thanks,
Allen