@@ -191,6 +191,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,
191
191
vq -> log_used = false;
192
192
vq -> log_addr = -1ull ;
193
193
vq -> private_data = NULL ;
194
+ vq -> acked_features = 0 ;
194
195
vq -> log_base = NULL ;
195
196
vq -> error_ctx = NULL ;
196
197
vq -> error = NULL ;
@@ -524,11 +525,13 @@ static int memory_access_ok(struct vhost_dev *d, struct vhost_memory *mem,
524
525
525
526
for (i = 0 ; i < d -> nvqs ; ++ i ) {
526
527
int ok ;
528
+ bool log ;
529
+
527
530
mutex_lock (& d -> vqs [i ]-> mutex );
531
+ log = log_all || vhost_has_feature (d -> vqs [i ], VHOST_F_LOG_ALL );
528
532
/* If ring is inactive, will check when it's enabled. */
529
533
if (d -> vqs [i ]-> private_data )
530
- ok = vq_memory_access_ok (d -> vqs [i ]-> log_base , mem ,
531
- log_all );
534
+ ok = vq_memory_access_ok (d -> vqs [i ]-> log_base , mem , log );
532
535
else
533
536
ok = 1 ;
534
537
mutex_unlock (& d -> vqs [i ]-> mutex );
@@ -538,12 +541,12 @@ static int memory_access_ok(struct vhost_dev *d, struct vhost_memory *mem,
538
541
return 1 ;
539
542
}
540
543
541
- static int vq_access_ok (struct vhost_dev * d , unsigned int num ,
544
+ static int vq_access_ok (struct vhost_virtqueue * vq , unsigned int num ,
542
545
struct vring_desc __user * desc ,
543
546
struct vring_avail __user * avail ,
544
547
struct vring_used __user * used )
545
548
{
546
- size_t s = vhost_has_feature (d , VIRTIO_RING_F_EVENT_IDX ) ? 2 : 0 ;
549
+ size_t s = vhost_has_feature (vq , VIRTIO_RING_F_EVENT_IDX ) ? 2 : 0 ;
547
550
return access_ok (VERIFY_READ , desc , num * sizeof * desc ) &&
548
551
access_ok (VERIFY_READ , avail ,
549
552
sizeof * avail + num * sizeof * avail -> ring + s ) &&
@@ -565,16 +568,16 @@ EXPORT_SYMBOL_GPL(vhost_log_access_ok);
565
568
566
569
/* Verify access for write logging. */
567
570
/* Caller should have vq mutex and device mutex */
568
- static int vq_log_access_ok (struct vhost_dev * d , struct vhost_virtqueue * vq ,
571
+ static int vq_log_access_ok (struct vhost_virtqueue * vq ,
569
572
void __user * log_base )
570
573
{
571
574
struct vhost_memory * mp ;
572
- size_t s = vhost_has_feature (d , VIRTIO_RING_F_EVENT_IDX ) ? 2 : 0 ;
575
+ size_t s = vhost_has_feature (vq , VIRTIO_RING_F_EVENT_IDX ) ? 2 : 0 ;
573
576
574
577
mp = rcu_dereference_protected (vq -> dev -> memory ,
575
578
lockdep_is_held (& vq -> mutex ));
576
579
return vq_memory_access_ok (log_base , mp ,
577
- vhost_has_feature (vq -> dev , VHOST_F_LOG_ALL )) &&
580
+ vhost_has_feature (vq , VHOST_F_LOG_ALL )) &&
578
581
(!vq -> log_used || log_access_ok (log_base , vq -> log_addr ,
579
582
sizeof * vq -> used +
580
583
vq -> num * sizeof * vq -> used -> ring + s ));
@@ -584,8 +587,8 @@ static int vq_log_access_ok(struct vhost_dev *d, struct vhost_virtqueue *vq,
584
587
/* Caller should have vq mutex and device mutex */
585
588
int vhost_vq_access_ok (struct vhost_virtqueue * vq )
586
589
{
587
- return vq_access_ok (vq -> dev , vq -> num , vq -> desc , vq -> avail , vq -> used ) &&
588
- vq_log_access_ok (vq -> dev , vq , vq -> log_base );
590
+ return vq_access_ok (vq , vq -> num , vq -> desc , vq -> avail , vq -> used ) &&
591
+ vq_log_access_ok (vq , vq -> log_base );
589
592
}
590
593
EXPORT_SYMBOL_GPL (vhost_vq_access_ok );
591
594
@@ -612,8 +615,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
612
615
return - EFAULT ;
613
616
}
614
617
615
- if (!memory_access_ok (d , newmem ,
616
- vhost_has_feature (d , VHOST_F_LOG_ALL ))) {
618
+ if (!memory_access_ok (d , newmem , 0 )) {
617
619
kfree (newmem );
618
620
return - EFAULT ;
619
621
}
@@ -726,7 +728,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp)
726
728
* If it is not, we don't as size might not have been setup.
727
729
* We will verify when backend is configured. */
728
730
if (vq -> private_data ) {
729
- if (!vq_access_ok (d , vq -> num ,
731
+ if (!vq_access_ok (vq , vq -> num ,
730
732
(void __user * )(unsigned long )a .desc_user_addr ,
731
733
(void __user * )(unsigned long )a .avail_user_addr ,
732
734
(void __user * )(unsigned long )a .used_user_addr )) {
@@ -866,7 +868,7 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
866
868
vq = d -> vqs [i ];
867
869
mutex_lock (& vq -> mutex );
868
870
/* If ring is inactive, will check when it's enabled. */
869
- if (vq -> private_data && !vq_log_access_ok (d , vq , base ))
871
+ if (vq -> private_data && !vq_log_access_ok (vq , base ))
870
872
r = - EFAULT ;
871
873
else
872
874
vq -> log_base = base ;
@@ -1434,11 +1436,11 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
1434
1436
* interrupts. */
1435
1437
smp_mb ();
1436
1438
1437
- if (vhost_has_feature (dev , VIRTIO_F_NOTIFY_ON_EMPTY ) &&
1439
+ if (vhost_has_feature (vq , VIRTIO_F_NOTIFY_ON_EMPTY ) &&
1438
1440
unlikely (vq -> avail_idx == vq -> last_avail_idx ))
1439
1441
return true;
1440
1442
1441
- if (!vhost_has_feature (dev , VIRTIO_RING_F_EVENT_IDX )) {
1443
+ if (!vhost_has_feature (vq , VIRTIO_RING_F_EVENT_IDX )) {
1442
1444
__u16 flags ;
1443
1445
if (__get_user (flags , & vq -> avail -> flags )) {
1444
1446
vq_err (vq , "Failed to get flags" );
@@ -1499,7 +1501,7 @@ bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
1499
1501
if (!(vq -> used_flags & VRING_USED_F_NO_NOTIFY ))
1500
1502
return false;
1501
1503
vq -> used_flags &= ~VRING_USED_F_NO_NOTIFY ;
1502
- if (!vhost_has_feature (dev , VIRTIO_RING_F_EVENT_IDX )) {
1504
+ if (!vhost_has_feature (vq , VIRTIO_RING_F_EVENT_IDX )) {
1503
1505
r = vhost_update_used_flags (vq );
1504
1506
if (r ) {
1505
1507
vq_err (vq , "Failed to enable notification at %p: %d\n" ,
@@ -1536,7 +1538,7 @@ void vhost_disable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
1536
1538
if (vq -> used_flags & VRING_USED_F_NO_NOTIFY )
1537
1539
return ;
1538
1540
vq -> used_flags |= VRING_USED_F_NO_NOTIFY ;
1539
- if (!vhost_has_feature (dev , VIRTIO_RING_F_EVENT_IDX )) {
1541
+ if (!vhost_has_feature (vq , VIRTIO_RING_F_EVENT_IDX )) {
1540
1542
r = vhost_update_used_flags (vq );
1541
1543
if (r )
1542
1544
vq_err (vq , "Failed to enable notification at %p: %d\n" ,
0 commit comments