* [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN
@ 2022-08-12 20:13 Haitao Huang
2022-08-14 19:39 ` Jarkko Sakkinen
0 siblings, 1 reply; 7+ messages in thread
From: Haitao Huang @ 2022-08-12 20:13 UTC (permalink / raw)
To: linux-sgx, jarkko, reinette.chatre, dave.hansen
For EMODT and EREMOVE ioctls with a large range, kernel
may not finish in one shot and return EAGAIN error code
and count of bytes of EPC pages on that operations are
finished successfully.
Change the unclobbered_vdso_oversubscribed_remove test
to rerun the ioctls in a loop, updating offset and length
using the byte count returned in each iteration.
Signed-off-by: Haitao Huang <haitao.huang@intel.com>
---
tools/testing/selftests/sgx/main.c | 39 +++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index 9820b3809c69..ff66ce2bbcac 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -391,7 +391,7 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
unsigned long total_mem;
int ret, errno_save;
unsigned long addr;
- unsigned long i;
+ unsigned long i, count;
/*
* Create enclave with additional heap that is as big as all
@@ -453,16 +453,27 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
modt_ioc.offset = heap->offset;
modt_ioc.length = heap->size;
modt_ioc.page_type = SGX_PAGE_TYPE_TRIM;
-
+ count = 0;
TH_LOG("Changing type of %zd bytes to trimmed may take a while ...",
heap->size);
- ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
- errno_save = ret == -1 ? errno : 0;
+ do {
+ ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
+ errno_save = ret == -1 ? errno : 0;
+ if (errno_save == EAGAIN) {
+ count += modt_ioc.count;
+ modt_ioc.offset += modt_ioc.count;
+ modt_ioc.length -= modt_ioc.count;
+ modt_ioc.result= 0;
+ modt_ioc.count = 0;
+ } else
+ break;
+ } while(modt_ioc.length != 0);
EXPECT_EQ(ret, 0);
EXPECT_EQ(errno_save, 0);
EXPECT_EQ(modt_ioc.result, 0);
- EXPECT_EQ(modt_ioc.count, heap->size);
+ count += modt_ioc.count;
+ EXPECT_EQ(count, heap->size);
/* EACCEPT all removed pages. */
addr = self->encl.encl_base + heap->offset;
@@ -490,15 +501,25 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
remove_ioc.offset = heap->offset;
remove_ioc.length = heap->size;
-
+ count = 0;
TH_LOG("Removing %zd bytes from enclave may take a while ...",
heap->size);
- ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc);
- errno_save = ret == -1 ? errno : 0;
+ do {
+ ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc);
+ errno_save = ret == -1 ? errno : 0;
+ if (errno_save == EAGAIN) {
+ count += remove_ioc.count;
+ remove_ioc.offset += remove_ioc.count;
+ remove_ioc.length -= remove_ioc.count;
+ remove_ioc.count = 0;
+ } else
+ break;
+ } while(remove_ioc.length != 0);
EXPECT_EQ(ret, 0);
EXPECT_EQ(errno_save, 0);
- EXPECT_EQ(remove_ioc.count, heap->size);
+ count += remove_ioc.count;
+ EXPECT_EQ(count, heap->size);
}
TEST_F(enclave, clobbered_vdso)
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN
2022-08-12 20:13 [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN Haitao Huang
@ 2022-08-14 19:39 ` Jarkko Sakkinen
2022-08-16 5:16 ` Haitao Huang
0 siblings, 1 reply; 7+ messages in thread
From: Jarkko Sakkinen @ 2022-08-14 19:39 UTC (permalink / raw)
To: Haitao Huang; +Cc: linux-sgx, reinette.chatre, dave.hansen
On Fri, Aug 12, 2022 at 01:13:31PM -0700, Haitao Huang wrote:
> For EMODT and EREMOVE ioctls with a large range, kernel
> may not finish in one shot and return EAGAIN error code
> and count of bytes of EPC pages on that operations are
> finished successfully.
>
> Change the unclobbered_vdso_oversubscribed_remove test
> to rerun the ioctls in a loop, updating offset and length
> using the byte count returned in each iteration.
>
> Signed-off-by: Haitao Huang <haitao.huang@intel.com>
> ---
> tools/testing/selftests/sgx/main.c | 39 +++++++++++++++++++++++-------
> 1 file changed, 30 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
> index 9820b3809c69..ff66ce2bbcac 100644
> --- a/tools/testing/selftests/sgx/main.c
> +++ b/tools/testing/selftests/sgx/main.c
> @@ -391,7 +391,7 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
> unsigned long total_mem;
> int ret, errno_save;
> unsigned long addr;
> - unsigned long i;
> + unsigned long i, count;
>
> /*
> * Create enclave with additional heap that is as big as all
> @@ -453,16 +453,27 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
> modt_ioc.offset = heap->offset;
> modt_ioc.length = heap->size;
> modt_ioc.page_type = SGX_PAGE_TYPE_TRIM;
> -
> + count = 0;
> TH_LOG("Changing type of %zd bytes to trimmed may take a while ...",
> heap->size);
> - ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
> - errno_save = ret == -1 ? errno : 0;
> + do {
> + ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
> + errno_save = ret == -1 ? errno : 0;
> + if (errno_save == EAGAIN) {
> + count += modt_ioc.count;
> + modt_ioc.offset += modt_ioc.count;
> + modt_ioc.length -= modt_ioc.count;
> + modt_ioc.result= 0;
> + modt_ioc.count = 0;
> + } else
> + break;
> + } while(modt_ioc.length != 0);
>
> EXPECT_EQ(ret, 0);
> EXPECT_EQ(errno_save, 0);
> EXPECT_EQ(modt_ioc.result, 0);
> - EXPECT_EQ(modt_ioc.count, heap->size);
> + count += modt_ioc.count;
> + EXPECT_EQ(count, heap->size);
>
> /* EACCEPT all removed pages. */
> addr = self->encl.encl_base + heap->offset;
> @@ -490,15 +501,25 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
>
> remove_ioc.offset = heap->offset;
> remove_ioc.length = heap->size;
> -
> + count = 0;
> TH_LOG("Removing %zd bytes from enclave may take a while ...",
> heap->size);
> - ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc);
> - errno_save = ret == -1 ? errno : 0;
> + do {
> + ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc);
> + errno_save = ret == -1 ? errno : 0;
> + if (errno_save == EAGAIN) {
> + count += remove_ioc.count;
> + remove_ioc.offset += remove_ioc.count;
> + remove_ioc.length -= remove_ioc.count;
> + remove_ioc.count = 0;
> + } else
> + break;
> + } while(remove_ioc.length != 0);
>
> EXPECT_EQ(ret, 0);
> EXPECT_EQ(errno_save, 0);
> - EXPECT_EQ(remove_ioc.count, heap->size);
> + count += remove_ioc.count;
> + EXPECT_EQ(count, heap->size);
> }
>
> TEST_F(enclave, clobbered_vdso)
> --
> 2.25.1
>
Thank you.
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN
2022-08-14 19:39 ` Jarkko Sakkinen
@ 2022-08-16 5:16 ` Haitao Huang
2022-08-16 14:24 ` Jarkko Sakkinen
0 siblings, 1 reply; 7+ messages in thread
From: Haitao Huang @ 2022-08-16 5:16 UTC (permalink / raw)
To: jarkko; +Cc: dave.hansen, haitao.huang, linux-sgx, reinette.chatre
For EMODT and EREMOVE ioctls with a large range, kernel
may not finish in one shot and return EAGAIN error code
and count of bytes of EPC pages on that operations are
finished successfully.
Change the unclobbered_vdso_oversubscribed_remove test
to rerun the ioctls in a loop, updating offset and length
using the byte count returned in each iteration.
Signed-off-by: Haitao Huang <haitao.huang@linux.intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
---
tools/testing/selftests/sgx/main.c | 39 +++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c
index 9820b3809c69..9c8b5868b0f3 100644
--- a/tools/testing/selftests/sgx/main.c
+++ b/tools/testing/selftests/sgx/main.c
@@ -391,7 +391,7 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
unsigned long total_mem;
int ret, errno_save;
unsigned long addr;
- unsigned long i;
+ unsigned long i, count;
/*
* Create enclave with additional heap that is as big as all
@@ -453,16 +453,27 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
modt_ioc.offset = heap->offset;
modt_ioc.length = heap->size;
modt_ioc.page_type = SGX_PAGE_TYPE_TRIM;
-
+ count = 0;
TH_LOG("Changing type of %zd bytes to trimmed may take a while ...",
heap->size);
- ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
- errno_save = ret == -1 ? errno : 0;
+ do {
+ ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_MODIFY_TYPES, &modt_ioc);
+ errno_save = ret == -1 ? errno : 0;
+ if (errno_save == EAGAIN) {
+ count += modt_ioc.count;
+ modt_ioc.offset += modt_ioc.count;
+ modt_ioc.length -= modt_ioc.count;
+ modt_ioc.result = 0;
+ modt_ioc.count = 0;
+ } else
+ break;
+ } while (modt_ioc.length != 0);
EXPECT_EQ(ret, 0);
EXPECT_EQ(errno_save, 0);
EXPECT_EQ(modt_ioc.result, 0);
- EXPECT_EQ(modt_ioc.count, heap->size);
+ count += modt_ioc.count;
+ EXPECT_EQ(count, heap->size);
/* EACCEPT all removed pages. */
addr = self->encl.encl_base + heap->offset;
@@ -490,15 +501,25 @@ TEST_F_TIMEOUT(enclave, unclobbered_vdso_oversubscribed_remove, 900)
remove_ioc.offset = heap->offset;
remove_ioc.length = heap->size;
-
+ count = 0;
TH_LOG("Removing %zd bytes from enclave may take a while ...",
heap->size);
- ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc);
- errno_save = ret == -1 ? errno : 0;
+ do {
+ ret = ioctl(self->encl.fd, SGX_IOC_ENCLAVE_REMOVE_PAGES, &remove_ioc);
+ errno_save = ret == -1 ? errno : 0;
+ if (errno_save == EAGAIN) {
+ count += remove_ioc.count;
+ remove_ioc.offset += remove_ioc.count;
+ remove_ioc.length -= remove_ioc.count;
+ remove_ioc.count = 0;
+ } else
+ break;
+ } while (remove_ioc.length != 0);
EXPECT_EQ(ret, 0);
EXPECT_EQ(errno_save, 0);
- EXPECT_EQ(remove_ioc.count, heap->size);
+ count += remove_ioc.count;
+ EXPECT_EQ(count, heap->size);
}
TEST_F(enclave, clobbered_vdso)
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN
2022-08-16 5:16 ` Haitao Huang
@ 2022-08-16 14:24 ` Jarkko Sakkinen
2022-08-22 23:24 ` Dave Hansen
0 siblings, 1 reply; 7+ messages in thread
From: Jarkko Sakkinen @ 2022-08-16 14:24 UTC (permalink / raw)
To: Haitao Huang, Dave Hansen
Cc: linux-sgx, reinette.chatre, Borislav Petkov, Tony Luck
On Mon, Aug 15, 2022 at 10:16:56PM -0700, Haitao Huang wrote:
> For EMODT and EREMOVE ioctls with a large range, kernel
> may not finish in one shot and return EAGAIN error code
> and count of bytes of EPC pages on that operations are
> finished successfully.
>
> Change the unclobbered_vdso_oversubscribed_remove test
> to rerun the ioctls in a loop, updating offset and length
> using the byte count returned in each iteration.
>
> Signed-off-by: Haitao Huang <haitao.huang@linux.intel.com>
> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Also,
Tested-by: Jarkko Sakkinen <jarkko@kernel.org>
Dave, in addition to [*], these should be picked x86 tree for v6.0
https://lore.kernel.org/linux-sgx/20220815233900.11225-1-jarkko@kernel.org/T/#t
BR, Jarkko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN
2022-08-16 14:24 ` Jarkko Sakkinen
@ 2022-08-22 23:24 ` Dave Hansen
2022-08-25 4:42 ` Jarkko Sakkinen
0 siblings, 1 reply; 7+ messages in thread
From: Dave Hansen @ 2022-08-22 23:24 UTC (permalink / raw)
To: Jarkko Sakkinen, Haitao Huang, Dave Hansen
Cc: linux-sgx, reinette.chatre, Borislav Petkov, Tony Luck
On 8/16/22 07:24, Jarkko Sakkinen wrote:
> Dave, in addition to [*], these should be picked x86 tree for v6.0
>
> https://lore.kernel.org/linux-sgx/20220815233900.11225-1-jarkko@kernel.org/T/#t
Was there an ack somewhere in that thread that I missed?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN
2022-08-22 23:24 ` Dave Hansen
@ 2022-08-25 4:42 ` Jarkko Sakkinen
2022-08-25 5:39 ` Jarkko Sakkinen
0 siblings, 1 reply; 7+ messages in thread
From: Jarkko Sakkinen @ 2022-08-25 4:42 UTC (permalink / raw)
To: Dave Hansen
Cc: Haitao Huang, Dave Hansen, linux-sgx, reinette.chatre,
Borislav Petkov, Tony Luck
On Mon, Aug 22, 2022 at 04:24:50PM -0700, Dave Hansen wrote:
> On 8/16/22 07:24, Jarkko Sakkinen wrote:
> > Dave, in addition to [*], these should be picked x86 tree for v6.0
> >
> > https://lore.kernel.org/linux-sgx/20220815233900.11225-1-jarkko@kernel.org/T/#t
>
> Was there an ack somewhere in that thread that I missed?
Yes, both had mine.
I sent both unmodified bundled into a single patch set, except cosmetic
changes to the commit message. The discussion that followed up came up a
day later I've send that response.
The next version will be lacking ack's, given that I'm modifying the
patches, i.e. will be disqualified to review them.
BR, Jarkko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN
2022-08-25 4:42 ` Jarkko Sakkinen
@ 2022-08-25 5:39 ` Jarkko Sakkinen
0 siblings, 0 replies; 7+ messages in thread
From: Jarkko Sakkinen @ 2022-08-25 5:39 UTC (permalink / raw)
To: Dave Hansen
Cc: Haitao Huang, Dave Hansen, linux-sgx, reinette.chatre,
Borislav Petkov, Tony Luck
On Thu, Aug 25, 2022 at 07:42:18AM +0300, Jarkko Sakkinen wrote:
> On Mon, Aug 22, 2022 at 04:24:50PM -0700, Dave Hansen wrote:
> > On 8/16/22 07:24, Jarkko Sakkinen wrote:
> > > Dave, in addition to [*], these should be picked x86 tree for v6.0
> > >
> > > https://lore.kernel.org/linux-sgx/20220815233900.11225-1-jarkko@kernel.org/T/#t
> >
> > Was there an ack somewhere in that thread that I missed?
>
> Yes, both had mine.
>
> I sent both unmodified bundled into a single patch set, except cosmetic
> changes to the commit message. The discussion that followed up came up a
> day later I've send that response.
>
> The next version will be lacking ack's, given that I'm modifying the
> patches, i.e. will be disqualified to review them.
Also, the next version will include additional patch for
a bpftrace script derived from what I tossed with Haitao
in order to root cause the error. Probably useful to have
available, as it did the trick.
BR, Jarkko
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-08-25 5:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-12 20:13 [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN Haitao Huang
2022-08-14 19:39 ` Jarkko Sakkinen
2022-08-16 5:16 ` Haitao Huang
2022-08-16 14:24 ` Jarkko Sakkinen
2022-08-22 23:24 ` Dave Hansen
2022-08-25 4:42 ` Jarkko Sakkinen
2022-08-25 5:39 ` Jarkko Sakkinen
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.