From nobody Fri Oct 31 09:42:12 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 1748647167478442.37707414761553; Fri, 30 May 2025 16:19:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1001601.1381722 (Exim 4.92) (envelope-from ) id 1uL90A-00056I-Fn; Fri, 30 May 2025 23:19:02 +0000 Received: by outflank-mailman (output) from mailman id 1001601.1381722; Fri, 30 May 2025 23:19: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 1uL90A-00056B-Cv; Fri, 30 May 2025 23:19:02 +0000 Received: by outflank-mailman (input) for mailman id 1001601; Fri, 30 May 2025 23:19:00 +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 1uL908-00055p-Nf for xen-devel@lists.xenproject.org; Fri, 30 May 2025 23:19:00 +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 766d3ff1-3dac-11f0-b894-0df219b8e170; Sat, 31 May 2025 01:18:58 +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: 766d3ff1-3dac-11f0-b894-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=cjfyrptl4ng5he7ajhctxrmcyq.protonmail; t=1748647136; x=1748906336; bh=YSUOLXyrO7AC8+AnY9XmvmG3t0KDhdjWKnpe7lbTOKA=; 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=kejDclk7enbZKjSY8z9Q91xwWE4NvLpKUZo6SlEX1ReFBCVW2bgdaltNJTZ/ZQr7q kWGVsl5Rwipa4SgDuUUXLK1VLg7ko5YifhPGo6lGAwYf4sv33+skz9sb0dTctZcKor 0za3beM3YWqGtGwBgOEDfgOSCLI0/qwwWMRKnHBjTcV+G88bN0OhucOHRCqm1/HzaX djQEqRymApavtK5eKJxJj07+Hz4qgPdn2OdhJyVsa0/VfLuXbsA+ZvdkCOXDWHvd8n pk5/gxUvpkI2lMJY2YGrsLP/+0olkesmxpi6qNTB9lSKGRXTnJ9M21yPZ2RKeBgXCB 4TpG7JHwkzSiQ== Date: Fri, 30 May 2025 23:18: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 v5 1/4] xen/console: rename switch_serial_input() to console_switch_input() Message-ID: <20250530231841.73386-2-dmukhin@ford.com> In-Reply-To: <20250530231841.73386-1-dmukhin@ford.com> References: <20250530231841.73386-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 423c493d8e7f267520abe8c351b28d1eab06b8b7 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748647169194116600 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin Update the function name as per naming notation in the console driver. No functional change. Signed-off-by: Denis Mukhin Acked-by: Jan Beulich --- Changes since v4: - kept A-b --- 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 c15987f5bb..30701ae0b0 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -523,7 +523,7 @@ void console_put_domain(struct domain *d) rcu_unlock_domain(d); } =20 -static void switch_serial_input(void) +static void console_switch_input(void) { unsigned int next_rx =3D console_rx; =20 @@ -617,7 +617,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; @@ -1171,7 +1171,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 09:42:12 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 1748647168207804.0257443701596; Fri, 30 May 2025 16:19:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1001602.1381732 (Exim 4.92) (envelope-from ) id 1uL90L-0005PY-Mh; Fri, 30 May 2025 23:19:13 +0000 Received: by outflank-mailman (output) from mailman id 1001602.1381732; Fri, 30 May 2025 23:19:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uL90L-0005PP-Jn; Fri, 30 May 2025 23:19:13 +0000 Received: by outflank-mailman (input) for mailman id 1001602; Fri, 30 May 2025 23:19:12 +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 1uL90K-00055p-0H for xen-devel@lists.xenproject.org; Fri, 30 May 2025 23:19:12 +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 7dcf4de1-3dac-11f0-b894-0df219b8e170; Sat, 31 May 2025 01:19:10 +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: 7dcf4de1-3dac-11f0-b894-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1748647149; x=1748906349; bh=YxCkgCQgEgcma2HR34BjqEKfMw9IKxiz4R9wP5xWv0o=; 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=jvxVPpgTZDTnOQSspE04WazOKRkEo3XQBj9exJwLKtc//Vs5ZjcrhqWKUgz+D1XIv Qku+ZLkqzGcAa7ALMwXXlOrF8mYZXbZsdqT5CDbdCqXyO/Ix6djWRxihpP8Hu2AOVY y9dcbu5WRhDf1C1+wgn2pj+gBHIUqV340O9aIGk0qzkvEPPCZG6dbvhn+z5Vn385wB Uz732eqr6IOd3Q/puYzYE+MsWUoRge18cdOR+e2wAR+Fz7Tp8oEOyIhr3SY+JlzZCZ bY+E/bWXEZ4vVp0b7pnmsc4ET+W/39Zmf2QAybrzhkEG6iq6viQQ8aCVOh+tv3LlKj pF4fOIJLfANBA== Date: Fri, 30 May 2025 23:19:01 +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 v5 2/4] xen/console: introduce console input permission Message-ID: <20250530231841.73386-3-dmukhin@ford.com> In-Reply-To: <20250530231841.73386-1-dmukhin@ford.com> References: <20250530231841.73386-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 49605cb8c5e79f6a3a4f10e2aed5b7481a08333f MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748647169269116600 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin Add new flag to domain structure for marking permission to intercept the physical console input by the domain. Update console input switch logic accordingly. No functional change intended. Signed-off-by: Denis Mukhin Reviewed-by: Stefano Stabellini --- Changes since v4: - kept input_allowed as a separate flag - updated logic for input_allowed in vpl011 - fixup for console_switch_input() --- xen/arch/arm/vpl011.c | 1 + xen/arch/x86/pv/shim.c | 2 ++ xen/common/domain.c | 2 ++ xen/drivers/char/console.c | 18 +++++++++++++++++- xen/include/xen/sched.h | 8 +++++++- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 66047bf33c..480fc664fc 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -713,6 +713,7 @@ int domain_vpl011_init(struct domain *d, struct vpl011_= init_info *info) } else { + d->console.input_allowed =3D true; vpl011->backend_in_domain =3D false; =20 vpl011->backend.xen =3D xzalloc(struct vpl011_xen_backend); 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 129b4fcb37..d75ece1b61 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -835,6 +835,8 @@ struct domain *domain_create(domid_t domid, flags |=3D CDF_hardware; if ( old_hwdom ) old_hwdom->cdf &=3D ~CDF_hardware; + + d->console.input_allowed =3D true; } =20 /* Holding CDF_* internal flags. */ diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 30701ae0b0..9a9836ba91 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -512,9 +512,21 @@ static unsigned int __read_mostly console_rx =3D 0; =20 struct domain *console_get_domain(void) { + struct domain *d; + if ( console_rx =3D=3D 0 ) return NULL; - return rcu_lock_domain_by_id(console_rx - 1); + + d =3D rcu_lock_domain_by_id(console_rx - 1); + if ( !d ) + return NULL; + + if ( d->console.input_allowed ) + return d; + + rcu_unlock_domain(d); + + return NULL; } =20 void console_put_domain(struct domain *d) @@ -551,6 +563,10 @@ static void console_switch_input(void) if ( d ) { rcu_unlock_domain(d); + + if ( !d->console.input_allowed ) + continue; + 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..e91c99a8f3 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 take ownership of the 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 09:42:12 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 174864717086561.54317811416388; Fri, 30 May 2025 16:19:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1001604.1381742 (Exim 4.92) (envelope-from ) id 1uL90Q-0005lL-3Y; Fri, 30 May 2025 23:19:18 +0000 Received: by outflank-mailman (output) from mailman id 1001604.1381742; Fri, 30 May 2025 23:19:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uL90Q-0005lC-0D; Fri, 30 May 2025 23:19:18 +0000 Received: by outflank-mailman (input) for mailman id 1001604; Fri, 30 May 2025 23:19:15 +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 1uL90N-0004sF-QA for xen-devel@lists.xenproject.org; Fri, 30 May 2025 23:19:15 +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 80794aae-3dac-11f0-a300-13f23c93f187; Sat, 31 May 2025 01:19: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: 80794aae-3dac-11f0-a300-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=2tysv52janf43araxgasgfotju.protonmail; t=1748647153; x=1748906353; bh=crjmZsSfdJFF0uqEvmUIgryAsQp9BDRn+DHw+7/ubRI=; 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=hzAE7H/wWRRZMn/AZ9JU0vGUuQdn4cBq9DOQ3aRbI7L4TEY+hiy6KqpmOVbK5xniP Gl1KXHwJSqU/XJVE51n/10McTZD7PYGLkEUnnVoI9umpfdbtgOiCD8pNIQO1r6Ey5T cqZTWg/lGLTIxgDweeaaI9FjCqb1fBsDWBztuP2a5zIliMB9CEsA7FY6XtHZjJ1kCG 16eCHlSBhrjDgtVxX/SCVLbmt2oMDFuEeZvLwTEvj/XohXd9lsQsZ8O/Xr3njYX06p yUPhY9KTkwy24pYu9E8zPjWROz85+XXCve47ANNJMh14yY2FwB/c7AXhkw3ngkUMA5 BTaHiQuUTqrkw== Date: Fri, 30 May 2025 23:19:09 +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 v5 3/4] xen/console: remove max_init_domid dependency Message-ID: <20250530231841.73386-4-dmukhin@ford.com> In-Reply-To: <20250530231841.73386-1-dmukhin@ford.com> References: <20250530231841.73386-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 42036b1625341995ac1242138504219f8b560777 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748647171382116600 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin The physical console input rotation depends on max_init_domid symbol, which= is managed differently across architectures. Instead of trying to manage max_init_domid in the arch-common code the cons= ole input rotation code can be reworked by removing dependency on max_init_domid entirely. To do that, introduce domid_find_with_input_allowed() in arch-independent location to find the ID of the next possible console owner domain. The IDs are rotated across non-system domain IDs and DOMID_XEN. Also, introduce helper console_set_domid() for updating identifier of the current console input owner (points to Xen or domain). Use domid_find_with_input_allowed() and console_set_domid() in console_switch_input(). Remove uses of max_init_domid in the code. Signed-off-by: Denis Mukhin --- Changes since v4: - fixed domid_find_with_input_allowed() - kept switching to get_initial_domain_id() in console_endboot() --- 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/device-tree/dom0less-build.c | 2 - xen/common/domain.c | 33 +++++++++ xen/drivers/char/console.c | 90 +++++++++---------------- xen/include/xen/domain.h | 1 + 9 files changed, 65 insertions(+), 71 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 734e23da44..0a18d479f9 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -61,8 +61,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 ac34c69855..b67de8577f 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/device-tree/dom0less-build.c b/xen/common/device-tr= ee/dom0less-build.c index 9a6015f4ce..703f20faed 100644 --- a/xen/common/device-tree/dom0less-build.c +++ b/xen/common/device-tree/dom0less-build.c @@ -977,8 +977,6 @@ void __init create_domUs(void) domid =3D domid_alloc(DOMID_INVALID); if ( domid =3D=3D DOMID_INVALID ) panic("Error allocating ID for domain %s\n", dt_node_name(node= )); - if ( max_init_domid < domid ) - max_init_domid =3D domid; =20 d =3D domain_create(domid, &d_cfg, flags); if ( IS_ERR(d) ) diff --git a/xen/common/domain.c b/xen/common/domain.c index d75ece1b61..4a54bc27a3 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -2461,6 +2461,39 @@ void domid_free(domid_t domid) spin_unlock(&domid_lock); } =20 +/* + * Find the ID of the next possible console owner domain. + * + * @return Domain ID: DOMID_XEN or non-system domain IDs within + * the range of [0..DOMID_FIRST_RESERVED-1]. + */ +domid_t domid_find_with_input_allowed(domid_t hint) +{ + domid_t domid =3D DOMID_XEN; + + if ( hint < DOMID_FIRST_RESERVED ) + { + struct domain *d; + + rcu_read_lock(&domlist_read_lock); + + for ( d =3D domid_to_domain(hint); + d && get_domain(d) && d->domain_id < DOMID_FIRST_RESERVED; + d =3D rcu_dereference(d->next_in_list) ) + { + if ( d->console.input_allowed ) + { + domid =3D d->domain_id; + break; + } + } + + rcu_read_unlock(&domlist_read_lock); + } + + return domid; +} + /* * Local variables: * mode: C diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 9a9836ba91..37289d5558 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -498,26 +498,17 @@ static void cf_check conring_dump_keyhandler(unsigned= char 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_rx =3D 0; =20 -#define max_console_rx (max_init_domid + 1) +/* Console owner domain identifier. */ +static domid_t __read_mostly console_rx =3D DOMID_XEN; =20 struct domain *console_get_domain(void) { - struct domain *d; + struct domain *d =3D rcu_lock_domain_by_id(console_rx); =20 - if ( console_rx =3D=3D 0 ) - return NULL; - - d =3D rcu_lock_domain_by_id(console_rx - 1); if ( !d ) return NULL; =20 @@ -535,43 +526,14 @@ void console_put_domain(struct domain *d) rcu_unlock_domain(d); } =20 -static void console_switch_input(void) +static void console_set_domid(domid_t domid) { - unsigned int next_rx =3D console_rx; + if ( domid =3D=3D DOMID_XEN ) + printk("*** Serial input to Xen"); + else + printk("*** Serial input to DOM%u", domid); =20 - /* - * Rotate among Xen, dom0 and boot-time created domUs while skipping - * switching serial input to non existing domains. - */ - for ( ; ; ) - { - domid_t domid; - struct domain *d; - - if ( next_rx++ >=3D max_console_rx ) - { - console_rx =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; - d =3D rcu_lock_domain_by_id(domid); - if ( d ) - { - rcu_unlock_domain(d); - - if ( !d->console.input_allowed ) - continue; - - console_rx =3D next_rx; - printk("*** Serial input to DOM%u", domid); - break; - } - } + console_rx =3D domid; =20 if ( switch_code ) printk(" (type 'CTRL-%c' three times to switch input)", @@ -579,12 +541,30 @@ static void console_switch_input(void) printk("\n"); } =20 +/* + * Switch console focus. + * Rotates input focus among Xen and domains with console input permission. + */ +static void console_switch_input(void) +{ + domid_t hint; + + if ( console_rx =3D=3D DOMID_XEN ) + hint =3D get_initial_domain_id(); + else + hint =3D console_rx + 1; + + hint =3D domid_find_with_input_allowed(hint); + + console_set_domid(hint); +} + static void __serial_rx(char c) { struct domain *d; int rc =3D 0; =20 - if ( console_rx =3D=3D 0 ) + if ( console_rx =3D=3D DOMID_XEN ) return handle_keypress(c, false); =20 d =3D console_get_domain(); @@ -1169,14 +1149,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_rx =3D max_console_rx; - register_keyhandler('w', conring_dump_keyhandler, "synchronously dump console ring buffer (dmesg)", = 0); register_irq_keyhandler('+', &do_inc_thresh, @@ -1186,8 +1158,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_domid(get_initial_domain_id()); } =20 int __init console_has(const char *device) diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 8aab05ae93..a88eb34f3f 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -36,6 +36,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_find_with_input_allowed(domid_t hint); domid_t get_initial_domain_id(void); =20 domid_t domid_alloc(domid_t domid); --=20 2.34.1 From nobody Fri Oct 31 09:42:12 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 1748647178081346.2733983042335; Fri, 30 May 2025 16:19:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1001607.1381751 (Exim 4.92) (envelope-from ) id 1uL90Y-0006Fu-Aw; Fri, 30 May 2025 23:19:26 +0000 Received: by outflank-mailman (output) from mailman id 1001607.1381751; Fri, 30 May 2025 23:19:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uL90Y-0006Fi-7Y; Fri, 30 May 2025 23:19:26 +0000 Received: by outflank-mailman (input) for mailman id 1001607; Fri, 30 May 2025 23:19:24 +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 1uL90W-00055p-Py for xen-devel@lists.xenproject.org; Fri, 30 May 2025 23:19:24 +0000 Received: from mail-10628.protonmail.ch (mail-10628.protonmail.ch [79.135.106.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8587ab02-3dac-11f0-b894-0df219b8e170; Sat, 31 May 2025 01:19: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: 8587ab02-3dac-11f0-b894-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=y532ikq7kra7dhltmtp4fdjura.protonmail; t=1748647162; x=1748906362; bh=jkfiK442l+6t8tHuxB/JprzcNDyu+sgNZHPHUFa9lYw=; 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=R4CYcQBGd3VSaCrwWVWPOPLq57+ERM5gNA0mkQ9VY3kwZwHblqr4CJbWs0ZtNQwqz W67sifljb+rsmrA43DjzKs1D2sD8BauHo2lFx8eP/huaC/LbiHBrXdWJWJmnBXk+x+ KxR8ljbm9ehSJIvqqy58zginRx5T2FH0DgixNOQ/8/Ny6mbRIfPzcCzhPlLvMlPkaj lA0RMC+dSlosbHblPyWOilSy9AFF7GiHdwfZfHO9VmWouj08bv/HllJEX+4HdlDQd1 CwP3pqX4kh+tkp0jPYzmR6uLkwinu2AcdcZpkn8rx9ruB7/o2tYMcvMez9zhXW4Old EZ7gXcJQcgOiA== Date: Fri, 30 May 2025 23:19:17 +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 v5 4/4] xen/console: rename console_rx to console_domid Message-ID: <20250530231841.73386-5-dmukhin@ford.com> In-Reply-To: <20250530231841.73386-1-dmukhin@ford.com> References: <20250530231841.73386-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: a63e93d5e86d2fb5344c6fbbda1c4880a17b4a9b MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748647179362116600 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin Update the symbol name to match the code better. No functional change. Signed-off-by: Denis Mukhin Reviewed-by: Stefano Stabellini --- xen/drivers/char/console.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 37289d5558..5797f29d31 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -503,11 +503,11 @@ static void cf_check conring_dump_keyhandler(unsigned= char key) #define switch_code (opt_conswitch[0]-'a'+1) =20 /* Console owner domain identifier. */ -static domid_t __read_mostly console_rx =3D DOMID_XEN; +static domid_t __read_mostly console_domid =3D DOMID_XEN; =20 struct domain *console_get_domain(void) { - struct domain *d =3D rcu_lock_domain_by_id(console_rx); + struct domain *d =3D rcu_lock_domain_by_id(console_domid); =20 if ( !d ) return NULL; @@ -533,7 +533,7 @@ static void console_set_domid(domid_t domid) else printk("*** Serial input to DOM%u", domid); =20 - console_rx =3D domid; + console_domid =3D domid; =20 if ( switch_code ) printk(" (type 'CTRL-%c' three times to switch input)", @@ -549,10 +549,10 @@ static void console_switch_input(void) { domid_t hint; =20 - if ( console_rx =3D=3D DOMID_XEN ) + if ( console_domid =3D=3D DOMID_XEN ) hint =3D get_initial_domain_id(); else - hint =3D console_rx + 1; + hint =3D console_domid + 1; =20 hint =3D domid_find_with_input_allowed(hint); =20 @@ -564,7 +564,7 @@ static void __serial_rx(char c) struct domain *d; int rc =3D 0; =20 - if ( console_rx =3D=3D DOMID_XEN ) + if ( console_domid =3D=3D DOMID_XEN ) return handle_keypress(c, false); =20 d =3D console_get_domain(); --=20 2.34.1