All of lore.kernel.org
 help / color / mirror / Atom feed
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 v4 7/8] tools/xl: enable NS16550-compatible UART emulator for PVH (x86)
Date: Fri, 01 Aug 2025 01:53:15 +0000	[thread overview]
Message-ID: <aIweBxdXJ3Rt2UO5@kraken> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2507311745340.468590@ubuntu-linux-20-04-desktop>

On Thu, Jul 31, 2025 at 05:46:37PM -0700, Stefano Stabellini wrote:
> On Thu, 31 Jul 2025, dmkhn@proton.me wrote:
> > From: Denis Mukhin <dmukhin@ford.com>
> >
> > Enable virtual NS16550 for PVH domains in xl.
> >
> > {map,unmap}_domain_emuirq_pirq() infrastructure is modified by adding new
> > type of interrupt resources 'IRQ_EMU' which means 'emulated device IRQ'
> > (similarly to IRQ_MSI_EMU).
> >
> > This is necessary to for IOAPIC emulation code to skip IRQ->PIRQ mapping
> > (vioapic_hwdom_map_gsi()) when guest OS unmasks vIOAPIC pin corresponding to
> > virtual device's IRQ.
> >
> > Also, hvm_gsi_eoi() is modified to trigger assertion in hvm_gsi_deassert()
> > path for ISA IRQs.
> >
> > Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> > ---
> > Changes since v3:
> > - new patch
> > ---
> >  tools/libs/light/libxl_x86.c          |  2 +-
> >  xen/arch/x86/domain.c                 |  2 ++
> >  xen/arch/x86/hvm/vioapic.c            | 10 ++++++++++
> >  xen/arch/x86/include/asm/irq.h        |  1 +
> >  xen/common/emul/vuart/vuart-ns16550.c | 27 +++++++++++++++++++++++++--
> >  xen/drivers/passthrough/x86/hvm.c     |  9 ++++-----
> >  6 files changed, 43 insertions(+), 8 deletions(-)
> >
> > diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c
> > index 0f039ca65a88..a40647c06cb9 100644
> > --- a/tools/libs/light/libxl_x86.c
> > +++ b/tools/libs/light/libxl_x86.c
> > @@ -54,7 +54,7 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
> >          break;
> >      case LIBXL_DOMAIN_TYPE_PVH:
> >          config->arch.emulation_flags = XEN_X86_EMU_LAPIC;
> > -        libxl__arch_domain_vuart_unsupported(gc, d_config, config);
> > +        libxl__arch_domain_vuart_enable(gc, d_config, config);
> >          break;
> >      case LIBXL_DOMAIN_TYPE_PV:
> >          config->arch.emulation_flags = 0;
> > diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> > index 6a010a509a60..39b0c0b199b9 100644
> > --- a/xen/arch/x86/domain.c
> > +++ b/xen/arch/x86/domain.c
> > @@ -769,12 +769,14 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
> >          {
> >              .caps   = CAP_HVM | CAP_HWDOM,
> >              .min    = X86_EMU_LAPIC | X86_EMU_IOAPIC | X86_EMU_VPCI,
> > +            .opt    = X86_EMU_NS16550,
> >          },
> >
> >          /* PVH domU */
> >          {
> >              .caps   = CAP_HVM | CAP_DOMU,
> >              .min    = X86_EMU_LAPIC,
> > +            .opt    = X86_EMU_NS16550,
> >          },
> >
> >          /* HVM domU */
> > diff --git a/xen/arch/x86/hvm/vioapic.c b/xen/arch/x86/hvm/vioapic.c
> > index 7c725f9e471f..86fe3aa4a201 100644
> > --- a/xen/arch/x86/hvm/vioapic.c
> > +++ b/xen/arch/x86/hvm/vioapic.c
> > @@ -177,6 +177,16 @@ static int vioapic_hwdom_map_gsi(unsigned int gsi, unsigned int trig,
> >
> >      ASSERT(is_hardware_domain(currd));
> >
> > +    /*
> > +     * Interrupt is claimed by one of the platform virtual devices (e.g.
> > +     * NS16550); do nothing.
> > +     */
> > +    read_lock(&currd->event_lock);
> > +    ret = domain_pirq_to_emuirq(currd, gsi);
> > +    read_unlock(&currd->event_lock);
> > +    if ( ret != IRQ_UNBOUND )
> > +        return 0;
> > +
> >      /* Interrupt has been unmasked, bind it now. */
> >      ret = mp_register_gsi(gsi, trig, pol);
> >      if ( ret == -EEXIST )
> > diff --git a/xen/arch/x86/include/asm/irq.h b/xen/arch/x86/include/asm/irq.h
> > index 8c81f66434a8..731d2bbbb1b4 100644
> > --- a/xen/arch/x86/include/asm/irq.h
> > +++ b/xen/arch/x86/include/asm/irq.h
> > @@ -221,6 +221,7 @@ void cleanup_domain_irq_mapping(struct domain *d);
> >  #define IRQ_UNBOUND (-1)
> >  #define IRQ_PT      (-2)
> >  #define IRQ_MSI_EMU (-3)
> > +#define IRQ_EMU     (-4)
> >
> >  bool cpu_has_pending_apic_eoi(void);
> >
> > diff --git a/xen/common/emul/vuart/vuart-ns16550.c b/xen/common/emul/vuart/vuart-ns16550.c
> > index 48bbf58264fe..9ec9aed2c594 100644
> > --- a/xen/common/emul/vuart/vuart-ns16550.c
> > +++ b/xen/common/emul/vuart/vuart-ns16550.c
> > @@ -355,7 +355,9 @@ static void ns16550_irq_assert(const struct vuart_ns16550 *vdev)
> >      struct domain *d = vdev->owner;
> >      int vector;
> >
> > -    if ( has_vpic(d) ) /* HVM */
> > +    if ( has_vioapic(d) && !has_vpic(d) ) /* PVH */
> > +        vector = hvm_ioapic_assert(d, vdev->irq, false);
> > +    else if ( has_vpic(d) ) /* HVM */
> >          vector = hvm_isa_irq_assert(d, vdev->irq, vioapic_get_vector);
> >      else
> >          ASSERT_UNREACHABLE();
> > @@ -367,7 +369,9 @@ static void ns16550_irq_deassert(const struct vuart_ns16550 *vdev)
> >  {
> >      struct domain *d = vdev->owner;
> >
> > -    if ( has_vpic(d) ) /* HVM */
> > +    if ( has_vioapic(d) && !has_vpic(d) ) /* PVH */
> > +        hvm_ioapic_deassert(d, vdev->irq);
> > +    else if ( has_vpic(d) ) /* HVM */
> >          hvm_isa_irq_deassert(d, vdev->irq);
> >      else
> >          ASSERT_UNREACHABLE();
> > @@ -889,6 +893,17 @@ static int cf_check ns16550_init(struct domain *d,
> >                  return rc;
> >              }
> >
> > +            /* Claim virtual IRQ */
> > +            write_lock(&d->event_lock);
> > +            rc = map_domain_emuirq_pirq(d, r->addr, IRQ_EMU);
> > +            write_unlock(&d->event_lock);
> > +            if ( rc )
> > +            {
> > +                pr_err("%s: virtual IRQ#%"PRIu64": cannot claim: %d\n",
> > +                        desc->name, r->addr, rc);
> > +                return rc;
> > +            }
> > +
> >              vdev->irq = r->addr;
> >          }
> >          else
> > @@ -919,12 +934,20 @@ static int cf_check ns16550_init(struct domain *d,
> >  static void cf_check ns16550_deinit(struct domain *d)
> >  {
> >      struct vuart_ns16550 *vdev = d->arch.hvm.vuart;
> > +    int rc;
> >
> >      if ( !vdev )
> >          return;
> >
> >      spin_lock(&vdev->lock);
> >
> > +    rc = unmap_domain_pirq_emuirq(vdev->owner, vdev->irq);
> > +    if ( rc )
> > +    {
> > +        pr_err("%s: virtual IRQ#%d: cannot unclaim: %d\n",
> > +                vdev->name, vdev->irq, rc);
> > +    }
> 
> write_lock(&d->event_lock); ?

Thanks

> 
> 
> >      ns16550_fifo_tx_flush(vdev);
> >
> >      spin_unlock(&vdev->lock);
> > diff --git a/xen/drivers/passthrough/x86/hvm.c b/xen/drivers/passthrough/x86/hvm.c
> > index a2ca7e0e570c..22905cd86f95 100644
> > --- a/xen/drivers/passthrough/x86/hvm.c
> > +++ b/xen/drivers/passthrough/x86/hvm.c
> > @@ -924,12 +924,11 @@ static void hvm_gsi_eoi(struct domain *d, unsigned int gsi)
> >  {
> >      struct pirq *pirq = pirq_info(d, gsi);
> >
> > -    /* Check if GSI is actually mapped. */
> > -    if ( !pirq_dpci(pirq) )
> > -        return;
> > -
> >      hvm_gsi_deassert(d, gsi);
> > -    hvm_pirq_eoi(pirq);
> > +
> > +    /* Check if GSI is actually mapped. */
> > +    if ( pirq_dpci(pirq) )
> > +        hvm_pirq_eoi(pirq);
> >  }
> >
> >  static int cf_check _hvm_dpci_isairq_eoi(
> > --
> > 2.34.1
> >
> >



  reply	other threads:[~2025-08-01  1:53 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
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 [this message]
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=aIweBxdXJ3Rt2UO5@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.