OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: "Denis V. Lunev" <den@openvz.org>, khorenko@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 2/2] ve/vtty: wait for a closing CT tty instead of failing the console attach
Date: Mon, 2 Nov 2026 17:51:24 +0000	[thread overview]
Message-ID: <010701a19d632cb4-bebddaa3-c9e7-4f1e-bf6d-43fd68a1577e-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261102171504.3809155-3-den@openvz.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] tty: vtty_open_master() busy-waits with bare schedule() for closing tty
--

commit ddd1463f95114c5d89bc233ad67329d19bb74551
Author: Denis V. Lunev <den@openvz.org>

ve/vtty: wait for a closing CT tty instead of failing the console attach

When the last CT-side close has committed to the final close,
vtty_open_master() used to return -EBUSY. With this patch it drops its
locks, calls schedule() and looks the pair up again. A pending signal ends
the wait with -ERESTARTSYS.

Link: https://virtuozzo.atlassian.net/browse/VSTOR-152365

> diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
> --- a/drivers/tty/pty.c
> +++ b/drivers/tty/pty.c

[ ... ]

>  	if (!created && slave->count == 0) {
> -		ret = -EBUSY;
> -		goto err_unlock;
> +		ret = -ERESTARTSYS;
> +		if (signal_pending(current))
> +			goto err_unlock;
> +		tty_unlock(slave);
> +		vtty_drop_context();
> +		mutex_unlock(&tty_mutex);
> +		schedule();
> +		goto retry;
>  	}

[Severity: Low]
Is a bare schedule() the right way to wait here? The task is still
TASK_RUNNING, and nothing sets the task state or waits on an event. In
that case schedule() only yields the CPU, and the loop becomes a busy-wait.

The closer can sleep for a while before it reaches vtty_shutdown():

tty_release_struct()
    tty_ldisc_release(tty);
    tty_flush_works(tty);
    ...
    mutex_lock(&tty_mutex);
    release_tty(tty, idx);

While it does this, vtty_open_master() keeps looping. Each pass does the
following:

    mutex_lock(&tty_mutex);
    ...
    mutex_unlock(&tty_mutex);
    schedule();

So the opener can use up to a full CPU and keeps contending with the closer
for tty_mutex. If the opener has a higher priority (for example SCHED_FIFO
or SCHED_RR) and runs on the same CPU as the closer, can it starve the
closer, so that the loop doesn't end until a signal arrives?

The commit message says the spinning matches tty_open(). Would a short
sleep, for example msleep_interruptible(), or an interruptible wait for the
pair to leave the vtty map be more robust here?

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261102171504.3809155-1-den@openvz.org?part=2

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-11-02 17:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 22:35 [Devel] [PATCH hci-8.1] ve/vtty: fix console attach failing with EBUSY while the CT closes the tty Denis V. Lunev
2026-10-29 22:38 ` no-reply
2026-11-02 10:41 ` Konstantin Khorenko
2026-11-02 10:42 ` Konstantin Khorenko
2026-11-02 15:17 ` Konstantin Khorenko
2026-11-02 17:15   ` [Devel] [PATCH hci-8.1 0/2] ve/vtty: wait for a closing CT tty in the kernel, drop the EAGAIN return Denis V. Lunev
2026-11-02 17:15     ` [Devel] [PATCH hci-8.1 1/2] Revert "ve/vtty: fix console attach failing with EBUSY while the CT closes the tty" Denis V. Lunev
2026-11-02 17:48       ` no-reply
2026-11-02 17:15     ` [Devel] [PATCH hci-8.1 2/2] ve/vtty: wait for a closing CT tty instead of failing the console attach Denis V. Lunev
2026-11-02 17:51       ` no-reply [this message]
2026-11-02 18:09       ` Vladimir Riabchun
2026-11-03 12:42         ` Denis V. Lunev
2026-11-03 15:54     ` [Devel] [PATCH hci-8.1 0/2] ve/vtty: wait for a closing CT tty in the kernel, drop the EAGAIN return Konstantin Khorenko

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=010701a19d632cb4-bebddaa3-c9e7-4f1e-bf6d-43fd68a1577e-000000@eu-central-1.amazonses.com \
    --to=no-reply@sashiko.virtuozzo.com \
    --cc=den@openvz.org \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    /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