On 5/29/24 2:18 AM, Li RongQing wrote: > list_for_each_entry_safe() should be used when the descriptor will be > freed in idxd_desc_complete(), Otherwise the freed descriptor will be > dereferenced to get its next, and always deletes freed descriptor from > list firstly > > Fixes: 16e19e11228b ("dmaengine: idxd: Fix list corruption in description completion") > Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx> > --- > drivers/dma/idxd/irq.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/dma/idxd/irq.c b/drivers/dma/idxd/irq.c > index 8dc029c..5571de1 100644 > --- a/drivers/dma/idxd/irq.c > +++ b/drivers/dma/idxd/irq.c > @@ -573,6 +573,8 @@ static void irq_process_pending_llist(struct idxd_irq_entry *irq_entry) > * Check against the original status as ABORT is software defined > * and 0xff, which DSA_COMP_STATUS_MASK can mask out. > */ > + list_del(&desc->list); I don't think this is needed. The iterator is working over a detached llist and nothing to do with 'struct list_head'. Otherwise everything else look ok. > + > if (unlikely(desc->completion->status == IDXD_COMP_DESC_ABORT)) { > idxd_desc_complete(desc, IDXD_COMPLETE_ABORT, true); > continue; > @@ -611,11 +613,13 @@ static void irq_process_work_list(struct idxd_irq_entry *irq_entry) > > spin_unlock(&irq_entry->list_lock); > > - list_for_each_entry(desc, &flist, list) { > + list_for_each_entry_safe(desc, n, &flist, list) { > /* > * Check against the original status as ABORT is software defined > * and 0xff, which DSA_COMP_STATUS_MASK can mask out. > */ > + list_del(&desc->list); > + > if (unlikely(desc->completion->status == IDXD_COMP_DESC_ABORT)) { > idxd_desc_complete(desc, IDXD_COMPLETE_ABORT, true); > continue;