Skip to content

Commit 64e1c80

Browse files
committed
vhost-net: batch use/unuse mm
Move use/unuse mm to vhost.c which makes it possible to batch these operations. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 533a19b commit 64e1c80

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

‎drivers/vhost/net.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <linux/eventfd.h>
1111
#include <linux/vhost.h>
1212
#include <linux/virtio_net.h>
13-
#include <linux/mmu_context.h>
1413
#include <linux/miscdevice.h>
1514
#include <linux/module.h>
1615
#include <linux/mutex.h>
@@ -142,7 +141,6 @@ static void handle_tx(struct vhost_net *net)
142141
return;
143142
}
144143

145-
use_mm(net->dev.mm);
146144
mutex_lock(&vq->mutex);
147145
vhost_disable_notify(vq);
148146

@@ -207,7 +205,6 @@ static void handle_tx(struct vhost_net *net)
207205
}
208206

209207
mutex_unlock(&vq->mutex);
210-
unuse_mm(net->dev.mm);
211208
}
212209

213210
static int peek_head_len(struct sock *sk)
@@ -312,7 +309,6 @@ static void handle_rx_big(struct vhost_net *net)
312309
if (!sock || skb_queue_empty(&sock->sk->sk_receive_queue))
313310
return;
314311

315-
use_mm(net->dev.mm);
316312
mutex_lock(&vq->mutex);
317313
vhost_disable_notify(vq);
318314
hdr_size = vq->vhost_hlen;
@@ -391,7 +387,6 @@ static void handle_rx_big(struct vhost_net *net)
391387
}
392388

393389
mutex_unlock(&vq->mutex);
394-
unuse_mm(net->dev.mm);
395390
}
396391

397392
/* Expects to be always run from workqueue - which acts as
@@ -423,7 +418,6 @@ static void handle_rx_mergeable(struct vhost_net *net)
423418
if (!sock || skb_queue_empty(&sock->sk->sk_receive_queue))
424419
return;
425420

426-
use_mm(net->dev.mm);
427421
mutex_lock(&vq->mutex);
428422
vhost_disable_notify(vq);
429423
vhost_hlen = vq->vhost_hlen;
@@ -500,7 +494,6 @@ static void handle_rx_mergeable(struct vhost_net *net)
500494
}
501495

502496
mutex_unlock(&vq->mutex);
503-
unuse_mm(net->dev.mm);
504497
}
505498

506499
static void handle_rx(struct vhost_net *net)

‎drivers/vhost/vhost.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/vhost.h>
1616
#include <linux/virtio_net.h>
1717
#include <linux/mm.h>
18+
#include <linux/mmu_context.h>
1819
#include <linux/miscdevice.h>
1920
#include <linux/mutex.h>
2021
#include <linux/rcupdate.h>
@@ -177,6 +178,8 @@ static int vhost_worker(void *data)
177178
struct vhost_work *work = NULL;
178179
unsigned uninitialized_var(seq);
179180

181+
use_mm(dev->mm);
182+
180183
for (;;) {
181184
/* mb paired w/ kthread_stop */
182185
set_current_state(TASK_INTERRUPTIBLE);
@@ -191,7 +194,7 @@ static int vhost_worker(void *data)
191194
if (kthread_should_stop()) {
192195
spin_unlock_irq(&dev->work_lock);
193196
__set_current_state(TASK_RUNNING);
194-
return 0;
197+
break;
195198
}
196199
if (!list_empty(&dev->work_list)) {
197200
work = list_first_entry(&dev->work_list,
@@ -209,6 +212,8 @@ static int vhost_worker(void *data)
209212
schedule();
210213

211214
}
215+
unuse_mm(dev->mm);
216+
return 0;
212217
}
213218

214219
/* Helper to allocate iovec buffers for all vqs. */

0 commit comments

Comments
 (0)