From nobody Fri May 17 02:41:25 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=1698245487; cv=none; d=zohomail.com; s=zohoarc; b=DHisamMDzcu389me7etlDc+5yCWeDqDOKIful1Hs0tk9AlsqROYICq2zw3VCOENIyvqW2RrH5YIFT4IJ3aLaRywLa0BCWV7Gmbp9xSuazJw+DoOqujbgIeCAgSLJxdJ2Qcv7c7M8stskk7DH43KUE8RrxfDq8T9aPyQLvfR+KS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245487; 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=QOmUYFl3LA5suJXP4FpVRY+eqhPYL8puoFjgeKxcxDM=; b=Z96frgSDCR1ZWplELa3wEFcUQnbai6Z0XAxr+izmrZJ63f1nBLzYSJnUO+LaLfvKJ68GNwncyYQ2WtQiimT9XitARHnyM8p257+pOkfybb0Pr2jjSPDBEd+bdu8GBI92M5JN3k494bcNduqVzQZWjyz0Yj48MpEJsQM+WGDg4g4= 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 169824548755150.4467908447823; Wed, 25 Oct 2023 07:51:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622962.970278 (Exim 4.92) (envelope-from ) id 1qvfDs-0000ej-Az; Wed, 25 Oct 2023 14:51:04 +0000 Received: by outflank-mailman (output) from mailman id 622962.970278; Wed, 25 Oct 2023 14:51:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDs-0000eN-7l; Wed, 25 Oct 2023 14:51:04 +0000 Received: by outflank-mailman (input) for mailman id 622962; Wed, 25 Oct 2023 14:51:03 +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 1qvfDo-0008W8-Oj for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:03 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e9274ceb-7345-11ee-98d5-6d05b1d4d9a1; Wed, 25 Oct 2023 16:50:59 +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 1qvfDY-009NmZ-68; Wed, 25 Oct 2023 14:50:44 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDX-002dDz-2J; Wed, 25 Oct 2023 15:50:43 +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: e9274ceb-7345-11ee-98d5-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=QOmUYFl3LA5suJXP4FpVRY+eqhPYL8puoFjgeKxcxDM=; b=fW1SfEY/kvSu1hhyw5jhHozZpT BGCnYlGkAE2crCuUIrcAsTx0w2hlaPkPVBCLIW1ibbhQ1+XtaPnSzex7Pwu+dAF85JQh7gFQdRjAl zIgIUCJax3Hmo7ZWdVrPibJwFgj/48XN7bfTRy7/1VR7fcKk5P2QtSGQCha29pjfT9P6uWKjnwOFz CmE1gauXLgd3P/27RuSd02cs3boi2x8wg6syoT/b3j9EG0XA7N7a30s6t9nSsIPX+TLBfmQHyiKh/ hY1QDNMjspLKxlgPapPDCCTdDer8uGg/doLugfSf7hGpYr7KPoHrgSRFm9u+mz9ajGjS4L8OFHHGA ZwVHPHgA==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 01/28] i386/xen: Don't advertise XENFEAT_supervisor_mode_kernel Date: Wed, 25 Oct 2023 15:50:15 +0100 Message-Id: <20231025145042.627381-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245489572100009 Content-Type: text/plain; charset="utf-8" From: David Woodhouse This confuses lscpu into thinking it's running in PVH mode. Fixes: bedcc139248 ("i386/xen: implement HYPERVISOR_xen_version") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- target/i386/kvm/xen-emu.c | 1 - 1 file changed, 1 deletion(-) diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index 76348f9d5d..0055441b2e 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -267,7 +267,6 @@ static bool kvm_xen_hcall_xen_version(struct kvm_xen_ex= it *exit, X86CPU *cpu, fi.submap |=3D 1 << XENFEAT_writable_page_tables | 1 << XENFEAT_writable_descriptor_tables | 1 << XENFEAT_auto_translated_physmap | - 1 << XENFEAT_supervisor_mode_kernel | 1 << XENFEAT_hvm_callback_vector | 1 << XENFEAT_hvm_safe_pvclock | 1 << XENFEAT_hvm_pirqs; --=20 2.40.1 From nobody Fri May 17 02:41:25 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=1698245657; cv=none; d=zohomail.com; s=zohoarc; b=nY00N5dJUvpJcSwpTdAp6NctUWkuL5RxCT7sYyxa/vl1j8+WEmTHtqQHV9ic/0LeJN/rIge4STE3oZ6De8O/hmJDwd52OKmV//2LLeKyO/W3vkpWpB5ohwYEmz1xoM9ANmiteYLhqajMjdMrd3nCYgTLRGQkUvEbzIyRFhuWyPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245657; 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=c1KnGQGfi3x53zdFBlcTqfnMwSbqzHUr3v6mm/A0vwE=; b=RLSt6I5MkfqG+Q6DIeOA+eTqfjDp20qFcdZDEzZVau4oXgOFxVvAK4lCdfBGfZczErXyaJ4fHdFyLGskyhtdwWiiLBmztPMjOgEFKLAa/UzJpUuhzIU5bq+lxHs9zAmlCGggME9FM+0yFvjITswIw1Jio+h/+WBwcnRMkiCPknA= 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 1698245657858363.4452280411273; Wed, 25 Oct 2023 07:54:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622995.970414 (Exim 4.92) (envelope-from ) id 1qvfGd-0000yD-ET; Wed, 25 Oct 2023 14:53:55 +0000 Received: by outflank-mailman (output) from mailman id 622995.970414; Wed, 25 Oct 2023 14:53:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfGd-0000y6-By; Wed, 25 Oct 2023 14:53:55 +0000 Received: by outflank-mailman (input) for mailman id 622995; Wed, 25 Oct 2023 14:53:54 +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 1qvfEI-0000WU-Ec for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:30 +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 f877121b-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:51:25 +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 1qvfDZ-00GPLu-00; Wed, 25 Oct 2023 14:51:04 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDX-002dE3-2b; Wed, 25 Oct 2023 15:50:43 +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: f877121b-7345-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=c1KnGQGfi3x53zdFBlcTqfnMwSbqzHUr3v6mm/A0vwE=; b=MTOqGgH08Ha9n5op96rLk0cUN1 wrSDL9Zs8TWudFgFJacVmoXeWHuZuMM25p9iLuSAJRwni4Pp8vZVd2wVwJG/jYJ5YXI+hMPkbPV23 btkqGYMy6rjvy8XJJq2oIK6of/Lli+tTc9jNmWYGDBGuMYkFGWN71sFXw9nPnDhlGT6EoEFjh3jbX fl3uNsNgDdRUXagpX6nvaN6UtMjLhKSuVWo/ScfKujBJlhWsB3MGDFgDNuL5vNukoz5A8blcT8EyH 6fweryHNiDOKzm24bkI5E9w/ZJAWQ4sPR3DB95dMIlz1DwCOUJDMp1Z7GV/zznFcI5Nu4ztjVEpwQ WphupaaQ==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 02/28] i386/xen: fix per-vCPU upcall vector for Xen emulation Date: Wed, 25 Oct 2023 15:50:16 +0100 Message-Id: <20231025145042.627381-3-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245658242100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse The per-vCPU upcall vector support had three problems. Firstly it was using the wrong hypercall argument and would always return -EFAULT when the guest tried to set it up. Secondly it was using the wrong ioctl() to pass the vector to the kernel and thus the *kernel* would always return -EINVAL. Finally, even when delivering the event directly from userspace with an MSI, it put the destination CPU ID into the wrong bits of the MSI address. 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index 0055441b2e..7c504d9fa4 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) @@ -440,7 +440,8 @@ void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_= id, int type) * deliver it as an MSI. */ MSIMessage msg =3D { - .address =3D APIC_DEFAULT_ADDRESS | X86_CPU(cs)->apic_id, + .address =3D APIC_DEFAULT_ADDRESS | + (X86_CPU(cs)->apic_id << MSI_ADDR_DEST_ID_SHIFT), .data =3D vector | (1UL << MSI_DATA_LEVEL_SHIFT), }; kvm_irqchip_send_msi(kvm_state, msg); @@ -849,8 +850,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 Fri May 17 02:41:25 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 1698245669375126.43799697864984; Wed, 25 Oct 2023 07:54:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEp-0006fm-Gi; Wed, 25 Oct 2023 10:52:03 -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 1qvfEH-0005KT-J4; Wed, 25 Oct 2023 10:51:29 -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 1qvfEF-00078W-0T; Wed, 25 Oct 2023 10:51:29 -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 1qvfDZ-00GPLv-00; Wed, 25 Oct 2023 14:51:03 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDX-002dE7-2w; Wed, 25 Oct 2023 15:50:43 +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=gpval2gkdnYSDfubhYXUo8Wmpo6ErNXXryv5FV8GJTI=; b=rSWy9LoA4wJ29Sdd8/z2hODjqk sU4jyfn/ca7c900gi56KR/yIHtgCkDipOf7DVpsfAhVoJhNpxot9LipzStyKPCVyqwKMKTxysIaEv 0YuAXNyE5AgxkxRSeJYKqBpfppT7/6ao2CisXyqhqzmDL2K6l4kQ5tHHleiN4DqL55cnqp7z5l9xR 4Z5wjBvcBtTYCR6i7K1gjbo4ajmj2LEStD5lXp3kLeHBxTzriCK9AQHne857Of2+1MRrkusbVQc15 lq7LnDg8Bb95Xbt+0qbQHD7Wbc+gBgQCeF9EzMWlLPQhPDYWQbDEOxDlcNayuAnjgD06/VptlWhXZ 2U2EZvtA==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 03/28] hw/xen: select kernel mode for per-vCPU event channel upcall vector Date: Wed, 25 Oct 2023 15:50:17 +0100 Message-Id: <20231025145042.627381-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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+fe87d11d956b9f6f1554+7367+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: 1698245670364100001 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#1, 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 Reviewed-by: Paul Durrant --- 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 a731738411..3d6f4b4a0a 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 7c504d9fa4..75b2c557b9 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 Fri May 17 02:41:25 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=1698245512; cv=none; d=zohomail.com; s=zohoarc; b=I2vDOTR1hbqP9GcYIvai95EDayjV0s02KWP+SEIYAmVcwpO8Yr+RWg+ExQznZRM38EpNop9IZUpSwlIykjRPki6Z0qL5aEB8/W2+NJck0Qan9nIb+xsbet82BN4kVYaiED9Yx04kDN03hu/iBj7VIcQObuCPTv64bxoDO4mL9So= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245512; 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=Q/tyhQvSuMwg2Gh5kOIH6qsA0eNCoglo/BC/VrIl6Es=; b=KMG2alOGHm0agYvBs+mYWK8FnqzpTabkTtNauWY81fVz2DE6yGQ4z2XQniFQA/5lGf36+zm1S8WlgE3vRixTRMfqjUDG0fi1ubgZjJilCILnQIi/Oyc9+1tPdkicS/uiWGkE7dcPy5xdTMQ9XYOO8RR+M4dLmYWY7fMdbFqCUPM= 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 1698245512338882.3211435325926; Wed, 25 Oct 2023 07:51:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622973.970384 (Exim 4.92) (envelope-from ) id 1qvfE3-0003jS-QL; Wed, 25 Oct 2023 14:51:15 +0000 Received: by outflank-mailman (output) from mailman id 622973.970384; Wed, 25 Oct 2023 14:51:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfE3-0003ie-E7; Wed, 25 Oct 2023 14:51:15 +0000 Received: by outflank-mailman (input) for mailman id 622973; Wed, 25 Oct 2023 14:51:13 +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 1qvfE1-0008W8-2k for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:13 +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 f0200bad-7345-11ee-98d5-6d05b1d4d9a1; Wed, 25 Oct 2023 16:51:12 +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 1qvfDZ-00GPLw-00; Wed, 25 Oct 2023 14:50:51 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDX-002dEB-38; Wed, 25 Oct 2023 15:50:43 +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: f0200bad-7345-11ee-98d5-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=Q/tyhQvSuMwg2Gh5kOIH6qsA0eNCoglo/BC/VrIl6Es=; b=KDYI3aY4tMOqlZWdfNfO3LfWji oD5wYOBY7+ELSt03QoqbH58su+Ih3wGW5y4L029rvsFpFws8RSdxkpx1kvzrlS+TR8NZrSvLHKS2E SjvLuuRm8b/GnqIqaDOe5rDZTyJ/8Guse6k/gguUsxYD44GH6Tn/1C0kqkUq3glxbg20jjPwKv8u9 Utgyvf4duButgytsgIFvJi/gbUd0SSA1jqoxw3sxA0TP7WEocX4xU//yXPAlhMq2BmAgFO6SYdQxX O1MwfOqd73UkIrEQm5B9gRr0qBVYQsayxRgtHc1M0nfSNSW/4X7QtGGxiam1VQgi1BhfsTGnBKIs/ 5Klyv7rQ==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 04/28] hw/xen: don't clear map_track[] in xen_gnttab_reset() Date: Wed, 25 Oct 2023 15:50:18 +0100 Message-Id: <20231025145042.627381-5-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245513718100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse The refcounts actually correspond to 'active_ref' structures stored in a GHashTable per "user" on the backend side (mostly, per XenDevice). If we zero map_track[] on reset, then when the backend drivers get torn down and release their mapping we hit the assert(s->map_track[ref] !=3D 0) in gnt_unref(). So leave them in place. Each backend driver will disconnect and reconnect as the guest comes back up again and reconnects, and it all works out OK in the end as the old refs get dropped. Fixes: de26b2619789 ("hw/xen: Implement soft reset for emulated gnttab") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/kvm/xen_gnttab.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/hw/i386/kvm/xen_gnttab.c b/hw/i386/kvm/xen_gnttab.c index 21c30e3659..839ec920a1 100644 --- a/hw/i386/kvm/xen_gnttab.c +++ b/hw/i386/kvm/xen_gnttab.c @@ -541,7 +541,5 @@ int xen_gnttab_reset(void) 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 - memset(s->map_track, 0, s->max_frames * ENTRIES_PER_FRAME_V1); - return 0; } --=20 2.40.1 From nobody Fri May 17 02:41:25 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 1698245555197514.149845828493; Wed, 25 Oct 2023 07:52:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfES-0005TZ-SS; Wed, 25 Oct 2023 10:51:41 -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 1qvfE4-0005CG-FR; Wed, 25 Oct 2023 10:51:18 -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 1qvfDp-000767-Dr; Wed, 25 Oct 2023 10:51:16 -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 1qvfDZ-00GPLx-01; Wed, 25 Oct 2023 14:50:52 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEF-06; Wed, 25 Oct 2023 15:50:44 +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: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description; bh=RxBAjsQ+mysvOozFK2bkVeJvxuxKEpOcW9P4vMvsaUw=; b=kWEwCVesu3RU1Gi+zD5e+MXOzL TI6NwMrSRoAQx1N/L//K4TlUXhKgj7PQrl+DuBhCNNSDgpxlC7tv6T7Eclwqo3JB/3jdzRkNzQ9qF quoMMtl9n21EtXIqLbI9iMJAqKE5Ob4RUIz7XAD1NO24I6Wwr+QeGorNW5GKyAU6AJbWDsEToPZSu XMKIpWSZ84bjXrvQIeIKE++0nq8nOdav05MHqaccNURQ/24YIQufkFSp5KZYBu8Or7scgLcu/6cHU UsvgICpmvIfuJWV3/+UaFP9GBwV1+sI8ZM3NKS1yiX/c3qj/QciOq9QyDey+tRL/JUEb9G4h67r4c sMq+tCFA==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 05/28] hw/xen: fix XenStore watch delivery to guest Date: Wed, 25 Oct 2023 15:50:19 +0100 Message-Id: <20231025145042.627381-6-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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+fe87d11d956b9f6f1554+7367+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: 1698245555976100003 From: David Woodhouse When fire_watch_cb() found the response buffer empty, it would call deliver_watch() to generate the XS_WATCH_EVENT message in the response buffer and send an event channel notification to the guest=E2=80=A6 without actually *copying* the response buffer into the ring. So there was nothing for the guest to see. The pending response didn't actually get processed into the ring until the guest next triggered some activity from its side. Add the missing call to put_rsp(). It might have been slightly nicer to call xen_xenstore_event() here, which would *almost* have worked. Except for the fact that it calls xen_be_evtchn_pending() to check that it really does have an event pending (and clear the eventfd for next time). And under Xen it's defined that setting that fd to O_NONBLOCK isn't guaranteed to work, so the emu implementation follows suit. This fixes Xen device hot-unplug. Fixes: 0254c4d19df ("hw/xen: Add xenstore wire implementation and implement= ation stubs") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/kvm/xen_xenstore.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index 660d0b72f9..8e716a7009 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -1357,10 +1357,12 @@ static void fire_watch_cb(void *opaque, const char = *path, const char *token) } else { deliver_watch(s, path, token); /* - * If the message was queued because there was already ring activi= ty, - * no need to wake the guest. But if not, we need to send the evtc= hn. + * Attempt to queue the message into the actual ring, and send + * the event channel notification if any bytes are copied. */ - xen_be_evtchn_notify(s->eh, s->be_port); + if (s->rsp_pending && put_rsp(s) > 0) { + xen_be_evtchn_notify(s->eh, s->be_port); + } } } =20 --=20 2.40.1 From nobody Fri May 17 02:41:25 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=1698245483; cv=none; d=zohomail.com; s=zohoarc; b=KqET32loYemVUWtmRs01I4bQY/wscCL3Pm6nplcIkPypdx3dQYwsti2S3i7wImYnwX+SI3tpEL9IeASqWuBp0tzEdOhNCKwQwCXP//9VVpJT4gbw/3ObBWNjyqMe8W6qYWKK6dj7/+oPBfqiTQO9fhXL8i/TNSM/cOzCivUKcS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245483; 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=cMQamAmGxVX8j1TYaTFUxDpxUmOm6N6treNgi5dENCI=; b=cG1DdgbcgRQyoK8a8JRwuuDOYcJdDFdsdq3Fv1reC6Kv8UQ0MgWsPmizn9u4ZKVEC0Ri6XTzoXJxC5iba1hQpfmlrbgrqLI5s7v5kpUZhpw4wkCMKguqN10xjQOYJCLfjQuf/wA5230AHjBtuVcwq+IR0H/yk1kKw5IW2mPD0OQ= 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 1698245483814813.7518521928217; Wed, 25 Oct 2023 07:51:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622961.970274 (Exim 4.92) (envelope-from ) id 1qvfDs-0000cA-3Q; Wed, 25 Oct 2023 14:51:04 +0000 Received: by outflank-mailman (output) from mailman id 622961.970274; Wed, 25 Oct 2023 14:51:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDs-0000c3-0q; Wed, 25 Oct 2023 14:51:04 +0000 Received: by outflank-mailman (input) for mailman id 622961; Wed, 25 Oct 2023 14:51:02 +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 1qvfDq-0000WU-NP for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:02 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e91455e0-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:50:59 +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 1qvfDY-009Nmf-Ta; Wed, 25 Oct 2023 14:50:44 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEJ-0I; Wed, 25 Oct 2023 15:50:44 +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: e91455e0-7345-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=cMQamAmGxVX8j1TYaTFUxDpxUmOm6N6treNgi5dENCI=; b=WtDuCSvr5Q0uexpCx5QwfNxVZy ROoD7PbXDpLBTHv10a4sb52qOcYxP7sVaVH/NJGwCgJ77PtptHAmxIq1lmRxaLvn1/sAI4mNcVa5y 12MBgl4J0jy+1GLBWvXaSTgc4K1BCjA/Yzihw3gyve96vcuHO9XMDH9OrxcLxgRE8veib5GQ8ptb2 hY7TYHtsyq18aAgKXiMYIlQ+358roX1Kia+c+gpKgmAlDKQ8yBhxawYBqJm5uBrelE/kfRoCjO185 nYGVKukjvboJ/wX9kHgvqrqfE/NVMb6HDHzCd7q1HBeO/OLNaZ1qtk3OhrwOmFOTaGnRChQkaQuje 9y7XfXuw==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 06/28] hw/xen: take iothread mutex in xen_evtchn_reset_op() Date: Wed, 25 Oct 2023 15:50:20 +0100 Message-Id: <20231025145042.627381-7-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245485630100003 Content-Type: text/plain; charset="utf-8" From: David Woodhouse The xen_evtchn_soft_reset() function requires the iothread mutex, but is also called for the EVTCHNOP_reset hypercall. Ensure the mutex is taken in that case. Fixes: a15b10978fe6 ("hw/xen: Implement EVTCHNOP_reset") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/kvm/xen_evtchn.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c index 3d6f4b4a0a..b2b4be9983 100644 --- a/hw/i386/kvm/xen_evtchn.c +++ b/hw/i386/kvm/xen_evtchn.c @@ -1135,6 +1135,7 @@ int xen_evtchn_reset_op(struct evtchn_reset *reset) return -ESRCH; } =20 + QEMU_IOTHREAD_LOCK_GUARD(); return xen_evtchn_soft_reset(); } =20 --=20 2.40.1 From nobody Fri May 17 02:41:25 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=1698245494; cv=none; d=zohomail.com; s=zohoarc; b=bcT5gOGOTVfm6zMDZQQ3hfLmS3sqHJctc/vXxf0ZiAPeCirG3tA+IAPoMZ8y7lgi/86GMN54lzxVhVjXgEVEp0nt6qT2s9Il7ITrhx7LPWYYwsq4e8pTFGBBO2CvtLIvpAfcfMjdvXF+XXQ9RGPviOw1XZCqgPTNA+SOGAWkvKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245494; 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=I7wwUWDSmNrD50IckcuS/vpghKxFsMuU+uj7Ug/+mno=; b=OW27B61VhhvwcliovPt/AEVQerXnUa+2s+pnNi4Nd9cbX2ZfqwBvUexVVzPRwyGyN+T2RDvhX4M0yPzMJrIE/T4ssyuTHMyb05hKtjiiCH+Tzc+ZLY+fhLUHkwatWj5o/PJixaDp52jC7nrDkOCOLVBrS+0IO7s/nvOlORLjqnk= 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 1698245494752939.2996992672985; Wed, 25 Oct 2023 07:51:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622965.970303 (Exim 4.92) (envelope-from ) id 1qvfDu-0001NF-Sm; Wed, 25 Oct 2023 14:51:06 +0000 Received: by outflank-mailman (output) from mailman id 622965.970303; Wed, 25 Oct 2023 14:51:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDu-0001N4-Pa; Wed, 25 Oct 2023 14:51:06 +0000 Received: by outflank-mailman (input) for mailman id 622965; Wed, 25 Oct 2023 14:51:04 +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 1qvfDs-0000WU-No for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:04 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e9144c93-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:50:59 +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 1qvfDY-009Nma-Hc; Wed, 25 Oct 2023 14:50:44 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEN-0Y; Wed, 25 Oct 2023 15:50:44 +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: e9144c93-7345-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=I7wwUWDSmNrD50IckcuS/vpghKxFsMuU+uj7Ug/+mno=; b=RvDifJ46k3zOQxzO3K8gyXMav9 h9wbWdHVLd9gbqWP/b4m/KQeTI2stcYxTPljdDzPt6hb7NbRhR2P0Z4xKNwxtgzxk3N2Igdu5kwqT AXV3Jx/OXlBhdliH0firkNh2O5qAZTR6XHzFMcLDeFRdKJoSGTYLHlhONm24s0uwaH0rDz1Fk/PGw 3QtrkBftuCQR9gV2WZxNA4tVN+MG4Zja8lhsVua2l7qFzWDiSaHeANeDiYbCF+WoLyBNRQbkEgsY2 OfZjG7o/oJkUjbPK3xppz5WL8MhBsZtqCyEEELWg6Dn7mGtZrcsYl+Wq2DQKqUo4lVF+bNWFOf8G7 JSaqrwxg==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 07/28] hw/xen: use correct default protocol for xen-block on x86 Date: Wed, 25 Oct 2023 15:50:21 +0100 Message-Id: <20231025145042.627381-8-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245495588100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Even on x86_64 the default protocol is the x86-32 one if the guest doesn't specifically ask for x86-64. Fixes: b6af8926fb85 ("xen: add implementations of xen-block connect and dis= connect functions...") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/block/xen-block.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index a07cd7eb5d..64470fc579 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -117,7 +117,11 @@ static void xen_block_connect(XenDevice *xendev, Error= **errp) =20 if (xen_device_frontend_scanf(xendev, "protocol", "%ms", &str) !=3D 1) { - protocol =3D BLKIF_PROTOCOL_NATIVE; + /* x86 defaults to the 32-bit protocol even for 64-bit guests. */ + if (object_dynamic_cast(OBJECT(qdev_get_machine()), "x86-machine")) + protocol =3D BLKIF_PROTOCOL_X86_32; + else + protocol =3D BLKIF_PROTOCOL_NATIVE; } else { if (strcmp(str, XEN_IO_PROTO_ABI_X86_32) =3D=3D 0) { protocol =3D BLKIF_PROTOCOL_X86_32; --=20 2.40.1 From nobody Fri May 17 02:41:25 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 1698245545619793.27544624526; Wed, 25 Oct 2023 07:52:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEP-0005SP-9Y; Wed, 25 Oct 2023 10:51:37 -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 1qvfE8-0005E6-Ry; Wed, 25 Oct 2023 10:51:23 -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 1qvfDp-00075z-DI; Wed, 25 Oct 2023 10:51:18 -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 1qvfDZ-00GPLy-00; Wed, 25 Oct 2023 14:50:52 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dER-0t; Wed, 25 Oct 2023 15:50:44 +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: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description; bh=whwrxQfu34eIg/PcGjcBAI/B4Oo/UALoBhuUlK3a190=; b=KDzGOyRparAnnjvPQuEd8zIi5K k7eb8lLOjHiB0WgXqvHuzQDwCGSF8SeNp3WXmidEbK2bWXOc8w6x3TD6K+UXDO4sPnW2qMxW/v5SM JkSb1Z2JTnWnr0HgbFIP0bx5OGzSEiK94Vb17zrb+YHVm0KZ7bymHP1u6UIhnhK+Bc6wUnU6y7Tcd QiEF0/VJRFk98yveKudVwc1RUon2pG3PxUld5/P+sDKlYT/AT53ZbUp+UowXdbZhIXvkNmCB2PEB1 nhKcb/KtHS5HnBx5aIdzj2GaTnYdKhVRfmjK8CnHDLlElncrHUR+DaNttogg600wZhp3rq1/l+3G0 urtNKg8g==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 08/28] i386/xen: Ignore VCPU_SSHOTTMR_future flag in set_singleshot_timer() Date: Wed, 25 Oct 2023 15:50:22 +0100 Message-Id: <20231025145042.627381-9-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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+fe87d11d956b9f6f1554+7367+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: 1698245548062100003 From: David Woodhouse Upstream Xen now ignores this flag=C2=B9, since the only guest kernel ever = to use it was buggy. =C2=B9 https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dcommitdiff;h=3D19c6c= bd909 Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- target/i386/kvm/xen-emu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index 75b2c557b9..1dc9ab0d91 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -1077,17 +1077,13 @@ static int vcpuop_stop_periodic_timer(CPUState *tar= get) * Must always be called with xen_timers_lock held. */ static int do_set_singleshot_timer(CPUState *cs, uint64_t timeout_abs, - bool future, bool linux_wa) + bool linux_wa) { CPUX86State *env =3D &X86_CPU(cs)->env; int64_t now =3D kvm_get_current_ns(); int64_t qemu_now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); int64_t delta =3D timeout_abs - now; =20 - if (future && timeout_abs < now) { - return -ETIME; - } - if (linux_wa && unlikely((int64_t)timeout_abs < 0 || (delta > 0 && (uint32_t)(delta >> 50) !=3D 0)= )) { /* @@ -1129,9 +1125,13 @@ static int vcpuop_set_singleshot_timer(CPUState *cs,= uint64_t arg) } =20 QEMU_LOCK_GUARD(&X86_CPU(cs)->env.xen_timers_lock); - return do_set_singleshot_timer(cs, sst.timeout_abs_ns, - !!(sst.flags & VCPU_SSHOTTMR_future), - false); + + /* + * We ignore the VCPU_SSHOTTMR_future flag, just as Xen now does. + * The only guest that ever used it, got it wrong. + * https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dcommitdiff;h=3D19c6= cbd909 + */ + return do_set_singleshot_timer(cs, sst.timeout_abs_ns, false); } =20 static int vcpuop_stop_singleshot_timer(CPUState *cs) @@ -1156,7 +1156,7 @@ static bool kvm_xen_hcall_set_timer_op(struct kvm_xen= _exit *exit, X86CPU *cpu, err =3D vcpuop_stop_singleshot_timer(CPU(cpu)); } else { QEMU_LOCK_GUARD(&X86_CPU(cpu)->env.xen_timers_lock); - err =3D do_set_singleshot_timer(CPU(cpu), timeout, false, true); + err =3D do_set_singleshot_timer(CPU(cpu), timeout, true); } exit->u.hcall.result =3D err; return true; @@ -1844,7 +1844,7 @@ int kvm_put_xen_state(CPUState *cs) QEMU_LOCK_GUARD(&env->xen_timers_lock); if (env->xen_singleshot_timer_ns) { ret =3D do_set_singleshot_timer(cs, env->xen_singleshot_timer_= ns, - false, false); + false); if (ret < 0) { return ret; } --=20 2.40.1 From nobody Fri May 17 02:41:25 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 1698245719234114.78523047975614; Wed, 25 Oct 2023 07:55:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEO-0005SJ-MG; Wed, 25 Oct 2023 10:51:36 -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 1qvfE2-0005C8-3A; Wed, 25 Oct 2023 10:51:18 -0400 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvfDo-00074r-97; Wed, 25 Oct 2023 10:51:13 -0400 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 1qvfDY-009Nmc-PU; Wed, 25 Oct 2023 14:50:44 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEV-19; Wed, 25 Oct 2023 15:50:44 +0100 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=53WomBMSQD6O08ryGIJ2Z7YE0izoAIIrgQty4UEWxiA=; b=rQcsVgd+7mP32wjXgrSCr6EOdY OHW7FEMVWCbgL3UhQXk0g+wObsk1DmThItrfxumad8S2DKR/SAy6pUZ3p/BHGZwOEXCRo0z2rCNDT owvcq0YIN4uAfTLkk1JEM/kVA4TgOyRlxY0raLHu9hnCjGEyq5CIIh+nVVhcE9jU3X7x+j2pU+d0C NhngvdA+i75zJ4Wa5qI5Djnh+O50utL/3zI8TXAjkOs82l1fVUOmPi+penG1RRESMtr3h9N8I12lP Ebw/OxLzBh+9y67LdxJk5svKxZuXesBQCs5pxnpZ7gXtM5B6CoscEmNoqdIEppjCxg0nA8AC2jXiB qKskIlbw==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 09/28] hw/xen: Clean up event channel 'type_val' handling to use union Date: Wed, 25 Oct 2023 15:50:23 +0100 Message-Id: <20231025145042.627381-10-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.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:1236::1; envelope-from=BATV+85b1c44ac99574f3713d+7367+infradead.org+dwmw2@casper.srs.infradead.org; helo=casper.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: 1698245720695100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse A previous implementation of this stuff used a 64-bit field for all of the port information (vcpu/type/type_val) and did atomic exchanges on them. When I implemented that in Qemu I regretted my life choices and just kept it simple with locking instead. So there's no need for the XenEvtchnPort to be so simplistic. We can use a union for the pirq/virq/interdomain information, which lets us keep a separate bit for the 'remote domain' in interdomain ports. A single bit is enough since the only possible targets are loopback or qemu itself. So now we can ditch PORT_INFO_TYPEVAL_REMOTE_QEMU and the horrid manual masking, although the in-memory representation is identical so there's no change in the saved state ABI. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/kvm/xen_evtchn.c | 151 ++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 81 deletions(-) diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c index b2b4be9983..02b8cbf8df 100644 --- a/hw/i386/kvm/xen_evtchn.c +++ b/hw/i386/kvm/xen_evtchn.c @@ -58,7 +58,15 @@ OBJECT_DECLARE_SIMPLE_TYPE(XenEvtchnState, XEN_EVTCHN) typedef struct XenEvtchnPort { uint32_t vcpu; /* Xen/ACPI vcpu_id */ uint16_t type; /* EVTCHNSTAT_xxxx */ - uint16_t type_val; /* pirq# / virq# / remote port according to type */ + union { + uint16_t val; /* raw value for serialization etc. */ + uint16_t pirq; + uint16_t virq; + struct { + uint16_t port:15; + uint16_t to_qemu:1; /* Only two targets; qemu or loopback */ + } interdomain; + } u; } XenEvtchnPort; =20 /* 32-bit compatibility definitions, also used natively in 32-bit build */ @@ -105,14 +113,6 @@ struct xenevtchn_handle { int fd; }; =20 -/* - * For unbound/interdomain ports there are only two possible remote - * domains; self and QEMU. Use a single high bit in type_val for that, - * and the low bits for the remote port number (or 0 for unbound). - */ -#define PORT_INFO_TYPEVAL_REMOTE_QEMU 0x8000 -#define PORT_INFO_TYPEVAL_REMOTE_PORT_MASK 0x7FFF - /* * These 'emuirq' values are used by Xen in the LM stream... and yes, I am * insane enough to think about guest-transparent live migration from actu= al @@ -210,16 +210,16 @@ static int xen_evtchn_post_load(void *opaque, int ver= sion_id) XenEvtchnPort *p =3D &s->port_table[i]; =20 if (p->type =3D=3D EVTCHNSTAT_pirq) { - assert(p->type_val); - assert(p->type_val < s->nr_pirqs); + assert(p->u.pirq); + assert(p->u.pirq < s->nr_pirqs); =20 /* * Set the gsi to IRQ_UNBOUND; it may be changed to an actual * GSI# below, or to IRQ_MSI_EMU when the MSI table snooping * catches up with it. */ - s->pirq[p->type_val].gsi =3D IRQ_UNBOUND; - s->pirq[p->type_val].port =3D i; + s->pirq[p->u.pirq].gsi =3D IRQ_UNBOUND; + s->pirq[p->u.pirq].port =3D i; } } /* Rebuild s->pirq[].gsi mapping */ @@ -243,7 +243,7 @@ static const VMStateDescription xen_evtchn_port_vmstate= =3D { .fields =3D (VMStateField[]) { VMSTATE_UINT32(vcpu, XenEvtchnPort), VMSTATE_UINT16(type, XenEvtchnPort), - VMSTATE_UINT16(type_val, XenEvtchnPort), + VMSTATE_UINT16(u.val, XenEvtchnPort), VMSTATE_END_OF_LIST() } }; @@ -605,14 +605,13 @@ static void unbind_backend_ports(XenEvtchnState *s) =20 for (i =3D 1; i < s->nr_ports; i++) { p =3D &s->port_table[i]; - if (p->type =3D=3D EVTCHNSTAT_interdomain && - (p->type_val & PORT_INFO_TYPEVAL_REMOTE_QEMU)) { - evtchn_port_t be_port =3D p->type_val & PORT_INFO_TYPEVAL_REMO= TE_PORT_MASK; + if (p->type =3D=3D EVTCHNSTAT_interdomain && p->u.interdomain.to_q= emu) { + evtchn_port_t be_port =3D p->u.interdomain.port; =20 if (s->be_handles[be_port]) { /* This part will be overwritten on the load anyway. */ p->type =3D EVTCHNSTAT_unbound; - p->type_val =3D PORT_INFO_TYPEVAL_REMOTE_QEMU; + p->u.interdomain.port =3D 0; =20 /* Leave the backend port open and unbound too. */ if (kvm_xen_has_cap(EVTCHN_SEND)) { @@ -650,30 +649,22 @@ int xen_evtchn_status_op(struct evtchn_status *status) =20 switch (p->type) { case EVTCHNSTAT_unbound: - if (p->type_val & PORT_INFO_TYPEVAL_REMOTE_QEMU) { - status->u.unbound.dom =3D DOMID_QEMU; - } else { - status->u.unbound.dom =3D xen_domid; - } + status->u.unbound.dom =3D p->u.interdomain.to_qemu ? DOMID_QEMU + : xen_domid; break; =20 case EVTCHNSTAT_interdomain: - if (p->type_val & PORT_INFO_TYPEVAL_REMOTE_QEMU) { - status->u.interdomain.dom =3D DOMID_QEMU; - } else { - status->u.interdomain.dom =3D xen_domid; - } - - status->u.interdomain.port =3D p->type_val & - PORT_INFO_TYPEVAL_REMOTE_PORT_MASK; + status->u.interdomain.dom =3D p->u.interdomain.to_qemu ? DOMID_QEMU + : xen_domid; + status->u.interdomain.port =3D p->u.interdomain.port; break; =20 case EVTCHNSTAT_pirq: - status->u.pirq =3D p->type_val; + status->u.pirq =3D p->u.pirq; break; =20 case EVTCHNSTAT_virq: - status->u.virq =3D p->type_val; + status->u.virq =3D p->u.virq; break; } =20 @@ -989,7 +980,7 @@ static int clear_port_pending(XenEvtchnState *s, evtchn= _port_t port) static void free_port(XenEvtchnState *s, evtchn_port_t port) { s->port_table[port].type =3D EVTCHNSTAT_closed; - s->port_table[port].type_val =3D 0; + s->port_table[port].u.val =3D 0; s->port_table[port].vcpu =3D 0; =20 if (s->nr_ports =3D=3D port + 1) { @@ -1012,7 +1003,7 @@ static int allocate_port(XenEvtchnState *s, uint32_t = vcpu, uint16_t type, if (s->port_table[p].type =3D=3D EVTCHNSTAT_closed) { s->port_table[p].vcpu =3D vcpu; s->port_table[p].type =3D type; - s->port_table[p].type_val =3D val; + s->port_table[p].u.val =3D val; =20 *port =3D p; =20 @@ -1053,15 +1044,15 @@ static int close_port(XenEvtchnState *s, evtchn_por= t_t port, return -ENOENT; =20 case EVTCHNSTAT_pirq: - s->pirq[p->type_val].port =3D 0; - if (s->pirq[p->type_val].is_translated) { + s->pirq[p->u.pirq].port =3D 0; + if (s->pirq[p->u.pirq].is_translated) { *flush_kvm_routes =3D true; } break; =20 case EVTCHNSTAT_virq: - kvm_xen_set_vcpu_virq(virq_is_global(p->type_val) ? 0 : p->vcpu, - p->type_val, 0); + kvm_xen_set_vcpu_virq(virq_is_global(p->u.virq) ? 0 : p->vcpu, + p->u.virq, 0); break; =20 case EVTCHNSTAT_ipi: @@ -1071,8 +1062,8 @@ static int close_port(XenEvtchnState *s, evtchn_port_= t port, break; =20 case EVTCHNSTAT_interdomain: - if (p->type_val & PORT_INFO_TYPEVAL_REMOTE_QEMU) { - uint16_t be_port =3D p->type_val & ~PORT_INFO_TYPEVAL_REMOTE_Q= EMU; + if (p->u.interdomain.to_qemu) { + uint16_t be_port =3D p->u.interdomain.port; struct xenevtchn_handle *xc =3D s->be_handles[be_port]; if (xc) { if (kvm_xen_has_cap(EVTCHN_SEND)) { @@ -1082,14 +1073,15 @@ static int close_port(XenEvtchnState *s, evtchn_por= t_t port, } } else { /* Loopback interdomain */ - XenEvtchnPort *rp =3D &s->port_table[p->type_val]; - if (!valid_port(p->type_val) || rp->type_val !=3D port || + XenEvtchnPort *rp =3D &s->port_table[p->u.interdomain.port]; + if (!valid_port(p->u.interdomain.port) || + rp->u.interdomain.port !=3D port || rp->type !=3D EVTCHNSTAT_interdomain) { error_report("Inconsistent state for interdomain unbind"); } else { /* Set the other end back to unbound */ rp->type =3D EVTCHNSTAT_unbound; - rp->type_val =3D 0; + rp->u.interdomain.port =3D 0; } } break; @@ -1214,7 +1206,7 @@ int xen_evtchn_bind_vcpu_op(struct evtchn_bind_vcpu *= vcpu) if (p->type =3D=3D EVTCHNSTAT_interdomain || p->type =3D=3D EVTCHNSTAT_unbound || p->type =3D=3D EVTCHNSTAT_pirq || - (p->type =3D=3D EVTCHNSTAT_virq && virq_is_global(p->type_val))) { + (p->type =3D=3D EVTCHNSTAT_virq && virq_is_global(p->u.virq))) { /* * unmask_port() with do_unmask=3D=3Dfalse will just raise the eve= nt * on the new vCPU if the port was already pending. @@ -1359,19 +1351,15 @@ int xen_evtchn_bind_ipi_op(struct evtchn_bind_ipi *= ipi) int xen_evtchn_bind_interdomain_op(struct evtchn_bind_interdomain *interdo= main) { XenEvtchnState *s =3D xen_evtchn_singleton; - uint16_t type_val; int ret; =20 if (!s) { return -ENOTSUP; } =20 - if (interdomain->remote_dom =3D=3D DOMID_QEMU) { - type_val =3D PORT_INFO_TYPEVAL_REMOTE_QEMU; - } else if (interdomain->remote_dom =3D=3D DOMID_SELF || - interdomain->remote_dom =3D=3D xen_domid) { - type_val =3D 0; - } else { + if (interdomain->remote_dom !=3D DOMID_QEMU && + interdomain->remote_dom !=3D DOMID_SELF && + interdomain->remote_dom !=3D xen_domid) { return -ESRCH; } =20 @@ -1382,8 +1370,8 @@ int xen_evtchn_bind_interdomain_op(struct evtchn_bind= _interdomain *interdomain) qemu_mutex_lock(&s->port_lock); =20 /* The newly allocated port starts out as unbound */ - ret =3D allocate_port(s, 0, EVTCHNSTAT_unbound, type_val, - &interdomain->local_port); + ret =3D allocate_port(s, 0, EVTCHNSTAT_unbound, 0, &interdomain->local= _port); + if (ret) { goto out; } @@ -1408,7 +1396,8 @@ int xen_evtchn_bind_interdomain_op(struct evtchn_bind= _interdomain *interdomain) assign_kernel_eventfd(lp->type, xc->guest_port, xc->fd); } lp->type =3D EVTCHNSTAT_interdomain; - lp->type_val =3D PORT_INFO_TYPEVAL_REMOTE_QEMU | interdomain->remo= te_port; + lp->u.interdomain.to_qemu =3D 1; + lp->u.interdomain.port =3D interdomain->remote_port; ret =3D 0; } else { /* Loopback */ @@ -1416,19 +1405,18 @@ int xen_evtchn_bind_interdomain_op(struct evtchn_bi= nd_interdomain *interdomain) XenEvtchnPort *lp =3D &s->port_table[interdomain->local_port]; =20 /* - * The 'remote' port for loopback must be an unbound port allocate= d for - * communication with the local domain (as indicated by rp->type_v= al - * being zero, not PORT_INFO_TYPEVAL_REMOTE_QEMU), and must *not* = be - * the port that was just allocated for the local end. + * The 'remote' port for loopback must be an unbound port allocated + * for communication with the local domain, and must *not* be the + * port that was just allocated for the local end. */ if (interdomain->local_port !=3D interdomain->remote_port && - rp->type =3D=3D EVTCHNSTAT_unbound && rp->type_val =3D=3D 0) { + rp->type =3D=3D EVTCHNSTAT_unbound && !rp->u.interdomain.to_qe= mu) { =20 rp->type =3D EVTCHNSTAT_interdomain; - rp->type_val =3D interdomain->local_port; + rp->u.interdomain.port =3D interdomain->local_port; =20 lp->type =3D EVTCHNSTAT_interdomain; - lp->type_val =3D interdomain->remote_port; + lp->u.interdomain.port =3D interdomain->remote_port; } else { ret =3D -EINVAL; } @@ -1447,7 +1435,6 @@ int xen_evtchn_bind_interdomain_op(struct evtchn_bind= _interdomain *interdomain) int xen_evtchn_alloc_unbound_op(struct evtchn_alloc_unbound *alloc) { XenEvtchnState *s =3D xen_evtchn_singleton; - uint16_t type_val; int ret; =20 if (!s) { @@ -1458,18 +1445,20 @@ int xen_evtchn_alloc_unbound_op(struct evtchn_alloc= _unbound *alloc) return -ESRCH; } =20 - if (alloc->remote_dom =3D=3D DOMID_QEMU) { - type_val =3D PORT_INFO_TYPEVAL_REMOTE_QEMU; - } else if (alloc->remote_dom =3D=3D DOMID_SELF || - alloc->remote_dom =3D=3D xen_domid) { - type_val =3D 0; - } else { + if (alloc->remote_dom !=3D DOMID_QEMU && + alloc->remote_dom !=3D DOMID_SELF && + alloc->remote_dom !=3D xen_domid) { return -EPERM; } =20 qemu_mutex_lock(&s->port_lock); =20 - ret =3D allocate_port(s, 0, EVTCHNSTAT_unbound, type_val, &alloc->port= ); + ret =3D allocate_port(s, 0, EVTCHNSTAT_unbound, 0, &alloc->port); + + if (!ret && alloc->remote_dom =3D=3D DOMID_QEMU) { + XenEvtchnPort *p =3D &s->port_table[alloc->port]; + p->u.interdomain.to_qemu =3D 1; + } =20 qemu_mutex_unlock(&s->port_lock); =20 @@ -1496,12 +1485,12 @@ int xen_evtchn_send_op(struct evtchn_send *send) =20 switch (p->type) { case EVTCHNSTAT_interdomain: - if (p->type_val & PORT_INFO_TYPEVAL_REMOTE_QEMU) { + if (p->u.interdomain.to_qemu) { /* * This is an event from the guest to qemu itself, which is * serving as the driver domain. */ - uint16_t be_port =3D p->type_val & ~PORT_INFO_TYPEVAL_REMOTE_Q= EMU; + uint16_t be_port =3D p->u.interdomain.port; struct xenevtchn_handle *xc =3D s->be_handles[be_port]; if (xc) { eventfd_write(xc->fd, 1); @@ -1511,7 +1500,7 @@ int xen_evtchn_send_op(struct evtchn_send *send) } } else { /* Loopback interdomain ports; just a complex IPI */ - set_port_pending(s, p->type_val); + set_port_pending(s, p->u.interdomain.port); } break; =20 @@ -1553,8 +1542,7 @@ int xen_evtchn_set_port(uint16_t port) =20 /* QEMU has no business sending to anything but these */ if (p->type =3D=3D EVTCHNSTAT_virq || - (p->type =3D=3D EVTCHNSTAT_interdomain && - (p->type_val & PORT_INFO_TYPEVAL_REMOTE_QEMU))) { + (p->type =3D=3D EVTCHNSTAT_interdomain && p->u.interdomain.to_qemu= )) { set_port_pending(s, port); ret =3D 0; } @@ -2064,7 +2052,7 @@ int xen_be_evtchn_bind_interdomain(struct xenevtchn_h= andle *xc, uint32_t domid, switch (gp->type) { case EVTCHNSTAT_interdomain: /* Allow rebinding after migration, preserve port # if possible */ - be_port =3D gp->type_val & ~PORT_INFO_TYPEVAL_REMOTE_QEMU; + be_port =3D gp->u.interdomain.port; assert(be_port !=3D 0); if (!s->be_handles[be_port]) { s->be_handles[be_port] =3D xc; @@ -2085,7 +2073,8 @@ int xen_be_evtchn_bind_interdomain(struct xenevtchn_h= andle *xc, uint32_t domid, } =20 gp->type =3D EVTCHNSTAT_interdomain; - gp->type_val =3D be_port | PORT_INFO_TYPEVAL_REMOTE_QEMU; + gp->u.interdomain.to_qemu =3D 1; + gp->u.interdomain.port =3D be_port; xc->guest_port =3D guest_port; if (kvm_xen_has_cap(EVTCHN_SEND)) { assign_kernel_eventfd(gp->type, guest_port, xc->fd); @@ -2130,7 +2119,7 @@ int xen_be_evtchn_unbind(struct xenevtchn_handle *xc,= evtchn_port_t port) /* This should never *not* be true */ if (gp->type =3D=3D EVTCHNSTAT_interdomain) { gp->type =3D EVTCHNSTAT_unbound; - gp->type_val =3D PORT_INFO_TYPEVAL_REMOTE_QEMU; + gp->u.interdomain.port =3D 0; } =20 if (kvm_xen_has_cap(EVTCHN_SEND)) { @@ -2284,11 +2273,11 @@ EvtchnInfoList *qmp_xen_event_list(Error **errp) =20 info->type =3D p->type; if (p->type =3D=3D EVTCHNSTAT_interdomain) { - info->remote_domain =3D g_strdup((p->type_val & PORT_INFO_TYPE= VAL_REMOTE_QEMU) ? + info->remote_domain =3D g_strdup(p->u.interdomain.to_qemu ? "qemu" : "loopback"); - info->target =3D p->type_val & PORT_INFO_TYPEVAL_REMOTE_PORT_M= ASK; + info->target =3D p->u.interdomain.port; } else { - info->target =3D p->type_val; + info->target =3D p->u.val; /* pirq# or virq# */ } info->vcpu =3D p->vcpu; info->pending =3D test_bit(i, pending); --=20 2.40.1 From nobody Fri May 17 02:41:25 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=1698245514; cv=none; d=zohomail.com; s=zohoarc; b=XiyTbaKfAhQzPM1P7xzw1mTOoP1Xlcmomiz9urE3Ztr6VYjFY3khLdYixFf1bNe7vUM6d9mlHpp6XRvfplZffXnvI//cZJ0/TK/e5/GeHpMsRy9WQlJYnZ5BIIT1QWXLQECyvPRkU1nrTowQXTlG4YGCk1iL0woASBoR1GnMCTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245514; 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=XM4BCSzoEtJvXeS86uLw8msDFOfdY5zdHQ+73Ub6giM=; b=QXn5030lAaTVkaA+4xswAUsZKWiELg07GKaklOk7n+ywLkGWwbAkcjWWwXDBvHaHE0YE+rQ3iHBCsthom0kzEnY6SR14LWFqD989uVd9Q0Ej7SQFJzadtMm5J34uqhED5yjILt1P45+B0UJxpwrz0revktbpSumrua3cidTo45Q= 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 169824551458872.90540305106981; Wed, 25 Oct 2023 07:51:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622971.970361 (Exim 4.92) (envelope-from ) id 1qvfE0-0002sM-As; Wed, 25 Oct 2023 14:51:12 +0000 Received: by outflank-mailman (output) from mailman id 622971.970361; Wed, 25 Oct 2023 14:51:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDz-0002qu-VH; Wed, 25 Oct 2023 14:51:11 +0000 Received: by outflank-mailman (input) for mailman id 622971; Wed, 25 Oct 2023 14:51:10 +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 1qvfDx-0000WU-OK for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:10 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id eb7810b8-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:51:03 +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 1qvfDY-009Nmd-Pe; Wed, 25 Oct 2023 14:50:44 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEa-1N; Wed, 25 Oct 2023 15:50:44 +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: eb7810b8-7345-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=XM4BCSzoEtJvXeS86uLw8msDFOfdY5zdHQ+73Ub6giM=; b=hy5kRVYxeMBvoX1ry9nKgHB4qD FMJnXSDgPaFEOyH+2lVADZwX/2X2Ykn59fOmM1bhPyDnRc7Te9qwl7tOmOP87m322MP/PEcTEb66m SaIGpJFN8pFfIrmkjWgKUcgM3LH0QcdsqfMIWAD9ul5TJInSO+oz2u3azdEi3iyZBjpwHBXWU6Rrf Wup7tldtWGX/nbXhRUpUWJRurYhU8CkeyfCeJ/DO0Kdcq5pP3yr9imPscrg+j3Z9J4iJNGyi51dP9 MSGdUyLfwmFHjI9jRNf+hJi0pX4kszVgCBQVj6CEHzdDjnf12zueiTRFPyjdFrHRGbEZIB6jg+AfJ CQZTRwUw==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 10/28] include: update Xen public headers to Xen 4.17.2 release Date: Wed, 25 Oct 2023 15:50:24 +0100 Message-Id: <20231025145042.627381-11-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245515799100005 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 8e716a7009..831da535fc 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 Fri May 17 02:41:25 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 1698245561577272.45679440487515; Wed, 25 Oct 2023 07:52:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEM-0005Ro-Ml; Wed, 25 Oct 2023 10:51:34 -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 1qvfEE-0005HP-S2; Wed, 25 Oct 2023 10:51:27 -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 1qvfED-000765-3Z; Wed, 25 Oct 2023 10:51:26 -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 1qvfDZ-00GPLz-00; Wed, 25 Oct 2023 14:50:52 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEe-1i; Wed, 25 Oct 2023 15:50:44 +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=3ol/nIDXbsJDFoVLEuQ1afcMOMk6Tbtz3hrJIXJZBzY=; b=NFNK6k1K2fwKP7Ocg+F7iiwScE G0hoCGS6u4vyAMHIPvezrI8DEw/b9DGG3KWI2GSeG63nYSvAU5oVobvdrxD+wwKz+9P6PaJC/SaQ5 mYNdvDv+InJs82hkPJ+9clbUM9Ko2hDQb35OCg6149Mw9Ioar6ATzO6+CTanCbjudKYK+HHlwEkWv xfHpwHiIA9XDtWJ0deiMHNEUuu/CrzXdy1mN2k9BPitoNbt7OKPcvRhTo8Z0nj1vmvJKOa3nrKRfl r1CwhZVWJW77Cim7VL7UBUjXPm5P+XQVhgUAAWxEA3HOsImeW52PfGmuNr8sqrD9dtlAOcnf5zNjR S2yC23jw==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 11/28] i386/xen: advertise XEN_HVM_CPUID_UPCALL_VECTOR in CPUID Date: Wed, 25 Oct 2023 15:50:25 +0100 Message-Id: <20231025145042.627381-12-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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+fe87d11d956b9f6f1554+7367+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: 1698245562002100001 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 e7c054cc16..8f93a0b5fc 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1889,6 +1889,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 Fri May 17 02:41:25 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=1698245504; cv=none; d=zohomail.com; s=zohoarc; b=U8/0vAfI7xlf5q8YGzqr3s5k8hYU3aqa4FU+Tbc6WxQ/wf89Eh8zGY2ygSt2ZDmQoNrZMzZxCPnQf4jZ68uULK6cGPNihJxFv+eFRISl3xgBpZ/8AWYd4Y3T7PfdUFsscsMN38/huwQel5QT8BAHvzOAGz2VxV0xfK1FwWOLMAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245504; 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=xu550fyiR7pDFVRdWcAZ9rrT91tg3y6fvozQk3tPZhU=; b=JaA5gxGM3cl+I5421mVpFnsuxb0EhIVhP9joJ+sBOOGCWEF6q+lW4IFVvUo6jhYR/dc99TeOBGTgsnq0zvoyoIfDvGeBgkMcU3NYsAjK5d3CRa4z584YVWUqEtgvPoW9aV+R0FTle8xkuCsw+HinpRDn+4yzhQdJXUnqAJ6EU+w= 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 1698245504752432.5313875076906; Wed, 25 Oct 2023 07:51:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622969.970341 (Exim 4.92) (envelope-from ) id 1qvfDy-0002Di-0H; Wed, 25 Oct 2023 14:51:10 +0000 Received: by outflank-mailman (output) from mailman id 622969.970341; Wed, 25 Oct 2023 14:51:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDx-0002D1-L6; Wed, 25 Oct 2023 14:51:09 +0000 Received: by outflank-mailman (input) for mailman id 622969; Wed, 25 Oct 2023 14:51:07 +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 1qvfDv-0000WU-O9 for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:07 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e9ffea17-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:51:01 +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 1qvfDY-009Nmg-TY; Wed, 25 Oct 2023 14:50:44 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEi-1t; Wed, 25 Oct 2023 15:50:44 +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: e9ffea17-7345-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=xu550fyiR7pDFVRdWcAZ9rrT91tg3y6fvozQk3tPZhU=; b=mlDgNH9hrQ2uE5gT+pnk2qg3lB qeAUB1XoT8ifIgUe4nUkauPhzIfs5A/8pqA09jexOsMulJiWz9XN7NTmXUaR9/gw+nMrrUxGaEvVr nWJgwc3ezPFTIb1LX688b92xQo9Mpr7EuZaLB86JnW6S8QrDcc8NwM4hgFF3FDRmKFwAY6v2L4zwU LpkpNnHWNFm3CamvDfJd2lDno0Pftld+dLsqy7kvDtaZJDdUmVse2jRMi0cS7mcebsabEBeswREcE ECwqTqNsIX6MhHB97zfdvsPq3WQYEbPK8NKGlSxiFggsAZ1HCyKiLwm2UT5jZVxcfDIECKYndudBF K6XpcfzQ==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 12/28] hw/xen: populate store frontend nodes with XenStore PFN/port Date: Wed, 25 Oct 2023 15:50:26 +0100 Message-Id: <20231025145042.627381-13-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245505652100007 Content-Type: text/plain; charset="utf-8" From: David Woodhouse This is kind of redundant since without being able to get these through some other method (HVMOP_get_param) the guest wouldn't be able to access XenStore in order to find them. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/kvm/xen_xenstore.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index 831da535fc..b7c0407765 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -1434,6 +1434,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) { @@ -1461,6 +1462,16 @@ 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/port", "%u", s->guest_port); + relpath_printf(s, perms, "store/ring-ref", "%lu", + XEN_SPECIAL_PFN(XENSTORE)); + + 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 Fri May 17 02:41:25 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 1698245763832227.9375723086032; Wed, 25 Oct 2023 07:56:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEn-0006aS-3T; Wed, 25 Oct 2023 10:52:01 -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 1qvfE9-0005E8-5U; Wed, 25 Oct 2023 10:51:23 -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 1qvfDp-000761-EZ; Wed, 25 Oct 2023 10:51:20 -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 1qvfDZ-00GPM0-01; Wed, 25 Oct 2023 14:50:51 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEp-2E; Wed, 25 Oct 2023 15:50:44 +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=ga7fdRezSCKkw56oddJDf5PSF3aHuZeS/N2m1OsP10s=; b=SvFORSmuOPtT7hodiNrUuUpIdR BgL4DHHiwD4DSEr2bo1GfcbNMKWqCTbKDCxcB+fAJ2Nuahv3RPyr6ves2JjS3MFoVdr6cvCCifigm PUzvODEyKHKyOS88vKQvaQO+OvAjvM0MlsAgCZOqe9EM/Pi1/dHzCLDzTlBFHWBrOtKJFLUpYxWJ/ UL5Xqm1O82SdYKbfkDB8y5pOivPKsD7pEaWFNDeXZrKGki1cvU81VF+jpoMcWFrXaaQnNb2FrVDBx SaoTEwgshgIfj3kgQxKhtK5yVJIPjbcCGhyQdU5iuSQCW3SxtH4Meuj25JG4TFSzwoOgPA36ID0xG evBsdDAQ==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 13/28] hw/xen: automatically assign device index to block devices Date: Wed, 25 Oct 2023 15:50:27 +0100 Message-Id: <20231025145042.627381-14-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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+fe87d11d956b9f6f1554+7367+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: 1698245764794100003 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. Rip out the legacy handling from the xenpv machine, which was scribbling over any disks configured by the toolstack, and didn't work with anything but raw images. Signed-off-by: David Woodhouse Acked-by: Kevin Wolf --- blockdev.c | 15 +++++++++--- hw/block/xen-block.c | 38 +++++++++++++++++++++++++++++ hw/xen/xen_devconfig.c | 28 --------------------- hw/xenpv/xen_machine_pv.c | 9 ------- include/hw/xen/xen-legacy-backend.h | 1 - 5 files changed, 50 insertions(+), 41 deletions(-) diff --git a/blockdev.c b/blockdev.c index a01c62596b..5d9f2e5395 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 64470fc579..5011fe9430 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -27,6 +27,7 @@ #include "sysemu/block-backend.h" #include "sysemu/iothread.h" #include "dataplane/xen-block.h" +#include "hw/xen/interface/io/xs_wire.h" #include "trace.h" =20 static char *xen_block_get_name(XenDevice *xendev, Error **errp) @@ -34,6 +35,43 @@ 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) { + XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); + char fe_path[XENSTORE_ABS_PATH_MAX + 1]; + char *value; + 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(fe_path, sizeof(fe_path), + "/local/domain/%u/device/vbd/%lu", + xendev->frontend_id, idx); + value =3D qemu_xen_xs_read(xenbus->xsh, XBT_NULL, fe_path, NUL= L); + if (!value) { + if (errno =3D=3D ENOENT) { + vdev->type =3D XEN_BLOCK_VDEV_TYPE_XVD; + vdev->partition =3D 0; + vdev->disk =3D disk; + vdev->number =3D idx; + goto found; + } + error_setg(errp, "cannot read %s: %s", fe_path, + strerror(errno)); + return NULL; + } + free(value); + disk++; + } + error_setg(errp, "cannot find device vdev for block device"); + return NULL; + } + found: return g_strdup_printf("%lu", vdev->number); } =20 diff --git a/hw/xen/xen_devconfig.c b/hw/xen/xen_devconfig.c index 9b7304e544..3f77c675c6 100644 --- a/hw/xen/xen_devconfig.c +++ b/hw/xen/xen_devconfig.c @@ -46,34 +46,6 @@ static int xen_config_dev_all(char *fe, char *be) =20 /* ------------------------------------------------------------- */ =20 -int xen_config_dev_blk(DriveInfo *disk) -{ - char fe[256], be[256], device_name[32]; - int vdev =3D 202 * 256 + 16 * disk->unit; - int cdrom =3D disk->media_cd; - const char *devtype =3D cdrom ? "cdrom" : "disk"; - const char *mode =3D cdrom ? "r" : "w"; - const char *filename =3D qemu_opt_get(disk->opts, "file"); - - snprintf(device_name, sizeof(device_name), "xvd%c", 'a' + disk->unit); - xen_pv_printf(NULL, 1, "config disk %d [%s]: %s\n", - disk->unit, device_name, filename); - xen_config_dev_dirs("vbd", "qdisk", vdev, fe, be, sizeof(fe)); - - /* frontend */ - xenstore_write_int(fe, "virtual-device", vdev); - xenstore_write_str(fe, "device-type", devtype); - - /* backend */ - xenstore_write_str(be, "dev", device_name); - xenstore_write_str(be, "type", "file"); - xenstore_write_str(be, "params", filename); - xenstore_write_str(be, "mode", mode); - - /* common stuff */ - return xen_config_dev_all(fe, be); -} - int xen_config_dev_nic(NICInfo *nic) { char fe[256], be[256]; diff --git a/hw/xenpv/xen_machine_pv.c b/hw/xenpv/xen_machine_pv.c index 17cda5ec13..1533f5dfb4 100644 --- a/hw/xenpv/xen_machine_pv.c +++ b/hw/xenpv/xen_machine_pv.c @@ -32,7 +32,6 @@ =20 static void xen_init_pv(MachineState *machine) { - DriveInfo *dinfo; int i; =20 setup_xen_backend_ops(); @@ -64,14 +63,6 @@ static void xen_init_pv(MachineState *machine) vga_interface_created =3D true; } =20 - /* configure disks */ - for (i =3D 0; i < 16; i++) { - dinfo =3D drive_get(IF_XEN, 0, i); - if (!dinfo) - continue; - xen_config_dev_blk(dinfo); - } - /* configure nics */ for (i =3D 0; i < nb_nics; i++) { if (!nd_table[i].model || 0 !=3D strcmp(nd_table[i].model, "xen")) diff --git a/include/hw/xen/xen-legacy-backend.h b/include/hw/xen/xen-legac= y-backend.h index 6c307c5f2c..fc42146bc2 100644 --- a/include/hw/xen/xen-legacy-backend.h +++ b/include/hw/xen/xen-legacy-backend.h @@ -81,7 +81,6 @@ extern struct XenDevOps xen_usb_ops; /* xen-usb.= c */ =20 /* configuration (aka xenbus setup) */ void xen_config_cleanup(void); -int xen_config_dev_blk(DriveInfo *disk); int xen_config_dev_nic(NICInfo *nic); int xen_config_dev_vfb(int vdev, const char *type); int xen_config_dev_vkbd(int vdev); --=20 2.40.1 From nobody Fri May 17 02:41:25 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=1698245487; cv=none; d=zohomail.com; s=zohoarc; b=BArZ1VVOiIVUQR3dXUPhzlNUcumwk/v0M+TyVahfn0CR9MJB0t1m1VjAaQYFIznM8pQlC8KejV35Hs8jhBfF0y0ZSsuNhARFU2mm+Fm6FOBo16/YCrmSRy4c8wZFzZPFWjecypNCxCcN0Q4HwHJgn1BdwBDrdKEp6CrYpGAnXOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245487; 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=nSyX13U7fFimGQ53pLarBeZoTcJ83YAj4kMDKmZCroo=; b=cZDvCDlWTU2kXVNiZJw3vKzv0VX7ml7LM1Lgn3i5Aphc+zBLiU6oCMXWU448USOFF8HqjVcW8P71qOd4iDhdxqhVQI7I261i2BPQ4T8DlvJSJBTnXHhU46xAhoYYi8eEV1EF6s8IH5LmgaojpAHrQRBV+TmTCCFCbdHRiK59+IA= 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 169824548718346.863815272528655; Wed, 25 Oct 2023 07:51:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622964.970294 (Exim 4.92) (envelope-from ) id 1qvfDt-00016A-K8; Wed, 25 Oct 2023 14:51:05 +0000 Received: by outflank-mailman (output) from mailman id 622964.970294; Wed, 25 Oct 2023 14:51:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDt-00014y-GO; Wed, 25 Oct 2023 14:51:05 +0000 Received: by outflank-mailman (input) for mailman id 622964; Wed, 25 Oct 2023 14:51:03 +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 1qvfDr-0000WU-Nb for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:03 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e9124e69-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:50:59 +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 1qvfDZ-009Nmh-5W; Wed, 25 Oct 2023 14:50:45 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEt-2Q; Wed, 25 Oct 2023 15:50:44 +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: e9124e69-7345-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=nSyX13U7fFimGQ53pLarBeZoTcJ83YAj4kMDKmZCroo=; b=sU8+/FmzjvrZSwWTPPHaMd+E4T jDMl4D0TCrxob06SgGcF9MfamCPAfdobDvLhfXAHXXUJy1JIIsdGOJrwJ6KkWpcQebdQIvtIRk2ZW 5evtP1+2Epvifd5plVPrEYcgUl+KNVqqnhYU6uDiAUpJTuO7KsfGFs6aqQNY1cdQM+xLFt+LIbQqo ItGqyZWn2VySri4f6dwJx5KlmfhaNHIUoJ1T/LcFvLwtN5Cj7xsOSVFG88YEt4I8ecxy2Tt1K+BKx ieaE8fBANaoPEcW7oXj/KXgHK/MgdrubPp0V6+Dtsmwuo2ZyVcJnxQWh/MQR/uUI9ghpGaiQGy+rZ FmQ4QrgQ==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 14/28] hw/xen: add get_frontend_path() method to XenDeviceClass Date: Wed, 25 Oct 2023 15:50:28 +0100 Message-Id: <20231025145042.627381-15-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245487580100006 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 Reviewed-by: Paul Durrant --- hw/xen/xen-bus.c | 11 ++++++++++- include/hw/xen/xen-bus.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index ece8ec40cd..12ff782005 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -711,8 +711,17 @@ 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) { + error_prepend(errp, "failed to create frontend: "); + 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 Fri May 17 02:41:25 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 1698245619137998.9948183976177; Wed, 25 Oct 2023 07:53:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEh-0005xA-AH; Wed, 25 Oct 2023 10:51:56 -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 1qvfE8-0005E3-Qt; Wed, 25 Oct 2023 10:51:22 -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 1qvfDp-00075y-Dg; Wed, 25 Oct 2023 10:51:20 -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 1qvfDa-00GPM1-1E; Wed, 25 Oct 2023 14:50:49 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dEx-2l; Wed, 25 Oct 2023 15:50:44 +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=2Wb+EUrVg9AtuUMx5pX7frHLqezL77YzFvoQWCoX1cE=; b=X5kyQg9nKJws90Yor1VZwSvdxT PFKAQkc7Kohzt5hJ093royAty0XQ7GtQR2eyArbjCEgH/lSpS7K3m/kQzdxBrLnLGILBrrwcuQbqN wpwJzKmz9Gm48KyniSGRnFBEcFjK05k4jWMCldJC46gE2kCmoq8NWnkW/bEOdm+IGfWfqX9vTIA1N vvbECXvGoVTYr5+OaEobyKoBtiR42MYWitTRJdnYT8lNbwJy6yS//+v19ieOueAfH0hhuo95b1Yug IMOq5/mX/O2qKy+6qZiR+xU6rYgQrIODR7PNwSP8LDnLbeI9FF1eHGctFN0rhxxrzYsZEgdkVORbu /wz/+CXw==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 15/28] hw/xen: do not repeatedly try to create a failing backend device Date: Wed, 25 Oct 2023 15:50:29 +0100 Message-Id: <20231025145042.627381-16-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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+fe87d11d956b9f6f1554+7367+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: 1698245620125100001 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 12ff782005..3ffd1a5333 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 Fri May 17 02:41:25 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 1698245669667816.8800567946114; Wed, 25 Oct 2023 07:54:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEq-0006hG-M7; Wed, 25 Oct 2023 10:52:04 -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 1qvfEB-0005Ex-Dk; Wed, 25 Oct 2023 10:51: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 1qvfDp-000779-Ak; Wed, 25 Oct 2023 10:51:23 -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 1qvfDa-00GPM2-1E; Wed, 25 Oct 2023 14:50:52 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dF1-2x; Wed, 25 Oct 2023 15:50:44 +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=auoyj1xEgaC8bMi0O7YUpQ0rx3BFjT2lyRCJL3y5wnE=; b=f9MCdDvLs+qhwkY0BLNlfs14jT yrufAYA9JVI6q35igUctpZ6mzrMYX7I5p9/s6ghbctBLFRaMt/6qiW7JclxMDG8Q1UnjnvEaWzbAg YN4r3n/mx+izvC/7zFhlKoaYMdVN5utuEXqi09ru8grPMQrP1B5UsCNbiLaR/C6mBBGpd2rjMig2J H3xaLdbmoQUfqN4wMM9ZuzOJXVF358Nug7RCgfVzNBsGiH8aM9hCh3VKZ74Xbau3LKG4qSvXEdaFb L/Lu1nKwEOPY1Pt9RFQxjKQNPSCuly+xtT5J3Vq1Dyyr2b8emQVdjD2Lkx9zslYfVFoTFsX+hP+L7 6bV63/wA==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 16/28] hw/xen: update Xen console to XenDevice model Date: Wed, 25 Oct 2023 15:50:30 +0100 Message-Id: <20231025145042.627381-17-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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+fe87d11d956b9f6f1554+7367+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: 1698245670413100002 Content-Type: text/plain; charset="utf-8" From: David Woodhouse This allows (non-primary) console devices to be created on the command line and hotplugged. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/char/trace-events | 8 + hw/char/xen_console.c | 532 +++++++++++++++++++++++++++--------- hw/xen/xen-legacy-backend.c | 1 - 3 files changed, 411 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..4a419dc287 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -20,15 +20,20 @@ */ =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 "hw/xen/interface/io/xs_wire.h" +#include "trace.h" =20 struct buffer { uint8_t *data; @@ -39,16 +44,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 +71,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 +84,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 +100,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 +112,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 +130,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 +153,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 +171,436 @@ 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; + + if (xen_device_backend_get_state(&con->xendev) !=3D XenbusStateConnect= ed) { + return false; + } + + done_something =3D buffer_append(con); + + if (con->buffer.size - con->buffer.consumed) { + done_something |=3D xencons_send(con); + } + return done_something; +} + +/* -------------------------------------------------------------------- */ + +static bool xen_console_connect(XenDevice *xendev, Error **errp) +{ + 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 false; + } =20 - /* Only continue if we're talking to a pty. */ - if (!CHARDEV_IS_PTY(cs)) { - return 0; + if (xen_device_frontend_scanf(xendev, "port", "%u", &port) !=3D 1) { + error_setg(errp, "failed to read remote port"); + return false; } - pts =3D cs->filename + 4; =20 - dom_path =3D qemu_xen_xs_get_domain_path(xenstore, xen_domid); - if (!dom_path) { - return 0; + if (xen_device_frontend_scanf(xendev, "limit", "%u", &limit) =3D=3D 1)= { + con->buffer.max_capacity =3D limit; } =20 - path =3D g_string_new(dom_path); - free(dom_path); + con->event_channel =3D xen_device_bind_event_channel(xendev, port, + con_event, + con, + errp); + if (!con->event_channel) { + return false; + } =20 - if (con->xendev.dev) { - g_string_append_printf(path, "/device/console/%d", con->xendev.dev= ); + 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 false; + } } else { - g_string_append(path, "/console"); + 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 false; + } } - 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; + 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); + return true; +} + +static void xen_console_disconnect(XenDevice *xendev, Error **errp) +{ + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + + trace_xen_console_disconnect(con->dev); + + qemu_chr_fe_set_handlers(&con->chr, NULL, NULL, NULL, NULL, + con, NULL, true); + + if (con->event_channel) { + xen_device_unbind_event_channel(xendev, con->event_channel, + errp); + con->event_channel =3D NULL; + } + + if (con->sring) { + if (!con->dev) { + qemu_xen_foreignmem_unmap(con->sring, 1); + } else { + xen_device_unmap_grant_refs(xendev, con->sring, + &con->ring_ref, 1, errp); + } + con->sring =3D NULL; } - return 0; } =20 -static int con_init(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); - 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); + 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; + } + + xen_console_disconnect(xendev, errp); + if (*errp) { + break; + } + + if (!xen_console_connect(xendev, errp)) { + xen_device_backend_set_state(xendev, XenbusStateClosing); + 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; } - 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; +static char *xen_console_get_name(XenDevice *xendev, Error **errp) +{ + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + + if (con->dev =3D=3D -1) { + XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); + char fe_path[XENSTORE_ABS_PATH_MAX + 1]; + char *value; + int idx =3D 1; + + /* Theoretically we could go up to INT_MAX here but that's overkil= l */ + while (idx < 100) { + snprintf(fe_path, sizeof(fe_path), + "/local/domain/%u/device/console/%u", + xendev->frontend_id, idx); + value =3D qemu_xen_xs_read(xenbus->xsh, XBT_NULL, fe_path, NUL= L); + if (!value) { + if (errno =3D=3D ENOENT) { + con->dev =3D idx; + goto found; + } + error_setg(errp, "cannot read %s: %s", fe_path, + strerror(errno)); + return NULL; + } + free(value); + idx++; + } + error_setg(errp, "cannot find device index for console device"); + return NULL; } + found: + return g_strdup_printf("%u", con->dev); +} + +static void xen_console_unrealize(XenDevice *xendev) +{ + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); + + trace_xen_console_unrealize(con->dev); =20 - output =3D xenstore_read_str(con->console, "output"); + /* Disconnect from the frontend in case this has not already happened = */ + xen_console_disconnect(xendev, NULL); =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); + qemu_chr_fe_deinit(&con->chr, false); +} + +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; + } + + /* + * 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; } + } + + 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 { - 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); + return g_strdup_printf("/local/domain/%u/device/console/%u", dom_i= d, + dev); } +} =20 - store_con_info(con); +static char *xen_console_get_frontend_path(XenDevice *xendev, Error **errp) +{ + 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 -out: - g_free(type); + if (!ret) { + error_setg(errp, "failed to create frontend path"); + } return ret; } =20 -static int con_initialise(struct XenLegacyDevice *xendev) + +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) { - 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; + 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); +} =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); - } - if (!con->sring) - return -1; +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, +}; =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 void xen_console_register_types(void) +{ + type_register_static(&xen_console_type_info); } =20 -static void con_disconnect(struct XenLegacyDevice *xendev) +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) { - struct XenConsole *con =3D container_of(xendev, struct XenConsole, xen= dev); + ERRP_GUARD(); + XenBus *xenbus =3D xen_backend_get_bus(backend); + const char *name =3D xen_backend_get_name(backend); + unsigned long number; + char *fe =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) || number > INT_MAX) { + error_setg(errp, "failed to parse name '%s'", name); + goto fail; + } =20 - qemu_chr_fe_deinit(&con->chr, false); - xen_pv_unbind_evtchn(&con->xendev); + trace_xen_console_device_create(number); =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); + fe =3D console_frontend_path(xsh, xen_domid, number); + if (fe =3D=3D NULL) { + error_setg(errp, "failed to generate frontend path"); + goto fail; + } + + if (xs_node_scanf(xsh, XBT_NULL, fe, "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, "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; } - con->sring =3D NULL; + } 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)) { + xen_backend_set_device(backend, xendev); + goto done; + } + + error_prepend(errp, "realization of console device %lu failed: ", + number); + + fail: + if (xendev) { + object_unparent(OBJECT(xendev)); } + done: + g_free(fe); + free(type); + free(output); } =20 -static void con_event(struct XenLegacyDevice *xendev) +static void xen_console_device_destroy(XenBackendInstance *backend, + Error **errp) { - struct XenConsole *con =3D container_of(xendev, struct XenConsole, xen= dev); + ERRP_GUARD(); + XenDevice *xendev =3D xen_backend_get_device(backend); + XenConsole *con =3D XEN_CONSOLE_DEVICE(xendev); =20 - buffer_append(con); - if (con->buffer.size - con->buffer.consumed) - xencons_send(con); -} + trace_xen_console_device_destroy(con->dev); =20 -/* -------------------------------------------------------------------- */ + object_unparent(OBJECT(xendev)); +} =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 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 Fri May 17 02:41:25 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=1698245498; cv=none; d=zohomail.com; s=zohoarc; b=V/ahUgqe/5+m1gjQs517HQLepiFegMVZPjEVFGCgb4KYs46A9n1IsKrOjVhwTcmua7V9fMoo4YE5TosNkmmoilkcP//leJRUhA/xnLj4zUw2FwQomfBs2L1ksN7geWA8OBXfcW1PwrIYNMCDvla0gG/veP6mckJwQpM9IHifWpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245498; 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=XhsYSfIQYSBmCatJUPtQ3cCtM2z0F6a5Ae6S/654rl8=; b=Xi+qw7NR97z2k/VOEj6c39Kf99YB38mlFSrDfCxeXaMdYBLaRe0C8jL5cJmzydjINIuERbbAoy4a9ph1nKoPI2JwAZ3hRNi5RVPeLEKAciom6MfVEAZistJwWHZVRzG74lOFTDYce7guUjbxPOWAA//QIwfm7Pwh0cxDQpA+Wb4= 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 1698245498788407.2192114599677; Wed, 25 Oct 2023 07:51:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622968.970333 (Exim 4.92) (envelope-from ) id 1qvfDx-00026t-C8; Wed, 25 Oct 2023 14:51:09 +0000 Received: by outflank-mailman (output) from mailman id 622968.970333; Wed, 25 Oct 2023 14:51:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDx-00024C-6n; Wed, 25 Oct 2023 14:51:09 +0000 Received: by outflank-mailman (input) for mailman id 622968; Wed, 25 Oct 2023 14:51:06 +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 1qvfDu-0000WU-O4 for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:06 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e91671fe-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:50:59 +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 1qvfDZ-009Nmm-FK; Wed, 25 Oct 2023 14:50:45 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDY-002dF5-39; Wed, 25 Oct 2023 15:50:44 +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: e91671fe-7345-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=XhsYSfIQYSBmCatJUPtQ3cCtM2z0F6a5Ae6S/654rl8=; b=bebDdC3UkVjTaxQCkZRKhYfreU Pi4BJykRwkqs2h7q4xklzUF5qaigSUJXfV0Q0z6OPCrW9Om6Sw/kfpxb/HVz/f4tJt1duma6/0Oyk MdntSYjSMjWbHzix9vXpcAW5h+rsHAVjxO8L9mZmfp10stYQ7nLxhyZrJdyGBQgDEMGZiTxb1UMzm xSLiV52M6aauG6qMFnLHqIZeBlJYJYLEjl8q2Jf11w/fJzELUVvQXy8XXBolaxZOPs4d19+TYYMT3 j7txOIhizMddoSuBqwI4MgqN3IcWDmMEEt9gMQ9PyoPW3aV5m3EL89n4kUjoEr/7Ov6WM4oYMahVA nITjymYg==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 17/28] hw/xen: add support for Xen primary console in emulated mode Date: Wed, 25 Oct 2023 15:50:31 +0100 Message-Id: <20231025145042.627381-18-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245499770100001 From: David Woodhouse The primary console is special because the toolstack maps a page into the guest for its ring, and also allocates the guest-side event channel. The guest's grant table is even primed to export that page using a known grant ref#. Add support for all that in emulated mode, so that we can have a primary console. For reasons unclear, the backends running under real Xen don't just use a mapping of the well-known GNTTAB_RESERVED_CONSOLE grant ref (which would also be in the ring-ref node in XenStore). Instead, the toolstack sets the ring-ref node of the primary console to the GFN of the guest page. The backend is expected to handle that special case and map it with foreignmem operations instead. We don't have an implementation of foreignmem ops for emulated Xen mode, so just make it map GNTTAB_RESERVED_CONSOLE instead. This would probably work for real Xen too, but we can't work out how to make real Xen create a primary console of type "ioemu" to make QEMU drive it, so we can't test that; might as well leave it as it is for now under Xen. Now at last we can boot the Xen PV shim and run PV kernels in QEMU. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/char/xen_console.c | 78 ++++++++---- hw/i386/kvm/meson.build | 1 + hw/i386/kvm/trace-events | 2 + hw/i386/kvm/xen-stubs.c | 8 ++ hw/i386/kvm/xen_gnttab.c | 7 +- hw/i386/kvm/xen_primary_console.c | 193 ++++++++++++++++++++++++++++++ hw/i386/kvm/xen_primary_console.h | 23 ++++ hw/i386/kvm/xen_xenstore.c | 10 ++ hw/xen/xen-bus.c | 5 + include/hw/xen/xen-bus.h | 1 + target/i386/kvm/xen-emu.c | 23 +++- 11 files changed, 328 insertions(+), 23 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 4a419dc287..5cbee2f184 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -33,6 +33,8 @@ #include "hw/qdev-properties-system.h" #include "hw/xen/interface/io/console.h" #include "hw/xen/interface/io/xs_wire.h" +#include "hw/xen/interface/grant_table.h" +#include "hw/i386/kvm/xen_primary_console.h" #include "trace.h" =20 struct buffer { @@ -230,24 +232,47 @@ static bool xen_console_connect(XenDevice *xendev, Er= ror **errp) return false; } =20 - 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 false; + switch (con->dev) { + case 0: + /* + * The primary console is special. For real Xen the ring-ref is + * actually a GFN which needs to be mapped as foreignmem. + */ + if (xen_mode !=3D XEN_EMULATE) { + xen_pfn_t mfn =3D (xen_pfn_t)con->ring_ref; + con->sring =3D qemu_xen_foreignmem_map(xendev->frontend_id, NU= LL, + PROT_READ | PROT_WRITE, + 1, &mfn, NULL); + if (!con->sring) { + error_setg(errp, "failed to map console page"); + return false; + } + break; } - } else { + + /* + * For Xen emulation, we still follow the convention of ring-ref + * holding the GFN, but we map the fixed GNTTAB_RESERVED_CONSOLE + * grant ref because there is no implementation of foreignmem + * operations for emulated mode. The emulation code which handles + * the guest-side page and event channel also needs to be informed + * of the backend event channel port, in order to reconnect to it + * after a soft reset. + */ + xen_primary_console_set_be_port( + xen_event_channel_get_local_port(con->event_channel)); + con->ring_ref =3D GNTTAB_RESERVED_CONSOLE; + /* fallthrough */ + default: 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: "); + error_prepend(errp, "failed to map console grant ref: "); return false; } + break; } =20 trace_xen_console_connect(con->dev, con->ring_ref, port, @@ -272,10 +297,14 @@ static void xen_console_disconnect(XenDevice *xendev,= Error **errp) xen_device_unbind_event_channel(xendev, con->event_channel, errp); con->event_channel =3D NULL; + + if (xen_mode =3D=3D XEN_EMULATE && !con->dev) { + xen_primary_console_set_be_port(0); + } } =20 if (con->sring) { - if (!con->dev) { + if (!con->dev && xen_mode !=3D XEN_EMULATE) { qemu_xen_foreignmem_unmap(con->sring, 1); } else { xen_device_unmap_grant_refs(xendev, con->sring, @@ -338,14 +367,19 @@ static char *xen_console_get_name(XenDevice *xendev, = Error **errp) if (con->dev =3D=3D -1) { XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); char fe_path[XENSTORE_ABS_PATH_MAX + 1]; + int idx =3D (xen_mode =3D=3D XEN_EMULATE) ? 0 : 1; char *value; - int idx =3D 1; =20 /* Theoretically we could go up to INT_MAX here but that's overkil= l */ while (idx < 100) { - snprintf(fe_path, sizeof(fe_path), - "/local/domain/%u/device/console/%u", - xendev->frontend_id, idx); + if (!idx) { + snprintf(fe_path, sizeof(fe_path), + "/local/domain/%u/console", xendev->frontend_id); + } else { + snprintf(fe_path, sizeof(fe_path), + "/local/domain/%u/device/console/%u", + xendev->frontend_id, idx); + } value =3D qemu_xen_xs_read(xenbus->xsh, XBT_NULL, fe_path, NUL= L); if (!value) { if (errno =3D=3D ENOENT) { @@ -400,11 +434,15 @@ 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= || - xen_device_frontend_scanf(xendev, "port", "%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; } @@ -417,8 +455,8 @@ static void xen_console_realize(XenDevice *xendev, Erro= r **errp) xen_device_frontend_printf(xendev, "tty", "%s", cs->filename + 4); } =20 - /* No normal PV driver initialization for the primary console */ - if (!con->dev) { + /* No normal PV driver initialization for the primary console under Xe= n */ + 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..d03131e686 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,13 @@ bool xen_evtchn_deliver_pirq_msi(uint64_t address, uint3= 2_t data) return false; } =20 +void xen_primary_console_create(void) +{ +} + +void xen_primary_console_set_be_port(uint16_t port) +{ +} #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 839ec920a1..0a24f53f20 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" @@ -537,9 +538,13 @@ 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); + } + 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..abe79f565b --- /dev/null +++ b/hw/i386/kvm/xen_primary_console.c @@ -0,0 +1,193 @@ +/* + * 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; +} + +void xen_primary_console_set_be_port(uint16_t port) +{ + XenPrimaryConsoleState *s =3D xen_primary_console_singleton; + if (s) { + s->be_port =3D 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; + } +} + +static void rebind_guest_port(XenPrimaryConsoleState *s) +{ + struct evtchn_bind_interdomain inter =3D { + .remote_dom =3D DOMID_QEMU, + .remote_port =3D s->be_port, + }; + + if (!xen_evtchn_bind_interdomain_op(&inter)) { + s->guest_port =3D inter.local_port; + } + + s->be_port =3D 0; +} + +int xen_primary_console_reset(void) +{ + XenPrimaryConsoleState *s =3D xen_primary_console_singleton; + 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); + } + + if (s->be_port) { + rebind_guest_port(s); + } else { + 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..7e2989ea0d --- /dev/null +++ b/hw/i386/kvm/xen_primary_console.h @@ -0,0 +1,23 @@ +/* + * 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); +void xen_primary_console_set_be_port(uint16_t port); +uint64_t xen_primary_console_get_pfn(void); +void *xen_primary_console_get_map(void); + +#endif /* QEMU_XEN_PRIMARY_CONSOLE_H */ diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index b7c0407765..6e651960b3 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" @@ -1434,6 +1435,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 @@ -1470,6 +1472,14 @@ int xen_xenstore_reset(void) relpath_printf(s, perms, "store/ring-ref", "%lu", XEN_SPECIAL_PFN(XENSTORE)); =20 + console_port =3D xen_primary_console_get_port(); + if (console_port) { + relpath_printf(s, perms, "console/ring-ref", "%lu", + XEN_SPECIAL_PFN(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/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 3ffd1a5333..cc6f1b362f 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -922,6 +922,11 @@ void xen_device_notify_event_channel(XenDevice *xendev, } } =20 +unsigned int xen_event_channel_get_local_port(XenEventChannel *channel) +{ + return channel->local_port; +} + void xen_device_unbind_event_channel(XenDevice *xendev, XenEventChannel *channel, Error **errp) diff --git a/include/hw/xen/xen-bus.h b/include/hw/xen/xen-bus.h index eb440880b5..38d40afa37 100644 --- a/include/hw/xen/xen-bus.h +++ b/include/hw/xen/xen-bus.h @@ -131,5 +131,6 @@ void xen_device_notify_event_channel(XenDevice *xendev, void xen_device_unbind_event_channel(XenDevice *xendev, XenEventChannel *channel, Error **errp); +unsigned int xen_event_channel_get_local_port(XenEventChannel *channel); =20 #endif /* HW_XEN_BUS_H */ diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index 1dc9ab0d91..c0631f9cf4 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; @@ -812,11 +814,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: @@ -1427,6 +1441,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 From nobody Fri May 17 02:41:25 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=1698245520; cv=none; d=zohomail.com; s=zohoarc; b=A6VL/iQiqzUnFCm2mbojoFe2RQDafivLUzTAgSA43HbqFwbg0+mARCIxJm1N+dBxCCnZOTWNRlI0WmMUSp90+WCI1Z+biWKMdVKns7qh1I9KoNf/MIaQbwagfjmygQ/pTcnsuT77rA36L5KZoCkhgqhiqX7wU+WXEb4op2JIsgU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245520; 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=ASyx27ABg/WdxWXFMwdeXHtm2HUFOe8n8pbrbgV+R1U=; b=NU8/whw6/3dE256VOXtr+Vuim+pN8FYuxSuV1KvPgzlve5tPPozD9WR6l9j6RsnFPMITFLylMYec7Qslo7Ef2f/nzFgKJmcMs1UAqTTCkxGjJJeo1dEjbdu3kCDhLN9AY55zwSj0OjMW36C94eV178XjTzUYPAvSW2qYWOcozcc= 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 1698245520298935.5978891667256; Wed, 25 Oct 2023 07:52:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622976.970404 (Exim 4.92) (envelope-from ) id 1qvfE9-0004kk-Tz; Wed, 25 Oct 2023 14:51:21 +0000 Received: by outflank-mailman (output) from mailman id 622976.970404; Wed, 25 Oct 2023 14:51:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfE9-0004kL-Pf; Wed, 25 Oct 2023 14:51:21 +0000 Received: by outflank-mailman (input) for mailman id 622976; Wed, 25 Oct 2023 14:51:20 +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 1qvfE8-0008W8-BO for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:20 +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 f518d2eb-7345-11ee-98d5-6d05b1d4d9a1; Wed, 25 Oct 2023 16:51:19 +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 1qvfDa-00GPM3-1E; Wed, 25 Oct 2023 14:50:59 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFB-0E; Wed, 25 Oct 2023 15:50:45 +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: f518d2eb-7345-11ee-98d5-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=ASyx27ABg/WdxWXFMwdeXHtm2HUFOe8n8pbrbgV+R1U=; b=KSw3c28aYsIp9zBAi8cllWWDpi K8vfkVYz6/oGDNu+k4/VRrApYRSLjOfuKlvOwBUVg9jYOF+gWouYRyma5JLfDxUpY1onGCtNGKQpF zBsNj3EUDXg0QWtWYUPvY8uBRIl54dJgWQvWuC8EvuOKw6VRy1J5bsJjkNwyijb/fI6mRiUfwhjVr OvRtBYcurzH/qFdJ06Lnsu0ODcytGK3P/g3Yqk3V1hxBDbf4R/qHZHjO+ItsHl7JrxZ/wE1tPEl0Q SroVpabcjcZWsiltYy0DIQdggLoMb/3M7L35Jlh++igC9qdxOa4z4pbQiGOsgSw1X5wI0fL9zweFf 32KoOv9A==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 18/28] hw/xen: only remove peers of PCI NICs on unplug Date: Wed, 25 Oct 2023 15:50:32 +0100 Message-Id: <20231025145042.627381-19-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245521741100004 Content-Type: text/plain; charset="utf-8" From: David Woodhouse When the Xen guest asks to unplug *emulated* NICs, it's kind of unhelpful also to unplug the peer of the *Xen* PV NIC. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/xen/xen_platform.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c index 17457ff3de..e2dd1b536a 100644 --- a/hw/i386/xen/xen_platform.c +++ b/hw/i386/xen/xen_platform.c @@ -140,9 +140,14 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *= o) /* Remove the peer of the NIC device. Normally, this would be a tap device= . */ static void del_nic_peer(NICState *nic, void *opaque) { - NetClientState *nc; + NetClientState *nc =3D qemu_get_queue(nic); + ObjectClass *klass =3D module_object_class_by_name(nc->model); + + /* Only delete peers of PCI NICs that we're about to delete */ + if (!klass || !object_class_dynamic_cast(klass, TYPE_PCI_DEVICE)) { + return; + } =20 - nc =3D qemu_get_queue(nic); if (nc->peer) qemu_del_net_client(nc->peer); } --=20 2.40.1 From nobody Fri May 17 02:41:25 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 1698245792311703.0548812608503; Wed, 25 Oct 2023 07:56:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEo-0006dr-0v; Wed, 25 Oct 2023 10:52:02 -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 1qvfEI-0005Mf-8d; Wed, 25 Oct 2023 10:51:31 -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 1qvfED-00078K-9B; Wed, 25 Oct 2023 10:51:29 -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 1qvfDa-00GPM4-1E; Wed, 25 Oct 2023 14:51:03 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFH-0X; Wed, 25 Oct 2023 15:50:45 +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=xvXxjykqZF+Agx7uTMlZcC/34TNa2PWC4UD2zd+uAJ8=; b=dKyMuFtfjDgAQMAjMUWXxC9cZy 2Vf9f54OurIaXywZd2FdL5e/LAfxbA3cU7NIWh2VNQc/v84Kkp1otj+jTJJx6xQetIf+yHemTMZlp f/4zDWwPwMd9/71G0Ni1812r5DhrM/2MvjxrEd8uxsiC4k0rWg9fH27o6A5zQ2TVM0rpLAfDWp4Im 1ZzpmIvysESQNfoFQ2V8ZtE3p7JXg3M1onfp1b7YdGc4AodgrUUpcupetvaSzT0iVHLjoIAl9+DGu hk8aU4zN6bkdSzII0iFWakeu0sQTzkWQwOEB+N0SHJWh5iHg9yxW1UUK7xrTHZmhojzjOgkZ7Xp0R lAp+3s2A==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 19/28] hw/xen: update Xen PV NIC to XenDevice model Date: Wed, 25 Oct 2023 15:50:33 +0100 Message-Id: <20231025145042.627381-20-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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+fe87d11d956b9f6f1554+7367+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: 1698245792970100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse This allows us to use Xen PV networking with emulated Xen guests, and to add them on the command line or hotplug. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/net/meson.build | 2 +- hw/net/trace-events | 11 + hw/net/xen_nic.c | 484 +++++++++++++++++++++++++++++--------- hw/xenpv/xen_machine_pv.c | 1 - 4 files changed, 381 insertions(+), 117 deletions(-) diff --git a/hw/net/meson.build b/hw/net/meson.build index 2632634df3..f64651c467 100644 --- a/hw/net/meson.build +++ b/hw/net/meson.build @@ -1,5 +1,5 @@ system_ss.add(when: 'CONFIG_DP8393X', if_true: files('dp8393x.c')) -system_ss.add(when: 'CONFIG_XEN', if_true: files('xen_nic.c')) +system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen_nic.c')) system_ss.add(when: 'CONFIG_NE2000_COMMON', if_true: files('ne2000.c')) =20 # PCI network cards diff --git a/hw/net/trace-events b/hw/net/trace-events index 3abfd65e5b..3097742cc0 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -482,3 +482,14 @@ dp8393x_receive_oversize(int size) "oversize packet, p= kt_size is %d" dp8393x_receive_not_netcard(void) "packet not for netcard" dp8393x_receive_packet(int crba) "Receive packet at 0x%"PRIx32 dp8393x_receive_write_status(int crba) "Write status at 0x%"PRIx32 + +# xen_nic.c +xen_netdev_realize(int dev, const char *info, const char *peer) "vif%u inf= o '%s' peer '%s'" +xen_netdev_unrealize(int dev) "vif%u" +xen_netdev_create(int dev) "vif%u" +xen_netdev_destroy(int dev) "vif%u" +xen_netdev_disconnect(int dev) "vif%u" +xen_netdev_connect(int dev, unsigned int tx, unsigned int rx, int port) "v= if%u tx %u rx %u port %u" +xen_netdev_frontend_changed(const char *dev, int state) "vif%s state %d" +xen_netdev_tx(int dev, int ref, int off, int len, unsigned int flags, cons= t char *c, const char *d, const char *m, const char *e) "vif%u ref %u off %= u len %u flags 0x%x%s%s%s%s" +xen_netdev_rx(int dev, int idx, int status, int flags) "vif%u idx %d statu= s %d flags 0x%x" diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 9bbf6599fc..af4ba3f1e6 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -20,6 +20,13 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "qemu/cutils.h" +#include "qemu/log.h" +#include "qemu/qemu-print.h" +#include "qapi/qmp/qdict.h" +#include "qapi/error.h" + #include #include #include @@ -27,18 +34,26 @@ #include "net/net.h" #include "net/checksum.h" #include "net/util.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" =20 #include "hw/xen/interface/io/netif.h" +#include "hw/xen/interface/io/xs_wire.h" + +#include "trace.h" =20 /* ------------------------------------------------------------- */ =20 struct XenNetDev { - struct XenLegacyDevice xendev; /* must be first */ - char *mac; + struct XenDevice xendev; /* must be first */ + XenEventChannel *event_channel; + int dev; int tx_work; - int tx_ring_ref; - int rx_ring_ref; + unsigned int tx_ring_ref; + unsigned int rx_ring_ref; struct netif_tx_sring *txs; struct netif_rx_sring *rxs; netif_tx_back_ring_t tx_ring; @@ -47,6 +62,11 @@ struct XenNetDev { NICState *nic; }; =20 +typedef struct XenNetDev XenNetDev; + +#define TYPE_XEN_NET_DEVICE "xen-net-device" +OBJECT_DECLARE_SIMPLE_TYPE(XenNetDev, XEN_NET_DEVICE) + /* ------------------------------------------------------------- */ =20 static void net_tx_response(struct XenNetDev *netdev, netif_tx_request_t *= txp, int8_t st) @@ -68,7 +88,8 @@ static void net_tx_response(struct XenNetDev *netdev, net= if_tx_request_t *txp, i netdev->tx_ring.rsp_prod_pvt =3D ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->tx_ring, notify); if (notify) { - xen_pv_send_notify(&netdev->xendev); + xen_device_notify_event_channel(XEN_DEVICE(netdev), + netdev->event_channel, NULL); } =20 if (i =3D=3D netdev->tx_ring.req_cons) { @@ -104,13 +125,16 @@ static void net_tx_error(struct XenNetDev *netdev, ne= tif_tx_request_t *txp, RING #endif } =20 -static void net_tx_packets(struct XenNetDev *netdev) +static bool net_tx_packets(struct XenNetDev *netdev) { + bool done_something =3D false; netif_tx_request_t txreq; RING_IDX rc, rp; void *page; void *tmpbuf =3D NULL; =20 + assert(qemu_mutex_iothread_locked()); + for (;;) { rc =3D netdev->tx_ring.req_cons; rp =3D netdev->tx_ring.sring->req_prod; @@ -122,49 +146,52 @@ static void net_tx_packets(struct XenNetDev *netdev) } memcpy(&txreq, RING_GET_REQUEST(&netdev->tx_ring, rc), sizeof(= txreq)); netdev->tx_ring.req_cons =3D ++rc; + done_something =3D true; =20 #if 1 /* should not happen in theory, we don't announce the * * feature-{sg,gso,whatelse} flags in xenstore (yet?) */ if (txreq.flags & NETTXF_extra_info) { - xen_pv_printf(&netdev->xendev, 0, "FIXME: extra info flag\= n"); + qemu_log_mask(LOG_UNIMP, "vif%u: FIXME: extra info flag\n", + netdev->dev); net_tx_error(netdev, &txreq, rc); continue; } if (txreq.flags & NETTXF_more_data) { - xen_pv_printf(&netdev->xendev, 0, "FIXME: more data flag\n= "); + qemu_log_mask(LOG_UNIMP, "vif%u: FIXME: more data flag\n", + netdev->dev); net_tx_error(netdev, &txreq, rc); continue; } #endif =20 if (txreq.size < 14) { - xen_pv_printf(&netdev->xendev, 0, "bad packet size: %d\n", - txreq.size); + qemu_log_mask(LOG_GUEST_ERROR, "vif%u: bad packet size: %d= \n", + netdev->dev, txreq.size); net_tx_error(netdev, &txreq, rc); continue; } =20 if ((txreq.offset + txreq.size) > XEN_PAGE_SIZE) { - xen_pv_printf(&netdev->xendev, 0, "error: page crossing\n"= ); + qemu_log_mask(LOG_GUEST_ERROR, "vif%u: error: page crossin= g\n", + netdev->dev); net_tx_error(netdev, &txreq, rc); continue; } =20 - xen_pv_printf(&netdev->xendev, 3, - "tx packet ref %d, off %d, len %d, flags 0x%x%s%= s%s%s\n", - txreq.gref, txreq.offset, txreq.size, txreq.flag= s, - (txreq.flags & NETTXF_csum_blank) ? " csum_b= lank" : "", - (txreq.flags & NETTXF_data_validated) ? " data_v= alidated" : "", - (txreq.flags & NETTXF_more_data) ? " more_d= ata" : "", - (txreq.flags & NETTXF_extra_info) ? " extra_= info" : ""); + trace_xen_netdev_tx(netdev->dev, txreq.gref, txreq.offset, + txreq.size, txreq.flags, + (txreq.flags & NETTXF_csum_blank) ? " = csum_blank" : "", + (txreq.flags & NETTXF_data_validated) ? " = data_validated" : "", + (txreq.flags & NETTXF_more_data) ? " = more_data" : "", + (txreq.flags & NETTXF_extra_info) ? " = extra_info" : ""); =20 - page =3D xen_be_map_grant_ref(&netdev->xendev, txreq.gref, - PROT_READ); + page =3D xen_device_map_grant_refs(&netdev->xendev, &txreq.gre= f, 1, + PROT_READ, NULL); if (page =3D=3D NULL) { - xen_pv_printf(&netdev->xendev, 0, - "error: tx gref dereference failed (%d)\n", - txreq.gref); + qemu_log_mask(LOG_GUEST_ERROR, + "vif%u: tx gref dereference failed (%d)\n", + netdev->dev, txreq.gref); net_tx_error(netdev, &txreq, rc); continue; } @@ -181,7 +208,8 @@ static void net_tx_packets(struct XenNetDev *netdev) qemu_send_packet(qemu_get_queue(netdev->nic), page + txreq.offset, txreq.size); } - xen_be_unmap_grant_ref(&netdev->xendev, page, txreq.gref); + xen_device_unmap_grant_refs(&netdev->xendev, page, &txreq.gref= , 1, + NULL); net_tx_response(netdev, &txreq, NETIF_RSP_OKAY); } if (!netdev->tx_work) { @@ -190,6 +218,7 @@ static void net_tx_packets(struct XenNetDev *netdev) netdev->tx_work =3D 0; } g_free(tmpbuf); + return done_something; } =20 /* ------------------------------------------------------------- */ @@ -212,14 +241,13 @@ static void net_rx_response(struct XenNetDev *netdev, resp->status =3D (int16_t)st; } =20 - xen_pv_printf(&netdev->xendev, 3, - "rx response: idx %d, status %d, flags 0x%x\n", - i, resp->status, resp->flags); + trace_xen_netdev_rx(netdev->dev, i, resp->status, resp->flags); =20 netdev->rx_ring.rsp_prod_pvt =3D ++i; RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netdev->rx_ring, notify); if (notify) { - xen_pv_send_notify(&netdev->xendev); + xen_device_notify_event_channel(XEN_DEVICE(netdev), + netdev->event_channel, NULL); } } =20 @@ -232,7 +260,9 @@ static ssize_t net_rx_packet(NetClientState *nc, const = uint8_t *buf, size_t size RING_IDX rc, rp; void *page; =20 - if (netdev->xendev.be_state !=3D XenbusStateConnected) { + assert(qemu_mutex_iothread_locked()); + + if (xen_device_backend_get_state(&netdev->xendev) !=3D XenbusStateConn= ected) { return -1; } =20 @@ -244,24 +274,26 @@ static ssize_t net_rx_packet(NetClientState *nc, cons= t uint8_t *buf, size_t size return 0; } if (size > XEN_PAGE_SIZE - NET_IP_ALIGN) { - xen_pv_printf(&netdev->xendev, 0, "packet too big (%lu > %ld)", - (unsigned long)size, XEN_PAGE_SIZE - NET_IP_ALIGN); + qemu_log_mask(LOG_GUEST_ERROR, "vif%u: packet too big (%lu > %ld)", + netdev->dev, (unsigned long)size, + XEN_PAGE_SIZE - NET_IP_ALIGN); return -1; } =20 memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq)); netdev->rx_ring.req_cons =3D ++rc; =20 - page =3D xen_be_map_grant_ref(&netdev->xendev, rxreq.gref, PROT_WRITE); + page =3D xen_device_map_grant_refs(&netdev->xendev, &rxreq.gref, 1, + PROT_WRITE, NULL); if (page =3D=3D NULL) { - xen_pv_printf(&netdev->xendev, 0, - "error: rx gref dereference failed (%d)\n", - rxreq.gref); + qemu_log_mask(LOG_GUEST_ERROR, + "vif%u: rx gref dereference failed (%d)\n", + netdev->dev, rxreq.gref); net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0); return -1; } memcpy(page + NET_IP_ALIGN, buf, size); - xen_be_unmap_grant_ref(&netdev->xendev, page, rxreq.gref); + xen_device_unmap_grant_refs(&netdev->xendev, page, &rxreq.gref, 1, NUL= L); net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0); =20 return size; @@ -275,139 +307,361 @@ static NetClientInfo net_xen_info =3D { .receive =3D net_rx_packet, }; =20 -static int net_init(struct XenLegacyDevice *xendev) +static void xen_netdev_realize(XenDevice *xendev, Error **errp) { - struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); + ERRP_GUARD(); + XenNetDev *netdev =3D XEN_NET_DEVICE(xendev); + NetClientState *nc; =20 - /* read xenstore entries */ - if (netdev->mac =3D=3D NULL) { - netdev->mac =3D xenstore_read_be_str(&netdev->xendev, "mac"); - } - - /* do we have all we need? */ - if (netdev->mac =3D=3D NULL) { - return -1; - } + qemu_macaddr_default_if_unset(&netdev->conf.macaddr); =20 - if (net_parse_macaddr(netdev->conf.macaddr.a, netdev->mac) < 0) { - return -1; - } + xen_device_frontend_printf(xendev, "mac", "%02x:%02x:%02x:%02x:%02x:%0= 2x", + netdev->conf.macaddr.a[0], + netdev->conf.macaddr.a[1], + netdev->conf.macaddr.a[2], + netdev->conf.macaddr.a[3], + netdev->conf.macaddr.a[4], + netdev->conf.macaddr.a[5]); =20 netdev->nic =3D qemu_new_nic(&net_xen_info, &netdev->conf, - "xen", NULL, netdev); + object_get_typename(OBJECT(xendev)), + DEVICE(xendev)->id, netdev); =20 - qemu_set_info_str(qemu_get_queue(netdev->nic), - "nic: xenbus vif macaddr=3D%s", netdev->mac); + nc =3D qemu_get_queue(netdev->nic); + qemu_format_nic_info_str(nc, netdev->conf.macaddr.a); =20 /* fill info */ - xenstore_write_be_int(&netdev->xendev, "feature-rx-copy", 1); - xenstore_write_be_int(&netdev->xendev, "feature-rx-flip", 0); + xen_device_backend_printf(xendev, "feature-rx-copy", "%u", 1); + xen_device_backend_printf(xendev, "feature-rx-flip", "%u", 0); =20 - return 0; + trace_xen_netdev_realize(netdev->dev, nc->info_str, nc->peer ? + nc->peer->name : "(none)"); } =20 -static int net_connect(struct XenLegacyDevice *xendev) +static bool net_event(void *_xendev) { - struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); - int rx_copy; + XenNetDev *netdev =3D XEN_NET_DEVICE(_xendev); + bool done_something; =20 - if (xenstore_read_fe_int(&netdev->xendev, "tx-ring-ref", - &netdev->tx_ring_ref) =3D=3D -1) { - return -1; + done_something =3D net_tx_packets(netdev); + qemu_flush_queued_packets(qemu_get_queue(netdev->nic)); + return done_something; +} + +static bool xen_netdev_connect(XenDevice *xendev, Error **errp) +{ + XenNetDev *netdev =3D XEN_NET_DEVICE(xendev); + unsigned int port, rx_copy; + + assert(qemu_mutex_iothread_locked()); + + if (xen_device_frontend_scanf(xendev, "tx-ring-ref", "%u", + &netdev->tx_ring_ref) !=3D 1) { + error_setg(errp, "failed to read tx-ring-ref"); + return false; } - if (xenstore_read_fe_int(&netdev->xendev, "rx-ring-ref", - &netdev->rx_ring_ref) =3D=3D -1) { - return 1; + + if (xen_device_frontend_scanf(xendev, "rx-ring-ref", "%u", + &netdev->rx_ring_ref) !=3D 1) { + error_setg(errp, "failed to read rx-ring-ref"); + return false; } - if (xenstore_read_fe_int(&netdev->xendev, "event-channel", - &netdev->xendev.remote_port) =3D=3D -1) { - return -1; + + if (xen_device_frontend_scanf(xendev, "event-channel", "%u", + &port) !=3D 1) { + error_setg(errp, "failed to read event-channel"); + return false; } =20 - if (xenstore_read_fe_int(&netdev->xendev, "request-rx-copy", &rx_copy)= =3D=3D -1) { + if (xen_device_frontend_scanf(xendev, "request-rx-copy", "%u", + &rx_copy) !=3D 1) { rx_copy =3D 0; } if (rx_copy =3D=3D 0) { - xen_pv_printf(&netdev->xendev, 0, - "frontend doesn't support rx-copy.\n"); - return -1; + error_setg(errp, "frontend doesn't support rx-copy"); + return false; } =20 - netdev->txs =3D xen_be_map_grant_ref(&netdev->xendev, - netdev->tx_ring_ref, - PROT_READ | PROT_WRITE); + netdev->txs =3D xen_device_map_grant_refs(xendev, + &netdev->tx_ring_ref, 1, + PROT_READ | PROT_WRITE, + errp); if (!netdev->txs) { - return -1; + error_prepend(errp, "failed to map tx grant ref: "); + return false; } - netdev->rxs =3D xen_be_map_grant_ref(&netdev->xendev, - netdev->rx_ring_ref, - PROT_READ | PROT_WRITE); + + netdev->rxs =3D xen_device_map_grant_refs(xendev, + &netdev->rx_ring_ref, 1, + PROT_READ | PROT_WRITE, + errp); if (!netdev->rxs) { - xen_be_unmap_grant_ref(&netdev->xendev, netdev->txs, - netdev->tx_ring_ref); - netdev->txs =3D NULL; - return -1; + error_prepend(errp, "failed to map rx grant ref: "); + return false; } + BACK_RING_INIT(&netdev->tx_ring, netdev->txs, XEN_PAGE_SIZE); BACK_RING_INIT(&netdev->rx_ring, netdev->rxs, XEN_PAGE_SIZE); =20 - xen_be_bind_evtchn(&netdev->xendev); + netdev->event_channel =3D xen_device_bind_event_channel(xendev, port, + net_event, + netdev, + errp); + if (!netdev->event_channel) { + return false; + } =20 - xen_pv_printf(&netdev->xendev, 1, "ok: tx-ring-ref %d, rx-ring-ref %d,= " - "remote port %d, local port %d\n", - netdev->tx_ring_ref, netdev->rx_ring_ref, - netdev->xendev.remote_port, netdev->xendev.local_port); + trace_xen_netdev_connect(netdev->dev, netdev->tx_ring_ref, + netdev->rx_ring_ref, port); =20 net_tx_packets(netdev); - return 0; + return true; } =20 -static void net_disconnect(struct XenLegacyDevice *xendev) +static void xen_netdev_disconnect(XenDevice *xendev, Error **errp) { - struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); + XenNetDev *netdev =3D XEN_NET_DEVICE(xendev); + + trace_xen_netdev_disconnect(netdev->dev); + + assert(qemu_mutex_iothread_locked()); =20 - xen_pv_unbind_evtchn(&netdev->xendev); + netdev->tx_ring.sring =3D NULL; + netdev->rx_ring.sring =3D NULL; =20 + if (netdev->event_channel) { + xen_device_unbind_event_channel(xendev, netdev->event_channel, + errp); + netdev->event_channel =3D NULL; + } if (netdev->txs) { - xen_be_unmap_grant_ref(&netdev->xendev, netdev->txs, - netdev->tx_ring_ref); + xen_device_unmap_grant_refs(xendev, netdev->txs, + &netdev->tx_ring_ref, 1, errp); netdev->txs =3D NULL; } if (netdev->rxs) { - xen_be_unmap_grant_ref(&netdev->xendev, netdev->rxs, - netdev->rx_ring_ref); + xen_device_unmap_grant_refs(xendev, netdev->rxs, + &netdev->rx_ring_ref, 1, errp); netdev->rxs =3D NULL; } } =20 -static void net_event(struct XenLegacyDevice *xendev) +/* -------------------------------------------------------------------- */ + + +static void xen_netdev_frontend_changed(XenDevice *xendev, + enum xenbus_state frontend_state, + Error **errp) { - struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); - net_tx_packets(netdev); - qemu_flush_queued_packets(qemu_get_queue(netdev->nic)); + ERRP_GUARD(); + enum xenbus_state backend_state =3D xen_device_backend_get_state(xende= v); + + trace_xen_netdev_frontend_changed(xendev->name, frontend_state); + + switch (frontend_state) { + case XenbusStateConnected: + if (backend_state =3D=3D XenbusStateConnected) { + break; + } + + xen_netdev_disconnect(xendev, errp); + if (*errp) { + break; + } + + if (!xen_netdev_connect(xendev, errp)) { + xen_netdev_disconnect(xendev, NULL); + xen_device_backend_set_state(xendev, XenbusStateClosing); + break; + } + + xen_device_backend_set_state(xendev, XenbusStateConnected); + break; + + case XenbusStateClosing: + xen_device_backend_set_state(xendev, XenbusStateClosing); + break; + + case XenbusStateClosed: + case XenbusStateUnknown: + xen_netdev_disconnect(xendev, errp); + if (*errp) { + break; + } + + xen_device_backend_set_state(xendev, XenbusStateClosed); + break; + + case XenbusStateInitialised: + /* + * Linux netback does nothing on the frontend going (back) to + * XenbusStateInitialised, so do the same here. + */ + default: + break; + } } =20 -static int net_free(struct XenLegacyDevice *xendev) +static char *xen_netdev_get_name(XenDevice *xendev, Error **errp) { - struct XenNetDev *netdev =3D container_of(xendev, struct XenNetDev, xe= ndev); + XenNetDev *netdev =3D XEN_NET_DEVICE(xendev); + + if (netdev->dev =3D=3D -1) { + XenBus *xenbus =3D XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); + char fe_path[XENSTORE_ABS_PATH_MAX + 1]; + int idx =3D (xen_mode =3D=3D XEN_EMULATE) ? 0 : 1; + char *value; + + /* Theoretically we could go up to INT_MAX here but that's overkil= l */ + while (idx < 100) { + snprintf(fe_path, sizeof(fe_path), + "/local/domain/%u/device/vif/%u", + xendev->frontend_id, idx); + value =3D qemu_xen_xs_read(xenbus->xsh, XBT_NULL, fe_path, NUL= L); + if (!value) { + if (errno =3D=3D ENOENT) { + netdev->dev =3D idx; + goto found; + } + error_setg(errp, "cannot read %s: %s", fe_path, + strerror(errno)); + return NULL; + } + free(value); + idx++; + } + error_setg(errp, "cannot find device index for netdev device"); + return NULL; + } + found: + return g_strdup_printf("%u", netdev->dev); +} + +static void xen_netdev_unrealize(XenDevice *xendev) +{ + XenNetDev *netdev =3D XEN_NET_DEVICE(xendev); + + trace_xen_netdev_unrealize(netdev->dev); + + /* Disconnect from the frontend in case this has not already happened = */ + xen_netdev_disconnect(xendev, NULL); =20 if (netdev->nic) { qemu_del_nic(netdev->nic); - netdev->nic =3D NULL; } - g_free(netdev->mac); - netdev->mac =3D NULL; - return 0; } =20 /* ------------------------------------------------------------- */ =20 -struct XenDevOps xen_netdev_ops =3D { - .size =3D sizeof(struct XenNetDev), - .flags =3D DEVOPS_FLAG_NEED_GNTDEV, - .init =3D net_init, - .initialise =3D net_connect, - .event =3D net_event, - .disconnect =3D net_disconnect, - .free =3D net_free, +static Property xen_netdev_properties[] =3D { + DEFINE_NIC_PROPERTIES(XenNetDev, conf), + DEFINE_PROP_INT32("idx", XenNetDev, dev, -1), + DEFINE_PROP_END_OF_LIST(), +}; + +static void xen_netdev_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 "qnic"; + xendev_class->device =3D "vif"; + xendev_class->get_name =3D xen_netdev_get_name; + xendev_class->realize =3D xen_netdev_realize; + xendev_class->frontend_changed =3D xen_netdev_frontend_changed; + xendev_class->unrealize =3D xen_netdev_unrealize; + set_bit(DEVICE_CATEGORY_NETWORK, dev_class->categories); + dev_class->user_creatable =3D true; + + device_class_set_props(dev_class, xen_netdev_properties); +} + +static const TypeInfo xen_net_type_info =3D { + .name =3D TYPE_XEN_NET_DEVICE, + .parent =3D TYPE_XEN_DEVICE, + .instance_size =3D sizeof(XenNetDev), + .class_init =3D xen_netdev_class_init, +}; + +static void xen_net_register_types(void) +{ + type_register_static(&xen_net_type_info); +} + +type_init(xen_net_register_types) + +/* Called to instantiate a XenNetDev when the backend is detected. */ +static void xen_net_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); + XenDevice *xendev =3D NULL; + unsigned long number; + const char *macstr; + XenNetDev *net; + MACAddr mac; + + if (qemu_strtoul(name, NULL, 10, &number) || number >=3D INT_MAX) { + error_setg(errp, "failed to parse name '%s'", name); + goto fail; + } + + trace_xen_netdev_create(number); + + macstr =3D qdict_get_try_str(opts, "mac"); + if (macstr =3D=3D NULL) { + error_setg(errp, "no MAC address found"); + goto fail; + } + + if (net_parse_macaddr(mac.a, macstr) < 0) { + error_setg(errp, "failed to parse MAC address"); + goto fail; + } + + xendev =3D XEN_DEVICE(qdev_new(TYPE_XEN_NET_DEVICE)); + net =3D XEN_NET_DEVICE(xendev); + + net->dev =3D number; + memcpy(&net->conf.macaddr, &mac, sizeof(mac)); + + if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) { + xen_backend_set_device(backend, xendev); + return; + } + + error_prepend(errp, "realization of net device %lu failed: ", + number); + + fail: + if (xendev) { + object_unparent(OBJECT(xendev)); + } +} + +static void xen_net_device_destroy(XenBackendInstance *backend, + Error **errp) +{ + ERRP_GUARD(); + XenDevice *xendev =3D xen_backend_get_device(backend); + XenNetDev *netdev =3D XEN_NET_DEVICE(xendev); + + trace_xen_netdev_destroy(netdev->dev); + + object_unparent(OBJECT(xendev)); +} + +static const XenBackendInfo xen_net_backend_info =3D { + .type =3D "qnic", + .create =3D xen_net_device_create, + .destroy =3D xen_net_device_destroy, }; + +static void xen_net_register_backend(void) +{ + xen_backend_register(&xen_net_backend_info); +} + +xen_backend_init(xen_net_register_backend); diff --git a/hw/xenpv/xen_machine_pv.c b/hw/xenpv/xen_machine_pv.c index 1533f5dfb4..9f9f137f99 100644 --- a/hw/xenpv/xen_machine_pv.c +++ b/hw/xenpv/xen_machine_pv.c @@ -54,7 +54,6 @@ static void xen_init_pv(MachineState *machine) } =20 xen_be_register("vfb", &xen_framebuffer_ops); - xen_be_register("qnic", &xen_netdev_ops); =20 /* configure framebuffer */ if (vga_interface_type =3D=3D VGA_XENFB) { --=20 2.40.1 From nobody Fri May 17 02:41:25 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 1698245563805285.72271184893964; Wed, 25 Oct 2023 07:52:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEc-0005ia-Ip; Wed, 25 Oct 2023 10:51:52 -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 1qvfE8-0005E5-R9; Wed, 25 Oct 2023 10:51:22 -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 1qvfDp-000764-99; Wed, 25 Oct 2023 10:51:20 -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 1qvfDa-00GPM5-1F; Wed, 25 Oct 2023 14:50:51 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFL-0k; Wed, 25 Oct 2023 15:50:45 +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=iaeDXSTaoWdCm87GDHXDzDikArDTOfszjp92r6YPQM0=; b=Fpo2lDHmkFJFrEzTxCnYSHMQc+ H+POf4RpTDXrqfi7zmTI2kpkXiZEJ/4ikVugJbl/UXMyulJnl8bxTi7gdq+Xlhe/NOsdTz353nXNS skhnTvQvc19bBykXDJLHjeBVQ97kJvOEjCn3zBqYb/BH5rDtwk6NqQC0EyXGhRuEVDofWOrIuQUbH eDXBfUYpNVxLjOjbdUpmFPsWWBCjffiEX876q5ArcW6FdlTHX93HUMDbaBkhxtxYaZxt/fpHXCNkE Ko/NceL/1GypeXooX+xxhcNkWMbOUUaDd3BrGGwo4s3+7LbNRB/e9K7vIixU+dnx+7J2jpuR7mvKp dd1Vd6Hw==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 20/28] net: do not delete nics in net_cleanup() Date: Wed, 25 Oct 2023 15:50:34 +0100 Message-Id: <20231025145042.627381-21-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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+fe87d11d956b9f6f1554+7367+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: 1698245565926100003 Content-Type: text/plain; charset="utf-8" From: David Woodhouse In net_cleanup() we only need to delete the netdevs, as those may have state which outlives Qemu when it exits, and thus may actually need to be cleaned up on exit. The nics, on the other hand, are owned by the device which created them. Most devices don't bother to clean up on exit because they don't have any state which will outlive Qemu... but XenBus devices do need to clean up their nodes in XenStore, and do have an exit handler to delete them. When the XenBus exit handler destroys the xen-net-device, it attempts to delete its nic after net_cleanup() had already done so. And crashes. Fix this by only deleting netdevs as we walk the list. As the comment notes, we can't use QTAILQ_FOREACH_SAFE() as each deletion may remove *multiple* entries, including the "safely" saved 'next' pointer. But we can store the *previous* entry, since nics are safe. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- net/net.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/net/net.c b/net/net.c index c0c0cbe99e..bbe33da176 100644 --- a/net/net.c +++ b/net/net.c @@ -1499,18 +1499,34 @@ static void net_vm_change_state_handler(void *opaqu= e, bool running, =20 void net_cleanup(void) { - NetClientState *nc; + NetClientState *nc, **p =3D &QTAILQ_FIRST(&net_clients); =20 /*cleanup colo compare module for COLO*/ colo_compare_cleanup(); =20 - /* We may del multiple entries during qemu_del_net_client(), - * so QTAILQ_FOREACH_SAFE() is also not safe here. + /* + * Walk the net_clients list and remove the netdevs but *not* any + * NET_CLIENT_DRIVER_NIC entries. The latter are owned by the device + * model which created them, and in some cases (e.g. xen-net-device) + * the device itself may do cleanup at exit and will be upset if we + * just delete its NIC from underneath it. + * + * Since qemu_del_net_client() may delete multiple entries, using + * QTAILQ_FOREACH_SAFE() is not safe here. The only safe pointer + * to keep as a bookmark is a NET_CLIENT_DRIVER_NIC entry, so keep + * 'p' pointing to either the head of the list, or the 'next' field + * of the latest NET_CLIENT_DRIVER_NIC, and operate on *p as we walk + * the list. + * + * The 'nc' variable isn't part of the list traversal; it's purely + * for convenience as too much '(*p)->' has a tendency to make the + * readers' eyes bleed. */ - while (!QTAILQ_EMPTY(&net_clients)) { - nc =3D QTAILQ_FIRST(&net_clients); + while (*p) { + nc =3D *p; if (nc->info->type =3D=3D NET_CLIENT_DRIVER_NIC) { - qemu_del_nic(qemu_get_nic(nc)); + /* Skip NET_CLIENT_DRIVER_NIC entries */ + p =3D &QTAILQ_NEXT(nc, next); } else { qemu_del_net_client(nc); } --=20 2.40.1 From nobody Fri May 17 02:41:25 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=1698245499; cv=none; d=zohomail.com; s=zohoarc; b=BnIlZMAg8sS03HEPqYyue0hpwKVKTIX5V+KEdA4+TUch1i/4DqRuBjSgwyU86M6B2DM5lLudThJDmFG6mwJL7Uo4mbNsb4By87YuqtNIqz22EJsOB2hzpApeKzDU7YoURsxug5LcIsYb5HNlgxSUAOI5HYQETiheFgqEOgtd9Sw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245499; 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=y4cEjsiuJ1bFNsoLeKKWM6n6686E9X1lvqONj/DtYQs=; b=YppTL5S7ZUCIEL+clD4xETKfL57O4uBPpdJgDcLRza+I7Ja6ho4ahV/llFIcfL4zXJsNCRSzN2doka+61s4zq6JMhEwSVjcPSRhIwBQZ7wLKuwC30+1ARhLDhbYt8IzvSBtGld1Nk5l6iDoTPVaC2zYtjAkabgOJfhSI/GxKXx8= 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 1698245499702325.67659327647914; Wed, 25 Oct 2023 07:51:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622972.970367 (Exim 4.92) (envelope-from ) id 1qvfE1-00030B-65; Wed, 25 Oct 2023 14:51:13 +0000 Received: by outflank-mailman (output) from mailman id 622972.970367; Wed, 25 Oct 2023 14:51:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfE0-0002xs-JU; Wed, 25 Oct 2023 14:51:12 +0000 Received: by outflank-mailman (input) for mailman id 622972; Wed, 25 Oct 2023 14:51:10 +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 1qvfDy-0000WU-OZ for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:10 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ed910d57-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:51:07 +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 1qvfDZ-009Nmp-OP; Wed, 25 Oct 2023 14:50:45 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFP-0x; Wed, 25 Oct 2023 15:50:45 +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: ed910d57-7345-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=y4cEjsiuJ1bFNsoLeKKWM6n6686E9X1lvqONj/DtYQs=; b=lrSrOgOplofh9XNYvO/Y6Cc20E b2BRTomTqLlH4ivgwD4sBmyXjLP3I1Fai6wk4h8Si1HSDLa25iMcQJekBASDQUPnHVIhgwPDGuIPe /fiD7p1xKwU7WPhmYzbbiUGkYAMCw9eYzzmKLc7jSYCCrbc9Il3cn+XOaaQle1LLOunGnghcs49bw 3xgOTsVL24eBNSqWchz1Vf7eCnWmMNu5ej9mU2LmU4o06Qtg1DKPiu8P5eSAmOZnGMDFsJIQQAZUI 06foiSUf0y/lJX5p1rYRRqKVhWC+mTGRpDqqHpAJiAZgoYQGU7Q2itxuffQXtTSt1ckoY4gF2ShZl N4J97H8w==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 21/28] xen-platform: unplug AHCI disks Date: Wed, 25 Oct 2023 15:50:35 +0100 Message-Id: <20231025145042.627381-22-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245501658100005 Content-Type: text/plain; charset="utf-8" From: David Woodhouse To support Xen guests using the Q35 chipset, the unplug protocol needs to also remove AHCI disks. Make pci_xen_ide_unplug() more generic, iterating over the children of the PCI device and destroying the "ide-hd" devices. That works the same for both AHCI and IDE, as does the detection of the primary disk as unit 0 on the bus named "ide.0". Then pci_xen_ide_unplug() can be used for both AHCI and IDE devices. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/xen/xen_platform.c | 68 +++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c index e2dd1b536a..ef7d3fc05f 100644 --- a/hw/i386/xen/xen_platform.c +++ b/hw/i386/xen/xen_platform.c @@ -169,39 +169,60 @@ static void pci_unplug_nics(PCIBus *bus) * * [1] https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dblob;f=3Ddocs/misc/= hvm-emulated-unplug.pandoc */ -static void pci_xen_ide_unplug(PCIDevice *d, bool aux) +struct ide_unplug_state { + bool aux; + int nr_unplugged; +}; + +static int ide_dev_unplug(DeviceState *dev, void *_st) { - DeviceState *dev =3D DEVICE(d); - PCIIDEState *pci_ide; - int i; + struct ide_unplug_state *st =3D _st; IDEDevice *idedev; IDEBus *idebus; BlockBackend *blk; + int unit; + + idedev =3D IDE_DEVICE(object_dynamic_cast(OBJECT(dev), "ide-hd")); + if (!idedev) { + return 0; + } =20 - pci_ide =3D PCI_IDE(dev); + idebus =3D IDE_BUS(qdev_get_parent_bus(dev)); =20 - for (i =3D aux ? 1 : 0; i < 4; i++) { - idebus =3D &pci_ide->bus[i / 2]; - blk =3D idebus->ifs[i % 2].blk; + unit =3D (idedev =3D=3D idebus->slave); + assert(unit || idedev =3D=3D idebus->master); =20 - if (blk && idebus->ifs[i % 2].drive_kind !=3D IDE_CD) { - if (!(i % 2)) { - idedev =3D idebus->master; - } else { - idedev =3D idebus->slave; - } + if (st->aux && !unit && !strcmp(BUS(idebus)->name, "ide.0")) { + return 0; + } =20 - blk_drain(blk); - blk_flush(blk); + blk =3D idebus->ifs[unit].blk; + if (blk) { + blk_drain(blk); + blk_flush(blk); =20 - blk_detach_dev(blk, DEVICE(idedev)); - idebus->ifs[i % 2].blk =3D NULL; - idedev->conf.blk =3D NULL; - monitor_remove_blk(blk); - blk_unref(blk); - } + blk_detach_dev(blk, DEVICE(idedev)); + idebus->ifs[unit].blk =3D NULL; + idedev->conf.blk =3D NULL; + monitor_remove_blk(blk); + blk_unref(blk); + } + + object_unparent(OBJECT(dev)); + st->nr_unplugged++; + + return 0; +} + +static void pci_xen_ide_unplug(PCIDevice *d, bool aux) +{ + struct ide_unplug_state st =3D { aux, 0 }; + DeviceState *dev =3D DEVICE(d); + + qdev_walk_children(dev, NULL, NULL, ide_dev_unplug, NULL, &st); + if (st.nr_unplugged) { + pci_device_reset(d); } - pci_device_reset(d); } =20 static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque) @@ -216,6 +237,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void = *opaque) =20 switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) { case PCI_CLASS_STORAGE_IDE: + case PCI_CLASS_STORAGE_SATA: pci_xen_ide_unplug(d, aux); break; =20 --=20 2.40.1 From nobody Fri May 17 02:41:25 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 1698245505186755.337568047387; Wed, 25 Oct 2023 07:51:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEJ-0005Lp-Od; Wed, 25 Oct 2023 10:51: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 1qvfE5-0005CH-1y; Wed, 25 Oct 2023 10:51:22 -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 1qvfDp-000763-As; Wed, 25 Oct 2023 10:51:16 -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 1qvfDa-00GPM6-1D; Wed, 25 Oct 2023 14:50:52 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFU-1H; Wed, 25 Oct 2023 15:50:45 +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=SKjWRXIgiNg5ff3bqQvSLiVcvlPitO7cHPHfc8XhUXU=; b=i2fwrV8zZ2vjfC4alhYHqho5Kg 69ItbcjuoufZl6Gv9FMYnIEB1jR+EI2qtRRyqdOFgFYEK1LzG6KxP647hv5/G6my2/D3e1Nf518Bs bpsvnspf+G1TgFmvc69VdUs+xMWSbH3w/d4GIgFwg5c42Bt8j3HQ0PB1C/Uw/bTNjij8N3BLhn+ME sAQG8vSqxTsmOj0rSVeluMyopsAtLcdgMvZEUnRoZLqQP3/BB165JjV78qWqWj2nFaH3b3IQwlvyc qdKCIT24XkYpjsTqPbsyzvjsef9hJe/F4fTkTDMQPAPKlnUOqPmS4ZrhiS0hKFMIO3E4buVrrQeEB WiLXn9OQ==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 22/28] net: add qemu_{configure, create}_nic_device(), qemu_find_nic_info() Date: Wed, 25 Oct 2023 15:50:36 +0100 Message-Id: <20231025145042.627381-23-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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+fe87d11d956b9f6f1554+7367+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: 1698245505996100009 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Most code which directly accesses nd_table[] and nb_nics uses them for one of two things. Either "I have created a NIC device and I'd like a configuration for it", or "I will create a NIC device *if* there is a configuration for it". With some variants on the theme around whether they actually *check* if the model specified in the configuration is the right one. Provide functions which perform both of those, allowing platforms to be a little more consistent and as a step towards making nd_table[] and nb_nics private to the net code. Also export the qemu_find_nic_info() helper, as some platforms have special cases they need to handle. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- include/net/net.h | 7 ++++++- net/net.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/include/net/net.h b/include/net/net.h index 2fb1c9181c..56be694c75 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -205,7 +205,12 @@ int qemu_show_nic_models(const char *arg, const char *= const *models); void qemu_check_nic_model(NICInfo *nd, const char *model); int qemu_find_nic_model(NICInfo *nd, const char * const *models, const char *default_model); - +NICInfo *qemu_find_nic_info(const char *typename, bool match_default, + const char *alias); +bool qemu_configure_nic_device(DeviceState *dev, bool match_default, + const char *alias); +DeviceState *qemu_create_nic_device(const char *typename, bool match_defau= lt, + const char *alias); void print_net_client(Monitor *mon, NetClientState *nc); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, diff --git a/net/net.c b/net/net.c index bbe33da176..f8b4973a1e 100644 --- a/net/net.c +++ b/net/net.c @@ -1072,6 +1072,57 @@ static int net_init_nic(const Netdev *netdev, const = char *name, return idx; } =20 +NICInfo *qemu_find_nic_info(const char *typename, bool match_default, + const char *alias) +{ + NICInfo *nd; + int i; + + for (i =3D 0; i < nb_nics; i++) { + nd =3D &nd_table[i]; + + if (!nd->used || nd->instantiated) { + continue; + } + + if ((match_default && !nd->model) || !g_strcmp0(nd->model, typenam= e) + || (alias && !g_strcmp0(nd->model, alias))) { + return nd; + } + } + return NULL; +} + + +/* "I have created a device. Please configure it if you can" */ +bool qemu_configure_nic_device(DeviceState *dev, bool match_default, + const char *alias) +{ + NICInfo *nd =3D qemu_find_nic_info(object_get_typename(OBJECT(dev)), + match_default, alias); + + if (nd) { + qdev_set_nic_properties(dev, nd); + return true; + } + return false; +} + +/* "Please create a device, if you have a configuration for it" */ +DeviceState *qemu_create_nic_device(const char *typename, bool match_defau= lt, + const char *alias) +{ + NICInfo *nd =3D qemu_find_nic_info(typename, match_default, alias); + DeviceState *dev; + + if (!nd) { + return NULL; + } + + dev =3D qdev_new(typename); + qdev_set_nic_properties(dev, nd); + return dev; +} =20 static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])( const Netdev *netdev, --=20 2.40.1 From nobody Fri May 17 02:41:25 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=1698245498; cv=none; d=zohomail.com; s=zohoarc; b=dMkvPWUGWcUg1kBluVxe7EB22tSpAxn4F55Fk8kAqHSAV2WX0mrGwWr8YoJUBI+p1P6ZZW1mNvIK9F5KBeGWVHTFGolflWsdoyQJbE0+sWRdzmYOe6fO+jpX4tvmnvFcoJFcK2P5ccqQ1xPBdt9kr92Mu27WaqMcsT6PgthxNDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245498; 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=uSYMnEZDiwsPKPtr72ZyrADmBs8CT77t/B1qZONpFnk=; b=L8r7SAf8fPEPdvVenb6JjdBatlpAyOTy3QmytOI9zC/B979Di1BfHtNA5V9gg2tdm2QehovcC5+EWyJD4uhJyf0KrukQNKmiZhBs2YCweOTCWy7TESwYSBSqcZFcjfh/InjPmsu+ZH3SosLDjq+0bEheP4SXWMmElmYpbAHY4pA= 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 1698245498503299.031941054022; Wed, 25 Oct 2023 07:51:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622967.970314 (Exim 4.92) (envelope-from ) id 1qvfDv-0001Ur-Kb; Wed, 25 Oct 2023 14:51:07 +0000 Received: by outflank-mailman (output) from mailman id 622967.970314; Wed, 25 Oct 2023 14:51:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDv-0001T4-CP; Wed, 25 Oct 2023 14:51:07 +0000 Received: by outflank-mailman (input) for mailman id 622967; Wed, 25 Oct 2023 14:51:06 +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 1qvfDu-0008W8-8V for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:06 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id eca87b99-7345-11ee-98d5-6d05b1d4d9a1; Wed, 25 Oct 2023 16:51:05 +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 1qvfDZ-009Nmr-Th; Wed, 25 Oct 2023 14:50:45 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFY-1e; Wed, 25 Oct 2023 15:50:45 +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: eca87b99-7345-11ee-98d5-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=uSYMnEZDiwsPKPtr72ZyrADmBs8CT77t/B1qZONpFnk=; b=WfqXIU2zPItQyXKjZHl4Uu9nXh B6aWg7LSpwUF0ueOAIEJSHiIEOHrRCeloIWpDcQLn00ZXlpH77lXvOJaiaJ+/nYln7eLJrszaiTL/ 50b3+nHmNgCiey+dLbJhOYuEqpXAmelyhhNY+Jf93M/8ffQ/AW/ZaXJ6BdpbzfhFn3y5SEKA7L7bb 5cxCrkxQM2ovzfSMvfuakvCgcXTE2C+qrxmRHBI/8yrS82PDGltHwhHIWhkoUKeTZMBz6cei2ZY1a i1qLV5q9D7zkuExZVKvvuuvpb5o+fOdDWtGJVQhuKAYVc8Ub6vIRyjQL7K53bgfylOkeRywegpm+R 8CpeF+jw==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 23/28] net: report list of available models according to platform Date: Wed, 25 Oct 2023 15:50:37 +0100 Message-Id: <20231025145042.627381-24-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245499846100003 Content-Type: text/plain; charset="utf-8" From: David Woodhouse By noting the models for which a configuration was requested, we can give the user an accurate list of which NIC models were actually available on the platform/configuration that was otherwise chosen. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- net/net.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/net/net.c b/net/net.c index f8b4973a1e..807220e630 100644 --- a/net/net.c +++ b/net/net.c @@ -75,6 +75,8 @@ typedef QSIMPLEQ_HEAD(, NetdevQueueEntry) NetdevQueue; =20 static NetdevQueue nd_queue =3D QSIMPLEQ_HEAD_INITIALIZER(nd_queue); =20 +static GHashTable *nic_model_help; + /***********************************************************/ /* network device redirectors */ =20 @@ -1072,12 +1074,94 @@ static int net_init_nic(const Netdev *netdev, const= char *name, return idx; } =20 +static gboolean add_nic_result(gpointer key, gpointer value, gpointer user= _data) +{ + GPtrArray *results =3D user_data; + GPtrArray *alias_list =3D value; + const char *model =3D key; + char *result; + + if (!alias_list) { + result =3D g_strdup(model); + } else { + GString *result_str =3D g_string_new(model); + int i; + + g_string_append(result_str, " (aka "); + for (i =3D 0; i < alias_list->len; i++) { + if (i) { + g_string_append(result_str, ", "); + } + g_string_append(result_str, alias_list->pdata[i]); + } + g_string_append(result_str, ")"); + result =3D result_str->str; + g_string_free(result_str, false); + g_ptr_array_unref(alias_list); + } + g_ptr_array_add(results, result); + return true; +} + +static int model_cmp(char **a, char **b) +{ + return strcmp(*a, *b); +} + +static void show_nic_models(void) +{ + GPtrArray *results =3D g_ptr_array_new(); + int i; + + g_hash_table_foreach_remove(nic_model_help, add_nic_result, results); + g_ptr_array_sort(results, (GCompareFunc)model_cmp); + + printf("Available NIC models for this configuration:\n"); + for (i =3D 0 ; i < results->len; i++) { + printf("%s\n", (char *)results->pdata[i]); + } + g_hash_table_unref(nic_model_help); + nic_model_help =3D NULL; +} + +static void add_nic_model_help(const char *model, const char *alias) +{ + GPtrArray *alias_list =3D NULL; + + if (g_hash_table_lookup_extended(nic_model_help, model, NULL, + (gpointer *)&alias_list)) { + /* Already exists, no alias to add: return */ + if (!alias) { + return; + } + if (alias_list) { + /* Check if this alias is already in the list. Add if not. */ + if (!g_ptr_array_find_with_equal_func(alias_list, alias, + g_str_equal, NULL)) { + g_ptr_array_add(alias_list, g_strdup(alias)); + } + return; + } + } + /* Either this model wasn't in the list already, or a first alias adde= d */ + if (alias) { + alias_list =3D g_ptr_array_new(); + g_ptr_array_set_free_func(alias_list, g_free); + g_ptr_array_add(alias_list, g_strdup(alias)); + } + g_hash_table_replace(nic_model_help, g_strdup(model), alias_list); +} + NICInfo *qemu_find_nic_info(const char *typename, bool match_default, const char *alias) { NICInfo *nd; int i; =20 + if (nic_model_help) { + add_nic_model_help(typename, alias); + } + for (i =3D 0; i < nb_nics; i++) { nd =3D &nd_table[i]; =20 @@ -1591,6 +1675,10 @@ void net_check_clients(void) NetClientState *nc; int i; =20 + if (nic_model_help) { + show_nic_models(); + exit(0); + } net_hub_check_clients(); =20 QTAILQ_FOREACH(nc, &net_clients, next) { @@ -1670,6 +1758,12 @@ static int net_param_nic(void *dummy, QemuOpts *opts= , Error **errp) memset(ni, 0, sizeof(*ni)); ni->model =3D qemu_opt_get_del(opts, "model"); =20 + if (!nic_model_help && !g_strcmp0(ni->model, "help")) { + nic_model_help =3D g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, NULL); + return 0; + } + /* Create an ID if the user did not specify one */ nd_id =3D g_strdup(qemu_opts_id(opts)); if (!nd_id) { --=20 2.40.1 From nobody Fri May 17 02:41:25 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 1698245580306497.4271146050828; Wed, 25 Oct 2023 07:53:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEc-0005iZ-Ix; Wed, 25 Oct 2023 10:51:52 -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 1qvfE8-0005E7-Rf; Wed, 25 Oct 2023 10:51:22 -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 1qvfDp-000766-9q; Wed, 25 Oct 2023 10:51:19 -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 1qvfDa-00GPM7-1F; Wed, 25 Oct 2023 14:50:52 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFc-1r; Wed, 25 Oct 2023 15:50:45 +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: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description; bh=e3RGCKPN6DnRwj3sLAh0PlZLNbe3bg+XVYAVQTfyq30=; b=crXqHB5cJnKDgUDkB2XyGw6pyF D1RJPAR3lehL0VnPW0BmjuI9b0+r5tpIJRCBhL6vOIhn5/oivqeQpf+Zje7YgnjTlzNpGjSUWfRY6 nf7vPKCAnUY41Zfp87PvioNtmZRSNnd+zAW+/JaV6Zuz5NfoJTRWSnrzscIXMqfLoXRyCM6KrC6no Pw68Qm362C2IIl69Eb+K6zL6Jt9MBz+N6gilQ4H061Gb7wZgKnVKSClEPnFEWH0Ck3L7x80SxkW/v MrSi9S6xjy7WmvYaTA5/Dc9kDSvaziPKvmGMpscSup+p0UULqjihmPIwqr9eyZnT86t5km8ZXSbzO YZt9XSrQ==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 24/28] net: add qemu_create_nic_bus_devices() Date: Wed, 25 Oct 2023 15:50:38 +0100 Message-Id: <20231025145042.627381-25-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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+fe87d11d956b9f6f1554+7367+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: 1698245581991100001 From: David Woodhouse This will instantiate any NICs which live on a given bus type. Each bus is allowed *one* substitution (for PCI it's virtio =E2=86=92 virtio-net-pci= , for Xen it's xen =E2=86=92 xen-net-device; no point in overengineering it unles= s we actually want more). Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- include/net/net.h | 3 +++ net/net.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 56be694c75..ce830a47d0 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -211,6 +211,9 @@ bool qemu_configure_nic_device(DeviceState *dev, bool m= atch_default, const char *alias); DeviceState *qemu_create_nic_device(const char *typename, bool match_defau= lt, const char *alias); +void qemu_create_nic_bus_devices(BusState *bus, const char *parent_type, + const char *default_model, + const char *alias, const char *alias_targ= et); void print_net_client(Monitor *mon, NetClientState *nc); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, diff --git a/net/net.c b/net/net.c index 807220e630..73621795cb 100644 --- a/net/net.c +++ b/net/net.c @@ -1208,6 +1208,59 @@ DeviceState *qemu_create_nic_device(const char *type= name, bool match_default, return dev; } =20 +void qemu_create_nic_bus_devices(BusState *bus, const char *parent_type, + const char *default_model, + const char *alias, const char *alias_targ= et) +{ + GPtrArray *nic_models =3D qemu_get_nic_models(parent_type); + const char *model; + DeviceState *dev; + NICInfo *nd; + int i; + + if (nic_model_help) { + if (alias_target) { + add_nic_model_help(alias_target, alias); + } + for (i =3D 0; i < nic_models->len - 1; i++) { + add_nic_model_help(nic_models->pdata[i], NULL); + } + } + + /* Drop the NULL terminator which would make g_str_equal() unhappy */ + nic_models->len--; + + for (i =3D 0; i < nb_nics; i++) { + nd =3D &nd_table[i]; + + if (!nd->used || nd->instantiated) { + continue; + } + + model =3D nd->model ? nd->model : default_model; + if (!model) { + continue; + } + + /* Each bus type is allowed *one* substitution */ + if (g_str_equal(model, alias)) { + model =3D alias_target; + } + + if (!g_ptr_array_find_with_equal_func(nic_models, model, + g_str_equal, NULL)) { + /* This NIC does not live on this bus. */ + continue; + } + + dev =3D qdev_new(model); + qdev_set_nic_properties(dev, nd); + qdev_realize_and_unref(dev, bus, &error_fatal); + } + + g_ptr_array_free(nic_models, true); +} + static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])( const Netdev *netdev, const char *name, --=20 2.40.1 From nobody Fri May 17 02:41:25 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 1698245636279132.3703728697161; Wed, 25 Oct 2023 07:53:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEh-0005xI-Af; Wed, 25 Oct 2023 10:51:56 -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 1qvfE8-0005E4-R3; Wed, 25 Oct 2023 10:51:22 -0400 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvfDp-00075i-E0; Wed, 25 Oct 2023 10:51:19 -0400 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 1qvfDa-009Nms-1e; Wed, 25 Oct 2023 14:50:46 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFg-23; Wed, 25 Oct 2023 15:50:45 +0100 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=yQfwtPbREGreJZVtftdMEfHE+iyAsm6cKl0Oh4POK+Q=; b=Mip1iYJSsW63MhtMiW7lLRRtcN ur5UxOh/K0bhJvgyuwL3anhrKnfHaqrYx5ZJMdFB5jGn+RMD+HS7wtiHcoklHoFvdv2I43TTgm4TN kbQMmZY/q2QwvkEfSnvyMGAeZsQKkHKyqXNtvLtoA1o6dpir3gCSx6zkRP/hgW+wVh0OdOIXsuUYe +74CUSSgTmHxS5NFl3qIuMTHyLzhGKDdzUo9JKEtFq0vxXU9zdIfzsD8r79TPKaOSKhqd+hJpJhsQ 6ol8uqebpxD+CZwrgZBC26MmQdHCy/53gOLmG5HnyAqdEDJdxy72SrwmzynaKS5u9rW9ksT7Dyte/ F/41VQRA==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 25/28] hw/pci: add pci_init_nic_devices(), pci_init_nic_in_slot() Date: Wed, 25 Oct 2023 15:50:39 +0100 Message-Id: <20231025145042.627381-26-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.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:1236::1; envelope-from=BATV+85b1c44ac99574f3713d+7367+infradead.org+dwmw2@casper.srs.infradead.org; helo=casper.infradead.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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: 1698245638171100003 Content-Type: text/plain; charset="utf-8" From: David Woodhouse The loop over nd_table[] to add PCI NICs is repeated in quite a few places. Add a helper function to do it. Some platforms also try to instantiate a specific model in a specific slot, to match the real hardware. Add pci_init_nic_in_slot() for that purpose. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/pci/pci.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 4 +++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 7d09e1a39d..51b0be3972 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1925,6 +1925,51 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *= rootbus, return pci_dev; } =20 +void pci_init_nic_devices(PCIBus *bus, const char *default_model) +{ + qemu_create_nic_bus_devices(&bus->qbus, TYPE_PCI_DEVICE, default_model, + "virtio", "virtio-net-pci"); +} + +bool pci_init_nic_in_slot(PCIBus *rootbus, const char *model, + const char *alias, const char *devaddr) +{ + NICInfo *nd =3D qemu_find_nic_info(model, true, alias); + int dom, busnr, devfn; + PCIDevice *pci_dev; + unsigned slot; + PCIBus *bus; + + if (!nd) { + return false; + } + + if (!devaddr || pci_parse_devaddr(devaddr, &dom, &busnr, &slot, NULL) = < 0) { + error_report("Invalid PCI device address %s for device %s", + devaddr, model); + exit(1); + } + + if (dom !=3D 0) { + error_report("No support for non-zero PCI domains"); + exit(1); + } + + devfn =3D PCI_DEVFN(slot, 0); + + bus =3D pci_find_bus_nr(rootbus, busnr); + if (!bus) { + error_report("Invalid PCI device address %s for device %s", + devaddr, model); + exit(1); + } + + pci_dev =3D pci_new(devfn, model); + qdev_set_nic_properties(&pci_dev->qdev, nd); + pci_realize_and_unref(pci_dev, bus, &error_fatal); + return true; +} + PCIDevice *pci_vga_init(PCIBus *bus) { vga_interface_created =3D true; diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index ea5aff118b..684d49bdcd 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -317,7 +317,9 @@ void pci_device_reset(PCIDevice *dev); PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, const char *default_model, const char *default_devaddr); - +void pci_init_nic_devices(PCIBus *bus, const char *default_model); +bool pci_init_nic_in_slot(PCIBus *rootbus, const char *default_model, + const char *alias, const char *devaddr); PCIDevice *pci_vga_init(PCIBus *bus); =20 static inline PCIBus *pci_get_bus(const PCIDevice *dev) --=20 2.40.1 From nobody Fri May 17 02:41:25 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=1698245486; cv=none; d=zohomail.com; s=zohoarc; b=DaUmS898nyO0xofrKhixbtzBt4zlnQAnZ53C9HWLrQhbF9uSFeNzaBZxHmxc0kamsXhTX0ZM7lIopdg/98RCRIgOAs5w/OikKBPgOsyl9LiEPaThPZk+M1oPFL+JM0QnWk/d0bFtnD6qGA6QWlkHPCEkC53It5YckCXDiEaXEmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245486; 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=W3zMp4SVis8Wv7C4rIvkdlKc8TVg4WhmG+yeqSWM84w=; b=ZxqG+cQSucvaEIOrNxyUAqoStRTAfBx6m2OHaZOQcV/O+MANnGGTM+rWukDou5yeT+uvKphqDHLZssizYU7DKop/nI/6sVegueIhMjcsoAYTUrWJswKw53uMlGFzAwEjVrCKtWyOIsYlxcz5ZeAWe9NcU0LkAegqTT+pe7WgCS0= 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 1698245486088604.3099861569552; Wed, 25 Oct 2023 07:51:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622966.970309 (Exim 4.92) (envelope-from ) id 1qvfDv-0001QB-A8; Wed, 25 Oct 2023 14:51:07 +0000 Received: by outflank-mailman (output) from mailman id 622966.970309; Wed, 25 Oct 2023 14:51:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDv-0001P6-3K; Wed, 25 Oct 2023 14:51:07 +0000 Received: by outflank-mailman (input) for mailman id 622966; Wed, 25 Oct 2023 14:51:05 +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 1qvfDt-0000WU-Nq for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:05 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e964e8c7-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:51:00 +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 1qvfDa-009Nmu-1W; Wed, 25 Oct 2023 14:50:46 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFl-2Q; Wed, 25 Oct 2023 15:50:45 +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: e964e8c7-7345-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=W3zMp4SVis8Wv7C4rIvkdlKc8TVg4WhmG+yeqSWM84w=; b=wVLFRJGQmZRYbF38D2mJVDI4T1 J2sT8KM4AN8l2FtLiNVMEXxXJ6L5Kc0mjz9IBlRZm7hC6RBF5LH04we+oKtfcBSC0ii2kD5aymOHI r1+vIfiElRK7jws52xiLwzEQ28bodju9NIvkGjA5n4KIu1mF7zVr/HbatbjmspO0ljpnoSrwX6qHb fo02p3GSOYLaJysuyXhDThtmYiVYkUMryRS1gCn1+iInl4NGo33AqT9sIrSXuMu+cAa3Z7DlvWJV1 6MXQwPSJ9BURTPIDSyk3QuQUxMa5405mqSg3h5s9Cn5yCcCW2oQEWqqnBAzDUjfCts1QRNvEq0LjD gPBOVUtw==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 26/28] hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices() Date: Wed, 25 Oct 2023 15:50:40 +0100 Message-Id: <20231025145042.627381-27-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245487573100005 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Eliminate direct access to nd_table[] and nb_nics by processing the the ISA NICs first and then calling pci_init_nic_devices() for the test. It's important to do this *before* the subsequent patch which registers the Xen PV network devices, because the code being remove here didn't check whether nd->instantiated was already set before using each entry. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/pc.c | 21 +++++++++++---------- include/hw/net/ne2000-isa.h | 2 -- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 11fed78d17..7d2ae2b3d7 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -652,8 +652,11 @@ static void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd) { static int nb_ne2k =3D 0; =20 - if (nb_ne2k =3D=3D NE2000_NB_MAX) + if (nb_ne2k =3D=3D NE2000_NB_MAX) { + error_setg(&error_fatal, + "maximum number of ISA NE2000 devices exceeded"); return; + } isa_ne2000_init(bus, ne2000_io[nb_ne2k], ne2000_irq[nb_ne2k], nd); nb_ne2k++; @@ -1294,19 +1297,17 @@ void pc_basic_device_init(struct PCMachineState *pc= ms, void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus) { MachineClass *mc =3D MACHINE_CLASS(pcmc); - int i; + bool default_is_ne2k =3D g_str_equal(mc->default_nic, TYPE_ISA_NE2000); + NICInfo *nd; =20 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_NIC); - for (i =3D 0; i < nb_nics; i++) { - NICInfo *nd =3D &nd_table[i]; - const char *model =3D nd->model ? nd->model : mc->default_nic; =20 - if (g_str_equal(model, "ne2k_isa")) { - pc_init_ne2k_isa(isa_bus, nd); - } else { - pci_nic_init_nofail(nd, pci_bus, model, NULL); - } + while ((nd =3D qemu_find_nic_info(TYPE_ISA_NE2000, default_is_ne2k, NU= LL))) { + pc_init_ne2k_isa(isa_bus, nd); } + + pci_init_nic_devices(pci_bus, mc->default_nic); + rom_reset_order_override(); } =20 diff --git a/include/hw/net/ne2000-isa.h b/include/hw/net/ne2000-isa.h index af59ee0b02..73bae10ad1 100644 --- a/include/hw/net/ne2000-isa.h +++ b/include/hw/net/ne2000-isa.h @@ -22,8 +22,6 @@ static inline ISADevice *isa_ne2000_init(ISABus *bus, int= base, int irq, { ISADevice *d; =20 - qemu_check_nic_model(nd, "ne2k_isa"); - d =3D isa_try_new(TYPE_ISA_NE2000); if (d) { DeviceState *dev =3D DEVICE(d); --=20 2.40.1 From nobody Fri May 17 02:41:25 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 1698245502718679.9028914395127; Wed, 25 Oct 2023 07:51:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvfEM-0005QZ-9o; Wed, 25 Oct 2023 10:51:34 -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 1qvfDv-0005AM-01; Wed, 25 Oct 2023 10:51:08 -0400 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvfDo-000754-95; Wed, 25 Oct 2023 10:51:06 -0400 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 1qvfDb-009Nmv-GY; Wed, 25 Oct 2023 14:50:47 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFp-2d; Wed, 25 Oct 2023 15:50:45 +0100 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=xzkyRUM7nQfBrePX87BOU/AjGHoWHaL/QraAYhiDuVA=; b=BL58INjOUPmq2JMYOeuvydyhAU tPTn/p80t5Eh08H3gRlleRlgP+tgQWGq7N5wXJH7X/mlOScXTpOEWnbOuRpXEPuP6qVNRYaSGOugd 6tcXeJgK3mLtMIaVmwTi4STOuz6ondMNTsb2Dj73DZe37n6idaDQJsRGljufaBfSmbEuV49teBrTx m/FgIqkMEwtqCXoCcT8ymUrb/NGT1pJYZuYZbwQtSluK2yb0iTICekflP2IJA3Gpi9MMvtZg5uGSH wfGZq2vvHZM4qZ/snaUefgRQOvq1JM0TDWen5C41IvSrdS9pyW1ej5/6MqLtxrfa64loaDy8AXSPz 05GH0pzA==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 27/28] hw/xen: use qemu_create_nic_bus_devices() to instantiate Xen NICs Date: Wed, 25 Oct 2023 15:50:41 +0100 Message-Id: <20231025145042.627381-28-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.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:1236::1; envelope-from=BATV+85b1c44ac99574f3713d+7367+infradead.org+dwmw2@casper.srs.infradead.org; helo=casper.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: 1698245503875100003 Content-Type: text/plain; charset="utf-8" From: David Woodhouse When instantiating XenBus itself, for each NIC which is configured with either the model unspecified, or set to to "xen" or "xen-net-device", create a corresponding xen-net-device for it. Now we can launch emulated Xen guests with '-nic user', and this fixes the setup for Xen PV guests, which was previously broken in various ways and never actually managed to peer with the netdev. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/xen/xen-bus.c | 4 ++++ hw/xen/xen_devconfig.c | 25 ------------------------- hw/xenpv/xen_machine_pv.c | 9 --------- include/hw/xen/xen-legacy-backend.h | 1 - 4 files changed, 4 insertions(+), 35 deletions(-) diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index cc6f1b362f..fb82cc33e4 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -19,6 +19,7 @@ #include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "sysemu/sysemu.h" +#include "net/net.h" #include "trace.h" =20 static char *xen_device_get_backend_path(XenDevice *xendev) @@ -1140,4 +1141,7 @@ void xen_bus_init(void) =20 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); qbus_set_bus_hotplug_handler(bus); + + qemu_create_nic_bus_devices(bus, TYPE_XEN_DEVICE, "xen-net-device", + "xen", "xen-net-device"); } diff --git a/hw/xen/xen_devconfig.c b/hw/xen/xen_devconfig.c index 3f77c675c6..2150869f60 100644 --- a/hw/xen/xen_devconfig.c +++ b/hw/xen/xen_devconfig.c @@ -46,31 +46,6 @@ static int xen_config_dev_all(char *fe, char *be) =20 /* ------------------------------------------------------------- */ =20 -int xen_config_dev_nic(NICInfo *nic) -{ - char fe[256], be[256]; - char mac[20]; - int vlan_id =3D -1; - - net_hub_id_for_client(nic->netdev, &vlan_id); - snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x", - nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2], - nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]); - xen_pv_printf(NULL, 1, "config nic %d: mac=3D\"%s\"\n", vlan_id, mac); - xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe)); - - /* frontend */ - xenstore_write_int(fe, "handle", vlan_id); - xenstore_write_str(fe, "mac", mac); - - /* backend */ - xenstore_write_int(be, "handle", vlan_id); - xenstore_write_str(be, "mac", mac); - - /* common stuff */ - return xen_config_dev_all(fe, be); -} - int xen_config_dev_vfb(int vdev, const char *type) { char fe[256], be[256]; diff --git a/hw/xenpv/xen_machine_pv.c b/hw/xenpv/xen_machine_pv.c index 9f9f137f99..1130d1a147 100644 --- a/hw/xenpv/xen_machine_pv.c +++ b/hw/xenpv/xen_machine_pv.c @@ -32,8 +32,6 @@ =20 static void xen_init_pv(MachineState *machine) { - int i; - setup_xen_backend_ops(); =20 /* Initialize backend core & drivers */ @@ -62,13 +60,6 @@ static void xen_init_pv(MachineState *machine) vga_interface_created =3D true; } =20 - /* configure nics */ - for (i =3D 0; i < nb_nics; i++) { - if (!nd_table[i].model || 0 !=3D strcmp(nd_table[i].model, "xen")) - continue; - xen_config_dev_nic(nd_table + i); - } - xen_bus_init(); =20 /* config cleanup hook */ diff --git a/include/hw/xen/xen-legacy-backend.h b/include/hw/xen/xen-legac= y-backend.h index fc42146bc2..2cca174778 100644 --- a/include/hw/xen/xen-legacy-backend.h +++ b/include/hw/xen/xen-legacy-backend.h @@ -81,7 +81,6 @@ extern struct XenDevOps xen_usb_ops; /* xen-usb.= c */ =20 /* configuration (aka xenbus setup) */ void xen_config_cleanup(void); -int xen_config_dev_nic(NICInfo *nic); int xen_config_dev_vfb(int vdev, const char *type); int xen_config_dev_vkbd(int vdev); int xen_config_dev_console(int vdev); --=20 2.40.1 From nobody Fri May 17 02:41:25 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=1698245501; cv=none; d=zohomail.com; s=zohoarc; b=BlSQKsSv/2Zm2HEEXFDPKFimgSOwozqbep3/BYbvKAsiUTgvlZyijUN03S8IlPpXCn/3RvtVQIbhb8dhtrjCPrW/r/H8U6FqfuckRn8JtqWJiwZAwoVTwM16n3u5AlPCs5kpT2Dsi1LXl1yu56UC5DdnicfHBhY7m3ZcLQJQf8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698245501; 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=j1Dn7q6Qaq7MnCa855VhKvMLvN78EtjWJTTcd6S4txs=; b=m5gLSQSNvVVes+3vMijBHLSFU+E6QJe7jG0ii2au19k5361UZpDsvarMzs7kYZWJnu2mB3DZ/i1o7jMvEklJSwzDWCi/kIyFqr9IeF6BMRk+97hg8/9bDYhvi1F8iULK0GjGymNgrzbjQNSjoMM2nu+P143lNArPwpnv2XspG1U= 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 1698245501560502.341909385829; Wed, 25 Oct 2023 07:51:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.622970.970346 (Exim 4.92) (envelope-from ) id 1qvfDy-0002IP-DE; Wed, 25 Oct 2023 14:51:10 +0000 Received: by outflank-mailman (output) from mailman id 622970.970346; Wed, 25 Oct 2023 14:51:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qvfDx-0002Gs-Vm; Wed, 25 Oct 2023 14:51:09 +0000 Received: by outflank-mailman (input) for mailman id 622970; Wed, 25 Oct 2023 14:51:08 +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 1qvfDw-0000WU-OJ for xen-devel@lists.xenproject.org; Wed, 25 Oct 2023 14:51:08 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ea359a73-7345-11ee-9b0e-b553b5be7939; Wed, 25 Oct 2023 16:51:01 +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 1qvfDb-009NnL-Gt; Wed, 25 Oct 2023 14:50:47 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qvfDZ-002dFt-2r; Wed, 25 Oct 2023 15:50:45 +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: ea359a73-7345-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=j1Dn7q6Qaq7MnCa855VhKvMLvN78EtjWJTTcd6S4txs=; b=rRulWpO/m0gfiN0feKRMJZSGn5 hRb9Vhn0bdyIvk8sj9Nt8PrmsB+acuGZEgM7FOw8AsoyxXxHygnhWbexOYTZSNvolWwwRcUpY7hjN XU24Q1mO6Z+auWuq84CoUAajkyrw/NRboHyl27cTjafRF6CgAJ9ul4iipKrpoBn0P3JGvvga1AXmv QxxoqHWiJGigYp5z+gD7lgnCjxs+fGVFEcVdbQbvAv6KVjR1H8moKw2mVAHvZ2E9c75IQppZnUuAi VRF1jA9gaRSwI4R/1xFcs4XD/lxEjotJUrUjcOw2BevIt2NNd/X3xQnnKAs5Y7sw7WIP62A7xqAxL pPIINzNw==; 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 , Jason Wang , Marcelo Tosatti , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v3 28/28] docs: update Xen-on-KVM documentation Date: Wed, 25 Oct 2023 15:50:42 +0100 Message-Id: <20231025145042.627381-29-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231025145042.627381-1-dwmw2@infradead.org> References: <20231025145042.627381-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: 1698245503701100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Add notes about console and network support, and how to launch PV guests. Clean up the disk configuration examples now that that's simpler, and remove the comment about IDE unplug on q35/AHCI now that it's fixed. Also update stale avocado test filename in MAINTAINERS. Signed-off-by: David Woodhouse --- MAINTAINERS | 2 +- docs/system/i386/xen.rst | 100 ++++++++++++++++++++++++++++----------- 2 files changed, 73 insertions(+), 29 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index d36aa44661..0fcc454ccd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -490,7 +490,7 @@ S: Supported F: include/sysemu/kvm_xen.h F: target/i386/kvm/xen* F: hw/i386/kvm/xen* -F: tests/avocado/xen_guest.py +F: tests/avocado/kvm_xen_guest.py =20 Guest CPU Cores (other accelerators) ------------------------------------ diff --git a/docs/system/i386/xen.rst b/docs/system/i386/xen.rst index f06765e88c..6214c4571e 100644 --- a/docs/system/i386/xen.rst +++ b/docs/system/i386/xen.rst @@ -15,46 +15,24 @@ Setup ----- =20 Xen mode is enabled by setting the ``xen-version`` property of the KVM -accelerator, for example for Xen 4.10: +accelerator, for example for Xen 4.17: =20 .. parsed-literal:: =20 - |qemu_system| --accel kvm,xen-version=3D0x4000a,kernel-irqchip=3Dsplit + |qemu_system| --accel kvm,xen-version=3D0x40011,kernel-irqchip=3Dsplit =20 Additionally, virtual APIC support can be advertised to the guest through = the ``xen-vapic`` CPU flag: =20 .. parsed-literal:: =20 - |qemu_system| --accel kvm,xen-version=3D0x4000a,kernel-irqchip=3Dsplit -= -cpu host,+xen_vapic + |qemu_system| --accel kvm,xen-version=3D0x40011,kernel-irqchip=3Dsplit -= -cpu host,+xen-vapic =20 When Xen support is enabled, QEMU changes hypervisor identification (CPUID 0x40000000..0x4000000A) to Xen. The KVM identification and features are not advertised to a Xen guest. If Hyper-V is also enabled, the Xen identificat= ion moves to leaves 0x40000100..0x4000010A. =20 -The Xen platform device is enabled automatically for a Xen guest. This all= ows -a guest to unplug all emulated devices, in order to use Xen PV block and n= etwork -drivers instead. Under Xen, the boot disk is typically available both via = IDE -emulation, and as a PV block device. Guest bootloaders typically use IDE t= o load -the guest kernel, which then unplugs the IDE and continues with the Xen PV= block -device. - -This configuration can be achieved as follows - -.. parsed-literal:: - - |qemu_system| -M pc --accel kvm,xen-version=3D0x4000a,kernel-irqchip=3Ds= plit \\ - -drive file=3D${GUEST_IMAGE},if=3Dnone,id=3Ddisk,file.locking=3Doff= -device xen-disk,drive=3Ddisk,vdev=3Dxvda \\ - -drive file=3D${GUEST_IMAGE},index=3D2,media=3Ddisk,file.locking=3D= off,if=3Dide - -It is necessary to use the pc machine type, as the q35 machine uses AHCI i= nstead -of legacy IDE, and AHCI disks are not unplugged through the Xen PV unplug -mechanism. - -VirtIO devices can also be used; Linux guests may need to be dissuaded from -umplugging them by adding 'xen_emul_unplug=3Dnever' on their command line. - Properties ---------- =20 @@ -63,7 +41,10 @@ The following properties exist on the KVM accelerator ob= ject: ``xen-version`` This property contains the Xen version in ``XENVER_version`` form, with = the major version in the top 16 bits and the minor version in the low 16 bit= s. - Setting this property enables the Xen guest support. + Setting this property enables the Xen guest support. If Xen version 4.5 = or + greater is specified, the HVM leaf in Xen CPUID is populated. Xen version + 4.6 enables the vCPU ID in CPUID, and version 4.17 advertises vCPU upcall + vector support to the guest. =20 ``xen-evtchn-max-pirq`` Xen PIRQs represent an emulated physical interrupt, either GSI or MSI, w= hich @@ -83,8 +64,71 @@ The following properties exist on the KVM accelerator ob= ject: through simultaneous grants. For guests with large numbers of PV devices= and high throughput, it may be desirable to increase this value. =20 -OS requirements ---------------- +Xen paravirtual devices +----------------------- + +The Xen PCI platform device is enabled automatically for a Xen guest. This +allows a guest to unplug all emulated devices, in order to use paravirtual +block and network drivers instead. + +Those paravirtual Xen block, network (and console) devices can be created +through the command line, and/or hot-plugged. + +To provide a Xen console device, define a character device and then a devi= ce +of type ``xen-console`` to connect to it. For the Xen console equivalent of +the handy ``-serial mon:stdio`` option, for example: + +.. parsed-literal:: + -chardev -chardev stdio,mux=3Don,id=3Dchar0,signal=3Doff -mon char0 \\ + -device xen-console,chardev=3Dchar0 + +The Xen network device is ``xen-net-device``, which becomes the default NIC +model for emulated Xen guests, meaning that just the default ``-nic user`` +should automatically work and present a Xen network device to the guest. + +Disks can be configured with '``-drive file=3D${GUEST_IMAGE},if=3Dxen``' a= nd will +appear to the guest as ``xvda`` onwards. + +Under Xen, the boot disk is typically available both via IDE emulation, and +as a PV block device. Guest bootloaders typically use IDE to load the guest +kernel, which then unplugs the IDE and continues with the Xen PV block dev= ice. + +This configuration can be achieved as follows: + +.. parsed-literal:: + + |qemu_system| --accel kvm,xen-version=3D0x40011,kernel-irqchip=3Dsplit \\ + -drive file=3D${GUEST_IMAGE},if=3Dxen \\ + -drive file=3D${GUEST_IMAGE},file.locking=3Doff,if=3Dide + +VirtIO devices can also be used; Linux guests may need to be dissuaded from +umplugging them by adding '``xen_emul_unplug=3Dnever``' on their command l= ine. + +Booting Xen PV guests +--------------------- + +Booting PV guest kernels is possible by using the Xen PV shim (a version o= f Xen +itself, designed to run inside a Xen HVM guest and provide memory manageme= nt +services for one guest alone). + +The Xen binary is provided as the ``-kernel`` and the guest kernel itself = (or +PV Grub image) as the ``-initrd`` image, which actually just means the fir= st +multiboot "module". For example: + +.. parsed-literal:: + + |qemu_system| --accel kvm,xen-version=3D0x40011,kernel-irqchip=3Dsplit \\ + -chardev stdio,id=3Dchar0 -device xen-console,chardev=3Dchar0 \\ + -display none -m 1G -kernel xen -initrd bzImage \\ + -append "pv-shim console=3Dxen,pv -- console=3Dhvc0 root=3D/dev/xvd= a1" \\ + -drive file=3D${GUEST_IMAGE},if=3Dxen + +The Xen image must be built with the ``CONFIG_XEN_GUEST`` and ``CONFIG_PV_= SHIM`` +options, and as of Xen 4.17, Xen's PV shim mode does not support using a s= erial +port; it must have a Xen console or it will panic. + +Host OS requirements +-------------------- =20 The minimal Xen support in the KVM accelerator requires the host to be run= ning Linux v5.12 or newer. Later versions add optimisations: Linux v5.17 added --=20 2.40.1