On Tue, 2025-04-15 at 14:51 +0300, Elena Reshetova wrote: > sgx_nr_free_pages is an atomic that is used to keep track of > free EPC pages and detect whenever page reclaiming should start. > Since successful execution of ENCLS[EUPDATESVN] requires empty
The mentioning of ENCLS[EUPDATESVN] is kinda out of blue here. It's better to introduce it first like the next patch does. > EPC and preferably a fast lockless way of checking for this > condition in all code paths where EPC is already used, change the > reclaiming code to track the number of used pages via > sgx_nr_used_pages instead of sgx_nr_free_pages. > For this change to work in the page reclamation code, add a new > variable, sgx_nr_total_pages, that will keep track of total > number of EPC pages. > > It would have been possible to implement ENCLS[EUPDATESVN] using > existing sgx_nr_free_pages counter and a new sgx_nr_total_pages > counter, but it won't be possible to avoid taking a lock *every time* > a new EPC page is being allocated. The conversion of sgx_nr_free_pages > into sgx_nr_used_pages allows avoiding the lock in all cases except > when it is the first EPC page being allocated via a quick > atomic_long_inc_not_zero check. > > Note: The serialization for sgx_nr_total_pages is not needed because > the variable is only updated during the initialization and there's no > concurrent access. > > Signed-off-by: Elena Reshetova <elena.reshet...@intel.com> Reviewed-by: Kai Huang <kai.hu...@intel.com>