public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Chen-Yu Tsai <wenst@chromium.org>
Cc: Benson Leung <bleung@chromium.org>,
	Guenter Roeck <groeck@chromium.org>,
	AngeloGioacchino Del Regno 
	<angelogioacchino.delregno@collabora.com>,
	chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] platform/chromeos: cros_ec: Use per-device lockdep key
Date: Wed, 11 Jan 2023 14:04:42 +0800	[thread overview]
Message-ID: <Y75RelNR3/QVdyyK@google.com> (raw)
In-Reply-To: <CAGXv+5FELCKmmU2tiETGagOk+83x8OkYAxFTTxt+9tRdsujtmA@mail.gmail.com>

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 <tzungbi@kernel.org> 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 <tzungbi@kernel.org> 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 <tzungbi@kernel.org> 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.

      reply	other threads:[~2023-01-11  6:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06  4:55 [PATCH] platform/chromeos: cros_ec: Use per-device lockdep key Chen-Yu Tsai
2023-01-06  9:08 ` Tzung-Bi Shih
2023-01-07  5:43   ` Chen-Yu Tsai
2023-01-09  5:46     ` Tzung-Bi Shih
2023-01-09  6:19       ` Chen-Yu Tsai
2023-01-09  7:30         ` Tzung-Bi Shih
2023-01-09  7:35           ` Chen-Yu Tsai
2023-01-11  6:04             ` Tzung-Bi Shih [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y75RelNR3/QVdyyK@google.com \
    --to=tzungbi@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=groeck@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wenst@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox