Set the CMMA flag also when the first ESSA instruction was performed in migration mode. Set the CMMA flag in kvm_s390_set_cmma_bits() before starting to set the CMMA values, instead of afterwards. Fix the stale comments in handle_essa(). Fence UCONTROL VMs from using the KVM_S390_SET_CMMA_BITS ioctl, returning -EINVAL. Fixes: e38c884df921 ("KVM: s390: Switch to new gmap") Cc: stable@vger.kernel.org Signed-off-by: Claudio Imbrenda --- arch/s390/kvm/s390/priv.c | 14 ++++++-------- arch/s390/kvm/s390/s390.c | 8 ++++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/s390/kvm/s390/priv.c b/arch/s390/kvm/s390/priv.c index f22612a127c9..4b590c09240c 100644 --- a/arch/s390/kvm/s390/priv.c +++ b/arch/s390/kvm/s390/priv.c @@ -1243,19 +1243,15 @@ static int handle_essa(struct kvm_vcpu *vcpu) if (!READ_ONCE(vcpu->kvm->arch.migration_mode)) { /* * CMMA is enabled in the KVM settings, but is disabled in - * the SIE block and in the mm_context, and we are not doing - * a migration. Enable CMMA in the mm_context. - * Since we need to take a write lock to write to the context - * to avoid races with storage keys handling, we check if the - * value really needs to be written to; if the value is - * already correct, we do nothing and avoid the lock. + * the SIE block and in the gmap, and we are not doing a + * migration. Enable CMMA in the gmap. */ set_bit(GMAP_FLAG_USES_CMM, &vcpu->arch.gmap->flags); /* * If we are here, we are supposed to have CMMA enabled in * the SIE block. Enabling CMMA works on a per-CPU basis, - * while the context use_cmma flag is per process. - * It's possible that the context flag is enabled and the + * while the GMAP_FLAG_USES_CMM flag is per gmap. + * It's possible that the gmap flag is enabled and the * SIE flag is not, so we set the flag always; if it was * already set, nothing changes, otherwise we enable it * on this CPU too. @@ -1264,6 +1260,8 @@ static int handle_essa(struct kvm_vcpu *vcpu) /* Retry the ESSA instruction */ kvm_s390_retry_instr(vcpu); } else { + set_bit(GMAP_FLAG_USES_CMM, &vcpu->arch.gmap->flags); + scoped_guard(mutex, &vcpu->kvm->slots_arch_lock) scoped_guard(read_lock, &vcpu->kvm->mmu_lock) i = __do_essa(vcpu, orc); diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c index 4ef7ca960b46..09c43770296d 100644 --- a/arch/s390/kvm/s390/s390.c +++ b/arch/s390/kvm/s390/s390.c @@ -2349,6 +2349,8 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm, if (r) return -EFAULT; + set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags); + do { r = kvm_s390_mmu_cache_topup(mc); if (r) @@ -2359,8 +2361,6 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm, } } while (r == -ENOMEM); - set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags); - return r <= 0 ? r : -EFAULT; } @@ -2991,6 +2991,10 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) r = -EFAULT; if (copy_from_user(&args, argp, sizeof(args))) break; + if (kvm_is_ucontrol(kvm)) { + r = -EINVAL; + break; + } mutex_lock(&kvm->slots_arch_lock); r = kvm_s390_set_cmma_bits(kvm, &args); mutex_unlock(&kvm->slots_arch_lock); -- 2.56.1