[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e58ee564-597a-336e-53dc-7c4d172d51f5@linuxfoundation.org>
Date: Mon, 16 Nov 2020 11:19:12 -0700
From: Shuah Khan <skhan@...uxfoundation.org>
To: Jarkko Sakkinen <jarkko@...nel.org>, x86@...nel.org,
linux-sgx@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, Shuah Khan <shuah@...nel.org>,
linux-kselftest@...r.kernel.org,
Jethro Beekman <jethro@...tanix.com>,
akpm@...ux-foundation.org, andriy.shevchenko@...ux.intel.com,
asapek@...gle.com, bp@...en8.de, cedric.xing@...el.com,
chenalexchen@...gle.com, conradparker@...gle.com,
cyhanish@...gle.com, dave.hansen@...el.com, haitao.huang@...el.com,
kai.huang@...el.com, kai.svahn@...el.com, kmoy@...gle.com,
ludloff@...gle.com, luto@...nel.org, nhorman@...hat.com,
npmccallum@...hat.com, puiterwijk@...hat.com, rientjes@...gle.com,
sean.j.christopherson@...el.com, tglx@...utronix.de,
yaozhangx@...gle.com, mikko.ylinen@...el.com
Subject: Re: [PATCH v41 20/24] selftests/x86: Add a selftest for SGX
On 11/12/20 3:01 PM, Jarkko Sakkinen wrote:
> Add a selftest for SGX. It is a trivial test where a simple enclave copies
> one 64-bit word of memory between two memory locations, but ensures that
> all SGX hardware and software infrastructure is functioning.
>
> Cc: Shuah Khan <shuah@...nel.org>
> Cc: linux-kselftest@...r.kernel.org
> Acked-by: Jethro Beekman <jethro@...tanix.com> # v40
> Signed-off-by: Jarkko Sakkinen <jarkko@...nel.org>
> ---
> Changes from v40:
> * Remove $(OUTPUT)/test_encl.elf from TEST_CUSTOM_PROGS, as otherwise
> run_tests tries to execute it. Add it as a build dependency.
> * Use the correct device path, /dev/sgx_enclave, instead of
> /dev/sgx/enclave.
> * Return kselftest framework expected return codes.
>
> tools/testing/selftests/Makefile | 1 +
> tools/testing/selftests/sgx/.gitignore | 2 +
> tools/testing/selftests/sgx/Makefile | 53 +++
> tools/testing/selftests/sgx/call.S | 44 ++
> tools/testing/selftests/sgx/defines.h | 21 +
> tools/testing/selftests/sgx/load.c | 277 +++++++++++++
> tools/testing/selftests/sgx/main.c | 246 +++++++++++
> tools/testing/selftests/sgx/main.h | 38 ++
> tools/testing/selftests/sgx/sigstruct.c | 391 ++++++++++++++++++
> tools/testing/selftests/sgx/test_encl.c | 20 +
> tools/testing/selftests/sgx/test_encl.lds | 40 ++
> .../selftests/sgx/test_encl_bootstrap.S | 89 ++++
> 12 files changed, 1222 insertions(+)
> create mode 100644 tools/testing/selftests/sgx/.gitignore
> create mode 100644 tools/testing/selftests/sgx/Makefile
> create mode 100644 tools/testing/selftests/sgx/call.S
> create mode 100644 tools/testing/selftests/sgx/defines.h
> create mode 100644 tools/testing/selftests/sgx/load.c
> create mode 100644 tools/testing/selftests/sgx/main.c
> create mode 100644 tools/testing/selftests/sgx/main.h
> create mode 100644 tools/testing/selftests/sgx/sigstruct.c
> create mode 100644 tools/testing/selftests/sgx/test_encl.c
> create mode 100644 tools/testing/selftests/sgx/test_encl.lds
> create mode 100644 tools/testing/selftests/sgx/test_encl_bootstrap.S
>
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index d9c283503159..aa06e3ea0250 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -68,6 +68,7 @@ TARGETS += user
> TARGETS += vm
> TARGETS += x86
> TARGETS += zram
> +TARGETS += sgx
> #Please keep the TARGETS list alphabetically sorted
Please keep the list sorted alphabetically as stated
in the comment above.
> +}
> +
> +int main(int argc, char *argv[], char *envp[])
> +{
> + struct sgx_enclave_run run;
> + struct vdso_symtab symtab;
> + Elf64_Sym *eenter_sym;
> + uint64_t result = 0;
> + struct encl encl;
> + unsigned int i;
> + void *addr;
> + int ret;
> +
> + memset(&run, 0, sizeof(run));
> +
> + if (!encl_load("test_encl.elf", &encl)) {
> + encl_delete(&encl);
> + ksft_exit_skip("cannot load enclaves\n");
> + }
> +
> + if (!encl_measure(&encl))
> + goto err;
> +
> + if (!encl_build(&encl))
> + goto err;
> +
> + /*
> + * An enclave consumer only must do this.
> + */
> + for (i = 0; i < encl.nr_segments; i++) {
> + struct encl_segment *seg = &encl.segment_tbl[i];
> +
> + addr = mmap((void *)encl.encl_base + seg->offset, seg->size,
> + seg->prot, MAP_SHARED | MAP_FIXED, encl.fd, 0);
> + if (addr == MAP_FAILED) {
> + fprintf(stderr, "mmap() failed, errno=%d.\n", errno);
> + exit(1);
This should be KSFT_FAIL.
thanks,
-- Shuah
Powered by blists - more mailing lists