linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Haitao Huang <haitao.huang@linux.intel.com>
Cc: linux-sgx@vger.kernel.org, dave.hansen@linux.intel.com,
	reinette.chatre@intel.com, vijay.dhanraj@intel.com
Subject: Re: [RFC PATCH v4 3/4] selftests/sgx: add len field for EACCEPT op
Date: Wed, 8 Feb 2023 01:29:18 +0200	[thread overview]
Message-ID: <Y+LezsQyMfqrzGuA@kernel.org> (raw)
In-Reply-To: <20230128045529.15749-4-haitao.huang@linux.intel.com>

On Fri, Jan 27, 2023 at 08:55:28PM -0800, Haitao Huang wrote:
> So we can EACCEPT multiple pages inside enclave without EEXIT,
> preparing for testing with MADV_WILLNEED for ranges bigger than
> a single page.
> 
> Signed-off-by: Haitao Huang <haitao.huang@linux.intel.com>
> ---
>  tools/testing/selftests/sgx/defines.h   |  1 +
>  tools/testing/selftests/sgx/main.c      | 15 +++++++++++++++
>  tools/testing/selftests/sgx/test_encl.c | 18 ++++++++++++------
>  3 files changed, 28 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/sgx/defines.h b/tools/testing/selftests/sgx/defines.h
> index d8587c971941..8578e773d3d8 100644
> --- a/tools/testing/selftests/sgx/defines.h
> +++ b/tools/testing/selftests/sgx/defines.h
> @@ -60,6 +60,7 @@ struct encl_op_eaccept {
>  	struct encl_op_header header;
>  	uint64_t epc_addr;
>  	uint64_t flags;
> +	uint64_t len;
>  	uint64_t ret;
>  };
>  
> diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
> index e596b45bc5f8..e457f2d35461 100644
> --- a/tools/testing/selftests/sgx/main.c
> +++ b/tools/testing/selftests/sgx/main.c
> @@ -493,6 +493,7 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, TIMEOUT_DEFAULT)
>  
>  	eaccept_op.flags = SGX_SECINFO_TRIM | SGX_SECINFO_MODIFIED;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> +	eaccept_op.len = PAGE_SIZE;
>  
>  	TH_LOG("Entering enclave to run EACCEPT for each page of %zd bytes may take a while ...",
>  	       heap->size);
> @@ -916,6 +917,7 @@ TEST_F(enclave, epcm_permissions)
>  	 * EPCM permissions changed from kernel, need to EACCEPT from enclave.
>  	 */
>  	eaccept_op.epc_addr = data_start;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.flags = SGX_SECINFO_R | SGX_SECINFO_REG | SGX_SECINFO_PR;
>  	eaccept_op.ret = 0;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> @@ -1092,6 +1094,7 @@ TEST_F(enclave, augment)
>  	self->run.tcs = self->encl.encl_base + PAGE_SIZE;
>  
>  	eaccept_op.epc_addr = self->encl.encl_base + total_size;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.flags = SGX_SECINFO_R | SGX_SECINFO_W | SGX_SECINFO_REG | SGX_SECINFO_PENDING;
>  	eaccept_op.ret = 0;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> @@ -1194,6 +1197,7 @@ TEST_F(enclave, augment_via_eaccept)
>  	 * without a #PF). All should be transparent to userspace.
>  	 */
>  	eaccept_op.epc_addr = self->encl.encl_base + total_size;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.flags = SGX_SECINFO_R | SGX_SECINFO_W | SGX_SECINFO_REG | SGX_SECINFO_PENDING;
>  	eaccept_op.ret = 0;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> @@ -1299,6 +1303,7 @@ TEST_F_TIMEOUT(enclave, augment_via_eaccept_long, TIMEOUT_DEFAULT)
>  	 * without a #PF). All should be transparent to userspace.
>  	 */
>  	eaccept_op.flags = SGX_SECINFO_R | SGX_SECINFO_W | SGX_SECINFO_REG | SGX_SECINFO_PENDING;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.ret = 0;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
>  
> @@ -1451,6 +1456,7 @@ TEST_F(enclave, tcs_create)
>  	 */
>  
>  	eaccept_op.epc_addr = (unsigned long)stack_end;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.flags = SGX_SECINFO_R | SGX_SECINFO_W | SGX_SECINFO_REG | SGX_SECINFO_PENDING;
>  	eaccept_op.ret = 0;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> @@ -1471,6 +1477,7 @@ TEST_F(enclave, tcs_create)
>  	EXPECT_EQ(eaccept_op.ret, 0);
>  
>  	eaccept_op.epc_addr = (unsigned long)ssa;
> +	eaccept_op.len = PAGE_SIZE;
>  
>  	EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0);
>  
> @@ -1481,6 +1488,7 @@ TEST_F(enclave, tcs_create)
>  	EXPECT_EQ(eaccept_op.ret, 0);
>  
>  	eaccept_op.epc_addr = (unsigned long)tcs;
> +	eaccept_op.len = PAGE_SIZE;
>  
>  	EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0);
>  
> @@ -1533,6 +1541,7 @@ TEST_F(enclave, tcs_create)
>  
>  	/* EACCEPT new TCS page from enclave. */
>  	eaccept_op.epc_addr = (unsigned long)tcs;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.flags = SGX_SECINFO_TCS | SGX_SECINFO_MODIFIED;
>  	eaccept_op.ret = 0;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> @@ -1601,6 +1610,7 @@ TEST_F(enclave, tcs_create)
>  	self->run.tcs = self->encl.encl_base;
>  
>  	eaccept_op.epc_addr = (unsigned long)stack_end;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.flags = SGX_SECINFO_TRIM | SGX_SECINFO_MODIFIED;
>  	eaccept_op.ret = 0;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> @@ -1614,6 +1624,7 @@ TEST_F(enclave, tcs_create)
>  	EXPECT_EQ(eaccept_op.ret, 0);
>  
>  	eaccept_op.epc_addr = (unsigned long)tcs;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.ret = 0;
>  
>  	EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0);
> @@ -1625,6 +1636,7 @@ TEST_F(enclave, tcs_create)
>  	EXPECT_EQ(eaccept_op.ret, 0);
>  
>  	eaccept_op.epc_addr = (unsigned long)ssa;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.ret = 0;
>  
>  	EXPECT_EQ(ENCL_CALL(&eaccept_op, &self->run, true), 0);
> @@ -1653,6 +1665,7 @@ TEST_F(enclave, tcs_create)
>  	 * trigger dynamic add of regular page at that location.
>  	 */
>  	eaccept_op.epc_addr = (unsigned long)tcs;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.flags = SGX_SECINFO_R | SGX_SECINFO_W | SGX_SECINFO_REG | SGX_SECINFO_PENDING;
>  	eaccept_op.ret = 0;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> @@ -2022,6 +2035,7 @@ TEST_F(enclave, remove_added_page_invalid_access_after_eaccept)
>  	EXPECT_EQ(ioc.count, 4096);
>  
>  	eaccept_op.epc_addr = (unsigned long)data_start;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.ret = 0;
>  	eaccept_op.flags = SGX_SECINFO_TRIM | SGX_SECINFO_MODIFIED;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> @@ -2112,6 +2126,7 @@ TEST_F(enclave, remove_untouched_page)
>  	 */
>  
>  	eaccept_op.epc_addr = data_start;
> +	eaccept_op.len = PAGE_SIZE;
>  	eaccept_op.flags = SGX_SECINFO_TRIM | SGX_SECINFO_MODIFIED;
>  	eaccept_op.ret = 0;
>  	eaccept_op.header.type = ENCL_OP_EACCEPT;
> diff --git a/tools/testing/selftests/sgx/test_encl.c b/tools/testing/selftests/sgx/test_encl.c
> index c0d6397295e3..439f1adbd357 100644
> --- a/tools/testing/selftests/sgx/test_encl.c
> +++ b/tools/testing/selftests/sgx/test_encl.c
> @@ -37,12 +37,18 @@ static void do_encl_eaccept(void *_op)
>  	int rax;
>  
>  	secinfo.flags = op->flags;
> -
> -	asm volatile(".byte 0x0f, 0x01, 0xd7"
> -				: "=a" (rax)
> -				: "a" (EACCEPT),
> -				  "b" (&secinfo),
> -				  "c" (op->epc_addr));
> +	for (uint64_t addr = op->epc_addr;
> +			addr < op->epc_addr + op->len; addr += 4096) {
> +		asm volatile(".byte 0x0f, 0x01, 0xd7"
> +					: "=a" (rax)
> +					: "a" (EACCEPT),
> +					  "b" (&secinfo),
> +					  "c" (addr));
> +		if (rax) {
> +			op->ret = rax;
> +			return;
> +		}
> +	}
>  
>  	op->ret = rax;
>  }
> -- 
> 2.25.1
> 

Tested-by: Jarkko Sakkinen <jarkko@kernel.org> # NUC7
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

  parent reply	other threads:[~2023-02-07 23:29 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-28  4:55 [RFC PATCH v4 0/4] x86/sgx: implement support for MADV_WILLNEED Haitao Huang
2023-01-28  4:55 ` [RFC PATCH v4 1/4] x86/sgx: Export sgx_encl_eaug_page Haitao Huang
2023-01-28  4:55   ` [RFC PATCH v4 2/4] x86/sgx: Implement support for MADV_WILLNEED Haitao Huang
2023-01-28  4:55     ` [RFC PATCH v4 3/4] selftests/sgx: add len field for EACCEPT op Haitao Huang
2023-01-28  4:55       ` [RFC PATCH v4 4/4] selftests/sgx: Add test for madvise(..., WILLNEED) Haitao Huang
2023-02-07 23:30         ` Jarkko Sakkinen
2023-02-15  2:38         ` Huang, Kai
2023-02-15  4:42           ` Haitao Huang
2023-02-15  8:46             ` Huang, Kai
2023-02-17 22:29               ` jarkko
2023-02-07 23:29       ` Jarkko Sakkinen [this message]
2023-02-07 23:28     ` [RFC PATCH v4 2/4] x86/sgx: Implement support for MADV_WILLNEED Jarkko Sakkinen
2023-02-14  9:47     ` Huang, Kai
2023-02-14 19:18       ` Haitao Huang
2023-02-14 20:54         ` Huang, Kai
2023-02-14 21:42           ` Haitao Huang
2023-02-14 22:36             ` Huang, Kai
2023-02-15  3:59               ` Haitao Huang
2023-02-15  8:51                 ` Huang, Kai
2023-02-15 15:42                   ` Haitao Huang
2023-02-16  7:53                     ` Huang, Kai
2023-02-16 17:12                       ` Haitao Huang
2023-02-17 22:32                     ` jarkko
2023-02-17 23:03                       ` Haitao Huang
2023-02-21 22:10                         ` jarkko
2023-02-22  1:37                           ` Haitao Huang
2023-03-07 23:32                             ` Huang, Kai
2023-03-09  0:50                               ` Haitao Huang
2023-03-09 11:31                                 ` Huang, Kai
2023-03-14 14:54                                   ` Haitao Huang
2023-03-19 13:26                                     ` jarkko
2023-03-20  9:36                                       ` Huang, Kai
2023-03-20 14:04                                         ` jarkko
2023-05-27  0:32                                   ` Haitao Huang
2023-06-06  4:11                                     ` Huang, Kai
2023-06-07 16:59                                       ` Haitao Huang
2023-06-16  3:49                                       ` Huang, Kai
2023-06-16 22:05                                         ` Sean Christopherson
2023-06-19 11:17                                           ` Huang, Kai
2023-06-22 22:01                                             ` Sean Christopherson
2023-06-22 23:21                                               ` Huang, Kai
2023-06-26 22:28                                                 ` Sean Christopherson
2023-06-27 11:43                                                   ` Huang, Kai
2023-06-27 14:50                                                     ` Sean Christopherson
2023-06-28  9:37                                                       ` Huang, Kai
2023-06-28 14:57                                                         ` Sean Christopherson
2023-06-29  3:10                                                           ` Huang, Kai
2023-06-29 14:23                                                             ` Sean Christopherson
2023-06-29 23:29                                                               ` Huang, Kai
2023-06-30  0:14                                                                 ` Sean Christopherson
2023-06-30  0:56                                                                   ` Huang, Kai
2023-06-30  1:54                                                                 ` Jarkko Sakkinen
2023-06-30  1:57                                                                   ` Jarkko Sakkinen
2023-06-30  4:26                                                                     ` Huang, Kai
2023-06-30  9:35                                                                       ` Jarkko Sakkinen
2023-03-12  1:25                               ` jarkko
2023-03-12 22:25                                 ` Huang, Kai
2023-02-17 22:07           ` jarkko
2023-02-17 21:50       ` jarkko
2023-02-07 23:26   ` [RFC PATCH v4 1/4] x86/sgx: Export sgx_encl_eaug_page 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=Y+LezsQyMfqrzGuA@kernel.org \
    --to=jarkko@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=haitao.huang@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=vijay.dhanraj@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
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).