From patchwork Mon Dec 12 10:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 13070898 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 40C6BC4332F for ; Mon, 12 Dec 2022 10:10:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.459355.717082 (Exim 4.92) (envelope-from ) id 1p4fku-00037h-Ia; Mon, 12 Dec 2022 10:09:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 459355.717082; Mon, 12 Dec 2022 10:09:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p4fku-00037a-Fx; Mon, 12 Dec 2022 10:09:52 +0000 Received: by outflank-mailman (input) for mailman id 459355; Mon, 12 Dec 2022 10:09:51 +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 1p4fkt-000356-Hy for xen-devel@lists.xen.org; Mon, 12 Dec 2022 10:09:51 +0000 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [2607:f8b0:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1c840e50-7a05-11ed-8fd2-01056ac49cbb; Mon, 12 Dec 2022 11:09:50 +0100 (CET) Received: by mail-pl1-x62e.google.com with SMTP id 17so4113231pll.0 for ; Mon, 12 Dec 2022 02:09:49 -0800 (PST) Received: from localhost ([122.172.87.149]) by smtp.gmail.com with ESMTPSA id gl7-20020a17090b120700b00218f9bd50c7sm5049114pjb.50.2022.12.12.02.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 02:09:47 -0800 (PST) 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: 1c840e50-7a05-11ed-8fd2-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=a1OhuQIJQwLi/mECPz3+nkOM6kZnQjkXe5DIuu8yWRM=; b=W7aDKYeVvC2M4iAKKuobsZuf28O+E43xK2p3AlBXXT74VY5tOJLqiweuY1Mzk9sqg+ iEi4iJyFkwbL15Lo9ra3gxJXS51Riiy1SyLj0R7+i2I/RN6KhZDTqY/USYgJBB1wdJOx URcUhvL1/Zkv2D/LoyFWcG5nIy+60Z5M2DSwcyN8iCP4ECYWYL4Ie9C30f7MkvcWBXoq p6nagauP+p+vx+o3/w1e1yjH0hxkBBMD9GnMqPoF+WyuX8eny/6FND95BlnOqhRIZNKb SdzvRlyzlm8s3zPwpmZ5tqjLzMnQo3uNCXZw2JxAQpisT+QJdV/iHmn2qbwXtlbdxe7N no3A== 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=a1OhuQIJQwLi/mECPz3+nkOM6kZnQjkXe5DIuu8yWRM=; b=j5etkyl5uMPCPcmWKDbHKcuHKFSFKsGawLDFoFGCWBguBuBYIguY3HwEMMJOP9Bwc6 EAePgev9lTu7CDnoAzABUpEczaEWU36qft9yh4Is+LmFaZbCHjvBZqZgXp+Gu7emY7Dj C+dj0bZhRQQumEG+s7QA3QtPynJk0NrCuk4rV5VtfCmt5+wCvZKgjVF8Sf3Q8PykfLYz TtF9wa4n/a/U5eqblE4WasiMy9DO4qO6JiN0kXU0AAkKRdC5ao+R817xuZtL4Fr2ii72 uZWYKsghP5FK//3sZ63tOhuawONwRk0NMPpLL6wOocJQ0Ar6n1zt8y0TwfeGiuBWFZoR wI/Q== X-Gm-Message-State: ANoB5pkAWjtF/ZhX6kbRFuuV+Jss9/p2bcesdfOobo5jAhrtfeWxmmPq z6ICoP2Y4PNx8aSLie7AL6mEtX9kWWDR+Fa1 X-Google-Smtp-Source: AA0mqf4ePxrnTbRobA3yKw8AqMuRWfOI8Wvy2WMPLobxyEfmcNecBdjNfxZjGtKbUW/NxONZQKa/QA== X-Received: by 2002:a17:90b:46ce:b0:219:e613:9006 with SMTP id jx14-20020a17090b46ce00b00219e6139006mr15766979pjb.41.1670839788372; Mon, 12 Dec 2022 02:09:48 -0800 (PST) From: Viresh Kumar To: xen-devel@lists.xen.org, Juergen Gross , Julien Grall , Anthony PERARD Cc: Viresh Kumar , Vincent Guittot , =?utf-8?q?Alex_Benn=C3=A9e?= , Stefano Stabellini Subject: [PATCH V8 1/3] libxl: Add support for generic virtio device Date: Mon, 12 Dec 2022 15:35:53 +0530 Message-Id: <0e58df1510d7d8c0186da6620882b7c4e4035ab0.1670839220.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 This patch adds basic support for configuring and assisting generic Virtio backends, which could run in any domain. An example of domain configuration for mmio based Virtio I2C device is: virtio = ["type=virtio,device22,transport=mmio"] To make this work on Arm, allocate Virtio MMIO params (IRQ and memory region) and pass them to the backend and update guest device-tree to create a DT node for the Virtio devices. Add special support for I2C and GPIO devices, which require the "compatible" DT property to be set, among other device specific properties. Support for generic virtio devices is also added, which just need a MMIO node but not any special DT properties, for such devices the user needs to pass "virtio,device" in the "type" string. The parsing of generic virtio device configurations will be done in a separate commit. Signed-off-by: Viresh Kumar Reviewed-by: Anthony PERARD Reviewed-by: Oleksandr Tyshchenko --- tools/libs/light/Makefile | 1 + tools/libs/light/libxl_arm.c | 100 +++++++++++++++ tools/libs/light/libxl_create.c | 4 + tools/libs/light/libxl_internal.h | 6 + tools/libs/light/libxl_types.idl | 18 +++ tools/libs/light/libxl_types_internal.idl | 1 + tools/libs/light/libxl_virtio.c | 144 ++++++++++++++++++++++ 7 files changed, 274 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 += libxl_vdispl.o OBJS-y += libxl_pvcalls.o OBJS-y += libxl_vsnd.o OBJS-y += libxl_vkb.o +OBJS-y += libxl_virtio.o OBJS-y += libxl_genid.o OBJS-y += _libxl_types.o OBJS-y += libxl_flask.o diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index fa3d61f1e882..292b31881210 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, } } + for (i = 0; i < d_config->num_virtios; i++) { + libxl_device_virtio *virtio = &d_config->virtios[i]; + + if (virtio->transport != LIBXL_VIRTIO_TRANSPORT_MMIO) + continue; + + rc = 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 are * present, make sure that we allocate enough SPIs for them. @@ -956,6 +969,79 @@ static int make_virtio_mmio_node(libxl__gc *gc, void *fdt, uint64_t base, return fdt_end_node(fdt); } +/* + * The DT bindings for GPIO device are present here: + * + * https://www.kernel.org/doc/Documentation/devicetree/bindings/i2c/i2c-virtio.yaml + */ +static int make_virtio_mmio_node_i2c(libxl__gc *gc, void *fdt) +{ + int res; + + res = fdt_begin_node(fdt, "i2c"); + if (res) return res; + + res = fdt_property_compat(gc, fdt, 1, VIRTIO_DEVICE_TYPE_I2C); + if (res) return res; + + return fdt_end_node(fdt); +} + +/* + * The DT bindings for GPIO device are present here: + * + * https://www.kernel.org/doc/Documentation/devicetree/bindings/gpio/gpio-virtio.yaml + */ +static int make_virtio_mmio_node_gpio(libxl__gc *gc, void *fdt) +{ + int res; + + res = fdt_begin_node(fdt, "gpio"); + if (res) return res; + + res = fdt_property_compat(gc, fdt, 1, VIRTIO_DEVICE_TYPE_GPIO); + if (res) return res; + + res = fdt_property(fdt, "gpio-controller", NULL, 0); + if (res) return res; + + res = fdt_property_cell(fdt, "#gpio-cells", 2); + if (res) return res; + + res = fdt_property(fdt, "interrupt-controller", NULL, 0); + if (res) return res; + + res = 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; + + res = make_virtio_mmio_node_common(gc, fdt, base, irq, backend_domid); + if (res) return res; + + /* Add device specific nodes */ + if (!strcmp(type, VIRTIO_DEVICE_TYPE_I2C)) { + res = make_virtio_mmio_node_i2c(gc, fdt); + if (res) return res; + } else if (!strcmp(type, VIRTIO_DEVICE_TYPE_GPIO)) { + res = make_virtio_mmio_node_gpio(gc, fdt); + if (res) return res; + } else if (strcmp(type, VIRTIO_DEVICE_TYPE_GENERIC)) { + /* Doesn't match generic virtio device */ + 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 *dom) { @@ -1277,6 +1363,20 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_domain_config *d_config, } } + for (i = 0; i < d_config->num_virtios; i++) { + libxl_device_virtio *virtio = &d_config->virtios[i]; + + if (virtio->transport != LIBXL_VIRTIO_TRANSPORT_MMIO) + continue; + + if (virtio->backend_domid != LIBXL_TOOLSTACK_DOMID) + iommu_needed = true; + + FDT( make_virtio_mmio_node_device(gc, fdt, virtio->base, + virtio->irq, virtio->type, + virtio->backend_domid) ); + } + /* * The iommu node should be created only once for all virtio-mmio * devices. diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c index 612eacfc7fac..beec3f6b6fec 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -1752,6 +1752,10 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev, libxl__device_add(gc, domid, &libxl__pvcallsif_devtype, &d_config->pvcallsifs[i]); + for (i = 0; i < d_config->num_virtios; i++) + libxl__device_add(gc, domid, &libxl__virtio_devtype, + &d_config->virtios[i]); + switch (d_config->c_info.type) { case LIBXL_DOMAIN_TYPE_HVM: { diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index a7c447c10e5f..97e1e66d98af 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -166,6 +166,11 @@ /* Convert pfn to physical address space. */ #define pfn_to_paddr(x) ((uint64_t)(x) << XC_PAGE_SHIFT) +/* Virtio device types */ +#define VIRTIO_DEVICE_TYPE_GENERIC "virtio,device" +#define VIRTIO_DEVICE_TYPE_GPIO "virtio,device22" +#define VIRTIO_DEVICE_TYPE_I2C "virtio,device29" + /* logging */ _hidden void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval, const char *file /* may be 0 */, int line /* ignored if !file */, @@ -4003,6 +4008,7 @@ static inline int *libxl__device_type_get_num( 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_types.idl index 9e3d33cb5a59..0cfad8508dbd 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -278,6 +278,11 @@ libxl_vkb_backend = Enumeration("vkb_backend", [ (2, "LINUX") ]) +libxl_virtio_transport = Enumeration("virtio_transport", [ + (0, "UNKNOWN"), + (1, "MMIO"), + ]) + libxl_passthrough = Enumeration("passthrough", [ (0, "default"), (1, "disabled"), @@ -703,6 +708,18 @@ libxl_device_vkb = Struct("device_vkb", [ ("multi_touch_num_contacts", uint32) ]) +libxl_device_virtio = Struct("device_virtio", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("type", string), + ("transport", libxl_virtio_transport), + ("devid", libxl_devid), + # Note that virtio-mmio parameters (irq and base) are for internal + # use by libxl and can't be modified. + ("irq", uint32), + ("base", uint64) + ]) + libxl_device_disk = Struct("device_disk", [ ("backend_domid", libxl_domid), ("backend_domname", string), @@ -980,6 +997,7 @@ libxl_domain_config = 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")), diff --git a/tools/libs/light/libxl_types_internal.idl b/tools/libs/light/libxl_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 = Enumeration("device_kind", [ (15, "VSND"), (16, "VINPUT"), (17, "VIRTIO_DISK"), + (18, "VIRTIO"), ]) libxl__console_backend = Enumeration("console_backend", [ diff --git a/tools/libs/light/libxl_virtio.c b/tools/libs/light/libxl_virtio.c new file mode 100644 index 000000000000..6a38def2faf5 --- /dev/null +++ b/tools/libs/light/libxl_virtio.c @@ -0,0 +1,144 @@ +/* + * 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 = virtio->devid; + device->backend_domid = virtio->backend_domid; + device->devid = virtio->devid; + device->domid = domid; + + device->backend_kind = LIBXL__DEVICE_KIND_VIRTIO; + device->kind = 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 *front, + flexarray_t *ro_front) +{ + const char *transport = libxl_virtio_transport_to_string(virtio->transport); + + 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_path, + libxl_devid devid, + libxl_device_virtio *virtio) +{ + const char *be_path, *tmp = NULL; + int rc; + + virtio->devid = devid; + + rc = libxl__xs_read_mandatory(gc, XBT_NULL, + GCSPRINTF("%s/backend", libxl_path), + &be_path); + if (rc) goto out; + + rc = libxl__backendpath_parse_domid(gc, be_path, &virtio->backend_domid); + if (rc) goto out; + + rc = libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/irq", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + virtio->irq = strtoul(tmp, NULL, 0); + } + + tmp = NULL; + rc = libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/base", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + virtio->base = strtoul(tmp, NULL, 0); + } + + tmp = NULL; + rc = libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/transport", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + if (!strcmp(tmp, "mmio")) { + virtio->transport = LIBXL_VIRTIO_TRANSPORT_MMIO; + } else { + return ERROR_INVAL; + } + } + + tmp = NULL; + rc = libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/type", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + int len = sizeof(VIRTIO_DEVICE_TYPE_GENERIC) - 1; + + if (!strncmp(tmp, VIRTIO_DEVICE_TYPE_GENERIC, len)) { + virtio->type = libxl__strdup(NOGC, tmp); + } else { + return ERROR_INVAL; + } + } + +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 = (device_set_xenstore_config_fn_t) + libxl__set_xenstore_virtio, + .from_xenstore = (device_from_xenstore_fn_t)libxl__virtio_from_xenstore, + .skip_attach = 1 +); + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Mon Dec 12 10:05:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 13070897 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 96B71C04FDE for ; Mon, 12 Dec 2022 10:10:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.459356.717093 (Exim 4.92) (envelope-from ) id 1p4fky-0003QZ-0P; Mon, 12 Dec 2022 10:09:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 459356.717093; Mon, 12 Dec 2022 10:09:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p4fkx-0003QS-T1; Mon, 12 Dec 2022 10:09:55 +0000 Received: by outflank-mailman (input) for mailman id 459356; Mon, 12 Dec 2022 10:09:54 +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 1p4fkv-0002rI-Tk for xen-devel@lists.xen.org; Mon, 12 Dec 2022 10:09:54 +0000 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [2607:f8b0:4864:20::42e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1e5413e3-7a05-11ed-91b6-6bf2151ebd3b; Mon, 12 Dec 2022 11:09:53 +0100 (CET) Received: by mail-pf1-x42e.google.com with SMTP id 130so8179889pfu.8 for ; Mon, 12 Dec 2022 02:09:52 -0800 (PST) Received: from localhost ([122.172.87.149]) by smtp.gmail.com with ESMTPSA id v66-20020a622f45000000b005754106e364sm5383662pfv.199.2022.12.12.02.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 02:09:50 -0800 (PST) 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: 1e5413e3-7a05-11ed-91b6-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=wZw/jcd26ULBLrGrTF2EhfE2I7WbIMOHWDnSInCc7qI=; b=oHOAIhgOWckbpTOOFOTGFxfhCmuxLPKjneh9C7pQVvRrmZO1ppf9S06XQsgLxsVaqb xC5D+57ryh9y+zMF4UebqSM3Fr9DXfypZkCjRpeWoI7LR0WxzMCgp3Q7MatLHEuNnQ4R Y5aa35vayUjojH5M1EuompOXcNRvYi8DtGFSmO0PSoMWqj2zOoxlT+F9xpqiZ0Y5FOyU qSrposgXOjBKcUCM6jfPMZ4Tk9a6+NzSsCzfw5kAbJ8MBxPRYr4Q43EYPSkdwcDT+w+z 1IZgc353CcF35mE8BkUueDx8nZHXw9JyGu9Br1C/knEUEvFXhekXtV99gB4bpn8QcsEC anSA== 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=wZw/jcd26ULBLrGrTF2EhfE2I7WbIMOHWDnSInCc7qI=; b=Zclk1OsxeTeId4yNbEFf2GMHwqbdhCzZ3GV5FSfNrC16Xt4DSLgDGBrKqUfb0xpVy7 /Ucakwl1mktItlbLh0FJWCXMTl4XbRXwHZ1231bncmLctL//ZO8MKt7KltBOlsAA3dh+ OPgpXysk93FKi+PFZhtQS4DujsE5UkfX7nd/f1wrK/gDalzxGTCfUtw1sG9fwSef6U3y fdgON3qenDU5MZv+cByC6zfLc7dGFK9Nry6GfkBImhb+QNqsYRtecqRhGmcmY7NnqJsA qibMlpUsSqNzsuQdISmLf11yAwgBfo6mRvyeNaBj7raXDsc7Sku8C0cMSbOULUnl7yHR vqfg== X-Gm-Message-State: ANoB5pk1LcObNF4od6LbIGY42cgdCSi6Wr3DcsYweA6hgWNiZizutR4k EPX4r+uxhfsS5014lXx7XYeS3xXRnhICx3uk X-Google-Smtp-Source: AA0mqf4BnBFdxcZVU4c7nJvppc+tpje5u8YtLk9lhwpkHMRCEpn232Ip/mP+/tVqnsPM/rcQIEQrxw== X-Received: by 2002:a62:87cc:0:b0:576:dc40:6db9 with SMTP id i195-20020a6287cc000000b00576dc406db9mr15885822pfe.13.1670839791435; Mon, 12 Dec 2022 02:09:51 -0800 (PST) From: Viresh Kumar To: xen-devel@lists.xen.org, Juergen Gross , Julien Grall , Anthony PERARD Cc: Viresh Kumar , Vincent Guittot , =?utf-8?q?Alex_Benn=C3=A9e?= , Stefano Stabellini Subject: [PATCH V8 2/3] xl: Add support to parse generic virtio device Date: Mon, 12 Dec 2022 15:35:54 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 This patch adds basic support for parsing generic Virtio backend. An example of domain configuration for mmio based Virtio I2C device is: virtio = ["type=virtio,device22,transport=mmio"] Signed-off-by: Viresh Kumar --- tools/ocaml/libs/xl/genwrap.py | 1 + tools/xl/xl_parse.c | 81 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 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 = [ ("list", ["ctx", "domid", "t list"]), functions = { # ( 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/xl/xl_parse.c b/tools/xl/xl_parse.c index 644ab8f8fd36..853e9f357a1a 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1208,6 +1208,83 @@ static void parse_vkb_list(const XLU_Config *config, if (rc) exit(EXIT_FAILURE); } +static int parse_virtio_config(libxl_device_virtio *virtio, char *token) +{ + char *oparg; + int rc; + + if (MATCH_OPTION("backend", token, oparg)) { + virtio->backend_domname = strdup(oparg); + } else if (MATCH_OPTION("type", token, oparg)) { + virtio->type = strdup(oparg); + } else if (MATCH_OPTION("transport", token, oparg)) { + rc = libxl_virtio_transport_from_string(oparg, &virtio->transport); + if (rc) return rc; + } 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 = NULL, *oparg, *str = NULL; + int rc; + + if (!xlu_cfg_get_list (config, "virtio", &virtios, 0, 0)) { + int entry = 0; + while ((item = xlu_cfg_get_listitem(virtios, entry)) != NULL) { + libxl_device_virtio *virtio; + char *p; + + virtio = ARRAY_EXTEND_INIT(d_config->virtios, d_config->num_virtios, + libxl_device_virtio_init); + + buf = strdup(item); + + p = strtok(buf, ","); + while (p != NULL) + { + while (*p == ' ') p++; + + // Type may contain a comma, do special handling. + if (MATCH_OPTION("type", p, oparg)) { + if (!strncmp(oparg, "virtio", strlen("virtio"))) { + char *p2 = strtok(NULL, ","); + str = malloc(strlen(p) + strlen(p2) + 2); + + strcpy(str, p); + strcat(str, ","); + strcat(str, p2); + p = str; + } + } + + rc = parse_virtio_config(virtio, p); + if (rc) goto out; + + free(str); + str = NULL; + p = 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, @@ -2753,6 +2830,10 @@ void parse_config_data(const char *config_source, parse_vkb_list(config, d_config); + d_config->virtios = NULL; + d_config->num_virtios = 0; + parse_virtio_list(config, d_config); + xlu_cfg_get_defbool(config, "xend_suspend_evtchn_compat", &c_info->xend_suspend_evtchn_compat, 0); From patchwork Mon Dec 12 10:05:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 13070899 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 3CC1EC4167B for ; Mon, 12 Dec 2022 10:10:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.459358.717104 (Exim 4.92) (envelope-from ) id 1p4fl0-0003jD-7i; Mon, 12 Dec 2022 10:09:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 459358.717104; Mon, 12 Dec 2022 10:09:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p4fl0-0003j3-4v; Mon, 12 Dec 2022 10:09:58 +0000 Received: by outflank-mailman (input) for mailman id 459358; Mon, 12 Dec 2022 10:09:57 +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 1p4fky-000356-Tw for xen-devel@lists.xen.org; Mon, 12 Dec 2022 10:09:57 +0000 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [2607:f8b0:4864:20::102d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 20434934-7a05-11ed-8fd2-01056ac49cbb; Mon, 12 Dec 2022 11:09:56 +0100 (CET) Received: by mail-pj1-x102d.google.com with SMTP id u5so11467589pjy.5 for ; Mon, 12 Dec 2022 02:09:56 -0800 (PST) Received: from localhost ([122.172.87.149]) by smtp.gmail.com with ESMTPSA id ij28-20020a170902ab5c00b00177faf558b5sm5910850plb.250.2022.12.12.02.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 02:09:54 -0800 (PST) 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: 20434934-7a05-11ed-8fd2-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=qTElSs9N8xx49WAzju81gXq5LYR4Uou2wisGAI9T00k=; b=EF3qY8M304UEl9w7u6V5aWCv5LqcgvqRTPu/w8W/MZtkxrpg48T8YoZcjpcHGBTm6R BU3h27QIl4sr7ECPDstwiG1buv/p5HfUlrRn/qJr6KtFC5NzPsiN0G+JagQlaiqNKHF6 K6MmoPervSFTFi5LGLoZLRYTsP1nemMAsxoSVZHxAdrPZwa79MfxFulOXM5exkdd6Wn2 6VI7bG72g4bBNfvG3CXmFORDF4KGpSBi+MPSkLi5Irh1DKwEEpzQpY3QtbSsXsIhEznn jcrbx8di/OECqlHF5oYB1j8YoPEf7GizXoXNHzrF9u6k3T+eDz3U5PmAU28JfY057A9F 5OLg== 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=qTElSs9N8xx49WAzju81gXq5LYR4Uou2wisGAI9T00k=; b=J2HRABVx5nz//mPrAbCLxdbv14RjdqRQgJy9mrcjy8oVkC0T/N0YQVUwKfAlyKN4Vb fkbcb5Brk696T2ai2J2L4RZfPJG8fN5sHMQulF+wU5+yAb3IEqq7HSI2ws9fXsJcD1X3 vfNonsYQ3zW3AM7cP7IviOXXFe/inaAcVB3q4GyM0PsW7siVitjlZl3CNE4kILQcnztG FdxWz/rI7Q8ooyzjSenT2bMQdlRKQ6eiLVuTNOn7TdD8pa7Iqv4hJYKOQy96rnzScDmQ qKhrJJ0XwadNTN1vuKFMKgf713FJPQHt+zf/KC4wD9cRj6XhVhJhx1ipr905mOD5CbdN KWyA== X-Gm-Message-State: ANoB5pkGxSwJIJvY+LCHm3H/je6bhzXWgWMN/ULNgaNIjFdpIZiaSKRj LGfizxjH5A+jERwkYibY1EYZz2jqJskjhAyO X-Google-Smtp-Source: AA0mqf5Y4o5w8FyCRHm+mENBFXVvZgkuokIgMrpop/Ld1lh/qOOPHnqghmPpyB1ckw7q/lIIe27TPA== X-Received: by 2002:a17:902:f78f:b0:188:59e2:5f91 with SMTP id q15-20020a170902f78f00b0018859e25f91mr18295517pln.59.1670839794768; Mon, 12 Dec 2022 02:09:54 -0800 (PST) From: Viresh Kumar To: xen-devel@lists.xen.org, Juergen Gross , Julien Grall , Anthony PERARD Cc: Viresh Kumar , Vincent Guittot , =?utf-8?q?Alex_Benn=C3=A9e?= , Stefano Stabellini Subject: [PATCH V8 3/3] docs: Add documentation for generic virtio devices Date: Mon, 12 Dec 2022 15:35:55 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 This patch updates xl.cfg man page with details of generic Virtio device related information. Signed-off-by: Viresh Kumar Reviewed-by: Anthony PERARD --- docs/man/xl.cfg.5.pod.in | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index ec444fb2ba79..024bceeb61b2 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1585,6 +1585,39 @@ Set maximum height for pointer device. =back +=item 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. As a special case, a single comma is allowed in the +VALUE of the "type" KEY, where the VALUE is set with "virtio,device". + +=over 4 + +=item B + +Specifies the backend domain name or id, defaults to dom0. + +=item B + +Specifies the compatible string for the specific Virtio device. The same will be +written in the Device Tree compatible property of the Virtio device. For +example, "type=virtio,device22" for the I2C device, whose device-tree binding is +present here: + +L + +For generic virtio devices, where we don't need to set special or compatible +properties in the Device Tree, the type field must be set to "virtio,device". + +=item B + +Specifies the transport mechanism for the Virtio device, only "mmio" is +supported for now. + +=back + =item B B Set TEE type for the guest. TEE is a Trusted Execution