Re: [PATCH 03/26] x86/sgx: Add 'struct sgx_epc_lru' to encapsulate lru list(s)

From: Jarkko Sakkinen
Date: Tue Nov 15 2022 - 18:35:47 EST


On Fri, Nov 11, 2022 at 10:35:08AM -0800, Kristen Carlson Accardi wrote:
> Introduce a data structure to wrap the existing reclaimable list
> and its spinlock in a struct to minimize the code changes needed
> to handle multiple LRUs as well as reclaimable and non-reclaimable
> lists, both of which will be introduced and used by SGX EPC cgroups.
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>
> Signed-off-by: Kristen Carlson Accardi <kristen@xxxxxxxxxxxxxxx>
> Cc: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
> arch/x86/kernel/cpu/sgx/sgx.h | 45 +++++++++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h
> index efb10eacd3aa..aac7d4feb0fa 100644
> --- a/arch/x86/kernel/cpu/sgx/sgx.h
> +++ b/arch/x86/kernel/cpu/sgx/sgx.h
> @@ -91,6 +91,51 @@ static inline void *sgx_get_epc_virt_addr(struct sgx_epc_page *page)
> return section->virt_addr + index * PAGE_SIZE;
> }
>
> +struct sgx_epc_lru {

It's not an LRU. It's a data structure containing two LRU's.

Please rename and add a descriptive comment.

> + spinlock_t lock;
> + struct list_head reclaimable;
> + struct list_head unreclaimable;
> +};
> +
> +static inline void sgx_lru_init(struct sgx_epc_lru *lru)
> +{
> + spin_lock_init(&lru->lock);
> + INIT_LIST_HEAD(&lru->reclaimable);
> + INIT_LIST_HEAD(&lru->unreclaimable);
> +}
> +
> +/*
> + * Must be called with queue lock acquired
> + */
> +static inline void __sgx_epc_page_list_push(struct list_head *list, struct sgx_epc_page *page)
> +{
> + list_add_tail(&page->list, list);
> +}
> +
> +/*
> + * Must be called with queue lock acquired
> + */
> +static inline struct sgx_epc_page * __sgx_epc_page_list_pop(struct list_head *list)
> +{
> + struct sgx_epc_page *epc_page;
> +
> + if (list_empty(list))
> + return NULL;
> +
> + epc_page = list_first_entry(list, struct sgx_epc_page, list);
> + list_del_init(&epc_page->list);
> + return epc_page;
> +}
> +
> +#define sgx_epc_pop_reclaimable(lru) \
> + __sgx_epc_page_list_pop(&(lru)->reclaimable)
> +#define sgx_epc_push_reclaimable(lru, page) \
> + __sgx_epc_page_list_push(&(lru)->reclaimable, page)
> +#define sgx_epc_pop_unreclaimable(lru) \
> + __sgx_epc_page_list_pop(&(lru)->unreclaimable)
> +#define sgx_epc_push_unreclaimable(lru, page) \
> + __sgx_epc_page_list_push(&(lru)->unreclaimable, page)

Is there any reason not to declare these as inline functions?

> +
> struct sgx_epc_page *__sgx_alloc_epc_page(void);
> void sgx_free_epc_page(struct sgx_epc_page *page);
>
> --
> 2.37.3
>

BR, Jarkko