From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23A90C28CC6 for ; Mon, 3 Jun 2019 20:08:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0414926894 for ; Mon, 3 Jun 2019 20:08:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726765AbfFCUIH (ORCPT ); Mon, 3 Jun 2019 16:08:07 -0400 Received: from mga04.intel.com ([192.55.52.120]:65148 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbfFCUIG (ORCPT ); Mon, 3 Jun 2019 16:08:06 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jun 2019 13:08:05 -0700 X-ExtLoop1: 1 Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by fmsmga007.fm.intel.com with ESMTP; 03 Jun 2019 13:08:04 -0700 Date: Mon, 3 Jun 2019 13:08:04 -0700 From: Sean Christopherson To: "Xing, Cedric" Cc: Jarkko Sakkinen , Andy Lutomirski , Stephen Smalley , James Morris , "Serge E . Hallyn" , LSM List , Paul Moore , Eric Paris , "selinux@vger.kernel.org" , Jethro Beekman , "Hansen, Dave" , Thomas Gleixner , Linus Torvalds , LKML , X86 ML , "linux-sgx@vger.kernel.org" , Andrew Morton , "nhorman@redhat.com" , "npmccallum@redhat.com" , "Ayoun, Serge" , "Katz-zamir, Shay" , "Huang, Haitao" , Andy Shevchenko , "Svahn, Kai" , Borislav Petkov , Josh Triplett , "Huang, Kai" , David Rientjes , "Roberts, William C" , "Tricca, Philip B" Subject: Re: [RFC PATCH 3/9] x86/sgx: Allow userspace to add multiple pages in single ioctl() Message-ID: <20190603200804.GG13384@linux.intel.com> References: <20190531233159.30992-1-sean.j.christopherson@intel.com> <20190531233159.30992-4-sean.j.christopherson@intel.com> <960B34DE67B9E140824F1DCDEC400C0F654ECBBD@ORSMSX116.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <960B34DE67B9E140824F1DCDEC400C0F654ECBBD@ORSMSX116.amr.corp.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jun 02, 2019 at 11:26:09PM -0700, Xing, Cedric wrote: > > From: Christopherson, Sean J > > Sent: Friday, May 31, 2019 4:32 PM > > > > +/** > > + * sgx_ioc_enclave_add_pages - handler for %SGX_IOC_ENCLAVE_ADD_PAGES > > + * > > + * @filep: open file to /dev/sgx > > + * @cmd: the command value > > + * @arg: pointer to an &sgx_enclave_add_page instance > > + * > > + * Add a range of pages to an uninitialized enclave (EADD), and > > +optionally > > + * extend the enclave's measurement with the contents of the page (EEXTEND). > > + * The range of pages must be virtually contiguous. The SECINFO and > > + * measurement maskare applied to all pages, i.e. pages with different > > + * properties must be added in separate calls. > > + * > > + * EADD and EEXTEND are done asynchronously via worker threads. A > > +successful > > + * sgx_ioc_enclave_add_page() only indicates the pages have been added > > +to the > > + * work queue, it does not guarantee adding the pages to the enclave > > +will > > + * succeed. > > + * > > + * Return: > > + * 0 on success, > > + * -errno otherwise > > + */ > > +static long sgx_ioc_enclave_add_pages(struct file *filep, unsigned int cmd, > > + unsigned long arg) > > +{ > > + struct sgx_enclave_add_pages *addp = (void *)arg; > > + struct sgx_encl *encl = filep->private_data; > > + struct sgx_secinfo secinfo; > > + unsigned int i; > > + int ret; > > + > > + if (copy_from_user(&secinfo, (void __user *)addp->secinfo, > > + sizeof(secinfo))) > > + return -EFAULT; > > + > > + for (i = 0, ret = 0; i < addp->nr_pages && !ret; i++) { > > + if (signal_pending(current)) > > + return -ERESTARTSYS; > > If interrupted, how would user mode code know how many pages have been EADD'ed? Hmm, updating nr_pages would be fairly simple and shouldn't confuse userspace, e.g. as opposed to overloading the return value. > > + > > + if (need_resched()) > > + cond_resched(); > > + > > + ret = sgx_encl_add_page(encl, addp->addr + i*PAGE_SIZE, > > + addp->src + i*PAGE_SIZE, > > + &secinfo, addp->mrmask); > > + } > > return ret; > > } > > > > @@ -823,8 +845,8 @@ long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) > > case SGX_IOC_ENCLAVE_CREATE: > > handler = sgx_ioc_enclave_create; > > break; > > - case SGX_IOC_ENCLAVE_ADD_PAGE: > > - handler = sgx_ioc_enclave_add_page; > > + case SGX_IOC_ENCLAVE_ADD_PAGES: > > + handler = sgx_ioc_enclave_add_pages; > > break; > > case SGX_IOC_ENCLAVE_INIT: > > handler = sgx_ioc_enclave_init; > > -- > > 2.21.0 >