From patchwork Thu Jul 6 21:14:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengfeng Ye X-Patchwork-Id: 13304190 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 54732EB64D9 for ; Thu, 6 Jul 2023 21:15:06 +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=5gwgQdVjVj/zuIrm+Gi330/k/T3r+6vHm3r3ucmgW3k=; b=A5jQt3iS0DIk+k 6MX6HZcEG88xC8wDFUibRUfzrNdX7VBRrY+IUPE1ZRdByn2YUdzU8VRMFWuzrDl48DaJ1AMDZXvFz bS6dlVEAaJezvI9iblc8lQutAgFTsRG1l8XCjQD152tBNeApHkqvtPnWsxtjVN8qtjrraREgSut4n 0jGiD9YRzObZYozAyp7IoUG29Kdf313n72H92wVIv6c3IvgvE7phd8HFi6JNOV1sSPw/e7CEMpIAH dzWfEjmflGkjsixqeRVLvAxOwgIUAFsquoOY0ZPibQrp50sVLfp37uehE1dpWHoxFYsiYoPQmq0cW oZRLskxVKYOvBg1zBdxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHWJ8-002hTr-25; Thu, 06 Jul 2023 21:14:34 +0000 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qHWJ5-002hT5-18 for linux-arm-kernel@lists.infradead.org; Thu, 06 Jul 2023 21:14:32 +0000 Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-56597d949b1so816182eaf.1 for ; Thu, 06 Jul 2023 14:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688678068; x=1691270068; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5HPMk53DYK8e+Bl4mudoo8nEvNlWFMO8Yu/MUeAfcgw=; b=ZP97fNRMvWcbMExc1H7NSAHzWi9iQ0xIKjsiOpTh7ZYnCiKemLc54lgjzF0PME6/rt 2yKAYt5Lm/pd6tTQ54AQ05jUIuMN+ITG3dWtb1dJ0F6a1ugAKz/BmfWnPDOwTxyTVhos Xgd4QPaczjHJIMpSfnhAO7JKU/p5201ioz95KDcBTY/io3T2OhcMp1Tsga8r2lrcpnAQ 3phKz03UuaZNTOEVv5+RrCP0bo+wWFQmXfgzoWqODaeK4tXa9imo1TsJ3QYvSWZkQiFT +JblbI3IwvlUIiH/bXZpAW1l91imIAXQChMJrEsvxV+SpSLodocKsGc4s5s8rZ8ZPM7q Gbew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688678068; x=1691270068; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5HPMk53DYK8e+Bl4mudoo8nEvNlWFMO8Yu/MUeAfcgw=; b=B7MbK0o393dd239z35u4fuupH3V1QP6xHKlKEUwiscDZ7CrSO603RuaTOoG8zEHOPm PfA3xyECR9fTj6Ip7P5dWsYnOSZvF4KBW87aqaBB5GM6QFRf2NwwlEMY62KC9/IVDw7s 1ToQ7Zu5Dl29lq4JkEZNas1U6lM9k61BPxC44lRS/ApjiJDrjHsxwoRYPSw+IgykBHK7 xUCpVXk8maxa8RZX7ElEBQP0tHSkJNfe1NECLCX9CPaUwkMSVrn1dvMOD/zZ2Ulm8MNN DPqbRUbZxVMMuj/plAj3px8sizRUv1fnCAgaYi5ewnJEE7dvHx3yh7YRA4p8aan+SnTO yKTA== X-Gm-Message-State: ABy/qLZmfnVDgiEwIEzmbvNLuTjAvpWRn6VVt5xZbokCFQXuI+phcNCL BkJFpmhLKXynkSLX8Fy9Q955Maq845U= X-Google-Smtp-Source: APBJJlEJRSlMqTAsb1/Mhe3I9HeKRUQFktrGM9vLEsMb/HkYxNLD2l/sDxoUsRgbeM51/mMsK7sRgA== X-Received: by 2002:a4a:5207:0:b0:565:9028:d034 with SMTP id d7-20020a4a5207000000b005659028d034mr2334846oob.4.1688678068662; Thu, 06 Jul 2023 14:14:28 -0700 (PDT) Received: from 377044c6c369.cse.ust.hk (191host097.mobilenet.cse.ust.hk. [143.89.191.97]) by smtp.gmail.com with ESMTPSA id v14-20020a4a8c4e000000b00565fcfabab8sm1077585ooj.21.2023.07.06.14.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 14:14:28 -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 RESEND] i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue Date: Thu, 6 Jul 2023 21:14:14 +0000 Message-Id: <20230706211414.10660-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-20230706_141431_388279_FB7166FC X-CRM114-Status: GOOD ( 10.04 ) 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. Signed-off-by: Chengfeng Ye --- drivers/i2c/busses/i2c-bcm-iproc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c index 85d8a6b04885..d02245e4db8c 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,13 @@ 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); }