From: Heiko Carstens Subject: Re: [patch 10/12] [PATCH] kvm-s390: storage key interface Date: Sun, 11 Dec 2011 22:57:18 +0100 Message-ID: <20111211215718.GA2543@osiris.boeblingen.de.ibm.com> References: <20111210123529.379102332@de.ibm.com> <20111210123707.571900097@de.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Avi Kivity , Marcelo Tossati , Christian Borntraeger , Martin Schwidefsky , Cornelia Huck , KVM , Joachim von Buttlar , Jens Freimann , Constantin Werner , agraf@suse.de To: Carsten Otte Return-path: Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:37872 "EHLO e06smtp16.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752439Ab1LKV5Y (ORCPT ); Sun, 11 Dec 2011 16:57:24 -0500 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 11 Dec 2011 21:57:23 -0000 Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBBLvJR92670744 for ; Sun, 11 Dec 2011 21:57:20 GMT Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBBLvJNl023965 for ; Sun, 11 Dec 2011 14:57:19 -0700 Content-Disposition: inline In-Reply-To: <20111210123707.571900097@de.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: On Sat, Dec 10, 2011 at 01:35:39PM +0100, Carsten Otte wrote: > This patch introduces an interface to access the guest visible > storage keys. It supports three operations that model the behavior > that SSKE/ISKE/RRBE instructions would have if they were issued by > the guest. These instructions are all documented in the z architecture > principles of operation book. > > Signed-off-by: Carsten Otte [...] > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -112,13 +112,115 @@ void kvm_arch_exit(void) > { > } > > +static long kvm_s390_keyop(struct kvm_s390_keyop *kop) > +{ > + unsigned long addr = kop->user_addr; > + pte_t *ptep; > + pgste_t pgste; > + int r; > + unsigned long skey; > + unsigned long bits; > + > + /* make sure this process is a hypervisor */ > + r = -EINVAL; > + if (!mm_has_pgste(current->mm)) > + goto out; > + > + r = -EFAULT; > + if (addr >= PGDIR_SIZE) > + goto out; > + > + spin_lock(¤t->mm->page_table_lock); > + ptep = ptep_for_addr(addr); Locking is broken; following order is possible: kvm_s390_keyop() - spin_lock(¤t->mm->page_table_lock) -> ptep_for_addr() - down_read(¤t->mm->mmap_sem) ---> Bug 1, we might schedule here -> __pmdp_for_addr() -> __pte_alloc() - spin_lock(&mm->page_table_lock) ---> Bug 2, deadlock