2018-05-24 13:33:33 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017-2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HW_VIRTIO_VHOST_USER_H
|
|
|
|
#define HW_VIRTIO_VHOST_USER_H
|
|
|
|
|
|
|
|
#include "chardev/char-fe.h"
|
2018-05-24 13:33:34 +03:00
|
|
|
#include "hw/virtio/virtio.h"
|
|
|
|
|
2023-09-27 01:41:07 +03:00
|
|
|
enum VhostUserProtocolFeature {
|
|
|
|
VHOST_USER_PROTOCOL_F_MQ = 0,
|
|
|
|
VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
|
|
|
|
VHOST_USER_PROTOCOL_F_RARP = 2,
|
|
|
|
VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
|
|
|
|
VHOST_USER_PROTOCOL_F_NET_MTU = 4,
|
|
|
|
VHOST_USER_PROTOCOL_F_BACKEND_REQ = 5,
|
|
|
|
VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
|
|
|
|
VHOST_USER_PROTOCOL_F_CRYPTO_SESSION = 7,
|
|
|
|
VHOST_USER_PROTOCOL_F_PAGEFAULT = 8,
|
|
|
|
VHOST_USER_PROTOCOL_F_CONFIG = 9,
|
|
|
|
VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD = 10,
|
|
|
|
VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11,
|
|
|
|
VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12,
|
|
|
|
VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
|
|
|
|
VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS = 14,
|
|
|
|
VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS = 15,
|
|
|
|
VHOST_USER_PROTOCOL_F_STATUS = 16,
|
vhost-user: Fix protocol feature bit conflict
The VHOST_USER_PROTOCOL_F_XEN_MMAP feature bit was defined in
f21e95ee97d, which has been part of qemu's 8.1.0 release. However, it
seems it was never added to qemu's code, but it is well possible that it
is already used by different front-ends outside of qemu (i.e., Xen).
VHOST_USER_PROTOCOL_F_SHARED_OBJECT in contrast was added to qemu's code
in 16094766627, but never defined in the vhost-user specification. As a
consequence, both bits were defined to be 17, which cannot work.
Regardless of whether actual code or the specification should take
precedence, F_XEN_MMAP is already part of a qemu release, while
F_SHARED_OBJECT is not. Therefore, bump the latter to take number 18
instead of 17, and add this to the specification.
Take the opportunity to add at least a little note on the
VhostUserShared structure to the specification. This structure is
referenced by the new commands introduced in 16094766627, but was not
defined.
Fixes: 160947666276c5b7f6bca4d746bcac2966635d79
("vhost-user: add shared_object msg")
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Message-Id: <20231016083201.23736-1-hreitz@redhat.com>
Reviewed-by: Emmanouil Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2023-10-16 11:32:01 +03:00
|
|
|
/* Feature 17 reserved for VHOST_USER_PROTOCOL_F_XEN_MMAP. */
|
|
|
|
VHOST_USER_PROTOCOL_F_SHARED_OBJECT = 18,
|
2023-09-27 01:41:07 +03:00
|
|
|
VHOST_USER_PROTOCOL_F_MAX
|
|
|
|
};
|
|
|
|
|
2022-03-21 18:30:37 +03:00
|
|
|
/**
|
|
|
|
* VhostUserHostNotifier - notifier information for one queue
|
|
|
|
* @rcu: rcu_head for cleanup
|
|
|
|
* @mr: memory region of notifier
|
|
|
|
* @addr: current mapped address
|
|
|
|
* @unmap_addr: address to be un-mapped
|
|
|
|
* @idx: virtioqueue index
|
|
|
|
*
|
|
|
|
* The VhostUserHostNotifier entries are re-used. When an old mapping
|
|
|
|
* is to be released it is moved to @unmap_addr and @addr is replaced.
|
|
|
|
* Once the RCU process has completed the unmap @unmap_addr is
|
|
|
|
* cleared.
|
|
|
|
*/
|
2018-05-24 13:33:34 +03:00
|
|
|
typedef struct VhostUserHostNotifier {
|
2022-02-07 10:19:29 +03:00
|
|
|
struct rcu_head rcu;
|
2018-05-24 13:33:34 +03:00
|
|
|
MemoryRegion mr;
|
|
|
|
void *addr;
|
2022-02-07 10:19:29 +03:00
|
|
|
void *unmap_addr;
|
2022-03-21 18:30:37 +03:00
|
|
|
int idx;
|
2018-05-24 13:33:34 +03:00
|
|
|
} VhostUserHostNotifier;
|
2018-05-24 13:33:33 +03:00
|
|
|
|
2022-03-21 18:30:37 +03:00
|
|
|
/**
|
|
|
|
* VhostUserState - shared state for all vhost-user devices
|
|
|
|
* @chr: the character backend for the socket
|
|
|
|
* @notifiers: GPtrArray of @VhostUserHostnotifier
|
|
|
|
* @memory_slots:
|
|
|
|
*/
|
2018-05-24 13:33:33 +03:00
|
|
|
typedef struct VhostUserState {
|
|
|
|
CharBackend *chr;
|
2022-03-21 18:30:37 +03:00
|
|
|
GPtrArray *notifiers;
|
2020-05-21 08:00:32 +03:00
|
|
|
int memory_slots;
|
2022-03-21 18:30:36 +03:00
|
|
|
bool supports_config;
|
2018-05-24 13:33:33 +03:00
|
|
|
} VhostUserState;
|
|
|
|
|
2022-03-21 18:30:37 +03:00
|
|
|
/**
|
|
|
|
* vhost_user_init() - initialise shared vhost_user state
|
|
|
|
* @user: allocated area for storing shared state
|
|
|
|
* @chr: the chardev for the vhost socket
|
|
|
|
* @errp: error handle
|
|
|
|
*
|
|
|
|
* User can either directly g_new() space for the state or embed
|
|
|
|
* VhostUserState in their larger device structure and just point to
|
|
|
|
* it.
|
|
|
|
*
|
|
|
|
* Return: true on success, false on error while setting errp.
|
|
|
|
*/
|
2019-03-08 17:04:45 +03:00
|
|
|
bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp);
|
2022-03-21 18:30:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* vhost_user_cleanup() - cleanup state
|
|
|
|
* @user: ptr to use state
|
|
|
|
*
|
|
|
|
* Cleans up shared state and notifiers, callee is responsible for
|
|
|
|
* freeing the @VhostUserState memory itself.
|
|
|
|
*/
|
2018-05-24 13:33:33 +03:00
|
|
|
void vhost_user_cleanup(VhostUserState *user);
|
|
|
|
|
2022-11-30 14:24:38 +03:00
|
|
|
/**
|
|
|
|
* 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,
|
vhost-user: fix lost reconnect
When the vhost-user is reconnecting to the backend, and if the vhost-user fails
at the get_features in vhost_dev_init(), then the reconnect will fail
and it will not be retriggered forever.
The reason is:
When the vhost-user fails at get_features, the vhost_dev_cleanup will be called
immediately.
vhost_dev_cleanup calls 'memset(hdev, 0, sizeof(struct vhost_dev))'.
The reconnect path is:
vhost_user_blk_event
vhost_user_async_close(.. vhost_user_blk_disconnect ..)
qemu_chr_fe_set_handlers <----- clear the notifier callback
schedule vhost_user_async_close_bh
The vhost->vdev is null, so the vhost_user_blk_disconnect will not be
called, then the event fd callback will not be reinstalled.
All vhost-user devices have this issue, including vhost-user-blk/scsi.
With this patch, if the vdev->vdev is null, the fd callback will still
be reinstalled.
Fixes: 71e076a07d ("hw/virtio: generalise CHR_EVENT_CLOSED handling")
Signed-off-by: Li Feng <fengli@smartx.com>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Message-Id: <20231009044735.941655-6-fengli@smartx.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2023-10-09 07:47:01 +03:00
|
|
|
vu_async_close_fn cb,
|
|
|
|
IOEventHandler *event_cb);
|
2022-11-30 14:24:38 +03:00
|
|
|
|
2018-05-24 13:33:33 +03:00
|
|
|
#endif
|