History

KVM: s390: enable MSA9 keywrapping functions depending on cpu model

Instead of adding a new machine option to disable/enable the keywrapping options of pckmo (like for AES and DEA) we can now use the CPU model to decide. As ECC is also wrapped with the AES key we need that to be enabled.

Christian Borntraeger committed 7 years ago

Commit 8ec2fa51 parent 4f45b903 files · +31 −2Browse files

Unified · Split

3 files
  1. arch/s390/include/asm/kvm_host.h +1 −0
  2. arch/s390/kvm/kvm-s390.c +26 −1
  3. arch/s390/kvm/vsie.c +4 −1
arch/s390/include/asm/kvm_host.h+1−0
@@ -278,6 +278,7 @@ struct kvm_s390_sie_block { · 277 unmodified lines
278278 #define ECD_HOSTREGMGMT 0x20000000
279279 #define ECD_MEF 0x08000000
280280 #define ECD_ETOKENF 0x02000000
281+#define ECD_ECC 0x00200000
281282 __u32 ecd; /* 0x01c8 */
282283 __u8 reserved1cc[18]; /* 0x01cc */
283284 __u64 pp; /* 0x01de */
arch/s390/kvm/kvm-s390.c+26−1
@@ -2890,6 +2890,25 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) · 2889 unmodified lines
28902890 vcpu->arch.enabled_gmap = vcpu->arch.gmap;
28912891 }
28922892
2893+static bool kvm_has_pckmo_subfunc(struct kvm *kvm, unsigned long nr)
2894+{
2895+ if (test_bit_inv(nr, (unsigned long *)&kvm->arch.model.subfuncs.pckmo) &&
2896+ test_bit_inv(nr, (unsigned long *)&kvm_s390_available_subfunc.pckmo))
2897+ return true;
2898+ return false;
2899+}
2900+
2901+static bool kvm_has_pckmo_ecc(struct kvm *kvm)
2902+{
2903+ /* At least one ECC subfunction must be present */
2904+ return kvm_has_pckmo_subfunc(kvm, 32) ||
2905+ kvm_has_pckmo_subfunc(kvm, 33) ||
2906+ kvm_has_pckmo_subfunc(kvm, 34) ||
2907+ kvm_has_pckmo_subfunc(kvm, 40) ||
2908+ kvm_has_pckmo_subfunc(kvm, 41);
2909+
2910+}
2911+
28932912 static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
28942913 {
28952914 /*
@@ -2902,13 +2921,19 @@ static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu) · 6 unmodified lines
29022921 vcpu->arch.sie_block->crycbd = vcpu->kvm->arch.crypto.crycbd;
29032922 vcpu->arch.sie_block->ecb3 &= ~(ECB3_AES | ECB3_DEA);
29042923 vcpu->arch.sie_block->eca &= ~ECA_APIE;
2924+ vcpu->arch.sie_block->ecd &= ~ECD_ECC;
29052925
29062926 if (vcpu->kvm->arch.crypto.apie)
29072927 vcpu->arch.sie_block->eca |= ECA_APIE;
29082928
29092929 /* Set up protected key support */
2910− if (vcpu->kvm->arch.crypto.aes_kw)
2930+ if (vcpu->kvm->arch.crypto.aes_kw) {
29112931 vcpu->arch.sie_block->ecb3 |= ECB3_AES;
2932+ /* ecc is also wrapped with AES key */
2933+ if (kvm_has_pckmo_ecc(vcpu->kvm))
2934+ vcpu->arch.sie_block->ecd |= ECD_ECC;
2935+ }
2936+
29122937 if (vcpu->kvm->arch.crypto.dea_kw)
29132938 vcpu->arch.sie_block->ecb3 |= ECB3_DEA;
29142939 }
arch/s390/kvm/vsie.c+4−1
@@ -288,6 +288,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · 287 unmodified lines
288288 const u32 crycb_addr = crycbd_o & 0x7ffffff8U;
289289 unsigned long *b1, *b2;
290290 u8 ecb3_flags;
291+ u32 ecd_flags;
291292 int apie_h;
292293 int key_msk = test_kvm_facility(vcpu->kvm, 76);
293294 int fmt_o = crycbd_o & CRYCB_FORMAT_MASK;
@@ -320,7 +321,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · 26 unmodified lines
320321 /* we may only allow it if enabled for guest 2 */
321322 ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
322323 (ECB3_AES | ECB3_DEA);
323− if (!ecb3_flags)
324+ ecd_flags = scb_o->ecd & vcpu->arch.sie_block->ecd & ECD_ECC;
325+ if (!ecb3_flags && !ecd_flags)
324326 goto end;
325327
326328 /* copy only the wrapping keys */
@@ -329,6 +331,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) · 2 unmodified lines
329331 return set_validity_icpt(scb_s, 0x0035U);
330332
331333 scb_s->ecb3 |= ecb3_flags;
334+ scb_s->ecd |= ecd_flags;
332335
333336 /* xor both blocks in one run */
334337 b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t