Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1286699imm; Thu, 4 Oct 2018 11:01:47 -0700 (PDT) X-Google-Smtp-Source: ACcGV624xCy//Q0iwYD/kfmct5m3U0ugqJZ2ySd231rWaeZ0BXaSs+M6p52FCQC7lYrHhp6kd6qQ X-Received: by 2002:a17:902:b410:: with SMTP id x16-v6mr6181227plr.13.1538676107737; Thu, 04 Oct 2018 11:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538676107; cv=none; d=google.com; s=arc-20160816; b=gQtFw8pcDwH6+XSksSkoh0wH6rTvh9mwFBLVq9TpUv3Ax67zNJGNgfEPWpOn/2b0aq 90VeekYw63Ugpk9SfTpGr5tXo11XvKSc8O73WE8XgTJyoJR9ATmrAZDtO2pYc9x3ROoA 8B8p/4lNhO9WomjANSSFm2bDigLm+/cLkah7hjFEunkwlu98oTO3Uzo/pAMB7eKrda5v v30k2ptDbWmud1Sb5OBCyZ+i0tdL2se4azJ3mU63gzlXZv+4nCAtZb1hDoK+wmjxC62i ULM5iNLNyvhUHg7MCT72rG8iJLv4pvrCerkTC7BbAnArMMwynIf5tSKkAYpc/+qMq9M6 4Zlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=yVce396lBVSCJ3l1vt68m/POOX3wa8geXwEfkOp577E=; b=0SwD1R26CXqWofh8eqMgHNiF1a7e97nGZ8re7NBF/LxMlpt0xoLpx33gLsdiIhwqiQ GlOM2FN6kevN84/KxukgmOuZDl806kY/3WViKJjlwd3wOa++TLN3wQ1iJiIbDEhsv3nv 7Qg/0y/HSDdJhVjJ4G/iFuROejX6SLzXGYsbaWOfarVRYm9G0yWYZafzkMkjuPGSna/j Vm8Q4t1n1rAjJ6D+Cljegv93Hwipw5eE6u7XEq8YQ3J/WMAGdQApp5ZexuOdsaPKFKsf 86ntWsRewWJAfhjFReX328/AyU2rDlI5fUmsRvpAjI497ZLmC6mLmlfyJKz+UjEGimqq 0giA== 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 k9-v6si5513769pgi.227.2018.10.04.11.01.31; Thu, 04 Oct 2018 11:01:47 -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 S1727709AbeJEAzs (ORCPT + 99 others); Thu, 4 Oct 2018 20:55:48 -0400 Received: from mga12.intel.com ([192.55.52.136]:25490 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727407AbeJEAzs (ORCPT ); Thu, 4 Oct 2018 20:55:48 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Oct 2018 11:01:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,340,1534834800"; d="scan'208";a="94678034" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.193]) by fmsmga004.fm.intel.com with ESMTP; 04 Oct 2018 11:01:17 -0700 Message-ID: <1538676077.2562.6.camel@intel.com> Subject: Re: [PATCH v14 15/19] platform/x86: Intel SGX driver From: Sean Christopherson To: Jarkko Sakkinen , x86@kernel.org, platform-driver-x86@vger.kernel.org Cc: dave.hansen@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, linux-sgx@vger.kernel.org, andriy.shevchenko@linux.intel.com, Suresh Siddha , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Darren Hart , Andy Shevchenko , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Date: Thu, 04 Oct 2018 11:01:17 -0700 In-Reply-To: <20180925130845.9962-16-jarkko.sakkinen@linux.intel.com> References: <20180925130845.9962-1-jarkko.sakkinen@linux.intel.com> <20180925130845.9962-16-jarkko.sakkinen@linux.intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-09-25 at 16:06 +0300, Jarkko Sakkinen wrote: > Intel Software Guard eXtensions (SGX) is a set of CPU instructions that > can be used by applications to set aside private regions of code and > data. The code outside the enclave is disallowed to access the memory > inside the enclave by the CPU access control. > > SGX driver provides a ioctl API for loading and initializing enclaves. > Address range for enclaves is reserved with mmap() and they are > destroyed with munmap(). Enclave construction, measurement and > initialization is done with the provided the ioctl API. ... > +/** > + * sgx_ioc_enclave_init - handler for %SGX_IOC_ENCLAVE_INIT > + * > + * @filep: open file to /dev/sgx > + * @cmd: the command value > + * @arg: pointer to an &sgx_enclave_init instance > + * > + * Flushes the remaining enqueued EADD operations and performs EINIT. Does not > + * allow the EINITTOKENKEY attribute for an enclave. > + * > + * Return: > + *   0 on success, > + *   SGX error code on EINIT failure, > + *   -errno otherwise > + */ > +static long sgx_ioc_enclave_init(struct file *filep, unsigned int cmd, > +  unsigned long arg) > +{ > + struct sgx_enclave_init *initp = (struct sgx_enclave_init *)arg; > + struct sgx_sigstruct *sigstruct; > + struct sgx_einittoken *einittoken; > + struct sgx_encl *encl; > + struct page *initp_page; > + int ret; > + > + initp_page = alloc_page(GFP_HIGHUSER); > + if (!initp_page) > + return -ENOMEM; > + > + sigstruct = kmap(initp_page); > + einittoken = (struct sgx_einittoken *) > + ((unsigned long)sigstruct + PAGE_SIZE / 2); > + memset(einittoken, 0, sizeof(*einittoken)); > + > + ret = copy_from_user(sigstruct, (void __user *)initp->sigstruct, > +      sizeof(*sigstruct)); > + if (ret) > + goto out; > + if (sigstruct->attributes & SGX_ATTR_EINITTOKENKEY) { > + ret = EINVAL; This should be "ret = -EINVAL". > + goto out; > + } > + > + ret = sgx_encl_get(initp->addr, &encl); > + if (ret) > + goto out; > + > + ret = sgx_encl_init(encl, sigstruct, einittoken); > + > + kref_put(&encl->refcount, sgx_encl_release); > + > +out: > + kunmap(initp_page); > + __free_page(initp_page); > + return ret; > +}