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

2024-07-10 Thread Haitao Huang
this page +* (because the page is still in enclave's xarray). To prevent +* CPU2 from loading the page, mark the page as busy. */ + entry->desc |= SGX_ENCL_PAGE_BUSY; mutex_unlock(>lock); sgx_zap

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

2024-07-10 Thread Haitao Huang
. 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

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

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

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

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

[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
-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 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
ing 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: - Reduce num

[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
PC 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 Signed-o

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

2024-05-31 Thread Haitao Huang
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 --- V13: - Rename

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

2024-05-31 Thread Haitao Huang
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: Haitao Huang

[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
. 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-off-

[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
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) V8: - Abstract out

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

2024-05-31 Thread Haitao Huang
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: Jarkko

[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 Reviewed

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

2024-05-31 Thread Haitao Huang
5108.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 scripts for EPC cgroup testing Kristen Carlson Accardi (9): cgroup/misc: Add per resource callbacks for CSS events

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" in sg

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

2024-05-15 Thread Haitao Huang
sgx_encl_free_epc_page(epc_page); + sgx_free_epc_page(epc_page); err_out_unlock: mutex_unlock(>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
x_encl_remove_pages(struct sgx_encl *encl, * Do not keep encl->lock because of dependency on * mmap_lock acquired in sgx_zap_enclave_ptes(). */ + entry->desc |= SGX_ENCL_PAGE_BEING_REMOVED; mutex_unlock(>lock

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

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(_global_lru, charge_mm); + if (IS_ENABLED(CONFIG_CGROUP_MISC

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

[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
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 Huang

[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
er-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-developed-

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

2024-04-30 Thread Haitao Huang
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: Haitao Huang

[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
ing 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 statements. (Tim)

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

2024-04-30 Thread Haitao Huang
. 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-off-

[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
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: Jarkko

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

2024-04-30 Thread Haitao Huang
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) V8: - Abstract out

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

2024-04-30 Thread Haitao Huang
rg/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 parameters with enums x86/sgx: Charge mem_cgroup for per-cgroup reclamation selftests/sgx: Add scripts for EPC

[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 Reviewed

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(_global_lru.reclaimable); +return

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

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 + /* +*

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

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 read

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

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 "

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

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 about

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

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

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

2024-04-16 Thread Haitao Huang
On Tue, 16 Apr 2024 09:07:33 -0500, Huang, Kai wrote: On Mon, 2024-04-15 at 20:20 -0700, Haitao Huang wrote: From: Kristen Carlson Accardi The functions, sgx_{mark,unmark}_page_reclaimable(), manage the tracking of reclaimable EPC pages: sgx_mark_page_reclaimable() adds a newly allocated

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

2024-04-16 Thread Haitao Huang
On Mon, 15 Apr 2024 22:20:02 -0500, Haitao Huang wrote: diff --git a/arch/x86/kernel/cpu/sgx/Makefile b/arch/x86/kernel/cpu/sgx/Makefile index 9c1656779b2a..400baa7cfb69 100644 --- a/arch/x86/kernel/cpu/sgx/Makefile +++ b/arch/x86/kernel/cpu/sgx/Makefile @@ -1,6 +1,7 @@ obj-y

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: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 missed it in my patch as stated earlier. IIUC, that would

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

2024-04-16 Thread Haitao Huang
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 the skip

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

2024-04-16 Thread Haitao Huang
On Tue, 16 Apr 2024 00:42:41 -0500, Huang, Kai wrote: I'll send a fixup for this patch or another version of the series if more changes are needed. Hi Haitao, I don't like to say but in general I think you are sending too frequently. The last version was sent April, 11th (my time),

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

2024-04-16 Thread Haitao Huang
On Tue, 16 Apr 2024 09:10:12 -0500, Jarkko Sakkinen wrote: On Tue Apr 16, 2024 at 5:05 PM EEST, Jarkko Sakkinen wrote: On Tue Apr 16, 2024 at 6:20 AM EEST, Haitao Huang wrote: > With different cgroups, the script starts one or multiple concurrent SGX > selftests (test_sgx), each

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

2024-04-15 Thread Haitao Huang
Missed adding the config file: index ..e7f1db1d3eff --- /dev/null +++ b/tools/testing/selftests/sgx/config @@ -0,0 +1,4 @@ +CONFIG_CGROUPS=y +CONFIG_CGROUP_MISC=y +CONFIG_MEMCG=y +CONFIG_X86_SGX=y I'll send a fixup for this patch or another version of the series if more changes

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

2024-04-15 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 --- V12: - Integrate the scripts to the "run_tests" target. (Jarkko) V11: - Remove cgroups-tools dependency and make scripts ash

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

2024-04-15 Thread Haitao Huang
-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson 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 SIGBUS - Remove statement of forced reclamation

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

2024-04-15 Thread Haitao Huang
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 --- V12

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

2024-04-15 Thread Haitao Huang
-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: Jarkko Sakkinen --- V10: - Add comments for the new function. (Jarkko) V7: - Split this out from the big patch, #10

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

2024-04-15 Thread Haitao Huang
er-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-developed-b

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

2024-04-15 Thread Haitao Huang
ing for an mm struct from enclave's mm_list. Signed-off-by: Haitao Huang Reported-by: Mikko Ylinen Tested-by: Mikko Ylinen Tested-by: Jarkko Sakkinen --- V10: - Pass mm struct instead of a boolean 'indirect'. (Dave, Jarkko) V9: - Reduce number of if statements. (Tim) V8: - Limit text paragraphs to

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

2024-04-15 Thread Haitao Huang
in sgx_alloc_epc_pages(). 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: Jarkko Sakkinen --- V11: - Print error instead of WARN (Kai) - Add check for need to queue an async

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

2024-04-15 Thread Haitao Huang
-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 Tested-by: Jarkko Sakkinen --- V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86

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

2024-04-15 Thread Haitao Huang
. 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 v12 06/14] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

2024-04-15 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 v12 04/14] cgroup/misc: Add SGX EPC resource type

2024-04-15 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 v12 02/14] cgroup/misc: Add per resource callbacks for CSS events

2024-04-15 Thread Haitao Huang
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) V8: - Abstract out

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

2024-04-15 Thread Haitao Huang
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: Jarkko

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

2024-04-15 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 Reviewed

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

2024-04-15 Thread Haitao Huang
nux-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/ Haitao Huang (3): x86/sgx: Replace boolean parameters with enums x86/sgx: Charge mem_cgroup for per-cgroup reclamation selftests/sgx: Add scripts

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

2024-04-15 Thread Haitao Huang
On Mon, 15 Apr 2024 14:08:44 -0500, Jarkko Sakkinen wrote: On Mon Apr 15, 2024 at 6:13 AM EEST, Haitao Huang wrote: On Sun, 14 Apr 2024 10:01:03 -0500, Jarkko Sakkinen wrote: > On Wed Apr 10, 2024 at 9:25 PM EEST, Haitao Huang wrote: >> To run selftests for EPC cgroup: &

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

2024-04-15 Thread Haitao Huang
On Sat, 13 Apr 2024 16:34:17 -0500, Jarkko Sakkinen wrote: On Wed Apr 10, 2024 at 9:25 PM EEST, Haitao Huang wrote: To run selftests for EPC cgroup: sudo ./run_epc_cg_selftests.sh To watch misc cgroup 'current' changes during testing, run this in a separate terminal

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

2024-04-14 Thread Haitao Huang
On Sun, 14 Apr 2024 10:01:03 -0500, Jarkko Sakkinen wrote: On Wed Apr 10, 2024 at 9:25 PM EEST, Haitao Huang wrote: To run selftests for EPC cgroup: sudo ./run_epc_cg_selftests.sh To watch misc cgroup 'current' changes during testing, run this in a separate terminal

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

2024-04-10 Thread Haitao Huang
On Tue, 09 Apr 2024 10:34:06 -0500, Haitao Huang wrote: On Tue, 09 Apr 2024 04:03:22 -0500, Michal Koutný wrote: On Mon, Apr 08, 2024 at 11:23:21PM -0500, Haitao Huang wrote: It's always non-NULL based on testing. It's hard for me to say definitely by reading the code. But IIUC

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

2024-04-10 Thread Haitao Huang
-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V8: - Limit text width to 80 characters to be consistent. V6: - Remove mentioning of VMM specific behavior on handling SIGBUS - Remove statement of forced reclamation, add statement to specify ENOMEM returned when

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

2024-04-10 Thread Haitao Huang
processes exit. The script also includes a test with low mem_cg limit and LARGE sgx_epc limit to verify that the RAM used for per-cgroup reclamation is charged to a proper mem_cg. For this test, it turns off swapping before start, and turns swapping back on afterwards. Signed-off-by: Haitao Huang

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

2024-04-10 Thread Haitao Huang
-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 --- V10: - Add comments for the new function. (Jarkko) V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch

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

2024-04-10 Thread Haitao Huang
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 --- V11: - Reword the comments for global reclamation

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

2024-04-10 Thread Haitao Huang
in sgx_alloc_epc_pages(). 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 --- V11: - Print error instead of WARN (Kai) - Add check for need to queue an async reclamation before returning from

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

2024-04-10 Thread Haitao Huang
er-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-developed

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

2024-04-10 Thread Haitao Huang
ing for an mm struct from enclave's mm_list. Signed-off-by: Haitao Huang Reported-by: Mikko Ylinen --- V10: - Pass mm struct instead of a boolean 'indirect'. (Dave, Jarkko) V9: - Reduce number of if statements. (Tim) V8: - Limit text paragraphs to 80 characters wide. (Jarkko) --- arch/x86/kernel/

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

2024-04-10 Thread Haitao Huang
-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 --- V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel/cpu/sgx/main.c | 30

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

2024-04-10 Thread Haitao Huang
Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Jarkko Sakkinen --- V6: - removed introduction to unreclaimables in commit message. V4: - Removed unneeded comments for the spinlock and the non-reclaimables. (Kai, Jarkko) - Revised

  1   2   3   4   >