@@ -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);
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(-)