xen/console: configurable conring size
v7 cover xen/console: configurable conring size
Series introduces compile-time configurable conring size along with few cleanups in conring management.
Patch 1 updates conring{,_size} annotations to __ro_after_init as per [1].
Patch 2 optimizes switch from early conring to permanent conring.
Patch 3 optimizes code in conring_puts().
Patch 4 updates the conring buffer allocation code.
Patch 5,6 updates for the command line options for the serial driver.
Patch 7 introduces CONRING_CONRING_SHIFT to select compile-time conring buffer size.
[1] https://lore.kernel.org/xen-devel/[email protected]
[2] Link to v6: https://lore.kernel.org/xen-devel/[email protected]/
[3] Link to CI: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/2673235063
Denis Mukhin (7):
xen/console: promote conring{,_size} to __ro_after_init xen/console: use memcpy() in console_init_ring() xen/console: use memcpy() in conring_puts() xen/console: switch conring runtime allocation to xvmalloc xen/serial: drop stale SERIAL_NEVER_DROP_CHARS xen/serial: harden serial_tx_buffer checks xen/console: make console buffer size configurable
docs/misc/xen-command-line.pandoc | 10 ++++- xen/drivers/char/Kconfig | 21 +++++++++ xen/drivers/char/console.c | 71 ++++++++++++++++++++++--------- xen/drivers/char/serial.c | 24 +++++++++-- 4 files changed, 99 insertions(+), 27 deletions(-)
Signature · 1 line
2.54.0
PATCH v7 1/7 xen/console: promote conring{,_size} to __ro_after_init
From: Denis Mukhin <[email protected]>
Both conring{,_size} should be RO after initialization is completed.
Change the conring integer parameters type to unsigned int as required by CODING_STYLE.
---
Changes since v6:
- rebased
--- xen/drivers/char/console.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
xen/drivers/char/console.c +4 -4
@@ -340,15 +340,15 @@ static void cf_check do_dec_thresh(unsigned char key, bool unused)*/ /* conring_size: allows a larger console ring than default (16kB). */ -static uint32_t __initdata opt_conring_size; +static unsigned int __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 = _conring; -static uint32_t __read_mostly conring_size = _CONRING_SIZE; -static uint32_t conringc, conringp; +static char *__ro_after_init conring = _conring; +static unsigned int __ro_after_init conring_size = _CONRING_SIZE; +static unsigned int conringc, conringp; static void cf_check conring_notify(void *unused) {
Signature · 1 line
2.54.0
Re: [PATCH v7 1/7] xen/console: promote conring{,_size} to __ro_after_init
Quoted 4 lines · On 13.07.2026 20:16, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Both conring{,_size} should be RO after initialization is completed.
Quoted 8 lines
Change the conring integer parameters type to
unsigned intas required byCODING_STYLE.Suggested-by Andrew Cooper <[email protected]>Signed-off-by Denis Mukhin <[email protected]>---
Changes since v6:
- rebased
With no changes, where did my A-b go (offered on v5 with the types adjusted)?
Jan
Re: [PATCH v7 1/7] xen/console: promote conring{,_size} to __ro_after_init
Quoted 8 lines · Jan Beulich
Quoted 7 lines · On 13.07.2026 20:16, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Both conring{,_size} should be RO after initialization is completed.
Change the conring integer parameters type to
unsigned intas required byCODING_STYLE.
Quoted 7 lines
Quoted 5 lines
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Denis Mukhin <[email protected]>---
Changes since v6:
- rebasedWith no changes, where did my A-b go (offered on v5 with the types adjusted)?
Will resend.
Re: [PATCH v7 1/7] xen/console: promote conring{,_size} to __ro_after_init
Quoted 15 lines · On 14.07.2026 14:30, [email protected] wrote:
Quoted 14 lines · Jan Beulich
Quoted 12 lines · On 13.07.2026 20:16, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Both conring{,_size} should be RO after initialization is completed.
Change the conring integer parameters type to
unsigned intas required byCODING_STYLE.Suggested-by Andrew Cooper <[email protected]>Signed-off-by Denis Mukhin <[email protected]>---
Changes since v6:
- rebased
Quoted 3 lines
Quoted 1 line
With no changes, where did my A-b go (offered on v5 with the types adjusted)?
Will resend.
Not just for this, please.
Jan
PATCH RESEND v7 1/7 xen/console: promote conring{,_size} to __ro_after_init
In reply to Jan BeulichFrom: Denis Mukhin <[email protected]>
Both conring{,_size} should be RO after initialization is completed.
Change the conring integer parameters type to unsigned int as required by CODING_STYLE.
---
Resending to include forgotten Jan's A-b from v5:
https://lore.kernel.org/xen-devel/[email protected]/
Changes since v6:
- rebased
- preserved Jan's A-b from v5
--- xen/drivers/char/console.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
xen/drivers/char/console.c +4 -4
@@ -340,15 +340,15 @@ static void cf_check do_dec_thresh(unsigned char key, bool unused)*/ /* conring_size: allows a larger console ring than default (16kB). */ -static uint32_t __initdata opt_conring_size; +static unsigned int __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 = _conring; -static uint32_t __read_mostly conring_size = _CONRING_SIZE; -static uint32_t conringc, conringp; +static char *__ro_after_init conring = _conring; +static unsigned int __ro_after_init conring_size = _CONRING_SIZE; +static unsigned int conringc, conringp; static void cf_check conring_notify(void *unused) {
Signature · 1 line
2.54.0
PATCH v7 2/7 xen/console: use memcpy() in console_init_ring()
In reply to [email protected]From: Denis Mukhin <[email protected]>
Make console_init_ring() more efficient by using memcpy()'s, rather than copying the ring a byte at a time.
No functional change intended.
---
Changes since v6:
- addressed Roger's feedback
- added Roger's A-b
--- xen/drivers/char/console.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
xen/drivers/char/console.c +15 -3
@@ -463,7 +463,8 @@ static void cf_check conring_dump_keyhandler(unsigned char key)void __init console_init_ring (void ) {char *ring; -unsigned int i, order, memflags; +XENCONS_RING_IDX done, size, n; +unsigned int order, memflags;unsigned long flags;if ( !opt_conring_size )
@@ -479,8 +480,19 @@ void __init console_init_ring(void) opt_conring_size =PAGE_SIZE << order;nrspin_lock_irqsave (&console_lock, flags); -for ( i = conringc ; i != conringp; i++ ) - ring[i & (opt_conring_size -1 )] = conring[i & (conring_size -1 )]; + + size = conringp - conringc; +for ( done =0 ; done < size; done += n ) + { +XENCONS_RING_IDX src = (conringc + done) & (conring_size -1 ); +XENCONS_RING_IDX dst = (conringc + done) & (opt_conring_size -1 ); + + n =min (opt_conring_size - dst, conring_size - src); + n =min (size - done, n); + +memcpy (&ring[dst], &conring[src], n); + } + conring = ring;smp_wmb ();/* Allow users of console_force_unlock() to see larger buffer. */ conring_size = opt_conring_size;
Signature · 1 line
2.54.0
Re: [PATCH v7 2/7] xen/console: use memcpy() in console_init_ring()
Quoted 34 lines · On 13/07/2026 7:16 pm, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Make
console_init_ring()more efficient by using memcpy()'s, rather than copying the ring a byte at a time.No functional change intended.
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Denis Mukhin <[email protected]>Acked-by Roger Pau Monne <[email protected]>---
Changes since v6:
- addressed Roger's feedback
- added Roger's A-b--- xen/drivers/char/console.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)xen/drivers/char/console.c +2
-1@@ -463,7 +463,8 @@ static void cf_check conring_dump_keyhandler(unsigned char key)void __init console_init_ring (void ) {char *ring; -unsigned int i, order, memflags; +XENCONS_RING_IDX done, size, n; +unsigned int order, memflags;unsigned long flags;if ( !opt_conring_size )@@ -479,8 +480,19 @@ void __init console_init_ring(void) opt_conring_size =PAGE_SIZE << order;
xen/drivers/char/console.c void __init console_init_ring(void) · line 488
Quoted 10 lines
xen/drivers/char/console.c +6
-2nrspin_lock_irqsave (&console_lock, flags); -for ( i = conringc ; i != conringp; i++ ) - ring[i & (opt_conring_size -1 )] = conring[i & (conring_size -1 )]; + + size = conringp - conringc; +for ( done =0 ; done < size; done += n ) + { +XENCONS_RING_IDX src = (conringc + done) & (conring_size -1 ); +XENCONS_RING_IDX dst = (conringc + done) & (opt_conring_size -1 );
I see this has been committed, but the use of XENCONS_RING_* is wrong here. This ring is not a XENCONS ring, and that header is almost straight obfuscation.
The types obscure what's going on, including the fact that this logic is unsafe with a 4G ring. And while that might be a legitimate implementation restriction, it needs to be obvious in the code.
These want to move back to being unsigned int.
~Andrew
Re: [PATCH v7 2/7] xen/console: use memcpy() in console_init_ring()
Quoted 50 lines · Andrew Cooper
Quoted 34 lines · On 13/07/2026 7:16 pm, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Make
console_init_ring()more efficient by using memcpy()'s, rather than copying the ring a byte at a time.No functional change intended.
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Denis Mukhin <[email protected]>Acked-by Roger Pau Monne <[email protected]>---
Changes since v6:
- addressed Roger's feedback
- added Roger's A-b--- xen/drivers/char/console.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)xen/drivers/char/console.c +2
-1@@ -463,7 +463,8 @@ static void cf_check conring_dump_keyhandler(unsigned char key)void __init console_init_ring (void ) {char *ring; -unsigned int i, order, memflags; +XENCONS_RING_IDX done, size, n; +unsigned int order, memflags;unsigned long flags;if ( !opt_conring_size )@@ -479,8 +480,19 @@ void __init console_init_ring(void) opt_conring_size =PAGE_SIZE << order;xen/drivers/char/console.c void __init console_init_ring(void) · line 488
Quoted 10 lines
xen/drivers/char/console.c +6
-2nrspin_lock_irqsave (&console_lock, flags); -for ( i = conringc ; i != conringp; i++ ) - ring[i & (opt_conring_size -1 )] = conring[i & (conring_size -1 )]; + + size = conringp - conringc; +for ( done =0 ; done < size; done += n ) + { +XENCONS_RING_IDX src = (conringc + done) & (conring_size -1 ); +XENCONS_RING_IDX dst = (conringc + done) & (opt_conring_size -1 );I see this has been committed, but the use of XENCONS_RING_* is wrong here. This ring is not a XENCONS ring, and that header is almost straight obfuscation.
Quoted 5 lines
The types obscure what's going on, including the fact that this logic is unsafe with a 4G ring. And while that might be a legitimate implementation restriction, it needs to be obvious in the code.
These want to move back to being unsigned int.
Will update in the next iteration of the series.
PATCH v7 3/7 xen/console: use memcpy() in conring_puts()
In reply to [email protected]From: Denis Mukhin <[email protected]>
Make conring_puts() more efficient by using memcpy()'s, rather than copying the ring a byte at a time.
No functional change intended.
---
Changes since v6:
- new patch
--- xen/drivers/char/console.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
xen/drivers/char/console.c +13 -3
@@ -360,12 +360,22 @@ static DECLARE_SOFTIRQ_TASKLET(conring_tasklet, conring_notify, NULL);/* NB: Do not send conring VIRQs during panic. */ static bool conring_no_notify; -static void conring_puts (const char *str,size_t len) +static void conring_puts (const char *str,unsigned int len) { +unsigned int src =likely (len < conring_size) ?0 : len - conring_size; +ASSERT (rspin_is_locked (&console_lock)); -while ( len-- ) - conring[CONRING_IDX_MASK (conringp++)] = *str++; +while ( src < len ) + { +unsigned int dst =CONRING_IDX_MASK (conringp + src); +unsigned int n =min (conring_size - dst, len - src); + +memcpy (&conring[dst], &str[src], n); + src += n; + } + + conringp += len;if ( conringp - conringc > conring_size ) conringc = conringp - conring_size;
Signature · 1 line
2.54.0
Re: [PATCH v7 3/7] xen/console: use memcpy() in conring_puts()
xen/drivers/char/console.c static DECLARE_SOFTIRQ_TASKLET(conring_tasklet, conring_notify, NULL); · line 365
Quoted 10 lines · On 13.07.2026 20:16, [email protected] wrote:
xen/drivers/char/console.c +2
-1@@ -360,12 +360,22 @@ static DECLARE_SOFTIRQ_TASKLET(conring_tasklet, conring_notify, NULL);/* NB: Do not send conring VIRQs during panic. */ static bool conring_no_notify; -static void conring_puts (const char *str,size_t len) +static void conring_puts (const char *str,unsigned int len) { +unsigned int src =likely (len < conring_size) ?0 : len - conring_size;
Isn't the attempt to handle strings longer than conring_size pretty much in vain? Things look correct as far as the rest of the logic in the function goes, but is this useful? It certainly warrants at least a brief comment imo.
Jan
Re: [PATCH v7 3/7] xen/console: use memcpy() in conring_puts()
Quoted 7 lines · Jan Beulich
Quoted 6 lines · On 13.07.2026 20:16, [email protected] wrote:
xen/drivers/char/console.c +0
-0@@ -360,12 +360,22 @@ static DECLARE_SOFTIRQ_TASKLET(conring_tasklet, conring_notify, NULL);/* NB: Do not send conring VIRQs during panic. */ static bool conring_no_notify;
Quoted 8 lines
xen/drivers/char/console.c static DECLARE_SOFTIRQ_TASKLET(conring_tasklet, conring_notify, NULL); · line 365
Quoted 4 lines
xen/drivers/char/console.c +2
-1-static void conring_puts (const char *str,size_t len) +static void conring_puts (const char *str,unsigned int len) { +unsigned int src =likely (len < conring_size) ?0 : len - conring_size;Isn't the attempt to handle strings longer than
conring_sizepretty much in vain? Things look correct as far as the rest of the logic in the function goes, but is this useful? It certainly warrants at least a brief comment imo.
Thanks for taking a look!
I don't think there ever will callers of conring_puts() with strings longer than conring_size... and I could not decide whether to keep the extra check or not.
Will update the code with a commentary.
Re: [PATCH v7 3/7] xen/console: use memcpy() in conring_puts()
Quoted 17 lines · On 17.07.2026 08:18, [email protected] wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines · On 13.07.2026 20:16, [email protected] wrote:
xen/drivers/char/console.c +0
-0@@ -360,12 +360,22 @@ static DECLARE_SOFTIRQ_TASKLET(conring_tasklet, conring_notify, NULL);/* NB: Do not send conring VIRQs during panic. */ static bool conring_no_notify;Quoted 8 lines
xen/drivers/char/console.c static DECLARE_SOFTIRQ_TASKLET(conring_tasklet, conring_notify, NULL); · line 365
Quoted 4 lines
xen/drivers/char/console.c +2
-1-static void conring_puts (const char *str,size_t len) +static void conring_puts (const char *str,unsigned int len) { +unsigned int src =likely (len < conring_size) ?0 : len - conring_size;Isn't the attempt to handle strings longer than
conring_sizepretty much in vain? Things look correct as far as the rest of the logic in the function goes, but is this useful? It certainly warrants at least a brief comment imo.
Quoted 5 lines
Thanks for taking a look!
I don't think there ever will callers of
conring_puts()with strings longer thanconring_size... and I could not decide whether to keep the extra check or not.
Having though about this a little more over night, I actually wonder whether e.g. len > PAGE_SIZE wouldn't already be indicative of an error. And which hence may instead want flagging by a BUG_ON(). REST maintainers, thoughts?
Jan
PATCH v7 4/7 xen/console: switch conring runtime allocation to xvmalloc
In reply to [email protected]From: Denis Mukhin <[email protected]>
The console ring only needs to be virtually contiguous; it does not need a naturally aligned or physically contiguous allocation. Replace the runtime xenheap allocation in console_init_ring() with an xvmalloc-backed buffer.
Also clamp the user-configured ring size to the supported range and emit warnings when the requested size is adjusted.
Drop full stops in all diagnostic messages in console_init_ring() to align code with the common code pattern.
---
Changes since v6:
- simplified size checks
--- xen/drivers/char/console.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
xen/drivers/char/console.c +16 -9
@@ -33,6 +33,7 @@#include <asm/setup.h> #include <xen/sections.h> #include <xen/consoled.h> +#include <xen/xvmalloc.h> #ifdef CONFIG_X86 #include <asm/guest.h>
@@ -474,20 +475,26 @@ void __init console_init_ring(void) {char *ring;XENCONS_RING_IDX done, size, n; -unsigned int order, memflags;unsigned long flags;if ( !opt_conring_size )return ; - - order =get_order_from_bytes (max (opt_conring_size, conring_size)); - memflags =MEMF_bits (crashinfo_maxaddr_bits); -while ( (ring =alloc_xenheap_pages (order, memflags)) ==NULL ) +else if ( opt_conring_size >GB (2 ) ) { -BUG_ON (order ==0 ); - order--; +printk (XENLOG_WARNING "Limiting user-configured console ring size to 2 GiB\n" ); + opt_conring_size =GB (2 ); } - opt_conring_size =PAGE_SIZE << order; +else + { +unsigned int order =get_order_from_bytes (max (opt_conring_size, + conring_size)); + opt_conring_size =PAGE_SIZE << order; + } + + ring =xvmalloc_array (char, opt_conring_size); +if ( !ring ) +panic ("Unable to allocate console ring of %u KiB\n" , + opt_conring_size >>10 );nrspin_lock_irqsave (&console_lock, flags);
@@ -508,7 +515,7 @@ void __init console_init_ring(void) conring_size = opt_conring_size;nrspin_unlock_irqrestore (&console_lock, flags); -printk ("Allocated console ring of %u KiB.\n" , opt_conring_size >>10 ); +printk ("Allocated console ring of %u KiB\n" , opt_conring_size >>10 ); }/*
Signature · 1 line
2.54.0
Re: [PATCH v7 4/7] xen/console: switch conring runtime allocation to xvmalloc
xen/drivers/char/console.c void __init console_init_ring(void) · line 482
Quoted 10 lines · On 13.07.2026 20:16, [email protected] wrote:
xen/drivers/char/console.c +0
-2@@ -474,20 +475,26 @@ void __init console_init_ring(void) {char *ring;XENCONS_RING_IDX done, size, n; -unsigned int order, memflags;unsigned long flags;if ( !opt_conring_size )return ; -
Please can we keep this blank line and ...
xen/drivers/char/console.c void __init console_init_ring(void) · line 482
Quoted 4 lines
xen/drivers/char/console.c +1
-3- order =get_order_from_bytes (max (opt_conring_size, conring_size)); - memflags =MEMF_bits (crashinfo_maxaddr_bits); -while ( (ring =alloc_xenheap_pages (order, memflags)) ==NULL ) +else if ( opt_conring_size >GB (2 ) )
... have this be just "if ()"? (I'd also suggest to make the "positive" case the "if()" part and have the out-of-range one in the "else" body.)
xen/drivers/char/console.c void __init console_init_ring(void) · line 484
Quoted 4 lines
xen/drivers/char/console.c +1
-2{ -BUG_ON (order ==0 ); - order--; +printk (XENLOG_WARNING "Limiting user-configured console ring size to 2 GiB\n" );
Nit: Too long line. Yes, format strings shouldn't be split, but XENLOG_* can every well live on a separate line.
xen/drivers/char/console.c void __init console_init_ring(void) · line 491
Quoted 8 lines
xen/drivers/char/console.c +6
-1+ opt_conring_size =GB (2 ); } - opt_conring_size =PAGE_SIZE << order; +else + { +unsigned int order =get_order_from_bytes (max (opt_conring_size, + conring_size)); + opt_conring_size =PAGE_SIZE << order;
Nit: Blank line please between declaration(s) and statement(s).
xen/drivers/char/console.c void __init console_init_ring(void) · line 497
Quoted 6 lines
xen/drivers/char/console.c +6
-0+ } + + ring =xvmalloc_array (char, opt_conring_size); +if ( !ring ) +panic ("Unable to allocate console ring of %u KiB\n" , + opt_conring_size >>10 );
Why do you lose the prior behavior of halving the size until allocation succeeds (or we can't even allocate a single page)?
Jan
PATCH v7 5/7 xen/serial: drop stale SERIAL_NEVER_DROP_CHARS
In reply to [email protected]From: Denis Mukhin <[email protected]>
---
Changes since v6:
- new patch
--- xen/drivers/char/serial.c | 3 --- 1 file changed, 3 deletions(-)
xen/drivers/char/serial.c +0 -3
@@ -15,9 +15,6 @@#include <asm/processor.h> -/* Never drop characters, even if the async transmit buffer fills. */ -/* #define SERIAL_NEVER_DROP_CHARS 1 */ -unsigned int __ro_after_init serial_txbufsz =CONFIG_SERIAL_TX_BUFSIZE ;size_param ("serial_tx_buffer" , serial_txbufsz);
Signature · 1 line
2.54.0
Re: [PATCH v7 5/7] xen/serial: drop stale SERIAL_NEVER_DROP_CHARS
Quoted 3 lines · On 13.07.2026 20:16, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Signed-off-by Denis Mukhin <[email protected]>
It would have helped if the origin of it being stale was identified right away. Looks like 275485700163 ("Bring back console_start_log_everything() as a milder alternative to") dropped the sole use only a few weeks after its introduction.
Quoted 12 lines
xen/drivers/char/serial.c +0
-3@@ -15,9 +15,6 @@#include <asm/processor.h> -/* Never drop characters, even if the async transmit buffer fills. */ -/* #define SERIAL_NEVER_DROP_CHARS 1 */ -unsigned int __ro_after_init serial_txbufsz =CONFIG_SERIAL_TX_BUFSIZE ;size_param ("serial_tx_buffer" , serial_txbufsz);
PATCH v7 6/7 xen/serial: harden serial_tx_buffer checks
In reply to [email protected]From: Denis Mukhin <[email protected]>
Ensure the user-defined value never crosses 2GB boundary and always rounded to the next power of 2 to align with console driver conring buffer management code.
---
Changes since v6:
- new patch
--- docs/misc/xen-command-line.pandoc | 2 ++ xen/drivers/char/serial.c | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)
docs/misc/xen-command-line.pandoc +2 -0
@@ -2396,6 +2396,8 @@ accidentally leaking secrets by releasing pages without proper sanitization. Set the serial transmit buffer size. +The value provided will be rounded down to the nearest power of 2. + ### serrors (ARM) > `= diverse | panic`
xen/drivers/char/serial.c +20 -1
@@ -16,7 +16,26 @@#include <asm/processor.h> unsigned int __ro_after_init serial_txbufsz =CONFIG_SERIAL_TX_BUFSIZE ; -size_param ("serial_tx_buffer" , serial_txbufsz); + +static int __init cf_check parse_serial_txbufsz(const char *s) +{ +long long val; + +if (parse_signed_integer ("serial_tx_buffer" , s,NULL , &val) ) +return 0 ; + +if ( val <KB (16 ) || val >GB (2 ) ) + { +printk (XENLOG_WARNING "'serial_tx_buffer=%lld' value out of range, " +"falling back to default\n" , val); + val =CONFIG_SERIAL_TX_BUFSIZE ; + } + + serial_txbufsz =PAGE_SIZE <<get_order_from_bytes (val); + +return 0 ; +} +custom_param ("serial_tx_buffer" , parse_serial_txbufsz);#define mask_serial_rxbuf_idx (_i) ((_i)&(serial_rxbufsz-1))#define mask_serial_txbuf_idx (_i) ((_i)&(serial_txbufsz-1))
Signature · 1 line
2.54.0
Re: [PATCH v7 6/7] xen/serial: harden serial_tx_buffer checks
Quoted 31 lines · On 13.07.2026 20:16, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Ensure the user-defined value never crosses 2GB boundary and always rounded to the next power of 2 to align with console driver conring buffer management code.
Signed-off-by Denis Mukhin <[email protected]>---
Changes since v6:
- new patch--- docs/misc/xen-command-line.pandoc | 2 ++ xen/drivers/char/serial.c | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)docs/misc/xen-command-line.pandoc +2
-0@@ -2396,6 +2396,8 @@ accidentally leaking secrets by releasing pages without proper sanitization. Set the serial transmit buffer size. +The value provided will be rounded down to the nearest power of 2. + ### serrors (ARM) > `= diverse | panic`
xen/drivers/char/serial.c line 19
Quoted 4 lines
xen/drivers/char/serial.c +0
-1@@ -16,7 +16,26 @@#include <asm/processor.h> unsigned int __ro_after_init serial_txbufsz =CONFIG_SERIAL_TX_BUFSIZE ; -size_param ("serial_tx_buffer" , serial_txbufsz);
Before making this change, surely you did look at the difference between size_param() and integer_param()? You should have noticed that you regress behavior by ...
xen/drivers/char/serial.c line 25
Quoted 6 lines
xen/drivers/char/serial.c +6
-0+static int __init cf_check parse_serial_txbufsz(const char *s) +{ +long long val; + +if (parse_signed_integer ("serial_tx_buffer" , s,NULL , &val) ) +return 0 ;
... using this function. It's additionally unclear why a signed value would want parsing here: What's a ring of negative size?
xen/drivers/char/serial.c line 31
Quoted 5 lines
xen/drivers/char/serial.c +5
-0+if ( val <KB (16 ) || val >GB (2 ) ) + { +printk (XENLOG_WARNING "'serial_tx_buffer=%lld' value out of range, " +"falling back to default\n" , val); + val =CONFIG_SERIAL_TX_BUFSIZE ;
In the earlier patch you used the upper bound for too large a value. Why does it become the default size here in such a case?
xen/drivers/char/serial.c line 38
Quoted 7 lines
xen/drivers/char/serial.c +7
-0+ } + + serial_txbufsz =PAGE_SIZE <<get_order_from_bytes (val); + +return 0 ; +} +custom_param ("serial_tx_buffer" , parse_serial_txbufsz);
Overall you're duplicating behavior that serial_async_transmit() provides. Why would we need such duplication? The more that there everything up from PAGE_SIZE is permitted, while you require at least 16k. If you want to add useful extra checks, put them there. Bonus would be to also replace the alloc_xenheap_pages() there (unless there's a hidden reason for it to remain physically contiguous).
Jan
PATCH v7 7/7 xen/console: make console buffer size configurable
In reply to [email protected]From: Denis Mukhin <[email protected]>
Add new CONRING_SHIFT Kconfig parameter to specify the boot console buffer size as a power of 2.
The supported range is [14..27] -> [16KiB..128MiB].
Set default to 15 (32 KiB).
Update the documentation for 'conring_size=' command line option.
Resolves: https://gitlab.com/xen-project/xen/-/issues/185
---
Changes since v6:
- fixed Kconfig and documentation text
--- docs/misc/xen-command-line.pandoc | 8 ++++++-- xen/drivers/char/Kconfig | 21 +++++++++++++++++++++ xen/drivers/char/console.c | 6 +++--- 3 files changed, 30 insertions(+), 5 deletions(-)
docs/misc/xen-command-line.pandoc +6 -2
@@ -425,10 +425,14 @@ The following are examples of correct specifications: ### conring_size > `= <size>` -> Default: `conring_size=16k` - Specify the size of the console ring buffer. +The default console ring buffer size is selected at build-time via +`CONFIG_CONRING_SHIFT` setting. + +The run-time console ring buffer size is the maximum of the build-time value +and the value specified by the `conring_size=` command-line option. + ### console > `= List of [ vga | com1[H,L] | com2[H,L] | pv | dbgp | ehci | xhci | none ]`
xen/drivers/char/Kconfig +21 -0
@@ -95,6 +95,27 @@ config SERIAL_TX_BUFSIZE Default value is 32768 (32KiB). +config CONRING_SHIFT + int "Console ring buffer size (power of 2)" + range 14 27 + default 15 + help + Select the boot console ring buffer size as a power of 2. + + The run-time console ring buffer is the maximum of the build-time + value and the value specified by the `conring_size=` command-line + option. + + If `conring_size=` is not specified on the command line, the run-time + console ring buffer size is the maximum of this value and + `num_present_cpus() << (9 + xenlog_lower_thresh)`. + + 27 => 128 MiB + 26 => 64 MiB + ... + 15 => 32 KiB (default) + 14 => 16 KiB + config XHCI bool "XHCI DbC UART driver" depends on X86
xen/drivers/char/console.c +3 -3
@@ -340,12 +340,12 @@ static void cf_check do_dec_thresh(unsigned char key, bool unused)* ******************************************************** */ -/* conring_size: allows a larger console ring than default (16kB). */ +/* conring_size: override build-time CONFIG_CONRING_SHIFT setting. */ static unsigned int __initdata opt_conring_size;size_param ("conring_size" , opt_conring_size); -#define _CONRING_SIZE 16384 -#define CONRING_IDX_MASK (i) ((i)&(conring_size-1)) +#define _CONRING_SIZE (1U << CONFIG_CONRING_SHIFT) +#define CONRING_IDX_MASK (i) ((i) & (conring_size - 1))static char __initdata _conring[_CONRING_SIZE];static char *__ro_after_init conring = _conring;static unsigned int __ro_after_init conring_size = _CONRING_SIZE;
Signature · 1 line
2.54.0