Skip to contentSkip to conversation

s390: vfio-ap: trace the update of APCB masks

PATCH In review Pierre Morel 5 participants 16 messages Oct 5, 2018

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

PATCH 1/1 s390: vfio-ap: trace the update of APCB masks

Define a tracing function to trace in the KVM trace buffer and trace the changes of the APCB masks.

---
 drivers/s390/crypto/vfio_ap_ops.c     | 22 ++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_private.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/s390/crypto/vfio_ap_ops.c +22 -0
index a8a9984..00e632a 100644
@@ -753,6 +753,28 @@ static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev)
 	memcpy(aqm, matrix_mdev->matrix.aqm, nbytes);
 	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.adm_max + 1, BITS_PER_BYTE);
 	memcpy(adm, matrix_mdev->matrix.adm, nbytes);
+
+	switch (matrix_mdev->kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) {
+	case CRYCB_FORMAT2:
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: apm %016lx %016lx %016lx %016lx",
+			    apm[0], apm[1], apm[2], apm[3]);
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: aqm %016lx %016lx %016lx %016lx",
+			    aqm[0], aqm[1], aqm[2], aqm[3]);
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: adm %016lx %016lx %016lx %016lx",
+			    adm[0], adm[1], adm[2], adm[3]);
+		break;
+	case CRYCB_FORMAT1:
+	case CRYCB_FORMAT0: /* Both CRYCB format uses APCB format 0 */
+	default: /* Can not happen */
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: apm %016lx aqm %04x adm %04x", apm[0],
+			    *((unsigned short *)aqm), *((unsigned short *)adm));
+		break;
+	}
+
 }
 
 /**
drivers/s390/crypto/vfio_ap_private.h +4 -0
index 5675492..4cd779d 100644
@@ -19,6 +19,10 @@
 
 #include "ap_bus.h"
 
+#define VM_AP_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
+	debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
+			    d_args)
+
 #define VFIO_AP_MODULE_NAME "vfio_ap"
 #define VFIO_AP_DRV_NAME "vfio_ap"
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 lines · On Fri, 5 Oct 2018 09:33:01 +0200 Pierre Morel <[email protected]> wrote:

Define a tracing function to trace in the KVM trace buffer and trace the changes of the APCB masks.

In general, trace events are good :)

Quoted 21 lines
---
 drivers/s390/crypto/vfio_ap_ops.c     | 22 ++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_private.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/s390/crypto/vfio_ap_ops.c +6 -0
index a8a9984..00e632a 100644
@@ -753,6 +753,28 @@ static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev)
 	memcpy(aqm, matrix_mdev->matrix.aqm, nbytes);
 	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.adm_max + 1, BITS_PER_BYTE);
 	memcpy(adm, matrix_mdev->matrix.adm, nbytes);
+
+	switch (matrix_mdev->kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) {
+	case CRYCB_FORMAT2:
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: apm %016lx %016lx %016lx %016lx",
+			    apm[0], apm[1], apm[2], apm[3]);

drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev) · line 771

Quoted 10 lines
drivers/s390/crypto/vfio_ap_ops.c +10 -0
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: aqm %016lx %016lx %016lx %016lx",
+			    aqm[0], aqm[1], aqm[2], aqm[3]);
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: adm %016lx %016lx %016lx %016lx",
+			    adm[0], adm[1], adm[2], adm[3]);
+		break;
+	case CRYCB_FORMAT1:
+	case CRYCB_FORMAT0: /* Both CRYCB format uses APCB format 0 */
+	default: /* Can not happen */

If it can't happen, trace "SET CRYCB: invalid format '%x'" instead?

Quoted 14 lines
drivers/s390/crypto/vfio_ap_ops.c +6 -0
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: apm %016lx aqm %04x adm %04x", apm[0],
+			    *((unsigned short *)aqm), *((unsigned short *)adm));
+		break;
+	}
+
 }
 
 /**
drivers/s390/crypto/vfio_ap_private.h +0 -0
index 5675492..4cd779d 100644

drivers/s390/crypto/vfio_ap_private.h line 28

Quoted 10 lines
drivers/s390/crypto/vfio_ap_private.h +4 -0
@@ -19,6 +19,10 @@
 
 #include "ap_bus.h"
 
+#define VM_AP_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
+	debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
+			    d_args)
+
 #define VFIO_AP_MODULE_NAME "vfio_ap"
 #define VFIO_AP_DRV_NAME "vfio_ap"
 

One thing I don't like about this is that you're using the kvm dbf from driver code, which looks odd. OTOH, these are kvm-specific masks...

Is there anything else that you may want to trace in the vfio-ap driver, so that you could add a dbf for it?

#2 lore raw
Quoted 59 lines · Cornelia Huck
Quoted 2 lines · On Fri, 5 Oct 2018 09:33:01 +0200 Pierre Morel <[email protected]> wrote:

Define a tracing function to trace in the KVM trace buffer and trace the changes of the APCB masks.

In general, trace events are good :)

Quoted 21 lines
---
 drivers/s390/crypto/vfio_ap_ops.c     | 22 ++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_private.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/s390/crypto/vfio_ap_ops.c +6 -0
index a8a9984..00e632a 100644
@@ -753,6 +753,28 @@ static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev)
 	memcpy(aqm, matrix_mdev->matrix.aqm, nbytes);
 	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.adm_max + 1, BITS_PER_BYTE);
 	memcpy(adm, matrix_mdev->matrix.adm, nbytes);
+
+	switch (matrix_mdev->kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) {
+	case CRYCB_FORMAT2:
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: apm %016lx %016lx %016lx %016lx",
+			    apm[0], apm[1], apm[2], apm[3]);

drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev) · line 771

Quoted 10 lines
drivers/s390/crypto/vfio_ap_ops.c +10 -0
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: aqm %016lx %016lx %016lx %016lx",
+			    aqm[0], aqm[1], aqm[2], aqm[3]);
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: adm %016lx %016lx %016lx %016lx",
+			    adm[0], adm[1], adm[2], adm[3]);
+		break;
+	case CRYCB_FORMAT1:
+	case CRYCB_FORMAT0: /* Both CRYCB format uses APCB format 0 */
+	default: /* Can not happen */

If it can't happen, trace "SET CRYCB: invalid format '%x'" instead?

Quoted 17 lines
drivers/s390/crypto/vfio_ap_ops.c +6 -0
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: apm %016lx aqm %04x adm %04x", apm[0],
+			    *((unsigned short *)aqm), *((unsigned short *)adm));
+		break;
+	}
+
 }
 
 /**
drivers/s390/crypto/vfio_ap_private.h +0 -0
index 5675492..4cd779d 100644
@@ -19,6 +19,10 @@
 
 #include "ap_bus.h"
 
Quoted 10 lines

drivers/s390/crypto/vfio_ap_private.h line 28

Quoted 7 lines
drivers/s390/crypto/vfio_ap_private.h +4 -0
+#define VM_AP_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
+	debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
+			    d_args)
+
 #define VFIO_AP_MODULE_NAME "vfio_ap"
 #define VFIO_AP_DRV_NAME "vfio_ap"
 

One thing I don't like about this is that you're using the kvm dbf from driver code, which looks odd. OTOH, these are kvm-specific masks...

Maybe factor out the setting of the actual masks to KVM code and do tracing there?

Quoted 4 lines

Is there anything else that you may want to trace in the vfio-ap driver, so that you could add a dbf for it?

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw
Quoted 71 lines · David Hildenbrand
Quoted 59 lines · Cornelia Huck
Quoted 2 lines · On Fri, 5 Oct 2018 09:33:01 +0200 Pierre Morel <[email protected]> wrote:

Define a tracing function to trace in the KVM trace buffer and trace the changes of the APCB masks.

In general, trace events are good :)

Quoted 21 lines
---
 drivers/s390/crypto/vfio_ap_ops.c     | 22 ++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_private.h |  4 ++++
 2 files changed, 26 insertions(+)
drivers/s390/crypto/vfio_ap_ops.c +6 -0
index a8a9984..00e632a 100644
@@ -753,6 +753,28 @@ static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev)
 	memcpy(aqm, matrix_mdev->matrix.aqm, nbytes);
 	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.adm_max + 1, BITS_PER_BYTE);
 	memcpy(adm, matrix_mdev->matrix.adm, nbytes);
+
+	switch (matrix_mdev->kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) {
+	case CRYCB_FORMAT2:
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: apm %016lx %016lx %016lx %016lx",
+			    apm[0], apm[1], apm[2], apm[3]);

drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev) · line 771

Quoted 10 lines
drivers/s390/crypto/vfio_ap_ops.c +10 -0
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: aqm %016lx %016lx %016lx %016lx",
+			    aqm[0], aqm[1], aqm[2], aqm[3]);
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: adm %016lx %016lx %016lx %016lx",
+			    adm[0], adm[1], adm[2], adm[3]);
+		break;
+	case CRYCB_FORMAT1:
+	case CRYCB_FORMAT0: /* Both CRYCB format uses APCB format 0 */
+	default: /* Can not happen */

If it can't happen, trace "SET CRYCB: invalid format '%x'" instead?

Quoted 17 lines
drivers/s390/crypto/vfio_ap_ops.c +6 -0
+		VM_AP_EVENT(matrix_mdev->kvm, 3,
+			    "SET CRYCB: apm %016lx aqm %04x adm %04x", apm[0],
+			    *((unsigned short *)aqm), *((unsigned short *)adm));
+		break;
+	}
+
 }
 
 /**
drivers/s390/crypto/vfio_ap_private.h +0 -0
index 5675492..4cd779d 100644
@@ -19,6 +19,10 @@
 
 #include "ap_bus.h"
 
Quoted 10 lines

drivers/s390/crypto/vfio_ap_private.h line 28

Quoted 7 lines
drivers/s390/crypto/vfio_ap_private.h +4 -0
+#define VM_AP_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
+	debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
+			    d_args)
+
 #define VFIO_AP_MODULE_NAME "vfio_ap"
 #define VFIO_AP_DRV_NAME "vfio_ap"
 

One thing I don't like about this is that you're using the kvm dbf from driver code, which looks odd. OTOH, these are kvm-specific masks...

Quoted 2 lines

Maybe factor out the setting of the actual masks to KVM code and do tracing there?

We had both versions internally, and this version looked shorter. But Pierre, can you send your v1 as well and then we can compare both variants.

Quoted 7 lines
Quoted 5 lines

Is there anything else that you may want to trace in the vfio-ap driver, so that you could add a dbf for it?

#4 lore raw

cover KVM: s390: Tracing APCB changes

In the first patch we define kvm_arch_crypto_set_masks, a new function to centralize the setup the APCB masks inside the CRYCB SIE satelite and add KVM_EVENT() to kvm_arch_crypto_set_masks and kvm_arch_crypto_clear_masks.

In the second patch we replace the vfio_ap_mdev_copy_masks() by the new kvm_arch_crypto_set_masks() function.

Pierre Morel (2):
KVM: s390: Tracing APCB changes
s390: vfio-ap: setup APCB mask using KVM dedicated function

 arch/s390/include/asm/kvm_host.h  |  2 ++
 arch/s390/kvm/kvm-s390.c          | 41 +++++++++++++++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_ops.c | 33 +++----------------------------
 3 files changed, 46 insertions(+), 30 deletions(-)
Signature · 1 line
2.7.4
#5 lore raw

PATCH 1/2 KVM: s390: Tracing APCB changes

kvm_arch_crypto_set_masks is a new function to centralize the setup the APCB masks inside the CRYCB SIE satelite.

To trace APCB mask changes, we add KVM_EVENT() tracing to both kvm_arch_crypto_set_masks and kvm_arch_crypto_clear_masks.

---
 arch/s390/include/asm/kvm_host.h |  2 ++
 arch/s390/kvm/kvm-s390.c         | 41 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
arch/s390/include/asm/kvm_host.h +2 -0
index 36d3531..22aa4da 100644
@@ -861,6 +861,8 @@ void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
 				 struct kvm_async_pf *work);
 
 void kvm_arch_crypto_clear_masks(struct kvm *kvm);
+void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
+			       unsigned long *aqm, unsigned long *adm);
 
 extern int sie64a(struct kvm_s390_sie_block *, u64 *);
 extern char sie_exit;
arch/s390/kvm/kvm-s390.c +41 -0

53 lines not on this page · raw message

Signature · 1 line
2.7.4
#9 lore raw

PATCH 2/2 s390: vfio-ap: setup APCB mask using KVM dedicated function

In reply to Pierre Morel

We replace the vfio_ap_mdev_copy_masks() by the new kvm_arch_crypto_set_masks() to be able to use the standard KVM tracing system.

---
 drivers/s390/crypto/vfio_ap_ops.c | 33 +++------------------------------
 1 file changed, 3 insertions(+), 30 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +3 -30
index a8a9984..f297779 100644
@@ -726,35 +726,6 @@ static const struct attribute_group *vfio_ap_mdev_attr_groups[] = {
 	NULL
 };
 
-static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev)
-{
-	int nbytes;
-	unsigned long *apm, *aqm, *adm;
-	struct kvm_s390_crypto_cb *crycb = matrix_mdev->kvm->arch.crypto.crycb;
-
-	switch (matrix_mdev->kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) {
-	case CRYCB_FORMAT2:
-		apm = (unsigned long *)crycb->apcb1.apm;
-		aqm = (unsigned long *)crycb->apcb1.aqm;
-		adm = (unsigned long *)crycb->apcb1.adm;
-		break;
-	case CRYCB_FORMAT1:
-	case CRYCB_FORMAT0:
-	default:
-		apm = (unsigned long *)crycb->apcb0.apm;
-		aqm = (unsigned long *)crycb->apcb0.aqm;
-		adm = (unsigned long *)crycb->apcb0.adm;
-		break;
-	}
-
-	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.apm_max + 1, BITS_PER_BYTE);
-	memcpy(apm, matrix_mdev->matrix.apm, nbytes);
-	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.aqm_max + 1, BITS_PER_BYTE);
-	memcpy(aqm, matrix_mdev->matrix.aqm, nbytes);
-	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.adm_max + 1, BITS_PER_BYTE);
-	memcpy(adm, matrix_mdev->matrix.adm, nbytes);
-}
-
 /**
  * vfio_ap_mdev_set_kvm
  *
@@ -811,7 +782,9 @@ static int vfio_ap_mdev_group_notifier(struct notifier_block *nb,
 	if (!matrix_mdev->kvm->arch.crypto.crycbd)
 		return NOTIFY_DONE;
 
-	vfio_ap_mdev_copy_masks(matrix_mdev);
+	kvm_arch_crypto_set_masks(matrix_mdev->kvm, matrix_mdev->matrix.apm,
+				  matrix_mdev->matrix.aqm,
+				  matrix_mdev->matrix.adm);
 
 	return NOTIFY_OK;
 }
Signature · 1 line
2.7.4
#12 lore raw

Re: [PATCH v1 0/2] KVM: s390: Tracing APCB changes

In reply to Pierre Morel
Quoted 9 lines · On Fri, 5 Oct 2018 10:31:08 +0200 Pierre Morel <[email protected]> wrote:

In the first patch we define kvm_arch_crypto_set_masks, a new function to centralize the setup the APCB masks inside the CRYCB SIE satelite and add KVM_EVENT() to kvm_arch_crypto_set_masks and kvm_arch_crypto_clear_masks.

In the second patch we replace the vfio_ap_mdev_copy_masks() by the new kvm_arch_crypto_set_masks() function.

Quoted 9 lines

Pierre Morel (2):
KVM: s390: Tracing APCB changes
s390: vfio-ap: setup APCB mask using KVM dedicated function

 arch/s390/include/asm/kvm_host.h  |  2 ++
 arch/s390/kvm/kvm-s390.c          | 41 +++++++++++++++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_ops.c | 33 +++----------------------------
 3 files changed, 46 insertions(+), 30 deletions(-)

I like this version better: it moves the mask-setting next to the mask-clearing, and, as a bonus, adds a trace event for clearing as well :)

#6 lore raw

Re: [PATCH v1 1/2] KVM: s390: Tracing APCB changes

In reply to Pierre Morel
Quoted 2 lines · On Fri, 5 Oct 2018 10:31:09 +0200 Pierre Morel <[email protected]> wrote:

kvm_arch_crypto_set_masks is a new function to centralize the setup the APCB masks inside the CRYCB SIE satelite.

s/satelite/satellite/

Quoted 58 lines

To trace APCB mask changes, we add KVM_EVENT() tracing to both kvm_arch_crypto_set_masks and kvm_arch_crypto_clear_masks.

---
 arch/s390/include/asm/kvm_host.h |  2 ++
 arch/s390/kvm/kvm-s390.c         | 41 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
arch/s390/include/asm/kvm_host.h +2 -0
index 36d3531..22aa4da 100644
@@ -861,6 +861,8 @@ void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
 				 struct kvm_async_pf *work);
 
 void kvm_arch_crypto_clear_masks(struct kvm *kvm);
+void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
+			       unsigned long *aqm, unsigned long *adm);
 
 extern int sie64a(struct kvm_s390_sie_block *, u64 *);
 extern char sie_exit;
arch/s390/kvm/kvm-s390.c +27 -0
index d3ea721..e871e5a 100644
@@ -2057,6 +2057,46 @@ static void kvm_s390_set_crycb_format(struct kvm *kvm)
 		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
 }
 
+void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
+			       unsigned long *aqm, unsigned long *adm)
+{
+	struct kvm_s390_crypto_cb *crycb = kvm->arch.crypto.crycb;
+
+	mutex_lock(&kvm->lock);
+	kvm_s390_vcpu_block_all(kvm);
+
+	switch (kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) {
+	case CRYCB_FORMAT2: /* APCB1 use 256 bits */
+		memcpy(crycb->apcb1.apm, apm, 32);
+		VM_EVENT(kvm, 3, "SET CRYCB: apm %016lx %016lx %016lx %016lx",
+			 apm[0], apm[1], apm[2], apm[3]);
+		memcpy(crycb->apcb1.aqm, aqm, 32);
+		VM_EVENT(kvm, 3, "SET CRYCB: aqm %016lx %016lx %016lx %016lx",
+			 aqm[0], aqm[1], aqm[2], aqm[3]);
+		memcpy(crycb->apcb1.adm, adm, 32);
+		VM_EVENT(kvm, 3, "SET CRYCB: adm %016lx %016lx %016lx %016lx",
+			 adm[0], adm[1], adm[2], adm[3]);
+		break;
+	case CRYCB_FORMAT1:
+	case CRYCB_FORMAT0: /* Fall through both use APCB0 */
+		memcpy(crycb->apcb0.apm, apm, 8);
+		memcpy(crycb->apcb0.aqm, aqm, 2);
+		memcpy(crycb->apcb0.adm, adm, 2);
+		VM_EVENT(kvm, 3, "SET CRYCB: apm %016lx aqm %04x adm %04x",
+			 apm[0], *((unsigned short *)aqm),

arch/s390/kvm/kvm-s390.c static void kvm_s390_set_crycb_format(struct kvm *kvm) · line 2096

Quoted 10 lines
arch/s390/kvm/kvm-s390.c +10 -0
+			 *((unsigned short *)adm));
+		break;
+	default:	/* Can not happen */
+		break;
+	}
+
+	/* recreate the shadow crycb for each vcpu */
+	kvm_s390_sync_request_broadcast(kvm, KVM_REQ_VSIE_RESTART);
+	kvm_s390_vcpu_unblock_all(kvm);
+	mutex_unlock(&kvm->lock);

The locking and requests makes me wonder if we missed them before... were they simply not needed for the prior use case (mdev group notifier)?

Quoted 14 lines
arch/s390/kvm/kvm-s390.c +4 -0
+}
+EXPORT_SYMBOL_GPL(kvm_arch_crypto_set_masks);
+
 void kvm_arch_crypto_clear_masks(struct kvm *kvm)
 {
 	mutex_lock(&kvm->lock);
@@ -2067,6 +2107,7 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm)
 	memset(&kvm->arch.crypto.crycb->apcb1, 0,
 	       sizeof(kvm->arch.crypto.crycb->apcb1));
 
+	VM_EVENT(kvm, 3, "%s", "CLR CRYCB:");
 	/* recreate the shadow crycb for each vcpu */
 	kvm_s390_sync_request_broadcast(kvm, KVM_REQ_VSIE_RESTART);
 	kvm_s390_vcpu_unblock_all(kvm);
#13 lore raw

Re: [PATCH v1 0/2] KVM: s390: Tracing APCB changes

In reply to Cornelia Huck
Quoted 22 lines · Cornelia Huck
Quoted 9 lines · On Fri, 5 Oct 2018 10:31:08 +0200 Pierre Morel <[email protected]> wrote:

In the first patch we define kvm_arch_crypto_set_masks, a new function to centralize the setup the APCB masks inside the CRYCB SIE satelite and add KVM_EVENT() to kvm_arch_crypto_set_masks and kvm_arch_crypto_clear_masks.

In the second patch we replace the vfio_ap_mdev_copy_masks() by the new kvm_arch_crypto_set_masks() function.

Quoted 9 lines

Pierre Morel (2):
KVM: s390: Tracing APCB changes
s390: vfio-ap: setup APCB mask using KVM dedicated function

 arch/s390/include/asm/kvm_host.h  |  2 ++
 arch/s390/kvm/kvm-s390.c          | 41 +++++++++++++++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_ops.c | 33 +++----------------------------
 3 files changed, 46 insertions(+), 30 deletions(-)
Quoted 4 lines

I like this version better: it moves the mask-setting next to the mask-clearing, and, as a bonus, adds a trace event for clearing as well :)

Yes, more code but looks cleaner to me.

Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

Re: [PATCH v1 1/2] KVM: s390: Tracing APCB changes

In reply to Cornelia Huck
Quoted 73 lines · Cornelia Huck
Quoted 2 lines · On Fri, 5 Oct 2018 10:31:09 +0200 Pierre Morel <[email protected]> wrote:

kvm_arch_crypto_set_masks is a new function to centralize the setup the APCB masks inside the CRYCB SIE satelite.

s/satelite/satellite/

Quoted 65 lines

To trace APCB mask changes, we add KVM_EVENT() tracing to both kvm_arch_crypto_set_masks and kvm_arch_crypto_clear_masks.

---
  arch/s390/include/asm/kvm_host.h |  2 ++
  arch/s390/kvm/kvm-s390.c         | 41 ++++++++++++++++++++++++++++++++++++++++
  2 files changed, 43 insertions(+)
arch/s390/include/asm/kvm_host.h +2 -0
index 36d3531..22aa4da 100644
@@ -861,6 +861,8 @@ void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
  				 struct kvm_async_pf *work);
 
  void kvm_arch_crypto_clear_masks(struct kvm *kvm);
+void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
+			       unsigned long *aqm, unsigned long *adm);
 
  extern int sie64a(struct kvm_s390_sie_block *, u64 *);
  extern char sie_exit;
arch/s390/kvm/kvm-s390.c +34 -0
index d3ea721..e871e5a 100644
@@ -2057,6 +2057,46 @@ static void kvm_s390_set_crycb_format(struct kvm *kvm)
  		kvm->arch.crypto.crycbd |= CRYCB_FORMAT1;
  }
 
+void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
+			       unsigned long *aqm, unsigned long *adm)
+{
+	struct kvm_s390_crypto_cb *crycb = kvm->arch.crypto.crycb;
+
+	mutex_lock(&kvm->lock);
+	kvm_s390_vcpu_block_all(kvm);
+
+	switch (kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) {
+	case CRYCB_FORMAT2: /* APCB1 use 256 bits */
+		memcpy(crycb->apcb1.apm, apm, 32);
+		VM_EVENT(kvm, 3, "SET CRYCB: apm %016lx %016lx %016lx %016lx",
+			 apm[0], apm[1], apm[2], apm[3]);
+		memcpy(crycb->apcb1.aqm, aqm, 32);
+		VM_EVENT(kvm, 3, "SET CRYCB: aqm %016lx %016lx %016lx %016lx",
+			 aqm[0], aqm[1], aqm[2], aqm[3]);
+		memcpy(crycb->apcb1.adm, adm, 32);
+		VM_EVENT(kvm, 3, "SET CRYCB: adm %016lx %016lx %016lx %016lx",
+			 adm[0], adm[1], adm[2], adm[3]);
+		break;
+	case CRYCB_FORMAT1:
+	case CRYCB_FORMAT0: /* Fall through both use APCB0 */
+		memcpy(crycb->apcb0.apm, apm, 8);
+		memcpy(crycb->apcb0.aqm, aqm, 2);
+		memcpy(crycb->apcb0.adm, adm, 2);
+		VM_EVENT(kvm, 3, "SET CRYCB: apm %016lx aqm %04x adm %04x",
+			 apm[0], *((unsigned short *)aqm),
+			 *((unsigned short *)adm));
+		break;
+	default:	/* Can not happen */
+		break;
+	}
+
+	/* recreate the shadow crycb for each vcpu */
Quoted 8 lines

arch/s390/kvm/kvm-s390.c static void kvm_s390_set_crycb_format(struct kvm *kvm) · line 2096

Quoted 3 lines
arch/s390/kvm/kvm-s390.c +3 -0
+	kvm_s390_sync_request_broadcast(kvm, KVM_REQ_VSIE_RESTART);
+	kvm_s390_vcpu_unblock_all(kvm);
+	mutex_unlock(&kvm->lock);

The locking and requests makes me wonder if we missed them before... were they simply not needed for the prior use case (mdev group notifier)?

Before we used to set the mask before creating the vcpu. In fact since we still call this function from the initialization of VFIO AP we still do.

But since this function is more generic we need to be more careful if it is called when vcpu are running.
We do the same locking mechanism in the kvm_arch_crypto_clear_mask().

Quoted 16 lines
Quoted 15 lines
arch/s390/kvm/kvm-s390.c +4 -0
+}
+EXPORT_SYMBOL_GPL(kvm_arch_crypto_set_masks);
+
  void kvm_arch_crypto_clear_masks(struct kvm *kvm)
  {
  	mutex_lock(&kvm->lock);
@@ -2067,6 +2107,7 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm)
  	memset(&kvm->arch.crypto.crycb->apcb1, 0,
  	       sizeof(kvm->arch.crypto.crycb->apcb1));
 
+	VM_EVENT(kvm, 3, "%s", "CLR CRYCB:");
  	/* recreate the shadow crycb for each vcpu */
  	kvm_s390_sync_request_broadcast(kvm, KVM_REQ_VSIE_RESTART);
  	kvm_s390_vcpu_unblock_all(kvm);
Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
Reviewed-by
#8 lore raw

Re: [PATCH v1 1/2] KVM: s390: Tracing APCB changes

Quoted 18 lines · On Fri, 5 Oct 2018 10:57:22 +0200 Pierre Morel <[email protected]> wrote:
Quoted 17 lines · Cornelia Huck
Quoted 2 lines · On Fri, 5 Oct 2018 10:31:09 +0200 Pierre Morel <[email protected]> wrote:

kvm_arch_crypto_set_masks is a new function to centralize the setup the APCB masks inside the CRYCB SIE satelite.

s/satelite/satellite/

Quoted 9 lines

To trace APCB mask changes, we add KVM_EVENT() tracing to both kvm_arch_crypto_set_masks and kvm_arch_crypto_clear_masks.

---
  arch/s390/include/asm/kvm_host.h |  2 ++
  arch/s390/kvm/kvm-s390.c         | 41 ++++++++++++++++++++++++++++++++++++++++
  2 files changed, 43 insertions(+)

(...)

Quoted 11 lines
Quoted 3 lines

The locking and requests makes me wonder if we missed them before... were they simply not needed for the prior use case (mdev group notifier)?

Before we used to set the mask before creating the vcpu. In fact since we still call this function from the initialization of VFIO AP we still do.

But since this function is more generic we need to be more careful if it is called when vcpu are running.
We do the same locking mechanism in the kvm_arch_crypto_clear_mask().

Yes, that makes sense.

Reviewed-by on v1 2/2
#10 lore raw

Re: [PATCH v1 2/2] s390: vfio-ap: setup APCB mask using KVM dedicated function

In reply to Pierre Morel
Quoted 8 lines · On Fri, 5 Oct 2018 10:31:10 +0200 Pierre Morel <[email protected]> wrote:

We replace the vfio_ap_mdev_copy_masks() by the new kvm_arch_crypto_set_masks() to be able to use the standard KVM tracing system.

---
 drivers/s390/crypto/vfio_ap_ops.c | 33 +++------------------------------
 1 file changed, 3 insertions(+), 30 deletions(-)
Reviewed-by on v1 2/2
#11 lore raw

Re: [PATCH v1 2/2] s390: vfio-ap: setup APCB mask using KVM dedicated function

In reply to Pierre Morel
Quoted 51 lines · Pierre Morel

We replace the vfio_ap_mdev_copy_masks() by the new kvm_arch_crypto_set_masks() to be able to use the standard KVM tracing system.

---
 drivers/s390/crypto/vfio_ap_ops.c | 33 +++------------------------------
 1 file changed, 3 insertions(+), 30 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +0 -29
index a8a9984..f297779 100644
@@ -726,35 +726,6 @@ static const struct attribute_group *vfio_ap_mdev_attr_groups[] = {
 	NULL
 };
 
-static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev)
-{
-	int nbytes;
-	unsigned long *apm, *aqm, *adm;
-	struct kvm_s390_crypto_cb *crycb = matrix_mdev->kvm->arch.crypto.crycb;
-
-	switch (matrix_mdev->kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) {
-	case CRYCB_FORMAT2:
-		apm = (unsigned long *)crycb->apcb1.apm;
-		aqm = (unsigned long *)crycb->apcb1.aqm;
-		adm = (unsigned long *)crycb->apcb1.adm;
-		break;
-	case CRYCB_FORMAT1:
-	case CRYCB_FORMAT0:
-	default:
-		apm = (unsigned long *)crycb->apcb0.apm;
-		aqm = (unsigned long *)crycb->apcb0.aqm;
-		adm = (unsigned long *)crycb->apcb0.adm;
-		break;
-	}
-
-	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.apm_max + 1, BITS_PER_BYTE);
-	memcpy(apm, matrix_mdev->matrix.apm, nbytes);
-	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.aqm_max + 1, BITS_PER_BYTE);
-	memcpy(aqm, matrix_mdev->matrix.aqm, nbytes);
-	nbytes = DIV_ROUND_UP(matrix_mdev->matrix.adm_max + 1, BITS_PER_BYTE);
-	memcpy(adm, matrix_mdev->matrix.adm, nbytes);
-}
-
 /**
  * vfio_ap_mdev_set_kvm
  *

drivers/s390/crypto/vfio_ap_ops.c static int vfio_ap_mdev_group_notifier(struct notifier_block *nb, · line 790

Quoted 10 lines
drivers/s390/crypto/vfio_ap_ops.c +3 -1
@@ -811,7 +782,9 @@ static int vfio_ap_mdev_group_notifier(struct notifier_block *nb,
 	if (!matrix_mdev->kvm->arch.crypto.crycbd)
 		return NOTIFY_DONE;
 
-	vfio_ap_mdev_copy_masks(matrix_mdev);
+	kvm_arch_crypto_set_masks(matrix_mdev->kvm, matrix_mdev->matrix.apm,
+				  matrix_mdev->matrix.aqm,
+				  matrix_mdev->matrix.adm);
 
 	return NOTIFY_OK;
 }
Signature · 3 lines
Thanks,

David / dhildenb
maintainer
#14 lore raw

Re: [PATCH v1 0/2] KVM: s390: Tracing APCB changes

In reply to Pierre Morel
Quoted 8 lines · Pierre Morel

In the first patch we define kvm_arch_crypto_set_masks, a new function to centralize the setup the APCB masks inside the CRYCB SIE satelite and add KVM_EVENT() to kvm_arch_crypto_set_masks and kvm_arch_crypto_clear_masks.

In the second patch we replace the vfio_ap_mdev_copy_masks() by the new kvm_arch_crypto_set_masks() function.

FWIW I also like this version better. And accommodating for on-the fly changes seems to be showing in the right direction anyway.

I did not look into the details but it looks good to me.

Halil

#15 lore raw

Re: [PATCH v1 0/2] KVM: s390: Tracing APCB changes

In reply to Pierre Morel

Both applied.
(FWIW, this was based on an older version of the ap patch set, I had to fixup the 2 patch)

Quoted 18 lines · Pierre Morel

In the first patch we define kvm_arch_crypto_set_masks, a new function to centralize the setup the APCB masks inside the CRYCB SIE satelite and add KVM_EVENT() to kvm_arch_crypto_set_masks and kvm_arch_crypto_clear_masks.

In the second patch we replace the vfio_ap_mdev_copy_masks() by the new kvm_arch_crypto_set_masks() function.

Pierre Morel (2):
KVM: s390: Tracing APCB changes
s390: vfio-ap: setup APCB mask using KVM dedicated function

 arch/s390/include/asm/kvm_host.h  |  2 ++
 arch/s390/kvm/kvm-s390.c          | 41 +++++++++++++++++++++++++++++++++++++++
 drivers/s390/crypto/vfio_ap_ops.c | 33 +++----------------------------
 3 files changed, 46 insertions(+), 30 deletions(-)