All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: julien.grall@arm.com
Cc: Stefano Stabellini <stefanos@xilinx.com>,
	sstabellini@kernel.org, andrii_anisov@epam.com,
	konrad.wilk@oracle.com, George.Dunlap@eu.citrix.com,
	andrew.cooper3@citrix.com, Achin.Gupta@arm.com,
	ian.jackson@eu.citrix.com, xen-devel@lists.xen.org, tim@xen.org,
	jbeulich@suse.com, wei.liu2@citrix.com
Subject: [PATCH v5 21/25] xen: support console_switching between Dom0 and DomUs on ARM
Date: Mon, 22 Oct 2018 19:03:00 -0700	[thread overview]
Message-ID: <1540260184-11294-21-git-send-email-sstabellini@kernel.org> (raw)
In-Reply-To: <alpine.DEB.2.10.1810221859480.31582@sstabellini-ThinkPad-X260>

Today Ctrl-AAA is used to switch between Xen and Dom0. Extend the
mechanism to allow for switching between Xen, Dom0, and any of the
initial DomU created from Xen alongside Dom0 out of information provided
via device tree.

Rename xen_rx to console_rx to match the new behavior.

Clarify existing comment about "notify the guest", making it clear that
it is only about the hardware domain.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
CC: andrew.cooper3@citrix.com
CC: George.Dunlap@eu.citrix.com
CC: ian.jackson@eu.citrix.com
CC: jbeulich@suse.com
CC: konrad.wilk@oracle.com
CC: tim@xen.org
CC: wei.liu2@citrix.com
---
Changes in v5:
- move patch earlier and disable code that calls vpl011_rx_char_xen (not
  defined yet)
- improve comments
- replace ifs with a switch
- code style

Changes in v4:
- handle console_rx == 0 in console_input_domain
- use rcu_lock_by_domain instead of get_domain_by_id
- handle the case where the returned domain is NULL
- send_global_virq(VIRQ_CONSOLE) only when chars are for Dom0
- make console_rx unsigned int
- fix comment
- code readability improvement
- fix opt_conswitch[1] == 'x' case
- move console_input_domain to next patch

Changes in v3:
- only call vpl011 functions ifdef CONFIG_SBSA_VUART_CONSOLE
- add blank line and spaces
- remove xen_rx from print messages
- rename xen_rx to console_rx
- keep switch_serial_input() at boot
- add better comments
- fix existing comment
- add warning if no guests console/uart is available
- add console_input_domain function

Changes in v2:
- only call vpl011_rx_char if the vpl011 has been initialized
---
 xen/drivers/char/console.c | 79 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 65 insertions(+), 14 deletions(-)

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 3b75f7a..75172e7 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -31,10 +31,13 @@
 #include <xen/early_printk.h>
 #include <xen/warning.h>
 #include <xen/pv_console.h>
+#include <asm/setup.h>
 
 #ifdef CONFIG_X86
 #include <xen/consoled.h>
 #include <asm/guest.h>
+#else
+#include <asm/vpl011.h>
 #endif
 
 /* console: comma-separated list of console outputs. */
@@ -391,31 +394,79 @@ static void dump_console_ring_key(unsigned char key)
     free_xenheap_pages(buf, order);
 }
 
-/* CTRL-<switch_char> switches input direction between Xen and DOM0. */
+/*
+ * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0,
+ * and DomUs.
+ */
 #define switch_code (opt_conswitch[0]-'a'+1)
-static int __read_mostly xen_rx = 1; /* FALSE => input passed to domain 0. */
+/*
+ * console_rx=0 => input to xen
+ * console_rx=1 => input to dom0
+ * console_rx=N => input to dom(N-1)
+ */
+static unsigned int __read_mostly console_rx = 0;
 
 static void switch_serial_input(void)
 {
-    static char *input_str[2] = { "DOM0", "Xen" };
-    xen_rx = !xen_rx;
-    printk("*** Serial input -> %s", input_str[xen_rx]);
+    if ( console_rx++ == max_init_domid + 1 )
+        console_rx = 0;
+
+    if ( console_rx == 0 )
+        printk("*** Serial input to Xen");
+    else
+        printk("*** Serial input to DOM%d", console_rx - 1);
+
     if ( switch_code )
-        printk(" (type 'CTRL-%c' three times to switch input to %s)",
-               opt_conswitch[0], input_str[!xen_rx]);
+        printk(" (type 'CTRL-%c' three times to switch input)",
+               opt_conswitch[0]);
     printk("\n");
 }
 
 static void __serial_rx(char c, struct cpu_user_regs *regs)
 {
-    if ( xen_rx )
+    switch ( console_rx )
+    {
+    case 0:
         return handle_keypress(c, regs);
+    case 1:
+    {
+        /*
+         * Deliver input to the hardware domain buffer, unless it is
+         * already full.
+         */
+        if ( (serial_rx_prod - serial_rx_cons) != SERIAL_RX_SIZE )
+            serial_rx_ring[SERIAL_RX_MASK(serial_rx_prod++)] = c;
+
+        /*
+         * Always notify the hardware domain: prevents receive path from
+         * getting stuck.
+         */
+        send_global_virq(VIRQ_CONSOLE);
+        break;
+    }
+#if 0
+    default:
+    {
+        struct domain *d = rcu_lock_domain_by_any_id(console_rx - 1);
+
+        /*
+         * If we have a properly initialized vpl011 console for the
+         * domain, without a full PV ring to Dom0 (in that case input
+         * comes from the PV ring), then send the character to it.
+         */
+        if ( d != NULL &&
+             !d->arch.vpl011.backend_in_domain &&
+             d->arch.vpl011.backend.xen != NULL )
+            vpl011_rx_char_xen(d, c);
+        else
+            printk("Cannot send chars to Dom%d: no UART available\n",
+                   console_rx - 1);
 
-    /* Deliver input to guest buffer, unless it is already full. */
-    if ( (serial_rx_prod-serial_rx_cons) != SERIAL_RX_SIZE )
-        serial_rx_ring[SERIAL_RX_MASK(serial_rx_prod++)] = c;
-    /* Always notify the guest: prevents receive path from getting stuck. */
-    send_global_virq(VIRQ_CONSOLE);
+        if ( d != NULL )
+            rcu_unlock_domain(d);
+    }
+#endif
+    }
 
 #ifdef CONFIG_X86
     if ( pv_shim && pv_console )
@@ -943,7 +994,7 @@ void __init console_endboot(void)
      * a useful 'how to switch' message.
      */
     if ( opt_conswitch[1] == 'x' )
-        xen_rx = !xen_rx;
+        console_rx = max_init_domid + 1;
 
     register_keyhandler('w', dump_console_ring_key,
                         "synchronously dump console ring buffer (dmesg)", 0);
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-10-23  2:03 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-23  2:02 [PATCH v5 00/25] dom0less step1: boot multiple domains from device tree Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 01/25] xen: allow console_io hypercalls from certain DomUs Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 02/25] xen/arm: extend device tree based multiboot protocol Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 03/25] xen/arm: document dom0less Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 04/25] xen/arm: increase MAX_MODULES Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 05/25] xen/arm: check for multiboot nodes only under /chosen Stefano Stabellini
2018-10-26 19:25   ` Julien Grall
2018-10-26 21:12     ` Stefano Stabellini
2018-10-26 21:27       ` Julien Grall
2018-10-26 21:32         ` Julien Grall
2018-10-27  0:42           ` Stefano Stabellini
2018-10-28 17:28             ` Julien Grall
2018-10-23  2:02 ` [PATCH v5 06/25] xen/arm: introduce bootcmdlines Stefano Stabellini
2018-10-26 19:44   ` Julien Grall
2018-10-27  0:34     ` Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 07/25] xen/arm: don't add duplicate boot modules, introduce domU flag Stefano Stabellini
2018-10-30 11:50   ` Julien Grall
2018-11-02 20:15     ` Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 08/25] xen/arm: probe domU kernels and initrds Stefano Stabellini
2018-10-30 12:03   ` Julien Grall
2018-11-02 20:41     ` Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 09/25] xen/arm: rename get_11_allocation_size to get_allocation_size Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 10/25] xen/arm: rename allocate_memory to allocate_memory_11 Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 11/25] xen/arm: introduce allocate_memory Stefano Stabellini
2018-10-30 12:24   ` Julien Grall
2018-11-02 22:20     ` Stefano Stabellini
2018-10-30 20:56   ` Julien Grall
2018-11-02 21:15     ` Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 12/25] xen/arm: refactor construct_dom0 Stefano Stabellini
2018-10-30 16:32   ` Julien Grall
2018-10-23  2:02 ` [PATCH v5 13/25] xen/arm: move unregister_init_virtual_region to init_done Stefano Stabellini
2018-10-30 16:33   ` Julien Grall
2018-10-23  2:02 ` [PATCH v5 14/25] xen/arm: introduce create_domUs Stefano Stabellini
2018-10-30 16:38   ` Julien Grall
2018-10-23  2:02 ` [PATCH v5 15/25] xen/arm: implement construct_domU Stefano Stabellini
2018-10-30 20:56   ` Julien Grall
2018-10-23  2:02 ` [PATCH v5 16/25] xen/arm: generate a simple device tree for domUs Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 17/25] xen/arm: make set_interrupt_ppi able to handle non-PPI Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 18/25] xen/arm: generate vpl011 node on device tree for domU Stefano Stabellini
2018-10-30 20:58   ` Julien Grall
2018-10-23  2:02 ` [PATCH v5 19/25] xen/arm: introduce a union in vpl011 Stefano Stabellini
2018-10-23  2:02 ` [PATCH v5 20/25] xen/arm: refactor vpl011_data_avail Stefano Stabellini
2018-10-23  2:03 ` Stefano Stabellini [this message]
2018-10-24 14:55   ` [PATCH v5 21/25] xen: support console_switching between Dom0 and DomUs on ARM Oleksandr Andrushchenko
2018-10-29 20:00     ` Stefano Stabellini
2018-10-29 20:01       ` Julien Grall
2018-10-26 14:29   ` Jan Beulich
2018-10-29 19:56     ` Stefano Stabellini
2018-10-23  2:03 ` [PATCH v5 22/25] xen/arm: Allow vpl011 to be used by DomU Stefano Stabellini
2018-10-24 17:14   ` Oleksandr Tyshchenko
2018-10-29 20:03     ` Stefano Stabellini
2018-10-30 11:04       ` Oleksandr Tyshchenko
2018-10-23  2:03 ` [PATCH v5 23/25] xen/vpl011: buffer out chars when the backend is xen Stefano Stabellini
2018-10-24 14:46   ` Oleksandr Andrushchenko
2018-10-29 20:09     ` Stefano Stabellini
2018-10-31 13:27   ` Julien Grall
2018-10-23  2:03 ` [PATCH v5 24/25] xen/arm: move kernel.h to asm-arm/ Stefano Stabellini
2018-10-31 13:28   ` Julien Grall
2018-10-23  2:03 ` [PATCH v5 25/25] xen/arm: split domain_build.c Stefano Stabellini
2018-10-31 13:44   ` Julien Grall
2018-11-01 20:37     ` Stefano Stabellini

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=1540260184-11294-21-git-send-email-sstabellini@kernel.org \
    --to=sstabellini@kernel.org \
    --cc=Achin.Gupta@arm.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=andrii_anisov@epam.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=stefanos@xilinx.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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.