From nobody Mon Feb 9 01:26:58 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1770255406; cv=none; d=zohomail.com; s=zohoarc; b=SO8m/4bU8OOtiPWQafhkp+G9EqtUn4nDgXYFvBUzgw6JRdKL+Q09e6HG+59c+ZZPHWGLoywwSbuV+Gbv07cr3GYwoZ5KVzV1fCICB5mpobxVO70f23eMawD/5c+n0HXxnSxrqp1pdLInvcxgkzbpr0XG59yMaWGfsvYh60gs5Ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770255406; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2hWVAX5cInV9+JHNZ4ERQlXamvda79ZLFDIRyBNBnyg=; b=EVHelOK+JsTazxeZQlyXcTLJeU8cGCeg94fZtwIf6veziKi12HWi27JAp/Bs3sYHi4XdMNvADEcpJXsREU5RqrujPlFUchxsrqTA1ivB84njBFLJMtv/pTkhG2FWajVU2U34YOZ6x+R0jfF48falGrnOgbQNUdR0aUQYvCDz3mw= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1770255406065867.9990728919665; Wed, 4 Feb 2026 17:36:46 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1221351.1529617 (Exim 4.92) (envelope-from ) id 1vnoI4-0001vS-Bz; Thu, 05 Feb 2026 01:36:16 +0000 Received: by outflank-mailman (output) from mailman id 1221351.1529617; Thu, 05 Feb 2026 01:36:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vnoI4-0001uv-9R; Thu, 05 Feb 2026 01:36:16 +0000 Received: by outflank-mailman (input) for mailman id 1221351; Thu, 05 Feb 2026 01:36:15 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vnoI3-0001iz-6Q for xen-devel@lists.xenproject.org; Thu, 05 Feb 2026 01:36:15 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1vnoI3-003wQC-0N; Thu, 05 Feb 2026 01:36:14 +0000 Received: from [140.209.201.102] (helo=localhost) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vnoI2-00HVX2-1u; Thu, 05 Feb 2026 01:36:14 +0000 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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From; bh=2hWVAX5cInV9+JHNZ4ERQlXamvda79ZLFDIRyBNBnyg=; b=WxbR2H+NO/hx9lVr0ieB68MZO1 bdXxPrxCmpFVs8mf4ofpC35FMRpfjksgu01WDUKkJthpYm2MMtecQxX14e0A8s87rZ1PPnBuABYjP Sf88iq0ZzaRvu22v4l9Gv6AoVZeNhiutYr8GNdwIEziqNFonoF+wX7ThC5dXjiSEkLJQ=; From: dmukhin@xen.org To: xen-devel@lists.xenproject.org Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org, dmukhin@ford.com Subject: [PATCH v5 1/6] xen/console: group conring code together Date: Wed, 4 Feb 2026 17:36:01 -0800 Message-ID: <20260205013606.3384798-2-dmukhin@ford.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260205013606.3384798-1-dmukhin@ford.com> References: <20260205013606.3384798-1-dmukhin@ford.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1770255407917158500 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin =20 Groups conring buffer management code in the console driver for ease of maintaining this code. Not a functional change. Signed-off-by: Denis Mukhin --- Changes since v4: - new patch --- xen/drivers/char/console.c | 161 ++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 81 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 2bdb4d5fb417..86319600e0af 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -126,17 +126,6 @@ static int cf_check parse_console_timestamps(const cha= r *s); custom_runtime_param("console_timestamps", parse_console_timestamps, con_timestamp_mode_upd); =20 -/* conring_size: allows a large console ring than default (16kB). */ -static uint32_t __initdata opt_conring_size; -size_param("conring_size", opt_conring_size); - -#define _CONRING_SIZE 16384 -#define CONRING_IDX_MASK(i) ((i)&(conring_size-1)) -static char __initdata _conring[_CONRING_SIZE]; -static char *__read_mostly conring =3D _conring; -static uint32_t __read_mostly conring_size =3D _CONRING_SIZE; -static uint32_t conringc, conringp; - static int __read_mostly sercon_handle =3D -1; =20 #ifdef CONFIG_X86 @@ -350,6 +339,17 @@ static void cf_check do_dec_thresh(unsigned char key, = bool unused) * ******************************************************** */ =20 +/* conring_size: allows a large console ring than default (16kB). */ +static uint32_t __initdata opt_conring_size; +size_param("conring_size", opt_conring_size); + +#define _CONRING_SIZE 16384 +#define CONRING_IDX_MASK(i) ((i)&(conring_size-1)) +static char __initdata _conring[_CONRING_SIZE]; +static char *__read_mostly conring =3D _conring; +static uint32_t __read_mostly conring_size =3D _CONRING_SIZE; +static uint32_t conringc, conringp; + static void cf_check conring_notify(void *unused) { send_global_virq(VIRQ_CON_RING); @@ -416,47 +416,6 @@ long read_console_ring(struct xen_sysctl_readconsole *= op) } #endif /* CONFIG_SYSCTL */ =20 - -/* - * ******************************************************* - * *************** ACCESS TO SERIAL LINE ***************** - * ******************************************************* - */ - -/* Characters received over the serial line are buffered for domain 0. */ -#define SERIAL_RX_SIZE 128 -#define SERIAL_RX_MASK(_i) ((_i)&(SERIAL_RX_SIZE-1)) -static char serial_rx_ring[SERIAL_RX_SIZE]; -static unsigned int serial_rx_cons, serial_rx_prod; - -static void (*serial_steal_fn)(const char *str, size_t nr) =3D early_puts; - -int console_steal(int handle, void (*fn)(const char *str, size_t nr)) -{ - if ( (handle =3D=3D -1) || (handle !=3D sercon_handle) ) - return 0; - - if ( serial_steal_fn !=3D NULL ) - return -EBUSY; - - serial_steal_fn =3D fn; - return 1; -} - -void console_giveback(int id) -{ - if ( id =3D=3D 1 ) - serial_steal_fn =3D NULL; -} - -void console_serial_puts(const char *s, size_t nr) -{ - if ( serial_steal_fn !=3D NULL ) - serial_steal_fn(s, nr); - else - serial_puts(sercon_handle, s, nr); -} - /* * Flush contents of the conring to the selected console devices. */ @@ -501,6 +460,75 @@ static void cf_check conring_dump_keyhandler(unsigned = char key) printk("failed to dump console ring buffer: %d\n", rc); } =20 +void __init console_init_ring(void) +{ + char *ring; + unsigned int i, order, memflags; + unsigned long flags; + + if ( !opt_conring_size ) + return; + + order =3D get_order_from_bytes(max(opt_conring_size, conring_size)); + memflags =3D MEMF_bits(crashinfo_maxaddr_bits); + while ( (ring =3D alloc_xenheap_pages(order, memflags)) =3D=3D NULL ) + { + BUG_ON(order =3D=3D 0); + order--; + } + opt_conring_size =3D PAGE_SIZE << order; + + nrspin_lock_irqsave(&console_lock, flags); + for ( i =3D conringc ; i !=3D conringp; i++ ) + ring[i & (opt_conring_size - 1)] =3D conring[i & (conring_size - 1= )]; + conring =3D ring; + smp_wmb(); /* Allow users of console_force_unlock() to see larger buff= er. */ + conring_size =3D opt_conring_size; + nrspin_unlock_irqrestore(&console_lock, flags); + + printk("Allocated console ring of %u KiB.\n", opt_conring_size >> 10); +} + +/* + * ******************************************************* + * *************** ACCESS TO SERIAL LINE ***************** + * ******************************************************* + */ + +/* Characters received over the serial line are buffered for domain 0. */ +#define SERIAL_RX_SIZE 128 +#define SERIAL_RX_MASK(_i) ((_i)&(SERIAL_RX_SIZE-1)) +static char serial_rx_ring[SERIAL_RX_SIZE]; +static unsigned int serial_rx_cons, serial_rx_prod; + +static void (*serial_steal_fn)(const char *str, size_t nr) =3D early_puts; + +int console_steal(int handle, void (*fn)(const char *str, size_t nr)) +{ + if ( (handle =3D=3D -1) || (handle !=3D sercon_handle) ) + return 0; + + if ( serial_steal_fn !=3D NULL ) + return -EBUSY; + + serial_steal_fn =3D fn; + return 1; +} + +void console_giveback(int id) +{ + if ( id =3D=3D 1 ) + serial_steal_fn =3D NULL; +} + +void console_serial_puts(const char *s, size_t nr) +{ + if ( serial_steal_fn !=3D NULL ) + serial_steal_fn(s, nr); + else + serial_puts(sercon_handle, s, nr); +} + /* * CTRL- changes input direction, rotating among Xen, Dom0, * and the DomUs started from Xen at boot. @@ -1125,35 +1153,6 @@ void __init console_init_preirq(void) } } =20 -void __init console_init_ring(void) -{ - char *ring; - unsigned int i, order, memflags; - unsigned long flags; - - if ( !opt_conring_size ) - return; - - order =3D get_order_from_bytes(max(opt_conring_size, conring_size)); - memflags =3D MEMF_bits(crashinfo_maxaddr_bits); - while ( (ring =3D alloc_xenheap_pages(order, memflags)) =3D=3D NULL ) - { - BUG_ON(order =3D=3D 0); - order--; - } - opt_conring_size =3D PAGE_SIZE << order; - - nrspin_lock_irqsave(&console_lock, flags); - for ( i =3D conringc ; i !=3D conringp; i++ ) - ring[i & (opt_conring_size - 1)] =3D conring[i & (conring_size - 1= )]; - conring =3D ring; - smp_wmb(); /* Allow users of console_force_unlock() to see larger buff= er. */ - conring_size =3D opt_conring_size; - nrspin_unlock_irqrestore(&console_lock, flags); - - printk("Allocated console ring of %u KiB.\n", opt_conring_size >> 10); -} - void __init console_init_irq(void) { serial_init_irq(); --=20 2.52.0