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

[xen master] xen/console: skip switching serial input to non existing domains



commit c2581c58bec96afa450ebaca3fa2a33bcb0a9974
Author:     Michal Orzel <michal.orzel@xxxxxxx>
AuthorDate: Mon Mar 20 17:12:51 2023 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Mar 20 17:12:51 2023 +0100

    xen/console: skip switching serial input to non existing domains
    
    At the moment, we direct serial input to hardware domain by default.
    This does not make any sense when running in true dom0less mode, since
    such domain does not exist. As a result, users wishing to write to
    an emulated UART of a domU are always forced to execute CTRL-AAA first.
    The same issue is when rotating among serial inputs, where we always
    have to go through hardware domain case. This problem can be elaborated
    further to all the domains that no longer exist.
    
    Modify switch_serial_input() so that we skip switching serial input to
    non existing domains. Take the opportunity to define and make use of
    macro max_console_rx to make it clear what 'max_init_domid + 1' means
    in the console code context. Also, modify call to printk() to use correct
    format specifier for unsigned int.
    
    For now, to minimize the required changes and to match the current
    behavior with hwdom, the default input goes to the first real domain.
    The choice is more or less arbitrary since dom0less domUs are supposedly
    equal. This will be handled in the future by adding support in boot time
    configuration for marking a specific domain preferred in terms of
    directing serial input to.
    
    Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/drivers/char/console.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 51e5408f21..0e410fa086 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -473,6 +473,8 @@ static void cf_check dump_console_ring_key(unsigned char 
key)
  */
 static unsigned int __read_mostly console_rx = 0;
 
+#define max_console_rx (max_init_domid + 1)
+
 /* Make sure to rcu_unlock_domain after use */
 struct domain *console_input_domain(void)
 {
@@ -483,15 +485,31 @@ struct domain *console_input_domain(void)
 
 static void switch_serial_input(void)
 {
-    if ( console_rx == max_init_domid + 1 )
-    {
-        console_rx = 0;
-        printk("*** Serial input to Xen");
-    }
-    else
+    unsigned int next_rx = console_rx;
+
+    /*
+     * Rotate among Xen, dom0 and boot-time created domUs while skipping
+     * switching serial input to non existing domains.
+     */
+    for ( ; ; )
     {
-        console_rx++;
-        printk("*** Serial input to DOM%d", console_rx - 1);
+        struct domain *d;
+
+        if ( next_rx++ >= max_console_rx )
+        {
+            console_rx = 0;
+            printk("*** Serial input to Xen");
+            break;
+        }
+
+        d = rcu_lock_domain_by_id(next_rx - 1);
+        if ( d )
+        {
+            rcu_unlock_domain(d);
+            console_rx = next_rx;
+            printk("*** Serial input to DOM%u", next_rx - 1);
+            break;
+        }
     }
 
     if ( switch_code )
@@ -1089,7 +1107,7 @@ void __init console_endboot(void)
      * a useful 'how to switch' message.
      */
     if ( opt_conswitch[1] == 'x' )
-        console_rx = max_init_domid + 1;
+        console_rx = max_console_rx;
 
     register_keyhandler('w', dump_console_ring_key,
                         "synchronously dump console ring buffer (dmesg)", 0);
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

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