Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/812237/?format=api
{ "id": 812237, "url": "http://patchwork.ozlabs.org/api/patches/812237/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1505202976-1784-2-git-send-email-changpeng.liu@intel.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<1505202976-1784-2-git-send-email-changpeng.liu@intel.com>", "list_archive_url": null, "date": "2017-09-12T07:56:13", "name": "[v3,1/4] vhost-user: add new vhost user messages to support virtio config space", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "62777774444560d670456076171bd36435bb261b", "submitter": { "id": 71275, "url": "http://patchwork.ozlabs.org/api/people/71275/?format=api", "name": "Liu, Changpeng", "email": "changpeng.liu@intel.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1505202976-1784-2-git-send-email-changpeng.liu@intel.com/mbox/", "series": [ { "id": 2447, "url": "http://patchwork.ozlabs.org/api/series/2447/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2447", "date": "2017-09-12T07:56:15", "name": "*** Introduce a new vhost-user-blk host device to Qemu ***", "version": 3, "mbox": "http://patchwork.ozlabs.org/series/2447/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/812237/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/812237/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)", "Received": [ "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrKZ119J8z9s83\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 11 Sep 2017 17:39:21 +1000 (AEST)", "from localhost ([::1]:55954 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drJJP-0003Bm-9Z\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 03:39:19 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:43357)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <changpeng.liu@intel.com>) id 1drJGV-0001DU-FA\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 03:36:21 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <changpeng.liu@intel.com>) id 1drJGS-0007dy-QW\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 03:36:19 -0400", "from mga05.intel.com ([192.55.52.43]:18824)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <changpeng.liu@intel.com>)\n\tid 1drJGS-0007cA-DB\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 03:36:16 -0400", "from orsmga004.jf.intel.com ([10.7.209.38])\n\tby fmsmga105.fm.intel.com with ESMTP; 11 Sep 2017 00:36:13 -0700", "from fedora.sh.intel.com ([10.67.112.210])\n\tby orsmga004.jf.intel.com with ESMTP; 11 Sep 2017 00:36:02 -0700" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.42,376,1500966000\"; d=\"scan'208\";a=\"127495094\"", "From": "Changpeng Liu <changpeng.liu@intel.com>", "To": "changpeng.liu@intel.com,\n\tqemu-devel@nongnu.org", "Date": "Tue, 12 Sep 2017 15:56:13 +0800", "Message-Id": "<1505202976-1784-2-git-send-email-changpeng.liu@intel.com>", "X-Mailer": "git-send-email 1.9.3", "In-Reply-To": "<1505202976-1784-1-git-send-email-changpeng.liu@intel.com>", "References": "<1505202976-1784-1-git-send-email-changpeng.liu@intel.com>", "X-detected-operating-system": "by eggs.gnu.org: Genre and OS details not\n\trecognized.", "X-Received-From": "192.55.52.43", "Subject": "[Qemu-devel] [PATCH v3 1/4] vhost-user: add new vhost user messages\n\tto support virtio config space", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.21", "Precedence": "list", "List-Id": "<qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel/>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Cc": "james.r.harris@intel.com, mst@redhat.com, stefanha@gmail.com,\n\tpbonzini@redhat.com, felipe@nutanix.com, marcandre.lureau@redhat.com", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>" }, "content": "Add VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG messages which can be\nused for live migration for vhost user devices, also vhost user devices\ncan benefit from the messages to get/set virtio config space from/to the\nI/O target besides Qemu. For the purpose to support virtio config space\nchange, VHOST_USER_SET_CONFIG_FD message is added as the event notifier\nin case virtio config space change.\n\nSigned-off-by: Changpeng Liu <changpeng.liu@intel.com>\n---\n docs/interop/vhost-user.txt | 32 +++++++++++++\n hw/virtio/vhost-user.c | 97 +++++++++++++++++++++++++++++++++++++++\n hw/virtio/vhost.c | 63 +++++++++++++++++++++++++\n include/hw/virtio/vhost-backend.h | 8 ++++\n include/hw/virtio/vhost.h | 16 +++++++\n 5 files changed, 216 insertions(+)", "diff": "diff --git a/docs/interop/vhost-user.txt b/docs/interop/vhost-user.txt\nindex 954771d..a953299 100644\n--- a/docs/interop/vhost-user.txt\n+++ b/docs/interop/vhost-user.txt\n@@ -116,6 +116,10 @@ Depending on the request type, payload can be:\n - 3: IOTLB invalidate\n - 4: IOTLB access fail\n \n+ * Virtio device config space\n+\n+ 256 Bytes static virito config space\n+\n In QEMU the vhost-user message is implemented with the following struct:\n \n typedef struct VhostUserMsg {\n@@ -129,6 +133,7 @@ typedef struct VhostUserMsg {\n VhostUserMemory memory;\n VhostUserLog log;\n struct vhost_iotlb_msg iotlb;\n+ uint8_t config[256];\n };\n } QEMU_PACKED VhostUserMsg;\n \n@@ -596,6 +601,33 @@ Master message types\n and expect this message once (per VQ) during device configuration\n (ie. before the master starts the VQ).\n \n+ * VHOST_USER_GET_CONFIG\n+ Id: 24\n+ Equivalent ioctl: N/A\n+ Master payload: virtio device config space\n+\n+ Submitted by the vhost-user master to fetch the contents of the virtio\n+ config space. The vhost-user master may cache the contents to avoid\n+ repeated VHOST_USER_GET_CONFIG calls.\n+\n+* VHOST_USER_SET_CONFIG\n+ Id: 25\n+ Equivalent ioctl: N/A\n+ Master payload: virtio device config space\n+\n+ Submitted by the vhost-user master when the guest writes to virtio\n+ config space and also after live migration on the destination host.\n+\n+* VHOST_USER_SET_CONFIG_FD\n+ Id: 26\n+ Equivalent ioctl: N/A\n+ Master payload: N/A\n+\n+ Sets the notifier file descriptor, which is passed as ancillary data.\n+ Vhost-user slave uses the file descriptor to notify vhost-user master\n+ when the virtio config space changed. The vhost-user master can read\n+ the virtio config space to get the update.\n+\n Slave message types\n -------------------\n \ndiff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c\nindex 093675e..4e7bafc 100644\n--- a/hw/virtio/vhost-user.c\n+++ b/hw/virtio/vhost-user.c\n@@ -26,6 +26,11 @@\n #define VHOST_MEMORY_MAX_NREGIONS 8\n #define VHOST_USER_F_PROTOCOL_FEATURES 30\n \n+/*\n+ * Maximum size of virtio device config space\n+ */\n+#define VHOST_USER_MAX_CONFIG_SIZE 256\n+\n enum VhostUserProtocolFeature {\n VHOST_USER_PROTOCOL_F_MQ = 0,\n VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,\n@@ -65,6 +70,9 @@ typedef enum VhostUserRequest {\n VHOST_USER_SET_SLAVE_REQ_FD = 21,\n VHOST_USER_IOTLB_MSG = 22,\n VHOST_USER_SET_VRING_ENDIAN = 23,\n+ VHOST_USER_GET_CONFIG = 24,\n+ VHOST_USER_SET_CONFIG = 25,\n+ VHOST_USER_SET_CONFIG_FD = 26,\n VHOST_USER_MAX\n } VhostUserRequest;\n \n@@ -109,6 +117,7 @@ typedef struct VhostUserMsg {\n VhostUserMemory memory;\n VhostUserLog log;\n struct vhost_iotlb_msg iotlb;\n+ uint8_t config[VHOST_USER_MAX_CONFIG_SIZE];\n } payload;\n } QEMU_PACKED VhostUserMsg;\n \n@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled)\n /* No-op as the receive channel is not dedicated to IOTLB messages. */\n }\n \n+static int vhost_user_get_config(struct vhost_dev *dev, uint8_t *config,\n+ size_t config_len)\n+{\n+ VhostUserMsg msg = {\n+ .request = VHOST_USER_GET_CONFIG,\n+ .flags = VHOST_USER_VERSION,\n+ .size = config_len,\n+ };\n+\n+ if (config_len == 0 || config_len > VHOST_USER_PAYLOAD_SIZE) {\n+ error_report(\"bad config length\");\n+ return -1;\n+ }\n+\n+ if (vhost_user_write(dev, &msg, NULL, 0) < 0) {\n+ return -1;\n+ }\n+\n+ if (vhost_user_read(dev, &msg) < 0) {\n+ return -1;\n+ }\n+\n+ if (msg.request != VHOST_USER_GET_CONFIG) {\n+ error_report(\"Received unexpected msg type. Expected %d received %d\",\n+ VHOST_USER_GET_CONFIG, msg.request);\n+ return -1;\n+ }\n+\n+ if (msg.size != config_len) {\n+ error_report(\"Received bad msg size.\");\n+ return -1;\n+ }\n+\n+ memcpy(config, &msg.payload.config, config_len);\n+\n+ return 0;\n+}\n+\n+static int vhost_user_set_config(struct vhost_dev *dev, const uint8_t *config,\n+ size_t config_len)\n+{\n+ bool reply_supported = virtio_has_feature(dev->protocol_features,\n+ VHOST_USER_PROTOCOL_F_REPLY_ACK);\n+\n+ VhostUserMsg msg = {\n+ .request = VHOST_USER_SET_CONFIG,\n+ .flags = VHOST_USER_VERSION,\n+ .size = config_len,\n+ };\n+\n+ if (reply_supported) {\n+ msg.flags |= VHOST_USER_NEED_REPLY_MASK;\n+ }\n+\n+ if (config_len == 0 || config_len > VHOST_USER_PAYLOAD_SIZE) {\n+ error_report(\"bad config length\");\n+ return -1;\n+ }\n+\n+ memcpy(&msg.payload.config, config, config_len);\n+ if (vhost_user_write(dev, &msg, NULL, 0) < 0) {\n+ return -1;\n+ }\n+\n+ if (reply_supported) {\n+ return process_message_reply(dev, &msg);\n+ }\n+\n+ return 0;\n+}\n+\n+static int vhost_user_set_config_fd(struct vhost_dev *dev, int fd)\n+{\n+ VhostUserMsg msg = {\n+ .request = VHOST_USER_SET_CONFIG_FD,\n+ .flags = VHOST_USER_VERSION,\n+ };\n+\n+ if (vhost_user_write(dev, &msg, &fd, 1) < 0) {\n+ return -1;\n+ }\n+\n+ return 0;\n+}\n+\n const VhostOps user_ops = {\n .backend_type = VHOST_BACKEND_TYPE_USER,\n .vhost_backend_init = vhost_user_init,\n@@ -948,4 +1042,7 @@ const VhostOps user_ops = {\n .vhost_net_set_mtu = vhost_user_net_set_mtu,\n .vhost_set_iotlb_callback = vhost_user_set_iotlb_callback,\n .vhost_send_device_iotlb_msg = vhost_user_send_device_iotlb_msg,\n+ .vhost_get_config = vhost_user_get_config,\n+ .vhost_set_config = vhost_user_set_config,\n+ .vhost_set_config_fd = vhost_user_set_config_fd,\n };\ndiff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c\nindex 5fd69f0..ddc3395 100644\n--- a/hw/virtio/vhost.c\n+++ b/hw/virtio/vhost.c\n@@ -1353,6 +1353,9 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)\n for (i = 0; i < hdev->nvqs; ++i) {\n vhost_virtqueue_cleanup(hdev->vqs + i);\n }\n+ if (hdev->config_ops) {\n+ event_notifier_cleanup(&hdev->config_notifier);\n+ }\n if (hdev->mem) {\n /* those are only safe after successful init */\n memory_listener_unregister(&hdev->memory_listener);\n@@ -1500,6 +1503,66 @@ void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits,\n }\n }\n \n+int vhost_dev_get_config(struct vhost_dev *hdev, uint8_t *config,\n+ size_t config_len)\n+{\n+ assert(hdev->vhost_ops);\n+\n+ if (hdev->vhost_ops->vhost_get_config) {\n+ return hdev->vhost_ops->vhost_get_config(hdev, config, config_len);\n+ }\n+\n+ return 0;\n+}\n+\n+int vhost_dev_set_config(struct vhost_dev *hdev, const uint8_t *config,\n+ size_t config_len)\n+{\n+ assert(hdev->vhost_ops);\n+\n+ if (hdev->vhost_ops->vhost_set_config) {\n+ return hdev->vhost_ops->vhost_set_config(hdev, config, config_len);\n+ }\n+\n+ return 0;\n+}\n+\n+static void vhost_dev_config_notifier_read(EventNotifier *n)\n+{\n+ struct vhost_dev *hdev = container_of(n, struct vhost_dev,\n+ config_notifier);\n+\n+ if (event_notifier_test_and_clear(n)) {\n+ if (hdev->config_ops) {\n+ hdev->config_ops->vhost_dev_config_notifier(hdev);\n+ }\n+ }\n+}\n+\n+int vhost_dev_set_config_notifier(struct vhost_dev *hdev,\n+ const VhostDevConfigOps *ops)\n+{\n+ int r, fd;\n+\n+ assert(hdev->vhost_ops);\n+\n+ r = event_notifier_init(&hdev->config_notifier, 0);\n+ if (r < 0) {\n+ return r;\n+ }\n+\n+ hdev->config_ops = ops;\n+ event_notifier_set_handler(&hdev->config_notifier,\n+ vhost_dev_config_notifier_read);\n+\n+ if (hdev->vhost_ops->vhost_set_config_fd) {\n+ fd = event_notifier_get_fd(&hdev->config_notifier);\n+ return hdev->vhost_ops->vhost_set_config_fd(hdev, fd);\n+ }\n+\n+ return 0;\n+}\n+\n /* Host notifiers must be enabled at this point. */\n int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)\n {\ndiff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h\nindex a7a5f22..df6769e 100644\n--- a/include/hw/virtio/vhost-backend.h\n+++ b/include/hw/virtio/vhost-backend.h\n@@ -84,6 +84,11 @@ typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev,\n int enabled);\n typedef int (*vhost_send_device_iotlb_msg_op)(struct vhost_dev *dev,\n struct vhost_iotlb_msg *imsg);\n+typedef int (*vhost_set_config_op)(struct vhost_dev *dev, const uint8_t *config,\n+ size_t config_len);\n+typedef int (*vhost_get_config_op)(struct vhost_dev *dev, uint8_t *config,\n+ size_t config_len);\n+typedef int (*vhost_set_config_fd_op)(struct vhost_dev *dev, int fd);\n \n typedef struct VhostOps {\n VhostBackendType backend_type;\n@@ -118,6 +123,9 @@ typedef struct VhostOps {\n vhost_vsock_set_running_op vhost_vsock_set_running;\n vhost_set_iotlb_callback_op vhost_set_iotlb_callback;\n vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg;\n+ vhost_get_config_op vhost_get_config;\n+ vhost_set_config_op vhost_set_config;\n+ vhost_set_config_fd_op vhost_set_config_fd;\n } VhostOps;\n \n extern const VhostOps user_ops;\ndiff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h\nindex 467dc77..ff172f2 100644\n--- a/include/hw/virtio/vhost.h\n+++ b/include/hw/virtio/vhost.h\n@@ -46,6 +46,12 @@ struct vhost_iommu {\n QLIST_ENTRY(vhost_iommu) iommu_next;\n };\n \n+typedef struct VhostDevConfigOps {\n+ /* Vhost device config space changed callback\n+ */\n+ void (*vhost_dev_config_notifier)(struct vhost_dev *dev);\n+} VhostDevConfigOps;\n+\n struct vhost_memory;\n struct vhost_dev {\n VirtIODevice *vdev;\n@@ -76,6 +82,8 @@ struct vhost_dev {\n QLIST_ENTRY(vhost_dev) entry;\n QLIST_HEAD(, vhost_iommu) iommu_list;\n IOMMUNotifier n;\n+ EventNotifier config_notifier;\n+ const VhostDevConfigOps *config_ops;\n };\n \n int vhost_dev_init(struct vhost_dev *hdev, void *opaque,\n@@ -106,4 +114,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev,\n struct vhost_vring_file *file);\n \n int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write);\n+int vhost_dev_get_config(struct vhost_dev *dev, uint8_t *config,\n+ size_t config_len);\n+int vhost_dev_set_config(struct vhost_dev *dev, const uint8_t *config,\n+ size_t config_len);\n+/* notifier callback in case vhost device config space changed\n+ */\n+int vhost_dev_set_config_notifier(struct vhost_dev *dev,\n+ const VhostDevConfigOps *ops);\n #endif\n", "prefixes": [ "v3", "1/4" ] }