From: Denis Mukhin <[email protected]> conring buffer doesn't need to be aligned to it's size; it just needs to be contiguous. Use xmalloc_bytes() in console_init_preirq() for run-time conring buffer allocation.
Warn user when the conring size is being changed behind the user's back during the console initialization. Also, limit the user-selectable conring buffer size to the maximum of 2GB and minimum of _CONRING_SIZE. Suggested-by: Andrew Cooper <[email protected]> Signed-off-by: Denis Mukhin <[email protected]> --- Changes since v4: - new patch --- xen/drivers/char/console.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 3ad86fd436e2..9394ab2a89eb 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -463,20 +463,34 @@ static void cf_check conring_dump_keyhandler(unsigned char key) void __init console_init_ring(void) { char *ring; - unsigned int start, size, chunk, order, memflags; + unsigned int start, size, chunk; 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 ) + opt_conring_size = max(opt_conring_size, conring_size); + size = ROUNDDOWN(opt_conring_size, PAGE_SIZE); + if ( size != opt_conring_size ) { - BUG_ON(order == 0); - order--; + opt_conring_size = size; + printk(XENLOG_WARNING "Rounding down console ring size to multiple of %lu KiB.\n", + PAGE_SIZE >> 10); } - opt_conring_size = PAGE_SIZE << order; + if ( opt_conring_size >= GB(2) ) + { + opt_conring_size = GB(2); + printk(XENLOG_WARNING "Limiting user-configured console ring size.\n"); + } + else if ( opt_conring_size < _CONRING_SIZE ) + { + opt_conring_size = _CONRING_SIZE; + printk(XENLOG_WARNING "Using compile-time console ring size.\n"); + } + + /* Contiguous buffer; does not need to be naturally aligned. */ + ring = xmalloc_bytes(opt_conring_size); + BUG_ON(ring == NULL); nrspin_lock_irqsave(&console_lock, flags); -- 2.52.0
