From nobody Sun May 12 07:37:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1667906682; cv=none; d=zohomail.com; s=zohoarc; b=dunf4C4h3P0ev15NLmxWJRV6gJiYOH4ozXhM+x0LnG+EqmQ+vfsyaq8cWVOD1gMLOoskKwHFJq1c1BAjtqoUMRQQB89rl/o5W/myqPQJr7xDMioU3ff+T++XofnXBZSrR2+9tqk9bS9+94Nj2nRE3h3e6iSrbNY0XzSOFb1R9+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667906682; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yWwLVsCfFGrMeQAxaHGExsLxmZy4kqtiAA8c8/+74wg=; b=MRhFmzHxecbyr5kWkDGm1oN8aMa6vNcTk63ejE6QyhPy7znzZyZdEYK7ejjcj9RPHR75Q2shV5Y/UaEEVk4iNxhoN6jgtqwpYC1Xew19BvCTYc1KrC6L32oegOHga/JIcf/C6jkyZOdKvAHXMUfBT9v757WrHgGf8bAHfSoUOKE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667906682531611.8271344991086; Tue, 8 Nov 2022 03:24:42 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.439975.694018 (Exim 4.92) (envelope-from ) id 1osMiM-0006jO-Gu; Tue, 08 Nov 2022 11:24:22 +0000 Received: by outflank-mailman (output) from mailman id 439975.694018; Tue, 08 Nov 2022 11:24:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1osMiM-0006jH-E3; Tue, 08 Nov 2022 11:24:22 +0000 Received: by outflank-mailman (input) for mailman id 439975; Tue, 08 Nov 2022 11:24:21 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1osMiK-0006iF-UF for xen-devel@lists.xen.org; Tue, 08 Nov 2022 11:24:21 +0000 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [2607:f8b0:4864:20::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e2817fa5-5f57-11ed-91b5-6bf2151ebd3b; Tue, 08 Nov 2022 12:24:19 +0100 (CET) Received: by mail-pl1-x62e.google.com with SMTP id g24so13914244plq.3 for ; Tue, 08 Nov 2022 03:24:19 -0800 (PST) Received: from localhost ([122.172.84.80]) by smtp.gmail.com with ESMTPSA id k26-20020aa7973a000000b0056da2ad6503sm6189458pfg.39.2022.11.08.03.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 03:24:17 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e2817fa5-5f57-11ed-91b5-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yWwLVsCfFGrMeQAxaHGExsLxmZy4kqtiAA8c8/+74wg=; b=dXWHyLAcc3S4YeQjOK/o9jRLk8+0FaUhy4e1P73qU9oEvps0On1zaJaLiyRhrvzJy+ NEzOSt3ZuUSJjki+Y/kt6VAzAGSy15HTF4WdWvGu2c5WD/GmdiEzBhmng80v3VF0NzJO jVrdopY9He9wQiFGm1yu4N9mjtzPzlMBZ9CmRIGTgRu+E6wTSz1jaAcTs7yHYqFlUm0r kGuLwo+aUcur1xH2GrUvTGVvWC5ZGiuBAtObQEUcV527s1T8dSow5GyRPhWvqDp5+WH6 Eip1xKkLxXOm93eQjniMsW8c9+H+WHCwI1gs9kWy+aVDGgp0XpgU/4PKbjmKmOqGw9ww YqLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yWwLVsCfFGrMeQAxaHGExsLxmZy4kqtiAA8c8/+74wg=; b=uiPQ6Gc/vNI3RCSx3hw1aZ2kyZMTrPAmd0cKVaeQ8sBMUGmrOPE8Os1E9+gVEzVAWs eI4zRggcIHrE24AvvBYsiuFyhKcZ3vE2w+qLcopyLiXpa0bharcKbDiK5ELsrbsAJj4W 14Az5kTxN5oYslrMO9DlvmGNtT8E4jcA/YVt9pNj5Nnj1Eu7BqHGUEQGR+CizKoWngIf J1+emLTk3twi9mLduyb1b+TTQSwrcbgTV1wNUseeYiN9NSdnEc6xTmnULjMOEjpeHCkz IkWwgIRLz0WwimxULytD0oPBGukTkYxPTxTmCXRN5jjCqKXYzUWRtyw/tocv02TwGh97 TmGw== X-Gm-Message-State: ACrzQf3xHLoq4zLaR1Skal5US947ZcEo/rRd9z8SH3R/M8WkzUqYkwS+ 6Ni1PZ2WQ2ljK9mMPD8hWSgnxXOxyuo9rA== X-Google-Smtp-Source: AMsMyM4pOZa7NXejO3RVIXXQdy76dSHf4MToE6NUCw4xUtbvccbhkrfxnzyXZhJEbNmiZ1OrXKfMlA== X-Received: by 2002:a17:90b:38ca:b0:214:2cff:fbb5 with SMTP id nn10-20020a17090b38ca00b002142cfffbb5mr34811900pjb.79.1667906657905; Tue, 08 Nov 2022 03:24:17 -0800 (PST) From: Viresh Kumar To: xen-devel@lists.xen.org, Juergen Gross , Julien Grall , Anthony PERARD Cc: Viresh Kumar , Vincent Guittot , stratos-dev@op-lists.linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Stefano Stabellini , Mathieu Poirier , Mike Holmes , Oleksandr Tyshchenko , Wei Liu Subject: [PATCH V6 1/3] libxl: Add support for generic virtio device Date: Tue, 8 Nov 2022 16:53:58 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1667906683684100001 Content-Type: text/plain; charset="utf-8" This patch adds basic support for configuring and assisting generic Virtio backend which could run in any domain. An example of domain configuration for mmio based Virtio I2C device is: virtio =3D ["type=3Dvirtio,device22,transport=3Dmmio"] Also to make this work on Arm, allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend. Update guest device-tree as well to create a DT node for the Virtio devices. Signed-off-by: Viresh Kumar --- tools/libs/light/Makefile | 1 + tools/libs/light/libxl_arm.c | 89 +++++++++++++++ tools/libs/light/libxl_create.c | 5 + tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 29 +++++ tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_virtio.c | 127 ++++++++++++++++++++++ 7 files changed, 253 insertions(+) create mode 100644 tools/libs/light/libxl_virtio.c diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index 374be1cfab25..4fddcc6f51d7 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -106,6 +106,7 @@ OBJS-y +=3D libxl_vdispl.o OBJS-y +=3D libxl_pvcalls.o OBJS-y +=3D libxl_vsnd.o OBJS-y +=3D libxl_vkb.o +OBJS-y +=3D libxl_virtio.o OBJS-y +=3D libxl_genid.o OBJS-y +=3D _libxl_types.o OBJS-y +=3D libxl_flask.o diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index b4928dbf673c..f33c9b273a4f 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -113,6 +113,19 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, } } =20 + for (i =3D 0; i < d_config->num_virtios; i++) { + libxl_device_virtio *virtio =3D &d_config->virtios[i]; + + if (virtio->transport !=3D LIBXL_VIRTIO_TRANSPORT_MMIO) + continue; + + rc =3D alloc_virtio_mmio_params(gc, &virtio->base, &virtio->irq, + &virtio_mmio_base, &virtio_mmio_irq); + + if (rc) + return rc; + } + /* * Every virtio-mmio device uses one emulated SPI. If Virtio devices a= re * present, make sure that we allocate enough SPIs for them. @@ -968,6 +981,68 @@ static int make_virtio_mmio_node(libxl__gc *gc, void *= fdt, uint64_t base, return fdt_end_node(fdt); } =20 +static int make_virtio_mmio_node_i2c(libxl__gc *gc, void *fdt) +{ + int res; + + res =3D fdt_begin_node(fdt, "i2c"); + if (res) return res; + + res =3D fdt_property_compat(gc, fdt, 1, "virtio,device22"); + if (res) return res; + + return fdt_end_node(fdt); +} + +static int make_virtio_mmio_node_gpio(libxl__gc *gc, void *fdt) +{ + int res; + + res =3D fdt_begin_node(fdt, "gpio"); + if (res) return res; + + res =3D fdt_property_compat(gc, fdt, 1, "virtio,device29"); + if (res) return res; + + res =3D fdt_property(fdt, "gpio-controller", NULL, 0); + if (res) return res; + + res =3D fdt_property_cell(fdt, "#gpio-cells", 2); + if (res) return res; + + res =3D fdt_property(fdt, "interrupt-controller", NULL, 0); + if (res) return res; + + res =3D fdt_property_cell(fdt, "#interrupt-cells", 2); + if (res) return res; + + return fdt_end_node(fdt); +} + +static int make_virtio_mmio_node_device(libxl__gc *gc, void *fdt, uint64_t= base, + uint32_t irq, const char *type, + uint32_t backend_domid) +{ + int res, len =3D strlen(type); + + res =3D make_virtio_mmio_node_common(gc, fdt, base, irq, backend_domid= ); + if (res) return res; + + /* Add device specific nodes */ + if (!strncmp(type, "virtio,device22", len)) { + res =3D make_virtio_mmio_node_i2c(gc, fdt); + if (res) return res; + } else if (!strncmp(type, "virtio,device29", len)) { + res =3D make_virtio_mmio_node_gpio(gc, fdt); + if (res) return res; + } else { + LOG(ERROR, "Invalid type for virtio device: %s", type); + return -EINVAL; + } + + return fdt_end_node(fdt); +} + static const struct arch_info *get_arch_info(libxl__gc *gc, const struct xc_dom_image *do= m) { @@ -1290,6 +1365,20 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_d= omain_config *d_config, } } =20 + for (i =3D 0; i < d_config->num_virtios; i++) { + libxl_device_virtio *virtio =3D &d_config->virtios[i]; + + if (virtio->transport !=3D LIBXL_VIRTIO_TRANSPORT_MMIO) + continue; + + if (virtio->backend_domid !=3D LIBXL_TOOLSTACK_DOMID) + iommu_needed =3D true; + + FDT( make_virtio_mmio_node_device(gc, fdt, virtio->base, + virtio->irq, virtio->type, + virtio->backend_domid) ); + } + /* * Note, this should be only called after creating all virtio-mmio * device nodes diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index 612eacfc7fac..15a32c75c045 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -1802,6 +1802,11 @@ static void domcreate_launch_dm(libxl__egc *egc, lib= xl__multidev *multidev, &d_config->vkbs[i]); } =20 + for (i =3D 0; i < d_config->num_virtios; i++) { + libxl__device_add(gc, domid, &libxl__virtio_devtype, + &d_config->virtios[i]); + } + if (d_config->b_info.arch_arm.vuart =3D=3D LIBXL_VUART_TYPE_SBSA_U= ART) { init_console_info(gc, &vuart, 0); vuart.backend_domid =3D state->console_domid; diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index cb9e8b3b8b5a..e5716f9bef80 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4003,6 +4003,7 @@ static inline int *libxl__device_type_get_num( =20 extern const libxl__device_type libxl__vfb_devtype; extern const libxl__device_type libxl__vkb_devtype; +extern const libxl__device_type libxl__virtio_devtype; extern const libxl__device_type libxl__disk_devtype; extern const libxl__device_type libxl__nic_devtype; extern const libxl__device_type libxl__vtpm_devtype; diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index d634f304cda2..d97a0795d312 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -278,6 +278,14 @@ libxl_vkb_backend =3D Enumeration("vkb_backend", [ (2, "LINUX") ]) =20 +libxl_virtio_backend =3D Enumeration("virtio_backend", [ + (1, "STANDALONE") + ]) + +libxl_virtio_transport =3D Enumeration("virtio_transport", [ + (1, "MMIO"), + ]) + libxl_passthrough =3D Enumeration("passthrough", [ (0, "default"), (1, "disabled"), @@ -705,6 +713,17 @@ libxl_device_vkb =3D Struct("device_vkb", [ ("multi_touch_num_contacts", uint32) ]) =20 +libxl_device_virtio =3D Struct("device_virtio", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("backend", libxl_virtio_backend), + ("type", string), + ("transport", libxl_virtio_transport), + ("devid", libxl_devid), + ("irq", uint32), + ("base", uint64) + ]) + libxl_device_disk =3D Struct("device_disk", [ ("backend_domid", libxl_domid), ("backend_domname", string), @@ -982,6 +1001,7 @@ libxl_domain_config =3D Struct("domain_config", [ ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), ("vfbs", Array(libxl_device_vfb, "num_vfbs")), ("vkbs", Array(libxl_device_vkb, "num_vkbs")), + ("virtios", Array(libxl_device_virtio, "num_virtios")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")), ("p9s", Array(libxl_device_p9, "num_p9s")), ("pvcallsifs", Array(libxl_device_pvcallsif, "num_pvcallsifs")), @@ -1145,6 +1165,15 @@ libxl_vkbinfo =3D Struct("vkbinfo", [ ("rref", integer) ], dir=3DDIR_OUT) =20 +libxl_virtioinfo =3D Struct("virtioinfo", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", libxl_devid), + ("state", integer), + ], dir=3DDIR_OUT) + # NUMA node characteristics: size and free are how much memory it has, and= how # much of it is free, respectively. dists is an array of distances from th= is # node to each other node. diff --git a/tools/libs/light/libxl_types_internal.idl b/tools/libs/light/l= ibxl_types_internal.idl index fb0f4f23d7c2..e24288f1a59e 100644 --- a/tools/libs/light/libxl_types_internal.idl +++ b/tools/libs/light/libxl_types_internal.idl @@ -33,6 +33,7 @@ libxl__device_kind =3D Enumeration("device_kind", [ (15, "VSND"), (16, "VINPUT"), (17, "VIRTIO_DISK"), + (18, "VIRTIO"), ]) =20 libxl__console_backend =3D Enumeration("console_backend", [ diff --git a/tools/libs/light/libxl_virtio.c b/tools/libs/light/libxl_virti= o.c new file mode 100644 index 000000000000..14b0c016a0a2 --- /dev/null +++ b/tools/libs/light/libxl_virtio.c @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2022 Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * 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 Lesser General Public License for more details. + */ + +#include "libxl_internal.h" + +static int libxl__device_virtio_setdefault(libxl__gc *gc, uint32_t domid, + libxl_device_virtio *virtio, + bool hotplug) +{ + return libxl__resolve_domid(gc, virtio->backend_domname, + &virtio->backend_domid); +} + +static int libxl__device_from_virtio(libxl__gc *gc, uint32_t domid, + libxl_device_virtio *virtio, + libxl__device *device) +{ + device->backend_devid =3D virtio->devid; + device->backend_domid =3D virtio->backend_domid; + device->devid =3D virtio->devid; + device->domid =3D domid; + + device->backend_kind =3D LIBXL__DEVICE_KIND_VIRTIO; + device->kind =3D LIBXL__DEVICE_KIND_VIRTIO; + + return 0; +} + +static int libxl__set_xenstore_virtio(libxl__gc *gc, uint32_t domid, + libxl_device_virtio *virtio, + flexarray_t *back, flexarray_t *fron= t, + flexarray_t *ro_front) +{ + const char *transport =3D libxl_virtio_transport_to_string(virtio->tra= nsport); + + flexarray_append_pair(back, "irq", GCSPRINTF("%u", virtio->irq)); + flexarray_append_pair(back, "base", GCSPRINTF("%lu", virtio->base)); + flexarray_append_pair(back, "type", GCSPRINTF("%s", virtio->type)); + flexarray_append_pair(back, "transport", GCSPRINTF("%s", transport)); + + flexarray_append_pair(front, "irq", GCSPRINTF("%u", virtio->irq)); + flexarray_append_pair(front, "base", GCSPRINTF("%lu", virtio->base)); + flexarray_append_pair(front, "type", GCSPRINTF("%s", virtio->type)); + flexarray_append_pair(front, "transport", GCSPRINTF("%s", transport)); + + return 0; +} + +static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_pa= th, + libxl_devid devid, + libxl_device_virtio *virtio) +{ + const char *be_path, *fe_path, *tmp; + libxl__device dev; + int rc; + + virtio->devid =3D devid; + + rc =3D libxl__xs_read_mandatory(gc, XBT_NULL, + GCSPRINTF("%s/backend", libxl_path), + &be_path); + if (rc) goto out; + + rc =3D libxl__xs_read_mandatory(gc, XBT_NULL, + GCSPRINTF("%s/frontend", libxl_path), + &fe_path); + if (rc) goto out; + + rc =3D libxl__backendpath_parse_domid(gc, be_path, &virtio->backend_do= mid); + if (rc) goto out; + + rc =3D libxl__parse_backend_path(gc, be_path, &dev); + if (rc) goto out; + + rc =3D libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/irq", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + virtio->irq =3D strtoul(tmp, NULL, 0); + } + + rc =3D libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/base", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + virtio->base =3D strtoul(tmp, NULL, 0); + } + + rc =3D 0; + +out: + + return rc; +} + +static LIBXL_DEFINE_UPDATE_DEVID(virtio) + +#define libxl__add_virtios NULL +#define libxl_device_virtio_compare NULL + +DEFINE_DEVICE_TYPE_STRUCT(virtio, VIRTIO, virtios, + .set_xenstore_config =3D (device_set_xenstore_config_fn_t) + libxl__set_xenstore_virtio, + .from_xenstore =3D (device_from_xenstore_fn_t)libxl__virtio_from_xenst= ore, + .skip_attach =3D 1 +); + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.31.1.272.g89b43f80a514 From nobody Sun May 12 07:37:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1667906688; cv=none; d=zohomail.com; s=zohoarc; b=fLgHBbniy4IlHVXynT6Ikae04ItZ/ix8Og9/BmNox3sZuatHibFT5L3UsQWrwfofpWm4YXAb2Q+8WZAX3nzJOh4OiK4y6YTompXLKphi1fntKUwxhfL2r7oZxQRIzEB626hVAWV/qdU/JWNRSPAC962CvDZ24dFAhDE0PNFz56w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667906688; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=obQ8DZ5BACOYz3wKPJhR8jMno97FAVM9CyAho1QNHtU=; b=H3ReBUPMIXPMkd21xCOyzILmwYp//dcUPrWFUvDQlfPtYyWbpj5vN0+gGn3ysJy+WN1ULf5P5S2o9NfNnDBd3b4dkqbEveS+bCjmRnUmrdponvLH1fPy7yzLH+Mzk3DeABZh64yAf/7i6sPE3jU/rcHlJqGN7qcXC24sImZKlQc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1667906688429198.1065557464375; Tue, 8 Nov 2022 03:24:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.439976.694029 (Exim 4.92) (envelope-from ) id 1osMiS-00074Z-Nz; Tue, 08 Nov 2022 11:24:28 +0000 Received: by outflank-mailman (output) from mailman id 439976.694029; Tue, 08 Nov 2022 11:24: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 1osMiS-00073j-Kp; Tue, 08 Nov 2022 11:24:28 +0000 Received: by outflank-mailman (input) for mailman id 439976; Tue, 08 Nov 2022 11:24:27 +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 1osMiR-0006S1-Cr for xen-devel@lists.xen.org; Tue, 08 Nov 2022 11:24:27 +0000 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [2607:f8b0:4864:20::1034]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e6a6b81e-5f57-11ed-8fd1-01056ac49cbb; Tue, 08 Nov 2022 12:24:26 +0100 (CET) Received: by mail-pj1-x1034.google.com with SMTP id m14-20020a17090a3f8e00b00212dab39bcdso17645849pjc.0 for ; Tue, 08 Nov 2022 03:24:26 -0800 (PST) Received: from localhost ([122.172.84.80]) by smtp.gmail.com with ESMTPSA id u9-20020a17090a3fc900b00200461cfa99sm7754719pjm.11.2022.11.08.03.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 03:24:20 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e6a6b81e-5f57-11ed-8fd1-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=obQ8DZ5BACOYz3wKPJhR8jMno97FAVM9CyAho1QNHtU=; b=nVYHAI3sksJD2yknMbxKHfKQFu00MZDzVrbCEykWA85twFbEAZ1toG3GjsTJvXPA3d VjNpakqVoseWB1FrzcB5Pxza5WQ7w0HRey9z0+jxDJi3Zuu6TCbcnLVl3aWLuwX185nt aNHHIy7eG155pbz1NmU1d8nL2uG8CzsfM3DJ160XMjLY+ugegeEooIYWFcepc2la5rL+ wDGqbouymHRZfMj8Ynb6FtfVUJYl2I2tmUdH1wc+k6xh44BpLxUBP/TSsJrikaLsYlOq rh0+oC4H0iby0Av23Jks+J0Rug2muhVWDhq4uqu6PMubjfriqU0ew94LRrWmwaL+xQZn tIrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=obQ8DZ5BACOYz3wKPJhR8jMno97FAVM9CyAho1QNHtU=; b=GP+dcs9wi/vQLJcSYMix8HZ3BfbNBoywxPx8BIaPdy4DPYHBzVagGtRgE1e7+gLZeT gfzAYhl0kon2IngLKWqSgr4rwZPVrQmOy5PH2FHFJU1+KQu0dHRMemaU++2+UYkuYebf P17X7BKmLZeAL2RJTESMWOYqKC9G1YFZPm5ncqWjano6/p5I5lrq5fNxhHDaEKU4Wk8e ct5l7YqrpOQq5eM64eRgYnYRP1dpdUfJWYQp0zrf9uE+eeLdibzMKnETKbI7e3b8M4lX eSr3GsyMapW5dmTi5UIWLGv6EXsnRuDZVqpWitJgDR4Ni1Oe8dsg4I5VES59DYbHr9In 44RA== X-Gm-Message-State: ACrzQf30wW4VlPeF3BC2NzaZPUQY7DzKO1GxKqmxgpoDs5WNvqlfuYLE 7YFhD3gnoVvoH7O7nwlm3X5k2DmHC9Ccwg== X-Google-Smtp-Source: AMsMyM5S+xvSbtuyQCGITbssl4YxD30xFW0fcg8YeyElkvcQSPzwLPQRwxIPekz5tbxFH9eT2duHBw== X-Received: by 2002:a17:902:e8cd:b0:186:9efc:6790 with SMTP id v13-20020a170902e8cd00b001869efc6790mr55901025plg.91.1667906664869; Tue, 08 Nov 2022 03:24:24 -0800 (PST) From: Viresh Kumar To: xen-devel@lists.xen.org, Juergen Gross , Julien Grall , Anthony PERARD Cc: Viresh Kumar , Vincent Guittot , stratos-dev@op-lists.linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Stefano Stabellini , Mathieu Poirier , Mike Holmes , Oleksandr Tyshchenko , Wei Liu Subject: [PATCH V6 2/3] xl: Add support to parse generic virtio device Date: Tue, 8 Nov 2022 16:53:59 +0530 Message-Id: <73663851c5223b99ed0f23a163a0d44cba0ebe29.1667906228.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1667906689413100001 Content-Type: text/plain; charset="utf-8" This patch adds basic support for parsing generic Virtio backend. An example of domain configuration for mmio based Virtio I2C device is: virtio =3D ["type=3Dvirtio,device22,transport=3Dmmio"] Signed-off-by: Viresh Kumar --- tools/ocaml/libs/xl/genwrap.py | 1 + tools/ocaml/libs/xl/xenlight_stubs.c | 1 + tools/xl/xl_parse.c | 84 ++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py index 7bf26bdcd831..b188104299b1 100644 --- a/tools/ocaml/libs/xl/genwrap.py +++ b/tools/ocaml/libs/xl/genwrap.py @@ -36,6 +36,7 @@ DEVICE_LIST =3D [ ("list", ["ctx", "domid"= , "t list"]), functions =3D { # ( name , [type1,type2,....] ) "device_vfb": DEVICE_FUNCTIONS, "device_vkb": DEVICE_FUNCTIONS, + "device_virtio": DEVICE_FUNCTIONS, "device_disk": DEVICE_FUNCTIONS + DEVICE_LIST + [ ("insert", ["ctx", "t", "domid", "?async:'= a", "unit", "unit"]), ("of_vdev", ["ctx", "domid", "string", "t"]= ), diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xen= light_stubs.c index 45b8af61c74a..8e54f95da7c7 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -707,6 +707,7 @@ DEVICE_ADDREMOVE(disk) DEVICE_ADDREMOVE(nic) DEVICE_ADDREMOVE(vfb) DEVICE_ADDREMOVE(vkb) +DEVICE_ADDREMOVE(virtio) DEVICE_ADDREMOVE(pci) _DEVICE_ADDREMOVE(disk, cdrom, insert) =20 diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 1b5381cef033..c6f35c069d2a 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1208,6 +1208,87 @@ static void parse_vkb_list(const XLU_Config *config, if (rc) exit(EXIT_FAILURE); } =20 +static int parse_virtio_config(libxl_device_virtio *virtio, char *token) +{ + char *oparg; + int rc; + + if (MATCH_OPTION("backend", token, oparg)) { + virtio->backend_domname =3D strdup(oparg); + } else if (MATCH_OPTION("type", token, oparg)) { + virtio->type =3D strdup(oparg); + } else if (MATCH_OPTION("transport", token, oparg)) { + rc =3D libxl_virtio_transport_from_string(oparg, &virtio->transpor= t); + if (rc) return rc; + } else if (MATCH_OPTION("irq", token, oparg)) { + virtio->irq =3D strtoul(oparg, NULL, 0); + } else if (MATCH_OPTION("base", token, oparg)) { + virtio->base =3D strtoul(oparg, NULL, 0); + } else { + fprintf(stderr, "Unknown string \"%s\" in virtio spec\n", token); + return -1; + } + + return 0; +} + +static void parse_virtio_list(const XLU_Config *config, + libxl_domain_config *d_config) +{ + XLU_ConfigList *virtios; + const char *item; + char *buf =3D NULL, *oparg, *str =3D NULL; + int rc; + + if (!xlu_cfg_get_list (config, "virtio", &virtios, 0, 0)) { + int entry =3D 0; + while ((item =3D xlu_cfg_get_listitem(virtios, entry)) !=3D NULL) { + libxl_device_virtio *virtio; + char *p; + + virtio =3D ARRAY_EXTEND_INIT(d_config->virtios, d_config->num_= virtios, + libxl_device_virtio_init); + + buf =3D strdup(item); + + p =3D strtok(buf, ","); + while (p !=3D NULL) + { + while (*p =3D=3D ' ') p++; + + // Type may contain a comma, do special handling. + if (MATCH_OPTION("type", p, oparg)) { + if (!strncmp(oparg, "virtio", strlen("virtio"))) { + char *p2 =3D strtok(NULL, ","); + str =3D malloc(strlen(p) + strlen(p2) + 2); + + strcpy(str, p); + strcat(str, ","); + strcat(str, p2); + p =3D str; + } + } + + rc =3D parse_virtio_config(virtio, p); + if (rc) goto out; + + free(str); + str =3D NULL; + p =3D strtok(NULL, ","); + } + + entry++; + free(buf); + } + } + + return; + +out: + free(buf); + if (rc) exit(EXIT_FAILURE); +} + void parse_config_data(const char *config_source, const char *config_data, int config_len, @@ -2309,8 +2390,10 @@ void parse_config_data(const char *config_source, =20 d_config->num_vfbs =3D 0; d_config->num_vkbs =3D 0; + d_config->num_virtios =3D 0; d_config->vfbs =3D NULL; d_config->vkbs =3D NULL; + d_config->virtios =3D NULL; =20 if (!xlu_cfg_get_list (config, "vfb", &cvfbs, 0, 0)) { while ((buf =3D xlu_cfg_get_listitem (cvfbs, d_config->num_vfbs)) = !=3D NULL) { @@ -2752,6 +2835,7 @@ void parse_config_data(const char *config_source, } =20 parse_vkb_list(config, d_config); + parse_virtio_list(config, d_config); =20 xlu_cfg_get_defbool(config, "xend_suspend_evtchn_compat", &c_info->xend_suspend_evtchn_compat, 0); --=20 2.31.1.272.g89b43f80a514 From nobody Sun May 12 07:37:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1667906688; cv=none; d=zohomail.com; s=zohoarc; b=KZae/dlG5u/dcFCuiEy8tA676XT5wqG/ifGeONuFOpglJSinENzT6LyLZTs6iUjjA0r10TrMat+zggrDLpSkIcHKl1QuQCv3nxrOL6P3SrRC9/JrUGokKj/jZjRD6bWrf9v4BzfLye1rH/A0wr4zbLNdgpt5EHeZNrbSsYh/2hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667906688; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4O5etID8pnJ+mOBEfmxIpjayhQN9TbUVsRBMhrbeh44=; b=mPNYdcDLvJoUUzbFhhc5sBwAUD+VNYWib+PSaL2Ph4FKgjnB1omwaXyU++3HNOCTjqAFBVYL/Jd+0YHwCnP2z1hrsMWIEue6qRnMwzBBQMF8j/r2hPVRF5vL+MNXEvxY+O2PJXspVHmfUrBh04IIm0fNEZ8yZvoHntkJjbIMUJA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 166790668888288.85748834714275; Tue, 8 Nov 2022 03:24:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.439977.694040 (Exim 4.92) (envelope-from ) id 1osMiV-0007Ns-4z; Tue, 08 Nov 2022 11:24:31 +0000 Received: by outflank-mailman (output) from mailman id 439977.694040; Tue, 08 Nov 2022 11:24:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1osMiV-0007NZ-12; Tue, 08 Nov 2022 11:24:31 +0000 Received: by outflank-mailman (input) for mailman id 439977; Tue, 08 Nov 2022 11:24:29 +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 1osMiT-0006S1-Lx for xen-devel@lists.xen.org; Tue, 08 Nov 2022 11:24:29 +0000 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [2607:f8b0:4864:20::431]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e824af50-5f57-11ed-8fd1-01056ac49cbb; Tue, 08 Nov 2022 12:24:29 +0100 (CET) Received: by mail-pf1-x431.google.com with SMTP id b185so13531509pfb.9 for ; Tue, 08 Nov 2022 03:24:28 -0800 (PST) Received: from localhost ([122.172.84.80]) by smtp.gmail.com with ESMTPSA id n6-20020a170903110600b001865c298588sm6677765plh.258.2022.11.08.03.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 03:24:27 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e824af50-5f57-11ed-8fd1-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4O5etID8pnJ+mOBEfmxIpjayhQN9TbUVsRBMhrbeh44=; b=NCjoYqLzGCF5lUfugIxT0rR9KaqTtPk0rXEL13eqJQojws8POkXXPr3CRRkY+y4K3D NvIGuyf6Vmk8CWW11agxMhUkscJjnD0m7QvpGJ2zcmBy03sG44IqD8qRKq7MRkNLzIP9 W4qfed7DoWIqs8fZqy7TfceQPQCTz/OLQ67SfG1XpMTebMzG9FstJKbQHAA3SbS3FTLV nsjBwbtZsM7/T+kirM3QtQItPb4B/vwepXaSwjJrU6N1qJUARWP9ca4b/ZaAoQTaeLNf OpKPFcX824Vp8As3cl7Pjlm4dXa1zHJM/04u3w/gm/Fb8v001z/FCSPjqvqm7mmdhaDT BUqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4O5etID8pnJ+mOBEfmxIpjayhQN9TbUVsRBMhrbeh44=; b=QcUQ6ImpxmnCbjZW5WfYD78M+xTJQ+sW99EPUTxpL9+rZU/5bwMpNqp1a+Lkxj8YXw c2y5Oplj/vupckRZrX8Hgi9O2bcpG0PMGAYN/6evyj0p9r6Ew2DlpRUwD/fti9Ut9+qI VIA11KF+kobHYgNwgPv/fJZfyE9ilsSlioA97gYdCIxxCJ2cFvW4Cb+emUy5bvYYrD/z mVcUOff6NJarwwqmPjfgvQtLKNuJHLwYj02SjMBXZC+s1V9v8pbacnc8VcqnB1UQYFtT ymIZ+nXR4qCeD4vrTVmPkmoQpmpJPyr4nepc7/tQUw3Or+rvKJcNddPRPHSigY4yhIiQ 7p/Q== X-Gm-Message-State: ACrzQf0Zr7WXT7o6zMg8QfHq9hFUYs8BtyMhpqXBOMtHtVYHJPbgjzzL WoecKUcyIZLriGPtkCWu7ZpcdXmiwr5hXA== X-Google-Smtp-Source: AMsMyM7OwRKvh4arUDf2IMW8MGEbBtDR2PFf/GJH4pH79GdWyFn2gsPOcsdW7kYp833YO+wkRtyIpg== X-Received: by 2002:a63:4420:0:b0:470:89:8e7c with SMTP id r32-20020a634420000000b0047000898e7cmr31541733pga.150.1667906667403; Tue, 08 Nov 2022 03:24:27 -0800 (PST) From: Viresh Kumar To: xen-devel@lists.xen.org, Juergen Gross , Julien Grall , Anthony PERARD Cc: Viresh Kumar , Vincent Guittot , stratos-dev@op-lists.linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Stefano Stabellini , Mathieu Poirier , Mike Holmes , Oleksandr Tyshchenko , Wei Liu Subject: [PATCH V6 3/3] docs: Add documentation for generic virtio devices Date: Tue, 8 Nov 2022 16:54:00 +0530 Message-Id: <24a0278313ea9a9e6c093880dead835184025734.1667906228.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1667906689463100002 Content-Type: text/plain; charset="utf-8" This patch updates xl.cfg man page with details of generic Virtio device related information. Signed-off-by: Viresh Kumar --- docs/man/xl.cfg.5.pod.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 31e58b73b0c9..1056b03df846 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1585,6 +1585,27 @@ Set maximum height for pointer device. =20 =3Dback =20 +=3Ditem B + +Specifies the Virtio devices to be provided to the guest. + +Each B is a comma-separated list of C +settings from the following list: + +=3Dover 4 + +=3Ditem B + +Specifies the compatible string for the specific Virtio device. The same w= ill be +written in the Device Tree compatible property of the Virtio device. For +example, "type=3Dvirtio,device22" for the I2C device. + +=3Ditem B + +Specifies the transport mechanism for the Virtio device, like "mmio" or "p= ci". + +=3Dback + =3Ditem B =20 B Set TEE type for the guest. TEE is a Trusted Execution --=20 2.31.1.272.g89b43f80a514