From patchwork Thu May 6 01:31:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 12241431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0F41C433B4 for ; Thu, 6 May 2021 01:32:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0D18613B4 for ; Thu, 6 May 2021 01:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230185AbhEFBdO (ORCPT ); Wed, 5 May 2021 21:33:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:39698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229465AbhEFBdN (ORCPT ); Wed, 5 May 2021 21:33:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 924F36139A; Thu, 6 May 2021 01:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620264736; bh=1xn40oQKUVwuTZyaZSO40QqkHHGTwn9D+xdZOmEckzU=; h=From:To:Cc:Subject:Date:From; b=oUcy/DaH57sYVYz+CNC2vAcDU14jVTt5wtNG8jvdUx6a/pyHxqo03FQPbaHPbPEN0 RHjdntUCFmJwoGZiAtitMEHtTdBi1zsfHxdjUqeYik2niogqluAClU4Clz2NvhFi7P fuPd5QaB+U0vOpQ1I0G3ZkH4zBgVKDjjZ+YyZFMU9QdtjDtRImRueELQXSDtDM/x0E oZQ7nWs0c5W+j4+MBpaLjXjy7soUrdYLx2dVxLSKgTHr50ikXItvX9Yx65SNH0bBG3 sHsc+yzHuPJY52861ZTo64bkk+Y5sZqnzKTYetDIlpqlACuLXvvyPFmFYhwB7ZAdC7 SZH13mvUXQ58Q== From: Jarkko Sakkinen To: Shuah Khan Cc: linux-sgx@vger.kernel.org, dave.hansen@intel.com, Jarkko Sakkinen , Dave Hansen , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] selftests/sgx: Rename 'eenter' and 'sgx_call_vdso' Date: Thu, 6 May 2021 04:31:59 +0300 Message-Id: <20210506013201.126612-1-jarkko@kernel.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Rename 'eenter' as 'sgx_enter_enclave', and 'sgx_call_vdso' as 'sgx_enter_enclave_unclobbered', in order to better self-describe the meaning and purpose of the symbols. Signed-off-by: Jarkko Sakkinen --- tools/testing/selftests/sgx/call.S | 6 +++--- tools/testing/selftests/sgx/main.c | 25 +++++++++++++------------ tools/testing/selftests/sgx/main.h | 4 ++-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/sgx/call.S b/tools/testing/selftests/sgx/call.S index 4ecadc7490f4..71865302119c 100644 --- a/tools/testing/selftests/sgx/call.S +++ b/tools/testing/selftests/sgx/call.S @@ -5,8 +5,8 @@ .text - .global sgx_call_vdso -sgx_call_vdso: + .global sgx_enter_enclave_unclobbered +sgx_enter_enclave_unclobbered: .cfi_startproc push %r15 .cfi_adjust_cfa_offset 8 @@ -27,7 +27,7 @@ sgx_call_vdso: .cfi_adjust_cfa_offset 8 push 0x38(%rsp) .cfi_adjust_cfa_offset 8 - call *eenter(%rip) + call *sgx_enter_enclave(%rip) add $0x10, %rsp .cfi_adjust_cfa_offset -0x10 pop %rbx diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c index d304a4044eb9..d3e1db9ee4bc 100644 --- a/tools/testing/selftests/sgx/main.c +++ b/tools/testing/selftests/sgx/main.c @@ -21,7 +21,7 @@ #include "../kselftest.h" static const uint64_t MAGIC = 0x1122334455667788ULL; -vdso_sgx_enter_enclave_t eenter; +vdso_sgx_enter_enclave_t sgx_enter_enclave; struct vdso_symtab { Elf64_Sym *elf_symtab; @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) { struct sgx_enclave_run run; struct vdso_symtab symtab; - Elf64_Sym *eenter_sym; + Elf64_Sym *sgx_enter_enclave_sym; uint64_t result = 0; struct encl encl; unsigned int i; @@ -194,29 +194,30 @@ int main(int argc, char *argv[]) if (!vdso_get_symtab(addr, &symtab)) goto err; - eenter_sym = vdso_symtab_get(&symtab, "__vdso_sgx_enter_enclave"); - if (!eenter_sym) + sgx_enter_enclave_sym = vdso_symtab_get(&symtab, "__vdso_sgx_enter_enclave"); + if (!sgx_enter_enclave_sym) goto err; - eenter = addr + eenter_sym->st_value; + sgx_enter_enclave = addr + sgx_enter_enclave_sym->st_value; - ret = sgx_call_vdso((void *)&MAGIC, &result, 0, EENTER, NULL, NULL, &run); - if (!report_results(&run, ret, result, "sgx_call_vdso")) + ret = sgx_enter_enclave_unclobbered((void *)&MAGIC, &result, 0, EENTER, + NULL, NULL, &run); + if (!report_results(&run, ret, result, "sgx_enter_enclave_unclobbered")) goto err; /* Invoke the vDSO directly. */ result = 0; - ret = eenter((unsigned long)&MAGIC, (unsigned long)&result, 0, EENTER, - 0, 0, &run); - if (!report_results(&run, ret, result, "eenter")) + ret = sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result, + 0, EENTER, 0, 0, &run); + if (!report_results(&run, ret, result, "sgx_enter_enclave")) goto err; /* And with an exit handler. */ run.user_handler = (__u64)user_handler; run.user_data = 0xdeadbeef; - ret = eenter((unsigned long)&MAGIC, (unsigned long)&result, 0, EENTER, - 0, 0, &run); + ret = sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result, + 0, EENTER, 0, 0, &run); if (!report_results(&run, ret, result, "user_handler")) goto err; diff --git a/tools/testing/selftests/sgx/main.h b/tools/testing/selftests/sgx/main.h index 67211a708f04..13479837f6eb 100644 --- a/tools/testing/selftests/sgx/main.h +++ b/tools/testing/selftests/sgx/main.h @@ -35,7 +35,7 @@ bool encl_load(const char *path, struct encl *encl); bool encl_measure(struct encl *encl); bool encl_build(struct encl *encl); -int sgx_call_vdso(void *rdi, void *rsi, long rdx, u32 function, void *r8, void *r9, - struct sgx_enclave_run *run); +int sgx_enter_enclave_unclobbered(void *rdi, void *rsi, long rdx, u32 function, void *r8, void *r9, + struct sgx_enclave_run *run); #endif /* MAIN_H */ From patchwork Thu May 6 01:32:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 12241433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C682C433ED for ; Thu, 6 May 2021 01:32:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 386F4613C0 for ; Thu, 6 May 2021 01:32:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbhEFBd1 (ORCPT ); Wed, 5 May 2021 21:33:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:40856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230059AbhEFBdZ (ORCPT ); Wed, 5 May 2021 21:33:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1A17E613B4; Thu, 6 May 2021 01:32:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620264748; bh=SBH+MobRpF+5DDP94nORP4AYMydp5fDZmfQhl9jAGzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=srvWBwloZNeSB4WOXjucMRJLoOfSNxcA0twb/dD8oJw2GHFSuzx1Jp7RTWbg+B7Kn KcRrH3XxIDfBmj5LD3ZAi71lIQsVb+NnIL0MZB3AfA98ZG7V61VctCPqQH45+le4Uv U3b09jIQbdtJsFqzt8BGW6QIgIV4Itrg0fyFC0YPyNl6mU2nxEhlyViLt1+L7dVu15 8fg2a81wnwutYrEXBjU/W3PGEdlTk6xt/ExCozH1aMTDmq5bIhIWPEdmS1vyHRRLQX 82rDXImQKREvowfPl7xB+86kmukK398dfxfEoocOQjaqiDzmUl8kiIQm8paXa9r1Z/ 6xljAh2WQkgEg== From: Jarkko Sakkinen To: Shuah Khan Cc: linux-sgx@vger.kernel.org, dave.hansen@intel.com, Jarkko Sakkinen , Dave Hansen , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] selftests/sgx: Report kselftest results Date: Thu, 6 May 2021 04:32:00 +0300 Message-Id: <20210506013201.126612-2-jarkko@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210506013201.126612-1-jarkko@kernel.org> References: <20210506013201.126612-1-jarkko@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Use ksft API documented in tools/testing/selftests/kselftest.h to count succeeded and failed tests and print all the debug output with ksft_print_msg(), as advised by the documentation. Signed-off-by: Jarkko Sakkinen --- tools/testing/selftests/sgx/main.c | 45 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c index d3e1db9ee4bc..b5f17076b0c3 100644 --- a/tools/testing/selftests/sgx/main.c +++ b/tools/testing/selftests/sgx/main.c @@ -20,6 +20,8 @@ #include "main.h" #include "../kselftest.h" +#define NR_KSELFTESTS 3 + static const uint64_t MAGIC = 0x1122334455667788ULL; vdso_sgx_enter_enclave_t sgx_enter_enclave; @@ -107,34 +109,35 @@ static Elf64_Sym *vdso_symtab_get(struct vdso_symtab *symtab, const char *name) return NULL; } -bool report_results(struct sgx_enclave_run *run, int ret, uint64_t result, - const char *test) +bool update_ksft(struct sgx_enclave_run *run, int ret, uint64_t result, const char *test) { bool valid = true; if (ret) { - printf("FAIL: %s() returned: %d\n", test, ret); + ksft_print_msg("%s: ret = %d\n", test, ret); valid = false; } if (run->function != EEXIT) { - printf("FAIL: %s() function, expected: %u, got: %u\n", test, EEXIT, - run->function); + ksft_print_msg("%s: function, expected: %u, got: %u\n", test, EEXIT, run->function); valid = false; } if (result != MAGIC) { - printf("FAIL: %s(), expected: 0x%lx, got: 0x%lx\n", test, MAGIC, - result); + ksft_print_msg("%s: expected: 0x%lx, got: 0x%lx\n", test, MAGIC, result); valid = false; } if (run->user_data) { - printf("FAIL: %s() user data, expected: 0x0, got: 0x%llx\n", - test, run->user_data); + ksft_print_msg("%s: user data, expected: 0x0, got: 0x%llx\n", test, run->user_data); valid = false; } + if (valid) + ksft_test_result_pass("%s: PASS"); + else + ksft_test_result_fail("%s: FAIL"); + return valid; } @@ -156,6 +159,9 @@ int main(int argc, char *argv[]) void *addr; int ret; + ksft_print_header(); + ksft_set_plan(NR_KSELFTESTS); + memset(&run, 0, sizeof(run)); if (!encl_load("test_encl.elf", &encl)) { @@ -178,8 +184,8 @@ int main(int argc, char *argv[]) addr = mmap((void *)encl.encl_base + seg->offset, seg->size, seg->prot, MAP_SHARED | MAP_FIXED, encl.fd, 0); if (addr == MAP_FAILED) { - perror("mmap() segment failed"); - exit(KSFT_FAIL); + ksft_print_msg("mmap() segment: %s", strerror(errno)); + goto err; } } @@ -200,32 +206,31 @@ int main(int argc, char *argv[]) sgx_enter_enclave = addr + sgx_enter_enclave_sym->st_value; + /* 1: unclobbered vDSO */ ret = sgx_enter_enclave_unclobbered((void *)&MAGIC, &result, 0, EENTER, NULL, NULL, &run); - if (!report_results(&run, ret, result, "sgx_enter_enclave_unclobbered")) + if (!update_ksft(&run, ret, result, "unclobbered")) goto err; - - /* Invoke the vDSO directly. */ + /* 2: clobbered vDSO */ result = 0; ret = sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result, 0, EENTER, 0, 0, &run); - if (!report_results(&run, ret, result, "sgx_enter_enclave")) + if (!update_ksft(&run, ret, result, "sgx_enter_enclave")) goto err; - /* And with an exit handler. */ + /* 3: clobbered vDSO with a callback. */ run.user_handler = (__u64)user_handler; run.user_data = 0xdeadbeef; ret = sgx_enter_enclave((unsigned long)&MAGIC, (unsigned long)&result, 0, EENTER, 0, 0, &run); - if (!report_results(&run, ret, result, "user_handler")) + if (!update_ksft(&run, ret, result, "user_handler")) goto err; - printf("SUCCESS\n"); encl_delete(&encl); - exit(KSFT_PASS); + ksft_exit_pass(); err: encl_delete(&encl); - exit(KSFT_FAIL); + ksft_exit_fail(); }