All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: dmukhin@ford.com
Cc: xen-devel@lists.xenproject.org,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH v2 19/35] xen/console: introduce console_set_owner()
Date: Thu, 12 Dec 2024 11:12:24 +0100	[thread overview]
Message-ID: <Z1q3COsFN3J9G60E@macbook.local> (raw)
In-Reply-To: <20241205-vuart-ns8250-v1-19-e9aa923127eb@ford.com>

On Thu, Dec 05, 2024 at 08:41:49PM -0800, Denis Mukhin via B4 Relay wrote:
> From: Denis Mukhin <dmukhin@ford.com>
> 
> console_set_owner() is introduced for setting the new console owner.
> 
> Switches console owner to domain ID vs range of integer numbers mapped to
> domain IDs.
> 
> This a public API to console driver, will be used in the follow on code change.
> 
> Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> ---
>  xen/drivers/char/console.c | 122 ++++++++++++++++++++++++++-------------------
>  xen/include/xen/console.h  |   1 +
>  2 files changed, 71 insertions(+), 52 deletions(-)
> 
> diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
> index 8cbac54c66044ae8581e486a782102b75c8bfaa9..52cf64dbf6fd18d599cb88835d03501a23b3e3c4 100644
> --- a/xen/drivers/char/console.c
> +++ b/xen/drivers/char/console.c
> @@ -463,82 +463,100 @@ static void cf_check dump_console_ring_key(unsigned char key)
>  
>  /*
>   * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0,
> - * and the DomUs started from Xen at boot.
> + * and the DomUs.
>   */
>  #define switch_code (opt_conswitch[0]-'a'+1)
> +
>  /*
> - * console_owner=0 => input to xen
> - * console_owner=1 => input to dom0 (or the sole shim domain)
> - * console_owner=N => input to dom(N-1)
> + * Current console owner domain ID: either Xen or domain w/ d->is_console ==
> + * true.
> + *
> + * Initialized in console_endboot().
>   */
> -static unsigned int __read_mostly console_owner = 0;
> +static domid_t __read_mostly console_owner;

Should this be initialized to DOMID_XEN?  I assume it doesn't make
much difference because the variable is not checked before
console_endboot() anyway, but it might be safer to initialize to a
value that assigns the console to Xen.

>  
> -#define max_console_rx (max_init_domid + 1)
> +static struct domain *rcu_lock_domain_console_by_id(domid_t domid)
> +{
> +    struct domain *d;
> +
> +    d = rcu_lock_domain_by_id(domid);
> +

Nit: I would remove this newline.

> +    if ( d == NULL )
> +        return NULL;
> +
> +    if ( d->is_console )
> +        return d;
> +
> +    rcu_unlock_domain(d);
> +
> +    return NULL;
> +}
>  
> -#ifdef CONFIG_SBSA_VUART_CONSOLE
>  /* Make sure to rcu_unlock_domain after use */
>  struct domain *rcu_lock_domain_console_owner(void)
>  {
> -    if ( console_owner == 0 )
> -            return NULL;
> -    return rcu_lock_domain_by_id(console_owner - 1);
> +    return rcu_lock_domain_console_by_id(console_owner);
>  }
> -#endif
>  
> -static void console_find_owner(void)
> +static bool console_owner_possible(domid_t domid)
>  {
> -    unsigned int next_rx = console_owner;
> -
> -    /*
> -     * Rotate among Xen, dom0 and boot-time created domUs while skipping
> -     * switching serial input to non existing domains.
> -     */
> -    for ( ; ; )
> -    {
> -        domid_t domid;
> -        struct domain *d;
> -
> -        if ( next_rx++ >= max_console_rx )
> -        {
> -            console_owner = 0;
> -            printk("*** Serial input to Xen");
> -            break;
> -        }
> -
> -        if ( consoled_is_enabled() && next_rx == 1 )
> -            domid = get_initial_domain_id();
> -        else
> -            domid = next_rx - 1;
> -
> -        d = rcu_lock_domain_by_id(domid);
> -        if ( d == NULL )
> -            continue;
> -
> -        if ( d->is_console )
> -        {
> -            rcu_unlock_domain(d);
> -            console_owner = next_rx;
> -            printk("*** Serial input to DOM%u", domid);
> -            break;
> -        }
> +    struct domain *d;
>  
> +    d = rcu_lock_domain_console_by_id(domid);
> +    if ( d != NULL )
>          rcu_unlock_domain(d);
> -    }
> +
> +    return d != NULL;
> +}
> +
> +int console_set_owner(domid_t domid)
> +{
> +    if ( domid == DOMID_XEN )
> +        printk("*** Serial input to Xen");
> +    else if ( console_owner_possible(domid) )
> +        printk("*** Serial input to DOM%u", domid);
> +    else
> +        return -ENOENT;
> +
> +    console_owner = domid;
>  
>      if ( switch_code )
>          printk(" (type 'CTRL-%c' three times to switch input)",
>                 opt_conswitch[0]);
>      printk("\n");
> +
> +    return 0;
> +}
> +
> +/*
> + * Switch console input focus.
> + * Rotates input focus among Xen, dom0 and boot-time created domUs while
> + * skipping switching serial input to non existing domains.
> + */
> +static void console_find_owner(void)
> +{
> +    domid_t i, n = max_init_domid + 1;

n can be made const, I would even rename to nr for clarity, but that's
personal taste.

> +
> +    if ( console_owner == DOMID_XEN )
> +        i = get_initial_domain_id();
> +    else
> +        i = console_owner + 1;
> +
> +    for ( ; i < n; i++ )
> +        if ( !console_set_owner(i) )
> +            break;

Hm, that could be a non-trivial amount of iteration if max_init_domid
is bumped for every domain created as you have it in patch 11/35
(albeit I'm not sure that was intended?)

> +    if ( i == n )
> +        console_set_owner(DOMID_XEN);
>  }
>  
>  static void __serial_rx(char c)
>  {
>      switch ( console_owner )
>      {
> -    case 0:
> +    case DOMID_XEN:
>          return handle_keypress(c, false);
>  
> -    case 1:
> +    case 0:

If console_owner now strictly contains a domid you cannot assume that
domid 0 is the hardware domain, you will need to handle this
differently and check whether the domain pointed by console_owner
passes the is_hardware_domain() check.

>          /*
>           * Deliver input to the hardware domain buffer, unless it is
>           * already full.
> @@ -556,7 +574,7 @@ static void __serial_rx(char c)
>  #ifdef CONFIG_SBSA_VUART_CONSOLE
>      default:
>      {
> -        struct domain *d = rcu_lock_domain_by_id(console_owner - 1);
> +        struct domain *d = rcu_lock_domain_by_id(console_owner);
>  
>          /*
>           * If we have a properly initialized vpl011 console for the
> @@ -567,7 +585,7 @@ static void __serial_rx(char c)
>              vpl011_rx_char_xen(d, c);
>          else
>              printk("Cannot send chars to Dom%d: no UART available\n",
> -                   console_owner - 1);
> +                   console_owner);
>  
>          if ( d != NULL )
>              rcu_unlock_domain(d);
> @@ -1126,7 +1144,7 @@ void __init console_endboot(void)
>       * a useful 'how to switch' message.
>       */
>      if ( opt_conswitch[1] == 'x' )
> -        console_owner = max_console_rx;
> +        console_owner = DOMID_XEN;

Hm, are you sure this still works as expected?  Setting console_owner
== DOMID_XEN will cause the call to switch_serial_input() below to
switch the console back to the first domain in the system.  Also
initializing console_owner to 0 by default would also cause the call
to switch_serial_input() to possibly switch it to the first domain
after domid 0 (or back to Xen).

Thanks, Roger.


  parent reply	other threads:[~2024-12-12 10:12 UTC|newest]

Thread overview: 218+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-06  4:41 [PATCH v2 00/35] Introduce NS8250 UART emulator Denis Mukhin
2024-12-06  4:41 ` Denis Mukhin via B4 Relay
2024-12-06  4:41 ` [PATCH v2 01/35] xen: introduce resource.h Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 13:13   ` Jan Beulich
2025-01-04  2:23     ` Denis Mukhin
2024-12-11 11:01   ` Roger Pau Monné
2025-01-04  3:10     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 02/35] xen/irq: introduce NO_IRQ Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 13:17   ` Jan Beulich
2025-01-04  2:26     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 03/35] xen/ctype: introduce isconsole() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 13:22   ` Jan Beulich
2025-01-04  2:31     ` Denis Mukhin
2025-01-06  8:55       ` Jan Beulich
2024-12-06  4:41 ` [PATCH v2 04/35] arm/vuart: use guest_printk() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-06  4:41 ` [PATCH v2 05/35] arm/vuart: make domain_has_vuart() public Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-06  4:41 ` [PATCH v2 06/35] riscv/domain: introduce domain_has_vuart() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-06  4:41 ` [PATCH v2 07/35] ppc/domain: " Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 13:24   ` Jan Beulich
2024-12-06  4:41 ` [PATCH v2 08/35] x86/domain: " Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 13:26   ` Jan Beulich
2025-01-04  2:34     ` Denis Mukhin
2024-12-11 15:13   ` Roger Pau Monné
2025-01-04  3:11     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 09/35] x86/domain: print emulation_flags Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 13:30   ` Jan Beulich
2025-01-04  3:55     ` Denis Mukhin
2024-12-11 15:19   ` Roger Pau Monné
2024-12-12 11:53     ` Jan Beulich
2024-12-12 12:11       ` Roger Pau Monné
2024-12-12 12:50         ` Jan Beulich
2025-01-04  3:56     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 10/35] xen/domain: add get_initial_domain_id() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 13:50   ` Jan Beulich
2025-01-04  2:50     ` Denis Mukhin
2024-12-11 16:50   ` Roger Pau Monné
2025-01-04  4:44     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 11/35] xen/domain: enable max_init_domid for all architectures Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 13:57   ` Jan Beulich
2025-01-04  2:51     ` Denis Mukhin
2024-12-11 17:00   ` Roger Pau Monné
2025-01-04  3:13     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 12/35] xen/console: move vpl011-related code to vpl011 emulator Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 13:33   ` Jan Beulich
2025-01-04  2:49     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 13/35] xen/console: rename console_input_domain Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 14:01   ` Jan Beulich
2025-01-04  2:53     ` Denis Mukhin
2024-12-11 17:17   ` Roger Pau Monné
2025-01-04  3:13     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 14/35] xen/console: rename switch_serial_input() to console_find_owner() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 14:13   ` Jan Beulich
2024-12-11 17:22     ` Roger Pau Monné
2025-01-04  3:14       ` Denis Mukhin
2025-01-04  2:54     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 15/35] xen/console: rename console_rx to console_owner Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 14:23   ` Jan Beulich
2024-12-12  8:58   ` Roger Pau Monné
2025-01-04  3:20     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 16/35] xen/console: introduce printk_common() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 14:27   ` Jan Beulich
2025-01-04  2:57     ` Denis Mukhin
2025-01-06  9:04       ` Jan Beulich
2024-12-12  9:14   ` Roger Pau Monné
2024-12-12 11:57     ` Jan Beulich
2024-12-12 12:15       ` Roger Pau Monné
2024-12-12 12:52         ` Jan Beulich
2024-12-12 15:25           ` Roger Pau Monné
2024-12-13  1:03           ` Stefano Stabellini
2025-01-04  4:11             ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 17/35] xen/console: introduce consoled_is_enabled() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 14:31   ` Jan Beulich
2025-01-04  3:00     ` Denis Mukhin
2025-01-06  9:05       ` Jan Beulich
2024-12-12  9:31   ` Roger Pau Monné
2025-01-04  3:21     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 18/35] xen/console: introduce use of 'is_console' flag Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 14:52   ` Jan Beulich
2025-01-04  3:05     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 19/35] xen/console: introduce console_set_owner() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 15:02   ` Jan Beulich
2025-01-04  3:07     ` Denis Mukhin
2025-01-06  9:08       ` Jan Beulich
2024-12-12 10:12   ` Roger Pau Monné [this message]
2024-12-12 11:59     ` Jan Beulich
2024-12-12 12:16       ` Roger Pau Monné
2025-01-04  3:31       ` Denis Mukhin
2025-01-04  3:30     ` Denis Mukhin
2025-01-06  9:58       ` Jan Beulich
2025-01-06 20:03         ` Denis Mukhin
2025-01-07  8:37           ` Jan Beulich
2024-12-06  4:41 ` [PATCH v2 20/35] xen/console: introduce console_owner_domid() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 22:11   ` Jason Andryuk
2024-12-11  7:33     ` Jan Beulich
2025-01-04  4:16       ` Denis Mukhin
2025-01-04  4:12     ` Denis Mukhin
2024-12-11  7:28   ` Jan Beulich
2025-01-04  4:15     ` Denis Mukhin
2025-01-06  9:14       ` Jan Beulich
2025-01-06 18:48         ` Stefano Stabellini
2025-01-07  8:40           ` Jan Beulich
2025-01-07 23:40             ` Stefano Stabellini
2025-01-08  7:28               ` Jan Beulich
2025-01-08  8:04                 ` Roger Pau Monné
2025-01-08  8:13                   ` Jan Beulich
2025-01-08  8:35                     ` Roger Pau Monné
2025-01-08 22:15                       ` Denis Mukhin
2025-01-09  0:29                         ` Stefano Stabellini
2025-01-09  8:06                           ` Roger Pau Monné
2025-01-09 23:46                             ` Stefano Stabellini
2025-01-10  1:39                               ` Denis Mukhin
2025-01-09  8:25                           ` Jan Beulich
2025-01-09  8:27                         ` Jan Beulich
2025-01-10  1:34                           ` Denis Mukhin
2024-12-12 10:18   ` Roger Pau Monné
2025-01-04  4:11     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 21/35] xen/console: introduce console_init_owner() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-10 22:30   ` Jason Andryuk
2024-12-11  7:31   ` Jan Beulich
2025-01-04  3:22     ` Denis Mukhin
2024-12-12 10:23   ` Roger Pau Monné
2025-01-04  3:23     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 22/35] xen/console: introduce handle_keypress_in_domain() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-12 10:51   ` Roger Pau Monné
2025-01-04  3:25     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 23/35] xen/console: introduce console_write() Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-12 12:04   ` Roger Pau Monné
2025-01-04  3:50     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 24/35] xen/console: introduce hwdom_crashconsole= Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-12 12:29   ` Roger Pau Monné
2025-01-04  4:48     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 25/35] xen/console: simplify console owner switch hint Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-06  4:41 ` [PATCH v2 26/35] xen/console: make console buffer size configurable Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-12 12:47   ` Roger Pau Monné
2025-01-04  3:52     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 27/35] xen/console: flush console ring to physical console Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-12 14:21   ` Roger Pau Monné
2025-01-04  3:56     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 28/35] xen/8250-uart: add missing definitions Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-12 14:29   ` Roger Pau Monné
2025-01-04  4:01     ` Denis Mukhin
2024-12-12 15:07   ` Jan Beulich
2025-01-04  4:00     ` Denis Mukhin
2024-12-06  4:41 ` [PATCH v2 29/35] x86/hvm: add HVM-specific Kconfig Denis Mukhin
2024-12-06  4:41   ` Denis Mukhin via B4 Relay
2024-12-12 15:06   ` Roger Pau Monné
2025-01-04  3:58     ` Denis Mukhin
2024-12-06  4:42 ` [PATCH v2 30/35] x86/hvm: add helpers for raising guest IRQs Denis Mukhin
2024-12-06  4:42   ` Denis Mukhin via B4 Relay
2024-12-12 16:18   ` Roger Pau Monné
2025-01-04  4:02     ` Denis Mukhin
2024-12-06  4:42 ` [PATCH v2 31/35] x86/hvm: introduce NS8250 UART emulator Denis Mukhin
2024-12-06  4:42   ` Denis Mukhin via B4 Relay
2024-12-13 11:43   ` Roger Pau Monné
2025-01-04  6:28     ` Denis Mukhin
2024-12-16 15:04   ` Jan Beulich
2025-01-04  5:31     ` Denis Mukhin
2025-01-06  9:19       ` Jan Beulich
2025-01-06 20:16         ` Denis Mukhin
2025-01-07  8:43           ` Jan Beulich
2024-12-06  4:42 ` [PATCH v2 32/35] x86/hvm: add debugging facility to " Denis Mukhin
2024-12-06  4:42   ` Denis Mukhin via B4 Relay
2024-12-13 12:08   ` Roger Pau Monné
2025-01-04  4:31     ` Denis Mukhin
2024-12-16 15:08   ` Jan Beulich
2025-01-04  4:37     ` Denis Mukhin
2024-12-06  4:42 ` [PATCH v2 33/35] x86/domain: implement domain_has_vuart() Denis Mukhin
2024-12-06  4:42   ` Denis Mukhin via B4 Relay
2024-12-13 12:23   ` Roger Pau Monné
2024-12-13 20:45     ` Stefano Stabellini
2024-12-16  8:40       ` Roger Pau Monné
2025-01-04  5:26       ` Denis Mukhin
2025-01-04  5:19     ` Denis Mukhin
2025-01-07 15:16       ` Roger Pau Monné
2025-01-07 17:33         ` Denis Mukhin
2024-12-16 15:11   ` Jan Beulich
2025-01-04  5:26     ` Denis Mukhin
2024-12-06  4:42 ` [PATCH v2 34/35] xen/console: enable console owners w/ emulated NS8250 Denis Mukhin
2024-12-06  4:42   ` Denis Mukhin via B4 Relay
2024-12-10 22:46   ` Jason Andryuk
2024-12-11  7:35     ` Jan Beulich
2024-12-11  7:38     ` Jan Beulich
2025-01-04  3:12       ` Denis Mukhin
2025-01-04  3:08     ` Denis Mukhin
2024-12-06  4:42 ` [PATCH v2 35/35] docs/misc: update console documentation Denis Mukhin
2024-12-06  4:42   ` Denis Mukhin via B4 Relay
2024-12-14 18:05 ` [PATCH v2 00/35] Introduce NS8250 UART emulator Marek Marczykowski-Górecki
2024-12-16  9:04   ` Roger Pau Monné
2025-01-04  4:28     ` Denis Mukhin
2025-01-04  4:27   ` Denis Mukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z1q3COsFN3J9G60E@macbook.local \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dmukhin@ford.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.