Linux-Sgx Archive on lore.kernel.org
 help / color / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: linux-sgx@vger.kernel.org
Subject: Re: [PATCH for_v22] selftests/x86/sgx: Ensure SECS base (ELRANGE) is naturally aligned
Date: Sat, 10 Aug 2019 14:22:16 +0300
Message-ID: <20190810112216.u2dolvtkv62dyeno@linux.intel.com> (raw)
In-Reply-To: <20190810003051.15712-1-sean.j.christopherson@intel.com>

On Fri, Aug 09, 2019 at 05:30:51PM -0700, Sean Christopherson wrote:
> Manually align ELRANGE now that the kernel doesn't automatically do so
> for SGX mappings.  To guarantee mmap() returns a region that can be
> naturally aligned, temporarily map 2x the enclave size and do fancy
> arithmetic to naturally align the base.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

Thank you.

I fine-tuned the calculations a bit:

area = mmap(NULL, secs->size * 2, PROT_NONE, MAP_SHARED, dev_fd, 0);
if (area == MAP_FAILED) {
	perror("mmap");
	return false;
}

secs->base = ((uint64_t)area + secs->size - 1) & ~(secs->size - 1);

munmap(area, secs->base - (uint64_t)area);
munmap((void *)(secs->base + secs->size),
       (uint64_t)area + secs->size - secs->base);

/Jarkko

      parent reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-10  0:30 Sean Christopherson
2019-08-10  0:39 ` Jethro Beekman
2019-08-10 11:23   ` Jarkko Sakkinen
2019-08-15 12:26   ` Jarkko Sakkinen
2019-08-10 11:22 ` Jarkko Sakkinen [this message]

Reply instructions:

You may reply publically 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=20190810112216.u2dolvtkv62dyeno@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=sean.j.christopherson@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

Linux-Sgx Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sgx/0 linux-sgx/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sgx linux-sgx/ https://lore.kernel.org/linux-sgx \
		linux-sgx@vger.kernel.org linux-sgx@archiver.kernel.org
	public-inbox-index linux-sgx


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sgx


AGPL code for this site: git clone https://public-inbox.org/ public-inbox