From nobody Thu Feb 22 10:31:18 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TgTvV5nz1z5CM5J; Thu, 22 Feb 2024 10:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TgTvV4qVtz4kXV; Thu, 22 Feb 2024 10:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708597878; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/y1dyd/yiWdO+49/9WWllpUTyBDEclF5EdMNcu6NpWg=; b=dwFBY+EjgAy47AAGl0vrHIzFc4aLWIXQfpCKGHTOVxKa+7vgURTwuNvLxgSbHO05BUdZL4 J5LAkdJ87iOzmxlsBJeVt9jS/Huq/2vvkUOIxRHRSGCJC0k0c7wWccwX8DB6n3U4OKtG+o 3UrecD0TzRULuUQBncIUgu0+m+WMLuYUoQT+HaLZyGEhCXBlkClVNUVuKfsU+NUEXED5Hj c6Xic1h/j2Aob0lW0cg6Ky1HNXKVFdL1zsnpotoodQ93CAHN9cG6r7y5SaTI+CNNWuJkl8 t3pYkf0TjMnzA353HVxe9LR0X6CnPX8+4sKlWy99S8TGhM50Vvxadn3ltqdtgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708597878; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/y1dyd/yiWdO+49/9WWllpUTyBDEclF5EdMNcu6NpWg=; b=gN016fy/5Qn0ScDHVZ2E38f1EG8Ub0hWHAQcCb/Hk4bk72Wt/wlqT75kvXbjAi4/h6p0uQ qciZ6kx4R3DBq4gvkLP9P4RObbhnCBllW8DsPGid+bOcbuV+1pFMeWuRIg1XZNAqj1FWB6 MRsbWgthm7Dp+WN3iee0GtnyuwU7pYY00wTPVi8bihLZ7YucSGqzHilzsFoVnVocfphpNc AjW0WSyIRCrBaMDIp/QtrSxxWSvGqXKbmMWm6idhXsMNFA2rQId/1BZHUxEHhtb5yIMyet 1oh73wjEf1GLkn6AyGfY0hQHEJCO4vpCxPK0h1hD7sfyPdVbWXfqF2CrEAYeMQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708597878; a=rsa-sha256; cv=none; b=vZkeKdqlFtZay5UHhZYl4YAotKdPEcbVN5L2lTTNA3OlBhngUp0blnOuv4E58wHuAHlNPW pNx0DCOvxdNi9rhObSJM78FTdHn2vU+RL4FKuvUoEinxnjUIJATL6IGCIDsFxAkqnuwTbQ zhhCV4Oa50/muInTxoZXaBxCYlvid1PZiDz/z/EOYDiJp2qH3ArVxXobbP3Pgi1eKrXbKw mpnEwhk6pnaLVJWe+izPQ2DxNMSMfmQ37ZuTX0HBILjJ+zdKHsyWgv0xSkGqKCL2Bgf6Iy 39cNX1vj/uSzuzZCejHdZHPlL5/mzdho9d52vX63xR8HTAh9S+xM/5C/7CiPhQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TgTvV3t6mzS74; Thu, 22 Feb 2024 10:31:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41MAVIhe016589; Thu, 22 Feb 2024 10:31:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41MAVIts016586; Thu, 22 Feb 2024 10:31:18 GMT (envelope-from git) Date: Thu, 22 Feb 2024 10:31:18 GMT Message-Id: <202402221031.41MAVIts016586@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roger Pau =?utf-8?Q?Monn=C3=A9?= Subject: git: 399386f190f1 - main - x86/xen: introduce non-hypercall based emergency print List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 399386f190f157073baaa56925e92cc90edded8c Auto-Submitted: auto-generated The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=399386f190f157073baaa56925e92cc90edded8c commit 399386f190f157073baaa56925e92cc90edded8c Author: Roger Pau Monné AuthorDate: 2024-01-22 13:20:25 +0000 Commit: Roger Pau Monné CommitDate: 2024-02-22 10:08:03 +0000 x86/xen: introduce non-hypercall based emergency print The current xc_printf() function uses an hypercall in order to send character buffers to the hypervisor for it to print on the hypervisor console (if the hypervisor is configured to print such messages). This requires the hypercall page to be initialized, which is extra work and can go wrong. On x86 instead of using the console IO hypercall use the debug console IO port, also called "port E9 hack". This allows sending characters to Xen using an outb instruction, without any initialization required. Keep the previous hypervisor based implementation by using the weak attribute, which allows each architecture to provide an alternate (arch-specific) implementation. Sponsored by: Cloud Software Group Reviewed by: markj Differential revision: https://reviews.freebsd.org/D43929 --- sys/dev/xen/console/xen_console.c | 15 ++++++++++----- sys/x86/xen/hvm.c | 5 +++++ sys/xen/xen-os.h | 7 +++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/sys/dev/xen/console/xen_console.c b/sys/dev/xen/console/xen_console.c index d232dd4e0c1c..f1a298a2aefa 100644 --- a/sys/dev/xen/console/xen_console.c +++ b/sys/dev/xen/console/xen_console.c @@ -138,6 +138,13 @@ struct putchar_arg { size_t n_next; }; +void __weak_symbol +xen_emergency_print(const char *str, size_t size) +{ + KASSERT((xen_domain()), ("call to xc_printf from non Xen guest")); + HYPERVISOR_console_write(str, size); +} + static void putchar(int c, void *arg) { @@ -150,12 +157,12 @@ putchar(int c, void *arg) * We have no buffer, output directly to the * console char by char. */ - HYPERVISOR_console_write((char *)&c, 1); + xen_emergency_print((char *)&c, 1); } else { pca->buf[pca->n_next++] = c; if ((pca->size == pca->n_next) || (c = '\0')) { /* Flush the buffer */ - HYPERVISOR_console_write(pca->buf, pca->n_next); + xen_emergency_print(pca->buf, pca->n_next); pca->n_next = 0; } } @@ -177,15 +184,13 @@ xc_printf(const char *fmt, ...) pca.size = 0; #endif - KASSERT((xen_domain()), ("call to xc_printf from non Xen guest")); - va_start(ap, fmt); kvprintf(fmt, putchar, &pca, 10, ap); va_end(ap); #ifdef PRINTF_BUFR_SIZE if (pca.n_next != 0) - HYPERVISOR_console_write(buf, pca.n_next); + xen_emergency_print(buf, pca.n_next); #endif } diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c index b8125e230b6f..6411b790a2be 100644 --- a/sys/x86/xen/hvm.c +++ b/sys/x86/xen/hvm.c @@ -95,6 +95,11 @@ TUNABLE_INT("hw.xen.disable_pv_nics", &xen_disable_pv_nics); /*---------------------- XEN Hypervisor Probe and Setup ----------------------*/ +void xen_emergency_print(const char *str, size_t size) +{ + outsb(XEN_HVM_DEBUGCONS_IOPORT, str, size); +} + uint32_t xen_cpuid_base; static uint32_t diff --git a/sys/xen/xen-os.h b/sys/xen/xen-os.h index d7e9b3ca8632..98be41124846 100644 --- a/sys/xen/xen-os.h +++ b/sys/xen/xen-os.h @@ -151,6 +151,13 @@ int xenmem_free(device_t dev, int res_id, struct resource *res); /* Debug/emergency function, prints directly to hypervisor console */ void xc_printf(const char *, ...) __printflike(1, 2); +/* + * Emergency print function, can be defined per-arch, otherwise defaults to + * HYPERVISOR_console_write. Should not be called directly, use xc_printf + * instead. + */ +void xen_emergency_print(const char *str, size_t size); + #ifndef xen_mb #define xen_mb() mb() #endif