History

vhost: allow per device message handler

This patch allow device to register its own message handler during vhost_dev_init(). vDPA device will use it to implement its own DMA mapping logic.

Jason Wang committed 6 years ago

Commit 792a4f21 parent 20c384f5 files · +19 −6Browse files

Unified · Split

5 files
  1. drivers/vhost/net.c +2 −1
  2. drivers/vhost/scsi.c +1 −1
  3. drivers/vhost/vhost.c +10 −2
  4. drivers/vhost/vhost.h +5 −1
  5. drivers/vhost/vsock.c +1 −1
drivers/vhost/net.c+2−1
@@ -1324,7 +1324,8 @@ static int vhost_net_open(struct inode *inode, struct file *f) · 1323 unmodified lines
13241324 }
13251325 vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX,
13261326 UIO_MAXIOV + VHOST_NET_BATCH,
1327− VHOST_NET_PKT_WEIGHT, VHOST_NET_WEIGHT);
1327+ VHOST_NET_PKT_WEIGHT, VHOST_NET_WEIGHT,
1328+ NULL);
13281329
13291330 vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, EPOLLOUT, dev);
13301331 vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, EPOLLIN, dev);
drivers/vhost/scsi.c+1−1
@@ -1628,7 +1628,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f) · 1627 unmodified lines
16281628 vs->vqs[i].vq.handle_kick = vhost_scsi_handle_kick;
16291629 }
16301630 vhost_dev_init(&vs->dev, vqs, VHOST_SCSI_MAX_VQ, UIO_MAXIOV,
1631− VHOST_SCSI_WEIGHT, 0);
1631+ VHOST_SCSI_WEIGHT, 0, NULL);
16321632
16331633 vhost_scsi_init_inflight(vs, NULL);
16341634
drivers/vhost/vhost.c+10−2
@@ -457,7 +457,9 @@ static size_t vhost_get_desc_size(struct vhost_virtqueue *vq, · 456 unmodified lines
457457
458458 void vhost_dev_init(struct vhost_dev *dev,
459459 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))
461463 {
462464 struct vhost_virtqueue *vq;
463465 int i;
@@ -473,6 +475,7 @@ void vhost_dev_init(struct vhost_dev *dev, · 9 unmodified lines
473475 dev->iov_limit = iov_limit;
474476 dev->weight = weight;
475477 dev->byte_weight = byte_weight;
478+ dev->msg_handler = msg_handler;
476479 init_llist_head(&dev->work_list);
477480 init_waitqueue_head(&dev->wait);
478481 INIT_LIST_HEAD(&dev->read_list);
@@ -1178,7 +1181,12 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, · 699 unmodified lines
11781181 ret = -EINVAL;
11791182 goto done;
11801183 }
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) {
11821190 ret = -EFAULT;
11831191 goto done;
11841192 }
drivers/vhost/vhost.h+5−1
@@ -174,11 +174,15 @@ struct vhost_dev { · 173 unmodified lines
174174 int weight;
175175 int byte_weight;
176176 u64 kcov_handle;
177+ int (*msg_handler)(struct vhost_dev *dev,
178+ struct vhost_iotlb_msg *msg);
177179 };
178180
179181 bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len);
180182 void vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs,
181− int nvqs, int iov_limit, int weight, int byte_weight);
183+ int nvqs, int iov_limit, int weight, int byte_weight,
184+ int (*msg_handler)(struct vhost_dev *dev,
185+ struct vhost_iotlb_msg *msg));
182186 long vhost_dev_set_owner(struct vhost_dev *dev);
183187 bool vhost_dev_has_owner(struct vhost_dev *dev);
184188 long vhost_dev_check_owner(struct vhost_dev *);
drivers/vhost/vsock.c+1−1
@@ -621,7 +621,7 @@ static int vhost_vsock_dev_open(struct inode *inode, struct file *file) · 620 unmodified lines
621621
622622 vhost_dev_init(&vsock->dev, vqs, ARRAY_SIZE(vsock->vqs),
623623 UIO_MAXIOV, VHOST_VSOCK_PKT_WEIGHT,
624− VHOST_VSOCK_WEIGHT);
624+ VHOST_VSOCK_WEIGHT, NULL);
625625
626626 file->private_data = vsock;
627627 spin_lock_init(&vsock->send_pkt_list_lock);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t