From nobody Sun Apr 19 02:15:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28E96C43334 for ; Thu, 7 Jul 2022 18:27:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236048AbiGGS1z (ORCPT ); Thu, 7 Jul 2022 14:27:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236356AbiGGS1h (ORCPT ); Thu, 7 Jul 2022 14:27:37 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ECBE5A2DF; Thu, 7 Jul 2022 11:27:36 -0700 (PDT) Date: Thu, 07 Jul 2022 18:27:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1657218454; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SqAo/PVKyAt6loE1MQhW84rDqNPsr9M3MwOg5xRSsX0=; b=SA0bMWCBd97hgB4Dhf53H7vGwABUVxhhIlpw/9XhxA/BFEQsf8yP1XsOpGFQbjylNraPWT 3qhUD476Ps2tMVea5MG8O+mk1p4QTjIU1tqOeZjalwW8T0S9cyvH3FL7n2qkw09Fo0jbYO 9FDB095V2i2wysCVITiOJTnCC/Xae/N+NTtck5KpjU1lX8VZh/+Mln+9MszVlMqi4dFFNl ZGTturPe69brMX2RlYc2nm0TMmneqKKY0tXIdyX05O6U/z6WRidthb8urd0C54InjnkboZ oaKdBu8ZmwJALWL0ZUOHH0dfu16A96YWSp7lYVlQLwZPh00AahjDbkhdMe1+ig== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1657218454; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SqAo/PVKyAt6loE1MQhW84rDqNPsr9M3MwOg5xRSsX0=; b=zh9Gn8CdxAoBtCN2+KoaNl52HGWfMc16Yu41e/7rLzcWzwD1GgeOJimTODw+gCe9zOYQ1R rWvnQvVzIXbQlmDQ== From: "tip-bot2 for Reinette Chatre" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sgx] selftests/sgx: Introduce TCS initialization enclave operation Cc: Reinette Chatre , Dave Hansen , Jarkko Sakkinen , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3Cbad6052056188bde753a54313da1ac8f1e29088a=2E16521?= =?utf-8?q?37848=2Egit=2Ereinette=2Echatre=40intel=2Ecom=3E?= References: =?utf-8?q?=3Cbad6052056188bde753a54313da1ac8f1e29088a=2E165213?= =?utf-8?q?7848=2Egit=2Ereinette=2Echatre=40intel=2Ecom=3E?= MIME-Version: 1.0 Message-ID: <165721845384.15455.15798019288134106051.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/sgx branch of tip: Commit-ID: b564982fda13be6314e49f2344e7c422565e34d3 Gitweb: https://git.kernel.org/tip/b564982fda13be6314e49f2344e7c4225= 65e34d3 Author: Reinette Chatre AuthorDate: Tue, 10 May 2022 11:09:02 -07:00 Committer: Dave Hansen CommitterDate: Thu, 07 Jul 2022 10:13:04 -07:00 selftests/sgx: Introduce TCS initialization enclave operation The Thread Control Structure (TCS) contains meta-data used by the hardware to save and restore thread specific information when entering/exiting the enclave. A TCS can be added to an initialized enclave by first adding a new regular enclave page, initializing the content of the new page from within the enclave, and then changing that page's type to a TCS. Support the initialization of a TCS from within the enclave. The variable information needed that should be provided from outside the enclave is the address of the TCS, address of the State Save Area (SSA), and the entry point that the thread should use to enter the enclave. With this information provided all needed fields of a TCS can be initialized. Signed-off-by: Reinette Chatre Signed-off-by: Dave Hansen Acked-by: Jarkko Sakkinen Link: https://lkml.kernel.org/r/bad6052056188bde753a54313da1ac8f1e29088a.16= 52137848.git.reinette.chatre@intel.com --- tools/testing/selftests/sgx/defines.h | 8 ++++++- tools/testing/selftests/sgx/test_encl.c | 30 ++++++++++++++++++++++++- 2 files changed, 38 insertions(+) diff --git a/tools/testing/selftests/sgx/defines.h b/tools/testing/selftest= s/sgx/defines.h index b638eb9..d8587c9 100644 --- a/tools/testing/selftests/sgx/defines.h +++ b/tools/testing/selftests/sgx/defines.h @@ -26,6 +26,7 @@ enum encl_op_type { ENCL_OP_NOP, ENCL_OP_EACCEPT, ENCL_OP_EMODPE, + ENCL_OP_INIT_TCS_PAGE, ENCL_OP_MAX, }; =20 @@ -68,4 +69,11 @@ struct encl_op_emodpe { uint64_t flags; }; =20 +struct encl_op_init_tcs_page { + struct encl_op_header header; + uint64_t tcs_page; + uint64_t ssa; + uint64_t entry; +}; + #endif /* DEFINES_H */ diff --git a/tools/testing/selftests/sgx/test_encl.c b/tools/testing/selfte= sts/sgx/test_encl.c index 5b6c653..c0d6397 100644 --- a/tools/testing/selftests/sgx/test_encl.c +++ b/tools/testing/selftests/sgx/test_encl.c @@ -57,6 +57,35 @@ static void *memcpy(void *dest, const void *src, size_t = n) return dest; } =20 +static void *memset(void *dest, int c, size_t n) +{ + size_t i; + + for (i =3D 0; i < n; i++) + ((char *)dest)[i] =3D c; + + return dest; +} + +static void do_encl_init_tcs_page(void *_op) +{ + struct encl_op_init_tcs_page *op =3D _op; + void *tcs =3D (void *)op->tcs_page; + uint32_t val_32; + + memset(tcs, 0, 16); /* STATE and FLAGS */ + memcpy(tcs + 16, &op->ssa, 8); /* OSSA */ + memset(tcs + 24, 0, 4); /* CSSA */ + val_32 =3D 1; + memcpy(tcs + 28, &val_32, 4); /* NSSA */ + memcpy(tcs + 32, &op->entry, 8); /* OENTRY */ + memset(tcs + 40, 0, 24); /* AEP, OFSBASE, OGSBASE */ + val_32 =3D 0xFFFFFFFF; + memcpy(tcs + 64, &val_32, 4); /* FSLIMIT */ + memcpy(tcs + 68, &val_32, 4); /* GSLIMIT */ + memset(tcs + 72, 0, 4024); /* Reserved */ +} + static void do_encl_op_put_to_buf(void *op) { struct encl_op_put_to_buf *op2 =3D op; @@ -100,6 +129,7 @@ void encl_body(void *rdi, void *rsi) do_encl_op_nop, do_encl_eaccept, do_encl_emodpe, + do_encl_init_tcs_page, }; =20 struct encl_op_header *op =3D (struct encl_op_header *)rdi;