Skip to contentSkip to conversation

KVM: s390: Fixes for 6.0 take 2

GIT PULL Janosch Frank 2 participants 6 messages Sep 23, 2022

Subsystems (3)
lore
Share & tools
lore

Janosch Frank

author maintainer
#0 lore raw

Paolo,

vfio-pci has kept us busy for a bit so here are three additional pci fixes. Additionally there's a smatch fix by Janis.

It might be a bit late for rc7 but we wanted to have the coverage. Enjoy the weekend!

The following changes since commit 521a547ced6477c54b4b0cc206000406c221b4d6:

Linux 6.0-rc6 (2022-09-18 13:44:14 -0700)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-master-6.0-2

for you to fetch changes up to 189e7d876e48d7c791fe1c9c01516f70f5621a9f:

KVM: s390: pci: register pci hooks without interpretation (2022-09-21 16:18:38 +0200)

----------------------------------------------------------------
More pci fixes
Fix for a code analyser warning
----------------------------------------------------------------

Janis Schoetterl-Glausch (1):
KVM: s390: Pass initialized arg even if unused

Matthew Rosato (3):
KVM: s390: pci: fix plain integer as NULL pointer warnings
KVM: s390: pci: fix GAIT physical vs virtual pointers usage
KVM: s390: pci: register pci hooks without interpretation

 arch/s390/kvm/gaccess.c   | 16 +++++++++++++---
 arch/s390/kvm/interrupt.c |  2 +-
 arch/s390/kvm/kvm-s390.c  |  4 ++--
 arch/s390/kvm/pci.c       | 20 ++++++++++++++------
 arch/s390/kvm/pci.h       |  6 +++---
 5 files changed, 33 insertions(+), 15 deletions(-)
Signature · 1 line
2.37.3
author maintainer
#1 lore raw

[GIT PULL 2/4] KVM: s390: Pass initialized arg even if unused

From: Janis Schoetterl-Glausch <[email protected]>

This silences smatch warnings reported by kbuild bot:
arch/s390/kvm/gaccess.c:859 guest_range_to_gpas() error: uninitialized symbol 'prot'. arch/s390/kvm/gaccess.c:1064 access_guest_with_key() error: uninitialized symbol 'prot'.

This is because it cannot tell that the value is not used in this case. The trans_exc* only examine prot if code is PGM_PROTECTION. Pass a dummy value for other codes.

---
 arch/s390/kvm/gaccess.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
arch/s390/kvm/gaccess.c +13 -3
index 082ec5f2c3a5..0243b6e38d36 100644
@@ -489,6 +489,8 @@ enum prot_type {
 	PROT_TYPE_ALC  = 2,
 	PROT_TYPE_DAT  = 3,
 	PROT_TYPE_IEP  = 4,
+	/* Dummy value for passing an initialized value when code != PGM_PROTECTION */
+	PROT_NONE,
 };
 
 static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva, u8 ar,
@@ -504,6 +506,10 @@ static int trans_exc_ending(struct kvm_vcpu *vcpu, int code, unsigned long gva,
 	switch (code) {
 	case PGM_PROTECTION:
 		switch (prot) {
+		case PROT_NONE:
+			/* We should never get here, acts like termination */
+			WARN_ON_ONCE(1);
+			break;
 		case PROT_TYPE_IEP:
 			tec->b61 = 1;
 			fallthrough;
@@ -968,8 +974,10 @@ static int guest_range_to_gpas(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
 				return rc;
 		} else {
 			gpa = kvm_s390_real_to_abs(vcpu, ga);
-			if (kvm_is_error_gpa(vcpu->kvm, gpa))
+			if (kvm_is_error_gpa(vcpu->kvm, gpa)) {
 				rc = PGM_ADDRESSING;
+				prot = PROT_NONE;
+			}
 		}
 		if (rc)
 			return trans_exc(vcpu, rc, ga, ar, mode, prot);
@@ -1112,8 +1120,6 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
 		if (rc == PGM_PROTECTION && try_storage_prot_override)
 			rc = access_guest_page_with_key(vcpu->kvm, mode, gpas[idx],
 							data, fragment_len, PAGE_SPO_ACC);
-		if (rc == PGM_PROTECTION)
-			prot = PROT_TYPE_KEYC;
 		if (rc)
 			break;
 		len -= fragment_len;
@@ -1123,6 +1129,10 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
 	if (rc > 0) {
 		bool terminate = (mode == GACC_STORE) && (idx > 0);
 
+		if (rc == PGM_PROTECTION)
+			prot = PROT_TYPE_KEYC;
+		else
+			prot = PROT_NONE;
 		rc = trans_exc_ending(vcpu, rc, ga, ar, mode, prot, terminate);
 	}
 out_unlock:
Signature · 1 line
2.37.3
author maintainer
#2 lore raw

[GIT PULL 4/4] KVM: s390: pci: register pci hooks without interpretation

In reply to Janosch Frank

From: 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")

Message-Id: <[email protected]>

---
 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 edfd4bbd0cba..b7ef0b71014d 100644
@@ -505,7 +505,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");
@@ -527,7 +527,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
author maintainer
#3 lore raw

[GIT PULL 3/4] KVM: s390: pci: fix GAIT physical vs virtual pointers usage

In reply to Janosch Frank

From: Matthew Rosato <[email protected]>

The GAIT and all of its entries must be represented by physical addresses as this structure is shared with underlying firmware. We can keep a virtual address of the GAIT origin in order to handle processing in the kernel, but when traversing the entries we must again convert the physical AISB stored in that GAIT entry into a virtual address in order to process it.

Note: this currently doesn't fix a real bug, since virtual addresses are indentical to physical ones.

Message-Id: <[email protected]>

---
 arch/s390/kvm/interrupt.c | 2 +-
 arch/s390/kvm/pci.c       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/interrupt.c +1 -1
index b9c944b262c7..ab569faf0df2 100644
@@ -3324,7 +3324,7 @@ static void aen_host_forward(unsigned long si)
 	if (gaite->count == 0)
 		return;
 	if (gaite->aisb != 0)
-		set_bit_inv(gaite->aisbo, (unsigned long *)gaite->aisb);
+		set_bit_inv(gaite->aisbo, phys_to_virt(gaite->aisb));
 
 	kvm = kvm_s390_pci_si_to_kvm(aift, si);
 	if (!kvm)
arch/s390/kvm/pci.c +1 -1
index 3c12637ce08c..90aaba80696a 100644
@@ -71,7 +71,7 @@ static int zpci_setup_aipb(u8 nisc)
 		rc = -ENOMEM;
 		goto free_sbv;
 	}
-	aift->gait = (struct zpci_gaite *)page_to_phys(page);
+	aift->gait = (struct zpci_gaite *)page_to_virt(page);
 
 	zpci_aipb->aipb.faisb = virt_to_phys(aift->sbv->vector);
 	zpci_aipb->aipb.gait = virt_to_phys(aift->gait);
Signature · 1 line
2.37.3
author maintainer
#4 lore raw

[GIT PULL 1/4] KVM: s390: pci: fix plain integer as NULL pointer warnings

In reply to Janosch Frank

From: Matthew Rosato <[email protected]>

Fix some sparse warnings that a plain integer 0 is being used instead of NULL.

---
 arch/s390/kvm/pci.c | 4 ++--
 arch/s390/kvm/pci.h | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/s390/kvm/pci.c +2 -2
index bb8c335d17b9..3c12637ce08c 100644
@@ -58,7 +58,7 @@ static int zpci_setup_aipb(u8 nisc)
 	if (!zpci_aipb)
 		return -ENOMEM;
 
-	aift->sbv = airq_iv_create(ZPCI_NR_DEVICES, AIRQ_IV_ALLOC, 0);
+	aift->sbv = airq_iv_create(ZPCI_NR_DEVICES, AIRQ_IV_ALLOC, NULL);
 	if (!aift->sbv) {
 		rc = -ENOMEM;
 		goto free_aipb;
@@ -373,7 +373,7 @@ static int kvm_s390_pci_aif_disable(struct zpci_dev *zdev, bool force)
 		gaite->gisc = 0;
 		gaite->aisbo = 0;
 		gaite->gisa = 0;
-		aift->kzdev[zdev->aisb] = 0;
+		aift->kzdev[zdev->aisb] = NULL;
 		/* Clear zdev info */
 		airq_iv_free_bit(aift->sbv, zdev->aisb);
 		airq_iv_release(zdev->aibv);
arch/s390/kvm/pci.h +3 -3
index 3a3606c3a0fe..486d06ef563f 100644
@@ -46,9 +46,9 @@ extern struct zpci_aift *aift;
 static inline struct kvm *kvm_s390_pci_si_to_kvm(struct zpci_aift *aift,
 						 unsigned long si)
 {
-	if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM) || aift->kzdev == 0 ||
-	    aift->kzdev[si] == 0)
-		return 0;
+	if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM) || !aift->kzdev ||
+	    !aift->kzdev[si])
+		return NULL;
 	return aift->kzdev[si]->kvm;
 };
 
Signature · 1 line
2.37.3
maintainer
#5 lore raw
In reply to Janosch Frank
Quoted 6 lines · Janosch Frank

Paolo,

vfio-pci has kept us busy for a bit so here are three additional pci fixes. Additionally there's a smatch fix by Janis.

It might be a bit late for rc7 but we wanted to have the coverage.

They're in today's linux-next even, and everybody was busy with other stuff last week, so it's fine. Pulled, thanks!

Paolo

Quoted 34 lines

Enjoy the weekend!

The following changes since commit 521a547ced6477c54b4b0cc206000406c221b4d6:

   Linux 6.0-rc6 (2022-09-18 13:44:14 -0700)

are available in the Git repository at:

   https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-master-6.0-2

for you to fetch changes up to 189e7d876e48d7c791fe1c9c01516f70f5621a9f:

KVM: s390: pci: register pci hooks without interpretation (2022-09-21 16:18:38 +0200)

----------------------------------------------------------------
More pci fixes
Fix for a code analyser warning
----------------------------------------------------------------

Janis Schoetterl-Glausch (1):
KVM: s390: Pass initialized arg even if unused

Matthew Rosato (3):
KVM: s390: pci: fix plain integer as NULL pointer warnings
KVM: s390: pci: fix GAIT physical vs virtual pointers usage
KVM: s390: pci: register pci hooks without interpretation

  arch/s390/kvm/gaccess.c   | 16 +++++++++++++---
  arch/s390/kvm/interrupt.c |  2 +-
  arch/s390/kvm/kvm-s390.c  |  4 ++--
  arch/s390/kvm/pci.c       | 20 ++++++++++++++------
  arch/s390/kvm/pci.h       |  6 +++---
  5 files changed, 33 insertions(+), 15 deletions(-)