From nobody Sun Apr 19 02:15:20 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 35FBBC433EF for ; Thu, 7 Jul 2022 18:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236477AbiGGS3F (ORCPT ); Thu, 7 Jul 2022 14:29:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236476AbiGGS2X (ORCPT ); Thu, 7 Jul 2022 14:28:23 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B46CE5C9D3; Thu, 7 Jul 2022 11:27:50 -0700 (PDT) Date: Thu, 07 Jul 2022 18:27:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1657218468; 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=cqVEe0Z1u/muFIhp/PjrXkoxFWR1Owh/IU0xZba3CwU=; b=0PkXakY6nbIl/lEeMmGbMqHKDXhfDmOzsbnrwWxst+pe5x0WBA1xeWhj2M6paGXQNcenys y8lGlAp+0jmmqTG0qkSikM87k7162JtDclHXqkSPhoFg4gB77+8Fsx9J4yl2ABjJvN8kL6 O3O/0QBbcXr+sSGbd/T0JV0VpjJnyht8WmraHOnhh8R/Q+CBcOMqlCJMELBKST6bIwkLg3 +L8OI4rGyFL2ufP5yQTIHf1rIaOCzNIeN3ohH1uOhYO5StnLc5GFxfEh+hyF9OjL+G4vA6 knDniRF0e+nvFVncthItlIoeK5y3EOhMmOwuAk2C0l2qU1rdB7IVzdDu17e92A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1657218468; 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=cqVEe0Z1u/muFIhp/PjrXkoxFWR1Owh/IU0xZba3CwU=; b=PZAtk2hVvy/MbTLTmDnWPL4OheTI0hRY9KRyNNrbcR0RmjrzpSE1GmPF5Q0HxulLu8U76v juqJTFY03LsynABw== 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] x86/sgx: Keep record of SGX page type Cc: Reinette Chatre , Dave Hansen , Jarkko Sakkinen , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3Ca0a6939eefe7ba26514f6c49723521cde372de64=2E16521?= =?utf-8?q?37848=2Egit=2Ereinette=2Echatre=40intel=2Ecom=3E?= References: =?utf-8?q?=3Ca0a6939eefe7ba26514f6c49723521cde372de64=2E165213?= =?utf-8?q?7848=2Egit=2Ereinette=2Echatre=40intel=2Ecom=3E?= MIME-Version: 1.0 Message-ID: <165721846783.15455.1708814761709184700.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: 8cb7b502f31e6cc4c6ebe2c5eeaa90dcab418cf1 Gitweb: https://git.kernel.org/tip/8cb7b502f31e6cc4c6ebe2c5eeaa90dca= b418cf1 Author: Reinette Chatre AuthorDate: Tue, 10 May 2022 11:08:47 -07:00 Committer: Dave Hansen CommitterDate: Thu, 07 Jul 2022 10:13:02 -07:00 x86/sgx: Keep record of SGX page type SGX2 functions are not allowed on all page types. For example, ENCLS[EMODPR] is only allowed on regular SGX enclave pages and ENCLS[EMODPT] is only allowed on TCS and regular pages. If these functions are attempted on another type of page the hardware would trigger a fault. Keep a record of the SGX page type so that there is more certainty whether an SGX2 instruction can succeed and faults can be treated as real failures. The page type is a property of struct sgx_encl_page and thus does not cover the VA page type. VA pages are maintained in separate structures and their type can be determined in a different way. The SGX2 instructions needing the page type do not operate on VA pages and this is thus not a scenario needing to be covered at this time. struct sgx_encl_page hosting this information is maintained for each enclave page so the space consumed by the struct is important. The existing sgx_encl_page->vm_max_prot_bits is already unsigned long while only using three bits. Transition to a bitfield for the two members to support the additional information without increasing the space consumed by the struct. Signed-off-by: Reinette Chatre Signed-off-by: Dave Hansen Reviewed-by: Jarkko Sakkinen Link: https://lkml.kernel.org/r/a0a6939eefe7ba26514f6c49723521cde372de64.16= 52137848.git.reinette.chatre@intel.com --- arch/x86/include/asm/sgx.h | 3 +++ arch/x86/kernel/cpu/sgx/encl.h | 3 ++- arch/x86/kernel/cpu/sgx/ioctl.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h index d67810b..eae20fa 100644 --- a/arch/x86/include/asm/sgx.h +++ b/arch/x86/include/asm/sgx.h @@ -239,6 +239,9 @@ struct sgx_pageinfo { * %SGX_PAGE_TYPE_REG: a regular page * %SGX_PAGE_TYPE_VA: a VA page * %SGX_PAGE_TYPE_TRIM: a page in trimmed state + * + * Make sure when making changes to this enum that its values can still fit + * in the bitfield within &struct sgx_encl_page */ enum sgx_page_type { SGX_PAGE_TYPE_SECS, diff --git a/arch/x86/kernel/cpu/sgx/encl.h b/arch/x86/kernel/cpu/sgx/encl.h index f72a674..799d4cd 100644 --- a/arch/x86/kernel/cpu/sgx/encl.h +++ b/arch/x86/kernel/cpu/sgx/encl.h @@ -27,7 +27,8 @@ =20 struct sgx_encl_page { unsigned long desc; - unsigned long vm_max_prot_bits; + unsigned long vm_max_prot_bits:8; + enum sgx_page_type type:16; struct sgx_epc_page *epc_page; struct sgx_encl *encl; struct sgx_va_page *va_page; diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioct= l.c index a66795e..21078c6 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -107,6 +107,7 @@ static int sgx_encl_create(struct sgx_encl *encl, struc= t sgx_secs *secs) set_bit(SGX_ENCL_DEBUG, &encl->flags); =20 encl->secs.encl =3D encl; + encl->secs.type =3D SGX_PAGE_TYPE_SECS; encl->base =3D secs->base; encl->size =3D secs->size; encl->attributes =3D secs->attributes; @@ -344,6 +345,7 @@ static int sgx_encl_add_page(struct sgx_encl *encl, uns= igned long src, */ encl_page->encl =3D encl; encl_page->epc_page =3D epc_page; + encl_page->type =3D (secinfo->flags & SGX_SECINFO_PAGE_TYPE_MASK) >> 8; encl->secs_child_cnt++; =20 if (flags & SGX_PAGE_MEASURE) {