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

Re: [PATCH v3 04/10] console: support multiple serial console simultaneously


  • To: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 4 Aug 2022 16:13:56 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=VTuDKxZ7q6XrynJBt6sd1xWkzC4emYIpt0uOrgjtYzI=; b=MTVtO4OyZYYyrXtS8Bx0JFuQ6DBzojcMS8GqcE8fJshth5kuemJJ6oF0+JPFvuicrfGv+sgVXHP83Uz1ZXfFP35bwlVIwlGjSWDXSaxjoozrQi1DygJC43QGnnznP2/zoGAaApIMxoHRTMqNMR7K10qZYJ2NRgtmBfT36tSfmW94BjTHIECKv7fvY64nW0zhhSFzfqn/L8R7gHafje5+KFAjysKED+UU6ooNh/CwTmDCp+TjCrGPL9BGl4dda5xzhjFBeKRcTOc+7w9kRtesGyjQ/IJpS/rjHgF5ZALpxTB0QM2HWlWzwij1TdTOt2EXquwKPUXlfnk/65lD3Y4bUQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mgcutbMdFrHM7NevH5EOloYyvYbNZaSDE5Z2jbGwKSHFTZgioYzCn7mseKQiLVKrKeTtI7D3lWBM2ewS6rWhBx9b0zz5Ljn/w92UUpfkgJAlN1TVS8DUyNoqQjeKZBLCvUV8QcHzmEesoFDqEOh8K3GC2L3D+yyotqHxKFxDQM+YgYsT+WQVnhSVKajcsmJzgeQOU0gBtihjHPthxsA00+AMfYAwSrynyc2uGUMWoQpGL/laWn5kHmnZHX/CAqYUOovb+OX61KPVNuvOWUAWMjmiiIkkTkiuaH+bbOz0ypSWChXCz0NWVm9YxH9rSSIDBxDrgKQ5/NMKPM7xatsITA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 04 Aug 2022 14:14:30 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 26.07.2022 05:23, Marek Marczykowski-Górecki wrote:
> --- a/xen/drivers/char/Kconfig
> +++ b/xen/drivers/char/Kconfig
> @@ -85,6 +85,17 @@ config SERIAL_TX_BUFSIZE
>  
>         Default value is 16384 (16kiB).
>  
> +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=` parameter will be ignored.
> +      When multiple consoles are configured, overhead of `sync_console` 
> option
> +      is even bigger.
> +
> +       Default value is 4.

Indentation (the help text ought to be indented by a tab and two spaces).

> --- a/xen/drivers/char/console.c
> +++ b/xen/drivers/char/console.c
> @@ -113,7 +113,9 @@ static char *__read_mostly conring = _conring;
>  static uint32_t __read_mostly conring_size = _CONRING_SIZE;
>  static uint32_t conringc, conringp;
>  
> -static int __read_mostly sercon_handle = -1;
> +#define MAX_SERCONS CONFIG_MAX_SERCONS
> +static int __read_mostly sercon_handle[MAX_SERCONS];
> +static int __read_mostly nr_sercon_handle = 0;

unsigned int please.

> @@ -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;
>  
> -static void (*serial_steal_fn)(const char *, size_t nr) = early_puts;
> +/* The last entry means "steal from all consoles" */
> +static void (*serial_steal_fn[MAX_SERCONS+1])(const char *, size_t nr) = {

Nit: blanks please around + . But with ...

> +    [MAX_SERCONS] = early_puts,

... this initializer you could as well omit the dimension.

> +};
>  
> +/*
> + * Redirect console *handle* output to *fn*. Use SERHND_STEAL_ALL as 
> *handle* to
> + * redirect all the consoles. 
> + */
>  int console_steal(int handle, void (*fn)(const char *, size_t nr))
>  {
> -    if ( (handle == -1) || (handle != sercon_handle) )
> -        return 0;
> +    int i;

While from the use inside the function this would better be unsigned int,
I can see how that would be slightly odd with the return value. But with
overly high a MAX_SERCONS ...

> +    if ( handle == -1 )
> +        return -ENOENT;
> +    if ( serial_steal_fn[MAX_SERCONS] != NULL )
> +        return -EBUSY;
> +    if ( handle == SERHND_STEAL_ALL )
> +    {
> +        serial_steal_fn[MAX_SERCONS] = fn;
> +        return MAX_SERCONS;
> +    }
> +    for ( i = 0; i < nr_sercon_handle; i++ )
> +        if ( handle == sercon_handle[i] )

... the array access will degenerate when i is "int", but will be okay
when i is "unsigned int" (and of course everything will break if
MAX_SERCONS > UINT_MAX).

> +            break;
> +    if ( i == nr_sercon_handle )
> +        return -ENOENT;
>  
> -    if ( serial_steal_fn != NULL )
> +    if ( serial_steal_fn[i] != NULL )
>          return -EBUSY;
>  
> -    serial_steal_fn = fn;
> -    return 1;
> +    serial_steal_fn[i] = fn;
> +    return i;
>  }
>  
>  void console_giveback(int id)
>  {
> -    if ( id == 1 )
> -        serial_steal_fn = NULL;
> +    if ( id >= 0 && id <= MAX_SERCONS )
> +        serial_steal_fn[id] = NULL;
>  }
>  
>  void console_serial_puts(const char *s, size_t nr)
>  {
> -    if ( serial_steal_fn != NULL )
> -        serial_steal_fn(s, nr);
> +    int i;

unsigned int please, again (yet more further down).

> +    if ( serial_steal_fn[MAX_SERCONS] != NULL )
> +        serial_steal_fn[MAX_SERCONS](s, nr);
>      else
> -        serial_puts(sercon_handle, s, nr);
> +        for ( i = 0; i < nr_sercon_handle; i++ )
> +            if ( serial_steal_fn[i] != NULL )
> +                serial_steal_fn[i](s, nr);
> +            else
> +                serial_puts(sercon_handle[i], s, nr);

This for() would better gain braces.

> @@ -977,8 +1006,12 @@ void __init console_init_preirq(void)
>              continue;
>          else if ( (sh = serial_parse_handle(p)) >= 0 )
>          {
> -            sercon_handle = sh;
> -            serial_steal_fn = NULL;
> +            if ( nr_sercon_handle < MAX_SERCONS )
> +                sercon_handle[nr_sercon_handle++] = sh;
> +            else
> +                printk("Too many consoles (max %d), ignoring '%s'\n",
> +                       MAX_SERCONS, p);

In order to use p here, I think we want (need?) to make
serial_parse_handle()'s parameter const char *.

> --- 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)
>  
>          e = parse_pci(opt_dbgp + 8, NULL, &bus, &slot, &func);
>          if ( !e || *e )
> +        {
> +            printk(XENLOG_ERR
> +                   "Invalid dbgp= PCI device spec: '%s'\n",
> +                   opt_dbgp);
>              return;
> -
> +        }
>          dbc->sbdf = PCI_SBDF(0, bus, slot, func);
>      }

Does this change belong elsewhere?

Jan



 


Rackspace

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