Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6017735ybc; Wed, 27 Nov 2019 13:29:27 -0800 (PST) X-Google-Smtp-Source: APXvYqyVF6yZhUXAeqdr9D1y68DUzS93ZwS1guitFXOJvKJUfO7uM259QydWEWgMUjao2kaFbYGz X-Received: by 2002:aa7:cb19:: with SMTP id s25mr35180020edt.148.1574890167766; Wed, 27 Nov 2019 13:29:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890167; cv=none; d=google.com; s=arc-20160816; b=czboqOqwPO6024r+JhGknHx7gs0jntaP8aTnYqXmLVfD5H+EaKEoSqDRNjdTOZDh8D VYxjGyfsw6CuCGphfpKKfK77sfdkQXhiAcJl3LosNUh/UyZfA4haZOKXitT7oXHqx51X 2tVV/d6XXcJfttJLfz89aPxe88Och/05NNQdDB4i7clwTC7dPvs2YOKqfFy7Hie81VNe iAAVm/QkFlYLtyMCS7ISFiIfpExJQ9sHxnDHSGoSmywOw+NYRBypmmnB7WQMAfAxn/rj 5ZbvcFK2sC0FJryv1yhrgzmCzEuUKgJjOvkCbfSBqyR1QPvBdbg1nRGw/LDbu9Av2p3E +3nQ== 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 z16si9982779eji.25.2019.11.27.13.29.04; Wed, 27 Nov 2019 13:29:27 -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 S1731401AbfK0VBb (ORCPT + 99 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 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: 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(-) 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; -- 2.20.1