Skip to content

Commit ab51225

Browse files
gkurzmstsirkin
authored andcommitted
vhost: Don't call log_access_ok() when using IOTLB
When the IOTLB device is enabled, the log_guest_addr that is passed by userspace to the VHOST_SET_VRING_ADDR ioctl, and which is then written to vq->log_addr, is a GIOVA. All writes to this address are translated by log_user() to writes to an HVA, and then ultimately logged through the corresponding GPAs in log_write_hva(). No logging will ever occur with vq->log_addr in this case. It is thus wrong to pass vq->log_addr and log_guest_addr to log_access_vq() which assumes they are actual GPAs. Introduce a new vq_log_used_access_ok() helper that only checks accesses to the log for the used structure when there isn't an IOTLB device around. Signed-off-by: Greg Kurz <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 71878fa commit ab51225

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/vhost/vhost.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,15 +1370,28 @@ bool vhost_log_access_ok(struct vhost_dev *dev)
13701370
}
13711371
EXPORT_SYMBOL_GPL(vhost_log_access_ok);
13721372

1373+
static bool vq_log_used_access_ok(struct vhost_virtqueue *vq,
1374+
void __user *log_base,
1375+
bool log_used,
1376+
u64 log_addr)
1377+
{
1378+
/* If an IOTLB device is present, log_addr is a GIOVA that
1379+
* will never be logged by log_used(). */
1380+
if (vq->iotlb)
1381+
return true;
1382+
1383+
return !log_used || log_access_ok(log_base, log_addr,
1384+
vhost_get_used_size(vq, vq->num));
1385+
}
1386+
13731387
/* Verify access for write logging. */
13741388
/* Caller should have vq mutex and device mutex */
13751389
static bool vq_log_access_ok(struct vhost_virtqueue *vq,
13761390
void __user *log_base)
13771391
{
13781392
return vq_memory_access_ok(log_base, vq->umem,
13791393
vhost_has_feature(vq, VHOST_F_LOG_ALL)) &&
1380-
(!vq->log_used || log_access_ok(log_base, vq->log_addr,
1381-
vhost_get_used_size(vq, vq->num)));
1394+
vq_log_used_access_ok(vq, log_base, vq->log_used, vq->log_addr);
13821395
}
13831396

13841397
/* Can we start vq? */
@@ -1517,9 +1530,9 @@ static long vhost_vring_set_addr(struct vhost_dev *d,
15171530
return -EINVAL;
15181531

15191532
/* Also validate log access for used ring if enabled. */
1520-
if ((a.flags & (0x1 << VHOST_VRING_F_LOG)) &&
1521-
!log_access_ok(vq->log_base, a.log_guest_addr,
1522-
vhost_get_used_size(vq, vq->num)))
1533+
if (!vq_log_used_access_ok(vq, vq->log_base,
1534+
a.flags & (0x1 << VHOST_VRING_F_LOG),
1535+
a.log_guest_addr))
15231536
return -EINVAL;
15241537
}
15251538

0 commit comments

Comments
 (0)