Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3487988pxb; Mon, 4 Apr 2022 18:35:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzk9YH2gMW5nC3FPTIuCFr0zUXSSi6J7OymGKJtEfb6MALhYW6eEtn3cPmmtUiUFjScbd3c X-Received: by 2002:a17:902:7798:b0:156:75c3:8e27 with SMTP id o24-20020a170902779800b0015675c38e27mr894534pll.91.1649122514780; Mon, 04 Apr 2022 18:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649122514; cv=none; d=google.com; s=arc-20160816; b=IqH9FeKl/NyUHyvY8VCi8fF9UM1vdgq0h2AumGjT8NMgA9XZf+XziAyk2COo5bcL9V /lIMPu8LX9Z7TMzxKabE3X8FvZGOHlBt0ap9dz/VlaUxDt3EdJxqmPoz9mA66ZZ22LSB rSzBaEx2LO0swZUy66jJXH5bVjM4DdmP9jhu6GACtI9ma0O4ZSsrDlSMk82HJ4KwzYFF Yo/hIKGwFrC9XJSn9+UMeBMMP+bVs4mNdHnjPVVwt16Kjli0tl8HvtfGcDDZSEi8vE1s 3R1VLAkEMLIq8ZGq1GwGT+bnMaeDLkWVr7liQtsOFfYR+i010Irdb4sHfE18gea2rtPV lpPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=truNZLUxDse9lDqJgd43mfvf810el7rkiYCivC95tU8=; b=nbSo+qs0OVay7IcjwJGJFUza/l3MJClmOhHYm8t68TkN+PP8szj5SJIDaVMZVOVBaC MErxrHI25MnnU3T+2wQp4UchNFZDMooPr9aYNg9pITx6B68RtvXw+I7lOQrfw+GllHKy nB+kdWVFseO1HKvI+fUrFSFnPt9tS+ILsOKFuruX5Ocb3qLGR6ZQkSSzwWx/DeRvF1d8 +J7YcVIqRwXzYTFv4h1JUi1Y+rAHzmpkrjhCstAjylSs/dMaEdLjFfdtSGCkdzcakznq 4LBMlUQdXOClEYq8KFQSS+YSQNwrpT/IC0D2LrXu5+ZS9ZAAsvcmTRojNFpqU/EgJ6FY ihjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Z3JA9w9B; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x18-20020a17090aca1200b001c68967d8f1si766770pjt.80.2022.04.04.18.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 18:35:14 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Z3JA9w9B; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B1C381D762E; Mon, 4 Apr 2022 17:25:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381405AbiDDVW7 (ORCPT + 99 others); Mon, 4 Apr 2022 17:22:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379255AbiDDQvt (ORCPT ); Mon, 4 Apr 2022 12:51:49 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C12B42DA8C; Mon, 4 Apr 2022 09:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649090992; x=1680626992; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XLHCtZ5lHLI6jvD7PuO5VfpRsas5f0b5jUQBwpQFz2s=; b=Z3JA9w9B+mH9/4XXyUPe+54QeuhNbT0DzlqDvF9pBaoLhpdyDevNh1ZW q4mJPIqyD6FI1boHjsTKET01+ezUKGPLDSAIPNt8VHnkfezL2EV+PlpdZ e2HVcNbqvPfOTm7BjE0dWFehYERc1+Y+7qZss4fmjq45AVLvxQrr1tlaG R2jkj6BRlC2wuV6O5Cv97czLX+s5ANfgDrSNgHxnNZaXZoXYIZnDTLByv ehtXGzFUvYFkUAX9VBbCs2oB3o+DACZkGL6cJNMieCsNIfRmmIUKqAvLF lJxwy+QbzOKeS0AMpQlnUdGHUPgP7Ffo+vTBEgNPenxIDLlYFUofAc9TF Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10307"; a="259390767" X-IronPort-AV: E=Sophos;i="5.90,234,1643702400"; d="scan'208";a="259390767" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2022 09:49:50 -0700 X-IronPort-AV: E=Sophos;i="5.90,234,1643702400"; d="scan'208";a="523105153" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2022 09:49:50 -0700 From: Reinette Chatre To: dave.hansen@linux.intel.com, jarkko@kernel.org, tglx@linutronix.de, bp@alien8.de, luto@kernel.org, mingo@redhat.com, linux-sgx@vger.kernel.org, x86@kernel.org Cc: seanjc@google.com, kai.huang@intel.com, cathy.zhang@intel.com, cedric.xing@intel.com, haitao.huang@intel.com, mark.shanahan@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org Subject: [PATCH V3 02/30] x86/sgx: Add wrapper for SGX2 EMODPR function Date: Mon, 4 Apr 2022 09:49:10 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a wrapper for the EMODPR ENCLS leaf function used to restrict enclave page permissions as maintained in the SGX hardware's Enclave Page Cache Map (EPCM). EMODPR: 1) Updates the EPCM permissions of an enclave page by treating the new permissions as a mask. Supplying a value that attempts to relax EPCM permissions has no effect on EPCM permissions (PR bit, see below, is changed). 2) Sets the PR bit in the EPCM entry of the enclave page to indicate that permission restriction is in progress. The bit is reset by the enclave by invoking ENCLU leaf function EACCEPT or EACCEPTCOPY. The enclave may access the page throughout the entire process if conforming to the EPCM permissions for the enclave page. After performing the permission restriction by issuing EMODPR the kernel needs to collaborate with the hardware to ensure that all logical processors sees the new restricted permissions. This is required for the enclave's EACCEPT/EACCEPTCOPY to succeed and is accomplished with the ETRACK flow. Expand enum sgx_return_code with the possible EMODPR return values. Signed-off-by: Reinette Chatre --- Changes since V2: - Add detail to changelog that PR bit is set when EPCM permissions not changed when relaxing of permissions using EMODPR attempted. Changes since V1: - Split original patch ("x86/sgx: Add wrappers for SGX2 functions") in three to introduce the SGX2 functions separately (Jarkko). - Rewrite commit message to include how the EPCM within the hardware is changed by the SGX2 function as well as the calling conditions (Jarkko). - Make short description more specific to which permissions (EPCM permissions) the function modifies. arch/x86/include/asm/sgx.h | 5 +++++ arch/x86/kernel/cpu/sgx/encls.h | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h index 3f9334ef67cd..d67810b50a81 100644 --- a/arch/x86/include/asm/sgx.h +++ b/arch/x86/include/asm/sgx.h @@ -65,17 +65,22 @@ enum sgx_encls_function { /** * enum sgx_return_code - The return code type for ENCLS, ENCLU and ENCLV + * %SGX_EPC_PAGE_CONFLICT: Page is being written by other ENCLS function. * %SGX_NOT_TRACKED: Previous ETRACK's shootdown sequence has not * been completed yet. * %SGX_CHILD_PRESENT SECS has child pages present in the EPC. * %SGX_INVALID_EINITTOKEN: EINITTOKEN is invalid and enclave signer's * public key does not match IA32_SGXLEPUBKEYHASH. + * %SGX_PAGE_NOT_MODIFIABLE: The EPC page cannot be modified because it + * is in the PENDING or MODIFIED state. * %SGX_UNMASKED_EVENT: An unmasked event, e.g. INTR, was received */ enum sgx_return_code { + SGX_EPC_PAGE_CONFLICT = 7, SGX_NOT_TRACKED = 11, SGX_CHILD_PRESENT = 13, SGX_INVALID_EINITTOKEN = 16, + SGX_PAGE_NOT_MODIFIABLE = 20, SGX_UNMASKED_EVENT = 128, }; diff --git a/arch/x86/kernel/cpu/sgx/encls.h b/arch/x86/kernel/cpu/sgx/encls.h index 0e22fa8f77c5..2b091912f038 100644 --- a/arch/x86/kernel/cpu/sgx/encls.h +++ b/arch/x86/kernel/cpu/sgx/encls.h @@ -215,4 +215,10 @@ static inline int __ewb(struct sgx_pageinfo *pginfo, void *addr, return __encls_ret_3(EWB, pginfo, addr, va); } +/* Restrict the EPCM permissions of an EPC page. */ +static inline int __emodpr(struct sgx_secinfo *secinfo, void *addr) +{ + return __encls_ret_2(EMODPR, secinfo, addr); +} + #endif /* _X86_ENCLS_H */ -- 2.25.1