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

2023-09-26 Thread Haitao Huang
On Tue, 26 Sep 2023 08:13:18 -0500, Jarkko Sakkinen wrote: ... > >> /** > >> @@ -410,7 +429,14 @@ misc_cg_alloc(struct cgroup_subsys_state > >> *parent_css) > >> */ > >> static void misc_cg_free(struct cgroup_subsys_state *css) > >> { > >> - kfree(css_misc(css)); > >> + struct misc_cg *c

Re: [PATCH v5 09/18] x86/sgx: Store struct sgx_encl when allocating new VA pages

2023-09-27 Thread Haitao Huang
Hi Kai, On Wed, 27 Sep 2023 06:14:20 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: From: Sean Christopherson In a later patch, when a cgroup has exceeded the max capacity for EPC pages, it may need to identify and OOM kill a less active enclave to make

Re: [PATCH v5 09/18] x86/sgx: Store struct sgx_encl when allocating new VA pages

2023-09-29 Thread Haitao Huang
On Wed, 27 Sep 2023 16:21:19 -0500, Huang, Kai wrote: On Wed, 2023-09-27 at 10:35 -0500, Haitao Huang wrote: > > + > > + /* Possible owner types */ > > + union { > > + struct sgx_encl_page *encl_page; > > + struct sgx_encl *en

Re: [PATCH v5 06/18] x86/sgx: Introduce EPC page states

2023-10-02 Thread Haitao Huang
On Wed, 27 Sep 2023 05:28:36 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: Use the lower 3 bits in the flags field of sgx_epc_page struct to track EPC states in its life cycle and define an enum for possible states. More state(s) will be added later. This

Re: [PATCH v5 08/18] x86/sgx: Use a list to track to-be-reclaimed pages

2023-10-02 Thread Haitao Huang
On Thu, 28 Sep 2023 04:28:34 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: @@ -314,18 +313,22 @@ static void sgx_reclaim_pages(void) if (kref_get_unless_zero(&encl_page->encl->refcount) != 0) { sgx_epc_page

Re: [PATCH v5 11/18] x86/sgx: store unreclaimable pages in LRU lists

2023-10-02 Thread Haitao Huang
On Thu, 28 Sep 2023 04:41:33 -0500, Huang, Kai wrote: --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -746,6 +746,7 @@ void sgx_encl_release(struct kref *ref) xa_destroy(&encl->page_array); if (!encl->secs_child_cnt && encl->secs.epc_page) { +

Re: [PATCH v5 11/18] x86/sgx: store unreclaimable pages in LRU lists

2023-10-02 Thread Haitao Huang
On Wed, 27 Sep 2023 06:57:18 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: From: Sean Christopherson When an OOM event occurs, all pages associated with an enclave will need to be freed, including pages that are not currently tracked by the cgroup LRU lists

Re: [PATCH v5 09/18] x86/sgx: Store struct sgx_encl when allocating new VA pages

2023-10-02 Thread Haitao Huang
On Wed, 27 Sep 2023 06:35:57 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: From: Sean Christopherson In a later patch, when a cgroup has exceeded the max capacity for EPC pages, it may need to identify and OOM kill a less active enclave to make room for

Re: [PATCH v5 02/18] cgroup/misc: Add SGX EPC resource type and export APIs for SGX driver

2023-10-03 Thread Haitao Huang
On Wed, 27 Sep 2023 22:59:12 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: From: Kristen Carlson Accardi Add SGX EPC memory, MISC_CG_RES_SGX_EPC, to be a valid resource type for the misc controller. Add per resource type private data so that SGX can store

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

2023-10-03 Thread Haitao Huang
On Wed, 27 Sep 2023 04:20:55 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -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: the 'css_

Re: [PATCH v5 09/18] x86/sgx: Store struct sgx_encl when allocating new VA pages

2023-10-04 Thread Haitao Huang
On Tue, 03 Oct 2023 15:07:42 -0500, Huang, Kai wrote: On Tue, 2023-10-03 at 01:45 -0500, Haitao Huang wrote: > > Btw, probably a dumb question: > > Theoretically if you only need to find a victim enclave you don't need > to put VA > pages to the unreclaimable list,

Re: [PATCH v5 06/18] x86/sgx: Introduce EPC page states

2023-10-04 Thread Haitao Huang
On Tue, 03 Oct 2023 15:03:48 -0500, Huang, Kai wrote: On Mon, 2023-10-02 at 23:49 -0500, Haitao Huang wrote: On Wed, 27 Sep 2023 05:28:36 -0500, Huang, Kai wrote: > On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: > > Use the lower 3 bits in the flags field of sgx_epc_page

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

2023-10-04 Thread Haitao Huang
Hi Jarkko On Mon, 02 Oct 2023 17:55:14 -0500, Jarkko Sakkinen wrote: ... > >> I noticed this one later: > >> > >> It would better to create a separate ops struct and declare the instance > >> as const at minimum. > >> > >> Then there is no need for dynamic assigment of ops and all that is

Re: [PATCH v5 09/18] x86/sgx: Store struct sgx_encl when allocating new VA pages

2023-10-05 Thread Haitao Huang
On Wed, 04 Oct 2023 16:13:41 -0500, Huang, Kai wrote: On Wed, 2023-10-04 at 10:03 -0500, Haitao Huang wrote: On Tue, 03 Oct 2023 15:07:42 -0500, Huang, Kai wrote: > On Tue, 2023-10-03 at 01:45 -0500, Haitao Huang wrote: > > > > > > Btw, probably a dumb question: >

Re: [PATCH v5 13/18] x86/sgx: Expose sgx_reclaim_pages() for use by EPC cgroup

2023-10-05 Thread Haitao Huang
On Thu, 05 Oct 2023 07:24:12 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: From: Sean Christopherson Adjust and expose the top-level reclaim function as sgx_reclaim_epc_pages() for use by the upcoming EPC cgroup, which will initiate reclaim to enforce the

Re: [PATCH v5 15/18] x86/sgx: Prepare for multiple LRUs

2023-10-05 Thread Haitao Huang
On Thu, 05 Oct 2023 07:30:46 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: +static inline struct sgx_epc_lru_lists *sgx_lru_lists(struct sgx_epc_page *epc_page) +{ + return &sgx_global_lru; +} + +static inline bool sgx_can_reclaim(

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-09 Thread Haitao Huang
On Mon, 09 Oct 2023 18:45:06 -0500, Huang, Kai wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: From: Sean Christopherson Introduce the OOM path for killing an enclave with a reclaimer that is no longer able to reclaim enough EPC pages. Find a victim enclave, which will be

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-09 Thread Haitao Huang
On Mon, 09 Oct 2023 20:18:00 -0500, Huang, Kai wrote: On Mon, 2023-10-09 at 20:04 -0500, Haitao Huang wrote: On Mon, 09 Oct 2023 18:45:06 -0500, Huang, Kai wrote: > On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: > > From: Sean Christopherson > > > > Intro

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-09 Thread Haitao Huang
Hi Sean On Mon, 09 Oct 2023 19:23:04 -0500, Sean Christopherson wrote: On Mon, Oct 09, 2023, Kai Huang wrote: On Fri, 2023-09-22 at 20:06 -0700, Haitao Huang wrote: > +/** > + * sgx_epc_oom() - invoke EPC out-of-memory handling on target LRU > + * @lru: LRU that is low > + *

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-10 Thread Haitao Huang
On Mon, 09 Oct 2023 21:23:12 -0500, Huang, Kai wrote: On Mon, 2023-10-09 at 20:42 -0500, Haitao Huang wrote: Hi Sean On Mon, 09 Oct 2023 19:23:04 -0500, Sean Christopherson wrote: > On Mon, Oct 09, 2023, Kai Huang wrote: > > On Fri, 2023-09-22 at 20:06 -0700, Haitao Hu

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-10 Thread Haitao Huang
On Mon, 09 Oct 2023 20:34:29 -0500, Huang, Kai wrote: On Tue, 2023-10-10 at 00:50 +, Huang, Kai wrote: On Mon, 2023-10-09 at 17:23 -0700, Sean Christopherson wrote: > On Mon, Oct 09, 2023, Kai Huang wrote: > > On Fri, 2023-09-22 at 20:06 -0700, Haitao Hu

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-10 Thread Haitao Huang
On Mon, 09 Oct 2023 21:12:27 -0500, Huang, Kai wrote: > > > > > Later the hosting process could migrated/reassigned to another cgroup? > > What to do when the new cgroup is OOM? > > > > You addressed in the documentation, no? > > +Migration > +- > + > +Once an EPC page is charged t

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-11 Thread Haitao Huang
On Tue, 10 Oct 2023 19:01:25 -0500, Sean Christopherson wrote: On Tue, Oct 10, 2023, Haitao Huang wrote: On Mon, 09 Oct 2023 21:23:12 -0500, Huang, Kai wrote: > On Mon, 2023-10-09 at 20:42 -0500, Haitao Huang wrote: > > Hi Sean > > > > On Mon, 09 Oct 2023

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-11 Thread Haitao Huang
On Tue, 10 Oct 2023 19:31:19 -0500, Huang, Kai wrote: On Tue, 2023-10-10 at 12:05 -0500, Haitao Huang wrote: On Mon, 09 Oct 2023 21:12:27 -0500, Huang, Kai wrote: > > > > > > > > > > Later the hosting process could migrated/reassigned to another > > cgr

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-12 Thread Haitao Huang
On Tue, 10 Oct 2023 19:51:17 -0500, Huang, Kai wrote: [...] (btw, even you track VA/SECS pages in unreclaimable list, given they both have 'enclave' as the owner, do you still need SGX_EPC_OWNER_ENCL and SGX_EPC_OWNER_PAGE ?) Let me think about it, there might be also a way just track encl

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-16 Thread Haitao Huang
On Mon, 16 Oct 2023 05:57:36 -0500, Huang, Kai wrote: On Thu, 2023-10-12 at 08:27 -0500, Haitao Huang wrote: On Tue, 10 Oct 2023 19:51:17 -0500, Huang, Kai wrote: [...] > (btw, even you track VA/SECS pages in unreclaimable list, given they > both have > 'enclave' as

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-16 Thread Haitao Huang
Hi Sean On Mon, 16 Oct 2023 16:32:31 -0500, Sean Christopherson wrote: On Mon, Oct 16, 2023, Haitao Huang wrote: From this perspective, I think the current implementation is "well-defined": EPC cgroup limits for VMs are only enforced at VM launch time, not runtime. In practic

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-16 Thread Haitao Huang
On Mon, 16 Oct 2023 16:09:52 -0500, Huang, Kai wrote: [...] still need to fix the bug mentioned above here. I really think you should just go this simple way: When you want to take EPC back from VM, kill the VM. My only concern is that this is a compromise due to current limitation (no o

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-17 Thread Haitao Huang
On Mon, 16 Oct 2023 20:34:57 -0500, Huang, Kai wrote: On Mon, 2023-10-16 at 19:10 -0500, Haitao Huang wrote: On Mon, 16 Oct 2023 16:09:52 -0500, Huang, Kai wrote: [...] > still need to fix the bug mentioned above here. > > I really think you should just go this simple way: >

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-17 Thread Haitao Huang
Hi Michal, On Tue, 17 Oct 2023 13:54:46 -0500, Michal Koutný wrote: Hello Haitao. On Tue, Oct 17, 2023 at 07:58:02AM -0500, Haitao Huang wrote: AFAIK, before we introducing max_write() callback in this series, no misc controller would possibly enforce the limit when misc.max is reduced

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-17 Thread Haitao Huang
On Tue, 17 Oct 2023 14:13:22 -0500, Michal Koutný wrote: On Tue, Oct 17, 2023 at 08:54:48PM +0200, Michal Koutný wrote: Is this distinction between preemptability of EPC pages mandated by the HW implementation? (host/"process" enclaves vs VM enclaves) Or do have users an option to lock certa

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-18 Thread Haitao Huang
On Wed, 18 Oct 2023 08:55:12 -0500, Dave Hansen wrote: On 10/17/23 21:37, Haitao Huang wrote: Yes we can introduce misc.reclaim to give user a knob to forcefully reducing usage if that is really needed in real usage. The semantics would make force-kill VMs explicit to user. Do any other

Re: [PATCH v5 12/18] x86/sgx: Add EPC OOM path to forcefully reclaim EPC

2023-10-18 Thread Haitao Huang
On Wed, 18 Oct 2023 10:52:23 -0500, Michal Koutný wrote: On Wed, Oct 18, 2023 at 08:37:25AM -0700, Dave Hansen wrote: 1. Admin sets a limit 2. Enclave is created 3. Enclave hits limit, allocation fails I was actually about to suggest reorganizing the series to a part implementing this simp

Re: [PATCH v5 16/18] x86/sgx: Limit process EPC usage with misc cgroup controller

2023-10-19 Thread Haitao Huang
On Tue, 17 Oct 2023 13:54:54 -0500, Michal Koutný wrote: On Fri, Sep 22, 2023 at 08:06:55PM -0700, Haitao Huang wrote: +static void sgx_epc_cgroup_free(struct misc_cg *cg) +{ + struct sgx_epc_cgroup *epc_cg; + + epc_cg = sgx_epc_cgroup_from_misc_cg(cg); It should check for

Re: [PATCH v5 16/18] x86/sgx: Limit process EPC usage with misc cgroup controller

2023-10-22 Thread Haitao Huang
On Mon, 09 Oct 2023 19:26:01 -0500, Huang, Kai wrote: @@ -332,6 +336,7 @@ void sgx_isolate_epc_pages(struct sgx_epc_lru_lists *lru, size_t nr_to_scan, * sgx_reclaim_epc_pages() - Reclaim EPC pages from the consumers * @nr_to_scan: Number of EPC pages to scan for reclaim

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

2023-10-30 Thread Haitao Huang
916-1-haitao.hu...@linux.intel.com/ [9]https://lore.kernel.org/linux-sgx/20230728051024.33063-1-haitao.hu...@linux.intel.com/ [10]https://lore.kernel.org/all/20230923030657.16148-1-haitao.hu...@linux.intel.com/ Haitao Huang (2): x86/sgx: Introduce EPC page states selftests/sgx: Add scripts for

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

2023-10-30 Thread Haitao Huang
data. Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang --- V6: - Create ops struct for per resource callbacks (Jarkko) - Drop max_write callback (Dave, Michal) - Style fixes (Kai) --- include/linux/misc_cgroup.h | 14 ++ kernel/cgrou

[PATCH v6 02/12] cgroup/misc: Export APIs for SGX driver

2023-10-30 Thread Haitao Huang
This requires a walk from the current cgroup up to the root similar to misc_cg_try_charge(). Export misc_cg_parent() to enable this walk. 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 v6 03/12] cgroup/misc: Add SGX EPC resource type

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

[PATCH v6 06/12] x86/sgx: Use sgx_epc_lru_list for existing active page list

2023-10-30 Thread Haitao Huang
Accardi Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V5: - Spelled out SECS, VA (Jarkko) V4: - No change, only reordered the patch. V3: - Remove usage of list wrapper --- arch/x86/kernel/cpu/sgx/main.c | 39

[PATCH v6 05/12] x86/sgx: Add sgx_epc_lru_list to encapsulate LRU list

2023-10-30 Thread Haitao Huang
cgroup reclaims pages from the reclaimable list in this structure when its usage reaches near its limit. 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 Cc: Sean

[PATCH v6 04/12] x86/sgx: Implement basic EPC misc cgroup functionality

2023-10-30 Thread Haitao Huang
count is lower than a threshold. Later patches will reorganize the tracking and reclamation code in the globale 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

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

2023-10-30 Thread Haitao Huang
son Co-developed-by: Kristen Carlson Accardi Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V6: - Drop UNRECLAIMABLE and use only 2 bits for states (Kai) - Combine the patch for RECLAIM_IN_PROGRESS - Style fixes (Jarkko and Kai) --- arch/x86/kernel/

[PATCH v6 08/12] x86/sgx: Use a list to track to-be-reclaimed pages

2023-10-30 Thread Haitao Huang
rward than using an array. 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 Cc: Sean Christopherson --- V6: - Remove extra list_del_init and style fix (Kai) V4: - Changes

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

2023-10-30 Thread Haitao Huang
be done in LRUs in its children groups. 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 Cc: Sean Christopherson --- V6: - Restructure patches to make it easier to

[PATCH v6 10/12] x86/sgx: Implement EPC reclamation for cgroup

2023-10-30 Thread Haitao Huang
is enabled, also calling sgx_epc_cgroup_reclaim_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 --- V6: - Drop EPC OOM killer.(Dave, Michal) - Patch restructuring: thi

[PATCH v6 12/12] selftests/sgx: Add scripts for EPC cgroup testing

2023-10-30 Thread Haitao Huang
ges during testing, run this in a separate terminal: ./watch_misc_for_tests.sh current [1] https://github.com/libcgroup/libcgroup/blob/main/README Signed-off-by: Haitao Huang --- V5: - Added script with automatic results checking, remove the interactive script. - The script can run independen

[PATCH v6 11/12] Docs/x86/sgx: Add description for cgroup support

2023-10-30 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

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

2023-11-06 Thread Haitao Huang
On Sun, 05 Nov 2023 21:26:44 -0600, Jarkko Sakkinen wrote: On Mon, 2023-10-30 at 11:20 -0700, Haitao Huang wrote: SGX Enclave Page Cache (EPC) memory allocations are separate from normal RAM allocations, and are managed solely by the SGX subsystem. The existing cgroup memory controller

[PATCH] x86/sgx: Charge proper mem_cgroup for usage due to EPC reclamation by cgroups

2023-11-06 Thread Haitao Huang
, if 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

Re: [PATCH v6 10/12] x86/sgx: Implement EPC reclamation for cgroup

2023-11-06 Thread Haitao Huang
There is an issue WRT charging proper mem_cgroups for backing pages once per-cgroup reclamation is implemented. Please apply the fix-up patch [1] on top of this patch or the series. Thanks Haitao [1] https://lore.kernel.org/all/20231106155859.7251-1-haitao.hu...@linux.intel.com/

Re: [PATCH v6 04/12] x86/sgx: Implement basic EPC misc cgroup functionality

2023-11-06 Thread Haitao Huang
On Mon, 06 Nov 2023 06:09:45 -0600, Huang, Kai wrote: On Mon, 2023-10-30 at 11:20 -0700, Haitao Huang wrote: From: Kristen Carlson Accardi Implement support for cgroup control of SGX Enclave Page Cache (EPC) memory using the misc cgroup controller. EPC memory is independent from normal

Re: [PATCH v6 04/12] x86/sgx: Implement basic EPC misc cgroup functionality

2023-11-06 Thread Haitao Huang
On Mon, 06 Nov 2023 16:18:30 -0600, Huang, Kai wrote: > > +/** > > + * sgx_epc_cgroup_try_charge() - hierarchically try to charge a single > > EPC page > > + * > > + * Returns EPC cgroup or NULL on success, -errno on failure. > > + */ > > +struct sgx_epc_cgroup *sgx_epc_cgroup_try_charge(vo

Re: [PATCH v6 04/12] x86/sgx: Implement basic EPC misc cgroup functionality

2023-11-06 Thread Haitao Huang
On Mon, 06 Nov 2023 19:16:30 -0600, Haitao Huang wrote: On Mon, 06 Nov 2023 16:18:30 -0600, Huang, Kai wrote: > > +/** > > + * sgx_epc_cgroup_try_charge() - hierarchically try to charge a single > > EPC page > > + * > > + * Returns EPC cgroup or NULL

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

2023-11-07 Thread Haitao Huang
On Mon, 06 Nov 2023 09:48:36 -0600, Haitao Huang wrote: On Sun, 05 Nov 2023 21:26:44 -0600, Jarkko Sakkinen wrote: On Mon, 2023-10-30 at 11:20 -0700, Haitao Huang wrote: SGX Enclave Page Cache (EPC) memory allocations are separate from normal RAM allocations, and are managed solely by

Re: [PATCH v6 12/12] selftests/sgx: Add scripts for EPC cgroup testing

2023-11-15 Thread Haitao Huang
+CG_ROOT=/sys/fs/cgroup +if [ ! -d "/sys/fs/cgroup/misc" ]; then +echo "# cgroup V2 is in use." +else +echo "# cgroup V1 is in use." +CG_ROOT=/sys/fs/cgroup/misc +fi Does the test need to support v1 cgroups? I thought some distro may still only support V1. I do my most work on

Re: [PATCH v6 04/12] x86/sgx: Implement basic EPC misc cgroup functionality

2023-11-26 Thread Haitao Huang
On Mon, 20 Nov 2023 11:16:42 +0800, Huang, Kai wrote: > > > > That's true. I was thinking no need to have them done in separate calls. > The caller has to check the return value for epc_cg instance first, then > check result of try_charge. But there is really only one caller, > sgx_alloc_e

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

2023-11-26 Thread Haitao Huang
On Mon, 20 Nov 2023 11:45:46 +0800, Huang, Kai wrote: On Mon, 2023-10-30 at 11:20 -0700, Haitao Huang wrote: From: Sean Christopherson To prepare for per-cgroup reclamation, separate the top-level reclaim function, sgx_reclaim_epc_pages(), into two separate functions

Re: [PATCH v6 04/12] x86/sgx: Implement basic EPC misc cgroup functionality

2023-11-26 Thread Haitao Huang
On Mon, 27 Nov 2023 00:01:56 +0800, Haitao Huang wrote: > > > > Then here we can have something like: > > > > > > > > void sgx_reclaim_pages(struct sgx_epc_cg *epc_cg) > > > > { > > > > struct sgx

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

2023-12-11 Thread Haitao Huang
Hi Kai On Mon, 27 Nov 2023 03:57:03 -0600, Huang, Kai wrote: On Mon, 2023-11-27 at 00:27 +0800, Haitao Huang wrote: On Mon, 20 Nov 2023 11:45:46 +0800, Huang, Kai wrote: > On Mon, 2023-10-30 at 11:20 -0700, Haitao Huang wrote: > > From: Sean Christopherson > > > &g

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

2023-12-15 Thread Haitao Huang
On Wed, 13 Dec 2023 05:17:11 -0600, Huang, Kai wrote: On Mon, 2023-12-11 at 22:04 -0600, Haitao Huang wrote: Hi Kai On Mon, 27 Nov 2023 03:57:03 -0600, Huang, Kai wrote: > On Mon, 2023-11-27 at 00:27 +0800, Haitao Huang wrote: > > On Mon, 20 Nov 2023 11:45:46 +0800, H

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

2023-12-18 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 v14 00/14] Add Cgroup support for SGX EPC memory

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

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

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

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

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

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

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

[PATCH v14 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 05/14] x86/sgx: Implement basic EPC misc cgroup functionality

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

[PATCH v14 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 07/14] x86/sgx: Abstract tracking reclaimable pages in LRU

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

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

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

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

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

[PATCH v14 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 11/14] x86/sgx: Charge mem_cgroup for per-cgroup reclamation

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

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

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

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

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

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

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

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

Re: [PATCH 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 02/14] cgroup/misc: Add per resource callbacks for CSS events

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

Re: [PATCH v14 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 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 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 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 12/14] x86/sgx: Turn on per-cgroup EPC reclamation

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

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

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

Re: [PATCH v15 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 v4 1/3] x86/sgx: Split SGX_ENCL_PAGE_BEING_RECLAIMED into two flags

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<    1   2   3   4   >