From: Sumit Garg via OP-TEE <op-tee@lists.trustedfirmware.org>
To: Jens Wiklander <jens.wiklander@linaro.org>
Cc: Amirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com>,
op-tee@lists.trustedfirmware.org
Subject: Re: [PATCH v10 3/9] tee: implement protected DMA-heap
Date: Mon, 7 Jul 2025 18:07:02 +0530 [thread overview]
Message-ID: <aGu_bgKuSDJUKUoP@sumit-X1> (raw)
In-Reply-To: <CAHUa44FV_maNF1Xx0hnqGT3=DnM3zEnLj6CLcz7pZvxEPmiGJw@mail.gmail.com>
On Mon, Jul 07, 2025 at 01:22:19PM +0200, Jens Wiklander wrote:
> Hi Amir,
>
> On Mon, Jul 7, 2025 at 4:22 AM Amirreza Zarrabi via OP-TEE
> <op-tee@lists.trustedfirmware.org> wrote:
> >
> > Hi Jens,
> >
> > On 6/10/2025 11:13 PM, Jens Wiklander wrote:
> > > Implement DMA heap for protected DMA-buf allocation in the TEE
> > > subsystem.
> > >
> > > Protected memory refers to memory buffers behind a hardware enforced
> > > firewall. It is not accessible to the kernel during normal circumstances
> > > but rather only accessible to certain hardware IPs or CPUs executing in
> > > higher or differently privileged mode than the kernel itself. This
> > > interface allows to allocate and manage such protected memory buffers
> > > via interaction with a TEE implementation.
> > >
> > > The protected memory is allocated for a specific use-case, like Secure
> > > Video Playback, Trusted UI, or Secure Video Recording where certain
> > > hardware devices can access the memory.
> > >
> > > The DMA-heaps are enabled explicitly by the TEE backend driver. The TEE
> > > backend drivers needs to implement protected memory pool to manage the
> > > protected memory.
> > >
> > > Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
> > > ---
> > > drivers/tee/Kconfig | 5 +
> > > drivers/tee/Makefile | 1 +
> > > drivers/tee/tee_heap.c | 472 ++++++++++++++++++++++++++++++++++++++
> > > drivers/tee/tee_private.h | 6 +
> > > include/linux/tee_core.h | 65 ++++++
> > > 5 files changed, 549 insertions(+)
> > > create mode 100644 drivers/tee/tee_heap.c
> > >
> [snip]
> >
> > I'm having a bit of trouble understanding the rationale behind
> > supporting tee_device_unregister_all_dma_heaps(). Considering that
> > the heap remains accessible from userspace, wouldn't this lead
> > to undefined behavior? For example, what happens if a user is
> > in the middle of a tee_dma_heap_alloc() -- specifically before
> > tee_device_get() -- while the backend calls tee_device_unregister_all_dma_heaps()?
>
> That can't happen since tee_device_unregister() has been called
> before, guaranteeing that no further calls to tee_device_get() can
> succeed.
>
> >
> > I understand that you want to use teedev refcount to protect against
> > the TEE driver unbinding if there is a buffer allocated. But what about
> > the heap device?
> >
> > Additionally, what if the user decides to unbind the TEE backend driver?
> > Would the dma_heap device still persist without any alloc function?
>
> Yes, the device would still be there, but alloc would return -EINVAL
> until a new heap has been registered.
> But I think you're on to something, we should perhaps increase the TEE
> module refcount when calling dma_heap_add(). Do you agree?
But that won't allow to cleanly un-bind/bind OP-TEE module. It looks
like we rather need to enforce the OP-TEE driver to be built-in in case
it is the provider of DMA heaps.
>
> >
> > In the case of qcomtee, my original idea was to have two separate
> > drivers loaded alongside each other. This setup would allow the
> > TEE backend driver to support unbinding, while the protected memory
> > backend could remain loaded. This separation is particularly useful
> > for FFA, or scenarios where the protected buffer does not need to be
> > transfered to TEE.
> >
> > Or
> >
> > A reference to teedev could be obtained when the heap is registered,
> > rather than for each buffer allocation. In other words, once the heap
> > is registered, the backend must remain active and cannot be unloaded.
> >
> > Or
> >
> > Find a way to have something like dma_heap_rm()?
>
> That would be helpful, but I'd prefer to keep it out of the scope of
> the patchset if possible.
Yeah lets keep that for next feature patch-set.
-Sumit
>
> Thanks,
> Jens
>
> >
> > Please let me know if I mis-understood something? or missing something :)
> >
> > Regards,
> > Amir
> >
> > > +void tee_device_unregister_all_dma_heaps(struct tee_device *teedev)
> > > +{
> > > + struct tee_protmem_pool *pool;
> > > + struct tee_dma_heap *h;
> > > + u_long i;
> > > +
> > > + xa_for_each(&tee_dma_heap, i, h) {
> > > + if (h) {
> > > + pool = NULL;
> > > + mutex_lock(&h->mu);
> > > + if (h->teedev == teedev) {
> > > + pool = h->pool;
> > > + h->teedev = NULL;
> > > + h->pool = NULL;
> > > + }
> > > + mutex_unlock(&h->mu);
> > > + if (pool)
> > > + pool->ops->destroy_pool(pool);
> > > + }
> > > + }
> > > +}
> > > +EXPORT_SYMBOL_GPL(tee_device_unregister_all_dma_heaps);
next prev parent reply other threads:[~2025-07-07 12:37 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 13:13 [PATCH v10 0/9] TEE subsystem for protected dma-buf allocations Jens Wiklander
2025-06-10 13:13 ` [PATCH v10 1/9] optee: sync secure world ABI headers Jens Wiklander
2025-06-10 13:13 ` [PATCH v10 2/9] dma-buf: dma-heap: export declared functions Jens Wiklander
2025-06-17 10:14 ` Sumit Garg via OP-TEE
2025-06-10 13:13 ` [PATCH v10 3/9] tee: implement protected DMA-heap Jens Wiklander
2025-06-17 10:33 ` Sumit Garg via OP-TEE
2025-07-02 0:22 ` Amirreza Zarrabi via OP-TEE
2025-07-02 13:08 ` Jens Wiklander
2025-07-02 21:09 ` Amirreza Zarrabi via OP-TEE
2025-07-07 2:21 ` Amirreza Zarrabi via OP-TEE
2025-07-07 11:22 ` Jens Wiklander
2025-07-07 12:37 ` Sumit Garg via OP-TEE [this message]
2025-07-07 13:37 ` Jens Wiklander
2025-07-09 0:40 ` Amirreza Zarrabi via OP-TEE
2025-07-09 4:45 ` Amirreza Zarrabi via OP-TEE
2025-07-09 7:24 ` Jens Wiklander
2025-06-10 13:13 ` [PATCH v10 4/9] tee: refactor params_from_user() Jens Wiklander
2025-06-10 13:13 ` [PATCH v10 5/9] tee: new ioctl to a register tee_shm from a dmabuf file descriptor Jens Wiklander
2025-06-17 10:48 ` Sumit Garg via OP-TEE
2025-06-18 6:47 ` Jens Wiklander
2025-07-03 7:22 ` Sumit Garg via OP-TEE
2025-07-03 7:34 ` Jens Wiklander
2025-06-10 13:13 ` [PATCH v10 6/9] tee: add tee_shm_alloc_dma_mem() Jens Wiklander
2025-06-17 11:32 ` Sumit Garg via OP-TEE
2025-06-18 7:03 ` Jens Wiklander
2025-07-03 6:28 ` Sumit Garg via OP-TEE
2025-07-03 7:13 ` Jens Wiklander
2025-06-10 13:13 ` [PATCH v10 7/9] optee: support protected memory allocation Jens Wiklander
2025-06-17 11:34 ` Sumit Garg via OP-TEE
2025-06-24 6:54 ` Amirreza Zarrabi via OP-TEE
2025-06-24 7:38 ` Jens Wiklander
2025-06-10 13:13 ` [PATCH v10 8/9] optee: FF-A: dynamic " Jens Wiklander
2025-06-17 11:37 ` Sumit Garg via OP-TEE
2025-06-10 13:13 ` [PATCH v10 9/9] optee: smc abi: " Jens Wiklander
2025-06-17 11:38 ` Sumit Garg via OP-TEE
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=aGu_bgKuSDJUKUoP@sumit-X1 \
--to=op-tee@lists.trustedfirmware.org \
--cc=amirreza.zarrabi@oss.qualcomm.com \
--cc=jens.wiklander@linaro.org \
--cc=sumit.garg@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