From nobody Fri Oct 31 23:30:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=proton.me Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1743462366708201.92991558853396; Mon, 31 Mar 2025 16:06:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.933114.1335146 (Exim 4.92) (envelope-from ) id 1tzOCI-0003Wh-IE; Mon, 31 Mar 2025 23:05:38 +0000 Received: by outflank-mailman (output) from mailman id 933114.1335146; Mon, 31 Mar 2025 23:05:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCI-0003Wa-Ev; Mon, 31 Mar 2025 23:05:38 +0000 Received: by outflank-mailman (input) for mailman id 933114; Mon, 31 Mar 2025 23:05:36 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCG-0003Id-St for xen-devel@lists.xenproject.org; Mon, 31 Mar 2025 23:05:36 +0000 Received: from mail-10630.protonmail.ch (mail-10630.protonmail.ch [79.135.106.30]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a73f650e-0e84-11f0-9ffb-bf95429c2676; Tue, 01 Apr 2025 01:05:35 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a73f650e-0e84-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743462333; x=1743721533; bh=P4yUAieCFUccYuxlmELh6hErnzZb8oGQtjdxvGGyV3c=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=U5AkLS0wHS8nRunrJiK1WSvCLvTqi5STt2CQoGyx3mfjLu4HoPAFx+Oo0k0D6ABCk 8+UNxU2FBVGFQ8KDow16P2GIA3PqOPtnl9tiE829fTjkuuj5j7KxILj17Cti48SMY6 HI8meuGCmtYJSQMVBq+evlfKJheOyifr2ou0hRErN7QycD5p3RqoPBMCIx+k7qttRI 1MbAuauuwfJ3CbTj0i4kJ+Gnvw15ff03KytfUMlD9jQIWLY8bq8AkC8i0QrIG+J+Wh HvylXdq151ZEqMbNrUj11q73kEXazbV3hk2Lhep5N1aSGHQUbL8ih+iivWvzIaH4ld DsuxI+lYZnVXQ== Date: Mon, 31 Mar 2025 23:05:29 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: 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: [PATCH v2 1/7] xen/console: introduce console input permission Message-ID: <20250331230508.440198-2-dmukhin@ford.com> In-Reply-To: <20250331230508.440198-1-dmukhin@ford.com> References: <20250331230508.440198-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: d22bea445843c75aa7cd8d61b6b10d7d282769c7 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1743462368971019000 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin Add new flag in domain structure for marking permission to intercept the physical console input by the domain. Update console input switch logic accordingly. Signed-off-by: Denis Mukhin --- Changes since v1: - dropped change in __serial_rx() --- xen/arch/arm/vpl011.c | 2 ++ xen/arch/x86/pv/shim.c | 2 ++ xen/common/domain.c | 2 ++ xen/drivers/char/console.c | 32 +++++++++++++++++++++++++++----- xen/include/xen/sched.h | 8 +++++++- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 66047bf33c..147958eee8 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -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); =20 + d->console.input_allowed =3D true; + return 0; =20 out1: diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index c506cc0bec..bc2a7dd5fa 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -238,6 +238,8 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgen= try_t *l4start, * guest from depleting the shim memory pool. */ d->max_pages =3D domain_tot_pages(d); + + d->console.input_allowed =3D true; } =20 static void write_start_info(struct domain *d) diff --git a/xen/common/domain.c b/xen/common/domain.c index 585fd726a9..b9f549c617 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -827,6 +827,8 @@ struct domain *domain_create(domid_t domid, =20 old_hwdom =3D hardware_domain; hardware_domain =3D d; + + d->console.input_allowed =3D true; } =20 TRACE_TIME(TRC_DOM0_DOM_ADD, d->domain_id); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index c3150fbdb7..b312a1223e 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -474,11 +474,26 @@ static unsigned int __read_mostly console_rx =3D 0; =20 #define max_console_rx (max_init_domid + 1) =20 +static struct domain *console_get_domain_by_id(domid_t domid) +{ + struct domain *d =3D rcu_lock_domain_by_id(domid); + + if ( !d ) + return NULL; + + if ( d->console.input_allowed ) + return d; + + rcu_unlock_domain(d); + + return NULL; +} + struct domain *console_get_domain(void) { if ( console_rx =3D=3D 0 ) return NULL; - return rcu_lock_domain_by_id(console_rx - 1); + return console_get_domain_by_id(console_rx - 1); } =20 void console_put_domain(struct domain *d) @@ -487,6 +502,15 @@ void console_put_domain(struct domain *d) rcu_unlock_domain(d); } =20 +static bool console_is_input_allowed(domid_t domid) +{ + struct domain *d =3D console_get_domain_by_id(domid); + + console_put_domain(d); + + return !!d; +} + static void switch_serial_input(void) { unsigned int next_rx =3D console_rx; @@ -498,7 +522,6 @@ static void switch_serial_input(void) for ( ; ; ) { domid_t domid; - struct domain *d; =20 if ( next_rx++ >=3D max_console_rx ) { @@ -511,10 +534,9 @@ static void switch_serial_input(void) domid =3D get_initial_domain_id(); else domid =3D next_rx - 1; - d =3D rcu_lock_domain_by_id(domid); - if ( d ) + + if ( console_is_input_allowed(domid) ) { - rcu_unlock_domain(d); console_rx =3D next_rx; printk("*** Serial input to DOM%u", domid); break; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 559d201e0c..292b1a91f9 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -512,7 +512,7 @@ struct domain bool 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 domain unsigned 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); =20 static inline struct page_list_head *page_to_list( --=20 2.34.1 From nobody Fri Oct 31 23:30:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=proton.me Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1743462364497157.96691718617285; Mon, 31 Mar 2025 16:06:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.933115.1335155 (Exim 4.92) (envelope-from ) id 1tzOCL-0003m2-OQ; Mon, 31 Mar 2025 23:05:41 +0000 Received: by outflank-mailman (output) from mailman id 933115.1335155; Mon, 31 Mar 2025 23:05:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCL-0003lt-LP; Mon, 31 Mar 2025 23:05:41 +0000 Received: by outflank-mailman (input) for mailman id 933115; Mon, 31 Mar 2025 23:05:40 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCJ-0003Id-Ve for xen-devel@lists.xenproject.org; Mon, 31 Mar 2025 23:05:39 +0000 Received: from mail-24417.protonmail.ch (mail-24417.protonmail.ch [109.224.244.17]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a8ee703a-0e84-11f0-9ffb-bf95429c2676; Tue, 01 Apr 2025 01:05:38 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a8ee703a-0e84-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743462337; x=1743721537; bh=dyXCUi+vmDLIhO4Pef6I/Jb6d7Tp3JhCzVlgaMYn8zA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=CVrRv41s7ikszRZ1TD7hqNSvr7SfqUuX4M3w3zdW2qkcrSoWhgHfdDKKwyM1xEoU5 0sF2u7EaaT88jd1bXRa2v3uKHgujlUwBa54CGQ4cUvKEH/pPvFnhTkoe17wpyvB42D 7p0/9SFfXfVxlnY9mL2NbgW8xOGOddbaARz/Ojj0GFotyWg7RtnEOmjTknL2LnFF9J Ek9ChGaaEx705E6Khbs7zpW59vjrP8usoxs6xZALvql14Hj+n+A+QiXPr2J5m0ik8v 4BBdAhF/na64PfZ96GRqUOisQMYdww6g0TamQnZfx831VI7NeacVh+nyK8ZpnYmhGK lLyj1cing/maA== Date: Mon, 31 Mar 2025 23:05:33 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: 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: [PATCH v2 2/7] xen/domain: introduce domid_alloc() Message-ID: <20250331230508.440198-3-dmukhin@ford.com> In-Reply-To: <20250331230508.440198-1-dmukhin@ford.com> References: <20250331230508.440198-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 34cd198a2bef150aa01177dde758ad9e039cc326 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1743462366764019000 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin Move domain ID allocation during domain creation to a dedicated function domid_alloc(). Allocation algorithm: - If an explicit domain ID is provided, verify its availability and use it if ID is unused; - Otherwise, perform an exhaustive search for the first available ID within the [0..DOMID_FIRST_RESERVED) range, excluding hardware_domid. This minimizes the use of max_init_domid in the code and, thus, is a prerequisite change for enabling console input rotation across domains with console input permission on x86 platforms (which currently is limited to dom0, PV shim and Xen). Signed-off-by: Denis Mukhin --- Changes since v1: - use domid_alloc() during dom0 creation on x86 --- xen/arch/arm/dom0less-build.c | 15 ++++++------ xen/arch/arm/domain_build.c | 19 +++++++++++---- xen/arch/x86/setup.c | 8 ++++++- xen/common/domain.c | 45 +++++++++++++++++++++++++++++++++++ xen/common/domctl.c | 45 ++++------------------------------- xen/include/xen/domain.h | 3 +++ 6 files changed, 80 insertions(+), 55 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 573b0d25ae..4b9e22039e 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -975,14 +975,18 @@ void __init create_domUs(void) .grant_opts =3D XEN_DOMCTL_GRANT_version(opt_gnttab_max_versio= n), }; unsigned int flags =3D 0U; + domid_t domid; uint32_t val; int rc; =20 if ( !dt_device_is_compatible(node, "xen,domain") ) continue; =20 - if ( (max_init_domid + 1) >=3D DOMID_FIRST_RESERVED ) - panic("No more domain IDs available\n"); + rc =3D domid_alloc(DOMID_AUTO); + if ( rc < 0 ) + panic("cannot allocate domain ID for domain %s (rc =3D %d)\n", + dt_node_name(node), rc); + domid =3D rc; =20 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"); =20 - /* - * The variable max_init_domid is initialized with zero, so here i= t's - * very important to use the pre-increment operator to call - * domain_create() with a domid > 0. (domid =3D=3D 0 is reserved f= or Dom0) - */ - d =3D domain_create(++max_init_domid, &d_cfg, flags); + d =3D domain_create(domid, &d_cfg, flags); if ( IS_ERR(d) ) panic("Error creating domain %s (rc =3D %ld)\n", dt_node_name(node), PTR_ERR(d)); diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 2b5b433183..2d8c2931d6 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2367,8 +2367,15 @@ void __init create_dom0(void) .grant_opts =3D XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), }; unsigned int flags =3D CDF_privileged; + domid_t domid; int rc; =20 + rc =3D domid_alloc(get_initial_domain_id()); + if ( rc < 0 ) + panic("Cannot use domain ID %d (rc =3D %d)\n", + get_initial_domain_id(), rc); + domid =3D rc; + /* The vGIC for DOM0 is exactly emulating the hardware GIC */ dom0_cfg.arch.gic_version =3D XEN_DOMCTL_CONFIG_GIC_NATIVE; dom0_cfg.arch.nr_spis =3D VGIC_DEF_NR_SPIS; @@ -2391,19 +2398,21 @@ void __init create_dom0(void) if ( !llc_coloring_enabled ) flags |=3D CDF_directmap; =20 - dom0 =3D domain_create(0, &dom0_cfg, flags); + dom0 =3D domain_create(domid, &dom0_cfg, flags); if ( IS_ERR(dom0) ) - panic("Error creating domain 0 (rc =3D %ld)\n", PTR_ERR(dom0)); + panic("Error creating domain %d (rc =3D %ld)\n", domid, PTR_ERR(do= m0)); =20 if ( llc_coloring_enabled && (rc =3D dom0_set_llc_colors(dom0)) ) - panic("Error initializing LLC coloring for domain 0 (rc =3D %d)\n"= , rc); + panic("Error initializing LLC coloring for domain %d (rc =3D %d)\n= ", + domid, rc); =20 if ( alloc_dom0_vcpu0(dom0) =3D=3D NULL ) - panic("Error creating domain 0 vcpu0\n"); + panic("Error creating domain %d vcpu0\n", domid); =20 rc =3D construct_dom0(dom0); if ( rc ) - panic("Could not set up DOM0 guest OS (rc =3D %d)\n", rc); + panic("Could not set up guest OS for domain %d (rc =3D %d)\n", + domid, rc); } =20 /* diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index d70abb7e0c..ad349528ea 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -996,6 +996,7 @@ static struct domain *__init create_dom0(struct boot_in= fo *bi) domid_t domid; struct boot_module *image; unsigned int idx; + int rc; =20 idx =3D first_boot_module_index(bi, BOOTMOD_KERNEL); if ( idx >=3D bi->nr_modules ) @@ -1003,6 +1004,12 @@ static struct domain *__init create_dom0(struct boot= _info *bi) =20 image =3D &bi->mods[idx]; =20 + rc =3D domid_alloc(get_initial_domain_id()); + if ( rc < 0 ) + panic("Cannot use domain ID %d (rc =3D %d)\n", + get_initial_domain_id(), rc); + domid =3D rc; + if ( opt_dom0_pvh ) { dom0_cfg.flags |=3D (XEN_DOMCTL_CDF_hvm | @@ -1017,7 +1024,6 @@ static struct domain *__init create_dom0(struct boot_= info *bi) dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; =20 /* Create initial domain. Not d0 for pvshim. */ - domid =3D get_initial_domain_id(); d =3D domain_create(domid, &dom0_cfg, pv_shim ? 0 : CDF_privileged); if ( IS_ERR(d) ) panic("Error creating d%u: %ld\n", domid, PTR_ERR(d)); diff --git a/xen/common/domain.c b/xen/common/domain.c index b9f549c617..b07d70a7e3 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -66,6 +66,51 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock); static struct domain *domain_hash[DOMAIN_HASH_SIZE]; struct domain *domain_list; =20 +static inline bool is_free_domid(domid_t dom) +{ + struct domain *d =3D rcu_lock_domain_by_id(dom); + + if ( d ) + rcu_unlock_domain(d); + + return !d; +} + +/* + * Allocate new domain ID based on the hint. + * + * If hint is outside of valid [0..DOMID_FIRST_RESERVED] range of IDs, + * perform an exhaustive search of the first free domain ID excluding + * hardware_domid. + */ +int domid_alloc(int hint) +{ + domid_t domid; + + if ( hint >=3D 0 && hint < DOMID_FIRST_RESERVED ) + { + if ( !is_free_domid(hint) ) + return -EEXIST; + + domid =3D hint; + } + else + { + for ( domid =3D 0; domid < DOMID_FIRST_RESERVED; domid++ ) + { + if ( domid =3D=3D hardware_domid ) + continue; + if ( is_free_domid(domid) ) + break; + } + + if ( domid =3D=3D DOMID_FIRST_RESERVED ) + return -ENOMEM; + } + + return domid; +} + /* * Insert a domain into the domlist/hash. This allows the domain to be lo= oked * up by domid, and therefore to be the subject of hypercalls/etc. diff --git a/xen/common/domctl.c b/xen/common/domctl.c index bfe2e1f9f0..3d21612660 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -49,20 +49,6 @@ static int xenctl_bitmap_to_nodemask(nodemask_t *nodemas= k, MAX_NUMNODES); } =20 -static inline int is_free_domid(domid_t dom) -{ - struct domain *d; - - if ( dom >=3D DOMID_FIRST_RESERVED ) - return 0; - - if ( (d =3D rcu_lock_domain_by_id(dom)) =3D=3D NULL ) - return 1; - - rcu_unlock_domain(d); - return 0; -} - void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info) { struct vcpu *v; @@ -421,34 +407,11 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u= _domctl) =20 case XEN_DOMCTL_createdomain: { - domid_t dom; - static domid_t rover =3D 0; + ret =3D domid_alloc(op->domain); + if ( ret < 0 ) + break; =20 - dom =3D op->domain; - if ( (dom > 0) && (dom < DOMID_FIRST_RESERVED) ) - { - ret =3D -EEXIST; - if ( !is_free_domid(dom) ) - break; - } - else - { - for ( dom =3D rover + 1; dom !=3D rover; dom++ ) - { - if ( dom =3D=3D DOMID_FIRST_RESERVED ) - dom =3D 1; - if ( is_free_domid(dom) ) - break; - } - - ret =3D -ENOMEM; - if ( dom =3D=3D rover ) - break; - - rover =3D dom; - } - - d =3D domain_create(dom, &op->u.createdomain, false); + d =3D domain_create(ret, &op->u.createdomain, false); if ( IS_ERR(d) ) { ret =3D PTR_ERR(d); diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 83069de501..9b7159a743 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -37,6 +37,9 @@ void arch_get_domain_info(const struct domain *d, =20 domid_t get_initial_domain_id(void); =20 +#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) --=20 2.34.1 From nobody Fri Oct 31 23:30:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=proton.me Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1743462368870805.4015654219756; Mon, 31 Mar 2025 16:06:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.933118.1335167 (Exim 4.92) (envelope-from ) id 1tzOCT-00047p-6n; Mon, 31 Mar 2025 23:05:49 +0000 Received: by outflank-mailman (output) from mailman id 933118.1335167; Mon, 31 Mar 2025 23:05:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCT-00047S-0j; Mon, 31 Mar 2025 23:05:49 +0000 Received: by outflank-mailman (input) for mailman id 933118; Mon, 31 Mar 2025 23:05:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCR-00041G-N6 for xen-devel@lists.xenproject.org; Mon, 31 Mar 2025 23:05:47 +0000 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ae1519ff-0e84-11f0-9ea7-5ba50f476ded; Tue, 01 Apr 2025 01:05:47 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ae1519ff-0e84-11f0-9ea7-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=qqcmz64trjcffpymyxvqi372ju.protonmail; t=1743462346; x=1743721546; bh=4TUVPVTtCJK3dKtje9YIdGrxMpCfMsMEMufsQMdkvLM=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=c1aGoYaMkjjaSPKhN1zoD2OBXJOrZ7tr77WobI/YN7NcZt7ebUpcyEmWXZc709qje ev/D23rGNyzj94Sklkh/HMC1Tr1KN+8CkxGH8T783GOHtOsw91ovPV1CqUyDxDGU4G 04EyfLAaPFipJx3EK+2mivsuCvw4J24o62R1PnOi+RZUNYoF1w8pLyxkPbb1fi85g3 SydS1kKz7gO4WvnsMNkhRsv4leNqizwQ8/C6IRR1bWroFWP1nh/UB+zAIeTjAfh3Es ApbkZeVjzhIM4qfX0opPBVIK8eqLx+z1D8ZyDaDvAiVcKOlATtbxpGCRDEvwECkvR/ ta8EzW7yOQNOg== Date: Mon, 31 Mar 2025 23:05:39 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: 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: [PATCH v2 3/7] xen/domain: introduce domid_top() Message-ID: <20250331230508.440198-4-dmukhin@ford.com> In-Reply-To: <20250331230508.440198-1-dmukhin@ford.com> References: <20250331230508.440198-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: e8cabdd52b024f1f8877b00cfc5c255bdba045e5 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1743462372124019100 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin Introduce domid_top() in architecture-independent location to retrieve the highest non-system domain ID for use in console input switch logic. Replace max_init_domid with domid_top(), which obsoletes max_init_domid in the code base. Signed-off-by: Denis Mukhin --- Changes since v1: - promote domid_top to a function which walks through the list of domains to identify the highest non-system domain ID which should be considered for console input rotation - elimitate use of max_init_domid --- 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 | 23 +++++++++++++++++++++++ xen/drivers/char/console.c | 2 +- xen/include/xen/domain.h | 1 + 8 files changed, 25 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 6cf272c160..f107e8eebb 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -25,8 +25,6 @@ struct map_range_data struct rangeset *irq_ranges; }; =20 -extern domid_t max_init_domid; - void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); =20 size_t estimate_efi_size(unsigned int mem_nr_banks); diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index bf39d41e9b..143808f592 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -60,8 +60,6 @@ struct cpuinfo_arm __read_mostly system_cpuinfo; bool __read_mostly acpi_disabled; #endif =20 -domid_t __read_mostly max_init_domid; - static __used void init_done(void) { int rc; diff --git a/xen/arch/ppc/include/asm/setup.h b/xen/arch/ppc/include/asm/se= tup.h index e4f64879b6..956fa6985a 100644 --- a/xen/arch/ppc/include/asm/setup.h +++ b/xen/arch/ppc/include/asm/setup.h @@ -1,6 +1,4 @@ #ifndef __ASM_PPC_SETUP_H__ #define __ASM_PPC_SETUP_H__ =20 -#define max_init_domid (0) - #endif /* __ASM_PPC_SETUP_H__ */ diff --git a/xen/arch/riscv/include/asm/setup.h b/xen/arch/riscv/include/as= m/setup.h index c9d69cdf51..d1fc64b673 100644 --- a/xen/arch/riscv/include/asm/setup.h +++ b/xen/arch/riscv/include/asm/setup.h @@ -5,8 +5,6 @@ =20 #include =20 -#define max_init_domid (0) - void setup_mm(void); =20 void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/se= tup.h index 5c2391a868..296348655b 100644 --- a/xen/arch/x86/include/asm/setup.h +++ b/xen/arch/x86/include/asm/setup.h @@ -69,6 +69,4 @@ extern bool opt_dom0_verbose; extern bool opt_dom0_cpuid_faulting; extern bool opt_dom0_msr_relaxed; =20 -#define max_init_domid (0) - #endif diff --git a/xen/common/domain.c b/xen/common/domain.c index b07d70a7e3..8e8e784b46 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -111,6 +111,29 @@ int domid_alloc(int hint) return domid; } =20 +/* + * Retrieve the highest known non-system domain ID. + */ +domid_t domid_top(void) +{ + struct domain *d; + domid_t i =3D 0; + + spin_lock(&domlist_update_lock); + + for ( d =3D domain_list; + d && (d->domain_id < DOMID_FIRST_RESERVED); + d =3D d->next_in_list ) + { + if ( i < d->domain_id ) + i =3D d->domain_id; + } + + spin_unlock(&domlist_update_lock); + + return i; +} + /* * Insert a domain into the domlist/hash. This allows the domain to be lo= oked * up by domid, and therefore to be the subject of hypercalls/etc. diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index b312a1223e..54163e93fb 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -472,7 +472,7 @@ static void cf_check dump_console_ring_key(unsigned cha= r key) */ static unsigned int __read_mostly console_rx =3D 0; =20 -#define max_console_rx (max_init_domid + 1) +#define max_console_rx (domid_top() + 1) =20 static struct domain *console_get_domain_by_id(domid_t domid) { diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 9b7159a743..c3dda8edf2 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -35,6 +35,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_ge= tdomaininfo *info); void arch_get_domain_info(const struct domain *d, struct xen_domctl_getdomaininfo *info); =20 +domid_t domid_top(void); domid_t get_initial_domain_id(void); =20 #define DOMID_AUTO (-1) --=20 2.34.1 From nobody Fri Oct 31 23:30:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=proton.me Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1743462371566754.4067110517385; Mon, 31 Mar 2025 16:06:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.933131.1335176 (Exim 4.92) (envelope-from ) id 1tzOCc-0004me-Bj; Mon, 31 Mar 2025 23:05:58 +0000 Received: by outflank-mailman (output) from mailman id 933131.1335176; Mon, 31 Mar 2025 23:05:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCc-0004mX-8F; Mon, 31 Mar 2025 23:05:58 +0000 Received: by outflank-mailman (input) for mailman id 933131; Mon, 31 Mar 2025 23:05:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCb-00041G-3f for xen-devel@lists.xenproject.org; Mon, 31 Mar 2025 23:05:57 +0000 Received: from mail-10629.protonmail.ch (mail-10629.protonmail.ch [79.135.106.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b3c3c743-0e84-11f0-9ea7-5ba50f476ded; Tue, 01 Apr 2025 01:05:56 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b3c3c743-0e84-11f0-9ea7-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743462355; x=1743721555; bh=fFhCvlB/1zqro9CkPetkZk3bqFHwLxMCAaqoQPXzqBA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=DO7B4oP0DNoI1UvAj5bAZiTIh7kMYXc3vLUqJ9nqfYR/csV+ncsFsmY4gM534ZmOi 78v2Pl5aD02A6GLFWbc4O0e3o1Ndww8GR2YbkyiGKFbxrP+t6bjiXk3ZR6IruHdoSV oMJru/PfOz0z7Wq4RS77N+T/E7vWEQHfPgfC9+sb6DBOUEd9afQHx5wXmHByHirtTY mW4R5u6OKRJyucHgJmuOc9nDX0vD2II0Qjvoou60m9ipRW1+bu8xr+NLxKXE+Nk3Xt VM6z/7AhKrb9c2nv1wCrjfLmOKjTiCTlTRA1zOz/qSP0DesLgkT1J4wbTVq/hlxfBN gV1H5OSsydC5A== Date: Mon, 31 Mar 2025 23:05:48 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: 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: [PATCH v2 4/7] xen/console: rename switch_serial_input() to console_switch_input() Message-ID: <20250331230508.440198-5-dmukhin@ford.com> In-Reply-To: <20250331230508.440198-1-dmukhin@ford.com> References: <20250331230508.440198-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: b14ccfa3a58e4e78b6fca6b051d930587e309221 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1743462373051019100 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin 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 --- Changes since v1: - rename console_switch_focus() to console_switch_input() --- xen/drivers/char/console.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 54163e93fb..48da4e5838 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -511,7 +511,7 @@ static bool console_is_input_allowed(domid_t domid) return !!d; } =20 -static void switch_serial_input(void) +static void console_switch_input(void) { unsigned int next_rx =3D console_rx; =20 @@ -603,7 +603,7 @@ static void cf_check serial_rx(char c) /* We eat CTRL- in groups of 3 to switch console inpu= t. */ if ( ++switch_code_count =3D=3D 3 ) { - switch_serial_input(); + console_switch_input(); switch_code_count =3D 0; } return; @@ -1147,7 +1147,7 @@ void __init console_endboot(void) "toggle host/guest log level adjustment", 0); =20 /* Serial input is directed to DOM0 by default. */ - switch_serial_input(); + console_switch_input(); } =20 int __init console_has(const char *device) --=20 2.34.1 From nobody Fri Oct 31 23:30:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=proton.me Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1743462663673321.0887743784359; Mon, 31 Mar 2025 16:11:03 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.933164.1335206 (Exim 4.92) (envelope-from ) id 1tzOHI-0008Kw-Ac; Mon, 31 Mar 2025 23:10:48 +0000 Received: by outflank-mailman (output) from mailman id 933164.1335206; Mon, 31 Mar 2025 23:10:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOHI-0008Kn-7c; Mon, 31 Mar 2025 23:10:48 +0000 Received: by outflank-mailman (input) for mailman id 933164; Mon, 31 Mar 2025 23:10:46 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCl-00041G-Dc for xen-devel@lists.xenproject.org; Mon, 31 Mar 2025 23:06:07 +0000 Received: from mail-10628.protonmail.ch (mail-10628.protonmail.ch [79.135.106.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b9f7c1f9-0e84-11f0-9ea7-5ba50f476ded; Tue, 01 Apr 2025 01:06:06 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b9f7c1f9-0e84-11f0-9ea7-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743462364; x=1743721564; bh=yUXhOIFrBvxndgTJ0FE4JLOgaaCgGWn626ZFG9p4vGE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=cLVgyW5rQdC5hksr9jOmetIysG9h/yWKWnlzJNGbZ314rk2Ev1DxPXxxmSaNcb91C cJnX19m9NLm9q3LFPK9FCwi4wGmEAPWIa8bNZC4GSWNgmnUZwZbBCOodMsBis83HOu q6jAbEHEIn80ltllHeW4F/TbAN5UuiSOZW6W9RvkqQauIGEaJk0oHziTsi6EC8gqkm te2T1frqQlxW4muz+1TMmwauBAxw9jrZiVgVxfXO/pLAEqsW8LD1CuyAKiQr9kz3/u TfBTusKWaM3AXLaUqpVGHOl7hQdiWTiTdJtJWQuawC/mlor03+U1dZXEdodDtC4Ciy 55KyOCOcsJtYw== Date: Mon, 31 Mar 2025 23:05:57 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: 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: [PATCH v2 5/7] xen/console: rename console_rx to console_focus Message-ID: <20250331230508.440198-6-dmukhin@ford.com> In-Reply-To: <20250331230508.440198-1-dmukhin@ford.com> References: <20250331230508.440198-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 3f33fe318213ab227d7b2ccdc0f8d1b8cf3eb1db MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1743462665727019000 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin Update the symbol name in preparation for the semantic change to the physical console input owner domain identifier. No functional change. Signed-off-by: Denis Mukhin --- Changes since v1: - keep the original console_focus description --- xen/drivers/char/console.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 48da4e5838..42974c0af7 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -470,7 +470,7 @@ static void cf_check dump_console_ring_key(unsigned cha= r key) * console_rx=3D1 =3D> input to dom0 (or the sole shim domain) * console_rx=3DN =3D> input to dom(N-1) */ -static unsigned int __read_mostly console_rx =3D 0; +static unsigned int __read_mostly console_focus =3D 0; =20 #define max_console_rx (domid_top() + 1) =20 @@ -491,9 +491,9 @@ static struct domain *console_get_domain_by_id(domid_t = domid) =20 struct domain *console_get_domain(void) { - if ( console_rx =3D=3D 0 ) + if ( console_focus =3D=3D 0 ) return NULL; - return console_get_domain_by_id(console_rx - 1); + return console_get_domain_by_id(console_focus - 1); } =20 void console_put_domain(struct domain *d) @@ -513,7 +513,7 @@ static bool console_is_input_allowed(domid_t domid) =20 static void console_switch_input(void) { - unsigned int next_rx =3D console_rx; + unsigned int next_rx =3D console_focus; =20 /* * Rotate among Xen, dom0 and boot-time created domUs while skipping @@ -525,7 +525,7 @@ static void console_switch_input(void) =20 if ( next_rx++ >=3D max_console_rx ) { - console_rx =3D 0; + console_focus =3D 0; printk("*** Serial input to Xen"); break; } @@ -537,7 +537,7 @@ static void console_switch_input(void) =20 if ( console_is_input_allowed(domid) ) { - console_rx =3D next_rx; + console_focus =3D next_rx; printk("*** Serial input to DOM%u", domid); break; } @@ -554,7 +554,7 @@ static void __serial_rx(char c) struct domain *d; int rc =3D 0; =20 - if ( console_rx =3D=3D 0 ) + if ( console_focus =3D=3D 0 ) return handle_keypress(c, false); =20 d =3D console_get_domain(); @@ -1135,7 +1135,7 @@ void __init console_endboot(void) * a useful 'how to switch' message. */ if ( opt_conswitch[1] =3D=3D 'x' ) - console_rx =3D max_console_rx; + console_focus =3D max_console_rx; =20 register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", = 0); --=20 2.34.1 From nobody Fri Oct 31 23:30:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=proton.me Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1743462659249273.161992020649; Mon, 31 Mar 2025 16:10:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.933159.1335187 (Exim 4.92) (envelope-from ) id 1tzOHA-0007Te-Ss; Mon, 31 Mar 2025 23:10:40 +0000 Received: by outflank-mailman (output) from mailman id 933159.1335187; Mon, 31 Mar 2025 23:10:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOHA-0007TX-OX; Mon, 31 Mar 2025 23:10:40 +0000 Received: by outflank-mailman (input) for mailman id 933159; Mon, 31 Mar 2025 23:10:40 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOCv-0003Id-9M for xen-devel@lists.xenproject.org; Mon, 31 Mar 2025 23:06:17 +0000 Received: from mail-10629.protonmail.ch (mail-10629.protonmail.ch [79.135.106.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bf3b71f5-0e84-11f0-9ffb-bf95429c2676; Tue, 01 Apr 2025 01:06:15 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bf3b71f5-0e84-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743462374; x=1743721574; bh=nA0e2TwhrmernoJeWCrYjCUgWR7cF87XdlQEarMxjlo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=C6nqmLNoL0nngaACQE0eRKjc2s9vhF7zfdMbcxNdvETuI/R0oRSeLe64aXvCDwrD2 BgLS/D3PTGou0OmQiTiNy+IwITGqtVHncvV4+gAQlBk+ReMDJ4S0lKmKjjI19k5AuD IEKZ1VldXSX7+cI8WYC7ZQnB6Civpc+fDs0IgoOwCmWAgdcOK53FkEjNLkSLtea+TR pjPID1RgMXiTv5Mzd2bXewXe0IiLJylQ0rJ4EkiOA6gkc/zwnTeRZAsMvoqWGE3Br2 jW0/aLBr0HBMYjMyeW356e1i/9p7J66NTpdsMBDLXq+3+2LUSTZdqxq01IjNc3Lb2a MBRdli7mNQ4wg== Date: Mon, 31 Mar 2025 23:06:05 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: 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: [PATCH v2 6/7] xen/console: introduce console_set_focus() Message-ID: <20250331230508.440198-7-dmukhin@ford.com> In-Reply-To: <20250331230508.440198-1-dmukhin@ford.com> References: <20250331230508.440198-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 9cf4c79d70e4712c1505e0ff6c87326deab81cd4 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1743462659632019000 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin 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. Signed-off-by: Denis Mukhin --- Changes since v1: - update console_focus description --- xen/drivers/char/console.c | 88 ++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 51 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 42974c0af7..9905ffd6b9 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -462,17 +462,12 @@ static void cf_check dump_console_ring_key(unsigned c= har key) =20 /* * CTRL- 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_rx=3D0 =3D> input to xen - * console_rx=3D1 =3D> input to dom0 (or the sole shim domain) - * console_rx=3DN =3D> input to dom(N-1) - */ -static unsigned int __read_mostly console_focus =3D 0; =20 -#define max_console_rx (domid_top() + 1) +/* Console owner domain identifier. */ +static domid_t __read_mostly console_focus =3D DOMID_XEN; =20 static struct domain *console_get_domain_by_id(domid_t domid) { @@ -491,9 +486,7 @@ static struct domain *console_get_domain_by_id(domid_t = domid) =20 struct domain *console_get_domain(void) { - if ( console_focus =3D=3D 0 ) - return NULL; - return console_get_domain_by_id(console_focus - 1); + return console_get_domain_by_id(console_focus); } =20 void console_put_domain(struct domain *d) @@ -511,42 +504,43 @@ static bool console_is_input_allowed(domid_t domid) return !!d; } =20 -static void console_switch_input(void) +/* + * Set owner of the physical console input. + */ +static bool cf_check console_set_focus(domid_t domid) { - unsigned int next_rx =3D console_focus; + if ( domid =3D=3D DOMID_XEN ) + printk("*** Serial input to Xen"); + else if ( console_is_input_allowed(domid) ) + printk("*** Serial input to DOM%u", domid); + else + return false; =20 - /* - * 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++ >=3D max_console_rx ) - { - console_focus =3D 0; - printk("*** Serial input to Xen"); - break; - } - - if ( consoled_is_enabled() && next_rx =3D=3D 1 ) - domid =3D get_initial_domain_id(); - else - domid =3D next_rx - 1; - - if ( console_is_input_allowed(domid) ) - { - console_focus =3D next_rx; - printk("*** Serial input to DOM%u", domid); - break; - } - } + console_focus =3D domid; =20 if ( switch_code ) printk(" (type 'CTRL-%c' three times to switch input)", opt_conswitch[0]); printk("\n"); + + return true; +} + +/* + * Switch console focus. + * Rotates input focus among Xen and domains with console input permission. + */ +static void console_switch_input(void) +{ + const domid_t n =3D domid_top() + 1; + domid_t i =3D ( console_focus =3D=3D DOMID_XEN ) + ? get_initial_domain_id() : console_focus + 1; + + for ( ; i < n; i++ ) + if ( console_set_focus(i) ) + return; + + ASSERT(console_set_focus(DOMID_XEN)); } =20 static void __serial_rx(char c) @@ -554,7 +548,7 @@ static void __serial_rx(char c) struct domain *d; int rc =3D 0; =20 - if ( console_focus =3D=3D 0 ) + if ( console_focus =3D=3D DOMID_XEN ) return handle_keypress(c, false); =20 d =3D console_get_domain(); @@ -1129,14 +1123,6 @@ void __init console_endboot(void) =20 video_endboot(); =20 - /* - * 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] =3D=3D 'x' ) - console_focus =3D max_console_rx; - register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", = 0); register_irq_keyhandler('+', &do_inc_thresh, @@ -1146,8 +1132,8 @@ void __init console_endboot(void) register_irq_keyhandler('G', &do_toggle_guest, "toggle host/guest log level adjustment", 0); =20 - /* Serial input is directed to DOM0 by default. */ - console_switch_input(); + if ( opt_conswitch[1] !=3D 'x' ) + (void)console_set_focus(get_initial_domain_id()); } =20 int __init console_has(const char *device) --=20 2.34.1 From nobody Fri Oct 31 23:30:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=proton.me Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1743462659162846.2547341801483; Mon, 31 Mar 2025 16:10:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.933160.1335196 (Exim 4.92) (envelope-from ) id 1tzOHG-0007wJ-3c; Mon, 31 Mar 2025 23:10:46 +0000 Received: by outflank-mailman (output) from mailman id 933160.1335196; Mon, 31 Mar 2025 23:10:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOHG-0007vk-05; Mon, 31 Mar 2025 23:10:46 +0000 Received: by outflank-mailman (input) for mailman id 933160; Mon, 31 Mar 2025 23:10:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzOD2-0003Id-KJ for xen-devel@lists.xenproject.org; Mon, 31 Mar 2025 23:06:24 +0000 Received: from mail-24418.protonmail.ch (mail-24418.protonmail.ch [109.224.244.18]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c3a4c86b-0e84-11f0-9ffb-bf95429c2676; Tue, 01 Apr 2025 01:06:23 +0200 (CEST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c3a4c86b-0e84-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743462382; x=1743721582; bh=SdBSfazbTf7ETSXxJ/9/JRpjBT4nbA/cZZmRLe9iXXo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=ZkAT7aY9ciihxoUHuqNbDsECqz/6oeK0GS+Ea9FjR7UOYZdrhg3xTBaiqGYIjIlGn JHSFxZ7iJMHKiCD2KZEsOWmZMUSsfcBv7RiZvIJx80Gho2Vtdu7HtHFPe73RXHaTrd Tju9z/N53Db7VVeOiaZDeBCq4aGXs9NWmzfn/SiIded4iMzYv7E5dcmztHbAhB6eE/ BjSZPf8ifImIX3dFxxWrupHfpXbjBcL8j4OdHATpFBxfWs6YXq/1GgfzCd782xHZen 2cQ3uFWC2O6BXbuLRDQxC+UR948M6u0Unkou2czPgsOidzEjM1pOVazeZOaOtRPAtX XddxIzjF506Sg== Date: Mon, 31 Mar 2025 23:06:16 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: 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: [PATCH v2 7/7] xen/console: introduce console_get_focus() Message-ID: <20250331230508.440198-8-dmukhin@ford.com> In-Reply-To: <20250331230508.440198-1-dmukhin@ford.com> References: <20250331230508.440198-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 1ffe553bbbf65e1147056fde733ce3781ed5df05 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1743462659535019000 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin 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. Signed-off-by: Denis Mukhin --- 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(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 147958eee8..9ce6151c2a 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -78,12 +78,11 @@ static void vpl011_write_data_xen(struct domain *d, uin= t8_t data) unsigned long flags; struct vpl011 *vpl011 =3D &d->arch.vpl011; struct vpl011_xen_backend *intf =3D vpl011->backend.xen; - struct domain *input =3D console_get_domain(); =20 VPL011_LOCK(d, flags); =20 intf->out[intf->out_prod++] =3D data; - if ( d =3D=3D input ) + if ( d->domain_id =3D=3D console_get_focus() ) { if ( intf->out_prod =3D=3D 1 ) { @@ -123,8 +122,6 @@ static void vpl011_write_data_xen(struct domain *d, uin= t8_t data) vpl011_update_interrupt_status(d); =20 VPL011_UNLOCK(d, flags); - - console_put_domain(input); } =20 /* diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 9905ffd6b9..888dabe8af 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -484,12 +484,12 @@ static struct domain *console_get_domain_by_id(domid_= t domid) return NULL; } =20 -struct domain *console_get_domain(void) +static struct domain *console_get_domain(void) { return console_get_domain_by_id(console_focus); } =20 -void console_put_domain(struct domain *d) +static void console_put_domain(struct domain *d) { if ( d ) rcu_unlock_domain(d); @@ -526,6 +526,11 @@ static bool cf_check console_set_focus(domid_t domid) return true; } =20 +domid_t console_get_focus(void) +{ + return console_focus; +} + /* * Switch console focus. * Rotates input focus among Xen and domains with console input permission. diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 83cbc9fbda..19da2b755c 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -32,8 +32,7 @@ void console_end_sync(void); void console_start_log_everything(void); void console_end_log_everything(void); =20 -struct domain *console_get_domain(void); -void console_put_domain(struct domain *d); +domid_t console_get_focus(void); =20 /* * Steal output from the console. Returns +ve identifier, else -ve error. --=20 2.34.1