From patchwork Sat Jan 4 01:58:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926039 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 02FF2E7719E for ; Sat, 4 Jan 2025 01:58:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864707.1275965 (Exim 4.92) (envelope-from ) id 1tTtQk-0005uk-VL; Sat, 04 Jan 2025 01:58:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864707.1275965; Sat, 04 Jan 2025 01:58:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQk-0005ro-O0; Sat, 04 Jan 2025 01:58:22 +0000 Received: by outflank-mailman (input) for mailman id 864707; Sat, 04 Jan 2025 01:58:20 +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 1tTtQi-0005Ay-JH for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:20 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5c7b92d9-ca3f-11ef-99a4-01e77a169b0f; Sat, 04 Jan 2025 02:58:16 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A04E95C60A3; Sat, 4 Jan 2025 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id AD788C4CEDD; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E522E7718F; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) 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: 5c7b92d9-ca3f-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955894; bh=ixkyuOkiW6UUd6nXZHVzHXwPEUcrn1ATQ8PMz6yYQZU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=PyyNaLDwe45fuLGzbHvRdggvoPjqnc7oOABO9umAdq0YHmlF9F9p4ZNEwbf9DhaK2 XkFz6dmSio1o49I3tdRoBz5QxHLgeix9rOWX5w99edorcTW6d0QIRG47jiq8tedHTo RArzjnB04YlJgCcqf46zII7c1w4ZzncDLjn/anpVQenDj0kQ2de6VeFcXHQ2sWqbgH MD86vHuP6vl9LK4OvupzyFzI3Uhjc8ohjvYyVNUNTaxAaC8hkvTvsvO/SOQ6flZEJ+ O80Hm+RhOiZvehVcZh+a2VmX+KEq3AEMTl9em3hCOa/jZfRdE31gL8D8OxUIFTmEpT fpRlULRfg2Fiw== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:07 -0800 Subject: [PATCH v3 01/24] xen/ctype: introduce is_console_printable() MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-1-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=3106; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=4D7ZxUDiCpTccpWinTY9R2Ndh2vzcucBN6SjTgn7Gmg=; b=jP4F9CwTPqrv4KtNpzI3kEeh+CKX6i8UdW4ulFgALmAvuDR3hVY/Dlkoa+ubfgC6Air3Fk8m4 YNzBwH/RNhJD6N4BnvvXA+FuT+K+yoRLo5vUGCDpHTrVfTycZTs7/aS X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin There are several console drivers which have same checks w.r.t. printable characters. The check is moved to new is_console_printable() function and re-used in the UART emulation / guest logging code. Also, MISRA rule 21.13 for ctype.h has been exploited while working on the code change, reference the rule from ctype.h for future engineers. Signed-off-by: Denis Mukhin --- xen/arch/arm/vuart.c | 3 +-- xen/arch/x86/hvm/hvm.c | 3 +-- xen/drivers/char/console.c | 2 +- xen/include/xen/ctype.h | 7 +++++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/vuart.c b/xen/arch/arm/vuart.c index d5ba483f1e63245e545346ad5045098152b8c152..98a65b99385a2a119725bab8634ed7cf9d926d68 100644 --- a/xen/arch/arm/vuart.c +++ b/xen/arch/arm/vuart.c @@ -79,8 +79,7 @@ static void vuart_print_char(struct vcpu *v, char c) struct domain *d = v->domain; struct vuart *uart = &d->arch.vuart; - /* Accept only printable characters, newline, and horizontal tab. */ - if ( !isprint(c) && (c != '\n') && (c != '\t') ) + if ( !is_console_printable(c) ) return ; spin_lock(&uart->lock); diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 922c9b3af64d9132022d37627c54af092275e9cf..c4f1df248c1a7b2b3e5c45cef154e7ca80018dfc 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -561,8 +561,7 @@ static int cf_check hvm_print_line( if ( dir != IOREQ_WRITE ) return X86EMUL_UNHANDLEABLE; - /* Accept only printable characters, newline, and horizontal tab. */ - if ( !isprint(c) && (c != '\n') && (c != '\t') ) + if ( !is_console_printable(c) ) return X86EMUL_OKAY; spin_lock(&cd->pbuf_lock); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 7da8c5296f3b62c6c45131c58fe5cf0e393e9ef3..4cb397116b44935214801c496b30e44c9399c59a 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -674,7 +674,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, c = *kin++; if ( c == '\n' ) break; - if ( isprint(c) || c == '\t' ) + if ( is_console_printable(c) ) *kout++ = c; } while ( --kcount > 0 ); diff --git a/xen/include/xen/ctype.h b/xen/include/xen/ctype.h index 773ac27aa44ac65e76e87cdec960450804310249..ceb8f028ddc80b3b688f13422c0362199a03ba9e 100644 --- a/xen/include/xen/ctype.h +++ b/xen/include/xen/ctype.h @@ -4,6 +4,8 @@ /* * NOTE! This ctype does not handle EOF like the standard C * library is required to. + * + * See Rule 21.13 in docs/misra/rules.rst. */ #define _U 0x01 /* upper */ @@ -51,4 +53,9 @@ static inline unsigned char __toupper(unsigned char c) #define tolower(c) ((char)__tolower(c)) #define toupper(c) ((char)__toupper(c)) +static inline unsigned is_console_printable(unsigned char c) +{ + return isprint(c) || c == '\n' || c == '\t'; +} + #endif From patchwork Sat Jan 4 01:58:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926032 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 743BDE77198 for ; Sat, 4 Jan 2025 01:58:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864705.1275952 (Exim 4.92) (envelope-from ) id 1tTtQk-0005fg-31; Sat, 04 Jan 2025 01:58:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864705.1275952; Sat, 04 Jan 2025 01:58:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQj-0005ew-UU; Sat, 04 Jan 2025 01:58:21 +0000 Received: by outflank-mailman (input) for mailman id 864705; Sat, 04 Jan 2025 01:58:20 +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 1tTtQi-0005Ay-5U for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:20 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5c89f58e-ca3f-11ef-99a4-01e77a169b0f; Sat, 04 Jan 2025 02:58:16 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id D3CDFA411A1; Sat, 4 Jan 2025 01:56:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id BA0E6C4CEDF; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD68FE77199; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) 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: 5c89f58e-ca3f-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955894; bh=rMk6e8dP6iduBbKYzKwM0zuq90kaxVjD4waV73BrMWU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rAG3wWpo3Wao5hFXTgJFLK2wbqRt51cycoWp3/srRpFpZr8cV7o6O0ptiI/gmpUq3 p9H8OPAnjH5YUckkHYcS3nSClDmSFCX1Yw8q1hFmEUbM/NLIWDCntJeMo9EREFu06d JxLfAom7YBjEtyTcLkbhczYn/m3oOC2d1ahDpzGGy96pDuWzzIXushtgLuURFpbqSa dsUhtELuRG7X2uaClomEvu5pyrDles2hgHfiiMx+f9DwuLJ2wH4FWe+WRiClpguqkp 0S9G8xARuASgtijd+jokt+pmlpOd1T48VXQ4uxsvRJq25f9ei7q9Cgrd0e8WOJT94T AsH+WDKCd9I1A== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:08 -0800 Subject: [PATCH v3 02/24] arm/vuart: move vpl011-related code to vpl011 emulator MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-2-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=4317; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=WBvO8bA+8Nj2y5g4Kr43LtifU20Luw0hJhjCrT4qixs=; b=HFI194W9aVN9+Fxa7KERSNI5ADEY+BH7XLcU4u6tM3rnmm0dWvu6LsM9uIa17987zZ2YYl9bn F+CVVTwcpKgDkOE0n0HGlCmYRbIhuuvizU+fBvDJOd7E/Zi9Ocism8K X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Xen console driver has vpl011-related logic which shall belong vpl011 emulator code (Arm port). Move vpl011-related code from arch-independent console driver to Arm's vpl011.c. Signed-off-by: Denis Mukhin --- xen/arch/arm/include/asm/vpl011.h | 2 +- xen/arch/arm/vpl011.c | 15 +++++++++++---- xen/drivers/char/console.c | 23 +++++++++-------------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/xen/arch/arm/include/asm/vpl011.h b/xen/arch/arm/include/asm/vpl011.h index c09abcd7a9b3356d0809743517934adae00087f5..cc838682815c0d049ba33d3bf9966a64b2e527dd 100644 --- a/xen/arch/arm/include/asm/vpl011.h +++ b/xen/arch/arm/include/asm/vpl011.h @@ -69,7 +69,7 @@ struct vpl011_init_info { int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info); void domain_vpl011_deinit(struct domain *d); -void vpl011_rx_char_xen(struct domain *d, char c); +int vpl011_rx_char_xen(struct domain *d, char c); #else static inline int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 1fc3114cce9ddb48cf199834c8e9abe8cfba92b5..c72f3778bfedf9434f9d1a0cd7fa33852563112d 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -567,16 +567,21 @@ static void vpl011_data_avail(struct domain *d, /* * vpl011_rx_char_xen adds a char to a domain's vpl011 receive buffer. - * It is only used when the vpl011 backend is in Xen. */ -void vpl011_rx_char_xen(struct domain *d, char c) +int vpl011_rx_char_xen(struct domain *d, char c) { unsigned long flags; struct vpl011 *vpl011 = &d->arch.vpl011; struct vpl011_xen_backend *intf = vpl011->backend.xen; XENCONS_RING_IDX in_cons, in_prod, in_fifo_level; - ASSERT(!vpl011->backend_in_domain); + /* Forward input iff the vpl011 backend is in Xen. */ + if ( vpl011->backend_in_domain ) + return -ENODEV; + + if ( intf == NULL ) + return -ENODEV; + VPL011_LOCK(d, flags); in_cons = intf->in_cons; @@ -584,7 +589,7 @@ void vpl011_rx_char_xen(struct domain *d, char c) if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) == sizeof(intf->in) ) { VPL011_UNLOCK(d, flags); - return; + return -ENOSPC; } intf->in[xencons_mask(in_prod, sizeof(intf->in))] = c; @@ -596,6 +601,8 @@ void vpl011_rx_char_xen(struct domain *d, char c) vpl011_data_avail(d, in_fifo_level, sizeof(intf->in), 0, SBSA_UART_FIFO_SIZE); VPL011_UNLOCK(d, flags); + + return 0; } static void vpl011_notification(struct vcpu *v, unsigned int port) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 4cb397116b44935214801c496b30e44c9399c59a..1411c991977b5fb26ee5709e523b7bc32b612808 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -529,6 +529,8 @@ static void switch_serial_input(void) static void __serial_rx(char c) { + int rc = 0; + switch ( console_rx ) { case 0: @@ -554,21 +556,11 @@ static void __serial_rx(char c) { struct domain *d = rcu_lock_domain_by_id(console_rx - 1); - /* - * If we have a properly initialized vpl011 console for the - * domain, without a full PV ring to Dom0 (in that case input - * comes from the PV ring), then send the character to it. - */ - if ( d != NULL && - !d->arch.vpl011.backend_in_domain && - d->arch.vpl011.backend.xen != NULL ) - vpl011_rx_char_xen(d, c); - else - printk("Cannot send chars to Dom%d: no UART available\n", - console_rx - 1); - - if ( d != NULL ) + if ( d ) + { + rc = vpl011_rx_char_xen(d, c); rcu_unlock_domain(d); + } break; } @@ -579,6 +571,9 @@ static void __serial_rx(char c) if ( pv_shim && pv_console ) consoled_guest_tx(c); #endif + + if ( rc ) + printk(KERN_ERR "d%pd: failed to process console input: %d\n", d, rc); } static void cf_check serial_rx(char c) From patchwork Sat Jan 4 01:58:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926037 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 C3B52E7719D for ; Sat, 4 Jan 2025 01:58:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864702.1275929 (Exim 4.92) (envelope-from ) id 1tTtQi-0005BO-8T; Sat, 04 Jan 2025 01:58:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864702.1275929; Sat, 04 Jan 2025 01:58:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQi-0005BF-4G; Sat, 04 Jan 2025 01:58:20 +0000 Received: by outflank-mailman (input) for mailman id 864702; Sat, 04 Jan 2025 01:58:19 +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 1tTtQh-0005Ax-4U for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:19 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5c87a119-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:16 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BBEAA5C60DF; Sat, 4 Jan 2025 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id C8C30C4CEE1; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0D91E77198; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) 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: 5c87a119-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955894; bh=tVS12C3USoReyjZxz4AVM9AHh6CImFwneSMxcZyOSa8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=t56hCG20y/WyCEIkZGqGRW9p2xOe7f+eCta5fx4HRyrE17LlXUl8aHToFHApOj7xW GN0FmA2K7qJUVED7ztlLhErSloOzjSnXrMUiMu+sNIHlQQ79FBYYt7YwHaPWnUXd8h Rx+dNAIljirHypcYcZ1g5yutC+/Ep+ccS7EWXPw8BDmdVwhwlU+oxnPuQyz70iDeYW X54LoNVrGaQDWHTLX4PT1BG2wRbcLvhsUyRHaTYxIVPNrTClrp8SpMJILY7/k2vbsF yp3gzSVIkzrViYCs5PJXz5wNOKz0TgWw0skhOGq++CsKqMASvHzP4NYSHTzYSAh4Ok yMwikRbXEvwgw== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:09 -0800 Subject: [PATCH v3 03/24] arm/vuart: add hwdom prefix to UART emulator MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-3-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=5463; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=40dwRBx75DrBuSFfvZFLHZmEe2vsPE5uifchSIh7mKk=; b=O03Oul5Yz2t/R10EGb36YwgTtsEtmTIUs7q1wxPKjY2LshZm6JN+BWIF22uZs0UHVoxm1LCD0 6jxn7KWnS68CDKjU4ybD+6OapE+CUUrGstgWybDjSOqQT5C1IeLg9Zq X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Using "vuart" in UART emulator designed for hardware domain debugging is confusing in generic Arm code (e.g. vpl011 is also "vuart"). Fix that by adding hwdom prefix to all symbols in arm/vuart.c. Also, remove domain_has_vuart() from arm/vuart.c since it is not needed. Signed-off-by: Denis Mukhin --- xen/arch/arm/domain.c | 4 ++-- xen/arch/arm/vuart.c | 35 +++++++++++++++-------------------- xen/arch/arm/vuart.h | 8 ++++---- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 3ba959f866338d2e7f7dc0e301cd79c10fbc4549..7ef1a95c290752d5a0167806e298aacc834ea640 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -775,7 +775,7 @@ int arch_domain_create(struct domain *d, * Only use it for the hardware domain because the linux kernel may not * support multi-platform. */ - if ( is_hardware_domain(d) && (rc = domain_vuart_init(d)) ) + if ( is_hardware_domain(d) && (rc = hwdom_vuart_init(d)) ) goto fail; if ( (rc = domain_vpci_init(d)) != 0 ) @@ -844,7 +844,7 @@ void arch_domain_destroy(struct domain *d) iommu_domain_destroy(d); p2m_final_teardown(d); domain_vgic_free(d); - domain_vuart_free(d); + hwdom_vuart_free(d); free_xenheap_page(d->shared_info); #ifdef CONFIG_ACPI free_xenheap_pages(d->arch.efi_acpi_table, diff --git a/xen/arch/arm/vuart.c b/xen/arch/arm/vuart.c index 98a65b99385a2a119725bab8634ed7cf9d926d68..23e05dba3a5617863f6c08f085c358f2cf32a292 100644 --- a/xen/arch/arm/vuart.c +++ b/xen/arch/arm/vuart.c @@ -31,19 +31,17 @@ #include "vuart.h" -#define domain_has_vuart(d) ((d)->arch.vuart.info != NULL) +static int hwdom_vuart_mmio_read(struct vcpu *v, mmio_info_t *info, + register_t *r, void *priv); +static int hwdom_vuart_mmio_write(struct vcpu *v, mmio_info_t *info, + register_t r, void *priv); -static int vuart_mmio_read(struct vcpu *v, mmio_info_t *info, - register_t *r, void *priv); -static int vuart_mmio_write(struct vcpu *v, mmio_info_t *info, - register_t r, void *priv); - -static const struct mmio_handler_ops vuart_mmio_handler = { - .read = vuart_mmio_read, - .write = vuart_mmio_write, +static const struct mmio_handler_ops hwdom_vuart_mmio_handler = { + .read = hwdom_vuart_mmio_read, + .write = hwdom_vuart_mmio_write, }; -int domain_vuart_init(struct domain *d) +int hwdom_vuart_init(struct domain *d) { ASSERT( is_hardware_domain(d) ); @@ -58,7 +56,7 @@ int domain_vuart_init(struct domain *d) if ( !d->arch.vuart.buf ) return -ENOMEM; - register_mmio_handler(d, &vuart_mmio_handler, + register_mmio_handler(d, &hwdom_vuart_mmio_handler, d->arch.vuart.info->base_addr, d->arch.vuart.info->size, NULL); @@ -66,15 +64,12 @@ int domain_vuart_init(struct domain *d) return 0; } -void domain_vuart_free(struct domain *d) +void hwdom_vuart_free(struct domain *d) { - if ( !domain_has_vuart(d) ) - return; - - xfree(d->arch.vuart.buf); + XFREE(d->arch.vuart.buf); } -static void vuart_print_char(struct vcpu *v, char c) +static void hwdom_vuart_print_char(struct vcpu *v, char c) { struct domain *d = v->domain; struct vuart *uart = &d->arch.vuart; @@ -95,7 +90,7 @@ static void vuart_print_char(struct vcpu *v, char c) spin_unlock(&uart->lock); } -static int vuart_mmio_read(struct vcpu *v, mmio_info_t *info, +static int hwdom_vuart_mmio_read(struct vcpu *v, mmio_info_t *info, register_t *r, void *priv) { struct domain *d = v->domain; @@ -113,7 +108,7 @@ static int vuart_mmio_read(struct vcpu *v, mmio_info_t *info, return 1; } -static int vuart_mmio_write(struct vcpu *v, mmio_info_t *info, +static int hwdom_vuart_mmio_write(struct vcpu *v, mmio_info_t *info, register_t r, void *priv) { struct domain *d = v->domain; @@ -123,7 +118,7 @@ static int vuart_mmio_write(struct vcpu *v, mmio_info_t *info, if ( offset == d->arch.vuart.info->data_off ) /* ignore any status bits */ - vuart_print_char(v, r & 0xFF); + hwdom_vuart_print_char(v, r & 0xFF); return 1; } diff --git a/xen/arch/arm/vuart.h b/xen/arch/arm/vuart.h index e90d84c6eddbb9d9089845c80062940eab997339..e6ca5582726736668765f5928b5c75e821db8aac 100644 --- a/xen/arch/arm/vuart.h +++ b/xen/arch/arm/vuart.h @@ -24,12 +24,12 @@ struct domain; #ifdef CONFIG_HWDOM_VUART -int domain_vuart_init(struct domain *d); -void domain_vuart_free(struct domain *d); +int hwdom_vuart_init(struct domain *d); +void hwdom_vuart_free(struct domain *d); #else -static inline int domain_vuart_init(struct domain *d) +static inline int hwdom_vuart_init(struct domain *d) { /* * The vUART is unconditionally inialized for the hw domain. So we @@ -38,7 +38,7 @@ static inline int domain_vuart_init(struct domain *d) return 0; } -static inline void domain_vuart_free(struct domain *d) {}; +static inline void hwdom_vuart_free(struct domain *d) {}; #endif /* CONFIG_HWDOM_VUART */ From patchwork Sat Jan 4 01:58:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926035 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 C3AC9E7719C for ; Sat, 4 Jan 2025 01:58:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864708.1275973 (Exim 4.92) (envelope-from ) id 1tTtQl-0005yG-FL; Sat, 04 Jan 2025 01:58:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864708.1275973; Sat, 04 Jan 2025 01:58:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQl-0005wf-1u; Sat, 04 Jan 2025 01:58:23 +0000 Received: by outflank-mailman (input) for mailman id 864708; Sat, 04 Jan 2025 01:58:20 +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 1tTtQi-0005Ax-QA for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:20 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5ca73fa4-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:16 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E33BF5C60ED; Sat, 4 Jan 2025 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id D71FBC4CEE2; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF2FCE77188; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) 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: 5ca73fa4-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955894; bh=+3lCSi+uoUjLrXI5KsViTk7A/iJtn55QaL5KYfpM3dY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=VtKbMyAsDxs/eyxr7xdavPZ/ZX8Cz0NvMrqSJFth6/byn76U9CHyJ4UFMd2mM7tlY mupTUqBtSA8RRG8PsQz1Ge2aCj9LMffCfedtw2fktoQxfEJXiv8FiIbI6p8yRhWSRI u+yI4HgeZKfSbx6Pv8r5JhF5SEDSJDISEsXCoxp2npdZSp6RRuqOFQysZ9PxoEbAqu 5E7fkgS98rnm+pB4ROJeykD+r3/D/WymT0Bw3jWnEnzhs5SX2MuancdfEzFpSRJQGm MH8xKVnACypKZoTV7lvcmv0uukCf7QYSjGoAnWkjD6nHDzHCwkLwgMpdDw/Ob9ezCL 7U8CzPUPEx8Mg== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:10 -0800 Subject: [PATCH v3 04/24] xen/console: introduce console_{get,put}_domain() MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-4-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=4310; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=R8dApJ/XiKqchnt0Y9PJCOHsEWibqS36Kuatzu/KWu8=; b=rK9fr+LsEaTbokvlrCZ5xF8dd1MfNZorXXzg3xb4JWUj/zpaTVp8S/Q0xZx0mVKdNRQp0oBC1 1zCgsNnNpYABQvoEcda1xy4WpELmdyQjZUv036bWzaLNEjynD9w9v9J X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin console_input_domain() takes an RCU lock to protect domain structure. That implies call to rcu_unlock_domain() after use. Introduce a pair of console_get_domain() / console_put_domain() to highlight the correct use of the call within the code interacting with Xen console driver. Also, use new calls in the console driver in __serial_rx(). That prepares the code for the follow-on console driver cleanup series. Signed-off-by: Denis Mukhin --- xen/arch/arm/vpl011.c | 6 +++--- xen/drivers/char/console.c | 44 +++++++++++++++++++++----------------------- xen/include/xen/console.h | 3 ++- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index c72f3778bfedf9434f9d1a0cd7fa33852563112d..66047bf33cedb930a6bd7c96577913cd1ae08f05 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -78,7 +78,7 @@ 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_input_domain(); + struct domain *input = console_get_domain(); VPL011_LOCK(d, flags); @@ -123,8 +123,8 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data) vpl011_update_interrupt_status(d); VPL011_UNLOCK(d, flags); - if ( input != NULL ) - rcu_unlock_domain(input); + + console_put_domain(input); } /* diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 1411c991977b5fb26ee5709e523b7bc32b612808..4785f0e93a17e3ecba79a7813d2928f946abab8f 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -475,15 +475,18 @@ static unsigned int __read_mostly console_rx = 0; #define max_console_rx (max_init_domid + 1) -#ifdef CONFIG_SBSA_VUART_CONSOLE -/* Make sure to rcu_unlock_domain after use */ -struct domain *console_input_domain(void) +struct domain *console_get_domain(void) { if ( console_rx == 0 ) return NULL; return rcu_lock_domain_by_id(console_rx - 1); } -#endif + +void console_put_domain(struct domain *d) +{ + if ( d ) + rcu_unlock_domain(d); +} static void switch_serial_input(void) { @@ -529,14 +532,18 @@ static void switch_serial_input(void) static void __serial_rx(char c) { + struct domain *d; int rc = 0; - switch ( console_rx ) - { - case 0: + if ( console_rx == 0 ) return handle_keypress(c, false); - case 1: + d = console_get_domain(); + if ( !d ) + return; + + if ( is_hardware_domain(d) ) + { /* * Deliver input to the hardware domain buffer, unless it is * already full. @@ -549,23 +556,12 @@ static void __serial_rx(char c) * getting stuck. */ send_global_virq(VIRQ_CONSOLE); - break; - + } #ifdef CONFIG_SBSA_VUART_CONSOLE - default: - { - struct domain *d = rcu_lock_domain_by_id(console_rx - 1); - - if ( d ) - { - rc = vpl011_rx_char_xen(d, c); - rcu_unlock_domain(d); - } - - break; - } + else + /* Deliver input to the emulated UART. */ + rc = vpl011_rx_char_xen(d, c); #endif - } #ifdef CONFIG_X86 if ( pv_shim && pv_console ) @@ -574,6 +570,8 @@ static void __serial_rx(char c) if ( rc ) printk(KERN_ERR "d%pd: failed to process console input: %d\n", d, rc); + + console_put_domain(d); } static void cf_check serial_rx(char c) diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 6dfbade3ece36352c74f1124305da945b210f2a7..8631fd279bfe1aba42b61d76fbdb45016c2859f9 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -31,7 +31,8 @@ void console_end_sync(void); void console_start_log_everything(void); void console_end_log_everything(void); -struct domain *console_input_domain(void); +struct domain *console_get_domain(void); +void console_put_domain(struct domain *d); /* * Steal output from the console. Returns +ve identifier, else -ve error. From patchwork Sat Jan 4 01:58:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926034 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 93807C3DA4A for ; Sat, 4 Jan 2025 01:58:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864714.1276024 (Exim 4.92) (envelope-from ) id 1tTtQq-00076n-5N; Sat, 04 Jan 2025 01:58:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864714.1276024; Sat, 04 Jan 2025 01:58:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQp-000740-Et; Sat, 04 Jan 2025 01:58:27 +0000 Received: by outflank-mailman (input) for mailman id 864714; Sat, 04 Jan 2025 01:58:24 +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 1tTtQl-0005Ax-Qi for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:23 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5dd063cb-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:18 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 08B4B5C613E; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id EB6A4C4CED6; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2F05E77198; Sat, 4 Jan 2025 01:58:14 +0000 (UTC) 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: 5dd063cb-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=AA7+mFgdv/CLreA2xkAbjLNCRVAgqmaEv1ja2uxK2AE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=kIWEW/eRK6fqXTa7M+eKyUBgFAU6g0f4xk5l5oE99ZnF0P1X0cWwRnuDgYGKYj6hc MIncbo7zBD1qIRsMYWCiYlmw7UAxjoHbCe08EEqxpQzX8uuCGAgySBCGBPuKb6WLIS OjUd4CKhK1BFxt/OpBtsmUKre/E+9ezEn6cbx5JwlxPeTWlNxOmxMjUkWLKHvItOEE tDuEwpinIHXawJOr104bGNSab64JRwi3g8jQjty0IlyrOvivNYa5ygUjA7zigC/E8Z k1RCWGsxcFTx3I8cSs3FgPAJygzY3zuCUvLP2VzTE9d6nICd+1zMTgOqxazXKaVtAP 0aA++obj1Ul3A== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:11 -0800 Subject: [PATCH v3 05/24] xen/console: introduce consoled_is_enabled() MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-5-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=4404; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=n4Aqa3ybnKIx5xmfT+5F0wUDK/FeirbGr0o6DW85ymA=; b=C4K8KLpFn1MjYhJMBZQMxhbcwkSQbMQPkN60/GkOpUDva4wrnJU3OI1jMwq1OYrhFKd3FJAbL pLO5JKF6+JdBYum8mrIHzPA5dZ7qRLqRtkU0jOY0jQiRbsCifK3SU4j X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin There are few places which check pv_shim console under CONFIG_PV_SHIM in xen console driver. Instead of #ifdef-ing, use new consoled_is_enabled() to customize the logic. Header file now can be included w/o CONFIG_X86. Signature of consoled_guest_{rx,tx} has changed so the error can be logged. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 13 +++++-------- xen/drivers/char/consoled.c | 17 +++++++++++++---- xen/include/xen/consoled.h | 32 +++++++++++++++++++++++++++----- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 4785f0e93a17e3ecba79a7813d2928f946abab8f..2d20a9d7531e069803eaf30ce79354b998c4a52f 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -33,9 +33,9 @@ #include #include #include +#include #ifdef CONFIG_X86 -#include #include #endif #ifdef CONFIG_SBSA_VUART_CONSOLE @@ -508,11 +508,9 @@ static void switch_serial_input(void) break; } -#ifdef CONFIG_PV_SHIM - if ( next_rx == 1 ) + if ( consoled_is_enabled() && next_rx == 1 ) domid = get_initial_domain_id(); else -#endif domid = next_rx - 1; d = rcu_lock_domain_by_id(domid); if ( d ) @@ -563,10 +561,9 @@ static void __serial_rx(char c) rc = vpl011_rx_char_xen(d, c); #endif -#ifdef CONFIG_X86 - if ( pv_shim && pv_console ) - consoled_guest_tx(c); -#endif + if ( consoled_is_enabled() ) + /* Deliver input to the PV shim console. */ + rc = consoled_guest_tx(c); if ( rc ) printk(KERN_ERR "d%pd: failed to process console input: %d\n", d, rc); diff --git a/xen/drivers/char/consoled.c b/xen/drivers/char/consoled.c index b415b632cecc0a80e161b701d7b70ba4f3cc5fb8..8704ec251eb19e9c1cdc5927f896aeb20cc5af1e 100644 --- a/xen/drivers/char/consoled.c +++ b/xen/drivers/char/consoled.c @@ -43,13 +43,13 @@ struct xencons_interface *consoled_get_ring_addr(void) static char buf[BUF_SZ + 1]; /* Receives characters from a domain's PV console */ -void consoled_guest_rx(void) +int consoled_guest_rx(void) { size_t idx = 0; XENCONS_RING_IDX cons, prod; if ( !cons_ring ) - return; + return -ENODEV; spin_lock(&rx_lock); @@ -91,15 +91,17 @@ void consoled_guest_rx(void) out: spin_unlock(&rx_lock); + + return 0; } /* Sends a character into a domain's PV console */ -void consoled_guest_tx(char c) +int consoled_guest_tx(char c) { XENCONS_RING_IDX cons, prod; if ( !cons_ring ) - return; + return -ENODEV; cons = ACCESS_ONCE(cons_ring->in_cons); prod = cons_ring->in_prod; @@ -125,6 +127,13 @@ void consoled_guest_tx(char c) notify: /* Always notify the guest: prevents receive path from getting stuck. */ pv_shim_inject_evtchn(pv_console_evtchn()); + + return 0; +} + +bool consoled_is_enabled(void) +{ + return pv_shim && pv_console; } /* diff --git a/xen/include/xen/consoled.h b/xen/include/xen/consoled.h index bd7ab6329ee8a7c466484021247241ded8ed03c7..14e5e3284a86201919f0f70a8c2785609f35b15f 100644 --- a/xen/include/xen/consoled.h +++ b/xen/include/xen/consoled.h @@ -1,14 +1,36 @@ -#ifndef __XEN_CONSOLED_H__ -#define __XEN_CONSOLED_H__ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef XEN__CONSOLED_H +#define XEN__CONSOLED_H #include +#ifdef CONFIG_PV_SHIM + void consoled_set_ring_addr(struct xencons_interface *ring); struct xencons_interface *consoled_get_ring_addr(void); -void consoled_guest_rx(void); -void consoled_guest_tx(char c); +int consoled_guest_rx(void); +int consoled_guest_tx(char c); +bool consoled_is_enabled(void); -#endif /* __XEN_CONSOLED_H__ */ +#else + +static inline int consoled_guest_rx(void) +{ + ASSERT_UNREACHABLE(); + return 0; +} + +static inline int consoled_guest_tx(char c) +{ + ASSERT_UNREACHABLE(); + return 0; +} + +#define consoled_is_enabled() ( false ) + +#endif /* CONFIG_PV_SHIM */ + +#endif /* XEN__CONSOLED_H */ /* * Local variables: * mode: C From patchwork Sat Jan 4 01:58:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926036 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 9123AE7719B for ; Sat, 4 Jan 2025 01:58:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864713.1276015 (Exim 4.92) (envelope-from ) id 1tTtQp-0006tt-Bc; Sat, 04 Jan 2025 01:58:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864713.1276015; Sat, 04 Jan 2025 01:58:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQo-0006ra-Jw; Sat, 04 Jan 2025 01:58:26 +0000 Received: by outflank-mailman (input) for mailman id 864713; Sat, 04 Jan 2025 01:58:23 +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 1tTtQl-0005Ay-Gz for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:23 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5cc6243e-ca3f-11ef-99a4-01e77a169b0f; Sat, 04 Jan 2025 02:58:16 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 01CB25C612B; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 0EABBC4CEDD; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 030C4E77199; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5cc6243e-ca3f-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=/WKmnea3yLIQ6a+oMKt9n2ogwwKjvRERH5nesO0D+A4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=OD1jaknYEc0PCdD3OGrHIkODdou0AzX4vUcJI3flns1hwehOL4P9JPmQ+aIBQ3rjO TlXCBDsEUh607FqwLg9hFiPQ1arJIvoapsVLxOOOJhK7UelCoK9g5Ekh7KUW6XlxmR tZmk/OttAQ+CyW9kjMH+dI5+Nr1BpekQcf867RiFQMYMRI858D/o1aR/U6SZFZvwD+ nPdDRd0Xv3glrDZHpSk6XGfx13nk28lmho4FtZud1tlqgL8JVEPQ17R30KZK5a4nfO lwi0tE5syOpK2BS8cQTH1JNEqljMIMkZUPZUAKTiOYgR8PdEyVBpki+0nC9xbqN1eH q5cW6TtWwSGJg== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:12 -0800 Subject: [PATCH v3 06/24] xen/domain: introduce hardware emulation flags MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-6-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=15422; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=yo4lK/WoRy/gFaXrqWR73G8aid7G29/FsP8hJ1ebvNs=; b=x65w53tEdhJNfnDQwDvwDCI6NghHC/63VP4zaLKnVqk0fUWNCWc/gcP61ZPVZC8xu1iwsvXGW mUlDZIBx7S4CbRDiYShFkvq1zTtTTSOVcQNRv5cCqQCg228IdGqqj2/ X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Define an architecture-independent location for describing hardware emulation flags for configuring in-hypervisor emulators. Print d->arch.emulation_flags from 'q' keyhandler for better traceability while debugging in-hypervisor hardware emulators. Also, expanded the error message in arch_domain_create() in x86 case when user-defined domain emulation_flags are incompatible w/ platform supported emulation_flags. Signed-off-by: Denis Mukhin --- tools/helpers/init-xenstore-domain.c | 1 + tools/libs/light/libxl_x86.c | 5 +- tools/ocaml/libs/xc/xenctrl_stubs.c | 1 + tools/python/xen/lowlevel/xc/xc.c | 5 +- tools/tests/paging-mempool/test-paging-mempool.c | 1 + tools/tests/resource/test-resource.c | 1 + tools/tests/tsx/test-tsx.c | 1 + xen/arch/arm/include/asm/domain.h | 2 + xen/arch/ppc/include/asm/domain.h | 2 + xen/arch/riscv/include/asm/domain.h | 2 + xen/arch/x86/domain.c | 11 +++-- xen/arch/x86/include/asm/domain.h | 3 +- xen/common/keyhandler.c | 1 + xen/include/Makefile | 1 + xen/include/public/arch-x86/xen.h | 30 +----------- xen/include/public/virtdev.h | 61 ++++++++++++++++++++++++ xen/include/xen/domain.h | 1 + 17 files changed, 90 insertions(+), 39 deletions(-) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c index 01ca667d25d15032e9acaff025e83b80aefd2ecb..4b64a417def59c92b8bfb828468591d00d16c105 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "init-dom-json.h" diff --git a/tools/libs/light/libxl_x86.c b/tools/libs/light/libxl_x86.c index a3164a3077fec7e1b81a34074894dc646954a49a..80a8a4f17a9a2d7f84f94382e110d511b76604a2 100644 --- a/tools/libs/light/libxl_x86.c +++ b/tools/libs/light/libxl_x86.c @@ -1,5 +1,6 @@ #include "libxl_internal.h" #include "libxl_arch.h" +#include #include int libxl__arch_domain_prepare_config(libxl__gc *gc, @@ -8,7 +9,9 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, { switch(d_config->c_info.type) { case LIBXL_DOMAIN_TYPE_HVM: - config->arch.emulation_flags = (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI); + config->arch.emulation_flags = XEN_X86_EMU_ALL; + config->arch.emulation_flags &= ~XEN_X86_EMU_VPCI; + if (!libxl_defbool_val(d_config->b_info.u.hvm.pirq)) config->arch.emulation_flags &= ~XEN_X86_EMU_USE_PIRQ; break; diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c index 863ab3c778cd19637d8c52ec67dac7623be848b5..b693f3458629fb956d543d7491348cf953c67d6f 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -35,6 +35,7 @@ #define XC_WANT_COMPAT_MAP_FOREIGN_API #include #include +#include #include #include "mmap_stubs.h" diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index 9feb12ae2b16e48cb5d0c3c45044ae226f152f2d..d064e9e7af2fcc09dbd6485e8b9ef648b8068d00 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -159,9 +160,7 @@ static PyObject *pyxc_domain_create(XcObject *self, #if defined (__i386) || defined(__x86_64__) if ( config.flags & XEN_DOMCTL_CDF_hvm ) - config.arch.emulation_flags = XEN_X86_EMU_ALL & - ~(XEN_X86_EMU_VPCI | - XEN_X86_EMU_USE_PIRQ); + config.arch.emulation_flags = XEN_X86_EMU_BASELINE; #elif defined (__arm__) || defined(__aarch64__) config.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE; #else diff --git a/tools/tests/paging-mempool/test-paging-mempool.c b/tools/tests/paging-mempool/test-paging-mempool.c index 1ebc13455ac263b8d2067f3676ba324da61abb83..121ffdcd376ddb324130a441352bf2a53d69b1e9 100644 --- a/tools/tests/paging-mempool/test-paging-mempool.c +++ b/tools/tests/paging-mempool/test-paging-mempool.c @@ -9,6 +9,7 @@ #include #include #include +#include static unsigned int nr_failures; #define fail(fmt, ...) \ diff --git a/tools/tests/resource/test-resource.c b/tools/tests/resource/test-resource.c index 1b10be16a6b43f8448a6f4ccf8fd093b6556b915..e388bfeec57b1f16a6ccd9ede8ff1c02c0448393 100644 --- a/tools/tests/resource/test-resource.c +++ b/tools/tests/resource/test-resource.c @@ -8,6 +8,7 @@ #include #include #include +#include static unsigned int nr_failures; #define fail(fmt, ...) \ diff --git a/tools/tests/tsx/test-tsx.c b/tools/tests/tsx/test-tsx.c index 5af04953f340febcf56da9b041338237b71617cb..5681b3c846715e913169277ee4a11ca087013fb6 100644 --- a/tools/tests/tsx/test-tsx.c +++ b/tools/tests/tsx/test-tsx.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "xg_private.h" diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index f1d72c6e48dfeba347b4cd091ca33603c368b7c0..3dedf758bbd1f142debbc7c2460398e1bea822d7 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -119,6 +119,8 @@ struct arch_domain void *tee; #endif + /* Hardware emulation flags. */ + uint32_t emulation_flags; } __cacheline_aligned; struct arch_vcpu diff --git a/xen/arch/ppc/include/asm/domain.h b/xen/arch/ppc/include/asm/domain.h index 3a447272c6f28586bf0d610929adbf228579e13f..8aa7b4a6ac0d0850542e94cb28e58c62c3a4b156 100644 --- a/xen/arch/ppc/include/asm/domain.h +++ b/xen/arch/ppc/include/asm/domain.h @@ -21,6 +21,8 @@ struct arch_vcpu { struct arch_domain { struct hvm_domain hvm; + /* Hardware emulation flags. */ + uint32_t emulation_flags; }; #include diff --git a/xen/arch/riscv/include/asm/domain.h b/xen/arch/riscv/include/asm/domain.h index c3d965a559b6ce3661bf17166d0c51853ff295a2..b561e6f4f868e1f4a6670b11111eb8cfe84ca385 100644 --- a/xen/arch/riscv/include/asm/domain.h +++ b/xen/arch/riscv/include/asm/domain.h @@ -18,6 +18,8 @@ struct arch_vcpu { struct arch_domain { struct hvm_domain hvm; + /* Hardware emulation flags. */ + uint32_t emulation_flags; }; #include diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 78a13e6812c9120901d0a70fb3bc1bd6a8b6917d..9669886ac95cbee27c9eb72b16386705b470e7b1 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -753,9 +753,7 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) emflags != (X86_EMU_VPCI | X86_EMU_LAPIC | X86_EMU_IOAPIC) ) return false; if ( !is_hardware_domain(d) && - /* HVM PIRQ feature is user-selectable. */ - (emflags & ~X86_EMU_USE_PIRQ) != - (X86_EMU_ALL & ~(X86_EMU_VPCI | X86_EMU_USE_PIRQ)) && + xen_emflags_allowable(emflags) != XEN_X86_EMU_BASELINE && emflags != X86_EMU_LAPIC ) return false; } @@ -818,9 +816,12 @@ int arch_domain_create(struct domain *d, if ( !emulation_flags_ok(d, emflags) ) { - printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation " + printk(XENLOG_G_ERR "%pd: Xen does not allow %s %sdomain creation " "with the current selection of emulators: %#x\n", - d->domain_id, is_hvm_domain(d) ? "HVM" : "PV", emflags); + d, + is_hvm_domain(d) ? "HVM" : "PV", + is_hardware_domain(d) ? "(hardware) " : "", + emflags); return -EOPNOTSUPP; } d->arch.emulation_flags = emflags; diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h index b79d6badd71c4d96279555df62fad75fe817a2b6..2532616bca015d0aad9abc35e14948937ab39b8f 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -456,7 +457,7 @@ struct arch_domain /* Don't unconditionally inject #GP for unhandled MSRs. */ bool msr_relaxed; - /* Emulated devices enabled bitmap. */ + /* Hardware emulation flags. */ uint32_t emulation_flags; } __cacheline_aligned; diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 6ea54838d434f9788e309c79119f1dab92fba6e3..7c331bc17bf279d4dd95ec5bbb540a70657cc1d1 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -302,6 +302,7 @@ static void cf_check dump_domains(unsigned char key) if ( test_bit(i, &d->watchdog_inuse_map) ) printk(" watchdog %d expires in %d seconds\n", i, (u32)((d->watchdog_timer[i].expires - NOW()) >> 30)); + printk(" emulation_flags %#x\n", d->arch.emulation_flags); arch_dump_domain_info(d); diff --git a/xen/include/Makefile b/xen/include/Makefile index 058b0a566b8b97305554add529ede6ba9ac53a7e..a7820e0e99763fbad36c52ba4f95290798e34893 100644 --- a/xen/include/Makefile +++ b/xen/include/Makefile @@ -15,6 +15,7 @@ headers-y := \ compat/sched.h \ compat/vcpu.h \ compat/version.h \ + compat/virtdev.h \ compat/xen.h \ compat/xlat.h headers-$(CONFIG_X86) += compat/arch-x86/pmu.h diff --git a/xen/include/public/arch-x86/xen.h b/xen/include/public/arch-x86/xen.h index fc2487986642a7694578ab9d2f5f16d09761bff8..fdf05875f26e63d7bcce34a1ad4e931ce22dbdc5 100644 --- a/xen/include/public/arch-x86/xen.h +++ b/xen/include/public/arch-x86/xen.h @@ -261,35 +261,7 @@ typedef struct arch_shared_info arch_shared_info_t; * XEN_DOMCTL_INTERFACE_VERSION. */ struct xen_arch_domainconfig { -#define _XEN_X86_EMU_LAPIC 0 -#define XEN_X86_EMU_LAPIC (1U<<_XEN_X86_EMU_LAPIC) -#define _XEN_X86_EMU_HPET 1 -#define XEN_X86_EMU_HPET (1U<<_XEN_X86_EMU_HPET) -#define _XEN_X86_EMU_PM 2 -#define XEN_X86_EMU_PM (1U<<_XEN_X86_EMU_PM) -#define _XEN_X86_EMU_RTC 3 -#define XEN_X86_EMU_RTC (1U<<_XEN_X86_EMU_RTC) -#define _XEN_X86_EMU_IOAPIC 4 -#define XEN_X86_EMU_IOAPIC (1U<<_XEN_X86_EMU_IOAPIC) -#define _XEN_X86_EMU_PIC 5 -#define XEN_X86_EMU_PIC (1U<<_XEN_X86_EMU_PIC) -#define _XEN_X86_EMU_VGA 6 -#define XEN_X86_EMU_VGA (1U<<_XEN_X86_EMU_VGA) -#define _XEN_X86_EMU_IOMMU 7 -#define XEN_X86_EMU_IOMMU (1U<<_XEN_X86_EMU_IOMMU) -#define _XEN_X86_EMU_PIT 8 -#define XEN_X86_EMU_PIT (1U<<_XEN_X86_EMU_PIT) -#define _XEN_X86_EMU_USE_PIRQ 9 -#define XEN_X86_EMU_USE_PIRQ (1U<<_XEN_X86_EMU_USE_PIRQ) -#define _XEN_X86_EMU_VPCI 10 -#define XEN_X86_EMU_VPCI (1U<<_XEN_X86_EMU_VPCI) - -#define XEN_X86_EMU_ALL (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET | \ - XEN_X86_EMU_PM | XEN_X86_EMU_RTC | \ - XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC | \ - XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \ - XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ - XEN_X86_EMU_VPCI) + /* Hardware emulation flags. */ uint32_t emulation_flags; /* diff --git a/xen/include/public/virtdev.h b/xen/include/public/virtdev.h new file mode 100644 index 0000000000000000000000000000000000000000..27434377ecacfe069a91dea3768d14b0c14e08b4 --- /dev/null +++ b/xen/include/public/virtdev.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef XEN__PUBLIC_VIRTDEV_H +#define XEN__PUBLIC_VIRTDEV_H + +/* + * Domain hardware emulation flags. + */ +enum { + VIRTDEV_LAPIC = 1U << 0, + VIRTDEV_HPET = 1U << 1, + VIRTDEV_PM = 1U << 2, + VIRTDEV_RTC = 1U << 3, + VIRTDEV_IOAPIC = 1U << 4, + VIRTDEV_PIC = 1U << 5, + VIRTDEV_VGA = 1U << 6, + VIRTDEV_IOMMU = 1U << 7, + VIRTDEV_PIT = 1U << 8, + VIRTDEV_PIRQ = 1U << 9, + VIRTDEV_PCI = 1U << 10, +}; + +#if defined(__i386__) || defined(__x86_64__) +#define XEN_X86_EMU_LAPIC VIRTDEV_LAPIC +#define XEN_X86_EMU_HPET VIRTDEV_HPET +#define XEN_X86_EMU_PM VIRTDEV_PM +#define XEN_X86_EMU_RTC VIRTDEV_RTC +#define XEN_X86_EMU_IOAPIC VIRTDEV_IOAPIC +#define XEN_X86_EMU_PIC VIRTDEV_PIC +#define XEN_X86_EMU_VGA VIRTDEV_VGA +#define XEN_X86_EMU_IOMMU VIRTDEV_IOMMU +#define XEN_X86_EMU_PIT VIRTDEV_PIT +#define XEN_X86_EMU_USE_PIRQ VIRTDEV_PIRQ +#define XEN_X86_EMU_VPCI VIRTDEV_PCI + +#define XEN_X86_EMU_ALL (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET | \ + XEN_X86_EMU_PM | XEN_X86_EMU_RTC | \ + XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC | \ + XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \ + XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ + XEN_X86_EMU_VPCI) + +/* PIRQ (HVM) feature is user-selectable (libxl). */ +#define XEN_X86_EMU_OPTIONAL (XEN_X86_EMU_VPCI | \ + XEN_X86_EMU_USE_PIRQ) + +#define XEN_X86_EMU_BASELINE xen_emflags_allowable(XEN_X86_EMU_ALL) + +#define xen_emflags_allowable(x) ( (x) & ~XEN_X86_EMU_OPTIONAL ) +#endif /* #if defined(__i386__) || defined(__x86_64__) */ + +#endif /* XEN__PUBLIC_VIRTDEV_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 3de56352911347a54cce310f0211bcc213d8a08d..eec093e9e167c14a536383422d280ed5ee56f698 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -5,6 +5,7 @@ #include #include +#include #include struct guest_area { From patchwork Sat Jan 4 01:58:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926046 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 0EE40C02182 for ; Sat, 4 Jan 2025 01:58:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864704.1275949 (Exim 4.92) (envelope-from ) id 1tTtQj-0005dd-Qx; Sat, 04 Jan 2025 01:58:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864704.1275949; Sat, 04 Jan 2025 01:58:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQj-0005dW-NP; Sat, 04 Jan 2025 01:58:21 +0000 Received: by outflank-mailman (input) for mailman id 864704; Sat, 04 Jan 2025 01:58:19 +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 1tTtQh-0005Ax-Po for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:19 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5c98c525-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:16 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 38D1BA406B3; Sat, 4 Jan 2025 01:56:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 1FBE0C4CEDE; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17060E77198; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5c98c525-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=ozuAIUEC9kYvZPh1viwAiXRxK6v41KulMiHqosxlddk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Xt0TQgCWoK3CpeiNu3J2IHjIb9Pe+2HhWLjz2kE+qpVzBgDSDENK+vJF8/HtkP/Rt QkLRRKIqqnt1VAvifCIfCqY0jXM7jMplW2U/0ewocCTu1jpRstsB8eXydVJ1/SfzGy 4/01jch0vTR3bUlV9OfQ0KMDETjanQZbMXrnsK0fcgZTSXWSbNWxaHnDLKM+UIkRIH mtatQRWfVxHdI6UQMyjiVbb/beOnh82IQKY53mU9gkFcMbpa8QPGBFPAKsW269CiEd OgC7KA+62rrfb49gPDJlqsKHH0xTm4/FwIESevxBoxj0WuY2aPfU0eE6fju7xyuURY Qs3sMALrx36Qw== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:13 -0800 Subject: [PATCH v3 07/24] xen/console: introduce framework for UART emulators MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-7-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=20565; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=+qDoty7zETfSP7cDTtaMjm20Q4Ar3xPkCT1pAjGNRBA=; b=NjNytDgX7I98JX0c3E/AXYpE2iJB+eZjNeTD482lBrp1oS+c9OEztAjDd1s0mETykULeJ1WF/ q4187w3hOq7DQwmy7jv/TiTBlxPe4QoiOYQwlPfPTOZNuOGwTkDDjcy X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Introduce a driver framework to abstract UART emulators in the hypervisor. That allows for architecture-independent handling of virtual UARTs from Xen console driver and simplifies enabling new architecture-dependent UART emulators. The framework is built under CONFIG_HAS_VUART, which is automatically enabled once the user selects a specific UART emulator. All domains w/ enabled vUART will have VIRTDEV_UART bit set in d->arch.emulation_flags. Current implementation supports maximum of one vUART per domain, excluding emulators for hardware domains. Use domain_has_vuart() in Xen console driver code to check whether the domain can own the physical console focus. Note, arm/vuart.c emulator is not hooked to virtdev-uart framework because the emulator is limited to the hardware domains only and was not designed to own the physical console input. Updated arm/vuart.c APIs to have 'hwdom_' prefix instead of generic 'domain_' to avoid possible confusion. Signed-off-by: Denis Mukhin --- xen/arch/arm/Kconfig | 1 + xen/arch/arm/dom0less-build.c | 4 +-- xen/arch/arm/domain.c | 2 +- xen/arch/arm/domctl.c | 11 +++--- xen/arch/arm/include/asm/vpl011.h | 21 +----------- xen/arch/arm/vpl011.c | 33 ++++++++++++------ xen/arch/arm/vuart.c | 3 ++ xen/arch/arm/xen.lds.S | 1 + xen/arch/ppc/xen.lds.S | 1 + xen/arch/riscv/xen.lds.S | 1 + xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/xen.lds.S | 1 + xen/common/keyhandler.c | 3 ++ xen/drivers/Kconfig | 5 +++ xen/drivers/Makefile | 1 + xen/drivers/char/console.c | 11 +++--- xen/drivers/virtdev-uart.c | 60 ++++++++++++++++++++++++++++++++ xen/include/public/virtdev.h | 1 + xen/include/xen/domain.h | 3 ++ xen/include/xen/virtdev-uart.h | 72 +++++++++++++++++++++++++++++++++++++++ xen/include/xen/xen.lds.h | 10 ++++++ 21 files changed, 200 insertions(+), 46 deletions(-) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index a26d3e11827cfe030d36400e322aa9b65502674c..8af4538bec2df3c3b15fa42b054bda658d9edad0 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -175,6 +175,7 @@ config NEW_VGIC config SBSA_VUART_CONSOLE bool "Emulated SBSA UART console support" default y + select HAS_VUART help Allows a guest to use SBSA Generic UART as a console. The SBSA Generic UART implements a subset of ARM PL011 UART. diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 49d1f14d659b28a906b498157e93ce544465d89e..78fba18b6aa80278207f920145c5aab4fecc6d18 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -785,7 +785,7 @@ static int __init construct_domU(struct domain *d, */ if ( kinfo.vpl011 ) { - rc = domain_vpl011_init(d, NULL); + rc = virtdev_uart_init(d, NULL); if ( rc < 0 ) return rc; } @@ -891,7 +891,7 @@ void __init create_domUs(void) * d->arch.vpl011.irq. So the logic to find the vIRQ has to * be hardcoded. * The logic here shall be consistent with the one in - * domain_vpl011_init(). + * vpl011_init(). */ if ( flags & CDF_directmap ) { diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 7ef1a95c290752d5a0167806e298aacc834ea640..dbc5bae6217b141b0f89f3e7fd2792ebd9c7a456 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -1067,7 +1067,7 @@ int domain_relinquish_resources(struct domain *d) * Release the resources allocated for vpl011 which were * allocated via a DOMCTL call XEN_DOMCTL_vuart_op. */ - domain_vpl011_deinit(d); + virtdev_uart_exit(d); #ifdef CONFIG_IOREQ_SERVER ioreq_server_destroy_all(d); diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index 9d047065ba13ffe003d2565879cd073e78f76893..53c57b092d28f7a6dd7b8bf280d1d6fd0d27f54b 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -30,10 +31,7 @@ static int handle_vuart_init(struct domain *d, struct xen_domctl_vuart_op *vuart_op) { int rc; - struct vpl011_init_info info; - - info.console_domid = vuart_op->console_domid; - info.gfn = _gfn(vuart_op->gfn); + struct virtdev_uart_params info; if ( d->creation_finished ) return -EPERM; @@ -41,8 +39,11 @@ static int handle_vuart_init(struct domain *d, if ( vuart_op->type != XEN_DOMCTL_VUART_TYPE_VPL011 ) return -EOPNOTSUPP; - rc = domain_vpl011_init(d, &info); + info.console_domid = vuart_op->console_domid; + info.gfn = _gfn(vuart_op->gfn); + info.evtchn = (evtchn_port_t)-1; + rc = virtdev_uart_init(d, &info); if ( !rc ) vuart_op->evtchn = info.evtchn; diff --git a/xen/arch/arm/include/asm/vpl011.h b/xen/arch/arm/include/asm/vpl011.h index cc838682815c0d049ba33d3bf9966a64b2e527dd..89937ce60a41d739e1efa5af5da86e1ee23621c6 100644 --- a/xen/arch/arm/include/asm/vpl011.h +++ b/xen/arch/arm/include/asm/vpl011.h @@ -23,6 +23,7 @@ #include #include #include +#include /* helper macros */ #define VPL011_LOCK(d,flags) spin_lock_irqsave(&(d)->arch.vpl011.lock, flags) @@ -59,26 +60,6 @@ struct vpl011 { evtchn_port_t evtchn; }; -struct vpl011_init_info { - domid_t console_domid; - gfn_t gfn; - evtchn_port_t evtchn; -}; - -#ifdef CONFIG_SBSA_VUART_CONSOLE -int domain_vpl011_init(struct domain *d, - struct vpl011_init_info *info); -void domain_vpl011_deinit(struct domain *d); -int vpl011_rx_char_xen(struct domain *d, char c); -#else -static inline int domain_vpl011_init(struct domain *d, - struct vpl011_init_info *info) -{ - return -ENOSYS; -} - -static inline void domain_vpl011_deinit(struct domain *d) { } -#endif #endif /* _VPL011_H_ */ /* diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 66047bf33cedb930a6bd7c96577913cd1ae08f05..236fd70d0847f375070dfff314bb8dd08d6ad166 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,8 @@ #include #include +static void cf_check vpl011_exit(struct domain *d); + /* * Since pl011 registers are 32-bit registers, all registers * are handled similarly allowing 8-bit, 16-bit and 32-bit @@ -566,9 +569,9 @@ static void vpl011_data_avail(struct domain *d, } /* - * vpl011_rx_char_xen adds a char to a domain's vpl011 receive buffer. + * vpl011_putchar adds a char to a domain's vpl011 receive buffer. */ -int vpl011_rx_char_xen(struct domain *d, char c) +static int cf_check vpl011_putchar(struct domain *d, char c) { unsigned long flags; struct vpl011 *vpl011 = &d->arch.vpl011; @@ -637,7 +640,8 @@ static void vpl011_notification(struct vcpu *v, unsigned int port) VPL011_UNLOCK(d, flags); } -int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info) +static int cf_check vpl011_init(struct domain *d, + struct virtdev_uart_params *params) { int rc; struct vpl011 *vpl011 = &d->arch.vpl011; @@ -689,27 +693,28 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info) } /* - * info is NULL when the backend is in Xen. - * info is != NULL when the backend is in a domain. + * params is NULL when the backend is in Xen. + * params is != NULL when the backend is in a domain. */ - if ( info != NULL ) + if ( params ) { vpl011->backend_in_domain = true; /* Map the guest PFN to Xen address space. */ rc = prepare_ring_for_helper(d, - gfn_x(info->gfn), + gfn_x(params->gfn), &vpl011->backend.dom.ring_page, &vpl011->backend.dom.ring_buf); if ( rc < 0 ) goto out; - rc = alloc_unbound_xen_event_channel(d, 0, info->console_domid, + rc = alloc_unbound_xen_event_channel(d, 0, params->console_domid, vpl011_notification); if ( rc < 0 ) goto out1; - vpl011->evtchn = info->evtchn = rc; + params->evtchn = rc; + vpl011->evtchn = rc; } else { @@ -740,13 +745,13 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info) return 0; out1: - domain_vpl011_deinit(d); + vpl011_exit(d); out: return rc; } -void domain_vpl011_deinit(struct domain *d) +static void cf_check vpl011_exit(struct domain *d) { struct vpl011 *vpl011 = &d->arch.vpl011; @@ -783,6 +788,12 @@ void domain_vpl011_deinit(struct domain *d) XFREE(vpl011->backend.xen); } +static void cf_check vpl011_dump(struct domain *d) +{ +} + +VIRTDEV_UART_REGISTER(vpl011); + /* * Local variables: * mode: C diff --git a/xen/arch/arm/vuart.c b/xen/arch/arm/vuart.c index 23e05dba3a5617863f6c08f085c358f2cf32a292..03366da17a604502f6e0afb45e8824c9d7cfa3dd 100644 --- a/xen/arch/arm/vuart.c +++ b/xen/arch/arm/vuart.c @@ -17,6 +17,9 @@ * /!\ This device is not intended to be enumerable or exposed to the OS * (e.g. via Device Tree). * + * Not hooked into virtdev-uart framework because this emulator is limited + * to hardware domains only and cannot own physical console input. + * * Julien Grall * Ian Campbell * Copyright (c) 2012 Citrix Systems. diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index bbccff1a0350ef7ce7099c4756be12a7232d8de5..dd68dadccd7c873ddc98240c66b5af5896e9f04a 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -69,6 +69,7 @@ SECTIONS __proc_info_end = .; VPCI_ARRAY + VIRTDEV_UART_SECTION } :text #if defined(BUILD_ID) diff --git a/xen/arch/ppc/xen.lds.S b/xen/arch/ppc/xen.lds.S index 3f2a7676ec96f6d773825f2d3ecb90ab2f604e9f..419b8c472de03bd7db76a3ecc5c87080500e1870 100644 --- a/xen/arch/ppc/xen.lds.S +++ b/xen/arch/ppc/xen.lds.S @@ -56,6 +56,7 @@ SECTIONS *(.data.rel.ro.*) VPCI_ARRAY + VIRTDEV_UART_SECTION . = ALIGN(POINTER_ALIGN); } :text diff --git a/xen/arch/riscv/xen.lds.S b/xen/arch/riscv/xen.lds.S index dffc6ae11913fa52d556ee6639bbbd4abb5f44f9..3a2cde3b7de55395f3fba1ead0db91f35b362107 100644 --- a/xen/arch/riscv/xen.lds.S +++ b/xen/arch/riscv/xen.lds.S @@ -51,6 +51,7 @@ SECTIONS *(.data.rel.ro.*) VPCI_ARRAY + VIRTDEV_UART_SECTION . = ALIGN(POINTER_ALIGN); } :text diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index c4f1df248c1a7b2b3e5c45cef154e7ca80018dfc..ce21f5884b554f27991f19d9953731a9e8241e90 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 42217eaf2485ebc221749c1cf12794af8a153616..42e15ab2cf078d0cf5d870c7bc5c5d3e327d9f5f 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -146,6 +146,7 @@ SECTIONS __note_gnu_build_id_end = .; #endif VPCI_ARRAY + VIRTDEV_UART_SECTION } PHDR(text) #if defined(CONFIG_PVH_GUEST) && !defined(EFI) diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 7c331bc17bf279d4dd95ec5bbb540a70657cc1d1..1040eda5a15f24fdf9324072b8524289969bad47 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -22,6 +22,7 @@ #include #include #include +#include #include static unsigned char keypress_key; @@ -350,6 +351,8 @@ static void cf_check dump_domains(unsigned char key) v->periodic_period / 1000000); } } + + virtdev_uart_dump(d); } for_each_domain ( d ) diff --git a/xen/drivers/Kconfig b/xen/drivers/Kconfig index 20050e9bb8b32bd16c2da76c2c3e0f68dab89394..355719c3af67683c153a4f7a35dad4944992846e 100644 --- a/xen/drivers/Kconfig +++ b/xen/drivers/Kconfig @@ -19,4 +19,9 @@ config HAS_VPCI_GUEST_SUPPORT bool select HAS_VPCI +config HAS_VUART + bool "UART emulation framework" + help + This selects UART emulation framework. + endmenu diff --git a/xen/drivers/Makefile b/xen/drivers/Makefile index 2a1ae8ad130a2e62bf391528be669d07c056fece..6593e2118e8e2d65778af96c9f2c066a705b0186 100644 --- a/xen/drivers/Makefile +++ b/xen/drivers/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_HAS_VPCI) += vpci/ obj-$(CONFIG_HAS_PASSTHROUGH) += passthrough/ obj-$(CONFIG_ACPI) += acpi/ obj-$(CONFIG_VIDEO) += video/ +obj-$(CONFIG_HAS_VUART) += virtdev-uart.o diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 2d20a9d7531e069803eaf30ce79354b998c4a52f..0927c0564a67098c70dab576ebeda3825fadfb61 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -34,13 +34,11 @@ #include #include #include +#include #ifdef CONFIG_X86 #include #endif -#ifdef CONFIG_SBSA_VUART_CONSOLE -#include -#endif /* console: comma-separated list of console outputs. */ static char __initdata opt_console[30] = OPT_CONSOLE_STR; @@ -545,6 +543,7 @@ static void __serial_rx(char c) /* * Deliver input to the hardware domain buffer, unless it is * already full. + * NB: must be the first check: hardware domain may have emulated UART. */ if ( (serial_rx_prod - serial_rx_cons) != SERIAL_RX_SIZE ) serial_rx_ring[SERIAL_RX_MASK(serial_rx_prod++)] = c; @@ -555,11 +554,9 @@ static void __serial_rx(char c) */ send_global_virq(VIRQ_CONSOLE); } -#ifdef CONFIG_SBSA_VUART_CONSOLE - else + else if ( domain_has_vuart(d) ) /* Deliver input to the emulated UART. */ - rc = vpl011_rx_char_xen(d, c); -#endif + rc = virtdev_uart_putchar(d, c); if ( consoled_is_enabled() ) /* Deliver input to the PV shim console. */ diff --git a/xen/drivers/virtdev-uart.c b/xen/drivers/virtdev-uart.c new file mode 100644 index 0000000000000000000000000000000000000000..d238ef369c6b94429eaad9f33c79b63ba325b7c6 --- /dev/null +++ b/xen/drivers/virtdev-uart.c @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include +#include + +extern const struct virtdev_uart *__start_virtdev_uart; + +int virtdev_uart_init(struct domain *d, struct virtdev_uart_params *params) +{ + int rc; + + ASSERT(__start_virtdev_uart); + + rc = __start_virtdev_uart->init(d, params); + if ( rc ) + return rc; + +#if !defined(__i386__) && !defined(__x86_64__) + d->arch.emulation_flags |= VIRTDEV_UART; +#endif + + return 0; +} + +void virtdev_uart_exit(struct domain *d) +{ + ASSERT(__start_virtdev_uart); + + __start_virtdev_uart->exit(d); + +#if !defined(__i386__) && !defined(__x86_64__) + d->arch.emulation_flags &= ~VIRTDEV_UART; +#endif +} + +int virtdev_uart_putchar(struct domain *d, char c) +{ + ASSERT(__start_virtdev_uart); + ASSERT(d->arch.emulation_flags & VIRTDEV_UART); + + return __start_virtdev_uart->putchar(d, c); +} + +void virtdev_uart_dump(struct domain *d) +{ + ASSERT(__start_virtdev_uart); + + __start_virtdev_uart->dump(d); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/public/virtdev.h b/xen/include/public/virtdev.h index 27434377ecacfe069a91dea3768d14b0c14e08b4..36931e0d679cedadd4212f34142d7c3f00cd3389 100644 --- a/xen/include/public/virtdev.h +++ b/xen/include/public/virtdev.h @@ -17,6 +17,7 @@ enum { VIRTDEV_PIT = 1U << 8, VIRTDEV_PIRQ = 1U << 9, VIRTDEV_PCI = 1U << 10, + VIRTDEV_UART = 1U << 11, }; #if defined(__i386__) || defined(__x86_64__) diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index eec093e9e167c14a536383422d280ed5ee56f698..4ae5def08eda40db58b6506b60a9393c82ba9aa7 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -54,6 +54,9 @@ void arch_get_domain_info(const struct domain *d, #define is_domain_direct_mapped(d) ((d)->cdf & CDF_directmap) #define is_domain_using_staticmem(d) ((d)->cdf & CDF_staticmem) +#define domain_has_vuart(d) \ + ( IS_ENABLED(CONFIG_HAS_VUART) && \ + (d)->arch.emulation_flags & VIRTDEV_UART ) /* * Arch-specifics. diff --git a/xen/include/xen/virtdev-uart.h b/xen/include/xen/virtdev-uart.h new file mode 100644 index 0000000000000000000000000000000000000000..fbe48e513996404d793d011747b3f40c236a6a57 --- /dev/null +++ b/xen/include/xen/virtdev-uart.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef XEN__VIRTDEV_UART_H +#define XEN__VIRTDEV_UART_H + +#include +#include +#include + +struct virtdev_uart_params { + domid_t console_domid; + gfn_t gfn; + evtchn_port_t evtchn; +}; + +struct virtdev_uart { + int (*putchar)(struct domain *d, char c); + int (*init)(struct domain *d, struct virtdev_uart_params *params); + void (*exit)(struct domain *d); + void (*dump)(struct domain *d); +}; + +#define VIRTDEV_UART_REGISTER(x) \ + static const struct virtdev_uart *x##_entry \ + __used_section(".data.virtdev.uart") = \ + &(const struct virtdev_uart){ \ + .init = x ## _init, \ + .exit = x ## _exit, \ + .dump = x ## _dump, \ + .putchar = x ## _putchar, \ + } + +#ifdef CONFIG_HAS_VUART + +int virtdev_uart_putchar(struct domain *d, char c); +int virtdev_uart_init(struct domain *d, struct virtdev_uart_params *params); +void virtdev_uart_exit(struct domain *d); +void virtdev_uart_dump(struct domain *d); + +#else + +static inline int virtdev_uart_putchar(struct domain *d, char c) +{ + ASSERT_UNREACHABLE(); + return -ENODEV; +} + +static inline int virtdev_uart_init(struct domain *d, + struct virtdev_uart_params *params) +{ + return 0; +} + +static inline void virtdev_uart_exit(struct domain *d) +{ +} + +static inline void virtdev_uart_dump(struct domain *d) +{ +} + +#endif /* CONFIG_HAS_VUART */ + +#endif /* XEN__VIRTDEV_UART_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/xen.lds.h b/xen/include/xen/xen.lds.h index 16a9b1ba03db4861c3a8dbfe38e73335cc90a55e..c19d82a73f4c19a02082c8a6cf920002353b1e09 100644 --- a/xen/include/xen/xen.lds.h +++ b/xen/include/xen/xen.lds.h @@ -193,4 +193,14 @@ #define VPCI_ARRAY #endif +#ifdef CONFIG_HAS_VUART +#define VIRTDEV_UART_SECTION \ + . = ALIGN(POINTER_ALIGN); \ + __start_virtdev_uart = .; \ + *(.data.virtdev.uart) \ + __end_virtdev_uart = .; +#else +#define VIRTDEV_UART_SECTION +#endif + #endif /* __XEN_LDS_H__ */ From patchwork Sat Jan 4 01:58:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926044 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 A530BC02185 for ; Sat, 4 Jan 2025 01:58:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864710.1275991 (Exim 4.92) (envelope-from ) id 1tTtQm-0006JW-PI; Sat, 04 Jan 2025 01:58:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864710.1275991; Sat, 04 Jan 2025 01:58:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQm-0006Hf-7z; Sat, 04 Jan 2025 01:58:24 +0000 Received: by outflank-mailman (input) for mailman id 864710; Sat, 04 Jan 2025 01:58:21 +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 1tTtQj-0005Ax-Q6 for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:21 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5dd06576-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:18 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1F7205C61A0; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 2F862C4CEDF; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 258D1E7719A; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5dd06576-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=WkgpINAi4NmXbCPyfSBPSjKkxNTDWSdwSg5wm9hn06Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=H9zfqAfx2RSRbi2EMUVSUK5A5YOdctvF9wzXgaRtutupZJbIU2q2d8AbEzvPTLyQ3 xBtuOwtfuHSO9BCbRcpqL13I5m3lIuSKDBhhcvRQ61SFzRTB3A5Z4lGOsmLXX2PyrK A5mHdUnmnJVhFcx9Nw7Zh+ApfuGjWuwrdafH0q3tGQsrtLyCXZKJ+clySk3PJOdmDq jyyCEvxnykvwyU4Ja+BNljO44nCTjVLnUyuduJK2oQLVUyVFZ9Gvbp85ObWGdR3k5t X9XfdkHs1SuM2shblGWjSiiX6XsDLSjifDP6GUwcasEMmBJaNpFdh7ZsH/Kf4mCBeu wDa82EC6J8jlQ== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:14 -0800 Subject: [PATCH v3 08/24] xen/console: rename switch_serial_input() to console_switch_input() MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-8-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=1473; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=VlrDmVYSUYYEG2sJ1u5nbMuy01Nt/S2plh2q6DJ+BIw=; b=S1s8vEh//WnTsVDQMRNzdQ8IrNEV/vZqF5vI012/k7AeJFUsj7kHlwgXqm6tbP8iH+pQoIZMm eh6s4rBUInzDHPPpwvMdJSQgTovGbPH5QGbGKna4mP/7Vse5daRUn15 X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Updated the name to highlight the physical console input selection logic: existing code does not switch only serial console, it also switches debugging console (debug I/O port and console hypercall). 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 0927c0564a67098c70dab576ebeda3825fadfb61..48866cf47beda39e48a7774277238273566382b1 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -486,7 +486,7 @@ void console_put_domain(struct domain *d) rcu_unlock_domain(d); } -static void switch_serial_input(void) +static void console_switch_input(void) { unsigned int next_rx = console_rx; @@ -577,7 +577,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_input(); switch_code_count = 0; } return; @@ -1117,7 +1117,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_input(); } int __init console_has(const char *device) From patchwork Sat Jan 4 01:58:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926033 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 8E3E0E77199 for ; Sat, 4 Jan 2025 01:58:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864706.1275960 (Exim 4.92) (envelope-from ) id 1tTtQk-0005nW-Ia; Sat, 04 Jan 2025 01:58:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864706.1275960; Sat, 04 Jan 2025 01:58:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQk-0005mw-DF; Sat, 04 Jan 2025 01:58:22 +0000 Received: by outflank-mailman (input) for mailman id 864706; Sat, 04 Jan 2025 01:58:20 +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 1tTtQi-0005Ay-CN for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:20 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5cc997fe-ca3f-11ef-99a4-01e77a169b0f; Sat, 04 Jan 2025 02:58:16 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 5D055A411CA; Sat, 4 Jan 2025 01:56:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 3D46CC4CEE3; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34815E77199; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5cc997fe-ca3f-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=xXcYmPnyoaBYwuvwmwzq65u8a7zL6rzG/+EY8Xv8xGE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=AcM7Vtoksl9NuXsBkmaV+MfZOCMRt2zDfmJPK3Gs9ieXp0syisbEcIaH8QlLJrQLB SK0JUVGW11+9hKqDLS/5CnS9gX1lCP7TNMpbehJo5pxrkbCx1f2XwD+X12QgNzweK+ Kb0Bv6pRUw5UCFQesSfHU1uyrbXWwfuLw5clv5jqeXIy2xJOBtvkCKQXYBnIWMBFUH v+dwRYvU2VEzOAf76MQFuSxW3ENllWV659LJ2nnv23vaVsVyct31+F9WFpxkQYkwjB N0uaqRTn0UuVjJlMTbLz3BClt0PGRnuixH/tRLyRcau00SCMZHzxykwgSEub+mg/9o nqii0jYMZ8Hog== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:15 -0800 Subject: [PATCH v3 09/24] xen/console: rename console_rx to console_owner MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-9-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=2836; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=hlHBU29TJ6azKlgJxKuwT5okumjd5Gkw0PPbKZ55oxg=; b=8gj6SDYe8BztlUQL/hKRBIYVD38Gp7CgTWQrnGT86srkbF/wCLOJPeSHzvZRRElqsEEVQAoxG SSRoin1gwJzBzBL2tPOlDVb3Ajj9sx2b2fV9mk90Edf+KMiLPBHdtvO X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Update the symbol name to prepare for the follow on semantic change of console owner identifier. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 48866cf47beda39e48a7774277238273566382b1..33da5ff7933ea2186245763e07940c17d74bf40f 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -465,19 +465,19 @@ static void cf_check dump_console_ring_key(unsigned char key) */ #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) + * console_owner=0 => input to xen + * console_owner=1 => input to dom0 (or the sole shim domain) + * console_owner=N => input to dom(N-1) */ -static unsigned int __read_mostly console_rx = 0; +static unsigned int __read_mostly console_owner = 0; #define max_console_rx (max_init_domid + 1) struct domain *console_get_domain(void) { - if ( console_rx == 0 ) + if ( console_owner == 0 ) return NULL; - return rcu_lock_domain_by_id(console_rx - 1); + return rcu_lock_domain_by_id(console_owner - 1); } void console_put_domain(struct domain *d) @@ -488,7 +488,7 @@ void console_put_domain(struct domain *d) static void console_switch_input(void) { - unsigned int next_rx = console_rx; + unsigned int next_rx = console_owner; /* * Rotate among Xen, dom0 and boot-time created domUs while skipping @@ -501,7 +501,7 @@ static void console_switch_input(void) if ( next_rx++ >= max_console_rx ) { - console_rx = 0; + console_owner = 0; printk("*** Serial input to Xen"); break; } @@ -514,7 +514,7 @@ static void console_switch_input(void) if ( d ) { rcu_unlock_domain(d); - console_rx = next_rx; + console_owner = next_rx; printk("*** Serial input to DOM%u", domid); break; } @@ -531,7 +531,7 @@ static void __serial_rx(char c) struct domain *d; int rc = 0; - if ( console_rx == 0 ) + if ( console_owner == 0 ) return handle_keypress(c, false); d = console_get_domain(); @@ -1105,7 +1105,7 @@ void __init console_endboot(void) * a useful 'how to switch' message. */ if ( opt_conswitch[1] == 'x' ) - console_rx = max_console_rx; + console_owner = max_console_rx; register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", 0); From patchwork Sat Jan 4 01:58:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926045 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 69663E77198 for ; Sat, 4 Jan 2025 01:58:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864716.1276044 (Exim 4.92) (envelope-from ) id 1tTtQs-0007kJ-Vw; Sat, 04 Jan 2025 01:58:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864716.1276044; Sat, 04 Jan 2025 01:58:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQr-0007gA-Sx; Sat, 04 Jan 2025 01:58:29 +0000 Received: by outflank-mailman (input) for mailman id 864716; Sat, 04 Jan 2025 01:58:25 +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 1tTtQm-0005Ax-R2 for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:24 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5e0b0c0b-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 362555C61E7; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 4A394C4CEE5; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43699E77188; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5e0b0c0b-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=AcdrW3O8H43kz0elqqoeILzh7ZG+wA08lKxXLcP1yPI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qFWPcMge1P3Kadc0hgvWN/ZI1ulugOzHad0WyuquIw4VVVdq6ItD5M50Lc6lfgaKG 1EBNGneBMz9XFuzlvtmTOoG0WI9b4vVyJSJ01ZFp3Ph2LmE/OalHSlwLMyL8BCZsg2 IS+ixF1AKwNQpjIcCX2hDbV/gM9Gp6/YiTmN0iaZooPj/3QcJIOIW1tfK3FKO6JV9Y scEqgbuw0rjTQgx6Koe0PnecrMxIJymYkHwESt+hUmEcj1j3EU2zfUxT9tfNy/Hu6n ugZYH8hL6KTz3KN2vv6T9G44xee1roMqN0UrG/N0bAUdoSZS6+Vf2eYBw18xAfRw4o 2xFJ8T+FMuZBw== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:16 -0800 Subject: [PATCH v3 10/24] xen/console: introduce use of 'is_console' flag MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-10-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=6019; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=HwgHil59vq9EKv+z5DPAShRIPOKHguO2oiS7uAA2fgM=; b=THBoqR6cFXYEpRta1DnD8ynIu+e0N3IIpv1WCUSL8mxTJf0v4ahgyFVw22S7EsevQiO/aNfdQ gTOEUQZPWe1AgSSXG5v76XgncIw7A76rvEW6HZzdSMPo6zNHBbixHgu X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin The code inspects d->is_console flag to decide whether the console focus should move to the domain with console after administrator uses key combination to switch the console focus. Console owner switch logic updated accordingly. Signed-off-by: Denis Mukhin --- xen/arch/arm/dom0less-build.c | 1 - xen/arch/x86/pv/shim.c | 2 ++ xen/common/domain.c | 2 ++ xen/drivers/char/console.c | 53 +++++++++++++++++++++++++++++++++++-------- xen/drivers/virtdev-uart.c | 2 ++ 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 78fba18b6aa80278207f920145c5aab4fecc6d18..818e693222059a5e99a44831be62644ac442392b 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -985,7 +985,6 @@ void __init create_domUs(void) panic("Error initializing LLC coloring for domain %s (rc = %d)\n", dt_node_name(node), rc); - d->is_console = true; dt_device_set_used_by(node, d->domain_id); rc = construct_domU(d, node); diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 81e4a0516d18b359561f471f1d96e38977661ca7..9eb120258aeaf7068eae88d1e7d1b95ea7a00f31 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->is_console = true; } static void write_start_info(struct domain *d) diff --git a/xen/common/domain.c b/xen/common/domain.c index 0c4cc771115509afe3bb457b8002961a73f5a8e7..711ec3bf3b7845a6c295575421c252193ccbc0ae 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -706,6 +706,8 @@ struct domain *domain_create(domid_t domid, old_hwdom = hardware_domain; hardware_domain = d; + + d->is_console = 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 33da5ff7933ea2186245763e07940c17d74bf40f..8d68116991ba9e2c5a36840b4d973f8cafe95488 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 @@ -473,11 +473,26 @@ static unsigned int __read_mostly console_owner = 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->is_console ) + return d; + + rcu_unlock_domain(d); + + return NULL; +} + struct domain *console_get_domain(void) { if ( console_owner == 0 ) return NULL; - return rcu_lock_domain_by_id(console_owner - 1); + return console_get_domain_by_id(console_owner - 1); } void console_put_domain(struct domain *d) @@ -486,6 +501,15 @@ void console_put_domain(struct domain *d) rcu_unlock_domain(d); } +static bool console_owner_possible(domid_t domid) +{ + struct domain *d = console_get_domain_by_id(domid); + + console_put_domain(d); + + return !!d; +} + static void console_switch_input(void) { unsigned int next_rx = console_owner; @@ -497,7 +521,6 @@ static void console_switch_input(void) for ( ; ; ) { domid_t domid; - struct domain *d; if ( next_rx++ >= max_console_rx ) { @@ -510,10 +533,9 @@ static void console_switch_input(void) domid = get_initial_domain_id(); else domid = next_rx - 1; - d = rcu_lock_domain_by_id(domid); - if ( d ) + + if ( console_owner_possible(domid) ) { - rcu_unlock_domain(d); console_owner = next_rx; printk("*** Serial input to DOM%u", domid); break; @@ -562,8 +584,19 @@ static void __serial_rx(char c) /* Deliver input to the PV shim console. */ rc = consoled_guest_tx(c); - if ( rc ) - printk(KERN_ERR "d%pd: failed to process console input: %d\n", d, rc); + switch ( rc ) + { + case 0: + break; + case -EBUSY: /* Loopback mode */ + case -ENOSPC: /* FIFO is full */ + printk(KERN_WARNING "d%pd: failed to process console input: %d\n", d, rc); + break; + default: + d->is_console = false; + printk(KERN_ERR "d%pd: disabled console forwarding: %d\n", d, rc); + break; + } console_put_domain(d); } @@ -807,7 +840,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) { diff --git a/xen/drivers/virtdev-uart.c b/xen/drivers/virtdev-uart.c index d238ef369c6b94429eaad9f33c79b63ba325b7c6..fe119e3e6e938957613b182cbef0a29bf67230d2 100644 --- a/xen/drivers/virtdev-uart.c +++ b/xen/drivers/virtdev-uart.c @@ -20,6 +20,7 @@ int virtdev_uart_init(struct domain *d, struct virtdev_uart_params *params) #if !defined(__i386__) && !defined(__x86_64__) d->arch.emulation_flags |= VIRTDEV_UART; #endif + d->is_console = true; return 0; } @@ -33,6 +34,7 @@ void virtdev_uart_exit(struct domain *d) #if !defined(__i386__) && !defined(__x86_64__) d->arch.emulation_flags &= ~VIRTDEV_UART; #endif + d->is_console = false; } int virtdev_uart_putchar(struct domain *d, char c) From patchwork Sat Jan 4 01:58:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926054 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 D697EE77199 for ; Sat, 4 Jan 2025 02:00:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864845.1276149 (Exim 4.92) (envelope-from ) id 1tTtTA-0001ts-Er; Sat, 04 Jan 2025 02:00:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864845.1276149; Sat, 04 Jan 2025 02:00: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 1tTtTA-0001sW-9q; Sat, 04 Jan 2025 02:00:52 +0000 Received: by outflank-mailman (input) for mailman id 864845; Sat, 04 Jan 2025 02:00:51 +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 1tTtQr-0005Ax-SB for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:29 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5e0b4e27-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 477C45C61FB; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 5750FC4CEE7; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 525B5E7719A; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5e0b4e27-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=0RiCLC0xOzoXE8zM6GuJsL0mR/n/aR+zKy5BKY4AmRI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Cc+SrVU8OiRGBxa/MQxYepNdpwn1YwuBa8DTaKdhhiesGN00s8ObKq73IJpqjMV+q NqC+aGc0snCvnnlXnutTjAjzUEKx/xSEkpqDlKS3PdI5Sn40BUE4DRTorkB5BJMpv/ KzQuWptl2wNWjsOz2vIfRESQUKIt1sf3nXyqyztc8RVwZ0w1tnsa5M4OgY2U1wRiRw wDbCwZPFnD1xla36YaMWcRekbujrSHyQKy6pK8lk//fdBuyki2ScSBciBDH8/uhoXb FzOt7PwJLnG/7uoF1Ssb880YEFHIrYiStrgPDMaeainhDywtTs8EO00YlX1o6akHIh 6sjiHFj4lOdJg== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:17 -0800 Subject: [PATCH v3 11/24] xen/domain: move get_initial_domain_id() to arch-independent header MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-11-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=10763; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=KSx1P0KAHxW1DtHrVs4w4BNN0t0xYk4+xwM0DZycLC0=; b=XY8kJ57Z4bAPPueW7p5ElCjXAaQkou+MZAejExcnaHDRFAST3sVyhGy8HHUaFQ/I3HOrYvOr9 kG+gPZ8+uGPBzexLC9uHJVRrvnzrJyKzRcZMyLj3faeCcwACnOdKPfS X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Honor 'hardware_domid=' parameter across all architectures and update max_init_domid correctly so that toolstack and, subsequently, console driver could iterate across known domains more efficiently. Also, move max_init_domid to arch-independent location. Signed-off-by: Denis Mukhin --- xen/arch/arm/dom0less-build.c | 6 +++--- xen/arch/arm/domain_build.c | 7 ++++--- 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/pv/shim.h | 5 +++-- xen/arch/x86/include/asm/setup.h | 2 -- xen/arch/x86/pv/shim.c | 5 +---- xen/common/domain.c | 15 +++++++++++++++ xen/common/domctl.c | 11 +++++------ xen/common/kernel.c | 8 ++++++++ xen/include/xen/domain.h | 4 ++++ 13 files changed, 43 insertions(+), 28 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 818e693222059a5e99a44831be62644ac442392b..b0c6c0b5c7762439dc74025333be092687c191e5 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -971,9 +971,9 @@ void __init create_domUs(void) 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) + * NB: it's very important to use the pre-increment operator to call + * domain_create() with a domid > get_initial_domain_id(). + * domid == get_initial_domain_id() is reserved for Dom0. */ d = domain_create(++max_init_domid, &d_cfg, flags); if ( IS_ERR(d) ) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index b072a16249feaab3eabe214040e4331e208ffae4..5fe2f397c8b1f7088b08c3435bc75a1acb8742b3 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2357,6 +2357,7 @@ void __init create_dom0(void) .grant_opts = XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), }; unsigned int flags = CDF_privileged; + domid_t domid = get_initial_domain_id(); int rc; /* The vGIC for DOM0 is exactly emulating the hardware GIC */ @@ -2387,15 +2388,15 @@ 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, CDF_privileged | CDF_directmap); 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); 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 ) diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 6cf272c160ef2443cb50bfa4ae2d2591c52e043d..f107e8eebb4904a4455167e8792a66994a093d86 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 c1f2d1b89d4317224bb1011e0db3a7372df807e2..47d80fcd43289ebbd751007f02eab2def60bebad 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 e4f64879b68ca5aac24bd9544255143e6ef693f3..956fa6985adb23375bd41d3e5d34d9d5f0712bd5 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 c9d69cdf51666c0ec31196411b52e9b39439ba5f..d1fc64b673ab618d9ad7a78c0a8b32b70a2daae6 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/pv/shim.h b/xen/arch/x86/include/asm/pv/shim.h index 6153e27005986881ad87e9db0b555b30edc59fc0..27053d4f6fb93a619edba2d34d92ea5e5cd27303 100644 --- a/xen/arch/x86/include/asm/pv/shim.h +++ b/xen/arch/x86/include/asm/pv/shim.h @@ -31,7 +31,7 @@ long cf_check pv_shim_cpu_up(void *data); long cf_check pv_shim_cpu_down(void *data); void pv_shim_online_memory(unsigned int nr, unsigned int order); void pv_shim_offline_memory(unsigned int nr, unsigned int order); -domid_t get_initial_domain_id(void); +domid_t pv_shim_get_initial_domain_id(void); uint64_t pv_shim_mem(uint64_t avail); void pv_shim_fixup_e820(void); const struct platform_bad_page *pv_shim_reserved_pages(unsigned int *size); @@ -76,8 +76,9 @@ static inline void pv_shim_offline_memory(unsigned int nr, unsigned int order) { ASSERT_UNREACHABLE(); } -static inline domid_t get_initial_domain_id(void) +static inline domid_t pv_shim_get_initial_domain_id(void) { + ASSERT_UNREACHABLE(); return 0; } static inline uint64_t pv_shim_mem(uint64_t avail) diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/setup.h index 5c2391a8684b66efdf4b092409ed33935db6b40c..296348655b9d146c73acc305cc9edd5fd46f7d47 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/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 9eb120258aeaf7068eae88d1e7d1b95ea7a00f31..8435f347ce31aed49309e942f9692a2307bcd93f 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -1018,13 +1018,10 @@ void pv_shim_offline_memory(unsigned int nr, unsigned int order) } } -domid_t get_initial_domain_id(void) +domid_t pv_shim_get_initial_domain_id(void) { uint32_t eax, ebx, ecx, edx; - if ( !pv_shim ) - return 0; - cpuid(xen_cpuid_base + 4, &eax, &ebx, &ecx, &edx); return (eax & XEN_HVM_CPUID_DOMID_PRESENT) ? ecx : 1; diff --git a/xen/common/domain.c b/xen/common/domain.c index 711ec3bf3b7845a6c295575421c252193ccbc0ae..61e0890052eb0c7ff7c19cc2fbdbfb9af512a545 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -43,6 +43,9 @@ #include #include #include +#ifdef CONFIG_PV_SHIM +#include +#endif #ifdef CONFIG_X86 #include @@ -65,6 +68,9 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock); static struct domain *domain_hash[DOMAIN_HASH_SIZE]; struct domain *domain_list; +/* Last known non-system domain ID. */ +domid_t __read_mostly max_init_domid; + /* * 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. @@ -2261,6 +2267,15 @@ int continue_hypercall_on_cpu( return 0; } +domid_t get_initial_domain_id(void) +{ +#ifdef CONFIG_PV_SHIM + if ( pv_shim ) + return pv_shim_get_initial_domain_id(); +#endif + return hardware_domid; +} + /* * Local variables: * mode: C diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 05abb581a03d9c4deaea432a8d5e65d6906f70b4..498bffe56e1fac217c868a0ed79a14db98cb025d 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -415,10 +415,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) case XEN_DOMCTL_createdomain: { domid_t dom; - static domid_t rover = 0; dom = op->domain; - if ( (dom > 0) && (dom < DOMID_FIRST_RESERVED) ) + if ( (dom > max_init_domid) && (dom < DOMID_FIRST_RESERVED) ) { ret = -EEXIST; if ( !is_free_domid(dom) ) @@ -426,19 +425,19 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) } else { - for ( dom = rover + 1; dom != rover; dom++ ) + for ( dom = max_init_domid + 1; dom != max_init_domid; dom++ ) { if ( dom == DOMID_FIRST_RESERVED ) - dom = 1; + dom = max_init_domid + 1; if ( is_free_domid(dom) ) break; } ret = -ENOMEM; - if ( dom == rover ) + if ( dom == max_init_domid ) break; - rover = dom; + max_init_domid = dom; } d = domain_create(dom, &op->u.createdomain, false); diff --git a/xen/common/kernel.c b/xen/common/kernel.c index 8b63ca55f14fb81b6b803a8f28d487dd954ef862..1a079c9bddcb705dad256b0be1673122d77f4dd7 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) +{ + max_init_domid = 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 4ae5def08eda40db58b6506b60a9393c82ba9aa7..eef36bafd3574c97d2f1f5c1fc93b4b7b46b78ba 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -175,4 +175,8 @@ extern bool vmtrace_available; extern bool vpmu_is_available; +extern domid_t max_init_domid; + +domid_t get_initial_domain_id(void); + #endif /* __XEN_DOMAIN_H__ */ From patchwork Sat Jan 4 01:58:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926043 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 0D358C02186 for ; Sat, 4 Jan 2025 01:58:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864715.1276030 (Exim 4.92) (envelope-from ) id 1tTtQr-0007WK-Dj; Sat, 04 Jan 2025 01:58:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864715.1276030; Sat, 04 Jan 2025 01:58:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQq-0007Sv-Qx; Sat, 04 Jan 2025 01:58:28 +0000 Received: by outflank-mailman (input) for mailman id 864715; Sat, 04 Jan 2025 01:58: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 1tTtQm-0005Ay-H0 for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:24 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5e464a18-ca3f-11ef-99a4-01e77a169b0f; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 558515C621C; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 685DEC4CED6; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60503E77198; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5e464a18-ca3f-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=Rhvc2dHX6LX7A5kB7XT3TmoF43oLjWAyucIlq8aPWO8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=h2vKd6wjlvtWJTSnq7BBIP2DCCk2KFcQqFErMa/vesz4YGrktaXvv4236nShvJaQ2 BL3Xn8zDsLKDdPMn81wGwk0mAcNA+csvfKZjlUD9xiRCw8jXFroWRFLbYVe5hlaxwi GUG7bgXf95/92/3fc7uM954c9QFwi8C20Cfjum4IO6orVb4Fk1z1E7pT/ruYVD+0C6 NqpZhwbSWDvQdz7BE1Icob/7S6yprAHHpZlTE+fjgj5PNWDDt+aGxgOP4rkZ7n/RRZ sQqMBU6anmn0KoYbbePqLNitnerGWE76Wi1lHt9yxxbhD/aNiCm9onCkV7VmBUYZwi 40En2jjmuwEOg== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:18 -0800 Subject: [PATCH v3 12/24] xen/console: introduce console_{get,set}_owner() MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-12-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=7114; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=dr4GoJ7mVh1JpOj1gtOyvwWAVMZqjbpSzztsCiE4+kM=; b=NnZnovgXXftfgxnQ8N3SMkVR+YZGMDuiEyNDqeNhX+V6VEW4Rut+uGiOeM4I+9pLYD39Hew8k qhwTi5Hgm+ID3jXYVkTApbFFLLhx6yrBx7PQS8JOF7VMJcO1ml6LApw X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Switch console_owner address spaces from integers mapped to domain IDs to straight domain IDs, which simplifies console focus handling code. console_set_owner() is introduced for setting the new console owner. This is a public API to Xen console driver (it will be used in the follow on code change). console_get_owner() is another public API used for retrieving current console owner domain ID. After the change, console_{get,put}_domain() do not need to be public console APIs. Signed-off-by: Denis Mukhin --- xen/arch/arm/vpl011.c | 5 +-- xen/drivers/char/console.c | 101 +++++++++++++++++++++------------------------ xen/include/xen/console.h | 4 +- 3 files changed, 51 insertions(+), 59 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index 236fd70d0847f375070dfff314bb8dd08d6ad166..efe77c13007716d0e0d70ab5ccf5f94268d5b693 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -81,12 +81,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_owner() ) { if ( intf->out_prod == 1 ) { @@ -126,8 +125,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 8d68116991ba9e2c5a36840b4d973f8cafe95488..f5ff3ebd830d631fa5d8fb5db1cf68adafcd02b4 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -461,17 +461,15 @@ 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=0 => input to xen - * console_owner=1 => input to dom0 (or the sole shim domain) - * console_owner=N => input to dom(N-1) - */ -static unsigned int __read_mostly console_owner = 0; -#define max_console_rx (max_init_domid + 1) +/* + * Current console owner domain ID: either Xen or domain w/ d->is_console == + * true. + */ +static domid_t __read_mostly console_owner = DOMID_XEN; static struct domain *console_get_domain_by_id(domid_t domid) { @@ -488,14 +486,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) { - if ( console_owner == 0 ) - return NULL; - return console_get_domain_by_id(console_owner - 1); + return console_get_domain_by_id(console_owner); } -void console_put_domain(struct domain *d) +static void console_put_domain(struct domain *d) { if ( d ) rcu_unlock_domain(d); @@ -510,42 +506,49 @@ static bool console_owner_possible(domid_t domid) return !!d; } -static void console_switch_input(void) +int console_set_owner(domid_t domid) { - unsigned int next_rx = console_owner; + if ( domid == DOMID_XEN ) + printk("*** Serial input to Xen"); + else if ( console_owner_possible(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_owner = 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_owner_possible(domid) ) - { - console_owner = next_rx; - printk("*** Serial input to DOM%u", domid); - break; - } - } + console_owner = domid; if ( switch_code ) printk(" (type 'CTRL-%c' three times to switch input)", opt_conswitch[0]); printk("\n"); + + return 0; +} + +domid_t console_get_owner(void) +{ + return console_owner; +} + +/* + * Switch console input 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_input(void) +{ + domid_t i, n = max_init_domid + 1; + + if ( console_owner == DOMID_XEN ) + i = get_initial_domain_id(); + else + i = console_owner + 1; + + for ( ; i < n; i++ ) + if ( !console_set_owner(i) ) + break; + if ( i == n ) + console_set_owner(DOMID_XEN); } static void __serial_rx(char c) @@ -553,7 +556,7 @@ static void __serial_rx(char c) struct domain *d; int rc = 0; - if ( console_owner == 0 ) + if ( console_owner == DOMID_XEN ) return handle_keypress(c, false); d = console_get_domain(); @@ -1132,14 +1135,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_owner = max_console_rx; - register_keyhandler('w', dump_console_ring_key, "synchronously dump console ring buffer (dmesg)", 0); register_irq_keyhandler('+', &do_inc_thresh, @@ -1149,8 +1144,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_input(); + if ( opt_conswitch[1] != 'x' ) + console_set_owner( get_initial_domain_id() ); } int __init console_has(const char *device) diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 8631fd279bfe1aba42b61d76fbdb45016c2859f9..c03028ad690fa6359105a174ecc77a30f2731948 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -31,8 +31,8 @@ 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); +int console_set_owner(domid_t domid); +domid_t console_get_owner(void); /* * Steal output from the console. Returns +ve identifier, else -ve error. From patchwork Sat Jan 4 01:58:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926042 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 8EA48C02184 for ; Sat, 4 Jan 2025 01:58:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864718.1276052 (Exim 4.92) (envelope-from ) id 1tTtQu-0007yX-2O; Sat, 04 Jan 2025 01:58:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864718.1276052; Sat, 04 Jan 2025 01:58:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQt-0007vR-1e; Sat, 04 Jan 2025 01:58:31 +0000 Received: by outflank-mailman (input) for mailman id 864718; Sat, 04 Jan 2025 01:58:26 +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 1tTtQn-0005Ax-RK for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:25 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5e419805-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 623155C625F; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 7516CC4CEE9; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DB20E77188; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5e419805-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=mGCIEroumybSgb30DA3BBd6J1k+0FYicVpy3E9PFeTI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ctBvz2h2HiFmbfQEBBl/oM8bOYWI3JupZjsJ8yg3yzx4HrpURZoMLCGmL0HErBCEj l/d8+CrJq4eoYsqUdldJQzyD5QfTht0Fu1VaTOVzoio0+LvKNh5ykkK+sANJ1m2lgO akmQejRoJASXz5PxdQbDgGKBnLxXTtMTHQqCiy45Avo/5lBnEK0pDmA3Hl66bZi4v/ gCA4tkbcFEISStiJi+VETTv9b8yD1DNIjEeG7C5c3DEl5XJ0pfB9AbpeF+OdCrVCCG SZld4vH5YGZWA8dSZnR0O8M2eHJGaeBuUYDnYSx+Pgn2QX4jY0ixsXlrzoBTsNsoy2 ygICIRleHsEhQ== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:19 -0800 Subject: [PATCH v3 13/24] xen/console: introduce hwdom_crashconsole= MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-13-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=4542; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=o12/OmA+RZtrOIYv5yea9Nc3i1rLnoZ0MtCOdADxSJE=; b=laDqlcBt7fXWKuNapo74tNzV0R3dtuySyU/fhDACTJj1HAdDb8hOd7TOnz2417TA0/aAgePzE m0fCgZPTNWVByduJodUh8Sxjnn3YP8OAQ5WwPrZV3Nq4hI/A+AC6YeP X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin The new command line switch `hwdom_crashconsole=BOOL` allows to switch serial console input focus to xen for machine state inspection using keyhandler mechanism after the hardware domain crashes. The new command line switch is aliased via `dom0=...,crashconsole` knob. Such functionality can be useful while debugging dom0 bringup. Signed-off-by: Denis Mukhin --- docs/misc/xen-command-line.pandoc | 14 ++++++++++++++ xen/arch/x86/dom0_build.c | 2 ++ xen/common/domain.c | 14 +++++++++++++- xen/include/xen/domain.h | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 08b0053f9ced7a5c44318a3414f927c31fe4c876..1a5ee3c91c5cc8bf653e5054211035b5d1bd560f 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -822,6 +822,7 @@ Specify the bit width of the DMA heap. ### dom0 = List of [ pv | pvh, shadow=, verbose=, + crashconsole=, cpuid-faulting=, msr-relaxed= ] (x86) = List of [ sve= ] (Arm64) @@ -855,6 +856,10 @@ Controls for how dom0 is constructed on x86 systems. information during the dom0 build. It defaults to the compile time choice of `CONFIG_VERBOSE_DEBUG`. +* The `crashconsole` boolean instructs Xen to switch input console focus to + the hypervisor when dom0 shuts down and avoid performing dom0 domain + destruction. Should only be used for debugging purposes. + * The `cpuid-faulting` boolean is an interim option, is only applicable to PV dom0, and defaults to true. @@ -1491,6 +1496,15 @@ Specify whether guests are to be given access to physical port 80 (often used for debugging purposes), to override the DMI based detection of systems known to misbehave upon accesses to that port. +### hwdom_crashconsole +> `= ` + +> Default: `false` + +The `hwdom_crashconsole` boolean instructs Xen to switch input console focus to +the hypervisor when dom0 shuts down and avoid performing dom0 domain +destruction. Should only be used for debugging purposes. + ### idle_latency_factor (x86) > `= ` diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index e8f5bf5447bc47a6daa3d95787106a4c11e80d31..706aeec0ecbb565a415edbfb33ca2fd72967c560 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -286,6 +286,8 @@ int __init parse_arch_dom0_param(const char *s, const char *e) opt_dom0_cpuid_faulting = val; else if ( (val = parse_boolean("msr-relaxed", s, e)) >= 0 ) opt_dom0_msr_relaxed = val; + else if ( (val = parse_boolean("crashconsole", s, e)) >= 0 ) + opt_hwdom_crashconsole = !!val; else return -EINVAL; diff --git a/xen/common/domain.c b/xen/common/domain.c index 61e0890052eb0c7ff7c19cc2fbdbfb9af512a545..1063463789224818017f7c893312e819acc0714c 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -59,6 +59,13 @@ unsigned int xen_processor_pmbits = XEN_PROCESSOR_PM_PX; bool opt_dom0_vcpus_pin; boolean_param("dom0_vcpus_pin", opt_dom0_vcpus_pin); +/* + * Hardware domain crash handler: if true, do not halt machine, but switch to + * Xen console for debugging. + */ +bool __ro_after_init opt_hwdom_crashconsole; +boolean_param("hwdom_crashconsole", opt_hwdom_crashconsole); + /* Protect updates/reads (resp.) of domain_list and domain_hash. */ DEFINE_SPINLOCK(domlist_update_lock); DEFINE_RCU_READ_LOCK(domlist_read_lock); @@ -1162,7 +1169,12 @@ int domain_shutdown(struct domain *d, u8 reason) reason = d->shutdown_code; if ( is_hardware_domain(d) ) - hwdom_shutdown(reason); + { + if ( opt_hwdom_crashconsole ) + console_set_owner(DOMID_XEN); + else + hwdom_shutdown(reason); + } if ( d->is_shutting_down ) { diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index eef36bafd3574c97d2f1f5c1fc93b4b7b46b78ba..1edebdce3754861244f23f6b884dd07d63958881 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -154,6 +154,7 @@ extern unsigned int xen_processor_pmbits; extern bool opt_dom0_vcpus_pin; extern cpumask_t dom0_cpus; extern bool dom0_affinity_relaxed; +extern bool opt_hwdom_crashconsole; /* vnuma topology per domain. */ struct vnuma_info { From patchwork Sat Jan 4 01:58:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926038 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 2BA15E7719A for ; Sat, 4 Jan 2025 01:58:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864703.1275931 (Exim 4.92) (envelope-from ) id 1tTtQi-0005De-F7; Sat, 04 Jan 2025 01:58:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864703.1275931; Sat, 04 Jan 2025 01:58:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQi-0005Ci-B6; Sat, 04 Jan 2025 01:58:20 +0000 Received: by outflank-mailman (input) for mailman id 864703; Sat, 04 Jan 2025 01:58:19 +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 1tTtQh-0005Ax-Cc for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:19 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5ceb498d-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:16 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 922D5A411CC; Sat, 4 Jan 2025 01:56:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 7FC86C4CEE1; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78E9EE77199; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5ceb498d-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=l5CaQI1poeUeBhWKU19UCrMQ4g4rX0YNIDC4pnEb90I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=E9oQQTd5LujcPgVUdEcB2UZB99M9Snlv5YHhTBLda8b+uM9O3bCrGkpcfWKPiOKPV HdT+JfFaJCdGXFElA2IxlT5teosXI3PU33DFQE0GPMd3s0ZmWrQSybRJoomY2tHOXl JlNw4fAz52BbVAE1wt1RYF90QePRggzFjahrOPay5YglUG2Awkdr7exH90vsysxzT7 +iXc2Jq/bEK5M43IHQnKVTH9ibaxUrcv8kXbZ36WF+FYGEnFjpOlVlH3dVWv6w3ROv Euq2c3x5bJUj6UbDPkhwOCUy/CAgWJRc4uRiITJoajQu9CDtQeJpsJbg+dPNfRsJP7 x3gMUyg7U1EHQ== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:20 -0800 Subject: [PATCH v3 14/24] xen/console: simplify console owner switch hint MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-14-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=896; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=WzdT/Oy8WMU/I7irURWT2SUpInPaVWdH8Z0/y7n+8AQ=; b=0j4lA25445KHzzpLVNgHBUI7bv00MN0Fqcvm5irJlwmNd4cGdfAKratJveXfG1O5lhSWXgwHE Y4tyt3EKNmYC05cRxLpm0AvVDCaAFO7SHVx7/Fypjcnz0cJJZjLKzPO X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Update the hint with the combination of keys to press for the physical console focus switch between the domains. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index f5ff3ebd830d631fa5d8fb5db1cf68adafcd02b4..1308236403df8a0f87aeb7e2c00a036c2d8433a7 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -518,8 +518,8 @@ int console_set_owner(domid_t domid) console_owner = domid; if ( switch_code ) - printk(" (type 'CTRL-%c' three times to switch input)", - opt_conswitch[0]); + printk(" (type 'CTRL-%c%c%c' to switch input)", + opt_conswitch[0], opt_conswitch[0], opt_conswitch[0]); printk("\n"); return 0; From patchwork Sat Jan 4 01:58:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926053 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 B019DE77188 for ; Sat, 4 Jan 2025 02:00:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864838.1276139 (Exim 4.92) (envelope-from ) id 1tTtT9-0001Xg-7S; Sat, 04 Jan 2025 02:00:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864838.1276139; Sat, 04 Jan 2025 02:00:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtT9-0001WW-1R; Sat, 04 Jan 2025 02:00:51 +0000 Received: by outflank-mailman (input) for mailman id 864838; Sat, 04 Jan 2025 02:00:49 +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 1tTtQs-0005Ax-Sa for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:30 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5e44473d-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 770E95C62A5; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 8C669C4CEE4; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86F8EE7719A; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5e44473d-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=Xgs2bv4JXXqvUy90eTrxGWRi5qSOMQjEKlvhtNuvWD0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gKVBWj1Q+WmEWJaWD7QxNZIudKk6SS4SvjEWEBLSsydcYHDXbuq+CkgIWhkKkYsyc 7WeIyRELjzVkDHwj15LTI350khFx9qlnLOokWC84cM6HB5z5hVOChWSsnWQW6Ji1Ir omJTU6H1Egx9q8641wHVq8dtX6X3z/bqXX8gIPZ73a+bt0DlaDUYL99K+0zTNG8WF8 ZZ/YumZ5NXWnlnJMUIpNiPmFSAjZY35bI0zSNc1CgLXSUhXUYfgPAhsolJSqtsg4w/ gep+XQ6Eqs4vcfxNMlaCHFenrwxgjOfTQ6Aho0t3aG/hbiBIl5c7+f6DJClIUBcNXW 4pthH1KzgUtEg== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:21 -0800 Subject: [PATCH v3 15/24] xen/console: make console buffer size configurable MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-15-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=3361; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=Q9U/5BpyrJDws6KsGm2DI3/vHtnpVBTCL+jo+AixI4I=; b=hMkW/p8d9e8YlW1EjCatE/+J+TNOaD3M7w+4q9v/uuzLx8LRbhrHqNYhHbNPSDhfpAOt9c3kG jcKW3DW1vu0Cbj1R7uk77E9E7hi4M5hw7d3a21DBA5Atm3hRvg/QUs8 X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Add new CONRING_SIZE Kconfig parameter to specify the boot console buffer size in bytes. The value is rounded to the nearest power of 2 to match existing conring_size= behavior. The supported range is [16KiB..128MiB]. Bump default size to 32 KiB. Link: https://gitlab.com/xen-project/xen/-/issues/185 Signed-off-by: Denis Mukhin --- docs/misc/xen-command-line.pandoc | 7 +++++-- xen/drivers/char/Kconfig | 11 +++++++++++ xen/drivers/char/console.c | 9 ++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 1a5ee3c91c5cc8bf653e5054211035b5d1bd560f..aeaee482f61aab41438a44eda470902e1e0806f8 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -423,12 +423,15 @@ The following are examples of correct specifications: com1=baud=115200,parity=n,stop-bits=1,io-base=0x3f8,reg-width=4 ### conring_size -> `= ` +> `= ` -> Default: `conring_size=16k` +> Default: `conring_size=32k` Specify the size of the console ring buffer. +The console ring buffer size can be selected at build time via +CONFIG_CONRING_SIZE. + ### console > `= List of [ vga | com1[H,L] | com2[H,L] | pv | dbgp | ehci | xhci | none ]` diff --git a/xen/drivers/char/Kconfig b/xen/drivers/char/Kconfig index e6e12bb4139717f9319031f51f5d20155d2caee2..f7e193e29e2d9ac7c1b878e13f3fb1ce444f31b5 100644 --- a/xen/drivers/char/Kconfig +++ b/xen/drivers/char/Kconfig @@ -96,6 +96,17 @@ config SERIAL_TX_BUFSIZE Default value is 32768 (32KiB). +config CONRING_SIZE + int "Console buffer size" + default 32768 + help + Select the boot console buffer size (in bytes). + Note, the value provided will be rounded down to the nearest power of 2. + Run-time console buffer size is the same as the boot console size, + unless enforced via 'conring_size=' boot parameter. + + Default value is 32768 (32KiB). The supported range is [16KiB..128MiB]. + config XHCI bool "XHCI DbC UART driver" depends on X86 diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 1308236403df8a0f87aeb7e2c00a036c2d8433a7..a33132b8fad95a1ad7e0aab4aef3fa3e46a5c03a 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -100,12 +100,15 @@ static int cf_check parse_console_timestamps(const char *s); custom_runtime_param("console_timestamps", parse_console_timestamps, con_timestamp_mode_upd); -/* conring_size: allows a large console ring than default (16kB). */ +/* conring_size: allows a large console ring than default (32 KiB). */ static uint32_t __initdata opt_conring_size; size_param("conring_size", opt_conring_size); -#define _CONRING_SIZE 16384 -#define CONRING_IDX_MASK(i) ((i)&(conring_size-1)) +#define _CONRING_SIZE (1UL << (31 - __builtin_clz(CONFIG_CONRING_SIZE))) +_Static_assert(_CONRING_SIZE >= 4096 && _CONRING_SIZE <= MB(128), + "CONFIG_CONRING_SIZE must be in [4K..128M] range"); + +#define CONRING_IDX_MASK(i) ( (i) & (conring_size - 1) ) static char __initdata _conring[_CONRING_SIZE]; static char *__read_mostly conring = _conring; static uint32_t __read_mostly conring_size = _CONRING_SIZE; From patchwork Sat Jan 4 01:58:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926040 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 6E835C02183 for ; Sat, 4 Jan 2025 01:58:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864711.1275998 (Exim 4.92) (envelope-from ) id 1tTtQn-0006dY-M9; Sat, 04 Jan 2025 01:58:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864711.1275998; Sat, 04 Jan 2025 01:58:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQn-0006b6-BJ; Sat, 04 Jan 2025 01:58:25 +0000 Received: by outflank-mailman (input) for mailman id 864711; Sat, 04 Jan 2025 01:58:22 +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 1tTtQk-0005Ay-Gz for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:22 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5d120322-ca3f-11ef-99a4-01e77a169b0f; Sat, 04 Jan 2025 02:58:17 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id AB401A411CE; Sat, 4 Jan 2025 01:56:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 9937EC4CEE6; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9332FE77198; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5d120322-ca3f-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=J1IQdeQ98d0vl6JdSs/gueZbYb4U6ovRO5LjK7ff2wk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=XQAZPVJ0qTKM/gXH+OPM9HCQu5UK1W10JCYvPHJREPMm+iwdwKPdyLjrd7mwZnDJ+ tXPEJ/sCMvOJ32DH5fK46DnIokHK4hHcNe+bgrH+ihb9KBV8EJuL6XvAITd8TqHMS6 EhyKA+gJbQ2R+wOSMrAP85FRIvzMWg8Yamp05s2iF5S+xZkWNkLO2zue0XNpqgcJG0 kV/jDoguwyMmw+JCvBmoEpsIdEc28fbXmiBrIO6PHZ+2V+LEf8ZOOYlsR5GoIV2Gwf UlOT1QpwsJf0U4LvMbaaYZYXhoIJZndOXwx4/Gvs36HIen6H9EzUADxTZmPm4byDE0 tZkP8R9bBDm4A== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:22 -0800 Subject: [PATCH v3 16/24] xen/console: introduce console_write() MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-16-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=4614; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=DQVskSH09OmedMdoHofKReknLx5qPNl8KeCzK1S41sE=; b=JfKZBsVOthWu4FvX+ORA18fOi5NiAdEjNH8Vtw0QxvRj8s+KeCXrvayD9yOs3vC+Koqfp1eeD kFqogSxq7OtC3pAsXmZfIeTbMvdrO3vcUFADurPkJJ2GGhzt05pytia X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin PV Linux kernel uses HYPERVISOR_console_io hypercall for early console which ends up being handled by Xen's console driver's guest_console_write(). guest_console_write() duplicates the code from __putstr(), elimitate code duplication. Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 103 ++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index a33132b8fad95a1ad7e0aab4aef3fa3e46a5c03a..2f776b2f07cb15fae8060f3574db73234a38727a 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -40,6 +40,11 @@ #include #endif +/* Console flags. */ +enum { + CONSOLE_RING = BIT(0, U), +}; + /* console: comma-separated list of console outputs. */ static char __initdata opt_console[30] = OPT_CONSOLE_STR; string_param("console", opt_console); @@ -636,6 +641,16 @@ static void cf_check notify_dom0_con_ring(void *unused) static DECLARE_SOFTIRQ_TASKLET(notify_dom0_con_ring_tasklet, notify_dom0_con_ring, NULL); +static bool console_locks_busted; + +static void conring_write(const char *str, size_t len) +{ + conring_puts(str, len); + + if ( !console_locks_busted ) + tasklet_schedule(¬ify_dom0_con_ring_tasklet); +} + #ifdef CONFIG_X86 static inline void xen_console_write_debug_port(const char *buf, size_t len) { @@ -644,8 +659,47 @@ static inline void xen_console_write_debug_port(const char *buf, size_t len) : "=&S" (tmp), "=&c" (tmp) : "0" (buf), "1" (len), "d" (XEN_HVM_DEBUGCONS_IOPORT) ); } + +static void xen_console_write(const char *str, size_t len) +{ + if ( xen_guest ) + xen_hypercall_console_write(str, len); + else + xen_console_write_debug_port(str, len); +} #endif +/* + * Write characters to console. + * + * That will handle all possible scenarios working w/ console + * - serial console; + * - VGA console (x86 only); + * - __HYPERVISOR_console_io hypercall (x86 only); + * - debug I/O port (x86 only); + * - PV console. + */ +static void console_write(const char *str, size_t len, unsigned int flags) +{ + ASSERT(rspin_is_locked(&console_lock)); + + console_serial_puts(str, len); + video_puts(str, len); + +#ifdef CONFIG_X86 + if ( opt_console_xen ) + xen_console_write(str, len); +#endif + + if ( flags & CONSOLE_RING ) + conring_write(str, len); +} + +static inline void __putstr(const char *str) +{ + console_write(str, strlen(str), CONSOLE_RING); +} + static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, unsigned int count) { @@ -666,28 +720,8 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, if ( is_hardware_domain(cd) ) { - /* Use direct console output as it could be interactive */ nrspin_lock_irq(&console_lock); - - console_serial_puts(kbuf, kcount); - video_puts(kbuf, kcount); - -#ifdef CONFIG_X86 - if ( opt_console_xen ) - { - if ( xen_guest ) - xen_hypercall_console_write(kbuf, kcount); - else - xen_console_write_debug_port(kbuf, kcount); - } -#endif - - if ( opt_console_to_ring ) - { - conring_puts(kbuf, kcount); - tasklet_schedule(¬ify_dom0_con_ring_tasklet); - } - + console_write(kbuf, kcount, !!opt_console_to_ring); nrspin_unlock_irq(&console_lock); } else @@ -788,33 +822,6 @@ long do_console_io( * ***************************************************** */ -static bool console_locks_busted; - -static void __putstr(const char *str) -{ - size_t len = strlen(str); - - ASSERT(rspin_is_locked(&console_lock)); - - console_serial_puts(str, len); - video_puts(str, len); - -#ifdef CONFIG_X86 - if ( opt_console_xen ) - { - if ( xen_guest ) - xen_hypercall_console_write(str, len); - else - xen_console_write_debug_port(str, len); - } -#endif - - conring_puts(str, len); - - if ( !console_locks_busted ) - tasklet_schedule(¬ify_dom0_con_ring_tasklet); -} - static int printk_prefix_check(char *p, char **pp) { int loglvl = -1; From patchwork Sat Jan 4 01:58:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926051 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 E64F2E77188 for ; Sat, 4 Jan 2025 02:00:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864798.1276119 (Exim 4.92) (envelope-from ) id 1tTtSq-0008J0-JS; Sat, 04 Jan 2025 02:00:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864798.1276119; Sat, 04 Jan 2025 02:00:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtSq-0008Io-FX; Sat, 04 Jan 2025 02:00:32 +0000 Received: by outflank-mailman (input) for mailman id 864798; Sat, 04 Jan 2025 02:00:30 +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 1tTtQp-0005Ax-Rb for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:27 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5e44909b-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9AA415C6371; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id AEADEC4CEE5; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7971E77188; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5e44909b-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=tKaGED9IpwVKbHVz8RwtOyv0k9Wjw6x6RHqz6c7KSyQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=B52T+kAO6qLDz7zq6gWE1B2qhOvFcxghKxzXb/+ZETwqeaoLAnm2fy1psS4c7gWup SMYJuQfE5ali3eGp8ZbC9qzE0n48Jk3JMvFWEEy3ERpR6Hy1htQFqAHGQLm1+JzblA 0yZvgojt2Jb7agXNEAlyiia4KaTSsi4mOcWhv3lktvk/OCpM0HNp6rEXxP3GHP9BR5 0XsQEU+BhsCv4uI1USP24C3viwYHPXg+40xZNxmVasK/UI7ZuboNzIk98/cufTs6GB t8PZ+i8iF1yalGYKL1LI2dqOEdr8rP6pqFuS+cOLri5SglU18CmuWpOKCQbtgaCzkV m9cQYK6B4L95g== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:23 -0800 Subject: [PATCH v3 17/24] xen/console: flush console ring to physical console MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-17-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=3242; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=HNsOcWLWQbY0cAiixdwe0nN3gebiJS/e1uoFMNrsBDM=; b=Xv6GoU4z4xrDCRW2Ui109tIiHZ591VBeCDEtWzc4OIBnOqGgb9g8t7eqHfMNJFf2HQfO9eUm7 +pxGVDJPNseDBbL6hz7cc71DJfD4v3daXwBkgrVfs/J93tGqVYRXDfK X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Internal console ring is used to hold Xen messages before external consoles (serial, VGA) consoles are fully initialized. Ensure all messages are sent to all external consoles after their initialization is completed. Link: https://gitlab.com/xen-project/xen/-/issues/184 Signed-off-by: Denis Mukhin --- xen/drivers/char/console.c | 56 +++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 2f776b2f07cb15fae8060f3574db73234a38727a..96375067164980a138b1a93161712c0758f4f7fe 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -430,23 +430,36 @@ void console_serial_puts(const char *s, size_t nr) pv_console_puts(s, nr); } -static void cf_check dump_console_ring_key(unsigned char key) +/* + * Write characters to physical console(s). + * That covers: + * - serial console; + * - video output. + */ +static void console_puts(const char *str, size_t len) +{ + ASSERT(rspin_is_locked(&console_lock)); + + console_serial_puts(str, len); + video_puts(str, len); +} + +/* + * Flush contents of the conring to the physical console devices. + */ +static int console_flush(void) { uint32_t idx, len, sofar, c; unsigned int order; char *buf; - printk("'%c' pressed -> dumping console ring buffer (dmesg)\n", key); - - /* create a buffer in which we'll copy the ring in the correct - order and NUL terminate */ order = get_order_from_bytes(conring_size + 1); buf = alloc_xenheap_pages(order, 0); if ( buf == NULL ) - { - printk("unable to allocate memory!\n"); - return; - } + return -ENOMEM; + + + nrspin_lock(&console_lock); c = conringc; sofar = 0; @@ -461,10 +474,23 @@ static void cf_check dump_console_ring_key(unsigned char key) c += len; } - console_serial_puts(buf, sofar); - video_puts(buf, sofar); + console_puts(buf, sofar); + + nrspin_unlock(&console_lock); free_xenheap_pages(buf, order); + + return 0; +} + +static void cf_check dump_console_ring_key(unsigned char key) +{ + int rc; + + printk("'%c' pressed -> dumping console ring buffer (dmesg)\n", key); + rc = console_flush(); + if ( rc ) + printk("failed to dump console ring buffer: %d\n", rc); } /* @@ -681,10 +707,7 @@ static void xen_console_write(const char *str, size_t len) */ static void console_write(const char *str, size_t len, unsigned int flags) { - ASSERT(rspin_is_locked(&console_lock)); - - console_serial_puts(str, len); - video_puts(str, len); + console_puts(str, len); #ifdef CONFIG_X86 if ( opt_console_xen ) @@ -1061,6 +1084,9 @@ void __init console_init_preirq(void) serial_set_rx_handler(sercon_handle, serial_rx); pv_console_set_rx_handler(serial_rx); + /* NB: send conring contents to all enabled physical consoles, if any */ + console_flush(); + /* HELLO WORLD --- start-of-day banner text. */ nrspin_lock(&console_lock); __putstr(xen_banner()); From patchwork Sat Jan 4 01:58:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926056 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 AA6B5E77199 for ; Sat, 4 Jan 2025 02:01:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864882.1276169 (Exim 4.92) (envelope-from ) id 1tTtTN-0003KE-6t; Sat, 04 Jan 2025 02:01:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864882.1276169; Sat, 04 Jan 2025 02:01:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtTN-0003JN-2u; Sat, 04 Jan 2025 02:01:05 +0000 Received: by outflank-mailman (input) for mailman id 864882; Sat, 04 Jan 2025 02:01:03 +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 1tTtQt-0005Ax-Sy for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:31 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5e823437-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A5B9F5C6378; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id BC5DAC4CEDE; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B72ABE77199; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5e823437-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=pZ5j5wlBPTG0Ro4TQWWchJcQ0lQWJtDiDgixm3j4y6w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=sb8BufUAfvJHF+HrR1YXHs6FJn2FKtHyqwvGAO49pNVSOb0IEFVaKR1y6va1Rly1U E/skfQ/W9Enf/posXj8Bnq/Bmgywh3KWM0CwDIQZBM4+CO5tNEFfSaTUaqsCR0+Ysr RHKLAvZuMvInx1xqFKhj1mi7MZwtgdx0RtMRiCsEQNGQAOWThAysUULKCbZOrMFmSM I0tPlQr2U1x6DCoYakTWNxEA9NTWi3elpMpbfNnxYMB8f4cKKBe/twOGsws5KvTjhr dA9WdxhyLULlI0Lt3NdDjEoj31sUM8h3+mfMOYSlQtlKdOXpYxo6ULIljvRrNO+TLO t45fQV88ThCeg== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:24 -0800 Subject: [PATCH v3 18/24] xen/include: introduce resource.h MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-18-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=4529; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=/P+5vP8U8ti5w5xPLZtVwxfiABIGoHWoOC2zq7CuRN4=; b=FQXcMfLgv4oy0lSh4nZAJJfZwlJFq4kmqFTwWUf1GKQJhh19eTVM2pPOzhN85YG6ZA/bi410l y/VJ3oanYN0A5a4cG4PypCJds9z7yDwWwR35ly14MCgXf/rH3H7TbzZ X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Move common resource definitions to a new architecture-agnostic shared header file. Signed-off-by: Denis Mukhin --- It will be used in follow on NS8250 emulator code to describe legacy PC COM resources. --- --- xen/common/device-tree/device-tree.c | 21 +-------------------- xen/drivers/passthrough/arm/smmu.c | 15 +-------------- xen/include/xen/resource.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/xen/common/device-tree/device-tree.c b/xen/common/device-tree/device-tree.c index d0528c5825651f7cc9ebca0c949229c9083063c6..e8f810b2fe10890c033ed3a9d4ca627010ad019b 100644 --- a/xen/common/device-tree/device-tree.c +++ b/xen/common/device-tree/device-tree.c @@ -24,6 +24,7 @@ #include #include #include +#include const void *device_tree_flattened; dt_irq_xlate_func dt_irq_xlate; @@ -535,26 +536,6 @@ int dt_child_n_size_cells(const struct dt_device_node *parent) return __dt_n_size_cells(parent, true); } -/* - * These are defined in Linux where much of this code comes from, but - * are currently unused outside this file in the context of Xen. - */ -#define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */ - -#define IORESOURCE_TYPE_BITS 0x00001f00 /* Resource type */ -#define IORESOURCE_IO 0x00000100 /* PCI/ISA I/O ports */ -#define IORESOURCE_MEM 0x00000200 -#define IORESOURCE_REG 0x00000300 /* Register offsets */ -#define IORESOURCE_IRQ 0x00000400 -#define IORESOURCE_DMA 0x00000800 -#define IORESOURCE_BUS 0x00001000 - -#define IORESOURCE_PREFETCH 0x00002000 /* No side effects */ -#define IORESOURCE_READONLY 0x00004000 -#define IORESOURCE_CACHEABLE 0x00008000 -#define IORESOURCE_RANGELENGTH 0x00010000 -#define IORESOURCE_SHADOWABLE 0x00020000 - /* * Default translator (generic bus) */ diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index 03d22bce1e497e41834c273f9048b98dcbd48a54..aa6a968b574dce7cc753e8070fad3a6e585cd9e7 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -70,22 +71,8 @@ #define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, out)) #define of_property_read_bool dt_property_read_bool #define of_parse_phandle_with_args dt_parse_phandle_with_args - -/* Xen: Helpers to get device MMIO and IRQs */ -struct resource -{ - paddr_t addr; - paddr_t size; - unsigned int type; -}; - -#define resource_size(res) (res)->size; - #define platform_device dt_device_node -#define IORESOURCE_MEM 0 -#define IORESOURCE_IRQ 1 - static struct resource *platform_get_resource(struct platform_device *pdev, unsigned int type, unsigned int num) diff --git a/xen/include/xen/resource.h b/xen/include/xen/resource.h new file mode 100644 index 0000000000000000000000000000000000000000..4512658133defe8dc62d87192ffd19ad94b63c3b --- /dev/null +++ b/xen/include/xen/resource.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * System resource description. + */ +#ifndef XEN__RESOURCE_H +#define XEN__RESOURCE_H + +#define IORESOURCE_BITS 0x000000FFU /* Bus-specific bits */ + +#define IORESOURCE_TYPE_BITS 0x00001F00U /* Resource type */ +#define IORESOURCE_IO 0x00000100U /* PCI/ISA I/O ports */ +#define IORESOURCE_MEM 0x00000200U +#define IORESOURCE_REG 0x00000300U /* Register offsets */ +#define IORESOURCE_IRQ 0x00000400U +#define IORESOURCE_DMA 0x00000800U +#define IORESOURCE_BUS 0x00001000U + +#define IORESOURCE_PREFETCH 0x00002000U /* No side effects */ +#define IORESOURCE_READONLY 0x00004000U +#define IORESOURCE_CACHEABLE 0x00008000U +#define IORESOURCE_RANGELENGTH 0x00010000U +#define IORESOURCE_SHADOWABLE 0x00020000U + +#define IORESOURCE_UNKNOWN ( ~0U ) + +struct resource { + paddr_t addr; + paddr_t size; + unsigned int type; +}; + +#define resource_size(res) ( (res)->size ) + +#endif /* XEN__RESOURCE_H */ From patchwork Sat Jan 4 01:58:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926048 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 0A934E77199 for ; Sat, 4 Jan 2025 01:58:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864717.1276054 (Exim 4.92) (envelope-from ) id 1tTtQu-0008CD-Rj; Sat, 04 Jan 2025 01:58:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864717.1276054; Sat, 04 Jan 2025 01:58:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQt-00085l-UB; Sat, 04 Jan 2025 01:58:31 +0000 Received: by outflank-mailman (input) for mailman id 864717; Sat, 04 Jan 2025 01:58:25 +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 1tTtQn-0005Ay-HM for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:25 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5e86857b-ca3f-11ef-99a4-01e77a169b0f; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BCBD75C6381; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id CCE25C4CEDD; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C54DCE77198; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5e86857b-ca3f-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=c/sQchAB2th2WIR91b/A5zvJkudq54ZcORx3s/2AFYc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=O3wpE11lMn4BMs9NE6jG7Q1a7wgxfshSnVuXaS7yZUJX8gSJrEUhFJPrZKeEPDjZf gQUE2PfMxP/McKgUaPCwcq236fLhwJnZHoekBjERHLzjTRYdkIdw3RN9h1MO7q2WCW +SYMuvCqHb2SsndAIQfD4FjgQfIB8oQN5BGoEd8L9GOsRpORKara7MJMu/UeOyYt7+ 2d1vHWZUV5P9CFWxmHYUylm6v5SYjuBO1bOFQl5ZVM7EGrkrPaxLUcFRALcYXL8HPc ESggfeSIh7sj08XUDmqZdyt0CVVOIQj8zDUaPg3ZjozYURGo0caiMU37m5gPOqH8Ym /hwyXTB2HrdnA== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:25 -0800 Subject: [PATCH v3 19/24] xen/8250-uart: add missing definitions MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-19-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=7808; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=T+cbSUlwhOiYz+Afz3lMbHpJVwMTNzMdAT/z7b8cRYc=; b=Seh7LR0DR3fCTrjLnw3IFzcTtD9s+yB1Dw9zGVcAIVgBH0T14IQCAi2JaSEmb3Itsmxz5kRJD fDh0gHaKhV9BZJqddjdkPR5d3OBSGRt1Jm6ts0V00OayTEtEPw4C1Re X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Added missing definitions needed for NS8250 UART emulator. Re-used newly introduced MSR definitions in the existing ns16550 driver. Also, fixed indentation in a comment for FCR register. Signed-off-by: Denis Mukhin --- xen/drivers/char/ns16550.c | 6 ++-- xen/include/xen/8250-uart.h | 78 +++++++++++++++++++++++++++++++++------------ 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c index eaeb0e09d01ea70f865b8aee4f34ab7a0d4c5cf9..025ba5819d46ea567d41cea512b5f166969fb95f 100644 --- a/xen/drivers/char/ns16550.c +++ b/xen/drivers/char/ns16550.c @@ -721,9 +721,9 @@ static int __init check_existence(struct ns16550 *uart) * Check to see if a UART is really there. * Use loopback test mode. */ - ns_write_reg(uart, UART_MCR, UART_MCR_LOOP | 0x0A); - status = ns_read_reg(uart, UART_MSR) & 0xF0; - return (status == 0x90); + ns_write_reg(uart, UART_MCR, UART_MCR_LOOP | UART_MCR_RTS | UART_MCR_OUT2); + status = ns_read_reg(uart, UART_MSR) & UART_MSR_STATUS; + return (status == (UART_MSR_CTS | UART_MSR_DCD)); } #ifdef CONFIG_HAS_PCI diff --git a/xen/include/xen/8250-uart.h b/xen/include/xen/8250-uart.h index d13352940c13c50bac17d4cdf2f3bf584380776a..6d1af31d582a3dd674a401d7f649e28c889cdc3e 100644 --- a/xen/include/xen/8250-uart.h +++ b/xen/include/xen/8250-uart.h @@ -32,6 +32,7 @@ #define UART_MCR 0x04 /* Modem control */ #define UART_LSR 0x05 /* line status */ #define UART_MSR 0x06 /* Modem status */ +#define UART_SCR 0x07 /* Scratch pad */ #define UART_USR 0x1f /* Status register (DW) */ #define UART_DLL 0x00 /* divisor latch (ls) (DLAB=1) */ #define UART_DLM 0x01 /* divisor latch (ms) (DLAB=1) */ @@ -42,6 +43,8 @@ #define UART_IER_ETHREI 0x02 /* tx reg. empty */ #define UART_IER_ELSI 0x04 /* rx line status */ #define UART_IER_EMSI 0x08 /* MODEM status */ +#define UART_IER_MASK \ + (UART_IER_ERDAI | UART_IER_ETHREI | UART_IER_ELSI | UART_IER_EMSI) /* Interrupt Identification Register */ #define UART_IIR_NOINT 0x01 /* no interrupt pending */ @@ -51,12 +54,19 @@ #define UART_IIR_THR 0x02 /* - tx reg. empty */ #define UART_IIR_MSI 0x00 /* - MODEM status */ #define UART_IIR_BSY 0x07 /* - busy detect (DW) */ +#define UART_IIR_FE 0xC0 /* FIFO enabled (2 bits) */ /* FIFO Control Register */ -#define UART_FCR_ENABLE 0x01 /* enable FIFO */ -#define UART_FCR_CLRX 0x02 /* clear Rx FIFO */ -#define UART_FCR_CLTX 0x04 /* clear Tx FIFO */ -#define UART_FCR_DMA 0x10 /* enter DMA mode */ +#define UART_FCR_ENABLE BIT(0, U) /* enable FIFO */ +#define UART_FCR_CLRX BIT(1, U) /* clear Rx FIFO */ +#define UART_FCR_CLTX BIT(2, U) /* clear Tx FIFO */ +#define UART_FCR_DMA BIT(3, U) /* enter DMA mode */ +#define UART_FCR_RESERVED0 BIT(4, U) /* reserved; always 0 */ +#define UART_FCR_RESERVED1 BIT(5, U) /* reserved; always 0 */ +#define UART_FCR_RTB0 BIT(6, U) /* receiver trigger bit #0 */ +#define UART_FCR_RTB1 BIT(7, U) /* receiver trigger bit #1 */ +#define UART_FCR_TRG_MASK (UART_FCR_RTB0 | UART_FCR_RTB1) + #define UART_FCR_TRG1 0x00 /* Rx FIFO trig lev 1 */ #define UART_FCR_TRG4 0x40 /* Rx FIFO trig lev 4 */ #define UART_FCR_TRG8 0x80 /* Rx FIFO trig lev 8 */ @@ -64,17 +74,17 @@ /* * Note: The FIFO trigger levels are chip specific: - * RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 - * PC16550D: 1 4 8 14 xx xx xx xx - * TI16C550A: 1 4 8 14 xx xx xx xx - * TI16C550C: 1 4 8 14 xx xx xx xx - * ST16C550: 1 4 8 14 xx xx xx xx - * ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 - * NS16C552: 1 4 8 14 xx xx xx xx - * ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 - * TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 - * TI16C752: 8 16 56 60 8 16 32 56 - * Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA + * RX:76 = 00 01 10 11 TX:54 = 00 01 10 11 + * PC16550D: 1 4 8 14 xx xx xx xx + * TI16C550A: 1 4 8 14 xx xx xx xx + * TI16C550C: 1 4 8 14 xx xx xx xx + * ST16C550: 1 4 8 14 xx xx xx xx + * ST16C650: 8 16 24 28 16 8 24 30 PORT_16650V2 + * NS16C552: 1 4 8 14 xx xx xx xx + * ST16C654: 8 16 56 60 8 16 32 56 PORT_16654 + * TI16C750: 1 16 32 56 xx xx xx xx PORT_16750 + * TI16C752: 8 16 56 60 8 16 32 56 + * Tegra: 1 4 8 14 16 8 4 1 PORT_TEGRA */ #define UART_FCR_R_TRIG_00 0x00 #define UART_FCR_R_TRIG_01 0x40 @@ -96,11 +106,33 @@ #define UART_LCR_CONF_MODE_B 0xBF /* Configuration mode B */ /* Modem Control Register */ -#define UART_MCR_DTR 0x01 /* Data Terminal Ready */ -#define UART_MCR_RTS 0x02 /* Request to Send */ -#define UART_MCR_OUT2 0x08 /* OUT2: interrupt mask */ -#define UART_MCR_LOOP 0x10 /* Enable loopback test mode */ -#define UART_MCR_TCRTLR 0x40 /* Access TCR/TLR (TI16C752, EFR[4]=1) */ +#define UART_MCR_DTR BIT(0, U) /* Data Terminal Ready */ +#define UART_MCR_RTS BIT(1, U) /* Request to Send */ +#define UART_MCR_OUT1 BIT(2, U) /* OUT1: interrupt mask */ +#define UART_MCR_OUT2 BIT(3, U) /* OUT2: interrupt mask */ +#define UART_MCR_LOOP BIT(4, U) /* Enable loopback test mode */ +#define UART_MCR_RESERVED0 BIT(5, U) /* Reserved #0 */ +#define UART_MCR_RESERVED1 BIT(6, U) /* Reserved #1 */ +#define UART_MCR_TCRTLR BIT(6, U) /* Access TCR/TLR (TI16C752, EFR[4]=1) */ +#define UART_MCR_RESERVED2 BIT(7, U) /* Reserved #2 */ +#define UART_MCR_MASK \ + (UART_MCR_DTR | UART_MCR_RTS | \ + UART_MCR_OUT1 | UART_MCR_OUT2 | \ + UART_MCR_LOOP) + +/* Modem Status Register */ +#define UART_MSR_DCTS BIT(0, U) /* Change in CTS */ +#define UART_MSR_DDSR BIT(1, U) /* Change in DSR */ +#define UART_MSR_TERI BIT(2, U) /* Change in RI */ +#define UART_MSR_DDCD BIT(3, U) /* Change in CTS */ +#define UART_MSR_CTS BIT(4, U) +#define UART_MSR_DSR BIT(5, U) +#define UART_MSR_RI BIT(6, U) +#define UART_MSR_DCD BIT(7, U) +#define UART_MSR_CHANGE \ + (UART_MSR_DCTS | UART_MSR_DDSR | UART_MSR_TERI | UART_MSR_DDCD) +#define UART_MSR_STATUS \ + (UART_MSR_CTS | UART_MSR_DSR | UART_MSR_RI | UART_MSR_DCD) /* Line Status Register */ #define UART_LSR_DR 0x01 /* Data ready */ @@ -111,6 +143,7 @@ #define UART_LSR_THRE 0x20 /* Xmit hold reg empty */ #define UART_LSR_TEMT 0x40 /* Xmitter empty */ #define UART_LSR_ERR 0x80 /* Error */ +#define UART_LSR_MASK (UART_LSR_OE | UART_LSR_BI) /* These parity settings can be ORed directly into the LCR. */ #define UART_PARITY_NONE (0<<3) @@ -119,7 +152,10 @@ #define UART_PARITY_MARK (5<<3) #define UART_PARITY_SPACE (7<<3) -/* Frequency of external clock source. This definition assumes PC platform. */ +/* + * Frequency of external UART clock source. + * Same as IBM PC master input clock frequency. + */ #define UART_CLOCK_HZ 1843200 /* Bits in Exar specific UART_XR_EFR register */ From patchwork Sat Jan 4 01:58:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926049 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 4605AE7719B for ; Sat, 4 Jan 2025 01:58:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864720.1276067 (Exim 4.92) (envelope-from ) id 1tTtQw-00006f-NH; Sat, 04 Jan 2025 01:58:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864720.1276067; Sat, 04 Jan 2025 01:58: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 1tTtQv-0008TL-I8; Sat, 04 Jan 2025 01:58:33 +0000 Received: by outflank-mailman (input) for mailman id 864720; Sat, 04 Jan 2025 01:58:27 +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 1tTtQo-0005Ax-RK for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:26 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5eac8ac3-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CAA915C639F; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id E0C8BC4CEE1; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D810FE77188; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5eac8ac3-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955895; bh=nSRwKS/LlYYRVpg8RD3W+jOmXH2WKIn1w6/k5ce46cI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Q0oJSytHpCJ18yKH3eU+0eiIoBhxu4aXsWcv+wQbyrAfsK0SblMhDqc8Fj1GH3zu2 nAf5Z5qhTjoWRdPUfQc/qQQ5l931UhCoSjHGrXHEdRLLq6OHFrVaFRrIa2ieieLdRx w3vsgK6F+lM3H9NanKEtv0Z8M+iF3kdHTChk+kfR5Qcg9EZJiCHfQoq5RiT1DvTUxY ALoMaAw8vW3JS7Q/43Ub3x0BASTI5iYMsJB7zLWmvipHHzhBcOm9XsVC7/1u9ZHpM/ SaVL8zlWrj76w0m4PS/A+WFPodEyvhNvou0kMp53iI2ODr5Nig3LNNaWhM+FLWL5ce OYi7DEg46BXug== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:26 -0800 Subject: [PATCH v3 20/24] x86/hvm: add HVM-specific Kconfig MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-20-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=5996; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=ZuTYcfV9biFH1je7dgKxHOvxFrMn/uUk/GeyiLFF3sY=; b=Ku3PacZpewsitaaL+kvBF+lfGyiiPlFVCVhhsjjgR1C+JMZqsYY5+po+CuFLwLCorvFrQSYaU tUP9VKEu1XVD7+pNk0pEDd3kjb5KXYHvZukXa/aIu2dExvh5lytJzrv X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Add separate menu for configuring HVM build-time settings to help organizing HVM-specific options. Signed-off-by: Denis Mukhin --- xen/arch/x86/Kconfig | 76 +----------------------------------------------- xen/arch/x86/hvm/Kconfig | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 75 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 9cdd04721afa1916c7edd8fdf7d606858c73ce88..37362c205dc664a1e809322c2cfe9f45394e30df 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -30,7 +30,6 @@ config X86 select HAS_SCHED_GRANULARITY select HAS_UBSAN select HAS_VMAP - select HAS_VPCI if HVM select NEEDS_LIBELF config ARCH_DEFCONFIG @@ -107,42 +106,7 @@ config PV_LINEAR_PT If unsure, say Y. -config HVM - bool "HVM support" - depends on !PV_SHIM_EXCLUSIVE - default !PV_SHIM - select COMPAT - select IOREQ_SERVER - select MEM_ACCESS_ALWAYS_ON - help - Interfaces to support HVM domains. HVM domains require hardware - virtualisation extensions (e.g. Intel VT-x, AMD SVM), but can boot - guests which have no specific Xen knowledge. - - This option is needed if you want to run HVM or PVH domains. - - If unsure, say Y. - -config AMD_SVM - bool "AMD-V" if EXPERT - depends on HVM - default y - help - Enables virtual machine extensions on platforms that implement the - AMD Virtualization Technology (AMD-V). - If your system includes a processor with AMD-V support, say Y. - If in doubt, say Y. - -config INTEL_VMX - bool "Intel VT-x" if EXPERT - depends on HVM - default y - select ARCH_VCPU_IOREQ_COMPLETION - help - Enables virtual machine extensions on platforms that implement the - Intel Virtualization Technology (Intel VT-x). - If your system includes a processor with Intel VT-x support, say Y. - If in doubt, say Y. +source "arch/x86/hvm/Kconfig" config XEN_SHSTK bool "Supervisor Shadow Stacks" @@ -201,25 +165,6 @@ config BIGMEM If unsure, say N. -config HVM_FEP - bool "HVM Forced Emulation Prefix support (UNSUPPORTED)" if UNSUPPORTED - default DEBUG - depends on HVM - help - - Compiles in a feature that allows HVM guest to arbitrarily - exercise the instruction emulator. - - This feature can only be enabled during boot time with - appropriate hypervisor command line option. Please read - hypervisor command line documentation before trying to use - this feature. - - This is strictly for testing purposes, and not appropriate - for use in production. - - If unsure, say N. - config TBOOT bool "Xen tboot support (UNSUPPORTED)" depends on INTEL && UNSUPPORTED @@ -348,14 +293,6 @@ config HYPERV_GUEST endif -config MEM_PAGING - bool "Xen memory paging support (UNSUPPORTED)" if UNSUPPORTED - depends on HVM - -config MEM_SHARING - bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED - depends on HVM - config REQUIRE_NX bool "Require NX (No eXecute) support" help @@ -372,17 +309,6 @@ config REQUIRE_NX was unavailable. However, if enabled, Xen will no longer boot on any CPU which is lacking NX support. -config ALTP2M - bool "Alternate P2M support" if EXPERT - depends on INTEL_VMX - default y - help - Alternate-p2m allows a guest to manage multiple p2m guest physical - "memory views" (as opposed to a single p2m). - Useful for memory introspection. - - If unsure, stay with defaults. - endmenu source "common/Kconfig" diff --git a/xen/arch/x86/hvm/Kconfig b/xen/arch/x86/hvm/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..fdfa9f80d30347ac9c34e52f5ba829bc11916dc0 --- /dev/null +++ b/xen/arch/x86/hvm/Kconfig @@ -0,0 +1,74 @@ +menuconfig HVM + bool "HVM support" + depends on !PV_SHIM_EXCLUSIVE + default !PV_SHIM + select COMPAT + select IOREQ_SERVER + select MEM_ACCESS_ALWAYS_ON + select HAS_VPCI + help + Interfaces to support HVM domains. HVM domains require hardware + virtualisation extensions (e.g. Intel VT-x, AMD SVM), but can boot + guests which have no specific Xen knowledge. + + This option is needed if you want to run HVM or PVH domains. + + If unsure, say Y. + +if HVM + +config AMD_SVM + bool "AMD-V" if EXPERT + default y + help + Enables virtual machine extensions on platforms that implement the + AMD Virtualization Technology (AMD-V). + If your system includes a processor with AMD-V support, say Y. + If in doubt, say Y. + +config INTEL_VMX + bool "Intel VT-x" if EXPERT + default y + select ARCH_VCPU_IOREQ_COMPLETION + help + Enables virtual machine extensions on platforms that implement the + Intel Virtualization Technology (Intel VT-x). + If your system includes a processor with Intel VT-x support, say Y. + If in doubt, say Y. + +config ALTP2M + bool "Alternate P2M support" if EXPERT + depends on INTEL_VMX + default y + help + Alternate-p2m allows a guest to manage multiple p2m guest physical + "memory views" (as opposed to a single p2m). + Useful for memory introspection. + + If unsure, stay with defaults. + +config MEM_PAGING + bool "Xen memory paging support (UNSUPPORTED)" if UNSUPPORTED + +config MEM_SHARING + bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED + +config HVM_FEP + bool "HVM Forced Emulation Prefix support (UNSUPPORTED)" if UNSUPPORTED + default DEBUG + help + + Compiles in a feature that allows HVM guest to arbitrarily + exercise the instruction emulator. + + This feature can only be enabled during boot time with + appropriate hypervisor command line option. Please read + hypervisor command line documentation before trying to use + this feature. + + This is strictly for testing purposes, and not appropriate + for use in production. + + If unsure, say N. + +endif From patchwork Sat Jan 4 01:58:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926050 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 E0750E77188 for ; Sat, 4 Jan 2025 01:58:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864719.1276078 (Exim 4.92) (envelope-from ) id 1tTtQy-0000OV-9j; Sat, 04 Jan 2025 01:58:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864719.1276078; Sat, 04 Jan 2025 01:58:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtQw-0000JU-Pt; Sat, 04 Jan 2025 01:58:34 +0000 Received: by outflank-mailman (input) for mailman id 864719; Sat, 04 Jan 2025 01:58:27 +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 1tTtQo-0005Ay-Hd for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:26 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5ec58b77-ca3f-11ef-99a4-01e77a169b0f; Sat, 04 Jan 2025 02:58:20 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E209E5C63D5; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 035ACC4CEE3; Sat, 4 Jan 2025 01:58:16 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F03C5E77199; Sat, 4 Jan 2025 01:58:15 +0000 (UTC) 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: 5ec58b77-ca3f-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955896; bh=ard5UX4ASLQLjRYgt3OZQKzVUpMmaZiWJf8THwt2c1U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=pjT2u1B9stcTye2oZXoJSsok8YnbeR7APOvvZFDRY0fe6gy/gUN7cnm1CQxp1BcRu 7wi2S1ioJ3dRXU0weq+015+gHH8TUEY5boJIqgPwa/1FfSqbIJnjvCMemyLLVgt0tF +fX1ORtEjRWQpMsYqrJipU/tdibJlndU5Wo1oh9jyqnbrl7Zjpkre6Tdbt5XCjyGhC w1dseJbChMBv/79CvAMfypfZ6iOYcAtxpzGJHrrH0i1khL3kPVutT5Wm97jgGz4T6B z7ME3lylYuKs644SevAIRaNwbHWLHl/TjBwq+bUz7cjPLfCmadEYC7XVIsQQ0d8350 9iLCM4gcg3Rtg== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:27 -0800 Subject: [PATCH v3 21/24] x86/hvm: introduce NS16550-compatible UART emulator MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-21-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=33000; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=JY8NnZN8J5h06Ci6rDls8X8bQvMTHJfCNc/lld0E2cs=; b=2L8iKGD6AUVIWHDKbg1Szk28hZQ7CfLJIVQJjGAYiGG79anmV/wrsZvPM0l5Hnhq0mnMfWHzd xCxAPAR0ODWAHGiqBl8VFqx9dgImRsResgUdqpT4oyCEr7K/CMEP7x/ X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Add initial in-hypervisor emulator for NS8250/NS16x50-compatible UARTs under CONFIG_VUART_NS16550. x86 port of Xen lacks vUART facility similar to Arm's vpl011 to support x86 guest OS bring up in the embedded setups. In parallel domain creation scenario (hyperlaunch), NS16550 emulator helps early guest firmware and OS bringup debugging, because it eliminates dependency on the external emulator (qemu) being operational by the time domains are created. The emulator also allows to forward the physical console input to the x86 domain which is useful when a system has only one physical UART for early debugging and this UART is owned by Xen. By default, CONFIG_VUART_NS16550 enables emulation of NS16550 at I/O port 0x3f8, IRQ#4 in guest OS (legacy COM1). Legacy COM resources can be selected at built-time and cannot be configured per-domain yet. Please refer to the NS16550 emulator code for limitations. Signed-off-by: Denis Mukhin --- xen/arch/x86/hvm/Kconfig | 48 ++ xen/arch/x86/hvm/Makefile | 1 + xen/arch/x86/hvm/hvm.c | 10 + xen/arch/x86/hvm/vuart-ns16550.c | 928 ++++++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/hvm/domain.h | 4 + xen/drivers/virtdev-uart.c | 6 + xen/include/xen/resource.h | 3 + 7 files changed, 1000 insertions(+) diff --git a/xen/arch/x86/hvm/Kconfig b/xen/arch/x86/hvm/Kconfig index fdfa9f80d30347ac9c34e52f5ba829bc11916dc0..29de48c147d8362be8bf4f07a3dc0302a0547497 100644 --- a/xen/arch/x86/hvm/Kconfig +++ b/xen/arch/x86/hvm/Kconfig @@ -71,4 +71,52 @@ config HVM_FEP If unsure, say N. +config VUART_NS16550 + bool "NS16550-compatible UART Emulation" if EXPERT + depends on HAS_IOPORTS + select HAS_VUART + help + In-hypervisor NS16550/NS16x50 UART emulation. + + Only legacy PC I/O ports are emulated. + + This is strictly for testing purposes (such as early HVM guest console), + and not appropriate for use in production. + +choice VUART_NS16550_PC + prompt "IBM PC COM resources" + depends on VUART_NS16550 + default VUART_NS16550_PC_COM1 + help + Default emulated NS16550 resources. + +config VUART_NS16550_PC_COM1 + bool "COM1 (I/O port 0x3f8, IRQ#4)" + +config VUART_NS16550_PC_COM2 + bool "COM2 (I/O port 0x2f8, IRQ#3)" + +config VUART_NS16550_PC_COM3 + bool "COM3 (I/O port 0x3e8, IRQ#4)" + +config VUART_NS16550_PC_COM4 + bool "COM4 (I/O port 0x2e8, IRQ#3)" + +endchoice + +config VUART_NS16550_LOG_LEVEL + int "UART emulator verbosity level" + range 0 3 + default "1" + depends on VUART_NS16550 + help + Set the default log level of UART emulator. + See include/xen/config.h for more details. + +config VUART_NS16550_DEBUG + bool "UART emulator development debugging" + depends on VUART_NS16550 + help + Enable development debugging. + endif diff --git a/xen/arch/x86/hvm/Makefile b/xen/arch/x86/hvm/Makefile index 4c1fa5c6c2bf75d336b39f343241bfced5b91b09..ba2baa850183c31b199e4d080aa549e59947ddc1 100644 --- a/xen/arch/x86/hvm/Makefile +++ b/xen/arch/x86/hvm/Makefile @@ -29,3 +29,4 @@ obj-y += vm_event.o obj-y += vmsi.o obj-y += vpic.o obj-y += vpt.o +obj-$(CONFIG_VUART_NS16550) += vuart-ns16550.o diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index ce21f5884b554f27991f19d9953731a9e8241e90..cf610c8e01974df012a93c60657218ae96ca36d9 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -680,6 +680,13 @@ int hvm_domain_initialise(struct domain *d, if ( rc != 0 ) goto fail1; + if ( domain_has_vuart(d) ) + { + rc = virtdev_uart_init(d, NULL); + if ( rc != 0 ) + goto out_vioapic_deinit; + } + stdvga_init(d); rtc_init(d); @@ -700,6 +707,9 @@ int hvm_domain_initialise(struct domain *d, return 0; fail2: + if ( domain_has_vuart(d) ) + virtdev_uart_exit(d); + out_vioapic_deinit: vioapic_deinit(d); fail1: if ( is_hardware_domain(d) ) diff --git a/xen/arch/x86/hvm/vuart-ns16550.c b/xen/arch/x86/hvm/vuart-ns16550.c new file mode 100644 index 0000000000000000000000000000000000000000..d0c19f53399bd8241f54d2fe2716e62046b8e59d --- /dev/null +++ b/xen/arch/x86/hvm/vuart-ns16550.c @@ -0,0 +1,928 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * NS16550-compatible UART Emulator. + * + * See: + * - Serial and UART Tutorial: + * https://download.freebsd.org/doc/en/articles/serial-uart/serial-uart_en.pdf + * - UART w/ 16 byte FIFO: + * https://www.ti.com/lit/ds/symlink/tl16c550c.pdf + * - UART w/ 64 byte FIFO: + * https://www.ti.com/lit/ds/symlink/tl16c750.pdf + * + * Limitations: + * - Only x86; + * - Only HVM domains support (build-time), PVH domains are not supported yet; + * - Only legacy COM{1,2,3,4} resources via Kconfig, custom I/O ports/IRQs + * are not supported; + * - Only Xen console as a backend, no inter-domain communication (similar to + * vpl011 on Arm); + * - Only 8n1 emulation (8-bit data, no parity, 1 stop bit); + * - No toolstack integration; + * - No baud rate emulation (reports 115200 baud to the guest OS); + * - No FIFO-less mode emulation; + * - No RX FIFO interrupt moderation (FCR) emulation; + * - No integration w/ VM snapshotting (HVM_REGISTER_SAVE_RESTORE() and + * friends); + * - No ISA IRQ sharing allowed; + * - No MMIO-based UART emulation. + */ + +#define pr_prefix "ns16550" +#define pr_fmt(fmt) pr_prefix ": " fmt +#define pr_log_level CONFIG_VUART_NS16550_LOG_LEVEL + +#include /* max_init_domid */ +#include +#include +#include +#include +#include +#include +#include + +#define pr_err(fmt, args...) do { \ + gprintk(KERN_ERR, pr_fmt(fmt), ## args); \ +} while (0) + +#define pr_warn(fmt, args...) do { \ + if ( pr_log_level >= 1) \ + gprintk(KERN_WARNING, pr_fmt(fmt), ## args); \ +} while (0) + +#define pr_info(fmt, args...) do { \ + if ( pr_log_level >= 2 ) \ + gprintk(KERN_INFO, pr_fmt(fmt), ## args); \ +} while (0) + +#define pr_debug(fmt, args...) do { \ + if ( pr_log_level >= 3 ) \ + gprintk(KERN_DEBUG, pr_fmt(fmt), ## args); \ +} while (0) + +#if defined(CONFIG_VUART_NS16550_PC_COM1) +#define X86_PC_UART_IDX 0 +#elif defined(CONFIG_VUART_NS16550_PC_COM2) +#define X86_PC_UART_IDX 1 +#elif defined(CONFIG_VUART_NS16550_PC_COM3) +#define X86_PC_UART_IDX 2 +#elif defined(CONFIG_VUART_NS16550_PC_COM4) +#define X86_PC_UART_IDX 3 +#else +#error "Unsupported I/O port" +#endif + +/* + * Number of supported registers in the UART. + */ +#define NS16550_REGS_NUM ( UART_SCR + 1 ) + +/* + * Number of emulated registers. + * + * - Emulated registers [0..NS16550_REGS_NUM] are R/W registers for DLAB=0. + * - DLAB=1, R/W, DLL = NS16550_REGS_NUM + 0 + * - DLAB=1, R/W, DLM = NS16550_REGS_NUM + 1 + * - R/O, IIR (IIR_THR) = NS16550_REGS_NUM + 2 + */ +#define NS16550_EMU_REGS_NUM ( NS16550_REGS_NUM + 3 ) + +/* + * Virtual NS16550 device state. + */ +struct vuart_ns16550 { + struct xencons_interface cons; /* Emulated RX/TX FIFOs */ + uint8_t regs[NS16550_EMU_REGS_NUM]; /* Emulated registers */ + unsigned int irq; /* Emulated IRQ# */ + uint64_t io_addr; /* Emulated I/O region base address */ + uint64_t io_size; /* Emulated I/O region size */ + const char *name; /* Device name */ + struct domain *owner; /* Owner domain */ + spinlock_t lock; /* Protection */ +}; + +/* + * Virtual device description. + */ +struct virtdev_desc { + const char *name; + const struct resource *res; +}; + +/* + * Legacy IBM PC NS16550 resources. + * There are only 4 I/O port ranges, hardcoding all of them here. + */ +static const struct virtdev_desc x86_pc_uarts[4] = { + [0] = { + .name = "COM1", + .res = (const struct resource[]){ + { .type = IORESOURCE_IO, .addr = 0x3F8, .size = NS16550_REGS_NUM }, + { .type = IORESOURCE_IRQ, .addr = 4, .size = 1 }, + { .type = IORESOURCE_UNKNOWN }, + }, + }, + [1] = { + .name = "COM2", + .res = (const struct resource[]){ + { .type = IORESOURCE_IO, .addr = 0x2F8, .size = NS16550_REGS_NUM }, + { .type = IORESOURCE_IRQ, .addr = 3, .size = 1 }, + { .type = IORESOURCE_UNKNOWN }, + }, + }, + [2] = { + .name = "COM3", + .res = (const struct resource[]){ + { .type = IORESOURCE_IO, .addr = 0x3E8, .size = NS16550_REGS_NUM }, + { .type = IORESOURCE_IRQ, .addr = 4, .size = 1 }, + { .type = IORESOURCE_UNKNOWN }, + }, + }, + [3] = { + .name = "COM4", + .res = (const struct resource[]){ + { .type = IORESOURCE_IO, .addr = 0x2E8, .size = NS16550_REGS_NUM }, + { .type = IORESOURCE_IRQ, .addr = 3, .size = 1 }, + { .type = IORESOURCE_UNKNOWN }, + }, + }, +}; + +static bool ns16550_fifo_rx_empty(const struct vuart_ns16550 *vdev) +{ + const struct xencons_interface *cons = &vdev->cons; + + return cons->in_prod == cons->in_cons; +} + +static bool ns16550_fifo_rx_full(const struct vuart_ns16550 *vdev) +{ + const struct xencons_interface *cons = &vdev->cons; + + return cons->in_prod - cons->in_cons == ARRAY_SIZE(cons->in); +} + +static void ns16550_fifo_rx_reset(struct vuart_ns16550 *vdev) +{ + struct xencons_interface *cons = &vdev->cons; + + cons->in_cons = cons->in_prod; +} + +static int ns16550_fifo_rx_getchar(struct vuart_ns16550 *vdev) +{ + struct xencons_interface *cons = &vdev->cons; + int rc; + + if ( ns16550_fifo_rx_empty(vdev) ) + { + pr_debug("%s: RX FIFO empty\n", vdev->name); + rc = -ENODATA; + } + else + { + rc = cons->in[MASK_XENCONS_IDX(cons->in_cons, cons->in)]; + cons->in_cons++; + } + + return rc; +} + +static int ns16550_fifo_rx_putchar(struct vuart_ns16550 *vdev, char c) +{ + struct xencons_interface *cons = &vdev->cons; + int rc; + + /* + * FIFO-less 8250/16450 UARTs: newly arrived word overwrites the contents + * of the THR. + */ + if ( ns16550_fifo_rx_full(vdev) ) + { + pr_debug("%s: RX FIFO full; resetting\n", vdev->name); + ns16550_fifo_rx_reset(vdev); + rc = -ENOSPC; + } + else + rc = 0; + + cons->in[MASK_XENCONS_IDX(cons->in_prod, cons->in)] = c; + cons->in_prod++; + + return rc; +} + +static bool ns16550_fifo_tx_empty(const struct vuart_ns16550 *vdev) +{ + const struct xencons_interface *cons = &vdev->cons; + + return cons->out_prod == cons->out_cons; +} + +static void ns16550_fifo_tx_reset(struct vuart_ns16550 *vdev) +{ + struct xencons_interface *cons = &vdev->cons; + + cons->out_prod = 0; + ASSERT(cons->out_cons == cons->out_prod); +} + +/* + * Flush cached output to Xen console. + */ +static void ns16550_fifo_tx_flush(struct vuart_ns16550 *vdev) +{ + struct xencons_interface *cons = &vdev->cons; + + if ( ns16550_fifo_tx_empty(vdev) ) + return; + + ASSERT(cons->out_prod < ARRAY_SIZE(cons->out)); + cons->out[cons->out_prod] = '\0'; + cons->out_prod++; + + guest_printk(vdev->owner, "%s", cons->out); + + ns16550_fifo_tx_reset(vdev); +} + +/* + * Accumulate guest OS output before sending to Xen console. + */ +static void ns16550_fifo_tx_putchar(struct vuart_ns16550 *vdev, char ch) +{ + struct xencons_interface *cons = &vdev->cons; + + if ( !is_console_printable(ch) ) + return; + + if ( ch != '\0' ) + { + cons->out[cons->out_prod] = ch; + cons->out_prod++; + } + + if ( cons->out_prod == ARRAY_SIZE(cons->out) - 1 || + ch == '\n' || ch == '\0' ) + ns16550_fifo_tx_flush(vdev); +} + +static inline uint8_t cf_check ns16550_dlab_get(const struct vuart_ns16550 *vdev) +{ + return vdev->regs[UART_LCR] & UART_LCR_DLAB ? 1 : 0; +} + +static bool cf_check ns16550_iir_check_lsi(const struct vuart_ns16550 *vdev) +{ + return !!(vdev->regs[UART_LSR] & UART_LSR_MASK); +} + +static bool cf_check ns16550_iir_check_rda(const struct vuart_ns16550 *vdev) +{ + return !ns16550_fifo_rx_empty(vdev); +} + +static bool cf_check ns16550_iir_check_thr(const struct vuart_ns16550 *vdev) +{ + return !!(vdev->regs[NS16550_REGS_NUM + UART_IIR] & UART_IIR_THR); +} + +static bool cf_check ns16550_iir_check_msi(const struct vuart_ns16550 *vdev) +{ + return !!(vdev->regs[UART_MSR] & UART_MSR_CHANGE); +} + +/* + * Get the interrupt identity reason. + * + * IIR is re-calculated once called, because NS16550 always reports high + * priority events first. + * regs[NS16550_REGS_NUM + UART_IIR] is used to store THR reason only. + */ +static uint8_t ns16550_iir_get(const struct vuart_ns16550 *vdev) +{ + /* + * Interrupt identity reasons by priority. + * NB: high priority are at lower indexes below. + */ + static const struct { + bool (*check)(const struct vuart_ns16550 *vdev); + uint8_t ier; + uint8_t iir; + } iir_by_prio[] = { + [0] = { ns16550_iir_check_lsi, UART_IER_ELSI, UART_IIR_LSI }, + [1] = { ns16550_iir_check_rda, UART_IER_ERDAI, UART_IIR_RDA }, + [2] = { ns16550_iir_check_thr, UART_IER_ETHREI, UART_IIR_THR }, + [3] = { ns16550_iir_check_msi, UART_IER_EMSI, UART_IIR_MSI }, + }; + const uint8_t *regs = vdev->regs; + uint8_t iir = 0; + unsigned int i; + + /* + * NB: every interaction w/ NS16550 registers (except DLAB=1) goes + * through that call. + */ + ASSERT(spin_is_locked(&vdev->lock)); + + for ( i = 0; i < ARRAY_SIZE(iir_by_prio); i++ ) + { + if ( (regs[UART_IER] & iir_by_prio[i].ier) && + iir_by_prio[i].check(vdev) ) + break; + + } + if ( i == ARRAY_SIZE(iir_by_prio) ) + iir |= UART_IIR_NOINT; + else + iir |= iir_by_prio[i].iir; + + if ( regs[UART_FCR] & UART_FCR_ENABLE ) + iir |= UART_IIR_FE; + + return iir; +} + +/* + * Assert/deassert virtual NS16550 interrupt line. + */ +static void ns16550_irq_check(const struct vuart_ns16550 *vdev) +{ + uint8_t iir = ns16550_iir_get(vdev); + + if ( iir & UART_IIR_NOINT ) + hvm_isa_irq_assert(vdev->owner, vdev->irq, NULL); + else + hvm_isa_irq_deassert(vdev->owner, vdev->irq); + + pr_debug("%s: IRQ#%d %x %s\n", vdev->name, vdev->irq, iir, + (iir & UART_IIR_NOINT) ? "deassert" : "assert"); +} + +/* + * Emulate 8-bit write access to NS16550 register. + */ +static int ns16550_io_write8( + struct vuart_ns16550 *vdev, uint32_t reg, uint8_t *data) +{ + uint8_t *regs = vdev->regs; + uint8_t val = *data; + int rc = 0; + + if ( ns16550_dlab_get(vdev) && (reg == UART_DLL || reg == UART_DLM) ) + regs[NS16550_REGS_NUM + reg] = val; + else + { + switch ( reg ) + { + case UART_THR: + if ( regs[UART_MCR] & UART_MCR_LOOP ) + { + (void)ns16550_fifo_rx_putchar(vdev, val); + regs[UART_LSR] |= UART_LSR_OE; + } + else + ns16550_fifo_tx_putchar(vdev, val); + + regs[NS16550_REGS_NUM + UART_IIR] |= UART_IIR_THR; + + break; + + case UART_IER: + /* + * NB: Make sure THR interrupt is re-triggered once guest OS + * re-enabled ETHREI in EIR. + */ + if ( val & regs[UART_IER] & UART_IER_ETHREI ) + regs[NS16550_REGS_NUM + UART_IIR] |= UART_IIR_THR; + + regs[UART_IER] = val & UART_IER_MASK; + + break; + + case UART_FCR: /* WO */ + if ( val & UART_FCR_RESERVED0 ) + pr_warn("%s: FCR: attempt to set reserved bit: %x\n", + vdev->name, UART_FCR_RESERVED0); + + if ( val & UART_FCR_RESERVED1 ) + pr_warn("%s: FCR: attempt to set reserved bit: %x\n", + vdev->name, UART_FCR_RESERVED1); + + if ( val & UART_FCR_CLRX ) + ns16550_fifo_rx_reset(vdev); + + if ( val & UART_FCR_CLTX ) + ns16550_fifo_tx_flush(vdev); + + if ( val & UART_FCR_ENABLE ) + val &= UART_FCR_ENABLE | UART_FCR_DMA | UART_FCR_TRG_MASK; + else + val = 0; + + regs[UART_FCR] = val; + + break; + + case UART_LCR: + regs[UART_LCR] = val; + break; + + case UART_MCR: { + uint8_t msr_curr, msr_next, msr_delta; + + msr_curr = regs[UART_MSR]; + msr_next = 0; + msr_delta = 0; + + if ( val & UART_MCR_RESERVED0 ) + pr_warn("%s: MCR: attempt to set reserved bit: %x\n", + vdev->name, UART_MCR_RESERVED0); + + if ( val & UART_MCR_RESERVED1 ) + pr_warn("%s: MCR: attempt to set reserved bit: %x\n", + vdev->name, UART_MCR_RESERVED1); + + if ( val & UART_MCR_RESERVED2 ) + pr_warn("%s: MCR: attempt to set reserved bit: %x\n", + vdev->name, UART_MCR_RESERVED2); + + /* Set modem status */ + if ( val & UART_MCR_LOOP ) + { + if ( val & UART_MCR_DTR ) + msr_next |= UART_MSR_DSR; + if ( val & UART_MCR_RTS ) + msr_next |= UART_MSR_CTS; + if ( val & UART_MCR_OUT1 ) + msr_next |= UART_MSR_RI; + if ( val & UART_MCR_OUT2 ) + msr_next |= UART_MSR_DCD; + } + else + msr_next |= UART_MSR_DCD | UART_MSR_DSR | UART_MSR_CTS; + + /* Calculate changes in modem status */ + if ( (msr_curr & UART_MSR_CTS) ^ (msr_next & UART_MSR_CTS) ) + msr_delta |= UART_MSR_DCTS; + if ( (msr_curr & UART_MCR_RTS) ^ (msr_next & UART_MCR_RTS) ) + msr_delta |= UART_MSR_DDSR; + if ( (msr_curr & UART_MSR_RI) & (msr_next & UART_MSR_RI) ) + msr_delta |= UART_MSR_TERI; + if ( (msr_curr & UART_MSR_DCD) ^ (msr_next & UART_MSR_DCD) ) + msr_delta |= UART_MSR_DDCD; + + regs[UART_MCR] = val & UART_MCR_MASK; + regs[UART_MSR] = msr_next | msr_delta; + + break; + } + + /* NB: Firmware (e.g. OVMF) may rely on SCR presence. */ + case UART_SCR: + regs[UART_SCR] = val; + break; + + case UART_LSR: /* RO */ + case UART_MSR: /* RO */ + default: + rc = -EINVAL; + break; + } + + ns16550_irq_check(vdev); + } + + return rc; +} + +/* + * Emulate 16-bit write access to NS16550 register. + * NB: some guest OSes use outw() to access UART_DLL. + */ +static int ns16550_io_write16( + struct vuart_ns16550 *vdev, uint32_t reg, uint16_t *data) +{ + uint16_t val = *data; + int rc; + + if ( ns16550_dlab_get(vdev) && reg == UART_DLL ) + { + vdev->regs[NS16550_REGS_NUM + UART_DLL] = val & 0xFF; + vdev->regs[NS16550_REGS_NUM + UART_DLM] = (val >> 8) & 0xFF; + rc = 0; + } + else + rc = -EINVAL; + + return rc; +} + +/* + * Emulate write access to NS16550 register. + */ +static int ns16550_io_write( + struct vuart_ns16550 *vdev, uint8_t reg, uint32_t size, uint32_t *data) +{ + int rc; + + switch ( size ) + { + case 1: + rc = ns16550_io_write8(vdev, reg, (uint8_t *)data); + break; + + case 2: + rc = ns16550_io_write16(vdev, reg, (uint16_t *)data); + break; + + default: + rc = -EINVAL; + break; + } + + return rc; +} + +/* + * Emulate 8-bit read access to NS16550 register. + */ +static int ns16550_io_read8( + struct vuart_ns16550 *vdev, uint32_t reg, uint8_t *data) +{ + uint8_t *regs = vdev->regs; + uint8_t val = 0xFFU; + int rc = 0; + + if ( ns16550_dlab_get(vdev) && (reg == UART_DLL || reg == UART_DLM) ) + val = regs[NS16550_REGS_NUM + reg]; + else { + switch ( reg ) + { + case UART_RBR: + /* NB: do not forget to clear overrun condition */ + regs[UART_LSR] &= ~UART_LSR_OE; + + rc = ns16550_fifo_rx_getchar(vdev); + if ( rc >= 0 ) + val = (uint8_t)rc; + + break; + + case UART_IER: + val = regs[UART_IER]; + break; + + case UART_IIR: /* RO */ + val = ns16550_iir_get(vdev); + + /* NB: clear IIR scratch location */ + if ( val & UART_IIR_THR ) + regs[NS16550_REGS_NUM + UART_IIR] &= ~UART_IIR_THR; + + break; + + case UART_LCR: + val = regs[UART_LCR]; + break; + + case UART_MCR: + val = regs[UART_MCR]; + break; + + case UART_LSR: + val = regs[UART_LSR] | UART_LSR_THRE | UART_LSR_TEMT; + if ( ns16550_fifo_rx_empty(vdev) ) + val &= ~UART_LSR_DR; + else + val |= UART_LSR_DR; + + regs[UART_LSR] = val & ~UART_LSR_MASK; + + break; + + case UART_MSR: + val = regs[UART_MSR]; + regs[UART_MSR] &= ~UART_MSR_CHANGE; + break; + + case UART_SCR: + val = regs[UART_SCR]; + break; + + default: + rc = -EINVAL; + break; + } + + ns16550_irq_check(vdev); + } + + *data = val; + + return rc; +} + +/* + * Emulate 16-bit read access to NS16550 register. + */ +static int ns16550_io_read16( + struct vuart_ns16550 *vdev, uint32_t reg, uint16_t *data) +{ + uint16_t val = 0xFFFFU; + int rc = -EINVAL; + + if ( ns16550_dlab_get(vdev) && reg == UART_DLL ) + { + val = vdev->regs[NS16550_REGS_NUM + UART_DLM] << 8 | + vdev->regs[NS16550_REGS_NUM + UART_DLL]; + rc = 0; + } + + *data = val; + + return rc; +} + +/* + * Emulate read access to NS16550 register. + */ +static int ns16550_io_read( + struct vuart_ns16550 *vdev, uint8_t reg, uint32_t size, uint32_t *data) +{ + int rc; + + switch ( size ) + { + case 1: + rc = ns16550_io_read8(vdev, reg, (uint8_t *)data); + break; + + case 2: + rc = ns16550_io_read16(vdev, reg, (uint16_t *)data); + break; + + default: + *data = 0xFFFFFFFFU; + rc = -EINVAL; + break; + } + + return rc; +} + +static void cf_check ns16550_dump(struct domain *d) +{ + struct vuart_ns16550 *vdev = d->arch.hvm.vuart; + const struct xencons_interface *cons; + const uint8_t *regs; + + if ( !vdev ) + return; + + /* Allow printing state in case of a deadlock. */ + if ( !spin_trylock(&vdev->lock) ) + return; + + cons = &vdev->cons; + regs = &vdev->regs[0]; + + printk("Virtual " pr_prefix " (%s) I/O port 0x%04"PRIx64" IRQ#%d owner %pd\n", + vdev->name, vdev->io_addr, vdev->irq, vdev->owner); + + printk(" RX FIFO size %ld in_prod %d in_cons %d used %d\n", + ARRAY_SIZE(cons->in), cons->in_prod, cons->in_cons, + cons->in_prod - cons->in_cons); + + printk(" TX FIFO size %ld out_prod %d out_cons %d used %d\n", + ARRAY_SIZE(cons->out), cons->out_prod, cons->out_cons, + cons->out_prod - cons->out_cons); + + printk(" %02"PRIx8" RBR %02"PRIx8" THR %02"PRIx8" DLL %02"PRIx8" DLM %02"PRIx8"\n", + UART_RBR, + cons->in[MASK_XENCONS_IDX(cons->in_prod, cons)], + cons->out[MASK_XENCONS_IDX(cons->out_prod, cons)], + regs[NS16550_REGS_NUM + UART_DLL], + regs[NS16550_REGS_NUM + UART_DLM]); + + printk(" %02"PRIx8" IER %02"PRIx8"\n", UART_IER, regs[UART_IER]); + + printk(" %02"PRIx8" FCR %02"PRIx8" IIR %02"PRIx8"\n", + UART_FCR, regs[UART_FCR], ns16550_iir_get(vdev)); + + printk(" %02"PRIx8" LCR %02"PRIx8"\n", UART_LCR, regs[UART_LCR]); + printk(" %02"PRIx8" MCR %02"PRIx8"\n", UART_MCR, regs[UART_MCR]); + printk(" %02"PRIx8" LSR %02"PRIx8"\n", UART_LSR, regs[UART_LSR]); + printk(" %02"PRIx8" MSR %02"PRIx8"\n", UART_MSR, regs[UART_MSR]); + printk(" %02"PRIx8" SCR %02"PRIx8"\n", UART_SCR, regs[UART_SCR]); + + spin_unlock(&vdev->lock); +} + +/* + * Emulate I/O access to NS16550 register. + * Note, emulation always returns X86EMUL_OKAY, once I/O port trap is enabled. + */ +static int cf_check ns16550_io_handle( + int dir, unsigned int addr, unsigned int size, uint32_t *data) +{ +#define op(dir) (((dir) == IOREQ_WRITE) ? 'W' : 'R') + struct domain *d = rcu_lock_current_domain(); + struct vuart_ns16550 *vdev = d->arch.hvm.vuart; + uint32_t reg; + unsigned dlab; + int rc; + + if ( !vdev ) + { + pr_err("%s: %c io 0x%04x %d: not initialized\n", + vdev->name, op(dir), addr, size); + + ASSERT_UNREACHABLE(); + goto out; + } + + if ( d != vdev->owner ) + { + pr_err("%s: %c io 0x%04x %d: does not match current domain %pv\n", + vdev->name, op(dir), addr, size, d); + + ASSERT_UNREACHABLE(); + goto out; + } + + reg = addr - vdev->io_addr; + if ( !IS_ALIGNED(reg, size) ) + { + pr_err("%s: %c 0x%04x %d: unaligned access\n", + vdev->name, op(dir), addr, size); + goto out; + } + + dlab = ns16550_dlab_get(vdev); + if ( reg >= NS16550_REGS_NUM ) + { + pr_err("%s: %c io 0x%04x %d: DLAB=%d %02"PRIx32" 0x%08"PRIx32": not implemented\n", + vdev->name, op(dir), addr, size, + dlab, reg, *data); + goto out; + } + + spin_lock(&vdev->lock); + + if ( dir == IOREQ_WRITE ) + { + pr_debug("%s: %c 0x%04x %d: DLAB=%d %02"PRIx32" 0x%08"PRIx32"\n", + vdev->name, op(dir), addr, size, + dlab, reg, *data); + rc = ns16550_io_write(vdev, reg, size, data); + } + else + { + rc = ns16550_io_read(vdev, reg, size, data); + pr_debug("%s: %c 0x%04x %d: DLAB=%d %02"PRIx32" 0x%08"PRIx32"\n", + vdev->name, op(dir), addr, size, + dlab, reg, *data); + } + if ( rc < 0 ) + pr_err("%s: %c 0x%04x %d: DLAB=%d %02"PRIx32" x%08"PRIx32": unsupported access\n", + vdev->name, op(dir), addr, size, + dlab, reg, *data); + + spin_unlock(&vdev->lock); +#ifdef CONFIG_VUART_NS16550_DEBUG + ns16550_dump(d); +#endif + +out: + rcu_unlock_domain(d); + + return X86EMUL_OKAY; +#undef op +} + +static int cf_check ns16550_init(struct domain *d, + struct virtdev_uart_params *params) +{ + const struct virtdev_desc *desc = &x86_pc_uarts[X86_PC_UART_IDX]; + const struct resource *r = desc->res; + const uint16_t divisor = (UART_CLOCK_HZ / 115200) >> 4; + struct vuart_ns16550 *vdev; + + BUG_ON(d->arch.hvm.vuart); + + vdev = xvzalloc(typeof(*vdev)); + if ( !vdev ) + return -ENOMEM; + + for_each_resource(r) + { + if ( r->type & IORESOURCE_IO ) + { + register_portio_handler(d, r->addr, r->size, ns16550_io_handle); + + /* Used to assert I/O port handler */ + vdev->io_addr = r->addr; + vdev->io_size = r->size; + } + else if ( r->type & IORESOURCE_IRQ ) + /* "Claim" virtual IRQ; assumes no ISA-device IRQ sharing */ + vdev->irq = r->addr; + else + ASSERT_UNREACHABLE(); + } + + vdev->owner = d; + vdev->name = desc->name; + + /* NB: report 115200 baud rate */ + vdev->regs[NS16550_REGS_NUM + UART_DLL] = divisor & 0xFFU; + vdev->regs[NS16550_REGS_NUM + UART_DLM] = (divisor >> 8) & 0xFFU; + + spin_lock_init(&vdev->lock); + hvm_isa_irq_deassert(vdev->owner, vdev->irq); + + d->arch.hvm.vuart = vdev; + + return 0; +} + +static void cf_check ns16550_exit(struct domain *d) +{ + struct vuart_ns16550 *vdev = d->arch.hvm.vuart; + + if ( vdev ) + { + spin_lock(&vdev->lock); + ns16550_fifo_tx_flush(vdev); + spin_unlock(&vdev->lock); + } + + XFREE(d->arch.hvm.vuart); +} + +static int cf_check ns16550_putchar(struct domain *d, char ch) +{ + struct vuart_ns16550 *vdev = d->arch.hvm.vuart; + uint8_t *regs; + uint8_t dlab; + int rc; + + ASSERT(d == vdev->owner); + if ( !vdev ) + return -ENODEV; + + spin_lock(&vdev->lock); + + dlab = ns16550_dlab_get(vdev); + regs = vdev->regs; + + if ( dlab ) + { + pr_debug("%s: THR/RBR access disabled: DLAB=1\n", vdev->name); + rc = -EBUSY; + } + else if ( regs[UART_MCR] & UART_MCR_LOOP ) + { + pr_debug("%s: THR/RBR access disabled: loopback mode\n", vdev->name); + rc = -EBUSY; + } + else + { + uint8_t val = 0; + + rc = ns16550_fifo_rx_putchar(vdev, ch); + if ( rc == -ENOSPC ) + val |= UART_LSR_OE; + + /* NB: UART_LSR_DR is also set when UART_LSR is accessed. */ + regs[UART_LSR] |= UART_LSR_DR | val; + + /* + * Echo the user input on Xen console. + * NB: use 'console_timestamps=none' to disable Xen timestamps. + */ + printk("%c", ch); + + /* FIXME: check FCR when to fire an interrupt */ + ns16550_irq_check(vdev); + } + + spin_unlock(&vdev->lock); +#ifdef CONFIG_VUART_NS16550_DEBUG + ns16550_dump(d); +#endif + + return rc; +} + +VIRTDEV_UART_REGISTER(ns16550); + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/include/asm/hvm/domain.h b/xen/arch/x86/include/asm/hvm/domain.h index 333501d5f2ac01676646b9b277b551f06d43c3a5..61f3c5ceec3b6753db657ce0027e89472dc52e1e 100644 --- a/xen/arch/x86/include/asm/hvm/domain.h +++ b/xen/arch/x86/include/asm/hvm/domain.h @@ -149,6 +149,10 @@ struct hvm_domain { #ifdef CONFIG_MEM_SHARING struct mem_sharing_domain mem_sharing; #endif + +#ifdef CONFIG_HAS_VUART + void *vuart; /* Virtual UART handle. */ +#endif }; #endif /* __ASM_X86_HVM_DOMAIN_H__ */ diff --git a/xen/drivers/virtdev-uart.c b/xen/drivers/virtdev-uart.c index fe119e3e6e938957613b182cbef0a29bf67230d2..7011f7b5afa26ac93a71249a3b700eb9a385cccf 100644 --- a/xen/drivers/virtdev-uart.c +++ b/xen/drivers/virtdev-uart.c @@ -12,6 +12,9 @@ int virtdev_uart_init(struct domain *d, struct virtdev_uart_params *params) int rc; ASSERT(__start_virtdev_uart); +#if defined(__i386__) || defined(__x86_64__) + ASSERT(d->arch.emulation_flags & VIRTDEV_UART); +#endif rc = __start_virtdev_uart->init(d, params); if ( rc ) @@ -28,6 +31,9 @@ int virtdev_uart_init(struct domain *d, struct virtdev_uart_params *params) void virtdev_uart_exit(struct domain *d) { ASSERT(__start_virtdev_uart); +#if defined(__i386__) || defined(__x86_64__) + ASSERT(d->arch.emulation_flags & VIRTDEV_UART); +#endif __start_virtdev_uart->exit(d); diff --git a/xen/include/xen/resource.h b/xen/include/xen/resource.h index 4512658133defe8dc62d87192ffd19ad94b63c3b..bdd9df4ded632082c8db929787455bc1aea96e9f 100644 --- a/xen/include/xen/resource.h +++ b/xen/include/xen/resource.h @@ -31,4 +31,7 @@ struct resource { #define resource_size(res) ( (res)->size ) +#define for_each_resource(res) \ + for ( ; (res) && (res)->type != IORESOURCE_UNKNOWN; (res)++ ) + #endif /* XEN__RESOURCE_H */ From patchwork Sat Jan 4 01:58:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926052 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 0961BE77198 for ; Sat, 4 Jan 2025 02:00:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864803.1276123 (Exim 4.92) (envelope-from ) id 1tTtSq-0008Lw-Qa; Sat, 04 Jan 2025 02:00:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864803.1276123; Sat, 04 Jan 2025 02:00:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tTtSq-0008Kq-Mo; Sat, 04 Jan 2025 02:00:32 +0000 Received: by outflank-mailman (input) for mailman id 864803; Sat, 04 Jan 2025 02:00:31 +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 1tTtQq-0005Ax-Rr for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:28 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5ecc83d6-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:19 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id EF89D5C63FD; Sat, 4 Jan 2025 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 10C16C4CEDF; Sat, 4 Jan 2025 01:58:16 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A1DEE77198; Sat, 4 Jan 2025 01:58:16 +0000 (UTC) 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: 5ecc83d6-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955896; bh=QazlpyV6psPVJxq90As+1tifoHdIpFVbG/2MHr8OLBw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rrUY+R9cOymfLlpHjaW/5WWuCxfD+kpXYC19m42ZvsRMQZ2tbFy+4fYSjh5nSqOnF MDzhLmOF4r2vJ7RDUNmGK6VtIPT/hg4KdPr88fIMBe856PpMni/SavUUC54S3nkJBs 97FS/wNUVRx2tgQ1vGcEYa94L/MBlToRq/UBPie/kp0o1+MbhbziOfNzyw/ZGh1nbt JOYbyxh1Nd4J0vJdOyqnbN4DXALfEvFVeNk5zmBuE1GQ78H1amMI58APMUcbsvA9i3 L3BTJnHJ51Kt69qXsCFuWptoqB+r5EH9bPDjgq+9kesmPxxoW1k1JLeYnILzGBHpNH msPk4KNQTq6Yw== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:28 -0800 Subject: [PATCH v3 22/24] x86/hvm: enable NS16550-compatible UART emulator MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-22-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=5808; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=oTdotR5rgkOxF28AQvVxnepnVm1tE7cePzIJQgwAwTE=; b=++NBrOXcXTVJ8AvbN0dFDKCaPX+KTiZWc6kqg1YW8cHeVU5lsUi46ifTL7rphNL0TvW1CYQXH XrobXLlc2ALALwgiWl1M0BltoYkrxIKgEelLgp8WFdBQIdlCQDKzw1V X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Introduce new emulation flag for virtual UART on x86 and plumb it through domain creation code so NS16550 emulator is enabled properly. Virtual UART facility is enabled for HVM domains only. Enabling it for PVH domains requires some work, as vPIC is not enabled in PVH. Also, since feature is currently for debugging only, vUART facility is controlled build-time only and globally for all HVM domains. The toolstack cannot configure virtual UART yet. Signed-off-by: Denis Mukhin --- In PVH case, vUART asserts on vpic_irq_positive_edge() call while firing a virtual IRQ to the guest OS: [[ ... Assertion 'has_vpic(d)' failed at arch/x86/hvm/vpic.c:525 (XEN) [ 28.984923] ----[ Xen-4.20-unstable x86_64 debug=y Not tainted ]---- (XEN) [ 28.984925] CPU: 3 (XEN) [ 28.984926] RIP: e008:[] vpic_irq_positive_edge+0x98/0xc0 ... ]] --- --- tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + xen/arch/x86/domain.c | 10 ++++++++++ xen/arch/x86/include/asm/domain.h | 5 +++-- xen/include/public/virtdev.h | 6 ++++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml index 2690f9a92316b812ad3d3ff0e1c36823070adb4a..647239b3e55e88b00eb8e9773a5267894cbbae54 100644 --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -47,6 +47,7 @@ type x86_arch_emulation_flags = | X86_EMU_PIT | X86_EMU_USE_PIRQ | X86_EMU_VPCI + | X86_EMU_VUART type x86_arch_misc_flags = | X86_MSR_RELAXED diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.mli index febbe1f6ae3f10c5abe45eaa3c06a8a67d9ba268..4f5f64c786e83e8a0c3dd3cdb0460f7095de4a62 100644 --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -41,6 +41,7 @@ type x86_arch_emulation_flags = | X86_EMU_PIT | X86_EMU_USE_PIRQ | X86_EMU_VPCI + | X86_EMU_VUART type x86_arch_misc_flags = | X86_MSR_RELAXED diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 9669886ac95cbee27c9eb72b16386705b470e7b1..c1b15ddf664269ba63d0bcd8a974491a4ab3524f 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -752,6 +752,10 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) if ( is_hardware_domain(d) && emflags != (X86_EMU_VPCI | X86_EMU_LAPIC | X86_EMU_IOAPIC) ) return false; + + /* FIXME: remove once virtual UART is configurable via xl */ + emflags &= ~XEN_X86_EMU_VUART; + if ( !is_hardware_domain(d) && xen_emflags_allowable(emflags) != XEN_X86_EMU_BASELINE && emflags != X86_EMU_LAPIC ) @@ -804,6 +808,12 @@ int arch_domain_create(struct domain *d, emflags = config->arch.emulation_flags; + /* FIXME: enable virtual UART for all HVMs; must be configurable via xl */ + if ( IS_ENABLED(CONFIG_HAS_VUART) && is_hvm_domain(d) ) + emflags |= XEN_X86_EMU_VUART; + else + emflags &= ~XEN_X86_EMU_VUART; + if ( is_hardware_domain(d) && is_pv_domain(d) ) emflags |= XEN_X86_EMU_PIT; diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h index 2532616bca015d0aad9abc35e14948937ab39b8f..53d14881d94f888e72f7443159c1c278d15d05cb 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -485,7 +485,8 @@ struct arch_domain #define X86_EMU_VPCI 0 #endif -#define X86_EMU_PIT XEN_X86_EMU_PIT +#define X86_EMU_PIT XEN_X86_EMU_PIT +#define X86_EMU_VUART XEN_X86_EMU_VUART /* This must match XEN_X86_EMU_ALL in xen.h */ #define X86_EMU_ALL (X86_EMU_LAPIC | X86_EMU_HPET | \ @@ -493,7 +494,7 @@ struct arch_domain X86_EMU_IOAPIC | X86_EMU_PIC | \ X86_EMU_VGA | X86_EMU_IOMMU | \ X86_EMU_PIT | X86_EMU_USE_PIRQ | \ - X86_EMU_VPCI) + X86_EMU_VPCI | X86_EMU_VUART) #define has_vlapic(d) (!!((d)->arch.emulation_flags & X86_EMU_LAPIC)) #define has_vhpet(d) (!!((d)->arch.emulation_flags & X86_EMU_HPET)) diff --git a/xen/include/public/virtdev.h b/xen/include/public/virtdev.h index 36931e0d679cedadd4212f34142d7c3f00cd3389..bcc71b519310e58d6094fadded14a3e0ee6bfd7e 100644 --- a/xen/include/public/virtdev.h +++ b/xen/include/public/virtdev.h @@ -32,17 +32,19 @@ enum { #define XEN_X86_EMU_PIT VIRTDEV_PIT #define XEN_X86_EMU_USE_PIRQ VIRTDEV_PIRQ #define XEN_X86_EMU_VPCI VIRTDEV_PCI +#define XEN_X86_EMU_VUART VIRTDEV_UART #define XEN_X86_EMU_ALL (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET | \ XEN_X86_EMU_PM | XEN_X86_EMU_RTC | \ XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC | \ XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \ XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ - XEN_X86_EMU_VPCI) + XEN_X86_EMU_VPCI | XEN_X86_EMU_VUART) /* PIRQ (HVM) feature is user-selectable (libxl). */ #define XEN_X86_EMU_OPTIONAL (XEN_X86_EMU_VPCI | \ - XEN_X86_EMU_USE_PIRQ) + XEN_X86_EMU_USE_PIRQ | \ + XEN_X86_EMU_VUART) #define XEN_X86_EMU_BASELINE xen_emflags_allowable(XEN_X86_EMU_ALL) From patchwork Sat Jan 4 01:58:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926055 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 DB520E77188 for ; Sat, 4 Jan 2025 02:01:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864878.1276158 (Exim 4.92) (envelope-from ) id 1tTtTL-0002vV-UQ; Sat, 04 Jan 2025 02:01:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864878.1276158; Sat, 04 Jan 2025 02:01: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 1tTtTL-0002vL-QM; Sat, 04 Jan 2025 02:01:03 +0000 Received: by outflank-mailman (input) for mailman id 864878; Sat, 04 Jan 2025 02:01:03 +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 1tTtQu-0005Ax-T7 for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:32 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5ee09da4-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:20 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0898E5C6411; Sat, 4 Jan 2025 01:57:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 1E314C4CEE4; Sat, 4 Jan 2025 01:58:16 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16F74E77188; Sat, 4 Jan 2025 01:58:16 +0000 (UTC) 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: 5ee09da4-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955896; bh=C4I0w8+5EC1wc6Fr7dK8Qf/iMDwJkx3ZOmN4HyH2Ud0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=QJCbct/KweF+9rRQW1qw0dCoTySabWk30VD93NOmGRcJwjxOs/qU3zDrrI5flFa8Y Mz1yRRiByk6k8UEepfCk2mtYwrCdkTBl/+XWqMulhJJG1SRjz/JE1xZo6t40bg6ieS H/Kq+OVSlY1B/Kx579lbK2SNFu/1KVUVpYe6DePm4lgkx3xbsGXs1I8+ywepXNJ3L1 9k9EDZ4sTu/+x/vpKaw/UW2jpGC4krcycctf/ZEXwqzqK/pSbWGsgz/YGuc8DMYx6v efXgKkn7P0Onq9JciB8/ijAsIs6rLSTGIprOCKN+JG0eMN7BkVvUNFhnzSnKdwdOy6 H9p+9Z/fl0m+g== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:29 -0800 Subject: [PATCH v3 23/24] docs/misc: update console documentation MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-23-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=5686; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=APQcmog0xQYM3EBoFVE5ETu0ersksioDS4x/FBTt9bk=; b=oqKShhLqX/avc2rWyyCrDQH9JFfddXKvzHL7pbNhO2CYyq/vCCa+kigFa1VIsi9tjZPicHGI0 qLaOcxQIb1yCMyyC3wkHVL1ZUfcbYFYPKIe6Rd7bLRYo4ErAcm2Phtz X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin Minor update related to virtual UART support. Also: s/pv/PV/g s/hvm/HVM/g Signed-off-by: Denis Mukhin --- docs/misc/console.txt | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/docs/misc/console.txt b/docs/misc/console.txt index 4e180f88ba1312d8fcc47d27622ec347d387ce12..7840729b0c95d9c4ea5295f17ce77c04177f48a5 100644 --- a/docs/misc/console.txt +++ b/docs/misc/console.txt @@ -4,11 +4,11 @@ Xen PV Console notes stefano.stabellini@eu.citrix.com -Xen traditionally provided a single pv console to pv guests, storing the +Xen traditionally provided a single PV console to PV guests, storing the relevant information in xenstore under /local/domain/$DOMID/console. -Now many years after the introduction of the pv console we have -multiple pv consoles support for pv and hvm guests; multiple pv +Now many years after the introduction of the PV console we have +multiple PV consoles support for PV and HVM guests; multiple PV console backends (qemu and xenconsoled, see limitations below) and emulated serial cards too. @@ -103,48 +103,50 @@ The supported values are only xenconsoled or ioemu; xenconsoled has several limitations: it can only be used for the first PV or virtual UART console and it can only connect to a pty. -Emulated serials are provided by qemu-dm only to hvm guests; the number -of emulated serials depends on how many "-serial" command line options -are given to qemu. The output of a serial is specified as argument to -the -serial command line option to qemu. Qemu writes the tty name to -xenstore in the following path: +Emulated serials are provided to HVM guests by qemu-dm or in-hypervisor UART +emulator (Xen needs to be re-compiled). + +In qemu-dm case, the number of emulated serials depends on how many "-serial" +command line options are given to qemu. The output of a serial is specified as +argument to the -serial command line option to qemu. Qemu writes the tty name +to xenstore in the following path: /local/domain/$DOMID/serial/$SERIAL_NUM/tty xenconsole is the tool to connect to a PV or virtual UART console or an emulated serial that has a pty as output. Xenconsole takes a domid as -parameter plus an optional console type (pv for PV consoles, vuart for -virtual UART or serial for emulated serials) and console number. +parameter plus an optional console type ('pv' for PV consoles, 'vuart' for +virtual UART or 'serial' for emulated serials) and console number. Depending on the type and console number, xenconsole will look for the tty node in different xenstore paths, as described above. If the user doesn't -specify the console type xenconsole will try to guess: if the guest is a pv -guest it defaults to PV console, if the guest is an hvm guest it defaults to +specify the console type xenconsole will try to guess: if the guest is a PV +guest it defaults to PV console, if the guest is an HVM guest it defaults to emulated serial. -By default xl creates a pv console for hvm guests, plus an emulated +By default xl creates a PV console for HVM guests, plus an emulated serial if the user specified 'serial = "pty"' in the VM config file. -Considering that xenconsole defaults to emulated serials for hvm guests, +Considering that xenconsole defaults to emulated serials for HVM guests, executing xl create -c "domain" causes xenconsole to attach to the emulated serial tty. This is most probably what the user wanted because -currently no bootloaders support xen pv consoles so the only way to +currently no bootloaders support xen PV consoles so the only way to interact with a bootloader like grub over a console is to use the emulated serial. -However the pv console is still easy to use with Linux PV on HVM guests: +However the PV console is still easy to use with Linux PV on HVM guests: the user just need to pass "console=hvc0" to the kernel command line and then execute "xl console -t pv " to connect to it. When using stubdoms the serial cards are still emulated by qemu (this time running in the stubdom), the number of serial cards and where the output goes is still specified using qemu command line options. -The difference is that for each emulated serial card there must be a pv +The difference is that for each emulated serial card there must be a PV console connection between the stubdom and dom0 to export the serial -output from the stubdom to dom0. The pv console backend for stubdom's pv -consoles is always ioemu because multiple pv consoles support is a -requirement in this case, considering that minios has its own pv console -too. In order to simplify the setup when using stubdoms the hvm guest -can only have one pv console with xenstored as backend (the stubdom -could provide pv console backends to the hvm guest but then it would -need another pv console connection for each console backend to export +output from the stubdom to dom0. The PV console backend for stubdom's PV +consoles is always ioemu because multiple PV consoles support is a +requirement in this case, considering that minios has its own PV console +too. In order to simplify the setup when using stubdoms the HVM guest +can only have one PV console with xenstored as backend (the stubdom +could provide PV console backends to the HVM guest but then it would +need another PV console connection for each console backend to export the pty to dom0). The xenconsole program supports a very simple protocol to notify parent about From patchwork Sat Jan 4 01:58:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin via B4 Relay X-Patchwork-Id: 13926041 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 6E802E7719F for ; Sat, 4 Jan 2025 01:58:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.864712.1276007 (Exim 4.92) (envelope-from ) id 1tTtQo-0006kd-I2; Sat, 04 Jan 2025 01:58:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 864712.1276007; Sat, 04 Jan 2025 01:58: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 1tTtQn-0006iI-Sr; Sat, 04 Jan 2025 01:58:25 +0000 Received: by outflank-mailman (input) for mailman id 864712; Sat, 04 Jan 2025 01:58:23 +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 1tTtQk-0005Ax-QO for xen-devel@lists.xenproject.org; Sat, 04 Jan 2025 01:58:22 +0000 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5df4cd6d-ca3f-11ef-a0de-8be0dac302b0; Sat, 04 Jan 2025 02:58:18 +0100 (CET) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 3C02AA411F0; Sat, 4 Jan 2025 01:56:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 2BCF9C4CEDD; Sat, 4 Jan 2025 01:58:16 +0000 (UTC) Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25896E7719A; Sat, 4 Jan 2025 01:58:16 +0000 (UTC) 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: 5df4cd6d-ca3f-11ef-a0de-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735955896; bh=2mHkPjXf6NjW+LO0bsnwT2e081y81crKinFFDfZUM/8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=b6CWmi2eXFjuj3dBJUQGQi2DY7mfzc2/rU/a5xqRt0c1R2D80+nzRD06J9oxLgaph fb20RRMaWbnKCm+6gMinN79bcDsQ2RteEJmXcDS0oehGj6G50iWSsFypAlBqnHYUeF ApZBfLLD8uDKdB2evAiGjWcfeWPBY6XRP2lTBPivxGMEcijxN/MUone536Dp6pb0Ir /43eUjBlMg/Dc/GA6Wy6UmByKg0YvnnRglOizjUOhi5b7CZqLY9ooyV7vPmPM8n077 tamcnloB59wF4hNhiu17UeeST4W7OuSO+/VhoNJKtFt9zVMVhJdVz7DKTZc3B4N9fm S6GtCSn6tx2mA== From: Denis Mukhin via B4 Relay Date: Fri, 03 Jan 2025 17:58:30 -0800 Subject: [PATCH v3 24/24] xen/console: unify printout behavior for UART emulators MIME-Version: 1.0 Message-Id: <20250103-vuart-ns8250-v3-v1-24-c5d36b31d66c@ford.com> References: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> In-Reply-To: <20250103-vuart-ns8250-v3-v1-0-c5d36b31d66c@ford.com> To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Michal Orzel , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Denis Mukhin X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735955892; l=6584; i=dmukhin@ford.com; s=20241125; h=from:subject:message-id; bh=ht6Wazj1keo9tj+WEpSpwlWS9w1mUW+HbPE+9o8P0XA=; b=a9v2A+pEGC73S64duP7Evt85PvPWNZaAkUU7eN+j8YqqbMH0bZXfZJ28pMx0ePRJsPx1uTi6w Bw2REOs04J5AizYVsUfSAOcGa9KX2lR3rudN3+aJ/KzFXDA+5IQITHi X-Developer-Key: i=dmukhin@ford.com; a=ed25519; pk=SsDZ9p39s0fqcpUKQuqKqrbn0rq6EtEAClvpOpzx6+U= X-Endpoint-Received: by B4 Relay for dmukhin@ford.com/20241125 with auth_id=287 X-Original-From: Denis Mukhin Reply-To: dmukhin@ford.com From: Denis Mukhin If virtual UART prints on the physical console, the behavior is updated to: - no prefix for Dom0 output; - DOM$NUM for DomUs when not in focus, otherwise no prefix. Introduce printk_noprefix() for convenient printouts which skip '(XEN)' prefix on the physical console. This is needed for the case when physical console is owned by a domain with in-hypervisor UART emulation enabled. Add printk_noprefix() to exception into ECLAIR deviations list for rule MC3A2.R17.1. Use guest_printk() in all current in-hypervisor UART emulators. That aligns behavior with debug I/O port 0xe9 handler in x86 port and slightly improves the logging since guest_printk() already prints the domain ID. Signed-off-by: Denis Mukhin --- automation/eclair_analysis/ECLAIR/deviations.ecl | 1 + xen/arch/arm/vpl011.c | 6 +++--- xen/arch/arm/vuart.c | 8 +++++++- xen/arch/x86/hvm/vuart-ns16550.c | 7 +++++-- xen/drivers/char/console.c | 8 ++++++++ xen/include/xen/lib.h | 3 +++ 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl index ae25eeb76ac938588d16c9b4f9f116ddcaf97956..d94a8bc59d0b562cc285bb236dbac41a151042ac 100644 --- a/automation/eclair_analysis/ECLAIR/deviations.ecl +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl @@ -523,6 +523,7 @@ safe." -config=MC3A2.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(panic)&&kind(function))))"} -config=MC3A2.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(elf_call_log_callback)&&kind(function))))"} -config=MC3A2.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(vprintk_common)&&kind(function))))"} +-config=MC3A2.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(printk_noprefix)&&kind(function))))"} -config=MC3A2.R17.1,macros+={hide , "^va_(arg|start|copy|end)$"} -doc_end diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index efe77c13007716d0e0d70ab5ccf5f94268d5b693..ab85893174e76c5ec4350931a030760c9e0331b0 100644 --- a/xen/arch/arm/vpl011.c +++ b/xen/arch/arm/vpl011.c @@ -89,7 +89,7 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data) { if ( intf->out_prod == 1 ) { - printk("%c", data); + printk_noprefix("%c", data); intf->out_prod = 0; } else @@ -97,7 +97,7 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data) if ( data != '\n' ) intf->out[intf->out_prod++] = '\n'; intf->out[intf->out_prod++] = '\0'; - printk("%s", intf->out); + printk_noprefix("%s", intf->out); intf->out_prod = 0; } } @@ -109,7 +109,7 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data) if ( data != '\n' ) intf->out[intf->out_prod++] = '\n'; intf->out[intf->out_prod++] = '\0'; - printk("DOM%u: %s", d->domain_id, intf->out); + guest_printk(d, "%s", intf->out); intf->out_prod = 0; } } diff --git a/xen/arch/arm/vuart.c b/xen/arch/arm/vuart.c index 03366da17a604502f6e0afb45e8824c9d7cfa3dd..0e0fba344b68760463e894dc43133121bccbd960 100644 --- a/xen/arch/arm/vuart.c +++ b/xen/arch/arm/vuart.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "vuart.h" @@ -87,7 +88,12 @@ static void hwdom_vuart_print_char(struct vcpu *v, char c) if ( c != '\n' ) uart->buf[uart->idx++] = '\n'; uart->buf[uart->idx] = '\0'; - printk(XENLOG_G_DEBUG "DOM%u: %s", d->domain_id, uart->buf); + + if ( d->domain_id == console_get_owner() ) + printk_noprefix("%s", uart->buf); + else + guest_printk(d, "%s", uart->buf); + uart->idx = 0; } spin_unlock(&uart->lock); diff --git a/xen/arch/x86/hvm/vuart-ns16550.c b/xen/arch/x86/hvm/vuart-ns16550.c index d0c19f53399bd8241f54d2fe2716e62046b8e59d..67cc7e9acc396a2f4346aebeef85d4b96c0d0e3f 100644 --- a/xen/arch/x86/hvm/vuart-ns16550.c +++ b/xen/arch/x86/hvm/vuart-ns16550.c @@ -35,6 +35,7 @@ #include /* max_init_domid */ #include #include +#include #include #include #include @@ -899,10 +900,12 @@ static int cf_check ns16550_putchar(struct domain *d, char ch) regs[UART_LSR] |= UART_LSR_DR | val; /* - * Echo the user input on Xen console. + * Echo the user input on Xen console iff Xen console input is owned + * by NS16550 domain. * NB: use 'console_timestamps=none' to disable Xen timestamps. */ - printk("%c", ch); + if ( d->domain_id == console_get_owner() ) + printk_noprefix("%c", ch); /* FIXME: check FCR when to fire an interrupt */ ns16550_irq_check(vdev); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 96375067164980a138b1a93161712c0758f4f7fe..64abde479305910d1a962e68d5c1f0c25000cb3d 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1026,6 +1026,14 @@ void printk(const char *fmt, ...) va_end(args); } +void printk_noprefix(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintk_common("", fmt, args); + va_end(args); +} + void guest_printk(const struct domain *d, const char *fmt, ...) { va_list args; diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index 81b722ea3e801e9089aaf8758249feb3a758c4f7..e55b8fac8d4d121262a56948638d83f1146e5a06 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -61,6 +61,9 @@ debugtrace_printk(const char *fmt, ...) {} extern void printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2), cold)); +extern void printk_noprefix(const char *fmt, ...) + __attribute__ ((format (printf, 1, 2), cold)); + #define printk_once(fmt, args...) \ ({ \ static bool __read_mostly once_; \