Skip to content

Commit 0210a8d

Browse files
gkurzmstsirkin
authored andcommitted
vhost: Don't call access_ok() when using IOTLB
When the IOTLB device is enabled, the vring addresses we get from userspace are GIOVAs. It is thus wrong to pass them down to access_ok() which only takes HVAs. Access validation is done at prefetch time with IOTLB. Teach vq_access_ok() about that by moving the (vq->iotlb) check from vhost_vq_access_ok() to vq_access_ok(). This prevents vhost_vring_set_addr() to fail when verifying the accesses. No behavior change for vhost_vq_access_ok(). BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1883084 Fixes: 6b1e6cc ("vhost: new device IOTLB API") Cc: jasowang@redhat.com CC: stable@vger.kernel.org # 4.14+ Signed-off-by: Greg Kurz <groug@kaod.org> Acked-by: Jason Wang <jasowang@redhat.com> Link: https://lore.kernel.org/r/160171931213.284610.2052489816407219136.stgit@bahia.lan Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 37787e9 commit 0210a8d

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

drivers/vhost/vhost.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,11 @@ static bool vq_access_ok(struct vhost_virtqueue *vq, unsigned int num,
12901290
vring_used_t __user *used)
12911291

12921292
{
1293+
/* If an IOTLB device is present, the vring addresses are
1294+
* GIOVAs. Access validation occurs at prefetch time. */
1295+
if (vq->iotlb)
1296+
return true;
1297+
12931298
return access_ok(desc, vhost_get_desc_size(vq, num)) &&
12941299
access_ok(avail, vhost_get_avail_size(vq, num)) &&
12951300
access_ok(used, vhost_get_used_size(vq, num));
@@ -1383,10 +1388,6 @@ bool vhost_vq_access_ok(struct vhost_virtqueue *vq)
13831388
if (!vq_log_access_ok(vq, vq->log_base))
13841389
return false;
13851390

1386-
/* Access validation occurs at prefetch time with IOTLB */
1387-
if (vq->iotlb)
1388-
return true;
1389-
13901391
return vq_access_ok(vq, vq->num, vq->desc, vq->avail, vq->used);
13911392
}
13921393
EXPORT_SYMBOL_GPL(vhost_vq_access_ok);

0 commit comments

Comments
 (0)