From patchwork Mon Jul 10 15:35:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 701039 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5246478wrs; Mon, 10 Jul 2023 08:44:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlFEQafFTZI/EjqzJvsw1ytWVtnSfdv58tG2sYsWHfwNqMWnrH9NF2HjhL0AUGxXYCFcRirf X-Received: by 2002:a05:620a:448b:b0:767:dc58:f256 with SMTP id x11-20020a05620a448b00b00767dc58f256mr1033519qkp.70.1689003867095; Mon, 10 Jul 2023 08:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003867; cv=none; d=google.com; s=arc-20160816; b=g+o/uhF3fP+v16FMjsj+wW5orouv4HLv0JTvLhyClcvwSYa7UXO6NMieUK/lm9Ygdn vtRUiGsVNJr3kuAprEvYPbvJJsQp+vWpofUsRIFCBrfLzhkiIrZV0IuctoXplDBz26pa xDqnWsBLgCFmU7wVas++bu8OZPaJuK5cy7+iwdzzoDuNx80I0e9wQtPN++U0oP9SM4PZ oJN+hGwGsWrSgyNlNbco+pO/KR0r2+F2HjCxHxvwbGH+CvQx8N+RUaDWWeXKrEYZD6pz WSGOCI7RrMngGFl1y15Td86lppimg1SCeXY59rxIo3igBiUfn96NXgonrdHCQt/8Czze KsrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IVoZ+61FKCrNdklMoUuKRwdzJcWCiwu+9oFevqFhgNQ=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=JwJBGLsCNbiOqRjztWAaH0mc5Hu3d8v1IJJj2Lfq+b2Id8Bxs/x5wUohLqX+3K7zDO Z1fTIpeLxvfE0l8VqGzh8DtQT2h9KGAqSYHw87S29iT8uo9VpRVQ2tViTOGCIkGncnFG FzVnm5cFKwWUoUWGcr4U6dmn5i6UppYo5v7sC5nNFo0Amc+wnmL/tdYbLRoQfdpw7EzM yTcB26iJJ1ZpUTfh+dSY2Nr13lJYDpYfdWGte5ZUwAfMN0OkcKRSf/wvFliaHUkWKcqV NEv9ZICKUxdR/DinqD5Pjv9FmCcoaD60Cu5tW/FQlOYX9GB1wNz2vJsvAQe2t6MVzHxd 6ntA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vr0iX5PB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id do46-20020a05620a2b2e00b00767d0ec9a2bsi1226994qkb.303.2023.07.10.08.44.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:44:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vr0iX5PB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIt30-0002ZO-A4; Mon, 10 Jul 2023 11:43:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIt2v-0002Xa-3s for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:29 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIt2q-0006MN-Mn for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:27 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fbc5d5742eso51989205e9.3 for ; Mon, 10 Jul 2023 08:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689003803; x=1691595803; 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=IVoZ+61FKCrNdklMoUuKRwdzJcWCiwu+9oFevqFhgNQ=; b=Vr0iX5PBlhO1Adj/4b7VlrHQkVn7GTOo5wyPKAYyOoIZEHmtrmf2CnnHEjUWaj3r5E gN1/wrYb3QfFv9cJ7Q+onYHROjTQ7g4Zk2+NvhwEx5lQUiRVDTA3Vspem0wuleZKlBTw HxZ5kfqcc4mZ5OGvHc4DKl1bxmJcccfgaf1hFufn/FOtw3wsH314q4Bjfx9ltnd83Dbg RvbJfwf39Lt2h6ddlusjcgwbBsceZCUeizDw6Aj5TX5ZaGT/rwtKPWaPWC5SFUqnexVj cNOLUD3riwHeX40BdeiIYBWMhiTu09Cv6qL4s4sfSUpe+/RCFyr7dZl0XKiMfrbRFWG9 2mtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689003803; x=1691595803; 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=IVoZ+61FKCrNdklMoUuKRwdzJcWCiwu+9oFevqFhgNQ=; b=M4XFUAq8ZIhWit1Fq4cxgw1uzJngQ5eqtvj8fV5RIkHub6nxswGFJmBPufglyYpwXu wv2VUDT6F+gEN78AavQsACpbBul0z7uQ9PWT0wZlnfn09HCblKuQFYj+dpTNaEHlO/zU IFN4aIBbhfr+u5fMVaKHMqHuvnivlUqLCsbbwAb2Bme+cs+P1gHsMR+hmSSVopLjUK3g FgVY4KBAukLkzSIseBH5AzaHy0aOFfn/9amhdRDwvDv7BededZ7lvprq70DcHGbrn/X6 P3rRFbH0+1nQKl8ngonVjhh0B8vpwwi1rHL0IsLAn+6BBXl5dFZoN1K1XoslKrN0tEEX oRSw== X-Gm-Message-State: ABy/qLbyv23JxHEHlR0OFn35V/J8x9RfUP+UIsaPdcUsN6x562Q3f2yc 2+6nf1jKEQq/DzcsA8zbdtT1oA== X-Received: by 2002:a7b:c5d6:0:b0:3f7:3991:e12e with SMTP id n22-20020a7bc5d6000000b003f73991e12emr12593197wmk.1.1689003803383; Mon, 10 Jul 2023 08:43:23 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id h5-20020adffd45000000b00313f07ccca4sm12027136wrs.117.2023.07.10.08.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 08:43:22 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8AFD81FFBC; Mon, 10 Jul 2023 16:35:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jason Wang , Viresh Kumar , Raphael Norwitz , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-block@nongnu.org, Eric Blake , "Michael S. Tsirkin" , Mark Cave-Ayland , Kevin Wolf , Markus Armbruster , Gerd Hoffmann , Mathieu Poirier , Hanna Reitz , =?utf-8?q?Alex_Benn=C3=A9e?= , Erik Schilling , "Gonglei (Arei)" , Eduardo Habkost , Fam Zheng , virtio-fs@redhat.com, Stefan Hajnoczi Subject: [RFC PATCH v3 20/20] hw/virtio: allow vhost-user-device to be driven by backend Date: Mon, 10 Jul 2023 16:35:22 +0100 Message-Id: <20230710153522.3469097-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org> References: <20230710153522.3469097-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Instead of requiring all the information up front allow the vhost_dev_init to complete and then see what information we have from the backend. This does change the order around somewhat. Signed-off-by: Alex Bennée --- hw/virtio/vhost-user-device.c | 45 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/hw/virtio/vhost-user-device.c b/hw/virtio/vhost-user-device.c index 0109d4829d..b30b6265fb 100644 --- a/hw/virtio/vhost-user-device.c +++ b/hw/virtio/vhost-user-device.c @@ -243,7 +243,6 @@ static void vub_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VHostUserBase *vub = VHOST_USER_BASE(dev); - int ret; if (!vub->chardev.chr) { error_setg(errp, "vhost-user-device: missing chardev"); @@ -254,13 +253,43 @@ static void vub_device_realize(DeviceState *dev, Error **errp) return; } + if (vhost_dev_init(&vub->vhost_dev, &vub->vhost_user, + VHOST_BACKEND_TYPE_USER, 0, errp)!=0) { + error_setg(errp, "vhost-user-device: unable to start connection"); + return; + } + + if (vub->vhost_dev.specs.device_id) { + if (vub->virtio_id && vub->virtio_id != vub->vhost_dev.specs.device_id) { + error_setg(errp, "vhost-user-device: backend id %d doesn't match cli %d", + vub->vhost_dev.specs.device_id, vub->virtio_id); + return; + } + vub->virtio_id = vub->vhost_dev.specs.device_id; + } + if (!vub->virtio_id) { - error_setg(errp, "vhost-user-device: need to define device id"); + error_setg(errp, "vhost-user-device: need to define or be told device id"); return; } + if (vub->vhost_dev.specs.min_vqs) { + if (vub->num_vqs) { + if (vub->num_vqs < vub->vhost_dev.specs.min_vqs || + vub->num_vqs > vub->vhost_dev.specs.max_vqs) { + error_setg(errp, + "vhost-user-device: selected nvqs (%d) out of bounds (%d->%d)", + vub->num_vqs, + vub->vhost_dev.specs.min_vqs, vub->vhost_dev.specs.max_vqs); + return; + } + } else { + vub->num_vqs = vub->vhost_dev.specs.min_vqs; + } + } + if (!vub->num_vqs) { - vub->num_vqs = 1; /* reasonable default? */ + error_setg(errp, "vhost-user-device: need to define number of vqs"); } /* @@ -287,16 +316,6 @@ static void vub_device_realize(DeviceState *dev, Error **errp) virtio_add_queue(vdev, 4, vub_handle_output)); } - vub->vhost_dev.nvqs = vub->num_vqs; - - /* connect to backend */ - ret = vhost_dev_init(&vub->vhost_dev, &vub->vhost_user, - VHOST_BACKEND_TYPE_USER, 0, errp); - - if (ret < 0) { - do_vhost_user_cleanup(vdev, vub); - } - qemu_chr_fe_set_handlers(&vub->chardev, NULL, NULL, vub_event, NULL, dev, NULL, true); }