Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp392518rwa; Sat, 20 Aug 2022 06:00:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR6dGZRU56wfK0z/yKyc2sD1UslELrmvXXIyx+5REYnHOYQj8evXJ4+YooKwSmhk7UOT9Jqt X-Received: by 2002:aa7:cb92:0:b0:443:98d6:20da with SMTP id r18-20020aa7cb92000000b0044398d620damr9443920edt.399.1661000445751; Sat, 20 Aug 2022 06:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661000445; cv=none; d=google.com; s=arc-20160816; b=DkYcMZh1apCTytNEntrbETDHRC6zJIfQ9um12fDfYRCv3kQQ4/x6nknhV1yQ5NN0O2 s1EMi2SYa6k+bf5Bbfttw0Ch98qQVynfKZRVHCBTatvOnAreWQ9WmqsM2cr5tA7tuzFE ir4KuRWtSpkNUKO/ZbGVeiXVxbFXRmNut12BZRvbPlqrslbkfCg/Z1W91FcQkgPBsmzl SniA3VW+g81eoNpHwxiig9sfWp+h4iGDmdaUBpvsvGI6QGW/DdSBVpqzpE6ID5uAElJ5 xLPiWK+GeoJJKzmEooMlV2bxUhksYw8QMlFO+q8PptAiPrGcmFVtnqNk9s37VDuHMUQF eXLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cvh3nYnGWEoJXWRFPJU9b88tqPy3/flbOaTwGjb9kDM=; b=bN1De2Amb+UMVq54cpsI91UgiBiCDewt8eVikUzYFhiKp7k22/ook2zZ4wLzEQWYWa If3Op5jbed71fYXYkBVuBFd3kh0Yf0tT3dSG10viv5Y6/SVRkxEtFExkIhFe+e79zl27 ahhUnS7MlPBMpthMU7QumAhXRxiY5ES0Zu9JcOQUmVfrxmjjQvETbj5WX1GDNp3moSxd AesqJ8+wVJaOk2KrOs38TPLTbBRh7wtkn776ibdBd1cm1b9aj9Zg5nHTt6501SFFtsgJ esX13R9GbhwtmN8JERSBqAzJh9xlE5Z6pn3XBKHCehsqIwAeoKgIiZjgT+MCHiqez1zb q0PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=u+ubR3Yi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd43-20020a17090796ab00b0073d5b605cefsi2779137ejc.261.2022.08.20.06.00.17; Sat, 20 Aug 2022 06:00:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=u+ubR3Yi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346667AbiHTM66 (ORCPT + 99 others); Sat, 20 Aug 2022 08:58:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346831AbiHTM6i (ORCPT ); Sat, 20 Aug 2022 08:58:38 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BEEA1B4; Sat, 20 Aug 2022 05:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1661000292; x=1692536292; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DoY/kmwSNdvclyuGL7rhO4ysuRQmmM1yEVWM6puZ2Hc=; b=u+ubR3YisAt/qkKq5QKVLQXAU26GLNMLkNivNizJUhs9p7hJvwl2PnhF 4KT4lB6ktKpgiQKqlEwZurMp93Ayf61J+kKvzZPg0PNRtVBSZvRA4gYzP dNi4n3M/1ZaVAPxPYEfrZjUkSBZWZuDm9zqVSDo1eOtmS+tJw6Siyz1Ft EVM6+mHYhEPpLlH9c3Z8LFxZMyQYdFHrgQd8S/HZj5oYP/gIh0wtPjJZr AW0Jn8WIE6job/6/+YSc432jCUFC1veyyP9uaT6rEnPXfI4p/BQkW2wO8 heu7c3jf93CnAUyBCz4oFkXabFWMBXlARej7DPwCXdu+xxeHffcK7pZR9 g==; X-IronPort-AV: E=Sophos;i="5.93,251,1654585200"; d="scan'208";a="177188241" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Aug 2022 05:58:10 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Sat, 20 Aug 2022 05:58:07 -0700 Received: from ROB-ULT-M18064N.mchp-main.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Sat, 20 Aug 2022 05:58:04 -0700 From: Tudor Ambarus To: , , , CC: , , , , , , , , , , Subject: [PATCH 13/33] dmaengine: at_hdmac: Fix concurrency problems by removing atc_complete_all() Date: Sat, 20 Aug 2022 15:56:57 +0300 Message-ID: <20220820125717.588722-14-tudor.ambarus@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220820125717.588722-1-tudor.ambarus@microchip.com> References: <20220820125717.588722-1-tudor.ambarus@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org atc_complete_all() had concurrency bugs, thus remove it: 1/ atc_complete_all() in its entirety was buggy, as when the atchan->queue list (the one that contains descriptors that are not yet issued to the hardware) contained descriptors, it fired just the first from the atchan->queue, but moved all the desc from atchan->queue to atchan->active_list and considered them all as fired. This could result in calling the completion of a descriptor that was not yet issued to the hardware. 2/ when in tasklet at atc_advance_work() time, atchan->active_list was queried without holding the lock of the chan. This can result in atchan->active_list concurrency problems between the tasklet and issue_pending(). 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 | 49 ++++-------------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c index aeb241832c52..10424a6fcbbf 100644 --- a/drivers/dma/at_hdmac.c +++ b/drivers/dma/at_hdmac.c @@ -920,42 +920,6 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc) dma_run_dependencies(txd); } -/** - * atc_complete_all - finish work for all transactions - * @atchan: channel to complete transactions for - * - * Eventually submit queued descriptors if any - * - * Assume channel is idle while calling this function - * Called with atchan->lock held and bh disabled - */ -static void atc_complete_all(struct at_dma_chan *atchan) -{ - struct at_desc *desc, *_desc; - LIST_HEAD(list); - unsigned long flags; - - dev_vdbg(chan2dev(&atchan->dma_chan), "complete all\n"); - - spin_lock_irqsave(&atchan->lock, flags); - - /* - * Submit queued descriptors ASAP, i.e. before we go through - * the completed ones. - */ - if (!list_empty(&atchan->queue)) - atc_dostart(atchan, atc_first_queued(atchan)); - /* empty active_list now it is completed */ - list_splice_init(&atchan->active_list, &list); - /* empty queue list by moving descriptors (if any) to active_list */ - list_splice_init(&atchan->queue, &atchan->active_list); - - spin_unlock_irqrestore(&atchan->lock, flags); - - list_for_each_entry_safe(desc, _desc, &list, desc_node) - atc_chain_complete(atchan, desc); -} - /** * atc_advance_work - at the end of a transaction, move forward * @atchan: channel where the transaction ended @@ -963,25 +927,20 @@ static void atc_complete_all(struct at_dma_chan *atchan) static void atc_advance_work(struct at_dma_chan *atchan) { unsigned long flags; - int ret; dev_vdbg(chan2dev(&atchan->dma_chan), "advance_work\n"); spin_lock_irqsave(&atchan->lock, flags); - ret = atc_chan_is_enabled(atchan); + if (atc_chan_is_enabled(atchan) || list_empty(&atchan->active_list)) + return spin_unlock_irqrestore(&atchan->lock, flags); spin_unlock_irqrestore(&atchan->lock, flags); - if (ret) - return; - - if (list_empty(&atchan->active_list) || - list_is_singular(&atchan->active_list)) - return atc_complete_all(atchan); atc_chain_complete(atchan, atc_first_active(atchan)); /* advance work */ spin_lock_irqsave(&atchan->lock, flags); - atc_dostart(atchan, atc_first_active(atchan)); + if (!list_empty(&atchan->active_list)) + atc_dostart(atchan, atc_first_active(atchan)); spin_unlock_irqrestore(&atchan->lock, flags); } -- 2.25.1