From patchwork Fri May 29 17:54:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11579441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 490D91392 for ; Fri, 29 May 2020 17:54:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38E822073B for ; Fri, 29 May 2020 17:54:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727030AbgE2RyM (ORCPT ); Fri, 29 May 2020 13:54:12 -0400 Received: from mga14.intel.com ([192.55.52.115]:51589 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725913AbgE2RyL (ORCPT ); Fri, 29 May 2020 13:54:11 -0400 IronPort-SDR: Wp0u2amyvwxwXM+sWANwiPMJdvxGXZlgTQAbbOFQIXY5qX54vJeeJoSVATz754zV/IzY6STv6z e/2dZ6YiUPBA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2020 10:54:08 -0700 IronPort-SDR: Oc4SX26W9PjIkh6aX5ts6cSrZR/FrvO0tUsnzDnob2Z5MhSPJvdd4CDGSfRrMnncxFQ8pCLFdY 0Mcfi4MJXI+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,449,1583222400"; d="scan'208";a="271292321" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by orsmga006.jf.intel.com with ESMTP; 29 May 2020 10:54:08 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-sgx@vger.kernel.org Subject: [PATCH for_v31 1/6] x86/sgx: Fix inadvertant early return from sgx_ioctl() Date: Fri, 29 May 2020 10:54:02 -0700 Message-Id: <20200529175407.2109-2-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200529175407.2109-1-sean.j.christopherson@intel.com> References: <20200529175407.2109-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Set 'ret' instead of returning if the enclave is dead in sgx_ioctl(), otherwise the goto that was added doesn't take effect. Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/sgx/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index ec5a0f017014b..2019ee1dc0b3e 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -790,7 +790,7 @@ long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) return -EBUSY; if (encl_flags & SGX_ENCL_DEAD) { - return -EFAULT; + ret = -EFAULT; goto out; } From patchwork Fri May 29 17:54:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11579445 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37D74912 for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FFDF2073B for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727980AbgE2RyM (ORCPT ); Fri, 29 May 2020 13:54:12 -0400 Received: from mga14.intel.com ([192.55.52.115]:51589 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725913AbgE2RyM (ORCPT ); Fri, 29 May 2020 13:54:12 -0400 IronPort-SDR: vL8sbvTnh6QvtIZuLoVWC0MIJ+ojnNFyvFyVy419s1+VwhMOEcu1zV/ihLKWsmTmgrBgNAZ54j byao1fgVa94w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2020 10:54:09 -0700 IronPort-SDR: u/pkWo/VrVW2mU3Zq63orkOZpFVlXjWdAmepysK+reDka1DicOvwWb0Q8fYhSeJSduwKLvOQwZ e1YgzRO4gIug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,449,1583222400"; d="scan'208";a="271292323" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by orsmga006.jf.intel.com with ESMTP; 29 May 2020 10:54:08 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-sgx@vger.kernel.org Subject: [PATCH for_v31 2/6] x86/sgx: Remove unnecessary globals after merging reclaim.c into main.c Date: Fri, 29 May 2020 10:54:03 -0700 Message-Id: <20200529175407.2109-3-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200529175407.2109-1-sean.j.christopherson@intel.com> References: <20200529175407.2109-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Make all variables that are only used in main.c static, rearranging code as needed. Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 16 ++++++---------- arch/x86/kernel/cpu/sgx/sgx.h | 3 --- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 5043d3700960b..ef7061bfa2a07 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -14,9 +14,12 @@ #include "encls.h" static struct task_struct *ksgxswapd_tsk; -DECLARE_WAIT_QUEUE_HEAD(ksgxswapd_waitq); -LIST_HEAD(sgx_active_page_list); -DEFINE_SPINLOCK(sgx_active_page_list_lock); +static DECLARE_WAIT_QUEUE_HEAD(ksgxswapd_waitq); +static LIST_HEAD(sgx_active_page_list); +static DEFINE_SPINLOCK(sgx_active_page_list_lock); + +struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS]; +static int sgx_nr_epc_sections; static void sgx_sanitize_section(struct sgx_epc_section *section) { @@ -45,10 +48,6 @@ static void sgx_sanitize_section(struct sgx_epc_section *section) } } -extern struct task_struct *ksgxswapd_tsk; -extern struct wait_queue_head(ksgxswapd_waitq); -extern spinlock_t sgx_active_page_list_lock; - static unsigned long sgx_nr_free_pages(void) { unsigned long cnt = 0; @@ -491,9 +490,6 @@ void sgx_reclaim_pages(void) } } -struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS]; -int sgx_nr_epc_sections; - static struct sgx_epc_page *__sgx_alloc_epc_page_from_section(struct sgx_epc_section *section) { struct sgx_epc_page *page; diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index 923028d568540..5b9dbcef981b0 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -41,14 +41,11 @@ struct sgx_epc_section { #define SGX_NR_LOW_PAGES 32 #define SGX_NR_HIGH_PAGES 64 -extern struct list_head sgx_active_page_list; - void sgx_mark_page_reclaimable(struct sgx_epc_page *page); int sgx_unmark_page_reclaimable(struct sgx_epc_page *page); void sgx_reclaim_pages(void); extern struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS]; -extern int sgx_nr_epc_sections; static inline struct sgx_epc_section *sgx_get_epc_section( struct sgx_epc_page *page) From patchwork Fri May 29 17:54:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11579447 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5167E14F6 for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4369D2075A for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727994AbgE2RyN (ORCPT ); Fri, 29 May 2020 13:54:13 -0400 Received: from mga14.intel.com ([192.55.52.115]:51589 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726829AbgE2RyM (ORCPT ); Fri, 29 May 2020 13:54:12 -0400 IronPort-SDR: uONlsrNg8bnJNbaBUvEDJdYXID9ofzYdQg2XHEptEBONZEdlGp4++hY3ZAe5LAp24s5dy7Ckar xT/i3MX6PoiQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2020 10:54:09 -0700 IronPort-SDR: oyaowmBIHQMqk0AcOoYuAQLO+xs9vPYJSD2IVwF0Shv5Cr32Mfu1lh26hy+tJIKat+jaEMCntY Etxoiz84k4cQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,449,1583222400"; d="scan'208";a="271292327" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by orsmga006.jf.intel.com with ESMTP; 29 May 2020 10:54:08 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-sgx@vger.kernel.org Subject: [PATCH for_v31 3/6] x86/sgx: Rename sgx_free_page() to sgx_free_epc_page() Date: Fri, 29 May 2020 10:54:04 -0700 Message-Id: <20200529175407.2109-4-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200529175407.2109-1-sean.j.christopherson@intel.com> References: <20200529175407.2109-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Add "epc" into the free page helper to match sgx_alloc_epc_page(). Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/sgx/encl.c | 10 +++++----- arch/x86/kernel/cpu/sgx/ioctl.c | 6 +++--- arch/x86/kernel/cpu/sgx/main.c | 12 ++++++------ arch/x86/kernel/cpu/sgx/sgx.h | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c index c52c937b8d67b..e9d72f05a1f12 100644 --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -73,7 +73,7 @@ static struct sgx_epc_page *sgx_encl_eldu(struct sgx_encl_page *encl_page, ret = __sgx_encl_eldu(encl_page, epc_page, secs_page); if (ret) { - sgx_free_page(epc_page); + sgx_free_epc_page(epc_page); return ERR_PTR(ret); } @@ -482,7 +482,7 @@ void sgx_encl_destroy(struct sgx_encl *encl) if (sgx_unmark_page_reclaimable(entry->epc_page)) continue; - sgx_free_page(entry->epc_page); + sgx_free_epc_page(entry->epc_page); encl->secs_child_cnt--; entry->epc_page = NULL; } @@ -493,7 +493,7 @@ void sgx_encl_destroy(struct sgx_encl *encl) } if (!encl->secs_child_cnt && encl->secs.epc_page) { - sgx_free_page(encl->secs.epc_page); + sgx_free_epc_page(encl->secs.epc_page); encl->secs.epc_page = NULL; } @@ -506,7 +506,7 @@ void sgx_encl_destroy(struct sgx_encl *encl) va_page = list_first_entry(&encl->va_pages, struct sgx_va_page, list); list_del(&va_page->list); - sgx_free_page(va_page->epc_page); + sgx_free_epc_page(va_page->epc_page); kfree(va_page); } } @@ -706,7 +706,7 @@ struct sgx_epc_page *sgx_grab_va_page(void) ret = __epa(sgx_get_epc_addr(epc_page)); if (ret) { WARN_ONCE(1, "EPA returned %d (0x%x)", ret, ret); - sgx_free_page(epc_page); + sgx_free_epc_page(epc_page); return ERR_PTR(-EFAULT); } diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index 2019ee1dc0b3e..f7232a5343262 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -50,7 +50,7 @@ static void sgx_encl_shrink(struct sgx_encl *encl, struct sgx_va_page *va_page) encl->page_cnt--; if (va_page) { - sgx_free_page(va_page->epc_page); + sgx_free_epc_page(va_page->epc_page); list_del(&va_page->list); kfree(va_page); } @@ -223,7 +223,7 @@ static int sgx_encl_create(struct sgx_encl *encl, struct sgx_secs *secs) return 0; err_out: - sgx_free_page(encl->secs.epc_page); + sgx_free_epc_page(encl->secs.epc_page); encl->secs.epc_page = NULL; err_out_backing: @@ -449,7 +449,7 @@ static int sgx_encl_add_page(struct sgx_encl *encl, unsigned long src, up_read(¤t->mm->mmap_sem); err_out_free: - sgx_free_page(epc_page); + sgx_free_epc_page(epc_page); kfree(encl_page); /* diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index ef7061bfa2a07..855b14237e7c4 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -376,7 +376,7 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page, if (!encl->secs_child_cnt) { if (atomic_read(&encl->flags) & SGX_ENCL_DEAD) { - sgx_free_page(encl->secs.epc_page); + sgx_free_epc_page(encl->secs.epc_page); encl->secs.epc_page = NULL; } else if (atomic_read(&encl->flags) & SGX_ENCL_INITIALIZED) { ret = sgx_encl_get_backing(encl, PFN_DOWN(encl->size), @@ -386,7 +386,7 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page, sgx_encl_ewb(encl->secs.epc_page, &secs_backing); - sgx_free_page(encl->secs.epc_page); + sgx_free_epc_page(encl->secs.epc_page); encl->secs.epc_page = NULL; sgx_encl_put_backing(&secs_backing, true); @@ -508,7 +508,7 @@ static struct sgx_epc_page *__sgx_alloc_epc_page_from_section(struct sgx_epc_sec * __sgx_alloc_epc_page() - Grab a free EPC page * * Iterate through EPC sections and borrow a free EPC page to the caller. When a - * page is no longer needed it must be released with sgx_free_page(). + * page is no longer needed it must be released with sgx_free_epc_page(). * * Return: * an EPC page, @@ -539,7 +539,7 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void) * @reclaim: reclaim pages if necessary * * Iterate through EPC sections and borrow a free EPC page to the caller. When a - * page is no longer needed it must be released with sgx_free_page(). If + * page is no longer needed it must be released with sgx_free_epc_page(). If * @reclaim is set to true, directly reclaim pages when we are out of pages. No * mm's can be locked when @reclaim is set to true. * @@ -585,12 +585,12 @@ struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) } /** - * sgx_free_page() - Free an EPC page + * sgx_free_epc_page() - Free an EPC page * @page: an EPC page * * Call EREMOVE for an EPC page and insert it back to the list of free pages. */ -void sgx_free_page(struct sgx_epc_page *page) +void sgx_free_epc_page(struct sgx_epc_page *page) { struct sgx_epc_section *section = sgx_get_epc_section(page); int ret; diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h index 5b9dbcef981b0..2983c1a3d725d 100644 --- a/arch/x86/kernel/cpu/sgx/sgx.h +++ b/arch/x86/kernel/cpu/sgx/sgx.h @@ -62,6 +62,6 @@ static inline void *sgx_get_epc_addr(struct sgx_epc_page *page) struct sgx_epc_page *__sgx_alloc_epc_page(void); struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim); -void sgx_free_page(struct sgx_epc_page *page); +void sgx_free_epc_page(struct sgx_epc_page *page); #endif /* _X86_SGX_H */ From patchwork Fri May 29 17:54:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11579453 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5D3717D1 for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE42F206E2 for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbgE2RyN (ORCPT ); Fri, 29 May 2020 13:54:13 -0400 Received: from mga14.intel.com ([192.55.52.115]:51592 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727964AbgE2RyN (ORCPT ); Fri, 29 May 2020 13:54:13 -0400 IronPort-SDR: jRCJmU2qO7sviZXULxoV996sVLReRtT5+0LNPi5YbD2py4QIF6dIRRu1EVKcOQGR+8nUFdHTbo zG2A+Gzl3UFQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2020 10:54:09 -0700 IronPort-SDR: u+wC8a5T5Zh/zsfQMRMaUdA9fQXjp4j+RtJTu+bHI9l7Zadlj+gFqc8v+A3jp6jFWbgzWNV2wJ G/UjrJehCzXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,449,1583222400"; d="scan'208";a="271292330" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by orsmga006.jf.intel.com with ESMTP; 29 May 2020 10:54:08 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-sgx@vger.kernel.org Subject: [PATCH for_v31 4/6] x86/sgx: Replace "grab" with "alloc" in VA page helper Date: Fri, 29 May 2020 10:54:05 -0700 Message-Id: <20200529175407.2109-5-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200529175407.2109-1-sean.j.christopherson@intel.com> References: <20200529175407.2109-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Rename sgx_grab_va_page() to sgx_alloc_va_page() to align with sgx_alloc_epc_page() as well as sgx_free_epc_page(); the latter is used directly when freeing the VA page, i.e. the names should be consistent. Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/sgx/encl.c | 6 +++--- arch/x86/kernel/cpu/sgx/encl.h | 2 +- arch/x86/kernel/cpu/sgx/ioctl.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c index e9d72f05a1f12..df4ae76dd83f6 100644 --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -686,15 +686,15 @@ struct sgx_encl_page *sgx_encl_reserve_page(struct sgx_encl *encl, } /** - * sgx_grab_va_page() - Grab a Version Array (VA) page + * sgx_alloc_va_page() - Allocate a Version Array (VA) page * - * Grab a free EPC page instance and convert it to a Version Array (VA) page. + * Allocate a free EPC page and convert it to a Version Array (VA) page. * * Return: * a VA page, * -errno otherwise */ -struct sgx_epc_page *sgx_grab_va_page(void) +struct sgx_epc_page *sgx_alloc_va_page(void) { struct sgx_epc_page *epc_page; int ret; diff --git a/arch/x86/kernel/cpu/sgx/encl.h b/arch/x86/kernel/cpu/sgx/encl.h index 625ad44a83215..f0f72e5912445 100644 --- a/arch/x86/kernel/cpu/sgx/encl.h +++ b/arch/x86/kernel/cpu/sgx/encl.h @@ -120,7 +120,7 @@ int sgx_encl_test_and_clear_young(struct mm_struct *mm, struct sgx_encl_page *sgx_encl_reserve_page(struct sgx_encl *encl, unsigned long addr); -struct sgx_epc_page *sgx_grab_va_page(void); +struct sgx_epc_page *sgx_alloc_va_page(void); unsigned int sgx_alloc_va_slot(struct sgx_va_page *va_page); void sgx_free_va_slot(struct sgx_va_page *va_page, unsigned int offset); bool sgx_va_page_full(struct sgx_va_page *va_page); diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index f7232a5343262..4f70cb8144ffd 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -32,7 +32,7 @@ static struct sgx_va_page *sgx_encl_grow(struct sgx_encl *encl) if (!va_page) return ERR_PTR(-ENOMEM); - va_page->epc_page = sgx_grab_va_page(); + va_page->epc_page = sgx_alloc_va_page(); if (IS_ERR(va_page->epc_page)) { err = ERR_CAST(va_page->epc_page); kfree(va_page); From patchwork Fri May 29 17:54:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11579449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8FEE8166C for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 780382073B for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726829AbgE2RyN (ORCPT ); Fri, 29 May 2020 13:54:13 -0400 Received: from mga14.intel.com ([192.55.52.115]:51589 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725913AbgE2RyM (ORCPT ); Fri, 29 May 2020 13:54:12 -0400 IronPort-SDR: E+DYVhe9BbToVfahedcTNwERMQTkTI42UrVojN4gvy2VmwEp57HzYU9JA+2W8XKLXIrpWco5Q1 KpHpvyjPcVeg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2020 10:54:09 -0700 IronPort-SDR: 82hgiKg5LAZ+OT+xGpu6aHO93KSAa+lgTgFB+pBZzMPIogjY9Qy5wPUXgNds1MjsPPXCs8zxkO xk7H0PiPjUFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,449,1583222400"; d="scan'208";a="271292333" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by orsmga006.jf.intel.com with ESMTP; 29 May 2020 10:54:08 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-sgx@vger.kernel.org Subject: [PATCH for_v31 5/6] x86/sgx: Update stale comment in EPC page allocators Date: Fri, 29 May 2020 10:54:06 -0700 Message-Id: <20200529175407.2109-6-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200529175407.2109-1-sean.j.christopherson@intel.com> References: <20200529175407.2109-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Replace "Grab" with "Allocate" in the function comments for the EPC page allocators. Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 855b14237e7c4..ba5486a1ef6f4 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -505,7 +505,7 @@ static struct sgx_epc_page *__sgx_alloc_epc_page_from_section(struct sgx_epc_sec } /** - * __sgx_alloc_epc_page() - Grab a free EPC page + * __sgx_alloc_epc_page() - Allocate a free EPC page * * Iterate through EPC sections and borrow a free EPC page to the caller. When a * page is no longer needed it must be released with sgx_free_epc_page(). @@ -534,7 +534,7 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void) } /** - * sgx_alloc_epc_page() - Grab a free EPC page + * sgx_alloc_epc_page() - Allocate a free EPC page * @owner: the owner of the EPC page * @reclaim: reclaim pages if necessary * From patchwork Fri May 29 17:54:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11579451 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC3CA1392 for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 94D642073B for ; Fri, 29 May 2020 17:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725913AbgE2RyN (ORCPT ); Fri, 29 May 2020 13:54:13 -0400 Received: from mga14.intel.com ([192.55.52.115]:51589 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727995AbgE2RyN (ORCPT ); Fri, 29 May 2020 13:54:13 -0400 IronPort-SDR: STFjqM8/LLDoh8g+4tn8Hk2fn4tZtQcFCaHVoQUzTsgHjKPDz3fZjSyQ9ebCfhTqZm73WI47jv oz8h503Qx9XQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2020 10:54:09 -0700 IronPort-SDR: sNFY45LoKwNd9Q0nGxdo1e/UBNcVFa8KccohghfB7+nk9t4heND7HUokZZs+j5l3WvrDpZyF7l gG1eKyRnwz5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,449,1583222400"; d="scan'208";a="271292336" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by orsmga006.jf.intel.com with ESMTP; 29 May 2020 10:54:08 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-sgx@vger.kernel.org Subject: [PATCH for_v31 6/6] x86/sgx: Drop the message that fires when there are too many EPC sections Date: Fri, 29 May 2020 10:54:07 -0700 Message-Id: <20200529175407.2109-7-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200529175407.2109-1-sean.j.christopherson@intel.com> References: <20200529175407.2109-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Terminate the section loop with '<' instead of '<=' and drop the associated pr_warn in sgx_page_cache_init(). Per Boris, there's no point in warning the user if they can't do anything about it. Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/sgx/main.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index ba5486a1ef6f4..c51a3ad7fcce0 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -692,7 +692,7 @@ static bool __init sgx_page_cache_init(void) u64 pa, size; int i; - for (i = 0; i <= ARRAY_SIZE(sgx_epc_sections); i++) { + for (i = 0; i < ARRAY_SIZE(sgx_epc_sections); i++) { cpuid_count(SGX_CPUID, i + SGX_CPUID_FIRST_VARIABLE_SUB_LEAF, &eax, &ebx, &ecx, &edx); @@ -705,11 +705,6 @@ static bool __init sgx_page_cache_init(void) break; } - if (i == ARRAY_SIZE(sgx_epc_sections)) { - pr_warn("No free slot for an EPC section\n"); - break; - } - pa = sgx_calc_section_metric(eax, ebx); size = sgx_calc_section_metric(ecx, edx);