All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	intel-sgx-kernel-dev@lists.01.org
Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org
Subject: Re: [intel-sgx-kernel-dev] [PATCH v5 10/11] intel_sgx: glue code for in-kernel LE
Date: Tue, 14 Nov 2017 10:16:43 -0800	[thread overview]
Message-ID: <1510683403.11044.2.camel@intel.com> (raw)
In-Reply-To: <20171113194528.28557-11-jarkko.sakkinen@linux.intel.com>

On Mon, 2017-11-13 at 21:45 +0200, Jarkko Sakkinen wrote:
> --- a/drivers/platform/x86/intel_sgx/sgx_main.c
> +++ b/drivers/platform/x86/intel_sgx/sgx_main.c
> @@ -88,6 +88,37 @@ u64 sgx_encl_size_max_64;
>  u64 sgx_xfrm_mask = 0x3;
>  u32 sgx_misc_reserved;
>  u32 sgx_xsave_size_tbl[64];
> +bool sgx_unlocked_msrs;
> +u64 sgx_le_pubkeyhash[4];
> +
> +static DECLARE_RWSEM(sgx_file_sem);
> +
> +static int sgx_open(struct inode *inode, struct file *file)
> +{
> +	int ret;
> +
> +	down_read(&sgx_file_sem);
> +
> +	ret = sgx_le_start(&sgx_le_ctx);
> +	if (ret) {
> +		up_read(&sgx_file_sem);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static int sgx_release(struct inode *inode, struct file *file)
> +{
> +	up_read(&sgx_file_sem);
> +
> +	if (down_write_trylock(&sgx_file_sem)) {
> +		sgx_le_stop(&sgx_le_ctx);
> +		up_write(&sgx_file_sem);
> +	}
> +
> +	return 0;
> +}

This semaphore approach is broken due to the LE process using an anon inode for
/dev/sgx, which results in sgx_release being called without an accompanying call
to sgx_open.  This causes deadlocks due to a semaphore underrun.

https://lists.01.org/pipermail/intel-sgx-kernel-dev/2017-November/000901.html

[  242.659272] INFO: task lsdt:9425 blocked for more than 120 seconds.
[  242.659783]       Not tainted 4.14.0-rc4+ #18
[  242.660063] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
[  242.660558] lsdt            D    0  9425      1 0x00000004
[  242.660559] Call Trace:
[  242.660564]  __schedule+0x3c2/0x8b0
[  242.660567]  schedule+0x36/0x80
[  242.660568]  rwsem_down_read_failed+0x10a/0x170
[  242.660569]  call_rwsem_down_read_failed+0x18/0x30
[  242.660570]  ? call_rwsem_down_read_failed+0x18/0x30
[  242.660571]  down_read+0x20/0x40
[  242.660572]  sgx_open+0x19/0x40 [intel_sgx]
[  242.660574]  chrdev_open+0xbf/0x1b0
[  242.660576]  do_dentry_open+0x1f8/0x300
[  242.660577]  ? cdev_put+0x30/0x30
[  242.660578]  vfs_open+0x4f/0x70
[  242.660579]  path_openat+0x2ae/0x13a0
[  242.660581]  ? mem_cgroup_uncharge_swap+0x60/0x90
[  242.660582]  do_filp_open+0x99/0x110
[  242.660583]  ? __check_object_size+0xfc/0x1a0
[  242.660585]  ? __alloc_fd+0xb0/0x170
[  242.660586]  do_sys_open+0x124/0x210
[  242.660587]  ? do_sys_open+0x124/0x210
[  242.660588]  SyS_open+0x1e/0x20
[  242.660589]  entry_SYSCALL_64_fastpath+0x1e/0xa9
[  242.660590] RIP: 0033:0x7f426cf9ec7d
[  242.660591] RSP: 002b:00007f426b31ea60 EFLAGS: 00000293 ORIG_RAX: 
[  242.660592] RAX: ffffffffffffffda RBX: 000000c4200ba000 RCX: 00007f426cf9ec7d
[  242.660592] RDX: 0000000000000000 RSI: 0000000000000002 RDI: 000000000068cca7
[  242.660593] RBP: 00007f426b31ec10 R08: 0000000000f6bc30 R09: 0000000000000000
[  242.660593] R10: 00007f4264000078 R11: 0000000000000293 R12: 0000000000000001
[  242.660594] R13: 0000000000000000 R14: 00007f426d31b13d R15: 00007f42640008c0

>  #ifdef CONFIG_COMPAT
>  long sgx_compat_ioctl(struct file *filep, unsigned int cmd, unsigned long
> arg)
> @@ -141,8 +172,10 @@ static unsigned long sgx_get_unmapped_area(struct file
> *file,
>  	return addr;
>  }
>  
> -static const struct file_operations sgx_fops = {
> +const struct file_operations sgx_fops = {
>  	.owner			= THIS_MODULE,
> +	.open			= sgx_open,
> +	.release		= sgx_release,
>  	.unlocked_ioctl		= sgx_ioctl,
>  #ifdef CONFIG_COMPAT
>  	.compat_ioctl		= sgx_compat_ioctl,

  reply	other threads:[~2017-11-14 18:20 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-13 19:45 [PATCH v5 00/11] Intel SGX Driver Jarkko Sakkinen
2017-11-13 19:45 ` [PATCH v5 01/11] intel_sgx: updated MAINTAINERS Jarkko Sakkinen
2017-11-17 21:54   ` Darren Hart
2017-11-24 19:18     ` Jarkko Sakkinen
2017-11-13 19:45 ` [PATCH v5 02/11] x86: add SGX definition to cpufeature Jarkko Sakkinen
2017-11-13 19:45 ` [PATCH v5 03/11] x86: define the feature control MSR's SGX enable bit Jarkko Sakkinen
2017-11-17 21:48   ` Darren Hart
2017-11-13 19:45 ` [PATCH v5 04/11] x86: define the feature control MSR's SGX launch control bit Jarkko Sakkinen
2017-11-13 19:45 ` [PATCH v5 05/11] x86: add SGX MSRs to msr-index.h Jarkko Sakkinen
2017-11-13 19:45 ` [PATCH v5 06/11] intel_sgx: driver for Intel Software Guard Extensions Jarkko Sakkinen
2017-11-13 23:41   ` James Morris
2017-11-14 20:12     ` Jarkko Sakkinen
2017-11-15 10:04       ` Jarkko Sakkinen
2017-11-14 17:55   ` [intel-sgx-kernel-dev] " Sean Christopherson
2017-11-14 20:28     ` Jarkko Sakkinen
2017-11-15 18:20       ` Sean Christopherson
2017-12-13 23:18         ` Christopherson, Sean J
2017-12-13 23:18           ` Christopherson, Sean J
2017-12-15 15:00           ` Jarkko Sakkinen
2017-12-15 15:00             ` Jarkko Sakkinen
2017-12-19 18:52             ` Christopherson, Sean J
2017-12-19 18:52               ` Christopherson, Sean J
2017-12-19 23:11               ` Jarkko Sakkinen
2017-12-19 23:11                 ` Jarkko Sakkinen
2017-12-19 23:24                 ` Christopherson, Sean J
2017-12-19 23:24                   ` Christopherson, Sean J
2017-12-20 10:13                   ` Jarkko Sakkinen
2017-12-20 10:13                     ` Jarkko Sakkinen
2017-11-13 19:45 ` [PATCH v5 07/11] intel_sgx: ptrace() support Jarkko Sakkinen
2017-11-16  9:28   ` Thomas Gleixner
2017-11-23 10:25     ` Jarkko Sakkinen
2017-11-13 19:45 ` [PATCH v5 08/11] intel_sgx: in-kernel launch enclave Jarkko Sakkinen
2017-11-14 17:05   ` [intel-sgx-kernel-dev] " Sean Christopherson
2017-11-14 20:05     ` Jarkko Sakkinen
2017-11-20 22:21       ` Jarkko Sakkinen
2017-11-15 11:50   ` Peter Zijlstra
2017-11-20 22:25     ` Jarkko Sakkinen
2017-11-20 22:43       ` Thomas Gleixner
2017-11-20 23:43         ` Jarkko Sakkinen
2017-11-20 23:48           ` Thomas Gleixner
2017-11-21 12:23             ` Jarkko Sakkinen
2017-11-21 23:36               ` Thomas Gleixner
2017-11-13 19:45 ` [PATCH v5 09/11] fs/pipe.c: export create_pipe_files() and replace_fd() Jarkko Sakkinen
2017-11-16  9:15   ` Thomas Gleixner
2017-11-20 22:30     ` Jarkko Sakkinen
2017-11-13 19:45 ` [PATCH v5 10/11] intel_sgx: glue code for in-kernel LE Jarkko Sakkinen
2017-11-14 18:16   ` Sean Christopherson [this message]
2017-11-14 20:31     ` [intel-sgx-kernel-dev] " Jarkko Sakkinen
2017-11-15 10:10       ` Jarkko Sakkinen
2017-11-17 23:07   ` Darren Hart
2017-11-25 12:52     ` Jarkko Sakkinen
2017-11-25 18:01     ` Jarkko Sakkinen
2017-11-13 19:45 ` [PATCH v5 11/11] intel_sgx: driver documentation Jarkko Sakkinen
2017-11-14  3:01   ` [intel-sgx-kernel-dev] " Kai Huang
2017-11-14 19:47     ` Jarkko Sakkinen
2017-11-14 21:12       ` Kai Huang
2017-11-14  8:36   ` Borislav Petkov
2017-11-14 20:49     ` Jarkko Sakkinen
2017-11-14 21:53       ` Borislav Petkov
2017-11-20 22:37         ` Jarkko Sakkinen
2017-11-20 22:42           ` Borislav Petkov
2017-11-20 23:41             ` Jarkko Sakkinen
2017-11-21 11:10               ` Borislav Petkov
2017-11-15 11:54       ` Peter Zijlstra
2017-11-20 22:46         ` Jarkko Sakkinen
2017-11-21 12:38           ` Jarkko Sakkinen
2017-11-21 12:47             ` Borislav Petkov
2017-11-21 23:45               ` Jethro Beekman
2017-11-22  0:10                 ` Borislav Petkov
2017-11-22  0:27                   ` Jethro Beekman
2017-11-22 11:00                     ` Borislav Petkov
2017-11-22 16:07                       ` Jethro Beekman
2017-11-17 21:43   ` Darren Hart
2017-11-17 23:34     ` Thomas Gleixner
2017-11-17 23:46       ` Darren Hart
2017-11-20 23:12         ` Jarkko Sakkinen
2017-11-20 23:08       ` Jarkko Sakkinen
2017-11-27 17:03         ` Sean Christopherson
2017-11-27 19:41           ` Sean Christopherson
2017-11-28 20:37           ` Jarkko Sakkinen
2017-11-28 20:46             ` Jarkko Sakkinen
2017-11-24 17:26     ` Jarkko Sakkinen
2017-11-15 10:35 ` [PATCH v5 00/11] Intel SGX Driver Thomas Gleixner
2017-11-20 22:20   ` 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=1510683403.11044.2.camel@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=intel-sgx-kernel-dev@lists.01.org \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.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.