From nobody Mon Jan 26 07:40:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1768351225; cv=none; d=zohomail.com; s=zohoarc; b=h4vKQcQWhE7AkKH2yvVi7lYmXse7nqYuutPS3SCHae02rMldiuoMtMsYgTgjmq18GjR2h5WBaAZnn+HALxfTcCTLn1+IFmC9K6tVg8QdreNVClXBd5GMOj09tF7beni4NzZL+OQ4jVymBV7ASWsd6Rj2URy5vyVHRZrQKGYk4qQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768351225; h=Content-Type:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LZUvPThUX2rHooOTpamyoy0KM0xuwJyWZshSYr3mbSs=; b=Naw32PQPCPc6gYRdwG0Fz0wJMaR/6ADKMtiPXNK8DhqgpRXZoznBwmxVdcVeQ1stQQKi594HTyFktKaggsacEPvx4r7gp3XL5NqPuppsG+zD49pOwJHRTIt/AAE7RoF56WCnko94cdkj2aFO6+p4Ub9k9lFFXQrZ1nzu0214uxs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1768351225848697.0897309281197; Tue, 13 Jan 2026 16:40:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1202417.1517987 (Exim 4.92) (envelope-from ) id 1vfovd-0005vx-JG; Wed, 14 Jan 2026 00:40:05 +0000 Received: by outflank-mailman (output) from mailman id 1202417.1517987; Wed, 14 Jan 2026 00:40:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vfovd-0005vp-EV; Wed, 14 Jan 2026 00:40:05 +0000 Received: by outflank-mailman (input) for mailman id 1202417; Wed, 14 Jan 2026 00:40:04 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vfovc-0005bB-4s for xen-devel@lists.xenproject.org; Wed, 14 Jan 2026 00:40:04 +0000 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8f7bb6a5-f0e1-11f0-b15e-2bf370ae4941; Wed, 14 Jan 2026 01:40:02 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 9547540765; Wed, 14 Jan 2026 00:40:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA606C116C6; Wed, 14 Jan 2026 00:39:58 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8f7bb6a5-f0e1-11f0-b15e-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768351200; bh=btgGbUV4PFGAKSPjJqxJj29N51HHpBgWuBJBYCxGcd4=; h=Date:From:To:cc:Subject:From; b=uUf2rLvXuQ4EeK4M3x9d8DFpBY8tiB1S5ZHaSUoDX7hhHpe35qj2pM9yfpJRLIpGH JcUXKCpEPlw1hGVf5bnuM3RzyfPM9k39dZ/scLdsvEIUCXhNhfjiUsYIbz7fZv0JBy GzTDna79TRCIgVndAM4/vn2ZQzi8exGIOpuTOP025Dv8ND0KjaWEGKMMDTg5gCOLy+ RjztMKkJjyAaHrAUm4njW85UlpePWiRC1qXcmmFsbqAaLoCGkDqfY41bY2ZfInpIJH 8DLAdawnRDUH8xx2YNSZ7eQE9dF45k9DdBbD9TZIksBjv9YFhaq8g8NRJ8bxzSPNds 9jEJbiGrgMYMw== Date: Tue, 13 Jan 2026 16:39:57 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: xen-devel@lists.xenproject.org cc: jbeulich@suse.com, Stefano Stabellini , grygorii_strashko@epam.com, Anthony PERARD , Michal Orzel , Julien Grall , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Jason Andryuk , Victor Lira , andrew.cooper3@citrix.com Subject: [PATCH v3] xen/console: handle multiple domains using console_io hypercalls Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1768351228061158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow multiple dom0less domains to use the console_io hypercalls to print to the console. Handle them in a similar way to vpl011: only the domain which has focus can read from the console. All domains can write to the console but the ones without focus have a prefix. In this case the prefix is applied by using guest_printk instead of printk or console_puts which is what the original code was already doing. When switching focus using Ctrl-AAA, discard any unread data in the input buffer. Input is read quickly and the user would be aware of it being slow or stuck as they use Ctrl-AAA to switch focus domain. In that situation, it is to be expected that the unread input is lost. The domain writes are buffered when the domain is not in focus. Push out the buffer when the domain enters focus. Add the console_lock around serial_rx_cons modifications to protect it against concurrent writes to it. Signed-off-by: Stefano Stabellini --- Changes in v3: - move serial_rx_cons before printk - call console_put_domain earlier on CONSOLEIO_read - take console_lock earlier - add console_lock around serial_rx_cons modifications Changes in v2: - fix code style - pbuf_idx/idx after ada53067083e - don't add extra \0 - clear input on console switch --- xen/drivers/char/console.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 2bdb4d5fb4..58c32f22ef 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -577,6 +577,10 @@ static void console_switch_input(void) =20 console_rx =3D next_rx; printk("*** Serial input to DOM%u", domid); + /* Don't let the next dom read the previous dom's unread data.= */ + nrspin_lock_irq(&console_lock); + serial_rx_cons =3D serial_rx_prod; + nrspin_unlock_irq(&console_lock); break; } } @@ -730,6 +734,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(= char) buffer, unsigned int flags =3D opt_console_to_ring ? CONSOLE_ALL : CONSOLE_DEFAULT; struct domain *cd =3D current->domain; + struct domain *input; =20 while ( count > 0 ) { @@ -742,18 +747,28 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARA= M(char) buffer, if ( copy_from_guest(kbuf, buffer, kcount) ) return -EFAULT; =20 - if ( is_hardware_domain(cd) ) + input =3D console_get_domain(); + if ( input && cd =3D=3D input ) { - /* Use direct console output as it could be interactive */ + struct domain_console *cons =3D cd->console; + nrspin_lock_irq(&console_lock); + if ( cons->idx ) + { + console_send(cons->buf, cons->idx, flags); + cons->idx =3D 0; + } + /* Use direct console output as it could be interactive */ console_send(kbuf, kcount, flags); nrspin_unlock_irq(&console_lock); + console_put_domain(input); } else { char *kin =3D kbuf, *kout =3D kbuf, c; struct domain_console *cons =3D cd->console; =20 + console_put_domain(input); /* Strip non-printable characters */ do { @@ -795,6 +810,7 @@ long do_console_io( { long rc; unsigned int idx, len; + struct domain *d; =20 rc =3D xsm_console_io(XSM_OTHER, current->domain, cmd); if ( rc ) @@ -815,6 +831,11 @@ long do_console_io( if ( count > INT_MAX ) break; =20 + d =3D console_get_domain(); + console_put_domain(d); + if ( d !=3D current->domain ) + return 0; + rc =3D 0; while ( (serial_rx_cons !=3D serial_rx_prod) && (rc < count) ) { @@ -830,7 +851,10 @@ long do_console_io( break; } rc +=3D len; - serial_rx_cons +=3D len; + nrspin_lock_irq(&console_lock); + if ( serial_rx_cons !=3D serial_rx_prod ) + serial_rx_cons +=3D len; + nrspin_unlock_irq(&console_lock); } break; default: --=20 2.25.1