From patchwork Fri Sep 4 10:44:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11756611 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 0964992C for ; Fri, 4 Sep 2020 10:45:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E56CC208B3 for ; Fri, 4 Sep 2020 10:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729950AbgIDKpF (ORCPT ); Fri, 4 Sep 2020 06:45:05 -0400 Received: from mga02.intel.com ([134.134.136.20]:43129 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729930AbgIDKpE (ORCPT ); Fri, 4 Sep 2020 06:45:04 -0400 IronPort-SDR: guuGhad5eU6tAi662a7kgZzGTuAbPtQjUWiCftbcOmxVCrz0uBQmfXmIsVUnV+vwTU5FiWleRB Al6V3MKTHZZw== X-IronPort-AV: E=McAfee;i="6000,8403,9733"; a="145455666" X-IronPort-AV: E=Sophos;i="5.76,389,1592895600"; d="scan'208";a="145455666" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Sep 2020 03:44:48 -0700 IronPort-SDR: QBzi98Hgk9UWni+Vi36Z9WvGjWSSPIRdvNaU+lITfW+yJE/MmvooVr07uhZ5FjWAITLwrD7/GR ytzsYYy2qbaw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,389,1592895600"; d="scan'208";a="283026292" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.160]) by fmsmga007.fm.intel.com with ESMTP; 04 Sep 2020 03:44:47 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: Nathaniel McCallum , Cedric Xing , Jethro Beekman , Andy Lutomirski , linux-sgx@vger.kernel.org Subject: [PATCH for_v37 6/6] selftests/sgx: Add a smoke test to ensure the user handler is invoked Date: Fri, 4 Sep 2020 03:44:37 -0700 Message-Id: <20200904104437.29555-7-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200904104437.29555-1-sean.j.christopherson@intel.com> References: <20200904104437.29555-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 Add a very simple exit handler and use it as a third variant of the SGX selftest to verify that the vDSO invokes then user's handler when one is supplied. Signed-off-by: Sean Christopherson Acked-by: Jarkko Sakkinen --- tools/testing/selftests/sgx/main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/testing/selftests/sgx/main.c b/tools/testing/selftests/sgx/main.c index 158ea9e2b6d3a..44acb3c720675 100644 --- a/tools/testing/selftests/sgx/main.c +++ b/tools/testing/selftests/sgx/main.c @@ -137,10 +137,21 @@ int check_result(struct sgx_enclave_run *run, int ret, uint64_t result, printf("FAIL: %s(), expected: 0x%lx, got: 0x%lx\n", test, MAGIC, result); return -EIO; + } else if (run->user_data) { + printf("FAIL: %s() user data, expected: 0x0, got: 0x%llx\n", + test, run->user_data); + return -EIO; } return 0; } +static int exit_handler(long rdi, long rsi, long rdx, long ursp, long r8, long r9, + struct sgx_enclave_run *run) +{ + run->user_data = 0; + return 0; +} + int main(int argc, char *argv[], char *envp[]) { struct sgx_enclave_run run; @@ -203,6 +214,14 @@ int main(int argc, char *argv[], char *envp[]) if (check_result(&run, ret, result, "eenter")) goto err; + /* And with an exit handler. */ + run.user_handler = exit_handler; + run.user_data = 0xdeadbeef; + ret = eenter((unsigned long)&MAGIC, (unsigned long)&result, 0, EENTER, + 0, 0, &run); + if (check_result(&run, ret, result, "exit_handler")) + goto err; + printf("SUCCESS\n"); encl_delete(&encl); exit(0);