From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418298; cv=none; d=zohomail.com; s=zohoarc; b=JFN8Em7b5LQczQ6gvD/37+qUN5pHaCNL9Iobgp8Z7ovihNrsBV2A7Xps8wtxCL54Gc8SrYd67bwVOMBo22eczhUJBjHdpekGkoOISJZLLVHYWBwj+AbGfUYRuU62KcY3H33lJiDNoknMXdkT2/Hhm1crb0m5bObOeRCIGYmIAA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418298; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hOqRYgnIRNDjegPtaWlw3oDrXRBw7c9FWDlx+7bW0R0=; b=f5+iK96Sb3Ik+wHo6YbWNxiVYChaL0gff9OIq131W39vTwb5Lh9ZEF6kC943IYJWpr9A+/i5CmoIf3Q7Tibv4KDvsuzIA5VmkkXHKxOucTQPLAfBaAKgcFjG56jrrd/6q24ePgPoqkhuOxzW/sOs0gJmBW1VK9hlh+yMcfjFRds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418298663474.1917394632187; Tue, 14 Feb 2023 15:44:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xX-0005IG-Nh; Tue, 14 Feb 2023 18:43:39 -0500 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 1pS4xV-0005Gn-T9 for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:37 -0500 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xU-0003k8-2X for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:37 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 61DD4B81E4A; Tue, 14 Feb 2023 23:43:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5488AC433EF; Tue, 14 Feb 2023 23:43:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418213; bh=kvIsppqJuGvkfwd1Y2Myje/RnRXHGaBztlU7IYWKzag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ow4q81n3Zv0mg61u9A1Pyfuq0WKRxv4dAGhe1WI2DzMUuLNf0Iea4QXUq2pJa8IhX 2FXJxQM2jllvQC8DZv0gfG+KT+7QusqQugida5Gjx1Q4BlUZAx6G4VGrKvXTBZdDou 7Rj+HzuA53LITDavrgmrQtzZbctgrojSaPZTyZ3kkbMY73Ycyc19C8XVhIApMrXniw KSylVgwrmxiVwVjo/OgI4e8GZcrCO0oKSFR61l/vsCOYL32TYo+ln4b4ZQyeIJ/SVl PQcMBNy22bz5xBDXN/dylgvUeShvDcnnPopbpfftMbWDfwl0j5M+ugbeI046BX0a2o DFF9uRgkTBclQ== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Vikram Garhwal , Stefano Stabellini , Paul Durrant Subject: [PULL v2 01/10] hw/i386/xen/: move xen-mapcache.c to hw/xen/ Date: Tue, 14 Feb 2023 15:43:21 -0800 Message-Id: <20230214234330.2107879-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2604:1380:4601:e00::1; envelope-from=sstabellini@kernel.org; helo=ams.source.kernel.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, DKIMWL_WL_HIGH=-0.001, 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_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418300324100005 Content-Type: text/plain; charset="utf-8" From: Vikram Garhwal xen-mapcache.c contains common functions which can be used for enabling Xen= on aarch64 with IOREQ handling. Moving it out from hw/i386/xen to hw/xen to ma= ke it accessible for both aarch64 and x86. Signed-off-by: Vikram Garhwal Signed-off-by: Stefano Stabellini Reviewed-by: Paul Durrant --- hw/i386/meson.build | 1 + hw/i386/xen/meson.build | 1 - hw/i386/xen/trace-events | 5 ----- hw/xen/meson.build | 4 ++++ hw/xen/trace-events | 5 +++++ hw/{i386 =3D> }/xen/xen-mapcache.c | 0 6 files changed, 10 insertions(+), 6 deletions(-) rename hw/{i386 =3D> }/xen/xen-mapcache.c (100%) diff --git a/hw/i386/meson.build b/hw/i386/meson.build index 213e2e82b3..cfdbfdcbcb 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -33,5 +33,6 @@ subdir('kvm') subdir('xen') =20 i386_ss.add_all(xenpv_ss) +i386_ss.add_all(xen_ss) =20 hw_arch +=3D {'i386': i386_ss} diff --git a/hw/i386/xen/meson.build b/hw/i386/xen/meson.build index be84130300..2fcc46e6ca 100644 --- a/hw/i386/xen/meson.build +++ b/hw/i386/xen/meson.build @@ -1,6 +1,5 @@ i386_ss.add(when: 'CONFIG_XEN', if_true: files( 'xen-hvm.c', - 'xen-mapcache.c', 'xen_apic.c', 'xen_platform.c', 'xen_pvdevice.c', diff --git a/hw/i386/xen/trace-events b/hw/i386/xen/trace-events index 5d6be61090..a0c89d91c4 100644 --- a/hw/i386/xen/trace-events +++ b/hw/i386/xen/trace-events @@ -21,8 +21,3 @@ xen_map_resource_ioreq(uint32_t id, void *addr) "id: %u a= ddr: %p" cpu_ioreq_config_read(void *req, uint32_t sbdf, uint32_t reg, uint32_t siz= e, uint32_t data) "I/O=3D%p sbdf=3D0x%x reg=3D%u size=3D%u data=3D0x%x" cpu_ioreq_config_write(void *req, uint32_t sbdf, uint32_t reg, uint32_t si= ze, uint32_t data) "I/O=3D%p sbdf=3D0x%x reg=3D%u size=3D%u data=3D0x%x" =20 -# xen-mapcache.c -xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64 -xen_remap_bucket(uint64_t index) "index 0x%"PRIx64 -xen_map_cache_return(void* ptr) "%p" - diff --git a/hw/xen/meson.build b/hw/xen/meson.build index ae0ace3046..19d0637c46 100644 --- a/hw/xen/meson.build +++ b/hw/xen/meson.build @@ -22,3 +22,7 @@ else endif =20 specific_ss.add_all(when: ['CONFIG_XEN', xen], if_true: xen_specific_ss) + +xen_ss =3D ss.source_set() + +xen_ss.add(when: 'CONFIG_XEN', if_true: files('xen-mapcache.c')) diff --git a/hw/xen/trace-events b/hw/xen/trace-events index 3da3fd8348..2c8f238f42 100644 --- a/hw/xen/trace-events +++ b/hw/xen/trace-events @@ -41,3 +41,8 @@ xs_node_vprintf(char *path, char *value) "%s %s" xs_node_vscanf(char *path, char *value) "%s %s" xs_node_watch(char *path) "%s" xs_node_unwatch(char *path) "%s" + +# xen-mapcache.c +xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64 +xen_remap_bucket(uint64_t index) "index 0x%"PRIx64 +xen_map_cache_return(void* ptr) "%p" diff --git a/hw/i386/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c similarity index 100% rename from hw/i386/xen/xen-mapcache.c rename to hw/xen/xen-mapcache.c --=20 2.25.1 From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418274; cv=none; d=zohomail.com; s=zohoarc; b=QBpBVZxWMV7ygAfC4agRlJdutivekx95a5NvQ/hQfHE3DBxS0NHBf+Rv5cONyMzOxWGYSNJLoVvOcx/XsdvX2Rf4poAy/OLltvC7fzFxlKlqnr3+eF8Zt3DSIZTc45/GAknoVmZK6TMYnyoED04cMzPNyzJIeAmcIJ7Yt4rcoOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418274; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2FYPeOpfPEZ0NlhFFhV8XyJxDqdo8+OBiEKk8++SjzI=; b=UPNAty+XpDOM2xYMdsFXlbgb0hnLNT7VaY4wsM8BVDKitreN39jpwsiC+IH4+kkk666eq9xw0xO/I3N/w3YJSxRj6K5bz7XOOQfYq3WSzxPRrjQdwbyX9xMm0vuP9de1v9KTKrnmby60HzwMXDvqfFuE0YVwk3WHnEUZvUGNssg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418274380279.77148659242073; Tue, 14 Feb 2023 15:44:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xZ-0005JK-CQ; Tue, 14 Feb 2023 18:43:42 -0500 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 1pS4xX-0005H8-4T for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:39 -0500 Received: from ams.source.kernel.org ([145.40.68.75]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xV-0003kE-Bq for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:38 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A348DB81F64; Tue, 14 Feb 2023 23:43:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 797C9C433D2; Tue, 14 Feb 2023 23:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418214; bh=tdZz167an86U63jjQhofWxvDKK4APmKXCIQILgOXsFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bV4N03Vgsk2Mxz+g+sSUQ/z4RwXxsqpZ9Amf8k0VoZh7W8dJ4qAldN5hdllxAkYIP E4k8IPgcaIBWYGC7tTVRdzYPQH3nn2Q7OxfPXDgZhTh/MZAtxHkNBsXiemSRrfyCsc K/OSPQAf5/zqTrlY+UBsc1bpEIbkdtcxQ6ikW0e8iGIQYEW9JF3jNizDOcRfIoBSz5 6n4hkDnvtj3I5r6dUDSJaGeAXqdzO3ZpmtIUykrVV+VmWBqMG0x11X6LGeWA7XDJC8 0PbsZJhXSfqKgXlEyW9xMoy4+0svtJs8kjkJ4DnTOPEyKzeHgf6h7g6NVb7WqkHHlL lFh00zQHJtxWw== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Vikram Garhwal , Stefano Stabellini , Paul Durrant Subject: [PULL v2 02/10] hw/i386/xen: rearrange xen_hvm_init_pc Date: Tue, 14 Feb 2023 15:43:22 -0800 Message-Id: <20230214234330.2107879-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=145.40.68.75; envelope-from=sstabellini@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418276266100001 Content-Type: text/plain; charset="utf-8" From: Vikram Garhwal In preparation to moving most of xen-hvm code to an arch-neutral location, move non IOREQ references to: - xen_get_vmport_regs_pfn - xen_suspend_notifier - xen_wakeup_notifier - xen_ram_init towards the end of the xen_hvm_init_pc() function. This is done to keep the common ioreq functions in one place which will be moved to new function in next patch in order to make it common to both x86 = and aarch64 machines. Signed-off-by: Vikram Garhwal Signed-off-by: Stefano Stabellini Reviewed-by: Paul Durrant --- hw/i386/xen/xen-hvm.c | 49 ++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index b9a6f7f538..1fba0e0ae1 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -1416,12 +1416,6 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryReg= ion **ram_memory) state->exit.notify =3D xen_exit_notifier; qemu_add_exit_notifier(&state->exit); =20 - state->suspend.notify =3D xen_suspend_notifier; - qemu_register_suspend_notifier(&state->suspend); - - state->wakeup.notify =3D xen_wakeup_notifier; - qemu_register_wakeup_notifier(&state->wakeup); - /* * Register wake-up support in QMP query-current-machine API */ @@ -1432,23 +1426,6 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryReg= ion **ram_memory) goto err; } =20 - rc =3D xen_get_vmport_regs_pfn(xen_xc, xen_domid, &ioreq_pfn); - if (!rc) { - DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn); - state->shared_vmport_page =3D - xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE, - 1, &ioreq_pfn, NULL); - if (state->shared_vmport_page =3D=3D NULL) { - error_report("map shared vmport IO page returned error %d hand= le=3D%p", - errno, xen_xc); - goto err; - } - } else if (rc !=3D -ENOSYS) { - error_report("get vmport regs pfn returned error %d, rc=3D%d", - errno, rc); - goto err; - } - /* Note: cpus is empty at this point in init */ state->cpu_by_vcpu_id =3D g_new0(CPUState *, max_cpus); =20 @@ -1486,7 +1463,6 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryRegi= on **ram_memory) #else xen_map_cache_init(NULL, state); #endif - xen_ram_init(pcms, ms->ram_size, ram_memory); =20 qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state); =20 @@ -1513,6 +1489,31 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryReg= ion **ram_memory) QLIST_INIT(&xen_physmap); xen_read_physmap(state); =20 + state->suspend.notify =3D xen_suspend_notifier; + qemu_register_suspend_notifier(&state->suspend); + + state->wakeup.notify =3D xen_wakeup_notifier; + qemu_register_wakeup_notifier(&state->wakeup); + + rc =3D xen_get_vmport_regs_pfn(xen_xc, xen_domid, &ioreq_pfn); + if (!rc) { + DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn); + state->shared_vmport_page =3D + xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE, + 1, &ioreq_pfn, NULL); + if (state->shared_vmport_page =3D=3D NULL) { + error_report("map shared vmport IO page returned error %d hand= le=3D%p", + errno, xen_xc); + goto err; + } + } else if (rc !=3D -ENOSYS) { + error_report("get vmport regs pfn returned error %d, rc=3D%d", + errno, rc); + goto err; + } + + xen_ram_init(pcms, ms->ram_size, ram_memory); + /* Disable ACPI build because Xen handles it */ pcms->acpi_build_enabled =3D false; =20 --=20 2.25.1 From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418247; cv=none; d=zohomail.com; s=zohoarc; b=gGEiWjpKQacv52YpNZZ7zznxz006S1jkhFmHxr9EbwMDXQKAiFYiIP9zA2LRiG8A8CdThCyA84rW5mFse8nhbOtsupOf1RzHErV3tGxWy3NSbMvVQsIg4qaDV1XLrEOj9TZKL/qZ9Z4qWx2XuW2R36CdtG+tvNLNe4XaUPetnr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418247; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z40VkkwrmUyIeMTtJumJ0ZZ+MxtCwdlfdOTgvqHiqrQ=; b=JORCHNhBGer3HplW2hO9uKgSEn1hzBkAxXbrwqVTIrc1XIpHiOMn+4iYM5QjGr+DPLRtfeuWYEsmW7qd3gcreyU7KhvgdIUHoyZfQXOXF1aCNRq4Cx57Zi0nPJKzWgjK2mlOuD6xmBu/UTfp68a6PB/yE2lFYe297s5wrBw2whA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418247948477.6162745337459; Tue, 14 Feb 2023 15:44:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xa-0005JN-5o; Tue, 14 Feb 2023 18:43:42 -0500 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 1pS4xX-0005IU-Tm for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:39 -0500 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xV-0003kL-Vl for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:39 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B7ADDB81F65; Tue, 14 Feb 2023 23:43:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A999C4339C; Tue, 14 Feb 2023 23:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418215; bh=5GTiFvLhRRfUKC0J3OLKtptMqNJZ2Qh9y/l3bmnCVvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k4vRxuQTHxsbbJ+jvsH6HqhiZlyxy3PsvQWdFasnl8XsZBoVeoOFGmonEOaR0S7Za +h9+HU78BXN1Kf7VVyEmI5C5iCv+jBPVgw/G1bN2V9qQUolpCx3GFsfMhmh7+y8NW6 o5Toe/GRk1aaEs86rG6c8mfpvAyk6NiBqMlOFDjVP/p6JrKNKAKEo+5Jn09OqOE434 Up8Ec2nJ6ASNSrymQTqLCPKAgYdz1Q9l5JIxzHP7zAZYI99Vu6dTZAN9bmbTHhBYww JpV2cxoKwft+UUcXJ7chSwiMqPfl3trmTk5NH+p4ATw46T3Z7UpY3B+l/QG04BvCcW Mkg1PZNVX+7fg== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Stefano Stabellini , Vikram Garhwal , Paul Durrant , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL v2 03/10] hw/i386/xen/xen-hvm: move x86-specific fields out of XenIOState Date: Tue, 14 Feb 2023 15:43:23 -0800 Message-Id: <20230214234330.2107879-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: pass client-ip=2604:1380:4601:e00::1; envelope-from=sstabellini@kernel.org; helo=ams.source.kernel.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, DKIMWL_WL_HIGH=-0.001, 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_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418250096100006 From: Stefano Stabellini In preparation to moving most of xen-hvm code to an arch-neutral location, = move: - shared_vmport_page - log_for_dirtybit - dirty_bitmap - suspend - wakeup out of XenIOState struct as these are only used on x86, especially the ones related to dirty logging. Updated XenIOState can be used for both aarch64 and x86. Also, remove free_phys_offset as it was unused. Signed-off-by: Stefano Stabellini Signed-off-by: Vikram Garhwal Reviewed-by: Paul Durrant Reviewed-by: Alex Benn=C3=A9e --- hw/i386/xen/xen-hvm.c | 58 ++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 1fba0e0ae1..06c446e7be 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -73,6 +73,7 @@ struct shared_vmport_iopage { }; typedef struct shared_vmport_iopage shared_vmport_iopage_t; #endif +static shared_vmport_iopage_t *shared_vmport_page; =20 static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i) { @@ -95,6 +96,11 @@ typedef struct XenPhysmap { } XenPhysmap; =20 static QLIST_HEAD(, XenPhysmap) xen_physmap; +static const XenPhysmap *log_for_dirtybit; +/* Buffer used by xen_sync_dirty_bitmap */ +static unsigned long *dirty_bitmap; +static Notifier suspend; +static Notifier wakeup; =20 typedef struct XenPciDevice { PCIDevice *pci_dev; @@ -105,7 +111,6 @@ typedef struct XenPciDevice { typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page; - shared_vmport_iopage_t *shared_vmport_page; buffered_iopage_t *buffered_io_page; xenforeignmemory_resource_handle *fres; QEMUTimer *buffered_io_timer; @@ -125,14 +130,8 @@ typedef struct XenIOState { MemoryListener io_listener; QLIST_HEAD(, XenPciDevice) dev_list; DeviceListener device_listener; - hwaddr free_phys_offset; - const XenPhysmap *log_for_dirtybit; - /* Buffer used by xen_sync_dirty_bitmap */ - unsigned long *dirty_bitmap; =20 Notifier exit; - Notifier suspend; - Notifier wakeup; } XenIOState; =20 /* Xen specific function for piix pci */ @@ -462,10 +461,10 @@ static int xen_remove_from_physmap(XenIOState *state, } =20 QLIST_REMOVE(physmap, list); - if (state->log_for_dirtybit =3D=3D physmap) { - state->log_for_dirtybit =3D NULL; - g_free(state->dirty_bitmap); - state->dirty_bitmap =3D NULL; + if (log_for_dirtybit =3D=3D physmap) { + log_for_dirtybit =3D NULL; + g_free(dirty_bitmap); + dirty_bitmap =3D NULL; } g_free(physmap); =20 @@ -626,16 +625,16 @@ static void xen_sync_dirty_bitmap(XenIOState *state, return; } =20 - if (state->log_for_dirtybit =3D=3D NULL) { - state->log_for_dirtybit =3D physmap; - state->dirty_bitmap =3D g_new(unsigned long, bitmap_size); - } else if (state->log_for_dirtybit !=3D physmap) { + if (log_for_dirtybit =3D=3D NULL) { + log_for_dirtybit =3D physmap; + dirty_bitmap =3D g_new(unsigned long, bitmap_size); + } else if (log_for_dirtybit !=3D physmap) { /* Only one range for dirty bitmap can be tracked. */ return; } =20 rc =3D xen_track_dirty_vram(xen_domid, start_addr >> TARGET_PAGE_BITS, - npages, state->dirty_bitmap); + npages, dirty_bitmap); if (rc < 0) { #ifndef ENODATA #define ENODATA ENOENT @@ -650,7 +649,7 @@ static void xen_sync_dirty_bitmap(XenIOState *state, } =20 for (i =3D 0; i < bitmap_size; i++) { - unsigned long map =3D state->dirty_bitmap[i]; + unsigned long map =3D dirty_bitmap[i]; while (map !=3D 0) { j =3D ctzl(map); map &=3D ~(1ul << j); @@ -676,12 +675,10 @@ static void xen_log_start(MemoryListener *listener, static void xen_log_stop(MemoryListener *listener, MemoryRegionSection *se= ction, int old, int new) { - XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); - if (old & ~new & (1 << DIRTY_MEMORY_VGA)) { - state->log_for_dirtybit =3D NULL; - g_free(state->dirty_bitmap); - state->dirty_bitmap =3D NULL; + log_for_dirtybit =3D NULL; + g_free(dirty_bitmap); + dirty_bitmap =3D NULL; /* Disable dirty bit tracking */ xen_track_dirty_vram(xen_domid, 0, 0, NULL); } @@ -1021,9 +1018,9 @@ static void handle_vmport_ioreq(XenIOState *state, io= req_t *req) { vmware_regs_t *vmport_regs; =20 - assert(state->shared_vmport_page); + assert(shared_vmport_page); vmport_regs =3D - &state->shared_vmport_page->vcpu_vmport_regs[state->send_vcpu]; + &shared_vmport_page->vcpu_vmport_regs[state->send_vcpu]; QEMU_BUILD_BUG_ON(sizeof(*req) < sizeof(*vmport_regs)); =20 current_cpu =3D state->cpu_by_vcpu_id[state->send_vcpu]; @@ -1468,7 +1465,6 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryRegi= on **ram_memory) =20 state->memory_listener =3D xen_memory_listener; memory_listener_register(&state->memory_listener, &address_space_memor= y); - state->log_for_dirtybit =3D NULL; =20 state->io_listener =3D xen_io_listener; memory_listener_register(&state->io_listener, &address_space_io); @@ -1489,19 +1485,19 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryRe= gion **ram_memory) QLIST_INIT(&xen_physmap); xen_read_physmap(state); =20 - state->suspend.notify =3D xen_suspend_notifier; - qemu_register_suspend_notifier(&state->suspend); + suspend.notify =3D xen_suspend_notifier; + qemu_register_suspend_notifier(&suspend); =20 - state->wakeup.notify =3D xen_wakeup_notifier; - qemu_register_wakeup_notifier(&state->wakeup); + wakeup.notify =3D xen_wakeup_notifier; + qemu_register_wakeup_notifier(&wakeup); =20 rc =3D xen_get_vmport_regs_pfn(xen_xc, xen_domid, &ioreq_pfn); if (!rc) { DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn); - state->shared_vmport_page =3D + shared_vmport_page =3D xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE, 1, &ioreq_pfn, NULL); - if (state->shared_vmport_page =3D=3D NULL) { + if (shared_vmport_page =3D=3D NULL) { error_report("map shared vmport IO page returned error %d hand= le=3D%p", errno, xen_xc); goto err; --=20 2.25.1 From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418275; cv=none; d=zohomail.com; s=zohoarc; b=WJjBMO8wBPucSxBuP3h2jTJHmX7zStP8KXyvEESt2t7v15uv8y82ZGLoRS6suM/TOiFnEFJdj3JPrnIILqQ7HVxc2v9ZuVa69vu7Z46AIU2WY2TeP9Uc+NBd+/oh6ySGfZk1Zq3rx4JLu4vg6xfasEtoSpGusBb2jTot+HLPSdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418275; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DXKXePiVp4/+LMQ/DyCg1ypJtS9EhepwrgDpinj4oew=; b=F3Qd+Uqsg8LeB+kyfHeuL7WvLxKAErpTcVNX0EpYzv38WsI1ORL1tW/Wpdy9m2iVQnn/jBw1ImhMRMai927eP3FxlZiNYU7aPnzj7GIkp63fHGHbiomeRvY2eOUYYjoYxqfpI5VmYXK2N1SYXULQ8lJ7PhW8G05hPAUnqnN8kpk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418275677246.41994705583886; Tue, 14 Feb 2023 15:44:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xh-0005M3-0b; Tue, 14 Feb 2023 18:43:49 -0500 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 1pS4xc-0005KW-A7 for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:45 -0500 Received: from ams.source.kernel.org ([145.40.68.75]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xX-0003ks-V0 for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:44 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E3B30B81F5C; Tue, 14 Feb 2023 23:43:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD9EDC4339E; Tue, 14 Feb 2023 23:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418216; bh=YbqmxJrGpbchH+jFUQjLheZgyQ1vKIx5Mb6TVzDupS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oe3gmonS/vdtMbhA4xrtmrWJJ67prCQV1bUtZjnT42giGNuWjpzvMMa0NYKTUoUVw fUhmm3PlZ+VcmANaus+gX2ItJXF2ebYvAOQgeRUdgQTTPq2B1PDSPfJ8J/U7QhQbf/ NMRiBX99ka/C4jbuSd8onJYg3NEtRwLPbyOksP7mZQ+ueTYf858058J+ljAJNaNWq2 lgki2jMtDgbU7ggYtt6+gIGEs1Zk2w1hlZ8GFGK40evdrpNds2k6MUyHyfooXXI1vQ 0JPfujDqKSc90PHy1UL1ewvAOqGf4RnzzsmDTRP/poqUfMcAsNUk5vI4M1FRIRWxF6 YJJ2zNwkMP4bg== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Stefano Stabellini , Vikram Garhwal , Paul Durrant Subject: [PULL v2 04/10] xen-hvm: reorganize xen-hvm and move common function to xen-hvm-common Date: Tue, 14 Feb 2023 15:43:24 -0800 Message-Id: <20230214234330.2107879-4-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=145.40.68.75; envelope-from=sstabellini@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418276290100002 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini This patch does following: 1. creates arch_handle_ioreq() and arch_xen_set_memory(). This is done in preparation for moving most of xen-hvm code to an arch-neutral location, move the x86-specific portion of xen_set_memory to arch_xen_set_memory. Also, move handle_vmport_ioreq to arch_handle_ioreq. 2. Pure code movement: move common functions to hw/xen/xen-hvm-common.c Extract common functionalities from hw/i386/xen/xen-hvm.c and move them= to hw/xen/xen-hvm-common.c. These common functions are useful for creating an IOREQ server. xen_hvm_init_pc() contains the architecture independent code for creati= ng and mapping a IOREQ server, connecting memory and IO listeners, initial= izing a xen bus and registering backends. Moved this common xen code to a new function xen_register_ioreq() which can be used by both x86 and ARM mac= hines. Following functions are moved to hw/xen/xen-hvm-common.c: xen_vcpu_eport(), xen_vcpu_ioreq(), xen_ram_alloc(), xen_set_memory= (), xen_region_add(), xen_region_del(), xen_io_add(), xen_io_del(), xen_device_realize(), xen_device_unrealize(), cpu_get_ioreq_from_shared_memory(), cpu_get_ioreq(), do_inp(), do_outp(), rw_phys_req_item(), read_phys_req_item(), write_phys_req_item(), cpu_ioreq_pio(), cpu_ioreq_move(), cpu_ioreq_config(), handle_ioreq(), handle_buffered_iopage(), handle_buffered_io(), cpu_handle_ioreq(), xen_main_loop_prepare(), xen_hvm_change_state_handler(), xen_exit_notifier(), xen_map_ioreq_server(), destroy_hvm_domain() and xen_shutdown_fatal_error() 3. Removed static type from below functions: 1. xen_region_add() 2. xen_region_del() 3. xen_io_add() 4. xen_io_del() 5. xen_device_realize() 6. xen_device_unrealize() 7. xen_hvm_change_state_handler() 8. cpu_ioreq_pio() 9. xen_exit_notifier() 4. Replace TARGET_PAGE_SIZE with XC_PAGE_SIZE to match the page side with X= en. Signed-off-by: Vikram Garhwal Signed-off-by: Stefano Stabellini Reviewed-by: Stefano Stabellini Reviewed-by: Paul Durrant --- hw/i386/xen/trace-events | 14 - hw/i386/xen/xen-hvm.c | 1019 ++----------------------------- hw/xen/meson.build | 5 +- hw/xen/trace-events | 14 + hw/xen/xen-hvm-common.c | 874 ++++++++++++++++++++++++++ include/hw/i386/xen_arch_hvm.h | 11 + include/hw/xen/arch_hvm.h | 3 + include/hw/xen/xen-hvm-common.h | 98 +++ 8 files changed, 1067 insertions(+), 971 deletions(-) create mode 100644 hw/xen/xen-hvm-common.c create mode 100644 include/hw/i386/xen_arch_hvm.h create mode 100644 include/hw/xen/arch_hvm.h create mode 100644 include/hw/xen/xen-hvm-common.h diff --git a/hw/i386/xen/trace-events b/hw/i386/xen/trace-events index a0c89d91c4..5d0a8d6dcf 100644 --- a/hw/i386/xen/trace-events +++ b/hw/i386/xen/trace-events @@ -7,17 +7,3 @@ xen_platform_log(char *s) "xen platform: %s" xen_pv_mmio_read(uint64_t addr) "WARNING: read from Xen PV Device MMIO spa= ce (address 0x%"PRIx64")" xen_pv_mmio_write(uint64_t addr) "WARNING: write to Xen PV Device MMIO spa= ce (address 0x%"PRIx64")" =20 -# xen-hvm.c -xen_ram_alloc(unsigned long ram_addr, unsigned long size) "requested: 0x%l= x, size 0x%lx" -xen_client_set_memory(uint64_t start_addr, unsigned long size, bool log_di= rty) "0x%"PRIx64" size 0x%lx, log_dirty %i" -handle_ioreq(void *req, uint32_t type, uint32_t dir, uint32_t df, uint32_t= data_is_ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) = "I/O=3D%p type=3D%d dir=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%= "PRIx64" count=3D%d size=3D%d" -handle_ioreq_read(void *req, uint32_t type, uint32_t df, uint32_t data_is_= ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=3D%p= read type=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%"PRIx64" coun= t=3D%d size=3D%d" -handle_ioreq_write(void *req, uint32_t type, uint32_t df, uint32_t data_is= _ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=3D%= p write type=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%"PRIx64" co= unt=3D%d size=3D%d" -cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, = uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=3D%p pio = dir=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%"PRIx64" count=3D%d = size=3D%d" -cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t s= ize) "I/O=3D%p pio read reg data=3D0x%"PRIx64" port=3D0x%"PRIx64" size=3D%d" -cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t = size) "I/O=3D%p pio write reg data=3D0x%"PRIx64" port=3D0x%"PRIx64" size=3D= %d" -cpu_ioreq_move(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr,= uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=3D%p cop= y dir=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%"PRIx64" count=3D%= d size=3D%d" -xen_map_resource_ioreq(uint32_t id, void *addr) "id: %u addr: %p" -cpu_ioreq_config_read(void *req, uint32_t sbdf, uint32_t reg, uint32_t siz= e, uint32_t data) "I/O=3D%p sbdf=3D0x%x reg=3D%u size=3D%u data=3D0x%x" -cpu_ioreq_config_write(void *req, uint32_t sbdf, uint32_t reg, uint32_t si= ze, uint32_t data) "I/O=3D%p sbdf=3D0x%x reg=3D%u size=3D%u data=3D0x%x" - diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 06c446e7be..4219308caf 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -10,43 +10,21 @@ =20 #include "qemu/osdep.h" #include "qemu/units.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-migration.h" +#include "trace.h" =20 -#include "cpu.h" -#include "hw/pci/pci.h" -#include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "hw/irq.h" -#include "hw/hw.h" #include "hw/i386/apic-msidef.h" -#include "hw/xen/xen_common.h" -#include "hw/xen/xen-legacy-backend.h" -#include "hw/xen/xen-bus.h" #include "hw/xen/xen-x86.h" -#include "qapi/error.h" -#include "qapi/qapi-commands-migration.h" -#include "qemu/error-report.h" -#include "qemu/main-loop.h" #include "qemu/range.h" -#include "sysemu/runstate.h" -#include "sysemu/sysemu.h" -#include "sysemu/xen.h" -#include "sysemu/xen-mapcache.h" -#include "trace.h" =20 -#include +#include "hw/xen/xen-hvm-common.h" +#include "hw/xen/arch_hvm.h" #include =20 -//#define DEBUG_XEN_HVM - -#ifdef DEBUG_XEN_HVM -#define DPRINTF(fmt, ...) \ - do { fprintf(stderr, "xen: " fmt, ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) \ - do { } while (0) -#endif - -static MemoryRegion ram_memory, ram_640k, ram_lo, ram_hi; +static MemoryRegion ram_640k, ram_lo, ram_hi; static MemoryRegion *framebuffer; static bool xen_in_migration; =20 @@ -73,27 +51,8 @@ struct shared_vmport_iopage { }; typedef struct shared_vmport_iopage shared_vmport_iopage_t; #endif -static shared_vmport_iopage_t *shared_vmport_page; =20 -static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i) -{ - return shared_page->vcpu_ioreq[i].vp_eport; -} -static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vc= pu) -{ - return &shared_page->vcpu_ioreq[vcpu]; -} - -#define BUFFER_IO_MAX_DELAY 100 - -typedef struct XenPhysmap { - hwaddr start_addr; - ram_addr_t size; - const char *name; - hwaddr phys_offset; - - QLIST_ENTRY(XenPhysmap) list; -} XenPhysmap; +static shared_vmport_iopage_t *shared_vmport_page; =20 static QLIST_HEAD(, XenPhysmap) xen_physmap; static const XenPhysmap *log_for_dirtybit; @@ -102,38 +61,6 @@ static unsigned long *dirty_bitmap; static Notifier suspend; static Notifier wakeup; =20 -typedef struct XenPciDevice { - PCIDevice *pci_dev; - uint32_t sbdf; - QLIST_ENTRY(XenPciDevice) entry; -} XenPciDevice; - -typedef struct XenIOState { - ioservid_t ioservid; - shared_iopage_t *shared_page; - buffered_iopage_t *buffered_io_page; - xenforeignmemory_resource_handle *fres; - QEMUTimer *buffered_io_timer; - CPUState **cpu_by_vcpu_id; - /* the evtchn port for polling the notification, */ - evtchn_port_t *ioreq_local_port; - /* evtchn remote and local ports for buffered io */ - evtchn_port_t bufioreq_remote_port; - evtchn_port_t bufioreq_local_port; - /* the evtchn fd for polling */ - xenevtchn_handle *xce_handle; - /* which vcpu we are serving */ - int send_vcpu; - - struct xs_handle *xenstore; - MemoryListener memory_listener; - MemoryListener io_listener; - QLIST_HEAD(, XenPciDevice) dev_list; - DeviceListener device_listener; - - Notifier exit; -} XenIOState; - /* Xen specific function for piix pci */ =20 int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num) @@ -246,42 +173,6 @@ static void xen_ram_init(PCMachineState *pcms, } } =20 -void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, - Error **errp) -{ - unsigned long nr_pfn; - xen_pfn_t *pfn_list; - int i; - - if (runstate_check(RUN_STATE_INMIGRATE)) { - /* RAM already populated in Xen */ - fprintf(stderr, "%s: do not alloc "RAM_ADDR_FMT - " bytes of ram at "RAM_ADDR_FMT" when runstate is INMIGRAT= E\n", - __func__, size, ram_addr); - return; - } - - if (mr =3D=3D &ram_memory) { - return; - } - - trace_xen_ram_alloc(ram_addr, size); - - nr_pfn =3D size >> TARGET_PAGE_BITS; - pfn_list =3D g_malloc(sizeof (*pfn_list) * nr_pfn); - - for (i =3D 0; i < nr_pfn; i++) { - pfn_list[i] =3D (ram_addr >> TARGET_PAGE_BITS) + i; - } - - if (xc_domain_populate_physmap_exact(xen_xc, xen_domid, nr_pfn, 0, 0, = pfn_list)) { - error_setg(errp, "xen: failed to populate ram at " RAM_ADDR_FMT, - ram_addr); - } - - g_free(pfn_list); -} - static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size) { XenPhysmap *physmap =3D NULL; @@ -471,144 +362,6 @@ static int xen_remove_from_physmap(XenIOState *state, return 0; } =20 -static void xen_set_memory(struct MemoryListener *listener, - MemoryRegionSection *section, - bool add) -{ - XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); - hwaddr start_addr =3D section->offset_within_address_space; - ram_addr_t size =3D int128_get64(section->size); - bool log_dirty =3D memory_region_is_logging(section->mr, DIRTY_MEMORY_= VGA); - hvmmem_type_t mem_type; - - if (section->mr =3D=3D &ram_memory) { - return; - } else { - if (add) { - xen_map_memory_section(xen_domid, state->ioservid, - section); - } else { - xen_unmap_memory_section(xen_domid, state->ioservid, - section); - } - } - - if (!memory_region_is_ram(section->mr)) { - return; - } - - if (log_dirty !=3D add) { - return; - } - - trace_xen_client_set_memory(start_addr, size, log_dirty); - - start_addr &=3D TARGET_PAGE_MASK; - size =3D TARGET_PAGE_ALIGN(size); - - if (add) { - if (!memory_region_is_rom(section->mr)) { - xen_add_to_physmap(state, start_addr, size, - section->mr, section->offset_within_region); - } else { - mem_type =3D HVMMEM_ram_ro; - if (xen_set_mem_type(xen_domid, mem_type, - start_addr >> TARGET_PAGE_BITS, - size >> TARGET_PAGE_BITS)) { - DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n", - start_addr); - } - } - } else { - if (xen_remove_from_physmap(state, start_addr, size) < 0) { - DPRINTF("physmapping does not exist at "HWADDR_FMT_plx"\n", st= art_addr); - } - } -} - -static void xen_region_add(MemoryListener *listener, - MemoryRegionSection *section) -{ - memory_region_ref(section->mr); - xen_set_memory(listener, section, true); -} - -static void xen_region_del(MemoryListener *listener, - MemoryRegionSection *section) -{ - xen_set_memory(listener, section, false); - memory_region_unref(section->mr); -} - -static void xen_io_add(MemoryListener *listener, - MemoryRegionSection *section) -{ - XenIOState *state =3D container_of(listener, XenIOState, io_listener); - MemoryRegion *mr =3D section->mr; - - if (mr->ops =3D=3D &unassigned_io_ops) { - return; - } - - memory_region_ref(mr); - - xen_map_io_section(xen_domid, state->ioservid, section); -} - -static void xen_io_del(MemoryListener *listener, - MemoryRegionSection *section) -{ - XenIOState *state =3D container_of(listener, XenIOState, io_listener); - MemoryRegion *mr =3D section->mr; - - if (mr->ops =3D=3D &unassigned_io_ops) { - return; - } - - xen_unmap_io_section(xen_domid, state->ioservid, section); - - memory_region_unref(mr); -} - -static void xen_device_realize(DeviceListener *listener, - DeviceState *dev) -{ - XenIOState *state =3D container_of(listener, XenIOState, device_listen= er); - - if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { - PCIDevice *pci_dev =3D PCI_DEVICE(dev); - XenPciDevice *xendev =3D g_new(XenPciDevice, 1); - - xendev->pci_dev =3D pci_dev; - xendev->sbdf =3D PCI_BUILD_BDF(pci_dev_bus_num(pci_dev), - pci_dev->devfn); - QLIST_INSERT_HEAD(&state->dev_list, xendev, entry); - - xen_map_pcidev(xen_domid, state->ioservid, pci_dev); - } -} - -static void xen_device_unrealize(DeviceListener *listener, - DeviceState *dev) -{ - XenIOState *state =3D container_of(listener, XenIOState, device_listen= er); - - if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { - PCIDevice *pci_dev =3D PCI_DEVICE(dev); - XenPciDevice *xendev, *next; - - xen_unmap_pcidev(xen_domid, state->ioservid, pci_dev); - - QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { - if (xendev->pci_dev =3D=3D pci_dev) { - QLIST_REMOVE(xendev, entry); - g_free(xendev); - break; - } - } - } -} - static void xen_sync_dirty_bitmap(XenIOState *state, hwaddr start_addr, ram_addr_t size) @@ -716,277 +469,6 @@ static MemoryListener xen_memory_listener =3D { .priority =3D 10, }; =20 -static MemoryListener xen_io_listener =3D { - .name =3D "xen-io", - .region_add =3D xen_io_add, - .region_del =3D xen_io_del, - .priority =3D 10, -}; - -static DeviceListener xen_device_listener =3D { - .realize =3D xen_device_realize, - .unrealize =3D xen_device_unrealize, -}; - -/* get the ioreq packets from share mem */ -static ioreq_t *cpu_get_ioreq_from_shared_memory(XenIOState *state, int vc= pu) -{ - ioreq_t *req =3D xen_vcpu_ioreq(state->shared_page, vcpu); - - if (req->state !=3D STATE_IOREQ_READY) { - DPRINTF("I/O request not ready: " - "%x, ptr: %x, port: %"PRIx64", " - "data: %"PRIx64", count: %u, size: %u\n", - req->state, req->data_is_ptr, req->addr, - req->data, req->count, req->size); - return NULL; - } - - xen_rmb(); /* see IOREQ_READY /then/ read contents of ioreq */ - - req->state =3D STATE_IOREQ_INPROCESS; - return req; -} - -/* use poll to get the port notification */ -/* ioreq_vec--out,the */ -/* retval--the number of ioreq packet */ -static ioreq_t *cpu_get_ioreq(XenIOState *state) -{ - MachineState *ms =3D MACHINE(qdev_get_machine()); - unsigned int max_cpus =3D ms->smp.max_cpus; - int i; - evtchn_port_t port; - - port =3D xenevtchn_pending(state->xce_handle); - if (port =3D=3D state->bufioreq_local_port) { - timer_mod(state->buffered_io_timer, - BUFFER_IO_MAX_DELAY + qemu_clock_get_ms(QEMU_CLOCK_REALTIM= E)); - return NULL; - } - - if (port !=3D -1) { - for (i =3D 0; i < max_cpus; i++) { - if (state->ioreq_local_port[i] =3D=3D port) { - break; - } - } - - if (i =3D=3D max_cpus) { - hw_error("Fatal error while trying to get io event!\n"); - } - - /* unmask the wanted port again */ - xenevtchn_unmask(state->xce_handle, port); - - /* get the io packet from shared memory */ - state->send_vcpu =3D i; - return cpu_get_ioreq_from_shared_memory(state, i); - } - - /* read error or read nothing */ - return NULL; -} - -static uint32_t do_inp(uint32_t addr, unsigned long size) -{ - switch (size) { - case 1: - return cpu_inb(addr); - case 2: - return cpu_inw(addr); - case 4: - return cpu_inl(addr); - default: - hw_error("inp: bad size: %04x %lx", addr, size); - } -} - -static void do_outp(uint32_t addr, - unsigned long size, uint32_t val) -{ - switch (size) { - case 1: - return cpu_outb(addr, val); - case 2: - return cpu_outw(addr, val); - case 4: - return cpu_outl(addr, val); - default: - hw_error("outp: bad size: %04x %lx", addr, size); - } -} - -/* - * Helper functions which read/write an object from/to physical guest - * memory, as part of the implementation of an ioreq. - * - * Equivalent to - * cpu_physical_memory_rw(addr + (req->df ? -1 : +1) * req->size * i, - * val, req->size, 0/1) - * except without the integer overflow problems. - */ -static void rw_phys_req_item(hwaddr addr, - ioreq_t *req, uint32_t i, void *val, int rw) -{ - /* Do everything unsigned so overflow just results in a truncated resu= lt - * and accesses to undesired parts of guest memory, which is up - * to the guest */ - hwaddr offset =3D (hwaddr)req->size * i; - if (req->df) { - addr -=3D offset; - } else { - addr +=3D offset; - } - cpu_physical_memory_rw(addr, val, req->size, rw); -} - -static inline void read_phys_req_item(hwaddr addr, - ioreq_t *req, uint32_t i, void *val) -{ - rw_phys_req_item(addr, req, i, val, 0); -} -static inline void write_phys_req_item(hwaddr addr, - ioreq_t *req, uint32_t i, void *val) -{ - rw_phys_req_item(addr, req, i, val, 1); -} - - -static void cpu_ioreq_pio(ioreq_t *req) -{ - uint32_t i; - - trace_cpu_ioreq_pio(req, req->dir, req->df, req->data_is_ptr, req->add= r, - req->data, req->count, req->size); - - if (req->size > sizeof(uint32_t)) { - hw_error("PIO: bad size (%u)", req->size); - } - - if (req->dir =3D=3D IOREQ_READ) { - if (!req->data_is_ptr) { - req->data =3D do_inp(req->addr, req->size); - trace_cpu_ioreq_pio_read_reg(req, req->data, req->addr, - req->size); - } else { - uint32_t tmp; - - for (i =3D 0; i < req->count; i++) { - tmp =3D do_inp(req->addr, req->size); - write_phys_req_item(req->data, req, i, &tmp); - } - } - } else if (req->dir =3D=3D IOREQ_WRITE) { - if (!req->data_is_ptr) { - trace_cpu_ioreq_pio_write_reg(req, req->data, req->addr, - req->size); - do_outp(req->addr, req->size, req->data); - } else { - for (i =3D 0; i < req->count; i++) { - uint32_t tmp =3D 0; - - read_phys_req_item(req->data, req, i, &tmp); - do_outp(req->addr, req->size, tmp); - } - } - } -} - -static void cpu_ioreq_move(ioreq_t *req) -{ - uint32_t i; - - trace_cpu_ioreq_move(req, req->dir, req->df, req->data_is_ptr, req->ad= dr, - req->data, req->count, req->size); - - if (req->size > sizeof(req->data)) { - hw_error("MMIO: bad size (%u)", req->size); - } - - if (!req->data_is_ptr) { - if (req->dir =3D=3D IOREQ_READ) { - for (i =3D 0; i < req->count; i++) { - read_phys_req_item(req->addr, req, i, &req->data); - } - } else if (req->dir =3D=3D IOREQ_WRITE) { - for (i =3D 0; i < req->count; i++) { - write_phys_req_item(req->addr, req, i, &req->data); - } - } - } else { - uint64_t tmp; - - if (req->dir =3D=3D IOREQ_READ) { - for (i =3D 0; i < req->count; i++) { - read_phys_req_item(req->addr, req, i, &tmp); - write_phys_req_item(req->data, req, i, &tmp); - } - } else if (req->dir =3D=3D IOREQ_WRITE) { - for (i =3D 0; i < req->count; i++) { - read_phys_req_item(req->data, req, i, &tmp); - write_phys_req_item(req->addr, req, i, &tmp); - } - } - } -} - -static void cpu_ioreq_config(XenIOState *state, ioreq_t *req) -{ - uint32_t sbdf =3D req->addr >> 32; - uint32_t reg =3D req->addr; - XenPciDevice *xendev; - - if (req->size !=3D sizeof(uint8_t) && req->size !=3D sizeof(uint16_t) = && - req->size !=3D sizeof(uint32_t)) { - hw_error("PCI config access: bad size (%u)", req->size); - } - - if (req->count !=3D 1) { - hw_error("PCI config access: bad count (%u)", req->count); - } - - QLIST_FOREACH(xendev, &state->dev_list, entry) { - if (xendev->sbdf !=3D sbdf) { - continue; - } - - if (!req->data_is_ptr) { - if (req->dir =3D=3D IOREQ_READ) { - req->data =3D pci_host_config_read_common( - xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE, - req->size); - trace_cpu_ioreq_config_read(req, xendev->sbdf, reg, - req->size, req->data); - } else if (req->dir =3D=3D IOREQ_WRITE) { - trace_cpu_ioreq_config_write(req, xendev->sbdf, reg, - req->size, req->data); - pci_host_config_write_common( - xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE, - req->data, req->size); - } - } else { - uint32_t tmp; - - if (req->dir =3D=3D IOREQ_READ) { - tmp =3D pci_host_config_read_common( - xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE, - req->size); - trace_cpu_ioreq_config_read(req, xendev->sbdf, reg, - req->size, tmp); - write_phys_req_item(req->data, req, 0, &tmp); - } else if (req->dir =3D=3D IOREQ_WRITE) { - read_phys_req_item(req->data, req, 0, &tmp); - trace_cpu_ioreq_config_write(req, xendev->sbdf, reg, - req->size, tmp); - pci_host_config_write_common( - xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE, - tmp, req->size); - } - } - } -} - static void regs_to_cpu(vmware_regs_t *vmport_regs, ioreq_t *req) { X86CPU *cpu; @@ -1030,226 +512,6 @@ static void handle_vmport_ioreq(XenIOState *state, i= oreq_t *req) current_cpu =3D NULL; } =20 -static void handle_ioreq(XenIOState *state, ioreq_t *req) -{ - trace_handle_ioreq(req, req->type, req->dir, req->df, req->data_is_ptr, - req->addr, req->data, req->count, req->size); - - if (!req->data_is_ptr && (req->dir =3D=3D IOREQ_WRITE) && - (req->size < sizeof (target_ulong))) { - req->data &=3D ((target_ulong) 1 << (8 * req->size)) - 1; - } - - if (req->dir =3D=3D IOREQ_WRITE) - trace_handle_ioreq_write(req, req->type, req->df, req->data_is_ptr, - req->addr, req->data, req->count, req->si= ze); - - switch (req->type) { - case IOREQ_TYPE_PIO: - cpu_ioreq_pio(req); - break; - case IOREQ_TYPE_COPY: - cpu_ioreq_move(req); - break; - case IOREQ_TYPE_VMWARE_PORT: - handle_vmport_ioreq(state, req); - break; - case IOREQ_TYPE_TIMEOFFSET: - break; - case IOREQ_TYPE_INVALIDATE: - xen_invalidate_map_cache(); - break; - case IOREQ_TYPE_PCI_CONFIG: - cpu_ioreq_config(state, req); - break; - default: - hw_error("Invalid ioreq type 0x%x\n", req->type); - } - if (req->dir =3D=3D IOREQ_READ) { - trace_handle_ioreq_read(req, req->type, req->df, req->data_is_ptr, - req->addr, req->data, req->count, req->siz= e); - } -} - -static bool handle_buffered_iopage(XenIOState *state) -{ - buffered_iopage_t *buf_page =3D state->buffered_io_page; - buf_ioreq_t *buf_req =3D NULL; - bool handled_ioreq =3D false; - ioreq_t req; - int qw; - - if (!buf_page) { - return 0; - } - - memset(&req, 0x00, sizeof(req)); - req.state =3D STATE_IOREQ_READY; - req.count =3D 1; - req.dir =3D IOREQ_WRITE; - - for (;;) { - uint32_t rdptr =3D buf_page->read_pointer, wrptr; - - xen_rmb(); - wrptr =3D buf_page->write_pointer; - xen_rmb(); - if (rdptr !=3D buf_page->read_pointer) { - continue; - } - if (rdptr =3D=3D wrptr) { - break; - } - buf_req =3D &buf_page->buf_ioreq[rdptr % IOREQ_BUFFER_SLOT_NUM]; - req.size =3D 1U << buf_req->size; - req.addr =3D buf_req->addr; - req.data =3D buf_req->data; - req.type =3D buf_req->type; - xen_rmb(); - qw =3D (req.size =3D=3D 8); - if (qw) { - if (rdptr + 1 =3D=3D wrptr) { - hw_error("Incomplete quad word buffered ioreq"); - } - buf_req =3D &buf_page->buf_ioreq[(rdptr + 1) % - IOREQ_BUFFER_SLOT_NUM]; - req.data |=3D ((uint64_t)buf_req->data) << 32; - xen_rmb(); - } - - handle_ioreq(state, &req); - - /* Only req.data may get updated by handle_ioreq(), albeit even th= at - * should not happen as such data would never make it to the guest= (we - * can only usefully see writes here after all). - */ - assert(req.state =3D=3D STATE_IOREQ_READY); - assert(req.count =3D=3D 1); - assert(req.dir =3D=3D IOREQ_WRITE); - assert(!req.data_is_ptr); - - qatomic_add(&buf_page->read_pointer, qw + 1); - handled_ioreq =3D true; - } - - return handled_ioreq; -} - -static void handle_buffered_io(void *opaque) -{ - XenIOState *state =3D opaque; - - if (handle_buffered_iopage(state)) { - timer_mod(state->buffered_io_timer, - BUFFER_IO_MAX_DELAY + qemu_clock_get_ms(QEMU_CLOCK_REALTIM= E)); - } else { - timer_del(state->buffered_io_timer); - xenevtchn_unmask(state->xce_handle, state->bufioreq_local_port); - } -} - -static void cpu_handle_ioreq(void *opaque) -{ - XenIOState *state =3D opaque; - ioreq_t *req =3D cpu_get_ioreq(state); - - handle_buffered_iopage(state); - if (req) { - ioreq_t copy =3D *req; - - xen_rmb(); - handle_ioreq(state, ©); - req->data =3D copy.data; - - if (req->state !=3D STATE_IOREQ_INPROCESS) { - fprintf(stderr, "Badness in I/O request ... not in service?!: " - "%x, ptr: %x, port: %"PRIx64", " - "data: %"PRIx64", count: %u, size: %u, type: %u\n", - req->state, req->data_is_ptr, req->addr, - req->data, req->count, req->size, req->type); - destroy_hvm_domain(false); - return; - } - - xen_wmb(); /* Update ioreq contents /then/ update state. */ - - /* - * We do this before we send the response so that the tools - * have the opportunity to pick up on the reset before the - * guest resumes and does a hlt with interrupts disabled which - * causes Xen to powerdown the domain. - */ - if (runstate_is_running()) { - ShutdownCause request; - - if (qemu_shutdown_requested_get()) { - destroy_hvm_domain(false); - } - request =3D qemu_reset_requested_get(); - if (request) { - qemu_system_reset(request); - destroy_hvm_domain(true); - } - } - - req->state =3D STATE_IORESP_READY; - xenevtchn_notify(state->xce_handle, - state->ioreq_local_port[state->send_vcpu]); - } -} - -static void xen_main_loop_prepare(XenIOState *state) -{ - int evtchn_fd =3D -1; - - if (state->xce_handle !=3D NULL) { - evtchn_fd =3D xenevtchn_fd(state->xce_handle); - } - - state->buffered_io_timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, handle_= buffered_io, - state); - - if (evtchn_fd !=3D -1) { - CPUState *cpu_state; - - DPRINTF("%s: Init cpu_by_vcpu_id\n", __func__); - CPU_FOREACH(cpu_state) { - DPRINTF("%s: cpu_by_vcpu_id[%d]=3D%p\n", - __func__, cpu_state->cpu_index, cpu_state); - state->cpu_by_vcpu_id[cpu_state->cpu_index] =3D cpu_state; - } - qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, state); - } -} - - -static void xen_hvm_change_state_handler(void *opaque, bool running, - RunState rstate) -{ - XenIOState *state =3D opaque; - - if (running) { - xen_main_loop_prepare(state); - } - - xen_set_ioreq_server_state(xen_domid, - state->ioservid, - (rstate =3D=3D RUN_STATE_RUNNING)); -} - -static void xen_exit_notifier(Notifier *n, void *data) -{ - XenIOState *state =3D container_of(n, XenIOState, exit); - - xen_destroy_ioreq_server(xen_domid, state->ioservid); - if (state->fres !=3D NULL) { - xenforeignmemory_unmap_resource(xen_fmem, state->fres); - } - - xenevtchn_close(state->xce_handle); - xs_daemon_close(state->xenstore); -} - #ifdef XEN_COMPAT_PHYSMAP static void xen_read_physmap(XenIOState *state) { @@ -1309,178 +571,17 @@ static void xen_wakeup_notifier(Notifier *notifier,= void *data) xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); } =20 -static int xen_map_ioreq_server(XenIOState *state) -{ - void *addr =3D NULL; - xen_pfn_t ioreq_pfn; - xen_pfn_t bufioreq_pfn; - evtchn_port_t bufioreq_evtchn; - int rc; - - /* - * Attempt to map using the resource API and fall back to normal - * foreign mapping if this is not supported. - */ - QEMU_BUILD_BUG_ON(XENMEM_resource_ioreq_server_frame_bufioreq !=3D 0); - QEMU_BUILD_BUG_ON(XENMEM_resource_ioreq_server_frame_ioreq(0) !=3D 1); - state->fres =3D xenforeignmemory_map_resource(xen_fmem, xen_domid, - XENMEM_resource_ioreq_server, - state->ioservid, 0, 2, - &addr, - PROT_READ | PROT_WRITE, 0); - if (state->fres !=3D NULL) { - trace_xen_map_resource_ioreq(state->ioservid, addr); - state->buffered_io_page =3D addr; - state->shared_page =3D addr + TARGET_PAGE_SIZE; - } else if (errno !=3D EOPNOTSUPP) { - error_report("failed to map ioreq server resources: error %d handl= e=3D%p", - errno, xen_xc); - return -1; - } - - rc =3D xen_get_ioreq_server_info(xen_domid, state->ioservid, - (state->shared_page =3D=3D NULL) ? - &ioreq_pfn : NULL, - (state->buffered_io_page =3D=3D NULL) ? - &bufioreq_pfn : NULL, - &bufioreq_evtchn); - if (rc < 0) { - error_report("failed to get ioreq server info: error %d handle=3D%= p", - errno, xen_xc); - return rc; - } - - if (state->shared_page =3D=3D NULL) { - DPRINTF("shared page at pfn %lx\n", ioreq_pfn); - - state->shared_page =3D xenforeignmemory_map(xen_fmem, xen_domid, - PROT_READ | PROT_WRITE, - 1, &ioreq_pfn, NULL); - if (state->shared_page =3D=3D NULL) { - error_report("map shared IO page returned error %d handle=3D%p= ", - errno, xen_xc); - } - } - - if (state->buffered_io_page =3D=3D NULL) { - DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn); - - state->buffered_io_page =3D xenforeignmemory_map(xen_fmem, xen_dom= id, - PROT_READ | PROT_WR= ITE, - 1, &bufioreq_pfn, - NULL); - if (state->buffered_io_page =3D=3D NULL) { - error_report("map buffered IO page returned error %d", errno); - return -1; - } - } - - if (state->shared_page =3D=3D NULL || state->buffered_io_page =3D=3D N= ULL) { - return -1; - } - - DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn); - - state->bufioreq_remote_port =3D bufioreq_evtchn; - - return 0; -} - void xen_hvm_init_pc(PCMachineState *pcms, MemoryRegion **ram_memory) { MachineState *ms =3D MACHINE(pcms); unsigned int max_cpus =3D ms->smp.max_cpus; - int i, rc; + int rc; xen_pfn_t ioreq_pfn; XenIOState *state; =20 state =3D g_new0(XenIOState, 1); =20 - state->xce_handle =3D xenevtchn_open(NULL, 0); - if (state->xce_handle =3D=3D NULL) { - perror("xen: event channel open"); - goto err; - } - - state->xenstore =3D xs_daemon_open(); - if (state->xenstore =3D=3D NULL) { - perror("xen: xenstore open"); - goto err; - } - - xen_create_ioreq_server(xen_domid, &state->ioservid); - - state->exit.notify =3D xen_exit_notifier; - qemu_add_exit_notifier(&state->exit); - - /* - * Register wake-up support in QMP query-current-machine API - */ - qemu_register_wakeup_support(); - - rc =3D xen_map_ioreq_server(state); - if (rc < 0) { - goto err; - } - - /* Note: cpus is empty at this point in init */ - state->cpu_by_vcpu_id =3D g_new0(CPUState *, max_cpus); - - rc =3D xen_set_ioreq_server_state(xen_domid, state->ioservid, true); - if (rc < 0) { - error_report("failed to enable ioreq server info: error %d handle= =3D%p", - errno, xen_xc); - goto err; - } - - state->ioreq_local_port =3D g_new0(evtchn_port_t, max_cpus); - - /* FIXME: how about if we overflow the page here? */ - for (i =3D 0; i < max_cpus; i++) { - rc =3D xenevtchn_bind_interdomain(state->xce_handle, xen_domid, - xen_vcpu_eport(state->shared_page,= i)); - if (rc =3D=3D -1) { - error_report("shared evtchn %d bind error %d", i, errno); - goto err; - } - state->ioreq_local_port[i] =3D rc; - } - - rc =3D xenevtchn_bind_interdomain(state->xce_handle, xen_domid, - state->bufioreq_remote_port); - if (rc =3D=3D -1) { - error_report("buffered evtchn bind error %d", errno); - goto err; - } - state->bufioreq_local_port =3D rc; - - /* Init RAM management */ -#ifdef XEN_COMPAT_PHYSMAP - xen_map_cache_init(xen_phys_offset_to_gaddr, state); -#else - xen_map_cache_init(NULL, state); -#endif - - qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state); - - state->memory_listener =3D xen_memory_listener; - memory_listener_register(&state->memory_listener, &address_space_memor= y); - - state->io_listener =3D xen_io_listener; - memory_listener_register(&state->io_listener, &address_space_io); - - state->device_listener =3D xen_device_listener; - QLIST_INIT(&state->dev_list); - device_listener_register(&state->device_listener); - - xen_bus_init(); - - /* Initialize backend core & drivers */ - if (xen_be_init() !=3D 0) { - error_report("xen backend core setup failed"); - goto err; - } - xen_be_register_common(); + xen_register_ioreq(state, max_cpus, xen_memory_listener); =20 QLIST_INIT(&xen_physmap); xen_read_physmap(state); @@ -1520,59 +621,11 @@ err: exit(1); } =20 -void destroy_hvm_domain(bool reboot) -{ - xc_interface *xc_handle; - int sts; - int rc; - - unsigned int reason =3D reboot ? SHUTDOWN_reboot : SHUTDOWN_poweroff; - - if (xen_dmod) { - rc =3D xendevicemodel_shutdown(xen_dmod, xen_domid, reason); - if (!rc) { - return; - } - if (errno !=3D ENOTTY /* old Xen */) { - perror("xendevicemodel_shutdown failed"); - } - /* well, try the old thing then */ - } - - xc_handle =3D xc_interface_open(0, 0, 0); - if (xc_handle =3D=3D NULL) { - fprintf(stderr, "Cannot acquire xenctrl handle\n"); - } else { - sts =3D xc_domain_shutdown(xc_handle, xen_domid, reason); - if (sts !=3D 0) { - fprintf(stderr, "xc_domain_shutdown failed to issue %s, " - "sts %d, %s\n", reboot ? "reboot" : "poweroff", - sts, strerror(errno)); - } else { - fprintf(stderr, "Issued domain %d %s\n", xen_domid, - reboot ? "reboot" : "poweroff"); - } - xc_interface_close(xc_handle); - } -} - void xen_register_framebuffer(MemoryRegion *mr) { framebuffer =3D mr; } =20 -void xen_shutdown_fatal_error(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "Will destroy the domain.\n"); - /* destroy the domain */ - qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_ERROR); -} - void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) { if (unlikely(xen_in_migration)) { @@ -1604,3 +657,57 @@ void qmp_xen_set_global_dirty_log(bool enable, Error = **errp) memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); } } + +void arch_xen_set_memory(XenIOState *state, MemoryRegionSection *section, + bool add) +{ + hwaddr start_addr =3D section->offset_within_address_space; + ram_addr_t size =3D int128_get64(section->size); + bool log_dirty =3D memory_region_is_logging(section->mr, DIRTY_MEMORY_= VGA); + hvmmem_type_t mem_type; + + if (!memory_region_is_ram(section->mr)) { + return; + } + + if (log_dirty !=3D add) { + return; + } + + trace_xen_client_set_memory(start_addr, size, log_dirty); + + start_addr &=3D TARGET_PAGE_MASK; + size =3D TARGET_PAGE_ALIGN(size); + + if (add) { + if (!memory_region_is_rom(section->mr)) { + xen_add_to_physmap(state, start_addr, size, + section->mr, section->offset_within_region); + } else { + mem_type =3D HVMMEM_ram_ro; + if (xen_set_mem_type(xen_domid, mem_type, + start_addr >> TARGET_PAGE_BITS, + size >> TARGET_PAGE_BITS)) { + DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n", + start_addr); + } + } + } else { + if (xen_remove_from_physmap(state, start_addr, size) < 0) { + DPRINTF("physmapping does not exist at "HWADDR_FMT_plx"\n", st= art_addr); + } + } +} + +void arch_handle_ioreq(XenIOState *state, ioreq_t *req) +{ + switch (req->type) { + case IOREQ_TYPE_VMWARE_PORT: + handle_vmport_ioreq(state, req); + break; + default: + hw_error("Invalid ioreq type 0x%x\n", req->type); + } + + return; +} diff --git a/hw/xen/meson.build b/hw/xen/meson.build index 19d0637c46..008e036d63 100644 --- a/hw/xen/meson.build +++ b/hw/xen/meson.build @@ -25,4 +25,7 @@ specific_ss.add_all(when: ['CONFIG_XEN', xen], if_true: x= en_specific_ss) =20 xen_ss =3D ss.source_set() =20 -xen_ss.add(when: 'CONFIG_XEN', if_true: files('xen-mapcache.c')) +xen_ss.add(when: 'CONFIG_XEN', if_true: files( + 'xen-mapcache.c', + 'xen-hvm-common.c', +)) diff --git a/hw/xen/trace-events b/hw/xen/trace-events index 2c8f238f42..02ca1183da 100644 --- a/hw/xen/trace-events +++ b/hw/xen/trace-events @@ -42,6 +42,20 @@ xs_node_vscanf(char *path, char *value) "%s %s" xs_node_watch(char *path) "%s" xs_node_unwatch(char *path) "%s" =20 +# xen-hvm.c +xen_ram_alloc(unsigned long ram_addr, unsigned long size) "requested: 0x%l= x, size 0x%lx" +xen_client_set_memory(uint64_t start_addr, unsigned long size, bool log_di= rty) "0x%"PRIx64" size 0x%lx, log_dirty %i" +handle_ioreq(void *req, uint32_t type, uint32_t dir, uint32_t df, uint32_t= data_is_ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) = "I/O=3D%p type=3D%d dir=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%= "PRIx64" count=3D%d size=3D%d" +handle_ioreq_read(void *req, uint32_t type, uint32_t df, uint32_t data_is_= ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=3D%p= read type=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%"PRIx64" coun= t=3D%d size=3D%d" +handle_ioreq_write(void *req, uint32_t type, uint32_t df, uint32_t data_is= _ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=3D%= p write type=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%"PRIx64" co= unt=3D%d size=3D%d" +cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, = uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=3D%p pio = dir=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%"PRIx64" count=3D%d = size=3D%d" +cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t s= ize) "I/O=3D%p pio read reg data=3D0x%"PRIx64" port=3D0x%"PRIx64" size=3D%d" +cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t = size) "I/O=3D%p pio write reg data=3D0x%"PRIx64" port=3D0x%"PRIx64" size=3D= %d" +cpu_ioreq_move(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr,= uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=3D%p cop= y dir=3D%d df=3D%d ptr=3D%d port=3D0x%"PRIx64" data=3D0x%"PRIx64" count=3D%= d size=3D%d" +xen_map_resource_ioreq(uint32_t id, void *addr) "id: %u addr: %p" +cpu_ioreq_config_read(void *req, uint32_t sbdf, uint32_t reg, uint32_t siz= e, uint32_t data) "I/O=3D%p sbdf=3D0x%x reg=3D%u size=3D%u data=3D0x%x" +cpu_ioreq_config_write(void *req, uint32_t sbdf, uint32_t reg, uint32_t si= ze, uint32_t data) "I/O=3D%p sbdf=3D0x%x reg=3D%u size=3D%u data=3D0x%x" + # xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64 xen_remap_bucket(uint64_t index) "index 0x%"PRIx64 diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c new file mode 100644 index 0000000000..c2e1e08124 --- /dev/null +++ b/hw/xen/xen-hvm-common.c @@ -0,0 +1,874 @@ +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qapi/error.h" +#include "trace.h" + +#include "hw/pci/pci_host.h" +#include "hw/xen/xen-hvm-common.h" +#include "hw/xen/xen-legacy-backend.h" +#include "hw/xen/xen-bus.h" +#include "hw/boards.h" +#include "hw/xen/arch_hvm.h" + +MemoryRegion ram_memory; + +void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, + Error **errp) +{ + unsigned long nr_pfn; + xen_pfn_t *pfn_list; + int i; + + if (runstate_check(RUN_STATE_INMIGRATE)) { + /* RAM already populated in Xen */ + fprintf(stderr, "%s: do not alloc "RAM_ADDR_FMT + " bytes of ram at "RAM_ADDR_FMT" when runstate is INMIGRAT= E\n", + __func__, size, ram_addr); + return; + } + + if (mr =3D=3D &ram_memory) { + return; + } + + trace_xen_ram_alloc(ram_addr, size); + + nr_pfn =3D size >> TARGET_PAGE_BITS; + pfn_list =3D g_malloc(sizeof (*pfn_list) * nr_pfn); + + for (i =3D 0; i < nr_pfn; i++) { + pfn_list[i] =3D (ram_addr >> TARGET_PAGE_BITS) + i; + } + + if (xc_domain_populate_physmap_exact(xen_xc, xen_domid, nr_pfn, 0, 0, = pfn_list)) { + error_setg(errp, "xen: failed to populate ram at " RAM_ADDR_FMT, + ram_addr); + } + + g_free(pfn_list); +} + +static void xen_set_memory(struct MemoryListener *listener, + MemoryRegionSection *section, + bool add) +{ + XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); + + if (section->mr =3D=3D &ram_memory) { + return; + } else { + if (add) { + xen_map_memory_section(xen_domid, state->ioservid, + section); + } else { + xen_unmap_memory_section(xen_domid, state->ioservid, + section); + } + } + + arch_xen_set_memory(state, section, add); +} + +void xen_region_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + memory_region_ref(section->mr); + xen_set_memory(listener, section, true); +} + +void xen_region_del(MemoryListener *listener, + MemoryRegionSection *section) +{ + xen_set_memory(listener, section, false); + memory_region_unref(section->mr); +} + +void xen_io_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + XenIOState *state =3D container_of(listener, XenIOState, io_listener); + MemoryRegion *mr =3D section->mr; + + if (mr->ops =3D=3D &unassigned_io_ops) { + return; + } + + memory_region_ref(mr); + + xen_map_io_section(xen_domid, state->ioservid, section); +} + +void xen_io_del(MemoryListener *listener, + MemoryRegionSection *section) +{ + XenIOState *state =3D container_of(listener, XenIOState, io_listener); + MemoryRegion *mr =3D section->mr; + + if (mr->ops =3D=3D &unassigned_io_ops) { + return; + } + + xen_unmap_io_section(xen_domid, state->ioservid, section); + + memory_region_unref(mr); +} + +void xen_device_realize(DeviceListener *listener, + DeviceState *dev) +{ + XenIOState *state =3D container_of(listener, XenIOState, device_listen= er); + + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + PCIDevice *pci_dev =3D PCI_DEVICE(dev); + XenPciDevice *xendev =3D g_new(XenPciDevice, 1); + + xendev->pci_dev =3D pci_dev; + xendev->sbdf =3D PCI_BUILD_BDF(pci_dev_bus_num(pci_dev), + pci_dev->devfn); + QLIST_INSERT_HEAD(&state->dev_list, xendev, entry); + + xen_map_pcidev(xen_domid, state->ioservid, pci_dev); + } +} + +void xen_device_unrealize(DeviceListener *listener, + DeviceState *dev) +{ + XenIOState *state =3D container_of(listener, XenIOState, device_listen= er); + + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + PCIDevice *pci_dev =3D PCI_DEVICE(dev); + XenPciDevice *xendev, *next; + + xen_unmap_pcidev(xen_domid, state->ioservid, pci_dev); + + QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { + if (xendev->pci_dev =3D=3D pci_dev) { + QLIST_REMOVE(xendev, entry); + g_free(xendev); + break; + } + } + } +} + +MemoryListener xen_io_listener =3D { + .name =3D "xen-io", + .region_add =3D xen_io_add, + .region_del =3D xen_io_del, + .priority =3D 10, +}; + +DeviceListener xen_device_listener =3D { + .realize =3D xen_device_realize, + .unrealize =3D xen_device_unrealize, +}; + +/* get the ioreq packets from share mem */ +static ioreq_t *cpu_get_ioreq_from_shared_memory(XenIOState *state, int vc= pu) +{ + ioreq_t *req =3D xen_vcpu_ioreq(state->shared_page, vcpu); + + if (req->state !=3D STATE_IOREQ_READY) { + DPRINTF("I/O request not ready: " + "%x, ptr: %x, port: %"PRIx64", " + "data: %"PRIx64", count: %u, size: %u\n", + req->state, req->data_is_ptr, req->addr, + req->data, req->count, req->size); + return NULL; + } + + xen_rmb(); /* see IOREQ_READY /then/ read contents of ioreq */ + + req->state =3D STATE_IOREQ_INPROCESS; + return req; +} + +/* use poll to get the port notification */ +/* ioreq_vec--out,the */ +/* retval--the number of ioreq packet */ +static ioreq_t *cpu_get_ioreq(XenIOState *state) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int max_cpus =3D ms->smp.max_cpus; + int i; + evtchn_port_t port; + + port =3D xenevtchn_pending(state->xce_handle); + if (port =3D=3D state->bufioreq_local_port) { + timer_mod(state->buffered_io_timer, + BUFFER_IO_MAX_DELAY + qemu_clock_get_ms(QEMU_CLOCK_REALTIM= E)); + return NULL; + } + + if (port !=3D -1) { + for (i =3D 0; i < max_cpus; i++) { + if (state->ioreq_local_port[i] =3D=3D port) { + break; + } + } + + if (i =3D=3D max_cpus) { + hw_error("Fatal error while trying to get io event!\n"); + } + + /* unmask the wanted port again */ + xenevtchn_unmask(state->xce_handle, port); + + /* get the io packet from shared memory */ + state->send_vcpu =3D i; + return cpu_get_ioreq_from_shared_memory(state, i); + } + + /* read error or read nothing */ + return NULL; +} + +static uint32_t do_inp(uint32_t addr, unsigned long size) +{ + switch (size) { + case 1: + return cpu_inb(addr); + case 2: + return cpu_inw(addr); + case 4: + return cpu_inl(addr); + default: + hw_error("inp: bad size: %04x %lx", addr, size); + } +} + +static void do_outp(uint32_t addr, + unsigned long size, uint32_t val) +{ + switch (size) { + case 1: + return cpu_outb(addr, val); + case 2: + return cpu_outw(addr, val); + case 4: + return cpu_outl(addr, val); + default: + hw_error("outp: bad size: %04x %lx", addr, size); + } +} + +/* + * Helper functions which read/write an object from/to physical guest + * memory, as part of the implementation of an ioreq. + * + * Equivalent to + * cpu_physical_memory_rw(addr + (req->df ? -1 : +1) * req->size * i, + * val, req->size, 0/1) + * except without the integer overflow problems. + */ +static void rw_phys_req_item(hwaddr addr, + ioreq_t *req, uint32_t i, void *val, int rw) +{ + /* Do everything unsigned so overflow just results in a truncated resu= lt + * and accesses to undesired parts of guest memory, which is up + * to the guest */ + hwaddr offset =3D (hwaddr)req->size * i; + if (req->df) { + addr -=3D offset; + } else { + addr +=3D offset; + } + cpu_physical_memory_rw(addr, val, req->size, rw); +} + +static inline void read_phys_req_item(hwaddr addr, + ioreq_t *req, uint32_t i, void *val) +{ + rw_phys_req_item(addr, req, i, val, 0); +} +static inline void write_phys_req_item(hwaddr addr, + ioreq_t *req, uint32_t i, void *val) +{ + rw_phys_req_item(addr, req, i, val, 1); +} + + +void cpu_ioreq_pio(ioreq_t *req) +{ + uint32_t i; + + trace_cpu_ioreq_pio(req, req->dir, req->df, req->data_is_ptr, req->add= r, + req->data, req->count, req->size); + + if (req->size > sizeof(uint32_t)) { + hw_error("PIO: bad size (%u)", req->size); + } + + if (req->dir =3D=3D IOREQ_READ) { + if (!req->data_is_ptr) { + req->data =3D do_inp(req->addr, req->size); + trace_cpu_ioreq_pio_read_reg(req, req->data, req->addr, + req->size); + } else { + uint32_t tmp; + + for (i =3D 0; i < req->count; i++) { + tmp =3D do_inp(req->addr, req->size); + write_phys_req_item(req->data, req, i, &tmp); + } + } + } else if (req->dir =3D=3D IOREQ_WRITE) { + if (!req->data_is_ptr) { + trace_cpu_ioreq_pio_write_reg(req, req->data, req->addr, + req->size); + do_outp(req->addr, req->size, req->data); + } else { + for (i =3D 0; i < req->count; i++) { + uint32_t tmp =3D 0; + + read_phys_req_item(req->data, req, i, &tmp); + do_outp(req->addr, req->size, tmp); + } + } + } +} + +static void cpu_ioreq_move(ioreq_t *req) +{ + uint32_t i; + + trace_cpu_ioreq_move(req, req->dir, req->df, req->data_is_ptr, req->ad= dr, + req->data, req->count, req->size); + + if (req->size > sizeof(req->data)) { + hw_error("MMIO: bad size (%u)", req->size); + } + + if (!req->data_is_ptr) { + if (req->dir =3D=3D IOREQ_READ) { + for (i =3D 0; i < req->count; i++) { + read_phys_req_item(req->addr, req, i, &req->data); + } + } else if (req->dir =3D=3D IOREQ_WRITE) { + for (i =3D 0; i < req->count; i++) { + write_phys_req_item(req->addr, req, i, &req->data); + } + } + } else { + uint64_t tmp; + + if (req->dir =3D=3D IOREQ_READ) { + for (i =3D 0; i < req->count; i++) { + read_phys_req_item(req->addr, req, i, &tmp); + write_phys_req_item(req->data, req, i, &tmp); + } + } else if (req->dir =3D=3D IOREQ_WRITE) { + for (i =3D 0; i < req->count; i++) { + read_phys_req_item(req->data, req, i, &tmp); + write_phys_req_item(req->addr, req, i, &tmp); + } + } + } +} + +static void cpu_ioreq_config(XenIOState *state, ioreq_t *req) +{ + uint32_t sbdf =3D req->addr >> 32; + uint32_t reg =3D req->addr; + XenPciDevice *xendev; + + if (req->size !=3D sizeof(uint8_t) && req->size !=3D sizeof(uint16_t) = && + req->size !=3D sizeof(uint32_t)) { + hw_error("PCI config access: bad size (%u)", req->size); + } + + if (req->count !=3D 1) { + hw_error("PCI config access: bad count (%u)", req->count); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { + if (xendev->sbdf !=3D sbdf) { + continue; + } + + if (!req->data_is_ptr) { + if (req->dir =3D=3D IOREQ_READ) { + req->data =3D pci_host_config_read_common( + xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE, + req->size); + trace_cpu_ioreq_config_read(req, xendev->sbdf, reg, + req->size, req->data); + } else if (req->dir =3D=3D IOREQ_WRITE) { + trace_cpu_ioreq_config_write(req, xendev->sbdf, reg, + req->size, req->data); + pci_host_config_write_common( + xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE, + req->data, req->size); + } + } else { + uint32_t tmp; + + if (req->dir =3D=3D IOREQ_READ) { + tmp =3D pci_host_config_read_common( + xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE, + req->size); + trace_cpu_ioreq_config_read(req, xendev->sbdf, reg, + req->size, tmp); + write_phys_req_item(req->data, req, 0, &tmp); + } else if (req->dir =3D=3D IOREQ_WRITE) { + read_phys_req_item(req->data, req, 0, &tmp); + trace_cpu_ioreq_config_write(req, xendev->sbdf, reg, + req->size, tmp); + pci_host_config_write_common( + xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE, + tmp, req->size); + } + } + } +} + +static void handle_ioreq(XenIOState *state, ioreq_t *req) +{ + trace_handle_ioreq(req, req->type, req->dir, req->df, req->data_is_ptr, + req->addr, req->data, req->count, req->size); + + if (!req->data_is_ptr && (req->dir =3D=3D IOREQ_WRITE) && + (req->size < sizeof (target_ulong))) { + req->data &=3D ((target_ulong) 1 << (8 * req->size)) - 1; + } + + if (req->dir =3D=3D IOREQ_WRITE) + trace_handle_ioreq_write(req, req->type, req->df, req->data_is_ptr, + req->addr, req->data, req->count, req->si= ze); + + switch (req->type) { + case IOREQ_TYPE_PIO: + cpu_ioreq_pio(req); + break; + case IOREQ_TYPE_COPY: + cpu_ioreq_move(req); + break; + case IOREQ_TYPE_TIMEOFFSET: + break; + case IOREQ_TYPE_INVALIDATE: + xen_invalidate_map_cache(); + break; + case IOREQ_TYPE_PCI_CONFIG: + cpu_ioreq_config(state, req); + break; + default: + arch_handle_ioreq(state, req); + } + if (req->dir =3D=3D IOREQ_READ) { + trace_handle_ioreq_read(req, req->type, req->df, req->data_is_ptr, + req->addr, req->data, req->count, req->siz= e); + } +} + +static bool handle_buffered_iopage(XenIOState *state) +{ + buffered_iopage_t *buf_page =3D state->buffered_io_page; + buf_ioreq_t *buf_req =3D NULL; + bool handled_ioreq =3D false; + ioreq_t req; + int qw; + + if (!buf_page) { + return 0; + } + + memset(&req, 0x00, sizeof(req)); + req.state =3D STATE_IOREQ_READY; + req.count =3D 1; + req.dir =3D IOREQ_WRITE; + + for (;;) { + uint32_t rdptr =3D buf_page->read_pointer, wrptr; + + xen_rmb(); + wrptr =3D buf_page->write_pointer; + xen_rmb(); + if (rdptr !=3D buf_page->read_pointer) { + continue; + } + if (rdptr =3D=3D wrptr) { + break; + } + buf_req =3D &buf_page->buf_ioreq[rdptr % IOREQ_BUFFER_SLOT_NUM]; + req.size =3D 1U << buf_req->size; + req.addr =3D buf_req->addr; + req.data =3D buf_req->data; + req.type =3D buf_req->type; + xen_rmb(); + qw =3D (req.size =3D=3D 8); + if (qw) { + if (rdptr + 1 =3D=3D wrptr) { + hw_error("Incomplete quad word buffered ioreq"); + } + buf_req =3D &buf_page->buf_ioreq[(rdptr + 1) % + IOREQ_BUFFER_SLOT_NUM]; + req.data |=3D ((uint64_t)buf_req->data) << 32; + xen_rmb(); + } + + handle_ioreq(state, &req); + + /* Only req.data may get updated by handle_ioreq(), albeit even th= at + * should not happen as such data would never make it to the guest= (we + * can only usefully see writes here after all). + */ + assert(req.state =3D=3D STATE_IOREQ_READY); + assert(req.count =3D=3D 1); + assert(req.dir =3D=3D IOREQ_WRITE); + assert(!req.data_is_ptr); + + qatomic_add(&buf_page->read_pointer, qw + 1); + handled_ioreq =3D true; + } + + return handled_ioreq; +} + +static void handle_buffered_io(void *opaque) +{ + XenIOState *state =3D opaque; + + if (handle_buffered_iopage(state)) { + timer_mod(state->buffered_io_timer, + BUFFER_IO_MAX_DELAY + qemu_clock_get_ms(QEMU_CLOCK_REALTIM= E)); + } else { + timer_del(state->buffered_io_timer); + xenevtchn_unmask(state->xce_handle, state->bufioreq_local_port); + } +} + +static void cpu_handle_ioreq(void *opaque) +{ + XenIOState *state =3D opaque; + ioreq_t *req =3D cpu_get_ioreq(state); + + handle_buffered_iopage(state); + if (req) { + ioreq_t copy =3D *req; + + xen_rmb(); + handle_ioreq(state, ©); + req->data =3D copy.data; + + if (req->state !=3D STATE_IOREQ_INPROCESS) { + fprintf(stderr, "Badness in I/O request ... not in service?!: " + "%x, ptr: %x, port: %"PRIx64", " + "data: %"PRIx64", count: %u, size: %u, type: %u\n", + req->state, req->data_is_ptr, req->addr, + req->data, req->count, req->size, req->type); + destroy_hvm_domain(false); + return; + } + + xen_wmb(); /* Update ioreq contents /then/ update state. */ + + /* + * We do this before we send the response so that the tools + * have the opportunity to pick up on the reset before the + * guest resumes and does a hlt with interrupts disabled which + * causes Xen to powerdown the domain. + */ + if (runstate_is_running()) { + ShutdownCause request; + + if (qemu_shutdown_requested_get()) { + destroy_hvm_domain(false); + } + request =3D qemu_reset_requested_get(); + if (request) { + qemu_system_reset(request); + destroy_hvm_domain(true); + } + } + + req->state =3D STATE_IORESP_READY; + xenevtchn_notify(state->xce_handle, + state->ioreq_local_port[state->send_vcpu]); + } +} + +static void xen_main_loop_prepare(XenIOState *state) +{ + int evtchn_fd =3D -1; + + if (state->xce_handle !=3D NULL) { + evtchn_fd =3D xenevtchn_fd(state->xce_handle); + } + + state->buffered_io_timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, handle_= buffered_io, + state); + + if (evtchn_fd !=3D -1) { + CPUState *cpu_state; + + DPRINTF("%s: Init cpu_by_vcpu_id\n", __func__); + CPU_FOREACH(cpu_state) { + DPRINTF("%s: cpu_by_vcpu_id[%d]=3D%p\n", + __func__, cpu_state->cpu_index, cpu_state); + state->cpu_by_vcpu_id[cpu_state->cpu_index] =3D cpu_state; + } + qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, state); + } +} + + +void xen_hvm_change_state_handler(void *opaque, bool running, + RunState rstate) +{ + XenIOState *state =3D opaque; + + if (running) { + xen_main_loop_prepare(state); + } + + xen_set_ioreq_server_state(xen_domid, + state->ioservid, + (rstate =3D=3D RUN_STATE_RUNNING)); +} + +void xen_exit_notifier(Notifier *n, void *data) +{ + XenIOState *state =3D container_of(n, XenIOState, exit); + + xen_destroy_ioreq_server(xen_domid, state->ioservid); + if (state->fres !=3D NULL) { + xenforeignmemory_unmap_resource(xen_fmem, state->fres); + } + + xenevtchn_close(state->xce_handle); + xs_daemon_close(state->xenstore); +} + +static int xen_map_ioreq_server(XenIOState *state) +{ + void *addr =3D NULL; + xen_pfn_t ioreq_pfn; + xen_pfn_t bufioreq_pfn; + evtchn_port_t bufioreq_evtchn; + int rc; + + /* + * Attempt to map using the resource API and fall back to normal + * foreign mapping if this is not supported. + */ + QEMU_BUILD_BUG_ON(XENMEM_resource_ioreq_server_frame_bufioreq !=3D 0); + QEMU_BUILD_BUG_ON(XENMEM_resource_ioreq_server_frame_ioreq(0) !=3D 1); + state->fres =3D xenforeignmemory_map_resource(xen_fmem, xen_domid, + XENMEM_resource_ioreq_server, + state->ioservid, 0, 2, + &addr, + PROT_READ | PROT_WRITE, 0); + if (state->fres !=3D NULL) { + trace_xen_map_resource_ioreq(state->ioservid, addr); + state->buffered_io_page =3D addr; + state->shared_page =3D addr + XC_PAGE_SIZE; + } else if (errno !=3D EOPNOTSUPP) { + error_report("failed to map ioreq server resources: error %d handl= e=3D%p", + errno, xen_xc); + return -1; + } + + rc =3D xen_get_ioreq_server_info(xen_domid, state->ioservid, + (state->shared_page =3D=3D NULL) ? + &ioreq_pfn : NULL, + (state->buffered_io_page =3D=3D NULL) ? + &bufioreq_pfn : NULL, + &bufioreq_evtchn); + if (rc < 0) { + error_report("failed to get ioreq server info: error %d handle=3D%= p", + errno, xen_xc); + return rc; + } + + if (state->shared_page =3D=3D NULL) { + DPRINTF("shared page at pfn %lx\n", ioreq_pfn); + + state->shared_page =3D xenforeignmemory_map(xen_fmem, xen_domid, + PROT_READ | PROT_WRITE, + 1, &ioreq_pfn, NULL); + if (state->shared_page =3D=3D NULL) { + error_report("map shared IO page returned error %d handle=3D%p= ", + errno, xen_xc); + } + } + + if (state->buffered_io_page =3D=3D NULL) { + DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn); + + state->buffered_io_page =3D xenforeignmemory_map(xen_fmem, xen_dom= id, + PROT_READ | PROT_WR= ITE, + 1, &bufioreq_pfn, + NULL); + if (state->buffered_io_page =3D=3D NULL) { + error_report("map buffered IO page returned error %d", errno); + return -1; + } + } + + if (state->shared_page =3D=3D NULL || state->buffered_io_page =3D=3D N= ULL) { + return -1; + } + + DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn); + + state->bufioreq_remote_port =3D bufioreq_evtchn; + + return 0; +} + +void destroy_hvm_domain(bool reboot) +{ + xc_interface *xc_handle; + int sts; + int rc; + + unsigned int reason =3D reboot ? SHUTDOWN_reboot : SHUTDOWN_poweroff; + + if (xen_dmod) { + rc =3D xendevicemodel_shutdown(xen_dmod, xen_domid, reason); + if (!rc) { + return; + } + if (errno !=3D ENOTTY /* old Xen */) { + perror("xendevicemodel_shutdown failed"); + } + /* well, try the old thing then */ + } + + xc_handle =3D xc_interface_open(0, 0, 0); + if (xc_handle =3D=3D NULL) { + fprintf(stderr, "Cannot acquire xenctrl handle\n"); + } else { + sts =3D xc_domain_shutdown(xc_handle, xen_domid, reason); + if (sts !=3D 0) { + fprintf(stderr, "xc_domain_shutdown failed to issue %s, " + "sts %d, %s\n", reboot ? "reboot" : "poweroff", + sts, strerror(errno)); + } else { + fprintf(stderr, "Issued domain %d %s\n", xen_domid, + reboot ? "reboot" : "poweroff"); + } + xc_interface_close(xc_handle); + } +} + +void xen_shutdown_fatal_error(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "Will destroy the domain.\n"); + /* destroy the domain */ + qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_ERROR); +} + +static void xen_register_backend(XenIOState *state) +{ + /* Initialize backend core & drivers */ + if (xen_be_init() !=3D 0) { + error_report("xen backend core setup failed"); + goto err; + } + xen_be_register_common(); + + return; + +err: + error_report("xen hardware virtual machine backend registration failed= "); + exit(1); +} + +void xen_register_ioreq(XenIOState *state, unsigned int max_cpus, + MemoryListener xen_memory_listener) +{ + int i, rc; + + state->xce_handle =3D xenevtchn_open(NULL, 0); + if (state->xce_handle =3D=3D NULL) { + perror("xen: event channel open"); + goto err; + } + + state->xenstore =3D xs_daemon_open(); + if (state->xenstore =3D=3D NULL) { + perror("xen: xenstore open"); + goto err; + } + + xen_create_ioreq_server(xen_domid, &state->ioservid); + + state->exit.notify =3D xen_exit_notifier; + qemu_add_exit_notifier(&state->exit); + + /* + * Register wake-up support in QMP query-current-machine API + */ + qemu_register_wakeup_support(); + + rc =3D xen_map_ioreq_server(state); + if (rc < 0) { + goto err; + } + + /* Note: cpus is empty at this point in init */ + state->cpu_by_vcpu_id =3D g_malloc0(max_cpus * sizeof(CPUState *)); + + rc =3D xen_set_ioreq_server_state(xen_domid, state->ioservid, true); + if (rc < 0) { + error_report("failed to enable ioreq server info: error %d handle= =3D%p", + errno, xen_xc); + goto err; + } + + state->ioreq_local_port =3D g_malloc0(max_cpus * sizeof (evtchn_port_t= )); + + /* FIXME: how about if we overflow the page here? */ + for (i =3D 0; i < max_cpus; i++) { + rc =3D xenevtchn_bind_interdomain(state->xce_handle, xen_domid, + xen_vcpu_eport(state->shared_page,= i)); + if (rc =3D=3D -1) { + error_report("shared evtchn %d bind error %d", i, errno); + goto err; + } + state->ioreq_local_port[i] =3D rc; + } + + rc =3D xenevtchn_bind_interdomain(state->xce_handle, xen_domid, + state->bufioreq_remote_port); + if (rc =3D=3D -1) { + error_report("buffered evtchn bind error %d", errno); + goto err; + } + state->bufioreq_local_port =3D rc; + + /* Init RAM management */ +#ifdef XEN_COMPAT_PHYSMAP + xen_map_cache_init(xen_phys_offset_to_gaddr, state); +#else + xen_map_cache_init(NULL, state); +#endif + + qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state); + + state->memory_listener =3D xen_memory_listener; + memory_listener_register(&state->memory_listener, &address_space_memor= y); + + state->io_listener =3D xen_io_listener; + memory_listener_register(&state->io_listener, &address_space_io); + + state->device_listener =3D xen_device_listener; + QLIST_INIT(&state->dev_list); + device_listener_register(&state->device_listener); + + xen_bus_init(); + + xen_register_backend(state); + + return; +err: + error_report("xen hardware virtual machine initialisation failed"); + exit(1); +} diff --git a/include/hw/i386/xen_arch_hvm.h b/include/hw/i386/xen_arch_hvm.h new file mode 100644 index 0000000000..1000f8f543 --- /dev/null +++ b/include/hw/i386/xen_arch_hvm.h @@ -0,0 +1,11 @@ +#ifndef HW_XEN_ARCH_I386_HVM_H +#define HW_XEN_ARCH_I386_HVM_H + +#include +#include "hw/xen/xen-hvm-common.h" + +void arch_handle_ioreq(XenIOState *state, ioreq_t *req); +void arch_xen_set_memory(XenIOState *state, + MemoryRegionSection *section, + bool add); +#endif diff --git a/include/hw/xen/arch_hvm.h b/include/hw/xen/arch_hvm.h new file mode 100644 index 0000000000..26674648d8 --- /dev/null +++ b/include/hw/xen/arch_hvm.h @@ -0,0 +1,3 @@ +#if defined(TARGET_I386) || defined(TARGET_X86_64) +#include "hw/i386/xen_arch_hvm.h" +#endif diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-commo= n.h new file mode 100644 index 0000000000..2979f84ee2 --- /dev/null +++ b/include/hw/xen/xen-hvm-common.h @@ -0,0 +1,98 @@ +#ifndef HW_XEN_HVM_COMMON_H +#define HW_XEN_HVM_COMMON_H + +#include "qemu/osdep.h" +#include "qemu/units.h" + +#include "cpu.h" +#include "hw/pci/pci.h" +#include "hw/hw.h" +#include "hw/xen/xen_common.h" +#include "sysemu/runstate.h" +#include "sysemu/sysemu.h" +#include "sysemu/xen.h" +#include "sysemu/xen-mapcache.h" + +#include + +extern MemoryRegion ram_memory; +extern MemoryListener xen_io_listener; +extern DeviceListener xen_device_listener; + +//#define DEBUG_XEN_HVM + +#ifdef DEBUG_XEN_HVM +#define DPRINTF(fmt, ...) \ + do { fprintf(stderr, "xen: " fmt, ## __VA_ARGS__); } while (0) +#else +#define DPRINTF(fmt, ...) \ + do { } while (0) +#endif + +static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i) +{ + return shared_page->vcpu_ioreq[i].vp_eport; +} +static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vc= pu) +{ + return &shared_page->vcpu_ioreq[vcpu]; +} + +#define BUFFER_IO_MAX_DELAY 100 + +typedef struct XenPhysmap { + hwaddr start_addr; + ram_addr_t size; + const char *name; + hwaddr phys_offset; + + QLIST_ENTRY(XenPhysmap) list; +} XenPhysmap; + +typedef struct XenPciDevice { + PCIDevice *pci_dev; + uint32_t sbdf; + QLIST_ENTRY(XenPciDevice) entry; +} XenPciDevice; + +typedef struct XenIOState { + ioservid_t ioservid; + shared_iopage_t *shared_page; + buffered_iopage_t *buffered_io_page; + xenforeignmemory_resource_handle *fres; + QEMUTimer *buffered_io_timer; + CPUState **cpu_by_vcpu_id; + /* the evtchn port for polling the notification, */ + evtchn_port_t *ioreq_local_port; + /* evtchn remote and local ports for buffered io */ + evtchn_port_t bufioreq_remote_port; + evtchn_port_t bufioreq_local_port; + /* the evtchn fd for polling */ + xenevtchn_handle *xce_handle; + /* which vcpu we are serving */ + int send_vcpu; + + struct xs_handle *xenstore; + MemoryListener memory_listener; + MemoryListener io_listener; + QLIST_HEAD(, XenPciDevice) dev_list; + DeviceListener device_listener; + + Notifier exit; +} XenIOState; + +void xen_exit_notifier(Notifier *n, void *data); + +void xen_region_add(MemoryListener *listener, MemoryRegionSection *section= ); +void xen_region_del(MemoryListener *listener, MemoryRegionSection *section= ); +void xen_io_add(MemoryListener *listener, MemoryRegionSection *section); +void xen_io_del(MemoryListener *listener, MemoryRegionSection *section); +void xen_device_realize(DeviceListener *listener, DeviceState *dev); +void xen_device_unrealize(DeviceListener *listener, DeviceState *dev); + +void xen_hvm_change_state_handler(void *opaque, bool running, RunState rst= ate); +void xen_register_ioreq(XenIOState *state, unsigned int max_cpus, + MemoryListener xen_memory_listener); + +void cpu_ioreq_pio(ioreq_t *req); +#endif /* HW_XEN_HVM_COMMON_H */ --=20 2.25.1 From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418325; cv=none; d=zohomail.com; s=zohoarc; b=WbbUXmF9rUX0+641fGzxwdDmfCUwZSSk5SbJAIzhTUq0F8efDXMXmQLQDeIb5NOeptd49i/e+CWrtX4OGTw1u/uZ3hSALqNw6XF8dMVCbUWWJNEBSRHXDiZP0foLQHjbXPmKE486GP2p1ajYrkbkfzgJZlQdWGYQ6Za8eVqy3G4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418325; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ajNQv1VkxvUCcLPyFYwpWx6ou2r/81Dsdld8S5EMRyw=; b=l0b+9e4y4PG3JA25j4HPw4PLQtcRQXM8JA/+SYJjMU2IRKpgMn7u1vQQU7amyfjLkOiVA4He16Xvk/oZFdXvUIp7paJl4ZW61Q2fFApPG0RWBZIysjmnMWFxLE0ntCelXalXStlb09nmFIrFfFQlzbqQHvEXavmik+3RvuLnZAg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418325437698.7563679663479; Tue, 14 Feb 2023 15:45:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xb-0005KI-HX; Tue, 14 Feb 2023 18:43:43 -0500 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 1pS4xZ-0005JO-DJ for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:42 -0500 Received: from ams.source.kernel.org ([145.40.68.75]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xX-0003ka-S9 for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:41 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 18FC2B81F5D; Tue, 14 Feb 2023 23:43:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 075F0C4339C; Tue, 14 Feb 2023 23:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418217; bh=P09GLhS3AipXDBR5fLwZN51vbqNBUqq+Ribpr8N2TSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WbwdZVMSQkxVKiqzEuuyPReoV/htc1XP2accHF2VW1jABmuIeD6dgc2bXaKiB06QM HKFnzZXITk9Ydoh12L1ZMlg3Jw411Cr3zIVXRy4BjMXfpnw+k/AuZ0gdRYs8vi1sws 3lfarEmErawWcmdh6HS90f/r00pLwHATbAt7cmVASLJGqN54SGt2bfLxqnkPsCuNeW vcRe0bgWpZQFwLWQPLiQHkVbSSQdHH81ClBrQx0A9oZ76ls7LxlO8jnmFkcVnSx088 8gjzDCRB7rg9ac9ZAwoUSYg7d1b8Auikeb49+gn8iIRL6BtAslst8pmV6/im3S0j9R ajFLjjeOuMvZg== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Stefano Stabellini , Vikram Garhwal , Paul Durrant Subject: [PULL v2 05/10] include/hw/xen/xen_common: return error from xen_create_ioreq_server Date: Tue, 14 Feb 2023 15:43:25 -0800 Message-Id: <20230214234330.2107879-5-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=145.40.68.75; envelope-from=sstabellini@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418326389100001 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini This is done to prepare for enabling xenpv support for ARM architecture. On ARM it is possible to have a functioning xenpv machine with only the PV backends and no IOREQ server. If the IOREQ server creation fails, continue to the PV backends initialization. Signed-off-by: Stefano Stabellini Signed-off-by: Vikram Garhwal Reviewed-by: Stefano Stabellini Reviewed-by: Paul Durrant --- include/hw/xen/xen_common.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 9a13a756ae..9ec69582b3 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -467,9 +467,10 @@ static inline void xen_unmap_pcidev(domid_t dom, { } =20 -static inline void xen_create_ioreq_server(domid_t dom, - ioservid_t *ioservid) +static inline int xen_create_ioreq_server(domid_t dom, + ioservid_t *ioservid) { + return 0; } =20 static inline void xen_destroy_ioreq_server(domid_t dom, @@ -600,8 +601,8 @@ static inline void xen_unmap_pcidev(domid_t dom, PCI_FUNC(pci_dev->devfn)= ); } =20 -static inline void xen_create_ioreq_server(domid_t dom, - ioservid_t *ioservid) +static inline int xen_create_ioreq_server(domid_t dom, + ioservid_t *ioservid) { int rc =3D xendevicemodel_create_ioreq_server(xen_dmod, dom, HVM_IOREQSRV_BUFIOREQ_ATOM= IC, @@ -609,12 +610,14 @@ static inline void xen_create_ioreq_server(domid_t do= m, =20 if (rc =3D=3D 0) { trace_xen_ioreq_server_create(*ioservid); - return; + return rc; } =20 *ioservid =3D 0; use_default_ioreq_server =3D true; trace_xen_default_ioreq_server(); + + return rc; } =20 static inline void xen_destroy_ioreq_server(domid_t dom, --=20 2.25.1 From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418299; cv=none; d=zohomail.com; s=zohoarc; b=CGv+LcuXHBIWvWOII73WC192Nnzq7+0HVpayUEBEBCZE31r97ehruMh41iaq544W8VWmQLvKudq4sUVC0g3vnDmLiFMpFZmwpPn/CuDtW2UZyE+LaufCaMsoBJV2D+8ppA+pCp+T0mfkhZaKKVfKXIBLMPnQZ2i+ocrsS+DCab8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418299; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mSPASEytLPML5uHeXj7pIdV2mM9siJNbNh1buI0CIKw=; b=SXDyholl0Zwb9JUymnaVFuOnkyzNlJQ/naxtuZkNXHhUHJPsRgUYRbRkmLUpTwoABRZrT9ucMVcdenwm42nhtOzesVrVkDHoWsDVHmXeW1ev0xI9QQKEKlp9W2n3QyigdAG9nRJHO/Lc+koj0J4DfzznSZF9+9SuyMo3TXThYeQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418299757445.7276292953669; Tue, 14 Feb 2023 15:44:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xd-0005KZ-IQ; Tue, 14 Feb 2023 18:43:45 -0500 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 1pS4xa-0005KB-QM for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:43 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xY-0003l2-9E for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:42 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 701B761927; Tue, 14 Feb 2023 23:43:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 199E0C433D2; Tue, 14 Feb 2023 23:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418218; bh=OA2AgeMCx7RRv0Vx8WIP0aooYg/Xp/x/p0wt5RQQtoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iw8COcUgDrp9qWbdjvvDQ0eF7xHmpBXQv+hX5GZoRrSMShMdAulizTFE2xxiRhtCr eOjTV1Yq9EyN/kkkVvyq5XgrsPnZN1pb7qgovU76ysY72BSw5Rf4bb9FocRsVPrALb eW3DdodKm/6wk3PLfasoZHZ4jpF7PIx8AltwGndKyUQhLd6+klLRyo4qVhWchnRs0P O7QgPdlo71cVUVTAFQiCdO4+WvC+PzftejFt7vh0WXb+0yOj8d3URKvMl3IpzsrNjX UwAgPvDk3qCUZu+LnBV91puN5jPPaHSuj9Z3OMczQaFWCeER/kmnvQSdAYX5+r4pbX CS/881VsQvvVw== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Stefano Stabellini , Vikram Garhwal , Paul Durrant Subject: [PULL v2 06/10] hw/xen/xen-hvm-common: skip ioreq creation on ioreq registration failure Date: Tue, 14 Feb 2023 15:43:26 -0800 Message-Id: <20230214234330.2107879-6-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=139.178.84.217; envelope-from=sstabellini@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418300333100006 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini On ARM it is possible to have a functioning xenpv machine with only the PV backends and no IOREQ server. If the IOREQ server creation fails continue to the PV backends initialization. Also, moved the IOREQ registration and mapping subroutine to new function xen_do_ioreq_register(). Signed-off-by: Stefano Stabellini Signed-off-by: Vikram Garhwal Reviewed-by: Stefano Stabellini Reviewed-by: Paul Durrant --- hw/xen/xen-hvm-common.c | 53 ++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index c2e1e08124..5e3c7b073f 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -781,25 +781,12 @@ err: exit(1); } =20 -void xen_register_ioreq(XenIOState *state, unsigned int max_cpus, - MemoryListener xen_memory_listener) +static void xen_do_ioreq_register(XenIOState *state, + unsigned int max_cpus, + MemoryListener xen_memory_liste= ner) { int i, rc; =20 - state->xce_handle =3D xenevtchn_open(NULL, 0); - if (state->xce_handle =3D=3D NULL) { - perror("xen: event channel open"); - goto err; - } - - state->xenstore =3D xs_daemon_open(); - if (state->xenstore =3D=3D NULL) { - perror("xen: xenstore open"); - goto err; - } - - xen_create_ioreq_server(xen_domid, &state->ioservid); - state->exit.notify =3D xen_exit_notifier; qemu_add_exit_notifier(&state->exit); =20 @@ -863,12 +850,44 @@ void xen_register_ioreq(XenIOState *state, unsigned i= nt max_cpus, QLIST_INIT(&state->dev_list); device_listener_register(&state->device_listener); =20 + return; + +err: + error_report("xen hardware virtual machine initialisation failed"); + exit(1); +} + +void xen_register_ioreq(XenIOState *state, unsigned int max_cpus, + MemoryListener xen_memory_listener) +{ + int rc; + + state->xce_handle =3D xenevtchn_open(NULL, 0); + if (state->xce_handle =3D=3D NULL) { + perror("xen: event channel open"); + goto err; + } + + state->xenstore =3D xs_daemon_open(); + if (state->xenstore =3D=3D NULL) { + perror("xen: xenstore open"); + goto err; + } + + rc =3D xen_create_ioreq_server(xen_domid, &state->ioservid); + if (!rc) { + xen_do_ioreq_register(state, max_cpus, xen_memory_listener); + } else { + warn_report("xen: failed to create ioreq server"); + } + xen_bus_init(); =20 xen_register_backend(state); =20 return; + err: - error_report("xen hardware virtual machine initialisation failed"); + error_report("xen hardware virtual machine backend registration failed= "); exit(1); } --=20 2.25.1 From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418298; cv=none; d=zohomail.com; s=zohoarc; b=cYdo1g+pEsLgYYD5wd31LzeZou0F8MWHKUyBgjm7/CJbM414TZLbkh0ZSsBOMWz2htsTLCtUVAi5+dOxUQ/Ijaj29Sr8PKe+kSmhlyNneoCqrNoJaDWkhbxhK0ON/SCK7EkfgBZC2cK6G6zI/8H3lkSKszOEW5QqoDSkL6W0jfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418298; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=teDn6xIuYNRmHmixku7ZozIqV1x3VmDQi4gAFRGVlEI=; b=dL6x5RTn81xLieskPOJnSmD3UJyftmHMjORvdDKebyM453LfuT8r78nuft+B8Gn3D1TT57Ylqe24+ESphUjQYi8JZAIcHON1/hBzYUhRBVyT3+RtrloImJJNKryfoYgjNTtS3MKo2kafX/i/CoTj9csnXAy+2EIwhHALywO9JOU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418298006727.0198230461954; Tue, 14 Feb 2023 15:44:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xi-0005MN-4O; Tue, 14 Feb 2023 18:43:50 -0500 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 1pS4xc-0005KO-3a for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:44 -0500 Received: from ams.source.kernel.org ([145.40.68.75]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xZ-0003ka-TV for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:43 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3A3E7B81F5D; Tue, 14 Feb 2023 23:43:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30137C4339C; Tue, 14 Feb 2023 23:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418219; bh=1muLhh2SpXPFOFywdWq/BvDLZkKQntHqhpnKPhAgHkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hPKclb5c1xsnH0AOzd/7xyfAz6JLXlf9fncFclzYm2eKtEecDnkETFZf+idacWgre 6ypcm3UEQr9+AeYib9QOf1i24RDvpnvRArF59KZrKF1FadHKeG9LQM548XhgXjhIjH /I13XbtptoPEc5wJ0NwOZFtoKyPmMmC057xTEVvz2pkh9gDybJra7/RWnQK4DoG6qz 3x6b8EiX7Vo6ehzZ2ERysvOfCkdRU7owFxAAMXlZeGgdbAtIhaVJqYFALMKJNlKQ16 ngMBvYy/UINqkJxQ6kXQiwYxINGJk6vNh/zgRnxDwiG2seNIsWTvYp0Knfl8R5175O 3ZyJc5OagpbYA== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Vikram Garhwal , Paul Durrant Subject: [PULL v2 07/10] hw/xen/xen-hvm-common: Use g_new and error_report Date: Tue, 14 Feb 2023 15:43:27 -0800 Message-Id: <20230214234330.2107879-7-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=145.40.68.75; envelope-from=sstabellini@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418298286100001 Content-Type: text/plain; charset="utf-8" From: Vikram Garhwal Replace g_malloc with g_new and perror with error_report. Signed-off-by: Vikram Garhwal Reviewed-by: Stefano Stabellini Reviewed-by: Paul Durrant --- hw/xen/xen-hvm-common.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index 5e3c7b073f..077c8dae5b 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -34,7 +34,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, = MemoryRegion *mr, trace_xen_ram_alloc(ram_addr, size); =20 nr_pfn =3D size >> TARGET_PAGE_BITS; - pfn_list =3D g_malloc(sizeof (*pfn_list) * nr_pfn); + pfn_list =3D g_new(xen_pfn_t, nr_pfn); =20 for (i =3D 0; i < nr_pfn; i++) { pfn_list[i] =3D (ram_addr >> TARGET_PAGE_BITS) + i; @@ -731,7 +731,7 @@ void destroy_hvm_domain(bool reboot) return; } if (errno !=3D ENOTTY /* old Xen */) { - perror("xendevicemodel_shutdown failed"); + error_report("xendevicemodel_shutdown failed with error %d", e= rrno); } /* well, try the old thing then */ } @@ -801,7 +801,7 @@ static void xen_do_ioreq_register(XenIOState *state, } =20 /* Note: cpus is empty at this point in init */ - state->cpu_by_vcpu_id =3D g_malloc0(max_cpus * sizeof(CPUState *)); + state->cpu_by_vcpu_id =3D g_new0(CPUState *, max_cpus); =20 rc =3D xen_set_ioreq_server_state(xen_domid, state->ioservid, true); if (rc < 0) { @@ -810,7 +810,7 @@ static void xen_do_ioreq_register(XenIOState *state, goto err; } =20 - state->ioreq_local_port =3D g_malloc0(max_cpus * sizeof (evtchn_port_t= )); + state->ioreq_local_port =3D g_new0(evtchn_port_t, max_cpus); =20 /* FIXME: how about if we overflow the page here? */ for (i =3D 0; i < max_cpus; i++) { @@ -864,13 +864,13 @@ void xen_register_ioreq(XenIOState *state, unsigned i= nt max_cpus, =20 state->xce_handle =3D xenevtchn_open(NULL, 0); if (state->xce_handle =3D=3D NULL) { - perror("xen: event channel open"); + error_report("xen: event channel open failed with error %d", errno= ); goto err; } =20 state->xenstore =3D xs_daemon_open(); if (state->xenstore =3D=3D NULL) { - perror("xen: xenstore open"); + error_report("xen: xenstore open failed with error %d", errno); goto err; } =20 --=20 2.25.1 From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418304; cv=none; d=zohomail.com; s=zohoarc; b=jfPPMnzfyXw4mDo8TPLTI4j7JOy6XrIEbCydUjL+/1GU2lLJOlCuimPADn1tu3+oe6rsndJvMQUBxi39W0X9mErTUh+o6kHnOyFyZGzHNZIg7obr99QP2RqW0qgBT6G6/xyDRJ553zOLcpRAo2YBzTAMVruf0qg3TNn82ulaYfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418304; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2A0Mm4jPHNz16yq3dY8tV4eD2kg9RjAUlMxXJ70nNl0=; b=j/dmoGFrxYhFBHkRRAhPTFdJVfILFPNaCBftP55Kh/JTC591meswHK+PZDfdERu2pSB7t/6w7i+lKJ8COcNV75GKh2YD8tD5zYiV2/APA1imBzfkCVDZz3SimywcSMafeQWVGi5sJ7kF4SwRoGwrreJF646X1nh9OIQ0eSgJVok= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418304034351.0399454133453; Tue, 14 Feb 2023 15:45:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xj-0005Md-Vk; Tue, 14 Feb 2023 18:43:51 -0500 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 1pS4xc-0005KX-Fg for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:45 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xa-0003ml-SQ for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:44 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 631E461953; Tue, 14 Feb 2023 23:43:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27681C433EF; Tue, 14 Feb 2023 23:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418220; bh=42Jxyu7MuQJSn29FeRbED62pUkX788RofzkHPycEJUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OKS9drivMmGx6ih1KIvAS72C1jueAO4VDrtjyV8SXQXtGJlpL8VSqKNLzJzdBpCbU NmOMBunSMIDLveHPLULoSKs6WTPs+e1RNkDNutR0ZcPfndTVpsZvTWxsV3OY2zQ29S 5xZSGPXRjLBmibOQ9uu6hnJhI8PITzYGrHIWpaWmM3NfI8xigI5AFs3YvEVj6bURoi 9wTsmpZEw6HVMVmRyQrZ0xwDoZmlrx7QJDHALrrUFozgMNKCoOOlbTljBAW0SvKXjQ cLIo0u6PmuJ0S2MqggFHFrlKxRcArC+ich0DYPSyHT3S3m8HyKtGdbiCTGekh01xAA 4jIKub1sFS7WA== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Stefano Stabellini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL v2 08/10] meson.build: do not set have_xen_pci_passthrough for aarch64 targets Date: Tue, 14 Feb 2023 15:43:28 -0800 Message-Id: <20230214234330.2107879-8-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: pass client-ip=139.178.84.217; envelope-from=sstabellini@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418304327100001 From: Stefano Stabellini have_xen_pci_passthrough is only used for Xen x86 VMs. Signed-off-by: Stefano Stabellini Reviewed-by: Alex Benn=C3=A9e --- meson.build | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meson.build b/meson.build index a76c855312..8292cdcec5 100644 --- a/meson.build +++ b/meson.build @@ -1471,6 +1471,8 @@ have_xen_pci_passthrough =3D get_option('xen_pci_pass= through') \ error_message: 'Xen PCI passthrough requested but Xen not enabl= ed') \ .require(targetos =3D=3D 'linux', error_message: 'Xen PCI passthrough not available on this platf= orm') \ + .require(cpu =3D=3D 'x86' or cpu =3D=3D 'x86_64', + error_message: 'Xen PCI passthrough not available on this platf= orm') \ .allowed() =20 =20 --=20 2.25.1 From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418282; cv=none; d=zohomail.com; s=zohoarc; b=E9th98KgPjkaf05dfQe8RzdS0WdAVXbiLC6RQjDAZYfzNjqm96SMS5dux+6vj8GTNcrfJ7iMCo+4WVtcPTJ19ngA6FMVzXoRKFw73HIExIWx2C78QYTVO5HhiK0d+8cWdwkrgFr47f31uL9iAhE3ZwcXKVgiv81o1yWatb5dcM0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418282; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VvsuxfrUn2fcuY0W0wWwOx3PCv8UJducNjhBOUDLJ94=; b=bozpsx3niA2R6aKkTqAClnu8IFSE5vbboadY/Mkkr/wXygM47bnHPkLrpQCvEuSJgC0ew8ORIUrLkAZYolnQk+5G/KZtTDPKoXufIbiwKogwDG0YPFc838sy+cOiYk80PJz4DSRTJIZpUYBVekWlTGT0PIvLyyR+5n0GOThPiaI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418282973307.5656592929274; Tue, 14 Feb 2023 15:44:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xk-0005Me-0B; Tue, 14 Feb 2023 18:43:52 -0500 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 1pS4xe-0005LS-3P for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:46 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xb-0003ms-66 for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:45 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5E78261956; Tue, 14 Feb 2023 23:43:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D3D6C4339E; Tue, 14 Feb 2023 23:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418221; bh=9jAC8F5xA/azSePIdP3et7YP+18kRnpPJUTbURgYLnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OeylNm4ZiMuqNphw/irBWMnhvchKrCMWPh+erUQSzWQcRkRVErX9QEkcI/QdznSgN 5rO3NYisu/cgYZ67pP44uUzVpJ/XXkKd7YEaPalxEOeobUMsmFjKGG4VPjMhQQKisp tA4b88hQLqU+V9Q6aPT1f8sCXPEA4uSgx1945MxzUvzbzgYuRN2qGd5lUgzssDacnk tVL1+b404AakZornoS+rzjpta74wkzi4z5728cBHEuwjeX/fp0RVIgMeBPDPmzg25V nSk3+SqiUbQV9w6CN/q9PJGGqrlAwM/hnIYuskkEy1Hlqi1lrJCATyY/aHN7pTsO4T yPfimdzxTlh2w== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Vikram Garhwal , Stefano Stabellini Subject: [PULL v2 09/10] hw/arm: introduce xenpvh machine Date: Tue, 14 Feb 2023 15:43:29 -0800 Message-Id: <20230214234330.2107879-9-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=139.178.84.217; envelope-from=sstabellini@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418284267100001 Content-Type: text/plain; charset="utf-8" From: Vikram Garhwal Add a new machine xenpvh which creates a IOREQ server to register/connect w= ith Xen Hypervisor. Optional: When CONFIG_TPM is enabled, it also creates a tpm-tis-device, add= s a TPM emulator and connects to swtpm running on host machine via chardev sock= et and support TPM functionalities for a guest domain. Extra command line for aarch64 xenpvh QEMU to connect to swtpm: -chardev socket,id=3Dchrtpm,path=3D/tmp/myvtpm2/swtpm-sock \ -tpmdev emulator,id=3Dtpm0,chardev=3Dchrtpm \ -machine tpm-base-addr=3D0x0c000000 \ swtpm implements a TPM software emulator(TPM 1.2 & TPM 2) built on libtpms = and provides access to TPM functionality over socket, chardev and CUSE interfac= e. Github repo: https://github.com/stefanberger/swtpm Example for starting swtpm on host machine: mkdir /tmp/vtpm2 swtpm socket --tpmstate dir=3D/tmp/vtpm2 \ --ctrl type=3Dunixio,path=3D/tmp/vtpm2/swtpm-sock & Signed-off-by: Vikram Garhwal Signed-off-by: Stefano Stabellini Reviewed-by: Stefano Stabellini --- docs/system/arm/xenpvh.rst | 34 +++++++ docs/system/target-arm.rst | 1 + hw/arm/meson.build | 2 + hw/arm/xen_arm.c | 182 ++++++++++++++++++++++++++++++++++ include/hw/arm/xen_arch_hvm.h | 9 ++ include/hw/xen/arch_hvm.h | 2 + 6 files changed, 230 insertions(+) create mode 100644 docs/system/arm/xenpvh.rst create mode 100644 hw/arm/xen_arm.c create mode 100644 include/hw/arm/xen_arch_hvm.h diff --git a/docs/system/arm/xenpvh.rst b/docs/system/arm/xenpvh.rst new file mode 100644 index 0000000000..e1655c7ab8 --- /dev/null +++ b/docs/system/arm/xenpvh.rst @@ -0,0 +1,34 @@ +XENPVH (``xenpvh``) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +This machine creates a IOREQ server to register/connect with Xen Hyperviso= r. + +When TPM is enabled, this machine also creates a tpm-tis-device at a user = input +tpm base address, adds a TPM emulator and connects to a swtpm application +running on host machine via chardev socket. This enables xenpvh to support= TPM +functionalities for a guest domain. + +More information about TPM use and installing swtpm linux application can = be +found at: docs/specs/tpm.rst. + +Example for starting swtpm on host machine: +.. code-block:: console + + mkdir /tmp/vtpm2 + swtpm socket --tpmstate dir=3D/tmp/vtpm2 \ + --ctrl type=3Dunixio,path=3D/tmp/vtpm2/swtpm-sock & + +Sample QEMU xenpvh commands for running and connecting with Xen: +.. code-block:: console + + qemu-system-aarch64 -xen-domid 1 \ + -chardev socket,id=3Dlibxl-cmd,path=3Dqmp-libxl-1,server=3Don,wait=3Do= ff \ + -mon chardev=3Dlibxl-cmd,mode=3Dcontrol \ + -chardev socket,id=3Dlibxenstat-cmd,path=3Dqmp-libxenstat-1,server=3Do= n,wait=3Doff \ + -mon chardev=3Dlibxenstat-cmd,mode=3Dcontrol \ + -xen-attach -name guest0 -vnc none -display none -nographic \ + -machine xenpvh -m 1301 \ + -chardev socket,id=3Dchrtpm,path=3Dtmp/vtpm2/swtpm-sock \ + -tpmdev emulator,id=3Dtpm0,chardev=3Dchrtpm -machine tpm-base-addr=3D0= x0C000000 + +In above QEMU command, last two lines are for connecting xenpvh QEMU to sw= tpm +via chardev socket. diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst index 91ebc26c6d..af8d7c77d6 100644 --- a/docs/system/target-arm.rst +++ b/docs/system/target-arm.rst @@ -106,6 +106,7 @@ undocumented; you can get a complete list by running arm/stm32 arm/virt arm/xlnx-versal-virt + arm/xenpvh =20 Emulated CPU architecture support =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/hw/arm/meson.build b/hw/arm/meson.build index b545ba0e4f..1b2a01a005 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -62,6 +62,8 @@ arm_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-i= mx7.c', 'mcimx7d-sabre. arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) arm_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-imx6ul.c', 'mcim= x6ul-evk.c')) arm_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_soc.c')) +arm_ss.add(when: 'CONFIG_XEN', if_true: files('xen_arm.c')) +arm_ss.add_all(xen_ss) =20 softmmu_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) softmmu_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4_boards.c')) diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c new file mode 100644 index 0000000000..eaca65af37 --- /dev/null +++ b/hw/arm/xen_arm.c @@ -0,0 +1,182 @@ +/* + * QEMU ARM Xen PVH Machine + * + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * 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. + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qapi/qapi-commands-migration.h" +#include "qapi/visitor.h" +#include "hw/boards.h" +#include "hw/sysbus.h" +#include "sysemu/block-backend.h" +#include "sysemu/tpm_backend.h" +#include "sysemu/sysemu.h" +#include "hw/xen/xen-legacy-backend.h" +#include "hw/xen/xen-hvm-common.h" +#include "sysemu/tpm.h" +#include "hw/xen/arch_hvm.h" + +#define TYPE_XEN_ARM MACHINE_TYPE_NAME("xenpvh") +OBJECT_DECLARE_SIMPLE_TYPE(XenArmState, XEN_ARM) + +static MemoryListener xen_memory_listener =3D { + .region_add =3D xen_region_add, + .region_del =3D xen_region_del, + .log_start =3D NULL, + .log_stop =3D NULL, + .log_sync =3D NULL, + .log_global_start =3D NULL, + .log_global_stop =3D NULL, + .priority =3D 10, +}; + +struct XenArmState { + /*< private >*/ + MachineState parent; + + XenIOState *state; + + struct { + uint64_t tpm_base_addr; + } cfg; +}; + +void arch_handle_ioreq(XenIOState *state, ioreq_t *req) +{ + hw_error("Invalid ioreq type 0x%x\n", req->type); + + return; +} + +void arch_xen_set_memory(XenIOState *state, MemoryRegionSection *section, + bool add) +{ +} + +void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) +{ +} + +void qmp_xen_set_global_dirty_log(bool enable, Error **errp) +{ +} + +#ifdef CONFIG_TPM +static void xen_enable_tpm(XenArmState *xam) +{ + Error *errp =3D NULL; + DeviceState *dev; + SysBusDevice *busdev; + + TPMBackend *be =3D qemu_find_tpm_be("tpm0"); + if (be =3D=3D NULL) { + DPRINTF("Couldn't fine the backend for tpm0\n"); + return; + } + dev =3D qdev_new(TYPE_TPM_TIS_SYSBUS); + object_property_set_link(OBJECT(dev), "tpmdev", OBJECT(be), &errp); + object_property_set_str(OBJECT(dev), "tpmdev", be->id, &errp); + busdev =3D SYS_BUS_DEVICE(dev); + sysbus_realize_and_unref(busdev, &error_fatal); + sysbus_mmio_map(busdev, 0, xam->cfg.tpm_base_addr); + + DPRINTF("Connected tpmdev at address 0x%lx\n", xam->cfg.tpm_base_addr); +} +#endif + +static void xen_arm_init(MachineState *machine) +{ + XenArmState *xam =3D XEN_ARM(machine); + + xam->state =3D g_new0(XenIOState, 1); + + xen_register_ioreq(xam->state, machine->smp.cpus, xen_memory_listener); + +#ifdef CONFIG_TPM + if (xam->cfg.tpm_base_addr) { + xen_enable_tpm(xam); + } else { + DPRINTF("tpm-base-addr is not provided. TPM will not be enabled\n"= ); + } +#endif +} + +#ifdef CONFIG_TPM +static void xen_arm_get_tpm_base_addr(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + XenArmState *xam =3D XEN_ARM(obj); + uint64_t value =3D xam->cfg.tpm_base_addr; + + visit_type_uint64(v, name, &value, errp); +} + +static void xen_arm_set_tpm_base_addr(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + XenArmState *xam =3D XEN_ARM(obj); + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + xam->cfg.tpm_base_addr =3D value; +} +#endif + +static void xen_arm_machine_class_init(ObjectClass *oc, void *data) +{ + + MachineClass *mc =3D MACHINE_CLASS(oc); + mc->desc =3D "Xen Para-virtualized PC"; + mc->init =3D xen_arm_init; + mc->max_cpus =3D 1; + mc->default_machine_opts =3D "accel=3Dxen"; + +#ifdef CONFIG_TPM + object_class_property_add(oc, "tpm-base-addr", "uint64_t", + xen_arm_get_tpm_base_addr, + xen_arm_set_tpm_base_addr, + NULL, NULL); + object_class_property_set_description(oc, "tpm-base-addr", + "Set Base address for TPM device= ."); + + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS); +#endif +} + +static const TypeInfo xen_arm_machine_type =3D { + .name =3D TYPE_XEN_ARM, + .parent =3D TYPE_MACHINE, + .class_init =3D xen_arm_machine_class_init, + .instance_size =3D sizeof(XenArmState), +}; + +static void xen_arm_machine_register_types(void) +{ + type_register_static(&xen_arm_machine_type); +} + +type_init(xen_arm_machine_register_types) diff --git a/include/hw/arm/xen_arch_hvm.h b/include/hw/arm/xen_arch_hvm.h new file mode 100644 index 0000000000..8fd645e723 --- /dev/null +++ b/include/hw/arm/xen_arch_hvm.h @@ -0,0 +1,9 @@ +#ifndef HW_XEN_ARCH_ARM_HVM_H +#define HW_XEN_ARCH_ARM_HVM_H + +#include +void arch_handle_ioreq(XenIOState *state, ioreq_t *req); +void arch_xen_set_memory(XenIOState *state, + MemoryRegionSection *section, + bool add); +#endif diff --git a/include/hw/xen/arch_hvm.h b/include/hw/xen/arch_hvm.h index 26674648d8..c7c515220d 100644 --- a/include/hw/xen/arch_hvm.h +++ b/include/hw/xen/arch_hvm.h @@ -1,3 +1,5 @@ #if defined(TARGET_I386) || defined(TARGET_X86_64) #include "hw/i386/xen_arch_hvm.h" +#elif defined(TARGET_ARM) || defined(TARGET_ARM_64) +#include "hw/arm/xen_arch_hvm.h" #endif --=20 2.25.1 From nobody Sat May 18 11:46:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1676418285; cv=none; d=zohomail.com; s=zohoarc; b=Yg3wxvtx3qqED75pZ/+L5Zrh6AGNRW/ZTamqHsLOLJxzqdGLohQghFIqH0XPU+zoug8aYxq5Nvb8b5+QILZTdntfCyfDE+N+22c9u4A07HJxK5hyFfC7uJRlsqqI3AdD9fVGeaVS+qtav8X/dCS2m8wDtoSSbimsDuXsysAFj94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676418285; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0MG5IIIEC51DiCzu1TkB6gEhqpUZJFPZP5+v3T+IsmE=; b=SKaI+MWNeHlmV0uPcaZfr51uWbVFMlZObUl8MtUoWgMr9uDo5IOQlr7pubd8UFRhJzKpCQpK9pdKF9UAvT2J83SGTKFLGMuLj5RK/y4qHnTWClko0jkbeWJv1BOovULelo3orwkGWZoDoCDWs5oGn7at5FJ9/0vvSfQVwJKbD1I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676418285972671.9708830793251; Tue, 14 Feb 2023 15:44:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS4xk-0005Mw-Iz; Tue, 14 Feb 2023 18:43:52 -0500 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 1pS4xe-0005Lb-Ol for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:47 -0500 Received: from ams.source.kernel.org ([145.40.68.75]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pS4xd-0003nN-9I for qemu-devel@nongnu.org; Tue, 14 Feb 2023 18:43:46 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 21EBEB81E4A; Tue, 14 Feb 2023 23:43:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20055C4339B; Tue, 14 Feb 2023 23:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676418222; bh=cp6daikvP3t+RpE/9gvp0uFZJNJEku9+tHJf5P14uPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mB+HmhJsQPB0wSHnnH56AMqu2xsW+P+lKf5Yr1sgBp9IUlTXo3qV+optMR7tt/WCw XQqKUH1Pv7sB76yrtPToXSoOBoBh2CQIBnQjreAbRwNjCBabUPd445UIx8mqonDQlg MAXZxYdNB320kkL3knx9KRzY9hszPhanHMjN4HpkgQ0hEeS/Cn70gbJ5aPuTx5zyUh K3DFy8aV4WJcBmjHru8rTmgt2e41nw5AfhvalIo1BZAmOAGiEbTKFC6inJuv2bZt2r JoUdz/IW5wT5GQ6+nwO9qXMma0bNlRkHAQs+LbTsD0nUqIKodkUeBt5XjttgcfMOPD 0DlMNVOlYA0vQ== From: Stefano Stabellini To: peter.maydell@linaro.org Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Vikram Garhwal , Stefano Stabellini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL v2 10/10] meson.build: enable xenpv machine build for ARM Date: Tue, 14 Feb 2023 15:43:30 -0800 Message-Id: <20230214234330.2107879-10-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: pass client-ip=145.40.68.75; envelope-from=sstabellini@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-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: pass (identity @kernel.org) X-ZM-MESSAGEID: 1676418286258100005 From: Vikram Garhwal Add CONFIG_XEN for aarch64 device to support build for ARM targets. Signed-off-by: Vikram Garhwal Signed-off-by: Stefano Stabellini Reviewed-by: Alex Benn=C3=A9e --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 8292cdcec5..3f08bceba0 100644 --- a/meson.build +++ b/meson.build @@ -135,7 +135,7 @@ endif if cpu in ['x86', 'x86_64', 'arm', 'aarch64'] # i386 emulator provides xenpv machine type for multiple architectures accelerator_targets +=3D { - 'CONFIG_XEN': ['i386-softmmu', 'x86_64-softmmu'], + 'CONFIG_XEN': ['i386-softmmu', 'x86_64-softmmu', 'aarch64-softmmu'], } endif if cpu in ['x86', 'x86_64'] --=20 2.25.1