Commit 6ac1afbf authored by Asias He's avatar Asias He Committed by Michael S. Tsirkin

vhost: Make vhost a separate module

Currently, vhost-net and vhost-scsi are sharing the vhost core code.
However, vhost-scsi shares the code by including the vhost.c file
directly.

Making vhost a separate module makes it is easier to share code with
other vhost devices.
Signed-off-by: default avatarAsias He <asias@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 3c63f66a
config VHOST_NET config VHOST_NET
tristate "Host kernel accelerator for virtio net" tristate "Host kernel accelerator for virtio net"
depends on NET && EVENTFD && (TUN || !TUN) && (MACVTAP || !MACVTAP) depends on NET && EVENTFD && (TUN || !TUN) && (MACVTAP || !MACVTAP)
select VHOST
select VHOST_RING select VHOST_RING
---help--- ---help---
This kernel module can be loaded in host kernel to accelerate This kernel module can be loaded in host kernel to accelerate
...@@ -13,6 +14,7 @@ config VHOST_NET ...@@ -13,6 +14,7 @@ config VHOST_NET
config VHOST_SCSI config VHOST_SCSI
tristate "VHOST_SCSI TCM fabric driver" tristate "VHOST_SCSI TCM fabric driver"
depends on TARGET_CORE && EVENTFD && m depends on TARGET_CORE && EVENTFD && m
select VHOST
select VHOST_RING select VHOST_RING
default n default n
---help--- ---help---
...@@ -24,3 +26,9 @@ config VHOST_RING ...@@ -24,3 +26,9 @@ config VHOST_RING
---help--- ---help---
This option is selected by any driver which needs to access This option is selected by any driver which needs to access
the host side of a virtio ring. the host side of a virtio ring.
config VHOST
tristate
---help---
This option is selected by any driver which needs to access
the core of vhost.
obj-$(CONFIG_VHOST_NET) += vhost_net.o obj-$(CONFIG_VHOST_NET) += vhost_net.o
vhost_net-y := vhost.o net.o vhost_net-y := net.o
obj-$(CONFIG_VHOST_SCSI) += vhost_scsi.o obj-$(CONFIG_VHOST_SCSI) += vhost_scsi.o
vhost_scsi-y := scsi.o vhost_scsi-y := scsi.o
obj-$(CONFIG_VHOST_RING) += vringh.o obj-$(CONFIG_VHOST_RING) += vringh.o
obj-$(CONFIG_VHOST) += vhost.o
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
#include <linux/llist.h> #include <linux/llist.h>
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include "vhost.c"
#include "vhost.h" #include "vhost.h"
#define TCM_VHOST_VERSION "v0.1" #define TCM_VHOST_VERSION "v0.1"
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include "test.h" #include "test.h"
#include "vhost.c" #include "vhost.h"
/* Max number of bytes transferred before requeueing the job. /* Max number of bytes transferred before requeueing the job.
* Using this limit prevents one virtqueue from starving others. */ * Using this limit prevents one virtqueue from starving others. */
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/kthread.h> #include <linux/kthread.h>
#include <linux/cgroup.h> #include <linux/cgroup.h>
#include <linux/module.h>
#include "vhost.h" #include "vhost.h"
...@@ -66,6 +67,7 @@ void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn) ...@@ -66,6 +67,7 @@ void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn)
work->flushing = 0; work->flushing = 0;
work->queue_seq = work->done_seq = 0; work->queue_seq = work->done_seq = 0;
} }
EXPORT_SYMBOL_GPL(vhost_work_init);
/* Init poll structure */ /* Init poll structure */
void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn, void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
...@@ -79,6 +81,7 @@ void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn, ...@@ -79,6 +81,7 @@ void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
vhost_work_init(&poll->work, fn); vhost_work_init(&poll->work, fn);
} }
EXPORT_SYMBOL_GPL(vhost_poll_init);
/* Start polling a file. We add ourselves to file's wait queue. The caller must /* Start polling a file. We add ourselves to file's wait queue. The caller must
* keep a reference to a file until after vhost_poll_stop is called. */ * keep a reference to a file until after vhost_poll_stop is called. */
...@@ -101,6 +104,7 @@ int vhost_poll_start(struct vhost_poll *poll, struct file *file) ...@@ -101,6 +104,7 @@ int vhost_poll_start(struct vhost_poll *poll, struct file *file)
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(vhost_poll_start);
/* Stop polling a file. After this function returns, it becomes safe to drop the /* Stop polling a file. After this function returns, it becomes safe to drop the
* file reference. You must also flush afterwards. */ * file reference. You must also flush afterwards. */
...@@ -111,6 +115,7 @@ void vhost_poll_stop(struct vhost_poll *poll) ...@@ -111,6 +115,7 @@ void vhost_poll_stop(struct vhost_poll *poll)
poll->wqh = NULL; poll->wqh = NULL;
} }
} }
EXPORT_SYMBOL_GPL(vhost_poll_stop);
static bool vhost_work_seq_done(struct vhost_dev *dev, struct vhost_work *work, static bool vhost_work_seq_done(struct vhost_dev *dev, struct vhost_work *work,
unsigned seq) unsigned seq)
...@@ -123,7 +128,7 @@ static bool vhost_work_seq_done(struct vhost_dev *dev, struct vhost_work *work, ...@@ -123,7 +128,7 @@ static bool vhost_work_seq_done(struct vhost_dev *dev, struct vhost_work *work,
return left <= 0; return left <= 0;
} }
static void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work) void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work)
{ {
unsigned seq; unsigned seq;
int flushing; int flushing;
...@@ -138,6 +143,7 @@ static void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work) ...@@ -138,6 +143,7 @@ static void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work)
spin_unlock_irq(&dev->work_lock); spin_unlock_irq(&dev->work_lock);
BUG_ON(flushing < 0); BUG_ON(flushing < 0);
} }
EXPORT_SYMBOL_GPL(vhost_work_flush);
/* Flush any work that has been scheduled. When calling this, don't hold any /* Flush any work that has been scheduled. When calling this, don't hold any
* locks that are also used by the callback. */ * locks that are also used by the callback. */
...@@ -145,6 +151,7 @@ void vhost_poll_flush(struct vhost_poll *poll) ...@@ -145,6 +151,7 @@ void vhost_poll_flush(struct vhost_poll *poll)
{ {
vhost_work_flush(poll->dev, &poll->work); vhost_work_flush(poll->dev, &poll->work);
} }
EXPORT_SYMBOL_GPL(vhost_poll_flush);
void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work) void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
{ {
...@@ -158,11 +165,13 @@ void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work) ...@@ -158,11 +165,13 @@ void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
} }
spin_unlock_irqrestore(&dev->work_lock, flags); spin_unlock_irqrestore(&dev->work_lock, flags);
} }
EXPORT_SYMBOL_GPL(vhost_work_queue);
void vhost_poll_queue(struct vhost_poll *poll) void vhost_poll_queue(struct vhost_poll *poll)
{ {
vhost_work_queue(poll->dev, &poll->work); vhost_work_queue(poll->dev, &poll->work);
} }
EXPORT_SYMBOL_GPL(vhost_poll_queue);
static void vhost_vq_reset(struct vhost_dev *dev, static void vhost_vq_reset(struct vhost_dev *dev,
struct vhost_virtqueue *vq) struct vhost_virtqueue *vq)
...@@ -311,6 +320,7 @@ long vhost_dev_init(struct vhost_dev *dev, ...@@ -311,6 +320,7 @@ long vhost_dev_init(struct vhost_dev *dev,
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(vhost_dev_init);
/* Caller should have device mutex */ /* Caller should have device mutex */
long vhost_dev_check_owner(struct vhost_dev *dev) long vhost_dev_check_owner(struct vhost_dev *dev)
...@@ -318,6 +328,7 @@ long vhost_dev_check_owner(struct vhost_dev *dev) ...@@ -318,6 +328,7 @@ long vhost_dev_check_owner(struct vhost_dev *dev)
/* Are you the owner? If not, I don't think you mean to do that */ /* Are you the owner? If not, I don't think you mean to do that */
return dev->mm == current->mm ? 0 : -EPERM; return dev->mm == current->mm ? 0 : -EPERM;
} }
EXPORT_SYMBOL_GPL(vhost_dev_check_owner);
struct vhost_attach_cgroups_struct { struct vhost_attach_cgroups_struct {
struct vhost_work work; struct vhost_work work;
...@@ -349,6 +360,7 @@ bool vhost_dev_has_owner(struct vhost_dev *dev) ...@@ -349,6 +360,7 @@ bool vhost_dev_has_owner(struct vhost_dev *dev)
{ {
return dev->mm; return dev->mm;
} }
EXPORT_SYMBOL_GPL(vhost_dev_has_owner);
/* Caller should have device mutex */ /* Caller should have device mutex */
long vhost_dev_set_owner(struct vhost_dev *dev) long vhost_dev_set_owner(struct vhost_dev *dev)
...@@ -392,11 +404,13 @@ long vhost_dev_set_owner(struct vhost_dev *dev) ...@@ -392,11 +404,13 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
err_mm: err_mm:
return err; return err;
} }
EXPORT_SYMBOL_GPL(vhost_dev_set_owner);
struct vhost_memory *vhost_dev_reset_owner_prepare(void) struct vhost_memory *vhost_dev_reset_owner_prepare(void)
{ {
return kmalloc(offsetof(struct vhost_memory, regions), GFP_KERNEL); return kmalloc(offsetof(struct vhost_memory, regions), GFP_KERNEL);
} }
EXPORT_SYMBOL_GPL(vhost_dev_reset_owner_prepare);
/* Caller should have device mutex */ /* Caller should have device mutex */
void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_memory *memory) void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_memory *memory)
...@@ -407,6 +421,7 @@ void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_memory *memory) ...@@ -407,6 +421,7 @@ void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_memory *memory)
memory->nregions = 0; memory->nregions = 0;
RCU_INIT_POINTER(dev->memory, memory); RCU_INIT_POINTER(dev->memory, memory);
} }
EXPORT_SYMBOL_GPL(vhost_dev_reset_owner);
void vhost_dev_stop(struct vhost_dev *dev) void vhost_dev_stop(struct vhost_dev *dev)
{ {
...@@ -419,6 +434,7 @@ void vhost_dev_stop(struct vhost_dev *dev) ...@@ -419,6 +434,7 @@ void vhost_dev_stop(struct vhost_dev *dev)
} }
} }
} }
EXPORT_SYMBOL_GPL(vhost_dev_stop);
/* Caller should have device mutex if and only if locked is set */ /* Caller should have device mutex if and only if locked is set */
void vhost_dev_cleanup(struct vhost_dev *dev, bool locked) void vhost_dev_cleanup(struct vhost_dev *dev, bool locked)
...@@ -459,6 +475,7 @@ void vhost_dev_cleanup(struct vhost_dev *dev, bool locked) ...@@ -459,6 +475,7 @@ void vhost_dev_cleanup(struct vhost_dev *dev, bool locked)
mmput(dev->mm); mmput(dev->mm);
dev->mm = NULL; dev->mm = NULL;
} }
EXPORT_SYMBOL_GPL(vhost_dev_cleanup);
static int log_access_ok(void __user *log_base, u64 addr, unsigned long sz) static int log_access_ok(void __user *log_base, u64 addr, unsigned long sz)
{ {
...@@ -544,6 +561,7 @@ int vhost_log_access_ok(struct vhost_dev *dev) ...@@ -544,6 +561,7 @@ int vhost_log_access_ok(struct vhost_dev *dev)
lockdep_is_held(&dev->mutex)); lockdep_is_held(&dev->mutex));
return memory_access_ok(dev, mp, 1); return memory_access_ok(dev, mp, 1);
} }
EXPORT_SYMBOL_GPL(vhost_log_access_ok);
/* Verify access for write logging. */ /* Verify access for write logging. */
/* Caller should have vq mutex and device mutex */ /* Caller should have vq mutex and device mutex */
...@@ -569,6 +587,7 @@ int vhost_vq_access_ok(struct vhost_virtqueue *vq) ...@@ -569,6 +587,7 @@ int vhost_vq_access_ok(struct vhost_virtqueue *vq)
return vq_access_ok(vq->dev, vq->num, vq->desc, vq->avail, vq->used) && return vq_access_ok(vq->dev, vq->num, vq->desc, vq->avail, vq->used) &&
vq_log_access_ok(vq->dev, vq, vq->log_base); vq_log_access_ok(vq->dev, vq, vq->log_base);
} }
EXPORT_SYMBOL_GPL(vhost_vq_access_ok);
static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
{ {
...@@ -798,6 +817,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp) ...@@ -798,6 +817,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp)
vhost_poll_flush(&vq->poll); vhost_poll_flush(&vq->poll);
return r; return r;
} }
EXPORT_SYMBOL_GPL(vhost_vring_ioctl);
/* Caller must have device mutex */ /* Caller must have device mutex */
long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
...@@ -878,6 +898,7 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) ...@@ -878,6 +898,7 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
done: done:
return r; return r;
} }
EXPORT_SYMBOL_GPL(vhost_dev_ioctl);
static const struct vhost_memory_region *find_region(struct vhost_memory *mem, static const struct vhost_memory_region *find_region(struct vhost_memory *mem,
__u64 addr, __u32 len) __u64 addr, __u32 len)
...@@ -969,6 +990,7 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, ...@@ -969,6 +990,7 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
BUG(); BUG();
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(vhost_log_write);
static int vhost_update_used_flags(struct vhost_virtqueue *vq) static int vhost_update_used_flags(struct vhost_virtqueue *vq)
{ {
...@@ -1020,6 +1042,7 @@ int vhost_init_used(struct vhost_virtqueue *vq) ...@@ -1020,6 +1042,7 @@ int vhost_init_used(struct vhost_virtqueue *vq)
vq->signalled_used_valid = false; vq->signalled_used_valid = false;
return get_user(vq->last_used_idx, &vq->used->idx); return get_user(vq->last_used_idx, &vq->used->idx);
} }
EXPORT_SYMBOL_GPL(vhost_init_used);
static int translate_desc(struct vhost_dev *dev, u64 addr, u32 len, static int translate_desc(struct vhost_dev *dev, u64 addr, u32 len,
struct iovec iov[], int iov_size) struct iovec iov[], int iov_size)
...@@ -1296,12 +1319,14 @@ int vhost_get_vq_desc(struct vhost_dev *dev, struct vhost_virtqueue *vq, ...@@ -1296,12 +1319,14 @@ int vhost_get_vq_desc(struct vhost_dev *dev, struct vhost_virtqueue *vq,
BUG_ON(!(vq->used_flags & VRING_USED_F_NO_NOTIFY)); BUG_ON(!(vq->used_flags & VRING_USED_F_NO_NOTIFY));
return head; return head;
} }
EXPORT_SYMBOL_GPL(vhost_get_vq_desc);
/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ /* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */
void vhost_discard_vq_desc(struct vhost_virtqueue *vq, int n) void vhost_discard_vq_desc(struct vhost_virtqueue *vq, int n)
{ {
vq->last_avail_idx -= n; vq->last_avail_idx -= n;
} }
EXPORT_SYMBOL_GPL(vhost_discard_vq_desc);
/* After we've used one of their buffers, we tell them about it. We'll then /* After we've used one of their buffers, we tell them about it. We'll then
* want to notify the guest, using eventfd. */ * want to notify the guest, using eventfd. */
...@@ -1350,6 +1375,7 @@ int vhost_add_used(struct vhost_virtqueue *vq, unsigned int head, int len) ...@@ -1350,6 +1375,7 @@ int vhost_add_used(struct vhost_virtqueue *vq, unsigned int head, int len)
vq->signalled_used_valid = false; vq->signalled_used_valid = false;
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(vhost_add_used);
static int __vhost_add_used_n(struct vhost_virtqueue *vq, static int __vhost_add_used_n(struct vhost_virtqueue *vq,
struct vring_used_elem *heads, struct vring_used_elem *heads,
...@@ -1419,6 +1445,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads, ...@@ -1419,6 +1445,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
} }
return r; return r;
} }
EXPORT_SYMBOL_GPL(vhost_add_used_n);
static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq) static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
{ {
...@@ -1463,6 +1490,7 @@ void vhost_signal(struct vhost_dev *dev, struct vhost_virtqueue *vq) ...@@ -1463,6 +1490,7 @@ void vhost_signal(struct vhost_dev *dev, struct vhost_virtqueue *vq)
if (vq->call_ctx && vhost_notify(dev, vq)) if (vq->call_ctx && vhost_notify(dev, vq))
eventfd_signal(vq->call_ctx, 1); eventfd_signal(vq->call_ctx, 1);
} }
EXPORT_SYMBOL_GPL(vhost_signal);
/* And here's the combo meal deal. Supersize me! */ /* And here's the combo meal deal. Supersize me! */
void vhost_add_used_and_signal(struct vhost_dev *dev, void vhost_add_used_and_signal(struct vhost_dev *dev,
...@@ -1472,6 +1500,7 @@ void vhost_add_used_and_signal(struct vhost_dev *dev, ...@@ -1472,6 +1500,7 @@ void vhost_add_used_and_signal(struct vhost_dev *dev,
vhost_add_used(vq, head, len); vhost_add_used(vq, head, len);
vhost_signal(dev, vq); vhost_signal(dev, vq);
} }
EXPORT_SYMBOL_GPL(vhost_add_used_and_signal);
/* multi-buffer version of vhost_add_used_and_signal */ /* multi-buffer version of vhost_add_used_and_signal */
void vhost_add_used_and_signal_n(struct vhost_dev *dev, void vhost_add_used_and_signal_n(struct vhost_dev *dev,
...@@ -1481,6 +1510,7 @@ void vhost_add_used_and_signal_n(struct vhost_dev *dev, ...@@ -1481,6 +1510,7 @@ void vhost_add_used_and_signal_n(struct vhost_dev *dev,
vhost_add_used_n(vq, heads, count); vhost_add_used_n(vq, heads, count);
vhost_signal(dev, vq); vhost_signal(dev, vq);
} }
EXPORT_SYMBOL_GPL(vhost_add_used_and_signal_n);
/* OK, now we need to know about added descriptors. */ /* OK, now we need to know about added descriptors. */
bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq) bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
...@@ -1518,6 +1548,7 @@ bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq) ...@@ -1518,6 +1548,7 @@ bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
return avail_idx != vq->avail_idx; return avail_idx != vq->avail_idx;
} }
EXPORT_SYMBOL_GPL(vhost_enable_notify);
/* We don't need to be notified again. */ /* We don't need to be notified again. */
void vhost_disable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq) void vhost_disable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
...@@ -1534,3 +1565,21 @@ void vhost_disable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq) ...@@ -1534,3 +1565,21 @@ void vhost_disable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
&vq->used->flags, r); &vq->used->flags, r);
} }
} }
EXPORT_SYMBOL_GPL(vhost_disable_notify);
static int __init vhost_init(void)
{
return 0;
}
static void __exit vhost_exit(void)
{
}
module_init(vhost_init);
module_exit(vhost_exit);
MODULE_VERSION("0.0.1");
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Michael S. Tsirkin");
MODULE_DESCRIPTION("Host kernel accelerator for virtio");
...@@ -46,6 +46,8 @@ int vhost_poll_start(struct vhost_poll *poll, struct file *file); ...@@ -46,6 +46,8 @@ int vhost_poll_start(struct vhost_poll *poll, struct file *file);
void vhost_poll_stop(struct vhost_poll *poll); void vhost_poll_stop(struct vhost_poll *poll);
void vhost_poll_flush(struct vhost_poll *poll); void vhost_poll_flush(struct vhost_poll *poll);
void vhost_poll_queue(struct vhost_poll *poll); void vhost_poll_queue(struct vhost_poll *poll);
void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work);
long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp);
struct vhost_log { struct vhost_log {
u64 addr; u64 addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment