From: dmkhn@proton.me
To: Stefano Stabellini <sstabellini@kernel.org>
Cc: xen-devel@lists.xenproject.org, andrew.cooper3@citrix.com,
anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org,
michal.orzel@amd.com, roger.pau@citrix.com, dmukhin@ford.com
Subject: Re: [PATCH v1 2/3] xen/console: introduce console_puts()
Date: Mon, 28 Apr 2025 01:47:44 +0000 [thread overview]
Message-ID: <aA7ePF23LExpH9NW@kraken> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2504251545480.785180@ubuntu-linux-20-04-desktop>
On Fri, Apr 25, 2025 at 03:47:53PM -0700, Stefano Stabellini wrote:
> On Thu, 3 Apr 2025, dmkhn@proton.me wrote:
> > From: Denis Mukhin <dmukhin@ford.com>
> >
> > guest_console_write() duplicates the code from __putstr(), eliminate code
> > duplication.
> >
> > Introduce console_puts() for writing a buffer to console devices.
> >
> > Also, introduce internal console flags to control which console devices
> > should be used.
> >
> > Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> > ---
> > xen/drivers/char/console.c | 112 ++++++++++++++++++++++---------------
> > 1 file changed, 66 insertions(+), 46 deletions(-)
> >
> > diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
> > index aaa97088aa..2618c2e47d 100644
> > --- a/xen/drivers/char/console.c
> > +++ b/xen/drivers/char/console.c
> > @@ -41,6 +41,20 @@
> > #include <asm/vpl011.h>
> > #endif
> >
> > +/* Internal console flags. */
> > +enum {
> > + CONSOLE_SERIAL = BIT(0, U), /* Use serial device. */
> > + CONSOLE_PV = BIT(1, U), /* Use PV console. */
> > + CONSOLE_VIDEO = BIT(2, U), /* Use video device. */
> > + CONSOLE_DEBUG = BIT(3, U), /* Use debug device. */
> > + CONSOLE_RING = BIT(4, U), /* Use console ring. */
> > + CONSOLE_DEFAULT = CONSOLE_SERIAL | CONSOLE_PV | CONSOLE_VIDEO |
> > + CONSOLE_DEBUG,
> > + CONSOLE_ALL = CONSOLE_DEFAULT | CONSOLE_RING,
> > +};
> > +
> > +static void console_puts(const char *str, size_t len, unsigned int flags);
> > +
> > /* console: comma-separated list of console outputs. */
> > static char __initdata opt_console[30] = OPT_CONSOLE_STR;
> > string_param("console", opt_console);
> > @@ -338,8 +352,6 @@ static bool console_locks_busted;
> >
> > static void conring_puts(const char *str, size_t len)
> > {
> > - ASSERT(rspin_is_locked(&console_lock));
> > -
> > while ( len-- )
> > conring[CONRING_IDX_MASK(conringp++)] = *str++;
> >
> > @@ -432,9 +444,6 @@ void console_serial_puts(const char *s, size_t nr)
> > serial_steal_fn(s, nr);
> > else
> > serial_puts(sercon_handle, s, nr);
> > -
> > - /* Copy all serial output into PV console */
> > - pv_console_puts(s, nr);
> > }
> >
> > static void cf_check dump_console_ring_key(unsigned char key)
> > @@ -468,8 +477,7 @@ static void cf_check dump_console_ring_key(unsigned char key)
> > c += len;
> > }
> >
> > - console_serial_puts(buf, sofar);
> > - video_puts(buf, sofar);
> > + console_puts(buf, sofar, CONSOLE_SERIAL | CONSOLE_VIDEO | CONSOLE_PV);
>
> Actually I take back the R-b. It looks like this change is breaking
> because console_puts now requires the console_lock to be held, while
> here the console_lock is not held.
Yes, the locking is wrong, thanks for the catch!
Lock adjustment from Patch 3 should be moved to Patch 2 (here).
>
> If I am not mistaken if you try to use the 'w' key with this patch
> applied you'll hit the ASSERT at the beginning of console_puts
>
>
> > free_xenheap_pages(buf, order);
> > }
> > @@ -618,11 +626,61 @@ static inline void xen_console_write_debug_port(const char *buf, size_t len)
> > }
> > #endif
> >
> > +static inline void console_debug_puts(const char *str, size_t 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
> > +}
> > +
> > +/*
> > + * Write buffer to all enabled console devices.
> > + *
> > + * That will handle all possible scenarios working w/ console
> > + * - physical console (serial console, VGA console (x86 only));
> > + * - PV console;
> > + * - debug console (x86 only): debug I/O port or __HYPERVISOR_console_io
> > + * hypercall;
> > + * - console ring.
> > + */
> > +static void console_puts(const char *str, size_t len, unsigned int flags)
> > +{
> > + ASSERT(rspin_is_locked(&console_lock));
> > +
> > + if ( flags & CONSOLE_SERIAL )
> > + console_serial_puts(str, len);
> > +
> > + if ( flags & CONSOLE_PV )
> > + pv_console_puts(str, len);
> > +
> > + if ( flags & CONSOLE_VIDEO )
> > + video_puts(str, len);
> > +
> > + if ( flags & CONSOLE_DEBUG )
> > + console_debug_puts(str, len);
> > +
> > + if ( flags & CONSOLE_RING )
> > + conring_puts(str, len);
> > +}
> > +
> > +static inline void __putstr(const char *str)
> > +{
> > + console_puts(str, strlen(str), CONSOLE_ALL);
> > +}
> > +
> > static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,
> > unsigned int count)
> > {
> > char kbuf[128];
> > unsigned int kcount = 0;
> > + unsigned int flags = opt_console_to_ring
> > + ? CONSOLE_ALL : CONSOLE_DEFAULT;
> > struct domain *cd = current->domain;
> >
> > while ( count > 0 )
> > @@ -640,23 +698,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,
> > {
> > /* 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);
> > -
> > + console_puts(kbuf, kcount, flags);
> > nrspin_unlock_irq(&console_lock);
> > }
> > else
> > @@ -757,28 +799,6 @@ long do_console_io(
> > * *****************************************************
> > */
> >
> > -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);
> > -}
> > -
> > static int printk_prefix_check(char *p, char **pp)
> > {
> > int loglvl = -1;
> > --
> > 2.34.1
> >
> >
next prev parent reply other threads:[~2025-04-28 1:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-03 0:06 [PATCH v1 0/3] xen/console: few cleanups in console driver dmkhn
2025-04-03 0:06 ` [PATCH v1 1/3] xen/console: cleanup conring management dmkhn
2025-04-08 15:10 ` Jan Beulich
2025-04-25 22:18 ` Stefano Stabellini
2025-04-28 6:47 ` Jan Beulich
2025-04-28 20:10 ` dmkhn
2025-04-03 0:06 ` [PATCH v1 2/3] xen/console: introduce console_puts() dmkhn
2025-04-25 22:35 ` Stefano Stabellini
2025-04-25 22:47 ` Stefano Stabellini
2025-04-28 1:47 ` dmkhn [this message]
2025-04-03 0:06 ` [PATCH v1 3/3] xen/console: introduce conring_flush() dmkhn
2025-04-25 22:53 ` 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=aA7ePF23LExpH9NW@kraken \
--to=dmkhn@proton.me \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=dmukhin@ford.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.com \
--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.