From patchwork Mon Nov 28 16:40:59 2022 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: 629001 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3099788pvb; Mon, 28 Nov 2022 08:44:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf4PbupRnhw1ldsms3fTZigZmuZ1wMwQxxe6alsk4lS3ZPDfqKxWReEHycePFXz4baTTDX5d X-Received: by 2002:a05:620a:e1c:b0:6fb:a5cc:208a with SMTP id y28-20020a05620a0e1c00b006fba5cc208amr30146586qkm.231.1669653851670; Mon, 28 Nov 2022 08:44:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669653851; cv=none; d=google.com; s=arc-20160816; b=UiFapuBFSSPbIzvQ7JV/cdKFEHUCcPRCS2vxGhu10yzqovhGvMIRUrgdHbCZsMo8wn dSvTLDEw8nNqYDGAbbm6kw6c+p664b4sdzHcq0GoO/VQtLCzCyJYBWkDI6aIaeph7+4V 5WqSEaJ+iZVjD2mzcy/zwmLy6AIIssQwS0KU7YHVyyitg5ghFmkOVn1U+nS1FFBHPOIC oN4AspsNFfV9j5nBa6vyQMVwI4hU7ICPGFg7c1N/3kRsK3AFEV3LW/UxAdocQHyKoDvV 7xBmNlcGY5zE3uxXcv4/L0eaeXzSLTMQekMM6zni4rn4kts67HzOLcKB2Q80rgg7XjlO xcYg== 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=oheCMzPlxFSw90huN9+zm9vfeGiOj55wqAJi+rQ46y8=; b=cocaZ9WtMGjjgLPQe+TOQbakuXVOP27o6TL3wPhLzp879ie31dnR3HFQ5Ssik4yFdd WN6xGkEusCt1iYWKNmOpSzQVwlY12SmBGFekvS7nHvGf1OMb2RjCa7BmEuiCY3ExTUhq TNLMZ301j9PkJHRDSdDoJRCIdOAwZ2pxNY75KU7e24YwBPcGNlF091F7u2F0Y+McoXzC u0ScyvpW9VaMFwEDvT8BPczYJQV7S+ZUlTYOs381QD10F5BtoRMDDH23PZvI682gNUJo DkaeR0KIqx7m1aZpaEPhQeWvxIqtKT0ziXA3ruFx9C+8SZnP7kMlKLPLAn34483pmTi0 Kg0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PZ+DIK/b"; 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 az12-20020a05620a170c00b006fa696cce73si7067595qkb.497.2022.11.28.08.44.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Nov 2022 08:44:11 -0800 (PST) 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="PZ+DIK/b"; 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 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=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_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Cc: Stefano Garzarella Cc: "Michael S. Tsirkin" Cc: Stefan Hajnoczi Acked-by: Stefano Garzarella --- 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, }; +/** + * 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; From patchwork Mon Nov 28 16:41:00 2022 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: 628998 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3099107pvb; Mon, 28 Nov 2022 08:43:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf74pXQCCgXiiRq1vceUr6hRzQn3+G2YxHsUQcqkdO8/67WtL9EXMofvQKLkfNLQRDlqRhXF X-Received: by 2002:ac8:740e:0:b0:3a5:21f1:81b5 with SMTP id p14-20020ac8740e000000b003a521f181b5mr49562152qtq.541.1669653790672; Mon, 28 Nov 2022 08:43:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669653790; cv=none; d=google.com; s=arc-20160816; b=AbMRDzolg+n9NeNhfkOCVW2OVhbYHAi4VKjNCnmElFhUQLi8XUupHEYpLteiP4uwQ2 DCCHjQ5dRyyqV1fRpHvTbzcXbE8CVO3Kiyi9NbFWxiVKlnRtXkoJvS9hqNydoYg5Vmhp 14OJ63+4kOxd0SiYLRI/xu43PiEJ+yr/0t9uXRiOI36diEct+uFoNVJcnNsP7XLVHfdI aMAHU3ZZEt9CUhPVHI5jAbnZ20PtQC4vCrjcQSB1PkjHEPHXrvMw2iwEeM6KjW1BAQ/z UTvtKl4uYlsjzTgKSi1/VYkk4DcK2Ue82jAUQuMckCmljGIp5gq9MPW2tfqZ1B/gWseE qHnA== 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=uka7vikx+meAP3llZrE2xZszY8K9HOEMeUD7dZAV6nM=; b=P+GDBJ9av5gaYPg9LI9lvHoLUxkapXWnwscwEmsQrXwWZH9apwV2cg/yetov1wEum6 7Eg86BYV28r4HTuhzvp/r8/+8WM5Lp8KwD7+4kNYAT3bvS3Jnaya2959hUJRnBr/Ljg2 JoGEANgkJeqHfimm/A6eHWjZiQWY9cBqpsPtT25HNO7TVpbuPEoG9XyCkCWkA9dJaZCv VyMkmFrNF30uGTCKDeU72ivJj9FpH1UIJrD7org9cLe9sGSgWWUTyOzVYIsmo4DMngQI FdSkjeawKBvd/MtkT2NzCdOoY+OniRwJpZdD/9SrL1aMh+keOUyv2lCYIgwWbyHcz6PW r2ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=inp1Ny7Q; 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 j4-20020a67ef04000000b003b08ca58cd4si1876849vsr.421.2022.11.28.08.43.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Nov 2022 08:43:10 -0800 (PST) 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=inp1Ny7Q; 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 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=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_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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_started) Fixes: 259d69c00b (hw/virtio: introduce virtio_device_should_start) Signed-off-by: Alex Bennée Tested-by: Christian Borntraeger --- 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; } +/** + * 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 status) { 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; } - return status & VIRTIO_CONFIG_S_DRIVER_OK; + return virtio_device_started(vdev, status); } static inline void virtio_set_started(VirtIODevice *vdev, bool started) From patchwork Mon Nov 28 16:41:01 2022 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: 628996 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3098584pvb; Mon, 28 Nov 2022 08:42:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf4dpzwEDrfvO2zuG55fKK5+iGuHsKB6j+ma+bUFDrXcTphDQkfbPY+RnCqqhzb99dFIzwFy X-Received: by 2002:a05:6214:3a01:b0:4ac:8568:12bb with SMTP id nw1-20020a0562143a0100b004ac856812bbmr48947086qvb.35.1669653738266; Mon, 28 Nov 2022 08:42:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669653738; cv=none; d=google.com; s=arc-20160816; b=uvao4JRSQOBIn+KrWp99n26Ff0PfqwyNdKz1SfKrFtmG2tcpq8OAq1hFlpOYJgw71l bs64XC45R9Jven4vPLThGDQbXNSJk1RTnumrmD7ZFUWg7QBaF/1uf/BHqqXHqBAYMtFC BPdlGm+qXR+i3iSqcM0Jhz393AFEYQiu8uhROlqfafju/9avqfQIbEkPnum1WU9cWWQ+ RxfWIZA7pVeodtyLtK5GYA2XLwPNX55Iu4VwxXiCwX3ey+LWjn2iBRQS036PZY0MJ8Wg DHWKDveIFnFcsz/iUft0JRJgb/KOVcCYKuWlraRQLfIEHPx2XfAGWmI6Or/tj3CzUucx B7gg== 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=KhIII14ps0nVEVy/8MmJ4sK/j5eE6abuNMevIXJoNIs=; b=TDvTc4RWOtYwpNFCBzS5VfAmM2fIxvyL5uWXFdu7RgqOVNCRKJmLu6xuqfK+sG2E2u sTrNkR9zCgDfsIIuiB2YKLaoOv4UcjjZZvJLhinhL5n8plv2UCf+G6p5f+DIPYi6chWC /e+WDwjB3Jh1pgVSYdzlGRjP0qx54Xa0ikkxnKmN6/Ii+JAy0y1fqwLY1tlkM0fGeohl Cw+fWiY1WWQ5x4sg0qRk6ZRVWhqjzfdscSOgQB7nMmd5QWwKkd+mPzBBmYUzsZROMr/v xOAOwo4BAH8DytVcwEKkDZKImBig5aajgngeilWHlzMf9XK1NpelfCp35YMX/cRHsyR0 +zzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F+GdSezC; 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 j21-20020ac85515000000b003a52649329asi6777697qtq.286.2022.11.28.08.42.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Nov 2022 08:42:18 -0800 (PST) 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=F+GdSezC; 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 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=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_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1333 --- 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-gpio.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 = { }; /* vhost-user-gpio-device */ - edge_opts.extra_device_opts = "id=gpio0,chardev=chr-vhost-user-test"; + edge_opts.extra_device_opts = "id=gpio0,chardev=chr-vhost-user-test " + "-global virtio-mmio.force-legacy=false"; qos_node_create_driver("vhost-user-gpio-device", virtio_gpio_device_create); qos_node_consumes("vhost-user-gpio-device", "virtio-bus", &edge_opts); From patchwork Mon Nov 28 16:41:02 2022 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: 628995 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3098409pvb; Mon, 28 Nov 2022 08:42:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf5+qZCTQh8ztTyeki5lw7dnOyalCTYFQWp2rkQezXbGZ3X8ob9eFyLvT6JwTBu6Y0FoqZEG X-Received: by 2002:a05:6102:3205:b0:3b0:94f7:5a10 with SMTP id r5-20020a056102320500b003b094f75a10mr5106566vsf.53.1669653725203; Mon, 28 Nov 2022 08:42:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669653725; cv=none; d=google.com; s=arc-20160816; b=iG/yWGMMKkz1Lp01we4+vOEZWrPpfOgy7rWBpLDoVxp8yEJnGERUV2RbFe7TIvukvv 5qQ9wdf8U0xAyQd0L55+C45dQtBxe6SkKAmcZ0+P2tzDLVvPxug2XxgmpO1/UVyaJLNy AxDwaERZLSDLLWXwo5N05qdhrXWlNxXxFJkl2bpm3AT6R+a33f/wTKeeKBZKJRhYOI8w tFB5psVf7U9Uh+55iIViKeKCB6k3PD/IvJuhX2iu6qh73w11fmwCVJNdqtGrg9SQ8/IT 3ydEpnbfB/DfmgFY8syXzsvK1e5rV39I1K+jJYdHrSugjCp8kn/OkwBp0lLQLyvB8CY+ 4dVw== 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=1Ird9EWm5rUrfSLhU9FEPVhmmn/d7w0Px+XaTSgwxrQ=; b=J7ClfWAaOHBUmjQHmSUHS+1EFrW9H1NePkgdIak8gBkZhgXz4Lp4T6NSrBiK1O2n4W tO12Oc3WOxqcWzM109klsxTpfNGi7LGYe3wfmYzU6zTgxJN5q8UQ7S82/fTSaJCU3mtc xHFO5ZnAPTfV9ExrQihsswi+Vdb/ZCQTvMgmPINP7CQxaynw2AdRcme+XR5eg4tFza07 mqOmuJddcSUB+c6YbHB2WauCdbbwQhQ7Zz61/CVOQzQ4a8N9n/1ib3d8BPQfsYxmbuUK LTm/j0/eCEeQpj23/STVKGh7Z+PBCC6FyFbQ/CiHL+Nw+sFPIWh9PaYp9klocfY375BK NPww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nkCcPPFq; 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 k20-20020a67c294000000b003b07e4dc005si3249933vsj.324.2022.11.28.08.42.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Nov 2022 08:42:05 -0800 (PST) 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=nkCcPPFq; 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 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=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_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- 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 **errp) return ret; } + /* + * Once we have initialised the vhost backend we can finally set + * the what host features are available for this device. + */ + vdev->host_features = vhost_dev->features; + /* restore vhost state */ if (virtio_device_started(vdev, vdev->status)) { vu_gpio_start(vdev); From patchwork Mon Nov 28 16:41:03 2022 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: 628997 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3099105pvb; Mon, 28 Nov 2022 08:43:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf5gMG/v8SqHWFfSctLSYb8fkQBNhxyJmT/9bmhvhSd+NfRhdBRCOAl98nyaqhcODkAVjgpn X-Received: by 2002:a1f:b2c9:0:b0:3b7:8f9b:4eff with SMTP id b192-20020a1fb2c9000000b003b78f9b4effmr19634643vkf.19.1669653790485; Mon, 28 Nov 2022 08:43:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669653790; cv=none; d=google.com; s=arc-20160816; b=stRt078gDwl4NBLlhRb93iGYp5fej0uB0dAo2GjbqqWDi1kPKxAYeyEyAS0HlPw8AC y4g0yEwC7sGmF9m5AUHdj33nPRgMFT7hW1iQ4I7G+E+Qzw+3jrHva+Ty1bJreO/lsIdH 3jY/sTTniWg+PEnihlN1ypFBuHHsZzUdZtyBNWoTv6to5aIzzxDVEjy+FwWrqdGU9epr DuPbuZVUkdy56GuX6X3g3RmLbt7VP+WWmrIuamJXsNOWv8ZTwUz/wKnvH2+kxoGt0MKf OzLJ8+OoYfXJgY6DwOKpWgaJR+ZnElo2OBh74Qj9x9EViu7tPkVcf+15H0aHow5Fiih4 kRhQ== 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=BJQ/JEKALcH9lJ7xFy8iXB5Ea36VbtyMrZxDHC60VlY=; b=a/g0SIeFi1wlydmuCYL8OyN1+hRUTRrsNDhjthsvW0A2Nih3XIr3KOkOpH8IOBCMH5 BNrdiHctpvGYByiC4M1GIrRUBhydphJa4s5OoxEwJslnDc2vSNFoTWd+ML08CgBSeUaD tfUsTHwAV8usnjiP75I88b9BA5IS2ppOGCfY3+lMAiWDS/F6jid11/vhnhuy3TTAQGqj JLBZx95DAsi+NWK/25XRL9jd7+GOpTx+E+fpXryCm9lcvYrEIv6RCbbwa69S3l6UQ0cJ LqMUvKDg5h8Z97DxQuR+peR01NVgohbRGFCf8HgugCM9akCcYCszfO5INtGIaiZBeaMi ewnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l1O7oGc5; 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 s74-20020a1f904d000000b003bccc2c79besi1384145vkd.127.2022.11.28.08.43.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Nov 2022 08:43:10 -0800 (PST) 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=l1O7oGc5; 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 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=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_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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-backend/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ée --- 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 vrings); /** * 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 vrings); /** * 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; } - r = vhost_dev_start(&crypto->dev, dev); + r = 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); } 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) } b->dev.acked_features = b->vdev->guest_features; - ret = vhost_dev_start(&b->dev, b->vdev); + ret = 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; } - vhost_dev_stop(&b->dev, b->vdev); + vhost_dev_stop(&b->dev, b->vdev, true); if (k->set_guest_notifiers) { ret = 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, Error **errp) } s->dev.vq_index_end = s->dev.nvqs; - ret = vhost_dev_start(&s->dev, vdev); + ret = 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; } - vhost_dev_stop(&s->dev, vdev); + vhost_dev_stop(&s->dev, vdev, true); ret = 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; } - r = vhost_dev_start(&net->dev, dev); + r = 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 >= 0); } - vhost_dev_stop(&net->dev, vdev); + vhost_dev_stop(&net->dev, vdev, false); 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; } - ret = vhost_dev_start(&vsc->dev, vdev); + ret = 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 = VIRTIO_BUS_GET_CLASS(qbus); int ret = 0; - vhost_dev_stop(&vsc->dev, vdev); + vhost_dev_stop(&vsc->dev, vdev, true); if (k->set_guest_notifiers) { ret = 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) } fs->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&fs->vhost_dev, vdev); + ret = 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; } - vhost_dev_stop(&fs->vhost_dev, vdev); + vhost_dev_stop(&fs->vhost_dev, vdev, true); ret = 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_features); - ret = vhost_dev_start(&gpio->vhost_dev, vdev); + ret = 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; } - vhost_dev_stop(vhost_dev, vdev); + vhost_dev_stop(vhost_dev, vdev, false); ret = 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) i2c->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&i2c->vhost_dev, vdev); + ret = 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; } - vhost_dev_stop(&i2c->vhost_dev, vdev); + vhost_dev_stop(&i2c->vhost_dev, vdev, true); ret = k->set_guest_notifiers(qbus->parent, i2c->vhost_dev.nvqs, false); 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) } rng->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&rng->vhost_dev, vdev); + ret = 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; } - vhost_dev_stop(&rng->vhost_dev, vdev); + vhost_dev_stop(&rng->vhost_dev, vdev, true); ret = k->set_guest_notifiers(qbus->parent, rng->vhost_dev.nvqs, false); 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) } vvc->vhost_dev.acked_features = vdev->guest_features; - ret = vhost_dev_start(&vvc->vhost_dev, vdev); + ret = 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; } - vhost_dev_stop(&vvc->vhost_dev, vdev); + vhost_dev_stop(&vvc->vhost_dev, vdev, true); ret = k->set_guest_notifiers(qbus->parent, vvc->vhost_dev.nvqs, false); 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, uint16_t queue_size, return 0; } +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 == 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 vrings) { int i, r; /* should only be called after backend is connected */ assert(hdev->vhost_ops); - trace_vhost_dev_start(hdev, vdev->name); + trace_vhost_dev_start(hdev, vdev->name, vrings); vdev->vhost_started = true; hdev->started = true; @@ -1830,10 +1851,16 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) goto fail_log; } } + if (vrings) { + r = vhost_dev_set_vring_enable(hdev, true); + if (r) { + goto fail_log; + } + } if (hdev->vhost_ops->vhost_dev_start) { r = 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, VirtIODevice *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: } /* 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 vrings) { int i; /* should only be called after backend is connected */ assert(hdev->vhost_ops); - trace_vhost_dev_stop(hdev, vdev->name); + trace_vhost_dev_stop(hdev, vdev->name, vrings); 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 = 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" # vhost-user.c From patchwork Mon Nov 28 16:41:04 2022 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: 629000 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3099444pvb; Mon, 28 Nov 2022 08:43:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4aEPphvz2k8FmWKwkH/WbH4ijhQ+BMUXyvE6ht3EIBARbEwmHYcmBCUbZEPOUYHPDlomEz X-Received: by 2002:a05:6214:319f:b0:4c6:c1e3:c5d with SMTP id lb31-20020a056214319f00b004c6c1e30c5dmr27562307qvb.31.1669653822180; Mon, 28 Nov 2022 08:43:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669653822; cv=none; d=google.com; s=arc-20160816; b=o6MzQ+4NPzw+f3ukKDLuAAZRWCycaENl68wlyO7c1kcPmHwLrY7ikrCpMs5DQ66r7A CTxJx0rFOpydiGvZX2TT1yEi6MY5a4aIXiSnR4J0P7jnUAFxArUteGNGxxs5Y5eeGLp5 PiCEtShjU8hOPHMzvsiFrK7vIQpcJfgVZYAZ8mJXaK3bNdjX19PngD5+XyEBQtGDzbd1 Eeq6EvchWr9/3l1ZNM9ZD/cZQ98qE4LagI3pvhR6BCmNk4CxOPx76Cc7sjQYHELGP3NU mO5H4z6SXq2Qjvmy1B1XIUXsafutq79TclNW4/sY/8IhI88hdk5BxqSBnZmmw4YYJV5k onOg== 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=zMVfFZ7FRLyaWuIyfzWfcdKs3MKvXj0482M/1lNqVQQ=; b=D6OBI/s7Dy9xwUtnQExC5YG0jfxCZxMV5LGRSCKltihuYiOY9R2ofu0an7MgPedG3Z 99MHHgHmh9a1lvhrcL6FzI6UyBy7v314FEMPMGUni3wK+0N9r+g5i4LczC8G+E6SqpwU j6AeMKITKvDvb5ZcOqMdIPemoNymFZRKd12Tcjr3g7+d0s4QHOqvVKTj70SP5PAJoMta HnR4Otq0viWxRijqCA0BlGWr8QIu0cY6GH4C94XIb0El4Mu+GfXTpa/HoJknMnMhpm/W qvHx4ba0UNgWWJQRaM8VDjKo4QJShH3zzT/H2Ox8gQR9bjQU7HeiVjeMx/KcD0tHqbrA Ngvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LJOxt02O; 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 ch5-20020a05622a40c500b003a556e330d9si7129018qtb.589.2022.11.28.08.43.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Nov 2022 08:43:42 -0800 (PST) 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=LJOxt02O; 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 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=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_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- 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 >*/ }; 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 = true; /* * 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 = &gpio->vhost_dev; int ret; - if (!k->set_guest_notifiers) { + if (!gpio->started_vu) { return; } + gpio->started_vu = false; - /* - * 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; } From patchwork Mon Nov 28 16:41:05 2022 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: 628999 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3099225pvb; Mon, 28 Nov 2022 08:43:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf7bKkfRL2yMiflSAoB8MS6DBbIRTBRHtTsp3Cx+lUdWl4WcVTAzxyGHwuXJ0A07WgmKL1PK X-Received: by 2002:a05:622a:40cb:b0:3a5:7e65:ddeb with SMTP id ch11-20020a05622a40cb00b003a57e65ddebmr30621192qtb.424.1669653801325; Mon, 28 Nov 2022 08:43:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669653801; cv=none; d=google.com; s=arc-20160816; b=FQiwsgw+BXzwZAxJOZxFh8+6s92nqaYyXAppixG4eJ1o42AsCEBVgoBm6iTIPjiwtL 0+xZATj7sV3U8reNwKxlE2WakfHxSQp2S+zvVh/xL1f4lYmOq+/QENKsy5gUu7KglOlK seWc2NJmZ4hwLkdbn58IvcPdE8ukuBqAJHmStrkZXuwQ0ZDxPCNcnrQd11Eixu0oBXcZ QZ+pu5SiQHDR+Nhem2wubgEC1KiFJMZooPC9RT6KN1BGTULiY5bTxNQlly3nymxzPNHz egL3x999CdrbwnkWWxX94Jh9uhRlY2v3YmH88mbDQrfRaD7sklMWuqb1GsLsahp4h2tr nIvw== 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=t99r97KCMhXOciLLqoHwe9PQyDGYbDiDI/NZ8iKrgRk=; b=QUf01zoD7RXusTM+XUdhR/NE5NsYJwwrlM61Y465tS7N3FyL552gf+dpysTa1FqDth CETKhvsJo86cxwHbbIjvpTVEtxWx5+uv6ygqazbSzQxyoj625CP7Ych3nnKCa0O2Hjx0 NKhP2o5h3i5apgp3aDrGjOmXRpggfNJYP2IXZLXKpcCVyhLz4z/GBV+FU6Vat7LyymVX AM1MaZ363eLb1PR57dgx3qrE5I7/eb472tOSSkqXkh0ynnx7VhweejS4UCicjoxkxT9o 4dqB/lK1iPaKC+6tT3BGY8/9zaK33VMYx3yqLxGFwsjjAQg51MBsVzDrmdR5Dvgi9IB/ MyPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gfzXxV+3; 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 h10-20020a0562140daa00b004bbd3df5317si7412347qvh.374.2022.11.28.08.43.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Nov 2022 08:43:21 -0800 (PST) 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=gfzXxV+3; 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 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=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_Benn=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org ..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ée 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); +/** + * 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 *dev) vhost_user_blk_stop(vdev); vhost_dev_cleanup(&s->dev); -} -static void vhost_user_blk_chr_closed_bh(void *opaque) -{ - DeviceState *dev = opaque; - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VHostUserBlk *s = 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); } static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) @@ -398,33 +391,9 @@ static void vhost_user_blk_event(void *opaque, QEMUChrEvent 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 = 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, opaque); - - /* - * 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). - * - * 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 = 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 **errp) return 0; } +static void vu_gpio_event(void *opaque, QEMUChrEvent event); + static void vu_gpio_disconnect(DeviceState *dev) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -251,6 +253,11 @@ static void vu_gpio_disconnect(DeviceState *dev) 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); } static void vu_gpio_event(void *opaque, QEMUChrEvent event) @@ -268,7 +275,9 @@ static void vu_gpio_event(void *opaque, QEMUChrEvent event) } 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 = NULL; } + +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 = opaque; + struct vhost_dev *vhost = 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 = qemu_get_current_aio_context(); + VhostAsyncCallback *data = g_new0(VhostAsyncCallback, 1); + + /* Save data for the callback */ + data->cb = cb; + data->dev = d; + data->cd = chardev; + data->vhost = 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 = false; + } +} + static int vhost_user_dev_start(struct vhost_dev *dev, bool started) { if (!virtio_has_feature(dev->protocol_features,