Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1230081lql; Tue, 12 Mar 2024 10:46:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWET9GmgnYITrGpeIWof1Gt7CWFvdtw2nTSD2bskSdtNKWYc/1/ptongDLzlSaWYku9WoAKmtUGfmyZTeXy/snfI687ASrBsjB8tGUQ0A== X-Google-Smtp-Source: AGHT+IHqAyQ/lOAlD9sWlnXMZlyHDIIBsurYvAWHk4e10ToWveSHvDkqqu0CBo/q3K+HeLTcyzYz X-Received: by 2002:a05:6830:438f:b0:6e5:303b:fb83 with SMTP id s15-20020a056830438f00b006e5303bfb83mr5365491otv.32.1710265614965; Tue, 12 Mar 2024 10:46:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710265614; cv=pass; d=google.com; s=arc-20160816; b=Ep6Yzh0Zpjf088a6LfbqwKEWSNMXeyBUzogBBXvtcTjqzKnMhUqLI+mFbZsdhU53uS 3fsDB/RheAfbX8FXhILl48UYZKlfqPWHUtIc912Vt3IrFu8L5hDLJchdSW65Bj8vdb0K qcmteg57X+ZdQJxolKmzYPQ1QNVWOKATdXqGHYGlkEOCUvWWR5yR6/Phk1+aAQX3znWG pDH68/mjdKvvL3agKYCBvhl3x1cOhez+BSOa6GSLijZgRSq4GxdwBnjWvACpS4QHNVMD YsWhzUky1VxrOp4NAx7vblE9m9aQe2HLvQIClbmZ5qaG1Tw17Tub6ejfUMciojISOkMR fB3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=GIl/8fsjmUJ+Og5Be9zzqTrcqB0qVzN1neR02nmTM7g=; fh=C4BlzOpDo0MyzouMz8Y7MYrGeRaZSqNvZ7dkaie1s7k=; b=TDlGWOoTHswEMCtr16AW4gNFG7H1aZhccVZxz+Pum0nevb5JLwFvjqrP5cHoUBXAC/ JYgtEKrQXcPxuZkdSbfnFxSKA/rjJKZ1XrFhDf9ufeGx9ydNU+FnBTHVPZHFohhezvXK cq3x04i0p9mevxBV1g1C9SYxH5ig5RE+S5bSv1X4AaHf4rKHYUH3tD94lStHCx1sx/MR 4YG1AzcntiMXP6xftsqoQ4GjvVE2Wg9xFOmmYuiYevAO6Ncj/dU2daYQT6prBU4au4sX zOsO1bFgpFAb9fchMuDfcwNpQ1KwmmlB4U/S6OudFUh9je7FIRgTfH5yH16+o4YPoNp9 Mqxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Hp/GvCMy"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-100619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100619-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c16-20020a05620a269000b007881d5db1casi8399997qkp.400.2024.03.12.10.46.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 10:46:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Hp/GvCMy"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-100619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100619-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AC8D31C22583 for ; Tue, 12 Mar 2024 17:46:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8FC01386BE; Tue, 12 Mar 2024 17:46:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Hp/GvCMy" Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E3677D406 for ; Tue, 12 Mar 2024 17:46:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710265609; cv=none; b=kqHttZNMvY61kmeaGtS0rZ3WfSW483+Ugbeyemls6kw6hWs8XR0WKc+YPVh4FxtsSZZ9ry/Rl/OHYElUHx9f55xQvw9BQSYjxmm5nNmi3B8LwD3/tpH6DkXmyuq2/tFr33ay4ylIkjhy6XJwpxfkpF3yoBGxZtky1vHkfdiQ7WE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710265609; c=relaxed/simple; bh=rPfGN5w2HwyLrxgDW8705e7jnqF6QYY783ggHhVlM+I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=UYwXn43WwGsw25koB935Vb6qw9rER4g4sQ7m3NHjeVprHCwE/KtmChxrqw/ypvj8F5XWxpsTqA+v7bTliWc7KYUqF9Z7zn1Vq4UF8Eh2+PvCxs+oXECCDDGzsmsavUW2l/blpN+cGL1comJJ1ZQU7pzgX95zsgUS2rx4gfV/dxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Hp/GvCMy; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT 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/