Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp562504ybl; Wed, 29 Jan 2020 05:43:35 -0800 (PST) X-Google-Smtp-Source: APXvYqyRF+JuMHdPaNB6e9ZjfZLT/bXx9+70jwkUeIp3lGKXnYcgge+U25+qsWa/sJC2Gh2U98+6 X-Received: by 2002:aca:4306:: with SMTP id q6mr6496536oia.54.1580305415630; Wed, 29 Jan 2020 05:43:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580305415; cv=none; d=google.com; s=arc-20160816; b=Yj2brTMz4T0nH+JjejiL3rLORF76zEx4YrxTfFcVITzqrumIk2bWpnFykIaCnRSAxi hO/5FufddDhssLUT9tl77DpiJR8OqJk0B2cYM2DJ3mU5CitCpDizsaa6ot7PjiFaIKBT eaQw84giohKOtF7jPOjog9Kf4KC+0K0imbNvG7z3O9Am0MbQVC03kuF/9B3LCKrFBkhF /xDRLxUa3XbhPmkahRgHzzwQKsVIkv8Y7uV1PvvYLeRqcLKy2RvCwHDBEJ5xUROkbQNp Ci7+mS7B0L4kPLC1TBPhSzqppEUfjQQiWO29aFE7uzy3cypvCSI0zny0VFfeFc29vGsi rh3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=LKAhm5fgnCM0f4ool+EzZtuKWekhU6ZjNjBMoV+cWXA=; b=L/8y0h6wh5h3sMoNo1g/BH1mAmXuJQOkqcvYcQ6tbTh7lOTQ16R+rfWcyKfwhnKjXs FiY76GCAda5Oi000H9UCxHgFfOiPhhTMQRicMzqxuzSOSKtdwjR5vGd7AMTpTp2w30PO h2EijW2iMhfVt+0dazcHhGwtCglBPX6Sj85ghEHxIS5/U8qfQSHoWM5WgF0/uLceh5v1 Kc0OYchMh+9m1fAjJwJm2PuO1AimW6icFv4bqbvtnI5h5Oy2syeoUnZSJwEqn9PBJWsA 3GlPiWq0qM9kxj2BeKXllidCeIxEtNZTCClA0ELqB3uqPmVYcGnTqMYzKS1rZwDRN/4R IGGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@flowbird.group header.s=google header.b=PMb22boP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flowbird.group Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j14si1099516otp.319.2020.01.29.05.43.23; Wed, 29 Jan 2020 05:43:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@flowbird.group header.s=google header.b=PMb22boP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flowbird.group Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726733AbgA2NlT (ORCPT + 99 others); Wed, 29 Jan 2020 08:41:19 -0500 Received: from mail-wr1-f100.google.com ([209.85.221.100]:33076 "EHLO mail-wr1-f100.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726178AbgA2NlS (ORCPT ); Wed, 29 Jan 2020 08:41:18 -0500 Received: by mail-wr1-f100.google.com with SMTP id b6so20258515wrq.0 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=W5Xgcbd7e4HEKHJnP8fJLergpLk2sXo+mVQUdjlKvea4a9FeMQJiLYzPGv2VMUnRey cm7TCsJ+3rSRze/NYVnYLNn9lf7YZpBXjF62EDhZM1tv5gN+tBNg5JVsI1Yor6ZrKr2D hbWOPhRgvAlBtsQ55/3spe2MmsKRfV/axzGnVxgXeRjyFHzE8aRLGQGOHHC4KfAP60Kf 36mluxWZMGuB++z7LB7e9dpm4xOnSBpfRQ15Q/5E0mqNhrc43blOkJwUaLr/dMWjq68X soON5ObaLZijljEhphy6oZpYOSLlElHG7+yhSECTc2+IFK1+dyYSRn4HSTKluaQe2Zyw MsDw== X-Gm-Message-State: APjAAAU4UCeSsN/DjSuZyFVvbqzKcwZ8UJVF7jUJn/CV83rpDbh9r+6W 9wjSmJLSDywUGI8BUjs0N5lV9Kpi7kElnjFPMIv/n/LnzPii 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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); -- 1.9.1