From patchwork Sat Feb 22 00:26:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 13986458 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 34827C021B3 for ; Sat, 22 Feb 2025 00:26:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.894722.1303437 (Exim 4.92) (envelope-from ) id 1tldLm-0001ks-El; Sat, 22 Feb 2025 00:26:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 894722.1303437; Sat, 22 Feb 2025 00:26: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 1tldLm-0001kl-C5; Sat, 22 Feb 2025 00:26:34 +0000 Received: by outflank-mailman (input) for mailman id 894722; Sat, 22 Feb 2025 00:26:33 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tldLk-0001kf-Un for xen-devel@lists.xenproject.org; Sat, 22 Feb 2025 00:26:33 +0000 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a8b05750-f0b3-11ef-9aaa-95dc52dad729; Sat, 22 Feb 2025 01:26:29 +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: a8b05750-f0b3-11ef-9aaa-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1740183988; x=1740443188; bh=tRdPIW1FjsHSNc5Xmw1ilCkq3YhqjA3RMyWNbwiyEEM=; 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=SJIO8phwNXLLidUPgyxoEsRt4H+ATx22c7dtWkmHkOGoy8yz3fZXAZMqTbLrRwFH5 8FjoRzGTjZyb8z2Ore0ZWy9TnYUVjFipKrmgr+WlMZBXF7XEkw5xM1B/JfaaDGonji wQwy/tT3ip4+Yr/QEocJ/eBSX2n1MUm2IwKOkO2Yxvy4s3wQG1ldDMj3oLd4TWWaA6 /sJBqrmewLFMrMFIPMm7nDQAbu2o2A0Q5u5IEQrHAcmjywa6VFEIDSUc2Roif0CqJL 51iMO59avVELqlCo2n59BTw+hWpT8mVBDBe/hZiXfqFGUX942NdHFgW9bJFW5hgOJK cp5j6jb0yCWJw== Date: Sat, 22 Feb 2025 00:26:21 +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/consoled: clean up console handling for pv_shim Message-ID: <20250222002520.2482334-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 52e55e5ece72d3e50bf1175ea7cc67bb2cd44936 MIME-Version: 1.0 There are few places which check pv_shim console under CONFIG_PV_SHIM or CONFIG_X86 in xen console driver. Instead of #ifdef-ing, use new consoled_is_enabled() in switch_serial_input() and __serial_rx() (where pv_shim condition is now detected correctly). Signature of consoled_guest_{rx,tx} has changed so the errors can be logged on the callsites. Signed-off-by: Denis Mukhin --- xen/arch/x86/pv/shim.c | 3 +-- xen/drivers/char/console.c | 15 ++++++--------- xen/drivers/char/consoled.c | 17 +++++++++++++---- xen/include/xen/consoled.h | 32 +++++++++++++++++++++++++++----- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index b9c034ccff..cbc2e3fced 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -605,8 +605,7 @@ long pv_shim_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) if ( pv_console && send.port == pv_console_evtchn() ) { - consoled_guest_rx(); - rc = 0; + rc = consoled_guest_rx(); } else rc = xen_hypercall_event_channel_op(EVTCHNOP_send, &send); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 992b37962e..c207fd8704 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -32,9 +32,9 @@ #include #include #include +#include #ifdef CONFIG_X86 -#include #include #endif #ifdef CONFIG_SBSA_VUART_CONSOLE @@ -507,11 +507,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 ) @@ -562,13 +560,12 @@ 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 ) - guest_printk(d, XENLOG_G_WARNING + guest_printk(d, XENLOG_WARNING "failed to process console input: %d\n", rc); console_put_domain(d); diff --git a/xen/drivers/char/consoled.c b/xen/drivers/char/consoled.c index b415b632ce..8704ec251e 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 bd7ab6329e..52a1358bea 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 -ENODEV; +} + +static inline int consoled_guest_tx(char c) +{ + ASSERT_UNREACHABLE(); + return -ENODEV; +} + +#define consoled_is_enabled() (false) + +#endif /* CONFIG_PV_SHIM */ + +#endif /* XEN__CONSOLED_H */ /* * Local variables: * mode: C