KVM: s390: vsie: Consolidate CRYCB validation
v3 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.
First patch seem obvious.
Second patch introduce a change in the behavior of the virtual machine in that the CRYCB is validated whenever we use or not the key masks to mimic the real machine.
Patch 3 does not correct the compiled code but make more clear what is done concerning the formating of the CRYCB in the guest original CRYCB and in the shadow CRYCB.
Pierre Morel (3):
KVM: s390: vsie: copy wrapping keys to right place
KVM: s390: vsie: Do the CRYCB validation first
KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
arch/s390/kvm/vsie.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
Signature · 13 lines
2.7.4 Changelog from V2: - Suppress two useless/broken patches - Change a patch on CRYCB format to a modification of the comment - modified the first patch title as expected - added R-Bs 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
PATCH v3 1/3 KVM: s390: vsie: copy wrapping keys to right place
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
@@ -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
PATCH v3 2/3 KVM: s390: vsie: Do the CRYCB validation first
In reply to Pierre MorelWhen 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
@@ -161,17 +161,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 );else 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
PATCH v3 3/3 KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
In reply to Pierre MorelThe comment preceding the shadow_crycb function is misleading, we effectively accept FORMAT2 CRYCB in the guest.
When using FORMAT2 in the host we do not need to or with FORMAT1.
--- arch/s390/kvm/vsie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/s390/kvm/vsie.c +3 -3
@@ -140,7 +140,8 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)* Create a shadow copy of the crycb block and setup key wrapping, if * requested for guest 3 and enabled for guest 2. * -* We only accept format-1 (no AP in g2), but convert it into format-2 +* We accept format-1 or format-2, but we treat it as a format-1 (no AP in g2), +* and we convert it into format-2 in the shadow CRYCB. * There is nothing to do for format-0. * * Returns: - 0 if shadowed or nothing to do
@@ -179,8 +180,7 @@ 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 ; + scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT2 ;/* xor both blocks in one run */ b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;
Signature · 1 line
2.7.4
Janosch Frank
maintainerRe: [PATCH v3 3/3] KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
Quoted 3 lines · Pierre Morel
The comment preceding the
shadow_crycbfunction is misleading, we effectively accept FORMAT2 CRYCB in the guest.
I beg to differ:
if (!(crycbd_o & vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1))
return 0;
Quoted 24 lines
When using FORMAT2 in the host we do not need to or with FORMAT1.
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/kvm/vsie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/s390/kvm/vsie.c +2
-1@@ -140,7 +140,8 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)* Create a shadow copy of the crycb block and setup key wrapping, if * requested for guest 3 and enabled for guest 2. * -* We only accept format-1 (no AP in g2), but convert it into format-2 +* We accept format-1 or format-2, but we treat it as a format-1 (no AP in g2), +* and we convert it into format-2 in the shadow CRYCB. * There is nothing to do for format-0. * * Returns: - 0 if shadowed or nothing to do
arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 183
Quoted 6 lines
arch/s390/kvm/vsie.c +1
-2@@ -179,8 +180,7 @@ 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 ; + scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT2 ;
That's purely cosmetic but valid.
Quoted 4 lines
arch/s390/kvm/vsie.c +0
-0/* xor both blocks in one run */ b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;
Re: [PATCH v3 1/3] KVM: s390: vsie: copy wrapping keys to right place
In reply to Pierre MorelQuoted 6 lines · Pierre Morel
Copy the key mask to the right offset inside the shadow CRYCB
Signed-off-by Pierre Morel <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Janosch Frank <[email protected]>
This should be cc stable I guess?
Quoted 19 lines
--- arch/s390/kvm/vsie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)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;
Re: [PATCH v3 2/3] KVM: s390: vsie: Do the CRYCB validation first
In reply to Pierre MorelQuoted 3 lines · Pierre Morel
When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.
Maybe something like
We need to handle the validity checks for the crycb, no matter what the settings for the keywrappings are. So lets move the keywrapping checks after we have done the validy checks.
?
Quoted 35 lines
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/kvm/vsie.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)arch/s390/kvm/vsie.c +6
-5@@ -161,17 +161,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 );else 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 ))
David Hildenbrand
Reviewed-byRe: [PATCH v3 2/3] KVM: s390: vsie: Do the CRYCB validation first
Quoted 7 lines · Christian Borntraeger
Quoted 3 lines · Pierre Morel
When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.
Quoted 7 lines
Maybe something like
We need to handle the validity checks for the crycb, no matter what the settings for the keywrappings are. So lets move the keywrapping checks after we have done the validy checks.
?
With that
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v3 1/3] KVM: s390: vsie: copy wrapping keys to right place
In reply to Christian BorntraegerQuoted 12 lines · Christian Borntraeger
Quoted 6 lines · Pierre Morel
Copy the key mask to the right offset inside the shadow CRYCB
Signed-off-by Pierre Morel <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Janosch Frank <[email protected]>This should be cc stable I guess?
Yes, g3 guests will be run with same wrapping keys.
Signature · 3 lines
Thanks, David / dhildenb
David Hildenbrand
Reviewed-byRe: [PATCH v3 3/3] KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
In reply to Janosch FrankQuoted 9 lines · Janosch Frank
Quoted 3 lines · Pierre Morel
The comment preceding the
shadow_crycbfunction is misleading, we effectively accept FORMAT2 CRYCB in the guest.I beg to differ:
if (!(crycbd_o &
vcpu->arch.sie_block->crycbd&CRYCB_FORMAT1))return 0;
FORMAT2 includes bit FORMAT1 (backwards compatible)
Quoted 27 lines
Quoted 27 lines
When using FORMAT2 in the host we do not need to or with FORMAT1.
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/kvm/vsie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/s390/kvm/vsie.c +2
-1@@ -140,7 +140,8 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)* Create a shadow copy of the crycb block and setup key wrapping, if * requested for guest 3 and enabled for guest 2. * -* We only accept format-1 (no AP in g2), but convert it into format-2 +* We accept format-1 or format-2, but we treat it as a format-1 (no AP in g2), +* and we convert it into format-2 in the shadow CRYCB. * There is nothing to do for format-0. * * Returns: - 0 if shadowed or nothing to do @@ -179,8 +180,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)return set_validity_icpt (scb_s,0x0035U );
Quoted 10 lines
arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 183
Quoted 4 lines
arch/s390/kvm/vsie.c +1
-2scb_s->ecb3 |= ecb3_flags; - scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT1 | -CRYCB_FORMAT2 ; + scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT2 ;That's purely cosmetic but valid.
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;
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v3 3/3] KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
Quoted 6 lines · David Hildenbrand
Quoted 5 lines · Janosch Frank
Quoted 3 lines · Pierre Morel
The comment preceding the
shadow_crycbfunction is misleading, we effectively accept FORMAT2 CRYCB in the guest.
Quoted 6 lines
Quoted 4 lines
I beg to differ:
if (!(crycbd_o &
vcpu->arch.sie_block->crycbd&CRYCB_FORMAT1))return 0;FORMAT2 includes bit FORMAT1 (backwards compatible)
Right, this check is very misleading because of the constant, we effectively test against Format 0 and Format 2.
Can we make this clearer by explicitly ANDing 0x01 or adding a comment?
Code makes sense:
Quoted 41 lines
Quoted 28 lines
Quoted 28 lines
When using FORMAT2 in the host we do not need to or with FORMAT1.
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/kvm/vsie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/s390/kvm/vsie.c +2
-1@@ -140,7 +140,8 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)* Create a shadow copy of the crycb block and setup key wrapping, if * requested for guest 3 and enabled for guest 2. * -* We only accept format-1 (no AP in g2), but convert it into format-2 +* We accept format-1 or format-2, but we treat it as a format-1 (no AP in g2), +* and we convert it into format-2 in the shadow CRYCB. * There is nothing to do for format-0. * * Returns: - 0 if shadowed or nothing to do @@ -179,8 +180,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)return set_validity_icpt (scb_s,0x0035U );Quoted 10 lines
arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 183
Quoted 4 lines
arch/s390/kvm/vsie.c +1
-2scb_s->ecb3 |= ecb3_flags; - scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT1 | -CRYCB_FORMAT2 ; + scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT2 ;That's purely cosmetic but valid.
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;Reviewed-by David Hildenbrand <[email protected]>
Re: [PATCH v3 2/3] KVM: s390: vsie: Do the CRYCB validation first
In reply to Christian BorntraegerQuoted 7 lines · Christian Borntraeger
Quoted 3 lines · Pierre Morel
When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.
Quoted 7 lines
Maybe something like
We need to handle the validity checks for the crycb, no matter what the settings for the keywrappings are. So lets move the keywrapping checks after we have done the validy checks.
?
OK thanks, I use this.
regards,
Pierre
Quoted 36 lines
Quoted 36 lines
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/kvm/vsie.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)arch/s390/kvm/vsie.c +6
-5@@ -161,17 +161,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 );else 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 · 2 lines
Pierre Morel Linux/KVM/QEMU in Böblingen - Germany
Re: [PATCH v3 3/3] KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
In reply to David HildenbrandQuoted 48 lines · David Hildenbrand
Quoted 9 lines · Janosch Frank
Quoted 3 lines · Pierre Morel
The comment preceding the
shadow_crycbfunction is misleading, we effectively accept FORMAT2 CRYCB in the guest.I beg to differ:
if (!(crycbd_o &
vcpu->arch.sie_block->crycbd&CRYCB_FORMAT1))return 0;FORMAT2 includes bit FORMAT1 (backwards compatible)
Quoted 35 lines
Quoted 25 lines
When using FORMAT2 in the host we do not need to or with FORMAT1.
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/kvm/vsie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/s390/kvm/vsie.c +2
-1@@ -140,7 +140,8 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)* Create a shadow copy of the crycb block and setup key wrapping, if * requested for guest 3 and enabled for guest 2. * -* We only accept format-1 (no AP in g2), but convert it into format-2 +* We accept format-1 or format-2, but we treat it as a format-1 (no AP in g2), +* and we convert it into format-2 in the shadow CRYCB. * There is nothing to do for format-0. * * Returns: - 0 if shadowed or nothing to do arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 183
Quoted 6 lines
arch/s390/kvm/vsie.c +1
-2@@ -179,8 +180,7 @@ 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 ; + scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT2 ;That's purely cosmetic but valid.
Quoted 1 line
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
/* xor both blocks in one run */
b1 = (unsigned long *)vsie_page->crycb.dea_wrapping_key_mask;Reviewed-by David Hildenbrand <[email protected]>
Thanks,
regards,
Pierre
Signature · 2 lines
Pierre Morel Linux/KVM/QEMU in Böblingen - Germany
Re: [PATCH v3 1/3] KVM: s390: vsie: copy wrapping keys to right place
In reply to David HildenbrandQuoted 11 lines · David Hildenbrand
Quoted 10 lines · Christian Borntraeger
Quoted 6 lines · Pierre Morel
Copy the key mask to the right offset inside the shadow CRYCB
Signed-off-by Pierre Morel <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Janosch Frank <[email protected]>
Quoted 5 lines
Quoted 2 lines
This should be cc stable I guess?
Yes, g3 guests will be run with same wrapping keys.
OK I do send it separated from the other patches.
regard,
Pierre
Signature · 2 lines
Pierre Morel Linux/KVM/QEMU in Böblingen - Germany
Re: [PATCH v3 2/3] KVM: s390: vsie: Do the CRYCB validation first
In reply to David HildenbrandQuoted 14 lines · David Hildenbrand
Quoted 13 lines · Christian Borntraeger
Quoted 3 lines · Pierre Morel
When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.Maybe something like
We need to handle the validity checks for the crycb, no matter what the settings for the keywrappings are. So lets move the keywrapping checks after we have done the validy checks.
Quoted 7 lines
Quoted 1 line
?
With that
Reviewed-by David Hildenbrand <[email protected]>
Thanks, I use the description proposed by Christian.
regards,
Pierre
Signature · 2 lines
Pierre Morel Linux/KVM/QEMU in Böblingen - Germany
Re: [PATCH v3 3/3] KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
In reply to Janosch FrankQuoted 12 lines · Janosch Frank
Quoted 11 lines · David Hildenbrand
Quoted 9 lines · Janosch Frank
Quoted 3 lines · Pierre Morel
The comment preceding the
shadow_crycbfunction is misleading, we effectively accept FORMAT2 CRYCB in the guest.I beg to differ:
if (!(crycbd_o &
vcpu->arch.sie_block->crycbd&CRYCB_FORMAT1))return 0;
Quoted 6 lines
Quoted 1 line
FORMAT2 includes bit FORMAT1 (backwards compatible)
Right, this check is very misleading because of the constant, we effectively test against Format 0 and Format 2.
Can we make this clearer by explicitly ANDing
0x01or adding a comment?
yes, done, I modified the comment in front of the function.
Quoted 3 lines
Code makes sense:
Reviewed-by Janosch Frank <[email protected]>
Thanks,
regards,
Pierre
Quoted 44 lines
Quoted 42 lines
Quoted 29 lines
Quoted 29 lines
When using FORMAT2 in the host we do not need to or with FORMAT1.
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/kvm/vsie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/s390/kvm/vsie.c +2
-1@@ -140,7 +140,8 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)* Create a shadow copy of the crycb block and setup key wrapping, if * requested for guest 3 and enabled for guest 2. * -* We only accept format-1 (no AP in g2), but convert it into format-2 +* We accept format-1 or format-2, but we treat it as a format-1 (no AP in g2), +* and we convert it into format-2 in the shadow CRYCB. * There is nothing to do for format-0. * * Returns: - 0 if shadowed or nothing to do @@ -179,8 +180,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)return set_validity_icpt (scb_s,0x0035U );Quoted 10 lines
arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 183
Quoted 4 lines
arch/s390/kvm/vsie.c +1
-2scb_s->ecb3 |= ecb3_flags; - scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT1 | -CRYCB_FORMAT2 ; + scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT2 ;That's purely cosmetic but valid.
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;Reviewed-by David Hildenbrand <[email protected]>
Signature · 2 lines
Pierre Morel Linux/KVM/QEMU in Böblingen - Germany
Janosch Frank
maintainerRe: [PATCH v3 3/3] KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
Quoted 13 lines · Pierre Morel
Quoted 12 lines · Janosch Frank
Quoted 11 lines · David Hildenbrand
Quoted 9 lines · Janosch Frank
Quoted 3 lines · Pierre Morel
The comment preceding the
shadow_crycbfunction is misleading, we effectively accept FORMAT2 CRYCB in the guest.I beg to differ:
if (!(crycbd_o &
vcpu->arch.sie_block->crycbd&CRYCB_FORMAT1))return 0;
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
FORMAT2 includes bit FORMAT1 (backwards compatible)
Right, this check is very misleading because of the constant, we effectively test against Format 0 and Format 2.
Can we make this clearer by explicitly ANDing
0x01or adding a comment?yes, done, I modified the comment in front of the function.
Which is not what I want, what I want is:
/* CRYCB_FORMAT2 includes the bit for CRYCB_FORMAT1, so we allow both formats here */
if (!(crycbd_o & vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1))
return 0;
Quoted 56 lines
Quoted 4 lines
Code makes sense:
Reviewed-by Janosch Frank <[email protected]>Thanks,
regards,
PierreQuoted 44 lines
Quoted 42 lines
Quoted 29 lines
Quoted 29 lines
When using FORMAT2 in the host we do not need to or with FORMAT1.
Signed-off-by Pierre Morel <[email protected]>--- arch/s390/kvm/vsie.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/s390/kvm/vsie.c +2
-1@@ -140,7 +140,8 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)* Create a shadow copy of the crycb block and setup key wrapping, if * requested for guest 3 and enabled for guest 2. * -* We only accept format-1 (no AP in g2), but convert it into format-2 +* We accept format-1 or format-2, but we treat it as a format-1 (no AP in g2), +* and we convert it into format-2 in the shadow CRYCB. * There is nothing to do for format-0. * * Returns: - 0 if shadowed or nothing to do @@ -179,8 +180,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)return set_validity_icpt (scb_s,0x0035U );Quoted 10 lines
arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 183
Quoted 4 lines
arch/s390/kvm/vsie.c +1
-2scb_s->ecb3 |= ecb3_flags; - scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT1 | -CRYCB_FORMAT2 ; + scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) |CRYCB_FORMAT2 ;That's purely cosmetic but valid.
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;Reviewed-by David Hildenbrand <[email protected]>
Re: [PATCH v3 3/3] KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
Quoted 21 lines · Janosch Frank
Quoted 20 lines · Pierre Morel
Quoted 18 lines · Janosch Frank
Quoted 6 lines · David Hildenbrand
Quoted 5 lines · Janosch Frank
Quoted 3 lines · Pierre Morel
The comment preceding the
shadow_crycbfunction is misleading, we effectively accept FORMAT2 CRYCB in the guest.Quoted 6 lines
Quoted 4 lines
I beg to differ:
if (!(crycbd_o &
vcpu->arch.sie_block->crycbd&CRYCB_FORMAT1))return 0;FORMAT2 includes bit FORMAT1 (backwards compatible)
Right, this check is very misleading because of the constant, we effectively test against Format 0 and Format 2.
Can we make this clearer by explicitly ANDing
0x01or adding a comment?
Quoted 8 lines
Quoted 1 line
yes, done, I modified the comment in front of the function.
Which is not what I want, what I want is:
/*
CRYCB_FORMAT2includes the bit forCRYCB_FORMAT1, so we allow both formats here */
if (!(crycbd_o &vcpu->arch.sie_block->crycbd&CRYCB_FORMAT1))return 0;
While it's not wrong, it is also not required. And it might soon be obsolete again (with APXA, as you said, there we always have to check).
But I'll leave that to you
Signature · 3 lines
Thanks, David / dhildenb
Janosch Frank
maintainerRe: [PATCH v3 3/3] KVM: s390: vsie: Make use of CRYCB FORMAT2 clear
Quoted 31 lines · David Hildenbrand
Quoted 21 lines · Janosch Frank
Quoted 20 lines · Pierre Morel
Quoted 18 lines · Janosch Frank
Quoted 6 lines · David Hildenbrand
Quoted 5 lines · Janosch Frank
Quoted 3 lines · Pierre Morel
The comment preceding the
shadow_crycbfunction is misleading, we effectively accept FORMAT2 CRYCB in the guest.Quoted 6 lines
Quoted 4 lines
I beg to differ:
if (!(crycbd_o &
vcpu->arch.sie_block->crycbd&CRYCB_FORMAT1))return 0;FORMAT2 includes bit FORMAT1 (backwards compatible)
Right, this check is very misleading because of the constant, we effectively test against Format 0 and Format 2.
Can we make this clearer by explicitly ANDing
0x01or adding a comment?Quoted 8 lines
Quoted 1 line
yes, done, I modified the comment in front of the function.
Which is not what I want, what I want is:
/*
CRYCB_FORMAT2includes the bit forCRYCB_FORMAT1, so we allow both formats here */
if (!(crycbd_o &vcpu->arch.sie_block->crycbd&CRYCB_FORMAT1))return 0;
Quoted 5 lines
While it's not wrong, it is also not required. And it might soon be obsolete again (with APXA, as you said, there we always have to check).
But I'll leave that to you
I have not checked the vfio-ap patches, Pierre just told me that it goes away in a few weeks anyway, so let's leave it out.
Re: [PATCH v3 1/3] KVM: s390: vsie: copy wrapping keys to right place
In reply to Pierre MorelQuoted 12 lines · Pierre Morel
Quoted 11 lines · David Hildenbrand
Quoted 10 lines · Christian Borntraeger
Quoted 6 lines · Pierre Morel
Copy the key mask to the right offset inside the shadow CRYCB
Signed-off-by Pierre Morel <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Janosch Frank <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This should be cc stable I guess?
Yes, g3 guests will be run with same wrapping keys.
OK I do send it separated from the other patches.
No need to do that. I can add that when picking up.
Re: [PATCH v3 1/3] KVM: s390: vsie: copy wrapping keys to right place
Quoted 18 lines · Christian Borntraeger
Quoted 15 lines · Pierre Morel
Quoted 14 lines · David Hildenbrand
Quoted 12 lines · Christian Borntraeger
Quoted 6 lines · Pierre Morel
Copy the key mask to the right offset inside the shadow CRYCB
Signed-off-by Pierre Morel <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Janosch Frank <[email protected]>This should be cc stable I guess?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Yes, g3 guests will be run with same wrapping keys.
OK I do send it separated from the other patches.
No need to do that. I can add that when picking up.
OK
Thank
Pierre
Signature · 2 lines
Pierre Morel Linux/KVM/QEMU in Böblingen - Germany
Re: [PATCH v3 1/3] KVM: s390: vsie: copy wrapping keys to right place
In reply to Pierre MorelQuoted 15 lines · Pierre Morel
Copy the key mask to the right offset inside the shadow CRYCB
Signed-off-by Pierre Morel <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Janosch Frank <[email protected]>--- arch/s390/kvm/vsie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/s390/kvm/vsie.c +0
-0
arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 177
Quoted 6 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 ))
When we fix that code.., dont we have to XOR the guest3 wrapping keys with the guest2 ones?
Quoted 4 lines
arch/s390/kvm/vsie.c +0
-0return set_validity_icpt (scb_s,0x0035U ); scb_s->ecb3 |= ecb3_flags;
Re: [PATCH v3 1/3] KVM: s390: vsie: copy wrapping keys to right place
Quoted 20 lines · Christian Borntraeger
Quoted 17 lines · Pierre Morel
Copy the key mask to the right offset inside the shadow CRYCB
Signed-off-by Pierre Morel <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Janosch Frank <[email protected]>--- arch/s390/kvm/vsie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/s390/kvm/vsie.c +0
-0@@ -173,7 +173,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)return set_validity_icpt (scb_s,0x0039U );
Quoted 7 lines
arch/s390/kvm/vsie.c static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · line 177
Quoted 4 lines
arch/s390/kvm/vsie.c +2
-1/* 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 ))When we fix that code.., dont we have to XOR the guest3 wrapping keys with the guest2 ones?
That's done further down in that function.
Quoted 7 lines
Quoted 6 lines
arch/s390/kvm/vsie.c +0
-0return set_validity_icpt (scb_s,0x0035U ); scb_s->ecb3 |= ecb3_flags;
Signature · 3 lines
Thanks, David / dhildenb
Quoted 10 lines · Pierre Morel
Before adapting the CRYCB shadowing for a guest supporting the AP instructions we want to clean the CRYCB shadowing code.
First patch seem obvious.
Second patch introduce a change in the behavior of the virtual machine in that the CRYCB is validated whenever we use or not the key masks to mimic the real machine.
Quoted 5 lines
Patch 3 does not correct the compiled code but make more clear what is done concerning the formating of the CRYCB in the guest original CRYCB and in the shadow CRYCB.
Thanks, applied.
Re: [PATCH v3 2/3] KVM: s390: vsie: Do the CRYCB validation first
In reply to Pierre MorelQuoted 28 lines · Pierre Morel
When entering the SIE the CRYCB validation better
be done independently of the instruction's
availability.Signed-off-by Pierre Morel <[email protected]>--- arch/s390/kvm/vsie.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)arch/s390/kvm/vsie.c +0
-5@@ -161,17 +161,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 );else 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 178
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 ))
I seemed to have forgotten to add this while being preoccupied with the search for the validity discussion in #3.