Skip to content

Commit 776f395

Browse files
Zhu Lingshanmstsirkin
authored andcommitted
vhost_vdpa: Support config interrupt in vdpa
This commit implements config interrupt support in vhost_vdpa layer. Signed-off-by: Zhu Lingshan <[email protected]> Acked-by: Jason Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent bb02e6e commit 776f395

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

drivers/vhost/vdpa.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/nospec.h>
2323
#include <linux/vhost.h>
2424
#include <linux/virtio_net.h>
25+
#include <linux/kernel.h>
2526

2627
#include "vhost.h"
2728

@@ -71,6 +72,7 @@ struct vhost_vdpa {
7172
int nvqs;
7273
int virtio_id;
7374
int minor;
75+
struct eventfd_ctx *config_ctx;
7476
};
7577

7678
static DEFINE_IDA(vhost_vdpa_ida);
@@ -102,6 +104,17 @@ static irqreturn_t vhost_vdpa_virtqueue_cb(void *private)
102104
return IRQ_HANDLED;
103105
}
104106

107+
static irqreturn_t vhost_vdpa_config_cb(void *private)
108+
{
109+
struct vhost_vdpa *v = private;
110+
struct eventfd_ctx *config_ctx = v->config_ctx;
111+
112+
if (config_ctx)
113+
eventfd_signal(config_ctx, 1);
114+
115+
return IRQ_HANDLED;
116+
}
117+
105118
static void vhost_vdpa_reset(struct vhost_vdpa *v)
106119
{
107120
struct vdpa_device *vdpa = v->vdpa;
@@ -289,6 +302,36 @@ static long vhost_vdpa_get_vring_num(struct vhost_vdpa *v, u16 __user *argp)
289302
return 0;
290303
}
291304

305+
static void vhost_vdpa_config_put(struct vhost_vdpa *v)
306+
{
307+
if (v->config_ctx)
308+
eventfd_ctx_put(v->config_ctx);
309+
}
310+
311+
static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)
312+
{
313+
struct vdpa_callback cb;
314+
int fd;
315+
struct eventfd_ctx *ctx;
316+
317+
cb.callback = vhost_vdpa_config_cb;
318+
cb.private = v->vdpa;
319+
if (copy_from_user(&fd, argp, sizeof(fd)))
320+
return -EFAULT;
321+
322+
ctx = fd == VHOST_FILE_UNBIND ? NULL : eventfd_ctx_fdget(fd);
323+
swap(ctx, v->config_ctx);
324+
325+
if (!IS_ERR_OR_NULL(ctx))
326+
eventfd_ctx_put(ctx);
327+
328+
if (IS_ERR(v->config_ctx))
329+
return PTR_ERR(v->config_ctx);
330+
331+
v->vdpa->config->set_config_cb(v->vdpa, &cb);
332+
333+
return 0;
334+
}
292335
static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
293336
void __user *argp)
294337
{
@@ -396,6 +439,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
396439
case VHOST_SET_LOG_FD:
397440
r = -ENOIOCTLCMD;
398441
break;
442+
case VHOST_VDPA_SET_CONFIG_CALL:
443+
r = vhost_vdpa_set_config_call(v, argp);
444+
break;
399445
default:
400446
r = vhost_dev_ioctl(&v->vdev, cmd, argp);
401447
if (r == -ENOIOCTLCMD)
@@ -730,6 +776,7 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep)
730776
vhost_dev_stop(&v->vdev);
731777
vhost_vdpa_iotlb_free(v);
732778
vhost_vdpa_free_domain(v);
779+
vhost_vdpa_config_put(v);
733780
vhost_dev_cleanup(&v->vdev);
734781
kfree(v->vdev.vqs);
735782
mutex_unlock(&d->mutex);

include/uapi/linux/vhost.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/types.h>
1616
#include <linux/ioctl.h>
1717

18+
#define VHOST_FILE_UNBIND -1
19+
1820
/* ioctls */
1921

2022
#define VHOST_VIRTIO 0xAF
@@ -140,4 +142,6 @@
140142
/* Get the max ring size. */
141143
#define VHOST_VDPA_GET_VRING_NUM _IOR(VHOST_VIRTIO, 0x76, __u16)
142144

145+
/* Set event fd for config interrupt*/
146+
#define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int)
143147
#endif

0 commit comments

Comments
 (0)