mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: Jarkko Sakkinen <jarkko@kernel.org>
Cc: <dave.hansen@linux.intel.com>, <md.iqbal.hossain@intel.com>,
	<haitao.huang@intel.com>, <linux-sgx@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86/sgx: Reduce delay and interference of enclave release
Date: Mon, 24 Oct 2022 11:56:39 -0700	[thread overview]
Message-ID: <77943714-b988-bf14-8795-c72ff0424418@intel.com> (raw)
In-Reply-To: <Y1WemizNZgFOVxja@kernel.org>

Hi Jarkko,

On 10/23/2022 1:06 PM, Jarkko Sakkinen wrote:
> On Tue, Oct 18, 2022 at 03:42:47PM -0700, Reinette Chatre wrote:

...

>> diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
>> index 1ec20807de1e..f7365c278525 100644
>> --- a/arch/x86/kernel/cpu/sgx/encl.c
>> +++ b/arch/x86/kernel/cpu/sgx/encl.c
>> @@ -682,9 +682,12 @@ void sgx_encl_release(struct kref *ref)
>>  	struct sgx_encl *encl = container_of(ref, struct sgx_encl, refcount);
>>  	struct sgx_va_page *va_page;
>>  	struct sgx_encl_page *entry;
>> -	unsigned long index;
>> +	unsigned long count = 0;
>> +
>> +	XA_STATE(xas, &encl->page_array, PFN_DOWN(encl->base));
>>  
>> -	xa_for_each(&encl->page_array, index, entry) {
>> +	xas_lock(&xas);
>> +	xas_for_each(&xas, entry, PFN_DOWN(encl->base + encl->size  - 1)) {
> 
> I would add to declarations:
> 
> unsigned long nr_pages = PFN_DOWN(encl->base + encl->size  - 1);
> 
> Makes this more readable.

Will do, but I prefer to name it "max_page_index" or something related instead.
"nr_pages" implies "number of pages" to me, which is not what
PFN_DOWN(encl->base + encl->size - 1) represents. What is represented is the
highest possible index of a page in page_array, where an index is the
pfn of a page.

> 
>>  		if (entry->epc_page) {
>>  			/*
>>  			 * The page and its radix tree entry cannot be freed
>> @@ -699,9 +702,20 @@ void sgx_encl_release(struct kref *ref)
>>  		}
>>  
>>  		kfree(entry);
>> -		/* Invoke scheduler to prevent soft lockups. */
>> -		cond_resched();
>> +		/*
>> +		 * Invoke scheduler on every XA_CHECK_SCHED iteration
>> +		 * to prevent soft lockups.
>> +		 */
>> +		if (!(++count % XA_CHECK_SCHED)) {
>> +			xas_pause(&xas);
>> +			xas_unlock(&xas);
>> +
>> +			cond_resched();
>> +
>> +			xas_lock(&xas);
>> +		}
>>  	}
> 
>         WARN_ON(count != nr_pages);
> 

nr_pages as assigned in your example does not represent a count of the
enclave pages but instead a pfn index into the page_array. Comparing it
to count, the number of removed enclave pages that are not being held
by reclaimer, is not appropriate.

This check would be problematic even if we create a "nr_pages" from
the range of possible indices. This is because of how enclave sizes are
required to be power-of-two that makes it likely for there to be indices
without pages associated with it.

>> +	xas_unlock(&xas);
>>  
>>  	xa_destroy(&encl->page_array);
>>  
>> -- 
>> 2.34.1
>>

Reinette

  reply	other threads:[~2022-10-24 20:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18 22:42 Reinette Chatre
2022-10-23 20:06 ` Jarkko Sakkinen
2022-10-24 18:56   ` Reinette Chatre [this message]
2022-11-01  0:52     ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=77943714-b988-bf14-8795-c72ff0424418@intel.com \
    --to=reinette.chatre@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=haitao.huang@intel.com \
    --cc=jarkko@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=md.iqbal.hossain@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®