All of lore.kernel.org
 help / color / mirror / Atom feed
From: dmkhn@proton.me
To: Anthony PERARD <anthony@xenproject.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,
	sstabellini@kernel.org, dmukhin@ford.com
Subject: Re: [PATCH v4 6/8] tools/xl: enable NS16550-compatible UART emulator for HVM (x86)
Date: Tue, 26 Aug 2025 09:26:46 +0000	[thread overview]
Message-ID: <aK190s5IAscTuJlr@kraken> (raw)
In-Reply-To: <aKx4FtlhAbXxtZlB@l14>

On Mon, Aug 25, 2025 at 04:49:58PM +0200, Anthony PERARD wrote:
> On Thu, Jul 31, 2025 at 07:22:12PM +0000, dmkhn@proton.me wrote:
> > diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in
> > index 5362fb0e9a6f..e1d012274eaf 100644
> > --- a/docs/man/xl.cfg.5.pod.in
> > +++ b/docs/man/xl.cfg.5.pod.in
> > @@ -3032,14 +3032,17 @@ the domain was created.
> >  This requires hardware compatibility with the requested version, either
> >  natively or via hardware backwards compatibility support.
> >
> > -=item B<vuart="uart">
> > +=item B<vuart=[ "sbsa_uart", "ns16550" ]>
> 
> This syntax here would inditace that `vuart` takes a list of items. You
> could write instead:
> 
>     vuart="UART"
> 
> which seems more in line with the rest of the man page. Then you can add
> some thing like "with UART been one of "sbsa_uart" or "ns16550". It's
> possible to also have a sublist, like the `tee` option have.

OK, will do.

> 
> 
> >  To enable vuart console, user must specify the following option in the
> > -VM config file:
> > +VM config file, e.g:
> >
> > +```
> 
> This file isn't in markdown, it's in perlpod.

Whoops, muscle memory. Thanks.

> 
> >  vuart = "sbsa_uart"
> > +```
> >
> > -Currently, only the "sbsa_uart" model is supported for ARM.
> > +Currently, "sbsa_uart" (ARM) and "ns16550" (x86) are the only supported
> > +UART models.
> >
> >  =back
> >
> > diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c
> > index 4a19a8d22bdf..f4721b24763c 100644
> > --- a/tools/libs/light/libxl_arm.c
> > +++ b/tools/libs/light/libxl_arm.c
> > @@ -92,14 +92,26 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
> >      uint32_t virtio_mmio_irq = GUEST_VIRTIO_MMIO_SPI_FIRST;
> >      int rc;
> >
> > -    /*
> > -     * If pl011 vuart is enabled then increment the nr_spis to allow allocation
> > -     * of SPI VIRQ for pl011.
> > -     */
> > -    if (d_config->b_info.arch_arm.vuart == LIBXL_VUART_TYPE_SBSA_UART) {
> > +    switch ( d_config->b_info.vuart )
> > +    {
> > +    case LIBXL_VUART_TYPE_SBSA_UART:
> > +        /*
> > +         * If pl011 vuart is enabled then increment the nr_spis to allow
> > +         * allocation of SPI VIRQ for pl011.
> > +         */
> >          nr_spis += (GUEST_VPL011_SPI - 32) + 1;
> >          vuart_irq = GUEST_VPL011_SPI;
> >          vuart_enabled = true;
> > +        break;
> > +
> > +    case LIBXL_VUART_TYPE_NS16550:
> > +        LOG(ERROR, "unsupported UART emulator %d\n", d_config->b_info.vuart);
> 
> This seems too late in libxl.  I think checking if the config value is
> correct could be done in one of the *_setdefault() like many other
> config check are done. There's
> libxl__arch_domain_build_info_setdefault() that could be used.

Thanks for the pointer.

> 
> > +        abort();
> > +        break;
> > +
> > +    case LIBXL_VUART_TYPE_UNKNOWN:
> > +    default:
> > +        break;
> >      }
> >
> >      for (i = 0; i < d_config->num_disks; i++) {
> > diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl
> > index fe251649f346..fd60c2b26764 100644
> > --- a/tools/libs/light/libxl_types.idl
> > +++ b/tools/libs/light/libxl_types.idl
> > @@ -276,6 +276,7 @@ libxl_checkpointed_stream = Enumeration("checkpointed_stream", [
> >  libxl_vuart_type = Enumeration("vuart_type", [
> >      (0, "unknown"),
> >      (1, "sbsa_uart"),
> > +    (2, "ns16550"),
> >      ])
> >
> >  libxl_vkb_backend = Enumeration("vkb_backend", [
> > @@ -722,7 +723,6 @@ libxl_domain_build_info = Struct("domain_build_info",[
> >
> >
> >      ("arch_arm", Struct(None, [("gic_version", libxl_gic_version),
> > -                               ("vuart", libxl_vuart_type),
> 
> arch_arm.vuart is part of libxl's API, it can't be removed. There's some
> explanation about "libxl API compatibility" at the top of "libxl.h".
> But for this change, you could add `vuart` to `arch_x86`, or if you want
> to add `vuart` at the root like you did, you'll need to check that both
> `arch_arm.vuart` and `vuart` aren't set at the same time, and have one
> of the *_setdefault() function do the work of migrating the option.
> 
> You'll need also a LIBXL_HAVE_* macro in libxl.h, probably named
> LIBXL_HAVE_VUART_NS16550.

Thanks for details, I will proceed with option 2, adding `vuart` at the root.

> 
> >                                 ("sve_vl", libxl_sve_type),
> >                                 ("nr_spis", uint32, {'init_val': 'LIBXL_NR_SPIS_DEFAULT'}),
> >                                ])),
> > @@ -739,6 +739,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
> >
> >      ("vpmu", libxl_defbool),
> >      ("trap_unmapped_accesses", libxl_defbool),
> > +    ("vuart", libxl_vuart_type),
> >
> >      ], dir=DIR_IN,
> >         copy_deprecated_fn="libxl__domain_build_info_copy_deprecated",
> > diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c
> > index 60d4e8661c93..0f039ca65a88 100644
> > --- a/tools/libs/light/libxl_x86.c
> > +++ b/tools/libs/light/libxl_x86.c
> > @@ -2,6 +2,45 @@
> >  #include "libxl_arch.h"
> >  #include <xen/arch-x86/cpuid.h>
> >
> > +static void libxl__arch_domain_vuart_assert(
> > +    libxl__gc *gc,
> > +    libxl_domain_config *d_config,
> > +    struct xen_domctl_createdomain *config)
> > +{
> > +    LOG(ERROR, "unsupported UART emulator %d\n", d_config->b_info.vuart);
> > +    abort();
> 
> The name of the function is wrong. It doens't assert anything, and just
> abort...
> I don't think this function is useful.

Yeah, I mostly added it to avoid typing the same error message several times. 
Will remove.

> 
> Also, don't abort() for configuration error, you need to return an error
> instead.

Ack.

> 
> > +}
> > +
> > +static void libxl__arch_domain_vuart_unsupported(
> > +    libxl__gc *gc,
> > +    libxl_domain_config *d_config,
> > +    struct xen_domctl_createdomain *config)
> > +{
> > +    if ( d_config->b_info.vuart != LIBXL_VUART_TYPE_UNKNOWN )
> > +        libxl__arch_domain_vuart_assert(gc, d_config, config);
> 
> This function have also a bad name, it doesn't check if a uart is
> unsupported.

Will rework.

> 
> > +}
> > +
> > +static void libxl__arch_domain_vuart_enable(
> > +    libxl__gc *gc,
> > +    libxl_domain_config *d_config,
> > +    struct xen_domctl_createdomain *config)
> > +{
> > +    switch ( d_config->b_info.vuart )
> > +    {
> > +    case LIBXL_VUART_TYPE_SBSA_UART:
> > +        libxl__arch_domain_vuart_assert(gc, d_config, config);
> > +        break;
> > +
> > +    case LIBXL_VUART_TYPE_NS16550:
> > +        config->arch.emulation_flags |= XEN_X86_EMU_NS16550;
> > +        break;
> > +
> > +    case LIBXL_VUART_TYPE_UNKNOWN:
> > +    default:
> > +        break;
> > +    }
> > +}
> > +
> >  int libxl__arch_domain_prepare_config(libxl__gc *gc,
> >                                        libxl_domain_config *d_config,
> >                                        struct xen_domctl_createdomain *config)
> > @@ -9,14 +48,17 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
> >      switch(d_config->c_info.type) {
> >      case LIBXL_DOMAIN_TYPE_HVM:
> >          config->arch.emulation_flags = (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI);
> > +        libxl__arch_domain_vuart_enable(gc, d_config, config);
> >          if (!libxl_defbool_val(d_config->b_info.u.hvm.pirq))
> >              config->arch.emulation_flags &= ~XEN_X86_EMU_USE_PIRQ;
> >          break;
> >      case LIBXL_DOMAIN_TYPE_PVH:
> >          config->arch.emulation_flags = XEN_X86_EMU_LAPIC;
> > +        libxl__arch_domain_vuart_unsupported(gc, d_config, config);
> >          break;
> >      case LIBXL_DOMAIN_TYPE_PV:
> >          config->arch.emulation_flags = 0;
> > +        libxl__arch_domain_vuart_unsupported(gc, d_config, config);
> >          break;
> >      default:
> >          abort();
> 
> Thanks,

Thanks for review!

--
Denis

> 
> --
> Anthony PERARD



  parent reply	other threads:[~2025-08-26  9:27 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-31 19:21 [PATCH v4 0/8] x86: introduce NS16550-compatible UART emulator dmkhn
2025-07-31 19:21 ` [PATCH v4 1/8] xen/domain: introduce common emulation flags dmkhn
2025-08-04  9:46   ` Jan Beulich
2025-08-05  0:54     ` dmkhn
2025-08-06 13:56       ` Roger Pau Monné
2025-08-07 17:54         ` dmkhn
2025-08-07 14:28       ` Oleksii Kurochko
2025-08-07 17:43         ` dmkhn
2025-07-31 19:21 ` [PATCH v4 2/8] emul/vuart: introduce framework for UART emulators dmkhn
2025-08-01  0:08   ` Stefano Stabellini
2025-08-01  2:54     ` dmkhn
2025-08-04 10:11   ` Jan Beulich
2025-08-09 18:55     ` dmkhn
2025-08-11  7:34       ` Jan Beulich
2025-08-11 23:55         ` dmkhn
2025-08-12  6:52           ` Jan Beulich
2025-08-14  6:32             ` dmkhn
2025-08-06 14:24   ` Roger Pau Monné
2025-08-07 19:12     ` dmkhn
2025-07-31 19:21 ` [PATCH v4 3/8] x86/domain: allocate d->{iomem,irq}_caps before arch-specific initialization dmkhn
2025-07-31 19:52   ` Grygorii Strashko
2025-07-31 20:21     ` dmkhn
2025-08-01  2:57       ` dmkhn
2025-07-31 23:20   ` Stefano Stabellini
2025-08-04 10:20   ` Jan Beulich
2025-08-07 18:59     ` dmkhn
2025-08-06 14:37   ` Roger Pau Monné
2025-08-07 18:57     ` dmkhn
2025-07-31 19:22 ` [PATCH v4 4/8] xen/8250-uart: update definitions dmkhn
2025-07-31 23:23   ` Stefano Stabellini
2025-08-04 10:23   ` Jan Beulich
2025-08-07 19:41     ` dmkhn
2025-07-31 19:22 ` [PATCH v4 5/8] emul/vuart-ns16550: introduce NS16550-compatible UART emulator (x86) dmkhn
2025-07-31 23:57   ` Stefano Stabellini
2025-08-01  3:28     ` dmkhn
2025-08-04 10:53   ` Jan Beulich
2025-08-09 18:37     ` dmkhn
2025-08-11  7:39       ` Jan Beulich
2025-08-12  0:06         ` dmkhn
2025-08-06 15:06   ` Roger Pau Monné
2025-08-06 17:24     ` Roger Pau Monné
2025-08-07 18:49     ` dmkhn
2025-07-31 19:22 ` [PATCH v4 6/8] tools/xl: enable NS16550-compatible UART emulator for HVM (x86) dmkhn
2025-08-04 10:54   ` Jan Beulich
2025-08-06 15:21   ` Roger Pau Monné
2025-08-25 14:49   ` Anthony PERARD
2025-08-25 15:03     ` Jan Beulich
2025-08-25 15:13       ` Anthony PERARD
2025-08-25 15:27         ` Jan Beulich
2025-08-25 15:39           ` Anthony PERARD
2025-08-25 15:45             ` Jan Beulich
2025-08-26  9:26     ` dmkhn [this message]
2025-07-31 19:22 ` [PATCH v4 7/8] tools/xl: enable NS16550-compatible UART emulator for PVH (x86) dmkhn
2025-08-01  0:46   ` Stefano Stabellini
2025-08-01  1:53     ` dmkhn
2025-08-04 11:06   ` Jan Beulich
2025-08-07 19:38     ` dmkhn
2025-07-31 19:22 ` [PATCH v4 8/8] emul/vuart: introduce console forwarding enforcement via vUART dmkhn
2025-08-01  0:10   ` Stefano Stabellini
2025-08-01  1:51     ` dmkhn
2025-08-06 13:48 ` [PATCH v4 0/8] x86: introduce NS16550-compatible UART emulator Roger Pau Monné

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=aK190s5IAscTuJlr@kraken \
    --to=dmkhn@proton.me \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=anthony@xenproject.org \
    --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.