Skip to contentSkip to conversation

KVM: s390: vsie: Consolidate CRYCB validation

PATCH Superseded Pierre Morel 4 participants 27 messages Aug 22, 2018 – Aug 23, 2018

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover KVM: s390: vsie: Consolidate CRYCB validation

Before adapting the CRYCB shadowing for a guest supporting the AP instructions we want to clean the CRYCB shadowing code.

Pierre Morel (5):
KVM: s390: vsie: BUG correction by shadow_crycb
KVM: s390: vsie: Only accept FORMAT1 CRYCB for guest2
KVM: s390: vsie: Allow support for a host without AP
KVM: s390: vsie: Always test the crycbd for NULL
KVM: s390: vsie: Do the CRYCB validation first

 arch/s390/kvm/vsie.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
Signature · 7 lines
2.7.4

Changelog from v1
- split into severall small patches
- insert the first cleaning patch ahead
- add a new patch to allow a host not having AP
  instructions
#1 lore raw

PATCH v2 1/5 KVM: s390: vsie: BUG correction by shadow_crycb

Copy the key mask to the right offset inside the shadow CRYCB

---
 arch/s390/kvm/vsie.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +2 -1
index 9175518..12b9707 100644
@@ -173,7 +173,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		return set_validity_icpt(scb_s, 0x0039U);
 
 	/* copy only the wrapping keys */
-	if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56))
+	if (read_guest_real(vcpu, crycb_addr + 72,
+			    vsie_page->crycb.dea_wrapping_key_mask, 56))
 		return set_validity_icpt(scb_s, 0x0035U);
 
 	scb_s->ecb3 |= ecb3_flags;
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v2 1/5] KVM: s390: vsie: BUG correction by shadow_crycb

Quoted 14 lines · Pierre Morel

Copy the key mask to the right offset inside the shadow CRYCB

---
 arch/s390/kvm/vsie.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +0 -0
index 9175518..12b9707 100644

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 180

Quoted 9 lines
arch/s390/kvm/vsie.c +2 -1
@@ -173,7 +173,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		return set_validity_icpt(scb_s, 0x0039U);
 
 	/* copy only the wrapping keys */
-	if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56))
+	if (read_guest_real(vcpu, crycb_addr + 72,
+			    vsie_page->crycb.dea_wrapping_key_mask, 56))
 		return set_validity_icpt(scb_s, 0x0035U);
 
 	scb_s->ecb3 |= ecb3_flags;

Please fixup the subject as requested. (were there more RB-s?)

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

Re: [PATCH v2 1/5] KVM: s390: vsie: BUG correction by shadow_crycb

Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Pierre Morel

Copy the key mask to the right offset inside the shadow CRYCB

---
  arch/s390/kvm/vsie.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +2 -1
index 9175518..12b9707 100644
@@ -173,7 +173,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  		return set_validity_icpt(scb_s, 0x0039U);
 
  	/* copy only the wrapping keys */
-	if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56))
+	if (read_guest_real(vcpu, crycb_addr + 72,
+			    vsie_page->crycb.dea_wrapping_key_mask, 56))
  		return set_validity_icpt(scb_s, 0x0035U);
 
Quoted 5 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 180

Quoted 2 lines
arch/s390/kvm/vsie.c +0 -0
  	scb_s->ecb3 |= ecb3_flags;

Please fixup the subject as requested. (were there more RB-s?)

Yes, sorry, will do.

No no other RB yet.

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
Reviewed-by
#4 lore raw

Re: [PATCH v2 1/5] KVM: s390: vsie: BUG correction by shadow_crycb

In reply to David Hildenbrand
Quoted 22 lines · On Wed, 22 Aug 2018 18:53:02 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 21 lines · Pierre Morel

Copy the key mask to the right offset inside the shadow CRYCB

---
 arch/s390/kvm/vsie.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +2 -1
index 9175518..12b9707 100644
@@ -173,7 +173,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		return set_validity_icpt(scb_s, 0x0039U);
 
 	/* copy only the wrapping keys */
-	if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56))
+	if (read_guest_real(vcpu, crycb_addr + 72,
+			    vsie_page->crycb.dea_wrapping_key_mask, 56))
 		return set_validity_icpt(scb_s, 0x0035U);
 
Quoted 4 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 180

Quoted 2 lines
arch/s390/kvm/vsie.c +0 -0
 	scb_s->ecb3 |= ecb3_flags;

Please fixup the subject as requested.

+1

Quoted 2 lines

(were there more RB-s?)

Yep, mine. FTR:

#5 lore raw

Re: [PATCH v2 1/5] KVM: s390: vsie: BUG correction by shadow_crycb

Quoted 25 lines · Cornelia Huck
Quoted 22 lines · On Wed, 22 Aug 2018 18:53:02 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 21 lines · Pierre Morel

Copy the key mask to the right offset inside the shadow CRYCB

---
  arch/s390/kvm/vsie.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +2 -1
index 9175518..12b9707 100644
@@ -173,7 +173,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  		return set_validity_icpt(scb_s, 0x0039U);
 
  	/* copy only the wrapping keys */
-	if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56))
+	if (read_guest_real(vcpu, crycb_addr + 72,
+			    vsie_page->crycb.dea_wrapping_key_mask, 56))
  		return set_validity_icpt(scb_s, 0x0035U);
 
Quoted 8 lines
Quoted 4 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 180

Quoted 2 lines
arch/s390/kvm/vsie.c +0 -0
  	scb_s->ecb3 |= ecb3_flags;

Please fixup the subject as requested.

+1

Quoted 1 line

(were there more RB-s?)

Already done in my local branch.

Quoted 6 lines
Quoted 1 line

Yep, mine. FTR:

Thanks,

regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
maintainer
#6 lore raw

Re: [PATCH v2 1/5] KVM: s390: vsie: BUG correction by shadow_crycb

In reply to David Hildenbrand
Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Pierre Morel

Copy the key mask to the right offset inside the shadow CRYCB

---
 arch/s390/kvm/vsie.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +2 -1
index 9175518..12b9707 100644
@@ -173,7 +173,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		return set_validity_icpt(scb_s, 0x0039U);
 
 	/* copy only the wrapping keys */
-	if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56))
+	if (read_guest_real(vcpu, crycb_addr + 72,
+			    vsie_page->crycb.dea_wrapping_key_mask, 56))
 		return set_validity_icpt(scb_s, 0x0035U);
 
Quoted 5 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 180

Quoted 2 lines
arch/s390/kvm/vsie.c +0 -0
 	scb_s->ecb3 |= ecb3_flags;

Please fixup the subject as requested. (were there more RB-s?)

Yes, he seems to have ignored mine...

#7 lore raw

Re: [PATCH v2 1/5] KVM: s390: vsie: BUG correction by shadow_crycb

Quoted 23 lines · Janosch Frank
Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Pierre Morel

Copy the key mask to the right offset inside the shadow CRYCB

---
  arch/s390/kvm/vsie.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +2 -1
index 9175518..12b9707 100644
@@ -173,7 +173,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  		return set_validity_icpt(scb_s, 0x0039U);
 
  	/* copy only the wrapping keys */
-	if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56))
+	if (read_guest_real(vcpu, crycb_addr + 72,
+			    vsie_page->crycb.dea_wrapping_key_mask, 56))
  		return set_validity_icpt(scb_s, 0x0035U);
 
Quoted 8 lines
Quoted 5 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 180

Quoted 2 lines
arch/s390/kvm/vsie.c +0 -0
  	scb_s->ecb3 |= ecb3_flags;

Please fixup the subject as requested. (were there more RB-s?)

Yes, he seems to have ignored mine...

Sorry,
I focused on your comment and the answer from David and forgot it.

thanks Janosch I will add it of course

regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#8 lore raw

PATCH v2 2/5 KVM: s390: vsie: Only accept FORMAT1 CRYCB for guest2

In reply to Pierre Morel

As the comment above the function suggested the shadowing of the guest2 CRYCB can only accept a format 1 since AP instructions are not supported in the guest.

Let's modify the check which allowed to accept a format 2 too.

---
 arch/s390/kvm/vsie.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +3 -1
index 12b9707..56a9d47 100644
@@ -156,7 +156,9 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	u8 ecb3_flags;
 
 	scb_s->crycbd = 0;
-	if (!(crycbd_o & vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1))
+	if (!(crycbd_o == CRYCB_FORMAT1))
+		return 0;
+	if (!(vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1))
 		return 0;
 	/* format-1 is supported with message-security-assist extension 3 */
 	if (!test_kvm_facility(vcpu->kvm, 76))
Signature · 1 line
2.7.4
#9 lore raw

Re: [PATCH v2 2/5] KVM: s390: vsie: Only accept FORMAT1 CRYCB for guest2

Quoted 5 lines · Pierre Morel

As the comment above the function suggested the shadowing of the guest2 CRYCB can only accept a format 1 since AP instructions are not supported in the guest.

Let's modify the check which allowed to accept a format 2 too.

As the bit is ignored without AP/APXA, it is perfectly valid to accept a format 2, we just have to interpret it as format 1 (which is what we do)

What am I missing?

Quoted 11 lines
---
 arch/s390/kvm/vsie.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +0 -0
index 12b9707..56a9d47 100644

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 160

Quoted 6 lines
arch/s390/kvm/vsie.c +2 -1
@@ -156,7 +156,9 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	u8 ecb3_flags;
 
 	scb_s->crycbd = 0;
-	if (!(crycbd_o & vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1))
+	if (!(crycbd_o == CRYCB_FORMAT1))
+		return 0;

huh, this looks very broken. The address is still in there.

Quoted 5 lines
arch/s390/kvm/vsie.c +1 -0
+	if (!(vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1))
 		return 0;
 	/* format-1 is supported with message-security-assist extension 3 */
 	if (!test_kvm_facility(vcpu->kvm, 76))
Signature · 3 lines
Thanks,

David / dhildenb
#10 lore raw

Re: [PATCH v2 2/5] KVM: s390: vsie: Only accept FORMAT1 CRYCB for guest2

Quoted 5 lines · David Hildenbrand
Quoted 4 lines · Pierre Morel

As the comment above the function suggested the shadowing of the guest2 CRYCB can only accept a format 1 since AP instructions are not supported in the guest.

Quoted 7 lines
Quoted 1 line

Let's modify the check which allowed to accept a format 2 too.

As the bit is ignored without AP/APXA, it is perfectly valid to accept a format 2, we just have to interpret it as format 1 (which is what we do)

What am I missing?

Nothing.
I was still having AP interpretation in mind.

Quoted 13 lines
Quoted 13 lines
---
  arch/s390/kvm/vsie.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/s390/kvm/vsie.c +0 -0
index 12b9707..56a9d47 100644
@@ -156,7 +156,9 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  	u8 ecb3_flags;
 
Quoted 6 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 160

Quoted 4 lines
arch/s390/kvm/vsie.c +2 -1
  	scb_s->crycbd = 0;
-	if (!(crycbd_o & vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1))
+	if (!(crycbd_o == CRYCB_FORMAT1))
+		return 0;

huh, this looks very broken. The address is still in there.

completely broken you are right

anyway this broken useless patch disappear.

Thanks,

regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#11 lore raw

PATCH v2 3/5 KVM: s390: vsie: Allow support for a host without AP

In reply to Pierre Morel

Currently the CRYCB format used in the host for the shadowed CRYCB is FORMAT2 while no check is done if AP instructions are supported in the host.

We better use the format the host calculated for the guest 1 as the host already tested it against its facility set.

---
 arch/s390/kvm/vsie.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/s390/kvm/vsie.c +3 -2
index 56a9d47..0b12916 100644
@@ -154,6 +154,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	const u32 crycb_addr = crycbd_o & 0x7ffffff8U;
 	unsigned long *b1, *b2;
 	u8 ecb3_flags;
+	unsigned long g1_fmt;
 
 	scb_s->crycbd = 0;
 	if (!(crycbd_o == CRYCB_FORMAT1))
@@ -180,8 +181,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		return set_validity_icpt(scb_s, 0x0035U);
 
 	scb_s->ecb3 |= ecb3_flags;
-	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT1 |
-			CRYCB_FORMAT2;
+	g1_fmt = vcpu->arch.sie_block->crycbd & 0x03;
+	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | g1_fmt;
 
 	/* xor both blocks in one run */
 	b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;
Signature · 1 line
2.7.4
#12 lore raw

Re: [PATCH v2 3/5] KVM: s390: vsie: Allow support for a host without AP

Quoted 27 lines · Pierre Morel

Currently the CRYCB format used in the host for the shadowed CRYCB is FORMAT2 while no check is done if AP instructions are supported in the host.

We better use the format the host calculated for the guest 1 as the host already tested it against its facility set.

---
 arch/s390/kvm/vsie.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/s390/kvm/vsie.c +1 -0
index 56a9d47..0b12916 100644
@@ -154,6 +154,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	const u32 crycb_addr = crycbd_o & 0x7ffffff8U;
 	unsigned long *b1, *b2;
 	u8 ecb3_flags;
+	unsigned long g1_fmt;
 
 	scb_s->crycbd = 0;
 	if (!(crycbd_o == CRYCB_FORMAT1))

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 188

Quoted 10 lines
arch/s390/kvm/vsie.c +2 -2
@@ -180,8 +181,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		return set_validity_icpt(scb_s, 0x0035U);
 
 	scb_s->ecb3 |= ecb3_flags;
-	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT1 |
-			CRYCB_FORMAT2;
+	g1_fmt = vcpu->arch.sie_block->crycbd & 0x03;
+	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | g1_fmt;
 
 	/* xor both blocks in one run */
 	b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;

This is wrong. I remember that with APXA, if FORMAT2 is available, we should always use FORMAT2. That's why we explicitly convert it here.

Signature · 3 lines
Thanks,

David / dhildenb
#13 lore raw

Re: [PATCH v2 3/5] KVM: s390: vsie: Allow support for a host without AP

Quoted 35 lines · David Hildenbrand
Quoted 34 lines · Pierre Morel

Currently the CRYCB format used in the host for the shadowed CRYCB is FORMAT2 while no check is done if AP instructions are supported in the host.

We better use the format the host calculated for the guest 1 as the host already tested it against its facility set.

---
  arch/s390/kvm/vsie.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
arch/s390/kvm/vsie.c +3 -2
index 56a9d47..0b12916 100644
@@ -154,6 +154,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  	const u32 crycb_addr = crycbd_o & 0x7ffffff8U;
  	unsigned long *b1, *b2;
  	u8 ecb3_flags;
+	unsigned long g1_fmt;
 
  	scb_s->crycbd = 0;
  	if (!(crycbd_o == CRYCB_FORMAT1))
@@ -180,8 +181,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  		return set_validity_icpt(scb_s, 0x0035U);
 
  	scb_s->ecb3 |= ecb3_flags;
-	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT1 |
-			CRYCB_FORMAT2;
+	g1_fmt = vcpu->arch.sie_block->crycbd & 0x03;
+	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | g1_fmt;
 
Quoted 7 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 188

Quoted 3 lines
arch/s390/kvm/vsie.c +0 -0
  	/* xor both blocks in one run */
  	b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;

This is wrong. I remember that with APXA, if FORMAT2 is available, we should always use FORMAT2. That's why we explicitly convert it here.

You are right if FORMAT2 is available we should use FORMAT2 but the intention here is to use what KVM crypto init function did, assuming it did the right thing.

Eventually we are running on a host without AP and we should use FORMAT1.

Isn't it correct?

Regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#14 lore raw

Re: [PATCH v2 3/5] KVM: s390: vsie: Allow support for a host without AP

Quoted 44 lines · Pierre Morel
Quoted 35 lines · David Hildenbrand
Quoted 34 lines · Pierre Morel

Currently the CRYCB format used in the host for the shadowed CRYCB is FORMAT2 while no check is done if AP instructions are supported in the host.

We better use the format the host calculated for the guest 1 as the host already tested it against its facility set.

---
  arch/s390/kvm/vsie.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
arch/s390/kvm/vsie.c +3 -2
index 56a9d47..0b12916 100644
@@ -154,6 +154,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  	const u32 crycb_addr = crycbd_o & 0x7ffffff8U;
  	unsigned long *b1, *b2;
  	u8 ecb3_flags;
+	unsigned long g1_fmt;
 
  	scb_s->crycbd = 0;
  	if (!(crycbd_o == CRYCB_FORMAT1))
@@ -180,8 +181,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  		return set_validity_icpt(scb_s, 0x0035U);
 
  	scb_s->ecb3 |= ecb3_flags;
-	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT1 |
-			CRYCB_FORMAT2;
+	g1_fmt = vcpu->arch.sie_block->crycbd & 0x03;
+	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | g1_fmt;
 
Quoted 7 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 188

Quoted 3 lines
arch/s390/kvm/vsie.c +0 -0
  	/* xor both blocks in one run */
  	b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;

This is wrong. I remember that with APXA, if FORMAT2 is available, we should always use FORMAT2. That's why we explicitly convert it here.

Quoted 7 lines

You are right if FORMAT2 is available we should use FORMAT2 but the intention here is to use what KVM crypto init function did, assuming it did the right thing.

Eventually we are running on a host without AP and we should use FORMAT1.

Isn't it correct?

Yes and no :)

No APXA -> FORMAT2 bit is ignored (and that is one of the reasons why I am being so strict about simulating HW behavior correctly in nested code :) )

This only holds as long as we are not using AP. Because from a MSA3 perspective, FORMAT1==FORMAT2 (apart from the length/alignment, which is fine for us).

Once we support AP (via ECA.28), we'll properly have to create either a Format0/Format1/Format2. Then, there is actually a semantically difference ("different fields used").

Quoted 5 lines

Regards,
Pierre

Signature · 3 lines
Thanks,

David / dhildenb
#15 lore raw

Re: [PATCH v2 3/5] KVM: s390: vsie: Allow support for a host without AP

Quoted 60 lines · David Hildenbrand
Quoted 44 lines · Pierre Morel
Quoted 35 lines · David Hildenbrand
Quoted 34 lines · Pierre Morel

Currently the CRYCB format used in the host for the shadowed CRYCB is FORMAT2 while no check is done if AP instructions are supported in the host.

We better use the format the host calculated for the guest 1 as the host already tested it against its facility set.

---
   arch/s390/kvm/vsie.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)
arch/s390/kvm/vsie.c +3 -2
index 56a9d47..0b12916 100644
@@ -154,6 +154,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
   	const u32 crycb_addr = crycbd_o & 0x7ffffff8U;
   	unsigned long *b1, *b2;
   	u8 ecb3_flags;
+	unsigned long g1_fmt;
 
   	scb_s->crycbd = 0;
   	if (!(crycbd_o == CRYCB_FORMAT1))
@@ -180,8 +181,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
   		return set_validity_icpt(scb_s, 0x0035U);
 
   	scb_s->ecb3 |= ecb3_flags;
-	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT1 |
-			CRYCB_FORMAT2;
+	g1_fmt = vcpu->arch.sie_block->crycbd & 0x03;
+	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | g1_fmt;
 
Quoted 7 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 188

Quoted 3 lines
arch/s390/kvm/vsie.c +0 -0
   	/* xor both blocks in one run */
   	b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;

This is wrong. I remember that with APXA, if FORMAT2 is available, we should always use FORMAT2. That's why we explicitly convert it here.

Quoted 7 lines

You are right if FORMAT2 is available we should use FORMAT2 but the intention here is to use what KVM crypto init function did, assuming it did the right thing.

Eventually we are running on a host without AP and we should use FORMAT1.

Isn't it correct?

Yes and no :)

No APXA -> FORMAT2 bit is ignored (and that is one of the reasons why I am being so strict about simulating HW behavior correctly in nested code :) )

Quoted 7 lines

This only holds as long as we are not using AP. Because from a MSA3 perspective, FORMAT1==FORMAT2 (apart from the length/alignment, which is fine for us).

Once we support AP (via ECA.28), we'll properly have to create either a Format0/Format1/Format2. Then, there is actually a semantically difference ("different fields used").

OK
I would have expect something more explicit in the documentation like for firmware versions older than xxx bit 30 is ignored instead of if APXA is not installed.
Still must learn the IBM language! :)

regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#16 lore raw

Re: [PATCH v2 3/5] KVM: s390: vsie: Allow support for a host without AP

In reply to David Hildenbrand
Quoted 35 lines · David Hildenbrand
Quoted 34 lines · Pierre Morel

Currently the CRYCB format used in the host for the shadowed CRYCB is FORMAT2 while no check is done if AP instructions are supported in the host.

We better use the format the host calculated for the guest 1 as the host already tested it against its facility set.

---
  arch/s390/kvm/vsie.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
arch/s390/kvm/vsie.c +3 -2
index 56a9d47..0b12916 100644
@@ -154,6 +154,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  	const u32 crycb_addr = crycbd_o & 0x7ffffff8U;
  	unsigned long *b1, *b2;
  	u8 ecb3_flags;
+	unsigned long g1_fmt;
 
  	scb_s->crycbd = 0;
  	if (!(crycbd_o == CRYCB_FORMAT1))
@@ -180,8 +181,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  		return set_validity_icpt(scb_s, 0x0035U);
 
  	scb_s->ecb3 |= ecb3_flags;
-	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT1 |
-			CRYCB_FORMAT2;
+	g1_fmt = vcpu->arch.sie_block->crycbd & 0x03;
+	scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | g1_fmt;
 
Quoted 7 lines

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 188

Quoted 3 lines
arch/s390/kvm/vsie.c +0 -0
  	/* xor both blocks in one run */
  	b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;

This is wrong. I remember that with APXA, if FORMAT2 is available, we should always use FORMAT2. That's why we explicitly convert it here.

You are right if FORMAT2 is available we should use FORMAT2 but the intention here is to use what KVM crypto init function did, assuming it did the right thing.

Eventually we are running on a host without AP and we should use FORMAT1.

Isn't it correct?

Regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#17 lore raw

PATCH v2 4/5 KVM: s390: vsie: Always test the crycbd for NULL

In reply to Pierre Morel
BUG: the crycbd must be tested for null even if

not crossing a page boundary (which will never
occur in this case anyway).

---
 arch/s390/kvm/vsie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/vsie.c +1 -1
index 0b12916..7ee4329 100644
@@ -172,7 +172,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 
 	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
 		return set_validity_icpt(scb_s, 0x003CU);
-	else if (!crycb_addr)
+	if (!crycb_addr)
 		return set_validity_icpt(scb_s, 0x0039U);
 
 	/* copy only the wrapping keys */
Signature · 1 line
2.7.4
#18 lore raw

Re: [PATCH v2 4/5] KVM: s390: vsie: Always test the crycbd for NULL

Quoted 3 lines · Pierre Morel
BUG: the crycbd must be tested for null even if

not crossing a page boundary (which will never
occur in this case anyway).

I don't see the BUG. Can you elaborate? (maybe it is too late for me)

Either we return or we check for !crycb_addr

Quoted 20 lines
---
 arch/s390/kvm/vsie.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/vsie.c +1 -1
index 0b12916..7ee4329 100644
@@ -172,7 +172,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 
 	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
 		return set_validity_icpt(scb_s, 0x003CU);
-	else if (!crycb_addr)
+	if (!crycb_addr)
 		return set_validity_icpt(scb_s, 0x0039U);
 
 	/* copy only the wrapping keys */
Signature · 3 lines
Thanks,

David / dhildenb
#19 lore raw

Re: [PATCH v2 4/5] KVM: s390: vsie: Always test the crycbd for NULL

Quoted 6 lines · David Hildenbrand
Quoted 3 lines · Pierre Morel
BUG: the crycbd must be tested for null even if

not crossing a page boundary (which will never
occur in this case anyway).

I don't see the BUG. Can you elaborate? (maybe it is too late for me)

No it was too late for me :)
The BUG was by me, my brain was fooled by the "else" there is not problem there.
CRCBD is always tested.

Sorry.

Quoted 25 lines

Either we return or we check for !crycb_addr

Quoted 20 lines
---
  arch/s390/kvm/vsie.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/vsie.c +1 -1
index 0b12916..7ee4329 100644
@@ -172,7 +172,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 
  	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
  		return set_validity_icpt(scb_s, 0x003CU);
-	else if (!crycb_addr)
+	if (!crycb_addr)
  		return set_validity_icpt(scb_s, 0x0039U);
 
  	/* copy only the wrapping keys */
Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#20 lore raw

PATCH v2 5/5 KVM: s390: vsie: Do the CRYCB validation first

In reply to Pierre Morel

When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.

---
 arch/s390/kvm/vsie.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/s390/kvm/vsie.c +6 -5
index 7ee4329..fca25aa 100644
@@ -164,17 +164,18 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	/* format-1 is supported with message-security-assist extension 3 */
 	if (!test_kvm_facility(vcpu->kvm, 76))
 		return 0;
-	/* we may only allow it if enabled for guest 2 */
-	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
-		     (ECB3_AES | ECB3_DEA);
-	if (!ecb3_flags)
-		return 0;
 
 	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
 		return set_validity_icpt(scb_s, 0x003CU);
 	if (!crycb_addr)
 		return set_validity_icpt(scb_s, 0x0039U);
 
+	/* we may only allow it if enabled for guest 2 */
+	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
+		     (ECB3_AES | ECB3_DEA);
+	if (!ecb3_flags)
+		return 0;
+
 	/* copy only the wrapping keys */
 	if (read_guest_real(vcpu, crycb_addr + 72,
 			    vsie_page->crycb.dea_wrapping_key_mask, 56))
Signature · 1 line
2.7.4
#21 lore raw

Re: [PATCH v2 5/5] KVM: s390: vsie: Do the CRYCB validation first

Quoted 28 lines · Pierre Morel

When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.

---
 arch/s390/kvm/vsie.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
arch/s390/kvm/vsie.c +0 -5
index 7ee4329..fca25aa 100644
@@ -164,17 +164,18 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	/* format-1 is supported with message-security-assist extension 3 */
 	if (!test_kvm_facility(vcpu->kvm, 76))
 		return 0;
-	/* we may only allow it if enabled for guest 2 */
-	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
-		     (ECB3_AES | ECB3_DEA);
-	if (!ecb3_flags)
-		return 0;
 
 	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
 		return set_validity_icpt(scb_s, 0x003CU);
 	if (!crycb_addr)
 		return set_validity_icpt(scb_s, 0x0039U);

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 181

Quoted 10 lines
arch/s390/kvm/vsie.c +6 -0
 
+	/* we may only allow it if enabled for guest 2 */
+	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
+		     (ECB3_AES | ECB3_DEA);
+	if (!ecb3_flags)
+		return 0;
+
 	/* copy only the wrapping keys */
 	if (read_guest_real(vcpu, crycb_addr + 72,
 			    vsie_page->crycb.dea_wrapping_key_mask, 56))

That makes sense, especially if ECB3_AES is used but effectively turned off by us.

What is the expected behavior if ECB3_AES | ECB3_DEA are not set by g2 for g3?

Signature · 3 lines
Thanks,

David / dhildenb
#22 lore raw

Re: [PATCH v2 5/5] KVM: s390: vsie: Do the CRYCB validation first

Quoted 43 lines · David Hildenbrand
Quoted 28 lines · Pierre Morel

When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.

---
  arch/s390/kvm/vsie.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
arch/s390/kvm/vsie.c +0 -5
index 7ee4329..fca25aa 100644
@@ -164,17 +164,18 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  	/* format-1 is supported with message-security-assist extension 3 */
  	if (!test_kvm_facility(vcpu->kvm, 76))
  		return 0;
-	/* we may only allow it if enabled for guest 2 */
-	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
-		     (ECB3_AES | ECB3_DEA);
-	if (!ecb3_flags)
-		return 0;
 
  	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
  		return set_validity_icpt(scb_s, 0x003CU);
  	if (!crycb_addr)
  		return set_validity_icpt(scb_s, 0x0039U);

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 181

Quoted 10 lines
arch/s390/kvm/vsie.c +6 -0
 
+	/* we may only allow it if enabled for guest 2 */
+	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
+		     (ECB3_AES | ECB3_DEA);
+	if (!ecb3_flags)
+		return 0;
+
  	/* copy only the wrapping keys */
  	if (read_guest_real(vcpu, crycb_addr + 72,
  			    vsie_page->crycb.dea_wrapping_key_mask, 56))

That makes sense, especially if ECB3_AES is used but effectively turned off by us.

Quoted 3 lines

What is the expected behavior if ECB3_AES | ECB3_DEA are not set by g2 for g3?

The use of functions PCKMO-Encrypt-DEA/AES induce a specification error.

However other MSA3 function will continue to be usable.

Regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#23 lore raw

Re: [PATCH v2 5/5] KVM: s390: vsie: Do the CRYCB validation first

Quoted 44 lines · Pierre Morel
Quoted 43 lines · David Hildenbrand
Quoted 28 lines · Pierre Morel

When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.

---
  arch/s390/kvm/vsie.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
arch/s390/kvm/vsie.c +0 -5
index 7ee4329..fca25aa 100644
@@ -164,17 +164,18 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
  	/* format-1 is supported with message-security-assist extension 3 */
  	if (!test_kvm_facility(vcpu->kvm, 76))
  		return 0;
-	/* we may only allow it if enabled for guest 2 */
-	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
-		     (ECB3_AES | ECB3_DEA);
-	if (!ecb3_flags)
-		return 0;
 
  	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
  		return set_validity_icpt(scb_s, 0x003CU);
  	if (!crycb_addr)
  		return set_validity_icpt(scb_s, 0x0039U);

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 181

Quoted 10 lines
arch/s390/kvm/vsie.c +6 -0
 
+	/* we may only allow it if enabled for guest 2 */
+	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
+		     (ECB3_AES | ECB3_DEA);
+	if (!ecb3_flags)
+		return 0;
+
  	/* copy only the wrapping keys */
  	if (read_guest_real(vcpu, crycb_addr + 72,
  			    vsie_page->crycb.dea_wrapping_key_mask, 56))

That makes sense, especially if ECB3_AES is used but effectively turned off by us.

Quoted 7 lines
Quoted 3 lines

What is the expected behavior if ECB3_AES | ECB3_DEA are not set by g2 for g3?

The use of functions PCKMO-Encrypt-DEA/AES induce a specification error.

However other MSA3 function will continue to be usable.

No, I meant which checks should be performed here.

Quoted 4 lines

Regards,
Pierre

Signature · 3 lines
Thanks,

David / dhildenb
#24 lore raw

Re: [PATCH v2 5/5] KVM: s390: vsie: Do the CRYCB validation first

Quoted 49 lines · David Hildenbrand
Quoted 48 lines · Pierre Morel
Quoted 46 lines · David Hildenbrand
Quoted 28 lines · Pierre Morel

When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.

---
   arch/s390/kvm/vsie.c | 11 ++++++-----
   1 file changed, 6 insertions(+), 5 deletions(-)
arch/s390/kvm/vsie.c +0 -5
index 7ee4329..fca25aa 100644
@@ -164,17 +164,18 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
   	/* format-1 is supported with message-security-assist extension 3 */
   	if (!test_kvm_facility(vcpu->kvm, 76))
   		return 0;
-	/* we may only allow it if enabled for guest 2 */
-	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
-		     (ECB3_AES | ECB3_DEA);
-	if (!ecb3_flags)
-		return 0;
 
   	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
   		return set_validity_icpt(scb_s, 0x003CU);
   	if (!crycb_addr)
   		return set_validity_icpt(scb_s, 0x0039U);

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 181

Quoted 10 lines
arch/s390/kvm/vsie.c +6 -0
 
+	/* we may only allow it if enabled for guest 2 */
+	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
+		     (ECB3_AES | ECB3_DEA);
+	if (!ecb3_flags)
+		return 0;
+
   	/* copy only the wrapping keys */
   	if (read_guest_real(vcpu, crycb_addr + 72,
   			    vsie_page->crycb.dea_wrapping_key_mask, 56))

That makes sense, especially if ECB3_AES is used but effectively turned off by us.

What is the expected behavior if ECB3_AES | ECB3_DEA are not set by g2 for g3?

Quoted 5 lines
Quoted 3 lines

The use of functions PCKMO-Encrypt-DEA/AES induce a specification error.

However other MSA3 function will continue to be usable.

No, I meant which checks should be performed here.

The SIE should check the validity of the CRYCB.

However since we do not copy the key masks we do not expect any access error on crycb_o

So it is more a philosophical problem, should the hypervizor enforce an error here to act as the firmware?

regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
maintainer
#25 lore raw

Re: [PATCH v2 5/5] KVM: s390: vsie: Do the CRYCB validation first

Quoted 56 lines · Pierre Morel
Quoted 49 lines · David Hildenbrand
Quoted 48 lines · Pierre Morel
Quoted 46 lines · David Hildenbrand
Quoted 28 lines · Pierre Morel

When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.

---
   arch/s390/kvm/vsie.c | 11 ++++++-----
   1 file changed, 6 insertions(+), 5 deletions(-)
arch/s390/kvm/vsie.c +0 -5
index 7ee4329..fca25aa 100644
@@ -164,17 +164,18 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
   	/* format-1 is supported with message-security-assist extension 3 */
   	if (!test_kvm_facility(vcpu->kvm, 76))
   		return 0;
-	/* we may only allow it if enabled for guest 2 */
-	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
-		     (ECB3_AES | ECB3_DEA);
-	if (!ecb3_flags)
-		return 0;
 
   	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
   		return set_validity_icpt(scb_s, 0x003CU);
   	if (!crycb_addr)
   		return set_validity_icpt(scb_s, 0x0039U);

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 181

Quoted 10 lines
arch/s390/kvm/vsie.c +6 -0
 
+	/* we may only allow it if enabled for guest 2 */
+	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
+		     (ECB3_AES | ECB3_DEA);
+	if (!ecb3_flags)
+		return 0;
+
   	/* copy only the wrapping keys */
   	if (read_guest_real(vcpu, crycb_addr + 72,
   			    vsie_page->crycb.dea_wrapping_key_mask, 56))

That makes sense, especially if ECB3_AES is used but effectively turned off by us.

What is the expected behavior if ECB3_AES | ECB3_DEA are not set by g2 for g3?

Quoted 5 lines
Quoted 3 lines

The use of functions PCKMO-Encrypt-DEA/AES induce a specification error.

However other MSA3 function will continue to be usable.

No, I meant which checks should be performed here.

Quoted 7 lines

The SIE should check the validity of the CRYCB.

However since we do not copy the key masks we do not expect any access error on crycb_o

So it is more a philosophical problem, should the hypervizor enforce an error here to act as the firmware?

No it's not philosophical, that's actually regulated in the SIE documentation for the validity intercepts.

CRYCB is checked if (any of these is true): ECA.28, CRYCB Format is one, APXA installed and CRYCB Format field is three.

ECB3 AES/DEA bits are handled like the matrix, i.e. they are ANDed over the different levels.

If that's still not what David meant to ask, then I must apologize for my caffeine deprived brain.

Quoted 7 lines

regards,
Pierre

#26 lore raw

Re: [PATCH v2 5/5] KVM: s390: vsie: Do the CRYCB validation first

Quoted 62 lines · Janosch Frank
Quoted 61 lines · Pierre Morel
Quoted 49 lines · David Hildenbrand
Quoted 48 lines · Pierre Morel
Quoted 46 lines · David Hildenbrand
Quoted 28 lines · Pierre Morel

When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.

---
   arch/s390/kvm/vsie.c | 11 ++++++-----
   1 file changed, 6 insertions(+), 5 deletions(-)
arch/s390/kvm/vsie.c +0 -5
index 7ee4329..fca25aa 100644
@@ -164,17 +164,18 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
   	/* format-1 is supported with message-security-assist extension 3 */
   	if (!test_kvm_facility(vcpu->kvm, 76))
   		return 0;
-	/* we may only allow it if enabled for guest 2 */
-	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
-		     (ECB3_AES | ECB3_DEA);
-	if (!ecb3_flags)
-		return 0;
 
   	if ((crycb_addr & PAGE_MASK) != ((crycb_addr + 128) & PAGE_MASK))
   		return set_validity_icpt(scb_s, 0x003CU);
   	if (!crycb_addr)
   		return set_validity_icpt(scb_s, 0x0039U);

arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 181

Quoted 10 lines
arch/s390/kvm/vsie.c +6 -0
 
+	/* we may only allow it if enabled for guest 2 */
+	ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
+		     (ECB3_AES | ECB3_DEA);
+	if (!ecb3_flags)
+		return 0;
+
   	/* copy only the wrapping keys */
   	if (read_guest_real(vcpu, crycb_addr + 72,
   			    vsie_page->crycb.dea_wrapping_key_mask, 56))

That makes sense, especially if ECB3_AES is used but effectively turned off by us.

What is the expected behavior if ECB3_AES | ECB3_DEA are not set by g2 for g3?

Quoted 5 lines
Quoted 3 lines

The use of functions PCKMO-Encrypt-DEA/AES induce a specification error.

However other MSA3 function will continue to be usable.

No, I meant which checks should be performed here.

The SIE should check the validity of the CRYCB.

However since we do not copy the key masks we do not expect any access error on crycb_o

Quoted 8 lines
Quoted 2 lines

So it is more a philosophical problem, should the hypervizor enforce an error here to act as the firmware?

No it's not philosophical, that's actually regulated in the SIE documentation for the validity intercepts.

CRYCB is checked if (any of these is true): ECA.28, CRYCB Format is one, APXA installed and CRYCB Format field is three.

So independent of setting of ECB3 AES/DEA by g2. That's what I wanted to know, thanks :)

Quoted 6 lines

ECB3 AES/DEA bits are handled like the matrix, i.e. they are ANDed over the different levels.

If that's still not what David meant to ask, then I must apologize for my caffeine deprived brain.

Signature · 3 lines
Thanks,

David / dhildenb