From patchwork Tue Mar 18 23:36:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14021743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFE44C35FFB for ; Tue, 18 Mar 2025 23:37:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.919886.1324225 (Exim 4.92) (envelope-from ) id 1tugUE-0004Da-2b; Tue, 18 Mar 2025 23:36:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 919886.1324225; Tue, 18 Mar 2025 23:36:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tugUD-0004DT-WC; Tue, 18 Mar 2025 23:36:41 +0000 Received: by outflank-mailman (input) for mailman id 919886; Tue, 18 Mar 2025 23:36:40 +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 1tugUC-0003zY-M0 for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 23:36:40 +0000 Received: from mail-24418.protonmail.ch (mail-24418.protonmail.ch [109.224.244.18]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d72418e2-0451-11f0-9abc-95dc52dad729; Wed, 19 Mar 2025 00:36:40 +0100 (CET) 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: d72418e2-0451-11f0-9abc-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1742340998; x=1742600198; bh=QtdLXYxNwzbKQmZe/6N+UHeOHnwW7yUtlmw52BzQ2+Y=; 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=iau+V0ryMHpEWMABNwtTh4Jyv7bidE5fCdIKIGjB6m2DFyBT7BctXQaCa3w08/pw7 NozMugX8QQsXzUSNz23k9kjxOYVt6OKE1CuIQscDSN6E1IRsS9+jGidgErLuY5Cl7q O+N7ecgnc9b5wcWwWSHXLwhBktUcB/MDcxDeULlTKjs/L9XmyK2ibjlIEyjal2Q48M uvSupxnbuHZB61yP3vb9uc43l+p6RdMO8D7LIGXblrCWZcMvswTm6p9BpJrHV8TsTl Sx/t3saCZK5cYONg2PQu8ZRapMRxT6QmKjoSwdZsz57p3bQTTt5aapHaLgFIizy0NW kJyrA+TQIzBiw== Date: Tue, 18 Mar 2025 23:36:34 +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 v1 1/8] xen/console: fix trailing whitespaces Message-ID: <20250318233617.849903-2-dmukhin@ford.com> In-Reply-To: <20250318233617.849903-1-dmukhin@ford.com> References: <20250318233617.849903-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: ea03fa4e2f7a43ce4ce55988ca7f5e32dfdf1a42 MIME-Version: 1.0 Remove trailing whitespaces in the console driver. No functional change. Signed-off-by: Denis Mukhin Acked-by: Jan Beulich --- 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 ba428199d2..c3150fbdb7 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -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) { From patchwork Tue Mar 18 23:36:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14021742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19EDBC282EC for ; Tue, 18 Mar 2025 23:36:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.919887.1324236 (Exim 4.92) (envelope-from ) id 1tugUH-0004Sx-DK; Tue, 18 Mar 2025 23:36:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 919887.1324236; Tue, 18 Mar 2025 23:36:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tugUH-0004Sq-A9; Tue, 18 Mar 2025 23:36:45 +0000 Received: by outflank-mailman (input) for mailman id 919887; Tue, 18 Mar 2025 23:36:43 +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 1tugUF-0004Rg-Ov for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 23:36:43 +0000 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d850c6d9-0451-11f0-9899-31a8f345e629; Wed, 19 Mar 2025 00:36:41 +0100 (CET) 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: d850c6d9-0451-11f0-9899-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1742341000; x=1742600200; bh=owVvjEcu2jhrINTS+SqEPbxvoEDw03hS/2Hjj7grNLw=; 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=LCC4KcnYfB5GtNUKbuYuKGGRwxSmtJ449Xq1CownOGpRmZyfi8H/2GuS5oQqGeYVK +KvvnKbuOnBMwXmuAgOg5sXZKVyxazE5ko4HMYR69fUmuKAslrqCL0amhp9PRUYUBL xqB1m4k0lHZXrxwqI0lzPOSgnlKKikvmyeGL69uq8SnACG9lrUkmSy+cL6QJ5mOIKr 0zipMnMjLebgULxIAVS3tHMkuDQOtdN1rujTVf/MwQCYJXZyQgI9CI8fPLzer7xIjw EMtD4Gy22OG5K8MtJKMdpP6WKIs65SIOzbuiTNNB8eZg96copwMQBJfiJe0tKnisST npYejPzKJGaHA== Date: Tue, 18 Mar 2025 23:36:37 +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 v1 2/8] xen/console: introduce console input permission Message-ID: <20250318233617.849903-3-dmukhin@ford.com> In-Reply-To: <20250318233617.849903-1-dmukhin@ford.com> References: <20250318233617.849903-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 4b739d5ca3de234e1019e5b8e8ce34db19cc8ae8 MIME-Version: 1.0 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 --- 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(-) 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); + d->console.input_allowed = true; + return 0; 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_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) 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, old_hwdom = hardware_domain; hardware_domain = d; + + d->console.input_allowed = true; } 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..d7d9800095 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -474,11 +474,26 @@ static unsigned int __read_mostly console_rx = 0; #define max_console_rx (max_init_domid + 1) +static struct domain *console_get_domain_by_id(domid_t domid) +{ + struct domain *d = 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 == 0 ) return NULL; - return rcu_lock_domain_by_id(console_rx - 1); + return console_get_domain_by_id(console_rx - 1); } void console_put_domain(struct domain *d) @@ -487,6 +502,15 @@ void console_put_domain(struct domain *d) rcu_unlock_domain(d); } +static bool console_check_focus_by_id(domid_t domid) +{ + struct domain *d = console_get_domain_by_id(domid); + + console_put_domain(d); + + return !!d; +} + static void switch_serial_input(void) { unsigned int next_rx = console_rx; @@ -498,7 +522,6 @@ static void switch_serial_input(void) for ( ; ; ) { domid_t domid; - struct domain *d; if ( next_rx++ >= max_console_rx ) { @@ -511,10 +534,9 @@ static void switch_serial_input(void) domid = get_initial_domain_id(); else domid = next_rx - 1; - d = rcu_lock_domain_by_id(domid); - if ( d ) + + if ( console_check_focus_by_id(domid) ) { - rcu_unlock_domain(d); console_rx = next_rx; printk("*** Serial input to DOM%u", domid); break; @@ -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; + + default: + d->console.input_allowed = false; + guest_printk(d, + XENLOG_ERR "disabled console input: %d\n", + rc); + break; + } console_put_domain(d); } 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); static inline struct page_list_head *page_to_list( From patchwork Tue Mar 18 23:36:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14021744 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6997C35FFC for ; Tue, 18 Mar 2025 23:37:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.919888.1324246 (Exim 4.92) (envelope-from ) id 1tugUJ-0004iY-MQ; Tue, 18 Mar 2025 23:36:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 919888.1324246; Tue, 18 Mar 2025 23:36:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tugUJ-0004iR-Ik; Tue, 18 Mar 2025 23:36:47 +0000 Received: by outflank-mailman (input) for mailman id 919888; Tue, 18 Mar 2025 23:36:46 +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 1tugUI-0004Rg-7r for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 23:36:46 +0000 Received: from mail-10631.protonmail.ch (mail-10631.protonmail.ch [79.135.106.31]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id da0c246c-0451-11f0-9899-31a8f345e629; Wed, 19 Mar 2025 00:36:44 +0100 (CET) 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: da0c246c-0451-11f0-9899-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1742341003; x=1742600203; bh=an7oco9t2MW1aPCyVdsDXyaEu4dmL76TiBG8/A0s7xA=; 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=PhDhJTdJEEerElqeuorniNkGGyf08ZNC7jbDQr8SnfQcjhNH9lpaqpmFsXJDsbtag dXj6hrtrbd2FcsGYGGv744CLVokUdWf+PnZ/nkFX/8+TOi7RY2woQxm9wuFehHl2F7 gGZiDR9yOPGoNH60k4ciy48CYZ45Vp9NOcZfup/cddMy10v7Ky1wiG0wOoMDbqMrte 1YN+KRYA0rWcj/oOUWF6nxInBCw29jeIhQeNyB5lD3149eN5SCO0jV0wkY8muHkz/k xeow6G6x6MKoGCu0xKj+X7xcjPDybcBMYIYosFGnYviRi/wppWOTk06CAd7Fm1e7Vg LPdpu4JyNtceQ== Date: Tue, 18 Mar 2025 23:36:40 +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 v1 3/8] xen/domain: introduce domid_top Message-ID: <20250318233617.849903-4-dmukhin@ford.com> In-Reply-To: <20250318233617.849903-1-dmukhin@ford.com> References: <20250318233617.849903-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 68345f0592094b4e9be75b2581fdeb838d44de27 MIME-Version: 1.0 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. Signed-off-by: Denis Mukhin --- 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(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 573b0d25ae..d7d7665c0a 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -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)); diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.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; }; -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); diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index ffcae900d7..ab60f0d189 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 -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/setup.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__ -#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/asm/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 @@ #include -#define max_init_domid (0) - void setup_mm(void); 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/setup.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; -#define max_init_domid (0) - #endif diff --git a/xen/common/domain.c b/xen/common/domain.c index b9f549c617..dac910d454 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -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. diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index d7d9800095..d04a5335ce 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 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) { diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 83069de501..b7425827b8 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -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. */ From patchwork Tue Mar 18 23:36:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14021745 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AEFECC35FF3 for ; Tue, 18 Mar 2025 23:37:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.919892.1324256 (Exim 4.92) (envelope-from ) id 1tugUO-00054h-TW; Tue, 18 Mar 2025 23:36:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 919892.1324256; Tue, 18 Mar 2025 23:36:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tugUO-00054O-QI; Tue, 18 Mar 2025 23:36:52 +0000 Received: by outflank-mailman (input) for mailman id 919892; Tue, 18 Mar 2025 23:36:52 +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 1tugUO-0004Rg-21 for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 23:36:52 +0000 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id dd39c87a-0451-11f0-9899-31a8f345e629; Wed, 19 Mar 2025 00:36:50 +0100 (CET) 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: dd39c87a-0451-11f0-9899-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1742341008; x=1742600208; bh=5+7Swk3BoRdHzWMaplmAr3XGJqn1SC0JZyVTBod6PsE=; 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=lgw/v88V3dGHf1I0jQKeceXMMjN3X9xQiDpef/IR4E+FIoElURXcaM2bCmLMe8m9d IJkZ1+d4mi0Ve9JpYiOR1pn9OsuGxz7poAT188JFSSwXQ4Hfsu/Q2N6gSxXE82UHDd WpSDVPIepjECTV64yPle+/w9IBs0Uom2rYrh0KFTg8PE7aPeQupKaQp+E0dUoRJmu2 krKB4egtruJY/kAaN3kov6BY+l0+BykusHLCPZ4d2bDTtMum6Eh07bar6PMowTe8Fu 6+HqQydSjLCWYXxPdSSnW/VJs+4G72zS8tkiiBBJ997THbVN66yNR7K/JAEgsq96mD HX4fQH4MpwkQA== Date: Tue, 18 Mar 2025 23:36:44 +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 v1 4/8] xen/domain: introduce domid_alloc() Message-ID: <20250318233617.849903-5-dmukhin@ford.com> In-Reply-To: <20250318233617.849903-1-dmukhin@ford.com> References: <20250318233617.849903-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: b4c7297e86a6cd66f321795cab7881583df8818c MIME-Version: 1.0 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). Signed-off-by: Denis Mukhin --- 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(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index d7d7665c0a..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 = 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)); 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 = 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); } /* diff --git a/xen/common/domctl.c b/xen/common/domctl.c index bfe2e1f9f0..9964aa000a 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -63,6 +63,46 @@ static inline int is_free_domid(domid_t dom) return 0; } +/* + * 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 >= 0 && hint < DOMID_FIRST_RESERVED ) + { + if ( !is_free_domid(hint) ) + return -EEXIST; + + domid = hint; + } + else + { + for ( domid = domid_top + 1; domid != domid_top; domid++ ) + { + if ( domid == DOMID_FIRST_RESERVED ) + domid = 0; + if ( domid == hardware_domid ) + continue; + if ( is_free_domid(domid) ) + break; + } + + if ( domid == domid_top ) + return -ENOMEM; + } + + if ( domid_top < domid ) + domid_top = domid; + + return domid; +} + void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info) { struct vcpu *v; @@ -421,34 +461,11 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) case XEN_DOMCTL_createdomain: { - domid_t dom; - static domid_t rover = 0; + ret = domid_alloc(op->domain); + if ( ret < 0 ) + break; - dom = op->domain; - if ( (dom > 0) && (dom < DOMID_FIRST_RESERVED) ) - { - ret = -EEXIST; - if ( !is_free_domid(dom) ) - break; - } - else - { - for ( dom = rover + 1; dom != rover; dom++ ) - { - if ( dom == DOMID_FIRST_RESERVED ) - dom = 1; - if ( is_free_domid(dom) ) - break; - } - - ret = -ENOMEM; - if ( dom == rover ) - break; - - rover = dom; - } - - d = domain_create(dom, &op->u.createdomain, false); + d = domain_create(ret, &op->u.createdomain, false); if ( IS_ERR(d) ) { ret = PTR_ERR(d); diff --git a/xen/common/kernel.c b/xen/common/kernel.c index 8b63ca55f1..50c44b986e 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -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); diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index b7425827b8..c91b9704de 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -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) From patchwork Tue Mar 18 23:36:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14021746 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C57C4C282EC for ; Tue, 18 Mar 2025 23:37:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.919906.1324266 (Exim 4.92) (envelope-from ) id 1tugUY-0005t3-5X; Tue, 18 Mar 2025 23:37:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 919906.1324266; Tue, 18 Mar 2025 23:37:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tugUY-0005sw-2O; Tue, 18 Mar 2025 23:37:02 +0000 Received: by outflank-mailman (input) for mailman id 919906; Tue, 18 Mar 2025 23:37:00 +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 1tugUW-0003zY-Js for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 23:37:00 +0000 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dfc467e9-0451-11f0-9abc-95dc52dad729; Wed, 19 Mar 2025 00:36:54 +0100 (CET) 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: dfc467e9-0451-11f0-9abc-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=3fi74tjqgbbwzowscapbqgn4tu.protonmail; t=1742341013; x=1742600213; bh=CnZXSLA5dm7t4GDjx0s2ayocR6HlIoQPG/eIj0cmur4=; 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=gvREQ0oC6sorljs9P37CDBcXbr1AIfNRvu3FXW5MZy1Zeaa9FNBVxJd4K/Bmv62iU kqSWO5yqeSEQkkfeTcnLObqkt49OjXeSCaEOKSQZrE84ORkUvjNKcOuy2iYhEUr9pa OI5AQzi8Qkt2BKL3SGMiNUDCbb6xTfv4gKL/Inho8I+Q+4nHx+X8N6RL3wqu29jdsS LgfO5+bU61tXUGpYljl3ri8eseGlqKVA66G6NZ41bm9GZ4bQAxTTNxGA7/SsZQKzaj 0q5R87YdXi0kYsABHkxavL1DmCUMAHXzlho1NTg50QxAabsQ1IdawwOlGtI1Yu5Scz P7p4ShkV6P5eA== Date: Tue, 18 Mar 2025 23:36:49 +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 v1 5/8] xen/console: rename switch_serial_input() to console_switch_focus() Message-ID: <20250318233617.849903-6-dmukhin@ford.com> In-Reply-To: <20250318233617.849903-1-dmukhin@ford.com> References: <20250318233617.849903-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 39587d8bc25c625f4d86e9a97312bdd5666aa16f MIME-Version: 1.0 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 --- 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 d04a5335ce..5910ff701c 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -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- 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) From patchwork Tue Mar 18 23:36:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14021747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7323C35FF3 for ; Tue, 18 Mar 2025 23:37:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.919910.1324275 (Exim 4.92) (envelope-from ) id 1tugUZ-00068X-DO; Tue, 18 Mar 2025 23:37:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 919910.1324275; Tue, 18 Mar 2025 23:37:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tugUZ-00068O-9s; Tue, 18 Mar 2025 23:37:03 +0000 Received: by outflank-mailman (input) for mailman id 919910; Tue, 18 Mar 2025 23:37:02 +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 1tugUX-0003zY-Uk for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 23:37:02 +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 e3c9c138-0451-11f0-9abc-95dc52dad729; Wed, 19 Mar 2025 00:37:01 +0100 (CET) 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: e3c9c138-0451-11f0-9abc-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=3f5ub7udzjca3a7xuimpehsshq.protonmail; t=1742341020; x=1742600220; bh=44jWyUHkeGYsWs6B7WroNwJN7y0NMAav7xOviMoLEyM=; 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=C41k7+eSoxGga9o6SZ5AC/OVvvYkegAtrbS3cN0FfJyfaZC1YTlAyTZIyhYQeCeqK cmXHWKJPDKceR7rlAMjcg+npv7hszu42GH3N02IiSLbtlDWCCoiEgmzM2tXIoiI3iv aGr65dgaftaJEGUL5a9NQylUFhIuTlvKqcokfEcYpqEGt1t+25W+a6ImSYwoyKXH7y IhSYDmyIdqMaFi0FJJLXx1rqAOfBTAIntDBRK/1D3GFxlgFvpbCQB+XFGDfiFEpA6r rAd59/WFNiK48hrOzxRmhi2iFToqu9L3rXxBwRjnRpvAqHTmFtAlxd7fT7zhpH1Uyz yBEZsIsDxY0GQ== Date: Tue, 18 Mar 2025 23:36:53 +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 v1 6/8] xen/console: rename console_rx to console_focus Message-ID: <20250318233617.849903-7-dmukhin@ford.com> In-Reply-To: <20250318233617.849903-1-dmukhin@ford.com> References: <20250318233617.849903-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 1c6e008ce3b97861f4cb50bac51ddf416733710b MIME-Version: 1.0 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 --- xen/drivers/char/console.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 5910ff701c..3d538510f4 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -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); From patchwork Tue Mar 18 23:37:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14021748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6840DC282EC for ; Tue, 18 Mar 2025 23:37:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.919915.1324285 (Exim 4.92) (envelope-from ) id 1tugUd-0006XX-PM; Tue, 18 Mar 2025 23:37:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 919915.1324285; Tue, 18 Mar 2025 23:37:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tugUd-0006XK-MR; Tue, 18 Mar 2025 23:37:07 +0000 Received: by outflank-mailman (input) for mailman id 919915; Tue, 18 Mar 2025 23:37:06 +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 1tugUc-0004Rg-OM for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 23:37:06 +0000 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e62e5ca6-0451-11f0-9899-31a8f345e629; Wed, 19 Mar 2025 00:37:05 +0100 (CET) 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: e62e5ca6-0451-11f0-9899-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1742341024; x=1742600224; bh=t/sF/l8n4hvHC7Py3lxhnLyK1qkxCg/TVTQUmwT1xmE=; 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=QnQc37B0lZ/5ePkqQQCbS5q7w6GGJ5ZlyguFpYe7LxdSzft8LneyBeVAacN6/DR4L koJZBgGRkJS8NLH5XnMisWGT0FuS8bWM8+tIXmeahENkyXLLUJuJWdTwYFbNG6COhP lYRydQngnzdg7SJVPF7EzdcMK++4vEUOUFLp9A7f67c965GayxoDtxk+C0Mgd83Op6 ZJVvltI7DponNppJUMwd7CJ+rsk5y+mp0KIhVBJOD5GjFTCifAx+s1zp3XMnwG0cvc 3iY7S5v+DMdDcFhLhSSgS9PtyO35ZUJ+fsF8i3SwJRLNIVkgKxAqtZlmTyog4QJvih ZCFIujC1/UvMA== Date: Tue, 18 Mar 2025 23:37:00 +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 v1 7/8] xen/console: introduce console_set_focus() Message-ID: <20250318233617.849903-8-dmukhin@ford.com> In-Reply-To: <20250318233617.849903-1-dmukhin@ford.com> References: <20250318233617.849903-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: fd269600793e4dda519a7b9dcfd7ee8a580717a5 MIME-Version: 1.0 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 --- xen/drivers/char/console.c | 81 ++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 47 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 3d538510f4..0e2349a868 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -462,14 +462,12 @@ static void cf_check dump_console_ring_key(unsigned char key) /* * 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 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) From patchwork Tue Mar 18 23:37:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14021749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB208C282EC for ; Tue, 18 Mar 2025 23:40:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.919966.1324296 (Exim 4.92) (envelope-from ) id 1tugY4-00019G-7v; Tue, 18 Mar 2025 23:40:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 919966.1324296; Tue, 18 Mar 2025 23:40: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 1tugY4-000199-50; Tue, 18 Mar 2025 23:40:40 +0000 Received: by outflank-mailman (input) for mailman id 919966; Tue, 18 Mar 2025 23:40:38 +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 1tugUf-0004Rg-Mu for xen-devel@lists.xenproject.org; Tue, 18 Mar 2025 23:37:09 +0000 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e8103e3e-0451-11f0-9899-31a8f345e629; Wed, 19 Mar 2025 00:37:08 +0100 (CET) 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: e8103e3e-0451-11f0-9899-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1742341027; x=1742600227; bh=KXwnzdVEulZZ+6NMu1oLFBFCPd+jRq+OUpgMkQKutFo=; 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=VRW/l+26wTM6UCNK6gG3oqU+/nFZ6rIZnIdYZtYSSKM3pO2VR/6b97xn7sO/By5Zd UqSVyNfJ7/9Sdudlu3n0a2LUYfkWVZUjj54FFxW5VgdK9MBzm1r0rXYGGJo3Wp4y91 SMMpnVvTF6+WmWmiG7UMeAAHnthVAGKZipNA6k5YWfbNVh+zmNoqGepXnvFhPDIhtj cnL/oKnNK+7DdPVyVNsfh7DId0f/eIweIKQbbadk0r2aFH4G0h2LEFCJmQC0P6YhFa B1ts+Pbzh7UWLbTcNKU4W0npZcjr1PPCkBU5ZY5Z1EMBjSyI6urm6QpPZ8CXHzsbgC Ik3s0D0Ud6QfA== Date: Tue, 18 Mar 2025 23:37:04 +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 v1 8/8] xen/console: introduce console_get_focus() Message-ID: <20250318233617.849903-9-dmukhin@ford.com> In-Reply-To: <20250318233617.849903-1-dmukhin@ford.com> References: <20250318233617.849903-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 74e65ad8738b6ac1a189ccd9fad33305fb25fd8c MIME-Version: 1.0 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, 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); } /* diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 0e2349a868..906a0ae996 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; } -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 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); -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.