From patchwork Wed Mar 22 20:10:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 9639937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9539A601E9 for ; Wed, 22 Mar 2017 20:10:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DC6E28482 for ; Wed, 22 Mar 2017 20:10:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82B3628485; Wed, 22 Mar 2017 20:10:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 46DE328482 for ; Wed, 22 Mar 2017 20:10:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DB62480282; Wed, 22 Mar 2017 13:10:41 -0700 (PDT) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D90ED80282 for ; Wed, 22 Mar 2017 13:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490213439; x=1521749439; h=from:to:cc:subject:date:message-id; bh=2Dlc2nW8f8f/Pv0tUs458isXZ5WH47f9/T3MLskeDiU=; b=aT2PDJKzN0Kp07d9G/fCNY6dm8o+6UouIBEfNZ/Fou5LB/cicg91jb7p Njtmd9Tyh53Z60kvUL8j3ktCerGmMQ==; Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Mar 2017 13:10:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,206,1486454400"; d="scan'208";a="69792206" Received: from sjchrist-ts.jf.intel.com ([10.54.74.20]) by orsmga004.jf.intel.com with ESMTP; 22 Mar 2017 13:10:39 -0700 From: Sean Christopherson To: intel-sgx-kernel-dev@lists.01.org Date: Wed, 22 Mar 2017 13:10:38 -0700 Message-Id: <1490213438-30560-1-git-send-email-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [intel-sgx-kernel-dev] [PATCH] intel_sgx: alloc EPC page for fault iff initial checks pass X-BeenThere: intel-sgx-kernel-dev@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Project: Intel® Software Guard Extensions for Linux*: https://01.org/intel-software-guard-extensions" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-sgx-kernel-dev-bounces@lists.01.org Sender: "intel-sgx-kernel-dev" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Sean Christopherson --- drivers/platform/x86/intel_sgx_util.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/intel_sgx_util.c b/drivers/platform/x86/intel_sgx_util.c index 234a5fb..1cfd7d2 100644 --- a/drivers/platform/x86/intel_sgx_util.c +++ b/drivers/platform/x86/intel_sgx_util.c @@ -313,13 +313,6 @@ static struct sgx_encl_page *sgx_do_fault(struct vm_area_struct *vma, goto out; } - epc_page = sgx_alloc_page(encl->tgid_ctx, SGX_ALLOC_ATOMIC); - if (IS_ERR(epc_page)) { - rc = PTR_ERR(epc_page); - epc_page = NULL; - goto out; - } - if (encl->flags & SGX_ENCL_DEAD) { rc = -EFAULT; goto out; @@ -345,6 +338,13 @@ static struct sgx_encl_page *sgx_do_fault(struct vm_area_struct *vma, goto out; } + epc_page = sgx_alloc_page(encl->tgid_ctx, SGX_ALLOC_ATOMIC); + if (IS_ERR(epc_page)) { + rc = PTR_ERR(epc_page); + epc_page = NULL; + goto out; + } + /* If SECS is evicted then reload it first */ if (encl->flags & SGX_ENCL_SECS_EVICTED) { secs_epc_page = sgx_alloc_page(encl->tgid_ctx, SGX_ALLOC_ATOMIC);