Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vduse: merge tree search logic of IOTLB_GET_FD and IOTLB_GET_INFO ioctls

The next patch adds new ioctl with the ASID member per entry. Abstract
these two so it can be build on top easily.

Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20260119143306.1818855-11-eperezma@redhat.com>

authored by

Eugenio Pérez and committed by
Michael S. Tsirkin
f3dc3a8a 489d7652

+56 -46
+56 -46
drivers/vdpa/vdpa_user/vduse_dev.c
··· 1243 1243 vq->irq_effective_cpu = curr_cpu; 1244 1244 } 1245 1245 1246 + static int vduse_dev_iotlb_entry(struct vduse_dev *dev, 1247 + struct vduse_iotlb_entry *entry, 1248 + struct file **f, uint64_t *capability) 1249 + { 1250 + int r = -EINVAL; 1251 + struct vhost_iotlb_map *map; 1252 + 1253 + if (entry->start > entry->last) 1254 + return -EINVAL; 1255 + 1256 + mutex_lock(&dev->domain_lock); 1257 + if (!dev->domain) 1258 + goto out; 1259 + 1260 + spin_lock(&dev->domain->iotlb_lock); 1261 + map = vhost_iotlb_itree_first(dev->domain->iotlb, entry->start, 1262 + entry->last); 1263 + if (map) { 1264 + if (f) { 1265 + const struct vdpa_map_file *map_file; 1266 + 1267 + map_file = (struct vdpa_map_file *)map->opaque; 1268 + entry->offset = map_file->offset; 1269 + *f = get_file(map_file->file); 1270 + } 1271 + entry->start = map->start; 1272 + entry->last = map->last; 1273 + entry->perm = map->perm; 1274 + if (capability) { 1275 + *capability = 0; 1276 + 1277 + if (dev->domain->bounce_map && map->start == 0 && 1278 + map->last == dev->domain->bounce_size - 1) 1279 + *capability |= VDUSE_IOVA_CAP_UMEM; 1280 + } 1281 + 1282 + r = 0; 1283 + } 1284 + spin_unlock(&dev->domain->iotlb_lock); 1285 + 1286 + out: 1287 + mutex_unlock(&dev->domain_lock); 1288 + return r; 1289 + } 1290 + 1246 1291 static long vduse_dev_ioctl(struct file *file, unsigned int cmd, 1247 1292 unsigned long arg) 1248 1293 { ··· 1301 1256 switch (cmd) { 1302 1257 case VDUSE_IOTLB_GET_FD: { 1303 1258 struct vduse_iotlb_entry entry; 1304 - struct vhost_iotlb_map *map; 1305 - struct vdpa_map_file *map_file; 1306 1259 struct file *f = NULL; 1307 1260 1308 1261 ret = -EFAULT; 1309 1262 if (copy_from_user(&entry, argp, sizeof(entry))) 1310 1263 break; 1311 1264 1312 - ret = -EINVAL; 1313 - if (entry.start > entry.last) 1265 + ret = vduse_dev_iotlb_entry(dev, &entry, &f, NULL); 1266 + if (ret) 1314 1267 break; 1315 1268 1316 - mutex_lock(&dev->domain_lock); 1317 - if (!dev->domain) { 1318 - mutex_unlock(&dev->domain_lock); 1319 - break; 1320 - } 1321 - spin_lock(&dev->domain->iotlb_lock); 1322 - map = vhost_iotlb_itree_first(dev->domain->iotlb, 1323 - entry.start, entry.last); 1324 - if (map) { 1325 - map_file = (struct vdpa_map_file *)map->opaque; 1326 - f = get_file(map_file->file); 1327 - entry.offset = map_file->offset; 1328 - entry.start = map->start; 1329 - entry.last = map->last; 1330 - entry.perm = map->perm; 1331 - } 1332 - spin_unlock(&dev->domain->iotlb_lock); 1333 - mutex_unlock(&dev->domain_lock); 1334 1269 ret = -EINVAL; 1335 1270 if (!f) 1336 1271 break; ··· 1500 1475 } 1501 1476 case VDUSE_IOTLB_GET_INFO: { 1502 1477 struct vduse_iova_info info; 1503 - struct vhost_iotlb_map *map; 1478 + struct vduse_iotlb_entry entry; 1504 1479 1505 1480 ret = -EFAULT; 1506 1481 if (copy_from_user(&info, argp, sizeof(info))) 1507 - break; 1508 - 1509 - ret = -EINVAL; 1510 - if (info.start > info.last) 1511 1482 break; 1512 1483 1513 1484 if (!is_mem_zero((const char *)info.reserved, 1514 1485 sizeof(info.reserved))) 1515 1486 break; 1516 1487 1517 - mutex_lock(&dev->domain_lock); 1518 - if (!dev->domain) { 1519 - mutex_unlock(&dev->domain_lock); 1488 + entry.start = info.start; 1489 + entry.last = info.last; 1490 + ret = vduse_dev_iotlb_entry(dev, &entry, NULL, 1491 + &info.capability); 1492 + if (ret < 0) 1520 1493 break; 1521 - } 1522 - spin_lock(&dev->domain->iotlb_lock); 1523 - map = vhost_iotlb_itree_first(dev->domain->iotlb, 1524 - info.start, info.last); 1525 - if (map) { 1526 - info.start = map->start; 1527 - info.last = map->last; 1528 - info.capability = 0; 1529 - if (dev->domain->bounce_map && map->start == 0 && 1530 - map->last == dev->domain->bounce_size - 1) 1531 - info.capability |= VDUSE_IOVA_CAP_UMEM; 1532 - } 1533 - spin_unlock(&dev->domain->iotlb_lock); 1534 - mutex_unlock(&dev->domain_lock); 1535 - if (!map) 1536 - break; 1494 + 1495 + info.start = entry.start; 1496 + info.last = entry.last; 1537 1497 1538 1498 ret = -EFAULT; 1539 1499 if (copy_to_user(argp, &info, sizeof(info)))