From nobody Fri Mar 29 06:04: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=1651709845; cv=none; d=zohomail.com; s=zohoarc; b=KBHdKJtPiubWB3P/hOaDPNWGWev6XZrIlHSYug2OZKRcp/7Qf7VW42uuhFI1ut4iPoNgIC3rHgKs4wxkQPkEN+8t6hxyDDFau+eclzKDRa8vkfT5lFHC2MigSHgm4hD4kIk+nm0WfOU+kSCMT39sceB7uortnvAJmp+XiWf4dto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651709845; 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=sgcCcYOWvvySjc8ox1iRn5YnZMNo/n307L4m8yIT7pY=; b=iASJzEMVso7/JaghGaLgSxd5hn4vrHJuVmnfQoIzyO65oBU6CkiDEamSwUVNAZzI565KlQOdkFIxPDgIVG1OSDqNvAfLBoIsgNMsTEX8Cn4d+Y2Gjh1b83kznlPyH7M7tiVRvMlVEjBxpBx0zZjThRtjcqpTjjR07XbgyzIpDJQ= 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 1651709845439767.1535329623209; Wed, 4 May 2022 17:17:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.321177.542118 (Exim 4.92) (envelope-from ) id 1nmPB3-0008Ou-Cl; Thu, 05 May 2022 00:17:05 +0000 Received: by outflank-mailman (output) from mailman id 321177.542118; Thu, 05 May 2022 00:17:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPB2-0008NG-Ri; Thu, 05 May 2022 00:17:04 +0000 Received: by outflank-mailman (input) for mailman id 321177; Thu, 05 May 2022 00:17:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPB1-0007ib-IB for xen-devel@lists.xenproject.org; Thu, 05 May 2022 00:17:03 +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 ae2c56aa-cc08-11ec-a406-831a346695d4; Thu, 05 May 2022 02:17:01 +0200 (CEST) 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 12ADEB82A2B; Thu, 5 May 2022 00:16:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E9F1C385A4; Thu, 5 May 2022 00:16: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: ae2c56aa-cc08-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651709817; bh=ZGLKYYisUFc7rn69ZuhuAK+ygCod9wup1sfHy1UwDoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S9CFQ9zfBSPi8met1QyoP+KqA5OQ0CtJXNnOXF7M9WbALyBL45NT0DcQv3P7mavXi mcVNUCqKbsqu8QpxNGsJozUtxpUNqcdyp5To2mhVgWgTRalQrX+ktfGrXRberm+9cx b3baurQQTmE88cYdA7NNnownmSZ2TK2LWBtVERmIQt9jYJ2eZfl1Ev9VgO4Izz/4rB 7lXnPD/qaGNJhqa9a6SuHdP/FSszW04AhLGnH3Fsp+ct6XKO5w7xVZ0T1tTNX1eQBD A6y0gQEEwW0mW4eZVssa4rDfie3V12YEygEDWjfIADo0MJzYpJUKsUpZqcN1BRT6mG v79oU1bRvbVsg== 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 , Luca Fancellu Subject: [PATCH v6 1/7] xen/dt: of_property_read_string return -ENODATA when !length Date: Wed, 4 May 2022 17:16:50 -0700 Message-Id: <20220505001656.395419-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: 1651709847730100001 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini When the length of the string is zero of_property_read_string should return -ENODATA according to the description of the function. However, of_property_read_string doesn't check prop->length. If prop->length is zero, return -ENODATA. Without this patch the following command in u-boot: fdt set /chosen/node property-name results in of_property_read_string returning -EILSEQ when attempting to read property-name. With this patch, it returns -ENODATA as expected. This commit is a backport of: https://lore.kernel.org/xen-devel/20220416003028.1315268-1-sstabellini@kern= el.org/ Signed-off-by: Stefano Stabellini Reviewed-by: Bertrand Marquis Reviewed-by: Luca Fancellu --- Changes in v5: - backport from Linux --- xen/common/device_tree.c | 2 +- xen/include/xen/device_tree.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 4aae281e89..0e8798bd24 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -198,7 +198,7 @@ int dt_property_read_string(const struct dt_device_node= *np, =20 if ( !pp ) return -EINVAL; - if ( !pp->value ) + if ( !pp->length ) return -ENODATA; if ( strnlen(pp->value, pp->length) >=3D pp->length ) return -EILSEQ; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index fd6cd00b43..430a1ef445 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -451,6 +451,9 @@ static inline bool_t dt_property_read_bool(const struct= dt_device_node *np, * doest not have value, and -EILSEQ if the string is not * null-terminated with the length of the property data. * + * Note that the empty string "" has length of 1, thus -ENODATA cannot + * be interpreted as an empty string. + * * The out_string pointer is modified only if a valid string can be decode= d. */ int dt_property_read_string(const struct dt_device_node *np, --=20 2.25.1 From nobody Fri Mar 29 06:04: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=1651709844; cv=none; d=zohomail.com; s=zohoarc; b=E18q+L2aeb3axJLEx1bDBPY3wsXiT9JcBNuden/E5SNHcDR2sArEqA5s9eD4K3u06wJU0BFRpQNX2w8Vo4cxQ/sqCzy5EewGjC0HGzWA/WsVxJqUoAkHq7GCdq+78jN5UYVTIKJPGUtUUCNRAdWLbBHvo+jpBvCdTk+6RSHfak4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651709844; 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=9WW3oG6a0TZUDqm8HfK1ZalbjPpH8uePM/vbL3ZmgVY=; b=NZfTGjtSj2EQrFU/h3WhJMF2gUI398/0Q+R//K9ypVXyrhKt++ws0jfro4/oz962R+q9tDHmTyMe0zYlQ8cPBYsyCXXOdew38P5tv3lVfgolRkUYHJGcKorswNQrffpZ1IG0eeRldBs/H/nRpifYwiZqtbj4Ve/61kdntZq+Pcc= 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 1651709844318713.9764818231163; Wed, 4 May 2022 17:17:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.321173.542092 (Exim 4.92) (envelope-from ) id 1nmPB0-0007rk-Ft; Thu, 05 May 2022 00:17:02 +0000 Received: by outflank-mailman (output) from mailman id 321173.542092; Thu, 05 May 2022 00:17: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 1nmPB0-0007rd-BA; Thu, 05 May 2022 00:17:02 +0000 Received: by outflank-mailman (input) for mailman id 321173; Thu, 05 May 2022 00:17: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 1nmPAz-0007pt-2e for xen-devel@lists.xenproject.org; Thu, 05 May 2022 00:17: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 ae072064-cc08-11ec-8fc4-03012f2f19d4; Thu, 05 May 2022 02:17:00 +0200 (CEST) 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 F25D861D48; Thu, 5 May 2022 00:16:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEC20C385A5; Thu, 5 May 2022 00:16: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: ae072064-cc08-11ec-8fc4-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651709818; bh=Mwel9XZZFmkKqmMXTUSqunEUmjRMBAHXbPN0MGWNniE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X1CQfMiiba7mxvH99FxIL6s0zrb0Fc7+eSFMhhFjOj4c+F465u6+ZLvNmQySQfgud AmoD7u+dD1zZ3W4t6HsqLBghxSkW3DIJwrF9lsNUxHHZxAojy6DeJFhlhb2eptpteU P316kO1K/T06fU7OB99OohEKNqV1iP36NdJCOuURxJ+6CIh0ymwdeUIe2IzYjcNCda /5KbvSzf7BBfccwe16Ms+X7H5GQQO+cM2pSalMM5Kz4+GYXOm5WRWdS5TV0mMUWQ/Y kEdPoFtCHn6++6d8a8gcYoWHW8AorTyLUhJmVdTKZ7eH7M6ejWQzcKHvQ1TMaHnXd9 ANgNDKFjVlnpg== 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 , Luca Fancellu , olekstysh@gmail.com Subject: [PATCH v6 2/7] xen/arm: implement domU extended regions Date: Wed, 4 May 2022 17:16:51 -0700 Message-Id: <20220505001656.395419-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: 1651709845369100003 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini Implement extended regions for dom0less domUs. The implementation is based on the libxl implementation. Also update docs for the ext_regions command line option. Signed-off-by: Stefano Stabellini Reviewed-by: Luca Fancellu CC: olekstysh@gmail.com Acked-by: Julien Grall Reviewed-by: Oleksandr Tyshchenko --- Changes in v6: - add reviewed-by - address 2 NITs - update docs Changes in v5: - print the domain - coding style - simplify the code in find_domU_holes - return error if no regions allocated in find_domU_holes - use ROUNDUP - uint64_t/paddr_t --- docs/misc/xen-command-line.pandoc | 9 ++--- xen/arch/arm/domain_build.c | 60 ++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 1dc7e1ca07..881fe409ac 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1110,11 +1110,12 @@ to use the default. =20 > Default : `true` =20 -Flag to enable or disable support for extended regions for Dom0. +Flag to enable or disable support for extended regions for Dom0 and +Dom0less DomUs. =20 -Extended regions are ranges of unused address space exposed to Dom0 as -"safe to use" for special memory mappings. Disable if your board device -tree is incomplete. +Extended regions are ranges of unused address space exposed to the guest +as "safe to use" for special memory mappings. Disable if your board +device tree is incomplete. =20 ### flask > `=3D permissive | enforcing | late | disabled` diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 1472ca4972..f22450b4b7 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -35,7 +35,10 @@ static unsigned int __initdata opt_dom0_max_vcpus; integer_param("dom0_max_vcpus", opt_dom0_max_vcpus); =20 -/* If true, the extended regions support is enabled for dom0 */ +/* + * If true, the extended regions support is enabled for dom0 and + * dom0less domUs. + */ static bool __initdata opt_ext_regions =3D true; boolean_param("ext_regions", opt_ext_regions); =20 @@ -1324,6 +1327,36 @@ out: return res; } =20 +static int __init find_domU_holes(const struct kernel_info *kinfo, + struct meminfo *ext_regions) +{ + unsigned int i; + paddr_t bankend; + const paddr_t bankbase[] =3D GUEST_RAM_BANK_BASES; + const paddr_t banksize[] =3D GUEST_RAM_BANK_SIZES; + int res =3D -ENOENT; + + for ( i =3D 0; i < GUEST_RAM_BANKS; i++ ) + { + struct membank *ext_bank =3D &(ext_regions->bank[ext_regions->nr_b= anks]); + + ext_bank->start =3D ROUNDUP(bankbase[i] + kinfo->mem.bank[i].size,= SZ_2M); + + bankend =3D ~0ULL >> (64 - p2m_ipa_bits); + bankend =3D min(bankend, bankbase[i] + banksize[i] - 1); + if ( bankend > ext_bank->start ) + ext_bank->size =3D bankend - ext_bank->start + 1; + + /* 64MB is the minimum size of an extended region */ + if ( ext_bank->size < MB(64) ) + continue; + ext_regions->nr_banks++; + res =3D 0; + } + + return res; +} + static int __init make_hypervisor_node(struct domain *d, const struct kernel_info *kinfo, int addrcells, int sizecells) @@ -1360,12 +1393,13 @@ static int __init make_hypervisor_node(struct domai= n *d, =20 if ( !opt_ext_regions ) { - printk(XENLOG_INFO "The extended regions support is disabled\n"); + printk(XENLOG_INFO "%pd: extended regions support is disabled\n", = d); nr_ext_regions =3D 0; } else if ( is_32bit_domain(d) ) { - printk(XENLOG_WARNING "The extended regions are only supported for= 64-bit guest currently\n"); + printk(XENLOG_WARNING + "%pd: extended regions not supported for 32-bit guests\n", = d); nr_ext_regions =3D 0; } else @@ -1374,13 +1408,21 @@ static int __init make_hypervisor_node(struct domai= n *d, if ( !ext_regions ) return -ENOMEM; =20 - if ( !is_iommu_enabled(d) ) - res =3D find_unallocated_memory(kinfo, ext_regions); + if ( is_domain_direct_mapped(d) ) + { + if ( !is_iommu_enabled(d) ) + res =3D find_unallocated_memory(kinfo, ext_regions); + else + res =3D find_memory_holes(kinfo, ext_regions); + } else - res =3D find_memory_holes(kinfo, ext_regions); + { + res =3D find_domU_holes(kinfo, ext_regions); + } =20 if ( res ) - printk(XENLOG_WARNING "Failed to allocate extended regions\n"); + printk(XENLOG_WARNING "%pd: failed to allocate extended region= s\n", + d); nr_ext_regions =3D ext_regions->nr_banks; } =20 @@ -1401,8 +1443,8 @@ static int __init make_hypervisor_node(struct domain = *d, u64 start =3D ext_regions->bank[i].start; u64 size =3D ext_regions->bank[i].size; =20 - printk("Extended region %d: %#"PRIx64"->%#"PRIx64"\n", - i, start, start + size); + printk("%pd: extended region %d: %#"PRIx64"->%#"PRIx64"\n", + d, i, start, start + size); =20 dt_child_set_range(&cells, addrcells, sizecells, start, size); } --=20 2.25.1 From nobody Fri Mar 29 06:04: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=1651709842; cv=none; d=zohomail.com; s=zohoarc; b=edg4V3l+GqjeAmCJvDU77IoqGax4OeXkawUi9BkPv33TDgaQlsnN0a4If+6fUgTuPar37b23DoPcOCsNIny7oOnuYgFM6XEsON3+ngUOyQqsdSemKsU6j32nSygV0l0a6kXLL8Uhoqy1AcUFwd9to53rSRCy1Uqf3k8n+i0ARmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651709842; 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=Ghg8SpLwurODyOG/fezIadWfjeO3CFDQrigoVQCxRcU=; b=Dy/ipU38zMVb8qauqo0ue0T5cTHN3ro/P+XLg9lmHPhQZ+OqyCpHVIQCqdUD5SRJ0Rdrb2iCApl6PVDJeQV0BEQhbc2kC5MuO3Cj1hZ1dPYT8R5mLXOwFEL5ERaZf2IShjAVTGasrIujfn8237ylN6IIfmgKYwgeG/Pp7RJR3M4= 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 1651709842380650.0556633681558; Wed, 4 May 2022 17:17:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.321174.542097 (Exim 4.92) (envelope-from ) id 1nmPB0-0007vU-VA; Thu, 05 May 2022 00:17:02 +0000 Received: by outflank-mailman (output) from mailman id 321174.542097; Thu, 05 May 2022 00:17: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 1nmPB0-0007up-NY; Thu, 05 May 2022 00:17:02 +0000 Received: by outflank-mailman (input) for mailman id 321174; Thu, 05 May 2022 00:17: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 1nmPB0-0007pt-2u for xen-devel@lists.xenproject.org; Thu, 05 May 2022 00:17:02 +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 ae6e9ef7-cc08-11ec-8fc4-03012f2f19d4; Thu, 05 May 2022 02:17:00 +0200 (CEST) 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 7348761D4A; Thu, 5 May 2022 00:16:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A635C385B0; Thu, 5 May 2022 00:16: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: ae6e9ef7-cc08-11ec-8fc4-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651709818; bh=1SZ90Yt0l4IaHxlGeXfmBz5khMim6VBa3OhRqKwwqVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ELx8Xsa4VisWKnYAVptArxVyNrykUSbHalc0JlZOUH/J+ExS9sbCy3ivYBHoJStLC 9/xqbsUD4cbsBUBBU6VFoRXJYjVakJUHNurJqjslDxV0X/OWgnJ1KtHP+65+5GYFZb WW/6yO/Lg6nhIQFuBbLcWhfE3jngodRytVBS0YZcrsbcjSWp4oWIpADUHVfV8NXnoR LR95aOZPoLtpcHbo8ZWFtXd46cxiqQyL2HIJSn5vKzIl7kggL1xT6qy/7zjRLk67k/ i7mhaGWDyGqB+lcYOHUh7vx/TWHdrRRkD6zM5cXq+qQjvuYt1az3hsNgb6okba3kuv ZApf0qHn1PAWg== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, jgross@suse.com, Bertrand.Marquis@arm.com, julien@xen.org, Volodymyr_Babchuk@epam.com, Stefano Stabellini , Bertrand Marquis Subject: [PATCH v6 3/7] xen: introduce xen,enhanced dom0less property Date: Wed, 4 May 2022 17:16:52 -0700 Message-Id: <20220505001656.395419-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: 1651709843503100001 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini Introduce a new "xen,enhanced" dom0less property to enable/disable PV driver interfaces for dom0less guests. Currently only "enabled" and "disabled" are supported property values (and empty). Leave the option open to implement further possible values in the future (e.g. "xenstore" to enable only xenstore.) The configurable option is for domUs only. For dom0 we always set the corresponding property in the Xen code to true (PV interfaces enabled.) This patch only parses the property. Next patches will make use of it. Signed-off-by: Stefano Stabellini Reviewed-by: Bertrand Marquis CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis --- Changes in v4: - move xen,enhanced to the bottom of the list - do not set kinfo.dom0less_enhanced for dom0 Changes in v3: - improve commit message Changes in v2: - rename kinfo.enhanced to kinfo.dom0less_enhanced - set kinfo.dom0less_enhanced to true for dom0 - handle -ENODATA in addition to -EILSEQ --- docs/misc/arm/device-tree/booting.txt | 18 ++++++++++++++++++ xen/arch/arm/domain_build.c | 7 +++++++ xen/arch/arm/include/asm/kernel.h | 3 +++ 3 files changed, 28 insertions(+) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-t= ree/booting.txt index a94125394e..92097c4969 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -188,6 +188,24 @@ with the following properties: An empty property to request the memory of the domain to be direct-map (guest physical address =3D=3D physical address). =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. + Under the "xen,domain" compatible node, one or more sub-nodes are present for the DomU kernel and ramdisk. =20 diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index f22450b4b7..016f56a99f 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -3154,6 +3154,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 @@ -3169,6 +3170,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 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 Mar 29 06:04: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=1651709847; cv=none; d=zohomail.com; s=zohoarc; b=MXEioHwIIkE7BLD1Uipe0jtCHUUpWkQr36hwTLej4yX7v55n0dd/6rIxcaB9qseXeGpMIYDF4cEAbUSgSFCYbmRf+zkTV2e3MIkDuxhQVCAKxL4RJ98oXmhga/naMPwg+LImEiuFD0XU26I8658+bHJsVk1YLjALb0IGMP+Ezbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651709847; 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=ktIF/X+bwXDTuHOMIzh9/rYgCtV3fhIUTCUthXk/Nug=; b=HbCMUB1g282toyJHZiA/YSdCxUOQtkthEhUn732oLUytdXSiIeA9AkDpi96ovZm2sQmFtzHR1ZFpGwl8mXD/3L9NNZLjvLAo0Jyce/u8zdy+fAOpz3mVtRIPfUbbQu4nOb+kHG+c63Y2EnYOl+4qfU+/U9Bvy72KkCzgq1gPy4Q= 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 1651709847489192.28821194730256; Wed, 4 May 2022 17:17:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.321179.542133 (Exim 4.92) (envelope-from ) id 1nmPB5-0000KZ-Cw; Thu, 05 May 2022 00:17:07 +0000 Received: by outflank-mailman (output) from mailman id 321179.542133; Thu, 05 May 2022 00:17:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPB5-0000Hm-08; Thu, 05 May 2022 00:17:07 +0000 Received: by outflank-mailman (input) for mailman id 321179; Thu, 05 May 2022 00:17:04 +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 1nmPB2-0007ib-IW for xen-devel@lists.xenproject.org; Thu, 05 May 2022 00:17:04 +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 ae66ea89-cc08-11ec-a406-831a346695d4; Thu, 05 May 2022 02:17:01 +0200 (CEST) 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 A6C5F61D46; Thu, 5 May 2022 00:16:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11B62C385B2; Thu, 5 May 2022 00:16:59 +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: ae66ea89-cc08-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651709819; bh=E9MSaccIsafpyB3w94QGDZQ01xMK5vlE5XQ9xApFP8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZWuCYpHaMtY1a2m/mVJcnt9ZaoqlCQSly0zRsecEpEhEUv00xb6ysU98BpbbGmHNo mzpC1T5eGczmunbZKFCKKv1Quulp+Zb2yKj2z+fiwcVzWPCP6RCcZ3UoAFAiCyLPAz d8ey2GVFPYrXVjdFmpVgUOmYaIFBNnOM/YLB076Ca/eUDTlH4UXQW8AkNx8D6B+Z+X iTI2DvKEqMYy4AuTBH4y2j8ZerRGDL3u92wHfUU4N4Y/YUL8eLW9Ui7MiX2brKHgRo YWy6rfud5XG8LbyQgZ+mgXr0J07dgQiY8GTusa6e/ReyR7U44UWmPZ+K5Tj7r5nkPg itZEpo81JhRyg== 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 , jbeulich@suse.com Subject: [PATCH v6 4/7] xen/arm: configure dom0less domain for enabling xenstore after boot Date: Wed, 4 May 2022 17:16:53 -0700 Message-Id: <20220505001656.395419-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: 1651709849335100005 Content-Type: text/plain; charset="utf-8" From: Luca Miccio Export evtchn_alloc_unbound and make it __must_check. If "xen,enhanced" is enabled, then add to dom0less domains: - the hypervisor node in device tree - the xenstore event channel The xenstore event channel is also used for the first notification to let the guest know that xenstore has become available. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini Reviewed-by: Bertrand Marquis CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: jbeulich@suse.com Acked-by: Julien Grall # common --- Changes in v5: - merge with "xen: export evtchn_alloc_unbound" - __must_check Changes in v3: - use evtchn_alloc_unbound Changes in v2: - set HVM_PARAM_STORE_PFN to ~0ULL at domain creation - in alloc_xenstore_evtchn do not call _evtchn_alloc_unbound xen: export evtchn_alloc_unbound It will be used during dom0less domains construction. Signed-off-by: Stefano Stabellini --- xen/arch/arm/domain_build.c | 37 +++++++++++++++++++++++++++++++++++++ xen/common/event_channel.c | 2 +- xen/include/xen/event.h | 3 +++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 016f56a99f..bb430f2189 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 @@ -2810,6 +2811,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; @@ -2884,6 +2887,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; @@ -3150,6 +3160,25 @@ static int __init construct_domain(struct domain *d,= struct kernel_info *kinfo) return 0; } =20 +static int __init alloc_xenstore_evtchn(struct domain *d) +{ + evtchn_alloc_unbound_t alloc; + int rc; + + alloc.dom =3D d->domain_id; + alloc.remote_dom =3D hardware_domain->domain_id; + rc =3D evtchn_alloc_unbound(&alloc); + if ( rc ) + { + printk("Failed allocating event channel for domain\n"); + return rc; + } + + d->arch.hvm.params[HVM_PARAM_STORE_EVTCHN] =3D alloc.port; + + return 0; +} + static int __init construct_domU(struct domain *d, const struct dt_device_node *node) { @@ -3214,6 +3243,14 @@ static int __init construct_domU(struct domain *d, if ( rc < 0 ) return rc; =20 + 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; + } + return rc; } =20 diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 0a82eb3ac2..e60cd98d75 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -290,7 +290,7 @@ void evtchn_free(struct domain *d, struct evtchn *chn) xsm_evtchn_close_post(chn); } =20 -static int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) +int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc) { struct evtchn *chn; struct domain *d; diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h index 21c95e14fd..f3021fe304 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 +/* Allocate a new event channel */ +int __must_check evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc); + /* Unmask a local event-channel port. */ int evtchn_unmask(unsigned int port); =20 --=20 2.25.1 From nobody Fri Mar 29 06:04: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=1651709845; cv=none; d=zohomail.com; s=zohoarc; b=gFEwQorNgpsUBF4rlt6iDbUTEpn0mzsMxpuXlqpoaDbQZlmFdmLOej+Vkp1fKY6QSNpwPpozKZUorI2X76RN/VRGBCc6inc9CDce6pWczL2/MUFKh+oJGMeXDiY8rdj5mVZzNEdz8Wl0xerGNtnSQRRdkNJF1XiM8dCA6+lb3XI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651709845; 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=enFEy0ih8iR6Vq1JJ3GAL7nRh48cdb6pZKlycGkesCk=; b=Frs5FIFXr0LT1F4wWcg9AqkjQ/NI3ZvLiBiSCNQH+sFrUM4QqQxO8Bq4ZkbiWZZW2ICfl/iWqgppifznsHhgAaNumJcx9cXRwcuYxsvV+lwO9wwTPwvc8x8fK38Rys8YiZZjO2GgJiDvfsvr1/OyF1XzwLUY9jnd1nTGnHaURMo= 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 1651709845384183.8044461141734; Wed, 4 May 2022 17:17:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.321175.542112 (Exim 4.92) (envelope-from ) id 1nmPB2-0008JP-E4; Thu, 05 May 2022 00:17:04 +0000 Received: by outflank-mailman (output) from mailman id 321175.542112; Thu, 05 May 2022 00:17: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 1nmPB2-0008I0-8n; Thu, 05 May 2022 00:17:04 +0000 Received: by outflank-mailman (input) for mailman id 321175; Thu, 05 May 2022 00:17:02 +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 1nmPB0-0007ib-Hu for xen-devel@lists.xenproject.org; Thu, 05 May 2022 00:17:02 +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 aec53614-cc08-11ec-a406-831a346695d4; Thu, 05 May 2022 02:17:01 +0200 (CEST) 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 4ACA561D50; Thu, 5 May 2022 00:17:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3FCEC385AF; Thu, 5 May 2022 00:16:59 +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: aec53614-cc08-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651709820; bh=rIw+2SrwT7YpYC/phawk5vOS/f23VxvR6M90QJVp4fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IzyPwIj4awg5UuN2mAFVNIw8aZZVyleXB9GoKZL7HhJafzHHCw/zn3G4VE4mxI3dw eNZxzPgcrdHBsuXo3GX5fW3S/4g7vQ1GsDhjd7LRKa99T23xZR35y8fpQc6ZpK61OV fDN8+cDyn5p81t52tReUHjv8pCqDwb6DCYyW4apHyeOR6YUPiaXoGH6kARsXSmcb6Z egnm+TToF8ks2H7EGKqxjiwipXZ0yRFE3g2blztRft/18ntFEUHn+u0GbbeXx1oRk3 YuBsq5u2SV1ll661dfDxBn9Gy+2bg0KCiHFL3T4sEN92UWu/OvTogsBU4RMmFfZWSO j5fKwJksZ+yCg== 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 , anthony.perard@citrix.com, wl@xen.org Subject: [PATCH v6 5/7] xenstored: send an evtchn notification on introduce_domain Date: Wed, 4 May 2022 17:16:54 -0700 Message-Id: <20220505001656.395419-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: 1651709847731100002 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. Before sending the notification, clear XENSTORE_RECONNECTING. The extra notification is harmless for domains that don't require it. In xs_wire.h update the commment on top of XENSTORE_RECONNECTING to generalize its meaning to suit the dom0less use-case better. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini CC: jgross@suse.com CC: anthony.perard@citrix.com CC: wl@xen.org Reviewed-by: Juergen Gross --- If you have better suggestions for the wording in xs_wire.h please suggest! Changes in v6: - use XENSTORE_CONNECTED instead of 0x0 - update xs_wire.h Changes in v5: - reset XS_CONNECTION_STATE_RECONNECTING before notifying the domU Changes in v2: - drop the new late_init parameter --- tools/xenstore/xenstored_domain.c | 4 ++++ xen/include/public/io/xs_wire.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index ae065fcbee..6f34af225c 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -493,6 +493,10 @@ 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 */ + interface->connection =3D XENSTORE_CONNECTED; + xenevtchn_notify(xce_handle, domain->port); + if (!is_master_domain && !restore) fire_watches(NULL, ctx, "@introduceDomain", NULL, false, NULL); diff --git a/xen/include/public/io/xs_wire.h b/xen/include/public/io/xs_wir= e.h index 953a0050a3..c1ec7c73e3 100644 --- a/xen/include/public/io/xs_wire.h +++ b/xen/include/public/io/xs_wire.h @@ -141,7 +141,7 @@ struct xenstore_domain_interface { =20 /* Valid values for the connection field */ #define XENSTORE_CONNECTED 0 /* the steady-state */ -#define XENSTORE_RECONNECT 1 /* guest has initiated a reconnect */ +#define XENSTORE_RECONNECT 1 /* reconnect in progress */ =20 /* Valid values for the error field */ #define XENSTORE_ERROR_NONE 0 /* No error */ --=20 2.25.1 From nobody Fri Mar 29 06:04: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=1651709851; cv=none; d=zohomail.com; s=zohoarc; b=YUL0wju9gKAEiclhClr4l0u6I3ftL+z+7d1F4wjg8X3guHc/DNUWmRnoVNWSjrngSXyt5iqDvENJclFEIWfEx3Dk24qo9wNYbWU3PGpKSSErQVhOLoYnqE7HCj0Dl/pJre2giU5aNb18jSL2eis41Paxxy8Lj3haeZQBjgO8wDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651709851; 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=dLgw0b7DVGtkLPPsJ4sSdxS6l5xqUV+fCH3YulCB5ds=; b=T5Pb7KaCqUh4fBDLJKNSAAs84DALAVn0auksni/XOnA/yT3I9ZivqUuLRP7vySIIaxss3r8+G/NfRjM/XBM2t5jiUl50eAPr3ShF5b9bqonX13tIhGfyehQRQlSyXnbdVUeE74im8GLy453ceeZ3LcZHneBxU16E+J3vFgYwlrs= 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 1651709851280315.227099236889; Wed, 4 May 2022 17:17:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.321180.542139 (Exim 4.92) (envelope-from ) id 1nmPB6-0000Wf-7Y; Thu, 05 May 2022 00:17:08 +0000 Received: by outflank-mailman (output) from mailman id 321180.542139; Thu, 05 May 2022 00:17:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPB5-0000Us-Rq; Thu, 05 May 2022 00:17:07 +0000 Received: by outflank-mailman (input) for mailman id 321180; Thu, 05 May 2022 00:17:06 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPB3-0007ib-Ii for xen-devel@lists.xenproject.org; Thu, 05 May 2022 00:17:05 +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 af68623d-cc08-11ec-a406-831a346695d4; Thu, 05 May 2022 02:17:02 +0200 (CEST) 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 51DE761D53; Thu, 5 May 2022 00:17:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 459E8C385A4; Thu, 5 May 2022 00:17:00 +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: af68623d-cc08-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651709820; bh=/N68VmzRvwvpluFCprOhDNpEgtNIdxYSilGj4T1UcRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lPKsmPT0fgZXnVdDg8bMTvjs8MDSJYA4qjPV6kUk8WP6P4hA4vU+d0S5yBKq+jYOi tAIWS+ZTnjcoTg+I7PMcBpI7oF7cjwdOatfNQMyijnLscfVcKuugmSNXEzuh6/CIoB 3QYu8GFnNLG51ZddkOmPz1M8iQRwLFjqwHyvmAeJ0SqcuXX4bfKWOI0akAE6J1jXyA xr4Hbxs/O00P7g32u4dvLczoM8xyPlUYl1lKe8HHnlq65p52Hs83oovvr60NSuQqmg +9nQWg6hyT6RZY8j6Gfuvs2Xq3k2mZdVlVhvgB8mr0fRo0pMukvlBuS8boEjwkwcxv RiEaaxAyG2xDQ== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, jgross@suse.com, Bertrand.Marquis@arm.com, julien@xen.org, Volodymyr_Babchuk@epam.com, Luca Miccio , Stefano Stabellini , Wei Liu , Anthony PERARD Subject: [PATCH v6 6/7] tools: add example application to initialize dom0less PV drivers Date: Wed, 4 May 2022 17:16:55 -0700 Message-Id: <20220505001656.395419-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: 1651709853443100001 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. The application sets "connection" to XENSTORE_RECONNECT on the xenstore page before calling xs_introduce_domain to signal that the connection is not ready yet to be used. XENSTORE_RECONNECT is reset soon after by xenstored. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini CC: Wei Liu CC: Anthony PERARD CC: Juergen Gross --- Changes in v6: - include xs_wire.h and use its definitions Changes in v5: - set XS_CONNECTION_STATE_RECONNECTING before xs_introduce_domain Changes in v4: - only alloc xs page (no other magic pages) - add xenstore permissions - check all return values - rename restore_xenstore to create_xenstore - set target_memkb - set start_time properly - close xs transaction on error - call xc_dom_gnttab_seed instead of xc_dom_gnttab_init - xs_open instead of xs_daemon_open Changes in v3: - handle xenstore errors - add an in-code comment about xenstore entries - less verbose output - clean-up error path in main Changes in v2: - do not set HVM_PARAM_STORE_EVTCHN twice - rename restore_xenstore to create_xenstore - increase maxmem connection reconnecting --- tools/helpers/Makefile | 13 ++ tools/helpers/init-dom0less.c | 340 ++++++++++++++++++++++++++++++++++ 2 files changed, 353 insertions(+) create mode 100644 tools/helpers/init-dom0less.c diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile index 7f6c422440..8d78ab1e90 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) $(LDLIBS_libxenforeignmemory) $(APPEND_LDFLA= GS) + .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..bfd5ff0761 --- /dev/null +++ b/tools/helpers/init-dom0less.c @@ -0,0 +1,340 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "init-dom-json.h" + +#define XENSTORE_PFN_OFFSET 1 +#define STR_MAX_LENGTH 64 + +static int alloc_xs_page(struct xc_interface_core *xch, + libxl_dominfo *info, + uint64_t *xenstore_pfn) +{ + int rc; + const xen_pfn_t base =3D GUEST_MAGIC_BASE >> XC_PAGE_SHIFT; + xen_pfn_t p2m =3D (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + XENSTORE_PFN_O= FFSET; + + rc =3D xc_domain_setmaxmem(xch, info->domid, + info->max_memkb + (XC_PAGE_SIZE/1024)); + if (rc < 0) + return rc; + + rc =3D xc_domain_populate_physmap_exact(xch, info->domid, 1, 0, 0, &p2= m); + if (rc < 0) + return rc; + + *xenstore_pfn =3D base + XENSTORE_PFN_OFFSET; + rc =3D xc_clear_domain_page(xch, info->domid, *xenstore_pfn); + if (rc < 0) + return rc; + + return 0; +} + +static bool do_xs_write_dom(struct xs_handle *xsh, xs_transaction_t t, + domid_t domid, char *path, char *val) +{ + char full_path[STR_MAX_LENGTH]; + struct xs_permissions perms[2]; + + perms[0].id =3D domid; + perms[0].perms =3D XS_PERM_NONE; + perms[1].id =3D 0; + perms[1].perms =3D XS_PERM_READ; + + if (snprintf(full_path, STR_MAX_LENGTH, + "/local/domain/%u/%s", domid, path) < 0) + return false; + if (!xs_write(xsh, t, full_path, val, strlen(val))) + return false; + return xs_set_permissions(xsh, t, full_path, perms, 2); +} + +static bool do_xs_write_libxl(struct xs_handle *xsh, xs_transaction_t t, + domid_t domid, char *path, char *val) +{ + char full_path[STR_MAX_LENGTH]; + + if (snprintf(full_path, STR_MAX_LENGTH, + "/libxl/%u/%s", domid, path) < 0) + return false; + return xs_write(xsh, t, full_path, val, strlen(val)); +} + +static bool do_xs_write_vm(struct xs_handle *xsh, xs_transaction_t t, + libxl_uuid uuid, char *path, char *val) +{ + char full_path[STR_MAX_LENGTH]; + + if (snprintf(full_path, STR_MAX_LENGTH, + "/vm/" LIBXL_UUID_FMT "/%s", LIBXL_UUID_BYTES(uuid), path= ) < 0) + return false; + return xs_write(xsh, t, full_path, val, strlen(val)); +} + +/* + * The xenstore nodes are the xenstore nodes libxl writes at domain + * creation. + * + * The list was retrieved by running xenstore-ls on a corresponding + * domain started by xl/libxl. + */ +static int create_xenstore(struct xs_handle *xsh, + libxl_dominfo *info, libxl_uuid uuid, + evtchn_port_t xenstore_port) +{ + domid_t domid; + unsigned 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 target_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; + struct timeval start_time; + char start_time_str[STR_MAX_LENGTH]; + int rc; + + if (gettimeofday(&start_time, NULL) < 0) + return -errno; + rc =3D snprintf(start_time_str, STR_MAX_LENGTH, "%jd.%02d", + (intmax_t)start_time.tv_sec, (int)start_time.tv_usec / 10000); + if (rc < 0) + return rc; + + domid =3D info->domid; + rc =3D snprintf(id_str, STR_MAX_LENGTH, "%u", domid); + if (rc < 0) + return rc; + rc =3D snprintf(dom_name_str, STR_MAX_LENGTH, "dom0less-%u", domid); + if (rc < 0) + return rc; + rc =3D snprintf(uuid_str, STR_MAX_LENGTH, LIBXL_UUID_FMT, LIBXL_UUID_B= YTES(uuid)); + if (rc < 0) + return rc; + rc =3D snprintf(vm_val_str, STR_MAX_LENGTH, + "vm/" LIBXL_UUID_FMT, LIBXL_UUID_BYTES(uuid)); + if (rc < 0) + return rc; + rc =3D snprintf(max_memkb_str, STR_MAX_LENGTH, "%lu", info->max_memkb); + if (rc < 0) + return rc; + rc =3D snprintf(target_memkb_str, STR_MAX_LENGTH, "%lu", info->current= _memkb); + if (rc < 0) + return rc; + rc =3D snprintf(ring_ref_str, STR_MAX_LENGTH, "%lld", + (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + XENSTORE_PFN_OFFSE= T); + if (rc < 0) + return rc; + rc =3D snprintf(xenstore_port_str, STR_MAX_LENGTH, "%u", xenstore_port= ); + if (rc < 0) + return rc; + +retry_transaction: + t =3D xs_transaction_start(xsh); + if (t =3D=3D XBT_NULL) + return -errno; + + rc =3D -EIO; + /* /vm */ + if (!do_xs_write_vm(xsh, t, uuid, "name", dom_name_str)) goto err; + if (!do_xs_write_vm(xsh, t, uuid, "uuid", uuid_str)) goto err; + if (!do_xs_write_vm(xsh, t, uuid, "start_time", start_time_str)) goto = err; + + /* /domain */ + if (!do_xs_write_dom(xsh, t, domid, "vm", vm_val_str)) goto err; + if (!do_xs_write_dom(xsh, t, domid, "name", dom_name_str)) goto err; + if (!do_xs_write_dom(xsh, t, domid, "cpu", "")) goto err; + for (i =3D 0; i < info->vcpu_max_id; i++) { + rc =3D snprintf(cpu_str, STR_MAX_LENGTH, "cpu/%u/availability/", i= ); + if (rc < 0) + goto err; + rc =3D -EIO; + if (!do_xs_write_dom(xsh, t, domid, cpu_str, + (info->cpupool & (1 << i)) ? "online" : "offl= ine")) + goto err; + } + + if (!do_xs_write_dom(xsh, t, domid, "memory", "")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "memory/static-max", max_memkb_str= )) goto err; + if (!do_xs_write_dom(xsh, t, domid, "memory/target", target_memkb_str)= ) goto err; + if (!do_xs_write_dom(xsh, t, domid, "memory/videoram", "-1")) goto err; + + if (!do_xs_write_dom(xsh, t, domid, "device", "")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "device/suspend", "")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "device/suspend/event-channel", ""= )) goto err; + + if (!do_xs_write_dom(xsh, t, domid, "control", "")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "control/shutdown", "")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "control/feature-poweroff", "1")) = goto err; + if (!do_xs_write_dom(xsh, t, domid, "control/feature-reboot", "1")) go= to err; + if (!do_xs_write_dom(xsh, t, domid, "control/feature-suspend", "")) go= to err; + if (!do_xs_write_dom(xsh, t, domid, "control/sysrq", "")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "control/platform-feature-multipro= cessor-suspend", "1")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "control/platform-feature-xs_reset= _watches", "1")) goto err; + + if (!do_xs_write_dom(xsh, t, domid, "domid", id_str)) goto err; + if (!do_xs_write_dom(xsh, t, domid, "data", "")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "drivers", "")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "feature", "")) goto err; + if (!do_xs_write_dom(xsh, t, domid, "attr", "")) goto err; + + if (!do_xs_write_dom(xsh, t, domid, "store/port", xenstore_port_str)) = goto err; + if (!do_xs_write_dom(xsh, t, domid, "store/ring-ref", ring_ref_str)) g= oto err; + + if (!do_xs_write_libxl(xsh, t, domid, "type", "pvh")) goto err; + if (!do_xs_write_libxl(xsh, t, domid, "dm-version", "qemu_xen")) goto = err; + + if (!xs_transaction_end(xsh, t, false)) { + if (errno =3D=3D EAGAIN) + goto retry_transaction; + else + return -errno; + } + + return 0; + +err: + xs_transaction_end(xsh, t, true); + return rc; +} + +static int init_domain(struct xs_handle *xsh, + struct xc_interface_core *xch, + xenforeignmemory_handle *xfh, + libxl_dominfo *info) +{ + libxl_uuid uuid; + uint64_t xenstore_evtchn, xenstore_pfn; + int rc; + struct xenstore_domain_interface *intf; + + printf("Init dom0less domain: %u\n", info->domid); + + rc =3D xc_hvm_param_get(xch, info->domid, HVM_PARAM_STORE_EVTCHN, + &xenstore_evtchn); + if (rc !=3D 0) { + printf("Failed to get HVM_PARAM_STORE_EVTCHN\n"); + return 1; + } + + /* Alloc xenstore page */ + if (alloc_xs_page(xch, info, &xenstore_pfn) !=3D 0) { + printf("Error on alloc magic pages\n"); + return 1; + } + + intf =3D xenforeignmemory_map(xfh, info->domid, XS_READ | XS_WRITE, 1, + &xenstore_pfn, NULL); + if (!intf) { + printf("Error mapping xenstore page\n"); + return 1; + } + intf->connection =3D XENSTORE_RECONNECT; + xenforeignmemory_unmap(xfh, intf, 1); + + rc =3D xc_dom_gnttab_seed(xch, info->domid, true, + (xen_pfn_t)-1, xenstore_pfn, 0, 0); + if (rc) + err(1, "xc_dom_gnttab_seed"); + + libxl_uuid_generate(&uuid); + xc_domain_sethandle(xch, info->domid, libxl_uuid_bytearray(&uuid)); + + rc =3D gen_stub_json_config(info->domid, &uuid); + if (rc) + err(1, "gen_stub_json_config"); + + /* Now everything is ready: set HVM_PARAM_STORE_PFN */ + rc =3D xc_hvm_param_set(xch, info->domid, HVM_PARAM_STORE_PFN, + xenstore_pfn); + if (rc < 0) + return rc; + + rc =3D create_xenstore(xsh, info, uuid, xenstore_evtchn); + if (rc) + err(1, "writing to xenstore"); + + rc =3D xs_introduce_domain(xsh, info->domid, + (GUEST_MAGIC_BASE >> XC_PAGE_SHIFT) + XENSTORE_PFN_OFFSET, + xenstore_evtchn); + if (!rc) + err(1, "xs_introduce_domain"); + return 0; +} + +/* Check if domain has been configured in XS */ +static bool domain_exists(struct xs_handle *xsh, int domid) +{ + return xs_is_domain_introduced(xsh, domid); +} + +int main(int argc, char **argv) +{ + libxl_dominfo *info =3D NULL; + libxl_ctx *ctx; + int nb_vm =3D 0, rc =3D 0, i; + struct xs_handle *xsh =3D NULL; + struct xc_interface_core *xch =3D NULL; + xenforeignmemory_handle *xfh =3D NULL; + + /* TODO reuse libxl xsh connection */ + xsh =3D xs_open(0); + xch =3D xc_interface_open(0, 0, 0); + xfh =3D xenforeignmemory_open(0, 0); + if (xsh =3D=3D NULL || xch =3D=3D NULL || xfh =3D=3D NULL) { + fprintf(stderr, "Cannot open xc/xs/xenforeignmemory interfaces"); + rc =3D -errno; + goto out; + } + + rc =3D libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, NULL); + if (rc) { + fprintf(stderr, "cannot init xl context\n"); + goto out; + } + + info =3D libxl_list_domain(ctx, &nb_vm); + if (!info) { + fprintf(stderr, "libxl_list_vm failed.\n"); + rc =3D -1; + goto out; + } + + for (i =3D 0; i < nb_vm; i++) { + domid_t domid =3D info[i].domid; + + /* Don't need to check for Dom0 */ + if (!domid) + continue; + + printf("Checking domid: %u\n", domid); + if (!domain_exists(xsh, domid)) { + rc =3D init_domain(xsh, xch, xfh, &info[i]); + if (rc < 0) { + fprintf(stderr, "init_domain failed.\n"); + goto out; + } + } else { + printf("Domain %u has already been initialized\n", domid); + } + } +out: + libxl_dominfo_list_free(info, nb_vm); + return rc; +} --=20 2.25.1 From nobody Fri Mar 29 06:04: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=1651709847; cv=none; d=zohomail.com; s=zohoarc; b=hy8GVi5lXbDVFmOYu83eJQPKNEMnupTet2YvhaAxczqiWLRDVicMIKBPCOF1RXv3KeWu6Nn6t5pmaDhkut3GQgVZfnbfkOdMilnYsCUesT9zbfEaK/lfnQDiyhMTjcW7IOu71Ro/Od25G1eztNtBRyiRcjJG31yPTZ9R1FYVmhY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651709847; 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=kYkCfvgfWO00f0OUsWEgTUHpNFSy4rzqnzRUZovoBeI=; b=PkX3aE39ibyG5OoO3JJlNyUXGDFAlQFSjarcRY0z0awPRmT1acgp0hc9fPvbMBNaKsz3/sY6m6zzFdDQ+t0NEMqNiDMC5+ZjZhL0KcDv6ND1h0XpKdw4+7PN3ayBzuCPFFEGKmxJ33vwp2zOvYYzNLlXAgIFycO1Fhq3M+oM6gQ= 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 1651709847944680.2817618367133; Wed, 4 May 2022 17:17:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.321178.542125 (Exim 4.92) (envelope-from ) id 1nmPB4-0000Bw-Jm; Thu, 05 May 2022 00:17:06 +0000 Received: by outflank-mailman (output) from mailman id 321178.542125; Thu, 05 May 2022 00:17:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPB4-00008o-9N; Thu, 05 May 2022 00:17:06 +0000 Received: by outflank-mailman (input) for mailman id 321178; Thu, 05 May 2022 00:17:04 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPB2-0007pt-Eu for xen-devel@lists.xenproject.org; Thu, 05 May 2022 00:17:04 +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 afaa955e-cc08-11ec-8fc4-03012f2f19d4; Thu, 05 May 2022 02:17:03 +0200 (CEST) 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 C526B61D54; Thu, 5 May 2022 00:17:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE3A7C385AF; Thu, 5 May 2022 00:17:00 +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: afaa955e-cc08-11ec-8fc4-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651709821; bh=22bdOt6XvBV3vZtPeEaCTfB0bw/G2RA4hDJ9uoEjSFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m4sfZKihHvArayriNCGoTIgtef6y1iMvURwOYyCteNAhVfmP39wW9p+FgVExSZF0/ ojrrvZPEKv34/HnQQDAUxl30cLS5gT1U120D4lXjW73osEmVkisYjQGzRRSnvBPP0+ 15PRbfYz2gFizytWchwxCW2fCJ/x+l+iwxLV4Czu7/I1T4mYM5GpIWvQ6t3sCDN6X0 9RkffTyiBR5eb1p9NgcTXVR4IJg5Ca5ATeLyM9xjJ359luLgecy+qPfM76eSfqiQKk DoaNyGFCO8bZOhIxN59eywz8smmRV+ClqxxmbQBCMZvd5irh/H6RWXBBH5r3Mm9EY4 FXMOhRpr/5mMA== 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 , Luca Fancellu Subject: [PATCH v6 7/7] docs: document dom0less + PV drivers Date: Wed, 4 May 2022 17:16:56 -0700 Message-Id: <20220505001656.395419-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: 1651709849343100006 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini Document how to use the feature and how the implementation works. Signed-off-by: Stefano Stabellini Reviewed-by: Luca Fancellu Acked-by: Julien Grall --- docs/features/dom0less.pandoc | 43 ++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/docs/features/dom0less.pandoc b/docs/features/dom0less.pandoc index c9edb529e1..725afa0558 100644 --- a/docs/features/dom0less.pandoc +++ b/docs/features/dom0less.pandoc @@ -90,6 +90,46 @@ Otherwise, they may be unusable in Xen (for instance if = they are compressed). =20 See docs/misc/arm/device-tree/booting.txt for more information. =20 +PV Drivers +---------- + +It is possible to use PV drivers with dom0less guests with some +restrictions: + +- dom0less domUs that want to use PV drivers support should have the + "xen,enhanced" property set under their device tree nodes (see + docs/misc/arm/device-tree/booting.txt) +- a dom0 must be present (or another domain with enough privileges to + run the toolstack) +- after dom0 is booted, the utility "init-dom0less" must be run +- do not run "init-dom0less" while creating other guests with xl + +After the execution of init-dom0less, it is possible to use "xl" to +hotplug PV drivers to dom0less guests. E.g. xl network-attach domU. + +The implementation works as follows: +- Xen allocates the xenstore event channel for each dom0less domU that + has the "xen,enhanced" property, and sets HVM_PARAM_STORE_EVTCHN +- Xen does *not* allocate the xenstore page and sets HVM_PARAM_STORE_PFN + to ~0ULL (invalid) +- Dom0less domU kernels check that HVM_PARAM_STORE_PFN is set to invalid + - Old kernels will continue without xenstore support (Note: some old + buggy kernels might crash because they don't check the validity of + HVM_PARAM_STORE_PFN before using it! Disable "xen,enhanced" in + those cases) + - New kernels will wait for a notification on the xenstore event + channel (HVM_PARAM_STORE_EVTCHN) before continuing with the + initialization +- Once dom0 is booted, init-dom0less is executed: + - it allocates the xenstore shared page and sets HVM_PARAM_STORE_PFN + - it calls xs_introduce_domain +- Xenstored notices the new domain, initializes interfaces as usual, and + sends an event channel notification to the domain using the xenstore + event channel (HVM_PARAM_STORE_EVTCHN) +- The Linux domU kernel receives the event channel notification, checks + HVM_PARAM_STORE_PFN again and continue with the initialization + + Limitations ----------- =20 @@ -107,9 +147,6 @@ limitations: information, the GIC version exposed to the domains started by Xen at boot is the same as the native GIC version. =20 -- No PV drivers. There is no support for PV devices at the moment. All - devices need to be statically assigned to guests. - - Pinning vCPUs of domains started by Xen at boot can be done from the control domain, using `xl vcpu-pin` as usual. It is not currently possible to configure vCPU pinning without a control domain. --=20 2.25.1