From nobody Sun Apr 28 08:33:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1669653852; cv=none; d=zohomail.com; s=zohoarc; b=V99V3kKcTP7qK7htNq+48nzJT7eh88Q6M/XBIwmivpB0knTCoirSsEkoevQX0vMKEM+Q0OYNzoD1jPReZsO8jbkNxbmE0M09mW6kGrUYQ8mkwTrkE41ufecVlCnjCRuA3a2MvDJDSWDIHR3AgZqtalMN8Lgp4fj5hiXaaXZ2ZyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669653852; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oheCMzPlxFSw90huN9+zm9vfeGiOj55wqAJi+rQ46y8=; b=FPtdc5vQaNH0EN3bjoO57+gkxLJEg7U1uh9QFyuzjklyOGXwP+bJav2XbVTFPqPavFPCfgmo4NI5fX44nNc3zP0QAWyivDL3oM7ZMSDMIrmw/s8VYHHtcsFIGsDkay45ZSQFqLivYgxqs/R8/+MvPZkB74EnWQWsCmcDGwiogVg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166965385212478.9143109685757; Mon, 28 Nov 2022 08:44:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozhCI-0005k6-B9; Mon, 28 Nov 2022 11:41:34 -0500 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 1ozhC1-0005eq-NY for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:17 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ozhBw-0004oO-30 for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:15 -0500 Received: by mail-wr1-x42b.google.com with SMTP id q7so16909397wrr.8 for ; Mon, 28 Nov 2022 08:41:08 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id l11-20020a1c790b000000b003b4a699ce8esm18815025wme.6.2022.11.28.08.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 08:41:06 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D165C1FFB8; Mon, 28 Nov 2022 16:41:05 +0000 (GMT) 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=oheCMzPlxFSw90huN9+zm9vfeGiOj55wqAJi+rQ46y8=; b=PZ+DIK/bXatBqFj139vxhq4Sqbfgo1GPys31fug2xCmfOUTA/qLyS+4ggLRvwG1vYX tOzPncE7y8Jf13fTHk2LmwcIbQyT5YC6cSVY9CQr1IC4O/5R/DxrhgTa4OXNmYXv4JYV y2oogVawwmn67HvktL7ltyY1YrbKxxVVcFTKMHcpY5ENBSOolmrlDixw+0bE+bKwym0+ 1SzE5mVZKF/KjvxEhRqYQ0fELqQW/sGkIGL3sapQaTq2asRKsZumqHVra5JOqPXRjFqJ oeAqmVEd76ALht+PGQjQpPhmvB35BtMFVzcUymU7yF1F8wt6+EcyegBBl8XKDkHLxI+9 pWLQ== 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=oheCMzPlxFSw90huN9+zm9vfeGiOj55wqAJi+rQ46y8=; b=mLCwruDou95e1NjNaLJYfxz4k5JK4E2RhO8lA6/MNhpEBtlfAN/iNHmN2h6eJ1Xzfr kYZzPhz609n40QNHc4VP2MFtTWGWpkKl2wSi5f9VRsET7gU0md1Yd90LnSku2cQxL+kO bebnsH8nFURkk4tGEMZ2geCTKommAp0EYneKrVgFKss/0e1BJ4X/TR4JkWqQque69N30 /avR7VLaKwgmGVG5mNhyQ6BTtoO4TWbbBBf4Mkr6K5zGrJnUxABvPwmcx5DRslMgtYVp M97+hgjceqUS97YEBGpv5pGesvsvquR/iiK+7SirP8TdrLEEpZsyom0fbEnnOAbztyn8 v6PA== X-Gm-Message-State: ANoB5pkT7igafbRBIc3f8lbAHCcWQns1lSQcCltxXlbyNDPXh/s67H+s 6HKV6i23DqC5kzescfNlGHR+MA== X-Google-Smtp-Source: AA0mqf6uR6rTNw3WL9p8qBY+1/2fHHLc6RnOzptQ+KTKWN96OI6ULlCt+WmCuUYpLRXv+hMuyD4WPA== X-Received: by 2002:adf:f6d1:0:b0:241:e2af:444f with SMTP id y17-20020adff6d1000000b00241e2af444fmr19929163wrp.676.1669653667586; Mon, 28 Nov 2022 08:41:07 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: slp@redhat.com, mst@redhat.com, marcandre.lureau@redhat.com, stefanha@redhat.com, mathieu.poirier@linaro.org, viresh.kumar@linaro.org, sgarzare@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Stefan Hajnoczi Subject: [PATCH v3 1/7] include/hw: attempt to document VirtIO feature variables Date: Mon, 28 Nov 2022 16:40:59 +0000 Message-Id: <20221128164105.1191058-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221128164105.1191058-1-alex.bennee@linaro.org> References: <20221128164105.1191058-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42b.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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1669653852625100001 We have a bunch of variables associated with the device and the vhost backend which are used inconsistently throughout the code base. Lets start trying to bring some order by agreeing what each variable is for. Signed-off-by: Alex Benn=C3=A9e Cc: Stefano Garzarella Cc: "Michael S. Tsirkin" Cc: Stefan Hajnoczi Acked-by: Stefano Garzarella Reviewed-by: Michael S. Tsirkin --- v2 - dropped DISCUSS and commentary - separated protocol section for clarity - updated working on vhost->backend_features - made clear guest_features was the written state --- include/hw/virtio/vhost.h | 25 ++++++++++++++++++++++--- include/hw/virtio/virtio.h | 19 ++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 353252ac3e..eaf628f656 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -88,13 +88,32 @@ struct vhost_dev { int vq_index_end; /* if non-zero, minimum required value for max_queues */ int num_queues; + /** + * vhost feature handling requires matching the feature set + * offered by a backend which may be a subset of the total + * features eventually offered to the guest. + * + * @features: available features provided by the backend + * @acked_features: final negotiated features with front-end driver + * + * @backend_features: this is used in a couple of places to either + * store VHOST_USER_F_PROTOCOL_FEATURES to apply to + * VHOST_USER_SET_FEATURES or VHOST_NET_F_VIRTIO_NET_HDR. Its + * future use should be discouraged and the variable retired as + * its easy to confuse with the VirtIO backend_features. + */ uint64_t features; - /** @acked_features: final set of negotiated features */ uint64_t acked_features; - /** @backend_features: backend specific feature bits */ uint64_t backend_features; - /** @protocol_features: final negotiated protocol features */ + + /** + * @protocol_features: is the vhost-user only feature set by + * VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only + * negotiated if VHOST_USER_F_PROTOCOL_FEATURES has been offered + * by the backend (see @features). + */ uint64_t protocol_features; + uint64_t max_queues; uint64_t backend_cap; /* @started: is the vhost device started? */ diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index a973811cbf..0f612067f7 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -93,6 +93,12 @@ enum virtio_device_endian { VIRTIO_DEVICE_ENDIAN_BIG, }; =20 +/** + * struct VirtIODevice - common VirtIO structure + * @name: name of the device + * @status: VirtIO Device Status field + * + */ struct VirtIODevice { DeviceState parent_obj; @@ -100,9 +106,20 @@ struct VirtIODevice uint8_t status; uint8_t isr; uint16_t queue_sel; - uint64_t guest_features; + /** + * These fields represent a set of VirtIO features at various + * levels of the stack. @host_features indicates the complete + * feature set the VirtIO device can offer to the driver. + * @guest_features indicates which features the VirtIO driver has + * selected by writing to the feature register. Finally + * @backend_features represents everything supported by the + * backend (e.g. vhost) and could potentially be a subset of the + * total feature set offered by QEMU. + */ uint64_t host_features; + uint64_t guest_features; uint64_t backend_features; + size_t config_len; void *config; uint16_t config_vector; --=20 2.34.1 From nobody Sun Apr 28 08:33:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1669653793; cv=none; d=zohomail.com; s=zohoarc; b=gUxM77bjDTAChYz9pSs8HqmA0Sa4cfFywBnJPahvSlppK65f/eMSmMf71EtfN4qopCVdoOmrupOStGssbTitVSI2N0OrYkG+St40CEKlvTpxael6ZBW3xtUhlarex6VDgRT7BjdoIA13wTXysaFU+GjkdBPqYJSI5zfoVlN9zyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669653793; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uka7vikx+meAP3llZrE2xZszY8K9HOEMeUD7dZAV6nM=; b=Ni10qdzFX24lDNbbpVaPR5MtZYO9Gh0VB4d44Eq07A5vmBdTXCf4Gp+frv4EbneSD8He62VhKrtQuycCZdfYKr9V4Wmwo2X2GTO1CMRLexI6o5FuzaHiXj5fVQRzjM4+tABRLmzh4B25+Rg2Sv9xdT9J447a+RsI6M+AZAcq6Gw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669653793085225.94933279737188; Mon, 28 Nov 2022 08:43:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozhCG-0005iG-4e; Mon, 28 Nov 2022 11:41:32 -0500 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 1ozhBx-0005eg-Us for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:16 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ozhBw-0004oV-34 for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:13 -0500 Received: by mail-wm1-x32b.google.com with SMTP id p16so8941847wmc.3 for ; Mon, 28 Nov 2022 08:41:09 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id x9-20020a5d6b49000000b002366e3f1497sm11331424wrw.6.2022.11.28.08.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 08:41:07 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id F02C41FFBA; Mon, 28 Nov 2022 16:41:05 +0000 (GMT) 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=uka7vikx+meAP3llZrE2xZszY8K9HOEMeUD7dZAV6nM=; b=inp1Ny7Q9uISTwqsbI+bXlxcuVtIsT8A3J5tVSJobOBFESO6q2EppAF2JnjyJzpJgk HlmCLYcwGFv9gtbCyIlZkyzUdwR8h7HkmXLmZ+UalRxVOSNTo5yGBTalUK7gkz4N0Qfn DtYBnm5inougoHEwFg/3oMtFaW3AmIzxGFpjWzvzJl6WiqHNvlnXHnr83SnxSFAM+u6r XNktAsaKj2R43cXm9GdYo9jElBztOqWiwq/xXxBGJ38PYF4Psdiwp2j4BilPq4gZ+bKI 7Y7MWazIgdMt6OJ22j7cSlj7v/TYKs02XoeRg+A6DEdbbAYTuOvmEsvuhUDFU9bmcbyd h8bQ== 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=uka7vikx+meAP3llZrE2xZszY8K9HOEMeUD7dZAV6nM=; b=Zws7CzyAujUzTGSuv7wWfWeGelmw8FBMOqrGprlOeBmdk2/NIDnDBz47DnBCaJaYdF Dvr7kaRq6yhiKvOBqelgNTu17fR8KIsFw0osfsQeCzAughdidiG48F79HhIN7JLErm+c fxGjpuh9EGJ6wx0c2GaBvu/LCC4b5T1He+V47kmIFtPALuUynIGNmcVbMHz1q2ZmNZCL Ha0cGzAK5jMeLmEMjCtSeEHvU9+hvWB1SVpXRmD13c8B/giFIFJF0pHcOC3kLSs7VVk+ 7fOUZAgfkTWIXy/B8iczXmFFmHbnTjqQNmPHKHicH+mofpU+lol0P+xxl9OE8vIXu9ro vfhg== X-Gm-Message-State: ANoB5pmEO1NqjYf2f0SP74Sgt1g633Ts2yjAV7uBcjKoKMGuIqXS+dgJ Arr9JAirBcl4qqIYhtFlCNTFkg== X-Google-Smtp-Source: AA0mqf69kjC+fiDobeMo191Q0I6TmO4nkNg+N0Ihs8xf3IhJE9d30lRq2UhrXSpuu1styQ5RIg1TlA== X-Received: by 2002:a05:600c:34d5:b0:3cf:7016:d401 with SMTP id d21-20020a05600c34d500b003cf7016d401mr41442324wmq.154.1669653668339; Mon, 28 Nov 2022 08:41:08 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: slp@redhat.com, mst@redhat.com, marcandre.lureau@redhat.com, stefanha@redhat.com, mathieu.poirier@linaro.org, viresh.kumar@linaro.org, sgarzare@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Christian Borntraeger Subject: [PATCH v3 2/7] include/hw: VM state takes precedence in virtio_device_should_start Date: Mon, 28 Nov 2022 16:41:00 +0000 Message-Id: <20221128164105.1191058-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221128164105.1191058-1-alex.bennee@linaro.org> References: <20221128164105.1191058-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1669653794371100001 The VM status should always preempt the device status for these checks. This ensures the device is in the correct state when we suspend the VM prior to migrations. This restores the checks to the order they where in before the refactoring moved things around. While we are at it lets improve our documentation of the various fields involved and document the two functions. Fixes: 9f6bcfd99f (hw/virtio: move vm_running check to virtio_device_starte= d) Fixes: 259d69c00b (hw/virtio: introduce virtio_device_should_start) Signed-off-by: Alex Benn=C3=A9e Tested-by: Christian Borntraeger Reviewed-by: Michael S. Tsirkin --- v3 - rm extra line - fix fn name in comment for virtio_device_started() --- include/hw/virtio/virtio.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 0f612067f7..24561e933a 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -133,6 +133,13 @@ struct VirtIODevice bool broken; /* device in invalid state, needs reset */ bool use_disabled_flag; /* allow use of 'disable' flag when needed */ bool disabled; /* device in temporarily disabled state */ + /** + * @use_started: true if the @started flag should be used to check the + * current state of the VirtIO device. Otherwise status bits + * should be checked for a current status of the device. + * @use_started is only set via QMP and defaults to true for all + * modern machines (since 4.1). + */ bool use_started; bool started; bool start_on_kick; /* when virtio 1.0 feature has not been negotiated= */ @@ -408,6 +415,16 @@ static inline bool virtio_is_big_endian(VirtIODevice *= vdev) return false; } =20 +/** + * virtio_device_started() - check if device started + * @vdev - the VirtIO device + * @status - the devices status bits + * + * Check if the device is started. For most modern machines this is + * tracked via the @vdev->started field (to support migration), + * otherwise we check for the final negotiated status bit that + * indicates everything is ready. + */ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t statu= s) { if (vdev->use_started) { @@ -428,15 +445,11 @@ static inline bool virtio_device_started(VirtIODevice= *vdev, uint8_t status) */ static inline bool virtio_device_should_start(VirtIODevice *vdev, uint8_t = status) { - if (vdev->use_started) { - return vdev->started; - } - if (!vdev->vm_running) { return false; } =20 - return status & VIRTIO_CONFIG_S_DRIVER_OK; + return virtio_device_started(vdev, status); } =20 static inline void virtio_set_started(VirtIODevice *vdev, bool started) --=20 2.34.1 From nobody Sun Apr 28 08:33:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1669653738; cv=none; d=zohomail.com; s=zohoarc; b=jlQTDnYy4/P++HdAbjtqAxe2yE9sY6Vj1zwETYLSWUGN8tVAT9BTg+M0D/hQC8ngLkvEqNwJNiFOW0lyxeUn8UZK1bAtf73PpNpzSXc2xgQiZ2wncxVgCRJSWE8wf5etL8BNlRuUHYhFc3nQHolRP20Xx7J9F1gDv3tRkTtoISE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669653738; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KhIII14ps0nVEVy/8MmJ4sK/j5eE6abuNMevIXJoNIs=; b=H6LfCFUXhfglfA07pEUF2XHmB/GX7YLUNE7B5yii4OzbW7gbL/3jQAbUjMkC5Gi+nLrwoHP1w2+GcHs/nfFUY6sHB5o96+0vzoUdWiP2u7LN7bndU2WGpjoPX1eOJEa+gxISUb0gZZYRU4FOMOM9ufzZw7oopoSstof2zVEeoPg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669653738917976.8028605994378; Mon, 28 Nov 2022 08:42:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozhC9-0005gp-Jt; Mon, 28 Nov 2022 11:41:29 -0500 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 1ozhBz-0005ek-7X for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:16 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ozhBw-0004oY-35 for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:14 -0500 Received: by mail-wr1-x429.google.com with SMTP id v1so17774859wrt.11 for ; Mon, 28 Nov 2022 08:41:09 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id e9-20020adff349000000b0023657e1b980sm11360381wrp.53.2022.11.28.08.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 08:41:07 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 12C031FFBB; Mon, 28 Nov 2022 16:41:06 +0000 (GMT) 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=KhIII14ps0nVEVy/8MmJ4sK/j5eE6abuNMevIXJoNIs=; b=F+GdSezCZ2NzoGKt88dnbT1O33cHzKPhUKDNBv3kM7FUe8eOWCGhyFcqnDkCjMBpxS Kt7UcGNnVuf7NC7PRDX3l1f7IA0FgBgWX3R3KDqVwDV9LQrxtXwbsWG7sqAVm4RUUMmY 0Fdyqcs7RMmcAuHOqqlMOLXX52bcMDBWdGY8VL+x4nYvX+FO19lxYzpI/fLW2VswDeQx dzanrYtazIq4tsp3W95Q2eVl/yEqwQN6ytD18+uqU2NLYHilzUDdzLBX5aCsjUoobk+L BKUBYxe04rEhhFZ2jppd4KG2xsbQ54E4LUHGccFS89gse/quaHCw/OsFsJ4pj4HOlZ5u /GiA== 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=KhIII14ps0nVEVy/8MmJ4sK/j5eE6abuNMevIXJoNIs=; b=2y7rRvwhUm0KqCeRZyqoUdjKL+OVTe5T2B2ZuXaTO2wirJ9nvAwiB+9ZcrEWwV84mX Xn58U9nVyMeFBFvlXMh106MMfZ2sANGBgr6PN/yWP+ucU+BjRupkXTDQRVds3TUGBBl5 6bSrC1oFQuYDTDoeNAE3FAUZ/hmoEDYKL4Ff7gMwRFJ6XYLsOfWZ9w3YO/KWl3nX1dcZ mbfdJ13opJ2Ii8q+5dNyTzWf5FudimrCCgeZiWmepFhaDcEynz1BrBr2CkIHI17KpFcF Gf3QNWWd6yjEiAV/hiMrUMsvnM0R2eW+pcoMF4oCnLVbRRizAjGBoul/25REvobIAtfs h45A== X-Gm-Message-State: ANoB5pnQIDSVfDKFbcG0f94QH3Emj7MfQ5503/atqrJL8tULw65cELkx J6D5QABaiGKKh9+PPm0QBIfmkg== X-Google-Smtp-Source: AA0mqf44Q6rRgTbu6jPvJikT4Cys58c9Pl3OzUbb3vn90Q5tB/A7qEjlR3JaCTa5sSuG2xddcKbbHg== X-Received: by 2002:a5d:6646:0:b0:242:164b:c58a with SMTP id f6-20020a5d6646000000b00242164bc58amr4176182wrw.45.1669653668634; Mon, 28 Nov 2022 08:41:08 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: slp@redhat.com, mst@redhat.com, marcandre.lureau@redhat.com, stefanha@redhat.com, mathieu.poirier@linaro.org, viresh.kumar@linaro.org, sgarzare@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Laurent Vivier , Paolo Bonzini Subject: [PATCH v3 3/7] tests/qtests: override "force-legacy" for gpio virtio-mmio tests Date: Mon, 28 Nov 2022 16:41:01 +0000 Message-Id: <20221128164105.1191058-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221128164105.1191058-1-alex.bennee@linaro.org> References: <20221128164105.1191058-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1669653740123100001 The GPIO device is a VIRTIO_F_VERSION_1 devices but running with a legacy MMIO interface we miss out that feature bit causing confusion. For the GPIO test force the mmio bus to support non-legacy so we can properly test it. Signed-off-by: Alex Benn=C3=A9e Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1333 Reviewed-by: Michael S. Tsirkin --- tests/qtest/libqos/virtio-gpio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qtest/libqos/virtio-gpio.c b/tests/qtest/libqos/virtio-g= pio.c index 762aa6695b..f22d7b5eb5 100644 --- a/tests/qtest/libqos/virtio-gpio.c +++ b/tests/qtest/libqos/virtio-gpio.c @@ -154,7 +154,8 @@ static void virtio_gpio_register_nodes(void) QOSGraphEdgeOptions edge_opts =3D { }; =20 /* vhost-user-gpio-device */ - edge_opts.extra_device_opts =3D "id=3Dgpio0,chardev=3Dchr-vhost-user-t= est"; + edge_opts.extra_device_opts =3D "id=3Dgpio0,chardev=3Dchr-vhost-user-t= est " + "-global virtio-mmio.force-legacy=3Dfalse"; qos_node_create_driver("vhost-user-gpio-device", virtio_gpio_device_create); qos_node_consumes("vhost-user-gpio-device", "virtio-bus", &edge_opts); --=20 2.34.1 From nobody Sun Apr 28 08:33:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1669653730; cv=none; d=zohomail.com; s=zohoarc; b=iwiutkBvAfJ0c7Snndn6QO5JKa2pTCeRgx2D7jKKcW0xA1/zp1OudPu9uu2nF5dFtd3iWdYMOXyEJ9xmV/a2Yv3CSXo3crIm9M3MoZ0gOFnFhKU+83Vnb81r/rNtSMtAiuS+xcw9GZeK56BZEF+hRQGJyCtyECm+K1lc0XgR8Jc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669653730; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1Ird9EWm5rUrfSLhU9FEPVhmmn/d7w0Px+XaTSgwxrQ=; b=asu0njiMy6IO2yhFMJArAoNMKt6yRLiDXpTe/ZV8Yxeppr6CCA+sjJxU7Ck3bOyJqQHlGVzdm54iRNwtVAxtYPgucYrfhDxkGfSyMv7he0izX8VTuYULsX4JfSEc/fozImbNrQ93EEffssL1SSHZ53R73ywYxnbzPonFVnCouhU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669653730595345.3086968918507; Mon, 28 Nov 2022 08:42:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozhCF-0005hx-4h; Mon, 28 Nov 2022 11:41:31 -0500 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 1ozhBz-0005ei-4O for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:16 -0500 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 1ozhBw-0004or-3f for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:14 -0500 Received: by mail-wm1-x330.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so12133869wma.1 for ; Mon, 28 Nov 2022 08:41:11 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id h9-20020adffd49000000b002383fc96509sm11319225wrs.47.2022.11.28.08.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 08:41:07 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 294281FFBC; Mon, 28 Nov 2022 16:41:06 +0000 (GMT) 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=1Ird9EWm5rUrfSLhU9FEPVhmmn/d7w0Px+XaTSgwxrQ=; b=nkCcPPFqBWaW61iBEMLREIEnf+2Aq1xU9clj8D+i10TPq8o+cYZqwvArEWmDyhIlde 2Ks3IOtZvu3A2hlQBOK8EWd8QTIZqxQ+JEVfDeHEUC7t7/Ypus98rf+4GMRhIwBhoite SDQJ4bIgiWTPP/L52iu84fSh1KBHgpNToa9E6xPrKTPbu4b+TLZx5A9WOVMHJiBYr7s2 eB9h69/Ia4FzKthrBGEFaetjnv2PbH69LK7ezitSBkxEG1Y8T8jI7xZ1c+OmymO5ZO8J M9aXTyfzhX+VjsUZKTD+A0BlbTeAhQSTkF+THHpK9F6o14aNuhYi/MRqEWdkc4TOG64P uJwQ== 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=1Ird9EWm5rUrfSLhU9FEPVhmmn/d7w0Px+XaTSgwxrQ=; b=rxSUenZ+gTovvCRdkGXs/sXU/eZLjrGjnFm2LWt5vYr9Ay1zoxYxYF/Z+tzuimFg3I EbWzuh63zyUC2JYTnhz0GaA1X+fkPkp+vGVrMPA8ow6fBbH8bgf/d8JiS33uId7GEi9J 7002sfUQtzsK5VUPnoYERMF7ruGstD32V1SQovBO6MJdg4imoVuEap+Z6qUezcYvKrzC 3v3gwrbi3v5V1x8n6CXDCeH4OBE+OBIseae+utzon7yvSHlexnTJ6ztJqWF9+aqnPIyg A6BUtLIq0HfVmBUCLa5wWgj+RhNmFHBNJYxgTcv6u7HUHme8YdRlyL4VfuIGLPrzqO/w zMuw== X-Gm-Message-State: ANoB5plGC7Nk+dZZGphHPlp6PTjywB8Ks2u/5PSKABocG2cojJZpmpSa 4ZdTiH5w10LmpcWxeQcGtUSIGQ== X-Google-Smtp-Source: AA0mqf5Rq3b12hTfCZEJzvalkz5uEXHW0mvJuiLgqGSkl1HM1J66N6W84sXEo7h/foz3YSg19cbjfg== X-Received: by 2002:a1c:f003:0:b0:3cf:e87a:806a with SMTP id a3-20020a1cf003000000b003cfe87a806amr41211226wmb.58.1669653670166; Mon, 28 Nov 2022 08:41:10 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: slp@redhat.com, mst@redhat.com, marcandre.lureau@redhat.com, stefanha@redhat.com, mathieu.poirier@linaro.org, viresh.kumar@linaro.org, sgarzare@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v3 4/7] hw/virtio: ensure a valid host_feature set for virtio-user-gpio Date: Mon, 28 Nov 2022 16:41:02 +0000 Message-Id: <20221128164105.1191058-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221128164105.1191058-1-alex.bennee@linaro.org> References: <20221128164105.1191058-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1669653735200100004 There was a disconnect here because vdev->host_features was set to random rubbish. This caused a weird negotiation between the driver and device that took no account of the features provided by the backend. To fix this we must set vdev->host_features once we have initialised the vhost backend. [AJB: however this is confusing because AFAICT none of the other vhost-user devices do this.] Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Michael S. Tsirkin --- hw/virtio/vhost-user-gpio.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index 5851cb3bc9..b2496c824c 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -228,6 +228,12 @@ static int vu_gpio_connect(DeviceState *dev, Error **e= rrp) return ret; } =20 + /* + * Once we have initialised the vhost backend we can finally set + * the what host features are available for this device. + */ + vdev->host_features =3D vhost_dev->features; + /* restore vhost state */ if (virtio_device_started(vdev, vdev->status)) { vu_gpio_start(vdev); --=20 2.34.1 From nobody Sun Apr 28 08:33:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1669653793; cv=none; d=zohomail.com; s=zohoarc; b=YJPpO6Gcrhv5hD7Di9Pz1wt1S1BRDpPhVsVQbS4QuACWOoQPRNyYJdDBtvs6f+n//QCDaj4WW/J7t0N17RbimyKIbTWMcEkVsjgh4nUZoijBV3HbNKRmcKYi3WwTGQWBQGRKvHSHHiQ69iaKL44TSwQBg6/P0sWuOhD3Hk+LbAM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669653793; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BJQ/JEKALcH9lJ7xFy8iXB5Ea36VbtyMrZxDHC60VlY=; b=d/l5jLO6ycKe7vGYDragdc4ktR+uVK79V9SdD9XlXurkZSkhYTt0Le30tBu3BwC7uHmkMew1hBT8AcV2U6zn75as4vv+dV60rL+a8zv7cAeKuZOLZgOiQcVIg2Wwpywe7gzOCNp052yelZ1hT8HmyhIjj+yGxatwM+/lZsnmrwY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669653792983929.3933301995513; Mon, 28 Nov 2022 08:43:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozhCH-0005iq-5j; Mon, 28 Nov 2022 11:41:33 -0500 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 1ozhC1-0005eo-Mb for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:17 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ozhBw-0004ol-77 for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:17 -0500 Received: by mail-wr1-x42c.google.com with SMTP id b12so17830726wrn.2 for ; Mon, 28 Nov 2022 08:41:11 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id s11-20020a5d6a8b000000b0022584c82c80sm11351346wru.19.2022.11.28.08.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 08:41:07 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6078E1FFBD; Mon, 28 Nov 2022 16:41:06 +0000 (GMT) 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=BJQ/JEKALcH9lJ7xFy8iXB5Ea36VbtyMrZxDHC60VlY=; b=l1O7oGc50hohSQ/r3jg9FfgUuiHTtqhc0Kgw13Eg5lupCMM36jrydSSuP/nvTUVKvX 9sIY8bj7q3fv8/+qgQsA4RlY9IjkI8gCoNNMDhBabhKQZFH587k0c85vjzoMCd2o1Sxr 76OeedD5+CFw2bMHGmJ70nUG7moSoHX0nI/XZFPLwXfCqbauipY8HSVdIzHwWb7p6Bc9 KWaE6wl7smuBzhfwvxleMuWnxmhrsOd1gvB37MKqci6w4Mv7kjSIkN0czIpidIKSaJ0W S5VMfOr20NTAw/ocYeNw+NCmZcY6pA3Z6/nNpqorCtfq56Ey0MvHHklLcW4aHg+oORUC 472Q== 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=BJQ/JEKALcH9lJ7xFy8iXB5Ea36VbtyMrZxDHC60VlY=; b=2I4oW3w0U/8rIIgDnG8CSkZvhPCRqFBZuJtCGnJc5cHBBt/H+e53Ap8jOm7lcsW5sV GFCxwjGe1/YelZT9aAwgtVSz8KyGQaVo2mOBoj6tQDM7TzgLi9X/NqQQKd/wUb2vwNy3 6gHwjZySKo4bl7kkw9ATZlzOzt9T7+y6sqToGgkg3yZrchzT+Sg9Ztidelag3IxVWwH6 6ob7lsUcKR3dDz89EvHMpOzjw95n/1Wx5RzrawW8zy7gMvWCArPk4rbC03MvGjcUGCGz sjIDjst/Pi4A/+878VbPswQNh8pHjigGgmCEFPEUzsdjAVxnCaw6NY+ehLUW+X94c8kJ 5MeA== X-Gm-Message-State: ANoB5pmBOy7MOBHzAuMGrKs+VM0avI8JM1f/DJ7U15ms2mSiufKF5ATE BfwNH9OqoyjVE5BWaBH0Xg4Cuw== X-Google-Smtp-Source: AA0mqf5tK/U5YmkkHnrOK8dga4b5KIfv4ABR6pVDd7Y7n8cbHI5afyaMQnvsrIletN+wZGgHsTnTJg== X-Received: by 2002:adf:e103:0:b0:241:e2d5:8ef2 with SMTP id t3-20020adfe103000000b00241e2d58ef2mr18939575wrz.630.1669653669758; Mon, 28 Nov 2022 08:41:09 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: slp@redhat.com, mst@redhat.com, marcandre.lureau@redhat.com, stefanha@redhat.com, mathieu.poirier@linaro.org, viresh.kumar@linaro.org, sgarzare@redhat.com, German Maglione , Raphael Norwitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Gonglei (Arei)" , Kevin Wolf , Hanna Reitz , Jason Wang , Paolo Bonzini , Fam Zheng , "Dr. David Alan Gilbert" , qemu-block@nongnu.org (open list:Block layer core), virtio-fs@redhat.com (open list:virtiofs) Subject: [PATCH v3 5/7] vhost: enable vrings in vhost_dev_start() for vhost-user devices Date: Mon, 28 Nov 2022 16:41:03 +0000 Message-Id: <20221128164105.1191058-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221128164105.1191058-1-alex.bennee@linaro.org> References: <20221128164105.1191058-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1669653794377100002 From: Stefano Garzarella Commit 02b61f38d3 ("hw/virtio: incorporate backend features in features") properly negotiates VHOST_USER_F_PROTOCOL_FEATURES with the vhost-user backend, but we forgot to enable vrings as specified in docs/interop/vhost-user.rst: If ``VHOST_USER_F_PROTOCOL_FEATURES`` has not been negotiated, the ring starts directly in the enabled state. If ``VHOST_USER_F_PROTOCOL_FEATURES`` has been negotiated, the ring is initialized in a disabled state and is enabled by ``VHOST_USER_SET_VRING_ENABLE`` with parameter 1. Some vhost-user front-ends already did this by calling vhost_ops.vhost_set_vring_enable() directly: - backends/cryptodev-vhost.c - hw/net/virtio-net.c - hw/virtio/vhost-user-gpio.c But most didn't do that, so we would leave the vrings disabled and some backends would not work. We observed this issue with the rust version of virtiofsd [1], which uses the event loop [2] provided by the vhost-user-backend crate where requests are not processed if vring is not enabled. Let's fix this issue by enabling the vrings in vhost_dev_start() for vhost-user front-ends that don't already do this directly. Same thing also in vhost_dev_stop() where we disable vrings. [1] https://gitlab.com/virtio-fs/virtiofsd [2] https://github.com/rust-vmm/vhost/blob/240fc2966/crates/vhost-user-back= end/src/event_loop.rs#L217 Fixes: 02b61f38d3 ("hw/virtio: incorporate backend features in features") Reported-by: German Maglione Tested-by: German Maglione Signed-off-by: Stefano Garzarella Acked-by: Raphael Norwitz Message-Id: <20221123131630.52020-1-sgarzare@redhat.com> Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Michael S. Tsirkin --- include/hw/virtio/vhost.h | 6 +++-- backends/cryptodev-vhost.c | 4 ++-- backends/vhost-user.c | 4 ++-- hw/block/vhost-user-blk.c | 4 ++-- hw/net/vhost_net.c | 8 +++---- hw/scsi/vhost-scsi-common.c | 4 ++-- hw/virtio/vhost-user-fs.c | 4 ++-- hw/virtio/vhost-user-gpio.c | 4 ++-- hw/virtio/vhost-user-i2c.c | 4 ++-- hw/virtio/vhost-user-rng.c | 4 ++-- hw/virtio/vhost-vsock-common.c | 4 ++-- hw/virtio/vhost.c | 44 ++++++++++++++++++++++++++++++---- hw/virtio/trace-events | 4 ++-- 13 files changed, 67 insertions(+), 31 deletions(-) diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index eaf628f656..1cafa0d776 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -203,24 +203,26 @@ static inline bool vhost_dev_is_started(struct vhost_= dev *hdev) * vhost_dev_start() - start the vhost device * @hdev: common vhost_dev structure * @vdev: the VirtIODevice structure + * @vrings: true to have vrings enabled in this call * * Starts the vhost device. From this point VirtIO feature negotiation * can start and the device can start processing VirtIO transactions. * * Return: 0 on success, < 0 on error. */ -int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); +int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vring= s); =20 /** * vhost_dev_stop() - stop the vhost device * @hdev: common vhost_dev structure * @vdev: the VirtIODevice structure + * @vrings: true to have vrings disabled in this call * * Stop the vhost device. After the device is stopped the notifiers * can be disabled (@vhost_dev_disable_notifiers) and the device can * be torn down (@vhost_dev_cleanup). */ -void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); +void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vring= s); =20 /** * DOC: vhost device configuration handling diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index bc13e466b4..572f87b3be 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -94,7 +94,7 @@ cryptodev_vhost_start_one(CryptoDevBackendVhost *crypto, goto fail_notifiers; } =20 - r =3D vhost_dev_start(&crypto->dev, dev); + r =3D vhost_dev_start(&crypto->dev, dev, false); if (r < 0) { goto fail_start; } @@ -111,7 +111,7 @@ static void cryptodev_vhost_stop_one(CryptoDevBackendVhost *crypto, VirtIODevice *dev) { - vhost_dev_stop(&crypto->dev, dev); + vhost_dev_stop(&crypto->dev, dev, false); vhost_dev_disable_notifiers(&crypto->dev, dev); } =20 diff --git a/backends/vhost-user.c b/backends/vhost-user.c index 5dedb2d987..7bfcaef976 100644 --- a/backends/vhost-user.c +++ b/backends/vhost-user.c @@ -85,7 +85,7 @@ vhost_user_backend_start(VhostUserBackend *b) } =20 b->dev.acked_features =3D b->vdev->guest_features; - ret =3D vhost_dev_start(&b->dev, b->vdev); + ret =3D vhost_dev_start(&b->dev, b->vdev, true); if (ret < 0) { error_report("Error start vhost dev"); goto err_guest_notifiers; @@ -120,7 +120,7 @@ vhost_user_backend_stop(VhostUserBackend *b) return; } =20 - vhost_dev_stop(&b->dev, b->vdev); + vhost_dev_stop(&b->dev, b->vdev, true); =20 if (k->set_guest_notifiers) { ret =3D k->set_guest_notifiers(qbus->parent, diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 0d5190accf..1177064631 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -178,7 +178,7 @@ static int vhost_user_blk_start(VirtIODevice *vdev, Err= or **errp) } =20 s->dev.vq_index_end =3D s->dev.nvqs; - ret =3D vhost_dev_start(&s->dev, vdev); + ret =3D vhost_dev_start(&s->dev, vdev, true); if (ret < 0) { error_setg_errno(errp, -ret, "Error starting vhost"); goto err_guest_notifiers; @@ -213,7 +213,7 @@ static void vhost_user_blk_stop(VirtIODevice *vdev) return; } =20 - vhost_dev_stop(&s->dev, vdev); + vhost_dev_stop(&s->dev, vdev, true); =20 ret =3D k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); if (ret < 0) { diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 26e4930676..043058ff43 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -259,7 +259,7 @@ static int vhost_net_start_one(struct vhost_net *net, goto fail_notifiers; } =20 - r =3D vhost_dev_start(&net->dev, dev); + r =3D vhost_dev_start(&net->dev, dev, false); if (r < 0) { goto fail_start; } @@ -308,7 +308,7 @@ fail: if (net->nc->info->poll) { net->nc->info->poll(net->nc, true); } - vhost_dev_stop(&net->dev, dev); + vhost_dev_stop(&net->dev, dev, false); fail_start: vhost_dev_disable_notifiers(&net->dev, dev); fail_notifiers: @@ -329,7 +329,7 @@ static void vhost_net_stop_one(struct vhost_net *net, if (net->nc->info->poll) { net->nc->info->poll(net->nc, true); } - vhost_dev_stop(&net->dev, dev); + vhost_dev_stop(&net->dev, dev, false); if (net->nc->info->stop) { net->nc->info->stop(net->nc); } @@ -606,7 +606,7 @@ err_start: assert(r >=3D 0); } =20 - vhost_dev_stop(&net->dev, vdev); + vhost_dev_stop(&net->dev, vdev, false); =20 return r; } diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c index 767f827e55..18ea5dcfa1 100644 --- a/hw/scsi/vhost-scsi-common.c +++ b/hw/scsi/vhost-scsi-common.c @@ -68,7 +68,7 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc) goto err_guest_notifiers; } =20 - ret =3D vhost_dev_start(&vsc->dev, vdev); + ret =3D vhost_dev_start(&vsc->dev, vdev, true); if (ret < 0) { error_report("Error start vhost dev"); goto err_guest_notifiers; @@ -101,7 +101,7 @@ void vhost_scsi_common_stop(VHostSCSICommon *vsc) VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); int ret =3D 0; =20 - vhost_dev_stop(&vsc->dev, vdev); + vhost_dev_stop(&vsc->dev, vdev, true); =20 if (k->set_guest_notifiers) { ret =3D k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false); diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index dc4014cdef..d97b179e6f 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -76,7 +76,7 @@ static void vuf_start(VirtIODevice *vdev) } =20 fs->vhost_dev.acked_features =3D vdev->guest_features; - ret =3D vhost_dev_start(&fs->vhost_dev, vdev); + ret =3D vhost_dev_start(&fs->vhost_dev, vdev, true); if (ret < 0) { error_report("Error starting vhost: %d", -ret); goto err_guest_notifiers; @@ -110,7 +110,7 @@ static void vuf_stop(VirtIODevice *vdev) return; } =20 - vhost_dev_stop(&fs->vhost_dev, vdev); + vhost_dev_stop(&fs->vhost_dev, vdev, true); =20 ret =3D k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false= ); if (ret < 0) { diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index b2496c824c..b38e4d4cf0 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -81,7 +81,7 @@ static int vu_gpio_start(VirtIODevice *vdev) */ vhost_ack_features(&gpio->vhost_dev, feature_bits, vdev->guest_feature= s); =20 - ret =3D vhost_dev_start(&gpio->vhost_dev, vdev); + ret =3D vhost_dev_start(&gpio->vhost_dev, vdev, false); if (ret < 0) { error_report("Error starting vhost-user-gpio: %d", ret); goto err_guest_notifiers; @@ -139,7 +139,7 @@ static void vu_gpio_stop(VirtIODevice *vdev) return; } =20 - vhost_dev_stop(vhost_dev, vdev); + vhost_dev_stop(vhost_dev, vdev, false); =20 ret =3D k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false); if (ret < 0) { diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c index 1c9f3d20dc..dc5c828ba6 100644 --- a/hw/virtio/vhost-user-i2c.c +++ b/hw/virtio/vhost-user-i2c.c @@ -46,7 +46,7 @@ static void vu_i2c_start(VirtIODevice *vdev) =20 i2c->vhost_dev.acked_features =3D vdev->guest_features; =20 - ret =3D vhost_dev_start(&i2c->vhost_dev, vdev); + ret =3D vhost_dev_start(&i2c->vhost_dev, vdev, true); if (ret < 0) { error_report("Error starting vhost-user-i2c: %d", -ret); goto err_guest_notifiers; @@ -80,7 +80,7 @@ static void vu_i2c_stop(VirtIODevice *vdev) return; } =20 - vhost_dev_stop(&i2c->vhost_dev, vdev); + vhost_dev_stop(&i2c->vhost_dev, vdev, true); =20 ret =3D k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, fals= e); if (ret < 0) { diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c index f9084cde58..201a39e220 100644 --- a/hw/virtio/vhost-user-rng.c +++ b/hw/virtio/vhost-user-rng.c @@ -47,7 +47,7 @@ static void vu_rng_start(VirtIODevice *vdev) } =20 rng->vhost_dev.acked_features =3D vdev->guest_features; - ret =3D vhost_dev_start(&rng->vhost_dev, vdev); + ret =3D vhost_dev_start(&rng->vhost_dev, vdev, true); if (ret < 0) { error_report("Error starting vhost-user-rng: %d", -ret); goto err_guest_notifiers; @@ -81,7 +81,7 @@ static void vu_rng_stop(VirtIODevice *vdev) return; } =20 - vhost_dev_stop(&rng->vhost_dev, vdev); + vhost_dev_stop(&rng->vhost_dev, vdev, true); =20 ret =3D k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, fals= e); if (ret < 0) { diff --git a/hw/virtio/vhost-vsock-common.c b/hw/virtio/vhost-vsock-common.c index a67a275de2..d21c72b401 100644 --- a/hw/virtio/vhost-vsock-common.c +++ b/hw/virtio/vhost-vsock-common.c @@ -70,7 +70,7 @@ int vhost_vsock_common_start(VirtIODevice *vdev) } =20 vvc->vhost_dev.acked_features =3D vdev->guest_features; - ret =3D vhost_dev_start(&vvc->vhost_dev, vdev); + ret =3D vhost_dev_start(&vvc->vhost_dev, vdev, true); if (ret < 0) { error_report("Error starting vhost: %d", -ret); goto err_guest_notifiers; @@ -105,7 +105,7 @@ void vhost_vsock_common_stop(VirtIODevice *vdev) return; } =20 - vhost_dev_stop(&vvc->vhost_dev, vdev); + vhost_dev_stop(&vvc->vhost_dev, vdev, true); =20 ret =3D k->set_guest_notifiers(qbus->parent, vvc->vhost_dev.nvqs, fals= e); if (ret < 0) { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index d1c4c20b8c..7fb008bc9e 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1777,15 +1777,36 @@ int vhost_dev_get_inflight(struct vhost_dev *dev, u= int16_t queue_size, return 0; } =20 +static int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable) +{ + if (!hdev->vhost_ops->vhost_set_vring_enable) { + return 0; + } + + /* + * For vhost-user devices, if VHOST_USER_F_PROTOCOL_FEATURES has not + * been negotiated, the rings start directly in the enabled state, and + * .vhost_set_vring_enable callback will fail since + * VHOST_USER_SET_VRING_ENABLE is not supported. + */ + if (hdev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_USER && + !virtio_has_feature(hdev->backend_features, + VHOST_USER_F_PROTOCOL_FEATURES)) { + return 0; + } + + return hdev->vhost_ops->vhost_set_vring_enable(hdev, enable); +} + /* Host notifiers must be enabled at this point. */ -int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) +int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vring= s) { int i, r; =20 /* should only be called after backend is connected */ assert(hdev->vhost_ops); =20 - trace_vhost_dev_start(hdev, vdev->name); + trace_vhost_dev_start(hdev, vdev->name, vrings); =20 vdev->vhost_started =3D true; hdev->started =3D true; @@ -1830,10 +1851,16 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIOD= evice *vdev) goto fail_log; } } + if (vrings) { + r =3D vhost_dev_set_vring_enable(hdev, true); + if (r) { + goto fail_log; + } + } if (hdev->vhost_ops->vhost_dev_start) { r =3D hdev->vhost_ops->vhost_dev_start(hdev, true); if (r) { - goto fail_log; + goto fail_start; } } if (vhost_dev_has_iommu(hdev) && @@ -1848,6 +1875,10 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev) } } return 0; +fail_start: + if (vrings) { + vhost_dev_set_vring_enable(hdev, false); + } fail_log: vhost_log_put(hdev, false); fail_vq: @@ -1866,18 +1897,21 @@ fail_features: } =20 /* Host notifiers must be enabled at this point. */ -void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev) +void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vring= s) { int i; =20 /* should only be called after backend is connected */ assert(hdev->vhost_ops); =20 - trace_vhost_dev_stop(hdev, vdev->name); + trace_vhost_dev_stop(hdev, vdev->name, vrings); =20 if (hdev->vhost_ops->vhost_dev_start) { hdev->vhost_ops->vhost_dev_start(hdev, false); } + if (vrings) { + vhost_dev_set_vring_enable(hdev, false); + } for (i =3D 0; i < hdev->nvqs; ++i) { vhost_virtqueue_stop(hdev, vdev, diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 820dadc26c..14fc5b9bb2 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -9,8 +9,8 @@ vhost_section(const char *name) "%s" vhost_reject_section(const char *name, int d) "%s:%d" vhost_iotlb_miss(void *dev, int step) "%p step %d" vhost_dev_cleanup(void *dev) "%p" -vhost_dev_start(void *dev, const char *name) "%p:%s" -vhost_dev_stop(void *dev, const char *name) "%p:%s" +vhost_dev_start(void *dev, const char *name, bool vrings) "%p:%s vrings:%d" +vhost_dev_stop(void *dev, const char *name, bool vrings) "%p:%s vrings:%d" =20 =20 # vhost-user.c --=20 2.34.1 From nobody Sun Apr 28 08:33:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1669653822; cv=none; d=zohomail.com; s=zohoarc; b=B+0yezcwqKS3UzGsxxkm9DxrpQGvr7Uf05GThmglH4sOe1VpDADhl0If6m5ynlAJ8FwD4jSklqNkxX6KL3D+ZnZfqGM8OY9Wsx7Yts9i0dIk+lqbTYZB6WYMN7Ta1atbCJBgnbLOJBOUi9wEY1PX3KdLhjzJFD5sMCY9r1dE5LA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669653822; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zMVfFZ7FRLyaWuIyfzWfcdKs3MKvXj0482M/1lNqVQQ=; b=ioK/2CNn4PIc3fNyf/E6PAhLL5PDGRd2WR/HYB3EDsOXWrVeOCPLfnh4aG4lkozbv+7pNFuKNXgpPCTRkOHX7fQIb4hW9KSGqpO1khk0OQX95PcWyWgojTPwSbKM5qawDIx0x8DffAx4eI+7MOGkyUgRK3gmUzqR0EK8CnzOySk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669653822709616.4985669556545; Mon, 28 Nov 2022 08:43:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozhCH-0005jm-Js; Mon, 28 Nov 2022 11:41:33 -0500 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 1ozhBz-0005ej-65 for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:17 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ozhBw-0004oc-34 for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:14 -0500 Received: by mail-wr1-x429.google.com with SMTP id n3so17810866wrp.5 for ; Mon, 28 Nov 2022 08:41:09 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id r6-20020a05600c458600b003cfd4a50d5asm20134820wmo.34.2022.11.28.08.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 08:41:07 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 79F7B1FFBE; Mon, 28 Nov 2022 16:41:06 +0000 (GMT) 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=zMVfFZ7FRLyaWuIyfzWfcdKs3MKvXj0482M/1lNqVQQ=; b=LJOxt02OgjyJIR9iTfZ8wP10HsZrsOxULuzBNdKFHwY08lOm1zdIr3Hxu1EjJU1+FX dB/a8ToszYsMSZks4DbDED3fPSq6tZXEBZL2rKjpndPQj6lk1aWPHdrS3sqro+ojWmsw qTKNLxG14GEex9N1zo6uphYlX9Lv85CJficn5pMCfXq5hztoGlO34hAMZRWddlLHAW4Y E11AkcuXwy6YVJbBXBVudRq8+GO5AY/iM3+Ddlbu3QCy6tey7u7q/eQsk8LYa8rfSUln qu5Pn27cEZf2rCk28rNy9vujiJM4wQYOvppfRHXqRWkdZDeg+TXOSM0TvgIST31tZFe3 5d6w== 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=zMVfFZ7FRLyaWuIyfzWfcdKs3MKvXj0482M/1lNqVQQ=; b=qMGQdJ+jPdP+kqO+2TZ4mpR4C++4t1TM7kpgLjWOdmt/Yeki4g/eoWI+pwlucZyk8D oo/9dMXN3nc4Hy8A56k0AEsTDJ1OyHpnRJlBz8C9kCinBbZrWY84yHaFr/Ku1jmDo0/M 6vKyzb1LblEUXHVqMB865ucWCZevOV0kbjJNthIOYE2BnmEtByvJ+crTSuw2i0CjtKMO hbVyfcBAiwubCThabf1om+nna56v6G6qmGMzsWxjD/cwN3NSojktGdy+38hdWH9Zj9cQ 05Ft0H6rOGfd040pLOFiQM+Jxzb1hfsUisqycf671btW1dxBzOKpN4wUXODx6gVt7xrF Fsug== X-Gm-Message-State: ANoB5pmOOxLGq2n6GYiIaNQcb1Ngvr5e5vhxNeaLKUoKajab3O4hczVT EFYs9NYQ/QEcFy3yl9TWRoOeyw== X-Google-Smtp-Source: AA0mqf7rlRJVhV4YwqEtlAerSEKv1lYny/K+Q4iExIlMY6fZxfGomvqsTBwTqhZlRh7lCWt37JPUWw== X-Received: by 2002:adf:e5d0:0:b0:242:17c9:a1e with SMTP id a16-20020adfe5d0000000b0024217c90a1emr3583140wrn.514.1669653669005; Mon, 28 Nov 2022 08:41:09 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: slp@redhat.com, mst@redhat.com, marcandre.lureau@redhat.com, stefanha@redhat.com, mathieu.poirier@linaro.org, viresh.kumar@linaro.org, sgarzare@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v3 6/7] hw/virtio: add started_vu status field to vhost-user-gpio Date: Mon, 28 Nov 2022 16:41:04 +0000 Message-Id: <20221128164105.1191058-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221128164105.1191058-1-alex.bennee@linaro.org> References: <20221128164105.1191058-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1669653824520100003 As per the fix to vhost-user-blk in f5b22d06fb (vhost: recheck dev state in the vhost_migration_log routine) we really should track the connection and starting separately. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Michael S. Tsirkin --- include/hw/virtio/vhost-user-gpio.h | 10 ++++++++++ hw/virtio/vhost-user-gpio.c | 11 ++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-= user-gpio.h index 4fe9aeecc0..a9305c5e6c 100644 --- a/include/hw/virtio/vhost-user-gpio.h +++ b/include/hw/virtio/vhost-user-gpio.h @@ -28,7 +28,17 @@ struct VHostUserGPIO { VhostUserState vhost_user; VirtQueue *command_vq; VirtQueue *interrupt_vq; + /** + * There are at least two steps of initialization of the + * vhost-user device. The first is a "connect" step and + * second is a "start" step. Make a separation between + * those initialization phases by using two fields. + * + * @connected: see vu_gpio_connect()/vu_gpio_disconnect() + * @started_vu: see vu_gpio_start()/vu_gpio_stop() + */ bool connected; + bool started_vu; /*< public >*/ }; =20 diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index b38e4d4cf0..75e28bcd3b 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -86,6 +86,7 @@ static int vu_gpio_start(VirtIODevice *vdev) error_report("Error starting vhost-user-gpio: %d", ret); goto err_guest_notifiers; } + gpio->started_vu =3D true; =20 /* * guest_notifier_mask/pending not used yet, so just unmask @@ -126,16 +127,12 @@ static void vu_gpio_stop(VirtIODevice *vdev) struct vhost_dev *vhost_dev =3D &gpio->vhost_dev; int ret; =20 - if (!k->set_guest_notifiers) { + if (!gpio->started_vu) { return; } + gpio->started_vu =3D false; =20 - /* - * We can call vu_gpio_stop multiple times, for example from - * vm_state_notify and the final object finalisation. Check we - * aren't already stopped before doing so. - */ - if (!vhost_dev_is_started(vhost_dev)) { + if (!k->set_guest_notifiers) { return; } =20 --=20 2.34.1 From nobody Sun Apr 28 08:33:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1669653801; cv=none; d=zohomail.com; s=zohoarc; b=jgRcHvY3inEDxdUBEQQuq8JcpsAGzmSDasG8MXtXlqC/l/VsIy9bkURf14ul+gsWtR4mYoDqEos4yOh9AN6LfxgiiDEHAuTROHbABRqEjRth8pyn/LVBW55f3BFXYcVUcJBGCb3NDLZikYSthCZUywBU4WIT1DyvTKxsX4hnuQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669653801; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=t99r97KCMhXOciLLqoHwe9PQyDGYbDiDI/NZ8iKrgRk=; b=YfonmtEcVKR4jIB7wn9wMYKcBdg9ryp9uDnN17jRYQPph4HISw7pMYbXWOee/tIsSc2vAzAEb3tdYHrnZQ/0MeCTcHbt5VG8+GF9zzVZY8BgNYt89LENLkrsyvy33XYRNoBMeOeg1MBaT8nhtikIm/iM0qZ9OQYQwv1MXJADIUA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166965380187626.028866877185465; Mon, 28 Nov 2022 08:43:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozhCJ-0005kB-4x; Mon, 28 Nov 2022 11:41:35 -0500 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 1ozhC1-0005es-OH for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:17 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ozhBw-0004p3-94 for qemu-devel@nongnu.org; Mon, 28 Nov 2022 11:41:16 -0500 Received: by mail-wr1-x429.google.com with SMTP id q7so16909634wrr.8 for ; Mon, 28 Nov 2022 08:41:11 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id u1-20020a5d5141000000b002365cd93d05sm11118156wrt.102.2022.11.28.08.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 08:41:10 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9F0401FFBF; Mon, 28 Nov 2022 16:41:06 +0000 (GMT) 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=t99r97KCMhXOciLLqoHwe9PQyDGYbDiDI/NZ8iKrgRk=; b=gfzXxV+32fSwTQnK/DhCd3u/ZV4415Ir9JddM1WpLdYlL16ZLNkRwOw64YWzMtNysq gX49rBDMVbK0AqQ3FyMYZNpuCJkxxPT0ojjwk7XDGezio1Gn6SiGRkPM/4wGm3OLCZkU DacMvQvm2LDzogfqlO+rwPUdf0P6JuNYuU33THgagOg8binDquCBL/WNoLiWpESmdTFY jrwMnHtSEirPCvsFXaqcOAxdtmrRe8Dr2Pb7bv+XUF/NTo6P0io4+eaQxnTklWTIVFb0 YSd0mMHv6XpaElSC5PW7w+y3VwBRmQgUOvzjQCC0R0NBbahLXSRIr6zIy+Jl8CPeZoAF qvjA== 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=t99r97KCMhXOciLLqoHwe9PQyDGYbDiDI/NZ8iKrgRk=; b=4HRDpnUZvPivTOQi2x5MyEw1tQBMe5ZzCqLsfC4zwdW3dH7TRe7f8EXmPQpN7t7IoV ROAr8XyTzbtsiz+zrykC7mv7mvJcQ1Ua5ogRni1Q/FWY0ui8YZNfbTx59icOXhUI48oU H3PUB5JSOb3hZ5BJ+UDp8XrrFZnysoJzSNXbNYA2IUOWll2A/cqmZZRQgy/ixdEhONX6 yT8eN1nyeluiNKMsfdrMZTdO/0xaEpB5iZmKcqhVcrFvYB0yV6lDN2RGUW2DC3uWLzyQ Q+yb5DvzPrOITtGSiZZGcPmPcIRrHthrb72l4jmCtFUCmUekGrNF5Pls601cZVjakpua sXCw== X-Gm-Message-State: ANoB5pnn2hox0BkovILX4yJHTtDL1N5FLEsKsqNkq8Zh7nJMK+/4Kcix xGbQEeTKN0DD8qNC5BXKVM37Qg== X-Google-Smtp-Source: AA0mqf5XZ7KJFi+vv4UufAZ1AFG16qx3Ks6zX5EblTjAWlH1dNcprQ/OWhcIVn0SiaZesCZohHmH7w== X-Received: by 2002:a05:6000:24f:b0:242:1f0d:a223 with SMTP id m15-20020a056000024f00b002421f0da223mr607250wrz.409.1669653670864; Mon, 28 Nov 2022 08:41:10 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: slp@redhat.com, mst@redhat.com, marcandre.lureau@redhat.com, stefanha@redhat.com, mathieu.poirier@linaro.org, viresh.kumar@linaro.org, sgarzare@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Raphael Norwitz , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PATCH v3 7/7] hw/virtio: generalise CHR_EVENT_CLOSED handling Date: Mon, 28 Nov 2022 16:41:05 +0000 Message-Id: <20221128164105.1191058-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221128164105.1191058-1-alex.bennee@linaro.org> References: <20221128164105.1191058-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1669653802442100001 ..and use for both virtio-user-blk and virtio-user-gpio. This avoids the circular close by deferring shutdown due to disconnection until a later point. virtio-user-blk already had this mechanism in place so generalise it as a vhost-user helper function and use for both blk and gpio devices. While we are at it we also fix up vhost-user-gpio to re-establish the event handler after close down so we can reconnect later. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Michael S. Tsirkin Reviewed-by: Raphael Norwitz --- include/hw/virtio/vhost-user.h | 18 +++++++++ hw/block/vhost-user-blk.c | 41 +++----------------- hw/virtio/vhost-user-gpio.c | 11 +++++- hw/virtio/vhost-user.c | 71 ++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 37 deletions(-) diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index c6e693cd3f..191216a74f 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -68,4 +68,22 @@ bool vhost_user_init(VhostUserState *user, CharBackend *= chr, Error **errp); */ void vhost_user_cleanup(VhostUserState *user); =20 +/** + * vhost_user_async_close() - cleanup vhost-user post connection drop + * @d: DeviceState for the associated device (passed to callback) + * @chardev: the CharBackend associated with the connection + * @vhost: the common vhost device + * @cb: the user callback function to complete the clean-up + * + * This function is used to handle the shutdown of a vhost-user + * connection to a backend. We handle this centrally to make sure we + * do all the steps and handle potential races due to VM shutdowns. + * Once the connection is disabled we call a backhalf to ensure + */ +typedef void (*vu_async_close_fn)(DeviceState *cb); + +void vhost_user_async_close(DeviceState *d, + CharBackend *chardev, struct vhost_dev *vhost, + vu_async_close_fn cb); + #endif diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 1177064631..aff4d2b8cb 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -369,17 +369,10 @@ static void vhost_user_blk_disconnect(DeviceState *de= v) vhost_user_blk_stop(vdev); =20 vhost_dev_cleanup(&s->dev); -} =20 -static void vhost_user_blk_chr_closed_bh(void *opaque) -{ - DeviceState *dev =3D opaque; - VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); - VHostUserBlk *s =3D VHOST_USER_BLK(vdev); - - vhost_user_blk_disconnect(dev); + /* Re-instate the event handler for new connections */ qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, - NULL, opaque, NULL, true); + NULL, dev, NULL, true); } =20 static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) @@ -398,33 +391,9 @@ static void vhost_user_blk_event(void *opaque, QEMUChr= Event event) } break; case CHR_EVENT_CLOSED: - if (!runstate_check(RUN_STATE_SHUTDOWN)) { - /* - * A close event may happen during a read/write, but vhost - * code assumes the vhost_dev remains setup, so delay the - * stop & clear. - */ - AioContext *ctx =3D qemu_get_current_aio_context(); - - qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, NULL, - NULL, NULL, false); - aio_bh_schedule_oneshot(ctx, vhost_user_blk_chr_closed_bh, opa= que); - - /* - * Move vhost device to the stopped state. The vhost-user devi= ce - * will be clean up and disconnected in BH. This can be useful= in - * the vhost migration code. If disconnect was caught there is= an - * option for the general vhost code to get the dev state with= out - * knowing its type (in this case vhost-user). - * - * FIXME: this is sketchy to be reaching into vhost_dev - * now because we are forcing something that implies we - * have executed vhost_dev_stop() but that won't happen - * until vhost_user_blk_stop() gets called from the bh. - * Really this state check should be tracked locally. - */ - s->dev.started =3D false; - } + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &s->chardev, &s->dev, + vhost_user_blk_disconnect); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c index 75e28bcd3b..cd76287766 100644 --- a/hw/virtio/vhost-user-gpio.c +++ b/hw/virtio/vhost-user-gpio.c @@ -239,6 +239,8 @@ static int vu_gpio_connect(DeviceState *dev, Error **er= rp) return 0; } =20 +static void vu_gpio_event(void *opaque, QEMUChrEvent event); + static void vu_gpio_disconnect(DeviceState *dev) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -251,6 +253,11 @@ static void vu_gpio_disconnect(DeviceState *dev) =20 vu_gpio_stop(vdev); vhost_dev_cleanup(&gpio->vhost_dev); + + /* Re-instate the event handler for new connections */ + qemu_chr_fe_set_handlers(&gpio->chardev, + NULL, NULL, vu_gpio_event, + NULL, dev, NULL, true); } =20 static void vu_gpio_event(void *opaque, QEMUChrEvent event) @@ -268,7 +275,9 @@ static void vu_gpio_event(void *opaque, QEMUChrEvent ev= ent) } break; case CHR_EVENT_CLOSED: - vu_gpio_disconnect(dev); + /* defer close until later to avoid circular close */ + vhost_user_async_close(dev, &gpio->chardev, &gpio->vhost_dev, + vu_gpio_disconnect); break; case CHR_EVENT_BREAK: case CHR_EVENT_MUX_IN: diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index abe23d4ebe..8f635844af 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -21,6 +21,7 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" +#include "sysemu/runstate.h" #include "sysemu/cryptodev.h" #include "migration/migration.h" #include "migration/postcopy-ram.h" @@ -2670,6 +2671,76 @@ void vhost_user_cleanup(VhostUserState *user) user->chr =3D NULL; } =20 + +typedef struct { + vu_async_close_fn cb; + DeviceState *dev; + CharBackend *cd; + struct vhost_dev *vhost; +} VhostAsyncCallback; + +static void vhost_user_async_close_bh(void *opaque) +{ + VhostAsyncCallback *data =3D opaque; + struct vhost_dev *vhost =3D data->vhost; + + /* + * If the vhost_dev has been cleared in the meantime there is + * nothing left to do as some other path has completed the + * cleanup. + */ + if (vhost->vdev) { + data->cb(data->dev); + } + + g_free(data); +} + +/* + * We only schedule the work if the machine is running. If suspended + * we want to keep all the in-flight data as is for migration + * purposes. + */ +void vhost_user_async_close(DeviceState *d, + CharBackend *chardev, struct vhost_dev *vhost, + vu_async_close_fn cb) +{ + if (!runstate_check(RUN_STATE_SHUTDOWN)) { + /* + * A close event may happen during a read/write, but vhost + * code assumes the vhost_dev remains setup, so delay the + * stop & clear. + */ + AioContext *ctx =3D qemu_get_current_aio_context(); + VhostAsyncCallback *data =3D g_new0(VhostAsyncCallback, 1); + + /* Save data for the callback */ + data->cb =3D cb; + data->dev =3D d; + data->cd =3D chardev; + data->vhost =3D vhost; + + /* Disable any further notifications on the chardev */ + qemu_chr_fe_set_handlers(chardev, + NULL, NULL, NULL, NULL, NULL, NULL, + false); + + aio_bh_schedule_oneshot(ctx, vhost_user_async_close_bh, data); + + /* + * Move vhost device to the stopped state. The vhost-user device + * will be clean up and disconnected in BH. This can be useful in + * the vhost migration code. If disconnect was caught there is an + * option for the general vhost code to get the dev state without + * knowing its type (in this case vhost-user). + * + * Note if the vhost device is fully cleared by the time we + * execute the bottom half we won't continue with the cleanup. + */ + vhost->started =3D false; + } +} + static int vhost_user_dev_start(struct vhost_dev *dev, bool started) { if (!virtio_has_feature(dev->protocol_features, --=20 2.34.1