From patchwork Mon Jul 10 15:35:18 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: 701036 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5246367wrs; Mon, 10 Jul 2023 08:44:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlE3bxk2luZ9dfZyJz/xX6twAIeOgpaPrUDe9DW5FVZ0HjsaE1wlaj0hvq0S8/K7Na/gM2B7 X-Received: by 2002:a0c:b453:0:b0:635:e56e:ccf1 with SMTP id e19-20020a0cb453000000b00635e56eccf1mr10881406qvf.46.1689003851940; Mon, 10 Jul 2023 08:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689003851; cv=none; d=google.com; s=arc-20160816; b=nekagDFCIJ7e7GeOyMljR69bFuQMHvqQm/fd30Arq9wkxlm8F0Cov+1kBLeFUQLAhO TStbHZBnJVDF5GBJw7uMT7mGRbD9fhGkTkFKFTAHLoaMZY66XYSP8/+9ZtJ1RLbU0n2A vvySQqpZiVoc1zrxZTJpLgmNlM0Y2NZ25KcWmZYh9vgOI3DwbQiVN1kBOT1xAvTUZFQW MBmIPQM1BRe7llf9lIXJm/A7/F+wi5MR48sI5oTE+d/tc48QYLrP4ahkT3V1ZWNjlyGY HMgxEuayTwDuU1bIXO1gXPqhf3ygx2i13MiMdUeBVNog9mhzYV1MrQa4qgfKh6pqFqtI V9+A== 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=b0ilIKM9UzrdIh1IGF/Dd3LVm1ZupBEQeVXkMJAA6OY=; fh=pHpVzH22N3up2JSv0jV3vGkBG2/OCgsTpbbdQUlofss=; b=RUIJoSx7ShpZV3a31CggdPvpjSE7rqOB3mp173h/LohJp6DZBVy0bEB8APr6YUWBJC 7lJiIVeTKCfV6xwII6gdv/WecI1SdzEvboKwR6mcjychXMU5ZuAUP4TLRSl1LPte8013 imgLdMrknFgep5O75Eq4JAhAt7Aqm0WRtBAovblTaBXbLzenuPpelLfRWZxZEwJ2MlzS mzjd9NUdMphkkn5z/GXbVcah8uX+pCKLzQLN79bFjcNhxnFp/iT5pGA9eVOC1T6/NsW/ Rx9qwaPyCsiMPALxw9Nw0jL6zDbIaZDUMsmcvJV8xMOTVIIk2uHjjIfAoMIR9o4ocjPk OqEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jxGO4ib/"; 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 g15-20020a0caacf000000b0057104cd4825si5548312qvb.68.2023.07.10.08.44.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jul 2023 08:44:11 -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="jxGO4ib/"; 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 1qIt2y-0002Ym-Ku; Mon, 10 Jul 2023 11:43:32 -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 1qIt2u-0002XG-Fj for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:28 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIt2r-0006ML-Lh for qemu-devel@nongnu.org; Mon, 10 Jul 2023 11:43:28 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fbc12181b6so52052015e9.2 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=b0ilIKM9UzrdIh1IGF/Dd3LVm1ZupBEQeVXkMJAA6OY=; b=jxGO4ib/7xl0KK29LlO6eT9Q5mPWTQSH5ZA7JO+oBfOkMqUt48G2424F2Bggu4Y1K3 eS2gJn5s4IsmfRA6Kc/PilOY0eGLJw4sNZeWsuLAixtkcOazolJEBW7CL/YrIHY8FHJj 3c+NEJI2MRqwC777n7sf2C9xufCHv0AZAB5dhUfiAkk0XXpqIkTAQ7lR+Z7RWmAsBAJr lPTXknQqVPkLZV4RoInWpXcqE/7b7zFU273iwgIKba0oT2gNA8d+ouUl7WzxoWIICMuU i+dVpkZfIJq03Kc2NV3o702IJl6f4MErKzukJkkniZ61uOcqlaspvsIWuX4mB8RqtOhn UlqA== 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=b0ilIKM9UzrdIh1IGF/Dd3LVm1ZupBEQeVXkMJAA6OY=; b=JMhdxkTmx3jp61XWutaHyi+WjCXNPJcRRKUdXlkj0F1+YjXsO7Gbw06Y7PhU0Cr3Hv T1rod3W8KluLrbOpggaer5f/RMcB54pO7pTeHhUXYyVrT/aMgEG3a1Guwh5QCZlYqqR7 H0bU1kbgPAeCLLg8ySXJpVgBp3/POlRi0lsBmFoU9C/wuWOiDaUYv61NPosJepyPSGku byPBo6bbicXRLWxcQqfSF4weJD2fFIm1dysmJTIDIGcHN2/HMw/Fbqju6Y4v9ILI77L+ OPWI9Z0N6kXmW8VVwIel6rKPR5xteN1LcM3NuTLJm2NQllhBt2Gt9ObcF15deV/1gmjA Jw0g== X-Gm-Message-State: ABy/qLZrFdkZ9cJMAR289xadAu9HNKemZ3H9B0k+knRcCGvRefcVFRwa XLS0C9L5c+e6yKzunwW8HchREw== X-Received: by 2002:a05:600c:378d:b0:3fc:e1:24b5 with SMTP id o13-20020a05600c378d00b003fc00e124b5mr8012473wmr.23.1689003803192; Mon, 10 Jul 2023 08:43:23 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc7d6000000b003fbcdba1a63sm206655wmk.12.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 0C1731FFCA; 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 16/20] hw/virtio: move virtq initialisation into internal helper Date: Mon, 10 Jul 2023 16:35:18 +0100 Message-Id: <20230710153522.3469097-17-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::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.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 This will be useful if we end up having to consider initialising the virtqs at a seperate time. Signed-off-by: Alex Bennée --- hw/virtio/vhost.c | 60 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 82394331bf..971df8ccc5 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1382,12 +1382,47 @@ static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq) } } +/* + * Initialise the virtqs. This can happen soon after the initial + * connection if we have all the details we need or be deferred until + * later. + */ +static bool vhost_init_virtqs(struct vhost_dev *hdev, uint32_t busyloop_timeout, + Error **errp) +{ + int i, r, n_initialized_vqs = 0; + + for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { + r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i); + if (r < 0) { + error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i); + /* not sure what the point of this is if we have failed... */ + hdev->nvqs = n_initialized_vqs; + return false; + } + } + + if (busyloop_timeout) { + for (i = 0; i < hdev->nvqs; ++i) { + r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, + busyloop_timeout); + if (r < 0) { + error_setg_errno(errp, -r, "Failed to set busyloop timeout"); + return false; + } + } + } + + g_assert(hdev->nvqs == n_initialized_vqs); + return true; +} + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeout, Error **errp) { uint64_t features; - int i, r, n_initialized_vqs = 0; + int i, r; hdev->vdev = NULL; hdev->migration_blocker = NULL; @@ -1412,22 +1447,10 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, goto fail; } - for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { - r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i); - if (r < 0) { - error_setg_errno(errp, -r, "Failed to initialize virtqueue %d", i); - goto fail; - } - } - - if (busyloop_timeout) { - for (i = 0; i < hdev->nvqs; ++i) { - r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, - busyloop_timeout); - if (r < 0) { - error_setg_errno(errp, -r, "Failed to set busyloop timeout"); - goto fail_busyloop; - } + /* Skip if we don't yet have number of vqs */ + if (hdev->vqs && hdev->nvqs) { + if (!vhost_init_virtqs(hdev, busyloop_timeout, errp)) { + goto fail_busyloop; } } @@ -1492,12 +1515,11 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, fail_busyloop: if (busyloop_timeout) { - while (--i >= 0) { + for (i = 0; i < hdev->nvqs; ++i) { vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0); } } fail: - hdev->nvqs = n_initialized_vqs; vhost_dev_cleanup(hdev); return r; }