All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: linux-sgx@vger.kernel.org
Subject: [PATCH for_v23 4/7] selftests/x86/sgx: Update enclave build flow to do multi-page add
Date: Tue,  8 Oct 2019 21:42:38 -0700	[thread overview]
Message-ID: <20191009044241.3591-5-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20191009044241.3591-1-sean.j.christopherson@intel.com>

Add the enclaves regular pages in a single ioctl to test the multi-page
capabilities of the ioctl.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 tools/testing/selftests/x86/sgx/main.c | 27 +++++++++++---------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/x86/sgx/main.c b/tools/testing/selftests/x86/sgx/main.c
index 7cffc16c02e0..4b652fd800f5 100644
--- a/tools/testing/selftests/x86/sgx/main.c
+++ b/tools/testing/selftests/x86/sgx/main.c
@@ -164,10 +164,10 @@ static bool encl_create(int dev_fd, unsigned long bin_size,
 	return true;
 }
 
-static bool encl_add_page(int dev_fd, unsigned long offset, void *data,
-			  uint64_t flags)
+static bool encl_add_pages(int dev_fd, unsigned long offset, void *data,
+			   unsigned long nr_pages, uint64_t flags)
 {
-	struct sgx_enclave_add_page ioc;
+	struct sgx_enclave_add_pages ioc;
 	struct sgx_secinfo secinfo;
 	int rc;
 
@@ -178,9 +178,10 @@ static bool encl_add_page(int dev_fd, unsigned long offset, void *data,
 	ioc.mrmask = 0xFFFF;
 	ioc.offset = offset;
 	ioc.src = (uint64_t)data;
+	ioc.nr_pages = nr_pages;
 	memset(ioc.reserved, 0, sizeof(ioc.reserved));
 
-	rc = ioctl(dev_fd, SGX_IOC_ENCLAVE_ADD_PAGE, &ioc);
+	rc = ioctl(dev_fd, SGX_IOC_ENCLAVE_ADD_PAGES, &ioc);
 	if (rc) {
 		fprintf(stderr, "EADD failed rc=%d.\n", rc);
 		return false;
@@ -189,12 +190,13 @@ static bool encl_add_page(int dev_fd, unsigned long offset, void *data,
 	return true;
 }
 
+#define SGX_REG_PAGE_FLAGS \
+	(SGX_SECINFO_REG | SGX_SECINFO_R | SGX_SECINFO_W | SGX_SECINFO_X)
+
 static bool encl_build(struct sgx_secs *secs, void *bin,
 		       unsigned long bin_size, struct sgx_sigstruct *sigstruct)
 {
 	struct sgx_enclave_init ioc;
-	uint64_t offset;
-	uint64_t flags;
 	void *addr;
 	int dev_fd;
 	int rc;
@@ -208,16 +210,9 @@ static bool encl_build(struct sgx_secs *secs, void *bin,
 	if (!encl_create(dev_fd, bin_size, secs))
 		goto out_dev_fd;
 
-	for (offset = 0; offset < bin_size; offset += 0x1000) {
-		if (!offset)
-			flags = SGX_SECINFO_TCS;
-		else
-			flags = SGX_SECINFO_REG | SGX_SECINFO_R |
-				SGX_SECINFO_W | SGX_SECINFO_X;
-
-		if (!encl_add_page(dev_fd, offset, bin + offset, flags))
-			goto out_map;
-	}
+	encl_add_pages(dev_fd, 0, bin, 1, SGX_SECINFO_TCS);
+	encl_add_pages(dev_fd, PAGE_SIZE, bin + PAGE_SIZE,
+		       (bin_size / PAGE_SIZE) - 1, SGX_REG_PAGE_FLAGS);
 
 	ioc.sigstruct = (uint64_t)sigstruct;
 	rc = ioctl(dev_fd, SGX_IOC_ENCLAVE_INIT, &ioc);
-- 
2.22.0


  parent reply	other threads:[~2019-10-09  4:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-09  4:42 [PATCH for_v23 0/7] x86/sgx: Improve add pages ioctl Sean Christopherson
2019-10-09  4:42 ` [PATCH for_v23 1/7] x86/sgx: Modify ADD_PAGE ioctl to take offset instead of full address Sean Christopherson
2019-10-09  4:42 ` [PATCH for_v23 2/7] selftests/x86/sgx: Update test to account for ADD_PAGE change Sean Christopherson
2019-10-09  4:42 ` [PATCH for_v23 3/7] x86/sgx: Tweak ADD_PAGE ioctl to allow adding multiple pages Sean Christopherson
2019-10-14 21:32   ` Jarkko Sakkinen
2019-10-14 21:35     ` Jarkko Sakkinen
2019-10-14 23:31       ` Sean Christopherson
2019-10-16 10:17         ` Jarkko Sakkinen
2019-10-16 10:19           ` Jarkko Sakkinen
2019-10-16 10:29             ` Jarkko Sakkinen
2019-10-21 11:24               ` Jarkko Sakkinen
2019-10-09  4:42 ` Sean Christopherson [this message]
2019-10-09  4:42 ` [PATCH for_v23 5/7] x86/sgx: Add a flag to ADD_PAGES to allow replicating the source page Sean Christopherson
2019-10-09  4:42 ` [PATCH for_v23 6/7] selftests/x86/sgx: Update selftest to account for ADD_PAGES flag Sean Christopherson
2019-10-09  4:42 ` [PATCH for_v23 7/7] selftests/x86/sgx: Add test coverage for reclaim and replicate Sean Christopherson
2019-10-10  3:28 ` [PATCH for_v23 0/7] x86/sgx: Improve add pages ioctl Haitao Huang
2019-10-11 14:37   ` Sean Christopherson
2019-10-13 15:15     ` Dr. Greg

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=20191009044241.3591-5-sean.j.christopherson@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.