xen/console: cleanup console input switch logic
cover xen/console: cleanup console input switch logic
Currently, on x86, console input can be rotated in round-robin manner only between dom0, PV shim, and Xen itself. On Arm the input rotation can include domUs with vpl011.
The patch series introduces the concept of "console focus", which is defined as the ID of the domain that currently owns the physical console input.
The patch series originates from the NS16550 UART emulator series [1] for x86, which requires ability to switch physical console input to a PVH/HVM domain with an emulated UART.
The main idea is introducing a per-domain permission flag that is set during domain initialization and used by the console driver to switch the input across permitted domains.
Patch 0 removes all the trailing white spaces in the console driver code.
Patch 1 introduces a new domain permission flag to mark ownership of the console input for the console driver.
Patches 2-4 prepare console driver to allow console input rotation across multiple domains based on the new permission flag.
Patches 5-6 perform mechanical renames to fit the usage in the code.
Patch 7 cleans up the console input switch logic.
Patch 8 simplifies the existing vUART code by using newly introduced APIs.
CI: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/1723361248
[1]: https://lore.kernel.org/xen-devel/[email protected]/
Denis Mukhin (8):
xen/console: fix trailing whitespaces
xen/console: introduce console input permission xen/domain: introduce domid_top
xen/domain: introduce domid_alloc()
xen/console: rename switch_serial_input() to console_switch_focus() xen/console: rename console_rx to console_focus xen/console: introduce console_set_focus()
xen/console: introduce console_get_focus()
xen/arch/arm/dom0less-build.c | 15 ++- xen/arch/arm/domain_build.c | 19 +++- xen/arch/arm/include/asm/setup.h | 2 - xen/arch/arm/setup.c | 2 - xen/arch/arm/vpl011.c | 7 +- xen/arch/ppc/include/asm/setup.h | 2 - xen/arch/riscv/include/asm/setup.h | 2 - xen/arch/x86/include/asm/setup.h | 2 - xen/arch/x86/pv/shim.c | 2 + xen/common/domain.c | 5 + xen/common/domctl.c | 71 +++++++++------ xen/common/kernel.c | 8 ++ xen/drivers/char/console.c | 142 +++++++++++++++++------------ xen/include/xen/console.h | 3 +- xen/include/xen/domain.h | 5 + xen/include/xen/sched.h | 8 +- 16 files changed, 180 insertions(+), 115 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/8 xen/console: fix trailing whitespaces
Remove trailing whitespaces in the console driver.
No functional change.
--- xen/drivers/char/console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/drivers/char/console.c +3 -3
@@ -1,8 +1,8 @@/****************************************************************************** * console.c -* +* * Emergency console I/O for Xen and the domain-0 guest OS. -* +* * Copyright (c) 2002-2004, K A Fraser. * * Added printf_ratelimit
@@ -811,7 +811,7 @@ static int printk_prefix_check(char *p, char **pp)return ((atomic_read (&print_everything) !=0 ) || (loglvl < lower_thresh) || ((loglvl < upper_thresh) &&printk_ratelimit ())); -} +} static int cf_check parse_console_timestamps(const char *s) {
Signature · 1 line
2.34.1
Re: [PATCH v1 1/8] xen/console: fix trailing whitespaces
Quoted 5 lines · On 19.03.2025 00:36, [email protected] wrote:
Remove trailing whitespaces in the console driver.
No functional change.
Signed-off-by Denis Mukhin <[email protected]>
PATCH 2/8 xen/console: introduce console input permission
In reply to [email protected]Add new flag in domain structure for marking permission to intercept the physical console input by the domain.
Update console input switch logic accordingly.
--- xen/arch/arm/vpl011.c | 2 ++ xen/arch/x86/pv/shim.c | 2 ++ xen/common/domain.c | 2 ++ xen/drivers/char/console.c | 49 +++++++++++++++++++++++++++++++++----- xen/include/xen/sched.h | 8 ++++++- 5 files changed, 56 insertions(+), 7 deletions(-)
xen/arch/arm/vpl011.c +2 -0
@@ -737,6 +737,8 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info)register_mmio_handler (d, &vpl011_mmio_handler, vpl011->base_addr,GUEST_PL011_SIZE ,NULL ); + d->console.input_allowed = true; +return 0 ; out1:
xen/arch/x86/pv/shim.c +2 -0
@@ -238,6 +238,8 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,* guest from depleting the shim memory pool. */ d->max_pages =domain_tot_pages (d); + + d->console.input_allowed = true; }static void write_start_info (struct domain *d)
xen/common/domain.c +2 -0
@@ -827,6 +827,8 @@ struct domain *domain_create(domid_t domid, old_hwdom = hardware_domain; hardware_domain = d; + + d->console.input_allowed = true; }TRACE_TIME (TRC_DOM0_DOM_ADD , d->domain_id);
xen/drivers/char/console.c +43 -6
87 lines not on this page · raw message
xen/include/xen/sched.h +7 -1
@@ -512,7 +512,7 @@ struct domainbool auto_node_affinity;/* Is this guest fully privileged (aka dom0)? */ bool is_privileged; -/* Can this guest access the Xen console? */ +/* XSM: permission to use HYPERCALL_console_io hypercall */ bool is_console;/* Is this guest being debugged by dom0? */ bool debugger_attached;
@@ -651,6 +651,12 @@ struct domainunsigned int num_llc_colors;const unsigned int *llc_colors;#endif + +/* Console settings. */ +struct { +/* Permission to own physical console input. */ +bool input_allowed; + } console; }__aligned(PAGE_SIZE) ; static inline struct page_list_head *page_to_list(
Signature · 1 line
2.34.1
Re: [PATCH v1 2/8] xen/console: introduce console input permission
Quoted 9 lines · On 19.03.2025 00:36, [email protected] wrote:
xen/drivers/char/console.c +4
-1@@ -564,10 +586,25 @@ static void __serial_rx(char c)/* Deliver input to the PV shim console. */ rc =consoled_guest_tx (c); -if ( rc ) +switch ( rc ) + { +case 0 : +break ;
xen/drivers/char/console.c static void __serial_rx(char c) · line 602
Quoted 10 lines
xen/drivers/char/console.c +7
-0+ +case -EBUSY :/* Loopback mode */ +case -ENOSPC :/* FIFO is full */ guest_printk (d,XENLOG_WARNING "failed to process console input: %d\n" , rc); +break ; + +default : + d->console.input_allowed = false;
This aspect isn't mentioned / justified in the description, and I also can't deduce why you would do so. Or to put it differently, why you'd then not also take away input focus from this domain, for it no longer being eligible to have focus.
Quoted 12 lines
xen/include/xen/sched.h +1
-1@@ -512,7 +512,7 @@ struct domainbool auto_node_affinity;/* Is this guest fully privileged (aka dom0)? */ bool is_privileged; -/* Can this guest access the Xen console? */ +/* XSM: permission to use HYPERCALL_console_io hypercall */ bool is_console;/* Is this guest being debugged by dom0? */ bool debugger_attached;
xen/include/xen/sched.h struct domain · line 659
Quoted 9 lines
xen/include/xen/sched.h +6
-0@@ -651,6 +651,12 @@ struct domainunsigned int num_llc_colors;const unsigned int *llc_colors;#endif + +/* Console settings. */ +struct { +/* Permission to own physical console input. */ +bool input_allowed; + } console;
Are further fields going to be added to this sub-struct? If not, is having a sub-struct here actually worth it?
Jan
Re: [PATCH v1 2/8] xen/console: introduce console input permission
Quoted 21 lines · Jan Beulich
Quoted 17 lines · On 19.03.2025 00:36, [email protected] wrote:
xen/drivers/char/console.c +9
-1@@ -564,10 +586,25 @@ static void __serial_rx(char c)/* Deliver input to the PV shim console. */ rc =consoled_guest_tx (c); -if ( rc ) +switch ( rc ) + { +case 0 : +break ; + +case -EBUSY :/* Loopback mode / +case -ENOSPC: / FIFO is full */ guest_printk (d,XENLOG_WARNING "failed to process console input: %d\n" , rc); +break ; +
Quoted 8 lines
xen/drivers/char/console.c static void __serial_rx(char c) · line 602
Quoted 2 lines
xen/drivers/char/console.c +2
-0+default : + d->console.input_allowed = false;This aspect isn't mentioned / justified in the description, and I also can't deduce why you would do so. Or to put it differently, why you'd then not also take away input focus from this domain, for it no longer being eligible to have focus.
My idea was to explicitly distinguish "recoverable" errors, such as "FIFO is full", from "emulator logical" errors when input character cannot be delivered to the domain because of an error in emulator, so those are easily seen in the debug logs.
I re-inspected return values, the only values currently supported are:
(1) 0: success
(2) -ENODEV: domain is not configured to have vUART
(3) -ENOSPC: FIFO is full
-EBUSY is supposed to mean "vUART is in loopback mode" and it is leaked from the future NS16550 emulator code.
I will drop that change in v2.
Quoted 18 lines
Quoted 18 lines
xen/include/xen/sched.h +1
-1@@ -512,7 +512,7 @@ struct domainbool auto_node_affinity;/* Is this guest fully privileged (aka dom0)? / bool is_privileged; -/ Can this guest access the Xen console? / +/ XSM: permission to use HYPERCALL_console_io hypercall / bool is_console; / Is this guest being debugged by dom0? */
booldebugger_attached;xen/include/xen/sched.h +2
-0@@ -651,6 +651,12 @@ struct domainunsigned int num_llc_colors;const unsigned int llc_colors;#endif + + / Console settings. /
Quoted 8 lines
xen/include/xen/sched.h struct domain · line 659
Quoted 4 lines
xen/include/xen/sched.h +4
-0+struct { +/ Permission to own physical console input. */ +bool input_allowed; + } console;Are further fields going to be added to this sub-struct? If not, is having a sub-struct here actually worth it?
I was thinking about grouping all console-related fields in struct domain here in the future: e.g. move pbuf-related fields under "struct console".
Quoted 2 lines
Jan
PATCH 3/8 xen/domain: introduce domid_top
In reply to [email protected]Rename max_init_domid to domid_top to align with its usage in the code (Arm), where it represents the upper boundary of the non-system domain ID range.
Relocate the domid_top declaration to an architecture-independent location.
--- xen/arch/arm/dom0less-build.c | 4 ++-- xen/arch/arm/include/asm/setup.h | 2 -- xen/arch/arm/setup.c | 2 -- xen/arch/ppc/include/asm/setup.h | 2 -- xen/arch/riscv/include/asm/setup.h | 2 -- xen/arch/x86/include/asm/setup.h | 2 -- xen/common/domain.c | 3 +++ xen/drivers/char/console.c | 2 +- xen/include/xen/domain.h | 2 ++ 9 files changed, 8 insertions(+), 13 deletions(-)
xen/arch/arm/dom0less-build.c +2 -2
@@ -981,7 +981,7 @@ void __init create_domUs(void)if ( !dt_device_is_compatible (node,"xen,domain" ) )continue ; -if ( (max_init_domid +1 ) >=DOMID_FIRST_RESERVED ) +if ( (domid_top +1 ) >=DOMID_FIRST_RESERVED )panic ("No more domain IDs available\n" );if (dt_find_property (node,"xen,static-mem" ,NULL ) )
@@ -1112,7 +1112,7 @@ void __init create_domUs(void)* very important to use the pre-increment operator to call * domain_create() with a domid > 0. (domid == 0 is reserved for Dom0) */ - d =domain_create (++max_init_domid, &d_cfg, flags); + d =domain_create (++domid_top, &d_cfg, flags);if (IS_ERR (d) )panic ("Error creating domain %s (rc = %ld)\n" ,dt_node_name (node),PTR_ERR (d));
xen/arch/arm/include/asm/setup.h +0 -2
@@ -25,8 +25,6 @@ struct map_range_datastruct rangeset *irq_ranges; }; -extern domid_t max_init_domid; -void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len);size_t estimate_efi_size (unsigned int mem_nr_banks);
xen/arch/arm/setup.c +0 -2
@@ -60,8 +60,6 @@ struct cpuinfo_arm __read_mostly system_cpuinfo;bool __read_mostly acpi_disabled;#endif -domid_t __read_mostly max_init_domid; -static __used void init_done (void ) {int rc;
xen/arch/ppc/include/asm/setup.h +0 -2
@@ -1,6 +1,4 @@#ifndef __ASM_PPC_SETUP_H__#define __ASM_PPC_SETUP_H__ -#define max_init_domid (0) -#endif /* __ASM_PPC_SETUP_H__ */
xen/arch/riscv/include/asm/setup.h +0 -2
@@ -5,8 +5,6 @@#include <xen/types.h> -#define max_init_domid (0) -void setup_mm (void );void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len);
xen/arch/x86/include/asm/setup.h +0 -2
@@ -69,6 +69,4 @@ extern bool opt_dom0_verbose;extern bool opt_dom0_cpuid_faulting;extern bool opt_dom0_msr_relaxed; -#define max_init_domid (0) -#endif
xen/common/domain.c +3 -0
@@ -66,6 +66,9 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);static struct domain *domain_hash[DOMAIN_HASH_SIZE ];struct domain *domain_list; +/* Highest known non-system domain ID. */ +domid_t domid_top; +/* * Insert a domain into the domlist/hash. This allows the domain to be looked * up by domid, and therefore to be the subject of hypercalls/etc.
xen/drivers/char/console.c +1 -1
@@ -472,7 +472,7 @@ static void cf_check dump_console_ring_key(unsigned char key)*/ static unsigned int __read_mostly console_rx =0 ; -#define max_console_rx (max_init_domid + 1) +#define max_console_rx (domid_top + 1)static struct domain *console_get_domain_by_id (domid_t domid) {
xen/include/xen/domain.h +2 -0
@@ -35,6 +35,8 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info);void arch_get_domain_info (const struct domain *d,struct xen_domctl_getdomaininfo *info); +extern domid_t domid_top; +domid_t get_initial_domain_id (void );/* CDF_* constant. Internal flags for domain creation. */
Signature · 1 line
2.34.1
Re: [PATCH v1 3/8] xen/domain: introduce domid_top
Quoted 3 lines · On 19.03.2025 00:36, [email protected] wrote:
Rename
max_init_domidtodomid_topto align with its usage in the code (Arm), where it represents the upper boundary of the non-system domain ID range.
I think I said before that I don't share this view of yours. The variable is quite appropriately named; it's the further use you made of it in earlier versions of work of yours in this area where the name ended up no longer reflecting the purpose. Yet that's not a reason to change the name.
I'm unconvinced we actually need a variable tracking the largest known non-system domain ID. The domain list is sorted, so obtaining that ID should be reasonably easy and cheap without such a variable.
Furthermore such a variable would likely also need reducing when the domain with the highest ID dies.
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 475
Quoted 8 lines
xen/drivers/char/console.c +1
-1@@ -472,7 +472,7 @@ static void cf_check dump_console_ring_key(unsigned char key)*/ static unsigned int __read_mostly console_rx =0 ; -#define max_console_rx (max_init_domid + 1) +#define max_console_rx (domid_top + 1)
This use in particular is bogus. The intention here is to permit console access only to (some?) domains created during boot. Making a (conceptual) change here would require separate justification.
Jan
PATCH 4/8 xen/domain: introduce domid_alloc()
In reply to [email protected]Move domain ID allocation to a dedicated function domid_alloc() and use it during domain creation.
Update domid_top within domid_alloc() to reflect the highest known domain ID.
Initialize domid_top using the result of get_initial_domain_id().
Allocation algorithm:
- If an explicit domain ID is provided, verify its availability and use it if free;
- Otherwise, perform an exhaustive search for the first available ID within the [0..DOMID_FIRST_RESERVED) range, excluding hardware_domid.
The change is a prerequisite for enabling console input rotation across domains on x86 (currently, limited to dom0, PV shim and Xen).
--- xen/arch/arm/dom0less-build.c | 15 ++++---- xen/arch/arm/domain_build.c | 19 +++++++--- xen/common/domctl.c | 71 ++++++++++++++++++++++------------- xen/common/kernel.c | 8 ++++ xen/include/xen/domain.h | 3 ++ 5 files changed, 76 insertions(+), 40 deletions(-)
xen/arch/arm/dom0less-build.c +7 -8
@@ -975,14 +975,18 @@ void __init create_domUs(void) .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), };unsigned int flags =0U ; +domid_t domid;uint32_t val;int rc;if ( !dt_device_is_compatible (node,"xen,domain" ) )continue ; -if ( (domid_top +1 ) >=DOMID_FIRST_RESERVED ) -panic ("No more domain IDs available\n" ); + rc =domid_alloc (DOMID_AUTO ); +if ( rc <0 ) +panic ("cannot allocate domain ID for domain %s (rc = %d)\n" , +dt_node_name (node), rc); + domid = rc;if (dt_find_property (node,"xen,static-mem" ,NULL ) ) {
@@ -1107,12 +1111,7 @@ void __init create_domUs(void)if ( !llc_coloring_enabled && llc_colors_str )panic ("'llc-colors' found, but LLC coloring is disabled\n" ); -/* -* The variable max_init_domid is initialized with zero, so here it's -* very important to use the pre-increment operator to call -* domain_create() with a domid > 0. (domid == 0 is reserved for Dom0) -*/ - d =domain_create (++domid_top, &d_cfg, flags); + d =domain_create (domid, &d_cfg, flags);if (IS_ERR (d) )panic ("Error creating domain %s (rc = %ld)\n" ,dt_node_name (node),PTR_ERR (d));
xen/arch/arm/domain_build.c +14 -5
@@ -2367,8 +2367,15 @@ void __init create_dom0(void) .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), };unsigned int flags = CDF_privileged; +domid_t domid;int rc; + rc =domid_alloc (get_initial_domain_id ()); +if ( rc <0 ) +panic ("Cannot use domain ID %d (rc = %d)\n" , +get_initial_domain_id (), rc); + domid = rc; +/* The vGIC for DOM0 is exactly emulating the hardware GIC */ dom0_cfg.arch.gic_version =XEN_DOMCTL_CONFIG_GIC_NATIVE ; dom0_cfg.arch.nr_spis =VGIC_DEF_NR_SPIS ;
@@ -2391,19 +2398,21 @@ void __init create_dom0(void)if ( !llc_coloring_enabled ) flags |= CDF_directmap; - dom0 =domain_create (0 , &dom0_cfg, flags); + dom0 =domain_create (domid, &dom0_cfg, flags);if (IS_ERR (dom0) ) -panic ("Error creating domain 0 (rc = %ld)\n" ,PTR_ERR (dom0)); +panic ("Error creating domain %d (rc = %ld)\n" , domid,PTR_ERR (dom0));if ( llc_coloring_enabled && (rc =dom0_set_llc_colors (dom0)) ) -panic ("Error initializing LLC coloring for domain 0 (rc = %d)\n" , rc); +panic ("Error initializing LLC coloring for domain %d (rc = %d)\n" , + domid, rc);if (alloc_dom0_vcpu0 (dom0) ==NULL ) -panic ("Error creating domain 0 vcpu0\n" ); +panic ("Error creating domain %d vcpu0\n" , domid); rc =construct_dom0 (dom0);if ( rc ) -panic ("Could not set up DOM0 guest OS (rc = %d)\n" , rc); +panic ("Could not set up guest OS for domain %d (rc = %d)\n" , + domid, rc); }/*
xen/common/domctl.c +44 -27
84 lines not on this page · raw message
xen/common/kernel.c +8 -0
@@ -568,6 +568,14 @@ static long xenver_varbuf_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return sz; } +static int __init cf_check globals_init(void) +{ + domid_top =get_initial_domain_id (); + +return 0 ; +} +__initcall (globals_init); +long do_xen_version (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {bool deny =xsm_xen_version (XSM_OTHER , cmd);
xen/include/xen/domain.h +3 -0
@@ -39,6 +39,9 @@ extern domid_t domid_top;domid_t get_initial_domain_id (void ); +#define DOMID_AUTO (-1) +int domid_alloc (int hint); +/* CDF_* constant. Internal flags for domain creation. */ /* Is this a privileged domain? */ #define CDF_privileged (1U << 0)
Signature · 1 line
2.34.1
Re: [PATCH v1 4/8] xen/domain: introduce domid_alloc()
Quoted 33 lines · On 19.03.2025 00:36, [email protected] wrote:
xen/arch/arm/domain_build.c +11
-3@@ -2367,8 +2367,15 @@ void __init create_dom0(void) .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), };unsigned int flags = CDF_privileged; +domid_t domid;int rc; + rc =domid_alloc (get_initial_domain_id ()); +if ( rc <0 ) +panic ("Cannot use domain ID %d (rc = %d)\n" , +get_initial_domain_id (), rc); + domid = rc; +/* The vGIC for DOM0 is exactly emulating the hardware GIC */ dom0_cfg.arch.gic_version =XEN_DOMCTL_CONFIG_GIC_NATIVE ; dom0_cfg.arch.nr_spis =VGIC_DEF_NR_SPIS ;@@ -2391,19 +2398,21 @@ void __init create_dom0(void)if ( !llc_coloring_enabled ) flags |= CDF_directmap; - dom0 =domain_create (0 , &dom0_cfg, flags); + dom0 =domain_create (domid, &dom0_cfg, flags);if (IS_ERR (dom0) ) -panic ("Error creating domain 0 (rc = %ld)\n" ,PTR_ERR (dom0)); +panic ("Error creating domain %d (rc = %ld)\n" , domid,PTR_ERR (dom0));if ( llc_coloring_enabled && (rc =dom0_set_llc_colors (dom0)) ) -panic ("Error initializing LLC coloring for domain 0 (rc = %d)\n" , rc); +panic ("Error initializing LLC coloring for domain %d (rc = %d)\n" , + domid, rc);
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 2416
Quoted 10 lines
xen/arch/arm/domain_build.c +3
-2if (alloc_dom0_vcpu0 (dom0) ==NULL ) -panic ("Error creating domain 0 vcpu0\n" ); +panic ("Error creating domain %d vcpu0\n" , domid); rc =construct_dom0 (dom0);if ( rc ) -panic ("Could not set up DOM0 guest OS (rc = %d)\n" , rc); +panic ("Could not set up guest OS for domain %d (rc = %d)\n" , + domid, rc); }
Assuming we really needed this new function, why would there be an Arm side change to Dom0 creation, but no equivalent change on the x86 side?
Jan
PATCH 5/8 xen/console: rename switch_serial_input() to console_switch_focus()
In reply to [email protected]Update the name to emphasize the physical console input switch to a new owner domain following the naming notation in the console driver.
No functional change.
--- xen/drivers/char/console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/drivers/char/console.c +3 -3
@@ -511,7 +511,7 @@ static bool console_check_focus_by_id(domid_t domid)return !!d; } -static void switch_serial_input (void ) +static void console_switch_focus (void ) {unsigned int next_rx = console_rx;
@@ -618,7 +618,7 @@ static void cf_check serial_rx(char c)/* We eat CTRL-<switch_char> in groups of 3 to switch console input. */ if ( ++switch_code_count ==3 ) { -switch_serial_input (); +console_switch_focus (); switch_code_count =0 ; }return ;
@@ -1162,7 +1162,7 @@ void __init console_endboot(void) "toggle host/guest log level adjustment", 0);/* Serial input is directed to DOM0 by default. */ -switch_serial_input (); +console_switch_focus (); }int __init console_has (const char *device)
Signature · 1 line
2.34.1
Re: [PATCH v1 5/8] xen/console: rename switch_serial_input() to console_switch_focus()
Quoted 6 lines · On 19.03.2025 00:36, [email protected] wrote:
Update the name to emphasize the physical console input switch to a new owner domain following the naming notation in the console driver.
No functional change.
Signed-off-by Denis Mukhin <[email protected]>
While I don't strictly mind the change, I'd like to point out that ...
xen/drivers/char/console.c static bool console_check_focus_by_id(domid_t domid) · line 514
Quoted 8 lines
xen/drivers/char/console.c +1
-1@@ -511,7 +511,7 @@ static bool console_check_focus_by_id(domid_t domid)return !!d; } -static void switch_serial_input (void ) +static void console_switch_focus (void )
... unlike the description says, "input" isn't reflected at all in the new name.
Jan
PATCH 6/8 xen/console: rename console_rx to console_focus
In reply to [email protected]Update the symbol name in preparation for the semantic change to the physical console input owner domain identifier.
No functional change.
--- xen/drivers/char/console.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
xen/drivers/char/console.c +10 -13
@@ -465,12 +465,9 @@ static void cf_check dump_console_ring_key(unsigned char key)* and the DomUs started from Xen at boot. */ #define switch_code (opt_conswitch[0]-'a'+1) -/* -* console_rx=0 => input to xen -* console_rx=1 => input to dom0 (or the sole shim domain) -* console_rx=N => input to dom(N-1) -*/ -static unsigned int __read_mostly console_rx =0 ; + +/* Console owner domain identifier. */ +static unsigned int __read_mostly console_focus =0 ;#define max_console_rx (domid_top + 1)
@@ -491,9 +488,9 @@ static struct domain *console_get_domain_by_id(domid_t domid)struct domain *console_get_domain (void ) { -if ( console_rx ==0 ) +if ( console_focus ==0 )return NULL ; -return console_get_domain_by_id (console_rx -1 ); +return console_get_domain_by_id (console_focus -1 ); }void console_put_domain (struct domain *d)
@@ -513,7 +510,7 @@ static bool console_check_focus_by_id(domid_t domid)static void console_switch_focus (void ) { -unsigned int next_rx = console_rx; +unsigned int next_rx = console_focus;/* * Rotate among Xen, dom0 and boot-time created domUs while skipping
@@ -525,7 +522,7 @@ static void console_switch_focus(void)if ( next_rx++ >= max_console_rx ) { - console_rx =0 ; + console_focus =0 ;printk ("*** Serial input to Xen" );break ; }
@@ -537,7 +534,7 @@ static void console_switch_focus(void)if (console_check_focus_by_id (domid) ) { - console_rx = next_rx; + console_focus = next_rx;printk ("*** Serial input to DOM%u" , domid);break ; }
@@ -554,7 +551,7 @@ static void __serial_rx(char c)struct domain *d;int rc =0 ; -if ( console_rx ==0 ) +if ( console_focus ==0 )return handle_keypress (c, false); d =console_get_domain ();
@@ -1150,7 +1147,7 @@ void __init console_endboot(void)* a useful 'how to switch' message. */ if ( opt_conswitch[1 ] =='x' ) - console_rx = max_console_rx; + console_focus = max_console_rx;register_keyhandler ('w' , dump_console_ring_key,"synchronously dump console ring buffer (dmesg)" ,0 );
Signature · 1 line
2.34.1
Re: [PATCH v1 6/8] xen/console: rename console_rx to console_focus
Quoted 2 lines · On 19.03.2025 00:36, [email protected] wrote:
Update the symbol name in preparation for the semantic change to the physical console input owner domain identifier.
As you say, no semantic change here just yet, but then ...
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 472
Quoted 11 lines
xen/drivers/char/console.c +0
-5@@ -465,12 +465,9 @@ static void cf_check dump_console_ring_key(unsigned char key)* and the DomUs started from Xen at boot. */ #define switch_code (opt_conswitch[0]-'a'+1) -/* -* console_rx=0 => input to xen -* console_rx=1 => input to dom0 (or the sole shim domain) -* console_rx=N => input to dom(N-1) -*/
... this (correct) comment is replaced by ...
xen/drivers/char/console.c static void cf_check dump_console_ring_key(unsigned char key) · line 469
Quoted 3 lines
xen/drivers/char/console.c +2
-1-static unsigned int __read_mostly console_rx =0 ; + +/* Console owner domain identifier. */
... this (right now) incorrect one.
Jan
PATCH 7/8 xen/console: introduce console_set_focus()
In reply to [email protected]Switch console_focus address space from integers mapped to domain IDs to direct domain IDs, simplifying the console input switching code.
Introduce console_set_focus() to set the console owner domain identifier.
--- xen/drivers/char/console.c | 81 ++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 47 deletions(-)
xen/drivers/char/console.c +34 -47
@@ -462,14 +462,12 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot. +* and the DomUs. */ #define switch_code (opt_conswitch[0]-'a'+1)/* Console owner domain identifier. */ -static unsigned int __read_mostly console_focus =0 ; - -#define max_console_rx (domid_top + 1) +static domid_t __read_mostly console_focus =DOMID_XEN ;static struct domain *console_get_domain_by_id (domid_t domid) {
@@ -488,9 +486,7 @@ static struct domain *console_get_domain_by_id(domid_t domid)struct domain *console_get_domain (void ) { -if ( console_focus ==0 ) -return NULL ; -return console_get_domain_by_id (console_focus -1 ); +return console_get_domain_by_id (console_focus); }void console_put_domain (struct domain *d)
@@ -508,42 +504,41 @@ static bool console_check_focus_by_id(domid_t domid)return !!d; } -static void console_switch_focus (void ) +static int console_set_focus (domid_t domid) { -unsigned int next_rx = console_focus; +if ( domid ==DOMID_XEN ) +printk ("*** Serial input to Xen" ); +else if (console_check_focus_by_id (domid) ) +printk ("*** Serial input to DOM%u" , domid); +else +return -ENOENT ; -/* -* Rotate among Xen, dom0 and boot-time created domUs while skipping -* switching serial input to non existing domains. -*/ -for ( ; ; ) - { -domid_t domid; - -if ( next_rx++ >= max_console_rx ) - { - console_focus =0 ; -printk ("*** Serial input to Xen" ); -break ; - } - -if (consoled_is_enabled () && next_rx ==1 ) - domid =get_initial_domain_id (); -else - domid = next_rx -1 ; - -if (console_check_focus_by_id (domid) ) - { - console_focus = next_rx; -printk ("*** Serial input to DOM%u" , domid); -break ; - } - } + console_focus = domid;if ( switch_code )printk (" (type 'CTRL-%c' three times to switch input)" , opt_conswitch[0 ]);printk ("\n" ); + +return 0 ; +} + +/* +* Switch console focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains. +*/ +static void console_switch_focus (void ) +{ +const domid_t n = domid_top +1 ; +domid_t i = ( console_focus ==DOMID_XEN ) + ?get_initial_domain_id () : console_focus +1 ; + +for ( ; i < n; i++ ) +if ( !console_set_focus (i) ) +return ; + +console_set_focus (DOMID_XEN ); }static void __serial_rx (char c)
@@ -551,7 +546,7 @@ static void __serial_rx(char c)struct domain *d;int rc =0 ; -if ( console_focus ==0 ) +if ( console_focus ==DOMID_XEN )return handle_keypress (c, false); d =console_get_domain ();
@@ -1141,14 +1136,6 @@ void __init console_endboot(void)video_endboot (); -/* -* If user specifies so, we fool the switch routine to redirect input -* straight back to Xen. I use this convoluted method so we still print -* a useful 'how to switch' message. -*/ -if ( opt_conswitch[1 ] =='x' ) - console_focus = max_console_rx; -register_keyhandler ('w' , dump_console_ring_key,"synchronously dump console ring buffer (dmesg)" ,0 ); register_irq_keyhandler('+', &do_inc_thresh,
@@ -1158,8 +1145,8 @@ void __init console_endboot(void)register_irq_keyhandler ('G' , &do_toggle_guest,"toggle host/guest log level adjustment" ,0 ); -/* Serial input is directed to DOM0 by default. */ -console_switch_focus (); +if ( opt_conswitch[1 ] !='x' ) +console_set_focus (get_initial_domain_id () ); }int __init console_has (const char *device)
Signature · 1 line
2.34.1
Re: [PATCH v1 7/8] xen/console: introduce console_set_focus()
Quoted 143 lines · On Tuesday, March 18th, 2025 at 4:37 PM, [email protected] <[email protected]>…
Switch
console_focusaddress space from integers mapped to domain IDs to direct domain IDs, simplifying the console input switching code.Introduce
console_set_focus()to set the console owner domain identifier.Signed-off-by Denis Mukhin [email protected]---
xen/drivers/char/console.c| 81 ++++++++++++++++----------------------1 file changed, 34 insertions(+), 47 deletions(-)xen/drivers/char/console.c +1
-1@@ -462,14 +462,12 @@ static void cf_check dump_console_ring_key(unsigned char key)/* * CTRL-<switch_char> changes input direction, rotating among Xen, Dom0, -* and the DomUs started from Xen at boot. +* and the DomUs. /
#defineswitch_code(opt_conswitch[0]-'a'+1)/ Console owner domain identifier. /
xen/drivers/char/console.c +1
-3-static unsigned int __read_mostly console_focus =0 ; - -#define max_console_rx (domid_top + 1) +static domid_t __read_mostly console_focus =DOMID_XEN ;static struct domain
console_get_domain_by_id(domid_t domid){xen/drivers/char/console.c +29
-32@@ -488,9 +486,7 @@ static struct domain console_get_domain_by_id(domid_t domid)struct domain console_get_domain (void ) { -if ( console_focus ==0 ) -return NULL ; -return console_get_domain_by_id (console_focus -1 ); +return console_get_domain_by_id (console_focus); }void console_put_domain (struct domain d)@@ -508,42 +504,41 @@ static bool console_check_focus_by_id(domid_t domid)return !!d; } -static void console_switch_focus (void ) +static int console_set_focus (domid_t domid) { -unsigned int next_rx = console_focus; +if ( domid ==DOMID_XEN ) +printk (" Serial input to Xen" ); +else if (console_check_focus_by_id (domid) ) +printk ("* Serial input to DOM%u" , domid); +else +return -ENOENT ; -/* -* Rotate among Xen, dom0 and boot-time created domUs while skipping -* switching serial input to non existing domains. -*/ -for ( ; ; ) - { -domid_t domid; - -if ( next_rx++ >= max_console_rx ) - { - console_focus =0 ; -printk ("*** Serial input to Xen" ); -break ; - } - -if (consoled_is_enabled () && next_rx ==1 ) - domid =get_initial_domain_id (); -else - domid = next_rx -1 ; - -if (console_check_focus_by_id (domid) ) - { - console_focus = next_rx; -printk ("*** Serial input to DOM%u" , domid); -break ; - } - } + console_focus = domid;if ( switch_code )printk (" (type 'CTRL-%c' three times to switch input)" , opt_conswitch[0 ]);printk ("\n" ); + +return 0 ; +} + +/* +* Switch console focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains. +*/ +static void console_switch_focus (void ) +{ +const domid_t n = domid_top +1 ; +domid_t i = ( console_focus ==DOMID_XEN ) + ?get_initial_domain_id () : console_focus +1 ; + +for ( ; i < n; i++ ) +if ( !console_set_focus (i) ) +return ; + +console_set_focus (DOMID_XEN ); }static void
__serial_rx(char c)xen/drivers/char/console.c +1
-9@@ -551,7 +546,7 @@ static void __serial_rx(char c)struct domain d;int rc =0 ; -if ( console_focus ==0 ) +if ( console_focus ==DOMID_XEN )return handle_keypress (c, false); d =console_get_domain ();@@ -1141,14 +1136,6 @@ void __init console_endboot(void)video_endboot (); - / - * If user specifies so, we fool the switch routine to redirect input - * straight back to Xen. I use this convoluted method so we still print - * a useful 'how to switch' message. - / - if ( opt_conswitch[1] == 'x' ) - console_focus = max_console_rx; -register_keyhandler ('w' , dump_console_ring_key,"synchronously dump console ring buffer (dmesg)" ,0 ); register_irq_keyhandler('+', &do_inc_thresh,
xen/drivers/char/console.c void __init console_endboot(void) · line 1149
Quoted 7 lines
xen/drivers/char/console.c +2
-2@@ -1158,8 +1145,8 @@ void __init console_endboot(void)register_irq_keyhandler ('G' , &do_toggle_guest,"toggle host/guest log level adjustment" ,0 ); -/ Serial input is directed to DOM0 by default. */ -console_switch_focus (); +if ( opt_conswitch[1 ] !='x' ) +console_set_focus (get_initial_domain_id () );
Forgot to drop extra spaces around the function parameter.
Quoted 5 lines
xen/drivers/char/console.c +0
-1}int __init console_has (const char *device) --2.34.1
Re: [PATCH v1 7/8] xen/console: introduce console_set_focus()
Quoted 10 lines · Denis Mukhin
xen/drivers/char/console.c static bool console_check_focus_by_id(domid_t domid) · line 534
Quoted 9 lines · On Tuesday, March 18th, 2025 at 4:37 PM, [email protected] <[email protected]>…
xen/drivers/char/console.c +9
-0+/* +* Switch console focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains. +*/ +static void console_switch_focus (void ) +{ +const domid_t n = domid_top +1 ; +domid_t i = ( console_focus ==DOMID_XEN )
Same issue here as ...
Quoted 10 lines
xen/drivers/char/console.c void __init console_endboot(void) · line 1149
Quoted 8 lines
xen/drivers/char/console.c +2
-2@@ -1158,8 +1145,8 @@ void __init console_endboot(void)register_irq_keyhandler ('G' , &do_toggle_guest,"toggle host/guest log level adjustment" ,0 ); -/ Serial input is directed to DOM0 by default. */ -console_switch_focus (); +if ( opt_conswitch[1 ] !='x' ) +console_set_focus (get_initial_domain_id () );Forgot to drop extra spaces around the function parameter.
... you noticed here.
Jan
Re: [PATCH v1 7/8] xen/console: introduce console_set_focus()
In reply to [email protected]xen/drivers/char/console.c static bool console_check_focus_by_id(domid_t domid) · line 533
Quoted 8 lines · On 19.03.2025 00:37, [email protected] wrote:
xen/drivers/char/console.c +8
-0+/* +* Switch console focus. +* Rotates input focus among Xen, dom0 and boot-time created domUs while +* skipping switching serial input to non existing domains. +*/ +static void console_switch_focus (void ) +{ +const domid_t n = domid_top +1 ;
The use of this renamed identifier is now in sharp conflict with the comment, talking about boot-time created domains only.
xen/drivers/char/console.c static bool console_check_focus_by_id(domid_t domid) · line 538
Quoted 5 lines
xen/drivers/char/console.c +5
-0+domid_t i = ( console_focus ==DOMID_XEN ) + ?get_initial_domain_id () : console_focus +1 ; + +for ( ; i < n; i++ ) +if ( !console_set_focus (i) )
This being the sole call caring about the function's return value, why isn't the function returning a mere boolean?
Jan
PATCH 8/8 xen/console: introduce console_get_focus()
In reply to [email protected]Add console_get_focus() as a console public API to the retrieve current console owner domain ID.
Make console_{get,put}_domain() private and simplify vpl011 code a bit.
--- xen/arch/arm/vpl011.c | 5 +---- xen/drivers/char/console.c | 9 +++++++-- xen/include/xen/console.h | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-)
xen/arch/arm/vpl011.c +1 -4
@@ -78,12 +78,11 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data)unsigned long flags;struct vpl011 *vpl011 = &d->arch.vpl011;struct vpl011_xen_backend *intf = vpl011->backend.xen; -struct domain *input =console_get_domain ();VPL011_LOCK (d, flags); intf->out[intf->out_prod++] = data; -if ( d == input ) +if ( d->domain_id ==console_get_focus () ) {if ( intf->out_prod ==1 ) {
@@ -123,8 +122,6 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data)vpl011_update_interrupt_status (d);VPL011_UNLOCK (d, flags); - -console_put_domain (input); }/*
xen/drivers/char/console.c +7 -2
@@ -484,12 +484,12 @@ static struct domain *console_get_domain_by_id(domid_t domid)return NULL ; } -struct domain *console_get_domain (void ) +static struct domain *console_get_domain (void ) {return console_get_domain_by_id (console_focus); } -void console_put_domain (struct domain *d) +static void console_put_domain (struct domain *d) {if ( d )rcu_unlock_domain (d);
@@ -523,6 +523,11 @@ static int console_set_focus(domid_t domid)return 0 ; } +domid_t console_get_focus (void ) +{ +return console_focus; +} +/* * Switch console focus. * Rotates input focus among Xen, dom0 and boot-time created domUs while
xen/include/xen/console.h +1 -2
@@ -32,8 +32,7 @@ void console_end_sync(void);void console_start_log_everything (void );void console_end_log_everything (void ); -struct domain *console_get_domain (void ); -void console_put_domain (struct domain *d); +domid_t console_get_focus (void );/* * Steal output from the console. Returns +ve identifier, else -ve error.
Signature · 1 line
2.34.1
Quoted 23 lines · On Tuesday, March 18th, 2025 at 4:36 PM, [email protected] <[email protected]>…
Currently, on x86, console input can be rotated in round-robin manner only between dom0, PV shim, and Xen itself. On Arm the input rotation can include domUs with vpl011.
The patch series introduces the concept of "console focus", which is defined as the ID of the domain that currently owns the physical console input.
The patch series originates from the NS16550 UART emulator series [1] for x86, which requires ability to switch physical console input to a PVH/HVM domain with an emulated UART.
The main idea is introducing a per-domain permission flag that is set during domain initialization and used by the console driver to switch the input across permitted domains.
Patch 0 removes all the trailing white spaces in the console driver code.
Patch 1 introduces a new domain permission flag to mark ownership of the console input for the console driver.
Quoted 8 lines
Patches 2-4 prepare console driver to allow console input rotation across multiple domains based on the new permission flag.
Patches 5-6 perform mechanical renames to fit the usage in the code.
Patch 7 cleans up the console input switch logic.
Patch 8 simplifies the existing vUART code by using newly introduced APIs.
Corrected series explanation:
Patch 1 removes all the trailing white spaces in the console driver code.
Patch 2 introduces a new domain permission flag to mark ownership of the console input for the console driver.
Patches 3, 4 prepare console driver to allow console input rotation across multiple domains based on the new permission flag.
Patches 5, 6 perform mechanical renames to fit the usage in the code.
Patch 7 cleans up the console input switch logic.
Patch 8 simplifies the existing vUART code by using newly introduced APIs.
Quoted 35 lines
CI: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/1723361248
[1]: https://lore.kernel.org/xen-devel/[email protected]/
Denis Mukhin (8):
xen/console: fix trailing whitespaces
xen/console: introduce console input permission xen/domain: introducedomid_top
xen/domain: introducedomid_alloc()
xen/console: renameswitch_serial_input()toconsole_switch_focus()xen/console: renameconsole_rxtoconsole_focusxen/console: introduceconsole_set_focus()
xen/console: introduceconsole_get_focus()
xen/arch/arm/dom0less-build.c| 15 ++-xen/arch/arm/domain_build.c| 19 +++-xen/arch/arm/include/asm/setup.h| 2 -xen/arch/arm/setup.c| 2 -xen/arch/arm/vpl011.c| 7 +-xen/arch/ppc/include/asm/setup.h| 2 -xen/arch/riscv/include/asm/setup.h| 2 -xen/arch/x86/include/asm/setup.h| 2 -xen/arch/x86/pv/shim.c| 2 +xen/common/domain.c | 5 + xen/common/domctl.c | 71 +++++++++------ xen/common/kernel.c | 8 ++
xen/drivers/char/console.c| 142 +++++++++++++++++------------xen/include/xen/console.h| 3 +-xen/include/xen/domain.h| 5 +xen/include/xen/sched.h| 8 +-16 files changed, 180 insertions(+), 115 deletions(-)--
2.34.1