From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Hillf Danton <hdanton@sina.com>
Cc: x86@kernel.org, linux-sgx@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Jethro Beekman <jethro@fortanix.com>,
Jordan Hand <jorhand@linux.microsoft.com>,
Nathaniel McCallum <npmccallum@redhat.com>,
Chunyang Hui <sanqian.hcy@antfin.com>,
Seth Moore <sethmo@google.com>,
Sean Christopherson <sean.j.christopherson@intel.com>,
akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
yaozhangx@google.com, mikko.ylinen@intel.com
Subject: Re: [PATCH v40 21/24] x86/sgx: Add a page reclaimer
Date: Mon, 9 Nov 2020 21:59:57 +0200 [thread overview]
Message-ID: <20201109195957.GA5544@linux.intel.com> (raw)
In-Reply-To: <20201108035630.11540-1-hdanton@sina.com>
On Sun, Nov 08, 2020 at 11:56:30AM +0800, Hillf Danton wrote:
> On Wed, 4 Nov 2020 16:54:27 Jarkko Sakkinen wrote:
> [...]
> > +/**
> > + * sgx_alloc_epc_page() - Allocate an EPC page
> > + * @owner: the owner of the EPC page
> > + * @reclaim: reclaim pages if necessary
> > + *
> > + * Iterate through EPC sections and borrow a free EPC page to the caller. When a
> > + * page is no longer needed it must be released with sgx_free_epc_page(). If
> > + * @reclaim is set to true, directly reclaim pages when we are out of pages. No
> > + * mm's can be locked when @reclaim is set to true.
> > + *
> > + * Finally, wake up ksgxswapd when the number of pages goes below the watermark
> > + * before returning back to the caller.
> > + *
> > + * Return:
> > + * an EPC page,
> > + * -errno on error
> > + */
> > +struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim)
> > +{
> > + struct sgx_epc_page *entry;
>
> Nit: s/entry/epc_page/
> > +
> > + for ( ; ; ) {
> > + entry = __sgx_alloc_epc_page();
> > + if (!IS_ERR(entry)) {
> > + entry->owner = owner;
> > + break;
> > + }
> > +
> > + if (list_empty(&sgx_active_page_list))
> > + return ERR_PTR(-ENOMEM);
> > +
> > + if (!reclaim) {
> > + entry = ERR_PTR(-EBUSY);
> > + break;
> > + }
> > +
> > + if (signal_pending(current)) {
> > + entry = ERR_PTR(-ERESTARTSYS);
> > + break;
> > + }
> > +
> > + sgx_reclaim_pages();
> i
> This is the direct reclaim mode with ksgxswapd that works in
> the background ignored in the entire for loop. But we can go
> with it in parallel, see below, if it tries as hard as it can
> to maitain the watermark in which allocators may have no
> interest.
I think this policy should be left at is and once the code in mainline
further refined. Consider it as a baseline/initial version for
reclaiming code.
> > + schedule();
>
> To cut allocator's latency use cond_resched();
Thanks, I'll change this.
> > + }
> > +
> > + if (sgx_should_reclaim(SGX_NR_LOW_PAGES))
> > + wake_up(&ksgxswapd_waitq);
>
> Nit: s/ksgxswapd/sgxd/ as it seems to have nothing to do with swap,
> given sgx itself is clear and good enough.
Yeah, it also handling kexec() situation, i.e. has multitude of
functions.
> > +
> > + return entry;
> > +}
>
> struct sgx_epc_page *sgx_alloc_epc_page(void *owner, bool reclaim)
> {
> struct sgx_epc_page *epc_page;
>
> for (;;) {
> epc_page = __sgx_alloc_epc_page();
>
> if (!IS_ERR(epc_page)) {
> epc_page->owner = owner;
> return epc_page;
> }
>
> if (signal_pending(current))
> return ERR_PTR(-ERESTARTSYS);
>
> if (list_empty(&sgx_active_page_list) || !reclaim)
> return ERR_PTR(-ENOMEM);
>
> wake_up(&ksgxswapd_waitq);
> cond_resched();
> }
> return ERR_PTR(-ENOMEM);
> }
/Jarkko
next prev parent reply other threads:[~2020-11-09 20:00 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-04 14:54 [PATCH v40 00/24] Intel SGX foundations Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 01/24] x86/sgx: Add SGX architectural data structures Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 02/24] x86/sgx: Add wrappers for ENCLS functions Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 03/24] x86/sgx: Initialize metadata for Enclave Page Cache (EPC) sections Jarkko Sakkinen
2020-11-04 18:21 ` Borislav Petkov
2020-11-04 19:04 ` Jarkko Sakkinen
2020-11-04 19:09 ` Jarkko Sakkinen
2020-11-04 19:12 ` Borislav Petkov
2020-11-04 14:54 ` [PATCH v40 04/24] x86/cpufeatures: x86/msr: Add Intel SGX hardware bits Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 05/24] x86/cpufeatures: x86/msr: Add Intel SGX Launch Control " Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 06/24] x86/mm: x86/sgx: Signal SIGSEGV with PF_SGX Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 07/24] x86/cpu/intel: Detect SGX support Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 08/24] x86/cpu/intel: Add nosgx kernel parameter Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 09/24] x86/sgx: Add SGX page allocator functions Jarkko Sakkinen
2020-11-05 15:08 ` Borislav Petkov
2020-11-04 14:54 ` [PATCH v40 10/24] mm: Add 'mprotect' hook to struct vm_operations_struct Jarkko Sakkinen
2020-11-05 16:04 ` Borislav Petkov
2020-11-05 17:33 ` Dave Hansen
2020-11-06 10:04 ` Mel Gorman
2020-11-06 16:51 ` Jarkko Sakkinen
2020-11-06 20:37 ` Borislav Petkov
2020-11-06 22:04 ` Jarkko Sakkinen
2020-11-06 22:31 ` Borislav Petkov
2020-11-06 17:43 ` Dr. Greg
2020-11-06 17:54 ` Dave Hansen
2020-11-07 15:09 ` Dr. Greg
2020-11-07 19:16 ` Dave Hansen
2020-11-12 20:58 ` Dr. Greg
2020-11-12 21:31 ` Dave Hansen
2020-11-12 22:41 ` Andy Lutomirski
2020-11-16 18:00 ` Dr. Greg
2020-11-19 1:39 ` Haitao Huang
2020-11-20 17:31 ` Dr. Greg
2020-11-15 18:59 ` Dr. Greg
2020-11-06 21:13 ` Matthew Wilcox
2020-11-06 21:23 ` Dave Hansen
2020-11-07 15:27 ` Dr. Greg
2020-11-04 14:54 ` [PATCH v40 11/24] x86/sgx: Add SGX misc driver interface Jarkko Sakkinen
2020-11-05 1:10 ` Jarkko Sakkinen
2020-11-05 1:16 ` Jarkko Sakkinen
2020-11-05 16:05 ` Borislav Petkov
2020-11-05 17:57 ` Jarkko Sakkinen
2020-11-05 18:10 ` Borislav Petkov
2020-11-06 16:07 ` Jarkko Sakkinen
2020-11-06 17:09 ` Borislav Petkov
2020-11-06 22:01 ` Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 12/24] x86/sgx: Add SGX_IOC_ENCLAVE_CREATE Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 13/24] x86/sgx: Add SGX_IOC_ENCLAVE_ADD_PAGES Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 14/24] x86/sgx: Add SGX_IOC_ENCLAVE_INIT Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 15/24] x86/sgx: Add SGX_IOC_ENCLAVE_PROVISION Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 16/24] x86/vdso: Add support for exception fixup in vDSO functions Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 17/24] x86/fault: Add helper function to sanitize error code Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 18/24] x86/traps: Attempt to fixup exceptions in vDSO before signaling Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 19/24] x86/vdso: Implement a vDSO for Intel SGX enclave call Jarkko Sakkinen
2020-11-08 18:24 ` Jethro Beekman
2020-11-08 20:08 ` Jethro Beekman
2020-11-08 20:26 ` Dave Hansen
2020-11-08 20:20 ` Jethro Beekman
2020-11-08 20:30 ` Dave Hansen
2020-11-04 14:54 ` [PATCH v40 20/24] selftests/x86: Add a selftest for SGX Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 21/24] x86/sgx: Add a page reclaimer Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 22/24] x86/sgx: Add ptrace() support for the SGX driver Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 23/24] docs: x86/sgx: Document SGX kernel architecture Jarkko Sakkinen
2020-11-04 14:54 ` [PATCH v40 24/24] x86/sgx: Update MAINTAINERS Jarkko Sakkinen
2020-11-08 20:48 ` [PATCH v40 00/24] Intel SGX foundations Jethro Beekman
[not found] ` <20201108035630.11540-1-hdanton@sina.com>
2020-11-09 19:59 ` Jarkko Sakkinen [this message]
2020-11-21 15:12 ` Dr. Greg
2020-11-21 16:25 ` Dave Hansen
2020-11-24 10:55 ` Dr. Greg
2020-11-24 17:49 ` Andy Lutomirski
2020-11-21 18:36 ` Andy Lutomirski
2020-11-24 18:40 ` Dr. Greg
2020-11-24 21:57 ` Andy Lutomirski
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=20201109195957.GA5544@linux.intel.com \
--to=jarkko.sakkinen@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=hdanton@sina.com \
--cc=jethro@fortanix.com \
--cc=jorhand@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-sgx@vger.kernel.org \
--cc=mikko.ylinen@intel.com \
--cc=npmccallum@redhat.com \
--cc=sanqian.hcy@antfin.com \
--cc=sean.j.christopherson@intel.com \
--cc=sethmo@google.com \
--cc=x86@kernel.org \
--cc=yaozhangx@google.com \
/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).