linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: linux-sgx@vger.kernel.org
Cc: Jarkko Sakkinen <jarkko@kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] x86/sgx: Add SGX_PAGE_REPEAT flag for SGX_IOC_ENCLAVE_ADD_PAGES
Date: Thu, 10 Jun 2021 10:21:17 +0300	[thread overview]
Message-ID: <20210610072117.76987-1-jarkko@kernel.org> (raw)

For uninitialized data, there's a need to add the same page multiple times,
e.g. a zero page, instead of traversing the source memory forward. With the
current API, this requires to call SGX_IOC_ENCLAVE_ADD_PAGES multiple
times, once per page, which is not very efficient.

Add a new SGX_PAGE_REPEAT flag to resolve the issue. When this flag is set
to the 'flags' field of struct sgx_enclave_pages, the ioctl will apply the
page at 'src' multiple times, instead of moving forward in the address
space.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 arch/x86/include/uapi/asm/sgx.h | 3 +++
 arch/x86/kernel/cpu/sgx/ioctl.c | 9 +++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/uapi/asm/sgx.h b/arch/x86/include/uapi/asm/sgx.h
index 9690d6899ad9..d20fd54fa250 100644
--- a/arch/x86/include/uapi/asm/sgx.h
+++ b/arch/x86/include/uapi/asm/sgx.h
@@ -12,9 +12,12 @@
  * enum sgx_page_flags - page control flags
  * %SGX_PAGE_MEASURE:	Measure the page contents with a sequence of
  *			ENCLS[EEXTEND] operations.
+ * %SGX_PAGE_REPEAT:	Read the same page at 'src' multiple times,
+ *			instead of traversing the memory forward.
  */
 enum sgx_page_flags {
 	SGX_PAGE_MEASURE	= 0x01,
+	SGX_PAGE_REPEAT		= 0x02,
 };
 
 #define SGX_MAGIC 0xA4
diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c
index 83df20e3e633..d81bb257bad0 100644
--- a/arch/x86/kernel/cpu/sgx/ioctl.c
+++ b/arch/x86/kernel/cpu/sgx/ioctl.c
@@ -415,6 +415,7 @@ static long sgx_ioc_enclave_add_pages(struct sgx_encl *encl, void __user *arg)
 {
 	struct sgx_enclave_add_pages add_arg;
 	struct sgx_secinfo secinfo;
+	unsigned long src;
 	unsigned long c;
 	int ret;
 
@@ -453,8 +454,12 @@ static long sgx_ioc_enclave_add_pages(struct sgx_encl *encl, void __user *arg)
 		if (need_resched())
 			cond_resched();
 
-		ret = sgx_encl_add_page(encl, add_arg.src + c, add_arg.offset + c,
-					&secinfo, add_arg.flags);
+		if (add_arg.flags & SGX_PAGE_REPEAT)
+			src = add_arg.src;
+		else
+			src = add_arg.src + c;
+
+		ret = sgx_encl_add_page(encl, src, add_arg.offset + c, &secinfo, add_arg.flags);
 		if (ret)
 			break;
 	}
-- 
2.31.1


             reply	other threads:[~2021-06-10  7:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10  7:21 Jarkko Sakkinen [this message]
2021-06-10  9:01 ` [PATCH] x86/sgx: Add SGX_PAGE_REPEAT flag for SGX_IOC_ENCLAVE_ADD_PAGES Jarkko Sakkinen
2021-06-10 14:11   ` Dave Hansen
2021-06-14 20:48     ` 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=20210610072117.76987-1-jarkko@kernel.org \
    --to=jarkko@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).