Re: [PATCH v3] x86/sgx: Synchronize encl->srcu in sgx_encl_release().

2021-01-13 Thread Haitao Huang
On Mon, 11 Jan 2021 18:08:10 -0600, Jarkko Sakkinen wrote: On Tue, Jan 05, 2021 at 03:57:49PM +0100, Borislav Petkov wrote: On Wed, Dec 16, 2020 at 03:49:20PM +0200, Jarkko Sakkinen wrote: > Add synchronize_srcu_expedited() to sgx_encl_release() to catch a grace > period initiated by

Re: [PATCH v38 12/24] x86/sgx: Add SGX_IOC_ENCLAVE_CREATE

2020-10-02 Thread Haitao Huang
-by: Jethro Beekman Tested-by: Haitao Huang Tested-by: Chunyang Hui Tested-by: Jordan Hand Tested-by: Nathaniel McCallum Tested-by: Seth Moore Tested-by: Darren Kenny Reviewed-by: Darren Kenny Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Co-developed-by: Suresh Siddha

Re: [PATCH v39 16/24] x86/sgx: Add a page reclaimer

2020-10-02 Thread Haitao Huang
When I turn on CONFIG_PROVE_LOCKING, kernel reports following suspicious RCU usages. Not sure if it is an issue. Just reporting here: [ +34.337095] = [ +0.01] WARNING: suspicious RCU usage [ +0.02] 5.9.0-rc6-lock-sgx39 #1 Not tainted [ +0.01]

Re: [PATCH v39 16/24] x86/sgx: Add a page reclaimer

2020-10-03 Thread Haitao Huang
On Sat, 03 Oct 2020 08:32:45 -0500, Jarkko Sakkinen wrote: On Sat, Oct 03, 2020 at 12:22:47AM -0500, Haitao Huang wrote: When I turn on CONFIG_PROVE_LOCKING, kernel reports following suspicious RCU usages. Not sure if it is an issue. Just reporting here: I'm glad to hear that my tip

Re: [PATCH v39 11/24] x86/sgx: Add SGX enclave driver

2020-10-07 Thread Haitao Huang
On Mon, 05 Oct 2020 07:42:21 -0500, Jarkko Sakkinen wrote: On Mon, Oct 05, 2020 at 11:42:46AM +0200, Greg KH wrote: > > You use gpl-only header files in this file, so how in the world can it > > be bsd-3 licensed? > > > > Please get your legal department to agree with this, after you

Re: [PATCH v38 13/24] x86/sgx: Add SGX_IOC_ENCLAVE_ADD_PAGES

2020-09-17 Thread Haitao Huang
On Thu, 17 Sep 2020 11:02:06 -0500, Jarkko Sakkinen wrote: On Thu, Sep 17, 2020 at 12:34:18AM -0500, Haitao Huang wrote: On Tue, 15 Sep 2020 06:05:11 -0500, Jarkko Sakkinen wrote: ... > +static int __sgx_encl_add_page(struct sgx_encl *encl, > + struct sgx_enc

Re: [PATCH v36 12/24] x86/sgx: Add SGX_IOC_ENCLAVE_CREATE

2020-09-01 Thread Haitao Huang
-by: Jethro Beekman Tested-by: Haitao Huang Tested-by: Chunyang Hui Tested-by: Jordan Hand Tested-by: Nathaniel McCallum Tested-by: Seth Moore Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Co-developed-by: Suresh Siddha Signed-off-by: Suresh Siddha Signed-off

Re: [PATCH v37 13/24] x86/sgx: Add SGX_IOC_ENCLAVE_ADD_PAGES

2020-09-13 Thread Haitao Huang
On Fri, 11 Sep 2020 07:40:08 -0500, Jarkko Sakkinen wrote: ... +/** + * sgx_ioc_enclave_add_pages() - The handler for %SGX_IOC_ENCLAVE_ADD_PAGES + * @encl: an enclave pointer + * @arg: a user pointer to a struct sgx_enclave_add_pages instance + * + * Add one or more pages

Re: [PATCH v3] x86/sgx: Synchronize encl->srcu in sgx_encl_release().

2021-01-04 Thread Haitao Huang
s: 1728ab54b4be ("x86/sgx: Add a page reclaimer") Suggested-by: Sean Christopherson Suggested-by: Haitao Huang Signed-off-by: Jarkko Sakkinen --- v3: Fine-tuned tags, and added missing change log for v2. v2: Switch to synchronize_srcu_expedited(). arch/x86/kernel/cpu/sgx/encl.c | 6

Re: [PATCH] x86/sgx: Synchronize encl->srcu in sgx_encl_release().

2020-12-15 Thread Haitao Huang
a legitimate bug and that the > synchronization in sgx_encl_release() was indeed necessary. Good and valid point. The way I see it, the tags should be: Reported-by: Haitao Huang Suggested-by: Sean Christopherson Haitao pointed out the bug but from your analysis I could resolve that this is the f

Re: [PATCH v40 10/24] mm: Add 'mprotect' hook to struct vm_operations_struct

2020-11-18 Thread Haitao Huang
On Mon, 16 Nov 2020 12:00:23 -0600, Dr. Greg wrote: On Thu, Nov 12, 2020 at 02:41:00PM -0800, Andy Lutomirski wrote: Good morning, I hope the week is starting well for everyone. On Thu, Nov 12, 2020 at 1:31 PM Dave Hansen wrote: > > On 11/12/20 12:58 PM, Dr. Greg wrote: > > @@ -270,11

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-09-01 Thread Haitao Huang
On Fri, 03 Jul 2020 22:31:10 -0500, Jarkko Sakkinen wrote: On Wed, Jul 01, 2020 at 08:59:02PM -0700, Sean Christopherson wrote: On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: > +static int sgx_validate_secs(const struct sgx_secs *secs, > + unsigned

Re: [PATCH v33 11/21] x86/sgx: Linux Enclave Driver

2020-09-02 Thread Haitao Huang
On Wed, 02 Sep 2020 11:10:12 -0500, Sean Christopherson wrote: On Tue, Sep 01, 2020 at 10:06:32PM -0500, Haitao Huang wrote: On Fri, 03 Jul 2020 22:31:10 -0500, Jarkko Sakkinen wrote: > On Wed, Jul 01, 2020 at 08:59:02PM -0700, Sean Christopherson wrote: > > On Thu, Jun 18, 2020

Re: [PATCH v38 10/24] mm: Add vm_ops->mprotect()

2020-09-24 Thread Haitao Huang
On Wed, 23 Sep 2020 08:50:56 -0500, Jarkko Sakkinen wrote: On Tue, Sep 22, 2020 at 09:43:02AM -0700, Sean Christopherson wrote: On Tue, Sep 22, 2020 at 08:35:15AM +0300, Jarkko Sakkinen wrote: > On Tue, Sep 22, 2020 at 08:30:06AM +0300, Jarkko Sakkinen wrote: > > On Mon, Sep 21, 2020 at

Re: [PATCH v29 00/20] Intel SGX foundations

2020-05-06 Thread Haitao Huang
On Wed, 06 May 2020 17:14:22 -0500, Sean Christopherson wrote: On Wed, May 06, 2020 at 05:42:42PM -0400, Nathaniel McCallum wrote: Tested on Enarx. This requires a patch[0] for v29 support. Tested-by: Nathaniel McCallum However, we did uncover a small usability issue. See below. [0]:

Re: [PATCH v29 00/20] Intel SGX foundations

2020-05-07 Thread Haitao Huang
On Thu, 07 May 2020 11:49:15 -0500, Nathaniel McCallum wrote: On Thu, May 7, 2020 at 1:03 AM Haitao Huang wrote: On Wed, 06 May 2020 17:14:22 -0500, Sean Christopherson wrote: > On Wed, May 06, 2020 at 05:42:42PM -0400, Nathaniel McCallum wrote: >> Tested on Enarx. This require

Re: [PATCH v29 00/20] Intel SGX foundations

2020-05-07 Thread Haitao Huang
On Thu, 07 May 2020 14:34:59 -0500, Sean Christopherson wrote: On Thu, May 07, 2020 at 12:49:15PM -0400, Nathaniel McCallum wrote: On Thu, May 7, 2020 at 1:03 AM Haitao Huang wrote: > > On Wed, 06 May 2020 17:14:22 -0500, Sean Christopherson > wrote: > > > On Wed, May

Re: [PATCH v20 00/28] Intel SGX1 support

2019-05-14 Thread Haitao Huang
On Fri, 10 May 2019 14:22:34 -0500, Andy Lutomirski wrote: On Fri, May 10, 2019 at 12:04 PM Jethro Beekman wrote: On 2019-05-10 11:56, Xing, Cedric wrote: > Hi Jethro, > >> ELF files are explicitly designed such that you can map them (with mmap) >> in 4096-byte chunks. However,

Re: [PATCH v20 00/28] Intel SGX1 support

2019-05-14 Thread Haitao Huang
On Tue, 14 May 2019 10:17:29 -0500, Andy Lutomirski wrote: On Tue, May 14, 2019 at 7:33 AM Haitao Huang wrote: On Fri, 10 May 2019 14:22:34 -0500, Andy Lutomirski wrote: > On Fri, May 10, 2019 at 12:04 PM Jethro Beekman > wrote: >> >> On 2019-05-10 11:56, Xing, Ced

Re: [PATCH v20 00/28] Intel SGX1 support

2019-05-14 Thread Haitao Huang
On Tue, 14 May 2019 15:45:54 -0500, Andy Lutomirski wrote: On May 14, 2019, at 8:30 AM, Haitao Huang wrote: On Tue, 14 May 2019 10:17:29 -0500, Andy Lutomirski wrote: On Tue, May 14, 2019 at 7:33 AM Haitao Huang wrote: On Fri, 10 May 2019 14:22:34 -0500, Andy Lutomirski wrote

Re: [PATCH v20 00/28] Intel SGX1 support

2019-05-14 Thread Haitao Huang
On Tue, 14 May 2019 16:58:24 -0500, Xing, Cedric wrote: Hi Everyone, I think we are talking about 2 different kinds of criteria for determining the sanity of an enclave. The first kind determines an enclave's sanity by generally accepted good practices. For example, no executable

Re: SGX vs LSM (Re: [PATCH v20 00/28] Intel SGX1 support)

2019-05-15 Thread Haitao Huang
On Wed, 15 May 2019 16:38:58 -0500, Sean Christopherson wrote: On Wed, May 15, 2019 at 11:27:04AM -0700, Andy Lutomirski wrote: 2) Just like any other DSO, there are potential issues with how enclaves deal with writable vs executable memory. This takes two forms. First, a task should

Re: [PATCH 02/25] x86/cpufeatures: Add SGX1 and SGX2 sub-features

2021-03-02 Thread Haitao Huang
On Mon, 01 Mar 2021 05:43:06 -0600, Kai Huang wrote: On Mon, 2021-03-01 at 12:32 +0100, Borislav Petkov wrote: On Tue, Mar 02, 2021 at 12:28:27AM +1300, Kai Huang wrote: > I think some script can utilize /proc/cpuinfo. For instance, admin can have > automation tool/script to deploy enclave

Re: [PATCH v8] x86/sgx: Maintain encl->refcount for each encl->mm_list entry

2021-04-13 Thread Haitao Huang
On Sun, 07 Feb 2021 16:14:01 -0600, Jarkko Sakkinen wrote: This has been shown in tests: [ +0.08] WARNING: CPU: 3 PID: 7620 at kernel/rcu/srcutree.c:374 cleanup_srcu_struct+0xed/0x100 This is essentially a use-after free, although SRCU notices it as an SRCU cleanup in an invalid

Re: [PATCH v4 03/18] x86/sgx: Add sgx_epc_lru_lists to encapsulate LRU lists

2023-09-15 Thread Haitao Huang
On Thu, 14 Sep 2023 05:31:30 -0500, Huang, Kai wrote: Some non-technical staff: On Tue, 2023-09-12 at 21:06 -0700, Haitao Huang wrote: From: Kristen Carlson Accardi The patch was from Kristen, but ... Introduce a data structure to wrap the existing reclaimable list and its spinlock

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

2023-09-15 Thread Haitao Huang
Hi Jarkko On Wed, 13 Sep 2023 04:39:06 -0500, Jarkko Sakkinen wrote: On Wed Sep 13, 2023 at 7:06 AM EEST, Haitao Huang wrote: From: Kristen Carlson Accardi Consumers of the misc cgroup controller might need to perform separate actions for Cgroups Subsystem State(CSS) events: cgroup

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

2023-09-15 Thread Haitao Huang
On Wed, 13 Sep 2023 10:34:28 -0500, Jarkko Sakkinen wrote: +++ b/arch/x86/kernel/cpu/sgx/encl.h @@ -39,6 +39,7 @@ enum sgx_encl_flags { SGX_ENCL_DEBUG = BIT(1), SGX_ENCL_CREATED= BIT(2), SGX_ENCL_INITIALIZED= BIT(3), + SGX_ENCL_OOM

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

2023-09-15 Thread Haitao Huang
On Fri, 15 Sep 2023 12:58:11 -0500, Tejun Heo wrote: On Fri, Sep 15, 2023 at 07:55:45AM -1000, Tejun Heo wrote: On Tue, Sep 12, 2023 at 09:06:18PM -0700, Haitao Huang wrote: > @@ -37,6 +37,11 @@ struct misc_res { >u64 max; >atomic64_t usage; >atomic64_t events; >

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

2023-09-15 Thread Haitao Huang
On Wed, 13 Sep 2023 10:42:52 -0500, Jarkko Sakkinen wrote: On Wed Sep 13, 2023 at 7:06 AM EEST, Haitao Huang wrote: Add sgx_can_reclaim() wrapper and encapsulate direct references to the global LRU list in the reclaimer functions so that they can be called with an LRU list per EPC cgroup

[PATCH v4 00/18] Add Cgroup support for SGX EPC memory

2023-09-12 Thread Haitao Huang
ore.kernel.org/linux-sgx/20220905020411.17290-1-jar...@kernel.org/ [7]https://lore.kernel.org/linux-sgx/zlcxmvdkhecry...@slm.duckdns.org/ [8]https://lore.kernel.org/linux-sgx/20230721120231.13916-1-haitao.hu...@linux.intel.com/ [9]https://lore.kernel.org/linux-sgx/20230728051024.33063-1-haitao.hu...@linux.intel.com/

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

2023-09-12 Thread Haitao Huang
callbacks for these operations, and call the corresponding per-resource-type callback when appropriate. This code will be utilized by the SGX driver in a future patch. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang --- V4: - Moved this to the front of the series. - Applies

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

2023-09-12 Thread Haitao Huang
struct. Allow SGX EPC memory to be a valid resource type for the misc controller. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang --- V4: - Moved this to the second in the series. --- include/linux/misc_cgroup.h | 29 + kernel/cgroup/misc.c

[PATCH v4 03/18] x86/sgx: Add sgx_epc_lru_lists to encapsulate LRU lists

2023-09-12 Thread Haitao Huang
to this structure to support this OOM killing of enclaves. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V4: - Removed unneeded comments for the spinlock and the non-reclaimables. (Kai, Jarkko) - Revised the commit to add

[PATCH v4 04/18] x86/sgx: Use sgx_epc_lru_lists for existing active page list

2023-09-12 Thread Haitao Huang
not tracked at this point but they will be tracked after an unreclaimable LRU list is added to the sgx_epc_lru_lists struct. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V4: - No change, only reordered

[PATCH v4 05/18] x86/sgx: Store reclaimable EPC pages in sgx_epc_lru_lists

2023-09-12 Thread Haitao Huang
eclaimable lists. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V4: - Code update needed for patch reordering - Revised commit message. --- arch/x86/kernel/cpu/sgx/encl.c | 8 +--- arch/x86/kernel/cpu/s

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

2023-09-12 Thread Haitao Huang
ghtforward than using an array. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V4: - Changes needed for patch reordering - Revised commit message V3: - Removed list wrappers --- arch/x86/kernel/cpu/sgx/m

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

2023-09-12 Thread Haitao Huang
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. Signed-off-by: Haitao Huang --- V4: - No changes other than required for patch reordering. V3: - This is new in V3

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

2023-09-12 Thread Haitao Huang
/drop_epc_pages()" functions for adding/removing VA and SECS pages to/from this "unreclaimable" list. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang --- V4: - Updates for patch reordering. - Revised commit messages. - Revised comments for the list. V3: - Remo

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

2023-09-12 Thread Haitao Huang
opherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Tested-by: Mikko Ylinen Cc: Sean Christopherson --- V4: - Fix a white space issue in Kconfig (Randy). - Update comments for LRU list as it can be owned by a cgroup. - Fix comments for sgx_reclaim_epc_pages() and use IS_EN

[PATCH v4 14/18] x86/sgx: Add helper to grab pages from an arbitrary EPC LRU

2023-09-12 Thread Haitao Huang
allows the cgroup iteration logic to be wholly encapsulated within the cgroup code. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V4: - No changes other than reordering the patches --- arch/x86/kernel/cpu/sgx

[PATCH v4 10/18] x86/sgx: Add EPC page flags to identify owner types

2023-09-12 Thread Haitao Huang
. Address this by adding flags for the owner type. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V4: - Updates for patch reordering. - Rename SGX_EPC_OWNER_ENCL_PAGE to SGX_EPC_OWNER_PAGE. (Jarkko) - Commit message

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

2023-09-12 Thread Haitao Huang
those enclave resources, instead, it lets all reclaiming in progress to finish, and relies (as currently done) on kref_put on encl->refcount to trigger sgx_encl_release() to do the final cleanup. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao

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

2023-09-12 Thread Haitao Huang
, e.g., calling this function with the flag to ignore age of pages. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V4: - Combined the 3 patches that made the individual changes to the function signature

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

2023-09-12 Thread Haitao Huang
Add sgx_can_reclaim() wrapper and encapsulate direct references to the global LRU list in the reclaimer functions so that they can be called with an LRU list per EPC cgroup. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean

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

2023-09-12 Thread Haitao Huang
by the cgroup to select the OOM killed enclave. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V4: - Changes needed for patch reordering - Revised commit messages (Jarkko) --- arch/x86/kernel/cpu/sgx/encl.c

[PATCH v4 07/18] x86/sgx: Introduce RECLAIM_IN_PROGRESS state

2023-09-12 Thread Haitao Huang
pty(_page->list). A later patch will replace the array on stack with a temporary list to store the candidate pages, so list_empty() should no longer be used for this purpose. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean Christop

[PATCH v4 17/18] Docs/x86/sgx: Add description for cgroup support

2023-09-12 Thread Haitao Huang
From: Kristen Carlson Accardi Add initial documentation of how to regulate the distribution of SGX Enclave Page Cache (EPC) memory via the Miscellaneous cgroup controller. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang Cc: Sean

[PATCH v4 18/18] selftests/sgx: Add scripts for epc cgroup testing

2023-09-12 Thread Haitao Huang
-by: Haitao Huang --- V4: Note: Need to apply on top of this series previously reviewed: https://lore.kernel.org/linux-sgx/20220905020411.17290-1-jar...@kernel.org/ --- .../selftests/sgx/run_tests_in_misc_cg.sh | 68 +++ tools/testing/selftests/sgx/setup_epc_cg.sh | 29

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

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

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

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

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

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

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

2023-10-30 Thread Haitao Huang
, 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: this includes

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

2023-10-30 Thread Haitao Huang
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 independent from

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

2023-10-30 Thread Haitao Huang
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/cpu/

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

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

2023-10-30 Thread Haitao Huang
to 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

[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 00/12] Add Cgroup support for SGX EPC memory

2023-10-30 Thread Haitao Huang
rg/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 EPC cgroup testing Kristen Carlson Accardi (5): cgro

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

2023-10-30 Thread Haitao Huang
-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/cgroup/misc.c| 27

[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

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

[PATCH v5 17/18] Docs/x86/sgx: Add description for cgroup support

2023-09-22 Thread Haitao Huang
-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson Reviewed-by: Bagas Sanjaya --- V4: - Fix indentation (Randy) - Change misc.events file to be read-only - Fix a typo for 'subsystem' - Add behavior when VMM overcommit EPC with a cgroup (Mikko) --- Documentation/arch/x86

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

2023-09-22 Thread Haitao Huang
rson 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 Cc: Sean Christopherson --- V5: - kernel-doc fixes (Jarkko) V4: - Fix a white space issue in Kconfig (Randy). - Update comments for

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

2023-09-22 Thread Haitao Huang
isc() into misc_cgroup.h and make inline to make this function available to SGX, rename it to misc_cg_parent(), and update kernel/cgroup/misc.c to use the new name. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang --- V5: - Revised commit message (Jarkko) V4: - Mo

[PATCH v5 04/18] x86/sgx: Use sgx_epc_lru_lists for existing active page list

2023-09-22 Thread Haitao Huang
-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 +- 1 file changed, 20 insertions

[PATCH v5 03/18] x86/sgx: Add sgx_epc_lru_lists to encapsulate LRU lists

2023-09-22 Thread Haitao Huang
to this structure to support this OOM killing of enclaves. 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 --- V4: - Removed unneeded comments for the spinlock

[PATCH v5 00/18] Add Cgroup support for SGX EPC memory

2023-09-22 Thread Haitao Huang
ao.hu...@linux.intel.com/ [9]https://lore.kernel.org/linux-sgx/20230728051024.33063-1-haitao.hu...@linux.intel.com/ Haitao Huang (2): x86/sgx: Introduce EPC page states selftests/sgx: Add scripts for EPC cgroup testing Kristen Carlson Accardi (3): cgroup/misc: Add per resource callbacks for CSS events

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

2023-09-22 Thread Haitao Huang
. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Haitao Huang --- V5: - Remove prefixes from the callback names (tj) - Update commit message (Jarkko) V4: - Moved this to the front of the series. - Applies on cgroup/for-6.6 with the overflow fix for misc. V3: - Removed the released() callback

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

2023-09-22 Thread Haitao Huang
, e.g., calling this function with the flag to ignore age of pages. 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 --- V4: - Combined the 3

[PATCH v5 10/18] x86/sgx: Add EPC page flags to identify owner types

2023-09-22 Thread Haitao Huang
. Address this by adding flags for the owner type. 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 --- V4: - Updates for patch reordering. - Rename

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

2023-09-22 Thread Haitao Huang
Signed-off-by: Kristen Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V5: - Revise commit message to make the purpose more clear. V4: - Re-organized this patch to include all changes related to encapsulation of the global LRU - Moved

[PATCH v5 18/18] selftests/sgx: Add scripts for EPC cgroup testing

2023-09-22 Thread Haitao Huang
/main/README Signed-off-by: Haitao Huang --- V5: - Added script with automatic results checking, remove the interactive script. - The script can run independent from the series below. V4: Note: Need to apply on top of this series previously reviewed: https://lore.kernel.org/linux-sgx

[PATCH v5 14/18] x86/sgx: Add helper to grab pages from an arbitrary EPC LRU

2023-09-22 Thread Haitao Huang
allows the cgroup iteration logic to be wholly encapsulated within the cgroup code. 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 --- V4

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

2023-09-22 Thread Haitao Huang
/drop_epc_pages()" functions for adding/removing VA and SECS pages to/from this "unreclaimable" list. 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 C

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

2023-09-22 Thread Haitao Huang
Carlson Accardi Co-developed-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V5: - Rename SGX_ENCL_OOM to SGX_ENCL_NO_MEMORY V4: - Updates for patch reordering and typo fixes. V3: - Rebased to use the new VMA_ITERATOR to zap VMAs. - Fixed the racing cases by b

[PATCH v5 07/18] x86/sgx: Introduce RECLAIM_IN_PROGRESS state

2023-09-22 Thread Haitao Huang
eloped-by: Haitao Huang Signed-off-by: Haitao Huang Cc: Sean Christopherson --- V4: - Fixed some typos. - Revised commit message. V3: - Extend the sgx_epc_page_state enum introduced earlier to replace the flag based approach. --- arch/x86/kernel/cpu/sgx/main.c | 21 ++--- ar

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

2023-09-22 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 --- V4: - Changes needed for patch reordering - Revised commit m

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

2023-09-22 Thread Haitao Huang
in an unreclaimable queue that can be examined by the cgroup to select the OOM killed enclave. 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 --- V5: - Fixed

[PATCH v5 05/18] x86/sgx: Store reclaimable EPC pages in sgx_epc_lru_lists

2023-09-22 Thread Haitao Huang
eclaimable lists. 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 --- V5: - style fixes (Jarkko) V4: - Code update needed for patch reordering

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

2023-09-22 Thread Haitao Huang
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. Signed-off-by: Haitao Huang --- V4: - No changes other than required for patch reordering. V3: - This is new in V3

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

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

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

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

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(_page->encl->refcount) != 0) { sgx_epc_page_set

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(>page_array); if (!encl->secs_child_cnt && encl->secs.epc_page) { +

  1   2   3   4   >