linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	linux-sgx@vger.kernel.org, akpm@linux-foundation.org,
	dave.hansen@intel.com, nhorman@redhat.com, npmccallum@redhat.com,
	haitao.huang@intel.com, andriy.shevchenko@linux.intel.com,
	tglx@linutronix.de, kai.svahn@intel.com, josh@joshtriplett.org,
	luto@kernel.org, kai.huang@intel.com, rientjes@google.com,
	cedric.xing@intel.com, puiterwijk@redhat.com,
	Jethro Beekman <jethro@fortanix.com>
Subject: Re: [PATCH v30 08/20] x86/sgx: Add functions to allocate and free EPC pages
Date: Thu, 28 May 2020 04:23:19 +0300	[thread overview]
Message-ID: <20200528012319.GA7577@linux.intel.com> (raw)
In-Reply-To: <20200527204638.GG1721@zn.tnic>

[-- Attachment #1: Type: text/plain, Size: 1651 bytes --]

On Wed, May 27, 2020 at 10:46:38PM +0200, Borislav Petkov wrote:
> On Tue, May 26, 2020 at 09:21:11PM -0700, Sean Christopherson wrote:
> > In other words, sgx_alloc_epc_section() is poorly named.  It doesn't
> > actually allocate EPC, it allocates kernel structures to map and track EPC.
> > sgx_(un)map_epc_section() would be more accurate and would hopefully
> > alleviate some of the confusion.
> 
> Makes sense.
> 
> > I have no objection to renaming __sgx_alloc_try_alloc_page() to something
> > like sgx_alloc_epc_page_section or whatever, but IMO using get/put will be
> > horrendously confusing.
> 
> Ok. My only issue is that the naming nomenclature sounds strange and
> confusing as it is. "try" in an "alloc" function is kinda tautological -
> of course the function will try to do its best. :)
> 
> And there are three functions having "alloc" in the name so I can
> imagine someone getting very confused when having to stare at that code.
> 
> So at least naming them in a way so that it is clear what kind of pages
> they "allocate" - i.e., what they actually do - would be a step in the
> right direction...
> 
> Thx.

I also think sgx_get_epc_page() is also kind of confusing name. The
reason is that "get" can many things.

I'm not sure I follow fully Sean's reasoning but the way alloc is used
mostly in Linux is to ask through some API the used kernel memory
allocator to give memory for some kernel data structures.

Agreed that it is not the best match on what we are doing.

The first common verb that comes to my mind about the action taken is
grabbing. Attached a patch reflecting this idea that I'm ready to
squash.

/Jarkko

[-- Attachment #2: 0001-x86-sgx-sgx_alloc_page-to-sgx_grab_page.patch --]
[-- Type: text/x-diff, Size: 5256 bytes --]

From 2598b920fc917790966ba314a2df524ff4695c75 Mon Sep 17 00:00:00 2001
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Date: Thu, 28 May 2020 04:21:08 +0300
Subject: [PATCH] x86/sgx: sgx_alloc_page() to sgx_grab_page()

$ git  grep -l sgx_alloc_page | xargs sed -i 's/sgx_alloc_page/sgx_grab_page/g'
$ git  grep -l sgx_try_alloc_page | xargs sed -i 's/sgx_try_alloc_page/sgx_try_grab_page/g'

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 arch/x86/kernel/cpu/sgx/encl.c  |  6 +++---
 arch/x86/kernel/cpu/sgx/ioctl.c |  4 ++--
 arch/x86/kernel/cpu/sgx/main.c  | 14 +++++++-------
 arch/x86/kernel/cpu/sgx/sgx.h   |  4 ++--
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index c070aa90b5fe..fab2a8aec410 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -67,7 +67,7 @@ static struct sgx_epc_page *sgx_encl_eldu(struct sgx_encl_page *encl_page,
 	struct sgx_epc_page *epc_page;
 	int ret;
 
-	epc_page = sgx_alloc_page(encl_page, false);
+	epc_page = sgx_grab_page(encl_page, false);
 	if (IS_ERR(epc_page))
 		return epc_page;
 
@@ -686,7 +686,7 @@ struct sgx_encl_page *sgx_encl_reserve_page(struct sgx_encl *encl,
 }
 
 /**
- * sgx_alloc_page - allocate a VA page
+ * sgx_grab_page - allocate a VA page
  *
  * Allocates an &sgx_epc_page instance and converts it to a VA page.
  *
@@ -699,7 +699,7 @@ struct sgx_epc_page *sgx_alloc_va_page(void)
 	struct sgx_epc_page *epc_page;
 	int ret;
 
-	epc_page = sgx_alloc_page(NULL, true);
+	epc_page = sgx_grab_page(NULL, true);
 	if (IS_ERR(epc_page))
 		return ERR_CAST(epc_page);
 
diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c
index 81b6c5d64c96..c880dc40310c 100644
--- a/arch/x86/kernel/cpu/sgx/ioctl.c
+++ b/arch/x86/kernel/cpu/sgx/ioctl.c
@@ -183,7 +183,7 @@ static int sgx_encl_create(struct sgx_encl *encl, struct sgx_secs *secs)
 
 	encl->backing = backing;
 
-	secs_epc = sgx_alloc_page(&encl->secs, true);
+	secs_epc = sgx_grab_page(&encl->secs, true);
 	if (IS_ERR(secs_epc)) {
 		ret = PTR_ERR(secs_epc);
 		goto err_out_backing;
@@ -376,7 +376,7 @@ static int sgx_encl_add_page(struct sgx_encl *encl, unsigned long src,
 	if (IS_ERR(encl_page))
 		return PTR_ERR(encl_page);
 
-	epc_page = sgx_alloc_page(encl_page, true);
+	epc_page = sgx_grab_page(encl_page, true);
 	if (IS_ERR(epc_page)) {
 		kfree(encl_page);
 		return PTR_ERR(epc_page);
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 5ce77e554676..b5cd941861bc 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -14,7 +14,7 @@
 struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS];
 int sgx_nr_epc_sections;
 
-static struct sgx_epc_page *__sgx_try_alloc_page(struct sgx_epc_section *section)
+static struct sgx_epc_page *__sgx_try_grab_page(struct sgx_epc_section *section)
 {
 	struct sgx_epc_page *page;
 
@@ -29,7 +29,7 @@ static struct sgx_epc_page *__sgx_try_alloc_page(struct sgx_epc_section *section
 }
 
 /**
- * sgx_try_alloc_page() - Allocate an EPC page
+ * sgx_try_grab_page() - Allocate an EPC page
  *
  * Try to grab a page from the free EPC page list.
  *
@@ -37,7 +37,7 @@ static struct sgx_epc_page *__sgx_try_alloc_page(struct sgx_epc_section *section
  *   a pointer to a &struct sgx_epc_page instance,
  *   -errno on error
  */
-struct sgx_epc_page *sgx_try_alloc_page(void)
+struct sgx_epc_page *sgx_try_grab_page(void)
 {
 	struct sgx_epc_section *section;
 	struct sgx_epc_page *page;
@@ -46,7 +46,7 @@ struct sgx_epc_page *sgx_try_alloc_page(void)
 	for (i = 0; i < sgx_nr_epc_sections; i++) {
 		section = &sgx_epc_sections[i];
 		spin_lock(&section->lock);
-		page = __sgx_try_alloc_page(section);
+		page = __sgx_try_grab_page(section);
 		spin_unlock(&section->lock);
 
 		if (page)
@@ -57,7 +57,7 @@ struct sgx_epc_page *sgx_try_alloc_page(void)
 }
 
 /**
- * sgx_alloc_page() - Allocate an EPC page
+ * sgx_grab_page() - Allocate an EPC page
  * @owner:	the owner of the EPC page
  * @reclaim:	reclaim pages if necessary
  *
@@ -69,12 +69,12 @@ struct sgx_epc_page *sgx_try_alloc_page(void)
  *   a pointer to a &struct sgx_epc_page instance,
  *   -errno on error
  */
-struct sgx_epc_page *sgx_alloc_page(void *owner, bool reclaim)
+struct sgx_epc_page *sgx_grab_page(void *owner, bool reclaim)
 {
 	struct sgx_epc_page *entry;
 
 	for ( ; ; ) {
-		entry = sgx_try_alloc_page();
+		entry = sgx_try_grab_page();
 		if (!IS_ERR(entry)) {
 			entry->owner = owner;
 			break;
diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h
index 0c481e6f2c95..84198c17e766 100644
--- a/arch/x86/kernel/cpu/sgx/sgx.h
+++ b/arch/x86/kernel/cpu/sgx/sgx.h
@@ -101,8 +101,8 @@ 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);
 
-struct sgx_epc_page *sgx_try_alloc_page(void);
-struct sgx_epc_page *sgx_alloc_page(void *owner, bool reclaim);
+struct sgx_epc_page *sgx_try_grab_page(void);
+struct sgx_epc_page *sgx_grab_page(void *owner, bool reclaim);
 void sgx_free_page(struct sgx_epc_page *page);
 
 #endif /* _X86_SGX_H */
-- 
2.25.1


  parent reply	other threads:[~2020-05-28  1:23 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15  0:43 [PATCH v30 00/20] Intel SGX foundations Jarkko Sakkinen
2020-05-15  0:43 ` [PATCH v30 01/20] x86/cpufeatures: x86/msr: Add Intel SGX hardware bits Jarkko Sakkinen
2020-05-20 12:16   ` Borislav Petkov
2020-05-20 14:00     ` Jarkko Sakkinen
2020-05-15  0:43 ` [PATCH v30 02/20] x86/cpufeatures: x86/msr: Intel SGX Launch Control " Jarkko Sakkinen
2020-05-20 12:23   ` Borislav Petkov
2020-05-20 14:04     ` Jarkko Sakkinen
2020-05-15  0:43 ` [PATCH v30 03/20] x86/mm: x86/sgx: Signal SIGSEGV with PF_SGX Jarkko Sakkinen
2020-05-15  0:43 ` [PATCH v30 04/20] x86/sgx: Add SGX microarchitectural data structures Jarkko Sakkinen
2020-05-20 18:47   ` Borislav Petkov
2020-05-20 21:04     ` Sean Christopherson
2020-05-22 15:54     ` Jarkko Sakkinen
2020-05-22 16:13       ` Sean Christopherson
2020-05-22 19:50         ` Jarkko Sakkinen
2020-05-25  8:20           ` Borislav Petkov
2020-05-27 19:43             ` Jarkko Sakkinen
2020-05-15  0:43 ` [PATCH v30 05/20] x86/sgx: Add wrappers for ENCLS leaf functions Jarkko Sakkinen
2020-05-15  0:43 ` [PATCH v30 06/20] x86/cpu/intel: Detect SGX support Jarkko Sakkinen
2020-05-15  0:43 ` [PATCH v30 07/20] x86/sgx: Enumerate and track EPC sections Jarkko Sakkinen
2020-05-25  9:23   ` Borislav Petkov
2020-05-27  3:56     ` Sean Christopherson
2020-05-27 20:35       ` Borislav Petkov
2020-05-28  7:36         ` Jarkko Sakkinen
2020-05-28  5:25       ` Jarkko Sakkinen
2020-05-28  5:35         ` Jarkko Sakkinen
2020-05-28  6:14           ` Jarkko Sakkinen
2020-05-28  6:16             ` Jarkko Sakkinen
2020-05-28  5:13     ` Jarkko Sakkinen
2020-05-15  0:43 ` [PATCH v30 08/20] x86/sgx: Add functions to allocate and free EPC pages Jarkko Sakkinen
2020-05-26 12:52   ` Borislav Petkov
2020-05-27  4:21     ` Sean Christopherson
2020-05-27 20:46       ` Borislav Petkov
2020-05-28  0:52         ` Sean Christopherson
2020-05-28  6:51           ` Jarkko Sakkinen
2020-05-28  1:23         ` Jarkko Sakkinen [this message]
2020-05-28  1:36           ` Sean Christopherson
2020-05-28  6:52             ` Jarkko Sakkinen
2020-05-28 17:16               ` Borislav Petkov
2020-05-28 17:19                 ` Sean Christopherson
2020-05-28 17:27                   ` Borislav Petkov
2020-05-28 17:34                     ` Sean Christopherson
2020-05-28 19:07                 ` Jarkko Sakkinen
2020-05-28 19:59                   ` Sean Christopherson
2020-05-29  3:28                     ` Jarkko Sakkinen
2020-05-29  3:37                       ` Sean Christopherson
2020-05-29  5:07                         ` Jarkko Sakkinen
2020-05-29  8:12                         ` Jarkko Sakkinen
2020-05-29  8:13                           ` Jarkko Sakkinen
2020-05-29  3:38                       ` Jarkko Sakkinen
2020-05-15  0:43 ` [PATCH v30 09/20] mm: Introduce vm_ops->may_mprotect() Jarkko Sakkinen
2020-05-29 12:10   ` Borislav Petkov
2020-05-29 18:18     ` Jarkko Sakkinen
2020-05-29 18:28   ` Dave Hansen
2020-05-31 23:12     ` Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 10/20] x86/sgx: Linux Enclave Driver Jarkko Sakkinen
2020-05-21 19:12   ` Sean Christopherson
2020-05-22 19:26     ` Jarkko Sakkinen
2020-05-22 19:39     ` Jarkko Sakkinen
2020-05-22  3:33   ` Sean Christopherson
2020-05-15  0:44 ` [PATCH v30 11/20] x86/sgx: Add provisioning Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 12/20] x86/sgx: Add a page reclaimer Jarkko Sakkinen
2020-05-22  6:58   ` Sean Christopherson
2020-05-22 19:57     ` Jarkko Sakkinen
2020-05-22 21:52       ` Sean Christopherson
2020-05-22  7:15   ` Sean Christopherson
2020-05-22 19:47     ` Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 13/20] x86/sgx: ptrace() support for the SGX driver Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 14/20] x86/vdso: Add support for exception fixup in vDSO functions Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 15/20] x86/fault: Add helper function to sanitize error code Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 16/20] x86/traps: Attempt to fixup exceptions in vDSO before signaling Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 17/20] x86/vdso: Implement a vDSO for Intel SGX enclave call Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 18/20] selftests/x86: Add a selftest for SGX Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 19/20] docs: x86/sgx: Document SGX micro architecture and kernel internals Jarkko Sakkinen
2020-05-15  0:44 ` [PATCH v30 20/20] x86/sgx: Update MAINTAINERS Jarkko Sakkinen
2020-05-16  8:57 ` [PATCH] x86/cpu/intel: Add nosgx kernel parameter Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200528012319.GA7577@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=cedric.xing@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=haitao.huang@intel.com \
    --cc=jethro@fortanix.com \
    --cc=josh@joshtriplett.org \
    --cc=kai.huang@intel.com \
    --cc=kai.svahn@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=nhorman@redhat.com \
    --cc=npmccallum@redhat.com \
    --cc=puiterwijk@redhat.com \
    --cc=rientjes@google.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).