linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kai Huang <kai.huang@intel.com>
To: Dave Hansen <dave.hansen@intel.com>
Cc: <linux-sgx@vger.kernel.org>, <kvm@vger.kernel.org>,
	<x86@kernel.org>, <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 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM
Date: Mon, 8 Mar 2021 22:30:06 +1300	[thread overview]
Message-ID: <20210308223006.5610bc084eb17844f43c0b27@intel.com> (raw)
In-Reply-To: <64a2d65f-ddf9-b42b-5b51-76bb3b79a30e@intel.com>

On Fri, 5 Mar 2021 09:51:56 -0800 Dave Hansen wrote:
> On 2/26/21 4:15 AM, Kai Huang wrote:
> > +int sgx_virt_ecreate(struct sgx_pageinfo *pageinfo, void __user *secs,
> > +		     int *trapnr)
> > +{
> > +	int ret;
> > +
> > +	/*
> > +	 * @secs is userspace address, and it's not guaranteed @secs points at
> > +	 * an actual EPC page. 
> 
> There are four cases that I can think of:
> 1. @secs points to an EPC page.  Good, return 0 and go on with life.
> 2. @secs points to a non-EPC page.  It will fault and permanently error
>    out
> 3. @secs points to a Present=0 PTE.  It will fault, but we need to call
>    the fault handler to get a page in here.
> 4. @secs points to a kernel address
> 
> #1 and #2 are handled and described.
> 
> #4 is probably impossible because the address comes out of some
> gpa_to_hva() KVM code.  But, it still _looks_ wonky here.  I wouldn't
> hate an access_ok() check on it.
> 
> 	/*
> 	 * @secs is an untrusted, userspace-provided address.  It comes
>          * from KVM and is assumed to point somewhere in userspace.
>  	 * This can fault and call SGX or other fault handlers.
> 	 */
> 
> You can also spend a moment to describe the kinds of faults that are
> handled and what is fatal.

Thanks Dave for the comments. I'll refine accordingly.

> 
> 
> > +	 * to physical EPC page by resolving PFN but using __uaccess_xx() is
> > +	 * simpler.
> > +	 */
> 
> I'd leave the justification for the changelog.

Will do.

> 
> > +	__uaccess_begin();
> > +	ret = __ecreate(pageinfo, (void *)secs);
> > +	__uaccess_end();
> > +
> > +	if (encls_faulted(ret)) {
> > +		*trapnr = ENCLS_TRAPNR(ret);
> > +		return -EFAULT;
> > +	}
> 

  reply	other threads:[~2021-03-08  9:31 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
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 [this message]
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=20210308223006.5610bc084eb17844f43c0b27@intel.com \
    --to=kai.huang@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=haitao.huang@intel.com \
    --cc=hpa@zytor.com \
    --cc=jarkko@kernel.org \
    --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).