From nobody Fri Oct 31 09:15:29 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 1747685573423735.5035545954993; Mon, 19 May 2025 13:12:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.990253.1374211 (Exim 4.92) (envelope-from ) id 1uH6qg-0001jQ-T8; Mon, 19 May 2025 20:12:34 +0000 Received: by outflank-mailman (output) from mailman id 990253.1374211; Mon, 19 May 2025 20:12:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uH6qg-0001jJ-Q7; Mon, 19 May 2025 20:12:34 +0000 Received: by outflank-mailman (input) for mailman id 990253; Mon, 19 May 2025 20:12:33 +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 1uH6qf-0001j7-QL for xen-devel@lists.xenproject.org; Mon, 19 May 2025 20:12:33 +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 989019db-34ed-11f0-a2fa-13f23c93f187; Mon, 19 May 2025 22:12:32 +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: 989019db-34ed-11f0-a2fa-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1747685550; x=1747944750; bh=E9iBDYrfKj31LI0uBbyEOTVIbFv75/GYvzBsSvZRX6M=; 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=W4aXddIKmLxBxELdx09Z2dBeF7rH0rw2NXlcL9s4ggfuIh8DPqEXlkXltpF4faT78 /K6f2Yo08fnd0EfM9tUg20+XdcJnZ6f6gKbQOksDRfQG7khfNDGVnGtXmOUpqnJHrS sxU3/XtGOMn4FjVKV3f4DobqWPZ2wsxrlbjfPtyyoI8Bw1vaagkTvCFdlPIWl7fkAm u0qQ5tHxtJ3ms37MEYeefnLiK4nUKcKHoiJlkjqNpXhTdMyOnRqYL0rWXcyTaBgDJz hG5/lJJQFA2cT9sCgrugsfxQ4odmaURi8a7Apue8uBCdG2fwXkW5rB1axIilXkcJa8 nHBYqMAUv4uBw== Date: Mon, 19 May 2025 20:12:27 +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 v3 1/5] xen/console: rename switch_serial_input() to console_switch_input() Message-ID: <20250519201211.1366244-2-dmukhin@ford.com> In-Reply-To: <20250519201211.1366244-1-dmukhin@ford.com> References: <20250519201211.1366244-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 2c7c174c17b8e55ae7bf60ddc31c94b0ac5dabf3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1747685575578116600 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 v2: - rebased - Link to v2: https://lore.kernel.org/xen-devel/20250331230508.440198-5-dmu= khin@ford.com/ --- 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 c3150fbdb7..c8dde38376 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -487,7 +487,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 @@ -581,7 +581,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; @@ -1125,7 +1125,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:15:29 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 1747685576520194.8234170459084; Mon, 19 May 2025 13:12:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.990255.1374221 (Exim 4.92) (envelope-from ) id 1uH6qr-00024e-3e; Mon, 19 May 2025 20:12:45 +0000 Received: by outflank-mailman (output) from mailman id 990255.1374221; Mon, 19 May 2025 20:12: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 1uH6qr-00024T-0u; Mon, 19 May 2025 20:12:45 +0000 Received: by outflank-mailman (input) for mailman id 990255; Mon, 19 May 2025 20:12: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 1uH6qq-0001VO-Ad for xen-devel@lists.xenproject.org; Mon, 19 May 2025 20:12:44 +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 9ee05afc-34ed-11f0-b892-0df219b8e170; Mon, 19 May 2025 22:12:42 +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: 9ee05afc-34ed-11f0-b892-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=lbcbjcqqnncq3hedkmxwtc5dli.protonmail; t=1747685561; x=1747944761; bh=qkF9UnSC7+WkiSRXBNkMlXtFklvN0JpodfP2cIlJzU4=; 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=KjlElFsag3cIH+39onDpbCXbSMUoYWS2MmVwsRlP7E7sdcYhD+bFYLnzYIwleKKTI HdmEXxgif6uPPFm8XYsMlkiFKoFRzAV/QzBJFh6fKg++435BY1Azc431z6zCeyNPZ7 9ufcjz1pWuOu6Mp/PmRqJACCes7I65lxTSfI6yPbt8RIx0Lo4GTtb6+gcNN2agGDsT 8pBTbW1CrQSuduJMVuCEo3wzbWHc/gXPYViE2T86Lnm9NqiahkVdQDStf0EzTq6P7m N2F7NG4AsYWdHW1KHx+ROczQic//0eQwVc1UHRXbAMYykiAj2d1Lg3157yNgM1U0et pNXGpmUqrvRcQ== Date: Mon, 19 May 2025 20:12: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 v3 2/5] xen/console: introduce console_get_domid() Message-ID: <20250519201211.1366244-3-dmukhin@ford.com> In-Reply-To: <20250519201211.1366244-1-dmukhin@ford.com> References: <20250519201211.1366244-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 6703ec991965501074107b8c9a962dece9dbce26 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1747685577479116600 Content-Type: text/plain; charset="utf-8" From: Denis Mukhin Add console_get_domid() to the console driver to retrieve the current conso= le owner domain ID. Use the function in vpl011 emulator which leads to simpler code. Make console_{get,put}_domain() private to the console driver. No functional change intended. Signed-off-by: Denis Mukhin --- Changes since v2: - changed commit subject line - Link to v2: https://lore.kernel.org/xen-devel/20250331230508.440198-8-dmu= khin@ford.com/ --- xen/arch/arm/vpl011.c | 5 +---- xen/drivers/char/console.c | 11 +++++++++-- xen/include/xen/console.h | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 66047bf33c..0f58b2c900 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_domid() ) { 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 c8dde38376..86fd0b427d 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -474,19 +474,26 @@ static unsigned int __read_mostly console_rx =3D 0; =20 #define max_console_rx (max_init_domid + 1) =20 -struct domain *console_get_domain(void) +static struct domain *console_get_domain(void) { if ( console_rx =3D=3D 0 ) return NULL; return rcu_lock_domain_by_id(console_rx - 1); } =20 -void console_put_domain(struct domain *d) +static void console_put_domain(struct domain *d) { if ( d ) rcu_unlock_domain(d); } =20 +domid_t console_get_domid(void) +{ + if ( console_rx =3D=3D 0 ) + return DOMID_XEN; + return console_rx - 1; +} + static void console_switch_input(void) { unsigned int next_rx =3D console_rx; diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 83cbc9fbda..c6f9d84d80 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_domid(void); =20 /* * Steal output from the console. Returns +ve identifier, else -ve error. --=20 2.34.1 From nobody Fri Oct 31 09:15:29 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 1747685580609570.2384694643143; Mon, 19 May 2025 13:13:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.990257.1374231 (Exim 4.92) (envelope-from ) id 1uH6qv-0002UF-AF; Mon, 19 May 2025 20:12:49 +0000 Received: by outflank-mailman (output) from mailman id 990257.1374231; Mon, 19 May 2025 20:12: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 1uH6qv-0002U8-7H; Mon, 19 May 2025 20:12:49 +0000 Received: by outflank-mailman (input) for mailman id 990257; Mon, 19 May 2025 20:12: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 1uH6qt-0001j7-Qx for xen-devel@lists.xenproject.org; Mon, 19 May 2025 20:12:47 +0000 Received: from mail-10630.protonmail.ch (mail-10630.protonmail.ch [79.135.106.30]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a1a2f019-34ed-11f0-a2fa-13f23c93f187; Mon, 19 May 2025 22:12: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: a1a2f019-34ed-11f0-a2fa-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1747685566; x=1747944766; bh=s9Xnr4J9o81p53iu9F5mfQfhSRRP2AAzWB/TipdHU3A=; 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=GxUrsqJP7iTVFfU6KuShVIQs6rT1SJDCEbhhBJC2XshG+JdWGazOPhn4cAAtZGJ9u BNx2r0x2KP5MIhDdOc4RqS8AuK0Ms61Sd+aTw/dYwPo6dawEhVGBJTreqOFwZiE6LQ NHmjaMj1RJfrEw/HQmZMUvI8o7K1zsV77HrbXuJYcdcIETOX6KXhPOZjN/6cXdudF8 UyuYZJAaQWVMZ52whWgS99tRsnL6xaDSjDytiFS/Ebv4dtnJNEjC/Ve+GppYSuAH0n GL6Z4cc6HqlhyzwdtCg1DNvw+6n1V4OO8ULeTYSNUwPlVoI+yzTQdQMjxpmVvRcly/ ogMyGxpJTv2Ew== Date: Mon, 19 May 2025 20:12:42 +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 v3 3/5] xen/console: introduce console input permission Message-ID: <20250519201211.1366244-4-dmukhin@ford.com> In-Reply-To: <20250519201211.1366244-1-dmukhin@ford.com> References: <20250519201211.1366244-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 73229b2a4a156b643aacc4fab0873cf0afa39ded MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1747685581715116600 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 --- Changes since v2: - rebased - Link to v2: https://lore.kernel.org/xen-devel/20250331230508.440198-2-dmu= khin@ford.com/ --- xen/arch/arm/vpl011.c | 2 ++ 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, 30 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 0f58b2c900..d0e5504e9e 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -734,6 +734,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 cb05156ff5..6a6cdd991b 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -836,6 +836,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 86fd0b427d..ccecda6523 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -476,9 +476,21 @@ static unsigned int __read_mostly console_rx =3D 0; =20 static 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 static void console_put_domain(struct domain *d) @@ -522,6 +534,10 @@ static void console_switch_input(void) if ( d ) { rcu_unlock_domain(d); + + if ( !d->console.input_allowed ) + break; + 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:15:29 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 1747685584195844.8281832442912; Mon, 19 May 2025 13:13:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.990259.1374241 (Exim 4.92) (envelope-from ) id 1uH6qz-0002rl-Hl; Mon, 19 May 2025 20:12:53 +0000 Received: by outflank-mailman (output) from mailman id 990259.1374241; Mon, 19 May 2025 20:12:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uH6qz-0002rd-Ej; Mon, 19 May 2025 20:12:53 +0000 Received: by outflank-mailman (input) for mailman id 990259; Mon, 19 May 2025 20:12:52 +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 1uH6qy-0001j7-8P for xen-devel@lists.xenproject.org; Mon, 19 May 2025 20:12:52 +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 a4149330-34ed-11f0-a2fa-13f23c93f187; Mon, 19 May 2025 22:12:51 +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: a4149330-34ed-11f0-a2fa-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=fdjbcg6bnra53gjokga2qhgkuq.protonmail; t=1747685570; x=1747944770; bh=qN2U2dQLJL1JMOGF37S4KVhD6fSMTiYi58zkKDBG0FE=; 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=mtVNnA0xWj8ZGXrtJXc/ZqmpBP58/kvlFljZRKgjbIFaK6dmawqP41Hqh5DSPnsPl dqLAGtG8qnopmxqx7SLs6HCP48uDfm5XHUrfVsyBbQjIwQgn4YyOl75TrfloOYBdNG 6fyKcjuVkY+GDVHs0QT50m1YR/7JfBHyvl5qBpmm0Rn5Di8W/h9OFRYvhAQvByrDqP 6+FT1mslY+ueMAUqI7dGYgseuGjRYJZ9ujMoxeScYgLdiEaf7Gax81P68Ep2iBDDgb yTlJfHTio4XVVdFmXAcRc2dTPvURfwPuCi6FfzcL7EBZiV9UbtzNDmI5G4GwNqo7fI YtEdHgWnDl91w== Date: Mon, 19 May 2025 20:12:47 +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 v3 4/5] xen/console: remove max_init_domid dependency Message-ID: <20250519201211.1366244-5-dmukhin@ford.com> In-Reply-To: <20250519201211.1366244-1-dmukhin@ford.com> References: <20250519201211.1366244-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 5910fde02699c1e1b7d6683d14e5de31da8b9449 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1747685585956116600 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 v2: - reworked to traversing domain list directly - Link to v2: https://lore.kernel.org/xen-devel/20250331230508.440198-7-dmu= khin@ford.com/ --- 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 | 29 +++++++ xen/drivers/char/console.c | 102 +++++++++--------------- xen/include/xen/domain.h | 1 + 9 files changed, 66 insertions(+), 78 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 10b46d0684..53e2f8b537 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 8e38affd0c..4c050b9ded 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 6a6cdd991b..90bd42b633 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -2460,6 +2460,35 @@ 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..CONFIG_MAX_DOMID-1]. + */ +domid_t domid_find_with_input_allowed(domid_t hint) +{ + struct domain *d; + domid_t domid =3D DOMID_XEN; + + spin_lock(&domlist_update_lock); + + for ( d =3D domid_to_domain(hint); + d && likely(get_domain(d)) && (d->domain_id < CONFIG_MAX_DOMID); + d =3D d->next_in_list ) + { + if ( d->console.input_allowed ) + { + domid =3D d->domain_id; + break; + } + } + + spin_unlock(&domlist_update_lock); + + return domid; +} + /* * Local variables: * mode: C diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index ccecda6523..ff20706ac9 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -462,26 +462,17 @@ 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_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 static 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 @@ -499,50 +490,14 @@ static void console_put_domain(struct domain *d) rcu_unlock_domain(d); } =20 -domid_t console_get_domid(void) +static void console_set_domid(domid_t domid) { - if ( console_rx =3D=3D 0 ) - return DOMID_XEN; - return console_rx - 1; -} + if ( domid =3D=3D DOMID_XEN ) + printk("*** Serial input to Xen"); + else + printk("*** Serial input to DOM%u", domid); =20 -static void console_switch_input(void) -{ - unsigned int next_rx =3D console_rx; - - /* - * 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 ) - break; - - 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)", @@ -550,12 +505,35 @@ static void console_switch_input(void) printk("\n"); } =20 +domid_t console_get_domid(void) +{ + return console_rx; +} + +/* + * 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(); @@ -1130,14 +1108,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', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", = 0); register_irq_keyhandler('+', &do_inc_thresh, @@ -1147,8 +1117,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:15:29 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 1747685592216223.94134763537852; Mon, 19 May 2025 13:13:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.990265.1374251 (Exim 4.92) (envelope-from ) id 1uH6r7-0003Td-0f; Mon, 19 May 2025 20:13:01 +0000 Received: by outflank-mailman (output) from mailman id 990265.1374251; Mon, 19 May 2025 20:13:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uH6r6-0003TU-Tm; Mon, 19 May 2025 20:13:00 +0000 Received: by outflank-mailman (input) for mailman id 990265; Mon, 19 May 2025 20:12:59 +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 1uH6r4-0001j7-WE for xen-devel@lists.xenproject.org; Mon, 19 May 2025 20:12:59 +0000 Received: from mail-24417.protonmail.ch (mail-24417.protonmail.ch [109.224.244.17]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a82ad5cf-34ed-11f0-a2fa-13f23c93f187; Mon, 19 May 2025 22:12: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: a82ad5cf-34ed-11f0-a2fa-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1747685575; x=1747944775; bh=6sXF1UKe68CpK8zF6xNGeqeo9Hd97I7fR8xMKBTgt9Q=; 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=AoxtZYN3dQWGUjkd5u2yMRqvDReYphUtqaJlT+41xVoS/ZpGGeQ7zb/9u10Y7b1g0 GUjV5h6VLlJ2RRoLpN9+frGQDtM43X1iJcw47C02D4Z+mxCAOu2FTumJl3Gxy9g7Wz b2FcgTwYVby+yNiud9mYdRbi97sbO1e9gBlKQRanRauOKJTOG77r2Ds+xGjiiXyDOw sYfs+2h+XRO9y7AY6I1EQzSo0+Q7stcpP6GGM5IIC1HwtxAwlRg5zQZVZUdgOMEZgi T+L+kXJFbAoBKSM+Ztg/2dGEcrDhKW6h4exmk+96H+/RD+RcXg0ljE21a0F+qPM91o mhl6qfJMc1B3Q== Date: Mon, 19 May 2025 20:12:51 +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 v3 5/5] xen/console: rename console_rx to console_domid Message-ID: <20250519201211.1366244-6-dmukhin@ford.com> In-Reply-To: <20250519201211.1366244-1-dmukhin@ford.com> References: <20250519201211.1366244-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 34962395dae726ecf123eaf0887728e83acd5270 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1747685593758116600 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 --- Changes since v2: - new patch --- xen/drivers/char/console.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index ff20706ac9..afcc6a236e 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -467,11 +467,11 @@ static void cf_check dump_console_ring_key(unsigned c= har 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 static 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; @@ -497,7 +497,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)", @@ -507,7 +507,7 @@ static void console_set_domid(domid_t domid) =20 domid_t console_get_domid(void) { - return console_rx; + return console_domid; } =20 /* @@ -518,10 +518,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 @@ -533,7 +533,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