From patchwork Mon May 1 17:43:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 9706747 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 DBE366038F for ; Mon, 1 May 2017 17:43:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFE2F27D4D for ; Mon, 1 May 2017 17:43:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4AC02808F; Mon, 1 May 2017 17:43:55 +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.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham 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 79B3A27D4D for ; Mon, 1 May 2017 17:43:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 47AD42195DA40; Mon, 1 May 2017 10:43:53 -0700 (PDT) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 B518F21A04830 for ; Mon, 1 May 2017 10:43:51 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 May 2017 10:43:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,401,1488873600"; d="scan'208";a="95939067" Received: from sjchrist-ts.jf.intel.com ([10.54.74.20]) by fmsmga005.fm.intel.com with ESMTP; 01 May 2017 10:43:51 -0700 From: Sean Christopherson To: intel-sgx-kernel-dev@lists.01.org Date: Mon, 1 May 2017 10:43:48 -0700 Message-Id: <1493660629-16888-2-git-send-email-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493660629-16888-1-git-send-email-sean.j.christopherson@intel.com> References: <1493660629-16888-1-git-send-email-sean.j.christopherson@intel.com> Subject: [intel-sgx-kernel-dev] [PATCH 1/2] intel_sgx: separate EPC bank addition from page cache init 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 Move the init code to process an EPC bank into a separate function, sgx_add_epc_bank, which can be safely called multiple times. Call sgx_page_cache_init only once after all EPC banks have been added. This fixes a bug where ksgxswapd_tsk is overwritten and lost when there is more than one EPC bank. Reported-by: Kai Huang Signed-off-by: Sean Christopherson --- drivers/platform/x86/intel_sgx/sgx.h | 3 ++- drivers/platform/x86/intel_sgx/sgx_main.c | 6 +++++- drivers/platform/x86/intel_sgx/sgx_page_cache.c | 12 ++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/platform/x86/intel_sgx/sgx.h b/drivers/platform/x86/intel_sgx/sgx.h index e59ff01..f169af3 100644 --- a/drivers/platform/x86/intel_sgx/sgx.h +++ b/drivers/platform/x86/intel_sgx/sgx.h @@ -223,7 +223,8 @@ enum sgx_alloc_flags { }; int ksgxswapd(void *p); -int sgx_page_cache_init(resource_size_t start, unsigned long size); +int sgx_add_epc_bank(resource_size_t start, unsigned long size); +int sgx_page_cache_init(void); void sgx_page_cache_teardown(void); struct sgx_epc_page *sgx_alloc_page(unsigned int flags); int sgx_free_page(struct sgx_epc_page *entry, struct sgx_encl *encl); diff --git a/drivers/platform/x86/intel_sgx/sgx_main.c b/drivers/platform/x86/intel_sgx/sgx_main.c index 5890643..98ee05d 100644 --- a/drivers/platform/x86/intel_sgx/sgx_main.c +++ b/drivers/platform/x86/intel_sgx/sgx_main.c @@ -289,7 +289,7 @@ static int sgx_dev_init(struct device *dev) goto out_iounmap; } #endif - ret = sgx_page_cache_init(sgx_epc_banks[i].start, + ret = sgx_add_epc_bank(sgx_epc_banks[i].start, sgx_epc_banks[i].end - sgx_epc_banks[i].start); if (ret) { sgx_nr_epc_banks = i+1; @@ -297,6 +297,10 @@ static int sgx_dev_init(struct device *dev) } } + ret = sgx_page_cache_init(); + if (ret) + goto out_iounmap; + wq_flags = WQ_UNBOUND | WQ_FREEZABLE; #ifdef WQ_NON_REENETRANT wq_flags |= WQ_NON_REENTRANT; diff --git a/drivers/platform/x86/intel_sgx/sgx_page_cache.c b/drivers/platform/x86/intel_sgx/sgx_page_cache.c index 59a67cb..d4cf0cc 100644 --- a/drivers/platform/x86/intel_sgx/sgx_page_cache.c +++ b/drivers/platform/x86/intel_sgx/sgx_page_cache.c @@ -416,7 +416,7 @@ int ksgxswapd(void *p) return 0; } -int sgx_page_cache_init(resource_size_t start, unsigned long size) +int sgx_add_epc_bank(resource_size_t start, unsigned long size) { unsigned long i; struct sgx_epc_page *new_epc_page, *entry; @@ -435,9 +435,6 @@ int sgx_page_cache_init(resource_size_t start, unsigned long size) spin_unlock(&sgx_free_list_lock); } - sgx_nr_high_pages = 2 * sgx_nr_low_pages; - ksgxswapd_tsk = kthread_run(ksgxswapd, NULL, "ksgxswapd"); - return 0; err_freelist: list_for_each_safe(parser, temp, &sgx_free_list) { @@ -450,6 +447,13 @@ int sgx_page_cache_init(resource_size_t start, unsigned long size) return -ENOMEM; } +int sgx_page_cache_init(void) +{ + sgx_nr_high_pages = 2 * sgx_nr_low_pages; + ksgxswapd_tsk = kthread_run(ksgxswapd, NULL, "ksgxswapd"); + return 0; +} + void sgx_page_cache_teardown(void) { struct sgx_epc_page *entry;