Re: [PATCH v30 08/20] x86/sgx: Add functions to allocate and free EPC pages

From: Jarkko Sakkinen
Date: Thu May 28 2020 - 15:07:42 EST


On Thu, May 28, 2020 at 07:16:35PM +0200, Borislav Petkov wrote:
> Lemme reply to all mails with one. :-)
>
> I think Sean almost had it:
>
> > sgx_alloc_epc_section -> sgx_map_epc_section
> > sgx_free_epc_section -> sgx_unmap_epc_section
>
> Or even
>
> sgx_setup_epc_section()
> sgx_free_epc_section()

I like these. Lets lock in.

> And except those last two. Those are allocating a page from the EPC
> sections so I'd call them:
>
> sgx_try_alloc_page -> sgx_alloc_epc_page_section
> __sgx_try_alloc_page -> __sgx_alloc_epc_page_section
>
> former doing the loop, latter doing the per-section list games.

sgx_alloc_epc_page_section() is a bit nasty and long name to use for
grabbing a page. And even the documentation spoke about grabbing before
this naming discussion. I think it is a great description what is going
on. Everytime I talk about the subject I talk about grabbing.

Lets just say that your suggestion, I could not use in a conference
talk as a verb when I describe what is going on. That function
signature does not fit to my mouth :-) I would talk about
grabbing a page.

This how I refactored yesterday (is in my GIT tree already):

/**
* sgx_grab_page() - Grab a free EPC page
* @owner: the owner of the EPC page
* @reclaim: reclaim pages if necessary
*
* Iterate through EPC sections and borrow a free EPC page to the caller. When a
* page is no longer needed it must be released with sgx_free_page(). If
* @reclaim is set to true, directly reclaim pages when we are out of pages. No
* mm's can be locked when @reclaim is set to true.
*
* Finally, wake up ksgxswapd when the number of pages goes below the watermark
* before returning back to the caller.
*
* Return:
* an EPC page,
* -errno on error
*/

I also rewrote the kdoc.

I do agree that sgx_try_grab_page() should be renamed as __sgx_grab_page().

/Jarkko