From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: x86@kernel.org, linux-sgx@vger.kernel.org,
akpm@linux-foundation.org, dave.hansen@intel.com,
nhorman@redhat.com, npmccallum@redhat.com, serge.ayoun@intel.com,
shay.katz-zamir@intel.com, haitao.huang@intel.com,
andriy.shevchenko@linux.intel.com, tglx@linutronix.de,
kai.svahn@intel.com, bp@alien8.de, josh@joshtriplett.org,
luto@kernel.org, kai.huang@intel.com, rientjes@google.com,
Suresh Siddha <suresh.b.siddha@intel.com>
Subject: Re: [PATCH v19 16/27] x86/sgx: Add the Linux SGX Enclave Driver
Date: Thu, 21 Mar 2019 09:47:14 -0700 [thread overview]
Message-ID: <20190321164714.GE6519@linux.intel.com> (raw)
In-Reply-To: <20190321155111.GR4603@linux.intel.com>
On Thu, Mar 21, 2019 at 05:51:11PM +0200, Jarkko Sakkinen wrote:
> On Tue, Mar 19, 2019 at 02:19:51PM -0700, Sean Christopherson wrote:
> > IMO we should get rid of SGX_POWER_LOST_ENCLAVE and the SUSPEND flag.
> >
> > - Userspace needs to handle -EFAULT cleanly even if we hook into
> > suspend/hibernate via sgx_encl_pm_notifier(), e.g. to handle virtual
> > machine migration.
> > - In the event that suspend is canceled after sgx_encl_pm_notifier()
> > runs, we'll have prematurely invalidated the enclave.
> > - Invalidating all enclaves could be slow on a system with GBs of EPC,
> > i.e. probably not the best thing to do in the suspend path.
> >
> > Removing SGX_POWER_LOST_ENCLAVE means we can drop all of the pm_notifier()
> > code, which will likely save us a bit of maintenance down the line.
>
> I don't disgree. Isn't it a racy flag in the VM context i.e. because
> suspend can happen without SGX core noticing it (running inside a VM)?
> That would a bug.
...
> > > +#ifdef CONFIG_ACPI
> > > +static struct acpi_device_id sgx_device_ids[] = {
> > > + {"INT0E0C", 0},
> > > + {"", 0},
> > > +};
> > > +MODULE_DEVICE_TABLE(acpi, sgx_device_ids);
> > > +#endif
> > > +
> > > +static struct platform_driver sgx_drv = {
> > > + .probe = sgx_drv_probe,
> > > + .remove = sgx_drv_remove,
> > > + .driver = {
> > > + .name = "sgx",
> > > + .acpi_match_table = ACPI_PTR(sgx_device_ids),
> > > + },
> > > +};
> >
> > Utilizing the platform driver is unnecessary, adds complexity and IMO is
> > flat out wrong given the current direction of implementing SGX as a
> > full-blooded architectural feature.
> >
> > - All hardware information is readily available via CPUID
> > - arch_initcall hooks obviates the need for ACPI autoprobe
> > - EPC manager assumes it has full control over all EPC, i.e. EPC
> > sections are not managed as independent "devices"
> > - BIOS will enumerate a single ACPI entry regardless of the number
> > of EPC sections, i.e. the ACPI entry is *only* useful for probing
> > - Userspace driver matches the EPC device, but doesn't actually
> > "own" the EPC
>
> It is for hotplugging. I don't really have strong opinions of this but
> having a driver for uapi allows things like blacklisting sgx.
Hotplugging what? EPC can't be hotplugged, EPC enumeration through CPUID
won't change post-boot and the ACPI entry can't be relied upon for EPC
base/size information when there are multiple EPC sections.
> > > +
> > > +static int __init sgx_drv_subsys_init(void)
> > > +{
> > > + int ret;
> > > +
> > > + ret = bus_register(&sgx_bus_type);
> >
> > Do we really need a bus/class? Allocating a chrdev region also seems like
> > overkill. At this point there is exactly one SGX device, and while there
> > is a pretty good chance we'll end up with a virtualization specific device
> > for exposing EPC to guest, there's no guarantee said device will be SGX
> > specific. Using a dynamic miscdevice would eliminate a big chunk of code.
>
> AFAIK misc is not recommended for any new drivers as it has suvere
> limitations like not allowing to add non-racy sysfs attributes. Whatever
> the solution is, lets not use misc.
Ah right, forgot about that.
> > > + if (ret)
> > > + return ret;
> > > +
> > > + ret = alloc_chrdev_region(&sgx_devt, 0, SGX_DRV_NR_DEVICES, "sgx");
> > > + if (ret < 0) {
> > > + bus_unregister(&sgx_bus_type);
> > > + return ret;
> > > + }
> > > +
> > > + return 0;
> > > +}
...
> > > +static void sgx_vma_open(struct vm_area_struct *vma)
> > > +{
> > > + struct sgx_encl *encl = vma->vm_private_data;
> > > + struct sgx_encl_mm *mm;
> > > +
> > > + if (!encl)
> > > + return;
> > > +
> > > + if (encl->flags & SGX_ENCL_DEAD)
> > > + goto out;
> > > +
> > > + mm = sgx_encl_get_mm(encl, vma->vm_mm);
> > > + if (!mm) {
> > > + mm = kzalloc(sizeof(*mm), GFP_KERNEL);
> > > + if (!mm) {
> > > + encl->flags |= SGX_ENCL_DEAD;
> >
> > Failure to allocate memory for one user of the enclave shouldn't kill
> > the enclave, e.g. failing during fork() shouldn't kill the enclave in
> > the the parent. And marking an enclave dead without holding its lock
> > is all kinds of bad.
>
> This is almost non-existent occasion. Agree with the locking though..
> And I'm open for other fallbacks but given the rarity I think the
> current one in sustainable.
What if we clear vm_private_data? And maybe do a pr_warn_ratelimited()
so that userspace gets some form of notification that forking an enclave
failed. A NULL encl is easy to check in the fault handler and any where
else we consume vmas.
>
> >
> > > + goto out;
> > > + }
> > > +
> > > + spin_lock(&encl->mm_lock);
> > > + mm->encl = encl;
> > > + mm->mm = vma->vm_mm;
> > > + list_add(&mm->list, &encl->mm_list);
> > > + kref_init(&mm->refcount);
> >
> > Not that it truly matters, but list_add() is the only thing that needs
> > to be protected with the spinlock, everything else can be done ahead of
> > time.
>
> True :-)
>
> >
> > > + spin_unlock(&encl->mm_lock);
> > > + } else {
> > > + mmdrop(mm->mm);
> > > + }
> > > +
> > > +out:
> > > + kref_get(&encl->refcount);
> > > +}
> > > +
> > > +static void sgx_vma_close(struct vm_area_struct *vma)
> > > +{
> > > + struct sgx_encl *encl = vma->vm_private_data;
> > > + struct sgx_encl_mm *mm;
> > > +
> > > + if (!encl)
> > > + return;
> > > +
> > > + mm = sgx_encl_get_mm(encl, vma->vm_mm);
> >
> > Isn't this unnecessary? sgx_vma_open() had to have been called on this
> > VMA, otherwise we wouldn't be here.
>
> Not in the case when allocation fails in vma_open.
Ah, I see the flow. If we do keep the enclave killing behavior then I
think it'd make sense to let this be handled by checking SGX_ENCL_DEAD.
But AFAICT things will "just work" if we nullify vm_private_data.
next prev parent reply other threads:[~2019-03-21 16:47 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-17 21:14 [PATCH v19 00/27] Intel SGX1 support Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 01/27] x86/cpufeatures: Add Intel-defined SGX feature bit Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 02/27] x86/cpufeatures: Add SGX sub-features (as Linux-defined bits) Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 03/27] x86/msr: Add IA32_FEATURE_CONTROL.SGX_ENABLE definition Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 04/27] x86/cpufeatures: Add Intel-defined SGX_LC feature bit Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 05/27] x86/msr: Add SGX Launch Control MSR definitions Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 06/27] x86/mm: x86/sgx: Add new 'PF_SGX' page fault error code bit Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 07/27] x86/mm: x86/sgx: Signal SIGSEGV for userspace #PFs w/ PF_SGX Jarkko Sakkinen
2019-03-18 17:15 ` Dave Hansen
2019-03-18 19:53 ` Sean Christopherson
2019-03-17 21:14 ` [PATCH v19 08/27] x86/cpu/intel: Detect SGX support and update caps appropriately Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 09/27] x86/sgx: Add ENCLS architectural error codes Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 10/27] x86/sgx: Add SGX1 and SGX2 architectural data structures Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 11/27] x86/sgx: Add definitions for SGX's CPUID leaf and variable sub-leafs Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 12/27] x86/sgx: Enumerate and track EPC sections Jarkko Sakkinen
2019-03-18 19:50 ` Sean Christopherson
2019-03-21 14:40 ` Jarkko Sakkinen
2019-03-21 15:28 ` Sean Christopherson
2019-03-22 10:19 ` Jarkko Sakkinen
2019-03-22 10:50 ` Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 13/27] x86/sgx: Add wrappers for ENCLS leaf functions Jarkko Sakkinen
2019-03-19 19:59 ` Sean Christopherson
2019-03-21 14:51 ` Jarkko Sakkinen
2019-03-21 15:40 ` Sean Christopherson
2019-03-22 11:00 ` Jarkko Sakkinen
2019-03-22 16:43 ` Sean Christopherson
2019-03-17 21:14 ` [PATCH v19 16/27] x86/sgx: Add the Linux SGX Enclave Driver Jarkko Sakkinen
2019-03-19 21:19 ` Sean Christopherson
2019-03-21 15:51 ` Jarkko Sakkinen
2019-03-21 16:47 ` Sean Christopherson [this message]
2019-03-22 11:10 ` Jarkko Sakkinen
2019-03-26 13:26 ` Jarkko Sakkinen
2019-03-26 23:58 ` Sean Christopherson
2019-03-27 5:28 ` Jarkko Sakkinen
2019-03-27 17:57 ` Sean Christopherson
2019-03-27 18:38 ` Jethro Beekman
2019-03-27 20:06 ` Sean Christopherson
2019-03-28 1:21 ` Jethro Beekman
2019-03-28 13:19 ` Jarkko Sakkinen
2019-03-28 19:05 ` Andy Lutomirski
2019-03-29 9:43 ` Jarkko Sakkinen
2019-03-29 16:20 ` Sean Christopherson
2019-04-01 10:01 ` Jarkko Sakkinen
2019-04-01 17:25 ` Jethro Beekman
2019-04-01 22:57 ` Jarkko Sakkinen
2019-03-28 13:15 ` Jarkko Sakkinen
2019-03-19 23:00 ` Sean Christopherson
2019-03-21 16:18 ` Jarkko Sakkinen
2019-03-21 17:38 ` Sean Christopherson
2019-03-22 11:17 ` Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 17/27] x86/sgx: Add provisioning Jarkko Sakkinen
2019-03-19 20:09 ` Sean Christopherson
2019-03-21 2:08 ` Huang, Kai
2019-03-21 14:32 ` Jarkko Sakkinen
2019-03-21 21:41 ` Huang, Kai
2019-03-22 11:31 ` Jarkko Sakkinen
2019-03-21 14:30 ` Jarkko Sakkinen
2019-03-21 14:38 ` Nathaniel McCallum
2019-03-22 11:22 ` Jarkko Sakkinen
2019-03-21 16:50 ` Andy Lutomirski
2019-03-22 11:29 ` Jarkko Sakkinen
2019-03-22 11:43 ` Jarkko Sakkinen
2019-03-22 18:20 ` Andy Lutomirski
2019-03-25 14:55 ` Jarkko Sakkinen
2019-03-27 0:14 ` Sean Christopherson
2019-04-05 10:18 ` Jarkko Sakkinen
2019-04-05 13:53 ` Andy Lutomirski
2019-04-05 14:20 ` Jarkko Sakkinen
2019-04-05 14:34 ` Greg KH
2019-04-09 13:37 ` Jarkko Sakkinen
2019-04-05 14:21 ` Greg KH
2019-03-17 21:14 ` [PATCH v19 19/27] x86/sgx: ptrace() support for the SGX driver Jarkko Sakkinen
2019-03-19 22:22 ` Sean Christopherson
2019-03-21 15:02 ` Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 20/27] x86/vdso: Add support for exception fixup in vDSO functions Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 21/27] x86/fault: Add helper function to sanitize error code Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 22/27] x86/fault: Attempt to fixup unhandled #PF in vDSO before signaling Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 23/27] x86/traps: Attempt to fixup exceptions " Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 25/27] x86/sgx: SGX documentation Jarkko Sakkinen
2019-03-20 17:14 ` Sean Christopherson
2019-03-21 16:24 ` Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 26/27] selftests/x86: Add a selftest for SGX Jarkko Sakkinen
2019-03-17 21:14 ` [PATCH v19 27/27] x86/sgx: Update MAINTAINERS Jarkko Sakkinen
2019-03-19 17:12 ` Sean Christopherson
2019-03-21 14:42 ` Jarkko Sakkinen
[not found] ` <20190317211456.13927-19-jarkko.sakkinen@linux.intel.com>
2019-03-19 22:09 ` [PATCH v19 18/27] x86/sgx: Add swapping code to the core and SGX driver Sean Christopherson
2019-03-21 14:59 ` Jarkko Sakkinen
2019-03-19 23:41 ` [PATCH v19 00/27] Intel SGX1 support Sean Christopherson
2019-03-19 23:52 ` Jethro Beekman
2019-03-20 0:22 ` Sean Christopherson
2019-03-21 16:20 ` Jarkko Sakkinen
2019-03-21 16:00 ` 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=20190321164714.GE6519@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=haitao.huang@intel.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=josh@joshtriplett.org \
--cc=kai.huang@intel.com \
--cc=kai.svahn@intel.com \
--cc=linux-sgx@vger.kernel.org \
--cc=luto@kernel.org \
--cc=nhorman@redhat.com \
--cc=npmccallum@redhat.com \
--cc=rientjes@google.com \
--cc=serge.ayoun@intel.com \
--cc=shay.katz-zamir@intel.com \
--cc=suresh.b.siddha@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.