From: Heiko Carstens Subject: Re: [patch 10/12] [PATCH] kvm-s390: storage key interface Date: Fri, 9 Dec 2011 13:04:01 +0100 Message-ID: <20111209120400.GA2333@osiris.boeblingen.de.ibm.com> References: <20111209112326.454852716@de.ibm.com> <20111209112752.097882009@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 To: Carsten Otte Return-path: Received: from e06smtp10.uk.ibm.com ([195.75.94.106]:57266 "EHLO e06smtp10.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751441Ab1LIMEM (ORCPT ); Fri, 9 Dec 2011 07:04:12 -0500 Received: from /spool/local by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Dec 2011 12:04:10 -0000 Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pB9C42Q42543800 for ; Fri, 9 Dec 2011 12:04:02 GMT Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pB9C410L002733 for ; Fri, 9 Dec 2011 12:04:01 GMT Content-Disposition: inline In-Reply-To: <20111209112752.097882009@de.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, Dec 09, 2011 at 12:23:36PM +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 [...] > +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 = -ENXIO; > + if (addr >= PGDIR_SIZE) > + goto out; imho this should be -EFAULT. > + spin_lock(¤t->mm->page_table_lock); > + ptep = ptep_for_addr(addr); > + if (!ptep) > + goto out_unlock; ptep is a pointer and may contain an error code, like you implemented it below. Therefore you need to check for IS_ERR() here. > +static pmd_t *__pmdp_for_addr(struct mm_struct *mm, unsigned long addr) > +{ > + struct vm_area_struct *vma; > + pgd_t *pgd; > + pud_t *pud; > + pmd_t *pmd; > + > + vma = find_vma(mm, addr); > + if (!vma) > + return ERR_PTR(-EINVAL); -EFAULT imho. Also, why is this check good enough? As far as I remember find_vma() only guarantees that addr < vma_end, (if vma != NULL), but it does not guarantee that addr >= vma_start. > - vma = find_vma(mm, vmaddr); > - if (!vma || vma->vm_start > vmaddr) > - return -EFAULT; ... you used to check for that and also used the proper return code, btw. Or is there a different reason why the above code is correct? > +pte_t *ptep_for_addr(unsigned long addr) > +{ > + pmd_t *pmd; > + pte_t *rc; Would you mind renaming rc into pte? > + > + down_read(¤t->mm->mmap_sem); > + > + pmd = __pmdp_for_addr(current->mm, addr); > + if (IS_ERR(pmd)) { > + rc = (pte_t *)pmd; > + goto up_out; > + } > + > + rc = pte_offset(pmd, addr); > +up_out: > + up_read(¤t->mm->mmap_sem); > + return rc;