From patchwork Fri Jul 7 08:49:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengfeng Ye X-Patchwork-Id: 13304600 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71A81EB64D9 for ; Fri, 7 Jul 2023 08:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=y+2sKBTZvyKNzVGzaTUV5No39pgndfR5lNAGlBRYdsk=; b=RniHakr1DyxiMk sGqpJ/6Tmud/jnAcFy4q+x975pPwbBJf/yiLiOccH11DovD9xqXtfwU5CvgeBecTUPUFQCXpA82Z6 8rZGqTTGkVCfsD+KyfVDUHA0kOFhvJcP2GKqtXtcczvYeuOp2orjAaNRKHnzA5Ionb3GuHD4i+zF5 DWyPC5U6Our0MhZyZppS8iMQ+XXgNstICXmTRrfcsEcIPGCO/jakgBxHpM3m+r/ANwIIjkURO2oa7 F81t1twCEVj21FT/YOq8x0hWIzgJwmHPHrJNCVNtMIFX12Q0mO5QklSsAE2Hj66m1WwhUKhnkQEoF WGyYOK7WQKjEbmFJoWtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHhA2-0042nI-0T; Fri, 07 Jul 2023 08:49:54 +0000 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qHhA0-0042mf-0V for linux-arm-kernel@lists.infradead.org; Fri, 07 Jul 2023 08:49:53 +0000 Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-38e04d1b2b4so1414461b6e.3 for ; Fri, 07 Jul 2023 01:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688719791; x=1691311791; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l6/HZzggng6ImBWV7Wybriq5wumL5ur/8rhDYyBTGzM=; b=mf2siBo5J9gq7eABB7Nm8y6ECnAEsFhsLEjn9li1jzqAut7sTbDqAzUa5vmqESHoT/ 3V7qqY/rXNervnLuM/b/IdNC5AthkbP9dmqgviypmZqeP4zr1W9ZUqUI/aYCZzwGLThi pw9taTdJ9DySBaNb5xk1Q0wHMgnKv3Ihs/+hiSaSIONlHvr2Oo8y4uNRb6xPWepYiAd1 yN0s9e+qQa/GkPPGErhZrmbe9OIzOhg3FpxV9l6w7PcdVH8+hkMnr1yOUHtDe67vSzEq X6mpTOIDnVs6G3/7R4djSPKVu9TyOFyn16HsaaCZW0suPaNkVseHbsYRvmxE7iFTjn1s sKLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688719791; x=1691311791; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l6/HZzggng6ImBWV7Wybriq5wumL5ur/8rhDYyBTGzM=; b=OVIv2DZ620Cn8e0fj7fIdnoN67Wm6ROOXrP7UPMng7sE/g3Faw0L/0s30+YB8YrLVx RLMOdeUHLLoaBaL685ELMk3DLcFQe+s+zi7tpn9wJo3BRAoh7oNBzv6icLv8UIQ89PcM tUOhEqcjHIRG7Wz0VVdL50Kp0uKUm/9m0g2Q/aoyaLwC6ldopARvwvhj8tt55OWPbXcB Jmbm71iPn+Ux3jHAIi0mANtBfOy+NdeCEHCskkPbBBpFpC0bzYuqPt0dWyEKQM7/B9YU tSWO6dBwLjT40DSwkTgd3EdAb1mI/XEM81eIVKQZ2164ltejEwNKwGJldKQ7Zb4jX8n6 sjjA== X-Gm-Message-State: ABy/qLZNN8x4hqFOeIh9ZedIDlOJYAdT0I4X91B4lTLS6jgF0FKI6N5n 8yyGximLIqDVoID0/BwXprk= X-Google-Smtp-Source: APBJJlFEpyo2vzyYqd2ZbgKtDCdcUh1QAkHSVhZFDmSzOSWV5c7me5KQwGYq59UC1guXPwa84d3oQA== X-Received: by 2002:aca:1c04:0:b0:3a1:e13e:a89e with SMTP id c4-20020aca1c04000000b003a1e13ea89emr3739262oic.19.1688719790616; Fri, 07 Jul 2023 01:49:50 -0700 (PDT) Received: from 377044c6c369.cse.ust.hk (191host097.mobilenet.cse.ust.hk. [143.89.191.97]) by smtp.gmail.com with ESMTPSA id bc13-20020a056808170d00b003a38df6284dsm1462632oib.11.2023.07.07.01.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 01:49:50 -0700 (PDT) From: Chengfeng Ye To: andi.shyti@kernel.org, rjui@broadcom.com, sbranden@broadcom.com, wsa@kernel.org Cc: bcm-kernel-feedback-list@broadcom.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Chengfeng Ye Subject: [PATCH v2] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue Date: Fri, 7 Jul 2023 08:49:41 +0000 Message-Id: <20230707084941.28964-1-dg573847474@gmail.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230707_014952_195516_BC69CC72 X-CRM114-Status: GOOD ( 10.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org iproc_i2c_rd_reg() and iproc_i2c_wr_reg() are called from both interrupt context (e.g. bcm_iproc_i2c_isr) and process context (e.g. bcm_iproc_i2c_suspend). Therefore, interrupts should be disabled to avoid potential deadlock. To prevent this scenario, use spin_lock_irqsave(). Fixes: 9a1038728037 ("i2c: iproc: add NIC I2C support") Signed-off-by: Chengfeng Ye Acked-by: Ray Jui Reviewed-by: Andi Shyti --- drivers/i2c/busses/i2c-bcm-iproc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c index 85d8a6b04885..30a2a3200bed 100644 --- a/drivers/i2c/busses/i2c-bcm-iproc.c +++ b/drivers/i2c/busses/i2c-bcm-iproc.c @@ -233,13 +233,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c, u32 offset) { u32 val; + unsigned long flags; if (iproc_i2c->idm_base) { - spin_lock(&iproc_i2c->idm_lock); + spin_lock_irqsave(&iproc_i2c->idm_lock, flags); writel(iproc_i2c->ape_addr_mask, iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); val = readl(iproc_i2c->base + offset); - spin_unlock(&iproc_i2c->idm_lock); + spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags); } else { val = readl(iproc_i2c->base + offset); } @@ -250,12 +251,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c, static inline void iproc_i2c_wr_reg(struct bcm_iproc_i2c_dev *iproc_i2c, u32 offset, u32 val) { + unsigned long flags; + if (iproc_i2c->idm_base) { - spin_lock(&iproc_i2c->idm_lock); + spin_lock_irqsave(&iproc_i2c->idm_lock, flags); writel(iproc_i2c->ape_addr_mask, iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); writel(val, iproc_i2c->base + offset); - spin_unlock(&iproc_i2c->idm_lock); + spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags); } else { writel(val, iproc_i2c->base + offset); }