Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1445416ybi; Wed, 17 Jul 2019 15:37:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEU7D9pZdNhUM6JbaF/3gw43SS+Y+daSvmCkM/BjMllxtsTG2gEI3dhrBtXyO+5Y9cR969 X-Received: by 2002:a17:90a:d80b:: with SMTP id a11mr44738827pjv.53.1563403064699; Wed, 17 Jul 2019 15:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563403064; cv=none; d=google.com; s=arc-20160816; b=zZRbdL4ZWzLrQVRV5bek85veB6HhV+/lkwD4W/Hm+1yOh/XuJZUGOjvTt5CeiDfT3i gnkQzGNxosvgtR+GIkOumSdwdWPkTaRHJB/WGnsKwaL8HqdpUMPZmoVLjLwOSV4fgMuX AQklq1zEaQ7agqNhq+fcK9ch3FhcF9ex6JXopxWb13sz/LSr7aZ5pH6F6zEPBLqsQNdO BFMf70K1W4Cs7oeuhpzoo8sAF+ZZMa68EfJMbbCEBLM1O3gY9Zmzsv+hK4nBYogMW0X+ khuD8ADtfa6fdil7iqmMHCZGrJO8FwSRf/7X2zjPanfze5P9DIF+y4BcSShF28Twl5wO kjWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=H7JblSBm6OjhONZUiLC4LwhBoOIRTxhSNk4edy8Maug=; b=bPhphxnM4p/zQjxtY0YhXa8cHtsakeDFnVed/8C4I2GJeOX+gysNmXhrKZ+yPYh/VZ hFcJUgXGmxe9nATjyQ/yn08+W2iwqr07DMZxceoNh5lj4aLSGoeCJVJgl5JQwb7RHo4E XO2/xFMkxXbVnhx/0S+DEl93KVuHrxLY1sFRQNLr9jjfgd4zKRSQFySDYl3hTBdgB37N nZfU5+WaQrlrWTgL3S0We6OduWT58FNJbBtJSAXtJEKPgetYdbaiwTWT4GgjNicRvDqq l5n7T4B7OweLRm3Z0/TPXAatF5kHNd+ABx71Rx/OQjLfB6/At27IKwzpNE7ZgcOz3I9/ SFBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si292625pln.228.2019.07.17.15.37.24; Wed, 17 Jul 2019 15:37:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728071AbfGQWhE (ORCPT + 99 others); Wed, 17 Jul 2019 18:37:04 -0400 Received: from mga03.intel.com ([134.134.136.65]:4184 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727606AbfGQWhE (ORCPT ); Wed, 17 Jul 2019 18:37:04 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2019 15:37:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,275,1559545200"; d="scan'208";a="366717388" Received: from bxing-desk.ccr.corp.intel.com (HELO [134.134.148.187]) ([134.134.148.187]) by fmsmga005.fm.intel.com with ESMTP; 17 Jul 2019 15:37:02 -0700 Subject: Re: [PATCH v21 24/28] selftests/x86: Add a selftest for SGX To: Jarkko Sakkinen , linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org Cc: akpm@linux-foundation.org, dave.hansen@intel.com, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com, shay.katz-zamir@intel.com, haitao.huang@intel.com, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kai.svahn@intel.com, bp@alien8.de, josh@joshtriplett.org, luto@kernel.org, kai.huang@intel.com, rientjes@google.com References: <20190713170804.2340-1-jarkko.sakkinen@linux.intel.com> <20190713170804.2340-25-jarkko.sakkinen@linux.intel.com> From: "Xing, Cedric" Message-ID: Date: Wed, 17 Jul 2019 15:37:03 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190713170804.2340-25-jarkko.sakkinen@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/13/2019 10:08 AM, 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 given to > the enclave as arguments. > > Signed-off-by: Jarkko Sakkinen > --- > tools/testing/selftests/x86/Makefile | 10 + > tools/testing/selftests/x86/sgx/Makefile | 48 ++ > tools/testing/selftests/x86/sgx/defines.h | 39 ++ > tools/testing/selftests/x86/sgx/encl.c | 20 + > tools/testing/selftests/x86/sgx/encl.lds | 33 ++ > .../selftests/x86/sgx/encl_bootstrap.S | 94 ++++ > tools/testing/selftests/x86/sgx/encl_piggy.S | 18 + > tools/testing/selftests/x86/sgx/encl_piggy.h | 14 + > tools/testing/selftests/x86/sgx/main.c | 301 +++++++++++ > tools/testing/selftests/x86/sgx/sgx_call.S | 49 ++ > tools/testing/selftests/x86/sgx/sgxsign.c | 508 ++++++++++++++++++ > .../testing/selftests/x86/sgx/signing_key.pem | 39 ++ > 12 files changed, 1173 insertions(+) > create mode 100644 tools/testing/selftests/x86/sgx/Makefile > create mode 100644 tools/testing/selftests/x86/sgx/defines.h > create mode 100644 tools/testing/selftests/x86/sgx/encl.c > create mode 100644 tools/testing/selftests/x86/sgx/encl.lds > create mode 100644 tools/testing/selftests/x86/sgx/encl_bootstrap.S > create mode 100644 tools/testing/selftests/x86/sgx/encl_piggy.S > create mode 100644 tools/testing/selftests/x86/sgx/encl_piggy.h > create mode 100644 tools/testing/selftests/x86/sgx/main.c > create mode 100644 tools/testing/selftests/x86/sgx/sgx_call.S > create mode 100644 tools/testing/selftests/x86/sgx/sgxsign.c > create mode 100644 tools/testing/selftests/x86/sgx/signing_key.pem > > diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests/x86/Makefile > index fa07d526fe39..a1831406fd01 100644 > --- a/tools/testing/selftests/x86/Makefile > +++ b/tools/testing/selftests/x86/Makefile > @@ -1,4 +1,7 @@ > # SPDX-License-Identifier: GPL-2.0 > + > +SUBDIRS_64 := sgx > + > all: > > include ../lib.mk > @@ -68,6 +71,13 @@ all_32: $(BINARIES_32) > > all_64: $(BINARIES_64) > > +all_64: $(SUBDIRS_64) $(SUBDIRS_64) aren't targets. No need for all_64 to depend on them. > + @for DIR in $(SUBDIRS_64); do \ > + BUILD_TARGET=$(OUTPUT)/$$DIR; \ > + mkdir $$BUILD_TARGET -p; \ > + make OUTPUT=$$BUILD_TARGET -C $$DIR $@; \ Please use $(MAKE), otherwise command line options cannot be passed onto sub-makes. > + done The above only builds but will not run SGX tests. Also, 'clean' target will not descend into sgx folder either. > + > EXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64) > > $(BINARIES_32): $(OUTPUT)/%_32: %.c > diff --git a/tools/testing/selftests/x86/sgx/Makefile b/tools/testing/selftests/x86/sgx/Makefile > new file mode 100644 > index 000000000000..10136b73096b > --- /dev/null > +++ b/tools/testing/selftests/x86/sgx/Makefile > @@ -0,0 +1,48 @@ > +top_srcdir = ../../../../.. > + > +include ../../lib.mk > + > +HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC -z noexecstack > +ENCL_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fPIC \ > + -fno-stack-protector -mrdrnd $(INCLUDES) > + > +TEST_CUSTOM_PROGS := $(OUTPUT)/test_sgx > +all_64: $(TEST_CUSTOM_PROGS) > + > +$(TEST_CUSTOM_PROGS): $(OUTPUT)/main.o $(OUTPUT)/sgx_call.o \ > + $(OUTPUT)/encl_piggy.o > + $(CC) $(HOST_CFLAGS) -o $@ $^ > + > +$(OUTPUT)/main.o: main.c > + $(CC) $(HOST_CFLAGS) -c $< -o $@ .o files don't have to be generated/kept. And to be consistent with other selftests, please don't generate/keep them. > + > +$(OUTPUT)/sgx_call.o: sgx_call.S > + $(CC) $(HOST_CFLAGS) -c $< -o $@ > + > +$(OUTPUT)/encl_piggy.o: $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss > + $(CC) $(HOST_CFLAGS) -c encl_piggy.S -o $@ Without -I, the above command breaks when "O=" is specified. > + > +$(OUTPUT)/encl.bin: $(OUTPUT)/encl.elf $(OUTPUT)/sgxsign > + objcopy --remove-section=.got.plt -O binary $< $@ .got.plt section will never be present for statically linked binaries. > + > +$(OUTPUT)/encl.elf: $(OUTPUT)/encl.o $(OUTPUT)/encl_bootstrap.o > + $(CC) $(ENCL_CFLAGS) -T encl.lds -o $@ $^ Please fix the warning of ".note.gnu.build-id section discarded". > + > +$(OUTPUT)/encl.o: encl.c > + $(CC) $(ENCL_CFLAGS) -c $< -o $@ > + > +$(OUTPUT)/encl_bootstrap.o: encl_bootstrap.S > + $(CC) $(ENCL_CFLAGS) -c $< -o $@ > + > +$(OUTPUT)/encl.ss: $(OUTPUT)/encl.bin $(OUTPUT)/sgxsign > + $(OUTPUT)/sgxsign signing_key.pem $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss > + > +$(OUTPUT)/sgxsign: sgxsign.c > + $(CC) -o $@ $< -lcrypto > + > +EXTRA_CLEAN := $(OUTPUT)/sgx-selftest $(OUTPUT)/sgx-selftest.o \ > + $(OUTPUT)/sgx_call.o $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss \ > + $(OUTPUT)/encl.elf $(OUTPUT)/encl.o $(OUTPUT)/encl_bootstrap.o \ > + $(OUTPUT)/sgxsign > + encl_piggy.o, main.o and test_sgx are not cleaned. > +.PHONY: clean