Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8921688rwl; Tue, 10 Jan 2023 22:08:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXsbxdP9yIoX8ebxxu81MNiylQIor1ONTrJyLtKdBn/trJXspBPRxf8uejU/7m38MFs2K2Uw X-Received: by 2002:a17:902:8688:b0:189:9dca:65e1 with SMTP id g8-20020a170902868800b001899dca65e1mr64776474plo.21.1673417335021; Tue, 10 Jan 2023 22:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673417335; cv=none; d=google.com; s=arc-20160816; b=x4BJRvuQHXQCsmU4h29t+kTTR9N9VJAsILIs0ooY5VpmoMiWI5dZda3nXpzWRCYzwA y54k2X9ocks2pkQXzK7VQ9OuK4vkelE847TIOuohzno/7row8EbNqtE3CpQyt1yxwtm4 V6o6hxpE1qEvdrlOLjEn4/jB/wzXWBc7FX4mUYHIc4cVQlv3Gu3Lvbi8UQ9XCTApIY9x y5Ykh900eqbLPXBxXrR9QWujUoncY/kVB9p74QClfpuS6QGoyJVVHujIuYMKm8GbYwqI p92xJlrjmoe8IuahRyS7NjNVCJoJN4DPXbgpk0fIk79yX1u/VHQb5dFiWSwX1/6wXDXp Wrmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1LMmSPPX7wBi+5EtLdCRbyjZk7rVEv1u84LGUNzAXvI=; b=Uxpsq/3q+wP1GGwNhlss1sd7J2tVRlUI9Mqbv+2fIE05To7EDwRrli+ZcETTlOFvva wR6ooQZKl6CPZNaBo22/APzX1h6o58tPsQntZ/l/5Cm9xz8FRd1UJn0NIR9h6nOo/tk8 oBZzgDAO+Ha/KYViDlXk78Qzd8T4eZHgfJu0pJhtKkzO2kJPtXzSS4OCoPbHn1UkYMmT 4GrpVLYpsuvYzGzzY7G0PJgJeixXuPXRB9Ts07sBHev1zIBT1A0LKl3LCA9ucrMcjMmh /JwYPZ5+KbhwxEnKwqqIGy4NVvkrau40LLhggnzfLXT+n5r76PthJQWeDhBbSV/JeM7i HFhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kQQcNKFR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a170902ea0c00b001926d641de9si13951915plg.553.2023.01.10.22.08.48; Tue, 10 Jan 2023 22:08:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kQQcNKFR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235407AbjAKGF1 (ORCPT + 55 others); Wed, 11 Jan 2023 01:05:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235950AbjAKGEy (ORCPT ); Wed, 11 Jan 2023 01:04:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 595D19FD8 for ; Tue, 10 Jan 2023 22:04:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1A662B81ACD for ; Wed, 11 Jan 2023 06:04:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96CADC433F0; Wed, 11 Jan 2023 06:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673417085; bh=8x00PHMnsNBNIzoLDGAVgEZW9hiYElc7W/tzQLc74OA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kQQcNKFRMghri3Bh3vkTFMYLHwtvEQBr6XibSbqxKjTZU3SDXe/TuIO3hyDm2f3eW nNUjL9vY0ih3LVd7imB+iv3jy5lN+1hxOP2VlV5IVHLRlOQ6yWtjdeNbj2S0hv7foB asthPvwQ1fwoXz/Xuu0UGaHEvQMh+4/UYwHwiMaRKfq6ZL9qxi4cPKku/m/uizwlak j8LRqj5KAzf/lwecO8lSVC1XRIC3BwnkzoSxijJFXvczqUtVyal7ooyFpmruugILEP Bno5NaYvoftfuVMPYZo+CJL7gAnTvhegFt/kVnugSo6YUxIejEYhJ7BzsoLYXf/d6t 5fppUz9s3BHIA== Date: Wed, 11 Jan 2023 14:04:42 +0800 From: Tzung-Bi Shih To: Chen-Yu Tsai Cc: Benson Leung , Guenter Roeck , AngeloGioacchino Del Regno , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] platform/chromeos: cros_ec: Use per-device lockdep key Message-ID: References: <20230106045537.1243887-1-wenst@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 09, 2023 at 03:35:08PM +0800, Chen-Yu Tsai wrote: > On Mon, Jan 9, 2023 at 3:30 PM Tzung-Bi Shih wrote: > > > > On Mon, Jan 09, 2023 at 02:19:38PM +0800, Chen-Yu Tsai wrote: > > > On Mon, Jan 9, 2023 at 1:46 PM Tzung-Bi Shih wrote: > > > > > > > > On Sat, Jan 07, 2023 at 01:43:57PM +0800, Chen-Yu Tsai wrote: > > > > > On Fri, Jan 6, 2023 at 5:08 PM Tzung-Bi Shih wrote: > > > > > > > > > > > > On Fri, Jan 06, 2023 at 12:55:37PM +0800, Chen-Yu Tsai wrote: > > > > > > > Lockdep reports a bogus possible deadlock on MT8192 Chromebooks due to > > > > > > > the following lock sequences: > > > > > > > > > > > > > > 1. lock(i2c_register_adapter) [1]; lock(&ec_dev->lock) > > > > > > > 2. lock(&ec_dev->lock); lock(prepare_lock); > > > > > > > > > > > > > > The actual dependency chains are much longer. The shortened version > > > > > > > looks somewhat like: > > > > > > > > > > > > > > 1. cros-ec-rpmsg on mtk-scp > > > > > > > ec_dev->lock -> prepare_lock > > > > > > > 2. In rt5682_i2c_probe() on native I2C bus: > > > > > > > prepare_lock -> regmap->lock -> (possibly) i2c_adapter->bus_lock > > > > > > > 3. In rt5682_i2c_probe() on native I2C bus: > > > > > > > regmap->lock -> i2c_adapter->bus_lock > > > > > > > 4. In sbs_probe() on cros-ec-i2c (passthrough) I2C bus on cros-ec > > > > > > > i2c_adapter->bus_lock -> ec_dev->lock > > > > > > > > > > > > > > While lockdep is correct that the shared lockdep classes have a circular > > > > > > > dependency, it is bogus because > > > > > > > > > > > > > > a) 2+3 happen on a native I2C bus > > > > > > > b) 4 happens on the actual EC on ChromeOS devices > > > > > > > c) 1 happens on the SCP coprocessor on MediaTek Chromebooks that just > > > > > > > happen to expose a cros-ec interface, but do not have a passthrough > > > > > > > I2C bus > > > > > > > > > > > > > > In short, the "dependencies" are actually on different devices. > > > > > > > > > > > > Path of 4 looks weird to me. > > > > > > > > > > > > Could you point out where sbs_probe() gets to acquire ec_dev->lock? > > > > > > > > > > sbs_probe() calls sbs_get_battery_presence_and_health(), which > > > > > > > > > > -> does an I2C transfer. This SBS instance is connected on the I2C bus > > > > > on the EC, so the I2C transfer > > > > > > > > > > -> acquires i2c_adapter->bus_lock, and > > > > > > > > I see. > > > > > > > > Another question: the i2c_adapter here should be different from the native > > > > I2C bus in 2 and 3. Did they really form the circular dependencies? > > > > > > That's why it's a false positive. lockdep normally doesn't track individual > > > instances, only classes of locks. The class is declared as part of the > > > mutex_init() macro. > > > > Is the following understanding correct: > > It has 2 ways to break the "fake" circular dependencies: separate lockdep key > > for i2c_adapter vs. ec_dev. The patch adopts the latter one because it has > > limited impact for other I2C-related drivers. > > That's correct. Thanks for the explanation. The patch looks good to me. Just realized a kernel-doc warning after applying the patch: $ ./scripts/kernel-doc -none include/linux/platform_data/cros_ec_proto.h include/linux/platform_data/cros_ec_proto.h:199: warning: Function parameter or member 'lockdep_key' not described in 'cros_ec_device' Please fix the warning and commit title.