Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp851751rdb; Wed, 6 Dec 2023 01:30:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0NCCCJzx1WWtoQDLku/0pJ+PRjcKgJvlhxELN+al3SJ1PHgAyl/V4FdG6ZctP0aj57TFy X-Received: by 2002:a17:90a:c901:b0:286:6cc0:cadd with SMTP id v1-20020a17090ac90100b002866cc0caddmr570126pjt.84.1701855041421; Wed, 06 Dec 2023 01:30:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701855041; cv=none; d=google.com; s=arc-20160816; b=FjdGKbwj/m0kXzebhNXGvybP94XuDdQKIJsMn3ppbVO7tS21kIDk7ne1ofq18nIuz+ tWbdaZFt8Epmk/2X9zc0sPzG4doNeFf0QY2nUtNAtlfSjqNbBQ2w7XhZYTQ6MljMaF4W SEnnK1WmxNu0KGQv4368acA1umg9VQvvxaZOA8QdrkZ+NpannNLWGpH2befdCWf6Hxcl b7LUYUW9qmjqVK9Qkks67GkgwHoJ9qc51edYKBHkgVjYcTldakwwE089OgHJf0/PGzfy FcEr7RMF/vmHNwlroM+AivsaghjZW6UOVp+iya/vNBcFLN2yMzjrWu2J5au4NvE4XQjg bJDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uuDfqj4Q4l53iyGRXb8CNnEjErofMm7TEAygFk+j/KU=; fh=VAtTgzLP67LRaNPuW8aroArme7FK3QL5fnFFIDC0mO8=; b=mnQSaACns+LR7/Yuf42ryfkz11rusYQc6EImqdBMJBslHoTScE9b4xmkboMcuwhRyw XfqBgrFKYHlx78tml/JxqePQAv73eHwozrhafRDVgfIaRzIxvdpLjTZpPfNQADZOLeMb Xv+7DX7eVrTWWiCysJpFDLYSZAhUyA+WQzV87DtefhG3uk7nbZAK4Z7uil05vykV06F7 RXqzSbIsCQnopPzTEl+qY3zYlWxWny9QRu/1gQXjz1UKM82zwkCvt77vWItyyQTSnxJx 6lFE2ax3YR0aioY9jxCe1PkWMJOJtpgeEQbr3YqT2Nd/cHUgzCp+9FMC9NGWyh5wKlaZ iGuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id pw9-20020a17090b278900b00286ab91a312si5219253pjb.79.2023.12.06.01.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 01:30:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id F120D8078E31; Wed, 6 Dec 2023 01:30:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346782AbjLFJ36 (ORCPT + 99 others); Wed, 6 Dec 2023 04:29:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346728AbjLFJ35 (ORCPT ); Wed, 6 Dec 2023 04:29:57 -0500 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8606EA4; Wed, 6 Dec 2023 01:30:00 -0800 (PST) Received: from i53875b61.versanet.de ([83.135.91.97] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rAoE4-0008Mk-HT; Wed, 06 Dec 2023 10:29:52 +0100 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: Andi Shyti , Jensen Huang Cc: Jensen Huang , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] i2c: rk3x: fix potential spinlock recursion on poll Date: Wed, 06 Dec 2023 10:29:51 +0100 Message-ID: <5298230.31r3eYUQgx@diego> In-Reply-To: <20231206090641.18849-1-jensenhuang@friendlyarm.com> References: <20231206090641.18849-1-jensenhuang@friendlyarm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 06 Dec 2023 01:30:16 -0800 (PST) Am Mittwoch, 6. Dezember 2023, 10:06:40 CET schrieb Jensen Huang: > Possible deadlock scenario (on reboot): > rk3x_i2c_xfer_common(polling) > -> rk3x_i2c_wait_xfer_poll() > -> rk3x_i2c_irq(0, i2c); > --> spin_lock(&i2c->lock); > ... > > -> rk3x_i2c_irq(0, i2c); > --> spin_lock(&i2c->lock); (deadlock here) > > Store the IRQ number and disable/enable it around the polling transfer. > This patch has been tested on NanoPC-T4. > > Signed-off-by: Jensen Huang Reviewed-by: Heiko Stuebner > --- > drivers/i2c/busses/i2c-rk3x.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c > index a044ca0c35a1..94514637c3bd 100644 > --- a/drivers/i2c/busses/i2c-rk3x.c > +++ b/drivers/i2c/busses/i2c-rk3x.c > @@ -200,6 +200,7 @@ struct rk3x_i2c { > struct clk *clk; > struct clk *pclk; > struct notifier_block clk_rate_nb; > + int irq; > > /* Settings */ > struct i2c_timings t; > @@ -1087,13 +1088,18 @@ static int rk3x_i2c_xfer_common(struct i2c_adapter *adap, > > spin_unlock_irqrestore(&i2c->lock, flags); > > - rk3x_i2c_start(i2c); > - > if (!polling) { > + rk3x_i2c_start(i2c); > + > timeout = wait_event_timeout(i2c->wait, !i2c->busy, > msecs_to_jiffies(WAIT_TIMEOUT)); > } else { > + disable_irq(i2c->irq); > + rk3x_i2c_start(i2c); > + > timeout = rk3x_i2c_wait_xfer_poll(i2c); > + > + enable_irq(i2c->irq); > } > > spin_lock_irqsave(&i2c->lock, flags); > @@ -1310,6 +1316,8 @@ static int rk3x_i2c_probe(struct platform_device *pdev) > return ret; > } > > + i2c->irq = irq; > + > platform_set_drvdata(pdev, i2c); > > if (i2c->soc_data->calc_timings == rk3x_i2c_v0_calc_timings) { >