From patchwork Wed Feb 5 03:55:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vicki Pfau X-Patchwork-Id: 13960545 X-Patchwork-Delegate: jikos@jikos.cz Received: from endrift.com (endrift.com [173.255.198.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AED8D20B1EC for ; Wed, 5 Feb 2025 04:05:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.255.198.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738728318; cv=none; b=jvA05UfHu9Wp2H/AKF3F80PTztG4P6FhlO+s2aRxbW8JXyz+VA2qrZXmAUcbaqo/RH5wZpCsD7jgbfXjJ2skzAdGTqeJyw1nEZTSvX2oCv/Dy6PGtd2mit8WhJ5abi29OyOOUhj2MkXYdI92satQSwgpamafqmewZMyCcu5awsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738728318; c=relaxed/simple; bh=PxxpiL/8c3vT0OkJq6Gr+zvkD+mKmTbxi3tOYNWzB/Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rbxZfHxRZJP18Ta8FAxH1c0CKJOD1zIcQfIOLtLqnnsiKjjhuYnSUt1HPsshriucoNQWvbNIzlJDb0x4k68VeEdCSPt/TMZD0RDTIPjviOTj3I+Mql8ts7lrm4P3U6cEae/yI2xFbygpsWkZWVFzc1QRxkuAimtBfg6PI/gIg6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=endrift.com; spf=pass smtp.mailfrom=endrift.com; dkim=pass (2048-bit key) header.d=endrift.com header.i=@endrift.com header.b=NYTDeIMP; arc=none smtp.client-ip=173.255.198.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=endrift.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=endrift.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=endrift.com header.i=@endrift.com header.b="NYTDeIMP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=endrift.com; s=2020; t=1738727758; bh=PxxpiL/8c3vT0OkJq6Gr+zvkD+mKmTbxi3tOYNWzB/Y=; h=From:To:Cc:Subject:Date:From; b=NYTDeIMPhoXVyrSgrko6OycTox6TzzCuHRP5atVwyafdStmu9nxog6RjZkiy46fPZ HxuyoFwX/AkAfKta4TtSk7lu68JPASAySIK4muBdlK491SuZGeDZLuH33PF2hI94GJ TrBG+o/mqTIOrx603uNIGyPwKmdLY041i1/S6yYd4wQPYy6CO4snXfLRNrzk2AZafU NYtixlVdIm+ueQttOT1ggu1vTh8/bScbfrrrPQGoTmuZsZ4YYuwab4tit/bpHvNEWa 6mFxbA4v2+kS5GIv80G1P90WBiiWEDFSJKBgCwk/kGm/EKbYAUllngC5RBUJD0FGQX Zo4DuUVJODalQ== Received: from nebulosa.vulpes.eutheria.net (71-212-74-234.tukw.qwest.net [71.212.74.234]) by endrift.com (Postfix) with ESMTPSA id DDBDF13208A; Tue, 4 Feb 2025 19:55:57 -0800 (PST) From: Vicki Pfau To: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org Cc: Vicki Pfau Subject: [PATCH 1/3] hid-steam: Move hidraw input (un)registering to work Date: Tue, 4 Feb 2025 19:55:27 -0800 Message-ID: <20250205035529.1022143-1-vi@endrift.com> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Due to an interplay between locking in the input and hid transport subsystems, attempting to register or deregister the relevant input devices during the hidraw open/close events can lead to a lock ordering issue. Though this shouldn't cause a deadlock, this commit moves the input device manipulation to deferred work to sidestep the issue. Signed-off-by: Vicki Pfau --- drivers/hid/hid-steam.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index af38fc8eb34f..395dbe642f00 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -313,6 +313,7 @@ struct steam_device { u16 rumble_left; u16 rumble_right; unsigned int sensor_timestamp_us; + struct work_struct unregister_work; }; static int steam_recv_report(struct steam_device *steam, @@ -1072,6 +1073,31 @@ static void steam_mode_switch_cb(struct work_struct *work) } } +static void steam_work_unregister_cb(struct work_struct *work) +{ + struct steam_device *steam = container_of(work, struct steam_device, + unregister_work); + unsigned long flags; + bool connected; + bool opened; + + spin_lock_irqsave(&steam->lock, flags); + opened = steam->client_opened; + connected = steam->connected; + spin_unlock_irqrestore(&steam->lock, flags); + + if (connected) { + if (opened) { + steam_sensors_unregister(steam); + steam_input_unregister(steam); + } else { + steam_set_lizard_mode(steam, lizard_mode); + steam_input_register(steam); + steam_sensors_register(steam); + } + } +} + static bool steam_is_valve_interface(struct hid_device *hdev) { struct hid_report_enum *rep_enum; @@ -1117,8 +1143,7 @@ static int steam_client_ll_open(struct hid_device *hdev) steam->client_opened++; spin_unlock_irqrestore(&steam->lock, flags); - steam_sensors_unregister(steam); - steam_input_unregister(steam); + schedule_work(&steam->unregister_work); return 0; } @@ -1135,11 +1160,7 @@ static void steam_client_ll_close(struct hid_device *hdev) connected = steam->connected && !steam->client_opened; spin_unlock_irqrestore(&steam->lock, flags); - if (connected) { - steam_set_lizard_mode(steam, lizard_mode); - steam_input_register(steam); - steam_sensors_register(steam); - } + schedule_work(&steam->unregister_work); } static int steam_client_ll_raw_request(struct hid_device *hdev, @@ -1231,6 +1252,7 @@ static int steam_probe(struct hid_device *hdev, INIT_LIST_HEAD(&steam->list); INIT_WORK(&steam->rumble_work, steam_haptic_rumble_cb); steam->sensor_timestamp_us = 0; + INIT_WORK(&steam->unregister_work, steam_work_unregister_cb); /* * With the real steam controller interface, do not connect hidraw. @@ -1291,6 +1313,7 @@ static int steam_probe(struct hid_device *hdev, cancel_work_sync(&steam->work_connect); cancel_delayed_work_sync(&steam->mode_switch); cancel_work_sync(&steam->rumble_work); + cancel_work_sync(&steam->unregister_work); return ret; } @@ -1307,6 +1330,7 @@ static void steam_remove(struct hid_device *hdev) cancel_delayed_work_sync(&steam->mode_switch); cancel_work_sync(&steam->work_connect); cancel_work_sync(&steam->rumble_work); + cancel_work_sync(&steam->unregister_work); hid_destroy_device(steam->client_hdev); steam->client_hdev = NULL; steam->client_opened = 0; From patchwork Wed Feb 5 03:55:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vicki Pfau X-Patchwork-Id: 13960544 X-Patchwork-Delegate: jikos@jikos.cz Received: from endrift.com (endrift.com [173.255.198.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AECEC25A62E for ; Wed, 5 Feb 2025 04:05:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.255.198.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738728318; cv=none; b=rKvKuadA0cXy815HrgLUtRpW6bc2k28vDr2WKcx/W5/RmXOW7lWfiWOSdaU8OWVB/mRTmJzNGUk57FAvjYOWJF8QtH9lvm5D7PmhV17urCbHgwvoTp1kbnTM2BL7QKzIsRJUfZiV/w3K+YZ+7z4O2jEvMRZEeApb4y8dh9x/UXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738728318; c=relaxed/simple; bh=NlcXe8q8EjOFYmk+W9np9glv6QgzAer/X1hMEvr1iQw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pKnFHBxDMYotQRmXHZSNdmtQG4lJgwJnfgWRxAr14A7Uae/daxXzlmxFSevSajdkwlvI+anrpv35rc3v31PUHxoOgZuJ/GuXp9FkIrPtCPKOfcFwa3UCtOMo/luBSyYX3evyzRF+DyfkZQx3UkhVIvY5xA1MsVQ0I6n3x3FGcjI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=endrift.com; spf=pass smtp.mailfrom=endrift.com; dkim=pass (2048-bit key) header.d=endrift.com header.i=@endrift.com header.b=qUMsqYPs; arc=none smtp.client-ip=173.255.198.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=endrift.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=endrift.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=endrift.com header.i=@endrift.com header.b="qUMsqYPs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=endrift.com; s=2020; t=1738727758; bh=NlcXe8q8EjOFYmk+W9np9glv6QgzAer/X1hMEvr1iQw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qUMsqYPsm44VOzObtSoSRs9q9cDOmc5SRgJ3GQv5P6VngrpMaZJGTKCXZf6Le7+zf 6uXZD4ff3OanMy1BUzb47H+iY4Ec8o9xMBOZnt2WKmPPEDNhreOVURKuhKznuyFQh4 bvzp0cXSOUONewHW7gdm/LHfGo5L5QJoyFTnNl3Tii04wuPsuWYWdtMFiU2zt+/cve jwEbE2e0JnHaQgnKRj/3TlHm0IQvHrIT/zBZiI/Gvdnl5Ua87QhBoPs+MHQO5icu6p urLjNtpCuPJsW9qf4hKokGXS2H/iQjzZrr4J3Z3i3PC9PstQQwU2AiIVnh8Fj5rZnn ze6SUwW9ksfaQ== Received: from nebulosa.vulpes.eutheria.net (71-212-74-234.tukw.qwest.net [71.212.74.234]) by endrift.com (Postfix) with ESMTPSA id 4845513208B; Tue, 4 Feb 2025 19:55:58 -0800 (PST) From: Vicki Pfau To: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org Cc: Vicki Pfau Subject: [PATCH 2/3] hid-steam: Mutex cleanup Date: Tue, 4 Feb 2025 19:55:28 -0800 Message-ID: <20250205035529.1022143-2-vi@endrift.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205035529.1022143-1-vi@endrift.com> References: <20250205035529.1022143-1-vi@endrift.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both branches of this if/else start with mutex_lock and end with mutex_unlock. This hoists the mutex lock/unlock outside of the if statement for simplicity. Signed-off-by: Vicki Pfau --- drivers/hid/hid-steam.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index 395dbe642f00..d6be0deea330 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -559,15 +559,13 @@ static void steam_set_lizard_mode(struct steam_device *steam, bool enable) if (steam->gamepad_mode) enable = false; + mutex_lock(&steam->report_mutex); if (enable) { - mutex_lock(&steam->report_mutex); /* enable esc, enter, cursors */ steam_send_report_byte(steam, ID_SET_DEFAULT_DIGITAL_MAPPINGS); /* reset settings */ steam_send_report_byte(steam, ID_LOAD_DEFAULT_SETTINGS); - mutex_unlock(&steam->report_mutex); } else { - mutex_lock(&steam->report_mutex); /* disable esc, enter, cursor */ steam_send_report_byte(steam, ID_CLEAR_DIGITAL_MAPPINGS); @@ -579,15 +577,14 @@ static void steam_set_lizard_mode(struct steam_device *steam, bool enable) SETTING_RIGHT_TRACKPAD_CLICK_PRESSURE, 0xFFFF, /* disable haptic click */ SETTING_STEAM_WATCHDOG_ENABLE, 0, /* disable watchdog that tests if Steam is active */ 0); - mutex_unlock(&steam->report_mutex); } else { steam_write_settings(steam, SETTING_LEFT_TRACKPAD_MODE, TRACKPAD_NONE, /* disable mouse */ SETTING_RIGHT_TRACKPAD_MODE, TRACKPAD_NONE, /* disable mouse */ 0); - mutex_unlock(&steam->report_mutex); } } + mutex_unlock(&steam->report_mutex); } static int steam_input_open(struct input_dev *dev) From patchwork Wed Feb 5 03:55:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vicki Pfau X-Patchwork-Id: 13960543 X-Patchwork-Delegate: jikos@jikos.cz Received: from endrift.com (endrift.com [173.255.198.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AED31134AB for ; Wed, 5 Feb 2025 04:05:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.255.198.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738728317; cv=none; b=V+Xe6iBt1dMfgIZRJiJ1QFCphZwpllliM6+WjwMt1EGoxH956Kad9/07G2F3NQ45vqB7klCEKQ1/6SWNyCu/52okQ+sJIwopyH67JlIRBEkE5xKHkVd1EPVp+EtDD+wmAgeAlQoyGMBDxQu8nq7WsE/XOIgZEN02ZRYXPY3rwZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738728317; c=relaxed/simple; bh=GpRtRX52C9sbH1/3xqxenzSFq/8m9v2WYvp/slEwp7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gBVsxIl1IZJ+/rLWzvsMueUkgAhu0SgqKzpLvCijegyb9KnG059C3J0FkX7Tfa09k/RVgDC79DROIwpHEGp/dlfsnFJhaJs694zvdH3X0GTLgehf2TeTvkjHBILxKUoVUjUOoz3hk6LkbAUgbwQI3LwvuF4+s+h1eO3/DnWV7iI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=endrift.com; spf=pass smtp.mailfrom=endrift.com; dkim=pass (2048-bit key) header.d=endrift.com header.i=@endrift.com header.b=YOvIYYmA; arc=none smtp.client-ip=173.255.198.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=endrift.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=endrift.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=endrift.com header.i=@endrift.com header.b="YOvIYYmA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=endrift.com; s=2020; t=1738727758; bh=GpRtRX52C9sbH1/3xqxenzSFq/8m9v2WYvp/slEwp7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YOvIYYmAfkpSMNzsFgrQhZtx0172v2acvUR3xWMB7Dn8mKgbCv0IrD7cU93uxCkqb X7w4h8IFWRve8kXQomqfhLHQh8yS6Hhzo9nzGPLe7IUBFoFdjKgNO33xC9ACo3bMjL HrY0NnSUn+1jZmmPHj3HrofFY+9PGCszp7oJHCyeE0m8BdVR1fBxEpoAoAmBfttfdO MFa6y9hmdA5dtPKpbxsOyiXvdr2mGgEtRIsv5MY8SW9BIFVlrxmQRGOOGVZ5JAMFip zSP1yytdWkreJsif7Fqd5u+f5qe/U6Bcr9u5OOBKKDFOPbZUsfjszDJ0oTtdfU6IaB s81SByS9qU07Q== Received: from nebulosa.vulpes.eutheria.net (71-212-74-234.tukw.qwest.net [71.212.74.234]) by endrift.com (Postfix) with ESMTPSA id A936013208C; Tue, 4 Feb 2025 19:55:58 -0800 (PST) From: Vicki Pfau To: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org Cc: Vicki Pfau Subject: [PATCH 3/3] hid-steam: Don't use cancel_delayed_work_sync in IRQ context Date: Tue, 4 Feb 2025 19:55:29 -0800 Message-ID: <20250205035529.1022143-3-vi@endrift.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205035529.1022143-1-vi@endrift.com> References: <20250205035529.1022143-1-vi@endrift.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Lockdep reported that, as steam_do_deck_input_event is called from steam_raw_event inside of an IRQ context, it can lead to issues if that IRQ occurs while the work to be cancelled is running. By using cancel_delayed_work, this issue can be avoided. The exact ordering of the work and the event processing is not super important, so this is safe. Signed-off-by: Vicki Pfau --- drivers/hid/hid-steam.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index d6be0deea330..0f4d55f82423 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -1614,7 +1614,7 @@ static void steam_do_deck_input_event(struct steam_device *steam, if (!(b9 & BIT(6)) && steam->did_mode_switch) { steam->did_mode_switch = false; - cancel_delayed_work_sync(&steam->mode_switch); + cancel_delayed_work(&steam->mode_switch); } else if (!steam->client_opened && (b9 & BIT(6)) && !steam->did_mode_switch) { steam->did_mode_switch = true; schedule_delayed_work(&steam->mode_switch, 45 * HZ / 100);