Automatically enable storage keys for UCONTROL VMs upon creation. There is no point in leaving it to the lazy initialization, as storage keys will almost surely be used very early in the boot process of a UCONTROL guest. Furthermore, if storage keys initialization fails, it will prevent the VM from starting, instead of failing at runtime. Opportunistically improve error handling if the fake memslot cannot be initialized properly. Signed-off-by: Claudio Imbrenda --- arch/s390/kvm/s390/s390.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c index e4912db67adc..dafcd104d316 100644 --- a/arch/s390/kvm/s390/s390.c +++ b/arch/s390/kvm/s390/s390.c @@ -3346,10 +3346,15 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) .flags = 0, }; + rc = gmap_enable_skeys(kvm->arch.gmap); + if (rc) + goto out_err; /* one flat fake memslot covering the whole address-space */ mutex_lock(&kvm->slots_lock); - KVM_BUG_ON(kvm_set_internal_memslot(kvm, &fake_memslot), kvm); + rc = kvm_set_internal_memslot(kvm, &fake_memslot); mutex_unlock(&kvm->slots_lock); + if (KVM_BUG_ON(rc, kvm)) + goto out_err; set_bit(GMAP_FLAG_IS_UCONTROL, &kvm->arch.gmap->flags); } else { struct crst_table *table = dereference_asce(kvm->arch.gmap->asce); @@ -3369,6 +3374,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) return 0; out_err: + if (kvm->arch.gmap) + kvm->arch.gmap = gmap_put(kvm->arch.gmap); free_page((unsigned long)kvm->arch.sie_page2); debug_unregister(kvm->arch.dbf); sca_dispose(kvm); -- 2.56.0