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

vfio-pci/zdev: add open/close device hooks

During vfio-pci open_device, pass the KVM associated with the vfio group
(if one exists). This is needed in order to pass a special indicator
(GISA) to firmware to allow zPCI interpretation facilities to be used
for only the specific KVM associated with the vfio-pci device. During
vfio-pci close_device, unregister the notifier.

Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Acked-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Pierre Morel <pmorel@linux.ibm.com>
Link: https://lore.kernel.org/r/20220606203325.110625-18-mjrosato@linux.ibm.com
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>

authored by

Matthew Rosato and committed by
Christian Borntraeger
8061d1c3 09340b2f

+43 -1
+9 -1
drivers/vfio/pci/vfio_pci_core.c
··· 316 316 pci_write_config_word(pdev, PCI_COMMAND, cmd); 317 317 } 318 318 319 - ret = vfio_config_init(vdev); 319 + ret = vfio_pci_zdev_open_device(vdev); 320 320 if (ret) 321 321 goto out_free_state; 322 + 323 + ret = vfio_config_init(vdev); 324 + if (ret) 325 + goto out_free_zdev; 322 326 323 327 msix_pos = pdev->msix_cap; 324 328 if (msix_pos) { ··· 344 340 345 341 return 0; 346 342 343 + out_free_zdev: 344 + vfio_pci_zdev_close_device(vdev); 347 345 out_free_state: 348 346 kfree(vdev->pci_saved_state); 349 347 vdev->pci_saved_state = NULL; ··· 423 417 } 424 418 425 419 vdev->needs_reset = true; 420 + 421 + vfio_pci_zdev_close_device(vdev); 426 422 427 423 /* 428 424 * If we have saved state, restore it. If we can reset the device,
+24
drivers/vfio/pci/vfio_pci_zdev.c
··· 11 11 #include <linux/uaccess.h> 12 12 #include <linux/vfio.h> 13 13 #include <linux/vfio_zdev.h> 14 + #include <linux/kvm_host.h> 14 15 #include <asm/pci_clp.h> 15 16 #include <asm/pci_io.h> 16 17 ··· 136 135 ret = zpci_pfip_cap(zdev, caps); 137 136 138 137 return ret; 138 + } 139 + 140 + int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev) 141 + { 142 + struct zpci_dev *zdev = to_zpci(vdev->pdev); 143 + 144 + if (!zdev) 145 + return -ENODEV; 146 + 147 + if (!vdev->vdev.kvm) 148 + return 0; 149 + 150 + return kvm_s390_pci_register_kvm(zdev, vdev->vdev.kvm); 151 + } 152 + 153 + void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev) 154 + { 155 + struct zpci_dev *zdev = to_zpci(vdev->pdev); 156 + 157 + if (!zdev || !vdev->vdev.kvm) 158 + return; 159 + 160 + kvm_s390_pci_unregister_kvm(zdev); 139 161 }
+10
include/linux/vfio_pci_core.h
··· 209 209 #ifdef CONFIG_VFIO_PCI_ZDEV_KVM 210 210 extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 211 211 struct vfio_info_cap *caps); 212 + int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev); 213 + void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev); 212 214 #else 213 215 static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 214 216 struct vfio_info_cap *caps) 215 217 { 216 218 return -ENODEV; 217 219 } 220 + 221 + static inline int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev) 222 + { 223 + return 0; 224 + } 225 + 226 + static inline void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev) 227 + {} 218 228 #endif 219 229 220 230 /* Will be exported for vfio pci drivers usage */