aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Krowiak <akrowiak@linux.vnet.ibm.com>2018-04-22 11:37:03 -0400
committerChristian Borntraeger <borntraeger@de.ibm.com>2018-05-17 03:02:10 -0400
commit20c922f04b17aa51a75e514eca8fcbfa337a002d (patch)
tree8e5a5fe79974e39726be205edc1681f61f9db407
parent55531b7431db789766ac952391e95c170db48581 (diff)
KVM: s390: reset crypto attributes for all vcpus
Introduces a new function to reset the crypto attributes for all vcpus whether they are running or not. Each vcpu in KVM will be removed from SIE prior to resetting the crypto attributes in its SIE state description. After all vcpus have had their crypto attributes reset the vcpus will be restored to SIE. This function is incorporated into the kvm_s390_vm_set_crypto(kvm) function to fix a reported issue whereby the crypto key wrapping attributes could potentially get out of synch for running vcpus. Reviewed-by: Cornelia Huck <cohuck@redhat.com> Reported-by: Halil Pasic <pasic@linux.vnet.ibm.com> Signed-off-by: Tony Krowiak <akrowiak@linux.vnet.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
-rw-r--r--arch/s390/kvm/kvm-s390.c17
-rw-r--r--arch/s390/kvm/kvm-s390.h13
2 files changed, 25 insertions, 5 deletions
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 007db8faafa5..d9799946722e 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -791,11 +791,21 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att
791 791
792static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu); 792static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu);
793 793
794static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr) 794void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm)
795{ 795{
796 struct kvm_vcpu *vcpu; 796 struct kvm_vcpu *vcpu;
797 int i; 797 int i;
798 798
799 kvm_s390_vcpu_block_all(kvm);
800
801 kvm_for_each_vcpu(i, vcpu, kvm)
802 kvm_s390_vcpu_crypto_setup(vcpu);
803
804 kvm_s390_vcpu_unblock_all(kvm);
805}
806
807static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
808{
799 if (!test_kvm_facility(kvm, 76)) 809 if (!test_kvm_facility(kvm, 76))
800 return -EINVAL; 810 return -EINVAL;
801 811
@@ -832,10 +842,7 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
832 return -ENXIO; 842 return -ENXIO;
833 } 843 }
834 844
835 kvm_for_each_vcpu(i, vcpu, kvm) { 845 kvm_s390_vcpu_crypto_reset_all(kvm);
836 kvm_s390_vcpu_crypto_setup(vcpu);
837 exit_sie(vcpu);
838 }
839 mutex_unlock(&kvm->lock); 846 mutex_unlock(&kvm->lock);
840 return 0; 847 return 0;
841} 848}
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index 1b5621f4fe5b..981e3ba97461 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -410,4 +410,17 @@ static inline int kvm_s390_use_sca_entries(void)
410} 410}
411void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu, 411void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,
412 struct mcck_volatile_info *mcck_info); 412 struct mcck_volatile_info *mcck_info);
413
414/**
415 * kvm_s390_vcpu_crypto_reset_all
416 *
417 * Reset the crypto attributes for each vcpu. This can be done while the vcpus
418 * are running as each vcpu will be removed from SIE before resetting the crypt
419 * attributes and restored to SIE afterward.
420 *
421 * Note: The kvm->lock must be held while calling this function
422 *
423 * @kvm: the KVM guest
424 */
425void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm);
413#endif 426#endif