Skip to content

Commit 6dba6ec

Browse files
committed
Merge tag 'dmaengine-fixes-3.14-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/dmaengine
Pull dmaengine fixes from Dan Williams: "Fix tasklet lifetime management in the ioat driver causing ksoftirqd to spin indefinitely. References: https://lkml.org/lkml/2014/1/27/282 https://lkml.org/lkml/2014/2/19/672" * tag 'dmaengine-fixes-3.14-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/dmaengine: ioat: fix tasklet tear down
2 parents e4cc60c + da87ca4 commit 6dba6ec

4 files changed

Lines changed: 54 additions & 13 deletions

File tree

‎drivers/dma/ioat/dma.c‎

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ static irqreturn_t ioat_dma_do_interrupt(int irq, void *data)
7777
attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET);
7878
for_each_set_bit(bit, &attnstatus, BITS_PER_LONG) {
7979
chan = ioat_chan_by_index(instance, bit);
80-
tasklet_schedule(&chan->cleanup_task);
80+
if (test_bit(IOAT_RUN, &chan->state))
81+
tasklet_schedule(&chan->cleanup_task);
8182
}
8283

8384
writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
@@ -93,7 +94,8 @@ static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)
9394
{
9495
struct ioat_chan_common *chan = data;
9596

96-
tasklet_schedule(&chan->cleanup_task);
97+
if (test_bit(IOAT_RUN, &chan->state))
98+
tasklet_schedule(&chan->cleanup_task);
9799

98100
return IRQ_HANDLED;
99101
}
@@ -116,7 +118,6 @@ void ioat_init_channel(struct ioatdma_device *device, struct ioat_chan_common *c
116118
chan->timer.function = device->timer_fn;
117119
chan->timer.data = data;
118120
tasklet_init(&chan->cleanup_task, device->cleanup_fn, data);
119-
tasklet_disable(&chan->cleanup_task);
120121
}
121122

122123
/**
@@ -354,13 +355,49 @@ static int ioat1_dma_alloc_chan_resources(struct dma_chan *c)
354355
writel(((u64) chan->completion_dma) >> 32,
355356
chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
356357

357-
tasklet_enable(&chan->cleanup_task);
358+
set_bit(IOAT_RUN, &chan->state);
358359
ioat1_dma_start_null_desc(ioat); /* give chain to dma device */
359360
dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n",
360361
__func__, ioat->desccount);
361362
return ioat->desccount;
362363
}
363364

365+
void ioat_stop(struct ioat_chan_common *chan)
366+
{
367+
struct ioatdma_device *device = chan->device;
368+
struct pci_dev *pdev = device->pdev;
369+
int chan_id = chan_num(chan);
370+
struct msix_entry *msix;
371+
372+
/* 1/ stop irq from firing tasklets
373+
* 2/ stop the tasklet from re-arming irqs
374+
*/
375+
clear_bit(IOAT_RUN, &chan->state);
376+
377+
/* flush inflight interrupts */
378+
switch (device->irq_mode) {
379+
case IOAT_MSIX:
380+
msix = &device->msix_entries[chan_id];
381+
synchronize_irq(msix->vector);
382+
break;
383+
case IOAT_MSI:
384+
case IOAT_INTX:
385+
synchronize_irq(pdev->irq);
386+
break;
387+
default:
388+
break;
389+
}
390+
391+
/* flush inflight timers */
392+
del_timer_sync(&chan->timer);
393+
394+
/* flush inflight tasklet runs */
395+
tasklet_kill(&chan->cleanup_task);
396+
397+
/* final cleanup now that everything is quiesced and can't re-arm */
398+
device->cleanup_fn((unsigned long) &chan->common);
399+
}
400+
364401
/**
365402
* ioat1_dma_free_chan_resources - release all the descriptors
366403
* @chan: the channel to be cleaned
@@ -379,9 +416,7 @@ static void ioat1_dma_free_chan_resources(struct dma_chan *c)
379416
if (ioat->desccount == 0)
380417
return;
381418

382-
tasklet_disable(&chan->cleanup_task);
383-
del_timer_sync(&chan->timer);
384-
ioat1_cleanup(ioat);
419+
ioat_stop(chan);
385420

386421
/* Delay 100ms after reset to allow internal DMA logic to quiesce
387422
* before removing DMA descriptor resources.
@@ -526,8 +561,11 @@ ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
526561
static void ioat1_cleanup_event(unsigned long data)
527562
{
528563
struct ioat_dma_chan *ioat = to_ioat_chan((void *) data);
564+
struct ioat_chan_common *chan = &ioat->base;
529565

530566
ioat1_cleanup(ioat);
567+
if (!test_bit(IOAT_RUN, &chan->state))
568+
return;
531569
writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
532570
}
533571

‎drivers/dma/ioat/dma.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
356356
void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
357357
void ioat_kobject_del(struct ioatdma_device *device);
358358
int ioat_dma_setup_interrupts(struct ioatdma_device *device);
359+
void ioat_stop(struct ioat_chan_common *chan);
359360
extern const struct sysfs_ops ioat_sysfs_ops;
360361
extern struct ioat_sysfs_entry ioat_version_attr;
361362
extern struct ioat_sysfs_entry ioat_cap_attr;

‎drivers/dma/ioat/dma_v2.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,11 @@ static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
190190
void ioat2_cleanup_event(unsigned long data)
191191
{
192192
struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
193+
struct ioat_chan_common *chan = &ioat->base;
193194

194195
ioat2_cleanup(ioat);
196+
if (!test_bit(IOAT_RUN, &chan->state))
197+
return;
195198
writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
196199
}
197200

@@ -553,10 +556,10 @@ int ioat2_alloc_chan_resources(struct dma_chan *c)
553556
ioat->issued = 0;
554557
ioat->tail = 0;
555558
ioat->alloc_order = order;
559+
set_bit(IOAT_RUN, &chan->state);
556560
spin_unlock_bh(&ioat->prep_lock);
557561
spin_unlock_bh(&chan->cleanup_lock);
558562

559-
tasklet_enable(&chan->cleanup_task);
560563
ioat2_start_null_desc(ioat);
561564

562565
/* check that we got off the ground */
@@ -566,7 +569,6 @@ int ioat2_alloc_chan_resources(struct dma_chan *c)
566569
} while (i++ < 20 && !is_ioat_active(status) && !is_ioat_idle(status));
567570

568571
if (is_ioat_active(status) || is_ioat_idle(status)) {
569-
set_bit(IOAT_RUN, &chan->state);
570572
return 1 << ioat->alloc_order;
571573
} else {
572574
u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
@@ -809,11 +811,8 @@ void ioat2_free_chan_resources(struct dma_chan *c)
809811
if (!ioat->ring)
810812
return;
811813

812-
tasklet_disable(&chan->cleanup_task);
813-
del_timer_sync(&chan->timer);
814-
device->cleanup_fn((unsigned long) c);
814+
ioat_stop(chan);
815815
device->reset_hw(chan);
816-
clear_bit(IOAT_RUN, &chan->state);
817816

818817
spin_lock_bh(&chan->cleanup_lock);
819818
spin_lock_bh(&ioat->prep_lock);

‎drivers/dma/ioat/dma_v3.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,11 @@ static void ioat3_cleanup(struct ioat2_dma_chan *ioat)
464464
static void ioat3_cleanup_event(unsigned long data)
465465
{
466466
struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
467+
struct ioat_chan_common *chan = &ioat->base;
467468

468469
ioat3_cleanup(ioat);
470+
if (!test_bit(IOAT_RUN, &chan->state))
471+
return;
469472
writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
470473
}
471474

0 commit comments

Comments
 (0)