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=1796404982; b=Is9/fBoe4+Gjat/hWhTpqatN1/8qldxY4lXgM9gqMVprAVCZree+znLgUga7iOTZp2cs UASSJsKN4QMeldWyuTWSDcI1BoZI2nJR/ukRIo26TSkVSFIZV0k0Ks19PUZYu+TOuI360 TyiGVhEMf5PQ6mzYdwRWZUMqgQWsYwAN4WePTlc5+Z8uv7ccCQYhK3+d85e3qQFfNzoW6 0sinMfoSZ70emKlsIShXYCTlb3nOdne+ojOJImANHRyYYusWIp/S9fcCxPX8Yg1vs2cDk 1r3uWxTYzvcUnxEIqnMiPs33lFmXif+/3//RUkUMrPkvIiLhWT3jJxecPHQiEsJhdIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796404982; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=0ZjLcPkqkwGM0OrjgLvoJyEugvBmFP72SKxNhHjUOIo=; b=OnVak4lpu4MmA7XuzlegDiyPLRRgfmvPcQri/nRz9e/G9LnvhwfqrY0ZTSdLPX5VY3SF PdHWw3KzBonKXmKIIAa8rYkdtk0s4gRuYba8GbNH4yZXyxJn6RnZdzbtfjUtjd2vileyu o8pmYkpA6UqKbgR/ZowxQi9piBaqGAudgfbdwEozH2UXWgNv5Y+AzYDR5Jqj63myjI0/5 E6sSKqckou5mQMzGy9ppyv1CKUGqB0qaXJpssCcTHqsXfzOb9snbvPRUU68AUlnCOmPGf UHW0/Pxsbbwn9k+ubyLvC925U4bljO54y01NCcTFY9ccDDWPWlPTVfydQrQrhPUZKlQ== 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=luxU2AbN; 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 E7162606A32C for ; Fri, 4 Dec 2026 17:23:01 +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=luxU2AbN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59EC31F0093B; Fri, 4 Dec 2026 17:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796404981; bh=0ZjLcPkqkwGM0OrjgLvoJyEugvBmFP72SKxNhHjUOIo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=luxU2AbNRoWq+NsnRiBjVOFxEYKO+JbkKtzupFG4AwlAWznhrQpyJzCD5ZqBp6v8Z ugdpMW+QUBehHS0jDox8v6B30Hv740hcy+DjSWVredFH6AhekDmEObpIkROBx1Q5Xe Sowdmmv9Knh18rBorEzXY4b09Bnhd+c+ttMkQe1Ua698MZFWQ2QLW/oS3wRKEbR/bE l09kyEklGdc89brjsQ85cALzhqkyfawb8XOtWBNSaeirT+DQ/kCAqYHrbmyBldJtB+ DONAe9eo5B6JpXjoeLTKnQuIB+9/OCf0pgVpB1+uXNRxUQXw06DcPx0wLIb5feKAwz NBexEUB95ugPA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RESEND v6 2/4] tty: serdev: Export functions to pause receive_buf callback calls Reply-To: sashiko-reviews@lists.linux.dev To: "Markus Probst" Cc: linux-serial@vger.kernel.org, ojeda@kernel.org, gary@garyguo.net In-Reply-To: <20261204-rust_serdev_probe_refactor-v6-2-0e12b6e6853b@posteo.de> References: <20261204-rust_serdev_probe_refactor-v6-0-0e12b6e6853b@posteo.de> <20261204-rust_serdev_probe_refactor-v6-2-0e12b6e6853b@posteo.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:23:00 +0000 X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] tty: serdev: ttyport_pause_rx() leaves flip-buffer work enabled while paused - [Low] tty: serdev: incomplete locking and lifecycle docs for pause/resume RX APIs - [Low] tty: serdev: commit message omits API rationale and serdev_drv_probe() change -- commit a73a9e651b0f3d8206df97abbd109f24d3e9d1c8 Author: Markus Probst > tty: serdev: Export functions to pause receive_buf callback calls > > These functions will be used to simply the serdev rust abstraction. It > also contributes to the fixing of 2 race conditions in the serdev rust > abstraction. > > Signed-off-by: Markus Probst [Severity: Low] Could the commit message explain the new API and the serdev_drv_probe() change in more detail? It does not name serdev_device_pause_rx() and serdev_device_resume_rx(), describe the two race conditions in the Rust abstraction and why RX pausing is needed in C, or mention that serdev_drv_probe() now calls serdev_device_resume_rx(). There is also a typo ("simply" -> "simplify"). > diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c > index 86d9cf8215edc..ca20304c7b20d 100644 > --- a/drivers/tty/serdev/core.c > +++ b/drivers/tty/serdev/core.c > @@ -193,6 +193,45 @@ void serdev_device_close(struct serdev_device *serde= v) > } > EXPORT_SYMBOL_GPL(serdev_device_close); > =20 > +/** > + * serdev_device_pause_rx() - pause data receive > + * @serdev: serdev device > + * > + * Pause calls to receive_buf. > + * > + * Note that if a call to receive_buf is currently executed, the functio= n will > + * sleep until it has finished. > + */ > +void serdev_device_pause_rx(struct serdev_device *serdev) > +{ > + struct serdev_controller *ctrl =3D serdev->ctrl; > + > + if (!ctrl || !ctrl->ops->pause_rx) > + return; > + > + ctrl->ops->pause_rx(ctrl); > +} > +EXPORT_SYMBOL_GPL(serdev_device_pause_rx); > + > +/** > + * serdev_device_resume_rx() - resume data receive > + * @serdev: serdev device > + * > + * Resume calls to receive_buf. > + * > + * This can be called even if not paused to ensure data receive is activ= e. > + */ > +void serdev_device_resume_rx(struct serdev_device *serdev) > +{ > + struct serdev_controller *ctrl =3D serdev->ctrl; > + > + if (!ctrl || !ctrl->ops->resume_rx) > + return; > + > + ctrl->ops->resume_rx(ctrl); > +} > +EXPORT_SYMBOL_GPL(serdev_device_resume_rx); [Severity: Low] Should the kernel-doc for serdev_device_pause_rx() and serdev_device_resume_rx() document their locking and lifecycle contracts? The comment on serdev_device_pause_rx() implies it only sleeps when receive_buf is currently running, and serdev_device_resume_rx() omits sleeping constraints altogether. In serdev-ttyport.c, both callbacks unconditionally acquire serport->lock (and serport->receive_lock). Because of that, neither function can be called from atomic context (such as write_wakeup) or from inside receive_buf(), where serport->receive_lock is already held and calling either function deadlocks. It would also help to note that data arriving while paused stays queued in the tty flip buffer up to mem_limit without asserting hardware flow control, and that the paused state persists across serdev_device_close() and reopen until resumed or re-probed. [ ... ] > diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/ser= dev-ttyport.c > index 17c18d4b0cb8f..6e11349769964 100644 > --- a/drivers/tty/serdev/serdev-ttyport.c > +++ b/drivers/tty/serdev/serdev-ttyport.c [ ... ] > @@ -185,6 +190,35 @@ static bool ttyport_close(struct serdev_controller *= ctrl) > return true; > } > =20 > +static void ttyport_pause_rx(struct serdev_controller *ctrl) > +{ > + struct serport *serport =3D serdev_controller_get_drvdata(ctrl); > + > + guard(mutex)(&serport->lock); > + > + scoped_guard(mutex, &serport->receive_lock) > + set_bit(SERPORT_PAUSE_RX, &serport->flags); > + > + if (test_bit(SERPORT_ACTIVE, &serport->flags)) > + tty_buffer_cancel_work(serport->tty->port); > +} [Severity: Medium] Does tty_buffer_cancel_work() actually prevent flush_to_ldisc() from running while RX is paused? tty_buffer_cancel_work() calls cancel_work_sync(&port->buf.work), which re-enables the work item before returning, and setting SERPORT_PAUSE_RX under serport->receive_lock already synchronizes with any in-flight ttyport_receive_buf(). When an active UART keeps receiving data while paused, every tty_flip_buffer_push() still schedules flush_to_ldisc(). Because ttyport_receive_buf() returns 0, flush_to_ldisc() calls lookahead_bufs() from the pinned buf->head before breaking. As incoming data chains up to 2,560 tty_buffer nodes, each RX push wakes the kworker, cycles buf->lock and serport->receive_lock, and rescans the entire list (O(N^2)) even though serdev-ttyport has no lookahead_buf callback. Disabling port->buf.work while paused (for example with disable_work_sync() and enable_work() coordinated with open and close) would avoid both the kworker wakeups and the rescans. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-rust_serde= v_probe_refactor-v6-0-0e12b6e6853b@posteo.de?part=3D2