From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 421EDC54E58 for ; Tue, 12 Mar 2024 17:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=g5vGVja7MLDZ2CI90KY7SzcWex7iVPCq3LKICxUMgjE=; b=Vi7Vm56wapifCP Bb0I4tAbFhzFF64Z3gDkZFn42fvvNGTTi7iKZv6A4HpC81H3JcRUntsGwc5TGH9ZLyOJ8fU0DJGsm QwrB9u5pl0EHKrowpYi2qbSODHSnQhhO+7j4zsx/cnj/4eUjYnD0GZXKfMKFPnsMfgAKgbCQnlXlb x/ilfeQjJiMsPf5ane73UenLS6VoffBx9ia6Zpq88jvv6Q1USQn4sZDtMGxYABkd25cCesxO13rB3 7UKOd51dki+o16FdRAfGVk2/fjzjn4987u3nh20XJmKJgZExe0af5Lgw+ITOHFz7cIdqJrtxb5LF+ zptYtIH2u12U6vXFy05Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk6DJ-00000006v3k-13JZ; Tue, 12 Mar 2024 17:46:57 +0000 Received: from out-187.mta0.migadu.com ([91.218.175.187]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk6DE-00000006v14-3oYI for linux-arm-kernel@lists.infradead.org; Tue, 12 Mar 2024 17:46:55 +0000 Message-ID: <1684c53c-05b6-4098-b80f-d7d3de15b393@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710265604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GIl/8fsjmUJ+Og5Be9zzqTrcqB0qVzN1neR02nmTM7g=; b=Hp/GvCMyTBwsj+Vl2sUT+N4TWlN6+mDejoQl8jHCvEs3fDvpdRmgIRhbhZE+6iBh50nkn1 5lFLIEtRaGi8KxL97BKcxAITnty/0+t4Tx9y7cq3EGLH5LrE0wLibNvjPvzGjHiT0Firsl m/+TiMp96v79b86qE3u/DhUtxLy8MYg= Date: Tue, 12 Mar 2024 13:46:40 -0400 MIME-Version: 1.0 Subject: Re: [PATCH v2 1/2] dmaengine: xilinx: dpdma: Fix race condition in vsync IRQ Content-Language: en-US To: Vishal Sagar , laurent.pinchart@ideasonboard.com, vkoul@kernel.org Cc: michal.simek@amd.com, dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, varunkumar.allagadapa@amd.com References: <20240228042124.3074044-1-vishal.sagar@amd.com> <20240228042124.3074044-2-vishal.sagar@amd.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sean Anderson In-Reply-To: <20240228042124.3074044-2-vishal.sagar@amd.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240312_104653_423644_0C7012A8 X-CRM114-Status: GOOD ( 17.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Vishal, On 2/27/24 23:21, Vishal Sagar wrote: > From: Neel Gandhi > > The vchan_next_desc() function, called from > xilinx_dpdma_chan_queue_transfer(), must be called with > virt_dma_chan.lock held. This isn't correctly handled in all code paths, > resulting in a race condition between the .device_issue_pending() > handler and the IRQ handler which causes DMA to randomly stop. Fix it by > taking the lock around xilinx_dpdma_chan_queue_transfer() calls that are > missing it. > > Signed-off-by: Neel Gandhi > Signed-off-by: Radhey Shyam Pandey > Signed-off-by: Tomi Valkeinen > Signed-off-by: Vishal Sagar > > Link: https://cas5-0-urlprotect.trendmicro.com:443/wis/clicktime/v1/query?url=https%3a%2f%2flore.kernel.org%2fall%2f20220122121407.11467%2d1%2dneel.gandhi%40xilinx.com&umid=a486940f-2fe3-47f4-9b3f-416e59036eab&auth=d807158c60b7d2502abde8a2fc01f40662980862-a75e22540e8429d70f26093b45d38995a0e6e1e8 > --- > drivers/dma/xilinx/xilinx_dpdma.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/dma/xilinx/xilinx_dpdma.c b/drivers/dma/xilinx/xilinx_dpdma.c > index b82815e64d24..28d9af8f00f0 100644 > --- a/drivers/dma/xilinx/xilinx_dpdma.c > +++ b/drivers/dma/xilinx/xilinx_dpdma.c > @@ -1097,12 +1097,14 @@ static void xilinx_dpdma_chan_vsync_irq(struct xilinx_dpdma_chan *chan) > * Complete the active descriptor, if any, promote the pending > * descriptor to active, and queue the next transfer, if any. > */ > + spin_lock(&chan->vchan.lock); > if (chan->desc.active) > vchan_cookie_complete(&chan->desc.active->vdesc); > chan->desc.active = pending; > chan->desc.pending = NULL; > > xilinx_dpdma_chan_queue_transfer(chan); > + spin_unlock(&chan->vchan.lock); > > out: > spin_unlock_irqrestore(&chan->lock, flags); > @@ -1264,10 +1266,12 @@ static void xilinx_dpdma_issue_pending(struct dma_chan *dchan) > struct xilinx_dpdma_chan *chan = to_xilinx_chan(dchan); > unsigned long flags; > > - spin_lock_irqsave(&chan->vchan.lock, flags); > + spin_lock_irqsave(&chan->lock, flags); > + spin_lock(&chan->vchan.lock); > if (vchan_issue_pending(&chan->vchan)) > xilinx_dpdma_chan_queue_transfer(chan); > - spin_unlock_irqrestore(&chan->vchan.lock, flags); > + spin_unlock(&chan->vchan.lock); > + spin_unlock_irqrestore(&chan->lock, flags); > } > > static int xilinx_dpdma_config(struct dma_chan *dchan, > @@ -1495,7 +1499,9 @@ static void xilinx_dpdma_chan_err_task(struct tasklet_struct *t) > XILINX_DPDMA_EINTR_CHAN_ERR_MASK << chan->id); > > spin_lock_irqsave(&chan->lock, flags); > + spin_lock(&chan->vchan.lock); > xilinx_dpdma_chan_queue_transfer(chan); > + spin_unlock(&chan->vchan.lock); > spin_unlock_irqrestore(&chan->lock, flags); > } I also ran into this issue and came up with the same fix [1]. Reviewed-by: Sean Anderson [1] https://lore.kernel.org/dmaengine/20240308210034.3634938-2-sean.anderson@linux.dev/ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel