From nobody Fri Nov 29 10:45:22 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=1642035566; cv=none; d=zohomail.com; s=zohoarc; b=J0Vf/qwKrhRoYi0K7J8maBkD9LzbYFq9zNaNso183SJSx3x1ovnYB/a3tk1Wn2Y4JtydrGyYj3+5V0vGCVOsO4FU9OJkym1Gwiv09a7k5W3oKpeP82amcoYks9QFeq98W0KzbOpeFPr8cXWhEDvksUVpHRsyX3uJIO2nUTWnPQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642035566; 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=oYZaGy4vxN3yZFmIPlvqk79ipu0akfk4kjwZbQyMFYk=; b=ELm01I5tIun0akzZhc2KZOArDoC+zY3ijIK8ac/qRt6lQfypmSeroS6VHyItr6SBt2ukehJX42i8Zf3AsbX4N6QAf+L+VpOqESohejyHkxgC89qE0++cZcscJX5L6RBvbqegjq5eSfswiewJ/uFQwivXyskbt3DQgRj30BR75rs= 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 1642035566684461.99805429870116; Wed, 12 Jan 2022 16:59:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256935.441229 (Exim 4.92) (envelope-from ) id 1n7oSE-0001Gn-C5; Thu, 13 Jan 2022 00:59:02 +0000 Received: by outflank-mailman (output) from mailman id 256935.441229; Thu, 13 Jan 2022 00:59:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7oSE-0001Gb-87; Thu, 13 Jan 2022 00:59:02 +0000 Received: by outflank-mailman (input) for mailman id 256935; Thu, 13 Jan 2022 00:59:01 +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 1n7oSC-0000yd-SI for xen-devel@lists.xenproject.org; Thu, 13 Jan 2022 00:59:00 +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 fd7ffc1e-740b-11ec-bd6f-bfb69f65cdc7; Thu, 13 Jan 2022 01:58:59 +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 37171B82013; Thu, 13 Jan 2022 00:58:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADD42C36AE9; Thu, 13 Jan 2022 00:58:56 +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: fd7ffc1e-740b-11ec-bd6f-bfb69f65cdc7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642035537; bh=sZFmedX5/wiNDC+oEIvQz6ME9nvU8F4fvaLjZQa8j68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LEP34n4m3IODU9NwNk+AMi9EnvYMktVOs+LH8vx7x9XGUX8mQhdN4GsNUPP2+Ek8g h0X/G+FOgoSdAe/tQL9f75gKBE6GMmHOgzRpnIPCy/A2a9SVZf4HmvQVlek77w8UcD NTLFSaxhcaErvw7APZOOLjMI5SNPquYuoTh1SYSXQQcE+5kLN7d4vdVATbWFFgEuZj 7yBgniaXu1EC/b4YGN4AxzxZ6YNBp5zWxv6xezoVbGixXwfpZUTdSS3TLpB/IClbtu H1ZMSSsLthvJxAakkjiDD40hFWDfjSXM8Azes/yzR+C0nKJrt2Nq25jb4i4YpQxZGh 3tpAXnnrHGOZw== 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: [XEN PATCH v2 1/5] xen: introduce xen,enhanced dom0less property Date: Wed, 12 Jan 2022 16:58:51 -0800 Message-Id: <20220113005855.1180101-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: 1642035567548100001 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 Reviewed-by: Bertrand Marquis Reviewed-by: Luca Fancellu --- 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 10:45:22 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=1642035567; cv=none; d=zohomail.com; s=zohoarc; b=m58909iUdPSj8aAL3Wud0ujMhC7s8DLmangmDeXJPBPU1xMdm5deUtulE2ViPDASkCSZfQRzJZj2emcbiEFSuLYRFVw3zVUTsH55tpKGHYLhLGd6gFNR+AS2xRNLkunjsYYgWSyBQbb3AtyxgNVCi0k/MGtuyYo+hTH1KrFoNw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642035567; 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=TjhSqT17Y7SmSSnuPg3epAYzUqT4qpXeqONILkC73Ws=; b=PVKb5ebu9a8arvb+Gl6PebSjdwuNHbNvD9KqkI7NnsNV+pOZfSiYYVkK0tmiyKeQku6hY7MwDO6FnIHN4DOio3Kv8LT7hp9lyoykCluKL5DNAVkiizXvGIe40MjNT1I7eXtH47+fxSXPT7IcR6twOztjjH5i4mHS97NzrdZgEMQ= 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 1642035567223550.9014242241378; Wed, 12 Jan 2022 16:59:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256934.441218 (Exim 4.92) (envelope-from ) id 1n7oSD-00010P-5p; Thu, 13 Jan 2022 00:59:01 +0000 Received: by outflank-mailman (output) from mailman id 256934.441218; Thu, 13 Jan 2022 00:59:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7oSD-00010E-04; Thu, 13 Jan 2022 00:59:01 +0000 Received: by outflank-mailman (input) for mailman id 256934; Thu, 13 Jan 2022 00:59:00 +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 1n7oSC-0000Zm-3C for xen-devel@lists.xenproject.org; Thu, 13 Jan 2022 00:59:00 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fd58511d-740b-11ec-a563-1748fde96b53; Thu, 13 Jan 2022 01:58:59 +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 3343161BC8; Thu, 13 Jan 2022 00:58:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31BF1C36AED; Thu, 13 Jan 2022 00:58:57 +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: fd58511d-740b-11ec-a563-1748fde96b53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642035537; bh=I7Qzw936fQaVQlipdIlxqTlxpstcgdZHzCA+avueHiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FEYW2DJyBr5XxJTcrRIxaXLVJhXy12zhMQwI3GZFVjrZIjbboNUw5UcONuENn6wki Cz8uV0n66gslF6z/4UHdgTlXYzmHYEJogxc2XzLcsMi3yE0TJO44pIFka5ggDNmhch sfdIKmnYOgEJwDn8F8jvwyjA/vpHxRjp8y4nPgm/xMJ5fztnq7uWaV4Un/GHsico8x fJP9wL9Nwv7ykhD5IiFuT9NAPCCW1Vk2MmKKtX+7Tj92lSFODbaZSLx8SXJLacHh4T Vw5pl0C0kw5BQGw5ZRqpSsJlhwXHDJIBTcL0mjV4KV9DVgBUK0Aas0zn3VFD0c6fmo BdTCmi36cOB6g== 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 , Jan Beulich , Andrew Cooper Subject: [XEN PATCH v2 2/5] xen: export get_free_port Date: Wed, 12 Jan 2022 16:58:52 -0800 Message-Id: <20220113005855.1180101-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: 1642035569509100003 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini get_free_port will soon be used to allocate the xenstore event channel for dom0less domains. Signed-off-by: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Jan Beulich CC: Andrew Cooper --- xen/common/event_channel.c | 2 +- xen/include/xen/event.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index da88ad141a..5b0bcaaad4 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -232,7 +232,7 @@ int evtchn_allocate_port(struct domain *d, evtchn_port_= t port) return 0; } =20 -static int get_free_port(struct domain *d) +int get_free_port(struct domain *d) { int port; =20 diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 21c95e14fd..0b35d9d4d2 100644 --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -71,6 +71,9 @@ void evtchn_free(struct domain *d, struct evtchn *chn); /* Allocate a specific event channel port. */ int evtchn_allocate_port(struct domain *d, unsigned int port); =20 +/* Get fix free event channel port */ +int get_free_port(struct domain *d); + /* Unmask a local event-channel port. */ int evtchn_unmask(unsigned int port); =20 --=20 2.25.1 From nobody Fri Nov 29 10:45:22 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=1642035567; cv=none; d=zohomail.com; s=zohoarc; b=IqXxwKAZzGIUkETk5kDiiNN+FeLWklJu00Wha5HnnpLCiV6Q6ZhsP9zIKdrRMa5tQVNuzHpwuz+0mepO5roD/OR2S4LlphAsVEOAWErXOPKKdLdE+s+Re+vnDxTrDHa+YTEGwpPsLpyjbUK0pK3PTvmEzCOu6etQyqwRvn5O/iU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642035567; 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=x0KmZmSTz9fxPbsS53GCjSk96nxzh6VBhGdjjhRUmiM=; b=dvcH61RBRwQklnejNfZzibAR6dPrULvBD4m9Bb5y27j4TpxRhku+mSCcG5+q1Vm9IOme9/KOnfHHw85db4XA7H3aIQJPOXmUnPxpytZeLye0QUm+SaJ0VlFRcboekMrNauhn8bj2EhHVEKF1+hg5CRVS3lhqZ3ShT4PCV4z8CdQ= 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 16420355679811001.1283562042106; Wed, 12 Jan 2022 16:59:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256937.441251 (Exim 4.92) (envelope-from ) id 1n7oSG-0001nq-5C; Thu, 13 Jan 2022 00:59:04 +0000 Received: by outflank-mailman (output) from mailman id 256937.441251; Thu, 13 Jan 2022 00:59:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7oSF-0001ms-VJ; Thu, 13 Jan 2022 00:59:03 +0000 Received: by outflank-mailman (input) for mailman id 256937; Thu, 13 Jan 2022 00:59:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7oSE-0000Zm-3P for xen-devel@lists.xenproject.org; Thu, 13 Jan 2022 00:59:02 +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 fe1f07cd-740b-11ec-a563-1748fde96b53; Thu, 13 Jan 2022 01:59:00 +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 78DB5B82186; Thu, 13 Jan 2022 00:58:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2990C36AEC; Thu, 13 Jan 2022 00:58:57 +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: fe1f07cd-740b-11ec-a563-1748fde96b53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642035538; bh=aVeTdpqg6xfKSe5v6f9xUurkpCgdvHnT4ByypG+sUSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iCnZc93432xJkVkk1QlGX9v1Tk0FKOmxsIC5dP4w1dcjPN9vsGaKusnNw881CETLl xI97hL7JC8nW5VEDH2kLapMSFZ8VwPoFoN0cOFLBrgfEnbZJgqOlcVabCidNNnJ4BU S3VC3swZ0pJJVUhs5Flw/qTCKZ7Z7WB+QPN1Rqo/+sj1Gtu3y+XW7Nvp0hQKV15+ZM zCq3+vd7pdopJXXOEpXufzNVtLUCNm5UPK0l7fQ+B5yn4DL0CP6E+rRdQYHNDDar8P tzfTr7n0Nt8NAjrA5yCA07/s5WDc+MtpSYKk4OKNWv4Qz2eHhqC9n+3x/J6XovgfxY dBSA9OtWdBE6A== 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: [XEN PATCH v2 3/5] xen/arm: configure dom0less domain for enabling xenstore after boot Date: Wed, 12 Jan 2022 16:58:53 -0800 Message-Id: <20220113005855.1180101-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: 1642035569689100005 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 Reviewed-by: Bertrand Marquis --- 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 | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 9144d6c0b6..251d933c8e 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,27 @@ static int __init construct_domain(struct domain *d,= struct kernel_info *kinfo) return 0; } =20 +static int __init alloc_xenstore_evtchn(struct domain *d) +{ + struct evtchn *chn; + int port; + + if ( (port =3D get_free_port(d)) < 0 ) + { + printk("Failed allocating event channel for domain\n"); + return port; + } + chn =3D evtchn_from_port(d, port); + + chn->state =3D ECS_UNBOUND; + chn->u.unbound.remote_domid =3D hardware_domain->domain_id; + evtchn_port_init(d, chn); + + 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) { @@ -3014,7 +3045,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 10:45:22 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=1642035570; cv=none; d=zohomail.com; s=zohoarc; b=hCmJOYEs0ye7xrDcCHSdN5OM5wPimg6A30azXXncIdd1oRLcH4F4NilCHVSbz92GOLI5Yh8k5XwYZFs7u7R26jn57G1vgiKjoe58gvGGpDVAuFRd948Dhj/wHRaXYWq+4UWX0C5kc6J9ZpxCCzBmmRDOzR9SqMw/eeSQ+gaOAVE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642035570; 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=vWd4eLtKVHZagWQA/OGwAss7wdWUonq2pXXtKZOTAfg=; b=G8Ga7CMQVS8Q2oQPr/+y/X9oEFI4qHvXuvZPdvWCaFyXe3IiCqQfOwr7RLalrli+dJ2crja9lhStn0FJzuRaKpcBHhL7CdKq6klnaDe7S3UNT+N7fFR7w6+3lhcNh2+NkCpklPAHMvfV7jTD8Zy1Imc3BrzmI0nu2ptXLS7AVRo= 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 1642035570138533.9304294632925; Wed, 12 Jan 2022 16:59:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256936.441235 (Exim 4.92) (envelope-from ) id 1n7oSE-0001Lm-PO; Thu, 13 Jan 2022 00:59:02 +0000 Received: by outflank-mailman (output) from mailman id 256936.441235; Thu, 13 Jan 2022 00:59:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7oSE-0001Jl-IZ; Thu, 13 Jan 2022 00:59:02 +0000 Received: by outflank-mailman (input) for mailman id 256936; Thu, 13 Jan 2022 00:59:01 +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 1n7oSD-0000Zm-3C for xen-devel@lists.xenproject.org; Thu, 13 Jan 2022 00:59:01 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fdb55d7c-740b-11ec-a563-1748fde96b53; Thu, 13 Jan 2022 01:58:59 +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 C784961BD1; Thu, 13 Jan 2022 00:58:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54EABC36AF2; Thu, 13 Jan 2022 00:58:58 +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: fdb55d7c-740b-11ec-a563-1748fde96b53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642035538; bh=fAM5YKlaoqXNElpxV8cs5t9a0K94TnXBpqeWzHX/YLs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MrtQLDgTxeYWiHqJ+w1RK29ndLFljUIZHfVsMXu5qIrpLhozntotpH0aLP7PCT3EK fOrbC3BoP9dow/a6fUEojg5yNpk+XQFoKu8lVQuCNXEZoa0S9H+gANZ81tjwEuXXmg 45m+83bvEJb3qilWZ47C1O/NqB8lGJuQFLcGhdtUmSnjlQ3+FwrhQ4fGCoeKJPdNe7 q3+frVU1C/jjPhv63JEWAnvkPZS4X0qqkyQLkuzlkdtK3H3/tkRqH0X7kCY2ba2Vmk kf05bfkOHFtyghID0DvFP2xQNYKvI90bwdgJB17IeCPYD2gI4Fmb6RbuMvsc1Tvk1c iz0Bm65PE6bmA== 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 Subject: [XEN PATCH v2 4/5] xenstored: send an evtchn notification on introduce_domain Date: Wed, 12 Jan 2022 16:58:54 -0800 Message-Id: <20220113005855.1180101-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: 1642035571856100001 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 10:45:22 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=1642035571; cv=none; d=zohomail.com; s=zohoarc; b=DQd3XpNVFXbSGV/jSuj40vzHVq5iEHnDdvryOddi4dQi3Abbwc2Avc3cJna6yzfotrwUfiDD7LJBe8/3iCkSl8KV1Y8G5Rx06WLIJFblGIwX0dcfpJH5NY9qRPPs1lMITsfrptZ3P2SH+UvvBF23CLtTy6sHWsb+Ty/knt+LYWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642035571; 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=XlwTntF8p+tyleLpOSlNrBVpAs57ICha8mZHxxKm4y4=; b=fn0um4XT/ty7KWPegv5bdljWOqwL2PXk8YCQp0M2TDQ69HJFspp+aY8t1/BfpeuZSDhfy2sIpnciuIJVoOokiAkYkxfS36G51/+GxyMXZI2GFzCPR7SGkNLtfmB/Tcm8zmqD/7ESXyjhUgNFulh9yWCW2HV4J9J9ftmsDAhn+5s= 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 1642035571878133.01494989442278; Wed, 12 Jan 2022 16:59:31 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256938.441256 (Exim 4.92) (envelope-from ) id 1n7oSG-0001va-PM; Thu, 13 Jan 2022 00:59:04 +0000 Received: by outflank-mailman (output) from mailman id 256938.441256; Thu, 13 Jan 2022 00:59:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7oSG-0001tr-Gu; Thu, 13 Jan 2022 00:59:04 +0000 Received: by outflank-mailman (input) for mailman id 256938; Thu, 13 Jan 2022 00:59:03 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7oSF-0000Zm-3a for xen-devel@lists.xenproject.org; Thu, 13 Jan 2022 00:59:03 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fe15ab36-740b-11ec-a563-1748fde96b53; Thu, 13 Jan 2022 01:59:00 +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 65B7E61BCE; Thu, 13 Jan 2022 00:58:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C30FEC36AEF; Thu, 13 Jan 2022 00:58:58 +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: fe15ab36-740b-11ec-a563-1748fde96b53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642035539; bh=dADcioPsMIPHCpayS/ngysHV69Vh+MWvBjX9BH62O10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UZYi4I9unq2FR5kjz3P/SN+wQjUs/AvVVYScN30W5cGiHK44A7mM62MquhM2RbAra EtJgqsbfKRP0g+roQ80jFvPDkxsW0Hg6eEH9rHNWTGT91pblFUIDCgikts4E2HNYUq FGccNmgGgUa9hTaxZs6LdXkSnPGuJUo781K/bsoiu/sa3A3g7SSI0Rgf7vJxktt9v9 pYXSMEm1rSzmKqlepwDmgKSGaU+X98x1VED/+kGeiJhjxqQIWKRpYiv0EA5GgGdCd6 7XvgREGrxo//g2YyombMUC5BVdgYXusGXIS1uFZpQGcoWSWTyuIzE6sM1DQB52W2kp BS2jxmsinhlXA== 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: [XEN PATCH v2 5/5] tools: add example application to initialize dom0less PV drivers Date: Wed, 12 Jan 2022 16:58:55 -0800 Message-Id: <20220113005855.1180101-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: 1642035573929100003 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 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 | 266 ++++++++++++++++++++++++++++++++++ 2 files changed, 279 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..0434ca064f --- /dev/null +++ b/tools/helpers/init-dom0less.c @@ -0,0 +1,266 @@ +#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 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(info, &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); + 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