From patchwork Tue Feb 8 18:00:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 12739144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF1ACC433FE for ; Tue, 8 Feb 2022 18:00:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268491.462331 (Exim 4.92) (envelope-from ) id 1nHUmo-00068d-Cc; Tue, 08 Feb 2022 18:00:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268491.462331; Tue, 08 Feb 2022 18:00:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmo-00068W-9f; Tue, 08 Feb 2022 18:00:18 +0000 Received: by outflank-mailman (input) for mailman id 268491; Tue, 08 Feb 2022 18:00:17 +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 1nHUmn-00068K-3w for xen-devel@lists.xenproject.org; Tue, 08 Feb 2022 18:00:17 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f67cc8ae-8908-11ec-8f75-fffcc8bd4f1a; Tue, 08 Feb 2022 19:00:14 +0100 (CET) Received: from pps.filterd (m0174678.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 218EgrT2015757; Tue, 8 Feb 2022 18:00:12 GMT Received: from eur02-he1-obe.outbound.protection.outlook.com (mail-he1eur02lp2057.outbound.protection.outlook.com [104.47.5.57]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3e3t5xrs6q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 18:00:11 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by VE1PR03MB5613.eurprd03.prod.outlook.com (2603:10a6:803:12a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19; Tue, 8 Feb 2022 18:00:06 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0%6]) with mapi id 15.20.4951.019; Tue, 8 Feb 2022 18:00:06 +0000 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: f67cc8ae-8908-11ec-8f75-fffcc8bd4f1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YiwDlP3vRAbBoMjwRE1DEMeNzuy/z4yOtYj+6mxRiCegonEQ01woy2anuIGi+cFAXjJMO4Pg4pF+S4t+6IdDlC3/lSAnJOqa7u9CnlJ61t3dYeNlmCxB8vYc+6kuBb6IsJgMh0QK3yL0moIsm0xypelXrtCZ4nrx0rk/rS1A4a0Uck07r/4VKwXSO398sTnvbTnFOCk4OIP7TGTvkfH70nms7uC8bqTyXhP0D/A6DChg8SETmd4WKiJ/YtyGlDmRKy6CiWRHqpChsceAFjjTuCB+9Ure1ZTkVZQbQjMaykuUralkABpHyWVj7V5qT9/6cx6XA8dEVYHu/wL2Peymaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Zp886fdenazy8I4uy4JOrrugnDLYw+4E5d77d3IGdYU=; b=QUxMC3tOWqSmKH7p+bAsfGvJGbup8DmnObj4KIOwZIF2F+Mtdh0XLM6Zwx0w0RnBgk/1EQAsraDfij8WoGQzkfEH1i7uoNnZPkpWldyfLhcTyYilWdiQEd5c9fgmjP9GGYjpUFEbHiiR3o3jueECbmiLLp3wNorJciPK7AmufAesPXxOwDEiTIs4gSqhihxhCuDkL5cAZWZ7Kmb29WUZCFWrIrGM195PWV1pCu3lw9aLSjNpnG0J99die9vW6XgyoGLNRbFX5iwbN/yg3lY23W4683ctxUQPs5/ReapKsQyTzBtZeU6zsHD7QeuxiDcOW5fh6nlnEukpeFi7KSZkUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zp886fdenazy8I4uy4JOrrugnDLYw+4E5d77d3IGdYU=; b=eC+n5fSTp8riCSmttv9a7mw1RZaur//zyuhK2meAE9XVyTLuXMkeQGGDBDpszNmcRA3f5M17PVhKNeYdIv1Zasz6TBKbsS9pcWAcNkxZU6Llx2xO39thw2aufY8hq1JB9j24XPvZ1vYqEQR2lHl3ZiSFardLrUImfQvFIoTpHY9LOHm6ZU8F99uX1kugrJqgy54JteK6JOhJyuYU7cW/Sk9x7IxCkCcdWi9Bz8dRkJPFlRR6bP4/ZQgW6do6ErVF1ov9puWknlEQd83cL01bZeBTEiZ1DRBaDtBfa667pcMKygoqfEwd/rLhAqDuZ3H9UwAzITSg5/Yq48sfSwuWjg== From: Oleksii Moisieiev To: "xen-devel@lists.xenproject.org" CC: Oleksii Moisieiev , Juergen Gross Subject: [RFC v2 1/8] xen/hypfs: support fo nested dynamic hypfs nodes Thread-Topic: [RFC v2 1/8] xen/hypfs: support fo nested dynamic hypfs nodes Thread-Index: AQHYHRW07SkrMxyT/k6/hhSCHW7Rmg== Date: Tue, 8 Feb 2022 18:00:06 +0000 Message-ID: <8ab7e9ffd5f041c2631f754c7c596874cf6a99c1.1644341635.git.oleksii_moisieiev@epam.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ec53d40c-2a59-49f2-c7b6-08d9eb2cd6e4 x-ms-traffictypediagnostic: VE1PR03MB5613:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4941; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: M925godofpc/lzkYZpjCxO5Z3+hNdtDE0Aeme/XmzDf6pgAQe9GTjMproVG2AhJNtKXKbTwUK+92SQ54Xb9DXbpdd6+nkygZncTMbuzsLn8hBxnI2dXKggeIR6p+Oy9RpS8hX7RWFZo/d6zLJQI4mfAczAxRXzQqh/71a17jHCVRyVG6YP8L7ZEFXhMpupR1l4eTAgqDpg9TVeHgVcYU2RO6fhfrZDnVYn5AP0NHQ071H1UouXsxbCNmcuZ2E3JWi+4EL7vVf8CinOFEsqtpMbIDNCHHNWXDS0Ng/KOb4EagJdnzRvVwghATY/sFJAVm9xSBbm4qb+y2QynfQAbSh/TewpcGIXCCUjPc4kVNs+rPQgexC2g6FtExTpl89wfWLNS3hRezjt6sK7N6BottTQOm0MQ5qtbubqfh53lzsX369HQUEYkoH7U98VcP7iMMMdO6ZSkqM+3ebaTdTqIBTSOWTuxQ1WeuTOtgAhacY2kIU4YSMklFm5H2viWCmfXDcsNq6xVpIuJbbNHLCnc3OTzWczBgf7R2BLop+oNVQF+mfg5gBeK2W4qWiBnOFY75v9g6fcZhDFzNNd7G+6UQfWD4IMZI25KKjXUp1cQANZFS5Mf7MOBKz0n01/9Hj5nhAKcu9yFp5ZTgv8rZ9zBoJYAu6kV5gEkWmejTbd7UnO3AalCtplUcZTQiWjYnidUY4v6ei0AOC2OLMzf3QJCkiA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38070700005)(71200400001)(6486002)(508600001)(66476007)(64756008)(86362001)(66556008)(316002)(122000001)(6916009)(6506007)(2616005)(5660300002)(6512007)(4326008)(83380400001)(54906003)(2906002)(26005)(186003)(8676002)(76116006)(38100700002)(66446008)(66946007)(8936002)(36756003)(91956017);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?xKkU+ob0B1OPUwigD9emPoD?= =?iso-8859-1?q?S22D1O39Rrg3DSS1fWHxhAr7Y5bEU8WvzIY6JV9Vu9BPWYuTzB58EqKnJdHF?= =?iso-8859-1?q?FeamOqTMBvHTw4gRaRptlonfOS07/fYBlXduE9KQ43rx7C31uy42IlKFTope?= =?iso-8859-1?q?Ip9W4naazv4wlpMftuZuA1Ugb8nUpFUnCgwrt3vWeSY1tGOPw4CoiL7Vxpl4?= =?iso-8859-1?q?wzT1sjZX0AC7p8P1GxJxRdMIZDgvB5nJf1pw9zBlYUArzGRQ70kt4Ol1bUYm?= =?iso-8859-1?q?D12+hg7GseRojRfiDf3ixylX47e96iRC5x1cNVgMI9W1bDovGT9QV4DjCFTm?= =?iso-8859-1?q?oww5tkAhWsrUTg7i32POmWDGeOy0+wX8WkrSUao6AFrQJZtWXrK+da+PwJck?= =?iso-8859-1?q?xk5M0rStf70sNoraF4Xiplb3RWs8McyG5Pq0O6QWvBs7eUUS4Zg83Mdzs+5o?= =?iso-8859-1?q?r5UXij1BRGg3o5lZi40u2BWcDA9eYuyJP/DGb6gXn2zOnoJArqpHZiWmM1CI?= =?iso-8859-1?q?JP92tj60yncpK5bVh/fV4QUzF+8ELuDrXvv0DT+hPW/77GzrTjyK/ox4EfbB?= =?iso-8859-1?q?hOvYDJil3vY9YSGTzOUVHLVb2zb4M+DqlBSJhcotbmFz+F32LcJrGMJdEBL4?= =?iso-8859-1?q?LbKlAd9/WRnRHqAC+h9r1RTqNIKjao8IDhyEfWu/7TVVNxdGFLvTWdcYLUiK?= =?iso-8859-1?q?rgsNKdXrsXz82ZSzuOqXlmi6EMnT8ZHTCOiFA4k2bkHJKB4OTJLnOKw4YIj9?= =?iso-8859-1?q?LibBLZdjpouxe25t8ybXI8AgmCr6Cbcf2KCmwwpDGHwyDHn//wtwXzQRLdQH?= =?iso-8859-1?q?i6QDASL4YdCY1iap4wGNMNES0hJT6v4f1PHk9qYVGkzBa6NqJRIj5qfahl+t?= =?iso-8859-1?q?gyzmTSrkf7zbEsb9XdrieItx7hTDfnt0qhZz4eyjh3u0CyuqUdfHM3ZoQxZF?= =?iso-8859-1?q?qi4Pk+u719DmVaWS6QDY0wzGZVIqzEVtZEh+xGW9v3Hqk6umg1txClUApWlZ?= =?iso-8859-1?q?V/UJx7rk6oG9V3n9VoQoQ641Qxj4YIkfC2Rbo65s+uBn/BnxHYKunNeW7FQO?= =?iso-8859-1?q?Tddoib8eAB7AQ/30VPf00pZ0Om5oCMPq9PGjKmrUzCxRonNjOUF57tjhxjny?= =?iso-8859-1?q?XaJumqLFI6b+ztYicmFxwzM5Dt2LvIQSaVqrU2OBDENTSvjin6eLW7K0oC04?= =?iso-8859-1?q?qvWRzPvH0fRkSSQl9+LGsLx9ZzRmJ7B24SVPjVwv/A5NhCz8u4r5jxwf4YSK?= =?iso-8859-1?q?9sO2pskpNvdHC+6hcSlaOvgnTgqMn1Jvz9lxS1CzUJxYLJLgJ/nLeAlB1iWB?= =?iso-8859-1?q?0o5Xzp+2jfXyLVsRosZubEhg53+iC71Yo8rdgpll6+/awQtKsh604r+a4wzZ?= =?iso-8859-1?q?BmTM75QaUl6vgelYYjsBOQ239Ov1I1x0/2dWnt0MgGaBAtaqkdhNs4xAfyat?= =?iso-8859-1?q?IVHetWo/wrzlGMIzHKYvTY/AiKZrw/ilIOnxYpj7NSzGG8m9PXtwhvZzLR34?= =?iso-8859-1?q?GD8ts3edyDzAyW1dUwqu6QDovxltcH0JUYuOr/L2QXUlD1wxKCIRVxbs3/+r?= =?iso-8859-1?q?uDLDy4xHm8WrCpixfqS2G9SLFvtSHTt7kiQmIb+TV7JDN7/RppWhHk/wxKQF?= =?iso-8859-1?q?d9d26T2zKRD3fx8bB/3VNcdFWUlZ3VOJOjziM5iAjmZiNaooPznVGIVAPuiy?= =?iso-8859-1?q?JFZIcOvnHGZC9KGMMNKumBpwl/Q3QuG2oqdXv+s8B+aYYPArPFJKrdmBRyJD?= =?iso-8859-1?q?P3hc=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec53d40c-2a59-49f2-c7b6-08d9eb2cd6e4 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Feb 2022 18:00:06.5573 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: gM2gdTx06HrrtJ3eII21MiAK5rjeTo34Opxb3ACRe6fNYG4RBMTkmvsByH5gx1qItsN1kNDrWrxfPX40aUvAKSnxNWBbXhGIA2CfjSSszks= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5613 X-Proofpoint-GUID: xlpRPLEwV6HuY1SOqqNURSozi-PfZpJB X-Proofpoint-ORIG-GUID: xlpRPLEwV6HuY1SOqqNURSozi-PfZpJB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_06,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080106 Add new api: - hypfs_read_dyndir_entry - hypfs_gen_dyndir_entry which are the extension of the dynamic hypfs nodes support, presented in 0b3b53be8cf226d947a79c2535a9efbb2dd7bc38. This allows nested dynamic nodes to be added. Also input parameter is hypfs_entry, so properties can also be generated dynamically. Generating mixed list of dirs and properties is also supported. Same as to the dynamic hypfs nodes, this is anchored in percpu pointer, which can be retriewed on any level of the dynamic entries. This handle should be allocated on enter() callback and released on exit() callback. When using nested dynamic dirs and properties handle should be allocated on the first enter() call and released on the last exit() call. Signed-off-by: Oleksii Moisieiev --- xen/common/hypfs.c | 83 +++++++++++++++++++++++++++++++++-------- xen/include/xen/hypfs.h | 14 ++++++- 2 files changed, 79 insertions(+), 18 deletions(-) diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c index e71f7df479..6901f5e311 100644 --- a/xen/common/hypfs.c +++ b/xen/common/hypfs.c @@ -367,28 +367,27 @@ unsigned int hypfs_getsize(const struct hypfs_entry *entry) /* * Fill the direntry for a dynamically generated entry. Especially the - * generated name needs to be kept in sync with hypfs_gen_dyndir_id_entry(). + * generated name needs to be kept in sync with hypfs_gen_dyndir_entry(). */ -int hypfs_read_dyndir_id_entry(const struct hypfs_entry_dir *template, - unsigned int id, bool is_last, +int hypfs_read_dyndir_entry(const struct hypfs_entry *template, + const char *name, unsigned int namelen, + bool is_last, XEN_GUEST_HANDLE_PARAM(void) *uaddr) { struct xen_hypfs_dirlistentry direntry; - char name[HYPFS_DYNDIR_ID_NAMELEN]; - unsigned int e_namelen, e_len; + unsigned int e_len; - e_namelen = snprintf(name, sizeof(name), template->e.name, id); - e_len = DIRENTRY_SIZE(e_namelen); + e_len = DIRENTRY_SIZE(namelen); direntry.e.pad = 0; - direntry.e.type = template->e.type; - direntry.e.encoding = template->e.encoding; - direntry.e.content_len = template->e.funcs->getsize(&template->e); - direntry.e.max_write_len = template->e.max_size; + direntry.e.type = template->type; + direntry.e.encoding = template->encoding; + direntry.e.content_len = template->funcs->getsize(template); + direntry.e.max_write_len = template->max_size; direntry.off_next = is_last ? 0 : e_len; if ( copy_to_guest(*uaddr, &direntry, 1) ) return -EFAULT; if ( copy_to_guest_offset(*uaddr, DIRENTRY_NAME_OFF, name, - e_namelen + 1) ) + namelen + 1) ) return -EFAULT; guest_handle_add_offset(*uaddr, e_len); @@ -396,6 +395,22 @@ int hypfs_read_dyndir_id_entry(const struct hypfs_entry_dir *template, return 0; } +/* + * Fill the direntry for a dynamically generated entry. Especially the + * generated name needs to be kept in sync with hypfs_gen_dyndir_id_entry(). + */ +int hypfs_read_dyndir_id_entry(const struct hypfs_entry_dir *template, + unsigned int id, bool is_last, + XEN_GUEST_HANDLE_PARAM(void) *uaddr) +{ + char name[HYPFS_DYNDIR_ID_NAMELEN]; + unsigned int e_namelen; + + e_namelen = snprintf(name, sizeof(name), template->e.name, id); + return hypfs_read_dyndir_entry(&template->e, name, e_namelen, is_last, uaddr); +} + + static const struct hypfs_entry *hypfs_dyndir_enter( const struct hypfs_entry *entry) { @@ -404,7 +419,7 @@ static const struct hypfs_entry *hypfs_dyndir_enter( data = hypfs_get_dyndata(); /* Use template with original enter function. */ - return data->template->e.funcs->enter(&data->template->e); + return data->template->funcs->enter(data->template); } static struct hypfs_entry *hypfs_dyndir_findentry( @@ -415,7 +430,7 @@ static struct hypfs_entry *hypfs_dyndir_findentry( data = hypfs_get_dyndata(); /* Use template with original findentry function. */ - return data->template->e.funcs->findentry(data->template, name, name_len); + return data->template->funcs->findentry(&data->dir, name, name_len); } static int hypfs_read_dyndir(const struct hypfs_entry *entry, @@ -426,7 +441,36 @@ static int hypfs_read_dyndir(const struct hypfs_entry *entry, data = hypfs_get_dyndata(); /* Use template with original read function. */ - return data->template->e.funcs->read(&data->template->e, uaddr); + return data->template->funcs->read(data->template, uaddr); +} + +/* + * Fill dyndata with a dynamically generated entry based on a template + * and a name. + * Needs to be kept in sync with hypfs_read_dyndir_entry() regarding the + * name generated. + */ +struct hypfs_entry *hypfs_gen_dyndir_entry( + const struct hypfs_entry *template, const char *name, + void *data) +{ + struct hypfs_dyndir_id *dyndata; + + dyndata = hypfs_get_dyndata(); + + dyndata->template = template; + dyndata->data = data; + memcpy(dyndata->name, name, strlen(name)); + dyndata->dir.e = *template; + dyndata->dir.e.name = dyndata->name; + + dyndata->dir.e.funcs = &dyndata->funcs; + dyndata->funcs = *template->funcs; + dyndata->funcs.enter = hypfs_dyndir_enter; + dyndata->funcs.findentry = hypfs_dyndir_findentry; + dyndata->funcs.read = hypfs_read_dyndir; + + return &dyndata->dir.e; } /* @@ -442,12 +486,13 @@ struct hypfs_entry *hypfs_gen_dyndir_id_entry( dyndata = hypfs_get_dyndata(); - dyndata->template = template; + dyndata->template = &template->e; dyndata->id = id; dyndata->data = data; snprintf(dyndata->name, sizeof(dyndata->name), template->e.name, id); dyndata->dir = *template; dyndata->dir.e.name = dyndata->name; + dyndata->dir.e.funcs = &dyndata->funcs; dyndata->funcs = *template->e.funcs; dyndata->funcs.enter = hypfs_dyndir_enter; @@ -457,6 +502,12 @@ struct hypfs_entry *hypfs_gen_dyndir_id_entry( return &dyndata->dir.e; } +unsigned int hypfs_dyndir_entry_size(const struct hypfs_entry *template, + const char *name) +{ + return DIRENTRY_SIZE(strlen(name)); +} + unsigned int hypfs_dynid_entry_size(const struct hypfs_entry *template, unsigned int id) { diff --git a/xen/include/xen/hypfs.h b/xen/include/xen/hypfs.h index e9d4c2555b..5d2728b963 100644 --- a/xen/include/xen/hypfs.h +++ b/xen/include/xen/hypfs.h @@ -79,8 +79,8 @@ struct hypfs_entry_dir { struct hypfs_dyndir_id { struct hypfs_entry_dir dir; /* Modified copy of template. */ struct hypfs_funcs funcs; /* Dynamic functions. */ - const struct hypfs_entry_dir *template; /* Template used. */ -#define HYPFS_DYNDIR_ID_NAMELEN 12 + const struct hypfs_entry *template; /* Template used. */ +#define HYPFS_DYNDIR_ID_NAMELEN 32 char name[HYPFS_DYNDIR_ID_NAMELEN]; /* Name of hypfs entry. */ unsigned int id; /* Numerical id. */ @@ -197,13 +197,23 @@ void *hypfs_alloc_dyndata(unsigned long size); #define hypfs_alloc_dyndata(type) ((type *)hypfs_alloc_dyndata(sizeof(type))) void *hypfs_get_dyndata(void); void hypfs_free_dyndata(void); +int hypfs_read_dyndir_entry(const struct hypfs_entry *template, + const char *name, unsigned int namelen, + bool is_last, + XEN_GUEST_HANDLE_PARAM(void) *uaddr); int hypfs_read_dyndir_id_entry(const struct hypfs_entry_dir *template, unsigned int id, bool is_last, XEN_GUEST_HANDLE_PARAM(void) *uaddr); +struct hypfs_entry *hypfs_gen_dyndir_entry( + const struct hypfs_entry *template, const char *name, + void *data); struct hypfs_entry *hypfs_gen_dyndir_id_entry( const struct hypfs_entry_dir *template, unsigned int id, void *data); unsigned int hypfs_dynid_entry_size(const struct hypfs_entry *template, unsigned int id); +unsigned int hypfs_dyndir_entry_size(const struct hypfs_entry *template, + const char *name); + #endif #endif /* __XEN_HYPFS_H__ */ From patchwork Tue Feb 8 18:00:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 12739145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9D42C43219 for ; Tue, 8 Feb 2022 18:00:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268492.462338 (Exim 4.92) (envelope-from ) id 1nHUmo-0006CC-OB; Tue, 08 Feb 2022 18:00:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268492.462338; Tue, 08 Feb 2022 18:00:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmo-0006B9-Hq; Tue, 08 Feb 2022 18:00:18 +0000 Received: by outflank-mailman (input) for mailman id 268492; Tue, 08 Feb 2022 18:00:17 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmn-00068L-ED for xen-devel@lists.xenproject.org; Tue, 08 Feb 2022 18:00:17 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f6c000f5-8908-11ec-8eb8-a37418f5ba1a; Tue, 08 Feb 2022 19:00:14 +0100 (CET) Received: from pps.filterd (m0174678.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 218EgrT3015757; Tue, 8 Feb 2022 18:00:13 GMT Received: from eur02-he1-obe.outbound.protection.outlook.com (mail-he1eur02lp2057.outbound.protection.outlook.com [104.47.5.57]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3e3t5xrs6q-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 18:00:12 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by VE1PR03MB5613.eurprd03.prod.outlook.com (2603:10a6:803:12a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19; Tue, 8 Feb 2022 18:00:07 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0%6]) with mapi id 15.20.4951.019; Tue, 8 Feb 2022 18:00:07 +0000 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: f6c000f5-8908-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jK2NgxUrslRzWeTpvLeTDGIt5K8UoM/KgoaY35I8p6o4UQlvj1aZ2iKi4bJGbCSRUmwJ3oaHzccn8Lr5GIW+YxcjL68rFVAQ4XwERbQhJcmLmM2jhbgaHqscKLHDdO2MyGu/KjvECTPwqrkIHsOXs6efvi5MqtXHkI2zYDtAMt2Ts0dVAbMA4SmKGwpbmIqCDvAX4ftUsqN5T6BVcGKdd3GOXcOjZAlww+Mw9nPRgVnp8Z4BmM3dZ/5Ho+CAEihm2OxWt6/myc+N8ks103SlvzzVn8G2ZiF6jQo1mswzdtdkQJx6yth2UQbuLe9V07t4y0NE0pSvUcLfaGAdfcnnVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=s+Pd6wDqIcFv+WQby17OvQO3c7K+c3WVoYLWvGL3Img=; b=OaIqooaCQ48+ZcNhTZy3IOTwfIbDqjVskgGKEOAEh6F5zg+WvHi4932WuJDLOuUpsWo9V/ccBodoy6pT7hiIYcVB5YnFZdrI+CPIM+6FO7cIodMZ6ecB50/RqZN2X3geuyy1aIEXxjvJLKo4qnK+eS7Iry3oMt/LD40nLVqDC7ValgN2o5rieTR4IO0tdLyKUgEP2f3Qe4D/37Ea2WHqANz0Kz7c8iVHG6durJ8rzoP9lMjE2BXpzo9b6NHkBSjL3c3Z8PynXqQ9vHc90A2YI7+3BK5HCjdb5TrQ+M8wNNSXTqUAAp/1AsvdcPWkhB3elnr+32TANfllBvP0wgYEZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s+Pd6wDqIcFv+WQby17OvQO3c7K+c3WVoYLWvGL3Img=; b=NKRI602rr+89pwZBu1o2KxvfP8dZTc3kYH6jB0oXp278uzs677VAHqCv6/SCR772ky+ak+NZ8CQv7jSgErHpMbrSZvWqR7L9Jg+/C5GuVsg9Rl3m+OfF2MxzW87CoMqwEXNgcnh6m6JbTwVOXU5+QCk8crXq3m3yNYdGYsFPUZRx3fmfLGu00FHFKXP7/le2xUK56rrwxtNVtMAWRyuPL0BBF2C5xCWJHMls1KRL3zFmJt/xz73TcubRkUqivD3od3NxBsIofFr52VaCMtJQaUwRFzLdqnG6BpkyXQ8nXlc/28TuPpnMHLsdi7yRWr3PiMjOBuBl+7JLr4e00MbREg== From: Oleksii Moisieiev To: "xen-devel@lists.xenproject.org" CC: Oleksii Moisieiev , Juergen Gross , Wei Liu Subject: [RFC v2 2/8] libs: libxenhypfs - handle blob properties Thread-Topic: [RFC v2 2/8] libs: libxenhypfs - handle blob properties Thread-Index: AQHYHRW0gTNwRxUA1k2bknae2DocAw== Date: Tue, 8 Feb 2022 18:00:07 +0000 Message-ID: <069eb801bc999ea85c529fa5033121e96b9df06f.1644341635.git.oleksii_moisieiev@epam.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d5209da9-18ed-42a0-e3ca-08d9eb2cd786 x-ms-traffictypediagnostic: VE1PR03MB5613:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: P7TW0UFCVr6XYzH45vY4lkwUMvmuQkNRNnz/bpFB9QYbMTMHuQ7wHnjDEpNF49tF+0YTlP/aKQjYK6W+JjM+Y+aR3bmQ2yY2GWhxAdWWihqmL0mANMKO6zaDCnHpkUNzd4SiZ4e0Y4c7Bmrr42uGU31oNU6VCPsoL5VGez00bUaRxgfofr3tG7JbRgfZaLYqhhqp6it6aSUnGu1DdwgRX0N0j0TOsM+uD+S3pD0mbt7xPc9C56LoerOZgz+vNYlt0ymwgd3zdYPdSb8S9q6wQ/Vc37QnJpD29UILf1NkQ0JIyitWc/tsHq9kkWGV0E3c/gMPwkdlktOxsFSrUCjLssZPkpJuWYEoI6XPwULiE8ZeM1Y8YeeQTTNG3iIWSHAaclUqHKK1z2bmKBE62RQALisvn+16ALWOKybAfa7nX/92LjPnMksNA1GpAzo0PbXWYNgB9SkfkSg1fHkl3b8C6m7xKSK9mJUpzaaDs5YRLMNwgoS9vyqcBijFpS+oPjwtjv/WRmBnRmFkMzrNG8xdk29qryFvYpXSAVQzmlcWizGeknQablPHi4bAn82LypzJg/bNMRy/hvsX0GUDgkkbVmGyuTgYy4tTWKX6dkEOnTMpLAvzMxKke3IQacl7H3NU+8NAIJVLOf2JBaPNrQcOZyEIzNn8ffOw1GLzUC4HGSeqC6hinp2LrnzYz/h4Hi2s0zpNq4e+0UsuiRI1r7/33A== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38070700005)(71200400001)(6486002)(508600001)(66476007)(64756008)(86362001)(66556008)(316002)(122000001)(6916009)(6506007)(2616005)(5660300002)(6512007)(4326008)(83380400001)(54906003)(4744005)(2906002)(26005)(186003)(8676002)(76116006)(38100700002)(66446008)(66946007)(8936002)(36756003)(91956017);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?LvvhPleD4XcuZ6FqzOy/tU6?= =?iso-8859-1?q?O3SeYh08wd7gkaw0UYP7HST1DluQeMBwcsdVK5XIRVPAojBQo5fJuMzddIDf?= =?iso-8859-1?q?2li3Y7dN9nJlFuxzPOKZvHlVs5odutLMXVAhbIodQwgOh3/iIbCQ4fGYwS41?= =?iso-8859-1?q?mhdmz2gk1C3NGs3Vr5JstgP3jylxHKD1HPNV2eM2lhdV5b43irrof4BQWRcy?= =?iso-8859-1?q?82U6Ry4MGPuLRCSIFSEfRsRwi2cRBqgI9cNNckXWVOPLrlGG2Et5wdNmNHR3?= =?iso-8859-1?q?h7OjQQ2y5IEAavHQ5vJBVRb+MeRCpPbFEHbVgmRy61pzLFjLOtGCnGkyrFKJ?= =?iso-8859-1?q?MIzDLVvKbU8v0RxhEpzcTNAC+s4SSL1SiUSdQQ6sljXiEuDvLmjmKuImjxtf?= =?iso-8859-1?q?lTOkgS1H8W4rCVc184ysvJ3pfPISH1tEwoY3T1BhOWBseaffH+4vuAiIM1y0?= =?iso-8859-1?q?2IOEXsCRkpueqvUXAwWkRAR7fvrwgaCoAfdI4RBkEJUZP5VAsj25kjgneEkA?= =?iso-8859-1?q?zceebL77aEjLYk8u+33qGrGAO+8cTgavvo7/WoIOlo/44ZllNnl6RlzjIe58?= =?iso-8859-1?q?mCb3cKoZukgMbSxPNMKp2VbF3GiUd0BOdbm9146fm68/78zzq5IoX87pw/9E?= =?iso-8859-1?q?Dqz8NY2XkVsCG2JpKn5oD3w4e/+yg/mhd+V7c3lMf4NDySkLgIlxc/YLVc2u?= =?iso-8859-1?q?yG8TdQ4b3tdsifuLAIBYI4DCUOq+RrQQLOkP/0LJZYU3iOW0YMutU04rFZzf?= =?iso-8859-1?q?gNUsh1ZSQVO61/JCrGPpkXD9Re9upLGgW2sNHsf97HiOs+N8f0V8AVQjun06?= =?iso-8859-1?q?cJdTwnLwtyn1H+jnPiED4hgGwbc1XQgYuVNWIn73BmS0E4jx1CtdcaVEBgVv?= =?iso-8859-1?q?U3a6fVHu6Xlsz/EYEtZKP18EMr982kmwWqSDluCAjZVnSBGGeJRisNpJNdKw?= =?iso-8859-1?q?VZCtmEssnlOormJVhdVQTfaVS5sAU8zILb9tCgBYEgT8Wxp5N63+NsIehBP4?= =?iso-8859-1?q?9AbQ4HXNQ8ea6zuR4/BzrL7kZyo7HhOamxa+QVlVsv19TIvbWn7eHUjKgTc7?= =?iso-8859-1?q?mTGoC8vSQIRWFfDvxkhrPt1qnFMTp7UMcPCbah89JzeYyLFahHTsvvcFJsRW?= =?iso-8859-1?q?HHi0xsbCk48O+vvAm/jj9L7saUa9XA+38Pidtx+c1/r0VIROOwL/YAlqLSFF?= =?iso-8859-1?q?hWqU8jx6CUwKx2Ho68Ba5XSWXa8x8LqDAcvVJHop/85yX+huYUJXaLbxs7vw?= =?iso-8859-1?q?Tlv6FKnaYvUx2iRt0j5ZCJMCQ2+175UM4fNlsINjPvxPCc0K9FCiSqUQ3Ac9?= =?iso-8859-1?q?rmqTWExg8yAKRyy778GuLcBtVHWi8wddHhgvZrOY7ZdhAIJzdW5m1nwCcEMh?= =?iso-8859-1?q?JMDirU6F8ls1rmEXqhhZPRwsEQgcqM5J4yTgk42HGZH5eQ5zngBoyrXTjPek?= =?iso-8859-1?q?+d4Uu87JgK03IcziJA0ZhkE06CTK9/Zc9RBNAn43YItIX0Cpxyrn4iDVCo4l?= =?iso-8859-1?q?oio7LuZWSVQE9l56GtO/t5d36uSV09L3ro3L2zIE3CwGx4jjlRPCMko/HFzb?= =?iso-8859-1?q?zlpm4Nz1qCeVYUC8lf88wtjp17rxFftS1IYx9UJ71fsDPtOhVcyCeiMOwiy5?= =?iso-8859-1?q?Jxe2fADV1Kf0+9RycrOsN0MNYft3T9zw/1YXj7tT+mm+YHXBela8wqB1vFXT?= =?iso-8859-1?q?fNABWcCfozrfij4r+cfkAo+/3LVkxn1o747nKS9VqBhyGnDXMPHQ6HBzhE7y?= =?iso-8859-1?q?nnLg=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5209da9-18ed-42a0-e3ca-08d9eb2cd786 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Feb 2022 18:00:07.5727 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: K+t9JbjMlj32GLMoocgkFrLadeNOO/AALJ2g91HJJm7hjH8uS8hwxHO9SUanaIcx2dOn1qmdjaJuzSTy23qeleYPOfAjDSHv0rU+fUQK/Mk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5613 X-Proofpoint-GUID: Yrdh4-iaXSekn28dL7blLXf5-oqSC9QH X-Proofpoint-ORIG-GUID: Yrdh4-iaXSekn28dL7blLXf5-oqSC9QH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_06,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=740 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080106 libxenhypfs will return blob properties as is. This output can be used to retrieve information from the hypfs. Caller is responsible for parsing property value. Signed-off-by: Oleksii Moisieiev Reviewed-by: Juergen Gross --- tools/libs/hypfs/core.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/libs/hypfs/core.c b/tools/libs/hypfs/core.c index 52b30db8d7..d09bba7d8c 100644 --- a/tools/libs/hypfs/core.c +++ b/tools/libs/hypfs/core.c @@ -307,8 +307,6 @@ char *xenhypfs_read(xenhypfs_handle *fshdl, const char *path) errno = EISDIR; break; case xenhypfs_type_blob: - errno = EDOM; - break; case xenhypfs_type_string: ret_buf = buf; buf = NULL; From patchwork Tue Feb 8 18:00:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 12739148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 07808C43217 for ; Tue, 8 Feb 2022 18:00:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268493.462354 (Exim 4.92) (envelope-from ) id 1nHUmr-0006e9-3z; Tue, 08 Feb 2022 18:00:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268493.462354; Tue, 08 Feb 2022 18:00:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmr-0006e0-0W; Tue, 08 Feb 2022 18:00:21 +0000 Received: by outflank-mailman (input) for mailman id 268493; Tue, 08 Feb 2022 18:00:19 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmp-00068L-6w for xen-devel@lists.xenproject.org; Tue, 08 Feb 2022 18:00:19 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f8c5c876-8908-11ec-8eb8-a37418f5ba1a; Tue, 08 Feb 2022 19:00:17 +0100 (CET) Received: from pps.filterd (m0174678.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 218EgrT5015757; Tue, 8 Feb 2022 18:00:14 GMT Received: from eur02-he1-obe.outbound.protection.outlook.com (mail-he1eur02lp2057.outbound.protection.outlook.com [104.47.5.57]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3e3t5xrs6q-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 18:00:14 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by VE1PR03MB5613.eurprd03.prod.outlook.com (2603:10a6:803:12a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19; Tue, 8 Feb 2022 18:00:08 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0%6]) with mapi id 15.20.4951.019; Tue, 8 Feb 2022 18:00:08 +0000 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: f8c5c876-8908-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hJatYUoZ25ZGt2oDLyOR456gPcza8CxVxTUEUiLehTYZbReiV+7+miEDeDULVwEZOAhCkxspH4VHkkyofEon3fFNxoz/JQ+CSM/ltwK7pyFw0XIDv4sX5i+jPZSLPbBFaEfOOZH8MM6cLqm7JS+q8cJT1+a/ZcrhJOYsCmn6V0AmO5cfRrpf0HDDmLcfiGM8oONcmSePFjOd7iA1qLejHjl/CYHEtQ1rj1gcW+XqQM/Uym97m3RMew8wQ7uLoX8e41FtZH157VKtBX+zQStgIQe/yIrgIPfJEjMWGFwyJmH6/uE0u3dItdyuooa1HJ2SQDDt4vaJqQp4b0Mm7heIPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GBlPOd7AiAkwGUmUKcL/QkLE6uduuCKGhZ0NfYwPn7M=; b=LoKqjkgnR+M19b2SLCE6GoUtfurG989VOjPipe0G4qYNEGAp1D7f+F0OqZnSRVrtBGDHdnmxyzBdrOAzuNr3zLPZyBYDCfmBCqbGMQsddQKZvU5ccfXbbKvfeXSBE+gMmfV6HPVB7OdTCN3DRXmij27QTE01HqTZiWwYnZl6inLSNOAqxL5yx3/1pHHK5sK77brWPX8r28GME9A+QhQxCHX76VhvpcQ1U9VPc3uduczaWLvVD41razb7MMuBH+iNei//h/M/NRW3qegTB3QxqCSONoVuJ3P34CaF9TqVZD5N4gTER+TQB+aDQ7CFy0xwxJOQp0NanwvxQPb5Oufzhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GBlPOd7AiAkwGUmUKcL/QkLE6uduuCKGhZ0NfYwPn7M=; b=fqDyvnbU2oGQp07LJhzRLyhP8xpdrYoQ3GYBsASMp2ND34jB7f789eSbt68CP6WNWKujVCF6KaNzD/Enl1jCEBpEoxLdZal96rpK5z8ak02wb1HgyTLWeYTtPKhgUJRhKO5nVziaXyCv6Wxq7NCUXDhah7qQrZIs1ylA6rM+dIrwuGi7hy/EdcnE92xuJsuiZXQb7BerK+j13PbUPaYi3h3yKaywLIUkBI+BTd2dR710ICfnJTs0ryqniJrVjUltlEzs2T5v2Lun4SdcZVRBS5PaiRgx8xHX0KQitAi9KRHNd4zb4Tl6m4vbvTAJ2y4SecZRts99IU8W2S6jf+xYng== From: Oleksii Moisieiev To: "xen-devel@lists.xenproject.org" CC: Oleksii Moisieiev , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis Subject: [RFC v2 3/8] xen/arm: Export host device-tree to hypfs Thread-Topic: [RFC v2 3/8] xen/arm: Export host device-tree to hypfs Thread-Index: AQHYHRW1S717SraA0Ui+K6wc2/TNAA== Date: Tue, 8 Feb 2022 18:00:08 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7fd82e46-c221-4ff7-f460-08d9eb2cd813 x-ms-traffictypediagnostic: VE1PR03MB5613:EE_ x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: eA0bzCYb7I/TEDiUeMjBIZ9YbX9Gnvap787CBuvVmndKbQC9Jyvjxhig/DUtnLgqoLSEzU0nApyueZUHwfI6UcfVLG3O6AA+g+qGVTg/H+idT0AhoQ6grg0f17Jp3iSS8ACcKnCDJyhrP3fozmJ7EAuxwgR//O9YG+NP1PFNlqQy0asIZYovdA8cEL+5vlszoDQhsXPXXEMqImZ9FB2vVp/4UMshkjNtYQ0vrr7hdN6G03FKCydow88FeptxJbNVLMiKT6JKUeh0tHrWIqSgPKiDktIcbGBD0qLyIYCZXFsM34zHVtvgp0aWK+NdsPEOi5iM9CGmf0XnspS341usE0u5J/Vl+v5qE+3eRh0pvkAa8bHOSAaB+A0ehQrboIRNJoLxOJLChd/t2e7+bxGJYLy/j6CWpQbWLFdhgXwnHUxgeWfEY7fNLe7An9+Xjv30svx8KYMTSFYmgvG9965h9ZIlgybZokx4pEEK4WaCYN0vFnz63XnceZ961H4V78SfnI3LaukL1gQsqjSO+RALABTgUnRjU4Suwv6UMEiz7muQG6J6lB1WK2UUMK8kSQs/cvPgtpqzmfOXd8v8lZWJYnm5gnB6fSQ4WqJYGPoT7CBQs9EkPi7dhowime74eXEyrrcCjjJEnqXioFdROtQa8Ii1G8DvIAF0BbuXSf+g3eNqt5j4Dy4nxpyfPhULh1H3+buGE6PPSwy9iK6PcVVpgkvYln78Gyx/UpbSEo/CSPc= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38070700005)(71200400001)(6486002)(508600001)(66476007)(64756008)(86362001)(66556008)(316002)(122000001)(6916009)(6506007)(2616005)(5660300002)(6512007)(4326008)(83380400001)(54906003)(2906002)(26005)(186003)(8676002)(76116006)(38100700002)(66446008)(66946007)(8936002)(36756003)(91956017)(2004002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?MGivsezwHpKlmbUPj+y2rFP?= =?iso-8859-1?q?N/epMygpIkmEZrDULehdMMH4VSwnZ4UABmxB2IHFOGuCkTS4iuBv3yI1QJyS?= =?iso-8859-1?q?nn+PHFJYKlKrClXeMwxSNRl1wOMvmL1/jogUYDk4mZYVQCcs8VeSjo2cB5VZ?= =?iso-8859-1?q?Nfjz4YhyDL0ldvn4NNrlUCLHx1ESF5uBPDqQw91+qCy5+toRV2Q0/inPJWpP?= =?iso-8859-1?q?NJuugSyYQa6U/aEMlZS0lFJ64MJMpDUBLR1VLYrCaT5mM8mnz1RYMKhci9TY?= =?iso-8859-1?q?Hkcn7+nDGNLi1IbOo2K/AO20zvcjADwbz51mtkh/k96TaJGoj2522tcGEcH9?= =?iso-8859-1?q?41IEimuGlLZuehljgQ1OssHdcBG3/mORWjVUKF7QXmhRA5th8UddVZH4CjEI?= =?iso-8859-1?q?/tW8+pcqlfzPZviwxv7HzKSpVJ8AK6quBCRRH6xkcy91AKBiNf45sJcd5xp+?= =?iso-8859-1?q?JKTc2dw3xfpOFCYahFuqwhKFgPtft4rKzhiJ/XmSHZgthnZWpNAw6Hz3/pW2?= =?iso-8859-1?q?Le6rXLaZprkt/eTsCLPOFk7xB8ZLZyBkTl/lLLVOVdM1PaxNRxrYtX8mlOH8?= =?iso-8859-1?q?IkTngdhjWelzpqw/H3zDHSht1tAVoevUVvj3BTpwj3pkIKTr0mzK2uOj2BtC?= =?iso-8859-1?q?rkQ6dYeUDBeCTffQQvbp8GrM0FqCIY4IXbo8RfhB0RCq+ZJdivuKVRL5W81A?= =?iso-8859-1?q?qEXhkycZZVOdcfDCW4HkexBFfDOtG55owKsZk/Xs5VrCFxgTaZu7lH4cmDpf?= =?iso-8859-1?q?09npiCUNtyS8kGQX3rsXlEOHh60TG4F5Fl+nfwEvDKKQCRmwMmRoLkuS0H+O?= =?iso-8859-1?q?o6af92WEqY34MITOET8U6k4h+wSjnUR+xirhoqwpnpX1FWwC9BeLtqAr7fkA?= =?iso-8859-1?q?SlyOYnjrCyns5hHmfiIvOIHvb297yez/VWhDSiV/qnONy+N+1Q2rgRZTdsD4?= =?iso-8859-1?q?HVUcUX/9TzSQFR5zhFNW+MY7f1uKYqbmR12PHxJgSRA2zCBTrEUF54TteWU2?= =?iso-8859-1?q?/Z55gQB3nPX4RkQ45Crpiu2vyUE09v6t1fOF9Z5ct7FJsJpYuAsQHJlzYTA3?= =?iso-8859-1?q?QzVqvRtNFIgw7q4vhYMocwVwENKPwNoN0/Mkih2jsulWmieIfAhujwPzJFZd?= =?iso-8859-1?q?sWyocAcjp26OsJvRMJh0QFbox3xhtrn6RTPxTeggTg7EmAcePXUDI382TMlu?= =?iso-8859-1?q?8JeG+f6HGE9phQGYJvxBE0EbDpEMWMZ0j7bOIpBfveIUDxQyvsi6J9AQmJ4U?= =?iso-8859-1?q?sFI5L+MfqWpt/jQ0jHvUT3zKqqPFd3NA+gO0RSkHUV01OK5WRayve/t324Br?= =?iso-8859-1?q?0x2ot82AEsUiFskkKAtM2wRJ1c+N1yjpF+E9OTcT7qcML+EzXdEHaeJ+wIJx?= =?iso-8859-1?q?OyF7w6yAX+BwvNEtXOMDCSG+OQGyRBkTfIv39w3m2MgGJQjkdzGdyxiAjGGa?= =?iso-8859-1?q?mbWEEgtVXl4I7ednBhwD1fGA+MfhtOVfA9kw7108S0nGAUxb2zyv1ublqpYr?= =?iso-8859-1?q?XGUqbnHIVur6uqgFhrfQCiddkrwohphfH4TloA5ey2t1Sz8O1brDtaLmQe1L?= =?iso-8859-1?q?w0xEwuNMgw/5KHr21ZeVYd0KFknm43ROfnHVKDyevCn1cyI1yeTJwc+b5VrY?= =?iso-8859-1?q?UQzeQ7yYirSNF9zZZTdxm2q6/ZiaBogqNtMmOYyY5Vruy8MaFcp9Pjh3eq9N?= =?iso-8859-1?q?aCzcMBapmXlmY1ctRZz5YrYkTThWbVfhJqdFZWvshNxhqUd/CRGwp2nHVTK+?= =?iso-8859-1?q?eBvE=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7fd82e46-c221-4ff7-f460-08d9eb2cd813 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Feb 2022 18:00:08.4817 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: nR6P7OcxH3Ms+uUSS9wpHiky5/5XPGfj7C+riLQE1Xt0LxMxgbb8RIFIeFrUU4cNJTLV+4s7ng27vBTm3TvAfJiRfuf+dpNRGjgIea+dxTo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5613 X-Proofpoint-GUID: 9x9RmyYBt--bIgC7LHnu8maOWqKwhB8o X-Proofpoint-ORIG-GUID: 9x9RmyYBt--bIgC7LHnu8maOWqKwhB8o X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_06,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080106 If enabled, host device-tree will be exported to hypfs and can be accessed through /devicetree path. Exported device-tree has the same format, as the device-tree exported to the sysfs by the Linux kernel. This is useful when XEN toolstack needs an access to the host device-tree. Signed-off-by: Oleksii Moisieiev --- xen/arch/arm/Kconfig | 8 + xen/arch/arm/Makefile | 1 + xen/arch/arm/host_dtb_export.c | 307 +++++++++++++++++++++++++++++++++ 3 files changed, 316 insertions(+) create mode 100644 xen/arch/arm/host_dtb_export.c diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index ecfa6822e4..895016b21e 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -33,6 +33,14 @@ config ACPI Advanced Configuration and Power Interface (ACPI) support for Xen is an alternative to device tree on ARM64. +config HOST_DTB_EXPORT + bool "Export host device tree to hypfs if enabled" + depends on ARM && HYPFS && !ACPI + ---help--- + + Export host device-tree to hypfs so toolstack can have an access for the + host device tree from Dom0. If you unsure say N. + config GICV3 bool "GICv3 driver" depends on ARM_64 && !NEW_VGIC diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 07f634508e..0a41f68f8c 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -8,6 +8,7 @@ obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_HAS_VPCI) += vpci.o +obj-$(CONFIG_HOST_DTB_EXPORT) += host_dtb_export.o obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o obj-y += bootfdt.init.o diff --git a/xen/arch/arm/host_dtb_export.c b/xen/arch/arm/host_dtb_export.c new file mode 100644 index 0000000000..794395683c --- /dev/null +++ b/xen/arch/arm/host_dtb_export.c @@ -0,0 +1,307 @@ +/* + * xen/arch/arm/host_dtb_export.c + * + * Export host device-tree to the hypfs so toolstack can access + * host device-tree from Dom0 + * + * Oleksii Moisieiev + * Copyright (C) 2021, EPAM Systems. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +#define HOST_DT_DIR "devicetree" + +static int host_dt_dir_read(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr); +static unsigned int host_dt_dir_getsize(const struct hypfs_entry *entry); + +static const struct hypfs_entry *host_dt_dir_enter( + const struct hypfs_entry *entry); +static void host_dt_dir_exit(const struct hypfs_entry *entry); + +static struct hypfs_entry *host_dt_dir_findentry( + const struct hypfs_entry_dir *dir, const char *name, unsigned int name_len); + +static const struct hypfs_funcs host_dt_dir_funcs = { + .enter = host_dt_dir_enter, + .exit = host_dt_dir_exit, + .read = host_dt_dir_read, + .write = hypfs_write_deny, + .getsize = host_dt_dir_getsize, + .findentry = host_dt_dir_findentry, +}; + +static int host_dt_prop_read(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr); + +static unsigned int host_dt_prop_getsize(const struct hypfs_entry *entry); + +const struct hypfs_funcs host_dt_prop_ro_funcs = { + .enter = host_dt_dir_enter, + .exit = host_dt_dir_exit, + .read = host_dt_prop_read, + .write = hypfs_write_deny, + .getsize = host_dt_prop_getsize, + .findentry = hypfs_leaf_findentry, +}; + +static HYPFS_DIR_INIT_FUNC(dt_dir, "node_template", &host_dt_dir_funcs); + +#define HYPFS_PROPERTY_MAX_SIZE 256 +static HYPFS_VARSIZE_INIT(dt_prop, XEN_HYPFS_TYPE_BLOB, "prop_template", + HYPFS_PROPERTY_MAX_SIZE, &host_dt_prop_ro_funcs); + +static const char *get_name_from_path(const char *path) +{ + const char *name = strrchr(path, '/'); + if ( !name ) + name = path; + else + { + name++; + if ( !*name ) + name--; + } + + return name; +} + +static char *get_root_from_path(const char *path, char *name) +{ + const char *nm = strchr(path, '/'); + if ( !nm ) + nm = path + strlen(path); + else + { + if ( !*nm ) + nm--; + } + + return memcpy(name, path, nm - path); +} + +static int host_dt_dir_read(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr) +{ + int ret = 0; + struct dt_device_node *node; + struct dt_device_node *child; + const struct dt_property *prop; + struct hypfs_dyndir_id *data; + + data = hypfs_get_dyndata(); + if ( !data ) + return -EINVAL; + + node = data->data; + if ( !node ) + return -EINVAL; + + dt_for_each_property_node( node, prop ) + { + ret = hypfs_read_dyndir_entry(&dt_prop.e, prop->name, + strlen(prop->name), + !prop->next && !node->child, + &uaddr); + + if ( ret ) + break; + } + + for ( child = node->child; child != NULL; child = child->sibling ) + { + const char *parsed_name = get_name_from_path(child->full_name); + data->data = child; + + ret = hypfs_read_dyndir_entry(&dt_dir.e, parsed_name, + strlen(parsed_name), + child->sibling == NULL, + &uaddr); + + if ( ret ) + break; + } + + return ret; +} + +static unsigned int host_dt_dir_getsize(const struct hypfs_entry *entry) +{ + struct dt_device_node *node; + struct dt_device_node *child; + struct hypfs_dyndir_id *data; + const struct dt_property *prop; + unsigned int size = 0; + + data = hypfs_get_dyndata(); + if ( !data ) + return -EINVAL; + + node = data->data; + if ( !node ) + return -EINVAL; + + dt_for_each_property_node( node, prop ) + { + size += hypfs_dyndir_entry_size(entry, prop->name); + } + + for ( child = node->child; child != NULL; child = child->sibling ) + { + const char *parsed_name = get_name_from_path(child->full_name); + size += hypfs_dyndir_entry_size(entry, parsed_name); + } + + return size; +} + +static DEFINE_PER_CPU(bool, data_alloc); + +static inline bool data_is_alloc(void) +{ + unsigned int cpu = smp_processor_id(); + return per_cpu(data_alloc, cpu); +} + +static inline void set_data_alloc(void) +{ + unsigned int cpu = smp_processor_id(); + ASSERT(!per_cpu(data_alloc, cpu)); + + this_cpu(data_alloc) = true; +} + +static inline void unset_data_alloc(void) +{ + this_cpu(data_alloc) = false; +} + +static const struct hypfs_entry *host_dt_dir_enter( + const struct hypfs_entry *entry) +{ + struct hypfs_dyndir_id *data; + + if ( !data_is_alloc() ) + { + data = hypfs_alloc_dyndata(struct hypfs_dyndir_id); + if ( !data ) + return ERR_PTR(-ENOMEM); + + set_data_alloc(); + } + + if ( strcmp(entry->name, HOST_DT_DIR) == 0 ) + { + data = hypfs_get_dyndata(); + data->data = dt_host; + } + + return entry; +} + +static void host_dt_dir_exit(const struct hypfs_entry *entry) +{ + if ( !data_is_alloc() ) + return; + + hypfs_free_dyndata(); + unset_data_alloc(); +} + +static struct hypfs_entry *host_dt_dir_findentry( + const struct hypfs_entry_dir *dir, const char *name, unsigned int name_len) +{ + struct dt_device_node *node; + char root_name[HYPFS_DYNDIR_ID_NAMELEN]; + struct dt_device_node *child; + struct hypfs_dyndir_id *data; + struct dt_property *prop; + + data = hypfs_get_dyndata(); + if ( !data ) + return ERR_PTR(-EINVAL); + + node = data->data; + if ( !node ) + return ERR_PTR(-EINVAL); + + memset(root_name, 0, sizeof(root_name)); + get_root_from_path(name, root_name); + + for ( child = node->child; child != NULL; child = child->sibling ) + { + if ( strcmp(get_name_from_path(child->full_name), root_name) == 0 ) + return hypfs_gen_dyndir_entry(&dt_dir.e, + get_name_from_path(child->full_name), child); + } + + dt_for_each_property_node( node, prop ) + { + + if ( dt_property_name_is_equal(prop, root_name) ) + return hypfs_gen_dyndir_entry(&dt_prop.e, prop->name, prop); + } + + return ERR_PTR(-ENOENT); +}; + +static int host_dt_prop_read(const struct hypfs_entry *entry, + XEN_GUEST_HANDLE_PARAM(void) uaddr) +{ + const struct dt_property *prop; + struct hypfs_dyndir_id *data; + + data = hypfs_get_dyndata(); + if ( !data ) + return -EINVAL; + + prop = data->data; + if ( !prop ) + return -EINVAL; + + return copy_to_guest(uaddr, prop->value, prop->length) ? -EFAULT : 0; +} + +static unsigned int host_dt_prop_getsize(const struct hypfs_entry *entry) +{ + const struct hypfs_dyndir_id *data; + const struct dt_property *prop; + + data = hypfs_get_dyndata(); + if ( !data ) + return -EINVAL; + + prop = data->data; + if ( !prop ) + return -EINVAL; + + return prop->length; +} + +static HYPFS_DIR_INIT_FUNC(host_dt_dir, HOST_DT_DIR, &host_dt_dir_funcs); + +static int __init host_dtb_export_init(void) +{ + ASSERT(dt_host && (dt_host->sibling == NULL)); + unset_data_alloc(); + + hypfs_add_dir(&hypfs_root, &host_dt_dir, true); + hypfs_add_dyndir(&hypfs_root, &dt_dir); + return 0; +} +__initcall(host_dtb_export_init); From patchwork Tue Feb 8 18:00:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 12739149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1161EC433EF for ; Tue, 8 Feb 2022 18:00:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268497.462393 (Exim 4.92) (envelope-from ) id 1nHUmv-0007Xz-Uh; Tue, 08 Feb 2022 18:00:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268497.462393; Tue, 08 Feb 2022 18:00:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmv-0007Xg-MN; Tue, 08 Feb 2022 18:00:25 +0000 Received: by outflank-mailman (input) for mailman id 268497; Tue, 08 Feb 2022 18:00:24 +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 1nHUmt-00068L-Uq for xen-devel@lists.xenproject.org; Tue, 08 Feb 2022 18:00:24 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fb07cd74-8908-11ec-8eb8-a37418f5ba1a; Tue, 08 Feb 2022 19:00:21 +0100 (CET) Received: from pps.filterd (m0174678.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 218EgrT8015757; Tue, 8 Feb 2022 18:00:17 GMT Received: from eur02-he1-obe.outbound.protection.outlook.com (mail-he1eur02lp2057.outbound.protection.outlook.com [104.47.5.57]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3e3t5xrs6q-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 18:00:16 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by VE1PR03MB5613.eurprd03.prod.outlook.com (2603:10a6:803:12a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19; Tue, 8 Feb 2022 18:00:09 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0%6]) with mapi id 15.20.4951.019; Tue, 8 Feb 2022 18:00:09 +0000 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: fb07cd74-8908-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mY+RaWVddAkBShMK2W/v2hY4BXTUyA7H5kj+8oORo432vKYFcOFXIA8npCiDdWiKWDXEkkmyEvQTiD+q2DF3rFED0OTA7pQewOKDDy0/kuflsNwMezKsvLhxD9OUwQSwR/nJEgdUDgaB5iMolp4jIWm/VsL9SufaYm91b/kjp3pe8ZgnJTgggHgGO6k2J4ia5DfBqwCnSFHL444BV5Sr/JVT9H6BNVSJ0dalb5pQ2eUwzCofUjKMkFtf0QSOTb/M5q6wgprDYI/hxZcjx0xoEMekKK2bJY89ytjZ2//3uUpg5Z3omI7d+CFayreG1MMuyR72zXFVSUkaVT8t87n3qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FDKbwCjLZ0DanLs0acIscY6UBZ+tUS318cgSdULOaTg=; b=FhC4vSwd/EHlw2WOgLDGBVWKU+o/GodGP5omeA/sR57/LrY4MbJsKNgcgonyzMGdVBa20hgnGe7hHOg4On01ZVpOQlFKVhkpthzI1LpA4SvvEPqnC8ohTWkeYbOSHNRwXI9K6Y1zorSR0waI2TSMBq5iu2IjPNmvr7KAAbQRVkEjRGhvXfTOKQATec6BH+GT8z72KPwWohfhXSj/EH6tA+s+CITgppFH/Dtt5HqKVmXaTaX2ElNKjlYa8bIsGDjYeZHfVOjgkTN/X3SoxLQStmgefmJj6aGyTTY2BMtnbIZqsrzz7FwFV+qU4HfBDhK7xsdsvLOevd2AS8meXKx7ow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FDKbwCjLZ0DanLs0acIscY6UBZ+tUS318cgSdULOaTg=; b=rFaqhDGBTGz4gKZ4MhsIX+kLwWEk+26jQSFZU03NjW34KeTzNt8ztxbuA78xADTTnk2MpcvGi2Rk6RIMR8PJ+us8NAtQpYTz7LbqCK0M7XZI5u+wtJJ08GxSaBX4F9F7k2i09jsqrmIBy3pxph1EbC1Z7j539/u25OpzhLjWQgYNhvNfwMsbM2eC8CPFn9vDqeGYTBVTpQZGg94fOvaI3hNIHJndSphh/iY27ePZ93gg8yMUGk+/fv8X8bgPhFnNetf1EfBODF1Ta0V38n/clzxEALZN9zrds1U42aSVN3ZK1mXhV2yMTfHMFSNRh2M+tumXgwBWtlnmW5qaMgX1mA== From: Oleksii Moisieiev To: "xen-devel@lists.xenproject.org" CC: Oleksii Moisieiev , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Volodymyr Babchuk , Bertrand Marquis Subject: [RFC v2 4/8] xen/arm: add generic SCI mediator framework Thread-Topic: [RFC v2 4/8] xen/arm: add generic SCI mediator framework Thread-Index: AQHYHRW2uVlYW22dYk+LMpDDmAXomw== Date: Tue, 8 Feb 2022 18:00:09 +0000 Message-ID: <83ecc9060352952bad547ad42c335ee979bf53c3.1644341635.git.oleksii_moisieiev@epam.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1001ae67-d63f-437f-d2b7-08d9eb2cd8ba x-ms-traffictypediagnostic: VE1PR03MB5613:EE_ x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GySFz62y0pVP20BKAldSaWT1FG+Kvk6Yc3QdhUZf7v6cVXTnKJ2cXMq1Nwj7/6Y2XPRorMHhEvDAE1m3iLRmnewtczBxD0vmRtgCZP34hSUm6jXvNLL9SOQQEdbc0mhCfnDHzclXkwnc+WxGuHbtetkZJmqoRTEaqGm9rBGNE2wP1KWgq91AOHbDHocX46rgtSvdyLjbDNX2+REyicV7gKD9q0OEMwyUxQduvNIvrOA2mzGqlRAhCoFU6XTXyvrjXq+oZUQUX70Vmtgf6b+QohRJ6o8XslBWcuehz8NpQeP/1udZ2VXlbKycn1r73bN+NPboJH7UVWp9Zb45nVtJD2ipfa0agtwkwv40R2ejDXZBOxGD6WizbXzOiOn5e+RwW40BixkcbjKYXBRcNj/VXEj1QCXzo9US07CgYvuRHewkNqvlNTGQLmte6nrjbm8hDt6tVZaHzn/W/+Bte89wG2YajlqvZmokrDvEg6NvYbTsvsptRuQKNm1KXUq/Mt6SWbYJFKj2EM/HoqHtiDRDDhBP/IEROlgFiUMEamf9xUoXu96KbO94FTL2BMhgEITTNOw7irpYrP8wpY7PEbZQLuMi0X4DWfcYQuOj8Fe/zePYdxJ849qnvarN/x/Llm9wTYldqH16hz72v0jjB880oXxONhDnjQFtFT1ruDbhSAf9fLGRPLi19Pm+MqywZDEklb4srA6F7GRsUz2OI2hu/OS5T7C3GC2cwk0KdcLq7eOIR8i9jcPRe+levxRtU011uZ6DrLisoEc2e8b3zeiFZa55jsMOxD2Jr2e4fOy4Tqs= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38070700005)(71200400001)(6486002)(508600001)(66476007)(64756008)(86362001)(66556008)(316002)(122000001)(6916009)(6506007)(2616005)(5660300002)(6512007)(4326008)(83380400001)(54906003)(30864003)(2906002)(26005)(186003)(8676002)(76116006)(38100700002)(66446008)(66946007)(8936002)(36756003)(91956017)(41533002)(2004002)(21314003);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?L2WYFMsGfGar/YWPAkdWTw/?= =?iso-8859-1?q?gWc9uUoGI7y+Fs2AeVK3Df9Jc2pHx3MKwSraFIfwrjW/BJUTK+MNMDWcchQ2?= =?iso-8859-1?q?xP324ATL3+qazqPYLa3W/swfHJ6R3APlNLMsRfRtvWme3uzWOCl5ULXVPMMD?= =?iso-8859-1?q?ntaf4MYv3NdLftHJoWzEqfFLIB/KOZXD5jKkf5QEXzewOgWvp8X+I44gcgNn?= =?iso-8859-1?q?Aa7tAAlc47Y+FXZb0xQ/3w34QAj6C4/R9F4gDPPr7a8L/w5pFvrDm0saMI0J?= =?iso-8859-1?q?BdQaZkWA+e9CKJysYOaj7SSLXslUvmV6hlHahK8zIsG2o+gzVy9zUDn38hIE?= =?iso-8859-1?q?Ze23cFU5Mg0SFL2jbgKVYtF6t6payt0NL3rUjrotra+eNiGR7qK5gJJI8eqg?= =?iso-8859-1?q?20bsQJMgQGuYEN16fdW9Pan404UGUeYeShUyq0tz3ekHfpcongyoPUrlbhnj?= =?iso-8859-1?q?2n/hyjxtl7C4aCr5nnuU4o9f90258Bo9I7C0Apgkff+NeNBdNreRglEPCIxm?= =?iso-8859-1?q?JB+fZsqa97rbzTSPt2VdoqqJY3ln1vnenivgeSpbr3QxgMRsSEafTHYUbynf?= =?iso-8859-1?q?EajVuO0FGHVSNzc+wGLMtGJmy6RRb3Rmo/nTf1FsWo7JL4JqM/AS3Tk/o6pO?= =?iso-8859-1?q?YmlTLc3ColwFts4By5k5tQyS599F4Ogs5oXbxgAyMH5ws92Qw7bhBHgTA0V1?= =?iso-8859-1?q?i/Xz/bVMam2SJwwyAJnoSWiQcztjNjGU9OzZIaKo+z/24rFHfF183T8e27Ee?= =?iso-8859-1?q?fKmTPnI9K2HgwqvQ2mlx/lm7JJMnz3rA0yNtLxCw+Xqso5mtzgyPkZw1Y0Xf?= =?iso-8859-1?q?5ZidURayHIzKUOpjkYxxESLirCcziv08K/eLBc50Ak8tLRgB4cCeV4JuYIVH?= =?iso-8859-1?q?i067q3cZJvikyrANj2HGVqtoQtmWAe2QFhy698kh/SKxBOhHSkA9YJ+DtRLM?= =?iso-8859-1?q?J0pmM+PIUldOIdawwysCZtFogeaaqZx7DO/hJ+Jt+uiQc4gi6Ox8QE93oBKm?= =?iso-8859-1?q?2OyBXY7ls/iq9dbVNjZgFkU1m3R/P0E+hEWI0oNN3FdJgroCXGelxGvTLm6X?= =?iso-8859-1?q?XBJ+/L1r8ku2WppU86tQqbkmkN0w4DkrO5nrOLLxRM5un5/fR9EtJvQLkg0p?= =?iso-8859-1?q?JS9YtpHVI2AzEhyvBkjX8QWqAnbAxXc6bPNTFUEEOpgPZkjaOcNG35FJ6qbM?= =?iso-8859-1?q?Vq4Eon+PoKLppMrxNUsOZ6de/ChvEJ7lH+WG9NQkfJ8Hg+6IsYKuaUgiehs7?= =?iso-8859-1?q?NP8djwNbbdSzr2qWc9s2B/zsW7AYu8Zb6hKsAFR1lkdmY5VsyQdvS9BjW01H?= =?iso-8859-1?q?5kNU31yiTX+FW4ojDtBsykDqmt+rZPrAW0oC8aTL/mGwKkVSva8oYkvsPMX5?= =?iso-8859-1?q?t95nAkKEDp+1/rVV2xfvyU8HCIVKjs5YaW3ZByvk4qntJ8tKuva+TDUw3Z8M?= =?iso-8859-1?q?uhIGjkJBqfTflIItoKo3g8xKCcSm+xoIk6wzWHupP678loE0eDi6aMZXkvJR?= =?iso-8859-1?q?qPw5zhePlt2vmos0Q6Jr7k95SyYOxIaNizIB6udmNl55UzF6BtRWP5uzjnlB?= =?iso-8859-1?q?1mAqoN4rj02ktrjrtICbJtPJcV/2ER+QLzQv6Vdlium8luUn18PFV5M4LcfT?= =?iso-8859-1?q?v5XMJ8Cqak41bVaFaadoBH5/tQSmNnauT+8E32YKFDnZeUp9QIMkb0WbIt9y?= =?iso-8859-1?q?fKIs+fmcLapPmerNe/RU65F1valgnih+OSol4YjAHe29gtmVKWhNhwfPwo2g?= =?iso-8859-1?q?/cg8=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1001ae67-d63f-437f-d2b7-08d9eb2cd8ba X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Feb 2022 18:00:09.5908 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Fvz0XaV4ZZ14C1yQBR08IJaqI0CoZ4i2HYY2Zt52ID3ARkWDmS8hUoXsdyY5kj6QjLE/F7n0V0wegxhE6BwhO7QQiLQlxC9sSYElKgUGOtg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5613 X-Proofpoint-GUID: cA5HE8dSeDrbPlw6Q8YLP4RcCfN2Sp5M X-Proofpoint-ORIG-GUID: cA5HE8dSeDrbPlw6Q8YLP4RcCfN2Sp5M X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_06,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080106 This patch adds the basic framework for SCI mediator. SCI is System Control Interface, which is designed to redirect requests from the Domains to Firmware. This will allow the devices, passed-through to the different Domains, to access to the System Controls (such as clocks/resets etc) by sending requests to the firmware. Xen mediates requests between the Domains and the Firmware, also it is responsible for permission handling during Domain crateion. SCI mediator register itself with REGISTER_SCI_MEDIATOR() macro. At run-time, during initialization, framework calls probe for the first matching device in the device-tree. When no device-tree is present - the first registered mediator should be probed. Signed-off-by: Oleksii Moisieiev --- MAINTAINERS | 6 ++ xen/arch/arm/Kconfig | 9 ++ xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 22 +++++ xen/arch/arm/domain_build.c | 11 +++ xen/arch/arm/sci/Makefile | 2 + xen/arch/arm/sci/sci.c | 152 +++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 1 + xen/arch/arm/vsmc.c | 5 +- xen/arch/arm/xen.lds.S | 7 ++ xen/include/asm-arm/domain.h | 4 + xen/include/asm-arm/sci/sci.h | 162 ++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 15 ++++ 13 files changed, 396 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/sci/Makefile create mode 100644 xen/arch/arm/sci/sci.c create mode 100644 xen/include/asm-arm/sci/sci.h diff --git a/MAINTAINERS b/MAINTAINERS index e43dc0edce..5f96ea35ba 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -512,6 +512,12 @@ S: Supported F: xen/arch/arm/tee/ F: xen/include/asm-arm/tee +SCI MEDIATORS +M: Oleksii Moisieiev +S: Supported +F: xen/arch/arm/sci +F: xen/include/asm-arm/sci + TOOLSTACK M: Wei Liu S: Supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 895016b21e..ab07833582 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -114,6 +114,15 @@ config TEE source "arch/arm/tee/Kconfig" +config ARM_SCI + bool "Enable ARM_SCI mediators support" + depends on ARM + default n + help + This option enables generic ARM_SCI (System Control Interface) mediators + support. It allows guests to control system resourcess via one of + ARM_SCI mediators implemented in XEN. + endmenu menu "ARM errata workaround via the alternative framework" diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 0a41f68f8c..f071d912aa 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -8,6 +8,7 @@ obj-y += platforms/ endif obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_HAS_VPCI) += vpci.o +obj-$(CONFIG_ARM_SCI) += sci/ obj-$(CONFIG_HOST_DTB_EXPORT) += host_dtb_export.o obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 96e1b23550..607ea8c3a8 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -688,6 +689,13 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) return -EINVAL; } + if ( config->arch.arm_sci_type != XEN_DOMCTL_CONFIG_ARM_SCI_NONE && + config->arch.arm_sci_type != sci_get_type() ) + { + dprintk(XENLOG_INFO, "Unsupported ARM_SCI type\n"); + return -EINVAL; + } + return 0; } @@ -764,6 +772,13 @@ int arch_domain_create(struct domain *d, /* At this stage vgic_reserve_virq should never fail */ if ( !vgic_reserve_virq(d, GUEST_EVTCHN_PPI) ) BUG(); + + if ( config->arch.arm_sci_type != XEN_DOMCTL_CONFIG_ARM_SCI_NONE ) + { + if ( (rc = sci_domain_init(d, config->arch.arm_sci_type, + &config->arch)) != 0) + goto fail; + } } /* @@ -796,6 +811,7 @@ void arch_domain_destroy(struct domain *d) domain_vgic_free(d); domain_vuart_free(d); free_xenheap_page(d->shared_info); + sci_domain_destroy(d); #ifdef CONFIG_ACPI free_xenheap_pages(d->arch.efi_acpi_table, get_order_from_bytes(d->arch.efi_acpi_len)); @@ -996,6 +1012,7 @@ enum { PROG_xen, PROG_page, PROG_mapping, + PROG_sci, PROG_done, }; @@ -1056,6 +1073,11 @@ int domain_relinquish_resources(struct domain *d) if ( ret ) return ret; + PROGRESS(sci): + ret = sci_relinquish_resources(d); + if ( ret ) + return ret; + PROGRESS(done): break; diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d02bacbcd1..05afd3e8e7 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -1894,6 +1895,10 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev, return res; } } + + res = sci_add_dt_device(d, dev); + if ( res < 0 ) + return res; } res = handle_device_interrupts(d, dev, need_mapping); @@ -3075,6 +3080,10 @@ static int __init construct_dom0(struct domain *d) if ( rc < 0 ) return rc; + rc = sci_domain_init(d, sci_get_type(), NULL); + if ( rc < 0 ) + return rc; + if ( acpi_disabled ) rc = prepare_dtb_hwdom(d, &kinfo); else @@ -3109,6 +3118,8 @@ void __init create_dom0(void) dom0_cfg.arch.tee_type = tee_get_type(); dom0_cfg.max_vcpus = dom0_max_vcpus(); + dom0_cfg.arch.arm_sci_type = sci_get_type(); + if ( iommu_enabled ) dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; diff --git a/xen/arch/arm/sci/Makefile b/xen/arch/arm/sci/Makefile new file mode 100644 index 0000000000..67f2611872 --- /dev/null +++ b/xen/arch/arm/sci/Makefile @@ -0,0 +1,2 @@ +obj-y += sci.o +obj-$(CONFIG_SCMI_SMC) += scmi_smc.o diff --git a/xen/arch/arm/sci/sci.c b/xen/arch/arm/sci/sci.c new file mode 100644 index 0000000000..05c948a071 --- /dev/null +++ b/xen/arch/arm/sci/sci.c @@ -0,0 +1,152 @@ +/* + * xen/arch/arm/sci/sci.c + * + * Generic part of SCI mediator driver + * + * Oleksii Moisieiev + * Copyright (C) 2021, EPAM Systems. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +#include + +extern const struct sci_mediator_desc _sscimediator[], _escimediator[]; +static const struct sci_mediator_desc __read_mostly *cur_mediator; + +bool sci_handle_call(struct domain *d, void *args) +{ + if ( unlikely(!cur_mediator) ) + return false; + + return cur_mediator->ops->handle_call(d, args); +} + +int sci_domain_init(struct domain *d, uint16_t sci_type, + struct xen_arch_domainconfig *config) +{ + if ( sci_type == XEN_DOMCTL_CONFIG_ARM_SCI_NONE ) + return 0; + + if ( !cur_mediator ) + return -ENODEV; + + if ( cur_mediator->sci_type != sci_type ) + return -EINVAL; + + return cur_mediator->ops->domain_init(d, config); +} + +void sci_domain_destroy(struct domain *d) +{ + if ( !cur_mediator ) + return; + + cur_mediator->ops->domain_destroy(d); +} + +int sci_relinquish_resources(struct domain *d) +{ + if ( !cur_mediator ) + return 0; + + return cur_mediator->ops->relinquish_resources(d); +} + + +int sci_add_dt_device(struct domain *d, struct dt_device_node *dev) +{ + if ( !cur_mediator ) + return 0; + + return cur_mediator->ops->add_dt_device(d, dev); +} + +uint16_t sci_get_type(void) +{ + if ( !cur_mediator ) + return XEN_DOMCTL_CONFIG_ARM_SCI_NONE; + + return cur_mediator->sci_type; +} + +int sci_do_domctl( + struct xen_domctl *domctl, struct domain *d, + XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) +{ + int rc = -EINVAL; + struct dt_device_node *dev; + + switch ( domctl->cmd ) + { + case XEN_DOMCTL_assign_device: + if ( domctl->u.assign_device.dev != XEN_DOMCTL_DEV_DT ) + break; + + rc = dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path, + domctl->u.assign_device.u.dt.size, + &dev); + if ( rc ) + return rc; + + rc = sci_add_dt_device(d, dev); + + break; + default: + rc = -ENOSYS; + break; + } + + return rc; +} + +static int __init sci_init(void) +{ + const struct sci_mediator_desc *desc; + struct dt_device_node *dt = NULL; + + + for ( desc = _sscimediator; desc != _escimediator; desc++ ) + { + if ( acpi_disabled ) + { + dt = dt_find_matching_node(dt_host, desc->dt_match); + if ( !dt ) + continue; + } + + if ( desc->ops->probe(dt) ) + { + printk(XENLOG_INFO "Using SCI mediator for %s\n", desc->name); + cur_mediator = desc; + return 0; + } + } + + return 0; +} + +__initcall(sci_init); + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index d5d0792ed4..201de01411 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include diff --git a/xen/arch/arm/vsmc.c b/xen/arch/arm/vsmc.c index a36db15fff..c68482fbd8 100644 --- a/xen/arch/arm/vsmc.c +++ b/xen/arch/arm/vsmc.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -275,7 +276,9 @@ static bool vsmccc_handle_call(struct cpu_user_regs *regs) handled = handle_sssc(regs); break; case ARM_SMCCC_OWNER_SIP: - handled = platform_smc(regs); + handled = sci_handle_call(current->domain, regs); + if ( !handled ) + handled = platform_smc(regs); break; case ARM_SMCCC_OWNER_TRUSTED_APP ... ARM_SMCCC_OWNER_TRUSTED_APP_END: case ARM_SMCCC_OWNER_TRUSTED_OS ... ARM_SMCCC_OWNER_TRUSTED_OS_END: diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 08016948ab..3683f4821f 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -142,6 +142,13 @@ SECTIONS _eteemediator = .; } :text + . = ALIGN(8); + .scimediator.info : { + _sscimediator = .; + *(.scimediator.info) + _escimediator = .; + } :text + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : { diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 9b3647587a..11c8db8db1 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -89,6 +89,10 @@ struct arch_domain #ifdef CONFIG_TEE void *tee; #endif + +#ifdef CONFIG_ARM_SCI + void *sci; +#endif } __cacheline_aligned; struct arch_vcpu diff --git a/xen/include/asm-arm/sci/sci.h b/xen/include/asm-arm/sci/sci.h new file mode 100644 index 0000000000..075e11bc16 --- /dev/null +++ b/xen/include/asm-arm/sci/sci.h @@ -0,0 +1,162 @@ +/* + * xen/include/asm-arm/sci/sci.h + * + * Generic part of the SCI (System Control Interface) subsystem. + * + * Oleksii Moisieiev + * Copyright (C) 2021, EPAM Systems. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __ASM_ARM_SCI_H +#define __ASM_ARM_SCI_H + +#include +#include +#include +#include + +#ifdef CONFIG_ARM_SCI + +struct sci_mediator_ops { + + /* + * Probe for SCI. Should return true if SCI found and + * mediator is initialized. + */ + bool (*probe)(struct dt_device_node *scmi_node); + + /* + * Called during domain construction if toolstack requests to enable + * SCI support so mediator can inform SCP-firmware about new + * guest and create own structures for the new domain. + */ + int (*domain_init)(struct domain *d, struct xen_arch_domainconfig *config); + + /* + * Called during domain destruction, releases all resources, that + * were allocated by the mediator. + */ + void (*domain_destroy)(struct domain *d); + + /* + * Called during parsing partial device-sci for the domain. + * Passing device_node so mediator could process the device and + * mark the device as related to the domain if needed. + */ + int (*add_dt_device)(struct domain *d, struct dt_device_node *dev); + + /* + * Called during domain destruction to relinquish resources used + * by mediator itself. This function can return -ERESTART to indicate + * that it does not finished work and should be called again. + */ + int (*relinquish_resources)(struct domain *d); + + /* Handle call for current domain */ + bool (*handle_call)(struct domain *d, void *regs); +}; + +struct sci_mediator_desc { + /* Printable name of the SCI. */ + const char *name; + + /* Mediator callbacks as described above. */ + const struct sci_mediator_ops *ops; + + /* + * ID of SCI. Corresponds to xen_arch_domainconfig.sci_type. + * Should be one of XEN_DOMCTL_CONFIG_ARM_SCI_xxx + */ + uint16_t sci_type; + + /* Match structure to init mediator */ + const struct dt_device_match *dt_match; + +}; + +int sci_domain_init(struct domain *d, uint16_t sci_type, + struct xen_arch_domainconfig *config); +void sci_domain_destroy(struct domain *d); +int sci_add_dt_device(struct domain *d, struct dt_device_node *dev); +int sci_relinquish_resources(struct domain *d); +bool sci_handle_call(struct domain *d, void *args); +uint16_t sci_get_type(void); +int sci_do_domctl( + struct xen_domctl *domctl, struct domain *d, + XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl); + +#define REGISTER_SCI_MEDIATOR(_name, _namestr, _type, _match, _ops) \ +static const struct sci_mediator_desc __sci_desc_##_name __used \ +__section(".scimediator.info") = { \ + .name = _namestr, \ + .ops = _ops, \ + .sci_type = _type, \ + .dt_match = _match \ +} + +#else + +static inline int sci_domain_init(struct domain *d, uint16_t sci_type, + struct xen_arch_domainconfig *config) +{ + if ( likely(sci_type == XEN_DOMCTL_CONFIG_ARM_SCI_NONE) ) + return 0; + + return -ENODEV; +} + +static inline void sci_domain_destroy(struct domain *d) +{ +} + +static inline int sci_add_dt_device(struct domain *d, + struct dt_device_node *dev) +{ + return 0; +} + +static inline int sci_relinquish_resources(struct domain *d) +{ + return 0; +} + +static inline bool sci_handle_call(struct domain *d, void *args) +{ + return false; +} + +static inline uint16_t sci_get_type(void) +{ + return XEN_DOMCTL_CONFIG_ARM_SCI_NONE; +} + +static inline int sci_do_domctl( + struct xen_domctl *domctl, struct domain *d, + XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) +{ + return -ENOSYS; +} + + +#endif /* CONFIG_ARM_SCI */ + +#endif /* __ASM_ARM_SCI_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 94b31511dd..a6131ab1fd 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -314,12 +314,17 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t); #define XEN_DOMCTL_CONFIG_TEE_NONE 0 #define XEN_DOMCTL_CONFIG_TEE_OPTEE 1 +#define XEN_DOMCTL_CONFIG_ARM_SCI_NONE 0 +#define XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC 1 + struct xen_arch_domainconfig { /* IN/OUT */ uint8_t gic_version; /* IN */ uint16_t tee_type; /* IN */ + uint16_t arm_sci_type; + /* IN */ uint32_t nr_spis; /* * OUT @@ -335,6 +340,12 @@ struct xen_arch_domainconfig { * */ uint32_t clock_frequency; + + /* Sets shared address to sw domains. + * This information is needed to set correct channel in Domain partial + * device-tree + */ + uint64_t arm_sci_agent_paddr; }; #endif /* __XEN__ || __XEN_TOOLS__ */ @@ -429,6 +440,10 @@ typedef uint64_t xen_callback_t; #define GUEST_ACPI_BASE xen_mk_ullong(0x20000000) #define GUEST_ACPI_SIZE xen_mk_ullong(0x02000000) +/* SCMI shared memory address */ +#define GUEST_SCI_SHMEM_BASE xen_mk_ullong(0x05ff0000) +#define GUEST_SCI_SHMEM_SIZE xen_mk_ullong(0x01000) + /* PL011 mappings */ #define GUEST_PL011_BASE xen_mk_ullong(0x22000000) #define GUEST_PL011_SIZE xen_mk_ullong(0x00001000) From patchwork Tue Feb 8 18:00:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 12739150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7EFC2C4332F for ; Tue, 8 Feb 2022 18:00:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268498.462409 (Exim 4.92) (envelope-from ) id 1nHUmy-000873-Gj; Tue, 08 Feb 2022 18:00:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268498.462409; Tue, 08 Feb 2022 18:00:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmy-00086h-CE; Tue, 08 Feb 2022 18:00:28 +0000 Received: by outflank-mailman (input) for mailman id 268498; Tue, 08 Feb 2022 18:00:25 +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 1nHUmv-00068L-Ec for xen-devel@lists.xenproject.org; Tue, 08 Feb 2022 18:00:25 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fc1d3e92-8908-11ec-8eb8-a37418f5ba1a; Tue, 08 Feb 2022 19:00:23 +0100 (CET) Received: from pps.filterd (m0174678.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 218EgrTB015757; Tue, 8 Feb 2022 18:00:19 GMT Received: from eur02-he1-obe.outbound.protection.outlook.com (mail-he1eur02lp2057.outbound.protection.outlook.com [104.47.5.57]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3e3t5xrs6q-10 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 18:00:19 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by VE1PR03MB5613.eurprd03.prod.outlook.com (2603:10a6:803:12a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19; Tue, 8 Feb 2022 18:00:11 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0%6]) with mapi id 15.20.4951.019; Tue, 8 Feb 2022 18:00:11 +0000 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: fc1d3e92-8908-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cfCuyyHlgadn8j+UYBWok7zac+2TzkmJ2j4bLiiwMg/1466/pTjVETa0HtAMQgCX6cP9eE38ZogXqstamqH9eMUEjNkVPPyYXYdT1ssz2XUI7SStubRZ6gK6dHtCLNTow3okq52G/65e7l5Nl1pU6kl5gRnNJO7zNoSn5POOb9NSgYuvrFzqTpQ4Hp5WJURa1yhZr7BlfL5IEGlldsB0UzjeuNO8SGZ79S1tvBEhC3dBFW/sGy8rMQVfSui47Y/t3vPrz3cpYqIDPOMaJeqpWoUFIQm3aJmeNi3GuBlNPp8vduMDNWNioSN8rf8An7t/+ad4+URTw87Sx+FsoztLjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lwBesdAFpbbKcuHszwtd+zJh3/6ZoEfXGDzAO3r/9m0=; b=c9UB4kZlMfSoZTWEqbYQtbmDVnhLxbrEoh7pFvdu3KrQVuIUpifU4fvwgvA4PCOACWI4/E9rJ4YbyYP+Sav2geTt0wo8lwiLdm7s0PWb/XpzM/d3hE1EWlJnl2ky+fTyBpLUKq1+SYUuvpYBsInuxWahFpzdB1CptNIAQAtN9f7m6ZemBaRdL4jVDKxc/sF86xBIYx/npPnQ3/5WJ1RJmCC1LircLrRxBVTDcjb+SrY4dle68TCnGWjNrz4/SEgpzXVGKuEj8kaipWb5uaRFKY3XoHG6CyhaxcThdQiyWw46XcHA2q8A44ccnA03U4eBXcgd3JkbeLAlxBHahS1Wlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lwBesdAFpbbKcuHszwtd+zJh3/6ZoEfXGDzAO3r/9m0=; b=TpPGHIgG0FILxJtDzG9X/2roEE4dC+yowbSQLihWnwBIa58Vxaox+kKNBXECiiMi0+zHo5/WCHAH7LmHan1uV3rCG7RvJU3XYUlHhQE7Bi1+pMYwFr7BUPrl2a5mCdnjSdswDBqQPBeYqyRa50FA88d88YBTRNk/WFIBXJmLvEnRXNdde0BnLv1UHhZsNTF7Hi5KHc+Q56U6DNxrz3maZGwFEb8hROHs24qqDClriSNR/pYX8V6omfFJWmUGhX0ej0gfamIirroEorjHMu/AOP6/kBpbeqNMnjxPahtiSwElORDQZZWsONJUbyj878Rek0JbTKiungZgMMxVeDWzPA== From: Oleksii Moisieiev To: "xen-devel@lists.xenproject.org" CC: Oleksii Moisieiev , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis Subject: [RFC v2 5/8] xen/arm: introduce SCMI-SMC mediator driver Thread-Topic: [RFC v2 5/8] xen/arm: introduce SCMI-SMC mediator driver Thread-Index: AQHYHRW24Dmb0qV8ZkqAv39Pf6/nVQ== Date: Tue, 8 Feb 2022 18:00:10 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 51fb966e-0e48-4ba5-d203-08d9eb2cd9cc x-ms-traffictypediagnostic: VE1PR03MB5613:EE_ x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3383; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: UIoCAc8+AFzUwByPeHaDyknesucUZr0veB6PMzgQPBSlzEC/jxCZtvOTDmZgLQS9/plIDRB8EgieFRTqpmk/Cb3hQSllfDvAa0oUTr9XWq7o63zOHA/FUwNjtm7MZrkcOMFumx7go/DPaF8VydGHITziojEhKtzmYPUDPaeTP4n/jXiLglRvATiVs2oxh7ChV1ZT+DYn3S8MA9Iq2gIXNqgaBQeF7A0S8w45Kyi06KMmnATsIT/5zAFihScY7mFTZuQ5iABLKr1NL/kFquWAMGPPTOHR6L4XaBZ+5qJed+c/onnuukx3vtk9xS623MRihgXecUjZgePD9RBq7HY9CGPby3nOoMa9IU35pMDoHVEL5R+bNwLI6bLlpZXfXjDF1CoqFJ3cpJLDhhooHaNry5vdQUwh/cDwZEFAQxHdO6SxMteaa2q11+eslAD47pZ2Ev005FLn159csA1mybXCanmX7OhRdMFfUTUkBZcaGeqod7snfxC+q8Q3Tm/dn+7kK3r/om10s00OIr05elF10KIKae1xafdg8qtMMJD05X34oPzNa/jlssN5HI0Zq9kIe3qMO8nHLdSCHF/xsdgQa3B2fbUTq0zFieEh1I+HNZWzEx07lQrwveRyqFY6z8UQWsUkX1XsMFPcSIF9tYMR7C6ijWv7KgoO8NBpN64F101YR0CD+4Owxt7LpmYwJwzUCOePc+qpzFz+0/JZonijGrJKIQN4FFgrvKtjCT13p+Q= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38070700005)(71200400001)(6486002)(508600001)(66476007)(64756008)(86362001)(66556008)(316002)(122000001)(6916009)(6506007)(2616005)(5660300002)(6512007)(4326008)(83380400001)(54906003)(30864003)(2906002)(26005)(186003)(8676002)(76116006)(38100700002)(66446008)(66946007)(8936002)(36756003)(91956017)(2004002)(579004)(559001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?7DKeJTm3R0sBtYj9VngbEwb?= =?iso-8859-1?q?gcb5SIqliGCV12ylc/tO668jfbZOrRSzw+E1Z/neW3FLRW5d+c910kMbSJX4?= =?iso-8859-1?q?+uLPOWWcytJ5LdYCihdf1/zkEaNqzOJZzcfUJGlr0j4+AigdBafZQkytDsDL?= =?iso-8859-1?q?qVUW85HYqEpKO4muG50nlxedLxe8al5rMcJBEvFyS1/jgINlNpjMVgjForVF?= =?iso-8859-1?q?pjCzNtuUr7iT3NVGSdluu+GS5E+GMs/oWSdc6wAl+N0zqkg68GmCzwI9wdG+?= =?iso-8859-1?q?cpcnZaLNDh+0LJC3bdHnIN3KGDicXkM7eZPNqAGU8sIRZVaknfDt9NY/zpop?= =?iso-8859-1?q?RYzDSvAvPeEPgjy0XuQxef0ZZG/Zs6tbr3zCk7tqv/1bnbkjxeNrajadymc0?= =?iso-8859-1?q?GYu+qk0/KOERXj9G6LVWT2vFlqJOqYlQUoKC6u9Qjj89sz9rOGdbdZz8H3N3?= =?iso-8859-1?q?90p6J+awqd1zOGxtDJ8MeqAtsZZIpSxeOX/QNoxxvUX6b2V+tm6MeQiEUAjX?= =?iso-8859-1?q?G+aoy0tKUKZdvn/yygtIyd6wk6texgJJ+OKFjQTEbFA3ANG6/QwJgToEhbHm?= =?iso-8859-1?q?+ogEUuruOpiSRRGRs0Njnco3DoEA/JJSFt1tr7TBgtcx+nAODiEbAGhHVMqU?= =?iso-8859-1?q?vzuMfvITa2GzxBSvOo5PxFSIFS87jBCbQnjAm3oJWibkfGnrgH/7UfqSOUU6?= =?iso-8859-1?q?gXYV5SDkLDBDqh9gyj9JiOnFi5vRQ/m/A649vKCaBx3NLFPIBvqSm7wMhhE9?= =?iso-8859-1?q?mMc2z10pXNB808No95b3MCIrUqVZ/h8EMU0X26XyvBFipfNuDlgXkR9YakfW?= =?iso-8859-1?q?6C+izOs0CA8cjx6i75n95CAfOv4uO0zy4lkYsG/f8RQr0nEub+87JMgFvJQ2?= =?iso-8859-1?q?ViV1e8qJgYMO8hv0FNkazdMPfGG5tfJqlWbKeMCLJ+zY4OvBm4mFJauU/wjn?= =?iso-8859-1?q?5PDxhA2EyMyACgtDkC724wE+zDWglZwiBN19h4xY70yP4KZtpjD/bn3nhbVe?= =?iso-8859-1?q?mnrVTMaK/ib7IUkGUjefqUEpO9cOL7uZc7AGr0ZZ5jr2TqB1ebrvsRat/HLA?= =?iso-8859-1?q?BT3Edh0d8cyQBm5LjqP0DJj14VTGNGW0LKpLEUhe7JicSJ3nmPnCdsMv4T7p?= =?iso-8859-1?q?+5ThbvWuCje220ZCNvGGkNgjBznAkl+nYhXnzMfSEonlra53xWJFKb1tagKH?= =?iso-8859-1?q?K2pL1hJnJN9ZHDMi4cgy8jJVZeLrUZI+x37IYWo3jRMqwNmJw7Rw/4mswWub?= =?iso-8859-1?q?hIkf1v9i/dV/PY4s2f+rr26o0GSaA/cVX+3AIP4VAoSSMGIvscR4hODArtzf?= =?iso-8859-1?q?8fl4A3gMJ3XP67dwkVpPMyJGlUfp1LHE8NJcitE3kgRLEp/vsX4tilCyolk/?= =?iso-8859-1?q?h0mbfdO3LfKrpIA7dMLL49FF8Zq7ioFYPvc9giHMN4UehdWNUXuDIsg9vhFj?= =?iso-8859-1?q?+aA9yPCrBMFkcjNvUpBqVrW5BXeJVOpyPOLr/jSWE7u3iJJ3OV5jK6ulnyG7?= =?iso-8859-1?q?s9+iZkpuf913wckfhoPMIM0umtGUTMBg6jqeHez4Kcs5Hkx0gzCWDg0VxWRk?= =?iso-8859-1?q?gT0LMZbso0oFT3XBBHPkSAsQIEMcMt0rg5nkz7HYJOIwIKBcuJe0ZVM+qpw8?= =?iso-8859-1?q?VNpquKMZUbLupwui7rIZiZnmFZR/i9VaEsNCVZ9cVyJ/cVyNvwjxxbREyVL0?= =?iso-8859-1?q?uMCuEIU/9fj6udtcprz7VEX8usMovdyOfkY5/vVtoQ+yK6uQMTvEHpECIztp?= =?iso-8859-1?q?iMTM=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51fb966e-0e48-4ba5-d203-08d9eb2cd9cc X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Feb 2022 18:00:10.4983 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: yGu9sE7NDwwHGwOdYtqFBcUWXZU6xbwMnEwcDmw6QdQtZf+MQmFrAVyteEg6ZK7w8OPd9EycTMTHfJ3GO25CjPWelkClig20eXRgIZOyTm4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5613 X-Proofpoint-GUID: Xjku0kQnLWwAjadQoLtDOOfoMLBUmhBS X-Proofpoint-ORIG-GUID: Xjku0kQnLWwAjadQoLtDOOfoMLBUmhBS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_06,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080106 This is the implementation of SCI interface, called SCMI-SMC driver, which works as the mediator between XEN Domains and Firmware (SCP, ATF etc). This allows devices from the Domains to work with clocks, resets and power-domains without access to CPG. Originally, cpg should be passed to the domain so it can work with power-domains/clocks/resets etc. Considering that cpg can't be split between the Domains, we get the limitation that the devices, which are using power-domains/clocks/resets etc, couldn't be split between the domains. The solution is to move the power-domain/clock/resets etc to the Firmware (such as SCP firmware or ATF) and provide interface for the Domains. XEN should have an entity, caled SCI-Mediator, which is responsible for messages redirection between Domains and Firmware and for permission handling. The following features are implemented: - request SCMI channels from ATF and pass channels to Domains; - set device permissions for Domains based on the Domain partial device-tree. Devices with permissions are able to work with clocks, resets and power-domains via SCMI; - redirect scmi messages from Domains to ATF. Signed-off-by: Oleksii Moisieiev --- xen/arch/arm/Kconfig | 2 + xen/arch/arm/sci/Kconfig | 10 + xen/arch/arm/sci/scmi_smc.c | 959 ++++++++++++++++++++++++++++++++++++ 3 files changed, 971 insertions(+) create mode 100644 xen/arch/arm/sci/Kconfig create mode 100644 xen/arch/arm/sci/scmi_smc.c diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index ab07833582..3b0dfc57b6 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -123,6 +123,8 @@ config ARM_SCI support. It allows guests to control system resourcess via one of ARM_SCI mediators implemented in XEN. + source "arch/arm/sci/Kconfig" + endmenu menu "ARM errata workaround via the alternative framework" diff --git a/xen/arch/arm/sci/Kconfig b/xen/arch/arm/sci/Kconfig new file mode 100644 index 0000000000..10b634d2ed --- /dev/null +++ b/xen/arch/arm/sci/Kconfig @@ -0,0 +1,10 @@ +config SCMI_SMC + bool "Enable SCMI-SMC mediator driver" + default n + depends on ARM_SCI && HOST_DTB_EXPORT + ---help--- + + Enables mediator in XEN to pass SCMI requests from Domains to ATF. + This feature allows drivers from Domains to work with System + Controllers (such as power,resets,clock etc.). SCP is used as transport + for communication. diff --git a/xen/arch/arm/sci/scmi_smc.c b/xen/arch/arm/sci/scmi_smc.c new file mode 100644 index 0000000000..103529dfab --- /dev/null +++ b/xen/arch/arm/sci/scmi_smc.c @@ -0,0 +1,959 @@ +/* + * xen/arch/arm/sci/scmi_smc.c + * + * SCMI mediator driver, using SCP as transport. + * + * Oleksii Moisieiev + * Copyright (C) 2021, EPAM Systems. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SCMI_BASE_PROTOCOL 0x10 +#define SCMI_BASE_PROTOCOL_ATTIBUTES 0x1 +#define SCMI_BASE_SET_DEVICE_PERMISSIONS 0x9 +#define SCMI_BASE_RESET_AGENT_CONFIGURATION 0xB +#define SCMI_BASE_DISCOVER_AGENT 0x7 + +/* SCMI return codes. See section 4.1.4 of SCMI spec (DEN0056C) */ +#define SCMI_SUCCESS 0 +#define SCMI_NOT_SUPPORTED (-1) +#define SCMI_INVALID_PARAMETERS (-2) +#define SCMI_DENIED (-3) +#define SCMI_NOT_FOUND (-4) +#define SCMI_OUT_OF_RANGE (-5) +#define SCMI_BUSY (-6) +#define SCMI_COMMS_ERROR (-7) +#define SCMI_GENERIC_ERROR (-8) +#define SCMI_HARDWARE_ERROR (-9) +#define SCMI_PROTOCOL_ERROR (-10) + +#define DT_MATCH_SCMI_SMC DT_MATCH_COMPATIBLE("arm,scmi-smc") + +#define SCMI_SMC_ID "arm,smc-id" +#define SCMI_SHARED_MEMORY "arm,scmi-shmem" +#define SCMI_SHMEM "shmem" +#define SCMI_SHMEM_MAPPED_SIZE PAGE_SIZE + +#define HYP_CHANNEL 0x0 + +#define HDR_ID GENMASK(7,0) +#define HDR_TYPE GENMASK(9, 8) +#define HDR_PROTO GENMASK(17, 10) + +/* SCMI protocol, refer to section 4.2.2.2 (DEN0056C) */ +#define MSG_N_AGENTS_MASK GENMASK(15, 8) + +#define FIELD_GET(_mask, _reg)\ + ((typeof(_mask))(((_reg) & (_mask)) >> (ffs64(_mask) - 1))) +#define FIELD_PREP(_mask, _val)\ + (((typeof(_mask))(_val) << (ffs64(_mask) - 1)) & (_mask)) + +typedef struct scmi_msg_header { + uint8_t id; + uint8_t type; + uint8_t protocol; +} scmi_msg_header_t; + +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE BIT(0, UL) +#define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR BIT(1, UL) + +#define SCMI_ALLOW_ACCESS BIT(0, UL) + +struct scmi_shared_mem { + uint32_t reserved; + uint32_t channel_status; + uint32_t reserved1[2]; + uint32_t flags; + uint32_t length; + uint32_t msg_header; + uint8_t msg_payload[]; +}; + +struct dt_channel_addr { + u64 addr; + u64 size; + struct list_head list; +}; + +struct scmi_channel { + int chan_id; + int agent_id; + uint32_t func_id; + domid_t domain_id; + uint64_t paddr; + uint64_t len; + struct scmi_shared_mem *shmem; + spinlock_t lock; + struct list_head list; +}; + +struct scmi_data { + struct list_head channel_list; + spinlock_t channel_list_lock; + bool initialized; +}; + +static struct scmi_data scmi_data; + + +/* + * pack_scmi_header() - packs and returns 32-bit header + * + * @hdr: pointer to header containing all the information on message id, + * protocol id and type id. + * + * Return: 32-bit packed message header to be sent to the platform. + */ +static inline uint32_t pack_scmi_header(scmi_msg_header_t *hdr) +{ + return FIELD_PREP(HDR_ID, hdr->id) | + FIELD_PREP(HDR_TYPE, hdr->type) | + FIELD_PREP(HDR_PROTO, hdr->protocol); +} + +/* + * unpack_scmi_header() - unpacks and records message and protocol id + * + * @msg_hdr: 32-bit packed message header sent from the platform + * @hdr: pointer to header to fetch message and protocol id. + */ +static inline void unpack_scmi_header(uint32_t msg_hdr, scmi_msg_header_t *hdr) +{ + hdr->id = FIELD_GET(HDR_ID, msg_hdr); + hdr->type = FIELD_GET(HDR_TYPE, msg_hdr); + hdr->protocol = FIELD_GET(HDR_PROTO, msg_hdr); +} + +static inline int channel_is_free(struct scmi_channel *chan_info) +{ + return ( chan_info->shmem->channel_status + & SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE ) ? 0 : -EBUSY; +} + +/* + * Copy data from IO memory space to "real" memory space. + */ +void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count) +{ + while (count && !IS_ALIGNED((unsigned long)from, 4)) { + *(u8 *)to = __raw_readb(from); + from++; + to++; + count--; + } + + while (count >= 4) { + *(u32 *)to = __raw_readl(from); + from += 4; + to += 4; + count -= 4; + } + + while (count) { + *(u8 *)to = __raw_readb(from); + from++; + to++; + count--; + } +} + +/* + * Copy data from "real" memory space to IO memory space. + */ +void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count) +{ + while (count && !IS_ALIGNED((unsigned long)to, 4)) { + __raw_writeb(*(u8 *)from, to); + from++; + to++; + count--; + } + + while (count >= 4) { + __raw_writel(*(u32 *)from, to); + from += 4; + to += 4; + count -= 4; + } + + while (count) { + __raw_writeb(*(u8 *)from, to); + from++; + to++; + count--; + } +} + +static int send_smc_message(struct scmi_channel *chan_info, + scmi_msg_header_t *hdr, void *data, int len) +{ + struct arm_smccc_res resp; + int ret; + + if ( (len + sizeof(chan_info->shmem->msg_header)) > + SCMI_SHMEM_MAPPED_SIZE ) + { + printk(XENLOG_ERR + "scmi: Wrong size of smc message. Data is invalid\n"); + return -EINVAL; + } + + printk(XENLOG_DEBUG "scmi: status =%d len=%d\n", + chan_info->shmem->channel_status, len); + printk(XENLOG_DEBUG "scmi: header id = %d type = %d, proto = %d\n", + hdr->id, hdr->type, hdr->protocol); + + ret = channel_is_free(chan_info); + if ( IS_ERR_VALUE(ret) ) + return ret; + + chan_info->shmem->channel_status = 0x0; + /* Writing 0x0 right now, but SCMI_SHMEM_FLAG_INTR_ENABLED can be set */ + chan_info->shmem->flags = 0x0; + chan_info->shmem->length = sizeof(chan_info->shmem->msg_header) + len; + chan_info->shmem->msg_header = pack_scmi_header(hdr); + + printk(XENLOG_DEBUG "scmi: Writing to shmem address %p\n", + chan_info->shmem); + if ( len > 0 && data ) + __memcpy_toio((void *)(chan_info->shmem->msg_payload), data, len); + + arm_smccc_smc(chan_info->func_id, 0, 0, 0, 0, 0, 0, chan_info->chan_id, + &resp); + + printk(XENLOG_DEBUG "scmi: scmccc_smc response %d\n", (int)(resp.a0)); + + if ( resp.a0 ) + return -EOPNOTSUPP; + + return 0; +} + +static int check_scmi_status(int scmi_status) +{ + if ( scmi_status == SCMI_SUCCESS ) + return 0; + + printk(XENLOG_DEBUG "scmi: Error received: %d\n", scmi_status); + + switch ( scmi_status ) + { + case SCMI_NOT_SUPPORTED: + return -EOPNOTSUPP; + case SCMI_INVALID_PARAMETERS: + return -EINVAL; + case SCMI_DENIED: + return -EACCES; + case SCMI_NOT_FOUND: + return -ENOENT; + case SCMI_OUT_OF_RANGE: + return -ERANGE; + case SCMI_BUSY: + return -EBUSY; + case SCMI_COMMS_ERROR: + return -ENOTCONN; + case SCMI_GENERIC_ERROR: + return -EIO; + case SCMI_HARDWARE_ERROR: + return -ENXIO; + case SCMI_PROTOCOL_ERROR: + return -EBADMSG; + default: + return -EINVAL; + } +} + +static int get_smc_response(struct scmi_channel *chan_info, + scmi_msg_header_t *hdr, void *data, int len) +{ + int recv_len; + int ret; + + printk(XENLOG_DEBUG "scmi: get smc responce msgid %d\n", hdr->id); + + if ( len >= SCMI_SHMEM_MAPPED_SIZE - sizeof(chan_info->shmem) ) + { + printk(XENLOG_ERR + "scmi: Wrong size of input smc message. Data may be invalid\n"); + return -EINVAL; + } + + ret = channel_is_free(chan_info); + if ( IS_ERR_VALUE(ret) ) + return ret; + + recv_len = chan_info->shmem->length - sizeof(chan_info->shmem->msg_header); + + if ( recv_len < 0 ) + { + printk(XENLOG_ERR + "scmi: Wrong size of smc message. Data may be invalid\n"); + return -EINVAL; + } + + if ( recv_len > len ) + { + printk(XENLOG_ERR + "scmi: Not enough buffer for message %d, expecting %d\n", + recv_len, len); + return -EINVAL; + } + + unpack_scmi_header(chan_info->shmem->msg_header, hdr); + + if ( recv_len > 0 ) + { + __memcpy_fromio(data, chan_info->shmem->msg_payload, recv_len); + } + + return 0; +} + +static int do_smc_xfer(struct scmi_channel *channel, scmi_msg_header_t *hdr, void *tx_data, int tx_size, + void *rx_data, int rx_size) +{ + int ret = 0; + + ASSERT( channel && channel->shmem); + + if ( !hdr ) + return -EINVAL; + + spin_lock(&channel->lock); + + ret = send_smc_message(channel, hdr, tx_data, tx_size); + if ( ret ) + goto clean; + + ret = get_smc_response(channel, hdr, rx_data, rx_size); +clean: + spin_unlock(&channel->lock); + + return ret; +} + +static struct scmi_channel *get_channel_by_id(uint8_t chan_id) +{ + struct scmi_channel *curr; + bool found = false; + + spin_lock(&scmi_data.channel_list_lock); + list_for_each_entry(curr, &scmi_data.channel_list, list) + { + if ( curr->chan_id == chan_id ) + { + found = true; + break; + } + } + + spin_unlock(&scmi_data.channel_list_lock); + if ( found ) + return curr; + + return NULL; +} + +static struct scmi_channel *aquire_scmi_channel(domid_t domain_id) +{ + struct scmi_channel *curr; + bool found = false; + + ASSERT(domain_id != DOMID_INVALID && domain_id >= 0); + + spin_lock(&scmi_data.channel_list_lock); + list_for_each_entry(curr, &scmi_data.channel_list, list) + { + if ( curr->domain_id == DOMID_INVALID ) + { + curr->domain_id = domain_id; + found = true; + break; + } + } + + spin_unlock(&scmi_data.channel_list_lock); + if ( found ) + return curr; + + return NULL; +} + +static void relinquish_scmi_channel(struct scmi_channel *channel) +{ + ASSERT(channel != NULL); + + spin_lock(&scmi_data.channel_list_lock); + channel->domain_id = DOMID_INVALID; + spin_unlock(&scmi_data.channel_list_lock); +} + +static int map_channel_memory(struct scmi_channel *channel) +{ + ASSERT( channel && channel->paddr ); + channel->shmem = ioremap_cache(channel->paddr, SCMI_SHMEM_MAPPED_SIZE); + if ( !channel->shmem ) + return -ENOMEM; + + channel->shmem->channel_status = SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE; + printk(XENLOG_DEBUG "scmi: Got shmem after vmap %p\n", channel->shmem); + return 0; +} + +static void unmap_channel_memory(struct scmi_channel *channel) +{ + ASSERT( channel && channel->shmem ); + iounmap(channel->shmem); + channel->shmem = NULL; +} + +static struct scmi_channel *smc_create_channel(uint8_t chan_id, + uint32_t func_id, uint64_t addr) +{ + struct scmi_channel *channel; + + channel = get_channel_by_id(chan_id); + if ( channel ) + return ERR_PTR(EEXIST); + + channel = xmalloc(struct scmi_channel); + if ( !channel ) + return ERR_PTR(ENOMEM); + + channel->chan_id = chan_id; + channel->func_id = func_id; + channel->domain_id = DOMID_INVALID; + channel->shmem = NULL; + channel->paddr = addr; + spin_lock_init(&channel->lock); + spin_lock(&scmi_data.channel_list_lock); + list_add(&channel->list, &scmi_data.channel_list); + spin_unlock(&scmi_data.channel_list_lock); + return channel; +} + +static int mem_permit_access(struct domain *d, uint64_t addr, uint64_t len) +{ + return iomem_permit_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len -1))); +} + +static int mem_deny_access(struct domain *d, uint64_t addr, + uint64_t len) +{ + return iomem_deny_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len -1))); +} + +static int dt_update_domain_range(uint64_t addr, uint64_t size) +{ + struct dt_device_node *shmem_node; + __be32 *hw_reg; + const struct dt_property *pp; + uint32_t len; + + shmem_node = dt_find_compatible_node(NULL, NULL, SCMI_SHARED_MEMORY); + if ( !shmem_node ) + { + printk(XENLOG_ERR "scmi: Unable to find %s node in DT\n", SCMI_SHMEM); + return -EINVAL; + } + + pp = dt_find_property(shmem_node, "reg", &len); + if ( !pp ) + { + printk(XENLOG_ERR "scmi: Unable to find regs entry in shmem node\n"); + return -ENOENT; + } + + hw_reg = pp->value; + dt_set_range(&hw_reg, shmem_node, addr, size); + + return 0; +} + +static void free_channel_list(void) +{ + struct scmi_channel *curr, *_curr; + + spin_lock(&scmi_data.channel_list_lock); + list_for_each_entry_safe (curr, _curr, &scmi_data.channel_list, list) + { + list_del(&curr->list); + xfree(curr); + } + + spin_unlock(&scmi_data.channel_list_lock); +} + +static struct dt_device_node *get_dt_node_from_property( + struct dt_device_node *node, const char * p_name) +{ + const __be32 *prop; + + ASSERT( node ); + + prop = dt_get_property(node, p_name, NULL); + if ( !prop ) + return ERR_PTR(-EINVAL); + + return dt_find_node_by_phandle(be32_to_cpup(prop)); +} + +static int get_shmem_regions(struct list_head *head, u64 hyp_addr) +{ + struct dt_device_node *node; + int ret; + struct dt_channel_addr *lchan; + u64 laddr, lsize; + + node = dt_find_compatible_node(NULL, NULL, SCMI_SHARED_MEMORY); + if ( !node ) + return -ENOENT; + + while ( node ) + { + ret = dt_device_get_address(node, 0, &laddr, &lsize); + if ( ret ) + return ret; + + if ( laddr != hyp_addr ) + { + lchan = xmalloc(struct dt_channel_addr); + if ( !lchan ) + return -ENOMEM; + lchan->addr = laddr; + lchan->size = lsize; + + list_add_tail(&lchan->list, head); + } + + node = dt_find_compatible_node(node, NULL, SCMI_SHARED_MEMORY); + } + + return 0; +} + +static int read_hyp_channel_addr(struct dt_device_node *scmi_node, + u64 *addr, u64 *size) +{ + struct dt_device_node *shmem_node; + shmem_node = get_dt_node_from_property(scmi_node, "shmem"); + if ( IS_ERR_OR_NULL(shmem_node) ) + { + printk(XENLOG_ERR + "scmi: Device tree error, can't parse reserved memory %ld\n", + PTR_ERR(shmem_node)); + return PTR_ERR(shmem_node); + } + + return dt_device_get_address(shmem_node, 0, addr, size); +} + +static void free_shmem_regions(struct list_head *addr_list) +{ + struct dt_channel_addr *curr, *_curr; + + list_for_each_entry_safe (curr, _curr, addr_list, list) + { + list_del(&curr->list); + xfree(curr); + } +} + +static __init bool scmi_probe(struct dt_device_node *scmi_node) +{ + u64 addr, size; + int ret, i; + struct scmi_channel *channel, *agent_channel; + int n_agents; + scmi_msg_header_t hdr; + struct rx_t { + int32_t status; + uint32_t attributes; + } rx; + struct dt_channel_addr *entry; + struct list_head addr_list; + + uint32_t func_id; + + ASSERT(scmi_node != NULL); + + INIT_LIST_HEAD(&scmi_data.channel_list); + spin_lock_init(&scmi_data.channel_list_lock); + + if ( !dt_property_read_u32(scmi_node, SCMI_SMC_ID, &func_id) ) + { + printk(XENLOG_ERR "scmi: Unable to read smc-id from DT\n"); + return false; + } + + ret = read_hyp_channel_addr(scmi_node, &addr, &size); + if ( IS_ERR_VALUE(ret) ) + return false; + + if ( !IS_ALIGNED(size, SCMI_SHMEM_MAPPED_SIZE) ) + { + printk(XENLOG_ERR "scmi: Reserved memory is not aligned\n"); + return false; + } + + INIT_LIST_HEAD(&addr_list); + + ret = get_shmem_regions(&addr_list, addr); + if ( IS_ERR_VALUE(ret) ) + goto out; + + channel = smc_create_channel(HYP_CHANNEL, func_id, addr); + if ( IS_ERR(channel) ) + goto out; + + ret = map_channel_memory(channel); + if ( ret ) + goto out; + + spin_lock(&scmi_data.channel_list_lock); + channel->domain_id = DOMID_XEN; + spin_unlock(&scmi_data.channel_list_lock); + + hdr.id = SCMI_BASE_PROTOCOL_ATTIBUTES; + hdr.type = 0; + hdr.protocol = SCMI_BASE_PROTOCOL; + + ret = do_smc_xfer(channel, &hdr, NULL, 0, &rx, sizeof(rx)); + if ( ret ) + goto error; + + ret = check_scmi_status(rx.status); + if ( ret ) + goto error; + + n_agents = FIELD_GET(MSG_N_AGENTS_MASK, rx.attributes); + printk(XENLOG_DEBUG "scmi: Got agent count %d\n", n_agents); + + i = 1; + list_for_each_entry(entry, &addr_list, list) + { + uint32_t tx_agent_id = 0xFFFFFFFF; + struct { + int32_t status; + uint32_t agent_id; + char name[16]; + } da_rx; + + agent_channel = smc_create_channel(i, func_id, + entry->addr); + if ( IS_ERR(agent_channel) ) + { + ret = PTR_ERR(agent_channel); + goto error; + } + + ret = map_channel_memory(agent_channel); + if ( ret ) + goto error; + + hdr.id = SCMI_BASE_DISCOVER_AGENT; + hdr.type = 0; + hdr.protocol = SCMI_BASE_PROTOCOL; + + ret = do_smc_xfer(agent_channel, &hdr, &tx_agent_id, + sizeof(tx_agent_id), &da_rx, sizeof(da_rx)); + if ( ret ) + { + unmap_channel_memory(agent_channel); + goto error; + } + + unmap_channel_memory(agent_channel); + + ret = check_scmi_status(da_rx.status); + if ( ret ) + goto error; + + printk(XENLOG_DEBUG "scmi: status=0x%x id=0x%x name=%s\n", + da_rx.status, da_rx.agent_id, da_rx.name); + + agent_channel->agent_id = da_rx.agent_id; + + if ( i == n_agents ) + break; + + i++; + } + + scmi_data.initialized = true; + goto out; + +error: + unmap_channel_memory(channel); + free_channel_list(); +out: + free_shmem_regions(&addr_list); + return ret == 0; +} + +static int scmi_domain_init(struct domain *d, + struct xen_arch_domainconfig *config) +{ + struct scmi_channel *channel; + int ret; + + if ( !scmi_data.initialized ) + return 0; + + printk(XENLOG_INFO "scmi: domain_id = %d\n", d->domain_id); + + channel = aquire_scmi_channel(d->domain_id); + if ( IS_ERR_OR_NULL(channel) ) + return -ENOENT; + +#ifdef CONFIG_ARM_32 + printk(XENLOG_INFO + "scmi: Aquire SCMI channel id = 0x%x , domain_id = %d paddr = 0x%llx\n", + channel->chan_id, channel->domain_id, channel->paddr); +#else + printk(XENLOG_INFO + "scmi: Aquire SCMI channel id = 0x%x , domain_id = %d paddr = 0x%lx\n", + channel->chan_id, channel->domain_id, channel->paddr); +#endif + + if ( is_hardware_domain(d) ) + { + ret = mem_permit_access(d, channel->paddr, PAGE_SIZE); + if ( IS_ERR_VALUE(ret) ) + goto error; + + ret = dt_update_domain_range(channel->paddr, PAGE_SIZE); + if ( IS_ERR_VALUE(ret) ) + { + int rc = mem_deny_access(d, channel->paddr, PAGE_SIZE); + if ( rc ) + printk(XENLOG_ERR "Unable to mem_deny_access\n"); + + goto error; + } + } + + d->arch.sci = channel; + if ( config ) + config->arm_sci_agent_paddr = channel->paddr; + + return 0; +error: + relinquish_scmi_channel(channel); + + return ret; +} + +static int scmi_add_device_by_devid(struct domain *d, uint32_t scmi_devid) +{ + struct scmi_channel *channel, *agent_channel; + scmi_msg_header_t hdr; + struct scmi_perms_tx { + uint32_t agent_id; + uint32_t device_id; + uint32_t flags; + } tx; + struct rx_t { + int32_t status; + uint32_t attributes; + } rx; + int ret; + + if ( !scmi_data.initialized ) + return 0; + + printk(XENLOG_DEBUG "scmi: scmi_devid = %d\n", scmi_devid); + + agent_channel = d->arch.sci; + if ( IS_ERR_OR_NULL(agent_channel) ) + return PTR_ERR(agent_channel); + + channel = get_channel_by_id(HYP_CHANNEL); + if ( IS_ERR_OR_NULL(channel) ) + return PTR_ERR(channel); + + hdr.id = SCMI_BASE_SET_DEVICE_PERMISSIONS; + hdr.type = 0; + hdr.protocol = SCMI_BASE_PROTOCOL; + + tx.agent_id = agent_channel->agent_id; + tx.device_id = scmi_devid; + tx.flags = SCMI_ALLOW_ACCESS; + + ret = do_smc_xfer(channel, &hdr, &tx, sizeof(tx), &rx, sizeof(&rx)); + if ( IS_ERR_VALUE(ret) ) + return ret; + + ret = check_scmi_status(rx.status); + if ( IS_ERR_VALUE(ret) ) + return ret; + + return 0; +} + +static int scmi_add_dt_device(struct domain *d, struct dt_device_node *dev) +{ + uint32_t scmi_devid; + + if ( (!scmi_data.initialized) || (!d->arch.sci) ) + return 0; + + if ( !dt_property_read_u32(dev, "scmi_devid", &scmi_devid) ) + return 0; + + printk(XENLOG_INFO "scmi: dt_node = %s\n", dt_node_full_name(dev)); + + return scmi_add_device_by_devid(d, scmi_devid); +} + +static int scmi_relinquish_resources(struct domain *d) +{ + int ret; + struct scmi_channel *channel, *agent_channel; + scmi_msg_header_t hdr; + struct reset_agent_tx { + uint32_t agent_id; + uint32_t flags; + } tx; + uint32_t rx; + + if ( !d->arch.sci ) + return 0; + + agent_channel = d->arch.sci; + + spin_lock(&agent_channel->lock); + tx.agent_id = agent_channel->agent_id; + spin_unlock(&agent_channel->lock); + + channel = get_channel_by_id(HYP_CHANNEL); + if ( !channel ) + { + printk(XENLOG_ERR + "scmi: Unable to get Hypervisor scmi channel for domain %d\n", + d->domain_id); + return -EINVAL; + } + + hdr.id = SCMI_BASE_RESET_AGENT_CONFIGURATION; + hdr.type = 0; + hdr.protocol = SCMI_BASE_PROTOCOL; + + tx.flags = 0; + + ret = do_smc_xfer(channel, &hdr, &tx, sizeof(tx), &rx, sizeof(rx)); + if ( ret ) + return ret; + + ret = check_scmi_status(rx); + + return ret; +} + +static void scmi_domain_destroy(struct domain *d) +{ + struct scmi_channel *channel; + + if ( !d->arch.sci ) + return; + + channel = d->arch.sci; + spin_lock(&channel->lock); + + relinquish_scmi_channel(channel); + printk(XENLOG_DEBUG "scmi: Free domain %d\n", d->domain_id); + + d->arch.sci = NULL; + + mem_deny_access(d, channel->paddr, PAGE_SIZE); + spin_unlock(&channel->lock); +} + +static bool scmi_handle_call(struct domain *d, void *args) +{ + bool res = false; + struct scmi_channel *agent_channel; + struct arm_smccc_res resp; + struct cpu_user_regs *regs = args; + + if ( !d->arch.sci ) + return false; + + agent_channel = d->arch.sci; + spin_lock(&agent_channel->lock); + + if ( agent_channel->func_id != regs->r0 ) + { + res = false; + goto unlock; + } + + arm_smccc_smc(agent_channel->func_id, 0, 0, 0, 0, 0, 0, + agent_channel->chan_id, &resp); + + set_user_reg(regs, 0, resp.a0); + set_user_reg(regs, 1, resp.a1); + set_user_reg(regs, 2, resp.a2); + set_user_reg(regs, 3, resp.a3); + res = true; +unlock: + spin_unlock(&agent_channel->lock); + + return res; +} + +static const struct dt_device_match scmi_smc_match[] __initconst = +{ + DT_MATCH_SCMI_SMC, + { /* sentinel */ }, +}; + +static const struct sci_mediator_ops scmi_ops = +{ + .probe = scmi_probe, + .domain_init = scmi_domain_init, + .domain_destroy = scmi_domain_destroy, + .add_dt_device = scmi_add_dt_device, + .relinquish_resources = scmi_relinquish_resources, + .handle_call = scmi_handle_call, +}; + +REGISTER_SCI_MEDIATOR(scmi_smc, "SCMI-SMC", XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC, + scmi_smc_match, &scmi_ops); + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Tue Feb 8 18:00:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 12739146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9E2EC4321E for ; Tue, 8 Feb 2022 18:00:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268495.462375 (Exim 4.92) (envelope-from ) id 1nHUmt-0007BO-Tn; Tue, 08 Feb 2022 18:00:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268495.462375; Tue, 08 Feb 2022 18:00:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmt-0007BF-Q6; Tue, 08 Feb 2022 18:00:23 +0000 Received: by outflank-mailman (input) for mailman id 268495; Tue, 08 Feb 2022 18:00:22 +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 1nHUmr-00068L-Uj for xen-devel@lists.xenproject.org; Tue, 08 Feb 2022 18:00:22 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fa4697a8-8908-11ec-8eb8-a37418f5ba1a; Tue, 08 Feb 2022 19:00:20 +0100 (CET) Received: from pps.filterd (m0174678.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 218EgrT7015757; Tue, 8 Feb 2022 18:00:16 GMT Received: from eur02-he1-obe.outbound.protection.outlook.com (mail-he1eur02lp2057.outbound.protection.outlook.com [104.47.5.57]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3e3t5xrs6q-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 18:00:15 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by VE1PR03MB5613.eurprd03.prod.outlook.com (2603:10a6:803:12a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19; Tue, 8 Feb 2022 18:00:12 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0%6]) with mapi id 15.20.4951.019; Tue, 8 Feb 2022 18:00:12 +0000 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: fa4697a8-8908-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h2KNhFxlgCVQ3hz6aHDPUNPiLYciaW/Wx82wVBnPSTn9Glspe4Pvd752Yhup5TeOWcEarzDyeZ8JH+S9nLgSfODgcCeuXYnE/pm/3TP68wgaXif26CW9PGeHXpil9dBdE+Y+ksydH8sO2MUg07mCqpnQ6ku/kKKkClNX0z8BqQodUK4Ax4HL2+SdIv688PiQkyWkGoR84mg2aYba18FflVp75FCmVzmRFYq3BCXdB9Kk66wM6lNw6JAEq/uNB6AlCKRNvLSgeqKPOIMvcIO4yDtfQcZlKpVsppn5tghhbGNDTdX/8qa62BEzlJubYRqQqnM8m0dcU5Aq5EpxU1BBEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HALhPv+64kbkAOfpSs3FqZOqYi5IDheOGLf5PgXphVE=; b=ccvM4G7+MTrS7txnx2sAe5VH+pF/x2c/AzFZz1U6sVlCWvmGc+kPWEYtWT5l1h5kD4jEzUPfy9JiyLraxAqIFHOANtGq7UJsUF+551WYEDKsiyBPFW1DdYJAqwUYbTgcHF5zAKYtBzU85KFcYbYD6dnCg+uEsNF8RFk1smy5K8FuO/dmrN3/L6CTV9ofMJz0IXDiINl6MZhXfzkURBUv/2YpgnL9HaUdrHWEcv4WRREwHZrhAKcr3aSqAN+2rKpcRQ9uW0/CyrD9aFwE5ejiSWvKOchkxINP8jKSzpRsBpJnXNOrojeZ3mNiNenxY7sRudlw83bV/IThXVtcsA07Rw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HALhPv+64kbkAOfpSs3FqZOqYi5IDheOGLf5PgXphVE=; b=ieLdGr4y1e7909uSLGz0HjamxFFs996NCd0HBilnPNN3C4vpjB8MWumuTRXf7qf0BAMKkOoDQHabEX9cZWJW7tSqcGXopofHS4nVPtRiEhYFduhpTO6b752KBb7plNHPJAuGp0lW/0RZaqjnrC2zswJtLC30tSZvzqOhU3Ba7W4V1GdmX4ueU2YugSEBX4BJkjHulIifGYOFhZ+se6BshIXAYIzEFDlY1PEdj56z5qKAIOU1jBCfAbBmaoUjr+r/p86XyOhQr+l1L2jnHt+gVPnAYCUX+NBOb/w78rHPxf3mocV8P3vLmTKC+sU4+SWlFUobNpTRbZg0Xz+gt4vOiw== From: Oleksii Moisieiev To: "xen-devel@lists.xenproject.org" CC: Oleksii Moisieiev , Wei Liu , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Nick Rosbrook , Anthony PERARD , Juergen Gross , Paul Durrant Subject: [RFC v2 6/8] tools/arm: Introduce force_assign_without_iommu option to xl.cfg Thread-Topic: [RFC v2 6/8] tools/arm: Introduce force_assign_without_iommu option to xl.cfg Thread-Index: AQHYHRW3O86755dYV0qSgPdVO9oeMQ== Date: Tue, 8 Feb 2022 18:00:12 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1406799b-d4c3-4d19-7fe5-08d9eb2cda71 x-ms-traffictypediagnostic: VE1PR03MB5613:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2733; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 593+KpeE3vja2YgkOiTpjRnUJLKsUnuEshoh2Z+V4mqsiSo09+3zRaS1Vrpv8dZ1iF/MqnsrWN/6uJj3IPvFXeyHgMPPFhyLjYLtQdCHGvz3x5MiTEdThKVlcsWcAOBYCm70PN/BkdRouDMixd5PCS6IYkW6v0vjahDLiDE9ZZwKve/jGlk2h7pfJp6pgQ3x5deUnaR+GPL7KbZsW53Jre8is0NkCBSmdLjMjk0FXgej+AILfM8vZFYtTPg23/1ci2UDpCHDNLGlWw/rIPAsYNvNyIXnLKKQDX5LVvQ09PhoGojoAHPRVhrbaCXc/l93tIS1rMB2FEc/lJruP+iKuym+aaruKVbACuzf4dVe98myH+NmviMnY3WtQ7EaDurHQvEz7xd7LZX30lJE9LbMVziWg2Jycy3yyIGOFNrff7HgxmMc4F4OBJFidDNLokEjZyBS3hU/GlkvugonmB/eXwyAouXPctx4J6XtcUnhOls9BBKDwNgun5ZY9DroINfjiWFDy8hq1Xjcm/eKoMVBsFovONlsF88xcVB5UJLSV8Cs2tGeOepWnfYDHEOXzi595m3+Y2qsHkCBbtXSDTK9nEcY7SW/nWEOMdBqzEs7nrThcYj63kObyzkok3T/66q3MddGajmE+q9iww35HLMfC8Aoyfhfrt9HIfGHyg+iOUjaAJXJXp5EHL2oNK11D/wzlvO8BRKM9VsrZijYDtwKSw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38070700005)(71200400001)(6486002)(508600001)(66476007)(64756008)(86362001)(66556008)(316002)(122000001)(6916009)(6506007)(2616005)(5660300002)(6512007)(7416002)(4326008)(83380400001)(54906003)(2906002)(26005)(186003)(8676002)(76116006)(38100700002)(66446008)(66946007)(8936002)(36756003)(91956017);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?H5luS7cGOqtky8dqBSfDdIB?= =?iso-8859-1?q?F46ch9LNqepgA9GrqaX4ojMAXig0k8+s4qof5lKGI9tUPDokXwTEGqrRhc2Z?= =?iso-8859-1?q?BpIKSOO2/P560SJXgreqWgV27tF0ReiU1+qF9up8uSuYejI2F8a0sO9Zv6Ax?= =?iso-8859-1?q?P3ijoB8mrmZ/VsCw68+c/tSmyEeHezXib09zKso5FC5Aa8vibGerdJVaaz9M?= =?iso-8859-1?q?mIr5TjbxzQJ4llz/Y2GOk5Bx8gyLN2cxMhw/FQF2HTsHrtKW8spAgwjJNYhH?= =?iso-8859-1?q?AotUKsZBNxbgsvqUak67wtc3VFXx1TCx+H7WEkSfH5Vs3SoGdOvEVqIWsEgh?= =?iso-8859-1?q?6O61XSPNO3IC9prDEbqFLKECoMaiTb2NvgBgFoK+EcBSvVBr4Q4CEIdUQ3Ce?= =?iso-8859-1?q?hkEcW22ruuLu6bADw7OurfyuIaTITO97i8FtNa39qQJ8G/IoxF4nwU03NMfn?= =?iso-8859-1?q?5z/6tJaelToWW0c06rfkG1t2dKwIdKNgulenR6CNB+lMNb6PSW4KeZpcnUVs?= =?iso-8859-1?q?jtMo7Z1rqihaAxx/D3P6mBf5iV/sukO9xCu/VSkSMnUaIhEXphzPaIVHkHc6?= =?iso-8859-1?q?HHfbJCjZy5xDDcqf9ZwADwtD66UiXcZe/oVJtQGyaN5258jhSDzDcDGRnmHl?= =?iso-8859-1?q?0N0uEOQlHhb/zblsUBQaAGZRlpdvlbuJbN8Myp6UovCN5VctfPlJmbQPAHp+?= =?iso-8859-1?q?M5BE6RO0EQaCx+Im/m1o+VHxofRcAKlbaUZnKb/X4tXjpl5S2kcSrRXddJza?= =?iso-8859-1?q?2hmXPaZaPmuo/douwHmz2iK5LO8aCFNy67JzrnG1UUJB/+9d5dtJfDb9Q5eX?= =?iso-8859-1?q?AoNuvZKVplEHt2Fq7+w5NRDVZnEbpSLkDBV6AwfYnU0CR6kQrYKut7BIULwC?= =?iso-8859-1?q?k+D7b+Zfuwr77PA62dO+U9UJviqXtYIEX+ROh9Pp87puCa8M0KAHuYuTua/o?= =?iso-8859-1?q?h7Shr2HpC8Z/mUq7gMG2edV07HWNE+AaYGFSSXKo7mycjJwn2w+z6dM+VVbc?= =?iso-8859-1?q?SFTd/auZ/4pDKBctfoO9tkZU2rPN5tjwdnoFWNyKu48bnlvJk6BwNpksZDK+?= =?iso-8859-1?q?vQZaMTgJMoBA4HMLj989wUEK+10FJ2B9R8wfJ6CggN13udtavg7XZq5j9nna?= =?iso-8859-1?q?b1tKkS7GSn54N9SVnKPMyM6sr2JJQt+wvV115FFS71vchWfq1dE00dBAT2s4?= =?iso-8859-1?q?wbDT3+vRzGM6Ws2BheIoql9OqOdmxbHqCOceS/4XA3PwMun56ytPN0i4AOsT?= =?iso-8859-1?q?vQUcRGCGaCWhoje2F1GeePOgoFVCYQiLIjWCMUljubHbWh5CUHbDaNOhuLPm?= =?iso-8859-1?q?vKiQ13AhvBX/nczL7sJ3KjAgWxVa10NdKwQs2L4sx+COje5FPszhxS5hl61V?= =?iso-8859-1?q?R8utIanAezbLu/SCv4omYchkh9jU2lVbBxdprOsC0V4C3ElllTtaXvbzCZF2?= =?iso-8859-1?q?VCvgcbk+YYDwZEmI2jLq0jXINdRulSET2eJg9akGcOO4SgcLgK2xh7NUGvKZ?= =?iso-8859-1?q?9eS8YqFZfGUC8tgVByzxa9iLzfgHmgREV2dSc+s2ic+mPBAAzWx9+6ORWxRp?= =?iso-8859-1?q?X5Wnpc9lJdPlL4A8/s7KWFi/TQb5g53HCJpn+s2ep2v56INYeOXeg2/paMEI?= =?iso-8859-1?q?gURJsTJYfvRkuu3FbZzSibmroOAVcVsPi5CFgtFrcXpXJS/MPfRNIino0Qqh?= =?iso-8859-1?q?CITWz8X1Oqe2SOabs/Idumn9HLtJdwiJAqz1tZy20zcihE3kJaDurxmiq2s2?= =?iso-8859-1?q?QCDo=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1406799b-d4c3-4d19-7fe5-08d9eb2cda71 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Feb 2022 18:00:12.4970 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 5DOSt7gwUuwIgKy6ZRyHgGtHxhKXNGVsOzC7tpi3/KuMPnoQfP0vUyJNjT1bel8QlNHtM6Avhi8jw+8ypNYye3goNyRILoMTWNdhNh7rJAA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5613 X-Proofpoint-GUID: bzJlSQfioNgt_-ErlNy4ipphN0IvOoPY X-Proofpoint-ORIG-GUID: bzJlSQfioNgt_-ErlNy4ipphN0IvOoPY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_06,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080106 If set, Xen is allowed to assign the devices even if they are not under IOMMU. Can be confugired from dom.cfg in the following format: force_assign_without_iommu = 1 This parameter has the same purpose as xen,force-assign-without-iommu property in dom0less archtecture. Signed-off-by: Oleksii Moisieiev --- docs/man/xl.cfg.5.pod.in | 9 +++++++++ tools/golang/xenlight/helpers.gen.go | 5 +++++ tools/golang/xenlight/types.gen.go | 1 + tools/libs/light/libxl_arm.c | 3 +++ tools/libs/light/libxl_types.idl | 1 + tools/xl/xl_parse.c | 3 +++ xen/common/domain.c | 2 +- xen/drivers/passthrough/device_tree.c | 19 +++++++++++++++++-- xen/drivers/passthrough/iommu.c | 5 ++++- xen/include/public/domctl.h | 5 ++++- xen/include/xen/iommu.h | 3 +++ 11 files changed, 51 insertions(+), 5 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index b98d161398..ddf82cb3bc 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1614,6 +1614,15 @@ This feature is a B. =back +=over 4 + +=item B + +If set, Xen allows to assign a devices even if it is not behind an IOMMU. +This renders your platform *unsafe* if the device is DMA-capable. + +=back + =back =head2 Paravirtualised (PV) Guest Specific Options diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index b746ff1081..664933bbb8 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1091,6 +1091,11 @@ if err := x.DmRestrict.fromC(&xc.dm_restrict);err != nil { return fmt.Errorf("converting field DmRestrict: %v", err) } x.Tee = TeeType(xc.tee) + +if err := x.ForceAssignWithoutIommu.fromC(&xc.force_assign_without_iommu);err != nil { +return fmt.Errorf("converting field ForceAssignWithoutIommu: %v", err) +} + x.Type = DomainType(xc._type) switch x.Type{ case DomainTypeHvm: diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/types.gen.go index b1e84d5258..2f7a088c3b 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -512,6 +512,7 @@ NestedHvm Defbool Apic Defbool DmRestrict Defbool Tee TeeType +ForceAssignWithoutIommu Defbool Type DomainType TypeUnion DomainBuildInfoTypeUnion ArchArm struct { diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index eef1de0939..c5090e2b32 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -101,6 +101,9 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, return ERROR_FAIL; } + if (libxl_defbool_val(d_config->b_info.force_assign_without_iommu)) + config->iommu_opts |= XEN_DOMCTL_IOMMU_force_iommu; + return 0; } diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl index 2a42da2f7d..1080966c33 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -564,6 +564,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("apic", libxl_defbool), ("dm_restrict", libxl_defbool), ("tee", libxl_tee_type), + ("force_assign_without_iommu", libxl_defbool), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), ("bios", libxl_bios_type), diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 117fcdcb2b..67fa96d949 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2747,6 +2747,9 @@ skip_usbdev: } } + xlu_cfg_get_defbool(config, "force_assign_without_iommu", + &b_info->force_assign_without_iommu, 0); + parse_vkb_list(config, d_config); xlu_cfg_get_defbool(config, "xend_suspend_evtchn_compat", diff --git a/xen/common/domain.c b/xen/common/domain.c index 093bb4403f..f1f19bf711 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -512,7 +512,7 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config) if ( iommu ) { - if ( config->iommu_opts & ~XEN_DOMCTL_IOMMU_no_sharept ) + if ( config->iommu_opts >> XEN_DOMCTL_IOMMU_MAX ) { dprintk(XENLOG_INFO, "Unknown IOMMU options %#x\n", config->iommu_opts); diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 98f2aa0dad..103608dec1 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -198,6 +198,7 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, { int ret; struct dt_device_node *dev; + struct domain_iommu *hd = dom_iommu(d); switch ( domctl->cmd ) { @@ -238,6 +239,16 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, return -EINVAL; ret = iommu_add_dt_device(dev); + + /* + * iommu_add_dt_device returns 1 if iommu is disabled or device don't + * have iommus property + */ + if ( (ret == 1) && (hd->force_assign_iommu) ) { + ret = -ENOSYS; + break; + } + if ( ret < 0 ) { printk(XENLOG_G_ERR "Failed to add %s to the IOMMU\n", @@ -275,10 +286,14 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, ret = iommu_deassign_dt_device(d, dev); - if ( ret ) - printk(XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign \"%s\"" + if ( ret ) { + if ( hd->force_assign_iommu ) + ret = -ENOSYS; + else + printk(XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign \"%s\"" " to dom%u failed (%d)\n", dt_node_full_name(dev), d->domain_id, ret); + } break; default: diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 6334370109..216a9058c0 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -193,6 +193,8 @@ int iommu_domain_init(struct domain *d, unsigned int opts) hd->node = NUMA_NO_NODE; #endif + hd->force_assign_iommu = opts & XEN_DOMCTL_IOMMU_force_iommu; + ret = arch_iommu_domain_init(d); if ( ret ) return ret; @@ -534,6 +536,7 @@ int iommu_do_domctl( { int ret = -ENODEV; + if ( !is_iommu_enabled(d) ) return -EOPNOTSUPP; @@ -542,7 +545,7 @@ int iommu_do_domctl( #endif #ifdef CONFIG_HAS_DEVICE_TREE - if ( ret == -ENODEV ) + if ( ret == -ENOSYS ) ret = iommu_do_dt_domctl(domctl, d, u_domctl); #endif diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index b85e6170b0..bf5f8c5b6b 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -81,8 +81,11 @@ struct xen_domctl_createdomain { #define _XEN_DOMCTL_IOMMU_no_sharept 0 #define XEN_DOMCTL_IOMMU_no_sharept (1U << _XEN_DOMCTL_IOMMU_no_sharept) +#define _XEN_DOMCTL_IOMMU_force_iommu 1 +#define XEN_DOMCTL_IOMMU_force_iommu (1U << _XEN_DOMCTL_IOMMU_force_iommu) + /* Max XEN_DOMCTL_IOMMU_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_IOMMU_MAX XEN_DOMCTL_IOMMU_no_sharept +#define XEN_DOMCTL_IOMMU_MAX XEN_DOMCTL_IOMMU_force_iommu uint32_t iommu_opts; diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 6b2cdffa4a..a9cf2334af 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -330,6 +330,9 @@ struct domain_iommu { * necessarily imply this is true. */ bool need_sync; + + /* Do not return error if the device without iommu is assigned */ + bool force_assign_iommu; }; #define dom_iommu(d) (&(d)->iommu) From patchwork Tue Feb 8 18:00:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 12739151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4A716C4167D for ; Tue, 8 Feb 2022 18:00:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268496.462387 (Exim 4.92) (envelope-from ) id 1nHUmv-0007T5-FB; Tue, 08 Feb 2022 18:00:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268496.462387; Tue, 08 Feb 2022 18:00:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmv-0007SF-94; Tue, 08 Feb 2022 18:00:25 +0000 Received: by outflank-mailman (input) for mailman id 268496; Tue, 08 Feb 2022 18:00:23 +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 1nHUms-00068L-Uo for xen-devel@lists.xenproject.org; Tue, 08 Feb 2022 18:00:23 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fa8cc221-8908-11ec-8eb8-a37418f5ba1a; Tue, 08 Feb 2022 19:00:20 +0100 (CET) Received: from pps.filterd (m0174678.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 218EgrT9015757; Tue, 8 Feb 2022 18:00:17 GMT Received: from eur02-he1-obe.outbound.protection.outlook.com (mail-he1eur02lp2057.outbound.protection.outlook.com [104.47.5.57]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3e3t5xrs6q-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 18:00:17 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by VE1PR03MB5613.eurprd03.prod.outlook.com (2603:10a6:803:12a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19; Tue, 8 Feb 2022 18:00:13 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0%6]) with mapi id 15.20.4951.019; Tue, 8 Feb 2022 18:00:13 +0000 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: fa8cc221-8908-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n/yYMu60zNdIqp3sIYHiLLxW1iQ/mMJaFpQBJySVIVjKMjBnhzHxjm54TPOJnd3ZPmFVnNT76N4UT0svt+78YJmj+8RBxO9dJ9iRxFP3rKZIWIwr0uBbAjgGbgQEnd37bVP+WaeJBGSSN9NjjqVDdLwIuGkih7cKK3UIb2by1ffvKgOcdcJvosNLDc6WNkrq+d4GU9R8Stp+3T9fXUTk1FhqENNvfHHK11ns2z7p9ubXN08loLkXw/AuTMw2/pAoOEfpoaI+MSxxAv4xfwfYIMKz/cxjhUypAEgPf5hM2vML8ib/kPl7xvuBIqXaCYOCSVW61zA5lte23YDD64CBYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oz8ls5jYpEH0zZ1iaWsjgXWp+zE0wyLWSst1sUoOmY8=; b=kU5YxXUpypTXS2Y6t5ar77Tg26uMcyuIAgFQfI9W8hC5HFQwNyNJB45Em15meaaelKZrG3uVBzqFrRnaHVFkc6JXsrKtjyxe4HyvmO2p0LxqufrAMbjOidziZb2Aemg78/YvogTJOblW6e4F/5IvSs9Qdb8mac8NBm2CT178kM1PKmIQDG12u2QlZJFFhXMTQ3VZ/96m400SbMQ1ixhtC+qEcO9/EAkYuCGqIlAgOfsmfKOFo1Rg6aIyPKi3VCC+oa1pFfBheefWd4shlxO/o7f4moswcqGqJKx20oc5poYPh9y3z2YnjgP//+3nkUgTMVzThvu+IExB9ucFhXKYQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oz8ls5jYpEH0zZ1iaWsjgXWp+zE0wyLWSst1sUoOmY8=; b=X+MsHsSczOmM7yw5IvGR0V8nO1anPEWIiCIV7Pk5vJqCuWEb4Paj5n/pSUD9PCEsLr+td6iDfu3/Vqh8STpjLKvrUUuApSGjSkvRxmZNpuFuWJjtiFuTMA+zGwq9vwqzbI1y7epa6PHyxLVrvoNdAYqt5qJ95fFGV2AKfiN9RUdBn1gPojbefyuK+MJr15ZhIzGc6qsBAy0/mK/5CVWMhfOyBR7/jr+Mm+WsdUd+42TZ8UPTkKnmZKv2ZwmtENWrvMkuCGisz2dAn5aCi7+Je62gxalZoamRKuou1qbFqjMF4koZ5eCTJr4Y7PWOlPA28B76lpNYWfF+RWe2ibNHag== From: Oleksii Moisieiev To: "xen-devel@lists.xenproject.org" CC: Oleksii Moisieiev , Wei Liu , George Dunlap , Nick Rosbrook , Anthony PERARD , Juergen Gross Subject: [RFC v2 7/8] tools/arm: add "arm_sci" option to xl.cfg Thread-Topic: [RFC v2 7/8] tools/arm: add "arm_sci" option to xl.cfg Thread-Index: AQHYHRW421V3hDnhNU+uBIx9/PfKVg== Date: Tue, 8 Feb 2022 18:00:13 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7c86fd87-1051-4555-8660-08d9eb2cdb00 x-ms-traffictypediagnostic: VE1PR03MB5613:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: CbIDa937LpIp4Ccm27Vusw4GZKDrT1VrjSsF3RQDM2BjY7MwjS+hTBbgbwW427+OIA8V3T0TLGomFsNhBmOE4gMR+fYmdCO97nan4Lvh/eLS8Pgr7vckkrtlq0M7e17Tr9FI4uqXdMmGrQLhTQmSNlKi3LLrQ9A/t/lvSaY8eq/vu5hCldLpPAU1wXFOsS2LnCl/SdZj/l5vHdC/YJc5K4nOeZ1xVJtvlJIqZod+gLKyqlXh6Oa5VTf3sF92rhFyb9eqFouW7tgxvfD3P38DpSvhTTfYfaaZGKfOQaqkm7IX2oPm9DlhZ1DeDtqYcFZQheS8RfZF65bpLt4VzXJlJYCtNZTB+dbVmmhvQ6xmz4hQM0vmx6HJLShJ7rkxmvhVq6NH91L5XuqERMnrfa/WiFBAz1oUqCTUvuDYP2Cno4DK/b6mJTJWJxJcH176vHXO90za7nN7Lo8/QS/Wvy+J4urPlxFASzs6eALbmvZBmdkwz8F7JS0u0hfsL1BLfCQNCti+jJGAYrIQbEUdQYL3HrNkec1LyBfX1H6/iGHzFQr4IXrnnMSfN4enqnLI42kI5mMHK9+ykUx5b5qvhTtAtAIipaxrAJTF6xDutjsoVbdISpGJ4ohGCILMklzzSx0at3Qn6Ln+w36WWSbpvgSXt3Iqd5yDJjrJ/zl0G5dc4tINb49VV3A+V7Bu0gISPrDQCled6fkQ3iRUOyfF5mZvKQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38070700005)(71200400001)(6486002)(508600001)(66476007)(64756008)(86362001)(66556008)(316002)(122000001)(6916009)(6506007)(2616005)(5660300002)(6512007)(4326008)(83380400001)(54906003)(2906002)(26005)(186003)(8676002)(76116006)(38100700002)(66446008)(66946007)(8936002)(36756003)(91956017);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?TjbVxtzLqxZNS/MSNWTT5fj?= =?iso-8859-1?q?duI0TtmR5B4Yx3MNKLMIiNlZQx/wFlV6Z83PgzvMb6SS3dZlqTy8UrYuEh44?= =?iso-8859-1?q?zw91KPmwV9zn2Rqo+uw09rp3WijSC3jjZuBtMyTs2MQ+/dm0QM+K/+K91vuL?= =?iso-8859-1?q?P2yNzNxkVNiu6Y9RZwnuqiOORqaVQ88MpJ0f8ahMikD5FIhThq9uCDOebXFA?= =?iso-8859-1?q?Hb8DHLp6oiEx8jhHY0Ht8Bpvl0Ape5i1tNCWRDsbX+mX5M7gfwEkrCyQQ6sX?= =?iso-8859-1?q?XoKt12o/5qYZ5SNEv2ctMP/p2Odv8sntBB+jrRJkazT3Es3jsYJ56fY9rupK?= =?iso-8859-1?q?FWvSKSClHf9PiWjd4mjX4kXJk2fPECHxu9nm1PIQEHr4ELP6iLzJwJfMv3GC?= =?iso-8859-1?q?1wp2sMFzKO8hGiMUCKttWIdBByxnE9NoeX06l3YvQ6HRjtxPzq0iJDnaxav4?= =?iso-8859-1?q?q97xNN5lU8cpVZymExWcpQvjfpJ/dwkWRZyG0i7BRX5v24nR36bHLE63anmv?= =?iso-8859-1?q?sms2yWGb63lji2HyYB4W6kyLBLhoQ1Cw0UEMzPNAvN43N58B7ntSCcAjU5q6?= =?iso-8859-1?q?qyw3sDCjRRIygCzD2yK5vkk3IjYrVWbZX5AJmIhESOD4gxji0BHyQOZRsF8A?= =?iso-8859-1?q?cTLSITdDOJ18jl/VTG6C64eLlzict/mxDPUKwJGEAykwrT9lDNtJhsN9J4Un?= =?iso-8859-1?q?XMlLW/R+0SaO1NiwmYY6ZvkAXh/wLQVOaou0wqwIvf+TRKkmvVaCHrKQfOHa?= =?iso-8859-1?q?bYOUIkcmeolEEs4IoKK4ZS8QJ1Qnadoyu3HleJXXoPOCMq7ApxxYBuRzpZNj?= =?iso-8859-1?q?agX2bIs7CVrtvfgo59AfmKH2vs1ky6p9btOxhdtPqLKKAk4cgQK7mFdmlbPU?= =?iso-8859-1?q?hjX48pAozvcffU761QdfOrOvWGfIbWIwuTTqbZblxtyFXTshaBrVr1uTMUw5?= =?iso-8859-1?q?O0v5cXBFT0J5mN/0CS/y/qcRXQFg1vfdw2bcuK9eSPzq6TjCIRneZOP//SC0?= =?iso-8859-1?q?3IXuq7rPAJkaNJzLIMbklJPb6oJu3BrjgkJFJUg8XATuHnDwvDcpMbEoR+4B?= =?iso-8859-1?q?gFt5dQIggHPdOSGUhF7sydjV5V7LluD3EmIKQHFH3ZDmJPCwET5cq0qOSNFZ?= =?iso-8859-1?q?VWsJvfbytXRzFsJPN3xw8RUlY4pS9bWrgD8WnZQVephIT6SZulx6w/69t4qX?= =?iso-8859-1?q?YUVnYB2htQk6z6fl8ZY4J6mZDh0UX8X6zslto/XW3JYMYYf68/Vb6OZo3fBc?= =?iso-8859-1?q?eN6ojjRlTm5ZiSOFwCGEo64V4j/yYLNZQzFzCH/mks+vZG8D3K/IH/MUBVde?= =?iso-8859-1?q?MJk+29XGB9OWyg7WXIUkgDmVrDWKsCg4sASuvUmdF3FhAMQT3ug4qX3GUcJP?= =?iso-8859-1?q?uydvwPUkpZJMKazypFUFBNbF3qFKYI26jNrkKem2TRpf6eDF//auB+FLWG/k?= =?iso-8859-1?q?j9TjpmtsHrca7zkCdN+x4xTqPbvDX7S2jSa8JomiiNN7ttdUIATiRvjtLkuh?= =?iso-8859-1?q?5j95uwl5eKQ2nL153st4pW2Jg/9qSh2qeOpbWWinm9S4f3E9JiDcqM+CC103?= =?iso-8859-1?q?SxYkE+d1tvYTzjpgX1NMP5duGqZrLv14qUmvAoyWnIeHkT7foWOHVhf9z9aE?= =?iso-8859-1?q?QnToRAvcRW0a3mQbhWcOnqLKW+apnqJsHCwLQku1bfWo/HxjkAfizp2bSNd/?= =?iso-8859-1?q?elUhdrTj7fUAK1G3Jr0NnjWfua3BcHO6YPKkU+UsNdpK9AN/dtmzNGm7kL9K?= =?iso-8859-1?q?z4nY=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c86fd87-1051-4555-8660-08d9eb2cdb00 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Feb 2022 18:00:13.4188 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SWz4WbBiq1w8dOgLA0CkLEWHTc2hMe5VjUbHhGRJk/6+7HKr8dyrMXgh+RKMYbbF+gnvpHfKnW+Z2dSYO7WbzvT1x3y2Qt2vdpKI3vjaKzA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5613 X-Proofpoint-GUID: wz6TY2sipT9sV7lH3pXo29mw_x7eIvka X-Proofpoint-ORIG-GUID: wz6TY2sipT9sV7lH3pXo29mw_x7eIvka X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_06,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080106 This enumeration sets SCI type for the domain. Currently there is two possible options: either 'none' or 'scmi_smc'. 'none' is the default value and it disables SCI support at all. 'scmi_smc' enables access to the Firmware from the domains using SCMI protocol and SMC as transport. Signed-off-by: Oleksii Moisieiev --- docs/man/xl.cfg.5.pod.in | 20 ++++++++++++++++++++ tools/golang/xenlight/helpers.gen.go | 2 ++ tools/golang/xenlight/types.gen.go | 7 +++++++ tools/include/libxl.h | 5 +++++ tools/libs/light/libxl_types.idl | 6 ++++++ tools/xl/xl_parse.c | 9 +++++++++ 6 files changed, 49 insertions(+) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index ddf82cb3bc..f960e367c4 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1614,8 +1614,28 @@ This feature is a B. =back +=item B + +B Set ARM_SCI type for the guest. ARM_SCI is System Control Protocol +allows domain to manage various functions that are provided by HW platform. + =over 4 +=item B + +Don't allow guest to use ARM_SCI if present on the platform. This is the +default value. + +=item B + +Enables SCMI_SMC support for the guest. SCMI is System Control Management +Inferface - allows domain to manage various functions that are provided by HW +platform, such as clocks, resets and power-domains. Xen will mediate access to +clocks, power-domains and resets between Domains and ATF. Disabled by default. +SCP is used as transport. + +=back + =item B If set, Xen allows to assign a devices even if it is not behind an IOMMU. diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index 664933bbb8..6cf7725735 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1091,6 +1091,7 @@ if err := x.DmRestrict.fromC(&xc.dm_restrict);err != nil { return fmt.Errorf("converting field DmRestrict: %v", err) } x.Tee = TeeType(xc.tee) +x.ArmSci = ArmSciType(xc.arm_sci) if err := x.ForceAssignWithoutIommu.fromC(&xc.force_assign_without_iommu);err != nil { return fmt.Errorf("converting field ForceAssignWithoutIommu: %v", err) @@ -1439,6 +1440,7 @@ if err := x.DmRestrict.toC(&xc.dm_restrict); err != nil { return fmt.Errorf("converting field DmRestrict: %v", err) } xc.tee = C.libxl_tee_type(x.Tee) +xc.arm_sci = C.libxl_arm_sci_type(x.ArmSci) xc._type = C.libxl_domain_type(x.Type) switch x.Type{ case DomainTypeHvm: diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/types.gen.go index 2f7a088c3b..3b5c959215 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -443,6 +443,12 @@ TeeTypeNone TeeType = 0 TeeTypeOptee TeeType = 1 ) +type ArmSciType int +const( +ArmSciTypeNone ArmSciType = 0 +ArmSciTypeScmi ArmSciType = 1 +) + type RdmReserve struct { Strategy RdmReserveStrategy Policy RdmReservePolicy @@ -512,6 +518,7 @@ NestedHvm Defbool Apic Defbool DmRestrict Defbool Tee TeeType +ArmSci ArmSciType ForceAssignWithoutIommu Defbool Type DomainType TypeUnion DomainBuildInfoTypeUnion diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 2bbbd21f0b..30e5aee119 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -278,6 +278,11 @@ */ #define LIBXL_HAVE_BUILDINFO_ARCH_ARM_TEE 1 +/* + * libxl_domain_build_info has the arch_arm.sci field. + */ +#define LIBXL_HAVE_BUILDINFO_ARCH_ARM_SCI 1 + /* * LIBXL_HAVE_SOFT_RESET indicates that libxl supports performing * 'soft reset' for domains and there is 'soft_reset' shutdown reason diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl index 1080966c33..1878c115c3 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -480,6 +480,11 @@ libxl_tee_type = Enumeration("tee_type", [ (1, "optee") ], init_val = "LIBXL_TEE_TYPE_NONE") +libxl_arm_sci_type = Enumeration("arm_sci_type", [ + (0, "none"), + (1, "scmi_smc") + ], init_val = "LIBXL_ARM_SCI_TYPE_NONE") + libxl_rdm_reserve = Struct("rdm_reserve", [ ("strategy", libxl_rdm_reserve_strategy), ("policy", libxl_rdm_reserve_policy), @@ -564,6 +569,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("apic", libxl_defbool), ("dm_restrict", libxl_defbool), ("tee", libxl_tee_type), + ("arm_sci", libxl_arm_sci_type), ("force_assign_without_iommu", libxl_defbool), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 67fa96d949..d53c9b1271 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2747,6 +2747,15 @@ skip_usbdev: } } + if (!xlu_cfg_get_string (config, "arm_sci", &buf, 1)) { + e = libxl_arm_sci_type_from_string(buf, &b_info->arm_sci); + if (e) { + fprintf(stderr, + "Unknown arm_sci \"%s\" specified\n", buf); + exit(-ERROR_FAIL); + } + } + xlu_cfg_get_defbool(config, "force_assign_without_iommu", &b_info->force_assign_without_iommu, 0); From patchwork Tue Feb 8 18:00:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 12739152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E41FC433FE for ; Tue, 8 Feb 2022 18:00:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.268499.462415 (Exim 4.92) (envelope-from ) id 1nHUmz-0008Aq-5t; Tue, 08 Feb 2022 18:00:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 268499.462415; Tue, 08 Feb 2022 18:00:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nHUmy-00089X-Ol; Tue, 08 Feb 2022 18:00:28 +0000 Received: by outflank-mailman (input) for mailman id 268499; Tue, 08 Feb 2022 18:00:26 +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 1nHUmw-00068L-7U for xen-devel@lists.xenproject.org; Tue, 08 Feb 2022 18:00:26 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fce3a86e-8908-11ec-8eb8-a37418f5ba1a; Tue, 08 Feb 2022 19:00:24 +0100 (CET) Received: from pps.filterd (m0174678.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 218EgrTD015757; Tue, 8 Feb 2022 18:00:21 GMT Received: from eur02-he1-obe.outbound.protection.outlook.com (mail-he1eur02lp2057.outbound.protection.outlook.com [104.47.5.57]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3e3t5xrs6q-12 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 08 Feb 2022 18:00:21 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by VE1PR03MB5613.eurprd03.prod.outlook.com (2603:10a6:803:12a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19; Tue, 8 Feb 2022 18:00:14 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::c1c:f98:9dd:86e0%6]) with mapi id 15.20.4951.019; Tue, 8 Feb 2022 18:00:14 +0000 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: fce3a86e-8908-11ec-8eb8-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SYO9MKfe3IgWmXp7lo+Bl4ljmMGi1ae0L+UWUR0qgoRpJaNT7rSRNjgXUvM+ryHMd0aUQ5tSg8M+jTHvnwuWWIdO2It7fMXrYmRMIp60U2nJlHsiruGdC70p2Z8E2WvYgA6iRhpk+gzdPuZsLvFZZTtF8nUiSn4cE54I5NCgH5VwzrmBCvca65BsMp+SuU5/j6Au3YrRv0JfynDFvxk/eh/WjsJ2dG/QvyLZIjsqG3YORnYoxNxDQUAFYEJ/t4R7Vu2RCqMdFNwBoRkmF9EyGRL/3/bItFEGhWiAL/zyWdbIG358Jp9ZozEeg/NuwdGVlse5suyRG581NEIC/f7t5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jayupWuWbjhOz7yWgZER6E30JTnHsZKWIQYO2oKaWWE=; b=bH+qApmhRzaaPMNJqomFxCloTOyKpsTwMCjgekox1CZpv83ogBXgTHBDGWtb0Ld1zZDCaTPZ4AbKW6C87DBxvi9bI84IiwzgZ53o5mit3cjQjYrm7LjQCiQ4Ogg1bp8ZqJi4PMgnEYcOErksjNFQ54I0i1vXbUS07dyxD7bfQBqs7kwOVzKLEj3V6qZq6aWjmBhmiA7YeMe8vkBXb4M4C8wleEWSUR5bi+qQMTHpfT1BZv8ek9fxIsBAWmU6gnwyNYEY50fTOJHS/Shg+Gh0tddW9rClAfJdIeCj1yOuDb5vz18xVIhNrHqXbFvuhrc9bCfBQs4UhBFTBxmPDb25pw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jayupWuWbjhOz7yWgZER6E30JTnHsZKWIQYO2oKaWWE=; b=SQ1KDkkWJX3kuq861ElC+WSGwMK7a6K9OsAr9YIq2ojajYWjVRCCD6OTyt4zpGrBGV3pV1Un14Ui5RS6coscRW4zBBjBABw9ddEE/KDqvnt2l/xOOn8/8gpYAELttIHcDzzN03wRGYZ0pGNK6awLhz9BTgYAfRWA1FvUTlyRZBAbKkUOQ87Nf03QPBgipuokh+EmDJ27TKfnmAOLQEgMRsTAM5mp+VyhmGXixwyCJIXhN31Vk+Buke8qCkrNaf/jykHKkubicVgppXgivFKrBDyoZxuZTu5XIm84x3tss9LPewENFhkJT6e7y6/Ki6OQWsgo+fDbcfHAe1pqsOIveA== From: Oleksii Moisieiev To: "xen-devel@lists.xenproject.org" CC: Oleksii Moisieiev , Wei Liu , Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Anthony PERARD , Volodymyr Babchuk , Bertrand Marquis Subject: [RFC v2 8/8] xen/arm: add SCI mediator support for DomUs Thread-Topic: [RFC v2 8/8] xen/arm: add SCI mediator support for DomUs Thread-Index: AQHYHRW5DNy0UeL9wEisMLPQvzYWsg== Date: Tue, 8 Feb 2022 18:00:14 +0000 Message-ID: <8aaab52f54841ebcf31a8f5fc6f1f8fd0b778e49.1644341635.git.oleksii_moisieiev@epam.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1d8aa3d6-94a8-4c12-78de-08d9eb2cdbd2 x-ms-traffictypediagnostic: VE1PR03MB5613:EE_ x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:538; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: rqxqne92tNVg0gXi1RQ1NO7eQOSv0cZvEyQLrHBW9kvSdYIC9sC5usBbMqoaUOMHYXnIChGrP+Z/YOGYqZSnIJTvlhoqtlp8r5QM+af1SG63r5aiCo1xGMTWOmreJsUj/+a/6RaEw8OCAqfhRCNRv2OQSdhrLux3S0K9365kjWktmT8ZbrVLNTfwnU3XGajHMFUV1BEID+Y2pxTRgl9OAmuGOHuBgJqhAJRqogQ7I2gHAmA3ptmhAD+5CgvGh88GWFno+tE7YlImDxEWah1hV0w0Omj3DaDC00JYTYpkDqn6HhzrvokzfwL2t8zrml7yy2DQXGwM3LwxNGe96NIntdifnsdDCCzJ4BERLjjouamm2idzO42yRcx90SPMETs9zFrhGBtMTQKtgoPyMVpCccYuBHPlJxg9ELJqsRcEGsHLG6K25aHXp9BOWDg5QuRzur+E5N5WA329PEpkWwJSo1ZoUJ3xY/uoC4MpCm+oeQDzbuPG3QzDOK0y3s3gdelU8V5tv7gDlptP39BQ4Rz57oQ+Kghg0j6K3q/z3y/5uQ5XPaEkSXz+HxoQz5yjONOt94jkZ3ajIcPAMn4EXfLVjMoSpX6+Sm3xfZRYlhT5QvpLa0Ha8Ag2wf84dDytbT+2DcdENjeTG5I1LZs7V54DDfN6zwY6N5Nq2kOO7cPtWY5kKUjyRZd2iwl5Paj38QmEVzgFliEhzHMHc9poEKV8/Q== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38070700005)(71200400001)(6486002)(508600001)(66476007)(64756008)(86362001)(66556008)(316002)(122000001)(6916009)(6506007)(2616005)(5660300002)(6512007)(7416002)(4326008)(83380400001)(54906003)(30864003)(2906002)(26005)(186003)(8676002)(76116006)(38100700002)(66446008)(66946007)(8936002)(36756003)(91956017);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?Bb/o0zHOWJ4lAaakLRPPxRO?= =?iso-8859-1?q?rgldRXBN4eTiPjo7EFECHkHlUv7I2bquMf4RHIj+oA3bvv7OVD6Z/eKzuHwT?= =?iso-8859-1?q?dmaOaLGdT+G8moFqV/zHH5SbSMr3oEoGPa0qoq+kRYbA+mETGE/MScrGaX3V?= =?iso-8859-1?q?/KPraHR0cetjYVUQv8t/llDXuUs4hGwJQR4J+ybvPDB/ayJkcONjs1sRRerH?= =?iso-8859-1?q?cxcdHCWoDrdufIAN5gdoqnovhhMFSxiIAJ8NBu5U9p+zV3CDH9WZwSkt8uao?= =?iso-8859-1?q?yNALUsgVTJ9kafXiSEoIveQV6EQ5S3h7UvVC9UsUw1hYOtr71nLQbd1Ri1Zo?= =?iso-8859-1?q?IXiuxZujZvBDnBTy+z8mtrx7gVtbnqjvj8V2tZ3KWFpH56xuqxvyPqoK7YZQ?= =?iso-8859-1?q?hCAv4uGLhjNWXebO16pEquZa/zhfOpYY5hFC3IQsQd2sYoYyiQ2XGSSMBtqR?= =?iso-8859-1?q?qUL4FTQ4XQy5yhRVZcWbVlrGcaCagkE5GK7R+pDC7LuED6OSXde0xpVAfdKP?= =?iso-8859-1?q?arxIgytJsXpTeL1SQgUc67E+MDAPJRol0v2KU2bsH7vt6pjieS/XXVpvOSY2?= =?iso-8859-1?q?plf+yRi3H1wd983YBIR1uAxAnIv/hN/AnIdIn1BauRERwnQYSuLCJU45+/ZY?= =?iso-8859-1?q?B2jvnca5XB4m7o4jfRBTwt/98C14/u0tVZp3nH11fnqdCUZCrHWCfohvPD5N?= =?iso-8859-1?q?J9JqDIF535T79ycsAdV38Zu2NfmKxTCCWiT7q/EAQU7FeM2QR+QlBebNhdbo?= =?iso-8859-1?q?XObypNi8X7Ld/GoLGXpgT5mdYxFjaQWRWW5WpnQgeHDmZWWooBZunk+beXWo?= =?iso-8859-1?q?XoSgoZ4qgkwj8U4VKIbA45w5HDU67/v0utBaekfV4W5MkJqik8d7xXMpxw/a?= =?iso-8859-1?q?9WDxGPRfwvt1cM2ETs7GuFIO0A+qyQQ+wdnzSNUtkQpXYY49ji6C9CGxPthT?= =?iso-8859-1?q?BXb3tTEnu7UpMygcbyuXJWGdu9dJL5NZBXWZF5uXcpIJkrTSmnNyWWLFH0u/?= =?iso-8859-1?q?hBtxFg2PFIAM0ftVJSpc2kfbv/y3K2jYZMZJRJitn7FDF8GOD2dWsVm0o9ov?= =?iso-8859-1?q?J7zUHjcMFbSf2Gc5pl+t+1dShYxUia4Ja84r3LlUljHx7LzAa1E2AiUEKxWy?= =?iso-8859-1?q?fVtLj1etsCcD2YhVEuecIaRt0+Ao3aGt49APiSOyYCh8K5EIKJ+h8KO8ytbq?= =?iso-8859-1?q?3TWy15iKGSO/Swt+z7D0U/ON5t5eCJYHDFkFi4X8BgcIhnYYJXgFNudWq1vn?= =?iso-8859-1?q?N9mdhdxFAXshIsZ0L7nrlpbiKn+x2iOnf3GgH3QMbdNdvANQtgnKl+2BZMhi?= =?iso-8859-1?q?TiWNHfOcL1lod4Gcey1TUEt8EE41g2ORe+SQCEhB3ywL9+ml61Ymfh3O5im8?= =?iso-8859-1?q?6xH+J2DdyXgTMebsxlEyiNDuJYu+64iY9jr6CXVRnHoGeb+KFGDdjBJiFSQJ?= =?iso-8859-1?q?kmuxRnnCaWFEtykHY9Cyn2fbXtvih54jJ4wVWHuiELNIDfTYrw+4Jlik2wwZ?= =?iso-8859-1?q?sEWR+13TZysjbbuiqSu+A5n4hTDqZtZdlyG+65WrpEEvRGNr+71Rvlvi5m5W?= =?iso-8859-1?q?WXtDlKZydZip+goQB0EnMGm639cGxRoQJJjqzI0EexcG3yUkVJerzh5Q1m9U?= =?iso-8859-1?q?XC48/tuOKRq4uKCRMx89J5W95bx/DHy/coIGQ40+lPZMnFGc3MEfInrpdP6F?= =?iso-8859-1?q?tmKRPkwS1wIyy62IGwJTP+KqhOSTm6SQ3vN7VvHuLFoSlulh/JzWYEgreF8c?= =?iso-8859-1?q?aZ5k=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d8aa3d6-94a8-4c12-78de-08d9eb2cdbd2 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Feb 2022 18:00:14.7791 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +r2E2QNZzlRK0MqL9DH03hTokkOFLMJtHCnQo2oVW6lsQyVQyOFTMrOHzsqjPm2whFJIbDef/fL2Md+FQIPYWX4VR8MFAYVVVaFZkR3WVyU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5613 X-Proofpoint-GUID: rMgEuywUpIi_Qn8ShMUDtOToY64rSaIr X-Proofpoint-ORIG-GUID: rMgEuywUpIi_Qn8ShMUDtOToY64rSaIr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-08_06,2022-02-07_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202080106 Integration of the SCMI mediator with xen libs: - add hypercalls to aquire SCI channel and set device permissions for DomUs; - add SCMI_SMC nodes to DomUs device-tree based on partial device-tree; - SCI requests redirection from DomUs to Firmware. Signed-off-by: Oleksii Moisieiev --- tools/include/xenctrl.h | 3 + tools/libs/light/libxl_arm.c | 214 ++++++++++++++++++++++++-- tools/libs/light/libxl_create.c | 44 +++++- tools/libs/light/libxl_internal.h | 3 + xen/arch/arm/domctl.c | 7 + xen/include/public/device_tree_defs.h | 1 + 6 files changed, 260 insertions(+), 12 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 07b96e6671..cdd14f465f 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1238,6 +1238,9 @@ int xc_domain_getvnuma(xc_interface *xch, int xc_domain_soft_reset(xc_interface *xch, uint32_t domid); +int xc_domain_add_sci_device(xc_interface *xch, + uint32_t domid, char *path); + #if defined(__i386__) || defined(__x86_64__) /* * PC BIOS standard E820 types and structure. diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index c5090e2b32..106ff33c84 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -7,6 +7,12 @@ #include #include #include +#include + +#define SCMI_NODE_PATH "/firmware/scmi" +#define SCMI_NODE_COMPATIBLE "arm,scmi-smc" +#define SCMI_SHMEM_COMPATIBLE "arm,scmi-shmem" +#define HYPFS_DEVICETREE_PATH "/devicetree" static const char *gicv_to_string(libxl_gic_version gic_version) { @@ -101,6 +107,19 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, return ERROR_FAIL; } + switch (d_config->b_info.arm_sci) { + case LIBXL_ARM_SCI_TYPE_NONE: + config->arch.arm_sci_type = XEN_DOMCTL_CONFIG_ARM_SCI_NONE; + break; + case LIBXL_ARM_SCI_TYPE_SCMI_SMC: + config->arch.arm_sci_type = XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC; + break; + default: + LOG(ERROR, "Unknown ARM_SCI type %d", + d_config->b_info.arm_sci); + return ERROR_FAIL; + } + if (libxl_defbool_val(d_config->b_info.force_assign_without_iommu)) config->iommu_opts |= XEN_DOMCTL_IOMMU_force_iommu; @@ -125,6 +144,7 @@ int libxl__arch_domain_save_config(libxl__gc *gc, } state->clock_frequency = config->arch.clock_frequency; + state->arm_sci_agent_paddr = config->arch.arm_sci_agent_paddr; return 0; } @@ -505,9 +525,6 @@ static int make_optee_node(libxl__gc *gc, void *fdt) int res; LOG(DEBUG, "Creating OP-TEE node in dtb"); - res = fdt_begin_node(fdt, "firmware"); - if (res) return res; - res = fdt_begin_node(fdt, "optee"); if (res) return res; @@ -520,9 +537,6 @@ static int make_optee_node(libxl__gc *gc, void *fdt) res = fdt_end_node(fdt); if (res) return res; - res = fdt_end_node(fdt); - if (res) return res; - return 0; } @@ -905,10 +919,9 @@ static int copy_node(libxl__gc *gc, void *fdt, void *pfdt, return 0; } -static int copy_node_by_path(libxl__gc *gc, const char *path, - void *fdt, void *pfdt) +static int get_path_nodeoff(const char *path, void *pfdt) { - int nodeoff, r; + int nodeoff; const char *name = strrchr(path, '/'); if (!name) @@ -928,12 +941,189 @@ static int copy_node_by_path(libxl__gc *gc, const char *path, if (strcmp(fdt_get_name(pfdt, nodeoff, NULL), name)) return -FDT_ERR_NOTFOUND; + return nodeoff; +} + +static int copy_node_by_path(libxl__gc *gc, const char *path, + void *fdt, void *pfdt) +{ + int nodeoff, r; + + nodeoff = get_path_nodeoff(path, pfdt); + if (nodeoff < 0) + return nodeoff; + r = copy_node(gc, fdt, pfdt, nodeoff, 0); if (r) return r; return 0; } +static int make_scmi_shmem_node(libxl__gc *gc, void *fdt, void *pfdt) +{ + int res; + char buf[64]; + +#ifdef CONFIG_ARM_32 + snprintf(buf, sizeof(buf), "scp-shmem@%lx", + GUEST_SCI_SHMEM_BASE); +#else + snprintf(buf, sizeof(buf), "scp-shmem@%llx", + GUEST_SCI_SHMEM_BASE); +#endif + + res = fdt_begin_node(fdt, buf); + if (res) return res; + + res = fdt_property_compat(gc, fdt, 1, SCMI_SHMEM_COMPATIBLE); + if (res) return res; + + res = fdt_property_regs(gc, fdt, GUEST_ROOT_ADDRESS_CELLS, + GUEST_ROOT_SIZE_CELLS, 1, + GUEST_SCI_SHMEM_BASE, GUEST_SCI_SHMEM_SIZE); + if (res) return res; + + res = fdt_property_cell(fdt, "phandle", GUEST_PHANDLE_SCMI); + if (res) return res; + + res = fdt_end_node(fdt); + if (res) return res; + + return 0; +} + +static int create_hypfs_property(struct xenhypfs_handle *hdl, void *fdt, + char *path, char *name) +{ + char *p, *result; + int ret = 0; + struct xenhypfs_dirent *ent; + + if (strcmp(name, "shmem") == 0) + return fdt_property_cell(fdt, name, GUEST_PHANDLE_SCMI); + + ret = asprintf(&p, "%s%s", HYPFS_DEVICETREE_PATH, path); + result = xenhypfs_read_raw(hdl, p, &ent); + free(p); + if (!result) + return -EINVAL; + + ret = fdt_property(fdt, name, result, ent->size); + free(result); + free(ent); + + return ret; +} +static int create_hypfs_subnode(struct xenhypfs_handle *hdl, void *fdt, + const char *path, const char *name) +{ + struct xenhypfs_dirent *ent; + unsigned int n, i; + char *p, *p_sub; + int res = 0; + + res = asprintf(&p, "%s%s", HYPFS_DEVICETREE_PATH, path); + if (res < 0) + return -ENOMEM; + + ent = xenhypfs_readdir(hdl, p, &n); + free(p); + if (!ent) + return -EINVAL; + + res = fdt_begin_node(fdt, name); + if (res) return res; + + for (i = 0; i < n; i++) { + res = asprintf(&p_sub,"%s/%s", path, ent[i].name); + if (res < 0) + break; + + if (ent[i].type == xenhypfs_type_dir) + res = create_hypfs_subnode(hdl, fdt, p_sub, ent[i].name); + else + res = create_hypfs_property(hdl, fdt, p_sub, ent[i].name); + + free(p_sub); + if (res) + break; + } + + res = fdt_end_node(fdt); + free(ent); + return res; +} + +static int create_scmi_from_hypfs(void *fdt, const char *path) +{ + struct xenhypfs_handle *hdl; + int res; + hdl = xenhypfs_open(NULL, 0); + if (!hdl) + return -EINVAL; + + res = create_hypfs_subnode(hdl, fdt, path, "scmi"); + xenhypfs_close(hdl); + + return res; +} + +static int set_shmem_phandle(void *fdt, const char *scmi_node_copmat) +{ + uint32_t val; + int nodeoff = fdt_node_offset_by_compatible(fdt, 0, scmi_node_copmat); + if (nodeoff < 0) + return -EINVAL; + + val = cpu_to_fdt32(GUEST_PHANDLE_SCMI); + return fdt_setprop_inplace(fdt, nodeoff, "shmem", &val, sizeof(val)); +} + +static int make_scmi_node(libxl__gc *gc, void *fdt, void *pfdt) +{ + int res = 0; + int nodeoff = + fdt_node_offset_by_compatible(pfdt, 0, SCMI_NODE_COMPATIBLE); + if (nodeoff > 0) { + res = copy_node(gc, fdt, pfdt, nodeoff, 0); + if (res) return res; + + res = set_shmem_phandle(fdt, SCMI_NODE_COMPATIBLE); + if (res) return res; + } + else + res = create_scmi_from_hypfs(fdt, SCMI_NODE_PATH); + + return res; +} + +static int make_firmware_node(libxl__gc *gc, void *fdt, void *pfdt, int tee, + int sci) +{ + int res; + + if ((tee == LIBXL_TEE_TYPE_NONE) && (sci == LIBXL_ARM_SCI_TYPE_NONE)) + return 0; + + res = fdt_begin_node(fdt, "firmware"); + if (res) return res; + + if (tee == LIBXL_TEE_TYPE_OPTEE) { + res = make_optee_node(gc, fdt); + if (res) return res; + } + + if (sci == LIBXL_ARM_SCI_TYPE_SCMI_SMC) { + res = make_scmi_node(gc, fdt, pfdt); + if (res) return res; + } + + res = fdt_end_node(fdt); + if (res) return res; + + return 0; +} + /* * The partial device tree is not copied entirely. Only the relevant bits are * copied to the guest device tree: @@ -1091,8 +1281,10 @@ next_resize: if (info->arch_arm.vuart == LIBXL_VUART_TYPE_SBSA_UART) FDT( make_vpl011_uart_node(gc, fdt, ainfo, dom) ); - if (info->tee == LIBXL_TEE_TYPE_OPTEE) - FDT( make_optee_node(gc, fdt) ); + if (info->arm_sci == LIBXL_ARM_SCI_TYPE_SCMI_SMC) + FDT( make_scmi_shmem_node(gc, fdt, pfdt) ); + + FDT( make_firmware_node(gc, fdt, pfdt, info->tee, info->arm_sci) ); if (d_config->num_pcidevs) FDT( make_vpci_node(gc, fdt, ainfo, dom) ); diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c index dcd09d32ba..f1f1e66275 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -596,6 +596,38 @@ out: return ret; } +static int map_sci_page(libxl__gc *gc, uint32_t domid, uint64_t paddr, + uint64_t guest_addr) +{ + int ret; + uint64_t _paddr_pfn = paddr >> XC_PAGE_SHIFT; + uint64_t _guest_pfn = guest_addr >> XC_PAGE_SHIFT; + + assert(paddr && guest_addr); + LOG(DEBUG, "iomem %"PRIx64, _paddr_pfn); + + ret = xc_domain_iomem_permission(CTX->xch, domid, _paddr_pfn, 1, 1); + if (ret < 0) { + LOG(ERROR, + "failed give domain access to iomem page %"PRIx64, + _paddr_pfn); + return ret; + } + + ret = xc_domain_memory_mapping(CTX->xch, domid, + _guest_pfn, _paddr_pfn, + 1, 1); + if (ret < 0) { + LOG(ERROR, + "failed to map to domain iomem page %"PRIx64 + " to guest address %"PRIx64, + _paddr_pfn, _guest_pfn); + return ret; + } + + return 0; +} + int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, libxl__domain_build_state *state, uint32_t *domid, bool soft_reset) @@ -762,6 +794,16 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, goto out; } + if (d_config->b_info.arm_sci == LIBXL_ARM_SCI_TYPE_SCMI_SMC) { + ret = map_sci_page(gc, *domid, state->arm_sci_agent_paddr, + GUEST_SCI_SHMEM_BASE); + if (ret < 0) { + LOGED(ERROR, *domid, "map scmi fail"); + rc = ERROR_FAIL; + goto out; + } + } + dom_path = libxl__xs_get_dompath(gc, *domid); if (!dom_path) { rc = ERROR_FAIL; @@ -1825,7 +1867,7 @@ static void libxl__add_dtdevs(libxl__egc *egc, libxl__ao *ao, uint32_t domid, LOGD(DEBUG, domid, "Assign device \"%s\" to domain", dtdev->path); rc = xc_assign_dt_device(CTX->xch, domid, dtdev->path); if (rc < 0) { - LOGD(ERROR, domid, "xc_assign_dtdevice failed: %d", rc); + LOGD(ERROR, domid, "xc_assign_dt_device failed: %d", rc); goto out; } } diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index 0b4671318c..79f38b60d4 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -1407,6 +1407,9 @@ typedef struct { /* Whether this domain is being migrated/restored, or booting fresh. Only * applicable to the primary domain, not support domains (e.g. stub QEMU). */ bool restore; + + /* arm_sci channel paddr to be set to device-tree node */ + uint64_t arm_sci_agent_paddr; } libxl__domain_build_state; _hidden void libxl__domain_build_state_init(libxl__domain_build_state *s); diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index 6245af6d0b..23c44f3a13 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -4,6 +4,7 @@ * Copyright (c) 2012, Citrix Systems */ +#include #include #include #include @@ -182,7 +183,13 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, rc = subarch_do_domctl(domctl, d, u_domctl); if ( rc == -ENOSYS ) + { rc = iommu_do_domctl(domctl, d, u_domctl); + if ( (rc) && (rc != -ENOSYS) ) + return rc; + + rc = sci_do_domctl(domctl, d, u_domctl); + } return rc; } diff --git a/xen/include/public/device_tree_defs.h b/xen/include/public/device_tree_defs.h index 209d43de3f..f57684547b 100644 --- a/xen/include/public/device_tree_defs.h +++ b/xen/include/public/device_tree_defs.h @@ -7,6 +7,7 @@ * onwards. Reserve a high value for the GIC phandle. */ #define GUEST_PHANDLE_GIC (65000) +#define GUEST_PHANDLE_SCMI (67000) #define GUEST_ROOT_ADDRESS_CELLS 2 #define GUEST_ROOT_SIZE_CELLS 2