From nobody Thu Nov 28 11:00:04 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=1670926181; cv=none; d=zohomail.com; s=zohoarc; b=fF6od2aLJ9OKRuZPMMOLtKG/AckOJkUf6NCb6XkqZKQ4wwhmr34xcNbdMlu64ej5aj23ohlqM3jttQt1X8Uxgx/88RVn1E6d1q8flQiMpgPW0151kaYPy/GiqZlAbSPu5S+59GEvBTs6cyJxqys8GRmUuIzdSjJsrFK5IC+HLJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670926181; 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=mTZu0m+CtVcg3lIpWEuYY6mdYbQncXJ7Pol70g22OOU=; b=DryGmRpDHaD+luayLLOsF15oBEpjIzF3rt4pv5+JD9PHaV0Hh9xi1tUTJfR0EGBW8Tr72+tav8kdCMgUSqumAQ0DZl8vSHz0d/aT1aF/6HcCGVOrBMBr3ONsV0y7u8Ky6JWeDXEjbRPqI7a9E0yMLbSyqRCC6wzXy5barq+My9g= 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 16709261810791021.0384227520469; Tue, 13 Dec 2022 02:09:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.460391.718295 (Exim 4.92) (envelope-from ) id 1p52Db-00008t-B4; Tue, 13 Dec 2022 10:08:59 +0000 Received: by outflank-mailman (output) from mailman id 460391.718295; Tue, 13 Dec 2022 10:08:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p52Db-00008m-7x; Tue, 13 Dec 2022 10:08:59 +0000 Received: by outflank-mailman (input) for mailman id 460391; Tue, 13 Dec 2022 10:08:58 +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 1p52Da-0008Kk-HI for xen-devel@lists.xen.org; Tue, 13 Dec 2022 10:08:58 +0000 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [2607:f8b0:4864:20::1030]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7f62006a-7acd-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 11:04:15 +0100 (CET) Received: by mail-pj1-x1030.google.com with SMTP id js9so2886003pjb.2 for ; Tue, 13 Dec 2022 02:08:57 -0800 (PST) Received: from localhost ([122.172.87.149]) by smtp.gmail.com with ESMTPSA id n10-20020a170902e54a00b00186ff402508sm8015004plf.281.2022.12.13.02.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 02:08:54 -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: 7f62006a-7acd-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=mTZu0m+CtVcg3lIpWEuYY6mdYbQncXJ7Pol70g22OOU=; b=KFukmjS53RU0JdTYkmBWL357JRG/21ARUmwmaBm1TlzA8StyRKPj42uJYqBRG1eQOT NfjMqsUG0s2vgQsn/yFnTbGGifHS9xQDvLRsnX90KAQm63m9MHY98QkkeV/SwCjHd0i0 28Bn655MtjvhxZJJhHquMRKI4iZyloyRyutV6YAyAlJTENMya8ETkNDgsspwj3y/WDBK GQ6FLsc9vJ+ETKR1z9b0A5j9OJK23WnpCsfKtBxQ6kixkwCmhn9EjpjVXRwH4vkxGnLH ZaJ3TLRAOd5rFiIv7lWPyXkRwnE6nXUobYJ0QOULvu40HTlZSpoTqBElNyqOlDIxsjnz Djfw== 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=mTZu0m+CtVcg3lIpWEuYY6mdYbQncXJ7Pol70g22OOU=; b=imweCmQVT2w8RT7jMqj+vbdbjV6pOxMBPxJmN/HCvAPj3OAmvLDF61cJsunaUdlWO0 9HeqQlLbsUO8FhVnmfmZMFeEZERzL+NIpNjgpsMSUGPsm0a1ETCYmVpJwUEHUiYvz4uM b5jLE9KBvXoslsbNkSe8VE60X7/lsZU/RscIrEY2iHwF03+CSOX+038uz5sJtj76Cvh/ VqRZS8QRIBR+t66Dv7WAJjIh6rRBB3KYkt7ETTRAZPfTkDc7Q3KRkMh5eol3aMm8VCJF I0dZCHUFBOwNuMPcQBNj05E438DS1bU7xSt58DIbqkE9FpFT68p4KKb+i0Nn7tCFkeqy Du1Q== X-Gm-Message-State: ANoB5plaVsBe3hG9NZHFdnqngK2DqyH5/ZFZCSWMOUCyAxZtaUD24gBd jJX7HCKpL6USvB3tyizua2Py3QbziCW1q/yv X-Google-Smtp-Source: AA0mqf7AgQdDN6Uqc0psd4UQTpisXQ5HkHH+MWsVU041Thb+OPk4Uh20sq+AjarQ5+eqK98jcks+Pg== X-Received: by 2002:a17:902:f80e:b0:189:a520:2ff0 with SMTP id ix14-20020a170902f80e00b00189a5202ff0mr19761339plb.34.1670926135525; Tue, 13 Dec 2022 02:08:55 -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 , Oleksandr Tyshchenko Subject: [PATCH V9 1/3] libxl: Add support for generic virtio device Date: Tue, 13 Dec 2022 15:38:46 +0530 Message-Id: <01dfa7692457a7f40255645f5239f74797e6db3a.1670925998.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: 1670926183166100003 Content-Type: text/plain; charset="utf-8" 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 =3D ["type=3Dvirtio,device22,transport=3Dmmio"] 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. Reviewed-by: Anthony PERARD Reviewed-by: Oleksandr Tyshchenko Signed-off-by: Viresh Kumar --- 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 +=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 fa3d61f1e882..ddc7b2a15975 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. @@ -956,6 +969,79 @@ static int make_virtio_mmio_node(libxl__gc *gc, void *= fdt, uint64_t base, return fdt_end_node(fdt); } =20 +/* + * The DT bindings for I2C device are present here: + * + * https://www.kernel.org/doc/Documentation/devicetree/bindings/i2c/i2c-vi= rtio.yaml + */ +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_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 =3D fdt_begin_node(fdt, "gpio"); + if (res) return res; + + res =3D fdt_property_compat(gc, fdt, 1, VIRTIO_DEVICE_TYPE_GPIO); + 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; + + res =3D 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 =3D make_virtio_mmio_node_i2c(gc, fdt); + if (res) return res; + } else if (!strcmp(type, VIRTIO_DEVICE_TYPE_GPIO)) { + res =3D 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 *do= m) { @@ -1277,6 +1363,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) ); + } + /* * 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_creat= e.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, lib= xl__multidev *multidev, libxl__device_add(gc, domid, &libxl__pvcallsif_devtype, &d_config->pvcallsifs[i]); =20 + for (i =3D 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_int= ernal.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) =20 +/* 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 er= rnoval, const char *file /* may be 0 */, int line /* ignored if !file= */, @@ -4003,6 +4008,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 9e3d33cb5a59..0cfad8508dbd 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -278,6 +278,11 @@ libxl_vkb_backend =3D Enumeration("vkb_backend", [ (2, "LINUX") ]) =20 +libxl_virtio_transport =3D Enumeration("virtio_transport", [ + (0, "UNKNOWN"), + (1, "MMIO"), + ]) + libxl_passthrough =3D Enumeration("passthrough", [ (0, "default"), (1, "disabled"), @@ -703,6 +708,18 @@ 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), + ("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 =3D Struct("device_disk", [ ("backend_domid", libxl_domid), ("backend_domname", string), @@ -980,6 +997,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")), 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..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 =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, *tmp =3D NULL; + 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__backendpath_parse_domid(gc, be_path, &virtio->backend_do= mid); + 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); + } + + tmp =3D NULL; + 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); + } + + tmp =3D NULL; + rc =3D 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 =3D LIBXL_VIRTIO_TRANSPORT_MMIO; + } else { + return ERROR_INVAL; + } + } + + tmp =3D NULL; + rc =3D libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/type", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + int len =3D sizeof(VIRTIO_DEVICE_TYPE_GENERIC) - 1; + + if (!strncmp(tmp, VIRTIO_DEVICE_TYPE_GENERIC, len)) { + virtio->type =3D 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 =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 Thu Nov 28 11:00:04 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=1670926308; cv=none; d=zohomail.com; s=zohoarc; b=Cj2Zjeps7NMfI2aLlqKhOsfiSNTeKzFjD9q/ts2HozHAgdutqH/QdQnBLRFK1sJPNGKrUqbd1VL8sjE+RDGPYOZVtrDPxq2cRZbJZAsrRDch319cvyjF2M4p2088Uwgk3gIPrzHobkVHIZv9ntBiOmWXa8ga0ajgtY3BBWDsMzE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670926308; 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=vXqoRJdEJYKdn1X+SDtx30T59nlBol+wjpDAJ9IO1pU=; b=inuNzqAT88RA+dZpKumXGPsajiLotbHihSYHRgO2mw2dUqIWnKJJcE8BjT5qKUnIUzTGvBf8BL0d/tvlnYeyjARosvOPu8bnN19pv916HWssKyylgOTcJMKu4YNPVGotEydTnsz0cJMlUNoiOz0AiClRvbPI4epUCfGfNaR/UMA= 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 167092630888150.96992138504481; Tue, 13 Dec 2022 02:11:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.460408.718317 (Exim 4.92) (envelope-from ) id 1p52Fk-0002Pd-6L; Tue, 13 Dec 2022 10:11:12 +0000 Received: by outflank-mailman (output) from mailman id 460408.718317; Tue, 13 Dec 2022 10:11:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p52Fk-0002PW-3k; Tue, 13 Dec 2022 10:11:12 +0000 Received: by outflank-mailman (input) for mailman id 460408; Tue, 13 Dec 2022 10:11:10 +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 1p52Fi-0002PB-5S for xen-devel@lists.xen.org; Tue, 13 Dec 2022 10:11:10 +0000 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [2607:f8b0:4864:20::52f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2940d26c-7ace-11ed-91b6-6bf2151ebd3b; Tue, 13 Dec 2022 11:10:41 +0100 (CET) Received: by mail-pg1-x52f.google.com with SMTP id 62so10069553pgb.13 for ; Tue, 13 Dec 2022 02:10:15 -0800 (PST) Received: from localhost ([122.172.87.149]) by smtp.gmail.com with ESMTPSA id q18-20020aa79832000000b005745635c5b5sm7319649pfl.183.2022.12.13.02.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 02:08:58 -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: 2940d26c-7ace-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=vXqoRJdEJYKdn1X+SDtx30T59nlBol+wjpDAJ9IO1pU=; b=aE7AlhS8CgiEtCGbMGnU/ptP0rTc82SENRGLfLbOy4cE3BNmEMTvP3xN2bM1/+QBGF JTvhcik719IsAk1k7kAoWvQSlIpPeUWl//gy3+BB7G0LLYBi2pKjEA/BffcrGpwKDMGT 5qdKhnSBTJVQAq1biGJjQ/Y8oG085gWBVVslABKQ36kR93ro3e39/RUExL/hqLnIx83K cfx3bXtW6vDrTF1lPulqjtBClPLmYiA2WpgEE5tDXBiOTIb9rZ9lO4mBt5W1R+xlvcDo 3q0Kp/arsZB67mVU466ddIO0XoUIQuYM6ppJMNu5SidTfQUwaKiCXRa8lyax/dV5PO9s JfNg== 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=vXqoRJdEJYKdn1X+SDtx30T59nlBol+wjpDAJ9IO1pU=; b=RQRRP4KxI4rq/4D5fra+DZuI0kbiFKaxKUaxHI/DzdKGeDXCvXs+SdmQE/6EPpv752 WI77hGV9+esp07jc0beIesSLKTq2WylzW+VvebiK/9a9FQm2vwQan15UC2vkU0yi8eJ9 hLbJu2ycef4O+jPKH1Vjtu4QwNLJ+nJC4Y3BLYmBEiuYOtAc8Wce/xi2wLn5vS/KK5YS wOicU7RMC9GpLJcYrOLSQ8hhnb7m+EpOKX9mI+viwZ7R3hBtXijbzwU3pyVDJ8nshRzP o4GRfypELP8pD2cCe/8fnRMaau/+bfVoB1tTXlIYhMEzCoF4CoEAtisGkAX08tddG3t1 vPOQ== X-Gm-Message-State: ANoB5plUngysryhGJdl9EnET4jwPaiemOERjA2VCxKdGFs3Sa3zIwr6s fDOMprs0V9M5Vq8sgw9idII+a/lkt7ajNuUx X-Google-Smtp-Source: AA0mqf7+39FAJZsI44hx/oCohVMvUC0nXhz3ahrFNjHR+3KrnEo/vp4OPA64ktQeWDAzTCHTsEqMmg== X-Received: by 2002:a62:870d:0:b0:576:f02e:d0ef with SMTP id i13-20020a62870d000000b00576f02ed0efmr18610880pfe.4.1670926138720; Tue, 13 Dec 2022 02:08:58 -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 V9 2/3] xl: Add support to parse generic virtio device Date: Tue, 13 Dec 2022 15:38:47 +0530 Message-Id: <9822fd35c2b072da0fcdc37fc029c67d5543c716.1670925998.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: 1670926310001100001 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 Reviewed-by: Anthony PERARD --- tools/xl/xl_parse.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) 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); } =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 { + 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, @@ -2753,6 +2830,10 @@ void parse_config_data(const char *config_source, =20 parse_vkb_list(config, d_config); =20 + d_config->virtios =3D NULL; + d_config->num_virtios =3D 0; + parse_virtio_list(config, d_config); + xlu_cfg_get_defbool(config, "xend_suspend_evtchn_compat", &c_info->xend_suspend_evtchn_compat, 0); =20 --=20 2.31.1.272.g89b43f80a514 From nobody Thu Nov 28 11:00:04 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=1670926185; cv=none; d=zohomail.com; s=zohoarc; b=DvqP43ugCARxOxxmccqfpj4KUwrZr6jLMqJOx1J2+7BBR2S0kiypeCyEnoMmgEGMttpW0FwgKEKcdx/4uI9GVuZTlGL7yqFt7fkMeamiRAzdbq0FAtpzvodMb6Luc1to2cIQrKlU0M3x1vVcEpjHFCetH3DRH+fkL2eNMjwdxMg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670926185; 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=+7t/bITPAutPCDFaVHnpGALOK3FXJdmGHlDPnk3jI8E=; b=Zw53HXohg0JMpX6pwiDPLs87LrCd46FUISVtc5NI2WeMCUewUV6LyF/2LzqX8SERwpM466ba1SJbXA1Ki73SWJ8lYfTvyev3N+POGhf8m579w/PXNBwl3netf80IZW32Jzrw4dwsipx000SnRC5xF6Kgim57pxoqDGjzw8ONqMQ= 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 1670926185095122.12110607765169; Tue, 13 Dec 2022 02:09:45 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.460392.718306 (Exim 4.92) (envelope-from ) id 1p52Dh-0000TH-KA; Tue, 13 Dec 2022 10:09:05 +0000 Received: by outflank-mailman (output) from mailman id 460392.718306; Tue, 13 Dec 2022 10:09:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p52Dh-0000TA-Gz; Tue, 13 Dec 2022 10:09:05 +0000 Received: by outflank-mailman (input) for mailman id 460392; Tue, 13 Dec 2022 10:09:04 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p52Df-0008Kk-UF for xen-devel@lists.xen.org; Tue, 13 Dec 2022 10:09:04 +0000 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [2607:f8b0:4864:20::1035]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8300234d-7acd-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 11:04:21 +0100 (CET) Received: by mail-pj1-x1035.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so2996126pjs.4 for ; Tue, 13 Dec 2022 02:09:03 -0800 (PST) Received: from localhost ([122.172.87.149]) by smtp.gmail.com with ESMTPSA id je19-20020a170903265300b00186b3c3e2dasm8022658plb.155.2022.12.13.02.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 02:09:01 -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: 8300234d-7acd-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=+7t/bITPAutPCDFaVHnpGALOK3FXJdmGHlDPnk3jI8E=; b=T6ILUYBJz8OYkA6h7aQqiHbdX/YufqnqVpUSrm46+PeL+wKskAseHPC9SD1qxUVjUU 5P8voGXKEmyspxViIvC3nb9bLhzYmy9Iu2fiFJLkC9C6cj1clKZKP2z5wuBNTgztltoP HmqQVP5yZhsIRSuVNu72NGAqtaBXoG1UE6AXG5HAfeweGRIs0suXf+SafE2qyAQfSX+X /Vu1ZTNxQtHtIS4FM2B1mSStascJbxis73+wlu7qiUX+9LDBOy8zwVAusslltRNnHYQJ gFwxWFbkVdsACxyWMaBbRVPqQCxw45xXk1SHs0Mys1vOBICCfgSq9pvV+C/ebAKVxkca CS/Q== 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=+7t/bITPAutPCDFaVHnpGALOK3FXJdmGHlDPnk3jI8E=; b=vCLkqD0IYHRdbbtomKfVsF0NqV7mRBeg+SJ2AFYMlw/PkDgXREQna8yffVRZRKHtMJ 8Q97I1pMvzC8UseLn2yWtZJHayKGQuoRXgHg+AIZbdGz7jw79vGZQUw2X9ECJUN0WqfG h+YsCkdiB9X05EMW87XpSpu7/OXeUNIAv0Zh3dzCUGu+zPcCTly4xP9kBY4hbFj3U+tB fNc2VuJMEgXw0bZe3A4kvNFuqLVXGv+OJOPHeQGHO3IjB/TZrTwRue20miGYdd8vp0Xg yoYdTEn//Kqpx+S05Qp6g0/02HJj373GOfRmwe1/MCEJyUaGTlCL3YUqyYwL2y2qXnqO 6CdA== X-Gm-Message-State: ANoB5pkrX0HPypHpI6lQ7w5EUTGDBwIZ0aRARhD2+N+FVFiHXAKQJE0O z6+OvDPqaAnJL8bI+DCrhrBzXWtp9HwDAK4S X-Google-Smtp-Source: AA0mqf7l+e1nb0jNYgH2yyzVnU1MdvImLWlvmag1vywWbAq22hfdLiuB2CN9FgOjV3n0e+SaULmc3A== X-Received: by 2002:a17:903:2448:b0:189:f277:3830 with SMTP id l8-20020a170903244800b00189f2773830mr29937549pls.68.1670926141782; Tue, 13 Dec 2022 02:09:01 -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 V9 3/3] docs: Add documentation for generic virtio devices Date: Tue, 13 Dec 2022 15:38:48 +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: 1670926187277100001 Content-Type: text/plain; charset="utf-8" This patch updates xl.cfg man page with details of generic Virtio device related information. Reviewed-by: Anthony PERARD Signed-off-by: Viresh Kumar Reviewed-by: Oleksandr Tyshchenko --- 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. =20 =3Dback =20 +=3Ditem B + +Specifies the Virtio devices to be provided to the guest. + +Each B is a comma-separated list of C s= ettings +from the following list. As a special case, a single comma is allowed in t= he +VALUE of the "type" KEY, where the VALUE is set with "virtio,device". + +=3Dover 4 + +=3Ditem B + +Specifies the backend domain name or id, defaults to dom0. + +=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, whose device-tree bi= nding is +present here: + +L + +For generic virtio devices, where we don't need to set special or compatib= le +properties in the Device Tree, the type field must be set to "virtio,devic= e". + +=3Ditem B + +Specifies the transport mechanism for the Virtio device, only "mmio" is +supported for now. + +=3Dback + =3Ditem B =20 B Set TEE type for the guest. TEE is a Trusted Execution --=20 2.31.1.272.g89b43f80a514