From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9112F40148E for ; Thu, 26 Mar 2026 15:14:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774538043; cv=none; b=n3t4I63iLvCnK3qtJhryFi30q48lPgo3nWqtCewO7GDlT5FYdk6fxMZbtjateCHScRUv4QBMI7up6lId2NNmXNomzeE886X2SqHMoUoQgUWqW1hPmUXdp10rw9MY0QxBJVORXofTIP1nLAt+40vbyqfqyOono0/9imuSRS7Z8po= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774538043; c=relaxed/simple; bh=FWf1dB2Qon/UR2aHHejUdu+2XcfIQ/PGLiP3BnMrCfk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TbNieg8kcmCv43yPOstOJRVFQrS8yVUTXc0fi1wbLEYObRyzDzXAqv818qpW6CS454BcXteVdQKDQQSxIhAj4+0cPDBOOVQtDW/En5DDCAUz/CyZQv5nkQjg9R3R1H8h5HViT6rtYHf1/+/QYca1l5DzMa4+iYZAJLcNjkcKgv4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l99oVyku; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l99oVyku" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-48558d6ef83so10246095e9.3 for ; Thu, 26 Mar 2026 08:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774538040; x=1775142840; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=D0sYiHqQQkLdMu3GiNtAqjtuktge8TgQEH5jdZWb9i0=; b=l99oVykusxGbrlmrUJMDEc4Dmnr8V1cV12rAO9HrZhUPZnYnUOZxacr93UnPCWJ/Nn BPwaY2teM7cxO9gem+jV5nMTkHox4zlvNgAHNdzE8INmgcuUL0WWJN0/u0f1pFDbRiHq +GzS/M4hj0kKn7bRSdE8J7OQu4of2F3wGoPtgcutXFSG50ti7YnICZiKuq5Do6qYbyoO FfkYwPQ3Lx3Yazbhd51tGHQvGWMQnCTa+8WWEDSpqS/Q0v9tKN5DfI8RhfdI1n0MTLWz 8qfB0pIYgqnVUuLf77fzFu59ob4i92u5CDk3/gXAw/2eBifTSo7GYsZiyPZ5cAB/4FN9 q6Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774538040; x=1775142840; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D0sYiHqQQkLdMu3GiNtAqjtuktge8TgQEH5jdZWb9i0=; b=SkafoHwT9kiqfV05vzhpz7TBsxel6Xaadj5+7tLOdlGyb/qip8no4XniA4d186X8cy 3l3nXVSKzUrUjMTycxh/hskPNDRlZHGSkDfQrRUcyiV7IlHGg8YXKoBs/hVLe64J0QdV OKbrg7ZSRDotLoxP6Gve91WEgKQ0A1cC+cxT6mPbaXd8Brg8Nq9emlA/k5HzAx/hp7Nj mXidq/+0BArmTtpOeDEIobdkvETP+AeqRbyqD7gqrGhd7gwri2y2sV64wy+LbMWf/YMz OJbaZ7CCQkPW0LUCJAFpgMwYfUGBCWD7npSWdam3MCCATnN+MhcKG4tFae7/bMhsSo9B ZGUw== X-Forwarded-Encrypted: i=1; AJvYcCX2mjihurHBVPwigHxGOCs77lrUiP4PdYwP7jwKSJdzD0lO3UBVIpEZafU48jR7WD6ydyOMDIQSG79sLW8=@vger.kernel.org X-Gm-Message-State: AOJu0YxCR8kH0r6jNlcdi758GOX+3WjNaqjtLrMSRKlFBeUcPSYG/q/9 VZdXSbqvh/9gRq5AM9cCaQsmjrdLfj6N1G24W6YyenGaAdaGQznP6FfRjbCv/oD3 X-Gm-Gg: ATEYQzySdY4ibgnKVaHtFmEBpjGLlY3nFBh2efJE38X4Zl68Xi2/+34gBh4ayaHb8Yn +7d+889mbrWGcYLb1nzQ9N5oFBH8fPJYQ3i2i/ozyBZzIUPtOq6OgTopsQGuOoz8b8DWHZ/AHhy IpTIhii0q53sgAuW7fvazvwuHvKc/u2FvGHjpVAkp5a8rgfZp07stui+WrVnsJMXJuDIGvHBxpx ZMfBH1D194GPQmHHPt8wcKRElYqzZiPagjCPWRGbJokRAX3dexSTjbU18U/03SJ23d5XUr00wOf ESJoag2p52ManpIelc029pI+1NuHo+JhqAfYYiiyNE9V+S8IJZ7aGmyMBlTr4qqd5pe0pB3O2uU JyFmTcM5jG00KOGe0G5Hwa0tDnCKx4c/TS42zdlZvEfPDU3JBk6fzz27Bof1YNPhRmZat0QnKBB aA6CLxZO8xCr78Ig== X-Received: by 2002:a05:600c:8b6d:b0:485:3e20:4013 with SMTP id 5b1f17b1804b1-4871604b905mr125124305e9.28.1774538039577; Thu, 26 Mar 2026 08:13:59 -0700 (PDT) Received: from nsa ([45.94.208.206]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4872090fb74sm21045505e9.7.2026.03.26.08.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 08:13:59 -0700 (PDT) Date: Thu, 26 Mar 2026 15:14:44 +0000 From: Nuno =?utf-8?B?U8Oh?= To: Nuno =?utf-8?B?U8Oh?= Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, Lars-Peter Clausen , Vinod Koul , Frank Li , Eliza Balas Subject: Re: [PATCH 1/2] dmaengine: dma-axi-dmac: Defer freeing DMA descriptors Message-ID: References: <20260326-dma-dmac-handle-vunmap-v1-0-be3e46ffaf69@analog.com> <20260326-dma-dmac-handle-vunmap-v1-1-be3e46ffaf69@analog.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260326-dma-dmac-handle-vunmap-v1-1-be3e46ffaf69@analog.com> On Thu, Mar 26, 2026 at 01:37:35PM +0000, Nuno Sá wrote: > From: Eliza Balas > > This IP core can be used in architectures (like Microblaze) where DMA > descriptors are allocated with vmalloc(). Hence, given that freeing the > descriptors happen in softirq context, vunmpap() will BUG(). > > To solve the above, we setup a work item during allocation of the > descriptors and schedule in softirq context. Hence, the actual freeing > happens in threaded context. > > Signed-off-by: Eliza Balas > Signed-off-by: Nuno Sá > --- > drivers/dma/dma-axi-dmac.c | 48 +++++++++++++++++++++++++++++++++------------- > 1 file changed, 35 insertions(+), 13 deletions(-) > > diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c > index 45c2c8e4bc45..df2668064ea2 100644 > --- a/drivers/dma/dma-axi-dmac.c > +++ b/drivers/dma/dma-axi-dmac.c > @@ -133,6 +133,8 @@ struct axi_dmac_desc { > struct virt_dma_desc vdesc; > struct axi_dmac_chan *chan; > > + struct work_struct sched_work; Ahh, just realized that workqueue.h needs to be included. Will wait for some feedback before v2. - Nuno Sá > + > bool cyclic; > bool cyclic_eot; > bool have_partial_xfer; > @@ -650,6 +652,26 @@ static void axi_dmac_issue_pending(struct dma_chan *c) > spin_unlock_irqrestore(&chan->vchan.lock, flags); > } > > +static void axi_dmac_free_desc(struct axi_dmac_desc *desc) > +{ > + struct axi_dmac *dmac = chan_to_axi_dmac(desc->chan); > + struct device *dev = dmac->dma_dev.dev; > + struct axi_dmac_hw_desc *hw = desc->sg[0].hw; > + dma_addr_t hw_phys = desc->sg[0].hw_phys; > + > + dma_free_coherent(dev, PAGE_ALIGN(desc->num_sgs * sizeof(*hw)), > + hw, hw_phys); > + kfree(desc); > +} > + > +static void axi_dmac_free_desc_schedule_work(struct work_struct *work) > +{ > + struct axi_dmac_desc *desc = container_of(work, struct axi_dmac_desc, > + sched_work); > + > + axi_dmac_free_desc(desc); > +} > + > static struct axi_dmac_desc * > axi_dmac_alloc_desc(struct axi_dmac_chan *chan, unsigned int num_sgs) > { > @@ -687,21 +709,18 @@ axi_dmac_alloc_desc(struct axi_dmac_chan *chan, unsigned int num_sgs) > /* The last hardware descriptor will trigger an interrupt */ > desc->sg[num_sgs - 1].hw->flags = AXI_DMAC_HW_FLAG_LAST | AXI_DMAC_HW_FLAG_IRQ; > > + /* > + * We need to setup a work item because this IP can be used on archs > + * that rely on vmalloced memory for descriptors. And given that freeing > + * the descriptors happens in softirq context, vunmpap() will BUG(). > + * Hence, setup the worker so that we can queue it and free the > + * descriptor in threaded context. > + */ > + INIT_WORK(&desc->sched_work, axi_dmac_free_desc_schedule_work); > + > return desc; > } > > -static void axi_dmac_free_desc(struct axi_dmac_desc *desc) > -{ > - struct axi_dmac *dmac = chan_to_axi_dmac(desc->chan); > - struct device *dev = dmac->dma_dev.dev; > - struct axi_dmac_hw_desc *hw = desc->sg[0].hw; > - dma_addr_t hw_phys = desc->sg[0].hw_phys; > - > - dma_free_coherent(dev, PAGE_ALIGN(desc->num_sgs * sizeof(*hw)), > - hw, hw_phys); > - kfree(desc); > -} > - > static struct axi_dmac_sg *axi_dmac_fill_linear_sg(struct axi_dmac_chan *chan, > enum dma_transfer_direction direction, dma_addr_t addr, > unsigned int num_periods, unsigned int period_len, > @@ -942,7 +961,10 @@ static void axi_dmac_free_chan_resources(struct dma_chan *c) > > static void axi_dmac_desc_free(struct virt_dma_desc *vdesc) > { > - axi_dmac_free_desc(to_axi_dmac_desc(vdesc)); > + struct axi_dmac_desc *desc = to_axi_dmac_desc(vdesc); > + > + /* See the comment in axi_dmac_alloc_desc() for the why! */ > + schedule_work(&desc->sched_work); > } > > static bool axi_dmac_regmap_rdwr(struct device *dev, unsigned int reg) > > -- > 2.53.0 >