From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795899486; b=XciDaahA7SpGiWkvxcIqSc+HJBU3nmuyVZ/J1DVSntbMwRlsRiZdh0OFUHzvex0eGKq3 MMWmK+zUHXi6F6t/wWcYXnU9XgpAe2U47jYMXpxwiZHU5ViTekpErLl6MRNHaw0fuMXF1 ZMiJ2C0YdOfERYMUy3pLv3xCzeSKPqM8vxQro7/MGeJuEUVgkJt7HhsKaVMOFujS56P0S 1vX/wOWUXAFNNuDoipn/gVhQbAWdhVwe7eLDl+i3PRy3LrUSyqQ3HHo7kzt2IYBIcrnvn 2L5fcVPtZDtvJqlrfn0q7EvNlr30+YWrk3V3YhKDKtAEFzh9F1DZGAUs+9/6O/tqI5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795899486; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=yisaRkWX/ONnm3WGp1sDwpQTEA0q4T4tGy4DUOgxdas=; b=kfMkdDaVBLC4MHYKOmXwAcfEz6cMCtAT0kA8UaRFdZWTnMY5mMbdMSyjVk4bbjoM0/mP TMO4uWenl6MshP6tKsQ0q4yD6oO+0miEuPozHlxSznNhEZgsE/4HRoKFoMhv+ZX68biEh PJwqFKVY3ZToCTHvTdjF5kdvv7dBbEOrhF9Z2YIgkz1yPzz9OhvZZiL1c9VaIllepS9c6 yLH0rT8PUyOWD/G1CrS3Hx1+R0ZiBzZmXsHjzYls/s4nCI3lJTF458QGLCzkYU43i2Yyq jEunjTFL0WxHpssvcot5V+fWKNsF2vIpiqBvLVfSjut6GlXdJTz5BtEQ4cfTZDsxXgQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mBKSr8Ne; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE14D606A31C; Sat, 28 Nov 2026 20:58:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mBKSr8Ne Received: by smtp.kernel.org (Postfix) with ESMTPSA id 944DD1F00893; Sat, 28 Nov 2026 20:58:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795899486; bh=yisaRkWX/ONnm3WGp1sDwpQTEA0q4T4tGy4DUOgxdas=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=mBKSr8NeAizUiJoRgnME42T+5B61UTko3rfQLmEocnd53cwYatBz0NZ9X6zGO9+4u w9BbFJY08q9mgDSvA+XgDPtnrMlTAmvM37uB0/hfigocCMgy0ZjWKU6uBA2e619Hj4 GtCciVwlB8Alkk6BDhPpAESK9mxadGDWttO9RcONaQxpb3XbSKhHJJ9x8jny9McL3I KHgVxEt83WoaJSNkHqZQRXJwoj0Kcj0uZagc0rMKV6W5XBoPqqhIekp0FADBJ3SCvC xlaEuRR05KPAkBen1U0SAPqxba7MufKSPu9T3y0kncyGAkvx1b8/YE7XhrKKH3ZKoT Sff7abLuapYHw== Date: Sat, 28 Nov 2026 20:58:00 +0000 From: Jonathan Cameron To: Ayaan Mirza Baig Cc: Jiri Kosina , Benjamin Tissoires , Srinivas Pandruvada , Zhang Lixu , Zheng Shuhao , Arnav Kapoor , Lee Jones , Heiko Stuebner , linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com Subject: Re: [PATCH v4] HID: hid-sensor-hub: avoid lock inversion in sensor_hub_remove() Message-ID: <20261128205800.75cae459@jic23-hlaptop> In-Reply-To: <20261123145505.1295929-1-ayaanmirzabaig85@gmail.com> References: <20261123145505.1295929-1-ayaanmirzabaig85@gmail.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 23 Nov 2026 20:25:05 +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. > > Reported-by: syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/all/6afddf21.a11fe2ad.1b4426.0003.GAE@google.com/T/ > Signed-off-by: Ayaan Mirza Baig This seems fine to me now. However, sashiko is tripping over it and failing to apply. Don't resend just for that, but if you do another version make sure that the patch includes what it is based on. Easiest route to that I've found is let b4 do it for you as that also generates any dependent patch list with the appropriate IDs. Reviewed-by: Jonathan Cameron > --- > Changes in v4: > - Actually pass 'data' instead of NULL to device_for_each_child() in > sensor_hub_remove() (inadvertently omitted in v3). > > Changes in v3: > - Rebase onto hid/for-next over commit 41cb3076a221 ("HID: sensor-hub: > Remove clients before stopping hardware"). > - 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 | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c > index e9d6eb3b3831..ce9602945586 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, > + device_for_each_child(&hdev->dev, data, > 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. */