From nobody Wed Nov 27 17:45:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1697730098; cv=none; d=zohomail.com; s=zohoarc; b=YPqz29r9bmMDxnuc2Na+p2F1nHftMFu2869q/KHTFmn+o+NXXhDlOcJt5mZvoec1MxfV07N6Pzo4Cz2wCF+uUXTwqdImdE7VdkOXqMwRrdSrnXG91DdTD19DpsgrktFM5InxofyZr0ecD5LW8Ha748ISc0rPvCzbL8gMimD1B2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697730098; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bY7G6BllzrJN3vFK/Y7G+K3RXXQYNifA9f7cWw91v+w=; b=RHEZKJzyBe0852CtQ0/eSfNi4b6UOaHa2a0AcDpADzaysFtGW5JnybSyf+uT3IhEODLeT3H+wTFPsjuYR37djvS9Q/5lu7AhJtwF9Twet+Eu4t50g692ulbn6dNnB8IIUKEFipGWABVmBL/7Dob7uK0JAOgy8BhyuwjL3CuxLQA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1697730098771632.4103923386608; Thu, 19 Oct 2023 08:41:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.619415.964445 (Exim 4.92) (envelope-from ) id 1qtV8o-0007CU-CA; Thu, 19 Oct 2023 15:40:54 +0000 Received: by outflank-mailman (output) from mailman id 619415.964445; Thu, 19 Oct 2023 15:40:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qtV8o-0007Bb-5L; Thu, 19 Oct 2023 15:40:54 +0000 Received: by outflank-mailman (input) for mailman id 619415; Thu, 19 Oct 2023 15:40:53 +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 1qtV8n-0005v1-7M for xen-devel@lists.xenproject.org; Thu, 19 Oct 2023 15:40:53 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e12af5ed-6e95-11ee-98d5-6d05b1d4d9a1; Thu, 19 Oct 2023 17:40:50 +0200 (CEST) Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qtV8N-007ost-6Z; Thu, 19 Oct 2023 15:40:27 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qtV8M-000Puj-2e; Thu, 19 Oct 2023 16:40:26 +0100 X-Outflank-Mailman: Message body and most headers restored to incoming version 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 X-Inumbo-ID: e12af5ed-6e95-11ee-98d5-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=bY7G6BllzrJN3vFK/Y7G+K3RXXQYNifA9f7cWw91v+w=; b=MWiT9XbJDhi9ujm0tGvm22upP7 te/lmQ/hmveZzn0ycVjWqixFGMKT6/5fU6uvVcMql6gSfMbgWZLlU7jwp9ryFUBA7uH56p+hVjjco 0AZoYkc+YKjxkHCN455FCa166iJ2BrpMdVUOsH/51ZvwultlVsVlL27jQtCS6+ycQutWfSv92YIn8 7ztLveVVi78j4kpc/qu9EyXLlAdscdGLg+mFl9+MTP4eKRjsKTd0Wr4JMvc3B3VT382bsQWkXT3pd P8bP7vqrqozgMjgfKrnxvHZI95genVjq6SQ4008ksTv9EPtTYLWgSGCSZ6RMS3gPObuzgRGF6D9zW 4qnfXlBg==; From: David Woodhouse To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefano Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , Jason Wang , Marcelo Tosatti , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Beraldo Leal , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v2 16/24] hw/xen: handle soft reset for primary console Date: Thu, 19 Oct 2023 16:40:12 +0100 Message-Id: <20231019154020.99080-17-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231019154020.99080-1-dwmw2@infradead.org> References: <20231019154020.99080-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1697730099276100009 Content-Type: text/plain; charset="utf-8" From: David Woodhouse On soft reset, the prinary console event channel needs to be rebound to the backend port (in the xen-console driver). We could put that into the xen-console driver itself, but it's slightly less ugly to keep it within the KVM/Xen code, by stashing the backend port# on event channel reset and then rebinding in the primary console reset when it has to recreate the guest port anyway. Signed-off-by: David Woodhouse --- hw/i386/kvm/xen_evtchn.c | 9 +++++++++ hw/i386/kvm/xen_primary_console.c | 29 ++++++++++++++++++++++++++++- hw/i386/kvm/xen_primary_console.h | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c index d72dca6591..ce4da6d37a 100644 --- a/hw/i386/kvm/xen_evtchn.c +++ b/hw/i386/kvm/xen_evtchn.c @@ -40,6 +40,7 @@ #include "xen_evtchn.h" #include "xen_overlay.h" #include "xen_xenstore.h" +#include "xen_primary_console.h" =20 #include "sysemu/kvm.h" #include "sysemu/kvm_xen.h" @@ -1098,6 +1099,7 @@ int xen_evtchn_soft_reset(void) { XenEvtchnState *s =3D xen_evtchn_singleton; bool flush_kvm_routes; + uint16_t con_port =3D xen_primary_console_get_port(); int i; =20 if (!s) { @@ -1108,6 +1110,13 @@ int xen_evtchn_soft_reset(void) =20 qemu_mutex_lock(&s->port_lock); =20 + if (con_port) { + XenEvtchnPort *p =3D &s->port_table[con_port]; + if (p->type =3D=3D EVTCHNSTAT_interdomain) { + xen_primary_console_set_be_port(p->u.interdomain.port); + } + } + for (i =3D 0; i < s->nr_ports; i++) { close_port(s, i, &flush_kvm_routes); } diff --git a/hw/i386/kvm/xen_primary_console.c b/hw/i386/kvm/xen_primary_co= nsole.c index 0aa1c16ad6..5e6e085ac7 100644 --- a/hw/i386/kvm/xen_primary_console.c +++ b/hw/i386/kvm/xen_primary_console.c @@ -112,6 +112,15 @@ uint16_t xen_primary_console_get_port(void) return s->guest_port; } =20 +void xen_primary_console_set_be_port(uint16_t port) +{ + XenPrimaryConsoleState *s =3D xen_primary_console_singleton; + if (s) { + printf("be port set to %d\n", port); + s->be_port =3D port; + } +} + uint64_t xen_primary_console_get_pfn(void) { XenPrimaryConsoleState *s =3D xen_primary_console_singleton; @@ -142,6 +151,20 @@ static void alloc_guest_port(XenPrimaryConsoleState *s) } } =20 +static void rebind_guest_port(XenPrimaryConsoleState *s) +{ + struct evtchn_bind_interdomain inter =3D { + .remote_dom =3D DOMID_QEMU, + .remote_port =3D s->be_port, + }; + + if (!xen_evtchn_bind_interdomain_op(&inter)) { + s->guest_port =3D inter.local_port; + } + + s->be_port =3D 0; +} + int xen_primary_console_reset(void) { XenPrimaryConsoleState *s =3D xen_primary_console_singleton; @@ -154,7 +177,11 @@ int xen_primary_console_reset(void) xen_overlay_do_map_page(&s->console_page, gpa); } =20 - alloc_guest_port(s); + if (s->be_port) { + rebind_guest_port(s); + } else { + alloc_guest_port(s); + } =20 trace_xen_primary_console_reset(s->guest_port); =20 diff --git a/hw/i386/kvm/xen_primary_console.h b/hw/i386/kvm/xen_primary_co= nsole.h index dd4922f3f4..7e2989ea0d 100644 --- a/hw/i386/kvm/xen_primary_console.h +++ b/hw/i386/kvm/xen_primary_console.h @@ -16,6 +16,7 @@ void xen_primary_console_create(void); int xen_primary_console_reset(void); =20 uint16_t xen_primary_console_get_port(void); +void xen_primary_console_set_be_port(uint16_t port); uint64_t xen_primary_console_get_pfn(void); void *xen_primary_console_get_map(void); =20 --=20 2.40.1