From nobody Sat May 18 17:16:07 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1696623776; cv=none; d=zohomail.com; s=zohoarc; b=m7BONewJ+vwamAfKET7gu3ll2nYVjUnmbd4xoy40i+raWiCpjmca23SOyXFV1Vw+pSgX4ftb0acTD/+ghlZfcgZJH4CM+5DGrs+jyLs012j1EVPWsBFOloKwo93/DGacDpjh7vhaODaMET2MQ0cWWu4qX57ZR9lxrV6DmPRZDx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696623776; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=syAAIAOzDHq5ojU1/sX7mdXQubeQ0DIGcKwtqZmbCE8=; b=hMeKOtatwS3UjQ3p7dKp44mq/bIR9wBZRHMiy5l0MFbtfHJakmJxzz7DbO0i/OedLrzaHzFpYVXLNdJva7Tkd2iYLN/5Z3Z9okY83s5nqp2ObkDF9JDXTUvsXeJFoCO6FMBqCNKVw5GEsbaLgbSb4Zor7ivZyDaSBi+NHyF3VuQ= 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 1696623776240936.3075890314016; Fri, 6 Oct 2023 13:22:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qorJr-0008Es-Eg; Fri, 06 Oct 2023 16:21:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qorJq-0008DZ-0a; Fri, 06 Oct 2023 16:21:06 -0400 Received: from forwardcorp1c.mail.yandex.net ([2a02:6b8:c03:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qorJm-0005lw-Tz; Fri, 06 Oct 2023 16:21:05 -0400 Received: from mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:3a8c:0:640:ec94:0]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id B7F1260EFB; Fri, 6 Oct 2023 23:20:58 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b403::1:3c]) by mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id kKgI6e5OrCg0-u47sV36S; Fri, 06 Oct 2023 23:20:58 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1696623658; bh=syAAIAOzDHq5ojU1/sX7mdXQubeQ0DIGcKwtqZmbCE8=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=YtYKqjdFBgqF/pT005LSQWS5AFaPj7zs7RhBIpsUDjJjT9YL8W8bVBg68oahIn1Do Gbt14Kjyc7GE99c1k6W/Myv6xlwLFS9zJT0al4swh9mef1m3ralBqOt9+Wm5I4WX0M 3berNGUVKRfNx3WgwYcEP2zmzgwn2qES2gX367L8= Authentication-Results: mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, eblake@redhat.com, dave@treblig.org, armbru@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, hreitz@redhat.com, kwolf@redhat.com, raphael.norwitz@nutanix.com, mst@redhat.com, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, daniil.tatianin@yandex.ru Subject: [PATCH 1/4] vhost-user-blk: simplify and fix vhost_user_blk_handle_config_change Date: Fri, 6 Oct 2023 23:20:42 +0300 Message-Id: <20231006202045.1161543-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006202045.1161543-1-vsementsov@yandex-team.ru> References: <20231006202045.1161543-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=2a02:6b8:c03:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net 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, 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 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 @yandex-team.ru) X-ZM-MESSAGEID: 1696623777701100001 Content-Type: text/plain; charset="utf-8" Let's not care about what was changed and update the whole config, reasons: 1. config->geometry should be updated together with capacity, so we fix a bug. 2. Vhost-user protocol doesn't say anything about config change limitation. Silent ignore of changes doesn't seem to be correct. 3. vhost-user-vsock reads the whole config 4. on realize we don't do any checks on retrieved config, so no reason to care here Also, let's notify guest unconditionally: 1. So does vhost-user-vsock 2. We are going to reuse the functionality in new cases when we do want to notify the guest unconditionally. So, no reason to create extra branches in the logic. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Raphael Norwitz --- hw/block/vhost-user-blk.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index eecf3f7a81..1ee05b46ee 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -93,7 +93,6 @@ static void vhost_user_blk_set_config(VirtIODevice *vdev,= const uint8_t *config) static int vhost_user_blk_handle_config_change(struct vhost_dev *dev) { int ret; - struct virtio_blk_config blkcfg; VirtIODevice *vdev =3D dev->vdev; VHostUserBlk *s =3D VHOST_USER_BLK(dev->vdev); Error *local_err =3D NULL; @@ -102,19 +101,15 @@ static int vhost_user_blk_handle_config_change(struct= vhost_dev *dev) return 0; } =20 - ret =3D vhost_dev_get_config(dev, (uint8_t *)&blkcfg, + ret =3D vhost_dev_get_config(dev, (uint8_t *)&s->blkcfg, vdev->config_len, &local_err); if (ret < 0) { error_report_err(local_err); return ret; } =20 - /* valid for resize only */ - if (blkcfg.capacity !=3D s->blkcfg.capacity) { - s->blkcfg.capacity =3D blkcfg.capacity; - memcpy(dev->vdev->config, &s->blkcfg, vdev->config_len); - virtio_notify_config(dev->vdev); - } + memcpy(dev->vdev->config, &s->blkcfg, vdev->config_len); + virtio_notify_config(dev->vdev); =20 return 0; } --=20 2.34.1 From nobody Sat May 18 17:16:07 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1696623750; cv=none; d=zohomail.com; s=zohoarc; b=PCBApK7FxCpEdxFXCR+BgvpYqkUxqpXG+XeqnL7UhsVS5jidguMw/qZ9Dn1eilFpVvEGvQ+JNdcwEmvAkZG88SOZZ2Jr63pkclyVCQ1qZJxnxAuNNwjor7Rc3B7NrDNnXYYzeZXk3JwT+M94ck962suoOHWyeuNJ+7HfTfhd1WU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696623750; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EvcBElGVDGRjVmgmuvZ7UzeLBgK5WmbdN7gavKrc1OM=; b=PLvajNFQzeJAXdni0uiU9KLK3qZ5a2vZKLCLDkCGyX5//zN9C9Cs2Bg46hebDLG/5mWuPAypy4AR94HuZ2eyDUpoh0r6YQ6yNQfBBehj1s9Rs5ubO3c/fiJUYfynu84EeQ+O//8t8ADxPH2QIT1N3gh1stAK1UU2aTPTdxWDdkI= 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 1696623750922441.71289926607596; Fri, 6 Oct 2023 13:22:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qorJv-0008H7-AC; Fri, 06 Oct 2023 16:21:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qorJq-0008E9-Dz; Fri, 06 Oct 2023 16:21:06 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qorJn-0005mE-0X; Fri, 06 Oct 2023 16:21:06 -0400 Received: from mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:3a8c:0:640:ec94:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 9F4146182B; Fri, 6 Oct 2023 23:20:59 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b403::1:3c]) by mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id kKgI6e5OrCg0-o5u96kqz; Fri, 06 Oct 2023 23:20:58 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1696623658; bh=EvcBElGVDGRjVmgmuvZ7UzeLBgK5WmbdN7gavKrc1OM=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=K1cynGCA81ezHibQthCIW8m8HCSzWFmcpycECQGxfkwqOo9nKHsO2F7hmiJVuLpKC hvUMACEuBu56YwCs+hnVo2D0yczt/aWVhkVYoVH40+MFRR/6AaNudlDrkGAK9WeJXe 0idLPA2zvym7Z1mglrtrVTX7ES4L0n2JXETB7htA= Authentication-Results: mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, eblake@redhat.com, dave@treblig.org, armbru@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, hreitz@redhat.com, kwolf@redhat.com, raphael.norwitz@nutanix.com, mst@redhat.com, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, daniil.tatianin@yandex.ru Subject: [PATCH 2/4] qapi: introduce device-sync-config Date: Fri, 6 Oct 2023 23:20:43 +0300 Message-Id: <20231006202045.1161543-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006202045.1161543-1-vsementsov@yandex-team.ru> References: <20231006202045.1161543-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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 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 @yandex-team.ru) X-ZM-MESSAGEID: 1696623751955100003 Content-Type: text/plain; charset="utf-8" Add command to sync config from vhost-user backend to the device. It may be helpful when VHOST_USER_SLAVE_CONFIG_CHANGE_MSG failed or not triggered interrupt to the guest or just not available (not supported by vhost-user server). Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/block/vhost-user-blk.c | 27 ++++++++++++++++++++------- hw/virtio/virtio-pci.c | 9 +++++++++ include/hw/qdev-core.h | 3 +++ qapi/qdev.json | 14 ++++++++++++++ softmmu/qdev-monitor.c | 23 +++++++++++++++++++++++ 5 files changed, 69 insertions(+), 7 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 1ee05b46ee..05ce7b5684 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -90,27 +90,39 @@ static void vhost_user_blk_set_config(VirtIODevice *vde= v, const uint8_t *config) s->blkcfg.wce =3D blkcfg->wce; } =20 +static int vhost_user_blk_sync_config(DeviceState *dev, Error **errp) +{ + int ret; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserBlk *s =3D VHOST_USER_BLK(vdev); + + ret =3D vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg, + vdev->config_len, errp); + if (ret < 0) { + return ret; + } + + memcpy(vdev->config, &s->blkcfg, vdev->config_len); + virtio_notify_config(vdev); + + return 0; +} + static int vhost_user_blk_handle_config_change(struct vhost_dev *dev) { int ret; - VirtIODevice *vdev =3D dev->vdev; - VHostUserBlk *s =3D VHOST_USER_BLK(dev->vdev); Error *local_err =3D NULL; =20 if (!dev->started) { return 0; } =20 - ret =3D vhost_dev_get_config(dev, (uint8_t *)&s->blkcfg, - vdev->config_len, &local_err); + ret =3D vhost_user_blk_sync_config(DEVICE(dev->vdev), &local_err); if (ret < 0) { error_report_err(local_err); return ret; } =20 - memcpy(dev->vdev->config, &s->blkcfg, vdev->config_len); - virtio_notify_config(dev->vdev); - return 0; } =20 @@ -580,6 +592,7 @@ static void vhost_user_blk_class_init(ObjectClass *klas= s, void *data) =20 device_class_set_props(dc, vhost_user_blk_properties); dc->vmsd =3D &vmstate_vhost_user_blk; + dc->sync_config =3D vhost_user_blk_sync_config; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); vdc->realize =3D vhost_user_blk_device_realize; vdc->unrealize =3D vhost_user_blk_device_unrealize; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index edbc0daa18..dd4620462b 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2315,6 +2315,14 @@ static void virtio_pci_dc_realize(DeviceState *qdev,= Error **errp) vpciklass->parent_dc_realize(qdev, errp); } =20 +static int virtio_pci_sync_config(DeviceState *dev, Error **errp) +{ + VirtIOPCIProxy *proxy =3D VIRTIO_PCI(dev); + VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + + return qdev_sync_config(DEVICE(vdev), errp); +} + static void virtio_pci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -2331,6 +2339,7 @@ static void virtio_pci_class_init(ObjectClass *klass,= void *data) device_class_set_parent_realize(dc, virtio_pci_dc_realize, &vpciklass->parent_dc_realize); rc->phases.hold =3D virtio_pci_bus_reset_hold; + dc->sync_config =3D virtio_pci_sync_config; } =20 static const TypeInfo virtio_pci_info =3D { diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index a27ef2eb24..6fa5bac86e 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -95,6 +95,7 @@ typedef void (*DeviceUnrealize)(DeviceState *dev); typedef void (*DeviceReset)(DeviceState *dev); typedef void (*BusRealize)(BusState *bus, Error **errp); typedef void (*BusUnrealize)(BusState *bus); +typedef int (*DeviceSyncConfig)(DeviceState *dev, Error **errp); =20 /** * struct DeviceClass - The base class for all devices. @@ -162,6 +163,7 @@ struct DeviceClass { DeviceReset reset; DeviceRealize realize; DeviceUnrealize unrealize; + DeviceSyncConfig sync_config; =20 /** * @vmsd: device state serialisation description for @@ -555,6 +557,7 @@ bool qdev_hotplug_allowed(DeviceState *dev, Error **err= p); */ HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev); void qdev_unplug(DeviceState *dev, Error **errp); +int qdev_sync_config(DeviceState *dev, Error **errp); void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp); void qdev_machine_creation_done(void); diff --git a/qapi/qdev.json b/qapi/qdev.json index fa80694735..2468f8bddf 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -315,3 +315,17 @@ # Since: 8.2 ## { 'event': 'X_DEVICE_ON', 'data': 'DeviceAndPath' } + +## +# @x-device-sync-config: +# +# Sync config from backend to the guest. +# +# @id: the device's ID or QOM path +# +# Returns: Nothing on success +# If @id is not a valid device, DeviceNotFound +# +# Since: 8.2 +## +{ 'command': 'x-device-sync-config', 'data': {'id': 'str'} } diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 19c31446d8..b6da24389f 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -987,6 +987,29 @@ HotplugInfo *qmp_x_query_hotplug(const char *id, Error= **errp) return hotplug_handler_get_state(hotplug_ctrl, dev, errp); } =20 +int qdev_sync_config(DeviceState *dev, Error **errp) +{ + DeviceClass *dc =3D DEVICE_GET_CLASS(dev); + + if (!dc->sync_config) { + error_setg(errp, "device-sync-config is not supported for '%s'", + object_get_typename(OBJECT(dev))); + return -ENOTSUP; + } + + return dc->sync_config(dev, errp); +} + +void qmp_x_device_sync_config(const char *id, Error **errp) +{ + DeviceState *dev =3D find_device_state(id, errp); + if (!dev) { + return; + } + + qdev_sync_config(dev, errp); +} + void hmp_device_add(Monitor *mon, const QDict *qdict) { Error *err =3D NULL; --=20 2.34.1 From nobody Sat May 18 17:16:07 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1696623750; cv=none; d=zohomail.com; s=zohoarc; b=T57d+fqmtu1hkN7mdQFLtTdptr+rjGZt5iVWkZXjeB1lgOwUaq/BFAYxWrXCXza08wyyfKwOcDAC80fSo5AZ9SSTPO5v3RI1ChA16uR15ktoaphIV9FrEG+OMVdDChZNtFC2wZm0sF8fZs5FI3w3ZdMktEb7EEpu9JG1WAwD3Ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696623750; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dAy7l69Vys7V3wlSX1d6pN71zQIe0P3DoLfLqC49yLc=; b=MJGOc+7e5FjyqF/3TXT7GvWHzslSwZlaby0/y8dTEUvhIoGTxCcbbwHpKma4SyPHscFEeIp0XGdZu/TwQcu8dskXjOo3qXXZ/WzAYJ0QWYc8c55+Siq1AW1VpflDhvzGvx7J8BsHRLPg6vi4MbkQ+eoza6fMD/sKOKmt1/TGcDE= 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 1696623750640103.86464794232268; Fri, 6 Oct 2023 13:22:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qorJr-0008Er-Ek; Fri, 06 Oct 2023 16:21:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qorJo-0008DE-Oy; Fri, 06 Oct 2023 16:21:04 -0400 Received: from forwardcorp1c.mail.yandex.net ([2a02:6b8:c03:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qorJm-0005mQ-PL; Fri, 06 Oct 2023 16:21:04 -0400 Received: from mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:3a8c:0:640:ec94:0]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id 5F4E660EFC; Fri, 6 Oct 2023 23:21:00 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b403::1:3c]) by mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id kKgI6e5OrCg0-nsKsNsQQ; Fri, 06 Oct 2023 23:20:59 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1696623659; bh=dAy7l69Vys7V3wlSX1d6pN71zQIe0P3DoLfLqC49yLc=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=bkRHgiPjX4+V6M4BcIH8EXB+5ho+jILkI61RJ0JhSzIo8y8D40oX8c510wTtWlfuU cuaMErKY+MZ41d1qwBq+fz8efVBBnsbIvMiWLkpIV6lSm7OBQjnFL3WBB19+9keQLf UaCmE5XXtPskLIji4aUaRa7Kq4CIlKXMfvZJoHKQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, eblake@redhat.com, dave@treblig.org, armbru@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, hreitz@redhat.com, kwolf@redhat.com, raphael.norwitz@nutanix.com, mst@redhat.com, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, daniil.tatianin@yandex.ru Subject: [PATCH 3/4] qapi: device-sync-config: check runstate Date: Fri, 6 Oct 2023 23:20:44 +0300 Message-Id: <20231006202045.1161543-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006202045.1161543-1-vsementsov@yandex-team.ru> References: <20231006202045.1161543-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=2a02:6b8:c03:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net 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, 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 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 @yandex-team.ru) X-ZM-MESSAGEID: 1696623751685100001 Content-Type: text/plain; charset="utf-8" Command result is racy if allow it during migration. Let's allow the sync only in RUNNING state. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/sysemu/runstate.h | 1 + softmmu/qdev-monitor.c | 27 ++++++++++++++++++++++++++- softmmu/runstate.c | 5 +++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index 08afb97695..1fc14c8122 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -5,6 +5,7 @@ #include "qemu/notify.h" =20 bool runstate_check(RunState state); +const char *current_run_state_str(void); void runstate_set(RunState new_state); RunState runstate_get(void); bool runstate_is_running(void); diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index b6da24389f..b485375049 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -23,6 +23,7 @@ #include "monitor/monitor.h" #include "monitor/qdev.h" #include "sysemu/arch_init.h" +#include "sysemu/runstate.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" #include "qapi/qapi-events-qdev.h" @@ -1002,7 +1003,31 @@ int qdev_sync_config(DeviceState *dev, Error **errp) =20 void qmp_x_device_sync_config(const char *id, Error **errp) { - DeviceState *dev =3D find_device_state(id, errp); + MigrationState *s =3D migrate_get_current(); + DeviceState *dev; + + /* + * During migration there is a race between syncing`config and migrati= ng it, + * so let's just not allow it. + * + * Moreover, let's not rely on setting up interrupts in paused state, = which + * may be a part of migration process. + */ + + if (migration_is_running(s->state)) { + error_setg(errp, "Config synchronization is not allowed " + "during migration."); + return; + } + + if (!runstate_is_running()) { + error_setg(errp, "Config synchronization allowed only in '%s' stat= e, " + "current state is '%s'", RunState_str(RUN_STATE_RUNNING= ), + current_run_state_str()); + return; + } + + dev =3D find_device_state(id, errp); if (!dev) { return; } diff --git a/softmmu/runstate.c b/softmmu/runstate.c index 1652ed0439..3a8211474e 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -181,6 +181,11 @@ bool runstate_check(RunState state) return current_run_state =3D=3D state; } =20 +const char *current_run_state_str(void) +{ + return RunState_str(current_run_state); +} + static void runstate_init(void) { const RunStateTransition *p; --=20 2.34.1 From nobody Sat May 18 17:16:07 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1696623751; cv=none; d=zohomail.com; s=zohoarc; b=Tb1idZF8/EdL2gCGCzwfq8F5EKr+kEpeQNQdsPaCiIyJxbJ/J1TPgL3dmVep/1v3OCvH+H4wD5thqpyTFFi3VXGAE0TG//60p130gSCZ4aWf4eXPYxglcCjDwY9hVkFDSN6DJKDb2bM3im/TEUgkLzpAfN6N+H6ijEOKs1WrJeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696623751; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cYIUd1vWCV2rSNw0Vd96GaLbaPbVWwVkbM3mnNEKBBU=; b=jsB9picwPnxDRjAzfRZ8IXYGYr1XCO7F3tI9ysO7NMsje9xJ1PEGaCT9x5kvrtdNwVhC8Gx9MEqPWt+6S3ZbjNZ5K/vOBZQApDG+2CG1ZcmEUTJnOFrEg0jSgEXDcXElEqWcbpupHm4P/C0BsG7q2tkk1IZ4px8DhyakasTHPbY= 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 1696623751435875.4057322648878; Fri, 6 Oct 2023 13:22:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qorJs-0008G4-Uy; Fri, 06 Oct 2023 16:21:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qorJq-0008Dv-Ap; Fri, 06 Oct 2023 16:21:06 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qorJn-0005mT-In; Fri, 06 Oct 2023 16:21:06 -0400 Received: from mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:3a8c:0:640:ec94:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTP id 296766182D; Fri, 6 Oct 2023 23:21:01 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b403::1:3c]) by mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id kKgI6e5OrCg0-iM1X41DT; Fri, 06 Oct 2023 23:21:00 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1696623660; bh=cYIUd1vWCV2rSNw0Vd96GaLbaPbVWwVkbM3mnNEKBBU=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=FHU5Ei4SdLL94jbpG8PbmtMBis2QvywCviG6jmN2kNY1byf5lZ+L6jjdoVQK3Ib9V +JUJ2XHdHxrav/iDES39cciETBo8R/YZGC5EitIFyHDUNfH/O1dm9okFDgA1CKsXzi w+cWABr3rKv6Dq+3Er60+TUIWHQJomG39MMAeqkQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-62.myt.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, eblake@redhat.com, dave@treblig.org, armbru@redhat.com, eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, hreitz@redhat.com, kwolf@redhat.com, raphael.norwitz@nutanix.com, mst@redhat.com, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, den-plotnikov@yandex-team.ru, daniil.tatianin@yandex.ru Subject: [PATCH 4/4] qapi: introduce CONFIG_READ event Date: Fri, 6 Oct 2023 23:20:45 +0300 Message-Id: <20231006202045.1161543-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231006202045.1161543-1-vsementsov@yandex-team.ru> References: <20231006202045.1161543-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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 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 @yandex-team.ru) X-ZM-MESSAGEID: 1696623753286100011 Content-Type: text/plain; charset="utf-8" Send a new event when guest reads virtio-pci config after virtio_notify_config() call. That's useful to check that guest fetched modified config, for example after resizing disk backend. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/virtio/virtio-pci.c | 9 +++++++++ include/monitor/qdev.h | 1 + monitor/monitor.c | 1 + qapi/qdev.json | 22 ++++++++++++++++++++++ softmmu/qdev-monitor.c | 5 +++++ 5 files changed, 38 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index dd4620462b..f24f8ff03d 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -23,6 +23,7 @@ #include "hw/boards.h" #include "hw/virtio/virtio.h" #include "migration/qemu-file-types.h" +#include "monitor/qdev.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" #include "hw/qdev-properties.h" @@ -541,6 +542,10 @@ static uint64_t virtio_pci_config_read(void *opaque, h= waddr addr, } addr -=3D config; =20 + if (vdev->generation > 0) { + qdev_config_read_event(DEVICE(proxy)); + } + switch (size) { case 1: val =3D virtio_config_readb(vdev, addr); @@ -1728,6 +1733,10 @@ static uint64_t virtio_pci_device_read(void *opaque,= hwaddr addr, return UINT64_MAX; } =20 + if (vdev->generation > 0) { + qdev_config_read_event(DEVICE(proxy)); + } + switch (size) { case 1: val =3D virtio_config_modern_readb(vdev, addr); diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 949a3672cb..f0b0eab07e 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -39,6 +39,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, const char *qdev_set_id(DeviceState *dev, char *id, Error **errp); =20 void qdev_hotplug_device_on_event(DeviceState *dev); +void qdev_config_read_event(DeviceState *dev); =20 DeviceAndPath *qdev_new_device_and_path(DeviceState *dev); =20 diff --git a/monitor/monitor.c b/monitor/monitor.c index 941f87815a..f8aa91b190 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -315,6 +315,7 @@ static MonitorQAPIEventConf monitor_qapi_event_conf[QAP= I_EVENT__MAX] =3D { [QAPI_EVENT_QUORUM_FAILURE] =3D { 1000 * SCALE_MS }, [QAPI_EVENT_VSERPORT_CHANGE] =3D { 1000 * SCALE_MS }, [QAPI_EVENT_MEMORY_DEVICE_SIZE_CHANGE] =3D { 1000 * SCALE_MS }, + [QAPI_EVENT_X_CONFIG_READ] =3D { 300 * SCALE_MS }, }; =20 /* diff --git a/qapi/qdev.json b/qapi/qdev.json index 2468f8bddf..37a8785b81 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -329,3 +329,25 @@ # Since: 8.2 ## { 'command': 'x-device-sync-config', 'data': {'id': 'str'} } + +## +# @X_CONFIG_READ: +# +# Emitted whenever guest reads virtio device config after config change. +# +# @device: device name +# +# @path: device path +# +# Since: 5.0.1-24 +# +# Example: +# +# <- { "event": "X_CONFIG_READ", +# "data": { "device": "virtio-net-pci-0", +# "path": "/machine/peripheral/virtio-net-pci-0" }, +# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +## +{ 'event': 'X_CONFIG_READ', + 'data': { '*device': 'str', 'path': 'str' } } diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index b485375049..d0f022e925 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -1252,3 +1252,8 @@ void qdev_hotplug_device_on_event(DeviceState *dev) dev->device_on_event_sent =3D true; qapi_event_send_x_device_on(dev->id, dev->canonical_path); } + +void qdev_config_read_event(DeviceState *dev) +{ + qapi_event_send_x_config_read(dev->id, dev->canonical_path); +} --=20 2.34.1