diff mbox series

[RFC,01/20] x86/sgx: Call cond_resched() at the end of sgx_reclaim_pages()

Message ID 20220922171057.1236139-2-kristen@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series Add Cgroup support for SGX EPC memory | expand

Commit Message

Kristen Carlson Accardi Sept. 22, 2022, 5:10 p.m. UTC
From: Sean Christopherson <sean.j.christopherson@intel.com>

Move the invocation of post-reclaim cond_resched() from the callers of
sgx_reclaim_pages() into the reclaim path itself.   sgx_reclaim_pages()
is always called in a loop and is always followed by a call to
cond_resched().  This will hold true for the EPC cgroup as well, which
adds even more calls to sgx_reclaim_pages() and thus cond_resched().

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com>
Cc: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kernel/cpu/sgx/main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Jarkko Sakkinen Sept. 23, 2022, 12:32 p.m. UTC | #1
On Thu, Sep 22, 2022 at 10:10:38AM -0700, Kristen Carlson Accardi wrote:
> From: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> Move the invocation of post-reclaim cond_resched() from the callers of
> sgx_reclaim_pages() into the reclaim path itself.   sgx_reclaim_pages()
> is always called in a loop and is always followed by a call to
> cond_resched().  This will hold true for the EPC cgroup as well, which
> adds even more calls to sgx_reclaim_pages() and thus cond_resched().

This would be in my opinion better:

"
In order to avoid repetion of cond_sched() in ksgxd() and
sgx_alloc_epc_page(), move the call inside sgx_reclaim_pages().

This will hold true for the EPC cgroup as well, which adds more
call sites sgx_reclaim_pages().
"

This way it is dead obvious and is better description because
it enumerates the consequences (i.e. call sites).

BR, Jarkko
Jarkko Sakkinen Sept. 23, 2022, 12:35 p.m. UTC | #2
On Fri, Sep 23, 2022 at 03:32:43PM +0300, Jarkko Sakkinen wrote:
> On Thu, Sep 22, 2022 at 10:10:38AM -0700, Kristen Carlson Accardi wrote:
> > From: Sean Christopherson <sean.j.christopherson@intel.com>
> > 
> > Move the invocation of post-reclaim cond_resched() from the callers of
> > sgx_reclaim_pages() into the reclaim path itself.   sgx_reclaim_pages()
> > is always called in a loop and is always followed by a call to
> > cond_resched().  This will hold true for the EPC cgroup as well, which
> > adds even more calls to sgx_reclaim_pages() and thus cond_resched().
> 
> This would be in my opinion better:
> 
> "
> In order to avoid repetion of cond_sched() in ksgxd() and
> sgx_alloc_epc_page(), move the call inside sgx_reclaim_pages().
> 
> This will hold true for the EPC cgroup as well, which adds more
> call sites sgx_reclaim_pages().
> "
> 
> This way it is dead obvious and is better description because
> it enumerates the consequences (i.e. call sites).

Forgot 3rd call site: sgx_reclaim_direct(), which is used by
SGX2 ioctls. The call sites of sgx_reclaim_direct() do not
call cond_resched(). You should address why adding this call
to those flows is fine.

BR, Jarkko
Jarkko Sakkinen Sept. 23, 2022, 12:37 p.m. UTC | #3
On Fri, Sep 23, 2022 at 03:35:25PM +0300, Jarkko Sakkinen wrote:
> On Fri, Sep 23, 2022 at 03:32:43PM +0300, Jarkko Sakkinen wrote:
> > On Thu, Sep 22, 2022 at 10:10:38AM -0700, Kristen Carlson Accardi wrote:
> > > From: Sean Christopherson <sean.j.christopherson@intel.com>
> > > 
> > > Move the invocation of post-reclaim cond_resched() from the callers of
> > > sgx_reclaim_pages() into the reclaim path itself.   sgx_reclaim_pages()
> > > is always called in a loop and is always followed by a call to
> > > cond_resched().  This will hold true for the EPC cgroup as well, which
> > > adds even more calls to sgx_reclaim_pages() and thus cond_resched().
> > 
> > This would be in my opinion better:
> > 
> > "
> > In order to avoid repetion of cond_sched() in ksgxd() and
> > sgx_alloc_epc_page(), move the call inside sgx_reclaim_pages().
> > 
> > This will hold true for the EPC cgroup as well, which adds more
> > call sites sgx_reclaim_pages().
> > "
> > 
> > This way it is dead obvious and is better description because
> > it enumerates the consequences (i.e. call sites).
> 
> Forgot 3rd call site: sgx_reclaim_direct(), which is used by
> SGX2 ioctls. The call sites of sgx_reclaim_direct() do not
> call cond_resched(). You should address why adding this call
> to those flows is fine.

Ofc adding a parameter to sgx_reclaim_pages() for cond_resched() call is
other option (not emphasising either option).

BR, Jarkko
diff mbox series

Patch

diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 515e2a5f25bb..4cdeb915dc86 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -367,6 +367,8 @@  static void sgx_reclaim_pages(void)
 
 		sgx_free_epc_page(epc_page);
 	}
+
+	cond_resched();
 }
 
 static bool sgx_should_reclaim(unsigned long watermark)
@@ -410,8 +412,6 @@  static int ksgxd(void *p)
 
 		if (sgx_should_reclaim(SGX_NR_HIGH_PAGES))
 			sgx_reclaim_pages();
-
-		cond_resched();
 	}
 
 	return 0;
@@ -578,7 +578,6 @@  struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim)
 		}
 
 		sgx_reclaim_pages();
-		cond_resched();
 	}
 
 	if (sgx_should_reclaim(SGX_NR_LOW_PAGES))