From patchwork Thu Mar 19 20:11:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1258414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=TwydsAJj; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48jykm18tTz9sRR for ; Fri, 20 Mar 2020 07:12:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727236AbgCSUMj (ORCPT ); Thu, 19 Mar 2020 16:12:39 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:35024 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727183AbgCSUMi (ORCPT ); Thu, 19 Mar 2020 16:12:38 -0400 Received: by mail-lj1-f195.google.com with SMTP id u12so4036229ljo.2; Thu, 19 Mar 2020 13:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wkLX2s1nqC4/s2saqipeX2z/4ELPxY+SBvbFqtjm2hU=; b=TwydsAJj8fSLn1Uj3o2Haivq/oiV2I2M1hW88D/4YfUQq559qApPr/vx91lKXFlRgy uHBz9/vM5/FYTdnQ71kEZksPThe0VMRZ9ciUuQ/3Iua8Of4BubAkPcHsVbUPqg9gHwUP KWIo2HXFGuoD6hxCOtU8S5C0ZDUkSEknTl61QzUl5obvo/sjgLBUVorEGADx95ICPssc Z6As6Y7spouFWqt93csCiGhD/SInV/g27n2gZEhNfZewJYX5mqsB7UrHsfmvSImzp5O5 0A0LY3Vs7Fbl4edAWwTbJbVUKfmuvVZwqafLAOjM73wW0GzTP2tceZTu3ZoesttbJQ0T z61A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=wkLX2s1nqC4/s2saqipeX2z/4ELPxY+SBvbFqtjm2hU=; b=Vr5xGtXMkPhuPWoIGgtgy6KwHhHjQhvtCPFLNWYOHvfmwzKrPBphTk/hudc1rTjzpR zqMNavfmgFIPxL9t6tdcb2WfzsbhV6/pQOhwZXGokn54cYHJIEZScUcJnN2nnbd/OrD4 fnKudblsjmkza6k1bdiQlv2/teJKZavBB/JSnvCPd6PqjyUsw5j4kLtYeKtvmgAg2o4V cRdYYMPWbhXTGpDybv6nW3XizrCDh1IzyqGfs9+r1QbC+HXKmFslwFqzvWxphy9ReNG4 s6P8N741YUfEVYAQ8G8sIkxFXhpl+X03y6fva0Km62UXcscGNz9h5Ph58cFDOvUDRhwf yA/w== X-Gm-Message-State: ANhLgQ3o2m0d0sG0QWlDXUrHQY7HOK7GeCSekW3cp7lwyxN1ZJphoRJo gBMR2MFrJ2lX5UlQIarP4co= X-Google-Smtp-Source: ADFU+vsJ1IvYqKOAsalgCu/GNkuLPf8EfUK4hU2fz7zgktmlhFHKLUClSRydu3/ewT8BvJgwFzZ6DA== X-Received: by 2002:a2e:b4e5:: with SMTP id s5mr3240453ljm.190.1584648756385; Thu, 19 Mar 2020 13:12:36 -0700 (PDT) Received: from localhost.localdomain (94-29-39-224.dynamic.spd-mgts.ru. [94.29.39.224]) by smtp.gmail.com with ESMTPSA id z21sm2059317ljz.49.2020.03.19.13.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 13:12:35 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, Vinod Koul , Dan Williams , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] i2c: tegra: Better handle case where CPU0 is busy for a long time Date: Thu, 19 Mar 2020 23:11:39 +0300 Message-Id: <20200319201140.17451-2-digetx@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200319201140.17451-1-digetx@gmail.com> References: <20200319201140.17451-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Boot CPU0 always handle I2C interrupt and under some rare circumstances (like running KASAN + NFS root) it may stuck in uninterruptible state for a significant time. In this case we will get timeout if I2C transfer is running on a sibling CPU, despite of IRQ being raised. In order to handle this rare condition, the IRQ status needs to be checked after completion timeout. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index cbc2ad49043e..dabb9223990c 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1034,14 +1034,18 @@ tegra_i2c_wait_completion_timeout(struct tegra_i2c_dev *i2c_dev, disable_irq(i2c_dev->irq); /* - * There is a chance that completion may happen after IRQ - * synchronization, which is done by disable_irq(). + * Under some rare circumstances (like running KASAN + + * NFS root) CPU, which handles interrupt, may stuck in + * uninterruptible state for a significant time. In this + * case we will get timeout if I2C transfer is running on + * a sibling CPU, despite of IRQ being raised. + * + * In order to handle this rare condition, the IRQ status + * needs to be checked after timeout. */ - if (ret == 0 && completion_done(complete)) { - dev_warn(i2c_dev->dev, - "completion done after timeout\n"); - ret = 1; - } + if (ret == 0) + ret = tegra_i2c_poll_completion_timeout(i2c_dev, + complete, 0); } return ret; From patchwork Thu Mar 19 20:11:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 1258412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=MHuJKeA/; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48jykh18Dbz9sRf for ; Fri, 20 Mar 2020 07:12:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727266AbgCSUMm (ORCPT ); Thu, 19 Mar 2020 16:12:42 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:35518 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbgCSUMl (ORCPT ); Thu, 19 Mar 2020 16:12:41 -0400 Received: by mail-lf1-f68.google.com with SMTP id m15so2747872lfp.2; Thu, 19 Mar 2020 13:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8rWnveVVUhV0jZP6qk2JekF9mt/8mR18XOrixvtwDns=; b=MHuJKeA/kZXo70Js7a1TtN19e8hJGw2o6tgp5HbLKe0ifRtReSjepyflK0E44eItgL V2NeNarC+m60rA8i2OBWS+EB6+Lat0Yz5X5/yMAj8avWI0E6tB2PAujmdIjRvJzHcbJG MzkZd9RXwnGn3Y/6OCE38pkpuIl6oQhChMczStjw1ylz7OqFwnF5xnV1u/mXellR71AL LMPIRLYKnV+TiMYrlP8vmqI9hbA1O5aor9XQ62p+OzPRfkN18b9gPX8WO1sih6s6kSgv q3u5qwF1TgS+22vNUVUeBbyKfW1RRdvdxKs6mKbk0ndIsi6GvBGZVwq3R6Y9ovC95If8 B7Ww== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=8rWnveVVUhV0jZP6qk2JekF9mt/8mR18XOrixvtwDns=; b=fgwVlIurcpd31V4xVY5OOpUL69IdE4hNeoS08kbZCHkGd0iAnNKk0KSM7SDurIfJo1 lxzt0flj+DJehiQKp7mUDwS0Jt8ROk1etJ2KTpaL6XKxm1h5bRODzxUe8BsQKrbCw39I sEYw5o3DdpaR6TXQmn2AASTP+rpaFiF7y2OXi0pMWU/0GyqU0LAAMAy7eRSth86/ChEY X27KuZWI0k3NO8hPFrvFEOxpVuqJibHtfDE3p0DJOd4U5YHUzR/4YwFTsv88lKkenid7 zIaawcRdP3xSH2MiPRdSvlNObFhK7J7U2nKia7h+3vnSmyTV7/kV+TX1epnL4MALMRUq VoEg== X-Gm-Message-State: ANhLgQ07DAWSEOJZ1bIaVMdw7RVLhkcAW2vRccFuaKP729DoYcekhFrp a3uT2V36WUeyWZzJJX2kVb8= X-Google-Smtp-Source: ADFU+vtSQAmtsDiVKncNEieuoVMXJL3wofav79o9W9WxOvss1hAc05X546TLUW07at33Bn8DfcG8OQ== X-Received: by 2002:a19:7907:: with SMTP id u7mr3123765lfc.18.1584648757441; Thu, 19 Mar 2020 13:12:37 -0700 (PDT) Received: from localhost.localdomain (94-29-39-224.dynamic.spd-mgts.ru. [94.29.39.224]) by smtp.gmail.com with ESMTPSA id z21sm2059317ljz.49.2020.03.19.13.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 13:12:37 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, Vinod Koul , Dan Williams , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] i2c: tegra: Synchronize DMA before termination Date: Thu, 19 Mar 2020 23:11:40 +0300 Message-Id: <20200319201140.17451-3-digetx@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200319201140.17451-1-digetx@gmail.com> References: <20200319201140.17451-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org DMA transfer could be completed, but CPU (which handles DMA interrupt) may get too busy and can't handle the interrupt in a timely manner, despite of DMA IRQ being raised. In this case the DMA state needs to synchronized before terminating DMA transfer in order not to miss the DMA transfer completion. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index dabb9223990c..b69a10497cd5 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1224,6 +1224,15 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, time_left = tegra_i2c_wait_completion_timeout( i2c_dev, &i2c_dev->dma_complete, xfer_time); + /* + * Synchronize DMA first, since dmaengine_terminate_sync() + * performs synchronization after the transfer's termination + * and we want to get a completion if transfer succeeded. + */ + dmaengine_synchronize(i2c_dev->msg_read ? + i2c_dev->rx_dma_chan : + i2c_dev->tx_dma_chan); + dmaengine_terminate_sync(i2c_dev->msg_read ? i2c_dev->rx_dma_chan : i2c_dev->tx_dma_chan);