devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Wiklander <jens.wiklander@linaro.org>
To: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Cc: Russell King - ARM Linux <linux@arm.linux.org.uk>,
	valentin.manea@huawei.com, devicetree@vger.kernel.org,
	javier@javigon.com, emmanuel.michel@st.com,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, jean-michel.delorme@st.com,
	tpmdd-devel@lists.sourceforge.net,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [tpmdd-devel] [RFC PATCH 1/2] tee: generic TEE subsystem
Date: Tue, 21 Apr 2015 07:59:32 +0200	[thread overview]
Message-ID: <20150421055932.GA7760@ermac> (raw)
In-Reply-To: <20150420175515.GA31958@obsidianresearch.com>

On Mon, Apr 20, 2015 at 11:55:15AM -0600, Jason Gunthorpe wrote:
> On Mon, Apr 20, 2015 at 03:02:03PM +0200, Jens Wiklander wrote:
> > > It appeared to me this driver was copying TPM's old architecture,
> > > which is very much known to be broken.
> > 
> > The struct tee_device holds a shared memory pool from which shared
> > memory objects are allocated. These shared memory objects can be mapped
> > both by user space and secure world. 
> 
> So this is a whole other set of problems besides what was already
> brought up.
> 
> You need to figure out a lifetime model for this shared memory that
> works.
> 
> > To come around the problem with what should happen when the driver
> > is removed I'm increasing the refcount on the driver for each
> > allocated shared memory object and created file pointers. As long as
> > any resource is in use by either user space or secure world the
> > driver can't be unloaded.
> 
> This isn't how the kernel works. The module refcount effects module
> unload (it protects the .text) - it does not interact with driver
> detatch. Userspace can trigger driver detatch (which results in
> tee_unregister being called) at any time via sysfs.
> 
> If you properly design for that case then module unload sequencing
> works properly for free.
> 
> Based on what I gather, I would suggest the following sequence in
> tee_unregister
>  - unregister all sysfs and char dev registrations.
>  - Write lock ops and set to null. This will error future cdev ioctls,
>    and guarentees no driver ops callbacks are in progress, or will be
>    started in future.
>  - Wait until all client accesses to shared memory are
>    released.
>  - Command the driver to release it's side of the
>    shared memory and wait for that to complete
>  - Free the shared memory
>  - deref the tee_device's struct device (match ref in tee_register)
> 
> Then in your struct tee_device's release function free the tee_device
> memory.
> 
> Replace all the module locking code with an active count in struct
> tee_device (see something like kernfs_drain for an example).
> 
> > * Change to use the pattern (with a struct device etc) as described
> >   above.
> 
> Yes, I think Greg confirmed you need to use a struct device, and purge
> misc_device from the mid layer.
> 
> >   I can't protect the ops with just a mutex since tee_ioctl_cmd() needs to
> >   be multithreaded.
> 
> Then use a sleeping read/write lock - aka an active count.

Thanks for the clarification, I got it now.

Regards,
Jens

  reply	other threads:[~2015-04-21  5:59 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-17  7:50 [RFC PATCH 0/2] generic TEE subsystem Jens Wiklander
     [not found] ` <1429257057-7935-1-git-send-email-jens.wiklander-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2015-04-17  7:50   ` [RFC PATCH 1/2] tee: " Jens Wiklander
2015-04-17 16:30     ` [tpmdd-devel] " Jason Gunthorpe
     [not found]       ` <20150417163054.GA28241-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-04-18  9:01         ` Russell King - ARM Linux
     [not found]           ` <20150418090147.GF12732-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2015-04-18 17:29             ` Jason Gunthorpe
     [not found]               ` <20150418172923.GA10605-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-04-18 21:57                 ` Russell King - ARM Linux
2015-04-20  5:08                   ` Jason Gunthorpe
2015-04-20 14:54                     ` Greg Kroah-Hartman
     [not found]                       ` <20150420145432.GD7261-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2015-04-20 15:56                         ` Jason Gunthorpe
     [not found]                           ` <20150420155648.GA7676-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-04-20 16:05                             ` Greg Kroah-Hartman
2015-04-20 13:02                 ` Jens Wiklander
2015-04-20 17:55                   ` Jason Gunthorpe
2015-04-21  5:59                     ` Jens Wiklander [this message]
2015-04-17 20:07     ` Arnd Bergmann
2015-04-18  7:20       ` Paul Bolle
2015-04-20  6:20       ` Jens Wiklander
2015-04-20 18:20         ` [tpmdd-devel] " Jason Gunthorpe
2015-04-21 10:45           ` Jens Wiklander
2015-04-18  8:55     ` Greg Kroah-Hartman
2015-04-18  8:57     ` Greg Kroah-Hartman
     [not found]       ` <20150418085712.GB29858-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2015-04-18  9:04         ` Russell King - ARM Linux
2015-04-18 18:47           ` Greg Kroah-Hartman
2015-04-18 19:02             ` Russell King - ARM Linux
2015-04-18 20:37               ` Greg Kroah-Hartman
2015-04-18 20:50                 ` Russell King - ARM Linux
2015-04-19  7:00                   ` Greg Kroah-Hartman
2015-04-17  7:50   ` [RFC PATCH 2/2] tee: add OP-TEE driver Jens Wiklander
2015-04-18  8:57     ` Greg Kroah-Hartman
2015-04-18  9:36       ` Javier González
2015-04-18 18:49         ` Greg Kroah-Hartman
2015-04-18 19:01           ` Arnd Bergmann
2015-04-19 11:17             ` Javier González
2015-04-19 19:47               ` Arnd Bergmann
2015-04-20  7:05                 ` Javier González
     [not found]       ` <20150418085747.GC29858-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2015-04-20  6:42         ` Jens Wiklander

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=20150421055932.GA7760@ermac \
    --to=jens.wiklander@linaro.org \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=emmanuel.michel@st.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=javier@javigon.com \
    --cc=jean-michel.delorme@st.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=tpmdd-devel@lists.sourceforge.net \
    --cc=valentin.manea@huawei.com \
    /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).