Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4877147pjb; Mon, 27 Jul 2020 07:24:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxp0o5s0ivuoDS6kUDcq8WC7H7nn8z0cofZnWJnkW+4bAdKyVIr9xJoNkIIdp9m7vTUijkn X-Received: by 2002:a17:906:aed4:: with SMTP id me20mr13027442ejb.141.1595859859102; Mon, 27 Jul 2020 07:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859859; cv=none; d=google.com; s=arc-20160816; b=o2VcJyIB2fiU3cEwZWo0z1uTIWvgG3tdmyxl05VyjXKxBgwZlTJL6+GUt/76tK9FrV DA5VVfa1X4SouKYamRTHpQkpq3eaB3pFfStrVnsg9TOZaklmVyUd2FcIvaIPzN7IQzWt nlPZNTMISob8dXhA+Z9SGQq6sQY4Cfv2j1h5AwiUu2mHq8mi3RQ7FybwOMNe0PIsgaje NKrEu3YXNetTBk2pw484ygI84vuN9mlklyY7agB5wSqAB125Rpp0TOLgBhZL6uQ9bXF1 cQcp8eP+n0gdj0YdJksK6d8JYeoXCzCbOf/NBeLhIcZ9duP8mnZG0KTQVdx/9f4Dxmqv 7mpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=neYo+JoaqMGvhmkh6iOSNBxmwf1kMzo9XIc774fdURE=; b=LNbEbVXYxSZqv0/u8YUySDlZ2z2CHQNyfV4NPswzay1ty/0fP5fibrbcB8XaqttQYQ chGQfa6lXFULAUgsWIxQKh4BKGT5YS6GaC8lJXBsGqb7fsZHq1zhAoiJXiCUci/2bFEX u/vvLOyXyS1b8lVqnW5wkqeperhfyWi7ahhATp+lKRI2oPakZkq9g7z1FaVZVrTm9vlH hxrDUe+NV8CIMOqD41VZe4IZBVF8T3uSWa3rRJndvj4BZHfwmr0jD99xNmEiveniGnqE fWy0m6QiZFFGSggrOt4kloazUBBNUNwXvefmLtFgVcAAoKKN6HGQb5AWtnF1VliVTjxK c7rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l0dIaZCq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mc26si628018ejb.333.2020.07.27.07.23.56; Mon, 27 Jul 2020 07:24:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l0dIaZCq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731940AbgG0OWh (ORCPT + 99 others); Mon, 27 Jul 2020 10:22:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:51514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731921AbgG0OWd (ORCPT ); Mon, 27 Jul 2020 10:22:33 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 60FB92075A; Mon, 27 Jul 2020 14:22:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859752; bh=aM8aXjRYZdfpSzdluY0ajWuw/nyk1LjO5JNDkFZWCuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l0dIaZCquUGFIU5T1sKdq9hbCrvqTpCJn+3B8GlBdBzK+ITE6DKufP9uWxWgOsLw4 Bg8w8p+ignYGOa83nrhJzrRgYAWm5B7nsegSAQh1G/g/+hG/ArEYXJY3zyJk9H6NsJ gTMozhCUhM8pAMjHOHKSSr/hTYrBS0OpY52UyJzA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Douglas Anderson , Sai Prakash Ranjan , Akash Asthana , Stephen Boyd , Mukesh Kumar Savaliya , Wolfram Sang , Sasha Levin Subject: [PATCH 5.7 092/179] i2c: i2c-qcom-geni: Fix DMA transfer race Date: Mon, 27 Jul 2020 16:04:27 +0200 Message-Id: <20200727134937.156171105@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Douglas Anderson [ Upstream commit 02b9aec59243c6240fc42884acc958602146ddf6 ] When I have KASAN enabled on my kernel and I start stressing the touchscreen my system tends to hang. The touchscreen is one of the only things that does a lot of big i2c transfers and ends up hitting the DMA paths in the geni i2c driver. It appears that KASAN adds enough delay in my system to tickle a race condition in the DMA setup code. When the system hangs, I found that it was running the geni_i2c_irq() over and over again. It had these: m_stat = 0x04000080 rx_st = 0x30000011 dm_tx_st = 0x00000000 dm_rx_st = 0x00000000 dma = 0x00000001 Notably we're in DMA mode but are getting M_RX_IRQ_EN and M_RX_FIFO_WATERMARK_EN over and over again. Putting some traces in geni_i2c_rx_one_msg() showed that when we failed we were getting to the start of geni_i2c_rx_one_msg() but were never executing geni_se_rx_dma_prep(). I believe that the problem here is that we are starting the geni command before we run geni_se_rx_dma_prep(). If a transfer makes it far enough before we do that then we get into the state I have observed. Let's change the order, which seems to work fine. Although problems were seen on the RX path, code inspection suggests that the TX should be changed too. Change it as well. Fixes: 37692de5d523 ("i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C controller") Signed-off-by: Douglas Anderson Tested-by: Sai Prakash Ranjan Reviewed-by: Akash Asthana Reviewed-by: Stephen Boyd Reviewed-by: Mukesh Kumar Savaliya Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-qcom-geni.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 18d1e4fd4cf34..7f130829bf018 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -367,7 +367,6 @@ static int geni_i2c_rx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg, geni_se_select_mode(se, GENI_SE_FIFO); writel_relaxed(len, se->base + SE_I2C_RX_TRANS_LEN); - geni_se_setup_m_cmd(se, I2C_READ, m_param); if (dma_buf && geni_se_rx_dma_prep(se, dma_buf, len, &rx_dma)) { geni_se_select_mode(se, GENI_SE_FIFO); @@ -375,6 +374,8 @@ static int geni_i2c_rx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg, dma_buf = NULL; } + geni_se_setup_m_cmd(se, I2C_READ, m_param); + time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT); if (!time_left) geni_i2c_abort_xfer(gi2c); @@ -408,7 +409,6 @@ static int geni_i2c_tx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg, geni_se_select_mode(se, GENI_SE_FIFO); writel_relaxed(len, se->base + SE_I2C_TX_TRANS_LEN); - geni_se_setup_m_cmd(se, I2C_WRITE, m_param); if (dma_buf && geni_se_tx_dma_prep(se, dma_buf, len, &tx_dma)) { geni_se_select_mode(se, GENI_SE_FIFO); @@ -416,6 +416,8 @@ static int geni_i2c_tx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg, dma_buf = NULL; } + geni_se_setup_m_cmd(se, I2C_WRITE, m_param); + if (!dma_buf) /* Get FIFO IRQ */ writel_relaxed(1, se->base + SE_GENI_TX_WATERMARK_REG); -- 2.25.1