mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: Ayaan Mirza Baig <ayaanmirzabaig85@gmail.com>,
	Jiri Kosina	 <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>,
	Jonathan Cameron	 <jic23@kernel.org>
Cc: Zhang Lixu <lixu.zhang@intel.com>,
	Zheng Shuhao <viennaoffh@gmail.com>,
	 Arnav Kapoor <kapoorarnav43@gmail.com>,
	Lee Jones <lee@kernel.org>, Heiko Stuebner <heiko@sntech.de>,
		linux-input@vger.kernel.org, linux-iio@vger.kernel.org,
		linux-kernel@vger.kernel.org,
	 syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com
Subject: Re: [PATCH v3] HID: hid-sensor-hub: avoid lock inversion in sensor_hub_remove()
Date: Mon, 23 Nov 2026 06:21:12 -0800	[thread overview]
Message-ID: <3d83eafc370354cef4280fd70d1228191486a212.camel@linux.intel.com> (raw)
In-Reply-To: <20261123124715.351511-1-ayaanmirzabaig85@gmail.com>

On Mon, 2026-11-23 at 18:17 +0530, Ayaan Mirza Baig wrote:
> In sensor_hub_remove(), spin_lock_irqsave(&data->lock, flags) is held
> while calling device_for_each_child(), which iterates child devices
> via
> klist_next() and acquires the driver core's &k->k_lock.
> 
> Because &data->lock is acquired in softirq context by
> sensor_hub_raw_event() while &k->k_lock is acquired elsewhere with
> softirqs enabled, nesting &k->k_lock under &data->lock triggers a
> SOFTIRQ-safe -> SOFTIRQ-unsafe lockdep warning and risks an ABBA
> deadlock between process context and softirq context.
> 
> Move spin_lock_irqsave()/spin_unlock_irqrestore() into
> sensor_hub_finalize_pending_fn() and pass data through
> device_for_each_child(), so &data->lock is only held while inspecting
> and completing each child's pending state after klist_next() releases
> &k->k_lock.
> 
> Fixes: 8a5b38c3fd70 ("HID: hid-sensor-hub: don't use stale platform-
> data on remove")
> Reported-by: syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com
> Closes:
> https://lore.kernel.org/all/6afddf21.a11fe2ad.1b4426.0003.GAE@google.com/T/
> Suggested-by: Zheng Shuhao <viennaoffh@gmail.com>
> Signed-off-by: Ayaan Mirza Baig <ayaanmirzabaig85@gmail.com>
> ---
> Changes in v3:
>  - Actually pass 'data' instead of NULL to device_for_each_child()
>    (missed in the v2 submission).

Are you sending correct patch?

 
-	spin_lock_irqsave(&data->lock, flags);
 	device_for_each_child(&hdev->dev, NULL,
 			      sensor_hub_finalize_pending_fn);
-	spin_unlock_irqrestore(&data->lock, flags);
 


Thanks,
Srinivas

>  - Drop the NULL platform_data guard since hid/for-next already
> checks
>    dev_is_platform() and !hsdev.
> 
> Changes in v2:
>  - Attempted to pass 'data' instead of NULL to
> device_for_each_child().
> 
>  drivers/hid/hid-sensor-hub.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-
> hub.c
> index e9d6eb3b3831..090e5a232efa 100644
> --- a/drivers/hid/hid-sensor-hub.c
> +++ b/drivers/hid/hid-sensor-hub.c
> @@ -808,6 +808,8 @@ static int sensor_hub_probe(struct hid_device
> *hdev,
>  static int sensor_hub_finalize_pending_fn(struct device *dev, void
> *data)
>  {
>  	struct hid_sensor_hub_device *hsdev;
> +	struct sensor_hub_data *sd = data;
> +	unsigned long flags;
>  
>  	if (!dev_is_platform(dev))
>  		return 0;
> @@ -816,8 +818,10 @@ static int sensor_hub_finalize_pending_fn(struct
> device *dev, void *data)
>  	if (!hsdev)
>  		return 0;
>  
> +	spin_lock_irqsave(&sd->lock, flags);
>  	if (hsdev->pending.status)
>  		complete(&hsdev->pending.ready);
> +	spin_unlock_irqrestore(&sd->lock, flags);
>  
>  	return 0;
>  }
> @@ -825,14 +829,11 @@ static int
> sensor_hub_finalize_pending_fn(struct device *dev, void *data)
>  static void sensor_hub_remove(struct hid_device *hdev)
>  {
>  	struct sensor_hub_data *data = hid_get_drvdata(hdev);
> -	unsigned long flags;
>  
>  	hid_dbg(hdev, " hardware removed\n");
>  
> -	spin_lock_irqsave(&data->lock, flags);
>  	device_for_each_child(&hdev->dev, NULL,
>  			      sensor_hub_finalize_pending_fn);
> -	spin_unlock_irqrestore(&data->lock, flags);
>  
>  	mfd_remove_devices(&hdev->dev);
>  	/* Clients share one HID open; release it if references
> remain. */

  reply	other threads:[~2026-11-23 14:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 12:47 Ayaan Mirza Baig
2026-11-23 14:21 ` Srinivas Pandruvada [this message]
2026-11-23 14:53   ` Ayaan Mirza Baig

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=3d83eafc370354cef4280fd70d1228191486a212.camel@linux.intel.com \
    --to=srinivas.pandruvada@linux.intel.com \
    --cc=ayaanmirzabaig85@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=heiko@sntech.de \
    --cc=jic23@kernel.org \
    --cc=jikos@kernel.org \
    --cc=kapoorarnav43@gmail.com \
    --cc=lee@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lixu.zhang@intel.com \
    --cc=syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com \
    --cc=viennaoffh@gmail.com \
    /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

all inboxes | Powered by JetHome®