From: Jarkko Sakkinen <jarkko@kernel.org>
To: Haitao Huang <haitao.huang@linux.intel.com>
Cc: linux-sgx@vger.kernel.org, reinette.chatre@intel.com,
dave.hansen@linux.intel.com
Subject: Re: [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN
Date: Sun, 14 Aug 2022 22:39:13 +0300 [thread overview]
Message-ID: <YvlPYRvMicz9CPFQ@kernel.org> (raw)
In-Reply-To: <20220812201331.18791-1-haitao.huang@linux.intel.com>
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
next prev parent reply other threads:[~2022-08-14 19:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-12 20:13 [PATCH] selftests/sgx: retry the ioctls returned with EAGAIN Haitao Huang
2022-08-14 19:39 ` Jarkko Sakkinen [this message]
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
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=YvlPYRvMicz9CPFQ@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 \
/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