public inbox for linux-sgx@vger.kernel.org
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: Jarkko Sakkinen <jarkko@kernel.org>, <linux-sgx@vger.kernel.org>
Cc: Haitao Huang <haitao.huang@linux.intel.com>,
	Vijay Dhanraj <vijay.dhanraj@intel.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 5/6] selftests/sgx: retry the ioctls returned with EAGAIN
Date: Tue, 30 Aug 2022 15:56:29 -0700	[thread overview]
Message-ID: <5d19be91-3aef-5cbe-6063-3ff3dbd5572b@intel.com> (raw)
In-Reply-To: <20220830031206.13449-6-jarkko@kernel.org>

Hi Haitao and Jarkko,


selftests/sgx: Retry the ioctl()s returned with EAGAIN


On 8/29/2022 8:12 PM, Jarkko Sakkinen wrote:
> From: Haitao Huang <haitao.huang@linux.intel.com>
> 
> For EMODT and EREMOVE ioctls with a large range, kernel

ioctl()s?

> 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

ioctl()s?

> using the byte count returned in each iteration.
> 

This is a valuable addition, thank you very much.

> Signed-off-by: Haitao Huang <haitao.huang@linux.intel.com>
> Tested-by: Jarkko Sakkinen <jarkko@kernel.org>
> Signed-off-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 867e98502120..3268d8b01b0b 100644
> --- a/tools/testing/selftests/sgx/main.c
> +++ b/tools/testing/selftests/sgx/main.c
> @@ -399,7 +399,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;

Reverse fir tree?

>  
>  	/*
>  	 * Create enclave with additional heap that is as big as all
> @@ -461,16 +461,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;

As part of the test I think it would be helpful to know if there was a result code
in here. What do you think of failing the test if it is not zero?

> +			modt_ioc.count = 0;
> +		} else
> +			break;

Watch out for unbalanced braces (also later in patch). This causes
checkpatch.pl noise.

> +	} 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;
> @@ -498,15 +509,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)

Reinette

  reply	other threads:[~2022-08-30 22:56 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30  3:12 [PATCH 0/6] x86/sgx: Test and fixes Jarkko Sakkinen
2022-08-30  3:12 ` [PATCH 1/6] x86/sgx: Do not consider unsanitized pages an error Jarkko Sakkinen
2022-08-30 22:54   ` Reinette Chatre
2022-08-31  1:27     ` Huang, Kai
2022-08-31  2:15       ` jarkko
2022-08-31  2:35         ` Huang, Kai
2022-08-31  2:44           ` jarkko
2022-08-31  2:55             ` Huang, Kai
2022-08-31  2:57               ` jarkko
2022-08-31  3:10                 ` Jarkko Sakkinen
2022-08-31  3:28                   ` Huang, Kai
2022-08-31  3:40                     ` jarkko
2022-08-31  3:17                 ` Huang, Kai
2022-08-31 15:18                   ` Haitao Huang
2022-08-31 18:28                     ` jarkko
2022-08-31 18:35                       ` Dave Hansen
2022-08-31 18:44                         ` jarkko
2022-08-31 18:45                         ` jarkko
2022-08-31 20:42                         ` Huang, Kai
2022-09-01 22:27                           ` jarkko
2022-09-01 22:41                             ` Huang, Kai
2022-09-01 23:58                               ` jarkko
2022-09-02  0:26                                 ` Huang, Kai
2022-08-31  1:55     ` Jarkko Sakkinen
2022-08-31  1:58       ` Jarkko Sakkinen
2022-08-31  2:01         ` Jarkko Sakkinen
2022-08-31 18:08       ` Reinette Chatre
2022-08-30  3:12 ` [PATCH 2/6] x86/sgx: Handle VA page allocation failure for EAUG on PF Jarkko Sakkinen
2022-08-30 22:54   ` Reinette Chatre
2022-08-30  3:12 ` [PATCH 3/6] selftests/sgx: Ignore OpenSSL 3.0 deprecated functions warning Jarkko Sakkinen
2022-08-30 18:18   ` Reinette Chatre
2022-08-31  1:07     ` Jarkko Sakkinen
2022-08-30  3:12 ` [PATCH 4/6] selftests/sgx: Add SGX selftest augment_via_eaccept_long Jarkko Sakkinen
2022-08-30 22:55   ` Reinette Chatre
2022-08-31  2:28     ` Jarkko Sakkinen
2022-08-31 18:09       ` Reinette Chatre
2022-09-01 22:16         ` Jarkko Sakkinen
2022-09-01 23:11           ` Reinette Chatre
2022-09-02  0:00             ` Jarkko Sakkinen
2022-09-02  0:02               ` Jarkko Sakkinen
2022-08-30  3:12 ` [PATCH 5/6] selftests/sgx: retry the ioctls returned with EAGAIN Jarkko Sakkinen
2022-08-30 22:56   ` Reinette Chatre [this message]
2022-08-31  2:31     ` Jarkko Sakkinen
2022-08-31 18:09       ` Reinette Chatre
2022-09-01 22:17         ` Jarkko Sakkinen
2022-08-31 18:14       ` Dave Hansen
2022-09-01 22:18         ` Jarkko Sakkinen
2022-08-30  3:12 ` [PATCH 6/6] selftests/sgx: Add a bpftrace script for tracking allocation errors Jarkko Sakkinen
2022-08-30 22:57   ` Reinette Chatre
2022-08-31  2:33     ` Jarkko Sakkinen
2022-08-31 18:10       ` Reinette Chatre
2022-08-31 18:23         ` Jarkko Sakkinen
2022-08-31 18:23   ` Dave Hansen
2022-09-01 22:20     ` Jarkko Sakkinen
2022-09-01 22:34       ` Dave Hansen
2022-09-01 23:55         ` 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=5d19be91-3aef-5cbe-6063-3ff3dbd5572b@intel.com \
    --to=reinette.chatre@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=haitao.huang@linux.intel.com \
    --cc=jarkko@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=shuah@kernel.org \
    --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