Re: [PATCH v6 09/12] x86/sgx: Restructure top-level EPC reclaim function

2024-01-04 Thread Haitao Huang
Hi Dave, On Wed, 03 Jan 2024 10:37:35 -0600, Dave Hansen wrote: On 12/18/23 13:24, Haitao Huang wrote:> @Dave and @Michal, Your thoughts? Or could you confirm we should not do reclaim per cgroup at all? What's the benefit of doing reclaim per cgroup? Is that worth the extra co

Re: [PATCH v6 09/12] x86/sgx: Restructure top-level EPC reclaim function

2024-01-04 Thread Haitao Huang
Hi Michal, On Thu, 04 Jan 2024 06:38:41 -0600, Michal Koutný wrote: Hello. On Mon, Dec 18, 2023 at 03:24:40PM -0600, Haitao Huang wrote: Thanks for raising this. Actually my understanding the above discussion was mainly about not doing reclaiming by killing enclaves, i.e., I assumed

Re: [PATCH v6 09/12] x86/sgx: Restructure top-level EPC reclaim function

2024-01-04 Thread Haitao Huang
On Thu, 04 Jan 2024 13:27:07 -0600, Dave Hansen wrote: On 1/4/24 11:11, Haitao Huang wrote: If those are OK with users and also make it acceptable for merge quickly, I'm happy to do that 🙂 How about we put some actual numbers behind this? How much complexity are we talking about

Re: [PATCH v6 00/12] Add Cgroup support for SGX EPC memory

2024-01-05 Thread Haitao Huang
On Fri, 05 Jan 2024 12:29:05 -0600, Dave Hansen wrote: There's very little about how the LRU design came to be in this cover letter. Let's add some details. How's this? Writing this up, I'm a lot more convinced that this series is, in general, taking the right approach. I honestly don't s

Re: [PATCH v6 01/12] cgroup/misc: Add per resource callbacks for CSS events

2024-01-05 Thread Haitao Huang
On Fri, 05 Jan 2024 03:45:02 -0600, Michal Koutný wrote: On Mon, Oct 30, 2023 at 11:20:02AM -0700, Haitao Huang wrote: From: Kristen Carlson Accardi The misc cgroup controller (subsystem) currently does not perform resource type specific action for Cgroups Subsystem State (CSS) events

Re: [PATCH v6 07/12] x86/sgx: Introduce EPC page states

2024-01-05 Thread Haitao Huang
On Fri, 05 Jan 2024 11:57:03 -0600, Dave Hansen wrote: On 10/30/23 11:20, Haitao Huang wrote: @@ -527,16 +530,13 @@ void sgx_mark_page_reclaimable(struct sgx_epc_page *page) int sgx_unmark_page_reclaimable(struct sgx_epc_page *page) { spin_lock(&sgx_global_lru.lock); -

Re: [PATCH v6 01/12] cgroup/misc: Add per resource callbacks for CSS events

2024-01-08 Thread Haitao Huang
On Wed, 15 Nov 2023 14:25:59 -0600, Jarkko Sakkinen wrote: On Mon Oct 30, 2023 at 8:20 PM EET, Haitao Huang wrote: From: Kristen Carlson Accardi The misc cgroup controller (subsystem) currently does not perform resource type specific action for Cgroups Subsystem State (CSS) events: the

Re: [PATCH v6 09/12] x86/sgx: Restructure top-level EPC reclaim function

2024-01-12 Thread Haitao Huang
On Sun, 17 Dec 2023 19:44:56 -0600, Huang, Kai wrote: > > The point is, with or w/o this patch, you can only reclaim 16 EPC pages > in one > function call (as you have said you are going to remove > SGX_NR_TO_SCAN_MAX, > which is a cipher to both of us). The only difference I can see is,

[PATCH v7 01/15] cgroup/misc: Add per resource callbacks for CSS events

2024-01-22 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: Haitao Huang

[PATCH v7 00/15] Add Cgroup support for SGX EPC memory

2024-01-22 Thread Haitao Huang
linux.intel.com/ [9]v4: https://lore.kernel.org/all/20230913040635.28815-1-haitao.hu...@linux.intel.com/ [10]v5: https://lore.kernel.org/all/20230923030657.16148-1-haitao.hu...@linux.intel.com/ [11]v6:https://lore.kernel.org/linux-sgx/20231030182013.40086-1-haitao.hu...@linux.intel.com/ Haitao Hu

[PATCH v7 02/15] cgroup/misc: Export APIs for SGX driver

2024-01-22 Thread Haitao Huang
also need 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 --- V6: - Make commit messages more concise and split the original patch into tw

[PATCH v7 06/15] x86/sgx: Abstract tracking reclaimable pages in LRU

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

[PATCH v7 04/15] x86/sgx: Implement basic EPC misc cgroup functionality

2024-01-22 Thread Haitao Huang
organize 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-by: Haitao Huang --- V7:

[PATCH v7 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-01-22 Thread Haitao Huang
empty. So no per-cgroup reclamation is activated yet. 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 --- V7: - Split this out from the big patch, #10 in V6. (Dave, Kai

[PATCH v7 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-01-22 Thread Haitao Huang
the flag is true, switch the active mem_cgroup to the one returned from sgx_encl_get_mem_cgroup(), prior to any backing page allocation, in order to ensure that shmem page allocations are charged to the enclave's cgroup. Removed current_is_ksgxd() as it is no longer needed. Signed-off-by: H

[PATCH v7 11/15] x86/sgx: Abstract check for global reclaimable pages

2024-01-22 Thread Haitao Huang
rson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- v7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel/cpu/sgx/main.c | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/ke

[PATCH v7 12/15] x86/sgx: Expose sgx_epc_cgroup_reclaim_pages() for global reclaimer

2024-01-22 Thread Haitao Huang
Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel/cpu/sgx/epc_cgroup.c | 2 +- arch/x86/kernel/cpu/sgx/epc_cgroup.h

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

2024-01-22 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

[PATCH v7 14/15] Docs/x86/sgx: Add description for cgroup support

2024-01-22 Thread Haitao Huang
-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V6: - Remove mentioning of VMM specific behavior on handling SIGBUS - Remove statement of forced reclamation, add statement to specify ENOMEM returned when no reclamation possible. - Added statements on the non-preemptive

[PATCH v7 13/15] x86/sgx: Turn on per-cgroup EPC reclamation

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

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

2024-01-22 Thread Haitao Huang
Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel/cpu/sgx/epc_cgroup.c | 174 ++- arch/x86/kernel/cpu/sgx/epc_cgroup.h | 5 +- 2 files changed, 177 insertions(+), 2

[PATCH v7 05/15] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

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

[PATCH v7 07/15] x86/sgx: Expose sgx_reclaim_pages() for cgroup

2024-01-22 Thread Haitao Huang
is added later, the wrapper will perform global reclamation from the root cgroup. Signed-off-by: Sean Christopherson Co-developed-by: Kristen Carlson Accardi Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V7: - Reworked from patch 9 of V6

[PATCH v7 03/15] cgroup/misc: Add SGX EPC resource type

2024-01-22 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 --- V6: - Split the original patch into this and the preceding one (Kai

Re: [PATCH v7 04/15] x86/sgx: Implement basic EPC misc cgroup functionality

2024-01-23 Thread Haitao Huang
On Mon, 22 Jan 2024 14:25:53 -0600, Jarkko Sakkinen wrote: On Mon Jan 22, 2024 at 7:20 PM EET, 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

Re: [PATCH v7 01/15] cgroup/misc: Add per resource callbacks for CSS events

2024-01-23 Thread Haitao Huang
On Mon, 22 Jan 2024 14:14:01 -0600, Jarkko Sakkinen wrote: On Mon Jan 22, 2024 at 7:20 PM EET, Haitao Huang wrote: From: Kristen Carlson Accardi The misc cgroup controller (subsystem) currently does not perform resource type specific action for Cgroups Subsystem State (CSS) events: the

Re: [PATCH v7 04/15] x86/sgx: Implement basic EPC misc cgroup functionality

2024-01-23 Thread Haitao Huang
On Mon, 22 Jan 2024 14:25:53 -0600, Jarkko Sakkinen wrote: On Mon Jan 22, 2024 at 7:20 PM EET, 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

Re: [PATCH v7 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-01-26 Thread Haitao Huang
On Fri, 26 Jan 2024 08:37:25 -0600, Huang, Kai wrote: Signed-off-by: Haitao Huang Reported-by: Mikko Ylinen --- Non-technical staff: I believe checkpatch requires you to have a "Closes" tag after "Reported-by" otherwise it complains something like this:

[PATCH v8 00/15] Add Cgroup support for SGX EPC memory

2024-01-29 Thread Haitao Huang
ntel.com/ [11]v6: https://lore.kernel.org/linux-sgx/20231030182013.40086-1-haitao.hu...@linux.intel.com/ [12]v7: https://lore.kernel.org/linux-sgx/20240122172048.11953-1-haitao.hu...@linux.intel.com/T/#t Haitao Huang (2): x86/sgx: Charge mem_cgroup for per-cgroup reclamation selftests/sgx: Add scripts

[PATCH v8 01/15] cgroup/misc: Add per resource callbacks for CSS events

2024-01-29 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: Haitao Huang

[PATCH v8 03/15] cgroup/misc: Add SGX EPC resource type

2024-01-29 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 v8 02/15] cgroup/misc: Export APIs for SGX driver

2024-01-29 Thread Haitao Huang
also need 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 --- V6: - Make commit messages more concise and split the ori

[PATCH v8 04/15] x86/sgx: Implement basic EPC misc cgroup functionality

2024-01-29 Thread Haitao Huang
organize 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-by: Haitao Huang --- V

[PATCH v8 06/15] x86/sgx: Abstract tracking reclaimable pages in LRU

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

[PATCH v8 05/15] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

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

[PATCH v8 07/15] x86/sgx: Expose sgx_reclaim_pages() for cgroup

2024-01-29 Thread Haitao Huang
is added later, the wrapper will perform global reclamation from the root cgroup. Signed-off-by: Sean Christopherson Co-developed-by: Kristen Carlson Accardi Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V8: - Use width of 80 characters in

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

2024-01-29 Thread Haitao Huang
Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V8: - Remove alignment for substructure variables. (Jarkko) V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel/cpu/sgx/epc_cgroup.c | 174 ++- arch/x86/kernel/cpu/sgx

[PATCH v8 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-01-29 Thread Haitao Huang
empty. So no per-cgroup reclamation is activated yet. 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 --- V7: - Split this out from the big patch, #10 in V6. (Dave, Kai

[PATCH v8 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-01-29 Thread Haitao Huang
the flag is true, switch the active mem_cgroup to the one returned from sgx_encl_get_mem_cgroup(), prior to any backing page allocation, in order to ensure that shmem page allocations are charged to the enclave's cgroup. Removed current_is_ksgxd() as it is no longer needed. Signed-off-by: H

[PATCH v8 11/15] x86/sgx: Abstract check for global reclaimable pages

2024-01-29 Thread Haitao Huang
rson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- v7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel/cpu/sgx/main.c | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/ke

[PATCH v8 12/15] x86/sgx: Expose sgx_epc_cgroup_reclaim_pages() for global reclaimer

2024-01-29 Thread Haitao Huang
Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V8: - Remove unneeded breaks in function declarations. (Jarkko) V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel

[PATCH v8 13/15] x86/sgx: Turn on per-cgroup EPC reclamation

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

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

2024-01-29 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

[PATCH v8 14/15] Docs/x86/sgx: Add description for cgroup support

2024-01-29 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: [PATCH v8 07/15] x86/sgx: Expose sgx_reclaim_pages() for cgroup

2024-01-30 Thread Haitao Huang
On Tue, 30 Jan 2024 09:39:44 -0600, Huang, Kai wrote: + * @lru: The LRU from which pages are reclaimed. + * @nr_to_scan: Pointer to the target number of pages to scan, must be less than + * SGX_NR_TO_SCAN. + * Return: Number of pages reclaimed. */ -static void sgx_rec

Re: [PATCH v8 04/15] x86/sgx: Implement basic EPC misc cgroup functionality

2024-01-30 Thread Haitao Huang
On Tue, 30 Jan 2024 09:22:14 -0600, Huang, Kai wrote: struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim) { + struct sgx_epc_cgroup *epc_cg; struct sgx_epc_page *page; + int ret; + + epc_cg = sgx_get_current_epc_cg(); + ret = sgx_epc_cgroup_try_c

Re: [PATCH v8 01/15] cgroup/misc: Add per resource callbacks for CSS events

2024-02-02 Thread Haitao Huang
On Thu, 01 Feb 2024 17:24:40 -0600, Jarkko Sakkinen wrote: On Tue Jan 30, 2024 at 4:09 AM EET, Haitao Huang wrote: From: Kristen Carlson Accardi The misc cgroup controller (subsystem) currently does not perform resource type specific action for Cgroups Subsystem State (CSS) events: the

Re: [PATCH v8 05/15] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

2024-02-02 Thread Haitao Huang
On Thu, 01 Feb 2024 17:28:32 -0600, Jarkko Sakkinen wrote: On Tue Jan 30, 2024 at 4:09 AM EET, Haitao Huang wrote: From: Sean Christopherson Introduce a data structure to wrap the existing reclaimable list and its spinlock. Each cgroup later will have one instance of this structure to

Re: [PATCH v7 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-02-02 Thread Haitao Huang
Hi Tim, On Fri, 02 Feb 2024 17:45:05 -0600, Tim Chen wrote: On Mon, 2024-01-22 at 09:20 -0800, Haitao Huang wrote: @@ -1047,29 +1037,38 @@ static struct mem_cgroup *sgx_encl_get_mem_cgroup(struct sgx_encl *encl) * @encl: an enclave pointer * @page_index:enclave page

[PATCH v9 00/15] Add Cgroup support for SGX EPC memory

2024-02-05 Thread Haitao Huang
.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 Haitao Huang (2): x86/sgx: Charge mem_cgroup for per-cgroup reclamation selftests/sgx: Add scripts for EPC cgroup testing Kristen Carlson Accardi (10):

[PATCH v9 03/15] cgroup/misc: Add SGX EPC resource type

2024-02-05 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 v9 01/15] cgroup/misc: Add per resource callbacks for CSS events

2024-02-05 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 v9 02/15] cgroup/misc: Export APIs for SGX driver

2024-02-05 Thread Haitao Huang
also need 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 co

[PATCH v9 06/15] x86/sgx: Abstract tracking reclaimable pages in LRU

2024-02-05 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 v9 04/15] x86/sgx: Implement basic EPC misc cgroup functionality

2024-02-05 Thread Haitao Huang
organize 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-by: Haitao Huang Review

[PATCH v9 07/15] x86/sgx: Expose sgx_reclaim_pages() for cgroup

2024-02-05 Thread Haitao Huang
is added later, the wrapper will perform global reclamation from the root cgroup. Signed-off-by: Sean Christopherson Co-developed-by: Kristen Carlson Accardi Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Reviewed-by: Jarkko Sakkinen --- V8

[PATCH v9 05/15] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

2024-02-05 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 v9 08/15] x86/sgx: Implement EPC reclamation flows for cgroup

2024-02-05 Thread Haitao Huang
Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V9: - Add comments for static variables. (Jarkko) V8: - Remove alignment for substructure variables. (Jarkko) V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel/cpu/sgx/epc_cgroup.c | 181

[PATCH v9 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-02-05 Thread Haitao Huang
the flag is true, switch the active mem_cgroup to the one returned from sgx_encl_get_mem_cgroup(), prior to any backing page allocation, in order to ensure that shmem page allocations are charged to the enclave's cgroup. Removed current_is_ksgxd() as it is no longer needed. Signed-off-by: H

[PATCH v9 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-02-05 Thread Haitao Huang
empty. So no per-cgroup reclamation is activated yet. 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 --- V7: - Split this out from the big patch, #10 in V6. (Dave, Kai

[PATCH v9 11/15] x86/sgx: Abstract check for global reclaimable pages

2024-02-05 Thread Haitao Huang
rson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- v7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel/cpu/sgx/main.c | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/ke

[PATCH v9 12/15] x86/sgx: Expose sgx_epc_cgroup_reclaim_pages() for global reclaimer

2024-02-05 Thread Haitao Huang
Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V8: - Remove unneeded breaks in function declarations. (Jarkko) V7: - Split this out from the big patch, #10 in V6. (Dave, Kai) --- arch/x86/kernel

[PATCH v9 14/15] Docs/x86/sgx: Add description for cgroup support

2024-02-05 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 v9 15/15] selftests/sgx: Add scripts for EPC cgroup testing

2024-02-05 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

[PATCH v9 13/15] x86/sgx: Turn on per-cgroup EPC reclamation

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

Re: [PATCH v9 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-02-12 Thread Haitao Huang
Hi Jarkko On Mon, 12 Feb 2024 13:55:46 -0600, Jarkko Sakkinen wrote: On Mon Feb 5, 2024 at 11:06 PM EET, Haitao Huang wrote: From: Kristen Carlson Accardi When the EPC usage of a cgroup is near its limit, the cgroup needs to reclaim pages used in the same cgroup to make room for new

Re: [PATCH v9 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-02-12 Thread Haitao Huang
On Mon, 12 Feb 2024 13:46:06 -0600, Jarkko Sakkinen wrote: On Mon Feb 5, 2024 at 11:06 PM EET, Haitao Huang wrote: Enclave Page Cache(EPC) memory can be swapped out to regular system "Enclave Page Cache (EPC)" ~ Will fix. [...] int sgx_encl_alloc_back

Re: [PATCH v9 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-02-15 Thread Haitao Huang
Hi Dave, On Thu, 15 Feb 2024 17:43:18 -0600, Dave Hansen wrote: On 2/5/24 13:06, Haitao Huang wrote: static struct mem_cgroup *sgx_encl_get_mem_cgroup(struct sgx_encl *encl) { @@ -1003,14 +1001,6 @@ static struct mem_cgroup *sgx_encl_get_mem_cgroup(struct sgx_encl *encl

Re: [PATCH v9 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-02-16 Thread Haitao Huang
On Fri, 16 Feb 2024 09:15:59 -0600, Dave Hansen wrote: On 2/5/24 13:06, Haitao Huang wrote: @@ -414,7 +416,7 @@ static void sgx_reclaim_pages_global(void) void sgx_reclaim_direct(void) { if (sgx_should_reclaim(SGX_NR_LOW_PAGES)) - sgx_reclaim_pages_global

Re: [PATCH v9 09/15] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

2024-02-16 Thread Haitao Huang
On Fri, 16 Feb 2024 15:55:10 -0600, Dave Hansen wrote: On 2/16/24 13:38, Haitao Huang wrote: On Fri, 16 Feb 2024 09:15:59 -0600, Dave Hansen wrote: ... Does this 'indirect' change any behavior other than whether it does a search for an mm to find a place to charge the backi

Re: [PATCH v9 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-02-19 Thread Haitao Huang
On Tue, 13 Feb 2024 19:52:25 -0600, Jarkko Sakkinen wrote: On Tue Feb 13, 2024 at 1:15 AM EET, Haitao Huang wrote: Hi Jarkko On Mon, 12 Feb 2024 13:55:46 -0600, Jarkko Sakkinen wrote: > On Mon Feb 5, 2024 at 11:06 PM EET, Haitao Huang wrote: >> From: Kristen Carlson Accardi &

[RFC PATCH] x86/sgx: Remove 'reclaim' boolean parameters

2024-02-19 Thread Haitao Huang
Remove all boolean parameters for 'reclaim' from the function sgx_alloc_epc_page() and its callers by making two versions of each function. Also opportunistically remove non-static declaration of __sgx_alloc_epc_page() and a typo Signed-off-by: Haitao Huang Suggested-by: Jarkk

Re: [RFC PATCH] x86/sgx: Remove 'reclaim' boolean parameters

2024-02-19 Thread Haitao Huang
On Mon, 19 Feb 2024 14:42:29 -0600, Jarkko Sakkinen wrote: On Mon Feb 19, 2024 at 3:56 PM UTC, Dave Hansen wrote: On 2/19/24 07:39, Haitao Huang wrote: > Remove all boolean parameters for 'reclaim' from the function > sgx_alloc_epc_page() and its callers by making two

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

2024-02-20 Thread Haitao Huang
StartHi Kai On Tue, 20 Feb 2024 03:52:39 -0600, Huang, Kai wrote: [...] So you introduced the work/workqueue here but there's no place which actually queues the work. IMHO you can either: 1) move relevant code change here; or 2) focus on introducing core functions to reclaim certain pages

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

2024-02-20 Thread Haitao Huang
[...] Here the @nr_to_scan is reduced by the number of pages that are isolated, but not actually reclaimed (which is reflected by @cnt). IIUC, looks you want to make this function do "each cycle" as what you mentioned in the v8 [1]: I tested with that approach and found we can on

Re: [PATCH v9 12/15] x86/sgx: Expose sgx_epc_cgroup_reclaim_pages() for global reclaimer

2024-02-22 Thread Haitao Huang
On Wed, 21 Feb 2024 05:10:36 -0600, Huang, Kai wrote: On Mon, 2024-02-05 at 13:06 -0800, Haitao Huang wrote: From: Kristen Carlson Accardi When cgroup is enabled, all reclaimable pages will be tracked in cgroup LRUs. The global reclaimer needs to start reclamation from the root cgroup

Re: [PATCH v9 13/15] x86/sgx: Turn on per-cgroup EPC reclamation

2024-02-22 Thread Haitao Huang
On Wed, 21 Feb 2024 05:23:00 -0600, Huang, Kai wrote: On Mon, 2024-02-05 at 13:06 -0800, Haitao Huang 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 v9 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-02-22 Thread Haitao Huang
On Wed, 21 Feb 2024 05:06:02 -0600, Huang, Kai wrote: -int sgx_epc_cgroup_try_charge(struct sgx_epc_cgroup *epc_cg) +int sgx_epc_cgroup_try_charge(struct sgx_epc_cgroup *epc_cg, bool reclaim) { - return misc_cg_try_charge(MISC_CG_RES_SGX_EPC, epc_cg->cg, PAGE_SIZE); + for (;;)

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

2024-02-22 Thread Haitao Huang
On Wed, 21 Feb 2024 05:00:27 -0600, Huang, Kai wrote: On Wed, 2024-02-21 at 00:44 -0600, Haitao Huang wrote: [...] > > Here the @nr_to_scan is reduced by the number of pages that are > isolated, but > not actually reclaimed (which is reflected by @cnt). > > IIUC, looks you

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

2024-02-22 Thread Haitao Huang
On Tue, 20 Feb 2024 03:52:39 -0600, Huang, Kai wrote: +/** + * sgx_epc_cgroup_reclaim_pages() - walk a cgroup tree and scan LRUs to reclaim pages + * @root: Root of the tree to start walking from. + * Return: Number of pages reclaimed. Just wondering, do you need to return @cnt gi

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

2024-02-22 Thread Haitao Huang
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: [...] > > So you introduced the work/workqueue here but there's no place which > actually > queue

Re: [PATCH v9 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-02-22 Thread Haitao Huang
On Thu, 22 Feb 2024 15:26:05 -0600, Huang, Kai wrote: On 23/02/2024 6:09 am, Haitao Huang wrote: On Wed, 21 Feb 2024 05:06:02 -0600, Huang, Kai wrote: -int sgx_epc_cgroup_try_charge(struct sgx_epc_cgroup *epc_cg) +int sgx_epc_cgroup_try_charge(struct sgx_epc_cgroup *epc_cg, bool

Re: [PATCH v9 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-02-23 Thread Haitao Huang
On Fri, 23 Feb 2024 04:18:18 -0600, Huang, Kai wrote: > Right. When code reaches to here, we already passed reclaim per cgroup. Yes if try_charge() failed we must do pre-cgroup reclaim. The cgroup may not at or reach limit but system has run out of physical EPC. But after try_charge() we

Re: [PATCH v9 13/15] x86/sgx: Turn on per-cgroup EPC reclamation

2024-02-23 Thread Haitao Huang
On Thu, 22 Feb 2024 16:44:45 -0600, Huang, Kai wrote: On 23/02/2024 5:36 am, Haitao Huang wrote: On Wed, 21 Feb 2024 05:23:00 -0600, Huang, Kai wrote: On Mon, 2024-02-05 at 13:06 -0800, Haitao Huang wrote: From: Kristen Carlson Accardi Previous patches have implemented all

Re: [PATCH v9 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-02-25 Thread Haitao Huang
On Sun, 25 Feb 2024 19:38:26 -0600, Huang, Kai wrote: On 24/02/2024 6:00 am, Haitao Huang wrote: On Fri, 23 Feb 2024 04:18:18 -0600, Huang, Kai wrote: > Right. When code reaches to here, we already passed reclaim per cgroup. Yes if try_charge() failed we must do pre-cgroup recl

Re: [PATCH v9 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-02-26 Thread Haitao Huang
On Mon, 26 Feb 2024 05:36:02 -0600, Huang, Kai wrote: On Sun, 2024-02-25 at 22:03 -0600, Haitao Huang wrote: On Sun, 25 Feb 2024 19:38:26 -0600, Huang, Kai wrote: > > > On 24/02/2024 6:00 am, Haitao Huang wrote: > > On Fri, 23 Feb 2024 04:18:18 -0600, Huang,

Re: [PATCH v9 10/15] x86/sgx: Add EPC reclamation in cgroup try_charge()

2024-02-26 Thread Haitao Huang
Hi Dave, On Mon, 26 Feb 2024 08:04:54 -0600, Dave Hansen wrote: On 2/26/24 03:36, Huang, Kai wrote: In case of overcomitting, even if we always reclaim from the same cgroup for each fault, one group may still interfere the other: e.g., consider an extreme case in that group A used up a

Re: [PATCH v9 04/15] x86/sgx: Implement basic EPC misc cgroup functionality

2024-02-27 Thread Haitao Huang
On Mon, 26 Feb 2024 12:25:58 -0600, Michal Koutný wrote: On Mon, Feb 05, 2024 at 01:06:27PM -0800, Haitao Huang wrote: +static int sgx_epc_cgroup_alloc(struct misc_cg *cg); + +const struct misc_res_ops sgx_epc_cgroup_ops = { + .alloc = sgx_epc_cgroup_alloc, + .free

Re: [PATCH v9 04/15] x86/sgx: Implement basic EPC misc cgroup functionality

2024-03-09 Thread Haitao Huang
On Tue, 27 Feb 2024 15:35:38 -0600, Haitao Huang wrote: On Mon, 26 Feb 2024 12:25:58 -0600, Michal Koutný wrote: On Mon, Feb 05, 2024 at 01:06:27PM -0800, Haitao Huang wrote: +static int sgx_epc_cgroup_alloc(struct misc_cg *cg); + +const struct misc_res_ops sgx_epc_cgroup_ops

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

2024-03-27 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 v10 00/14] Add Cgroup support for SGX EPC memory

2024-03-27 Thread Haitao Huang
haitao.hu...@linux.intel.com/T/#t [14]v9: https://lore.kernel.org/lkml/20240205210638.157741-1-haitao.hu...@linux.intel.com/T/ 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 Car

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

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

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

2024-03-27 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 v10 05/14] x86/sgx: Implement basic EPC misc cgroup functionality

2024-03-27 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 v10 06/14] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

2024-03-27 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 v10 09/14] x86/sgx: Implement async reclamation for cgroup

2024-03-27 Thread Haitao Huang
: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V10: - Split asynchronous flow in separate patch. (Kai) - Consider cgroup disabled when the workqueue allocation fail during init. (Kai) - Abstract out

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

2024-03-27 Thread Haitao Huang
: Haitao Huang Signed-off-by: Haitao Huang --- V10: - Simplify the signature by removing a pointer to nr_to_scan (Kai) - Return pages attempted instead of reclaimed as it is really what the cgroup caller needs to track progress. This further simplifies the design. - Merge patch for exposing

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

2024-03-27 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 v10 11/14] x86/sgx: Abstract check for global reclaimable pages

2024-03-27 Thread Haitao Huang
rson 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/x86/kernel/cpu/sgx/main.c | 12 ++-- 1 file changed

  1   2   3   4   >