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

2024-03-27 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 --- V10: - Add comment to clarify each page belongs to one

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

2024-03-27 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 no

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

2024-03-27 Thread Haitao Huang
/blob/main/README Signed-off-by: Haitao Huang --- V7: - Added memcontrol test. V5: - Added script with automatic results checking, remove the interactive script. - The script can run independent from the series below. --- .../selftests/sgx/run_epc_cg_selftests.sh | 246 ++ .../sel

Re: [PATCH v9 08/15] x86/sgx: Implement EPC reclamation flows for cgroup

2024-03-27 Thread Haitao Huang
On Thu, 22 Feb 2024 16:24:47 -0600, Huang, Kai wrote: On 23/02/2024 9:12 am, Haitao Huang wrote: On Wed, 21 Feb 2024 04:48:58 -0600, Huang, Kai wrote: On Wed, 2024-02-21 at 00:23 -0600, Haitao Huang wrote: StartHi Kai On Tue, 20 Feb 2024 03:52:39 -0600, Huang, Kai wrote

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

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

Re: [PATCH v9 15/15] selftests/sgx: Add scripts for EPC cgroup testing

2024-03-27 Thread Haitao Huang
On Wed, 27 Mar 2024 11:56:35 -0500, Jarkko Sakkinen wrote: On Wed Mar 27, 2024 at 2:55 PM EET, Jarkko Sakkinen wrote: On Mon, 2024-02-05 at 13:06 -0800, Haitao Huang wrote: > The scripts rely on cgroup-tools package from libcgroup [1]. > > To run selftests for epc cgroup:

Re: [PATCH v9 15/15] selftests/sgx: Add scripts for EPC cgroup testing

2024-03-27 Thread Haitao Huang
On Wed, 27 Mar 2024 19:57:26 -0500, Haitao Huang wrote: On Wed, 27 Mar 2024 11:56:35 -0500, Jarkko Sakkinen wrote: On Wed Mar 27, 2024 at 2:55 PM EET, Jarkko Sakkinen wrote: On Mon, 2024-02-05 at 13:06 -0800, Haitao Huang wrote: > The scripts rely on cgroup-tools package from libcgr

Re: [PATCH v9 15/15] selftests/sgx: Add scripts for EPC cgroup testing

2024-03-27 Thread Haitao Huang
On Wed, 27 Mar 2024 07:55:34 -0500, Jarkko Sakkinen wrote: On Mon, 2024-02-05 at 13:06 -0800, Haitao Huang wrote: The scripts rely on cgroup-tools package from libcgroup [1]. To run selftests for epc cgroup: sudo ./run_epc_cg_selftests.sh To watch misc cgroup 'current' chan

Re: [PATCH v9 15/15] selftests/sgx: Add scripts for EPC cgroup testing

2024-03-30 Thread Haitao Huang
On Sat, 30 Mar 2024 06:15:14 -0500, Jarkko Sakkinen wrote: On Thu Mar 28, 2024 at 5:54 AM EET, Haitao Huang wrote: On Wed, 27 Mar 2024 07:55:34 -0500, Jarkko Sakkinen wrote: > On Mon, 2024-02-05 at 13:06 -0800, Haitao Huang wrote: >> The scripts rely on cgroup-tools package from

Re: [PATCH v9 15/15] selftests/sgx: Add scripts for EPC cgroup testing

2024-03-31 Thread Haitao Huang
On Sun, 31 Mar 2024 11:19:04 -0500, Jarkko Sakkinen wrote: On Sat Mar 30, 2024 at 5:32 PM EET, Haitao Huang wrote: On Sat, 30 Mar 2024 06:15:14 -0500, Jarkko Sakkinen wrote: > On Thu Mar 28, 2024 at 5:54 AM EET, Haitao Huang wrote: >> On Wed, 27 Mar 2024 07:55:34 -0500, Jarkko

[PATCH] selftests/sgx: Improve cgroup test scripts

2024-03-31 Thread Haitao Huang
Make cgroup test scripts ash compatible. Remove cg-tools dependency. Add documentation for functions. Tested with busybox on Ubuntu. Signed-off-by: Haitao Huang --- tools/testing/selftests/sgx/ash_cgexec.sh | 58 ++ .../selftests/sgx/run_epc_cg_selftests.sh | 171

Re: [PATCH] selftests/sgx: Improve cgroup test scripts

2024-04-01 Thread Haitao Huang
On Mon, 01 Apr 2024 09:22:21 -0500, Jarkko Sakkinen wrote: On Sun Mar 31, 2024 at 8:44 PM EEST, Haitao Huang wrote: Make cgroup test scripts ash compatible. Remove cg-tools dependency. Add documentation for functions. Tested with busybox on Ubuntu. Signed-off-by: Haitao Huang I'l

[PATCH v2] selftests/sgx: Improve cgroup test scripts

2024-04-01 Thread Haitao Huang
Make cgroup test scripts ash compatible. Remove cg-tools dependency. Add documentation for functions. Tested with busybox on Ubuntu. Signed-off-by: Haitao Huang --- v2: - Fixes for v2 cgroup - Turn off swapping before memcontrol tests and back on after - Add comments and reformat --- tools

Re: [PATCH v9 15/15] selftests/sgx: Add scripts for EPC cgroup testing

2024-04-02 Thread Haitao Huang
On Tue, 02 Apr 2024 06:58:40 -0500, Jarkko Sakkinen wrote: On Tue Apr 2, 2024 at 2:23 PM EEST, Michal Koutný wrote: Hello. On Sat, Mar 30, 2024 at 01:26:08PM +0200, Jarkko Sakkinen wrote: > > > It'd be more complicated and less readable to do all the stuff without the > > > cgroup-tool

Re: [PATCH v2] selftests/sgx: Improve cgroup test scripts

2024-04-02 Thread Haitao Huang
On Tue, 02 Apr 2024 02:43:25 -0500, Jarkko Sakkinen wrote: On Tue Apr 2, 2024 at 4:42 AM EEST, Haitao Huang wrote: Make cgroup test scripts ash compatible. Remove cg-tools dependency. Add documentation for functions. Tested with busybox on Ubuntu. Signed-off-by: Haitao Huang --- v2

Re: Re: [PATCH v9 15/15] selftests/sgx: Add scripts for EPC cgroup testing

2024-04-02 Thread Haitao Huang
On Tue, 02 Apr 2024 12:40:03 -0500, Michal Koutný wrote: On Tue, Apr 02, 2024 at 11:20:21AM -0500, Haitao Huang wrote: Do we really want to have it implemented in c? I only pointed to the available C boilerplate. There are much fewer lines of code in shell scripts. Note we are not

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

2024-04-04 Thread Haitao Huang
On Thu, 04 Apr 2024 06:16:54 -0500, Huang, Kai wrote: On Wed, 2024-03-27 at 17:22 -0700, Haitao Huang wrote: void sgx_cgroup_init(void) { + sgx_cg_wq = alloc_workqueue("sgx_cg_wq", WQ_UNBOUND | WQ_FREEZABLE, WQ_UNBOUND_MAX_ACTIVE); + + /* All Cgroups functionalities ar

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

2024-04-04 Thread Haitao Huang
Hi Kai, Thanks for your suggestions. I'll adopt most of it as it. Minor details below. On Wed, 03 Apr 2024 08:08:28 -0500, Huang, Kai wrote: On Wed, 2024-03-27 at 17:22 -0700, Haitao Huang wrote: From: Kristen Carlson Accardi When a cgroup usage reaches its limit, and it is to be ch

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

2024-04-04 Thread Haitao Huang
On Thu, 28 Mar 2024 07:53:45 -0500, Huang, Kai wrote: --- /dev/null +++ b/arch/x86/kernel/cpu/sgx/epc_cgroup.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright(c) 2022 Intel Corporation. It's 2024 now. And looks you need to use C style comment for /* Copyright ... */, af

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

2024-04-08 Thread Haitao Huang
On Mon, 08 Apr 2024 07:20:23 -0500, Huang, Kai wrote: --- a/arch/x86/kernel/cpu/sgx/epc_cgroup.h +++ b/arch/x86/kernel/cpu/sgx/epc_cgroup.h @@ -28,6 +28,10 @@ static inline int sgx_cgroup_try_charge(struct sgx_cgroup *sgx_cg, enum sgx_recl static inline void sgx_cgroup_uncharge(struct sgx

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

2024-04-08 Thread Haitao Huang
On Mon, 08 Apr 2024 17:37:10 -0500, Huang, Kai wrote: On 9/04/2024 6:03 am, Haitao Huang wrote: The misc root cgroup is a static similar to sgx_cg_root. So misc_cg_root() won't be NULL However, based on how css_misc() was check NULL, I suppose sgx_get_current_cg() may be NULL

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

2024-04-09 Thread Haitao Huang
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 cgroup_disable command-line only blocks operations

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

2024-04-10 Thread Haitao Huang
12]v7: https://lore.kernel.org/linux-sgx/20240122172048.11953-1-haitao.hu...@linux.intel.com/T/#t [13]v8: https://lore.kernel.org/linux-sgx/20240130020938.10025-1-haitao.hu...@linux.intel.com/T/#t [14]v9: https://lore.kernel.org/lkml/20240205210638.157741-1-haitao.hu...@linux.intel.com/T/ [15]v10: ht

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

2024-04-10 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

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

2024-04-10 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 --- V6: - Make commit messages more concis

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

2024-04-10 Thread Haitao Huang
callbacks for those events and allow resource providers to register the callbacks per resource type as needed. This will be utilized later by the EPC misc cgroup support implemented in the SGX driver. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haita

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

2024-04-10 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 --- V6: - Split the original patch into

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

2024-04-10 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 Signe

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

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

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

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

2024-04-10 Thread Haitao Huang
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) --- a

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

2024-04-10 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-dev

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

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

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

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

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

2024-04-10 Thread Haitao Huang
after all 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: Ha

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

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

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 separat

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 separat

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: &

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

2024-04-15 Thread Haitao Huang
nel.org/lkml/20240205210638.157741-1-haitao.hu...@linux.intel.com/T/ [15]v10: https://lore.kernel.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/ Haitao Huang (3): x86/sgx: Replace boolean p

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

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

2024-04-15 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 v12 03/14] cgroup/misc: Export APIs for SGX driver

2024-04-15 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 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 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 07/14] x86/sgx: Abstract tracking reclaimable pages in LRU

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

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

2024-04-15 Thread Haitao Huang
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 10/14] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

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

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

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

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

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

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

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 a

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-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), so

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 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 not

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

[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

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

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

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

<    1   2   3   4   >