linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for_v31 0/6]  x86/sgx: Misc fixes for v31
@ 2020-05-29 17:54 Sean Christopherson
  2020-05-29 17:54 ` [PATCH for_v31 1/6] x86/sgx: Fix inadvertant early return from sgx_ioctl() Sean Christopherson
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Sean Christopherson @ 2020-05-29 17:54 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: linux-sgx

One bug fix and a variety of cleanups that apply on top of your current
master, commit b625c3d1370ca ("x86/sgx: Update MAINTAINERS").

Sean Christopherson (6):
  x86/sgx: Fix inadvertant early return from sgx_ioctl()
  x86/sgx: Remove unnecessary globals after merging reclaim.c into
    main.c
  x86/sgx: Rename sgx_free_page() to sgx_free_epc_page()
  x86/sgx: Replace "grab" with "alloc" in VA page helper
  x86/sgx: Update stale comment in EPC page allocators
  x86/sgx: Drop the message that fires when there are too many EPC
    sections

 arch/x86/kernel/cpu/sgx/encl.c  | 16 +++++++-------
 arch/x86/kernel/cpu/sgx/encl.h  |  2 +-
 arch/x86/kernel/cpu/sgx/ioctl.c | 10 ++++-----
 arch/x86/kernel/cpu/sgx/main.c  | 39 +++++++++++++--------------------
 arch/x86/kernel/cpu/sgx/sgx.h   |  5 +----
 5 files changed, 30 insertions(+), 42 deletions(-)

-- 
2.26.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH for_v31 1/6] x86/sgx: Fix inadvertant early return from sgx_ioctl()
  2020-05-29 17:54 [PATCH for_v31 0/6] x86/sgx: Misc fixes for v31 Sean Christopherson
@ 2020-05-29 17:54 ` Sean Christopherson
  2020-05-29 17:54 ` [PATCH for_v31 2/6] x86/sgx: Remove unnecessary globals after merging reclaim.c into main.c Sean Christopherson
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: Sean Christopherson @ 2020-05-29 17:54 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: linux-sgx

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 <sean.j.christopherson@intel.com>
---
 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;
 	}
 
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH for_v31 2/6] x86/sgx: Remove unnecessary globals after merging reclaim.c into main.c
  2020-05-29 17:54 [PATCH for_v31 0/6] x86/sgx: Misc fixes for v31 Sean Christopherson
  2020-05-29 17:54 ` [PATCH for_v31 1/6] x86/sgx: Fix inadvertant early return from sgx_ioctl() Sean Christopherson
@ 2020-05-29 17:54 ` Sean Christopherson
  2020-05-30  8:43   ` Jarkko Sakkinen
  2020-05-29 17:54 ` [PATCH for_v31 3/6] x86/sgx: Rename sgx_free_page() to sgx_free_epc_page() Sean Christopherson
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Sean Christopherson @ 2020-05-29 17:54 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: linux-sgx

Make all variables that are only used in main.c static, rearranging code
as needed.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 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)
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH for_v31 3/6] x86/sgx: Rename sgx_free_page() to sgx_free_epc_page()
  2020-05-29 17:54 [PATCH for_v31 0/6] x86/sgx: Misc fixes for v31 Sean Christopherson
  2020-05-29 17:54 ` [PATCH for_v31 1/6] x86/sgx: Fix inadvertant early return from sgx_ioctl() Sean Christopherson
  2020-05-29 17:54 ` [PATCH for_v31 2/6] x86/sgx: Remove unnecessary globals after merging reclaim.c into main.c Sean Christopherson
@ 2020-05-29 17:54 ` Sean Christopherson
  2020-06-01  0:50   ` Jarkko Sakkinen
  2020-05-29 17:54 ` [PATCH for_v31 4/6] x86/sgx: Replace "grab" with "alloc" in VA page helper Sean Christopherson
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Sean Christopherson @ 2020-05-29 17:54 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: linux-sgx

Add "epc" into the free page helper to match sgx_alloc_epc_page().

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 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(&current->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 */
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH for_v31 4/6] x86/sgx: Replace "grab" with "alloc" in VA page helper
  2020-05-29 17:54 [PATCH for_v31 0/6] x86/sgx: Misc fixes for v31 Sean Christopherson
                   ` (2 preceding siblings ...)
  2020-05-29 17:54 ` [PATCH for_v31 3/6] x86/sgx: Rename sgx_free_page() to sgx_free_epc_page() Sean Christopherson
@ 2020-05-29 17:54 ` Sean Christopherson
  2020-06-01  0:53   ` Jarkko Sakkinen
  2020-05-29 17:54 ` [PATCH for_v31 5/6] x86/sgx: Update stale comment in EPC page allocators Sean Christopherson
  2020-05-29 17:54 ` [PATCH for_v31 6/6] x86/sgx: Drop the message that fires when there are too many EPC sections Sean Christopherson
  5 siblings, 1 reply; 14+ messages in thread
From: Sean Christopherson @ 2020-05-29 17:54 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: linux-sgx

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 <sean.j.christopherson@intel.com>
---
 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);
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH for_v31 5/6] x86/sgx: Update stale comment in EPC page allocators
  2020-05-29 17:54 [PATCH for_v31 0/6] x86/sgx: Misc fixes for v31 Sean Christopherson
                   ` (3 preceding siblings ...)
  2020-05-29 17:54 ` [PATCH for_v31 4/6] x86/sgx: Replace "grab" with "alloc" in VA page helper Sean Christopherson
@ 2020-05-29 17:54 ` Sean Christopherson
  2020-06-01  0:59   ` Jarkko Sakkinen
  2020-05-29 17:54 ` [PATCH for_v31 6/6] x86/sgx: Drop the message that fires when there are too many EPC sections Sean Christopherson
  5 siblings, 1 reply; 14+ messages in thread
From: Sean Christopherson @ 2020-05-29 17:54 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: linux-sgx

Replace "Grab" with "Allocate" in the function comments for the EPC page
allocators.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 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
  *
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH for_v31 6/6] x86/sgx: Drop the message that fires when there are too many EPC sections
  2020-05-29 17:54 [PATCH for_v31 0/6] x86/sgx: Misc fixes for v31 Sean Christopherson
                   ` (4 preceding siblings ...)
  2020-05-29 17:54 ` [PATCH for_v31 5/6] x86/sgx: Update stale comment in EPC page allocators Sean Christopherson
@ 2020-05-29 17:54 ` Sean Christopherson
  2020-06-01  1:01   ` Jarkko Sakkinen
  5 siblings, 1 reply; 14+ messages in thread
From: Sean Christopherson @ 2020-05-29 17:54 UTC (permalink / raw)
  To: Jarkko Sakkinen; +Cc: linux-sgx

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 <sean.j.christopherson@intel.com>
---
 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);
 
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH for_v31 2/6] x86/sgx: Remove unnecessary globals after merging reclaim.c into main.c
  2020-05-29 17:54 ` [PATCH for_v31 2/6] x86/sgx: Remove unnecessary globals after merging reclaim.c into main.c Sean Christopherson
@ 2020-05-30  8:43   ` Jarkko Sakkinen
  2020-05-30  8:47     ` Jarkko Sakkinen
  0 siblings, 1 reply; 14+ messages in thread
From: Jarkko Sakkinen @ 2020-05-30  8:43 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: linux-sgx

On Fri, May 29, 2020 at 10:54:03AM -0700, Sean Christopherson wrote:
> Make all variables that are only used in main.c static, rearranging code
> as needed.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

As with merging, it is a multiphase process to make these changes.

I.e. I'll do manually similar changes but cannot use this patch for
anything.

/Jarkko

> ---
>  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)
> -- 
> 2.26.0
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH for_v31 2/6] x86/sgx: Remove unnecessary globals after merging reclaim.c into main.c
  2020-05-30  8:43   ` Jarkko Sakkinen
@ 2020-05-30  8:47     ` Jarkko Sakkinen
  2020-05-30 10:36       ` Jarkko Sakkinen
  0 siblings, 1 reply; 14+ messages in thread
From: Jarkko Sakkinen @ 2020-05-30  8:47 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: linux-sgx

On Sat, May 30, 2020 at 11:43:39AM +0300, Jarkko Sakkinen wrote:
> On Fri, May 29, 2020 at 10:54:03AM -0700, Sean Christopherson wrote:
> > Make all variables that are only used in main.c static, rearranging code
> > as needed.
> > 
> > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> As with merging, it is a multiphase process to make these changes.
> 
> I.e. I'll do manually similar changes but cannot use this patch for
> anything.

Also this moves sgx_nr_epc_sections and sgx_epc_sections to a wrong
location. Reclaimer code is before other code. I don't understand
why sgx_epc_sections had to be moved as part of changing variables
to static.

/Jarkko

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH for_v31 2/6] x86/sgx: Remove unnecessary globals after merging reclaim.c into main.c
  2020-05-30  8:47     ` Jarkko Sakkinen
@ 2020-05-30 10:36       ` Jarkko Sakkinen
  0 siblings, 0 replies; 14+ messages in thread
From: Jarkko Sakkinen @ 2020-05-30 10:36 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: linux-sgx

On Sat, May 30, 2020 at 11:47:39AM +0300, Jarkko Sakkinen wrote:
> On Sat, May 30, 2020 at 11:43:39AM +0300, Jarkko Sakkinen wrote:
> > On Fri, May 29, 2020 at 10:54:03AM -0700, Sean Christopherson wrote:
> > > Make all variables that are only used in main.c static, rearranging code
> > > as needed.
> > > 
> > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > 
> > As with merging, it is a multiphase process to make these changes.
> > 
> > I.e. I'll do manually similar changes but cannot use this patch for
> > anything.
> 
> Also this moves sgx_nr_epc_sections and sgx_epc_sections to a wrong
> location. Reclaimer code is before other code. I don't understand
> why sgx_epc_sections had to be moved as part of changing variables
> to static.

I think should be right now :-)

/Jarkko

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH for_v31 3/6] x86/sgx: Rename sgx_free_page() to sgx_free_epc_page()
  2020-05-29 17:54 ` [PATCH for_v31 3/6] x86/sgx: Rename sgx_free_page() to sgx_free_epc_page() Sean Christopherson
@ 2020-06-01  0:50   ` Jarkko Sakkinen
  0 siblings, 0 replies; 14+ messages in thread
From: Jarkko Sakkinen @ 2020-06-01  0:50 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: linux-sgx

On Fri, May 29, 2020 at 10:54:04AM -0700, Sean Christopherson wrote:
> Add "epc" into the free page helper to match sgx_alloc_epc_page().
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

Would be better if you find something like this you just send patch
against the commit that introduces the symbol. That way the patch would
have at least some utilitary use.

/Jarkko

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH for_v31 4/6] x86/sgx: Replace "grab" with "alloc" in VA page helper
  2020-05-29 17:54 ` [PATCH for_v31 4/6] x86/sgx: Replace "grab" with "alloc" in VA page helper Sean Christopherson
@ 2020-06-01  0:53   ` Jarkko Sakkinen
  0 siblings, 0 replies; 14+ messages in thread
From: Jarkko Sakkinen @ 2020-06-01  0:53 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: linux-sgx

On Fri, May 29, 2020 at 10:54:05AM -0700, Sean Christopherson wrote:
> 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 <sean.j.christopherson@intel.com>

Thanks I applied this directly to the page reclaimer patch.

/Jarkko

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH for_v31 5/6] x86/sgx: Update stale comment in EPC page allocators
  2020-05-29 17:54 ` [PATCH for_v31 5/6] x86/sgx: Update stale comment in EPC page allocators Sean Christopherson
@ 2020-06-01  0:59   ` Jarkko Sakkinen
  0 siblings, 0 replies; 14+ messages in thread
From: Jarkko Sakkinen @ 2020-06-01  0:59 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: linux-sgx

On Fri, May 29, 2020 at 10:54:06AM -0700, Sean Christopherson wrote:
> Replace "Grab" with "Allocate" in the function comments for the EPC page
> allocators.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

Neither can apply this to anything.

/Jarkko

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH for_v31 6/6] x86/sgx: Drop the message that fires when there are too many EPC sections
  2020-05-29 17:54 ` [PATCH for_v31 6/6] x86/sgx: Drop the message that fires when there are too many EPC sections Sean Christopherson
@ 2020-06-01  1:01   ` Jarkko Sakkinen
  0 siblings, 0 replies; 14+ messages in thread
From: Jarkko Sakkinen @ 2020-06-01  1:01 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: linux-sgx

On Fri, May 29, 2020 at 10:54:07AM -0700, Sean Christopherson wrote:
> 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 <sean.j.christopherson@intel.com>

Applied this directly to the correct patch, thanks.

/Jarkko

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-06-01  1:02 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29 17:54 [PATCH for_v31 0/6] x86/sgx: Misc fixes for v31 Sean Christopherson
2020-05-29 17:54 ` [PATCH for_v31 1/6] x86/sgx: Fix inadvertant early return from sgx_ioctl() Sean Christopherson
2020-05-29 17:54 ` [PATCH for_v31 2/6] x86/sgx: Remove unnecessary globals after merging reclaim.c into main.c Sean Christopherson
2020-05-30  8:43   ` Jarkko Sakkinen
2020-05-30  8:47     ` Jarkko Sakkinen
2020-05-30 10:36       ` Jarkko Sakkinen
2020-05-29 17:54 ` [PATCH for_v31 3/6] x86/sgx: Rename sgx_free_page() to sgx_free_epc_page() Sean Christopherson
2020-06-01  0:50   ` Jarkko Sakkinen
2020-05-29 17:54 ` [PATCH for_v31 4/6] x86/sgx: Replace "grab" with "alloc" in VA page helper Sean Christopherson
2020-06-01  0:53   ` Jarkko Sakkinen
2020-05-29 17:54 ` [PATCH for_v31 5/6] x86/sgx: Update stale comment in EPC page allocators Sean Christopherson
2020-06-01  0:59   ` Jarkko Sakkinen
2020-05-29 17:54 ` [PATCH for_v31 6/6] x86/sgx: Drop the message that fires when there are too many EPC sections Sean Christopherson
2020-06-01  1:01   ` Jarkko Sakkinen

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).