Re: [PATCH v2 2/2] x86/sgx: account backing pages

From: Dave Hansen
Date: Fri Jan 14 2022 - 12:56:15 EST


On 1/14/22 9:51 AM, Kristen Carlson Accardi wrote:
>>> +int sgx_encl_lookup_backing(struct sgx_encl *encl, unsigned long
>>> page_index,
>>> + struct sgx_backing *backing)
>>> +{
>>> + return sgx_encl_get_backing(encl, page_index, backing);
>>> +}
>> IMHO, sgx_encl_backing() should be open-coded here.
> I can understand your hesitation, but I agree with Dave here that
> wrapping the function makes the code more clear. I would prefer to keep
> this the way it is.

I'd also like to see sgx_encl_lookup_backing() and
sgx_encl_alloc_backing() diverge more in the future.

For instance, sgx_encl_alloc_backing() could ensure that the page does
not exist in the file before doing the sgx_encl_get_backing() call.
This would ensure that it truly *does* allocate a page and does not just
return a previously-allocated page.

sgx_encl_lookup_backing() could ensure the opposite: that the page
*DOES* exist in the file before doing the sgx_encl_get_backing() call.
This would ensure that it does not allocate a page in a case where we
expected an old, existing page to be present.