From patchwork Fri Dec 2 18:36:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristen Carlson Accardi X-Patchwork-Id: 29077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1017217wrr; Fri, 2 Dec 2022 10:46:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf4GqVZENDCTvBNpvIOd/cARwXbPg/0szcEGeWevAov4rehoejkks1JI54fJj7T4wGMU5I4v X-Received: by 2002:aa7:c986:0:b0:46b:b010:3f43 with SMTP id c6-20020aa7c986000000b0046bb0103f43mr12333284edt.215.1670006796420; Fri, 02 Dec 2022 10:46:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670006796; cv=none; d=google.com; s=arc-20160816; b=HbVlNvY1xalfwVViju6l43dmTDsPhVPYYMb+0TmDzqDf46D0cbaL4kK+FtNKy7rjUl fUXyPrBUnC2jq1MhIwKGuRae1g0ey9PHmI7mzRsCtn2RCIAkNKPWJziKyANxK/+mRwaV vfSYiKvEJg/sNASux52ZvcpC4+NnNpwfN+NfLwSM0bnpPpgkldP1nGjMhBPBc7n7wMv/ IgUc0x4Obq+M9n4zw8SjzpE1WU0sv7+KrBErFNe40N8ZhEfn9UjaNQKyoOHhNqvY3MzE UkUmxBNBVn4cOs33PLIXX8iKyAW+4Q2KU8CneQp8qBJT39YzidAAM0UvArPKbIz65twa 3KfQ== 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=uj9mBIf8hxc0GqaFA7/edc3NdxazH/JnOj3sPeMuYoU=; b=Gkwh2hw4mEX13KMvpUBJq4iW1hMAiubMWNwsD3yRWGP/88PqbCjPTelQSzXvxMzmp4 Wn4w/z1TziAnIVnJ6zvVi4nhsAdWUZbFLFPZ/c9OMYmsDHYX54sG+7LcOvRS2eovI+49 QWQK6ymkdR7gXrxpFb0b54mYE+gKby+y1cigaDEtxuKIyO41Pj4m3z90IJJ2BEHzU1ar mGawh254Ugkqe7F83XKry2evCzisoXX8oC9qWugCZBiVbRilkeYR3qCeMuM7PW1awJ3H xQBYhMj7a0hSAUe0K811fhPcJZaT7D/E9Nw0dRE6zMIDxeP4Csrgis5OMTzbDhcYmEF1 wsZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XJHMzZBb; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn2-20020a1709070d0200b007ae2dfe020bsi7421811ejc.783.2022.12.02.10.46.12; Fri, 02 Dec 2022 10:46:36 -0800 (PST) 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=XJHMzZBb; 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 S234576AbiLBSje (ORCPT + 99 others); Fri, 2 Dec 2022 13:39:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234571AbiLBSiz (ORCPT ); Fri, 2 Dec 2022 13:38:55 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 244A81B7BD; Fri, 2 Dec 2022 10:37:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670006270; x=1701542270; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rCrTrxnacTNys7o3ZdRVf0ByGL11XnpENVPAAjiGcmg=; b=XJHMzZBbYbSEjBNhuqCxyjaASKLb1LTnWrYJ7Pp5szrBE+009Gquzvkh 46pLGwsIQe0tv2xAVu+zPP9R5gffCN45eS5yjmnY9sa8pn8uk2xmhuEd0 sLA+swaeuh6NbsHHafqzgB/RNTFTLPLVBY/Qs0eePbiifNU83ppz6TvkK 7yUVuRQTqu1Ur4tpUShj2QGArMtuWdNsGj9JPFq4Rax0S3WQRv+h5JaDk tCDoZyqiaaKr8dSUKC2epqvBzh4uaKsMcSGrIs4tO4XrTp2mKvb4+YWYz j9ntrNM7yUn+e8e/sE8W7CTHqAYnmE2Tb9LWiKqDZkqXd6kX5N2itpSTY g==; X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="314724704" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="314724704" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 10:37:41 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="713717597" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="713717597" Received: from kcaskeyx-mobl1.amr.corp.intel.com (HELO kcaccard-desk.amr.corp.intel.com) ([10.251.1.207]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 10:37:38 -0800 From: Kristen Carlson Accardi To: jarkko@kernel.org, dave.hansen@linux.intel.com, tj@kernel.org, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, cgroups@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Jonathan Corbet Cc: zhiquan1.li@intel.com, Kristen Carlson Accardi , Sean Christopherson , Bagas Sanjaya , linux-doc@vger.kernel.org Subject: [PATCH v2 18/18] Docs/x86/sgx: Add description for cgroup support Date: Fri, 2 Dec 2022 10:36:54 -0800 Message-Id: <20221202183655.3767674-19-kristen@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221202183655.3767674-1-kristen@linux.intel.com> References: <20221202183655.3767674-1-kristen@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751129046827811408?= X-GMAIL-MSGID: =?utf-8?q?1751129046827811408?= Add initial documentation of how to regulate the distribution of SGX Enclave Page Cache (EPC) memory via the Miscellaneous cgroup controller. Signed-off-by: Sean Christopherson Signed-off-by: Kristen Carlson Accardi Cc: Sean Christopherson Reviewed-by: Bagas Sanjaya --- Documentation/x86/sgx.rst | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/Documentation/x86/sgx.rst b/Documentation/x86/sgx.rst index 2bcbffacbed5..f6ca5594dcf2 100644 --- a/Documentation/x86/sgx.rst +++ b/Documentation/x86/sgx.rst @@ -300,3 +300,80 @@ to expected failures and handle them as follows: first call. It indicates a bug in the kernel or the userspace client if any of the second round of ``SGX_IOC_VEPC_REMOVE_ALL`` calls has a return code other than 0. + + +Cgroup Support +============== + +The "sgx_epc" resource within the Miscellaneous cgroup controller regulates +distribution of SGX EPC memory, which is a subset of system RAM that +is used to provide SGX-enabled applications with protected memory, +and is otherwise inaccessible, i.e. shows up as reserved in +/proc/iomem and cannot be read/written outside of an SGX enclave. + +Although current systems implement EPC by stealing memory from RAM, +for all intents and purposes the EPC is independent from normal system +memory, e.g. must be reserved at boot from RAM and cannot be converted +between EPC and normal memory while the system is running. The EPC is +managed by the SGX subsystem and is not accounted by the memory +controller. Note that this is true only for EPC memory itself, i.e. +normal memory allocations related to SGX and EPC memory, e.g. the +backing memory for evicted EPC pages, are accounted, limited and +protected by the memory controller. + +Much like normal system memory, EPC memory can be overcommitted via +virtual memory techniques and pages can be swapped out of the EPC +to their backing store (normal system memory allocated via shmem). +The SGX EPC subsystem is analogous to the memory subsytem, and +it implements limit and protection models for EPC memory. + +SGX EPC Interface Files +----------------------- + +For a generic description of the Miscellaneous controller interface +files, please see Documentation/admin-guide/cgroup-v2.rst + +All SGX EPC memory amounts are in bytes unless explicitly stated +otherwise. If a value which is not PAGE_SIZE aligned is written, +the actual value used by the controller will be rounded down to +the closest PAGE_SIZE multiple. + + misc.capacity + A read-only flat-keyed file shown only in the root cgroup. + The sgx_epc resource will show the total amount of EPC + memory available on the platform. + + misc.current + A read-only flat-keyed file shown in the non-root cgroups. + The sgx_epc resource will show the current active EPC memory + usage of the cgroup and its descendants. EPC pages that are + swapped out to backing RAM are not included in the current count. + + misc.max + A read-write single value file which exists on non-root + cgroups. The sgx_epc resource will show the EPC usage + hard limit. The default is "max". + + If a cgroup's EPC usage reaches this limit, EPC allocations, + e.g. for page fault handling, will be blocked until EPC can + be reclaimed from the cgroup. If EPC cannot be reclaimed in + a timely manner, reclaim will be forced, e.g. by ignoring LRU. + + misc.events + A read-write flat-keyed file which exists on non-root cgroups. + Writes to the file reset the event counters to zero. A value + change in this file generates a file modified event. + + max + The number of times the cgroup has triggered a reclaim + due to its EPC usage approaching (or exceeding) its max + EPC boundary. + +Migration +--------- + +Once an EPC page is charged to a cgroup (during allocation), it +remains charged to the original cgroup until the page is released +or reclaimed. Migrating a process to a different cgroup doesn't +move the EPC charges that it incurred while in the previous cgroup +to its new cgroup.