Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4118455pxb; Tue, 17 Nov 2020 11:45:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJw32QOqIck4EyULJ8e7tLCZAO4uTtp9ktrnwW/JdCad3fmAnfFJjMq0LPH4mDaoo9Zt3hCY X-Received: by 2002:aa7:d599:: with SMTP id r25mr21340522edq.280.1605642318218; Tue, 17 Nov 2020 11:45:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605642318; cv=none; d=google.com; s=arc-20160816; b=c5CLBlVuTpF/CHpMMeIkaCARNu6TmtbZBQ/aDQbLXqrB2ETYYd7anK0MqvTdgyfYeM 74y7OQU0l8LqS6otZSE4Xsz+SCr1VJl80udlnJUX0CN+1I1bRwa2H1S9YmGVzaorAvJj puRjN3nORSCPRWlo+RE3rRDbWDkPzB08IgY32FdE7ZCRUdYT0if1HjhVH7EwOx92tjNN 3JC5mt0TcpFKmYaAhuDbcFPwBVzE4nai4yxKGwDBx03fSNHiQOgekJc4cWVoX278HVIE 9AM3AhlMyWXDdmOY8bXZlz7eMOFiI6e/BbyJCHYtbMHltOwGs0Y3hhu8RwW7ZBV7o5lL Tweg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6YGsWeq+GOVR7aLeAsTOM2h4t8njLLWam6ZoDkCORAE=; b=qf7znpY5lyG2jjL9AjL4chvlw/LtFzdSPyBPGl0T1dxgtng1yrtF7lxV2oYIlLwPvr e9IatMP23MKmP33A4c/h72iruBzNnhgFHUKVrPnf1/YqKgGbJJBxEfwr/cQ4z/Q2Tsab Gk7l/pHyswsYreARvOhYkxqcHQjGK2WU+t6l+A2d5m50lcR6DsGP+Hl6J7iTSM36vk7m WN/zeLGmpePOW+JIqDphAwienXUAYP77yJm1rVPFsOuZcDbUvEdt+o35xbqA8knFh/aY za/5te1ynSmklihiNjH5i5vsLZEdOZso9ETusL0yRVdw00L0RmCHwUa6JOcldrJmIrPc HL2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vmvo0oLI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i7si1247162ejc.568.2020.11.17.11.44.55; Tue, 17 Nov 2020 11:45:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vmvo0oLI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730735AbgKQTm3 (ORCPT + 99 others); Tue, 17 Nov 2020 14:42:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:54646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728060AbgKQTm3 (ORCPT ); Tue, 17 Nov 2020 14:42:29 -0500 Received: from kernel.org (83-245-197-237.elisa-laajakaista.fi [83.245.197.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F2B622463D; Tue, 17 Nov 2020 19:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605642147; bh=WfH7BFVzUSEZv+f6jZxK9ydp1lynvYQ2oovxy7EJVXg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vmvo0oLI2+zUSZRhwq0NiGDjYhcKWJZyY+Ph8A1MJPfxjbJH0Zol91ECmkxg91DyH NXWk7uQXJtd/v1xuxdNQ/GI5Ed040w/C7hrjjZBRrgfQy+sNkrZpD48Pz8cg82N6po cl4QXLIN7mw/CndOK2P3ZytLUp2cBUGrSWYQ5kVI= Date: Tue, 17 Nov 2020 21:42:17 +0200 From: Jarkko Sakkinen To: Shuah Khan Cc: x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org, Jethro Beekman , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, bp@alien8.de, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, npmccallum@redhat.com, puiterwijk@redhat.com, rientjes@google.com, sean.j.christopherson@intel.com, tglx@linutronix.de, yaozhangx@google.com, mikko.ylinen@intel.com Subject: Re: [PATCH v41 20/24] selftests/x86: Add a selftest for SGX Message-ID: <20201117194217.GG10393@kernel.org> References: <20201112220135.165028-1-jarkko@kernel.org> <20201112220135.165028-21-jarkko@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 16, 2020 at 11:19:12AM -0700, Shuah Khan wrote: > 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 > > Cc: linux-kselftest@vger.kernel.org > > Acked-by: Jethro Beekman # v40 > > Signed-off-by: Jarkko Sakkinen > > --- > > 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 Thanks. /Jarkko