Skip to content

Commit b5d1274

Browse files
Janis Schoetterl-Glauschhcahca
authored andcommitted
KVM: s390: Fix lockdep issue in vm memop
Issuing a memop on a protected vm does not make sense, neither is the memory readable/writable, nor does it make sense to check storage keys. This is why the ioctl will return -EINVAL when it detects the vm to be protected. However, in order to ensure that the vm cannot become protected during the memop, the kvm->lock would need to be taken for the duration of the ioctl. This is also required because kvm_s390_pv_is_protected asserts that the lock must be held. Instead, don't try to prevent this. If user space enables secure execution concurrently with a memop it must accecpt the possibility of the memop failing. Still check if the vm is currently protected, but without locking and consider it a heuristic. Fixes: ef11c94 ("KVM: s390: Add vm IOCTL for key checked guest absolute memory access") Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com> Reviewed-by: Janosch Frank <frankja@linux.ibm.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Link: https://lore.kernel.org/r/20220322153204.2637400-1-scgl@linux.ibm.com Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 8b202ee commit b5d1274

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

arch/s390/kvm/kvm-s390.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,16 @@ static int kvm_s390_vm_mem_op(struct kvm *kvm, struct kvm_s390_mem_op *mop)
23842384
return -EINVAL;
23852385
if (mop->size > MEM_OP_MAX_SIZE)
23862386
return -E2BIG;
2387-
if (kvm_s390_pv_is_protected(kvm))
2387+
/*
2388+
* This is technically a heuristic only, if the kvm->lock is not
2389+
* taken, it is not guaranteed that the vm is/remains non-protected.
2390+
* This is ok from a kernel perspective, wrongdoing is detected
2391+
* on the access, -EFAULT is returned and the vm may crash the
2392+
* next time it accesses the memory in question.
2393+
* There is no sane usecase to do switching and a memop on two
2394+
* different CPUs at the same time.
2395+
*/
2396+
if (kvm_s390_pv_get_handle(kvm))
23882397
return -EINVAL;
23892398
if (mop->flags & KVM_S390_MEMOP_F_SKEY_PROTECTION) {
23902399
if (access_key_invalid(mop->key))

0 commit comments

Comments
 (0)