Re: [PATCH v3] x86/sgx: Do not consider unsanitized pages an error

From: Dave Hansen
Date: Thu Aug 25 2022 - 14:51:43 EST


On 8/25/22 01:08, Jarkko Sakkinen wrote:
> + /* Can happen, when the initialization is retracted: */
> + if (verbose && dirty_count > 0)
> + pr_info("%d unsanitized pages\n", dirty_count);
> }
>
> static bool sgx_reclaimer_age(struct sgx_epc_page *epc_page)
> @@ -394,11 +403,8 @@ static int ksgxd(void *p)
> * Sanitize pages in order to recover from kexec(). The 2nd pass is
> * required for SECS pages, whose child pages blocked EREMOVE.
> */
> - __sgx_sanitize_pages(&sgx_dirty_page_list);
> - __sgx_sanitize_pages(&sgx_dirty_page_list);
> -
> - /* sanity check: */
> - WARN_ON(!list_empty(&sgx_dirty_page_list));
> + __sgx_sanitize_pages(&sgx_dirty_page_list, false);
> + __sgx_sanitize_pages(&sgx_dirty_page_list, true);

This is backwards, IMNHO.

Make __sgx_sanitize_pages() return the number of pages that it leaves
dirty.

__sgx_sanitize_pages(&sgx_dirty_page_list)
left_dirty = __sgx_sanitize_pages(&sgx_dirty_page_list);
if (left_dirty)
pr_warn(...);

That rids us of the mystery true/false and puts the pr_warn() in a place
that makes logical sense. Then, let's either *not* do the

pr_err_ratelimited(EREMOVE_ERROR_MESSAGE, ret, ret);

at all, or make it an unconditional pr_warn_ratelimited(). They're not
going to be common and multiple messages are virtually worthless anyway.

I actually think a common tracepoint, or out-of-line ENCLS/ENCLU
functions that can be easily ftraced are a much better idea than a
one-off pr_whatever().