From patchwork Fri Feb 7 00:58:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 13964155 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 0A61DC02194 for ; Fri, 7 Feb 2025 00:59:01 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.883220.1293268 (Exim 4.92) (envelope-from ) id 1tgChb-0003b2-Qu; Fri, 07 Feb 2025 00:58:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 883220.1293268; Fri, 07 Feb 2025 00:58:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tgChb-0003av-OM; Fri, 07 Feb 2025 00:58:39 +0000 Received: by outflank-mailman (input) for mailman id 883220; Fri, 07 Feb 2025 00:58:39 +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 1tgCha-0003ap-0J for xen-devel@lists.xenproject.org; Fri, 07 Feb 2025 00:58:39 +0000 Received: from mail-10628.protonmail.ch (mail-10628.protonmail.ch [79.135.106.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a7e570a1-e4ee-11ef-a073-877d107080fb; Fri, 07 Feb 2025 01:58:34 +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: a7e570a1-e4ee-11ef-a073-877d107080fb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=6yp2bnovengjphqql24wxmzzh4.protonmail; t=1738889912; x=1739149112; bh=yKbm9n3L7JqSqPlss7AbCrsbaTV2slnQWg8SYLHYRaM=; 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=YPK79bj8XmhBCEvAaRaivSc8kPrzX+8bEMubP5W9n0n7PiH1rBmZ60QOQGtQQedrv 9UDiGlbt/jLAl1l98VZ/fo6ytMpi6WcvTjHY+0tz++CHcZqP+VOpPk80ALP0buFIzZ 9pvQT3DTeaXlM47iHTJynreyeEOHxLwB0+8TAMpu3YBVKBfVCV2BZlhz1gR3VCBm/x STZDuYNkChx49yV2g56vXjeu5GG5+w08KWdIQXs9QbrKDpsciLtlkDaYnBlDRMY/Dw ZL8UbzOWWRMxoUtBkxQkdxyzhy0pY/XhDm/k51tsRE+Xt4zrKD0xRmkquhfGtKhZsj 1C9H39C52ZJCw== Date: Fri, 07 Feb 2025 00:58:26 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, dmukhin@ford.com, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org Subject: [PATCH] xen/console: introduce is_console_printable() Message-ID: <20250207005532.345746-1-dmkhn@proton.me> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: a3aff08d2b2144ecf3e84a5199d227b75df6d2ba MIME-Version: 1.0 From: Denis Mukhin Add is_console_printable() to implement a common check for printable characters in the UART emulation and guest logging code. Signed-off-by: Denis Mukhin Reviewed-by: Stefano Stabellini --- Link to the original patch: https://lore.kernel.org/xen-devel/20250103-vuart-ns8250-v3-v1-1-c5d36b31d66c@ford.com/ --- --- xen/arch/arm/vuart.c | 5 ++--- xen/arch/x86/hvm/hvm.c | 5 ++--- xen/drivers/char/console.c | 3 +-- xen/include/xen/console.h | 6 ++++++ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/vuart.c b/xen/arch/arm/vuart.c index d5ba483f1e..bd2f425214 100644 --- a/xen/arch/arm/vuart.c +++ b/xen/arch/arm/vuart.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -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 39e39ce4ce..219028969a 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -7,7 +7,6 @@ * Copyright (c) 2008, Citrix Systems, Inc. */ -#include #include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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 7da8c5296f..b4cec77247 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include /* for do_console_io */ @@ -674,7 +673,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/console.h b/xen/include/xen/console.h index 6dfbade3ec..eac6525c30 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -8,6 +8,7 @@ #define __CONSOLE_H__ #include +#include #include struct xen_sysctl_readconsole; @@ -50,4 +51,9 @@ void console_serial_puts(const char *s, size_t nr); extern int8_t opt_console_xen; +static inline bool is_console_printable(unsigned char c) +{ + return isprint(c) || c == '\n' || c == '\t'; +} + #endif /* __CONSOLE_H__ */