From nobody Sun May 5 20:00:05 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565011869; cv=none; d=zoho.com; s=zohoarc; b=OVGHpjflmnu7FlJFGMuOXUvZrBpjjDNSb8o415mnRgdii+bcFqzFBVv95i9fni84ozg0SKIodd+bivgEqXBnKuYFM6yNylYUuU8c9w5neRrQLSNsTZF0P5eAOwbbwXq9lEQD2LKn6aX0IuRh8g24HeOkhnC0wVELJW1HdI/X/Vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565011869; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=IfcHleaBYfl80C5LApa01JaZBqG+gpJgdOFLjIVtueY=; b=Lc+a27Sq0Vd6sFlk5wJtshLhRwpv/EXJIz6dnY/xorBxvGuQ/CA3j6I/9t820MA66CaR+GQuRn/MF7NX/mPzkYQ7WcG1aUoDDyB1zWDSvlysH1H5mBExnUloahFmik42zGdcCoXnwybHp8gvKH6wpvmmfeDnwxM04xqtZX8BQT0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565011869256470.02293228092924; Mon, 5 Aug 2019 06:31:09 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hud3t-0004ik-59; Mon, 05 Aug 2019 13:30:05 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hud3s-0004a3-BO for xen-devel@lists.xenproject.org; Mon, 05 Aug 2019 13:30:04 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 215ad532-b785-11e9-8980-bc764e045a96; Mon, 05 Aug 2019 13:30:02 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8FB891570; Mon, 5 Aug 2019 06:30:02 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DE2D63F706; Mon, 5 Aug 2019 06:30:00 -0700 (PDT) X-Inumbo-ID: 215ad532-b785-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 5 Aug 2019 14:29:52 +0100 Message-Id: <20190805132955.1630-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190805132955.1630-1-julien.grall@arm.com> References: <20190805132955.1630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v2 1/4] xen/console: Don't treat NUL character as the end of the buffer X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Volodymyr Babchuk MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" After upgrading Debian to Buster, I have began to notice console mangling when using zsh in Dom0. This is happenning because output sent by zsh to the console may contain NULs in the middle of the buffer. The actual implementation of CONSOLEIO_write considers that a buffer always terminate with a NUL and therefore will ignore anything after it. In general, NULs are perfectly legitimate in terminal streams. For instance, this could be used for padding slow terminals. See terminfo(5) section `Delays and Padding`, or search for the pcre '\bpad'. Other use cases includes using the console for dumping non-human readable information (e.g debugger, file if no network...). With the current behavior, the resulting stream will end up to be corrupted. The documentation for CONSOLEIO_write is pretty limited (to not say inexistent). From the declaration, the hypercall takes a buffer and size. So this could lead to think the NUL character is allowed in the middle of the buffer. This patch updates the console API to pass the size along the buffer down so we can remove the reliance on buffer terminating by a NUL character. Signed-off-by: Julien Grall Acked-by: Stefano Stabellini Reviewed-by: Jan Beulich --- This patch was originally sent standalone [1]. But the series grows to include another bug found in the console code and documentation. Cnhanges in v2: - Switch from unsigned int to size_t. So truncation is avoided. We can decide whether we want explicit truncation later on. - Remove unecessary leading NUL added in dump_console_ring_key - Remove unecessary decoration in sercon_puts - Fix loop in lfb_scroll_puts - use while() rather than do {} while() Change since the standalone version: - Fix early printk on Arm - Fix gdbstub - Remove unecessary leading NUL character added by Xen - Handle DomU console - Rework the commit message Below a small C program to repro the bug on Xen: int main(void) { write(1, "\r\33[0m\0\0\0\0\0\0\0\0\33[27m\33[24m\33[j\33[32mjulien\33[31m@= \33[00m\33[36mjuno2-julieng:~\33[37m>", 75); write(1, "\33[K\33[32C\33[01;33m--juno2-julieng-13:44--\33[00m\33[37m\33[5= 5D", 54); write(1, "\33[?2004h", 8); return 0; } Without this patch, the only --juno2-julieng-13:44-- will be printed in yellow. This patch was tested on Arm using serial console. I am not entirely sure whether the video and PV console is correct. I would appreciate help for testing here. [1] https://lists.xenproject.org/archives/html/xen-devel/2019-02/msg01932.h= tml --- xen/arch/arm/early_printk.c | 5 ++-- xen/common/gdbstub.c | 6 ++-- xen/drivers/char/console.c | 59 +++++++++++++++++++----------------= ---- xen/drivers/char/consoled.c | 7 ++--- xen/drivers/char/serial.c | 7 +++-- xen/drivers/char/xen_pv_console.c | 10 +++---- xen/drivers/video/lfb.c | 14 ++++++---- xen/drivers/video/lfb.h | 4 +-- xen/drivers/video/vga.c | 14 +++++----- xen/include/xen/console.h | 2 +- xen/include/xen/early_printk.h | 2 +- xen/include/xen/pv_console.h | 4 +-- xen/include/xen/serial.h | 4 +-- xen/include/xen/video.h | 4 +-- 14 files changed, 71 insertions(+), 71 deletions(-) diff --git a/xen/arch/arm/early_printk.c b/xen/arch/arm/early_printk.c index 97466a12b1..333073d97e 100644 --- a/xen/arch/arm/early_printk.c +++ b/xen/arch/arm/early_printk.c @@ -17,9 +17,10 @@ void early_putch(char c); void early_flush(void); =20 -void early_puts(const char *s) +void early_puts(const char *s, size_t nr) { - while (*s !=3D '\0') { + while ( nr-- > 0 ) + { if (*s =3D=3D '\n') early_putch('\r'); early_putch(*s); diff --git a/xen/common/gdbstub.c b/xen/common/gdbstub.c index 07095e1ec7..6234834a20 100644 --- a/xen/common/gdbstub.c +++ b/xen/common/gdbstub.c @@ -68,7 +68,7 @@ static void gdb_smp_resume(void); static char __initdata opt_gdb[30]; string_param("gdb", opt_gdb); =20 -static void gdbstub_console_puts(const char *str); +static void gdbstub_console_puts(const char *str, size_t nr); =20 /* value <-> char (de)serialzers */ static char @@ -546,14 +546,14 @@ __gdb_ctx =3D { static struct gdb_context *gdb_ctx =3D &__gdb_ctx; =20 static void -gdbstub_console_puts(const char *str) +gdbstub_console_puts(const char *str, size_t nr) { const char *p; =20 gdb_start_packet(gdb_ctx); gdb_write_to_packet_char('O', gdb_ctx); =20 - for ( p =3D str; *p !=3D '\0'; p++ ) + for ( p =3D str; nr > 0; p++, nr-- ) { gdb_write_to_packet_char(hex2char((*p>>4) & 0x0f), gdb_ctx ); gdb_write_to_packet_char(hex2char((*p) & 0x0f), gdb_ctx ); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index d728e737d1..752a11f6c5 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -326,9 +326,9 @@ long read_console_ring(struct xen_sysctl_readconsole *o= p) static char serial_rx_ring[SERIAL_RX_SIZE]; static unsigned int serial_rx_cons, serial_rx_prod; =20 -static void (*serial_steal_fn)(const char *) =3D early_puts; +static void (*serial_steal_fn)(const char *, size_t nr) =3D early_puts; =20 -int console_steal(int handle, void (*fn)(const char *)) +int console_steal(int handle, void (*fn)(const char *, size_t nr)) { if ( (handle =3D=3D -1) || (handle !=3D sercon_handle) ) return 0; @@ -346,15 +346,15 @@ void console_giveback(int id) serial_steal_fn =3D NULL; } =20 -static void sercon_puts(const char *s) +static void sercon_puts(const char *s, size_t nr) { if ( serial_steal_fn !=3D NULL ) - (*serial_steal_fn)(s); + serial_steal_fn(s, nr); else - serial_puts(sercon_handle, s); + serial_puts(sercon_handle, s, nr); =20 /* Copy all serial output into PV console */ - pv_console_puts(s); + pv_console_puts(s, nr); } =20 static void dump_console_ring_key(unsigned char key) @@ -387,10 +387,9 @@ static void dump_console_ring_key(unsigned char key) sofar +=3D len; c +=3D len; } - buf[sofar] =3D '\0'; =20 - sercon_puts(buf); - video_puts(buf); + sercon_puts(buf, sofar); + video_puts(buf, sofar); =20 free_xenheap_pages(buf, order); } @@ -528,7 +527,7 @@ static inline void xen_console_write_debug_port(const c= har *buf, size_t len) static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, int c= ount) { char kbuf[128]; - int kcount =3D 0; + unsigned int kcount =3D 0; struct domain *cd =3D current->domain; =20 while ( count > 0 ) @@ -541,25 +540,22 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARA= M(char) buffer, int count) kcount =3D min_t(int, count, sizeof(kbuf)-1); if ( copy_from_guest(kbuf, buffer, kcount) ) return -EFAULT; - kbuf[kcount] =3D '\0'; =20 if ( is_hardware_domain(cd) ) { /* Use direct console output as it could be interactive */ spin_lock_irq(&console_lock); =20 - sercon_puts(kbuf); - video_puts(kbuf); + sercon_puts(kbuf, kcount); + video_puts(kbuf, kcount); =20 #ifdef CONFIG_X86 if ( opt_console_xen ) { - size_t len =3D strlen(kbuf); - if ( xen_guest ) - xen_hypercall_console_write(kbuf, len); + xen_hypercall_console_write(kbuf, kcount); else - xen_console_write_debug_port(kbuf, len); + xen_console_write_debug_port(kbuf, kcount); } #endif =20 @@ -576,19 +572,20 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARA= M(char) buffer, int count) char *kin =3D kbuf, *kout =3D kbuf, c; =20 /* Strip non-printable characters */ - for ( ; ; ) + do { c =3D *kin++; - if ( c =3D=3D '\0' || c =3D=3D '\n' ) + if ( c =3D=3D '\n' ) break; if ( isprint(c) || c =3D=3D '\t' ) *kout++ =3D c; - } + } while ( --kcount > 0 ); + *kout =3D '\0'; spin_lock(&cd->pbuf_lock); + kcount =3D kin - kbuf; if ( c =3D=3D '\n' ) { - kcount =3D kin - kbuf; cd->pbuf[cd->pbuf_idx] =3D '\0'; guest_printk(cd, XENLOG_G_DEBUG "%s%s\n", cd->pbuf, kbuf); cd->pbuf_idx =3D 0; @@ -667,16 +664,16 @@ static bool_t console_locks_busted; =20 static void __putstr(const char *str) { + size_t len =3D strlen(str); + ASSERT(spin_is_locked(&console_lock)); =20 - sercon_puts(str); - video_puts(str); + sercon_puts(str, len); + video_puts(str, len); =20 #ifdef CONFIG_X86 if ( opt_console_xen ) { - size_t len =3D strlen(str); - if ( xen_guest ) xen_hypercall_console_write(str, len); else @@ -1250,6 +1247,7 @@ void debugtrace_printk(const char *fmt, ...) char cntbuf[24]; va_list args; unsigned long flags; + unsigned int nr; =20 if ( debugtrace_bytes =3D=3D 0 ) return; @@ -1261,14 +1259,15 @@ void debugtrace_printk(const char *fmt, ...) ASSERT(debugtrace_buf[debugtrace_bytes - 1] =3D=3D 0); =20 va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); + nr =3D vscnprintf(buf, sizeof(buf), fmt, args); va_end(args); =20 if ( debugtrace_send_to_console ) { - snprintf(cntbuf, sizeof(cntbuf), "%u ", ++count); - serial_puts(sercon_handle, cntbuf); - serial_puts(sercon_handle, buf); + unsigned int n =3D snprintf(cntbuf, sizeof(cntbuf), "%u ", ++count= ); + + serial_puts(sercon_handle, cntbuf, n); + serial_puts(sercon_handle, buf, nr); } else { @@ -1381,7 +1380,7 @@ void panic(const char *fmt, ...) * ************************************************************** */ =20 -static void suspend_steal_fn(const char *str) { } +static void suspend_steal_fn(const char *str, size_t nr) { } static int suspend_steal_id; =20 int console_suspend(void) diff --git a/xen/drivers/char/consoled.c b/xen/drivers/char/consoled.c index 552abf5766..222e018442 100644 --- a/xen/drivers/char/consoled.c +++ b/xen/drivers/char/consoled.c @@ -77,16 +77,13 @@ size_t consoled_guest_rx(void) =20 if ( idx >=3D BUF_SZ ) { - pv_console_puts(buf); + pv_console_puts(buf, BUF_SZ); idx =3D 0; } } =20 if ( idx ) - { - buf[idx] =3D '\0'; - pv_console_puts(buf); - } + pv_console_puts(buf, idx); =20 /* No need for a mem barrier because every character was already consu= med */ barrier(); diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c index 221a14c092..88cd876790 100644 --- a/xen/drivers/char/serial.c +++ b/xen/drivers/char/serial.c @@ -223,11 +223,10 @@ void serial_putc(int handle, char c) spin_unlock_irqrestore(&port->tx_lock, flags); } =20 -void serial_puts(int handle, const char *s) +void serial_puts(int handle, const char *s, size_t nr) { struct serial_port *port; unsigned long flags; - char c; =20 if ( handle =3D=3D -1 ) return; @@ -238,8 +237,10 @@ void serial_puts(int handle, const char *s) =20 spin_lock_irqsave(&port->tx_lock, flags); =20 - while ( (c =3D *s++) !=3D '\0' ) + for ( ; nr > 0; nr--, s++ ) { + char c =3D *s; + if ( (c =3D=3D '\n') && (handle & SERHND_COOKED) ) __serial_putc(port, '\r' | ((handle & SERHND_HI) ? 0x80 : 0x00= )); =20 diff --git a/xen/drivers/char/xen_pv_console.c b/xen/drivers/char/xen_pv_co= nsole.c index cc1c1d743f..612784b074 100644 --- a/xen/drivers/char/xen_pv_console.c +++ b/xen/drivers/char/xen_pv_console.c @@ -129,13 +129,13 @@ size_t pv_console_rx(struct cpu_user_regs *regs) return recv; } =20 -static size_t pv_ring_puts(const char *buf) +static size_t pv_ring_puts(const char *buf, size_t nr) { XENCONS_RING_IDX cons, prod; size_t sent =3D 0, avail; bool put_r =3D false; =20 - while ( buf[sent] !=3D '\0' || put_r ) + while ( sent < nr || put_r ) { cons =3D ACCESS_ONCE(cons_ring->out_cons); prod =3D cons_ring->out_prod; @@ -156,7 +156,7 @@ static size_t pv_ring_puts(const char *buf) continue; } =20 - while ( avail && (buf[sent] !=3D '\0' || put_r) ) + while ( avail && (sent < nr || put_r) ) { if ( put_r ) { @@ -185,7 +185,7 @@ static size_t pv_ring_puts(const char *buf) return sent; } =20 -void pv_console_puts(const char *buf) +void pv_console_puts(const char *buf, size_t nr) { unsigned long flags; =20 @@ -193,7 +193,7 @@ void pv_console_puts(const char *buf) return; =20 spin_lock_irqsave(&tx_lock, flags); - pv_ring_puts(buf); + pv_ring_puts(buf, nr); spin_unlock_irqrestore(&tx_lock, flags); } =20 diff --git a/xen/drivers/video/lfb.c b/xen/drivers/video/lfb.c index 5022195ae5..75b749b330 100644 --- a/xen/drivers/video/lfb.c +++ b/xen/drivers/video/lfb.c @@ -53,14 +53,15 @@ static void lfb_show_line( } =20 /* Fast mode which redraws all modified parts of a 2D text buffer. */ -void lfb_redraw_puts(const char *s) +void lfb_redraw_puts(const char *s, size_t nr) { unsigned int i, min_redraw_y =3D lfb.ypos; - char c; =20 /* Paste characters into text buffer. */ - while ( (c =3D *s++) !=3D '\0' ) + for ( ; nr > 0; nr--, s++ ) { + char c =3D *s; + if ( (c =3D=3D '\n') || (lfb.xpos >=3D lfb.lfbp.text_columns) ) { if ( ++lfb.ypos >=3D lfb.lfbp.text_rows ) @@ -97,13 +98,14 @@ void lfb_redraw_puts(const char *s) } =20 /* Slower line-based scroll mode which interacts better with dom0. */ -void lfb_scroll_puts(const char *s) +void lfb_scroll_puts(const char *s, size_t nr) { unsigned int i; - char c; =20 - while ( (c =3D *s++) !=3D '\0' ) + for ( ; nr > 0; nr--, s++ ) { + char c =3D *s; + if ( (c =3D=3D '\n') || (lfb.xpos >=3D lfb.lfbp.text_columns) ) { unsigned int bytes =3D (lfb.lfbp.width * diff --git a/xen/drivers/video/lfb.h b/xen/drivers/video/lfb.h index ac40a66379..e743ccdd6b 100644 --- a/xen/drivers/video/lfb.h +++ b/xen/drivers/video/lfb.h @@ -35,8 +35,8 @@ struct lfb_prop { unsigned int text_rows; }; =20 -void lfb_redraw_puts(const char *s); -void lfb_scroll_puts(const char *s); +void lfb_redraw_puts(const char *s, size_t nr); +void lfb_scroll_puts(const char *s, size_t nr); void lfb_carriage_return(void); void lfb_free(void); =20 diff --git a/xen/drivers/video/vga.c b/xen/drivers/video/vga.c index 454457ade8..666f2e2509 100644 --- a/xen/drivers/video/vga.c +++ b/xen/drivers/video/vga.c @@ -18,9 +18,9 @@ static int vgacon_keep; static unsigned int xpos, ypos; static unsigned char *video; =20 -static void vga_text_puts(const char *s); -static void vga_noop_puts(const char *s) {} -void (*video_puts)(const char *) =3D vga_noop_puts; +static void vga_text_puts(const char *s, size_t nr); +static void vga_noop_puts(const char *s, size_t nr) {} +void (*video_puts)(const char *, size_t nr) =3D vga_noop_puts; =20 /* * 'vga=3D[,keep]' where is one of: @@ -174,12 +174,12 @@ void __init video_endboot(void) } } =20 -static void vga_text_puts(const char *s) +static void vga_text_puts(const char *s, size_t nr) { - char c; - - while ( (c =3D *s++) !=3D '\0' ) + for ( ; nr > 0; nr--, s++ ) { + char c =3D *s; + if ( (c =3D=3D '\n') || (xpos >=3D columns) ) { if ( ++ypos >=3D lines ) diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index b4f9463936..ba914f9e5b 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -38,7 +38,7 @@ struct domain *console_input_domain(void); * Steal output from the console. Returns +ve identifier, else -ve error. * Takes the handle of the serial line to steal, and steal callback functi= on. */ -int console_steal(int handle, void (*fn)(const char *)); +int console_steal(int handle, void (*fn)(const char *, size_t nr)); =20 /* Give back stolen console. Takes the identifier returned by console_stea= l. */ void console_giveback(int id); diff --git a/xen/include/xen/early_printk.h b/xen/include/xen/early_printk.h index 2c3e1b3519..0f76c3a74f 100644 --- a/xen/include/xen/early_printk.h +++ b/xen/include/xen/early_printk.h @@ -5,7 +5,7 @@ #define __XEN_EARLY_PRINTK_H__ =20 #ifdef CONFIG_EARLY_PRINTK -void early_puts(const char *s); +void early_puts(const char *s, size_t nr); #else #define early_puts NULL #endif diff --git a/xen/include/xen/pv_console.h b/xen/include/xen/pv_console.h index cb92539666..4745f46f2d 100644 --- a/xen/include/xen/pv_console.h +++ b/xen/include/xen/pv_console.h @@ -8,7 +8,7 @@ void pv_console_init(void); void pv_console_set_rx_handler(serial_rx_fn fn); void pv_console_init_postirq(void); -void pv_console_puts(const char *buf); +void pv_console_puts(const char *buf, size_t nr); size_t pv_console_rx(struct cpu_user_regs *regs); evtchn_port_t pv_console_evtchn(void); =20 @@ -17,7 +17,7 @@ evtchn_port_t pv_console_evtchn(void); static inline void pv_console_init(void) {} static inline void pv_console_set_rx_handler(serial_rx_fn fn) { } static inline void pv_console_init_postirq(void) { } -static inline void pv_console_puts(const char *buf) { } +static inline void pv_console_puts(const char *buf, size_t nr) { } static inline size_t pv_console_rx(struct cpu_user_regs *regs) { return 0;= } evtchn_port_t pv_console_evtchn(void) { diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h index f2994d4093..6548f0b0a9 100644 --- a/xen/include/xen/serial.h +++ b/xen/include/xen/serial.h @@ -114,8 +114,8 @@ int serial_parse_handle(char *conf); /* Transmit a single character via the specified COM port. */ void serial_putc(int handle, char c); =20 -/* Transmit a NULL-terminated string via the specified COM port. */ -void serial_puts(int handle, const char *s); +/* Transmit a string via the specified COM port. */ +void serial_puts(int handle, const char *s, size_t nr); =20 /* * An alternative to registering a character-receive hook. This function diff --git a/xen/include/xen/video.h b/xen/include/xen/video.h index 2e897f9df5..905f331112 100644 --- a/xen/include/xen/video.h +++ b/xen/include/xen/video.h @@ -13,11 +13,11 @@ =20 #ifdef CONFIG_VIDEO void video_init(void); -extern void (*video_puts)(const char *); +extern void (*video_puts)(const char *, size_t nr); void video_endboot(void); #else #define video_init() ((void)0) -#define video_puts(s) ((void)0) +#define video_puts(s, nr) ((void)0) #define video_endboot() ((void)0) #endif =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sun May 5 20:00:05 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565011869; cv=none; d=zoho.com; s=zohoarc; b=K+NcH7NNxaixe44F8l79QUGVhQjjLY/12eW6hKfwZnpeFyhkWBOlpHQBegdAgYUOCcRNL48jjJGTxKItsakeIYssLgyhh77ifyniGX+ECQHB8kgv06w0E6zprw1tUEeDPFYRFhk7hK3AQ7Eqx8UdcIKllFiGbtpC37Acpz1JFn8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565011869; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=IyhcvQXH9gW2tGONV+gE7mCtMvi8mRRFFf/Go7z1NhE=; b=oj5MfeEyFsu/4B2eL14XppdwRwJQ8LGnW4XpZVFeGijbX2b6wZsSrB5mCMKBXXiaC0ZoyG2mDMxg5rRXxR0R8yqjXTBULC7wTAb3Mxdr+Sgy3LS+Rt5I5opPACtcDiLleIosWCvM1rtxTPm9E3zfZ2QvWWJxO6cyHJvbMPTDAEY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565011869022638.4662403328463; Mon, 5 Aug 2019 06:31:09 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hud3v-0004rp-GI; Mon, 05 Aug 2019 13:30:07 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hud3t-0004mH-S7 for xen-devel@lists.xenproject.org; Mon, 05 Aug 2019 13:30:05 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 2247a2a8-b785-11e9-baf5-930cb7644b7c; Mon, 05 Aug 2019 13:30:04 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2657A1597; Mon, 5 Aug 2019 06:30:04 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C525C3F706; Mon, 5 Aug 2019 06:30:02 -0700 (PDT) X-Inumbo-ID: 2247a2a8-b785-11e9-baf5-930cb7644b7c From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 5 Aug 2019 14:29:53 +0100 Message-Id: <20190805132955.1630-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190805132955.1630-1-julien.grall@arm.com> References: <20190805132955.1630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v2 2/4] xen/console: Rework HYPERCALL_console_io interface X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, HYPERCALL_console_io is using signed int to describe the command (@cmd) and the size of the buffer (@count). * @cmd does not need to be signed this used as a set of named value. None of them are negative. If new one are introduced they can be positive. * @count is used to know the size of the buffer. It makes little sense to have a negative value here. So both variables are now switched to use unsigned int. Changing @count to unsigned type will result in a change of behavior for the existing commands: - write: Any buffer bigger than 2GB will now be printed rather than been ignored (the command return 0). - read: The return value is a signed 32-bit value for 32-bit Xen. To keep compatibility between 32-bit and 64-bit ABI, it effectively means the return value is 32-bit (despite been long on 64-bit). Negative value are used for error and positive value for the number of characters read. To avoid clash between the two sets, the buffer is still limited to 2GB. The only difference is an error is returned rather than claiming there are no characters. The behavior is only affecting unlikely use of the current interface, so this is not a big concern regarding backward compatibility. Signed-off-by: Julien Grall Reviewed-by: Jan Beulich --- This will be documented in the public interface in the next patch. Changes in v2: - Patch added --- xen/drivers/char/console.c | 15 +++++++++++++-- xen/include/xen/hypercall.h | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 752a11f6c5..fa8f5cff4b 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -524,7 +524,8 @@ static inline void xen_console_write_debug_port(const c= har *buf, size_t len) } #endif =20 -static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, int c= ount) +static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, + unsigned int count) { char kbuf[128]; unsigned int kcount =3D 0; @@ -612,7 +613,8 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(= char) buffer, int count) return 0; } =20 -long do_console_io(int cmd, int count, XEN_GUEST_HANDLE_PARAM(char) buffer) +long do_console_io(unsigned int cmd, unsigned int count, + XEN_GUEST_HANDLE_PARAM(char) buffer) { long rc; unsigned int idx, len; @@ -627,6 +629,15 @@ long do_console_io(int cmd, int count, XEN_GUEST_HANDL= E_PARAM(char) buffer) rc =3D guest_console_write(buffer, count); break; case CONSOLEIO_read: + /* + * The return value is either the number of characters read or + * a negative value in case of error. So we need to prevent + * overlap between the two sets. + */ + rc =3D -E2BIG; + if ( (int)count < 0 ) + break; + rc =3D 0; while ( (serial_rx_cons !=3D serial_rx_prod) && (rc < count) ) { diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h index fc00a67448..ad8ad27b23 100644 --- a/xen/include/xen/hypercall.h +++ b/xen/include/xen/hypercall.h @@ -83,8 +83,8 @@ do_xen_version( =20 extern long do_console_io( - int cmd, - int count, + unsigned int cmd, + unsigned int count, XEN_GUEST_HANDLE_PARAM(char) buffer); =20 extern long --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sun May 5 20:00:05 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565011874; cv=none; d=zoho.com; s=zohoarc; b=Il9LAWkUae9k+2YoZRvc8SnL/Qezuoy/tq78qMyRaPIdZy7PtAC5G5IWa+I6B9uuAGFxspWY/fWbdnYeoRFTu19sZIq9Hg/rpC0Za5QYHgOGM+XQlz6S/AwE8IwQcR/phww5To1PM5y7h7Zz/PdBNMMnlXzuK025RQCnwfsp4/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565011874; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HHIHjrBGG596JWlofG7YLmVKqgz0smgqBsm5ErrSrPc=; b=iNIfU0KZM0k61SsGNSh+A9dCQ5kT1IXSqlAmiHWFC1Z4OBiTlBt3+KoceiJn0gMUrINGslM9c0ve448nQDOgv/RzDaAjdVBvks6Fqf+3Cqhh3wjvE58drWzWp+kTU8bhwuU3vah7E6VXrLChvRfweGlOV2+L2v6YijDGGh6zZvk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565011874007565.5662156899438; Mon, 5 Aug 2019 06:31:14 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hud3w-0004sf-RU; Mon, 05 Aug 2019 13:30:08 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hud3u-0004rC-UB for xen-devel@lists.xenproject.org; Mon, 05 Aug 2019 13:30:06 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 231d066c-b785-11e9-8980-bc764e045a96; Mon, 05 Aug 2019 13:30:05 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B022D337; Mon, 5 Aug 2019 06:30:05 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5BF573F706; Mon, 5 Aug 2019 06:30:04 -0700 (PDT) X-Inumbo-ID: 231d066c-b785-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 5 Aug 2019 14:29:54 +0100 Message-Id: <20190805132955.1630-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190805132955.1630-1-julien.grall@arm.com> References: <20190805132955.1630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v2 3/4] xen/public: Document HYPERCALL_console_io() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently, OS developpers will have to look at Xen code in order to know the parameters of an hypercall and how it is meant to work. This is not a trivial task as you may need to have a deep understanding of Xen internal. This patch attempts to document the behavior of HYPERCALL_console_io() to help OS developer. Signed-off-by: Julien Grall Acked-by: Jan Beulich --- Changes in v2: - Follow the style of other comments within the file - Use @return to make return value - Add a sentence regarding the buffer size --- xen/include/public/xen.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index cb2917e74b..742ab71004 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -486,7 +486,29 @@ DEFINE_XEN_GUEST_HANDLE(mmuext_op_t); /* ` } */ =20 /* - * Commands to HYPERVISOR_console_io(). + * ` int + * ` HYPERVISOR_console_io(unsigned int cmd, + * ` unsigned int count, + * ` char buffer[]); + * + * @cmd: Command (see below) + * @count: Size of the buffer to read/write + * @buffer: Pointer in the guest memory + * + * List of commands: + * + * * CONSOLEIO_write: Write the buffer on Xen console. + * For the hardware domain, all the characters in the buffer will + * be written. Characters will be printed to directly to the + * console. + * For all the other domains, only the printable characters will be + * written. Characters may be buffered until a newline (i.e '\n') is + * found. + * @return 0 on success, otherwise return an error code. + * * CONSOLEIO_read: Attempts to read up @count characters from Xen conso= le. + * The maximum buffer size (i.e @count) supported is 2GB. + * @return the number of character read on success, otherwise return + * an error code. */ #define CONSOLEIO_write 0 #define CONSOLEIO_read 1 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sun May 5 20:00:05 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565011866; cv=none; d=zoho.com; s=zohoarc; b=i8i2P25l8JIfkUiVstGaLzMDW8hgF4OaFfOU3z4ek6w0656FlO2JtuqPThyRxUGhanVWfKQnAMGCV/6WNHa6gk3t2yEH47B4UMWc+9DZfPYLELsengU1PlmSD7m40gVBUomdZz8V1PNqU0rQH00x5yEPdyU09a70Yc+TOJXvtRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565011866; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=CYOhK3NAeUWautBSGVHLrN1UQsoxEynEdX6EN5FxhNM=; b=gegmEUdtqvwhJ/54jQz7yf68m966PytumWDQLDqpliFzdbj4UPkzQRc3SDUlwXIso2naWfXA6vSsvBTkm1AGDPE8Vuw7NnprEh822CKrq1B3oCjbx2JDpzo+m8FLz8/KIb41JML3gEmV+RG7ivEuuZCPz/ZNEFAyVvPviHyEZZM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565011866259307.26834981528293; Mon, 5 Aug 2019 06:31:06 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hud3y-0004tr-As; Mon, 05 Aug 2019 13:30:10 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hud3w-0004sR-Ei for xen-devel@lists.xenproject.org; Mon, 05 Aug 2019 13:30:08 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 24105ea2-b785-11e9-8980-bc764e045a96; Mon, 05 Aug 2019 13:30:07 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 664B61570; Mon, 5 Aug 2019 06:30:07 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E64FA3F706; Mon, 5 Aug 2019 06:30:05 -0700 (PDT) X-Inumbo-ID: 24105ea2-b785-11e9-8980-bc764e045a96 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 5 Aug 2019 14:29:55 +0100 Message-Id: <20190805132955.1630-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190805132955.1630-1-julien.grall@arm.com> References: <20190805132955.1630-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v2 4/4] xen/console: Simplify domU console handling in guest_console_write X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 2 paths in the domU console handling are now the same. So they can be merged to make the code simpler. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini Acked-by: Wei Liu --- Changes in v2: - Fix indentation - Add Stefano's reviewed-by - Add Wei's acked-by --- xen/drivers/char/console.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index fa8f5cff4b..4105ca58d8 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -585,13 +585,8 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM= (char) buffer, *kout =3D '\0'; spin_lock(&cd->pbuf_lock); kcount =3D kin - kbuf; - if ( c =3D=3D '\n' ) - { - cd->pbuf[cd->pbuf_idx] =3D '\0'; - guest_printk(cd, XENLOG_G_DEBUG "%s%s\n", cd->pbuf, kbuf); - cd->pbuf_idx =3D 0; - } - else if ( cd->pbuf_idx + (kout - kbuf) < (DOMAIN_PBUF_SIZE - 1= ) ) + if ( c !=3D '\n' && + (cd->pbuf_idx + (kout - kbuf) < (DOMAIN_PBUF_SIZE - 1)) ) { /* buffer the output until a newline */ memcpy(cd->pbuf + cd->pbuf_idx, kbuf, kout - kbuf); --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel