From nobody Fri Nov 29 10:31:58 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=1641602992; cv=none; d=zohomail.com; s=zohoarc; b=SpQmRtMGApf3vuCYtFvD+eE9dXPy1qQQpjbGeENacp2FZivgRVOaSmWPNkc7ZIsuS67/JlqWqG3iqDYMkobVUA+S49W8WoVBiHUS7J2FsrLdO2/VpnSmDtkkRdVfQmfx1FElUKqRsHjxYJRHGbC92iUJmaDh4htyzFXhKJ6lqgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641602992; 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=BvkRrmBq4vV8aOi+h1JSeIbjQ0DsuWKl7c8CzurIIFo=; b=IsCKftNc5EAcOUkcE/C59oqOMzXgdNRx9iizOE+DREIiMwj1zQiybL4pca9ivIMQ0Zsp1iw7xjhP8UgFvRI5c9GMQqJVb4FxLNDsgZmw2lVTsM2lx5WozX0SmI93qPMObO4bcQpt+cLg+JNFtuhmABgqb1I+mnNVG3tD/QVX4o4= 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 1641602992401577.5438978594651; Fri, 7 Jan 2022 16:49:52 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.254710.436507 (Exim 4.92) (envelope-from ) id 1n5zv4-0006rC-H9; Sat, 08 Jan 2022 00:49:18 +0000 Received: by outflank-mailman (output) from mailman id 254710.436507; Sat, 08 Jan 2022 00:49:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n5zv4-0006r5-E7; Sat, 08 Jan 2022 00:49:18 +0000 Received: by outflank-mailman (input) for mailman id 254710; Sat, 08 Jan 2022 00:49:17 +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 1n5zv2-0006ZD-Uu for xen-devel@lists.xenproject.org; Sat, 08 Jan 2022 00:49:17 +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 cd98067b-701c-11ec-9ce5-af14b9085ebd; Sat, 08 Jan 2022 01:49:16 +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 E47EC62044; Sat, 8 Jan 2022 00:49:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA0A2C36AED; Sat, 8 Jan 2022 00:49:13 +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: cd98067b-701c-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641602954; bh=m/xs8jzbYy0KnjGA4YEq7wqnz5M74arMWbE5OnRY2a8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IqjZ2jB++HvGbybnwDVSteXiREAUHykf8HcStkfcW61SIEzZFfhY+l8iloW2hHbK8 6JlN6lRLPTiY7kjMpXf00cHWAah97cBU7SrZIp9b5ExEwXvlUf5ln4CRQ4XkQ7KEgY Jl0ZnKG5jLUUQAxHMwtv9YGTjeCnhbOJFj73nJ0Fv9y30UlHC7xnZXhBZYFCyX2O5+ jvJl+7dJaVXNKCJwTAVkoMoumCcyJZRTzchP8Fqx0v4e1bwqK7xYRzdBa7gAl+L8To vDNvDydccEbcVXlIv17pelZKuQpkgz3DbN0RisiIx235g1vmIB/HWRcBnfNnrt7rbP d8/KnZceh1+fA== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, julien@xen.org, Bertrand.Marquis@arm.com, Luca Miccio , Stefano Stabellini , Volodymyr Babchuk , Bertrand Marquis , Andrew Cooper , Jan Beulich , George Dunlap , Wei Liu Subject: [XEN PATCH 1/7] xen: introduce XENFEAT_xenstore_late_init Date: Fri, 7 Jan 2022 16:49:06 -0800 Message-Id: <20220108004912.3820176-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: 1641602993127100002 Content-Type: text/plain; charset="utf-8" From: Luca Miccio Introduce a new feature flag to signal that xenstore will not be immediately available at boot time. Instead, xenstore will become available later, and a notification of xenstore readiness will be signalled to the guest using the xenstore event channel. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Andrew Cooper CC: Jan Beulich CC: George Dunlap CC: Wei Liu --- xen/arch/arm/include/asm/domain.h | 2 ++ xen/common/kernel.c | 2 ++ xen/include/public/features.h | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/d= omain.h index 9b3647587a..e5ae57cd09 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -89,6 +89,8 @@ struct arch_domain #ifdef CONFIG_TEE void *tee; #endif + /* Is this guest a dom0less domain? */ + bool is_dom0less; } __cacheline_aligned; =20 struct arch_vcpu diff --git a/xen/common/kernel.c b/xen/common/kernel.c index e119e5401f..c00ea67e5f 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -550,6 +550,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) a= rg) if ( is_hardware_domain(d) ) fi.submap |=3D 1U << XENFEAT_dom0; #ifdef CONFIG_ARM + if ( d->arch.is_dom0less ) + fi.submap |=3D (1U << XENFEAT_xenstore_late_init); fi.submap |=3D (1U << XENFEAT_ARM_SMCCC_supported); #endif #ifdef CONFIG_X86 diff --git a/xen/include/public/features.h b/xen/include/public/features.h index 9ee2f760ef..18f32b1a98 100644 --- a/xen/include/public/features.h +++ b/xen/include/public/features.h @@ -128,6 +128,12 @@ #define XENFEAT_not_direct_mapped 16 #define XENFEAT_direct_mapped 17 =20 +/* + * The xenstore interface should be initialized only after receiving a + * xenstore event channel notification. + */ +#define XENFEAT_xenstore_late_init 18 + #define XENFEAT_NR_SUBMAPS 1 =20 #endif /* __XEN_PUBLIC_FEATURES_H__ */ --=20 2.25.1 From nobody Fri Nov 29 10:31:58 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=1641602991; cv=none; d=zohomail.com; s=zohoarc; b=VCdJD14n2y748xK5cPBh7AKzW7telqX/zj4hHtTy2PHiYwq3wqayxagMe+Zx1elV7umKchEpI67S0Rhx41o4DSclT6S2IPku2pS+4Qoqhwoer8+yFIdDkc7F+IPSoAB/BEU1V1pNUylC4sEliHcXIogJfIoHqlZR14irx4Boj14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641602991; 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=Cg/0KuHvaF5Txa0aRyRfstZ6qiHJ95oho/J5LeSFfvk=; b=Y7rG5v7FLKlSomPIW3illPLcMnUAlk2Df8yVJxabVqo9QhP2aQ3/eKWy0ppU3PHaI1AfNLuRT5D0hCIwwTExqRb3ddTBXU3haP4oYjjFpq2459lSelFc0hfGAw1BNEcpOxuw9cJ46e9X5VDIBXyT7Xx+HrdgD/r93X9M1W7hVzo= 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 1641602991328937.7307445037915; Fri, 7 Jan 2022 16:49:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.254714.436535 (Exim 4.92) (envelope-from ) id 1n5zv8-0007SO-AW; Sat, 08 Jan 2022 00:49:22 +0000 Received: by outflank-mailman (output) from mailman id 254714.436535; Sat, 08 Jan 2022 00:49:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n5zv7-0007Nl-UE; Sat, 08 Jan 2022 00:49:21 +0000 Received: by outflank-mailman (input) for mailman id 254714; Sat, 08 Jan 2022 00:49:20 +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 1n5zv6-000706-1v for xen-devel@lists.xenproject.org; Sat, 08 Jan 2022 00:49:20 +0000 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ce8f032a-701c-11ec-81c1-a30af7de8005; Sat, 08 Jan 2022 01:49:17 +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 3C23DB827C0; Sat, 8 Jan 2022 00:49:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82219C36AEF; Sat, 8 Jan 2022 00:49:14 +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: ce8f032a-701c-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641602955; bh=5gqnkAJOfXnqVGXZ1qlNwhP+taPqzRbwoAe4Pxn2FBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OyHNvkvda/IppfmN5ffOApPiggGKdA6fHkKcxGtbEGfmCurNqL9cCKuEdWr40fJDA 4oC9SKxj8Ik2xh0JVoU3jItm0cwkfAtmPxE94JyN5/hR0INnezaoHoSj44UoDiCxBa ilacuOy5whBIAbd1PbBP6MByN/c+Bvg92LcxBKpwsYxfDoHmi8TUgrKar2wKndw+Mm eaI2MT5baBcnxq/rxkOJhS60EZMOs1kK4sHnwdWzOZ6CQw+HXjnXmAYfwYPTQle30n bU8I4dUnMqpKdqLfhIckxGT4nfCCw6HZTiZK0TomvlNBzq7MgsZjCG1nLLFIU1oZNa wxR6k7hYry/Vw== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, julien@xen.org, Bertrand.Marquis@arm.com, Luca Miccio , Stefano Stabellini , Volodymyr Babchuk , Bertrand Marquis , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [XEN PATCH 2/7] xen: introduce _evtchn_alloc_unbound Date: Fri, 7 Jan 2022 16:49:07 -0800 Message-Id: <20220108004912.3820176-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: 1641602993133100003 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. Factor out the part that actually allocates the event channel from evtchn_alloc_unbound and introduce this new function as _evtchn_alloc_unbound. (xsm_evtchn_unbound wouldn't work for a call originated from Xen.) 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 --- xen/common/event_channel.c | 49 +++++++++++++++++++++++++------------- xen/include/xen/event.h | 3 +++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index da88ad141a..8a19bbf7ae 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -18,6 +18,7 @@ =20 #include #include +#include #include #include #include @@ -284,11 +285,32 @@ 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) +struct evtchn *_evtchn_alloc_unbound(struct domain *d, domid_t remote_dom) { struct evtchn *chn; + int port; + + if ( (port =3D get_free_port(d)) < 0 ) + return ERR_PTR(port); + chn =3D evtchn_from_port(d, port); + + evtchn_write_lock(chn); + + chn->state =3D ECS_UNBOUND; + if ( (chn->u.unbound.remote_domid =3D remote_dom) =3D=3D DOMID_SELF ) + chn->u.unbound.remote_domid =3D current->domain->domain_id; + evtchn_port_init(d, chn); + + evtchn_write_unlock(chn); + + return chn; +} + +static int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) +{ + struct evtchn *chn =3D NULL; struct domain *d; - int port, rc; + int rc; domid_t dom =3D alloc->dom; =20 d =3D rcu_lock_domain_by_any_id(dom); @@ -297,27 +319,22 @@ static int evtchn_alloc_unbound(evtchn_alloc_unbound_= t *alloc) =20 spin_lock(&d->event_lock); =20 - if ( (port =3D get_free_port(d)) < 0 ) - ERROR_EXIT_DOM(port, d); - chn =3D evtchn_from_port(d, port); + chn =3D _evtchn_alloc_unbound(d, alloc->remote_dom); + if ( IS_ERR(chn) ) + { + rc =3D PTR_ERR(chn); + ERROR_EXIT_DOM(rc, d); + } =20 rc =3D xsm_evtchn_unbound(XSM_TARGET, d, chn, alloc->remote_dom); if ( rc ) goto out; =20 - evtchn_write_lock(chn); - - chn->state =3D ECS_UNBOUND; - if ( (chn->u.unbound.remote_domid =3D alloc->remote_dom) =3D=3D DOMID_= SELF ) - chn->u.unbound.remote_domid =3D current->domain->domain_id; - evtchn_port_init(d, chn); - - evtchn_write_unlock(chn); - - alloc->port =3D port; + alloc->port =3D chn->port; =20 out: - check_free_port(d, port); + if ( chn !=3D NULL ) + check_free_port(d, chn->port); spin_unlock(&d->event_lock); rcu_unlock_domain(d); =20 diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 21c95e14fd..6aedbccbf1 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 */ +struct evtchn *_evtchn_alloc_unbound(struct domain *d, domid_t remote_dom); + /* 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 10:31:58 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=1641602994; cv=none; d=zohomail.com; s=zohoarc; b=LZBh+HFUsGE64Siy5HH2B8TCE/7PpcKqGwdvGCfoKYT5H0vFELqPePTAPiaJNGU4Q2pRmYJElF+kyyTlNcpolcoXo45vlqoUJdeEj+AdYsSTKLfNpAIars2vm0mWvu66+hGJsECTVXIGLrwoQpf1iU8X2PitBIOruSthlrA25I4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641602994; 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=Wilri6x6XwWzfVzd8RMkoVryfN1MgwiEKn0ujqREUmw=; b=m6wD8gdvx7zg6W9YqHkMvEm2krOIf2M2E5H5zdnEn0cwf78JWpI/Ap+WcfsBOFUA7RfwxI9LXmlB8lbKgmHEJ1YRMOC+RqWpoGhmWgoz87DiHAooNnGfZeFNGFTKhf2OLmn4BkGlFZJ2LVy3BEZ814RrG1llo1HtWN1IljrG714= 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 1641602994288123.99738313160265; Fri, 7 Jan 2022 16:49:54 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.254711.436518 (Exim 4.92) (envelope-from ) id 1n5zv6-00079E-Th; Sat, 08 Jan 2022 00:49:20 +0000 Received: by outflank-mailman (output) from mailman id 254711.436518; Sat, 08 Jan 2022 00:49:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n5zv6-000795-QQ; Sat, 08 Jan 2022 00:49:20 +0000 Received: by outflank-mailman (input) for mailman id 254711; Sat, 08 Jan 2022 00:49:18 +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 1n5zv4-0006ZD-Mm for xen-devel@lists.xenproject.org; Sat, 08 Jan 2022 00:49:18 +0000 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cea63d42-701c-11ec-9ce5-af14b9085ebd; Sat, 08 Jan 2022 01:49:17 +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 BBC23B827C3; Sat, 8 Jan 2022 00:49:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 260ABC36AF2; Sat, 8 Jan 2022 00:49:15 +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: cea63d42-701c-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641602955; bh=CDrrsjp15mArIctwhofaLq+GzkkGMG31l1XpyQakdzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s74qh4wvO/RR5LKh2IfvYR0fI8rZcLCQBUPotG3Wn3UDmMsFW0QCH5MHCj429aRAh aIhbDeAwPiR6i5MQ1ZDd+alEHNMTgPj99tsWXRKY+cl+IHOMwlbBVPu4DmgALRqhiP DalkoftRyp5urKCOIXjdbcYtFyu0KQqf5fows7xgQj5L0DIHfm/gi+vj5OzSL1T++I QLe2N9bV+VFuUdwtWngQndeKQqXV1/OcSrfxNAwAUMATToEOO6NtBUbKil5Qaxq9uI wPdqgmIof2B4iM03YbxZBjt5Ad4f/dfOXDum/h/zVGa/5psoz74oOvFoY7Ek8UPbde Gi1USrNk+/U3A== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, julien@xen.org, Bertrand.Marquis@arm.com, Luca Miccio , Stefano Stabellini , wl@xen.org, anthony.perard@citrix.com, jgross@suse.com, marmarek@invisiblethingslab.com Subject: [XEN PATCH 3/7] tools: add a late_init argument to xs_introduce_domain Date: Fri, 7 Jan 2022 16:49:08 -0800 Message-Id: <20220108004912.3820176-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: 1641602994970100009 Content-Type: text/plain; charset="utf-8" From: Luca Miccio Add a late_init argument to xs_introduce_domain to handle dom0less guests whose xenstore interfaces are initialized after boot. This patch mechanically adds the new parameter; it doesn't change behaviors. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini CC: wl@xen.org CC: anthony.perard@citrix.com CC: jgross@suse.com CC: marmarek@invisiblethingslab.com Acked-by: Marek Marczykowski-G=C3=B3recki --- tools/include/xenstore.h | 3 ++- tools/libs/light/libxl_dom.c | 3 ++- tools/libs/store/xs.c | 8 ++++++-- tools/python/xen/lowlevel/xs/xs.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/include/xenstore.h b/tools/include/xenstore.h index 2b3f69fb61..1a302b5ff9 100644 --- a/tools/include/xenstore.h +++ b/tools/include/xenstore.h @@ -226,7 +226,8 @@ bool xs_transaction_end(struct xs_handle *h, xs_transac= tion_t t, bool xs_introduce_domain(struct xs_handle *h, unsigned int domid, unsigned long mfn, - unsigned int eventchn);=20 + unsigned int eventchn, + bool late_init); =20 /* Set the target of a domain * This tells the store daemon that a domain is targetting another one, so diff --git a/tools/libs/light/libxl_dom.c b/tools/libs/light/libxl_dom.c index 2abaab439c..bacfdfa9df 100644 --- a/tools/libs/light/libxl_dom.c +++ b/tools/libs/light/libxl_dom.c @@ -497,7 +497,8 @@ retry_transaction: if (!xs_transaction_end(ctx->xsh, t, 0)) if (errno =3D=3D EAGAIN) goto retry_transaction; - xs_introduce_domain(ctx->xsh, domid, state->store_mfn, state->store_po= rt); + xs_introduce_domain(ctx->xsh, domid, state->store_mfn, state->store_po= rt, + false); free(vm_path); return 0; } diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c index 7a9a8b1656..dd47d607fd 100644 --- a/tools/libs/store/xs.c +++ b/tools/libs/store/xs.c @@ -1089,16 +1089,18 @@ bool xs_transaction_end(struct xs_handle *h, xs_tra= nsaction_t t, */ bool xs_introduce_domain(struct xs_handle *h, unsigned int domid, unsigned long mfn, - unsigned int eventchn) + unsigned int eventchn, bool late_init) { char domid_str[MAX_STRLEN(domid)]; char mfn_str[MAX_STRLEN(mfn)]; char eventchn_str[MAX_STRLEN(eventchn)]; - struct iovec iov[3]; + char late_init_str[MAX_STRLEN(late_init)]; + struct iovec iov[4]; =20 snprintf(domid_str, sizeof(domid_str), "%u", domid); snprintf(mfn_str, sizeof(mfn_str), "%lu", mfn); snprintf(eventchn_str, sizeof(eventchn_str), "%u", eventchn); + snprintf(late_init_str, sizeof(late_init_str), "%u", late_init); =20 iov[0].iov_base =3D domid_str; iov[0].iov_len =3D strlen(domid_str) + 1; @@ -1106,6 +1108,8 @@ bool xs_introduce_domain(struct xs_handle *h, iov[1].iov_len =3D strlen(mfn_str) + 1; iov[2].iov_base =3D eventchn_str; iov[2].iov_len =3D strlen(eventchn_str) + 1; + iov[3].iov_base =3D late_init_str; + iov[3].iov_len =3D strlen(late_init_str) + 1; =20 return xs_bool(xs_talkv(h, XBT_NULL, XS_INTRODUCE, iov, ARRAY_SIZE(iov), NULL)); diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/= xs/xs.c index 0dad7fa5f2..dc667fb231 100644 --- a/tools/python/xen/lowlevel/xs/xs.c +++ b/tools/python/xen/lowlevel/xs/xs.c @@ -678,7 +678,7 @@ static PyObject *xspy_introduce_domain(XsHandle *self, = PyObject *args) return NULL; =20 Py_BEGIN_ALLOW_THREADS - result =3D xs_introduce_domain(xh, dom, page, port); + result =3D xs_introduce_domain(xh, dom, page, port, false); Py_END_ALLOW_THREADS =20 return none(result); --=20 2.25.1 From nobody Fri Nov 29 10:31:58 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=1641602995; cv=none; d=zohomail.com; s=zohoarc; b=hn1pseAkCJH9K6VJAkuX4uzkbYtqQxZEuEsp0hKT2A8bvFAqAgIKkqT1zqSht+ypz7vviAbcpUjevmA+V59JcLwayW2V0XGFkqhqNtTVVcfSFfeo2xa83umy+nopX9nMhhUrHNNNnCEdwgjJoZGIdA6QSQegNzuvg2imm4GCGts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641602995; 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=tlSJ1JK700Gky8o3B1+M+nNyQaVgsFDFQoo1NmGFYt0=; b=VAWflH2ittHPu0FIeTxi3gkP2jA/58tYUnolG45NAZaQyYdscxEfXzA3iPPiBs0vMbi+cTPj9pcQPbkyw9HJzWF2bZtecO0BJV+Jny33pfeNStRksTLU2WAze2ZbHau6owBktDfJsrwcNfFOWwBPaU2L0eJbnKXVS0AkcuweuAM= 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 1641602995387913.8291087863862; Fri, 7 Jan 2022 16:49:55 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.254715.436542 (Exim 4.92) (envelope-from ) id 1n5zv8-0007Zm-N1; Sat, 08 Jan 2022 00:49:22 +0000 Received: by outflank-mailman (output) from mailman id 254715.436542; Sat, 08 Jan 2022 00:49:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n5zv8-0007XC-F8; Sat, 08 Jan 2022 00:49:22 +0000 Received: by outflank-mailman (input) for mailman id 254715; Sat, 08 Jan 2022 00:49:20 +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 1n5zv6-000706-JD for xen-devel@lists.xenproject.org; Sat, 08 Jan 2022 00:49:20 +0000 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cf1291ff-701c-11ec-81c1-a30af7de8005; Sat, 08 Jan 2022 01:49:17 +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 3C82AB827C2; Sat, 8 Jan 2022 00:49:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5CBBC36AF3; Sat, 8 Jan 2022 00:49:15 +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: cf1291ff-701c-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641602956; bh=+olmyE0Lg6XuJ73hfq8gcQj3c7BupLFwwV9RL76Bu44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nNV/gTQeGRQ8f5t89xOrXNtWlbNj9U75IkmCH/6RY5redkMDGlNG1vLgZiNEgMhP/ gyXfWgw2jNDAv3J8EqyZR5R9otT9s2PgRUjwUcZomzEjhH1yWYgkCmZd2Ctr0ftZ68 l1gvlZ+XC+0UNlLjoykroFfwSOmpLOPADceBNwLG4o4/jI4CILn08OPk8sO69w4MxD IUYmSn830YlpzxRUFGyjmcsHm23P+14kYDxS53zUfEL4u9rNADpgGwGz5ClLY7ZTzc 23XMy1ze1Il58U4eG0bBgbXJ/iEP3zJ5Ys5C5eJdAwHPx3dcf8Z1i3ZGSM/ABfq4kD 4Ov1JhRy++DaA== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, julien@xen.org, Bertrand.Marquis@arm.com, Stefano Stabellini , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH 4/7] xen: introduce xen,enhanced dom0less property Date: Fri, 7 Jan 2022 16:49:09 -0800 Message-Id: <20220108004912.3820176-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: 1641602996927100011 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.) This patch only parses the property. Next patches will make use of it. Signed-off-by: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis --- docs/misc/arm/device-tree/booting.txt | 18 ++++++++++++++++++ xen/arch/arm/domain_build.c | 5 +++++ xen/arch/arm/include/asm/kernel.h | 3 +++ 3 files changed, 26 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..96a94fa434 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 *enhanced; int rc; u64 mem; =20 @@ -2978,6 +2979,10 @@ 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", &enhanced); + if ( rc =3D=3D -EILSEQ || (rc =3D=3D 0 && !strcmp(enhanced, "enabled")= ) ) + kinfo.enhanced =3D true; + if ( vcpu_create(d, 0) =3D=3D NULL ) return -ENOMEM; =20 diff --git a/xen/arch/arm/include/asm/kernel.h b/xen/arch/arm/include/asm/k= ernel.h index 874aa108a7..3275f7fbca 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 enhanced; + /* GIC phandle */ uint32_t phandle_gic; =20 --=20 2.25.1 From nobody Fri Nov 29 10:31:58 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=1641602991; cv=none; d=zohomail.com; s=zohoarc; b=hV8FaKPgg3skUASYjCwULNTqf91kEFvlpg4MgK4kBhOQNauZ2/Aq6xgGEQv4MmwPoo5zDjMpBuIMN4739GF9+iAGm9alT8SowS3xM9KwtsyQnuclGLZbsBnnGr2A1giUqMF4GFIHnaYtD7fQ/cmv4n5gDuVQo2Cgt5+eunGm0lY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641602991; 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=gqR0xw/C57xWJN5gNpipHSKTTaTcqvE89XlLWiicR30=; b=LIO8TdCvmX/oSO9uE1UVuPJgr/HG+AmSVBklZhIOysB8/Q7qtq/M6H20meM5J6ZyTQRgVBaZpnJF0GS6sVhwNYjcRV1o1kKlMOFkontRxmoev/RmcQrfLFQGxz+kE0reapFuT73htFIR2OyXsYOIZmwtyIFcopOo/LuIBT/INY4= 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 1641602991809327.91974543815604; Fri, 7 Jan 2022 16:49:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.254712.436522 (Exim 4.92) (envelope-from ) id 1n5zv7-0007Bp-7u; Sat, 08 Jan 2022 00:49:21 +0000 Received: by outflank-mailman (output) from mailman id 254712.436522; Sat, 08 Jan 2022 00:49:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n5zv7-0007Ap-1r; Sat, 08 Jan 2022 00:49:21 +0000 Received: by outflank-mailman (input) for mailman id 254712; Sat, 08 Jan 2022 00:49:19 +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 1n5zv5-0006ZD-8T for xen-devel@lists.xenproject.org; Sat, 08 Jan 2022 00:49:19 +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 ce942e4f-701c-11ec-9ce5-af14b9085ebd; Sat, 08 Jan 2022 01:49:17 +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 952C362051; Sat, 8 Jan 2022 00:49:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21B41C36AE5; Sat, 8 Jan 2022 00:49:16 +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: ce942e4f-701c-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641602956; bh=EGPEVLXhWQH12aVdIUkqLBGXZpzA81egp2OEZ8dJ6zc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HxHAQ4ErTsDgZTJVOsdvzFyply9bIp/SE/doo34v6kN8UKl56zqHxHibiShim1DCc eBQpyhrRJuJm/gUm9SMcDbT/A3js3eECbvhVfFRyrBwm5OV6VEqH6U7XDuCP5Qo2kT wBua1BMGnNrlpJPtWqlRm1IzynYf2bC0S7Zkx+VxVvgi3DRzO2iozqOoLgq/hqRceA zgA4XAQ1R0Vs++rCzsX5KEj34miWSUbjdZGdqLVGvjNSQibghoVj9Sf7Z1/U77Z8Pa 29ZcCso8tfkE1QFCrRxpQpYHHc25J1bsnR+30DiIvnIodDTESBNRkQMlgEXqP55qyE F3huguX6N8eKA== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, julien@xen.org, Bertrand.Marquis@arm.com, Luca Miccio , Stefano Stabellini , Volodymyr Babchuk , Bertrand Marquis Subject: [XEN PATCH 5/7] xen/arm: configure dom0less domain for enabling xenstore after boot Date: Fri, 7 Jan 2022 16:49:10 -0800 Message-Id: <20220108004912.3820176-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: 1641602993121100001 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 CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis --- xen/arch/arm/domain_build.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 96a94fa434..fafa921aa8 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->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,22 @@ static int __init construct_domain(struct domain *d,= struct kernel_info *kinfo) return 0; } =20 +static int alloc_xenstore_evtchn(struct domain *d) +{ + struct evtchn *chn; + + chn =3D _evtchn_alloc_unbound(d, hardware_domain->domain_id); + if ( !chn ) + { + printk("Failed allocating event channel for domain\n"); + return -ENOMEM; + } + + d->arch.hvm.params[HVM_PARAM_STORE_EVTCHN] =3D chn->port; + + return 0; +} + static int __init construct_domU(struct domain *d, const struct dt_device_node *node) { @@ -3012,7 +3038,14 @@ 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.enhanced ) + rc =3D alloc_xenstore_evtchn(d); =20 return rc; } @@ -3068,6 +3101,7 @@ void __init create_domUs(void) panic("Error creating domain %s\n", dt_node_name(node)); =20 d->is_console =3D true; + d->arch.is_dom0less =3D true; =20 if ( construct_domU(d, node) !=3D 0 ) panic("Could not set up domain %s\n", dt_node_name(node)); --=20 2.25.1 From nobody Fri Nov 29 10:31:58 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=1641602997; cv=none; d=zohomail.com; s=zohoarc; b=XB/CyBiak72zrdEphxROwihyC6wf1Pn0inPjTxTbRCOfONzskyEGWn+NoRAHWMjKzRkkS5qLJPkSuv3KuhREKJ6a70JFDZU/V5urxm5QlYzRdhBDpR2udSV76CL/r8wRF9uIy73FeU5o1F+ToL35LzDFmiQMuEsXX4pz+pYVk4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641602997; 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=1uQGm4/NGVVr6vxCHEyl3fZ7rEL3l4RHOQZ3KgjY/Jg=; b=dLndzdVqwnyX1It4ERExwhiq+wAznm1+kqtT/sph6QSAFj3W6s/WNqvnVZ03qRDgA9h58zdmMDCEwEgS0ySu6yt0xd1zHW0rMV8rLtby8u56rYAw5D1inF7ykRuWRIHowXUIc3TkKzUgTgTZv6afYRgC55HGbwuBR9UbLRl4oRU= 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 1641602997263423.5036525803173; Fri, 7 Jan 2022 16:49:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.254713.436531 (Exim 4.92) (envelope-from ) id 1n5zv7-0007IK-S3; Sat, 08 Jan 2022 00:49:21 +0000 Received: by outflank-mailman (output) from mailman id 254713.436531; Sat, 08 Jan 2022 00:49:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n5zv7-0007GB-Fs; Sat, 08 Jan 2022 00:49:21 +0000 Received: by outflank-mailman (input) for mailman id 254713; Sat, 08 Jan 2022 00:49:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n5zv5-0006ZD-VP for xen-devel@lists.xenproject.org; Sat, 08 Jan 2022 00:49:20 +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 cee73143-701c-11ec-9ce5-af14b9085ebd; Sat, 08 Jan 2022 01:49:18 +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 160E96204B; Sat, 8 Jan 2022 00:49:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90EA5C36AEB; Sat, 8 Jan 2022 00:49:16 +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: cee73143-701c-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641602956; bh=1DYdXK2tClbqaET4zfKHxmO/dU14+PSWtdLzPmYufVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gLY7s9g3064cPYrRE0vNzRVXgTryktVR3QLtM4kE3r5euXcsNZ+6hrMLMK3HKx6ZG s32FqQpLcoOFboQTzsT4d90prWOHQmyiFCpz44a+v2N2cztLwc5P20cGSie7sIwH1d o2UQcGFaZ4G1llkvyRymE9gmjmE7w4QiJrTxXTSjYbjfjSqmCGFcl9orQnJ58v1QxF q4s2K4b5RZYwkCdxR2rE4hhYubafK/qe//k3LHBTcTxRJlFFp/Xo8kD53Ri9iBERRc e18UByRzR/lfAFIMS7AC/+/GvEh/SygHmg+g1FViVxIT9kMNSZ9nbSG7kg5KoxXAyU tSH0sDepqMCJA== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, julien@xen.org, Bertrand.Marquis@arm.com, Luca Miccio , Stefano Stabellini , wl@xen.org, Anthony PERARD , Juergen Gross Subject: [XEN PATCH 6/7] xenstored: do_introduce: handle the late_init case Date: Fri, 7 Jan 2022 16:49:11 -0800 Message-Id: <20220108004912.3820176-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 X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1641602998908100013 Content-Type: text/plain; charset="utf-8" From: Luca Miccio If the function is called with late_init set then also notify the domain using the xenstore event channel. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini CC: wl@xen.org CC: Anthony PERARD CC: Juergen Gross CC: julien@xen.org --- tools/xenstore/xenstored_domain.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index d03c7d93a9..17b8021ca8 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -429,7 +429,7 @@ static void domain_conn_reset(struct domain *domain) =20 static struct domain *introduce_domain(const void *ctx, unsigned int domid, - evtchn_port_t port, bool restore) + evtchn_port_t port, bool restore, bool late_init) { struct domain *domain; int rc; @@ -461,6 +461,9 @@ static struct domain *introduce_domain(const void *ctx, /* Now domain belongs to its connection. */ talloc_steal(domain->conn, domain); =20 + if (late_init) + xenevtchn_notify(xce_handle, domain->port); + if (!is_master_domain && !restore) fire_watches(NULL, ctx, "@introduceDomain", NULL, false, NULL); @@ -479,9 +482,10 @@ static struct domain *introduce_domain(const void *ctx, int do_introduce(struct connection *conn, struct buffered_data *in) { struct domain *domain; - char *vec[3]; + char *vec[4]; unsigned int domid; evtchn_port_t port; + bool late_init; =20 if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) return EINVAL; @@ -489,12 +493,13 @@ int do_introduce(struct connection *conn, struct buff= ered_data *in) domid =3D atoi(vec[0]); /* Ignore the gfn, we don't need it. */ port =3D atoi(vec[2]); + late_init =3D atoi(vec[3]); =20 /* Sanity check args. */ if (port <=3D 0) return EINVAL; =20 - domain =3D introduce_domain(in, domid, port, false); + domain =3D introduce_domain(in, domid, port, false, late_init); if (!domain) return errno; =20 @@ -723,7 +728,7 @@ void dom0_init(void) if (port =3D=3D -1) barf_perror("Failed to initialize dom0 port"); =20 - dom0 =3D introduce_domain(NULL, xenbus_master_domid(), port, false); + dom0 =3D introduce_domain(NULL, xenbus_master_domid(), port, false, false= ); if (!dom0) barf_perror("Failed to initialize dom0"); =20 @@ -1292,7 +1297,7 @@ void read_state_connection(const void *ctx, const voi= d *state) #endif } else { domain =3D introduce_domain(ctx, sc->spec.ring.domid, - sc->spec.ring.evtchn, true); + sc->spec.ring.evtchn, true, false); if (!domain) barf("domain allocation error"); =20 --=20 2.25.1 From nobody Fri Nov 29 10:31:58 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=1641602991; cv=none; d=zohomail.com; s=zohoarc; b=ipIvafGiC/c0ZfpP7zeQ77LhAQNOUE+sAB1BOm6aSWZbBam0/OT2w1ZKTzbTY6Ko3eVTHauQv6KcD6VMRg/J+Rf9siyjgxzjwGGJL0g5NowELCy7UfF+YHUTqKwDgf295rJ3/HV487dYQOiP90XAmkGK4TuF5gwqymHKxzLBezQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641602991; 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=gUNtM2vL1rrOxWTN9QpawWXUdCw/vj/m1eCR2sohWpc=; b=iOHNcd2pY+DIQ8KEkem434PcREs893tlp0p6rw75t91pu1Yj0duEIvthMlvNGm5AoSx6IEKLxoqV8o0M131qAL6BNYdJ4tijIlgc52AYv4/wWnT6bFjVAdGxRUY9It8brbeDtB6AbArxkQgwnYPwykOC+wq3NVG5aDl+qy+kUJk= 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 1641602991585436.3688338770082; Fri, 7 Jan 2022 16:49:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.254716.436558 (Exim 4.92) (envelope-from ) id 1n5zvA-00081q-3n; Sat, 08 Jan 2022 00:49:24 +0000 Received: by outflank-mailman (output) from mailman id 254716.436558; Sat, 08 Jan 2022 00:49:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n5zv9-0007wT-PX; Sat, 08 Jan 2022 00:49:23 +0000 Received: by outflank-mailman (input) for mailman id 254716; Sat, 08 Jan 2022 00:49:21 +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 1n5zv6-0006ZD-VQ for xen-devel@lists.xenproject.org; Sat, 08 Jan 2022 00:49:21 +0000 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cfc511d6-701c-11ec-9ce5-af14b9085ebd; Sat, 08 Jan 2022 01:49:19 +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 99764B827C6; Sat, 8 Jan 2022 00:49:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1298BC36AED; Sat, 8 Jan 2022 00:49:17 +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: cfc511d6-701c-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641602957; bh=cJpLwwW8OdmngDb+C/1eNjUgTbMHWokoFmWCQuobrSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aVG/KhWGND1i1gzbk6AiU107+9n35oPsX0ZRvROVtGumYsmRnTm3otXT+/CPIqH47 QEn3oYaUQ4h6faVPMobaG9BRudubJHy8Z5QDpOb84HI0a4UMOkQV7iLzACJdlXUAgh m9ig+UBtFc5UdDIkuFSXXmSo5ZHFvhDko102evBq+MDg8JvZekyYi+VxiekTLaCjTO kn/KJ6TuaIZWxRB6RSyeId+BlhTxw36nVgz04uxA+n5aHeir96m5H9MnF1diARmDlr OtFGbOM53qu+OJRDzp+yhEMYUI3SXqebnYB5Y1cR+uXloOcP40RNlRU+JFR5PPXW0L J8h7GkdXYyVlQ== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, julien@xen.org, Bertrand.Marquis@arm.com, Luca Miccio , Stefano Stabellini , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN PATCH 7/7] tools: add example application to initialize dom0less PV drivers Date: Fri, 7 Jan 2022 16:49:12 -0800 Message-Id: <20220108004912.3820176-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 X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1641602993151100004 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 --- tools/helpers/Makefile | 13 ++ tools/helpers/init-dom0less.c | 263 ++++++++++++++++++++++++++++++++++ 2 files changed, 276 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..055bf76cf5 --- /dev/null +++ b/tools/helpers/init-dom0less.c @@ -0,0 +1,263 @@ +#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(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]; + + 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); + xc_hvm_param_set(dom->xch, dom->guest_domid, HVM_PARAM_STORE_EVTCHN, + dom->xenstore_evtchn); + return 0; +} + +static void do_xs_write(struct xs_handle *xsh, xs_transaction_t t, + char *path, char *val) +{ + if (!xs_write(xsh, t, path, val, strlen(val))) + fprintf(stderr, "writing %s to xenstore failed.\n", path); +} + +static void 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); + do_xs_write(xsh, t, full_path, val); +} + +static void 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); + do_xs_write(xsh, t, full_path, val); +} + +static void 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); + do_xs_write(xsh, t, full_path, val); +} + +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 */ + do_xs_write_vm(xsh, t, uuid, "name", dom_name_str); + do_xs_write_vm(xsh, t, uuid, "uuid", uuid_str); + do_xs_write_vm(xsh, t, uuid, "start_time", "0"); + + /* /domain */ + do_xs_write_dom(xsh, t, domid, "vm", vm_val_str); + do_xs_write_dom(xsh, t, domid, "name", dom_name_str); + do_xs_write_dom(xsh, t, domid, "cpu", ""); + for (i =3D 0; i < info->vcpu_max_id; i++) { + snprintf(cpu_str, STR_MAX_LENGTH, "cpu/%d/availability/", i); + do_xs_write_dom(xsh, t, domid, cpu_str, + (info->cpupool & (1 << i)) ? "online" : "offline"); + } + do_xs_write_dom(xsh, t, domid, "cpu/0", ""); + do_xs_write_dom(xsh, t, domid, "cpu/availability", "online"); + + do_xs_write_dom(xsh, t, domid, "memory", ""); + do_xs_write_dom(xsh, t, domid, "memory/static-max", max_memkb_str); + do_xs_write_dom(xsh, t, domid, "memory/videoram", "-1"); + + do_xs_write_dom(xsh, t, domid, "device", ""); + do_xs_write_dom(xsh, t, domid, "device/suspend", ""); + do_xs_write_dom(xsh, t, domid, "device/suspend/event-channel", ""); + + do_xs_write_dom(xsh, t, domid, "control", ""); + do_xs_write_dom(xsh, t, domid, "control/shutdown", ""); + do_xs_write_dom(xsh, t, domid, "control/feature-poweroff", "1"); + do_xs_write_dom(xsh, t, domid, "control/feature-reboot", "1"); + do_xs_write_dom(xsh, t, domid, "control/feature-suspend", ""); + do_xs_write_dom(xsh, t, domid, "control/sysrq", ""); + do_xs_write_dom(xsh, t, domid, "control/platform-feature-multiprocesso= r-suspend", "1"); + do_xs_write_dom(xsh, t, domid, "control", "platform-feature-xs_reset_w= atches"); + + do_xs_write_dom(xsh, t, domid, "domid", id_str); + do_xs_write_dom(xsh, t, domid, "data", ""); + do_xs_write_dom(xsh, t, domid, "drivers", ""); + do_xs_write_dom(xsh, t, domid, "feature", ""); + do_xs_write_dom(xsh, t, domid, "attr", ""); + + do_xs_write_dom(xsh, t, domid, "store/port", xenstore_port_str); + do_xs_write_dom(xsh, t, domid, "store/ring-ref", ring_ref_str); + + do_xs_write_libxl(xsh, t, domid, "type", "pvh"); + do_xs_write_libxl(xsh, t, domid, "dm-version", "qemu_xen"); + + if (!xs_transaction_end(xsh, t, false)) + if (errno =3D=3D EAGAIN) + goto retry_transaction; + + 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 */ + printf("Allocating magic pages\n"); + if (alloc_magic_pages(&dom) !=3D 0) { + printf("Error on alloc magic pages\n"); + return 1; + } + + printf("Setup Grant Tables\n"); + xc_dom_gnttab_init(&dom); + + printf("Setup UUID\n"); + libxl_uuid_generate(&uuid); + xc_domain_sethandle(dom.xch, info->domid, libxl_uuid_bytearray(&uuid)); + + printf("Creating JSON\n"); + rc =3D gen_stub_json_config(info->domid, &uuid); + if (rc) + err(1, "gen_stub_json_config"); + + printf("Restoring Xenstore values\n"); + restore_xenstore(xsh, info, uuid, dom.xenstore_evtchn); + + printf("Introducing domain\n"); + xs_introduce_domain(xsh, info->domid, + (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + XENSTORE_PFN_OFFSET, + dom.xenstore_evtchn, true); + 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; + libxl_ctx *ctx; + int nb_vm, i; + struct xs_handle *xsh; + + xsh =3D xs_daemon_open(); + if (xsh =3D=3D NULL) { + fprintf(stderr, "Could not contact XenStore"); + exit(1); + } + + if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, NULL)) { + fprintf(stderr, "cannot init xl context\n"); + exit(1); + } + + info =3D libxl_list_domain(ctx, &nb_vm); + if (!info) { + fprintf(stderr, "libxl_list_vm failed.\n"); + exit(EXIT_FAILURE); + } + + 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); + } + libxl_dominfo_list_free(info, nb_vm); + xs_close(xsh); + return 0; +} --=20 2.25.1