vhost-net fix ubuf
Subsystems (3)
cover vhost-net fix ubuf
Asias He (2):
vhost: Export vhost_dev_set_owner
vhost-net: Free ubuf when vhost_dev_set_owner fails
drivers/vhost/net.c | 38 ++++++++++++++++++++++++++++++++------ drivers/vhost/vhost.c | 2 +- drivers/vhost/vhost.h | 1 + 3 files changed, 34 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/2 vhost: Export vhost_dev_set_owner
Signed-off-by Asias He <[email protected]>
--- drivers/vhost/vhost.c | 2 +- drivers/vhost/vhost.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vhost.c +1 -1
@@ -344,7 +344,7 @@ static int vhost_attach_cgroups(struct vhost_dev *dev) }/* Caller should have device mutex */ -static long vhost_dev_set_owner (struct vhost_dev *dev) +long vhost_dev_set_owner (struct vhost_dev *dev) {struct task_struct *worker;int err;
drivers/vhost/vhost.h +1 -0
@@ -135,6 +135,7 @@ struct vhost_dev { };long vhost_dev_init (struct vhost_dev *,struct vhost_virtqueue **vqs,int nvqs); +long vhost_dev_set_owner (struct vhost_dev *dev);long vhost_dev_check_owner (struct vhost_dev *);struct vhost_memory *vhost_dev_reset_owner_prepare (void );void vhost_dev_reset_owner (struct vhost_dev *,struct vhost_memory *);
Signature · 1 line
1.8.1.4
PATCH 2/2 vhost-net: Free ubuf when vhost_dev_set_owner fails
In reply to Asias HeSigned-off-by Asias He <[email protected]>
--- drivers/vhost/net.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)
drivers/vhost/net.c +32 -6
@@ -146,6 +146,19 @@ void vhost_ubuf_put_and_wait(struct vhost_ubuf_ref *ubufs)kfree (ubufs); } +static void vhost_net_clear_ubuf_info (struct vhost_net *n) +{ + +bool zcopy; +int i; + +for (i =0 ; i < n->dev.nvqs; ++i) { + zcopy = vhost_zcopy_mask & (0x1 << i); +if (zcopy) +kfree (n->vqs[i].ubuf_info); + } +} +int vhost_net_set_ubuf_info (struct vhost_net *n) {bool zcopy;
@@ -1027,6 +1040,23 @@ static int vhost_net_set_features(struct vhost_net *n, u64 features)return 0 ; } +static long vhost_net_set_owner (struct vhost_net *n) +{ +int r; + +mutex_lock (&n->dev.mutex); + r =vhost_net_set_ubuf_info (n); +if (r) + goto out; + r =vhost_dev_set_owner (&n->dev); +if (r) +vhost_net_clear_ubuf_info (n); +vhost_net_flush (n); +out: +mutex_unlock (&n->dev.mutex); +return r; +} +static long vhost_net_ioctl (struct file *f,unsigned int ioctl,unsigned long arg) {
@@ -1055,19 +1085,15 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,return vhost_net_set_features (n, features);case VHOST_RESET_OWNER :return vhost_net_reset_owner (n); +case VHOST_SET_OWNER : +return vhost_net_set_owner (n);default :mutex_lock (&n->dev.mutex); -if (ioctl ==VHOST_SET_OWNER ) { - r =vhost_net_set_ubuf_info (n); -if (r) - goto out; - } r =vhost_dev_ioctl (&n->dev, ioctl, argp);if (r == -ENOIOCTLCMD ) r =vhost_vring_ioctl (&n->dev, ioctl, argp);else vhost_net_flush (n); -out:mutex_unlock (&n->dev.mutex);return r; }
Signature · 1 line
1.8.1.4
PATCH 2/2 vhost-net: Free ubuf when vhost_dev_set_owner fails
In reply to Asias HeSigned-off-by Asias He <[email protected]>
--- drivers/vhost/net.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-)
drivers/vhost/net.c +32 -6
@@ -146,6 +146,19 @@ void vhost_ubuf_put_and_wait(struct vhost_ubuf_ref *ubufs)kfree (ubufs); } +static void vhost_net_clear_ubuf_info (struct vhost_net *n) +{ + +bool zcopy; +int i; + +for (i =0 ; i < n->dev.nvqs; ++i) { + zcopy = vhost_zcopy_mask & (0x1 << i); +if (zcopy) +kfree (n->vqs[i].ubuf_info); + } +} +int vhost_net_set_ubuf_info (struct vhost_net *n) {bool zcopy;
@@ -1027,6 +1040,23 @@ static int vhost_net_set_features(struct vhost_net *n, u64 features)return 0 ; } +static long vhost_net_set_owner (struct vhost_net *n) +{ +int r; + +mutex_lock (&n->dev.mutex); + r =vhost_net_set_ubuf_info (n); +if (r) + goto out; + r =vhost_dev_set_owner (&n->dev); +if (r) +vhost_net_clear_ubuf_info (n); +vhost_net_flush (n); +out: +mutex_unlock (&n->dev.mutex); +return r; +} +static long vhost_net_ioctl (struct file *f,unsigned int ioctl,unsigned long arg) {
@@ -1055,19 +1085,15 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,return vhost_net_set_features (n, features);case VHOST_RESET_OWNER :return vhost_net_reset_owner (n); +case VHOST_SET_OWNER : +return vhost_net_set_owner (n);default :mutex_lock (&n->dev.mutex); -if (ioctl ==VHOST_SET_OWNER ) { - r =vhost_net_set_ubuf_info (n); -if (r) - goto out; - } r =vhost_dev_ioctl (&n->dev, ioctl, argp);if (r == -ENOIOCTLCMD ) r =vhost_vring_ioctl (&n->dev, ioctl, argp);else vhost_net_flush (n); -out:mutex_unlock (&n->dev.mutex);return r; }
Signature · 1 line
1.8.1.4