Re: [PATCH v38 16/24] x86/sgx: Add a page reclaimer
From: Borislav Petkov
Date: Tue Sep 22 2020 - 14:02:20 EST
On Tue, Sep 22, 2020 at 09:24:38AM -0700, Sean Christopherson wrote:
> The "else if" is correct. Version Array (VA) pages have 512 slots that hold
> metadata for evicted EPC pages, i.e. swapping a page out of the EPC requires
> a VA slot. For simplicity (LOL),
> the approach we are taking for initial support is to reserve a VA slot
> when adding a page to the enclave[*]. In most cases, reserving a slot
> does not require allocating a new VA page, e.g. to reserve slots 1-511
> of the "current" VA page. The if-elif is handling the case where the
> current VA page is fully reserved and a new one needs to be allocated.
> The if handles the error, the elif handles success, i.e.
> if (IS_ERR(va_page)) <- needed a new VA page, allocation failed
> return PTR_ERR(va_page);
> else if (va_page) <- needed a new VA page, allocation succeeded
> list_add(&va_page->list, &encl->va_pages);
> <- reused the current VA page
Aha, in that case va_page will be NULL but you're not using it in that
function later and that current VA page is on encl->va_pages which
others can get from there. Ok, gotcha.