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 23/35] xen/console: introduce console_write()
Date: Thu, 12 Dec 2024 13:04:40 +0100	[thread overview]
Message-ID: <Z1rRWAWzC1pnD3PW@macbook.local> (raw)
In-Reply-To: <20241205-vuart-ns8250-v1-23-e9aa923127eb@ford.com>

On Thu, Dec 05, 2024 at 08:41:53PM -0800, Denis Mukhin via B4 Relay wrote:
> From: Denis Mukhin <dmukhin@ford.com>
> 
> PV Linux kernel uses HYPERVISOR_console_io hypercall for early console which
> ends up being handled by Xen's console driver's guest_console_write().
> 
> guest_console_write() duplicates the code from __putstr(), elimitate code
> duplication.

It might be better to split the code that unifies
guest_console_write() and __putstr() as a non-functional change.
While the introduction of use_conring is likely a functional change.

> Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> ---
>  xen/drivers/char/console.c | 97 +++++++++++++++++++++++++---------------------
>  1 file changed, 53 insertions(+), 44 deletions(-)
> 
> diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
> index ce3639a4cdcda00ea63e3bf119bc3b242cbfdf6a..115967d179998cba4a81578caba09db4e4aca7f7 100644
> --- a/xen/drivers/char/console.c
> +++ b/xen/drivers/char/console.c
> @@ -63,6 +63,8 @@ static const char __initconst warning_sync_console[] =
>      "However it can introduce SIGNIFICANT latencies and affect\n"
>      "timekeeping. It is NOT recommended for production use!\n";
>  
> +/* Flag: use conring for early console; switches to opt_console_to_ring */
> +static bool __read_mostly use_conring = true;

__ro_after_init instead of __read_mostly.

>  /* console_to_ring: send guest (incl. dom 0) console data to console ring. */
>  static bool __read_mostly opt_console_to_ring;
>  boolean_param("console_to_ring", opt_console_to_ring);
> @@ -661,6 +663,16 @@ static void cf_check notify_dom0_con_ring(void *unused)
>  static DECLARE_SOFTIRQ_TASKLET(notify_dom0_con_ring_tasklet,
>                                 notify_dom0_con_ring, NULL);
>  
> +static bool console_locks_busted;
> +
> +static void conring_write(const char *str, size_t len)
> +{
> +    conring_puts(str, len);
> +
> +    if ( !console_locks_busted )
> +        tasklet_schedule(&notify_dom0_con_ring_tasklet);
> +}
> +
>  #ifdef CONFIG_X86
>  static inline void xen_console_write_debug_port(const char *buf, size_t len)
>  {
> @@ -669,8 +681,44 @@ static inline void xen_console_write_debug_port(const char *buf, size_t len)
>                     : "=&S" (tmp), "=&c" (tmp)
>                     : "0" (buf), "1" (len), "d" (XEN_HVM_DEBUGCONS_IOPORT) );
>  }
> +
> +static void xen_console_write(const char *str, size_t len)
> +{
> +    if ( xen_guest )
> +        xen_hypercall_console_write(str, len);
> +    else
> +        xen_console_write_debug_port(str, len);
> +}
> +#else
> +static inline void xen_console_write(const char *str, size_t len)
> +{

opt_console_xen would only be set on x86 with the current command line
parsing done in console_init_preirq(), so you could add an
ASSERT_UNREACHABLE() here.

> +}
>  #endif
>  
> +/*
> + * Write characters to console.
> + *
> + * That will handle all possible scenarios working w/ console
> + * - serial console;
> + * - video output;
> + * - __HYPERVISOR_console_io hypercall (x86 only);
> + * - debug I/O port (x86 only);
> + * - forward to Xen event channel.

"Xen event channel" is not the correct term.  I would use "PV
console".  The event channel is just used to send the notification.

> + */
> +static void console_write(const char *str, size_t len)
> +{
> +    ASSERT(rspin_is_locked(&console_lock));
> +
> +    console_serial_puts(str, len);
> +    video_puts(str, len);
> +
> +    if ( opt_console_xen )
> +        xen_console_write(str, len);

Are you sure this builds?  opt_console_xen is only defined on x86, and
AFAICT console_write() is generic.  AFAICT you need to keep the X86
preprocessor guards, or alternatively do something like:

#define opt_console_xen false

For non-x86 arches in xen/console.h

> +
> +    if ( use_conring )
> +        conring_write(str, len);
> +}
> +
>  static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,
>                                  unsigned int count)
>  {
> @@ -691,28 +739,8 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,
>  
>          if ( is_hardware_domain(cd) )
>          {
> -            /* Use direct console output as it could be interactive */
>              nrspin_lock_irq(&console_lock);
> -
> -            console_serial_puts(kbuf, kcount);
> -            video_puts(kbuf, kcount);
> -
> -#ifdef CONFIG_X86
> -            if ( opt_console_xen )
> -            {
> -                if ( xen_guest )
> -                    xen_hypercall_console_write(kbuf, kcount);
> -                else
> -                    xen_console_write_debug_port(kbuf, kcount);
> -            }
> -#endif
> -
> -            if ( opt_console_to_ring )
> -            {
> -                conring_puts(kbuf, kcount);
> -                tasklet_schedule(&notify_dom0_con_ring_tasklet);
> -            }
> -
> +            console_write(kbuf, kcount);
>              nrspin_unlock_irq(&console_lock);
>          }
>          else
> @@ -813,31 +841,9 @@ long do_console_io(
>   * *****************************************************
>   */
>  
> -static bool console_locks_busted;
> -
>  static void __putstr(const char *str)
>  {
> -    size_t len = strlen(str);
> -
> -    ASSERT(rspin_is_locked(&console_lock));
> -
> -    console_serial_puts(str, len);
> -    video_puts(str, len);
> -
> -#ifdef CONFIG_X86
> -    if ( opt_console_xen )
> -    {
> -        if ( xen_guest )
> -            xen_hypercall_console_write(str, len);
> -        else
> -            xen_console_write_debug_port(str, len);
> -    }
> -#endif
> -
> -    conring_puts(str, len);
> -
> -    if ( !console_locks_busted )
> -        tasklet_schedule(&notify_dom0_con_ring_tasklet);
> +    console_write(str, strlen(str));
>  }
>  
>  static int printk_prefix_check(char *p, char **pp)
> @@ -1171,6 +1177,9 @@ void __init console_endboot(void)
>  
>      video_endboot();
>  
> +    use_conring = opt_console_to_ring;
> +    smp_wmb();

Do you really need the barrier?  If so it would need a comment
describing exactly why it's needed.  I don't think it's possible for
the write to be reordered past the return of the function, which would
be enough to ensure correctness?

Thanks, Roger.


  reply	other threads:[~2024-12-12 12:05 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é
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é [this message]
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=Z1rRWAWzC1pnD3PW@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.