From patchwork Tue Oct 25 09:02:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 13018830 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 0E90EC04A95 for ; Tue, 25 Oct 2022 09:08:44 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=F0KvnL1yeSBf6KqZW+cIxLthlEP4B8EhANz4TxQtzSI=; b=X2sf8XC4EbA5Sx jXUEn9b3jrrVdoSJzyX2z663iWdlbE05mHb1LzHrO/9WLsWEEGGHXgpNHp1G4nTPYVH9zvhZ5/1BB TYCCfe1rn8IS5fk83th7Aw5cL4jD1jg+9uEEfH9RMpLp/630GbzXFzqD1zIQNM5h4OkWZDjoMiZV3 oaPIGDt53hxu1GFnKxfqOLcQsCpBUbJNHDaUCJ2RzSZR0rG26IjDo/e5oDyxcX5FoO3viP0Y2njjI nDNv2hIMXVFku0sbCEnuUfuDMs/51XuC0K/TRVehfcHZrnvzuqPk0nDULF19F3sCtpjtW+waR8uU5 EGtk1JXu4aM6uhm/HQAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onFuN-004RFs-J0; Tue, 25 Oct 2022 09:07:40 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1onFqZ-004PL9-SO for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2022 09:03:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1666688623; x=1698224623; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bZZdBBlLXwMT8tESxcHFn6Z30Buv3zSEykmc4D8zsf4=; b=lB+SS3Ui1lNbyy5l83a07ruFKz8GB7UcOfrAqZFiNx2TjKABIYgAcDvA 7H9qwZ7D146jYOsTbTBnWFA3Q+lgPSkSqryEvgxI9hvlKa+MWHE+DT01q kR4gyxi4B3nsgfnNXw9Tm/UdemLgmVLVrSRRS/BGR51/WjSAt64YQhHcx 7jrjpWIxhl6tYBw9ZmK6Vs84JWP+WlyAPJC3YeBRO9nWOcuS7wTPf1i2J kX061WE1i4Nk1qY+IkVHQDaMll+W9x2DPpdHnwMnhqutnY4AHX3n+f0yO 60un8/MjglenFMfptdIIc+d6jE+3ucaFox+ceFnvS9pxwS56Iy4wiTnTr w==; X-IronPort-AV: E=Sophos;i="5.95,211,1661842800"; d="scan'208";a="120221281" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 25 Oct 2022 02:03:42 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Tue, 25 Oct 2022 02:03:42 -0700 Received: from ROB-ULT-M18064N.mchp-main.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Tue, 25 Oct 2022 02:03:40 -0700 From: Tudor Ambarus To: , , Subject: [PATCH v2 10/32] dmaengine: at_hdmac: Fix concurrency over the active list Date: Tue, 25 Oct 2022 12:02:44 +0300 Message-ID: <20221025090306.297886-11-tudor.ambarus@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025090306.297886-1-tudor.ambarus@microchip.com> References: <20221025090306.297886-1-tudor.ambarus@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221025_020344_002693_E987AAF3 X-CRM114-Status: GOOD ( 11.25 ) 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: , Cc: Tudor Ambarus , maciej.sosnowski@intel.com, linux-kernel@vger.kernel.org, mripard@kernel.org, linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, stable@vger.kernel.org, torfl6749@gmail.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The tasklet (atc_advance_work()) did not held the channel lock when retrieving the first active descriptor, causing concurrency problems if issue_pending() was called in between. If issue_pending() was called exactly after the lock was released in the tasklet (atc_advance_work()), atc_chain_complete() could complete a descriptor for which the controller has not yet raised an interrupt. Fixes: dc78baa2b90b ("dmaengine: at_hdmac: new driver for the Atmel AHB DMA Controller") Reported-by: Peter Rosin Signed-off-by: Tudor Ambarus Cc: stable@vger.kernel.org Link: https://lore.kernel.org/lkml/13c6c9a2-6db5-c3bf-349b-4c127ad3496a@axentia.se/ --- drivers/dma/at_hdmac.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c index 0fb44f622d35..b53a9fc15dd9 100644 --- a/drivers/dma/at_hdmac.c +++ b/drivers/dma/at_hdmac.c @@ -462,8 +462,6 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc) if (!atc_chan_is_cyclic(atchan)) dma_cookie_complete(txd); - /* Remove transfer node from the active list. */ - list_del_init(&desc->desc_node); spin_unlock_irqrestore(&atchan->lock, flags); dma_descriptor_unmap(txd); @@ -495,6 +493,7 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc) */ static void atc_advance_work(struct at_dma_chan *atchan) { + struct at_desc *desc; unsigned long flags; dev_vdbg(chan2dev(&atchan->chan_common), "advance_work\n"); @@ -502,9 +501,12 @@ static void atc_advance_work(struct at_dma_chan *atchan) spin_lock_irqsave(&atchan->lock, flags); if (atc_chan_is_enabled(atchan) || list_empty(&atchan->active_list)) return spin_unlock_irqrestore(&atchan->lock, flags); - spin_unlock_irqrestore(&atchan->lock, flags); - atc_chain_complete(atchan, atc_first_active(atchan)); + desc = atc_first_active(atchan); + /* Remove the transfer node from the active list. */ + list_del_init(&desc->desc_node); + spin_unlock_irqrestore(&atchan->lock, flags); + atc_chain_complete(atchan, desc); /* advance work */ spin_lock_irqsave(&atchan->lock, flags);