From nobody Fri Oct 31 16:26:38 2025 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; 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=fail(p=none dis=none) header.from=invisiblethingslab.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1748182852217491.64772725285025; Sun, 25 May 2025 07:20:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.997158.1378170 (Exim 4.92) (envelope-from ) id 1uJCDC-00072W-Vq; Sun, 25 May 2025 14:20:26 +0000 Received: by outflank-mailman (output) from mailman id 997158.1378170; Sun, 25 May 2025 14:20:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCDC-00072F-SO; Sun, 25 May 2025 14:20:26 +0000 Received: by outflank-mailman (input) for mailman id 997158; Sun, 25 May 2025 14:20:24 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJCDA-0006Ah-Os for xen-devel@lists.xenproject.org; Sun, 25 May 2025 14:20:24 +0000 Received: from fhigh-b6-smtp.messagingengine.com (fhigh-b6-smtp.messagingengine.com [202.12.124.157]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 638175e0-3973-11f0-b893-0df219b8e170; Sun, 25 May 2025 16:20:20 +0200 (CEST) Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id B9CF425400CA; Sun, 25 May 2025 10:20:19 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Sun, 25 May 2025 10:20:19 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 25 May 2025 10:20:17 -0400 (EDT) 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: 638175e0-3973-11f0-b893-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1748182819; x=1748269219; bh=8N0UZzKt4D QbodDXdvRtwVlKHw5NKvan8QfhJwtoCk8=; b=BhL1n/QeRiZ5LIM3pw/lE4MNPI jnNyVsgCW6EOTbt2MYUlrmmicZ0DHbaaY66u0Tn3MULNqBXJQ7ZdxerNg4aoFKto 7AVB++4Ow+EemU1aLbdkOXf90Zm9A2ONnf2HrrtKe/wwNPr5ruBFtbpTzMVG9xBW AL2GLp319pmzi+eqYbDN6kXnMYYDoSSp31gtGfdJCvoH3UA+sVArHJuDBm7Cnffg 1NKQHXOUPdgv0xI1EjoTslHWNuyKr6lXNlkNd7HNgHVlJ+GE3ps3FkdsVOEAap0A VQQLRT6ZyLJbUgOTfZOhZbP7IjZvcoVnBVQnS062uUHVl46niQ2qL7r71wgQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1748182819; x= 1748269219; bh=8N0UZzKt4DQbodDXdvRtwVlKHw5NKvan8QfhJwtoCk8=; b=U J6bOiBqrsmflyAGrQZRClJtBba3espjZkLKDVsCaIB8dyAhfwDIAyqZVTidk47dV XwHNuU3Ych4r/eXVYN9e7Z+/GyPgAeh/HvIHIiNTrwvli+uIu/YfWEqpA8S3FWXa W1JjiawMc6IJj6NxOWbaRn6mh91IqZCrCgHcjK/tC4pObbxyjKRwhIsqUSJakS/q M+lklnhY6RTixkKJ1ddubGMVO67JYgGPFCBEbBQI66I5RghW6JL9oC2bW/c/KQ+J yGr1g47hL2hLsbCyWjVu6J949DJER4yrQavgKkYL9p5Z2IDn3Up0270ej9Nr7FWU 0Uovp1mdjiPYRHICDMQiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgddugeekfeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffo jghfgggtgfesthekredtredtjeenucfhrhhomhepofgrrhgvkhcuofgrrhgtiiihkhhofi hskhhiqdfikphrvggtkhhiuceomhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhn ghhslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepffeitdegveffteelvdeghffhve fghfefkeelheeujeejgedvvdfgffejuedtvdelnecuffhomhgrihhnpehkvghrnhgvlhdr ohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hmrghrmhgrrhgvkhesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmpdhnsggp rhgtphhtthhopeelpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeigvghnqdguvg hvvghlsehlihhsthhsrdigvghnphhrohhjvggtthdrohhrghdprhgtphhtthhopehmrghr mhgrrhgvkhesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmpdhrtghpthhtoh eprghnughrvgifrdgtohhophgvrhefsegtihhtrhhigidrtghomhdprhgtphhtthhopegr nhhthhhonhihrdhpvghrrghrugesvhgrthgvshdrthgvtghhpdhrtghpthhtohepmhhitg hhrghlrdhorhiivghlsegrmhgurdgtohhmpdhrtghpthhtohepjhgsvghulhhitghhsehs uhhsvgdrtghomhdprhgtphhtthhopehjuhhlihgvnhesgigvnhdrohhrghdprhgtphhtth hopehrohhgvghrrdhprghusegtihhtrhhigidrtghomhdprhgtphhtthhopehsshhtrggs vghllhhinhhisehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i1568416f:Fastmail From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v1 5/5] console: support multiple serial console simultaneously Date: Sun, 25 May 2025 16:15:46 +0200 Message-ID: <98ff383ff2ee3dc162b2d12afaea2b3f1406d99e.1748182535.git-series.marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1748182853671116600 Previously only one serial console was supported at the same time. Using console=3Dcom1,dbgp,vga silently ignored all but last serial console (in this case: only dbgp and vga were active). Fix this by storing not a single sercon_handle, but an array of them, up to MAX_SERCONS entries. The value of MAX_SERCONS can be chosen in kconfig, the default (4) is arbitrary, inspired by the number of SERHND_IDX values. Make console_steal() aware of multiple consoles too. It can now either steal output from specific console (for gdbstub), or from all of them at once (for console suspend). Signed-off-by: Marek Marczykowski-G=C3=B3recki --- This was posted before as part of initial xhci console submission, it reached v6 (but last changes were in v4), but wasn't considered useful enough to review/ack: https://lore.kernel.org/xen-devel/Yu0XHUhsebE+WG0g@mail-itl/ Since I needed this feature again, to debug xhci console issue, I'm including this patch again in the series. Changes in v4: - use unsigned int for loop counters - other minor changes Changes in v3: - adjust console_steal() for multiple consoles too - add MAX_SERCONS to kconfig - add warning about sync_console impact - add warning if too many consoles are configured - log issue with PCI spec parsing --- docs/misc/xen-command-line.pandoc | 4 +- xen/drivers/char/Kconfig | 11 ++++- xen/drivers/char/console.c | 98 ++++++++++++++++++++++++-------- xen/include/xen/serial.h | 1 +- 4 files changed, 92 insertions(+), 22 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index b0eadd2c5d58..052c01f87bfc 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -456,6 +456,9 @@ only available when used together with `pv-in-pvh`. `none` indicates that Xen should not use a console. This option only makes sense on its own. =20 +Specifying more than one serial console will increase console latency, +especially when `sync_console` option is used. + ### console_timestamps > `=3D none | date | datems | boot | raw` =20 @@ -2637,6 +2640,7 @@ Intel SA-00982. Intel suggest that some workloads wi= ll benefit from this. =20 Flag to force synchronous console output. Useful for debugging, but not suitable for production environments due to incurred overhead. +If multiple consoles are configured, the incurred overhead is even bigger. =20 ### tboot (x86) > `=3D 0x` diff --git a/xen/drivers/char/Kconfig b/xen/drivers/char/Kconfig index e6e12bb41397..76305fcb4afa 100644 --- a/xen/drivers/char/Kconfig +++ b/xen/drivers/char/Kconfig @@ -96,6 +96,17 @@ config SERIAL_TX_BUFSIZE =20 Default value is 32768 (32KiB). =20 +config MAX_SERCONS + int "Maximum number of serial consoles active at once" + default 4 + help + Controls how many serial consoles can be active at once. Configuring mo= re + using `console=3D` parameter will be ignored. + When multiple consoles are configured, overhead of `sync_console` option + is even bigger. + + Default value is 4. + config XHCI bool "XHCI DbC UART driver" depends on X86 diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 12898b684b5e..e306986bfcbc 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -134,7 +134,9 @@ static char *__read_mostly conring =3D _conring; static uint32_t __read_mostly conring_size =3D _CONRING_SIZE; static uint32_t conringc, conringp; =20 -static int __read_mostly sercon_handle =3D -1; +#define MAX_SERCONS CONFIG_MAX_SERCONS +static int __read_mostly sercon_handle[MAX_SERCONS]; +static unsigned int __read_mostly nr_sercon_handle =3D 0; =20 #ifdef CONFIG_X86 /* Tristate: 0 disabled, 1 user enabled, -1 default enabled */ @@ -424,32 +426,61 @@ long read_console_ring(struct xen_sysctl_readconsole = *op) static char serial_rx_ring[SERIAL_RX_SIZE]; static unsigned int serial_rx_cons, serial_rx_prod; =20 -static void (*serial_steal_fn)(const char *str, size_t nr) =3D early_puts; +/* The last entry means "steal from all consoles" */ +static void (*serial_steal_fn[])(const char *str, size_t nr) =3D { + [MAX_SERCONS] =3D early_puts, +}; =20 +/* + * Redirect console *handle* output to *fn*. Use SERHND_STEAL_ALL as *hand= le* to + * redirect all the consoles.=20 + */ int console_steal(int handle, void (*fn)(const char *str, size_t nr)) { - if ( (handle =3D=3D -1) || (handle !=3D sercon_handle) ) - return 0; + unsigned int i; + + if ( handle =3D=3D -1 ) + return -ENOENT; + if ( serial_steal_fn[MAX_SERCONS] !=3D NULL ) + return -EBUSY; + if ( handle =3D=3D SERHND_STEAL_ALL ) + { + serial_steal_fn[MAX_SERCONS] =3D fn; + return MAX_SERCONS; + } + for ( i =3D 0; i < nr_sercon_handle; i++ ) + if ( handle =3D=3D sercon_handle[i] ) + break; + if ( i =3D=3D nr_sercon_handle ) + return -ENOENT; =20 - if ( serial_steal_fn !=3D NULL ) + if ( serial_steal_fn[i] !=3D NULL ) return -EBUSY; =20 - serial_steal_fn =3D fn; - return 1; + serial_steal_fn[i] =3D fn; + return i; } =20 void console_giveback(int id) { - if ( id =3D=3D 1 ) - serial_steal_fn =3D NULL; + if ( id >=3D 0 && id <=3D MAX_SERCONS ) + serial_steal_fn[id] =3D NULL; } =20 void console_serial_puts(const char *s, size_t nr) { - if ( serial_steal_fn !=3D NULL ) - serial_steal_fn(s, nr); + unsigned int i; + + if ( serial_steal_fn[MAX_SERCONS] !=3D NULL ) + serial_steal_fn[MAX_SERCONS](s, nr); else - serial_puts(sercon_handle, s, nr); + for ( i =3D 0; i < nr_sercon_handle; i++ ) + { + if ( serial_steal_fn[i] !=3D NULL ) + serial_steal_fn[i](s, nr); + else + serial_puts(sercon_handle[i], s, nr); + } } =20 /* @@ -1026,6 +1057,7 @@ void __init console_init_preirq(void) { char *p; int sh; + unsigned int i; =20 serial_init_preirq(); =20 @@ -1046,8 +1078,12 @@ void __init console_init_preirq(void) continue; else if ( (sh =3D serial_parse_handle(p)) >=3D 0 ) { - sercon_handle =3D sh; - serial_steal_fn =3D NULL; + if ( nr_sercon_handle < MAX_SERCONS ) + sercon_handle[nr_sercon_handle++] =3D sh; + else + printk("Too many consoles (max %d), ignoring '%s'\n", + MAX_SERCONS, p); + serial_steal_fn[MAX_SERCONS] =3D NULL; } else { @@ -1065,7 +1101,8 @@ void __init console_init_preirq(void) opt_console_xen =3D 0; #endif =20 - serial_set_rx_handler(sercon_handle, serial_rx); + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_set_rx_handler(sercon_handle[i], serial_rx); pv_console_set_rx_handler(serial_rx); =20 /* NB: send conring contents to all enabled physical consoles, if any = */ @@ -1084,7 +1121,8 @@ void __init console_init_preirq(void) =20 if ( opt_sync_console ) { - serial_start_sync(sercon_handle); + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_start_sync(sercon_handle[i]); add_taint(TAINT_SYNC_CONSOLE); printk("Console output is synchronous.\n"); warning_add(warning_sync_console); @@ -1201,13 +1239,19 @@ int __init console_has(const char *device) =20 void console_start_log_everything(void) { - serial_start_log_everything(sercon_handle); + unsigned int i; + + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_start_log_everything(sercon_handle[i]); atomic_inc(&print_everything); } =20 void console_end_log_everything(void) { - serial_end_log_everything(sercon_handle); + unsigned int i; + + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_end_log_everything(sercon_handle[i]); atomic_dec(&print_everything); } =20 @@ -1223,23 +1267,32 @@ void console_unlock_recursive_irqrestore(unsigned l= ong flags) =20 void console_force_unlock(void) { + unsigned int i; + watchdog_disable(); spin_debug_disable(); rspin_lock_init(&console_lock); - serial_force_unlock(sercon_handle); + for ( i =3D 0 ; i < nr_sercon_handle ; i++ ) + serial_force_unlock(sercon_handle[i]); conring_no_notify =3D true; console_start_sync(); } =20 void console_start_sync(void) { + unsigned int i; + atomic_inc(&print_everything); - serial_start_sync(sercon_handle); + for ( i =3D 0 ; i < nr_sercon_handle ; i++ ) + serial_start_sync(sercon_handle[i]); } =20 void console_end_sync(void) { - serial_end_sync(sercon_handle); + unsigned int i; + + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_end_sync(sercon_handle[i]); atomic_dec(&print_everything); } =20 @@ -1362,7 +1415,8 @@ static int suspend_steal_id; =20 int console_suspend(void) { - suspend_steal_id =3D console_steal(sercon_handle, suspend_steal_fn); + if ( nr_sercon_handle ) + suspend_steal_id =3D console_steal(SERHND_STEAL_ALL, suspend_steal= _fn); serial_suspend(); return 0; } diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h index 1ee3df2624fb..31159814d883 100644 --- a/xen/include/xen/serial.h +++ b/xen/include/xen/serial.h @@ -101,6 +101,7 @@ struct uart_driver { #define SERHND_HI (1<<2) /* Mux/demux each transferred char by MSB. = */ #define SERHND_LO (1<<3) /* Ditto, except that the MSB is cleared. = */ #define SERHND_COOKED (1<<4) /* Newline/carriage-return translation? = */ +#define SERHND_STEAL_ALL 0xff /* Synthetic handle used in console_steal()= */ =20 /* Three-stage initialisation (before/during/after IRQ-subsystem setup). */ void serial_init_preirq(void); --=20 git-series 0.9.1