From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: linux-serial@vger.kernel.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH RESEND v6 2/4] tty: serdev: Export functions to pause receive_buf callback calls
Date: Fri, 04 Dec 2026 17:23:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-250303@kernel.org> (raw)
In-Reply-To: <20261204-rust_serdev_probe_refactor-v6-2-0e12b6e6853b@posteo.de>
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 <markus.probst@posteo.de>
> 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 <markus.probst@posteo.de>
[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 *serdev)
> }
> EXPORT_SYMBOL_GPL(serdev_device_close);
>
> +/**
> + * 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 function will
> + * sleep until it has finished.
> + */
> +void serdev_device_pause_rx(struct serdev_device *serdev)
> +{
> + struct serdev_controller *ctrl = 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 active.
> + */
> +void serdev_device_resume_rx(struct serdev_device *serdev)
> +{
> + struct serdev_controller *ctrl = 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/serdev-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;
> }
>
> +static void ttyport_pause_rx(struct serdev_controller *ctrl)
> +{
> + struct serport *serport = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-rust_serdev_probe_refactor-v6-0-0e12b6e6853b@posteo.de?part=2
next prev parent reply other threads:[~2026-12-04 17:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 16:58 [PATCH RESEND v6 0/4] rust: serdev: Refactor Markus Probst
2026-12-04 16:58 ` [PATCH RESEND v6 1/4] tty: serdev: Add mutex lock Markus Probst
2026-12-04 17:22 ` sashiko-bot
2026-12-04 17:45 ` Markus Probst
2026-12-04 16:58 ` [PATCH RESEND v6 2/4] tty: serdev: Export functions to pause receive_buf callback calls Markus Probst
2026-12-04 17:23 ` sashiko-bot [this message]
2026-12-04 16:58 ` [PATCH RESEND v6 3/4] rust: serdev: Replace `active` mutex with receive pause Markus Probst
2026-12-04 16:58 ` [PATCH RESEND v6 4/4] rust: serdev: Simplify callbacks Markus Probst
2026-12-04 17:13 ` sashiko-bot
2026-12-04 17:37 ` Markus Probst
2026-12-04 17:23 ` [PATCH RESEND v6 0/4] rust: serdev: Refactor sashiko-bot
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=sashiko-outbox-250303@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-serial@vger.kernel.org \
--cc=markus.probst@posteo.de \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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