Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2202476rdb; Fri, 8 Dec 2023 00:54:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaH/tYnSI9zZAU2En4q94m9ZsWz0O9cl4Y/OVi9uuzv3oGYEYovH6j1lmGFmo5j5fwGQAQ X-Received: by 2002:a17:90a:304b:b0:28a:2f48:ce0a with SMTP id q11-20020a17090a304b00b0028a2f48ce0amr396890pjl.66.1702025657567; Fri, 08 Dec 2023 00:54:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702025657; cv=none; d=google.com; s=arc-20160816; b=NwBU6t4y1m7WUufCzUodsMvwRQzxsVMOtR0fZT7+ZLLEqofzs3z0YGCn474zsHVhXW yDu8Ei450/8S3mlHrX5wrqACqSsBtjOeK2fbae0DXpMZ2sTtJp4LvdZoSHtvT75YMogn z4rxDzCfri7kTXx2yoSdbtF7z8km6drg9/VGK/JkZetFT025dDhsfSNyf6drCY1RfW43 3baEYP8lK0YfYLZCi2FT9T5VNfC4+fcZDhAvz6cQNSffCLA2SrPZob6Uh6tbVfGYHLOd vAyojc+m1cNI1Xno+MPDvTXgzDyiux3LsxNkBUaQ9HBZUWAkbYfeJCZT9AVq0Z4Tcdv8 9f3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ZznzSpsp3ftowq6O5Q/Cg5o9GO0Eay4RAUCcfPR/vuE=; fh=6LVGvI6PROuLp6ioimYp7On4tApd20Ln57qp/hUHV7k=; b=BVYpwAk/aJq2btqe5v0pY2WbyU4ngjPrWJQ1bFIvoWisKHJF5uw+Knw8TpR0hw53Js A+NgsxB8KapBDAz1hqzTRyuvjv4J4dtRoKwKjc3F2SGYiK5vyRj6Z5B7UmgusjH2c8HR fiAOiIBOH/BURkBcI/a9y/6kMUfFFAQxWjjzVlUSP7yJ7OH5Fe1e39AgGmRzdL2nO6as HfdZfQi5h8yYjmz0bKc8QR4j+ajCzTh8HuyT/nu6ScFsRWTZcx+zp0xwrhh99cktfwac FbQLKM1CgMGll5nBbRTXo3nQjRG1AQSpmC3BJbaRKNhDa9vUwmKnBq/JQjYXBjNWEnCt DHPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@friendlyarm-com.20230601.gappssmtp.com header.s=20230601 header.b=AVhC9k83; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id 30-20020a17090a09a100b00286926f5b20si2614054pjo.148.2023.12.08.00.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 00:54:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@friendlyarm-com.20230601.gappssmtp.com header.s=20230601 header.b=AVhC9k83; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id F234D80C2551; Fri, 8 Dec 2023 00:54:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573358AbjLHIx6 (ORCPT + 99 others); Fri, 8 Dec 2023 03:53:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235774AbjLHIxz (ORCPT ); Fri, 8 Dec 2023 03:53:55 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A62C61737 for ; Fri, 8 Dec 2023 00:54:00 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-54c7744a93fso2619529a12.2 for ; Fri, 08 Dec 2023 00:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=friendlyarm-com.20230601.gappssmtp.com; s=20230601; t=1702025639; x=1702630439; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZznzSpsp3ftowq6O5Q/Cg5o9GO0Eay4RAUCcfPR/vuE=; b=AVhC9k83gKxJJxcAdzBoWahkcE4gAJu5o35ldYSxUWTwhNWFeCORdCVNbPnQNKiMtS L5j1HgpPnOg0r5fxmWG1MEoXLxY4rFiGt5r0pHhkpSOWxav1ejVsu33AJmAIrNPP2Rw/ NHcgqu6DXS8t5POAF6AtsGzoryUyItMEQ76kMibCHr/0zNSPaTRQsA598b65RaC6pJne JgOh33vJIZEjA7yD5+QeD2AeQwfK3YAGwVlKYvRzAx0x7BJ/Iu+2rvd+6yJtNLJI86za KDk7Xgt2NLPxGh4bd2Q+UL8KjFquxxuqhgK8XsdohDnhWEPXITQ/1f7bV4wIor8mQ5Ud eJVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702025639; x=1702630439; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZznzSpsp3ftowq6O5Q/Cg5o9GO0Eay4RAUCcfPR/vuE=; b=WQY9fXsgDCBcqJRY0vj2r8QJq/OlZZhL0Mi2tgU8cNux+3Hl3pZFsAiIi6+7qFHopd AsldCPhCF3aeMWrO8e8s0coNTvbq+sDlFd+hvGfylX4ymi4yfkLtX5SLy/fhavRwBSnX SfRWWMMxeHS4EkiQOhe9moDvXvMbMV3ROtBPI/cl+LD1+HRNYnZgeVsStn7/vgzG79/C 6ciS2eF86GrjklnSPplhzTzBZRLV7k88jYUIfD2+cu0wIpYwj86U0M8x2p1Xyq470pQu xJQ+P5qRKURTALpirKCadJw5gFANT8t+gPsXGPFtZwIgAYGt3JzsSnkyq03GtgCNVOJh +yxQ== X-Gm-Message-State: AOJu0YxvoKXTquhIG3KUKqpEMVPJFSLGaUp2wL3U6SSyGop97SESl5+B W7/qIk0ATtmrYCNK/T6Qz36lyqGW/XwkkpPHyCOFGA== X-Received: by 2002:a50:a6d6:0:b0:54c:4837:9a9f with SMTP id f22-20020a50a6d6000000b0054c48379a9fmr2315391edc.70.1702025638968; Fri, 08 Dec 2023 00:53:58 -0800 (PST) MIME-Version: 1.0 References: <20231207082200.16388-1-jensenhuang@friendlyarm.com> <5e11553952c02ad20591992be4284bbd@manjaro.org> <95cc7716-ba01-e239-e7c0-eba0b7da7955@collabora.com> In-Reply-To: <95cc7716-ba01-e239-e7c0-eba0b7da7955@collabora.com> From: Jensen Huang Date: Fri, 8 Dec 2023 16:53:47 +0800 Message-ID: Subject: Re: [PATCH v2] i2c: rk3x: fix potential spinlock recursion on poll To: Dmitry Osipenko Cc: Dragan Simic , Heiko Stuebner , Andi Shyti , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Morgan , Benjamin Bara Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 08 Dec 2023 00:54:15 -0800 (PST) On Fri, Dec 8, 2023 at 12:00=E2=80=AFAM Dmitry Osipenko wrote: > > On 12/7/23 17:10, Dragan Simic wrote: > > On 2023-12-07 10:25, Jensen Huang wrote: > >> On Thu, Dec 7, 2023 at 4:37=E2=80=AFPM Dragan Simic wrote: > >>> > >>> On 2023-12-07 09:21, Jensen Huang wrote: > >>> > 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. > >>> > >>> In case you haven't already seen the related discussion linked below, > >>> please have a look. I also added more people to the list of recipien= ts, > >>> in an attempt to make everyone aware of the different approaches to > >>> solving this issue. > >>> > >>> https://lore.kernel.org/all/655177f4.050a0220.d85c9.3ba0@mx.google.co= m/T/#m6fc9c214452fec6681843e7f455978c35c6f6c8b > >> > >> Thank you for providing the information. I hadn't seen this link befor= e. > >> After carefully looking into the related discussion, it appears that > >> Dmitry Osipenko is already working on a suitable patch. To avoid > >> duplication > >> or conflicts, my patch can be discarded. > > > > Thank you for responding so quickly. Perhaps it would be best to hear > > from Dmitry as well, before discarding anything. It's been a while > > since Dmitry wrote about working on the patch, so he might have > > abandoned it. > > This patch is okay. In general, will be better to have IRQ disabled by > default like I did in my variant, it should allow to remove the spinlock > entirely. Of course this also can be done later on in a follow up > patches. Jensen, feel free to use my variant of the patch, add my > s-o-b+co-developed tags to the commit msg if you'll do. Otherwise I'll > be able to send my patch next week. Thank you for the suggestion. I've updated the patch to your variant, and as confirmed by others, reboots are functioning correctly. I measured the overhead of enable_irq/disable_irq() by calculating ktime in the updated version, and on rk3399, the minimum delta I observed was 291/875 ns. This extra cost may impact most interrupt-based transfers. Therefore, I personally lea= n towards the current v2 patch and handle the spinlock and irqsave/restore in a follow up patch. I'd like to hear everyone's thoughts on this. -- Best regards, Jensen