All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: dmukhin@ford.com, xen-devel@lists.xenproject.org
Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech,
	jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com,
	roger@xenproject.org, sstabellini@kernel.org,
	xakep.amatop@gmail.com, dmukhin@xen.org
Subject: Re: [PATCH v8 13/26] emul/ns16550: implement dump_state() hook
Date: Thu, 19 Nov 2026 20:43:30 +0100	[thread overview]
Message-ID: <51da3b24-58e1-4f16-af4e-c813531a7b8c@gmail.com> (raw)
In-Reply-To: <20261111194800.1070016-14-dmukhin@ford.com>



On 11/11/26 8:47 PM, dmukhin@ford.com wrote:
> From: Denis Mukhin <dmukhin@ford.com>

At the commit subject:

Nit: emul/ns16x50: like the rest of the series.

> 
> Implement dump_state() vUART hook for debugging UART state machine over
> Xen console. dump_state() prints state of all emulated registers
> (including state-less IIR) and state of RX/TX FIFOs.
> 
> Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> ---
>   xen/common/emul/vuart/ns16x50.c | 64 ++++++++++++++++++++++++++++++++-
>   1 file changed, 63 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/common/emul/vuart/ns16x50.c b/xen/common/emul/vuart/ns16x50.c
> index 404e12311090..cda21c15cf78 100644
> --- a/xen/common/emul/vuart/ns16x50.c
> +++ b/xen/common/emul/vuart/ns16x50.c
> @@ -728,6 +728,62 @@ static int ns16x50_io_read(
>       return rc;
>   }
>   
> +static void cf_check ns16x50_dump_state(void *arg)
> +{
> +#ifdef CONFIG_VUART_NS16X50_DEBUG

With the whole body under CONFIG_VUART_NS16X50_DEBUG, the 'q'
keyhandler prints nothing for the vUART on a normal build, which is
where a state dump is most useful. The function doesn't cost anything
until someone presses 'q'; I'd drop the #ifdef (or, if it must stay,
leave .dump_state NULL instead of registering an empty hook).

> +    struct vuart_ns16x50 *vdev = arg;
> +    const struct domain *d;
> +    const struct vuart_info *info;
> +    const struct xencons_interface *cons;
> +    const uint8_t *regs;
> +    const char *as = (info->base_type & IORESOURCE_IO) ? "ioport":
> +                                                         "iomem";

As mentioned in my reply to the cover letter, info is used before it
is assigned; gcc rejects this with -Werror=uninitialized, so the series
doesn't build with CONFIG_VUART_NS16X50_DEBUG=y. Computing as after
info = vdev->info fixes it.

> +    unsigned long flags;
> +
> +    ASSERT(vdev);
> +
> +    /* Allow printing state in case of a deadlock. */
> +    if ( !ns16x50_trylock(vdev, &flags) )
> +        return;
> +
> +    d = vdev->owner;
> +    info = vdev->info;
> +    cons = &vdev->cons;
> +    regs = &vdev->regs[0];
> +
> +    printk("Virtual " pr_prefix " (%s) %s %#"PRIx64" IRQ#%d owner %pd\n",
> +            vdev->name, as, info->base_addr, info->irq, d);

Nits on the format strings: PRIpaddr for base_addr, %u for irq and the
XENCONS_RING_IDX values, %zu for ARRAY_SIZE(), and PRIx8 for UART_RBR
and friends, which are plain ints. Also the continuation lines are
indented one column too far.

> +
> +    printk("  RX FIFO size %ld in_prod %d in_cons %d used %d\n",
> +            ARRAY_SIZE(cons->in), cons->in_prod, cons->in_cons,
> +            cons->in_prod - cons->in_cons);
> +
> +    printk("  TX FIFO size %ld out_prod %d out_cons %d used %d\n",
> +            ARRAY_SIZE(cons->out), cons->out_prod, cons->out_cons,
> +            cons->out_prod - cons->out_cons);
> +
> +    printk("  %02"PRIx8" RBR %02"PRIx8" THR %02"PRIx8" DLL %02"PRIx8" DLM %02"PRIx8"\n",
> +            UART_RBR,
> +            cons->in[MASK_XENCONS_IDX(cons->in_prod, cons->in)],
> +            cons->out[MASK_XENCONS_IDX(cons->out_prod, cons->out)],
> +            regs[NS16X50_REGS_NUM + UART_DLL],
> +            regs[NS16X50_REGS_NUM + UART_DLM]);

in_prod and out_prod point at the next free slot, so these print
whatever stale byte happens to be there. For RBR, the character the
guest will read next is in[in_cons] (only meaningful if the FIFO isn't
empty); for THR, the last character written is out[out_prod - 1].

> +
> +    printk("  %02"PRIx8" IER %02"PRIx8"\n", UART_IER, regs[UART_IER]);
> +
> +    printk("  %02"PRIx8" FCR %02"PRIx8" IIR %02"PRIx8"\n",
> +            UART_FCR, regs[UART_FCR], ns16x50_iir_get(vdev));
> +
> +    printk("  %02"PRIx8" LCR %02"PRIx8"\n", UART_LCR, regs[UART_LCR]);
> +    printk("  %02"PRIx8" MCR %02"PRIx8"\n", UART_MCR, regs[UART_MCR]);
> +    printk("  %02"PRIx8" LSR %02"PRIx8"\n", UART_LSR, regs[UART_LSR]);
> +    printk("  %02"PRIx8" MSR %02"PRIx8"\n", UART_MSR, regs[UART_MSR]);
> +    printk("  %02"PRIx8" SCR %02"PRIx8"\n", UART_SCR, regs[UART_SCR]);
> +
> +    ns16x50_unlock(vdev, &flags);
> +#endif /* CONFIG_VUART_NS16X50_DEBUG */
> +}
> +
>   static void ns16x50_access(int dir, unsigned int type,
>                              unsigned long addr, unsigned int size,
>                              uint32_t *data)
> @@ -794,6 +850,9 @@ static void ns16x50_access(int dir, unsigned int type,
>           rc = ns16x50_io_read(vdev, reg, size, data);
>   
>   
> +    if ( ns16x50_log_level >= 3 )
> +        ns16x50_dump_state(vdev);

ns16x50_log_level is at most 2, so this never runs (see 04/26). If it
did, it would run with vdev->lock held, so the trylock in
ns16x50_dump_state() would fail and print nothing. I'd drop both
call sites added here and keep dump_state() for the keyhandler only. 
Another call site is here ...

> +
>       if ( rc == 0 )
>           ns16x50_debug(vdev, "%c %s %#"PRIx64" %d: LCR=%#02x %#02x %#08x\n",
>                         op, as, addr, size, vdev->regs[UART_LCR], reg, *data);
> @@ -971,6 +1030,9 @@ static int cf_check ns16x50_put_rx(void *arg, char ch)
>   
>       ns16x50_unlock(vdev, &flags);
>   
> +    if ( ns16x50_log_level >= 3 )
> +        ns16x50_dump_state(vdev);

... ^.

> +
>       return rc;
>   }
>   
> @@ -979,7 +1041,7 @@ static int cf_check ns16x50_put_rx(void *arg, char ch)
>       .compatible = "ns16550",            \
>       .alloc      = ns16x50_alloc,        \
>       .free       = ns16x50_free,         \
> -    .dump_state = NULL,                 \
> +    .dump_state = ns16x50_dump_state,   \
>       .put_rx     = ns16x50_put_rx,       \
>   }
>   

~ Oleksii



  reply	other threads:[~2026-11-19 19:43 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 19:47 [PATCH v8 00/26] x86: introduce NS16550-compatible UART emulator dmukhin
2026-11-11 19:47 ` [PATCH v8 01/26] emul/vuart: introduce framework for UART emulators dmukhin
2026-11-12 15:35   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 02/26] xen/8250-uart: update definitions dmukhin
2026-11-12 14:49   ` Jan Beulich
2026-11-12 16:34   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 03/26] x86: fixup dependencies for asm/x86_emulate.h dmukhin
2026-11-12 20:25   ` Oleksii Kurochko
2026-11-13  7:20     ` Jan Beulich
2026-11-11 19:47 ` [PATCH v8 04/26] emul/ns16x50: implement emulator stub dmukhin
2026-11-13 11:48   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 05/26] emul/ns16x50: implement DLL/DLM registers dmukhin
2026-11-11 19:47 ` [PATCH v8 06/26] emul/ns16x50: implement SCR register dmukhin
2026-11-16 10:42   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 07/26] emul/ns16x50: implement IER/IIR registers dmukhin
2026-11-16 16:59   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 08/26] emul/ns16x50: implement LCR/LSR registers dmukhin
2026-11-17 16:33   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 09/26] emul/ns16x50: implement MCR/MSR registers dmukhin
2026-11-17 18:32   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 10/26] emul/ns16x50: implement RBR register dmukhin
2026-11-18 16:28   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 11/26] emul/ns16x50: implement THR register dmukhin
2026-11-19 10:22   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 12/26] emul/ns16x50: implement FCR register (write-only) dmukhin
2026-11-19 11:14   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 13/26] emul/ns16550: implement dump_state() hook dmukhin
2026-11-19 19:43   ` Oleksii Kurochko [this message]
2026-11-11 19:47 ` [PATCH v8 14/26] emul/vuart: add global UART emulator configuration knob dmukhin
2026-11-20  9:37   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 15/26] emul/ns16x50: enable emulator dmukhin
2026-11-20  9:45   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 16/26] emul/ns16x50: add Kconfig options dmukhin
2026-11-20  9:53   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 17/26] x86/domain: enable per-domain I/O port bitmaps dmukhin
2026-11-11 19:47 ` [PATCH v8 18/26] emul/ns16x50: resolve physical I/O port sharing dmukhin
2026-11-20 10:17   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 19/26] xen/domain: allocate d->irq_caps before arch-specific initialization dmukhin
2026-11-11 19:47 ` [PATCH v8 20/26] emul/ns16x50: resolve physical IRQ sharing dmukhin
2026-11-11 19:47 ` [PATCH v8 21/26] emul/ns16x50: implement IRQ emulation via vIOAPIC dmukhin
2026-11-11 19:47 ` [PATCH v8 22/26] MAINTAINERS: add myself as vUART framework maintainer dmukhin
2026-11-20 10:23   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 23/26] docs/fusa: add NS16x50 UART requirements for x86 dmukhin
2026-11-19 17:10   ` Halder, Ayan Kumar
2026-11-19 22:22     ` Stefano Stabellini
2026-11-20 11:17       ` Halder, Ayan Kumar
2026-11-20 10:26   ` Oleksii Kurochko
2026-11-20 11:16     ` Halder, Ayan Kumar
2026-11-11 19:47 ` [PATCH v8 24/26] ci: add initial NS16550-compatible XTF test dmukhin
2026-11-20 10:34   ` Oleksii Kurochko
2026-11-11 19:47 ` [PATCH v8 25/26] ci: add smoke NS16550-compatible PVH Linux test dmukhin
2026-11-11 19:48 ` [PATCH v8 26/26] ci: do not merge: test dmukhin
2026-11-12 14:53 ` [PATCH v8 00/26] x86: introduce NS16550-compatible UART emulator Oleksii Kurochko

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=51da3b24-58e1-4f16-af4e-c813531a7b8c@gmail.com \
    --to=oleksii.kurochko@gmail.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=dmukhin@ford.com \
    --cc=dmukhin@xen.org \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=roger@xenproject.org \
    --cc=sstabellini@kernel.org \
    --cc=xakep.amatop@gmail.com \
    --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.