Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp799369pxb; Wed, 15 Sep 2021 13:33:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuuKAsfzQOnS9outgL774H8Y1N0GC8PV0ONilf1zwXU31U3nak7Nxno9NKANOk70YDgz6P X-Received: by 2002:a17:907:7f93:: with SMTP id qk19mr1964191ejc.433.1631737996319; Wed, 15 Sep 2021 13:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631737996; cv=none; d=google.com; s=arc-20160816; b=tk02LJ72xeQqRWYCgNXEFKZQy4mM501NLfIxhDlxS4iWiqpf0Cw3dS5qYg890IpJvp hVFvLPPNxdiJq0un+4eMNpPGXnEG7iSISHHIy6xPlrgnXkNMhnXu3qzufUkDCN8a6soE PCF6cNGd1Vc4YNUI0BqJHSqdx3Ay5QgB3Sz3owoDu+UOS9pEh2pj6TXelmdbHSaPyPjA kCBdRK3SeXMpQKjcpmoiDglWvQKS1F512u+YwVl78TSZL4DmgINwbBoh9UMg7e1OsOvT l6S269RrjP+AFK3FAfSfmkoE6JDjMGl2R00komyRtbJoFaY1pBZQ894tQzEsISk4z/ug ElCA== 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; bh=QrzWw91/7e55G8/V5G8CttLUueepdOzO7aeHxaU53Hg=; b=z8l5h0qIm1IsJkqEb+chSQRsRG22eKMLafOVPQKIRGFfMarEHwXO3L5V1vNd5UknoQ XRhb9kimhjpDa5H3xU/rjTL/1GwCB1DnpLnlCw1SuimQeHLHCWV1sRoiCIt+q0akS22+ 6lhWD2FEFiGd0plF9eUJdgtzew7Q2DRIdwON2O//m2H+cVI7sBXOnPz6NzRovZRmPBOh CqaTC1OI3snc2mZ9J2UwbHNmI7E+y0mXBSoAreg5Oh8h5aH/J8GrAUU6zXjJi+g9lvPW AsGWGG3ywsupVEr+kRAUCyXNZeUGGFW5Yy8kIEYgx8OssVEEzF9jPqOFjBgNxbHBLMa5 VLPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd8si1179360ejb.751.2021.09.15.13.32.52; Wed, 15 Sep 2021 13:33:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232208AbhIOUco (ORCPT + 99 others); Wed, 15 Sep 2021 16:32:44 -0400 Received: from mga07.intel.com ([134.134.136.100]:13811 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231592AbhIOUcd (ORCPT ); Wed, 15 Sep 2021 16:32:33 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10108"; a="286109360" X-IronPort-AV: E=Sophos;i="5.85,296,1624345200"; d="scan'208";a="286109360" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2021 13:31:13 -0700 X-IronPort-AV: E=Sophos;i="5.85,296,1624345200"; d="scan'208";a="545092774" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2021 13:31:13 -0700 From: Reinette Chatre To: linux-sgx@vger.kernel.org, jarkko@kernel.org, shuah@kernel.org Cc: seanjc@google.com, bp@alien8.de, dave.hansen@linux.intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/14] x86/sgx: Add /sys/kernel/debug/x86/sgx_total_mem Date: Wed, 15 Sep 2021 13:30:52 -0700 Message-Id: <086aa5a16faf0d9b47ba9e0ebd2213713d0e76ff.1631731214.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jarkko Sakkinen Just like normal memory, SGX memory can be overcommitted. SGX has its own reclaim mechanism which kicks in when physical SGX memory (Enclave Page Cache / EPC) is exhausted. That reclaim mechanism is relatively rarely exercised and needs selftests to poke at it. The amount of EPC on the system is determined by the BIOS and it varies wildly between systems. It can be dozens of MB on desktops, or many GB on servers. To run in a reasonable amount of time, the selftest needs to know how much EPC there is in the system. Introduce a new debugfs file to export that information. Acked-by: Dave Hansen Signed-off-by: Jarkko Sakkinen [reinette: Use as placeholder patch until other discussions complete] Signed-off-by: Reinette Chatre --- Documentation/x86/sgx.rst | 6 ++++++ arch/x86/kernel/cpu/sgx/main.c | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Documentation/x86/sgx.rst b/Documentation/x86/sgx.rst index dd0ac96ff9ef..f11bfb331b93 100644 --- a/Documentation/x86/sgx.rst +++ b/Documentation/x86/sgx.rst @@ -250,3 +250,9 @@ user wants to deploy SGX applications both on the host and in guests on the same machine, the user should reserve enough EPC (by taking out total virtual EPC size of all SGX VMs from the physical EPC size) for host SGX applications so they can run with acceptable performance. + +Debugging +========= + +*/sys/kernel/debug/x86/sgx_total_mem* contains an integer describing +the total SGX reserved memory in bytes, available in the system. diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 63d3de02bbcc..b65da19a53ee 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2016-20 Intel Corporation. */ +#include #include #include #include @@ -28,7 +29,10 @@ static DECLARE_WAIT_QUEUE_HEAD(ksgxd_waitq); static LIST_HEAD(sgx_active_page_list); static DEFINE_SPINLOCK(sgx_reclaimer_lock); -/* The free page list lock protected variables prepend the lock. */ +/* Total EPC memory available in bytes. */ +static unsigned long sgx_total_mem; + +/* The number of free EPC pages in all nodes. */ static unsigned long sgx_nr_free_pages; /* Nodes with one or more EPC sections. */ @@ -656,6 +660,8 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, list_add_tail(§ion->pages[i].list, &sgx_dirty_page_list); } + sgx_total_mem += nr_pages * PAGE_SIZE; + return true; } @@ -823,6 +829,8 @@ static int __init sgx_init(void) if (sgx_vepc_init() && ret) goto err_provision; + debugfs_create_ulong("sgx_total_mem", 0444, arch_debugfs_dir, &sgx_total_mem); + return 0; err_provision: -- 2.25.1