Re: [PATCH v10 3/4] tee: add OP-TEE driver

2016-06-07 Thread Jens Wiklander
On Mon, Jun 06, 2016 at 04:49:57PM -0500, Nishanth Menon wrote:
> On 06/01/2016 07:41 AM, Jens Wiklander wrote:
> [...]
> > diff --git a/drivers/tee/Makefile b/drivers/tee/Makefile
> > index 60d2dab..53f3c76 100644
> > --- a/drivers/tee/Makefile
> > +++ b/drivers/tee/Makefile
> > @@ -1,3 +1,4 @@
> >  obj-y += tee.o
> >  obj-y += tee_shm.o
> >  obj-y += tee_shm_pool.o
> > +obj-$(CONFIG_OPTEE) += optee/
> > diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
> > new file mode 100644
> > index 000..a7a8b71
> > --- /dev/null
> > +++ b/drivers/tee/optee/Kconfig
> > @@ -0,0 +1,8 @@
> > +# OP-TEE Trusted Execution Environment Configuration
> > +config OPTEE
> > +   tristate "OP-TEE"
> > +   default n
> You should'nt need this.

I'll fix.

> 
> > +   depends on HAVE_ARM_SMCCC
> 
> HAVE_ARM_SMCCC might depend on OPTEE secure support in place, right? I
> wonder if setsup any constraints for having a single zImage for OPTEE
> and non-OPTEE systems, I think not.. just wondering.

No, HAVE_ARM_SMCCC indicates just the presence of the arm_smccc_smc()
and arm_smccc_hvc() assembly functions. They are used by PSCI
independent of any TEE driver also.

> 
> Further, at this patch, smatch[1] complains:
> > +drivers/tee/optee/core.c:488 optee_probe() error: we previously assumed 
> > 'optee' could be null (see line 444) 

Sorry, I'll fix.

> 
> Checkpatch --strict complains:
> 
> > +CHECK: Alignment should match open parenthesis
> > +#878: FILE: drivers/tee/optee/core.c:333:
> > ++static struct tee_shm_pool *optee_config_shm_ioremap(struct device *dev,
> > ++  optee_invoke_fn *invoke_fn,

Fixing this warning would make it less readable in my opinion, I'd
rather keep it as it is if you don't mind.

--
Thanks,
Jens


Re: [PATCH v10 3/4] tee: add OP-TEE driver

2016-06-06 Thread Nishanth Menon
On 06/01/2016 07:41 AM, Jens Wiklander wrote:
[...]
> diff --git a/drivers/tee/Makefile b/drivers/tee/Makefile
> index 60d2dab..53f3c76 100644
> --- a/drivers/tee/Makefile
> +++ b/drivers/tee/Makefile
> @@ -1,3 +1,4 @@
>  obj-y += tee.o
>  obj-y += tee_shm.o
>  obj-y += tee_shm_pool.o
> +obj-$(CONFIG_OPTEE) += optee/
> diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
> new file mode 100644
> index 000..a7a8b71
> --- /dev/null
> +++ b/drivers/tee/optee/Kconfig
> @@ -0,0 +1,8 @@
> +# OP-TEE Trusted Execution Environment Configuration
> +config OPTEE
> + tristate "OP-TEE"
> + default n
You should'nt need this.

> + depends on HAVE_ARM_SMCCC

HAVE_ARM_SMCCC might depend on OPTEE secure support in place, right? I
wonder if setsup any constraints for having a single zImage for OPTEE
and non-OPTEE systems, I think not.. just wondering.

Further, at this patch, smatch[1] complains:
> +drivers/tee/optee/core.c:488 optee_probe() error: we previously assumed 
> 'optee' could be null (see line 444) 

Checkpatch --strict complains:

> +CHECK: Alignment should match open parenthesis
> +#878: FILE: drivers/tee/optee/core.c:333:
> ++static struct tee_shm_pool *optee_config_shm_ioremap(struct device *dev,
> ++  optee_invoke_fn *invoke_fn,


[1] git://repo.or.cz/smatch.git
-- 
Regards,
Nishanth Menon


Re: [PATCH v10 3/4] tee: add OP-TEE driver

2016-06-06 Thread Javier González
> 
> On 01 Jun 2016, at 14:41, Jens Wiklander  wrote:
> 
> Adds a OP-TEE driver which also can be compiled as a loadable module.
> 
> * Targets ARM and ARM64
> * Supports using reserved memory from OP-TEE as shared memory
> * Probes OP-TEE version using SMCs
> * Accepts requests on privileged and unprivileged device
> * Uses OPTEE message protocol version 2 to communicate with secure world
> 
> Acked-by: Andreas Dannenberg 
> Signed-off-by: Jens Wiklander 
> ---
> MAINTAINERS   |   5 +
> drivers/tee/Kconfig   |  10 +
> drivers/tee/Makefile  |   1 +
> drivers/tee/optee/Kconfig |   8 +
> drivers/tee/optee/Makefile|   5 +
> drivers/tee/optee/call.c  | 422 +
> drivers/tee/optee/core.c  | 553 ++
> drivers/tee/optee/optee_msg.h | 435 ++
> drivers/tee/optee/optee_private.h | 181 +
> drivers/tee/optee/optee_smc.h | 418 
> drivers/tee/optee/rpc.c   | 401 +++
> drivers/tee/optee/supp.c  | 241 +
> 12 files changed, 2680 insertions(+)
> create mode 100644 drivers/tee/optee/Kconfig
> create mode 100644 drivers/tee/optee/Makefile
> create mode 100644 drivers/tee/optee/call.c
> create mode 100644 drivers/tee/optee/core.c
> create mode 100644 drivers/tee/optee/optee_msg.h
> create mode 100644 drivers/tee/optee/optee_private.h
> create mode 100644 drivers/tee/optee/optee_smc.h
> create mode 100644 drivers/tee/optee/rpc.c
> create mode 100644 drivers/tee/optee/supp.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 802ccf9..c02243c 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -8479,6 +8479,11 @@ F: arch/*/oprofile/
> F:drivers/oprofile/
> F:include/linux/oprofile.h
> 
> +OP-TEE DRIVER
> +M:   Jens Wiklander 
> +S:   Maintained
> +F:   drivers/tee/optee/
> +
> ORACLE CLUSTER FILESYSTEM 2 (OCFS2)
> M:Mark Fasheh 
> M:Joel Becker 
> diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig
> index f3ba154..7228045 100644
> --- a/drivers/tee/Kconfig
> +++ b/drivers/tee/Kconfig
> @@ -7,3 +7,13 @@ config TEE
>   help
> This implements a generic interface towards a Trusted Execution
> Environment (TEE).
> +
> +if TEE
> +
> +menu "TEE drivers"
> +
> +source "drivers/tee/optee/Kconfig"
> +
> +endmenu
> +
> +endif
> diff --git a/drivers/tee/Makefile b/drivers/tee/Makefile
> index 60d2dab..53f3c76 100644
> --- a/drivers/tee/Makefile
> +++ b/drivers/tee/Makefile
> @@ -1,3 +1,4 @@
> obj-y += tee.o
> obj-y += tee_shm.o
> obj-y += tee_shm_pool.o
> +obj-$(CONFIG_OPTEE) += optee/
> diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
> new file mode 100644
> index 000..a7a8b71
> --- /dev/null
> +++ b/drivers/tee/optee/Kconfig
> @@ -0,0 +1,8 @@
> +# OP-TEE Trusted Execution Environment Configuration
> +config OPTEE
> + tristate "OP-TEE"
> + default n
> + depends on HAVE_ARM_SMCCC
> + help
> +   This implements the OP-TEE Trusted Execution Environment (TEE)
> +   driver.
> diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile
> new file mode 100644
> index 000..92fe578
> --- /dev/null
> +++ b/drivers/tee/optee/Makefile
> @@ -0,0 +1,5 @@
> +obj-$(CONFIG_OPTEE) += optee.o
> +optee-objs += core.o
> +optee-objs += call.o
> +optee-objs += rpc.o
> +optee-objs += supp.o
> diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c
> new file mode 100644
> index 000..8f9b12e
> --- /dev/null
> +++ b/drivers/tee/optee/call.c
> @@ -0,0 +1,422 @@
> +/*
> + * Copyright (c) 2015, Linaro Limited
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "optee_private.h"
> +#include "optee_smc.h"
> +
> +struct optee_call_waiter {
> + struct list_head list_node;
> + struct completion c;
> + bool completed;
> +};
> +
> +static void optee_cq_wait_init(struct optee_call_queue *cq,
> +struct optee_call_waiter *w)
> +{
> + mutex_lock(&cq->mutex);
> + /*
> +  * We add ourselves to the queue, but we don't wait. This
> +  * guarentees that we don't lose a completion if secure world
> +  * returns busy and another thread just exited and try to complete
> +  * someone.
> +  */
> + w->completed = false;
> + init_completion(&w->c);
> + list_add_tail(&w->list_node, &

[PATCH v10 3/4] tee: add OP-TEE driver

2016-06-01 Thread Jens Wiklander
Adds a OP-TEE driver which also can be compiled as a loadable module.

* Targets ARM and ARM64
* Supports using reserved memory from OP-TEE as shared memory
* Probes OP-TEE version using SMCs
* Accepts requests on privileged and unprivileged device
* Uses OPTEE message protocol version 2 to communicate with secure world

Acked-by: Andreas Dannenberg 
Signed-off-by: Jens Wiklander 
---
 MAINTAINERS   |   5 +
 drivers/tee/Kconfig   |  10 +
 drivers/tee/Makefile  |   1 +
 drivers/tee/optee/Kconfig |   8 +
 drivers/tee/optee/Makefile|   5 +
 drivers/tee/optee/call.c  | 422 +
 drivers/tee/optee/core.c  | 553 ++
 drivers/tee/optee/optee_msg.h | 435 ++
 drivers/tee/optee/optee_private.h | 181 +
 drivers/tee/optee/optee_smc.h | 418 
 drivers/tee/optee/rpc.c   | 401 +++
 drivers/tee/optee/supp.c  | 241 +
 12 files changed, 2680 insertions(+)
 create mode 100644 drivers/tee/optee/Kconfig
 create mode 100644 drivers/tee/optee/Makefile
 create mode 100644 drivers/tee/optee/call.c
 create mode 100644 drivers/tee/optee/core.c
 create mode 100644 drivers/tee/optee/optee_msg.h
 create mode 100644 drivers/tee/optee/optee_private.h
 create mode 100644 drivers/tee/optee/optee_smc.h
 create mode 100644 drivers/tee/optee/rpc.c
 create mode 100644 drivers/tee/optee/supp.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 802ccf9..c02243c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8479,6 +8479,11 @@ F:   arch/*/oprofile/
 F: drivers/oprofile/
 F: include/linux/oprofile.h
 
+OP-TEE DRIVER
+M: Jens Wiklander 
+S: Maintained
+F: drivers/tee/optee/
+
 ORACLE CLUSTER FILESYSTEM 2 (OCFS2)
 M: Mark Fasheh 
 M: Joel Becker 
diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig
index f3ba154..7228045 100644
--- a/drivers/tee/Kconfig
+++ b/drivers/tee/Kconfig
@@ -7,3 +7,13 @@ config TEE
help
  This implements a generic interface towards a Trusted Execution
  Environment (TEE).
+
+if TEE
+
+menu "TEE drivers"
+
+source "drivers/tee/optee/Kconfig"
+
+endmenu
+
+endif
diff --git a/drivers/tee/Makefile b/drivers/tee/Makefile
index 60d2dab..53f3c76 100644
--- a/drivers/tee/Makefile
+++ b/drivers/tee/Makefile
@@ -1,3 +1,4 @@
 obj-y += tee.o
 obj-y += tee_shm.o
 obj-y += tee_shm_pool.o
+obj-$(CONFIG_OPTEE) += optee/
diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
new file mode 100644
index 000..a7a8b71
--- /dev/null
+++ b/drivers/tee/optee/Kconfig
@@ -0,0 +1,8 @@
+# OP-TEE Trusted Execution Environment Configuration
+config OPTEE
+   tristate "OP-TEE"
+   default n
+   depends on HAVE_ARM_SMCCC
+   help
+ This implements the OP-TEE Trusted Execution Environment (TEE)
+ driver.
diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile
new file mode 100644
index 000..92fe578
--- /dev/null
+++ b/drivers/tee/optee/Makefile
@@ -0,0 +1,5 @@
+obj-$(CONFIG_OPTEE) += optee.o
+optee-objs += core.o
+optee-objs += call.o
+optee-objs += rpc.o
+optee-objs += supp.o
diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c
new file mode 100644
index 000..8f9b12e
--- /dev/null
+++ b/drivers/tee/optee/call.c
@@ -0,0 +1,422 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "optee_private.h"
+#include "optee_smc.h"
+
+struct optee_call_waiter {
+   struct list_head list_node;
+   struct completion c;
+   bool completed;
+};
+
+static void optee_cq_wait_init(struct optee_call_queue *cq,
+  struct optee_call_waiter *w)
+{
+   mutex_lock(&cq->mutex);
+   /*
+* We add ourselves to the queue, but we don't wait. This
+* guarentees that we don't lose a completion if secure world
+* returns busy and another thread just exited and try to complete
+* someone.
+*/
+   w->completed = false;
+   init_completion(&w->c);
+   list_add_tail(&w->list_node, &cq->waiters);
+   mutex_unlock(&cq->mutex);
+}
+
+static void optee_cq_wait_for_completion(struct optee_call_queue *cq,
+struct optee_call_waiter *w)
+{
+   wait_for_completion(&w->c);
+
+   mutex_lock(&cq->mutex);
+
+