public inbox for linux-sgx@vger.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-sgx@vger.kernel.org,
	Haitao Huang <haitao.huang@linux.intel.com>,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	Jethro Beekman <jethro@fortanix.com>,
	Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH v2] Fix the issue further discussed in:
Date: Mon, 5 Oct 2020 14:48:55 +0300	[thread overview]
Message-ID: <20201005114855.GD181338@linux.intel.com> (raw)
In-Reply-To: <20201005114802.GC181338@linux.intel.com>

On Mon, Oct 05, 2020 at 02:48:07PM +0300, Jarkko Sakkinen wrote:
> On Mon, Oct 05, 2020 at 12:11:39PM +0100, Matthew Wilcox wrote:
> > On Mon, Oct 05, 2020 at 06:17:59AM +0300, Jarkko Sakkinen wrote:
> > > @@ -317,10 +318,31 @@ int sgx_encl_may_map(struct sgx_encl *encl, unsigned long start,
> > >  	if (current->personality & READ_IMPLIES_EXEC)
> > >  		return -EACCES;
> > >  
> > > -	xas_for_each(&xas, page, idx_end)
> > > +	/*
> > > +	 * No need to hold encl->lock:
> > > +	 * 1. None of the page->* get written.
> > > +	 * 2. page->vm_max_prot_bits is set in sgx_encl_page_alloc(). This
> > > +	 *    is before calling xa_insert(). After that it is never modified.
> > > +	 */
> > > +	xas_lock(&xas);
> > > +	xas_for_each(&xas, page, idx_end) {
> > > +		if (++count % XA_CHECK_SCHED)
> > > +			continue;
> > 
> > This really doesn't do what you think it does.
> > 
> > 	int ret = 0;
> > 	int count = 0;
> > 
> > 	xas_lock(&xas);
> > 	while (xas.index < idx_end) {
> > 		struct sgx_page *page = xas_next(&xas);
> > 
> > 		if (!page || (~page->vm_max_prot_bits & vm_prot_bits)) {
> > 			ret = -EACCESS;
> > 			break;
> > 		}
> > 
> > 		if (++count % XA_CHECK_SCHED)
> > 			continue;
> > 		xas_pause(&xas);
> > 		xas_unlock(&xas);
> > 		cond_resched();
> > 		xas_lock(&xas);
> > 	}
> > 	xas_unlock(&xas);
> > 
> > 	return ret;
> 
> No mine certainly does not, it locks up the system if the loop succeeds
> (i.e. does not return -EACCESS) :-) Unfortunately had by mistake the v1
> patch (xa_load()) in the kernel that I used to test.

... and not having xas_unlock() in the end was not intentional.

/Jarkko

      reply	other threads:[~2020-10-05 11:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05  3:17 [PATCH v2] Fix the issue further discussed in: Jarkko Sakkinen
2020-10-05 11:11 ` Matthew Wilcox
2020-10-05 11:48   ` Jarkko Sakkinen
2020-10-05 11:48     ` Jarkko Sakkinen [this message]

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=20201005114855.GD181338@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=haitao.huang@linux.intel.com \
    --cc=jethro@fortanix.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=sean.j.christopherson@intel.com \
    --cc=willy@infradead.org \
    /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