linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Hansen <dave@sr71.net>
To: Kai Huang <kai.huang@intel.com>,
	linux-sgx@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org
Cc: seanjc@google.com, jarkko@kernel.org, luto@kernel.org,
	rick.p.edgecombe@intel.com, haitao.huang@intel.com,
	pbonzini@redhat.com, bp@alien8.de, tglx@linutronix.de,
	mingo@redhat.com, hpa@zytor.com
Subject: Re: [RFC PATCH v6 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()
Date: Fri, 26 Feb 2021 09:08:54 -0800	[thread overview]
Message-ID: <746450bb-917d-ab6c-9a6a-671112cd203e@sr71.net> (raw)
In-Reply-To: <308bd5a53199d1bf520d488f748e11ce76156a33.1614338774.git.kai.huang@intel.com>

On 2/26/21 4:14 AM, Kai Huang wrote:
> +/*
> + * Place the page in uninitialized state.  Only usable by callers that
> + * know the page is in a clean state in which EREMOVE will succeed.
> + */
> +static int sgx_reset_epc_page(struct sgx_epc_page *epc_page)
> +{
> +	int ret;
> +
> +	WARN_ON_ONCE(epc_page->flags & SGX_EPC_PAGE_RECLAIMER_TRACKED);
> +
> +	ret = __eremove(sgx_get_epc_virt_addr(epc_page));
> +	WARN_ONCE(ret, "EREMOVE returned %d (0x%x)", ret, ret);
> +
> +	return ret;
> +}
> +
>  /**
>   * sgx_encl_release - Destroy an enclave instance
>   * @kref:	address of a kref inside &sgx_encl
> @@ -404,7 +421,8 @@ void sgx_encl_release(struct kref *ref)
>  			if (sgx_unmark_page_reclaimable(entry->epc_page))
>  				continue;
>  
> -			sgx_free_epc_page(entry->epc_page);
> +			if (!sgx_reset_epc_page(entry->epc_page))
> +				sgx_free_epc_page(entry->epc_page);

Won't this leak the page?

I think that's fine; the page *IS* unusable if this happens.  But, the
error message that will show up isn't super informative.  If this
happened to a bunch of EPC pages, we'd be out of EPC with nothing to
show for it.

We must give a more informative message saying that the page is leaked.
 Ideally, we'd also make this debuggable by dumping out how many of
these pages there have been somewhere.  That can wait, though, until we
have some kind of stats coming out of the code (there's nothing now).  A
comment to remind us to do this would be nice.

Anyway, these are in decent shape and only getting better.  It's time to
get some more eyeballs on them and get the RFC tag off, so assuming that
a better error message gets stuck in here:

Acked-by: Dave Hansen <dave.hansen@intel.com>

  reply	other threads:[~2021-02-26 17:20 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-26 12:14 [RFC PATCH v6 00/25] KVM SGX virtualization support Kai Huang
2021-02-26 12:14 ` [RFC PATCH v6 01/25] x86/cpufeatures: Make SGX_LC feature bit depend on SGX bit Kai Huang
2021-02-26 12:14 ` [RFC PATCH v6 02/25] x86/cpufeatures: Add SGX1 and SGX2 sub-features Kai Huang
2021-02-26 12:14 ` [RFC PATCH v6 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page() Kai Huang
2021-02-26 17:08   ` Dave Hansen [this message]
2021-02-26 19:52     ` Sean Christopherson
2021-02-26 20:12       ` Dave Hansen
2021-02-26 22:34         ` Sean Christopherson
2021-03-01  6:13         ` Kai Huang
2021-02-26 12:14 ` [RFC PATCH v6 04/25] x86/sgx: Add SGX_CHILD_PRESENT hardware error code Kai Huang
2021-02-26 12:14 ` [RFC PATCH v6 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests Kai Huang
2021-02-26 12:14 ` [RFC PATCH v6 06/25] x86/cpu/intel: Allow SGX virtualization without Launch Control support Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 08/25] x86/sgx: Expose SGX architectural definitions to the kernel Kai Huang
2021-02-26 17:09   ` Dave Hansen
2021-02-26 12:15 ` [RFC PATCH v6 09/25] x86/sgx: Move ENCLS leaf definitions to sgx.h Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 10/25] x86/sgx: Add SGX2 ENCLS leaf definitions (EAUG, EMODPR and EMODT) Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 11/25] x86/sgx: Add encls_faulted() helper Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 12/25] x86/sgx: Add helper to update SGX_LEPUBKEYHASHn MSRs Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM Kai Huang
2021-03-05 17:51   ` Dave Hansen
2021-03-08  9:30     ` Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 14/25] x86/sgx: Move provisioning device creation out of SGX driver Kai Huang
2021-03-05 17:45   ` Dave Hansen
2021-02-26 12:15 ` [RFC PATCH v6 15/25] KVM: x86: Export kvm_mmu_gva_to_gpa_{read,write}() for SGX (VMX) Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 16/25] KVM: x86: Define new #PF SGX error code bit Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 17/25] KVM: x86: Add support for reverse CPUID lookup of scattered features Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 18/25] KVM: x86: Add reverse-CPUID lookup support for scattered SGX features Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 19/25] KVM: VMX: Add basic handling of VM-Exit from SGX enclave Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 20/25] KVM: VMX: Frame in ENCLS handler for SGX virtualization Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 21/25] KVM: VMX: Add SGX ENCLS[ECREATE] handler to enforce CPUID restrictions Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 22/25] KVM: VMX: Add emulation of SGX Launch Control LE hash MSRs Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 23/25] KVM: VMX: Add ENCLS[EINIT] handler to support SGX Launch Control (LC) Kai Huang
2021-02-26 12:15 ` [RFC PATCH v6 24/25] KVM: VMX: Enable SGX virtualization for SGX1, SGX2 and LC Kai Huang
2021-02-26 12:16 ` [RFC PATCH v6 25/25] KVM: x86: Add capability to grant VM access to privileged SGX attribute Kai Huang

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=746450bb-917d-ab6c-9a6a-671112cd203e@sr71.net \
    --to=dave@sr71.net \
    --cc=bp@alien8.de \
    --cc=haitao.huang@intel.com \
    --cc=hpa@zytor.com \
    --cc=jarkko@kernel.org \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    --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).