Skip to contentSkip to conversation

KVM: s390: pci: register pci hooks without interpretation

PATCH In review Matthew Rosato 3 participants 3 messages Sep 20, 2022 – Sep 28, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: s390: pci: register pci hooks without interpretation

The kvm registration hooks must be registered even if the facilities necessary for zPCI interpretation are unavailable, as vfio-pci-zdev will expect to use the hooks regardless.
This fixes an issue where vfio-pci-zdev will fail its open function because of a missing kvm_register when running on hardware that does not support zPCI interpretation.

Fixes ca922fecda6c ("KVM: s390: pci: Hook to access KVM lowlevel from VFIO")
---
 arch/s390/kvm/kvm-s390.c |  4 ++--
 arch/s390/kvm/pci.c      | 14 +++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)
arch/s390/kvm/kvm-s390.c +2 -2
index e20e126944aa..5c7f5f97ea09 100644
@@ -510,7 +510,7 @@ int kvm_arch_init(void *opaque)
 		goto out;
 	}
 
-	if (kvm_s390_pci_interp_allowed()) {
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) {
 		rc = kvm_s390_pci_init();
 		if (rc) {
 			pr_err("Unable to allocate AIFT for PCI\n");
@@ -532,7 +532,7 @@ int kvm_arch_init(void *opaque)
 void kvm_arch_exit(void)
 {
 	kvm_s390_gib_destroy();
-	if (kvm_s390_pci_interp_allowed())
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM))
 		kvm_s390_pci_exit();
 	debug_unregister(kvm_s390_dbf);
 	debug_unregister(kvm_s390_dbf_uv);
arch/s390/kvm/pci.c +11 -3
index 90aaba80696a..c50c1645c0ae 100644
@@ -672,23 +672,31 @@ int kvm_s390_pci_zpci_op(struct kvm *kvm, struct kvm_s390_zpci_op *args)
 
 int kvm_s390_pci_init(void)
 {
+	zpci_kvm_hook.kvm_register = kvm_s390_pci_register_kvm;
+	zpci_kvm_hook.kvm_unregister = kvm_s390_pci_unregister_kvm;
+
+	if (!kvm_s390_pci_interp_allowed())
+		return 0;
+
 	aift = kzalloc(sizeof(struct zpci_aift), GFP_KERNEL);
 	if (!aift)
 		return -ENOMEM;
 
 	spin_lock_init(&aift->gait_lock);
 	mutex_init(&aift->aift_lock);
-	zpci_kvm_hook.kvm_register = kvm_s390_pci_register_kvm;
-	zpci_kvm_hook.kvm_unregister = kvm_s390_pci_unregister_kvm;
 
 	return 0;
 }
 
 void kvm_s390_pci_exit(void)
 {
-	mutex_destroy(&aift->aift_lock);
 	zpci_kvm_hook.kvm_register = NULL;
 	zpci_kvm_hook.kvm_unregister = NULL;
 
+	if (!kvm_s390_pci_interp_allowed())
+		return;
+
+	mutex_destroy(&aift->aift_lock);
+
 	kfree(aift);
 }
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Matthew Rosato

The kvm registration hooks must be registered even if the facilities necessary for zPCI interpretation are unavailable, as vfio-pci-zdev will expect to use the hooks regardless.
This fixes an issue where vfio-pci-zdev will fail its open function because of a missing kvm_register when running on hardware that does not support zPCI interpretation.

Fixes ca922fecda6c ("KVM: s390: pci: Hook to access KVM lowlevel from VFIO")
Quoted 66 lines
---
  arch/s390/kvm/kvm-s390.c |  4 ++--
  arch/s390/kvm/pci.c      | 14 +++++++++++---
  2 files changed, 13 insertions(+), 5 deletions(-)
arch/s390/kvm/kvm-s390.c +2 -2
index e20e126944aa..5c7f5f97ea09 100644
@@ -510,7 +510,7 @@ int kvm_arch_init(void *opaque)
  		goto out;
  	}
 
-	if (kvm_s390_pci_interp_allowed()) {
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) {
  		rc = kvm_s390_pci_init();
  		if (rc) {
  			pr_err("Unable to allocate AIFT for PCI\n");
@@ -532,7 +532,7 @@ int kvm_arch_init(void *opaque)
  void kvm_arch_exit(void)
  {
  	kvm_s390_gib_destroy();
-	if (kvm_s390_pci_interp_allowed())
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM))
  		kvm_s390_pci_exit();
  	debug_unregister(kvm_s390_dbf);
  	debug_unregister(kvm_s390_dbf_uv);
arch/s390/kvm/pci.c +11 -3
index 90aaba80696a..c50c1645c0ae 100644
@@ -672,23 +672,31 @@ int kvm_s390_pci_zpci_op(struct kvm *kvm, struct kvm_s390_zpci_op *args)
 
  int kvm_s390_pci_init(void)
  {
+	zpci_kvm_hook.kvm_register = kvm_s390_pci_register_kvm;
+	zpci_kvm_hook.kvm_unregister = kvm_s390_pci_unregister_kvm;
+
+	if (!kvm_s390_pci_interp_allowed())
+		return 0;
+
  	aift = kzalloc(sizeof(struct zpci_aift), GFP_KERNEL);
  	if (!aift)
  		return -ENOMEM;
 
  	spin_lock_init(&aift->gait_lock);
  	mutex_init(&aift->aift_lock);
-	zpci_kvm_hook.kvm_register = kvm_s390_pci_register_kvm;
-	zpci_kvm_hook.kvm_unregister = kvm_s390_pci_unregister_kvm;
 
  	return 0;
  }
 
  void kvm_s390_pci_exit(void)
  {
-	mutex_destroy(&aift->aift_lock);
  	zpci_kvm_hook.kvm_register = NULL;
  	zpci_kvm_hook.kvm_unregister = NULL;
 
+	if (!kvm_s390_pci_interp_allowed())
+		return;
+
+	mutex_destroy(&aift->aift_lock);
+
  	kfree(aift);
  }
Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Matthew Rosato
Quoted 9 lines · On Tue, 20 Sep 2022 15:30:25 -0400 Matthew Rosato <[email protected]>…

The kvm registration hooks must be registered even if the facilities necessary for zPCI interpretation are unavailable, as vfio-pci-zdev will expect to use the hooks regardless.
This fixes an issue where vfio-pci-zdev will fail its open function because of a missing kvm_register when running on hardware that does not support zPCI interpretation.

Fixes ca922fecda6c ("KVM: s390: pci: Hook to access KVM lowlevel from VFIO")
Quoted 66 lines
---
 arch/s390/kvm/kvm-s390.c |  4 ++--
 arch/s390/kvm/pci.c      | 14 +++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)
arch/s390/kvm/kvm-s390.c +2 -2
index e20e126944aa..5c7f5f97ea09 100644
@@ -510,7 +510,7 @@ int kvm_arch_init(void *opaque)
 		goto out;
 	}
 
-	if (kvm_s390_pci_interp_allowed()) {
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) {
 		rc = kvm_s390_pci_init();
 		if (rc) {
 			pr_err("Unable to allocate AIFT for PCI\n");
@@ -532,7 +532,7 @@ int kvm_arch_init(void *opaque)
 void kvm_arch_exit(void)
 {
 	kvm_s390_gib_destroy();
-	if (kvm_s390_pci_interp_allowed())
+	if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM))
 		kvm_s390_pci_exit();
 	debug_unregister(kvm_s390_dbf);
 	debug_unregister(kvm_s390_dbf_uv);
arch/s390/kvm/pci.c +11 -3
index 90aaba80696a..c50c1645c0ae 100644
@@ -672,23 +672,31 @@ int kvm_s390_pci_zpci_op(struct kvm *kvm, struct kvm_s390_zpci_op *args)
 
 int kvm_s390_pci_init(void)
 {
+	zpci_kvm_hook.kvm_register = kvm_s390_pci_register_kvm;
+	zpci_kvm_hook.kvm_unregister = kvm_s390_pci_unregister_kvm;
+
+	if (!kvm_s390_pci_interp_allowed())
+		return 0;
+
 	aift = kzalloc(sizeof(struct zpci_aift), GFP_KERNEL);
 	if (!aift)
 		return -ENOMEM;
 
 	spin_lock_init(&aift->gait_lock);
 	mutex_init(&aift->aift_lock);
-	zpci_kvm_hook.kvm_register = kvm_s390_pci_register_kvm;
-	zpci_kvm_hook.kvm_unregister = kvm_s390_pci_unregister_kvm;
 
 	return 0;
 }
 
 void kvm_s390_pci_exit(void)
 {
-	mutex_destroy(&aift->aift_lock);
 	zpci_kvm_hook.kvm_register = NULL;
 	zpci_kvm_hook.kvm_unregister = NULL;
 
+	if (!kvm_s390_pci_interp_allowed())
+		return;
+
+	mutex_destroy(&aift->aift_lock);
+
 	kfree(aift);
 }