Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp426886pxb; Fri, 15 Apr 2022 02:57:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNdCSbarm88wRtM0TqDpcGPANzD7sjiUl1R7NboQrqaAj8Q6lXqXRUf7dka3qQGSVKMJMm X-Received: by 2002:a17:906:7742:b0:6e8:3f85:4da1 with SMTP id o2-20020a170906774200b006e83f854da1mr5482931ejn.495.1650016662699; Fri, 15 Apr 2022 02:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650016662; cv=none; d=google.com; s=arc-20160816; b=KB7ZILrnMNF4b74tUiraMsAWE4IBTwoKegqpONh/KSpgohCAEh/JsUW3IH/J3kfphg Z4HBGtp4uaHys5c6EAlVUK7DkyHCWz/KIsd9kVzte266bCVO6B4xJsA5AlmXGCvr64/3 IUB4tcShjMRT5M97g6nV/M0lJMujoDKueqkzvBcR6uoWq/9AF6veCRG+BjIOvV+ND6lw k71rkMVIqU6pSjsPhbiHXMFlhkUVTo2n5txoL/qDZ9ccQhZGvfgRCQwy5B0bD9XonTMn yqV6qqK3qXr/edbaC48ULE3v4UuT3UzriV8xiJWLMzwb2Wag9nvBXxiS06h/1NLa11b+ 9RLA== 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=NtdodYWY+mAIOlP55lzo5q8FkGrzVoJ3Gr4TFUrt9eI=; b=gJt3FYKitAvSjBXKIFrcETFFQ/pY8Iuz24QSORnOE4UZK9PaUIIkutGkKKGHOCZZhd 2d8Q3p88Niv8pwbpZYJ1Ku+kxZxyAlWaF8uyilC5ovg0ohyeZq5RDMRj4dBuk40VnP7H 2SCPlU6HDn1mChG91SG8UedbCPi7Uj9CnB48W8bxxQjrAeMpsCaSND41cFtOID+MDl2I Jcads01vYW/ctLhH6UjB45Hdk5gXPR+ArsSIg7L6BWCPKHnxunurDu2xwZlSCZ26OmDq PzBdenYX9KzCpOyOECNgmrlXEOOSCEa88HopjEc+KpDXkBJzgu3rbmOTRatnswTsJTTo HiDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="JWkYl6/L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v4-20020a170906858400b006df76385c0asi723596ejx.170.2022.04.15.02.57.17; Fri, 15 Apr 2022 02:57:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="JWkYl6/L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238953AbiDMVNh (ORCPT + 99 others); Wed, 13 Apr 2022 17:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238992AbiDMVNE (ORCPT ); Wed, 13 Apr 2022 17:13:04 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A24044A33; Wed, 13 Apr 2022 14:10:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649884242; x=1681420242; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dcMxe8a94DLNE+YeP1u3c0mh9m/uBiTw5yv0/gCU0iA=; b=JWkYl6/LrHOaU6tcvQ9XgwqoiYIbfpxPSzvq53f4GQl1+fSwDVsmHT1y aHA2iYkWZbHWQNipK2xEXcUY6tpWQWb1th59nP6uv5P2YNA5ywrPkryu4 gwf+xFbKGHJExBo1BD1uaqXxxtRTPiag9MZc/wFX/R9oijvf04Cn07qgz 7yegXgVOiLqqzk2+yWHS8Bu4ANnr1xGTEa8Z/uJNHlyY+xHMlrBpedokC 1XhH5WvE21V/cUetwqqm37HS5A//dG+rCWFzClSFyesFPnTvA5dVcakPT 8N5D9uagzawxlrQGH9t6i4vT2Kxf98yuIn/6Vx0NG1h00fd+q63sDK9Cm w==; X-IronPort-AV: E=McAfee;i="6400,9594,10316"; a="323218996" X-IronPort-AV: E=Sophos;i="5.90,257,1643702400"; d="scan'208";a="323218996" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 14:10:40 -0700 X-IronPort-AV: E=Sophos;i="5.90,257,1643702400"; d="scan'208";a="725054240" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 14:10:40 -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, shuah@kernel.org, linux-kselftest@vger.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, vijay.dhanraj@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org Subject: [PATCH V4 02/31] x86/sgx: Add wrapper for SGX2 EMODPR function Date: Wed, 13 Apr 2022 14:10:02 -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.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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. Reviewed-by: Jarkko Sakkinen Signed-off-by: Reinette Chatre --- Changes since V3: - Add Jarkko's Reviewed-by tag. 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