Skip to content

Commit 37940fb

Browse files
Tony Krowiakborntraeger
authored andcommitted
KVM: s390: device attrs to enable/disable AP interpretation
Introduces two new VM crypto device attributes (KVM_S390_VM_CRYPTO) to enable or disable AP instruction interpretation from userspace via the KVM_SET_DEVICE_ATTR ioctl: * The KVM_S390_VM_CRYPTO_ENABLE_APIE attribute enables hardware interpretation of AP instructions executed on the guest. * The KVM_S390_VM_CRYPTO_DISABLE_APIE attribute disables hardware interpretation of AP instructions executed on the guest. In this case the instructions will be intercepted and pass through to the guest. Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Message-Id: <20180925231641.4954-25-akrowiak@linux.vnet.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
1 parent 9ee71f2 commit 37940fb

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

arch/s390/include/uapi/asm/kvm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ struct kvm_s390_vm_cpu_subfunc {
160160
#define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW 1
161161
#define KVM_S390_VM_CRYPTO_DISABLE_AES_KW 2
162162
#define KVM_S390_VM_CRYPTO_DISABLE_DEA_KW 3
163+
#define KVM_S390_VM_CRYPTO_ENABLE_APIE 4
164+
#define KVM_S390_VM_CRYPTO_DISABLE_APIE 5
163165

164166
/* kvm attributes for migration mode */
165167
#define KVM_S390_VM_MIGRATION_STOP 0

arch/s390/kvm/kvm-s390.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,37 +856,56 @@ void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm)
856856

857857
static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr)
858858
{
859-
if (!test_kvm_facility(kvm, 76))
860-
return -EINVAL;
861-
862859
mutex_lock(&kvm->lock);
863860
switch (attr->attr) {
864861
case KVM_S390_VM_CRYPTO_ENABLE_AES_KW:
862+
if (!test_kvm_facility(kvm, 76))
863+
return -EINVAL;
865864
get_random_bytes(
866865
kvm->arch.crypto.crycb->aes_wrapping_key_mask,
867866
sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask));
868867
kvm->arch.crypto.aes_kw = 1;
869868
VM_EVENT(kvm, 3, "%s", "ENABLE: AES keywrapping support");
870869
break;
871870
case KVM_S390_VM_CRYPTO_ENABLE_DEA_KW:
871+
if (!test_kvm_facility(kvm, 76))
872+
return -EINVAL;
872873
get_random_bytes(
873874
kvm->arch.crypto.crycb->dea_wrapping_key_mask,
874875
sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask));
875876
kvm->arch.crypto.dea_kw = 1;
876877
VM_EVENT(kvm, 3, "%s", "ENABLE: DEA keywrapping support");
877878
break;
878879
case KVM_S390_VM_CRYPTO_DISABLE_AES_KW:
880+
if (!test_kvm_facility(kvm, 76))
881+
return -EINVAL;
879882
kvm->arch.crypto.aes_kw = 0;
880883
memset(kvm->arch.crypto.crycb->aes_wrapping_key_mask, 0,
881884
sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask));
882885
VM_EVENT(kvm, 3, "%s", "DISABLE: AES keywrapping support");
883886
break;
884887
case KVM_S390_VM_CRYPTO_DISABLE_DEA_KW:
888+
if (!test_kvm_facility(kvm, 76))
889+
return -EINVAL;
885890
kvm->arch.crypto.dea_kw = 0;
886891
memset(kvm->arch.crypto.crycb->dea_wrapping_key_mask, 0,
887892
sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask));
888893
VM_EVENT(kvm, 3, "%s", "DISABLE: DEA keywrapping support");
889894
break;
895+
case KVM_S390_VM_CRYPTO_ENABLE_APIE:
896+
if (!ap_instructions_available()) {
897+
mutex_unlock(&kvm->lock);
898+
return -EOPNOTSUPP;
899+
}
900+
kvm->arch.crypto.apie = 1;
901+
break;
902+
case KVM_S390_VM_CRYPTO_DISABLE_APIE:
903+
if (!ap_instructions_available()) {
904+
mutex_unlock(&kvm->lock);
905+
return -EOPNOTSUPP;
906+
}
907+
kvm->arch.crypto.apie = 0;
908+
break;
890909
default:
891910
mutex_unlock(&kvm->lock);
892911
return -ENXIO;
@@ -1495,6 +1514,10 @@ static int kvm_s390_vm_has_attr(struct kvm *kvm, struct kvm_device_attr *attr)
14951514
case KVM_S390_VM_CRYPTO_DISABLE_DEA_KW:
14961515
ret = 0;
14971516
break;
1517+
case KVM_S390_VM_CRYPTO_ENABLE_APIE:
1518+
case KVM_S390_VM_CRYPTO_DISABLE_APIE:
1519+
ret = ap_instructions_available() ? 0 : -ENXIO;
1520+
break;
14981521
default:
14991522
ret = -ENXIO;
15001523
break;
@@ -2601,6 +2624,7 @@ static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
26012624

26022625
vcpu->arch.sie_block->crycbd = vcpu->kvm->arch.crypto.crycbd;
26032626
vcpu->arch.sie_block->ecb3 &= ~(ECB3_AES | ECB3_DEA);
2627+
vcpu->arch.sie_block->eca &= ~ECA_APIE;
26042628

26052629
if (vcpu->kvm->arch.crypto.apie)
26062630
vcpu->arch.sie_block->eca |= ECA_APIE;

0 commit comments

Comments
 (0)