xref: /linux/drivers/vhost/vhost.h (revision a23e1966932464e1c5226cb9ac4ce1d5fc10ba22)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
23a4d5c94SMichael S. Tsirkin #ifndef _VHOST_H
33a4d5c94SMichael S. Tsirkin #define _VHOST_H
43a4d5c94SMichael S. Tsirkin 
53a4d5c94SMichael S. Tsirkin #include <linux/eventfd.h>
63a4d5c94SMichael S. Tsirkin #include <linux/vhost.h>
73a4d5c94SMichael S. Tsirkin #include <linux/mm.h>
83a4d5c94SMichael S. Tsirkin #include <linux/mutex.h>
93a4d5c94SMichael S. Tsirkin #include <linux/poll.h>
103a4d5c94SMichael S. Tsirkin #include <linux/file.h>
113a4d5c94SMichael S. Tsirkin #include <linux/uio.h>
123a4d5c94SMichael S. Tsirkin #include <linux/virtio_config.h>
133a4d5c94SMichael S. Tsirkin #include <linux/virtio_ring.h>
1460063497SArun Sharma #include <linux/atomic.h>
150bbe3066SJason Wang #include <linux/vhost_iotlb.h>
16265a0ad8SZhu Lingshan #include <linux/irqbypass.h>
173a4d5c94SMichael S. Tsirkin 
18c23f3445STejun Heo struct vhost_work;
196e890c5dSMike Christie struct vhost_task;
20c23f3445STejun Heo typedef void (*vhost_work_fn_t)(struct vhost_work *work);
21c23f3445STejun Heo 
2204b96e55SJason Wang #define VHOST_WORK_QUEUED 1
23c23f3445STejun Heo struct vhost_work {
2404b96e55SJason Wang 	struct llist_node	node;
25c23f3445STejun Heo 	vhost_work_fn_t		fn;
2604b96e55SJason Wang 	unsigned long		flags;
27c23f3445STejun Heo };
28c23f3445STejun Heo 
291a5f8090SMike Christie struct vhost_worker {
306e890c5dSMike Christie 	struct vhost_task	*vtsk;
31228a27cfSMike Christie 	/* Used to serialize device wide flushing with worker swapping. */
32228a27cfSMike Christie 	struct mutex		mutex;
331a5f8090SMike Christie 	struct llist_head	work_list;
341a5f8090SMike Christie 	u64			kcov_handle;
351cdaafa1SMike Christie 	u32			id;
36c1ecd8e9SMike Christie 	int			attachment_cnt;
371a5f8090SMike Christie };
381a5f8090SMike Christie 
393a4d5c94SMichael S. Tsirkin /* Poll a file (eventfd or socket) */
403a4d5c94SMichael S. Tsirkin /* Note: there's nothing vhost specific about this structure. */
413a4d5c94SMichael S. Tsirkin struct vhost_poll {
423a4d5c94SMichael S. Tsirkin 	poll_table		table;
433a4d5c94SMichael S. Tsirkin 	wait_queue_head_t	*wqh;
44ac6424b9SIngo Molnar 	wait_queue_entry_t	wait;
45c23f3445STejun Heo 	struct vhost_work	work;
4658e3b602SAl Viro 	__poll_t		mask;
47c23f3445STejun Heo 	struct vhost_dev	*dev;
48493b94bfSMike Christie 	struct vhost_virtqueue	*vq;
493a4d5c94SMichael S. Tsirkin };
503a4d5c94SMichael S. Tsirkin 
51c23f3445STejun Heo void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
52493b94bfSMike Christie 		     __poll_t mask, struct vhost_dev *dev,
53493b94bfSMike Christie 		     struct vhost_virtqueue *vq);
542b8b328bSJason Wang int vhost_poll_start(struct vhost_poll *poll, struct file *file);
553a4d5c94SMichael S. Tsirkin void vhost_poll_stop(struct vhost_poll *poll);
563a4d5c94SMichael S. Tsirkin void vhost_poll_queue(struct vhost_poll *poll);
5727eca189SMike Christie 
5827eca189SMike Christie void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn);
59b2ffa407SMike Christie void vhost_dev_flush(struct vhost_dev *dev);
603a4d5c94SMichael S. Tsirkin 
613a4d5c94SMichael S. Tsirkin struct vhost_log {
623a4d5c94SMichael S. Tsirkin 	u64 addr;
633a4d5c94SMichael S. Tsirkin 	u64 len;
643a4d5c94SMichael S. Tsirkin };
653a4d5c94SMichael S. Tsirkin 
66f8894913SJason Wang enum vhost_uaddr_type {
67f8894913SJason Wang 	VHOST_ADDR_DESC = 0,
68f8894913SJason Wang 	VHOST_ADDR_AVAIL = 1,
69f8894913SJason Wang 	VHOST_ADDR_USED = 2,
70f8894913SJason Wang 	VHOST_NUM_ADDRS = 3,
71f8894913SJason Wang };
72f8894913SJason Wang 
73265a0ad8SZhu Lingshan struct vhost_vring_call {
74265a0ad8SZhu Lingshan 	struct eventfd_ctx *ctx;
75265a0ad8SZhu Lingshan 	struct irq_bypass_producer producer;
76265a0ad8SZhu Lingshan };
77265a0ad8SZhu Lingshan 
783a4d5c94SMichael S. Tsirkin /* The virtqueue structure describes a queue attached to a device. */
793a4d5c94SMichael S. Tsirkin struct vhost_virtqueue {
803a4d5c94SMichael S. Tsirkin 	struct vhost_dev *dev;
81228a27cfSMike Christie 	struct vhost_worker __rcu *worker;
823a4d5c94SMichael S. Tsirkin 
833a4d5c94SMichael S. Tsirkin 	/* The actual ring of buffers. */
843a4d5c94SMichael S. Tsirkin 	struct mutex mutex;
853a4d5c94SMichael S. Tsirkin 	unsigned int num;
86a865e420SMichael S. Tsirkin 	vring_desc_t __user *desc;
87a865e420SMichael S. Tsirkin 	vring_avail_t __user *avail;
88a865e420SMichael S. Tsirkin 	vring_used_t __user *used;
890bbe3066SJason Wang 	const struct vhost_iotlb_map *meta_iotlb[VHOST_NUM_ADDRS];
903a4d5c94SMichael S. Tsirkin 	struct file *kick;
91265a0ad8SZhu Lingshan 	struct vhost_vring_call call_ctx;
923a4d5c94SMichael S. Tsirkin 	struct eventfd_ctx *error_ctx;
933a4d5c94SMichael S. Tsirkin 	struct eventfd_ctx *log_ctx;
943a4d5c94SMichael S. Tsirkin 
953a4d5c94SMichael S. Tsirkin 	struct vhost_poll poll;
963a4d5c94SMichael S. Tsirkin 
973a4d5c94SMichael S. Tsirkin 	/* The routine to call when the Guest pings us, or timeout. */
98c23f3445STejun Heo 	vhost_work_fn_t handle_kick;
993a4d5c94SMichael S. Tsirkin 
10055d8122fSShannon Nelson 	/* Last available index we saw.
10155d8122fSShannon Nelson 	 * Values are limited to 0x7fff, and the high bit is used as
10255d8122fSShannon Nelson 	 * a wrap counter when using VIRTIO_F_RING_PACKED. */
1033a4d5c94SMichael S. Tsirkin 	u16 last_avail_idx;
1043a4d5c94SMichael S. Tsirkin 
1053a4d5c94SMichael S. Tsirkin 	/* Caches available index value from user. */
1063a4d5c94SMichael S. Tsirkin 	u16 avail_idx;
1073a4d5c94SMichael S. Tsirkin 
10855d8122fSShannon Nelson 	/* Last index we used.
10955d8122fSShannon Nelson 	 * Values are limited to 0x7fff, and the high bit is used as
11055d8122fSShannon Nelson 	 * a wrap counter when using VIRTIO_F_RING_PACKED. */
1113a4d5c94SMichael S. Tsirkin 	u16 last_used_idx;
1123a4d5c94SMichael S. Tsirkin 
1133a4d5c94SMichael S. Tsirkin 	/* Used flags */
1143a4d5c94SMichael S. Tsirkin 	u16 used_flags;
1153a4d5c94SMichael S. Tsirkin 
1168ea8cf89SMichael S. Tsirkin 	/* Last used index value we have signalled on */
1178ea8cf89SMichael S. Tsirkin 	u16 signalled_used;
1188ea8cf89SMichael S. Tsirkin 
1198ea8cf89SMichael S. Tsirkin 	/* Last used index value we have signalled on */
1208ea8cf89SMichael S. Tsirkin 	bool signalled_used_valid;
1218ea8cf89SMichael S. Tsirkin 
1223a4d5c94SMichael S. Tsirkin 	/* Log writes to used structure. */
1233a4d5c94SMichael S. Tsirkin 	bool log_used;
1243a4d5c94SMichael S. Tsirkin 	u64 log_addr;
1253a4d5c94SMichael S. Tsirkin 
126e0e9b406SJason Wang 	struct iovec iov[UIO_MAXIOV];
1276b1e6cc7SJason Wang 	struct iovec iotlb_iov[64];
128e0e9b406SJason Wang 	struct iovec *indirect;
129e0e9b406SJason Wang 	struct vring_used_elem *heads;
13022fa90c7SAsias He 	/* Protected by virtqueue mutex. */
1310bbe3066SJason Wang 	struct vhost_iotlb *umem;
1320bbe3066SJason Wang 	struct vhost_iotlb *iotlb;
13322fa90c7SAsias He 	void *private_data;
134bd82752aSMichael S. Tsirkin 	u64 acked_features;
135429711aeSJason Wang 	u64 acked_backend_features;
1363a4d5c94SMichael S. Tsirkin 	/* Log write descriptors */
1373a4d5c94SMichael S. Tsirkin 	void __user *log_base;
138e0e9b406SJason Wang 	struct vhost_log *log;
1395e5e8736SLi Wang 	struct iovec log_iov[64];
1402751c988SGreg Kurz 
1412751c988SGreg Kurz 	/* Ring endianness. Defaults to legacy native endianness.
1422751c988SGreg Kurz 	 * Set to true when starting a modern virtio device. */
1432751c988SGreg Kurz 	bool is_le;
1442751c988SGreg Kurz #ifdef CONFIG_VHOST_CROSS_ENDIAN_LEGACY
1452751c988SGreg Kurz 	/* Ring endianness requested by userspace for cross-endian support. */
1462751c988SGreg Kurz 	bool user_be;
1472751c988SGreg Kurz #endif
14803088137SJason Wang 	u32 busyloop_timeout;
1493a4d5c94SMichael S. Tsirkin };
1503a4d5c94SMichael S. Tsirkin 
1516b1e6cc7SJason Wang struct vhost_msg_node {
152429711aeSJason Wang   union {
1536b1e6cc7SJason Wang 	  struct vhost_msg msg;
154429711aeSJason Wang 	  struct vhost_msg_v2 msg_v2;
155429711aeSJason Wang   };
1566b1e6cc7SJason Wang   struct vhost_virtqueue *vq;
1576b1e6cc7SJason Wang   struct list_head node;
1586b1e6cc7SJason Wang };
1596b1e6cc7SJason Wang 
1603a4d5c94SMichael S. Tsirkin struct vhost_dev {
1613a4d5c94SMichael S. Tsirkin 	struct mm_struct *mm;
1623a4d5c94SMichael S. Tsirkin 	struct mutex mutex;
1633ab2e420SAsias He 	struct vhost_virtqueue **vqs;
1643a4d5c94SMichael S. Tsirkin 	int nvqs;
1653a4d5c94SMichael S. Tsirkin 	struct eventfd_ctx *log_ctx;
1660bbe3066SJason Wang 	struct vhost_iotlb *umem;
1670bbe3066SJason Wang 	struct vhost_iotlb *iotlb;
1686b1e6cc7SJason Wang 	spinlock_t iotlb_lock;
1696b1e6cc7SJason Wang 	struct list_head read_list;
1706b1e6cc7SJason Wang 	struct list_head pending_list;
1716b1e6cc7SJason Wang 	wait_queue_head_t wait;
172b46a0bf7SJason Wang 	int iov_limit;
173e82b9b07SJason Wang 	int weight;
174e82b9b07SJason Wang 	int byte_weight;
1751cdaafa1SMike Christie 	struct xarray worker_xa;
17601fcb1cbSJason Wang 	bool use_worker;
17791233ad7SGautam Dawar 	int (*msg_handler)(struct vhost_dev *dev, u32 asid,
178792a4f2eSJason Wang 			   struct vhost_iotlb_msg *msg);
1793a4d5c94SMichael S. Tsirkin };
1803a4d5c94SMichael S. Tsirkin 
181e82b9b07SJason Wang bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len);
182b46a0bf7SJason Wang void vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs,
183792a4f2eSJason Wang 		    int nvqs, int iov_limit, int weight, int byte_weight,
18401fcb1cbSJason Wang 		    bool use_worker,
18591233ad7SGautam Dawar 		    int (*msg_handler)(struct vhost_dev *dev, u32 asid,
186792a4f2eSJason Wang 				       struct vhost_iotlb_msg *msg));
18754db63c2SAsias He long vhost_dev_set_owner(struct vhost_dev *dev);
18805c05351SMichael S. Tsirkin bool vhost_dev_has_owner(struct vhost_dev *dev);
1893a4d5c94SMichael S. Tsirkin long vhost_dev_check_owner(struct vhost_dev *);
1900bbe3066SJason Wang struct vhost_iotlb *vhost_dev_reset_owner_prepare(void);
1910bbe3066SJason Wang void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_iotlb *iotlb);
192f6f93f75S夷则(Caspar) void vhost_dev_cleanup(struct vhost_dev *);
193b211616dSMichael S. Tsirkin void vhost_dev_stop(struct vhost_dev *);
194935cdee7SMichael S. Tsirkin long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, void __user *argp);
19526b36604SSonny Rao long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp);
196c1ecd8e9SMike Christie long vhost_worker_ioctl(struct vhost_dev *dev, unsigned int ioctl,
197c1ecd8e9SMike Christie 			void __user *argp);
198ddd3d408SStefan Hajnoczi bool vhost_vq_access_ok(struct vhost_virtqueue *vq);
199ddd3d408SStefan Hajnoczi bool vhost_log_access_ok(struct vhost_dev *);
2009526f9a2SEric Auger void vhost_clear_msg(struct vhost_dev *dev);
2013a4d5c94SMichael S. Tsirkin 
20247283befSMichael S. Tsirkin int vhost_get_vq_desc(struct vhost_virtqueue *,
2039e396a2fSXianting Tian 		      struct iovec iov[], unsigned int iov_size,
2043a4d5c94SMichael S. Tsirkin 		      unsigned int *out_num, unsigned int *in_num,
2053a4d5c94SMichael S. Tsirkin 		      struct vhost_log *log, unsigned int *log_num);
2068dd014adSDavid Stevens void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);
2073a4d5c94SMichael S. Tsirkin 
208a6fc0473SMike Christie void vhost_vq_flush(struct vhost_virtqueue *vq);
2090921dddcSMike Christie bool vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *work);
2109784df15SMike Christie bool vhost_vq_has_work(struct vhost_virtqueue *vq);
2116bcf3422SMike Christie bool vhost_vq_is_setup(struct vhost_virtqueue *vq);
21280f7d030SGreg Kurz int vhost_vq_init_access(struct vhost_virtqueue *);
2133a4d5c94SMichael S. Tsirkin int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len);
2148dd014adSDavid Stevens int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads,
2158dd014adSDavid Stevens 		     unsigned count);
2163a4d5c94SMichael S. Tsirkin void vhost_add_used_and_signal(struct vhost_dev *, struct vhost_virtqueue *,
2178dd014adSDavid Stevens 			       unsigned int id, int len);
2188dd014adSDavid Stevens void vhost_add_used_and_signal_n(struct vhost_dev *, struct vhost_virtqueue *,
2198dd014adSDavid Stevens 			       struct vring_used_elem *heads, unsigned count);
2208dd014adSDavid Stevens void vhost_signal(struct vhost_dev *, struct vhost_virtqueue *);
2218ea8cf89SMichael S. Tsirkin void vhost_disable_notify(struct vhost_dev *, struct vhost_virtqueue *);
222d4a60603SJason Wang bool vhost_vq_avail_empty(struct vhost_dev *, struct vhost_virtqueue *);
2238ea8cf89SMichael S. Tsirkin bool vhost_enable_notify(struct vhost_dev *, struct vhost_virtqueue *);
2243a4d5c94SMichael S. Tsirkin 
2253a4d5c94SMichael S. Tsirkin int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
226cc5e7107SJason Wang 		    unsigned int log_num, u64 len,
227cc5e7107SJason Wang 		    struct iovec *iov, int count);
2289b5e830bSJason Wang int vq_meta_prefetch(struct vhost_virtqueue *vq);
2296b1e6cc7SJason Wang 
2306b1e6cc7SJason Wang struct vhost_msg_node *vhost_new_msg(struct vhost_virtqueue *vq, int type);
2316b1e6cc7SJason Wang void vhost_enqueue_msg(struct vhost_dev *dev,
2326b1e6cc7SJason Wang 		       struct list_head *head,
2336b1e6cc7SJason Wang 		       struct vhost_msg_node *node);
2346b1e6cc7SJason Wang struct vhost_msg_node *vhost_dequeue_msg(struct vhost_dev *dev,
2356b1e6cc7SJason Wang 					 struct list_head *head);
236460f7ce1SJason Wang void vhost_set_backend_features(struct vhost_dev *dev, u64 features);
237460f7ce1SJason Wang 
238afc9a42bSAl Viro __poll_t vhost_chr_poll(struct file *file, struct vhost_dev *dev,
2396b1e6cc7SJason Wang 			    poll_table *wait);
2406b1e6cc7SJason Wang ssize_t vhost_chr_read_iter(struct vhost_dev *dev, struct iov_iter *to,
2416b1e6cc7SJason Wang 			    int noblock);
2426b1e6cc7SJason Wang ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
2436b1e6cc7SJason Wang 			     struct iov_iter *from);
244759aba1eSLiming Wu int vhost_init_device_iotlb(struct vhost_dev *d);
2453a4d5c94SMichael S. Tsirkin 
2460bbe3066SJason Wang void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
2470bbe3066SJason Wang 			  struct vhost_iotlb_map *map);
2480bbe3066SJason Wang 
2493a4d5c94SMichael S. Tsirkin #define vq_err(vq, fmt, ...) do {                                  \
2503a4d5c94SMichael S. Tsirkin 		pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
2513a4d5c94SMichael S. Tsirkin 		if ((vq)->error_ctx)                               \
252*3652117fSChristian Brauner 				eventfd_signal((vq)->error_ctx);\
2533a4d5c94SMichael S. Tsirkin 	} while (0)
2543a4d5c94SMichael S. Tsirkin 
2553a4d5c94SMichael S. Tsirkin enum {
2568ea8cf89SMichael S. Tsirkin 	VHOST_FEATURES = (1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) |
2578ea8cf89SMichael S. Tsirkin 			 (1ULL << VIRTIO_RING_F_INDIRECT_DESC) |
2588ea8cf89SMichael S. Tsirkin 			 (1ULL << VIRTIO_RING_F_EVENT_IDX) |
2594e9fa50cSMichael S. Tsirkin 			 (1ULL << VHOST_F_LOG_ALL) |
2604e9fa50cSMichael S. Tsirkin 			 (1ULL << VIRTIO_F_ANY_LAYOUT) |
2614e9fa50cSMichael S. Tsirkin 			 (1ULL << VIRTIO_F_VERSION_1)
2623a4d5c94SMichael S. Tsirkin };
2633a4d5c94SMichael S. Tsirkin 
264247643f8SEugenio Pérez /**
265247643f8SEugenio Pérez  * vhost_vq_set_backend - Set backend.
266247643f8SEugenio Pérez  *
267247643f8SEugenio Pérez  * @vq            Virtqueue.
268247643f8SEugenio Pérez  * @private_data  The private data.
269247643f8SEugenio Pérez  *
270247643f8SEugenio Pérez  * Context: Need to call with vq->mutex acquired.
271247643f8SEugenio Pérez  */
272247643f8SEugenio Pérez static inline void vhost_vq_set_backend(struct vhost_virtqueue *vq,
273247643f8SEugenio Pérez 					void *private_data)
274247643f8SEugenio Pérez {
275247643f8SEugenio Pérez 	vq->private_data = private_data;
276247643f8SEugenio Pérez }
277247643f8SEugenio Pérez 
278247643f8SEugenio Pérez /**
279247643f8SEugenio Pérez  * vhost_vq_get_backend - Get backend.
280247643f8SEugenio Pérez  *
281247643f8SEugenio Pérez  * @vq            Virtqueue.
282247643f8SEugenio Pérez  *
283247643f8SEugenio Pérez  * Context: Need to call with vq->mutex acquired.
284247643f8SEugenio Pérez  * Return: Private data previously set with vhost_vq_set_backend.
285247643f8SEugenio Pérez  */
286247643f8SEugenio Pérez static inline void *vhost_vq_get_backend(struct vhost_virtqueue *vq)
287247643f8SEugenio Pérez {
288247643f8SEugenio Pérez 	return vq->private_data;
289247643f8SEugenio Pérez }
290247643f8SEugenio Pérez 
291bd82752aSMichael S. Tsirkin static inline bool vhost_has_feature(struct vhost_virtqueue *vq, int bit)
2923a4d5c94SMichael S. Tsirkin {
293bd82752aSMichael S. Tsirkin 	return vq->acked_features & (1ULL << bit);
2943a4d5c94SMichael S. Tsirkin }
295e05fd12bSMichael S. Tsirkin 
296429711aeSJason Wang static inline bool vhost_backend_has_feature(struct vhost_virtqueue *vq, int bit)
297429711aeSJason Wang {
298429711aeSJason Wang 	return vq->acked_backend_features & (1ULL << bit);
299429711aeSJason Wang }
300429711aeSJason Wang 
301e407f39aSMichael S. Tsirkin #ifdef CONFIG_VHOST_CROSS_ENDIAN_LEGACY
302ab27c07fSGreg Kurz static inline bool vhost_is_little_endian(struct vhost_virtqueue *vq)
303ab27c07fSGreg Kurz {
3042751c988SGreg Kurz 	return vq->is_le;
305ab27c07fSGreg Kurz }
306e407f39aSMichael S. Tsirkin #else
307e407f39aSMichael S. Tsirkin static inline bool vhost_is_little_endian(struct vhost_virtqueue *vq)
308e407f39aSMichael S. Tsirkin {
309e407f39aSMichael S. Tsirkin 	return virtio_legacy_is_little_endian() || vq->is_le;
310e407f39aSMichael S. Tsirkin }
311e407f39aSMichael S. Tsirkin #endif
312ab27c07fSGreg Kurz 
313e05fd12bSMichael S. Tsirkin /* Memory accessors */
314e05fd12bSMichael S. Tsirkin static inline u16 vhost16_to_cpu(struct vhost_virtqueue *vq, __virtio16 val)
315e05fd12bSMichael S. Tsirkin {
316ab27c07fSGreg Kurz 	return __virtio16_to_cpu(vhost_is_little_endian(vq), val);
317e05fd12bSMichael S. Tsirkin }
318e05fd12bSMichael S. Tsirkin 
319e05fd12bSMichael S. Tsirkin static inline __virtio16 cpu_to_vhost16(struct vhost_virtqueue *vq, u16 val)
320e05fd12bSMichael S. Tsirkin {
321ab27c07fSGreg Kurz 	return __cpu_to_virtio16(vhost_is_little_endian(vq), val);
322e05fd12bSMichael S. Tsirkin }
323e05fd12bSMichael S. Tsirkin 
324e05fd12bSMichael S. Tsirkin static inline u32 vhost32_to_cpu(struct vhost_virtqueue *vq, __virtio32 val)
325e05fd12bSMichael S. Tsirkin {
326ab27c07fSGreg Kurz 	return __virtio32_to_cpu(vhost_is_little_endian(vq), val);
327e05fd12bSMichael S. Tsirkin }
328e05fd12bSMichael S. Tsirkin 
329e05fd12bSMichael S. Tsirkin static inline __virtio32 cpu_to_vhost32(struct vhost_virtqueue *vq, u32 val)
330e05fd12bSMichael S. Tsirkin {
331ab27c07fSGreg Kurz 	return __cpu_to_virtio32(vhost_is_little_endian(vq), val);
332e05fd12bSMichael S. Tsirkin }
333e05fd12bSMichael S. Tsirkin 
334e05fd12bSMichael S. Tsirkin static inline u64 vhost64_to_cpu(struct vhost_virtqueue *vq, __virtio64 val)
335e05fd12bSMichael S. Tsirkin {
336ab27c07fSGreg Kurz 	return __virtio64_to_cpu(vhost_is_little_endian(vq), val);
337e05fd12bSMichael S. Tsirkin }
338e05fd12bSMichael S. Tsirkin 
339e05fd12bSMichael S. Tsirkin static inline __virtio64 cpu_to_vhost64(struct vhost_virtqueue *vq, u64 val)
340e05fd12bSMichael S. Tsirkin {
341ab27c07fSGreg Kurz 	return __cpu_to_virtio64(vhost_is_little_endian(vq), val);
342e05fd12bSMichael S. Tsirkin }
3433a4d5c94SMichael S. Tsirkin #endif
344