Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3788726ybi; Sun, 2 Jun 2019 23:41:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKS+RJ783j3cNYwDhwawSoeX5ivj9WIa+xmGWg0GrFhyYGAeIdsRCdt62dHkDlYMA6nUxr X-Received: by 2002:a17:90a:5d09:: with SMTP id s9mr27091041pji.120.1559544083066; Sun, 02 Jun 2019 23:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559544083; cv=none; d=google.com; s=arc-20160816; b=fcpuw6aZ1x18mWettcEkkkA0Y03lbi3z0PEXlupat3h7G7C/yNZ8zZqryTqNZkAtOn rjUT/F7WpXi1H36RR3dNgYPOG0HkZYP2dgnq8x0FL5WgUh6Nss1Py23FCi3Y9nl4Lo7p ApVPJDsBC22CkPfVRmDT1lPLtXfmD18m0xPOdMmHnXaDVpMLcyBuoIWR42NY6+gSGTb5 EZaFwrriMhIijd8peRAFYw7IQGZXYkrz+YiLqHZ0BSUM7duiMwJ73iHs6xPK+oAZsRxi Bk85YwapSNyD2YvC/lkKPtzCUcA7+AtGChDzsce0i0ssLnp1L/424kB2KZR7vwpYDZiC E24Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=XZtwNAmz36YH1HLE08lrVGvXudt+nSP0+WAo6InDXHw=; b=yr6dqlmfvnOilgE/I8LNQibXBhU2VILjr6+BOh2oc9cPPKyqyURwEqdjQsoeWcJPxb TQxEDNJwtfFB/UFnAUTpR/YhNhGqtTxNOn4oM3GZwfUANuoy4S+g0YRwfmt43dYiFpyo 2lhKcdqNZrVYaaH7t9gcpGSQt2faTx1eNiDZdpX+YEJaHKe/aIZCPUVHPwkNy0Tpk2x7 RXXrHd9acu5zf7YJEGk/HogYvI1OLf6Vf/nP85bgeFimQWct9dORCFiuclf3qYoNKSt5 qhguE1mQNNPagr+8ph+zBbetNb6hORUHO3gTYXNgtRHDNH0ZA6CPm+u8lPvj8xrqnb/E m3rQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si18457670pld.399.2019.06.02.23.41.05; Sun, 02 Jun 2019 23:41:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726933AbfFCG0L convert rfc822-to-8bit (ORCPT + 99 others); Mon, 3 Jun 2019 02:26:11 -0400 Received: from mga07.intel.com ([134.134.136.100]:41645 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726486AbfFCG0L (ORCPT ); Mon, 3 Jun 2019 02:26:11 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jun 2019 23:26:10 -0700 X-ExtLoop1: 1 Received: from orsmsx105.amr.corp.intel.com ([10.22.225.132]) by orsmga005.jf.intel.com with ESMTP; 02 Jun 2019 23:26:10 -0700 Received: from orsmsx126.amr.corp.intel.com (10.22.240.126) by ORSMSX105.amr.corp.intel.com (10.22.225.132) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sun, 2 Jun 2019 23:26:10 -0700 Received: from orsmsx116.amr.corp.intel.com ([169.254.7.165]) by ORSMSX126.amr.corp.intel.com ([169.254.4.35]) with mapi id 14.03.0415.000; Sun, 2 Jun 2019 23:26:10 -0700 From: "Xing, Cedric" To: "Christopherson, Sean J" , "Jarkko Sakkinen" CC: 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() Thread-Topic: [RFC PATCH 3/9] x86/sgx: Allow userspace to add multiple pages in single ioctl() Thread-Index: AQHVGAki7TYpY4ZsUk+m4jTej+khLaaJYAJQ Date: Mon, 3 Jun 2019 06:26:09 +0000 Message-ID: <960B34DE67B9E140824F1DCDEC400C0F654ECBBD@ORSMSX116.amr.corp.intel.com> References: <20190531233159.30992-1-sean.j.christopherson@intel.com> <20190531233159.30992-4-sean.j.christopherson@intel.com> In-Reply-To: <20190531233159.30992-4-sean.j.christopherson@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMTFhYjE5MTAtN2M1Ny00NzQ1LWI4MWYtYTYyOTljMTBlOWY1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiUUo4ZUN3aGVZbGxhQ3RnK21xZWRVZTVxWVBtS1VnYVVcL25DMmVCOGoyTnlTbDQ5aFYxa09ySVwvQ2VOZjNNcU1oIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.22.254.138] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > 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? > + > + 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