vhost.c (c95baf12f5077419db01313ab61c2aac007d40cd) vhost.c (792a4f2ed24fcdf0a1956e84fe2a71ada318ba7c)
1// SPDX-License-Identifier: GPL-2.0-only
2/* Copyright (C) 2009 Red Hat, Inc.
3 * Copyright (C) 2006 Rusty Russell IBM Corporation
4 *
5 * Author: Michael S. Tsirkin <mst@redhat.com>
6 *
7 * Inspiration, some code, and most witty comments come from
8 * Documentation/virtual/lguest/lguest.c, by Rusty Russell

--- 443 unchanged lines hidden (view full) ---

452static size_t vhost_get_desc_size(struct vhost_virtqueue *vq,
453 unsigned int num)
454{
455 return sizeof(*vq->desc) * num;
456}
457
458void vhost_dev_init(struct vhost_dev *dev,
459 struct vhost_virtqueue **vqs, int nvqs,
1// SPDX-License-Identifier: GPL-2.0-only
2/* Copyright (C) 2009 Red Hat, Inc.
3 * Copyright (C) 2006 Rusty Russell IBM Corporation
4 *
5 * Author: Michael S. Tsirkin <mst@redhat.com>
6 *
7 * Inspiration, some code, and most witty comments come from
8 * Documentation/virtual/lguest/lguest.c, by Rusty Russell

--- 443 unchanged lines hidden (view full) ---

452static size_t vhost_get_desc_size(struct vhost_virtqueue *vq,
453 unsigned int num)
454{
455 return sizeof(*vq->desc) * num;
456}
457
458void vhost_dev_init(struct vhost_dev *dev,
459 struct vhost_virtqueue **vqs, int nvqs,
460 int iov_limit, int weight, int byte_weight)
460 int iov_limit, int weight, int byte_weight,
461 int (*msg_handler)(struct vhost_dev *dev,
462 struct vhost_iotlb_msg *msg))
461{
462 struct vhost_virtqueue *vq;
463 int i;
464
465 dev->vqs = vqs;
466 dev->nvqs = nvqs;
467 mutex_init(&dev->mutex);
468 dev->log_ctx = NULL;
469 dev->umem = NULL;
470 dev->iotlb = NULL;
471 dev->mm = NULL;
472 dev->worker = NULL;
473 dev->iov_limit = iov_limit;
474 dev->weight = weight;
475 dev->byte_weight = byte_weight;
463{
464 struct vhost_virtqueue *vq;
465 int i;
466
467 dev->vqs = vqs;
468 dev->nvqs = nvqs;
469 mutex_init(&dev->mutex);
470 dev->log_ctx = NULL;
471 dev->umem = NULL;
472 dev->iotlb = NULL;
473 dev->mm = NULL;
474 dev->worker = NULL;
475 dev->iov_limit = iov_limit;
476 dev->weight = weight;
477 dev->byte_weight = byte_weight;
478 dev->msg_handler = msg_handler;
476 init_llist_head(&dev->work_list);
477 init_waitqueue_head(&dev->wait);
478 INIT_LIST_HEAD(&dev->read_list);
479 INIT_LIST_HEAD(&dev->pending_list);
480 spin_lock_init(&dev->iotlb_lock);
481
482
483 for (i = 0; i < dev->nvqs; ++i) {

--- 689 unchanged lines hidden (view full) ---

1173 }
1174
1175 iov_iter_advance(from, offset);
1176 ret = copy_from_iter(&msg, sizeof(msg), from);
1177 if (ret != sizeof(msg)) {
1178 ret = -EINVAL;
1179 goto done;
1180 }
479 init_llist_head(&dev->work_list);
480 init_waitqueue_head(&dev->wait);
481 INIT_LIST_HEAD(&dev->read_list);
482 INIT_LIST_HEAD(&dev->pending_list);
483 spin_lock_init(&dev->iotlb_lock);
484
485
486 for (i = 0; i < dev->nvqs; ++i) {

--- 689 unchanged lines hidden (view full) ---

1176 }
1177
1178 iov_iter_advance(from, offset);
1179 ret = copy_from_iter(&msg, sizeof(msg), from);
1180 if (ret != sizeof(msg)) {
1181 ret = -EINVAL;
1182 goto done;
1183 }
1181 if (vhost_process_iotlb_msg(dev, &msg)) {
1184
1185 if (dev->msg_handler)
1186 ret = dev->msg_handler(dev, &msg);
1187 else
1188 ret = vhost_process_iotlb_msg(dev, &msg);
1189 if (ret) {
1182 ret = -EFAULT;
1183 goto done;
1184 }
1185
1186 ret = (type == VHOST_IOTLB_MSG) ? sizeof(struct vhost_msg) :
1187 sizeof(struct vhost_msg_v2);
1188done:
1189 return ret;

--- 1453 unchanged lines hidden ---
1190 ret = -EFAULT;
1191 goto done;
1192 }
1193
1194 ret = (type == VHOST_IOTLB_MSG) ? sizeof(struct vhost_msg) :
1195 sizeof(struct vhost_msg_v2);
1196done:
1197 return ret;

--- 1453 unchanged lines hidden ---