From patchwork Wed Jan 29 13:40:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fuzzey, Martin" X-Patchwork-Id: 11356189 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E75C9112B for ; Wed, 29 Jan 2020 13:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFD162071E for ; Wed, 29 Jan 2020 13:41:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=flowbird.group header.i=@flowbird.group header.b="PMb22boP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726560AbgA2NlS (ORCPT ); Wed, 29 Jan 2020 08:41:18 -0500 Received: from mail-wr1-f100.google.com ([209.85.221.100]:39567 "EHLO mail-wr1-f100.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbgA2NlS (ORCPT ); Wed, 29 Jan 2020 08:41:18 -0500 Received: by mail-wr1-f100.google.com with SMTP id y11so20212479wrt.6 for ; Wed, 29 Jan 2020 05:41:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flowbird.group; s=google; h=from:to:cc:subject:date:message-id; bh=LKAhm5fgnCM0f4ool+EzZtuKWekhU6ZjNjBMoV+cWXA=; b=PMb22boP3CV1EyVw1dzQscsMHDiMAsnTPfS80IVQS+kzcT55qoid2iPIWveJzgs1t4 TbtnBge7nIGnp4Yk2L58XyNcE5vaEbZl1icPp8g9mvE81iNUQZBIHdx03Jzb/O19uYjR lm5tgSgLRJIZdcb3ZXqucs9cpbiJJRec7cNEBeh0jLIxESZPSN8rxqivDbcu6lNgT6m8 EKHj9I3QJSf453pGCmysJSM7LOkU3+B4onEA/w/xWvFxxVK/Ae5fYCEq182LGRJECnU3 0h/9iSOseqfUelq0iw0GKK3tuawCrHhslneda3rv+roe31BI9cd5MLZAPyj17bhP1n0R gIew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LKAhm5fgnCM0f4ool+EzZtuKWekhU6ZjNjBMoV+cWXA=; b=Pw3sxbCoagKCSWTa3pIVDbM0S9asLvB4QyRnviDC6fOI7BS94H/OEXiQuNss3jKocv 5LYeGv96Cs6CbajnROaed45DfVlHJ8AKQNUEJtUwd/D3lOSOqIq1K6Cqhb/OryR8orKz npMhOeNgjoEWjJwuEez3v7p94usRaNuEHAZWmkGjyK7aqDtCPQPL/2rVe12m5ue2i6IH /xA1yakKdIsaqlnSofpXhezAaxpk8NougSfG6GtyWQ5UWUDsl2yMfyodXvIjkU363NZl yDmz5c2xtsJt57snm5KmHUNtC8aEG1848I+RVLG8H/9RMFS2QhyM8sVDeq5A0W7nt8DK SdDw== X-Gm-Message-State: APjAAAW9fZ6azHkytaIi26AUxAuE2R8CWjBXYI/E5gkHmRiPN043gTGc y9sBtHR2qpu8aj3u9r2ZiWyMWhQ66CjYNmUa/0JhWqL51Qtx X-Google-Smtp-Source: APXvYqyFQ98FYktk+97oLQYaNelIlb9g5MjMxMu3Mz01RbmXwDkqAxJuAuvFxeN+z7MX3XHkYpJc92dWUgQm X-Received: by 2002:adf:97d6:: with SMTP id t22mr35073052wrb.407.1580305275875; Wed, 29 Jan 2020 05:41:15 -0800 (PST) Received: from mail.besancon.parkeon.com ([185.149.63.251]) by smtp-relay.gmail.com with ESMTPS id r3sm33567wro.56.2020.01.29.05.41.15 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 29 Jan 2020 05:41:15 -0800 (PST) X-Relaying-Domain: flowbird.group Received: from [10.32.51.186] (port=60422 helo=PC12445-BES.dynamic.besancon.parkeon.com) by mail.besancon.parkeon.com with esmtp (Exim 4.71) (envelope-from ) id 1iwnak-0003Z2-Rk; Wed, 29 Jan 2020 14:41:14 +0100 From: Martin Fuzzey To: dmaengine@vger.kernel.org Cc: stable@vger.kernel.org, Shawn Guo , Sascha Hauer , Fabio Estevam , NXP Linux Team , Robin Gong , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] dmaengine: imx-sdma: fix context cache Date: Wed, 29 Jan 2020 14:40:06 +0100 Message-Id: <1580305274-27274-1-git-send-email-martin.fuzzey@flowbird.group> X-Mailer: git-send-email 1.9.1 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org There is a DMA problem with the serial ports on i.MX6. When the following sequence is performed: 1) Open a port 2) Write some data 3) Close the port 4) Open a *different* port 5) Write some data 6) Close the port The second write sends nothing and the second close hangs. If the first close() is omitted it works. Adding logs to the the UART driver shows that the DMA is being setup but the callback is never invoked for the second write. This used to work in 4.19. Git bisect leads to: ad0d92d: "dmaengine: imx-sdma: refine to load context only once" This commit adds a "context_loaded" flag used to avoid unnecessary context setups. However the flag is only reset in sdma_channel_terminate_work(), which is only invoked in a worker triggered by sdma_terminate_all() IF there is an active descriptor. So, if no active descriptor remains when the channel is terminated, the flag is not reset and, when the channel is later reused the old context is used. Fix the problem by always resetting the flag in sdma_free_chan_resources(). Fixes: ad0d92d: "dmaengine: imx-sdma: refine to load context only once" Cc: stable@vger.kernel.org Signed-off-by: Martin Fuzzey Reviewed-by: Fabio Estevam Tested-by: Richard Leitner --- The following python script may be used to reproduce the problem: import re, serial, sys ports=(0, 4) # Can be any ports not used (no need to connect anything) NOT console... def get_tx_counts(): pattern = re.compile("(\d+):.*tx:(\d+).*") tx_counts = {} with open("/proc/tty/driver/IMX-uart", "r") as f: for line in f: match = pattern.match(line) if match: tx_counts[int(match.group(1))] = int(match.group(2)) return tx_counts before = get_tx_counts() a = serial.Serial("/dev/ttymxc%d" % ports[0]) a.write("polop") a.close() b = serial.Serial("/dev/ttymxc%d" % ports[1]) b.write("test") after = get_tx_counts() if (after[ports[0]] - before[ports[0]] > 0) and (after[ports[1]] - before[ports[1]] > 0): print "PASS" sys.exit(0) else: print "FAIL" print "Before: %s" % before print "After: %s" % after sys.exit(1) --- drivers/dma/imx-sdma.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index 066b21a..332ca50 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -1338,6 +1338,7 @@ static void sdma_free_chan_resources(struct dma_chan *chan) sdmac->event_id0 = 0; sdmac->event_id1 = 0; + sdmac->context_loaded = false; sdma_set_channel_priority(sdmac, 0);