From patchwork Wed Nov 27 20:30:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 180335 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp6647301ilf; Wed, 27 Nov 2019 13:01:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwknw7bglsE7mwD7hnt9dd17dVg8/MPaseOvXQr4P+u+FM0oL2OUXyrLu9BxOihTGBy3te0 X-Received: by 2002:aa7:c883:: with SMTP id p3mr994833eds.130.1574888493400; Wed, 27 Nov 2019 13:01:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888493; cv=none; d=google.com; s=arc-20160816; b=IJiw7xqRjEDbuL5AmedWIIFj1inLJmZj0pHAnoaDXUIRodFaJJ2h2orVIhyoD5AXBx tKaUPd72dn6sglB3jS+s+Nw36kPsKD6MouThofpfxq4sMcJfV8mVA30NKEKIvYpn7qds QJ8pwMx021Bs2THoAsvHvczWMyodVJKPD3jKeia2gWwkusuQnnkuI5c/P4U14t5Qgtem 6EixfFJk8+T7d0uU/cp7gn9z++k21Bkwx88mXuH0zRPNsCNoj3d2pqVAEa5VYHhD2fMM biaKIpdw+LFOzuAtlX8eHaOQ6WhweBsd3ARoyfqsuAl+9Y33I2cxKB6Q9HAdQ3QGR6r8 MueA== 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=jz//2/zmF1uLNex+dP9eVNW00/XTGI0+qNVcAIq846Y=; b=0XhdcTR8oZWODL84c/+1AjfXx50VeHuvUcFIJeUkcElactoD56TSe39+Mdq9cbqUd3 9A1XZaXdvDNyRarjWJ6f2T6nsxfGgtbRBwEYoVwSb4djJcaDCle3CfRdQke4Ii+xJUI4 bADjv7UMpOpGojc+RhQomk1iue02rK6HrcTaOyFLYohNoDhKKD/4EFUWfDdzIrB17BmO olWl0s2EP8/A6bLLAp1jixF4HQUBIVhxQb4wfS+BZxKFBbwpdkAER+v4T2T29nqhFzWb RiGmICzR8lFfUjgacxQcow2H+D2aN+cNcRts/hF9bSY5SuZEbXGF91HwWRruYFrcTVCm fXuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BgI5xlUh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si13023330ede.45.2019.11.27.13.01.33; Wed, 27 Nov 2019 13:01:33 -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=@kernel.org header.s=default header.b=BgI5xlUh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731740AbfK0VBb (ORCPT + 26 others); Wed, 27 Nov 2019 16:01:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:53666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731720AbfK0VB1 (ORCPT ); Wed, 27 Nov 2019 16:01:27 -0500 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 173122158C; Wed, 27 Nov 2019 21:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888486; bh=NjWy5znEkoWXqsJzxRB5cmvhQBP3xr8ifrgF/0d3lR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BgI5xlUhpFI3In54M94lMGY2Q+WMzYJCcAlp4sGvn7eeTBSwX3574wU5F3MLMStA/ 57IPHlbDxJ1PPylM/Q8dIi76LbEE9PBFXIQL/2aRF2xNBFnNv8+YQ8dxZV4pIDjheU C28VL6kbk/2kV4Bp6+8hvuK83E/uDRt90l3B4aUQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Wolfram Sang , Sasha Levin Subject: [PATCH 4.19 154/306] i2c: uniphier-f: make driver robust against concurrency Date: Wed, 27 Nov 2019 21:30:04 +0100 Message-Id: <20191127203126.897078772@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masahiro Yamada [ Upstream commit f1fdcbbdf45d9609f3d4063b67e9ea941ba3a58f ] This is unlikely to happen, but it is possible for a CPU to enter the interrupt handler just after wait_for_completion_timeout() has expired. If this happens, the hardware is accessed from multiple contexts concurrently. Disable the IRQ after wait_for_completion_timeout(), and do nothing from the handler when the IRQ is disabled. Fixes: 6a62974b667f ("i2c: uniphier_f: add UniPhier FIFO-builtin I2C driver") Signed-off-by: Masahiro Yamada Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-uniphier-f.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c index bc26ec822e268..b9a0690b4fd73 100644 --- a/drivers/i2c/busses/i2c-uniphier-f.c +++ b/drivers/i2c/busses/i2c-uniphier-f.c @@ -98,6 +98,7 @@ struct uniphier_fi2c_priv { unsigned int flags; unsigned int busy_cnt; unsigned int clk_cycle; + spinlock_t lock; /* IRQ synchronization */ }; static void uniphier_fi2c_fill_txfifo(struct uniphier_fi2c_priv *priv, @@ -162,7 +163,10 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) struct uniphier_fi2c_priv *priv = dev_id; u32 irq_status; + spin_lock(&priv->lock); + irq_status = readl(priv->membase + UNIPHIER_FI2C_INT); + irq_status &= priv->enabled_irqs; dev_dbg(&priv->adap.dev, "interrupt: enabled_irqs=%04x, irq_status=%04x\n", @@ -230,6 +234,8 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) goto handled; } + spin_unlock(&priv->lock); + return IRQ_NONE; data_done: @@ -246,6 +252,8 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) handled: uniphier_fi2c_clear_irqs(priv); + spin_unlock(&priv->lock); + return IRQ_HANDLED; } @@ -311,7 +319,7 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap, { struct uniphier_fi2c_priv *priv = i2c_get_adapdata(adap); bool is_read = msg->flags & I2C_M_RD; - unsigned long time_left; + unsigned long time_left, flags; dev_dbg(&adap->dev, "%s: addr=0x%02x, len=%d, stop=%d\n", is_read ? "receive" : "transmit", msg->addr, msg->len, stop); @@ -342,6 +350,12 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap, priv->membase + UNIPHIER_FI2C_CR); time_left = wait_for_completion_timeout(&priv->comp, adap->timeout); + + spin_lock_irqsave(&priv->lock, flags); + priv->enabled_irqs = 0; + uniphier_fi2c_set_irqs(priv); + spin_unlock_irqrestore(&priv->lock, flags); + if (!time_left) { dev_err(&adap->dev, "transaction timeout.\n"); uniphier_fi2c_recover(priv); @@ -546,6 +560,7 @@ static int uniphier_fi2c_probe(struct platform_device *pdev) priv->clk_cycle = clk_rate / bus_speed; init_completion(&priv->comp); + spin_lock_init(&priv->lock); priv->adap.owner = THIS_MODULE; priv->adap.algo = &uniphier_fi2c_algo; priv->adap.dev.parent = dev;