From patchwork Tue Apr 4 07:29:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Huang X-Patchwork-Id: 9660903 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 C76076032D for ; Tue, 4 Apr 2017 07:29:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF3A028285 for ; Tue, 4 Apr 2017 07:29:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A323F2849D; Tue, 4 Apr 2017 07:29:59 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 116BE28285 for ; Tue, 4 Apr 2017 07:29:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 120A32193930D; Tue, 4 Apr 2017 00:29:59 -0700 (PDT) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B707D2193930D for ; Tue, 4 Apr 2017 00:29:57 -0700 (PDT) Received: by mail-pg0-x244.google.com with SMTP id o123so35351804pga.1 for ; Tue, 04 Apr 2017 00:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=bI9LVlvDk+drpFqvWAgA4uWS9Q2ZPy+rFzN2Wu672uk=; b=GZJoa+8X90ThrwDXP34Xa0UXfBCnNcWh3313qS6F6hLQaGgiv6w4KqTXRPnN03eqOb UhQx2yXj+stMuYWwRAxPjdk1dpEDCY7K0//7Jp8oIyua+/YjFxu5OmhuRciobmRL5nk2 emZjInMDTs/giOJptVF3+aw0ZGX75gYskvzmu/vQpJf7jbGlYF9enyFHam0gLAZ+UGgh tAXVxaUElF2mgT0KKFRAeVwzqIZmZUYfsBwTgUyEezXMiWUuNHDzPQykJAJS8G+t26jV z/nXfnae2jqrIgGIZRYcYOJJTzk8bJkXDKwkaurHJ55C+4hG+aR0iA1r/iFyyaeIBEaa +RnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=bI9LVlvDk+drpFqvWAgA4uWS9Q2ZPy+rFzN2Wu672uk=; b=HEiFPG/4HUk1FK+JGk7zMsi+22v4Vm/WUTz7VXwddG2Nybljz+GPv2F0bDDNrLmQzg h1zf8q6/8FUvhh1pM9ticTrSOppZfbIl+rDDlWjGMZYFQ1c/1HCH0IwR5hhwwsgGq5s2 MjFssSnlvUwDpLSskr/b0uYrS6eF4STvg21RbtZ3SMBfMfDCWf5MvYiZCnnH5boDE+9S 39FGZtW3l5NnTFjzMQTG7yO5S0KmOa5pnK3JYm9ARCwC6xS7xnlj3HK+AxPGAmko7DYQ x/yKsuouiQjo+NyBgAziN1DcNgmfLVGj08GGFSA5zGeXUjz50BI51OC6GfttCFS8kBAm YoTg== X-Gm-Message-State: AFeK/H1Mv1mQyMvtcqWV4o/034IW1g9IUysbVZO2RUlzehI2f8taKD4zQcupB9afEi3TeQ== X-Received: by 10.98.211.143 with SMTP id z15mr21669885pfk.46.1491290997140; Tue, 04 Apr 2017 00:29:57 -0700 (PDT) Received: from localhost.localdomain (118-92-235-112.dsl.dyn.ihug.co.nz. [118.92.235.112]) by smtp.gmail.com with ESMTPSA id y7sm29724831pfk.93.2017.04.04.00.29.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 00:29:56 -0700 (PDT) From: Kai Huang X-Google-Original-From: Kai Huang To: intel-sgx-kernel-dev@lists.01.org, jarkko.sakkinen@linux.intel.com Date: Tue, 4 Apr 2017 19:29:35 +1200 Message-Id: <20170404072938.4800-5-kai.huang@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170404072938.4800-1-kai.huang@linux.intel.com> References: <20170404072938.4800-1-kai.huang@linux.intel.com> Subject: [intel-sgx-kernel-dev] [PATCH 4/7] intel_sgx: expose sgx_kmap{kunmap}_epc_page 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 Rename sgx_get{put}_epc_page to sgx_kmap{kunmap}_epc_page, and expose them. For normal memory, get{put}_page increases{decreases} reference count of 'struct page', and they have nothing to do with map/unmap page to kernel virtual address. Rename the equivalent for EPC to follow this convention. Signed-off-by: Kai Huang --- arch/x86/include/asm/sgx.h | 2 ++ drivers/platform/x86/intel_sgx.h | 2 -- drivers/platform/x86/intel_sgx_ioctl.c | 28 ++++++++++++++-------------- drivers/platform/x86/intel_sgx_page_cache.c | 20 ++++++++++---------- drivers/platform/x86/intel_sgx_util.c | 18 ++++++++++-------- drivers/platform/x86/intel_sgx_vma.c | 12 ++++++------ 6 files changed, 42 insertions(+), 40 deletions(-) diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h index 0e3fee1..fe1a2ba 100644 --- a/arch/x86/include/asm/sgx.h +++ b/arch/x86/include/asm/sgx.h @@ -369,5 +369,7 @@ struct sgx_epc_page { struct sgx_epc_page *sgx_epc_pfn_to_page(unsigned long pfn); unsigned long sgx_epc_page_to_pfn(struct sgx_epc_page *entry); +void *sgx_kmap_epc_page(struct sgx_epc_page *entry); +void sgx_kunmap_epc_page(void *epc_page_vaddr); #endif /* _ASM_X86_SGX_H */ diff --git a/drivers/platform/x86/intel_sgx.h b/drivers/platform/x86/intel_sgx.h index da662d0..b9b81d6 100644 --- a/drivers/platform/x86/intel_sgx.h +++ b/drivers/platform/x86/intel_sgx.h @@ -199,8 +199,6 @@ long sgx_compat_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); /* Utility functions */ int sgx_test_and_clear_young(struct sgx_encl_page *page, struct sgx_encl *encl); -void *sgx_get_epc_page(struct sgx_epc_page *entry); -void sgx_put_epc_page(void *epc_page_vaddr); struct page *sgx_get_backing(struct sgx_encl *encl, struct sgx_encl_page *entry, bool pcmd); diff --git a/drivers/platform/x86/intel_sgx_ioctl.c b/drivers/platform/x86/intel_sgx_ioctl.c index 3fc89ac..a8729c3 100644 --- a/drivers/platform/x86/intel_sgx_ioctl.c +++ b/drivers/platform/x86/intel_sgx_ioctl.c @@ -170,13 +170,13 @@ static int sgx_measure(struct sgx_epc_page *secs_page, if (!(j & mrmask)) continue; - secs = sgx_get_epc_page(secs_page); - epc = sgx_get_epc_page(epc_page); + secs = sgx_kmap_epc_page(secs_page); + epc = sgx_kmap_epc_page(epc_page); ret = __eextend(secs, (void *)((unsigned long)epc + i)); - sgx_put_epc_page(epc); - sgx_put_epc_page(secs); + sgx_kunmap_epc_page(epc); + sgx_kunmap_epc_page(secs); } return ret; @@ -193,15 +193,15 @@ static int sgx_add_page(struct sgx_epc_page *secs_page, int ret; pginfo.srcpge = (unsigned long)kmap_atomic(backing); - pginfo.secs = (unsigned long)sgx_get_epc_page(secs_page); - epc_page_vaddr = sgx_get_epc_page(epc_page); + pginfo.secs = (unsigned long)sgx_kmap_epc_page(secs_page); + epc_page_vaddr = sgx_kmap_epc_page(epc_page); pginfo.linaddr = linaddr; pginfo.secinfo = (unsigned long)secinfo; ret = __eadd(&pginfo, epc_page_vaddr); - sgx_put_epc_page(epc_page_vaddr); - sgx_put_epc_page((void *)(unsigned long)pginfo.secs); + sgx_kunmap_epc_page(epc_page_vaddr); + sgx_kunmap_epc_page((void *)(unsigned long)pginfo.secs); kunmap_atomic((void *)(unsigned long)pginfo.srcpge); return ret; @@ -411,7 +411,7 @@ static int sgx_init_page(struct sgx_encl *encl, return PTR_ERR(epc_page); } - vaddr = sgx_get_epc_page(epc_page); + vaddr = sgx_kmap_epc_page(epc_page); if (!vaddr) { sgx_warn(encl, "kmap of a new VA page failed %d\n", ret); @@ -421,7 +421,7 @@ static int sgx_init_page(struct sgx_encl *encl, } ret = __epa(vaddr); - sgx_put_epc_page(vaddr); + sgx_kunmap_epc_page(vaddr); if (ret) { sgx_warn(encl, "EPA returned %d\n", ret); @@ -555,7 +555,7 @@ static long sgx_ioc_enclave_create(struct file *filep, unsigned int cmd, if (ret) goto out; - secs_vaddr = sgx_get_epc_page(secs_epc); + secs_vaddr = sgx_kmap_epc_page(secs_epc); pginfo.srcpge = (unsigned long)secs; pginfo.linaddr = 0; @@ -564,7 +564,7 @@ static long sgx_ioc_enclave_create(struct file *filep, unsigned int cmd, memset(&secinfo, 0, sizeof(secinfo)); ret = __ecreate((void *)&pginfo, secs_vaddr); - sgx_put_epc_page(secs_vaddr); + sgx_kunmap_epc_page(secs_vaddr); if (ret) { sgx_dbg(encl, "ECREATE returned %ld\n", ret); @@ -828,9 +828,9 @@ static int __sgx_encl_init(struct sgx_encl *encl, char *sigstruct, for (i = 0; i < SGX_EINIT_SLEEP_COUNT; i++) { for (j = 0; j < SGX_EINIT_SPIN_COUNT; j++) { mutex_lock(&encl->lock); - secs_va = sgx_get_epc_page(secs_epc); + secs_va = sgx_kmap_epc_page(secs_epc); ret = __einit(sigstruct, einittoken, secs_va); - sgx_put_epc_page(secs_va); + sgx_kunmap_epc_page(secs_va); mutex_unlock(&encl->lock); if (ret == SGX_UNMASKED_EVENT) continue; diff --git a/drivers/platform/x86/intel_sgx_page_cache.c b/drivers/platform/x86/intel_sgx_page_cache.c index 8d323f4..3f9ba9c 100644 --- a/drivers/platform/x86/intel_sgx_page_cache.c +++ b/drivers/platform/x86/intel_sgx_page_cache.c @@ -225,9 +225,9 @@ static void sgx_eblock(struct sgx_encl *encl, void *vaddr; int ret; - vaddr = sgx_get_epc_page(epc_page); + vaddr = sgx_kmap_epc_page(epc_page); ret = __eblock((unsigned long)vaddr); - sgx_put_epc_page(vaddr); + sgx_kunmap_epc_page(vaddr); if (ret) { sgx_crit(encl, "EBLOCK returned %d\n", ret); @@ -242,9 +242,9 @@ static void sgx_etrack(struct sgx_encl *encl) void *epc; int ret; - epc = sgx_get_epc_page(encl->secs_page.epc_page); + epc = sgx_kmap_epc_page(encl->secs_page.epc_page); ret = __etrack(epc); - sgx_put_epc_page(epc); + sgx_kunmap_epc_page(epc); if (ret) { sgx_crit(encl, "ETRACK returned %d\n", ret); @@ -282,8 +282,8 @@ static int __sgx_ewb(struct sgx_encl *encl, goto out; } - epc = sgx_get_epc_page(encl_page->epc_page); - va = sgx_get_epc_page(encl_page->va_page->epc_page); + epc = sgx_kmap_epc_page(encl_page->epc_page); + va = sgx_kmap_epc_page(encl_page->va_page->epc_page); pginfo.srcpge = (unsigned long)kmap_atomic(backing); pginfo.pcmd = (unsigned long)kmap_atomic(pcmd) + pcmd_offset; @@ -294,8 +294,8 @@ static int __sgx_ewb(struct sgx_encl *encl, kunmap_atomic((void *)(unsigned long)(pginfo.pcmd - pcmd_offset)); kunmap_atomic((void *)(unsigned long)pginfo.srcpge); - sgx_put_epc_page(va); - sgx_put_epc_page(epc); + sgx_kunmap_epc_page(va); + sgx_kunmap_epc_page(epc); sgx_put_backing(pcmd, true); out: @@ -597,9 +597,9 @@ int sgx_free_page(struct sgx_epc_page *entry, struct sgx_encl *encl, void *epc; int ret; - epc = sgx_get_epc_page(entry); + epc = sgx_kmap_epc_page(entry); ret = __eremove(epc); - sgx_put_epc_page(epc); + sgx_kunmap_epc_page(epc); if (ret) { if (flags & SGX_FREE_RETURN_ERROR) diff --git a/drivers/platform/x86/intel_sgx_util.c b/drivers/platform/x86/intel_sgx_util.c index 6d36b98..c63193d 100644 --- a/drivers/platform/x86/intel_sgx_util.c +++ b/drivers/platform/x86/intel_sgx_util.c @@ -125,7 +125,7 @@ unsigned long sgx_epc_page_to_pfn(struct sgx_epc_page *entry) } EXPORT_SYMBOL_GPL(sgx_epc_page_to_pfn); -void *sgx_get_epc_page(struct sgx_epc_page *entry) +void *sgx_kmap_epc_page(struct sgx_epc_page *entry) { #ifdef CONFIG_X86_32 return kmap_atomic_pfn(sgx_epc_page_to_pfn(entry)); @@ -138,14 +138,16 @@ void *sgx_get_epc_page(struct sgx_epc_page *entry) return bank->mem + ((entry - bank->epgtbl) << PAGE_SHIFT); #endif } +EXPORT_SYMBOL_GPL(sgx_kmap_epc_page); -void sgx_put_epc_page(void *epc_page_vaddr) +void sgx_kunmap_epc_page(void *epc_page_vaddr) { #ifdef CONFIG_X86_32 kunmap_atomic(epc_page_vaddr); #else #endif } +EXPORT_SYMBOL_GPL(sgx_kunmap_epc_page); struct page *sgx_get_backing(struct sgx_encl *encl, struct sgx_encl_page *entry, @@ -313,10 +315,10 @@ static int sgx_eldu(struct sgx_encl *encl, } if (!is_secs) - secs_ptr = sgx_get_epc_page(encl->secs_page.epc_page); + secs_ptr = sgx_kmap_epc_page(encl->secs_page.epc_page); - epc_ptr = sgx_get_epc_page(epc_page); - va_ptr = sgx_get_epc_page(encl_page->va_page->epc_page); + epc_ptr = sgx_kmap_epc_page(epc_page); + va_ptr = sgx_kmap_epc_page(encl_page->va_page->epc_page); pginfo.srcpge = (unsigned long)kmap_atomic(backing); pginfo.pcmd = (unsigned long)kmap_atomic(pcmd) + pcmd_offset; pginfo.linaddr = is_secs ? 0 : encl_page->addr; @@ -333,11 +335,11 @@ static int sgx_eldu(struct sgx_encl *encl, kunmap_atomic((void *)(unsigned long)(pginfo.pcmd - pcmd_offset)); kunmap_atomic((void *)(unsigned long)pginfo.srcpge); - sgx_put_epc_page(va_ptr); - sgx_put_epc_page(epc_ptr); + sgx_kunmap_epc_page(va_ptr); + sgx_kunmap_epc_page(epc_ptr); if (!is_secs) - sgx_put_epc_page(secs_ptr); + sgx_kunmap_epc_page(secs_ptr); sgx_put_backing(pcmd, false); diff --git a/drivers/platform/x86/intel_sgx_vma.c b/drivers/platform/x86/intel_sgx_vma.c index 854bd7a..d80b22a 100644 --- a/drivers/platform/x86/intel_sgx_vma.c +++ b/drivers/platform/x86/intel_sgx_vma.c @@ -132,10 +132,10 @@ static inline int sgx_vma_access_word(struct sgx_encl *encl, return -ECANCELED; if (align || (cnt != sizeof(unsigned long))) { - vaddr = sgx_get_epc_page(encl_page->epc_page); + vaddr = sgx_kmap_epc_page(encl_page->epc_page); ret = __edbgrd((void *)((unsigned long)vaddr + offset), (unsigned long *)data); - sgx_put_epc_page(vaddr); + sgx_kunmap_epc_page(vaddr); if (ret) { sgx_dbg(encl, "EDBGRD returned %d\n", ret); return -EFAULT; @@ -143,10 +143,10 @@ static inline int sgx_vma_access_word(struct sgx_encl *encl, } memcpy(data + align, buf + i, cnt); - vaddr = sgx_get_epc_page(encl_page->epc_page); + vaddr = sgx_kmap_epc_page(encl_page->epc_page); ret = __edbgwr((void *)((unsigned long)vaddr + offset), (unsigned long *)data); - sgx_put_epc_page(vaddr); + sgx_kunmap_epc_page(vaddr); if (ret) { sgx_dbg(encl, "EDBGWR returned %d\n", ret); return -EFAULT; @@ -156,10 +156,10 @@ static inline int sgx_vma_access_word(struct sgx_encl *encl, (offset + (len - i)) > 72) return -ECANCELED; - vaddr = sgx_get_epc_page(encl_page->epc_page); + vaddr = sgx_kmap_epc_page(encl_page->epc_page); ret = __edbgrd((void *)((unsigned long)vaddr + offset), (unsigned long *)data); - sgx_put_epc_page(vaddr); + sgx_kunmap_epc_page(vaddr); if (ret) { sgx_dbg(encl, "EDBGRD returned %d\n", ret); return -EFAULT;