Skip to content

Commit e7545cf

Browse files
vivekkreddykawasaki
authored andcommitted
vfio/pci: Share the core device pointer while invoking feature functions
There is no need to share the main device pointer (struct vfio_device *) with all the feature functions as they only need the core device pointer. Therefore, extract the core device pointer once in the caller (vfio_pci_core_ioctl_feature) and share it instead. Signed-off-by: Vivek Kasireddy <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 65658da commit e7545cf

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

drivers/vfio/pci/vfio_pci_core.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,9 @@ static int vfio_pci_runtime_pm_entry(struct vfio_pci_core_device *vdev,
301301
return 0;
302302
}
303303

304-
static int vfio_pci_core_pm_entry(struct vfio_device *device, u32 flags,
304+
static int vfio_pci_core_pm_entry(struct vfio_pci_core_device *vdev, u32 flags,
305305
void __user *arg, size_t argsz)
306306
{
307-
struct vfio_pci_core_device *vdev =
308-
container_of(device, struct vfio_pci_core_device, vdev);
309307
int ret;
310308

311309
ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, 0);
@@ -322,12 +320,10 @@ static int vfio_pci_core_pm_entry(struct vfio_device *device, u32 flags,
322320
}
323321

324322
static int vfio_pci_core_pm_entry_with_wakeup(
325-
struct vfio_device *device, u32 flags,
323+
struct vfio_pci_core_device *vdev, u32 flags,
326324
struct vfio_device_low_power_entry_with_wakeup __user *arg,
327325
size_t argsz)
328326
{
329-
struct vfio_pci_core_device *vdev =
330-
container_of(device, struct vfio_pci_core_device, vdev);
331327
struct vfio_device_low_power_entry_with_wakeup entry;
332328
struct eventfd_ctx *efdctx;
333329
int ret;
@@ -378,11 +374,9 @@ static void vfio_pci_runtime_pm_exit(struct vfio_pci_core_device *vdev)
378374
up_write(&vdev->memory_lock);
379375
}
380376

381-
static int vfio_pci_core_pm_exit(struct vfio_device *device, u32 flags,
377+
static int vfio_pci_core_pm_exit(struct vfio_pci_core_device *vdev, u32 flags,
382378
void __user *arg, size_t argsz)
383379
{
384-
struct vfio_pci_core_device *vdev =
385-
container_of(device, struct vfio_pci_core_device, vdev);
386380
int ret;
387381

388382
ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, 0);
@@ -1475,11 +1469,10 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
14751469
}
14761470
EXPORT_SYMBOL_GPL(vfio_pci_core_ioctl);
14771471

1478-
static int vfio_pci_core_feature_token(struct vfio_device *device, u32 flags,
1479-
uuid_t __user *arg, size_t argsz)
1472+
static int vfio_pci_core_feature_token(struct vfio_pci_core_device *vdev,
1473+
u32 flags, uuid_t __user *arg,
1474+
size_t argsz)
14801475
{
1481-
struct vfio_pci_core_device *vdev =
1482-
container_of(device, struct vfio_pci_core_device, vdev);
14831476
uuid_t uuid;
14841477
int ret;
14851478

@@ -1506,16 +1499,19 @@ static int vfio_pci_core_feature_token(struct vfio_device *device, u32 flags,
15061499
int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,
15071500
void __user *arg, size_t argsz)
15081501
{
1502+
struct vfio_pci_core_device *vdev =
1503+
container_of(device, struct vfio_pci_core_device, vdev);
1504+
15091505
switch (flags & VFIO_DEVICE_FEATURE_MASK) {
15101506
case VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY:
1511-
return vfio_pci_core_pm_entry(device, flags, arg, argsz);
1507+
return vfio_pci_core_pm_entry(vdev, flags, arg, argsz);
15121508
case VFIO_DEVICE_FEATURE_LOW_POWER_ENTRY_WITH_WAKEUP:
1513-
return vfio_pci_core_pm_entry_with_wakeup(device, flags,
1509+
return vfio_pci_core_pm_entry_with_wakeup(vdev, flags,
15141510
arg, argsz);
15151511
case VFIO_DEVICE_FEATURE_LOW_POWER_EXIT:
1516-
return vfio_pci_core_pm_exit(device, flags, arg, argsz);
1512+
return vfio_pci_core_pm_exit(vdev, flags, arg, argsz);
15171513
case VFIO_DEVICE_FEATURE_PCI_VF_TOKEN:
1518-
return vfio_pci_core_feature_token(device, flags, arg, argsz);
1514+
return vfio_pci_core_feature_token(vdev, flags, arg, argsz);
15191515
default:
15201516
return -ENOTTY;
15211517
}

0 commit comments

Comments
 (0)