From nobody Fri Nov 29 09:21:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1643405615; cv=none; d=zohomail.com; s=zohoarc; b=kG57+CEuZEW6PXQQwLER4wCQEQ6leo356CPLsH0a94uPHzqfJqtlUNtckbie+ZM/oSLkCOzbF35X8/lIb13vizsuNBZXA0IGl3sthRX+3fXOIqudzxJ35bw6MVp25NjwmSaLXIKOCMtZgaMpgUOUkvUjgXQAXw3V2fa3idjTMCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643405615; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kZjay0gy4jrcHWeLuSSrw3/hxzuzUKgWmUZusoNkDEw=; b=W2VXWrW6gLtkIitDjnwxy2LofHH6kSU+ltHR5rpZcVdfqFeHq0qMOFLz3HP6/AlD640xdtPwpwgiGeBulw0n60X1bZ4ftcEdMawpovwebLC7VzaeTMmMgdh6YIMKJWkKbs8EmNKK9nCLh0ERDmcoQeoGvLrJbD9gxG6qyAr9+NI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1643405615621711.547626367914; Fri, 28 Jan 2022 13:33:35 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.262146.454290 (Exim 4.92) (envelope-from ) id 1nDYrr-0001eL-5f; Fri, 28 Jan 2022 21:33:15 +0000 Received: by outflank-mailman (output) from mailman id 262146.454290; Fri, 28 Jan 2022 21:33:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrr-0001e9-1o; Fri, 28 Jan 2022 21:33:15 +0000 Received: by outflank-mailman (input) for mailman id 262146; Fri, 28 Jan 2022 21:33:13 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrp-0001cx-ME for xen-devel@lists.xenproject.org; Fri, 28 Jan 2022 21:33:13 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e45ac956-8081-11ec-8eb8-a37418f5ba1a; Fri, 28 Jan 2022 22:33:12 +0100 (CET) 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 D0C6961EA2; Fri, 28 Jan 2022 21:33:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48118C340E7; Fri, 28 Jan 2022 21:33:10 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e45ac956-8081-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643405590; bh=YK3fmTEfi9K2Ficig+PWAtwXSeRhCCBhmIzpGhNdTvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kALIBh445OYoredSX29fwx2QMuUsON3Ykd9WBMP0xTv1jPh3BzHc4tnLGjAOOx35z 6KAEEMhg2+lYywXJpZZeI0kty2+R6Qaq6JpLNnrOZ87oTeRhCR8mWmWUzQ3pvG2rGb UAIc4jiqOz9HHjqkj9WSeQegqi6JUOkqArsdXAiJlujQxFrKITAjMwUENaF1MQ1kR9 bnMn/Rw71iHRJJBknYr30eJYYn4XuejGTrKUlO/aQxMlbHjYMxTs3JC8B3yLhvitji a0Z46GLIOM3Au1C0XKjIyXNa03IHHQwIdXeLldTyoMNiVOuvFf/Vq4jPy9ABJutkuc UzfgDxHz+DyCg== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, jgross@suse.com, Bertrand.Marquis@arm.com, julien@xen.org, Volodymyr_Babchuk@epam.com, Stefano Stabellini , Bertrand Marquis Subject: [PATCH v3 1/5] xen: introduce xen,enhanced dom0less property Date: Fri, 28 Jan 2022 13:33:02 -0800 Message-Id: <20220128213307.2822078-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 X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1643405618500100005 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini Introduce a new "xen,enhanced" dom0less property to enable/disable PV driver interfaces for dom0less guests. Currently only "enabled" and "disabled" are supported property values (and empty). Leave the option open to implement further possible values in the future (e.g. "xenstore" to enable only xenstore.) The configurable option is for domUs only. For dom0 we always set the corresponding property in the Xen code to true (PV interfaces enabled.) This patch only parses the property. Next patches will make use of it. Signed-off-by: Stefano Stabellini Reviewed-by: Bertrand Marquis CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis --- Changes in v3: - improve commit message Changes in v2: - rename kinfo.enhanced to kinfo.dom0less_enhanced - set kinfo.dom0less_enhanced to true for dom0 - handle -ENODATA in addition to -EILSEQ --- docs/misc/arm/device-tree/booting.txt | 18 ++++++++++++++++++ xen/arch/arm/domain_build.c | 8 ++++++++ xen/arch/arm/include/asm/kernel.h | 3 +++ 3 files changed, 29 insertions(+) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-t= ree/booting.txt index 71895663a4..38c29fb3d8 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -169,6 +169,24 @@ with the following properties: Please note that the SPI used for the virtual pl011 could clash with t= he physical SPI of a physical device assigned to the guest. =20 +- xen,enhanced + + A string property. Possible property values are: + + - "enabled" (or missing property value) + Xen PV interfaces, including grant-table and xenstore, will be + enabled for the VM. + + - "disabled" + Xen PV interfaces are disabled. + + If the xen,enhanced property is present with no value, it defaults + to "enabled". If the xen,enhanced property is not present, PV + interfaces are disabled. + + In the future other possible property values might be added to + enable only selected interfaces. + - nr_spis =20 Optional. A 32-bit integer specifying the number of SPIs (Shared diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 6931c022a2..9144d6c0b6 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2963,6 +2963,7 @@ static int __init construct_domU(struct domain *d, const struct dt_device_node *node) { struct kernel_info kinfo =3D {}; + const char *dom0less_enhanced; int rc; u64 mem; =20 @@ -2978,6 +2979,12 @@ static int __init construct_domU(struct domain *d, =20 kinfo.vpl011 =3D dt_property_read_bool(node, "vpl011"); =20 + rc =3D dt_property_read_string(node, "xen,enhanced", &dom0less_enhance= d); + if ( rc =3D=3D -EILSEQ || + rc =3D=3D -ENODATA || + (rc =3D=3D 0 && !strcmp(dom0less_enhanced, "enabled")) ) + kinfo.dom0less_enhanced =3D true; + if ( vcpu_create(d, 0) =3D=3D NULL ) return -ENOMEM; =20 @@ -3095,6 +3102,7 @@ static int __init construct_dom0(struct domain *d) =20 kinfo.unassigned_mem =3D dom0_mem; kinfo.d =3D d; + kinfo.dom0less_enhanced =3D true; =20 rc =3D kernel_probe(&kinfo, NULL); if ( rc < 0 ) diff --git a/xen/arch/arm/include/asm/kernel.h b/xen/arch/arm/include/asm/k= ernel.h index 874aa108a7..c4dc039b54 100644 --- a/xen/arch/arm/include/asm/kernel.h +++ b/xen/arch/arm/include/asm/kernel.h @@ -36,6 +36,9 @@ struct kernel_info { /* Enable pl011 emulation */ bool vpl011; =20 + /* Enable PV drivers */ + bool dom0less_enhanced; + /* GIC phandle */ uint32_t phandle_gic; =20 --=20 2.25.1 From nobody Fri Nov 29 09:21:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1643405615; cv=none; d=zohomail.com; s=zohoarc; b=Hbxt5QCkxBXDpNusx078P7mImMyp36rC+4KIlpRNyFNVdFjVaXcMMI9hNki8++n/HWh8KL76mdfORj84ZRdwi1QOMI4B+FYR0LS8WMtuewOa7ckh5PtAfGFxE34OLXWfmb8ML/6c5PW0OIOSJNvQJblwUdFPuUa7WG0Kx/J5ugc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643405615; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=m/QexUybqJbqEihbNoz8F2WgZTbHGUbquiWzmT6EX6Y=; b=Nf5GdVULC3vdT4thbt9xorRkJhBd49BIN46eqX5WEzYZGiTzTOoHpuIIkQHxD8MXt+3/CmSSj9gEd8CTS2cglkxcPlBM4U9FpIJ5bfmNGthUS1uA7KYfmXSY76ya4NJlxfHiY6pmj7nIeNmSkQ2VbCGAcZgDcv24K77tJ78YeeM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1643405615724400.15357877915187; Fri, 28 Jan 2022 13:33:35 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.262148.454300 (Exim 4.92) (envelope-from ) id 1nDYrs-0001rL-1j; Fri, 28 Jan 2022 21:33:16 +0000 Received: by outflank-mailman (output) from mailman id 262148.454300; Fri, 28 Jan 2022 21:33:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrr-0001oM-SN; Fri, 28 Jan 2022 21:33:15 +0000 Received: by outflank-mailman (input) for mailman id 262148; Fri, 28 Jan 2022 21:33:15 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrq-0001M8-RU for xen-devel@lists.xenproject.org; Fri, 28 Jan 2022 21:33:14 +0000 Received: from ams.source.kernel.org (ams.source.kernel.org [2604:1380:4601:e00::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e579ac03-8081-11ec-8f75-fffcc8bd4f1a; Fri, 28 Jan 2022 22:33:14 +0100 (CET) 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 89CCCB82697; Fri, 28 Jan 2022 21:33:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD8F4C340EC; Fri, 28 Jan 2022 21:33:10 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e579ac03-8081-11ec-8f75-fffcc8bd4f1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643405591; bh=7u5+Xn46ET2Kq+hchW4hiMSc7HY0HUOJ2bLjmmIyZt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l4nD26LstxRti4Jvl8qKqfGLBIdjuVDo0UkmTz6mTyCa/PFnxmnJmsGCHz94YKyd2 5ZRJaPrHAnrrdYC+etQB8+qmMmwTNz5StdQzP9gldgF1xfqqLMPt6/3GnUtIi2Y3gs lh4OUyf+WB3Fu9ZbyfYG0L7BZLOLduX9BFbdgEVen9kV5i170q7cyTzWSUfqpEIPQC Vjq1aV5JprTAYs/chDfIsT0VeD4MddnLPv55KD49XLgpahwiYIsnMfCxxUFAP9PzcR CuCrKz14k4DyC9TaHNdmOfullJx/Qtyqi0QiyqpfY4TptdB2mc7a9QRomuIlRs6cn1 f/vW1KKEKZ+gw== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, jgross@suse.com, Bertrand.Marquis@arm.com, julien@xen.org, Volodymyr_Babchuk@epam.com, Luca Miccio , Stefano Stabellini , Bertrand Marquis , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [PATCH v3 2/5] xen: make evtchn_alloc_unbound public Date: Fri, 28 Jan 2022 13:33:03 -0800 Message-Id: <20220128213307.2822078-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 X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1643405618491100004 Content-Type: text/plain; charset="utf-8" From: Luca Miccio The xenstore event channel will be allocated for dom0less domains. It is necessary to have access to the evtchn_alloc_unbound function to do that, so make evtchn_alloc_unbound public. Add a skip_xsm parameter to allow disabling the XSM check in evtchn_alloc_unbound (xsm_evtchn_unbound wouldn't work for a call originated from Xen before running any domains.) Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Andrew Cooper CC: George Dunlap CC: Jan Beulich CC: Wei Liu --- Changes v3: - expose evtchn_alloc_unbound, assing a skip_xsm parameter --- xen/common/event_channel.c | 13 ++++++++----- xen/include/xen/event.h | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index da88ad141a..be57d00a15 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -284,7 +284,7 @@ void evtchn_free(struct domain *d, struct evtchn *chn) xsm_evtchn_close_post(chn); } =20 -static int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) +int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, bool skip_xsm) { struct evtchn *chn; struct domain *d; @@ -301,9 +301,12 @@ static int evtchn_alloc_unbound(evtchn_alloc_unbound_t= *alloc) ERROR_EXIT_DOM(port, d); chn =3D evtchn_from_port(d, port); =20 - rc =3D xsm_evtchn_unbound(XSM_TARGET, d, chn, alloc->remote_dom); - if ( rc ) - goto out; + if ( !skip_xsm ) + { + rc =3D xsm_evtchn_unbound(XSM_TARGET, d, chn, alloc->remote_dom); + if ( rc ) + goto out; + } =20 evtchn_write_lock(chn); =20 @@ -1195,7 +1198,7 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PA= RAM(void) arg) struct evtchn_alloc_unbound alloc_unbound; if ( copy_from_guest(&alloc_unbound, arg, 1) !=3D 0 ) return -EFAULT; - rc =3D evtchn_alloc_unbound(&alloc_unbound); + rc =3D evtchn_alloc_unbound(&alloc_unbound, false); if ( !rc && __copy_to_guest(arg, &alloc_unbound, 1) ) rc =3D -EFAULT; /* Cleaning up here would be a mess! */ break; diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 21c95e14fd..0a2cdedf7d 100644 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -68,6 +68,9 @@ int evtchn_close(struct domain *d1, int port1, bool guest= ); /* Free an event channel. */ void evtchn_free(struct domain *d, struct evtchn *chn); =20 +/* Create a new event channel port */ +int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, bool skip_xsm); + /* Allocate a specific event channel port. */ int evtchn_allocate_port(struct domain *d, unsigned int port); =20 --=20 2.25.1 From nobody Fri Nov 29 09:21:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1643405615; cv=none; d=zohomail.com; s=zohoarc; b=cPx9bgJyFatC8o85G2DyoD2dn0IyfuEK9oqBICmzMtjV9ocd8iMQn01ZTqo1WlC1cWxamkJDIH7kv4E+5KQQdX0GsOMwLZr/BF2XlRjl/Qvit+fYHpxsb/vIpfxtNYfF4bCVWrWBLjf6ieHDYKxk74GUPjQWwqg4Dk0vD5+k/PE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643405615; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sApqcoKoRlQVC+CCtUrJEbfPJAgZky2QLNZHBF2rBZk=; b=mPp/Xx4V8lqz88QtXWPF/ACICZRs2DqZEn6VUN2I0ztcniogierNsw0C+3iuQ8yGWRu2WXutzdEARaxlx5X8s/g4PcarhDT8qwbBq+NGhy9MPUF6XZLt0bHIVGiuUTF/ox0gve2nYjPEhRNp9rXOeoZqML+XgbHxVJZ9r33FuPo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1643405615630777.161080434898; Fri, 28 Jan 2022 13:33:35 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.262147.454295 (Exim 4.92) (envelope-from ) id 1nDYrr-0001l8-LI; Fri, 28 Jan 2022 21:33:15 +0000 Received: by outflank-mailman (output) from mailman id 262147.454295; Fri, 28 Jan 2022 21:33:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrr-0001k3-HQ; Fri, 28 Jan 2022 21:33:15 +0000 Received: by outflank-mailman (input) for mailman id 262147; Fri, 28 Jan 2022 21:33:14 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrq-0001cx-LL for xen-devel@lists.xenproject.org; Fri, 28 Jan 2022 21:33:14 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e5572ef4-8081-11ec-8eb8-a37418f5ba1a; Fri, 28 Jan 2022 22:33:13 +0100 (CET) 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 7DAF061EA3; Fri, 28 Jan 2022 21:33:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 873FFC36AE2; Fri, 28 Jan 2022 21:33:11 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e5572ef4-8081-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643405591; bh=fAa4cp3TGd4xOz1KtDl8R7cluLC6rckspNgjRiOwBEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dVOg5DCnM0f/14hOYzWu0kzFECqXqGddMpRaC1B/zrzvVPHsyx01co1S71ITpbxQ2 05ekOCBEnVGxQRHDhfBkWaHifAfaeo4YLG34O5VtoSMywqQFzIJ0bulRA2Vl2my67u umGBkuEgv/zf3Ycsl1HwN0LSqDA12RJg5DhXO5P24ohAA+Tuhw3NBC5uTImaSKBoiV oWOhaB6SM9dVgC4rhQKZo3VjNjXBhANwPtWqfJ3n9ykxqAhlFrZjyJujIXIkVpZ+F4 RiwEqonDQrgRGwHolQymFC+BULCxCjmerg/b/jleej4n/dHY3fz4OXGqHtSiTsRFyu /Qylq2cE8LdYw== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, jgross@suse.com, Bertrand.Marquis@arm.com, julien@xen.org, Volodymyr_Babchuk@epam.com, Luca Miccio , Stefano Stabellini , Bertrand Marquis Subject: [PATCH v3 3/5] xen/arm: configure dom0less domain for enabling xenstore after boot Date: Fri, 28 Jan 2022 13:33:04 -0800 Message-Id: <20220128213307.2822078-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1643405618490100003 Content-Type: text/plain; charset="utf-8" From: Luca Miccio If "xen,enhanced" is enabled, then add to dom0less domains: - the hypervisor node in device tree - the xenstore event channel The xenstore event channel is also used for the first notification to let the guest know that xenstore has become available. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini Reviewed-by: Bertrand Marquis CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis --- Changes in v3: - use evtchn_alloc_unbound Changes in v2: - set HVM_PARAM_STORE_PFN to ~0ULL at domain creation - in alloc_xenstore_evtchn do not call _evtchn_alloc_unbound --- xen/arch/arm/domain_build.c | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 9144d6c0b6..8e030a7f05 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -27,6 +27,7 @@ #include #include #include +#include =20 #include #include @@ -2619,6 +2620,8 @@ static int __init prepare_dtb_domU(struct domain *d, = struct kernel_info *kinfo) int ret; =20 kinfo->phandle_gic =3D GUEST_PHANDLE_GIC; + kinfo->gnttab_start =3D GUEST_GNTTAB_BASE; + kinfo->gnttab_size =3D GUEST_GNTTAB_SIZE; =20 addrcells =3D GUEST_ROOT_ADDRESS_CELLS; sizecells =3D GUEST_ROOT_SIZE_CELLS; @@ -2693,6 +2696,13 @@ static int __init prepare_dtb_domU(struct domain *d,= struct kernel_info *kinfo) goto err; } =20 + if ( kinfo->dom0less_enhanced ) + { + ret =3D make_hypervisor_node(d, kinfo, addrcells, sizecells); + if ( ret ) + goto err; + } + ret =3D fdt_end_node(kinfo->fdt); if ( ret < 0 ) goto err; @@ -2959,6 +2969,25 @@ static int __init construct_domain(struct domain *d,= struct kernel_info *kinfo) return 0; } =20 +static int __init alloc_xenstore_evtchn(struct domain *d) +{ + evtchn_alloc_unbound_t alloc; + int rc; + + alloc.dom =3D d->domain_id; + alloc.remote_dom =3D hardware_domain->domain_id; + rc =3D evtchn_alloc_unbound(&alloc, true); + if ( rc ) + { + printk("Failed allocating event channel for domain\n"); + return rc; + } + + d->arch.hvm.params[HVM_PARAM_STORE_EVTCHN] =3D alloc.port; + + return 0; +} + static int __init construct_domU(struct domain *d, const struct dt_device_node *node) { @@ -3014,7 +3043,19 @@ static int __init construct_domU(struct domain *d, return rc; =20 if ( kinfo.vpl011 ) + { rc =3D domain_vpl011_init(d, NULL); + if ( rc < 0 ) + return rc; + } + + if ( kinfo.dom0less_enhanced ) + { + rc =3D alloc_xenstore_evtchn(d); + if ( rc < 0 ) + return rc; + d->arch.hvm.params[HVM_PARAM_STORE_PFN] =3D ~0ULL; + } =20 return rc; } --=20 2.25.1 From nobody Fri Nov 29 09:21:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1643405615; cv=none; d=zohomail.com; s=zohoarc; b=hQcqfOiSFu4PJB/WpIFxZK3vcW6bDS3oqCSBsF8tdbBHuymjjZ7DyWV1ev9KeKGq+fCZ9uj0kq1koDFhEk7JlvwBgFeK6xN+PFXaq71bnLFpKVjjNwrq+Id8w16ilblPXY7qdbNQkmz7NoeLzv5fkT67AEu1nztBZ8EundxFQlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643405615; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JGvpopaI837HOOyNcEoAxL1XCFEdCdAn0PIe/X3pm6c=; b=BjAdy9lziqsdVYRXPGvgq47k0mf/uu7fkfgHqEpl+Q5s9+GDJHOtSxA+fUSxZAukK773akoSJt7PT1enZDi2kyasbhLDxJ2mwc5xNlAnio26Tl9vYp3d4bqmd8BjD6EdI4O8OLSYDofEw9ezGudi0htf8qWeij15pdaR558VOhI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16434056158021010.9268314979811; Fri, 28 Jan 2022 13:33:35 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.262149.454322 (Exim 4.92) (envelope-from ) id 1nDYrt-0002Mm-JI; Fri, 28 Jan 2022 21:33:17 +0000 Received: by outflank-mailman (output) from mailman id 262149.454322; Fri, 28 Jan 2022 21:33:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrt-0002K1-9V; Fri, 28 Jan 2022 21:33:17 +0000 Received: by outflank-mailman (input) for mailman id 262149; Fri, 28 Jan 2022 21:33:15 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrr-0001cx-6y for xen-devel@lists.xenproject.org; Fri, 28 Jan 2022 21:33:15 +0000 Received: from ams.source.kernel.org (ams.source.kernel.org [2604:1380:4601:e00::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e61555c2-8081-11ec-8eb8-a37418f5ba1a; Fri, 28 Jan 2022 22:33:14 +0100 (CET) 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 C32B7B82712; Fri, 28 Jan 2022 21:33:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A333C340EE; Fri, 28 Jan 2022 21:33:12 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e61555c2-8081-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643405592; bh=uo5SD5LknaPvjJ9o9KYAlXFMnGBluvR70SgtsEcJmPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qS5bRtf9dV22ICIT+x5QZ2noHh8He9luIbktKoCmhY5OGZngy+eTM7I49jDQ/13Aw yXcedtKzNAUUf6WosIsKmjXl8mZZtIDpGOBra2mhp6cunv2m58uCxxqCg8rPF42gZ/ sUig1fxB3dN3HycV8EfnhlxpUNWL8iaTMUWsNJSSf6fC6eYPAKCzA1W3U+IOR1zEWJ w+XXBEs+MXyZFOSLft9ec/HAMer96h+tGmCNVTouhPrmkoLp0Ea5toXDAzgjcg0ze4 iNrV0Tr9ZiROtZis07SaK37Lq7dJXDtOEYT64hxqLI4WSQzMgCsfpf2NU4vEVkVKVh He/BWwNTfYoIw== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, jgross@suse.com, Bertrand.Marquis@arm.com, julien@xen.org, Volodymyr_Babchuk@epam.com, Luca Miccio , Stefano Stabellini , Bertrand Marquis Subject: [PATCH v3 4/5] xenstored: send an evtchn notification on introduce_domain Date: Fri, 28 Jan 2022 13:33:05 -0800 Message-Id: <20220128213307.2822078-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 X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1643405618479100002 Content-Type: text/plain; charset="utf-8" From: Luca Miccio When xs_introduce_domain is called, send out a notification on the xenstore event channel so that any (dom0less) domain waiting for the xenstore interface to be ready can continue with the initialization. The extra notification is harmless for domains that don't require it. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini Reviewed-by: Bertrand Marquis --- Changes in v2: - drop the new late_init parameter --- tools/xenstore/xenstored_domain.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index d03c7d93a9..7487129e47 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -461,6 +461,9 @@ static struct domain *introduce_domain(const void *ctx, /* Now domain belongs to its connection. */ talloc_steal(domain->conn, domain); =20 + /* Notify the domain that xenstore is available */ + xenevtchn_notify(xce_handle, domain->port); + if (!is_master_domain && !restore) fire_watches(NULL, ctx, "@introduceDomain", NULL, false, NULL); --=20 2.25.1 From nobody Fri Nov 29 09:21:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1643405617; cv=none; d=zohomail.com; s=zohoarc; b=ZrCgdb1sm1DdHRDtvQ7eqPvTZKBS0mFNgKXNe6G30oJ2FDK9HI8aBUErGJgr8vW3mN2BD+QgPqPdcXn7L08Rqt+G4LXk6JZjR1jn2WG5Wu31J3hLKevqVPFIQxRS086mHq9q6HJoKHmLjYAMJiY29qjvN1VRwoZIZ4lXfxvvjRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643405617; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=46qn5qHgkWfLorWmUS4UTBuRMfF/pQBzeJTycw6WvXU=; b=KqCF29TKOYNBpZiI51J2ak+QLQ+J6jaLc2S321kPWygVrxtmy8KMA4jr8gmTaa4JYglzxfuGmfCCG+Ycr6It5UQwrZVAdCq0npR2r9wB8ouTQercFK4Z99/IQYkvJptMm18n5gS2baVbonMnPuSaEFsCuRTV4k+mV24n2uVPSXs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 164340561734519.8955479018573; Fri, 28 Jan 2022 13:33:37 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.262150.454325 (Exim 4.92) (envelope-from ) id 1nDYrt-0002RM-SX; Fri, 28 Jan 2022 21:33:17 +0000 Received: by outflank-mailman (output) from mailman id 262150.454325; Fri, 28 Jan 2022 21:33:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrt-0002Oh-MX; Fri, 28 Jan 2022 21:33:17 +0000 Received: by outflank-mailman (input) for mailman id 262150; Fri, 28 Jan 2022 21:33:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDYrs-0001cx-6u for xen-devel@lists.xenproject.org; Fri, 28 Jan 2022 21:33:16 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e5c69e33-8081-11ec-8eb8-a37418f5ba1a; Fri, 28 Jan 2022 22:33:14 +0100 (CET) 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 4310261EB0; Fri, 28 Jan 2022 21:33:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B52AC340E8; Fri, 28 Jan 2022 21:33:12 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e5c69e33-8081-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643405593; bh=bEd7iBxH0aTKKnunQQ2/vuu6A9e4BjW1WCimR3ym00Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qyafbf/DFj4CCLbH9w/HQJdusfkxlSlAd+e3fJcGSBvI6T43KCYyi81Ou4Rb7HCzX IeGsbxpjJiGt8j4T1LNSQOmiNGTUqKBAYmOkEB1HeryGonv1bqezuwzOzCjZXTZQNZ j3Yr0cAcI94uJdWwmv8fhzqR7zIvLkiPKjXo2t66irVGc3fpdoOGKXq8txMZ1RuhUL jMYXy7htJ6VWj3rJq3M+8Ye4xTAE6jnxfxgpy32B4MU5te/QYuruM9W/n4LU36Bhxh YcD325IUHxtpPe4IVrFkAWmUii9ktXrPt3Pp+oQ0m7x/ouEWO1oGoDPM7b+oAStXl2 szmucjY0XGb2Q== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, jgross@suse.com, Bertrand.Marquis@arm.com, julien@xen.org, Volodymyr_Babchuk@epam.com, Luca Miccio , Stefano Stabellini , Wei Liu , Anthony PERARD Subject: [PATCH v3 5/5] tools: add example application to initialize dom0less PV drivers Date: Fri, 28 Jan 2022 13:33:06 -0800 Message-Id: <20220128213307.2822078-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 X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1643405618550100006 Content-Type: text/plain; charset="utf-8" From: Luca Miccio Add an example application that can be run in dom0 to complete the dom0less domains initialization so that they can get access to xenstore and use PV drivers. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini CC: Wei Liu CC: Anthony PERARD CC: Juergen Gross --- Changes in v3: - handle xenstore errors - add an in-code comment about xenstore entries - less verbose output - clean-up error path in main Changes in v2: - do not set HVM_PARAM_STORE_EVTCHN twice - rename restore_xenstore to create_xenstore - increase maxmem --- tools/helpers/Makefile | 13 ++ tools/helpers/init-dom0less.c | 269 ++++++++++++++++++++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 tools/helpers/init-dom0less.c diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile index 7f6c422440..8e42997052 100644 --- a/tools/helpers/Makefile +++ b/tools/helpers/Makefile @@ -10,6 +10,9 @@ ifeq ($(CONFIG_Linux),y) ifeq ($(CONFIG_X86),y) PROGS +=3D init-xenstore-domain endif +ifeq ($(CONFIG_ARM),y) +PROGS +=3D init-dom0less +endif endif =20 XEN_INIT_DOM0_OBJS =3D xen-init-dom0.o init-dom-json.o @@ -26,6 +29,13 @@ $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS +=3D $(CFLAGS_libxe= nstore) $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS +=3D $(CFLAGS_libxenlight) $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS +=3D -include $(XEN_ROOT)/tools/confi= g.h =20 +INIT_DOM0LESS_OBJS =3D init-dom0less.o init-dom-json.o +$(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxentoollog) +$(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxenstore) +$(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxenlight) +$(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxenctrl) +$(INIT_DOM0LESS_OBJS): CFLAGS +=3D $(CFLAGS_libxenevtchn) + .PHONY: all all: $(PROGS) =20 @@ -35,6 +45,9 @@ xen-init-dom0: $(XEN_INIT_DOM0_OBJS) init-xenstore-domain: $(INIT_XENSTORE_DOMAIN_OBJS) $(CC) $(LDFLAGS) -o $@ $(INIT_XENSTORE_DOMAIN_OBJS) $(LDLIBS_libxentoollo= g) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIB= S_libxenlight) $(APPEND_LDFLAGS) =20 +init-dom0less: $(INIT_DOM0LESS_OBJS) + $(CC) $(LDFLAGS) -o $@ $(INIT_DOM0LESS_OBJS) $(LDLIBS_libxenctrl) $(LDLIB= S_libxenevtchn) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libx= enlight) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS) + .PHONY: install install: all $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN) diff --git a/tools/helpers/init-dom0less.c b/tools/helpers/init-dom0less.c new file mode 100644 index 0000000000..b6a3831cb5 --- /dev/null +++ b/tools/helpers/init-dom0less.c @@ -0,0 +1,269 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "init-dom-json.h" + +#define NR_MAGIC_PAGES 4 +#define CONSOLE_PFN_OFFSET 0 +#define XENSTORE_PFN_OFFSET 1 +#define STR_MAX_LENGTH 64 + +static int alloc_magic_pages(libxl_dominfo *info, struct xc_dom_image *dom) +{ + int rc, i; + const xen_pfn_t base =3D GUEST_MAGIC_BASE >> XC_PAGE_SHIFT; + xen_pfn_t p2m[NR_MAGIC_PAGES]; + + rc =3D xc_domain_setmaxmem(dom->xch, dom->guest_domid, + info->max_memkb + NR_MAGIC_PAGES * 4); + if (rc < 0) + return rc; + + for (i =3D 0; i < NR_MAGIC_PAGES; i++) + p2m[i] =3D base + i; + + rc =3D xc_domain_populate_physmap_exact(dom->xch, dom->guest_domid, + NR_MAGIC_PAGES, 0, 0, p2m); + if (rc < 0) + return rc; + + dom->xenstore_pfn =3D base + XENSTORE_PFN_OFFSET; + + xc_clear_domain_page(dom->xch, dom->guest_domid, dom->xenstore_pfn); + + xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_PFN, + dom->xenstore_pfn); + return 0; +} + +static bool do_xs_write_dom(struct xs_handle *xsh, xs_transaction_t t, + domid_t domid, char *path, char *val) +{ + char full_path[STR_MAX_LENGTH]; + + snprintf(full_path, STR_MAX_LENGTH, + "/local/domain/%d/%s", domid, path); + return xs_write(xsh, t, full_path, val, strlen(val)); +} + +static bool do_xs_write_libxl(struct xs_handle *xsh, xs_transaction_t t, + domid_t domid, char *path, char *val) +{ + char full_path[STR_MAX_LENGTH]; + + snprintf(full_path, STR_MAX_LENGTH, + "/libxl/%d/%s", domid, path); + return xs_write(xsh, t, full_path, val, strlen(val)); +} + +static bool do_xs_write_vm(struct xs_handle *xsh, xs_transaction_t t, + libxl_uuid uuid, char *path, char *val) +{ + char full_path[STR_MAX_LENGTH]; + + snprintf(full_path, STR_MAX_LENGTH, + "/vm/" LIBXL_UUID_FMT "/%s", LIBXL_UUID_BYTES(uuid), path); + return xs_write(xsh, t, full_path, val, strlen(val)); +} + +/* + * The xenstore nodes are the xenstore nodes libxl writes at domain + * creation. + * + * The list was retrieved by running xenstore-ls on a corresponding + * domain started by xl/libxl. + */ +static int restore_xenstore(struct xs_handle *xsh, + libxl_dominfo *info, libxl_uuid uuid, + evtchn_port_t xenstore_port) +{ + domid_t domid; + int i; + char uuid_str[STR_MAX_LENGTH]; + char dom_name_str[STR_MAX_LENGTH]; + char vm_val_str[STR_MAX_LENGTH]; + char id_str[STR_MAX_LENGTH]; + char max_memkb_str[STR_MAX_LENGTH]; + char cpu_str[STR_MAX_LENGTH]; + char xenstore_port_str[STR_MAX_LENGTH]; + char ring_ref_str[STR_MAX_LENGTH]; + xs_transaction_t t; + + domid =3D info->domid; + snprintf(id_str, STR_MAX_LENGTH, "%d", domid); + snprintf(dom_name_str, STR_MAX_LENGTH, "dom0less-%d", domid); + snprintf(uuid_str, STR_MAX_LENGTH, LIBXL_UUID_FMT, LIBXL_UUID_BYTES(uu= id)); + snprintf(vm_val_str, STR_MAX_LENGTH, + "vm/" LIBXL_UUID_FMT, LIBXL_UUID_BYTES(uuid)); + snprintf(max_memkb_str, STR_MAX_LENGTH, "%lu", info->max_memkb); + snprintf(ring_ref_str, STR_MAX_LENGTH, "%lld", + (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + XENSTORE_PFN_OFFSET); + snprintf(xenstore_port_str, STR_MAX_LENGTH, "%d", xenstore_port); + +retry_transaction: + t =3D xs_transaction_start(xsh); + if (t =3D=3D XBT_NULL) + return -errno; + + /* /vm */ + if (!do_xs_write_vm(xsh, t, uuid, "name", dom_name_str)) return -EIO; + if (!do_xs_write_vm(xsh, t, uuid, "uuid", uuid_str)) return -EIO; + if (!do_xs_write_vm(xsh, t, uuid, "start_time", "0")) return -EIO; + + /* /domain */ + if (!do_xs_write_dom(xsh, t, domid, "vm", vm_val_str)) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "name", dom_name_str)) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "cpu", "")) return -EIO; + for (i =3D 0; i < info->vcpu_max_id; i++) { + snprintf(cpu_str, STR_MAX_LENGTH, "cpu/%d/availability/", i); + if (!do_xs_write_dom(xsh, t, domid, cpu_str, + (info->cpupool & (1 << i)) ? "online" : "offl= ine")) + return -EIO; + } + if (!do_xs_write_dom(xsh, t, domid, "cpu/0", "")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "cpu/availability", "online")) ret= urn -EIO; + + if (!do_xs_write_dom(xsh, t, domid, "memory", "")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "memory/static-max", max_memkb_str= )) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "memory/videoram", "-1")) return -= EIO; + + if (!do_xs_write_dom(xsh, t, domid, "device", "")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "device/suspend", "")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "device/suspend/event-channel", ""= )) return -EIO; + + if (!do_xs_write_dom(xsh, t, domid, "control", "")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "control/shutdown", "")) return -E= IO; + if (!do_xs_write_dom(xsh, t, domid, "control/feature-poweroff", "1")) = return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "control/feature-reboot", "1")) re= turn -EIO; + if (!do_xs_write_dom(xsh, t, domid, "control/feature-suspend", "")) re= turn -EIO; + if (!do_xs_write_dom(xsh, t, domid, "control/sysrq", "")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "control/platform-feature-multipro= cessor-suspend", "1")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "control", "platform-feature-xs_re= set_watches")) return -EIO; + + if (!do_xs_write_dom(xsh, t, domid, "domid", id_str)) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "data", "")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "drivers", "")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "feature", "")) return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "attr", "")) return -EIO; + + if (!do_xs_write_dom(xsh, t, domid, "store/port", xenstore_port_str)) = return -EIO; + if (!do_xs_write_dom(xsh, t, domid, "store/ring-ref", ring_ref_str)) r= eturn -EIO; + + if (!do_xs_write_libxl(xsh, t, domid, "type", "pvh")) return -EIO; + if (!do_xs_write_libxl(xsh, t, domid, "dm-version", "qemu_xen")) retur= n -EIO; + + if (!xs_transaction_end(xsh, t, false)) + if (errno =3D=3D EAGAIN) + goto retry_transaction; + else + return -errno; + + return 0; +} + +static int init_domain(struct xs_handle *xsh, libxl_dominfo *info) +{ + struct xc_dom_image dom; + libxl_uuid uuid; + uint64_t v; + int rc; + + printf("Init dom0less domain: %d\n", info->domid); + dom.guest_domid =3D info->domid; + dom.xenstore_domid =3D 0; + dom.xch =3D xc_interface_open(0, 0, 0); + + rc =3D xc_hvm_param_get(dom.xch, info->domid, HVM_PARAM_STORE_EVTCHN, = &v); + if (rc !=3D 0) { + printf("Failed to get HVM_PARAM_STORE_EVTCHN\n"); + return 1; + } + dom.xenstore_evtchn =3D v; + + /* Console won't be initialized but set its data for completeness */ + dom.console_domid =3D 0; + + /* Alloc magic pages */ + if (alloc_magic_pages(info, &dom) !=3D 0) { + printf("Error on alloc magic pages\n"); + return 1; + } + + xc_dom_gnttab_init(&dom); + + libxl_uuid_generate(&uuid); + xc_domain_sethandle(dom.xch, info->domid, libxl_uuid_bytearray(&uuid)); + + rc =3D gen_stub_json_config(info->domid, &uuid); + if (rc) + err(1, "gen_stub_json_config"); + + rc =3D restore_xenstore(xsh, info, uuid, dom.xenstore_evtchn); + if (rc) + err(1, "writing to xenstore"); + + xs_introduce_domain(xsh, info->domid, + (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + XENSTORE_PFN_OFFSET, + dom.xenstore_evtchn); + return 0; +} + +/* Check if domain has been configured in XS */ +static bool domain_exists(struct xs_handle *xsh, int domid) +{ + return xs_is_domain_introduced(xsh, domid); +} + +int main(int argc, char **argv) +{ + libxl_dominfo *info =3D NULL; + libxl_ctx *ctx; + int nb_vm =3D 0, rc =3D 0, i; + struct xs_handle *xsh =3D NULL; + + xsh =3D xs_daemon_open(); + if (xsh =3D=3D NULL) { + fprintf(stderr, "Could not contact XenStore"); + rc =3D -errno; + goto out; + } + + rc =3D libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, NULL); + if (rc) { + fprintf(stderr, "cannot init xl context\n"); + goto out; + } + + info =3D libxl_list_domain(ctx, &nb_vm); + if (!info) { + fprintf(stderr, "libxl_list_vm failed.\n"); + rc =3D -1; + goto out; + } + + for (i =3D 0; i < nb_vm; i++) { + domid_t domid =3D info[i].domid; + + /* Don't need to check for Dom0 */ + if (!domid) + continue; + + printf("Checking domid: %u\n", domid); + if (!domain_exists(xsh, domid)) + init_domain(xsh, &info[i]); + else + printf("Domain %d has already been initialized\n", domid); + } +out: + libxl_dominfo_list_free(info, nb_vm); + xs_close(xsh); + return rc; +} --=20 2.25.1