From: Foo Bar <muratseker@meta.com>
To: Amit Shah <amit@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Rusty Russell <rusty@rustcorp.com.au>,
<virtualization@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
<muratseker@meta.com>
Subject: [PATCH] virtio_console: add console port to list before hvc_alloc()
Date: Sat, 31 Oct 2026 19:24:35 -0700 [thread overview]
Message-ID: <20261101022435.3466820-1-muratseker@meta.com> (raw)
From: Murat Seker <muratseker@meta.com>
init_port_console() calls hvc_alloc() before adding the port to
pdrvdata.consoles. When the port is the preferred console (for example
console=hvc0), hvc_alloc() registers it, and register_console() replays
the log buffer through put_chars(). put_chars() looks the port up by
vtermno in pdrvdata.consoles, does not find it yet and returns -EPIPE,
so hvc discards every message printed before virtio-console probed.
The messages are still in the kernel log, but a host capturing the
virtio console never receives them.
Add the port to the list before calling hvc_alloc(), and remove it again
if hvc_alloc() fails. The out_vq, outvq_lock and portdev used by
put_chars() are set up in add_port() before init_port_console() runs,
and the other users of cons.hvc check it through is_console_port().
Tested on x86_64 QEMU/KVM with KASAN, PROVE_LOCKING and DEBUG_LIST:
with console=hvc0 the virtio console now starts at [0.000000] instead of
at virtio-console probe; with hvc0 next to ttyS0 both carry the full
log; with earlycon (no replay) output is unchanged; and hot-adding and
removing extra virtconsole ports still works. No new warnings.
Fixes: 38edf58d73c2 ("virtio: console: don't assume a single console port.")
Signed-off-by: Murat Seker <muratseker@meta.com>
---
drivers/char/virtio_console.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 019bcae81af5..a31fdac65891 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1280,18 +1280,28 @@ static int init_port_console(struct port *port)
return ret;
port->cons.vtermno = ret;
+
+ /*
+ * hvc_alloc() may register the console, which replays the log buffer
+ * through put_chars(). put_chars() finds the port on this list, so
+ * add it first or the replayed messages are dropped.
+ */
+ spin_lock_irq(&pdrvdata_lock);
+ list_add_tail(&port->cons.list, &pdrvdata.consoles);
+ spin_unlock_irq(&pdrvdata_lock);
+
port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE);
if (IS_ERR(port->cons.hvc)) {
ret = PTR_ERR(port->cons.hvc);
dev_err(port->dev,
"error %d allocating hvc for port\n", ret);
port->cons.hvc = NULL;
+ spin_lock_irq(&pdrvdata_lock);
+ list_del(&port->cons.list);
+ spin_unlock_irq(&pdrvdata_lock);
ida_free(&vtermno_ida, port->cons.vtermno);
return ret;
}
- spin_lock_irq(&pdrvdata_lock);
- list_add_tail(&port->cons.list, &pdrvdata.consoles);
- spin_unlock_irq(&pdrvdata_lock);
port->guest_connected = true;
/* Notify host of port being opened */
--
2.53.0-Meta
next reply other threads:[~2026-11-01 2:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 2:24 Foo Bar [this message]
2026-11-01 2:59 ` Murat Seker
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=20261101022435.3466820-1-muratseker@meta.com \
--to=muratseker@meta.com \
--cc=amit@kernel.org \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@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
all inboxes | Powered by JetHome®