From patchwork Thu Oct 17 03:03:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11194717 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E6C429B1 for ; Thu, 17 Oct 2019 03:03:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68580218DE for ; Thu, 17 Oct 2019 03:03:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392136AbfJQDDr (ORCPT ); Wed, 16 Oct 2019 23:03:47 -0400 Received: from mga18.intel.com ([134.134.136.126]:51165 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392141AbfJQDDr (ORCPT ); Wed, 16 Oct 2019 23:03:47 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2019 20:03:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,306,1566889200"; d="scan'208";a="195026833" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.41]) by fmsmga008.fm.intel.com with ESMTP; 16 Oct 2019 20:03:44 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-sgx@vger.kernel.org, Cedric Xing , Andy Lutomirski Subject: [PATCH for_v2? v2 05/14] selftests/x86/sgx: Move vDSO setup to a helper function Date: Wed, 16 Oct 2019 20:03:31 -0700 Message-Id: <20191017030340.18301-6-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20191017030340.18301-1-sean.j.christopherson@intel.com> References: <20191017030340.18301-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Move the vDSO setup code to a helper function so that it is more obvious that it's run-once setup, and that setting eenter is the end goal of the code. Signed-off-by: Sean Christopherson --- tools/testing/selftests/x86/sgx/main.c | 41 ++++++++++++++++---------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/x86/sgx/main.c b/tools/testing/selftests/x86/sgx/main.c index e87e445f6de1..2510cacb5154 100644 --- a/tools/testing/selftests/x86/sgx/main.c +++ b/tools/testing/selftests/x86/sgx/main.c @@ -309,16 +309,36 @@ static bool load_sigstruct(const char *path, void *sigstruct) return true; } +static bool setup_vdso(void) +{ + struct vdso_symtab symtab; + Elf64_Sym *eenter_sym; + void *addr; + + addr = vdso_get_base_addr(); + if (!addr) + return false; + + if (!vdso_get_symtab(addr, &symtab)) + return false; + + eenter_sym = vdso_symtab_get(&symtab, "__vdso_sgx_enter_enclave"); + if (!eenter_sym) + return false; + + /* eenter is used by sgx_call_vdso() to call into the vDSO. */ + eenter = addr + eenter_sym->st_value; + + return true; +} + int main(int argc, char *argv[], char *envp[]) { struct sgx_enclave_exception exception; struct sgx_sigstruct sigstruct; - struct vdso_symtab symtab; - Elf64_Sym *eenter_sym; struct sgx_secs secs; uint64_t result = 0; off_t bin_size; - void *addr; void *bin; if (!encl_data_map("encl.bin", &bin, &bin_size)) @@ -340,20 +360,11 @@ int main(int argc, char *argv[], char *envp[]) printf("Output: 0x%lx\n", result); + if (!setup_vdso()) + exit(1); + memset(&exception, 0, sizeof(exception)); - addr = vdso_get_base_addr(); - if (!addr) - exit(1); - - if (!vdso_get_symtab(addr, &symtab)) - exit(1); - - eenter_sym = vdso_symtab_get(&symtab, "__vdso_sgx_enter_enclave"); - if (!eenter_sym) - exit(1); - eenter = addr + eenter_sym->st_value; - printf("Input: 0x%lx\n", MAGIC); sgx_call_vdso((void *)&MAGIC, &result, NULL, NULL, NULL, NULL,