From patchwork Tue Feb 18 08:31:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 13979258 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 CD5ABC02198 for ; Tue, 18 Feb 2025 08:32:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.891134.1300218 (Exim 4.92) (envelope-from ) id 1tkJ1Q-0000wX-ND; Tue, 18 Feb 2025 08:32:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 891134.1300218; Tue, 18 Feb 2025 08:32:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tkJ1Q-0000wQ-KG; Tue, 18 Feb 2025 08:32:04 +0000 Received: by outflank-mailman (input) for mailman id 891134; Tue, 18 Feb 2025 08:32:03 +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 1tkJ1O-0000wJ-54 for xen-devel@lists.xenproject.org; Tue, 18 Feb 2025 08:32:03 +0000 Received: from mail-10628.protonmail.ch (mail-10628.protonmail.ch [79.135.106.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d1ed3c8e-edd2-11ef-9896-31a8f345e629; Tue, 18 Feb 2025 09:31:59 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d1ed3c8e-edd2-11ef-9896-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=qa7lmzhflrgb3lcnf443tqr4sq.protonmail; t=1739867518; x=1740126718; bh=gerNu6CMr9u8/WvLNlYmlhDtV192ZjUBtdFRXO3fCug=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=dHZUq+n4nLYGKk+0dD8sOeD7twOOSlqUDJDpCXOcSvsNaYsd1PYDfNxlB6ARj3Nsu QJ1h/ueZ7f4fGnNR5taXei7nvxv7r7hoxVXTgJ+89MPb8YFERkcufmwp2KfCPeJ/g0 eVrfK/z/LzkKUrZKJxnEAvrJslheZSv8TI4ThcMtc9EsHOqSgSPdxAWzIvRrCs8zzS 8YFdHZmyFwazmgxMMJP8N1tZ5ZG6m0KO6HeynaJDAxck1AlPnl4pm+HjG3zWa4uR8c o2C86dcoqVusaSGkeHpnnlDsxo06FeF+tFZLEJ7KM52lwbV1puRgk+1z1HeigUTRu3 LBrnLnoiIHe3A== Date: Tue, 18 Feb 2025 08:31:49 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org, dmukhin@ford.com Subject: [PATCH] xen/console: introduce console_{get,put}_domain() Message-ID: <20250218083048.596012-1-dmkhn@proton.me> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: a378a0ab6d8bba07b7ffea7e89c659563cd7b5c4 MIME-Version: 1.0 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. The new calls used in __serial_rx(), which also fixed console forwarding to late hardware domains which run with domain IDs different from 0. Signed-off-by: Denis Mukhin Reviewed-by: Jan Beulich Acked-by: Stefano Stabellini --- Link to the original patch: https://lore.kernel.org/xen-devel/20250103-vuart-ns8250-v3-v1-4-c5d36b31d66c@ford.com/ --- xen/arch/arm/vpl011.c | 6 ++--- xen/drivers/char/console.c | 53 +++++++++++++++++++------------------- xen/include/xen/console.h | 3 ++- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/xen/arch/arm/vpl011.c b/xen/arch/arm/vpl011.c index c72f3778bf..66047bf33c 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 2e23910dfa..992b37962e 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -474,15 +474,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) { @@ -528,12 +531,18 @@ static void switch_serial_input(void) static void __serial_rx(char c) { - switch ( console_rx ) - { - case 0: + struct domain *d; + int rc = 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. @@ -546,31 +555,23 @@ 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 ) - { - int rc = vpl011_rx_char_xen(d, c); - if ( rc ) - guest_printk(d, XENLOG_G_WARNING - "failed to process console input: %d\n", rc); - 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 ) consoled_guest_tx(c); #endif + + if ( rc ) + guest_printk(d, XENLOG_G_WARNING + "failed to process console input: %d\n", 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 c4650231be..83cbc9fbda 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -32,7 +32,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.