From nobody Thu May 16 12:55:27 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=1697469609; cv=none; d=zohomail.com; s=zohoarc; b=doZNWI/Ccz1Jt1KjXS1+HXm4awdXVPrRtOzvImkxL2ulQ6g3rgUbRlHwx7nr/BuzaShSnVc4NXI7zvZpCB5krzUsJpM0ERfFbptLLw/45Qd1cex9y4o/Wpw1nI0X60GyNylqKeK+j7sueKilovPSSnanbnmxBul5T5/e7XxAcJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469609; 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=vtO5N+wDv4TrwwTv9zLMoxCNzI1zqbUwBjGBebK9mtU=; b=TqovUv3HVoYBxwDfAclpOvcSONZSIq3WEJE0Q0UnrtsJYUpjlDic8aeduer3JKpzo2JqCcAtj83lwzuPQP0mCIu92jKk5NkYDHdTJLdWk7IcZPCNacaAGfv8d86XMUgPZDG3RO2iT/zCYkBS3V9k4Jle3LJ0FnW+dHH8U+41/ik= 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 1697469609196216.55311325138643; Mon, 16 Oct 2023 08:20:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617752.960709 (Exim 4.92) (envelope-from ) id 1qsPNa-0002P6-UZ; Mon, 16 Oct 2023 15:19:38 +0000 Received: by outflank-mailman (output) from mailman id 617752.960709; Mon, 16 Oct 2023 15:19:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNa-0002Jd-Na; Mon, 16 Oct 2023 15:19:38 +0000 Received: by outflank-mailman (input) for mailman id 617752; Mon, 16 Oct 2023 15:19:36 +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 1qsPNY-0001wi-S1 for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:36 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6a0a8dc3-6c37-11ee-98d4-6d05b1d4d9a1; Mon, 16 Oct 2023 17:19:35 +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 1qsPNC-006lqY-2R; Mon, 16 Oct 2023 15:19:14 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0005n8-27; Mon, 16 Oct 2023 16:19:13 +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: 6a0a8dc3-6c37-11ee-98d4-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=vtO5N+wDv4TrwwTv9zLMoxCNzI1zqbUwBjGBebK9mtU=; b=VytKiJSn6jDj/vFvhCOH+pzA+G hNoBp0fpQwayhvdjr2fGGMYnebOK+W9bolWMK3n10K6ocwhz7jBgMf10Dp4DKZgQWM24VmEvfTIsE BZb05ZDYRAQ2flMzqF/Wpj+6ewIlRuJG5zXq1par0JIOpljTKHvpNrC8EohvEaqA+jbnW5LlQEdqC TMs9W7hXJxB0RczoRR+VMHhxzhgqntDLNFLucvRN+++GPz7esDSR48LH0HkiDfuQDozgqbnwlx3EG GObBhsnpZgllt6nksabXqe90NabHtijgMAggzFnDlDfBwqXFegA1Rr1sdawRi/6Q7Ls9L3W7875C/ CDyI0V6A==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 01/12] i386/xen: fix per-vCPU upcall vector for Xen emulation Date: Mon, 16 Oct 2023 16:18:58 +0100 Message-Id: <20231016151909.22133-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-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: 1697469611211100003 Content-Type: text/plain; charset="utf-8" From: David Woodhouse The per-vCPU upcall vector support had two problems. Firstly it was using the wrong hypercall argument and would always return -EFAULT. And secondly it was using the wrong ioctl() to pass the vector to the kernel and thus the *kernel* would always return -EINVAL. Linux doesn't (yet) use this mode so it went without decent testing for a while. Fixes: 105b47fdf2d0 ("i386/xen: implement HVMOP_set_evtchn_upcall_vector") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- target/i386/kvm/xen-emu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index c4fa84a982..b49a840438 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -306,7 +306,7 @@ static int kvm_xen_set_vcpu_callback_vector(CPUState *c= s) =20 trace_kvm_xen_set_vcpu_callback(cs->cpu_index, vector); =20 - return kvm_vcpu_ioctl(cs, KVM_XEN_HVM_SET_ATTR, &xva); + return kvm_vcpu_ioctl(cs, KVM_XEN_VCPU_SET_ATTR, &xva); } =20 static void do_set_vcpu_callback_vector(CPUState *cs, run_on_cpu_data data) @@ -849,8 +849,7 @@ static bool kvm_xen_hcall_hvm_op(struct kvm_xen_exit *e= xit, X86CPU *cpu, int ret =3D -ENOSYS; switch (cmd) { case HVMOP_set_evtchn_upcall_vector: - ret =3D kvm_xen_hcall_evtchn_upcall_vector(exit, cpu, - exit->u.hcall.params[0]); + ret =3D kvm_xen_hcall_evtchn_upcall_vector(exit, cpu, arg); break; =20 case HVMOP_pagetable_dying: --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469621; cv=none; d=zohomail.com; s=zohoarc; b=gNqS+kM1bCu3aCqUZy0L+0wAfcN6CsPcUv8DGU82UYEJDBkkZbKP5gfRBMROA0bqzm5m0dtV97XcGyqyiTFuUaUXAHUgdbWCJ3XKoPy3TYgGP7mKdm628W4qSEUvMiRaW5LAkz2eRxMbhwBYAvrLRQn2O6TUqYOGoT6BlFgtVNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469621; 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=sLSQjDyHM6H6vyCwrNd1oC0DrClv2UPw9aKIA6AhbP0=; b=Ppwz1VYaJg3HIptpXz2S9jlapxGxXNKDg2xoMOo7DlgexJau0NawZfnxWNtOq0nLgNNSPXtxY+Q5+LzQiuFlvy1ZIoAHDrNwBeCHr2dBsRII5BZCFLG+ocaRaAQY57CdAQ+n34fQHGqmewp09+M+P+4riSQs0IvcCEhXRDjUiWU= 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 1697469621744696.3480676581725; Mon, 16 Oct 2023 08:20:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617753.960718 (Exim 4.92) (envelope-from ) id 1qsPNb-0002YO-Fo; Mon, 16 Oct 2023 15:19:39 +0000 Received: by outflank-mailman (output) from mailman id 617753.960718; Mon, 16 Oct 2023 15:19: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 1qsPNb-0002WO-6T; Mon, 16 Oct 2023 15:19:39 +0000 Received: by outflank-mailman (input) for mailman id 617753; Mon, 16 Oct 2023 15:19:38 +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 1qsPNZ-0001wi-SH for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:37 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6a2920c6-6c37-11ee-98d4-6d05b1d4d9a1; Mon, 16 Oct 2023 17:19:36 +0200 (CEST) Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0067AG-2H; Mon, 16 Oct 2023 15:19:15 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0005nB-2D; Mon, 16 Oct 2023 16:19:13 +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: 6a2920c6-6c37-11ee-98d4-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=sLSQjDyHM6H6vyCwrNd1oC0DrClv2UPw9aKIA6AhbP0=; b=FqeMYA/JfTC8p0DG5XK/5ZIu7B EUetaVF1ix6DTUyqYJPmR6BEKr8LA+088i3w5FooNB+tJ2CGq5fIwEk6CHqTMqRWi4A4JkeZDj4PO FFVaxZlOnTksjcWikg7PxddJcMky3TKcRovSYEeLHXsu9U/2HJZfBr2d77FPfZMF9Lw1bhqNl7arM I7LF7ZN8+aIXN0kV7FUmX70qmrghYiYcTbPPqJb6BE4mD4zOv1LHUL/J+w/UCAeu+v78F92hv3ea5 KYP7zA2OShwtZ30hVrz5y3VZ46/VNhecSXsjdugWtI+wFOhgX2X++SXZeSAtEBesjmULCUOv8BaMW +MTswpPQ==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 02/12] hw/xen: select kernel mode for per-vCPU event channel upcall vector Date: Mon, 16 Oct 2023 16:18:59 +0100 Message-Id: <20231016151909.22133-3-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-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 desiato.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1697469623309100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse A guest which has configured the per-vCPU upcall vector may set the HVM_PARAM_CALLBACK_IRQ param to fairly much anything other than zero. For example, Linux v6.0+ after commit b1c3497e604 ("x86/xen: Add support for HVMOP_set_evtchn_upcall_vector") will just do this after setting the vector: /* Trick toolstack to think we are enlightened. */ if (!cpu) rc =3D xen_set_callback_via(1); That's explicitly setting the delivery to GSI#, but it's supposed to be overridden by the per-vCPU vector setting. This mostly works in QEMU *except* for the logic to enable the in-kernel handling of event channels, which falsely determines that the kernel cannot accelerate GSI delivery in this case. Add a kvm_xen_has_vcpu_callback_vector() to report whether vCPU#0 has the vector set, and use that in xen_evtchn_set_callback_param() to enable the kernel acceleration features even when the param *appears* to be set to target a GSI. Preserve the Xen behaviour that when HVM_PARAM_CALLBACK_IRQ is set to *zero* the event channel delivery is disabled completely. (Which is what that bizarre guest behaviour is working round in the first place.) Fixes: 91cce756179 ("hw/xen: Add xen_evtchn device for event channel emulat= ion") Signed-off-by: David Woodhouse --- hw/i386/kvm/xen_evtchn.c | 6 ++++++ include/sysemu/kvm_xen.h | 1 + target/i386/kvm/xen-emu.c | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c index 4df973022c..d72dca6591 100644 --- a/hw/i386/kvm/xen_evtchn.c +++ b/hw/i386/kvm/xen_evtchn.c @@ -490,6 +490,12 @@ int xen_evtchn_set_callback_param(uint64_t param) break; } =20 + /* If the guest has set a per-vCPU callback vector, prefer that. */ + if (gsi && kvm_xen_has_vcpu_callback_vector()) { + in_kernel =3D kvm_xen_has_cap(EVTCHN_SEND); + gsi =3D 0; + } + if (!ret) { /* If vector delivery was turned *off* then tell the kernel */ if ((s->callback_param >> CALLBACK_VIA_TYPE_SHIFT) =3D=3D diff --git a/include/sysemu/kvm_xen.h b/include/sysemu/kvm_xen.h index 595abfbe40..961c702c4e 100644 --- a/include/sysemu/kvm_xen.h +++ b/include/sysemu/kvm_xen.h @@ -22,6 +22,7 @@ int kvm_xen_soft_reset(void); uint32_t kvm_xen_get_caps(void); void *kvm_xen_get_vcpu_info_hva(uint32_t vcpu_id); +bool kvm_xen_has_vcpu_callback_vector(void); void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_id, int type); void kvm_xen_set_callback_asserted(void); int kvm_xen_set_vcpu_virq(uint32_t vcpu_id, uint16_t virq, uint16_t port); diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index b49a840438..477e93cd92 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -424,6 +424,13 @@ void kvm_xen_set_callback_asserted(void) } } =20 +bool kvm_xen_has_vcpu_callback_vector(void) +{ + CPUState *cs =3D qemu_get_cpu(0); + + return cs && !!X86_CPU(cs)->env.xen_vcpu_callback_vector; +} + void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_id, int type) { CPUState *cs =3D qemu_get_cpu(vcpu_id); --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469637; cv=none; d=zohomail.com; s=zohoarc; b=Q6sYIz8UuaFr8IeDArIp9JoLuyaWZtcTroio7qIb566Z8X+hUOWw56o2o8xD/euMQt80QHHfajDY6Jm7j+a66Cuuux0By1JoiDd+kfhhMdF7XD6a2PA3PjMvHf2VbXDOQV0SLS1vCx/B7TaFpUKKRzgV10dW9W2sEDBYGkJ3nL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469637; 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=oXIYkBgWqGifderSC1Ie6itfGDjOSlFxOetg0dgIlJc=; b=jDqLLZu7BFNmIT6s/ZDtT1+o4otSnN7gkE/hAZigNBS8VRHmGMqwNTtPGD7AXMwEedaTF/CQEdJdbAZR3ejfSGJYmUQk3e1URftvAohn1H59/DY5FMJAm9X3OfZLV3b8RflJoo0ULCZHYXtOO7UPXIepvm6joxvVxDBTeHQImG4= 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 1697469637473579.5841541707881; Mon, 16 Oct 2023 08:20:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617760.960787 (Exim 4.92) (envelope-from ) id 1qsPNh-0004TL-Oa; Mon, 16 Oct 2023 15:19:45 +0000 Received: by outflank-mailman (output) from mailman id 617760.960787; Mon, 16 Oct 2023 15:19:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNh-0004Pp-4o; Mon, 16 Oct 2023 15:19:45 +0000 Received: by outflank-mailman (input) for mailman id 617760; Mon, 16 Oct 2023 15:19:43 +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 1qsPNe-0001wi-Fc for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:42 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6d093efc-6c37-11ee-98d4-6d05b1d4d9a1; Mon, 16 Oct 2023 17:19:40 +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 1qsPNC-006lqZ-25; Mon, 16 Oct 2023 15:19:14 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0005nH-2M; Mon, 16 Oct 2023 16:19:13 +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: 6d093efc-6c37-11ee-98d4-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=oXIYkBgWqGifderSC1Ie6itfGDjOSlFxOetg0dgIlJc=; b=ZqvA1DHpT6EVnq1euEg0gDCBf9 zSVGzt6IKidO+fSnJxuFNxyeMPQL1z4FjZ52x3GefUUC6Uo8d/aytm/h1jw9qocdhjZOGcX8RiyNS NIpXSPw9iBK2BXZHrRwUM/8MG3xzuwa+lCIyyepUvCecX3XN3rySeoEx1lbB2MAt1Td1WAqF/KCUo csjWxFKfaZjk7AFxeU0WHuCkFAVqzh6Oie8noyrWhXdxXQ5/R6x6DNX9VMqv/tfkgjXT0l/i47BAF KVuWXsTz1qp/yBCO3SEPd2iyx53DEPo/MkMutsbbPAeUOCiYx+LHqT9hQca33aVMaGRqhtIDC75S4 ODl5+8Sg==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 03/12] include: update Xen public headers to Xen 4.17.2 release Date: Mon, 16 Oct 2023 16:19:00 +0100 Message-Id: <20231016151909.22133-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-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: 1697469639459100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse ... in order to advertise the XEN_HVM_CPUID_UPCALL_VECTOR feature, which will come in a subsequent commit. Signed-off-by: David Woodhouse Acked-by: Paul Durrant --- hw/i386/kvm/xen_xenstore.c | 2 +- include/hw/xen/interface/arch-arm.h | 37 +++++++------- include/hw/xen/interface/arch-x86/cpuid.h | 31 +++++------- .../hw/xen/interface/arch-x86/xen-x86_32.h | 19 +------ .../hw/xen/interface/arch-x86/xen-x86_64.h | 19 +------ include/hw/xen/interface/arch-x86/xen.h | 26 ++-------- include/hw/xen/interface/event_channel.h | 19 +------ include/hw/xen/interface/features.h | 19 +------ include/hw/xen/interface/grant_table.h | 19 +------ include/hw/xen/interface/hvm/hvm_op.h | 19 +------ include/hw/xen/interface/hvm/params.h | 19 +------ include/hw/xen/interface/io/blkif.h | 27 ++++------ include/hw/xen/interface/io/console.h | 19 +------ include/hw/xen/interface/io/fbif.h | 19 +------ include/hw/xen/interface/io/kbdif.h | 19 +------ include/hw/xen/interface/io/netif.h | 25 +++------- include/hw/xen/interface/io/protocols.h | 19 +------ include/hw/xen/interface/io/ring.h | 49 ++++++++++--------- include/hw/xen/interface/io/usbif.h | 19 +------ include/hw/xen/interface/io/xenbus.h | 19 +------ include/hw/xen/interface/io/xs_wire.h | 36 ++++++-------- include/hw/xen/interface/memory.h | 30 +++++------- include/hw/xen/interface/physdev.h | 23 ++------- include/hw/xen/interface/sched.h | 19 +------ include/hw/xen/interface/trace.h | 19 +------ include/hw/xen/interface/vcpu.h | 19 +------ include/hw/xen/interface/version.h | 19 +------ include/hw/xen/interface/xen-compat.h | 19 +------ include/hw/xen/interface/xen.h | 19 +------ 29 files changed, 124 insertions(+), 523 deletions(-) diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index 660d0b72f9..d2b311109b 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -331,7 +331,7 @@ static void xs_error(XenXenstoreState *s, unsigned int = id, const char *errstr =3D NULL; =20 for (unsigned int i =3D 0; i < ARRAY_SIZE(xsd_errors); i++) { - struct xsd_errors *xsd_error =3D &xsd_errors[i]; + const struct xsd_errors *xsd_error =3D &xsd_errors[i]; =20 if (xsd_error->errnum =3D=3D errnum) { errstr =3D xsd_error->errstring; diff --git a/include/hw/xen/interface/arch-arm.h b/include/hw/xen/interface= /arch-arm.h index 94b31511dd..1528ced509 100644 --- a/include/hw/xen/interface/arch-arm.h +++ b/include/hw/xen/interface/arch-arm.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * arch-arm.h * * Guest OS interface to ARM Xen. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright 2011 (C) Citrix Systems */ =20 @@ -361,6 +344,7 @@ typedef uint64_t xen_callback_t; #define PSR_DBG_MASK (1<<9) /* arm64: Debug Exception mask */ #define PSR_IT_MASK (0x0600fc00) /* Thumb If-Then Mask */ #define PSR_JAZELLE (1<<24) /* Jazelle Mode */ +#define PSR_Z (1<<30) /* Zero condition flag */ =20 /* 32 bit modes */ #define PSR_MODE_USR 0x10 @@ -383,7 +367,15 @@ typedef uint64_t xen_callback_t; #define PSR_MODE_EL1t 0x04 #define PSR_MODE_EL0t 0x00 =20 -#define PSR_GUEST32_INIT (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE= _SVC) +/* + * We set PSR_Z to be able to boot Linux kernel versions with an invalid + * encoding of the first 8 NOP instructions. See commit a92882a4d270 in + * Linux. + * + * Note that PSR_Z is also set by U-Boot and QEMU -kernel when loading + * zImage kernels on aarch32. + */ +#define PSR_GUEST32_INIT (PSR_Z|PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR= _MODE_SVC) #define PSR_GUEST64_INIT (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_= EL1h) =20 #define SCTLR_GUEST_INIT xen_mk_ullong(0x00c50078) @@ -398,6 +390,10 @@ typedef uint64_t xen_callback_t; =20 /* Physical Address Space */ =20 +/* Virtio MMIO mappings */ +#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000) +#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000) + /* * vGIC mappings: Only one set of mapping is used by the guest. * Therefore they can overlap. @@ -484,6 +480,9 @@ typedef uint64_t xen_callback_t; =20 #define GUEST_VPL011_SPI 32 =20 +#define GUEST_VIRTIO_MMIO_SPI_FIRST 33 +#define GUEST_VIRTIO_MMIO_SPI_LAST 43 + /* PSCI functions */ #define PSCI_cpu_suspend 0 #define PSCI_cpu_off 1 diff --git a/include/hw/xen/interface/arch-x86/cpuid.h b/include/hw/xen/int= erface/arch-x86/cpuid.h index ce46305bee..7ecd16ae05 100644 --- a/include/hw/xen/interface/arch-x86/cpuid.h +++ b/include/hw/xen/interface/arch-x86/cpuid.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * arch-x86/cpuid.h * * CPUID interface to Xen. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2007 Citrix Systems, Inc. * * Authors: @@ -102,6 +85,18 @@ #define XEN_HVM_CPUID_IOMMU_MAPPINGS (1u << 2) #define XEN_HVM_CPUID_VCPU_ID_PRESENT (1u << 3) /* vcpu id is present in = EBX */ #define XEN_HVM_CPUID_DOMID_PRESENT (1u << 4) /* domid is present in EC= X */ +/* + * With interrupt format set to 0 (non-remappable) bits 55:49 from the + * IO-APIC RTE and bits 11:5 from the MSI address can be used to store + * high bits for the Destination ID. This expands the Destination ID + * field from 8 to 15 bits, allowing to target APIC IDs up 32768. + */ +#define XEN_HVM_CPUID_EXT_DEST_ID (1u << 5) +/* + * Per-vCPU event channel upcalls work correctly with physical IRQs + * bound to event channels. + */ +#define XEN_HVM_CPUID_UPCALL_VECTOR (1u << 6) =20 /* * Leaf 6 (0x40000x05) diff --git a/include/hw/xen/interface/arch-x86/xen-x86_32.h b/include/hw/xe= n/interface/arch-x86/xen-x86_32.h index 19d7388633..139438e835 100644 --- a/include/hw/xen/interface/arch-x86/xen-x86_32.h +++ b/include/hw/xen/interface/arch-x86/xen-x86_32.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * xen-x86_32.h * * Guest OS interface to x86 32-bit Xen. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2004-2007, K A Fraser */ =20 diff --git a/include/hw/xen/interface/arch-x86/xen-x86_64.h b/include/hw/xe= n/interface/arch-x86/xen-x86_64.h index 40aed14366..5d9035ed22 100644 --- a/include/hw/xen/interface/arch-x86/xen-x86_64.h +++ b/include/hw/xen/interface/arch-x86/xen-x86_64.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * xen-x86_64.h * * Guest OS interface to x86 64-bit Xen. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2004-2006, K A Fraser */ =20 diff --git a/include/hw/xen/interface/arch-x86/xen.h b/include/hw/xen/inter= face/arch-x86/xen.h index 7acd94c8eb..c0f4551247 100644 --- a/include/hw/xen/interface/arch-x86/xen.h +++ b/include/hw/xen/interface/arch-x86/xen.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * arch-x86/xen.h * * Guest OS interface to x86 Xen. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2004-2006, K A Fraser */ =20 @@ -320,12 +303,9 @@ struct xen_arch_domainconfig { uint32_t misc_flags; }; =20 -/* Location of online VCPU bitmap. */ -#define XEN_ACPI_CPU_MAP 0xaf00 -#define XEN_ACPI_CPU_MAP_LEN ((HVM_MAX_VCPUS + 7) / 8) +/* Max XEN_X86_* constant. Used for ABI checking. */ +#define XEN_X86_MISC_FLAGS_MAX XEN_X86_MSR_RELAXED =20 -/* GPE0 bit set during CPU hotplug */ -#define XEN_ACPI_GPE0_CPUHP_BIT 2 #endif =20 /* diff --git a/include/hw/xen/interface/event_channel.h b/include/hw/xen/inte= rface/event_channel.h index 73c9f38ce1..0d91a1c4af 100644 --- a/include/hw/xen/interface/event_channel.h +++ b/include/hw/xen/interface/event_channel.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * event_channel.h * * Event channels between domains. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2003-2004, K A Fraser. */ =20 diff --git a/include/hw/xen/interface/features.h b/include/hw/xen/interface= /features.h index 9ee2f760ef..d2a9175aae 100644 --- a/include/hw/xen/interface/features.h +++ b/include/hw/xen/interface/features.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * features.h * * Feature flags, reported by XENVER_get_features. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2006, Keir Fraser */ =20 diff --git a/include/hw/xen/interface/grant_table.h b/include/hw/xen/interf= ace/grant_table.h index 7934d7b718..1dfa17a6d0 100644 --- a/include/hw/xen/interface/grant_table.h +++ b/include/hw/xen/interface/grant_table.h @@ -1,27 +1,10 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * grant_table.h * * Interface for granting foreign access to page frames, and receiving * page-ownership transfers. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2004, K A Fraser */ =20 diff --git a/include/hw/xen/interface/hvm/hvm_op.h b/include/hw/xen/interfa= ce/hvm/hvm_op.h index 870ec52060..e22adf0319 100644 --- a/include/hw/xen/interface/hvm/hvm_op.h +++ b/include/hw/xen/interface/hvm/hvm_op.h @@ -1,22 +1,5 @@ +/* SPDX-License-Identifier: MIT */ /* - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2007, Keir Fraser */ =20 diff --git a/include/hw/xen/interface/hvm/params.h b/include/hw/xen/interfa= ce/hvm/params.h index c9d6e70d7b..a22b4ed45d 100644 --- a/include/hw/xen/interface/hvm/params.h +++ b/include/hw/xen/interface/hvm/params.h @@ -1,22 +1,5 @@ +/* SPDX-License-Identifier: MIT */ /* - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2007, Keir Fraser */ =20 diff --git a/include/hw/xen/interface/io/blkif.h b/include/hw/xen/interface= /io/blkif.h index 4cdba79aba..22f1eef0c0 100644 --- a/include/hw/xen/interface/io/blkif.h +++ b/include/hw/xen/interface/io/blkif.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * blkif.h * * Unified block-device I/O interface for Xen guest OSes. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2003-2004, Keir Fraser * Copyright (c) 2012, Spectra Logic Corporation */ @@ -363,6 +346,14 @@ * that the frontend requires that the logical block size is 512 as it * is hardcoded (which is the case in some frontend implementations). * + * trusted + * Values: 0/1 (boolean) + * Default value: 1 + * + * A value of "0" indicates that the frontend should not trust the + * backend, and should deploy whatever measures available to protect = from + * a malicious backend on the other end. + * *------------------------- Virtual Device Properties --------------------= ----- * * device-type diff --git a/include/hw/xen/interface/io/console.h b/include/hw/xen/interfa= ce/io/console.h index 4811f47220..4509b4b689 100644 --- a/include/hw/xen/interface/io/console.h +++ b/include/hw/xen/interface/io/console.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * console.h * * Console I/O interface for Xen guest OSes. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2005, Keir Fraser */ =20 diff --git a/include/hw/xen/interface/io/fbif.h b/include/hw/xen/interface/= io/fbif.h index cc25aab32e..93c73195d8 100644 --- a/include/hw/xen/interface/io/fbif.h +++ b/include/hw/xen/interface/io/fbif.h @@ -1,24 +1,7 @@ +/* SPDX-License-Identifier: MIT */ /* * fbif.h -- Xen virtual frame buffer device * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (C) 2005 Anthony Liguori * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster */ diff --git a/include/hw/xen/interface/io/kbdif.h b/include/hw/xen/interface= /io/kbdif.h index a6b01c52c7..4bde6b3821 100644 --- a/include/hw/xen/interface/io/kbdif.h +++ b/include/hw/xen/interface/io/kbdif.h @@ -1,24 +1,7 @@ +/* SPDX-License-Identifier: MIT */ /* * kbdif.h -- Xen virtual keyboard/mouse * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (C) 2005 Anthony Liguori * Copyright (C) 2006 Red Hat, Inc., Markus Armbruster */ diff --git a/include/hw/xen/interface/io/netif.h b/include/hw/xen/interface= /io/netif.h index 00dd258712..c13b85061d 100644 --- a/include/hw/xen/interface/io/netif.h +++ b/include/hw/xen/interface/io/netif.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * netif.h * * Unified network-device I/O interface for Xen guest OSes. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2003-2004, Keir Fraser */ =20 @@ -160,6 +143,12 @@ * be applied if it is set. */ =20 +/* + * The setting of "trusted" node to "0" in the frontend path signals that = the + * frontend should not trust the backend, and should deploy whatever measu= res + * available to protect from a malicious backend on the other end. + */ + /* * Control ring * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/include/hw/xen/interface/io/protocols.h b/include/hw/xen/inter= face/io/protocols.h index 52b4de0f81..7815e1ff0f 100644 --- a/include/hw/xen/interface/io/protocols.h +++ b/include/hw/xen/interface/io/protocols.h @@ -1,24 +1,7 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * protocols.h * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2008, Keir Fraser */ =20 diff --git a/include/hw/xen/interface/io/ring.h b/include/hw/xen/interface/= io/ring.h index c486c457e0..025939278b 100644 --- a/include/hw/xen/interface/io/ring.h +++ b/include/hw/xen/interface/io/ring.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * ring.h * * Shared producer-consumer ring macros. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Tim Deegan and Andrew Warfield November 2004. */ =20 @@ -95,9 +78,8 @@ typedef unsigned int RING_IDX; * of the shared memory area (PAGE_SIZE, for instance). To initialise * the front half: * - * mytag_front_ring_t front_ring; - * SHARED_RING_INIT((mytag_sring_t *)shared_page); - * FRONT_RING_INIT(&front_ring, (mytag_sring_t *)shared_page, PAGE_SIZ= E); + * mytag_front_ring_t ring; + * XEN_FRONT_RING_INIT(&ring, (mytag_sring_t *)shared_page, PAGE_SIZE); * * Initializing the back follows similarly (note that only the front * initializes the shared ring): @@ -184,6 +166,11 @@ typedef struct __name##_back_ring __name##_back_ring_t =20 #define FRONT_RING_INIT(_r, _s, __size) FRONT_RING_ATTACH(_r, _s, 0, __siz= e) =20 +#define XEN_FRONT_RING_INIT(r, s, size) do { \ + SHARED_RING_INIT(s); \ + FRONT_RING_INIT(r, s, size); \ +} while (0) + #define BACK_RING_ATTACH(_r, _s, _i, __size) do { \ (_r)->rsp_prod_pvt =3D (_i); \ (_r)->req_cons =3D (_i); \ @@ -208,11 +195,11 @@ typedef struct __name##_back_ring __name##_back_ring_t (RING_FREE_REQUESTS(_r) =3D=3D 0) =20 /* Test if there are outstanding messages to be processed on a ring. */ -#define RING_HAS_UNCONSUMED_RESPONSES(_r) \ +#define XEN_RING_NR_UNCONSUMED_RESPONSES(_r) \ ((_r)->sring->rsp_prod - (_r)->rsp_cons) =20 #ifdef __GNUC__ -#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ \ +#define XEN_RING_NR_UNCONSUMED_REQUESTS(_r) ({ \ unsigned int req =3D (_r)->sring->req_prod - (_r)->req_cons; \ unsigned int rsp =3D RING_SIZE(_r) - \ ((_r)->req_cons - (_r)->rsp_prod_pvt); \ @@ -220,13 +207,27 @@ typedef struct __name##_back_ring __name##_back_ring_t }) #else /* Same as above, but without the nice GCC ({ ... }) syntax. */ -#define RING_HAS_UNCONSUMED_REQUESTS(_r) \ +#define XEN_RING_NR_UNCONSUMED_REQUESTS(_r) \ ((((_r)->sring->req_prod - (_r)->req_cons) < \ (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) ? \ ((_r)->sring->req_prod - (_r)->req_cons) : \ (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) #endif =20 +#ifdef XEN_RING_HAS_UNCONSUMED_IS_BOOL +/* + * These variants should only be used in case no caller is abusing them for + * obtaining the number of unconsumed responses/requests. + */ +#define RING_HAS_UNCONSUMED_RESPONSES(_r) \ + (!!XEN_RING_NR_UNCONSUMED_RESPONSES(_r)) +#define RING_HAS_UNCONSUMED_REQUESTS(_r) \ + (!!XEN_RING_NR_UNCONSUMED_REQUESTS(_r)) +#else +#define RING_HAS_UNCONSUMED_RESPONSES(_r) XEN_RING_NR_UNCONSUMED_RESPONSES= (_r) +#define RING_HAS_UNCONSUMED_REQUESTS(_r) XEN_RING_NR_UNCONSUMED_REQUESTS(= _r) +#endif + /* Direct access to individual ring elements, by index. */ #define RING_GET_REQUEST(_r, _idx) \ (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req)) diff --git a/include/hw/xen/interface/io/usbif.h b/include/hw/xen/interface= /io/usbif.h index c0a552e195..875af0dc7c 100644 --- a/include/hw/xen/interface/io/usbif.h +++ b/include/hw/xen/interface/io/usbif.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: MIT */ /* * usbif.h * @@ -5,24 +6,6 @@ * * Copyright (C) 2009, FUJITSU LABORATORIES LTD. * Author: Noboru Iwamatsu - * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. */ =20 #ifndef __XEN_PUBLIC_IO_USBIF_H__ diff --git a/include/hw/xen/interface/io/xenbus.h b/include/hw/xen/interfac= e/io/xenbus.h index 927f9db552..9cd0cd7c67 100644 --- a/include/hw/xen/interface/io/xenbus.h +++ b/include/hw/xen/interface/io/xenbus.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= **** * xenbus.h * * Xenbus protocol details. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (C) 2005 XenSource Ltd. */ =20 diff --git a/include/hw/xen/interface/io/xs_wire.h b/include/hw/xen/interfa= ce/io/xs_wire.h index 4dd6632669..04e6849feb 100644 --- a/include/hw/xen/interface/io/xs_wire.h +++ b/include/hw/xen/interface/io/xs_wire.h @@ -1,25 +1,8 @@ +/* SPDX-License-Identifier: MIT */ /* * Details of the "wire" protocol between Xen Store Daemon and client * library or guest kernel. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (C) 2005 Rusty Russell IBM Corporation */ =20 @@ -71,11 +54,12 @@ struct xsd_errors #ifdef EINVAL #define XSD_ERROR(x) { x, #x } /* LINTED: static unused */ -static struct xsd_errors xsd_errors[] +static const struct xsd_errors xsd_errors[] #if defined(__GNUC__) __attribute__((unused)) #endif =3D { + /* /!\ New errors should be added at the end of the array. */ XSD_ERROR(EINVAL), XSD_ERROR(EACCES), XSD_ERROR(EEXIST), @@ -90,7 +74,8 @@ __attribute__((unused)) XSD_ERROR(EBUSY), XSD_ERROR(EAGAIN), XSD_ERROR(EISCONN), - XSD_ERROR(E2BIG) + XSD_ERROR(E2BIG), + XSD_ERROR(EPERM), }; #endif =20 @@ -124,6 +109,7 @@ struct xenstore_domain_interface { XENSTORE_RING_IDX rsp_cons, rsp_prod; uint32_t server_features; /* Bitmap of features supported by the serve= r */ uint32_t connection; + uint32_t error; }; =20 /* Violating this is very bad. See docs/misc/xenstore.txt. */ @@ -135,10 +121,18 @@ struct xenstore_domain_interface { =20 /* The ability to reconnect a ring */ #define XENSTORE_SERVER_FEATURE_RECONNECTION 1 +/* The presence of the "error" field in the ring page */ +#define XENSTORE_SERVER_FEATURE_ERROR 2 =20 /* Valid values for the connection field */ #define XENSTORE_CONNECTED 0 /* the steady-state */ -#define XENSTORE_RECONNECT 1 /* guest has initiated a reconnect */ +#define XENSTORE_RECONNECT 1 /* reconnect in progress */ + +/* Valid values for the error field */ +#define XENSTORE_ERROR_NONE 0 /* No error */ +#define XENSTORE_ERROR_COMM 1 /* Communication problem */ +#define XENSTORE_ERROR_RINGIDX 2 /* Invalid ring index */ +#define XENSTORE_ERROR_PROTO 3 /* Protocol violation (payload too long) = */ =20 #endif /* _XS_WIRE_H */ =20 diff --git a/include/hw/xen/interface/memory.h b/include/hw/xen/interface/m= emory.h index 383a9468c3..29cf5c8239 100644 --- a/include/hw/xen/interface/memory.h +++ b/include/hw/xen/interface/memory.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * memory.h * * Memory reservation and information. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2005, Keir Fraser */ =20 @@ -541,12 +524,14 @@ struct xen_mem_sharing_op { uint32_t gref; /* IN: gref to debug */ } u; } debug; - struct mem_sharing_op_fork { /* OP_FORK */ + struct mem_sharing_op_fork { /* OP_FORK{,_RESET} */ domid_t parent_domain; /* IN: parent's domain id */ /* Only makes sense for short-lived forks */ #define XENMEM_FORK_WITH_IOMMU_ALLOWED (1u << 0) /* Only makes sense for short-lived forks */ #define XENMEM_FORK_BLOCK_INTERRUPTS (1u << 1) +#define XENMEM_FORK_RESET_STATE (1u << 2) +#define XENMEM_FORK_RESET_MEMORY (1u << 3) uint16_t flags; /* IN: optional settings */ uint32_t pad; /* Must be set to 0 */ } fork; @@ -662,6 +647,13 @@ struct xen_mem_acquire_resource { * two calls. */ uint32_t nr_frames; + /* + * Padding field, must be zero on input. + * In a previous version this was an output field with the lowest bit + * named XENMEM_rsrc_acq_caller_owned. Future versions of this interfa= ce + * will not reuse this bit as an output with the field being zero on + * input. + */ uint32_t pad; /* * IN - the index of the initial frame to be mapped. This parameter diff --git a/include/hw/xen/interface/physdev.h b/include/hw/xen/interface/= physdev.h index d271766ad0..f0c0d4727c 100644 --- a/include/hw/xen/interface/physdev.h +++ b/include/hw/xen/interface/physdev.h @@ -1,22 +1,5 @@ +/* SPDX-License-Identifier: MIT */ /* - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2006, Keir Fraser */ =20 @@ -211,8 +194,8 @@ struct physdev_manage_pci_ext { /* IN */ uint8_t bus; uint8_t devfn; - unsigned is_extfn; - unsigned is_virtfn; + uint32_t is_extfn; + uint32_t is_virtfn; struct { uint8_t bus; uint8_t devfn; diff --git a/include/hw/xen/interface/sched.h b/include/hw/xen/interface/sc= hed.h index 811bd87c82..b4362c6a1d 100644 --- a/include/hw/xen/interface/sched.h +++ b/include/hw/xen/interface/sched.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * sched.h * * Scheduler state interactions * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2005, Keir Fraser */ =20 diff --git a/include/hw/xen/interface/trace.h b/include/hw/xen/interface/tr= ace.h index d5fa4aea8d..62a179971d 100644 --- a/include/hw/xen/interface/trace.h +++ b/include/hw/xen/interface/trace.h @@ -1,24 +1,7 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * include/public/trace.h * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Mark Williamson, (C) 2004 Intel Research Cambridge * Copyright (C) 2005 Bin Ren */ diff --git a/include/hw/xen/interface/vcpu.h b/include/hw/xen/interface/vcp= u.h index 3623af932f..81a3b3a743 100644 --- a/include/hw/xen/interface/vcpu.h +++ b/include/hw/xen/interface/vcpu.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * vcpu.h * * VCPU initialisation, query, and hotplug. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2005, Keir Fraser */ =20 diff --git a/include/hw/xen/interface/version.h b/include/hw/xen/interface/= version.h index 17a81e23cd..9c78b4f3b6 100644 --- a/include/hw/xen/interface/version.h +++ b/include/hw/xen/interface/version.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * version.h * * Xen version, type, and compile information. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2005, Nguyen Anh Quynh * Copyright (c) 2005, Keir Fraser */ diff --git a/include/hw/xen/interface/xen-compat.h b/include/hw/xen/interfa= ce/xen-compat.h index e1c027a95c..97fe698498 100644 --- a/include/hw/xen/interface/xen-compat.h +++ b/include/hw/xen/interface/xen-compat.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * xen-compat.h * * Guest OS interface to Xen. Compatibility layer. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2006, Christian Limpach */ =20 diff --git a/include/hw/xen/interface/xen.h b/include/hw/xen/interface/xen.h index e373592c33..920567e006 100644 --- a/include/hw/xen/interface/xen.h +++ b/include/hw/xen/interface/xen.h @@ -1,26 +1,9 @@ +/* SPDX-License-Identifier: MIT */ /*************************************************************************= ***** * xen.h * * Guest OS interface to Xen. * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation = the - * rights to use, copy, modify, merge, publish, distribute, sublicense, an= d/or - * sell copies of the Software, and to permit persons to whom the Software= is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * * Copyright (c) 2004, K A Fraser */ =20 --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469613; cv=none; d=zohomail.com; s=zohoarc; b=JNow7MyHppsnLUNI95hhuIm7qdou3jVtotUJrhSUmOzVppWxXq+Wetf5zlnJgv/yGp6JGUJv1K/JsnzgP+C5tD+bvz2Z6HaG+pf8xkUlO7K8onL+Pxe+dHYV7Sx2AVGZc1VCT4p6op2p6lwjNaZRSxvXmXmbrbqZjBfNzGhUqls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469613; 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=iXDULQVzCobMyEZ4WUylbwZd7CUi+M/tuPLUTKt/3jw=; b=NIWAM2e1EcjsUkukNCNVPlDB5z+8kWyvExOnj5wVF7tUQn2kP2Aku6UxCzGL7u1dd+QmUS9q1zf/QqUqJ8N5vC0EVu+HarYs+oIXWuXa0Hus5NGECQRW+eykmf9EjL0pBi43FUkX1/kQOdWyiHq65iKV88Sn/HuCYZh5WR+oMC8= 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 1697469613959985.5434473628211; Mon, 16 Oct 2023 08:20:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617755.960745 (Exim 4.92) (envelope-from ) id 1qsPNd-0003OM-JZ; Mon, 16 Oct 2023 15:19:41 +0000 Received: by outflank-mailman (output) from mailman id 617755.960745; Mon, 16 Oct 2023 15:19:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNd-0003L9-DM; Mon, 16 Oct 2023 15:19:41 +0000 Received: by outflank-mailman (input) for mailman id 617755; Mon, 16 Oct 2023 15:19:39 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNb-0001wj-3Y for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:39 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6a187ae1-6c37-11ee-9b0e-b553b5be7939; Mon, 16 Oct 2023 17:19:35 +0200 (CEST) Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0067AH-2I; Mon, 16 Oct 2023 15:19:15 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0005nK-2S; Mon, 16 Oct 2023 16:19:13 +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: 6a187ae1-6c37-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=iXDULQVzCobMyEZ4WUylbwZd7CUi+M/tuPLUTKt/3jw=; b=l1d5jbcw6JNVUwXd23LtcOWIrz awoQAWR2TcM4l7zFuNYfHDL5IW5doK4mER0sDrz9GFfi7g/6TGn1GKF7Nh4SXaBj7lExkZqV/6OBu BFw1UTrhAyKXsOt9PwCTU2pMxqKJdP2htFgualbxn+lvN/uSw/zpRypzgvobUd3b+niKIDlRnOUN0 y25iFrORunLd1zKmTJ4gAmMrkYqYU3tM4LCEhYMpEqbeBcCd11W2GY5HtBdadVn3PG+6tuK2XfGfg nLsgelc99k1Us9mOk0LZPdAD9438EocKtKfbD+cMKYAq2PLkAUu3jedsBUI2LXJKDiK3BJ8DZHlBK 82Uotnsw==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 04/12] i386/xen: advertise XEN_HVM_CPUID_UPCALL_VECTOR in CPUID Date: Mon, 16 Oct 2023 16:19:01 +0100 Message-Id: <20231016151909.22133-5-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-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 desiato.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1697469615260100007 Content-Type: text/plain; charset="utf-8" From: David Woodhouse This will allow Linux guests (since v6.0) to use the per-vCPU upcall vector delivered as MSI through the local APIC. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- target/i386/kvm/kvm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index f6c7f7e268..8bdbdcdffe 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1887,6 +1887,10 @@ int kvm_arch_init_vcpu(CPUState *cs) c->eax |=3D XEN_HVM_CPUID_VCPU_ID_PRESENT; c->ebx =3D cs->cpu_index; } + + if (cs->kvm_state->xen_version >=3D XEN_VERSION(4, 17)) { + c->eax |=3D XEN_HVM_CPUID_UPCALL_VECTOR; + } } =20 r =3D kvm_xen_init_vcpu(cs); --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469605; cv=none; d=zohomail.com; s=zohoarc; b=M4vWDdK5gI0e+vCAtNvSE4ALb1DTJ9VeWPYd+Be6M0wcgtfnr3K1m8GpF+Jrlnwi/S+R1a46T6zTnf0n8XALeKEaa6NBPh4SC5wFiubgjKaaG11MTsaGA257MFSSMkjKNeD873QX/HNtkLt+9mXJpGsRF6M4ztbI+f7bbp3BsQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469605; 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=f7F9SDM1bUdOvNZpQs4iJJJk6zsJmxlOCqdnVelp0m8=; b=RY5i/162hEoK7XmgCH4Dhj9NOAakw+1dqAjR3ZTKd4sTFir5rKQmzWiT83ZvbSGHVTPYLyM5Sq21fztLYSOAC5+PSO7zxJpCkZzVRbyv09V2qx/1y32jBon2tQKyTZ1ez3mUZzGett+au1cqSSFfTdO8sg+ihHtXdYCH3pIDlvY= 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 1697469605472867.8006397996379; Mon, 16 Oct 2023 08:20:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617748.960685 (Exim 4.92) (envelope-from ) id 1qsPNZ-0001xG-Kx; Mon, 16 Oct 2023 15:19:37 +0000 Received: by outflank-mailman (output) from mailman id 617748.960685; Mon, 16 Oct 2023 15:19:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNZ-0001x9-Hg; Mon, 16 Oct 2023 15:19:37 +0000 Received: by outflank-mailman (input) for mailman id 617748; Mon, 16 Oct 2023 15:19:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNX-0001wj-Pu for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:35 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 67e39f91-6c37-11ee-9b0e-b553b5be7939; Mon, 16 Oct 2023 17:19:32 +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 1qsPNC-006lqa-6s; Mon, 16 Oct 2023 15:19:14 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0005nO-2c; Mon, 16 Oct 2023 16:19:13 +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: 67e39f91-6c37-11ee-9b0e-b553b5be7939 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=f7F9SDM1bUdOvNZpQs4iJJJk6zsJmxlOCqdnVelp0m8=; b=JI9Cp5t4Jep1lUjFFL+2rPgVxX C+t5NGWYH8UJ/aniIMYUBrCu0fIU9iTJ+vTpef8EEAB7SClGjGZM/EHHHHvzHfaviA3kVmuw1wCTJ N7L+3vVvqu10dZZELOd1F/uW8Zt80B+gQ/ZJhmZDGhB0DYFzJigrRm1rtICjhe0g+3KEYcdPGyHO9 wYtpxo1U140xHjDKeY1hLWRucnyzVL4t3HlKbqhCq7zFNEb1R7eKbY7k1Xudw5PNi5r3ohP/2s063 dGaCe88IwhB57Kh2/CRrEW4ABoisGKH9B0hgP5tyFACRikVrXcHTs55vFS4Nh/i/uiTWMq4zN+miS eO7T8Hpg==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 05/12] hw/xen: populate store frontend nodes with XenStore PFN/port Date: Mon, 16 Oct 2023 16:19:02 +0100 Message-Id: <20231016151909.22133-6-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-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: 1697469607243100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse This is kind of redundant since without being able to get these through ome other method (HVMOP_get_param) the guest wouldn't be able to access XenStore in order to find them. But Xen populates them, and it does allow guests to *rebind* to the event channel port after a reset. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/kvm/xen_xenstore.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index d2b311109b..3300e0614a 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -1432,6 +1432,7 @@ static void alloc_guest_port(XenXenstoreState *s) int xen_xenstore_reset(void) { XenXenstoreState *s =3D xen_xenstore_singleton; + GList *perms; int err; =20 if (!s) { @@ -1459,6 +1460,15 @@ int xen_xenstore_reset(void) } s->be_port =3D err; =20 + /* Create frontend store nodes */ + perms =3D g_list_append(NULL, xs_perm_as_string(XS_PERM_NONE, DOMID_QE= MU)); + perms =3D g_list_append(perms, xs_perm_as_string(XS_PERM_READ, xen_dom= id)); + + relpath_printf(s, perms, "store/ring-ref", "%lu", XEN_SPECIAL_PFN(XENS= TORE)); + relpath_printf(s, perms, "store/port", "%u", s->be_port); + + g_list_free_full(perms, g_free); + /* * We don't actually access the guest's page through the grant, because * this isn't real Xen, and we can just use the page we gave it in the --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469615; cv=none; d=zohomail.com; s=zohoarc; b=KJVxTgFYwLmUDhyEir7h6iYaaBoLmstbMaXRycv8tKfdfAgbpfgYMZR1RtBKcgWAWUj6O/LWkiTjqNDvnPqYcAmNSUE3mSTdEXZgYVQIh8Wlff8F1EUf9GJiIOc1qGNs4414Do9ePtbmLbYMLSJtDxQoIIdA7f7URgXbGdtQg3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469615; h=Content-Type: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=j10esoq0FJNH76opTx2Ikt3KjCQW6JceQg/cwlpclKs=; b=dmW4io1Tnf7CnWS7FUjh2TGJqv7SQZu0QCxeIaDXyC6GD2/rSpXsfJegs9lpww9nAOSwvyU2R9tnXXv5365Kw18q3LVpFfOCYA1awCmGJUXRGK6PFTqRSdKzMnH9jmnfQlE+1wYe2ZT2WeKibzIdYOGt0/ei9V2dRhQdt+lA3ZU= 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 1697469615926259.457385299258; Mon, 16 Oct 2023 08:20:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617751.960703 (Exim 4.92) (envelope-from ) id 1qsPNa-0002Be-II; Mon, 16 Oct 2023 15:19:38 +0000 Received: by outflank-mailman (output) from mailman id 617751.960703; Mon, 16 Oct 2023 15:19:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNa-00028g-9N; Mon, 16 Oct 2023 15:19:38 +0000 Received: by outflank-mailman (input) for mailman id 617751; Mon, 16 Oct 2023 15:19:36 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNY-0001wj-Fn for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:36 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 685c8466-6c37-11ee-9b0e-b553b5be7939; Mon, 16 Oct 2023 17:19:32 +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 1qsPNC-006lqb-6o; Mon, 16 Oct 2023 15:19:14 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0005nS-2q; Mon, 16 Oct 2023 16:19:13 +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: 685c8466-6c37-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description; bh=j10esoq0FJNH76opTx2Ikt3KjCQW6JceQg/cwlpclKs=; b=ZduFMOvoJdtQDogmTwvZyLrQi7 L5xONBMXumaxapRtcqiXoK0WZgkbhT065bsjcEyhBGwuMIgptpB+Id+ZQY8bIRlZe9ln/4+PdOeGo sRrlHgzM1xlelgVAmfltZTG1qwyquW2mixVDt8Q3NPEIRXTs5OScTehD4TDup9ceZaeNOVgVKaO/k xfvAmlGJ9gM3gJfpvmnFvi6WybtURPVTOKJDAxxygl85ZTIUgL96GiUP0wtXt84zGw/tALtO/CLco kb3nRQ4/tOtXtXPZJUqhKO2Di+M1vNQXeU8zftYCP05E4/AU8kkLeYHDAoGoofY0asYS/bSwngSOY 0rPBEqUA==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 06/12] hw/xen: add get_frontend_path() method to XenDeviceClass Date: Mon, 16 Oct 2023 16:19:03 +0100 Message-Id: <20231016151909.22133-7-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: 1697469617274100015 From: David Woodhouse The primary Xen console is special. The guest's side is set up for it by the toolstack automatically and not by the standard PV init sequence. Accordingly, its *frontend* doesn't appear in =E2=80=A6/device/console/0 ei= ther; instead it appears under =E2=80=A6/console in the guest's XenStore node. To allow the Xen console driver to override the frontend path for the primary console, add a method to the XenDeviceClass which can be used instead of the standard xen_device_get_frontend_path() Signed-off-by: David Woodhouse --- hw/xen/xen-bus.c | 10 +++++++++- include/hw/xen/xen-bus.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index ece8ec40cd..cc524ed92c 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -711,8 +711,16 @@ static void xen_device_frontend_create(XenDevice *xend= ev, Error **errp) { ERRP_GUARD(); XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); + XenDeviceClass *xendev_class =3D XEN_DEVICE_GET_CLASS(xendev); =20 - xendev->frontend_path =3D xen_device_get_frontend_path(xendev); + if (xendev_class->get_frontend_path) { + xendev->frontend_path =3D xendev_class->get_frontend_path(xendev, = errp); + if (!xendev->frontend_path) { + return; + } + } else { + xendev->frontend_path =3D xen_device_get_frontend_path(xendev); + } =20 /* * The frontend area may have already been created by a legacy diff --git a/include/hw/xen/xen-bus.h b/include/hw/xen/xen-bus.h index f435898164..eb440880b5 100644 --- a/include/hw/xen/xen-bus.h +++ b/include/hw/xen/xen-bus.h @@ -33,6 +33,7 @@ struct XenDevice { }; typedef struct XenDevice XenDevice; =20 +typedef char *(*XenDeviceGetFrontendPath)(XenDevice *xendev, Error **errp); typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp); typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp); typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev, @@ -46,6 +47,7 @@ struct XenDeviceClass { /*< public >*/ const char *backend; const char *device; + XenDeviceGetFrontendPath get_frontend_path; XenDeviceGetName get_name; XenDeviceRealize realize; XenDeviceFrontendChanged frontend_changed; --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469613; cv=none; d=zohomail.com; s=zohoarc; b=m6wZ0ffuKjWCJK4j/+eH7iN3E8SwREHZWg7TSjAmtTe10K+njI3BEMd/P+GQ3xCBUuRWJCMO4hOB05UGR5D11CuRmYIkMkiheYpvCgmCXX1hjhgNlpKQ9+zScRJK2Zo3UUIjZrMSAYhlZ68o9xjcuEkNzcC7GBCCjfYG/S29ckc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469613; 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=MW+VqkBMBDTx8qpmwaHvLd47tVYOYFHTVMg8ZLGqw+E=; b=RlLkd+M06VGxmTqedfG6t6FaITDBFYo35v2W7cMelTEs6myy5Ml1M0xGx66TNjLEtCPYJnEmtDwD3TPytl5Noe8GZHlCgSmqmntenK5t3YbiHUAglpBToSRwsTUQlLYxVtoD+7TDOyll2sdnTaWHfd1grW7Dx8Fu/NCB0GDr1IY= 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 1697469613258108.45631449260168; Mon, 16 Oct 2023 08:20:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617758.960772 (Exim 4.92) (envelope-from ) id 1qsPNg-00043t-2n; Mon, 16 Oct 2023 15:19:44 +0000 Received: by outflank-mailman (output) from mailman id 617758.960772; Mon, 16 Oct 2023 15:19:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNf-00040D-Io; Mon, 16 Oct 2023 15:19:43 +0000 Received: by outflank-mailman (input) for mailman id 617758; Mon, 16 Oct 2023 15:19:40 +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 1qsPNc-0001wi-EQ for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:40 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6c680535-6c37-11ee-98d4-6d05b1d4d9a1; Mon, 16 Oct 2023 17:19:39 +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 1qsPNC-006lqc-Bb; Mon, 16 Oct 2023 15:19:14 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0005nW-37; Mon, 16 Oct 2023 16:19:13 +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: 6c680535-6c37-11ee-98d4-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=MW+VqkBMBDTx8qpmwaHvLd47tVYOYFHTVMg8ZLGqw+E=; b=F6Le8wEulZH/uGxnTtpjVzO9ks 9OnUELoCQHWZpUn/3J6l2TGdPJwLX8s0ZW6hyNfyRPBV+C7+l9seIP59ZPz4k4cKYhhHVS1dDUx4+ PPPZDhIUbz3fykPPx7t2MFnACpZYcs7kJkjS8HweTafNS4o+gzn5cMC7MsQfCvFAriMq7WJis47n4 Y8hwSAY0GPu2RemhT6zyN84lmtbiUjyDrBv+97ojYvjFBLJpZLHiXCtpl3kY6hQ6ebLthx0owWmXN deJEsBA0gren6xtJuy2xDD2w9k3puHr0xO2u8/hy+XyPGvwLve73rWPevvfZ4HXAu0Tm1sbmfA6Hs yWkA8PyA==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 07/12] hw/xen: update Xen console to XenDevice model Date: Mon, 16 Oct 2023 16:19:04 +0100 Message-Id: <20231016151909.22133-8-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-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: 1697469615322100009 Content-Type: text/plain; charset="utf-8" This allows (non-primary) console devices to be created on the command line. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/char/trace-events | 8 + hw/char/xen_console.c | 502 +++++++++++++++++++++++++++--------- hw/xen/xen-legacy-backend.c | 1 - 3 files changed, 381 insertions(+), 130 deletions(-) diff --git a/hw/char/trace-events b/hw/char/trace-events index babf4d35ea..7a398c82a5 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -105,3 +105,11 @@ cadence_uart_baudrate(unsigned baudrate) "baudrate %u" # sh_serial.c sh_serial_read(char *id, unsigned size, uint64_t offs, uint64_t val) " %s = size %d offs 0x%02" PRIx64 " -> 0x%02" PRIx64 sh_serial_write(char *id, unsigned size, uint64_t offs, uint64_t val) "%s = size %d offs 0x%02" PRIx64 " <- 0x%02" PRIx64 + +# xen_console.c +xen_console_connect(unsigned int idx, unsigned int ring_ref, unsigned int = port, unsigned int limit) "idx %u ring_ref %u port %u limit %u" +xen_console_disconnect(unsigned int idx) "idx %u" +xen_console_unrealize(unsigned int idx) "idx %u" +xen_console_realize(unsigned int idx, const char *chrdev) "idx %u chrdev %= s" +xen_console_device_create(unsigned int idx) "idx %u" +xen_console_device_destroy(unsigned int idx) "idx %u" diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 810dae3f44..bd20be116c 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -20,15 +20,19 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/cutils.h" #include #include =20 #include "qapi/error.h" #include "sysemu/sysemu.h" #include "chardev/char-fe.h" -#include "hw/xen/xen-legacy-backend.h" - +#include "hw/xen/xen-backend.h" +#include "hw/xen/xen-bus-helper.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-properties-system.h" #include "hw/xen/interface/io/console.h" +#include "trace.h" =20 struct buffer { uint8_t *data; @@ -39,16 +43,22 @@ struct buffer { }; =20 struct XenConsole { - struct XenLegacyDevice xendev; /* must be first */ + struct XenDevice xendev; /* must be first */ + XenEventChannel *event_channel; + int dev; struct buffer buffer; - char console[XEN_BUFSIZE]; - int ring_ref; + char *fe_path; + unsigned int ring_ref; void *sring; CharBackend chr; int backlog; }; +typedef struct XenConsole XenConsole; + +#define TYPE_XEN_CONSOLE_DEVICE "xen-console" +OBJECT_DECLARE_SIMPLE_TYPE(XenConsole, XEN_CONSOLE_DEVICE) =20 -static void buffer_append(struct XenConsole *con) +static bool buffer_append(XenConsole *con) { struct buffer *buffer =3D &con->buffer; XENCONS_RING_IDX cons, prod, size; @@ -60,7 +70,7 @@ static void buffer_append(struct XenConsole *con) =20 size =3D prod - cons; if ((size =3D=3D 0) || (size > sizeof(intf->out))) - return; + return false; =20 if ((buffer->capacity - buffer->size) < size) { buffer->capacity +=3D (size + 1024); @@ -73,7 +83,7 @@ static void buffer_append(struct XenConsole *con) =20 xen_mb(); intf->out_cons =3D cons; - xen_pv_send_notify(&con->xendev); + xen_device_notify_event_channel(XEN_DEVICE(con), con->event_channel, N= ULL); =20 if (buffer->max_capacity && buffer->size > buffer->max_capacity) { @@ -89,6 +99,7 @@ static void buffer_append(struct XenConsole *con) if (buffer->consumed > buffer->max_capacity - over) buffer->consumed =3D buffer->max_capacity - over; } + return true; } =20 static void buffer_advance(struct buffer *buffer, size_t len) @@ -100,7 +111,7 @@ static void buffer_advance(struct buffer *buffer, size_= t len) } } =20 -static int ring_free_bytes(struct XenConsole *con) +static int ring_free_bytes(XenConsole *con) { struct xencons_interface *intf =3D con->sring; XENCONS_RING_IDX cons, prod, space; @@ -118,13 +129,13 @@ static int ring_free_bytes(struct XenConsole *con) =20 static int xencons_can_receive(void *opaque) { - struct XenConsole *con =3D opaque; + XenConsole *con =3D opaque; return ring_free_bytes(con); } =20 static void xencons_receive(void *opaque, const uint8_t *buf, int len) { - struct XenConsole *con =3D opaque; + XenConsole *con =3D opaque; struct xencons_interface *intf =3D con->sring; XENCONS_RING_IDX prod; int i, max; @@ -141,10 +152,10 @@ static void xencons_receive(void *opaque, const uint8= _t *buf, int len) } xen_wmb(); intf->in_prod =3D prod; - xen_pv_send_notify(&con->xendev); + xen_device_notify_event_channel(XEN_DEVICE(con), con->event_channel, N= ULL); } =20 -static void xencons_send(struct XenConsole *con) +static bool xencons_send(XenConsole *con) { ssize_t len, size; =20 @@ -159,174 +170,407 @@ static void xencons_send(struct XenConsole *con) if (len < 1) { if (!con->backlog) { con->backlog =3D 1; - xen_pv_printf(&con->xendev, 1, - "backlog piling up, nobody listening?\n"); } } else { buffer_advance(&con->buffer, len); if (con->backlog && len =3D=3D size) { con->backlog =3D 0; - xen_pv_printf(&con->xendev, 1, "backlog is gone\n"); } } + return len > 0; } =20 /* -------------------------------------------------------------------- */ =20 -static int store_con_info(struct XenConsole *con) +static bool con_event(void *_xendev) { - Chardev *cs =3D qemu_chr_fe_get_driver(&con->chr); - char *pts =3D NULL; - char *dom_path; - g_autoptr(GString) path =3D NULL; + XenConsole *con =3D XEN_CONSOLE_DEVICE(_xendev); + bool done_something; =20 - /* Only continue if we're talking to a pty. */ - if (!CHARDEV_IS_PTY(cs)) { - return 0; - } - pts =3D cs->filename + 4; + done_something =3D buffer_append(con); =20 - dom_path =3D qemu_xen_xs_get_domain_path(xenstore, xen_domid); - if (!dom_path) { - return 0; + if (con->buffer.size - con->buffer.consumed) { + done_something |=3D xencons_send(con); } + return done_something; +} =20 - path =3D g_string_new(dom_path); - free(dom_path); +/* -------------------------------------------------------------------- */ =20 - if (con->xendev.dev) { - g_string_append_printf(path, "/device/console/%d", con->xendev.dev= ); - } else { - g_string_append(path, "/console"); +static void xen_console_disconnect(XenDevice *xendev, Error **errp) +{ + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + + qemu_chr_fe_set_handlers(&con->chr, NULL, NULL, NULL, NULL, + con, NULL, true); + + + trace_xen_console_disconnect(con->dev); + + if (con->event_channel) { + xen_device_unbind_event_channel(xendev, con->event_channel, + errp); } - g_string_append(path, "/tty"); =20 - if (xenstore_write_str(con->console, path->str, pts)) { - fprintf(stderr, "xenstore_write_str for '%s' fail", path->str); - return -1; + if (!con->sring) { + return; + } + + if (!con->dev) { + qemu_xen_foreignmem_unmap(con->sring, 1); + } else { + xen_device_unmap_grant_refs(xendev, con->sring, + &con->ring_ref, 1, errp); } - return 0; } =20 -static int con_init(struct XenLegacyDevice *xendev) +static void xen_console_connect(XenDevice *xendev, Error **errp) { - struct XenConsole *con =3D container_of(xendev, struct XenConsole, xen= dev); - char *type, *dom, label[32]; - int ret =3D 0; - const char *output; - - /* setup */ - dom =3D qemu_xen_xs_get_domain_path(xenstore, con->xendev.dom); - if (!xendev->dev) { - snprintf(con->console, sizeof(con->console), "%s/console", dom); - } else { - snprintf(con->console, sizeof(con->console), "%s/device/console/%d= ", dom, xendev->dev); + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + unsigned int port, limit; + + if (xen_device_frontend_scanf(xendev, "ring-ref", "%u", + &con->ring_ref) !=3D 1) { + error_setg(errp, "failed to read ring-ref"); + return; } - free(dom); =20 - type =3D xenstore_read_str(con->console, "type"); - if (!type || strcmp(type, "ioemu") !=3D 0) { - xen_pv_printf(xendev, 1, "not for me (type=3D%s)\n", type); - ret =3D -1; - goto out; + if (xen_device_frontend_scanf(xendev, "port", "%u", &port) !=3D 1) { + error_setg(errp, "failed to read remote port"); + return; } =20 - output =3D xenstore_read_str(con->console, "output"); + if (xen_device_frontend_scanf(xendev, "limit", "%u", &limit) =3D=3D 1)= { + con->buffer.max_capacity =3D limit; + } =20 - /* no Xen override, use qemu output device */ - if (output =3D=3D NULL) { - if (con->xendev.dev) { - qemu_chr_fe_init(&con->chr, serial_hd(con->xendev.dev), - &error_abort); + if (!con->dev) { + xen_pfn_t mfn =3D (xen_pfn_t)con->ring_ref; + con->sring =3D qemu_xen_foreignmem_map(xendev->frontend_id, NULL, + PROT_READ | PROT_WRITE, + 1, &mfn, NULL); + if (!con->sring) { + error_setg(errp, "failed to map console page"); + return; } } else { - snprintf(label, sizeof(label), "xencons%d", con->xendev.dev); - qemu_chr_fe_init(&con->chr, - /* - * FIXME: sure we want to support implicit - * muxed monitors here? - */ - qemu_chr_new_mux_mon(label, output, NULL), - &error_abort); + con->sring =3D xen_device_map_grant_refs(xendev, + &con->ring_ref, 1, + PROT_READ | PROT_WRITE, + errp); + if (!con->sring) { + error_prepend(errp, "failed to map grant ref: "); + return; + } } =20 - store_con_info(con); + con->event_channel =3D xen_device_bind_event_channel(xendev, port, + con_event, + con, + errp); + if (!con->event_channel) { + xen_console_disconnect(xendev, NULL); + return; + } =20 -out: - g_free(type); - return ret; + trace_xen_console_connect(con->dev, con->ring_ref, port, + con->buffer.max_capacity); + + qemu_chr_fe_set_handlers(&con->chr, xencons_can_receive, + xencons_receive, NULL, NULL, con, NULL, + true); } =20 -static int con_initialise(struct XenLegacyDevice *xendev) + +static void xen_console_frontend_changed(XenDevice *xendev, + enum xenbus_state frontend_state, + Error **errp) { - struct XenConsole *con =3D container_of(xendev, struct XenConsole, xen= dev); - int limit; - - if (xenstore_read_int(con->console, "ring-ref", &con->ring_ref) =3D=3D= -1) - return -1; - if (xenstore_read_int(con->console, "port", &con->xendev.remote_port) = =3D=3D -1) - return -1; - if (xenstore_read_int(con->console, "limit", &limit) =3D=3D 0) - con->buffer.max_capacity =3D limit; + ERRP_GUARD(); + enum xenbus_state backend_state =3D xen_device_backend_get_state(xende= v); + + switch (frontend_state) { + case XenbusStateInitialised: + case XenbusStateConnected: + if (backend_state =3D=3D XenbusStateConnected) { + break; + } =20 - if (!xendev->dev) { - xen_pfn_t mfn =3D con->ring_ref; - con->sring =3D qemu_xen_foreignmem_map(con->xendev.dom, NULL, - PROT_READ | PROT_WRITE, - 1, &mfn, NULL); - } else { - con->sring =3D xen_be_map_grant_ref(xendev, con->ring_ref, - PROT_READ | PROT_WRITE); + xen_console_disconnect(xendev, errp); + if (*errp) { + break; + } + + xen_console_connect(xendev, errp); + if (*errp) { + break; + } + + xen_device_backend_set_state(xendev, XenbusStateConnected); + break; + + case XenbusStateClosing: + xen_device_backend_set_state(xendev, XenbusStateClosing); + break; + + case XenbusStateClosed: + case XenbusStateUnknown: + xen_console_disconnect(xendev, errp); + if (*errp) { + break; + } + + xen_device_backend_set_state(xendev, XenbusStateClosed); + break; + + default: + break; } - if (!con->sring) - return -1; +} =20 - xen_be_bind_evtchn(&con->xendev); - qemu_chr_fe_set_handlers(&con->chr, xencons_can_receive, - xencons_receive, NULL, NULL, con, NULL, true); - - xen_pv_printf(xendev, 1, - "ring mfn %d, remote port %d, local port %d, limit %zd\n= ", - con->ring_ref, - con->xendev.remote_port, - con->xendev.local_port, - con->buffer.max_capacity); - return 0; + +static char *xen_console_get_name(XenDevice *xendev, Error **errp) +{ + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + + return g_strdup_printf("%u", con->dev); } =20 -static void con_disconnect(struct XenLegacyDevice *xendev) +static void xen_console_unrealize(XenDevice *xendev) { - struct XenConsole *con =3D container_of(xendev, struct XenConsole, xen= dev); + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + + trace_xen_console_unrealize(con->dev); + + /* Disconnect from the frontend in case this has not already happened = */ + xen_console_disconnect(xendev, NULL); =20 qemu_chr_fe_deinit(&con->chr, false); - xen_pv_unbind_evtchn(&con->xendev); +} + +static void xen_console_realize(XenDevice *xendev, Error **errp) +{ + ERRP_GUARD(); + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + Chardev *cs =3D qemu_chr_fe_get_driver(&con->chr); + unsigned int u; + + if (!cs) { + error_setg(errp, "no backing character device"); + return; + } + + if (con->dev =3D=3D -1) { + error_setg(errp, "no device index provided"); + return; + } =20 - if (con->sring) { - if (!xendev->dev) { - qemu_xen_foreignmem_unmap(con->sring, 1); - } else { - xen_be_unmap_grant_ref(xendev, con->sring, con->ring_ref); + /* + * The Xen primary console is special. The ring-ref is actually a GFN = to + * be mapped directly as foreignmem (not a grant ref), and the guest p= ort + * was allocated *for* the guest by the toolstack. The guest gets these + * through HVMOP_get_param and can use the console long before it's got + * XenStore up and running. We cannot create those for a Xen guest. + */ + if (!con->dev) { + if (xen_device_frontend_scanf(xendev, "ring-ref", "%u", &u) !=3D 1= || + xen_device_frontend_scanf(xendev, "port", "%u", &u) !=3D 1) { + error_setg(errp, "cannot create primary Xen console"); + return; } - con->sring =3D NULL; + } + + trace_xen_console_realize(con->dev, object_get_typename(OBJECT(cs))); + + if (CHARDEV_IS_PTY(cs)) { + /* Strip the leading 'pty:' */ + xen_device_frontend_printf(xendev, "tty", "%s", cs->filename + 4); + } + + /* No normal PV driver initialization for the primary console */ + if (!con->dev) { + xen_console_connect(xendev, errp); + } +} + +static char *console_frontend_path(struct qemu_xs_handle *xenstore, + unsigned int dom_id, unsigned int dev) +{ + if (!dev) { + return g_strdup_printf("/local/domain/%u/console", dom_id); + } else { + return g_strdup_printf("/local/domain/%u/device/console/%u", dom_i= d, dev); } } =20 -static void con_event(struct XenLegacyDevice *xendev) +static char *xen_console_get_frontend_path(XenDevice *xendev, Error **errp) { - struct XenConsole *con =3D container_of(xendev, struct XenConsole, xen= dev); + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); + char *ret =3D console_frontend_path(xenbus->xsh, xendev->frontend_id, + con->dev); =20 - buffer_append(con); - if (con->buffer.size - con->buffer.consumed) - xencons_send(con); + if (!ret) { + error_setg(errp, "failed to create frontend path"); + } + return ret; } =20 -/* -------------------------------------------------------------------- */ =20 -struct XenDevOps xen_console_ops =3D { - .size =3D sizeof(struct XenConsole), - .flags =3D DEVOPS_FLAG_IGNORE_STATE|DEVOPS_FLAG_NEED_GNTDEV, - .init =3D con_init, - .initialise =3D con_initialise, - .event =3D con_event, - .disconnect =3D con_disconnect, +static Property xen_console_properties[] =3D { + DEFINE_PROP_CHR("chardev", XenConsole, chr), + DEFINE_PROP_INT32("idx", XenConsole, dev, -1), + DEFINE_PROP_END_OF_LIST(), +}; + +static void xen_console_class_init(ObjectClass *class, void *data) +{ + DeviceClass *dev_class =3D DEVICE_CLASS(class); + XenDeviceClass *xendev_class =3D XEN_DEVICE_CLASS(class); + + xendev_class->backend =3D "console"; + xendev_class->device =3D "console"; + xendev_class->get_name =3D xen_console_get_name; + xendev_class->realize =3D xen_console_realize; + xendev_class->frontend_changed =3D xen_console_frontend_changed; + xendev_class->unrealize =3D xen_console_unrealize; + xendev_class->get_frontend_path =3D xen_console_get_frontend_path; + + device_class_set_props(dev_class, xen_console_properties); +} + +static const TypeInfo xen_console_type_info =3D { + .name =3D TYPE_XEN_CONSOLE_DEVICE, + .parent =3D TYPE_XEN_DEVICE, + .instance_size =3D sizeof(XenConsole), + .class_init =3D xen_console_class_init, +}; + +static void xen_console_register_types(void) +{ + type_register_static(&xen_console_type_info); +} + +type_init(xen_console_register_types) + +/* Called to instantiate a XenConsole when the backend is detected. */ +static void xen_console_device_create(XenBackendInstance *backend, + QDict *opts, Error **errp) +{ + ERRP_GUARD(); + XenBus *xenbus =3D xen_backend_get_bus(backend); + const char *name =3D xen_backend_get_name(backend); + unsigned long number; + char *fe_path =3D NULL, *type =3D NULL, *output =3D NULL; + char label[32]; + XenDevice *xendev =3D NULL; + XenConsole *con; + Chardev *cd =3D NULL; + struct qemu_xs_handle *xsh =3D xenbus->xsh; + + if (qemu_strtoul(name, NULL, 10, &number)) { + error_setg(errp, "failed to parse name '%s'", name); + goto fail; + } + + trace_xen_console_device_create(number); + + fe_path =3D console_frontend_path(xsh, xen_domid, number); + if (fe_path =3D=3D NULL) { + error_setg(errp, "failed to generate frontend path"); + goto fail; + } + + if (xs_node_scanf(xsh, XBT_NULL, fe_path, "type", errp, "%ms", &type) = !=3D 1) { + error_prepend(errp, "failed to read console device type: "); + goto fail; + } + + if (strcmp(type, "ioemu")) { + error_setg(errp, "declining to handle console type '%s'", + type); + goto fail; + } + + xendev =3D XEN_DEVICE(qdev_new(TYPE_XEN_CONSOLE_DEVICE)); + con =3D XEN_CONSOLE_DEVICE(xendev); + + con->dev =3D number; + + snprintf(label, sizeof(label), "xencons%ld", number); + + if (xs_node_scanf(xsh, XBT_NULL, fe_path, "output", NULL, "%ms", + &output) =3D=3D 1) { + /* + * FIXME: sure we want to support implicit + * muxed monitors here? + */ + cd =3D qemu_chr_new_mux_mon(label, output, NULL); + if (!cd) { + error_setg(errp, "console: No valid chardev found at '%s': ", + output); + goto fail; + } + } else if (number) { + cd =3D serial_hd(number); + if (!cd) { + error_prepend(errp, "console: No serial device #%ld found: ", + number); + goto fail; + } + } else { + /* No 'output' node on primary console: use null. */ + cd =3D qemu_chr_new(label, "null", NULL); + if (!cd) { + error_setg(errp, "console: failed to create null device"); + goto fail; + } + } + + if (!qemu_chr_fe_init(&con->chr, cd, errp)) { + error_prepend(errp, "console: failed to initialize backing chardev= : "); + goto fail; + } + + if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) { + xendev =3D NULL; + } else { + error_prepend(errp, "realization of console device %lu failed: ", + number); + goto fail; + } + + fail: + if (xendev) { + object_unparent(OBJECT(xendev)); + } + + g_free(fe_path); + free(type); + free(output); +} + +static void xen_console_device_destroy(XenBackendInstance *backend, + Error **errp) +{ + ERRP_GUARD(); + XenDevice *xendev =3D xen_backend_get_device(backend); + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + + trace_xen_console_device_destroy(con->dev); + + object_unparent(OBJECT(xendev)); +} + +static const XenBackendInfo xen_console_backend_info =3D { + .type =3D "console", + .create =3D xen_console_device_create, + .destroy =3D xen_console_device_destroy, }; + +static void xen_console_register_backend(void) +{ + xen_backend_register(&xen_console_backend_info); +} + +xen_backend_init(xen_console_register_backend); diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c index 4ded3cec23..124dd5f3d6 100644 --- a/hw/xen/xen-legacy-backend.c +++ b/hw/xen/xen-legacy-backend.c @@ -623,7 +623,6 @@ void xen_be_init(void) =20 xen_set_dynamic_sysbus(); =20 - xen_be_register("console", &xen_console_ops); xen_be_register("vkbd", &xen_kbdmouse_ops); #ifdef CONFIG_VIRTFS xen_be_register("9pfs", &xen_9pfs_ops); --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469625; cv=none; d=zohomail.com; s=zohoarc; b=fxOFEG5Xcz5PiRWx1ghypFM1yJMyMKOm1dTtGvgWmqiXKUIFoqxuuZ+LK0frIy/P5yYGrPl5lSw5y97uRRRdyk+hlOWRQ0fHHOBqJUl3UK89F9BwNyJzAr0+7+1NuEp1gFraV6kXoaF1L4XyYrYJGmtCAVWZTw/yXNjr9huLdWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469625; 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=MzyeUS8+Q6DyGG1BYkZOM8Vo8wKa2UEntgjHbKC7sqQ=; b=hvS1dNnKnRjNfNuuNXCdIGfbSl/B8pHHM2Pw6ffXYYsS8GnhWkBjbU4qDEmdI3SLAbFKDl21P/Bxovop0/KcDmtilYeZv7qgD1+87L8FfDSjQn30BxZ3tBcX4lj5q+dLMkYVNprDF6q/YcQ8x5CF7K8jWBisSXEfKcKdirYdzkc= 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 1697469625314944.5760132478113; Mon, 16 Oct 2023 08:20:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617756.960758 (Exim 4.92) (envelope-from ) id 1qsPNe-0003eq-Jk; Mon, 16 Oct 2023 15:19:42 +0000 Received: by outflank-mailman (output) from mailman id 617756.960758; Mon, 16 Oct 2023 15:19:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNe-0003bu-5k; Mon, 16 Oct 2023 15:19:42 +0000 Received: by outflank-mailman (input) for mailman id 617756; Mon, 16 Oct 2023 15:19:39 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNb-0001wj-GF for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:39 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6a8034e5-6c37-11ee-9b0e-b553b5be7939; Mon, 16 Oct 2023 17:19:36 +0200 (CEST) Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0067AI-2H; Mon, 16 Oct 2023 15:19:15 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNC-0005na-07; Mon, 16 Oct 2023 16:19:14 +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: 6a8034e5-6c37-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=MzyeUS8+Q6DyGG1BYkZOM8Vo8wKa2UEntgjHbKC7sqQ=; b=GJb2yG67l2i9wJHfLSPli4NmiV +WTJ+STZ9PvEtXrFika2dLjRUrokj2hMR900jok8EpQMettPN7gS3FHyPQKoznf647TUOpQSYHY87 7NhsXIonFGtW9kxXtw/WrFVNq3USbXjMFevv9C8aamNvWluW8r5OoAlCDIqIh2MY7r95iGlt3LwPy 5WsUY2qda44FfRXdd6nB2ta+X7WWj3YG/9DdMeQ3M++iT+3xJ8ubaNHJ4hpP0CAXaBOr6HpHe17qm Dw1r3eL81en6tel9bQMu5Y3fvInjNbKvWsdnZNPfP0uvJdUrEuS9xLq5kA/UMXrbV4xTXsKUFPxUa fbe12+bQ==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 08/12] hw/xen: do not repeatedly try to create a failing backend device Date: Mon, 16 Oct 2023 16:19:05 +0100 Message-Id: <20231016151909.22133-9-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-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 desiato.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1697469627321100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse If xen_backend_device_create() fails to instantiate a device, the XenBus code will just keep trying over and over again each time the bus is re-enumerated, as long as the backend appears online and in XenbusStateInitialising. The only thing which prevents the XenBus code from recreating duplicates of devices which already exist, is the fact that xen_device_realize() sets the backend state to XenbusStateInitWait. If the attempt to create the device doesn't get *that* far, that's when it will keep getting retried. My first thought was to handle errors by setting the backend state to XenbusStateClosed, but that doesn't work for XenConsole which wants to *ignore* any device of type !=3D "ioemu" completely. So, make xen_backend_device_create() *keep* the XenBackendInstance for a failed device, and provide a new xen_backend_exists() function to allow xen_bus_type_enumerate() to check whether one already exists before creating a new one. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/xen/xen-backend.c | 27 +++++++++++++++++++++------ hw/xen/xen-bus.c | 3 ++- include/hw/xen/xen-backend.h | 1 + 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/hw/xen/xen-backend.c b/hw/xen/xen-backend.c index 5b0fb76eae..b9bf70a9f5 100644 --- a/hw/xen/xen-backend.c +++ b/hw/xen/xen-backend.c @@ -101,6 +101,24 @@ static XenBackendInstance *xen_backend_list_find(XenDe= vice *xendev) return NULL; } =20 +bool xen_backend_exists(const char *type, const char *name) +{ + const XenBackendImpl *impl =3D xen_backend_table_lookup(type); + XenBackendInstance *backend; + + if (!impl) { + return false; + } + + QLIST_FOREACH(backend, &backend_list, entry) { + if (backend->impl =3D=3D impl && !strcmp(backend->name, name)) { + return true; + } + } + + return false; +} + static void xen_backend_list_remove(XenBackendInstance *backend) { QLIST_REMOVE(backend, entry); @@ -122,11 +140,6 @@ void xen_backend_device_create(XenBus *xenbus, const c= har *type, backend->name =3D g_strdup(name); =20 impl->create(backend, opts, errp); - if (*errp) { - g_free(backend->name); - g_free(backend); - return; - } =20 backend->impl =3D impl; xen_backend_list_add(backend); @@ -165,7 +178,9 @@ bool xen_backend_try_device_destroy(XenDevice *xendev, = Error **errp) } =20 impl =3D backend->impl; - impl->destroy(backend, errp); + if (backend->xendev) { + impl->destroy(backend, errp); + } =20 xen_backend_list_remove(backend); g_free(backend->name); diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index cc524ed92c..0da2aa219a 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -209,7 +209,8 @@ static void xen_bus_type_enumerate(XenBus *xenbus, cons= t char *type) NULL, "%u", &online) !=3D 1) online =3D 0; =20 - if (online && state =3D=3D XenbusStateInitialising) { + if (online && state =3D=3D XenbusStateInitialising && + !xen_backend_exists(type, backend[i])) { Error *local_err =3D NULL; =20 xen_bus_backend_create(xenbus, type, backend[i], backend_path, diff --git a/include/hw/xen/xen-backend.h b/include/hw/xen/xen-backend.h index aac2fd454d..0f01631ae7 100644 --- a/include/hw/xen/xen-backend.h +++ b/include/hw/xen/xen-backend.h @@ -33,6 +33,7 @@ XenDevice *xen_backend_get_device(XenBackendInstance *bac= kend); void xen_backend_register(const XenBackendInfo *info); const char **xen_backend_get_types(unsigned int *nr); =20 +bool xen_backend_exists(const char *type, const char *name); void xen_backend_device_create(XenBus *xenbus, const char *type, const char *name, QDict *opts, Error **errp= ); bool xen_backend_try_device_destroy(XenDevice *xendev, Error **errp); --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469626; cv=none; d=zohomail.com; s=zohoarc; b=F6SM26DNL3l7d3MAg+AzltnPIDjJ9cvqyarfz51K+vLEQe14skSgvg/3fwHk5jcoX1rnbBh0S+FZXqFLtnhsHUh/IK4RXq7LLG6nQsYbKVgtxKTncEw/jR5WooOlY5U126JldgPcVPnyY0WvwlxWiw/FIB/BCselQxgwbFyBtWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469626; 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=TdW7pWLHlLv278eB+Yc1VQQLRAc6P36ZNDdKDPh28m0=; b=YYttbz4GsYXj1RnnSSV5D29BPW+2RKN+6bnDRBkRM7vJTB8WzUYoOuoOjEW1w5f6pSg4Jkd1zgrkdsHwvjImoqZ36zbdKVXp0oiUHW+aVLNqEnl9VhpCmQ2tCWP7JKu8LZ5ahhTPLFdWdGWAPHS5BUdU0dmUbS01HBn9JtqEnm4= 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 1697469626197526.0909941046713; Mon, 16 Oct 2023 08:20:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617757.960762 (Exim 4.92) (envelope-from ) id 1qsPNf-0003sy-6D; Mon, 16 Oct 2023 15:19:43 +0000 Received: by outflank-mailman (output) from mailman id 617757.960762; Mon, 16 Oct 2023 15:19:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNf-0003qr-0b; Mon, 16 Oct 2023 15:19:43 +0000 Received: by outflank-mailman (input) for mailman id 617757; Mon, 16 Oct 2023 15:19:40 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNc-0001wj-GK for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:40 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6b0e86a4-6c37-11ee-9b0e-b553b5be7939; Mon, 16 Oct 2023 17:19:37 +0200 (CEST) Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0067AJ-2F; Mon, 16 Oct 2023 15:19:15 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNC-0005ne-0D; Mon, 16 Oct 2023 16:19:14 +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: 6b0e86a4-6c37-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=TdW7pWLHlLv278eB+Yc1VQQLRAc6P36ZNDdKDPh28m0=; b=RGDymOaeG8K1D/v44ruA5TZh8q yIisakCcpuamBOij8UlBgpYUEpR1D1wEBLaWOSU+ss27q//FiVgfKJeg7VS8pbyC9PsQmXmwnrOmW o5iVb9ww1iBkPJhyOi7Sc43Xfr7YBbFVdfusAPOOwRATZNOM2ObJhyC7K66YjP+S5gUOdMo0pr9mK Jo+USZWvusMx/TNmvhcGTcsrSwDS5+1Z1bYJmgYpEilt7n2HkBGrvg+D7T8zHfi73sb2dEblB7LX2 iNt0YZiJQwK3W1lkbDeL4VfcIg9XkLaUoqSE48WawQUxp9Q87L69aiRbTfJZJYSkjK1T/tBHXRNPD lvQikPAQ==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 09/12] hw/xen: prevent duplicate device registrations Date: Mon, 16 Oct 2023 16:19:06 +0100 Message-Id: <20231016151909.22133-10-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-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 desiato.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1697469627322100002 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Ensure that we have a XenBackendInstance for every device regardless of whether it was "discovered" in XenStore or created directly in QEMU. This allows the backend_list to be a source of truth about whether a given backend exists, and allows us to reject duplicates. This also cleans up the fact that backend drivers were calling xen_backend_set_device() with a XenDevice immediately after calling qdev_realize_and_unref() on it, when it wasn't theirs to play with any more. Signed-off-by: David Woodhouse --- hw/block/xen-block.c | 1 - hw/char/xen_console.c | 2 +- hw/xen/xen-backend.c | 78 ++++++++++++++++++++++++++---------- hw/xen/xen-bus.c | 8 ++++ include/hw/xen/xen-backend.h | 3 ++ 5 files changed, 69 insertions(+), 23 deletions(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index a07cd7eb5d..9262338535 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -975,7 +975,6 @@ static void xen_block_device_create(XenBackendInstance = *backend, goto fail; } =20 - xen_backend_set_device(backend, xendev); return; =20 fail: diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index bd20be116c..2825b8c511 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -468,7 +468,7 @@ static void xen_console_device_create(XenBackendInstanc= e *backend, Chardev *cd =3D NULL; struct qemu_xs_handle *xsh =3D xenbus->xsh; =20 - if (qemu_strtoul(name, NULL, 10, &number)) { + if (qemu_strtoul(name, NULL, 10, &number) || number >=3D INT_MAX) { error_setg(errp, "failed to parse name '%s'", name); goto fail; } diff --git a/hw/xen/xen-backend.c b/hw/xen/xen-backend.c index b9bf70a9f5..dcb4329258 100644 --- a/hw/xen/xen-backend.c +++ b/hw/xen/xen-backend.c @@ -101,22 +101,28 @@ static XenBackendInstance *xen_backend_list_find(XenD= evice *xendev) return NULL; } =20 -bool xen_backend_exists(const char *type, const char *name) +static XenBackendInstance *xen_backend_lookup(const XenBackendImpl *impl, = const char *name) { - const XenBackendImpl *impl =3D xen_backend_table_lookup(type); XenBackendInstance *backend; =20 - if (!impl) { - return false; - } - QLIST_FOREACH(backend, &backend_list, entry) { if (backend->impl =3D=3D impl && !strcmp(backend->name, name)) { - return true; + return backend; } } =20 - return false; + return NULL; +} + +bool xen_backend_exists(const char *type, const char *name) +{ + const XenBackendImpl *impl =3D xen_backend_table_lookup(type); + + if (!impl) { + return false; + } + + return !!xen_backend_lookup(impl, name); } =20 static void xen_backend_list_remove(XenBackendInstance *backend) @@ -138,11 +144,10 @@ void xen_backend_device_create(XenBus *xenbus, const = char *type, backend =3D g_new0(XenBackendInstance, 1); backend->xenbus =3D xenbus; backend->name =3D g_strdup(name); - - impl->create(backend, opts, errp); - backend->impl =3D impl; xen_backend_list_add(backend); + + impl->create(backend, opts, errp); } =20 XenBus *xen_backend_get_bus(XenBackendInstance *backend) @@ -155,13 +160,6 @@ const char *xen_backend_get_name(XenBackendInstance *b= ackend) return backend->name; } =20 -void xen_backend_set_device(XenBackendInstance *backend, - XenDevice *xendev) -{ - g_assert(!backend->xendev); - backend->xendev =3D xendev; -} - XenDevice *xen_backend_get_device(XenBackendInstance *backend) { return backend->xendev; @@ -178,9 +176,7 @@ bool xen_backend_try_device_destroy(XenDevice *xendev, = Error **errp) } =20 impl =3D backend->impl; - if (backend->xendev) { - impl->destroy(backend, errp); - } + impl->destroy(backend, errp); =20 xen_backend_list_remove(backend); g_free(backend->name); @@ -188,3 +184,43 @@ bool xen_backend_try_device_destroy(XenDevice *xendev,= Error **errp) =20 return true; } + +bool xen_backend_device_realized(XenDevice *xendev, Error **errp) +{ + XenDeviceClass *xendev_class =3D XEN_DEVICE_GET_CLASS(xendev); + const char *type =3D xendev_class->backend ? : object_get_typename(OBJ= ECT(xendev)); + const XenBackendImpl *impl =3D xen_backend_table_lookup(type); + XenBackendInstance *backend; + + if (!impl) { + return false; + } + + backend =3D xen_backend_lookup(impl, xendev->name); + if (backend) { + if (backend->xendev && backend->xendev !=3D xendev) { + error_setg(errp, "device %s/%s already exists", type, xendev->= name); + return false; + } + backend->xendev =3D xendev; + return true; + } + + backend =3D g_new0(XenBackendInstance, 1); + backend->xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); + backend->xendev =3D xendev; + backend->name =3D g_strdup(xendev->name); + backend->impl =3D impl; + + xen_backend_list_add(backend); + return true; +} + +void xen_backend_device_unrealized(XenDevice *xendev) +{ + XenBackendInstance *backend =3D xen_backend_list_find(xendev); + + if (backend) { + backend->xendev =3D NULL; + } +} diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 0da2aa219a..0b232d1f94 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -359,6 +359,8 @@ static void xen_bus_realize(BusState *bus, Error **errp) =20 g_free(type); g_free(key); + + xen_bus_enumerate(xenbus); return; =20 fail: @@ -958,6 +960,8 @@ static void xen_device_unrealize(DeviceState *dev) =20 trace_xen_device_unrealize(type, xendev->name); =20 + xen_backend_device_unrealized(xendev); + if (xendev->exit.notify) { qemu_remove_exit_notifier(&xendev->exit); xendev->exit.notify =3D NULL; @@ -1024,6 +1028,10 @@ static void xen_device_realize(DeviceState *dev, Err= or **errp) goto unrealize; } =20 + if (!xen_backend_device_realized(xendev, errp)) { + goto unrealize; + } + trace_xen_device_realize(type, xendev->name); =20 xendev->xsh =3D qemu_xen_xs_open(); diff --git a/include/hw/xen/xen-backend.h b/include/hw/xen/xen-backend.h index 0f01631ae7..3f1e764c51 100644 --- a/include/hw/xen/xen-backend.h +++ b/include/hw/xen/xen-backend.h @@ -38,4 +38,7 @@ void xen_backend_device_create(XenBus *xenbus, const char= *type, const char *name, QDict *opts, Error **errp= ); bool xen_backend_try_device_destroy(XenDevice *xendev, Error **errp); =20 +bool xen_backend_device_realized(XenDevice *xendev, Error **errp); +void xen_backend_device_unrealized(XenDevice *xendev); + #endif /* HW_XEN_BACKEND_H */ --=20 2.40.1 From nobody Thu May 16 12:55:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169746961518160.63527641160408; Mon, 16 Oct 2023 08:20:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsPNS-0000Pv-97; Mon, 16 Oct 2023 11:19:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qsPNM-0000Nc-RO; Mon, 16 Oct 2023 11:19:24 -0400 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qsPNK-0001ao-Pv; Mon, 16 Oct 2023 11:19:24 -0400 Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0067AK-2I; Mon, 16 Oct 2023 15:19:15 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNC-0005ni-0J; Mon, 16 Oct 2023 16:19:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=8ikJQCC5TLkL7JR5JlTU3UpA6g8LaKWjgM9/evGEzFk=; b=aGOU43EkvyJiadbd3LlgugWndr 4xurUA890xm0/ENhk99UVqAb54O6T00LyeHtXfR8m3GM6lFk6OtKRHZ5HDxMqzKrpTPqvg5curQTr rIV6Rucgz20nRUsiqKnlZowMUo/NLQs17ZwN1GSv1fANshFRCM9lfJKWuQM8Ra8d0q9BT36RFta0K HgM66p0WtsRQkI9a/yI/ofe75YSiQI0/JmLUayOl4LbMquRoXLqmWyDFtxA6W3xa50XAID32EGqMX D1y4MMKSArdJ+xYoB6kSbjUQ7fDqJ6/e+9bWR4mjrbKDiSh7b0s3OvJc+W87KuuuGX5pAcILS2i5L 20Sx+dJw==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 10/12] hw/xen: automatically assign device index to console devices Date: Mon, 16 Oct 2023 16:19:07 +0100 Message-Id: <20231016151909.22133-11-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; envelope-from=BATV+1bdf71eab2d76d13073e+7358+infradead.org+dwmw2@desiato.srs.infradead.org; helo=desiato.infradead.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1697469617995100019 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Now that we can reliably tell whether a given device already exists, we can allow the user to add console devices on the command line with just '-device xen-console,chardev=3Dfoo'. Start at 1, because we can't add the *primary* console; that's special because the toolstack has to set up the guest end of that. Signed-off-by: David Woodhouse --- hw/char/xen_console.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 2825b8c511..1a0f5ed3e1 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -333,6 +333,22 @@ static char *xen_console_get_name(XenDevice *xendev, E= rror **errp) { XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); =20 + if (con->dev =3D=3D -1) { + char name[11]; + int idx =3D 1; + + /* Theoretically we could go up to INT_MAX here but that's overkil= l */ + while (idx < 100) { + snprintf(name, sizeof(name), "%u", idx); + if (!xen_backend_exists("console", name)) { + con->dev =3D idx; + return g_strdup(name); + } + idx++; + } + error_setg(errp, "cannot find device index for console device"); + return NULL; + } return g_strdup_printf("%u", con->dev); } =20 --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469607; cv=none; d=zohomail.com; s=zohoarc; b=cnvuyiRW7qo0sKC76Ffk1qYsJZGTVParob/D1pKAvQQcKHG2/Qk1fBVF9gE6EeIzVRiu2hVM3vphFG/c5Y2lwHo7hX9es+gmybyRHK386Wtm+depewkAGDauLgDtV7f676g+Rp9JGNg1zef+ibbnRVEw1hYrfpVr1BPZq8XspFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469607; 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=CKGyyzKxuGsuwvI9v9sDpTYzNulOlzm/j1apww1tl2E=; b=NutzjDm40EsXDrQwUzGS3B8Vc4MHdCYjwv328JOe0P91nBn4kh3BWkxwv1O0l8qjqAteXD5pv9a1IDG4vyF3m+RHP4GRKFVFexGWtE+AMHOGnapLfoNyvCc5LTLU4T3cNlrM353STgw1SnxPtz8WD6W0vx2wONIRzKV3X9hiHeU= 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 1697469607314947.7434601956872; Mon, 16 Oct 2023 08:20:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617750.960694 (Exim 4.92) (envelope-from ) id 1qsPNa-000239-3g; Mon, 16 Oct 2023 15:19:38 +0000 Received: by outflank-mailman (output) from mailman id 617750.960694; Mon, 16 Oct 2023 15:19:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNZ-00022P-V5; Mon, 16 Oct 2023 15:19:37 +0000 Received: by outflank-mailman (input) for mailman id 617750; Mon, 16 Oct 2023 15:19:36 +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 1qsPNY-0001wi-A7 for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:36 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6953712c-6c37-11ee-98d4-6d05b1d4d9a1; Mon, 16 Oct 2023 17:19:34 +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 1qsPNC-006lqd-K5; Mon, 16 Oct 2023 15:19:14 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNC-0005nm-0O; Mon, 16 Oct 2023 16:19:14 +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: 6953712c-6c37-11ee-98d4-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=CKGyyzKxuGsuwvI9v9sDpTYzNulOlzm/j1apww1tl2E=; b=uA3k1jxFkJRBbPY6r9+ROrl9xB Ed1eunSvi3H/KfvrxrT9lP5H2djfPrnFHcFygKZj4VcGF52CxaRrHRDnTZjj+UZ4Vmx3fme2ifd+8 jLrO4NXss7pNWzjoHdrAHJMckswmA04WATXDPBzFy1GB/kwDx0q70Asa+juNKTadNvBADrARDRpaq qED7epYAiAoHEZ4Mc691xWO7fHvrFofp1UauU0/ULASJmdaKqcMU8KUj1WRBkHIk/dO85a0houl97 suKAGPYQ0Sa9d51Ix6QAOP2so7mLXRySlKD02UAH/xsCQG0QNTs9AMYKlBF2zNqslKh21c7iwIGu8 1TscSXxA==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 11/12] hw/xen: automatically assign device index to block devices Date: Mon, 16 Oct 2023 16:19:08 +0100 Message-Id: <20231016151909.22133-12-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-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: 1697469609287100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse There's no need to force the user to assign a vdev. We can automatically assign one, starting at xvda and searching until we find the first disk name that's unused. This means we can now allow '-drive if=3Dxen,file=3Dxxx' to work without an explicit separate -driver argument, just like if=3Dvirtio. Signed-off-by: David Woodhouse Acked-by: Kevin Wolf --- blockdev.c | 15 ++++++++++++--- hw/block/xen-block.c | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 325b7a3bef..9dec4c9c74 100644 --- a/blockdev.c +++ b/blockdev.c @@ -255,13 +255,13 @@ void drive_check_orphaned(void) * Ignore default drives, because we create certain default * drives unconditionally, then leave them unclaimed. Not the * users fault. - * Ignore IF_VIRTIO, because it gets desugared into -device, - * so we can leave failing to -device. + * Ignore IF_VIRTIO or IF_XEN, because it gets desugared into + * -device, so we can leave failing to -device. * Ignore IF_NONE, because leaving unclaimed IF_NONE remains * available for device_add is a feature. */ if (dinfo->is_default || dinfo->type =3D=3D IF_VIRTIO - || dinfo->type =3D=3D IF_NONE) { + || dinfo->type =3D=3D IF_XEN || dinfo->type =3D=3D IF_NONE) { continue; } if (!blk_get_attached_dev(blk)) { @@ -977,6 +977,15 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfac= eType block_default_type, qemu_opt_set(devopts, "driver", "virtio-blk", &error_abort); qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id"), &error_abort); + } else if (type =3D=3D IF_XEN) { + QemuOpts *devopts; + devopts =3D qemu_opts_create(qemu_find_opts("device"), NULL, 0, + &error_abort); + qemu_opt_set(devopts, "driver", + (media =3D=3D MEDIA_CDROM) ? "xen-cdrom" : "xen-disk", + &error_abort); + qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id"), + &error_abort); } =20 filename =3D qemu_opt_get(legacy_opts, "file"); diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 9262338535..20fa783cbe 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -34,6 +34,31 @@ static char *xen_block_get_name(XenDevice *xendev, Error= **errp) XenBlockDevice *blockdev =3D XEN_BLOCK_DEVICE(xendev); XenBlockVdev *vdev =3D &blockdev->props.vdev; =20 + if (blockdev->props.vdev.type =3D=3D XEN_BLOCK_VDEV_TYPE_INVALID) { + char name[11]; + int disk =3D 0; + unsigned long idx; + + /* Find an unoccupied device name */ + while (disk < (1 << 20)) { + if (disk < (1 << 4)) { + idx =3D (202 << 8) | (disk << 4); + } else { + idx =3D (1 << 28) | (disk << 8); + } + snprintf(name, sizeof(name), "%lu", idx); + if (!xen_backend_exists("qdisk", name)) { + vdev->type =3D XEN_BLOCK_VDEV_TYPE_XVD; + vdev->partition =3D 0; + vdev->disk =3D disk; + vdev->number =3D idx; + return g_strdup(name); + } + disk++; + } + error_setg(errp, "cannot find device vdev for block device"); + return NULL; + } return g_strdup_printf("%lu", vdev->number); } =20 --=20 2.40.1 From nobody Thu May 16 12:55:27 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=1697469642; cv=none; d=zohomail.com; s=zohoarc; b=eTse13yTEM81QmueyzVpllwU0Pza+DstA0YpfyTOuGaRRW27x+w1Wbsw/v74Z70i8vPuFVkSqiG+J6YtX8ALJErn2Qhe0AqyNDbx/z66BtgU4PQdGXPRh6R765SCYk08VdHz83kIBWO64ob9bM2nS/wwM/24jimrBH1h4kHGEP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697469642; h=Content-Type: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=jwGGWJD+aiNhUio6yXXYsQeQjFRX090/8s/pV5DcAPo=; b=kGyRWkot4+HUGZhrjNlPcgndaHsSIQ1Pv6K9RAlDwhJnLWxNJGYW0JmBfCNJDIX9b4L+R7i+kEuLU9V0GQzf8+vz5PuB4/TC9u0c+oB9B9dmGD43i2VaA0D2VvD7eJqZImgMr3+juCoBbpN5DmaWCITFX+gx1tav9mZl8T/dQ/M= 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 1697469642857677.1243421583944; Mon, 16 Oct 2023 08:20:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617759.960781 (Exim 4.92) (envelope-from ) id 1qsPNh-0004Jh-21; Mon, 16 Oct 2023 15:19:45 +0000 Received: by outflank-mailman (output) from mailman id 617759.960781; Mon, 16 Oct 2023 15:19:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNg-0004G2-KR; Mon, 16 Oct 2023 15:19:44 +0000 Received: by outflank-mailman (input) for mailman id 617759; Mon, 16 Oct 2023 15:19:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsPNe-0001wj-6E for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 15:19:42 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6c36a377-6c37-11ee-9b0e-b553b5be7939; Mon, 16 Oct 2023 17:19:39 +0200 (CEST) Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNB-0067AL-2I; Mon, 16 Oct 2023 15:19:15 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qsPNC-0005nr-0V; Mon, 16 Oct 2023 16:19:14 +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: 6c36a377-6c37-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description; bh=jwGGWJD+aiNhUio6yXXYsQeQjFRX090/8s/pV5DcAPo=; b=nTtN6JRD/EBeLKEvbsufzqlbru I5Y17CMSysfhnozFHuM9sbPyu6B7o38BvbjJP7YM/huwOwOmM7M69ztifXBKwRAx+0BFBQu/nSafh 6D5Hv2f20ZHCxPY1qUHqQNx+EwO6SpBTNfmcTAyTvyd32h7REGSMT09J1UCxPWmSpYcunHlREOgEd mD1QhZbOwWNsw7Vpi9yQCxYy7YACIbopBij9Slp+QO4r7TG6Lj3YYB2qbVh0D0Bvjuwr2tU41hUkj RLpPFgm1NjcggUm8/3qf7afu4o64ishMZRotMptZIwIKC3APG/f9sfEVPIPSyV+gM5OK+VgVgnszX cORGT8mw==; 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 , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost , David Woodhouse , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org Subject: [PATCH 12/12] hw/xen: add support for Xen primary console in emulated mode Date: Mon, 16 Oct 2023 16:19:09 +0100 Message-Id: <20231016151909.22133-13-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016151909.22133-1-dwmw2@infradead.org> References: <20231016151909.22133-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1697469643444100001 From: David Woodhouse The primary console is special because the toolstack maps a page at a fixed GFN and also allocates the guest-side event channel. Add support for that in emulated mode, so that we can have a primary console. Add a *very* rudimentary stub of foriegnmem ops for emulated mode, which supports literally nothing except a single-page mapping of the console page. This might as well have been a hack in the xen_console driver, but this way at least the special-casing is kept within the Xen emulation code, and it gives us a hook for a more complete implementation if/when we ever do need one. Now at last we can boot the Xen PV shim and run PV kernels in QEMU. Signed-off-by: David Woodhouse --- hw/char/xen_console.c | 12 ++- hw/i386/kvm/meson.build | 1 + hw/i386/kvm/trace-events | 2 + hw/i386/kvm/xen-stubs.c | 5 + hw/i386/kvm/xen_gnttab.c | 32 +++++- hw/i386/kvm/xen_primary_console.c | 167 ++++++++++++++++++++++++++++++ hw/i386/kvm/xen_primary_console.h | 22 ++++ hw/i386/kvm/xen_xenstore.c | 9 ++ target/i386/kvm/xen-emu.c | 23 +++- 9 files changed, 266 insertions(+), 7 deletions(-) create mode 100644 hw/i386/kvm/xen_primary_console.c create mode 100644 hw/i386/kvm/xen_primary_console.h diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 1a0f5ed3e1..dfc4be0aa1 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -32,6 +32,7 @@ #include "hw/qdev-properties.h" #include "hw/qdev-properties-system.h" #include "hw/xen/interface/io/console.h" +#include "hw/i386/kvm/xen_primary_console.h" #include "trace.h" =20 struct buffer { @@ -334,8 +335,8 @@ static char *xen_console_get_name(XenDevice *xendev, Er= ror **errp) XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); =20 if (con->dev =3D=3D -1) { + int idx =3D (xen_mode =3D=3D XEN_EMULATE) ? 0 : 1; char name[11]; - int idx =3D 1; =20 /* Theoretically we could go up to INT_MAX here but that's overkil= l */ while (idx < 100) { @@ -386,10 +387,13 @@ static void xen_console_realize(XenDevice *xendev, Er= ror **errp) * be mapped directly as foreignmem (not a grant ref), and the guest p= ort * was allocated *for* the guest by the toolstack. The guest gets these * through HVMOP_get_param and can use the console long before it's got - * XenStore up and running. We cannot create those for a Xen guest. + * XenStore up and running. We cannot create those for a true Xen gues= t, + * but we can for Xen emulation. */ if (!con->dev) { - if (xen_device_frontend_scanf(xendev, "ring-ref", "%u", &u) !=3D 1= || + if (xen_mode =3D=3D XEN_EMULATE) { + xen_primary_console_create(); + } else if (xen_device_frontend_scanf(xendev, "ring-ref", "%u", &u)= !=3D 1 || xen_device_frontend_scanf(xendev, "port", "%u", &u) !=3D 1) { error_setg(errp, "cannot create primary Xen console"); return; @@ -404,7 +408,7 @@ static void xen_console_realize(XenDevice *xendev, Erro= r **errp) } =20 /* No normal PV driver initialization for the primary console */ - if (!con->dev) { + if (!con->dev && xen_mode !=3D XEN_EMULATE) { xen_console_connect(xendev, errp); } } diff --git a/hw/i386/kvm/meson.build b/hw/i386/kvm/meson.build index ab143d6474..a4a2e23c06 100644 --- a/hw/i386/kvm/meson.build +++ b/hw/i386/kvm/meson.build @@ -9,6 +9,7 @@ i386_kvm_ss.add(when: 'CONFIG_XEN_EMU', if_true: files( 'xen_evtchn.c', 'xen_gnttab.c', 'xen_xenstore.c', + 'xen_primary_console.c', 'xenstore_impl.c', )) =20 diff --git a/hw/i386/kvm/trace-events b/hw/i386/kvm/trace-events index e4c82de6f3..67bf7f174e 100644 --- a/hw/i386/kvm/trace-events +++ b/hw/i386/kvm/trace-events @@ -18,3 +18,5 @@ xenstore_watch(const char *path, const char *token) "path= %s token %s" xenstore_unwatch(const char *path, const char *token) "path %s token %s" xenstore_reset_watches(void) "" xenstore_watch_event(const char *path, const char *token) "path %s token %= s" +xen_primary_console_create(void) "" +xen_primary_console_reset(int port) "port %u" diff --git a/hw/i386/kvm/xen-stubs.c b/hw/i386/kvm/xen-stubs.c index ae406e0b02..10068970fe 100644 --- a/hw/i386/kvm/xen-stubs.c +++ b/hw/i386/kvm/xen-stubs.c @@ -15,6 +15,7 @@ #include "qapi/qapi-commands-misc-target.h" =20 #include "xen_evtchn.h" +#include "xen_primary_console.h" =20 void xen_evtchn_snoop_msi(PCIDevice *dev, bool is_msix, unsigned int vecto= r, uint64_t addr, uint32_t data, bool is_masked) @@ -30,6 +31,10 @@ bool xen_evtchn_deliver_pirq_msi(uint64_t address, uint3= 2_t data) return false; } =20 +void xen_primary_console_create(void) +{ +} + #ifdef TARGET_I386 EvtchnInfoList *qmp_xen_event_list(Error **errp) { diff --git a/hw/i386/kvm/xen_gnttab.c b/hw/i386/kvm/xen_gnttab.c index 21c30e3659..ea201cd582 100644 --- a/hw/i386/kvm/xen_gnttab.c +++ b/hw/i386/kvm/xen_gnttab.c @@ -25,6 +25,7 @@ #include "hw/xen/xen_backend_ops.h" #include "xen_overlay.h" #include "xen_gnttab.h" +#include "xen_primary_console.h" =20 #include "sysemu/kvm.h" #include "sysemu/kvm_xen.h" @@ -38,6 +39,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(XenGnttabState, XEN_GNTTAB) #define ENTRIES_PER_FRAME_V1 (XEN_PAGE_SIZE / sizeof(grant_entry_v1_t)) =20 static struct gnttab_backend_ops emu_gnttab_backend_ops; +static struct foreignmem_backend_ops emu_foreignmem_backend_ops; =20 struct XenGnttabState { /*< private >*/ @@ -100,6 +102,7 @@ static void xen_gnttab_realize(DeviceState *dev, Error = **errp) s->map_track =3D g_new0(uint8_t, s->max_frames * ENTRIES_PER_FRAME_V1); =20 xen_gnttab_ops =3D &emu_gnttab_backend_ops; + xen_foreignmem_ops =3D &emu_foreignmem_backend_ops; } =20 static int xen_gnttab_post_load(void *opaque, int version_id) @@ -524,6 +527,29 @@ static struct gnttab_backend_ops emu_gnttab_backend_op= s =3D { .unmap =3D xen_be_gnttab_unmap, }; =20 +/* Dummy implementation of foriegnmem; just enough for console */ +static void *xen_be_foreignmem_map(uint32_t dom, void *addr, int prot, + size_t pages, xen_pfn_t *pfns, + int *errs) +{ + if (dom =3D=3D xen_domid && !addr && pages =3D=3D 1 && + pfns[0] =3D=3D xen_primary_console_get_pfn()) { + return xen_primary_console_get_map(); + } + + return NULL; +} + +static int xen_be_foreignmem_unmap(void *addr, size_t pages) +{ + return 0; +} + +static struct foreignmem_backend_ops emu_foreignmem_backend_ops =3D { + .map =3D xen_be_foreignmem_map, + .unmap =3D xen_be_foreignmem_unmap, +}; + int xen_gnttab_reset(void) { XenGnttabState *s =3D xen_gnttab_singleton; @@ -537,10 +563,14 @@ int xen_gnttab_reset(void) s->nr_frames =3D 0; =20 memset(s->entries.v1, 0, XEN_PAGE_SIZE * s->max_frames); - s->entries.v1[GNTTAB_RESERVED_XENSTORE].flags =3D GTF_permit_access; s->entries.v1[GNTTAB_RESERVED_XENSTORE].frame =3D XEN_SPECIAL_PFN(XENS= TORE); =20 + if (xen_primary_console_get_pfn()) { + s->entries.v1[GNTTAB_RESERVED_CONSOLE].flags =3D GTF_permit_access; + s->entries.v1[GNTTAB_RESERVED_CONSOLE].frame =3D XEN_SPECIAL_PFN(C= ONSOLE); + } + memset(s->map_track, 0, s->max_frames * ENTRIES_PER_FRAME_V1); =20 return 0; diff --git a/hw/i386/kvm/xen_primary_console.c b/hw/i386/kvm/xen_primary_co= nsole.c new file mode 100644 index 0000000000..0aa1c16ad6 --- /dev/null +++ b/hw/i386/kvm/xen_primary_console.c @@ -0,0 +1,167 @@ +/* + * QEMU Xen emulation: Primary console support + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * Authors: David Woodhouse + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "qapi/error.h" + +#include "hw/sysbus.h" +#include "hw/xen/xen.h" +#include "hw/xen/xen_backend_ops.h" +#include "xen_evtchn.h" +#include "xen_overlay.h" +#include "xen_primary_console.h" + +#include "sysemu/kvm.h" +#include "sysemu/kvm_xen.h" + +#include "trace.h" + +#include "hw/xen/interface/event_channel.h" +#include "hw/xen/interface/grant_table.h" + +#define TYPE_XEN_PRIMARY_CONSOLE "xen-primary-console" +OBJECT_DECLARE_SIMPLE_TYPE(XenPrimaryConsoleState, XEN_PRIMARY_CONSOLE) + +struct XenPrimaryConsoleState { + /*< private >*/ + SysBusDevice busdev; + /*< public >*/ + + MemoryRegion console_page; + void *cp; + + evtchn_port_t guest_port; + evtchn_port_t be_port; + + struct xengntdev_handle *gt; + void *granted_xs; +}; + +struct XenPrimaryConsoleState *xen_primary_console_singleton; + +static void xen_primary_console_realize(DeviceState *dev, Error **errp) +{ + XenPrimaryConsoleState *s =3D XEN_PRIMARY_CONSOLE(dev); + + if (xen_mode !=3D XEN_EMULATE) { + error_setg(errp, "Xen primary console support is for Xen emulation= "); + return; + } + + memory_region_init_ram(&s->console_page, OBJECT(dev), "xen:console_pag= e", + XEN_PAGE_SIZE, &error_abort); + memory_region_set_enabled(&s->console_page, true); + s->cp =3D memory_region_get_ram_ptr(&s->console_page); + memset(s->cp, 0, XEN_PAGE_SIZE); + + /* We can't map it this early as KVM isn't ready */ + xen_primary_console_singleton =3D s; +} + +static void xen_primary_console_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D xen_primary_console_realize; +} + +static const TypeInfo xen_primary_console_info =3D { + .name =3D TYPE_XEN_PRIMARY_CONSOLE, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(XenPrimaryConsoleState), + .class_init =3D xen_primary_console_class_init, +}; + + +void xen_primary_console_create(void) +{ + DeviceState *dev =3D sysbus_create_simple(TYPE_XEN_PRIMARY_CONSOLE, -1= , NULL); + + trace_xen_primary_console_create(); + + xen_primary_console_singleton =3D XEN_PRIMARY_CONSOLE(dev); + + /* + * Defer the init (xen_primary_console_reset()) until KVM is set up an= d the + * overlay page can be mapped. + */ +} + +static void xen_primary_console_register_types(void) +{ + type_register_static(&xen_primary_console_info); +} + +type_init(xen_primary_console_register_types) + +uint16_t xen_primary_console_get_port(void) +{ + XenPrimaryConsoleState *s =3D xen_primary_console_singleton; + if (!s) { + return 0; + } + return s->guest_port; +} + +uint64_t xen_primary_console_get_pfn(void) +{ + XenPrimaryConsoleState *s =3D xen_primary_console_singleton; + if (!s) { + return 0; + } + return XEN_SPECIAL_PFN(CONSOLE); +} + +void *xen_primary_console_get_map(void) +{ + XenPrimaryConsoleState *s =3D xen_primary_console_singleton; + if (!s) { + return 0; + } + return s->cp; +} + +static void alloc_guest_port(XenPrimaryConsoleState *s) +{ + struct evtchn_alloc_unbound alloc =3D { + .dom =3D DOMID_SELF, + .remote_dom =3D DOMID_QEMU, + }; + + if (!xen_evtchn_alloc_unbound_op(&alloc)) { + s->guest_port =3D alloc.port; + } +} + +int xen_primary_console_reset(void) +{ + XenPrimaryConsoleState *s =3D xen_primary_console_singleton; + if (!s) { + return 0; + } + + if (!memory_region_is_mapped(&s->console_page)) { + uint64_t gpa =3D XEN_SPECIAL_PFN(CONSOLE) << TARGET_PAGE_BITS; + xen_overlay_do_map_page(&s->console_page, gpa); + } + + alloc_guest_port(s); + + trace_xen_primary_console_reset(s->guest_port); + + s->gt =3D qemu_xen_gnttab_open(); + uint32_t xs_gntref =3D GNTTAB_RESERVED_CONSOLE; + s->granted_xs =3D qemu_xen_gnttab_map_refs(s->gt, 1, xen_domid, &xs_gn= tref, + PROT_READ | PROT_WRITE); + + return 0; +} diff --git a/hw/i386/kvm/xen_primary_console.h b/hw/i386/kvm/xen_primary_co= nsole.h new file mode 100644 index 0000000000..dd4922f3f4 --- /dev/null +++ b/hw/i386/kvm/xen_primary_console.h @@ -0,0 +1,22 @@ +/* + * QEMU Xen emulation: Primary console support + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * Authors: David Woodhouse + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_XEN_PRIMARY_CONSOLE_H +#define QEMU_XEN_PRIMARY_CONSOLE_H + +void xen_primary_console_create(void); +int xen_primary_console_reset(void); + +uint16_t xen_primary_console_get_port(void); +uint64_t xen_primary_console_get_pfn(void); +void *xen_primary_console_get_map(void); + +#endif /* QEMU_XEN_PRIMARY_CONSOLE_H */ diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index 3300e0614a..9f8946e0ce 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -25,6 +25,7 @@ #include "hw/xen/xen_backend_ops.h" #include "xen_overlay.h" #include "xen_evtchn.h" +#include "xen_primary_console.h" #include "xen_xenstore.h" =20 #include "sysemu/kvm.h" @@ -1432,6 +1433,7 @@ static void alloc_guest_port(XenXenstoreState *s) int xen_xenstore_reset(void) { XenXenstoreState *s =3D xen_xenstore_singleton; + int console_port; GList *perms; int err; =20 @@ -1467,6 +1469,13 @@ int xen_xenstore_reset(void) relpath_printf(s, perms, "store/ring-ref", "%lu", XEN_SPECIAL_PFN(XENS= TORE)); relpath_printf(s, perms, "store/port", "%u", s->be_port); =20 + console_port =3D xen_primary_console_get_port(); + if (console_port) { + relpath_printf(s, perms, "console/ring-ref", "%lu", XEN_SPECIAL_PF= N(CONSOLE)); + relpath_printf(s, perms, "console/port", "%u", console_port); + relpath_printf(s, perms, "console/state", "%u", XenbusStateInitial= ised); + } + g_list_free_full(perms, g_free); =20 /* diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index 477e93cd92..9f57786e95 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -28,6 +28,7 @@ #include "hw/i386/kvm/xen_overlay.h" #include "hw/i386/kvm/xen_evtchn.h" #include "hw/i386/kvm/xen_gnttab.h" +#include "hw/i386/kvm/xen_primary_console.h" #include "hw/i386/kvm/xen_xenstore.h" =20 #include "hw/xen/interface/version.h" @@ -182,7 +183,8 @@ int kvm_xen_init(KVMState *s, uint32_t hypercall_msr) return ret; } =20 - /* The page couldn't be overlaid until KVM was initialized */ + /* The pages couldn't be overlaid until KVM was initialized */ + xen_primary_console_reset(); xen_xenstore_reset(); =20 return 0; @@ -811,11 +813,23 @@ static bool handle_get_param(struct kvm_xen_exit *exi= t, X86CPU *cpu, case HVM_PARAM_STORE_EVTCHN: hp.value =3D xen_xenstore_get_port(); break; + case HVM_PARAM_CONSOLE_PFN: + hp.value =3D xen_primary_console_get_pfn(); + if (!hp.value) { + err =3D -EINVAL; + } + break; + case HVM_PARAM_CONSOLE_EVTCHN: + hp.value =3D xen_primary_console_get_port(); + if (!hp.value) { + err =3D -EINVAL; + } + break; default: return false; } =20 - if (kvm_copy_to_gva(cs, arg, &hp, sizeof(hp))) { + if (!err && kvm_copy_to_gva(cs, arg, &hp, sizeof(hp))) { err =3D -EFAULT; } out: @@ -1426,6 +1440,11 @@ int kvm_xen_soft_reset(void) return err; } =20 + err =3D xen_primary_console_reset(); + if (err) { + return err; + } + err =3D xen_xenstore_reset(); if (err) { return err; --=20 2.40.1