]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
KVM: s390: reset crypto attributes for all vcpus
authorTony Krowiak <akrowiak@linux.vnet.ibm.com>
Sun, 22 Apr 2018 15:37:03 +0000 (11:37 -0400)
committerJoseph Salisbury <joseph.salisbury@canonical.com>
Thu, 15 Nov 2018 17:38:11 +0000 (12:38 -0500)
BugLink: https://bugs.launchpad.net/bugs/1787405
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>
(cherry picked from commit 20c922f04b17aa51a75e514eca8fcbfa337a002d)
Signed-off-by: Joseph Salisbury <joseph.salisbury@canonical.com>
Acked-by: Brad Figg <brad.figg@canonical.com>
Acked-by: Kamal Mostafa <kamal@canonical.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
arch/s390/kvm/kvm-s390.c
arch/s390/kvm/kvm-s390.h

index bc637fd34ec0d161092a0a39c02ea88f4c0c8a76..d432372bf6cce48992166d16944324ba7592825b 100644 (file)
@@ -768,11 +768,21 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att
 
 static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu);
 
-static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
+void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm)
 {
        struct kvm_vcpu *vcpu;
        int i;
 
+       kvm_s390_vcpu_block_all(kvm);
+
+       kvm_for_each_vcpu(i, vcpu, kvm)
+               kvm_s390_vcpu_crypto_setup(vcpu);
+
+       kvm_s390_vcpu_unblock_all(kvm);
+}
+
+static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
+{
        if (!test_kvm_facility(kvm, 76))
                return -EINVAL;
 
@@ -809,10 +819,7 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
                return -ENXIO;
        }
 
-       kvm_for_each_vcpu(i, vcpu, kvm) {
-               kvm_s390_vcpu_crypto_setup(vcpu);
-               exit_sie(vcpu);
-       }
+       kvm_s390_vcpu_crypto_reset_all(kvm);
        mutex_unlock(&kvm->lock);
        return 0;
 }
index 0f08873937d442318c590fb287865b5e77c50ddb..38c788c9a1c17e96522f0046ebf310dd71a836bf 100644 (file)
@@ -394,4 +394,17 @@ static inline int kvm_s390_use_sca_entries(void)
 }
 void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,
                                     struct mcck_volatile_info *mcck_info);
+
+/**
+ * kvm_s390_vcpu_crypto_reset_all
+ *
+ * Reset the crypto attributes for each vcpu. This can be done while the vcpus
+ * are running as each vcpu will be removed from SIE before resetting the crypt
+ * attributes and restored to SIE afterward.
+ *
+ * Note: The kvm->lock must be held while calling this function
+ *
+ * @kvm: the KVM guest
+ */
+void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm);
 #endif