From: Jarkko Sakkinen <jarkko@kernel.org>
To: Dave Hansen <dave.hansen@intel.com>
Cc: Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-sgx@vger.kernel.org,
Reinette Chatre <reinette.chatre@intel.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Jonathan Corbet <corbet@lwn.net>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v2 1/4] x86/sgx: Add /sys/kernel/debug/x86/sgx_total_mem
Date: Fri, 30 Jul 2021 03:59:30 +0300 [thread overview]
Message-ID: <20210730005930.ew3evpnnlqcjtf26@kernel.org> (raw)
In-Reply-To: <5d3614af-2393-6744-9d85-7001241ca76e@intel.com>
On Thu, Jul 29, 2021 at 09:27:41AM -0700, Dave Hansen wrote:
> On 7/28/21 3:51 PM, Jarkko Sakkinen wrote:
> > Create /sys/kernel/debug/x86/sgx_total_mem, after the driver is
> > initialized, describing the total amount of SGX reserved memory (also known
> > as Enclave Page Cache (EPC)) available in the system.
> >
> > This can be used to implement stress that trigger the page reclaimer, and
> > it is probably useful information when admistering a system running
> > enclaves anyhow.
>
> How about this as a rewrite?
>
> 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.
>
> > diff --git a/Documentation/x86/sgx.rst b/Documentation/x86/sgx.rst
> > index dd0ac96ff9ef..15bb8f4e42af 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.
> > +
> > +SGX debugging
> > +=============
> > +
> > +*/sys/kernel/debug/x86/sgx_total_mem* describes the total available
> > +SGX mwemory available in the system.
>
> ^ memory
>
> It would also be nice to say what the units are here, even if they are
> bytes.
>
> > 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 <linux/debugfs.h>
> > #include <linux/file.h>
> > #include <linux/freezer.h>
> > #include <linux/highmem.h>
> > @@ -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:
> >
>
> Assuming the new changelog is adopted and typos fixed:
>
> Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Thanks, I'll commit these changes and include to the next version.
/Jarkko
next prev parent reply other threads:[~2021-07-30 0:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-28 22:51 [PATCH v2 0/4] Swap and fault all the pages of the test enclave binary Jarkko Sakkinen
2021-07-28 22:51 ` [PATCH v2 1/4] x86/sgx: Add /sys/kernel/debug/x86/sgx_total_mem Jarkko Sakkinen
2021-07-29 16:27 ` Dave Hansen
2021-07-30 0:59 ` Jarkko Sakkinen [this message]
2021-07-28 22:51 ` [PATCH v2 2/4] selftests/sgx: Fix calculations for sub-maximum field sizes Jarkko Sakkinen
2021-07-28 22:51 ` [PATCH v2 3/4] selftests/sgx: Assign source for each segment Jarkko Sakkinen
2021-07-28 22:51 ` [PATCH v2 4/4] selftests/sgx: Trigger the reclaimer and #PF handler Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210730005930.ew3evpnnlqcjtf26@kernel.org \
--to=jarkko@kernel.org \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=reinette.chatre@intel.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).