[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v8 14/26] emul/vuart: add global UART emulator configuration knob





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

Introduce new command line setting `vuart=domid[:compatible,name]` for
configuring UART emulator per given domain.

A new command line option needs an entry in
docs/misc/xen-command-line.pandoc; I don't see one in the series.


Only one domain is supported for now.

Format:
   domid      - vUART owner domain ID
   compatible - vUART compatible string, must match with one of the
                registered emulators
   name       - vUART user-friendly name used for searching for one of
                the pre-defined guest I/O resources

compatible string and name are optional, if skipped, platform default

Is `name` really optional? Look my reply below ([A]).

values will be chosen.

Note, documentation update is not covered in this patch.

Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
---
  xen/common/emul/vuart/vuart.c | 85 +++++++++++++++++++++++++++++++++++
  1 file changed, 85 insertions(+)

diff --git a/xen/common/emul/vuart/vuart.c b/xen/common/emul/vuart/vuart.c
index bd3b756fb4d6..0df29540b1b6 100644
--- a/xen/common/emul/vuart/vuart.c
+++ b/xen/common/emul/vuart/vuart.c
@@ -6,8 +6,10 @@
#include <asm/types.h> +#include <xen/ctype.h>
  #include <xen/err.h>
  #include <xen/resource.h>
+#include <xen/param.h>

Inclusion of headers should be sorted in alphabetical order so please put xen/param.h before xen/resouce.h.

  #include <xen/sched.h>
  #include <xen/vuart.h>
  #include <xen/xvmalloc.h>
@@ -18,6 +20,89 @@
  extern const struct vuart_emulator vuart_array_start[];
  extern const struct vuart_emulator vuart_array_end[];
+static domid_t __read_mostly opt_vuart_domid = DOMID_INVALID;
+static const struct vuart_info * __read_mostly opt_vuart_info;

Only a single domain can be given a vUART, and a later vuart= silently
replaces an earlier one. If that's the intended scope, the
documentation should say so.

+
+static const struct vuart_info vuart_supported[] = {
+#define VUART(c,n,t,a,s,i) { \
+    .compatible = c, \
+    .name = n, \
+    .flags = VUART_CONSOLE_INPUT, \
+    .base_type = t, \
+    .base_addr = a, \
+    .size = s, \
+    .irq = i, \
+}
+#ifdef CONFIG_VUART_NS16X50
+        VUART("ns16550", "com1", IORESOURCE_IO, 0x3f8u, 8u, 4u),
+        VUART("ns16550", "com2", IORESOURCE_IO, 0x2f8u, 8u, 3u),
+        VUART("ns16550", "com3", IORESOURCE_IO, 0x3feu, 8u, 4u),
+        VUART("ns16550", "com4", IORESOURCE_IO, 0x2feu, 8u, 3u),
+#endif /* CONFIG_VUART_NS16X50 */

COM3 and COM4 are at 0x3e8 and 0x2e8 (e.g. Linux's
arch/x86/include/asm/serial.h). 0x3fe and 0x2fe fall inside the COM1 and
COM2 ranges (0x3fe is COM1's MSR), so a guest wouldn't find com3/com4
where it looks for them, and the emulated range would overlap the
neighbouring ports.

Also, this table describes legacy PC COM ports, i.e. it's x86-specific,
but it lives in the arch-independent framework. For the RISC-V port I
had to limit it to CONFIG_X86. Could it move to x86 code, or into ns16x50.c, with the framework only parsing the option?

+#undef VUART
+};
+
+static int __init cf_check vuart_parse_cmdline(const char *s)
+{
+    const char *compat = "ns16550";
+    size_t compat_len = strlen(compat);
+    const char *name = "com1";
+    size_t name_len = strlen(name);
+    const char *end;
+    domid_t domid;
+    unsigned int i;
+
+    /* vuart=domid:compatible,name */
+    if ( !isdigit(*s) )
+        return -EINVAL;
+
+    domid = simple_strtoul(s, &end, 0);
+    if ( domid >= DOMID_FIRST_RESERVED )
+        return -EINVAL;

The value is truncated to domid_t before the range check, so e.g.
vuart=65537 is accepted as domain 1. Also, base 0 makes vuart=010 mean
domain 8. I'd parse into an unsigned long with base 10 and check that
before assigning:

    unsigned long val = simple_strtoul(s, &end, 10);

    if ( end == s || val >= DOMID_FIRST_RESERVED )
        return -EINVAL;

    domid = val;


+
+    if ( *end == '\0' )
+        goto match_defaults;
+
+    if ( *end != ':' )
+        return -EINVAL;
+
+    compat = end + 1;
+
+    while ( *end && *end != ',' )
+        end++;
+    if ( *end != ',' )
+        return -EINVAL;

[A] So once ":compatible" is given, ",name" is mandatory: vuart=1:ns16550 is rejected. The Kconfig help in 16/26 documents
'vuart=<domid>:<compatible>[,com[1-4]]', i.e. the name as optional;
one of the two needs adjusting.

Also, the comment then should be adjusted too.

+
+    compat_len = end - compat;
+    if ( !compat_len )
+        return -EINVAL;
+
+    name = end + 1;
+    name_len = strlen(name);
+    if ( !name_len )
+        return -EINVAL;
+
+ match_defaults:
+    for ( i = 0; i < ARRAY_SIZE(vuart_supported); i++ )
+    {
+        if ( compat_len != strlen(vuart_supported[i].compatible) ||
+             strncmp(compat, vuart_supported[i].compatible, compat_len) )

Nit: this matches the compatible exactly, while vuart_match_by_compatible() (01/26) matches a prefix; it would be good
to use one rule for both.

~ Oleksii



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.