Skip to content

Commit ca922fe

Browse files
Pierre Morelfrankjaa
authored andcommitted
KVM: s390: pci: Hook to access KVM lowlevel from VFIO
We have a cross dependency between KVM and VFIO when using s390 vfio_pci_zdev extensions for PCI passthrough To be able to keep both subsystem modular we add a registering hook inside the S390 core code. This fixes a build problem when VFIO is built-in and KVM is built as a module. Reported-by: Randy Dunlap <rdunlap@infradead.org> Reported-by: kernel test robot <lkp@intel.com> Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Pierre Morel <pmorel@linux.ibm.com> Fixes: 09340b2 ("KVM: s390: pci: add routines to start/stop interpretive execution") Cc: <stable@vger.kernel.org> Acked-by: Janosch Frank <frankja@linux.ibm.com> Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested Link: https://lore.kernel.org/r/20220819122945.9309-1-pmorel@linux.ibm.com Message-Id: <20220819122945.9309-1-pmorel@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
1 parent b90cb10 commit ca922fe

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

arch/s390/include/asm/kvm_host.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,16 +1038,11 @@ static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
10381038
#define __KVM_HAVE_ARCH_VM_FREE
10391039
void kvm_arch_free_vm(struct kvm *kvm);
10401040

1041-
#ifdef CONFIG_VFIO_PCI_ZDEV_KVM
1042-
int kvm_s390_pci_register_kvm(struct zpci_dev *zdev, struct kvm *kvm);
1043-
void kvm_s390_pci_unregister_kvm(struct zpci_dev *zdev);
1044-
#else
1045-
static inline int kvm_s390_pci_register_kvm(struct zpci_dev *dev,
1046-
struct kvm *kvm)
1047-
{
1048-
return -EPERM;
1049-
}
1050-
static inline void kvm_s390_pci_unregister_kvm(struct zpci_dev *dev) {}
1051-
#endif
1041+
struct zpci_kvm_hook {
1042+
int (*kvm_register)(void *opaque, struct kvm *kvm);
1043+
void (*kvm_unregister)(void *opaque);
1044+
};
1045+
1046+
extern struct zpci_kvm_hook zpci_kvm_hook;
10521047

10531048
#endif

arch/s390/kvm/pci.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,9 @@ static void kvm_s390_pci_dev_release(struct zpci_dev *zdev)
431431
* available, enable them and let userspace indicate whether or not they will
432432
* be used (specify SHM bit to disable).
433433
*/
434-
int kvm_s390_pci_register_kvm(struct zpci_dev *zdev, struct kvm *kvm)
434+
static int kvm_s390_pci_register_kvm(void *opaque, struct kvm *kvm)
435435
{
436+
struct zpci_dev *zdev = opaque;
436437
int rc;
437438

438439
if (!zdev)
@@ -510,10 +511,10 @@ int kvm_s390_pci_register_kvm(struct zpci_dev *zdev, struct kvm *kvm)
510511
kvm_put_kvm(kvm);
511512
return rc;
512513
}
513-
EXPORT_SYMBOL_GPL(kvm_s390_pci_register_kvm);
514514

515-
void kvm_s390_pci_unregister_kvm(struct zpci_dev *zdev)
515+
static void kvm_s390_pci_unregister_kvm(void *opaque)
516516
{
517+
struct zpci_dev *zdev = opaque;
517518
struct kvm *kvm;
518519

519520
if (!zdev)
@@ -566,7 +567,6 @@ void kvm_s390_pci_unregister_kvm(struct zpci_dev *zdev)
566567

567568
kvm_put_kvm(kvm);
568569
}
569-
EXPORT_SYMBOL_GPL(kvm_s390_pci_unregister_kvm);
570570

571571
void kvm_s390_pci_init_list(struct kvm *kvm)
572572
{
@@ -678,13 +678,17 @@ int kvm_s390_pci_init(void)
678678

679679
spin_lock_init(&aift->gait_lock);
680680
mutex_init(&aift->aift_lock);
681+
zpci_kvm_hook.kvm_register = kvm_s390_pci_register_kvm;
682+
zpci_kvm_hook.kvm_unregister = kvm_s390_pci_unregister_kvm;
681683

682684
return 0;
683685
}
684686

685687
void kvm_s390_pci_exit(void)
686688
{
687689
mutex_destroy(&aift->aift_lock);
690+
zpci_kvm_hook.kvm_register = NULL;
691+
zpci_kvm_hook.kvm_unregister = NULL;
688692

689693
kfree(aift);
690694
}

arch/s390/pci/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
obj-$(CONFIG_PCI) += pci.o pci_irq.o pci_dma.o pci_clp.o pci_sysfs.o \
77
pci_event.o pci_debug.o pci_insn.o pci_mmio.o \
8-
pci_bus.o
8+
pci_bus.o pci_kvm_hook.o
99
obj-$(CONFIG_PCI_IOV) += pci_iov.o

arch/s390/pci/pci_kvm_hook.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* VFIO ZPCI devices support
4+
*
5+
* Copyright (C) IBM Corp. 2022. All rights reserved.
6+
* Author(s): Pierre Morel <pmorel@linux.ibm.com>
7+
*/
8+
#include <linux/kvm_host.h>
9+
10+
struct zpci_kvm_hook zpci_kvm_hook;
11+
EXPORT_SYMBOL_GPL(zpci_kvm_hook);

drivers/vfio/pci/vfio_pci_zdev.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev)
151151
if (!vdev->vdev.kvm)
152152
return 0;
153153

154-
return kvm_s390_pci_register_kvm(zdev, vdev->vdev.kvm);
154+
if (zpci_kvm_hook.kvm_register)
155+
return zpci_kvm_hook.kvm_register(zdev, vdev->vdev.kvm);
156+
157+
return -ENOENT;
155158
}
156159

157160
void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev)
@@ -161,5 +164,6 @@ void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev)
161164
if (!zdev || !vdev->vdev.kvm)
162165
return;
163166

164-
kvm_s390_pci_unregister_kvm(zdev);
167+
if (zpci_kvm_hook.kvm_unregister)
168+
zpci_kvm_hook.kvm_unregister(zdev);
165169
}

0 commit comments

Comments
 (0)