diff mbox series

[RFC,v3,3/4] selftests/sgx: add len field for EACCEPT op

Message ID 20221107220212.257422-4-haitao.huang@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series x86/sgx: implement support for MADV_WILLNEED | expand

Commit Message

Haitao Huang Nov. 7, 2022, 10:02 p.m. UTC
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/test_encl.c | 20 ++++++++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

Comments

Jarkko Sakkinen Nov. 15, 2022, 11:24 p.m. UTC | #1
On Mon, Nov 07, 2022 at 02:02:11PM -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/test_encl.c | 20 ++++++++++++++------
>  2 files changed, 15 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/test_encl.c b/tools/testing/selftests/sgx/test_encl.c
> index c0d6397295e3..fc797385200b 100644
> --- a/tools/testing/selftests/sgx/test_encl.c
> +++ b/tools/testing/selftests/sgx/test_encl.c
> @@ -35,14 +35,22 @@ static void do_encl_eaccept(void *_op)
>  	struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo)) = {0};
>  	struct encl_op_eaccept *op = _op;
>  	int rax;

Should be empty line after declarations.

> +	if (op->len == 0)
> +		op->len = 4096;

What is this?

>  
>  	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
> 

BR, Jarkko
Haitao Huang Nov. 16, 2022, 7:26 p.m. UTC | #2
On Tue, 15 Nov 2022 17:24:29 -0600, Jarkko Sakkinen <jarkko@kernel.org>  
wrote:

> On Mon, Nov 07, 2022 at 02:02:11PM -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/test_encl.c | 20 ++++++++++++++------
>>  2 files changed, 15 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/test_encl.c  
>> b/tools/testing/selftests/sgx/test_encl.c
>> index c0d6397295e3..fc797385200b 100644
>> --- a/tools/testing/selftests/sgx/test_encl.c
>> +++ b/tools/testing/selftests/sgx/test_encl.c
>> @@ -35,14 +35,22 @@ static void do_encl_eaccept(void *_op)
>>  	struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo)) =  
>> {0};
>>  	struct encl_op_eaccept *op = _op;
>>  	int rax;
>
> Should be empty line after declarations.
>
>> +	if (op->len == 0)
>> +		op->len = 4096;
>
> What is this?

Existing test cases is always eaccepting one page at a time.
With the new len field, this is to set value to 1 page by default so no  
changes in other places is needed.
I can add a comment in struct encl_op_eaccept declaration or let me know  
if you prefer a different way.

Thanks
Haitao
Haitao
Jarkko Sakkinen Nov. 27, 2022, 5:16 p.m. UTC | #3
On Wed, Nov 16, 2022 at 01:26:46PM -0600, Haitao Huang wrote:
> On Tue, 15 Nov 2022 17:24:29 -0600, Jarkko Sakkinen <jarkko@kernel.org>
> wrote:
> 
> > On Mon, Nov 07, 2022 at 02:02:11PM -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/test_encl.c | 20 ++++++++++++++------
> > >  2 files changed, 15 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/test_encl.c
> > > b/tools/testing/selftests/sgx/test_encl.c
> > > index c0d6397295e3..fc797385200b 100644
> > > --- a/tools/testing/selftests/sgx/test_encl.c
> > > +++ b/tools/testing/selftests/sgx/test_encl.c
> > > @@ -35,14 +35,22 @@ static void do_encl_eaccept(void *_op)
> > >  	struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo)) =
> > > {0};
> > >  	struct encl_op_eaccept *op = _op;
> > >  	int rax;
> > 
> > Should be empty line after declarations.
> > 
> > > +	if (op->len == 0)
> > > +		op->len = 4096;
> > 
> > What is this?
> 
> Existing test cases is always eaccepting one page at a time.
> With the new len field, this is to set value to 1 page by default so no
> changes in other places is needed.
> I can add a comment in struct encl_op_eaccept declaration or let me know if
> you prefer a different way.

Please set op->len properly in all test cases.

BR, Jarkko
diff mbox series

Patch

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/test_encl.c b/tools/testing/selftests/sgx/test_encl.c
index c0d6397295e3..fc797385200b 100644
--- a/tools/testing/selftests/sgx/test_encl.c
+++ b/tools/testing/selftests/sgx/test_encl.c
@@ -35,14 +35,22 @@  static void do_encl_eaccept(void *_op)
 	struct sgx_secinfo secinfo __aligned(sizeof(struct sgx_secinfo)) = {0};
 	struct encl_op_eaccept *op = _op;
 	int rax;
+	if (op->len == 0)
+		op->len = 4096;
 
 	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;
 }