From nobody Tue Feb 10 11:16:59 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; 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 1658805841853173.3244960555902; Mon, 25 Jul 2022 20:24:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.374938.607187 (Exim 4.92) (envelope-from ) id 1oGBAX-0004Hp-5P; Tue, 26 Jul 2022 03:23:37 +0000 Received: by outflank-mailman (output) from mailman id 374938.607187; Tue, 26 Jul 2022 03:23:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oGBAW-0004Fq-TN; Tue, 26 Jul 2022 03:23:36 +0000 Received: by outflank-mailman (input) for mailman id 374938; Tue, 26 Jul 2022 03:23:36 +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 1oGBAW-000459-BF for xen-devel@lists.xenproject.org; Tue, 26 Jul 2022 03:23:36 +0000 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 54a90892-0c92-11ed-924f-1f966e50362f; Tue, 26 Jul 2022 05:23:34 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 38A6F5C00C4; Mon, 25 Jul 2022 23:23:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 25 Jul 2022 23:23:34 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 25 Jul 2022 23:23:32 -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: 54a90892-0c92-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1658805814; x=1658892214; bh=hSsEZHy6kJ LcmqWZuPa/umq2lr+G/hdZU1gW2QDjIRI=; b=hIFn0DIgOSL3dauKE5PXTJegSt GlpZO47OaT7GxSTdX0cGtkv2FrVfxKey4WVaAAOY4bGZ39yt4fH1TLVjRkKXNnCx XoMAhkufI4fVrw6vdwug8YOoWm/cuVdKLHtN1iHHqW9MHr6t8CeRYH9nVoMfd6s8 V7TiIS8GepYCkUUQLA+voybRNnIBcAQuy46XpPh9UA4HsJjmeJpiT8eu10PO+FeP 6n9OtNVi2N3FcgY42baDW0rWAXngKInIF2Z/eJDpnRQS9azDFC7z2L5DaQNFyIa/ sRqHJWx7RiqKZt8tJdUY7lSm8ujXgzZJMf2mocgzZLZAImRoKDUkFN5+r9+g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1658805814; x= 1658892214; bh=hSsEZHy6kJLcmqWZuPa/umq2lr+G/hdZU1gW2QDjIRI=; b=O rxHoquYpjEzNSsjsYn2n1ZBx9j6TSD60CNrjkV9STnEzNXC98XoDNZHvyNmO2TB2 +dQWEg57TvAtL4ughDcqq3R/EOnK8ZNSPZcV9l42T5bbl9kpx9PjuiS9CDn8fbzE u+NDcA2nZgoWJOAhf6+oZL2T0n4FeGx9rfK1ULygvPrOUPOF9P39D2/zYNuaA0W1 FfdtVDSYDZ/+rf2OzEkLaXRp3k/aXN5xyGuLY/2UcqBgxjZs1neE0lTlWBMP1VBm FoP1zBXGihE5b0mKtbAii0zaNXzcUXw4Ob01p0q3xzvhyVtN/pxGIhn4tDZhjFD6 MRDRbGGY5Pmgpf3C3o2Nw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvddtledgieelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpeforghr vghkucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesih hnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpefg ueduhefgvdefheehudejheefudevueeghfekhfehleegveduteeuiedugffgffenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrghrmhgrrhgv khesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhm 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 , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v3 04/10] console: support multiple serial console simultaneously Date: Tue, 26 Jul 2022 05:23:09 +0200 Message-Id: <14411aa674b61d22d9626a3455206454793b6a37.1658804819.git-series.marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1658805843199100011 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 --- 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 | 97 ++++++++++++++++++++++++-------- xen/drivers/char/xhci-dbc.c | 6 +- xen/include/xen/serial.h | 1 +- 5 files changed, 95 insertions(+), 24 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index d594bd5c7436..e53efdb324b3 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -433,6 +433,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 @@ -2372,6 +2375,7 @@ vulnerabilities. =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 06350c387371..1010436d245c 100644 --- a/xen/drivers/char/Kconfig +++ b/xen/drivers/char/Kconfig @@ -85,6 +85,17 @@ config SERIAL_TX_BUFSIZE =20 Default value is 16384 (16kiB). =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= more + using `console=3D` parameter will be ignored. + When multiple consoles are configured, overhead of `sync_console` op= tion + 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 f9937c5134c0..2ffc919445c6 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -113,7 +113,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 int __read_mostly nr_sercon_handle =3D 0; =20 #ifdef CONFIG_X86 /* Tristate: 0 disabled, 1 user enabled, -1 default enabled */ @@ -393,32 +395,59 @@ 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 *, size_t nr) =3D early_puts; +/* The last entry means "steal from all consoles" */ +static void (*serial_steal_fn[MAX_SERCONS+1])(const char *, 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 *, size_t nr)) { - if ( (handle =3D=3D -1) || (handle !=3D sercon_handle) ) - return 0; + 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); + 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 /* Copy all serial output into PV console */ pv_console_puts(s, nr); @@ -956,7 +985,7 @@ void guest_printk(const struct domain *d, const char *f= mt, ...) void __init console_init_preirq(void) { char *p; - int sh; + int sh, i; =20 serial_init_preirq(); =20 @@ -977,8 +1006,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 { @@ -996,7 +1029,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 /* HELLO WORLD --- start-of-day banner text. */ @@ -1014,7 +1048,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); @@ -1121,13 +1156,19 @@ int __init console_has(const char *device) =20 void console_start_log_everything(void) { - serial_start_log_everything(sercon_handle); + 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); + int i; + + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_end_log_everything(sercon_handle[i]); atomic_dec(&print_everything); } =20 @@ -1149,23 +1190,32 @@ void console_unlock_recursive_irqrestore(unsigned l= ong flags) =20 void console_force_unlock(void) { + int i; + watchdog_disable(); spin_debug_disable(); spin_lock_init(&console_lock); - serial_force_unlock(sercon_handle); + for ( i =3D 0 ; i < nr_sercon_handle ; i++ ) + serial_force_unlock(sercon_handle[i]); console_locks_busted =3D 1; console_start_sync(); } =20 void console_start_sync(void) { + 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); + int i; + + for ( i =3D 0; i < nr_sercon_handle; i++ ) + serial_end_sync(sercon_handle[i]); atomic_dec(&print_everything); } =20 @@ -1291,7 +1341,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/drivers/char/xhci-dbc.c b/xen/drivers/char/xhci-dbc.c index 11026d3b71f0..14a2d3eb0ee2 100644 --- a/xen/drivers/char/xhci-dbc.c +++ b/xen/drivers/char/xhci-dbc.c @@ -1078,8 +1078,12 @@ void __init xhci_dbc_uart_init(void) =20 e =3D parse_pci(opt_dbgp + 8, NULL, &bus, &slot, &func); if ( !e || *e ) + { + printk(XENLOG_ERR + "Invalid dbgp=3D PCI device spec: '%s'\n", + opt_dbgp); return; - + } dbc->sbdf =3D PCI_SBDF(0, bus, slot, func); } =20 diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h index 181e026967bc..c3bca000e238 100644 --- a/xen/include/xen/serial.h +++ b/xen/include/xen/serial.h @@ -99,6 +99,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