From patchwork Mon Nov 27 07:32:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13469253 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 412A8C4167B for ; Mon, 27 Nov 2023 07:38:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.641647.1000398 (Exim 4.92) (envelope-from ) id 1r7WBv-0001An-EO; Mon, 27 Nov 2023 07:38:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 641647.1000398; Mon, 27 Nov 2023 07:38:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r7WBv-0001Ag-BD; Mon, 27 Nov 2023 07:38:03 +0000 Received: by outflank-mailman (input) for mailman id 641647; Mon, 27 Nov 2023 07:38:01 +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 1r7WBt-00019G-TV for xen-devel@lists.xenproject.org; Mon, 27 Nov 2023 07:38:01 +0000 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e36b66e6-8cf7-11ee-98e2-6d05b1d4d9a1; Mon, 27 Nov 2023 08:38:00 +0100 (CET) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 1C7EE1A5A6; Mon, 27 Nov 2023 02:37:59 -0500 (EST) (envelope-from sakib@darkstar.site) Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 13B171A5A5; Mon, 27 Nov 2023 02:37:59 -0500 (EST) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [188.163.75.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id A0B661A5A4; Mon, 27 Nov 2023 02:37:54 -0500 (EST) (envelope-from sakib@darkstar.site) 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: e36b66e6-8cf7-11ee-98e2-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=/Z6kaeEKawpzWl9Eo1m8IbkY5 KCnWj8r3LTFolwrXyg=; b=CgYzO7Qbsw3D7wjBW12uiZp86cQ3nJuYdPlOr68+G eTVZjOJYaLoy4LRWeCtPI5pJOiR6nOhRtVdTkZuWPttAc5fvDqTVA5KUjxAQVSt9 IYzit7HhTfuojt70/VlwVRhl4VpRqB4PPYVoCNLZCXzbZpGefy7ADE5stpLl3W6X bg= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org, Julien Grall Cc: Oleksandr Tyshchenko , Stefano Stabellini , Volodymyr Babchuk , Stewart Hildebrand , Juergen Gross , Wei Liu , Anthony PERARD , Sergiy Kibrik Subject: [RFC PATCH v1 5/5] libxl: Add "backend_type" property for the Virtio devices Date: Mon, 27 Nov 2023 09:32:21 +0200 Message-Id: <20231127073221.4046427-2-Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231127073221.4046427-1-Sergiy_Kibrik@epam.com> References: <20231127072754.4045254-1-Sergiy_Kibrik@epam.com> <20231127073221.4046427-1-Sergiy_Kibrik@epam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: E085CC4E-8CF7-11EE-9B4A-A19503B9AAD1-90055647!pb-smtp21.pobox.com From: Oleksandr Tyshchenko Introduce new configuration option "backend_type" for the Virtio devices in order to specify backend implementation to use. There are two possible values "qemu" (default) and "standalone". If backend is in Qemu (backend_type=qemu) and Qemu runs in toolstack domain (backend=Domain-0) then Qemu will be launched automatically at the guest creation time. For this to work implement "dm_needed" callback. Please note, there is no support for Qemu in other domains for the time being, so the combination of "backend=DomD" and "backend_type=qemu" just won't work. Qemu configuration for Virtio devices should be described via "device_model_args" property. Signed-off-by: Oleksandr Tyshchenko Signed-off-by: Sergiy Kibrik Reviewed-by: Juergen Gross --- docs/man/xl.cfg.5.pod.in | 9 +++++++++ tools/libs/light/libxl_types.idl | 7 +++++++ tools/libs/light/libxl_virtio.c | 29 ++++++++++++++++++++++++++++- tools/xl/xl_parse.c | 3 +++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 0fba750815..592aad1d1e 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -1624,6 +1624,15 @@ are supported. This option is mandatory. The Virtio device with transport "pci" must be identified by its B. See L for more details about the format for B. +=item B + +Specifies the software implementation of the backend implementation to use. +This option doesn't affect the guest's view of the Virtio device. + +Both "qemu" and "standalone" are supported. The only difference is +that for the former the toolstack assists with configuring and launching +the device-model. If this option is missing, then "qemu" value will be used. + =item B If this option is B, the Xen grants are always enabled. diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl index a86c601994..13b8ade41c 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -284,6 +284,12 @@ libxl_virtio_transport = Enumeration("virtio_transport", [ (2, "PCI"), ]) +libxl_virtio_backend = Enumeration("virtio_backend", [ + (0, "UNKNOWN"), + (1, "QEMU"), + (2, "STANDALONE"), + ]) + libxl_passthrough = Enumeration("passthrough", [ (0, "default"), (1, "disabled"), @@ -778,6 +784,7 @@ libxl_device_vkb = Struct("device_vkb", [ libxl_device_virtio = Struct("device_virtio", [ ("backend_domid", libxl_domid), ("backend_domname", string), + ("backend_type", libxl_virtio_backend), ("type", string), ("u", KeyedUnion(None, libxl_virtio_transport, "transport", [("unknown", None), diff --git a/tools/libs/light/libxl_virtio.c b/tools/libs/light/libxl_virtio.c index 8062423c75..339a2006f0 100644 --- a/tools/libs/light/libxl_virtio.c +++ b/tools/libs/light/libxl_virtio.c @@ -32,9 +32,20 @@ static int libxl__device_virtio_setdefault(libxl__gc *gc, uint32_t domid, libxl_defbool_setdefault(&virtio->grant_usage, virtio->backend_domid != LIBXL_TOOLSTACK_DOMID); + if (virtio->backend_type == LIBXL_VIRTIO_BACKEND_UNKNOWN) + virtio->backend_type = LIBXL_VIRTIO_BACKEND_QEMU; + return 0; } +static int libxl__device_virtio_dm_needed(void *e, unsigned domid) +{ + libxl_device_virtio *elem = e; + + return elem->backend_type == LIBXL_VIRTIO_BACKEND_QEMU && + elem->backend_domid == domid; +} + static int libxl__device_from_virtio(libxl__gc *gc, uint32_t domid, libxl_device_virtio *virtio, libxl__device *device) @@ -55,7 +66,8 @@ static int libxl__set_xenstore_virtio(libxl__gc *gc, uint32_t domid, flexarray_t *back, flexarray_t *front, flexarray_t *ro_front) { - const char *transport = libxl_virtio_transport_to_string(virtio->transport); + const char *transport = libxl_virtio_transport_to_string(virtio->transport), + *backend = libxl_virtio_backend_to_string(virtio->backend_type); if (virtio->transport == LIBXL_VIRTIO_TRANSPORT_MMIO) { flexarray_append_pair(back, "irq", GCSPRINTF("%u", virtio->u.mmio.irq)); @@ -74,6 +86,7 @@ static int libxl__set_xenstore_virtio(libxl__gc *gc, uint32_t domid, } flexarray_append_pair(back, "type", GCSPRINTF("%s", virtio->type)); flexarray_append_pair(back, "transport", GCSPRINTF("%s", transport)); + flexarray_append_pair(back, "backend_type", GCSPRINTF("%s", backend)); flexarray_append_pair(back, "grant_usage", libxl_defbool_val(virtio->grant_usage) ? "1" : "0"); @@ -166,6 +179,19 @@ static int libxl__virtio_from_xenstore(libxl__gc *gc, const char *libxl_path, } } + tmp = NULL; + rc = libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/backend_type", be_path), &tmp); + if (rc) goto out; + + if (tmp) { + rc = libxl_virtio_backend_from_string(tmp, &virtio->backend_type); + if (rc) { + LOG(ERROR, "Unable to parse xenstore node %s/backend_type", be_path); + goto out; + } + } + tmp = NULL; rc = libxl__xs_read_checked(gc, XBT_NULL, GCSPRINTF("%s/grant_usage", be_path), &tmp); @@ -200,6 +226,7 @@ static LIBXL_DEFINE_UPDATE_DEVID(virtio) #define libxl_device_virtio_compare NULL DEFINE_DEVICE_TYPE_STRUCT(virtio, VIRTIO, virtios, + .dm_needed = libxl__device_virtio_dm_needed, .set_xenstore_config = (device_set_xenstore_config_fn_t) libxl__set_xenstore_virtio, .from_xenstore = (device_from_xenstore_fn_t)libxl__virtio_from_xenstore, diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 4544ce2307..234cef5f7e 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1215,6 +1215,9 @@ static int parse_virtio_config(libxl_device_virtio *virtio, char *token) } else if (MATCH_OPTION("transport", token, oparg)) { rc = libxl_virtio_transport_from_string(oparg, &virtio->transport); if (rc) return rc; + } else if (MATCH_OPTION("backend_type", token, oparg)) { + rc = libxl_virtio_backend_from_string(oparg, &virtio->backend_type); + if (rc) return rc; } else if (MATCH_OPTION("grant_usage", token, oparg)) { libxl_defbool_set(&virtio->grant_usage, strtoul(oparg, NULL, 0)); } else if (MATCH_OPTION("bdf", token, oparg)) {