diff mbox series

[v2,21/35] xen/console: introduce console_init_owner()

Message ID 20241205-vuart-ns8250-v1-21-e9aa923127eb@ford.com (mailing list archive)
State New
Headers show
Series Introduce NS8250 UART emulator | expand

Commit Message

Denis Mukhin via B4 Relay Dec. 6, 2024, 4:41 a.m. UTC
From: Denis Mukhin <dmukhin@ford.com>

console_init_owner() is introduced for selecting the boot-time console owner.

Signed-off-by: Denis Mukhin <dmukhin@ford.com>
---
 xen/drivers/char/console.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

Comments

Jason Andryuk Dec. 10, 2024, 10:30 p.m. UTC | #1
On 2024-12-05 23:41, Denis Mukhin via B4 Relay wrote:
> From: Denis Mukhin <dmukhin@ford.com>
> 
> console_init_owner() is introduced for selecting the boot-time console owner.
> 
> Signed-off-by: Denis Mukhin <dmukhin@ford.com>

Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
Jan Beulich Dec. 11, 2024, 7:31 a.m. UTC | #2
On 06.12.2024 05:41, Denis Mukhin via B4 Relay wrote:
> --- a/xen/drivers/char/console.c
> +++ b/xen/drivers/char/console.c
> @@ -554,6 +554,22 @@ static void console_find_owner(void)
>          console_set_owner(DOMID_XEN);
>  }
>  
> +static void console_init_owner(void)
> +{
> +    domid_t domid;
> +
> +    /*
> +     * If user specifies so, we fool the switch routine to redirect input
> +     * straight back to Xen.
> +     */
> +    if ( opt_conswitch[1] == 'x' )
> +        domid = DOMID_XEN;
> +    else
> +        domid = get_initial_domain_id();
> +
> +    console_set_owner(domid);
> +}

Is this function meant to gain a 2nd user? If not, what exactly is the goal
of introducing this new function?

If the function's addition is warranted, it wants to be __init, matching ...

> @@ -1160,8 +1168,7 @@ void __init console_endboot(void)
>      register_irq_keyhandler('G', &do_toggle_guest,
>                              "toggle host/guest log level adjustment", 0);
>  
> -    /* Serial input is directed to DOM0 by default. */
> -    console_find_owner();
> +    console_init_owner();
>  }

... sole caller.

Jan
Roger Pau Monné Dec. 12, 2024, 10:23 a.m. UTC | #3
On Thu, Dec 05, 2024 at 08:41:51PM -0800, Denis Mukhin via B4 Relay wrote:
> From: Denis Mukhin <dmukhin@ford.com>
> 
> console_init_owner() is introduced for selecting the boot-time console owner.
> 
> Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> ---
>  xen/drivers/char/console.c | 27 +++++++++++++++++----------
>  1 file changed, 17 insertions(+), 10 deletions(-)
> 
> diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
> index a8ab5c2bcb98e4cadf9ad2c9ad28d297977d0557..6261bdb5a2ac1075bc89fa408c0fd6cfef380ae6 100644
> --- a/xen/drivers/char/console.c
> +++ b/xen/drivers/char/console.c
> @@ -554,6 +554,22 @@ static void console_find_owner(void)
>          console_set_owner(DOMID_XEN);
>  }
>  
> +static void console_init_owner(void)

__init attribute missing (given current call context), but see below.

> +{
> +    domid_t domid;
> +
> +    /*
> +     * If user specifies so, we fool the switch routine to redirect input
> +     * straight back to Xen.
> +     */
> +    if ( opt_conswitch[1] == 'x' )
> +        domid = DOMID_XEN;
> +    else
> +        domid = get_initial_domain_id();
> +
> +    console_set_owner(domid);
> +}
> +
>  static void __serial_rx(char c)
>  {
>      switch ( console_owner )
> @@ -1143,14 +1159,6 @@ void __init console_endboot(void)
>  
>      video_endboot();
>  
> -    /*
> -     * If user specifies so, we fool the switch routine to redirect input
> -     * straight back to Xen. I use this convoluted method so we still print
> -     * a useful 'how to switch' message.
> -     */
> -    if ( opt_conswitch[1] == 'x' )
> -        console_owner = DOMID_XEN;
> -
>      register_keyhandler('w', dump_console_ring_key,
>                          "synchronously dump console ring buffer (dmesg)", 0);
>      register_irq_keyhandler('+', &do_inc_thresh,
> @@ -1160,8 +1168,7 @@ void __init console_endboot(void)
>      register_irq_keyhandler('G', &do_toggle_guest,
>                              "toggle host/guest log level adjustment", 0);
>  
> -    /* Serial input is directed to DOM0 by default. */
> -    console_find_owner();
> +    console_init_owner();

Oh, so this is what fixes the regression introduced in patch 19/35.
THB I'm not sure it's worth introducing the console_init_owner()
helper if it's just for this usage.  You could do:

console_set_owner(opt_conswitch[1] == 'x' ? DOMID_XEN
                                          : get_initial_domain_id());

Thanks, Roger.
diff mbox series

Patch

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index a8ab5c2bcb98e4cadf9ad2c9ad28d297977d0557..6261bdb5a2ac1075bc89fa408c0fd6cfef380ae6 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -554,6 +554,22 @@  static void console_find_owner(void)
         console_set_owner(DOMID_XEN);
 }
 
+static void console_init_owner(void)
+{
+    domid_t domid;
+
+    /*
+     * If user specifies so, we fool the switch routine to redirect input
+     * straight back to Xen.
+     */
+    if ( opt_conswitch[1] == 'x' )
+        domid = DOMID_XEN;
+    else
+        domid = get_initial_domain_id();
+
+    console_set_owner(domid);
+}
+
 static void __serial_rx(char c)
 {
     switch ( console_owner )
@@ -1143,14 +1159,6 @@  void __init console_endboot(void)
 
     video_endboot();
 
-    /*
-     * If user specifies so, we fool the switch routine to redirect input
-     * straight back to Xen. I use this convoluted method so we still print
-     * a useful 'how to switch' message.
-     */
-    if ( opt_conswitch[1] == 'x' )
-        console_owner = DOMID_XEN;
-
     register_keyhandler('w', dump_console_ring_key,
                         "synchronously dump console ring buffer (dmesg)", 0);
     register_irq_keyhandler('+', &do_inc_thresh,
@@ -1160,8 +1168,7 @@  void __init console_endboot(void)
     register_irq_keyhandler('G', &do_toggle_guest,
                             "toggle host/guest log level adjustment", 0);
 
-    /* Serial input is directed to DOM0 by default. */
-    console_find_owner();
+    console_init_owner();
 }
 
 int __init console_has(const char *device)