[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 4/4] xen/console: switch conring runtime allocation to xvmalloc


  • To: dmukhin@xxxxxxxx
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 2 Jun 2026 11:49:02 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iPxSoZqGyGQQTAKUzy4uyC5cj6Bm7gEwiqRl8Oof5JY=; b=RJProFqCEedUlI/M2r9QA/g60IcRvtE0ZkQXictRcREsmhUg3rm6sgVcJYUETFd8fS8UutG+7BBHgpgtJUSj7ar+5txBOPlHqYXV82oFwrP61UVc11IVHpzARKsBUOIAn2Ki24xKZHjtxxC0ABBwVPgSqpuHJNORGsaNfIfam5/kKQTvxuRbTpBiNmKd5rLR4JNhQm4+1qtQG9LdE86awXx2TioXz8w2E2TRKtysoYlHUdDaYUHiLeIsG35rJ1l5hQqAvmBLoAx5OdOlfExvilua6LPoHOVR9LfaX1HhVHJwlBqOMPcfQNa0opgwbIDedBKhQrln2PGlHQ3qeG9xWg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uyRkmNyeRLaTrvppdX+edSV/m74Ckkj207E7Fe0ckDS11ORkFSWtMIxcCv0st/+9mXfvilznagl5N3/ZOfVKs9LSnOoHY+r27Z+EMvlEkVve5/lUwvPhhVAOugecdxOj89sWAJ7g86Z4/elyvOQ1CLAMUxH4NQZT25MW6Bb3ANTSGEPuayx0cX3vhB9ose7hoteCnvkaj5czQnrMm4ZrYhC28Fbz7T0rVgjRBth0SrR5g3kiiTl5DP7bdrDTNhZjQl35Ryg2vEFW41/rarP2OUoaPDEItUy5SfnTaInziA0D88AMozslGKwTHMMbOq5gpTKvfwGY2XaGQjCMgit1aQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, andrew.cooper3@xxxxxxxxxx, anthony.perard@xxxxxxxxxx, jbeulich@xxxxxxxx, julien@xxxxxxx, michal.orzel@xxxxxxx, sstabellini@xxxxxxxxxx
  • Delivery-date: Tue, 02 Jun 2026 09:49:17 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, May 08, 2026 at 05:57:14PM -0700, dmukhin@xxxxxxxx wrote:
> From: Denis Mukhin <dmukhin@xxxxxxxx> 
> 
> 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.
> 
> Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
> ---
> Changes since v5:
> - switched to xvmalloc_array()
> - fixed conring size checks
> - corrected diagnostic messages
> ---
>  xen/drivers/char/console.c | 27 +++++++++++++++++++++------
>  1 file changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
> index 5cac87d052b9..29b9359468e7 100644
> --- a/xen/drivers/char/console.c
> +++ b/xen/drivers/char/console.c
> @@ -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>
> @@ -343,6 +344,7 @@ static void cf_check do_dec_thresh(unsigned char key, 
> bool unused)
>  static unsigned int __initdata opt_conring_size;
>  size_param("conring_size", opt_conring_size);
>  
> +#define CONRING_SIZE_MIN    (1U << 14)
>  #define _CONRING_SIZE       (1U << CONFIG_CONRING_SHIFT)
>  #define CONRING_IDX_MASK(i) ((i) & (conring_size - 1))
>  static char __initdata _conring[_CONRING_SIZE];
> @@ -464,20 +466,33 @@ void __init console_init_ring(void)
>  {
>      char *ring;
>      XENCONS_RING_IDX i, size;
> -    unsigned int order, memflags;
> +    unsigned int order;
>      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 )
> +    size = PAGE_SIZE << order;
> +    if ( size != opt_conring_size )
>      {
> -        BUG_ON(order == 0);
> -        order--;
> +        opt_conring_size = size;
> +        printk(XENLOG_WARNING "Normalizing console ring size.\n");

I think you want to also specify to what it has been normalized, ie:

"Normalizing command line console ring size %u to %u.\n", opt_conring_size, size

However, note how console_init_postirq() sets opt_conring_size if not
specified, and AFAICT that calculated value might not be a power of 2,
and it might be lower than the build time setting.  If you want to
print warning messages about the user-provided value (if any), you
need to split the checking from console_init_ring(), and do it
exclusively for the command line user-provided value, not for the
value generated by Xen in console_init_postirq().

Also, a user attempting to set a console buffer size below the
built-time value will get this "Normalizing size" message, when it
should otherwise get a message about the command line value being
smaller than the built time setting.

>      }
> -    opt_conring_size = PAGE_SIZE << order;
> +    if ( opt_conring_size < CONRING_SIZE_MIN )
> +    {
> +        opt_conring_size = 0;
> +        printk(XENLOG_WARNING "Ignoring too-small console ring size 
> override.\n");
> +        return;
> +    }

I don't think this is possible, as the built time Kconfig value is
forced to be >= 14, and hence the order calculated above can never be
smaller than 14.

> +    else if ( opt_conring_size > GB(2) )
> +    {
> +        opt_conring_size = GB(2);
> +        printk(XENLOG_WARNING "Limiting user-configured console ring size to 
> 2 GiB.\n");
> +    }
> +
> +    ring = xvmalloc_array(char, opt_conring_size);
> +    BUG_ON(ring == NULL);

Since you are already touching this, might I suggest to use a panic
rather than a BUG?

if ( !ring )
    panic("Unable to allocate console ring buffer of size %u\n",...);

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.