[PATCH v17 15/16] Docs/x86/sgx: Add description for cgroup support

2024-08-30 Thread Haitao Huang
-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Bagas Sanjaya Reviewed-by: Jarkko Sakkinen Acked-by: Kai Huang Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V8: - Limit text width to 80 characters to be consistent. V6: - Remove mentioning of VMM

[PATCH v17 14/16] x86/sgx: Turn on per-cgroup EPC reclamation

2024-08-30 Thread Haitao Huang
reclamation and per-cgroup reclamation both work properly with all pages tracked in per-cgroup LRUs. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko

[PATCH v17 10/16] x86/sgx: Implement async reclamation for cgroup

2024-08-30 Thread Haitao Huang
ronous per-cgroup EPC reclamation when the usage reaches the threshold after try_charge() is successful. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Tested-by: Jarkk

[PATCH v17 07/16] x86/sgx: Abstract tracking reclaimable pages in LRU

2024-08-30 Thread Haitao Huang
ing to the global LRU directly. This allows EPC page being able to be tracked in "per-cgroup" LRU when that becomes ready. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haita

[PATCH v17 16/16] selftests/sgx: Add scripts for EPC cgroup testing

2024-08-30 Thread Haitao Huang
, it turns off swapping before start, and turns swapping back on afterwards. Add README to document how to run the tests. Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen Acked-by: Kai Huang --- V13: - More improvement on handling error cases and style fixes

[PATCH v17 13/16] x86/sgx: Revise global reclamation for EPC cgroups

2024-08-30 Thread Haitao Huang
ot;) SGX_NR_TO_SCAN pages _across_ the given EPC cgroup _AND_ its descendants, and then do the actual reclaim in one batch. But this is unnecessarily complicated at this stage to address such rare cases. Signed-off-by: Haitao Huang Reviewed-by: Kai Huang Reviewed-by: Jarkko Sakkinen -

[PATCH v17 06/16] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

2024-08-30 Thread Haitao Huang
Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko Sakkinen --- V17: - Make comment for spinlock more accurate. V15: - Add comment for spinlock. (Jarkko, Kai) V6: - removed

[PATCH v17 05/16] x86/sgx: Implement basic EPC misc cgroup functionality

2024-08-30 Thread Haitao Huang
shold. Later patches will reorganize the tracking and reclamation code in the global reclaimer and implement per-cgroup tracking and reclaiming. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-of

[PATCH v17 12/16] x86/sgx: Implement direct reclamation for cgroups

2024-08-30 Thread Haitao Huang
g/all/a0d8f037c4a075d56bf79f432438412985f7ff7a.1652137848.git.reinette.cha...@intel.com/T/#u Signed-off-by: Haitao Huang Reviewed-by: Kai Huang Reviewed-by: Jarkko Sakkinen --- V17: - Improve comments and capitalization. (Kai) --- arch/x86/kernel/cpu/sgx/epc_cgroup.c | 15 +++ arch/x86/k

[PATCH v17 11/16] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-08-30 Thread Haitao Huang
for an mm struct from enclave's mm_list. Signed-off-by: Haitao Huang Reported-by: Mikko Ylinen Reviewed-by: Kai Huang Reviewed-by: Jarkko Sakkinen Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V10: - Pass mm struct instead of a boolean 'indirect'. (Dave, Jarkko) V9:

[PATCH v17 09/16] x86/sgx: Add basic EPC reclamation flow for cgroup

2024-08-30 Thread Haitao Huang
en Carlson Accardi Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Reviewed-by: Kai Huang Reviewed-by: Jarkko Sakkinen --- V17: - Fix grammar in commit and improve comments.(Kai) - Fix error in initializing 'next' in sgx_cgroup_next_descendant_pre() V16: - Revise comm

[PATCH v17 04/16] cgroup/misc: Add SGX EPC resource type

2024-08-30 Thread Haitao Huang
From: Kristen Carlson Accardi Add SGX EPC memory, MISC_CG_RES_SGX_EPC, to be a valid resource type for the misc controller. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko

[PATCH v17 03/16] cgroup/misc: Expose APIs for SGX driver

2024-08-30 Thread Haitao Huang
needs start a global level reclamation from the root. Expose misc_cg_root() for the SGX driver to access. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Tejun Heo Reviewed-by: Kai Huang Tested-by: J

[PATCH v17 08/16] x86/sgx: Encapsulate uses of the global LRU

2024-08-30 Thread Haitao Huang
eparate the two cases. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Co-developed-by: Kristen Carlson Accardi Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Reviewed-by: Kai Huang Reviewed-by: Jarkko Sakkinen --- V17: - remove comments in sgx_can

[PATCH v17 02/16] cgroup/misc: Add per resource callbacks for CSS events

2024-08-30 Thread Haitao Huang
sc_cg' to the callbacks but not the 'struct misc_res' because the latter doesn't have a pointer pointing back to 'struct misc_cg'. Link: https://lore.kernel.org/lkml/op.2kdw36otwjv...@hhuan26-mobl.amr.corp.intel.com/ Signed-off-by: Kristen Carlson Accardi Co-developed-b

[PATCH v17 01/16] x86/sgx: Replace boolean parameters with enums

2024-08-30 Thread Haitao Huang
Replace boolean parameters for 'reclaim' in the function sgx_alloc_epc_page() and its callers with an enum. Also opportunistically remove non-static declaration of __sgx_alloc_epc_page() and a typo Signed-off-by: Haitao Huang Suggested-by: Jarkko Sakkinen Suggested-by: Dave Hansen R

[PATCH v17 00/16] Add Cgroup support for SGX EPC memory

2024-08-30 Thread Haitao Huang
-sgx/20240531222630.4634-1-haitao.hu...@linux.intel.com/T/#t [20]v15: https://lore.kernel.org/linux-sgx/20240617125321.36658-1-haitao.hu...@linux.intel.com/T/#t [21]v16: https://lore.kernel.org/lkml/20240821015404.6038-1-haitao.hu...@linux.intel.com/T/#t Haitao Huang (7): x86/sgx: Replace boolea

Re: [PATCH v16 09/16] x86/sgx: Add basic EPC reclamation flow for cgroup

2024-08-21 Thread Haitao Huang
+static struct sgx_cgroup *sgx_cgroup_next_descendant_pre(struct sgx_cgroup *root, +struct sgx_cgroup *cg) +{ + struct cgroup_subsys_state *next; + + rcu_read_lock(); + for (;;) { + next = css_next_descendant

[PATCH v16 16/16] selftests/sgx: Add scripts for EPC cgroup testing

2024-08-20 Thread Haitao Huang
, it turns off swapping before start, and turns swapping back on afterwards. Add README to document how to run the tests. Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen --- V13: - More improvement on handling error cases and style fixes. - Add settings file

[PATCH v16 15/16] Docs/x86/sgx: Add description for cgroup support

2024-08-20 Thread Haitao Huang
-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Bagas Sanjaya Reviewed-by: Jarkko Sakkinen Acked-by: Kai Huang Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V8: - Limit text width to 80 characters to be consistent. V6: - Remove mentioning of VMM

[PATCH v16 14/16] x86/sgx: Turn on per-cgroup EPC reclamation

2024-08-20 Thread Haitao Huang
reclamation and per-cgroup reclamation both work properly with all pages tracked in per-cgroup LRUs. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko

[PATCH v16 13/16] x86/sgx: implement direct reclamation for cgroups

2024-08-20 Thread Haitao Huang
g/all/a0d8f037c4a075d56bf79f432438412985f7ff7a.1652137848.git.reinette.cha...@intel.com/T/#u Signed-off-by: Haitao Huang --- arch/x86/kernel/cpu/sgx/epc_cgroup.c | 15 +++ arch/x86/kernel/cpu/sgx/epc_cgroup.h | 3 +++ arch/x86/kernel/cpu/sgx/main.c | 4 3 files changed, 22 inser

[PATCH v16 12/16] x86/sgx: Revise global reclamation for EPC cgroups

2024-08-20 Thread Haitao Huang
be to have a new function to only "scan" (or "isolate") SGX_NR_TO_SCAN pages _across_ the given EPC cgroup _AND_ its descendants, and then do the actual reclaim in one batch. But this is unnecessarily complicated at this stage to address such rare cases. Signed-off-by: Haitao Hu

[PATCH v16 11/16] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-08-20 Thread Haitao Huang
for an mm struct from enclave's mm_list. Signed-off-by: Haitao Huang Reported-by: Mikko Ylinen Reviewed-by: Kai Huang Reviewed-by: Jarkko Sakkinen Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V10: - Pass mm struct instead of a boolean 'indirect'. (Dave, Jarkko) V9:

[PATCH v16 10/16] x86/sgx: Implement async reclamation for cgroup

2024-08-20 Thread Haitao Huang
ronous per-cgroup EPC reclamation when the usage reaches the threshold after try_charge() is successful. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Tested-by: Jarkk

[PATCH v16 09/16] x86/sgx: Add basic EPC reclamation flow for cgroup

2024-08-20 Thread Haitao Huang
en Carlson Accardi Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang --- V16: - Revise commit log to define reclamation requirement and the design more clearly. (Kai) - Revise sgx_cgroup_reclaim_pages() to scan cgroups in subtree more fairly, track next_cg in each sgx_cgroup and a

[PATCH v16 07/16] x86/sgx: Abstract tracking reclaimable pages in LRU

2024-08-20 Thread Haitao Huang
ing to the global LRU directly. This allows EPC page being able to be tracked in "per-cgroup" LRU when that becomes ready. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haita

[PATCH v16 08/16] x86/sgx: Encapsulate uses of the global LRU

2024-08-20 Thread Haitao Huang
eparate the two cases. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Co-developed-by: Kristen Carlson Accardi Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang --- v16: - Regroup all abstraction related to global LRU usage to this patch from diffe

[PATCH v16 06/16] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

2024-08-20 Thread Haitao Huang
Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko Sakkinen --- V15: - Add comment for spinlock. (Jarkko, Kai) V6: - removed introduction to unreclaimables in commit message. V4

[PATCH v16 05/16] x86/sgx: Implement basic EPC misc cgroup functionality

2024-08-20 Thread Haitao Huang
shold. Later patches will reorganize the tracking and reclamation code in the global reclaimer and implement per-cgroup tracking and reclaiming. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-of

[PATCH v16 04/16] cgroup/misc: Add SGX EPC resource type

2024-08-20 Thread Haitao Huang
From: Kristen Carlson Accardi Add SGX EPC memory, MISC_CG_RES_SGX_EPC, to be a valid resource type for the misc controller. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko

[PATCH v16 03/16] cgroup/misc: Export APIs for SGX driver

2024-08-20 Thread Haitao Huang
needs start a global level reclamation from the root. Export misc_cg_root() for the SGX driver to access. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Tejun Heo Reviewed-by: Kai Huang Tested-by: J

[PATCH v16 02/16] cgroup/misc: Add per resource callbacks for CSS events

2024-08-20 Thread Haitao Huang
sc_cg' to the callbacks but not the 'struct misc_res' because the latter doesn't have a pointer pointing back to 'struct misc_cg'. Link: https://lore.kernel.org/lkml/op.2kdw36otwjv...@hhuan26-mobl.amr.corp.intel.com/ Signed-off-by: Kristen Carlson Accardi Co-developed-b

[PATCH v16 01/16] x86/sgx: Replace boolean parameters with enums

2024-08-20 Thread Haitao Huang
Replace boolean parameters for 'reclaim' in the function sgx_alloc_epc_page() and its callers with an enum. Also opportunistically remove non-static declaration of __sgx_alloc_epc_page() and a typo Signed-off-by: Haitao Huang Suggested-by: Jarkko Sakkinen Suggested-by: Dave Hansen R

[PATCH v16 00/16] Add Cgroup support for SGX EPC memory

2024-08-20 Thread Haitao Huang
467-1-haitao.hu...@linux.intel.com/ [17]v12: https://lore.kernel.org/lkml/20240416032011.58578-1-haitao.hu...@linux.intel.com/ [18]v13: https://lore.kernel.org/lkml/20240430195108.5676-1-haitao.hu...@linux.intel.com/ [19]v14: https://lore.kernel.org/linux-sgx/20240531222630.4634-1-haitao.hu...@l

Re: [PATCH v4 3/3] x86/sgx: Resolve EREMOVE page vs EAUG page data race

2024-07-10 Thread Haitao Huang
esc |= SGX_ENCL_PAGE_BUSY; mutex_unlock(&encl->lock); sgx_zap_enclave_ptes(encl, addr); Reviewed-by: Haitao Huang Thanks Haitao

Re: [PATCH v4 1/3] x86/sgx: Split SGX_ENCL_PAGE_BEING_RECLAIMED into two flags

2024-07-10 Thread Haitao Huang
reclaimed. A future commit will introduce a new case when the enclave page is being removed; this new case will set only the SGX_ENCL_PAGE_BUSY flag. LGTM. Reviewed-by: Haitao Huang Thanks Haitao

Re: [PATCH v15 08/14] x86/sgx: Add basic EPC reclamation flow for cgroup

2024-06-20 Thread Haitao Huang
On Thu, 20 Jun 2024 08:28:57 -0500, Huang, Kai wrote: On 18/06/2024 12:53 am, Huang, Haitao wrote: From: Kristen Carlson Accardi Currently in the EPC page allocation, the kernel simply fails the allocation when the current EPC cgroup fails to charge due to its usage reaching limit. This

Re: [PATCH v15 10/14] x86/sgx: Implement async reclamation for cgroup

2024-06-20 Thread Haitao Huang
+ if (cgroup_subsys_enabled(misc_cgrp_subsys)) { + sgx_cg_wq = alloc_workqueue("sgx_cg_wq", WQ_UNBOUND | WQ_FREEZABLE, + WQ_UNBOUND_MAX_ACTIVE); + return -ENOMEM; Argh, missing if(!sgx_cg_wq), sorry for the brain far

Re: [PATCH v15 12/14] x86/sgx: Turn on per-cgroup EPC reclamation

2024-06-20 Thread Haitao Huang
Hi Kai On Thu, 20 Jun 2024 05:30:16 -0500, Huang, Kai wrote: On 18/06/2024 12:53 am, Huang, Haitao wrote: From: Kristen Carlson Accardi Previous patches have implemented all infrastructure needed for per-cgroup EPC page tracking and reclaiming. But all reclaimable EPC pages are still track

Re: [PATCH v15 05/14] x86/sgx: Implement basic EPC misc cgroup functionality

2024-06-18 Thread Haitao Huang
On Tue, 18 Jun 2024 18:15:37 -0500, Huang, Kai wrote: On Tue, 2024-06-18 at 07:56 -0500, Haitao Huang wrote: On Tue, 18 Jun 2024 06:31:09 -0500, Huang, Kai wrote: > > > @@ -921,7 +956,8 @@ static int __init sgx_init(void) > > if (!sgx_page_cache_init()) > >

Re: [PATCH v15 05/14] x86/sgx: Implement basic EPC misc cgroup functionality

2024-06-18 Thread Haitao Huang
On Tue, 18 Jun 2024 06:31:09 -0500, Huang, Kai wrote: @@ -921,7 +956,8 @@ static int __init sgx_init(void) if (!sgx_page_cache_init()) return -ENOMEM; - if (!sgx_page_reclaimer_init()) { + if (!sgx_page_reclaimer_init() || !sgx_cgroup_init()) { +

Re: [PATCH v14 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-06-11 Thread Haitao Huang
On Mon, 10 Jun 2024 17:39:53 -0500, Huang, Kai wrote: --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -1045,7 +1045,7 @@ static int __init sgx_init(void) if (!sgx_page_cache_init()) return -ENOMEM; -if (!sgx_page_reclaimer_init()) { +if

Re: [PATCH v14 02/14] cgroup/misc: Add per resource callbacks for CSS events

2024-06-07 Thread Haitao Huang
, just call _misc_cg_res_free(cg, MISC_CG_RES_TYPES) to free all. That makes sense now, Will do that. (BTW you need comment inline :-) Thanks Haitao On 2024/6/6 22:51, Haitao Huang wrote: On Thu, 06 Jun 2024 08:37:31 -0500, chenridong wrote: If _misc_cg_res_alloc fails, maybe some

Re: [PATCH v14 02/14] cgroup/misc: Add per resource callbacks for CSS events

2024-06-06 Thread Haitao Huang
On Thu, 06 Jun 2024 08:37:31 -0500, chenridong wrote: If _misc_cg_res_alloc fails, maybe some types do not call ->alloc(), but all types ->free() callback >will be called, is that ok? Not sure I understand. Are you suggesting we ignore failures from ->alloc() callback in _misc_cg_r

Re: [PATCH v14 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-06-06 Thread Haitao Huang
On Thu, 06 Jun 2024 00:32:55 -0500, Jarkko Sakkinen wrote: On Wed Jun 5, 2024 at 6:33 PM EEST, Haitao Huang wrote: sgx_cgroup_try_charge() expects sgx_cg_wq, so it would break unless we check and return 0 which was the initially implemented in v12. But then Kai had some concern on that we

Re: [PATCH v14 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-06-05 Thread Haitao Huang
Hi Jarkko Thanks for your review. On Tue, 04 Jun 2024 17:00:34 -0500, Jarkko Sakkinen wrote: On Sat Jun 1, 2024 at 1:26 AM EEST, Haitao Huang wrote: With different cgroups, the script starts one or multiple concurrent SGX selftests (test_sgx), each to run the

Re: [PATCH v3 2/2] x86/sgx: Resolve EREMOVE page vs EAUG page data race

2024-06-03 Thread Haitao Huang
On Tue, 28 May 2024 11:23:13 -0500, Dave Hansen wrote: On 5/17/24 04:06, Dmitrii Kuvaiskii wrote: ... First, why is SGX so special here? How is the SGX problem different than what the core mm code does? --- a/arch/x86/kernel/cpu/sgx/encl.h +++ b/arch/x86/kernel/cpu/sgx/encl.h @@ -25,6 +25

[PATCH v14 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-05-31 Thread Haitao Huang
, it turns off swapping before start, and turns swapping back on afterwards. Add README to document how to run the tests. Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen --- V13: - More improvement on handling error cases and style fixes. - Add settings file

[PATCH v14 13/14] Docs/x86/sgx: Add description for cgroup support

2024-05-31 Thread Haitao Huang
-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Bagas Sanjaya Reviewed-by: Jarkko Sakkinen Acked-by: Kai Huang Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V8: - Limit text width to 80 characters to be consistent. V6: - Remove mentioning of VMM

[PATCH v14 12/14] x86/sgx: Turn on per-cgroup EPC reclamation

2024-05-31 Thread Haitao Huang
: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V14: - Update global reclamation to use the new

[PATCH v14 11/14] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-05-31 Thread Haitao Huang
for an mm struct from enclave's mm_list. Signed-off-by: Haitao Huang Reported-by: Mikko Ylinen Reviewed-by: Kai Huang Reviewed-by: Jarkko Sakkinen Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V10: - Pass mm struct instead of a boolean 'indirect'. (Dave, Jarkko) V9:

[PATCH v14 10/14] x86/sgx: Implement async reclamation for cgroup

2024-05-31 Thread Haitao Huang
Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen --- V13: - Revert to BUG_ON() in case of workq allocation failure in init and only alloc if misc is enabled. V11: - Print error

[PATCH v14 08/14] x86/sgx: Add basic EPC reclamation flow for cgroup

2024-05-31 Thread Haitao Huang
laimable EPC pages are still tracked in the global LRU thus no per-cgroup reclamation is actually active at the moment. Per-cgroup tracking and reclamation will be turned on in the end after all necessary infrastructure is in place. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson

[PATCH v14 09/14] x86/sgx: Abstract check for global reclaimable pages

2024-05-31 Thread Haitao Huang
s to sgx_can_reclaim_global(). Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko Sakkinen ---

[PATCH v14 07/14] x86/sgx: Abstract tracking reclaimable pages in LRU

2024-05-31 Thread Haitao Huang
ing to the global LRU directly. This allows EPC page being able to be tracked in "per-cgroup" LRU when that becomes ready. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haita

[PATCH v14 06/14] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

2024-05-31 Thread Haitao Huang
Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko Sakkinen --- V6: - removed introduction to unreclaimables in commit message. V4: - Removed unneeded comments for the spinlock

[PATCH v14 05/14] x86/sgx: Implement basic EPC misc cgroup functionality

2024-05-31 Thread Haitao Huang
shold. Later patches will reorganize the tracking and reclamation code in the global reclaimer and implement per-cgroup tracking and reclaiming. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-of

[PATCH v14 04/14] cgroup/misc: Add SGX EPC resource type

2024-05-31 Thread Haitao Huang
From: Kristen Carlson Accardi Add SGX EPC memory, MISC_CG_RES_SGX_EPC, to be a valid resource type for the misc controller. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko

[PATCH v14 02/14] cgroup/misc: Add per resource callbacks for CSS events

2024-05-31 Thread Haitao Huang
sten Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Tejun Heo Reviewed-by: Kai Huang Tested-by: Jarkko Sakkinen --- V12: - Add comments in commit to clarify reason to pass in misc_cg, not misc_res. (Kai) - Remove unlikely (Kai)

[PATCH v14 03/14] cgroup/misc: Export APIs for SGX driver

2024-05-31 Thread Haitao Huang
needs start a global level reclamation from the root. Export misc_cg_root() for the SGX driver to access. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Tejun Heo Reviewed-by: Kai Huang Tested-by: J

[PATCH v14 01/14] x86/sgx: Replace boolean parameters with enums

2024-05-31 Thread Haitao Huang
Replace boolean parameters for 'reclaim' in the function sgx_alloc_epc_page() and its callers with an enum. Also opportunistically remove non-static declaration of __sgx_alloc_epc_page() and a typo Signed-off-by: Haitao Huang Suggested-by: Jarkko Sakkinen Suggested-by: Dave Hansen R

[PATCH v14 00/14] Add Cgroup support for SGX EPC memory

2024-05-31 Thread Haitao Huang
nel.org/lkml/20240416032011.58578-1-haitao.hu...@linux.intel.com/ [18]v13: https://lore.kernel.org/lkml/20240430195108.5676-1-haitao.hu...@linux.intel.com/ Haitao Huang (3): x86/sgx: Replace boolean parameters with enums x86/sgx: Charge mem_cgroup for per-cgroup reclamation selftests/sgx: Add scri

Re: [RFC PATCH v3 1/1] x86/sgx: Explicitly give up the CPU in EDMM's ioctl() to avoid softlockup

2024-05-15 Thread Haitao Huang
On Wed, 15 May 2024 16:55:59 -0500, Haitao Huang wrote: On Wed, 15 May 2024 01:55:21 -0500, Bojun Zhu wrote: EDMM's ioctl()s support batch operations, which may be time-consuming. Try to explicitly give up the CPU as the prefix operation at the every begin of "for loop"

Re: [PATCH v2 1/2] x86/sgx: Resolve EAUG race where losing thread returns SIGBUS

2024-05-15 Thread Haitao Huang
t_t sgx_encl_eaug_page(struct vm_area_struct *vma, err_out_shrink: sgx_encl_shrink(encl, va_page); err_out_epc: - sgx_encl_free_epc_page(epc_page); + sgx_free_epc_page(epc_page); err_out_unlock: mutex_unlock(&encl->lock); kfree(encl_page); Reviewed-by: Haitao Huang

Re: [PATCH v2 2/2] x86/sgx: Resolve EREMOVE page vs EAUG page data race

2024-05-15 Thread Haitao Huang
ave_ptes(). */ + entry->desc |= SGX_ENCL_PAGE_BEING_REMOVED; mutex_unlock(&encl->lock); sgx_zap_enclave_ptes(encl, addr); Reviewed-by: Haitao Huang

Re: [RFC PATCH v3 1/1] x86/sgx: Explicitly give up the CPU in EDMM's ioctl() to avoid softlockup

2024-05-15 Thread Haitao Huang
On Wed, 15 May 2024 01:55:21 -0500, Bojun Zhu wrote: EDMM's ioctl()s support batch operations, which may be time-consuming. Try to explicitly give up the CPU as the prefix operation at the every begin of "for loop" in sgx_enclave_{ modify_types | restrict_permissions | remove_pages} to give o

Re: [PATCH v13 12/14] x86/sgx: Turn on per-cgroup EPC reclamation

2024-05-06 Thread Haitao Huang
On Mon, 06 May 2024 19:10:42 -0500, Huang, Kai wrote: On 1/05/2024 7:51 am, Haitao Huang wrote: static void sgx_reclaim_pages_global(struct mm_struct *charge_mm) { - sgx_reclaim_pages(&sgx_global_lru, charge_mm); + if (IS_ENABLED(CONFIG_CGROUP_

Re: [PATCH v13 11/14] x86/sgx: Abstract check for global reclaimable pages

2024-05-06 Thread Haitao Huang
Hi Kai Sorry there seems to be some delay in receiving my emails. On Thu, 02 May 2024 18:23:06 -0500, Huang, Kai wrote: On 1/05/2024 7:51 am, Haitao Huang wrote: From: Kristen Carlson Accardi For the global reclaimer to determine if any page available for reclamation at the global level

[PATCH v13 13/14] Docs/x86/sgx: Add description for cgroup support

2024-04-30 Thread Haitao Huang
-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Bagas Sanjaya Acked-by: Kai Huang Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V8: - Limit text width to 80 characters to be consistent. V6: - Remove mentioning of VMM specific behavior on handling

[PATCH v13 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-04-30 Thread Haitao Huang
, it turns off swapping before start, and turns swapping back on afterwards. Add README to document how to run the tests. Signed-off-by: Haitao Huang --- V13: - More improvement on handling error cases and style fixes. - Add settings file for custom timeout V12: - Integrate the scripts to the

[PATCH v13 12/14] x86/sgx: Turn on per-cgroup EPC reclamation

2024-04-30 Thread Haitao Huang
reclamation both work properly with all pages tracked in per-cgroup LRUs. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen

[PATCH v13 11/14] x86/sgx: Abstract check for global reclaimable pages

2024-04-30 Thread Haitao Huang
s to sgx_can_reclaim_global(). Rename sgx_should_reclaim() to sgx_should_reclaim_global() as it is used to check if a global reclamation should be performed. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao H

[PATCH v13 09/14] x86/sgx: Implement async reclamation for cgroup

2024-04-30 Thread Haitao Huang
Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Tested-by: Jarkko Sakkinen --- V13: - Revert to BUG_ON() in case of workq allocation failure in init and only alloc if misc is enabled. V11: - Print error instead of WARN (Kai) - Add check

[PATCH v13 08/14] x86/sgx: Add basic EPC reclamation flow for cgroup

2024-04-30 Thread Haitao Huang
thus no per-cgroup reclamation is actually active at the moment. Per-cgroup tracking and reclamation will be turned on in the end after all necessary infrastructure is in place. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-

[PATCH v13 07/14] x86/sgx: Abstract tracking reclaimable pages in LRU

2024-04-30 Thread Haitao Huang
ing to the global LRU directly. This allows EPC page being able to be tracked in "per-cgroup" LRU when that becomes ready. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haita

[PATCH v13 06/14] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

2024-04-30 Thread Haitao Huang
Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko Sakkinen --- V6: - removed introduction to unreclaimables in commit message. V4: - Removed unneeded comments for the spinlock

[PATCH v13 10/14] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-04-30 Thread Haitao Huang
for an mm struct from enclave's mm_list. Signed-off-by: Haitao Huang Reported-by: Mikko Ylinen Reviewed-by: Kai Huang Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V10: - Pass mm struct instead of a boolean 'indirect'. (Dave, Jarkko) V9: - Reduce number of if sta

[PATCH v13 05/14] x86/sgx: Implement basic EPC misc cgroup functionality

2024-04-30 Thread Haitao Huang
shold. Later patches will reorganize the tracking and reclamation code in the global reclaimer and implement per-cgroup tracking and reclaiming. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-of

[PATCH v13 04/14] cgroup/misc: Add SGX EPC resource type

2024-04-30 Thread Haitao Huang
From: Kristen Carlson Accardi Add SGX EPC memory, MISC_CG_RES_SGX_EPC, to be a valid resource type for the misc controller. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Kai Huang Tested-by: Jarkko

[PATCH v13 03/14] cgroup/misc: Export APIs for SGX driver

2024-04-30 Thread Haitao Huang
needs start a global level reclamation from the root. Export misc_cg_root() for the SGX driver to access. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Tejun Heo Reviewed-by: Kai Huang Tested-by: J

[PATCH v13 02/14] cgroup/misc: Add per resource callbacks for CSS events

2024-04-30 Thread Haitao Huang
sten Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen Reviewed-by: Tejun Heo Reviewed-by: Kai Huang Tested-by: Jarkko Sakkinen --- V12: - Add comments in commit to clarify reason to pass in misc_cg, not misc_res. (Kai) - Remove unlikely (Kai)

[PATCH v13 00/14] Add Cgroup support for SGX EPC memory

2024-04-30 Thread Haitao Huang
el.org/linux-sgx/20240328002229.30264-1-haitao.hu...@linux.intel.com/T/#t [16]v11: https://lore.kernel.org/lkml/20240410182558.41467-1-haitao.hu...@linux.intel.com/ [17]v12: https://lore.kernel.org/lkml/20240416032011.58578-1-haitao.hu...@linux.intel.com/ Haitao Huang (3): x86/sgx: Replace boolean parameter

[PATCH v13 01/14] x86/sgx: Replace boolean parameters with enums

2024-04-30 Thread Haitao Huang
Replace boolean parameters for 'reclaim' in the function sgx_alloc_epc_page() and its callers with an enum. Also opportunistically remove non-static declaration of __sgx_alloc_epc_page() and a typo Signed-off-by: Haitao Huang Suggested-by: Jarkko Sakkinen Suggested-by: Dave Hansen R

Re: [PATCH v12 12/14] x86/sgx: Turn on per-cgroup EPC reclamation

2024-04-29 Thread Haitao Huang
On Mon, 29 Apr 2024 17:18:05 -0500, Huang, Kai wrote: /* @@ -42,7 +63,8 @@ static inline struct sgx_epc_lru_list *sgx_lru_list(struct sgx_epc_page *epc_pag */ static inline bool sgx_can_reclaim(void) { -return !list_empty(&sgx_global_lru.reclaimable); +return !sgx_cgroup_lru_e

Re: [PATCH v12 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-04-29 Thread Haitao Huang
On Mon, 29 Apr 2024 11:43:05 -0500, Jarkko Sakkinen wrote: On Mon Apr 29, 2024 at 7:18 PM EEST, Haitao Huang wrote: Hi Jarkko On Sun, 28 Apr 2024 17:03:17 -0500, Jarkko Sakkinen wrote: > On Fri Apr 26, 2024 at 5:28 PM EEST, Dave Hansen wrote: >> On 4/16/24 07:15, Jarkko Sakki

Re: [PATCH v12 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-04-29 Thread Haitao Huang
Hi Jarkko On Sun, 28 Apr 2024 17:03:17 -0500, Jarkko Sakkinen wrote: On Fri Apr 26, 2024 at 5:28 PM EEST, Dave Hansen wrote: On 4/16/24 07:15, Jarkko Sakkinen wrote: > On Tue Apr 16, 2024 at 8:42 AM EEST, Huang, Kai wrote: > Yes, exactly. I'd take one week break and cycle the kselftest par

Re: [PATCH v12 12/14] x86/sgx: Turn on per-cgroup EPC reclamation

2024-04-29 Thread Haitao Huang
On Mon, 29 Apr 2024 05:49:13 -0500, Huang, Kai wrote: +/* + * Get the per-cgroup or global LRU list that tracks the given reclaimable page. + */ static inline struct sgx_epc_lru_list *sgx_lru_list(struct sgx_epc_page *epc_page) { +#ifdef CONFIG_CGROUP_MISC + /* +* epc_pa

Re: [PATCH v12 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-04-24 Thread Haitao Huang
Hi Jarkko On Tue, 16 Apr 2024 11:08:11 -0500, Jarkko Sakkinen wrote: On Tue Apr 16, 2024 at 5:54 PM EEST, Haitao Huang wrote: I did declare the configs in the config file but I missed it in my patch as stated earlier. IIUC, that would not cause this error though. Maybe I should exit with

Re: [PATCH v12 09/14] x86/sgx: Implement async reclamation for cgroup

2024-04-23 Thread Haitao Huang
On Tue, 23 Apr 2024 17:13:15 -0500, Huang, Kai wrote: On Tue, 2024-04-23 at 10:30 -0500, Haitao Huang wrote: > > It's a workaround because you use the capacity==0 but it does not really > > mean to disable the misc cgroup for specific resource IIUC. > > Please

Re: [PATCH v12 08/14] x86/sgx: Add basic EPC reclamation flow for cgroup

2024-04-23 Thread Haitao Huang
On Wed, 17 Apr 2024 18:51:28 -0500, Huang, Kai wrote: On 16/04/2024 3:20 pm, Haitao Huang wrote: From: Kristen Carlson Accardi Currently in the EPC page allocation, the kernel simply fails the allocation when the current EPC cgroup fails to charge due to its usage reaching limit. This is

Re: [PATCH v12 09/14] x86/sgx: Implement async reclamation for cgroup

2024-04-23 Thread Haitao Huang
On Tue, 23 Apr 2024 09:19:53 -0500, Huang, Kai wrote: On Tue, 2024-04-23 at 08:08 -0500, Haitao Huang wrote: On Mon, 22 Apr 2024 17:16:34 -0500, Huang, Kai wrote: > On Mon, 2024-04-22 at 11:17 -0500, Haitao Huang wrote: > > On Sun, 21 Apr 2024 19:22:27 -0500, Huang, Kai

Re: [PATCH v12 09/14] x86/sgx: Implement async reclamation for cgroup

2024-04-23 Thread Haitao Huang
On Mon, 22 Apr 2024 17:16:34 -0500, Huang, Kai wrote: On Mon, 2024-04-22 at 11:17 -0500, Haitao Huang wrote: On Sun, 21 Apr 2024 19:22:27 -0500, Huang, Kai wrote: > On Fri, 2024-04-19 at 20:14 -0500, Haitao Huang wrote: > > > > I think we can add support for "sgx

Re: [PATCH v11 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-04-22 Thread Haitao Huang
Hi Jarkko On Mon, 15 Apr 2024 14:08:44 -0500, Jarkko Sakkinen wrote: I did run the basic test by manually creating the cgroup so you could add tested-by from my side to the other kernel patches expect this one I've reviewed it enough rounds and given various code suggestions etc. For me it

Re: [PATCH v12 09/14] x86/sgx: Implement async reclamation for cgroup

2024-04-22 Thread Haitao Huang
On Sun, 21 Apr 2024 19:22:27 -0500, Huang, Kai wrote: On Fri, 2024-04-19 at 20:14 -0500, Haitao Huang wrote: > > I think we can add support for "sgx_cgroup=disabled" in future if indeed > > needed. But just for init failure, no? > > > > It's not abo

Re: [PATCH v12 09/14] x86/sgx: Implement async reclamation for cgroup

2024-04-19 Thread Haitao Huang
On Fri, 19 Apr 2024 17:44:59 -0500, Huang, Kai wrote: On Fri, 2024-04-19 at 13:55 -0500, Haitao Huang wrote: On Thu, 18 Apr 2024 20:32:14 -0500, Huang, Kai wrote: > > > On 16/04/2024 3:20 pm, Haitao Huang wrote: > > From: Kristen Carlson Accardi > > In cases EPC pa

Re: [PATCH v12 09/14] x86/sgx: Implement async reclamation for cgroup

2024-04-19 Thread Haitao Huang
On Thu, 18 Apr 2024 20:32:14 -0500, Huang, Kai wrote: On 16/04/2024 3:20 pm, Haitao Huang wrote: From: Kristen Carlson Accardi In cases EPC pages need be allocated during a page fault and the cgroup usage is near its limit, an asynchronous reclamation needs be triggered to avoid blocking

Re: [PATCH v12 05/14] x86/sgx: Implement basic EPC misc cgroup functionality

2024-04-19 Thread Haitao Huang
On Thu, 18 Apr 2024 18:29:53 -0500, Huang, Kai wrote: --- /dev/null +++ b/arch/x86/kernel/cpu/sgx/epc_cgroup.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SGX_EPC_CGROUP_H_ +#define _SGX_EPC_CGROUP_H_ + +#include I don't see why you need here. Also, ... +#include

Re: [PATCH v12 05/14] x86/sgx: Implement basic EPC misc cgroup functionality

2024-04-18 Thread Haitao Huang
On Tue, 16 Apr 2024 08:22:06 -0500, Huang, Kai wrote: On Mon, 2024-04-15 at 20:20 -0700, Haitao Huang wrote: From: Kristen Carlson Accardi SGX Enclave Page Cache (EPC) memory allocations are separate from normal RAM allocations, and are managed solely by the SGX subsystem. The existing

Re: [PATCH v12 14/14] selftests/sgx: Add scripts for EPC cgroup testing

2024-04-16 Thread Haitao Huang
On Tue, 16 Apr 2024 17:21:24 -0500, Haitao Huang wrote: On Tue, 16 Apr 2024 17:04:21 -0500, Haitao Huang wrote: On Tue, 16 Apr 2024 11:08:11 -0500, Jarkko Sakkinen wrote: On Tue Apr 16, 2024 at 5:54 PM EEST, Haitao Huang wrote: I did declare the configs in the config file but I

  1   2   3   4   >