Skip to contentSkip to conversation

Input: synaptics - add transparent pass-through mode for TrackPoint

PATCH Superseded Laserology OSS 2 participants 2 messages Aug 9

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: synaptics - add transparent pass-through mode for TrackPoint

This reworks an earlier implementation by Miroslav Bendík from 2022 that was never merged. It keeps the same hardware-mode approach but commits the mode flag only after a successful mode command, moves the reconnect handling into a generic psmouse hook instead of protocol- specific checks in psmouse-interrupt, and documents the interface.

---
 .../ABI/testing/sysfs-driver-synaptics        |  28 +++
 MAINTAINERS                                   |   1 +
 drivers/input/mouse/psmouse-base.c            |  12 +-
 drivers/input/mouse/psmouse.h                 |   7 +
 drivers/input/mouse/synaptics.c               | 215 +++++++++++++++++-
 drivers/input/mouse/synaptics.h               |   2 +
 6 files changed, 254 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-synaptics
Documentation/ABI/testing/sysfs-driver-synaptics new file +28 -0
new file mode 100644
index 000000000000..bec715677e3e
@@ -0,0 +1,28 @@
+What:		/sys/bus/serio/devices/serioX/transparent_mode
+Date:		August 2026
+Contact:	[email protected]
+Description:
+		Controls the transparent pass-through mode of Synaptics
+		touchpads that feature a pass-through (PS/2 guest) port, such as
+		those used for a TrackPoint.
+
+		In normal operation the touchpad serves as the PS/2 host for
+		the pass-through guest: it scans the guest during its own scan
+		cycle and encapsulates the guest's data into its own packets,
+		which limits the guest to the touchpad's low poll rate. When
+		transparent mode is enabled the touchpad stops generating its
+		own packets and simply relays the raw byte stream of the
+		pass-through guest, letting the guest run at its high poll rate
+		while the touchpad is effectively disabled.
+
+		Write 1 to enable the mode, or 0 to disable it. Reading the
+		attribute returns the current state ("0" or "1").
+
+		Note that both devices cannot be serviced at full rate at the
+		same time on this hardware; enabling the mode disables the
+		touchpad until it is disabled again. The attribute is present
+		only on devices that report the pass-through capability.
+
+Users:		Userspace that arbitrates between full-rate TrackPoint and
+		full-rate touchpad operation. No consumer exists yet; the
+		interface is provided so that one can be developed.
MAINTAINERS +1 -0
index 8014b9f8253e..312c13690c91 100644
@@ -12817,6 +12817,7 @@ L:	[email protected]
 S:	Maintained
 Q:	http://patchwork.kernel.org/project/linux-input/list/
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git
+F:	Documentation/ABI/testing/sysfs-driver-synaptics
 F:	Documentation/devicetree/bindings/input/
 F:	Documentation/devicetree/bindings/serio/
 F:	Documentation/input/
drivers/input/mouse/psmouse-base.c +11 -1
index 6ab5f1d96eae..b2c4948a5378 100644
@@ -385,8 +385,18 @@ static void psmouse_receive_byte(struct ps2dev *ps2dev, u8 data)
 		}
 
 		if (psmouse->packet[1] == PSMOUSE_RET_ID) {
+			struct serio *serio = ps2dev->serio;
+			struct psmouse *parent_psmouse = NULL;
+
 			__psmouse_set_state(psmouse, PSMOUSE_IGNORE);
-			serio_reconnect(ps2dev->serio);
+			/* Some devices need parent to be reconnected instead */
+			if (serio->parent)
+				parent_psmouse = psmouse_from_serio(serio->parent);
+			if (parent_psmouse && parent_psmouse->pt_reconnect_parent &&
+			    parent_psmouse->pt_reconnect_parent(parent_psmouse))
+				serio_reconnect(serio->parent);
+			else
+				serio_reconnect(serio);
 			return;
 		}
 
drivers/input/mouse/psmouse.h +7 -0
index 90ed8cd15d85..7525926f5121 100644
@@ -128,6 +128,13 @@ struct psmouse {
 
 	void (*pt_activate)(struct psmouse *psmouse);
 	void (*pt_deactivate)(struct psmouse *psmouse);
+
+	/*
+	 * Called on the parent device when a pass-through guest reports a new
+	 * device announcement (0xAA 0x00). Return true if the parent, and not
+	 * the guest, should be reconnected.
+	 */
+	bool (*pt_reconnect_parent)(struct psmouse *psmouse);
 };
 
 struct psmouse *psmouse_from_serio(struct serio *serio);
drivers/input/mouse/synaptics.c +205 -10

294 lines not on this page · raw message

drivers/input/mouse/synaptics.h +2 -0
index 3853165b6b3a..c1a78eb29c11 100644
@@ -24,6 +24,7 @@
 /* synaptics modes */
 #define SYN_BIT_ABSOLUTE_MODE		BIT(7)
 #define SYN_BIT_HIGH_RATE		BIT(6)
+#define SYN_BIT_TRANSPARENT_MODE	BIT(5)
 #define SYN_BIT_SLEEP_MODE		BIT(3)
 #define SYN_BIT_DISABLE_GESTURE		BIT(2)
 #define SYN_BIT_FOUR_BYTE_CLIENT	BIT(1)
@@ -186,6 +187,7 @@ struct synaptics_data {
 
 	bool absolute_mode;			/* run in Absolute mode */
 	bool disable_gesture;			/* disable gestures */
+	bool transparent_mode;			/* pass packets directly from guest */
 
 	struct serio *pt_port;			/* Pass-through serio port */
 	bool pt_port_open;
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

New issues:
- [Critical] Missing pass-through port check in psmouse_receive_byte causes type confusion and control flow hijacking for non-psmouse parent ports.
- [High] Blind cast of pass-through port's drvdata in synaptics_set_transparent_mode leads to type confusion and NULL pointer dereferences.
- [Medium] Hardware and software states become permanently desynchronized if the guest port is stopped while transparent mode is active.
- [Medium] Unprotected updates to protocol_handler and pktsize in synaptics_set_transparent_mode() cause a data race with the RX interrupt.
- [Medium] Skipping synaptics_set_mode() during reconnect in transparent mode leaves the hardware uninitialized when transparent mode is later disabled.

Pre-existing issues:
- [High] Failing to create sysfs attributes leaks the pass-through port and causes a use-after-free on its access. --

--- Patch [1]: [PATCH] Input: synaptics - add transparent pass-through mode for TrackPoint --- commit 1fc824e1e4a325dcff29e0fb66487d7ede60f009
Author: Laserology OSS <[email protected]>
Subject: Input: synaptics - add transparent pass-through mode for TrackPoint

This patch adds a transparent pass-through mode for Synaptics touchpads with a pass-through port. It allows the guest device to run at its full poll rate while temporarily disabling the touchpad.

Quoted 3 lines
drivers/input/mouse/psmouse-base.c +0 -0

[ ... ]

Quoted 4 lines
drivers/input/mouse/psmouse-base.c +0 -0
@@ -392,8 +392,18 @@ static void psmouse_receive_byte(struct ps2dev *ps2dev, u8 data)
 		}
 
 		if (psmouse->packet[1] == PSMOUSE_RET_ID) {

drivers/input/mouse/psmouse-base.c static void psmouse_receive_byte(struct ps2dev *ps2dev, u8 data) · line 403

Quoted 10 lines
drivers/input/mouse/psmouse-base.c +8 -1
+			struct serio *serio = ps2dev->serio;
+			struct psmouse *parent_psmouse = NULL;
+
 			__psmouse_set_state(psmouse, PSMOUSE_IGNORE);
-			serio_reconnect(ps2dev->serio);
+			/* Some devices need parent to be reconnected instead */
+			if (serio->parent)
+				parent_psmouse = psmouse_from_serio(serio->parent);
+			if (parent_psmouse && parent_psmouse->pt_reconnect_parent &&
+			    parent_psmouse->pt_reconnect_parent(parent_psmouse))

[Severity: Critical]
Is it safe to unconditionally cast serio->parent's driver data to a psmouse struct here?

If the parent port is a multiplexer driven by ps2mult, its driver data would be a different struct. Accessing parent_psmouse->pt_reconnect_parent could then lead to type confusion and read a bogus function pointer, potentially causing a crash or arbitrary execution when called.

Quoted 9 lines
drivers/input/mouse/psmouse-base.c +3 -0
+				serio_reconnect(serio->parent);
+			else
+				serio_reconnect(serio);
 			return;
 		}
 
drivers/input/mouse/synaptics.c +0 -0

[ ... ]

drivers/input/mouse/synaptics.c static void synaptics_pt_stop(struct serio *serio) · line 754

Quoted 6 lines
drivers/input/mouse/synaptics.c +2 -0
@@ -672,6 +750,8 @@ static void synaptics_pt_stop(struct serio *serio)
 
 	guard(serio_pause_rx)(parent->ps2dev.serio);
 	priv->pt_port = NULL;
+
+	synaptics_update_protocol_handler(parent);

[Severity: Medium]
If the guest port is unbound while transparent mode is active, priv->pt_port becomes NULL and synaptics_update_protocol_handler() will revert the software handler to synaptics_process_byte. Will this cause the hardware and software states to become permanently desynchronized?

The hardware would still be in transparent mode sending 3-byte packets, but the software would expect 6-byte absolute packets, which could lead to erratic pointer behavior.

Quoted 1 line
drivers/input/mouse/synaptics.c +0 -0
 }

[ ... ]

Quoted 1 line
drivers/input/mouse/synaptics.c +0 -0
@@ -1438,6 +1535,80 @@ PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL,

[ ... ]

drivers/input/mouse/synaptics.c PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL, · line 1588

Quoted 3 lines
drivers/input/mouse/synaptics.c +3 -0
+	WRITE_ONCE(priv->transparent_mode, value);
+
+	synaptics_update_protocol_handler(psmouse);

[Severity: Medium]
Should this call to synaptics_update_protocol_handler() be protected by guard(serio_pause_rx)? It updates psmouse->protocol_handler and psmouse->pktsize outside of the lock.

If an interrupt arrives concurrently, psmouse_receive_byte() might read the new pktsize but the old protocol_handler, leading to incorrect packet processing.

Quoted 4 lines
drivers/input/mouse/synaptics.c +4 -0
+
+	/*
+	 * The touchpad is stopped for the duration of the mode switch, but the
+	 * pass-through guest keeps streaming. It may therefore be left with a

drivers/input/mouse/synaptics.c PSMOUSE_DEFINE_ATTR(disable_gesture, S_IWUSR | S_IRUGO, NULL, · line 1602

Quoted 10 lines
drivers/input/mouse/synaptics.c +10 -0
+	 * partially assembled packet from the previous mode. Drop it so the
+	 * stream restarts cleanly in the new mode and no stale bytes are
+	 * misparsed as pointer motion or spurious button clicks.
+	 */
+	if (READ_ONCE(priv->pt_port)) {
+		struct psmouse *child = psmouse_from_serio(priv->pt_port);
+
+		if (child && child->state == PSMOUSE_ACTIVATED)
+			psmouse_set_state(child, PSMOUSE_ACTIVATED);
+	}

[Severity: High]
Does this cast safely handle the case where the guest port is unbound or bound to a different driver?

If the port is unbound, the drvdata is NULL and psmouse_from_serio() evaluates to a negative offset, causing a panic when child->state is checked.

If it is bound to another driver like serio_raw, this causes type confusion and psmouse_set_state() could dereference an invalid pointer, leading to memory corruption.

Quoted 3 lines
drivers/input/mouse/synaptics.c +3 -0
+
+	return len;
+}

[ ... ]

drivers/input/mouse/synaptics.c static int synaptics_reconnect(struct psmouse *psmouse) · line 1663

Quoted 12 lines
drivers/input/mouse/synaptics.c +6 -2
@@ -1478,8 +1655,16 @@ static int synaptics_reconnect(struct psmouse *psmouse)
 			 */
 			ssleep(1);
 		}
-		ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
-		error = synaptics_detect(psmouse, 0);
+		if (READ_ONCE(priv->transparent_mode) && READ_ONCE(priv->pt_port)) {
+			error = synaptics_enter_transparent_mode(psmouse);
+			if (!error) {
+				serio_reconnect(priv->pt_port);
+				return 0;
+			}

[Severity: Medium]
Returning early here bypasses the normal synaptics_set_mode() initialization during reconnect. If the user later disables transparent mode via sysfs, synaptics_exit_transparent_mode() only restores the previous mode byte but won't re-enable Advanced Gesture Mode or other configurations set up by synaptics_set_mode().

Could this leave the touchpad uninitialized after a suspend/resume cycle?

Quoted 5 lines
drivers/input/mouse/synaptics.c +4 -0
+		} else {
+			ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETID);
+			error = synaptics_detect(psmouse, 0);
+		}
 	} while (error && ++retry < 3);

[ ... ]

Quoted 1 line
drivers/input/mouse/synaptics.c +0 -0
@@ -1691,9 +1869,26 @@ static int synaptics_init_ps2(struct psmouse *psmouse,

[ ... ]

drivers/input/mouse/synaptics.c static int synaptics_init_ps2(struct psmouse *psmouse, · line 1893

Quoted 10 lines

init_fail:

drivers/input/mouse/synaptics.c +6 -0
+	if (!priv->absolute_mode && SYN_ID_DISGEST_SUPPORTED(priv->info.identity))
+		device_remove_file(&psmouse->ps2dev.serio->dev,
+				   &psmouse_attr_disable_gesture.dattr);
+	if (SYN_CAP_PASS_THROUGH(priv->info.capabilities))
+		device_remove_file(&psmouse->ps2dev.serio->dev,
+				   &psmouse_attr_transparent_mode.dattr);
 	kfree(priv);
 	return err;
 }

[Severity: High]
This isn't a bug introduced by this patch, but if device_create_file() fails in synaptics_init_ps2(), the code jumps to init_fail, frees the priv structure, and returns an error without unregistering the pass-through serio child port.

The child port remains active, and any subsequent interaction with it could trigger callbacks that dereference the freed parent->private pointer, resulting in a use-after-free. Should the port be unregistered during cleanup?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1